2
0

pdf.combined.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885
  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. /* jshint globalstrict: false */
  16. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/build/pdf.combined', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfCombined = {}));
  25. }
  26. }(this, function (exports) {
  27. // Use strict in our context only - users might not want it
  28. 'use strict';
  29. var pdfjsVersion = '1.4.111';
  30. var pdfjsBuild = '6b1de4a';
  31. var pdfjsFilePath =
  32. typeof document !== 'undefined' && document.currentScript ?
  33. document.currentScript.src : null;
  34. var pdfjsLibs = {};
  35. (function pdfjsWrapper() {
  36. (function (root, factory) {
  37. {
  38. factory((root.pdfjsCoreArithmeticDecoder = {}));
  39. }
  40. }(this, function (exports) {
  41. /* This class implements the QM Coder decoding as defined in
  42. * JPEG 2000 Part I Final Committee Draft Version 1.0
  43. * Annex C.3 Arithmetic decoding procedure
  44. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  45. *
  46. * The arithmetic decoder is used in conjunction with context models to decode
  47. * JPEG2000 and JBIG2 streams.
  48. */
  49. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  50. // Table C-2
  51. var QeTable = [
  52. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  53. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  54. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  55. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  56. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  57. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  58. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  59. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  60. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  61. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  62. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  63. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  64. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  65. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  66. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  67. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  68. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  69. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  70. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  71. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  72. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  73. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  74. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  75. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  76. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  77. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  78. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  79. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  80. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  81. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  82. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  83. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  84. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  85. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  86. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  87. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  88. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  89. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  90. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  91. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  92. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  93. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  94. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  95. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  96. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  97. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  98. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  99. ];
  100. // C.3.5 Initialisation of the decoder (INITDEC)
  101. function ArithmeticDecoder(data, start, end) {
  102. this.data = data;
  103. this.bp = start;
  104. this.dataEnd = end;
  105. this.chigh = data[start];
  106. this.clow = 0;
  107. this.byteIn();
  108. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  109. this.clow = (this.clow << 7) & 0xFFFF;
  110. this.ct -= 7;
  111. this.a = 0x8000;
  112. }
  113. ArithmeticDecoder.prototype = {
  114. // C.3.4 Compressed data input (BYTEIN)
  115. byteIn: function ArithmeticDecoder_byteIn() {
  116. var data = this.data;
  117. var bp = this.bp;
  118. if (data[bp] === 0xFF) {
  119. var b1 = data[bp + 1];
  120. if (b1 > 0x8F) {
  121. this.clow += 0xFF00;
  122. this.ct = 8;
  123. } else {
  124. bp++;
  125. this.clow += (data[bp] << 9);
  126. this.ct = 7;
  127. this.bp = bp;
  128. }
  129. } else {
  130. bp++;
  131. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  132. this.ct = 8;
  133. this.bp = bp;
  134. }
  135. if (this.clow > 0xFFFF) {
  136. this.chigh += (this.clow >> 16);
  137. this.clow &= 0xFFFF;
  138. }
  139. },
  140. // C.3.2 Decoding a decision (DECODE)
  141. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  142. // contexts are packed into 1 byte:
  143. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  144. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  145. var qeTableIcx = QeTable[cx_index];
  146. var qeIcx = qeTableIcx.qe;
  147. var d;
  148. var a = this.a - qeIcx;
  149. if (this.chigh < qeIcx) {
  150. // exchangeLps
  151. if (a < qeIcx) {
  152. a = qeIcx;
  153. d = cx_mps;
  154. cx_index = qeTableIcx.nmps;
  155. } else {
  156. a = qeIcx;
  157. d = 1 ^ cx_mps;
  158. if (qeTableIcx.switchFlag === 1) {
  159. cx_mps = d;
  160. }
  161. cx_index = qeTableIcx.nlps;
  162. }
  163. } else {
  164. this.chigh -= qeIcx;
  165. if ((a & 0x8000) !== 0) {
  166. this.a = a;
  167. return cx_mps;
  168. }
  169. // exchangeMps
  170. if (a < qeIcx) {
  171. d = 1 ^ cx_mps;
  172. if (qeTableIcx.switchFlag === 1) {
  173. cx_mps = d;
  174. }
  175. cx_index = qeTableIcx.nlps;
  176. } else {
  177. d = cx_mps;
  178. cx_index = qeTableIcx.nmps;
  179. }
  180. }
  181. // C.3.3 renormD;
  182. do {
  183. if (this.ct === 0) {
  184. this.byteIn();
  185. }
  186. a <<= 1;
  187. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  188. this.clow = (this.clow << 1) & 0xFFFF;
  189. this.ct--;
  190. } while ((a & 0x8000) === 0);
  191. this.a = a;
  192. contexts[pos] = cx_index << 1 | cx_mps;
  193. return d;
  194. }
  195. };
  196. return ArithmeticDecoder;
  197. })();
  198. exports.ArithmeticDecoder = ArithmeticDecoder;
  199. }));
  200. (function (root, factory) {
  201. {
  202. factory((root.pdfjsCoreCharsets = {}));
  203. }
  204. }(this, function (exports) {
  205. var ISOAdobeCharset = [
  206. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  207. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  208. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  209. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  210. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  211. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  212. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  213. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  214. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  215. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  216. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  217. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  218. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  219. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  220. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  221. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  222. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  223. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  224. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  225. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  226. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  227. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  228. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  229. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  230. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  231. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  232. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  233. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  234. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  235. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  236. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  237. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  238. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  239. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  240. ];
  241. var ExpertCharset = [
  242. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  243. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  244. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  245. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  246. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  247. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  248. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  249. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  250. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  251. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  252. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  253. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  254. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  255. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  256. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  257. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  258. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  259. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  260. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  261. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  262. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  263. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  264. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  265. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  266. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  267. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  268. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  269. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  270. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  271. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  272. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  273. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  274. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  275. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  276. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  277. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  278. 'Ydieresissmall'
  279. ];
  280. var ExpertSubsetCharset = [
  281. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  282. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  283. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  284. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  285. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  286. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  287. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  288. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  289. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  290. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  291. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  292. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  293. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  294. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  295. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  296. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  297. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  298. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  299. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  300. 'periodinferior', 'commainferior'
  301. ];
  302. exports.ISOAdobeCharset = ISOAdobeCharset;
  303. exports.ExpertCharset = ExpertCharset;
  304. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  305. }));
  306. (function (root, factory) {
  307. {
  308. factory((root.pdfjsCoreEncodings = {}));
  309. }
  310. }(this, function (exports) {
  311. var ExpertEncoding = [
  312. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  313. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  314. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  315. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  316. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  317. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  318. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  319. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  320. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  321. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  322. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  323. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  324. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  325. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  326. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  327. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  328. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  329. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  330. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  331. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  332. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  333. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  334. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  335. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  336. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  337. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  338. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  339. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  340. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  341. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  342. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  343. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  344. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  345. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  346. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  347. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  348. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  349. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  350. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  351. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  352. 'Ydieresissmall'];
  353. var MacExpertEncoding = [
  354. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  355. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  356. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  357. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  358. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  359. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  360. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  361. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  362. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  363. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  364. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  365. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  366. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  367. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  368. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  369. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  370. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  371. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  372. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  373. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  374. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  375. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  376. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  377. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  378. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  379. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  380. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  381. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  382. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  383. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  384. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  385. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  386. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  387. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  388. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  389. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  390. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  391. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  392. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  393. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'];
  394. var MacRomanEncoding = [
  395. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  396. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  397. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  398. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  399. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  400. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  401. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  402. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  403. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  404. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  405. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  406. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  407. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  408. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  409. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  410. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  411. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  412. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  413. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  414. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  415. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  416. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  417. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  418. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  419. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  420. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  421. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  422. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  423. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  424. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  425. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  426. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  427. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  428. 'ogonek', 'caron'];
  429. var StandardEncoding = [
  430. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  431. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  432. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  433. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  434. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  435. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  436. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  437. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  438. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  439. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  440. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  441. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  442. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  443. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  444. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  445. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  446. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  447. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  448. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  449. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  450. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  451. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  452. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  453. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  454. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'];
  455. var WinAnsiEncoding = [
  456. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  457. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  458. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  459. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  460. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  461. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  462. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  463. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  464. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  465. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  466. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  467. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  468. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  469. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  470. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  471. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  472. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  473. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  474. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  475. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  476. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  477. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  478. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  479. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  480. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  481. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  482. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  483. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  484. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  485. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  486. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  487. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  488. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  489. 'ydieresis'];
  490. var SymbolSetEncoding = [
  491. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  492. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  493. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  494. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  495. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  496. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  497. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  498. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  499. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  500. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  501. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  502. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  503. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  504. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  505. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  506. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  507. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  508. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  509. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  510. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  511. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  512. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  513. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  514. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  515. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  516. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  517. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  518. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  519. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  520. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  521. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  522. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  523. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  524. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  525. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  526. 'bracerightbt'];
  527. var ZapfDingbatsEncoding = [
  528. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  529. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  530. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  531. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  532. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  533. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  534. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  535. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  536. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  537. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  538. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  539. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  540. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  541. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  542. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  543. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  544. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  545. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  546. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  547. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  548. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  549. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  550. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  551. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191'];
  552. function getEncoding(encodingName) {
  553. switch (encodingName) {
  554. case 'WinAnsiEncoding':
  555. return WinAnsiEncoding;
  556. case 'StandardEncoding':
  557. return StandardEncoding;
  558. case 'MacRomanEncoding':
  559. return MacRomanEncoding;
  560. case 'SymbolSetEncoding':
  561. return SymbolSetEncoding;
  562. case 'ZapfDingbatsEncoding':
  563. return ZapfDingbatsEncoding;
  564. case 'ExpertEncoding':
  565. return ExpertEncoding;
  566. case 'MacExpertEncoding':
  567. return MacExpertEncoding;
  568. default:
  569. return null;
  570. }
  571. }
  572. exports.WinAnsiEncoding = WinAnsiEncoding;
  573. exports.StandardEncoding = StandardEncoding;
  574. exports.MacRomanEncoding = MacRomanEncoding;
  575. exports.SymbolSetEncoding = SymbolSetEncoding;
  576. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  577. exports.ExpertEncoding = ExpertEncoding;
  578. exports.getEncoding = getEncoding;
  579. }));
  580. (function (root, factory) {
  581. {
  582. factory((root.pdfjsCoreJpg = {}));
  583. }
  584. }(this, function (exports) {
  585. /*
  586. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  587. version was created by github user notmasteryet
  588. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  589. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  590. - The JFIF specification can be found in the JPEG File Interchange Format
  591. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  592. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  593. in PostScript Level 2, Technical Note #5116
  594. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  595. */
  596. var JpegImage = (function jpegImage() {
  597. var dctZigZag = new Uint8Array([
  598. 0,
  599. 1, 8,
  600. 16, 9, 2,
  601. 3, 10, 17, 24,
  602. 32, 25, 18, 11, 4,
  603. 5, 12, 19, 26, 33, 40,
  604. 48, 41, 34, 27, 20, 13, 6,
  605. 7, 14, 21, 28, 35, 42, 49, 56,
  606. 57, 50, 43, 36, 29, 22, 15,
  607. 23, 30, 37, 44, 51, 58,
  608. 59, 52, 45, 38, 31,
  609. 39, 46, 53, 60,
  610. 61, 54, 47,
  611. 55, 62,
  612. 63
  613. ]);
  614. var dctCos1 = 4017; // cos(pi/16)
  615. var dctSin1 = 799; // sin(pi/16)
  616. var dctCos3 = 3406; // cos(3*pi/16)
  617. var dctSin3 = 2276; // sin(3*pi/16)
  618. var dctCos6 = 1567; // cos(6*pi/16)
  619. var dctSin6 = 3784; // sin(6*pi/16)
  620. var dctSqrt2 = 5793; // sqrt(2)
  621. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  622. function constructor() {
  623. }
  624. function buildHuffmanTable(codeLengths, values) {
  625. var k = 0, code = [], i, j, length = 16;
  626. while (length > 0 && !codeLengths[length - 1]) {
  627. length--;
  628. }
  629. code.push({children: [], index: 0});
  630. var p = code[0], q;
  631. for (i = 0; i < length; i++) {
  632. for (j = 0; j < codeLengths[i]; j++) {
  633. p = code.pop();
  634. p.children[p.index] = values[k];
  635. while (p.index > 0) {
  636. p = code.pop();
  637. }
  638. p.index++;
  639. code.push(p);
  640. while (code.length <= i) {
  641. code.push(q = {children: [], index: 0});
  642. p.children[p.index] = q.children;
  643. p = q;
  644. }
  645. k++;
  646. }
  647. if (i + 1 < length) {
  648. // p here points to last code
  649. code.push(q = {children: [], index: 0});
  650. p.children[p.index] = q.children;
  651. p = q;
  652. }
  653. }
  654. return code[0].children;
  655. }
  656. function getBlockBufferOffset(component, row, col) {
  657. return 64 * ((component.blocksPerLine + 1) * row + col);
  658. }
  659. function decodeScan(data, offset, frame, components, resetInterval,
  660. spectralStart, spectralEnd, successivePrev, successive) {
  661. var mcusPerLine = frame.mcusPerLine;
  662. var progressive = frame.progressive;
  663. var startOffset = offset, bitsData = 0, bitsCount = 0;
  664. function readBit() {
  665. if (bitsCount > 0) {
  666. bitsCount--;
  667. return (bitsData >> bitsCount) & 1;
  668. }
  669. bitsData = data[offset++];
  670. if (bitsData === 0xFF) {
  671. var nextByte = data[offset++];
  672. if (nextByte) {
  673. throw 'unexpected marker: ' +
  674. ((bitsData << 8) | nextByte).toString(16);
  675. }
  676. // unstuff 0
  677. }
  678. bitsCount = 7;
  679. return bitsData >>> 7;
  680. }
  681. function decodeHuffman(tree) {
  682. var node = tree;
  683. while (true) {
  684. node = node[readBit()];
  685. if (typeof node === 'number') {
  686. return node;
  687. }
  688. if (typeof node !== 'object') {
  689. throw 'invalid huffman sequence';
  690. }
  691. }
  692. }
  693. function receive(length) {
  694. var n = 0;
  695. while (length > 0) {
  696. n = (n << 1) | readBit();
  697. length--;
  698. }
  699. return n;
  700. }
  701. function receiveAndExtend(length) {
  702. if (length === 1) {
  703. return readBit() === 1 ? 1 : -1;
  704. }
  705. var n = receive(length);
  706. if (n >= 1 << (length - 1)) {
  707. return n;
  708. }
  709. return n + (-1 << length) + 1;
  710. }
  711. function decodeBaseline(component, offset) {
  712. var t = decodeHuffman(component.huffmanTableDC);
  713. var diff = t === 0 ? 0 : receiveAndExtend(t);
  714. component.blockData[offset] = (component.pred += diff);
  715. var k = 1;
  716. while (k < 64) {
  717. var rs = decodeHuffman(component.huffmanTableAC);
  718. var s = rs & 15, r = rs >> 4;
  719. if (s === 0) {
  720. if (r < 15) {
  721. break;
  722. }
  723. k += 16;
  724. continue;
  725. }
  726. k += r;
  727. var z = dctZigZag[k];
  728. component.blockData[offset + z] = receiveAndExtend(s);
  729. k++;
  730. }
  731. }
  732. function decodeDCFirst(component, offset) {
  733. var t = decodeHuffman(component.huffmanTableDC);
  734. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  735. component.blockData[offset] = (component.pred += diff);
  736. }
  737. function decodeDCSuccessive(component, offset) {
  738. component.blockData[offset] |= readBit() << successive;
  739. }
  740. var eobrun = 0;
  741. function decodeACFirst(component, offset) {
  742. if (eobrun > 0) {
  743. eobrun--;
  744. return;
  745. }
  746. var k = spectralStart, e = spectralEnd;
  747. while (k <= e) {
  748. var rs = decodeHuffman(component.huffmanTableAC);
  749. var s = rs & 15, r = rs >> 4;
  750. if (s === 0) {
  751. if (r < 15) {
  752. eobrun = receive(r) + (1 << r) - 1;
  753. break;
  754. }
  755. k += 16;
  756. continue;
  757. }
  758. k += r;
  759. var z = dctZigZag[k];
  760. component.blockData[offset + z] =
  761. receiveAndExtend(s) * (1 << successive);
  762. k++;
  763. }
  764. }
  765. var successiveACState = 0, successiveACNextValue;
  766. function decodeACSuccessive(component, offset) {
  767. var k = spectralStart;
  768. var e = spectralEnd;
  769. var r = 0;
  770. var s;
  771. var rs;
  772. while (k <= e) {
  773. var z = dctZigZag[k];
  774. switch (successiveACState) {
  775. case 0: // initial state
  776. rs = decodeHuffman(component.huffmanTableAC);
  777. s = rs & 15;
  778. r = rs >> 4;
  779. if (s === 0) {
  780. if (r < 15) {
  781. eobrun = receive(r) + (1 << r);
  782. successiveACState = 4;
  783. } else {
  784. r = 16;
  785. successiveACState = 1;
  786. }
  787. } else {
  788. if (s !== 1) {
  789. throw 'invalid ACn encoding';
  790. }
  791. successiveACNextValue = receiveAndExtend(s);
  792. successiveACState = r ? 2 : 3;
  793. }
  794. continue;
  795. case 1: // skipping r zero items
  796. case 2:
  797. if (component.blockData[offset + z]) {
  798. component.blockData[offset + z] += (readBit() << successive);
  799. } else {
  800. r--;
  801. if (r === 0) {
  802. successiveACState = successiveACState === 2 ? 3 : 0;
  803. }
  804. }
  805. break;
  806. case 3: // set value for a zero item
  807. if (component.blockData[offset + z]) {
  808. component.blockData[offset + z] += (readBit() << successive);
  809. } else {
  810. component.blockData[offset + z] =
  811. successiveACNextValue << successive;
  812. successiveACState = 0;
  813. }
  814. break;
  815. case 4: // eob
  816. if (component.blockData[offset + z]) {
  817. component.blockData[offset + z] += (readBit() << successive);
  818. }
  819. break;
  820. }
  821. k++;
  822. }
  823. if (successiveACState === 4) {
  824. eobrun--;
  825. if (eobrun === 0) {
  826. successiveACState = 0;
  827. }
  828. }
  829. }
  830. function decodeMcu(component, decode, mcu, row, col) {
  831. var mcuRow = (mcu / mcusPerLine) | 0;
  832. var mcuCol = mcu % mcusPerLine;
  833. var blockRow = mcuRow * component.v + row;
  834. var blockCol = mcuCol * component.h + col;
  835. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  836. decode(component, offset);
  837. }
  838. function decodeBlock(component, decode, mcu) {
  839. var blockRow = (mcu / component.blocksPerLine) | 0;
  840. var blockCol = mcu % component.blocksPerLine;
  841. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  842. decode(component, offset);
  843. }
  844. var componentsLength = components.length;
  845. var component, i, j, k, n;
  846. var decodeFn;
  847. if (progressive) {
  848. if (spectralStart === 0) {
  849. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  850. } else {
  851. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  852. }
  853. } else {
  854. decodeFn = decodeBaseline;
  855. }
  856. var mcu = 0, marker;
  857. var mcuExpected;
  858. if (componentsLength === 1) {
  859. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  860. } else {
  861. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  862. }
  863. if (!resetInterval) {
  864. resetInterval = mcuExpected;
  865. }
  866. var h, v;
  867. while (mcu < mcuExpected) {
  868. // reset interval stuff
  869. for (i = 0; i < componentsLength; i++) {
  870. components[i].pred = 0;
  871. }
  872. eobrun = 0;
  873. if (componentsLength === 1) {
  874. component = components[0];
  875. for (n = 0; n < resetInterval; n++) {
  876. decodeBlock(component, decodeFn, mcu);
  877. mcu++;
  878. }
  879. } else {
  880. for (n = 0; n < resetInterval; n++) {
  881. for (i = 0; i < componentsLength; i++) {
  882. component = components[i];
  883. h = component.h;
  884. v = component.v;
  885. for (j = 0; j < v; j++) {
  886. for (k = 0; k < h; k++) {
  887. decodeMcu(component, decodeFn, mcu, j, k);
  888. }
  889. }
  890. }
  891. mcu++;
  892. }
  893. }
  894. // find marker
  895. bitsCount = 0;
  896. marker = (data[offset] << 8) | data[offset + 1];
  897. if (marker <= 0xFF00) {
  898. throw 'marker was not found';
  899. }
  900. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  901. offset += 2;
  902. } else {
  903. break;
  904. }
  905. }
  906. return offset - startOffset;
  907. }
  908. // A port of poppler's IDCT method which in turn is taken from:
  909. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  910. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  911. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  912. // 988-991.
  913. function quantizeAndInverse(component, blockBufferOffset, p) {
  914. var qt = component.quantizationTable, blockData = component.blockData;
  915. var v0, v1, v2, v3, v4, v5, v6, v7;
  916. var p0, p1, p2, p3, p4, p5, p6, p7;
  917. var t;
  918. // inverse DCT on rows
  919. for (var row = 0; row < 64; row += 8) {
  920. // gather block data
  921. p0 = blockData[blockBufferOffset + row];
  922. p1 = blockData[blockBufferOffset + row + 1];
  923. p2 = blockData[blockBufferOffset + row + 2];
  924. p3 = blockData[blockBufferOffset + row + 3];
  925. p4 = blockData[blockBufferOffset + row + 4];
  926. p5 = blockData[blockBufferOffset + row + 5];
  927. p6 = blockData[blockBufferOffset + row + 6];
  928. p7 = blockData[blockBufferOffset + row + 7];
  929. // dequant p0
  930. p0 *= qt[row];
  931. // check for all-zero AC coefficients
  932. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  933. t = (dctSqrt2 * p0 + 512) >> 10;
  934. p[row] = t;
  935. p[row + 1] = t;
  936. p[row + 2] = t;
  937. p[row + 3] = t;
  938. p[row + 4] = t;
  939. p[row + 5] = t;
  940. p[row + 6] = t;
  941. p[row + 7] = t;
  942. continue;
  943. }
  944. // dequant p1 ... p7
  945. p1 *= qt[row + 1];
  946. p2 *= qt[row + 2];
  947. p3 *= qt[row + 3];
  948. p4 *= qt[row + 4];
  949. p5 *= qt[row + 5];
  950. p6 *= qt[row + 6];
  951. p7 *= qt[row + 7];
  952. // stage 4
  953. v0 = (dctSqrt2 * p0 + 128) >> 8;
  954. v1 = (dctSqrt2 * p4 + 128) >> 8;
  955. v2 = p2;
  956. v3 = p6;
  957. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  958. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  959. v5 = p3 << 4;
  960. v6 = p5 << 4;
  961. // stage 3
  962. v0 = (v0 + v1 + 1) >> 1;
  963. v1 = v0 - v1;
  964. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  965. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  966. v3 = t;
  967. v4 = (v4 + v6 + 1) >> 1;
  968. v6 = v4 - v6;
  969. v7 = (v7 + v5 + 1) >> 1;
  970. v5 = v7 - v5;
  971. // stage 2
  972. v0 = (v0 + v3 + 1) >> 1;
  973. v3 = v0 - v3;
  974. v1 = (v1 + v2 + 1) >> 1;
  975. v2 = v1 - v2;
  976. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  977. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  978. v7 = t;
  979. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  980. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  981. v6 = t;
  982. // stage 1
  983. p[row] = v0 + v7;
  984. p[row + 7] = v0 - v7;
  985. p[row + 1] = v1 + v6;
  986. p[row + 6] = v1 - v6;
  987. p[row + 2] = v2 + v5;
  988. p[row + 5] = v2 - v5;
  989. p[row + 3] = v3 + v4;
  990. p[row + 4] = v3 - v4;
  991. }
  992. // inverse DCT on columns
  993. for (var col = 0; col < 8; ++col) {
  994. p0 = p[col];
  995. p1 = p[col + 8];
  996. p2 = p[col + 16];
  997. p3 = p[col + 24];
  998. p4 = p[col + 32];
  999. p5 = p[col + 40];
  1000. p6 = p[col + 48];
  1001. p7 = p[col + 56];
  1002. // check for all-zero AC coefficients
  1003. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  1004. t = (dctSqrt2 * p0 + 8192) >> 14;
  1005. // convert to 8 bit
  1006. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  1007. blockData[blockBufferOffset + col] = t;
  1008. blockData[blockBufferOffset + col + 8] = t;
  1009. blockData[blockBufferOffset + col + 16] = t;
  1010. blockData[blockBufferOffset + col + 24] = t;
  1011. blockData[blockBufferOffset + col + 32] = t;
  1012. blockData[blockBufferOffset + col + 40] = t;
  1013. blockData[blockBufferOffset + col + 48] = t;
  1014. blockData[blockBufferOffset + col + 56] = t;
  1015. continue;
  1016. }
  1017. // stage 4
  1018. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  1019. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  1020. v2 = p2;
  1021. v3 = p6;
  1022. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  1023. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  1024. v5 = p3;
  1025. v6 = p5;
  1026. // stage 3
  1027. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  1028. // converting to UInt8 range later.
  1029. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  1030. v1 = v0 - v1;
  1031. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  1032. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  1033. v3 = t;
  1034. v4 = (v4 + v6 + 1) >> 1;
  1035. v6 = v4 - v6;
  1036. v7 = (v7 + v5 + 1) >> 1;
  1037. v5 = v7 - v5;
  1038. // stage 2
  1039. v0 = (v0 + v3 + 1) >> 1;
  1040. v3 = v0 - v3;
  1041. v1 = (v1 + v2 + 1) >> 1;
  1042. v2 = v1 - v2;
  1043. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  1044. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  1045. v7 = t;
  1046. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  1047. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  1048. v6 = t;
  1049. // stage 1
  1050. p0 = v0 + v7;
  1051. p7 = v0 - v7;
  1052. p1 = v1 + v6;
  1053. p6 = v1 - v6;
  1054. p2 = v2 + v5;
  1055. p5 = v2 - v5;
  1056. p3 = v3 + v4;
  1057. p4 = v3 - v4;
  1058. // convert to 8-bit integers
  1059. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  1060. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  1061. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  1062. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  1063. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  1064. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  1065. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  1066. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  1067. // store block data
  1068. blockData[blockBufferOffset + col] = p0;
  1069. blockData[blockBufferOffset + col + 8] = p1;
  1070. blockData[blockBufferOffset + col + 16] = p2;
  1071. blockData[blockBufferOffset + col + 24] = p3;
  1072. blockData[blockBufferOffset + col + 32] = p4;
  1073. blockData[blockBufferOffset + col + 40] = p5;
  1074. blockData[blockBufferOffset + col + 48] = p6;
  1075. blockData[blockBufferOffset + col + 56] = p7;
  1076. }
  1077. }
  1078. function buildComponentData(frame, component) {
  1079. var blocksPerLine = component.blocksPerLine;
  1080. var blocksPerColumn = component.blocksPerColumn;
  1081. var computationBuffer = new Int16Array(64);
  1082. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  1083. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  1084. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1085. quantizeAndInverse(component, offset, computationBuffer);
  1086. }
  1087. }
  1088. return component.blockData;
  1089. }
  1090. function clamp0to255(a) {
  1091. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  1092. }
  1093. constructor.prototype = {
  1094. parse: function parse(data) {
  1095. function readUint16() {
  1096. var value = (data[offset] << 8) | data[offset + 1];
  1097. offset += 2;
  1098. return value;
  1099. }
  1100. function readDataBlock() {
  1101. var length = readUint16();
  1102. var array = data.subarray(offset, offset + length - 2);
  1103. offset += array.length;
  1104. return array;
  1105. }
  1106. function prepareComponents(frame) {
  1107. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  1108. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  1109. for (var i = 0; i < frame.components.length; i++) {
  1110. component = frame.components[i];
  1111. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  1112. component.h / frame.maxH);
  1113. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  1114. component.v / frame.maxV);
  1115. var blocksPerLineForMcu = mcusPerLine * component.h;
  1116. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  1117. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  1118. (blocksPerLineForMcu + 1);
  1119. component.blockData = new Int16Array(blocksBufferSize);
  1120. component.blocksPerLine = blocksPerLine;
  1121. component.blocksPerColumn = blocksPerColumn;
  1122. }
  1123. frame.mcusPerLine = mcusPerLine;
  1124. frame.mcusPerColumn = mcusPerColumn;
  1125. }
  1126. var offset = 0;
  1127. var jfif = null;
  1128. var adobe = null;
  1129. var frame, resetInterval;
  1130. var quantizationTables = [];
  1131. var huffmanTablesAC = [], huffmanTablesDC = [];
  1132. var fileMarker = readUint16();
  1133. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  1134. throw 'SOI not found';
  1135. }
  1136. fileMarker = readUint16();
  1137. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  1138. var i, j, l;
  1139. switch(fileMarker) {
  1140. case 0xFFE0: // APP0 (Application Specific)
  1141. case 0xFFE1: // APP1
  1142. case 0xFFE2: // APP2
  1143. case 0xFFE3: // APP3
  1144. case 0xFFE4: // APP4
  1145. case 0xFFE5: // APP5
  1146. case 0xFFE6: // APP6
  1147. case 0xFFE7: // APP7
  1148. case 0xFFE8: // APP8
  1149. case 0xFFE9: // APP9
  1150. case 0xFFEA: // APP10
  1151. case 0xFFEB: // APP11
  1152. case 0xFFEC: // APP12
  1153. case 0xFFED: // APP13
  1154. case 0xFFEE: // APP14
  1155. case 0xFFEF: // APP15
  1156. case 0xFFFE: // COM (Comment)
  1157. var appData = readDataBlock();
  1158. if (fileMarker === 0xFFE0) {
  1159. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  1160. appData[2] === 0x49 && appData[3] === 0x46 &&
  1161. appData[4] === 0) { // 'JFIF\x00'
  1162. jfif = {
  1163. version: { major: appData[5], minor: appData[6] },
  1164. densityUnits: appData[7],
  1165. xDensity: (appData[8] << 8) | appData[9],
  1166. yDensity: (appData[10] << 8) | appData[11],
  1167. thumbWidth: appData[12],
  1168. thumbHeight: appData[13],
  1169. thumbData: appData.subarray(14, 14 +
  1170. 3 * appData[12] * appData[13])
  1171. };
  1172. }
  1173. }
  1174. // TODO APP1 - Exif
  1175. if (fileMarker === 0xFFEE) {
  1176. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  1177. appData[2] === 0x6F && appData[3] === 0x62 &&
  1178. appData[4] === 0x65) { // 'Adobe'
  1179. adobe = {
  1180. version: (appData[5] << 8) | appData[6],
  1181. flags0: (appData[7] << 8) | appData[8],
  1182. flags1: (appData[9] << 8) | appData[10],
  1183. transformCode: appData[11]
  1184. };
  1185. }
  1186. }
  1187. break;
  1188. case 0xFFDB: // DQT (Define Quantization Tables)
  1189. var quantizationTablesLength = readUint16();
  1190. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  1191. var z;
  1192. while (offset < quantizationTablesEnd) {
  1193. var quantizationTableSpec = data[offset++];
  1194. var tableData = new Uint16Array(64);
  1195. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  1196. for (j = 0; j < 64; j++) {
  1197. z = dctZigZag[j];
  1198. tableData[z] = data[offset++];
  1199. }
  1200. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  1201. for (j = 0; j < 64; j++) {
  1202. z = dctZigZag[j];
  1203. tableData[z] = readUint16();
  1204. }
  1205. } else {
  1206. throw 'DQT: invalid table spec';
  1207. }
  1208. quantizationTables[quantizationTableSpec & 15] = tableData;
  1209. }
  1210. break;
  1211. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  1212. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  1213. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  1214. if (frame) {
  1215. throw 'Only single frame JPEGs supported';
  1216. }
  1217. readUint16(); // skip data length
  1218. frame = {};
  1219. frame.extended = (fileMarker === 0xFFC1);
  1220. frame.progressive = (fileMarker === 0xFFC2);
  1221. frame.precision = data[offset++];
  1222. frame.scanLines = readUint16();
  1223. frame.samplesPerLine = readUint16();
  1224. frame.components = [];
  1225. frame.componentIds = {};
  1226. var componentsCount = data[offset++], componentId;
  1227. var maxH = 0, maxV = 0;
  1228. for (i = 0; i < componentsCount; i++) {
  1229. componentId = data[offset];
  1230. var h = data[offset + 1] >> 4;
  1231. var v = data[offset + 1] & 15;
  1232. if (maxH < h) {
  1233. maxH = h;
  1234. }
  1235. if (maxV < v) {
  1236. maxV = v;
  1237. }
  1238. var qId = data[offset + 2];
  1239. l = frame.components.push({
  1240. h: h,
  1241. v: v,
  1242. quantizationTable: quantizationTables[qId]
  1243. });
  1244. frame.componentIds[componentId] = l - 1;
  1245. offset += 3;
  1246. }
  1247. frame.maxH = maxH;
  1248. frame.maxV = maxV;
  1249. prepareComponents(frame);
  1250. break;
  1251. case 0xFFC4: // DHT (Define Huffman Tables)
  1252. var huffmanLength = readUint16();
  1253. for (i = 2; i < huffmanLength;) {
  1254. var huffmanTableSpec = data[offset++];
  1255. var codeLengths = new Uint8Array(16);
  1256. var codeLengthSum = 0;
  1257. for (j = 0; j < 16; j++, offset++) {
  1258. codeLengthSum += (codeLengths[j] = data[offset]);
  1259. }
  1260. var huffmanValues = new Uint8Array(codeLengthSum);
  1261. for (j = 0; j < codeLengthSum; j++, offset++) {
  1262. huffmanValues[j] = data[offset];
  1263. }
  1264. i += 17 + codeLengthSum;
  1265. ((huffmanTableSpec >> 4) === 0 ?
  1266. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  1267. buildHuffmanTable(codeLengths, huffmanValues);
  1268. }
  1269. break;
  1270. case 0xFFDD: // DRI (Define Restart Interval)
  1271. readUint16(); // skip data length
  1272. resetInterval = readUint16();
  1273. break;
  1274. case 0xFFDA: // SOS (Start of Scan)
  1275. var scanLength = readUint16();
  1276. var selectorsCount = data[offset++];
  1277. var components = [], component;
  1278. for (i = 0; i < selectorsCount; i++) {
  1279. var componentIndex = frame.componentIds[data[offset++]];
  1280. component = frame.components[componentIndex];
  1281. var tableSpec = data[offset++];
  1282. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  1283. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  1284. components.push(component);
  1285. }
  1286. var spectralStart = data[offset++];
  1287. var spectralEnd = data[offset++];
  1288. var successiveApproximation = data[offset++];
  1289. var processed = decodeScan(data, offset,
  1290. frame, components, resetInterval,
  1291. spectralStart, spectralEnd,
  1292. successiveApproximation >> 4, successiveApproximation & 15);
  1293. offset += processed;
  1294. break;
  1295. case 0xFFFF: // Fill bytes
  1296. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  1297. offset--;
  1298. }
  1299. break;
  1300. default:
  1301. if (data[offset - 3] === 0xFF &&
  1302. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  1303. // could be incorrect encoding -- last 0xFF byte of the previous
  1304. // block was eaten by the encoder
  1305. offset -= 3;
  1306. break;
  1307. }
  1308. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  1309. }
  1310. fileMarker = readUint16();
  1311. }
  1312. this.width = frame.samplesPerLine;
  1313. this.height = frame.scanLines;
  1314. this.jfif = jfif;
  1315. this.adobe = adobe;
  1316. this.components = [];
  1317. for (i = 0; i < frame.components.length; i++) {
  1318. component = frame.components[i];
  1319. this.components.push({
  1320. output: buildComponentData(frame, component),
  1321. scaleX: component.h / frame.maxH,
  1322. scaleY: component.v / frame.maxV,
  1323. blocksPerLine: component.blocksPerLine,
  1324. blocksPerColumn: component.blocksPerColumn
  1325. });
  1326. }
  1327. this.numComponents = this.components.length;
  1328. },
  1329. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  1330. var scaleX = this.width / width, scaleY = this.height / height;
  1331. var component, componentScaleX, componentScaleY, blocksPerScanline;
  1332. var x, y, i, j, k;
  1333. var index;
  1334. var offset = 0;
  1335. var output;
  1336. var numComponents = this.components.length;
  1337. var dataLength = width * height * numComponents;
  1338. var data = new Uint8Array(dataLength);
  1339. var xScaleBlockOffset = new Uint32Array(width);
  1340. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  1341. for (i = 0; i < numComponents; i++) {
  1342. component = this.components[i];
  1343. componentScaleX = component.scaleX * scaleX;
  1344. componentScaleY = component.scaleY * scaleY;
  1345. offset = i;
  1346. output = component.output;
  1347. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  1348. // precalculate the xScaleBlockOffset
  1349. for (x = 0; x < width; x++) {
  1350. j = 0 | (x * componentScaleX);
  1351. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  1352. }
  1353. // linearize the blocks of the component
  1354. for (y = 0; y < height; y++) {
  1355. j = 0 | (y * componentScaleY);
  1356. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  1357. for (x = 0; x < width; x++) {
  1358. data[offset] = output[index + xScaleBlockOffset[x]];
  1359. offset += numComponents;
  1360. }
  1361. }
  1362. }
  1363. // decodeTransform contains pairs of multiplier (-256..256) and additive
  1364. var transform = this.decodeTransform;
  1365. if (transform) {
  1366. for (i = 0; i < dataLength;) {
  1367. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  1368. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  1369. }
  1370. }
  1371. }
  1372. return data;
  1373. },
  1374. _isColorConversionNeeded: function isColorConversionNeeded() {
  1375. if (this.adobe && this.adobe.transformCode) {
  1376. // The adobe transform marker overrides any previous setting
  1377. return true;
  1378. } else if (this.numComponents === 3) {
  1379. return true;
  1380. } else {
  1381. return false;
  1382. }
  1383. },
  1384. _convertYccToRgb: function convertYccToRgb(data) {
  1385. var Y, Cb, Cr;
  1386. for (var i = 0, length = data.length; i < length; i += 3) {
  1387. Y = data[i ];
  1388. Cb = data[i + 1];
  1389. Cr = data[i + 2];
  1390. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  1391. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  1392. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  1393. }
  1394. return data;
  1395. },
  1396. _convertYcckToRgb: function convertYcckToRgb(data) {
  1397. var Y, Cb, Cr, k;
  1398. var offset = 0;
  1399. for (var i = 0, length = data.length; i < length; i += 4) {
  1400. Y = data[i];
  1401. Cb = data[i + 1];
  1402. Cr = data[i + 2];
  1403. k = data[i + 3];
  1404. var r = -122.67195406894 +
  1405. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  1406. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  1407. 0.154362151871126) +
  1408. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  1409. 0.00477271405408747 * k + 1.53380253221734) +
  1410. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  1411. 0.48357088451265) +
  1412. k * (-0.000336197177618394 * k + 0.484791561490776);
  1413. var g = 107.268039397724 +
  1414. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  1415. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  1416. 0.176491792462875) +
  1417. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  1418. 0.000770482631801132 * k - 0.151051492775562) +
  1419. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  1420. 0.25802910206845) +
  1421. k * (-0.000318913117588328 * k - 0.213742400323665);
  1422. var b = -20.810012546947 +
  1423. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  1424. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  1425. 0.814272968359295) +
  1426. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  1427. 0.000560833691242812 * k - 0.195152027534049) +
  1428. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  1429. 0.116935020465145) +
  1430. k * (-0.000343531996510555 * k + 0.24165260232407);
  1431. data[offset++] = clamp0to255(r);
  1432. data[offset++] = clamp0to255(g);
  1433. data[offset++] = clamp0to255(b);
  1434. }
  1435. return data;
  1436. },
  1437. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  1438. var Y, Cb, Cr;
  1439. for (var i = 0, length = data.length; i < length; i += 4) {
  1440. Y = data[i];
  1441. Cb = data[i + 1];
  1442. Cr = data[i + 2];
  1443. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  1444. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  1445. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  1446. // K in data[i + 3] is unchanged
  1447. }
  1448. return data;
  1449. },
  1450. _convertCmykToRgb: function convertCmykToRgb(data) {
  1451. var c, m, y, k;
  1452. var offset = 0;
  1453. var min = -255 * 255 * 255;
  1454. var scale = 1 / 255 / 255;
  1455. for (var i = 0, length = data.length; i < length; i += 4) {
  1456. c = data[i];
  1457. m = data[i + 1];
  1458. y = data[i + 2];
  1459. k = data[i + 3];
  1460. var r =
  1461. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  1462. 18.82290502165302 * y + 212.25662451639585 * k -
  1463. 72734.4411664936) +
  1464. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  1465. 17.873870861415444 * k - 1401.7366389350734) +
  1466. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  1467. 4465.541406466231) -
  1468. k * (21.86122147463605 * k + 48317.86113160301);
  1469. var g =
  1470. c * (8.841041422036149 * c + 60.118027045597366 * m +
  1471. 6.871425592049007 * y + 31.159100130055922 * k -
  1472. 20220.756542821975) +
  1473. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  1474. 131.35250912493976 * k - 48691.05921601825) +
  1475. y * (4.444339102852739 * y + 9.8632861493405 * k -
  1476. 6341.191035517494) -
  1477. k * (20.737325471181034 * k + 47890.15695978492);
  1478. var b =
  1479. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  1480. 30.89978309703729 * y - 0.23883238689178934 * k -
  1481. 3616.812083916688) +
  1482. m * (10.49593273432072 * m + 63.02378494754052 * y +
  1483. 50.606957656360734 * k - 28620.90484698408) +
  1484. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  1485. 49363.43385999684) -
  1486. k * (22.33816807309886 * k + 45932.16563550634);
  1487. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  1488. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  1489. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  1490. }
  1491. return data;
  1492. },
  1493. getData: function getData(width, height, forceRGBoutput) {
  1494. if (this.numComponents > 4) {
  1495. throw 'Unsupported color mode';
  1496. }
  1497. // type of data: Uint8Array(width * height * numComponents)
  1498. var data = this._getLinearizedBlockData(width, height);
  1499. if (this.numComponents === 1 && forceRGBoutput) {
  1500. var dataLength = data.length;
  1501. var rgbData = new Uint8Array(dataLength * 3);
  1502. var offset = 0;
  1503. for (var i = 0; i < dataLength; i++) {
  1504. var grayColor = data[i];
  1505. rgbData[offset++] = grayColor;
  1506. rgbData[offset++] = grayColor;
  1507. rgbData[offset++] = grayColor;
  1508. }
  1509. return rgbData;
  1510. } else if (this.numComponents === 3) {
  1511. return this._convertYccToRgb(data);
  1512. } else if (this.numComponents === 4) {
  1513. if (this._isColorConversionNeeded()) {
  1514. if (forceRGBoutput) {
  1515. return this._convertYcckToRgb(data);
  1516. } else {
  1517. return this._convertYcckToCmyk(data);
  1518. }
  1519. } else if (forceRGBoutput) {
  1520. return this._convertCmykToRgb(data);
  1521. }
  1522. }
  1523. return data;
  1524. }
  1525. };
  1526. return constructor;
  1527. })();
  1528. exports.JpegImage = JpegImage;
  1529. }));
  1530. (function (root, factory) {
  1531. {
  1532. factory((root.pdfjsSharedGlobal = {}));
  1533. }
  1534. }(this, function (exports) {
  1535. var globalScope = (typeof window !== 'undefined') ? window :
  1536. (typeof global !== 'undefined') ? global :
  1537. (typeof self !== 'undefined') ? self : this;
  1538. var isWorker = (typeof window === 'undefined');
  1539. // The global PDFJS object exposes the API
  1540. // In production, it will be declared outside a global wrapper
  1541. // In development, it will be declared here
  1542. if (!globalScope.PDFJS) {
  1543. globalScope.PDFJS = {};
  1544. }
  1545. if (typeof pdfjsVersion !== 'undefined') {
  1546. globalScope.PDFJS.version = pdfjsVersion;
  1547. }
  1548. if (typeof pdfjsVersion !== 'undefined') {
  1549. globalScope.PDFJS.build = pdfjsBuild;
  1550. }
  1551. globalScope.PDFJS.pdfBug = false;
  1552. exports.globalScope = globalScope;
  1553. exports.isWorker = isWorker;
  1554. exports.PDFJS = globalScope.PDFJS;
  1555. }));
  1556. (function (root, factory) {
  1557. {
  1558. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  1559. }
  1560. }(this, function (exports, sharedGlobal) {
  1561. var PDFJS = sharedGlobal.PDFJS;
  1562. var bidi = PDFJS.bidi = (function bidiClosure() {
  1563. // Character types for symbols from 0000 to 00FF.
  1564. var baseTypes = [
  1565. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  1566. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1567. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  1568. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  1569. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  1570. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1571. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  1572. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1573. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1574. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  1575. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1576. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1577. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  1578. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  1579. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1580. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1581. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1582. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1583. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  1584. ];
  1585. // Character types for symbols from 0600 to 06FF
  1586. var arabicTypes = [
  1587. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1588. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  1589. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1590. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1591. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1592. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1593. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1594. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1595. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  1596. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1597. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1598. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1599. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1600. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1601. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1602. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1603. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1604. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1605. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1606. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  1607. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1608. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  1609. ];
  1610. function isOdd(i) {
  1611. return (i & 1) !== 0;
  1612. }
  1613. function isEven(i) {
  1614. return (i & 1) === 0;
  1615. }
  1616. function findUnequal(arr, start, value) {
  1617. for (var j = start, jj = arr.length; j < jj; ++j) {
  1618. if (arr[j] !== value) {
  1619. return j;
  1620. }
  1621. }
  1622. return j;
  1623. }
  1624. function setValues(arr, start, end, value) {
  1625. for (var j = start; j < end; ++j) {
  1626. arr[j] = value;
  1627. }
  1628. }
  1629. function reverseValues(arr, start, end) {
  1630. for (var i = start, j = end - 1; i < j; ++i, --j) {
  1631. var temp = arr[i];
  1632. arr[i] = arr[j];
  1633. arr[j] = temp;
  1634. }
  1635. }
  1636. function createBidiText(str, isLTR, vertical) {
  1637. return {
  1638. str: str,
  1639. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  1640. };
  1641. }
  1642. // These are used in bidi(), which is called frequently. We re-use them on
  1643. // each call to avoid unnecessary allocations.
  1644. var chars = [];
  1645. var types = [];
  1646. function bidi(str, startLevel, vertical) {
  1647. var isLTR = true;
  1648. var strLength = str.length;
  1649. if (strLength === 0 || vertical) {
  1650. return createBidiText(str, isLTR, vertical);
  1651. }
  1652. // Get types and fill arrays
  1653. chars.length = strLength;
  1654. types.length = strLength;
  1655. var numBidi = 0;
  1656. var i, ii;
  1657. for (i = 0; i < strLength; ++i) {
  1658. chars[i] = str.charAt(i);
  1659. var charCode = str.charCodeAt(i);
  1660. var charType = 'L';
  1661. if (charCode <= 0x00ff) {
  1662. charType = baseTypes[charCode];
  1663. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1664. charType = 'R';
  1665. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1666. charType = arabicTypes[charCode & 0xff];
  1667. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1668. charType = 'AL';
  1669. }
  1670. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1671. numBidi++;
  1672. }
  1673. types[i] = charType;
  1674. }
  1675. // Detect the bidi method
  1676. // - If there are no rtl characters then no bidi needed
  1677. // - If less than 30% chars are rtl then string is primarily ltr
  1678. // - If more than 30% chars are rtl then string is primarily rtl
  1679. if (numBidi === 0) {
  1680. isLTR = true;
  1681. return createBidiText(str, isLTR);
  1682. }
  1683. if (startLevel === -1) {
  1684. if ((strLength / numBidi) < 0.3) {
  1685. isLTR = true;
  1686. startLevel = 0;
  1687. } else {
  1688. isLTR = false;
  1689. startLevel = 1;
  1690. }
  1691. }
  1692. var levels = [];
  1693. for (i = 0; i < strLength; ++i) {
  1694. levels[i] = startLevel;
  1695. }
  1696. /*
  1697. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1698. */
  1699. var e = (isOdd(startLevel) ? 'R' : 'L');
  1700. var sor = e;
  1701. var eor = sor;
  1702. /*
  1703. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1704. type of the NSM to the type of the previous character. If the NSM is at the
  1705. start of the level run, it will get the type of sor.
  1706. */
  1707. var lastType = sor;
  1708. for (i = 0; i < strLength; ++i) {
  1709. if (types[i] === 'NSM') {
  1710. types[i] = lastType;
  1711. } else {
  1712. lastType = types[i];
  1713. }
  1714. }
  1715. /*
  1716. W2. Search backwards from each instance of a European number until the
  1717. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1718. the type of the European number to Arabic number.
  1719. */
  1720. lastType = sor;
  1721. var t;
  1722. for (i = 0; i < strLength; ++i) {
  1723. t = types[i];
  1724. if (t === 'EN') {
  1725. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  1726. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1727. lastType = t;
  1728. }
  1729. }
  1730. /*
  1731. W3. Change all ALs to R.
  1732. */
  1733. for (i = 0; i < strLength; ++i) {
  1734. t = types[i];
  1735. if (t === 'AL') {
  1736. types[i] = 'R';
  1737. }
  1738. }
  1739. /*
  1740. W4. A single European separator between two European numbers changes to a
  1741. European number. A single common separator between two numbers of the same
  1742. type changes to that type:
  1743. */
  1744. for (i = 1; i < strLength - 1; ++i) {
  1745. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1746. types[i] = 'EN';
  1747. }
  1748. if (types[i] === 'CS' &&
  1749. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  1750. types[i + 1] === types[i - 1]) {
  1751. types[i] = types[i - 1];
  1752. }
  1753. }
  1754. /*
  1755. W5. A sequence of European terminators adjacent to European numbers changes
  1756. to all European numbers:
  1757. */
  1758. for (i = 0; i < strLength; ++i) {
  1759. if (types[i] === 'EN') {
  1760. // do before
  1761. var j;
  1762. for (j = i - 1; j >= 0; --j) {
  1763. if (types[j] !== 'ET') {
  1764. break;
  1765. }
  1766. types[j] = 'EN';
  1767. }
  1768. // do after
  1769. for (j = i + 1; j < strLength; --j) {
  1770. if (types[j] !== 'ET') {
  1771. break;
  1772. }
  1773. types[j] = 'EN';
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. W6. Otherwise, separators and terminators change to Other Neutral:
  1779. */
  1780. for (i = 0; i < strLength; ++i) {
  1781. t = types[i];
  1782. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1783. types[i] = 'ON';
  1784. }
  1785. }
  1786. /*
  1787. W7. Search backwards from each instance of a European number until the
  1788. first strong type (R, L, or sor) is found. If an L is found, then change
  1789. the type of the European number to L.
  1790. */
  1791. lastType = sor;
  1792. for (i = 0; i < strLength; ++i) {
  1793. t = types[i];
  1794. if (t === 'EN') {
  1795. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  1796. } else if (t === 'R' || t === 'L') {
  1797. lastType = t;
  1798. }
  1799. }
  1800. /*
  1801. N1. A sequence of neutrals takes the direction of the surrounding strong
  1802. text if the text on both sides has the same direction. European and Arabic
  1803. numbers are treated as though they were R. Start-of-level-run (sor) and
  1804. end-of-level-run (eor) are used at level run boundaries.
  1805. */
  1806. for (i = 0; i < strLength; ++i) {
  1807. if (types[i] === 'ON') {
  1808. var end = findUnequal(types, i + 1, 'ON');
  1809. var before = sor;
  1810. if (i > 0) {
  1811. before = types[i - 1];
  1812. }
  1813. var after = eor;
  1814. if (end + 1 < strLength) {
  1815. after = types[end + 1];
  1816. }
  1817. if (before !== 'L') {
  1818. before = 'R';
  1819. }
  1820. if (after !== 'L') {
  1821. after = 'R';
  1822. }
  1823. if (before === after) {
  1824. setValues(types, i, end, before);
  1825. }
  1826. i = end - 1; // reset to end (-1 so next iteration is ok)
  1827. }
  1828. }
  1829. /*
  1830. N2. Any remaining neutrals take the embedding direction.
  1831. */
  1832. for (i = 0; i < strLength; ++i) {
  1833. if (types[i] === 'ON') {
  1834. types[i] = e;
  1835. }
  1836. }
  1837. /*
  1838. I1. For all characters with an even (left-to-right) embedding direction,
  1839. those of type R go up one level and those of type AN or EN go up two
  1840. levels.
  1841. I2. For all characters with an odd (right-to-left) embedding direction,
  1842. those of type L, EN or AN go up one level.
  1843. */
  1844. for (i = 0; i < strLength; ++i) {
  1845. t = types[i];
  1846. if (isEven(levels[i])) {
  1847. if (t === 'R') {
  1848. levels[i] += 1;
  1849. } else if (t === 'AN' || t === 'EN') {
  1850. levels[i] += 2;
  1851. }
  1852. } else { // isOdd
  1853. if (t === 'L' || t === 'AN' || t === 'EN') {
  1854. levels[i] += 1;
  1855. }
  1856. }
  1857. }
  1858. /*
  1859. L1. On each line, reset the embedding level of the following characters to
  1860. the paragraph embedding level:
  1861. segment separators,
  1862. paragraph separators,
  1863. any sequence of whitespace characters preceding a segment separator or
  1864. paragraph separator, and any sequence of white space characters at the end
  1865. of the line.
  1866. */
  1867. // don't bother as text is only single line
  1868. /*
  1869. L2. From the highest level found in the text to the lowest odd level on
  1870. each line, reverse any contiguous sequence of characters that are at that
  1871. level or higher.
  1872. */
  1873. // find highest level & lowest odd level
  1874. var highestLevel = -1;
  1875. var lowestOddLevel = 99;
  1876. var level;
  1877. for (i = 0, ii = levels.length; i < ii; ++i) {
  1878. level = levels[i];
  1879. if (highestLevel < level) {
  1880. highestLevel = level;
  1881. }
  1882. if (lowestOddLevel > level && isOdd(level)) {
  1883. lowestOddLevel = level;
  1884. }
  1885. }
  1886. // now reverse between those limits
  1887. for (level = highestLevel; level >= lowestOddLevel; --level) {
  1888. // find segments to reverse
  1889. var start = -1;
  1890. for (i = 0, ii = levels.length; i < ii; ++i) {
  1891. if (levels[i] < level) {
  1892. if (start >= 0) {
  1893. reverseValues(chars, start, i);
  1894. start = -1;
  1895. }
  1896. } else if (start < 0) {
  1897. start = i;
  1898. }
  1899. }
  1900. if (start >= 0) {
  1901. reverseValues(chars, start, levels.length);
  1902. }
  1903. }
  1904. /*
  1905. L3. Combining marks applied to a right-to-left base character will at this
  1906. point precede their base character. If the rendering engine expects them to
  1907. follow the base characters in the final display process, then the ordering
  1908. of the marks and the base character must be reversed.
  1909. */
  1910. // don't bother for now
  1911. /*
  1912. L4. A character that possesses the mirrored property as specified by
  1913. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  1914. directionality of that character is R.
  1915. */
  1916. // don't mirror as characters are already mirrored in the pdf
  1917. // Finally, return string
  1918. for (i = 0, ii = chars.length; i < ii; ++i) {
  1919. var ch = chars[i];
  1920. if (ch === '<' || ch === '>') {
  1921. chars[i] = '';
  1922. }
  1923. }
  1924. return createBidiText(chars.join(''), isLTR);
  1925. }
  1926. return bidi;
  1927. })();
  1928. exports.bidi = bidi;
  1929. }));
  1930. (function (root, factory) {
  1931. {
  1932. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  1933. }
  1934. }(this, function (exports, sharedGlobal) {
  1935. var PDFJS = sharedGlobal.PDFJS;
  1936. /**
  1937. * Optimised CSS custom property getter/setter.
  1938. * @class
  1939. */
  1940. var CustomStyle = (function CustomStyleClosure() {
  1941. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  1942. // animate-css-transforms-firefox-webkit.html
  1943. // in some versions of IE9 it is critical that ms appear in this list
  1944. // before Moz
  1945. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  1946. var _cache = Object.create(null);
  1947. function CustomStyle() {}
  1948. CustomStyle.getProp = function get(propName, element) {
  1949. // check cache only when no element is given
  1950. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  1951. return _cache[propName];
  1952. }
  1953. element = element || document.documentElement;
  1954. var style = element.style, prefixed, uPropName;
  1955. // test standard property first
  1956. if (typeof style[propName] === 'string') {
  1957. return (_cache[propName] = propName);
  1958. }
  1959. // capitalize
  1960. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  1961. // test vendor specific properties
  1962. for (var i = 0, l = prefixes.length; i < l; i++) {
  1963. prefixed = prefixes[i] + uPropName;
  1964. if (typeof style[prefixed] === 'string') {
  1965. return (_cache[propName] = prefixed);
  1966. }
  1967. }
  1968. //if all fails then set to undefined
  1969. return (_cache[propName] = 'undefined');
  1970. };
  1971. CustomStyle.setProp = function set(propName, element, str) {
  1972. var prop = this.getProp(propName);
  1973. if (prop !== 'undefined') {
  1974. element.style[prop] = str;
  1975. }
  1976. };
  1977. return CustomStyle;
  1978. })();
  1979. PDFJS.CustomStyle = CustomStyle;
  1980. exports.CustomStyle = CustomStyle;
  1981. }));
  1982. (function (root, factory) {
  1983. {
  1984. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  1985. }
  1986. }(this, function (exports, sharedGlobal) {
  1987. var PDFJS = sharedGlobal.PDFJS;
  1988. var globalScope = sharedGlobal.globalScope;
  1989. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  1990. var TextRenderingMode = {
  1991. FILL: 0,
  1992. STROKE: 1,
  1993. FILL_STROKE: 2,
  1994. INVISIBLE: 3,
  1995. FILL_ADD_TO_PATH: 4,
  1996. STROKE_ADD_TO_PATH: 5,
  1997. FILL_STROKE_ADD_TO_PATH: 6,
  1998. ADD_TO_PATH: 7,
  1999. FILL_STROKE_MASK: 3,
  2000. ADD_TO_PATH_FLAG: 4
  2001. };
  2002. var ImageKind = {
  2003. GRAYSCALE_1BPP: 1,
  2004. RGB_24BPP: 2,
  2005. RGBA_32BPP: 3
  2006. };
  2007. var AnnotationType = {
  2008. TEXT: 1,
  2009. LINK: 2,
  2010. FREETEXT: 3,
  2011. LINE: 4,
  2012. SQUARE: 5,
  2013. CIRCLE: 6,
  2014. POLYGON: 7,
  2015. POLYLINE: 8,
  2016. HIGHLIGHT: 9,
  2017. UNDERLINE: 10,
  2018. SQUIGGLY: 11,
  2019. STRIKEOUT: 12,
  2020. STAMP: 13,
  2021. CARET: 14,
  2022. INK: 15,
  2023. POPUP: 16,
  2024. FILEATTACHMENT: 17,
  2025. SOUND: 18,
  2026. MOVIE: 19,
  2027. WIDGET: 20,
  2028. SCREEN: 21,
  2029. PRINTERMARK: 22,
  2030. TRAPNET: 23,
  2031. WATERMARK: 24,
  2032. THREED: 25,
  2033. REDACT: 26
  2034. };
  2035. var AnnotationFlag = {
  2036. INVISIBLE: 0x01,
  2037. HIDDEN: 0x02,
  2038. PRINT: 0x04,
  2039. NOZOOM: 0x08,
  2040. NOROTATE: 0x10,
  2041. NOVIEW: 0x20,
  2042. READONLY: 0x40,
  2043. LOCKED: 0x80,
  2044. TOGGLENOVIEW: 0x100,
  2045. LOCKEDCONTENTS: 0x200
  2046. };
  2047. var AnnotationBorderStyleType = {
  2048. SOLID: 1,
  2049. DASHED: 2,
  2050. BEVELED: 3,
  2051. INSET: 4,
  2052. UNDERLINE: 5
  2053. };
  2054. var StreamType = {
  2055. UNKNOWN: 0,
  2056. FLATE: 1,
  2057. LZW: 2,
  2058. DCT: 3,
  2059. JPX: 4,
  2060. JBIG: 5,
  2061. A85: 6,
  2062. AHX: 7,
  2063. CCF: 8,
  2064. RL: 9
  2065. };
  2066. var FontType = {
  2067. UNKNOWN: 0,
  2068. TYPE1: 1,
  2069. TYPE1C: 2,
  2070. CIDFONTTYPE0: 3,
  2071. CIDFONTTYPE0C: 4,
  2072. TRUETYPE: 5,
  2073. CIDFONTTYPE2: 6,
  2074. TYPE3: 7,
  2075. OPENTYPE: 8,
  2076. TYPE0: 9,
  2077. MMTYPE1: 10
  2078. };
  2079. PDFJS.VERBOSITY_LEVELS = {
  2080. errors: 0,
  2081. warnings: 1,
  2082. infos: 5
  2083. };
  2084. // All the possible operations for an operator list.
  2085. var OPS = PDFJS.OPS = {
  2086. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2087. // 0's.
  2088. dependency: 1,
  2089. setLineWidth: 2,
  2090. setLineCap: 3,
  2091. setLineJoin: 4,
  2092. setMiterLimit: 5,
  2093. setDash: 6,
  2094. setRenderingIntent: 7,
  2095. setFlatness: 8,
  2096. setGState: 9,
  2097. save: 10,
  2098. restore: 11,
  2099. transform: 12,
  2100. moveTo: 13,
  2101. lineTo: 14,
  2102. curveTo: 15,
  2103. curveTo2: 16,
  2104. curveTo3: 17,
  2105. closePath: 18,
  2106. rectangle: 19,
  2107. stroke: 20,
  2108. closeStroke: 21,
  2109. fill: 22,
  2110. eoFill: 23,
  2111. fillStroke: 24,
  2112. eoFillStroke: 25,
  2113. closeFillStroke: 26,
  2114. closeEOFillStroke: 27,
  2115. endPath: 28,
  2116. clip: 29,
  2117. eoClip: 30,
  2118. beginText: 31,
  2119. endText: 32,
  2120. setCharSpacing: 33,
  2121. setWordSpacing: 34,
  2122. setHScale: 35,
  2123. setLeading: 36,
  2124. setFont: 37,
  2125. setTextRenderingMode: 38,
  2126. setTextRise: 39,
  2127. moveText: 40,
  2128. setLeadingMoveText: 41,
  2129. setTextMatrix: 42,
  2130. nextLine: 43,
  2131. showText: 44,
  2132. showSpacedText: 45,
  2133. nextLineShowText: 46,
  2134. nextLineSetSpacingShowText: 47,
  2135. setCharWidth: 48,
  2136. setCharWidthAndBounds: 49,
  2137. setStrokeColorSpace: 50,
  2138. setFillColorSpace: 51,
  2139. setStrokeColor: 52,
  2140. setStrokeColorN: 53,
  2141. setFillColor: 54,
  2142. setFillColorN: 55,
  2143. setStrokeGray: 56,
  2144. setFillGray: 57,
  2145. setStrokeRGBColor: 58,
  2146. setFillRGBColor: 59,
  2147. setStrokeCMYKColor: 60,
  2148. setFillCMYKColor: 61,
  2149. shadingFill: 62,
  2150. beginInlineImage: 63,
  2151. beginImageData: 64,
  2152. endInlineImage: 65,
  2153. paintXObject: 66,
  2154. markPoint: 67,
  2155. markPointProps: 68,
  2156. beginMarkedContent: 69,
  2157. beginMarkedContentProps: 70,
  2158. endMarkedContent: 71,
  2159. beginCompat: 72,
  2160. endCompat: 73,
  2161. paintFormXObjectBegin: 74,
  2162. paintFormXObjectEnd: 75,
  2163. beginGroup: 76,
  2164. endGroup: 77,
  2165. beginAnnotations: 78,
  2166. endAnnotations: 79,
  2167. beginAnnotation: 80,
  2168. endAnnotation: 81,
  2169. paintJpegXObject: 82,
  2170. paintImageMaskXObject: 83,
  2171. paintImageMaskXObjectGroup: 84,
  2172. paintImageXObject: 85,
  2173. paintInlineImageXObject: 86,
  2174. paintInlineImageXObjectGroup: 87,
  2175. paintImageXObjectRepeat: 88,
  2176. paintImageMaskXObjectRepeat: 89,
  2177. paintSolidColorImageMask: 90,
  2178. constructPath: 91
  2179. };
  2180. // A notice for devs. These are good for things that are helpful to devs, such
  2181. // as warning that Workers were disabled, which is important to devs but not
  2182. // end users.
  2183. function info(msg) {
  2184. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  2185. console.log('Info: ' + msg);
  2186. }
  2187. }
  2188. // Non-fatal warnings.
  2189. function warn(msg) {
  2190. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  2191. console.log('Warning: ' + msg);
  2192. }
  2193. }
  2194. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2195. function deprecated(details) {
  2196. console.log('Deprecated API usage: ' + details);
  2197. }
  2198. // Fatal errors that should trigger the fallback UI and halt execution by
  2199. // throwing an exception.
  2200. function error(msg) {
  2201. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  2202. console.log('Error: ' + msg);
  2203. console.log(backtrace());
  2204. }
  2205. throw new Error(msg);
  2206. }
  2207. function backtrace() {
  2208. try {
  2209. throw new Error();
  2210. } catch (e) {
  2211. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2212. }
  2213. }
  2214. function assert(cond, msg) {
  2215. if (!cond) {
  2216. error(msg);
  2217. }
  2218. }
  2219. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  2220. unknown: 'unknown',
  2221. forms: 'forms',
  2222. javaScript: 'javaScript',
  2223. smask: 'smask',
  2224. shadingPattern: 'shadingPattern',
  2225. font: 'font'
  2226. };
  2227. // Gets the file name from a given URL.
  2228. function getFilenameFromUrl(url) {
  2229. var anchor = url.indexOf('#');
  2230. var query = url.indexOf('?');
  2231. var end = Math.min(
  2232. anchor > 0 ? anchor : url.length,
  2233. query > 0 ? query : url.length);
  2234. return url.substring(url.lastIndexOf('/', end) + 1, end);
  2235. }
  2236. PDFJS.getFilenameFromUrl = getFilenameFromUrl;
  2237. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  2238. // absolute URL, it will be returned as is.
  2239. function combineUrl(baseUrl, url) {
  2240. if (!url) {
  2241. return baseUrl;
  2242. }
  2243. return new URL(url, baseUrl).href;
  2244. }
  2245. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2246. function isSameOrigin(baseUrl, otherUrl) {
  2247. try {
  2248. var base = new URL(baseUrl);
  2249. if (!base.origin || base.origin === 'null') {
  2250. return false; // non-HTTP url
  2251. }
  2252. } catch (e) {
  2253. return false;
  2254. }
  2255. var other = new URL(otherUrl, base);
  2256. return base.origin === other.origin;
  2257. }
  2258. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2259. function isValidUrl(url, allowRelative) {
  2260. if (!url) {
  2261. return false;
  2262. }
  2263. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2264. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2265. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2266. if (!protocol) {
  2267. return allowRelative;
  2268. }
  2269. protocol = protocol[0].toLowerCase();
  2270. switch (protocol) {
  2271. case 'http':
  2272. case 'https':
  2273. case 'ftp':
  2274. case 'mailto':
  2275. case 'tel':
  2276. return true;
  2277. default:
  2278. return false;
  2279. }
  2280. }
  2281. PDFJS.isValidUrl = isValidUrl;
  2282. /**
  2283. * Adds various attributes (href, title, target, rel) to hyperlinks.
  2284. * @param {HTMLLinkElement} link - The link element.
  2285. * @param {Object} params - An object with the properties:
  2286. * @param {string} params.url - An absolute URL.
  2287. */
  2288. function addLinkAttributes(link, params) {
  2289. var url = params && params.url;
  2290. link.href = link.title = (url ? removeNullCharacters(url) : '');
  2291. if (url) {
  2292. if (isExternalLinkTargetSet()) {
  2293. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  2294. }
  2295. // Strip referrer from the URL.
  2296. link.rel = PDFJS.externalLinkRel;
  2297. }
  2298. }
  2299. PDFJS.addLinkAttributes = addLinkAttributes;
  2300. function shadow(obj, prop, value) {
  2301. Object.defineProperty(obj, prop, { value: value,
  2302. enumerable: true,
  2303. configurable: true,
  2304. writable: false });
  2305. return value;
  2306. }
  2307. PDFJS.shadow = shadow;
  2308. function getLookupTableFactory(initializer) {
  2309. var lookup;
  2310. return function () {
  2311. if (initializer) {
  2312. lookup = Object.create(null);
  2313. initializer(lookup);
  2314. initializer = null;
  2315. }
  2316. return lookup;
  2317. };
  2318. }
  2319. var LinkTarget = PDFJS.LinkTarget = {
  2320. NONE: 0, // Default value.
  2321. SELF: 1,
  2322. BLANK: 2,
  2323. PARENT: 3,
  2324. TOP: 4,
  2325. };
  2326. var LinkTargetStringMap = [
  2327. '',
  2328. '_self',
  2329. '_blank',
  2330. '_parent',
  2331. '_top'
  2332. ];
  2333. function isExternalLinkTargetSet() {
  2334. if (PDFJS.openExternalLinksInNewWindow) {
  2335. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  2336. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  2337. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  2338. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  2339. }
  2340. // Reset the deprecated parameter, to suppress further warnings.
  2341. PDFJS.openExternalLinksInNewWindow = false;
  2342. }
  2343. switch (PDFJS.externalLinkTarget) {
  2344. case LinkTarget.NONE:
  2345. return false;
  2346. case LinkTarget.SELF:
  2347. case LinkTarget.BLANK:
  2348. case LinkTarget.PARENT:
  2349. case LinkTarget.TOP:
  2350. return true;
  2351. }
  2352. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  2353. // Reset the external link target, to suppress further warnings.
  2354. PDFJS.externalLinkTarget = LinkTarget.NONE;
  2355. return false;
  2356. }
  2357. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  2358. var PasswordResponses = PDFJS.PasswordResponses = {
  2359. NEED_PASSWORD: 1,
  2360. INCORRECT_PASSWORD: 2
  2361. };
  2362. var PasswordException = (function PasswordExceptionClosure() {
  2363. function PasswordException(msg, code) {
  2364. this.name = 'PasswordException';
  2365. this.message = msg;
  2366. this.code = code;
  2367. }
  2368. PasswordException.prototype = new Error();
  2369. PasswordException.constructor = PasswordException;
  2370. return PasswordException;
  2371. })();
  2372. PDFJS.PasswordException = PasswordException;
  2373. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2374. function UnknownErrorException(msg, details) {
  2375. this.name = 'UnknownErrorException';
  2376. this.message = msg;
  2377. this.details = details;
  2378. }
  2379. UnknownErrorException.prototype = new Error();
  2380. UnknownErrorException.constructor = UnknownErrorException;
  2381. return UnknownErrorException;
  2382. })();
  2383. PDFJS.UnknownErrorException = UnknownErrorException;
  2384. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2385. function InvalidPDFException(msg) {
  2386. this.name = 'InvalidPDFException';
  2387. this.message = msg;
  2388. }
  2389. InvalidPDFException.prototype = new Error();
  2390. InvalidPDFException.constructor = InvalidPDFException;
  2391. return InvalidPDFException;
  2392. })();
  2393. PDFJS.InvalidPDFException = InvalidPDFException;
  2394. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2395. function MissingPDFException(msg) {
  2396. this.name = 'MissingPDFException';
  2397. this.message = msg;
  2398. }
  2399. MissingPDFException.prototype = new Error();
  2400. MissingPDFException.constructor = MissingPDFException;
  2401. return MissingPDFException;
  2402. })();
  2403. PDFJS.MissingPDFException = MissingPDFException;
  2404. var UnexpectedResponseException =
  2405. (function UnexpectedResponseExceptionClosure() {
  2406. function UnexpectedResponseException(msg, status) {
  2407. this.name = 'UnexpectedResponseException';
  2408. this.message = msg;
  2409. this.status = status;
  2410. }
  2411. UnexpectedResponseException.prototype = new Error();
  2412. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2413. return UnexpectedResponseException;
  2414. })();
  2415. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  2416. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2417. function NotImplementedException(msg) {
  2418. this.message = msg;
  2419. }
  2420. NotImplementedException.prototype = new Error();
  2421. NotImplementedException.prototype.name = 'NotImplementedException';
  2422. NotImplementedException.constructor = NotImplementedException;
  2423. return NotImplementedException;
  2424. })();
  2425. var MissingDataException = (function MissingDataExceptionClosure() {
  2426. function MissingDataException(begin, end) {
  2427. this.begin = begin;
  2428. this.end = end;
  2429. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2430. }
  2431. MissingDataException.prototype = new Error();
  2432. MissingDataException.prototype.name = 'MissingDataException';
  2433. MissingDataException.constructor = MissingDataException;
  2434. return MissingDataException;
  2435. })();
  2436. var XRefParseException = (function XRefParseExceptionClosure() {
  2437. function XRefParseException(msg) {
  2438. this.message = msg;
  2439. }
  2440. XRefParseException.prototype = new Error();
  2441. XRefParseException.prototype.name = 'XRefParseException';
  2442. XRefParseException.constructor = XRefParseException;
  2443. return XRefParseException;
  2444. })();
  2445. var NullCharactersRegExp = /\x00/g;
  2446. function removeNullCharacters(str) {
  2447. if (typeof str !== 'string') {
  2448. warn('The argument for removeNullCharacters must be a string.');
  2449. return str;
  2450. }
  2451. return str.replace(NullCharactersRegExp, '');
  2452. }
  2453. PDFJS.removeNullCharacters = removeNullCharacters;
  2454. function bytesToString(bytes) {
  2455. assert(bytes !== null && typeof bytes === 'object' &&
  2456. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2457. var length = bytes.length;
  2458. var MAX_ARGUMENT_COUNT = 8192;
  2459. if (length < MAX_ARGUMENT_COUNT) {
  2460. return String.fromCharCode.apply(null, bytes);
  2461. }
  2462. var strBuf = [];
  2463. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2464. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2465. var chunk = bytes.subarray(i, chunkEnd);
  2466. strBuf.push(String.fromCharCode.apply(null, chunk));
  2467. }
  2468. return strBuf.join('');
  2469. }
  2470. function stringToBytes(str) {
  2471. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2472. var length = str.length;
  2473. var bytes = new Uint8Array(length);
  2474. for (var i = 0; i < length; ++i) {
  2475. bytes[i] = str.charCodeAt(i) & 0xFF;
  2476. }
  2477. return bytes;
  2478. }
  2479. /**
  2480. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  2481. * @param {Array|Uint8Array|string} arr
  2482. * @returns {number}
  2483. */
  2484. function arrayByteLength(arr) {
  2485. if (arr.length !== undefined) {
  2486. return arr.length;
  2487. }
  2488. assert(arr.byteLength !== undefined);
  2489. return arr.byteLength;
  2490. }
  2491. /**
  2492. * Combines array items (arrays) into single Uint8Array object.
  2493. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  2494. * @returns {Uint8Array}
  2495. */
  2496. function arraysToBytes(arr) {
  2497. // Shortcut: if first and only item is Uint8Array, return it.
  2498. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  2499. return arr[0];
  2500. }
  2501. var resultLength = 0;
  2502. var i, ii = arr.length;
  2503. var item, itemLength ;
  2504. for (i = 0; i < ii; i++) {
  2505. item = arr[i];
  2506. itemLength = arrayByteLength(item);
  2507. resultLength += itemLength;
  2508. }
  2509. var pos = 0;
  2510. var data = new Uint8Array(resultLength);
  2511. for (i = 0; i < ii; i++) {
  2512. item = arr[i];
  2513. if (!(item instanceof Uint8Array)) {
  2514. if (typeof item === 'string') {
  2515. item = stringToBytes(item);
  2516. } else {
  2517. item = new Uint8Array(item);
  2518. }
  2519. }
  2520. itemLength = item.byteLength;
  2521. data.set(item, pos);
  2522. pos += itemLength;
  2523. }
  2524. return data;
  2525. }
  2526. function string32(value) {
  2527. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2528. (value >> 8) & 0xff, value & 0xff);
  2529. }
  2530. function log2(x) {
  2531. var n = 1, i = 0;
  2532. while (x > n) {
  2533. n <<= 1;
  2534. i++;
  2535. }
  2536. return i;
  2537. }
  2538. function readInt8(data, start) {
  2539. return (data[start] << 24) >> 24;
  2540. }
  2541. function readUint16(data, offset) {
  2542. return (data[offset] << 8) | data[offset + 1];
  2543. }
  2544. function readUint32(data, offset) {
  2545. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2546. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2547. }
  2548. // Lazy test the endianness of the platform
  2549. // NOTE: This will be 'true' for simulated TypedArrays
  2550. function isLittleEndian() {
  2551. var buffer8 = new Uint8Array(2);
  2552. buffer8[0] = 1;
  2553. var buffer16 = new Uint16Array(buffer8.buffer);
  2554. return (buffer16[0] === 1);
  2555. }
  2556. Object.defineProperty(PDFJS, 'isLittleEndian', {
  2557. configurable: true,
  2558. get: function PDFJS_isLittleEndian() {
  2559. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  2560. }
  2561. });
  2562. // Lazy test if the userAgent support CanvasTypedArrays
  2563. function hasCanvasTypedArrays() {
  2564. var canvas = document.createElement('canvas');
  2565. canvas.width = canvas.height = 1;
  2566. var ctx = canvas.getContext('2d');
  2567. var imageData = ctx.createImageData(1, 1);
  2568. return (typeof imageData.data.buffer !== 'undefined');
  2569. }
  2570. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  2571. configurable: true,
  2572. get: function PDFJS_hasCanvasTypedArrays() {
  2573. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  2574. }
  2575. });
  2576. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2577. function Uint32ArrayView(buffer, length) {
  2578. this.buffer = buffer;
  2579. this.byteLength = buffer.length;
  2580. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2581. ensureUint32ArrayViewProps(this.length);
  2582. }
  2583. Uint32ArrayView.prototype = Object.create(null);
  2584. var uint32ArrayViewSetters = 0;
  2585. function createUint32ArrayProp(index) {
  2586. return {
  2587. get: function () {
  2588. var buffer = this.buffer, offset = index << 2;
  2589. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2590. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2591. },
  2592. set: function (value) {
  2593. var buffer = this.buffer, offset = index << 2;
  2594. buffer[offset] = value & 255;
  2595. buffer[offset + 1] = (value >> 8) & 255;
  2596. buffer[offset + 2] = (value >> 16) & 255;
  2597. buffer[offset + 3] = (value >>> 24) & 255;
  2598. }
  2599. };
  2600. }
  2601. function ensureUint32ArrayViewProps(length) {
  2602. while (uint32ArrayViewSetters < length) {
  2603. Object.defineProperty(Uint32ArrayView.prototype,
  2604. uint32ArrayViewSetters,
  2605. createUint32ArrayProp(uint32ArrayViewSetters));
  2606. uint32ArrayViewSetters++;
  2607. }
  2608. }
  2609. return Uint32ArrayView;
  2610. })();
  2611. exports.Uint32ArrayView = Uint32ArrayView;
  2612. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2613. var Util = PDFJS.Util = (function UtilClosure() {
  2614. function Util() {}
  2615. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2616. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2617. // creating many intermediate strings.
  2618. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2619. rgbBuf[1] = r;
  2620. rgbBuf[3] = g;
  2621. rgbBuf[5] = b;
  2622. return rgbBuf.join('');
  2623. };
  2624. // Concatenates two transformation matrices together and returns the result.
  2625. Util.transform = function Util_transform(m1, m2) {
  2626. return [
  2627. m1[0] * m2[0] + m1[2] * m2[1],
  2628. m1[1] * m2[0] + m1[3] * m2[1],
  2629. m1[0] * m2[2] + m1[2] * m2[3],
  2630. m1[1] * m2[2] + m1[3] * m2[3],
  2631. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2632. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2633. ];
  2634. };
  2635. // For 2d affine transforms
  2636. Util.applyTransform = function Util_applyTransform(p, m) {
  2637. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2638. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2639. return [xt, yt];
  2640. };
  2641. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2642. var d = m[0] * m[3] - m[1] * m[2];
  2643. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2644. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2645. return [xt, yt];
  2646. };
  2647. // Applies the transform to the rectangle and finds the minimum axially
  2648. // aligned bounding box.
  2649. Util.getAxialAlignedBoundingBox =
  2650. function Util_getAxialAlignedBoundingBox(r, m) {
  2651. var p1 = Util.applyTransform(r, m);
  2652. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2653. var p3 = Util.applyTransform([r[0], r[3]], m);
  2654. var p4 = Util.applyTransform([r[2], r[1]], m);
  2655. return [
  2656. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2657. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2658. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2659. Math.max(p1[1], p2[1], p3[1], p4[1])
  2660. ];
  2661. };
  2662. Util.inverseTransform = function Util_inverseTransform(m) {
  2663. var d = m[0] * m[3] - m[1] * m[2];
  2664. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2665. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2666. };
  2667. // Apply a generic 3d matrix M on a 3-vector v:
  2668. // | a b c | | X |
  2669. // | d e f | x | Y |
  2670. // | g h i | | Z |
  2671. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2672. // with v as [X,Y,Z]
  2673. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2674. return [
  2675. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2676. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2677. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2678. ];
  2679. };
  2680. // This calculation uses Singular Value Decomposition.
  2681. // The SVD can be represented with formula A = USV. We are interested in the
  2682. // matrix S here because it represents the scale values.
  2683. Util.singularValueDecompose2dScale =
  2684. function Util_singularValueDecompose2dScale(m) {
  2685. var transpose = [m[0], m[2], m[1], m[3]];
  2686. // Multiply matrix m with its transpose.
  2687. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2688. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2689. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2690. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2691. // Solve the second degree polynomial to get roots.
  2692. var first = (a + d) / 2;
  2693. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2694. var sx = first + second || 1;
  2695. var sy = first - second || 1;
  2696. // Scale values are the square roots of the eigenvalues.
  2697. return [Math.sqrt(sx), Math.sqrt(sy)];
  2698. };
  2699. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2700. // For coordinate systems whose origin lies in the bottom-left, this
  2701. // means normalization to (BL,TR) ordering. For systems with origin in the
  2702. // top-left, this means (TL,BR) ordering.
  2703. Util.normalizeRect = function Util_normalizeRect(rect) {
  2704. var r = rect.slice(0); // clone rect
  2705. if (rect[0] > rect[2]) {
  2706. r[0] = rect[2];
  2707. r[2] = rect[0];
  2708. }
  2709. if (rect[1] > rect[3]) {
  2710. r[1] = rect[3];
  2711. r[3] = rect[1];
  2712. }
  2713. return r;
  2714. };
  2715. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2716. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2717. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2718. Util.intersect = function Util_intersect(rect1, rect2) {
  2719. function compare(a, b) {
  2720. return a - b;
  2721. }
  2722. // Order points along the axes
  2723. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2724. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2725. result = [];
  2726. rect1 = Util.normalizeRect(rect1);
  2727. rect2 = Util.normalizeRect(rect2);
  2728. // X: first and second points belong to different rectangles?
  2729. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2730. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2731. // Intersection must be between second and third points
  2732. result[0] = orderedX[1];
  2733. result[2] = orderedX[2];
  2734. } else {
  2735. return false;
  2736. }
  2737. // Y: first and second points belong to different rectangles?
  2738. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2739. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2740. // Intersection must be between second and third points
  2741. result[1] = orderedY[1];
  2742. result[3] = orderedY[2];
  2743. } else {
  2744. return false;
  2745. }
  2746. return result;
  2747. };
  2748. Util.sign = function Util_sign(num) {
  2749. return num < 0 ? -1 : 1;
  2750. };
  2751. var ROMAN_NUMBER_MAP = [
  2752. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2753. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2754. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2755. ];
  2756. /**
  2757. * Converts positive integers to (upper case) Roman numerals.
  2758. * @param {integer} number - The number that should be converted.
  2759. * @param {boolean} lowerCase - Indicates if the result should be converted
  2760. * to lower case letters. The default is false.
  2761. * @return {string} The resulting Roman number.
  2762. */
  2763. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2764. assert(isInt(number) && number > 0,
  2765. 'The number should be a positive integer.');
  2766. var pos, romanBuf = [];
  2767. // Thousands
  2768. while (number >= 1000) {
  2769. number -= 1000;
  2770. romanBuf.push('M');
  2771. }
  2772. // Hundreds
  2773. pos = (number / 100) | 0;
  2774. number %= 100;
  2775. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2776. // Tens
  2777. pos = (number / 10) | 0;
  2778. number %= 10;
  2779. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2780. // Ones
  2781. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2782. var romanStr = romanBuf.join('');
  2783. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2784. };
  2785. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2786. Array.prototype.push.apply(arr1, arr2);
  2787. };
  2788. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2789. Array.prototype.unshift.apply(arr1, arr2);
  2790. };
  2791. Util.extendObj = function extendObj(obj1, obj2) {
  2792. for (var key in obj2) {
  2793. obj1[key] = obj2[key];
  2794. }
  2795. };
  2796. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2797. name) {
  2798. while (dict && !dict.has(name)) {
  2799. dict = dict.get('Parent');
  2800. }
  2801. if (!dict) {
  2802. return null;
  2803. }
  2804. return dict.get(name);
  2805. };
  2806. Util.inherit = function Util_inherit(sub, base, prototype) {
  2807. sub.prototype = Object.create(base.prototype);
  2808. sub.prototype.constructor = sub;
  2809. for (var prop in prototype) {
  2810. sub.prototype[prop] = prototype[prop];
  2811. }
  2812. };
  2813. Util.loadScript = function Util_loadScript(src, callback) {
  2814. var script = document.createElement('script');
  2815. var loaded = false;
  2816. script.setAttribute('src', src);
  2817. if (callback) {
  2818. script.onload = function() {
  2819. if (!loaded) {
  2820. callback();
  2821. }
  2822. loaded = true;
  2823. };
  2824. }
  2825. document.getElementsByTagName('head')[0].appendChild(script);
  2826. };
  2827. return Util;
  2828. })();
  2829. /**
  2830. * PDF page viewport created based on scale, rotation and offset.
  2831. * @class
  2832. * @alias PDFJS.PageViewport
  2833. */
  2834. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  2835. /**
  2836. * @constructor
  2837. * @private
  2838. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  2839. * @param scale {number} scale of the viewport.
  2840. * @param rotation {number} rotations of the viewport in degrees.
  2841. * @param offsetX {number} offset X
  2842. * @param offsetY {number} offset Y
  2843. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  2844. */
  2845. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  2846. this.viewBox = viewBox;
  2847. this.scale = scale;
  2848. this.rotation = rotation;
  2849. this.offsetX = offsetX;
  2850. this.offsetY = offsetY;
  2851. // creating transform to convert pdf coordinate system to the normal
  2852. // canvas like coordinates taking in account scale and rotation
  2853. var centerX = (viewBox[2] + viewBox[0]) / 2;
  2854. var centerY = (viewBox[3] + viewBox[1]) / 2;
  2855. var rotateA, rotateB, rotateC, rotateD;
  2856. rotation = rotation % 360;
  2857. rotation = rotation < 0 ? rotation + 360 : rotation;
  2858. switch (rotation) {
  2859. case 180:
  2860. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  2861. break;
  2862. case 90:
  2863. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  2864. break;
  2865. case 270:
  2866. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  2867. break;
  2868. //case 0:
  2869. default:
  2870. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  2871. break;
  2872. }
  2873. if (dontFlip) {
  2874. rotateC = -rotateC; rotateD = -rotateD;
  2875. }
  2876. var offsetCanvasX, offsetCanvasY;
  2877. var width, height;
  2878. if (rotateA === 0) {
  2879. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2880. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2881. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2882. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2883. } else {
  2884. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2885. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2886. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2887. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2888. }
  2889. // creating transform for the following operations:
  2890. // translate(-centerX, -centerY), rotate and flip vertically,
  2891. // scale, and translate(offsetCanvasX, offsetCanvasY)
  2892. this.transform = [
  2893. rotateA * scale,
  2894. rotateB * scale,
  2895. rotateC * scale,
  2896. rotateD * scale,
  2897. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  2898. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  2899. ];
  2900. this.width = width;
  2901. this.height = height;
  2902. this.fontScale = scale;
  2903. }
  2904. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  2905. /**
  2906. * Clones viewport with additional properties.
  2907. * @param args {Object} (optional) If specified, may contain the 'scale' or
  2908. * 'rotation' properties to override the corresponding properties in
  2909. * the cloned viewport.
  2910. * @returns {PDFJS.PageViewport} Cloned viewport.
  2911. */
  2912. clone: function PageViewPort_clone(args) {
  2913. args = args || {};
  2914. var scale = 'scale' in args ? args.scale : this.scale;
  2915. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  2916. return new PageViewport(this.viewBox.slice(), scale, rotation,
  2917. this.offsetX, this.offsetY, args.dontFlip);
  2918. },
  2919. /**
  2920. * Converts PDF point to the viewport coordinates. For examples, useful for
  2921. * converting PDF location into canvas pixel coordinates.
  2922. * @param x {number} X coordinate.
  2923. * @param y {number} Y coordinate.
  2924. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2925. * point in the viewport coordinate space.
  2926. * @see {@link convertToPdfPoint}
  2927. * @see {@link convertToViewportRectangle}
  2928. */
  2929. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  2930. return Util.applyTransform([x, y], this.transform);
  2931. },
  2932. /**
  2933. * Converts PDF rectangle to the viewport coordinates.
  2934. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  2935. * @returns {Array} Contains corresponding coordinates of the rectangle
  2936. * in the viewport coordinate space.
  2937. * @see {@link convertToViewportPoint}
  2938. */
  2939. convertToViewportRectangle:
  2940. function PageViewport_convertToViewportRectangle(rect) {
  2941. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  2942. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  2943. return [tl[0], tl[1], br[0], br[1]];
  2944. },
  2945. /**
  2946. * Converts viewport coordinates to the PDF location. For examples, useful
  2947. * for converting canvas pixel location into PDF one.
  2948. * @param x {number} X coordinate.
  2949. * @param y {number} Y coordinate.
  2950. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2951. * point in the PDF coordinate space.
  2952. * @see {@link convertToViewportPoint}
  2953. */
  2954. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  2955. return Util.applyInverseTransform([x, y], this.transform);
  2956. }
  2957. };
  2958. return PageViewport;
  2959. })();
  2960. var PDFStringTranslateTable = [
  2961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2962. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  2963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  2967. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  2968. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  2969. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  2970. ];
  2971. function stringToPDFString(str) {
  2972. var i, n = str.length, strBuf = [];
  2973. if (str[0] === '\xFE' && str[1] === '\xFF') {
  2974. // UTF16BE BOM
  2975. for (i = 2; i < n; i += 2) {
  2976. strBuf.push(String.fromCharCode(
  2977. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  2978. }
  2979. } else {
  2980. for (i = 0; i < n; ++i) {
  2981. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  2982. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  2983. }
  2984. }
  2985. return strBuf.join('');
  2986. }
  2987. function stringToUTF8String(str) {
  2988. return decodeURIComponent(escape(str));
  2989. }
  2990. function utf8StringToString(str) {
  2991. return unescape(encodeURIComponent(str));
  2992. }
  2993. function isEmptyObj(obj) {
  2994. for (var key in obj) {
  2995. return false;
  2996. }
  2997. return true;
  2998. }
  2999. function isBool(v) {
  3000. return typeof v === 'boolean';
  3001. }
  3002. function isInt(v) {
  3003. return typeof v === 'number' && ((v | 0) === v);
  3004. }
  3005. function isNum(v) {
  3006. return typeof v === 'number';
  3007. }
  3008. function isString(v) {
  3009. return typeof v === 'string';
  3010. }
  3011. function isArray(v) {
  3012. return v instanceof Array;
  3013. }
  3014. function isArrayBuffer(v) {
  3015. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  3016. }
  3017. /**
  3018. * Promise Capability object.
  3019. *
  3020. * @typedef {Object} PromiseCapability
  3021. * @property {Promise} promise - A promise object.
  3022. * @property {function} resolve - Fullfills the promise.
  3023. * @property {function} reject - Rejects the promise.
  3024. */
  3025. /**
  3026. * Creates a promise capability object.
  3027. * @alias PDFJS.createPromiseCapability
  3028. *
  3029. * @return {PromiseCapability} A capability object contains:
  3030. * - a Promise, resolve and reject methods.
  3031. */
  3032. function createPromiseCapability() {
  3033. var capability = {};
  3034. capability.promise = new Promise(function (resolve, reject) {
  3035. capability.resolve = resolve;
  3036. capability.reject = reject;
  3037. });
  3038. return capability;
  3039. }
  3040. PDFJS.createPromiseCapability = createPromiseCapability;
  3041. /**
  3042. * Polyfill for Promises:
  3043. * The following promise implementation tries to generally implement the
  3044. * Promise/A+ spec. Some notable differences from other promise libaries are:
  3045. * - There currently isn't a seperate deferred and promise object.
  3046. * - Unhandled rejections eventually show an error if they aren't handled.
  3047. *
  3048. * Based off of the work in:
  3049. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  3050. */
  3051. (function PromiseClosure() {
  3052. if (globalScope.Promise) {
  3053. // Promises existing in the DOM/Worker, checking presence of all/resolve
  3054. if (typeof globalScope.Promise.all !== 'function') {
  3055. globalScope.Promise.all = function (iterable) {
  3056. var count = 0, results = [], resolve, reject;
  3057. var promise = new globalScope.Promise(function (resolve_, reject_) {
  3058. resolve = resolve_;
  3059. reject = reject_;
  3060. });
  3061. iterable.forEach(function (p, i) {
  3062. count++;
  3063. p.then(function (result) {
  3064. results[i] = result;
  3065. count--;
  3066. if (count === 0) {
  3067. resolve(results);
  3068. }
  3069. }, reject);
  3070. });
  3071. if (count === 0) {
  3072. resolve(results);
  3073. }
  3074. return promise;
  3075. };
  3076. }
  3077. if (typeof globalScope.Promise.resolve !== 'function') {
  3078. globalScope.Promise.resolve = function (value) {
  3079. return new globalScope.Promise(function (resolve) { resolve(value); });
  3080. };
  3081. }
  3082. if (typeof globalScope.Promise.reject !== 'function') {
  3083. globalScope.Promise.reject = function (reason) {
  3084. return new globalScope.Promise(function (resolve, reject) {
  3085. reject(reason);
  3086. });
  3087. };
  3088. }
  3089. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  3090. globalScope.Promise.prototype.catch = function (onReject) {
  3091. return globalScope.Promise.prototype.then(undefined, onReject);
  3092. };
  3093. }
  3094. return;
  3095. }
  3096. var STATUS_PENDING = 0;
  3097. var STATUS_RESOLVED = 1;
  3098. var STATUS_REJECTED = 2;
  3099. // In an attempt to avoid silent exceptions, unhandled rejections are
  3100. // tracked and if they aren't handled in a certain amount of time an
  3101. // error is logged.
  3102. var REJECTION_TIMEOUT = 500;
  3103. var HandlerManager = {
  3104. handlers: [],
  3105. running: false,
  3106. unhandledRejections: [],
  3107. pendingRejectionCheck: false,
  3108. scheduleHandlers: function scheduleHandlers(promise) {
  3109. if (promise._status === STATUS_PENDING) {
  3110. return;
  3111. }
  3112. this.handlers = this.handlers.concat(promise._handlers);
  3113. promise._handlers = [];
  3114. if (this.running) {
  3115. return;
  3116. }
  3117. this.running = true;
  3118. setTimeout(this.runHandlers.bind(this), 0);
  3119. },
  3120. runHandlers: function runHandlers() {
  3121. var RUN_TIMEOUT = 1; // ms
  3122. var timeoutAt = Date.now() + RUN_TIMEOUT;
  3123. while (this.handlers.length > 0) {
  3124. var handler = this.handlers.shift();
  3125. var nextStatus = handler.thisPromise._status;
  3126. var nextValue = handler.thisPromise._value;
  3127. try {
  3128. if (nextStatus === STATUS_RESOLVED) {
  3129. if (typeof handler.onResolve === 'function') {
  3130. nextValue = handler.onResolve(nextValue);
  3131. }
  3132. } else if (typeof handler.onReject === 'function') {
  3133. nextValue = handler.onReject(nextValue);
  3134. nextStatus = STATUS_RESOLVED;
  3135. if (handler.thisPromise._unhandledRejection) {
  3136. this.removeUnhandeledRejection(handler.thisPromise);
  3137. }
  3138. }
  3139. } catch (ex) {
  3140. nextStatus = STATUS_REJECTED;
  3141. nextValue = ex;
  3142. }
  3143. handler.nextPromise._updateStatus(nextStatus, nextValue);
  3144. if (Date.now() >= timeoutAt) {
  3145. break;
  3146. }
  3147. }
  3148. if (this.handlers.length > 0) {
  3149. setTimeout(this.runHandlers.bind(this), 0);
  3150. return;
  3151. }
  3152. this.running = false;
  3153. },
  3154. addUnhandledRejection: function addUnhandledRejection(promise) {
  3155. this.unhandledRejections.push({
  3156. promise: promise,
  3157. time: Date.now()
  3158. });
  3159. this.scheduleRejectionCheck();
  3160. },
  3161. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  3162. promise._unhandledRejection = false;
  3163. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3164. if (this.unhandledRejections[i].promise === promise) {
  3165. this.unhandledRejections.splice(i);
  3166. i--;
  3167. }
  3168. }
  3169. },
  3170. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3171. if (this.pendingRejectionCheck) {
  3172. return;
  3173. }
  3174. this.pendingRejectionCheck = true;
  3175. setTimeout(function rejectionCheck() {
  3176. this.pendingRejectionCheck = false;
  3177. var now = Date.now();
  3178. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3179. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3180. var unhandled = this.unhandledRejections[i].promise._value;
  3181. var msg = 'Unhandled rejection: ' + unhandled;
  3182. if (unhandled.stack) {
  3183. msg += '\n' + unhandled.stack;
  3184. }
  3185. warn(msg);
  3186. this.unhandledRejections.splice(i);
  3187. i--;
  3188. }
  3189. }
  3190. if (this.unhandledRejections.length) {
  3191. this.scheduleRejectionCheck();
  3192. }
  3193. }.bind(this), REJECTION_TIMEOUT);
  3194. }
  3195. };
  3196. function Promise(resolver) {
  3197. this._status = STATUS_PENDING;
  3198. this._handlers = [];
  3199. try {
  3200. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3201. } catch (e) {
  3202. this._reject(e);
  3203. }
  3204. }
  3205. /**
  3206. * Builds a promise that is resolved when all the passed in promises are
  3207. * resolved.
  3208. * @param {array} array of data and/or promises to wait for.
  3209. * @return {Promise} New dependant promise.
  3210. */
  3211. Promise.all = function Promise_all(promises) {
  3212. var resolveAll, rejectAll;
  3213. var deferred = new Promise(function (resolve, reject) {
  3214. resolveAll = resolve;
  3215. rejectAll = reject;
  3216. });
  3217. var unresolved = promises.length;
  3218. var results = [];
  3219. if (unresolved === 0) {
  3220. resolveAll(results);
  3221. return deferred;
  3222. }
  3223. function reject(reason) {
  3224. if (deferred._status === STATUS_REJECTED) {
  3225. return;
  3226. }
  3227. results = [];
  3228. rejectAll(reason);
  3229. }
  3230. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3231. var promise = promises[i];
  3232. var resolve = (function(i) {
  3233. return function(value) {
  3234. if (deferred._status === STATUS_REJECTED) {
  3235. return;
  3236. }
  3237. results[i] = value;
  3238. unresolved--;
  3239. if (unresolved === 0) {
  3240. resolveAll(results);
  3241. }
  3242. };
  3243. })(i);
  3244. if (Promise.isPromise(promise)) {
  3245. promise.then(resolve, reject);
  3246. } else {
  3247. resolve(promise);
  3248. }
  3249. }
  3250. return deferred;
  3251. };
  3252. /**
  3253. * Checks if the value is likely a promise (has a 'then' function).
  3254. * @return {boolean} true if value is thenable
  3255. */
  3256. Promise.isPromise = function Promise_isPromise(value) {
  3257. return value && typeof value.then === 'function';
  3258. };
  3259. /**
  3260. * Creates resolved promise
  3261. * @param value resolve value
  3262. * @returns {Promise}
  3263. */
  3264. Promise.resolve = function Promise_resolve(value) {
  3265. return new Promise(function (resolve) { resolve(value); });
  3266. };
  3267. /**
  3268. * Creates rejected promise
  3269. * @param reason rejection value
  3270. * @returns {Promise}
  3271. */
  3272. Promise.reject = function Promise_reject(reason) {
  3273. return new Promise(function (resolve, reject) { reject(reason); });
  3274. };
  3275. Promise.prototype = {
  3276. _status: null,
  3277. _value: null,
  3278. _handlers: null,
  3279. _unhandledRejection: null,
  3280. _updateStatus: function Promise__updateStatus(status, value) {
  3281. if (this._status === STATUS_RESOLVED ||
  3282. this._status === STATUS_REJECTED) {
  3283. return;
  3284. }
  3285. if (status === STATUS_RESOLVED &&
  3286. Promise.isPromise(value)) {
  3287. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3288. this._updateStatus.bind(this, STATUS_REJECTED));
  3289. return;
  3290. }
  3291. this._status = status;
  3292. this._value = value;
  3293. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3294. this._unhandledRejection = true;
  3295. HandlerManager.addUnhandledRejection(this);
  3296. }
  3297. HandlerManager.scheduleHandlers(this);
  3298. },
  3299. _resolve: function Promise_resolve(value) {
  3300. this._updateStatus(STATUS_RESOLVED, value);
  3301. },
  3302. _reject: function Promise_reject(reason) {
  3303. this._updateStatus(STATUS_REJECTED, reason);
  3304. },
  3305. then: function Promise_then(onResolve, onReject) {
  3306. var nextPromise = new Promise(function (resolve, reject) {
  3307. this.resolve = resolve;
  3308. this.reject = reject;
  3309. });
  3310. this._handlers.push({
  3311. thisPromise: this,
  3312. onResolve: onResolve,
  3313. onReject: onReject,
  3314. nextPromise: nextPromise
  3315. });
  3316. HandlerManager.scheduleHandlers(this);
  3317. return nextPromise;
  3318. },
  3319. catch: function Promise_catch(onReject) {
  3320. return this.then(undefined, onReject);
  3321. }
  3322. };
  3323. globalScope.Promise = Promise;
  3324. })();
  3325. var StatTimer = (function StatTimerClosure() {
  3326. function rpad(str, pad, length) {
  3327. while (str.length < length) {
  3328. str += pad;
  3329. }
  3330. return str;
  3331. }
  3332. function StatTimer() {
  3333. this.started = Object.create(null);
  3334. this.times = [];
  3335. this.enabled = true;
  3336. }
  3337. StatTimer.prototype = {
  3338. time: function StatTimer_time(name) {
  3339. if (!this.enabled) {
  3340. return;
  3341. }
  3342. if (name in this.started) {
  3343. warn('Timer is already running for ' + name);
  3344. }
  3345. this.started[name] = Date.now();
  3346. },
  3347. timeEnd: function StatTimer_timeEnd(name) {
  3348. if (!this.enabled) {
  3349. return;
  3350. }
  3351. if (!(name in this.started)) {
  3352. warn('Timer has not been started for ' + name);
  3353. }
  3354. this.times.push({
  3355. 'name': name,
  3356. 'start': this.started[name],
  3357. 'end': Date.now()
  3358. });
  3359. // Remove timer from started so it can be called again.
  3360. delete this.started[name];
  3361. },
  3362. toString: function StatTimer_toString() {
  3363. var i, ii;
  3364. var times = this.times;
  3365. var out = '';
  3366. // Find the longest name for padding purposes.
  3367. var longest = 0;
  3368. for (i = 0, ii = times.length; i < ii; ++i) {
  3369. var name = times[i]['name'];
  3370. if (name.length > longest) {
  3371. longest = name.length;
  3372. }
  3373. }
  3374. for (i = 0, ii = times.length; i < ii; ++i) {
  3375. var span = times[i];
  3376. var duration = span.end - span.start;
  3377. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3378. }
  3379. return out;
  3380. }
  3381. };
  3382. return StatTimer;
  3383. })();
  3384. PDFJS.createBlob = function createBlob(data, contentType) {
  3385. if (typeof Blob !== 'undefined') {
  3386. return new Blob([data], { type: contentType });
  3387. }
  3388. // Blob builder is deprecated in FF14 and removed in FF18.
  3389. var bb = new MozBlobBuilder();
  3390. bb.append(data);
  3391. return bb.getBlob(contentType);
  3392. };
  3393. PDFJS.createObjectURL = (function createObjectURLClosure() {
  3394. // Blob/createObjectURL is not available, falling back to data schema.
  3395. var digits =
  3396. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3397. return function createObjectURL(data, contentType) {
  3398. if (!PDFJS.disableCreateObjectURL &&
  3399. typeof URL !== 'undefined' && URL.createObjectURL) {
  3400. var blob = PDFJS.createBlob(data, contentType);
  3401. return URL.createObjectURL(blob);
  3402. }
  3403. var buffer = 'data:' + contentType + ';base64,';
  3404. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3405. var b1 = data[i] & 0xFF;
  3406. var b2 = data[i + 1] & 0xFF;
  3407. var b3 = data[i + 2] & 0xFF;
  3408. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3409. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3410. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3411. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3412. }
  3413. return buffer;
  3414. };
  3415. })();
  3416. function MessageHandler(sourceName, targetName, comObj) {
  3417. this.sourceName = sourceName;
  3418. this.targetName = targetName;
  3419. this.comObj = comObj;
  3420. this.callbackIndex = 1;
  3421. this.postMessageTransfers = true;
  3422. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3423. var ah = this.actionHandler = Object.create(null);
  3424. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3425. var data = event.data;
  3426. if (data.targetName !== this.sourceName) {
  3427. return;
  3428. }
  3429. if (data.isReply) {
  3430. var callbackId = data.callbackId;
  3431. if (data.callbackId in callbacksCapabilities) {
  3432. var callback = callbacksCapabilities[callbackId];
  3433. delete callbacksCapabilities[callbackId];
  3434. if ('error' in data) {
  3435. callback.reject(data.error);
  3436. } else {
  3437. callback.resolve(data.data);
  3438. }
  3439. } else {
  3440. error('Cannot resolve callback ' + callbackId);
  3441. }
  3442. } else if (data.action in ah) {
  3443. var action = ah[data.action];
  3444. if (data.callbackId) {
  3445. var sourceName = this.sourceName;
  3446. var targetName = data.sourceName;
  3447. Promise.resolve().then(function () {
  3448. return action[0].call(action[1], data.data);
  3449. }).then(function (result) {
  3450. comObj.postMessage({
  3451. sourceName: sourceName,
  3452. targetName: targetName,
  3453. isReply: true,
  3454. callbackId: data.callbackId,
  3455. data: result
  3456. });
  3457. }, function (reason) {
  3458. if (reason instanceof Error) {
  3459. // Serialize error to avoid "DataCloneError"
  3460. reason = reason + '';
  3461. }
  3462. comObj.postMessage({
  3463. sourceName: sourceName,
  3464. targetName: targetName,
  3465. isReply: true,
  3466. callbackId: data.callbackId,
  3467. error: reason
  3468. });
  3469. });
  3470. } else {
  3471. action[0].call(action[1], data.data);
  3472. }
  3473. } else {
  3474. error('Unknown action from worker: ' + data.action);
  3475. }
  3476. }.bind(this);
  3477. comObj.addEventListener('message', this._onComObjOnMessage);
  3478. }
  3479. MessageHandler.prototype = {
  3480. on: function messageHandlerOn(actionName, handler, scope) {
  3481. var ah = this.actionHandler;
  3482. if (ah[actionName]) {
  3483. error('There is already an actionName called "' + actionName + '"');
  3484. }
  3485. ah[actionName] = [handler, scope];
  3486. },
  3487. /**
  3488. * Sends a message to the comObj to invoke the action with the supplied data.
  3489. * @param {String} actionName Action to call.
  3490. * @param {JSON} data JSON data to send.
  3491. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3492. */
  3493. send: function messageHandlerSend(actionName, data, transfers) {
  3494. var message = {
  3495. sourceName: this.sourceName,
  3496. targetName: this.targetName,
  3497. action: actionName,
  3498. data: data
  3499. };
  3500. this.postMessage(message, transfers);
  3501. },
  3502. /**
  3503. * Sends a message to the comObj to invoke the action with the supplied data.
  3504. * Expects that other side will callback with the response.
  3505. * @param {String} actionName Action to call.
  3506. * @param {JSON} data JSON data to send.
  3507. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3508. * @returns {Promise} Promise to be resolved with response data.
  3509. */
  3510. sendWithPromise:
  3511. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3512. var callbackId = this.callbackIndex++;
  3513. var message = {
  3514. sourceName: this.sourceName,
  3515. targetName: this.targetName,
  3516. action: actionName,
  3517. data: data,
  3518. callbackId: callbackId
  3519. };
  3520. var capability = createPromiseCapability();
  3521. this.callbacksCapabilities[callbackId] = capability;
  3522. try {
  3523. this.postMessage(message, transfers);
  3524. } catch (e) {
  3525. capability.reject(e);
  3526. }
  3527. return capability.promise;
  3528. },
  3529. /**
  3530. * Sends raw message to the comObj.
  3531. * @private
  3532. * @param message {Object} Raw message.
  3533. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3534. */
  3535. postMessage: function (message, transfers) {
  3536. if (transfers && this.postMessageTransfers) {
  3537. this.comObj.postMessage(message, transfers);
  3538. } else {
  3539. this.comObj.postMessage(message);
  3540. }
  3541. },
  3542. destroy: function () {
  3543. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3544. }
  3545. };
  3546. function loadJpegStream(id, imageUrl, objs) {
  3547. var img = new Image();
  3548. img.onload = (function loadJpegStream_onloadClosure() {
  3549. objs.resolve(id, img);
  3550. });
  3551. img.onerror = (function loadJpegStream_onerrorClosure() {
  3552. objs.resolve(id, null);
  3553. warn('Error during JPEG image loading');
  3554. });
  3555. img.src = imageUrl;
  3556. }
  3557. // Polyfill from https://github.com/Polymer/URL
  3558. /* Any copyright is dedicated to the Public Domain.
  3559. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3560. (function checkURLConstructor(scope) {
  3561. /* jshint ignore:start */
  3562. // feature detect for URL constructor
  3563. var hasWorkingUrl = false;
  3564. try {
  3565. if (typeof URL === 'function' &&
  3566. typeof URL.prototype === 'object' &&
  3567. ('origin' in URL.prototype)) {
  3568. var u = new URL('b', 'http://a');
  3569. u.pathname = 'c%20d';
  3570. hasWorkingUrl = u.href === 'http://a/c%20d';
  3571. }
  3572. } catch(e) { }
  3573. if (hasWorkingUrl)
  3574. return;
  3575. var relative = Object.create(null);
  3576. relative['ftp'] = 21;
  3577. relative['file'] = 0;
  3578. relative['gopher'] = 70;
  3579. relative['http'] = 80;
  3580. relative['https'] = 443;
  3581. relative['ws'] = 80;
  3582. relative['wss'] = 443;
  3583. var relativePathDotMapping = Object.create(null);
  3584. relativePathDotMapping['%2e'] = '.';
  3585. relativePathDotMapping['.%2e'] = '..';
  3586. relativePathDotMapping['%2e.'] = '..';
  3587. relativePathDotMapping['%2e%2e'] = '..';
  3588. function isRelativeScheme(scheme) {
  3589. return relative[scheme] !== undefined;
  3590. }
  3591. function invalid() {
  3592. clear.call(this);
  3593. this._isInvalid = true;
  3594. }
  3595. function IDNAToASCII(h) {
  3596. if ('' == h) {
  3597. invalid.call(this)
  3598. }
  3599. // XXX
  3600. return h.toLowerCase()
  3601. }
  3602. function percentEscape(c) {
  3603. var unicode = c.charCodeAt(0);
  3604. if (unicode > 0x20 &&
  3605. unicode < 0x7F &&
  3606. // " # < > ? `
  3607. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3608. ) {
  3609. return c;
  3610. }
  3611. return encodeURIComponent(c);
  3612. }
  3613. function percentEscapeQuery(c) {
  3614. // XXX This actually needs to encode c using encoding and then
  3615. // convert the bytes one-by-one.
  3616. var unicode = c.charCodeAt(0);
  3617. if (unicode > 0x20 &&
  3618. unicode < 0x7F &&
  3619. // " # < > ` (do not escape '?')
  3620. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3621. ) {
  3622. return c;
  3623. }
  3624. return encodeURIComponent(c);
  3625. }
  3626. var EOF = undefined,
  3627. ALPHA = /[a-zA-Z]/,
  3628. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3629. function parse(input, stateOverride, base) {
  3630. function err(message) {
  3631. errors.push(message)
  3632. }
  3633. var state = stateOverride || 'scheme start',
  3634. cursor = 0,
  3635. buffer = '',
  3636. seenAt = false,
  3637. seenBracket = false,
  3638. errors = [];
  3639. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3640. var c = input[cursor];
  3641. switch (state) {
  3642. case 'scheme start':
  3643. if (c && ALPHA.test(c)) {
  3644. buffer += c.toLowerCase(); // ASCII-safe
  3645. state = 'scheme';
  3646. } else if (!stateOverride) {
  3647. buffer = '';
  3648. state = 'no scheme';
  3649. continue;
  3650. } else {
  3651. err('Invalid scheme.');
  3652. break loop;
  3653. }
  3654. break;
  3655. case 'scheme':
  3656. if (c && ALPHANUMERIC.test(c)) {
  3657. buffer += c.toLowerCase(); // ASCII-safe
  3658. } else if (':' == c) {
  3659. this._scheme = buffer;
  3660. buffer = '';
  3661. if (stateOverride) {
  3662. break loop;
  3663. }
  3664. if (isRelativeScheme(this._scheme)) {
  3665. this._isRelative = true;
  3666. }
  3667. if ('file' == this._scheme) {
  3668. state = 'relative';
  3669. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3670. state = 'relative or authority';
  3671. } else if (this._isRelative) {
  3672. state = 'authority first slash';
  3673. } else {
  3674. state = 'scheme data';
  3675. }
  3676. } else if (!stateOverride) {
  3677. buffer = '';
  3678. cursor = 0;
  3679. state = 'no scheme';
  3680. continue;
  3681. } else if (EOF == c) {
  3682. break loop;
  3683. } else {
  3684. err('Code point not allowed in scheme: ' + c)
  3685. break loop;
  3686. }
  3687. break;
  3688. case 'scheme data':
  3689. if ('?' == c) {
  3690. this._query = '?';
  3691. state = 'query';
  3692. } else if ('#' == c) {
  3693. this._fragment = '#';
  3694. state = 'fragment';
  3695. } else {
  3696. // XXX error handling
  3697. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3698. this._schemeData += percentEscape(c);
  3699. }
  3700. }
  3701. break;
  3702. case 'no scheme':
  3703. if (!base || !(isRelativeScheme(base._scheme))) {
  3704. err('Missing scheme.');
  3705. invalid.call(this);
  3706. } else {
  3707. state = 'relative';
  3708. continue;
  3709. }
  3710. break;
  3711. case 'relative or authority':
  3712. if ('/' == c && '/' == input[cursor+1]) {
  3713. state = 'authority ignore slashes';
  3714. } else {
  3715. err('Expected /, got: ' + c);
  3716. state = 'relative';
  3717. continue
  3718. }
  3719. break;
  3720. case 'relative':
  3721. this._isRelative = true;
  3722. if ('file' != this._scheme)
  3723. this._scheme = base._scheme;
  3724. if (EOF == c) {
  3725. this._host = base._host;
  3726. this._port = base._port;
  3727. this._path = base._path.slice();
  3728. this._query = base._query;
  3729. this._username = base._username;
  3730. this._password = base._password;
  3731. break loop;
  3732. } else if ('/' == c || '\\' == c) {
  3733. if ('\\' == c)
  3734. err('\\ is an invalid code point.');
  3735. state = 'relative slash';
  3736. } else if ('?' == c) {
  3737. this._host = base._host;
  3738. this._port = base._port;
  3739. this._path = base._path.slice();
  3740. this._query = '?';
  3741. this._username = base._username;
  3742. this._password = base._password;
  3743. state = 'query';
  3744. } else if ('#' == c) {
  3745. this._host = base._host;
  3746. this._port = base._port;
  3747. this._path = base._path.slice();
  3748. this._query = base._query;
  3749. this._fragment = '#';
  3750. this._username = base._username;
  3751. this._password = base._password;
  3752. state = 'fragment';
  3753. } else {
  3754. var nextC = input[cursor+1]
  3755. var nextNextC = input[cursor+2]
  3756. if (
  3757. 'file' != this._scheme || !ALPHA.test(c) ||
  3758. (nextC != ':' && nextC != '|') ||
  3759. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3760. this._host = base._host;
  3761. this._port = base._port;
  3762. this._username = base._username;
  3763. this._password = base._password;
  3764. this._path = base._path.slice();
  3765. this._path.pop();
  3766. }
  3767. state = 'relative path';
  3768. continue;
  3769. }
  3770. break;
  3771. case 'relative slash':
  3772. if ('/' == c || '\\' == c) {
  3773. if ('\\' == c) {
  3774. err('\\ is an invalid code point.');
  3775. }
  3776. if ('file' == this._scheme) {
  3777. state = 'file host';
  3778. } else {
  3779. state = 'authority ignore slashes';
  3780. }
  3781. } else {
  3782. if ('file' != this._scheme) {
  3783. this._host = base._host;
  3784. this._port = base._port;
  3785. this._username = base._username;
  3786. this._password = base._password;
  3787. }
  3788. state = 'relative path';
  3789. continue;
  3790. }
  3791. break;
  3792. case 'authority first slash':
  3793. if ('/' == c) {
  3794. state = 'authority second slash';
  3795. } else {
  3796. err("Expected '/', got: " + c);
  3797. state = 'authority ignore slashes';
  3798. continue;
  3799. }
  3800. break;
  3801. case 'authority second slash':
  3802. state = 'authority ignore slashes';
  3803. if ('/' != c) {
  3804. err("Expected '/', got: " + c);
  3805. continue;
  3806. }
  3807. break;
  3808. case 'authority ignore slashes':
  3809. if ('/' != c && '\\' != c) {
  3810. state = 'authority';
  3811. continue;
  3812. } else {
  3813. err('Expected authority, got: ' + c);
  3814. }
  3815. break;
  3816. case 'authority':
  3817. if ('@' == c) {
  3818. if (seenAt) {
  3819. err('@ already seen.');
  3820. buffer += '%40';
  3821. }
  3822. seenAt = true;
  3823. for (var i = 0; i < buffer.length; i++) {
  3824. var cp = buffer[i];
  3825. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3826. err('Invalid whitespace in authority.');
  3827. continue;
  3828. }
  3829. // XXX check URL code points
  3830. if (':' == cp && null === this._password) {
  3831. this._password = '';
  3832. continue;
  3833. }
  3834. var tempC = percentEscape(cp);
  3835. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3836. }
  3837. buffer = '';
  3838. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3839. cursor -= buffer.length;
  3840. buffer = '';
  3841. state = 'host';
  3842. continue;
  3843. } else {
  3844. buffer += c;
  3845. }
  3846. break;
  3847. case 'file host':
  3848. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3849. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  3850. state = 'relative path';
  3851. } else if (buffer.length == 0) {
  3852. state = 'relative path start';
  3853. } else {
  3854. this._host = IDNAToASCII.call(this, buffer);
  3855. buffer = '';
  3856. state = 'relative path start';
  3857. }
  3858. continue;
  3859. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3860. err('Invalid whitespace in file host.');
  3861. } else {
  3862. buffer += c;
  3863. }
  3864. break;
  3865. case 'host':
  3866. case 'hostname':
  3867. if (':' == c && !seenBracket) {
  3868. // XXX host parsing
  3869. this._host = IDNAToASCII.call(this, buffer);
  3870. buffer = '';
  3871. state = 'port';
  3872. if ('hostname' == stateOverride) {
  3873. break loop;
  3874. }
  3875. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3876. this._host = IDNAToASCII.call(this, buffer);
  3877. buffer = '';
  3878. state = 'relative path start';
  3879. if (stateOverride) {
  3880. break loop;
  3881. }
  3882. continue;
  3883. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3884. if ('[' == c) {
  3885. seenBracket = true;
  3886. } else if (']' == c) {
  3887. seenBracket = false;
  3888. }
  3889. buffer += c;
  3890. } else {
  3891. err('Invalid code point in host/hostname: ' + c);
  3892. }
  3893. break;
  3894. case 'port':
  3895. if (/[0-9]/.test(c)) {
  3896. buffer += c;
  3897. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  3898. if ('' != buffer) {
  3899. var temp = parseInt(buffer, 10);
  3900. if (temp != relative[this._scheme]) {
  3901. this._port = temp + '';
  3902. }
  3903. buffer = '';
  3904. }
  3905. if (stateOverride) {
  3906. break loop;
  3907. }
  3908. state = 'relative path start';
  3909. continue;
  3910. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3911. err('Invalid code point in port: ' + c);
  3912. } else {
  3913. invalid.call(this);
  3914. }
  3915. break;
  3916. case 'relative path start':
  3917. if ('\\' == c)
  3918. err("'\\' not allowed in path.");
  3919. state = 'relative path';
  3920. if ('/' != c && '\\' != c) {
  3921. continue;
  3922. }
  3923. break;
  3924. case 'relative path':
  3925. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  3926. if ('\\' == c) {
  3927. err('\\ not allowed in relative path.');
  3928. }
  3929. var tmp;
  3930. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  3931. buffer = tmp;
  3932. }
  3933. if ('..' == buffer) {
  3934. this._path.pop();
  3935. if ('/' != c && '\\' != c) {
  3936. this._path.push('');
  3937. }
  3938. } else if ('.' == buffer && '/' != c && '\\' != c) {
  3939. this._path.push('');
  3940. } else if ('.' != buffer) {
  3941. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  3942. buffer = buffer[0] + ':';
  3943. }
  3944. this._path.push(buffer);
  3945. }
  3946. buffer = '';
  3947. if ('?' == c) {
  3948. this._query = '?';
  3949. state = 'query';
  3950. } else if ('#' == c) {
  3951. this._fragment = '#';
  3952. state = 'fragment';
  3953. }
  3954. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3955. buffer += percentEscape(c);
  3956. }
  3957. break;
  3958. case 'query':
  3959. if (!stateOverride && '#' == c) {
  3960. this._fragment = '#';
  3961. state = 'fragment';
  3962. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3963. this._query += percentEscapeQuery(c);
  3964. }
  3965. break;
  3966. case 'fragment':
  3967. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3968. this._fragment += c;
  3969. }
  3970. break;
  3971. }
  3972. cursor++;
  3973. }
  3974. }
  3975. function clear() {
  3976. this._scheme = '';
  3977. this._schemeData = '';
  3978. this._username = '';
  3979. this._password = null;
  3980. this._host = '';
  3981. this._port = '';
  3982. this._path = [];
  3983. this._query = '';
  3984. this._fragment = '';
  3985. this._isInvalid = false;
  3986. this._isRelative = false;
  3987. }
  3988. // Does not process domain names or IP addresses.
  3989. // Does not handle encoding for the query parameter.
  3990. function jURL(url, base /* , encoding */) {
  3991. if (base !== undefined && !(base instanceof jURL))
  3992. base = new jURL(String(base));
  3993. this._url = url;
  3994. clear.call(this);
  3995. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  3996. // encoding = encoding || 'utf-8'
  3997. parse.call(this, input, null, base);
  3998. }
  3999. jURL.prototype = {
  4000. toString: function() {
  4001. return this.href;
  4002. },
  4003. get href() {
  4004. if (this._isInvalid)
  4005. return this._url;
  4006. var authority = '';
  4007. if ('' != this._username || null != this._password) {
  4008. authority = this._username +
  4009. (null != this._password ? ':' + this._password : '') + '@';
  4010. }
  4011. return this.protocol +
  4012. (this._isRelative ? '//' + authority + this.host : '') +
  4013. this.pathname + this._query + this._fragment;
  4014. },
  4015. set href(href) {
  4016. clear.call(this);
  4017. parse.call(this, href);
  4018. },
  4019. get protocol() {
  4020. return this._scheme + ':';
  4021. },
  4022. set protocol(protocol) {
  4023. if (this._isInvalid)
  4024. return;
  4025. parse.call(this, protocol + ':', 'scheme start');
  4026. },
  4027. get host() {
  4028. return this._isInvalid ? '' : this._port ?
  4029. this._host + ':' + this._port : this._host;
  4030. },
  4031. set host(host) {
  4032. if (this._isInvalid || !this._isRelative)
  4033. return;
  4034. parse.call(this, host, 'host');
  4035. },
  4036. get hostname() {
  4037. return this._host;
  4038. },
  4039. set hostname(hostname) {
  4040. if (this._isInvalid || !this._isRelative)
  4041. return;
  4042. parse.call(this, hostname, 'hostname');
  4043. },
  4044. get port() {
  4045. return this._port;
  4046. },
  4047. set port(port) {
  4048. if (this._isInvalid || !this._isRelative)
  4049. return;
  4050. parse.call(this, port, 'port');
  4051. },
  4052. get pathname() {
  4053. return this._isInvalid ? '' : this._isRelative ?
  4054. '/' + this._path.join('/') : this._schemeData;
  4055. },
  4056. set pathname(pathname) {
  4057. if (this._isInvalid || !this._isRelative)
  4058. return;
  4059. this._path = [];
  4060. parse.call(this, pathname, 'relative path start');
  4061. },
  4062. get search() {
  4063. return this._isInvalid || !this._query || '?' == this._query ?
  4064. '' : this._query;
  4065. },
  4066. set search(search) {
  4067. if (this._isInvalid || !this._isRelative)
  4068. return;
  4069. this._query = '?';
  4070. if ('?' == search[0])
  4071. search = search.slice(1);
  4072. parse.call(this, search, 'query');
  4073. },
  4074. get hash() {
  4075. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  4076. '' : this._fragment;
  4077. },
  4078. set hash(hash) {
  4079. if (this._isInvalid)
  4080. return;
  4081. this._fragment = '#';
  4082. if ('#' == hash[0])
  4083. hash = hash.slice(1);
  4084. parse.call(this, hash, 'fragment');
  4085. },
  4086. get origin() {
  4087. var host;
  4088. if (this._isInvalid || !this._scheme) {
  4089. return '';
  4090. }
  4091. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  4092. // Gecko throws error for "data://"
  4093. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  4094. // Gecko returns String("") for file: mailto:
  4095. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  4096. switch (this._scheme) {
  4097. case 'data':
  4098. case 'file':
  4099. case 'javascript':
  4100. case 'mailto':
  4101. return 'null';
  4102. }
  4103. host = this.host;
  4104. if (!host) {
  4105. return '';
  4106. }
  4107. return this._scheme + '://' + host;
  4108. }
  4109. };
  4110. // Copy over the static methods
  4111. var OriginalURL = scope.URL;
  4112. if (OriginalURL) {
  4113. jURL.createObjectURL = function(blob) {
  4114. // IE extension allows a second optional options argument.
  4115. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  4116. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  4117. };
  4118. jURL.revokeObjectURL = function(url) {
  4119. OriginalURL.revokeObjectURL(url);
  4120. };
  4121. }
  4122. scope.URL = jURL;
  4123. /* jshint ignore:end */
  4124. })(globalScope);
  4125. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  4126. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  4127. exports.OPS = OPS;
  4128. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  4129. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  4130. exports.AnnotationFlag = AnnotationFlag;
  4131. exports.AnnotationType = AnnotationType;
  4132. exports.FontType = FontType;
  4133. exports.ImageKind = ImageKind;
  4134. exports.InvalidPDFException = InvalidPDFException;
  4135. exports.LinkTarget = LinkTarget;
  4136. exports.LinkTargetStringMap = LinkTargetStringMap;
  4137. exports.MessageHandler = MessageHandler;
  4138. exports.MissingDataException = MissingDataException;
  4139. exports.MissingPDFException = MissingPDFException;
  4140. exports.NotImplementedException = NotImplementedException;
  4141. exports.PasswordException = PasswordException;
  4142. exports.PasswordResponses = PasswordResponses;
  4143. exports.StatTimer = StatTimer;
  4144. exports.StreamType = StreamType;
  4145. exports.TextRenderingMode = TextRenderingMode;
  4146. exports.UnexpectedResponseException = UnexpectedResponseException;
  4147. exports.UnknownErrorException = UnknownErrorException;
  4148. exports.Util = Util;
  4149. exports.XRefParseException = XRefParseException;
  4150. exports.arrayByteLength = arrayByteLength;
  4151. exports.arraysToBytes = arraysToBytes;
  4152. exports.assert = assert;
  4153. exports.bytesToString = bytesToString;
  4154. exports.combineUrl = combineUrl;
  4155. exports.createPromiseCapability = createPromiseCapability;
  4156. exports.deprecated = deprecated;
  4157. exports.error = error;
  4158. exports.getFilenameFromUrl = getFilenameFromUrl;
  4159. exports.getLookupTableFactory = getLookupTableFactory;
  4160. exports.info = info;
  4161. exports.isArray = isArray;
  4162. exports.isArrayBuffer = isArrayBuffer;
  4163. exports.isBool = isBool;
  4164. exports.isEmptyObj = isEmptyObj;
  4165. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  4166. exports.isInt = isInt;
  4167. exports.isNum = isNum;
  4168. exports.isString = isString;
  4169. exports.isSameOrigin = isSameOrigin;
  4170. exports.isValidUrl = isValidUrl;
  4171. exports.addLinkAttributes = addLinkAttributes;
  4172. exports.loadJpegStream = loadJpegStream;
  4173. exports.log2 = log2;
  4174. exports.readInt8 = readInt8;
  4175. exports.readUint16 = readUint16;
  4176. exports.readUint32 = readUint32;
  4177. exports.removeNullCharacters = removeNullCharacters;
  4178. exports.shadow = shadow;
  4179. exports.string32 = string32;
  4180. exports.stringToBytes = stringToBytes;
  4181. exports.stringToPDFString = stringToPDFString;
  4182. exports.stringToUTF8String = stringToUTF8String;
  4183. exports.utf8StringToString = utf8StringToString;
  4184. exports.warn = warn;
  4185. }));
  4186. (function (root, factory) {
  4187. {
  4188. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4189. }
  4190. }(this, function (exports, sharedUtil) {
  4191. var MissingDataException = sharedUtil.MissingDataException;
  4192. var arrayByteLength = sharedUtil.arrayByteLength;
  4193. var arraysToBytes = sharedUtil.arraysToBytes;
  4194. var assert = sharedUtil.assert;
  4195. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4196. var isInt = sharedUtil.isInt;
  4197. var isEmptyObj = sharedUtil.isEmptyObj;
  4198. var ChunkedStream = (function ChunkedStreamClosure() {
  4199. function ChunkedStream(length, chunkSize, manager) {
  4200. this.bytes = new Uint8Array(length);
  4201. this.start = 0;
  4202. this.pos = 0;
  4203. this.end = length;
  4204. this.chunkSize = chunkSize;
  4205. this.loadedChunks = [];
  4206. this.numChunksLoaded = 0;
  4207. this.numChunks = Math.ceil(length / chunkSize);
  4208. this.manager = manager;
  4209. this.progressiveDataLength = 0;
  4210. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4211. }
  4212. // required methods for a stream. if a particular stream does not
  4213. // implement these, an error should be thrown
  4214. ChunkedStream.prototype = {
  4215. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4216. var chunks = [];
  4217. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4218. if (!this.loadedChunks[chunk]) {
  4219. chunks.push(chunk);
  4220. }
  4221. }
  4222. return chunks;
  4223. },
  4224. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4225. return [this];
  4226. },
  4227. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4228. return this.numChunksLoaded === this.numChunks;
  4229. },
  4230. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4231. var end = begin + chunk.byteLength;
  4232. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4233. // Using this.length is inaccurate here since this.start can be moved
  4234. // See ChunkedStream.moveStart()
  4235. var length = this.bytes.length;
  4236. assert(end % this.chunkSize === 0 || end === length,
  4237. 'Bad end offset: ' + end);
  4238. this.bytes.set(new Uint8Array(chunk), begin);
  4239. var chunkSize = this.chunkSize;
  4240. var beginChunk = Math.floor(begin / chunkSize);
  4241. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4242. var curChunk;
  4243. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4244. if (!this.loadedChunks[curChunk]) {
  4245. this.loadedChunks[curChunk] = true;
  4246. ++this.numChunksLoaded;
  4247. }
  4248. }
  4249. },
  4250. onReceiveProgressiveData:
  4251. function ChunkedStream_onReceiveProgressiveData(data) {
  4252. var position = this.progressiveDataLength;
  4253. var beginChunk = Math.floor(position / this.chunkSize);
  4254. this.bytes.set(new Uint8Array(data), position);
  4255. position += data.byteLength;
  4256. this.progressiveDataLength = position;
  4257. var endChunk = position >= this.end ? this.numChunks :
  4258. Math.floor(position / this.chunkSize);
  4259. var curChunk;
  4260. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4261. if (!this.loadedChunks[curChunk]) {
  4262. this.loadedChunks[curChunk] = true;
  4263. ++this.numChunksLoaded;
  4264. }
  4265. }
  4266. },
  4267. ensureByte: function ChunkedStream_ensureByte(pos) {
  4268. var chunk = Math.floor(pos / this.chunkSize);
  4269. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4270. return;
  4271. }
  4272. if (!this.loadedChunks[chunk]) {
  4273. throw new MissingDataException(pos, pos + 1);
  4274. }
  4275. this.lastSuccessfulEnsureByteChunk = chunk;
  4276. },
  4277. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4278. if (begin >= end) {
  4279. return;
  4280. }
  4281. if (end <= this.progressiveDataLength) {
  4282. return;
  4283. }
  4284. var chunkSize = this.chunkSize;
  4285. var beginChunk = Math.floor(begin / chunkSize);
  4286. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4287. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4288. if (!this.loadedChunks[chunk]) {
  4289. throw new MissingDataException(begin, end);
  4290. }
  4291. }
  4292. },
  4293. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4294. var chunk, numChunks = this.numChunks;
  4295. for (var i = 0; i < numChunks; ++i) {
  4296. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4297. if (!this.loadedChunks[chunk]) {
  4298. return chunk;
  4299. }
  4300. }
  4301. return null;
  4302. },
  4303. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4304. return !!this.loadedChunks[chunk];
  4305. },
  4306. get length() {
  4307. return this.end - this.start;
  4308. },
  4309. get isEmpty() {
  4310. return this.length === 0;
  4311. },
  4312. getByte: function ChunkedStream_getByte() {
  4313. var pos = this.pos;
  4314. if (pos >= this.end) {
  4315. return -1;
  4316. }
  4317. this.ensureByte(pos);
  4318. return this.bytes[this.pos++];
  4319. },
  4320. getUint16: function ChunkedStream_getUint16() {
  4321. var b0 = this.getByte();
  4322. var b1 = this.getByte();
  4323. if (b0 === -1 || b1 === -1) {
  4324. return -1;
  4325. }
  4326. return (b0 << 8) + b1;
  4327. },
  4328. getInt32: function ChunkedStream_getInt32() {
  4329. var b0 = this.getByte();
  4330. var b1 = this.getByte();
  4331. var b2 = this.getByte();
  4332. var b3 = this.getByte();
  4333. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4334. },
  4335. // returns subarray of original buffer
  4336. // should only be read
  4337. getBytes: function ChunkedStream_getBytes(length) {
  4338. var bytes = this.bytes;
  4339. var pos = this.pos;
  4340. var strEnd = this.end;
  4341. if (!length) {
  4342. this.ensureRange(pos, strEnd);
  4343. return bytes.subarray(pos, strEnd);
  4344. }
  4345. var end = pos + length;
  4346. if (end > strEnd) {
  4347. end = strEnd;
  4348. }
  4349. this.ensureRange(pos, end);
  4350. this.pos = end;
  4351. return bytes.subarray(pos, end);
  4352. },
  4353. peekByte: function ChunkedStream_peekByte() {
  4354. var peekedByte = this.getByte();
  4355. this.pos--;
  4356. return peekedByte;
  4357. },
  4358. peekBytes: function ChunkedStream_peekBytes(length) {
  4359. var bytes = this.getBytes(length);
  4360. this.pos -= bytes.length;
  4361. return bytes;
  4362. },
  4363. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4364. this.ensureRange(begin, end);
  4365. return this.bytes.subarray(begin, end);
  4366. },
  4367. skip: function ChunkedStream_skip(n) {
  4368. if (!n) {
  4369. n = 1;
  4370. }
  4371. this.pos += n;
  4372. },
  4373. reset: function ChunkedStream_reset() {
  4374. this.pos = this.start;
  4375. },
  4376. moveStart: function ChunkedStream_moveStart() {
  4377. this.start = this.pos;
  4378. },
  4379. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4380. this.ensureRange(start, start + length);
  4381. function ChunkedStreamSubstream() {}
  4382. ChunkedStreamSubstream.prototype = Object.create(this);
  4383. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4384. var chunkSize = this.chunkSize;
  4385. var beginChunk = Math.floor(this.start / chunkSize);
  4386. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4387. var missingChunks = [];
  4388. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4389. if (!this.loadedChunks[chunk]) {
  4390. missingChunks.push(chunk);
  4391. }
  4392. }
  4393. return missingChunks;
  4394. };
  4395. var subStream = new ChunkedStreamSubstream();
  4396. subStream.pos = subStream.start = start;
  4397. subStream.end = start + length || this.end;
  4398. subStream.dict = dict;
  4399. return subStream;
  4400. },
  4401. isStream: true
  4402. };
  4403. return ChunkedStream;
  4404. })();
  4405. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4406. function ChunkedStreamManager(pdfNetworkStream, args) {
  4407. var chunkSize = args.rangeChunkSize;
  4408. var length = args.length;
  4409. this.stream = new ChunkedStream(length, chunkSize, this);
  4410. this.length = length;
  4411. this.chunkSize = chunkSize;
  4412. this.pdfNetworkStream = pdfNetworkStream;
  4413. this.url = args.url;
  4414. this.disableAutoFetch = args.disableAutoFetch;
  4415. this.msgHandler = args.msgHandler;
  4416. this.currRequestId = 0;
  4417. this.chunksNeededByRequest = Object.create(null);
  4418. this.requestsByChunk = Object.create(null);
  4419. this.promisesByRequest = Object.create(null);
  4420. this.progressiveDataLength = 0;
  4421. this.aborted = false;
  4422. this._loadedStreamCapability = createPromiseCapability();
  4423. }
  4424. ChunkedStreamManager.prototype = {
  4425. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4426. return this._loadedStreamCapability.promise;
  4427. },
  4428. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  4429. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  4430. if (!rangeReader.isStreamingSupported) {
  4431. rangeReader.onProgress = this.onProgress.bind(this);
  4432. }
  4433. var chunks = [], loaded = 0;
  4434. var manager = this;
  4435. var promise = new Promise(function (resolve, reject) {
  4436. var readChunk = function (chunk) {
  4437. try {
  4438. if (!chunk.done) {
  4439. var data = chunk.value;
  4440. chunks.push(data);
  4441. loaded += arrayByteLength(data);
  4442. if (rangeReader.isStreamingSupported) {
  4443. manager.onProgress({loaded: loaded});
  4444. }
  4445. rangeReader.read().then(readChunk, reject);
  4446. return;
  4447. }
  4448. var chunkData = arraysToBytes(chunks);
  4449. chunks = null;
  4450. resolve(chunkData);
  4451. } catch (e) {
  4452. reject(e);
  4453. }
  4454. };
  4455. rangeReader.read().then(readChunk, reject);
  4456. });
  4457. promise.then(function (data) {
  4458. if (this.aborted) {
  4459. return; // ignoring any data after abort
  4460. }
  4461. this.onReceiveData({chunk: data, begin: begin});
  4462. }.bind(this));
  4463. // TODO check errors
  4464. },
  4465. // Get all the chunks that are not yet loaded and groups them into
  4466. // contiguous ranges to load in as few requests as possible
  4467. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4468. var missingChunks = this.stream.getMissingChunks();
  4469. this._requestChunks(missingChunks);
  4470. return this._loadedStreamCapability.promise;
  4471. },
  4472. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4473. var requestId = this.currRequestId++;
  4474. var i, ii;
  4475. var chunksNeeded = Object.create(null);
  4476. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4477. for (i = 0, ii = chunks.length; i < ii; i++) {
  4478. if (!this.stream.hasChunk(chunks[i])) {
  4479. chunksNeeded[chunks[i]] = true;
  4480. }
  4481. }
  4482. if (isEmptyObj(chunksNeeded)) {
  4483. return Promise.resolve();
  4484. }
  4485. var capability = createPromiseCapability();
  4486. this.promisesByRequest[requestId] = capability;
  4487. var chunksToRequest = [];
  4488. for (var chunk in chunksNeeded) {
  4489. chunk = chunk | 0;
  4490. if (!(chunk in this.requestsByChunk)) {
  4491. this.requestsByChunk[chunk] = [];
  4492. chunksToRequest.push(chunk);
  4493. }
  4494. this.requestsByChunk[chunk].push(requestId);
  4495. }
  4496. if (!chunksToRequest.length) {
  4497. return capability.promise;
  4498. }
  4499. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  4500. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  4501. var groupedChunk = groupedChunksToRequest[i];
  4502. var begin = groupedChunk.beginChunk * this.chunkSize;
  4503. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  4504. this.sendRequest(begin, end);
  4505. }
  4506. return capability.promise;
  4507. },
  4508. getStream: function ChunkedStreamManager_getStream() {
  4509. return this.stream;
  4510. },
  4511. // Loads any chunks in the requested range that are not yet loaded
  4512. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  4513. end = Math.min(end, this.length);
  4514. var beginChunk = this.getBeginChunk(begin);
  4515. var endChunk = this.getEndChunk(end);
  4516. var chunks = [];
  4517. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4518. chunks.push(chunk);
  4519. }
  4520. return this._requestChunks(chunks);
  4521. },
  4522. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  4523. ranges = ranges || [];
  4524. var chunksToRequest = [];
  4525. for (var i = 0; i < ranges.length; i++) {
  4526. var beginChunk = this.getBeginChunk(ranges[i].begin);
  4527. var endChunk = this.getEndChunk(ranges[i].end);
  4528. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4529. if (chunksToRequest.indexOf(chunk) < 0) {
  4530. chunksToRequest.push(chunk);
  4531. }
  4532. }
  4533. }
  4534. chunksToRequest.sort(function(a, b) { return a - b; });
  4535. return this._requestChunks(chunksToRequest);
  4536. },
  4537. // Groups a sorted array of chunks into as few contiguous larger
  4538. // chunks as possible
  4539. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  4540. var groupedChunks = [];
  4541. var beginChunk = -1;
  4542. var prevChunk = -1;
  4543. for (var i = 0; i < chunks.length; ++i) {
  4544. var chunk = chunks[i];
  4545. if (beginChunk < 0) {
  4546. beginChunk = chunk;
  4547. }
  4548. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  4549. groupedChunks.push({ beginChunk: beginChunk,
  4550. endChunk: prevChunk + 1 });
  4551. beginChunk = chunk;
  4552. }
  4553. if (i + 1 === chunks.length) {
  4554. groupedChunks.push({ beginChunk: beginChunk,
  4555. endChunk: chunk + 1 });
  4556. }
  4557. prevChunk = chunk;
  4558. }
  4559. return groupedChunks;
  4560. },
  4561. onProgress: function ChunkedStreamManager_onProgress(args) {
  4562. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  4563. args.loaded);
  4564. this.msgHandler.send('DocProgress', {
  4565. loaded: bytesLoaded,
  4566. total: this.length
  4567. });
  4568. },
  4569. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  4570. var chunk = args.chunk;
  4571. var isProgressive = args.begin === undefined;
  4572. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  4573. var end = begin + chunk.byteLength;
  4574. var beginChunk = Math.floor(begin / this.chunkSize);
  4575. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  4576. Math.ceil(end / this.chunkSize);
  4577. if (isProgressive) {
  4578. this.stream.onReceiveProgressiveData(chunk);
  4579. this.progressiveDataLength = end;
  4580. } else {
  4581. this.stream.onReceiveData(begin, chunk);
  4582. }
  4583. if (this.stream.allChunksLoaded()) {
  4584. this._loadedStreamCapability.resolve(this.stream);
  4585. }
  4586. var loadedRequests = [];
  4587. var i, requestId;
  4588. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  4589. // The server might return more chunks than requested
  4590. var requestIds = this.requestsByChunk[chunk] || [];
  4591. delete this.requestsByChunk[chunk];
  4592. for (i = 0; i < requestIds.length; ++i) {
  4593. requestId = requestIds[i];
  4594. var chunksNeeded = this.chunksNeededByRequest[requestId];
  4595. if (chunk in chunksNeeded) {
  4596. delete chunksNeeded[chunk];
  4597. }
  4598. if (!isEmptyObj(chunksNeeded)) {
  4599. continue;
  4600. }
  4601. loadedRequests.push(requestId);
  4602. }
  4603. }
  4604. // If there are no pending requests, automatically fetch the next
  4605. // unfetched chunk of the PDF
  4606. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  4607. var nextEmptyChunk;
  4608. if (this.stream.numChunksLoaded === 1) {
  4609. // This is a special optimization so that after fetching the first
  4610. // chunk, rather than fetching the second chunk, we fetch the last
  4611. // chunk.
  4612. var lastChunk = this.stream.numChunks - 1;
  4613. if (!this.stream.hasChunk(lastChunk)) {
  4614. nextEmptyChunk = lastChunk;
  4615. }
  4616. } else {
  4617. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  4618. }
  4619. if (isInt(nextEmptyChunk)) {
  4620. this._requestChunks([nextEmptyChunk]);
  4621. }
  4622. }
  4623. for (i = 0; i < loadedRequests.length; ++i) {
  4624. requestId = loadedRequests[i];
  4625. var capability = this.promisesByRequest[requestId];
  4626. delete this.promisesByRequest[requestId];
  4627. capability.resolve();
  4628. }
  4629. this.msgHandler.send('DocProgress', {
  4630. loaded: this.stream.numChunksLoaded * this.chunkSize,
  4631. total: this.length
  4632. });
  4633. },
  4634. onError: function ChunkedStreamManager_onError(err) {
  4635. this._loadedStreamCapability.reject(err);
  4636. },
  4637. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  4638. var chunk = Math.floor(begin / this.chunkSize);
  4639. return chunk;
  4640. },
  4641. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  4642. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  4643. return chunk;
  4644. },
  4645. abort: function ChunkedStreamManager_abort() {
  4646. this.aborted = true;
  4647. if (this.pdfNetworkStream) {
  4648. this.pdfNetworkStream.cancelAllRequests('abort');
  4649. }
  4650. for(var requestId in this.promisesByRequest) {
  4651. var capability = this.promisesByRequest[requestId];
  4652. capability.reject(new Error('Request was aborted'));
  4653. }
  4654. }
  4655. };
  4656. return ChunkedStreamManager;
  4657. })();
  4658. exports.ChunkedStream = ChunkedStream;
  4659. exports.ChunkedStreamManager = ChunkedStreamManager;
  4660. }));
  4661. (function (root, factory) {
  4662. {
  4663. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  4664. }
  4665. }(this, function (exports, sharedUtil) {
  4666. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  4667. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  4668. t['A'] = 0x0041;
  4669. t['AE'] = 0x00C6;
  4670. t['AEacute'] = 0x01FC;
  4671. t['AEmacron'] = 0x01E2;
  4672. t['AEsmall'] = 0xF7E6;
  4673. t['Aacute'] = 0x00C1;
  4674. t['Aacutesmall'] = 0xF7E1;
  4675. t['Abreve'] = 0x0102;
  4676. t['Abreveacute'] = 0x1EAE;
  4677. t['Abrevecyrillic'] = 0x04D0;
  4678. t['Abrevedotbelow'] = 0x1EB6;
  4679. t['Abrevegrave'] = 0x1EB0;
  4680. t['Abrevehookabove'] = 0x1EB2;
  4681. t['Abrevetilde'] = 0x1EB4;
  4682. t['Acaron'] = 0x01CD;
  4683. t['Acircle'] = 0x24B6;
  4684. t['Acircumflex'] = 0x00C2;
  4685. t['Acircumflexacute'] = 0x1EA4;
  4686. t['Acircumflexdotbelow'] = 0x1EAC;
  4687. t['Acircumflexgrave'] = 0x1EA6;
  4688. t['Acircumflexhookabove'] = 0x1EA8;
  4689. t['Acircumflexsmall'] = 0xF7E2;
  4690. t['Acircumflextilde'] = 0x1EAA;
  4691. t['Acute'] = 0xF6C9;
  4692. t['Acutesmall'] = 0xF7B4;
  4693. t['Acyrillic'] = 0x0410;
  4694. t['Adblgrave'] = 0x0200;
  4695. t['Adieresis'] = 0x00C4;
  4696. t['Adieresiscyrillic'] = 0x04D2;
  4697. t['Adieresismacron'] = 0x01DE;
  4698. t['Adieresissmall'] = 0xF7E4;
  4699. t['Adotbelow'] = 0x1EA0;
  4700. t['Adotmacron'] = 0x01E0;
  4701. t['Agrave'] = 0x00C0;
  4702. t['Agravesmall'] = 0xF7E0;
  4703. t['Ahookabove'] = 0x1EA2;
  4704. t['Aiecyrillic'] = 0x04D4;
  4705. t['Ainvertedbreve'] = 0x0202;
  4706. t['Alpha'] = 0x0391;
  4707. t['Alphatonos'] = 0x0386;
  4708. t['Amacron'] = 0x0100;
  4709. t['Amonospace'] = 0xFF21;
  4710. t['Aogonek'] = 0x0104;
  4711. t['Aring'] = 0x00C5;
  4712. t['Aringacute'] = 0x01FA;
  4713. t['Aringbelow'] = 0x1E00;
  4714. t['Aringsmall'] = 0xF7E5;
  4715. t['Asmall'] = 0xF761;
  4716. t['Atilde'] = 0x00C3;
  4717. t['Atildesmall'] = 0xF7E3;
  4718. t['Aybarmenian'] = 0x0531;
  4719. t['B'] = 0x0042;
  4720. t['Bcircle'] = 0x24B7;
  4721. t['Bdotaccent'] = 0x1E02;
  4722. t['Bdotbelow'] = 0x1E04;
  4723. t['Becyrillic'] = 0x0411;
  4724. t['Benarmenian'] = 0x0532;
  4725. t['Beta'] = 0x0392;
  4726. t['Bhook'] = 0x0181;
  4727. t['Blinebelow'] = 0x1E06;
  4728. t['Bmonospace'] = 0xFF22;
  4729. t['Brevesmall'] = 0xF6F4;
  4730. t['Bsmall'] = 0xF762;
  4731. t['Btopbar'] = 0x0182;
  4732. t['C'] = 0x0043;
  4733. t['Caarmenian'] = 0x053E;
  4734. t['Cacute'] = 0x0106;
  4735. t['Caron'] = 0xF6CA;
  4736. t['Caronsmall'] = 0xF6F5;
  4737. t['Ccaron'] = 0x010C;
  4738. t['Ccedilla'] = 0x00C7;
  4739. t['Ccedillaacute'] = 0x1E08;
  4740. t['Ccedillasmall'] = 0xF7E7;
  4741. t['Ccircle'] = 0x24B8;
  4742. t['Ccircumflex'] = 0x0108;
  4743. t['Cdot'] = 0x010A;
  4744. t['Cdotaccent'] = 0x010A;
  4745. t['Cedillasmall'] = 0xF7B8;
  4746. t['Chaarmenian'] = 0x0549;
  4747. t['Cheabkhasiancyrillic'] = 0x04BC;
  4748. t['Checyrillic'] = 0x0427;
  4749. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  4750. t['Chedescendercyrillic'] = 0x04B6;
  4751. t['Chedieresiscyrillic'] = 0x04F4;
  4752. t['Cheharmenian'] = 0x0543;
  4753. t['Chekhakassiancyrillic'] = 0x04CB;
  4754. t['Cheverticalstrokecyrillic'] = 0x04B8;
  4755. t['Chi'] = 0x03A7;
  4756. t['Chook'] = 0x0187;
  4757. t['Circumflexsmall'] = 0xF6F6;
  4758. t['Cmonospace'] = 0xFF23;
  4759. t['Coarmenian'] = 0x0551;
  4760. t['Csmall'] = 0xF763;
  4761. t['D'] = 0x0044;
  4762. t['DZ'] = 0x01F1;
  4763. t['DZcaron'] = 0x01C4;
  4764. t['Daarmenian'] = 0x0534;
  4765. t['Dafrican'] = 0x0189;
  4766. t['Dcaron'] = 0x010E;
  4767. t['Dcedilla'] = 0x1E10;
  4768. t['Dcircle'] = 0x24B9;
  4769. t['Dcircumflexbelow'] = 0x1E12;
  4770. t['Dcroat'] = 0x0110;
  4771. t['Ddotaccent'] = 0x1E0A;
  4772. t['Ddotbelow'] = 0x1E0C;
  4773. t['Decyrillic'] = 0x0414;
  4774. t['Deicoptic'] = 0x03EE;
  4775. t['Delta'] = 0x2206;
  4776. t['Deltagreek'] = 0x0394;
  4777. t['Dhook'] = 0x018A;
  4778. t['Dieresis'] = 0xF6CB;
  4779. t['DieresisAcute'] = 0xF6CC;
  4780. t['DieresisGrave'] = 0xF6CD;
  4781. t['Dieresissmall'] = 0xF7A8;
  4782. t['Digammagreek'] = 0x03DC;
  4783. t['Djecyrillic'] = 0x0402;
  4784. t['Dlinebelow'] = 0x1E0E;
  4785. t['Dmonospace'] = 0xFF24;
  4786. t['Dotaccentsmall'] = 0xF6F7;
  4787. t['Dslash'] = 0x0110;
  4788. t['Dsmall'] = 0xF764;
  4789. t['Dtopbar'] = 0x018B;
  4790. t['Dz'] = 0x01F2;
  4791. t['Dzcaron'] = 0x01C5;
  4792. t['Dzeabkhasiancyrillic'] = 0x04E0;
  4793. t['Dzecyrillic'] = 0x0405;
  4794. t['Dzhecyrillic'] = 0x040F;
  4795. t['E'] = 0x0045;
  4796. t['Eacute'] = 0x00C9;
  4797. t['Eacutesmall'] = 0xF7E9;
  4798. t['Ebreve'] = 0x0114;
  4799. t['Ecaron'] = 0x011A;
  4800. t['Ecedillabreve'] = 0x1E1C;
  4801. t['Echarmenian'] = 0x0535;
  4802. t['Ecircle'] = 0x24BA;
  4803. t['Ecircumflex'] = 0x00CA;
  4804. t['Ecircumflexacute'] = 0x1EBE;
  4805. t['Ecircumflexbelow'] = 0x1E18;
  4806. t['Ecircumflexdotbelow'] = 0x1EC6;
  4807. t['Ecircumflexgrave'] = 0x1EC0;
  4808. t['Ecircumflexhookabove'] = 0x1EC2;
  4809. t['Ecircumflexsmall'] = 0xF7EA;
  4810. t['Ecircumflextilde'] = 0x1EC4;
  4811. t['Ecyrillic'] = 0x0404;
  4812. t['Edblgrave'] = 0x0204;
  4813. t['Edieresis'] = 0x00CB;
  4814. t['Edieresissmall'] = 0xF7EB;
  4815. t['Edot'] = 0x0116;
  4816. t['Edotaccent'] = 0x0116;
  4817. t['Edotbelow'] = 0x1EB8;
  4818. t['Efcyrillic'] = 0x0424;
  4819. t['Egrave'] = 0x00C8;
  4820. t['Egravesmall'] = 0xF7E8;
  4821. t['Eharmenian'] = 0x0537;
  4822. t['Ehookabove'] = 0x1EBA;
  4823. t['Eightroman'] = 0x2167;
  4824. t['Einvertedbreve'] = 0x0206;
  4825. t['Eiotifiedcyrillic'] = 0x0464;
  4826. t['Elcyrillic'] = 0x041B;
  4827. t['Elevenroman'] = 0x216A;
  4828. t['Emacron'] = 0x0112;
  4829. t['Emacronacute'] = 0x1E16;
  4830. t['Emacrongrave'] = 0x1E14;
  4831. t['Emcyrillic'] = 0x041C;
  4832. t['Emonospace'] = 0xFF25;
  4833. t['Encyrillic'] = 0x041D;
  4834. t['Endescendercyrillic'] = 0x04A2;
  4835. t['Eng'] = 0x014A;
  4836. t['Enghecyrillic'] = 0x04A4;
  4837. t['Enhookcyrillic'] = 0x04C7;
  4838. t['Eogonek'] = 0x0118;
  4839. t['Eopen'] = 0x0190;
  4840. t['Epsilon'] = 0x0395;
  4841. t['Epsilontonos'] = 0x0388;
  4842. t['Ercyrillic'] = 0x0420;
  4843. t['Ereversed'] = 0x018E;
  4844. t['Ereversedcyrillic'] = 0x042D;
  4845. t['Escyrillic'] = 0x0421;
  4846. t['Esdescendercyrillic'] = 0x04AA;
  4847. t['Esh'] = 0x01A9;
  4848. t['Esmall'] = 0xF765;
  4849. t['Eta'] = 0x0397;
  4850. t['Etarmenian'] = 0x0538;
  4851. t['Etatonos'] = 0x0389;
  4852. t['Eth'] = 0x00D0;
  4853. t['Ethsmall'] = 0xF7F0;
  4854. t['Etilde'] = 0x1EBC;
  4855. t['Etildebelow'] = 0x1E1A;
  4856. t['Euro'] = 0x20AC;
  4857. t['Ezh'] = 0x01B7;
  4858. t['Ezhcaron'] = 0x01EE;
  4859. t['Ezhreversed'] = 0x01B8;
  4860. t['F'] = 0x0046;
  4861. t['Fcircle'] = 0x24BB;
  4862. t['Fdotaccent'] = 0x1E1E;
  4863. t['Feharmenian'] = 0x0556;
  4864. t['Feicoptic'] = 0x03E4;
  4865. t['Fhook'] = 0x0191;
  4866. t['Fitacyrillic'] = 0x0472;
  4867. t['Fiveroman'] = 0x2164;
  4868. t['Fmonospace'] = 0xFF26;
  4869. t['Fourroman'] = 0x2163;
  4870. t['Fsmall'] = 0xF766;
  4871. t['G'] = 0x0047;
  4872. t['GBsquare'] = 0x3387;
  4873. t['Gacute'] = 0x01F4;
  4874. t['Gamma'] = 0x0393;
  4875. t['Gammaafrican'] = 0x0194;
  4876. t['Gangiacoptic'] = 0x03EA;
  4877. t['Gbreve'] = 0x011E;
  4878. t['Gcaron'] = 0x01E6;
  4879. t['Gcedilla'] = 0x0122;
  4880. t['Gcircle'] = 0x24BC;
  4881. t['Gcircumflex'] = 0x011C;
  4882. t['Gcommaaccent'] = 0x0122;
  4883. t['Gdot'] = 0x0120;
  4884. t['Gdotaccent'] = 0x0120;
  4885. t['Gecyrillic'] = 0x0413;
  4886. t['Ghadarmenian'] = 0x0542;
  4887. t['Ghemiddlehookcyrillic'] = 0x0494;
  4888. t['Ghestrokecyrillic'] = 0x0492;
  4889. t['Gheupturncyrillic'] = 0x0490;
  4890. t['Ghook'] = 0x0193;
  4891. t['Gimarmenian'] = 0x0533;
  4892. t['Gjecyrillic'] = 0x0403;
  4893. t['Gmacron'] = 0x1E20;
  4894. t['Gmonospace'] = 0xFF27;
  4895. t['Grave'] = 0xF6CE;
  4896. t['Gravesmall'] = 0xF760;
  4897. t['Gsmall'] = 0xF767;
  4898. t['Gsmallhook'] = 0x029B;
  4899. t['Gstroke'] = 0x01E4;
  4900. t['H'] = 0x0048;
  4901. t['H18533'] = 0x25CF;
  4902. t['H18543'] = 0x25AA;
  4903. t['H18551'] = 0x25AB;
  4904. t['H22073'] = 0x25A1;
  4905. t['HPsquare'] = 0x33CB;
  4906. t['Haabkhasiancyrillic'] = 0x04A8;
  4907. t['Hadescendercyrillic'] = 0x04B2;
  4908. t['Hardsigncyrillic'] = 0x042A;
  4909. t['Hbar'] = 0x0126;
  4910. t['Hbrevebelow'] = 0x1E2A;
  4911. t['Hcedilla'] = 0x1E28;
  4912. t['Hcircle'] = 0x24BD;
  4913. t['Hcircumflex'] = 0x0124;
  4914. t['Hdieresis'] = 0x1E26;
  4915. t['Hdotaccent'] = 0x1E22;
  4916. t['Hdotbelow'] = 0x1E24;
  4917. t['Hmonospace'] = 0xFF28;
  4918. t['Hoarmenian'] = 0x0540;
  4919. t['Horicoptic'] = 0x03E8;
  4920. t['Hsmall'] = 0xF768;
  4921. t['Hungarumlaut'] = 0xF6CF;
  4922. t['Hungarumlautsmall'] = 0xF6F8;
  4923. t['Hzsquare'] = 0x3390;
  4924. t['I'] = 0x0049;
  4925. t['IAcyrillic'] = 0x042F;
  4926. t['IJ'] = 0x0132;
  4927. t['IUcyrillic'] = 0x042E;
  4928. t['Iacute'] = 0x00CD;
  4929. t['Iacutesmall'] = 0xF7ED;
  4930. t['Ibreve'] = 0x012C;
  4931. t['Icaron'] = 0x01CF;
  4932. t['Icircle'] = 0x24BE;
  4933. t['Icircumflex'] = 0x00CE;
  4934. t['Icircumflexsmall'] = 0xF7EE;
  4935. t['Icyrillic'] = 0x0406;
  4936. t['Idblgrave'] = 0x0208;
  4937. t['Idieresis'] = 0x00CF;
  4938. t['Idieresisacute'] = 0x1E2E;
  4939. t['Idieresiscyrillic'] = 0x04E4;
  4940. t['Idieresissmall'] = 0xF7EF;
  4941. t['Idot'] = 0x0130;
  4942. t['Idotaccent'] = 0x0130;
  4943. t['Idotbelow'] = 0x1ECA;
  4944. t['Iebrevecyrillic'] = 0x04D6;
  4945. t['Iecyrillic'] = 0x0415;
  4946. t['Ifraktur'] = 0x2111;
  4947. t['Igrave'] = 0x00CC;
  4948. t['Igravesmall'] = 0xF7EC;
  4949. t['Ihookabove'] = 0x1EC8;
  4950. t['Iicyrillic'] = 0x0418;
  4951. t['Iinvertedbreve'] = 0x020A;
  4952. t['Iishortcyrillic'] = 0x0419;
  4953. t['Imacron'] = 0x012A;
  4954. t['Imacroncyrillic'] = 0x04E2;
  4955. t['Imonospace'] = 0xFF29;
  4956. t['Iniarmenian'] = 0x053B;
  4957. t['Iocyrillic'] = 0x0401;
  4958. t['Iogonek'] = 0x012E;
  4959. t['Iota'] = 0x0399;
  4960. t['Iotaafrican'] = 0x0196;
  4961. t['Iotadieresis'] = 0x03AA;
  4962. t['Iotatonos'] = 0x038A;
  4963. t['Ismall'] = 0xF769;
  4964. t['Istroke'] = 0x0197;
  4965. t['Itilde'] = 0x0128;
  4966. t['Itildebelow'] = 0x1E2C;
  4967. t['Izhitsacyrillic'] = 0x0474;
  4968. t['Izhitsadblgravecyrillic'] = 0x0476;
  4969. t['J'] = 0x004A;
  4970. t['Jaarmenian'] = 0x0541;
  4971. t['Jcircle'] = 0x24BF;
  4972. t['Jcircumflex'] = 0x0134;
  4973. t['Jecyrillic'] = 0x0408;
  4974. t['Jheharmenian'] = 0x054B;
  4975. t['Jmonospace'] = 0xFF2A;
  4976. t['Jsmall'] = 0xF76A;
  4977. t['K'] = 0x004B;
  4978. t['KBsquare'] = 0x3385;
  4979. t['KKsquare'] = 0x33CD;
  4980. t['Kabashkircyrillic'] = 0x04A0;
  4981. t['Kacute'] = 0x1E30;
  4982. t['Kacyrillic'] = 0x041A;
  4983. t['Kadescendercyrillic'] = 0x049A;
  4984. t['Kahookcyrillic'] = 0x04C3;
  4985. t['Kappa'] = 0x039A;
  4986. t['Kastrokecyrillic'] = 0x049E;
  4987. t['Kaverticalstrokecyrillic'] = 0x049C;
  4988. t['Kcaron'] = 0x01E8;
  4989. t['Kcedilla'] = 0x0136;
  4990. t['Kcircle'] = 0x24C0;
  4991. t['Kcommaaccent'] = 0x0136;
  4992. t['Kdotbelow'] = 0x1E32;
  4993. t['Keharmenian'] = 0x0554;
  4994. t['Kenarmenian'] = 0x053F;
  4995. t['Khacyrillic'] = 0x0425;
  4996. t['Kheicoptic'] = 0x03E6;
  4997. t['Khook'] = 0x0198;
  4998. t['Kjecyrillic'] = 0x040C;
  4999. t['Klinebelow'] = 0x1E34;
  5000. t['Kmonospace'] = 0xFF2B;
  5001. t['Koppacyrillic'] = 0x0480;
  5002. t['Koppagreek'] = 0x03DE;
  5003. t['Ksicyrillic'] = 0x046E;
  5004. t['Ksmall'] = 0xF76B;
  5005. t['L'] = 0x004C;
  5006. t['LJ'] = 0x01C7;
  5007. t['LL'] = 0xF6BF;
  5008. t['Lacute'] = 0x0139;
  5009. t['Lambda'] = 0x039B;
  5010. t['Lcaron'] = 0x013D;
  5011. t['Lcedilla'] = 0x013B;
  5012. t['Lcircle'] = 0x24C1;
  5013. t['Lcircumflexbelow'] = 0x1E3C;
  5014. t['Lcommaaccent'] = 0x013B;
  5015. t['Ldot'] = 0x013F;
  5016. t['Ldotaccent'] = 0x013F;
  5017. t['Ldotbelow'] = 0x1E36;
  5018. t['Ldotbelowmacron'] = 0x1E38;
  5019. t['Liwnarmenian'] = 0x053C;
  5020. t['Lj'] = 0x01C8;
  5021. t['Ljecyrillic'] = 0x0409;
  5022. t['Llinebelow'] = 0x1E3A;
  5023. t['Lmonospace'] = 0xFF2C;
  5024. t['Lslash'] = 0x0141;
  5025. t['Lslashsmall'] = 0xF6F9;
  5026. t['Lsmall'] = 0xF76C;
  5027. t['M'] = 0x004D;
  5028. t['MBsquare'] = 0x3386;
  5029. t['Macron'] = 0xF6D0;
  5030. t['Macronsmall'] = 0xF7AF;
  5031. t['Macute'] = 0x1E3E;
  5032. t['Mcircle'] = 0x24C2;
  5033. t['Mdotaccent'] = 0x1E40;
  5034. t['Mdotbelow'] = 0x1E42;
  5035. t['Menarmenian'] = 0x0544;
  5036. t['Mmonospace'] = 0xFF2D;
  5037. t['Msmall'] = 0xF76D;
  5038. t['Mturned'] = 0x019C;
  5039. t['Mu'] = 0x039C;
  5040. t['N'] = 0x004E;
  5041. t['NJ'] = 0x01CA;
  5042. t['Nacute'] = 0x0143;
  5043. t['Ncaron'] = 0x0147;
  5044. t['Ncedilla'] = 0x0145;
  5045. t['Ncircle'] = 0x24C3;
  5046. t['Ncircumflexbelow'] = 0x1E4A;
  5047. t['Ncommaaccent'] = 0x0145;
  5048. t['Ndotaccent'] = 0x1E44;
  5049. t['Ndotbelow'] = 0x1E46;
  5050. t['Nhookleft'] = 0x019D;
  5051. t['Nineroman'] = 0x2168;
  5052. t['Nj'] = 0x01CB;
  5053. t['Njecyrillic'] = 0x040A;
  5054. t['Nlinebelow'] = 0x1E48;
  5055. t['Nmonospace'] = 0xFF2E;
  5056. t['Nowarmenian'] = 0x0546;
  5057. t['Nsmall'] = 0xF76E;
  5058. t['Ntilde'] = 0x00D1;
  5059. t['Ntildesmall'] = 0xF7F1;
  5060. t['Nu'] = 0x039D;
  5061. t['O'] = 0x004F;
  5062. t['OE'] = 0x0152;
  5063. t['OEsmall'] = 0xF6FA;
  5064. t['Oacute'] = 0x00D3;
  5065. t['Oacutesmall'] = 0xF7F3;
  5066. t['Obarredcyrillic'] = 0x04E8;
  5067. t['Obarreddieresiscyrillic'] = 0x04EA;
  5068. t['Obreve'] = 0x014E;
  5069. t['Ocaron'] = 0x01D1;
  5070. t['Ocenteredtilde'] = 0x019F;
  5071. t['Ocircle'] = 0x24C4;
  5072. t['Ocircumflex'] = 0x00D4;
  5073. t['Ocircumflexacute'] = 0x1ED0;
  5074. t['Ocircumflexdotbelow'] = 0x1ED8;
  5075. t['Ocircumflexgrave'] = 0x1ED2;
  5076. t['Ocircumflexhookabove'] = 0x1ED4;
  5077. t['Ocircumflexsmall'] = 0xF7F4;
  5078. t['Ocircumflextilde'] = 0x1ED6;
  5079. t['Ocyrillic'] = 0x041E;
  5080. t['Odblacute'] = 0x0150;
  5081. t['Odblgrave'] = 0x020C;
  5082. t['Odieresis'] = 0x00D6;
  5083. t['Odieresiscyrillic'] = 0x04E6;
  5084. t['Odieresissmall'] = 0xF7F6;
  5085. t['Odotbelow'] = 0x1ECC;
  5086. t['Ogoneksmall'] = 0xF6FB;
  5087. t['Ograve'] = 0x00D2;
  5088. t['Ogravesmall'] = 0xF7F2;
  5089. t['Oharmenian'] = 0x0555;
  5090. t['Ohm'] = 0x2126;
  5091. t['Ohookabove'] = 0x1ECE;
  5092. t['Ohorn'] = 0x01A0;
  5093. t['Ohornacute'] = 0x1EDA;
  5094. t['Ohorndotbelow'] = 0x1EE2;
  5095. t['Ohorngrave'] = 0x1EDC;
  5096. t['Ohornhookabove'] = 0x1EDE;
  5097. t['Ohorntilde'] = 0x1EE0;
  5098. t['Ohungarumlaut'] = 0x0150;
  5099. t['Oi'] = 0x01A2;
  5100. t['Oinvertedbreve'] = 0x020E;
  5101. t['Omacron'] = 0x014C;
  5102. t['Omacronacute'] = 0x1E52;
  5103. t['Omacrongrave'] = 0x1E50;
  5104. t['Omega'] = 0x2126;
  5105. t['Omegacyrillic'] = 0x0460;
  5106. t['Omegagreek'] = 0x03A9;
  5107. t['Omegaroundcyrillic'] = 0x047A;
  5108. t['Omegatitlocyrillic'] = 0x047C;
  5109. t['Omegatonos'] = 0x038F;
  5110. t['Omicron'] = 0x039F;
  5111. t['Omicrontonos'] = 0x038C;
  5112. t['Omonospace'] = 0xFF2F;
  5113. t['Oneroman'] = 0x2160;
  5114. t['Oogonek'] = 0x01EA;
  5115. t['Oogonekmacron'] = 0x01EC;
  5116. t['Oopen'] = 0x0186;
  5117. t['Oslash'] = 0x00D8;
  5118. t['Oslashacute'] = 0x01FE;
  5119. t['Oslashsmall'] = 0xF7F8;
  5120. t['Osmall'] = 0xF76F;
  5121. t['Ostrokeacute'] = 0x01FE;
  5122. t['Otcyrillic'] = 0x047E;
  5123. t['Otilde'] = 0x00D5;
  5124. t['Otildeacute'] = 0x1E4C;
  5125. t['Otildedieresis'] = 0x1E4E;
  5126. t['Otildesmall'] = 0xF7F5;
  5127. t['P'] = 0x0050;
  5128. t['Pacute'] = 0x1E54;
  5129. t['Pcircle'] = 0x24C5;
  5130. t['Pdotaccent'] = 0x1E56;
  5131. t['Pecyrillic'] = 0x041F;
  5132. t['Peharmenian'] = 0x054A;
  5133. t['Pemiddlehookcyrillic'] = 0x04A6;
  5134. t['Phi'] = 0x03A6;
  5135. t['Phook'] = 0x01A4;
  5136. t['Pi'] = 0x03A0;
  5137. t['Piwrarmenian'] = 0x0553;
  5138. t['Pmonospace'] = 0xFF30;
  5139. t['Psi'] = 0x03A8;
  5140. t['Psicyrillic'] = 0x0470;
  5141. t['Psmall'] = 0xF770;
  5142. t['Q'] = 0x0051;
  5143. t['Qcircle'] = 0x24C6;
  5144. t['Qmonospace'] = 0xFF31;
  5145. t['Qsmall'] = 0xF771;
  5146. t['R'] = 0x0052;
  5147. t['Raarmenian'] = 0x054C;
  5148. t['Racute'] = 0x0154;
  5149. t['Rcaron'] = 0x0158;
  5150. t['Rcedilla'] = 0x0156;
  5151. t['Rcircle'] = 0x24C7;
  5152. t['Rcommaaccent'] = 0x0156;
  5153. t['Rdblgrave'] = 0x0210;
  5154. t['Rdotaccent'] = 0x1E58;
  5155. t['Rdotbelow'] = 0x1E5A;
  5156. t['Rdotbelowmacron'] = 0x1E5C;
  5157. t['Reharmenian'] = 0x0550;
  5158. t['Rfraktur'] = 0x211C;
  5159. t['Rho'] = 0x03A1;
  5160. t['Ringsmall'] = 0xF6FC;
  5161. t['Rinvertedbreve'] = 0x0212;
  5162. t['Rlinebelow'] = 0x1E5E;
  5163. t['Rmonospace'] = 0xFF32;
  5164. t['Rsmall'] = 0xF772;
  5165. t['Rsmallinverted'] = 0x0281;
  5166. t['Rsmallinvertedsuperior'] = 0x02B6;
  5167. t['S'] = 0x0053;
  5168. t['SF010000'] = 0x250C;
  5169. t['SF020000'] = 0x2514;
  5170. t['SF030000'] = 0x2510;
  5171. t['SF040000'] = 0x2518;
  5172. t['SF050000'] = 0x253C;
  5173. t['SF060000'] = 0x252C;
  5174. t['SF070000'] = 0x2534;
  5175. t['SF080000'] = 0x251C;
  5176. t['SF090000'] = 0x2524;
  5177. t['SF100000'] = 0x2500;
  5178. t['SF110000'] = 0x2502;
  5179. t['SF190000'] = 0x2561;
  5180. t['SF200000'] = 0x2562;
  5181. t['SF210000'] = 0x2556;
  5182. t['SF220000'] = 0x2555;
  5183. t['SF230000'] = 0x2563;
  5184. t['SF240000'] = 0x2551;
  5185. t['SF250000'] = 0x2557;
  5186. t['SF260000'] = 0x255D;
  5187. t['SF270000'] = 0x255C;
  5188. t['SF280000'] = 0x255B;
  5189. t['SF360000'] = 0x255E;
  5190. t['SF370000'] = 0x255F;
  5191. t['SF380000'] = 0x255A;
  5192. t['SF390000'] = 0x2554;
  5193. t['SF400000'] = 0x2569;
  5194. t['SF410000'] = 0x2566;
  5195. t['SF420000'] = 0x2560;
  5196. t['SF430000'] = 0x2550;
  5197. t['SF440000'] = 0x256C;
  5198. t['SF450000'] = 0x2567;
  5199. t['SF460000'] = 0x2568;
  5200. t['SF470000'] = 0x2564;
  5201. t['SF480000'] = 0x2565;
  5202. t['SF490000'] = 0x2559;
  5203. t['SF500000'] = 0x2558;
  5204. t['SF510000'] = 0x2552;
  5205. t['SF520000'] = 0x2553;
  5206. t['SF530000'] = 0x256B;
  5207. t['SF540000'] = 0x256A;
  5208. t['Sacute'] = 0x015A;
  5209. t['Sacutedotaccent'] = 0x1E64;
  5210. t['Sampigreek'] = 0x03E0;
  5211. t['Scaron'] = 0x0160;
  5212. t['Scarondotaccent'] = 0x1E66;
  5213. t['Scaronsmall'] = 0xF6FD;
  5214. t['Scedilla'] = 0x015E;
  5215. t['Schwa'] = 0x018F;
  5216. t['Schwacyrillic'] = 0x04D8;
  5217. t['Schwadieresiscyrillic'] = 0x04DA;
  5218. t['Scircle'] = 0x24C8;
  5219. t['Scircumflex'] = 0x015C;
  5220. t['Scommaaccent'] = 0x0218;
  5221. t['Sdotaccent'] = 0x1E60;
  5222. t['Sdotbelow'] = 0x1E62;
  5223. t['Sdotbelowdotaccent'] = 0x1E68;
  5224. t['Seharmenian'] = 0x054D;
  5225. t['Sevenroman'] = 0x2166;
  5226. t['Shaarmenian'] = 0x0547;
  5227. t['Shacyrillic'] = 0x0428;
  5228. t['Shchacyrillic'] = 0x0429;
  5229. t['Sheicoptic'] = 0x03E2;
  5230. t['Shhacyrillic'] = 0x04BA;
  5231. t['Shimacoptic'] = 0x03EC;
  5232. t['Sigma'] = 0x03A3;
  5233. t['Sixroman'] = 0x2165;
  5234. t['Smonospace'] = 0xFF33;
  5235. t['Softsigncyrillic'] = 0x042C;
  5236. t['Ssmall'] = 0xF773;
  5237. t['Stigmagreek'] = 0x03DA;
  5238. t['T'] = 0x0054;
  5239. t['Tau'] = 0x03A4;
  5240. t['Tbar'] = 0x0166;
  5241. t['Tcaron'] = 0x0164;
  5242. t['Tcedilla'] = 0x0162;
  5243. t['Tcircle'] = 0x24C9;
  5244. t['Tcircumflexbelow'] = 0x1E70;
  5245. t['Tcommaaccent'] = 0x0162;
  5246. t['Tdotaccent'] = 0x1E6A;
  5247. t['Tdotbelow'] = 0x1E6C;
  5248. t['Tecyrillic'] = 0x0422;
  5249. t['Tedescendercyrillic'] = 0x04AC;
  5250. t['Tenroman'] = 0x2169;
  5251. t['Tetsecyrillic'] = 0x04B4;
  5252. t['Theta'] = 0x0398;
  5253. t['Thook'] = 0x01AC;
  5254. t['Thorn'] = 0x00DE;
  5255. t['Thornsmall'] = 0xF7FE;
  5256. t['Threeroman'] = 0x2162;
  5257. t['Tildesmall'] = 0xF6FE;
  5258. t['Tiwnarmenian'] = 0x054F;
  5259. t['Tlinebelow'] = 0x1E6E;
  5260. t['Tmonospace'] = 0xFF34;
  5261. t['Toarmenian'] = 0x0539;
  5262. t['Tonefive'] = 0x01BC;
  5263. t['Tonesix'] = 0x0184;
  5264. t['Tonetwo'] = 0x01A7;
  5265. t['Tretroflexhook'] = 0x01AE;
  5266. t['Tsecyrillic'] = 0x0426;
  5267. t['Tshecyrillic'] = 0x040B;
  5268. t['Tsmall'] = 0xF774;
  5269. t['Twelveroman'] = 0x216B;
  5270. t['Tworoman'] = 0x2161;
  5271. t['U'] = 0x0055;
  5272. t['Uacute'] = 0x00DA;
  5273. t['Uacutesmall'] = 0xF7FA;
  5274. t['Ubreve'] = 0x016C;
  5275. t['Ucaron'] = 0x01D3;
  5276. t['Ucircle'] = 0x24CA;
  5277. t['Ucircumflex'] = 0x00DB;
  5278. t['Ucircumflexbelow'] = 0x1E76;
  5279. t['Ucircumflexsmall'] = 0xF7FB;
  5280. t['Ucyrillic'] = 0x0423;
  5281. t['Udblacute'] = 0x0170;
  5282. t['Udblgrave'] = 0x0214;
  5283. t['Udieresis'] = 0x00DC;
  5284. t['Udieresisacute'] = 0x01D7;
  5285. t['Udieresisbelow'] = 0x1E72;
  5286. t['Udieresiscaron'] = 0x01D9;
  5287. t['Udieresiscyrillic'] = 0x04F0;
  5288. t['Udieresisgrave'] = 0x01DB;
  5289. t['Udieresismacron'] = 0x01D5;
  5290. t['Udieresissmall'] = 0xF7FC;
  5291. t['Udotbelow'] = 0x1EE4;
  5292. t['Ugrave'] = 0x00D9;
  5293. t['Ugravesmall'] = 0xF7F9;
  5294. t['Uhookabove'] = 0x1EE6;
  5295. t['Uhorn'] = 0x01AF;
  5296. t['Uhornacute'] = 0x1EE8;
  5297. t['Uhorndotbelow'] = 0x1EF0;
  5298. t['Uhorngrave'] = 0x1EEA;
  5299. t['Uhornhookabove'] = 0x1EEC;
  5300. t['Uhorntilde'] = 0x1EEE;
  5301. t['Uhungarumlaut'] = 0x0170;
  5302. t['Uhungarumlautcyrillic'] = 0x04F2;
  5303. t['Uinvertedbreve'] = 0x0216;
  5304. t['Ukcyrillic'] = 0x0478;
  5305. t['Umacron'] = 0x016A;
  5306. t['Umacroncyrillic'] = 0x04EE;
  5307. t['Umacrondieresis'] = 0x1E7A;
  5308. t['Umonospace'] = 0xFF35;
  5309. t['Uogonek'] = 0x0172;
  5310. t['Upsilon'] = 0x03A5;
  5311. t['Upsilon1'] = 0x03D2;
  5312. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5313. t['Upsilonafrican'] = 0x01B1;
  5314. t['Upsilondieresis'] = 0x03AB;
  5315. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5316. t['Upsilonhooksymbol'] = 0x03D2;
  5317. t['Upsilontonos'] = 0x038E;
  5318. t['Uring'] = 0x016E;
  5319. t['Ushortcyrillic'] = 0x040E;
  5320. t['Usmall'] = 0xF775;
  5321. t['Ustraightcyrillic'] = 0x04AE;
  5322. t['Ustraightstrokecyrillic'] = 0x04B0;
  5323. t['Utilde'] = 0x0168;
  5324. t['Utildeacute'] = 0x1E78;
  5325. t['Utildebelow'] = 0x1E74;
  5326. t['V'] = 0x0056;
  5327. t['Vcircle'] = 0x24CB;
  5328. t['Vdotbelow'] = 0x1E7E;
  5329. t['Vecyrillic'] = 0x0412;
  5330. t['Vewarmenian'] = 0x054E;
  5331. t['Vhook'] = 0x01B2;
  5332. t['Vmonospace'] = 0xFF36;
  5333. t['Voarmenian'] = 0x0548;
  5334. t['Vsmall'] = 0xF776;
  5335. t['Vtilde'] = 0x1E7C;
  5336. t['W'] = 0x0057;
  5337. t['Wacute'] = 0x1E82;
  5338. t['Wcircle'] = 0x24CC;
  5339. t['Wcircumflex'] = 0x0174;
  5340. t['Wdieresis'] = 0x1E84;
  5341. t['Wdotaccent'] = 0x1E86;
  5342. t['Wdotbelow'] = 0x1E88;
  5343. t['Wgrave'] = 0x1E80;
  5344. t['Wmonospace'] = 0xFF37;
  5345. t['Wsmall'] = 0xF777;
  5346. t['X'] = 0x0058;
  5347. t['Xcircle'] = 0x24CD;
  5348. t['Xdieresis'] = 0x1E8C;
  5349. t['Xdotaccent'] = 0x1E8A;
  5350. t['Xeharmenian'] = 0x053D;
  5351. t['Xi'] = 0x039E;
  5352. t['Xmonospace'] = 0xFF38;
  5353. t['Xsmall'] = 0xF778;
  5354. t['Y'] = 0x0059;
  5355. t['Yacute'] = 0x00DD;
  5356. t['Yacutesmall'] = 0xF7FD;
  5357. t['Yatcyrillic'] = 0x0462;
  5358. t['Ycircle'] = 0x24CE;
  5359. t['Ycircumflex'] = 0x0176;
  5360. t['Ydieresis'] = 0x0178;
  5361. t['Ydieresissmall'] = 0xF7FF;
  5362. t['Ydotaccent'] = 0x1E8E;
  5363. t['Ydotbelow'] = 0x1EF4;
  5364. t['Yericyrillic'] = 0x042B;
  5365. t['Yerudieresiscyrillic'] = 0x04F8;
  5366. t['Ygrave'] = 0x1EF2;
  5367. t['Yhook'] = 0x01B3;
  5368. t['Yhookabove'] = 0x1EF6;
  5369. t['Yiarmenian'] = 0x0545;
  5370. t['Yicyrillic'] = 0x0407;
  5371. t['Yiwnarmenian'] = 0x0552;
  5372. t['Ymonospace'] = 0xFF39;
  5373. t['Ysmall'] = 0xF779;
  5374. t['Ytilde'] = 0x1EF8;
  5375. t['Yusbigcyrillic'] = 0x046A;
  5376. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5377. t['Yuslittlecyrillic'] = 0x0466;
  5378. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5379. t['Z'] = 0x005A;
  5380. t['Zaarmenian'] = 0x0536;
  5381. t['Zacute'] = 0x0179;
  5382. t['Zcaron'] = 0x017D;
  5383. t['Zcaronsmall'] = 0xF6FF;
  5384. t['Zcircle'] = 0x24CF;
  5385. t['Zcircumflex'] = 0x1E90;
  5386. t['Zdot'] = 0x017B;
  5387. t['Zdotaccent'] = 0x017B;
  5388. t['Zdotbelow'] = 0x1E92;
  5389. t['Zecyrillic'] = 0x0417;
  5390. t['Zedescendercyrillic'] = 0x0498;
  5391. t['Zedieresiscyrillic'] = 0x04DE;
  5392. t['Zeta'] = 0x0396;
  5393. t['Zhearmenian'] = 0x053A;
  5394. t['Zhebrevecyrillic'] = 0x04C1;
  5395. t['Zhecyrillic'] = 0x0416;
  5396. t['Zhedescendercyrillic'] = 0x0496;
  5397. t['Zhedieresiscyrillic'] = 0x04DC;
  5398. t['Zlinebelow'] = 0x1E94;
  5399. t['Zmonospace'] = 0xFF3A;
  5400. t['Zsmall'] = 0xF77A;
  5401. t['Zstroke'] = 0x01B5;
  5402. t['a'] = 0x0061;
  5403. t['aabengali'] = 0x0986;
  5404. t['aacute'] = 0x00E1;
  5405. t['aadeva'] = 0x0906;
  5406. t['aagujarati'] = 0x0A86;
  5407. t['aagurmukhi'] = 0x0A06;
  5408. t['aamatragurmukhi'] = 0x0A3E;
  5409. t['aarusquare'] = 0x3303;
  5410. t['aavowelsignbengali'] = 0x09BE;
  5411. t['aavowelsigndeva'] = 0x093E;
  5412. t['aavowelsigngujarati'] = 0x0ABE;
  5413. t['abbreviationmarkarmenian'] = 0x055F;
  5414. t['abbreviationsigndeva'] = 0x0970;
  5415. t['abengali'] = 0x0985;
  5416. t['abopomofo'] = 0x311A;
  5417. t['abreve'] = 0x0103;
  5418. t['abreveacute'] = 0x1EAF;
  5419. t['abrevecyrillic'] = 0x04D1;
  5420. t['abrevedotbelow'] = 0x1EB7;
  5421. t['abrevegrave'] = 0x1EB1;
  5422. t['abrevehookabove'] = 0x1EB3;
  5423. t['abrevetilde'] = 0x1EB5;
  5424. t['acaron'] = 0x01CE;
  5425. t['acircle'] = 0x24D0;
  5426. t['acircumflex'] = 0x00E2;
  5427. t['acircumflexacute'] = 0x1EA5;
  5428. t['acircumflexdotbelow'] = 0x1EAD;
  5429. t['acircumflexgrave'] = 0x1EA7;
  5430. t['acircumflexhookabove'] = 0x1EA9;
  5431. t['acircumflextilde'] = 0x1EAB;
  5432. t['acute'] = 0x00B4;
  5433. t['acutebelowcmb'] = 0x0317;
  5434. t['acutecmb'] = 0x0301;
  5435. t['acutecomb'] = 0x0301;
  5436. t['acutedeva'] = 0x0954;
  5437. t['acutelowmod'] = 0x02CF;
  5438. t['acutetonecmb'] = 0x0341;
  5439. t['acyrillic'] = 0x0430;
  5440. t['adblgrave'] = 0x0201;
  5441. t['addakgurmukhi'] = 0x0A71;
  5442. t['adeva'] = 0x0905;
  5443. t['adieresis'] = 0x00E4;
  5444. t['adieresiscyrillic'] = 0x04D3;
  5445. t['adieresismacron'] = 0x01DF;
  5446. t['adotbelow'] = 0x1EA1;
  5447. t['adotmacron'] = 0x01E1;
  5448. t['ae'] = 0x00E6;
  5449. t['aeacute'] = 0x01FD;
  5450. t['aekorean'] = 0x3150;
  5451. t['aemacron'] = 0x01E3;
  5452. t['afii00208'] = 0x2015;
  5453. t['afii08941'] = 0x20A4;
  5454. t['afii10017'] = 0x0410;
  5455. t['afii10018'] = 0x0411;
  5456. t['afii10019'] = 0x0412;
  5457. t['afii10020'] = 0x0413;
  5458. t['afii10021'] = 0x0414;
  5459. t['afii10022'] = 0x0415;
  5460. t['afii10023'] = 0x0401;
  5461. t['afii10024'] = 0x0416;
  5462. t['afii10025'] = 0x0417;
  5463. t['afii10026'] = 0x0418;
  5464. t['afii10027'] = 0x0419;
  5465. t['afii10028'] = 0x041A;
  5466. t['afii10029'] = 0x041B;
  5467. t['afii10030'] = 0x041C;
  5468. t['afii10031'] = 0x041D;
  5469. t['afii10032'] = 0x041E;
  5470. t['afii10033'] = 0x041F;
  5471. t['afii10034'] = 0x0420;
  5472. t['afii10035'] = 0x0421;
  5473. t['afii10036'] = 0x0422;
  5474. t['afii10037'] = 0x0423;
  5475. t['afii10038'] = 0x0424;
  5476. t['afii10039'] = 0x0425;
  5477. t['afii10040'] = 0x0426;
  5478. t['afii10041'] = 0x0427;
  5479. t['afii10042'] = 0x0428;
  5480. t['afii10043'] = 0x0429;
  5481. t['afii10044'] = 0x042A;
  5482. t['afii10045'] = 0x042B;
  5483. t['afii10046'] = 0x042C;
  5484. t['afii10047'] = 0x042D;
  5485. t['afii10048'] = 0x042E;
  5486. t['afii10049'] = 0x042F;
  5487. t['afii10050'] = 0x0490;
  5488. t['afii10051'] = 0x0402;
  5489. t['afii10052'] = 0x0403;
  5490. t['afii10053'] = 0x0404;
  5491. t['afii10054'] = 0x0405;
  5492. t['afii10055'] = 0x0406;
  5493. t['afii10056'] = 0x0407;
  5494. t['afii10057'] = 0x0408;
  5495. t['afii10058'] = 0x0409;
  5496. t['afii10059'] = 0x040A;
  5497. t['afii10060'] = 0x040B;
  5498. t['afii10061'] = 0x040C;
  5499. t['afii10062'] = 0x040E;
  5500. t['afii10063'] = 0xF6C4;
  5501. t['afii10064'] = 0xF6C5;
  5502. t['afii10065'] = 0x0430;
  5503. t['afii10066'] = 0x0431;
  5504. t['afii10067'] = 0x0432;
  5505. t['afii10068'] = 0x0433;
  5506. t['afii10069'] = 0x0434;
  5507. t['afii10070'] = 0x0435;
  5508. t['afii10071'] = 0x0451;
  5509. t['afii10072'] = 0x0436;
  5510. t['afii10073'] = 0x0437;
  5511. t['afii10074'] = 0x0438;
  5512. t['afii10075'] = 0x0439;
  5513. t['afii10076'] = 0x043A;
  5514. t['afii10077'] = 0x043B;
  5515. t['afii10078'] = 0x043C;
  5516. t['afii10079'] = 0x043D;
  5517. t['afii10080'] = 0x043E;
  5518. t['afii10081'] = 0x043F;
  5519. t['afii10082'] = 0x0440;
  5520. t['afii10083'] = 0x0441;
  5521. t['afii10084'] = 0x0442;
  5522. t['afii10085'] = 0x0443;
  5523. t['afii10086'] = 0x0444;
  5524. t['afii10087'] = 0x0445;
  5525. t['afii10088'] = 0x0446;
  5526. t['afii10089'] = 0x0447;
  5527. t['afii10090'] = 0x0448;
  5528. t['afii10091'] = 0x0449;
  5529. t['afii10092'] = 0x044A;
  5530. t['afii10093'] = 0x044B;
  5531. t['afii10094'] = 0x044C;
  5532. t['afii10095'] = 0x044D;
  5533. t['afii10096'] = 0x044E;
  5534. t['afii10097'] = 0x044F;
  5535. t['afii10098'] = 0x0491;
  5536. t['afii10099'] = 0x0452;
  5537. t['afii10100'] = 0x0453;
  5538. t['afii10101'] = 0x0454;
  5539. t['afii10102'] = 0x0455;
  5540. t['afii10103'] = 0x0456;
  5541. t['afii10104'] = 0x0457;
  5542. t['afii10105'] = 0x0458;
  5543. t['afii10106'] = 0x0459;
  5544. t['afii10107'] = 0x045A;
  5545. t['afii10108'] = 0x045B;
  5546. t['afii10109'] = 0x045C;
  5547. t['afii10110'] = 0x045E;
  5548. t['afii10145'] = 0x040F;
  5549. t['afii10146'] = 0x0462;
  5550. t['afii10147'] = 0x0472;
  5551. t['afii10148'] = 0x0474;
  5552. t['afii10192'] = 0xF6C6;
  5553. t['afii10193'] = 0x045F;
  5554. t['afii10194'] = 0x0463;
  5555. t['afii10195'] = 0x0473;
  5556. t['afii10196'] = 0x0475;
  5557. t['afii10831'] = 0xF6C7;
  5558. t['afii10832'] = 0xF6C8;
  5559. t['afii10846'] = 0x04D9;
  5560. t['afii299'] = 0x200E;
  5561. t['afii300'] = 0x200F;
  5562. t['afii301'] = 0x200D;
  5563. t['afii57381'] = 0x066A;
  5564. t['afii57388'] = 0x060C;
  5565. t['afii57392'] = 0x0660;
  5566. t['afii57393'] = 0x0661;
  5567. t['afii57394'] = 0x0662;
  5568. t['afii57395'] = 0x0663;
  5569. t['afii57396'] = 0x0664;
  5570. t['afii57397'] = 0x0665;
  5571. t['afii57398'] = 0x0666;
  5572. t['afii57399'] = 0x0667;
  5573. t['afii57400'] = 0x0668;
  5574. t['afii57401'] = 0x0669;
  5575. t['afii57403'] = 0x061B;
  5576. t['afii57407'] = 0x061F;
  5577. t['afii57409'] = 0x0621;
  5578. t['afii57410'] = 0x0622;
  5579. t['afii57411'] = 0x0623;
  5580. t['afii57412'] = 0x0624;
  5581. t['afii57413'] = 0x0625;
  5582. t['afii57414'] = 0x0626;
  5583. t['afii57415'] = 0x0627;
  5584. t['afii57416'] = 0x0628;
  5585. t['afii57417'] = 0x0629;
  5586. t['afii57418'] = 0x062A;
  5587. t['afii57419'] = 0x062B;
  5588. t['afii57420'] = 0x062C;
  5589. t['afii57421'] = 0x062D;
  5590. t['afii57422'] = 0x062E;
  5591. t['afii57423'] = 0x062F;
  5592. t['afii57424'] = 0x0630;
  5593. t['afii57425'] = 0x0631;
  5594. t['afii57426'] = 0x0632;
  5595. t['afii57427'] = 0x0633;
  5596. t['afii57428'] = 0x0634;
  5597. t['afii57429'] = 0x0635;
  5598. t['afii57430'] = 0x0636;
  5599. t['afii57431'] = 0x0637;
  5600. t['afii57432'] = 0x0638;
  5601. t['afii57433'] = 0x0639;
  5602. t['afii57434'] = 0x063A;
  5603. t['afii57440'] = 0x0640;
  5604. t['afii57441'] = 0x0641;
  5605. t['afii57442'] = 0x0642;
  5606. t['afii57443'] = 0x0643;
  5607. t['afii57444'] = 0x0644;
  5608. t['afii57445'] = 0x0645;
  5609. t['afii57446'] = 0x0646;
  5610. t['afii57448'] = 0x0648;
  5611. t['afii57449'] = 0x0649;
  5612. t['afii57450'] = 0x064A;
  5613. t['afii57451'] = 0x064B;
  5614. t['afii57452'] = 0x064C;
  5615. t['afii57453'] = 0x064D;
  5616. t['afii57454'] = 0x064E;
  5617. t['afii57455'] = 0x064F;
  5618. t['afii57456'] = 0x0650;
  5619. t['afii57457'] = 0x0651;
  5620. t['afii57458'] = 0x0652;
  5621. t['afii57470'] = 0x0647;
  5622. t['afii57505'] = 0x06A4;
  5623. t['afii57506'] = 0x067E;
  5624. t['afii57507'] = 0x0686;
  5625. t['afii57508'] = 0x0698;
  5626. t['afii57509'] = 0x06AF;
  5627. t['afii57511'] = 0x0679;
  5628. t['afii57512'] = 0x0688;
  5629. t['afii57513'] = 0x0691;
  5630. t['afii57514'] = 0x06BA;
  5631. t['afii57519'] = 0x06D2;
  5632. t['afii57534'] = 0x06D5;
  5633. t['afii57636'] = 0x20AA;
  5634. t['afii57645'] = 0x05BE;
  5635. t['afii57658'] = 0x05C3;
  5636. t['afii57664'] = 0x05D0;
  5637. t['afii57665'] = 0x05D1;
  5638. t['afii57666'] = 0x05D2;
  5639. t['afii57667'] = 0x05D3;
  5640. t['afii57668'] = 0x05D4;
  5641. t['afii57669'] = 0x05D5;
  5642. t['afii57670'] = 0x05D6;
  5643. t['afii57671'] = 0x05D7;
  5644. t['afii57672'] = 0x05D8;
  5645. t['afii57673'] = 0x05D9;
  5646. t['afii57674'] = 0x05DA;
  5647. t['afii57675'] = 0x05DB;
  5648. t['afii57676'] = 0x05DC;
  5649. t['afii57677'] = 0x05DD;
  5650. t['afii57678'] = 0x05DE;
  5651. t['afii57679'] = 0x05DF;
  5652. t['afii57680'] = 0x05E0;
  5653. t['afii57681'] = 0x05E1;
  5654. t['afii57682'] = 0x05E2;
  5655. t['afii57683'] = 0x05E3;
  5656. t['afii57684'] = 0x05E4;
  5657. t['afii57685'] = 0x05E5;
  5658. t['afii57686'] = 0x05E6;
  5659. t['afii57687'] = 0x05E7;
  5660. t['afii57688'] = 0x05E8;
  5661. t['afii57689'] = 0x05E9;
  5662. t['afii57690'] = 0x05EA;
  5663. t['afii57694'] = 0xFB2A;
  5664. t['afii57695'] = 0xFB2B;
  5665. t['afii57700'] = 0xFB4B;
  5666. t['afii57705'] = 0xFB1F;
  5667. t['afii57716'] = 0x05F0;
  5668. t['afii57717'] = 0x05F1;
  5669. t['afii57718'] = 0x05F2;
  5670. t['afii57723'] = 0xFB35;
  5671. t['afii57793'] = 0x05B4;
  5672. t['afii57794'] = 0x05B5;
  5673. t['afii57795'] = 0x05B6;
  5674. t['afii57796'] = 0x05BB;
  5675. t['afii57797'] = 0x05B8;
  5676. t['afii57798'] = 0x05B7;
  5677. t['afii57799'] = 0x05B0;
  5678. t['afii57800'] = 0x05B2;
  5679. t['afii57801'] = 0x05B1;
  5680. t['afii57802'] = 0x05B3;
  5681. t['afii57803'] = 0x05C2;
  5682. t['afii57804'] = 0x05C1;
  5683. t['afii57806'] = 0x05B9;
  5684. t['afii57807'] = 0x05BC;
  5685. t['afii57839'] = 0x05BD;
  5686. t['afii57841'] = 0x05BF;
  5687. t['afii57842'] = 0x05C0;
  5688. t['afii57929'] = 0x02BC;
  5689. t['afii61248'] = 0x2105;
  5690. t['afii61289'] = 0x2113;
  5691. t['afii61352'] = 0x2116;
  5692. t['afii61573'] = 0x202C;
  5693. t['afii61574'] = 0x202D;
  5694. t['afii61575'] = 0x202E;
  5695. t['afii61664'] = 0x200C;
  5696. t['afii63167'] = 0x066D;
  5697. t['afii64937'] = 0x02BD;
  5698. t['agrave'] = 0x00E0;
  5699. t['agujarati'] = 0x0A85;
  5700. t['agurmukhi'] = 0x0A05;
  5701. t['ahiragana'] = 0x3042;
  5702. t['ahookabove'] = 0x1EA3;
  5703. t['aibengali'] = 0x0990;
  5704. t['aibopomofo'] = 0x311E;
  5705. t['aideva'] = 0x0910;
  5706. t['aiecyrillic'] = 0x04D5;
  5707. t['aigujarati'] = 0x0A90;
  5708. t['aigurmukhi'] = 0x0A10;
  5709. t['aimatragurmukhi'] = 0x0A48;
  5710. t['ainarabic'] = 0x0639;
  5711. t['ainfinalarabic'] = 0xFECA;
  5712. t['aininitialarabic'] = 0xFECB;
  5713. t['ainmedialarabic'] = 0xFECC;
  5714. t['ainvertedbreve'] = 0x0203;
  5715. t['aivowelsignbengali'] = 0x09C8;
  5716. t['aivowelsigndeva'] = 0x0948;
  5717. t['aivowelsigngujarati'] = 0x0AC8;
  5718. t['akatakana'] = 0x30A2;
  5719. t['akatakanahalfwidth'] = 0xFF71;
  5720. t['akorean'] = 0x314F;
  5721. t['alef'] = 0x05D0;
  5722. t['alefarabic'] = 0x0627;
  5723. t['alefdageshhebrew'] = 0xFB30;
  5724. t['aleffinalarabic'] = 0xFE8E;
  5725. t['alefhamzaabovearabic'] = 0x0623;
  5726. t['alefhamzaabovefinalarabic'] = 0xFE84;
  5727. t['alefhamzabelowarabic'] = 0x0625;
  5728. t['alefhamzabelowfinalarabic'] = 0xFE88;
  5729. t['alefhebrew'] = 0x05D0;
  5730. t['aleflamedhebrew'] = 0xFB4F;
  5731. t['alefmaddaabovearabic'] = 0x0622;
  5732. t['alefmaddaabovefinalarabic'] = 0xFE82;
  5733. t['alefmaksuraarabic'] = 0x0649;
  5734. t['alefmaksurafinalarabic'] = 0xFEF0;
  5735. t['alefmaksurainitialarabic'] = 0xFEF3;
  5736. t['alefmaksuramedialarabic'] = 0xFEF4;
  5737. t['alefpatahhebrew'] = 0xFB2E;
  5738. t['alefqamatshebrew'] = 0xFB2F;
  5739. t['aleph'] = 0x2135;
  5740. t['allequal'] = 0x224C;
  5741. t['alpha'] = 0x03B1;
  5742. t['alphatonos'] = 0x03AC;
  5743. t['amacron'] = 0x0101;
  5744. t['amonospace'] = 0xFF41;
  5745. t['ampersand'] = 0x0026;
  5746. t['ampersandmonospace'] = 0xFF06;
  5747. t['ampersandsmall'] = 0xF726;
  5748. t['amsquare'] = 0x33C2;
  5749. t['anbopomofo'] = 0x3122;
  5750. t['angbopomofo'] = 0x3124;
  5751. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  5752. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  5753. t['angkhankhuthai'] = 0x0E5A;
  5754. t['angle'] = 0x2220;
  5755. t['anglebracketleft'] = 0x3008;
  5756. t['anglebracketleftvertical'] = 0xFE3F;
  5757. t['anglebracketright'] = 0x3009;
  5758. t['anglebracketrightvertical'] = 0xFE40;
  5759. t['angleleft'] = 0x2329;
  5760. t['angleright'] = 0x232A;
  5761. t['angstrom'] = 0x212B;
  5762. t['anoteleia'] = 0x0387;
  5763. t['anudattadeva'] = 0x0952;
  5764. t['anusvarabengali'] = 0x0982;
  5765. t['anusvaradeva'] = 0x0902;
  5766. t['anusvaragujarati'] = 0x0A82;
  5767. t['aogonek'] = 0x0105;
  5768. t['apaatosquare'] = 0x3300;
  5769. t['aparen'] = 0x249C;
  5770. t['apostrophearmenian'] = 0x055A;
  5771. t['apostrophemod'] = 0x02BC;
  5772. t['apple'] = 0xF8FF;
  5773. t['approaches'] = 0x2250;
  5774. t['approxequal'] = 0x2248;
  5775. t['approxequalorimage'] = 0x2252;
  5776. t['approximatelyequal'] = 0x2245;
  5777. t['araeaekorean'] = 0x318E;
  5778. t['araeakorean'] = 0x318D;
  5779. t['arc'] = 0x2312;
  5780. t['arighthalfring'] = 0x1E9A;
  5781. t['aring'] = 0x00E5;
  5782. t['aringacute'] = 0x01FB;
  5783. t['aringbelow'] = 0x1E01;
  5784. t['arrowboth'] = 0x2194;
  5785. t['arrowdashdown'] = 0x21E3;
  5786. t['arrowdashleft'] = 0x21E0;
  5787. t['arrowdashright'] = 0x21E2;
  5788. t['arrowdashup'] = 0x21E1;
  5789. t['arrowdblboth'] = 0x21D4;
  5790. t['arrowdbldown'] = 0x21D3;
  5791. t['arrowdblleft'] = 0x21D0;
  5792. t['arrowdblright'] = 0x21D2;
  5793. t['arrowdblup'] = 0x21D1;
  5794. t['arrowdown'] = 0x2193;
  5795. t['arrowdownleft'] = 0x2199;
  5796. t['arrowdownright'] = 0x2198;
  5797. t['arrowdownwhite'] = 0x21E9;
  5798. t['arrowheaddownmod'] = 0x02C5;
  5799. t['arrowheadleftmod'] = 0x02C2;
  5800. t['arrowheadrightmod'] = 0x02C3;
  5801. t['arrowheadupmod'] = 0x02C4;
  5802. t['arrowhorizex'] = 0xF8E7;
  5803. t['arrowleft'] = 0x2190;
  5804. t['arrowleftdbl'] = 0x21D0;
  5805. t['arrowleftdblstroke'] = 0x21CD;
  5806. t['arrowleftoverright'] = 0x21C6;
  5807. t['arrowleftwhite'] = 0x21E6;
  5808. t['arrowright'] = 0x2192;
  5809. t['arrowrightdblstroke'] = 0x21CF;
  5810. t['arrowrightheavy'] = 0x279E;
  5811. t['arrowrightoverleft'] = 0x21C4;
  5812. t['arrowrightwhite'] = 0x21E8;
  5813. t['arrowtableft'] = 0x21E4;
  5814. t['arrowtabright'] = 0x21E5;
  5815. t['arrowup'] = 0x2191;
  5816. t['arrowupdn'] = 0x2195;
  5817. t['arrowupdnbse'] = 0x21A8;
  5818. t['arrowupdownbase'] = 0x21A8;
  5819. t['arrowupleft'] = 0x2196;
  5820. t['arrowupleftofdown'] = 0x21C5;
  5821. t['arrowupright'] = 0x2197;
  5822. t['arrowupwhite'] = 0x21E7;
  5823. t['arrowvertex'] = 0xF8E6;
  5824. t['asciicircum'] = 0x005E;
  5825. t['asciicircummonospace'] = 0xFF3E;
  5826. t['asciitilde'] = 0x007E;
  5827. t['asciitildemonospace'] = 0xFF5E;
  5828. t['ascript'] = 0x0251;
  5829. t['ascriptturned'] = 0x0252;
  5830. t['asmallhiragana'] = 0x3041;
  5831. t['asmallkatakana'] = 0x30A1;
  5832. t['asmallkatakanahalfwidth'] = 0xFF67;
  5833. t['asterisk'] = 0x002A;
  5834. t['asteriskaltonearabic'] = 0x066D;
  5835. t['asteriskarabic'] = 0x066D;
  5836. t['asteriskmath'] = 0x2217;
  5837. t['asteriskmonospace'] = 0xFF0A;
  5838. t['asterisksmall'] = 0xFE61;
  5839. t['asterism'] = 0x2042;
  5840. t['asuperior'] = 0xF6E9;
  5841. t['asymptoticallyequal'] = 0x2243;
  5842. t['at'] = 0x0040;
  5843. t['atilde'] = 0x00E3;
  5844. t['atmonospace'] = 0xFF20;
  5845. t['atsmall'] = 0xFE6B;
  5846. t['aturned'] = 0x0250;
  5847. t['aubengali'] = 0x0994;
  5848. t['aubopomofo'] = 0x3120;
  5849. t['audeva'] = 0x0914;
  5850. t['augujarati'] = 0x0A94;
  5851. t['augurmukhi'] = 0x0A14;
  5852. t['aulengthmarkbengali'] = 0x09D7;
  5853. t['aumatragurmukhi'] = 0x0A4C;
  5854. t['auvowelsignbengali'] = 0x09CC;
  5855. t['auvowelsigndeva'] = 0x094C;
  5856. t['auvowelsigngujarati'] = 0x0ACC;
  5857. t['avagrahadeva'] = 0x093D;
  5858. t['aybarmenian'] = 0x0561;
  5859. t['ayin'] = 0x05E2;
  5860. t['ayinaltonehebrew'] = 0xFB20;
  5861. t['ayinhebrew'] = 0x05E2;
  5862. t['b'] = 0x0062;
  5863. t['babengali'] = 0x09AC;
  5864. t['backslash'] = 0x005C;
  5865. t['backslashmonospace'] = 0xFF3C;
  5866. t['badeva'] = 0x092C;
  5867. t['bagujarati'] = 0x0AAC;
  5868. t['bagurmukhi'] = 0x0A2C;
  5869. t['bahiragana'] = 0x3070;
  5870. t['bahtthai'] = 0x0E3F;
  5871. t['bakatakana'] = 0x30D0;
  5872. t['bar'] = 0x007C;
  5873. t['barmonospace'] = 0xFF5C;
  5874. t['bbopomofo'] = 0x3105;
  5875. t['bcircle'] = 0x24D1;
  5876. t['bdotaccent'] = 0x1E03;
  5877. t['bdotbelow'] = 0x1E05;
  5878. t['beamedsixteenthnotes'] = 0x266C;
  5879. t['because'] = 0x2235;
  5880. t['becyrillic'] = 0x0431;
  5881. t['beharabic'] = 0x0628;
  5882. t['behfinalarabic'] = 0xFE90;
  5883. t['behinitialarabic'] = 0xFE91;
  5884. t['behiragana'] = 0x3079;
  5885. t['behmedialarabic'] = 0xFE92;
  5886. t['behmeeminitialarabic'] = 0xFC9F;
  5887. t['behmeemisolatedarabic'] = 0xFC08;
  5888. t['behnoonfinalarabic'] = 0xFC6D;
  5889. t['bekatakana'] = 0x30D9;
  5890. t['benarmenian'] = 0x0562;
  5891. t['bet'] = 0x05D1;
  5892. t['beta'] = 0x03B2;
  5893. t['betasymbolgreek'] = 0x03D0;
  5894. t['betdagesh'] = 0xFB31;
  5895. t['betdageshhebrew'] = 0xFB31;
  5896. t['bethebrew'] = 0x05D1;
  5897. t['betrafehebrew'] = 0xFB4C;
  5898. t['bhabengali'] = 0x09AD;
  5899. t['bhadeva'] = 0x092D;
  5900. t['bhagujarati'] = 0x0AAD;
  5901. t['bhagurmukhi'] = 0x0A2D;
  5902. t['bhook'] = 0x0253;
  5903. t['bihiragana'] = 0x3073;
  5904. t['bikatakana'] = 0x30D3;
  5905. t['bilabialclick'] = 0x0298;
  5906. t['bindigurmukhi'] = 0x0A02;
  5907. t['birusquare'] = 0x3331;
  5908. t['blackcircle'] = 0x25CF;
  5909. t['blackdiamond'] = 0x25C6;
  5910. t['blackdownpointingtriangle'] = 0x25BC;
  5911. t['blackleftpointingpointer'] = 0x25C4;
  5912. t['blackleftpointingtriangle'] = 0x25C0;
  5913. t['blacklenticularbracketleft'] = 0x3010;
  5914. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  5915. t['blacklenticularbracketright'] = 0x3011;
  5916. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  5917. t['blacklowerlefttriangle'] = 0x25E3;
  5918. t['blacklowerrighttriangle'] = 0x25E2;
  5919. t['blackrectangle'] = 0x25AC;
  5920. t['blackrightpointingpointer'] = 0x25BA;
  5921. t['blackrightpointingtriangle'] = 0x25B6;
  5922. t['blacksmallsquare'] = 0x25AA;
  5923. t['blacksmilingface'] = 0x263B;
  5924. t['blacksquare'] = 0x25A0;
  5925. t['blackstar'] = 0x2605;
  5926. t['blackupperlefttriangle'] = 0x25E4;
  5927. t['blackupperrighttriangle'] = 0x25E5;
  5928. t['blackuppointingsmalltriangle'] = 0x25B4;
  5929. t['blackuppointingtriangle'] = 0x25B2;
  5930. t['blank'] = 0x2423;
  5931. t['blinebelow'] = 0x1E07;
  5932. t['block'] = 0x2588;
  5933. t['bmonospace'] = 0xFF42;
  5934. t['bobaimaithai'] = 0x0E1A;
  5935. t['bohiragana'] = 0x307C;
  5936. t['bokatakana'] = 0x30DC;
  5937. t['bparen'] = 0x249D;
  5938. t['bqsquare'] = 0x33C3;
  5939. t['braceex'] = 0xF8F4;
  5940. t['braceleft'] = 0x007B;
  5941. t['braceleftbt'] = 0xF8F3;
  5942. t['braceleftmid'] = 0xF8F2;
  5943. t['braceleftmonospace'] = 0xFF5B;
  5944. t['braceleftsmall'] = 0xFE5B;
  5945. t['bracelefttp'] = 0xF8F1;
  5946. t['braceleftvertical'] = 0xFE37;
  5947. t['braceright'] = 0x007D;
  5948. t['bracerightbt'] = 0xF8FE;
  5949. t['bracerightmid'] = 0xF8FD;
  5950. t['bracerightmonospace'] = 0xFF5D;
  5951. t['bracerightsmall'] = 0xFE5C;
  5952. t['bracerighttp'] = 0xF8FC;
  5953. t['bracerightvertical'] = 0xFE38;
  5954. t['bracketleft'] = 0x005B;
  5955. t['bracketleftbt'] = 0xF8F0;
  5956. t['bracketleftex'] = 0xF8EF;
  5957. t['bracketleftmonospace'] = 0xFF3B;
  5958. t['bracketlefttp'] = 0xF8EE;
  5959. t['bracketright'] = 0x005D;
  5960. t['bracketrightbt'] = 0xF8FB;
  5961. t['bracketrightex'] = 0xF8FA;
  5962. t['bracketrightmonospace'] = 0xFF3D;
  5963. t['bracketrighttp'] = 0xF8F9;
  5964. t['breve'] = 0x02D8;
  5965. t['brevebelowcmb'] = 0x032E;
  5966. t['brevecmb'] = 0x0306;
  5967. t['breveinvertedbelowcmb'] = 0x032F;
  5968. t['breveinvertedcmb'] = 0x0311;
  5969. t['breveinverteddoublecmb'] = 0x0361;
  5970. t['bridgebelowcmb'] = 0x032A;
  5971. t['bridgeinvertedbelowcmb'] = 0x033A;
  5972. t['brokenbar'] = 0x00A6;
  5973. t['bstroke'] = 0x0180;
  5974. t['bsuperior'] = 0xF6EA;
  5975. t['btopbar'] = 0x0183;
  5976. t['buhiragana'] = 0x3076;
  5977. t['bukatakana'] = 0x30D6;
  5978. t['bullet'] = 0x2022;
  5979. t['bulletinverse'] = 0x25D8;
  5980. t['bulletoperator'] = 0x2219;
  5981. t['bullseye'] = 0x25CE;
  5982. t['c'] = 0x0063;
  5983. t['caarmenian'] = 0x056E;
  5984. t['cabengali'] = 0x099A;
  5985. t['cacute'] = 0x0107;
  5986. t['cadeva'] = 0x091A;
  5987. t['cagujarati'] = 0x0A9A;
  5988. t['cagurmukhi'] = 0x0A1A;
  5989. t['calsquare'] = 0x3388;
  5990. t['candrabindubengali'] = 0x0981;
  5991. t['candrabinducmb'] = 0x0310;
  5992. t['candrabindudeva'] = 0x0901;
  5993. t['candrabindugujarati'] = 0x0A81;
  5994. t['capslock'] = 0x21EA;
  5995. t['careof'] = 0x2105;
  5996. t['caron'] = 0x02C7;
  5997. t['caronbelowcmb'] = 0x032C;
  5998. t['caroncmb'] = 0x030C;
  5999. t['carriagereturn'] = 0x21B5;
  6000. t['cbopomofo'] = 0x3118;
  6001. t['ccaron'] = 0x010D;
  6002. t['ccedilla'] = 0x00E7;
  6003. t['ccedillaacute'] = 0x1E09;
  6004. t['ccircle'] = 0x24D2;
  6005. t['ccircumflex'] = 0x0109;
  6006. t['ccurl'] = 0x0255;
  6007. t['cdot'] = 0x010B;
  6008. t['cdotaccent'] = 0x010B;
  6009. t['cdsquare'] = 0x33C5;
  6010. t['cedilla'] = 0x00B8;
  6011. t['cedillacmb'] = 0x0327;
  6012. t['cent'] = 0x00A2;
  6013. t['centigrade'] = 0x2103;
  6014. t['centinferior'] = 0xF6DF;
  6015. t['centmonospace'] = 0xFFE0;
  6016. t['centoldstyle'] = 0xF7A2;
  6017. t['centsuperior'] = 0xF6E0;
  6018. t['chaarmenian'] = 0x0579;
  6019. t['chabengali'] = 0x099B;
  6020. t['chadeva'] = 0x091B;
  6021. t['chagujarati'] = 0x0A9B;
  6022. t['chagurmukhi'] = 0x0A1B;
  6023. t['chbopomofo'] = 0x3114;
  6024. t['cheabkhasiancyrillic'] = 0x04BD;
  6025. t['checkmark'] = 0x2713;
  6026. t['checyrillic'] = 0x0447;
  6027. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6028. t['chedescendercyrillic'] = 0x04B7;
  6029. t['chedieresiscyrillic'] = 0x04F5;
  6030. t['cheharmenian'] = 0x0573;
  6031. t['chekhakassiancyrillic'] = 0x04CC;
  6032. t['cheverticalstrokecyrillic'] = 0x04B9;
  6033. t['chi'] = 0x03C7;
  6034. t['chieuchacirclekorean'] = 0x3277;
  6035. t['chieuchaparenkorean'] = 0x3217;
  6036. t['chieuchcirclekorean'] = 0x3269;
  6037. t['chieuchkorean'] = 0x314A;
  6038. t['chieuchparenkorean'] = 0x3209;
  6039. t['chochangthai'] = 0x0E0A;
  6040. t['chochanthai'] = 0x0E08;
  6041. t['chochingthai'] = 0x0E09;
  6042. t['chochoethai'] = 0x0E0C;
  6043. t['chook'] = 0x0188;
  6044. t['cieucacirclekorean'] = 0x3276;
  6045. t['cieucaparenkorean'] = 0x3216;
  6046. t['cieuccirclekorean'] = 0x3268;
  6047. t['cieuckorean'] = 0x3148;
  6048. t['cieucparenkorean'] = 0x3208;
  6049. t['cieucuparenkorean'] = 0x321C;
  6050. t['circle'] = 0x25CB;
  6051. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6052. t['circlemultiply'] = 0x2297;
  6053. t['circleot'] = 0x2299;
  6054. t['circleplus'] = 0x2295;
  6055. t['circlepostalmark'] = 0x3036;
  6056. t['circlewithlefthalfblack'] = 0x25D0;
  6057. t['circlewithrighthalfblack'] = 0x25D1;
  6058. t['circumflex'] = 0x02C6;
  6059. t['circumflexbelowcmb'] = 0x032D;
  6060. t['circumflexcmb'] = 0x0302;
  6061. t['clear'] = 0x2327;
  6062. t['clickalveolar'] = 0x01C2;
  6063. t['clickdental'] = 0x01C0;
  6064. t['clicklateral'] = 0x01C1;
  6065. t['clickretroflex'] = 0x01C3;
  6066. t['club'] = 0x2663;
  6067. t['clubsuitblack'] = 0x2663;
  6068. t['clubsuitwhite'] = 0x2667;
  6069. t['cmcubedsquare'] = 0x33A4;
  6070. t['cmonospace'] = 0xFF43;
  6071. t['cmsquaredsquare'] = 0x33A0;
  6072. t['coarmenian'] = 0x0581;
  6073. t['colon'] = 0x003A;
  6074. t['colonmonetary'] = 0x20A1;
  6075. t['colonmonospace'] = 0xFF1A;
  6076. t['colonsign'] = 0x20A1;
  6077. t['colonsmall'] = 0xFE55;
  6078. t['colontriangularhalfmod'] = 0x02D1;
  6079. t['colontriangularmod'] = 0x02D0;
  6080. t['comma'] = 0x002C;
  6081. t['commaabovecmb'] = 0x0313;
  6082. t['commaaboverightcmb'] = 0x0315;
  6083. t['commaaccent'] = 0xF6C3;
  6084. t['commaarabic'] = 0x060C;
  6085. t['commaarmenian'] = 0x055D;
  6086. t['commainferior'] = 0xF6E1;
  6087. t['commamonospace'] = 0xFF0C;
  6088. t['commareversedabovecmb'] = 0x0314;
  6089. t['commareversedmod'] = 0x02BD;
  6090. t['commasmall'] = 0xFE50;
  6091. t['commasuperior'] = 0xF6E2;
  6092. t['commaturnedabovecmb'] = 0x0312;
  6093. t['commaturnedmod'] = 0x02BB;
  6094. t['compass'] = 0x263C;
  6095. t['congruent'] = 0x2245;
  6096. t['contourintegral'] = 0x222E;
  6097. t['control'] = 0x2303;
  6098. t['controlACK'] = 0x0006;
  6099. t['controlBEL'] = 0x0007;
  6100. t['controlBS'] = 0x0008;
  6101. t['controlCAN'] = 0x0018;
  6102. t['controlCR'] = 0x000D;
  6103. t['controlDC1'] = 0x0011;
  6104. t['controlDC2'] = 0x0012;
  6105. t['controlDC3'] = 0x0013;
  6106. t['controlDC4'] = 0x0014;
  6107. t['controlDEL'] = 0x007F;
  6108. t['controlDLE'] = 0x0010;
  6109. t['controlEM'] = 0x0019;
  6110. t['controlENQ'] = 0x0005;
  6111. t['controlEOT'] = 0x0004;
  6112. t['controlESC'] = 0x001B;
  6113. t['controlETB'] = 0x0017;
  6114. t['controlETX'] = 0x0003;
  6115. t['controlFF'] = 0x000C;
  6116. t['controlFS'] = 0x001C;
  6117. t['controlGS'] = 0x001D;
  6118. t['controlHT'] = 0x0009;
  6119. t['controlLF'] = 0x000A;
  6120. t['controlNAK'] = 0x0015;
  6121. t['controlRS'] = 0x001E;
  6122. t['controlSI'] = 0x000F;
  6123. t['controlSO'] = 0x000E;
  6124. t['controlSOT'] = 0x0002;
  6125. t['controlSTX'] = 0x0001;
  6126. t['controlSUB'] = 0x001A;
  6127. t['controlSYN'] = 0x0016;
  6128. t['controlUS'] = 0x001F;
  6129. t['controlVT'] = 0x000B;
  6130. t['copyright'] = 0x00A9;
  6131. t['copyrightsans'] = 0xF8E9;
  6132. t['copyrightserif'] = 0xF6D9;
  6133. t['cornerbracketleft'] = 0x300C;
  6134. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6135. t['cornerbracketleftvertical'] = 0xFE41;
  6136. t['cornerbracketright'] = 0x300D;
  6137. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6138. t['cornerbracketrightvertical'] = 0xFE42;
  6139. t['corporationsquare'] = 0x337F;
  6140. t['cosquare'] = 0x33C7;
  6141. t['coverkgsquare'] = 0x33C6;
  6142. t['cparen'] = 0x249E;
  6143. t['cruzeiro'] = 0x20A2;
  6144. t['cstretched'] = 0x0297;
  6145. t['curlyand'] = 0x22CF;
  6146. t['curlyor'] = 0x22CE;
  6147. t['currency'] = 0x00A4;
  6148. t['cyrBreve'] = 0xF6D1;
  6149. t['cyrFlex'] = 0xF6D2;
  6150. t['cyrbreve'] = 0xF6D4;
  6151. t['cyrflex'] = 0xF6D5;
  6152. t['d'] = 0x0064;
  6153. t['daarmenian'] = 0x0564;
  6154. t['dabengali'] = 0x09A6;
  6155. t['dadarabic'] = 0x0636;
  6156. t['dadeva'] = 0x0926;
  6157. t['dadfinalarabic'] = 0xFEBE;
  6158. t['dadinitialarabic'] = 0xFEBF;
  6159. t['dadmedialarabic'] = 0xFEC0;
  6160. t['dagesh'] = 0x05BC;
  6161. t['dageshhebrew'] = 0x05BC;
  6162. t['dagger'] = 0x2020;
  6163. t['daggerdbl'] = 0x2021;
  6164. t['dagujarati'] = 0x0AA6;
  6165. t['dagurmukhi'] = 0x0A26;
  6166. t['dahiragana'] = 0x3060;
  6167. t['dakatakana'] = 0x30C0;
  6168. t['dalarabic'] = 0x062F;
  6169. t['dalet'] = 0x05D3;
  6170. t['daletdagesh'] = 0xFB33;
  6171. t['daletdageshhebrew'] = 0xFB33;
  6172. t['dalethebrew'] = 0x05D3;
  6173. t['dalfinalarabic'] = 0xFEAA;
  6174. t['dammaarabic'] = 0x064F;
  6175. t['dammalowarabic'] = 0x064F;
  6176. t['dammatanaltonearabic'] = 0x064C;
  6177. t['dammatanarabic'] = 0x064C;
  6178. t['danda'] = 0x0964;
  6179. t['dargahebrew'] = 0x05A7;
  6180. t['dargalefthebrew'] = 0x05A7;
  6181. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6182. t['dblGrave'] = 0xF6D3;
  6183. t['dblanglebracketleft'] = 0x300A;
  6184. t['dblanglebracketleftvertical'] = 0xFE3D;
  6185. t['dblanglebracketright'] = 0x300B;
  6186. t['dblanglebracketrightvertical'] = 0xFE3E;
  6187. t['dblarchinvertedbelowcmb'] = 0x032B;
  6188. t['dblarrowleft'] = 0x21D4;
  6189. t['dblarrowright'] = 0x21D2;
  6190. t['dbldanda'] = 0x0965;
  6191. t['dblgrave'] = 0xF6D6;
  6192. t['dblgravecmb'] = 0x030F;
  6193. t['dblintegral'] = 0x222C;
  6194. t['dbllowline'] = 0x2017;
  6195. t['dbllowlinecmb'] = 0x0333;
  6196. t['dbloverlinecmb'] = 0x033F;
  6197. t['dblprimemod'] = 0x02BA;
  6198. t['dblverticalbar'] = 0x2016;
  6199. t['dblverticallineabovecmb'] = 0x030E;
  6200. t['dbopomofo'] = 0x3109;
  6201. t['dbsquare'] = 0x33C8;
  6202. t['dcaron'] = 0x010F;
  6203. t['dcedilla'] = 0x1E11;
  6204. t['dcircle'] = 0x24D3;
  6205. t['dcircumflexbelow'] = 0x1E13;
  6206. t['dcroat'] = 0x0111;
  6207. t['ddabengali'] = 0x09A1;
  6208. t['ddadeva'] = 0x0921;
  6209. t['ddagujarati'] = 0x0AA1;
  6210. t['ddagurmukhi'] = 0x0A21;
  6211. t['ddalarabic'] = 0x0688;
  6212. t['ddalfinalarabic'] = 0xFB89;
  6213. t['dddhadeva'] = 0x095C;
  6214. t['ddhabengali'] = 0x09A2;
  6215. t['ddhadeva'] = 0x0922;
  6216. t['ddhagujarati'] = 0x0AA2;
  6217. t['ddhagurmukhi'] = 0x0A22;
  6218. t['ddotaccent'] = 0x1E0B;
  6219. t['ddotbelow'] = 0x1E0D;
  6220. t['decimalseparatorarabic'] = 0x066B;
  6221. t['decimalseparatorpersian'] = 0x066B;
  6222. t['decyrillic'] = 0x0434;
  6223. t['degree'] = 0x00B0;
  6224. t['dehihebrew'] = 0x05AD;
  6225. t['dehiragana'] = 0x3067;
  6226. t['deicoptic'] = 0x03EF;
  6227. t['dekatakana'] = 0x30C7;
  6228. t['deleteleft'] = 0x232B;
  6229. t['deleteright'] = 0x2326;
  6230. t['delta'] = 0x03B4;
  6231. t['deltaturned'] = 0x018D;
  6232. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6233. t['dezh'] = 0x02A4;
  6234. t['dhabengali'] = 0x09A7;
  6235. t['dhadeva'] = 0x0927;
  6236. t['dhagujarati'] = 0x0AA7;
  6237. t['dhagurmukhi'] = 0x0A27;
  6238. t['dhook'] = 0x0257;
  6239. t['dialytikatonos'] = 0x0385;
  6240. t['dialytikatonoscmb'] = 0x0344;
  6241. t['diamond'] = 0x2666;
  6242. t['diamondsuitwhite'] = 0x2662;
  6243. t['dieresis'] = 0x00A8;
  6244. t['dieresisacute'] = 0xF6D7;
  6245. t['dieresisbelowcmb'] = 0x0324;
  6246. t['dieresiscmb'] = 0x0308;
  6247. t['dieresisgrave'] = 0xF6D8;
  6248. t['dieresistonos'] = 0x0385;
  6249. t['dihiragana'] = 0x3062;
  6250. t['dikatakana'] = 0x30C2;
  6251. t['dittomark'] = 0x3003;
  6252. t['divide'] = 0x00F7;
  6253. t['divides'] = 0x2223;
  6254. t['divisionslash'] = 0x2215;
  6255. t['djecyrillic'] = 0x0452;
  6256. t['dkshade'] = 0x2593;
  6257. t['dlinebelow'] = 0x1E0F;
  6258. t['dlsquare'] = 0x3397;
  6259. t['dmacron'] = 0x0111;
  6260. t['dmonospace'] = 0xFF44;
  6261. t['dnblock'] = 0x2584;
  6262. t['dochadathai'] = 0x0E0E;
  6263. t['dodekthai'] = 0x0E14;
  6264. t['dohiragana'] = 0x3069;
  6265. t['dokatakana'] = 0x30C9;
  6266. t['dollar'] = 0x0024;
  6267. t['dollarinferior'] = 0xF6E3;
  6268. t['dollarmonospace'] = 0xFF04;
  6269. t['dollaroldstyle'] = 0xF724;
  6270. t['dollarsmall'] = 0xFE69;
  6271. t['dollarsuperior'] = 0xF6E4;
  6272. t['dong'] = 0x20AB;
  6273. t['dorusquare'] = 0x3326;
  6274. t['dotaccent'] = 0x02D9;
  6275. t['dotaccentcmb'] = 0x0307;
  6276. t['dotbelowcmb'] = 0x0323;
  6277. t['dotbelowcomb'] = 0x0323;
  6278. t['dotkatakana'] = 0x30FB;
  6279. t['dotlessi'] = 0x0131;
  6280. t['dotlessj'] = 0xF6BE;
  6281. t['dotlessjstrokehook'] = 0x0284;
  6282. t['dotmath'] = 0x22C5;
  6283. t['dottedcircle'] = 0x25CC;
  6284. t['doubleyodpatah'] = 0xFB1F;
  6285. t['doubleyodpatahhebrew'] = 0xFB1F;
  6286. t['downtackbelowcmb'] = 0x031E;
  6287. t['downtackmod'] = 0x02D5;
  6288. t['dparen'] = 0x249F;
  6289. t['dsuperior'] = 0xF6EB;
  6290. t['dtail'] = 0x0256;
  6291. t['dtopbar'] = 0x018C;
  6292. t['duhiragana'] = 0x3065;
  6293. t['dukatakana'] = 0x30C5;
  6294. t['dz'] = 0x01F3;
  6295. t['dzaltone'] = 0x02A3;
  6296. t['dzcaron'] = 0x01C6;
  6297. t['dzcurl'] = 0x02A5;
  6298. t['dzeabkhasiancyrillic'] = 0x04E1;
  6299. t['dzecyrillic'] = 0x0455;
  6300. t['dzhecyrillic'] = 0x045F;
  6301. t['e'] = 0x0065;
  6302. t['eacute'] = 0x00E9;
  6303. t['earth'] = 0x2641;
  6304. t['ebengali'] = 0x098F;
  6305. t['ebopomofo'] = 0x311C;
  6306. t['ebreve'] = 0x0115;
  6307. t['ecandradeva'] = 0x090D;
  6308. t['ecandragujarati'] = 0x0A8D;
  6309. t['ecandravowelsigndeva'] = 0x0945;
  6310. t['ecandravowelsigngujarati'] = 0x0AC5;
  6311. t['ecaron'] = 0x011B;
  6312. t['ecedillabreve'] = 0x1E1D;
  6313. t['echarmenian'] = 0x0565;
  6314. t['echyiwnarmenian'] = 0x0587;
  6315. t['ecircle'] = 0x24D4;
  6316. t['ecircumflex'] = 0x00EA;
  6317. t['ecircumflexacute'] = 0x1EBF;
  6318. t['ecircumflexbelow'] = 0x1E19;
  6319. t['ecircumflexdotbelow'] = 0x1EC7;
  6320. t['ecircumflexgrave'] = 0x1EC1;
  6321. t['ecircumflexhookabove'] = 0x1EC3;
  6322. t['ecircumflextilde'] = 0x1EC5;
  6323. t['ecyrillic'] = 0x0454;
  6324. t['edblgrave'] = 0x0205;
  6325. t['edeva'] = 0x090F;
  6326. t['edieresis'] = 0x00EB;
  6327. t['edot'] = 0x0117;
  6328. t['edotaccent'] = 0x0117;
  6329. t['edotbelow'] = 0x1EB9;
  6330. t['eegurmukhi'] = 0x0A0F;
  6331. t['eematragurmukhi'] = 0x0A47;
  6332. t['efcyrillic'] = 0x0444;
  6333. t['egrave'] = 0x00E8;
  6334. t['egujarati'] = 0x0A8F;
  6335. t['eharmenian'] = 0x0567;
  6336. t['ehbopomofo'] = 0x311D;
  6337. t['ehiragana'] = 0x3048;
  6338. t['ehookabove'] = 0x1EBB;
  6339. t['eibopomofo'] = 0x311F;
  6340. t['eight'] = 0x0038;
  6341. t['eightarabic'] = 0x0668;
  6342. t['eightbengali'] = 0x09EE;
  6343. t['eightcircle'] = 0x2467;
  6344. t['eightcircleinversesansserif'] = 0x2791;
  6345. t['eightdeva'] = 0x096E;
  6346. t['eighteencircle'] = 0x2471;
  6347. t['eighteenparen'] = 0x2485;
  6348. t['eighteenperiod'] = 0x2499;
  6349. t['eightgujarati'] = 0x0AEE;
  6350. t['eightgurmukhi'] = 0x0A6E;
  6351. t['eighthackarabic'] = 0x0668;
  6352. t['eighthangzhou'] = 0x3028;
  6353. t['eighthnotebeamed'] = 0x266B;
  6354. t['eightideographicparen'] = 0x3227;
  6355. t['eightinferior'] = 0x2088;
  6356. t['eightmonospace'] = 0xFF18;
  6357. t['eightoldstyle'] = 0xF738;
  6358. t['eightparen'] = 0x247B;
  6359. t['eightperiod'] = 0x248F;
  6360. t['eightpersian'] = 0x06F8;
  6361. t['eightroman'] = 0x2177;
  6362. t['eightsuperior'] = 0x2078;
  6363. t['eightthai'] = 0x0E58;
  6364. t['einvertedbreve'] = 0x0207;
  6365. t['eiotifiedcyrillic'] = 0x0465;
  6366. t['ekatakana'] = 0x30A8;
  6367. t['ekatakanahalfwidth'] = 0xFF74;
  6368. t['ekonkargurmukhi'] = 0x0A74;
  6369. t['ekorean'] = 0x3154;
  6370. t['elcyrillic'] = 0x043B;
  6371. t['element'] = 0x2208;
  6372. t['elevencircle'] = 0x246A;
  6373. t['elevenparen'] = 0x247E;
  6374. t['elevenperiod'] = 0x2492;
  6375. t['elevenroman'] = 0x217A;
  6376. t['ellipsis'] = 0x2026;
  6377. t['ellipsisvertical'] = 0x22EE;
  6378. t['emacron'] = 0x0113;
  6379. t['emacronacute'] = 0x1E17;
  6380. t['emacrongrave'] = 0x1E15;
  6381. t['emcyrillic'] = 0x043C;
  6382. t['emdash'] = 0x2014;
  6383. t['emdashvertical'] = 0xFE31;
  6384. t['emonospace'] = 0xFF45;
  6385. t['emphasismarkarmenian'] = 0x055B;
  6386. t['emptyset'] = 0x2205;
  6387. t['enbopomofo'] = 0x3123;
  6388. t['encyrillic'] = 0x043D;
  6389. t['endash'] = 0x2013;
  6390. t['endashvertical'] = 0xFE32;
  6391. t['endescendercyrillic'] = 0x04A3;
  6392. t['eng'] = 0x014B;
  6393. t['engbopomofo'] = 0x3125;
  6394. t['enghecyrillic'] = 0x04A5;
  6395. t['enhookcyrillic'] = 0x04C8;
  6396. t['enspace'] = 0x2002;
  6397. t['eogonek'] = 0x0119;
  6398. t['eokorean'] = 0x3153;
  6399. t['eopen'] = 0x025B;
  6400. t['eopenclosed'] = 0x029A;
  6401. t['eopenreversed'] = 0x025C;
  6402. t['eopenreversedclosed'] = 0x025E;
  6403. t['eopenreversedhook'] = 0x025D;
  6404. t['eparen'] = 0x24A0;
  6405. t['epsilon'] = 0x03B5;
  6406. t['epsilontonos'] = 0x03AD;
  6407. t['equal'] = 0x003D;
  6408. t['equalmonospace'] = 0xFF1D;
  6409. t['equalsmall'] = 0xFE66;
  6410. t['equalsuperior'] = 0x207C;
  6411. t['equivalence'] = 0x2261;
  6412. t['erbopomofo'] = 0x3126;
  6413. t['ercyrillic'] = 0x0440;
  6414. t['ereversed'] = 0x0258;
  6415. t['ereversedcyrillic'] = 0x044D;
  6416. t['escyrillic'] = 0x0441;
  6417. t['esdescendercyrillic'] = 0x04AB;
  6418. t['esh'] = 0x0283;
  6419. t['eshcurl'] = 0x0286;
  6420. t['eshortdeva'] = 0x090E;
  6421. t['eshortvowelsigndeva'] = 0x0946;
  6422. t['eshreversedloop'] = 0x01AA;
  6423. t['eshsquatreversed'] = 0x0285;
  6424. t['esmallhiragana'] = 0x3047;
  6425. t['esmallkatakana'] = 0x30A7;
  6426. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6427. t['estimated'] = 0x212E;
  6428. t['esuperior'] = 0xF6EC;
  6429. t['eta'] = 0x03B7;
  6430. t['etarmenian'] = 0x0568;
  6431. t['etatonos'] = 0x03AE;
  6432. t['eth'] = 0x00F0;
  6433. t['etilde'] = 0x1EBD;
  6434. t['etildebelow'] = 0x1E1B;
  6435. t['etnahtafoukhhebrew'] = 0x0591;
  6436. t['etnahtafoukhlefthebrew'] = 0x0591;
  6437. t['etnahtahebrew'] = 0x0591;
  6438. t['etnahtalefthebrew'] = 0x0591;
  6439. t['eturned'] = 0x01DD;
  6440. t['eukorean'] = 0x3161;
  6441. t['euro'] = 0x20AC;
  6442. t['evowelsignbengali'] = 0x09C7;
  6443. t['evowelsigndeva'] = 0x0947;
  6444. t['evowelsigngujarati'] = 0x0AC7;
  6445. t['exclam'] = 0x0021;
  6446. t['exclamarmenian'] = 0x055C;
  6447. t['exclamdbl'] = 0x203C;
  6448. t['exclamdown'] = 0x00A1;
  6449. t['exclamdownsmall'] = 0xF7A1;
  6450. t['exclammonospace'] = 0xFF01;
  6451. t['exclamsmall'] = 0xF721;
  6452. t['existential'] = 0x2203;
  6453. t['ezh'] = 0x0292;
  6454. t['ezhcaron'] = 0x01EF;
  6455. t['ezhcurl'] = 0x0293;
  6456. t['ezhreversed'] = 0x01B9;
  6457. t['ezhtail'] = 0x01BA;
  6458. t['f'] = 0x0066;
  6459. t['fadeva'] = 0x095E;
  6460. t['fagurmukhi'] = 0x0A5E;
  6461. t['fahrenheit'] = 0x2109;
  6462. t['fathaarabic'] = 0x064E;
  6463. t['fathalowarabic'] = 0x064E;
  6464. t['fathatanarabic'] = 0x064B;
  6465. t['fbopomofo'] = 0x3108;
  6466. t['fcircle'] = 0x24D5;
  6467. t['fdotaccent'] = 0x1E1F;
  6468. t['feharabic'] = 0x0641;
  6469. t['feharmenian'] = 0x0586;
  6470. t['fehfinalarabic'] = 0xFED2;
  6471. t['fehinitialarabic'] = 0xFED3;
  6472. t['fehmedialarabic'] = 0xFED4;
  6473. t['feicoptic'] = 0x03E5;
  6474. t['female'] = 0x2640;
  6475. t['ff'] = 0xFB00;
  6476. t['ffi'] = 0xFB03;
  6477. t['ffl'] = 0xFB04;
  6478. t['fi'] = 0xFB01;
  6479. t['fifteencircle'] = 0x246E;
  6480. t['fifteenparen'] = 0x2482;
  6481. t['fifteenperiod'] = 0x2496;
  6482. t['figuredash'] = 0x2012;
  6483. t['filledbox'] = 0x25A0;
  6484. t['filledrect'] = 0x25AC;
  6485. t['finalkaf'] = 0x05DA;
  6486. t['finalkafdagesh'] = 0xFB3A;
  6487. t['finalkafdageshhebrew'] = 0xFB3A;
  6488. t['finalkafhebrew'] = 0x05DA;
  6489. t['finalmem'] = 0x05DD;
  6490. t['finalmemhebrew'] = 0x05DD;
  6491. t['finalnun'] = 0x05DF;
  6492. t['finalnunhebrew'] = 0x05DF;
  6493. t['finalpe'] = 0x05E3;
  6494. t['finalpehebrew'] = 0x05E3;
  6495. t['finaltsadi'] = 0x05E5;
  6496. t['finaltsadihebrew'] = 0x05E5;
  6497. t['firsttonechinese'] = 0x02C9;
  6498. t['fisheye'] = 0x25C9;
  6499. t['fitacyrillic'] = 0x0473;
  6500. t['five'] = 0x0035;
  6501. t['fivearabic'] = 0x0665;
  6502. t['fivebengali'] = 0x09EB;
  6503. t['fivecircle'] = 0x2464;
  6504. t['fivecircleinversesansserif'] = 0x278E;
  6505. t['fivedeva'] = 0x096B;
  6506. t['fiveeighths'] = 0x215D;
  6507. t['fivegujarati'] = 0x0AEB;
  6508. t['fivegurmukhi'] = 0x0A6B;
  6509. t['fivehackarabic'] = 0x0665;
  6510. t['fivehangzhou'] = 0x3025;
  6511. t['fiveideographicparen'] = 0x3224;
  6512. t['fiveinferior'] = 0x2085;
  6513. t['fivemonospace'] = 0xFF15;
  6514. t['fiveoldstyle'] = 0xF735;
  6515. t['fiveparen'] = 0x2478;
  6516. t['fiveperiod'] = 0x248C;
  6517. t['fivepersian'] = 0x06F5;
  6518. t['fiveroman'] = 0x2174;
  6519. t['fivesuperior'] = 0x2075;
  6520. t['fivethai'] = 0x0E55;
  6521. t['fl'] = 0xFB02;
  6522. t['florin'] = 0x0192;
  6523. t['fmonospace'] = 0xFF46;
  6524. t['fmsquare'] = 0x3399;
  6525. t['fofanthai'] = 0x0E1F;
  6526. t['fofathai'] = 0x0E1D;
  6527. t['fongmanthai'] = 0x0E4F;
  6528. t['forall'] = 0x2200;
  6529. t['four'] = 0x0034;
  6530. t['fourarabic'] = 0x0664;
  6531. t['fourbengali'] = 0x09EA;
  6532. t['fourcircle'] = 0x2463;
  6533. t['fourcircleinversesansserif'] = 0x278D;
  6534. t['fourdeva'] = 0x096A;
  6535. t['fourgujarati'] = 0x0AEA;
  6536. t['fourgurmukhi'] = 0x0A6A;
  6537. t['fourhackarabic'] = 0x0664;
  6538. t['fourhangzhou'] = 0x3024;
  6539. t['fourideographicparen'] = 0x3223;
  6540. t['fourinferior'] = 0x2084;
  6541. t['fourmonospace'] = 0xFF14;
  6542. t['fournumeratorbengali'] = 0x09F7;
  6543. t['fouroldstyle'] = 0xF734;
  6544. t['fourparen'] = 0x2477;
  6545. t['fourperiod'] = 0x248B;
  6546. t['fourpersian'] = 0x06F4;
  6547. t['fourroman'] = 0x2173;
  6548. t['foursuperior'] = 0x2074;
  6549. t['fourteencircle'] = 0x246D;
  6550. t['fourteenparen'] = 0x2481;
  6551. t['fourteenperiod'] = 0x2495;
  6552. t['fourthai'] = 0x0E54;
  6553. t['fourthtonechinese'] = 0x02CB;
  6554. t['fparen'] = 0x24A1;
  6555. t['fraction'] = 0x2044;
  6556. t['franc'] = 0x20A3;
  6557. t['g'] = 0x0067;
  6558. t['gabengali'] = 0x0997;
  6559. t['gacute'] = 0x01F5;
  6560. t['gadeva'] = 0x0917;
  6561. t['gafarabic'] = 0x06AF;
  6562. t['gaffinalarabic'] = 0xFB93;
  6563. t['gafinitialarabic'] = 0xFB94;
  6564. t['gafmedialarabic'] = 0xFB95;
  6565. t['gagujarati'] = 0x0A97;
  6566. t['gagurmukhi'] = 0x0A17;
  6567. t['gahiragana'] = 0x304C;
  6568. t['gakatakana'] = 0x30AC;
  6569. t['gamma'] = 0x03B3;
  6570. t['gammalatinsmall'] = 0x0263;
  6571. t['gammasuperior'] = 0x02E0;
  6572. t['gangiacoptic'] = 0x03EB;
  6573. t['gbopomofo'] = 0x310D;
  6574. t['gbreve'] = 0x011F;
  6575. t['gcaron'] = 0x01E7;
  6576. t['gcedilla'] = 0x0123;
  6577. t['gcircle'] = 0x24D6;
  6578. t['gcircumflex'] = 0x011D;
  6579. t['gcommaaccent'] = 0x0123;
  6580. t['gdot'] = 0x0121;
  6581. t['gdotaccent'] = 0x0121;
  6582. t['gecyrillic'] = 0x0433;
  6583. t['gehiragana'] = 0x3052;
  6584. t['gekatakana'] = 0x30B2;
  6585. t['geometricallyequal'] = 0x2251;
  6586. t['gereshaccenthebrew'] = 0x059C;
  6587. t['gereshhebrew'] = 0x05F3;
  6588. t['gereshmuqdamhebrew'] = 0x059D;
  6589. t['germandbls'] = 0x00DF;
  6590. t['gershayimaccenthebrew'] = 0x059E;
  6591. t['gershayimhebrew'] = 0x05F4;
  6592. t['getamark'] = 0x3013;
  6593. t['ghabengali'] = 0x0998;
  6594. t['ghadarmenian'] = 0x0572;
  6595. t['ghadeva'] = 0x0918;
  6596. t['ghagujarati'] = 0x0A98;
  6597. t['ghagurmukhi'] = 0x0A18;
  6598. t['ghainarabic'] = 0x063A;
  6599. t['ghainfinalarabic'] = 0xFECE;
  6600. t['ghaininitialarabic'] = 0xFECF;
  6601. t['ghainmedialarabic'] = 0xFED0;
  6602. t['ghemiddlehookcyrillic'] = 0x0495;
  6603. t['ghestrokecyrillic'] = 0x0493;
  6604. t['gheupturncyrillic'] = 0x0491;
  6605. t['ghhadeva'] = 0x095A;
  6606. t['ghhagurmukhi'] = 0x0A5A;
  6607. t['ghook'] = 0x0260;
  6608. t['ghzsquare'] = 0x3393;
  6609. t['gihiragana'] = 0x304E;
  6610. t['gikatakana'] = 0x30AE;
  6611. t['gimarmenian'] = 0x0563;
  6612. t['gimel'] = 0x05D2;
  6613. t['gimeldagesh'] = 0xFB32;
  6614. t['gimeldageshhebrew'] = 0xFB32;
  6615. t['gimelhebrew'] = 0x05D2;
  6616. t['gjecyrillic'] = 0x0453;
  6617. t['glottalinvertedstroke'] = 0x01BE;
  6618. t['glottalstop'] = 0x0294;
  6619. t['glottalstopinverted'] = 0x0296;
  6620. t['glottalstopmod'] = 0x02C0;
  6621. t['glottalstopreversed'] = 0x0295;
  6622. t['glottalstopreversedmod'] = 0x02C1;
  6623. t['glottalstopreversedsuperior'] = 0x02E4;
  6624. t['glottalstopstroke'] = 0x02A1;
  6625. t['glottalstopstrokereversed'] = 0x02A2;
  6626. t['gmacron'] = 0x1E21;
  6627. t['gmonospace'] = 0xFF47;
  6628. t['gohiragana'] = 0x3054;
  6629. t['gokatakana'] = 0x30B4;
  6630. t['gparen'] = 0x24A2;
  6631. t['gpasquare'] = 0x33AC;
  6632. t['gradient'] = 0x2207;
  6633. t['grave'] = 0x0060;
  6634. t['gravebelowcmb'] = 0x0316;
  6635. t['gravecmb'] = 0x0300;
  6636. t['gravecomb'] = 0x0300;
  6637. t['gravedeva'] = 0x0953;
  6638. t['gravelowmod'] = 0x02CE;
  6639. t['gravemonospace'] = 0xFF40;
  6640. t['gravetonecmb'] = 0x0340;
  6641. t['greater'] = 0x003E;
  6642. t['greaterequal'] = 0x2265;
  6643. t['greaterequalorless'] = 0x22DB;
  6644. t['greatermonospace'] = 0xFF1E;
  6645. t['greaterorequivalent'] = 0x2273;
  6646. t['greaterorless'] = 0x2277;
  6647. t['greateroverequal'] = 0x2267;
  6648. t['greatersmall'] = 0xFE65;
  6649. t['gscript'] = 0x0261;
  6650. t['gstroke'] = 0x01E5;
  6651. t['guhiragana'] = 0x3050;
  6652. t['guillemotleft'] = 0x00AB;
  6653. t['guillemotright'] = 0x00BB;
  6654. t['guilsinglleft'] = 0x2039;
  6655. t['guilsinglright'] = 0x203A;
  6656. t['gukatakana'] = 0x30B0;
  6657. t['guramusquare'] = 0x3318;
  6658. t['gysquare'] = 0x33C9;
  6659. t['h'] = 0x0068;
  6660. t['haabkhasiancyrillic'] = 0x04A9;
  6661. t['haaltonearabic'] = 0x06C1;
  6662. t['habengali'] = 0x09B9;
  6663. t['hadescendercyrillic'] = 0x04B3;
  6664. t['hadeva'] = 0x0939;
  6665. t['hagujarati'] = 0x0AB9;
  6666. t['hagurmukhi'] = 0x0A39;
  6667. t['haharabic'] = 0x062D;
  6668. t['hahfinalarabic'] = 0xFEA2;
  6669. t['hahinitialarabic'] = 0xFEA3;
  6670. t['hahiragana'] = 0x306F;
  6671. t['hahmedialarabic'] = 0xFEA4;
  6672. t['haitusquare'] = 0x332A;
  6673. t['hakatakana'] = 0x30CF;
  6674. t['hakatakanahalfwidth'] = 0xFF8A;
  6675. t['halantgurmukhi'] = 0x0A4D;
  6676. t['hamzaarabic'] = 0x0621;
  6677. t['hamzalowarabic'] = 0x0621;
  6678. t['hangulfiller'] = 0x3164;
  6679. t['hardsigncyrillic'] = 0x044A;
  6680. t['harpoonleftbarbup'] = 0x21BC;
  6681. t['harpoonrightbarbup'] = 0x21C0;
  6682. t['hasquare'] = 0x33CA;
  6683. t['hatafpatah'] = 0x05B2;
  6684. t['hatafpatah16'] = 0x05B2;
  6685. t['hatafpatah23'] = 0x05B2;
  6686. t['hatafpatah2f'] = 0x05B2;
  6687. t['hatafpatahhebrew'] = 0x05B2;
  6688. t['hatafpatahnarrowhebrew'] = 0x05B2;
  6689. t['hatafpatahquarterhebrew'] = 0x05B2;
  6690. t['hatafpatahwidehebrew'] = 0x05B2;
  6691. t['hatafqamats'] = 0x05B3;
  6692. t['hatafqamats1b'] = 0x05B3;
  6693. t['hatafqamats28'] = 0x05B3;
  6694. t['hatafqamats34'] = 0x05B3;
  6695. t['hatafqamatshebrew'] = 0x05B3;
  6696. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  6697. t['hatafqamatsquarterhebrew'] = 0x05B3;
  6698. t['hatafqamatswidehebrew'] = 0x05B3;
  6699. t['hatafsegol'] = 0x05B1;
  6700. t['hatafsegol17'] = 0x05B1;
  6701. t['hatafsegol24'] = 0x05B1;
  6702. t['hatafsegol30'] = 0x05B1;
  6703. t['hatafsegolhebrew'] = 0x05B1;
  6704. t['hatafsegolnarrowhebrew'] = 0x05B1;
  6705. t['hatafsegolquarterhebrew'] = 0x05B1;
  6706. t['hatafsegolwidehebrew'] = 0x05B1;
  6707. t['hbar'] = 0x0127;
  6708. t['hbopomofo'] = 0x310F;
  6709. t['hbrevebelow'] = 0x1E2B;
  6710. t['hcedilla'] = 0x1E29;
  6711. t['hcircle'] = 0x24D7;
  6712. t['hcircumflex'] = 0x0125;
  6713. t['hdieresis'] = 0x1E27;
  6714. t['hdotaccent'] = 0x1E23;
  6715. t['hdotbelow'] = 0x1E25;
  6716. t['he'] = 0x05D4;
  6717. t['heart'] = 0x2665;
  6718. t['heartsuitblack'] = 0x2665;
  6719. t['heartsuitwhite'] = 0x2661;
  6720. t['hedagesh'] = 0xFB34;
  6721. t['hedageshhebrew'] = 0xFB34;
  6722. t['hehaltonearabic'] = 0x06C1;
  6723. t['heharabic'] = 0x0647;
  6724. t['hehebrew'] = 0x05D4;
  6725. t['hehfinalaltonearabic'] = 0xFBA7;
  6726. t['hehfinalalttwoarabic'] = 0xFEEA;
  6727. t['hehfinalarabic'] = 0xFEEA;
  6728. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  6729. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  6730. t['hehinitialaltonearabic'] = 0xFBA8;
  6731. t['hehinitialarabic'] = 0xFEEB;
  6732. t['hehiragana'] = 0x3078;
  6733. t['hehmedialaltonearabic'] = 0xFBA9;
  6734. t['hehmedialarabic'] = 0xFEEC;
  6735. t['heiseierasquare'] = 0x337B;
  6736. t['hekatakana'] = 0x30D8;
  6737. t['hekatakanahalfwidth'] = 0xFF8D;
  6738. t['hekutaarusquare'] = 0x3336;
  6739. t['henghook'] = 0x0267;
  6740. t['herutusquare'] = 0x3339;
  6741. t['het'] = 0x05D7;
  6742. t['hethebrew'] = 0x05D7;
  6743. t['hhook'] = 0x0266;
  6744. t['hhooksuperior'] = 0x02B1;
  6745. t['hieuhacirclekorean'] = 0x327B;
  6746. t['hieuhaparenkorean'] = 0x321B;
  6747. t['hieuhcirclekorean'] = 0x326D;
  6748. t['hieuhkorean'] = 0x314E;
  6749. t['hieuhparenkorean'] = 0x320D;
  6750. t['hihiragana'] = 0x3072;
  6751. t['hikatakana'] = 0x30D2;
  6752. t['hikatakanahalfwidth'] = 0xFF8B;
  6753. t['hiriq'] = 0x05B4;
  6754. t['hiriq14'] = 0x05B4;
  6755. t['hiriq21'] = 0x05B4;
  6756. t['hiriq2d'] = 0x05B4;
  6757. t['hiriqhebrew'] = 0x05B4;
  6758. t['hiriqnarrowhebrew'] = 0x05B4;
  6759. t['hiriqquarterhebrew'] = 0x05B4;
  6760. t['hiriqwidehebrew'] = 0x05B4;
  6761. t['hlinebelow'] = 0x1E96;
  6762. t['hmonospace'] = 0xFF48;
  6763. t['hoarmenian'] = 0x0570;
  6764. t['hohipthai'] = 0x0E2B;
  6765. t['hohiragana'] = 0x307B;
  6766. t['hokatakana'] = 0x30DB;
  6767. t['hokatakanahalfwidth'] = 0xFF8E;
  6768. t['holam'] = 0x05B9;
  6769. t['holam19'] = 0x05B9;
  6770. t['holam26'] = 0x05B9;
  6771. t['holam32'] = 0x05B9;
  6772. t['holamhebrew'] = 0x05B9;
  6773. t['holamnarrowhebrew'] = 0x05B9;
  6774. t['holamquarterhebrew'] = 0x05B9;
  6775. t['holamwidehebrew'] = 0x05B9;
  6776. t['honokhukthai'] = 0x0E2E;
  6777. t['hookabovecomb'] = 0x0309;
  6778. t['hookcmb'] = 0x0309;
  6779. t['hookpalatalizedbelowcmb'] = 0x0321;
  6780. t['hookretroflexbelowcmb'] = 0x0322;
  6781. t['hoonsquare'] = 0x3342;
  6782. t['horicoptic'] = 0x03E9;
  6783. t['horizontalbar'] = 0x2015;
  6784. t['horncmb'] = 0x031B;
  6785. t['hotsprings'] = 0x2668;
  6786. t['house'] = 0x2302;
  6787. t['hparen'] = 0x24A3;
  6788. t['hsuperior'] = 0x02B0;
  6789. t['hturned'] = 0x0265;
  6790. t['huhiragana'] = 0x3075;
  6791. t['huiitosquare'] = 0x3333;
  6792. t['hukatakana'] = 0x30D5;
  6793. t['hukatakanahalfwidth'] = 0xFF8C;
  6794. t['hungarumlaut'] = 0x02DD;
  6795. t['hungarumlautcmb'] = 0x030B;
  6796. t['hv'] = 0x0195;
  6797. t['hyphen'] = 0x002D;
  6798. t['hypheninferior'] = 0xF6E5;
  6799. t['hyphenmonospace'] = 0xFF0D;
  6800. t['hyphensmall'] = 0xFE63;
  6801. t['hyphensuperior'] = 0xF6E6;
  6802. t['hyphentwo'] = 0x2010;
  6803. t['i'] = 0x0069;
  6804. t['iacute'] = 0x00ED;
  6805. t['iacyrillic'] = 0x044F;
  6806. t['ibengali'] = 0x0987;
  6807. t['ibopomofo'] = 0x3127;
  6808. t['ibreve'] = 0x012D;
  6809. t['icaron'] = 0x01D0;
  6810. t['icircle'] = 0x24D8;
  6811. t['icircumflex'] = 0x00EE;
  6812. t['icyrillic'] = 0x0456;
  6813. t['idblgrave'] = 0x0209;
  6814. t['ideographearthcircle'] = 0x328F;
  6815. t['ideographfirecircle'] = 0x328B;
  6816. t['ideographicallianceparen'] = 0x323F;
  6817. t['ideographiccallparen'] = 0x323A;
  6818. t['ideographiccentrecircle'] = 0x32A5;
  6819. t['ideographicclose'] = 0x3006;
  6820. t['ideographiccomma'] = 0x3001;
  6821. t['ideographiccommaleft'] = 0xFF64;
  6822. t['ideographiccongratulationparen'] = 0x3237;
  6823. t['ideographiccorrectcircle'] = 0x32A3;
  6824. t['ideographicearthparen'] = 0x322F;
  6825. t['ideographicenterpriseparen'] = 0x323D;
  6826. t['ideographicexcellentcircle'] = 0x329D;
  6827. t['ideographicfestivalparen'] = 0x3240;
  6828. t['ideographicfinancialcircle'] = 0x3296;
  6829. t['ideographicfinancialparen'] = 0x3236;
  6830. t['ideographicfireparen'] = 0x322B;
  6831. t['ideographichaveparen'] = 0x3232;
  6832. t['ideographichighcircle'] = 0x32A4;
  6833. t['ideographiciterationmark'] = 0x3005;
  6834. t['ideographiclaborcircle'] = 0x3298;
  6835. t['ideographiclaborparen'] = 0x3238;
  6836. t['ideographicleftcircle'] = 0x32A7;
  6837. t['ideographiclowcircle'] = 0x32A6;
  6838. t['ideographicmedicinecircle'] = 0x32A9;
  6839. t['ideographicmetalparen'] = 0x322E;
  6840. t['ideographicmoonparen'] = 0x322A;
  6841. t['ideographicnameparen'] = 0x3234;
  6842. t['ideographicperiod'] = 0x3002;
  6843. t['ideographicprintcircle'] = 0x329E;
  6844. t['ideographicreachparen'] = 0x3243;
  6845. t['ideographicrepresentparen'] = 0x3239;
  6846. t['ideographicresourceparen'] = 0x323E;
  6847. t['ideographicrightcircle'] = 0x32A8;
  6848. t['ideographicsecretcircle'] = 0x3299;
  6849. t['ideographicselfparen'] = 0x3242;
  6850. t['ideographicsocietyparen'] = 0x3233;
  6851. t['ideographicspace'] = 0x3000;
  6852. t['ideographicspecialparen'] = 0x3235;
  6853. t['ideographicstockparen'] = 0x3231;
  6854. t['ideographicstudyparen'] = 0x323B;
  6855. t['ideographicsunparen'] = 0x3230;
  6856. t['ideographicsuperviseparen'] = 0x323C;
  6857. t['ideographicwaterparen'] = 0x322C;
  6858. t['ideographicwoodparen'] = 0x322D;
  6859. t['ideographiczero'] = 0x3007;
  6860. t['ideographmetalcircle'] = 0x328E;
  6861. t['ideographmooncircle'] = 0x328A;
  6862. t['ideographnamecircle'] = 0x3294;
  6863. t['ideographsuncircle'] = 0x3290;
  6864. t['ideographwatercircle'] = 0x328C;
  6865. t['ideographwoodcircle'] = 0x328D;
  6866. t['ideva'] = 0x0907;
  6867. t['idieresis'] = 0x00EF;
  6868. t['idieresisacute'] = 0x1E2F;
  6869. t['idieresiscyrillic'] = 0x04E5;
  6870. t['idotbelow'] = 0x1ECB;
  6871. t['iebrevecyrillic'] = 0x04D7;
  6872. t['iecyrillic'] = 0x0435;
  6873. t['ieungacirclekorean'] = 0x3275;
  6874. t['ieungaparenkorean'] = 0x3215;
  6875. t['ieungcirclekorean'] = 0x3267;
  6876. t['ieungkorean'] = 0x3147;
  6877. t['ieungparenkorean'] = 0x3207;
  6878. t['igrave'] = 0x00EC;
  6879. t['igujarati'] = 0x0A87;
  6880. t['igurmukhi'] = 0x0A07;
  6881. t['ihiragana'] = 0x3044;
  6882. t['ihookabove'] = 0x1EC9;
  6883. t['iibengali'] = 0x0988;
  6884. t['iicyrillic'] = 0x0438;
  6885. t['iideva'] = 0x0908;
  6886. t['iigujarati'] = 0x0A88;
  6887. t['iigurmukhi'] = 0x0A08;
  6888. t['iimatragurmukhi'] = 0x0A40;
  6889. t['iinvertedbreve'] = 0x020B;
  6890. t['iishortcyrillic'] = 0x0439;
  6891. t['iivowelsignbengali'] = 0x09C0;
  6892. t['iivowelsigndeva'] = 0x0940;
  6893. t['iivowelsigngujarati'] = 0x0AC0;
  6894. t['ij'] = 0x0133;
  6895. t['ikatakana'] = 0x30A4;
  6896. t['ikatakanahalfwidth'] = 0xFF72;
  6897. t['ikorean'] = 0x3163;
  6898. t['ilde'] = 0x02DC;
  6899. t['iluyhebrew'] = 0x05AC;
  6900. t['imacron'] = 0x012B;
  6901. t['imacroncyrillic'] = 0x04E3;
  6902. t['imageorapproximatelyequal'] = 0x2253;
  6903. t['imatragurmukhi'] = 0x0A3F;
  6904. t['imonospace'] = 0xFF49;
  6905. t['increment'] = 0x2206;
  6906. t['infinity'] = 0x221E;
  6907. t['iniarmenian'] = 0x056B;
  6908. t['integral'] = 0x222B;
  6909. t['integralbottom'] = 0x2321;
  6910. t['integralbt'] = 0x2321;
  6911. t['integralex'] = 0xF8F5;
  6912. t['integraltop'] = 0x2320;
  6913. t['integraltp'] = 0x2320;
  6914. t['intersection'] = 0x2229;
  6915. t['intisquare'] = 0x3305;
  6916. t['invbullet'] = 0x25D8;
  6917. t['invcircle'] = 0x25D9;
  6918. t['invsmileface'] = 0x263B;
  6919. t['iocyrillic'] = 0x0451;
  6920. t['iogonek'] = 0x012F;
  6921. t['iota'] = 0x03B9;
  6922. t['iotadieresis'] = 0x03CA;
  6923. t['iotadieresistonos'] = 0x0390;
  6924. t['iotalatin'] = 0x0269;
  6925. t['iotatonos'] = 0x03AF;
  6926. t['iparen'] = 0x24A4;
  6927. t['irigurmukhi'] = 0x0A72;
  6928. t['ismallhiragana'] = 0x3043;
  6929. t['ismallkatakana'] = 0x30A3;
  6930. t['ismallkatakanahalfwidth'] = 0xFF68;
  6931. t['issharbengali'] = 0x09FA;
  6932. t['istroke'] = 0x0268;
  6933. t['isuperior'] = 0xF6ED;
  6934. t['iterationhiragana'] = 0x309D;
  6935. t['iterationkatakana'] = 0x30FD;
  6936. t['itilde'] = 0x0129;
  6937. t['itildebelow'] = 0x1E2D;
  6938. t['iubopomofo'] = 0x3129;
  6939. t['iucyrillic'] = 0x044E;
  6940. t['ivowelsignbengali'] = 0x09BF;
  6941. t['ivowelsigndeva'] = 0x093F;
  6942. t['ivowelsigngujarati'] = 0x0ABF;
  6943. t['izhitsacyrillic'] = 0x0475;
  6944. t['izhitsadblgravecyrillic'] = 0x0477;
  6945. t['j'] = 0x006A;
  6946. t['jaarmenian'] = 0x0571;
  6947. t['jabengali'] = 0x099C;
  6948. t['jadeva'] = 0x091C;
  6949. t['jagujarati'] = 0x0A9C;
  6950. t['jagurmukhi'] = 0x0A1C;
  6951. t['jbopomofo'] = 0x3110;
  6952. t['jcaron'] = 0x01F0;
  6953. t['jcircle'] = 0x24D9;
  6954. t['jcircumflex'] = 0x0135;
  6955. t['jcrossedtail'] = 0x029D;
  6956. t['jdotlessstroke'] = 0x025F;
  6957. t['jecyrillic'] = 0x0458;
  6958. t['jeemarabic'] = 0x062C;
  6959. t['jeemfinalarabic'] = 0xFE9E;
  6960. t['jeeminitialarabic'] = 0xFE9F;
  6961. t['jeemmedialarabic'] = 0xFEA0;
  6962. t['jeharabic'] = 0x0698;
  6963. t['jehfinalarabic'] = 0xFB8B;
  6964. t['jhabengali'] = 0x099D;
  6965. t['jhadeva'] = 0x091D;
  6966. t['jhagujarati'] = 0x0A9D;
  6967. t['jhagurmukhi'] = 0x0A1D;
  6968. t['jheharmenian'] = 0x057B;
  6969. t['jis'] = 0x3004;
  6970. t['jmonospace'] = 0xFF4A;
  6971. t['jparen'] = 0x24A5;
  6972. t['jsuperior'] = 0x02B2;
  6973. t['k'] = 0x006B;
  6974. t['kabashkircyrillic'] = 0x04A1;
  6975. t['kabengali'] = 0x0995;
  6976. t['kacute'] = 0x1E31;
  6977. t['kacyrillic'] = 0x043A;
  6978. t['kadescendercyrillic'] = 0x049B;
  6979. t['kadeva'] = 0x0915;
  6980. t['kaf'] = 0x05DB;
  6981. t['kafarabic'] = 0x0643;
  6982. t['kafdagesh'] = 0xFB3B;
  6983. t['kafdageshhebrew'] = 0xFB3B;
  6984. t['kaffinalarabic'] = 0xFEDA;
  6985. t['kafhebrew'] = 0x05DB;
  6986. t['kafinitialarabic'] = 0xFEDB;
  6987. t['kafmedialarabic'] = 0xFEDC;
  6988. t['kafrafehebrew'] = 0xFB4D;
  6989. t['kagujarati'] = 0x0A95;
  6990. t['kagurmukhi'] = 0x0A15;
  6991. t['kahiragana'] = 0x304B;
  6992. t['kahookcyrillic'] = 0x04C4;
  6993. t['kakatakana'] = 0x30AB;
  6994. t['kakatakanahalfwidth'] = 0xFF76;
  6995. t['kappa'] = 0x03BA;
  6996. t['kappasymbolgreek'] = 0x03F0;
  6997. t['kapyeounmieumkorean'] = 0x3171;
  6998. t['kapyeounphieuphkorean'] = 0x3184;
  6999. t['kapyeounpieupkorean'] = 0x3178;
  7000. t['kapyeounssangpieupkorean'] = 0x3179;
  7001. t['karoriisquare'] = 0x330D;
  7002. t['kashidaautoarabic'] = 0x0640;
  7003. t['kashidaautonosidebearingarabic'] = 0x0640;
  7004. t['kasmallkatakana'] = 0x30F5;
  7005. t['kasquare'] = 0x3384;
  7006. t['kasraarabic'] = 0x0650;
  7007. t['kasratanarabic'] = 0x064D;
  7008. t['kastrokecyrillic'] = 0x049F;
  7009. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7010. t['kaverticalstrokecyrillic'] = 0x049D;
  7011. t['kbopomofo'] = 0x310E;
  7012. t['kcalsquare'] = 0x3389;
  7013. t['kcaron'] = 0x01E9;
  7014. t['kcedilla'] = 0x0137;
  7015. t['kcircle'] = 0x24DA;
  7016. t['kcommaaccent'] = 0x0137;
  7017. t['kdotbelow'] = 0x1E33;
  7018. t['keharmenian'] = 0x0584;
  7019. t['kehiragana'] = 0x3051;
  7020. t['kekatakana'] = 0x30B1;
  7021. t['kekatakanahalfwidth'] = 0xFF79;
  7022. t['kenarmenian'] = 0x056F;
  7023. t['kesmallkatakana'] = 0x30F6;
  7024. t['kgreenlandic'] = 0x0138;
  7025. t['khabengali'] = 0x0996;
  7026. t['khacyrillic'] = 0x0445;
  7027. t['khadeva'] = 0x0916;
  7028. t['khagujarati'] = 0x0A96;
  7029. t['khagurmukhi'] = 0x0A16;
  7030. t['khaharabic'] = 0x062E;
  7031. t['khahfinalarabic'] = 0xFEA6;
  7032. t['khahinitialarabic'] = 0xFEA7;
  7033. t['khahmedialarabic'] = 0xFEA8;
  7034. t['kheicoptic'] = 0x03E7;
  7035. t['khhadeva'] = 0x0959;
  7036. t['khhagurmukhi'] = 0x0A59;
  7037. t['khieukhacirclekorean'] = 0x3278;
  7038. t['khieukhaparenkorean'] = 0x3218;
  7039. t['khieukhcirclekorean'] = 0x326A;
  7040. t['khieukhkorean'] = 0x314B;
  7041. t['khieukhparenkorean'] = 0x320A;
  7042. t['khokhaithai'] = 0x0E02;
  7043. t['khokhonthai'] = 0x0E05;
  7044. t['khokhuatthai'] = 0x0E03;
  7045. t['khokhwaithai'] = 0x0E04;
  7046. t['khomutthai'] = 0x0E5B;
  7047. t['khook'] = 0x0199;
  7048. t['khorakhangthai'] = 0x0E06;
  7049. t['khzsquare'] = 0x3391;
  7050. t['kihiragana'] = 0x304D;
  7051. t['kikatakana'] = 0x30AD;
  7052. t['kikatakanahalfwidth'] = 0xFF77;
  7053. t['kiroguramusquare'] = 0x3315;
  7054. t['kiromeetorusquare'] = 0x3316;
  7055. t['kirosquare'] = 0x3314;
  7056. t['kiyeokacirclekorean'] = 0x326E;
  7057. t['kiyeokaparenkorean'] = 0x320E;
  7058. t['kiyeokcirclekorean'] = 0x3260;
  7059. t['kiyeokkorean'] = 0x3131;
  7060. t['kiyeokparenkorean'] = 0x3200;
  7061. t['kiyeoksioskorean'] = 0x3133;
  7062. t['kjecyrillic'] = 0x045C;
  7063. t['klinebelow'] = 0x1E35;
  7064. t['klsquare'] = 0x3398;
  7065. t['kmcubedsquare'] = 0x33A6;
  7066. t['kmonospace'] = 0xFF4B;
  7067. t['kmsquaredsquare'] = 0x33A2;
  7068. t['kohiragana'] = 0x3053;
  7069. t['kohmsquare'] = 0x33C0;
  7070. t['kokaithai'] = 0x0E01;
  7071. t['kokatakana'] = 0x30B3;
  7072. t['kokatakanahalfwidth'] = 0xFF7A;
  7073. t['kooposquare'] = 0x331E;
  7074. t['koppacyrillic'] = 0x0481;
  7075. t['koreanstandardsymbol'] = 0x327F;
  7076. t['koroniscmb'] = 0x0343;
  7077. t['kparen'] = 0x24A6;
  7078. t['kpasquare'] = 0x33AA;
  7079. t['ksicyrillic'] = 0x046F;
  7080. t['ktsquare'] = 0x33CF;
  7081. t['kturned'] = 0x029E;
  7082. t['kuhiragana'] = 0x304F;
  7083. t['kukatakana'] = 0x30AF;
  7084. t['kukatakanahalfwidth'] = 0xFF78;
  7085. t['kvsquare'] = 0x33B8;
  7086. t['kwsquare'] = 0x33BE;
  7087. t['l'] = 0x006C;
  7088. t['labengali'] = 0x09B2;
  7089. t['lacute'] = 0x013A;
  7090. t['ladeva'] = 0x0932;
  7091. t['lagujarati'] = 0x0AB2;
  7092. t['lagurmukhi'] = 0x0A32;
  7093. t['lakkhangyaothai'] = 0x0E45;
  7094. t['lamaleffinalarabic'] = 0xFEFC;
  7095. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7096. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7097. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7098. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7099. t['lamalefisolatedarabic'] = 0xFEFB;
  7100. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7101. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7102. t['lamarabic'] = 0x0644;
  7103. t['lambda'] = 0x03BB;
  7104. t['lambdastroke'] = 0x019B;
  7105. t['lamed'] = 0x05DC;
  7106. t['lameddagesh'] = 0xFB3C;
  7107. t['lameddageshhebrew'] = 0xFB3C;
  7108. t['lamedhebrew'] = 0x05DC;
  7109. t['lamfinalarabic'] = 0xFEDE;
  7110. t['lamhahinitialarabic'] = 0xFCCA;
  7111. t['laminitialarabic'] = 0xFEDF;
  7112. t['lamjeeminitialarabic'] = 0xFCC9;
  7113. t['lamkhahinitialarabic'] = 0xFCCB;
  7114. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7115. t['lammedialarabic'] = 0xFEE0;
  7116. t['lammeemhahinitialarabic'] = 0xFD88;
  7117. t['lammeeminitialarabic'] = 0xFCCC;
  7118. t['largecircle'] = 0x25EF;
  7119. t['lbar'] = 0x019A;
  7120. t['lbelt'] = 0x026C;
  7121. t['lbopomofo'] = 0x310C;
  7122. t['lcaron'] = 0x013E;
  7123. t['lcedilla'] = 0x013C;
  7124. t['lcircle'] = 0x24DB;
  7125. t['lcircumflexbelow'] = 0x1E3D;
  7126. t['lcommaaccent'] = 0x013C;
  7127. t['ldot'] = 0x0140;
  7128. t['ldotaccent'] = 0x0140;
  7129. t['ldotbelow'] = 0x1E37;
  7130. t['ldotbelowmacron'] = 0x1E39;
  7131. t['leftangleabovecmb'] = 0x031A;
  7132. t['lefttackbelowcmb'] = 0x0318;
  7133. t['less'] = 0x003C;
  7134. t['lessequal'] = 0x2264;
  7135. t['lessequalorgreater'] = 0x22DA;
  7136. t['lessmonospace'] = 0xFF1C;
  7137. t['lessorequivalent'] = 0x2272;
  7138. t['lessorgreater'] = 0x2276;
  7139. t['lessoverequal'] = 0x2266;
  7140. t['lesssmall'] = 0xFE64;
  7141. t['lezh'] = 0x026E;
  7142. t['lfblock'] = 0x258C;
  7143. t['lhookretroflex'] = 0x026D;
  7144. t['lira'] = 0x20A4;
  7145. t['liwnarmenian'] = 0x056C;
  7146. t['lj'] = 0x01C9;
  7147. t['ljecyrillic'] = 0x0459;
  7148. t['ll'] = 0xF6C0;
  7149. t['lladeva'] = 0x0933;
  7150. t['llagujarati'] = 0x0AB3;
  7151. t['llinebelow'] = 0x1E3B;
  7152. t['llladeva'] = 0x0934;
  7153. t['llvocalicbengali'] = 0x09E1;
  7154. t['llvocalicdeva'] = 0x0961;
  7155. t['llvocalicvowelsignbengali'] = 0x09E3;
  7156. t['llvocalicvowelsigndeva'] = 0x0963;
  7157. t['lmiddletilde'] = 0x026B;
  7158. t['lmonospace'] = 0xFF4C;
  7159. t['lmsquare'] = 0x33D0;
  7160. t['lochulathai'] = 0x0E2C;
  7161. t['logicaland'] = 0x2227;
  7162. t['logicalnot'] = 0x00AC;
  7163. t['logicalnotreversed'] = 0x2310;
  7164. t['logicalor'] = 0x2228;
  7165. t['lolingthai'] = 0x0E25;
  7166. t['longs'] = 0x017F;
  7167. t['lowlinecenterline'] = 0xFE4E;
  7168. t['lowlinecmb'] = 0x0332;
  7169. t['lowlinedashed'] = 0xFE4D;
  7170. t['lozenge'] = 0x25CA;
  7171. t['lparen'] = 0x24A7;
  7172. t['lslash'] = 0x0142;
  7173. t['lsquare'] = 0x2113;
  7174. t['lsuperior'] = 0xF6EE;
  7175. t['ltshade'] = 0x2591;
  7176. t['luthai'] = 0x0E26;
  7177. t['lvocalicbengali'] = 0x098C;
  7178. t['lvocalicdeva'] = 0x090C;
  7179. t['lvocalicvowelsignbengali'] = 0x09E2;
  7180. t['lvocalicvowelsigndeva'] = 0x0962;
  7181. t['lxsquare'] = 0x33D3;
  7182. t['m'] = 0x006D;
  7183. t['mabengali'] = 0x09AE;
  7184. t['macron'] = 0x00AF;
  7185. t['macronbelowcmb'] = 0x0331;
  7186. t['macroncmb'] = 0x0304;
  7187. t['macronlowmod'] = 0x02CD;
  7188. t['macronmonospace'] = 0xFFE3;
  7189. t['macute'] = 0x1E3F;
  7190. t['madeva'] = 0x092E;
  7191. t['magujarati'] = 0x0AAE;
  7192. t['magurmukhi'] = 0x0A2E;
  7193. t['mahapakhhebrew'] = 0x05A4;
  7194. t['mahapakhlefthebrew'] = 0x05A4;
  7195. t['mahiragana'] = 0x307E;
  7196. t['maichattawalowleftthai'] = 0xF895;
  7197. t['maichattawalowrightthai'] = 0xF894;
  7198. t['maichattawathai'] = 0x0E4B;
  7199. t['maichattawaupperleftthai'] = 0xF893;
  7200. t['maieklowleftthai'] = 0xF88C;
  7201. t['maieklowrightthai'] = 0xF88B;
  7202. t['maiekthai'] = 0x0E48;
  7203. t['maiekupperleftthai'] = 0xF88A;
  7204. t['maihanakatleftthai'] = 0xF884;
  7205. t['maihanakatthai'] = 0x0E31;
  7206. t['maitaikhuleftthai'] = 0xF889;
  7207. t['maitaikhuthai'] = 0x0E47;
  7208. t['maitholowleftthai'] = 0xF88F;
  7209. t['maitholowrightthai'] = 0xF88E;
  7210. t['maithothai'] = 0x0E49;
  7211. t['maithoupperleftthai'] = 0xF88D;
  7212. t['maitrilowleftthai'] = 0xF892;
  7213. t['maitrilowrightthai'] = 0xF891;
  7214. t['maitrithai'] = 0x0E4A;
  7215. t['maitriupperleftthai'] = 0xF890;
  7216. t['maiyamokthai'] = 0x0E46;
  7217. t['makatakana'] = 0x30DE;
  7218. t['makatakanahalfwidth'] = 0xFF8F;
  7219. t['male'] = 0x2642;
  7220. t['mansyonsquare'] = 0x3347;
  7221. t['maqafhebrew'] = 0x05BE;
  7222. t['mars'] = 0x2642;
  7223. t['masoracirclehebrew'] = 0x05AF;
  7224. t['masquare'] = 0x3383;
  7225. t['mbopomofo'] = 0x3107;
  7226. t['mbsquare'] = 0x33D4;
  7227. t['mcircle'] = 0x24DC;
  7228. t['mcubedsquare'] = 0x33A5;
  7229. t['mdotaccent'] = 0x1E41;
  7230. t['mdotbelow'] = 0x1E43;
  7231. t['meemarabic'] = 0x0645;
  7232. t['meemfinalarabic'] = 0xFEE2;
  7233. t['meeminitialarabic'] = 0xFEE3;
  7234. t['meemmedialarabic'] = 0xFEE4;
  7235. t['meemmeeminitialarabic'] = 0xFCD1;
  7236. t['meemmeemisolatedarabic'] = 0xFC48;
  7237. t['meetorusquare'] = 0x334D;
  7238. t['mehiragana'] = 0x3081;
  7239. t['meizierasquare'] = 0x337E;
  7240. t['mekatakana'] = 0x30E1;
  7241. t['mekatakanahalfwidth'] = 0xFF92;
  7242. t['mem'] = 0x05DE;
  7243. t['memdagesh'] = 0xFB3E;
  7244. t['memdageshhebrew'] = 0xFB3E;
  7245. t['memhebrew'] = 0x05DE;
  7246. t['menarmenian'] = 0x0574;
  7247. t['merkhahebrew'] = 0x05A5;
  7248. t['merkhakefulahebrew'] = 0x05A6;
  7249. t['merkhakefulalefthebrew'] = 0x05A6;
  7250. t['merkhalefthebrew'] = 0x05A5;
  7251. t['mhook'] = 0x0271;
  7252. t['mhzsquare'] = 0x3392;
  7253. t['middledotkatakanahalfwidth'] = 0xFF65;
  7254. t['middot'] = 0x00B7;
  7255. t['mieumacirclekorean'] = 0x3272;
  7256. t['mieumaparenkorean'] = 0x3212;
  7257. t['mieumcirclekorean'] = 0x3264;
  7258. t['mieumkorean'] = 0x3141;
  7259. t['mieumpansioskorean'] = 0x3170;
  7260. t['mieumparenkorean'] = 0x3204;
  7261. t['mieumpieupkorean'] = 0x316E;
  7262. t['mieumsioskorean'] = 0x316F;
  7263. t['mihiragana'] = 0x307F;
  7264. t['mikatakana'] = 0x30DF;
  7265. t['mikatakanahalfwidth'] = 0xFF90;
  7266. t['minus'] = 0x2212;
  7267. t['minusbelowcmb'] = 0x0320;
  7268. t['minuscircle'] = 0x2296;
  7269. t['minusmod'] = 0x02D7;
  7270. t['minusplus'] = 0x2213;
  7271. t['minute'] = 0x2032;
  7272. t['miribaarusquare'] = 0x334A;
  7273. t['mirisquare'] = 0x3349;
  7274. t['mlonglegturned'] = 0x0270;
  7275. t['mlsquare'] = 0x3396;
  7276. t['mmcubedsquare'] = 0x33A3;
  7277. t['mmonospace'] = 0xFF4D;
  7278. t['mmsquaredsquare'] = 0x339F;
  7279. t['mohiragana'] = 0x3082;
  7280. t['mohmsquare'] = 0x33C1;
  7281. t['mokatakana'] = 0x30E2;
  7282. t['mokatakanahalfwidth'] = 0xFF93;
  7283. t['molsquare'] = 0x33D6;
  7284. t['momathai'] = 0x0E21;
  7285. t['moverssquare'] = 0x33A7;
  7286. t['moverssquaredsquare'] = 0x33A8;
  7287. t['mparen'] = 0x24A8;
  7288. t['mpasquare'] = 0x33AB;
  7289. t['mssquare'] = 0x33B3;
  7290. t['msuperior'] = 0xF6EF;
  7291. t['mturned'] = 0x026F;
  7292. t['mu'] = 0x00B5;
  7293. t['mu1'] = 0x00B5;
  7294. t['muasquare'] = 0x3382;
  7295. t['muchgreater'] = 0x226B;
  7296. t['muchless'] = 0x226A;
  7297. t['mufsquare'] = 0x338C;
  7298. t['mugreek'] = 0x03BC;
  7299. t['mugsquare'] = 0x338D;
  7300. t['muhiragana'] = 0x3080;
  7301. t['mukatakana'] = 0x30E0;
  7302. t['mukatakanahalfwidth'] = 0xFF91;
  7303. t['mulsquare'] = 0x3395;
  7304. t['multiply'] = 0x00D7;
  7305. t['mumsquare'] = 0x339B;
  7306. t['munahhebrew'] = 0x05A3;
  7307. t['munahlefthebrew'] = 0x05A3;
  7308. t['musicalnote'] = 0x266A;
  7309. t['musicalnotedbl'] = 0x266B;
  7310. t['musicflatsign'] = 0x266D;
  7311. t['musicsharpsign'] = 0x266F;
  7312. t['mussquare'] = 0x33B2;
  7313. t['muvsquare'] = 0x33B6;
  7314. t['muwsquare'] = 0x33BC;
  7315. t['mvmegasquare'] = 0x33B9;
  7316. t['mvsquare'] = 0x33B7;
  7317. t['mwmegasquare'] = 0x33BF;
  7318. t['mwsquare'] = 0x33BD;
  7319. t['n'] = 0x006E;
  7320. t['nabengali'] = 0x09A8;
  7321. t['nabla'] = 0x2207;
  7322. t['nacute'] = 0x0144;
  7323. t['nadeva'] = 0x0928;
  7324. t['nagujarati'] = 0x0AA8;
  7325. t['nagurmukhi'] = 0x0A28;
  7326. t['nahiragana'] = 0x306A;
  7327. t['nakatakana'] = 0x30CA;
  7328. t['nakatakanahalfwidth'] = 0xFF85;
  7329. t['napostrophe'] = 0x0149;
  7330. t['nasquare'] = 0x3381;
  7331. t['nbopomofo'] = 0x310B;
  7332. t['nbspace'] = 0x00A0;
  7333. t['ncaron'] = 0x0148;
  7334. t['ncedilla'] = 0x0146;
  7335. t['ncircle'] = 0x24DD;
  7336. t['ncircumflexbelow'] = 0x1E4B;
  7337. t['ncommaaccent'] = 0x0146;
  7338. t['ndotaccent'] = 0x1E45;
  7339. t['ndotbelow'] = 0x1E47;
  7340. t['nehiragana'] = 0x306D;
  7341. t['nekatakana'] = 0x30CD;
  7342. t['nekatakanahalfwidth'] = 0xFF88;
  7343. t['newsheqelsign'] = 0x20AA;
  7344. t['nfsquare'] = 0x338B;
  7345. t['ngabengali'] = 0x0999;
  7346. t['ngadeva'] = 0x0919;
  7347. t['ngagujarati'] = 0x0A99;
  7348. t['ngagurmukhi'] = 0x0A19;
  7349. t['ngonguthai'] = 0x0E07;
  7350. t['nhiragana'] = 0x3093;
  7351. t['nhookleft'] = 0x0272;
  7352. t['nhookretroflex'] = 0x0273;
  7353. t['nieunacirclekorean'] = 0x326F;
  7354. t['nieunaparenkorean'] = 0x320F;
  7355. t['nieuncieuckorean'] = 0x3135;
  7356. t['nieuncirclekorean'] = 0x3261;
  7357. t['nieunhieuhkorean'] = 0x3136;
  7358. t['nieunkorean'] = 0x3134;
  7359. t['nieunpansioskorean'] = 0x3168;
  7360. t['nieunparenkorean'] = 0x3201;
  7361. t['nieunsioskorean'] = 0x3167;
  7362. t['nieuntikeutkorean'] = 0x3166;
  7363. t['nihiragana'] = 0x306B;
  7364. t['nikatakana'] = 0x30CB;
  7365. t['nikatakanahalfwidth'] = 0xFF86;
  7366. t['nikhahitleftthai'] = 0xF899;
  7367. t['nikhahitthai'] = 0x0E4D;
  7368. t['nine'] = 0x0039;
  7369. t['ninearabic'] = 0x0669;
  7370. t['ninebengali'] = 0x09EF;
  7371. t['ninecircle'] = 0x2468;
  7372. t['ninecircleinversesansserif'] = 0x2792;
  7373. t['ninedeva'] = 0x096F;
  7374. t['ninegujarati'] = 0x0AEF;
  7375. t['ninegurmukhi'] = 0x0A6F;
  7376. t['ninehackarabic'] = 0x0669;
  7377. t['ninehangzhou'] = 0x3029;
  7378. t['nineideographicparen'] = 0x3228;
  7379. t['nineinferior'] = 0x2089;
  7380. t['ninemonospace'] = 0xFF19;
  7381. t['nineoldstyle'] = 0xF739;
  7382. t['nineparen'] = 0x247C;
  7383. t['nineperiod'] = 0x2490;
  7384. t['ninepersian'] = 0x06F9;
  7385. t['nineroman'] = 0x2178;
  7386. t['ninesuperior'] = 0x2079;
  7387. t['nineteencircle'] = 0x2472;
  7388. t['nineteenparen'] = 0x2486;
  7389. t['nineteenperiod'] = 0x249A;
  7390. t['ninethai'] = 0x0E59;
  7391. t['nj'] = 0x01CC;
  7392. t['njecyrillic'] = 0x045A;
  7393. t['nkatakana'] = 0x30F3;
  7394. t['nkatakanahalfwidth'] = 0xFF9D;
  7395. t['nlegrightlong'] = 0x019E;
  7396. t['nlinebelow'] = 0x1E49;
  7397. t['nmonospace'] = 0xFF4E;
  7398. t['nmsquare'] = 0x339A;
  7399. t['nnabengali'] = 0x09A3;
  7400. t['nnadeva'] = 0x0923;
  7401. t['nnagujarati'] = 0x0AA3;
  7402. t['nnagurmukhi'] = 0x0A23;
  7403. t['nnnadeva'] = 0x0929;
  7404. t['nohiragana'] = 0x306E;
  7405. t['nokatakana'] = 0x30CE;
  7406. t['nokatakanahalfwidth'] = 0xFF89;
  7407. t['nonbreakingspace'] = 0x00A0;
  7408. t['nonenthai'] = 0x0E13;
  7409. t['nonuthai'] = 0x0E19;
  7410. t['noonarabic'] = 0x0646;
  7411. t['noonfinalarabic'] = 0xFEE6;
  7412. t['noonghunnaarabic'] = 0x06BA;
  7413. t['noonghunnafinalarabic'] = 0xFB9F;
  7414. t['nooninitialarabic'] = 0xFEE7;
  7415. t['noonjeeminitialarabic'] = 0xFCD2;
  7416. t['noonjeemisolatedarabic'] = 0xFC4B;
  7417. t['noonmedialarabic'] = 0xFEE8;
  7418. t['noonmeeminitialarabic'] = 0xFCD5;
  7419. t['noonmeemisolatedarabic'] = 0xFC4E;
  7420. t['noonnoonfinalarabic'] = 0xFC8D;
  7421. t['notcontains'] = 0x220C;
  7422. t['notelement'] = 0x2209;
  7423. t['notelementof'] = 0x2209;
  7424. t['notequal'] = 0x2260;
  7425. t['notgreater'] = 0x226F;
  7426. t['notgreaternorequal'] = 0x2271;
  7427. t['notgreaternorless'] = 0x2279;
  7428. t['notidentical'] = 0x2262;
  7429. t['notless'] = 0x226E;
  7430. t['notlessnorequal'] = 0x2270;
  7431. t['notparallel'] = 0x2226;
  7432. t['notprecedes'] = 0x2280;
  7433. t['notsubset'] = 0x2284;
  7434. t['notsucceeds'] = 0x2281;
  7435. t['notsuperset'] = 0x2285;
  7436. t['nowarmenian'] = 0x0576;
  7437. t['nparen'] = 0x24A9;
  7438. t['nssquare'] = 0x33B1;
  7439. t['nsuperior'] = 0x207F;
  7440. t['ntilde'] = 0x00F1;
  7441. t['nu'] = 0x03BD;
  7442. t['nuhiragana'] = 0x306C;
  7443. t['nukatakana'] = 0x30CC;
  7444. t['nukatakanahalfwidth'] = 0xFF87;
  7445. t['nuktabengali'] = 0x09BC;
  7446. t['nuktadeva'] = 0x093C;
  7447. t['nuktagujarati'] = 0x0ABC;
  7448. t['nuktagurmukhi'] = 0x0A3C;
  7449. t['numbersign'] = 0x0023;
  7450. t['numbersignmonospace'] = 0xFF03;
  7451. t['numbersignsmall'] = 0xFE5F;
  7452. t['numeralsigngreek'] = 0x0374;
  7453. t['numeralsignlowergreek'] = 0x0375;
  7454. t['numero'] = 0x2116;
  7455. t['nun'] = 0x05E0;
  7456. t['nundagesh'] = 0xFB40;
  7457. t['nundageshhebrew'] = 0xFB40;
  7458. t['nunhebrew'] = 0x05E0;
  7459. t['nvsquare'] = 0x33B5;
  7460. t['nwsquare'] = 0x33BB;
  7461. t['nyabengali'] = 0x099E;
  7462. t['nyadeva'] = 0x091E;
  7463. t['nyagujarati'] = 0x0A9E;
  7464. t['nyagurmukhi'] = 0x0A1E;
  7465. t['o'] = 0x006F;
  7466. t['oacute'] = 0x00F3;
  7467. t['oangthai'] = 0x0E2D;
  7468. t['obarred'] = 0x0275;
  7469. t['obarredcyrillic'] = 0x04E9;
  7470. t['obarreddieresiscyrillic'] = 0x04EB;
  7471. t['obengali'] = 0x0993;
  7472. t['obopomofo'] = 0x311B;
  7473. t['obreve'] = 0x014F;
  7474. t['ocandradeva'] = 0x0911;
  7475. t['ocandragujarati'] = 0x0A91;
  7476. t['ocandravowelsigndeva'] = 0x0949;
  7477. t['ocandravowelsigngujarati'] = 0x0AC9;
  7478. t['ocaron'] = 0x01D2;
  7479. t['ocircle'] = 0x24DE;
  7480. t['ocircumflex'] = 0x00F4;
  7481. t['ocircumflexacute'] = 0x1ED1;
  7482. t['ocircumflexdotbelow'] = 0x1ED9;
  7483. t['ocircumflexgrave'] = 0x1ED3;
  7484. t['ocircumflexhookabove'] = 0x1ED5;
  7485. t['ocircumflextilde'] = 0x1ED7;
  7486. t['ocyrillic'] = 0x043E;
  7487. t['odblacute'] = 0x0151;
  7488. t['odblgrave'] = 0x020D;
  7489. t['odeva'] = 0x0913;
  7490. t['odieresis'] = 0x00F6;
  7491. t['odieresiscyrillic'] = 0x04E7;
  7492. t['odotbelow'] = 0x1ECD;
  7493. t['oe'] = 0x0153;
  7494. t['oekorean'] = 0x315A;
  7495. t['ogonek'] = 0x02DB;
  7496. t['ogonekcmb'] = 0x0328;
  7497. t['ograve'] = 0x00F2;
  7498. t['ogujarati'] = 0x0A93;
  7499. t['oharmenian'] = 0x0585;
  7500. t['ohiragana'] = 0x304A;
  7501. t['ohookabove'] = 0x1ECF;
  7502. t['ohorn'] = 0x01A1;
  7503. t['ohornacute'] = 0x1EDB;
  7504. t['ohorndotbelow'] = 0x1EE3;
  7505. t['ohorngrave'] = 0x1EDD;
  7506. t['ohornhookabove'] = 0x1EDF;
  7507. t['ohorntilde'] = 0x1EE1;
  7508. t['ohungarumlaut'] = 0x0151;
  7509. t['oi'] = 0x01A3;
  7510. t['oinvertedbreve'] = 0x020F;
  7511. t['okatakana'] = 0x30AA;
  7512. t['okatakanahalfwidth'] = 0xFF75;
  7513. t['okorean'] = 0x3157;
  7514. t['olehebrew'] = 0x05AB;
  7515. t['omacron'] = 0x014D;
  7516. t['omacronacute'] = 0x1E53;
  7517. t['omacrongrave'] = 0x1E51;
  7518. t['omdeva'] = 0x0950;
  7519. t['omega'] = 0x03C9;
  7520. t['omega1'] = 0x03D6;
  7521. t['omegacyrillic'] = 0x0461;
  7522. t['omegalatinclosed'] = 0x0277;
  7523. t['omegaroundcyrillic'] = 0x047B;
  7524. t['omegatitlocyrillic'] = 0x047D;
  7525. t['omegatonos'] = 0x03CE;
  7526. t['omgujarati'] = 0x0AD0;
  7527. t['omicron'] = 0x03BF;
  7528. t['omicrontonos'] = 0x03CC;
  7529. t['omonospace'] = 0xFF4F;
  7530. t['one'] = 0x0031;
  7531. t['onearabic'] = 0x0661;
  7532. t['onebengali'] = 0x09E7;
  7533. t['onecircle'] = 0x2460;
  7534. t['onecircleinversesansserif'] = 0x278A;
  7535. t['onedeva'] = 0x0967;
  7536. t['onedotenleader'] = 0x2024;
  7537. t['oneeighth'] = 0x215B;
  7538. t['onefitted'] = 0xF6DC;
  7539. t['onegujarati'] = 0x0AE7;
  7540. t['onegurmukhi'] = 0x0A67;
  7541. t['onehackarabic'] = 0x0661;
  7542. t['onehalf'] = 0x00BD;
  7543. t['onehangzhou'] = 0x3021;
  7544. t['oneideographicparen'] = 0x3220;
  7545. t['oneinferior'] = 0x2081;
  7546. t['onemonospace'] = 0xFF11;
  7547. t['onenumeratorbengali'] = 0x09F4;
  7548. t['oneoldstyle'] = 0xF731;
  7549. t['oneparen'] = 0x2474;
  7550. t['oneperiod'] = 0x2488;
  7551. t['onepersian'] = 0x06F1;
  7552. t['onequarter'] = 0x00BC;
  7553. t['oneroman'] = 0x2170;
  7554. t['onesuperior'] = 0x00B9;
  7555. t['onethai'] = 0x0E51;
  7556. t['onethird'] = 0x2153;
  7557. t['oogonek'] = 0x01EB;
  7558. t['oogonekmacron'] = 0x01ED;
  7559. t['oogurmukhi'] = 0x0A13;
  7560. t['oomatragurmukhi'] = 0x0A4B;
  7561. t['oopen'] = 0x0254;
  7562. t['oparen'] = 0x24AA;
  7563. t['openbullet'] = 0x25E6;
  7564. t['option'] = 0x2325;
  7565. t['ordfeminine'] = 0x00AA;
  7566. t['ordmasculine'] = 0x00BA;
  7567. t['orthogonal'] = 0x221F;
  7568. t['oshortdeva'] = 0x0912;
  7569. t['oshortvowelsigndeva'] = 0x094A;
  7570. t['oslash'] = 0x00F8;
  7571. t['oslashacute'] = 0x01FF;
  7572. t['osmallhiragana'] = 0x3049;
  7573. t['osmallkatakana'] = 0x30A9;
  7574. t['osmallkatakanahalfwidth'] = 0xFF6B;
  7575. t['ostrokeacute'] = 0x01FF;
  7576. t['osuperior'] = 0xF6F0;
  7577. t['otcyrillic'] = 0x047F;
  7578. t['otilde'] = 0x00F5;
  7579. t['otildeacute'] = 0x1E4D;
  7580. t['otildedieresis'] = 0x1E4F;
  7581. t['oubopomofo'] = 0x3121;
  7582. t['overline'] = 0x203E;
  7583. t['overlinecenterline'] = 0xFE4A;
  7584. t['overlinecmb'] = 0x0305;
  7585. t['overlinedashed'] = 0xFE49;
  7586. t['overlinedblwavy'] = 0xFE4C;
  7587. t['overlinewavy'] = 0xFE4B;
  7588. t['overscore'] = 0x00AF;
  7589. t['ovowelsignbengali'] = 0x09CB;
  7590. t['ovowelsigndeva'] = 0x094B;
  7591. t['ovowelsigngujarati'] = 0x0ACB;
  7592. t['p'] = 0x0070;
  7593. t['paampssquare'] = 0x3380;
  7594. t['paasentosquare'] = 0x332B;
  7595. t['pabengali'] = 0x09AA;
  7596. t['pacute'] = 0x1E55;
  7597. t['padeva'] = 0x092A;
  7598. t['pagedown'] = 0x21DF;
  7599. t['pageup'] = 0x21DE;
  7600. t['pagujarati'] = 0x0AAA;
  7601. t['pagurmukhi'] = 0x0A2A;
  7602. t['pahiragana'] = 0x3071;
  7603. t['paiyannoithai'] = 0x0E2F;
  7604. t['pakatakana'] = 0x30D1;
  7605. t['palatalizationcyrilliccmb'] = 0x0484;
  7606. t['palochkacyrillic'] = 0x04C0;
  7607. t['pansioskorean'] = 0x317F;
  7608. t['paragraph'] = 0x00B6;
  7609. t['parallel'] = 0x2225;
  7610. t['parenleft'] = 0x0028;
  7611. t['parenleftaltonearabic'] = 0xFD3E;
  7612. t['parenleftbt'] = 0xF8ED;
  7613. t['parenleftex'] = 0xF8EC;
  7614. t['parenleftinferior'] = 0x208D;
  7615. t['parenleftmonospace'] = 0xFF08;
  7616. t['parenleftsmall'] = 0xFE59;
  7617. t['parenleftsuperior'] = 0x207D;
  7618. t['parenlefttp'] = 0xF8EB;
  7619. t['parenleftvertical'] = 0xFE35;
  7620. t['parenright'] = 0x0029;
  7621. t['parenrightaltonearabic'] = 0xFD3F;
  7622. t['parenrightbt'] = 0xF8F8;
  7623. t['parenrightex'] = 0xF8F7;
  7624. t['parenrightinferior'] = 0x208E;
  7625. t['parenrightmonospace'] = 0xFF09;
  7626. t['parenrightsmall'] = 0xFE5A;
  7627. t['parenrightsuperior'] = 0x207E;
  7628. t['parenrighttp'] = 0xF8F6;
  7629. t['parenrightvertical'] = 0xFE36;
  7630. t['partialdiff'] = 0x2202;
  7631. t['paseqhebrew'] = 0x05C0;
  7632. t['pashtahebrew'] = 0x0599;
  7633. t['pasquare'] = 0x33A9;
  7634. t['patah'] = 0x05B7;
  7635. t['patah11'] = 0x05B7;
  7636. t['patah1d'] = 0x05B7;
  7637. t['patah2a'] = 0x05B7;
  7638. t['patahhebrew'] = 0x05B7;
  7639. t['patahnarrowhebrew'] = 0x05B7;
  7640. t['patahquarterhebrew'] = 0x05B7;
  7641. t['patahwidehebrew'] = 0x05B7;
  7642. t['pazerhebrew'] = 0x05A1;
  7643. t['pbopomofo'] = 0x3106;
  7644. t['pcircle'] = 0x24DF;
  7645. t['pdotaccent'] = 0x1E57;
  7646. t['pe'] = 0x05E4;
  7647. t['pecyrillic'] = 0x043F;
  7648. t['pedagesh'] = 0xFB44;
  7649. t['pedageshhebrew'] = 0xFB44;
  7650. t['peezisquare'] = 0x333B;
  7651. t['pefinaldageshhebrew'] = 0xFB43;
  7652. t['peharabic'] = 0x067E;
  7653. t['peharmenian'] = 0x057A;
  7654. t['pehebrew'] = 0x05E4;
  7655. t['pehfinalarabic'] = 0xFB57;
  7656. t['pehinitialarabic'] = 0xFB58;
  7657. t['pehiragana'] = 0x307A;
  7658. t['pehmedialarabic'] = 0xFB59;
  7659. t['pekatakana'] = 0x30DA;
  7660. t['pemiddlehookcyrillic'] = 0x04A7;
  7661. t['perafehebrew'] = 0xFB4E;
  7662. t['percent'] = 0x0025;
  7663. t['percentarabic'] = 0x066A;
  7664. t['percentmonospace'] = 0xFF05;
  7665. t['percentsmall'] = 0xFE6A;
  7666. t['period'] = 0x002E;
  7667. t['periodarmenian'] = 0x0589;
  7668. t['periodcentered'] = 0x00B7;
  7669. t['periodhalfwidth'] = 0xFF61;
  7670. t['periodinferior'] = 0xF6E7;
  7671. t['periodmonospace'] = 0xFF0E;
  7672. t['periodsmall'] = 0xFE52;
  7673. t['periodsuperior'] = 0xF6E8;
  7674. t['perispomenigreekcmb'] = 0x0342;
  7675. t['perpendicular'] = 0x22A5;
  7676. t['perthousand'] = 0x2030;
  7677. t['peseta'] = 0x20A7;
  7678. t['pfsquare'] = 0x338A;
  7679. t['phabengali'] = 0x09AB;
  7680. t['phadeva'] = 0x092B;
  7681. t['phagujarati'] = 0x0AAB;
  7682. t['phagurmukhi'] = 0x0A2B;
  7683. t['phi'] = 0x03C6;
  7684. t['phi1'] = 0x03D5;
  7685. t['phieuphacirclekorean'] = 0x327A;
  7686. t['phieuphaparenkorean'] = 0x321A;
  7687. t['phieuphcirclekorean'] = 0x326C;
  7688. t['phieuphkorean'] = 0x314D;
  7689. t['phieuphparenkorean'] = 0x320C;
  7690. t['philatin'] = 0x0278;
  7691. t['phinthuthai'] = 0x0E3A;
  7692. t['phisymbolgreek'] = 0x03D5;
  7693. t['phook'] = 0x01A5;
  7694. t['phophanthai'] = 0x0E1E;
  7695. t['phophungthai'] = 0x0E1C;
  7696. t['phosamphaothai'] = 0x0E20;
  7697. t['pi'] = 0x03C0;
  7698. t['pieupacirclekorean'] = 0x3273;
  7699. t['pieupaparenkorean'] = 0x3213;
  7700. t['pieupcieuckorean'] = 0x3176;
  7701. t['pieupcirclekorean'] = 0x3265;
  7702. t['pieupkiyeokkorean'] = 0x3172;
  7703. t['pieupkorean'] = 0x3142;
  7704. t['pieupparenkorean'] = 0x3205;
  7705. t['pieupsioskiyeokkorean'] = 0x3174;
  7706. t['pieupsioskorean'] = 0x3144;
  7707. t['pieupsiostikeutkorean'] = 0x3175;
  7708. t['pieupthieuthkorean'] = 0x3177;
  7709. t['pieuptikeutkorean'] = 0x3173;
  7710. t['pihiragana'] = 0x3074;
  7711. t['pikatakana'] = 0x30D4;
  7712. t['pisymbolgreek'] = 0x03D6;
  7713. t['piwrarmenian'] = 0x0583;
  7714. t['plus'] = 0x002B;
  7715. t['plusbelowcmb'] = 0x031F;
  7716. t['pluscircle'] = 0x2295;
  7717. t['plusminus'] = 0x00B1;
  7718. t['plusmod'] = 0x02D6;
  7719. t['plusmonospace'] = 0xFF0B;
  7720. t['plussmall'] = 0xFE62;
  7721. t['plussuperior'] = 0x207A;
  7722. t['pmonospace'] = 0xFF50;
  7723. t['pmsquare'] = 0x33D8;
  7724. t['pohiragana'] = 0x307D;
  7725. t['pointingindexdownwhite'] = 0x261F;
  7726. t['pointingindexleftwhite'] = 0x261C;
  7727. t['pointingindexrightwhite'] = 0x261E;
  7728. t['pointingindexupwhite'] = 0x261D;
  7729. t['pokatakana'] = 0x30DD;
  7730. t['poplathai'] = 0x0E1B;
  7731. t['postalmark'] = 0x3012;
  7732. t['postalmarkface'] = 0x3020;
  7733. t['pparen'] = 0x24AB;
  7734. t['precedes'] = 0x227A;
  7735. t['prescription'] = 0x211E;
  7736. t['primemod'] = 0x02B9;
  7737. t['primereversed'] = 0x2035;
  7738. t['product'] = 0x220F;
  7739. t['projective'] = 0x2305;
  7740. t['prolongedkana'] = 0x30FC;
  7741. t['propellor'] = 0x2318;
  7742. t['propersubset'] = 0x2282;
  7743. t['propersuperset'] = 0x2283;
  7744. t['proportion'] = 0x2237;
  7745. t['proportional'] = 0x221D;
  7746. t['psi'] = 0x03C8;
  7747. t['psicyrillic'] = 0x0471;
  7748. t['psilipneumatacyrilliccmb'] = 0x0486;
  7749. t['pssquare'] = 0x33B0;
  7750. t['puhiragana'] = 0x3077;
  7751. t['pukatakana'] = 0x30D7;
  7752. t['pvsquare'] = 0x33B4;
  7753. t['pwsquare'] = 0x33BA;
  7754. t['q'] = 0x0071;
  7755. t['qadeva'] = 0x0958;
  7756. t['qadmahebrew'] = 0x05A8;
  7757. t['qafarabic'] = 0x0642;
  7758. t['qaffinalarabic'] = 0xFED6;
  7759. t['qafinitialarabic'] = 0xFED7;
  7760. t['qafmedialarabic'] = 0xFED8;
  7761. t['qamats'] = 0x05B8;
  7762. t['qamats10'] = 0x05B8;
  7763. t['qamats1a'] = 0x05B8;
  7764. t['qamats1c'] = 0x05B8;
  7765. t['qamats27'] = 0x05B8;
  7766. t['qamats29'] = 0x05B8;
  7767. t['qamats33'] = 0x05B8;
  7768. t['qamatsde'] = 0x05B8;
  7769. t['qamatshebrew'] = 0x05B8;
  7770. t['qamatsnarrowhebrew'] = 0x05B8;
  7771. t['qamatsqatanhebrew'] = 0x05B8;
  7772. t['qamatsqatannarrowhebrew'] = 0x05B8;
  7773. t['qamatsqatanquarterhebrew'] = 0x05B8;
  7774. t['qamatsqatanwidehebrew'] = 0x05B8;
  7775. t['qamatsquarterhebrew'] = 0x05B8;
  7776. t['qamatswidehebrew'] = 0x05B8;
  7777. t['qarneyparahebrew'] = 0x059F;
  7778. t['qbopomofo'] = 0x3111;
  7779. t['qcircle'] = 0x24E0;
  7780. t['qhook'] = 0x02A0;
  7781. t['qmonospace'] = 0xFF51;
  7782. t['qof'] = 0x05E7;
  7783. t['qofdagesh'] = 0xFB47;
  7784. t['qofdageshhebrew'] = 0xFB47;
  7785. t['qofhebrew'] = 0x05E7;
  7786. t['qparen'] = 0x24AC;
  7787. t['quarternote'] = 0x2669;
  7788. t['qubuts'] = 0x05BB;
  7789. t['qubuts18'] = 0x05BB;
  7790. t['qubuts25'] = 0x05BB;
  7791. t['qubuts31'] = 0x05BB;
  7792. t['qubutshebrew'] = 0x05BB;
  7793. t['qubutsnarrowhebrew'] = 0x05BB;
  7794. t['qubutsquarterhebrew'] = 0x05BB;
  7795. t['qubutswidehebrew'] = 0x05BB;
  7796. t['question'] = 0x003F;
  7797. t['questionarabic'] = 0x061F;
  7798. t['questionarmenian'] = 0x055E;
  7799. t['questiondown'] = 0x00BF;
  7800. t['questiondownsmall'] = 0xF7BF;
  7801. t['questiongreek'] = 0x037E;
  7802. t['questionmonospace'] = 0xFF1F;
  7803. t['questionsmall'] = 0xF73F;
  7804. t['quotedbl'] = 0x0022;
  7805. t['quotedblbase'] = 0x201E;
  7806. t['quotedblleft'] = 0x201C;
  7807. t['quotedblmonospace'] = 0xFF02;
  7808. t['quotedblprime'] = 0x301E;
  7809. t['quotedblprimereversed'] = 0x301D;
  7810. t['quotedblright'] = 0x201D;
  7811. t['quoteleft'] = 0x2018;
  7812. t['quoteleftreversed'] = 0x201B;
  7813. t['quotereversed'] = 0x201B;
  7814. t['quoteright'] = 0x2019;
  7815. t['quoterightn'] = 0x0149;
  7816. t['quotesinglbase'] = 0x201A;
  7817. t['quotesingle'] = 0x0027;
  7818. t['quotesinglemonospace'] = 0xFF07;
  7819. t['r'] = 0x0072;
  7820. t['raarmenian'] = 0x057C;
  7821. t['rabengali'] = 0x09B0;
  7822. t['racute'] = 0x0155;
  7823. t['radeva'] = 0x0930;
  7824. t['radical'] = 0x221A;
  7825. t['radicalex'] = 0xF8E5;
  7826. t['radoverssquare'] = 0x33AE;
  7827. t['radoverssquaredsquare'] = 0x33AF;
  7828. t['radsquare'] = 0x33AD;
  7829. t['rafe'] = 0x05BF;
  7830. t['rafehebrew'] = 0x05BF;
  7831. t['ragujarati'] = 0x0AB0;
  7832. t['ragurmukhi'] = 0x0A30;
  7833. t['rahiragana'] = 0x3089;
  7834. t['rakatakana'] = 0x30E9;
  7835. t['rakatakanahalfwidth'] = 0xFF97;
  7836. t['ralowerdiagonalbengali'] = 0x09F1;
  7837. t['ramiddlediagonalbengali'] = 0x09F0;
  7838. t['ramshorn'] = 0x0264;
  7839. t['ratio'] = 0x2236;
  7840. t['rbopomofo'] = 0x3116;
  7841. t['rcaron'] = 0x0159;
  7842. t['rcedilla'] = 0x0157;
  7843. t['rcircle'] = 0x24E1;
  7844. t['rcommaaccent'] = 0x0157;
  7845. t['rdblgrave'] = 0x0211;
  7846. t['rdotaccent'] = 0x1E59;
  7847. t['rdotbelow'] = 0x1E5B;
  7848. t['rdotbelowmacron'] = 0x1E5D;
  7849. t['referencemark'] = 0x203B;
  7850. t['reflexsubset'] = 0x2286;
  7851. t['reflexsuperset'] = 0x2287;
  7852. t['registered'] = 0x00AE;
  7853. t['registersans'] = 0xF8E8;
  7854. t['registerserif'] = 0xF6DA;
  7855. t['reharabic'] = 0x0631;
  7856. t['reharmenian'] = 0x0580;
  7857. t['rehfinalarabic'] = 0xFEAE;
  7858. t['rehiragana'] = 0x308C;
  7859. t['rekatakana'] = 0x30EC;
  7860. t['rekatakanahalfwidth'] = 0xFF9A;
  7861. t['resh'] = 0x05E8;
  7862. t['reshdageshhebrew'] = 0xFB48;
  7863. t['reshhebrew'] = 0x05E8;
  7864. t['reversedtilde'] = 0x223D;
  7865. t['reviahebrew'] = 0x0597;
  7866. t['reviamugrashhebrew'] = 0x0597;
  7867. t['revlogicalnot'] = 0x2310;
  7868. t['rfishhook'] = 0x027E;
  7869. t['rfishhookreversed'] = 0x027F;
  7870. t['rhabengali'] = 0x09DD;
  7871. t['rhadeva'] = 0x095D;
  7872. t['rho'] = 0x03C1;
  7873. t['rhook'] = 0x027D;
  7874. t['rhookturned'] = 0x027B;
  7875. t['rhookturnedsuperior'] = 0x02B5;
  7876. t['rhosymbolgreek'] = 0x03F1;
  7877. t['rhotichookmod'] = 0x02DE;
  7878. t['rieulacirclekorean'] = 0x3271;
  7879. t['rieulaparenkorean'] = 0x3211;
  7880. t['rieulcirclekorean'] = 0x3263;
  7881. t['rieulhieuhkorean'] = 0x3140;
  7882. t['rieulkiyeokkorean'] = 0x313A;
  7883. t['rieulkiyeoksioskorean'] = 0x3169;
  7884. t['rieulkorean'] = 0x3139;
  7885. t['rieulmieumkorean'] = 0x313B;
  7886. t['rieulpansioskorean'] = 0x316C;
  7887. t['rieulparenkorean'] = 0x3203;
  7888. t['rieulphieuphkorean'] = 0x313F;
  7889. t['rieulpieupkorean'] = 0x313C;
  7890. t['rieulpieupsioskorean'] = 0x316B;
  7891. t['rieulsioskorean'] = 0x313D;
  7892. t['rieulthieuthkorean'] = 0x313E;
  7893. t['rieultikeutkorean'] = 0x316A;
  7894. t['rieulyeorinhieuhkorean'] = 0x316D;
  7895. t['rightangle'] = 0x221F;
  7896. t['righttackbelowcmb'] = 0x0319;
  7897. t['righttriangle'] = 0x22BF;
  7898. t['rihiragana'] = 0x308A;
  7899. t['rikatakana'] = 0x30EA;
  7900. t['rikatakanahalfwidth'] = 0xFF98;
  7901. t['ring'] = 0x02DA;
  7902. t['ringbelowcmb'] = 0x0325;
  7903. t['ringcmb'] = 0x030A;
  7904. t['ringhalfleft'] = 0x02BF;
  7905. t['ringhalfleftarmenian'] = 0x0559;
  7906. t['ringhalfleftbelowcmb'] = 0x031C;
  7907. t['ringhalfleftcentered'] = 0x02D3;
  7908. t['ringhalfright'] = 0x02BE;
  7909. t['ringhalfrightbelowcmb'] = 0x0339;
  7910. t['ringhalfrightcentered'] = 0x02D2;
  7911. t['rinvertedbreve'] = 0x0213;
  7912. t['rittorusquare'] = 0x3351;
  7913. t['rlinebelow'] = 0x1E5F;
  7914. t['rlongleg'] = 0x027C;
  7915. t['rlonglegturned'] = 0x027A;
  7916. t['rmonospace'] = 0xFF52;
  7917. t['rohiragana'] = 0x308D;
  7918. t['rokatakana'] = 0x30ED;
  7919. t['rokatakanahalfwidth'] = 0xFF9B;
  7920. t['roruathai'] = 0x0E23;
  7921. t['rparen'] = 0x24AD;
  7922. t['rrabengali'] = 0x09DC;
  7923. t['rradeva'] = 0x0931;
  7924. t['rragurmukhi'] = 0x0A5C;
  7925. t['rreharabic'] = 0x0691;
  7926. t['rrehfinalarabic'] = 0xFB8D;
  7927. t['rrvocalicbengali'] = 0x09E0;
  7928. t['rrvocalicdeva'] = 0x0960;
  7929. t['rrvocalicgujarati'] = 0x0AE0;
  7930. t['rrvocalicvowelsignbengali'] = 0x09C4;
  7931. t['rrvocalicvowelsigndeva'] = 0x0944;
  7932. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  7933. t['rsuperior'] = 0xF6F1;
  7934. t['rtblock'] = 0x2590;
  7935. t['rturned'] = 0x0279;
  7936. t['rturnedsuperior'] = 0x02B4;
  7937. t['ruhiragana'] = 0x308B;
  7938. t['rukatakana'] = 0x30EB;
  7939. t['rukatakanahalfwidth'] = 0xFF99;
  7940. t['rupeemarkbengali'] = 0x09F2;
  7941. t['rupeesignbengali'] = 0x09F3;
  7942. t['rupiah'] = 0xF6DD;
  7943. t['ruthai'] = 0x0E24;
  7944. t['rvocalicbengali'] = 0x098B;
  7945. t['rvocalicdeva'] = 0x090B;
  7946. t['rvocalicgujarati'] = 0x0A8B;
  7947. t['rvocalicvowelsignbengali'] = 0x09C3;
  7948. t['rvocalicvowelsigndeva'] = 0x0943;
  7949. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  7950. t['s'] = 0x0073;
  7951. t['sabengali'] = 0x09B8;
  7952. t['sacute'] = 0x015B;
  7953. t['sacutedotaccent'] = 0x1E65;
  7954. t['sadarabic'] = 0x0635;
  7955. t['sadeva'] = 0x0938;
  7956. t['sadfinalarabic'] = 0xFEBA;
  7957. t['sadinitialarabic'] = 0xFEBB;
  7958. t['sadmedialarabic'] = 0xFEBC;
  7959. t['sagujarati'] = 0x0AB8;
  7960. t['sagurmukhi'] = 0x0A38;
  7961. t['sahiragana'] = 0x3055;
  7962. t['sakatakana'] = 0x30B5;
  7963. t['sakatakanahalfwidth'] = 0xFF7B;
  7964. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  7965. t['samekh'] = 0x05E1;
  7966. t['samekhdagesh'] = 0xFB41;
  7967. t['samekhdageshhebrew'] = 0xFB41;
  7968. t['samekhhebrew'] = 0x05E1;
  7969. t['saraaathai'] = 0x0E32;
  7970. t['saraaethai'] = 0x0E41;
  7971. t['saraaimaimalaithai'] = 0x0E44;
  7972. t['saraaimaimuanthai'] = 0x0E43;
  7973. t['saraamthai'] = 0x0E33;
  7974. t['saraathai'] = 0x0E30;
  7975. t['saraethai'] = 0x0E40;
  7976. t['saraiileftthai'] = 0xF886;
  7977. t['saraiithai'] = 0x0E35;
  7978. t['saraileftthai'] = 0xF885;
  7979. t['saraithai'] = 0x0E34;
  7980. t['saraothai'] = 0x0E42;
  7981. t['saraueeleftthai'] = 0xF888;
  7982. t['saraueethai'] = 0x0E37;
  7983. t['saraueleftthai'] = 0xF887;
  7984. t['sarauethai'] = 0x0E36;
  7985. t['sarauthai'] = 0x0E38;
  7986. t['sarauuthai'] = 0x0E39;
  7987. t['sbopomofo'] = 0x3119;
  7988. t['scaron'] = 0x0161;
  7989. t['scarondotaccent'] = 0x1E67;
  7990. t['scedilla'] = 0x015F;
  7991. t['schwa'] = 0x0259;
  7992. t['schwacyrillic'] = 0x04D9;
  7993. t['schwadieresiscyrillic'] = 0x04DB;
  7994. t['schwahook'] = 0x025A;
  7995. t['scircle'] = 0x24E2;
  7996. t['scircumflex'] = 0x015D;
  7997. t['scommaaccent'] = 0x0219;
  7998. t['sdotaccent'] = 0x1E61;
  7999. t['sdotbelow'] = 0x1E63;
  8000. t['sdotbelowdotaccent'] = 0x1E69;
  8001. t['seagullbelowcmb'] = 0x033C;
  8002. t['second'] = 0x2033;
  8003. t['secondtonechinese'] = 0x02CA;
  8004. t['section'] = 0x00A7;
  8005. t['seenarabic'] = 0x0633;
  8006. t['seenfinalarabic'] = 0xFEB2;
  8007. t['seeninitialarabic'] = 0xFEB3;
  8008. t['seenmedialarabic'] = 0xFEB4;
  8009. t['segol'] = 0x05B6;
  8010. t['segol13'] = 0x05B6;
  8011. t['segol1f'] = 0x05B6;
  8012. t['segol2c'] = 0x05B6;
  8013. t['segolhebrew'] = 0x05B6;
  8014. t['segolnarrowhebrew'] = 0x05B6;
  8015. t['segolquarterhebrew'] = 0x05B6;
  8016. t['segoltahebrew'] = 0x0592;
  8017. t['segolwidehebrew'] = 0x05B6;
  8018. t['seharmenian'] = 0x057D;
  8019. t['sehiragana'] = 0x305B;
  8020. t['sekatakana'] = 0x30BB;
  8021. t['sekatakanahalfwidth'] = 0xFF7E;
  8022. t['semicolon'] = 0x003B;
  8023. t['semicolonarabic'] = 0x061B;
  8024. t['semicolonmonospace'] = 0xFF1B;
  8025. t['semicolonsmall'] = 0xFE54;
  8026. t['semivoicedmarkkana'] = 0x309C;
  8027. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8028. t['sentisquare'] = 0x3322;
  8029. t['sentosquare'] = 0x3323;
  8030. t['seven'] = 0x0037;
  8031. t['sevenarabic'] = 0x0667;
  8032. t['sevenbengali'] = 0x09ED;
  8033. t['sevencircle'] = 0x2466;
  8034. t['sevencircleinversesansserif'] = 0x2790;
  8035. t['sevendeva'] = 0x096D;
  8036. t['seveneighths'] = 0x215E;
  8037. t['sevengujarati'] = 0x0AED;
  8038. t['sevengurmukhi'] = 0x0A6D;
  8039. t['sevenhackarabic'] = 0x0667;
  8040. t['sevenhangzhou'] = 0x3027;
  8041. t['sevenideographicparen'] = 0x3226;
  8042. t['seveninferior'] = 0x2087;
  8043. t['sevenmonospace'] = 0xFF17;
  8044. t['sevenoldstyle'] = 0xF737;
  8045. t['sevenparen'] = 0x247A;
  8046. t['sevenperiod'] = 0x248E;
  8047. t['sevenpersian'] = 0x06F7;
  8048. t['sevenroman'] = 0x2176;
  8049. t['sevensuperior'] = 0x2077;
  8050. t['seventeencircle'] = 0x2470;
  8051. t['seventeenparen'] = 0x2484;
  8052. t['seventeenperiod'] = 0x2498;
  8053. t['seventhai'] = 0x0E57;
  8054. t['sfthyphen'] = 0x00AD;
  8055. t['shaarmenian'] = 0x0577;
  8056. t['shabengali'] = 0x09B6;
  8057. t['shacyrillic'] = 0x0448;
  8058. t['shaddaarabic'] = 0x0651;
  8059. t['shaddadammaarabic'] = 0xFC61;
  8060. t['shaddadammatanarabic'] = 0xFC5E;
  8061. t['shaddafathaarabic'] = 0xFC60;
  8062. t['shaddakasraarabic'] = 0xFC62;
  8063. t['shaddakasratanarabic'] = 0xFC5F;
  8064. t['shade'] = 0x2592;
  8065. t['shadedark'] = 0x2593;
  8066. t['shadelight'] = 0x2591;
  8067. t['shademedium'] = 0x2592;
  8068. t['shadeva'] = 0x0936;
  8069. t['shagujarati'] = 0x0AB6;
  8070. t['shagurmukhi'] = 0x0A36;
  8071. t['shalshelethebrew'] = 0x0593;
  8072. t['shbopomofo'] = 0x3115;
  8073. t['shchacyrillic'] = 0x0449;
  8074. t['sheenarabic'] = 0x0634;
  8075. t['sheenfinalarabic'] = 0xFEB6;
  8076. t['sheeninitialarabic'] = 0xFEB7;
  8077. t['sheenmedialarabic'] = 0xFEB8;
  8078. t['sheicoptic'] = 0x03E3;
  8079. t['sheqel'] = 0x20AA;
  8080. t['sheqelhebrew'] = 0x20AA;
  8081. t['sheva'] = 0x05B0;
  8082. t['sheva115'] = 0x05B0;
  8083. t['sheva15'] = 0x05B0;
  8084. t['sheva22'] = 0x05B0;
  8085. t['sheva2e'] = 0x05B0;
  8086. t['shevahebrew'] = 0x05B0;
  8087. t['shevanarrowhebrew'] = 0x05B0;
  8088. t['shevaquarterhebrew'] = 0x05B0;
  8089. t['shevawidehebrew'] = 0x05B0;
  8090. t['shhacyrillic'] = 0x04BB;
  8091. t['shimacoptic'] = 0x03ED;
  8092. t['shin'] = 0x05E9;
  8093. t['shindagesh'] = 0xFB49;
  8094. t['shindageshhebrew'] = 0xFB49;
  8095. t['shindageshshindot'] = 0xFB2C;
  8096. t['shindageshshindothebrew'] = 0xFB2C;
  8097. t['shindageshsindot'] = 0xFB2D;
  8098. t['shindageshsindothebrew'] = 0xFB2D;
  8099. t['shindothebrew'] = 0x05C1;
  8100. t['shinhebrew'] = 0x05E9;
  8101. t['shinshindot'] = 0xFB2A;
  8102. t['shinshindothebrew'] = 0xFB2A;
  8103. t['shinsindot'] = 0xFB2B;
  8104. t['shinsindothebrew'] = 0xFB2B;
  8105. t['shook'] = 0x0282;
  8106. t['sigma'] = 0x03C3;
  8107. t['sigma1'] = 0x03C2;
  8108. t['sigmafinal'] = 0x03C2;
  8109. t['sigmalunatesymbolgreek'] = 0x03F2;
  8110. t['sihiragana'] = 0x3057;
  8111. t['sikatakana'] = 0x30B7;
  8112. t['sikatakanahalfwidth'] = 0xFF7C;
  8113. t['siluqhebrew'] = 0x05BD;
  8114. t['siluqlefthebrew'] = 0x05BD;
  8115. t['similar'] = 0x223C;
  8116. t['sindothebrew'] = 0x05C2;
  8117. t['siosacirclekorean'] = 0x3274;
  8118. t['siosaparenkorean'] = 0x3214;
  8119. t['sioscieuckorean'] = 0x317E;
  8120. t['sioscirclekorean'] = 0x3266;
  8121. t['sioskiyeokkorean'] = 0x317A;
  8122. t['sioskorean'] = 0x3145;
  8123. t['siosnieunkorean'] = 0x317B;
  8124. t['siosparenkorean'] = 0x3206;
  8125. t['siospieupkorean'] = 0x317D;
  8126. t['siostikeutkorean'] = 0x317C;
  8127. t['six'] = 0x0036;
  8128. t['sixarabic'] = 0x0666;
  8129. t['sixbengali'] = 0x09EC;
  8130. t['sixcircle'] = 0x2465;
  8131. t['sixcircleinversesansserif'] = 0x278F;
  8132. t['sixdeva'] = 0x096C;
  8133. t['sixgujarati'] = 0x0AEC;
  8134. t['sixgurmukhi'] = 0x0A6C;
  8135. t['sixhackarabic'] = 0x0666;
  8136. t['sixhangzhou'] = 0x3026;
  8137. t['sixideographicparen'] = 0x3225;
  8138. t['sixinferior'] = 0x2086;
  8139. t['sixmonospace'] = 0xFF16;
  8140. t['sixoldstyle'] = 0xF736;
  8141. t['sixparen'] = 0x2479;
  8142. t['sixperiod'] = 0x248D;
  8143. t['sixpersian'] = 0x06F6;
  8144. t['sixroman'] = 0x2175;
  8145. t['sixsuperior'] = 0x2076;
  8146. t['sixteencircle'] = 0x246F;
  8147. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8148. t['sixteenparen'] = 0x2483;
  8149. t['sixteenperiod'] = 0x2497;
  8150. t['sixthai'] = 0x0E56;
  8151. t['slash'] = 0x002F;
  8152. t['slashmonospace'] = 0xFF0F;
  8153. t['slong'] = 0x017F;
  8154. t['slongdotaccent'] = 0x1E9B;
  8155. t['smileface'] = 0x263A;
  8156. t['smonospace'] = 0xFF53;
  8157. t['sofpasuqhebrew'] = 0x05C3;
  8158. t['softhyphen'] = 0x00AD;
  8159. t['softsigncyrillic'] = 0x044C;
  8160. t['sohiragana'] = 0x305D;
  8161. t['sokatakana'] = 0x30BD;
  8162. t['sokatakanahalfwidth'] = 0xFF7F;
  8163. t['soliduslongoverlaycmb'] = 0x0338;
  8164. t['solidusshortoverlaycmb'] = 0x0337;
  8165. t['sorusithai'] = 0x0E29;
  8166. t['sosalathai'] = 0x0E28;
  8167. t['sosothai'] = 0x0E0B;
  8168. t['sosuathai'] = 0x0E2A;
  8169. t['space'] = 0x0020;
  8170. t['spacehackarabic'] = 0x0020;
  8171. t['spade'] = 0x2660;
  8172. t['spadesuitblack'] = 0x2660;
  8173. t['spadesuitwhite'] = 0x2664;
  8174. t['sparen'] = 0x24AE;
  8175. t['squarebelowcmb'] = 0x033B;
  8176. t['squarecc'] = 0x33C4;
  8177. t['squarecm'] = 0x339D;
  8178. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8179. t['squarehorizontalfill'] = 0x25A4;
  8180. t['squarekg'] = 0x338F;
  8181. t['squarekm'] = 0x339E;
  8182. t['squarekmcapital'] = 0x33CE;
  8183. t['squareln'] = 0x33D1;
  8184. t['squarelog'] = 0x33D2;
  8185. t['squaremg'] = 0x338E;
  8186. t['squaremil'] = 0x33D5;
  8187. t['squaremm'] = 0x339C;
  8188. t['squaremsquared'] = 0x33A1;
  8189. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8190. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8191. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8192. t['squareverticalfill'] = 0x25A5;
  8193. t['squarewhitewithsmallblack'] = 0x25A3;
  8194. t['srsquare'] = 0x33DB;
  8195. t['ssabengali'] = 0x09B7;
  8196. t['ssadeva'] = 0x0937;
  8197. t['ssagujarati'] = 0x0AB7;
  8198. t['ssangcieuckorean'] = 0x3149;
  8199. t['ssanghieuhkorean'] = 0x3185;
  8200. t['ssangieungkorean'] = 0x3180;
  8201. t['ssangkiyeokkorean'] = 0x3132;
  8202. t['ssangnieunkorean'] = 0x3165;
  8203. t['ssangpieupkorean'] = 0x3143;
  8204. t['ssangsioskorean'] = 0x3146;
  8205. t['ssangtikeutkorean'] = 0x3138;
  8206. t['ssuperior'] = 0xF6F2;
  8207. t['sterling'] = 0x00A3;
  8208. t['sterlingmonospace'] = 0xFFE1;
  8209. t['strokelongoverlaycmb'] = 0x0336;
  8210. t['strokeshortoverlaycmb'] = 0x0335;
  8211. t['subset'] = 0x2282;
  8212. t['subsetnotequal'] = 0x228A;
  8213. t['subsetorequal'] = 0x2286;
  8214. t['succeeds'] = 0x227B;
  8215. t['suchthat'] = 0x220B;
  8216. t['suhiragana'] = 0x3059;
  8217. t['sukatakana'] = 0x30B9;
  8218. t['sukatakanahalfwidth'] = 0xFF7D;
  8219. t['sukunarabic'] = 0x0652;
  8220. t['summation'] = 0x2211;
  8221. t['sun'] = 0x263C;
  8222. t['superset'] = 0x2283;
  8223. t['supersetnotequal'] = 0x228B;
  8224. t['supersetorequal'] = 0x2287;
  8225. t['svsquare'] = 0x33DC;
  8226. t['syouwaerasquare'] = 0x337C;
  8227. t['t'] = 0x0074;
  8228. t['tabengali'] = 0x09A4;
  8229. t['tackdown'] = 0x22A4;
  8230. t['tackleft'] = 0x22A3;
  8231. t['tadeva'] = 0x0924;
  8232. t['tagujarati'] = 0x0AA4;
  8233. t['tagurmukhi'] = 0x0A24;
  8234. t['taharabic'] = 0x0637;
  8235. t['tahfinalarabic'] = 0xFEC2;
  8236. t['tahinitialarabic'] = 0xFEC3;
  8237. t['tahiragana'] = 0x305F;
  8238. t['tahmedialarabic'] = 0xFEC4;
  8239. t['taisyouerasquare'] = 0x337D;
  8240. t['takatakana'] = 0x30BF;
  8241. t['takatakanahalfwidth'] = 0xFF80;
  8242. t['tatweelarabic'] = 0x0640;
  8243. t['tau'] = 0x03C4;
  8244. t['tav'] = 0x05EA;
  8245. t['tavdages'] = 0xFB4A;
  8246. t['tavdagesh'] = 0xFB4A;
  8247. t['tavdageshhebrew'] = 0xFB4A;
  8248. t['tavhebrew'] = 0x05EA;
  8249. t['tbar'] = 0x0167;
  8250. t['tbopomofo'] = 0x310A;
  8251. t['tcaron'] = 0x0165;
  8252. t['tccurl'] = 0x02A8;
  8253. t['tcedilla'] = 0x0163;
  8254. t['tcheharabic'] = 0x0686;
  8255. t['tchehfinalarabic'] = 0xFB7B;
  8256. t['tchehinitialarabic'] = 0xFB7C;
  8257. t['tchehmedialarabic'] = 0xFB7D;
  8258. t['tcircle'] = 0x24E3;
  8259. t['tcircumflexbelow'] = 0x1E71;
  8260. t['tcommaaccent'] = 0x0163;
  8261. t['tdieresis'] = 0x1E97;
  8262. t['tdotaccent'] = 0x1E6B;
  8263. t['tdotbelow'] = 0x1E6D;
  8264. t['tecyrillic'] = 0x0442;
  8265. t['tedescendercyrillic'] = 0x04AD;
  8266. t['teharabic'] = 0x062A;
  8267. t['tehfinalarabic'] = 0xFE96;
  8268. t['tehhahinitialarabic'] = 0xFCA2;
  8269. t['tehhahisolatedarabic'] = 0xFC0C;
  8270. t['tehinitialarabic'] = 0xFE97;
  8271. t['tehiragana'] = 0x3066;
  8272. t['tehjeeminitialarabic'] = 0xFCA1;
  8273. t['tehjeemisolatedarabic'] = 0xFC0B;
  8274. t['tehmarbutaarabic'] = 0x0629;
  8275. t['tehmarbutafinalarabic'] = 0xFE94;
  8276. t['tehmedialarabic'] = 0xFE98;
  8277. t['tehmeeminitialarabic'] = 0xFCA4;
  8278. t['tehmeemisolatedarabic'] = 0xFC0E;
  8279. t['tehnoonfinalarabic'] = 0xFC73;
  8280. t['tekatakana'] = 0x30C6;
  8281. t['tekatakanahalfwidth'] = 0xFF83;
  8282. t['telephone'] = 0x2121;
  8283. t['telephoneblack'] = 0x260E;
  8284. t['telishagedolahebrew'] = 0x05A0;
  8285. t['telishaqetanahebrew'] = 0x05A9;
  8286. t['tencircle'] = 0x2469;
  8287. t['tenideographicparen'] = 0x3229;
  8288. t['tenparen'] = 0x247D;
  8289. t['tenperiod'] = 0x2491;
  8290. t['tenroman'] = 0x2179;
  8291. t['tesh'] = 0x02A7;
  8292. t['tet'] = 0x05D8;
  8293. t['tetdagesh'] = 0xFB38;
  8294. t['tetdageshhebrew'] = 0xFB38;
  8295. t['tethebrew'] = 0x05D8;
  8296. t['tetsecyrillic'] = 0x04B5;
  8297. t['tevirhebrew'] = 0x059B;
  8298. t['tevirlefthebrew'] = 0x059B;
  8299. t['thabengali'] = 0x09A5;
  8300. t['thadeva'] = 0x0925;
  8301. t['thagujarati'] = 0x0AA5;
  8302. t['thagurmukhi'] = 0x0A25;
  8303. t['thalarabic'] = 0x0630;
  8304. t['thalfinalarabic'] = 0xFEAC;
  8305. t['thanthakhatlowleftthai'] = 0xF898;
  8306. t['thanthakhatlowrightthai'] = 0xF897;
  8307. t['thanthakhatthai'] = 0x0E4C;
  8308. t['thanthakhatupperleftthai'] = 0xF896;
  8309. t['theharabic'] = 0x062B;
  8310. t['thehfinalarabic'] = 0xFE9A;
  8311. t['thehinitialarabic'] = 0xFE9B;
  8312. t['thehmedialarabic'] = 0xFE9C;
  8313. t['thereexists'] = 0x2203;
  8314. t['therefore'] = 0x2234;
  8315. t['theta'] = 0x03B8;
  8316. t['theta1'] = 0x03D1;
  8317. t['thetasymbolgreek'] = 0x03D1;
  8318. t['thieuthacirclekorean'] = 0x3279;
  8319. t['thieuthaparenkorean'] = 0x3219;
  8320. t['thieuthcirclekorean'] = 0x326B;
  8321. t['thieuthkorean'] = 0x314C;
  8322. t['thieuthparenkorean'] = 0x320B;
  8323. t['thirteencircle'] = 0x246C;
  8324. t['thirteenparen'] = 0x2480;
  8325. t['thirteenperiod'] = 0x2494;
  8326. t['thonangmonthothai'] = 0x0E11;
  8327. t['thook'] = 0x01AD;
  8328. t['thophuthaothai'] = 0x0E12;
  8329. t['thorn'] = 0x00FE;
  8330. t['thothahanthai'] = 0x0E17;
  8331. t['thothanthai'] = 0x0E10;
  8332. t['thothongthai'] = 0x0E18;
  8333. t['thothungthai'] = 0x0E16;
  8334. t['thousandcyrillic'] = 0x0482;
  8335. t['thousandsseparatorarabic'] = 0x066C;
  8336. t['thousandsseparatorpersian'] = 0x066C;
  8337. t['three'] = 0x0033;
  8338. t['threearabic'] = 0x0663;
  8339. t['threebengali'] = 0x09E9;
  8340. t['threecircle'] = 0x2462;
  8341. t['threecircleinversesansserif'] = 0x278C;
  8342. t['threedeva'] = 0x0969;
  8343. t['threeeighths'] = 0x215C;
  8344. t['threegujarati'] = 0x0AE9;
  8345. t['threegurmukhi'] = 0x0A69;
  8346. t['threehackarabic'] = 0x0663;
  8347. t['threehangzhou'] = 0x3023;
  8348. t['threeideographicparen'] = 0x3222;
  8349. t['threeinferior'] = 0x2083;
  8350. t['threemonospace'] = 0xFF13;
  8351. t['threenumeratorbengali'] = 0x09F6;
  8352. t['threeoldstyle'] = 0xF733;
  8353. t['threeparen'] = 0x2476;
  8354. t['threeperiod'] = 0x248A;
  8355. t['threepersian'] = 0x06F3;
  8356. t['threequarters'] = 0x00BE;
  8357. t['threequartersemdash'] = 0xF6DE;
  8358. t['threeroman'] = 0x2172;
  8359. t['threesuperior'] = 0x00B3;
  8360. t['threethai'] = 0x0E53;
  8361. t['thzsquare'] = 0x3394;
  8362. t['tihiragana'] = 0x3061;
  8363. t['tikatakana'] = 0x30C1;
  8364. t['tikatakanahalfwidth'] = 0xFF81;
  8365. t['tikeutacirclekorean'] = 0x3270;
  8366. t['tikeutaparenkorean'] = 0x3210;
  8367. t['tikeutcirclekorean'] = 0x3262;
  8368. t['tikeutkorean'] = 0x3137;
  8369. t['tikeutparenkorean'] = 0x3202;
  8370. t['tilde'] = 0x02DC;
  8371. t['tildebelowcmb'] = 0x0330;
  8372. t['tildecmb'] = 0x0303;
  8373. t['tildecomb'] = 0x0303;
  8374. t['tildedoublecmb'] = 0x0360;
  8375. t['tildeoperator'] = 0x223C;
  8376. t['tildeoverlaycmb'] = 0x0334;
  8377. t['tildeverticalcmb'] = 0x033E;
  8378. t['timescircle'] = 0x2297;
  8379. t['tipehahebrew'] = 0x0596;
  8380. t['tipehalefthebrew'] = 0x0596;
  8381. t['tippigurmukhi'] = 0x0A70;
  8382. t['titlocyrilliccmb'] = 0x0483;
  8383. t['tiwnarmenian'] = 0x057F;
  8384. t['tlinebelow'] = 0x1E6F;
  8385. t['tmonospace'] = 0xFF54;
  8386. t['toarmenian'] = 0x0569;
  8387. t['tohiragana'] = 0x3068;
  8388. t['tokatakana'] = 0x30C8;
  8389. t['tokatakanahalfwidth'] = 0xFF84;
  8390. t['tonebarextrahighmod'] = 0x02E5;
  8391. t['tonebarextralowmod'] = 0x02E9;
  8392. t['tonebarhighmod'] = 0x02E6;
  8393. t['tonebarlowmod'] = 0x02E8;
  8394. t['tonebarmidmod'] = 0x02E7;
  8395. t['tonefive'] = 0x01BD;
  8396. t['tonesix'] = 0x0185;
  8397. t['tonetwo'] = 0x01A8;
  8398. t['tonos'] = 0x0384;
  8399. t['tonsquare'] = 0x3327;
  8400. t['topatakthai'] = 0x0E0F;
  8401. t['tortoiseshellbracketleft'] = 0x3014;
  8402. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8403. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8404. t['tortoiseshellbracketright'] = 0x3015;
  8405. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8406. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8407. t['totaothai'] = 0x0E15;
  8408. t['tpalatalhook'] = 0x01AB;
  8409. t['tparen'] = 0x24AF;
  8410. t['trademark'] = 0x2122;
  8411. t['trademarksans'] = 0xF8EA;
  8412. t['trademarkserif'] = 0xF6DB;
  8413. t['tretroflexhook'] = 0x0288;
  8414. t['triagdn'] = 0x25BC;
  8415. t['triaglf'] = 0x25C4;
  8416. t['triagrt'] = 0x25BA;
  8417. t['triagup'] = 0x25B2;
  8418. t['ts'] = 0x02A6;
  8419. t['tsadi'] = 0x05E6;
  8420. t['tsadidagesh'] = 0xFB46;
  8421. t['tsadidageshhebrew'] = 0xFB46;
  8422. t['tsadihebrew'] = 0x05E6;
  8423. t['tsecyrillic'] = 0x0446;
  8424. t['tsere'] = 0x05B5;
  8425. t['tsere12'] = 0x05B5;
  8426. t['tsere1e'] = 0x05B5;
  8427. t['tsere2b'] = 0x05B5;
  8428. t['tserehebrew'] = 0x05B5;
  8429. t['tserenarrowhebrew'] = 0x05B5;
  8430. t['tserequarterhebrew'] = 0x05B5;
  8431. t['tserewidehebrew'] = 0x05B5;
  8432. t['tshecyrillic'] = 0x045B;
  8433. t['tsuperior'] = 0xF6F3;
  8434. t['ttabengali'] = 0x099F;
  8435. t['ttadeva'] = 0x091F;
  8436. t['ttagujarati'] = 0x0A9F;
  8437. t['ttagurmukhi'] = 0x0A1F;
  8438. t['tteharabic'] = 0x0679;
  8439. t['ttehfinalarabic'] = 0xFB67;
  8440. t['ttehinitialarabic'] = 0xFB68;
  8441. t['ttehmedialarabic'] = 0xFB69;
  8442. t['tthabengali'] = 0x09A0;
  8443. t['tthadeva'] = 0x0920;
  8444. t['tthagujarati'] = 0x0AA0;
  8445. t['tthagurmukhi'] = 0x0A20;
  8446. t['tturned'] = 0x0287;
  8447. t['tuhiragana'] = 0x3064;
  8448. t['tukatakana'] = 0x30C4;
  8449. t['tukatakanahalfwidth'] = 0xFF82;
  8450. t['tusmallhiragana'] = 0x3063;
  8451. t['tusmallkatakana'] = 0x30C3;
  8452. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8453. t['twelvecircle'] = 0x246B;
  8454. t['twelveparen'] = 0x247F;
  8455. t['twelveperiod'] = 0x2493;
  8456. t['twelveroman'] = 0x217B;
  8457. t['twentycircle'] = 0x2473;
  8458. t['twentyhangzhou'] = 0x5344;
  8459. t['twentyparen'] = 0x2487;
  8460. t['twentyperiod'] = 0x249B;
  8461. t['two'] = 0x0032;
  8462. t['twoarabic'] = 0x0662;
  8463. t['twobengali'] = 0x09E8;
  8464. t['twocircle'] = 0x2461;
  8465. t['twocircleinversesansserif'] = 0x278B;
  8466. t['twodeva'] = 0x0968;
  8467. t['twodotenleader'] = 0x2025;
  8468. t['twodotleader'] = 0x2025;
  8469. t['twodotleadervertical'] = 0xFE30;
  8470. t['twogujarati'] = 0x0AE8;
  8471. t['twogurmukhi'] = 0x0A68;
  8472. t['twohackarabic'] = 0x0662;
  8473. t['twohangzhou'] = 0x3022;
  8474. t['twoideographicparen'] = 0x3221;
  8475. t['twoinferior'] = 0x2082;
  8476. t['twomonospace'] = 0xFF12;
  8477. t['twonumeratorbengali'] = 0x09F5;
  8478. t['twooldstyle'] = 0xF732;
  8479. t['twoparen'] = 0x2475;
  8480. t['twoperiod'] = 0x2489;
  8481. t['twopersian'] = 0x06F2;
  8482. t['tworoman'] = 0x2171;
  8483. t['twostroke'] = 0x01BB;
  8484. t['twosuperior'] = 0x00B2;
  8485. t['twothai'] = 0x0E52;
  8486. t['twothirds'] = 0x2154;
  8487. t['u'] = 0x0075;
  8488. t['uacute'] = 0x00FA;
  8489. t['ubar'] = 0x0289;
  8490. t['ubengali'] = 0x0989;
  8491. t['ubopomofo'] = 0x3128;
  8492. t['ubreve'] = 0x016D;
  8493. t['ucaron'] = 0x01D4;
  8494. t['ucircle'] = 0x24E4;
  8495. t['ucircumflex'] = 0x00FB;
  8496. t['ucircumflexbelow'] = 0x1E77;
  8497. t['ucyrillic'] = 0x0443;
  8498. t['udattadeva'] = 0x0951;
  8499. t['udblacute'] = 0x0171;
  8500. t['udblgrave'] = 0x0215;
  8501. t['udeva'] = 0x0909;
  8502. t['udieresis'] = 0x00FC;
  8503. t['udieresisacute'] = 0x01D8;
  8504. t['udieresisbelow'] = 0x1E73;
  8505. t['udieresiscaron'] = 0x01DA;
  8506. t['udieresiscyrillic'] = 0x04F1;
  8507. t['udieresisgrave'] = 0x01DC;
  8508. t['udieresismacron'] = 0x01D6;
  8509. t['udotbelow'] = 0x1EE5;
  8510. t['ugrave'] = 0x00F9;
  8511. t['ugujarati'] = 0x0A89;
  8512. t['ugurmukhi'] = 0x0A09;
  8513. t['uhiragana'] = 0x3046;
  8514. t['uhookabove'] = 0x1EE7;
  8515. t['uhorn'] = 0x01B0;
  8516. t['uhornacute'] = 0x1EE9;
  8517. t['uhorndotbelow'] = 0x1EF1;
  8518. t['uhorngrave'] = 0x1EEB;
  8519. t['uhornhookabove'] = 0x1EED;
  8520. t['uhorntilde'] = 0x1EEF;
  8521. t['uhungarumlaut'] = 0x0171;
  8522. t['uhungarumlautcyrillic'] = 0x04F3;
  8523. t['uinvertedbreve'] = 0x0217;
  8524. t['ukatakana'] = 0x30A6;
  8525. t['ukatakanahalfwidth'] = 0xFF73;
  8526. t['ukcyrillic'] = 0x0479;
  8527. t['ukorean'] = 0x315C;
  8528. t['umacron'] = 0x016B;
  8529. t['umacroncyrillic'] = 0x04EF;
  8530. t['umacrondieresis'] = 0x1E7B;
  8531. t['umatragurmukhi'] = 0x0A41;
  8532. t['umonospace'] = 0xFF55;
  8533. t['underscore'] = 0x005F;
  8534. t['underscoredbl'] = 0x2017;
  8535. t['underscoremonospace'] = 0xFF3F;
  8536. t['underscorevertical'] = 0xFE33;
  8537. t['underscorewavy'] = 0xFE4F;
  8538. t['union'] = 0x222A;
  8539. t['universal'] = 0x2200;
  8540. t['uogonek'] = 0x0173;
  8541. t['uparen'] = 0x24B0;
  8542. t['upblock'] = 0x2580;
  8543. t['upperdothebrew'] = 0x05C4;
  8544. t['upsilon'] = 0x03C5;
  8545. t['upsilondieresis'] = 0x03CB;
  8546. t['upsilondieresistonos'] = 0x03B0;
  8547. t['upsilonlatin'] = 0x028A;
  8548. t['upsilontonos'] = 0x03CD;
  8549. t['uptackbelowcmb'] = 0x031D;
  8550. t['uptackmod'] = 0x02D4;
  8551. t['uragurmukhi'] = 0x0A73;
  8552. t['uring'] = 0x016F;
  8553. t['ushortcyrillic'] = 0x045E;
  8554. t['usmallhiragana'] = 0x3045;
  8555. t['usmallkatakana'] = 0x30A5;
  8556. t['usmallkatakanahalfwidth'] = 0xFF69;
  8557. t['ustraightcyrillic'] = 0x04AF;
  8558. t['ustraightstrokecyrillic'] = 0x04B1;
  8559. t['utilde'] = 0x0169;
  8560. t['utildeacute'] = 0x1E79;
  8561. t['utildebelow'] = 0x1E75;
  8562. t['uubengali'] = 0x098A;
  8563. t['uudeva'] = 0x090A;
  8564. t['uugujarati'] = 0x0A8A;
  8565. t['uugurmukhi'] = 0x0A0A;
  8566. t['uumatragurmukhi'] = 0x0A42;
  8567. t['uuvowelsignbengali'] = 0x09C2;
  8568. t['uuvowelsigndeva'] = 0x0942;
  8569. t['uuvowelsigngujarati'] = 0x0AC2;
  8570. t['uvowelsignbengali'] = 0x09C1;
  8571. t['uvowelsigndeva'] = 0x0941;
  8572. t['uvowelsigngujarati'] = 0x0AC1;
  8573. t['v'] = 0x0076;
  8574. t['vadeva'] = 0x0935;
  8575. t['vagujarati'] = 0x0AB5;
  8576. t['vagurmukhi'] = 0x0A35;
  8577. t['vakatakana'] = 0x30F7;
  8578. t['vav'] = 0x05D5;
  8579. t['vavdagesh'] = 0xFB35;
  8580. t['vavdagesh65'] = 0xFB35;
  8581. t['vavdageshhebrew'] = 0xFB35;
  8582. t['vavhebrew'] = 0x05D5;
  8583. t['vavholam'] = 0xFB4B;
  8584. t['vavholamhebrew'] = 0xFB4B;
  8585. t['vavvavhebrew'] = 0x05F0;
  8586. t['vavyodhebrew'] = 0x05F1;
  8587. t['vcircle'] = 0x24E5;
  8588. t['vdotbelow'] = 0x1E7F;
  8589. t['vecyrillic'] = 0x0432;
  8590. t['veharabic'] = 0x06A4;
  8591. t['vehfinalarabic'] = 0xFB6B;
  8592. t['vehinitialarabic'] = 0xFB6C;
  8593. t['vehmedialarabic'] = 0xFB6D;
  8594. t['vekatakana'] = 0x30F9;
  8595. t['venus'] = 0x2640;
  8596. t['verticalbar'] = 0x007C;
  8597. t['verticallineabovecmb'] = 0x030D;
  8598. t['verticallinebelowcmb'] = 0x0329;
  8599. t['verticallinelowmod'] = 0x02CC;
  8600. t['verticallinemod'] = 0x02C8;
  8601. t['vewarmenian'] = 0x057E;
  8602. t['vhook'] = 0x028B;
  8603. t['vikatakana'] = 0x30F8;
  8604. t['viramabengali'] = 0x09CD;
  8605. t['viramadeva'] = 0x094D;
  8606. t['viramagujarati'] = 0x0ACD;
  8607. t['visargabengali'] = 0x0983;
  8608. t['visargadeva'] = 0x0903;
  8609. t['visargagujarati'] = 0x0A83;
  8610. t['vmonospace'] = 0xFF56;
  8611. t['voarmenian'] = 0x0578;
  8612. t['voicediterationhiragana'] = 0x309E;
  8613. t['voicediterationkatakana'] = 0x30FE;
  8614. t['voicedmarkkana'] = 0x309B;
  8615. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  8616. t['vokatakana'] = 0x30FA;
  8617. t['vparen'] = 0x24B1;
  8618. t['vtilde'] = 0x1E7D;
  8619. t['vturned'] = 0x028C;
  8620. t['vuhiragana'] = 0x3094;
  8621. t['vukatakana'] = 0x30F4;
  8622. t['w'] = 0x0077;
  8623. t['wacute'] = 0x1E83;
  8624. t['waekorean'] = 0x3159;
  8625. t['wahiragana'] = 0x308F;
  8626. t['wakatakana'] = 0x30EF;
  8627. t['wakatakanahalfwidth'] = 0xFF9C;
  8628. t['wakorean'] = 0x3158;
  8629. t['wasmallhiragana'] = 0x308E;
  8630. t['wasmallkatakana'] = 0x30EE;
  8631. t['wattosquare'] = 0x3357;
  8632. t['wavedash'] = 0x301C;
  8633. t['wavyunderscorevertical'] = 0xFE34;
  8634. t['wawarabic'] = 0x0648;
  8635. t['wawfinalarabic'] = 0xFEEE;
  8636. t['wawhamzaabovearabic'] = 0x0624;
  8637. t['wawhamzaabovefinalarabic'] = 0xFE86;
  8638. t['wbsquare'] = 0x33DD;
  8639. t['wcircle'] = 0x24E6;
  8640. t['wcircumflex'] = 0x0175;
  8641. t['wdieresis'] = 0x1E85;
  8642. t['wdotaccent'] = 0x1E87;
  8643. t['wdotbelow'] = 0x1E89;
  8644. t['wehiragana'] = 0x3091;
  8645. t['weierstrass'] = 0x2118;
  8646. t['wekatakana'] = 0x30F1;
  8647. t['wekorean'] = 0x315E;
  8648. t['weokorean'] = 0x315D;
  8649. t['wgrave'] = 0x1E81;
  8650. t['whitebullet'] = 0x25E6;
  8651. t['whitecircle'] = 0x25CB;
  8652. t['whitecircleinverse'] = 0x25D9;
  8653. t['whitecornerbracketleft'] = 0x300E;
  8654. t['whitecornerbracketleftvertical'] = 0xFE43;
  8655. t['whitecornerbracketright'] = 0x300F;
  8656. t['whitecornerbracketrightvertical'] = 0xFE44;
  8657. t['whitediamond'] = 0x25C7;
  8658. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  8659. t['whitedownpointingsmalltriangle'] = 0x25BF;
  8660. t['whitedownpointingtriangle'] = 0x25BD;
  8661. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  8662. t['whiteleftpointingtriangle'] = 0x25C1;
  8663. t['whitelenticularbracketleft'] = 0x3016;
  8664. t['whitelenticularbracketright'] = 0x3017;
  8665. t['whiterightpointingsmalltriangle'] = 0x25B9;
  8666. t['whiterightpointingtriangle'] = 0x25B7;
  8667. t['whitesmallsquare'] = 0x25AB;
  8668. t['whitesmilingface'] = 0x263A;
  8669. t['whitesquare'] = 0x25A1;
  8670. t['whitestar'] = 0x2606;
  8671. t['whitetelephone'] = 0x260F;
  8672. t['whitetortoiseshellbracketleft'] = 0x3018;
  8673. t['whitetortoiseshellbracketright'] = 0x3019;
  8674. t['whiteuppointingsmalltriangle'] = 0x25B5;
  8675. t['whiteuppointingtriangle'] = 0x25B3;
  8676. t['wihiragana'] = 0x3090;
  8677. t['wikatakana'] = 0x30F0;
  8678. t['wikorean'] = 0x315F;
  8679. t['wmonospace'] = 0xFF57;
  8680. t['wohiragana'] = 0x3092;
  8681. t['wokatakana'] = 0x30F2;
  8682. t['wokatakanahalfwidth'] = 0xFF66;
  8683. t['won'] = 0x20A9;
  8684. t['wonmonospace'] = 0xFFE6;
  8685. t['wowaenthai'] = 0x0E27;
  8686. t['wparen'] = 0x24B2;
  8687. t['wring'] = 0x1E98;
  8688. t['wsuperior'] = 0x02B7;
  8689. t['wturned'] = 0x028D;
  8690. t['wynn'] = 0x01BF;
  8691. t['x'] = 0x0078;
  8692. t['xabovecmb'] = 0x033D;
  8693. t['xbopomofo'] = 0x3112;
  8694. t['xcircle'] = 0x24E7;
  8695. t['xdieresis'] = 0x1E8D;
  8696. t['xdotaccent'] = 0x1E8B;
  8697. t['xeharmenian'] = 0x056D;
  8698. t['xi'] = 0x03BE;
  8699. t['xmonospace'] = 0xFF58;
  8700. t['xparen'] = 0x24B3;
  8701. t['xsuperior'] = 0x02E3;
  8702. t['y'] = 0x0079;
  8703. t['yaadosquare'] = 0x334E;
  8704. t['yabengali'] = 0x09AF;
  8705. t['yacute'] = 0x00FD;
  8706. t['yadeva'] = 0x092F;
  8707. t['yaekorean'] = 0x3152;
  8708. t['yagujarati'] = 0x0AAF;
  8709. t['yagurmukhi'] = 0x0A2F;
  8710. t['yahiragana'] = 0x3084;
  8711. t['yakatakana'] = 0x30E4;
  8712. t['yakatakanahalfwidth'] = 0xFF94;
  8713. t['yakorean'] = 0x3151;
  8714. t['yamakkanthai'] = 0x0E4E;
  8715. t['yasmallhiragana'] = 0x3083;
  8716. t['yasmallkatakana'] = 0x30E3;
  8717. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  8718. t['yatcyrillic'] = 0x0463;
  8719. t['ycircle'] = 0x24E8;
  8720. t['ycircumflex'] = 0x0177;
  8721. t['ydieresis'] = 0x00FF;
  8722. t['ydotaccent'] = 0x1E8F;
  8723. t['ydotbelow'] = 0x1EF5;
  8724. t['yeharabic'] = 0x064A;
  8725. t['yehbarreearabic'] = 0x06D2;
  8726. t['yehbarreefinalarabic'] = 0xFBAF;
  8727. t['yehfinalarabic'] = 0xFEF2;
  8728. t['yehhamzaabovearabic'] = 0x0626;
  8729. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  8730. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  8731. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  8732. t['yehinitialarabic'] = 0xFEF3;
  8733. t['yehmedialarabic'] = 0xFEF4;
  8734. t['yehmeeminitialarabic'] = 0xFCDD;
  8735. t['yehmeemisolatedarabic'] = 0xFC58;
  8736. t['yehnoonfinalarabic'] = 0xFC94;
  8737. t['yehthreedotsbelowarabic'] = 0x06D1;
  8738. t['yekorean'] = 0x3156;
  8739. t['yen'] = 0x00A5;
  8740. t['yenmonospace'] = 0xFFE5;
  8741. t['yeokorean'] = 0x3155;
  8742. t['yeorinhieuhkorean'] = 0x3186;
  8743. t['yerahbenyomohebrew'] = 0x05AA;
  8744. t['yerahbenyomolefthebrew'] = 0x05AA;
  8745. t['yericyrillic'] = 0x044B;
  8746. t['yerudieresiscyrillic'] = 0x04F9;
  8747. t['yesieungkorean'] = 0x3181;
  8748. t['yesieungpansioskorean'] = 0x3183;
  8749. t['yesieungsioskorean'] = 0x3182;
  8750. t['yetivhebrew'] = 0x059A;
  8751. t['ygrave'] = 0x1EF3;
  8752. t['yhook'] = 0x01B4;
  8753. t['yhookabove'] = 0x1EF7;
  8754. t['yiarmenian'] = 0x0575;
  8755. t['yicyrillic'] = 0x0457;
  8756. t['yikorean'] = 0x3162;
  8757. t['yinyang'] = 0x262F;
  8758. t['yiwnarmenian'] = 0x0582;
  8759. t['ymonospace'] = 0xFF59;
  8760. t['yod'] = 0x05D9;
  8761. t['yoddagesh'] = 0xFB39;
  8762. t['yoddageshhebrew'] = 0xFB39;
  8763. t['yodhebrew'] = 0x05D9;
  8764. t['yodyodhebrew'] = 0x05F2;
  8765. t['yodyodpatahhebrew'] = 0xFB1F;
  8766. t['yohiragana'] = 0x3088;
  8767. t['yoikorean'] = 0x3189;
  8768. t['yokatakana'] = 0x30E8;
  8769. t['yokatakanahalfwidth'] = 0xFF96;
  8770. t['yokorean'] = 0x315B;
  8771. t['yosmallhiragana'] = 0x3087;
  8772. t['yosmallkatakana'] = 0x30E7;
  8773. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  8774. t['yotgreek'] = 0x03F3;
  8775. t['yoyaekorean'] = 0x3188;
  8776. t['yoyakorean'] = 0x3187;
  8777. t['yoyakthai'] = 0x0E22;
  8778. t['yoyingthai'] = 0x0E0D;
  8779. t['yparen'] = 0x24B4;
  8780. t['ypogegrammeni'] = 0x037A;
  8781. t['ypogegrammenigreekcmb'] = 0x0345;
  8782. t['yr'] = 0x01A6;
  8783. t['yring'] = 0x1E99;
  8784. t['ysuperior'] = 0x02B8;
  8785. t['ytilde'] = 0x1EF9;
  8786. t['yturned'] = 0x028E;
  8787. t['yuhiragana'] = 0x3086;
  8788. t['yuikorean'] = 0x318C;
  8789. t['yukatakana'] = 0x30E6;
  8790. t['yukatakanahalfwidth'] = 0xFF95;
  8791. t['yukorean'] = 0x3160;
  8792. t['yusbigcyrillic'] = 0x046B;
  8793. t['yusbigiotifiedcyrillic'] = 0x046D;
  8794. t['yuslittlecyrillic'] = 0x0467;
  8795. t['yuslittleiotifiedcyrillic'] = 0x0469;
  8796. t['yusmallhiragana'] = 0x3085;
  8797. t['yusmallkatakana'] = 0x30E5;
  8798. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  8799. t['yuyekorean'] = 0x318B;
  8800. t['yuyeokorean'] = 0x318A;
  8801. t['yyabengali'] = 0x09DF;
  8802. t['yyadeva'] = 0x095F;
  8803. t['z'] = 0x007A;
  8804. t['zaarmenian'] = 0x0566;
  8805. t['zacute'] = 0x017A;
  8806. t['zadeva'] = 0x095B;
  8807. t['zagurmukhi'] = 0x0A5B;
  8808. t['zaharabic'] = 0x0638;
  8809. t['zahfinalarabic'] = 0xFEC6;
  8810. t['zahinitialarabic'] = 0xFEC7;
  8811. t['zahiragana'] = 0x3056;
  8812. t['zahmedialarabic'] = 0xFEC8;
  8813. t['zainarabic'] = 0x0632;
  8814. t['zainfinalarabic'] = 0xFEB0;
  8815. t['zakatakana'] = 0x30B6;
  8816. t['zaqefgadolhebrew'] = 0x0595;
  8817. t['zaqefqatanhebrew'] = 0x0594;
  8818. t['zarqahebrew'] = 0x0598;
  8819. t['zayin'] = 0x05D6;
  8820. t['zayindagesh'] = 0xFB36;
  8821. t['zayindageshhebrew'] = 0xFB36;
  8822. t['zayinhebrew'] = 0x05D6;
  8823. t['zbopomofo'] = 0x3117;
  8824. t['zcaron'] = 0x017E;
  8825. t['zcircle'] = 0x24E9;
  8826. t['zcircumflex'] = 0x1E91;
  8827. t['zcurl'] = 0x0291;
  8828. t['zdot'] = 0x017C;
  8829. t['zdotaccent'] = 0x017C;
  8830. t['zdotbelow'] = 0x1E93;
  8831. t['zecyrillic'] = 0x0437;
  8832. t['zedescendercyrillic'] = 0x0499;
  8833. t['zedieresiscyrillic'] = 0x04DF;
  8834. t['zehiragana'] = 0x305C;
  8835. t['zekatakana'] = 0x30BC;
  8836. t['zero'] = 0x0030;
  8837. t['zeroarabic'] = 0x0660;
  8838. t['zerobengali'] = 0x09E6;
  8839. t['zerodeva'] = 0x0966;
  8840. t['zerogujarati'] = 0x0AE6;
  8841. t['zerogurmukhi'] = 0x0A66;
  8842. t['zerohackarabic'] = 0x0660;
  8843. t['zeroinferior'] = 0x2080;
  8844. t['zeromonospace'] = 0xFF10;
  8845. t['zerooldstyle'] = 0xF730;
  8846. t['zeropersian'] = 0x06F0;
  8847. t['zerosuperior'] = 0x2070;
  8848. t['zerothai'] = 0x0E50;
  8849. t['zerowidthjoiner'] = 0xFEFF;
  8850. t['zerowidthnonjoiner'] = 0x200C;
  8851. t['zerowidthspace'] = 0x200B;
  8852. t['zeta'] = 0x03B6;
  8853. t['zhbopomofo'] = 0x3113;
  8854. t['zhearmenian'] = 0x056A;
  8855. t['zhebrevecyrillic'] = 0x04C2;
  8856. t['zhecyrillic'] = 0x0436;
  8857. t['zhedescendercyrillic'] = 0x0497;
  8858. t['zhedieresiscyrillic'] = 0x04DD;
  8859. t['zihiragana'] = 0x3058;
  8860. t['zikatakana'] = 0x30B8;
  8861. t['zinorhebrew'] = 0x05AE;
  8862. t['zlinebelow'] = 0x1E95;
  8863. t['zmonospace'] = 0xFF5A;
  8864. t['zohiragana'] = 0x305E;
  8865. t['zokatakana'] = 0x30BE;
  8866. t['zparen'] = 0x24B5;
  8867. t['zretroflexhook'] = 0x0290;
  8868. t['zstroke'] = 0x01B6;
  8869. t['zuhiragana'] = 0x305A;
  8870. t['zukatakana'] = 0x30BA;
  8871. t['.notdef'] = 0x0000;
  8872. });
  8873. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  8874. t['space'] = 0x0020;
  8875. t['a1'] = 0x2701;
  8876. t['a2'] = 0x2702;
  8877. t['a202'] = 0x2703;
  8878. t['a3'] = 0x2704;
  8879. t['a4'] = 0x260E;
  8880. t['a5'] = 0x2706;
  8881. t['a119'] = 0x2707;
  8882. t['a118'] = 0x2708;
  8883. t['a117'] = 0x2709;
  8884. t['a11'] = 0x261B;
  8885. t['a12'] = 0x261E;
  8886. t['a13'] = 0x270C;
  8887. t['a14'] = 0x270D;
  8888. t['a15'] = 0x270E;
  8889. t['a16'] = 0x270F;
  8890. t['a105'] = 0x2710;
  8891. t['a17'] = 0x2711;
  8892. t['a18'] = 0x2712;
  8893. t['a19'] = 0x2713;
  8894. t['a20'] = 0x2714;
  8895. t['a21'] = 0x2715;
  8896. t['a22'] = 0x2716;
  8897. t['a23'] = 0x2717;
  8898. t['a24'] = 0x2718;
  8899. t['a25'] = 0x2719;
  8900. t['a26'] = 0x271A;
  8901. t['a27'] = 0x271B;
  8902. t['a28'] = 0x271C;
  8903. t['a6'] = 0x271D;
  8904. t['a7'] = 0x271E;
  8905. t['a8'] = 0x271F;
  8906. t['a9'] = 0x2720;
  8907. t['a10'] = 0x2721;
  8908. t['a29'] = 0x2722;
  8909. t['a30'] = 0x2723;
  8910. t['a31'] = 0x2724;
  8911. t['a32'] = 0x2725;
  8912. t['a33'] = 0x2726;
  8913. t['a34'] = 0x2727;
  8914. t['a35'] = 0x2605;
  8915. t['a36'] = 0x2729;
  8916. t['a37'] = 0x272A;
  8917. t['a38'] = 0x272B;
  8918. t['a39'] = 0x272C;
  8919. t['a40'] = 0x272D;
  8920. t['a41'] = 0x272E;
  8921. t['a42'] = 0x272F;
  8922. t['a43'] = 0x2730;
  8923. t['a44'] = 0x2731;
  8924. t['a45'] = 0x2732;
  8925. t['a46'] = 0x2733;
  8926. t['a47'] = 0x2734;
  8927. t['a48'] = 0x2735;
  8928. t['a49'] = 0x2736;
  8929. t['a50'] = 0x2737;
  8930. t['a51'] = 0x2738;
  8931. t['a52'] = 0x2739;
  8932. t['a53'] = 0x273A;
  8933. t['a54'] = 0x273B;
  8934. t['a55'] = 0x273C;
  8935. t['a56'] = 0x273D;
  8936. t['a57'] = 0x273E;
  8937. t['a58'] = 0x273F;
  8938. t['a59'] = 0x2740;
  8939. t['a60'] = 0x2741;
  8940. t['a61'] = 0x2742;
  8941. t['a62'] = 0x2743;
  8942. t['a63'] = 0x2744;
  8943. t['a64'] = 0x2745;
  8944. t['a65'] = 0x2746;
  8945. t['a66'] = 0x2747;
  8946. t['a67'] = 0x2748;
  8947. t['a68'] = 0x2749;
  8948. t['a69'] = 0x274A;
  8949. t['a70'] = 0x274B;
  8950. t['a71'] = 0x25CF;
  8951. t['a72'] = 0x274D;
  8952. t['a73'] = 0x25A0;
  8953. t['a74'] = 0x274F;
  8954. t['a203'] = 0x2750;
  8955. t['a75'] = 0x2751;
  8956. t['a204'] = 0x2752;
  8957. t['a76'] = 0x25B2;
  8958. t['a77'] = 0x25BC;
  8959. t['a78'] = 0x25C6;
  8960. t['a79'] = 0x2756;
  8961. t['a81'] = 0x25D7;
  8962. t['a82'] = 0x2758;
  8963. t['a83'] = 0x2759;
  8964. t['a84'] = 0x275A;
  8965. t['a97'] = 0x275B;
  8966. t['a98'] = 0x275C;
  8967. t['a99'] = 0x275D;
  8968. t['a100'] = 0x275E;
  8969. t['a101'] = 0x2761;
  8970. t['a102'] = 0x2762;
  8971. t['a103'] = 0x2763;
  8972. t['a104'] = 0x2764;
  8973. t['a106'] = 0x2765;
  8974. t['a107'] = 0x2766;
  8975. t['a108'] = 0x2767;
  8976. t['a112'] = 0x2663;
  8977. t['a111'] = 0x2666;
  8978. t['a110'] = 0x2665;
  8979. t['a109'] = 0x2660;
  8980. t['a120'] = 0x2460;
  8981. t['a121'] = 0x2461;
  8982. t['a122'] = 0x2462;
  8983. t['a123'] = 0x2463;
  8984. t['a124'] = 0x2464;
  8985. t['a125'] = 0x2465;
  8986. t['a126'] = 0x2466;
  8987. t['a127'] = 0x2467;
  8988. t['a128'] = 0x2468;
  8989. t['a129'] = 0x2469;
  8990. t['a130'] = 0x2776;
  8991. t['a131'] = 0x2777;
  8992. t['a132'] = 0x2778;
  8993. t['a133'] = 0x2779;
  8994. t['a134'] = 0x277A;
  8995. t['a135'] = 0x277B;
  8996. t['a136'] = 0x277C;
  8997. t['a137'] = 0x277D;
  8998. t['a138'] = 0x277E;
  8999. t['a139'] = 0x277F;
  9000. t['a140'] = 0x2780;
  9001. t['a141'] = 0x2781;
  9002. t['a142'] = 0x2782;
  9003. t['a143'] = 0x2783;
  9004. t['a144'] = 0x2784;
  9005. t['a145'] = 0x2785;
  9006. t['a146'] = 0x2786;
  9007. t['a147'] = 0x2787;
  9008. t['a148'] = 0x2788;
  9009. t['a149'] = 0x2789;
  9010. t['a150'] = 0x278A;
  9011. t['a151'] = 0x278B;
  9012. t['a152'] = 0x278C;
  9013. t['a153'] = 0x278D;
  9014. t['a154'] = 0x278E;
  9015. t['a155'] = 0x278F;
  9016. t['a156'] = 0x2790;
  9017. t['a157'] = 0x2791;
  9018. t['a158'] = 0x2792;
  9019. t['a159'] = 0x2793;
  9020. t['a160'] = 0x2794;
  9021. t['a161'] = 0x2192;
  9022. t['a163'] = 0x2194;
  9023. t['a164'] = 0x2195;
  9024. t['a196'] = 0x2798;
  9025. t['a165'] = 0x2799;
  9026. t['a192'] = 0x279A;
  9027. t['a166'] = 0x279B;
  9028. t['a167'] = 0x279C;
  9029. t['a168'] = 0x279D;
  9030. t['a169'] = 0x279E;
  9031. t['a170'] = 0x279F;
  9032. t['a171'] = 0x27A0;
  9033. t['a172'] = 0x27A1;
  9034. t['a173'] = 0x27A2;
  9035. t['a162'] = 0x27A3;
  9036. t['a174'] = 0x27A4;
  9037. t['a175'] = 0x27A5;
  9038. t['a176'] = 0x27A6;
  9039. t['a177'] = 0x27A7;
  9040. t['a178'] = 0x27A8;
  9041. t['a179'] = 0x27A9;
  9042. t['a193'] = 0x27AA;
  9043. t['a180'] = 0x27AB;
  9044. t['a199'] = 0x27AC;
  9045. t['a181'] = 0x27AD;
  9046. t['a200'] = 0x27AE;
  9047. t['a182'] = 0x27AF;
  9048. t['a201'] = 0x27B1;
  9049. t['a183'] = 0x27B2;
  9050. t['a184'] = 0x27B3;
  9051. t['a197'] = 0x27B4;
  9052. t['a185'] = 0x27B5;
  9053. t['a194'] = 0x27B6;
  9054. t['a198'] = 0x27B7;
  9055. t['a186'] = 0x27B8;
  9056. t['a195'] = 0x27B9;
  9057. t['a187'] = 0x27BA;
  9058. t['a188'] = 0x27BB;
  9059. t['a189'] = 0x27BC;
  9060. t['a190'] = 0x27BD;
  9061. t['a191'] = 0x27BE;
  9062. t['a89'] = 0x2768; // 0xF8D7
  9063. t['a90'] = 0x2769; // 0xF8D8
  9064. t['a93'] = 0x276A; // 0xF8D9
  9065. t['a94'] = 0x276B; // 0xF8DA
  9066. t['a91'] = 0x276C; // 0xF8DB
  9067. t['a92'] = 0x276D; // 0xF8DC
  9068. t['a205'] = 0x276E; // 0xF8DD
  9069. t['a85'] = 0x276F; // 0xF8DE
  9070. t['a206'] = 0x2770; // 0xF8DF
  9071. t['a86'] = 0x2771; // 0xF8E0
  9072. t['a87'] = 0x2772; // 0xF8E1
  9073. t['a88'] = 0x2773; // 0xF8E2
  9074. t['a95'] = 0x2774; // 0xF8E3
  9075. t['a96'] = 0x2775; // 0xF8E4
  9076. t['.notdef'] = 0x0000;
  9077. });
  9078. exports.getGlyphsUnicode = getGlyphsUnicode;
  9079. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9080. }));
  9081. (function (root, factory) {
  9082. {
  9083. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9084. root.pdfjsCoreArithmeticDecoder);
  9085. }
  9086. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9087. var error = sharedUtil.error;
  9088. var log2 = sharedUtil.log2;
  9089. var readInt8 = sharedUtil.readInt8;
  9090. var readUint16 = sharedUtil.readUint16;
  9091. var readUint32 = sharedUtil.readUint32;
  9092. var shadow = sharedUtil.shadow;
  9093. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9094. var Jbig2Image = (function Jbig2ImageClosure() {
  9095. // Utility data structures
  9096. function ContextCache() {}
  9097. ContextCache.prototype = {
  9098. getContexts: function(id) {
  9099. if (id in this) {
  9100. return this[id];
  9101. }
  9102. return (this[id] = new Int8Array(1 << 16));
  9103. }
  9104. };
  9105. function DecodingContext(data, start, end) {
  9106. this.data = data;
  9107. this.start = start;
  9108. this.end = end;
  9109. }
  9110. DecodingContext.prototype = {
  9111. get decoder() {
  9112. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9113. return shadow(this, 'decoder', decoder);
  9114. },
  9115. get contextCache() {
  9116. var cache = new ContextCache();
  9117. return shadow(this, 'contextCache', cache);
  9118. }
  9119. };
  9120. // Annex A. Arithmetic Integer Decoding Procedure
  9121. // A.2 Procedure for decoding values
  9122. function decodeInteger(contextCache, procedure, decoder) {
  9123. var contexts = contextCache.getContexts(procedure);
  9124. var prev = 1;
  9125. function readBits(length) {
  9126. var v = 0;
  9127. for (var i = 0; i < length; i++) {
  9128. var bit = decoder.readBit(contexts, prev);
  9129. prev = (prev < 256 ? (prev << 1) | bit :
  9130. (((prev << 1) | bit) & 511) | 256);
  9131. v = (v << 1) | bit;
  9132. }
  9133. return v >>> 0;
  9134. }
  9135. var sign = readBits(1);
  9136. var value = readBits(1) ?
  9137. (readBits(1) ?
  9138. (readBits(1) ?
  9139. (readBits(1) ?
  9140. (readBits(1) ?
  9141. (readBits(32) + 4436) :
  9142. readBits(12) + 340) :
  9143. readBits(8) + 84) :
  9144. readBits(6) + 20) :
  9145. readBits(4) + 4) :
  9146. readBits(2);
  9147. return (sign === 0 ? value : (value > 0 ? -value : null));
  9148. }
  9149. // A.3 The IAID decoding procedure
  9150. function decodeIAID(contextCache, decoder, codeLength) {
  9151. var contexts = contextCache.getContexts('IAID');
  9152. var prev = 1;
  9153. for (var i = 0; i < codeLength; i++) {
  9154. var bit = decoder.readBit(contexts, prev);
  9155. prev = (prev << 1) | bit;
  9156. }
  9157. if (codeLength < 31) {
  9158. return prev & ((1 << codeLength) - 1);
  9159. }
  9160. return prev & 0x7FFFFFFF;
  9161. }
  9162. // 7.3 Segment types
  9163. var SegmentTypes = [
  9164. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9165. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9166. null, null, null, null, null, 'patternDictionary', null, null, null,
  9167. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9168. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9169. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9170. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9171. 'IntermediateGenericRefinementRegion', null,
  9172. 'ImmediateGenericRefinementRegion',
  9173. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9174. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9175. 'Tables', null, null, null, null, null, null, null, null,
  9176. 'Extension'
  9177. ];
  9178. var CodingTemplates = [
  9179. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9180. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9181. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9182. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9183. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9184. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9185. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9186. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9187. {x: -1, y: 0}],
  9188. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9189. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9190. ];
  9191. var RefinementTemplates = [
  9192. {
  9193. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9194. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9195. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9196. },
  9197. {
  9198. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9199. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9200. {x: 0, y: 1}, {x: 1, y: 1}]
  9201. }
  9202. ];
  9203. // See 6.2.5.7 Decoding the bitmap.
  9204. var ReusedContexts = [
  9205. 0x9B25, // 10011 0110010 0101
  9206. 0x0795, // 0011 110010 101
  9207. 0x00E5, // 001 11001 01
  9208. 0x0195 // 011001 0101
  9209. ];
  9210. var RefinementReusedContexts = [
  9211. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9212. 0x0008 // '0000' + '001000'
  9213. ];
  9214. function decodeBitmapTemplate0(width, height, decodingContext) {
  9215. var decoder = decodingContext.decoder;
  9216. var contexts = decodingContext.contextCache.getContexts('GB');
  9217. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9218. // ...ooooo....
  9219. // ..ooooooo... Context template for current pixel (X)
  9220. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9221. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9222. for (i = 0; i < height; i++) {
  9223. row = bitmap[i] = new Uint8Array(width);
  9224. row1 = (i < 1) ? row : bitmap[i - 1];
  9225. row2 = (i < 2) ? row : bitmap[i - 2];
  9226. // At the beginning of each row:
  9227. // Fill contextLabel with pixels that are above/right of (X)
  9228. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9229. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9230. (row1[3] << 4);
  9231. for (j = 0; j < width; j++) {
  9232. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9233. // At each pixel: Clear contextLabel pixels that are shifted
  9234. // out of the context, then add new ones.
  9235. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9236. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9237. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9238. }
  9239. }
  9240. return bitmap;
  9241. }
  9242. // 6.2 Generic Region Decoding Procedure
  9243. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9244. decodingContext) {
  9245. if (mmr) {
  9246. error('JBIG2 error: MMR encoding is not supported');
  9247. }
  9248. // Use optimized version for the most common case
  9249. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9250. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9251. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9252. return decodeBitmapTemplate0(width, height, decodingContext);
  9253. }
  9254. var useskip = !!skip;
  9255. var template = CodingTemplates[templateIndex].concat(at);
  9256. // Sorting is non-standard, and it is not required. But sorting increases
  9257. // the number of template bits that can be reused from the previous
  9258. // contextLabel in the main loop.
  9259. template.sort(function (a, b) {
  9260. return (a.y - b.y) || (a.x - b.x);
  9261. });
  9262. var templateLength = template.length;
  9263. var templateX = new Int8Array(templateLength);
  9264. var templateY = new Int8Array(templateLength);
  9265. var changingTemplateEntries = [];
  9266. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9267. var c, k;
  9268. for (k = 0; k < templateLength; k++) {
  9269. templateX[k] = template[k].x;
  9270. templateY[k] = template[k].y;
  9271. minX = Math.min(minX, template[k].x);
  9272. maxX = Math.max(maxX, template[k].x);
  9273. minY = Math.min(minY, template[k].y);
  9274. // Check if the template pixel appears in two consecutive context labels,
  9275. // so it can be reused. Otherwise, we add it to the list of changing
  9276. // template entries.
  9277. if (k < templateLength - 1 &&
  9278. template[k].y === template[k + 1].y &&
  9279. template[k].x === template[k + 1].x - 1) {
  9280. reuseMask |= 1 << (templateLength - 1 - k);
  9281. } else {
  9282. changingTemplateEntries.push(k);
  9283. }
  9284. }
  9285. var changingEntriesLength = changingTemplateEntries.length;
  9286. var changingTemplateX = new Int8Array(changingEntriesLength);
  9287. var changingTemplateY = new Int8Array(changingEntriesLength);
  9288. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9289. for (c = 0; c < changingEntriesLength; c++) {
  9290. k = changingTemplateEntries[c];
  9291. changingTemplateX[c] = template[k].x;
  9292. changingTemplateY[c] = template[k].y;
  9293. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9294. }
  9295. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9296. var sbb_left = -minX;
  9297. var sbb_top = -minY;
  9298. var sbb_right = width - maxX;
  9299. var pseudoPixelContext = ReusedContexts[templateIndex];
  9300. var row = new Uint8Array(width);
  9301. var bitmap = [];
  9302. var decoder = decodingContext.decoder;
  9303. var contexts = decodingContext.contextCache.getContexts('GB');
  9304. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9305. for (var i = 0; i < height; i++) {
  9306. if (prediction) {
  9307. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9308. ltp ^= sltp;
  9309. if (ltp) {
  9310. bitmap.push(row); // duplicate previous row
  9311. continue;
  9312. }
  9313. }
  9314. row = new Uint8Array(row);
  9315. bitmap.push(row);
  9316. for (j = 0; j < width; j++) {
  9317. if (useskip && skip[i][j]) {
  9318. row[j] = 0;
  9319. continue;
  9320. }
  9321. // Are we in the middle of a scanline, so we can reuse contextLabel
  9322. // bits?
  9323. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9324. // If yes, we can just shift the bits that are reusable and only
  9325. // fetch the remaining ones.
  9326. contextLabel = (contextLabel << 1) & reuseMask;
  9327. for (k = 0; k < changingEntriesLength; k++) {
  9328. i0 = i + changingTemplateY[k];
  9329. j0 = j + changingTemplateX[k];
  9330. bit = bitmap[i0][j0];
  9331. if (bit) {
  9332. bit = changingTemplateBit[k];
  9333. contextLabel |= bit;
  9334. }
  9335. }
  9336. } else {
  9337. // compute the contextLabel from scratch
  9338. contextLabel = 0;
  9339. shift = templateLength - 1;
  9340. for (k = 0; k < templateLength; k++, shift--) {
  9341. j0 = j + templateX[k];
  9342. if (j0 >= 0 && j0 < width) {
  9343. i0 = i + templateY[k];
  9344. if (i0 >= 0) {
  9345. bit = bitmap[i0][j0];
  9346. if (bit) {
  9347. contextLabel |= bit << shift;
  9348. }
  9349. }
  9350. }
  9351. }
  9352. }
  9353. var pixel = decoder.readBit(contexts, contextLabel);
  9354. row[j] = pixel;
  9355. }
  9356. }
  9357. return bitmap;
  9358. }
  9359. // 6.3.2 Generic Refinement Region Decoding Procedure
  9360. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9361. offsetX, offsetY, prediction, at,
  9362. decodingContext) {
  9363. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9364. if (templateIndex === 0) {
  9365. codingTemplate = codingTemplate.concat([at[0]]);
  9366. }
  9367. var codingTemplateLength = codingTemplate.length;
  9368. var codingTemplateX = new Int32Array(codingTemplateLength);
  9369. var codingTemplateY = new Int32Array(codingTemplateLength);
  9370. var k;
  9371. for (k = 0; k < codingTemplateLength; k++) {
  9372. codingTemplateX[k] = codingTemplate[k].x;
  9373. codingTemplateY[k] = codingTemplate[k].y;
  9374. }
  9375. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9376. if (templateIndex === 0) {
  9377. referenceTemplate = referenceTemplate.concat([at[1]]);
  9378. }
  9379. var referenceTemplateLength = referenceTemplate.length;
  9380. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9381. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9382. for (k = 0; k < referenceTemplateLength; k++) {
  9383. referenceTemplateX[k] = referenceTemplate[k].x;
  9384. referenceTemplateY[k] = referenceTemplate[k].y;
  9385. }
  9386. var referenceWidth = referenceBitmap[0].length;
  9387. var referenceHeight = referenceBitmap.length;
  9388. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9389. var bitmap = [];
  9390. var decoder = decodingContext.decoder;
  9391. var contexts = decodingContext.contextCache.getContexts('GR');
  9392. var ltp = 0;
  9393. for (var i = 0; i < height; i++) {
  9394. if (prediction) {
  9395. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9396. ltp ^= sltp;
  9397. if (ltp) {
  9398. error('JBIG2 error: prediction is not supported');
  9399. }
  9400. }
  9401. var row = new Uint8Array(width);
  9402. bitmap.push(row);
  9403. for (var j = 0; j < width; j++) {
  9404. var i0, j0;
  9405. var contextLabel = 0;
  9406. for (k = 0; k < codingTemplateLength; k++) {
  9407. i0 = i + codingTemplateY[k];
  9408. j0 = j + codingTemplateX[k];
  9409. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9410. contextLabel <<= 1; // out of bound pixel
  9411. } else {
  9412. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9413. }
  9414. }
  9415. for (k = 0; k < referenceTemplateLength; k++) {
  9416. i0 = i + referenceTemplateY[k] + offsetY;
  9417. j0 = j + referenceTemplateX[k] + offsetX;
  9418. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9419. j0 >= referenceWidth) {
  9420. contextLabel <<= 1; // out of bound pixel
  9421. } else {
  9422. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9423. }
  9424. }
  9425. var pixel = decoder.readBit(contexts, contextLabel);
  9426. row[j] = pixel;
  9427. }
  9428. }
  9429. return bitmap;
  9430. }
  9431. // 6.5.5 Decoding the symbol dictionary
  9432. function decodeSymbolDictionary(huffman, refinement, symbols,
  9433. numberOfNewSymbols, numberOfExportedSymbols,
  9434. huffmanTables, templateIndex, at,
  9435. refinementTemplateIndex, refinementAt,
  9436. decodingContext) {
  9437. if (huffman) {
  9438. error('JBIG2 error: huffman is not supported');
  9439. }
  9440. var newSymbols = [];
  9441. var currentHeight = 0;
  9442. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9443. var decoder = decodingContext.decoder;
  9444. var contextCache = decodingContext.contextCache;
  9445. while (newSymbols.length < numberOfNewSymbols) {
  9446. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9447. currentHeight += deltaHeight;
  9448. var currentWidth = 0;
  9449. var totalWidth = 0;
  9450. while (true) {
  9451. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9452. if (deltaWidth === null) {
  9453. break; // OOB
  9454. }
  9455. currentWidth += deltaWidth;
  9456. totalWidth += currentWidth;
  9457. var bitmap;
  9458. if (refinement) {
  9459. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9460. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9461. if (numberOfInstances > 1) {
  9462. bitmap = decodeTextRegion(huffman, refinement,
  9463. currentWidth, currentHeight, 0,
  9464. numberOfInstances, 1, //strip size
  9465. symbols.concat(newSymbols),
  9466. symbolCodeLength,
  9467. 0, //transposed
  9468. 0, //ds offset
  9469. 1, //top left 7.4.3.1.1
  9470. 0, //OR operator
  9471. huffmanTables,
  9472. refinementTemplateIndex, refinementAt,
  9473. decodingContext);
  9474. } else {
  9475. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9476. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9477. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9478. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9479. newSymbols[symbolId - symbols.length]);
  9480. bitmap = decodeRefinement(currentWidth, currentHeight,
  9481. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9482. decodingContext);
  9483. }
  9484. } else {
  9485. // 6.5.8.1 Direct-coded symbol bitmap
  9486. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  9487. templateIndex, false, null, at, decodingContext);
  9488. }
  9489. newSymbols.push(bitmap);
  9490. }
  9491. }
  9492. // 6.5.10 Exported symbols
  9493. var exportedSymbols = [];
  9494. var flags = [], currentFlag = false;
  9495. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  9496. while (flags.length < totalSymbolsLength) {
  9497. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  9498. while (runLength--) {
  9499. flags.push(currentFlag);
  9500. }
  9501. currentFlag = !currentFlag;
  9502. }
  9503. for (var i = 0, ii = symbols.length; i < ii; i++) {
  9504. if (flags[i]) {
  9505. exportedSymbols.push(symbols[i]);
  9506. }
  9507. }
  9508. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  9509. if (flags[i]) {
  9510. exportedSymbols.push(newSymbols[j]);
  9511. }
  9512. }
  9513. return exportedSymbols;
  9514. }
  9515. function decodeTextRegion(huffman, refinement, width, height,
  9516. defaultPixelValue, numberOfSymbolInstances,
  9517. stripSize, inputSymbols, symbolCodeLength,
  9518. transposed, dsOffset, referenceCorner,
  9519. combinationOperator, huffmanTables,
  9520. refinementTemplateIndex, refinementAt,
  9521. decodingContext) {
  9522. if (huffman) {
  9523. error('JBIG2 error: huffman is not supported');
  9524. }
  9525. // Prepare bitmap
  9526. var bitmap = [];
  9527. var i, row;
  9528. for (i = 0; i < height; i++) {
  9529. row = new Uint8Array(width);
  9530. if (defaultPixelValue) {
  9531. for (var j = 0; j < width; j++) {
  9532. row[j] = defaultPixelValue;
  9533. }
  9534. }
  9535. bitmap.push(row);
  9536. }
  9537. var decoder = decodingContext.decoder;
  9538. var contextCache = decodingContext.contextCache;
  9539. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9540. var firstS = 0;
  9541. i = 0;
  9542. while (i < numberOfSymbolInstances) {
  9543. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9544. stripT += deltaT;
  9545. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  9546. firstS += deltaFirstS;
  9547. var currentS = firstS;
  9548. do {
  9549. var currentT = (stripSize === 1 ? 0 :
  9550. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  9551. var t = stripSize * stripT + currentT;
  9552. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9553. var applyRefinement = (refinement &&
  9554. decodeInteger(contextCache, 'IARI', decoder));
  9555. var symbolBitmap = inputSymbols[symbolId];
  9556. var symbolWidth = symbolBitmap[0].length;
  9557. var symbolHeight = symbolBitmap.length;
  9558. if (applyRefinement) {
  9559. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  9560. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  9561. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9562. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9563. symbolWidth += rdw;
  9564. symbolHeight += rdh;
  9565. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  9566. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  9567. (rdh >> 1) + rdy, false, refinementAt,
  9568. decodingContext);
  9569. }
  9570. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  9571. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  9572. var s2, t2, symbolRow;
  9573. if (transposed) {
  9574. // Place Symbol Bitmap from T1,S1
  9575. for (s2 = 0; s2 < symbolHeight; s2++) {
  9576. row = bitmap[offsetS + s2];
  9577. if (!row) {
  9578. continue;
  9579. }
  9580. symbolRow = symbolBitmap[s2];
  9581. // To ignore Parts of Symbol bitmap which goes
  9582. // outside bitmap region
  9583. var maxWidth = Math.min(width - offsetT, symbolWidth);
  9584. switch (combinationOperator) {
  9585. case 0: // OR
  9586. for (t2 = 0; t2 < maxWidth; t2++) {
  9587. row[offsetT + t2] |= symbolRow[t2];
  9588. }
  9589. break;
  9590. case 2: // XOR
  9591. for (t2 = 0; t2 < maxWidth; t2++) {
  9592. row[offsetT + t2] ^= symbolRow[t2];
  9593. }
  9594. break;
  9595. default:
  9596. error('JBIG2 error: operator ' + combinationOperator +
  9597. ' is not supported');
  9598. }
  9599. }
  9600. currentS += symbolHeight - 1;
  9601. } else {
  9602. for (t2 = 0; t2 < symbolHeight; t2++) {
  9603. row = bitmap[offsetT + t2];
  9604. if (!row) {
  9605. continue;
  9606. }
  9607. symbolRow = symbolBitmap[t2];
  9608. switch (combinationOperator) {
  9609. case 0: // OR
  9610. for (s2 = 0; s2 < symbolWidth; s2++) {
  9611. row[offsetS + s2] |= symbolRow[s2];
  9612. }
  9613. break;
  9614. case 2: // XOR
  9615. for (s2 = 0; s2 < symbolWidth; s2++) {
  9616. row[offsetS + s2] ^= symbolRow[s2];
  9617. }
  9618. break;
  9619. default:
  9620. error('JBIG2 error: operator ' + combinationOperator +
  9621. ' is not supported');
  9622. }
  9623. }
  9624. currentS += symbolWidth - 1;
  9625. }
  9626. i++;
  9627. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  9628. if (deltaS === null) {
  9629. break; // OOB
  9630. }
  9631. currentS += deltaS + dsOffset;
  9632. } while (true);
  9633. }
  9634. return bitmap;
  9635. }
  9636. function readSegmentHeader(data, start) {
  9637. var segmentHeader = {};
  9638. segmentHeader.number = readUint32(data, start);
  9639. var flags = data[start + 4];
  9640. var segmentType = flags & 0x3F;
  9641. if (!SegmentTypes[segmentType]) {
  9642. error('JBIG2 error: invalid segment type: ' + segmentType);
  9643. }
  9644. segmentHeader.type = segmentType;
  9645. segmentHeader.typeName = SegmentTypes[segmentType];
  9646. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  9647. var pageAssociationFieldSize = !!(flags & 0x40);
  9648. var referredFlags = data[start + 5];
  9649. var referredToCount = (referredFlags >> 5) & 7;
  9650. var retainBits = [referredFlags & 31];
  9651. var position = start + 6;
  9652. if (referredFlags === 7) {
  9653. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  9654. position += 3;
  9655. var bytes = (referredToCount + 7) >> 3;
  9656. retainBits[0] = data[position++];
  9657. while (--bytes > 0) {
  9658. retainBits.push(data[position++]);
  9659. }
  9660. } else if (referredFlags === 5 || referredFlags === 6) {
  9661. error('JBIG2 error: invalid referred-to flags');
  9662. }
  9663. segmentHeader.retainBits = retainBits;
  9664. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  9665. (segmentHeader.number <= 65536 ? 2 : 4));
  9666. var referredTo = [];
  9667. var i, ii;
  9668. for (i = 0; i < referredToCount; i++) {
  9669. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  9670. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  9671. readUint32(data, position)));
  9672. referredTo.push(number);
  9673. position += referredToSegmentNumberSize;
  9674. }
  9675. segmentHeader.referredTo = referredTo;
  9676. if (!pageAssociationFieldSize) {
  9677. segmentHeader.pageAssociation = data[position++];
  9678. } else {
  9679. segmentHeader.pageAssociation = readUint32(data, position);
  9680. position += 4;
  9681. }
  9682. segmentHeader.length = readUint32(data, position);
  9683. position += 4;
  9684. if (segmentHeader.length === 0xFFFFFFFF) {
  9685. // 7.2.7 Segment data length, unknown segment length
  9686. if (segmentType === 38) { // ImmediateGenericRegion
  9687. var genericRegionInfo = readRegionSegmentInformation(data, position);
  9688. var genericRegionSegmentFlags = data[position +
  9689. RegionSegmentInformationFieldLength];
  9690. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  9691. // searching for the segment end
  9692. var searchPatternLength = 6;
  9693. var searchPattern = new Uint8Array(searchPatternLength);
  9694. if (!genericRegionMmr) {
  9695. searchPattern[0] = 0xFF;
  9696. searchPattern[1] = 0xAC;
  9697. }
  9698. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  9699. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  9700. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  9701. searchPattern[5] = genericRegionInfo.height & 0xFF;
  9702. for (i = position, ii = data.length; i < ii; i++) {
  9703. var j = 0;
  9704. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  9705. j++;
  9706. }
  9707. if (j === searchPatternLength) {
  9708. segmentHeader.length = i + searchPatternLength;
  9709. break;
  9710. }
  9711. }
  9712. if (segmentHeader.length === 0xFFFFFFFF) {
  9713. error('JBIG2 error: segment end was not found');
  9714. }
  9715. } else {
  9716. error('JBIG2 error: invalid unknown segment length');
  9717. }
  9718. }
  9719. segmentHeader.headerEnd = position;
  9720. return segmentHeader;
  9721. }
  9722. function readSegments(header, data, start, end) {
  9723. var segments = [];
  9724. var position = start;
  9725. while (position < end) {
  9726. var segmentHeader = readSegmentHeader(data, position);
  9727. position = segmentHeader.headerEnd;
  9728. var segment = {
  9729. header: segmentHeader,
  9730. data: data
  9731. };
  9732. if (!header.randomAccess) {
  9733. segment.start = position;
  9734. position += segmentHeader.length;
  9735. segment.end = position;
  9736. }
  9737. segments.push(segment);
  9738. if (segmentHeader.type === 51) {
  9739. break; // end of file is found
  9740. }
  9741. }
  9742. if (header.randomAccess) {
  9743. for (var i = 0, ii = segments.length; i < ii; i++) {
  9744. segments[i].start = position;
  9745. position += segments[i].header.length;
  9746. segments[i].end = position;
  9747. }
  9748. }
  9749. return segments;
  9750. }
  9751. // 7.4.1 Region segment information field
  9752. function readRegionSegmentInformation(data, start) {
  9753. return {
  9754. width: readUint32(data, start),
  9755. height: readUint32(data, start + 4),
  9756. x: readUint32(data, start + 8),
  9757. y: readUint32(data, start + 12),
  9758. combinationOperator: data[start + 16] & 7
  9759. };
  9760. }
  9761. var RegionSegmentInformationFieldLength = 17;
  9762. function processSegment(segment, visitor) {
  9763. var header = segment.header;
  9764. var data = segment.data, position = segment.start, end = segment.end;
  9765. var args, at, i, atLength;
  9766. switch (header.type) {
  9767. case 0: // SymbolDictionary
  9768. // 7.4.2 Symbol dictionary segment syntax
  9769. var dictionary = {};
  9770. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  9771. dictionary.huffman = !!(dictionaryFlags & 1);
  9772. dictionary.refinement = !!(dictionaryFlags & 2);
  9773. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  9774. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  9775. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  9776. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  9777. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  9778. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  9779. dictionary.template = (dictionaryFlags >> 10) & 3;
  9780. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  9781. position += 2;
  9782. if (!dictionary.huffman) {
  9783. atLength = dictionary.template === 0 ? 4 : 1;
  9784. at = [];
  9785. for (i = 0; i < atLength; i++) {
  9786. at.push({
  9787. x: readInt8(data, position),
  9788. y: readInt8(data, position + 1)
  9789. });
  9790. position += 2;
  9791. }
  9792. dictionary.at = at;
  9793. }
  9794. if (dictionary.refinement && !dictionary.refinementTemplate) {
  9795. at = [];
  9796. for (i = 0; i < 2; i++) {
  9797. at.push({
  9798. x: readInt8(data, position),
  9799. y: readInt8(data, position + 1)
  9800. });
  9801. position += 2;
  9802. }
  9803. dictionary.refinementAt = at;
  9804. }
  9805. dictionary.numberOfExportedSymbols = readUint32(data, position);
  9806. position += 4;
  9807. dictionary.numberOfNewSymbols = readUint32(data, position);
  9808. position += 4;
  9809. args = [dictionary, header.number, header.referredTo,
  9810. data, position, end];
  9811. break;
  9812. case 6: // ImmediateTextRegion
  9813. case 7: // ImmediateLosslessTextRegion
  9814. var textRegion = {};
  9815. textRegion.info = readRegionSegmentInformation(data, position);
  9816. position += RegionSegmentInformationFieldLength;
  9817. var textRegionSegmentFlags = readUint16(data, position);
  9818. position += 2;
  9819. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  9820. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  9821. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  9822. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  9823. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  9824. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  9825. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  9826. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  9827. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  9828. if (textRegion.huffman) {
  9829. var textRegionHuffmanFlags = readUint16(data, position);
  9830. position += 2;
  9831. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  9832. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  9833. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  9834. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  9835. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  9836. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  9837. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  9838. textRegion.huffmanRefinementSizeSelector =
  9839. !!(textRegionHuffmanFlags & 14);
  9840. }
  9841. if (textRegion.refinement && !textRegion.refinementTemplate) {
  9842. at = [];
  9843. for (i = 0; i < 2; i++) {
  9844. at.push({
  9845. x: readInt8(data, position),
  9846. y: readInt8(data, position + 1)
  9847. });
  9848. position += 2;
  9849. }
  9850. textRegion.refinementAt = at;
  9851. }
  9852. textRegion.numberOfSymbolInstances = readUint32(data, position);
  9853. position += 4;
  9854. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  9855. if (textRegion.huffman) {
  9856. error('JBIG2 error: huffman is not supported');
  9857. }
  9858. args = [textRegion, header.referredTo, data, position, end];
  9859. break;
  9860. case 38: // ImmediateGenericRegion
  9861. case 39: // ImmediateLosslessGenericRegion
  9862. var genericRegion = {};
  9863. genericRegion.info = readRegionSegmentInformation(data, position);
  9864. position += RegionSegmentInformationFieldLength;
  9865. var genericRegionSegmentFlags = data[position++];
  9866. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  9867. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  9868. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  9869. if (!genericRegion.mmr) {
  9870. atLength = genericRegion.template === 0 ? 4 : 1;
  9871. at = [];
  9872. for (i = 0; i < atLength; i++) {
  9873. at.push({
  9874. x: readInt8(data, position),
  9875. y: readInt8(data, position + 1)
  9876. });
  9877. position += 2;
  9878. }
  9879. genericRegion.at = at;
  9880. }
  9881. args = [genericRegion, data, position, end];
  9882. break;
  9883. case 48: // PageInformation
  9884. var pageInfo = {
  9885. width: readUint32(data, position),
  9886. height: readUint32(data, position + 4),
  9887. resolutionX: readUint32(data, position + 8),
  9888. resolutionY: readUint32(data, position + 12)
  9889. };
  9890. if (pageInfo.height === 0xFFFFFFFF) {
  9891. delete pageInfo.height;
  9892. }
  9893. var pageSegmentFlags = data[position + 16];
  9894. var pageStripingInformation = readUint16(data, position + 17);
  9895. pageInfo.lossless = !!(pageSegmentFlags & 1);
  9896. pageInfo.refinement = !!(pageSegmentFlags & 2);
  9897. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  9898. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  9899. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  9900. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  9901. args = [pageInfo];
  9902. break;
  9903. case 49: // EndOfPage
  9904. break;
  9905. case 50: // EndOfStripe
  9906. break;
  9907. case 51: // EndOfFile
  9908. break;
  9909. case 62: // 7.4.15 defines 2 extension types which
  9910. // are comments and can be ignored.
  9911. break;
  9912. default:
  9913. error('JBIG2 error: segment type ' + header.typeName + '(' +
  9914. header.type + ') is not implemented');
  9915. }
  9916. var callbackName = 'on' + header.typeName;
  9917. if (callbackName in visitor) {
  9918. visitor[callbackName].apply(visitor, args);
  9919. }
  9920. }
  9921. function processSegments(segments, visitor) {
  9922. for (var i = 0, ii = segments.length; i < ii; i++) {
  9923. processSegment(segments[i], visitor);
  9924. }
  9925. }
  9926. function parseJbig2(data, start, end) {
  9927. var position = start;
  9928. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  9929. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  9930. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  9931. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  9932. error('JBIG2 error: invalid header');
  9933. }
  9934. var header = {};
  9935. position += 8;
  9936. var flags = data[position++];
  9937. header.randomAccess = !(flags & 1);
  9938. if (!(flags & 2)) {
  9939. header.numberOfPages = readUint32(data, position);
  9940. position += 4;
  9941. }
  9942. var segments = readSegments(header, data, position, end);
  9943. error('Not implemented');
  9944. // processSegments(segments, new SimpleSegmentVisitor());
  9945. }
  9946. function parseJbig2Chunks(chunks) {
  9947. var visitor = new SimpleSegmentVisitor();
  9948. for (var i = 0, ii = chunks.length; i < ii; i++) {
  9949. var chunk = chunks[i];
  9950. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  9951. processSegments(segments, visitor);
  9952. }
  9953. return visitor.buffer;
  9954. }
  9955. function SimpleSegmentVisitor() {}
  9956. SimpleSegmentVisitor.prototype = {
  9957. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  9958. this.currentPageInfo = info;
  9959. var rowSize = (info.width + 7) >> 3;
  9960. var buffer = new Uint8Array(rowSize * info.height);
  9961. // The contents of ArrayBuffers are initialized to 0.
  9962. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  9963. if (info.defaultPixelValue) {
  9964. for (var i = 0, ii = buffer.length; i < ii; i++) {
  9965. buffer[i] = 0xFF;
  9966. }
  9967. }
  9968. this.buffer = buffer;
  9969. },
  9970. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  9971. var pageInfo = this.currentPageInfo;
  9972. var width = regionInfo.width, height = regionInfo.height;
  9973. var rowSize = (pageInfo.width + 7) >> 3;
  9974. var combinationOperator = pageInfo.combinationOperatorOverride ?
  9975. regionInfo.combinationOperator : pageInfo.combinationOperator;
  9976. var buffer = this.buffer;
  9977. var mask0 = 128 >> (regionInfo.x & 7);
  9978. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  9979. var i, j, mask, offset;
  9980. switch (combinationOperator) {
  9981. case 0: // OR
  9982. for (i = 0; i < height; i++) {
  9983. mask = mask0;
  9984. offset = offset0;
  9985. for (j = 0; j < width; j++) {
  9986. if (bitmap[i][j]) {
  9987. buffer[offset] |= mask;
  9988. }
  9989. mask >>= 1;
  9990. if (!mask) {
  9991. mask = 128;
  9992. offset++;
  9993. }
  9994. }
  9995. offset0 += rowSize;
  9996. }
  9997. break;
  9998. case 2: // XOR
  9999. for (i = 0; i < height; i++) {
  10000. mask = mask0;
  10001. offset = offset0;
  10002. for (j = 0; j < width; j++) {
  10003. if (bitmap[i][j]) {
  10004. buffer[offset] ^= mask;
  10005. }
  10006. mask >>= 1;
  10007. if (!mask) {
  10008. mask = 128;
  10009. offset++;
  10010. }
  10011. }
  10012. offset0 += rowSize;
  10013. }
  10014. break;
  10015. default:
  10016. error('JBIG2 error: operator ' + combinationOperator +
  10017. ' is not supported');
  10018. }
  10019. },
  10020. onImmediateGenericRegion:
  10021. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10022. start, end) {
  10023. var regionInfo = region.info;
  10024. var decodingContext = new DecodingContext(data, start, end);
  10025. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10026. region.template, region.prediction, null,
  10027. region.at, decodingContext);
  10028. this.drawBitmap(regionInfo, bitmap);
  10029. },
  10030. onImmediateLosslessGenericRegion:
  10031. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10032. this.onImmediateGenericRegion.apply(this, arguments);
  10033. },
  10034. onSymbolDictionary:
  10035. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10036. currentSegment,
  10037. referredSegments,
  10038. data, start, end) {
  10039. var huffmanTables;
  10040. if (dictionary.huffman) {
  10041. error('JBIG2 error: huffman is not supported');
  10042. }
  10043. // Combines exported symbols from all referred segments
  10044. var symbols = this.symbols;
  10045. if (!symbols) {
  10046. this.symbols = symbols = {};
  10047. }
  10048. var inputSymbols = [];
  10049. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10050. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10051. }
  10052. var decodingContext = new DecodingContext(data, start, end);
  10053. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10054. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10055. dictionary.numberOfExportedSymbols, huffmanTables,
  10056. dictionary.template, dictionary.at,
  10057. dictionary.refinementTemplate, dictionary.refinementAt,
  10058. decodingContext);
  10059. },
  10060. onImmediateTextRegion:
  10061. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10062. referredSegments,
  10063. data, start, end) {
  10064. var regionInfo = region.info;
  10065. var huffmanTables;
  10066. // Combines exported symbols from all referred segments
  10067. var symbols = this.symbols;
  10068. var inputSymbols = [];
  10069. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10070. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10071. }
  10072. var symbolCodeLength = log2(inputSymbols.length);
  10073. var decodingContext = new DecodingContext(data, start, end);
  10074. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10075. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10076. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10077. symbolCodeLength, region.transposed, region.dsOffset,
  10078. region.referenceCorner, region.combinationOperator, huffmanTables,
  10079. region.refinementTemplate, region.refinementAt, decodingContext);
  10080. this.drawBitmap(regionInfo, bitmap);
  10081. },
  10082. onImmediateLosslessTextRegion:
  10083. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10084. this.onImmediateTextRegion.apply(this, arguments);
  10085. }
  10086. };
  10087. function Jbig2Image() {}
  10088. Jbig2Image.prototype = {
  10089. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10090. return parseJbig2Chunks(chunks);
  10091. }
  10092. };
  10093. return Jbig2Image;
  10094. })();
  10095. exports.Jbig2Image = Jbig2Image;
  10096. }));
  10097. (function (root, factory) {
  10098. {
  10099. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  10100. root.pdfjsCoreArithmeticDecoder);
  10101. }
  10102. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10103. var info = sharedUtil.info;
  10104. var log2 = sharedUtil.log2;
  10105. var readUint16 = sharedUtil.readUint16;
  10106. var readUint32 = sharedUtil.readUint32;
  10107. var warn = sharedUtil.warn;
  10108. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10109. var JpxImage = (function JpxImageClosure() {
  10110. // Table E.1
  10111. var SubbandsGainLog2 = {
  10112. 'LL': 0,
  10113. 'LH': 1,
  10114. 'HL': 1,
  10115. 'HH': 2
  10116. };
  10117. function JpxImage() {
  10118. this.failOnCorruptedImage = false;
  10119. }
  10120. JpxImage.prototype = {
  10121. parse: function JpxImage_parse(data) {
  10122. var head = readUint16(data, 0);
  10123. // No box header, immediate start of codestream (SOC)
  10124. if (head === 0xFF4F) {
  10125. this.parseCodestream(data, 0, data.length);
  10126. return;
  10127. }
  10128. var position = 0, length = data.length;
  10129. while (position < length) {
  10130. var headerSize = 8;
  10131. var lbox = readUint32(data, position);
  10132. var tbox = readUint32(data, position + 4);
  10133. position += headerSize;
  10134. if (lbox === 1) {
  10135. // XLBox: read UInt64 according to spec.
  10136. // JavaScript's int precision of 53 bit should be sufficient here.
  10137. lbox = readUint32(data, position) * 4294967296 +
  10138. readUint32(data, position + 4);
  10139. position += 8;
  10140. headerSize += 8;
  10141. }
  10142. if (lbox === 0) {
  10143. lbox = length - position + headerSize;
  10144. }
  10145. if (lbox < headerSize) {
  10146. throw new Error('JPX Error: Invalid box field size');
  10147. }
  10148. var dataLength = lbox - headerSize;
  10149. var jumpDataLength = true;
  10150. switch (tbox) {
  10151. case 0x6A703268: // 'jp2h'
  10152. jumpDataLength = false; // parsing child boxes
  10153. break;
  10154. case 0x636F6C72: // 'colr'
  10155. // Colorspaces are not used, the CS from the PDF is used.
  10156. var method = data[position];
  10157. if (method === 1) {
  10158. // enumerated colorspace
  10159. var colorspace = readUint32(data, position + 3);
  10160. switch (colorspace) {
  10161. case 16: // this indicates a sRGB colorspace
  10162. case 17: // this indicates a grayscale colorspace
  10163. case 18: // this indicates a YUV colorspace
  10164. break;
  10165. default:
  10166. warn('Unknown colorspace ' + colorspace);
  10167. break;
  10168. }
  10169. } else if (method === 2) {
  10170. info('ICC profile not supported');
  10171. }
  10172. break;
  10173. case 0x6A703263: // 'jp2c'
  10174. this.parseCodestream(data, position, position + dataLength);
  10175. break;
  10176. case 0x6A502020: // 'jP\024\024'
  10177. if (0x0d0a870a !== readUint32(data, position)) {
  10178. warn('Invalid JP2 signature');
  10179. }
  10180. break;
  10181. // The following header types are valid but currently not used:
  10182. case 0x6A501A1A: // 'jP\032\032'
  10183. case 0x66747970: // 'ftyp'
  10184. case 0x72726571: // 'rreq'
  10185. case 0x72657320: // 'res '
  10186. case 0x69686472: // 'ihdr'
  10187. break;
  10188. default:
  10189. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  10190. (tbox >> 16) & 0xFF,
  10191. (tbox >> 8) & 0xFF,
  10192. tbox & 0xFF);
  10193. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  10194. break;
  10195. }
  10196. if (jumpDataLength) {
  10197. position += dataLength;
  10198. }
  10199. }
  10200. },
  10201. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  10202. var newByte = stream.getByte();
  10203. while (newByte >= 0) {
  10204. var oldByte = newByte;
  10205. newByte = stream.getByte();
  10206. var code = (oldByte << 8) | newByte;
  10207. // Image and tile size (SIZ)
  10208. if (code === 0xFF51) {
  10209. stream.skip(4);
  10210. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  10211. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  10212. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  10213. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  10214. stream.skip(16);
  10215. var Csiz = stream.getUint16(); // Byte 36
  10216. this.width = Xsiz - XOsiz;
  10217. this.height = Ysiz - YOsiz;
  10218. this.componentsCount = Csiz;
  10219. // Results are always returned as Uint8Arrays
  10220. this.bitsPerComponent = 8;
  10221. return;
  10222. }
  10223. }
  10224. throw new Error('JPX Error: No size marker found in JPX stream');
  10225. },
  10226. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  10227. var context = {};
  10228. try {
  10229. var doNotRecover = false;
  10230. var position = start;
  10231. while (position + 1 < end) {
  10232. var code = readUint16(data, position);
  10233. position += 2;
  10234. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  10235. switch (code) {
  10236. case 0xFF4F: // Start of codestream (SOC)
  10237. context.mainHeader = true;
  10238. break;
  10239. case 0xFFD9: // End of codestream (EOC)
  10240. break;
  10241. case 0xFF51: // Image and tile size (SIZ)
  10242. length = readUint16(data, position);
  10243. var siz = {};
  10244. siz.Xsiz = readUint32(data, position + 4);
  10245. siz.Ysiz = readUint32(data, position + 8);
  10246. siz.XOsiz = readUint32(data, position + 12);
  10247. siz.YOsiz = readUint32(data, position + 16);
  10248. siz.XTsiz = readUint32(data, position + 20);
  10249. siz.YTsiz = readUint32(data, position + 24);
  10250. siz.XTOsiz = readUint32(data, position + 28);
  10251. siz.YTOsiz = readUint32(data, position + 32);
  10252. var componentsCount = readUint16(data, position + 36);
  10253. siz.Csiz = componentsCount;
  10254. var components = [];
  10255. j = position + 38;
  10256. for (var i = 0; i < componentsCount; i++) {
  10257. var component = {
  10258. precision: (data[j] & 0x7F) + 1,
  10259. isSigned: !!(data[j] & 0x80),
  10260. XRsiz: data[j + 1],
  10261. YRsiz: data[j + 1]
  10262. };
  10263. calculateComponentDimensions(component, siz);
  10264. components.push(component);
  10265. }
  10266. context.SIZ = siz;
  10267. context.components = components;
  10268. calculateTileGrids(context, components);
  10269. context.QCC = [];
  10270. context.COC = [];
  10271. break;
  10272. case 0xFF5C: // Quantization default (QCD)
  10273. length = readUint16(data, position);
  10274. var qcd = {};
  10275. j = position + 2;
  10276. sqcd = data[j++];
  10277. switch (sqcd & 0x1F) {
  10278. case 0:
  10279. spqcdSize = 8;
  10280. scalarExpounded = true;
  10281. break;
  10282. case 1:
  10283. spqcdSize = 16;
  10284. scalarExpounded = false;
  10285. break;
  10286. case 2:
  10287. spqcdSize = 16;
  10288. scalarExpounded = true;
  10289. break;
  10290. default:
  10291. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10292. }
  10293. qcd.noQuantization = (spqcdSize === 8);
  10294. qcd.scalarExpounded = scalarExpounded;
  10295. qcd.guardBits = sqcd >> 5;
  10296. spqcds = [];
  10297. while (j < length + position) {
  10298. var spqcd = {};
  10299. if (spqcdSize === 8) {
  10300. spqcd.epsilon = data[j++] >> 3;
  10301. spqcd.mu = 0;
  10302. } else {
  10303. spqcd.epsilon = data[j] >> 3;
  10304. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10305. j += 2;
  10306. }
  10307. spqcds.push(spqcd);
  10308. }
  10309. qcd.SPqcds = spqcds;
  10310. if (context.mainHeader) {
  10311. context.QCD = qcd;
  10312. } else {
  10313. context.currentTile.QCD = qcd;
  10314. context.currentTile.QCC = [];
  10315. }
  10316. break;
  10317. case 0xFF5D: // Quantization component (QCC)
  10318. length = readUint16(data, position);
  10319. var qcc = {};
  10320. j = position + 2;
  10321. var cqcc;
  10322. if (context.SIZ.Csiz < 257) {
  10323. cqcc = data[j++];
  10324. } else {
  10325. cqcc = readUint16(data, j);
  10326. j += 2;
  10327. }
  10328. sqcd = data[j++];
  10329. switch (sqcd & 0x1F) {
  10330. case 0:
  10331. spqcdSize = 8;
  10332. scalarExpounded = true;
  10333. break;
  10334. case 1:
  10335. spqcdSize = 16;
  10336. scalarExpounded = false;
  10337. break;
  10338. case 2:
  10339. spqcdSize = 16;
  10340. scalarExpounded = true;
  10341. break;
  10342. default:
  10343. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10344. }
  10345. qcc.noQuantization = (spqcdSize === 8);
  10346. qcc.scalarExpounded = scalarExpounded;
  10347. qcc.guardBits = sqcd >> 5;
  10348. spqcds = [];
  10349. while (j < (length + position)) {
  10350. spqcd = {};
  10351. if (spqcdSize === 8) {
  10352. spqcd.epsilon = data[j++] >> 3;
  10353. spqcd.mu = 0;
  10354. } else {
  10355. spqcd.epsilon = data[j] >> 3;
  10356. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10357. j += 2;
  10358. }
  10359. spqcds.push(spqcd);
  10360. }
  10361. qcc.SPqcds = spqcds;
  10362. if (context.mainHeader) {
  10363. context.QCC[cqcc] = qcc;
  10364. } else {
  10365. context.currentTile.QCC[cqcc] = qcc;
  10366. }
  10367. break;
  10368. case 0xFF52: // Coding style default (COD)
  10369. length = readUint16(data, position);
  10370. var cod = {};
  10371. j = position + 2;
  10372. var scod = data[j++];
  10373. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  10374. cod.sopMarkerUsed = !!(scod & 2);
  10375. cod.ephMarkerUsed = !!(scod & 4);
  10376. cod.progressionOrder = data[j++];
  10377. cod.layersCount = readUint16(data, j);
  10378. j += 2;
  10379. cod.multipleComponentTransform = data[j++];
  10380. cod.decompositionLevelsCount = data[j++];
  10381. cod.xcb = (data[j++] & 0xF) + 2;
  10382. cod.ycb = (data[j++] & 0xF) + 2;
  10383. var blockStyle = data[j++];
  10384. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  10385. cod.resetContextProbabilities = !!(blockStyle & 2);
  10386. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  10387. cod.verticalyStripe = !!(blockStyle & 8);
  10388. cod.predictableTermination = !!(blockStyle & 16);
  10389. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  10390. cod.reversibleTransformation = data[j++];
  10391. if (cod.entropyCoderWithCustomPrecincts) {
  10392. var precinctsSizes = [];
  10393. while (j < length + position) {
  10394. var precinctsSize = data[j++];
  10395. precinctsSizes.push({
  10396. PPx: precinctsSize & 0xF,
  10397. PPy: precinctsSize >> 4
  10398. });
  10399. }
  10400. cod.precinctsSizes = precinctsSizes;
  10401. }
  10402. var unsupported = [];
  10403. if (cod.selectiveArithmeticCodingBypass) {
  10404. unsupported.push('selectiveArithmeticCodingBypass');
  10405. }
  10406. if (cod.resetContextProbabilities) {
  10407. unsupported.push('resetContextProbabilities');
  10408. }
  10409. if (cod.terminationOnEachCodingPass) {
  10410. unsupported.push('terminationOnEachCodingPass');
  10411. }
  10412. if (cod.verticalyStripe) {
  10413. unsupported.push('verticalyStripe');
  10414. }
  10415. if (cod.predictableTermination) {
  10416. unsupported.push('predictableTermination');
  10417. }
  10418. if (unsupported.length > 0) {
  10419. doNotRecover = true;
  10420. throw new Error('JPX Error: Unsupported COD options (' +
  10421. unsupported.join(', ') + ')');
  10422. }
  10423. if (context.mainHeader) {
  10424. context.COD = cod;
  10425. } else {
  10426. context.currentTile.COD = cod;
  10427. context.currentTile.COC = [];
  10428. }
  10429. break;
  10430. case 0xFF90: // Start of tile-part (SOT)
  10431. length = readUint16(data, position);
  10432. tile = {};
  10433. tile.index = readUint16(data, position + 2);
  10434. tile.length = readUint32(data, position + 4);
  10435. tile.dataEnd = tile.length + position - 2;
  10436. tile.partIndex = data[position + 8];
  10437. tile.partsCount = data[position + 9];
  10438. context.mainHeader = false;
  10439. if (tile.partIndex === 0) {
  10440. // reset component specific settings
  10441. tile.COD = context.COD;
  10442. tile.COC = context.COC.slice(0); // clone of the global COC
  10443. tile.QCD = context.QCD;
  10444. tile.QCC = context.QCC.slice(0); // clone of the global COC
  10445. }
  10446. context.currentTile = tile;
  10447. break;
  10448. case 0xFF93: // Start of data (SOD)
  10449. tile = context.currentTile;
  10450. if (tile.partIndex === 0) {
  10451. initializeTile(context, tile.index);
  10452. buildPackets(context);
  10453. }
  10454. // moving to the end of the data
  10455. length = tile.dataEnd - position;
  10456. parseTilePackets(context, data, position, length);
  10457. break;
  10458. case 0xFF55: // Tile-part lengths, main header (TLM)
  10459. case 0xFF57: // Packet length, main header (PLM)
  10460. case 0xFF58: // Packet length, tile-part header (PLT)
  10461. case 0xFF64: // Comment (COM)
  10462. length = readUint16(data, position);
  10463. // skipping content
  10464. break;
  10465. case 0xFF53: // Coding style component (COC)
  10466. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  10467. 'not implemented');
  10468. default:
  10469. throw new Error('JPX Error: Unknown codestream code: ' +
  10470. code.toString(16));
  10471. }
  10472. position += length;
  10473. }
  10474. } catch (e) {
  10475. if (doNotRecover || this.failOnCorruptedImage) {
  10476. throw e;
  10477. } else {
  10478. warn('Trying to recover from ' + e.message);
  10479. }
  10480. }
  10481. this.tiles = transformComponents(context);
  10482. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  10483. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  10484. this.componentsCount = context.SIZ.Csiz;
  10485. }
  10486. };
  10487. function calculateComponentDimensions(component, siz) {
  10488. // Section B.2 Component mapping
  10489. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  10490. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  10491. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  10492. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  10493. component.width = component.x1 - component.x0;
  10494. component.height = component.y1 - component.y0;
  10495. }
  10496. function calculateTileGrids(context, components) {
  10497. var siz = context.SIZ;
  10498. // Section B.3 Division into tile and tile-components
  10499. var tile, tiles = [];
  10500. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  10501. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  10502. for (var q = 0; q < numYtiles; q++) {
  10503. for (var p = 0; p < numXtiles; p++) {
  10504. tile = {};
  10505. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  10506. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  10507. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  10508. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  10509. tile.width = tile.tx1 - tile.tx0;
  10510. tile.height = tile.ty1 - tile.ty0;
  10511. tile.components = [];
  10512. tiles.push(tile);
  10513. }
  10514. }
  10515. context.tiles = tiles;
  10516. var componentsCount = siz.Csiz;
  10517. for (var i = 0, ii = componentsCount; i < ii; i++) {
  10518. var component = components[i];
  10519. for (var j = 0, jj = tiles.length; j < jj; j++) {
  10520. var tileComponent = {};
  10521. tile = tiles[j];
  10522. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  10523. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  10524. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  10525. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  10526. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  10527. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  10528. tile.components[i] = tileComponent;
  10529. }
  10530. }
  10531. }
  10532. function getBlocksDimensions(context, component, r) {
  10533. var codOrCoc = component.codingStyleParameters;
  10534. var result = {};
  10535. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  10536. result.PPx = 15;
  10537. result.PPy = 15;
  10538. } else {
  10539. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  10540. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  10541. }
  10542. // calculate codeblock size as described in section B.7
  10543. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  10544. Math.min(codOrCoc.xcb, result.PPx));
  10545. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  10546. Math.min(codOrCoc.ycb, result.PPy));
  10547. return result;
  10548. }
  10549. function buildPrecincts(context, resolution, dimensions) {
  10550. // Section B.6 Division resolution to precincts
  10551. var precinctWidth = 1 << dimensions.PPx;
  10552. var precinctHeight = 1 << dimensions.PPy;
  10553. // Jasper introduces codeblock groups for mapping each subband codeblocks
  10554. // to precincts. Precinct partition divides a resolution according to width
  10555. // and height parameters. The subband that belongs to the resolution level
  10556. // has a different size than the level, unless it is the zero resolution.
  10557. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  10558. // The precinct partitioning for a particular subband is derived from a
  10559. // partitioning of its parent LL band (i.e., the LL band at the next higher
  10560. // resolution level)... The LL band associated with each resolution level is
  10561. // divided into precincts... Each of the resulting precinct regions is then
  10562. // mapped into its child subbands (if any) at the next lower resolution
  10563. // level. This is accomplished by using the coordinate transformation
  10564. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  10565. // coordinates of a point in the LL band and child subband, respectively.
  10566. var isZeroRes = resolution.resLevel === 0;
  10567. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  10568. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  10569. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  10570. Math.ceil(resolution.trx1 / precinctWidth) -
  10571. Math.floor(resolution.trx0 / precinctWidth) : 0);
  10572. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  10573. Math.ceil(resolution.try1 / precinctHeight) -
  10574. Math.floor(resolution.try0 / precinctHeight) : 0);
  10575. var numprecincts = numprecinctswide * numprecinctshigh;
  10576. resolution.precinctParameters = {
  10577. precinctWidth: precinctWidth,
  10578. precinctHeight: precinctHeight,
  10579. numprecinctswide: numprecinctswide,
  10580. numprecinctshigh: numprecinctshigh,
  10581. numprecincts: numprecincts,
  10582. precinctWidthInSubband: precinctWidthInSubband,
  10583. precinctHeightInSubband: precinctHeightInSubband
  10584. };
  10585. }
  10586. function buildCodeblocks(context, subband, dimensions) {
  10587. // Section B.7 Division sub-band into code-blocks
  10588. var xcb_ = dimensions.xcb_;
  10589. var ycb_ = dimensions.ycb_;
  10590. var codeblockWidth = 1 << xcb_;
  10591. var codeblockHeight = 1 << ycb_;
  10592. var cbx0 = subband.tbx0 >> xcb_;
  10593. var cby0 = subband.tby0 >> ycb_;
  10594. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  10595. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  10596. var precinctParameters = subband.resolution.precinctParameters;
  10597. var codeblocks = [];
  10598. var precincts = [];
  10599. var i, j, codeblock, precinctNumber;
  10600. for (j = cby0; j < cby1; j++) {
  10601. for (i = cbx0; i < cbx1; i++) {
  10602. codeblock = {
  10603. cbx: i,
  10604. cby: j,
  10605. tbx0: codeblockWidth * i,
  10606. tby0: codeblockHeight * j,
  10607. tbx1: codeblockWidth * (i + 1),
  10608. tby1: codeblockHeight * (j + 1)
  10609. };
  10610. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  10611. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  10612. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  10613. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  10614. // Calculate precinct number for this codeblock, codeblock position
  10615. // should be relative to its subband, use actual dimension and position
  10616. // See comment about codeblock group width and height
  10617. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  10618. precinctParameters.precinctWidthInSubband);
  10619. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  10620. precinctParameters.precinctHeightInSubband);
  10621. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  10622. codeblock.precinctNumber = precinctNumber;
  10623. codeblock.subbandType = subband.type;
  10624. codeblock.Lblock = 3;
  10625. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  10626. codeblock.tby1_ <= codeblock.tby0_) {
  10627. continue;
  10628. }
  10629. codeblocks.push(codeblock);
  10630. // building precinct for the sub-band
  10631. var precinct = precincts[precinctNumber];
  10632. if (precinct !== undefined) {
  10633. if (i < precinct.cbxMin) {
  10634. precinct.cbxMin = i;
  10635. } else if (i > precinct.cbxMax) {
  10636. precinct.cbxMax = i;
  10637. }
  10638. if (j < precinct.cbyMin) {
  10639. precinct.cbxMin = j;
  10640. } else if (j > precinct.cbyMax) {
  10641. precinct.cbyMax = j;
  10642. }
  10643. } else {
  10644. precincts[precinctNumber] = precinct = {
  10645. cbxMin: i,
  10646. cbyMin: j,
  10647. cbxMax: i,
  10648. cbyMax: j
  10649. };
  10650. }
  10651. codeblock.precinct = precinct;
  10652. }
  10653. }
  10654. subband.codeblockParameters = {
  10655. codeblockWidth: xcb_,
  10656. codeblockHeight: ycb_,
  10657. numcodeblockwide: cbx1 - cbx0 + 1,
  10658. numcodeblockhigh: cby1 - cby0 + 1
  10659. };
  10660. subband.codeblocks = codeblocks;
  10661. subband.precincts = precincts;
  10662. }
  10663. function createPacket(resolution, precinctNumber, layerNumber) {
  10664. var precinctCodeblocks = [];
  10665. // Section B.10.8 Order of info in packet
  10666. var subbands = resolution.subbands;
  10667. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  10668. for (var i = 0, ii = subbands.length; i < ii; i++) {
  10669. var subband = subbands[i];
  10670. var codeblocks = subband.codeblocks;
  10671. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  10672. var codeblock = codeblocks[j];
  10673. if (codeblock.precinctNumber !== precinctNumber) {
  10674. continue;
  10675. }
  10676. precinctCodeblocks.push(codeblock);
  10677. }
  10678. }
  10679. return {
  10680. layerNumber: layerNumber,
  10681. codeblocks: precinctCodeblocks
  10682. };
  10683. }
  10684. function LayerResolutionComponentPositionIterator(context) {
  10685. var siz = context.SIZ;
  10686. var tileIndex = context.currentTile.index;
  10687. var tile = context.tiles[tileIndex];
  10688. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10689. var componentsCount = siz.Csiz;
  10690. var maxDecompositionLevelsCount = 0;
  10691. for (var q = 0; q < componentsCount; q++) {
  10692. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10693. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10694. }
  10695. var l = 0, r = 0, i = 0, k = 0;
  10696. this.nextPacket = function JpxImage_nextPacket() {
  10697. // Section B.12.1.1 Layer-resolution-component-position
  10698. for (; l < layersCount; l++) {
  10699. for (; r <= maxDecompositionLevelsCount; r++) {
  10700. for (; i < componentsCount; i++) {
  10701. var component = tile.components[i];
  10702. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10703. continue;
  10704. }
  10705. var resolution = component.resolutions[r];
  10706. var numprecincts = resolution.precinctParameters.numprecincts;
  10707. for (; k < numprecincts;) {
  10708. var packet = createPacket(resolution, k, l);
  10709. k++;
  10710. return packet;
  10711. }
  10712. k = 0;
  10713. }
  10714. i = 0;
  10715. }
  10716. r = 0;
  10717. }
  10718. throw new Error('JPX Error: Out of packets');
  10719. };
  10720. }
  10721. function ResolutionLayerComponentPositionIterator(context) {
  10722. var siz = context.SIZ;
  10723. var tileIndex = context.currentTile.index;
  10724. var tile = context.tiles[tileIndex];
  10725. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10726. var componentsCount = siz.Csiz;
  10727. var maxDecompositionLevelsCount = 0;
  10728. for (var q = 0; q < componentsCount; q++) {
  10729. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10730. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10731. }
  10732. var r = 0, l = 0, i = 0, k = 0;
  10733. this.nextPacket = function JpxImage_nextPacket() {
  10734. // Section B.12.1.2 Resolution-layer-component-position
  10735. for (; r <= maxDecompositionLevelsCount; r++) {
  10736. for (; l < layersCount; l++) {
  10737. for (; i < componentsCount; i++) {
  10738. var component = tile.components[i];
  10739. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10740. continue;
  10741. }
  10742. var resolution = component.resolutions[r];
  10743. var numprecincts = resolution.precinctParameters.numprecincts;
  10744. for (; k < numprecincts;) {
  10745. var packet = createPacket(resolution, k, l);
  10746. k++;
  10747. return packet;
  10748. }
  10749. k = 0;
  10750. }
  10751. i = 0;
  10752. }
  10753. l = 0;
  10754. }
  10755. throw new Error('JPX Error: Out of packets');
  10756. };
  10757. }
  10758. function ResolutionPositionComponentLayerIterator(context) {
  10759. var siz = context.SIZ;
  10760. var tileIndex = context.currentTile.index;
  10761. var tile = context.tiles[tileIndex];
  10762. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10763. var componentsCount = siz.Csiz;
  10764. var l, r, c, p;
  10765. var maxDecompositionLevelsCount = 0;
  10766. for (c = 0; c < componentsCount; c++) {
  10767. var component = tile.components[c];
  10768. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10769. component.codingStyleParameters.decompositionLevelsCount);
  10770. }
  10771. var maxNumPrecinctsInLevel = new Int32Array(
  10772. maxDecompositionLevelsCount + 1);
  10773. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  10774. var maxNumPrecincts = 0;
  10775. for (c = 0; c < componentsCount; ++c) {
  10776. var resolutions = tile.components[c].resolutions;
  10777. if (r < resolutions.length) {
  10778. maxNumPrecincts = Math.max(maxNumPrecincts,
  10779. resolutions[r].precinctParameters.numprecincts);
  10780. }
  10781. }
  10782. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  10783. }
  10784. l = 0;
  10785. r = 0;
  10786. c = 0;
  10787. p = 0;
  10788. this.nextPacket = function JpxImage_nextPacket() {
  10789. // Section B.12.1.3 Resolution-position-component-layer
  10790. for (; r <= maxDecompositionLevelsCount; r++) {
  10791. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  10792. for (; c < componentsCount; c++) {
  10793. var component = tile.components[c];
  10794. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10795. continue;
  10796. }
  10797. var resolution = component.resolutions[r];
  10798. var numprecincts = resolution.precinctParameters.numprecincts;
  10799. if (p >= numprecincts) {
  10800. continue;
  10801. }
  10802. for (; l < layersCount;) {
  10803. var packet = createPacket(resolution, p, l);
  10804. l++;
  10805. return packet;
  10806. }
  10807. l = 0;
  10808. }
  10809. c = 0;
  10810. }
  10811. p = 0;
  10812. }
  10813. throw new Error('JPX Error: Out of packets');
  10814. };
  10815. }
  10816. function PositionComponentResolutionLayerIterator(context) {
  10817. var siz = context.SIZ;
  10818. var tileIndex = context.currentTile.index;
  10819. var tile = context.tiles[tileIndex];
  10820. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10821. var componentsCount = siz.Csiz;
  10822. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10823. var precinctsIterationSizes = precinctsSizes;
  10824. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10825. this.nextPacket = function JpxImage_nextPacket() {
  10826. // Section B.12.1.4 Position-component-resolution-layer
  10827. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10828. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10829. for (; c < componentsCount; c++) {
  10830. var component = tile.components[c];
  10831. var decompositionLevelsCount =
  10832. component.codingStyleParameters.decompositionLevelsCount;
  10833. for (; r <= decompositionLevelsCount; r++) {
  10834. var resolution = component.resolutions[r];
  10835. var sizeInImageScale =
  10836. precinctsSizes.components[c].resolutions[r];
  10837. var k = getPrecinctIndexIfExist(
  10838. px,
  10839. py,
  10840. sizeInImageScale,
  10841. precinctsIterationSizes,
  10842. resolution);
  10843. if (k === null) {
  10844. continue;
  10845. }
  10846. for (; l < layersCount;) {
  10847. var packet = createPacket(resolution, k, l);
  10848. l++;
  10849. return packet;
  10850. }
  10851. l = 0;
  10852. }
  10853. r = 0;
  10854. }
  10855. c = 0;
  10856. }
  10857. px = 0;
  10858. }
  10859. throw new Error('JPX Error: Out of packets');
  10860. };
  10861. }
  10862. function ComponentPositionResolutionLayerIterator(context) {
  10863. var siz = context.SIZ;
  10864. var tileIndex = context.currentTile.index;
  10865. var tile = context.tiles[tileIndex];
  10866. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10867. var componentsCount = siz.Csiz;
  10868. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10869. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10870. this.nextPacket = function JpxImage_nextPacket() {
  10871. // Section B.12.1.5 Component-position-resolution-layer
  10872. for (; c < componentsCount; ++c) {
  10873. var component = tile.components[c];
  10874. var precinctsIterationSizes = precinctsSizes.components[c];
  10875. var decompositionLevelsCount =
  10876. component.codingStyleParameters.decompositionLevelsCount;
  10877. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10878. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10879. for (; r <= decompositionLevelsCount; r++) {
  10880. var resolution = component.resolutions[r];
  10881. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  10882. var k = getPrecinctIndexIfExist(
  10883. px,
  10884. py,
  10885. sizeInImageScale,
  10886. precinctsIterationSizes,
  10887. resolution);
  10888. if (k === null) {
  10889. continue;
  10890. }
  10891. for (; l < layersCount;) {
  10892. var packet = createPacket(resolution, k, l);
  10893. l++;
  10894. return packet;
  10895. }
  10896. l = 0;
  10897. }
  10898. r = 0;
  10899. }
  10900. px = 0;
  10901. }
  10902. py = 0;
  10903. }
  10904. throw new Error('JPX Error: Out of packets');
  10905. };
  10906. }
  10907. function getPrecinctIndexIfExist(
  10908. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  10909. var posX = pxIndex * precinctIterationSizes.minWidth;
  10910. var posY = pyIndex * precinctIterationSizes.minHeight;
  10911. if (posX % sizeInImageScale.width !== 0 ||
  10912. posY % sizeInImageScale.height !== 0) {
  10913. return null;
  10914. }
  10915. var startPrecinctRowIndex =
  10916. (posY / sizeInImageScale.width) *
  10917. resolution.precinctParameters.numprecinctswide;
  10918. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  10919. }
  10920. function getPrecinctSizesInImageScale(tile) {
  10921. var componentsCount = tile.components.length;
  10922. var minWidth = Number.MAX_VALUE;
  10923. var minHeight = Number.MAX_VALUE;
  10924. var maxNumWide = 0;
  10925. var maxNumHigh = 0;
  10926. var sizePerComponent = new Array(componentsCount);
  10927. for (var c = 0; c < componentsCount; c++) {
  10928. var component = tile.components[c];
  10929. var decompositionLevelsCount =
  10930. component.codingStyleParameters.decompositionLevelsCount;
  10931. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  10932. var minWidthCurrentComponent = Number.MAX_VALUE;
  10933. var minHeightCurrentComponent = Number.MAX_VALUE;
  10934. var maxNumWideCurrentComponent = 0;
  10935. var maxNumHighCurrentComponent = 0;
  10936. var scale = 1;
  10937. for (var r = decompositionLevelsCount; r >= 0; --r) {
  10938. var resolution = component.resolutions[r];
  10939. var widthCurrentResolution =
  10940. scale * resolution.precinctParameters.precinctWidth;
  10941. var heightCurrentResolution =
  10942. scale * resolution.precinctParameters.precinctHeight;
  10943. minWidthCurrentComponent = Math.min(
  10944. minWidthCurrentComponent,
  10945. widthCurrentResolution);
  10946. minHeightCurrentComponent = Math.min(
  10947. minHeightCurrentComponent,
  10948. heightCurrentResolution);
  10949. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  10950. resolution.precinctParameters.numprecinctswide);
  10951. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  10952. resolution.precinctParameters.numprecinctshigh);
  10953. sizePerResolution[r] = {
  10954. width: widthCurrentResolution,
  10955. height: heightCurrentResolution
  10956. };
  10957. scale <<= 1;
  10958. }
  10959. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  10960. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  10961. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  10962. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  10963. sizePerComponent[c] = {
  10964. resolutions: sizePerResolution,
  10965. minWidth: minWidthCurrentComponent,
  10966. minHeight: minHeightCurrentComponent,
  10967. maxNumWide: maxNumWideCurrentComponent,
  10968. maxNumHigh: maxNumHighCurrentComponent
  10969. };
  10970. }
  10971. return {
  10972. components: sizePerComponent,
  10973. minWidth: minWidth,
  10974. minHeight: minHeight,
  10975. maxNumWide: maxNumWide,
  10976. maxNumHigh: maxNumHigh
  10977. };
  10978. }
  10979. function buildPackets(context) {
  10980. var siz = context.SIZ;
  10981. var tileIndex = context.currentTile.index;
  10982. var tile = context.tiles[tileIndex];
  10983. var componentsCount = siz.Csiz;
  10984. // Creating resolutions and sub-bands for each component
  10985. for (var c = 0; c < componentsCount; c++) {
  10986. var component = tile.components[c];
  10987. var decompositionLevelsCount =
  10988. component.codingStyleParameters.decompositionLevelsCount;
  10989. // Section B.5 Resolution levels and sub-bands
  10990. var resolutions = [];
  10991. var subbands = [];
  10992. for (var r = 0; r <= decompositionLevelsCount; r++) {
  10993. var blocksDimensions = getBlocksDimensions(context, component, r);
  10994. var resolution = {};
  10995. var scale = 1 << (decompositionLevelsCount - r);
  10996. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  10997. resolution.try0 = Math.ceil(component.tcy0 / scale);
  10998. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  10999. resolution.try1 = Math.ceil(component.tcy1 / scale);
  11000. resolution.resLevel = r;
  11001. buildPrecincts(context, resolution, blocksDimensions);
  11002. resolutions.push(resolution);
  11003. var subband;
  11004. if (r === 0) {
  11005. // one sub-band (LL) with last decomposition
  11006. subband = {};
  11007. subband.type = 'LL';
  11008. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  11009. subband.tby0 = Math.ceil(component.tcy0 / scale);
  11010. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  11011. subband.tby1 = Math.ceil(component.tcy1 / scale);
  11012. subband.resolution = resolution;
  11013. buildCodeblocks(context, subband, blocksDimensions);
  11014. subbands.push(subband);
  11015. resolution.subbands = [subband];
  11016. } else {
  11017. var bscale = 1 << (decompositionLevelsCount - r + 1);
  11018. var resolutionSubbands = [];
  11019. // three sub-bands (HL, LH and HH) with rest of decompositions
  11020. subband = {};
  11021. subband.type = 'HL';
  11022. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11023. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  11024. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11025. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  11026. subband.resolution = resolution;
  11027. buildCodeblocks(context, subband, blocksDimensions);
  11028. subbands.push(subband);
  11029. resolutionSubbands.push(subband);
  11030. subband = {};
  11031. subband.type = 'LH';
  11032. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  11033. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11034. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  11035. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11036. subband.resolution = resolution;
  11037. buildCodeblocks(context, subband, blocksDimensions);
  11038. subbands.push(subband);
  11039. resolutionSubbands.push(subband);
  11040. subband = {};
  11041. subband.type = 'HH';
  11042. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11043. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11044. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11045. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11046. subband.resolution = resolution;
  11047. buildCodeblocks(context, subband, blocksDimensions);
  11048. subbands.push(subband);
  11049. resolutionSubbands.push(subband);
  11050. resolution.subbands = resolutionSubbands;
  11051. }
  11052. }
  11053. component.resolutions = resolutions;
  11054. component.subbands = subbands;
  11055. }
  11056. // Generate the packets sequence
  11057. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  11058. switch (progressionOrder) {
  11059. case 0:
  11060. tile.packetsIterator =
  11061. new LayerResolutionComponentPositionIterator(context);
  11062. break;
  11063. case 1:
  11064. tile.packetsIterator =
  11065. new ResolutionLayerComponentPositionIterator(context);
  11066. break;
  11067. case 2:
  11068. tile.packetsIterator =
  11069. new ResolutionPositionComponentLayerIterator(context);
  11070. break;
  11071. case 3:
  11072. tile.packetsIterator =
  11073. new PositionComponentResolutionLayerIterator(context);
  11074. break;
  11075. case 4:
  11076. tile.packetsIterator =
  11077. new ComponentPositionResolutionLayerIterator(context);
  11078. break;
  11079. default:
  11080. throw new Error('JPX Error: Unsupported progression order ' +
  11081. progressionOrder);
  11082. }
  11083. }
  11084. function parseTilePackets(context, data, offset, dataLength) {
  11085. var position = 0;
  11086. var buffer, bufferSize = 0, skipNextBit = false;
  11087. function readBits(count) {
  11088. while (bufferSize < count) {
  11089. var b = data[offset + position];
  11090. position++;
  11091. if (skipNextBit) {
  11092. buffer = (buffer << 7) | b;
  11093. bufferSize += 7;
  11094. skipNextBit = false;
  11095. } else {
  11096. buffer = (buffer << 8) | b;
  11097. bufferSize += 8;
  11098. }
  11099. if (b === 0xFF) {
  11100. skipNextBit = true;
  11101. }
  11102. }
  11103. bufferSize -= count;
  11104. return (buffer >>> bufferSize) & ((1 << count) - 1);
  11105. }
  11106. function skipMarkerIfEqual(value) {
  11107. if (data[offset + position - 1] === 0xFF &&
  11108. data[offset + position] === value) {
  11109. skipBytes(1);
  11110. return true;
  11111. } else if (data[offset + position] === 0xFF &&
  11112. data[offset + position + 1] === value) {
  11113. skipBytes(2);
  11114. return true;
  11115. }
  11116. return false;
  11117. }
  11118. function skipBytes(count) {
  11119. position += count;
  11120. }
  11121. function alignToByte() {
  11122. bufferSize = 0;
  11123. if (skipNextBit) {
  11124. position++;
  11125. skipNextBit = false;
  11126. }
  11127. }
  11128. function readCodingpasses() {
  11129. if (readBits(1) === 0) {
  11130. return 1;
  11131. }
  11132. if (readBits(1) === 0) {
  11133. return 2;
  11134. }
  11135. var value = readBits(2);
  11136. if (value < 3) {
  11137. return value + 3;
  11138. }
  11139. value = readBits(5);
  11140. if (value < 31) {
  11141. return value + 6;
  11142. }
  11143. value = readBits(7);
  11144. return value + 37;
  11145. }
  11146. var tileIndex = context.currentTile.index;
  11147. var tile = context.tiles[tileIndex];
  11148. var sopMarkerUsed = context.COD.sopMarkerUsed;
  11149. var ephMarkerUsed = context.COD.ephMarkerUsed;
  11150. var packetsIterator = tile.packetsIterator;
  11151. while (position < dataLength) {
  11152. alignToByte();
  11153. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  11154. // Skip also marker segment length and packet sequence ID
  11155. skipBytes(4);
  11156. }
  11157. var packet = packetsIterator.nextPacket();
  11158. if (!readBits(1)) {
  11159. continue;
  11160. }
  11161. var layerNumber = packet.layerNumber;
  11162. var queue = [], codeblock;
  11163. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  11164. codeblock = packet.codeblocks[i];
  11165. var precinct = codeblock.precinct;
  11166. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  11167. var codeblockRow = codeblock.cby - precinct.cbyMin;
  11168. var codeblockIncluded = false;
  11169. var firstTimeInclusion = false;
  11170. var valueReady;
  11171. if (codeblock['included'] !== undefined) {
  11172. codeblockIncluded = !!readBits(1);
  11173. } else {
  11174. // reading inclusion tree
  11175. precinct = codeblock.precinct;
  11176. var inclusionTree, zeroBitPlanesTree;
  11177. if (precinct['inclusionTree'] !== undefined) {
  11178. inclusionTree = precinct.inclusionTree;
  11179. } else {
  11180. // building inclusion and zero bit-planes trees
  11181. var width = precinct.cbxMax - precinct.cbxMin + 1;
  11182. var height = precinct.cbyMax - precinct.cbyMin + 1;
  11183. inclusionTree = new InclusionTree(width, height, layerNumber);
  11184. zeroBitPlanesTree = new TagTree(width, height);
  11185. precinct.inclusionTree = inclusionTree;
  11186. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  11187. }
  11188. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  11189. while (true) {
  11190. if (readBits(1)) {
  11191. valueReady = !inclusionTree.nextLevel();
  11192. if (valueReady) {
  11193. codeblock.included = true;
  11194. codeblockIncluded = firstTimeInclusion = true;
  11195. break;
  11196. }
  11197. } else {
  11198. inclusionTree.incrementValue(layerNumber);
  11199. break;
  11200. }
  11201. }
  11202. }
  11203. }
  11204. if (!codeblockIncluded) {
  11205. continue;
  11206. }
  11207. if (firstTimeInclusion) {
  11208. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  11209. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  11210. while (true) {
  11211. if (readBits(1)) {
  11212. valueReady = !zeroBitPlanesTree.nextLevel();
  11213. if (valueReady) {
  11214. break;
  11215. }
  11216. } else {
  11217. zeroBitPlanesTree.incrementValue();
  11218. }
  11219. }
  11220. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  11221. }
  11222. var codingpasses = readCodingpasses();
  11223. while (readBits(1)) {
  11224. codeblock.Lblock++;
  11225. }
  11226. var codingpassesLog2 = log2(codingpasses);
  11227. // rounding down log2
  11228. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  11229. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  11230. var codedDataLength = readBits(bits);
  11231. queue.push({
  11232. codeblock: codeblock,
  11233. codingpasses: codingpasses,
  11234. dataLength: codedDataLength
  11235. });
  11236. }
  11237. alignToByte();
  11238. if (ephMarkerUsed) {
  11239. skipMarkerIfEqual(0x92);
  11240. }
  11241. while (queue.length > 0) {
  11242. var packetItem = queue.shift();
  11243. codeblock = packetItem.codeblock;
  11244. if (codeblock['data'] === undefined) {
  11245. codeblock.data = [];
  11246. }
  11247. codeblock.data.push({
  11248. data: data,
  11249. start: offset + position,
  11250. end: offset + position + packetItem.dataLength,
  11251. codingpasses: packetItem.codingpasses
  11252. });
  11253. position += packetItem.dataLength;
  11254. }
  11255. }
  11256. return position;
  11257. }
  11258. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  11259. delta, mb, reversible, segmentationSymbolUsed) {
  11260. var x0 = subband.tbx0;
  11261. var y0 = subband.tby0;
  11262. var width = subband.tbx1 - subband.tbx0;
  11263. var codeblocks = subband.codeblocks;
  11264. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  11265. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  11266. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  11267. var codeblock = codeblocks[i];
  11268. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  11269. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  11270. if (blockWidth === 0 || blockHeight === 0) {
  11271. continue;
  11272. }
  11273. if (codeblock['data'] === undefined) {
  11274. continue;
  11275. }
  11276. var bitModel, currentCodingpassType;
  11277. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  11278. codeblock.zeroBitPlanes, mb);
  11279. currentCodingpassType = 2; // first bit plane starts from cleanup
  11280. // collect data
  11281. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  11282. var j, jj, dataItem;
  11283. for (j = 0, jj = data.length; j < jj; j++) {
  11284. dataItem = data[j];
  11285. totalLength += dataItem.end - dataItem.start;
  11286. codingpasses += dataItem.codingpasses;
  11287. }
  11288. var encodedData = new Uint8Array(totalLength);
  11289. var position = 0;
  11290. for (j = 0, jj = data.length; j < jj; j++) {
  11291. dataItem = data[j];
  11292. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  11293. encodedData.set(chunk, position);
  11294. position += chunk.length;
  11295. }
  11296. // decoding the item
  11297. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  11298. bitModel.setDecoder(decoder);
  11299. for (j = 0; j < codingpasses; j++) {
  11300. switch (currentCodingpassType) {
  11301. case 0:
  11302. bitModel.runSignificancePropogationPass();
  11303. break;
  11304. case 1:
  11305. bitModel.runMagnitudeRefinementPass();
  11306. break;
  11307. case 2:
  11308. bitModel.runCleanupPass();
  11309. if (segmentationSymbolUsed) {
  11310. bitModel.checkSegmentationSymbol();
  11311. }
  11312. break;
  11313. }
  11314. currentCodingpassType = (currentCodingpassType + 1) % 3;
  11315. }
  11316. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  11317. var sign = bitModel.coefficentsSign;
  11318. var magnitude = bitModel.coefficentsMagnitude;
  11319. var bitsDecoded = bitModel.bitsDecoded;
  11320. var magnitudeCorrection = reversible ? 0 : 0.5;
  11321. var k, n, nb;
  11322. position = 0;
  11323. // Do the interleaving of Section F.3.3 here, so we do not need
  11324. // to copy later. LL level is not interleaved, just copied.
  11325. var interleave = (subband.type !== 'LL');
  11326. for (j = 0; j < blockHeight; j++) {
  11327. var row = (offset / width) | 0; // row in the non-interleaved subband
  11328. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  11329. for (k = 0; k < blockWidth; k++) {
  11330. n = magnitude[position];
  11331. if (n !== 0) {
  11332. n = (n + magnitudeCorrection) * delta;
  11333. if (sign[position] !== 0) {
  11334. n = -n;
  11335. }
  11336. nb = bitsDecoded[position];
  11337. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  11338. if (reversible && (nb >= mb)) {
  11339. coefficients[pos] = n;
  11340. } else {
  11341. coefficients[pos] = n * (1 << (mb - nb));
  11342. }
  11343. }
  11344. offset++;
  11345. position++;
  11346. }
  11347. offset += width - blockWidth;
  11348. }
  11349. }
  11350. }
  11351. function transformTile(context, tile, c) {
  11352. var component = tile.components[c];
  11353. var codingStyleParameters = component.codingStyleParameters;
  11354. var quantizationParameters = component.quantizationParameters;
  11355. var decompositionLevelsCount =
  11356. codingStyleParameters.decompositionLevelsCount;
  11357. var spqcds = quantizationParameters.SPqcds;
  11358. var scalarExpounded = quantizationParameters.scalarExpounded;
  11359. var guardBits = quantizationParameters.guardBits;
  11360. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  11361. var precision = context.components[c].precision;
  11362. var reversible = codingStyleParameters.reversibleTransformation;
  11363. var transform = (reversible ? new ReversibleTransform() :
  11364. new IrreversibleTransform());
  11365. var subbandCoefficients = [];
  11366. var b = 0;
  11367. for (var i = 0; i <= decompositionLevelsCount; i++) {
  11368. var resolution = component.resolutions[i];
  11369. var width = resolution.trx1 - resolution.trx0;
  11370. var height = resolution.try1 - resolution.try0;
  11371. // Allocate space for the whole sublevel.
  11372. var coefficients = new Float32Array(width * height);
  11373. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  11374. var mu, epsilon;
  11375. if (!scalarExpounded) {
  11376. // formula E-5
  11377. mu = spqcds[0].mu;
  11378. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  11379. } else {
  11380. mu = spqcds[b].mu;
  11381. epsilon = spqcds[b].epsilon;
  11382. b++;
  11383. }
  11384. var subband = resolution.subbands[j];
  11385. var gainLog2 = SubbandsGainLog2[subband.type];
  11386. // calulate quantization coefficient (Section E.1.1.1)
  11387. var delta = (reversible ? 1 :
  11388. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  11389. var mb = (guardBits + epsilon - 1);
  11390. // In the first resolution level, copyCoefficients will fill the
  11391. // whole array with coefficients. In the succeding passes,
  11392. // copyCoefficients will consecutively fill in the values that belong
  11393. // to the interleaved positions of the HL, LH, and HH coefficients.
  11394. // The LL coefficients will then be interleaved in Transform.iterate().
  11395. copyCoefficients(coefficients, width, height, subband, delta, mb,
  11396. reversible, segmentationSymbolUsed);
  11397. }
  11398. subbandCoefficients.push({
  11399. width: width,
  11400. height: height,
  11401. items: coefficients
  11402. });
  11403. }
  11404. var result = transform.calculate(subbandCoefficients,
  11405. component.tcx0, component.tcy0);
  11406. return {
  11407. left: component.tcx0,
  11408. top: component.tcy0,
  11409. width: result.width,
  11410. height: result.height,
  11411. items: result.items
  11412. };
  11413. }
  11414. function transformComponents(context) {
  11415. var siz = context.SIZ;
  11416. var components = context.components;
  11417. var componentsCount = siz.Csiz;
  11418. var resultImages = [];
  11419. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  11420. var tile = context.tiles[i];
  11421. var transformedTiles = [];
  11422. var c;
  11423. for (c = 0; c < componentsCount; c++) {
  11424. transformedTiles[c] = transformTile(context, tile, c);
  11425. }
  11426. var tile0 = transformedTiles[0];
  11427. var out = new Uint8Array(tile0.items.length * componentsCount);
  11428. var result = {
  11429. left: tile0.left,
  11430. top: tile0.top,
  11431. width: tile0.width,
  11432. height: tile0.height,
  11433. items: out
  11434. };
  11435. // Section G.2.2 Inverse multi component transform
  11436. var shift, offset, max, min, maxK;
  11437. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  11438. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  11439. var fourComponents = componentsCount === 4;
  11440. var y0items = transformedTiles[0].items;
  11441. var y1items = transformedTiles[1].items;
  11442. var y2items = transformedTiles[2].items;
  11443. var y3items = fourComponents ? transformedTiles[3].items : null;
  11444. // HACK: The multiple component transform formulas below assume that
  11445. // all components have the same precision. With this in mind, we
  11446. // compute shift and offset only once.
  11447. shift = components[0].precision - 8;
  11448. offset = (128 << shift) + 0.5;
  11449. max = 255 * (1 << shift);
  11450. maxK = max * 0.5;
  11451. min = -maxK;
  11452. var component0 = tile.components[0];
  11453. var alpha01 = componentsCount - 3;
  11454. jj = y0items.length;
  11455. if (!component0.codingStyleParameters.reversibleTransformation) {
  11456. // inverse irreversible multiple component transform
  11457. for (j = 0; j < jj; j++, pos += alpha01) {
  11458. y0 = y0items[j] + offset;
  11459. y1 = y1items[j];
  11460. y2 = y2items[j];
  11461. r = y0 + 1.402 * y2;
  11462. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  11463. b = y0 + 1.772 * y1;
  11464. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11465. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11466. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11467. }
  11468. } else {
  11469. // inverse reversible multiple component transform
  11470. for (j = 0; j < jj; j++, pos += alpha01) {
  11471. y0 = y0items[j] + offset;
  11472. y1 = y1items[j];
  11473. y2 = y2items[j];
  11474. g = y0 - ((y2 + y1) >> 2);
  11475. r = g + y2;
  11476. b = g + y1;
  11477. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11478. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11479. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11480. }
  11481. }
  11482. if (fourComponents) {
  11483. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  11484. k = y3items[j];
  11485. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  11486. }
  11487. }
  11488. } else { // no multi-component transform
  11489. for (c = 0; c < componentsCount; c++) {
  11490. var items = transformedTiles[c].items;
  11491. shift = components[c].precision - 8;
  11492. offset = (128 << shift) + 0.5;
  11493. max = (127.5 * (1 << shift));
  11494. min = -max;
  11495. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  11496. val = items[j];
  11497. out[pos] = val <= min ? 0 :
  11498. val >= max ? 255 : (val + offset) >> shift;
  11499. pos += componentsCount;
  11500. }
  11501. }
  11502. }
  11503. resultImages.push(result);
  11504. }
  11505. return resultImages;
  11506. }
  11507. function initializeTile(context, tileIndex) {
  11508. var siz = context.SIZ;
  11509. var componentsCount = siz.Csiz;
  11510. var tile = context.tiles[tileIndex];
  11511. for (var c = 0; c < componentsCount; c++) {
  11512. var component = tile.components[c];
  11513. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  11514. context.currentTile.QCC[c] : context.currentTile.QCD);
  11515. component.quantizationParameters = qcdOrQcc;
  11516. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  11517. context.currentTile.COC[c] : context.currentTile.COD);
  11518. component.codingStyleParameters = codOrCoc;
  11519. }
  11520. tile.codingStyleDefaultParameters = context.currentTile.COD;
  11521. }
  11522. // Section B.10.2 Tag trees
  11523. var TagTree = (function TagTreeClosure() {
  11524. function TagTree(width, height) {
  11525. var levelsLength = log2(Math.max(width, height)) + 1;
  11526. this.levels = [];
  11527. for (var i = 0; i < levelsLength; i++) {
  11528. var level = {
  11529. width: width,
  11530. height: height,
  11531. items: []
  11532. };
  11533. this.levels.push(level);
  11534. width = Math.ceil(width / 2);
  11535. height = Math.ceil(height / 2);
  11536. }
  11537. }
  11538. TagTree.prototype = {
  11539. reset: function TagTree_reset(i, j) {
  11540. var currentLevel = 0, value = 0, level;
  11541. while (currentLevel < this.levels.length) {
  11542. level = this.levels[currentLevel];
  11543. var index = i + j * level.width;
  11544. if (level.items[index] !== undefined) {
  11545. value = level.items[index];
  11546. break;
  11547. }
  11548. level.index = index;
  11549. i >>= 1;
  11550. j >>= 1;
  11551. currentLevel++;
  11552. }
  11553. currentLevel--;
  11554. level = this.levels[currentLevel];
  11555. level.items[level.index] = value;
  11556. this.currentLevel = currentLevel;
  11557. delete this.value;
  11558. },
  11559. incrementValue: function TagTree_incrementValue() {
  11560. var level = this.levels[this.currentLevel];
  11561. level.items[level.index]++;
  11562. },
  11563. nextLevel: function TagTree_nextLevel() {
  11564. var currentLevel = this.currentLevel;
  11565. var level = this.levels[currentLevel];
  11566. var value = level.items[level.index];
  11567. currentLevel--;
  11568. if (currentLevel < 0) {
  11569. this.value = value;
  11570. return false;
  11571. }
  11572. this.currentLevel = currentLevel;
  11573. level = this.levels[currentLevel];
  11574. level.items[level.index] = value;
  11575. return true;
  11576. }
  11577. };
  11578. return TagTree;
  11579. })();
  11580. var InclusionTree = (function InclusionTreeClosure() {
  11581. function InclusionTree(width, height, defaultValue) {
  11582. var levelsLength = log2(Math.max(width, height)) + 1;
  11583. this.levels = [];
  11584. for (var i = 0; i < levelsLength; i++) {
  11585. var items = new Uint8Array(width * height);
  11586. for (var j = 0, jj = items.length; j < jj; j++) {
  11587. items[j] = defaultValue;
  11588. }
  11589. var level = {
  11590. width: width,
  11591. height: height,
  11592. items: items
  11593. };
  11594. this.levels.push(level);
  11595. width = Math.ceil(width / 2);
  11596. height = Math.ceil(height / 2);
  11597. }
  11598. }
  11599. InclusionTree.prototype = {
  11600. reset: function InclusionTree_reset(i, j, stopValue) {
  11601. var currentLevel = 0;
  11602. while (currentLevel < this.levels.length) {
  11603. var level = this.levels[currentLevel];
  11604. var index = i + j * level.width;
  11605. level.index = index;
  11606. var value = level.items[index];
  11607. if (value === 0xFF) {
  11608. break;
  11609. }
  11610. if (value > stopValue) {
  11611. this.currentLevel = currentLevel;
  11612. // already know about this one, propagating the value to top levels
  11613. this.propagateValues();
  11614. return false;
  11615. }
  11616. i >>= 1;
  11617. j >>= 1;
  11618. currentLevel++;
  11619. }
  11620. this.currentLevel = currentLevel - 1;
  11621. return true;
  11622. },
  11623. incrementValue: function InclusionTree_incrementValue(stopValue) {
  11624. var level = this.levels[this.currentLevel];
  11625. level.items[level.index] = stopValue + 1;
  11626. this.propagateValues();
  11627. },
  11628. propagateValues: function InclusionTree_propagateValues() {
  11629. var levelIndex = this.currentLevel;
  11630. var level = this.levels[levelIndex];
  11631. var currentValue = level.items[level.index];
  11632. while (--levelIndex >= 0) {
  11633. level = this.levels[levelIndex];
  11634. level.items[level.index] = currentValue;
  11635. }
  11636. },
  11637. nextLevel: function InclusionTree_nextLevel() {
  11638. var currentLevel = this.currentLevel;
  11639. var level = this.levels[currentLevel];
  11640. var value = level.items[level.index];
  11641. level.items[level.index] = 0xFF;
  11642. currentLevel--;
  11643. if (currentLevel < 0) {
  11644. return false;
  11645. }
  11646. this.currentLevel = currentLevel;
  11647. level = this.levels[currentLevel];
  11648. level.items[level.index] = value;
  11649. return true;
  11650. }
  11651. };
  11652. return InclusionTree;
  11653. })();
  11654. // Section D. Coefficient bit modeling
  11655. var BitModel = (function BitModelClosure() {
  11656. var UNIFORM_CONTEXT = 17;
  11657. var RUNLENGTH_CONTEXT = 18;
  11658. // Table D-1
  11659. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  11660. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  11661. var LLAndLHContextsLabel = new Uint8Array([
  11662. 0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4,
  11663. 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6,
  11664. 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8
  11665. ]);
  11666. var HLContextLabel = new Uint8Array([
  11667. 0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8,
  11668. 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3,
  11669. 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8
  11670. ]);
  11671. var HHContextLabel = new Uint8Array([
  11672. 0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5,
  11673. 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8,
  11674. 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8
  11675. ]);
  11676. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  11677. this.width = width;
  11678. this.height = height;
  11679. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  11680. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  11681. var coefficientCount = width * height;
  11682. // coefficients outside the encoding region treated as insignificant
  11683. // add border state cells for significanceState
  11684. this.neighborsSignificance = new Uint8Array(coefficientCount);
  11685. this.coefficentsSign = new Uint8Array(coefficientCount);
  11686. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  11687. mb > 6 ? new Uint16Array(coefficientCount) :
  11688. new Uint8Array(coefficientCount);
  11689. this.processingFlags = new Uint8Array(coefficientCount);
  11690. var bitsDecoded = new Uint8Array(coefficientCount);
  11691. if (zeroBitPlanes !== 0) {
  11692. for (var i = 0; i < coefficientCount; i++) {
  11693. bitsDecoded[i] = zeroBitPlanes;
  11694. }
  11695. }
  11696. this.bitsDecoded = bitsDecoded;
  11697. this.reset();
  11698. }
  11699. BitModel.prototype = {
  11700. setDecoder: function BitModel_setDecoder(decoder) {
  11701. this.decoder = decoder;
  11702. },
  11703. reset: function BitModel_reset() {
  11704. // We have 17 contexts that are accessed via context labels,
  11705. // plus the uniform and runlength context.
  11706. this.contexts = new Int8Array(19);
  11707. // Contexts are packed into 1 byte:
  11708. // highest 7 bits carry the index, lowest bit carries mps
  11709. this.contexts[0] = (4 << 1) | 0;
  11710. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  11711. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  11712. },
  11713. setNeighborsSignificance:
  11714. function BitModel_setNeighborsSignificance(row, column, index) {
  11715. var neighborsSignificance = this.neighborsSignificance;
  11716. var width = this.width, height = this.height;
  11717. var left = (column > 0);
  11718. var right = (column + 1 < width);
  11719. var i;
  11720. if (row > 0) {
  11721. i = index - width;
  11722. if (left) {
  11723. neighborsSignificance[i - 1] += 0x10;
  11724. }
  11725. if (right) {
  11726. neighborsSignificance[i + 1] += 0x10;
  11727. }
  11728. neighborsSignificance[i] += 0x04;
  11729. }
  11730. if (row + 1 < height) {
  11731. i = index + width;
  11732. if (left) {
  11733. neighborsSignificance[i - 1] += 0x10;
  11734. }
  11735. if (right) {
  11736. neighborsSignificance[i + 1] += 0x10;
  11737. }
  11738. neighborsSignificance[i] += 0x04;
  11739. }
  11740. if (left) {
  11741. neighborsSignificance[index - 1] += 0x01;
  11742. }
  11743. if (right) {
  11744. neighborsSignificance[index + 1] += 0x01;
  11745. }
  11746. neighborsSignificance[index] |= 0x80;
  11747. },
  11748. runSignificancePropogationPass:
  11749. function BitModel_runSignificancePropogationPass() {
  11750. var decoder = this.decoder;
  11751. var width = this.width, height = this.height;
  11752. var coefficentsMagnitude = this.coefficentsMagnitude;
  11753. var coefficentsSign = this.coefficentsSign;
  11754. var neighborsSignificance = this.neighborsSignificance;
  11755. var processingFlags = this.processingFlags;
  11756. var contexts = this.contexts;
  11757. var labels = this.contextLabelTable;
  11758. var bitsDecoded = this.bitsDecoded;
  11759. var processedInverseMask = ~1;
  11760. var processedMask = 1;
  11761. var firstMagnitudeBitMask = 2;
  11762. for (var i0 = 0; i0 < height; i0 += 4) {
  11763. for (var j = 0; j < width; j++) {
  11764. var index = i0 * width + j;
  11765. for (var i1 = 0; i1 < 4; i1++, index += width) {
  11766. var i = i0 + i1;
  11767. if (i >= height) {
  11768. break;
  11769. }
  11770. // clear processed flag first
  11771. processingFlags[index] &= processedInverseMask;
  11772. if (coefficentsMagnitude[index] ||
  11773. !neighborsSignificance[index]) {
  11774. continue;
  11775. }
  11776. var contextLabel = labels[neighborsSignificance[index]];
  11777. var decision = decoder.readBit(contexts, contextLabel);
  11778. if (decision) {
  11779. var sign = this.decodeSignBit(i, j, index);
  11780. coefficentsSign[index] = sign;
  11781. coefficentsMagnitude[index] = 1;
  11782. this.setNeighborsSignificance(i, j, index);
  11783. processingFlags[index] |= firstMagnitudeBitMask;
  11784. }
  11785. bitsDecoded[index]++;
  11786. processingFlags[index] |= processedMask;
  11787. }
  11788. }
  11789. }
  11790. },
  11791. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  11792. var width = this.width, height = this.height;
  11793. var coefficentsMagnitude = this.coefficentsMagnitude;
  11794. var coefficentsSign = this.coefficentsSign;
  11795. var contribution, sign0, sign1, significance1;
  11796. var contextLabel, decoded;
  11797. // calculate horizontal contribution
  11798. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  11799. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  11800. sign1 = coefficentsSign[index + 1];
  11801. if (significance1) {
  11802. sign0 = coefficentsSign[index - 1];
  11803. contribution = 1 - sign1 - sign0;
  11804. } else {
  11805. contribution = 1 - sign1 - sign1;
  11806. }
  11807. } else if (significance1) {
  11808. sign0 = coefficentsSign[index - 1];
  11809. contribution = 1 - sign0 - sign0;
  11810. } else {
  11811. contribution = 0;
  11812. }
  11813. var horizontalContribution = 3 * contribution;
  11814. // calculate vertical contribution and combine with the horizontal
  11815. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  11816. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  11817. sign1 = coefficentsSign[index + width];
  11818. if (significance1) {
  11819. sign0 = coefficentsSign[index - width];
  11820. contribution = 1 - sign1 - sign0 + horizontalContribution;
  11821. } else {
  11822. contribution = 1 - sign1 - sign1 + horizontalContribution;
  11823. }
  11824. } else if (significance1) {
  11825. sign0 = coefficentsSign[index - width];
  11826. contribution = 1 - sign0 - sign0 + horizontalContribution;
  11827. } else {
  11828. contribution = horizontalContribution;
  11829. }
  11830. if (contribution >= 0) {
  11831. contextLabel = 9 + contribution;
  11832. decoded = this.decoder.readBit(this.contexts, contextLabel);
  11833. } else {
  11834. contextLabel = 9 - contribution;
  11835. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  11836. }
  11837. return decoded;
  11838. },
  11839. runMagnitudeRefinementPass:
  11840. function BitModel_runMagnitudeRefinementPass() {
  11841. var decoder = this.decoder;
  11842. var width = this.width, height = this.height;
  11843. var coefficentsMagnitude = this.coefficentsMagnitude;
  11844. var neighborsSignificance = this.neighborsSignificance;
  11845. var contexts = this.contexts;
  11846. var bitsDecoded = this.bitsDecoded;
  11847. var processingFlags = this.processingFlags;
  11848. var processedMask = 1;
  11849. var firstMagnitudeBitMask = 2;
  11850. var length = width * height;
  11851. var width4 = width * 4;
  11852. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  11853. indexNext = Math.min(length, index0 + width4);
  11854. for (var j = 0; j < width; j++) {
  11855. for (var index = index0 + j; index < indexNext; index += width) {
  11856. // significant but not those that have just become
  11857. if (!coefficentsMagnitude[index] ||
  11858. (processingFlags[index] & processedMask) !== 0) {
  11859. continue;
  11860. }
  11861. var contextLabel = 16;
  11862. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  11863. processingFlags[index] ^= firstMagnitudeBitMask;
  11864. // first refinement
  11865. var significance = neighborsSignificance[index] & 127;
  11866. contextLabel = significance === 0 ? 15 : 14;
  11867. }
  11868. var bit = decoder.readBit(contexts, contextLabel);
  11869. coefficentsMagnitude[index] =
  11870. (coefficentsMagnitude[index] << 1) | bit;
  11871. bitsDecoded[index]++;
  11872. processingFlags[index] |= processedMask;
  11873. }
  11874. }
  11875. }
  11876. },
  11877. runCleanupPass: function BitModel_runCleanupPass() {
  11878. var decoder = this.decoder;
  11879. var width = this.width, height = this.height;
  11880. var neighborsSignificance = this.neighborsSignificance;
  11881. var coefficentsMagnitude = this.coefficentsMagnitude;
  11882. var coefficentsSign = this.coefficentsSign;
  11883. var contexts = this.contexts;
  11884. var labels = this.contextLabelTable;
  11885. var bitsDecoded = this.bitsDecoded;
  11886. var processingFlags = this.processingFlags;
  11887. var processedMask = 1;
  11888. var firstMagnitudeBitMask = 2;
  11889. var oneRowDown = width;
  11890. var twoRowsDown = width * 2;
  11891. var threeRowsDown = width * 3;
  11892. var iNext;
  11893. for (var i0 = 0; i0 < height; i0 = iNext) {
  11894. iNext = Math.min(i0 + 4, height);
  11895. var indexBase = i0 * width;
  11896. var checkAllEmpty = i0 + 3 < height;
  11897. for (var j = 0; j < width; j++) {
  11898. var index0 = indexBase + j;
  11899. // using the property: labels[neighborsSignificance[index]] === 0
  11900. // when neighborsSignificance[index] === 0
  11901. var allEmpty = (checkAllEmpty &&
  11902. processingFlags[index0] === 0 &&
  11903. processingFlags[index0 + oneRowDown] === 0 &&
  11904. processingFlags[index0 + twoRowsDown] === 0 &&
  11905. processingFlags[index0 + threeRowsDown] === 0 &&
  11906. neighborsSignificance[index0] === 0 &&
  11907. neighborsSignificance[index0 + oneRowDown] === 0 &&
  11908. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  11909. neighborsSignificance[index0 + threeRowsDown] === 0);
  11910. var i1 = 0, index = index0;
  11911. var i = i0, sign;
  11912. if (allEmpty) {
  11913. var hasSignificantCoefficent =
  11914. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  11915. if (!hasSignificantCoefficent) {
  11916. bitsDecoded[index0]++;
  11917. bitsDecoded[index0 + oneRowDown]++;
  11918. bitsDecoded[index0 + twoRowsDown]++;
  11919. bitsDecoded[index0 + threeRowsDown]++;
  11920. continue; // next column
  11921. }
  11922. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  11923. decoder.readBit(contexts, UNIFORM_CONTEXT);
  11924. if (i1 !== 0) {
  11925. i = i0 + i1;
  11926. index += i1 * width;
  11927. }
  11928. sign = this.decodeSignBit(i, j, index);
  11929. coefficentsSign[index] = sign;
  11930. coefficentsMagnitude[index] = 1;
  11931. this.setNeighborsSignificance(i, j, index);
  11932. processingFlags[index] |= firstMagnitudeBitMask;
  11933. index = index0;
  11934. for (var i2 = i0; i2 <= i; i2++, index += width) {
  11935. bitsDecoded[index]++;
  11936. }
  11937. i1++;
  11938. }
  11939. for (i = i0 + i1; i < iNext; i++, index += width) {
  11940. if (coefficentsMagnitude[index] ||
  11941. (processingFlags[index] & processedMask) !== 0) {
  11942. continue;
  11943. }
  11944. var contextLabel = labels[neighborsSignificance[index]];
  11945. var decision = decoder.readBit(contexts, contextLabel);
  11946. if (decision === 1) {
  11947. sign = this.decodeSignBit(i, j, index);
  11948. coefficentsSign[index] = sign;
  11949. coefficentsMagnitude[index] = 1;
  11950. this.setNeighborsSignificance(i, j, index);
  11951. processingFlags[index] |= firstMagnitudeBitMask;
  11952. }
  11953. bitsDecoded[index]++;
  11954. }
  11955. }
  11956. }
  11957. },
  11958. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  11959. var decoder = this.decoder;
  11960. var contexts = this.contexts;
  11961. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  11962. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  11963. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  11964. decoder.readBit(contexts, UNIFORM_CONTEXT);
  11965. if (symbol !== 0xA) {
  11966. throw new Error('JPX Error: Invalid segmentation symbol');
  11967. }
  11968. }
  11969. };
  11970. return BitModel;
  11971. })();
  11972. // Section F, Discrete wavelet transformation
  11973. var Transform = (function TransformClosure() {
  11974. function Transform() {}
  11975. Transform.prototype.calculate =
  11976. function transformCalculate(subbands, u0, v0) {
  11977. var ll = subbands[0];
  11978. for (var i = 1, ii = subbands.length; i < ii; i++) {
  11979. ll = this.iterate(ll, subbands[i], u0, v0);
  11980. }
  11981. return ll;
  11982. };
  11983. Transform.prototype.extend = function extend(buffer, offset, size) {
  11984. // Section F.3.7 extending... using max extension of 4
  11985. var i1 = offset - 1, j1 = offset + 1;
  11986. var i2 = offset + size - 2, j2 = offset + size;
  11987. buffer[i1--] = buffer[j1++];
  11988. buffer[j2++] = buffer[i2--];
  11989. buffer[i1--] = buffer[j1++];
  11990. buffer[j2++] = buffer[i2--];
  11991. buffer[i1--] = buffer[j1++];
  11992. buffer[j2++] = buffer[i2--];
  11993. buffer[i1] = buffer[j1];
  11994. buffer[j2] = buffer[i2];
  11995. };
  11996. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  11997. u0, v0) {
  11998. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  11999. var width = hl_lh_hh.width;
  12000. var height = hl_lh_hh.height;
  12001. var items = hl_lh_hh.items;
  12002. var i, j, k, l, u, v;
  12003. // Interleave LL according to Section F.3.3
  12004. for (k = 0, i = 0; i < llHeight; i++) {
  12005. l = i * 2 * width;
  12006. for (j = 0; j < llWidth; j++, k++, l += 2) {
  12007. items[l] = llItems[k];
  12008. }
  12009. }
  12010. // The LL band is not needed anymore.
  12011. llItems = ll.items = null;
  12012. var bufferPadding = 4;
  12013. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  12014. // Section F.3.4 HOR_SR
  12015. if (width === 1) {
  12016. // if width = 1, when u0 even keep items as is, when odd divide by 2
  12017. if ((u0 & 1) !== 0) {
  12018. for (v = 0, k = 0; v < height; v++, k += width) {
  12019. items[k] *= 0.5;
  12020. }
  12021. }
  12022. } else {
  12023. for (v = 0, k = 0; v < height; v++, k += width) {
  12024. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  12025. this.extend(rowBuffer, bufferPadding, width);
  12026. this.filter(rowBuffer, bufferPadding, width);
  12027. items.set(
  12028. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  12029. k);
  12030. }
  12031. }
  12032. // Accesses to the items array can take long, because it may not fit into
  12033. // CPU cache and has to be fetched from main memory. Since subsequent
  12034. // accesses to the items array are not local when reading columns, we
  12035. // have a cache miss every time. To reduce cache misses, get up to
  12036. // 'numBuffers' items at a time and store them into the individual
  12037. // buffers. The colBuffers should be small enough to fit into CPU cache.
  12038. var numBuffers = 16;
  12039. var colBuffers = [];
  12040. for (i = 0; i < numBuffers; i++) {
  12041. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  12042. }
  12043. var b, currentBuffer = 0;
  12044. ll = bufferPadding + height;
  12045. // Section F.3.5 VER_SR
  12046. if (height === 1) {
  12047. // if height = 1, when v0 even keep items as is, when odd divide by 2
  12048. if ((v0 & 1) !== 0) {
  12049. for (u = 0; u < width; u++) {
  12050. items[u] *= 0.5;
  12051. }
  12052. }
  12053. } else {
  12054. for (u = 0; u < width; u++) {
  12055. // if we ran out of buffers, copy several image columns at once
  12056. if (currentBuffer === 0) {
  12057. numBuffers = Math.min(width - u, numBuffers);
  12058. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  12059. for (b = 0; b < numBuffers; b++) {
  12060. colBuffers[b][l] = items[k + b];
  12061. }
  12062. }
  12063. currentBuffer = numBuffers;
  12064. }
  12065. currentBuffer--;
  12066. var buffer = colBuffers[currentBuffer];
  12067. this.extend(buffer, bufferPadding, height);
  12068. this.filter(buffer, bufferPadding, height);
  12069. // If this is last buffer in this group of buffers, flush all buffers.
  12070. if (currentBuffer === 0) {
  12071. k = u - numBuffers + 1;
  12072. for (l = bufferPadding; l < ll; k += width, l++) {
  12073. for (b = 0; b < numBuffers; b++) {
  12074. items[k + b] = colBuffers[b][l];
  12075. }
  12076. }
  12077. }
  12078. }
  12079. }
  12080. return {
  12081. width: width,
  12082. height: height,
  12083. items: items
  12084. };
  12085. };
  12086. return Transform;
  12087. })();
  12088. // Section 3.8.2 Irreversible 9-7 filter
  12089. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  12090. function IrreversibleTransform() {
  12091. Transform.call(this);
  12092. }
  12093. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  12094. IrreversibleTransform.prototype.filter =
  12095. function irreversibleTransformFilter(x, offset, length) {
  12096. var len = length >> 1;
  12097. offset = offset | 0;
  12098. var j, n, current, next;
  12099. var alpha = -1.586134342059924;
  12100. var beta = -0.052980118572961;
  12101. var gamma = 0.882911075530934;
  12102. var delta = 0.443506852043971;
  12103. var K = 1.230174104914001;
  12104. var K_ = 1 / K;
  12105. // step 1 is combined with step 3
  12106. // step 2
  12107. j = offset - 3;
  12108. for (n = len + 4; n--; j += 2) {
  12109. x[j] *= K_;
  12110. }
  12111. // step 1 & 3
  12112. j = offset - 2;
  12113. current = delta * x[j -1];
  12114. for (n = len + 3; n--; j += 2) {
  12115. next = delta * x[j + 1];
  12116. x[j] = K * x[j] - current - next;
  12117. if (n--) {
  12118. j += 2;
  12119. current = delta * x[j + 1];
  12120. x[j] = K * x[j] - current - next;
  12121. } else {
  12122. break;
  12123. }
  12124. }
  12125. // step 4
  12126. j = offset - 1;
  12127. current = gamma * x[j - 1];
  12128. for (n = len + 2; n--; j += 2) {
  12129. next = gamma * x[j + 1];
  12130. x[j] -= current + next;
  12131. if (n--) {
  12132. j += 2;
  12133. current = gamma * x[j + 1];
  12134. x[j] -= current + next;
  12135. } else {
  12136. break;
  12137. }
  12138. }
  12139. // step 5
  12140. j = offset;
  12141. current = beta * x[j - 1];
  12142. for (n = len + 1; n--; j += 2) {
  12143. next = beta * x[j + 1];
  12144. x[j] -= current + next;
  12145. if (n--) {
  12146. j += 2;
  12147. current = beta * x[j + 1];
  12148. x[j] -= current + next;
  12149. } else {
  12150. break;
  12151. }
  12152. }
  12153. // step 6
  12154. if (len !== 0) {
  12155. j = offset + 1;
  12156. current = alpha * x[j - 1];
  12157. for (n = len; n--; j += 2) {
  12158. next = alpha * x[j + 1];
  12159. x[j] -= current + next;
  12160. if (n--) {
  12161. j += 2;
  12162. current = alpha * x[j + 1];
  12163. x[j] -= current + next;
  12164. } else {
  12165. break;
  12166. }
  12167. }
  12168. }
  12169. };
  12170. return IrreversibleTransform;
  12171. })();
  12172. // Section 3.8.1 Reversible 5-3 filter
  12173. var ReversibleTransform = (function ReversibleTransformClosure() {
  12174. function ReversibleTransform() {
  12175. Transform.call(this);
  12176. }
  12177. ReversibleTransform.prototype = Object.create(Transform.prototype);
  12178. ReversibleTransform.prototype.filter =
  12179. function reversibleTransformFilter(x, offset, length) {
  12180. var len = length >> 1;
  12181. offset = offset | 0;
  12182. var j, n;
  12183. for (j = offset, n = len + 1; n--; j += 2) {
  12184. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  12185. }
  12186. for (j = offset + 1, n = len; n--; j += 2) {
  12187. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  12188. }
  12189. };
  12190. return ReversibleTransform;
  12191. })();
  12192. return JpxImage;
  12193. })();
  12194. exports.JpxImage = JpxImage;
  12195. }));
  12196. (function (root, factory) {
  12197. {
  12198. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  12199. }
  12200. }(this, function (exports, sharedUtil) {
  12201. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  12202. // The Metrics object contains glyph widths (in glyph space units).
  12203. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  12204. // space unit corresponds to 1/1000th of text space unit.
  12205. var getMetrics = getLookupTableFactory(function (t) {
  12206. t['Courier'] = 600;
  12207. t['Courier-Bold'] = 600;
  12208. t['Courier-BoldOblique'] = 600;
  12209. t['Courier-Oblique'] = 600;
  12210. t['Helvetica'] = getLookupTableFactory(function (t) {
  12211. t['space'] = 278;
  12212. t['exclam'] = 278;
  12213. t['quotedbl'] = 355;
  12214. t['numbersign'] = 556;
  12215. t['dollar'] = 556;
  12216. t['percent'] = 889;
  12217. t['ampersand'] = 667;
  12218. t['quoteright'] = 222;
  12219. t['parenleft'] = 333;
  12220. t['parenright'] = 333;
  12221. t['asterisk'] = 389;
  12222. t['plus'] = 584;
  12223. t['comma'] = 278;
  12224. t['hyphen'] = 333;
  12225. t['period'] = 278;
  12226. t['slash'] = 278;
  12227. t['zero'] = 556;
  12228. t['one'] = 556;
  12229. t['two'] = 556;
  12230. t['three'] = 556;
  12231. t['four'] = 556;
  12232. t['five'] = 556;
  12233. t['six'] = 556;
  12234. t['seven'] = 556;
  12235. t['eight'] = 556;
  12236. t['nine'] = 556;
  12237. t['colon'] = 278;
  12238. t['semicolon'] = 278;
  12239. t['less'] = 584;
  12240. t['equal'] = 584;
  12241. t['greater'] = 584;
  12242. t['question'] = 556;
  12243. t['at'] = 1015;
  12244. t['A'] = 667;
  12245. t['B'] = 667;
  12246. t['C'] = 722;
  12247. t['D'] = 722;
  12248. t['E'] = 667;
  12249. t['F'] = 611;
  12250. t['G'] = 778;
  12251. t['H'] = 722;
  12252. t['I'] = 278;
  12253. t['J'] = 500;
  12254. t['K'] = 667;
  12255. t['L'] = 556;
  12256. t['M'] = 833;
  12257. t['N'] = 722;
  12258. t['O'] = 778;
  12259. t['P'] = 667;
  12260. t['Q'] = 778;
  12261. t['R'] = 722;
  12262. t['S'] = 667;
  12263. t['T'] = 611;
  12264. t['U'] = 722;
  12265. t['V'] = 667;
  12266. t['W'] = 944;
  12267. t['X'] = 667;
  12268. t['Y'] = 667;
  12269. t['Z'] = 611;
  12270. t['bracketleft'] = 278;
  12271. t['backslash'] = 278;
  12272. t['bracketright'] = 278;
  12273. t['asciicircum'] = 469;
  12274. t['underscore'] = 556;
  12275. t['quoteleft'] = 222;
  12276. t['a'] = 556;
  12277. t['b'] = 556;
  12278. t['c'] = 500;
  12279. t['d'] = 556;
  12280. t['e'] = 556;
  12281. t['f'] = 278;
  12282. t['g'] = 556;
  12283. t['h'] = 556;
  12284. t['i'] = 222;
  12285. t['j'] = 222;
  12286. t['k'] = 500;
  12287. t['l'] = 222;
  12288. t['m'] = 833;
  12289. t['n'] = 556;
  12290. t['o'] = 556;
  12291. t['p'] = 556;
  12292. t['q'] = 556;
  12293. t['r'] = 333;
  12294. t['s'] = 500;
  12295. t['t'] = 278;
  12296. t['u'] = 556;
  12297. t['v'] = 500;
  12298. t['w'] = 722;
  12299. t['x'] = 500;
  12300. t['y'] = 500;
  12301. t['z'] = 500;
  12302. t['braceleft'] = 334;
  12303. t['bar'] = 260;
  12304. t['braceright'] = 334;
  12305. t['asciitilde'] = 584;
  12306. t['exclamdown'] = 333;
  12307. t['cent'] = 556;
  12308. t['sterling'] = 556;
  12309. t['fraction'] = 167;
  12310. t['yen'] = 556;
  12311. t['florin'] = 556;
  12312. t['section'] = 556;
  12313. t['currency'] = 556;
  12314. t['quotesingle'] = 191;
  12315. t['quotedblleft'] = 333;
  12316. t['guillemotleft'] = 556;
  12317. t['guilsinglleft'] = 333;
  12318. t['guilsinglright'] = 333;
  12319. t['fi'] = 500;
  12320. t['fl'] = 500;
  12321. t['endash'] = 556;
  12322. t['dagger'] = 556;
  12323. t['daggerdbl'] = 556;
  12324. t['periodcentered'] = 278;
  12325. t['paragraph'] = 537;
  12326. t['bullet'] = 350;
  12327. t['quotesinglbase'] = 222;
  12328. t['quotedblbase'] = 333;
  12329. t['quotedblright'] = 333;
  12330. t['guillemotright'] = 556;
  12331. t['ellipsis'] = 1000;
  12332. t['perthousand'] = 1000;
  12333. t['questiondown'] = 611;
  12334. t['grave'] = 333;
  12335. t['acute'] = 333;
  12336. t['circumflex'] = 333;
  12337. t['tilde'] = 333;
  12338. t['macron'] = 333;
  12339. t['breve'] = 333;
  12340. t['dotaccent'] = 333;
  12341. t['dieresis'] = 333;
  12342. t['ring'] = 333;
  12343. t['cedilla'] = 333;
  12344. t['hungarumlaut'] = 333;
  12345. t['ogonek'] = 333;
  12346. t['caron'] = 333;
  12347. t['emdash'] = 1000;
  12348. t['AE'] = 1000;
  12349. t['ordfeminine'] = 370;
  12350. t['Lslash'] = 556;
  12351. t['Oslash'] = 778;
  12352. t['OE'] = 1000;
  12353. t['ordmasculine'] = 365;
  12354. t['ae'] = 889;
  12355. t['dotlessi'] = 278;
  12356. t['lslash'] = 222;
  12357. t['oslash'] = 611;
  12358. t['oe'] = 944;
  12359. t['germandbls'] = 611;
  12360. t['Idieresis'] = 278;
  12361. t['eacute'] = 556;
  12362. t['abreve'] = 556;
  12363. t['uhungarumlaut'] = 556;
  12364. t['ecaron'] = 556;
  12365. t['Ydieresis'] = 667;
  12366. t['divide'] = 584;
  12367. t['Yacute'] = 667;
  12368. t['Acircumflex'] = 667;
  12369. t['aacute'] = 556;
  12370. t['Ucircumflex'] = 722;
  12371. t['yacute'] = 500;
  12372. t['scommaaccent'] = 500;
  12373. t['ecircumflex'] = 556;
  12374. t['Uring'] = 722;
  12375. t['Udieresis'] = 722;
  12376. t['aogonek'] = 556;
  12377. t['Uacute'] = 722;
  12378. t['uogonek'] = 556;
  12379. t['Edieresis'] = 667;
  12380. t['Dcroat'] = 722;
  12381. t['commaaccent'] = 250;
  12382. t['copyright'] = 737;
  12383. t['Emacron'] = 667;
  12384. t['ccaron'] = 500;
  12385. t['aring'] = 556;
  12386. t['Ncommaaccent'] = 722;
  12387. t['lacute'] = 222;
  12388. t['agrave'] = 556;
  12389. t['Tcommaaccent'] = 611;
  12390. t['Cacute'] = 722;
  12391. t['atilde'] = 556;
  12392. t['Edotaccent'] = 667;
  12393. t['scaron'] = 500;
  12394. t['scedilla'] = 500;
  12395. t['iacute'] = 278;
  12396. t['lozenge'] = 471;
  12397. t['Rcaron'] = 722;
  12398. t['Gcommaaccent'] = 778;
  12399. t['ucircumflex'] = 556;
  12400. t['acircumflex'] = 556;
  12401. t['Amacron'] = 667;
  12402. t['rcaron'] = 333;
  12403. t['ccedilla'] = 500;
  12404. t['Zdotaccent'] = 611;
  12405. t['Thorn'] = 667;
  12406. t['Omacron'] = 778;
  12407. t['Racute'] = 722;
  12408. t['Sacute'] = 667;
  12409. t['dcaron'] = 643;
  12410. t['Umacron'] = 722;
  12411. t['uring'] = 556;
  12412. t['threesuperior'] = 333;
  12413. t['Ograve'] = 778;
  12414. t['Agrave'] = 667;
  12415. t['Abreve'] = 667;
  12416. t['multiply'] = 584;
  12417. t['uacute'] = 556;
  12418. t['Tcaron'] = 611;
  12419. t['partialdiff'] = 476;
  12420. t['ydieresis'] = 500;
  12421. t['Nacute'] = 722;
  12422. t['icircumflex'] = 278;
  12423. t['Ecircumflex'] = 667;
  12424. t['adieresis'] = 556;
  12425. t['edieresis'] = 556;
  12426. t['cacute'] = 500;
  12427. t['nacute'] = 556;
  12428. t['umacron'] = 556;
  12429. t['Ncaron'] = 722;
  12430. t['Iacute'] = 278;
  12431. t['plusminus'] = 584;
  12432. t['brokenbar'] = 260;
  12433. t['registered'] = 737;
  12434. t['Gbreve'] = 778;
  12435. t['Idotaccent'] = 278;
  12436. t['summation'] = 600;
  12437. t['Egrave'] = 667;
  12438. t['racute'] = 333;
  12439. t['omacron'] = 556;
  12440. t['Zacute'] = 611;
  12441. t['Zcaron'] = 611;
  12442. t['greaterequal'] = 549;
  12443. t['Eth'] = 722;
  12444. t['Ccedilla'] = 722;
  12445. t['lcommaaccent'] = 222;
  12446. t['tcaron'] = 317;
  12447. t['eogonek'] = 556;
  12448. t['Uogonek'] = 722;
  12449. t['Aacute'] = 667;
  12450. t['Adieresis'] = 667;
  12451. t['egrave'] = 556;
  12452. t['zacute'] = 500;
  12453. t['iogonek'] = 222;
  12454. t['Oacute'] = 778;
  12455. t['oacute'] = 556;
  12456. t['amacron'] = 556;
  12457. t['sacute'] = 500;
  12458. t['idieresis'] = 278;
  12459. t['Ocircumflex'] = 778;
  12460. t['Ugrave'] = 722;
  12461. t['Delta'] = 612;
  12462. t['thorn'] = 556;
  12463. t['twosuperior'] = 333;
  12464. t['Odieresis'] = 778;
  12465. t['mu'] = 556;
  12466. t['igrave'] = 278;
  12467. t['ohungarumlaut'] = 556;
  12468. t['Eogonek'] = 667;
  12469. t['dcroat'] = 556;
  12470. t['threequarters'] = 834;
  12471. t['Scedilla'] = 667;
  12472. t['lcaron'] = 299;
  12473. t['Kcommaaccent'] = 667;
  12474. t['Lacute'] = 556;
  12475. t['trademark'] = 1000;
  12476. t['edotaccent'] = 556;
  12477. t['Igrave'] = 278;
  12478. t['Imacron'] = 278;
  12479. t['Lcaron'] = 556;
  12480. t['onehalf'] = 834;
  12481. t['lessequal'] = 549;
  12482. t['ocircumflex'] = 556;
  12483. t['ntilde'] = 556;
  12484. t['Uhungarumlaut'] = 722;
  12485. t['Eacute'] = 667;
  12486. t['emacron'] = 556;
  12487. t['gbreve'] = 556;
  12488. t['onequarter'] = 834;
  12489. t['Scaron'] = 667;
  12490. t['Scommaaccent'] = 667;
  12491. t['Ohungarumlaut'] = 778;
  12492. t['degree'] = 400;
  12493. t['ograve'] = 556;
  12494. t['Ccaron'] = 722;
  12495. t['ugrave'] = 556;
  12496. t['radical'] = 453;
  12497. t['Dcaron'] = 722;
  12498. t['rcommaaccent'] = 333;
  12499. t['Ntilde'] = 722;
  12500. t['otilde'] = 556;
  12501. t['Rcommaaccent'] = 722;
  12502. t['Lcommaaccent'] = 556;
  12503. t['Atilde'] = 667;
  12504. t['Aogonek'] = 667;
  12505. t['Aring'] = 667;
  12506. t['Otilde'] = 778;
  12507. t['zdotaccent'] = 500;
  12508. t['Ecaron'] = 667;
  12509. t['Iogonek'] = 278;
  12510. t['kcommaaccent'] = 500;
  12511. t['minus'] = 584;
  12512. t['Icircumflex'] = 278;
  12513. t['ncaron'] = 556;
  12514. t['tcommaaccent'] = 278;
  12515. t['logicalnot'] = 584;
  12516. t['odieresis'] = 556;
  12517. t['udieresis'] = 556;
  12518. t['notequal'] = 549;
  12519. t['gcommaaccent'] = 556;
  12520. t['eth'] = 556;
  12521. t['zcaron'] = 500;
  12522. t['ncommaaccent'] = 556;
  12523. t['onesuperior'] = 333;
  12524. t['imacron'] = 278;
  12525. t['Euro'] = 556;
  12526. });
  12527. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  12528. t['space'] = 278;
  12529. t['exclam'] = 333;
  12530. t['quotedbl'] = 474;
  12531. t['numbersign'] = 556;
  12532. t['dollar'] = 556;
  12533. t['percent'] = 889;
  12534. t['ampersand'] = 722;
  12535. t['quoteright'] = 278;
  12536. t['parenleft'] = 333;
  12537. t['parenright'] = 333;
  12538. t['asterisk'] = 389;
  12539. t['plus'] = 584;
  12540. t['comma'] = 278;
  12541. t['hyphen'] = 333;
  12542. t['period'] = 278;
  12543. t['slash'] = 278;
  12544. t['zero'] = 556;
  12545. t['one'] = 556;
  12546. t['two'] = 556;
  12547. t['three'] = 556;
  12548. t['four'] = 556;
  12549. t['five'] = 556;
  12550. t['six'] = 556;
  12551. t['seven'] = 556;
  12552. t['eight'] = 556;
  12553. t['nine'] = 556;
  12554. t['colon'] = 333;
  12555. t['semicolon'] = 333;
  12556. t['less'] = 584;
  12557. t['equal'] = 584;
  12558. t['greater'] = 584;
  12559. t['question'] = 611;
  12560. t['at'] = 975;
  12561. t['A'] = 722;
  12562. t['B'] = 722;
  12563. t['C'] = 722;
  12564. t['D'] = 722;
  12565. t['E'] = 667;
  12566. t['F'] = 611;
  12567. t['G'] = 778;
  12568. t['H'] = 722;
  12569. t['I'] = 278;
  12570. t['J'] = 556;
  12571. t['K'] = 722;
  12572. t['L'] = 611;
  12573. t['M'] = 833;
  12574. t['N'] = 722;
  12575. t['O'] = 778;
  12576. t['P'] = 667;
  12577. t['Q'] = 778;
  12578. t['R'] = 722;
  12579. t['S'] = 667;
  12580. t['T'] = 611;
  12581. t['U'] = 722;
  12582. t['V'] = 667;
  12583. t['W'] = 944;
  12584. t['X'] = 667;
  12585. t['Y'] = 667;
  12586. t['Z'] = 611;
  12587. t['bracketleft'] = 333;
  12588. t['backslash'] = 278;
  12589. t['bracketright'] = 333;
  12590. t['asciicircum'] = 584;
  12591. t['underscore'] = 556;
  12592. t['quoteleft'] = 278;
  12593. t['a'] = 556;
  12594. t['b'] = 611;
  12595. t['c'] = 556;
  12596. t['d'] = 611;
  12597. t['e'] = 556;
  12598. t['f'] = 333;
  12599. t['g'] = 611;
  12600. t['h'] = 611;
  12601. t['i'] = 278;
  12602. t['j'] = 278;
  12603. t['k'] = 556;
  12604. t['l'] = 278;
  12605. t['m'] = 889;
  12606. t['n'] = 611;
  12607. t['o'] = 611;
  12608. t['p'] = 611;
  12609. t['q'] = 611;
  12610. t['r'] = 389;
  12611. t['s'] = 556;
  12612. t['t'] = 333;
  12613. t['u'] = 611;
  12614. t['v'] = 556;
  12615. t['w'] = 778;
  12616. t['x'] = 556;
  12617. t['y'] = 556;
  12618. t['z'] = 500;
  12619. t['braceleft'] = 389;
  12620. t['bar'] = 280;
  12621. t['braceright'] = 389;
  12622. t['asciitilde'] = 584;
  12623. t['exclamdown'] = 333;
  12624. t['cent'] = 556;
  12625. t['sterling'] = 556;
  12626. t['fraction'] = 167;
  12627. t['yen'] = 556;
  12628. t['florin'] = 556;
  12629. t['section'] = 556;
  12630. t['currency'] = 556;
  12631. t['quotesingle'] = 238;
  12632. t['quotedblleft'] = 500;
  12633. t['guillemotleft'] = 556;
  12634. t['guilsinglleft'] = 333;
  12635. t['guilsinglright'] = 333;
  12636. t['fi'] = 611;
  12637. t['fl'] = 611;
  12638. t['endash'] = 556;
  12639. t['dagger'] = 556;
  12640. t['daggerdbl'] = 556;
  12641. t['periodcentered'] = 278;
  12642. t['paragraph'] = 556;
  12643. t['bullet'] = 350;
  12644. t['quotesinglbase'] = 278;
  12645. t['quotedblbase'] = 500;
  12646. t['quotedblright'] = 500;
  12647. t['guillemotright'] = 556;
  12648. t['ellipsis'] = 1000;
  12649. t['perthousand'] = 1000;
  12650. t['questiondown'] = 611;
  12651. t['grave'] = 333;
  12652. t['acute'] = 333;
  12653. t['circumflex'] = 333;
  12654. t['tilde'] = 333;
  12655. t['macron'] = 333;
  12656. t['breve'] = 333;
  12657. t['dotaccent'] = 333;
  12658. t['dieresis'] = 333;
  12659. t['ring'] = 333;
  12660. t['cedilla'] = 333;
  12661. t['hungarumlaut'] = 333;
  12662. t['ogonek'] = 333;
  12663. t['caron'] = 333;
  12664. t['emdash'] = 1000;
  12665. t['AE'] = 1000;
  12666. t['ordfeminine'] = 370;
  12667. t['Lslash'] = 611;
  12668. t['Oslash'] = 778;
  12669. t['OE'] = 1000;
  12670. t['ordmasculine'] = 365;
  12671. t['ae'] = 889;
  12672. t['dotlessi'] = 278;
  12673. t['lslash'] = 278;
  12674. t['oslash'] = 611;
  12675. t['oe'] = 944;
  12676. t['germandbls'] = 611;
  12677. t['Idieresis'] = 278;
  12678. t['eacute'] = 556;
  12679. t['abreve'] = 556;
  12680. t['uhungarumlaut'] = 611;
  12681. t['ecaron'] = 556;
  12682. t['Ydieresis'] = 667;
  12683. t['divide'] = 584;
  12684. t['Yacute'] = 667;
  12685. t['Acircumflex'] = 722;
  12686. t['aacute'] = 556;
  12687. t['Ucircumflex'] = 722;
  12688. t['yacute'] = 556;
  12689. t['scommaaccent'] = 556;
  12690. t['ecircumflex'] = 556;
  12691. t['Uring'] = 722;
  12692. t['Udieresis'] = 722;
  12693. t['aogonek'] = 556;
  12694. t['Uacute'] = 722;
  12695. t['uogonek'] = 611;
  12696. t['Edieresis'] = 667;
  12697. t['Dcroat'] = 722;
  12698. t['commaaccent'] = 250;
  12699. t['copyright'] = 737;
  12700. t['Emacron'] = 667;
  12701. t['ccaron'] = 556;
  12702. t['aring'] = 556;
  12703. t['Ncommaaccent'] = 722;
  12704. t['lacute'] = 278;
  12705. t['agrave'] = 556;
  12706. t['Tcommaaccent'] = 611;
  12707. t['Cacute'] = 722;
  12708. t['atilde'] = 556;
  12709. t['Edotaccent'] = 667;
  12710. t['scaron'] = 556;
  12711. t['scedilla'] = 556;
  12712. t['iacute'] = 278;
  12713. t['lozenge'] = 494;
  12714. t['Rcaron'] = 722;
  12715. t['Gcommaaccent'] = 778;
  12716. t['ucircumflex'] = 611;
  12717. t['acircumflex'] = 556;
  12718. t['Amacron'] = 722;
  12719. t['rcaron'] = 389;
  12720. t['ccedilla'] = 556;
  12721. t['Zdotaccent'] = 611;
  12722. t['Thorn'] = 667;
  12723. t['Omacron'] = 778;
  12724. t['Racute'] = 722;
  12725. t['Sacute'] = 667;
  12726. t['dcaron'] = 743;
  12727. t['Umacron'] = 722;
  12728. t['uring'] = 611;
  12729. t['threesuperior'] = 333;
  12730. t['Ograve'] = 778;
  12731. t['Agrave'] = 722;
  12732. t['Abreve'] = 722;
  12733. t['multiply'] = 584;
  12734. t['uacute'] = 611;
  12735. t['Tcaron'] = 611;
  12736. t['partialdiff'] = 494;
  12737. t['ydieresis'] = 556;
  12738. t['Nacute'] = 722;
  12739. t['icircumflex'] = 278;
  12740. t['Ecircumflex'] = 667;
  12741. t['adieresis'] = 556;
  12742. t['edieresis'] = 556;
  12743. t['cacute'] = 556;
  12744. t['nacute'] = 611;
  12745. t['umacron'] = 611;
  12746. t['Ncaron'] = 722;
  12747. t['Iacute'] = 278;
  12748. t['plusminus'] = 584;
  12749. t['brokenbar'] = 280;
  12750. t['registered'] = 737;
  12751. t['Gbreve'] = 778;
  12752. t['Idotaccent'] = 278;
  12753. t['summation'] = 600;
  12754. t['Egrave'] = 667;
  12755. t['racute'] = 389;
  12756. t['omacron'] = 611;
  12757. t['Zacute'] = 611;
  12758. t['Zcaron'] = 611;
  12759. t['greaterequal'] = 549;
  12760. t['Eth'] = 722;
  12761. t['Ccedilla'] = 722;
  12762. t['lcommaaccent'] = 278;
  12763. t['tcaron'] = 389;
  12764. t['eogonek'] = 556;
  12765. t['Uogonek'] = 722;
  12766. t['Aacute'] = 722;
  12767. t['Adieresis'] = 722;
  12768. t['egrave'] = 556;
  12769. t['zacute'] = 500;
  12770. t['iogonek'] = 278;
  12771. t['Oacute'] = 778;
  12772. t['oacute'] = 611;
  12773. t['amacron'] = 556;
  12774. t['sacute'] = 556;
  12775. t['idieresis'] = 278;
  12776. t['Ocircumflex'] = 778;
  12777. t['Ugrave'] = 722;
  12778. t['Delta'] = 612;
  12779. t['thorn'] = 611;
  12780. t['twosuperior'] = 333;
  12781. t['Odieresis'] = 778;
  12782. t['mu'] = 611;
  12783. t['igrave'] = 278;
  12784. t['ohungarumlaut'] = 611;
  12785. t['Eogonek'] = 667;
  12786. t['dcroat'] = 611;
  12787. t['threequarters'] = 834;
  12788. t['Scedilla'] = 667;
  12789. t['lcaron'] = 400;
  12790. t['Kcommaaccent'] = 722;
  12791. t['Lacute'] = 611;
  12792. t['trademark'] = 1000;
  12793. t['edotaccent'] = 556;
  12794. t['Igrave'] = 278;
  12795. t['Imacron'] = 278;
  12796. t['Lcaron'] = 611;
  12797. t['onehalf'] = 834;
  12798. t['lessequal'] = 549;
  12799. t['ocircumflex'] = 611;
  12800. t['ntilde'] = 611;
  12801. t['Uhungarumlaut'] = 722;
  12802. t['Eacute'] = 667;
  12803. t['emacron'] = 556;
  12804. t['gbreve'] = 611;
  12805. t['onequarter'] = 834;
  12806. t['Scaron'] = 667;
  12807. t['Scommaaccent'] = 667;
  12808. t['Ohungarumlaut'] = 778;
  12809. t['degree'] = 400;
  12810. t['ograve'] = 611;
  12811. t['Ccaron'] = 722;
  12812. t['ugrave'] = 611;
  12813. t['radical'] = 549;
  12814. t['Dcaron'] = 722;
  12815. t['rcommaaccent'] = 389;
  12816. t['Ntilde'] = 722;
  12817. t['otilde'] = 611;
  12818. t['Rcommaaccent'] = 722;
  12819. t['Lcommaaccent'] = 611;
  12820. t['Atilde'] = 722;
  12821. t['Aogonek'] = 722;
  12822. t['Aring'] = 722;
  12823. t['Otilde'] = 778;
  12824. t['zdotaccent'] = 500;
  12825. t['Ecaron'] = 667;
  12826. t['Iogonek'] = 278;
  12827. t['kcommaaccent'] = 556;
  12828. t['minus'] = 584;
  12829. t['Icircumflex'] = 278;
  12830. t['ncaron'] = 611;
  12831. t['tcommaaccent'] = 333;
  12832. t['logicalnot'] = 584;
  12833. t['odieresis'] = 611;
  12834. t['udieresis'] = 611;
  12835. t['notequal'] = 549;
  12836. t['gcommaaccent'] = 611;
  12837. t['eth'] = 611;
  12838. t['zcaron'] = 500;
  12839. t['ncommaaccent'] = 611;
  12840. t['onesuperior'] = 333;
  12841. t['imacron'] = 278;
  12842. t['Euro'] = 556;
  12843. });
  12844. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  12845. t['space'] = 278;
  12846. t['exclam'] = 333;
  12847. t['quotedbl'] = 474;
  12848. t['numbersign'] = 556;
  12849. t['dollar'] = 556;
  12850. t['percent'] = 889;
  12851. t['ampersand'] = 722;
  12852. t['quoteright'] = 278;
  12853. t['parenleft'] = 333;
  12854. t['parenright'] = 333;
  12855. t['asterisk'] = 389;
  12856. t['plus'] = 584;
  12857. t['comma'] = 278;
  12858. t['hyphen'] = 333;
  12859. t['period'] = 278;
  12860. t['slash'] = 278;
  12861. t['zero'] = 556;
  12862. t['one'] = 556;
  12863. t['two'] = 556;
  12864. t['three'] = 556;
  12865. t['four'] = 556;
  12866. t['five'] = 556;
  12867. t['six'] = 556;
  12868. t['seven'] = 556;
  12869. t['eight'] = 556;
  12870. t['nine'] = 556;
  12871. t['colon'] = 333;
  12872. t['semicolon'] = 333;
  12873. t['less'] = 584;
  12874. t['equal'] = 584;
  12875. t['greater'] = 584;
  12876. t['question'] = 611;
  12877. t['at'] = 975;
  12878. t['A'] = 722;
  12879. t['B'] = 722;
  12880. t['C'] = 722;
  12881. t['D'] = 722;
  12882. t['E'] = 667;
  12883. t['F'] = 611;
  12884. t['G'] = 778;
  12885. t['H'] = 722;
  12886. t['I'] = 278;
  12887. t['J'] = 556;
  12888. t['K'] = 722;
  12889. t['L'] = 611;
  12890. t['M'] = 833;
  12891. t['N'] = 722;
  12892. t['O'] = 778;
  12893. t['P'] = 667;
  12894. t['Q'] = 778;
  12895. t['R'] = 722;
  12896. t['S'] = 667;
  12897. t['T'] = 611;
  12898. t['U'] = 722;
  12899. t['V'] = 667;
  12900. t['W'] = 944;
  12901. t['X'] = 667;
  12902. t['Y'] = 667;
  12903. t['Z'] = 611;
  12904. t['bracketleft'] = 333;
  12905. t['backslash'] = 278;
  12906. t['bracketright'] = 333;
  12907. t['asciicircum'] = 584;
  12908. t['underscore'] = 556;
  12909. t['quoteleft'] = 278;
  12910. t['a'] = 556;
  12911. t['b'] = 611;
  12912. t['c'] = 556;
  12913. t['d'] = 611;
  12914. t['e'] = 556;
  12915. t['f'] = 333;
  12916. t['g'] = 611;
  12917. t['h'] = 611;
  12918. t['i'] = 278;
  12919. t['j'] = 278;
  12920. t['k'] = 556;
  12921. t['l'] = 278;
  12922. t['m'] = 889;
  12923. t['n'] = 611;
  12924. t['o'] = 611;
  12925. t['p'] = 611;
  12926. t['q'] = 611;
  12927. t['r'] = 389;
  12928. t['s'] = 556;
  12929. t['t'] = 333;
  12930. t['u'] = 611;
  12931. t['v'] = 556;
  12932. t['w'] = 778;
  12933. t['x'] = 556;
  12934. t['y'] = 556;
  12935. t['z'] = 500;
  12936. t['braceleft'] = 389;
  12937. t['bar'] = 280;
  12938. t['braceright'] = 389;
  12939. t['asciitilde'] = 584;
  12940. t['exclamdown'] = 333;
  12941. t['cent'] = 556;
  12942. t['sterling'] = 556;
  12943. t['fraction'] = 167;
  12944. t['yen'] = 556;
  12945. t['florin'] = 556;
  12946. t['section'] = 556;
  12947. t['currency'] = 556;
  12948. t['quotesingle'] = 238;
  12949. t['quotedblleft'] = 500;
  12950. t['guillemotleft'] = 556;
  12951. t['guilsinglleft'] = 333;
  12952. t['guilsinglright'] = 333;
  12953. t['fi'] = 611;
  12954. t['fl'] = 611;
  12955. t['endash'] = 556;
  12956. t['dagger'] = 556;
  12957. t['daggerdbl'] = 556;
  12958. t['periodcentered'] = 278;
  12959. t['paragraph'] = 556;
  12960. t['bullet'] = 350;
  12961. t['quotesinglbase'] = 278;
  12962. t['quotedblbase'] = 500;
  12963. t['quotedblright'] = 500;
  12964. t['guillemotright'] = 556;
  12965. t['ellipsis'] = 1000;
  12966. t['perthousand'] = 1000;
  12967. t['questiondown'] = 611;
  12968. t['grave'] = 333;
  12969. t['acute'] = 333;
  12970. t['circumflex'] = 333;
  12971. t['tilde'] = 333;
  12972. t['macron'] = 333;
  12973. t['breve'] = 333;
  12974. t['dotaccent'] = 333;
  12975. t['dieresis'] = 333;
  12976. t['ring'] = 333;
  12977. t['cedilla'] = 333;
  12978. t['hungarumlaut'] = 333;
  12979. t['ogonek'] = 333;
  12980. t['caron'] = 333;
  12981. t['emdash'] = 1000;
  12982. t['AE'] = 1000;
  12983. t['ordfeminine'] = 370;
  12984. t['Lslash'] = 611;
  12985. t['Oslash'] = 778;
  12986. t['OE'] = 1000;
  12987. t['ordmasculine'] = 365;
  12988. t['ae'] = 889;
  12989. t['dotlessi'] = 278;
  12990. t['lslash'] = 278;
  12991. t['oslash'] = 611;
  12992. t['oe'] = 944;
  12993. t['germandbls'] = 611;
  12994. t['Idieresis'] = 278;
  12995. t['eacute'] = 556;
  12996. t['abreve'] = 556;
  12997. t['uhungarumlaut'] = 611;
  12998. t['ecaron'] = 556;
  12999. t['Ydieresis'] = 667;
  13000. t['divide'] = 584;
  13001. t['Yacute'] = 667;
  13002. t['Acircumflex'] = 722;
  13003. t['aacute'] = 556;
  13004. t['Ucircumflex'] = 722;
  13005. t['yacute'] = 556;
  13006. t['scommaaccent'] = 556;
  13007. t['ecircumflex'] = 556;
  13008. t['Uring'] = 722;
  13009. t['Udieresis'] = 722;
  13010. t['aogonek'] = 556;
  13011. t['Uacute'] = 722;
  13012. t['uogonek'] = 611;
  13013. t['Edieresis'] = 667;
  13014. t['Dcroat'] = 722;
  13015. t['commaaccent'] = 250;
  13016. t['copyright'] = 737;
  13017. t['Emacron'] = 667;
  13018. t['ccaron'] = 556;
  13019. t['aring'] = 556;
  13020. t['Ncommaaccent'] = 722;
  13021. t['lacute'] = 278;
  13022. t['agrave'] = 556;
  13023. t['Tcommaaccent'] = 611;
  13024. t['Cacute'] = 722;
  13025. t['atilde'] = 556;
  13026. t['Edotaccent'] = 667;
  13027. t['scaron'] = 556;
  13028. t['scedilla'] = 556;
  13029. t['iacute'] = 278;
  13030. t['lozenge'] = 494;
  13031. t['Rcaron'] = 722;
  13032. t['Gcommaaccent'] = 778;
  13033. t['ucircumflex'] = 611;
  13034. t['acircumflex'] = 556;
  13035. t['Amacron'] = 722;
  13036. t['rcaron'] = 389;
  13037. t['ccedilla'] = 556;
  13038. t['Zdotaccent'] = 611;
  13039. t['Thorn'] = 667;
  13040. t['Omacron'] = 778;
  13041. t['Racute'] = 722;
  13042. t['Sacute'] = 667;
  13043. t['dcaron'] = 743;
  13044. t['Umacron'] = 722;
  13045. t['uring'] = 611;
  13046. t['threesuperior'] = 333;
  13047. t['Ograve'] = 778;
  13048. t['Agrave'] = 722;
  13049. t['Abreve'] = 722;
  13050. t['multiply'] = 584;
  13051. t['uacute'] = 611;
  13052. t['Tcaron'] = 611;
  13053. t['partialdiff'] = 494;
  13054. t['ydieresis'] = 556;
  13055. t['Nacute'] = 722;
  13056. t['icircumflex'] = 278;
  13057. t['Ecircumflex'] = 667;
  13058. t['adieresis'] = 556;
  13059. t['edieresis'] = 556;
  13060. t['cacute'] = 556;
  13061. t['nacute'] = 611;
  13062. t['umacron'] = 611;
  13063. t['Ncaron'] = 722;
  13064. t['Iacute'] = 278;
  13065. t['plusminus'] = 584;
  13066. t['brokenbar'] = 280;
  13067. t['registered'] = 737;
  13068. t['Gbreve'] = 778;
  13069. t['Idotaccent'] = 278;
  13070. t['summation'] = 600;
  13071. t['Egrave'] = 667;
  13072. t['racute'] = 389;
  13073. t['omacron'] = 611;
  13074. t['Zacute'] = 611;
  13075. t['Zcaron'] = 611;
  13076. t['greaterequal'] = 549;
  13077. t['Eth'] = 722;
  13078. t['Ccedilla'] = 722;
  13079. t['lcommaaccent'] = 278;
  13080. t['tcaron'] = 389;
  13081. t['eogonek'] = 556;
  13082. t['Uogonek'] = 722;
  13083. t['Aacute'] = 722;
  13084. t['Adieresis'] = 722;
  13085. t['egrave'] = 556;
  13086. t['zacute'] = 500;
  13087. t['iogonek'] = 278;
  13088. t['Oacute'] = 778;
  13089. t['oacute'] = 611;
  13090. t['amacron'] = 556;
  13091. t['sacute'] = 556;
  13092. t['idieresis'] = 278;
  13093. t['Ocircumflex'] = 778;
  13094. t['Ugrave'] = 722;
  13095. t['Delta'] = 612;
  13096. t['thorn'] = 611;
  13097. t['twosuperior'] = 333;
  13098. t['Odieresis'] = 778;
  13099. t['mu'] = 611;
  13100. t['igrave'] = 278;
  13101. t['ohungarumlaut'] = 611;
  13102. t['Eogonek'] = 667;
  13103. t['dcroat'] = 611;
  13104. t['threequarters'] = 834;
  13105. t['Scedilla'] = 667;
  13106. t['lcaron'] = 400;
  13107. t['Kcommaaccent'] = 722;
  13108. t['Lacute'] = 611;
  13109. t['trademark'] = 1000;
  13110. t['edotaccent'] = 556;
  13111. t['Igrave'] = 278;
  13112. t['Imacron'] = 278;
  13113. t['Lcaron'] = 611;
  13114. t['onehalf'] = 834;
  13115. t['lessequal'] = 549;
  13116. t['ocircumflex'] = 611;
  13117. t['ntilde'] = 611;
  13118. t['Uhungarumlaut'] = 722;
  13119. t['Eacute'] = 667;
  13120. t['emacron'] = 556;
  13121. t['gbreve'] = 611;
  13122. t['onequarter'] = 834;
  13123. t['Scaron'] = 667;
  13124. t['Scommaaccent'] = 667;
  13125. t['Ohungarumlaut'] = 778;
  13126. t['degree'] = 400;
  13127. t['ograve'] = 611;
  13128. t['Ccaron'] = 722;
  13129. t['ugrave'] = 611;
  13130. t['radical'] = 549;
  13131. t['Dcaron'] = 722;
  13132. t['rcommaaccent'] = 389;
  13133. t['Ntilde'] = 722;
  13134. t['otilde'] = 611;
  13135. t['Rcommaaccent'] = 722;
  13136. t['Lcommaaccent'] = 611;
  13137. t['Atilde'] = 722;
  13138. t['Aogonek'] = 722;
  13139. t['Aring'] = 722;
  13140. t['Otilde'] = 778;
  13141. t['zdotaccent'] = 500;
  13142. t['Ecaron'] = 667;
  13143. t['Iogonek'] = 278;
  13144. t['kcommaaccent'] = 556;
  13145. t['minus'] = 584;
  13146. t['Icircumflex'] = 278;
  13147. t['ncaron'] = 611;
  13148. t['tcommaaccent'] = 333;
  13149. t['logicalnot'] = 584;
  13150. t['odieresis'] = 611;
  13151. t['udieresis'] = 611;
  13152. t['notequal'] = 549;
  13153. t['gcommaaccent'] = 611;
  13154. t['eth'] = 611;
  13155. t['zcaron'] = 500;
  13156. t['ncommaaccent'] = 611;
  13157. t['onesuperior'] = 333;
  13158. t['imacron'] = 278;
  13159. t['Euro'] = 556;
  13160. });
  13161. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  13162. t['space'] = 278;
  13163. t['exclam'] = 278;
  13164. t['quotedbl'] = 355;
  13165. t['numbersign'] = 556;
  13166. t['dollar'] = 556;
  13167. t['percent'] = 889;
  13168. t['ampersand'] = 667;
  13169. t['quoteright'] = 222;
  13170. t['parenleft'] = 333;
  13171. t['parenright'] = 333;
  13172. t['asterisk'] = 389;
  13173. t['plus'] = 584;
  13174. t['comma'] = 278;
  13175. t['hyphen'] = 333;
  13176. t['period'] = 278;
  13177. t['slash'] = 278;
  13178. t['zero'] = 556;
  13179. t['one'] = 556;
  13180. t['two'] = 556;
  13181. t['three'] = 556;
  13182. t['four'] = 556;
  13183. t['five'] = 556;
  13184. t['six'] = 556;
  13185. t['seven'] = 556;
  13186. t['eight'] = 556;
  13187. t['nine'] = 556;
  13188. t['colon'] = 278;
  13189. t['semicolon'] = 278;
  13190. t['less'] = 584;
  13191. t['equal'] = 584;
  13192. t['greater'] = 584;
  13193. t['question'] = 556;
  13194. t['at'] = 1015;
  13195. t['A'] = 667;
  13196. t['B'] = 667;
  13197. t['C'] = 722;
  13198. t['D'] = 722;
  13199. t['E'] = 667;
  13200. t['F'] = 611;
  13201. t['G'] = 778;
  13202. t['H'] = 722;
  13203. t['I'] = 278;
  13204. t['J'] = 500;
  13205. t['K'] = 667;
  13206. t['L'] = 556;
  13207. t['M'] = 833;
  13208. t['N'] = 722;
  13209. t['O'] = 778;
  13210. t['P'] = 667;
  13211. t['Q'] = 778;
  13212. t['R'] = 722;
  13213. t['S'] = 667;
  13214. t['T'] = 611;
  13215. t['U'] = 722;
  13216. t['V'] = 667;
  13217. t['W'] = 944;
  13218. t['X'] = 667;
  13219. t['Y'] = 667;
  13220. t['Z'] = 611;
  13221. t['bracketleft'] = 278;
  13222. t['backslash'] = 278;
  13223. t['bracketright'] = 278;
  13224. t['asciicircum'] = 469;
  13225. t['underscore'] = 556;
  13226. t['quoteleft'] = 222;
  13227. t['a'] = 556;
  13228. t['b'] = 556;
  13229. t['c'] = 500;
  13230. t['d'] = 556;
  13231. t['e'] = 556;
  13232. t['f'] = 278;
  13233. t['g'] = 556;
  13234. t['h'] = 556;
  13235. t['i'] = 222;
  13236. t['j'] = 222;
  13237. t['k'] = 500;
  13238. t['l'] = 222;
  13239. t['m'] = 833;
  13240. t['n'] = 556;
  13241. t['o'] = 556;
  13242. t['p'] = 556;
  13243. t['q'] = 556;
  13244. t['r'] = 333;
  13245. t['s'] = 500;
  13246. t['t'] = 278;
  13247. t['u'] = 556;
  13248. t['v'] = 500;
  13249. t['w'] = 722;
  13250. t['x'] = 500;
  13251. t['y'] = 500;
  13252. t['z'] = 500;
  13253. t['braceleft'] = 334;
  13254. t['bar'] = 260;
  13255. t['braceright'] = 334;
  13256. t['asciitilde'] = 584;
  13257. t['exclamdown'] = 333;
  13258. t['cent'] = 556;
  13259. t['sterling'] = 556;
  13260. t['fraction'] = 167;
  13261. t['yen'] = 556;
  13262. t['florin'] = 556;
  13263. t['section'] = 556;
  13264. t['currency'] = 556;
  13265. t['quotesingle'] = 191;
  13266. t['quotedblleft'] = 333;
  13267. t['guillemotleft'] = 556;
  13268. t['guilsinglleft'] = 333;
  13269. t['guilsinglright'] = 333;
  13270. t['fi'] = 500;
  13271. t['fl'] = 500;
  13272. t['endash'] = 556;
  13273. t['dagger'] = 556;
  13274. t['daggerdbl'] = 556;
  13275. t['periodcentered'] = 278;
  13276. t['paragraph'] = 537;
  13277. t['bullet'] = 350;
  13278. t['quotesinglbase'] = 222;
  13279. t['quotedblbase'] = 333;
  13280. t['quotedblright'] = 333;
  13281. t['guillemotright'] = 556;
  13282. t['ellipsis'] = 1000;
  13283. t['perthousand'] = 1000;
  13284. t['questiondown'] = 611;
  13285. t['grave'] = 333;
  13286. t['acute'] = 333;
  13287. t['circumflex'] = 333;
  13288. t['tilde'] = 333;
  13289. t['macron'] = 333;
  13290. t['breve'] = 333;
  13291. t['dotaccent'] = 333;
  13292. t['dieresis'] = 333;
  13293. t['ring'] = 333;
  13294. t['cedilla'] = 333;
  13295. t['hungarumlaut'] = 333;
  13296. t['ogonek'] = 333;
  13297. t['caron'] = 333;
  13298. t['emdash'] = 1000;
  13299. t['AE'] = 1000;
  13300. t['ordfeminine'] = 370;
  13301. t['Lslash'] = 556;
  13302. t['Oslash'] = 778;
  13303. t['OE'] = 1000;
  13304. t['ordmasculine'] = 365;
  13305. t['ae'] = 889;
  13306. t['dotlessi'] = 278;
  13307. t['lslash'] = 222;
  13308. t['oslash'] = 611;
  13309. t['oe'] = 944;
  13310. t['germandbls'] = 611;
  13311. t['Idieresis'] = 278;
  13312. t['eacute'] = 556;
  13313. t['abreve'] = 556;
  13314. t['uhungarumlaut'] = 556;
  13315. t['ecaron'] = 556;
  13316. t['Ydieresis'] = 667;
  13317. t['divide'] = 584;
  13318. t['Yacute'] = 667;
  13319. t['Acircumflex'] = 667;
  13320. t['aacute'] = 556;
  13321. t['Ucircumflex'] = 722;
  13322. t['yacute'] = 500;
  13323. t['scommaaccent'] = 500;
  13324. t['ecircumflex'] = 556;
  13325. t['Uring'] = 722;
  13326. t['Udieresis'] = 722;
  13327. t['aogonek'] = 556;
  13328. t['Uacute'] = 722;
  13329. t['uogonek'] = 556;
  13330. t['Edieresis'] = 667;
  13331. t['Dcroat'] = 722;
  13332. t['commaaccent'] = 250;
  13333. t['copyright'] = 737;
  13334. t['Emacron'] = 667;
  13335. t['ccaron'] = 500;
  13336. t['aring'] = 556;
  13337. t['Ncommaaccent'] = 722;
  13338. t['lacute'] = 222;
  13339. t['agrave'] = 556;
  13340. t['Tcommaaccent'] = 611;
  13341. t['Cacute'] = 722;
  13342. t['atilde'] = 556;
  13343. t['Edotaccent'] = 667;
  13344. t['scaron'] = 500;
  13345. t['scedilla'] = 500;
  13346. t['iacute'] = 278;
  13347. t['lozenge'] = 471;
  13348. t['Rcaron'] = 722;
  13349. t['Gcommaaccent'] = 778;
  13350. t['ucircumflex'] = 556;
  13351. t['acircumflex'] = 556;
  13352. t['Amacron'] = 667;
  13353. t['rcaron'] = 333;
  13354. t['ccedilla'] = 500;
  13355. t['Zdotaccent'] = 611;
  13356. t['Thorn'] = 667;
  13357. t['Omacron'] = 778;
  13358. t['Racute'] = 722;
  13359. t['Sacute'] = 667;
  13360. t['dcaron'] = 643;
  13361. t['Umacron'] = 722;
  13362. t['uring'] = 556;
  13363. t['threesuperior'] = 333;
  13364. t['Ograve'] = 778;
  13365. t['Agrave'] = 667;
  13366. t['Abreve'] = 667;
  13367. t['multiply'] = 584;
  13368. t['uacute'] = 556;
  13369. t['Tcaron'] = 611;
  13370. t['partialdiff'] = 476;
  13371. t['ydieresis'] = 500;
  13372. t['Nacute'] = 722;
  13373. t['icircumflex'] = 278;
  13374. t['Ecircumflex'] = 667;
  13375. t['adieresis'] = 556;
  13376. t['edieresis'] = 556;
  13377. t['cacute'] = 500;
  13378. t['nacute'] = 556;
  13379. t['umacron'] = 556;
  13380. t['Ncaron'] = 722;
  13381. t['Iacute'] = 278;
  13382. t['plusminus'] = 584;
  13383. t['brokenbar'] = 260;
  13384. t['registered'] = 737;
  13385. t['Gbreve'] = 778;
  13386. t['Idotaccent'] = 278;
  13387. t['summation'] = 600;
  13388. t['Egrave'] = 667;
  13389. t['racute'] = 333;
  13390. t['omacron'] = 556;
  13391. t['Zacute'] = 611;
  13392. t['Zcaron'] = 611;
  13393. t['greaterequal'] = 549;
  13394. t['Eth'] = 722;
  13395. t['Ccedilla'] = 722;
  13396. t['lcommaaccent'] = 222;
  13397. t['tcaron'] = 317;
  13398. t['eogonek'] = 556;
  13399. t['Uogonek'] = 722;
  13400. t['Aacute'] = 667;
  13401. t['Adieresis'] = 667;
  13402. t['egrave'] = 556;
  13403. t['zacute'] = 500;
  13404. t['iogonek'] = 222;
  13405. t['Oacute'] = 778;
  13406. t['oacute'] = 556;
  13407. t['amacron'] = 556;
  13408. t['sacute'] = 500;
  13409. t['idieresis'] = 278;
  13410. t['Ocircumflex'] = 778;
  13411. t['Ugrave'] = 722;
  13412. t['Delta'] = 612;
  13413. t['thorn'] = 556;
  13414. t['twosuperior'] = 333;
  13415. t['Odieresis'] = 778;
  13416. t['mu'] = 556;
  13417. t['igrave'] = 278;
  13418. t['ohungarumlaut'] = 556;
  13419. t['Eogonek'] = 667;
  13420. t['dcroat'] = 556;
  13421. t['threequarters'] = 834;
  13422. t['Scedilla'] = 667;
  13423. t['lcaron'] = 299;
  13424. t['Kcommaaccent'] = 667;
  13425. t['Lacute'] = 556;
  13426. t['trademark'] = 1000;
  13427. t['edotaccent'] = 556;
  13428. t['Igrave'] = 278;
  13429. t['Imacron'] = 278;
  13430. t['Lcaron'] = 556;
  13431. t['onehalf'] = 834;
  13432. t['lessequal'] = 549;
  13433. t['ocircumflex'] = 556;
  13434. t['ntilde'] = 556;
  13435. t['Uhungarumlaut'] = 722;
  13436. t['Eacute'] = 667;
  13437. t['emacron'] = 556;
  13438. t['gbreve'] = 556;
  13439. t['onequarter'] = 834;
  13440. t['Scaron'] = 667;
  13441. t['Scommaaccent'] = 667;
  13442. t['Ohungarumlaut'] = 778;
  13443. t['degree'] = 400;
  13444. t['ograve'] = 556;
  13445. t['Ccaron'] = 722;
  13446. t['ugrave'] = 556;
  13447. t['radical'] = 453;
  13448. t['Dcaron'] = 722;
  13449. t['rcommaaccent'] = 333;
  13450. t['Ntilde'] = 722;
  13451. t['otilde'] = 556;
  13452. t['Rcommaaccent'] = 722;
  13453. t['Lcommaaccent'] = 556;
  13454. t['Atilde'] = 667;
  13455. t['Aogonek'] = 667;
  13456. t['Aring'] = 667;
  13457. t['Otilde'] = 778;
  13458. t['zdotaccent'] = 500;
  13459. t['Ecaron'] = 667;
  13460. t['Iogonek'] = 278;
  13461. t['kcommaaccent'] = 500;
  13462. t['minus'] = 584;
  13463. t['Icircumflex'] = 278;
  13464. t['ncaron'] = 556;
  13465. t['tcommaaccent'] = 278;
  13466. t['logicalnot'] = 584;
  13467. t['odieresis'] = 556;
  13468. t['udieresis'] = 556;
  13469. t['notequal'] = 549;
  13470. t['gcommaaccent'] = 556;
  13471. t['eth'] = 556;
  13472. t['zcaron'] = 500;
  13473. t['ncommaaccent'] = 556;
  13474. t['onesuperior'] = 333;
  13475. t['imacron'] = 278;
  13476. t['Euro'] = 556;
  13477. });
  13478. t['Symbol'] = getLookupTableFactory(function (t) {
  13479. t['space'] = 250;
  13480. t['exclam'] = 333;
  13481. t['universal'] = 713;
  13482. t['numbersign'] = 500;
  13483. t['existential'] = 549;
  13484. t['percent'] = 833;
  13485. t['ampersand'] = 778;
  13486. t['suchthat'] = 439;
  13487. t['parenleft'] = 333;
  13488. t['parenright'] = 333;
  13489. t['asteriskmath'] = 500;
  13490. t['plus'] = 549;
  13491. t['comma'] = 250;
  13492. t['minus'] = 549;
  13493. t['period'] = 250;
  13494. t['slash'] = 278;
  13495. t['zero'] = 500;
  13496. t['one'] = 500;
  13497. t['two'] = 500;
  13498. t['three'] = 500;
  13499. t['four'] = 500;
  13500. t['five'] = 500;
  13501. t['six'] = 500;
  13502. t['seven'] = 500;
  13503. t['eight'] = 500;
  13504. t['nine'] = 500;
  13505. t['colon'] = 278;
  13506. t['semicolon'] = 278;
  13507. t['less'] = 549;
  13508. t['equal'] = 549;
  13509. t['greater'] = 549;
  13510. t['question'] = 444;
  13511. t['congruent'] = 549;
  13512. t['Alpha'] = 722;
  13513. t['Beta'] = 667;
  13514. t['Chi'] = 722;
  13515. t['Delta'] = 612;
  13516. t['Epsilon'] = 611;
  13517. t['Phi'] = 763;
  13518. t['Gamma'] = 603;
  13519. t['Eta'] = 722;
  13520. t['Iota'] = 333;
  13521. t['theta1'] = 631;
  13522. t['Kappa'] = 722;
  13523. t['Lambda'] = 686;
  13524. t['Mu'] = 889;
  13525. t['Nu'] = 722;
  13526. t['Omicron'] = 722;
  13527. t['Pi'] = 768;
  13528. t['Theta'] = 741;
  13529. t['Rho'] = 556;
  13530. t['Sigma'] = 592;
  13531. t['Tau'] = 611;
  13532. t['Upsilon'] = 690;
  13533. t['sigma1'] = 439;
  13534. t['Omega'] = 768;
  13535. t['Xi'] = 645;
  13536. t['Psi'] = 795;
  13537. t['Zeta'] = 611;
  13538. t['bracketleft'] = 333;
  13539. t['therefore'] = 863;
  13540. t['bracketright'] = 333;
  13541. t['perpendicular'] = 658;
  13542. t['underscore'] = 500;
  13543. t['radicalex'] = 500;
  13544. t['alpha'] = 631;
  13545. t['beta'] = 549;
  13546. t['chi'] = 549;
  13547. t['delta'] = 494;
  13548. t['epsilon'] = 439;
  13549. t['phi'] = 521;
  13550. t['gamma'] = 411;
  13551. t['eta'] = 603;
  13552. t['iota'] = 329;
  13553. t['phi1'] = 603;
  13554. t['kappa'] = 549;
  13555. t['lambda'] = 549;
  13556. t['mu'] = 576;
  13557. t['nu'] = 521;
  13558. t['omicron'] = 549;
  13559. t['pi'] = 549;
  13560. t['theta'] = 521;
  13561. t['rho'] = 549;
  13562. t['sigma'] = 603;
  13563. t['tau'] = 439;
  13564. t['upsilon'] = 576;
  13565. t['omega1'] = 713;
  13566. t['omega'] = 686;
  13567. t['xi'] = 493;
  13568. t['psi'] = 686;
  13569. t['zeta'] = 494;
  13570. t['braceleft'] = 480;
  13571. t['bar'] = 200;
  13572. t['braceright'] = 480;
  13573. t['similar'] = 549;
  13574. t['Euro'] = 750;
  13575. t['Upsilon1'] = 620;
  13576. t['minute'] = 247;
  13577. t['lessequal'] = 549;
  13578. t['fraction'] = 167;
  13579. t['infinity'] = 713;
  13580. t['florin'] = 500;
  13581. t['club'] = 753;
  13582. t['diamond'] = 753;
  13583. t['heart'] = 753;
  13584. t['spade'] = 753;
  13585. t['arrowboth'] = 1042;
  13586. t['arrowleft'] = 987;
  13587. t['arrowup'] = 603;
  13588. t['arrowright'] = 987;
  13589. t['arrowdown'] = 603;
  13590. t['degree'] = 400;
  13591. t['plusminus'] = 549;
  13592. t['second'] = 411;
  13593. t['greaterequal'] = 549;
  13594. t['multiply'] = 549;
  13595. t['proportional'] = 713;
  13596. t['partialdiff'] = 494;
  13597. t['bullet'] = 460;
  13598. t['divide'] = 549;
  13599. t['notequal'] = 549;
  13600. t['equivalence'] = 549;
  13601. t['approxequal'] = 549;
  13602. t['ellipsis'] = 1000;
  13603. t['arrowvertex'] = 603;
  13604. t['arrowhorizex'] = 1000;
  13605. t['carriagereturn'] = 658;
  13606. t['aleph'] = 823;
  13607. t['Ifraktur'] = 686;
  13608. t['Rfraktur'] = 795;
  13609. t['weierstrass'] = 987;
  13610. t['circlemultiply'] = 768;
  13611. t['circleplus'] = 768;
  13612. t['emptyset'] = 823;
  13613. t['intersection'] = 768;
  13614. t['union'] = 768;
  13615. t['propersuperset'] = 713;
  13616. t['reflexsuperset'] = 713;
  13617. t['notsubset'] = 713;
  13618. t['propersubset'] = 713;
  13619. t['reflexsubset'] = 713;
  13620. t['element'] = 713;
  13621. t['notelement'] = 713;
  13622. t['angle'] = 768;
  13623. t['gradient'] = 713;
  13624. t['registerserif'] = 790;
  13625. t['copyrightserif'] = 790;
  13626. t['trademarkserif'] = 890;
  13627. t['product'] = 823;
  13628. t['radical'] = 549;
  13629. t['dotmath'] = 250;
  13630. t['logicalnot'] = 713;
  13631. t['logicaland'] = 603;
  13632. t['logicalor'] = 603;
  13633. t['arrowdblboth'] = 1042;
  13634. t['arrowdblleft'] = 987;
  13635. t['arrowdblup'] = 603;
  13636. t['arrowdblright'] = 987;
  13637. t['arrowdbldown'] = 603;
  13638. t['lozenge'] = 494;
  13639. t['angleleft'] = 329;
  13640. t['registersans'] = 790;
  13641. t['copyrightsans'] = 790;
  13642. t['trademarksans'] = 786;
  13643. t['summation'] = 713;
  13644. t['parenlefttp'] = 384;
  13645. t['parenleftex'] = 384;
  13646. t['parenleftbt'] = 384;
  13647. t['bracketlefttp'] = 384;
  13648. t['bracketleftex'] = 384;
  13649. t['bracketleftbt'] = 384;
  13650. t['bracelefttp'] = 494;
  13651. t['braceleftmid'] = 494;
  13652. t['braceleftbt'] = 494;
  13653. t['braceex'] = 494;
  13654. t['angleright'] = 329;
  13655. t['integral'] = 274;
  13656. t['integraltp'] = 686;
  13657. t['integralex'] = 686;
  13658. t['integralbt'] = 686;
  13659. t['parenrighttp'] = 384;
  13660. t['parenrightex'] = 384;
  13661. t['parenrightbt'] = 384;
  13662. t['bracketrighttp'] = 384;
  13663. t['bracketrightex'] = 384;
  13664. t['bracketrightbt'] = 384;
  13665. t['bracerighttp'] = 494;
  13666. t['bracerightmid'] = 494;
  13667. t['bracerightbt'] = 494;
  13668. t['apple'] = 790;
  13669. });
  13670. t['Times-Roman'] = getLookupTableFactory(function (t) {
  13671. t['space'] = 250;
  13672. t['exclam'] = 333;
  13673. t['quotedbl'] = 408;
  13674. t['numbersign'] = 500;
  13675. t['dollar'] = 500;
  13676. t['percent'] = 833;
  13677. t['ampersand'] = 778;
  13678. t['quoteright'] = 333;
  13679. t['parenleft'] = 333;
  13680. t['parenright'] = 333;
  13681. t['asterisk'] = 500;
  13682. t['plus'] = 564;
  13683. t['comma'] = 250;
  13684. t['hyphen'] = 333;
  13685. t['period'] = 250;
  13686. t['slash'] = 278;
  13687. t['zero'] = 500;
  13688. t['one'] = 500;
  13689. t['two'] = 500;
  13690. t['three'] = 500;
  13691. t['four'] = 500;
  13692. t['five'] = 500;
  13693. t['six'] = 500;
  13694. t['seven'] = 500;
  13695. t['eight'] = 500;
  13696. t['nine'] = 500;
  13697. t['colon'] = 278;
  13698. t['semicolon'] = 278;
  13699. t['less'] = 564;
  13700. t['equal'] = 564;
  13701. t['greater'] = 564;
  13702. t['question'] = 444;
  13703. t['at'] = 921;
  13704. t['A'] = 722;
  13705. t['B'] = 667;
  13706. t['C'] = 667;
  13707. t['D'] = 722;
  13708. t['E'] = 611;
  13709. t['F'] = 556;
  13710. t['G'] = 722;
  13711. t['H'] = 722;
  13712. t['I'] = 333;
  13713. t['J'] = 389;
  13714. t['K'] = 722;
  13715. t['L'] = 611;
  13716. t['M'] = 889;
  13717. t['N'] = 722;
  13718. t['O'] = 722;
  13719. t['P'] = 556;
  13720. t['Q'] = 722;
  13721. t['R'] = 667;
  13722. t['S'] = 556;
  13723. t['T'] = 611;
  13724. t['U'] = 722;
  13725. t['V'] = 722;
  13726. t['W'] = 944;
  13727. t['X'] = 722;
  13728. t['Y'] = 722;
  13729. t['Z'] = 611;
  13730. t['bracketleft'] = 333;
  13731. t['backslash'] = 278;
  13732. t['bracketright'] = 333;
  13733. t['asciicircum'] = 469;
  13734. t['underscore'] = 500;
  13735. t['quoteleft'] = 333;
  13736. t['a'] = 444;
  13737. t['b'] = 500;
  13738. t['c'] = 444;
  13739. t['d'] = 500;
  13740. t['e'] = 444;
  13741. t['f'] = 333;
  13742. t['g'] = 500;
  13743. t['h'] = 500;
  13744. t['i'] = 278;
  13745. t['j'] = 278;
  13746. t['k'] = 500;
  13747. t['l'] = 278;
  13748. t['m'] = 778;
  13749. t['n'] = 500;
  13750. t['o'] = 500;
  13751. t['p'] = 500;
  13752. t['q'] = 500;
  13753. t['r'] = 333;
  13754. t['s'] = 389;
  13755. t['t'] = 278;
  13756. t['u'] = 500;
  13757. t['v'] = 500;
  13758. t['w'] = 722;
  13759. t['x'] = 500;
  13760. t['y'] = 500;
  13761. t['z'] = 444;
  13762. t['braceleft'] = 480;
  13763. t['bar'] = 200;
  13764. t['braceright'] = 480;
  13765. t['asciitilde'] = 541;
  13766. t['exclamdown'] = 333;
  13767. t['cent'] = 500;
  13768. t['sterling'] = 500;
  13769. t['fraction'] = 167;
  13770. t['yen'] = 500;
  13771. t['florin'] = 500;
  13772. t['section'] = 500;
  13773. t['currency'] = 500;
  13774. t['quotesingle'] = 180;
  13775. t['quotedblleft'] = 444;
  13776. t['guillemotleft'] = 500;
  13777. t['guilsinglleft'] = 333;
  13778. t['guilsinglright'] = 333;
  13779. t['fi'] = 556;
  13780. t['fl'] = 556;
  13781. t['endash'] = 500;
  13782. t['dagger'] = 500;
  13783. t['daggerdbl'] = 500;
  13784. t['periodcentered'] = 250;
  13785. t['paragraph'] = 453;
  13786. t['bullet'] = 350;
  13787. t['quotesinglbase'] = 333;
  13788. t['quotedblbase'] = 444;
  13789. t['quotedblright'] = 444;
  13790. t['guillemotright'] = 500;
  13791. t['ellipsis'] = 1000;
  13792. t['perthousand'] = 1000;
  13793. t['questiondown'] = 444;
  13794. t['grave'] = 333;
  13795. t['acute'] = 333;
  13796. t['circumflex'] = 333;
  13797. t['tilde'] = 333;
  13798. t['macron'] = 333;
  13799. t['breve'] = 333;
  13800. t['dotaccent'] = 333;
  13801. t['dieresis'] = 333;
  13802. t['ring'] = 333;
  13803. t['cedilla'] = 333;
  13804. t['hungarumlaut'] = 333;
  13805. t['ogonek'] = 333;
  13806. t['caron'] = 333;
  13807. t['emdash'] = 1000;
  13808. t['AE'] = 889;
  13809. t['ordfeminine'] = 276;
  13810. t['Lslash'] = 611;
  13811. t['Oslash'] = 722;
  13812. t['OE'] = 889;
  13813. t['ordmasculine'] = 310;
  13814. t['ae'] = 667;
  13815. t['dotlessi'] = 278;
  13816. t['lslash'] = 278;
  13817. t['oslash'] = 500;
  13818. t['oe'] = 722;
  13819. t['germandbls'] = 500;
  13820. t['Idieresis'] = 333;
  13821. t['eacute'] = 444;
  13822. t['abreve'] = 444;
  13823. t['uhungarumlaut'] = 500;
  13824. t['ecaron'] = 444;
  13825. t['Ydieresis'] = 722;
  13826. t['divide'] = 564;
  13827. t['Yacute'] = 722;
  13828. t['Acircumflex'] = 722;
  13829. t['aacute'] = 444;
  13830. t['Ucircumflex'] = 722;
  13831. t['yacute'] = 500;
  13832. t['scommaaccent'] = 389;
  13833. t['ecircumflex'] = 444;
  13834. t['Uring'] = 722;
  13835. t['Udieresis'] = 722;
  13836. t['aogonek'] = 444;
  13837. t['Uacute'] = 722;
  13838. t['uogonek'] = 500;
  13839. t['Edieresis'] = 611;
  13840. t['Dcroat'] = 722;
  13841. t['commaaccent'] = 250;
  13842. t['copyright'] = 760;
  13843. t['Emacron'] = 611;
  13844. t['ccaron'] = 444;
  13845. t['aring'] = 444;
  13846. t['Ncommaaccent'] = 722;
  13847. t['lacute'] = 278;
  13848. t['agrave'] = 444;
  13849. t['Tcommaaccent'] = 611;
  13850. t['Cacute'] = 667;
  13851. t['atilde'] = 444;
  13852. t['Edotaccent'] = 611;
  13853. t['scaron'] = 389;
  13854. t['scedilla'] = 389;
  13855. t['iacute'] = 278;
  13856. t['lozenge'] = 471;
  13857. t['Rcaron'] = 667;
  13858. t['Gcommaaccent'] = 722;
  13859. t['ucircumflex'] = 500;
  13860. t['acircumflex'] = 444;
  13861. t['Amacron'] = 722;
  13862. t['rcaron'] = 333;
  13863. t['ccedilla'] = 444;
  13864. t['Zdotaccent'] = 611;
  13865. t['Thorn'] = 556;
  13866. t['Omacron'] = 722;
  13867. t['Racute'] = 667;
  13868. t['Sacute'] = 556;
  13869. t['dcaron'] = 588;
  13870. t['Umacron'] = 722;
  13871. t['uring'] = 500;
  13872. t['threesuperior'] = 300;
  13873. t['Ograve'] = 722;
  13874. t['Agrave'] = 722;
  13875. t['Abreve'] = 722;
  13876. t['multiply'] = 564;
  13877. t['uacute'] = 500;
  13878. t['Tcaron'] = 611;
  13879. t['partialdiff'] = 476;
  13880. t['ydieresis'] = 500;
  13881. t['Nacute'] = 722;
  13882. t['icircumflex'] = 278;
  13883. t['Ecircumflex'] = 611;
  13884. t['adieresis'] = 444;
  13885. t['edieresis'] = 444;
  13886. t['cacute'] = 444;
  13887. t['nacute'] = 500;
  13888. t['umacron'] = 500;
  13889. t['Ncaron'] = 722;
  13890. t['Iacute'] = 333;
  13891. t['plusminus'] = 564;
  13892. t['brokenbar'] = 200;
  13893. t['registered'] = 760;
  13894. t['Gbreve'] = 722;
  13895. t['Idotaccent'] = 333;
  13896. t['summation'] = 600;
  13897. t['Egrave'] = 611;
  13898. t['racute'] = 333;
  13899. t['omacron'] = 500;
  13900. t['Zacute'] = 611;
  13901. t['Zcaron'] = 611;
  13902. t['greaterequal'] = 549;
  13903. t['Eth'] = 722;
  13904. t['Ccedilla'] = 667;
  13905. t['lcommaaccent'] = 278;
  13906. t['tcaron'] = 326;
  13907. t['eogonek'] = 444;
  13908. t['Uogonek'] = 722;
  13909. t['Aacute'] = 722;
  13910. t['Adieresis'] = 722;
  13911. t['egrave'] = 444;
  13912. t['zacute'] = 444;
  13913. t['iogonek'] = 278;
  13914. t['Oacute'] = 722;
  13915. t['oacute'] = 500;
  13916. t['amacron'] = 444;
  13917. t['sacute'] = 389;
  13918. t['idieresis'] = 278;
  13919. t['Ocircumflex'] = 722;
  13920. t['Ugrave'] = 722;
  13921. t['Delta'] = 612;
  13922. t['thorn'] = 500;
  13923. t['twosuperior'] = 300;
  13924. t['Odieresis'] = 722;
  13925. t['mu'] = 500;
  13926. t['igrave'] = 278;
  13927. t['ohungarumlaut'] = 500;
  13928. t['Eogonek'] = 611;
  13929. t['dcroat'] = 500;
  13930. t['threequarters'] = 750;
  13931. t['Scedilla'] = 556;
  13932. t['lcaron'] = 344;
  13933. t['Kcommaaccent'] = 722;
  13934. t['Lacute'] = 611;
  13935. t['trademark'] = 980;
  13936. t['edotaccent'] = 444;
  13937. t['Igrave'] = 333;
  13938. t['Imacron'] = 333;
  13939. t['Lcaron'] = 611;
  13940. t['onehalf'] = 750;
  13941. t['lessequal'] = 549;
  13942. t['ocircumflex'] = 500;
  13943. t['ntilde'] = 500;
  13944. t['Uhungarumlaut'] = 722;
  13945. t['Eacute'] = 611;
  13946. t['emacron'] = 444;
  13947. t['gbreve'] = 500;
  13948. t['onequarter'] = 750;
  13949. t['Scaron'] = 556;
  13950. t['Scommaaccent'] = 556;
  13951. t['Ohungarumlaut'] = 722;
  13952. t['degree'] = 400;
  13953. t['ograve'] = 500;
  13954. t['Ccaron'] = 667;
  13955. t['ugrave'] = 500;
  13956. t['radical'] = 453;
  13957. t['Dcaron'] = 722;
  13958. t['rcommaaccent'] = 333;
  13959. t['Ntilde'] = 722;
  13960. t['otilde'] = 500;
  13961. t['Rcommaaccent'] = 667;
  13962. t['Lcommaaccent'] = 611;
  13963. t['Atilde'] = 722;
  13964. t['Aogonek'] = 722;
  13965. t['Aring'] = 722;
  13966. t['Otilde'] = 722;
  13967. t['zdotaccent'] = 444;
  13968. t['Ecaron'] = 611;
  13969. t['Iogonek'] = 333;
  13970. t['kcommaaccent'] = 500;
  13971. t['minus'] = 564;
  13972. t['Icircumflex'] = 333;
  13973. t['ncaron'] = 500;
  13974. t['tcommaaccent'] = 278;
  13975. t['logicalnot'] = 564;
  13976. t['odieresis'] = 500;
  13977. t['udieresis'] = 500;
  13978. t['notequal'] = 549;
  13979. t['gcommaaccent'] = 500;
  13980. t['eth'] = 500;
  13981. t['zcaron'] = 444;
  13982. t['ncommaaccent'] = 500;
  13983. t['onesuperior'] = 300;
  13984. t['imacron'] = 278;
  13985. t['Euro'] = 500;
  13986. });
  13987. t['Times-Bold'] = getLookupTableFactory(function (t) {
  13988. t['space'] = 250;
  13989. t['exclam'] = 333;
  13990. t['quotedbl'] = 555;
  13991. t['numbersign'] = 500;
  13992. t['dollar'] = 500;
  13993. t['percent'] = 1000;
  13994. t['ampersand'] = 833;
  13995. t['quoteright'] = 333;
  13996. t['parenleft'] = 333;
  13997. t['parenright'] = 333;
  13998. t['asterisk'] = 500;
  13999. t['plus'] = 570;
  14000. t['comma'] = 250;
  14001. t['hyphen'] = 333;
  14002. t['period'] = 250;
  14003. t['slash'] = 278;
  14004. t['zero'] = 500;
  14005. t['one'] = 500;
  14006. t['two'] = 500;
  14007. t['three'] = 500;
  14008. t['four'] = 500;
  14009. t['five'] = 500;
  14010. t['six'] = 500;
  14011. t['seven'] = 500;
  14012. t['eight'] = 500;
  14013. t['nine'] = 500;
  14014. t['colon'] = 333;
  14015. t['semicolon'] = 333;
  14016. t['less'] = 570;
  14017. t['equal'] = 570;
  14018. t['greater'] = 570;
  14019. t['question'] = 500;
  14020. t['at'] = 930;
  14021. t['A'] = 722;
  14022. t['B'] = 667;
  14023. t['C'] = 722;
  14024. t['D'] = 722;
  14025. t['E'] = 667;
  14026. t['F'] = 611;
  14027. t['G'] = 778;
  14028. t['H'] = 778;
  14029. t['I'] = 389;
  14030. t['J'] = 500;
  14031. t['K'] = 778;
  14032. t['L'] = 667;
  14033. t['M'] = 944;
  14034. t['N'] = 722;
  14035. t['O'] = 778;
  14036. t['P'] = 611;
  14037. t['Q'] = 778;
  14038. t['R'] = 722;
  14039. t['S'] = 556;
  14040. t['T'] = 667;
  14041. t['U'] = 722;
  14042. t['V'] = 722;
  14043. t['W'] = 1000;
  14044. t['X'] = 722;
  14045. t['Y'] = 722;
  14046. t['Z'] = 667;
  14047. t['bracketleft'] = 333;
  14048. t['backslash'] = 278;
  14049. t['bracketright'] = 333;
  14050. t['asciicircum'] = 581;
  14051. t['underscore'] = 500;
  14052. t['quoteleft'] = 333;
  14053. t['a'] = 500;
  14054. t['b'] = 556;
  14055. t['c'] = 444;
  14056. t['d'] = 556;
  14057. t['e'] = 444;
  14058. t['f'] = 333;
  14059. t['g'] = 500;
  14060. t['h'] = 556;
  14061. t['i'] = 278;
  14062. t['j'] = 333;
  14063. t['k'] = 556;
  14064. t['l'] = 278;
  14065. t['m'] = 833;
  14066. t['n'] = 556;
  14067. t['o'] = 500;
  14068. t['p'] = 556;
  14069. t['q'] = 556;
  14070. t['r'] = 444;
  14071. t['s'] = 389;
  14072. t['t'] = 333;
  14073. t['u'] = 556;
  14074. t['v'] = 500;
  14075. t['w'] = 722;
  14076. t['x'] = 500;
  14077. t['y'] = 500;
  14078. t['z'] = 444;
  14079. t['braceleft'] = 394;
  14080. t['bar'] = 220;
  14081. t['braceright'] = 394;
  14082. t['asciitilde'] = 520;
  14083. t['exclamdown'] = 333;
  14084. t['cent'] = 500;
  14085. t['sterling'] = 500;
  14086. t['fraction'] = 167;
  14087. t['yen'] = 500;
  14088. t['florin'] = 500;
  14089. t['section'] = 500;
  14090. t['currency'] = 500;
  14091. t['quotesingle'] = 278;
  14092. t['quotedblleft'] = 500;
  14093. t['guillemotleft'] = 500;
  14094. t['guilsinglleft'] = 333;
  14095. t['guilsinglright'] = 333;
  14096. t['fi'] = 556;
  14097. t['fl'] = 556;
  14098. t['endash'] = 500;
  14099. t['dagger'] = 500;
  14100. t['daggerdbl'] = 500;
  14101. t['periodcentered'] = 250;
  14102. t['paragraph'] = 540;
  14103. t['bullet'] = 350;
  14104. t['quotesinglbase'] = 333;
  14105. t['quotedblbase'] = 500;
  14106. t['quotedblright'] = 500;
  14107. t['guillemotright'] = 500;
  14108. t['ellipsis'] = 1000;
  14109. t['perthousand'] = 1000;
  14110. t['questiondown'] = 500;
  14111. t['grave'] = 333;
  14112. t['acute'] = 333;
  14113. t['circumflex'] = 333;
  14114. t['tilde'] = 333;
  14115. t['macron'] = 333;
  14116. t['breve'] = 333;
  14117. t['dotaccent'] = 333;
  14118. t['dieresis'] = 333;
  14119. t['ring'] = 333;
  14120. t['cedilla'] = 333;
  14121. t['hungarumlaut'] = 333;
  14122. t['ogonek'] = 333;
  14123. t['caron'] = 333;
  14124. t['emdash'] = 1000;
  14125. t['AE'] = 1000;
  14126. t['ordfeminine'] = 300;
  14127. t['Lslash'] = 667;
  14128. t['Oslash'] = 778;
  14129. t['OE'] = 1000;
  14130. t['ordmasculine'] = 330;
  14131. t['ae'] = 722;
  14132. t['dotlessi'] = 278;
  14133. t['lslash'] = 278;
  14134. t['oslash'] = 500;
  14135. t['oe'] = 722;
  14136. t['germandbls'] = 556;
  14137. t['Idieresis'] = 389;
  14138. t['eacute'] = 444;
  14139. t['abreve'] = 500;
  14140. t['uhungarumlaut'] = 556;
  14141. t['ecaron'] = 444;
  14142. t['Ydieresis'] = 722;
  14143. t['divide'] = 570;
  14144. t['Yacute'] = 722;
  14145. t['Acircumflex'] = 722;
  14146. t['aacute'] = 500;
  14147. t['Ucircumflex'] = 722;
  14148. t['yacute'] = 500;
  14149. t['scommaaccent'] = 389;
  14150. t['ecircumflex'] = 444;
  14151. t['Uring'] = 722;
  14152. t['Udieresis'] = 722;
  14153. t['aogonek'] = 500;
  14154. t['Uacute'] = 722;
  14155. t['uogonek'] = 556;
  14156. t['Edieresis'] = 667;
  14157. t['Dcroat'] = 722;
  14158. t['commaaccent'] = 250;
  14159. t['copyright'] = 747;
  14160. t['Emacron'] = 667;
  14161. t['ccaron'] = 444;
  14162. t['aring'] = 500;
  14163. t['Ncommaaccent'] = 722;
  14164. t['lacute'] = 278;
  14165. t['agrave'] = 500;
  14166. t['Tcommaaccent'] = 667;
  14167. t['Cacute'] = 722;
  14168. t['atilde'] = 500;
  14169. t['Edotaccent'] = 667;
  14170. t['scaron'] = 389;
  14171. t['scedilla'] = 389;
  14172. t['iacute'] = 278;
  14173. t['lozenge'] = 494;
  14174. t['Rcaron'] = 722;
  14175. t['Gcommaaccent'] = 778;
  14176. t['ucircumflex'] = 556;
  14177. t['acircumflex'] = 500;
  14178. t['Amacron'] = 722;
  14179. t['rcaron'] = 444;
  14180. t['ccedilla'] = 444;
  14181. t['Zdotaccent'] = 667;
  14182. t['Thorn'] = 611;
  14183. t['Omacron'] = 778;
  14184. t['Racute'] = 722;
  14185. t['Sacute'] = 556;
  14186. t['dcaron'] = 672;
  14187. t['Umacron'] = 722;
  14188. t['uring'] = 556;
  14189. t['threesuperior'] = 300;
  14190. t['Ograve'] = 778;
  14191. t['Agrave'] = 722;
  14192. t['Abreve'] = 722;
  14193. t['multiply'] = 570;
  14194. t['uacute'] = 556;
  14195. t['Tcaron'] = 667;
  14196. t['partialdiff'] = 494;
  14197. t['ydieresis'] = 500;
  14198. t['Nacute'] = 722;
  14199. t['icircumflex'] = 278;
  14200. t['Ecircumflex'] = 667;
  14201. t['adieresis'] = 500;
  14202. t['edieresis'] = 444;
  14203. t['cacute'] = 444;
  14204. t['nacute'] = 556;
  14205. t['umacron'] = 556;
  14206. t['Ncaron'] = 722;
  14207. t['Iacute'] = 389;
  14208. t['plusminus'] = 570;
  14209. t['brokenbar'] = 220;
  14210. t['registered'] = 747;
  14211. t['Gbreve'] = 778;
  14212. t['Idotaccent'] = 389;
  14213. t['summation'] = 600;
  14214. t['Egrave'] = 667;
  14215. t['racute'] = 444;
  14216. t['omacron'] = 500;
  14217. t['Zacute'] = 667;
  14218. t['Zcaron'] = 667;
  14219. t['greaterequal'] = 549;
  14220. t['Eth'] = 722;
  14221. t['Ccedilla'] = 722;
  14222. t['lcommaaccent'] = 278;
  14223. t['tcaron'] = 416;
  14224. t['eogonek'] = 444;
  14225. t['Uogonek'] = 722;
  14226. t['Aacute'] = 722;
  14227. t['Adieresis'] = 722;
  14228. t['egrave'] = 444;
  14229. t['zacute'] = 444;
  14230. t['iogonek'] = 278;
  14231. t['Oacute'] = 778;
  14232. t['oacute'] = 500;
  14233. t['amacron'] = 500;
  14234. t['sacute'] = 389;
  14235. t['idieresis'] = 278;
  14236. t['Ocircumflex'] = 778;
  14237. t['Ugrave'] = 722;
  14238. t['Delta'] = 612;
  14239. t['thorn'] = 556;
  14240. t['twosuperior'] = 300;
  14241. t['Odieresis'] = 778;
  14242. t['mu'] = 556;
  14243. t['igrave'] = 278;
  14244. t['ohungarumlaut'] = 500;
  14245. t['Eogonek'] = 667;
  14246. t['dcroat'] = 556;
  14247. t['threequarters'] = 750;
  14248. t['Scedilla'] = 556;
  14249. t['lcaron'] = 394;
  14250. t['Kcommaaccent'] = 778;
  14251. t['Lacute'] = 667;
  14252. t['trademark'] = 1000;
  14253. t['edotaccent'] = 444;
  14254. t['Igrave'] = 389;
  14255. t['Imacron'] = 389;
  14256. t['Lcaron'] = 667;
  14257. t['onehalf'] = 750;
  14258. t['lessequal'] = 549;
  14259. t['ocircumflex'] = 500;
  14260. t['ntilde'] = 556;
  14261. t['Uhungarumlaut'] = 722;
  14262. t['Eacute'] = 667;
  14263. t['emacron'] = 444;
  14264. t['gbreve'] = 500;
  14265. t['onequarter'] = 750;
  14266. t['Scaron'] = 556;
  14267. t['Scommaaccent'] = 556;
  14268. t['Ohungarumlaut'] = 778;
  14269. t['degree'] = 400;
  14270. t['ograve'] = 500;
  14271. t['Ccaron'] = 722;
  14272. t['ugrave'] = 556;
  14273. t['radical'] = 549;
  14274. t['Dcaron'] = 722;
  14275. t['rcommaaccent'] = 444;
  14276. t['Ntilde'] = 722;
  14277. t['otilde'] = 500;
  14278. t['Rcommaaccent'] = 722;
  14279. t['Lcommaaccent'] = 667;
  14280. t['Atilde'] = 722;
  14281. t['Aogonek'] = 722;
  14282. t['Aring'] = 722;
  14283. t['Otilde'] = 778;
  14284. t['zdotaccent'] = 444;
  14285. t['Ecaron'] = 667;
  14286. t['Iogonek'] = 389;
  14287. t['kcommaaccent'] = 556;
  14288. t['minus'] = 570;
  14289. t['Icircumflex'] = 389;
  14290. t['ncaron'] = 556;
  14291. t['tcommaaccent'] = 333;
  14292. t['logicalnot'] = 570;
  14293. t['odieresis'] = 500;
  14294. t['udieresis'] = 556;
  14295. t['notequal'] = 549;
  14296. t['gcommaaccent'] = 500;
  14297. t['eth'] = 500;
  14298. t['zcaron'] = 444;
  14299. t['ncommaaccent'] = 556;
  14300. t['onesuperior'] = 300;
  14301. t['imacron'] = 278;
  14302. t['Euro'] = 500;
  14303. });
  14304. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  14305. t['space'] = 250;
  14306. t['exclam'] = 389;
  14307. t['quotedbl'] = 555;
  14308. t['numbersign'] = 500;
  14309. t['dollar'] = 500;
  14310. t['percent'] = 833;
  14311. t['ampersand'] = 778;
  14312. t['quoteright'] = 333;
  14313. t['parenleft'] = 333;
  14314. t['parenright'] = 333;
  14315. t['asterisk'] = 500;
  14316. t['plus'] = 570;
  14317. t['comma'] = 250;
  14318. t['hyphen'] = 333;
  14319. t['period'] = 250;
  14320. t['slash'] = 278;
  14321. t['zero'] = 500;
  14322. t['one'] = 500;
  14323. t['two'] = 500;
  14324. t['three'] = 500;
  14325. t['four'] = 500;
  14326. t['five'] = 500;
  14327. t['six'] = 500;
  14328. t['seven'] = 500;
  14329. t['eight'] = 500;
  14330. t['nine'] = 500;
  14331. t['colon'] = 333;
  14332. t['semicolon'] = 333;
  14333. t['less'] = 570;
  14334. t['equal'] = 570;
  14335. t['greater'] = 570;
  14336. t['question'] = 500;
  14337. t['at'] = 832;
  14338. t['A'] = 667;
  14339. t['B'] = 667;
  14340. t['C'] = 667;
  14341. t['D'] = 722;
  14342. t['E'] = 667;
  14343. t['F'] = 667;
  14344. t['G'] = 722;
  14345. t['H'] = 778;
  14346. t['I'] = 389;
  14347. t['J'] = 500;
  14348. t['K'] = 667;
  14349. t['L'] = 611;
  14350. t['M'] = 889;
  14351. t['N'] = 722;
  14352. t['O'] = 722;
  14353. t['P'] = 611;
  14354. t['Q'] = 722;
  14355. t['R'] = 667;
  14356. t['S'] = 556;
  14357. t['T'] = 611;
  14358. t['U'] = 722;
  14359. t['V'] = 667;
  14360. t['W'] = 889;
  14361. t['X'] = 667;
  14362. t['Y'] = 611;
  14363. t['Z'] = 611;
  14364. t['bracketleft'] = 333;
  14365. t['backslash'] = 278;
  14366. t['bracketright'] = 333;
  14367. t['asciicircum'] = 570;
  14368. t['underscore'] = 500;
  14369. t['quoteleft'] = 333;
  14370. t['a'] = 500;
  14371. t['b'] = 500;
  14372. t['c'] = 444;
  14373. t['d'] = 500;
  14374. t['e'] = 444;
  14375. t['f'] = 333;
  14376. t['g'] = 500;
  14377. t['h'] = 556;
  14378. t['i'] = 278;
  14379. t['j'] = 278;
  14380. t['k'] = 500;
  14381. t['l'] = 278;
  14382. t['m'] = 778;
  14383. t['n'] = 556;
  14384. t['o'] = 500;
  14385. t['p'] = 500;
  14386. t['q'] = 500;
  14387. t['r'] = 389;
  14388. t['s'] = 389;
  14389. t['t'] = 278;
  14390. t['u'] = 556;
  14391. t['v'] = 444;
  14392. t['w'] = 667;
  14393. t['x'] = 500;
  14394. t['y'] = 444;
  14395. t['z'] = 389;
  14396. t['braceleft'] = 348;
  14397. t['bar'] = 220;
  14398. t['braceright'] = 348;
  14399. t['asciitilde'] = 570;
  14400. t['exclamdown'] = 389;
  14401. t['cent'] = 500;
  14402. t['sterling'] = 500;
  14403. t['fraction'] = 167;
  14404. t['yen'] = 500;
  14405. t['florin'] = 500;
  14406. t['section'] = 500;
  14407. t['currency'] = 500;
  14408. t['quotesingle'] = 278;
  14409. t['quotedblleft'] = 500;
  14410. t['guillemotleft'] = 500;
  14411. t['guilsinglleft'] = 333;
  14412. t['guilsinglright'] = 333;
  14413. t['fi'] = 556;
  14414. t['fl'] = 556;
  14415. t['endash'] = 500;
  14416. t['dagger'] = 500;
  14417. t['daggerdbl'] = 500;
  14418. t['periodcentered'] = 250;
  14419. t['paragraph'] = 500;
  14420. t['bullet'] = 350;
  14421. t['quotesinglbase'] = 333;
  14422. t['quotedblbase'] = 500;
  14423. t['quotedblright'] = 500;
  14424. t['guillemotright'] = 500;
  14425. t['ellipsis'] = 1000;
  14426. t['perthousand'] = 1000;
  14427. t['questiondown'] = 500;
  14428. t['grave'] = 333;
  14429. t['acute'] = 333;
  14430. t['circumflex'] = 333;
  14431. t['tilde'] = 333;
  14432. t['macron'] = 333;
  14433. t['breve'] = 333;
  14434. t['dotaccent'] = 333;
  14435. t['dieresis'] = 333;
  14436. t['ring'] = 333;
  14437. t['cedilla'] = 333;
  14438. t['hungarumlaut'] = 333;
  14439. t['ogonek'] = 333;
  14440. t['caron'] = 333;
  14441. t['emdash'] = 1000;
  14442. t['AE'] = 944;
  14443. t['ordfeminine'] = 266;
  14444. t['Lslash'] = 611;
  14445. t['Oslash'] = 722;
  14446. t['OE'] = 944;
  14447. t['ordmasculine'] = 300;
  14448. t['ae'] = 722;
  14449. t['dotlessi'] = 278;
  14450. t['lslash'] = 278;
  14451. t['oslash'] = 500;
  14452. t['oe'] = 722;
  14453. t['germandbls'] = 500;
  14454. t['Idieresis'] = 389;
  14455. t['eacute'] = 444;
  14456. t['abreve'] = 500;
  14457. t['uhungarumlaut'] = 556;
  14458. t['ecaron'] = 444;
  14459. t['Ydieresis'] = 611;
  14460. t['divide'] = 570;
  14461. t['Yacute'] = 611;
  14462. t['Acircumflex'] = 667;
  14463. t['aacute'] = 500;
  14464. t['Ucircumflex'] = 722;
  14465. t['yacute'] = 444;
  14466. t['scommaaccent'] = 389;
  14467. t['ecircumflex'] = 444;
  14468. t['Uring'] = 722;
  14469. t['Udieresis'] = 722;
  14470. t['aogonek'] = 500;
  14471. t['Uacute'] = 722;
  14472. t['uogonek'] = 556;
  14473. t['Edieresis'] = 667;
  14474. t['Dcroat'] = 722;
  14475. t['commaaccent'] = 250;
  14476. t['copyright'] = 747;
  14477. t['Emacron'] = 667;
  14478. t['ccaron'] = 444;
  14479. t['aring'] = 500;
  14480. t['Ncommaaccent'] = 722;
  14481. t['lacute'] = 278;
  14482. t['agrave'] = 500;
  14483. t['Tcommaaccent'] = 611;
  14484. t['Cacute'] = 667;
  14485. t['atilde'] = 500;
  14486. t['Edotaccent'] = 667;
  14487. t['scaron'] = 389;
  14488. t['scedilla'] = 389;
  14489. t['iacute'] = 278;
  14490. t['lozenge'] = 494;
  14491. t['Rcaron'] = 667;
  14492. t['Gcommaaccent'] = 722;
  14493. t['ucircumflex'] = 556;
  14494. t['acircumflex'] = 500;
  14495. t['Amacron'] = 667;
  14496. t['rcaron'] = 389;
  14497. t['ccedilla'] = 444;
  14498. t['Zdotaccent'] = 611;
  14499. t['Thorn'] = 611;
  14500. t['Omacron'] = 722;
  14501. t['Racute'] = 667;
  14502. t['Sacute'] = 556;
  14503. t['dcaron'] = 608;
  14504. t['Umacron'] = 722;
  14505. t['uring'] = 556;
  14506. t['threesuperior'] = 300;
  14507. t['Ograve'] = 722;
  14508. t['Agrave'] = 667;
  14509. t['Abreve'] = 667;
  14510. t['multiply'] = 570;
  14511. t['uacute'] = 556;
  14512. t['Tcaron'] = 611;
  14513. t['partialdiff'] = 494;
  14514. t['ydieresis'] = 444;
  14515. t['Nacute'] = 722;
  14516. t['icircumflex'] = 278;
  14517. t['Ecircumflex'] = 667;
  14518. t['adieresis'] = 500;
  14519. t['edieresis'] = 444;
  14520. t['cacute'] = 444;
  14521. t['nacute'] = 556;
  14522. t['umacron'] = 556;
  14523. t['Ncaron'] = 722;
  14524. t['Iacute'] = 389;
  14525. t['plusminus'] = 570;
  14526. t['brokenbar'] = 220;
  14527. t['registered'] = 747;
  14528. t['Gbreve'] = 722;
  14529. t['Idotaccent'] = 389;
  14530. t['summation'] = 600;
  14531. t['Egrave'] = 667;
  14532. t['racute'] = 389;
  14533. t['omacron'] = 500;
  14534. t['Zacute'] = 611;
  14535. t['Zcaron'] = 611;
  14536. t['greaterequal'] = 549;
  14537. t['Eth'] = 722;
  14538. t['Ccedilla'] = 667;
  14539. t['lcommaaccent'] = 278;
  14540. t['tcaron'] = 366;
  14541. t['eogonek'] = 444;
  14542. t['Uogonek'] = 722;
  14543. t['Aacute'] = 667;
  14544. t['Adieresis'] = 667;
  14545. t['egrave'] = 444;
  14546. t['zacute'] = 389;
  14547. t['iogonek'] = 278;
  14548. t['Oacute'] = 722;
  14549. t['oacute'] = 500;
  14550. t['amacron'] = 500;
  14551. t['sacute'] = 389;
  14552. t['idieresis'] = 278;
  14553. t['Ocircumflex'] = 722;
  14554. t['Ugrave'] = 722;
  14555. t['Delta'] = 612;
  14556. t['thorn'] = 500;
  14557. t['twosuperior'] = 300;
  14558. t['Odieresis'] = 722;
  14559. t['mu'] = 576;
  14560. t['igrave'] = 278;
  14561. t['ohungarumlaut'] = 500;
  14562. t['Eogonek'] = 667;
  14563. t['dcroat'] = 500;
  14564. t['threequarters'] = 750;
  14565. t['Scedilla'] = 556;
  14566. t['lcaron'] = 382;
  14567. t['Kcommaaccent'] = 667;
  14568. t['Lacute'] = 611;
  14569. t['trademark'] = 1000;
  14570. t['edotaccent'] = 444;
  14571. t['Igrave'] = 389;
  14572. t['Imacron'] = 389;
  14573. t['Lcaron'] = 611;
  14574. t['onehalf'] = 750;
  14575. t['lessequal'] = 549;
  14576. t['ocircumflex'] = 500;
  14577. t['ntilde'] = 556;
  14578. t['Uhungarumlaut'] = 722;
  14579. t['Eacute'] = 667;
  14580. t['emacron'] = 444;
  14581. t['gbreve'] = 500;
  14582. t['onequarter'] = 750;
  14583. t['Scaron'] = 556;
  14584. t['Scommaaccent'] = 556;
  14585. t['Ohungarumlaut'] = 722;
  14586. t['degree'] = 400;
  14587. t['ograve'] = 500;
  14588. t['Ccaron'] = 667;
  14589. t['ugrave'] = 556;
  14590. t['radical'] = 549;
  14591. t['Dcaron'] = 722;
  14592. t['rcommaaccent'] = 389;
  14593. t['Ntilde'] = 722;
  14594. t['otilde'] = 500;
  14595. t['Rcommaaccent'] = 667;
  14596. t['Lcommaaccent'] = 611;
  14597. t['Atilde'] = 667;
  14598. t['Aogonek'] = 667;
  14599. t['Aring'] = 667;
  14600. t['Otilde'] = 722;
  14601. t['zdotaccent'] = 389;
  14602. t['Ecaron'] = 667;
  14603. t['Iogonek'] = 389;
  14604. t['kcommaaccent'] = 500;
  14605. t['minus'] = 606;
  14606. t['Icircumflex'] = 389;
  14607. t['ncaron'] = 556;
  14608. t['tcommaaccent'] = 278;
  14609. t['logicalnot'] = 606;
  14610. t['odieresis'] = 500;
  14611. t['udieresis'] = 556;
  14612. t['notequal'] = 549;
  14613. t['gcommaaccent'] = 500;
  14614. t['eth'] = 500;
  14615. t['zcaron'] = 389;
  14616. t['ncommaaccent'] = 556;
  14617. t['onesuperior'] = 300;
  14618. t['imacron'] = 278;
  14619. t['Euro'] = 500;
  14620. });
  14621. t['Times-Italic'] = getLookupTableFactory(function (t) {
  14622. t['space'] = 250;
  14623. t['exclam'] = 333;
  14624. t['quotedbl'] = 420;
  14625. t['numbersign'] = 500;
  14626. t['dollar'] = 500;
  14627. t['percent'] = 833;
  14628. t['ampersand'] = 778;
  14629. t['quoteright'] = 333;
  14630. t['parenleft'] = 333;
  14631. t['parenright'] = 333;
  14632. t['asterisk'] = 500;
  14633. t['plus'] = 675;
  14634. t['comma'] = 250;
  14635. t['hyphen'] = 333;
  14636. t['period'] = 250;
  14637. t['slash'] = 278;
  14638. t['zero'] = 500;
  14639. t['one'] = 500;
  14640. t['two'] = 500;
  14641. t['three'] = 500;
  14642. t['four'] = 500;
  14643. t['five'] = 500;
  14644. t['six'] = 500;
  14645. t['seven'] = 500;
  14646. t['eight'] = 500;
  14647. t['nine'] = 500;
  14648. t['colon'] = 333;
  14649. t['semicolon'] = 333;
  14650. t['less'] = 675;
  14651. t['equal'] = 675;
  14652. t['greater'] = 675;
  14653. t['question'] = 500;
  14654. t['at'] = 920;
  14655. t['A'] = 611;
  14656. t['B'] = 611;
  14657. t['C'] = 667;
  14658. t['D'] = 722;
  14659. t['E'] = 611;
  14660. t['F'] = 611;
  14661. t['G'] = 722;
  14662. t['H'] = 722;
  14663. t['I'] = 333;
  14664. t['J'] = 444;
  14665. t['K'] = 667;
  14666. t['L'] = 556;
  14667. t['M'] = 833;
  14668. t['N'] = 667;
  14669. t['O'] = 722;
  14670. t['P'] = 611;
  14671. t['Q'] = 722;
  14672. t['R'] = 611;
  14673. t['S'] = 500;
  14674. t['T'] = 556;
  14675. t['U'] = 722;
  14676. t['V'] = 611;
  14677. t['W'] = 833;
  14678. t['X'] = 611;
  14679. t['Y'] = 556;
  14680. t['Z'] = 556;
  14681. t['bracketleft'] = 389;
  14682. t['backslash'] = 278;
  14683. t['bracketright'] = 389;
  14684. t['asciicircum'] = 422;
  14685. t['underscore'] = 500;
  14686. t['quoteleft'] = 333;
  14687. t['a'] = 500;
  14688. t['b'] = 500;
  14689. t['c'] = 444;
  14690. t['d'] = 500;
  14691. t['e'] = 444;
  14692. t['f'] = 278;
  14693. t['g'] = 500;
  14694. t['h'] = 500;
  14695. t['i'] = 278;
  14696. t['j'] = 278;
  14697. t['k'] = 444;
  14698. t['l'] = 278;
  14699. t['m'] = 722;
  14700. t['n'] = 500;
  14701. t['o'] = 500;
  14702. t['p'] = 500;
  14703. t['q'] = 500;
  14704. t['r'] = 389;
  14705. t['s'] = 389;
  14706. t['t'] = 278;
  14707. t['u'] = 500;
  14708. t['v'] = 444;
  14709. t['w'] = 667;
  14710. t['x'] = 444;
  14711. t['y'] = 444;
  14712. t['z'] = 389;
  14713. t['braceleft'] = 400;
  14714. t['bar'] = 275;
  14715. t['braceright'] = 400;
  14716. t['asciitilde'] = 541;
  14717. t['exclamdown'] = 389;
  14718. t['cent'] = 500;
  14719. t['sterling'] = 500;
  14720. t['fraction'] = 167;
  14721. t['yen'] = 500;
  14722. t['florin'] = 500;
  14723. t['section'] = 500;
  14724. t['currency'] = 500;
  14725. t['quotesingle'] = 214;
  14726. t['quotedblleft'] = 556;
  14727. t['guillemotleft'] = 500;
  14728. t['guilsinglleft'] = 333;
  14729. t['guilsinglright'] = 333;
  14730. t['fi'] = 500;
  14731. t['fl'] = 500;
  14732. t['endash'] = 500;
  14733. t['dagger'] = 500;
  14734. t['daggerdbl'] = 500;
  14735. t['periodcentered'] = 250;
  14736. t['paragraph'] = 523;
  14737. t['bullet'] = 350;
  14738. t['quotesinglbase'] = 333;
  14739. t['quotedblbase'] = 556;
  14740. t['quotedblright'] = 556;
  14741. t['guillemotright'] = 500;
  14742. t['ellipsis'] = 889;
  14743. t['perthousand'] = 1000;
  14744. t['questiondown'] = 500;
  14745. t['grave'] = 333;
  14746. t['acute'] = 333;
  14747. t['circumflex'] = 333;
  14748. t['tilde'] = 333;
  14749. t['macron'] = 333;
  14750. t['breve'] = 333;
  14751. t['dotaccent'] = 333;
  14752. t['dieresis'] = 333;
  14753. t['ring'] = 333;
  14754. t['cedilla'] = 333;
  14755. t['hungarumlaut'] = 333;
  14756. t['ogonek'] = 333;
  14757. t['caron'] = 333;
  14758. t['emdash'] = 889;
  14759. t['AE'] = 889;
  14760. t['ordfeminine'] = 276;
  14761. t['Lslash'] = 556;
  14762. t['Oslash'] = 722;
  14763. t['OE'] = 944;
  14764. t['ordmasculine'] = 310;
  14765. t['ae'] = 667;
  14766. t['dotlessi'] = 278;
  14767. t['lslash'] = 278;
  14768. t['oslash'] = 500;
  14769. t['oe'] = 667;
  14770. t['germandbls'] = 500;
  14771. t['Idieresis'] = 333;
  14772. t['eacute'] = 444;
  14773. t['abreve'] = 500;
  14774. t['uhungarumlaut'] = 500;
  14775. t['ecaron'] = 444;
  14776. t['Ydieresis'] = 556;
  14777. t['divide'] = 675;
  14778. t['Yacute'] = 556;
  14779. t['Acircumflex'] = 611;
  14780. t['aacute'] = 500;
  14781. t['Ucircumflex'] = 722;
  14782. t['yacute'] = 444;
  14783. t['scommaaccent'] = 389;
  14784. t['ecircumflex'] = 444;
  14785. t['Uring'] = 722;
  14786. t['Udieresis'] = 722;
  14787. t['aogonek'] = 500;
  14788. t['Uacute'] = 722;
  14789. t['uogonek'] = 500;
  14790. t['Edieresis'] = 611;
  14791. t['Dcroat'] = 722;
  14792. t['commaaccent'] = 250;
  14793. t['copyright'] = 760;
  14794. t['Emacron'] = 611;
  14795. t['ccaron'] = 444;
  14796. t['aring'] = 500;
  14797. t['Ncommaaccent'] = 667;
  14798. t['lacute'] = 278;
  14799. t['agrave'] = 500;
  14800. t['Tcommaaccent'] = 556;
  14801. t['Cacute'] = 667;
  14802. t['atilde'] = 500;
  14803. t['Edotaccent'] = 611;
  14804. t['scaron'] = 389;
  14805. t['scedilla'] = 389;
  14806. t['iacute'] = 278;
  14807. t['lozenge'] = 471;
  14808. t['Rcaron'] = 611;
  14809. t['Gcommaaccent'] = 722;
  14810. t['ucircumflex'] = 500;
  14811. t['acircumflex'] = 500;
  14812. t['Amacron'] = 611;
  14813. t['rcaron'] = 389;
  14814. t['ccedilla'] = 444;
  14815. t['Zdotaccent'] = 556;
  14816. t['Thorn'] = 611;
  14817. t['Omacron'] = 722;
  14818. t['Racute'] = 611;
  14819. t['Sacute'] = 500;
  14820. t['dcaron'] = 544;
  14821. t['Umacron'] = 722;
  14822. t['uring'] = 500;
  14823. t['threesuperior'] = 300;
  14824. t['Ograve'] = 722;
  14825. t['Agrave'] = 611;
  14826. t['Abreve'] = 611;
  14827. t['multiply'] = 675;
  14828. t['uacute'] = 500;
  14829. t['Tcaron'] = 556;
  14830. t['partialdiff'] = 476;
  14831. t['ydieresis'] = 444;
  14832. t['Nacute'] = 667;
  14833. t['icircumflex'] = 278;
  14834. t['Ecircumflex'] = 611;
  14835. t['adieresis'] = 500;
  14836. t['edieresis'] = 444;
  14837. t['cacute'] = 444;
  14838. t['nacute'] = 500;
  14839. t['umacron'] = 500;
  14840. t['Ncaron'] = 667;
  14841. t['Iacute'] = 333;
  14842. t['plusminus'] = 675;
  14843. t['brokenbar'] = 275;
  14844. t['registered'] = 760;
  14845. t['Gbreve'] = 722;
  14846. t['Idotaccent'] = 333;
  14847. t['summation'] = 600;
  14848. t['Egrave'] = 611;
  14849. t['racute'] = 389;
  14850. t['omacron'] = 500;
  14851. t['Zacute'] = 556;
  14852. t['Zcaron'] = 556;
  14853. t['greaterequal'] = 549;
  14854. t['Eth'] = 722;
  14855. t['Ccedilla'] = 667;
  14856. t['lcommaaccent'] = 278;
  14857. t['tcaron'] = 300;
  14858. t['eogonek'] = 444;
  14859. t['Uogonek'] = 722;
  14860. t['Aacute'] = 611;
  14861. t['Adieresis'] = 611;
  14862. t['egrave'] = 444;
  14863. t['zacute'] = 389;
  14864. t['iogonek'] = 278;
  14865. t['Oacute'] = 722;
  14866. t['oacute'] = 500;
  14867. t['amacron'] = 500;
  14868. t['sacute'] = 389;
  14869. t['idieresis'] = 278;
  14870. t['Ocircumflex'] = 722;
  14871. t['Ugrave'] = 722;
  14872. t['Delta'] = 612;
  14873. t['thorn'] = 500;
  14874. t['twosuperior'] = 300;
  14875. t['Odieresis'] = 722;
  14876. t['mu'] = 500;
  14877. t['igrave'] = 278;
  14878. t['ohungarumlaut'] = 500;
  14879. t['Eogonek'] = 611;
  14880. t['dcroat'] = 500;
  14881. t['threequarters'] = 750;
  14882. t['Scedilla'] = 500;
  14883. t['lcaron'] = 300;
  14884. t['Kcommaaccent'] = 667;
  14885. t['Lacute'] = 556;
  14886. t['trademark'] = 980;
  14887. t['edotaccent'] = 444;
  14888. t['Igrave'] = 333;
  14889. t['Imacron'] = 333;
  14890. t['Lcaron'] = 611;
  14891. t['onehalf'] = 750;
  14892. t['lessequal'] = 549;
  14893. t['ocircumflex'] = 500;
  14894. t['ntilde'] = 500;
  14895. t['Uhungarumlaut'] = 722;
  14896. t['Eacute'] = 611;
  14897. t['emacron'] = 444;
  14898. t['gbreve'] = 500;
  14899. t['onequarter'] = 750;
  14900. t['Scaron'] = 500;
  14901. t['Scommaaccent'] = 500;
  14902. t['Ohungarumlaut'] = 722;
  14903. t['degree'] = 400;
  14904. t['ograve'] = 500;
  14905. t['Ccaron'] = 667;
  14906. t['ugrave'] = 500;
  14907. t['radical'] = 453;
  14908. t['Dcaron'] = 722;
  14909. t['rcommaaccent'] = 389;
  14910. t['Ntilde'] = 667;
  14911. t['otilde'] = 500;
  14912. t['Rcommaaccent'] = 611;
  14913. t['Lcommaaccent'] = 556;
  14914. t['Atilde'] = 611;
  14915. t['Aogonek'] = 611;
  14916. t['Aring'] = 611;
  14917. t['Otilde'] = 722;
  14918. t['zdotaccent'] = 389;
  14919. t['Ecaron'] = 611;
  14920. t['Iogonek'] = 333;
  14921. t['kcommaaccent'] = 444;
  14922. t['minus'] = 675;
  14923. t['Icircumflex'] = 333;
  14924. t['ncaron'] = 500;
  14925. t['tcommaaccent'] = 278;
  14926. t['logicalnot'] = 675;
  14927. t['odieresis'] = 500;
  14928. t['udieresis'] = 500;
  14929. t['notequal'] = 549;
  14930. t['gcommaaccent'] = 500;
  14931. t['eth'] = 500;
  14932. t['zcaron'] = 389;
  14933. t['ncommaaccent'] = 500;
  14934. t['onesuperior'] = 300;
  14935. t['imacron'] = 278;
  14936. t['Euro'] = 500;
  14937. });
  14938. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  14939. t['space'] = 278;
  14940. t['a1'] = 974;
  14941. t['a2'] = 961;
  14942. t['a202'] = 974;
  14943. t['a3'] = 980;
  14944. t['a4'] = 719;
  14945. t['a5'] = 789;
  14946. t['a119'] = 790;
  14947. t['a118'] = 791;
  14948. t['a117'] = 690;
  14949. t['a11'] = 960;
  14950. t['a12'] = 939;
  14951. t['a13'] = 549;
  14952. t['a14'] = 855;
  14953. t['a15'] = 911;
  14954. t['a16'] = 933;
  14955. t['a105'] = 911;
  14956. t['a17'] = 945;
  14957. t['a18'] = 974;
  14958. t['a19'] = 755;
  14959. t['a20'] = 846;
  14960. t['a21'] = 762;
  14961. t['a22'] = 761;
  14962. t['a23'] = 571;
  14963. t['a24'] = 677;
  14964. t['a25'] = 763;
  14965. t['a26'] = 760;
  14966. t['a27'] = 759;
  14967. t['a28'] = 754;
  14968. t['a6'] = 494;
  14969. t['a7'] = 552;
  14970. t['a8'] = 537;
  14971. t['a9'] = 577;
  14972. t['a10'] = 692;
  14973. t['a29'] = 786;
  14974. t['a30'] = 788;
  14975. t['a31'] = 788;
  14976. t['a32'] = 790;
  14977. t['a33'] = 793;
  14978. t['a34'] = 794;
  14979. t['a35'] = 816;
  14980. t['a36'] = 823;
  14981. t['a37'] = 789;
  14982. t['a38'] = 841;
  14983. t['a39'] = 823;
  14984. t['a40'] = 833;
  14985. t['a41'] = 816;
  14986. t['a42'] = 831;
  14987. t['a43'] = 923;
  14988. t['a44'] = 744;
  14989. t['a45'] = 723;
  14990. t['a46'] = 749;
  14991. t['a47'] = 790;
  14992. t['a48'] = 792;
  14993. t['a49'] = 695;
  14994. t['a50'] = 776;
  14995. t['a51'] = 768;
  14996. t['a52'] = 792;
  14997. t['a53'] = 759;
  14998. t['a54'] = 707;
  14999. t['a55'] = 708;
  15000. t['a56'] = 682;
  15001. t['a57'] = 701;
  15002. t['a58'] = 826;
  15003. t['a59'] = 815;
  15004. t['a60'] = 789;
  15005. t['a61'] = 789;
  15006. t['a62'] = 707;
  15007. t['a63'] = 687;
  15008. t['a64'] = 696;
  15009. t['a65'] = 689;
  15010. t['a66'] = 786;
  15011. t['a67'] = 787;
  15012. t['a68'] = 713;
  15013. t['a69'] = 791;
  15014. t['a70'] = 785;
  15015. t['a71'] = 791;
  15016. t['a72'] = 873;
  15017. t['a73'] = 761;
  15018. t['a74'] = 762;
  15019. t['a203'] = 762;
  15020. t['a75'] = 759;
  15021. t['a204'] = 759;
  15022. t['a76'] = 892;
  15023. t['a77'] = 892;
  15024. t['a78'] = 788;
  15025. t['a79'] = 784;
  15026. t['a81'] = 438;
  15027. t['a82'] = 138;
  15028. t['a83'] = 277;
  15029. t['a84'] = 415;
  15030. t['a97'] = 392;
  15031. t['a98'] = 392;
  15032. t['a99'] = 668;
  15033. t['a100'] = 668;
  15034. t['a89'] = 390;
  15035. t['a90'] = 390;
  15036. t['a93'] = 317;
  15037. t['a94'] = 317;
  15038. t['a91'] = 276;
  15039. t['a92'] = 276;
  15040. t['a205'] = 509;
  15041. t['a85'] = 509;
  15042. t['a206'] = 410;
  15043. t['a86'] = 410;
  15044. t['a87'] = 234;
  15045. t['a88'] = 234;
  15046. t['a95'] = 334;
  15047. t['a96'] = 334;
  15048. t['a101'] = 732;
  15049. t['a102'] = 544;
  15050. t['a103'] = 544;
  15051. t['a104'] = 910;
  15052. t['a106'] = 667;
  15053. t['a107'] = 760;
  15054. t['a108'] = 760;
  15055. t['a112'] = 776;
  15056. t['a111'] = 595;
  15057. t['a110'] = 694;
  15058. t['a109'] = 626;
  15059. t['a120'] = 788;
  15060. t['a121'] = 788;
  15061. t['a122'] = 788;
  15062. t['a123'] = 788;
  15063. t['a124'] = 788;
  15064. t['a125'] = 788;
  15065. t['a126'] = 788;
  15066. t['a127'] = 788;
  15067. t['a128'] = 788;
  15068. t['a129'] = 788;
  15069. t['a130'] = 788;
  15070. t['a131'] = 788;
  15071. t['a132'] = 788;
  15072. t['a133'] = 788;
  15073. t['a134'] = 788;
  15074. t['a135'] = 788;
  15075. t['a136'] = 788;
  15076. t['a137'] = 788;
  15077. t['a138'] = 788;
  15078. t['a139'] = 788;
  15079. t['a140'] = 788;
  15080. t['a141'] = 788;
  15081. t['a142'] = 788;
  15082. t['a143'] = 788;
  15083. t['a144'] = 788;
  15084. t['a145'] = 788;
  15085. t['a146'] = 788;
  15086. t['a147'] = 788;
  15087. t['a148'] = 788;
  15088. t['a149'] = 788;
  15089. t['a150'] = 788;
  15090. t['a151'] = 788;
  15091. t['a152'] = 788;
  15092. t['a153'] = 788;
  15093. t['a154'] = 788;
  15094. t['a155'] = 788;
  15095. t['a156'] = 788;
  15096. t['a157'] = 788;
  15097. t['a158'] = 788;
  15098. t['a159'] = 788;
  15099. t['a160'] = 894;
  15100. t['a161'] = 838;
  15101. t['a163'] = 1016;
  15102. t['a164'] = 458;
  15103. t['a196'] = 748;
  15104. t['a165'] = 924;
  15105. t['a192'] = 748;
  15106. t['a166'] = 918;
  15107. t['a167'] = 927;
  15108. t['a168'] = 928;
  15109. t['a169'] = 928;
  15110. t['a170'] = 834;
  15111. t['a171'] = 873;
  15112. t['a172'] = 828;
  15113. t['a173'] = 924;
  15114. t['a162'] = 924;
  15115. t['a174'] = 917;
  15116. t['a175'] = 930;
  15117. t['a176'] = 931;
  15118. t['a177'] = 463;
  15119. t['a178'] = 883;
  15120. t['a179'] = 836;
  15121. t['a193'] = 836;
  15122. t['a180'] = 867;
  15123. t['a199'] = 867;
  15124. t['a181'] = 696;
  15125. t['a200'] = 696;
  15126. t['a182'] = 874;
  15127. t['a201'] = 874;
  15128. t['a183'] = 760;
  15129. t['a184'] = 946;
  15130. t['a197'] = 771;
  15131. t['a185'] = 865;
  15132. t['a194'] = 771;
  15133. t['a198'] = 888;
  15134. t['a186'] = 967;
  15135. t['a195'] = 888;
  15136. t['a187'] = 831;
  15137. t['a188'] = 873;
  15138. t['a189'] = 927;
  15139. t['a190'] = 970;
  15140. t['a191'] = 918;
  15141. });
  15142. });
  15143. exports.getMetrics = getMetrics;
  15144. }));
  15145. (function (root, factory) {
  15146. {
  15147. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  15148. }
  15149. }(this, function (exports, sharedUtil) {
  15150. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  15151. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  15152. // Workaround for missing math precison in JS.
  15153. var MASK_HIGH = 0xffff0000;
  15154. var MASK_LOW = 0xffff;
  15155. function MurmurHash3_64 (seed) {
  15156. var SEED = 0xc3d2e1f0;
  15157. this.h1 = seed ? seed & 0xffffffff : SEED;
  15158. this.h2 = seed ? seed & 0xffffffff : SEED;
  15159. }
  15160. var alwaysUseUint32ArrayView = false;
  15161. // old webkits have issues with non-aligned arrays
  15162. try {
  15163. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  15164. } catch (e) {
  15165. alwaysUseUint32ArrayView = true;
  15166. }
  15167. MurmurHash3_64.prototype = {
  15168. update: function MurmurHash3_64_update(input) {
  15169. var useUint32ArrayView = alwaysUseUint32ArrayView;
  15170. var i;
  15171. if (typeof input === 'string') {
  15172. var data = new Uint8Array(input.length * 2);
  15173. var length = 0;
  15174. for (i = 0; i < input.length; i++) {
  15175. var code = input.charCodeAt(i);
  15176. if (code <= 0xff) {
  15177. data[length++] = code;
  15178. }
  15179. else {
  15180. data[length++] = code >>> 8;
  15181. data[length++] = code & 0xff;
  15182. }
  15183. }
  15184. } else if (input instanceof Uint8Array) {
  15185. data = input;
  15186. length = data.length;
  15187. } else if (typeof input === 'object' && ('length' in input)) {
  15188. // processing regular arrays as well, e.g. for IE9
  15189. data = input;
  15190. length = data.length;
  15191. useUint32ArrayView = true;
  15192. } else {
  15193. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  15194. 'Input must be a string or array.');
  15195. }
  15196. var blockCounts = length >> 2;
  15197. var tailLength = length - blockCounts * 4;
  15198. // we don't care about endianness here
  15199. var dataUint32 = useUint32ArrayView ?
  15200. new Uint32ArrayView(data, blockCounts) :
  15201. new Uint32Array(data.buffer, 0, blockCounts);
  15202. var k1 = 0;
  15203. var k2 = 0;
  15204. var h1 = this.h1;
  15205. var h2 = this.h2;
  15206. var C1 = 0xcc9e2d51;
  15207. var C2 = 0x1b873593;
  15208. var C1_LOW = C1 & MASK_LOW;
  15209. var C2_LOW = C2 & MASK_LOW;
  15210. for (i = 0; i < blockCounts; i++) {
  15211. if (i & 1) {
  15212. k1 = dataUint32[i];
  15213. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15214. k1 = k1 << 15 | k1 >>> 17;
  15215. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15216. h1 ^= k1;
  15217. h1 = h1 << 13 | h1 >>> 19;
  15218. h1 = h1 * 5 + 0xe6546b64;
  15219. } else {
  15220. k2 = dataUint32[i];
  15221. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  15222. k2 = k2 << 15 | k2 >>> 17;
  15223. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  15224. h2 ^= k2;
  15225. h2 = h2 << 13 | h2 >>> 19;
  15226. h2 = h2 * 5 + 0xe6546b64;
  15227. }
  15228. }
  15229. k1 = 0;
  15230. switch (tailLength) {
  15231. case 3:
  15232. k1 ^= data[blockCounts * 4 + 2] << 16;
  15233. /* falls through */
  15234. case 2:
  15235. k1 ^= data[blockCounts * 4 + 1] << 8;
  15236. /* falls through */
  15237. case 1:
  15238. k1 ^= data[blockCounts * 4];
  15239. /* falls through */
  15240. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15241. k1 = k1 << 15 | k1 >>> 17;
  15242. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15243. if (blockCounts & 1) {
  15244. h1 ^= k1;
  15245. } else {
  15246. h2 ^= k1;
  15247. }
  15248. }
  15249. this.h1 = h1;
  15250. this.h2 = h2;
  15251. return this;
  15252. },
  15253. hexdigest: function MurmurHash3_64_hexdigest () {
  15254. var h1 = this.h1;
  15255. var h2 = this.h2;
  15256. h1 ^= h2 >>> 1;
  15257. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15258. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15259. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15260. h1 ^= h2 >>> 1;
  15261. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15262. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15263. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15264. h1 ^= h2 >>> 1;
  15265. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15266. var hex = (arr[i] >>> 0).toString(16);
  15267. while (hex.length < 8) {
  15268. hex = '0' + hex;
  15269. }
  15270. str += hex;
  15271. }
  15272. return str;
  15273. }
  15274. };
  15275. return MurmurHash3_64;
  15276. })();
  15277. exports.MurmurHash3_64 = MurmurHash3_64;
  15278. }));
  15279. (function (root, factory) {
  15280. {
  15281. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15282. }
  15283. }(this, function (exports, sharedUtil) {
  15284. var isArray = sharedUtil.isArray;
  15285. var Name = (function NameClosure() {
  15286. function Name(name) {
  15287. this.name = name;
  15288. }
  15289. Name.prototype = {};
  15290. var nameCache = Object.create(null);
  15291. Name.get = function Name_get(name) {
  15292. var nameValue = nameCache[name];
  15293. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15294. };
  15295. return Name;
  15296. })();
  15297. var Cmd = (function CmdClosure() {
  15298. function Cmd(cmd) {
  15299. this.cmd = cmd;
  15300. }
  15301. Cmd.prototype = {};
  15302. var cmdCache = Object.create(null);
  15303. Cmd.get = function Cmd_get(cmd) {
  15304. var cmdValue = cmdCache[cmd];
  15305. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15306. };
  15307. return Cmd;
  15308. })();
  15309. var Dict = (function DictClosure() {
  15310. var nonSerializable = function nonSerializableClosure() {
  15311. return nonSerializable; // creating closure on some variable
  15312. };
  15313. // xref is optional
  15314. function Dict(xref) {
  15315. // Map should only be used internally, use functions below to access.
  15316. this.map = Object.create(null);
  15317. this.xref = xref;
  15318. this.objId = null;
  15319. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15320. }
  15321. Dict.prototype = {
  15322. assignXref: function Dict_assignXref(newXref) {
  15323. this.xref = newXref;
  15324. },
  15325. // automatically dereferences Ref objects
  15326. get: function Dict_get(key1, key2, key3) {
  15327. var value;
  15328. var xref = this.xref;
  15329. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15330. typeof key2 === 'undefined') {
  15331. return xref ? xref.fetchIfRef(value) : value;
  15332. }
  15333. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15334. typeof key3 === 'undefined') {
  15335. return xref ? xref.fetchIfRef(value) : value;
  15336. }
  15337. value = this.map[key3] || null;
  15338. return xref ? xref.fetchIfRef(value) : value;
  15339. },
  15340. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15341. getAsync: function Dict_getAsync(key1, key2, key3) {
  15342. var value;
  15343. var xref = this.xref;
  15344. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15345. typeof key2 === 'undefined') {
  15346. if (xref) {
  15347. return xref.fetchIfRefAsync(value);
  15348. }
  15349. return Promise.resolve(value);
  15350. }
  15351. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15352. typeof key3 === 'undefined') {
  15353. if (xref) {
  15354. return xref.fetchIfRefAsync(value);
  15355. }
  15356. return Promise.resolve(value);
  15357. }
  15358. value = this.map[key3] || null;
  15359. if (xref) {
  15360. return xref.fetchIfRefAsync(value);
  15361. }
  15362. return Promise.resolve(value);
  15363. },
  15364. // Same as get(), but dereferences all elements if the result is an Array.
  15365. getArray: function Dict_getArray(key1, key2, key3) {
  15366. var value = this.get(key1, key2, key3);
  15367. var xref = this.xref;
  15368. if (!isArray(value) || !xref) {
  15369. return value;
  15370. }
  15371. value = value.slice(); // Ensure that we don't modify the Dict data.
  15372. for (var i = 0, ii = value.length; i < ii; i++) {
  15373. if (!isRef(value[i])) {
  15374. continue;
  15375. }
  15376. value[i] = xref.fetch(value[i]);
  15377. }
  15378. return value;
  15379. },
  15380. // no dereferencing
  15381. getRaw: function Dict_getRaw(key) {
  15382. return this.map[key];
  15383. },
  15384. getKeys: function Dict_getKeys() {
  15385. return Object.keys(this.map);
  15386. },
  15387. set: function Dict_set(key, value) {
  15388. this.map[key] = value;
  15389. },
  15390. has: function Dict_has(key) {
  15391. return key in this.map;
  15392. },
  15393. forEach: function Dict_forEach(callback) {
  15394. for (var key in this.map) {
  15395. callback(key, this.get(key));
  15396. }
  15397. }
  15398. };
  15399. Dict.empty = new Dict(null);
  15400. Dict.merge = function Dict_merge(xref, dictArray) {
  15401. var mergedDict = new Dict(xref);
  15402. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15403. var dict = dictArray[i];
  15404. if (!isDict(dict)) {
  15405. continue;
  15406. }
  15407. for (var keyName in dict.map) {
  15408. if (mergedDict.map[keyName]) {
  15409. continue;
  15410. }
  15411. mergedDict.map[keyName] = dict.map[keyName];
  15412. }
  15413. }
  15414. return mergedDict;
  15415. };
  15416. return Dict;
  15417. })();
  15418. var Ref = (function RefClosure() {
  15419. function Ref(num, gen) {
  15420. this.num = num;
  15421. this.gen = gen;
  15422. }
  15423. Ref.prototype = {
  15424. toString: function Ref_toString() {
  15425. // This function is hot, so we make the string as compact as possible.
  15426. // |this.gen| is almost always zero, so we treat that case specially.
  15427. var str = this.num + 'R';
  15428. if (this.gen !== 0) {
  15429. str += this.gen;
  15430. }
  15431. return str;
  15432. }
  15433. };
  15434. return Ref;
  15435. })();
  15436. // The reference is identified by number and generation.
  15437. // This structure stores only one instance of the reference.
  15438. var RefSet = (function RefSetClosure() {
  15439. function RefSet() {
  15440. this.dict = Object.create(null);
  15441. }
  15442. RefSet.prototype = {
  15443. has: function RefSet_has(ref) {
  15444. return ref.toString() in this.dict;
  15445. },
  15446. put: function RefSet_put(ref) {
  15447. this.dict[ref.toString()] = true;
  15448. },
  15449. remove: function RefSet_remove(ref) {
  15450. delete this.dict[ref.toString()];
  15451. }
  15452. };
  15453. return RefSet;
  15454. })();
  15455. var RefSetCache = (function RefSetCacheClosure() {
  15456. function RefSetCache() {
  15457. this.dict = Object.create(null);
  15458. }
  15459. RefSetCache.prototype = {
  15460. get: function RefSetCache_get(ref) {
  15461. return this.dict[ref.toString()];
  15462. },
  15463. has: function RefSetCache_has(ref) {
  15464. return ref.toString() in this.dict;
  15465. },
  15466. put: function RefSetCache_put(ref, obj) {
  15467. this.dict[ref.toString()] = obj;
  15468. },
  15469. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15470. this.dict[ref.toString()] = this.get(aliasRef);
  15471. },
  15472. forEach: function RefSetCache_forEach(fn, thisArg) {
  15473. for (var i in this.dict) {
  15474. fn.call(thisArg, this.dict[i]);
  15475. }
  15476. },
  15477. clear: function RefSetCache_clear() {
  15478. this.dict = Object.create(null);
  15479. }
  15480. };
  15481. return RefSetCache;
  15482. })();
  15483. function isName(v) {
  15484. return v instanceof Name;
  15485. }
  15486. function isCmd(v, cmd) {
  15487. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15488. }
  15489. function isDict(v, type) {
  15490. if (!(v instanceof Dict)) {
  15491. return false;
  15492. }
  15493. if (!type) {
  15494. return true;
  15495. }
  15496. var dictType = v.get('Type');
  15497. return isName(dictType) && dictType.name === type;
  15498. }
  15499. function isRef(v) {
  15500. return v instanceof Ref;
  15501. }
  15502. function isStream(v) {
  15503. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15504. }
  15505. exports.Cmd = Cmd;
  15506. exports.Dict = Dict;
  15507. exports.Name = Name;
  15508. exports.Ref = Ref;
  15509. exports.RefSet = RefSet;
  15510. exports.RefSetCache = RefSetCache;
  15511. exports.isCmd = isCmd;
  15512. exports.isDict = isDict;
  15513. exports.isName = isName;
  15514. exports.isRef = isRef;
  15515. exports.isStream = isStream;
  15516. }));
  15517. (function (root, factory) {
  15518. {
  15519. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  15520. }
  15521. }(this, function (exports, sharedUtil) {
  15522. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15523. /**
  15524. * Hold a map of decoded fonts and of the standard fourteen Type1
  15525. * fonts and their acronyms.
  15526. */
  15527. var getStdFontMap = getLookupTableFactory(function (t) {
  15528. t['ArialNarrow'] = 'Helvetica';
  15529. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  15530. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  15531. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  15532. t['ArialBlack'] = 'Helvetica';
  15533. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  15534. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  15535. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  15536. t['Arial'] = 'Helvetica';
  15537. t['Arial-Bold'] = 'Helvetica-Bold';
  15538. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  15539. t['Arial-Italic'] = 'Helvetica-Oblique';
  15540. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  15541. t['Arial-BoldMT'] = 'Helvetica-Bold';
  15542. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  15543. t['ArialMT'] = 'Helvetica';
  15544. t['Courier-Bold'] = 'Courier-Bold';
  15545. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  15546. t['Courier-Italic'] = 'Courier-Oblique';
  15547. t['CourierNew'] = 'Courier';
  15548. t['CourierNew-Bold'] = 'Courier-Bold';
  15549. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  15550. t['CourierNew-Italic'] = 'Courier-Oblique';
  15551. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  15552. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  15553. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  15554. t['CourierNewPSMT'] = 'Courier';
  15555. t['Helvetica'] = 'Helvetica';
  15556. t['Helvetica-Bold'] = 'Helvetica-Bold';
  15557. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  15558. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  15559. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  15560. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  15561. t['Symbol-Bold'] = 'Symbol';
  15562. t['Symbol-BoldItalic'] = 'Symbol';
  15563. t['Symbol-Italic'] = 'Symbol';
  15564. t['TimesNewRoman'] = 'Times-Roman';
  15565. t['TimesNewRoman-Bold'] = 'Times-Bold';
  15566. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  15567. t['TimesNewRoman-Italic'] = 'Times-Italic';
  15568. t['TimesNewRomanPS'] = 'Times-Roman';
  15569. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  15570. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  15571. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  15572. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  15573. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  15574. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  15575. t['TimesNewRomanPSMT'] = 'Times-Roman';
  15576. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  15577. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  15578. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  15579. });
  15580. /**
  15581. * Holds the map of the non-standard fonts that might be included as
  15582. * a standard fonts without glyph data.
  15583. */
  15584. var getNonStdFontMap = getLookupTableFactory(function (t) {
  15585. t['CenturyGothic'] = 'Helvetica';
  15586. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  15587. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  15588. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  15589. t['ComicSansMS'] = 'Comic Sans MS';
  15590. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  15591. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  15592. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  15593. t['LucidaConsole'] = 'Courier';
  15594. t['LucidaConsole-Bold'] = 'Courier-Bold';
  15595. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  15596. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  15597. t['MS-Gothic'] = 'MS Gothic';
  15598. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  15599. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  15600. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  15601. t['MS-Mincho'] = 'MS Mincho';
  15602. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  15603. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  15604. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  15605. t['MS-PGothic'] = 'MS PGothic';
  15606. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  15607. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  15608. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  15609. t['MS-PMincho'] = 'MS PMincho';
  15610. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  15611. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  15612. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  15613. t['Wingdings'] = 'ZapfDingbats';
  15614. });
  15615. var getSerifFonts = getLookupTableFactory(function (t) {
  15616. t['Adobe Jenson'] = true;
  15617. t['Adobe Text'] = true;
  15618. t['Albertus'] = true;
  15619. t['Aldus'] = true;
  15620. t['Alexandria'] = true;
  15621. t['Algerian'] = true;
  15622. t['American Typewriter'] = true;
  15623. t['Antiqua'] = true;
  15624. t['Apex'] = true;
  15625. t['Arno'] = true;
  15626. t['Aster'] = true;
  15627. t['Aurora'] = true;
  15628. t['Baskerville'] = true;
  15629. t['Bell'] = true;
  15630. t['Bembo'] = true;
  15631. t['Bembo Schoolbook'] = true;
  15632. t['Benguiat'] = true;
  15633. t['Berkeley Old Style'] = true;
  15634. t['Bernhard Modern'] = true;
  15635. t['Berthold City'] = true;
  15636. t['Bodoni'] = true;
  15637. t['Bauer Bodoni'] = true;
  15638. t['Book Antiqua'] = true;
  15639. t['Bookman'] = true;
  15640. t['Bordeaux Roman'] = true;
  15641. t['Californian FB'] = true;
  15642. t['Calisto'] = true;
  15643. t['Calvert'] = true;
  15644. t['Capitals'] = true;
  15645. t['Cambria'] = true;
  15646. t['Cartier'] = true;
  15647. t['Caslon'] = true;
  15648. t['Catull'] = true;
  15649. t['Centaur'] = true;
  15650. t['Century Old Style'] = true;
  15651. t['Century Schoolbook'] = true;
  15652. t['Chaparral'] = true;
  15653. t['Charis SIL'] = true;
  15654. t['Cheltenham'] = true;
  15655. t['Cholla Slab'] = true;
  15656. t['Clarendon'] = true;
  15657. t['Clearface'] = true;
  15658. t['Cochin'] = true;
  15659. t['Colonna'] = true;
  15660. t['Computer Modern'] = true;
  15661. t['Concrete Roman'] = true;
  15662. t['Constantia'] = true;
  15663. t['Cooper Black'] = true;
  15664. t['Corona'] = true;
  15665. t['Ecotype'] = true;
  15666. t['Egyptienne'] = true;
  15667. t['Elephant'] = true;
  15668. t['Excelsior'] = true;
  15669. t['Fairfield'] = true;
  15670. t['FF Scala'] = true;
  15671. t['Folkard'] = true;
  15672. t['Footlight'] = true;
  15673. t['FreeSerif'] = true;
  15674. t['Friz Quadrata'] = true;
  15675. t['Garamond'] = true;
  15676. t['Gentium'] = true;
  15677. t['Georgia'] = true;
  15678. t['Gloucester'] = true;
  15679. t['Goudy Old Style'] = true;
  15680. t['Goudy Schoolbook'] = true;
  15681. t['Goudy Pro Font'] = true;
  15682. t['Granjon'] = true;
  15683. t['Guardian Egyptian'] = true;
  15684. t['Heather'] = true;
  15685. t['Hercules'] = true;
  15686. t['High Tower Text'] = true;
  15687. t['Hiroshige'] = true;
  15688. t['Hoefler Text'] = true;
  15689. t['Humana Serif'] = true;
  15690. t['Imprint'] = true;
  15691. t['Ionic No. 5'] = true;
  15692. t['Janson'] = true;
  15693. t['Joanna'] = true;
  15694. t['Korinna'] = true;
  15695. t['Lexicon'] = true;
  15696. t['Liberation Serif'] = true;
  15697. t['Linux Libertine'] = true;
  15698. t['Literaturnaya'] = true;
  15699. t['Lucida'] = true;
  15700. t['Lucida Bright'] = true;
  15701. t['Melior'] = true;
  15702. t['Memphis'] = true;
  15703. t['Miller'] = true;
  15704. t['Minion'] = true;
  15705. t['Modern'] = true;
  15706. t['Mona Lisa'] = true;
  15707. t['Mrs Eaves'] = true;
  15708. t['MS Serif'] = true;
  15709. t['Museo Slab'] = true;
  15710. t['New York'] = true;
  15711. t['Nimbus Roman'] = true;
  15712. t['NPS Rawlinson Roadway'] = true;
  15713. t['Palatino'] = true;
  15714. t['Perpetua'] = true;
  15715. t['Plantin'] = true;
  15716. t['Plantin Schoolbook'] = true;
  15717. t['Playbill'] = true;
  15718. t['Poor Richard'] = true;
  15719. t['Rawlinson Roadway'] = true;
  15720. t['Renault'] = true;
  15721. t['Requiem'] = true;
  15722. t['Rockwell'] = true;
  15723. t['Roman'] = true;
  15724. t['Rotis Serif'] = true;
  15725. t['Sabon'] = true;
  15726. t['Scala'] = true;
  15727. t['Seagull'] = true;
  15728. t['Sistina'] = true;
  15729. t['Souvenir'] = true;
  15730. t['STIX'] = true;
  15731. t['Stone Informal'] = true;
  15732. t['Stone Serif'] = true;
  15733. t['Sylfaen'] = true;
  15734. t['Times'] = true;
  15735. t['Trajan'] = true;
  15736. t['Trinité'] = true;
  15737. t['Trump Mediaeval'] = true;
  15738. t['Utopia'] = true;
  15739. t['Vale Type'] = true;
  15740. t['Bitstream Vera'] = true;
  15741. t['Vera Serif'] = true;
  15742. t['Versailles'] = true;
  15743. t['Wanted'] = true;
  15744. t['Weiss'] = true;
  15745. t['Wide Latin'] = true;
  15746. t['Windsor'] = true;
  15747. t['XITS'] = true;
  15748. });
  15749. var getSymbolsFonts = getLookupTableFactory(function (t) {
  15750. t['Dingbats'] = true;
  15751. t['Symbol'] = true;
  15752. t['ZapfDingbats'] = true;
  15753. });
  15754. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  15755. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  15756. // for all glyphs, but common for some set of the standard fonts.
  15757. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  15758. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  15759. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  15760. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  15761. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  15762. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  15763. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  15764. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  15765. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  15766. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  15767. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  15768. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  15769. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  15770. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  15771. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  15772. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  15773. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  15774. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  15775. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  15776. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  15777. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  15778. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  15779. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  15780. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  15781. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  15782. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  15783. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  15784. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  15785. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  15786. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  15787. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  15788. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  15789. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  15790. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  15791. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  15792. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  15793. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  15794. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  15795. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  15796. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  15797. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  15798. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  15799. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  15800. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  15801. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  15802. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  15803. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  15804. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  15805. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  15806. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  15807. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  15808. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  15809. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  15810. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  15811. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  15812. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  15813. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  15814. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  15815. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  15816. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  15817. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  15818. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  15819. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  15820. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  15821. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  15822. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  15823. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  15824. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  15825. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  15826. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  15827. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  15828. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  15829. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  15830. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  15831. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  15832. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  15833. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  15834. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  15835. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  15836. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  15837. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  15838. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  15839. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  15840. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  15841. t[3416] = 8377;
  15842. });
  15843. // The glyph map for ArialBlack differs slightly from the glyph map used for
  15844. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  15845. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  15846. var getSupplementalGlyphMapForArialBlack =
  15847. getLookupTableFactory(function (t) {
  15848. t[227] = 322; t[264] = 261; t[291] = 346;
  15849. });
  15850. exports.getStdFontMap = getStdFontMap;
  15851. exports.getNonStdFontMap = getNonStdFontMap;
  15852. exports.getSerifFonts = getSerifFonts;
  15853. exports.getSymbolsFonts = getSymbolsFonts;
  15854. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  15855. exports.getSupplementalGlyphMapForArialBlack =
  15856. getSupplementalGlyphMapForArialBlack;
  15857. }));
  15858. (function (root, factory) {
  15859. {
  15860. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  15861. }
  15862. }(this, function (exports, sharedUtil) {
  15863. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15864. // Some characters, e.g. copyrightserif, are mapped to the private use area
  15865. // and might not be displayed using standard fonts. Mapping/hacking well-known
  15866. // chars to the similar equivalents in the normal characters range.
  15867. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  15868. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  15869. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  15870. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  15871. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  15872. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  15873. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  15874. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  15875. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  15876. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  15877. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  15878. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  15879. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  15880. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  15881. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  15882. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  15883. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  15884. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  15885. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  15886. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  15887. t[63724] = 0x239C; // parenleftex (0xF8EC)
  15888. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  15889. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  15890. t[63735] = 0x239F; // parenrightex (0xF8F7)
  15891. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  15892. });
  15893. function mapSpecialUnicodeValues(code) {
  15894. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  15895. return 0;
  15896. } else if (code >= 0xF600 && code <= 0xF8FF) {
  15897. return (getSpecialPUASymbols()[code] || code);
  15898. }
  15899. return code;
  15900. }
  15901. var UnicodeRanges = [
  15902. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  15903. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  15904. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  15905. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  15906. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  15907. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  15908. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  15909. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  15910. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  15911. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  15912. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  15913. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  15914. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  15915. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  15916. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  15917. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  15918. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  15919. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  15920. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  15921. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  15922. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  15923. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  15924. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  15925. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  15926. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  15927. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  15928. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  15929. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  15930. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  15931. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  15932. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  15933. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  15934. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  15935. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  15936. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  15937. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  15938. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  15939. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  15940. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  15941. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  15942. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  15943. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  15944. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  15945. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  15946. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  15947. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  15948. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  15949. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  15950. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  15951. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  15952. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  15953. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  15954. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  15955. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  15956. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  15957. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  15958. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  15959. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  15960. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  15961. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  15962. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  15963. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  15964. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  15965. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  15966. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  15967. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  15968. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  15969. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  15970. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  15971. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  15972. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  15973. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  15974. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  15975. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  15976. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  15977. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  15978. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  15979. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  15980. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  15981. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  15982. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  15983. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  15984. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  15985. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  15986. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  15987. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  15988. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  15989. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  15990. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  15991. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  15992. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  15993. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  15994. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  15995. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  15996. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  15997. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  15998. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  15999. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  16000. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  16001. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  16002. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  16003. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  16004. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  16005. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  16006. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  16007. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  16008. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  16009. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  16010. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  16011. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  16012. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  16013. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  16014. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  16015. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  16016. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  16017. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  16018. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  16019. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  16020. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  16021. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  16022. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  16023. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  16024. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  16025. ];
  16026. function getUnicodeRangeFor(value) {
  16027. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  16028. var range = UnicodeRanges[i];
  16029. if (value >= range.begin && value < range.end) {
  16030. return i;
  16031. }
  16032. }
  16033. return -1;
  16034. }
  16035. function isRTLRangeFor(value) {
  16036. var range = UnicodeRanges[13];
  16037. if (value >= range.begin && value < range.end) {
  16038. return true;
  16039. }
  16040. range = UnicodeRanges[11];
  16041. if (value >= range.begin && value < range.end) {
  16042. return true;
  16043. }
  16044. return false;
  16045. }
  16046. // The normalization table is obtained by filtering the Unicode characters
  16047. // database with <compat> entries.
  16048. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  16049. t['\u00A8'] = '\u0020\u0308';
  16050. t['\u00AF'] = '\u0020\u0304';
  16051. t['\u00B4'] = '\u0020\u0301';
  16052. t['\u00B5'] = '\u03BC';
  16053. t['\u00B8'] = '\u0020\u0327';
  16054. t['\u0132'] = '\u0049\u004A';
  16055. t['\u0133'] = '\u0069\u006A';
  16056. t['\u013F'] = '\u004C\u00B7';
  16057. t['\u0140'] = '\u006C\u00B7';
  16058. t['\u0149'] = '\u02BC\u006E';
  16059. t['\u017F'] = '\u0073';
  16060. t['\u01C4'] = '\u0044\u017D';
  16061. t['\u01C5'] = '\u0044\u017E';
  16062. t['\u01C6'] = '\u0064\u017E';
  16063. t['\u01C7'] = '\u004C\u004A';
  16064. t['\u01C8'] = '\u004C\u006A';
  16065. t['\u01C9'] = '\u006C\u006A';
  16066. t['\u01CA'] = '\u004E\u004A';
  16067. t['\u01CB'] = '\u004E\u006A';
  16068. t['\u01CC'] = '\u006E\u006A';
  16069. t['\u01F1'] = '\u0044\u005A';
  16070. t['\u01F2'] = '\u0044\u007A';
  16071. t['\u01F3'] = '\u0064\u007A';
  16072. t['\u02D8'] = '\u0020\u0306';
  16073. t['\u02D9'] = '\u0020\u0307';
  16074. t['\u02DA'] = '\u0020\u030A';
  16075. t['\u02DB'] = '\u0020\u0328';
  16076. t['\u02DC'] = '\u0020\u0303';
  16077. t['\u02DD'] = '\u0020\u030B';
  16078. t['\u037A'] = '\u0020\u0345';
  16079. t['\u0384'] = '\u0020\u0301';
  16080. t['\u03D0'] = '\u03B2';
  16081. t['\u03D1'] = '\u03B8';
  16082. t['\u03D2'] = '\u03A5';
  16083. t['\u03D5'] = '\u03C6';
  16084. t['\u03D6'] = '\u03C0';
  16085. t['\u03F0'] = '\u03BA';
  16086. t['\u03F1'] = '\u03C1';
  16087. t['\u03F2'] = '\u03C2';
  16088. t['\u03F4'] = '\u0398';
  16089. t['\u03F5'] = '\u03B5';
  16090. t['\u03F9'] = '\u03A3';
  16091. t['\u0587'] = '\u0565\u0582';
  16092. t['\u0675'] = '\u0627\u0674';
  16093. t['\u0676'] = '\u0648\u0674';
  16094. t['\u0677'] = '\u06C7\u0674';
  16095. t['\u0678'] = '\u064A\u0674';
  16096. t['\u0E33'] = '\u0E4D\u0E32';
  16097. t['\u0EB3'] = '\u0ECD\u0EB2';
  16098. t['\u0EDC'] = '\u0EAB\u0E99';
  16099. t['\u0EDD'] = '\u0EAB\u0EA1';
  16100. t['\u0F77'] = '\u0FB2\u0F81';
  16101. t['\u0F79'] = '\u0FB3\u0F81';
  16102. t['\u1E9A'] = '\u0061\u02BE';
  16103. t['\u1FBD'] = '\u0020\u0313';
  16104. t['\u1FBF'] = '\u0020\u0313';
  16105. t['\u1FC0'] = '\u0020\u0342';
  16106. t['\u1FFE'] = '\u0020\u0314';
  16107. t['\u2002'] = '\u0020';
  16108. t['\u2003'] = '\u0020';
  16109. t['\u2004'] = '\u0020';
  16110. t['\u2005'] = '\u0020';
  16111. t['\u2006'] = '\u0020';
  16112. t['\u2008'] = '\u0020';
  16113. t['\u2009'] = '\u0020';
  16114. t['\u200A'] = '\u0020';
  16115. t['\u2017'] = '\u0020\u0333';
  16116. t['\u2024'] = '\u002E';
  16117. t['\u2025'] = '\u002E\u002E';
  16118. t['\u2026'] = '\u002E\u002E\u002E';
  16119. t['\u2033'] = '\u2032\u2032';
  16120. t['\u2034'] = '\u2032\u2032\u2032';
  16121. t['\u2036'] = '\u2035\u2035';
  16122. t['\u2037'] = '\u2035\u2035\u2035';
  16123. t['\u203C'] = '\u0021\u0021';
  16124. t['\u203E'] = '\u0020\u0305';
  16125. t['\u2047'] = '\u003F\u003F';
  16126. t['\u2048'] = '\u003F\u0021';
  16127. t['\u2049'] = '\u0021\u003F';
  16128. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  16129. t['\u205F'] = '\u0020';
  16130. t['\u20A8'] = '\u0052\u0073';
  16131. t['\u2100'] = '\u0061\u002F\u0063';
  16132. t['\u2101'] = '\u0061\u002F\u0073';
  16133. t['\u2103'] = '\u00B0\u0043';
  16134. t['\u2105'] = '\u0063\u002F\u006F';
  16135. t['\u2106'] = '\u0063\u002F\u0075';
  16136. t['\u2107'] = '\u0190';
  16137. t['\u2109'] = '\u00B0\u0046';
  16138. t['\u2116'] = '\u004E\u006F';
  16139. t['\u2121'] = '\u0054\u0045\u004C';
  16140. t['\u2135'] = '\u05D0';
  16141. t['\u2136'] = '\u05D1';
  16142. t['\u2137'] = '\u05D2';
  16143. t['\u2138'] = '\u05D3';
  16144. t['\u213B'] = '\u0046\u0041\u0058';
  16145. t['\u2160'] = '\u0049';
  16146. t['\u2161'] = '\u0049\u0049';
  16147. t['\u2162'] = '\u0049\u0049\u0049';
  16148. t['\u2163'] = '\u0049\u0056';
  16149. t['\u2164'] = '\u0056';
  16150. t['\u2165'] = '\u0056\u0049';
  16151. t['\u2166'] = '\u0056\u0049\u0049';
  16152. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  16153. t['\u2168'] = '\u0049\u0058';
  16154. t['\u2169'] = '\u0058';
  16155. t['\u216A'] = '\u0058\u0049';
  16156. t['\u216B'] = '\u0058\u0049\u0049';
  16157. t['\u216C'] = '\u004C';
  16158. t['\u216D'] = '\u0043';
  16159. t['\u216E'] = '\u0044';
  16160. t['\u216F'] = '\u004D';
  16161. t['\u2170'] = '\u0069';
  16162. t['\u2171'] = '\u0069\u0069';
  16163. t['\u2172'] = '\u0069\u0069\u0069';
  16164. t['\u2173'] = '\u0069\u0076';
  16165. t['\u2174'] = '\u0076';
  16166. t['\u2175'] = '\u0076\u0069';
  16167. t['\u2176'] = '\u0076\u0069\u0069';
  16168. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  16169. t['\u2178'] = '\u0069\u0078';
  16170. t['\u2179'] = '\u0078';
  16171. t['\u217A'] = '\u0078\u0069';
  16172. t['\u217B'] = '\u0078\u0069\u0069';
  16173. t['\u217C'] = '\u006C';
  16174. t['\u217D'] = '\u0063';
  16175. t['\u217E'] = '\u0064';
  16176. t['\u217F'] = '\u006D';
  16177. t['\u222C'] = '\u222B\u222B';
  16178. t['\u222D'] = '\u222B\u222B\u222B';
  16179. t['\u222F'] = '\u222E\u222E';
  16180. t['\u2230'] = '\u222E\u222E\u222E';
  16181. t['\u2474'] = '\u0028\u0031\u0029';
  16182. t['\u2475'] = '\u0028\u0032\u0029';
  16183. t['\u2476'] = '\u0028\u0033\u0029';
  16184. t['\u2477'] = '\u0028\u0034\u0029';
  16185. t['\u2478'] = '\u0028\u0035\u0029';
  16186. t['\u2479'] = '\u0028\u0036\u0029';
  16187. t['\u247A'] = '\u0028\u0037\u0029';
  16188. t['\u247B'] = '\u0028\u0038\u0029';
  16189. t['\u247C'] = '\u0028\u0039\u0029';
  16190. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  16191. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  16192. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  16193. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  16194. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  16195. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  16196. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  16197. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  16198. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  16199. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  16200. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  16201. t['\u2488'] = '\u0031\u002E';
  16202. t['\u2489'] = '\u0032\u002E';
  16203. t['\u248A'] = '\u0033\u002E';
  16204. t['\u248B'] = '\u0034\u002E';
  16205. t['\u248C'] = '\u0035\u002E';
  16206. t['\u248D'] = '\u0036\u002E';
  16207. t['\u248E'] = '\u0037\u002E';
  16208. t['\u248F'] = '\u0038\u002E';
  16209. t['\u2490'] = '\u0039\u002E';
  16210. t['\u2491'] = '\u0031\u0030\u002E';
  16211. t['\u2492'] = '\u0031\u0031\u002E';
  16212. t['\u2493'] = '\u0031\u0032\u002E';
  16213. t['\u2494'] = '\u0031\u0033\u002E';
  16214. t['\u2495'] = '\u0031\u0034\u002E';
  16215. t['\u2496'] = '\u0031\u0035\u002E';
  16216. t['\u2497'] = '\u0031\u0036\u002E';
  16217. t['\u2498'] = '\u0031\u0037\u002E';
  16218. t['\u2499'] = '\u0031\u0038\u002E';
  16219. t['\u249A'] = '\u0031\u0039\u002E';
  16220. t['\u249B'] = '\u0032\u0030\u002E';
  16221. t['\u249C'] = '\u0028\u0061\u0029';
  16222. t['\u249D'] = '\u0028\u0062\u0029';
  16223. t['\u249E'] = '\u0028\u0063\u0029';
  16224. t['\u249F'] = '\u0028\u0064\u0029';
  16225. t['\u24A0'] = '\u0028\u0065\u0029';
  16226. t['\u24A1'] = '\u0028\u0066\u0029';
  16227. t['\u24A2'] = '\u0028\u0067\u0029';
  16228. t['\u24A3'] = '\u0028\u0068\u0029';
  16229. t['\u24A4'] = '\u0028\u0069\u0029';
  16230. t['\u24A5'] = '\u0028\u006A\u0029';
  16231. t['\u24A6'] = '\u0028\u006B\u0029';
  16232. t['\u24A7'] = '\u0028\u006C\u0029';
  16233. t['\u24A8'] = '\u0028\u006D\u0029';
  16234. t['\u24A9'] = '\u0028\u006E\u0029';
  16235. t['\u24AA'] = '\u0028\u006F\u0029';
  16236. t['\u24AB'] = '\u0028\u0070\u0029';
  16237. t['\u24AC'] = '\u0028\u0071\u0029';
  16238. t['\u24AD'] = '\u0028\u0072\u0029';
  16239. t['\u24AE'] = '\u0028\u0073\u0029';
  16240. t['\u24AF'] = '\u0028\u0074\u0029';
  16241. t['\u24B0'] = '\u0028\u0075\u0029';
  16242. t['\u24B1'] = '\u0028\u0076\u0029';
  16243. t['\u24B2'] = '\u0028\u0077\u0029';
  16244. t['\u24B3'] = '\u0028\u0078\u0029';
  16245. t['\u24B4'] = '\u0028\u0079\u0029';
  16246. t['\u24B5'] = '\u0028\u007A\u0029';
  16247. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  16248. t['\u2A74'] = '\u003A\u003A\u003D';
  16249. t['\u2A75'] = '\u003D\u003D';
  16250. t['\u2A76'] = '\u003D\u003D\u003D';
  16251. t['\u2E9F'] = '\u6BCD';
  16252. t['\u2EF3'] = '\u9F9F';
  16253. t['\u2F00'] = '\u4E00';
  16254. t['\u2F01'] = '\u4E28';
  16255. t['\u2F02'] = '\u4E36';
  16256. t['\u2F03'] = '\u4E3F';
  16257. t['\u2F04'] = '\u4E59';
  16258. t['\u2F05'] = '\u4E85';
  16259. t['\u2F06'] = '\u4E8C';
  16260. t['\u2F07'] = '\u4EA0';
  16261. t['\u2F08'] = '\u4EBA';
  16262. t['\u2F09'] = '\u513F';
  16263. t['\u2F0A'] = '\u5165';
  16264. t['\u2F0B'] = '\u516B';
  16265. t['\u2F0C'] = '\u5182';
  16266. t['\u2F0D'] = '\u5196';
  16267. t['\u2F0E'] = '\u51AB';
  16268. t['\u2F0F'] = '\u51E0';
  16269. t['\u2F10'] = '\u51F5';
  16270. t['\u2F11'] = '\u5200';
  16271. t['\u2F12'] = '\u529B';
  16272. t['\u2F13'] = '\u52F9';
  16273. t['\u2F14'] = '\u5315';
  16274. t['\u2F15'] = '\u531A';
  16275. t['\u2F16'] = '\u5338';
  16276. t['\u2F17'] = '\u5341';
  16277. t['\u2F18'] = '\u535C';
  16278. t['\u2F19'] = '\u5369';
  16279. t['\u2F1A'] = '\u5382';
  16280. t['\u2F1B'] = '\u53B6';
  16281. t['\u2F1C'] = '\u53C8';
  16282. t['\u2F1D'] = '\u53E3';
  16283. t['\u2F1E'] = '\u56D7';
  16284. t['\u2F1F'] = '\u571F';
  16285. t['\u2F20'] = '\u58EB';
  16286. t['\u2F21'] = '\u5902';
  16287. t['\u2F22'] = '\u590A';
  16288. t['\u2F23'] = '\u5915';
  16289. t['\u2F24'] = '\u5927';
  16290. t['\u2F25'] = '\u5973';
  16291. t['\u2F26'] = '\u5B50';
  16292. t['\u2F27'] = '\u5B80';
  16293. t['\u2F28'] = '\u5BF8';
  16294. t['\u2F29'] = '\u5C0F';
  16295. t['\u2F2A'] = '\u5C22';
  16296. t['\u2F2B'] = '\u5C38';
  16297. t['\u2F2C'] = '\u5C6E';
  16298. t['\u2F2D'] = '\u5C71';
  16299. t['\u2F2E'] = '\u5DDB';
  16300. t['\u2F2F'] = '\u5DE5';
  16301. t['\u2F30'] = '\u5DF1';
  16302. t['\u2F31'] = '\u5DFE';
  16303. t['\u2F32'] = '\u5E72';
  16304. t['\u2F33'] = '\u5E7A';
  16305. t['\u2F34'] = '\u5E7F';
  16306. t['\u2F35'] = '\u5EF4';
  16307. t['\u2F36'] = '\u5EFE';
  16308. t['\u2F37'] = '\u5F0B';
  16309. t['\u2F38'] = '\u5F13';
  16310. t['\u2F39'] = '\u5F50';
  16311. t['\u2F3A'] = '\u5F61';
  16312. t['\u2F3B'] = '\u5F73';
  16313. t['\u2F3C'] = '\u5FC3';
  16314. t['\u2F3D'] = '\u6208';
  16315. t['\u2F3E'] = '\u6236';
  16316. t['\u2F3F'] = '\u624B';
  16317. t['\u2F40'] = '\u652F';
  16318. t['\u2F41'] = '\u6534';
  16319. t['\u2F42'] = '\u6587';
  16320. t['\u2F43'] = '\u6597';
  16321. t['\u2F44'] = '\u65A4';
  16322. t['\u2F45'] = '\u65B9';
  16323. t['\u2F46'] = '\u65E0';
  16324. t['\u2F47'] = '\u65E5';
  16325. t['\u2F48'] = '\u66F0';
  16326. t['\u2F49'] = '\u6708';
  16327. t['\u2F4A'] = '\u6728';
  16328. t['\u2F4B'] = '\u6B20';
  16329. t['\u2F4C'] = '\u6B62';
  16330. t['\u2F4D'] = '\u6B79';
  16331. t['\u2F4E'] = '\u6BB3';
  16332. t['\u2F4F'] = '\u6BCB';
  16333. t['\u2F50'] = '\u6BD4';
  16334. t['\u2F51'] = '\u6BDB';
  16335. t['\u2F52'] = '\u6C0F';
  16336. t['\u2F53'] = '\u6C14';
  16337. t['\u2F54'] = '\u6C34';
  16338. t['\u2F55'] = '\u706B';
  16339. t['\u2F56'] = '\u722A';
  16340. t['\u2F57'] = '\u7236';
  16341. t['\u2F58'] = '\u723B';
  16342. t['\u2F59'] = '\u723F';
  16343. t['\u2F5A'] = '\u7247';
  16344. t['\u2F5B'] = '\u7259';
  16345. t['\u2F5C'] = '\u725B';
  16346. t['\u2F5D'] = '\u72AC';
  16347. t['\u2F5E'] = '\u7384';
  16348. t['\u2F5F'] = '\u7389';
  16349. t['\u2F60'] = '\u74DC';
  16350. t['\u2F61'] = '\u74E6';
  16351. t['\u2F62'] = '\u7518';
  16352. t['\u2F63'] = '\u751F';
  16353. t['\u2F64'] = '\u7528';
  16354. t['\u2F65'] = '\u7530';
  16355. t['\u2F66'] = '\u758B';
  16356. t['\u2F67'] = '\u7592';
  16357. t['\u2F68'] = '\u7676';
  16358. t['\u2F69'] = '\u767D';
  16359. t['\u2F6A'] = '\u76AE';
  16360. t['\u2F6B'] = '\u76BF';
  16361. t['\u2F6C'] = '\u76EE';
  16362. t['\u2F6D'] = '\u77DB';
  16363. t['\u2F6E'] = '\u77E2';
  16364. t['\u2F6F'] = '\u77F3';
  16365. t['\u2F70'] = '\u793A';
  16366. t['\u2F71'] = '\u79B8';
  16367. t['\u2F72'] = '\u79BE';
  16368. t['\u2F73'] = '\u7A74';
  16369. t['\u2F74'] = '\u7ACB';
  16370. t['\u2F75'] = '\u7AF9';
  16371. t['\u2F76'] = '\u7C73';
  16372. t['\u2F77'] = '\u7CF8';
  16373. t['\u2F78'] = '\u7F36';
  16374. t['\u2F79'] = '\u7F51';
  16375. t['\u2F7A'] = '\u7F8A';
  16376. t['\u2F7B'] = '\u7FBD';
  16377. t['\u2F7C'] = '\u8001';
  16378. t['\u2F7D'] = '\u800C';
  16379. t['\u2F7E'] = '\u8012';
  16380. t['\u2F7F'] = '\u8033';
  16381. t['\u2F80'] = '\u807F';
  16382. t['\u2F81'] = '\u8089';
  16383. t['\u2F82'] = '\u81E3';
  16384. t['\u2F83'] = '\u81EA';
  16385. t['\u2F84'] = '\u81F3';
  16386. t['\u2F85'] = '\u81FC';
  16387. t['\u2F86'] = '\u820C';
  16388. t['\u2F87'] = '\u821B';
  16389. t['\u2F88'] = '\u821F';
  16390. t['\u2F89'] = '\u826E';
  16391. t['\u2F8A'] = '\u8272';
  16392. t['\u2F8B'] = '\u8278';
  16393. t['\u2F8C'] = '\u864D';
  16394. t['\u2F8D'] = '\u866B';
  16395. t['\u2F8E'] = '\u8840';
  16396. t['\u2F8F'] = '\u884C';
  16397. t['\u2F90'] = '\u8863';
  16398. t['\u2F91'] = '\u897E';
  16399. t['\u2F92'] = '\u898B';
  16400. t['\u2F93'] = '\u89D2';
  16401. t['\u2F94'] = '\u8A00';
  16402. t['\u2F95'] = '\u8C37';
  16403. t['\u2F96'] = '\u8C46';
  16404. t['\u2F97'] = '\u8C55';
  16405. t['\u2F98'] = '\u8C78';
  16406. t['\u2F99'] = '\u8C9D';
  16407. t['\u2F9A'] = '\u8D64';
  16408. t['\u2F9B'] = '\u8D70';
  16409. t['\u2F9C'] = '\u8DB3';
  16410. t['\u2F9D'] = '\u8EAB';
  16411. t['\u2F9E'] = '\u8ECA';
  16412. t['\u2F9F'] = '\u8F9B';
  16413. t['\u2FA0'] = '\u8FB0';
  16414. t['\u2FA1'] = '\u8FB5';
  16415. t['\u2FA2'] = '\u9091';
  16416. t['\u2FA3'] = '\u9149';
  16417. t['\u2FA4'] = '\u91C6';
  16418. t['\u2FA5'] = '\u91CC';
  16419. t['\u2FA6'] = '\u91D1';
  16420. t['\u2FA7'] = '\u9577';
  16421. t['\u2FA8'] = '\u9580';
  16422. t['\u2FA9'] = '\u961C';
  16423. t['\u2FAA'] = '\u96B6';
  16424. t['\u2FAB'] = '\u96B9';
  16425. t['\u2FAC'] = '\u96E8';
  16426. t['\u2FAD'] = '\u9751';
  16427. t['\u2FAE'] = '\u975E';
  16428. t['\u2FAF'] = '\u9762';
  16429. t['\u2FB0'] = '\u9769';
  16430. t['\u2FB1'] = '\u97CB';
  16431. t['\u2FB2'] = '\u97ED';
  16432. t['\u2FB3'] = '\u97F3';
  16433. t['\u2FB4'] = '\u9801';
  16434. t['\u2FB5'] = '\u98A8';
  16435. t['\u2FB6'] = '\u98DB';
  16436. t['\u2FB7'] = '\u98DF';
  16437. t['\u2FB8'] = '\u9996';
  16438. t['\u2FB9'] = '\u9999';
  16439. t['\u2FBA'] = '\u99AC';
  16440. t['\u2FBB'] = '\u9AA8';
  16441. t['\u2FBC'] = '\u9AD8';
  16442. t['\u2FBD'] = '\u9ADF';
  16443. t['\u2FBE'] = '\u9B25';
  16444. t['\u2FBF'] = '\u9B2F';
  16445. t['\u2FC0'] = '\u9B32';
  16446. t['\u2FC1'] = '\u9B3C';
  16447. t['\u2FC2'] = '\u9B5A';
  16448. t['\u2FC3'] = '\u9CE5';
  16449. t['\u2FC4'] = '\u9E75';
  16450. t['\u2FC5'] = '\u9E7F';
  16451. t['\u2FC6'] = '\u9EA5';
  16452. t['\u2FC7'] = '\u9EBB';
  16453. t['\u2FC8'] = '\u9EC3';
  16454. t['\u2FC9'] = '\u9ECD';
  16455. t['\u2FCA'] = '\u9ED1';
  16456. t['\u2FCB'] = '\u9EF9';
  16457. t['\u2FCC'] = '\u9EFD';
  16458. t['\u2FCD'] = '\u9F0E';
  16459. t['\u2FCE'] = '\u9F13';
  16460. t['\u2FCF'] = '\u9F20';
  16461. t['\u2FD0'] = '\u9F3B';
  16462. t['\u2FD1'] = '\u9F4A';
  16463. t['\u2FD2'] = '\u9F52';
  16464. t['\u2FD3'] = '\u9F8D';
  16465. t['\u2FD4'] = '\u9F9C';
  16466. t['\u2FD5'] = '\u9FA0';
  16467. t['\u3036'] = '\u3012';
  16468. t['\u3038'] = '\u5341';
  16469. t['\u3039'] = '\u5344';
  16470. t['\u303A'] = '\u5345';
  16471. t['\u309B'] = '\u0020\u3099';
  16472. t['\u309C'] = '\u0020\u309A';
  16473. t['\u3131'] = '\u1100';
  16474. t['\u3132'] = '\u1101';
  16475. t['\u3133'] = '\u11AA';
  16476. t['\u3134'] = '\u1102';
  16477. t['\u3135'] = '\u11AC';
  16478. t['\u3136'] = '\u11AD';
  16479. t['\u3137'] = '\u1103';
  16480. t['\u3138'] = '\u1104';
  16481. t['\u3139'] = '\u1105';
  16482. t['\u313A'] = '\u11B0';
  16483. t['\u313B'] = '\u11B1';
  16484. t['\u313C'] = '\u11B2';
  16485. t['\u313D'] = '\u11B3';
  16486. t['\u313E'] = '\u11B4';
  16487. t['\u313F'] = '\u11B5';
  16488. t['\u3140'] = '\u111A';
  16489. t['\u3141'] = '\u1106';
  16490. t['\u3142'] = '\u1107';
  16491. t['\u3143'] = '\u1108';
  16492. t['\u3144'] = '\u1121';
  16493. t['\u3145'] = '\u1109';
  16494. t['\u3146'] = '\u110A';
  16495. t['\u3147'] = '\u110B';
  16496. t['\u3148'] = '\u110C';
  16497. t['\u3149'] = '\u110D';
  16498. t['\u314A'] = '\u110E';
  16499. t['\u314B'] = '\u110F';
  16500. t['\u314C'] = '\u1110';
  16501. t['\u314D'] = '\u1111';
  16502. t['\u314E'] = '\u1112';
  16503. t['\u314F'] = '\u1161';
  16504. t['\u3150'] = '\u1162';
  16505. t['\u3151'] = '\u1163';
  16506. t['\u3152'] = '\u1164';
  16507. t['\u3153'] = '\u1165';
  16508. t['\u3154'] = '\u1166';
  16509. t['\u3155'] = '\u1167';
  16510. t['\u3156'] = '\u1168';
  16511. t['\u3157'] = '\u1169';
  16512. t['\u3158'] = '\u116A';
  16513. t['\u3159'] = '\u116B';
  16514. t['\u315A'] = '\u116C';
  16515. t['\u315B'] = '\u116D';
  16516. t['\u315C'] = '\u116E';
  16517. t['\u315D'] = '\u116F';
  16518. t['\u315E'] = '\u1170';
  16519. t['\u315F'] = '\u1171';
  16520. t['\u3160'] = '\u1172';
  16521. t['\u3161'] = '\u1173';
  16522. t['\u3162'] = '\u1174';
  16523. t['\u3163'] = '\u1175';
  16524. t['\u3164'] = '\u1160';
  16525. t['\u3165'] = '\u1114';
  16526. t['\u3166'] = '\u1115';
  16527. t['\u3167'] = '\u11C7';
  16528. t['\u3168'] = '\u11C8';
  16529. t['\u3169'] = '\u11CC';
  16530. t['\u316A'] = '\u11CE';
  16531. t['\u316B'] = '\u11D3';
  16532. t['\u316C'] = '\u11D7';
  16533. t['\u316D'] = '\u11D9';
  16534. t['\u316E'] = '\u111C';
  16535. t['\u316F'] = '\u11DD';
  16536. t['\u3170'] = '\u11DF';
  16537. t['\u3171'] = '\u111D';
  16538. t['\u3172'] = '\u111E';
  16539. t['\u3173'] = '\u1120';
  16540. t['\u3174'] = '\u1122';
  16541. t['\u3175'] = '\u1123';
  16542. t['\u3176'] = '\u1127';
  16543. t['\u3177'] = '\u1129';
  16544. t['\u3178'] = '\u112B';
  16545. t['\u3179'] = '\u112C';
  16546. t['\u317A'] = '\u112D';
  16547. t['\u317B'] = '\u112E';
  16548. t['\u317C'] = '\u112F';
  16549. t['\u317D'] = '\u1132';
  16550. t['\u317E'] = '\u1136';
  16551. t['\u317F'] = '\u1140';
  16552. t['\u3180'] = '\u1147';
  16553. t['\u3181'] = '\u114C';
  16554. t['\u3182'] = '\u11F1';
  16555. t['\u3183'] = '\u11F2';
  16556. t['\u3184'] = '\u1157';
  16557. t['\u3185'] = '\u1158';
  16558. t['\u3186'] = '\u1159';
  16559. t['\u3187'] = '\u1184';
  16560. t['\u3188'] = '\u1185';
  16561. t['\u3189'] = '\u1188';
  16562. t['\u318A'] = '\u1191';
  16563. t['\u318B'] = '\u1192';
  16564. t['\u318C'] = '\u1194';
  16565. t['\u318D'] = '\u119E';
  16566. t['\u318E'] = '\u11A1';
  16567. t['\u3200'] = '\u0028\u1100\u0029';
  16568. t['\u3201'] = '\u0028\u1102\u0029';
  16569. t['\u3202'] = '\u0028\u1103\u0029';
  16570. t['\u3203'] = '\u0028\u1105\u0029';
  16571. t['\u3204'] = '\u0028\u1106\u0029';
  16572. t['\u3205'] = '\u0028\u1107\u0029';
  16573. t['\u3206'] = '\u0028\u1109\u0029';
  16574. t['\u3207'] = '\u0028\u110B\u0029';
  16575. t['\u3208'] = '\u0028\u110C\u0029';
  16576. t['\u3209'] = '\u0028\u110E\u0029';
  16577. t['\u320A'] = '\u0028\u110F\u0029';
  16578. t['\u320B'] = '\u0028\u1110\u0029';
  16579. t['\u320C'] = '\u0028\u1111\u0029';
  16580. t['\u320D'] = '\u0028\u1112\u0029';
  16581. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  16582. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  16583. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  16584. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  16585. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  16586. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  16587. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  16588. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  16589. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  16590. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  16591. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  16592. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  16593. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  16594. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  16595. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  16596. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  16597. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  16598. t['\u3220'] = '\u0028\u4E00\u0029';
  16599. t['\u3221'] = '\u0028\u4E8C\u0029';
  16600. t['\u3222'] = '\u0028\u4E09\u0029';
  16601. t['\u3223'] = '\u0028\u56DB\u0029';
  16602. t['\u3224'] = '\u0028\u4E94\u0029';
  16603. t['\u3225'] = '\u0028\u516D\u0029';
  16604. t['\u3226'] = '\u0028\u4E03\u0029';
  16605. t['\u3227'] = '\u0028\u516B\u0029';
  16606. t['\u3228'] = '\u0028\u4E5D\u0029';
  16607. t['\u3229'] = '\u0028\u5341\u0029';
  16608. t['\u322A'] = '\u0028\u6708\u0029';
  16609. t['\u322B'] = '\u0028\u706B\u0029';
  16610. t['\u322C'] = '\u0028\u6C34\u0029';
  16611. t['\u322D'] = '\u0028\u6728\u0029';
  16612. t['\u322E'] = '\u0028\u91D1\u0029';
  16613. t['\u322F'] = '\u0028\u571F\u0029';
  16614. t['\u3230'] = '\u0028\u65E5\u0029';
  16615. t['\u3231'] = '\u0028\u682A\u0029';
  16616. t['\u3232'] = '\u0028\u6709\u0029';
  16617. t['\u3233'] = '\u0028\u793E\u0029';
  16618. t['\u3234'] = '\u0028\u540D\u0029';
  16619. t['\u3235'] = '\u0028\u7279\u0029';
  16620. t['\u3236'] = '\u0028\u8CA1\u0029';
  16621. t['\u3237'] = '\u0028\u795D\u0029';
  16622. t['\u3238'] = '\u0028\u52B4\u0029';
  16623. t['\u3239'] = '\u0028\u4EE3\u0029';
  16624. t['\u323A'] = '\u0028\u547C\u0029';
  16625. t['\u323B'] = '\u0028\u5B66\u0029';
  16626. t['\u323C'] = '\u0028\u76E3\u0029';
  16627. t['\u323D'] = '\u0028\u4F01\u0029';
  16628. t['\u323E'] = '\u0028\u8CC7\u0029';
  16629. t['\u323F'] = '\u0028\u5354\u0029';
  16630. t['\u3240'] = '\u0028\u796D\u0029';
  16631. t['\u3241'] = '\u0028\u4F11\u0029';
  16632. t['\u3242'] = '\u0028\u81EA\u0029';
  16633. t['\u3243'] = '\u0028\u81F3\u0029';
  16634. t['\u32C0'] = '\u0031\u6708';
  16635. t['\u32C1'] = '\u0032\u6708';
  16636. t['\u32C2'] = '\u0033\u6708';
  16637. t['\u32C3'] = '\u0034\u6708';
  16638. t['\u32C4'] = '\u0035\u6708';
  16639. t['\u32C5'] = '\u0036\u6708';
  16640. t['\u32C6'] = '\u0037\u6708';
  16641. t['\u32C7'] = '\u0038\u6708';
  16642. t['\u32C8'] = '\u0039\u6708';
  16643. t['\u32C9'] = '\u0031\u0030\u6708';
  16644. t['\u32CA'] = '\u0031\u0031\u6708';
  16645. t['\u32CB'] = '\u0031\u0032\u6708';
  16646. t['\u3358'] = '\u0030\u70B9';
  16647. t['\u3359'] = '\u0031\u70B9';
  16648. t['\u335A'] = '\u0032\u70B9';
  16649. t['\u335B'] = '\u0033\u70B9';
  16650. t['\u335C'] = '\u0034\u70B9';
  16651. t['\u335D'] = '\u0035\u70B9';
  16652. t['\u335E'] = '\u0036\u70B9';
  16653. t['\u335F'] = '\u0037\u70B9';
  16654. t['\u3360'] = '\u0038\u70B9';
  16655. t['\u3361'] = '\u0039\u70B9';
  16656. t['\u3362'] = '\u0031\u0030\u70B9';
  16657. t['\u3363'] = '\u0031\u0031\u70B9';
  16658. t['\u3364'] = '\u0031\u0032\u70B9';
  16659. t['\u3365'] = '\u0031\u0033\u70B9';
  16660. t['\u3366'] = '\u0031\u0034\u70B9';
  16661. t['\u3367'] = '\u0031\u0035\u70B9';
  16662. t['\u3368'] = '\u0031\u0036\u70B9';
  16663. t['\u3369'] = '\u0031\u0037\u70B9';
  16664. t['\u336A'] = '\u0031\u0038\u70B9';
  16665. t['\u336B'] = '\u0031\u0039\u70B9';
  16666. t['\u336C'] = '\u0032\u0030\u70B9';
  16667. t['\u336D'] = '\u0032\u0031\u70B9';
  16668. t['\u336E'] = '\u0032\u0032\u70B9';
  16669. t['\u336F'] = '\u0032\u0033\u70B9';
  16670. t['\u3370'] = '\u0032\u0034\u70B9';
  16671. t['\u33E0'] = '\u0031\u65E5';
  16672. t['\u33E1'] = '\u0032\u65E5';
  16673. t['\u33E2'] = '\u0033\u65E5';
  16674. t['\u33E3'] = '\u0034\u65E5';
  16675. t['\u33E4'] = '\u0035\u65E5';
  16676. t['\u33E5'] = '\u0036\u65E5';
  16677. t['\u33E6'] = '\u0037\u65E5';
  16678. t['\u33E7'] = '\u0038\u65E5';
  16679. t['\u33E8'] = '\u0039\u65E5';
  16680. t['\u33E9'] = '\u0031\u0030\u65E5';
  16681. t['\u33EA'] = '\u0031\u0031\u65E5';
  16682. t['\u33EB'] = '\u0031\u0032\u65E5';
  16683. t['\u33EC'] = '\u0031\u0033\u65E5';
  16684. t['\u33ED'] = '\u0031\u0034\u65E5';
  16685. t['\u33EE'] = '\u0031\u0035\u65E5';
  16686. t['\u33EF'] = '\u0031\u0036\u65E5';
  16687. t['\u33F0'] = '\u0031\u0037\u65E5';
  16688. t['\u33F1'] = '\u0031\u0038\u65E5';
  16689. t['\u33F2'] = '\u0031\u0039\u65E5';
  16690. t['\u33F3'] = '\u0032\u0030\u65E5';
  16691. t['\u33F4'] = '\u0032\u0031\u65E5';
  16692. t['\u33F5'] = '\u0032\u0032\u65E5';
  16693. t['\u33F6'] = '\u0032\u0033\u65E5';
  16694. t['\u33F7'] = '\u0032\u0034\u65E5';
  16695. t['\u33F8'] = '\u0032\u0035\u65E5';
  16696. t['\u33F9'] = '\u0032\u0036\u65E5';
  16697. t['\u33FA'] = '\u0032\u0037\u65E5';
  16698. t['\u33FB'] = '\u0032\u0038\u65E5';
  16699. t['\u33FC'] = '\u0032\u0039\u65E5';
  16700. t['\u33FD'] = '\u0033\u0030\u65E5';
  16701. t['\u33FE'] = '\u0033\u0031\u65E5';
  16702. t['\uFB00'] = '\u0066\u0066';
  16703. t['\uFB01'] = '\u0066\u0069';
  16704. t['\uFB02'] = '\u0066\u006C';
  16705. t['\uFB03'] = '\u0066\u0066\u0069';
  16706. t['\uFB04'] = '\u0066\u0066\u006C';
  16707. t['\uFB05'] = '\u017F\u0074';
  16708. t['\uFB06'] = '\u0073\u0074';
  16709. t['\uFB13'] = '\u0574\u0576';
  16710. t['\uFB14'] = '\u0574\u0565';
  16711. t['\uFB15'] = '\u0574\u056B';
  16712. t['\uFB16'] = '\u057E\u0576';
  16713. t['\uFB17'] = '\u0574\u056D';
  16714. t['\uFB4F'] = '\u05D0\u05DC';
  16715. t['\uFB50'] = '\u0671';
  16716. t['\uFB51'] = '\u0671';
  16717. t['\uFB52'] = '\u067B';
  16718. t['\uFB53'] = '\u067B';
  16719. t['\uFB54'] = '\u067B';
  16720. t['\uFB55'] = '\u067B';
  16721. t['\uFB56'] = '\u067E';
  16722. t['\uFB57'] = '\u067E';
  16723. t['\uFB58'] = '\u067E';
  16724. t['\uFB59'] = '\u067E';
  16725. t['\uFB5A'] = '\u0680';
  16726. t['\uFB5B'] = '\u0680';
  16727. t['\uFB5C'] = '\u0680';
  16728. t['\uFB5D'] = '\u0680';
  16729. t['\uFB5E'] = '\u067A';
  16730. t['\uFB5F'] = '\u067A';
  16731. t['\uFB60'] = '\u067A';
  16732. t['\uFB61'] = '\u067A';
  16733. t['\uFB62'] = '\u067F';
  16734. t['\uFB63'] = '\u067F';
  16735. t['\uFB64'] = '\u067F';
  16736. t['\uFB65'] = '\u067F';
  16737. t['\uFB66'] = '\u0679';
  16738. t['\uFB67'] = '\u0679';
  16739. t['\uFB68'] = '\u0679';
  16740. t['\uFB69'] = '\u0679';
  16741. t['\uFB6A'] = '\u06A4';
  16742. t['\uFB6B'] = '\u06A4';
  16743. t['\uFB6C'] = '\u06A4';
  16744. t['\uFB6D'] = '\u06A4';
  16745. t['\uFB6E'] = '\u06A6';
  16746. t['\uFB6F'] = '\u06A6';
  16747. t['\uFB70'] = '\u06A6';
  16748. t['\uFB71'] = '\u06A6';
  16749. t['\uFB72'] = '\u0684';
  16750. t['\uFB73'] = '\u0684';
  16751. t['\uFB74'] = '\u0684';
  16752. t['\uFB75'] = '\u0684';
  16753. t['\uFB76'] = '\u0683';
  16754. t['\uFB77'] = '\u0683';
  16755. t['\uFB78'] = '\u0683';
  16756. t['\uFB79'] = '\u0683';
  16757. t['\uFB7A'] = '\u0686';
  16758. t['\uFB7B'] = '\u0686';
  16759. t['\uFB7C'] = '\u0686';
  16760. t['\uFB7D'] = '\u0686';
  16761. t['\uFB7E'] = '\u0687';
  16762. t['\uFB7F'] = '\u0687';
  16763. t['\uFB80'] = '\u0687';
  16764. t['\uFB81'] = '\u0687';
  16765. t['\uFB82'] = '\u068D';
  16766. t['\uFB83'] = '\u068D';
  16767. t['\uFB84'] = '\u068C';
  16768. t['\uFB85'] = '\u068C';
  16769. t['\uFB86'] = '\u068E';
  16770. t['\uFB87'] = '\u068E';
  16771. t['\uFB88'] = '\u0688';
  16772. t['\uFB89'] = '\u0688';
  16773. t['\uFB8A'] = '\u0698';
  16774. t['\uFB8B'] = '\u0698';
  16775. t['\uFB8C'] = '\u0691';
  16776. t['\uFB8D'] = '\u0691';
  16777. t['\uFB8E'] = '\u06A9';
  16778. t['\uFB8F'] = '\u06A9';
  16779. t['\uFB90'] = '\u06A9';
  16780. t['\uFB91'] = '\u06A9';
  16781. t['\uFB92'] = '\u06AF';
  16782. t['\uFB93'] = '\u06AF';
  16783. t['\uFB94'] = '\u06AF';
  16784. t['\uFB95'] = '\u06AF';
  16785. t['\uFB96'] = '\u06B3';
  16786. t['\uFB97'] = '\u06B3';
  16787. t['\uFB98'] = '\u06B3';
  16788. t['\uFB99'] = '\u06B3';
  16789. t['\uFB9A'] = '\u06B1';
  16790. t['\uFB9B'] = '\u06B1';
  16791. t['\uFB9C'] = '\u06B1';
  16792. t['\uFB9D'] = '\u06B1';
  16793. t['\uFB9E'] = '\u06BA';
  16794. t['\uFB9F'] = '\u06BA';
  16795. t['\uFBA0'] = '\u06BB';
  16796. t['\uFBA1'] = '\u06BB';
  16797. t['\uFBA2'] = '\u06BB';
  16798. t['\uFBA3'] = '\u06BB';
  16799. t['\uFBA4'] = '\u06C0';
  16800. t['\uFBA5'] = '\u06C0';
  16801. t['\uFBA6'] = '\u06C1';
  16802. t['\uFBA7'] = '\u06C1';
  16803. t['\uFBA8'] = '\u06C1';
  16804. t['\uFBA9'] = '\u06C1';
  16805. t['\uFBAA'] = '\u06BE';
  16806. t['\uFBAB'] = '\u06BE';
  16807. t['\uFBAC'] = '\u06BE';
  16808. t['\uFBAD'] = '\u06BE';
  16809. t['\uFBAE'] = '\u06D2';
  16810. t['\uFBAF'] = '\u06D2';
  16811. t['\uFBB0'] = '\u06D3';
  16812. t['\uFBB1'] = '\u06D3';
  16813. t['\uFBD3'] = '\u06AD';
  16814. t['\uFBD4'] = '\u06AD';
  16815. t['\uFBD5'] = '\u06AD';
  16816. t['\uFBD6'] = '\u06AD';
  16817. t['\uFBD7'] = '\u06C7';
  16818. t['\uFBD8'] = '\u06C7';
  16819. t['\uFBD9'] = '\u06C6';
  16820. t['\uFBDA'] = '\u06C6';
  16821. t['\uFBDB'] = '\u06C8';
  16822. t['\uFBDC'] = '\u06C8';
  16823. t['\uFBDD'] = '\u0677';
  16824. t['\uFBDE'] = '\u06CB';
  16825. t['\uFBDF'] = '\u06CB';
  16826. t['\uFBE0'] = '\u06C5';
  16827. t['\uFBE1'] = '\u06C5';
  16828. t['\uFBE2'] = '\u06C9';
  16829. t['\uFBE3'] = '\u06C9';
  16830. t['\uFBE4'] = '\u06D0';
  16831. t['\uFBE5'] = '\u06D0';
  16832. t['\uFBE6'] = '\u06D0';
  16833. t['\uFBE7'] = '\u06D0';
  16834. t['\uFBE8'] = '\u0649';
  16835. t['\uFBE9'] = '\u0649';
  16836. t['\uFBEA'] = '\u0626\u0627';
  16837. t['\uFBEB'] = '\u0626\u0627';
  16838. t['\uFBEC'] = '\u0626\u06D5';
  16839. t['\uFBED'] = '\u0626\u06D5';
  16840. t['\uFBEE'] = '\u0626\u0648';
  16841. t['\uFBEF'] = '\u0626\u0648';
  16842. t['\uFBF0'] = '\u0626\u06C7';
  16843. t['\uFBF1'] = '\u0626\u06C7';
  16844. t['\uFBF2'] = '\u0626\u06C6';
  16845. t['\uFBF3'] = '\u0626\u06C6';
  16846. t['\uFBF4'] = '\u0626\u06C8';
  16847. t['\uFBF5'] = '\u0626\u06C8';
  16848. t['\uFBF6'] = '\u0626\u06D0';
  16849. t['\uFBF7'] = '\u0626\u06D0';
  16850. t['\uFBF8'] = '\u0626\u06D0';
  16851. t['\uFBF9'] = '\u0626\u0649';
  16852. t['\uFBFA'] = '\u0626\u0649';
  16853. t['\uFBFB'] = '\u0626\u0649';
  16854. t['\uFBFC'] = '\u06CC';
  16855. t['\uFBFD'] = '\u06CC';
  16856. t['\uFBFE'] = '\u06CC';
  16857. t['\uFBFF'] = '\u06CC';
  16858. t['\uFC00'] = '\u0626\u062C';
  16859. t['\uFC01'] = '\u0626\u062D';
  16860. t['\uFC02'] = '\u0626\u0645';
  16861. t['\uFC03'] = '\u0626\u0649';
  16862. t['\uFC04'] = '\u0626\u064A';
  16863. t['\uFC05'] = '\u0628\u062C';
  16864. t['\uFC06'] = '\u0628\u062D';
  16865. t['\uFC07'] = '\u0628\u062E';
  16866. t['\uFC08'] = '\u0628\u0645';
  16867. t['\uFC09'] = '\u0628\u0649';
  16868. t['\uFC0A'] = '\u0628\u064A';
  16869. t['\uFC0B'] = '\u062A\u062C';
  16870. t['\uFC0C'] = '\u062A\u062D';
  16871. t['\uFC0D'] = '\u062A\u062E';
  16872. t['\uFC0E'] = '\u062A\u0645';
  16873. t['\uFC0F'] = '\u062A\u0649';
  16874. t['\uFC10'] = '\u062A\u064A';
  16875. t['\uFC11'] = '\u062B\u062C';
  16876. t['\uFC12'] = '\u062B\u0645';
  16877. t['\uFC13'] = '\u062B\u0649';
  16878. t['\uFC14'] = '\u062B\u064A';
  16879. t['\uFC15'] = '\u062C\u062D';
  16880. t['\uFC16'] = '\u062C\u0645';
  16881. t['\uFC17'] = '\u062D\u062C';
  16882. t['\uFC18'] = '\u062D\u0645';
  16883. t['\uFC19'] = '\u062E\u062C';
  16884. t['\uFC1A'] = '\u062E\u062D';
  16885. t['\uFC1B'] = '\u062E\u0645';
  16886. t['\uFC1C'] = '\u0633\u062C';
  16887. t['\uFC1D'] = '\u0633\u062D';
  16888. t['\uFC1E'] = '\u0633\u062E';
  16889. t['\uFC1F'] = '\u0633\u0645';
  16890. t['\uFC20'] = '\u0635\u062D';
  16891. t['\uFC21'] = '\u0635\u0645';
  16892. t['\uFC22'] = '\u0636\u062C';
  16893. t['\uFC23'] = '\u0636\u062D';
  16894. t['\uFC24'] = '\u0636\u062E';
  16895. t['\uFC25'] = '\u0636\u0645';
  16896. t['\uFC26'] = '\u0637\u062D';
  16897. t['\uFC27'] = '\u0637\u0645';
  16898. t['\uFC28'] = '\u0638\u0645';
  16899. t['\uFC29'] = '\u0639\u062C';
  16900. t['\uFC2A'] = '\u0639\u0645';
  16901. t['\uFC2B'] = '\u063A\u062C';
  16902. t['\uFC2C'] = '\u063A\u0645';
  16903. t['\uFC2D'] = '\u0641\u062C';
  16904. t['\uFC2E'] = '\u0641\u062D';
  16905. t['\uFC2F'] = '\u0641\u062E';
  16906. t['\uFC30'] = '\u0641\u0645';
  16907. t['\uFC31'] = '\u0641\u0649';
  16908. t['\uFC32'] = '\u0641\u064A';
  16909. t['\uFC33'] = '\u0642\u062D';
  16910. t['\uFC34'] = '\u0642\u0645';
  16911. t['\uFC35'] = '\u0642\u0649';
  16912. t['\uFC36'] = '\u0642\u064A';
  16913. t['\uFC37'] = '\u0643\u0627';
  16914. t['\uFC38'] = '\u0643\u062C';
  16915. t['\uFC39'] = '\u0643\u062D';
  16916. t['\uFC3A'] = '\u0643\u062E';
  16917. t['\uFC3B'] = '\u0643\u0644';
  16918. t['\uFC3C'] = '\u0643\u0645';
  16919. t['\uFC3D'] = '\u0643\u0649';
  16920. t['\uFC3E'] = '\u0643\u064A';
  16921. t['\uFC3F'] = '\u0644\u062C';
  16922. t['\uFC40'] = '\u0644\u062D';
  16923. t['\uFC41'] = '\u0644\u062E';
  16924. t['\uFC42'] = '\u0644\u0645';
  16925. t['\uFC43'] = '\u0644\u0649';
  16926. t['\uFC44'] = '\u0644\u064A';
  16927. t['\uFC45'] = '\u0645\u062C';
  16928. t['\uFC46'] = '\u0645\u062D';
  16929. t['\uFC47'] = '\u0645\u062E';
  16930. t['\uFC48'] = '\u0645\u0645';
  16931. t['\uFC49'] = '\u0645\u0649';
  16932. t['\uFC4A'] = '\u0645\u064A';
  16933. t['\uFC4B'] = '\u0646\u062C';
  16934. t['\uFC4C'] = '\u0646\u062D';
  16935. t['\uFC4D'] = '\u0646\u062E';
  16936. t['\uFC4E'] = '\u0646\u0645';
  16937. t['\uFC4F'] = '\u0646\u0649';
  16938. t['\uFC50'] = '\u0646\u064A';
  16939. t['\uFC51'] = '\u0647\u062C';
  16940. t['\uFC52'] = '\u0647\u0645';
  16941. t['\uFC53'] = '\u0647\u0649';
  16942. t['\uFC54'] = '\u0647\u064A';
  16943. t['\uFC55'] = '\u064A\u062C';
  16944. t['\uFC56'] = '\u064A\u062D';
  16945. t['\uFC57'] = '\u064A\u062E';
  16946. t['\uFC58'] = '\u064A\u0645';
  16947. t['\uFC59'] = '\u064A\u0649';
  16948. t['\uFC5A'] = '\u064A\u064A';
  16949. t['\uFC5B'] = '\u0630\u0670';
  16950. t['\uFC5C'] = '\u0631\u0670';
  16951. t['\uFC5D'] = '\u0649\u0670';
  16952. t['\uFC5E'] = '\u0020\u064C\u0651';
  16953. t['\uFC5F'] = '\u0020\u064D\u0651';
  16954. t['\uFC60'] = '\u0020\u064E\u0651';
  16955. t['\uFC61'] = '\u0020\u064F\u0651';
  16956. t['\uFC62'] = '\u0020\u0650\u0651';
  16957. t['\uFC63'] = '\u0020\u0651\u0670';
  16958. t['\uFC64'] = '\u0626\u0631';
  16959. t['\uFC65'] = '\u0626\u0632';
  16960. t['\uFC66'] = '\u0626\u0645';
  16961. t['\uFC67'] = '\u0626\u0646';
  16962. t['\uFC68'] = '\u0626\u0649';
  16963. t['\uFC69'] = '\u0626\u064A';
  16964. t['\uFC6A'] = '\u0628\u0631';
  16965. t['\uFC6B'] = '\u0628\u0632';
  16966. t['\uFC6C'] = '\u0628\u0645';
  16967. t['\uFC6D'] = '\u0628\u0646';
  16968. t['\uFC6E'] = '\u0628\u0649';
  16969. t['\uFC6F'] = '\u0628\u064A';
  16970. t['\uFC70'] = '\u062A\u0631';
  16971. t['\uFC71'] = '\u062A\u0632';
  16972. t['\uFC72'] = '\u062A\u0645';
  16973. t['\uFC73'] = '\u062A\u0646';
  16974. t['\uFC74'] = '\u062A\u0649';
  16975. t['\uFC75'] = '\u062A\u064A';
  16976. t['\uFC76'] = '\u062B\u0631';
  16977. t['\uFC77'] = '\u062B\u0632';
  16978. t['\uFC78'] = '\u062B\u0645';
  16979. t['\uFC79'] = '\u062B\u0646';
  16980. t['\uFC7A'] = '\u062B\u0649';
  16981. t['\uFC7B'] = '\u062B\u064A';
  16982. t['\uFC7C'] = '\u0641\u0649';
  16983. t['\uFC7D'] = '\u0641\u064A';
  16984. t['\uFC7E'] = '\u0642\u0649';
  16985. t['\uFC7F'] = '\u0642\u064A';
  16986. t['\uFC80'] = '\u0643\u0627';
  16987. t['\uFC81'] = '\u0643\u0644';
  16988. t['\uFC82'] = '\u0643\u0645';
  16989. t['\uFC83'] = '\u0643\u0649';
  16990. t['\uFC84'] = '\u0643\u064A';
  16991. t['\uFC85'] = '\u0644\u0645';
  16992. t['\uFC86'] = '\u0644\u0649';
  16993. t['\uFC87'] = '\u0644\u064A';
  16994. t['\uFC88'] = '\u0645\u0627';
  16995. t['\uFC89'] = '\u0645\u0645';
  16996. t['\uFC8A'] = '\u0646\u0631';
  16997. t['\uFC8B'] = '\u0646\u0632';
  16998. t['\uFC8C'] = '\u0646\u0645';
  16999. t['\uFC8D'] = '\u0646\u0646';
  17000. t['\uFC8E'] = '\u0646\u0649';
  17001. t['\uFC8F'] = '\u0646\u064A';
  17002. t['\uFC90'] = '\u0649\u0670';
  17003. t['\uFC91'] = '\u064A\u0631';
  17004. t['\uFC92'] = '\u064A\u0632';
  17005. t['\uFC93'] = '\u064A\u0645';
  17006. t['\uFC94'] = '\u064A\u0646';
  17007. t['\uFC95'] = '\u064A\u0649';
  17008. t['\uFC96'] = '\u064A\u064A';
  17009. t['\uFC97'] = '\u0626\u062C';
  17010. t['\uFC98'] = '\u0626\u062D';
  17011. t['\uFC99'] = '\u0626\u062E';
  17012. t['\uFC9A'] = '\u0626\u0645';
  17013. t['\uFC9B'] = '\u0626\u0647';
  17014. t['\uFC9C'] = '\u0628\u062C';
  17015. t['\uFC9D'] = '\u0628\u062D';
  17016. t['\uFC9E'] = '\u0628\u062E';
  17017. t['\uFC9F'] = '\u0628\u0645';
  17018. t['\uFCA0'] = '\u0628\u0647';
  17019. t['\uFCA1'] = '\u062A\u062C';
  17020. t['\uFCA2'] = '\u062A\u062D';
  17021. t['\uFCA3'] = '\u062A\u062E';
  17022. t['\uFCA4'] = '\u062A\u0645';
  17023. t['\uFCA5'] = '\u062A\u0647';
  17024. t['\uFCA6'] = '\u062B\u0645';
  17025. t['\uFCA7'] = '\u062C\u062D';
  17026. t['\uFCA8'] = '\u062C\u0645';
  17027. t['\uFCA9'] = '\u062D\u062C';
  17028. t['\uFCAA'] = '\u062D\u0645';
  17029. t['\uFCAB'] = '\u062E\u062C';
  17030. t['\uFCAC'] = '\u062E\u0645';
  17031. t['\uFCAD'] = '\u0633\u062C';
  17032. t['\uFCAE'] = '\u0633\u062D';
  17033. t['\uFCAF'] = '\u0633\u062E';
  17034. t['\uFCB0'] = '\u0633\u0645';
  17035. t['\uFCB1'] = '\u0635\u062D';
  17036. t['\uFCB2'] = '\u0635\u062E';
  17037. t['\uFCB3'] = '\u0635\u0645';
  17038. t['\uFCB4'] = '\u0636\u062C';
  17039. t['\uFCB5'] = '\u0636\u062D';
  17040. t['\uFCB6'] = '\u0636\u062E';
  17041. t['\uFCB7'] = '\u0636\u0645';
  17042. t['\uFCB8'] = '\u0637\u062D';
  17043. t['\uFCB9'] = '\u0638\u0645';
  17044. t['\uFCBA'] = '\u0639\u062C';
  17045. t['\uFCBB'] = '\u0639\u0645';
  17046. t['\uFCBC'] = '\u063A\u062C';
  17047. t['\uFCBD'] = '\u063A\u0645';
  17048. t['\uFCBE'] = '\u0641\u062C';
  17049. t['\uFCBF'] = '\u0641\u062D';
  17050. t['\uFCC0'] = '\u0641\u062E';
  17051. t['\uFCC1'] = '\u0641\u0645';
  17052. t['\uFCC2'] = '\u0642\u062D';
  17053. t['\uFCC3'] = '\u0642\u0645';
  17054. t['\uFCC4'] = '\u0643\u062C';
  17055. t['\uFCC5'] = '\u0643\u062D';
  17056. t['\uFCC6'] = '\u0643\u062E';
  17057. t['\uFCC7'] = '\u0643\u0644';
  17058. t['\uFCC8'] = '\u0643\u0645';
  17059. t['\uFCC9'] = '\u0644\u062C';
  17060. t['\uFCCA'] = '\u0644\u062D';
  17061. t['\uFCCB'] = '\u0644\u062E';
  17062. t['\uFCCC'] = '\u0644\u0645';
  17063. t['\uFCCD'] = '\u0644\u0647';
  17064. t['\uFCCE'] = '\u0645\u062C';
  17065. t['\uFCCF'] = '\u0645\u062D';
  17066. t['\uFCD0'] = '\u0645\u062E';
  17067. t['\uFCD1'] = '\u0645\u0645';
  17068. t['\uFCD2'] = '\u0646\u062C';
  17069. t['\uFCD3'] = '\u0646\u062D';
  17070. t['\uFCD4'] = '\u0646\u062E';
  17071. t['\uFCD5'] = '\u0646\u0645';
  17072. t['\uFCD6'] = '\u0646\u0647';
  17073. t['\uFCD7'] = '\u0647\u062C';
  17074. t['\uFCD8'] = '\u0647\u0645';
  17075. t['\uFCD9'] = '\u0647\u0670';
  17076. t['\uFCDA'] = '\u064A\u062C';
  17077. t['\uFCDB'] = '\u064A\u062D';
  17078. t['\uFCDC'] = '\u064A\u062E';
  17079. t['\uFCDD'] = '\u064A\u0645';
  17080. t['\uFCDE'] = '\u064A\u0647';
  17081. t['\uFCDF'] = '\u0626\u0645';
  17082. t['\uFCE0'] = '\u0626\u0647';
  17083. t['\uFCE1'] = '\u0628\u0645';
  17084. t['\uFCE2'] = '\u0628\u0647';
  17085. t['\uFCE3'] = '\u062A\u0645';
  17086. t['\uFCE4'] = '\u062A\u0647';
  17087. t['\uFCE5'] = '\u062B\u0645';
  17088. t['\uFCE6'] = '\u062B\u0647';
  17089. t['\uFCE7'] = '\u0633\u0645';
  17090. t['\uFCE8'] = '\u0633\u0647';
  17091. t['\uFCE9'] = '\u0634\u0645';
  17092. t['\uFCEA'] = '\u0634\u0647';
  17093. t['\uFCEB'] = '\u0643\u0644';
  17094. t['\uFCEC'] = '\u0643\u0645';
  17095. t['\uFCED'] = '\u0644\u0645';
  17096. t['\uFCEE'] = '\u0646\u0645';
  17097. t['\uFCEF'] = '\u0646\u0647';
  17098. t['\uFCF0'] = '\u064A\u0645';
  17099. t['\uFCF1'] = '\u064A\u0647';
  17100. t['\uFCF2'] = '\u0640\u064E\u0651';
  17101. t['\uFCF3'] = '\u0640\u064F\u0651';
  17102. t['\uFCF4'] = '\u0640\u0650\u0651';
  17103. t['\uFCF5'] = '\u0637\u0649';
  17104. t['\uFCF6'] = '\u0637\u064A';
  17105. t['\uFCF7'] = '\u0639\u0649';
  17106. t['\uFCF8'] = '\u0639\u064A';
  17107. t['\uFCF9'] = '\u063A\u0649';
  17108. t['\uFCFA'] = '\u063A\u064A';
  17109. t['\uFCFB'] = '\u0633\u0649';
  17110. t['\uFCFC'] = '\u0633\u064A';
  17111. t['\uFCFD'] = '\u0634\u0649';
  17112. t['\uFCFE'] = '\u0634\u064A';
  17113. t['\uFCFF'] = '\u062D\u0649';
  17114. t['\uFD00'] = '\u062D\u064A';
  17115. t['\uFD01'] = '\u062C\u0649';
  17116. t['\uFD02'] = '\u062C\u064A';
  17117. t['\uFD03'] = '\u062E\u0649';
  17118. t['\uFD04'] = '\u062E\u064A';
  17119. t['\uFD05'] = '\u0635\u0649';
  17120. t['\uFD06'] = '\u0635\u064A';
  17121. t['\uFD07'] = '\u0636\u0649';
  17122. t['\uFD08'] = '\u0636\u064A';
  17123. t['\uFD09'] = '\u0634\u062C';
  17124. t['\uFD0A'] = '\u0634\u062D';
  17125. t['\uFD0B'] = '\u0634\u062E';
  17126. t['\uFD0C'] = '\u0634\u0645';
  17127. t['\uFD0D'] = '\u0634\u0631';
  17128. t['\uFD0E'] = '\u0633\u0631';
  17129. t['\uFD0F'] = '\u0635\u0631';
  17130. t['\uFD10'] = '\u0636\u0631';
  17131. t['\uFD11'] = '\u0637\u0649';
  17132. t['\uFD12'] = '\u0637\u064A';
  17133. t['\uFD13'] = '\u0639\u0649';
  17134. t['\uFD14'] = '\u0639\u064A';
  17135. t['\uFD15'] = '\u063A\u0649';
  17136. t['\uFD16'] = '\u063A\u064A';
  17137. t['\uFD17'] = '\u0633\u0649';
  17138. t['\uFD18'] = '\u0633\u064A';
  17139. t['\uFD19'] = '\u0634\u0649';
  17140. t['\uFD1A'] = '\u0634\u064A';
  17141. t['\uFD1B'] = '\u062D\u0649';
  17142. t['\uFD1C'] = '\u062D\u064A';
  17143. t['\uFD1D'] = '\u062C\u0649';
  17144. t['\uFD1E'] = '\u062C\u064A';
  17145. t['\uFD1F'] = '\u062E\u0649';
  17146. t['\uFD20'] = '\u062E\u064A';
  17147. t['\uFD21'] = '\u0635\u0649';
  17148. t['\uFD22'] = '\u0635\u064A';
  17149. t['\uFD23'] = '\u0636\u0649';
  17150. t['\uFD24'] = '\u0636\u064A';
  17151. t['\uFD25'] = '\u0634\u062C';
  17152. t['\uFD26'] = '\u0634\u062D';
  17153. t['\uFD27'] = '\u0634\u062E';
  17154. t['\uFD28'] = '\u0634\u0645';
  17155. t['\uFD29'] = '\u0634\u0631';
  17156. t['\uFD2A'] = '\u0633\u0631';
  17157. t['\uFD2B'] = '\u0635\u0631';
  17158. t['\uFD2C'] = '\u0636\u0631';
  17159. t['\uFD2D'] = '\u0634\u062C';
  17160. t['\uFD2E'] = '\u0634\u062D';
  17161. t['\uFD2F'] = '\u0634\u062E';
  17162. t['\uFD30'] = '\u0634\u0645';
  17163. t['\uFD31'] = '\u0633\u0647';
  17164. t['\uFD32'] = '\u0634\u0647';
  17165. t['\uFD33'] = '\u0637\u0645';
  17166. t['\uFD34'] = '\u0633\u062C';
  17167. t['\uFD35'] = '\u0633\u062D';
  17168. t['\uFD36'] = '\u0633\u062E';
  17169. t['\uFD37'] = '\u0634\u062C';
  17170. t['\uFD38'] = '\u0634\u062D';
  17171. t['\uFD39'] = '\u0634\u062E';
  17172. t['\uFD3A'] = '\u0637\u0645';
  17173. t['\uFD3B'] = '\u0638\u0645';
  17174. t['\uFD3C'] = '\u0627\u064B';
  17175. t['\uFD3D'] = '\u0627\u064B';
  17176. t['\uFD50'] = '\u062A\u062C\u0645';
  17177. t['\uFD51'] = '\u062A\u062D\u062C';
  17178. t['\uFD52'] = '\u062A\u062D\u062C';
  17179. t['\uFD53'] = '\u062A\u062D\u0645';
  17180. t['\uFD54'] = '\u062A\u062E\u0645';
  17181. t['\uFD55'] = '\u062A\u0645\u062C';
  17182. t['\uFD56'] = '\u062A\u0645\u062D';
  17183. t['\uFD57'] = '\u062A\u0645\u062E';
  17184. t['\uFD58'] = '\u062C\u0645\u062D';
  17185. t['\uFD59'] = '\u062C\u0645\u062D';
  17186. t['\uFD5A'] = '\u062D\u0645\u064A';
  17187. t['\uFD5B'] = '\u062D\u0645\u0649';
  17188. t['\uFD5C'] = '\u0633\u062D\u062C';
  17189. t['\uFD5D'] = '\u0633\u062C\u062D';
  17190. t['\uFD5E'] = '\u0633\u062C\u0649';
  17191. t['\uFD5F'] = '\u0633\u0645\u062D';
  17192. t['\uFD60'] = '\u0633\u0645\u062D';
  17193. t['\uFD61'] = '\u0633\u0645\u062C';
  17194. t['\uFD62'] = '\u0633\u0645\u0645';
  17195. t['\uFD63'] = '\u0633\u0645\u0645';
  17196. t['\uFD64'] = '\u0635\u062D\u062D';
  17197. t['\uFD65'] = '\u0635\u062D\u062D';
  17198. t['\uFD66'] = '\u0635\u0645\u0645';
  17199. t['\uFD67'] = '\u0634\u062D\u0645';
  17200. t['\uFD68'] = '\u0634\u062D\u0645';
  17201. t['\uFD69'] = '\u0634\u062C\u064A';
  17202. t['\uFD6A'] = '\u0634\u0645\u062E';
  17203. t['\uFD6B'] = '\u0634\u0645\u062E';
  17204. t['\uFD6C'] = '\u0634\u0645\u0645';
  17205. t['\uFD6D'] = '\u0634\u0645\u0645';
  17206. t['\uFD6E'] = '\u0636\u062D\u0649';
  17207. t['\uFD6F'] = '\u0636\u062E\u0645';
  17208. t['\uFD70'] = '\u0636\u062E\u0645';
  17209. t['\uFD71'] = '\u0637\u0645\u062D';
  17210. t['\uFD72'] = '\u0637\u0645\u062D';
  17211. t['\uFD73'] = '\u0637\u0645\u0645';
  17212. t['\uFD74'] = '\u0637\u0645\u064A';
  17213. t['\uFD75'] = '\u0639\u062C\u0645';
  17214. t['\uFD76'] = '\u0639\u0645\u0645';
  17215. t['\uFD77'] = '\u0639\u0645\u0645';
  17216. t['\uFD78'] = '\u0639\u0645\u0649';
  17217. t['\uFD79'] = '\u063A\u0645\u0645';
  17218. t['\uFD7A'] = '\u063A\u0645\u064A';
  17219. t['\uFD7B'] = '\u063A\u0645\u0649';
  17220. t['\uFD7C'] = '\u0641\u062E\u0645';
  17221. t['\uFD7D'] = '\u0641\u062E\u0645';
  17222. t['\uFD7E'] = '\u0642\u0645\u062D';
  17223. t['\uFD7F'] = '\u0642\u0645\u0645';
  17224. t['\uFD80'] = '\u0644\u062D\u0645';
  17225. t['\uFD81'] = '\u0644\u062D\u064A';
  17226. t['\uFD82'] = '\u0644\u062D\u0649';
  17227. t['\uFD83'] = '\u0644\u062C\u062C';
  17228. t['\uFD84'] = '\u0644\u062C\u062C';
  17229. t['\uFD85'] = '\u0644\u062E\u0645';
  17230. t['\uFD86'] = '\u0644\u062E\u0645';
  17231. t['\uFD87'] = '\u0644\u0645\u062D';
  17232. t['\uFD88'] = '\u0644\u0645\u062D';
  17233. t['\uFD89'] = '\u0645\u062D\u062C';
  17234. t['\uFD8A'] = '\u0645\u062D\u0645';
  17235. t['\uFD8B'] = '\u0645\u062D\u064A';
  17236. t['\uFD8C'] = '\u0645\u062C\u062D';
  17237. t['\uFD8D'] = '\u0645\u062C\u0645';
  17238. t['\uFD8E'] = '\u0645\u062E\u062C';
  17239. t['\uFD8F'] = '\u0645\u062E\u0645';
  17240. t['\uFD92'] = '\u0645\u062C\u062E';
  17241. t['\uFD93'] = '\u0647\u0645\u062C';
  17242. t['\uFD94'] = '\u0647\u0645\u0645';
  17243. t['\uFD95'] = '\u0646\u062D\u0645';
  17244. t['\uFD96'] = '\u0646\u062D\u0649';
  17245. t['\uFD97'] = '\u0646\u062C\u0645';
  17246. t['\uFD98'] = '\u0646\u062C\u0645';
  17247. t['\uFD99'] = '\u0646\u062C\u0649';
  17248. t['\uFD9A'] = '\u0646\u0645\u064A';
  17249. t['\uFD9B'] = '\u0646\u0645\u0649';
  17250. t['\uFD9C'] = '\u064A\u0645\u0645';
  17251. t['\uFD9D'] = '\u064A\u0645\u0645';
  17252. t['\uFD9E'] = '\u0628\u062E\u064A';
  17253. t['\uFD9F'] = '\u062A\u062C\u064A';
  17254. t['\uFDA0'] = '\u062A\u062C\u0649';
  17255. t['\uFDA1'] = '\u062A\u062E\u064A';
  17256. t['\uFDA2'] = '\u062A\u062E\u0649';
  17257. t['\uFDA3'] = '\u062A\u0645\u064A';
  17258. t['\uFDA4'] = '\u062A\u0645\u0649';
  17259. t['\uFDA5'] = '\u062C\u0645\u064A';
  17260. t['\uFDA6'] = '\u062C\u062D\u0649';
  17261. t['\uFDA7'] = '\u062C\u0645\u0649';
  17262. t['\uFDA8'] = '\u0633\u062E\u0649';
  17263. t['\uFDA9'] = '\u0635\u062D\u064A';
  17264. t['\uFDAA'] = '\u0634\u062D\u064A';
  17265. t['\uFDAB'] = '\u0636\u062D\u064A';
  17266. t['\uFDAC'] = '\u0644\u062C\u064A';
  17267. t['\uFDAD'] = '\u0644\u0645\u064A';
  17268. t['\uFDAE'] = '\u064A\u062D\u064A';
  17269. t['\uFDAF'] = '\u064A\u062C\u064A';
  17270. t['\uFDB0'] = '\u064A\u0645\u064A';
  17271. t['\uFDB1'] = '\u0645\u0645\u064A';
  17272. t['\uFDB2'] = '\u0642\u0645\u064A';
  17273. t['\uFDB3'] = '\u0646\u062D\u064A';
  17274. t['\uFDB4'] = '\u0642\u0645\u062D';
  17275. t['\uFDB5'] = '\u0644\u062D\u0645';
  17276. t['\uFDB6'] = '\u0639\u0645\u064A';
  17277. t['\uFDB7'] = '\u0643\u0645\u064A';
  17278. t['\uFDB8'] = '\u0646\u062C\u062D';
  17279. t['\uFDB9'] = '\u0645\u062E\u064A';
  17280. t['\uFDBA'] = '\u0644\u062C\u0645';
  17281. t['\uFDBB'] = '\u0643\u0645\u0645';
  17282. t['\uFDBC'] = '\u0644\u062C\u0645';
  17283. t['\uFDBD'] = '\u0646\u062C\u062D';
  17284. t['\uFDBE'] = '\u062C\u062D\u064A';
  17285. t['\uFDBF'] = '\u062D\u062C\u064A';
  17286. t['\uFDC0'] = '\u0645\u062C\u064A';
  17287. t['\uFDC1'] = '\u0641\u0645\u064A';
  17288. t['\uFDC2'] = '\u0628\u062D\u064A';
  17289. t['\uFDC3'] = '\u0643\u0645\u0645';
  17290. t['\uFDC4'] = '\u0639\u062C\u0645';
  17291. t['\uFDC5'] = '\u0635\u0645\u0645';
  17292. t['\uFDC6'] = '\u0633\u062E\u064A';
  17293. t['\uFDC7'] = '\u0646\u062C\u064A';
  17294. t['\uFE49'] = '\u203E';
  17295. t['\uFE4A'] = '\u203E';
  17296. t['\uFE4B'] = '\u203E';
  17297. t['\uFE4C'] = '\u203E';
  17298. t['\uFE4D'] = '\u005F';
  17299. t['\uFE4E'] = '\u005F';
  17300. t['\uFE4F'] = '\u005F';
  17301. t['\uFE80'] = '\u0621';
  17302. t['\uFE81'] = '\u0622';
  17303. t['\uFE82'] = '\u0622';
  17304. t['\uFE83'] = '\u0623';
  17305. t['\uFE84'] = '\u0623';
  17306. t['\uFE85'] = '\u0624';
  17307. t['\uFE86'] = '\u0624';
  17308. t['\uFE87'] = '\u0625';
  17309. t['\uFE88'] = '\u0625';
  17310. t['\uFE89'] = '\u0626';
  17311. t['\uFE8A'] = '\u0626';
  17312. t['\uFE8B'] = '\u0626';
  17313. t['\uFE8C'] = '\u0626';
  17314. t['\uFE8D'] = '\u0627';
  17315. t['\uFE8E'] = '\u0627';
  17316. t['\uFE8F'] = '\u0628';
  17317. t['\uFE90'] = '\u0628';
  17318. t['\uFE91'] = '\u0628';
  17319. t['\uFE92'] = '\u0628';
  17320. t['\uFE93'] = '\u0629';
  17321. t['\uFE94'] = '\u0629';
  17322. t['\uFE95'] = '\u062A';
  17323. t['\uFE96'] = '\u062A';
  17324. t['\uFE97'] = '\u062A';
  17325. t['\uFE98'] = '\u062A';
  17326. t['\uFE99'] = '\u062B';
  17327. t['\uFE9A'] = '\u062B';
  17328. t['\uFE9B'] = '\u062B';
  17329. t['\uFE9C'] = '\u062B';
  17330. t['\uFE9D'] = '\u062C';
  17331. t['\uFE9E'] = '\u062C';
  17332. t['\uFE9F'] = '\u062C';
  17333. t['\uFEA0'] = '\u062C';
  17334. t['\uFEA1'] = '\u062D';
  17335. t['\uFEA2'] = '\u062D';
  17336. t['\uFEA3'] = '\u062D';
  17337. t['\uFEA4'] = '\u062D';
  17338. t['\uFEA5'] = '\u062E';
  17339. t['\uFEA6'] = '\u062E';
  17340. t['\uFEA7'] = '\u062E';
  17341. t['\uFEA8'] = '\u062E';
  17342. t['\uFEA9'] = '\u062F';
  17343. t['\uFEAA'] = '\u062F';
  17344. t['\uFEAB'] = '\u0630';
  17345. t['\uFEAC'] = '\u0630';
  17346. t['\uFEAD'] = '\u0631';
  17347. t['\uFEAE'] = '\u0631';
  17348. t['\uFEAF'] = '\u0632';
  17349. t['\uFEB0'] = '\u0632';
  17350. t['\uFEB1'] = '\u0633';
  17351. t['\uFEB2'] = '\u0633';
  17352. t['\uFEB3'] = '\u0633';
  17353. t['\uFEB4'] = '\u0633';
  17354. t['\uFEB5'] = '\u0634';
  17355. t['\uFEB6'] = '\u0634';
  17356. t['\uFEB7'] = '\u0634';
  17357. t['\uFEB8'] = '\u0634';
  17358. t['\uFEB9'] = '\u0635';
  17359. t['\uFEBA'] = '\u0635';
  17360. t['\uFEBB'] = '\u0635';
  17361. t['\uFEBC'] = '\u0635';
  17362. t['\uFEBD'] = '\u0636';
  17363. t['\uFEBE'] = '\u0636';
  17364. t['\uFEBF'] = '\u0636';
  17365. t['\uFEC0'] = '\u0636';
  17366. t['\uFEC1'] = '\u0637';
  17367. t['\uFEC2'] = '\u0637';
  17368. t['\uFEC3'] = '\u0637';
  17369. t['\uFEC4'] = '\u0637';
  17370. t['\uFEC5'] = '\u0638';
  17371. t['\uFEC6'] = '\u0638';
  17372. t['\uFEC7'] = '\u0638';
  17373. t['\uFEC8'] = '\u0638';
  17374. t['\uFEC9'] = '\u0639';
  17375. t['\uFECA'] = '\u0639';
  17376. t['\uFECB'] = '\u0639';
  17377. t['\uFECC'] = '\u0639';
  17378. t['\uFECD'] = '\u063A';
  17379. t['\uFECE'] = '\u063A';
  17380. t['\uFECF'] = '\u063A';
  17381. t['\uFED0'] = '\u063A';
  17382. t['\uFED1'] = '\u0641';
  17383. t['\uFED2'] = '\u0641';
  17384. t['\uFED3'] = '\u0641';
  17385. t['\uFED4'] = '\u0641';
  17386. t['\uFED5'] = '\u0642';
  17387. t['\uFED6'] = '\u0642';
  17388. t['\uFED7'] = '\u0642';
  17389. t['\uFED8'] = '\u0642';
  17390. t['\uFED9'] = '\u0643';
  17391. t['\uFEDA'] = '\u0643';
  17392. t['\uFEDB'] = '\u0643';
  17393. t['\uFEDC'] = '\u0643';
  17394. t['\uFEDD'] = '\u0644';
  17395. t['\uFEDE'] = '\u0644';
  17396. t['\uFEDF'] = '\u0644';
  17397. t['\uFEE0'] = '\u0644';
  17398. t['\uFEE1'] = '\u0645';
  17399. t['\uFEE2'] = '\u0645';
  17400. t['\uFEE3'] = '\u0645';
  17401. t['\uFEE4'] = '\u0645';
  17402. t['\uFEE5'] = '\u0646';
  17403. t['\uFEE6'] = '\u0646';
  17404. t['\uFEE7'] = '\u0646';
  17405. t['\uFEE8'] = '\u0646';
  17406. t['\uFEE9'] = '\u0647';
  17407. t['\uFEEA'] = '\u0647';
  17408. t['\uFEEB'] = '\u0647';
  17409. t['\uFEEC'] = '\u0647';
  17410. t['\uFEED'] = '\u0648';
  17411. t['\uFEEE'] = '\u0648';
  17412. t['\uFEEF'] = '\u0649';
  17413. t['\uFEF0'] = '\u0649';
  17414. t['\uFEF1'] = '\u064A';
  17415. t['\uFEF2'] = '\u064A';
  17416. t['\uFEF3'] = '\u064A';
  17417. t['\uFEF4'] = '\u064A';
  17418. t['\uFEF5'] = '\u0644\u0622';
  17419. t['\uFEF6'] = '\u0644\u0622';
  17420. t['\uFEF7'] = '\u0644\u0623';
  17421. t['\uFEF8'] = '\u0644\u0623';
  17422. t['\uFEF9'] = '\u0644\u0625';
  17423. t['\uFEFA'] = '\u0644\u0625';
  17424. t['\uFEFB'] = '\u0644\u0627';
  17425. t['\uFEFC'] = '\u0644\u0627';
  17426. });
  17427. function reverseIfRtl(chars) {
  17428. var charsLength = chars.length;
  17429. //reverse an arabic ligature
  17430. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  17431. return chars;
  17432. }
  17433. var s = '';
  17434. for (var ii = charsLength - 1; ii >= 0; ii--) {
  17435. s += chars[ii];
  17436. }
  17437. return s;
  17438. }
  17439. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  17440. exports.reverseIfRtl = reverseIfRtl;
  17441. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  17442. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  17443. }));
  17444. (function (root, factory) {
  17445. {
  17446. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  17447. root.pdfjsDisplayDOMUtils);
  17448. }
  17449. }(this, function (exports, sharedUtil, displayDOMUtils) {
  17450. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  17451. var AnnotationType = sharedUtil.AnnotationType;
  17452. var Util = sharedUtil.Util;
  17453. var addLinkAttributes = sharedUtil.addLinkAttributes;
  17454. var getFilenameFromUrl = sharedUtil.getFilenameFromUrl;
  17455. var warn = sharedUtil.warn;
  17456. var CustomStyle = displayDOMUtils.CustomStyle;
  17457. /**
  17458. * @typedef {Object} AnnotationElementParameters
  17459. * @property {Object} data
  17460. * @property {HTMLDivElement} layer
  17461. * @property {PDFPage} page
  17462. * @property {PageViewport} viewport
  17463. * @property {IPDFLinkService} linkService
  17464. * @property {DownloadManager} downloadManager
  17465. */
  17466. /**
  17467. * @class
  17468. * @alias AnnotationElementFactory
  17469. */
  17470. function AnnotationElementFactory() {}
  17471. AnnotationElementFactory.prototype =
  17472. /** @lends AnnotationElementFactory.prototype */ {
  17473. /**
  17474. * @param {AnnotationElementParameters} parameters
  17475. * @returns {AnnotationElement}
  17476. */
  17477. create: function AnnotationElementFactory_create(parameters) {
  17478. var subtype = parameters.data.annotationType;
  17479. switch (subtype) {
  17480. case AnnotationType.LINK:
  17481. return new LinkAnnotationElement(parameters);
  17482. case AnnotationType.TEXT:
  17483. return new TextAnnotationElement(parameters);
  17484. case AnnotationType.WIDGET:
  17485. return new WidgetAnnotationElement(parameters);
  17486. case AnnotationType.POPUP:
  17487. return new PopupAnnotationElement(parameters);
  17488. case AnnotationType.HIGHLIGHT:
  17489. return new HighlightAnnotationElement(parameters);
  17490. case AnnotationType.UNDERLINE:
  17491. return new UnderlineAnnotationElement(parameters);
  17492. case AnnotationType.SQUIGGLY:
  17493. return new SquigglyAnnotationElement(parameters);
  17494. case AnnotationType.STRIKEOUT:
  17495. return new StrikeOutAnnotationElement(parameters);
  17496. case AnnotationType.FILEATTACHMENT:
  17497. return new FileAttachmentAnnotationElement(parameters);
  17498. default:
  17499. return new AnnotationElement(parameters);
  17500. }
  17501. }
  17502. };
  17503. /**
  17504. * @class
  17505. * @alias AnnotationElement
  17506. */
  17507. var AnnotationElement = (function AnnotationElementClosure() {
  17508. function AnnotationElement(parameters, isRenderable) {
  17509. this.isRenderable = isRenderable || false;
  17510. this.data = parameters.data;
  17511. this.layer = parameters.layer;
  17512. this.page = parameters.page;
  17513. this.viewport = parameters.viewport;
  17514. this.linkService = parameters.linkService;
  17515. this.downloadManager = parameters.downloadManager;
  17516. if (isRenderable) {
  17517. this.container = this._createContainer();
  17518. }
  17519. }
  17520. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  17521. /**
  17522. * Create an empty container for the annotation's HTML element.
  17523. *
  17524. * @private
  17525. * @memberof AnnotationElement
  17526. * @returns {HTMLSectionElement}
  17527. */
  17528. _createContainer: function AnnotationElement_createContainer() {
  17529. var data = this.data, page = this.page, viewport = this.viewport;
  17530. var container = document.createElement('section');
  17531. var width = data.rect[2] - data.rect[0];
  17532. var height = data.rect[3] - data.rect[1];
  17533. container.setAttribute('data-annotation-id', data.id);
  17534. // Do *not* modify `data.rect`, since that will corrupt the annotation
  17535. // position on subsequent calls to `_createContainer` (see issue 6804).
  17536. var rect = Util.normalizeRect([
  17537. data.rect[0],
  17538. page.view[3] - data.rect[1] + page.view[1],
  17539. data.rect[2],
  17540. page.view[3] - data.rect[3] + page.view[1]
  17541. ]);
  17542. CustomStyle.setProp('transform', container,
  17543. 'matrix(' + viewport.transform.join(',') + ')');
  17544. CustomStyle.setProp('transformOrigin', container,
  17545. -rect[0] + 'px ' + -rect[1] + 'px');
  17546. if (data.borderStyle.width > 0) {
  17547. container.style.borderWidth = data.borderStyle.width + 'px';
  17548. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  17549. // Underline styles only have a bottom border, so we do not need
  17550. // to adjust for all borders. This yields a similar result as
  17551. // Adobe Acrobat/Reader.
  17552. width = width - 2 * data.borderStyle.width;
  17553. height = height - 2 * data.borderStyle.width;
  17554. }
  17555. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  17556. var verticalRadius = data.borderStyle.verticalCornerRadius;
  17557. if (horizontalRadius > 0 || verticalRadius > 0) {
  17558. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  17559. CustomStyle.setProp('borderRadius', container, radius);
  17560. }
  17561. switch (data.borderStyle.style) {
  17562. case AnnotationBorderStyleType.SOLID:
  17563. container.style.borderStyle = 'solid';
  17564. break;
  17565. case AnnotationBorderStyleType.DASHED:
  17566. container.style.borderStyle = 'dashed';
  17567. break;
  17568. case AnnotationBorderStyleType.BEVELED:
  17569. warn('Unimplemented border style: beveled');
  17570. break;
  17571. case AnnotationBorderStyleType.INSET:
  17572. warn('Unimplemented border style: inset');
  17573. break;
  17574. case AnnotationBorderStyleType.UNDERLINE:
  17575. container.style.borderBottomStyle = 'solid';
  17576. break;
  17577. default:
  17578. break;
  17579. }
  17580. if (data.color) {
  17581. container.style.borderColor =
  17582. Util.makeCssRgb(data.color[0] | 0,
  17583. data.color[1] | 0,
  17584. data.color[2] | 0);
  17585. } else {
  17586. // Transparent (invisible) border, so do not draw it at all.
  17587. container.style.borderWidth = 0;
  17588. }
  17589. }
  17590. container.style.left = rect[0] + 'px';
  17591. container.style.top = rect[1] + 'px';
  17592. container.style.width = width + 'px';
  17593. container.style.height = height + 'px';
  17594. return container;
  17595. },
  17596. /**
  17597. * Create a popup for the annotation's HTML element. This is used for
  17598. * annotations that do not have a Popup entry in the dictionary, but
  17599. * are of a type that works with popups (such as Highlight annotations).
  17600. *
  17601. * @private
  17602. * @param {HTMLSectionElement} container
  17603. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  17604. * @param {Object} data
  17605. * @memberof AnnotationElement
  17606. */
  17607. _createPopup:
  17608. function AnnotationElement_createPopup(container, trigger, data) {
  17609. // If no trigger element is specified, create it.
  17610. if (!trigger) {
  17611. trigger = document.createElement('div');
  17612. trigger.style.height = container.style.height;
  17613. trigger.style.width = container.style.width;
  17614. container.appendChild(trigger);
  17615. }
  17616. var popupElement = new PopupElement({
  17617. container: container,
  17618. trigger: trigger,
  17619. color: data.color,
  17620. title: data.title,
  17621. contents: data.contents,
  17622. hideWrapper: true
  17623. });
  17624. var popup = popupElement.render();
  17625. // Position the popup next to the annotation's container.
  17626. popup.style.left = container.style.width;
  17627. container.appendChild(popup);
  17628. },
  17629. /**
  17630. * Render the annotation's HTML element in the empty container.
  17631. *
  17632. * @public
  17633. * @memberof AnnotationElement
  17634. */
  17635. render: function AnnotationElement_render() {
  17636. throw new Error('Abstract method AnnotationElement.render called');
  17637. }
  17638. };
  17639. return AnnotationElement;
  17640. })();
  17641. /**
  17642. * @class
  17643. * @alias LinkAnnotationElement
  17644. */
  17645. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  17646. function LinkAnnotationElement(parameters) {
  17647. AnnotationElement.call(this, parameters, true);
  17648. }
  17649. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  17650. /**
  17651. * Render the link annotation's HTML element in the empty container.
  17652. *
  17653. * @public
  17654. * @memberof LinkAnnotationElement
  17655. * @returns {HTMLSectionElement}
  17656. */
  17657. render: function LinkAnnotationElement_render() {
  17658. this.container.className = 'linkAnnotation';
  17659. var link = document.createElement('a');
  17660. addLinkAttributes(link, { url: this.data.url });
  17661. if (!this.data.url) {
  17662. if (this.data.action) {
  17663. this._bindNamedAction(link, this.data.action);
  17664. } else {
  17665. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  17666. }
  17667. }
  17668. this.container.appendChild(link);
  17669. return this.container;
  17670. },
  17671. /**
  17672. * Bind internal links to the link element.
  17673. *
  17674. * @private
  17675. * @param {Object} link
  17676. * @param {Object} destination
  17677. * @memberof LinkAnnotationElement
  17678. */
  17679. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  17680. var self = this;
  17681. link.href = this.linkService.getDestinationHash(destination);
  17682. link.onclick = function() {
  17683. if (destination) {
  17684. self.linkService.navigateTo(destination);
  17685. }
  17686. return false;
  17687. };
  17688. if (destination) {
  17689. link.className = 'internalLink';
  17690. }
  17691. },
  17692. /**
  17693. * Bind named actions to the link element.
  17694. *
  17695. * @private
  17696. * @param {Object} link
  17697. * @param {Object} action
  17698. * @memberof LinkAnnotationElement
  17699. */
  17700. _bindNamedAction:
  17701. function LinkAnnotationElement_bindNamedAction(link, action) {
  17702. var self = this;
  17703. link.href = this.linkService.getAnchorUrl('');
  17704. link.onclick = function() {
  17705. self.linkService.executeNamedAction(action);
  17706. return false;
  17707. };
  17708. link.className = 'internalLink';
  17709. }
  17710. });
  17711. return LinkAnnotationElement;
  17712. })();
  17713. /**
  17714. * @class
  17715. * @alias TextAnnotationElement
  17716. */
  17717. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  17718. function TextAnnotationElement(parameters) {
  17719. var isRenderable = !!(parameters.data.hasPopup ||
  17720. parameters.data.title || parameters.data.contents);
  17721. AnnotationElement.call(this, parameters, isRenderable);
  17722. }
  17723. Util.inherit(TextAnnotationElement, AnnotationElement, {
  17724. /**
  17725. * Render the text annotation's HTML element in the empty container.
  17726. *
  17727. * @public
  17728. * @memberof TextAnnotationElement
  17729. * @returns {HTMLSectionElement}
  17730. */
  17731. render: function TextAnnotationElement_render() {
  17732. this.container.className = 'textAnnotation';
  17733. var image = document.createElement('img');
  17734. image.style.height = this.container.style.height;
  17735. image.style.width = this.container.style.width;
  17736. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  17737. this.data.name.toLowerCase() + '.svg';
  17738. image.alt = '[{{type}} Annotation]';
  17739. image.dataset.l10nId = 'text_annotation_type';
  17740. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  17741. if (!this.data.hasPopup) {
  17742. this._createPopup(this.container, image, this.data);
  17743. }
  17744. this.container.appendChild(image);
  17745. return this.container;
  17746. }
  17747. });
  17748. return TextAnnotationElement;
  17749. })();
  17750. /**
  17751. * @class
  17752. * @alias WidgetAnnotationElement
  17753. */
  17754. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  17755. function WidgetAnnotationElement(parameters) {
  17756. var isRenderable = !parameters.data.hasAppearance &&
  17757. !!parameters.data.fieldValue;
  17758. AnnotationElement.call(this, parameters, isRenderable);
  17759. }
  17760. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  17761. /**
  17762. * Render the widget annotation's HTML element in the empty container.
  17763. *
  17764. * @public
  17765. * @memberof WidgetAnnotationElement
  17766. * @returns {HTMLSectionElement}
  17767. */
  17768. render: function WidgetAnnotationElement_render() {
  17769. var content = document.createElement('div');
  17770. content.textContent = this.data.fieldValue;
  17771. var textAlignment = this.data.textAlignment;
  17772. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  17773. content.style.verticalAlign = 'middle';
  17774. content.style.display = 'table-cell';
  17775. var font = (this.data.fontRefName ?
  17776. this.page.commonObjs.getData(this.data.fontRefName) : null);
  17777. this._setTextStyle(content, font);
  17778. this.container.appendChild(content);
  17779. return this.container;
  17780. },
  17781. /**
  17782. * Apply text styles to the text in the element.
  17783. *
  17784. * @private
  17785. * @param {HTMLDivElement} element
  17786. * @param {Object} font
  17787. * @memberof WidgetAnnotationElement
  17788. */
  17789. _setTextStyle:
  17790. function WidgetAnnotationElement_setTextStyle(element, font) {
  17791. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  17792. var style = element.style;
  17793. style.fontSize = this.data.fontSize + 'px';
  17794. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  17795. if (!font) {
  17796. return;
  17797. }
  17798. style.fontWeight = (font.black ?
  17799. (font.bold ? '900' : 'bold') :
  17800. (font.bold ? 'bold' : 'normal'));
  17801. style.fontStyle = (font.italic ? 'italic' : 'normal');
  17802. // Use a reasonable default font if the font doesn't specify a fallback.
  17803. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  17804. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  17805. style.fontFamily = fontFamily + fallbackName;
  17806. }
  17807. });
  17808. return WidgetAnnotationElement;
  17809. })();
  17810. /**
  17811. * @class
  17812. * @alias PopupAnnotationElement
  17813. */
  17814. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  17815. function PopupAnnotationElement(parameters) {
  17816. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  17817. AnnotationElement.call(this, parameters, isRenderable);
  17818. }
  17819. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  17820. /**
  17821. * Render the popup annotation's HTML element in the empty container.
  17822. *
  17823. * @public
  17824. * @memberof PopupAnnotationElement
  17825. * @returns {HTMLSectionElement}
  17826. */
  17827. render: function PopupAnnotationElement_render() {
  17828. this.container.className = 'popupAnnotation';
  17829. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  17830. var parentElement = this.layer.querySelector(selector);
  17831. if (!parentElement) {
  17832. return this.container;
  17833. }
  17834. var popup = new PopupElement({
  17835. container: this.container,
  17836. trigger: parentElement,
  17837. color: this.data.color,
  17838. title: this.data.title,
  17839. contents: this.data.contents
  17840. });
  17841. // Position the popup next to the parent annotation's container.
  17842. // PDF viewers ignore a popup annotation's rectangle.
  17843. var parentLeft = parseFloat(parentElement.style.left);
  17844. var parentWidth = parseFloat(parentElement.style.width);
  17845. CustomStyle.setProp('transformOrigin', this.container,
  17846. -(parentLeft + parentWidth) + 'px -' +
  17847. parentElement.style.top);
  17848. this.container.style.left = (parentLeft + parentWidth) + 'px';
  17849. this.container.appendChild(popup.render());
  17850. return this.container;
  17851. }
  17852. });
  17853. return PopupAnnotationElement;
  17854. })();
  17855. /**
  17856. * @class
  17857. * @alias PopupElement
  17858. */
  17859. var PopupElement = (function PopupElementClosure() {
  17860. var BACKGROUND_ENLIGHT = 0.7;
  17861. function PopupElement(parameters) {
  17862. this.container = parameters.container;
  17863. this.trigger = parameters.trigger;
  17864. this.color = parameters.color;
  17865. this.title = parameters.title;
  17866. this.contents = parameters.contents;
  17867. this.hideWrapper = parameters.hideWrapper || false;
  17868. this.pinned = false;
  17869. }
  17870. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  17871. /**
  17872. * Render the popup's HTML element.
  17873. *
  17874. * @public
  17875. * @memberof PopupElement
  17876. * @returns {HTMLSectionElement}
  17877. */
  17878. render: function PopupElement_render() {
  17879. var wrapper = document.createElement('div');
  17880. wrapper.className = 'popupWrapper';
  17881. // For Popup annotations we hide the entire section because it contains
  17882. // only the popup. However, for Text annotations without a separate Popup
  17883. // annotation, we cannot hide the entire container as the image would
  17884. // disappear too. In that special case, hiding the wrapper suffices.
  17885. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  17886. this.hideElement.setAttribute('hidden', true);
  17887. var popup = document.createElement('div');
  17888. popup.className = 'popup';
  17889. var color = this.color;
  17890. if (color) {
  17891. // Enlighten the color.
  17892. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  17893. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  17894. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  17895. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  17896. }
  17897. var contents = this._formatContents(this.contents);
  17898. var title = document.createElement('h1');
  17899. title.textContent = this.title;
  17900. // Attach the event listeners to the trigger element.
  17901. this.trigger.addEventListener('click', this._toggle.bind(this));
  17902. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  17903. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  17904. popup.addEventListener('click', this._hide.bind(this, true));
  17905. popup.appendChild(title);
  17906. popup.appendChild(contents);
  17907. wrapper.appendChild(popup);
  17908. return wrapper;
  17909. },
  17910. /**
  17911. * Format the contents of the popup by adding newlines where necessary.
  17912. *
  17913. * @private
  17914. * @param {string} contents
  17915. * @memberof PopupElement
  17916. * @returns {HTMLParagraphElement}
  17917. */
  17918. _formatContents: function PopupElement_formatContents(contents) {
  17919. var p = document.createElement('p');
  17920. var lines = contents.split(/(?:\r\n?|\n)/);
  17921. for (var i = 0, ii = lines.length; i < ii; ++i) {
  17922. var line = lines[i];
  17923. p.appendChild(document.createTextNode(line));
  17924. if (i < (ii - 1)) {
  17925. p.appendChild(document.createElement('br'));
  17926. }
  17927. }
  17928. return p;
  17929. },
  17930. /**
  17931. * Toggle the visibility of the popup.
  17932. *
  17933. * @private
  17934. * @memberof PopupElement
  17935. */
  17936. _toggle: function PopupElement_toggle() {
  17937. if (this.pinned) {
  17938. this._hide(true);
  17939. } else {
  17940. this._show(true);
  17941. }
  17942. },
  17943. /**
  17944. * Show the popup.
  17945. *
  17946. * @private
  17947. * @param {boolean} pin
  17948. * @memberof PopupElement
  17949. */
  17950. _show: function PopupElement_show(pin) {
  17951. if (pin) {
  17952. this.pinned = true;
  17953. }
  17954. if (this.hideElement.hasAttribute('hidden')) {
  17955. this.hideElement.removeAttribute('hidden');
  17956. this.container.style.zIndex += 1;
  17957. }
  17958. },
  17959. /**
  17960. * Hide the popup.
  17961. *
  17962. * @private
  17963. * @param {boolean} unpin
  17964. * @memberof PopupElement
  17965. */
  17966. _hide: function PopupElement_hide(unpin) {
  17967. if (unpin) {
  17968. this.pinned = false;
  17969. }
  17970. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  17971. this.hideElement.setAttribute('hidden', true);
  17972. this.container.style.zIndex -= 1;
  17973. }
  17974. }
  17975. };
  17976. return PopupElement;
  17977. })();
  17978. /**
  17979. * @class
  17980. * @alias HighlightAnnotationElement
  17981. */
  17982. var HighlightAnnotationElement = (
  17983. function HighlightAnnotationElementClosure() {
  17984. function HighlightAnnotationElement(parameters) {
  17985. var isRenderable = !!(parameters.data.hasPopup ||
  17986. parameters.data.title || parameters.data.contents);
  17987. AnnotationElement.call(this, parameters, isRenderable);
  17988. }
  17989. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  17990. /**
  17991. * Render the highlight annotation's HTML element in the empty container.
  17992. *
  17993. * @public
  17994. * @memberof HighlightAnnotationElement
  17995. * @returns {HTMLSectionElement}
  17996. */
  17997. render: function HighlightAnnotationElement_render() {
  17998. this.container.className = 'highlightAnnotation';
  17999. if (!this.data.hasPopup) {
  18000. this._createPopup(this.container, null, this.data);
  18001. }
  18002. return this.container;
  18003. }
  18004. });
  18005. return HighlightAnnotationElement;
  18006. })();
  18007. /**
  18008. * @class
  18009. * @alias UnderlineAnnotationElement
  18010. */
  18011. var UnderlineAnnotationElement = (
  18012. function UnderlineAnnotationElementClosure() {
  18013. function UnderlineAnnotationElement(parameters) {
  18014. var isRenderable = !!(parameters.data.hasPopup ||
  18015. parameters.data.title || parameters.data.contents);
  18016. AnnotationElement.call(this, parameters, isRenderable);
  18017. }
  18018. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  18019. /**
  18020. * Render the underline annotation's HTML element in the empty container.
  18021. *
  18022. * @public
  18023. * @memberof UnderlineAnnotationElement
  18024. * @returns {HTMLSectionElement}
  18025. */
  18026. render: function UnderlineAnnotationElement_render() {
  18027. this.container.className = 'underlineAnnotation';
  18028. if (!this.data.hasPopup) {
  18029. this._createPopup(this.container, null, this.data);
  18030. }
  18031. return this.container;
  18032. }
  18033. });
  18034. return UnderlineAnnotationElement;
  18035. })();
  18036. /**
  18037. * @class
  18038. * @alias SquigglyAnnotationElement
  18039. */
  18040. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  18041. function SquigglyAnnotationElement(parameters) {
  18042. var isRenderable = !!(parameters.data.hasPopup ||
  18043. parameters.data.title || parameters.data.contents);
  18044. AnnotationElement.call(this, parameters, isRenderable);
  18045. }
  18046. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  18047. /**
  18048. * Render the squiggly annotation's HTML element in the empty container.
  18049. *
  18050. * @public
  18051. * @memberof SquigglyAnnotationElement
  18052. * @returns {HTMLSectionElement}
  18053. */
  18054. render: function SquigglyAnnotationElement_render() {
  18055. this.container.className = 'squigglyAnnotation';
  18056. if (!this.data.hasPopup) {
  18057. this._createPopup(this.container, null, this.data);
  18058. }
  18059. return this.container;
  18060. }
  18061. });
  18062. return SquigglyAnnotationElement;
  18063. })();
  18064. /**
  18065. * @class
  18066. * @alias StrikeOutAnnotationElement
  18067. */
  18068. var StrikeOutAnnotationElement = (
  18069. function StrikeOutAnnotationElementClosure() {
  18070. function StrikeOutAnnotationElement(parameters) {
  18071. var isRenderable = !!(parameters.data.hasPopup ||
  18072. parameters.data.title || parameters.data.contents);
  18073. AnnotationElement.call(this, parameters, isRenderable);
  18074. }
  18075. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  18076. /**
  18077. * Render the strikeout annotation's HTML element in the empty container.
  18078. *
  18079. * @public
  18080. * @memberof StrikeOutAnnotationElement
  18081. * @returns {HTMLSectionElement}
  18082. */
  18083. render: function StrikeOutAnnotationElement_render() {
  18084. this.container.className = 'strikeoutAnnotation';
  18085. if (!this.data.hasPopup) {
  18086. this._createPopup(this.container, null, this.data);
  18087. }
  18088. return this.container;
  18089. }
  18090. });
  18091. return StrikeOutAnnotationElement;
  18092. })();
  18093. /**
  18094. * @class
  18095. * @alias FileAttachmentAnnotationElement
  18096. */
  18097. var FileAttachmentAnnotationElement = (
  18098. function FileAttachmentAnnotationElementClosure() {
  18099. function FileAttachmentAnnotationElement(parameters) {
  18100. AnnotationElement.call(this, parameters, true);
  18101. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  18102. this.content = parameters.data.file.content;
  18103. }
  18104. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  18105. /**
  18106. * Render the file attachment annotation's HTML element in the empty
  18107. * container.
  18108. *
  18109. * @public
  18110. * @memberof FileAttachmentAnnotationElement
  18111. * @returns {HTMLSectionElement}
  18112. */
  18113. render: function FileAttachmentAnnotationElement_render() {
  18114. this.container.className = 'fileAttachmentAnnotation';
  18115. var trigger = document.createElement('div');
  18116. trigger.style.height = this.container.style.height;
  18117. trigger.style.width = this.container.style.width;
  18118. trigger.addEventListener('dblclick', this._download.bind(this));
  18119. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  18120. this._createPopup(this.container, trigger, this.data);
  18121. }
  18122. this.container.appendChild(trigger);
  18123. return this.container;
  18124. },
  18125. /**
  18126. * Download the file attachment associated with this annotation.
  18127. *
  18128. * @private
  18129. * @memberof FileAttachmentAnnotationElement
  18130. */
  18131. _download: function FileAttachmentAnnotationElement_download() {
  18132. if (!this.downloadManager) {
  18133. warn('Download cannot be started due to unavailable download manager');
  18134. return;
  18135. }
  18136. this.downloadManager.downloadData(this.content, this.filename, '');
  18137. }
  18138. });
  18139. return FileAttachmentAnnotationElement;
  18140. })();
  18141. /**
  18142. * @typedef {Object} AnnotationLayerParameters
  18143. * @property {PageViewport} viewport
  18144. * @property {HTMLDivElement} div
  18145. * @property {Array} annotations
  18146. * @property {PDFPage} page
  18147. * @property {IPDFLinkService} linkService
  18148. */
  18149. /**
  18150. * @class
  18151. * @alias AnnotationLayer
  18152. */
  18153. var AnnotationLayer = (function AnnotationLayerClosure() {
  18154. return {
  18155. /**
  18156. * Render a new annotation layer with all annotation elements.
  18157. *
  18158. * @public
  18159. * @param {AnnotationLayerParameters} parameters
  18160. * @memberof AnnotationLayer
  18161. */
  18162. render: function AnnotationLayer_render(parameters) {
  18163. var annotationElementFactory = new AnnotationElementFactory();
  18164. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  18165. var data = parameters.annotations[i];
  18166. if (!data) {
  18167. continue;
  18168. }
  18169. var properties = {
  18170. data: data,
  18171. layer: parameters.div,
  18172. page: parameters.page,
  18173. viewport: parameters.viewport,
  18174. linkService: parameters.linkService,
  18175. downloadManager: parameters.downloadManager
  18176. };
  18177. var element = annotationElementFactory.create(properties);
  18178. if (element.isRenderable) {
  18179. parameters.div.appendChild(element.render());
  18180. }
  18181. }
  18182. },
  18183. /**
  18184. * Update the annotation elements on existing annotation layer.
  18185. *
  18186. * @public
  18187. * @param {AnnotationLayerParameters} parameters
  18188. * @memberof AnnotationLayer
  18189. */
  18190. update: function AnnotationLayer_update(parameters) {
  18191. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  18192. var data = parameters.annotations[i];
  18193. var element = parameters.div.querySelector(
  18194. '[data-annotation-id="' + data.id + '"]');
  18195. if (element) {
  18196. CustomStyle.setProp('transform', element,
  18197. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  18198. }
  18199. }
  18200. parameters.div.removeAttribute('hidden');
  18201. }
  18202. };
  18203. })();
  18204. PDFJS.AnnotationLayer = AnnotationLayer;
  18205. exports.AnnotationLayer = AnnotationLayer;
  18206. }));
  18207. (function (root, factory) {
  18208. {
  18209. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  18210. root.pdfjsSharedGlobal);
  18211. }
  18212. }(this, function (exports, sharedUtil, sharedGlobal) {
  18213. var assert = sharedUtil.assert;
  18214. var bytesToString = sharedUtil.bytesToString;
  18215. var string32 = sharedUtil.string32;
  18216. var shadow = sharedUtil.shadow;
  18217. var warn = sharedUtil.warn;
  18218. var PDFJS = sharedGlobal.PDFJS;
  18219. var globalScope = sharedGlobal.globalScope;
  18220. var isWorker = sharedGlobal.isWorker;
  18221. function FontLoader(docId) {
  18222. this.docId = docId;
  18223. this.styleElement = null;
  18224. this.nativeFontFaces = [];
  18225. this.loadTestFontId = 0;
  18226. this.loadingContext = {
  18227. requests: [],
  18228. nextRequestId: 0
  18229. };
  18230. }
  18231. FontLoader.prototype = {
  18232. insertRule: function fontLoaderInsertRule(rule) {
  18233. var styleElement = this.styleElement;
  18234. if (!styleElement) {
  18235. styleElement = this.styleElement = document.createElement('style');
  18236. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  18237. document.documentElement.getElementsByTagName('head')[0].appendChild(
  18238. styleElement);
  18239. }
  18240. var styleSheet = styleElement.sheet;
  18241. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  18242. },
  18243. clear: function fontLoaderClear() {
  18244. var styleElement = this.styleElement;
  18245. if (styleElement) {
  18246. styleElement.parentNode.removeChild(styleElement);
  18247. styleElement = this.styleElement = null;
  18248. }
  18249. this.nativeFontFaces.forEach(function(nativeFontFace) {
  18250. document.fonts.delete(nativeFontFace);
  18251. });
  18252. this.nativeFontFaces.length = 0;
  18253. },
  18254. get loadTestFont() {
  18255. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  18256. // height.
  18257. return shadow(this, 'loadTestFont', atob(
  18258. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  18259. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  18260. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  18261. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  18262. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  18263. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  18264. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  18265. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  18266. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  18267. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  18268. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  18269. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  18270. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  18271. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18272. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18273. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18274. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  18275. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  18276. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  18277. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  18278. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  18279. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  18280. ));
  18281. },
  18282. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  18283. this.nativeFontFaces.push(nativeFontFace);
  18284. document.fonts.add(nativeFontFace);
  18285. },
  18286. bind: function fontLoaderBind(fonts, callback) {
  18287. assert(!isWorker, 'bind() shall be called from main thread');
  18288. var rules = [];
  18289. var fontsToLoad = [];
  18290. var fontLoadPromises = [];
  18291. var getNativeFontPromise = function(nativeFontFace) {
  18292. // Return a promise that is always fulfilled, even when the font fails to
  18293. // load.
  18294. return nativeFontFace.loaded.catch(function(e) {
  18295. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  18296. });
  18297. };
  18298. for (var i = 0, ii = fonts.length; i < ii; i++) {
  18299. var font = fonts[i];
  18300. // Add the font to the DOM only once or skip if the font
  18301. // is already loaded.
  18302. if (font.attached || font.loading === false) {
  18303. continue;
  18304. }
  18305. font.attached = true;
  18306. if (FontLoader.isFontLoadingAPISupported) {
  18307. var nativeFontFace = font.createNativeFontFace();
  18308. if (nativeFontFace) {
  18309. this.addNativeFontFace(nativeFontFace);
  18310. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  18311. }
  18312. } else {
  18313. var rule = font.createFontFaceRule();
  18314. if (rule) {
  18315. this.insertRule(rule);
  18316. rules.push(rule);
  18317. fontsToLoad.push(font);
  18318. }
  18319. }
  18320. }
  18321. var request = this.queueLoadingCallback(callback);
  18322. if (FontLoader.isFontLoadingAPISupported) {
  18323. Promise.all(fontLoadPromises).then(function() {
  18324. request.complete();
  18325. });
  18326. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  18327. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  18328. } else {
  18329. request.complete();
  18330. }
  18331. },
  18332. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  18333. function LoadLoader_completeRequest() {
  18334. assert(!request.end, 'completeRequest() cannot be called twice');
  18335. request.end = Date.now();
  18336. // sending all completed requests in order how they were queued
  18337. while (context.requests.length > 0 && context.requests[0].end) {
  18338. var otherRequest = context.requests.shift();
  18339. setTimeout(otherRequest.callback, 0);
  18340. }
  18341. }
  18342. var context = this.loadingContext;
  18343. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  18344. var request = {
  18345. id: requestId,
  18346. complete: LoadLoader_completeRequest,
  18347. callback: callback,
  18348. started: Date.now()
  18349. };
  18350. context.requests.push(request);
  18351. return request;
  18352. },
  18353. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  18354. fonts,
  18355. request) {
  18356. /** Hack begin */
  18357. // There's currently no event when a font has finished downloading so the
  18358. // following code is a dirty hack to 'guess' when a font is
  18359. // ready. It's assumed fonts are loaded in order, so add a known test
  18360. // font after the desired fonts and then test for the loading of that
  18361. // test font.
  18362. function int32(data, offset) {
  18363. return (data.charCodeAt(offset) << 24) |
  18364. (data.charCodeAt(offset + 1) << 16) |
  18365. (data.charCodeAt(offset + 2) << 8) |
  18366. (data.charCodeAt(offset + 3) & 0xff);
  18367. }
  18368. function spliceString(s, offset, remove, insert) {
  18369. var chunk1 = s.substr(0, offset);
  18370. var chunk2 = s.substr(offset + remove);
  18371. return chunk1 + insert + chunk2;
  18372. }
  18373. var i, ii;
  18374. var canvas = document.createElement('canvas');
  18375. canvas.width = 1;
  18376. canvas.height = 1;
  18377. var ctx = canvas.getContext('2d');
  18378. var called = 0;
  18379. function isFontReady(name, callback) {
  18380. called++;
  18381. // With setTimeout clamping this gives the font ~100ms to load.
  18382. if(called > 30) {
  18383. warn('Load test font never loaded.');
  18384. callback();
  18385. return;
  18386. }
  18387. ctx.font = '30px ' + name;
  18388. ctx.fillText('.', 0, 20);
  18389. var imageData = ctx.getImageData(0, 0, 1, 1);
  18390. if (imageData.data[3] > 0) {
  18391. callback();
  18392. return;
  18393. }
  18394. setTimeout(isFontReady.bind(null, name, callback));
  18395. }
  18396. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  18397. // Chromium seems to cache fonts based on a hash of the actual font data,
  18398. // so the font must be modified for each load test else it will appear to
  18399. // be loaded already.
  18400. // TODO: This could maybe be made faster by avoiding the btoa of the full
  18401. // font by splitting it in chunks before hand and padding the font id.
  18402. var data = this.loadTestFont;
  18403. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  18404. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  18405. loadTestFontId);
  18406. // CFF checksum is important for IE, adjusting it
  18407. var CFF_CHECKSUM_OFFSET = 16;
  18408. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  18409. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  18410. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  18411. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  18412. }
  18413. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  18414. checksum = (checksum - XXXX_VALUE +
  18415. int32(loadTestFontId + 'XXX', i)) | 0;
  18416. }
  18417. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  18418. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  18419. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  18420. url + '}';
  18421. this.insertRule(rule);
  18422. var names = [];
  18423. for (i = 0, ii = fonts.length; i < ii; i++) {
  18424. names.push(fonts[i].loadedName);
  18425. }
  18426. names.push(loadTestFontId);
  18427. var div = document.createElement('div');
  18428. div.setAttribute('style',
  18429. 'visibility: hidden;' +
  18430. 'width: 10px; height: 10px;' +
  18431. 'position: absolute; top: 0px; left: 0px;');
  18432. for (i = 0, ii = names.length; i < ii; ++i) {
  18433. var span = document.createElement('span');
  18434. span.textContent = 'Hi';
  18435. span.style.fontFamily = names[i];
  18436. div.appendChild(span);
  18437. }
  18438. document.body.appendChild(div);
  18439. isFontReady(loadTestFontId, function() {
  18440. document.body.removeChild(div);
  18441. request.complete();
  18442. });
  18443. /** Hack end */
  18444. }
  18445. };
  18446. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  18447. typeof document !== 'undefined' && !!document.fonts);
  18448. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  18449. get: function () {
  18450. var supported = false;
  18451. // User agent string sniffing is bad, but there is no reliable way to tell
  18452. // if font is fully loaded and ready to be used with canvas.
  18453. var userAgent = window.navigator.userAgent;
  18454. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  18455. if (m && m[1] >= 14) {
  18456. supported = true;
  18457. }
  18458. // TODO other browsers
  18459. if (userAgent === 'node') {
  18460. supported = true;
  18461. }
  18462. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  18463. },
  18464. enumerable: true,
  18465. configurable: true
  18466. });
  18467. var FontFaceObject = (function FontFaceObjectClosure() {
  18468. function FontFaceObject(translatedData) {
  18469. this.compiledGlyphs = Object.create(null);
  18470. // importing translated data
  18471. for (var i in translatedData) {
  18472. this[i] = translatedData[i];
  18473. }
  18474. }
  18475. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  18476. get: function () {
  18477. var evalSupport = false;
  18478. if (PDFJS.isEvalSupported) {
  18479. try {
  18480. /* jshint evil: true */
  18481. new Function('');
  18482. evalSupport = true;
  18483. } catch (e) {}
  18484. }
  18485. return shadow(this, 'isEvalSupported', evalSupport);
  18486. },
  18487. enumerable: true,
  18488. configurable: true
  18489. });
  18490. FontFaceObject.prototype = {
  18491. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  18492. if (!this.data) {
  18493. return null;
  18494. }
  18495. if (PDFJS.disableFontFace) {
  18496. this.disableFontFace = true;
  18497. return null;
  18498. }
  18499. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  18500. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  18501. globalScope['FontInspector'].enabled) {
  18502. globalScope['FontInspector'].fontAdded(this);
  18503. }
  18504. return nativeFontFace;
  18505. },
  18506. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  18507. if (!this.data) {
  18508. return null;
  18509. }
  18510. if (PDFJS.disableFontFace) {
  18511. this.disableFontFace = true;
  18512. return null;
  18513. }
  18514. var data = bytesToString(new Uint8Array(this.data));
  18515. var fontName = this.loadedName;
  18516. // Add the font-face rule to the document
  18517. var url = ('url(data:' + this.mimetype + ';base64,' +
  18518. window.btoa(data) + ');');
  18519. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  18520. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  18521. globalScope['FontInspector'].enabled) {
  18522. globalScope['FontInspector'].fontAdded(this, url);
  18523. }
  18524. return rule;
  18525. },
  18526. getPathGenerator:
  18527. function FontFaceObject_getPathGenerator(objs, character) {
  18528. if (!(character in this.compiledGlyphs)) {
  18529. var cmds = objs.get(this.loadedName + '_path_' + character);
  18530. var current, i, len;
  18531. // If we can, compile cmds into JS for MAXIMUM SPEED
  18532. if (FontFaceObject.isEvalSupported) {
  18533. var args, js = '';
  18534. for (i = 0, len = cmds.length; i < len; i++) {
  18535. current = cmds[i];
  18536. if (current.args !== undefined) {
  18537. args = current.args.join(',');
  18538. } else {
  18539. args = '';
  18540. }
  18541. js += 'c.' + current.cmd + '(' + args + ');\n';
  18542. }
  18543. /* jshint -W054 */
  18544. this.compiledGlyphs[character] = new Function('c', 'size', js);
  18545. } else {
  18546. // But fall back on using Function.prototype.apply() if we're
  18547. // blocked from using eval() for whatever reason (like CSP policies)
  18548. this.compiledGlyphs[character] = function(c, size) {
  18549. for (i = 0, len = cmds.length; i < len; i++) {
  18550. current = cmds[i];
  18551. if (current.cmd === 'scale') {
  18552. current.args = [size, -size];
  18553. }
  18554. c[current.cmd].apply(c, current.args);
  18555. }
  18556. };
  18557. }
  18558. }
  18559. return this.compiledGlyphs[character];
  18560. }
  18561. };
  18562. return FontFaceObject;
  18563. })();
  18564. exports.FontFaceObject = FontFaceObject;
  18565. exports.FontLoader = FontLoader;
  18566. }));
  18567. (function (root, factory) {
  18568. {
  18569. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  18570. }
  18571. }(this, function (exports, sharedUtil) {
  18572. var error = sharedUtil.error;
  18573. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  18574. function fixMetadata(meta) {
  18575. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  18576. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  18577. function(code, d1, d2, d3) {
  18578. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  18579. });
  18580. var chars = '';
  18581. for (var i = 0; i < bytes.length; i += 2) {
  18582. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  18583. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  18584. code !== 38 && false ? String.fromCharCode(code) :
  18585. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  18586. }
  18587. return '>' + chars;
  18588. });
  18589. }
  18590. function Metadata(meta) {
  18591. if (typeof meta === 'string') {
  18592. // Ghostscript produces invalid metadata
  18593. meta = fixMetadata(meta);
  18594. var parser = new DOMParser();
  18595. meta = parser.parseFromString(meta, 'application/xml');
  18596. } else if (!(meta instanceof Document)) {
  18597. error('Metadata: Invalid metadata object');
  18598. }
  18599. this.metaDocument = meta;
  18600. this.metadata = Object.create(null);
  18601. this.parse();
  18602. }
  18603. Metadata.prototype = {
  18604. parse: function Metadata_parse() {
  18605. var doc = this.metaDocument;
  18606. var rdf = doc.documentElement;
  18607. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  18608. rdf = rdf.firstChild;
  18609. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  18610. rdf = rdf.nextSibling;
  18611. }
  18612. }
  18613. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  18614. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  18615. return;
  18616. }
  18617. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  18618. for (i = 0, length = children.length; i < length; i++) {
  18619. desc = children[i];
  18620. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  18621. continue;
  18622. }
  18623. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  18624. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  18625. entry = desc.childNodes[ii];
  18626. name = entry.nodeName.toLowerCase();
  18627. this.metadata[name] = entry.textContent.trim();
  18628. }
  18629. }
  18630. }
  18631. },
  18632. get: function Metadata_get(name) {
  18633. return this.metadata[name] || null;
  18634. },
  18635. has: function Metadata_has(name) {
  18636. return typeof this.metadata[name] !== 'undefined';
  18637. }
  18638. };
  18639. return Metadata;
  18640. })();
  18641. exports.Metadata = Metadata;
  18642. }));
  18643. (function (root, factory) {
  18644. {
  18645. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  18646. }
  18647. }(this, function (exports, sharedUtil) {
  18648. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  18649. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  18650. var ImageKind = sharedUtil.ImageKind;
  18651. var OPS = sharedUtil.OPS;
  18652. var Util = sharedUtil.Util;
  18653. var isNum = sharedUtil.isNum;
  18654. var isArray = sharedUtil.isArray;
  18655. var warn = sharedUtil.warn;
  18656. var SVG_DEFAULTS = {
  18657. fontStyle: 'normal',
  18658. fontWeight: 'normal',
  18659. fillColor: '#000000'
  18660. };
  18661. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  18662. var PNG_HEADER =
  18663. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  18664. var CHUNK_WRAPPER_SIZE = 12;
  18665. var crcTable = new Int32Array(256);
  18666. for (var i = 0; i < 256; i++) {
  18667. var c = i;
  18668. for (var h = 0; h < 8; h++) {
  18669. if (c & 1) {
  18670. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  18671. } else {
  18672. c = (c >> 1) & 0x7fffffff;
  18673. }
  18674. }
  18675. crcTable[i] = c;
  18676. }
  18677. function crc32(data, start, end) {
  18678. var crc = -1;
  18679. for (var i = start; i < end; i++) {
  18680. var a = (crc ^ data[i]) & 0xff;
  18681. var b = crcTable[a];
  18682. crc = (crc >>> 8) ^ b;
  18683. }
  18684. return crc ^ -1;
  18685. }
  18686. function writePngChunk(type, body, data, offset) {
  18687. var p = offset;
  18688. var len = body.length;
  18689. data[p] = len >> 24 & 0xff;
  18690. data[p + 1] = len >> 16 & 0xff;
  18691. data[p + 2] = len >> 8 & 0xff;
  18692. data[p + 3] = len & 0xff;
  18693. p += 4;
  18694. data[p] = type.charCodeAt(0) & 0xff;
  18695. data[p + 1] = type.charCodeAt(1) & 0xff;
  18696. data[p + 2] = type.charCodeAt(2) & 0xff;
  18697. data[p + 3] = type.charCodeAt(3) & 0xff;
  18698. p += 4;
  18699. data.set(body, p);
  18700. p += body.length;
  18701. var crc = crc32(data, offset + 4, p);
  18702. data[p] = crc >> 24 & 0xff;
  18703. data[p + 1] = crc >> 16 & 0xff;
  18704. data[p + 2] = crc >> 8 & 0xff;
  18705. data[p + 3] = crc & 0xff;
  18706. }
  18707. function adler32(data, start, end) {
  18708. var a = 1;
  18709. var b = 0;
  18710. for (var i = start; i < end; ++i) {
  18711. a = (a + (data[i] & 0xff)) % 65521;
  18712. b = (b + a) % 65521;
  18713. }
  18714. return (b << 16) | a;
  18715. }
  18716. function encode(imgData, kind) {
  18717. var width = imgData.width;
  18718. var height = imgData.height;
  18719. var bitDepth, colorType, lineSize;
  18720. var bytes = imgData.data;
  18721. switch (kind) {
  18722. case ImageKind.GRAYSCALE_1BPP:
  18723. colorType = 0;
  18724. bitDepth = 1;
  18725. lineSize = (width + 7) >> 3;
  18726. break;
  18727. case ImageKind.RGB_24BPP:
  18728. colorType = 2;
  18729. bitDepth = 8;
  18730. lineSize = width * 3;
  18731. break;
  18732. case ImageKind.RGBA_32BPP:
  18733. colorType = 6;
  18734. bitDepth = 8;
  18735. lineSize = width * 4;
  18736. break;
  18737. default:
  18738. throw new Error('invalid format');
  18739. }
  18740. // prefix every row with predictor 0
  18741. var literals = new Uint8Array((1 + lineSize) * height);
  18742. var offsetLiterals = 0, offsetBytes = 0;
  18743. var y, i;
  18744. for (y = 0; y < height; ++y) {
  18745. literals[offsetLiterals++] = 0; // no prediction
  18746. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  18747. offsetLiterals);
  18748. offsetBytes += lineSize;
  18749. offsetLiterals += lineSize;
  18750. }
  18751. if (kind === ImageKind.GRAYSCALE_1BPP) {
  18752. // inverting for B/W
  18753. offsetLiterals = 0;
  18754. for (y = 0; y < height; y++) {
  18755. offsetLiterals++; // skipping predictor
  18756. for (i = 0; i < lineSize; i++) {
  18757. literals[offsetLiterals++] ^= 0xFF;
  18758. }
  18759. }
  18760. }
  18761. var ihdr = new Uint8Array([
  18762. width >> 24 & 0xff,
  18763. width >> 16 & 0xff,
  18764. width >> 8 & 0xff,
  18765. width & 0xff,
  18766. height >> 24 & 0xff,
  18767. height >> 16 & 0xff,
  18768. height >> 8 & 0xff,
  18769. height & 0xff,
  18770. bitDepth, // bit depth
  18771. colorType, // color type
  18772. 0x00, // compression method
  18773. 0x00, // filter method
  18774. 0x00 // interlace method
  18775. ]);
  18776. var len = literals.length;
  18777. var maxBlockLength = 0xFFFF;
  18778. var deflateBlocks = Math.ceil(len / maxBlockLength);
  18779. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  18780. var pi = 0;
  18781. idat[pi++] = 0x78; // compression method and flags
  18782. idat[pi++] = 0x9c; // flags
  18783. var pos = 0;
  18784. while (len > maxBlockLength) {
  18785. // writing non-final DEFLATE blocks type 0 and length of 65535
  18786. idat[pi++] = 0x00;
  18787. idat[pi++] = 0xff;
  18788. idat[pi++] = 0xff;
  18789. idat[pi++] = 0x00;
  18790. idat[pi++] = 0x00;
  18791. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  18792. pi += maxBlockLength;
  18793. pos += maxBlockLength;
  18794. len -= maxBlockLength;
  18795. }
  18796. // writing non-final DEFLATE blocks type 0
  18797. idat[pi++] = 0x01;
  18798. idat[pi++] = len & 0xff;
  18799. idat[pi++] = len >> 8 & 0xff;
  18800. idat[pi++] = (~len & 0xffff) & 0xff;
  18801. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  18802. idat.set(literals.subarray(pos), pi);
  18803. pi += literals.length - pos;
  18804. var adler = adler32(literals, 0, literals.length); // checksum
  18805. idat[pi++] = adler >> 24 & 0xff;
  18806. idat[pi++] = adler >> 16 & 0xff;
  18807. idat[pi++] = adler >> 8 & 0xff;
  18808. idat[pi++] = adler & 0xff;
  18809. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  18810. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  18811. ihdr.length + idat.length;
  18812. var data = new Uint8Array(pngLength);
  18813. var offset = 0;
  18814. data.set(PNG_HEADER, offset);
  18815. offset += PNG_HEADER.length;
  18816. writePngChunk('IHDR', ihdr, data, offset);
  18817. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  18818. writePngChunk('IDATA', idat, data, offset);
  18819. offset += CHUNK_WRAPPER_SIZE + idat.length;
  18820. writePngChunk('IEND', new Uint8Array(0), data, offset);
  18821. return PDFJS.createObjectURL(data, 'image/png');
  18822. }
  18823. return function convertImgDataToPng(imgData) {
  18824. var kind = (imgData.kind === undefined ?
  18825. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  18826. return encode(imgData, kind);
  18827. };
  18828. })();
  18829. var SVGExtraState = (function SVGExtraStateClosure() {
  18830. function SVGExtraState() {
  18831. this.fontSizeScale = 1;
  18832. this.fontWeight = SVG_DEFAULTS.fontWeight;
  18833. this.fontSize = 0;
  18834. this.textMatrix = IDENTITY_MATRIX;
  18835. this.fontMatrix = FONT_IDENTITY_MATRIX;
  18836. this.leading = 0;
  18837. // Current point (in user coordinates)
  18838. this.x = 0;
  18839. this.y = 0;
  18840. // Start of text line (in text coordinates)
  18841. this.lineX = 0;
  18842. this.lineY = 0;
  18843. // Character and word spacing
  18844. this.charSpacing = 0;
  18845. this.wordSpacing = 0;
  18846. this.textHScale = 1;
  18847. this.textRise = 0;
  18848. // Default foreground and background colors
  18849. this.fillColor = SVG_DEFAULTS.fillColor;
  18850. this.strokeColor = '#000000';
  18851. this.fillAlpha = 1;
  18852. this.strokeAlpha = 1;
  18853. this.lineWidth = 1;
  18854. this.lineJoin = '';
  18855. this.lineCap = '';
  18856. this.miterLimit = 0;
  18857. this.dashArray = [];
  18858. this.dashPhase = 0;
  18859. this.dependencies = [];
  18860. // Clipping
  18861. this.clipId = '';
  18862. this.pendingClip = false;
  18863. this.maskId = '';
  18864. }
  18865. SVGExtraState.prototype = {
  18866. clone: function SVGExtraState_clone() {
  18867. return Object.create(this);
  18868. },
  18869. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  18870. this.x = x;
  18871. this.y = y;
  18872. }
  18873. };
  18874. return SVGExtraState;
  18875. })();
  18876. var SVGGraphics = (function SVGGraphicsClosure() {
  18877. function createScratchSVG(width, height) {
  18878. var NS = 'http://www.w3.org/2000/svg';
  18879. var svg = document.createElementNS(NS, 'svg:svg');
  18880. svg.setAttributeNS(null, 'version', '1.1');
  18881. svg.setAttributeNS(null, 'width', width + 'px');
  18882. svg.setAttributeNS(null, 'height', height + 'px');
  18883. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  18884. return svg;
  18885. }
  18886. function opListToTree(opList) {
  18887. var opTree = [];
  18888. var tmp = [];
  18889. var opListLen = opList.length;
  18890. for (var x = 0; x < opListLen; x++) {
  18891. if (opList[x].fn === 'save') {
  18892. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  18893. tmp.push(opTree);
  18894. opTree = opTree[opTree.length - 1].items;
  18895. continue;
  18896. }
  18897. if(opList[x].fn === 'restore') {
  18898. opTree = tmp.pop();
  18899. } else {
  18900. opTree.push(opList[x]);
  18901. }
  18902. }
  18903. return opTree;
  18904. }
  18905. /**
  18906. * Formats float number.
  18907. * @param value {number} number to format.
  18908. * @returns {string}
  18909. */
  18910. function pf(value) {
  18911. if (value === (value | 0)) { // integer number
  18912. return value.toString();
  18913. }
  18914. var s = value.toFixed(10);
  18915. var i = s.length - 1;
  18916. if (s[i] !== '0') {
  18917. return s;
  18918. }
  18919. // removing trailing zeros
  18920. do {
  18921. i--;
  18922. } while (s[i] === '0');
  18923. return s.substr(0, s[i] === '.' ? i : i + 1);
  18924. }
  18925. /**
  18926. * Formats transform matrix. The standard rotation, scale and translate
  18927. * matrices are replaced by their shorter forms, and for identity matrix
  18928. * returns empty string to save the memory.
  18929. * @param m {Array} matrix to format.
  18930. * @returns {string}
  18931. */
  18932. function pm(m) {
  18933. if (m[4] === 0 && m[5] === 0) {
  18934. if (m[1] === 0 && m[2] === 0) {
  18935. if (m[0] === 1 && m[3] === 1) {
  18936. return '';
  18937. }
  18938. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  18939. }
  18940. if (m[0] === m[3] && m[1] === -m[2]) {
  18941. var a = Math.acos(m[0]) * 180 / Math.PI;
  18942. return 'rotate(' + pf(a) + ')';
  18943. }
  18944. } else {
  18945. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  18946. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  18947. }
  18948. }
  18949. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  18950. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  18951. }
  18952. function SVGGraphics(commonObjs, objs) {
  18953. this.current = new SVGExtraState();
  18954. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  18955. this.transformStack = [];
  18956. this.extraStack = [];
  18957. this.commonObjs = commonObjs;
  18958. this.objs = objs;
  18959. this.pendingEOFill = false;
  18960. this.embedFonts = false;
  18961. this.embeddedFonts = Object.create(null);
  18962. this.cssStyle = null;
  18963. }
  18964. var NS = 'http://www.w3.org/2000/svg';
  18965. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  18966. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  18967. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  18968. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  18969. var clipCount = 0;
  18970. var maskCount = 0;
  18971. SVGGraphics.prototype = {
  18972. save: function SVGGraphics_save() {
  18973. this.transformStack.push(this.transformMatrix);
  18974. var old = this.current;
  18975. this.extraStack.push(old);
  18976. this.current = old.clone();
  18977. },
  18978. restore: function SVGGraphics_restore() {
  18979. this.transformMatrix = this.transformStack.pop();
  18980. this.current = this.extraStack.pop();
  18981. this.tgrp = document.createElementNS(NS, 'svg:g');
  18982. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  18983. this.pgrp.appendChild(this.tgrp);
  18984. },
  18985. group: function SVGGraphics_group(items) {
  18986. this.save();
  18987. this.executeOpTree(items);
  18988. this.restore();
  18989. },
  18990. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  18991. var fnArray = operatorList.fnArray;
  18992. var fnArrayLen = fnArray.length;
  18993. var argsArray = operatorList.argsArray;
  18994. var self = this;
  18995. for (var i = 0; i < fnArrayLen; i++) {
  18996. if (OPS.dependency === fnArray[i]) {
  18997. var deps = argsArray[i];
  18998. for (var n = 0, nn = deps.length; n < nn; n++) {
  18999. var obj = deps[n];
  19000. var common = obj.substring(0, 2) === 'g_';
  19001. var promise;
  19002. if (common) {
  19003. promise = new Promise(function(resolve) {
  19004. self.commonObjs.get(obj, resolve);
  19005. });
  19006. } else {
  19007. promise = new Promise(function(resolve) {
  19008. self.objs.get(obj, resolve);
  19009. });
  19010. }
  19011. this.current.dependencies.push(promise);
  19012. }
  19013. }
  19014. }
  19015. return Promise.all(this.current.dependencies);
  19016. },
  19017. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19018. var transformMatrix = [a, b, c, d, e, f];
  19019. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  19020. transformMatrix);
  19021. this.tgrp = document.createElementNS(NS, 'svg:g');
  19022. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19023. },
  19024. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19025. this.svg = createScratchSVG(viewport.width, viewport.height);
  19026. this.viewport = viewport;
  19027. return this.loadDependencies(operatorList).then(function () {
  19028. this.transformMatrix = IDENTITY_MATRIX;
  19029. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19030. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19031. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19032. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19033. this.defs = document.createElementNS(NS, 'svg:defs');
  19034. this.pgrp.appendChild(this.defs);
  19035. this.pgrp.appendChild(this.tgrp);
  19036. this.svg.appendChild(this.pgrp);
  19037. var opTree = this.convertOpList(operatorList);
  19038. this.executeOpTree(opTree);
  19039. return this.svg;
  19040. }.bind(this));
  19041. },
  19042. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19043. var argsArray = operatorList.argsArray;
  19044. var fnArray = operatorList.fnArray;
  19045. var fnArrayLen = fnArray.length;
  19046. var REVOPS = [];
  19047. var opList = [];
  19048. for (var op in OPS) {
  19049. REVOPS[OPS[op]] = op;
  19050. }
  19051. for (var x = 0; x < fnArrayLen; x++) {
  19052. var fnId = fnArray[x];
  19053. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19054. }
  19055. return opListToTree(opList);
  19056. },
  19057. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19058. var opTreeLen = opTree.length;
  19059. for(var x = 0; x < opTreeLen; x++) {
  19060. var fn = opTree[x].fn;
  19061. var fnId = opTree[x].fnId;
  19062. var args = opTree[x].args;
  19063. switch (fnId | 0) {
  19064. case OPS.beginText:
  19065. this.beginText();
  19066. break;
  19067. case OPS.setLeading:
  19068. this.setLeading(args);
  19069. break;
  19070. case OPS.setLeadingMoveText:
  19071. this.setLeadingMoveText(args[0], args[1]);
  19072. break;
  19073. case OPS.setFont:
  19074. this.setFont(args);
  19075. break;
  19076. case OPS.showText:
  19077. this.showText(args[0]);
  19078. break;
  19079. case OPS.showSpacedText:
  19080. this.showText(args[0]);
  19081. break;
  19082. case OPS.endText:
  19083. this.endText();
  19084. break;
  19085. case OPS.moveText:
  19086. this.moveText(args[0], args[1]);
  19087. break;
  19088. case OPS.setCharSpacing:
  19089. this.setCharSpacing(args[0]);
  19090. break;
  19091. case OPS.setWordSpacing:
  19092. this.setWordSpacing(args[0]);
  19093. break;
  19094. case OPS.setHScale:
  19095. this.setHScale(args[0]);
  19096. break;
  19097. case OPS.setTextMatrix:
  19098. this.setTextMatrix(args[0], args[1], args[2],
  19099. args[3], args[4], args[5]);
  19100. break;
  19101. case OPS.setLineWidth:
  19102. this.setLineWidth(args[0]);
  19103. break;
  19104. case OPS.setLineJoin:
  19105. this.setLineJoin(args[0]);
  19106. break;
  19107. case OPS.setLineCap:
  19108. this.setLineCap(args[0]);
  19109. break;
  19110. case OPS.setMiterLimit:
  19111. this.setMiterLimit(args[0]);
  19112. break;
  19113. case OPS.setFillRGBColor:
  19114. this.setFillRGBColor(args[0], args[1], args[2]);
  19115. break;
  19116. case OPS.setStrokeRGBColor:
  19117. this.setStrokeRGBColor(args[0], args[1], args[2]);
  19118. break;
  19119. case OPS.setDash:
  19120. this.setDash(args[0], args[1]);
  19121. break;
  19122. case OPS.setGState:
  19123. this.setGState(args[0]);
  19124. break;
  19125. case OPS.fill:
  19126. this.fill();
  19127. break;
  19128. case OPS.eoFill:
  19129. this.eoFill();
  19130. break;
  19131. case OPS.stroke:
  19132. this.stroke();
  19133. break;
  19134. case OPS.fillStroke:
  19135. this.fillStroke();
  19136. break;
  19137. case OPS.eoFillStroke:
  19138. this.eoFillStroke();
  19139. break;
  19140. case OPS.clip:
  19141. this.clip('nonzero');
  19142. break;
  19143. case OPS.eoClip:
  19144. this.clip('evenodd');
  19145. break;
  19146. case OPS.paintSolidColorImageMask:
  19147. this.paintSolidColorImageMask();
  19148. break;
  19149. case OPS.paintJpegXObject:
  19150. this.paintJpegXObject(args[0], args[1], args[2]);
  19151. break;
  19152. case OPS.paintImageXObject:
  19153. this.paintImageXObject(args[0]);
  19154. break;
  19155. case OPS.paintInlineImageXObject:
  19156. this.paintInlineImageXObject(args[0]);
  19157. break;
  19158. case OPS.paintImageMaskXObject:
  19159. this.paintImageMaskXObject(args[0]);
  19160. break;
  19161. case OPS.paintFormXObjectBegin:
  19162. this.paintFormXObjectBegin(args[0], args[1]);
  19163. break;
  19164. case OPS.paintFormXObjectEnd:
  19165. this.paintFormXObjectEnd();
  19166. break;
  19167. case OPS.closePath:
  19168. this.closePath();
  19169. break;
  19170. case OPS.closeStroke:
  19171. this.closeStroke();
  19172. break;
  19173. case OPS.closeFillStroke:
  19174. this.closeFillStroke();
  19175. break;
  19176. case OPS.nextLine:
  19177. this.nextLine();
  19178. break;
  19179. case OPS.transform:
  19180. this.transform(args[0], args[1], args[2], args[3],
  19181. args[4], args[5]);
  19182. break;
  19183. case OPS.constructPath:
  19184. this.constructPath(args[0], args[1]);
  19185. break;
  19186. case OPS.endPath:
  19187. this.endPath();
  19188. break;
  19189. case 92:
  19190. this.group(opTree[x].items);
  19191. break;
  19192. default:
  19193. warn('Unimplemented method '+ fn);
  19194. break;
  19195. }
  19196. }
  19197. },
  19198. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  19199. this.current.wordSpacing = wordSpacing;
  19200. },
  19201. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  19202. this.current.charSpacing = charSpacing;
  19203. },
  19204. nextLine: function SVGGraphics_nextLine() {
  19205. this.moveText(0, this.current.leading);
  19206. },
  19207. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  19208. var current = this.current;
  19209. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  19210. this.current.x = this.current.lineX = 0;
  19211. this.current.y = this.current.lineY = 0;
  19212. current.xcoords = [];
  19213. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19214. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19215. current.tspan.setAttributeNS(null, 'font-size',
  19216. pf(current.fontSize) + 'px');
  19217. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19218. current.txtElement = document.createElementNS(NS, 'svg:text');
  19219. current.txtElement.appendChild(current.tspan);
  19220. },
  19221. beginText: function SVGGraphics_beginText() {
  19222. this.current.x = this.current.lineX = 0;
  19223. this.current.y = this.current.lineY = 0;
  19224. this.current.textMatrix = IDENTITY_MATRIX;
  19225. this.current.lineMatrix = IDENTITY_MATRIX;
  19226. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  19227. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  19228. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  19229. this.current.xcoords = [];
  19230. },
  19231. moveText: function SVGGraphics_moveText(x, y) {
  19232. var current = this.current;
  19233. this.current.x = this.current.lineX += x;
  19234. this.current.y = this.current.lineY += y;
  19235. current.xcoords = [];
  19236. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19237. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19238. current.tspan.setAttributeNS(null, 'font-size',
  19239. pf(current.fontSize) + 'px');
  19240. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19241. },
  19242. showText: function SVGGraphics_showText(glyphs) {
  19243. var current = this.current;
  19244. var font = current.font;
  19245. var fontSize = current.fontSize;
  19246. if (fontSize === 0) {
  19247. return;
  19248. }
  19249. var charSpacing = current.charSpacing;
  19250. var wordSpacing = current.wordSpacing;
  19251. var fontDirection = current.fontDirection;
  19252. var textHScale = current.textHScale * fontDirection;
  19253. var glyphsLength = glyphs.length;
  19254. var vertical = font.vertical;
  19255. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  19256. var x = 0, i;
  19257. for (i = 0; i < glyphsLength; ++i) {
  19258. var glyph = glyphs[i];
  19259. if (glyph === null) {
  19260. // word break
  19261. x += fontDirection * wordSpacing;
  19262. continue;
  19263. } else if (isNum(glyph)) {
  19264. x += -glyph * fontSize * 0.001;
  19265. continue;
  19266. }
  19267. current.xcoords.push(current.x + x * textHScale);
  19268. var width = glyph.width;
  19269. var character = glyph.fontChar;
  19270. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  19271. x += charWidth;
  19272. current.tspan.textContent += character;
  19273. }
  19274. if (vertical) {
  19275. current.y -= x * textHScale;
  19276. } else {
  19277. current.x += x * textHScale;
  19278. }
  19279. current.tspan.setAttributeNS(null, 'x',
  19280. current.xcoords.map(pf).join(' '));
  19281. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19282. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19283. current.tspan.setAttributeNS(null, 'font-size',
  19284. pf(current.fontSize) + 'px');
  19285. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  19286. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  19287. }
  19288. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  19289. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  19290. }
  19291. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  19292. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  19293. }
  19294. current.txtElement.setAttributeNS(null, 'transform',
  19295. pm(current.textMatrix) +
  19296. ' scale(1, -1)' );
  19297. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  19298. current.txtElement.appendChild(current.tspan);
  19299. current.txtgrp.appendChild(current.txtElement);
  19300. this.tgrp.appendChild(current.txtElement);
  19301. },
  19302. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  19303. this.setLeading(-y);
  19304. this.moveText(x, y);
  19305. },
  19306. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  19307. if (!this.cssStyle) {
  19308. this.cssStyle = document.createElementNS(NS, 'svg:style');
  19309. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  19310. this.defs.appendChild(this.cssStyle);
  19311. }
  19312. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  19313. this.cssStyle.textContent +=
  19314. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  19315. ' src: url(' + url + '); }\n';
  19316. },
  19317. setFont: function SVGGraphics_setFont(details) {
  19318. var current = this.current;
  19319. var fontObj = this.commonObjs.get(details[0]);
  19320. var size = details[1];
  19321. this.current.font = fontObj;
  19322. if (this.embedFonts && fontObj.data &&
  19323. !this.embeddedFonts[fontObj.loadedName]) {
  19324. this.addFontStyle(fontObj);
  19325. this.embeddedFonts[fontObj.loadedName] = fontObj;
  19326. }
  19327. current.fontMatrix = (fontObj.fontMatrix ?
  19328. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  19329. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  19330. (fontObj.bold ? 'bold' : 'normal');
  19331. var italic = fontObj.italic ? 'italic' : 'normal';
  19332. if (size < 0) {
  19333. size = -size;
  19334. current.fontDirection = -1;
  19335. } else {
  19336. current.fontDirection = 1;
  19337. }
  19338. current.fontSize = size;
  19339. current.fontFamily = fontObj.loadedName;
  19340. current.fontWeight = bold;
  19341. current.fontStyle = italic;
  19342. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19343. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19344. current.xcoords = [];
  19345. },
  19346. endText: function SVGGraphics_endText() {
  19347. if (this.current.pendingClip) {
  19348. this.cgrp.appendChild(this.tgrp);
  19349. this.pgrp.appendChild(this.cgrp);
  19350. } else {
  19351. this.pgrp.appendChild(this.tgrp);
  19352. }
  19353. this.tgrp = document.createElementNS(NS, 'svg:g');
  19354. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19355. },
  19356. // Path properties
  19357. setLineWidth: function SVGGraphics_setLineWidth(width) {
  19358. this.current.lineWidth = width;
  19359. },
  19360. setLineCap: function SVGGraphics_setLineCap(style) {
  19361. this.current.lineCap = LINE_CAP_STYLES[style];
  19362. },
  19363. setLineJoin: function SVGGraphics_setLineJoin(style) {
  19364. this.current.lineJoin = LINE_JOIN_STYLES[style];
  19365. },
  19366. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  19367. this.current.miterLimit = limit;
  19368. },
  19369. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  19370. var color = Util.makeCssRgb(r, g, b);
  19371. this.current.strokeColor = color;
  19372. },
  19373. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  19374. var color = Util.makeCssRgb(r, g, b);
  19375. this.current.fillColor = color;
  19376. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  19377. this.current.xcoords = [];
  19378. },
  19379. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  19380. this.current.dashArray = dashArray;
  19381. this.current.dashPhase = dashPhase;
  19382. },
  19383. constructPath: function SVGGraphics_constructPath(ops, args) {
  19384. var current = this.current;
  19385. var x = current.x, y = current.y;
  19386. current.path = document.createElementNS(NS, 'svg:path');
  19387. var d = [];
  19388. var opLength = ops.length;
  19389. for (var i = 0, j = 0; i < opLength; i++) {
  19390. switch (ops[i] | 0) {
  19391. case OPS.rectangle:
  19392. x = args[j++];
  19393. y = args[j++];
  19394. var width = args[j++];
  19395. var height = args[j++];
  19396. var xw = x + width;
  19397. var yh = y + height;
  19398. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  19399. 'L', pf(x), pf(yh), 'Z');
  19400. break;
  19401. case OPS.moveTo:
  19402. x = args[j++];
  19403. y = args[j++];
  19404. d.push('M', pf(x), pf(y));
  19405. break;
  19406. case OPS.lineTo:
  19407. x = args[j++];
  19408. y = args[j++];
  19409. d.push('L', pf(x) , pf(y));
  19410. break;
  19411. case OPS.curveTo:
  19412. x = args[j + 4];
  19413. y = args[j + 5];
  19414. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  19415. pf(args[j + 3]), pf(x), pf(y));
  19416. j += 6;
  19417. break;
  19418. case OPS.curveTo2:
  19419. x = args[j + 2];
  19420. y = args[j + 3];
  19421. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  19422. pf(args[j + 2]), pf(args[j + 3]));
  19423. j += 4;
  19424. break;
  19425. case OPS.curveTo3:
  19426. x = args[j + 2];
  19427. y = args[j + 3];
  19428. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  19429. pf(x), pf(y));
  19430. j += 4;
  19431. break;
  19432. case OPS.closePath:
  19433. d.push('Z');
  19434. break;
  19435. }
  19436. }
  19437. current.path.setAttributeNS(null, 'd', d.join(' '));
  19438. current.path.setAttributeNS(null, 'stroke-miterlimit',
  19439. pf(current.miterLimit));
  19440. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  19441. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  19442. current.path.setAttributeNS(null, 'stroke-width',
  19443. pf(current.lineWidth) + 'px');
  19444. current.path.setAttributeNS(null, 'stroke-dasharray',
  19445. current.dashArray.map(pf).join(' '));
  19446. current.path.setAttributeNS(null, 'stroke-dashoffset',
  19447. pf(current.dashPhase) + 'px');
  19448. current.path.setAttributeNS(null, 'fill', 'none');
  19449. this.tgrp.appendChild(current.path);
  19450. if (current.pendingClip) {
  19451. this.cgrp.appendChild(this.tgrp);
  19452. this.pgrp.appendChild(this.cgrp);
  19453. } else {
  19454. this.pgrp.appendChild(this.tgrp);
  19455. }
  19456. // Saving a reference in current.element so that it can be addressed
  19457. // in 'fill' and 'stroke'
  19458. current.element = current.path;
  19459. current.setCurrentPoint(x, y);
  19460. },
  19461. endPath: function SVGGraphics_endPath() {
  19462. var current = this.current;
  19463. if (current.pendingClip) {
  19464. this.cgrp.appendChild(this.tgrp);
  19465. this.pgrp.appendChild(this.cgrp);
  19466. } else {
  19467. this.pgrp.appendChild(this.tgrp);
  19468. }
  19469. this.tgrp = document.createElementNS(NS, 'svg:g');
  19470. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19471. },
  19472. clip: function SVGGraphics_clip(type) {
  19473. var current = this.current;
  19474. // Add current path to clipping path
  19475. current.clipId = 'clippath' + clipCount;
  19476. clipCount++;
  19477. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  19478. this.clippath.setAttributeNS(null, 'id', current.clipId);
  19479. var clipElement = current.element.cloneNode();
  19480. if (type === 'evenodd') {
  19481. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  19482. } else {
  19483. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  19484. }
  19485. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19486. this.clippath.appendChild(clipElement);
  19487. this.defs.appendChild(this.clippath);
  19488. // Create a new group with that attribute
  19489. current.pendingClip = true;
  19490. this.cgrp = document.createElementNS(NS, 'svg:g');
  19491. this.cgrp.setAttributeNS(null, 'clip-path',
  19492. 'url(#' + current.clipId + ')');
  19493. this.pgrp.appendChild(this.cgrp);
  19494. },
  19495. closePath: function SVGGraphics_closePath() {
  19496. var current = this.current;
  19497. var d = current.path.getAttributeNS(null, 'd');
  19498. d += 'Z';
  19499. current.path.setAttributeNS(null, 'd', d);
  19500. },
  19501. setLeading: function SVGGraphics_setLeading(leading) {
  19502. this.current.leading = -leading;
  19503. },
  19504. setTextRise: function SVGGraphics_setTextRise(textRise) {
  19505. this.current.textRise = textRise;
  19506. },
  19507. setHScale: function SVGGraphics_setHScale(scale) {
  19508. this.current.textHScale = scale / 100;
  19509. },
  19510. setGState: function SVGGraphics_setGState(states) {
  19511. for (var i = 0, ii = states.length; i < ii; i++) {
  19512. var state = states[i];
  19513. var key = state[0];
  19514. var value = state[1];
  19515. switch (key) {
  19516. case 'LW':
  19517. this.setLineWidth(value);
  19518. break;
  19519. case 'LC':
  19520. this.setLineCap(value);
  19521. break;
  19522. case 'LJ':
  19523. this.setLineJoin(value);
  19524. break;
  19525. case 'ML':
  19526. this.setMiterLimit(value);
  19527. break;
  19528. case 'D':
  19529. this.setDash(value[0], value[1]);
  19530. break;
  19531. case 'RI':
  19532. break;
  19533. case 'FL':
  19534. break;
  19535. case 'Font':
  19536. this.setFont(value);
  19537. break;
  19538. case 'CA':
  19539. break;
  19540. case 'ca':
  19541. break;
  19542. case 'BM':
  19543. break;
  19544. case 'SMask':
  19545. break;
  19546. }
  19547. }
  19548. },
  19549. fill: function SVGGraphics_fill() {
  19550. var current = this.current;
  19551. current.element.setAttributeNS(null, 'fill', current.fillColor);
  19552. },
  19553. stroke: function SVGGraphics_stroke() {
  19554. var current = this.current;
  19555. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  19556. current.element.setAttributeNS(null, 'fill', 'none');
  19557. },
  19558. eoFill: function SVGGraphics_eoFill() {
  19559. var current = this.current;
  19560. current.element.setAttributeNS(null, 'fill', current.fillColor);
  19561. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  19562. },
  19563. fillStroke: function SVGGraphics_fillStroke() {
  19564. // Order is important since stroke wants fill to be none.
  19565. // First stroke, then if fill needed, it will be overwritten.
  19566. this.stroke();
  19567. this.fill();
  19568. },
  19569. eoFillStroke: function SVGGraphics_eoFillStroke() {
  19570. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  19571. this.fillStroke();
  19572. },
  19573. closeStroke: function SVGGraphics_closeStroke() {
  19574. this.closePath();
  19575. this.stroke();
  19576. },
  19577. closeFillStroke: function SVGGraphics_closeFillStroke() {
  19578. this.closePath();
  19579. this.fillStroke();
  19580. },
  19581. paintSolidColorImageMask:
  19582. function SVGGraphics_paintSolidColorImageMask() {
  19583. var current = this.current;
  19584. var rect = document.createElementNS(NS, 'svg:rect');
  19585. rect.setAttributeNS(null, 'x', '0');
  19586. rect.setAttributeNS(null, 'y', '0');
  19587. rect.setAttributeNS(null, 'width', '1px');
  19588. rect.setAttributeNS(null, 'height', '1px');
  19589. rect.setAttributeNS(null, 'fill', current.fillColor);
  19590. this.tgrp.appendChild(rect);
  19591. },
  19592. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  19593. var current = this.current;
  19594. var imgObj = this.objs.get(objId);
  19595. var imgEl = document.createElementNS(NS, 'svg:image');
  19596. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  19597. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  19598. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  19599. imgEl.setAttributeNS(null, 'x', '0');
  19600. imgEl.setAttributeNS(null, 'y', pf(-h));
  19601. imgEl.setAttributeNS(null, 'transform',
  19602. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  19603. this.tgrp.appendChild(imgEl);
  19604. if (current.pendingClip) {
  19605. this.cgrp.appendChild(this.tgrp);
  19606. this.pgrp.appendChild(this.cgrp);
  19607. } else {
  19608. this.pgrp.appendChild(this.tgrp);
  19609. }
  19610. },
  19611. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  19612. var imgData = this.objs.get(objId);
  19613. if (!imgData) {
  19614. warn('Dependent image isn\'t ready yet');
  19615. return;
  19616. }
  19617. this.paintInlineImageXObject(imgData);
  19618. },
  19619. paintInlineImageXObject:
  19620. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  19621. var current = this.current;
  19622. var width = imgData.width;
  19623. var height = imgData.height;
  19624. var imgSrc = convertImgDataToPng(imgData);
  19625. var cliprect = document.createElementNS(NS, 'svg:rect');
  19626. cliprect.setAttributeNS(null, 'x', '0');
  19627. cliprect.setAttributeNS(null, 'y', '0');
  19628. cliprect.setAttributeNS(null, 'width', pf(width));
  19629. cliprect.setAttributeNS(null, 'height', pf(height));
  19630. current.element = cliprect;
  19631. this.clip('nonzero');
  19632. var imgEl = document.createElementNS(NS, 'svg:image');
  19633. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  19634. imgEl.setAttributeNS(null, 'x', '0');
  19635. imgEl.setAttributeNS(null, 'y', pf(-height));
  19636. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  19637. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  19638. imgEl.setAttributeNS(null, 'transform',
  19639. 'scale(' + pf(1 / width) + ' ' +
  19640. pf(-1 / height) + ')');
  19641. if (mask) {
  19642. mask.appendChild(imgEl);
  19643. } else {
  19644. this.tgrp.appendChild(imgEl);
  19645. }
  19646. if (current.pendingClip) {
  19647. this.cgrp.appendChild(this.tgrp);
  19648. this.pgrp.appendChild(this.cgrp);
  19649. } else {
  19650. this.pgrp.appendChild(this.tgrp);
  19651. }
  19652. },
  19653. paintImageMaskXObject:
  19654. function SVGGraphics_paintImageMaskXObject(imgData) {
  19655. var current = this.current;
  19656. var width = imgData.width;
  19657. var height = imgData.height;
  19658. var fillColor = current.fillColor;
  19659. current.maskId = 'mask' + maskCount++;
  19660. var mask = document.createElementNS(NS, 'svg:mask');
  19661. mask.setAttributeNS(null, 'id', current.maskId);
  19662. var rect = document.createElementNS(NS, 'svg:rect');
  19663. rect.setAttributeNS(null, 'x', '0');
  19664. rect.setAttributeNS(null, 'y', '0');
  19665. rect.setAttributeNS(null, 'width', pf(width));
  19666. rect.setAttributeNS(null, 'height', pf(height));
  19667. rect.setAttributeNS(null, 'fill', fillColor);
  19668. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  19669. this.defs.appendChild(mask);
  19670. this.tgrp.appendChild(rect);
  19671. this.paintInlineImageXObject(imgData, mask);
  19672. },
  19673. paintFormXObjectBegin:
  19674. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  19675. this.save();
  19676. if (isArray(matrix) && matrix.length === 6) {
  19677. this.transform(matrix[0], matrix[1], matrix[2],
  19678. matrix[3], matrix[4], matrix[5]);
  19679. }
  19680. if (isArray(bbox) && bbox.length === 4) {
  19681. var width = bbox[2] - bbox[0];
  19682. var height = bbox[3] - bbox[1];
  19683. var cliprect = document.createElementNS(NS, 'svg:rect');
  19684. cliprect.setAttributeNS(null, 'x', bbox[0]);
  19685. cliprect.setAttributeNS(null, 'y', bbox[1]);
  19686. cliprect.setAttributeNS(null, 'width', pf(width));
  19687. cliprect.setAttributeNS(null, 'height', pf(height));
  19688. this.current.element = cliprect;
  19689. this.clip('nonzero');
  19690. this.endPath();
  19691. }
  19692. },
  19693. paintFormXObjectEnd:
  19694. function SVGGraphics_paintFormXObjectEnd() {
  19695. this.restore();
  19696. }
  19697. };
  19698. return SVGGraphics;
  19699. })();
  19700. PDFJS.SVGGraphics = SVGGraphics;
  19701. exports.SVGGraphics = SVGGraphics;
  19702. }));
  19703. (function (root, factory) {
  19704. {
  19705. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  19706. root.pdfjsDisplayDOMUtils, root.pdfjsSharedGlobal);
  19707. }
  19708. }(this, function (exports, sharedUtil, displayDOMUtils, sharedGlobal) {
  19709. var Util = sharedUtil.Util;
  19710. var createPromiseCapability = sharedUtil.createPromiseCapability;
  19711. var CustomStyle = displayDOMUtils.CustomStyle;
  19712. var PDFJS = sharedGlobal.PDFJS;
  19713. /**
  19714. * Text layer render parameters.
  19715. *
  19716. * @typedef {Object} TextLayerRenderParameters
  19717. * @property {TextContent} textContent - Text content to render (the object is
  19718. * returned by the page's getTextContent() method).
  19719. * @property {HTMLElement} container - HTML element that will contain text runs.
  19720. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  19721. * layout the text runs.
  19722. * @property {Array} textDivs - (optional) HTML elements that are correspond
  19723. * the text items of the textContent input. This is output and shall be
  19724. * initially be set to empty array.
  19725. * @property {number} timeout - (optional) Delay in milliseconds before
  19726. * rendering of the text runs occurs.
  19727. */
  19728. var renderTextLayer = (function renderTextLayerClosure() {
  19729. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  19730. var NonWhitespaceRegexp = /\S/;
  19731. function isAllWhitespace(str) {
  19732. return !NonWhitespaceRegexp.test(str);
  19733. }
  19734. function appendText(textDivs, viewport, geom, styles) {
  19735. var style = styles[geom.fontName];
  19736. var textDiv = document.createElement('div');
  19737. textDivs.push(textDiv);
  19738. if (isAllWhitespace(geom.str)) {
  19739. textDiv.dataset.isWhitespace = true;
  19740. return;
  19741. }
  19742. var tx = Util.transform(viewport.transform, geom.transform);
  19743. var angle = Math.atan2(tx[1], tx[0]);
  19744. if (style.vertical) {
  19745. angle += Math.PI / 2;
  19746. }
  19747. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  19748. var fontAscent = fontHeight;
  19749. if (style.ascent) {
  19750. fontAscent = style.ascent * fontAscent;
  19751. } else if (style.descent) {
  19752. fontAscent = (1 + style.descent) * fontAscent;
  19753. }
  19754. var left;
  19755. var top;
  19756. if (angle === 0) {
  19757. left = tx[4];
  19758. top = tx[5] - fontAscent;
  19759. } else {
  19760. left = tx[4] + (fontAscent * Math.sin(angle));
  19761. top = tx[5] - (fontAscent * Math.cos(angle));
  19762. }
  19763. textDiv.style.left = left + 'px';
  19764. textDiv.style.top = top + 'px';
  19765. textDiv.style.fontSize = fontHeight + 'px';
  19766. textDiv.style.fontFamily = style.fontFamily;
  19767. textDiv.textContent = geom.str;
  19768. // |fontName| is only used by the Font Inspector. This test will succeed
  19769. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  19770. // not worth the effort to do a more accurate test.
  19771. if (PDFJS.pdfBug) {
  19772. textDiv.dataset.fontName = geom.fontName;
  19773. }
  19774. // Storing into dataset will convert number into string.
  19775. if (angle !== 0) {
  19776. textDiv.dataset.angle = angle * (180 / Math.PI);
  19777. }
  19778. // We don't bother scaling single-char text divs, because it has very
  19779. // little effect on text highlighting. This makes scrolling on docs with
  19780. // lots of such divs a lot faster.
  19781. if (geom.str.length > 1) {
  19782. if (style.vertical) {
  19783. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  19784. } else {
  19785. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  19786. }
  19787. }
  19788. }
  19789. function render(task) {
  19790. if (task._canceled) {
  19791. return;
  19792. }
  19793. var textLayerFrag = task._container;
  19794. var textDivs = task._textDivs;
  19795. var capability = task._capability;
  19796. var textDivsLength = textDivs.length;
  19797. // No point in rendering many divs as it would make the browser
  19798. // unusable even after the divs are rendered.
  19799. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  19800. capability.resolve();
  19801. return;
  19802. }
  19803. var canvas = document.createElement('canvas');
  19804. var ctx = canvas.getContext('2d', {alpha: false});
  19805. var lastFontSize;
  19806. var lastFontFamily;
  19807. for (var i = 0; i < textDivsLength; i++) {
  19808. var textDiv = textDivs[i];
  19809. if (textDiv.dataset.isWhitespace !== undefined) {
  19810. continue;
  19811. }
  19812. var fontSize = textDiv.style.fontSize;
  19813. var fontFamily = textDiv.style.fontFamily;
  19814. // Only build font string and set to context if different from last.
  19815. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  19816. ctx.font = fontSize + ' ' + fontFamily;
  19817. lastFontSize = fontSize;
  19818. lastFontFamily = fontFamily;
  19819. }
  19820. var width = ctx.measureText(textDiv.textContent).width;
  19821. if (width > 0) {
  19822. textLayerFrag.appendChild(textDiv);
  19823. var transform;
  19824. if (textDiv.dataset.canvasWidth !== undefined) {
  19825. // Dataset values come of type string.
  19826. var textScale = textDiv.dataset.canvasWidth / width;
  19827. transform = 'scaleX(' + textScale + ')';
  19828. } else {
  19829. transform = '';
  19830. }
  19831. var rotation = textDiv.dataset.angle;
  19832. if (rotation) {
  19833. transform = 'rotate(' + rotation + 'deg) ' + transform;
  19834. }
  19835. if (transform) {
  19836. CustomStyle.setProp('transform' , textDiv, transform);
  19837. }
  19838. }
  19839. }
  19840. capability.resolve();
  19841. }
  19842. /**
  19843. * Text layer rendering task.
  19844. *
  19845. * @param {TextContent} textContent
  19846. * @param {HTMLElement} container
  19847. * @param {PDFJS.PageViewport} viewport
  19848. * @param {Array} textDivs
  19849. * @private
  19850. */
  19851. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  19852. this._textContent = textContent;
  19853. this._container = container;
  19854. this._viewport = viewport;
  19855. textDivs = textDivs || [];
  19856. this._textDivs = textDivs;
  19857. this._canceled = false;
  19858. this._capability = createPromiseCapability();
  19859. this._renderTimer = null;
  19860. }
  19861. TextLayerRenderTask.prototype = {
  19862. get promise() {
  19863. return this._capability.promise;
  19864. },
  19865. cancel: function TextLayer_cancel() {
  19866. this._canceled = true;
  19867. if (this._renderTimer !== null) {
  19868. clearTimeout(this._renderTimer);
  19869. this._renderTimer = null;
  19870. }
  19871. this._capability.reject('canceled');
  19872. },
  19873. _render: function TextLayer_render(timeout) {
  19874. var textItems = this._textContent.items;
  19875. var styles = this._textContent.styles;
  19876. var textDivs = this._textDivs;
  19877. var viewport = this._viewport;
  19878. for (var i = 0, len = textItems.length; i < len; i++) {
  19879. appendText(textDivs, viewport, textItems[i], styles);
  19880. }
  19881. if (!timeout) { // Render right away
  19882. render(this);
  19883. } else { // Schedule
  19884. var self = this;
  19885. this._renderTimer = setTimeout(function() {
  19886. render(self);
  19887. self._renderTimer = null;
  19888. }, timeout);
  19889. }
  19890. }
  19891. };
  19892. /**
  19893. * Starts rendering of the text layer.
  19894. *
  19895. * @param {TextLayerRenderParameters} renderParameters
  19896. * @returns {TextLayerRenderTask}
  19897. */
  19898. function renderTextLayer(renderParameters) {
  19899. var task = new TextLayerRenderTask(renderParameters.textContent,
  19900. renderParameters.container,
  19901. renderParameters.viewport,
  19902. renderParameters.textDivs);
  19903. task._render(renderParameters.timeout);
  19904. return task;
  19905. }
  19906. return renderTextLayer;
  19907. })();
  19908. PDFJS.renderTextLayer = renderTextLayer;
  19909. exports.renderTextLayer = renderTextLayer;
  19910. }));
  19911. (function (root, factory) {
  19912. {
  19913. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  19914. }
  19915. }(this, function (exports, sharedUtil) {
  19916. var shadow = sharedUtil.shadow;
  19917. var WebGLUtils = (function WebGLUtilsClosure() {
  19918. function loadShader(gl, code, shaderType) {
  19919. var shader = gl.createShader(shaderType);
  19920. gl.shaderSource(shader, code);
  19921. gl.compileShader(shader);
  19922. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  19923. if (!compiled) {
  19924. var errorMsg = gl.getShaderInfoLog(shader);
  19925. throw new Error('Error during shader compilation: ' + errorMsg);
  19926. }
  19927. return shader;
  19928. }
  19929. function createVertexShader(gl, code) {
  19930. return loadShader(gl, code, gl.VERTEX_SHADER);
  19931. }
  19932. function createFragmentShader(gl, code) {
  19933. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  19934. }
  19935. function createProgram(gl, shaders) {
  19936. var program = gl.createProgram();
  19937. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  19938. gl.attachShader(program, shaders[i]);
  19939. }
  19940. gl.linkProgram(program);
  19941. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  19942. if (!linked) {
  19943. var errorMsg = gl.getProgramInfoLog(program);
  19944. throw new Error('Error during program linking: ' + errorMsg);
  19945. }
  19946. return program;
  19947. }
  19948. function createTexture(gl, image, textureId) {
  19949. gl.activeTexture(textureId);
  19950. var texture = gl.createTexture();
  19951. gl.bindTexture(gl.TEXTURE_2D, texture);
  19952. // Set the parameters so we can render any size image.
  19953. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  19954. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  19955. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  19956. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  19957. // Upload the image into the texture.
  19958. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  19959. return texture;
  19960. }
  19961. var currentGL, currentCanvas;
  19962. function generateGL() {
  19963. if (currentGL) {
  19964. return;
  19965. }
  19966. currentCanvas = document.createElement('canvas');
  19967. currentGL = currentCanvas.getContext('webgl',
  19968. { premultipliedalpha: false });
  19969. }
  19970. var smaskVertexShaderCode = '\
  19971. attribute vec2 a_position; \
  19972. attribute vec2 a_texCoord; \
  19973. \
  19974. uniform vec2 u_resolution; \
  19975. \
  19976. varying vec2 v_texCoord; \
  19977. \
  19978. void main() { \
  19979. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  19980. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  19981. \
  19982. v_texCoord = a_texCoord; \
  19983. } ';
  19984. var smaskFragmentShaderCode = '\
  19985. precision mediump float; \
  19986. \
  19987. uniform vec4 u_backdrop; \
  19988. uniform int u_subtype; \
  19989. uniform sampler2D u_image; \
  19990. uniform sampler2D u_mask; \
  19991. \
  19992. varying vec2 v_texCoord; \
  19993. \
  19994. void main() { \
  19995. vec4 imageColor = texture2D(u_image, v_texCoord); \
  19996. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  19997. if (u_backdrop.a > 0.0) { \
  19998. maskColor.rgb = maskColor.rgb * maskColor.a + \
  19999. u_backdrop.rgb * (1.0 - maskColor.a); \
  20000. } \
  20001. float lum; \
  20002. if (u_subtype == 0) { \
  20003. lum = maskColor.a; \
  20004. } else { \
  20005. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  20006. maskColor.b * 0.11; \
  20007. } \
  20008. imageColor.a *= lum; \
  20009. imageColor.rgb *= imageColor.a; \
  20010. gl_FragColor = imageColor; \
  20011. } ';
  20012. var smaskCache = null;
  20013. function initSmaskGL() {
  20014. var canvas, gl;
  20015. generateGL();
  20016. canvas = currentCanvas;
  20017. currentCanvas = null;
  20018. gl = currentGL;
  20019. currentGL = null;
  20020. // setup a GLSL program
  20021. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  20022. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  20023. var program = createProgram(gl, [vertexShader, fragmentShader]);
  20024. gl.useProgram(program);
  20025. var cache = {};
  20026. cache.gl = gl;
  20027. cache.canvas = canvas;
  20028. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  20029. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  20030. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  20031. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  20032. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  20033. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  20034. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  20035. // provide texture coordinates for the rectangle.
  20036. var texCoordBuffer = gl.createBuffer();
  20037. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  20038. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  20039. 0.0, 0.0,
  20040. 1.0, 0.0,
  20041. 0.0, 1.0,
  20042. 0.0, 1.0,
  20043. 1.0, 0.0,
  20044. 1.0, 1.0]), gl.STATIC_DRAW);
  20045. gl.enableVertexAttribArray(texCoordLocation);
  20046. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  20047. gl.uniform1i(texLayerLocation, 0);
  20048. gl.uniform1i(texMaskLocation, 1);
  20049. smaskCache = cache;
  20050. }
  20051. function composeSMask(layer, mask, properties) {
  20052. var width = layer.width, height = layer.height;
  20053. if (!smaskCache) {
  20054. initSmaskGL();
  20055. }
  20056. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  20057. canvas.width = width;
  20058. canvas.height = height;
  20059. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  20060. gl.uniform2f(cache.resolutionLocation, width, height);
  20061. if (properties.backdrop) {
  20062. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  20063. properties.backdrop[1], properties.backdrop[2], 1);
  20064. } else {
  20065. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  20066. }
  20067. gl.uniform1i(cache.subtypeLocation,
  20068. properties.subtype === 'Luminosity' ? 1 : 0);
  20069. // Create a textures
  20070. var texture = createTexture(gl, layer, gl.TEXTURE0);
  20071. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  20072. // Create a buffer and put a single clipspace rectangle in
  20073. // it (2 triangles)
  20074. var buffer = gl.createBuffer();
  20075. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  20076. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  20077. 0, 0,
  20078. width, 0,
  20079. 0, height,
  20080. 0, height,
  20081. width, 0,
  20082. width, height]), gl.STATIC_DRAW);
  20083. gl.enableVertexAttribArray(cache.positionLocation);
  20084. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  20085. // draw
  20086. gl.clearColor(0, 0, 0, 0);
  20087. gl.enable(gl.BLEND);
  20088. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  20089. gl.clear(gl.COLOR_BUFFER_BIT);
  20090. gl.drawArrays(gl.TRIANGLES, 0, 6);
  20091. gl.flush();
  20092. gl.deleteTexture(texture);
  20093. gl.deleteTexture(maskTexture);
  20094. gl.deleteBuffer(buffer);
  20095. return canvas;
  20096. }
  20097. var figuresVertexShaderCode = '\
  20098. attribute vec2 a_position; \
  20099. attribute vec3 a_color; \
  20100. \
  20101. uniform vec2 u_resolution; \
  20102. uniform vec2 u_scale; \
  20103. uniform vec2 u_offset; \
  20104. \
  20105. varying vec4 v_color; \
  20106. \
  20107. void main() { \
  20108. vec2 position = (a_position + u_offset) * u_scale; \
  20109. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  20110. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  20111. \
  20112. v_color = vec4(a_color / 255.0, 1.0); \
  20113. } ';
  20114. var figuresFragmentShaderCode = '\
  20115. precision mediump float; \
  20116. \
  20117. varying vec4 v_color; \
  20118. \
  20119. void main() { \
  20120. gl_FragColor = v_color; \
  20121. } ';
  20122. var figuresCache = null;
  20123. function initFiguresGL() {
  20124. var canvas, gl;
  20125. generateGL();
  20126. canvas = currentCanvas;
  20127. currentCanvas = null;
  20128. gl = currentGL;
  20129. currentGL = null;
  20130. // setup a GLSL program
  20131. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  20132. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  20133. var program = createProgram(gl, [vertexShader, fragmentShader]);
  20134. gl.useProgram(program);
  20135. var cache = {};
  20136. cache.gl = gl;
  20137. cache.canvas = canvas;
  20138. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  20139. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  20140. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  20141. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  20142. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  20143. figuresCache = cache;
  20144. }
  20145. function drawFigures(width, height, backgroundColor, figures, context) {
  20146. if (!figuresCache) {
  20147. initFiguresGL();
  20148. }
  20149. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  20150. canvas.width = width;
  20151. canvas.height = height;
  20152. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  20153. gl.uniform2f(cache.resolutionLocation, width, height);
  20154. // count triangle points
  20155. var count = 0;
  20156. var i, ii, rows;
  20157. for (i = 0, ii = figures.length; i < ii; i++) {
  20158. switch (figures[i].type) {
  20159. case 'lattice':
  20160. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  20161. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  20162. break;
  20163. case 'triangles':
  20164. count += figures[i].coords.length;
  20165. break;
  20166. }
  20167. }
  20168. // transfer data
  20169. var coords = new Float32Array(count * 2);
  20170. var colors = new Uint8Array(count * 3);
  20171. var coordsMap = context.coords, colorsMap = context.colors;
  20172. var pIndex = 0, cIndex = 0;
  20173. for (i = 0, ii = figures.length; i < ii; i++) {
  20174. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  20175. switch (figure.type) {
  20176. case 'lattice':
  20177. var cols = figure.verticesPerRow;
  20178. rows = (ps.length / cols) | 0;
  20179. for (var row = 1; row < rows; row++) {
  20180. var offset = row * cols + 1;
  20181. for (var col = 1; col < cols; col++, offset++) {
  20182. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  20183. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  20184. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  20185. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  20186. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  20187. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  20188. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  20189. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  20190. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  20191. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  20192. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  20193. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  20194. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  20195. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  20196. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  20197. coords[pIndex + 6] = coords[pIndex + 2];
  20198. coords[pIndex + 7] = coords[pIndex + 3];
  20199. coords[pIndex + 8] = coords[pIndex + 4];
  20200. coords[pIndex + 9] = coords[pIndex + 5];
  20201. coords[pIndex + 10] = coordsMap[ps[offset]];
  20202. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  20203. colors[cIndex + 9] = colors[cIndex + 3];
  20204. colors[cIndex + 10] = colors[cIndex + 4];
  20205. colors[cIndex + 11] = colors[cIndex + 5];
  20206. colors[cIndex + 12] = colors[cIndex + 6];
  20207. colors[cIndex + 13] = colors[cIndex + 7];
  20208. colors[cIndex + 14] = colors[cIndex + 8];
  20209. colors[cIndex + 15] = colorsMap[cs[offset]];
  20210. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  20211. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  20212. pIndex += 12;
  20213. cIndex += 18;
  20214. }
  20215. }
  20216. break;
  20217. case 'triangles':
  20218. for (var j = 0, jj = ps.length; j < jj; j++) {
  20219. coords[pIndex] = coordsMap[ps[j]];
  20220. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  20221. colors[cIndex] = colorsMap[cs[j]];
  20222. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  20223. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  20224. pIndex += 2;
  20225. cIndex += 3;
  20226. }
  20227. break;
  20228. }
  20229. }
  20230. // draw
  20231. if (backgroundColor) {
  20232. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  20233. backgroundColor[2] / 255, 1.0);
  20234. } else {
  20235. gl.clearColor(0, 0, 0, 0);
  20236. }
  20237. gl.clear(gl.COLOR_BUFFER_BIT);
  20238. var coordsBuffer = gl.createBuffer();
  20239. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  20240. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  20241. gl.enableVertexAttribArray(cache.positionLocation);
  20242. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  20243. var colorsBuffer = gl.createBuffer();
  20244. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  20245. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  20246. gl.enableVertexAttribArray(cache.colorLocation);
  20247. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  20248. 0, 0);
  20249. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  20250. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  20251. gl.drawArrays(gl.TRIANGLES, 0, count);
  20252. gl.flush();
  20253. gl.deleteBuffer(coordsBuffer);
  20254. gl.deleteBuffer(colorsBuffer);
  20255. return canvas;
  20256. }
  20257. function cleanup() {
  20258. if (smaskCache && smaskCache.canvas) {
  20259. smaskCache.canvas.width = 0;
  20260. smaskCache.canvas.height = 0;
  20261. }
  20262. if (figuresCache && figuresCache.canvas) {
  20263. figuresCache.canvas.width = 0;
  20264. figuresCache.canvas.height = 0;
  20265. }
  20266. smaskCache = null;
  20267. figuresCache = null;
  20268. }
  20269. return {
  20270. get isEnabled() {
  20271. if (PDFJS.disableWebGL) {
  20272. return false;
  20273. }
  20274. var enabled = false;
  20275. try {
  20276. generateGL();
  20277. enabled = !!currentGL;
  20278. } catch (e) { }
  20279. return shadow(this, 'isEnabled', enabled);
  20280. },
  20281. composeSMask: composeSMask,
  20282. drawFigures: drawFigures,
  20283. clear: cleanup
  20284. };
  20285. })();
  20286. exports.WebGLUtils = WebGLUtils;
  20287. }));
  20288. (function (root, factory) {
  20289. {
  20290. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20291. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20292. root.pdfjsCoreJpx);
  20293. }
  20294. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20295. coreJpx) {
  20296. var Util = sharedUtil.Util;
  20297. var error = sharedUtil.error;
  20298. var info = sharedUtil.info;
  20299. var isArray = sharedUtil.isArray;
  20300. var shadow = sharedUtil.shadow;
  20301. var warn = sharedUtil.warn;
  20302. var Dict = corePrimitives.Dict;
  20303. var Jbig2Image = coreJbig2.Jbig2Image;
  20304. var JpegImage = coreJpg.JpegImage;
  20305. var JpxImage = coreJpx.JpxImage;
  20306. var coreParser; // see _setCoreParser below
  20307. var EOF; // = coreParser.EOF;
  20308. var Lexer; // = coreParser.Lexer;
  20309. var coreColorSpace; // see _setCoreColorSpace below
  20310. var ColorSpace; // = coreColorSpace.ColorSpace;
  20311. var Stream = (function StreamClosure() {
  20312. function Stream(arrayBuffer, start, length, dict) {
  20313. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20314. arrayBuffer : new Uint8Array(arrayBuffer));
  20315. this.start = start || 0;
  20316. this.pos = this.start;
  20317. this.end = (start + length) || this.bytes.length;
  20318. this.dict = dict;
  20319. }
  20320. // required methods for a stream. if a particular stream does not
  20321. // implement these, an error should be thrown
  20322. Stream.prototype = {
  20323. get length() {
  20324. return this.end - this.start;
  20325. },
  20326. get isEmpty() {
  20327. return this.length === 0;
  20328. },
  20329. getByte: function Stream_getByte() {
  20330. if (this.pos >= this.end) {
  20331. return -1;
  20332. }
  20333. return this.bytes[this.pos++];
  20334. },
  20335. getUint16: function Stream_getUint16() {
  20336. var b0 = this.getByte();
  20337. var b1 = this.getByte();
  20338. if (b0 === -1 || b1 === -1) {
  20339. return -1;
  20340. }
  20341. return (b0 << 8) + b1;
  20342. },
  20343. getInt32: function Stream_getInt32() {
  20344. var b0 = this.getByte();
  20345. var b1 = this.getByte();
  20346. var b2 = this.getByte();
  20347. var b3 = this.getByte();
  20348. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20349. },
  20350. // returns subarray of original buffer
  20351. // should only be read
  20352. getBytes: function Stream_getBytes(length) {
  20353. var bytes = this.bytes;
  20354. var pos = this.pos;
  20355. var strEnd = this.end;
  20356. if (!length) {
  20357. return bytes.subarray(pos, strEnd);
  20358. }
  20359. var end = pos + length;
  20360. if (end > strEnd) {
  20361. end = strEnd;
  20362. }
  20363. this.pos = end;
  20364. return bytes.subarray(pos, end);
  20365. },
  20366. peekByte: function Stream_peekByte() {
  20367. var peekedByte = this.getByte();
  20368. this.pos--;
  20369. return peekedByte;
  20370. },
  20371. peekBytes: function Stream_peekBytes(length) {
  20372. var bytes = this.getBytes(length);
  20373. this.pos -= bytes.length;
  20374. return bytes;
  20375. },
  20376. skip: function Stream_skip(n) {
  20377. if (!n) {
  20378. n = 1;
  20379. }
  20380. this.pos += n;
  20381. },
  20382. reset: function Stream_reset() {
  20383. this.pos = this.start;
  20384. },
  20385. moveStart: function Stream_moveStart() {
  20386. this.start = this.pos;
  20387. },
  20388. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20389. return new Stream(this.bytes.buffer, start, length, dict);
  20390. },
  20391. isStream: true
  20392. };
  20393. return Stream;
  20394. })();
  20395. var StringStream = (function StringStreamClosure() {
  20396. function StringStream(str) {
  20397. var length = str.length;
  20398. var bytes = new Uint8Array(length);
  20399. for (var n = 0; n < length; ++n) {
  20400. bytes[n] = str.charCodeAt(n);
  20401. }
  20402. Stream.call(this, bytes);
  20403. }
  20404. StringStream.prototype = Stream.prototype;
  20405. return StringStream;
  20406. })();
  20407. // super class for the decoding streams
  20408. var DecodeStream = (function DecodeStreamClosure() {
  20409. // Lots of DecodeStreams are created whose buffers are never used. For these
  20410. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20411. // having special cases that would be required if we used |null| for an empty
  20412. // buffer.
  20413. var emptyBuffer = new Uint8Array(0);
  20414. function DecodeStream(maybeMinBufferLength) {
  20415. this.pos = 0;
  20416. this.bufferLength = 0;
  20417. this.eof = false;
  20418. this.buffer = emptyBuffer;
  20419. this.minBufferLength = 512;
  20420. if (maybeMinBufferLength) {
  20421. // Compute the first power of two that is as big as maybeMinBufferLength.
  20422. while (this.minBufferLength < maybeMinBufferLength) {
  20423. this.minBufferLength *= 2;
  20424. }
  20425. }
  20426. }
  20427. DecodeStream.prototype = {
  20428. get isEmpty() {
  20429. while (!this.eof && this.bufferLength === 0) {
  20430. this.readBlock();
  20431. }
  20432. return this.bufferLength === 0;
  20433. },
  20434. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20435. var buffer = this.buffer;
  20436. if (requested <= buffer.byteLength) {
  20437. return buffer;
  20438. }
  20439. var size = this.minBufferLength;
  20440. while (size < requested) {
  20441. size *= 2;
  20442. }
  20443. var buffer2 = new Uint8Array(size);
  20444. buffer2.set(buffer);
  20445. return (this.buffer = buffer2);
  20446. },
  20447. getByte: function DecodeStream_getByte() {
  20448. var pos = this.pos;
  20449. while (this.bufferLength <= pos) {
  20450. if (this.eof) {
  20451. return -1;
  20452. }
  20453. this.readBlock();
  20454. }
  20455. return this.buffer[this.pos++];
  20456. },
  20457. getUint16: function DecodeStream_getUint16() {
  20458. var b0 = this.getByte();
  20459. var b1 = this.getByte();
  20460. if (b0 === -1 || b1 === -1) {
  20461. return -1;
  20462. }
  20463. return (b0 << 8) + b1;
  20464. },
  20465. getInt32: function DecodeStream_getInt32() {
  20466. var b0 = this.getByte();
  20467. var b1 = this.getByte();
  20468. var b2 = this.getByte();
  20469. var b3 = this.getByte();
  20470. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20471. },
  20472. getBytes: function DecodeStream_getBytes(length) {
  20473. var end, pos = this.pos;
  20474. if (length) {
  20475. this.ensureBuffer(pos + length);
  20476. end = pos + length;
  20477. while (!this.eof && this.bufferLength < end) {
  20478. this.readBlock();
  20479. }
  20480. var bufEnd = this.bufferLength;
  20481. if (end > bufEnd) {
  20482. end = bufEnd;
  20483. }
  20484. } else {
  20485. while (!this.eof) {
  20486. this.readBlock();
  20487. }
  20488. end = this.bufferLength;
  20489. }
  20490. this.pos = end;
  20491. return this.buffer.subarray(pos, end);
  20492. },
  20493. peekByte: function DecodeStream_peekByte() {
  20494. var peekedByte = this.getByte();
  20495. this.pos--;
  20496. return peekedByte;
  20497. },
  20498. peekBytes: function DecodeStream_peekBytes(length) {
  20499. var bytes = this.getBytes(length);
  20500. this.pos -= bytes.length;
  20501. return bytes;
  20502. },
  20503. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20504. var end = start + length;
  20505. while (this.bufferLength <= end && !this.eof) {
  20506. this.readBlock();
  20507. }
  20508. return new Stream(this.buffer, start, length, dict);
  20509. },
  20510. skip: function DecodeStream_skip(n) {
  20511. if (!n) {
  20512. n = 1;
  20513. }
  20514. this.pos += n;
  20515. },
  20516. reset: function DecodeStream_reset() {
  20517. this.pos = 0;
  20518. },
  20519. getBaseStreams: function DecodeStream_getBaseStreams() {
  20520. if (this.str && this.str.getBaseStreams) {
  20521. return this.str.getBaseStreams();
  20522. }
  20523. return [];
  20524. }
  20525. };
  20526. return DecodeStream;
  20527. })();
  20528. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20529. function StreamsSequenceStream(streams) {
  20530. this.streams = streams;
  20531. DecodeStream.call(this, /* maybeLength = */ null);
  20532. }
  20533. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20534. StreamsSequenceStream.prototype.readBlock =
  20535. function streamSequenceStreamReadBlock() {
  20536. var streams = this.streams;
  20537. if (streams.length === 0) {
  20538. this.eof = true;
  20539. return;
  20540. }
  20541. var stream = streams.shift();
  20542. var chunk = stream.getBytes();
  20543. var bufferLength = this.bufferLength;
  20544. var newLength = bufferLength + chunk.length;
  20545. var buffer = this.ensureBuffer(newLength);
  20546. buffer.set(chunk, bufferLength);
  20547. this.bufferLength = newLength;
  20548. };
  20549. StreamsSequenceStream.prototype.getBaseStreams =
  20550. function StreamsSequenceStream_getBaseStreams() {
  20551. var baseStreams = [];
  20552. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20553. var stream = this.streams[i];
  20554. if (stream.getBaseStreams) {
  20555. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20556. }
  20557. }
  20558. return baseStreams;
  20559. };
  20560. return StreamsSequenceStream;
  20561. })();
  20562. var FlateStream = (function FlateStreamClosure() {
  20563. var codeLenCodeMap = new Int32Array([
  20564. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20565. ]);
  20566. var lengthDecode = new Int32Array([
  20567. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20568. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20569. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20570. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20571. ]);
  20572. var distDecode = new Int32Array([
  20573. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20574. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20575. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20576. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20577. ]);
  20578. var fixedLitCodeTab = [new Int32Array([
  20579. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20580. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20581. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20582. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20583. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20584. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20585. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20586. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20587. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20588. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20589. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20590. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20591. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20592. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20593. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20594. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20595. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20596. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20597. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20598. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20599. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20600. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20601. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20602. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20603. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20604. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20605. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20606. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20607. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20608. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20609. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20610. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20611. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20612. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20613. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20614. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20615. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20616. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20617. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20618. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20619. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20620. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20621. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20622. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20623. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20624. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20625. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20626. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20627. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20628. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20629. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20630. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20631. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20632. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20633. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20634. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20635. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20636. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20637. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20638. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20639. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20640. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20641. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20642. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20643. ]), 9];
  20644. var fixedDistCodeTab = [new Int32Array([
  20645. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20646. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20647. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20648. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  20649. ]), 5];
  20650. function FlateStream(str, maybeLength) {
  20651. this.str = str;
  20652. this.dict = str.dict;
  20653. var cmf = str.getByte();
  20654. var flg = str.getByte();
  20655. if (cmf === -1 || flg === -1) {
  20656. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  20657. }
  20658. if ((cmf & 0x0f) !== 0x08) {
  20659. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  20660. }
  20661. if ((((cmf << 8) + flg) % 31) !== 0) {
  20662. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  20663. }
  20664. if (flg & 0x20) {
  20665. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  20666. }
  20667. this.codeSize = 0;
  20668. this.codeBuf = 0;
  20669. DecodeStream.call(this, maybeLength);
  20670. }
  20671. FlateStream.prototype = Object.create(DecodeStream.prototype);
  20672. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  20673. var str = this.str;
  20674. var codeSize = this.codeSize;
  20675. var codeBuf = this.codeBuf;
  20676. var b;
  20677. while (codeSize < bits) {
  20678. if ((b = str.getByte()) === -1) {
  20679. error('Bad encoding in flate stream');
  20680. }
  20681. codeBuf |= b << codeSize;
  20682. codeSize += 8;
  20683. }
  20684. b = codeBuf & ((1 << bits) - 1);
  20685. this.codeBuf = codeBuf >> bits;
  20686. this.codeSize = codeSize -= bits;
  20687. return b;
  20688. };
  20689. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  20690. var str = this.str;
  20691. var codes = table[0];
  20692. var maxLen = table[1];
  20693. var codeSize = this.codeSize;
  20694. var codeBuf = this.codeBuf;
  20695. var b;
  20696. while (codeSize < maxLen) {
  20697. if ((b = str.getByte()) === -1) {
  20698. // premature end of stream. code might however still be valid.
  20699. // codeSize < codeLen check below guards against incomplete codeVal.
  20700. break;
  20701. }
  20702. codeBuf |= (b << codeSize);
  20703. codeSize += 8;
  20704. }
  20705. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  20706. var codeLen = code >> 16;
  20707. var codeVal = code & 0xffff;
  20708. if (codeLen < 1 || codeSize < codeLen) {
  20709. error('Bad encoding in flate stream');
  20710. }
  20711. this.codeBuf = (codeBuf >> codeLen);
  20712. this.codeSize = (codeSize - codeLen);
  20713. return codeVal;
  20714. };
  20715. FlateStream.prototype.generateHuffmanTable =
  20716. function flateStreamGenerateHuffmanTable(lengths) {
  20717. var n = lengths.length;
  20718. // find max code length
  20719. var maxLen = 0;
  20720. var i;
  20721. for (i = 0; i < n; ++i) {
  20722. if (lengths[i] > maxLen) {
  20723. maxLen = lengths[i];
  20724. }
  20725. }
  20726. // build the table
  20727. var size = 1 << maxLen;
  20728. var codes = new Int32Array(size);
  20729. for (var len = 1, code = 0, skip = 2;
  20730. len <= maxLen;
  20731. ++len, code <<= 1, skip <<= 1) {
  20732. for (var val = 0; val < n; ++val) {
  20733. if (lengths[val] === len) {
  20734. // bit-reverse the code
  20735. var code2 = 0;
  20736. var t = code;
  20737. for (i = 0; i < len; ++i) {
  20738. code2 = (code2 << 1) | (t & 1);
  20739. t >>= 1;
  20740. }
  20741. // fill the table entries
  20742. for (i = code2; i < size; i += skip) {
  20743. codes[i] = (len << 16) | val;
  20744. }
  20745. ++code;
  20746. }
  20747. }
  20748. }
  20749. return [codes, maxLen];
  20750. };
  20751. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  20752. var buffer, len;
  20753. var str = this.str;
  20754. // read block header
  20755. var hdr = this.getBits(3);
  20756. if (hdr & 1) {
  20757. this.eof = true;
  20758. }
  20759. hdr >>= 1;
  20760. if (hdr === 0) { // uncompressed block
  20761. var b;
  20762. if ((b = str.getByte()) === -1) {
  20763. error('Bad block header in flate stream');
  20764. }
  20765. var blockLen = b;
  20766. if ((b = str.getByte()) === -1) {
  20767. error('Bad block header in flate stream');
  20768. }
  20769. blockLen |= (b << 8);
  20770. if ((b = str.getByte()) === -1) {
  20771. error('Bad block header in flate stream');
  20772. }
  20773. var check = b;
  20774. if ((b = str.getByte()) === -1) {
  20775. error('Bad block header in flate stream');
  20776. }
  20777. check |= (b << 8);
  20778. if (check !== (~blockLen & 0xffff) &&
  20779. (blockLen !== 0 || check !== 0)) {
  20780. // Ignoring error for bad "empty" block (see issue 1277)
  20781. error('Bad uncompressed block length in flate stream');
  20782. }
  20783. this.codeBuf = 0;
  20784. this.codeSize = 0;
  20785. var bufferLength = this.bufferLength;
  20786. buffer = this.ensureBuffer(bufferLength + blockLen);
  20787. var end = bufferLength + blockLen;
  20788. this.bufferLength = end;
  20789. if (blockLen === 0) {
  20790. if (str.peekByte() === -1) {
  20791. this.eof = true;
  20792. }
  20793. } else {
  20794. for (var n = bufferLength; n < end; ++n) {
  20795. if ((b = str.getByte()) === -1) {
  20796. this.eof = true;
  20797. break;
  20798. }
  20799. buffer[n] = b;
  20800. }
  20801. }
  20802. return;
  20803. }
  20804. var litCodeTable;
  20805. var distCodeTable;
  20806. if (hdr === 1) { // compressed block, fixed codes
  20807. litCodeTable = fixedLitCodeTab;
  20808. distCodeTable = fixedDistCodeTab;
  20809. } else if (hdr === 2) { // compressed block, dynamic codes
  20810. var numLitCodes = this.getBits(5) + 257;
  20811. var numDistCodes = this.getBits(5) + 1;
  20812. var numCodeLenCodes = this.getBits(4) + 4;
  20813. // build the code lengths code table
  20814. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  20815. var i;
  20816. for (i = 0; i < numCodeLenCodes; ++i) {
  20817. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  20818. }
  20819. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  20820. // build the literal and distance code tables
  20821. len = 0;
  20822. i = 0;
  20823. var codes = numLitCodes + numDistCodes;
  20824. var codeLengths = new Uint8Array(codes);
  20825. var bitsLength, bitsOffset, what;
  20826. while (i < codes) {
  20827. var code = this.getCode(codeLenCodeTab);
  20828. if (code === 16) {
  20829. bitsLength = 2; bitsOffset = 3; what = len;
  20830. } else if (code === 17) {
  20831. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  20832. } else if (code === 18) {
  20833. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  20834. } else {
  20835. codeLengths[i++] = len = code;
  20836. continue;
  20837. }
  20838. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  20839. while (repeatLength-- > 0) {
  20840. codeLengths[i++] = what;
  20841. }
  20842. }
  20843. litCodeTable =
  20844. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  20845. distCodeTable =
  20846. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  20847. } else {
  20848. error('Unknown block type in flate stream');
  20849. }
  20850. buffer = this.buffer;
  20851. var limit = buffer ? buffer.length : 0;
  20852. var pos = this.bufferLength;
  20853. while (true) {
  20854. var code1 = this.getCode(litCodeTable);
  20855. if (code1 < 256) {
  20856. if (pos + 1 >= limit) {
  20857. buffer = this.ensureBuffer(pos + 1);
  20858. limit = buffer.length;
  20859. }
  20860. buffer[pos++] = code1;
  20861. continue;
  20862. }
  20863. if (code1 === 256) {
  20864. this.bufferLength = pos;
  20865. return;
  20866. }
  20867. code1 -= 257;
  20868. code1 = lengthDecode[code1];
  20869. var code2 = code1 >> 16;
  20870. if (code2 > 0) {
  20871. code2 = this.getBits(code2);
  20872. }
  20873. len = (code1 & 0xffff) + code2;
  20874. code1 = this.getCode(distCodeTable);
  20875. code1 = distDecode[code1];
  20876. code2 = code1 >> 16;
  20877. if (code2 > 0) {
  20878. code2 = this.getBits(code2);
  20879. }
  20880. var dist = (code1 & 0xffff) + code2;
  20881. if (pos + len >= limit) {
  20882. buffer = this.ensureBuffer(pos + len);
  20883. limit = buffer.length;
  20884. }
  20885. for (var k = 0; k < len; ++k, ++pos) {
  20886. buffer[pos] = buffer[pos - dist];
  20887. }
  20888. }
  20889. };
  20890. return FlateStream;
  20891. })();
  20892. var PredictorStream = (function PredictorStreamClosure() {
  20893. function PredictorStream(str, maybeLength, params) {
  20894. var predictor = this.predictor = params.get('Predictor') || 1;
  20895. if (predictor <= 1) {
  20896. return str; // no prediction
  20897. }
  20898. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  20899. error('Unsupported predictor: ' + predictor);
  20900. }
  20901. if (predictor === 2) {
  20902. this.readBlock = this.readBlockTiff;
  20903. } else {
  20904. this.readBlock = this.readBlockPng;
  20905. }
  20906. this.str = str;
  20907. this.dict = str.dict;
  20908. var colors = this.colors = params.get('Colors') || 1;
  20909. var bits = this.bits = params.get('BitsPerComponent') || 8;
  20910. var columns = this.columns = params.get('Columns') || 1;
  20911. this.pixBytes = (colors * bits + 7) >> 3;
  20912. this.rowBytes = (columns * colors * bits + 7) >> 3;
  20913. DecodeStream.call(this, maybeLength);
  20914. return this;
  20915. }
  20916. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  20917. PredictorStream.prototype.readBlockTiff =
  20918. function predictorStreamReadBlockTiff() {
  20919. var rowBytes = this.rowBytes;
  20920. var bufferLength = this.bufferLength;
  20921. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  20922. var bits = this.bits;
  20923. var colors = this.colors;
  20924. var rawBytes = this.str.getBytes(rowBytes);
  20925. this.eof = !rawBytes.length;
  20926. if (this.eof) {
  20927. return;
  20928. }
  20929. var inbuf = 0, outbuf = 0;
  20930. var inbits = 0, outbits = 0;
  20931. var pos = bufferLength;
  20932. var i;
  20933. if (bits === 1) {
  20934. for (i = 0; i < rowBytes; ++i) {
  20935. var c = rawBytes[i];
  20936. inbuf = (inbuf << 8) | c;
  20937. // bitwise addition is exclusive or
  20938. // first shift inbuf and then add
  20939. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  20940. // truncate inbuf (assumes colors < 16)
  20941. inbuf &= 0xFFFF;
  20942. }
  20943. } else if (bits === 8) {
  20944. for (i = 0; i < colors; ++i) {
  20945. buffer[pos++] = rawBytes[i];
  20946. }
  20947. for (; i < rowBytes; ++i) {
  20948. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  20949. pos++;
  20950. }
  20951. } else {
  20952. var compArray = new Uint8Array(colors + 1);
  20953. var bitMask = (1 << bits) - 1;
  20954. var j = 0, k = bufferLength;
  20955. var columns = this.columns;
  20956. for (i = 0; i < columns; ++i) {
  20957. for (var kk = 0; kk < colors; ++kk) {
  20958. if (inbits < bits) {
  20959. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  20960. inbits += 8;
  20961. }
  20962. compArray[kk] = (compArray[kk] +
  20963. (inbuf >> (inbits - bits))) & bitMask;
  20964. inbits -= bits;
  20965. outbuf = (outbuf << bits) | compArray[kk];
  20966. outbits += bits;
  20967. if (outbits >= 8) {
  20968. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  20969. outbits -= 8;
  20970. }
  20971. }
  20972. }
  20973. if (outbits > 0) {
  20974. buffer[k++] = (outbuf << (8 - outbits)) +
  20975. (inbuf & ((1 << (8 - outbits)) - 1));
  20976. }
  20977. }
  20978. this.bufferLength += rowBytes;
  20979. };
  20980. PredictorStream.prototype.readBlockPng =
  20981. function predictorStreamReadBlockPng() {
  20982. var rowBytes = this.rowBytes;
  20983. var pixBytes = this.pixBytes;
  20984. var predictor = this.str.getByte();
  20985. var rawBytes = this.str.getBytes(rowBytes);
  20986. this.eof = !rawBytes.length;
  20987. if (this.eof) {
  20988. return;
  20989. }
  20990. var bufferLength = this.bufferLength;
  20991. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  20992. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  20993. if (prevRow.length === 0) {
  20994. prevRow = new Uint8Array(rowBytes);
  20995. }
  20996. var i, j = bufferLength, up, c;
  20997. switch (predictor) {
  20998. case 0:
  20999. for (i = 0; i < rowBytes; ++i) {
  21000. buffer[j++] = rawBytes[i];
  21001. }
  21002. break;
  21003. case 1:
  21004. for (i = 0; i < pixBytes; ++i) {
  21005. buffer[j++] = rawBytes[i];
  21006. }
  21007. for (; i < rowBytes; ++i) {
  21008. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21009. j++;
  21010. }
  21011. break;
  21012. case 2:
  21013. for (i = 0; i < rowBytes; ++i) {
  21014. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21015. }
  21016. break;
  21017. case 3:
  21018. for (i = 0; i < pixBytes; ++i) {
  21019. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21020. }
  21021. for (; i < rowBytes; ++i) {
  21022. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21023. rawBytes[i]) & 0xFF;
  21024. j++;
  21025. }
  21026. break;
  21027. case 4:
  21028. // we need to save the up left pixels values. the simplest way
  21029. // is to create a new buffer
  21030. for (i = 0; i < pixBytes; ++i) {
  21031. up = prevRow[i];
  21032. c = rawBytes[i];
  21033. buffer[j++] = up + c;
  21034. }
  21035. for (; i < rowBytes; ++i) {
  21036. up = prevRow[i];
  21037. var upLeft = prevRow[i - pixBytes];
  21038. var left = buffer[j - pixBytes];
  21039. var p = left + up - upLeft;
  21040. var pa = p - left;
  21041. if (pa < 0) {
  21042. pa = -pa;
  21043. }
  21044. var pb = p - up;
  21045. if (pb < 0) {
  21046. pb = -pb;
  21047. }
  21048. var pc = p - upLeft;
  21049. if (pc < 0) {
  21050. pc = -pc;
  21051. }
  21052. c = rawBytes[i];
  21053. if (pa <= pb && pa <= pc) {
  21054. buffer[j++] = left + c;
  21055. } else if (pb <= pc) {
  21056. buffer[j++] = up + c;
  21057. } else {
  21058. buffer[j++] = upLeft + c;
  21059. }
  21060. }
  21061. break;
  21062. default:
  21063. error('Unsupported predictor: ' + predictor);
  21064. }
  21065. this.bufferLength += rowBytes;
  21066. };
  21067. return PredictorStream;
  21068. })();
  21069. /**
  21070. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21071. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21072. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21073. * a library to decode these images and the stream behaves like all the other
  21074. * DecodeStreams.
  21075. */
  21076. var JpegStream = (function JpegStreamClosure() {
  21077. function JpegStream(stream, maybeLength, dict, xref) {
  21078. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21079. // Note: this seems to mainly affect inline images.
  21080. var ch;
  21081. while ((ch = stream.getByte()) !== -1) {
  21082. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21083. stream.skip(-1); // Reset the stream position to the SOI.
  21084. break;
  21085. }
  21086. }
  21087. this.stream = stream;
  21088. this.maybeLength = maybeLength;
  21089. this.dict = dict;
  21090. DecodeStream.call(this, maybeLength);
  21091. }
  21092. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21093. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21094. get: function JpegStream_bytes() {
  21095. // If this.maybeLength is null, we'll get the entire stream.
  21096. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21097. },
  21098. configurable: true
  21099. });
  21100. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21101. if (this.bufferLength) {
  21102. return;
  21103. }
  21104. try {
  21105. var jpegImage = new JpegImage();
  21106. // checking if values needs to be transformed before conversion
  21107. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  21108. var decodeArr = this.dict.get('Decode');
  21109. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21110. var decodeArrLength = decodeArr.length;
  21111. var transform = new Int32Array(decodeArrLength);
  21112. var transformNeeded = false;
  21113. var maxValue = (1 << bitsPerComponent) - 1;
  21114. for (var i = 0; i < decodeArrLength; i += 2) {
  21115. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21116. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21117. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21118. transformNeeded = true;
  21119. }
  21120. }
  21121. if (transformNeeded) {
  21122. jpegImage.decodeTransform = transform;
  21123. }
  21124. }
  21125. jpegImage.parse(this.bytes);
  21126. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21127. this.forceRGB);
  21128. this.buffer = data;
  21129. this.bufferLength = data.length;
  21130. this.eof = true;
  21131. } catch (e) {
  21132. error('JPEG error: ' + e);
  21133. }
  21134. };
  21135. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21136. this.ensureBuffer();
  21137. return this.buffer;
  21138. };
  21139. JpegStream.prototype.getIR = function JpegStream_getIR() {
  21140. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  21141. };
  21142. /**
  21143. * Checks if the image can be decoded and displayed by the browser without any
  21144. * further processing such as color space conversions.
  21145. */
  21146. JpegStream.prototype.isNativelySupported =
  21147. function JpegStream_isNativelySupported(xref, res) {
  21148. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  21149. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  21150. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  21151. };
  21152. /**
  21153. * Checks if the image can be decoded by the browser.
  21154. */
  21155. JpegStream.prototype.isNativelyDecodable =
  21156. function JpegStream_isNativelyDecodable(xref, res) {
  21157. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  21158. return (cs.numComps === 1 || cs.numComps === 3) &&
  21159. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  21160. };
  21161. return JpegStream;
  21162. })();
  21163. /**
  21164. * For JPEG 2000's we use a library to decode these images and
  21165. * the stream behaves like all the other DecodeStreams.
  21166. */
  21167. var JpxStream = (function JpxStreamClosure() {
  21168. function JpxStream(stream, maybeLength, dict) {
  21169. this.stream = stream;
  21170. this.maybeLength = maybeLength;
  21171. this.dict = dict;
  21172. DecodeStream.call(this, maybeLength);
  21173. }
  21174. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21175. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21176. get: function JpxStream_bytes() {
  21177. // If this.maybeLength is null, we'll get the entire stream.
  21178. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21179. },
  21180. configurable: true
  21181. });
  21182. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21183. if (this.bufferLength) {
  21184. return;
  21185. }
  21186. var jpxImage = new JpxImage();
  21187. jpxImage.parse(this.bytes);
  21188. var width = jpxImage.width;
  21189. var height = jpxImage.height;
  21190. var componentsCount = jpxImage.componentsCount;
  21191. var tileCount = jpxImage.tiles.length;
  21192. if (tileCount === 1) {
  21193. this.buffer = jpxImage.tiles[0].items;
  21194. } else {
  21195. var data = new Uint8Array(width * height * componentsCount);
  21196. for (var k = 0; k < tileCount; k++) {
  21197. var tileComponents = jpxImage.tiles[k];
  21198. var tileWidth = tileComponents.width;
  21199. var tileHeight = tileComponents.height;
  21200. var tileLeft = tileComponents.left;
  21201. var tileTop = tileComponents.top;
  21202. var src = tileComponents.items;
  21203. var srcPosition = 0;
  21204. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21205. var imgRowSize = width * componentsCount;
  21206. var tileRowSize = tileWidth * componentsCount;
  21207. for (var j = 0; j < tileHeight; j++) {
  21208. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21209. data.set(rowBytes, dataPosition);
  21210. srcPosition += tileRowSize;
  21211. dataPosition += imgRowSize;
  21212. }
  21213. }
  21214. this.buffer = data;
  21215. }
  21216. this.bufferLength = this.buffer.length;
  21217. this.eof = true;
  21218. };
  21219. return JpxStream;
  21220. })();
  21221. /**
  21222. * For JBIG2's we use a library to decode these images and
  21223. * the stream behaves like all the other DecodeStreams.
  21224. */
  21225. var Jbig2Stream = (function Jbig2StreamClosure() {
  21226. function Jbig2Stream(stream, maybeLength, dict) {
  21227. this.stream = stream;
  21228. this.maybeLength = maybeLength;
  21229. this.dict = dict;
  21230. DecodeStream.call(this, maybeLength);
  21231. }
  21232. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21233. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21234. get: function Jbig2Stream_bytes() {
  21235. // If this.maybeLength is null, we'll get the entire stream.
  21236. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21237. },
  21238. configurable: true
  21239. });
  21240. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21241. if (this.bufferLength) {
  21242. return;
  21243. }
  21244. var jbig2Image = new Jbig2Image();
  21245. var chunks = [], xref = this.dict.xref;
  21246. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  21247. // According to the PDF specification, DecodeParms can be either
  21248. // a dictionary, or an array whose elements are dictionaries.
  21249. if (isArray(decodeParams)) {
  21250. if (decodeParams.length > 1) {
  21251. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21252. 'not supported.');
  21253. }
  21254. decodeParams = xref.fetchIfRef(decodeParams[0]);
  21255. }
  21256. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21257. var globalsStream = decodeParams.get('JBIG2Globals');
  21258. var globals = globalsStream.getBytes();
  21259. chunks.push({data: globals, start: 0, end: globals.length});
  21260. }
  21261. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21262. var data = jbig2Image.parseChunks(chunks);
  21263. var dataLength = data.length;
  21264. // JBIG2 had black as 1 and white as 0, inverting the colors
  21265. for (var i = 0; i < dataLength; i++) {
  21266. data[i] ^= 0xFF;
  21267. }
  21268. this.buffer = data;
  21269. this.bufferLength = dataLength;
  21270. this.eof = true;
  21271. };
  21272. return Jbig2Stream;
  21273. })();
  21274. var DecryptStream = (function DecryptStreamClosure() {
  21275. function DecryptStream(str, maybeLength, decrypt) {
  21276. this.str = str;
  21277. this.dict = str.dict;
  21278. this.decrypt = decrypt;
  21279. this.nextChunk = null;
  21280. this.initialized = false;
  21281. DecodeStream.call(this, maybeLength);
  21282. }
  21283. var chunkSize = 512;
  21284. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21285. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21286. var chunk;
  21287. if (this.initialized) {
  21288. chunk = this.nextChunk;
  21289. } else {
  21290. chunk = this.str.getBytes(chunkSize);
  21291. this.initialized = true;
  21292. }
  21293. if (!chunk || chunk.length === 0) {
  21294. this.eof = true;
  21295. return;
  21296. }
  21297. this.nextChunk = this.str.getBytes(chunkSize);
  21298. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21299. var decrypt = this.decrypt;
  21300. chunk = decrypt(chunk, !hasMoreData);
  21301. var bufferLength = this.bufferLength;
  21302. var i, n = chunk.length;
  21303. var buffer = this.ensureBuffer(bufferLength + n);
  21304. for (i = 0; i < n; i++) {
  21305. buffer[bufferLength++] = chunk[i];
  21306. }
  21307. this.bufferLength = bufferLength;
  21308. };
  21309. return DecryptStream;
  21310. })();
  21311. var Ascii85Stream = (function Ascii85StreamClosure() {
  21312. function Ascii85Stream(str, maybeLength) {
  21313. this.str = str;
  21314. this.dict = str.dict;
  21315. this.input = new Uint8Array(5);
  21316. // Most streams increase in size when decoded, but Ascii85 streams
  21317. // typically shrink by ~20%.
  21318. if (maybeLength) {
  21319. maybeLength = 0.8 * maybeLength;
  21320. }
  21321. DecodeStream.call(this, maybeLength);
  21322. }
  21323. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21324. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21325. var TILDA_CHAR = 0x7E; // '~'
  21326. var Z_LOWER_CHAR = 0x7A; // 'z'
  21327. var EOF = -1;
  21328. var str = this.str;
  21329. var c = str.getByte();
  21330. while (Lexer.isSpace(c)) {
  21331. c = str.getByte();
  21332. }
  21333. if (c === EOF || c === TILDA_CHAR) {
  21334. this.eof = true;
  21335. return;
  21336. }
  21337. var bufferLength = this.bufferLength, buffer;
  21338. var i;
  21339. // special code for z
  21340. if (c === Z_LOWER_CHAR) {
  21341. buffer = this.ensureBuffer(bufferLength + 4);
  21342. for (i = 0; i < 4; ++i) {
  21343. buffer[bufferLength + i] = 0;
  21344. }
  21345. this.bufferLength += 4;
  21346. } else {
  21347. var input = this.input;
  21348. input[0] = c;
  21349. for (i = 1; i < 5; ++i) {
  21350. c = str.getByte();
  21351. while (Lexer.isSpace(c)) {
  21352. c = str.getByte();
  21353. }
  21354. input[i] = c;
  21355. if (c === EOF || c === TILDA_CHAR) {
  21356. break;
  21357. }
  21358. }
  21359. buffer = this.ensureBuffer(bufferLength + i - 1);
  21360. this.bufferLength += i - 1;
  21361. // partial ending;
  21362. if (i < 5) {
  21363. for (; i < 5; ++i) {
  21364. input[i] = 0x21 + 84;
  21365. }
  21366. this.eof = true;
  21367. }
  21368. var t = 0;
  21369. for (i = 0; i < 5; ++i) {
  21370. t = t * 85 + (input[i] - 0x21);
  21371. }
  21372. for (i = 3; i >= 0; --i) {
  21373. buffer[bufferLength + i] = t & 0xFF;
  21374. t >>= 8;
  21375. }
  21376. }
  21377. };
  21378. return Ascii85Stream;
  21379. })();
  21380. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21381. function AsciiHexStream(str, maybeLength) {
  21382. this.str = str;
  21383. this.dict = str.dict;
  21384. this.firstDigit = -1;
  21385. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21386. // by 50%.
  21387. if (maybeLength) {
  21388. maybeLength = 0.5 * maybeLength;
  21389. }
  21390. DecodeStream.call(this, maybeLength);
  21391. }
  21392. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21393. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21394. var UPSTREAM_BLOCK_SIZE = 8000;
  21395. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21396. if (!bytes.length) {
  21397. this.eof = true;
  21398. return;
  21399. }
  21400. var maxDecodeLength = (bytes.length + 1) >> 1;
  21401. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21402. var bufferLength = this.bufferLength;
  21403. var firstDigit = this.firstDigit;
  21404. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21405. var ch = bytes[i], digit;
  21406. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21407. digit = ch & 0x0F;
  21408. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21409. // 'A'-'Z', 'a'-'z'
  21410. digit = (ch & 0x0F) + 9;
  21411. } else if (ch === 0x3E) { // '>'
  21412. this.eof = true;
  21413. break;
  21414. } else { // probably whitespace
  21415. continue; // ignoring
  21416. }
  21417. if (firstDigit < 0) {
  21418. firstDigit = digit;
  21419. } else {
  21420. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21421. firstDigit = -1;
  21422. }
  21423. }
  21424. if (firstDigit >= 0 && this.eof) {
  21425. // incomplete byte
  21426. buffer[bufferLength++] = (firstDigit << 4);
  21427. firstDigit = -1;
  21428. }
  21429. this.firstDigit = firstDigit;
  21430. this.bufferLength = bufferLength;
  21431. };
  21432. return AsciiHexStream;
  21433. })();
  21434. var RunLengthStream = (function RunLengthStreamClosure() {
  21435. function RunLengthStream(str, maybeLength) {
  21436. this.str = str;
  21437. this.dict = str.dict;
  21438. DecodeStream.call(this, maybeLength);
  21439. }
  21440. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21441. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21442. // The repeatHeader has following format. The first byte defines type of run
  21443. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21444. // (in addition to the second byte from the header), n = 129 through 255 -
  21445. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21446. var repeatHeader = this.str.getBytes(2);
  21447. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21448. this.eof = true;
  21449. return;
  21450. }
  21451. var buffer;
  21452. var bufferLength = this.bufferLength;
  21453. var n = repeatHeader[0];
  21454. if (n < 128) {
  21455. // copy n bytes
  21456. buffer = this.ensureBuffer(bufferLength + n + 1);
  21457. buffer[bufferLength++] = repeatHeader[1];
  21458. if (n > 0) {
  21459. var source = this.str.getBytes(n);
  21460. buffer.set(source, bufferLength);
  21461. bufferLength += n;
  21462. }
  21463. } else {
  21464. n = 257 - n;
  21465. var b = repeatHeader[1];
  21466. buffer = this.ensureBuffer(bufferLength + n + 1);
  21467. for (var i = 0; i < n; i++) {
  21468. buffer[bufferLength++] = b;
  21469. }
  21470. }
  21471. this.bufferLength = bufferLength;
  21472. };
  21473. return RunLengthStream;
  21474. })();
  21475. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21476. var ccittEOL = -2;
  21477. var twoDimPass = 0;
  21478. var twoDimHoriz = 1;
  21479. var twoDimVert0 = 2;
  21480. var twoDimVertR1 = 3;
  21481. var twoDimVertL1 = 4;
  21482. var twoDimVertR2 = 5;
  21483. var twoDimVertL2 = 6;
  21484. var twoDimVertR3 = 7;
  21485. var twoDimVertL3 = 8;
  21486. var twoDimTable = [
  21487. [-1, -1], [-1, -1], // 000000x
  21488. [7, twoDimVertL3], // 0000010
  21489. [7, twoDimVertR3], // 0000011
  21490. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21491. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21492. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21493. [4, twoDimPass], [4, twoDimPass],
  21494. [4, twoDimPass], [4, twoDimPass],
  21495. [4, twoDimPass], [4, twoDimPass],
  21496. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21497. [3, twoDimHoriz], [3, twoDimHoriz],
  21498. [3, twoDimHoriz], [3, twoDimHoriz],
  21499. [3, twoDimHoriz], [3, twoDimHoriz],
  21500. [3, twoDimHoriz], [3, twoDimHoriz],
  21501. [3, twoDimHoriz], [3, twoDimHoriz],
  21502. [3, twoDimHoriz], [3, twoDimHoriz],
  21503. [3, twoDimHoriz], [3, twoDimHoriz],
  21504. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21505. [3, twoDimVertL1], [3, twoDimVertL1],
  21506. [3, twoDimVertL1], [3, twoDimVertL1],
  21507. [3, twoDimVertL1], [3, twoDimVertL1],
  21508. [3, twoDimVertL1], [3, twoDimVertL1],
  21509. [3, twoDimVertL1], [3, twoDimVertL1],
  21510. [3, twoDimVertL1], [3, twoDimVertL1],
  21511. [3, twoDimVertL1], [3, twoDimVertL1],
  21512. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21513. [3, twoDimVertR1], [3, twoDimVertR1],
  21514. [3, twoDimVertR1], [3, twoDimVertR1],
  21515. [3, twoDimVertR1], [3, twoDimVertR1],
  21516. [3, twoDimVertR1], [3, twoDimVertR1],
  21517. [3, twoDimVertR1], [3, twoDimVertR1],
  21518. [3, twoDimVertR1], [3, twoDimVertR1],
  21519. [3, twoDimVertR1], [3, twoDimVertR1],
  21520. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21521. [1, twoDimVert0], [1, twoDimVert0],
  21522. [1, twoDimVert0], [1, twoDimVert0],
  21523. [1, twoDimVert0], [1, twoDimVert0],
  21524. [1, twoDimVert0], [1, twoDimVert0],
  21525. [1, twoDimVert0], [1, twoDimVert0],
  21526. [1, twoDimVert0], [1, twoDimVert0],
  21527. [1, twoDimVert0], [1, twoDimVert0],
  21528. [1, twoDimVert0], [1, twoDimVert0],
  21529. [1, twoDimVert0], [1, twoDimVert0],
  21530. [1, twoDimVert0], [1, twoDimVert0],
  21531. [1, twoDimVert0], [1, twoDimVert0],
  21532. [1, twoDimVert0], [1, twoDimVert0],
  21533. [1, twoDimVert0], [1, twoDimVert0],
  21534. [1, twoDimVert0], [1, twoDimVert0],
  21535. [1, twoDimVert0], [1, twoDimVert0],
  21536. [1, twoDimVert0], [1, twoDimVert0],
  21537. [1, twoDimVert0], [1, twoDimVert0],
  21538. [1, twoDimVert0], [1, twoDimVert0],
  21539. [1, twoDimVert0], [1, twoDimVert0],
  21540. [1, twoDimVert0], [1, twoDimVert0],
  21541. [1, twoDimVert0], [1, twoDimVert0],
  21542. [1, twoDimVert0], [1, twoDimVert0],
  21543. [1, twoDimVert0], [1, twoDimVert0],
  21544. [1, twoDimVert0], [1, twoDimVert0],
  21545. [1, twoDimVert0], [1, twoDimVert0],
  21546. [1, twoDimVert0], [1, twoDimVert0],
  21547. [1, twoDimVert0], [1, twoDimVert0],
  21548. [1, twoDimVert0], [1, twoDimVert0],
  21549. [1, twoDimVert0], [1, twoDimVert0],
  21550. [1, twoDimVert0], [1, twoDimVert0],
  21551. [1, twoDimVert0], [1, twoDimVert0]
  21552. ];
  21553. var whiteTable1 = [
  21554. [-1, -1], // 00000
  21555. [12, ccittEOL], // 00001
  21556. [-1, -1], [-1, -1], // 0001x
  21557. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21558. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21559. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21560. [11, 1792], [11, 1792], // 1000x
  21561. [12, 1984], // 10010
  21562. [12, 2048], // 10011
  21563. [12, 2112], // 10100
  21564. [12, 2176], // 10101
  21565. [12, 2240], // 10110
  21566. [12, 2304], // 10111
  21567. [11, 1856], [11, 1856], // 1100x
  21568. [11, 1920], [11, 1920], // 1101x
  21569. [12, 2368], // 11100
  21570. [12, 2432], // 11101
  21571. [12, 2496], // 11110
  21572. [12, 2560] // 11111
  21573. ];
  21574. var whiteTable2 = [
  21575. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21576. [8, 29], [8, 29], // 00000010x
  21577. [8, 30], [8, 30], // 00000011x
  21578. [8, 45], [8, 45], // 00000100x
  21579. [8, 46], [8, 46], // 00000101x
  21580. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21581. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21582. [8, 47], [8, 47], // 00001010x
  21583. [8, 48], [8, 48], // 00001011x
  21584. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21585. [6, 13], [6, 13], [6, 13], [6, 13],
  21586. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21587. [8, 33], [8, 33], // 00010010x
  21588. [8, 34], [8, 34], // 00010011x
  21589. [8, 35], [8, 35], // 00010100x
  21590. [8, 36], [8, 36], // 00010101x
  21591. [8, 37], [8, 37], // 00010110x
  21592. [8, 38], [8, 38], // 00010111x
  21593. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21594. [8, 31], [8, 31], // 00011010x
  21595. [8, 32], [8, 32], // 00011011x
  21596. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21597. [6, 1], [6, 1], [6, 1], [6, 1],
  21598. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21599. [6, 12], [6, 12], [6, 12], [6, 12],
  21600. [8, 53], [8, 53], // 00100100x
  21601. [8, 54], [8, 54], // 00100101x
  21602. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21603. [8, 39], [8, 39], // 00101000x
  21604. [8, 40], [8, 40], // 00101001x
  21605. [8, 41], [8, 41], // 00101010x
  21606. [8, 42], [8, 42], // 00101011x
  21607. [8, 43], [8, 43], // 00101100x
  21608. [8, 44], [8, 44], // 00101101x
  21609. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21610. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21611. [8, 61], [8, 61], // 00110010x
  21612. [8, 62], [8, 62], // 00110011x
  21613. [8, 63], [8, 63], // 00110100x
  21614. [8, 0], [8, 0], // 00110101x
  21615. [8, 320], [8, 320], // 00110110x
  21616. [8, 384], [8, 384], // 00110111x
  21617. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21618. [5, 10], [5, 10], [5, 10], [5, 10],
  21619. [5, 10], [5, 10], [5, 10], [5, 10],
  21620. [5, 10], [5, 10], [5, 10], [5, 10],
  21621. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21622. [5, 11], [5, 11], [5, 11], [5, 11],
  21623. [5, 11], [5, 11], [5, 11], [5, 11],
  21624. [5, 11], [5, 11], [5, 11], [5, 11],
  21625. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21626. [8, 59], [8, 59], // 01001010x
  21627. [8, 60], [8, 60], // 01001011x
  21628. [9, 1472], // 010011000
  21629. [9, 1536], // 010011001
  21630. [9, 1600], // 010011010
  21631. [9, 1728], // 010011011
  21632. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21633. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21634. [8, 49], [8, 49], // 01010010x
  21635. [8, 50], [8, 50], // 01010011x
  21636. [8, 51], [8, 51], // 01010100x
  21637. [8, 52], [8, 52], // 01010101x
  21638. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21639. [8, 55], [8, 55], // 01011000x
  21640. [8, 56], [8, 56], // 01011001x
  21641. [8, 57], [8, 57], // 01011010x
  21642. [8, 58], [8, 58], // 01011011x
  21643. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21644. [6, 192], [6, 192], [6, 192], [6, 192],
  21645. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21646. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21647. [8, 448], [8, 448], // 01100100x
  21648. [8, 512], [8, 512], // 01100101x
  21649. [9, 704], // 011001100
  21650. [9, 768], // 011001101
  21651. [8, 640], [8, 640], // 01100111x
  21652. [8, 576], [8, 576], // 01101000x
  21653. [9, 832], // 011010010
  21654. [9, 896], // 011010011
  21655. [9, 960], // 011010100
  21656. [9, 1024], // 011010101
  21657. [9, 1088], // 011010110
  21658. [9, 1152], // 011010111
  21659. [9, 1216], // 011011000
  21660. [9, 1280], // 011011001
  21661. [9, 1344], // 011011010
  21662. [9, 1408], // 011011011
  21663. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  21664. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  21665. [4, 2], [4, 2], [4, 2], [4, 2],
  21666. [4, 2], [4, 2], [4, 2], [4, 2],
  21667. [4, 2], [4, 2], [4, 2], [4, 2],
  21668. [4, 2], [4, 2], [4, 2], [4, 2],
  21669. [4, 2], [4, 2], [4, 2], [4, 2],
  21670. [4, 2], [4, 2], [4, 2], [4, 2],
  21671. [4, 2], [4, 2], [4, 2], [4, 2],
  21672. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  21673. [4, 3], [4, 3], [4, 3], [4, 3],
  21674. [4, 3], [4, 3], [4, 3], [4, 3],
  21675. [4, 3], [4, 3], [4, 3], [4, 3],
  21676. [4, 3], [4, 3], [4, 3], [4, 3],
  21677. [4, 3], [4, 3], [4, 3], [4, 3],
  21678. [4, 3], [4, 3], [4, 3], [4, 3],
  21679. [4, 3], [4, 3], [4, 3], [4, 3],
  21680. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  21681. [5, 128], [5, 128], [5, 128], [5, 128],
  21682. [5, 128], [5, 128], [5, 128], [5, 128],
  21683. [5, 128], [5, 128], [5, 128], [5, 128],
  21684. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  21685. [5, 8], [5, 8], [5, 8], [5, 8],
  21686. [5, 8], [5, 8], [5, 8], [5, 8],
  21687. [5, 8], [5, 8], [5, 8], [5, 8],
  21688. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  21689. [5, 9], [5, 9], [5, 9], [5, 9],
  21690. [5, 9], [5, 9], [5, 9], [5, 9],
  21691. [5, 9], [5, 9], [5, 9], [5, 9],
  21692. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  21693. [6, 16], [6, 16], [6, 16], [6, 16],
  21694. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  21695. [6, 17], [6, 17], [6, 17], [6, 17],
  21696. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  21697. [4, 4], [4, 4], [4, 4], [4, 4],
  21698. [4, 4], [4, 4], [4, 4], [4, 4],
  21699. [4, 4], [4, 4], [4, 4], [4, 4],
  21700. [4, 4], [4, 4], [4, 4], [4, 4],
  21701. [4, 4], [4, 4], [4, 4], [4, 4],
  21702. [4, 4], [4, 4], [4, 4], [4, 4],
  21703. [4, 4], [4, 4], [4, 4], [4, 4],
  21704. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  21705. [4, 5], [4, 5], [4, 5], [4, 5],
  21706. [4, 5], [4, 5], [4, 5], [4, 5],
  21707. [4, 5], [4, 5], [4, 5], [4, 5],
  21708. [4, 5], [4, 5], [4, 5], [4, 5],
  21709. [4, 5], [4, 5], [4, 5], [4, 5],
  21710. [4, 5], [4, 5], [4, 5], [4, 5],
  21711. [4, 5], [4, 5], [4, 5], [4, 5],
  21712. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  21713. [6, 14], [6, 14], [6, 14], [6, 14],
  21714. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  21715. [6, 15], [6, 15], [6, 15], [6, 15],
  21716. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  21717. [5, 64], [5, 64], [5, 64], [5, 64],
  21718. [5, 64], [5, 64], [5, 64], [5, 64],
  21719. [5, 64], [5, 64], [5, 64], [5, 64],
  21720. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  21721. [4, 6], [4, 6], [4, 6], [4, 6],
  21722. [4, 6], [4, 6], [4, 6], [4, 6],
  21723. [4, 6], [4, 6], [4, 6], [4, 6],
  21724. [4, 6], [4, 6], [4, 6], [4, 6],
  21725. [4, 6], [4, 6], [4, 6], [4, 6],
  21726. [4, 6], [4, 6], [4, 6], [4, 6],
  21727. [4, 6], [4, 6], [4, 6], [4, 6],
  21728. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  21729. [4, 7], [4, 7], [4, 7], [4, 7],
  21730. [4, 7], [4, 7], [4, 7], [4, 7],
  21731. [4, 7], [4, 7], [4, 7], [4, 7],
  21732. [4, 7], [4, 7], [4, 7], [4, 7],
  21733. [4, 7], [4, 7], [4, 7], [4, 7],
  21734. [4, 7], [4, 7], [4, 7], [4, 7],
  21735. [4, 7], [4, 7], [4, 7], [4, 7]
  21736. ];
  21737. var blackTable1 = [
  21738. [-1, -1], [-1, -1], // 000000000000x
  21739. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  21740. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  21741. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  21742. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  21743. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  21744. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  21745. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  21746. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  21747. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  21748. [12, 1984], [12, 1984], // 000000010010x
  21749. [12, 2048], [12, 2048], // 000000010011x
  21750. [12, 2112], [12, 2112], // 000000010100x
  21751. [12, 2176], [12, 2176], // 000000010101x
  21752. [12, 2240], [12, 2240], // 000000010110x
  21753. [12, 2304], [12, 2304], // 000000010111x
  21754. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  21755. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  21756. [12, 2368], [12, 2368], // 000000011100x
  21757. [12, 2432], [12, 2432], // 000000011101x
  21758. [12, 2496], [12, 2496], // 000000011110x
  21759. [12, 2560], [12, 2560], // 000000011111x
  21760. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  21761. [10, 18], [10, 18], [10, 18], [10, 18],
  21762. [12, 52], [12, 52], // 000000100100x
  21763. [13, 640], // 0000001001010
  21764. [13, 704], // 0000001001011
  21765. [13, 768], // 0000001001100
  21766. [13, 832], // 0000001001101
  21767. [12, 55], [12, 55], // 000000100111x
  21768. [12, 56], [12, 56], // 000000101000x
  21769. [13, 1280], // 0000001010010
  21770. [13, 1344], // 0000001010011
  21771. [13, 1408], // 0000001010100
  21772. [13, 1472], // 0000001010101
  21773. [12, 59], [12, 59], // 000000101011x
  21774. [12, 60], [12, 60], // 000000101100x
  21775. [13, 1536], // 0000001011010
  21776. [13, 1600], // 0000001011011
  21777. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  21778. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  21779. [13, 1664], // 0000001100100
  21780. [13, 1728], // 0000001100101
  21781. [12, 320], [12, 320], // 000000110011x
  21782. [12, 384], [12, 384], // 000000110100x
  21783. [12, 448], [12, 448], // 000000110101x
  21784. [13, 512], // 0000001101100
  21785. [13, 576], // 0000001101101
  21786. [12, 53], [12, 53], // 000000110111x
  21787. [12, 54], [12, 54], // 000000111000x
  21788. [13, 896], // 0000001110010
  21789. [13, 960], // 0000001110011
  21790. [13, 1024], // 0000001110100
  21791. [13, 1088], // 0000001110101
  21792. [13, 1152], // 0000001110110
  21793. [13, 1216], // 0000001110111
  21794. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  21795. [10, 64], [10, 64], [10, 64], [10, 64]
  21796. ];
  21797. var blackTable2 = [
  21798. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  21799. [8, 13], [8, 13], [8, 13], [8, 13],
  21800. [8, 13], [8, 13], [8, 13], [8, 13],
  21801. [8, 13], [8, 13], [8, 13], [8, 13],
  21802. [11, 23], [11, 23], // 00000101000x
  21803. [12, 50], // 000001010010
  21804. [12, 51], // 000001010011
  21805. [12, 44], // 000001010100
  21806. [12, 45], // 000001010101
  21807. [12, 46], // 000001010110
  21808. [12, 47], // 000001010111
  21809. [12, 57], // 000001011000
  21810. [12, 58], // 000001011001
  21811. [12, 61], // 000001011010
  21812. [12, 256], // 000001011011
  21813. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  21814. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  21815. [12, 48], // 000001100100
  21816. [12, 49], // 000001100101
  21817. [12, 62], // 000001100110
  21818. [12, 63], // 000001100111
  21819. [12, 30], // 000001101000
  21820. [12, 31], // 000001101001
  21821. [12, 32], // 000001101010
  21822. [12, 33], // 000001101011
  21823. [12, 40], // 000001101100
  21824. [12, 41], // 000001101101
  21825. [11, 22], [11, 22], // 00000110111x
  21826. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  21827. [8, 14], [8, 14], [8, 14], [8, 14],
  21828. [8, 14], [8, 14], [8, 14], [8, 14],
  21829. [8, 14], [8, 14], [8, 14], [8, 14],
  21830. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  21831. [7, 10], [7, 10], [7, 10], [7, 10],
  21832. [7, 10], [7, 10], [7, 10], [7, 10],
  21833. [7, 10], [7, 10], [7, 10], [7, 10],
  21834. [7, 10], [7, 10], [7, 10], [7, 10],
  21835. [7, 10], [7, 10], [7, 10], [7, 10],
  21836. [7, 10], [7, 10], [7, 10], [7, 10],
  21837. [7, 10], [7, 10], [7, 10], [7, 10],
  21838. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  21839. [7, 11], [7, 11], [7, 11], [7, 11],
  21840. [7, 11], [7, 11], [7, 11], [7, 11],
  21841. [7, 11], [7, 11], [7, 11], [7, 11],
  21842. [7, 11], [7, 11], [7, 11], [7, 11],
  21843. [7, 11], [7, 11], [7, 11], [7, 11],
  21844. [7, 11], [7, 11], [7, 11], [7, 11],
  21845. [7, 11], [7, 11], [7, 11], [7, 11],
  21846. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  21847. [9, 15], [9, 15], [9, 15], [9, 15],
  21848. [12, 128], // 000011001000
  21849. [12, 192], // 000011001001
  21850. [12, 26], // 000011001010
  21851. [12, 27], // 000011001011
  21852. [12, 28], // 000011001100
  21853. [12, 29], // 000011001101
  21854. [11, 19], [11, 19], // 00001100111x
  21855. [11, 20], [11, 20], // 00001101000x
  21856. [12, 34], // 000011010010
  21857. [12, 35], // 000011010011
  21858. [12, 36], // 000011010100
  21859. [12, 37], // 000011010101
  21860. [12, 38], // 000011010110
  21861. [12, 39], // 000011010111
  21862. [11, 21], [11, 21], // 00001101100x
  21863. [12, 42], // 000011011010
  21864. [12, 43], // 000011011011
  21865. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  21866. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  21867. [7, 12], [7, 12], [7, 12], [7, 12],
  21868. [7, 12], [7, 12], [7, 12], [7, 12],
  21869. [7, 12], [7, 12], [7, 12], [7, 12],
  21870. [7, 12], [7, 12], [7, 12], [7, 12],
  21871. [7, 12], [7, 12], [7, 12], [7, 12],
  21872. [7, 12], [7, 12], [7, 12], [7, 12],
  21873. [7, 12], [7, 12], [7, 12], [7, 12]
  21874. ];
  21875. var blackTable3 = [
  21876. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  21877. [6, 9], // 000100
  21878. [6, 8], // 000101
  21879. [5, 7], [5, 7], // 00011x
  21880. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  21881. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  21882. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  21883. [3, 1], [3, 1], [3, 1], [3, 1],
  21884. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  21885. [3, 4], [3, 4], [3, 4], [3, 4],
  21886. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  21887. [2, 3], [2, 3], [2, 3], [2, 3],
  21888. [2, 3], [2, 3], [2, 3], [2, 3],
  21889. [2, 3], [2, 3], [2, 3], [2, 3],
  21890. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  21891. [2, 2], [2, 2], [2, 2], [2, 2],
  21892. [2, 2], [2, 2], [2, 2], [2, 2],
  21893. [2, 2], [2, 2], [2, 2], [2, 2]
  21894. ];
  21895. function CCITTFaxStream(str, maybeLength, params) {
  21896. this.str = str;
  21897. this.dict = str.dict;
  21898. params = params || Dict.empty;
  21899. this.encoding = params.get('K') || 0;
  21900. this.eoline = params.get('EndOfLine') || false;
  21901. this.byteAlign = params.get('EncodedByteAlign') || false;
  21902. this.columns = params.get('Columns') || 1728;
  21903. this.rows = params.get('Rows') || 0;
  21904. var eoblock = params.get('EndOfBlock');
  21905. if (eoblock === null || eoblock === undefined) {
  21906. eoblock = true;
  21907. }
  21908. this.eoblock = eoblock;
  21909. this.black = params.get('BlackIs1') || false;
  21910. this.codingLine = new Uint32Array(this.columns + 1);
  21911. this.refLine = new Uint32Array(this.columns + 2);
  21912. this.codingLine[0] = this.columns;
  21913. this.codingPos = 0;
  21914. this.row = 0;
  21915. this.nextLine2D = this.encoding < 0;
  21916. this.inputBits = 0;
  21917. this.inputBuf = 0;
  21918. this.outputBits = 0;
  21919. var code1;
  21920. while ((code1 = this.lookBits(12)) === 0) {
  21921. this.eatBits(1);
  21922. }
  21923. if (code1 === 1) {
  21924. this.eatBits(12);
  21925. }
  21926. if (this.encoding > 0) {
  21927. this.nextLine2D = !this.lookBits(1);
  21928. this.eatBits(1);
  21929. }
  21930. DecodeStream.call(this, maybeLength);
  21931. }
  21932. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  21933. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  21934. while (!this.eof) {
  21935. var c = this.lookChar();
  21936. this.ensureBuffer(this.bufferLength + 1);
  21937. this.buffer[this.bufferLength++] = c;
  21938. }
  21939. };
  21940. CCITTFaxStream.prototype.addPixels =
  21941. function ccittFaxStreamAddPixels(a1, blackPixels) {
  21942. var codingLine = this.codingLine;
  21943. var codingPos = this.codingPos;
  21944. if (a1 > codingLine[codingPos]) {
  21945. if (a1 > this.columns) {
  21946. info('row is wrong length');
  21947. this.err = true;
  21948. a1 = this.columns;
  21949. }
  21950. if ((codingPos & 1) ^ blackPixels) {
  21951. ++codingPos;
  21952. }
  21953. codingLine[codingPos] = a1;
  21954. }
  21955. this.codingPos = codingPos;
  21956. };
  21957. CCITTFaxStream.prototype.addPixelsNeg =
  21958. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  21959. var codingLine = this.codingLine;
  21960. var codingPos = this.codingPos;
  21961. if (a1 > codingLine[codingPos]) {
  21962. if (a1 > this.columns) {
  21963. info('row is wrong length');
  21964. this.err = true;
  21965. a1 = this.columns;
  21966. }
  21967. if ((codingPos & 1) ^ blackPixels) {
  21968. ++codingPos;
  21969. }
  21970. codingLine[codingPos] = a1;
  21971. } else if (a1 < codingLine[codingPos]) {
  21972. if (a1 < 0) {
  21973. info('invalid code');
  21974. this.err = true;
  21975. a1 = 0;
  21976. }
  21977. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  21978. --codingPos;
  21979. }
  21980. codingLine[codingPos] = a1;
  21981. }
  21982. this.codingPos = codingPos;
  21983. };
  21984. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  21985. var refLine = this.refLine;
  21986. var codingLine = this.codingLine;
  21987. var columns = this.columns;
  21988. var refPos, blackPixels, bits, i;
  21989. if (this.outputBits === 0) {
  21990. if (this.eof) {
  21991. return null;
  21992. }
  21993. this.err = false;
  21994. var code1, code2, code3;
  21995. if (this.nextLine2D) {
  21996. for (i = 0; codingLine[i] < columns; ++i) {
  21997. refLine[i] = codingLine[i];
  21998. }
  21999. refLine[i++] = columns;
  22000. refLine[i] = columns;
  22001. codingLine[0] = 0;
  22002. this.codingPos = 0;
  22003. refPos = 0;
  22004. blackPixels = 0;
  22005. while (codingLine[this.codingPos] < columns) {
  22006. code1 = this.getTwoDimCode();
  22007. switch (code1) {
  22008. case twoDimPass:
  22009. this.addPixels(refLine[refPos + 1], blackPixels);
  22010. if (refLine[refPos + 1] < columns) {
  22011. refPos += 2;
  22012. }
  22013. break;
  22014. case twoDimHoriz:
  22015. code1 = code2 = 0;
  22016. if (blackPixels) {
  22017. do {
  22018. code1 += (code3 = this.getBlackCode());
  22019. } while (code3 >= 64);
  22020. do {
  22021. code2 += (code3 = this.getWhiteCode());
  22022. } while (code3 >= 64);
  22023. } else {
  22024. do {
  22025. code1 += (code3 = this.getWhiteCode());
  22026. } while (code3 >= 64);
  22027. do {
  22028. code2 += (code3 = this.getBlackCode());
  22029. } while (code3 >= 64);
  22030. }
  22031. this.addPixels(codingLine[this.codingPos] +
  22032. code1, blackPixels);
  22033. if (codingLine[this.codingPos] < columns) {
  22034. this.addPixels(codingLine[this.codingPos] + code2,
  22035. blackPixels ^ 1);
  22036. }
  22037. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22038. refLine[refPos] < columns) {
  22039. refPos += 2;
  22040. }
  22041. break;
  22042. case twoDimVertR3:
  22043. this.addPixels(refLine[refPos] + 3, blackPixels);
  22044. blackPixels ^= 1;
  22045. if (codingLine[this.codingPos] < columns) {
  22046. ++refPos;
  22047. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22048. refLine[refPos] < columns) {
  22049. refPos += 2;
  22050. }
  22051. }
  22052. break;
  22053. case twoDimVertR2:
  22054. this.addPixels(refLine[refPos] + 2, blackPixels);
  22055. blackPixels ^= 1;
  22056. if (codingLine[this.codingPos] < columns) {
  22057. ++refPos;
  22058. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22059. refLine[refPos] < columns) {
  22060. refPos += 2;
  22061. }
  22062. }
  22063. break;
  22064. case twoDimVertR1:
  22065. this.addPixels(refLine[refPos] + 1, blackPixels);
  22066. blackPixels ^= 1;
  22067. if (codingLine[this.codingPos] < columns) {
  22068. ++refPos;
  22069. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22070. refLine[refPos] < columns) {
  22071. refPos += 2;
  22072. }
  22073. }
  22074. break;
  22075. case twoDimVert0:
  22076. this.addPixels(refLine[refPos], blackPixels);
  22077. blackPixels ^= 1;
  22078. if (codingLine[this.codingPos] < columns) {
  22079. ++refPos;
  22080. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22081. refLine[refPos] < columns) {
  22082. refPos += 2;
  22083. }
  22084. }
  22085. break;
  22086. case twoDimVertL3:
  22087. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22088. blackPixels ^= 1;
  22089. if (codingLine[this.codingPos] < columns) {
  22090. if (refPos > 0) {
  22091. --refPos;
  22092. } else {
  22093. ++refPos;
  22094. }
  22095. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22096. refLine[refPos] < columns) {
  22097. refPos += 2;
  22098. }
  22099. }
  22100. break;
  22101. case twoDimVertL2:
  22102. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22103. blackPixels ^= 1;
  22104. if (codingLine[this.codingPos] < columns) {
  22105. if (refPos > 0) {
  22106. --refPos;
  22107. } else {
  22108. ++refPos;
  22109. }
  22110. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22111. refLine[refPos] < columns) {
  22112. refPos += 2;
  22113. }
  22114. }
  22115. break;
  22116. case twoDimVertL1:
  22117. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22118. blackPixels ^= 1;
  22119. if (codingLine[this.codingPos] < columns) {
  22120. if (refPos > 0) {
  22121. --refPos;
  22122. } else {
  22123. ++refPos;
  22124. }
  22125. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22126. refLine[refPos] < columns) {
  22127. refPos += 2;
  22128. }
  22129. }
  22130. break;
  22131. case EOF:
  22132. this.addPixels(columns, 0);
  22133. this.eof = true;
  22134. break;
  22135. default:
  22136. info('bad 2d code');
  22137. this.addPixels(columns, 0);
  22138. this.err = true;
  22139. }
  22140. }
  22141. } else {
  22142. codingLine[0] = 0;
  22143. this.codingPos = 0;
  22144. blackPixels = 0;
  22145. while (codingLine[this.codingPos] < columns) {
  22146. code1 = 0;
  22147. if (blackPixels) {
  22148. do {
  22149. code1 += (code3 = this.getBlackCode());
  22150. } while (code3 >= 64);
  22151. } else {
  22152. do {
  22153. code1 += (code3 = this.getWhiteCode());
  22154. } while (code3 >= 64);
  22155. }
  22156. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22157. blackPixels ^= 1;
  22158. }
  22159. }
  22160. var gotEOL = false;
  22161. if (this.byteAlign) {
  22162. this.inputBits &= ~7;
  22163. }
  22164. if (!this.eoblock && this.row === this.rows - 1) {
  22165. this.eof = true;
  22166. } else {
  22167. code1 = this.lookBits(12);
  22168. if (this.eoline) {
  22169. while (code1 !== EOF && code1 !== 1) {
  22170. this.eatBits(1);
  22171. code1 = this.lookBits(12);
  22172. }
  22173. } else {
  22174. while (code1 === 0) {
  22175. this.eatBits(1);
  22176. code1 = this.lookBits(12);
  22177. }
  22178. }
  22179. if (code1 === 1) {
  22180. this.eatBits(12);
  22181. gotEOL = true;
  22182. } else if (code1 === EOF) {
  22183. this.eof = true;
  22184. }
  22185. }
  22186. if (!this.eof && this.encoding > 0) {
  22187. this.nextLine2D = !this.lookBits(1);
  22188. this.eatBits(1);
  22189. }
  22190. if (this.eoblock && gotEOL && this.byteAlign) {
  22191. code1 = this.lookBits(12);
  22192. if (code1 === 1) {
  22193. this.eatBits(12);
  22194. if (this.encoding > 0) {
  22195. this.lookBits(1);
  22196. this.eatBits(1);
  22197. }
  22198. if (this.encoding >= 0) {
  22199. for (i = 0; i < 4; ++i) {
  22200. code1 = this.lookBits(12);
  22201. if (code1 !== 1) {
  22202. info('bad rtc code: ' + code1);
  22203. }
  22204. this.eatBits(12);
  22205. if (this.encoding > 0) {
  22206. this.lookBits(1);
  22207. this.eatBits(1);
  22208. }
  22209. }
  22210. }
  22211. this.eof = true;
  22212. }
  22213. } else if (this.err && this.eoline) {
  22214. while (true) {
  22215. code1 = this.lookBits(13);
  22216. if (code1 === EOF) {
  22217. this.eof = true;
  22218. return null;
  22219. }
  22220. if ((code1 >> 1) === 1) {
  22221. break;
  22222. }
  22223. this.eatBits(1);
  22224. }
  22225. this.eatBits(12);
  22226. if (this.encoding > 0) {
  22227. this.eatBits(1);
  22228. this.nextLine2D = !(code1 & 1);
  22229. }
  22230. }
  22231. if (codingLine[0] > 0) {
  22232. this.outputBits = codingLine[this.codingPos = 0];
  22233. } else {
  22234. this.outputBits = codingLine[this.codingPos = 1];
  22235. }
  22236. this.row++;
  22237. }
  22238. var c;
  22239. if (this.outputBits >= 8) {
  22240. c = (this.codingPos & 1) ? 0 : 0xFF;
  22241. this.outputBits -= 8;
  22242. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22243. this.codingPos++;
  22244. this.outputBits = (codingLine[this.codingPos] -
  22245. codingLine[this.codingPos - 1]);
  22246. }
  22247. } else {
  22248. bits = 8;
  22249. c = 0;
  22250. do {
  22251. if (this.outputBits > bits) {
  22252. c <<= bits;
  22253. if (!(this.codingPos & 1)) {
  22254. c |= 0xFF >> (8 - bits);
  22255. }
  22256. this.outputBits -= bits;
  22257. bits = 0;
  22258. } else {
  22259. c <<= this.outputBits;
  22260. if (!(this.codingPos & 1)) {
  22261. c |= 0xFF >> (8 - this.outputBits);
  22262. }
  22263. bits -= this.outputBits;
  22264. this.outputBits = 0;
  22265. if (codingLine[this.codingPos] < columns) {
  22266. this.codingPos++;
  22267. this.outputBits = (codingLine[this.codingPos] -
  22268. codingLine[this.codingPos - 1]);
  22269. } else if (bits > 0) {
  22270. c <<= bits;
  22271. bits = 0;
  22272. }
  22273. }
  22274. } while (bits);
  22275. }
  22276. if (this.black) {
  22277. c ^= 0xFF;
  22278. }
  22279. return c;
  22280. };
  22281. // This functions returns the code found from the table.
  22282. // The start and end parameters set the boundaries for searching the table.
  22283. // The limit parameter is optional. Function returns an array with three
  22284. // values. The first array element indicates whether a valid code is being
  22285. // returned. The second array element is the actual code. The third array
  22286. // element indicates whether EOF was reached.
  22287. CCITTFaxStream.prototype.findTableCode =
  22288. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22289. var limitValue = limit || 0;
  22290. for (var i = start; i <= end; ++i) {
  22291. var code = this.lookBits(i);
  22292. if (code === EOF) {
  22293. return [true, 1, false];
  22294. }
  22295. if (i < end) {
  22296. code <<= end - i;
  22297. }
  22298. if (!limitValue || code >= limitValue) {
  22299. var p = table[code - limitValue];
  22300. if (p[0] === i) {
  22301. this.eatBits(i);
  22302. return [true, p[1], true];
  22303. }
  22304. }
  22305. }
  22306. return [false, 0, false];
  22307. };
  22308. CCITTFaxStream.prototype.getTwoDimCode =
  22309. function ccittFaxStreamGetTwoDimCode() {
  22310. var code = 0;
  22311. var p;
  22312. if (this.eoblock) {
  22313. code = this.lookBits(7);
  22314. p = twoDimTable[code];
  22315. if (p && p[0] > 0) {
  22316. this.eatBits(p[0]);
  22317. return p[1];
  22318. }
  22319. } else {
  22320. var result = this.findTableCode(1, 7, twoDimTable);
  22321. if (result[0] && result[2]) {
  22322. return result[1];
  22323. }
  22324. }
  22325. info('Bad two dim code');
  22326. return EOF;
  22327. };
  22328. CCITTFaxStream.prototype.getWhiteCode =
  22329. function ccittFaxStreamGetWhiteCode() {
  22330. var code = 0;
  22331. var p;
  22332. if (this.eoblock) {
  22333. code = this.lookBits(12);
  22334. if (code === EOF) {
  22335. return 1;
  22336. }
  22337. if ((code >> 5) === 0) {
  22338. p = whiteTable1[code];
  22339. } else {
  22340. p = whiteTable2[code >> 3];
  22341. }
  22342. if (p[0] > 0) {
  22343. this.eatBits(p[0]);
  22344. return p[1];
  22345. }
  22346. } else {
  22347. var result = this.findTableCode(1, 9, whiteTable2);
  22348. if (result[0]) {
  22349. return result[1];
  22350. }
  22351. result = this.findTableCode(11, 12, whiteTable1);
  22352. if (result[0]) {
  22353. return result[1];
  22354. }
  22355. }
  22356. info('bad white code');
  22357. this.eatBits(1);
  22358. return 1;
  22359. };
  22360. CCITTFaxStream.prototype.getBlackCode =
  22361. function ccittFaxStreamGetBlackCode() {
  22362. var code, p;
  22363. if (this.eoblock) {
  22364. code = this.lookBits(13);
  22365. if (code === EOF) {
  22366. return 1;
  22367. }
  22368. if ((code >> 7) === 0) {
  22369. p = blackTable1[code];
  22370. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22371. p = blackTable2[(code >> 1) - 64];
  22372. } else {
  22373. p = blackTable3[code >> 7];
  22374. }
  22375. if (p[0] > 0) {
  22376. this.eatBits(p[0]);
  22377. return p[1];
  22378. }
  22379. } else {
  22380. var result = this.findTableCode(2, 6, blackTable3);
  22381. if (result[0]) {
  22382. return result[1];
  22383. }
  22384. result = this.findTableCode(7, 12, blackTable2, 64);
  22385. if (result[0]) {
  22386. return result[1];
  22387. }
  22388. result = this.findTableCode(10, 13, blackTable1);
  22389. if (result[0]) {
  22390. return result[1];
  22391. }
  22392. }
  22393. info('bad black code');
  22394. this.eatBits(1);
  22395. return 1;
  22396. };
  22397. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22398. var c;
  22399. while (this.inputBits < n) {
  22400. if ((c = this.str.getByte()) === -1) {
  22401. if (this.inputBits === 0) {
  22402. return EOF;
  22403. }
  22404. return ((this.inputBuf << (n - this.inputBits)) &
  22405. (0xFFFF >> (16 - n)));
  22406. }
  22407. this.inputBuf = (this.inputBuf << 8) + c;
  22408. this.inputBits += 8;
  22409. }
  22410. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22411. };
  22412. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22413. if ((this.inputBits -= n) < 0) {
  22414. this.inputBits = 0;
  22415. }
  22416. };
  22417. return CCITTFaxStream;
  22418. })();
  22419. var LZWStream = (function LZWStreamClosure() {
  22420. function LZWStream(str, maybeLength, earlyChange) {
  22421. this.str = str;
  22422. this.dict = str.dict;
  22423. this.cachedData = 0;
  22424. this.bitsCached = 0;
  22425. var maxLzwDictionarySize = 4096;
  22426. var lzwState = {
  22427. earlyChange: earlyChange,
  22428. codeLength: 9,
  22429. nextCode: 258,
  22430. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22431. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22432. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22433. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22434. currentSequenceLength: 0
  22435. };
  22436. for (var i = 0; i < 256; ++i) {
  22437. lzwState.dictionaryValues[i] = i;
  22438. lzwState.dictionaryLengths[i] = 1;
  22439. }
  22440. this.lzwState = lzwState;
  22441. DecodeStream.call(this, maybeLength);
  22442. }
  22443. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22444. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22445. var bitsCached = this.bitsCached;
  22446. var cachedData = this.cachedData;
  22447. while (bitsCached < n) {
  22448. var c = this.str.getByte();
  22449. if (c === -1) {
  22450. this.eof = true;
  22451. return null;
  22452. }
  22453. cachedData = (cachedData << 8) | c;
  22454. bitsCached += 8;
  22455. }
  22456. this.bitsCached = (bitsCached -= n);
  22457. this.cachedData = cachedData;
  22458. this.lastCode = null;
  22459. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22460. };
  22461. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22462. var blockSize = 512;
  22463. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22464. var i, j, q;
  22465. var lzwState = this.lzwState;
  22466. if (!lzwState) {
  22467. return; // eof was found
  22468. }
  22469. var earlyChange = lzwState.earlyChange;
  22470. var nextCode = lzwState.nextCode;
  22471. var dictionaryValues = lzwState.dictionaryValues;
  22472. var dictionaryLengths = lzwState.dictionaryLengths;
  22473. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22474. var codeLength = lzwState.codeLength;
  22475. var prevCode = lzwState.prevCode;
  22476. var currentSequence = lzwState.currentSequence;
  22477. var currentSequenceLength = lzwState.currentSequenceLength;
  22478. var decodedLength = 0;
  22479. var currentBufferLength = this.bufferLength;
  22480. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22481. for (i = 0; i < blockSize; i++) {
  22482. var code = this.readBits(codeLength);
  22483. var hasPrev = currentSequenceLength > 0;
  22484. if (code < 256) {
  22485. currentSequence[0] = code;
  22486. currentSequenceLength = 1;
  22487. } else if (code >= 258) {
  22488. if (code < nextCode) {
  22489. currentSequenceLength = dictionaryLengths[code];
  22490. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22491. currentSequence[j] = dictionaryValues[q];
  22492. q = dictionaryPrevCodes[q];
  22493. }
  22494. } else {
  22495. currentSequence[currentSequenceLength++] = currentSequence[0];
  22496. }
  22497. } else if (code === 256) {
  22498. codeLength = 9;
  22499. nextCode = 258;
  22500. currentSequenceLength = 0;
  22501. continue;
  22502. } else {
  22503. this.eof = true;
  22504. delete this.lzwState;
  22505. break;
  22506. }
  22507. if (hasPrev) {
  22508. dictionaryPrevCodes[nextCode] = prevCode;
  22509. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22510. dictionaryValues[nextCode] = currentSequence[0];
  22511. nextCode++;
  22512. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22513. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22514. 0.6931471805599453 + 1, 12) | 0;
  22515. }
  22516. prevCode = code;
  22517. decodedLength += currentSequenceLength;
  22518. if (estimatedDecodedSize < decodedLength) {
  22519. do {
  22520. estimatedDecodedSize += decodedSizeDelta;
  22521. } while (estimatedDecodedSize < decodedLength);
  22522. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22523. }
  22524. for (j = 0; j < currentSequenceLength; j++) {
  22525. buffer[currentBufferLength++] = currentSequence[j];
  22526. }
  22527. }
  22528. lzwState.nextCode = nextCode;
  22529. lzwState.codeLength = codeLength;
  22530. lzwState.prevCode = prevCode;
  22531. lzwState.currentSequenceLength = currentSequenceLength;
  22532. this.bufferLength = currentBufferLength;
  22533. };
  22534. return LZWStream;
  22535. })();
  22536. var NullStream = (function NullStreamClosure() {
  22537. function NullStream() {
  22538. Stream.call(this, new Uint8Array(0));
  22539. }
  22540. NullStream.prototype = Stream.prototype;
  22541. return NullStream;
  22542. })();
  22543. // TODO refactor to remove dependency on parser.js
  22544. function _setCoreParser(coreParser_) {
  22545. coreParser = coreParser_;
  22546. EOF = coreParser_.EOF;
  22547. Lexer = coreParser_.Lexer;
  22548. }
  22549. exports._setCoreParser = _setCoreParser;
  22550. // TODO refactor to remove dependency on colorspace.js
  22551. function _setCoreColorSpace(coreColorSpace_) {
  22552. coreColorSpace = coreColorSpace_;
  22553. ColorSpace = coreColorSpace_.ColorSpace;
  22554. }
  22555. exports._setCoreColorSpace = _setCoreColorSpace;
  22556. exports.Ascii85Stream = Ascii85Stream;
  22557. exports.AsciiHexStream = AsciiHexStream;
  22558. exports.CCITTFaxStream = CCITTFaxStream;
  22559. exports.DecryptStream = DecryptStream;
  22560. exports.DecodeStream = DecodeStream;
  22561. exports.FlateStream = FlateStream;
  22562. exports.Jbig2Stream = Jbig2Stream;
  22563. exports.JpegStream = JpegStream;
  22564. exports.JpxStream = JpxStream;
  22565. exports.NullStream = NullStream;
  22566. exports.PredictorStream = PredictorStream;
  22567. exports.RunLengthStream = RunLengthStream;
  22568. exports.Stream = Stream;
  22569. exports.StreamsSequenceStream = StreamsSequenceStream;
  22570. exports.StringStream = StringStream;
  22571. exports.LZWStream = LZWStream;
  22572. }));
  22573. (function (root, factory) {
  22574. {
  22575. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  22576. root.pdfjsDisplayWebGL);
  22577. }
  22578. }(this, function (exports, sharedUtil, displayWebGL) {
  22579. var Util = sharedUtil.Util;
  22580. var info = sharedUtil.info;
  22581. var isArray = sharedUtil.isArray;
  22582. var error = sharedUtil.error;
  22583. var WebGLUtils = displayWebGL.WebGLUtils;
  22584. var ShadingIRs = {};
  22585. ShadingIRs.RadialAxial = {
  22586. fromIR: function RadialAxial_fromIR(raw) {
  22587. var type = raw[1];
  22588. var colorStops = raw[2];
  22589. var p0 = raw[3];
  22590. var p1 = raw[4];
  22591. var r0 = raw[5];
  22592. var r1 = raw[6];
  22593. return {
  22594. type: 'Pattern',
  22595. getPattern: function RadialAxial_getPattern(ctx) {
  22596. var grad;
  22597. if (type === 'axial') {
  22598. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  22599. } else if (type === 'radial') {
  22600. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  22601. }
  22602. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  22603. var c = colorStops[i];
  22604. grad.addColorStop(c[0], c[1]);
  22605. }
  22606. return grad;
  22607. }
  22608. };
  22609. }
  22610. };
  22611. var createMeshCanvas = (function createMeshCanvasClosure() {
  22612. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  22613. // Very basic Gouraud-shaded triangle rasterization algorithm.
  22614. var coords = context.coords, colors = context.colors;
  22615. var bytes = data.data, rowSize = data.width * 4;
  22616. var tmp;
  22617. if (coords[p1 + 1] > coords[p2 + 1]) {
  22618. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  22619. }
  22620. if (coords[p2 + 1] > coords[p3 + 1]) {
  22621. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  22622. }
  22623. if (coords[p1 + 1] > coords[p2 + 1]) {
  22624. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  22625. }
  22626. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  22627. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  22628. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  22629. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  22630. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  22631. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  22632. if (y1 >= y3) {
  22633. return;
  22634. }
  22635. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  22636. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  22637. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  22638. var minY = Math.round(y1), maxY = Math.round(y3);
  22639. var xa, car, cag, cab;
  22640. var xb, cbr, cbg, cbb;
  22641. var k;
  22642. for (var y = minY; y <= maxY; y++) {
  22643. if (y < y2) {
  22644. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  22645. xa = x1 - (x1 - x2) * k;
  22646. car = c1r - (c1r - c2r) * k;
  22647. cag = c1g - (c1g - c2g) * k;
  22648. cab = c1b - (c1b - c2b) * k;
  22649. } else {
  22650. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  22651. xa = x2 - (x2 - x3) * k;
  22652. car = c2r - (c2r - c3r) * k;
  22653. cag = c2g - (c2g - c3g) * k;
  22654. cab = c2b - (c2b - c3b) * k;
  22655. }
  22656. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  22657. xb = x1 - (x1 - x3) * k;
  22658. cbr = c1r - (c1r - c3r) * k;
  22659. cbg = c1g - (c1g - c3g) * k;
  22660. cbb = c1b - (c1b - c3b) * k;
  22661. var x1_ = Math.round(Math.min(xa, xb));
  22662. var x2_ = Math.round(Math.max(xa, xb));
  22663. var j = rowSize * y + x1_ * 4;
  22664. for (var x = x1_; x <= x2_; x++) {
  22665. k = (xa - x) / (xa - xb);
  22666. k = k < 0 ? 0 : k > 1 ? 1 : k;
  22667. bytes[j++] = (car - (car - cbr) * k) | 0;
  22668. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  22669. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  22670. bytes[j++] = 255;
  22671. }
  22672. }
  22673. }
  22674. function drawFigure(data, figure, context) {
  22675. var ps = figure.coords;
  22676. var cs = figure.colors;
  22677. var i, ii;
  22678. switch (figure.type) {
  22679. case 'lattice':
  22680. var verticesPerRow = figure.verticesPerRow;
  22681. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  22682. var cols = verticesPerRow - 1;
  22683. for (i = 0; i < rows; i++) {
  22684. var q = i * verticesPerRow;
  22685. for (var j = 0; j < cols; j++, q++) {
  22686. drawTriangle(data, context,
  22687. ps[q], ps[q + 1], ps[q + verticesPerRow],
  22688. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  22689. drawTriangle(data, context,
  22690. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  22691. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  22692. }
  22693. }
  22694. break;
  22695. case 'triangles':
  22696. for (i = 0, ii = ps.length; i < ii; i += 3) {
  22697. drawTriangle(data, context,
  22698. ps[i], ps[i + 1], ps[i + 2],
  22699. cs[i], cs[i + 1], cs[i + 2]);
  22700. }
  22701. break;
  22702. default:
  22703. error('illigal figure');
  22704. break;
  22705. }
  22706. }
  22707. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  22708. backgroundColor, cachedCanvases) {
  22709. // we will increase scale on some weird factor to let antialiasing take
  22710. // care of "rough" edges
  22711. var EXPECTED_SCALE = 1.1;
  22712. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  22713. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  22714. var offsetX = Math.floor(bounds[0]);
  22715. var offsetY = Math.floor(bounds[1]);
  22716. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  22717. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  22718. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  22719. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  22720. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  22721. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  22722. var scaleX = boundsWidth / width;
  22723. var scaleY = boundsHeight / height;
  22724. var context = {
  22725. coords: coords,
  22726. colors: colors,
  22727. offsetX: -offsetX,
  22728. offsetY: -offsetY,
  22729. scaleX: 1 / scaleX,
  22730. scaleY: 1 / scaleY
  22731. };
  22732. var canvas, tmpCanvas, i, ii;
  22733. if (WebGLUtils.isEnabled) {
  22734. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  22735. figures, context);
  22736. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  22737. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  22738. tmpCanvas.context.drawImage(canvas, 0, 0);
  22739. canvas = tmpCanvas.canvas;
  22740. } else {
  22741. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  22742. var tmpCtx = tmpCanvas.context;
  22743. var data = tmpCtx.createImageData(width, height);
  22744. if (backgroundColor) {
  22745. var bytes = data.data;
  22746. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  22747. bytes[i] = backgroundColor[0];
  22748. bytes[i + 1] = backgroundColor[1];
  22749. bytes[i + 2] = backgroundColor[2];
  22750. bytes[i + 3] = 255;
  22751. }
  22752. }
  22753. for (i = 0; i < figures.length; i++) {
  22754. drawFigure(data, figures[i], context);
  22755. }
  22756. tmpCtx.putImageData(data, 0, 0);
  22757. canvas = tmpCanvas.canvas;
  22758. }
  22759. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  22760. scaleX: scaleX, scaleY: scaleY};
  22761. }
  22762. return createMeshCanvas;
  22763. })();
  22764. ShadingIRs.Mesh = {
  22765. fromIR: function Mesh_fromIR(raw) {
  22766. //var type = raw[1];
  22767. var coords = raw[2];
  22768. var colors = raw[3];
  22769. var figures = raw[4];
  22770. var bounds = raw[5];
  22771. var matrix = raw[6];
  22772. //var bbox = raw[7];
  22773. var background = raw[8];
  22774. return {
  22775. type: 'Pattern',
  22776. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  22777. var scale;
  22778. if (shadingFill) {
  22779. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  22780. } else {
  22781. // Obtain scale from matrix and current transformation matrix.
  22782. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  22783. if (matrix) {
  22784. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  22785. scale = [scale[0] * matrixScale[0],
  22786. scale[1] * matrixScale[1]];
  22787. }
  22788. }
  22789. // Rasterizing on the main thread since sending/queue large canvases
  22790. // might cause OOM.
  22791. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  22792. colors, figures, shadingFill ? null : background,
  22793. owner.cachedCanvases);
  22794. if (!shadingFill) {
  22795. ctx.setTransform.apply(ctx, owner.baseTransform);
  22796. if (matrix) {
  22797. ctx.transform.apply(ctx, matrix);
  22798. }
  22799. }
  22800. ctx.translate(temporaryPatternCanvas.offsetX,
  22801. temporaryPatternCanvas.offsetY);
  22802. ctx.scale(temporaryPatternCanvas.scaleX,
  22803. temporaryPatternCanvas.scaleY);
  22804. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  22805. }
  22806. };
  22807. }
  22808. };
  22809. ShadingIRs.Dummy = {
  22810. fromIR: function Dummy_fromIR() {
  22811. return {
  22812. type: 'Pattern',
  22813. getPattern: function Dummy_fromIR_getPattern() {
  22814. return 'hotpink';
  22815. }
  22816. };
  22817. }
  22818. };
  22819. function getShadingPatternFromIR(raw) {
  22820. var shadingIR = ShadingIRs[raw[0]];
  22821. if (!shadingIR) {
  22822. error('Unknown IR type: ' + raw[0]);
  22823. }
  22824. return shadingIR.fromIR(raw);
  22825. }
  22826. var TilingPattern = (function TilingPatternClosure() {
  22827. var PaintType = {
  22828. COLORED: 1,
  22829. UNCOLORED: 2
  22830. };
  22831. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  22832. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  22833. this.operatorList = IR[2];
  22834. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  22835. this.bbox = IR[4];
  22836. this.xstep = IR[5];
  22837. this.ystep = IR[6];
  22838. this.paintType = IR[7];
  22839. this.tilingType = IR[8];
  22840. this.color = color;
  22841. this.canvasGraphicsFactory = canvasGraphicsFactory;
  22842. this.baseTransform = baseTransform;
  22843. this.type = 'Pattern';
  22844. this.ctx = ctx;
  22845. }
  22846. TilingPattern.prototype = {
  22847. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  22848. var operatorList = this.operatorList;
  22849. var bbox = this.bbox;
  22850. var xstep = this.xstep;
  22851. var ystep = this.ystep;
  22852. var paintType = this.paintType;
  22853. var tilingType = this.tilingType;
  22854. var color = this.color;
  22855. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  22856. info('TilingType: ' + tilingType);
  22857. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  22858. var topLeft = [x0, y0];
  22859. // we want the canvas to be as large as the step size
  22860. var botRight = [x0 + xstep, y0 + ystep];
  22861. var width = botRight[0] - topLeft[0];
  22862. var height = botRight[1] - topLeft[1];
  22863. // Obtain scale from matrix and current transformation matrix.
  22864. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  22865. var curMatrixScale = Util.singularValueDecompose2dScale(
  22866. this.baseTransform);
  22867. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  22868. matrixScale[1] * curMatrixScale[1]];
  22869. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  22870. // Use width and height values that are as close as possible to the end
  22871. // result when the pattern is used. Too low value makes the pattern look
  22872. // blurry. Too large value makes it look too crispy.
  22873. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  22874. MAX_PATTERN_SIZE);
  22875. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  22876. MAX_PATTERN_SIZE);
  22877. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  22878. width, height, true);
  22879. var tmpCtx = tmpCanvas.context;
  22880. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  22881. graphics.groupLevel = owner.groupLevel;
  22882. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  22883. this.setScale(width, height, xstep, ystep);
  22884. this.transformToScale(graphics);
  22885. // transform coordinates to pattern space
  22886. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  22887. graphics.transform.apply(graphics, tmpTranslate);
  22888. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  22889. graphics.executeOperatorList(operatorList);
  22890. return tmpCanvas.canvas;
  22891. },
  22892. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  22893. this.scale = [width / xstep, height / ystep];
  22894. },
  22895. transformToScale: function TilingPattern_transformToScale(graphics) {
  22896. var scale = this.scale;
  22897. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  22898. graphics.transform.apply(graphics, tmpScale);
  22899. },
  22900. scaleToContext: function TilingPattern_scaleToContext() {
  22901. var scale = this.scale;
  22902. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  22903. },
  22904. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  22905. if (bbox && isArray(bbox) && bbox.length === 4) {
  22906. var bboxWidth = x1 - x0;
  22907. var bboxHeight = y1 - y0;
  22908. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  22909. graphics.clip();
  22910. graphics.endPath();
  22911. }
  22912. },
  22913. setFillAndStrokeStyleToContext:
  22914. function setFillAndStrokeStyleToContext(context, paintType, color) {
  22915. switch (paintType) {
  22916. case PaintType.COLORED:
  22917. var ctx = this.ctx;
  22918. context.fillStyle = ctx.fillStyle;
  22919. context.strokeStyle = ctx.strokeStyle;
  22920. break;
  22921. case PaintType.UNCOLORED:
  22922. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  22923. context.fillStyle = cssColor;
  22924. context.strokeStyle = cssColor;
  22925. break;
  22926. default:
  22927. error('Unsupported paint type: ' + paintType);
  22928. }
  22929. },
  22930. getPattern: function TilingPattern_getPattern(ctx, owner) {
  22931. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  22932. ctx = this.ctx;
  22933. ctx.setTransform.apply(ctx, this.baseTransform);
  22934. ctx.transform.apply(ctx, this.matrix);
  22935. this.scaleToContext();
  22936. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  22937. }
  22938. };
  22939. return TilingPattern;
  22940. })();
  22941. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  22942. exports.TilingPattern = TilingPattern;
  22943. }));
  22944. (function (root, factory) {
  22945. {
  22946. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  22947. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  22948. }
  22949. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  22950. var PasswordException = sharedUtil.PasswordException;
  22951. var PasswordResponses = sharedUtil.PasswordResponses;
  22952. var bytesToString = sharedUtil.bytesToString;
  22953. var error = sharedUtil.error;
  22954. var isInt = sharedUtil.isInt;
  22955. var stringToBytes = sharedUtil.stringToBytes;
  22956. var utf8StringToString = sharedUtil.utf8StringToString;
  22957. var warn = sharedUtil.warn;
  22958. var Name = corePrimitives.Name;
  22959. var isName = corePrimitives.isName;
  22960. var isDict = corePrimitives.isDict;
  22961. var DecryptStream = coreStream.DecryptStream;
  22962. var ARCFourCipher = (function ARCFourCipherClosure() {
  22963. function ARCFourCipher(key) {
  22964. this.a = 0;
  22965. this.b = 0;
  22966. var s = new Uint8Array(256);
  22967. var i, j = 0, tmp, keyLength = key.length;
  22968. for (i = 0; i < 256; ++i) {
  22969. s[i] = i;
  22970. }
  22971. for (i = 0; i < 256; ++i) {
  22972. tmp = s[i];
  22973. j = (j + tmp + key[i % keyLength]) & 0xFF;
  22974. s[i] = s[j];
  22975. s[j] = tmp;
  22976. }
  22977. this.s = s;
  22978. }
  22979. ARCFourCipher.prototype = {
  22980. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  22981. var i, n = data.length, tmp, tmp2;
  22982. var a = this.a, b = this.b, s = this.s;
  22983. var output = new Uint8Array(n);
  22984. for (i = 0; i < n; ++i) {
  22985. a = (a + 1) & 0xFF;
  22986. tmp = s[a];
  22987. b = (b + tmp) & 0xFF;
  22988. tmp2 = s[b];
  22989. s[a] = tmp2;
  22990. s[b] = tmp;
  22991. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  22992. }
  22993. this.a = a;
  22994. this.b = b;
  22995. return output;
  22996. }
  22997. };
  22998. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  22999. return ARCFourCipher;
  23000. })();
  23001. var calculateMD5 = (function calculateMD5Closure() {
  23002. var r = new Uint8Array([
  23003. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23004. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23005. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23006. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23007. var k = new Int32Array([
  23008. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23009. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23010. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23011. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23012. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23013. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23014. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23015. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23016. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23017. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23018. -145523070, -1120210379, 718787259, -343485551]);
  23019. function hash(data, offset, length) {
  23020. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23021. // pre-processing
  23022. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23023. var padded = new Uint8Array(paddedLength);
  23024. var i, j, n;
  23025. for (i = 0; i < length; ++i) {
  23026. padded[i] = data[offset++];
  23027. }
  23028. padded[i++] = 0x80;
  23029. n = paddedLength - 8;
  23030. while (i < n) {
  23031. padded[i++] = 0;
  23032. }
  23033. padded[i++] = (length << 3) & 0xFF;
  23034. padded[i++] = (length >> 5) & 0xFF;
  23035. padded[i++] = (length >> 13) & 0xFF;
  23036. padded[i++] = (length >> 21) & 0xFF;
  23037. padded[i++] = (length >>> 29) & 0xFF;
  23038. padded[i++] = 0;
  23039. padded[i++] = 0;
  23040. padded[i++] = 0;
  23041. var w = new Int32Array(16);
  23042. for (i = 0; i < paddedLength;) {
  23043. for (j = 0; j < 16; ++j, i += 4) {
  23044. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23045. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23046. }
  23047. var a = h0, b = h1, c = h2, d = h3, f, g;
  23048. for (j = 0; j < 64; ++j) {
  23049. if (j < 16) {
  23050. f = (b & c) | ((~b) & d);
  23051. g = j;
  23052. } else if (j < 32) {
  23053. f = (d & b) | ((~d) & c);
  23054. g = (5 * j + 1) & 15;
  23055. } else if (j < 48) {
  23056. f = b ^ c ^ d;
  23057. g = (3 * j + 5) & 15;
  23058. } else {
  23059. f = c ^ (b | (~d));
  23060. g = (7 * j) & 15;
  23061. }
  23062. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23063. d = c;
  23064. c = b;
  23065. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23066. a = tmp;
  23067. }
  23068. h0 = (h0 + a) | 0;
  23069. h1 = (h1 + b) | 0;
  23070. h2 = (h2 + c) | 0;
  23071. h3 = (h3 + d) | 0;
  23072. }
  23073. return new Uint8Array([
  23074. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23075. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23076. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23077. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23078. ]);
  23079. }
  23080. return hash;
  23081. })();
  23082. var Word64 = (function Word64Closure() {
  23083. function Word64(highInteger, lowInteger) {
  23084. this.high = highInteger | 0;
  23085. this.low = lowInteger | 0;
  23086. }
  23087. Word64.prototype = {
  23088. and: function Word64_and(word) {
  23089. this.high &= word.high;
  23090. this.low &= word.low;
  23091. },
  23092. xor: function Word64_xor(word) {
  23093. this.high ^= word.high;
  23094. this.low ^= word.low;
  23095. },
  23096. or: function Word64_or(word) {
  23097. this.high |= word.high;
  23098. this.low |= word.low;
  23099. },
  23100. shiftRight: function Word64_shiftRight(places) {
  23101. if (places >= 32) {
  23102. this.low = (this.high >>> (places - 32)) | 0;
  23103. this.high = 0;
  23104. } else {
  23105. this.low = (this.low >>> places) | (this.high << (32 - places));
  23106. this.high = (this.high >>> places) | 0;
  23107. }
  23108. },
  23109. shiftLeft: function Word64_shiftLeft(places) {
  23110. if (places >= 32) {
  23111. this.high = this.low << (places - 32);
  23112. this.low = 0;
  23113. } else {
  23114. this.high = (this.high << places) | (this.low >>> (32 - places));
  23115. this.low = this.low << places;
  23116. }
  23117. },
  23118. rotateRight: function Word64_rotateRight(places) {
  23119. var low, high;
  23120. if (places & 32) {
  23121. high = this.low;
  23122. low = this.high;
  23123. } else {
  23124. low = this.low;
  23125. high = this.high;
  23126. }
  23127. places &= 31;
  23128. this.low = (low >>> places) | (high << (32 - places));
  23129. this.high = (high >>> places) | (low << (32 - places));
  23130. },
  23131. not: function Word64_not() {
  23132. this.high = ~this.high;
  23133. this.low = ~this.low;
  23134. },
  23135. add: function Word64_add(word) {
  23136. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  23137. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  23138. if (lowAdd > 0xFFFFFFFF) {
  23139. highAdd += 1;
  23140. }
  23141. this.low = lowAdd | 0;
  23142. this.high = highAdd | 0;
  23143. },
  23144. copyTo: function Word64_copyTo(bytes, offset) {
  23145. bytes[offset] = (this.high >>> 24) & 0xFF;
  23146. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  23147. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  23148. bytes[offset + 3] = this.high & 0xFF;
  23149. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  23150. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  23151. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  23152. bytes[offset + 7] = this.low & 0xFF;
  23153. },
  23154. assign: function Word64_assign(word) {
  23155. this.high = word.high;
  23156. this.low = word.low;
  23157. }
  23158. };
  23159. return Word64;
  23160. })();
  23161. var calculateSHA256 = (function calculateSHA256Closure() {
  23162. function rotr(x, n) {
  23163. return (x >>> n) | (x << 32 - n);
  23164. }
  23165. function ch(x, y, z) {
  23166. return (x & y) ^ (~x & z);
  23167. }
  23168. function maj(x, y, z) {
  23169. return (x & y) ^ (x & z) ^ (y & z);
  23170. }
  23171. function sigma(x) {
  23172. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  23173. }
  23174. function sigmaPrime(x) {
  23175. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  23176. }
  23177. function littleSigma(x) {
  23178. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  23179. }
  23180. function littleSigmaPrime(x) {
  23181. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  23182. }
  23183. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  23184. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  23185. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  23186. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  23187. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  23188. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  23189. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  23190. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  23191. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  23192. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  23193. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  23194. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  23195. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  23196. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  23197. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  23198. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  23199. function hash(data, offset, length) {
  23200. // initial hash values
  23201. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  23202. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  23203. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  23204. // pre-processing
  23205. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  23206. var padded = new Uint8Array(paddedLength);
  23207. var i, j, n;
  23208. for (i = 0; i < length; ++i) {
  23209. padded[i] = data[offset++];
  23210. }
  23211. padded[i++] = 0x80;
  23212. n = paddedLength - 8;
  23213. while (i < n) {
  23214. padded[i++] = 0;
  23215. }
  23216. padded[i++] = 0;
  23217. padded[i++] = 0;
  23218. padded[i++] = 0;
  23219. padded[i++] = (length >>> 29) & 0xFF;
  23220. padded[i++] = (length >> 21) & 0xFF;
  23221. padded[i++] = (length >> 13) & 0xFF;
  23222. padded[i++] = (length >> 5) & 0xFF;
  23223. padded[i++] = (length << 3) & 0xFF;
  23224. var w = new Uint32Array(64);
  23225. // for each 512 bit block
  23226. for (i = 0; i < paddedLength;) {
  23227. for (j = 0; j < 16; ++j) {
  23228. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  23229. (padded[i + 2] << 8) | (padded[i + 3]));
  23230. i += 4;
  23231. }
  23232. for (j = 16; j < 64; ++j) {
  23233. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  23234. littleSigma(w[j - 15]) + w[j - 16] | 0;
  23235. }
  23236. var a = h0, b = h1, c = h2, d = h3, e = h4,
  23237. f = h5, g = h6, h = h7, t1, t2;
  23238. for (j = 0; j < 64; ++j) {
  23239. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  23240. t2 = sigma(a) + maj(a, b, c);
  23241. h = g;
  23242. g = f;
  23243. f = e;
  23244. e = (d + t1) | 0;
  23245. d = c;
  23246. c = b;
  23247. b = a;
  23248. a = (t1 + t2) | 0;
  23249. }
  23250. h0 = (h0 + a) | 0;
  23251. h1 = (h1 + b) | 0;
  23252. h2 = (h2 + c) | 0;
  23253. h3 = (h3 + d) | 0;
  23254. h4 = (h4 + e) | 0;
  23255. h5 = (h5 + f) | 0;
  23256. h6 = (h6 + g) | 0;
  23257. h7 = (h7 + h) | 0;
  23258. }
  23259. return new Uint8Array([
  23260. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  23261. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  23262. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  23263. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  23264. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  23265. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  23266. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  23267. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  23268. ]);
  23269. }
  23270. return hash;
  23271. })();
  23272. var calculateSHA512 = (function calculateSHA512Closure() {
  23273. function ch(result, x, y, z, tmp) {
  23274. result.assign(x);
  23275. result.and(y);
  23276. tmp.assign(x);
  23277. tmp.not();
  23278. tmp.and(z);
  23279. result.xor(tmp);
  23280. }
  23281. function maj(result, x, y, z, tmp) {
  23282. result.assign(x);
  23283. result.and(y);
  23284. tmp.assign(x);
  23285. tmp.and(z);
  23286. result.xor(tmp);
  23287. tmp.assign(y);
  23288. tmp.and(z);
  23289. result.xor(tmp);
  23290. }
  23291. function sigma(result, x, tmp) {
  23292. result.assign(x);
  23293. result.rotateRight(28);
  23294. tmp.assign(x);
  23295. tmp.rotateRight(34);
  23296. result.xor(tmp);
  23297. tmp.assign(x);
  23298. tmp.rotateRight(39);
  23299. result.xor(tmp);
  23300. }
  23301. function sigmaPrime(result, x, tmp) {
  23302. result.assign(x);
  23303. result.rotateRight(14);
  23304. tmp.assign(x);
  23305. tmp.rotateRight(18);
  23306. result.xor(tmp);
  23307. tmp.assign(x);
  23308. tmp.rotateRight(41);
  23309. result.xor(tmp);
  23310. }
  23311. function littleSigma(result, x, tmp) {
  23312. result.assign(x);
  23313. result.rotateRight(1);
  23314. tmp.assign(x);
  23315. tmp.rotateRight(8);
  23316. result.xor(tmp);
  23317. tmp.assign(x);
  23318. tmp.shiftRight(7);
  23319. result.xor(tmp);
  23320. }
  23321. function littleSigmaPrime(result, x, tmp) {
  23322. result.assign(x);
  23323. result.rotateRight(19);
  23324. tmp.assign(x);
  23325. tmp.rotateRight(61);
  23326. result.xor(tmp);
  23327. tmp.assign(x);
  23328. tmp.shiftRight(6);
  23329. result.xor(tmp);
  23330. }
  23331. var k = [
  23332. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  23333. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  23334. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  23335. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  23336. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  23337. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  23338. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  23339. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  23340. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  23341. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  23342. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  23343. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  23344. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  23345. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  23346. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  23347. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  23348. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  23349. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  23350. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  23351. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  23352. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  23353. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  23354. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  23355. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  23356. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  23357. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  23358. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  23359. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  23360. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  23361. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  23362. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  23363. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  23364. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  23365. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  23366. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  23367. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  23368. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  23369. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  23370. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  23371. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  23372. function hash(data, offset, length, mode384) {
  23373. mode384 = !!mode384;
  23374. // initial hash values
  23375. var h0, h1, h2, h3, h4, h5, h6, h7;
  23376. if (!mode384) {
  23377. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  23378. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  23379. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  23380. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  23381. h4 = new Word64(0x510e527f, 0xade682d1);
  23382. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  23383. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  23384. h7 = new Word64(0x5be0cd19, 0x137e2179);
  23385. }
  23386. else {
  23387. // SHA384 is exactly the same
  23388. // except with different starting values and a trimmed result
  23389. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  23390. h1 = new Word64(0x629a292a, 0x367cd507);
  23391. h2 = new Word64(0x9159015a, 0x3070dd17);
  23392. h3 = new Word64(0x152fecd8, 0xf70e5939);
  23393. h4 = new Word64(0x67332667, 0xffc00b31);
  23394. h5 = new Word64(0x8eb44a87, 0x68581511);
  23395. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  23396. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  23397. }
  23398. // pre-processing
  23399. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  23400. var padded = new Uint8Array(paddedLength);
  23401. var i, j, n;
  23402. for (i = 0; i < length; ++i) {
  23403. padded[i] = data[offset++];
  23404. }
  23405. padded[i++] = 0x80;
  23406. n = paddedLength - 16;
  23407. while (i < n) {
  23408. padded[i++] = 0;
  23409. }
  23410. padded[i++] = 0;
  23411. padded[i++] = 0;
  23412. padded[i++] = 0;
  23413. padded[i++] = 0;
  23414. padded[i++] = 0;
  23415. padded[i++] = 0;
  23416. padded[i++] = 0;
  23417. padded[i++] = 0;
  23418. padded[i++] = 0;
  23419. padded[i++] = 0;
  23420. padded[i++] = 0;
  23421. padded[i++] = (length >>> 29) & 0xFF;
  23422. padded[i++] = (length >> 21) & 0xFF;
  23423. padded[i++] = (length >> 13) & 0xFF;
  23424. padded[i++] = (length >> 5) & 0xFF;
  23425. padded[i++] = (length << 3) & 0xFF;
  23426. var w = new Array(80);
  23427. for (i = 0; i < 80; i++) {
  23428. w[i] = new Word64(0, 0);
  23429. }
  23430. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  23431. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  23432. var g = new Word64(0, 0), h = new Word64(0, 0);
  23433. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  23434. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  23435. // for each 1024 bit block
  23436. for (i = 0; i < paddedLength;) {
  23437. for (j = 0; j < 16; ++j) {
  23438. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  23439. (padded[i + 2] << 8) | (padded[i + 3]);
  23440. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  23441. (padded[i + 6]) << 8 | (padded[i + 7]);
  23442. i += 8;
  23443. }
  23444. for (j = 16; j < 80; ++j) {
  23445. tmp3 = w[j];
  23446. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  23447. tmp3.add(w[j - 7]);
  23448. littleSigma(tmp1, w[j - 15], tmp2);
  23449. tmp3.add(tmp1);
  23450. tmp3.add(w[j - 16]);
  23451. }
  23452. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  23453. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  23454. for (j = 0; j < 80; ++j) {
  23455. t1.assign(h);
  23456. sigmaPrime(tmp1, e, tmp2);
  23457. t1.add(tmp1);
  23458. ch(tmp1, e, f, g, tmp2);
  23459. t1.add(tmp1);
  23460. t1.add(k[j]);
  23461. t1.add(w[j]);
  23462. sigma(t2, a, tmp2);
  23463. maj(tmp1, a, b, c, tmp2);
  23464. t2.add(tmp1);
  23465. tmp3 = h;
  23466. h = g;
  23467. g = f;
  23468. f = e;
  23469. d.add(t1);
  23470. e = d;
  23471. d = c;
  23472. c = b;
  23473. b = a;
  23474. tmp3.assign(t1);
  23475. tmp3.add(t2);
  23476. a = tmp3;
  23477. }
  23478. h0.add(a);
  23479. h1.add(b);
  23480. h2.add(c);
  23481. h3.add(d);
  23482. h4.add(e);
  23483. h5.add(f);
  23484. h6.add(g);
  23485. h7.add(h);
  23486. }
  23487. var result;
  23488. if (!mode384) {
  23489. result = new Uint8Array(64);
  23490. h0.copyTo(result,0);
  23491. h1.copyTo(result,8);
  23492. h2.copyTo(result,16);
  23493. h3.copyTo(result,24);
  23494. h4.copyTo(result,32);
  23495. h5.copyTo(result,40);
  23496. h6.copyTo(result,48);
  23497. h7.copyTo(result,56);
  23498. }
  23499. else {
  23500. result = new Uint8Array(48);
  23501. h0.copyTo(result,0);
  23502. h1.copyTo(result,8);
  23503. h2.copyTo(result,16);
  23504. h3.copyTo(result,24);
  23505. h4.copyTo(result,32);
  23506. h5.copyTo(result,40);
  23507. }
  23508. return result;
  23509. }
  23510. return hash;
  23511. })();
  23512. var calculateSHA384 = (function calculateSHA384Closure() {
  23513. function hash(data, offset, length) {
  23514. return calculateSHA512(data, offset, length, true);
  23515. }
  23516. return hash;
  23517. })();
  23518. var NullCipher = (function NullCipherClosure() {
  23519. function NullCipher() {
  23520. }
  23521. NullCipher.prototype = {
  23522. decryptBlock: function NullCipher_decryptBlock(data) {
  23523. return data;
  23524. }
  23525. };
  23526. return NullCipher;
  23527. })();
  23528. var AES128Cipher = (function AES128CipherClosure() {
  23529. var rcon = new Uint8Array([
  23530. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23531. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23532. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23533. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23534. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  23535. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  23536. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  23537. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  23538. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  23539. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  23540. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  23541. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  23542. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  23543. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  23544. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  23545. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  23546. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  23547. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23548. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23549. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23550. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23551. 0x74, 0xe8, 0xcb, 0x8d]);
  23552. var s = new Uint8Array([
  23553. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  23554. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  23555. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  23556. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  23557. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  23558. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  23559. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  23560. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  23561. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  23562. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  23563. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  23564. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  23565. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  23566. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  23567. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  23568. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  23569. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  23570. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  23571. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  23572. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  23573. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  23574. 0xb0, 0x54, 0xbb, 0x16]);
  23575. var inv_s = new Uint8Array([
  23576. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  23577. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  23578. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  23579. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  23580. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  23581. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  23582. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  23583. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  23584. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  23585. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  23586. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  23587. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  23588. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  23589. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  23590. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  23591. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  23592. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  23593. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  23594. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  23595. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  23596. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  23597. 0x55, 0x21, 0x0c, 0x7d]);
  23598. var mixCol = new Uint8Array(256);
  23599. for (var i = 0; i < 256; i++) {
  23600. if (i < 128) {
  23601. mixCol[i] = i << 1;
  23602. } else {
  23603. mixCol[i] = (i << 1) ^ 0x1b;
  23604. }
  23605. }
  23606. var mix = new Uint32Array([
  23607. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  23608. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  23609. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  23610. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  23611. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  23612. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  23613. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  23614. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  23615. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  23616. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  23617. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  23618. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  23619. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  23620. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  23621. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  23622. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  23623. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  23624. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  23625. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  23626. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  23627. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  23628. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  23629. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  23630. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  23631. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  23632. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  23633. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  23634. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  23635. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  23636. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  23637. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  23638. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  23639. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  23640. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  23641. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  23642. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  23643. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  23644. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  23645. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  23646. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  23647. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  23648. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  23649. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  23650. function expandKey128(cipherKey) {
  23651. var b = 176, result = new Uint8Array(b);
  23652. result.set(cipherKey);
  23653. for (var j = 16, i = 1; j < b; ++i) {
  23654. // RotWord
  23655. var t1 = result[j - 3], t2 = result[j - 2],
  23656. t3 = result[j - 1], t4 = result[j - 4];
  23657. // SubWord
  23658. t1 = s[t1];
  23659. t2 = s[t2];
  23660. t3 = s[t3];
  23661. t4 = s[t4];
  23662. // Rcon
  23663. t1 = t1 ^ rcon[i];
  23664. for (var n = 0; n < 4; ++n) {
  23665. result[j] = (t1 ^= result[j - 16]);
  23666. j++;
  23667. result[j] = (t2 ^= result[j - 16]);
  23668. j++;
  23669. result[j] = (t3 ^= result[j - 16]);
  23670. j++;
  23671. result[j] = (t4 ^= result[j - 16]);
  23672. j++;
  23673. }
  23674. }
  23675. return result;
  23676. }
  23677. function decrypt128(input, key) {
  23678. var state = new Uint8Array(16);
  23679. state.set(input);
  23680. var i, j, k;
  23681. var t, u, v;
  23682. // AddRoundKey
  23683. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23684. state[j] ^= key[k];
  23685. }
  23686. for (i = 9; i >= 1; --i) {
  23687. // InvShiftRows
  23688. t = state[13];
  23689. state[13] = state[9];
  23690. state[9] = state[5];
  23691. state[5] = state[1];
  23692. state[1] = t;
  23693. t = state[14];
  23694. u = state[10];
  23695. state[14] = state[6];
  23696. state[10] = state[2];
  23697. state[6] = t;
  23698. state[2] = u;
  23699. t = state[15];
  23700. u = state[11];
  23701. v = state[7];
  23702. state[15] = state[3];
  23703. state[11] = t;
  23704. state[7] = u;
  23705. state[3] = v;
  23706. // InvSubBytes
  23707. for (j = 0; j < 16; ++j) {
  23708. state[j] = inv_s[state[j]];
  23709. }
  23710. // AddRoundKey
  23711. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23712. state[j] ^= key[k];
  23713. }
  23714. // InvMixColumns
  23715. for (j = 0; j < 16; j += 4) {
  23716. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  23717. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  23718. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  23719. (s3 >>> 24) ^ (s3 << 8));
  23720. state[j] = (t >>> 24) & 0xFF;
  23721. state[j + 1] = (t >> 16) & 0xFF;
  23722. state[j + 2] = (t >> 8) & 0xFF;
  23723. state[j + 3] = t & 0xFF;
  23724. }
  23725. }
  23726. // InvShiftRows
  23727. t = state[13];
  23728. state[13] = state[9];
  23729. state[9] = state[5];
  23730. state[5] = state[1];
  23731. state[1] = t;
  23732. t = state[14];
  23733. u = state[10];
  23734. state[14] = state[6];
  23735. state[10] = state[2];
  23736. state[6] = t;
  23737. state[2] = u;
  23738. t = state[15];
  23739. u = state[11];
  23740. v = state[7];
  23741. state[15] = state[3];
  23742. state[11] = t;
  23743. state[7] = u;
  23744. state[3] = v;
  23745. for (j = 0; j < 16; ++j) {
  23746. // InvSubBytes
  23747. state[j] = inv_s[state[j]];
  23748. // AddRoundKey
  23749. state[j] ^= key[j];
  23750. }
  23751. return state;
  23752. }
  23753. function encrypt128(input, key) {
  23754. var t, u, v, k;
  23755. var state = new Uint8Array(16);
  23756. state.set(input);
  23757. for (j = 0; j < 16; ++j) {
  23758. // AddRoundKey
  23759. state[j] ^= key[j];
  23760. }
  23761. for (i = 1; i < 10; i++) {
  23762. //SubBytes
  23763. for (j = 0; j < 16; ++j) {
  23764. state[j] = s[state[j]];
  23765. }
  23766. //ShiftRows
  23767. v = state[1];
  23768. state[1] = state[5];
  23769. state[5] = state[9];
  23770. state[9] = state[13];
  23771. state[13] = v;
  23772. v = state[2];
  23773. u = state[6];
  23774. state[2] = state[10];
  23775. state[6] = state[14];
  23776. state[10] = v;
  23777. state[14] = u;
  23778. v = state[3];
  23779. u = state[7];
  23780. t = state[11];
  23781. state[3] = state[15];
  23782. state[7] = v;
  23783. state[11] = u;
  23784. state[15] = t;
  23785. //MixColumns
  23786. for (var j = 0; j < 16; j += 4) {
  23787. var s0 = state[j + 0], s1 = state[j + 1];
  23788. var s2 = state[j + 2], s3 = state[j + 3];
  23789. t = s0 ^ s1 ^ s2 ^ s3;
  23790. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  23791. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  23792. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  23793. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  23794. }
  23795. //AddRoundKey
  23796. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23797. state[j] ^= key[k];
  23798. }
  23799. }
  23800. //SubBytes
  23801. for (j = 0; j < 16; ++j) {
  23802. state[j] = s[state[j]];
  23803. }
  23804. //ShiftRows
  23805. v = state[1];
  23806. state[1] = state[5];
  23807. state[5] = state[9];
  23808. state[9] = state[13];
  23809. state[13] = v;
  23810. v = state[2];
  23811. u = state[6];
  23812. state[2] = state[10];
  23813. state[6] = state[14];
  23814. state[10] = v;
  23815. state[14] = u;
  23816. v = state[3];
  23817. u = state[7];
  23818. t = state[11];
  23819. state[3] = state[15];
  23820. state[7] = v;
  23821. state[11] = u;
  23822. state[15] = t;
  23823. //AddRoundKey
  23824. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23825. state[j] ^= key[k];
  23826. }
  23827. return state;
  23828. }
  23829. function AES128Cipher(key) {
  23830. this.key = expandKey128(key);
  23831. this.buffer = new Uint8Array(16);
  23832. this.bufferPosition = 0;
  23833. }
  23834. function decryptBlock2(data, finalize) {
  23835. var i, j, ii, sourceLength = data.length,
  23836. buffer = this.buffer, bufferLength = this.bufferPosition,
  23837. result = [], iv = this.iv;
  23838. for (i = 0; i < sourceLength; ++i) {
  23839. buffer[bufferLength] = data[i];
  23840. ++bufferLength;
  23841. if (bufferLength < 16) {
  23842. continue;
  23843. }
  23844. // buffer is full, decrypting
  23845. var plain = decrypt128(buffer, this.key);
  23846. // xor-ing the IV vector to get plain text
  23847. for (j = 0; j < 16; ++j) {
  23848. plain[j] ^= iv[j];
  23849. }
  23850. iv = buffer;
  23851. result.push(plain);
  23852. buffer = new Uint8Array(16);
  23853. bufferLength = 0;
  23854. }
  23855. // saving incomplete buffer
  23856. this.buffer = buffer;
  23857. this.bufferLength = bufferLength;
  23858. this.iv = iv;
  23859. if (result.length === 0) {
  23860. return new Uint8Array([]);
  23861. }
  23862. // combining plain text blocks into one
  23863. var outputLength = 16 * result.length;
  23864. if (finalize) {
  23865. // undo a padding that is described in RFC 2898
  23866. var lastBlock = result[result.length - 1];
  23867. var psLen = lastBlock[15];
  23868. if (psLen <= 16) {
  23869. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  23870. if (lastBlock[i] !== psLen) {
  23871. // Invalid padding, assume that the block has no padding.
  23872. psLen = 0;
  23873. break;
  23874. }
  23875. }
  23876. outputLength -= psLen;
  23877. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  23878. }
  23879. }
  23880. var output = new Uint8Array(outputLength);
  23881. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  23882. output.set(result[i], j);
  23883. }
  23884. return output;
  23885. }
  23886. AES128Cipher.prototype = {
  23887. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  23888. var i, sourceLength = data.length;
  23889. var buffer = this.buffer, bufferLength = this.bufferPosition;
  23890. // waiting for IV values -- they are at the start of the stream
  23891. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  23892. buffer[bufferLength] = data[i];
  23893. }
  23894. if (bufferLength < 16) {
  23895. // need more data
  23896. this.bufferLength = bufferLength;
  23897. return new Uint8Array([]);
  23898. }
  23899. this.iv = buffer;
  23900. this.buffer = new Uint8Array(16);
  23901. this.bufferLength = 0;
  23902. // starting decryption
  23903. this.decryptBlock = decryptBlock2;
  23904. return this.decryptBlock(data.subarray(16), finalize);
  23905. },
  23906. encrypt: function AES128Cipher_encrypt(data, iv) {
  23907. var i, j, ii, sourceLength = data.length,
  23908. buffer = this.buffer, bufferLength = this.bufferPosition,
  23909. result = [];
  23910. if (!iv) {
  23911. iv = new Uint8Array(16);
  23912. }
  23913. for (i = 0; i < sourceLength; ++i) {
  23914. buffer[bufferLength] = data[i];
  23915. ++bufferLength;
  23916. if (bufferLength < 16) {
  23917. continue;
  23918. }
  23919. for (j = 0; j < 16; ++j) {
  23920. buffer[j] ^= iv[j];
  23921. }
  23922. // buffer is full, encrypting
  23923. var cipher = encrypt128(buffer, this.key);
  23924. iv = cipher;
  23925. result.push(cipher);
  23926. buffer = new Uint8Array(16);
  23927. bufferLength = 0;
  23928. }
  23929. // saving incomplete buffer
  23930. this.buffer = buffer;
  23931. this.bufferLength = bufferLength;
  23932. this.iv = iv;
  23933. if (result.length === 0) {
  23934. return new Uint8Array([]);
  23935. }
  23936. // combining plain text blocks into one
  23937. var outputLength = 16 * result.length;
  23938. var output = new Uint8Array(outputLength);
  23939. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  23940. output.set(result[i], j);
  23941. }
  23942. return output;
  23943. }
  23944. };
  23945. return AES128Cipher;
  23946. })();
  23947. var AES256Cipher = (function AES256CipherClosure() {
  23948. var rcon = new Uint8Array([
  23949. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23950. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23951. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23952. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23953. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  23954. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  23955. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  23956. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  23957. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  23958. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  23959. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  23960. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  23961. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  23962. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  23963. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  23964. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  23965. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  23966. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23967. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23968. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23969. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23970. 0x74, 0xe8, 0xcb, 0x8d]);
  23971. var s = new Uint8Array([
  23972. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  23973. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  23974. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  23975. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  23976. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  23977. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  23978. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  23979. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  23980. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  23981. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  23982. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  23983. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  23984. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  23985. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  23986. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  23987. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  23988. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  23989. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  23990. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  23991. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  23992. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  23993. 0xb0, 0x54, 0xbb, 0x16]);
  23994. var inv_s = new Uint8Array([
  23995. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  23996. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  23997. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  23998. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  23999. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24000. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24001. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24002. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24003. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24004. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24005. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24006. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24007. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24008. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24009. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24010. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24011. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24012. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24013. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24014. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24015. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24016. 0x55, 0x21, 0x0c, 0x7d]);
  24017. var mixCol = new Uint8Array(256);
  24018. for (var i = 0; i < 256; i++) {
  24019. if (i < 128) {
  24020. mixCol[i] = i << 1;
  24021. } else {
  24022. mixCol[i] = (i << 1) ^ 0x1b;
  24023. }
  24024. }
  24025. var mix = new Uint32Array([
  24026. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24027. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24028. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24029. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24030. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24031. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24032. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24033. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24034. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24035. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24036. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24037. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24038. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24039. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24040. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24041. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24042. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24043. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24044. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24045. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24046. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24047. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24048. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24049. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24050. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24051. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24052. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24053. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24054. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24055. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24056. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24057. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24058. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24059. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24060. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24061. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24062. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24063. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24064. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24065. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24066. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24067. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24068. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24069. function expandKey256(cipherKey) {
  24070. var b = 240, result = new Uint8Array(b);
  24071. var r = 1;
  24072. result.set(cipherKey);
  24073. for (var j = 32, i = 1; j < b; ++i) {
  24074. if (j % 32 === 16) {
  24075. t1 = s[t1];
  24076. t2 = s[t2];
  24077. t3 = s[t3];
  24078. t4 = s[t4];
  24079. } else if (j % 32 === 0) {
  24080. // RotWord
  24081. var t1 = result[j - 3], t2 = result[j - 2],
  24082. t3 = result[j - 1], t4 = result[j - 4];
  24083. // SubWord
  24084. t1 = s[t1];
  24085. t2 = s[t2];
  24086. t3 = s[t3];
  24087. t4 = s[t4];
  24088. // Rcon
  24089. t1 = t1 ^ r;
  24090. if ((r <<= 1) >= 256) {
  24091. r = (r ^ 0x1b) & 0xFF;
  24092. }
  24093. }
  24094. for (var n = 0; n < 4; ++n) {
  24095. result[j] = (t1 ^= result[j - 32]);
  24096. j++;
  24097. result[j] = (t2 ^= result[j - 32]);
  24098. j++;
  24099. result[j] = (t3 ^= result[j - 32]);
  24100. j++;
  24101. result[j] = (t4 ^= result[j - 32]);
  24102. j++;
  24103. }
  24104. }
  24105. return result;
  24106. }
  24107. function decrypt256(input, key) {
  24108. var state = new Uint8Array(16);
  24109. state.set(input);
  24110. var i, j, k;
  24111. var t, u, v;
  24112. // AddRoundKey
  24113. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24114. state[j] ^= key[k];
  24115. }
  24116. for (i = 13; i >= 1; --i) {
  24117. // InvShiftRows
  24118. t = state[13];
  24119. state[13] = state[9];
  24120. state[9] = state[5];
  24121. state[5] = state[1];
  24122. state[1] = t;
  24123. t = state[14];
  24124. u = state[10];
  24125. state[14] = state[6];
  24126. state[10] = state[2];
  24127. state[6] = t;
  24128. state[2] = u;
  24129. t = state[15];
  24130. u = state[11];
  24131. v = state[7];
  24132. state[15] = state[3];
  24133. state[11] = t;
  24134. state[7] = u;
  24135. state[3] = v;
  24136. // InvSubBytes
  24137. for (j = 0; j < 16; ++j) {
  24138. state[j] = inv_s[state[j]];
  24139. }
  24140. // AddRoundKey
  24141. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24142. state[j] ^= key[k];
  24143. }
  24144. // InvMixColumns
  24145. for (j = 0; j < 16; j += 4) {
  24146. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24147. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24148. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24149. (s3 >>> 24) ^ (s3 << 8));
  24150. state[j] = (t >>> 24) & 0xFF;
  24151. state[j + 1] = (t >> 16) & 0xFF;
  24152. state[j + 2] = (t >> 8) & 0xFF;
  24153. state[j + 3] = t & 0xFF;
  24154. }
  24155. }
  24156. // InvShiftRows
  24157. t = state[13];
  24158. state[13] = state[9];
  24159. state[9] = state[5];
  24160. state[5] = state[1];
  24161. state[1] = t;
  24162. t = state[14];
  24163. u = state[10];
  24164. state[14] = state[6];
  24165. state[10] = state[2];
  24166. state[6] = t;
  24167. state[2] = u;
  24168. t = state[15];
  24169. u = state[11];
  24170. v = state[7];
  24171. state[15] = state[3];
  24172. state[11] = t;
  24173. state[7] = u;
  24174. state[3] = v;
  24175. for (j = 0; j < 16; ++j) {
  24176. // InvSubBytes
  24177. state[j] = inv_s[state[j]];
  24178. // AddRoundKey
  24179. state[j] ^= key[j];
  24180. }
  24181. return state;
  24182. }
  24183. function encrypt256(input, key) {
  24184. var t, u, v, k;
  24185. var state = new Uint8Array(16);
  24186. state.set(input);
  24187. for (j = 0; j < 16; ++j) {
  24188. // AddRoundKey
  24189. state[j] ^= key[j];
  24190. }
  24191. for (i = 1; i < 14; i++) {
  24192. //SubBytes
  24193. for (j = 0; j < 16; ++j) {
  24194. state[j] = s[state[j]];
  24195. }
  24196. //ShiftRows
  24197. v = state[1];
  24198. state[1] = state[5];
  24199. state[5] = state[9];
  24200. state[9] = state[13];
  24201. state[13] = v;
  24202. v = state[2];
  24203. u = state[6];
  24204. state[2] = state[10];
  24205. state[6] = state[14];
  24206. state[10] = v;
  24207. state[14] = u;
  24208. v = state[3];
  24209. u = state[7];
  24210. t = state[11];
  24211. state[3] = state[15];
  24212. state[7] = v;
  24213. state[11] = u;
  24214. state[15] = t;
  24215. //MixColumns
  24216. for (var j = 0; j < 16; j += 4) {
  24217. var s0 = state[j + 0], s1 = state[j + 1];
  24218. var s2 = state[j + 2], s3 = state[j + 3];
  24219. t = s0 ^ s1 ^ s2 ^ s3;
  24220. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24221. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24222. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24223. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24224. }
  24225. //AddRoundKey
  24226. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24227. state[j] ^= key[k];
  24228. }
  24229. }
  24230. //SubBytes
  24231. for (j = 0; j < 16; ++j) {
  24232. state[j] = s[state[j]];
  24233. }
  24234. //ShiftRows
  24235. v = state[1];
  24236. state[1] = state[5];
  24237. state[5] = state[9];
  24238. state[9] = state[13];
  24239. state[13] = v;
  24240. v = state[2];
  24241. u = state[6];
  24242. state[2] = state[10];
  24243. state[6] = state[14];
  24244. state[10] = v;
  24245. state[14] = u;
  24246. v = state[3];
  24247. u = state[7];
  24248. t = state[11];
  24249. state[3] = state[15];
  24250. state[7] = v;
  24251. state[11] = u;
  24252. state[15] = t;
  24253. //AddRoundKey
  24254. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24255. state[j] ^= key[k];
  24256. }
  24257. return state;
  24258. }
  24259. function AES256Cipher(key) {
  24260. this.key = expandKey256(key);
  24261. this.buffer = new Uint8Array(16);
  24262. this.bufferPosition = 0;
  24263. }
  24264. function decryptBlock2(data, finalize) {
  24265. var i, j, ii, sourceLength = data.length,
  24266. buffer = this.buffer, bufferLength = this.bufferPosition,
  24267. result = [], iv = this.iv;
  24268. for (i = 0; i < sourceLength; ++i) {
  24269. buffer[bufferLength] = data[i];
  24270. ++bufferLength;
  24271. if (bufferLength < 16) {
  24272. continue;
  24273. }
  24274. // buffer is full, decrypting
  24275. var plain = decrypt256(buffer, this.key);
  24276. // xor-ing the IV vector to get plain text
  24277. for (j = 0; j < 16; ++j) {
  24278. plain[j] ^= iv[j];
  24279. }
  24280. iv = buffer;
  24281. result.push(plain);
  24282. buffer = new Uint8Array(16);
  24283. bufferLength = 0;
  24284. }
  24285. // saving incomplete buffer
  24286. this.buffer = buffer;
  24287. this.bufferLength = bufferLength;
  24288. this.iv = iv;
  24289. if (result.length === 0) {
  24290. return new Uint8Array([]);
  24291. }
  24292. // combining plain text blocks into one
  24293. var outputLength = 16 * result.length;
  24294. if (finalize) {
  24295. // undo a padding that is described in RFC 2898
  24296. var lastBlock = result[result.length - 1];
  24297. var psLen = lastBlock[15];
  24298. if (psLen <= 16) {
  24299. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24300. if (lastBlock[i] !== psLen) {
  24301. // Invalid padding, assume that the block has no padding.
  24302. psLen = 0;
  24303. break;
  24304. }
  24305. }
  24306. outputLength -= psLen;
  24307. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24308. }
  24309. }
  24310. var output = new Uint8Array(outputLength);
  24311. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24312. output.set(result[i], j);
  24313. }
  24314. return output;
  24315. }
  24316. AES256Cipher.prototype = {
  24317. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  24318. var i, sourceLength = data.length;
  24319. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24320. // if not supplied an IV wait for IV values
  24321. // they are at the start of the stream
  24322. if (iv) {
  24323. this.iv = iv;
  24324. } else {
  24325. for (i = 0; bufferLength < 16 &&
  24326. i < sourceLength; ++i, ++bufferLength) {
  24327. buffer[bufferLength] = data[i];
  24328. }
  24329. if (bufferLength < 16) {
  24330. //need more data
  24331. this.bufferLength = bufferLength;
  24332. return new Uint8Array([]);
  24333. }
  24334. this.iv = buffer;
  24335. data = data.subarray(16);
  24336. }
  24337. this.buffer = new Uint8Array(16);
  24338. this.bufferLength = 0;
  24339. // starting decryption
  24340. this.decryptBlock = decryptBlock2;
  24341. return this.decryptBlock(data, finalize);
  24342. },
  24343. encrypt: function AES256Cipher_encrypt(data, iv) {
  24344. var i, j, ii, sourceLength = data.length,
  24345. buffer = this.buffer, bufferLength = this.bufferPosition,
  24346. result = [];
  24347. if (!iv) {
  24348. iv = new Uint8Array(16);
  24349. }
  24350. for (i = 0; i < sourceLength; ++i) {
  24351. buffer[bufferLength] = data[i];
  24352. ++bufferLength;
  24353. if (bufferLength < 16) {
  24354. continue;
  24355. }
  24356. for (j = 0; j < 16; ++j) {
  24357. buffer[j] ^= iv[j];
  24358. }
  24359. // buffer is full, encrypting
  24360. var cipher = encrypt256(buffer, this.key);
  24361. this.iv = cipher;
  24362. result.push(cipher);
  24363. buffer = new Uint8Array(16);
  24364. bufferLength = 0;
  24365. }
  24366. // saving incomplete buffer
  24367. this.buffer = buffer;
  24368. this.bufferLength = bufferLength;
  24369. this.iv = iv;
  24370. if (result.length === 0) {
  24371. return new Uint8Array([]);
  24372. }
  24373. // combining plain text blocks into one
  24374. var outputLength = 16 * result.length;
  24375. var output = new Uint8Array(outputLength);
  24376. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24377. output.set(result[i], j);
  24378. }
  24379. return output;
  24380. }
  24381. };
  24382. return AES256Cipher;
  24383. })();
  24384. var PDF17 = (function PDF17Closure() {
  24385. function compareByteArrays(array1, array2) {
  24386. if (array1.length !== array2.length) {
  24387. return false;
  24388. }
  24389. for (var i = 0; i < array1.length; i++) {
  24390. if (array1[i] !== array2[i]) {
  24391. return false;
  24392. }
  24393. }
  24394. return true;
  24395. }
  24396. function PDF17() {
  24397. }
  24398. PDF17.prototype = {
  24399. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  24400. ownerValidationSalt,
  24401. userBytes,
  24402. ownerPassword) {
  24403. var hashData = new Uint8Array(password.length + 56);
  24404. hashData.set(password, 0);
  24405. hashData.set(ownerValidationSalt, password.length);
  24406. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24407. var result = calculateSHA256(hashData, 0, hashData.length);
  24408. return compareByteArrays(result, ownerPassword);
  24409. },
  24410. checkUserPassword: function PDF17_checkUserPassword(password,
  24411. userValidationSalt,
  24412. userPassword) {
  24413. var hashData = new Uint8Array(password.length + 8);
  24414. hashData.set(password, 0);
  24415. hashData.set(userValidationSalt, password.length);
  24416. var result = calculateSHA256(hashData, 0, hashData.length);
  24417. return compareByteArrays(result, userPassword);
  24418. },
  24419. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  24420. ownerEncryption) {
  24421. var hashData = new Uint8Array(password.length + 56);
  24422. hashData.set(password, 0);
  24423. hashData.set(ownerKeySalt, password.length);
  24424. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24425. var key = calculateSHA256(hashData, 0, hashData.length);
  24426. var cipher = new AES256Cipher(key);
  24427. return cipher.decryptBlock(ownerEncryption,
  24428. false,
  24429. new Uint8Array(16));
  24430. },
  24431. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  24432. userEncryption) {
  24433. var hashData = new Uint8Array(password.length + 8);
  24434. hashData.set(password, 0);
  24435. hashData.set(userKeySalt, password.length);
  24436. //key is the decryption key for the UE string
  24437. var key = calculateSHA256(hashData, 0, hashData.length);
  24438. var cipher = new AES256Cipher(key);
  24439. return cipher.decryptBlock(userEncryption,
  24440. false,
  24441. new Uint8Array(16));
  24442. }
  24443. };
  24444. return PDF17;
  24445. })();
  24446. var PDF20 = (function PDF20Closure() {
  24447. function concatArrays(array1, array2) {
  24448. var t = new Uint8Array(array1.length + array2.length);
  24449. t.set(array1, 0);
  24450. t.set(array2, array1.length);
  24451. return t;
  24452. }
  24453. function calculatePDF20Hash(password, input, userBytes) {
  24454. //This refers to Algorithm 2.B as defined in ISO 32000-2
  24455. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  24456. var e = [0];
  24457. var i = 0;
  24458. while (i < 64 || e[e.length - 1] > i - 32) {
  24459. var arrayLength = password.length + k.length + userBytes.length;
  24460. var k1 = new Uint8Array(arrayLength * 64);
  24461. var array = concatArrays(password, k);
  24462. array = concatArrays(array, userBytes);
  24463. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  24464. k1.set(array, pos);
  24465. }
  24466. //AES128 CBC NO PADDING with
  24467. //first 16 bytes of k as the key and the second 16 as the iv.
  24468. var cipher = new AES128Cipher(k.subarray(0, 16));
  24469. e = cipher.encrypt(k1, k.subarray(16, 32));
  24470. //Now we have to take the first 16 bytes of an unsigned
  24471. //big endian integer... and compute the remainder
  24472. //modulo 3.... That is a fairly large number and
  24473. //JavaScript isn't going to handle that well...
  24474. //So we're using a trick that allows us to perform
  24475. //modulo math byte by byte
  24476. var remainder = 0;
  24477. for (var z = 0; z < 16; z++) {
  24478. remainder *= (256 % 3);
  24479. remainder %= 3;
  24480. remainder += ((e[z] >>> 0) % 3);
  24481. remainder %= 3;
  24482. }
  24483. if (remainder === 0) {
  24484. k = calculateSHA256(e, 0, e.length);
  24485. }
  24486. else if (remainder === 1) {
  24487. k = calculateSHA384(e, 0, e.length);
  24488. }
  24489. else if (remainder === 2) {
  24490. k = calculateSHA512(e, 0, e.length);
  24491. }
  24492. i++;
  24493. }
  24494. return k.subarray(0, 32);
  24495. }
  24496. function PDF20() {
  24497. }
  24498. function compareByteArrays(array1, array2) {
  24499. if (array1.length !== array2.length) {
  24500. return false;
  24501. }
  24502. for (var i = 0; i < array1.length; i++) {
  24503. if (array1[i] !== array2[i]) {
  24504. return false;
  24505. }
  24506. }
  24507. return true;
  24508. }
  24509. PDF20.prototype = {
  24510. hash: function PDF20_hash(password, concatBytes, userBytes) {
  24511. return calculatePDF20Hash(password, concatBytes, userBytes);
  24512. },
  24513. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  24514. ownerValidationSalt,
  24515. userBytes,
  24516. ownerPassword) {
  24517. var hashData = new Uint8Array(password.length + 56);
  24518. hashData.set(password, 0);
  24519. hashData.set(ownerValidationSalt, password.length);
  24520. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24521. var result = calculatePDF20Hash(password, hashData, userBytes);
  24522. return compareByteArrays(result, ownerPassword);
  24523. },
  24524. checkUserPassword: function PDF20_checkUserPassword(password,
  24525. userValidationSalt,
  24526. userPassword) {
  24527. var hashData = new Uint8Array(password.length + 8);
  24528. hashData.set(password, 0);
  24529. hashData.set(userValidationSalt, password.length);
  24530. var result = calculatePDF20Hash(password, hashData, []);
  24531. return compareByteArrays(result, userPassword);
  24532. },
  24533. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  24534. ownerEncryption) {
  24535. var hashData = new Uint8Array(password.length + 56);
  24536. hashData.set(password, 0);
  24537. hashData.set(ownerKeySalt, password.length);
  24538. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24539. var key = calculatePDF20Hash(password, hashData, userBytes);
  24540. var cipher = new AES256Cipher(key);
  24541. return cipher.decryptBlock(ownerEncryption,
  24542. false,
  24543. new Uint8Array(16));
  24544. },
  24545. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  24546. userEncryption) {
  24547. var hashData = new Uint8Array(password.length + 8);
  24548. hashData.set(password, 0);
  24549. hashData.set(userKeySalt, password.length);
  24550. //key is the decryption key for the UE string
  24551. var key = calculatePDF20Hash(password, hashData, []);
  24552. var cipher = new AES256Cipher(key);
  24553. return cipher.decryptBlock(userEncryption,
  24554. false,
  24555. new Uint8Array(16));
  24556. }
  24557. };
  24558. return PDF20;
  24559. })();
  24560. var CipherTransform = (function CipherTransformClosure() {
  24561. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  24562. this.stringCipherConstructor = stringCipherConstructor;
  24563. this.streamCipherConstructor = streamCipherConstructor;
  24564. }
  24565. CipherTransform.prototype = {
  24566. createStream: function CipherTransform_createStream(stream, length) {
  24567. var cipher = new this.streamCipherConstructor();
  24568. return new DecryptStream(stream, length,
  24569. function cipherTransformDecryptStream(data, finalize) {
  24570. return cipher.decryptBlock(data, finalize);
  24571. }
  24572. );
  24573. },
  24574. decryptString: function CipherTransform_decryptString(s) {
  24575. var cipher = new this.stringCipherConstructor();
  24576. var data = stringToBytes(s);
  24577. data = cipher.decryptBlock(data, true);
  24578. return bytesToString(data);
  24579. }
  24580. };
  24581. return CipherTransform;
  24582. })();
  24583. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  24584. var defaultPasswordBytes = new Uint8Array([
  24585. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  24586. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  24587. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  24588. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  24589. function createEncryptionKey20(revision, password, ownerPassword,
  24590. ownerValidationSalt, ownerKeySalt, uBytes,
  24591. userPassword, userValidationSalt, userKeySalt,
  24592. ownerEncryption, userEncryption, perms) {
  24593. if (password) {
  24594. var passwordLength = Math.min(127, password.length);
  24595. password = password.subarray(0, passwordLength);
  24596. } else {
  24597. password = [];
  24598. }
  24599. var pdfAlgorithm;
  24600. if (revision === 6) {
  24601. pdfAlgorithm = new PDF20();
  24602. } else {
  24603. pdfAlgorithm = new PDF17();
  24604. }
  24605. if (pdfAlgorithm) {
  24606. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  24607. userPassword)) {
  24608. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  24609. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  24610. ownerValidationSalt,
  24611. uBytes,
  24612. ownerPassword)) {
  24613. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  24614. ownerEncryption);
  24615. }
  24616. }
  24617. return null;
  24618. }
  24619. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  24620. flags, revision, keyLength, encryptMetadata) {
  24621. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  24622. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  24623. if (password) {
  24624. n = Math.min(32, password.length);
  24625. for (; i < n; ++i) {
  24626. hashData[i] = password[i];
  24627. }
  24628. }
  24629. j = 0;
  24630. while (i < 32) {
  24631. hashData[i++] = defaultPasswordBytes[j++];
  24632. }
  24633. // as now the padded password in the hashData[0..i]
  24634. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  24635. hashData[i++] = ownerPassword[j];
  24636. }
  24637. hashData[i++] = flags & 0xFF;
  24638. hashData[i++] = (flags >> 8) & 0xFF;
  24639. hashData[i++] = (flags >> 16) & 0xFF;
  24640. hashData[i++] = (flags >>> 24) & 0xFF;
  24641. for (j = 0, n = fileId.length; j < n; ++j) {
  24642. hashData[i++] = fileId[j];
  24643. }
  24644. if (revision >= 4 && !encryptMetadata) {
  24645. hashData[i++] = 0xFF;
  24646. hashData[i++] = 0xFF;
  24647. hashData[i++] = 0xFF;
  24648. hashData[i++] = 0xFF;
  24649. }
  24650. var hash = calculateMD5(hashData, 0, i);
  24651. var keyLengthInBytes = keyLength >> 3;
  24652. if (revision >= 3) {
  24653. for (j = 0; j < 50; ++j) {
  24654. hash = calculateMD5(hash, 0, keyLengthInBytes);
  24655. }
  24656. }
  24657. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  24658. var cipher, checkData;
  24659. if (revision >= 3) {
  24660. for (i = 0; i < 32; ++i) {
  24661. hashData[i] = defaultPasswordBytes[i];
  24662. }
  24663. for (j = 0, n = fileId.length; j < n; ++j) {
  24664. hashData[i++] = fileId[j];
  24665. }
  24666. cipher = new ARCFourCipher(encryptionKey);
  24667. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  24668. n = encryptionKey.length;
  24669. var derivedKey = new Uint8Array(n), k;
  24670. for (j = 1; j <= 19; ++j) {
  24671. for (k = 0; k < n; ++k) {
  24672. derivedKey[k] = encryptionKey[k] ^ j;
  24673. }
  24674. cipher = new ARCFourCipher(derivedKey);
  24675. checkData = cipher.encryptBlock(checkData);
  24676. }
  24677. for (j = 0, n = checkData.length; j < n; ++j) {
  24678. if (userPassword[j] !== checkData[j]) {
  24679. return null;
  24680. }
  24681. }
  24682. } else {
  24683. cipher = new ARCFourCipher(encryptionKey);
  24684. checkData = cipher.encryptBlock(defaultPasswordBytes);
  24685. for (j = 0, n = checkData.length; j < n; ++j) {
  24686. if (userPassword[j] !== checkData[j]) {
  24687. return null;
  24688. }
  24689. }
  24690. }
  24691. return encryptionKey;
  24692. }
  24693. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  24694. var hashData = new Uint8Array(32), i = 0, j, n;
  24695. n = Math.min(32, password.length);
  24696. for (; i < n; ++i) {
  24697. hashData[i] = password[i];
  24698. }
  24699. j = 0;
  24700. while (i < 32) {
  24701. hashData[i++] = defaultPasswordBytes[j++];
  24702. }
  24703. var hash = calculateMD5(hashData, 0, i);
  24704. var keyLengthInBytes = keyLength >> 3;
  24705. if (revision >= 3) {
  24706. for (j = 0; j < 50; ++j) {
  24707. hash = calculateMD5(hash, 0, hash.length);
  24708. }
  24709. }
  24710. var cipher, userPassword;
  24711. if (revision >= 3) {
  24712. userPassword = ownerPassword;
  24713. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  24714. for (j = 19; j >= 0; j--) {
  24715. for (k = 0; k < keyLengthInBytes; ++k) {
  24716. derivedKey[k] = hash[k] ^ j;
  24717. }
  24718. cipher = new ARCFourCipher(derivedKey);
  24719. userPassword = cipher.encryptBlock(userPassword);
  24720. }
  24721. } else {
  24722. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  24723. userPassword = cipher.encryptBlock(ownerPassword);
  24724. }
  24725. return userPassword;
  24726. }
  24727. var identityName = Name.get('Identity');
  24728. function CipherTransformFactory(dict, fileId, password) {
  24729. var filter = dict.get('Filter');
  24730. if (!isName(filter) || filter.name !== 'Standard') {
  24731. error('unknown encryption method');
  24732. }
  24733. this.dict = dict;
  24734. var algorithm = dict.get('V');
  24735. if (!isInt(algorithm) ||
  24736. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  24737. algorithm !== 5)) {
  24738. error('unsupported encryption algorithm');
  24739. }
  24740. this.algorithm = algorithm;
  24741. var keyLength = dict.get('Length');
  24742. if (!keyLength) {
  24743. // Spec asks to rely on encryption dictionary's Length entry, however
  24744. // some PDFs don't have it. Trying to recover.
  24745. if (algorithm <= 3) {
  24746. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  24747. keyLength = 40;
  24748. } else {
  24749. // Trying to find default handler -- it usually has Length.
  24750. var cfDict = dict.get('CF');
  24751. var streamCryptoName = dict.get('StmF');
  24752. if (isDict(cfDict) && isName(streamCryptoName)) {
  24753. var handlerDict = cfDict.get(streamCryptoName.name);
  24754. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  24755. if (keyLength < 40) {
  24756. // Sometimes it's incorrect value of bits, generators specify bytes.
  24757. keyLength <<= 3;
  24758. }
  24759. }
  24760. }
  24761. }
  24762. if (!isInt(keyLength) ||
  24763. keyLength < 40 || (keyLength % 8) !== 0) {
  24764. error('invalid key length');
  24765. }
  24766. // prepare keys
  24767. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  24768. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  24769. var flags = dict.get('P');
  24770. var revision = dict.get('R');
  24771. // meaningful when V is 4 or 5
  24772. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  24773. dict.get('EncryptMetadata') !== false);
  24774. this.encryptMetadata = encryptMetadata;
  24775. var fileIdBytes = stringToBytes(fileId);
  24776. var passwordBytes;
  24777. if (password) {
  24778. if (revision === 6) {
  24779. try {
  24780. password = utf8StringToString(password);
  24781. } catch (ex) {
  24782. warn('CipherTransformFactory: ' +
  24783. 'Unable to convert UTF8 encoded password.');
  24784. }
  24785. }
  24786. passwordBytes = stringToBytes(password);
  24787. }
  24788. var encryptionKey;
  24789. if (algorithm !== 5) {
  24790. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  24791. ownerPassword, userPassword, flags,
  24792. revision, keyLength, encryptMetadata);
  24793. }
  24794. else {
  24795. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  24796. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  24797. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  24798. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  24799. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  24800. var ownerEncryption = stringToBytes(dict.get('OE'));
  24801. var userEncryption = stringToBytes(dict.get('UE'));
  24802. var perms = stringToBytes(dict.get('Perms'));
  24803. encryptionKey =
  24804. createEncryptionKey20(revision, passwordBytes,
  24805. ownerPassword, ownerValidationSalt,
  24806. ownerKeySalt, uBytes,
  24807. userPassword, userValidationSalt,
  24808. userKeySalt, ownerEncryption,
  24809. userEncryption, perms);
  24810. }
  24811. if (!encryptionKey && !password) {
  24812. throw new PasswordException('No password given',
  24813. PasswordResponses.NEED_PASSWORD);
  24814. } else if (!encryptionKey && password) {
  24815. // Attempting use the password as an owner password
  24816. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  24817. revision, keyLength);
  24818. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  24819. ownerPassword, userPassword, flags,
  24820. revision, keyLength, encryptMetadata);
  24821. }
  24822. if (!encryptionKey) {
  24823. throw new PasswordException('Incorrect Password',
  24824. PasswordResponses.INCORRECT_PASSWORD);
  24825. }
  24826. this.encryptionKey = encryptionKey;
  24827. if (algorithm >= 4) {
  24828. this.cf = dict.get('CF');
  24829. this.stmf = dict.get('StmF') || identityName;
  24830. this.strf = dict.get('StrF') || identityName;
  24831. this.eff = dict.get('EFF') || this.stmf;
  24832. }
  24833. }
  24834. function buildObjectKey(num, gen, encryptionKey, isAes) {
  24835. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  24836. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  24837. key[i] = encryptionKey[i];
  24838. }
  24839. key[i++] = num & 0xFF;
  24840. key[i++] = (num >> 8) & 0xFF;
  24841. key[i++] = (num >> 16) & 0xFF;
  24842. key[i++] = gen & 0xFF;
  24843. key[i++] = (gen >> 8) & 0xFF;
  24844. if (isAes) {
  24845. key[i++] = 0x73;
  24846. key[i++] = 0x41;
  24847. key[i++] = 0x6C;
  24848. key[i++] = 0x54;
  24849. }
  24850. var hash = calculateMD5(key, 0, i);
  24851. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  24852. }
  24853. function buildCipherConstructor(cf, name, num, gen, key) {
  24854. var cryptFilter = cf.get(name.name);
  24855. var cfm;
  24856. if (cryptFilter !== null && cryptFilter !== undefined) {
  24857. cfm = cryptFilter.get('CFM');
  24858. }
  24859. if (!cfm || cfm.name === 'None') {
  24860. return function cipherTransformFactoryBuildCipherConstructorNone() {
  24861. return new NullCipher();
  24862. };
  24863. }
  24864. if ('V2' === cfm.name) {
  24865. return function cipherTransformFactoryBuildCipherConstructorV2() {
  24866. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  24867. };
  24868. }
  24869. if ('AESV2' === cfm.name) {
  24870. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  24871. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  24872. };
  24873. }
  24874. if ('AESV3' === cfm.name) {
  24875. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  24876. return new AES256Cipher(key);
  24877. };
  24878. }
  24879. error('Unknown crypto method');
  24880. }
  24881. CipherTransformFactory.prototype = {
  24882. createCipherTransform:
  24883. function CipherTransformFactory_createCipherTransform(num, gen) {
  24884. if (this.algorithm === 4 || this.algorithm === 5) {
  24885. return new CipherTransform(
  24886. buildCipherConstructor(this.cf, this.stmf,
  24887. num, gen, this.encryptionKey),
  24888. buildCipherConstructor(this.cf, this.strf,
  24889. num, gen, this.encryptionKey));
  24890. }
  24891. // algorithms 1 and 2
  24892. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  24893. var cipherConstructor = function buildCipherCipherConstructor() {
  24894. return new ARCFourCipher(key);
  24895. };
  24896. return new CipherTransform(cipherConstructor, cipherConstructor);
  24897. }
  24898. };
  24899. return CipherTransformFactory;
  24900. })();
  24901. exports.AES128Cipher = AES128Cipher;
  24902. exports.AES256Cipher = AES256Cipher;
  24903. exports.ARCFourCipher = ARCFourCipher;
  24904. exports.CipherTransformFactory = CipherTransformFactory;
  24905. exports.PDF17 = PDF17;
  24906. exports.PDF20 = PDF20;
  24907. exports.calculateMD5 = calculateMD5;
  24908. exports.calculateSHA256 = calculateSHA256;
  24909. exports.calculateSHA384 = calculateSHA384;
  24910. exports.calculateSHA512 = calculateSHA512;
  24911. }));
  24912. (function (root, factory) {
  24913. {
  24914. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  24915. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings);
  24916. }
  24917. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  24918. coreEncodings) {
  24919. var Util = sharedUtil.Util;
  24920. var bytesToString = sharedUtil.bytesToString;
  24921. var error = sharedUtil.error;
  24922. var Stream = coreStream.Stream;
  24923. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  24924. var StandardEncoding = coreEncodings.StandardEncoding;
  24925. var coreFonts; // see _setCoreFonts below
  24926. var CFFParser; // = coreFonts.CFFParser;
  24927. var FontRendererFactory = (function FontRendererFactoryClosure() {
  24928. function getLong(data, offset) {
  24929. return (data[offset] << 24) | (data[offset + 1] << 16) |
  24930. (data[offset + 2] << 8) | data[offset + 3];
  24931. }
  24932. function getUshort(data, offset) {
  24933. return (data[offset] << 8) | data[offset + 1];
  24934. }
  24935. function parseCmap(data, start, end) {
  24936. var offset = (getUshort(data, start + 2) === 1 ?
  24937. getLong(data, start + 8) : getLong(data, start + 16));
  24938. var format = getUshort(data, start + offset);
  24939. var length, ranges, p, i;
  24940. if (format === 4) {
  24941. length = getUshort(data, start + offset + 2);
  24942. var segCount = getUshort(data, start + offset + 6) >> 1;
  24943. p = start + offset + 14;
  24944. ranges = [];
  24945. for (i = 0; i < segCount; i++, p += 2) {
  24946. ranges[i] = {end: getUshort(data, p)};
  24947. }
  24948. p += 2;
  24949. for (i = 0; i < segCount; i++, p += 2) {
  24950. ranges[i].start = getUshort(data, p);
  24951. }
  24952. for (i = 0; i < segCount; i++, p += 2) {
  24953. ranges[i].idDelta = getUshort(data, p);
  24954. }
  24955. for (i = 0; i < segCount; i++, p += 2) {
  24956. var idOffset = getUshort(data, p);
  24957. if (idOffset === 0) {
  24958. continue;
  24959. }
  24960. ranges[i].ids = [];
  24961. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  24962. ranges[i].ids[j] = getUshort(data, p + idOffset);
  24963. idOffset += 2;
  24964. }
  24965. }
  24966. return ranges;
  24967. } else if (format === 12) {
  24968. length = getLong(data, start + offset + 4);
  24969. var groups = getLong(data, start + offset + 12);
  24970. p = start + offset + 16;
  24971. ranges = [];
  24972. for (i = 0; i < groups; i++) {
  24973. ranges.push({
  24974. start: getLong(data, p),
  24975. end: getLong(data, p + 4),
  24976. idDelta: getLong(data, p + 8) - getLong(data, p)
  24977. });
  24978. p += 12;
  24979. }
  24980. return ranges;
  24981. }
  24982. error('not supported cmap: ' + format);
  24983. }
  24984. function parseCff(data, start, end) {
  24985. var properties = {};
  24986. var parser = new CFFParser(new Stream(data, start, end - start),
  24987. properties);
  24988. var cff = parser.parse();
  24989. return {
  24990. glyphs: cff.charStrings.objects,
  24991. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  24992. cff.topDict.privateDict.subrsIndex.objects),
  24993. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  24994. };
  24995. }
  24996. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  24997. var itemSize, itemDecode;
  24998. if (isGlyphLocationsLong) {
  24999. itemSize = 4;
  25000. itemDecode = function fontItemDecodeLong(data, offset) {
  25001. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25002. (data[offset + 2] << 8) | data[offset + 3];
  25003. };
  25004. } else {
  25005. itemSize = 2;
  25006. itemDecode = function fontItemDecode(data, offset) {
  25007. return (data[offset] << 9) | (data[offset + 1] << 1);
  25008. };
  25009. }
  25010. var glyphs = [];
  25011. var startOffset = itemDecode(loca, 0);
  25012. for (var j = itemSize; j < loca.length; j += itemSize) {
  25013. var endOffset = itemDecode(loca, j);
  25014. glyphs.push(glyf.subarray(startOffset, endOffset));
  25015. startOffset = endOffset;
  25016. }
  25017. return glyphs;
  25018. }
  25019. function lookupCmap(ranges, unicode) {
  25020. var code = unicode.charCodeAt(0);
  25021. var l = 0, r = ranges.length - 1;
  25022. while (l < r) {
  25023. var c = (l + r + 1) >> 1;
  25024. if (code < ranges[c].start) {
  25025. r = c - 1;
  25026. } else {
  25027. l = c;
  25028. }
  25029. }
  25030. if (ranges[l].start <= code && code <= ranges[l].end) {
  25031. return (ranges[l].idDelta + (ranges[l].ids ?
  25032. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25033. }
  25034. return 0;
  25035. }
  25036. function compileGlyf(code, cmds, font) {
  25037. function moveTo(x, y) {
  25038. cmds.push({cmd: 'moveTo', args: [x, y]});
  25039. }
  25040. function lineTo(x, y) {
  25041. cmds.push({cmd: 'lineTo', args: [x, y]});
  25042. }
  25043. function quadraticCurveTo(xa, ya, x, y) {
  25044. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25045. }
  25046. var i = 0;
  25047. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25048. var flags;
  25049. var x = 0, y = 0;
  25050. i += 10;
  25051. if (numberOfContours < 0) {
  25052. // composite glyph
  25053. do {
  25054. flags = (code[i] << 8) | code[i + 1];
  25055. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25056. i += 4;
  25057. var arg1, arg2;
  25058. if ((flags & 0x01)) {
  25059. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25060. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25061. i += 4;
  25062. } else {
  25063. arg1 = code[i++]; arg2 = code[i++];
  25064. }
  25065. if ((flags & 0x02)) {
  25066. x = arg1;
  25067. y = arg2;
  25068. } else {
  25069. x = 0; y = 0; // TODO "they are points" ?
  25070. }
  25071. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25072. if ((flags & 0x08)) {
  25073. scaleX =
  25074. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25075. i += 2;
  25076. } else if ((flags & 0x40)) {
  25077. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25078. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25079. i += 4;
  25080. } else if ((flags & 0x80)) {
  25081. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25082. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25083. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25084. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25085. i += 8;
  25086. }
  25087. var subglyph = font.glyphs[glyphIndex];
  25088. if (subglyph) {
  25089. cmds.push({cmd: 'save'});
  25090. cmds.push({cmd: 'transform',
  25091. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25092. compileGlyf(subglyph, cmds, font);
  25093. cmds.push({cmd: 'restore'});
  25094. }
  25095. } while ((flags & 0x20));
  25096. } else {
  25097. // simple glyph
  25098. var endPtsOfContours = [];
  25099. var j, jj;
  25100. for (j = 0; j < numberOfContours; j++) {
  25101. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25102. i += 2;
  25103. }
  25104. var instructionLength = (code[i] << 8) | code[i + 1];
  25105. i += 2 + instructionLength; // skipping the instructions
  25106. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25107. var points = [];
  25108. while (points.length < numberOfPoints) {
  25109. flags = code[i++];
  25110. var repeat = 1;
  25111. if ((flags & 0x08)) {
  25112. repeat += code[i++];
  25113. }
  25114. while (repeat-- > 0) {
  25115. points.push({flags: flags});
  25116. }
  25117. }
  25118. for (j = 0; j < numberOfPoints; j++) {
  25119. switch (points[j].flags & 0x12) {
  25120. case 0x00:
  25121. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25122. i += 2;
  25123. break;
  25124. case 0x02:
  25125. x -= code[i++];
  25126. break;
  25127. case 0x12:
  25128. x += code[i++];
  25129. break;
  25130. }
  25131. points[j].x = x;
  25132. }
  25133. for (j = 0; j < numberOfPoints; j++) {
  25134. switch (points[j].flags & 0x24) {
  25135. case 0x00:
  25136. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25137. i += 2;
  25138. break;
  25139. case 0x04:
  25140. y -= code[i++];
  25141. break;
  25142. case 0x24:
  25143. y += code[i++];
  25144. break;
  25145. }
  25146. points[j].y = y;
  25147. }
  25148. var startPoint = 0;
  25149. for (i = 0; i < numberOfContours; i++) {
  25150. var endPoint = endPtsOfContours[i];
  25151. // contours might have implicit points, which is located in the middle
  25152. // between two neighboring off-curve points
  25153. var contour = points.slice(startPoint, endPoint + 1);
  25154. if ((contour[0].flags & 1)) {
  25155. contour.push(contour[0]); // using start point at the contour end
  25156. } else if ((contour[contour.length - 1].flags & 1)) {
  25157. // first is off-curve point, trying to use one from the end
  25158. contour.unshift(contour[contour.length - 1]);
  25159. } else {
  25160. // start and end are off-curve points, creating implicit one
  25161. var p = {
  25162. flags: 1,
  25163. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25164. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25165. };
  25166. contour.unshift(p);
  25167. contour.push(p);
  25168. }
  25169. moveTo(contour[0].x, contour[0].y);
  25170. for (j = 1, jj = contour.length; j < jj; j++) {
  25171. if ((contour[j].flags & 1)) {
  25172. lineTo(contour[j].x, contour[j].y);
  25173. } else if ((contour[j + 1].flags & 1)){
  25174. quadraticCurveTo(contour[j].x, contour[j].y,
  25175. contour[j + 1].x, contour[j + 1].y);
  25176. j++;
  25177. } else {
  25178. quadraticCurveTo(contour[j].x, contour[j].y,
  25179. (contour[j].x + contour[j + 1].x) / 2,
  25180. (contour[j].y + contour[j + 1].y) / 2);
  25181. }
  25182. }
  25183. startPoint = endPoint + 1;
  25184. }
  25185. }
  25186. }
  25187. function compileCharString(code, cmds, font) {
  25188. var stack = [];
  25189. var x = 0, y = 0;
  25190. var stems = 0;
  25191. function moveTo(x, y) {
  25192. cmds.push({cmd: 'moveTo', args: [x, y]});
  25193. }
  25194. function lineTo(x, y) {
  25195. cmds.push({cmd: 'lineTo', args: [x, y]});
  25196. }
  25197. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25198. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  25199. }
  25200. function parse(code) {
  25201. var i = 0;
  25202. while (i < code.length) {
  25203. var stackClean = false;
  25204. var v = code[i++];
  25205. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25206. switch (v) {
  25207. case 1: // hstem
  25208. stems += stack.length >> 1;
  25209. stackClean = true;
  25210. break;
  25211. case 3: // vstem
  25212. stems += stack.length >> 1;
  25213. stackClean = true;
  25214. break;
  25215. case 4: // vmoveto
  25216. y += stack.pop();
  25217. moveTo(x, y);
  25218. stackClean = true;
  25219. break;
  25220. case 5: // rlineto
  25221. while (stack.length > 0) {
  25222. x += stack.shift();
  25223. y += stack.shift();
  25224. lineTo(x, y);
  25225. }
  25226. break;
  25227. case 6: // hlineto
  25228. while (stack.length > 0) {
  25229. x += stack.shift();
  25230. lineTo(x, y);
  25231. if (stack.length === 0) {
  25232. break;
  25233. }
  25234. y += stack.shift();
  25235. lineTo(x, y);
  25236. }
  25237. break;
  25238. case 7: // vlineto
  25239. while (stack.length > 0) {
  25240. y += stack.shift();
  25241. lineTo(x, y);
  25242. if (stack.length === 0) {
  25243. break;
  25244. }
  25245. x += stack.shift();
  25246. lineTo(x, y);
  25247. }
  25248. break;
  25249. case 8: // rrcurveto
  25250. while (stack.length > 0) {
  25251. xa = x + stack.shift(); ya = y + stack.shift();
  25252. xb = xa + stack.shift(); yb = ya + stack.shift();
  25253. x = xb + stack.shift(); y = yb + stack.shift();
  25254. bezierCurveTo(xa, ya, xb, yb, x, y);
  25255. }
  25256. break;
  25257. case 10: // callsubr
  25258. n = stack.pop() + font.subrsBias;
  25259. subrCode = font.subrs[n];
  25260. if (subrCode) {
  25261. parse(subrCode);
  25262. }
  25263. break;
  25264. case 11: // return
  25265. return;
  25266. case 12:
  25267. v = code[i++];
  25268. switch (v) {
  25269. case 34: // flex
  25270. xa = x + stack.shift();
  25271. xb = xa + stack.shift(); y1 = y + stack.shift();
  25272. x = xb + stack.shift();
  25273. bezierCurveTo(xa, y, xb, y1, x, y1);
  25274. xa = x + stack.shift();
  25275. xb = xa + stack.shift();
  25276. x = xb + stack.shift();
  25277. bezierCurveTo(xa, y1, xb, y, x, y);
  25278. break;
  25279. case 35: // flex
  25280. xa = x + stack.shift(); ya = y + stack.shift();
  25281. xb = xa + stack.shift(); yb = ya + stack.shift();
  25282. x = xb + stack.shift(); y = yb + stack.shift();
  25283. bezierCurveTo(xa, ya, xb, yb, x, y);
  25284. xa = x + stack.shift(); ya = y + stack.shift();
  25285. xb = xa + stack.shift(); yb = ya + stack.shift();
  25286. x = xb + stack.shift(); y = yb + stack.shift();
  25287. bezierCurveTo(xa, ya, xb, yb, x, y);
  25288. stack.pop(); // fd
  25289. break;
  25290. case 36: // hflex1
  25291. xa = x + stack.shift(); y1 = y + stack.shift();
  25292. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25293. x = xb + stack.shift();
  25294. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25295. xa = x + stack.shift();
  25296. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25297. x = xb + stack.shift();
  25298. bezierCurveTo(xa, y2, xb, y3, x, y);
  25299. break;
  25300. case 37: // flex1
  25301. var x0 = x, y0 = y;
  25302. xa = x + stack.shift(); ya = y + stack.shift();
  25303. xb = xa + stack.shift(); yb = ya + stack.shift();
  25304. x = xb + stack.shift(); y = yb + stack.shift();
  25305. bezierCurveTo(xa, ya, xb, yb, x, y);
  25306. xa = x + stack.shift(); ya = y + stack.shift();
  25307. xb = xa + stack.shift(); yb = ya + stack.shift();
  25308. x = xb; y = yb;
  25309. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25310. x += stack.shift();
  25311. } else {
  25312. y += stack.shift();
  25313. }
  25314. bezierCurveTo(xa, ya, xb, yb, x, y);
  25315. break;
  25316. default:
  25317. error('unknown operator: 12 ' + v);
  25318. }
  25319. break;
  25320. case 14: // endchar
  25321. if (stack.length >= 4) {
  25322. var achar = stack.pop();
  25323. var bchar = stack.pop();
  25324. y = stack.pop();
  25325. x = stack.pop();
  25326. cmds.push({cmd: 'save'});
  25327. cmds.push({cmd: 'translate', args: [x, y]});
  25328. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25329. font.glyphNameMap[StandardEncoding[achar]]));
  25330. compileCharString(font.glyphs[gid], cmds, font);
  25331. cmds.push({cmd: 'restore'});
  25332. gid = lookupCmap(font.cmap, String.fromCharCode(
  25333. font.glyphNameMap[StandardEncoding[bchar]]));
  25334. compileCharString(font.glyphs[gid], cmds, font);
  25335. }
  25336. return;
  25337. case 18: // hstemhm
  25338. stems += stack.length >> 1;
  25339. stackClean = true;
  25340. break;
  25341. case 19: // hintmask
  25342. stems += stack.length >> 1;
  25343. i += (stems + 7) >> 3;
  25344. stackClean = true;
  25345. break;
  25346. case 20: // cntrmask
  25347. stems += stack.length >> 1;
  25348. i += (stems + 7) >> 3;
  25349. stackClean = true;
  25350. break;
  25351. case 21: // rmoveto
  25352. y += stack.pop();
  25353. x += stack.pop();
  25354. moveTo(x, y);
  25355. stackClean = true;
  25356. break;
  25357. case 22: // hmoveto
  25358. x += stack.pop();
  25359. moveTo(x, y);
  25360. stackClean = true;
  25361. break;
  25362. case 23: // vstemhm
  25363. stems += stack.length >> 1;
  25364. stackClean = true;
  25365. break;
  25366. case 24: // rcurveline
  25367. while (stack.length > 2) {
  25368. xa = x + stack.shift(); ya = y + stack.shift();
  25369. xb = xa + stack.shift(); yb = ya + stack.shift();
  25370. x = xb + stack.shift(); y = yb + stack.shift();
  25371. bezierCurveTo(xa, ya, xb, yb, x, y);
  25372. }
  25373. x += stack.shift();
  25374. y += stack.shift();
  25375. lineTo(x, y);
  25376. break;
  25377. case 25: // rlinecurve
  25378. while (stack.length > 6) {
  25379. x += stack.shift();
  25380. y += stack.shift();
  25381. lineTo(x, y);
  25382. }
  25383. xa = x + stack.shift(); ya = y + stack.shift();
  25384. xb = xa + stack.shift(); yb = ya + stack.shift();
  25385. x = xb + stack.shift(); y = yb + stack.shift();
  25386. bezierCurveTo(xa, ya, xb, yb, x, y);
  25387. break;
  25388. case 26: // vvcurveto
  25389. if (stack.length % 2) {
  25390. x += stack.shift();
  25391. }
  25392. while (stack.length > 0) {
  25393. xa = x; ya = y + stack.shift();
  25394. xb = xa + stack.shift(); yb = ya + stack.shift();
  25395. x = xb; y = yb + stack.shift();
  25396. bezierCurveTo(xa, ya, xb, yb, x, y);
  25397. }
  25398. break;
  25399. case 27: // hhcurveto
  25400. if (stack.length % 2) {
  25401. y += stack.shift();
  25402. }
  25403. while (stack.length > 0) {
  25404. xa = x + stack.shift(); ya = y;
  25405. xb = xa + stack.shift(); yb = ya + stack.shift();
  25406. x = xb + stack.shift(); y = yb;
  25407. bezierCurveTo(xa, ya, xb, yb, x, y);
  25408. }
  25409. break;
  25410. case 28:
  25411. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25412. i += 2;
  25413. break;
  25414. case 29: // callgsubr
  25415. n = stack.pop() + font.gsubrsBias;
  25416. subrCode = font.gsubrs[n];
  25417. if (subrCode) {
  25418. parse(subrCode);
  25419. }
  25420. break;
  25421. case 30: // vhcurveto
  25422. while (stack.length > 0) {
  25423. xa = x; ya = y + stack.shift();
  25424. xb = xa + stack.shift(); yb = ya + stack.shift();
  25425. x = xb + stack.shift();
  25426. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25427. bezierCurveTo(xa, ya, xb, yb, x, y);
  25428. if (stack.length === 0) {
  25429. break;
  25430. }
  25431. xa = x + stack.shift(); ya = y;
  25432. xb = xa + stack.shift(); yb = ya + stack.shift();
  25433. y = yb + stack.shift();
  25434. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25435. bezierCurveTo(xa, ya, xb, yb, x, y);
  25436. }
  25437. break;
  25438. case 31: // hvcurveto
  25439. while (stack.length > 0) {
  25440. xa = x + stack.shift(); ya = y;
  25441. xb = xa + stack.shift(); yb = ya + stack.shift();
  25442. y = yb + stack.shift();
  25443. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25444. bezierCurveTo(xa, ya, xb, yb, x, y);
  25445. if (stack.length === 0) {
  25446. break;
  25447. }
  25448. xa = x; ya = y + stack.shift();
  25449. xb = xa + stack.shift(); yb = ya + stack.shift();
  25450. x = xb + stack.shift();
  25451. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25452. bezierCurveTo(xa, ya, xb, yb, x, y);
  25453. }
  25454. break;
  25455. default:
  25456. if (v < 32) {
  25457. error('unknown operator: ' + v);
  25458. }
  25459. if (v < 247) {
  25460. stack.push(v - 139);
  25461. } else if (v < 251) {
  25462. stack.push((v - 247) * 256 + code[i++] + 108);
  25463. } else if (v < 255) {
  25464. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25465. } else {
  25466. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25467. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25468. i += 4;
  25469. }
  25470. break;
  25471. }
  25472. if (stackClean) {
  25473. stack.length = 0;
  25474. }
  25475. }
  25476. }
  25477. parse(code);
  25478. }
  25479. var noop = '';
  25480. function CompiledFont(fontMatrix) {
  25481. this.compiledGlyphs = Object.create(null);
  25482. this.fontMatrix = fontMatrix;
  25483. }
  25484. CompiledFont.prototype = {
  25485. getPathJs: function (unicode) {
  25486. var gid = lookupCmap(this.cmap, unicode);
  25487. var fn = this.compiledGlyphs[gid];
  25488. if (!fn) {
  25489. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25490. }
  25491. return fn;
  25492. },
  25493. compileGlyph: function (code) {
  25494. if (!code || code.length === 0 || code[0] === 14) {
  25495. return noop;
  25496. }
  25497. var cmds = [];
  25498. cmds.push({cmd: 'save'});
  25499. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  25500. cmds.push({cmd: 'scale', args: ['size', '-size']});
  25501. this.compileGlyphImpl(code, cmds);
  25502. cmds.push({cmd: 'restore'});
  25503. return cmds;
  25504. },
  25505. compileGlyphImpl: function () {
  25506. error('Children classes should implement this.');
  25507. },
  25508. hasBuiltPath: function (unicode) {
  25509. var gid = lookupCmap(this.cmap, unicode);
  25510. return gid in this.compiledGlyphs;
  25511. }
  25512. };
  25513. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25514. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25515. CompiledFont.call(this, fontMatrix);
  25516. this.glyphs = glyphs;
  25517. this.cmap = cmap;
  25518. this.compiledGlyphs = [];
  25519. }
  25520. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25521. compileGlyphImpl: function (code, cmds) {
  25522. compileGlyf(code, cmds, this);
  25523. }
  25524. });
  25525. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25526. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25527. CompiledFont.call(this, fontMatrix);
  25528. this.glyphs = cffInfo.glyphs;
  25529. this.gsubrs = cffInfo.gsubrs || [];
  25530. this.subrs = cffInfo.subrs || [];
  25531. this.cmap = cmap;
  25532. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  25533. this.compiledGlyphs = [];
  25534. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25535. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25536. this.subrsBias = (this.subrs.length < 1240 ?
  25537. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25538. }
  25539. Util.inherit(Type2Compiled, CompiledFont, {
  25540. compileGlyphImpl: function (code, cmds) {
  25541. compileCharString(code, cmds, this);
  25542. }
  25543. });
  25544. return {
  25545. create: function FontRendererFactory_create(font) {
  25546. var data = new Uint8Array(font.data);
  25547. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25548. var numTables = getUshort(data, 4);
  25549. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25550. var tag = bytesToString(data.subarray(p, p + 4));
  25551. var offset = getLong(data, p + 8);
  25552. var length = getLong(data, p + 12);
  25553. switch (tag) {
  25554. case 'cmap':
  25555. cmap = parseCmap(data, offset, offset + length);
  25556. break;
  25557. case 'glyf':
  25558. glyf = data.subarray(offset, offset + length);
  25559. break;
  25560. case 'loca':
  25561. loca = data.subarray(offset, offset + length);
  25562. break;
  25563. case 'head':
  25564. unitsPerEm = getUshort(data, offset + 18);
  25565. indexToLocFormat = getUshort(data, offset + 50);
  25566. break;
  25567. case 'CFF ':
  25568. cff = parseCff(data, offset, offset + length);
  25569. break;
  25570. }
  25571. }
  25572. if (glyf) {
  25573. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25574. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25575. return new TrueTypeCompiled(
  25576. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25577. } else {
  25578. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25579. }
  25580. }
  25581. };
  25582. })();
  25583. // TODO refactor to remove cyclic dependency on fonts.js
  25584. function _setCoreFonts(coreFonts_) {
  25585. coreFonts = coreFonts_;
  25586. CFFParser = coreFonts_.CFFParser;
  25587. }
  25588. exports._setCoreFonts = _setCoreFonts;
  25589. exports.FontRendererFactory = FontRendererFactory;
  25590. }));
  25591. (function (root, factory) {
  25592. {
  25593. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  25594. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  25595. }
  25596. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  25597. var MissingDataException = sharedUtil.MissingDataException;
  25598. var StreamType = sharedUtil.StreamType;
  25599. var assert = sharedUtil.assert;
  25600. var error = sharedUtil.error;
  25601. var info = sharedUtil.info;
  25602. var isArray = sharedUtil.isArray;
  25603. var isInt = sharedUtil.isInt;
  25604. var isNum = sharedUtil.isNum;
  25605. var isString = sharedUtil.isString;
  25606. var warn = sharedUtil.warn;
  25607. var Cmd = corePrimitives.Cmd;
  25608. var Dict = corePrimitives.Dict;
  25609. var Name = corePrimitives.Name;
  25610. var Ref = corePrimitives.Ref;
  25611. var isCmd = corePrimitives.isCmd;
  25612. var isDict = corePrimitives.isDict;
  25613. var isName = corePrimitives.isName;
  25614. var Ascii85Stream = coreStream.Ascii85Stream;
  25615. var AsciiHexStream = coreStream.AsciiHexStream;
  25616. var CCITTFaxStream = coreStream.CCITTFaxStream;
  25617. var FlateStream = coreStream.FlateStream;
  25618. var Jbig2Stream = coreStream.Jbig2Stream;
  25619. var JpegStream = coreStream.JpegStream;
  25620. var JpxStream = coreStream.JpxStream;
  25621. var LZWStream = coreStream.LZWStream;
  25622. var NullStream = coreStream.NullStream;
  25623. var PredictorStream = coreStream.PredictorStream;
  25624. var RunLengthStream = coreStream.RunLengthStream;
  25625. var EOF = {};
  25626. function isEOF(v) {
  25627. return (v === EOF);
  25628. }
  25629. var MAX_LENGTH_TO_CACHE = 1000;
  25630. var Parser = (function ParserClosure() {
  25631. function Parser(lexer, allowStreams, xref) {
  25632. this.lexer = lexer;
  25633. this.allowStreams = allowStreams;
  25634. this.xref = xref;
  25635. this.imageCache = Object.create(null);
  25636. this.refill();
  25637. }
  25638. Parser.prototype = {
  25639. refill: function Parser_refill() {
  25640. this.buf1 = this.lexer.getObj();
  25641. this.buf2 = this.lexer.getObj();
  25642. },
  25643. shift: function Parser_shift() {
  25644. if (isCmd(this.buf2, 'ID')) {
  25645. this.buf1 = this.buf2;
  25646. this.buf2 = null;
  25647. } else {
  25648. this.buf1 = this.buf2;
  25649. this.buf2 = this.lexer.getObj();
  25650. }
  25651. },
  25652. tryShift: function Parser_tryShift() {
  25653. try {
  25654. this.shift();
  25655. return true;
  25656. } catch (e) {
  25657. if (e instanceof MissingDataException) {
  25658. throw e;
  25659. }
  25660. // Upon failure, the caller should reset this.lexer.pos to a known good
  25661. // state and call this.shift() twice to reset the buffers.
  25662. return false;
  25663. }
  25664. },
  25665. getObj: function Parser_getObj(cipherTransform) {
  25666. var buf1 = this.buf1;
  25667. this.shift();
  25668. if (buf1 instanceof Cmd) {
  25669. switch (buf1.cmd) {
  25670. case 'BI': // inline image
  25671. return this.makeInlineImage(cipherTransform);
  25672. case '[': // array
  25673. var array = [];
  25674. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  25675. array.push(this.getObj(cipherTransform));
  25676. }
  25677. if (isEOF(this.buf1)) {
  25678. error('End of file inside array');
  25679. }
  25680. this.shift();
  25681. return array;
  25682. case '<<': // dictionary or stream
  25683. var dict = new Dict(this.xref);
  25684. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  25685. if (!isName(this.buf1)) {
  25686. info('Malformed dictionary: key must be a name object');
  25687. this.shift();
  25688. continue;
  25689. }
  25690. var key = this.buf1.name;
  25691. this.shift();
  25692. if (isEOF(this.buf1)) {
  25693. break;
  25694. }
  25695. dict.set(key, this.getObj(cipherTransform));
  25696. }
  25697. if (isEOF(this.buf1)) {
  25698. error('End of file inside dictionary');
  25699. }
  25700. // Stream objects are not allowed inside content streams or
  25701. // object streams.
  25702. if (isCmd(this.buf2, 'stream')) {
  25703. return (this.allowStreams ?
  25704. this.makeStream(dict, cipherTransform) : dict);
  25705. }
  25706. this.shift();
  25707. return dict;
  25708. default: // simple object
  25709. return buf1;
  25710. }
  25711. }
  25712. if (isInt(buf1)) { // indirect reference or integer
  25713. var num = buf1;
  25714. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  25715. var ref = new Ref(num, this.buf1);
  25716. this.shift();
  25717. this.shift();
  25718. return ref;
  25719. }
  25720. return num;
  25721. }
  25722. if (isString(buf1)) { // string
  25723. var str = buf1;
  25724. if (cipherTransform) {
  25725. str = cipherTransform.decryptString(str);
  25726. }
  25727. return str;
  25728. }
  25729. // simple object
  25730. return buf1;
  25731. },
  25732. /**
  25733. * Find the end of the stream by searching for the /EI\s/.
  25734. * @returns {number} The inline stream length.
  25735. */
  25736. findDefaultInlineStreamEnd:
  25737. function Parser_findDefaultInlineStreamEnd(stream) {
  25738. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  25739. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  25740. while ((ch = stream.getByte()) !== -1) {
  25741. if (state === 0) {
  25742. state = (ch === E) ? 1 : 0;
  25743. } else if (state === 1) {
  25744. state = (ch === I) ? 2 : 0;
  25745. } else {
  25746. assert(state === 2);
  25747. if (ch === SPACE || ch === LF || ch === CR) {
  25748. // Let's check the next five bytes are ASCII... just be sure.
  25749. n = 5;
  25750. followingBytes = stream.peekBytes(n);
  25751. for (i = 0; i < n; i++) {
  25752. ch = followingBytes[i];
  25753. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  25754. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  25755. // it's binary stuff. Resetting the state.
  25756. state = 0;
  25757. break;
  25758. }
  25759. }
  25760. if (state === 2) {
  25761. break; // Finished!
  25762. }
  25763. } else {
  25764. state = 0;
  25765. }
  25766. }
  25767. }
  25768. return ((stream.pos - 4) - startPos);
  25769. },
  25770. /**
  25771. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  25772. * @returns {number} The inline stream length.
  25773. */
  25774. findDCTDecodeInlineStreamEnd:
  25775. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  25776. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  25777. while ((b = stream.getByte()) !== -1) {
  25778. if (b !== 0xFF) { // Not a valid marker.
  25779. continue;
  25780. }
  25781. switch (stream.getByte()) {
  25782. case 0x00: // Byte stuffing.
  25783. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  25784. break;
  25785. case 0xFF: // Fill byte.
  25786. // Avoid skipping a valid marker, resetting the stream position.
  25787. stream.skip(-1);
  25788. break;
  25789. case 0xD9: // EOI
  25790. foundEOI = true;
  25791. break;
  25792. case 0xC0: // SOF0
  25793. case 0xC1: // SOF1
  25794. case 0xC2: // SOF2
  25795. case 0xC3: // SOF3
  25796. case 0xC5: // SOF5
  25797. case 0xC6: // SOF6
  25798. case 0xC7: // SOF7
  25799. case 0xC9: // SOF9
  25800. case 0xCA: // SOF10
  25801. case 0xCB: // SOF11
  25802. case 0xCD: // SOF13
  25803. case 0xCE: // SOF14
  25804. case 0xCF: // SOF15
  25805. case 0xC4: // DHT
  25806. case 0xCC: // DAC
  25807. case 0xDA: // SOS
  25808. case 0xDB: // DQT
  25809. case 0xDC: // DNL
  25810. case 0xDD: // DRI
  25811. case 0xDE: // DHP
  25812. case 0xDF: // EXP
  25813. case 0xE0: // APP0
  25814. case 0xE1: // APP1
  25815. case 0xE2: // APP2
  25816. case 0xE3: // APP3
  25817. case 0xE4: // APP4
  25818. case 0xE5: // APP5
  25819. case 0xE6: // APP6
  25820. case 0xE7: // APP7
  25821. case 0xE8: // APP8
  25822. case 0xE9: // APP9
  25823. case 0xEA: // APP10
  25824. case 0xEB: // APP11
  25825. case 0xEC: // APP12
  25826. case 0xED: // APP13
  25827. case 0xEE: // APP14
  25828. case 0xEF: // APP15
  25829. case 0xFE: // COM
  25830. // The marker should be followed by the length of the segment.
  25831. markerLength = stream.getUint16();
  25832. if (markerLength > 2) {
  25833. // |markerLength| contains the byte length of the marker segment,
  25834. // including its own length (2 bytes) and excluding the marker.
  25835. stream.skip(markerLength - 2); // Jump to the next marker.
  25836. } else {
  25837. // The marker length is invalid, resetting the stream position.
  25838. stream.skip(-2);
  25839. }
  25840. break;
  25841. }
  25842. if (foundEOI) {
  25843. break;
  25844. }
  25845. }
  25846. length = stream.pos - startPos;
  25847. if (b === -1) {
  25848. warn('Inline DCTDecode image stream: ' +
  25849. 'EOI marker not found, searching for /EI/ instead.');
  25850. stream.skip(-length); // Reset the stream position.
  25851. return this.findDefaultInlineStreamEnd(stream);
  25852. }
  25853. this.inlineStreamSkipEI(stream);
  25854. return length;
  25855. },
  25856. /**
  25857. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  25858. * @returns {number} The inline stream length.
  25859. */
  25860. findASCII85DecodeInlineStreamEnd:
  25861. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  25862. var TILDE = 0x7E, GT = 0x3E;
  25863. var startPos = stream.pos, ch, length;
  25864. while ((ch = stream.getByte()) !== -1) {
  25865. if (ch === TILDE && stream.peekByte() === GT) {
  25866. stream.skip();
  25867. break;
  25868. }
  25869. }
  25870. length = stream.pos - startPos;
  25871. if (ch === -1) {
  25872. warn('Inline ASCII85Decode image stream: ' +
  25873. 'EOD marker not found, searching for /EI/ instead.');
  25874. stream.skip(-length); // Reset the stream position.
  25875. return this.findDefaultInlineStreamEnd(stream);
  25876. }
  25877. this.inlineStreamSkipEI(stream);
  25878. return length;
  25879. },
  25880. /**
  25881. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  25882. * @returns {number} The inline stream length.
  25883. */
  25884. findASCIIHexDecodeInlineStreamEnd:
  25885. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  25886. var GT = 0x3E;
  25887. var startPos = stream.pos, ch, length;
  25888. while ((ch = stream.getByte()) !== -1) {
  25889. if (ch === GT) {
  25890. break;
  25891. }
  25892. }
  25893. length = stream.pos - startPos;
  25894. if (ch === -1) {
  25895. warn('Inline ASCIIHexDecode image stream: ' +
  25896. 'EOD marker not found, searching for /EI/ instead.');
  25897. stream.skip(-length); // Reset the stream position.
  25898. return this.findDefaultInlineStreamEnd(stream);
  25899. }
  25900. this.inlineStreamSkipEI(stream);
  25901. return length;
  25902. },
  25903. /**
  25904. * Skip over the /EI/ for streams where we search for an EOD marker.
  25905. */
  25906. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  25907. var E = 0x45, I = 0x49;
  25908. var state = 0, ch;
  25909. while ((ch = stream.getByte()) !== -1) {
  25910. if (state === 0) {
  25911. state = (ch === E) ? 1 : 0;
  25912. } else if (state === 1) {
  25913. state = (ch === I) ? 2 : 0;
  25914. } else if (state === 2) {
  25915. break;
  25916. }
  25917. }
  25918. },
  25919. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  25920. var lexer = this.lexer;
  25921. var stream = lexer.stream;
  25922. // Parse dictionary.
  25923. var dict = new Dict(this.xref);
  25924. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  25925. if (!isName(this.buf1)) {
  25926. error('Dictionary key must be a name object');
  25927. }
  25928. var key = this.buf1.name;
  25929. this.shift();
  25930. if (isEOF(this.buf1)) {
  25931. break;
  25932. }
  25933. dict.set(key, this.getObj(cipherTransform));
  25934. }
  25935. // Extract the name of the first (i.e. the current) image filter.
  25936. var filter = dict.get('Filter', 'F'), filterName;
  25937. if (isName(filter)) {
  25938. filterName = filter.name;
  25939. } else if (isArray(filter) && isName(filter[0])) {
  25940. filterName = filter[0].name;
  25941. }
  25942. // Parse image stream.
  25943. var startPos = stream.pos, length, i, ii;
  25944. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  25945. length = this.findDCTDecodeInlineStreamEnd(stream);
  25946. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  25947. length = this.findASCII85DecodeInlineStreamEnd(stream);
  25948. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  25949. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  25950. } else {
  25951. length = this.findDefaultInlineStreamEnd(stream);
  25952. }
  25953. var imageStream = stream.makeSubStream(startPos, length, dict);
  25954. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  25955. // adler32 checksum.
  25956. var adler32;
  25957. if (length < MAX_LENGTH_TO_CACHE) {
  25958. var imageBytes = imageStream.getBytes();
  25959. imageStream.reset();
  25960. var a = 1;
  25961. var b = 0;
  25962. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  25963. // No modulo required in the loop if imageBytes.length < 5552.
  25964. a += imageBytes[i] & 0xff;
  25965. b += a;
  25966. }
  25967. adler32 = ((b % 65521) << 16) | (a % 65521);
  25968. if (this.imageCache.adler32 === adler32) {
  25969. this.buf2 = Cmd.get('EI');
  25970. this.shift();
  25971. this.imageCache[adler32].reset();
  25972. return this.imageCache[adler32];
  25973. }
  25974. }
  25975. if (cipherTransform) {
  25976. imageStream = cipherTransform.createStream(imageStream, length);
  25977. }
  25978. imageStream = this.filter(imageStream, dict, length);
  25979. imageStream.dict = dict;
  25980. if (adler32 !== undefined) {
  25981. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  25982. this.imageCache[adler32] = imageStream;
  25983. }
  25984. this.buf2 = Cmd.get('EI');
  25985. this.shift();
  25986. return imageStream;
  25987. },
  25988. makeStream: function Parser_makeStream(dict, cipherTransform) {
  25989. var lexer = this.lexer;
  25990. var stream = lexer.stream;
  25991. // get stream start position
  25992. lexer.skipToNextLine();
  25993. var pos = stream.pos - 1;
  25994. // get length
  25995. var length = dict.get('Length');
  25996. if (!isInt(length)) {
  25997. info('Bad ' + length + ' attribute in stream');
  25998. length = 0;
  25999. }
  26000. // skip over the stream data
  26001. stream.pos = pos + length;
  26002. lexer.nextChar();
  26003. // Shift '>>' and check whether the new object marks the end of the stream
  26004. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26005. this.shift(); // 'stream'
  26006. } else {
  26007. // bad stream length, scanning for endstream
  26008. stream.pos = pos;
  26009. var SCAN_BLOCK_SIZE = 2048;
  26010. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26011. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26012. 0x61, 0x6D];
  26013. var skipped = 0, found = false, i, j;
  26014. while (stream.pos < stream.end) {
  26015. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26016. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26017. if (scanLength <= 0) {
  26018. break;
  26019. }
  26020. found = false;
  26021. i = 0;
  26022. while (i < scanLength) {
  26023. j = 0;
  26024. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  26025. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  26026. j++;
  26027. }
  26028. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26029. found = true;
  26030. break;
  26031. }
  26032. i++;
  26033. }
  26034. if (found) {
  26035. skipped += i;
  26036. stream.pos += i;
  26037. break;
  26038. }
  26039. skipped += scanLength;
  26040. stream.pos += scanLength;
  26041. }
  26042. if (!found) {
  26043. error('Missing endstream');
  26044. }
  26045. length = skipped;
  26046. lexer.nextChar();
  26047. this.shift();
  26048. this.shift();
  26049. }
  26050. this.shift(); // 'endstream'
  26051. stream = stream.makeSubStream(pos, length, dict);
  26052. if (cipherTransform) {
  26053. stream = cipherTransform.createStream(stream, length);
  26054. }
  26055. stream = this.filter(stream, dict, length);
  26056. stream.dict = dict;
  26057. return stream;
  26058. },
  26059. filter: function Parser_filter(stream, dict, length) {
  26060. var filter = dict.get('Filter', 'F');
  26061. var params = dict.get('DecodeParms', 'DP');
  26062. if (isName(filter)) {
  26063. return this.makeFilter(stream, filter.name, length, params);
  26064. }
  26065. var maybeLength = length;
  26066. if (isArray(filter)) {
  26067. var filterArray = filter;
  26068. var paramsArray = params;
  26069. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26070. filter = filterArray[i];
  26071. if (!isName(filter)) {
  26072. error('Bad filter name: ' + filter);
  26073. }
  26074. params = null;
  26075. if (isArray(paramsArray) && (i in paramsArray)) {
  26076. params = paramsArray[i];
  26077. }
  26078. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26079. // after the first stream the length variable is invalid
  26080. maybeLength = null;
  26081. }
  26082. }
  26083. return stream;
  26084. },
  26085. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26086. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26087. warn('Empty "' + name + '" stream.');
  26088. return new NullStream(stream);
  26089. }
  26090. try {
  26091. if (params && this.xref) {
  26092. params = this.xref.fetchIfRef(params);
  26093. }
  26094. var xrefStreamStats = this.xref.stats.streamTypes;
  26095. if (name === 'FlateDecode' || name === 'Fl') {
  26096. xrefStreamStats[StreamType.FLATE] = true;
  26097. if (params) {
  26098. return new PredictorStream(new FlateStream(stream, maybeLength),
  26099. maybeLength, params);
  26100. }
  26101. return new FlateStream(stream, maybeLength);
  26102. }
  26103. if (name === 'LZWDecode' || name === 'LZW') {
  26104. xrefStreamStats[StreamType.LZW] = true;
  26105. var earlyChange = 1;
  26106. if (params) {
  26107. if (params.has('EarlyChange')) {
  26108. earlyChange = params.get('EarlyChange');
  26109. }
  26110. return new PredictorStream(
  26111. new LZWStream(stream, maybeLength, earlyChange),
  26112. maybeLength, params);
  26113. }
  26114. return new LZWStream(stream, maybeLength, earlyChange);
  26115. }
  26116. if (name === 'DCTDecode' || name === 'DCT') {
  26117. xrefStreamStats[StreamType.DCT] = true;
  26118. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26119. }
  26120. if (name === 'JPXDecode' || name === 'JPX') {
  26121. xrefStreamStats[StreamType.JPX] = true;
  26122. return new JpxStream(stream, maybeLength, stream.dict);
  26123. }
  26124. if (name === 'ASCII85Decode' || name === 'A85') {
  26125. xrefStreamStats[StreamType.A85] = true;
  26126. return new Ascii85Stream(stream, maybeLength);
  26127. }
  26128. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26129. xrefStreamStats[StreamType.AHX] = true;
  26130. return new AsciiHexStream(stream, maybeLength);
  26131. }
  26132. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26133. xrefStreamStats[StreamType.CCF] = true;
  26134. return new CCITTFaxStream(stream, maybeLength, params);
  26135. }
  26136. if (name === 'RunLengthDecode' || name === 'RL') {
  26137. xrefStreamStats[StreamType.RL] = true;
  26138. return new RunLengthStream(stream, maybeLength);
  26139. }
  26140. if (name === 'JBIG2Decode') {
  26141. xrefStreamStats[StreamType.JBIG] = true;
  26142. return new Jbig2Stream(stream, maybeLength, stream.dict);
  26143. }
  26144. warn('filter "' + name + '" not supported yet');
  26145. return stream;
  26146. } catch (ex) {
  26147. if (ex instanceof MissingDataException) {
  26148. throw ex;
  26149. }
  26150. warn('Invalid stream: \"' + ex + '\"');
  26151. return new NullStream(stream);
  26152. }
  26153. }
  26154. };
  26155. return Parser;
  26156. })();
  26157. var Lexer = (function LexerClosure() {
  26158. function Lexer(stream, knownCommands) {
  26159. this.stream = stream;
  26160. this.nextChar();
  26161. // While lexing, we build up many strings one char at a time. Using += for
  26162. // this can result in lots of garbage strings. It's better to build an
  26163. // array of single-char strings and then join() them together at the end.
  26164. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  26165. // purpose uses less memory than using a new array for each string.
  26166. this.strBuf = [];
  26167. // The PDFs might have "glued" commands with other commands, operands or
  26168. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  26169. // commands and their prefixes. The prefixes are built the following way:
  26170. // if there a command that is a prefix of the other valid command or
  26171. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  26172. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  26173. // other commands or literals as a prefix. The knowCommands is optional.
  26174. this.knownCommands = knownCommands;
  26175. }
  26176. Lexer.isSpace = function Lexer_isSpace(ch) {
  26177. // Space is one of the following characters: SPACE, TAB, CR or LF.
  26178. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  26179. };
  26180. // A '1' in this array means the character is white space. A '1' or
  26181. // '2' means the character ends a name or command.
  26182. var specialChars = [
  26183. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  26184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  26185. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  26186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  26187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  26188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  26189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  26190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  26191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  26192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  26193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  26194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  26195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  26196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  26197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  26198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  26199. ];
  26200. function toHexDigit(ch) {
  26201. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  26202. return ch & 0x0F;
  26203. }
  26204. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  26205. // 'A'-'F', 'a'-'f'
  26206. return (ch & 0x0F) + 9;
  26207. }
  26208. return -1;
  26209. }
  26210. Lexer.prototype = {
  26211. nextChar: function Lexer_nextChar() {
  26212. return (this.currentChar = this.stream.getByte());
  26213. },
  26214. peekChar: function Lexer_peekChar() {
  26215. return this.stream.peekByte();
  26216. },
  26217. getNumber: function Lexer_getNumber() {
  26218. var ch = this.currentChar;
  26219. var eNotation = false;
  26220. var divideBy = 0; // different from 0 if it's a floating point value
  26221. var sign = 1;
  26222. if (ch === 0x2D) { // '-'
  26223. sign = -1;
  26224. ch = this.nextChar();
  26225. if (ch === 0x2D) { // '-'
  26226. // Ignore double negative (this is consistent with Adobe Reader).
  26227. ch = this.nextChar();
  26228. }
  26229. } else if (ch === 0x2B) { // '+'
  26230. ch = this.nextChar();
  26231. }
  26232. if (ch === 0x2E) { // '.'
  26233. divideBy = 10;
  26234. ch = this.nextChar();
  26235. }
  26236. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26237. error('Invalid number: ' + String.fromCharCode(ch));
  26238. return 0;
  26239. }
  26240. var baseValue = ch - 0x30; // '0'
  26241. var powerValue = 0;
  26242. var powerValueSign = 1;
  26243. while ((ch = this.nextChar()) >= 0) {
  26244. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  26245. var currentDigit = ch - 0x30; // '0'
  26246. if (eNotation) { // We are after an 'e' or 'E'
  26247. powerValue = powerValue * 10 + currentDigit;
  26248. } else {
  26249. if (divideBy !== 0) { // We are after a point
  26250. divideBy *= 10;
  26251. }
  26252. baseValue = baseValue * 10 + currentDigit;
  26253. }
  26254. } else if (ch === 0x2E) { // '.'
  26255. if (divideBy === 0) {
  26256. divideBy = 1;
  26257. } else {
  26258. // A number can have only one '.'
  26259. break;
  26260. }
  26261. } else if (ch === 0x2D) { // '-'
  26262. // ignore minus signs in the middle of numbers to match
  26263. // Adobe's behavior
  26264. warn('Badly formated number');
  26265. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  26266. // 'E' can be either a scientific notation or the beginning of a new
  26267. // operator
  26268. ch = this.peekChar();
  26269. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  26270. powerValueSign = (ch === 0x2D) ? -1 : 1;
  26271. this.nextChar(); // Consume the sign character
  26272. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26273. // The 'E' must be the beginning of a new operator
  26274. break;
  26275. }
  26276. eNotation = true;
  26277. } else {
  26278. // the last character doesn't belong to us
  26279. break;
  26280. }
  26281. }
  26282. if (divideBy !== 0) {
  26283. baseValue /= divideBy;
  26284. }
  26285. if (eNotation) {
  26286. baseValue *= Math.pow(10, powerValueSign * powerValue);
  26287. }
  26288. return sign * baseValue;
  26289. },
  26290. getString: function Lexer_getString() {
  26291. var numParen = 1;
  26292. var done = false;
  26293. var strBuf = this.strBuf;
  26294. strBuf.length = 0;
  26295. var ch = this.nextChar();
  26296. while (true) {
  26297. var charBuffered = false;
  26298. switch (ch | 0) {
  26299. case -1:
  26300. warn('Unterminated string');
  26301. done = true;
  26302. break;
  26303. case 0x28: // '('
  26304. ++numParen;
  26305. strBuf.push('(');
  26306. break;
  26307. case 0x29: // ')'
  26308. if (--numParen === 0) {
  26309. this.nextChar(); // consume strings ')'
  26310. done = true;
  26311. } else {
  26312. strBuf.push(')');
  26313. }
  26314. break;
  26315. case 0x5C: // '\\'
  26316. ch = this.nextChar();
  26317. switch (ch) {
  26318. case -1:
  26319. warn('Unterminated string');
  26320. done = true;
  26321. break;
  26322. case 0x6E: // 'n'
  26323. strBuf.push('\n');
  26324. break;
  26325. case 0x72: // 'r'
  26326. strBuf.push('\r');
  26327. break;
  26328. case 0x74: // 't'
  26329. strBuf.push('\t');
  26330. break;
  26331. case 0x62: // 'b'
  26332. strBuf.push('\b');
  26333. break;
  26334. case 0x66: // 'f'
  26335. strBuf.push('\f');
  26336. break;
  26337. case 0x5C: // '\'
  26338. case 0x28: // '('
  26339. case 0x29: // ')'
  26340. strBuf.push(String.fromCharCode(ch));
  26341. break;
  26342. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  26343. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  26344. var x = ch & 0x0F;
  26345. ch = this.nextChar();
  26346. charBuffered = true;
  26347. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26348. x = (x << 3) + (ch & 0x0F);
  26349. ch = this.nextChar();
  26350. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26351. charBuffered = false;
  26352. x = (x << 3) + (ch & 0x0F);
  26353. }
  26354. }
  26355. strBuf.push(String.fromCharCode(x));
  26356. break;
  26357. case 0x0D: // CR
  26358. if (this.peekChar() === 0x0A) { // LF
  26359. this.nextChar();
  26360. }
  26361. break;
  26362. case 0x0A: // LF
  26363. break;
  26364. default:
  26365. strBuf.push(String.fromCharCode(ch));
  26366. break;
  26367. }
  26368. break;
  26369. default:
  26370. strBuf.push(String.fromCharCode(ch));
  26371. break;
  26372. }
  26373. if (done) {
  26374. break;
  26375. }
  26376. if (!charBuffered) {
  26377. ch = this.nextChar();
  26378. }
  26379. }
  26380. return strBuf.join('');
  26381. },
  26382. getName: function Lexer_getName() {
  26383. var ch, previousCh;
  26384. var strBuf = this.strBuf;
  26385. strBuf.length = 0;
  26386. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26387. if (ch === 0x23) { // '#'
  26388. ch = this.nextChar();
  26389. if (specialChars[ch]) {
  26390. warn('Lexer_getName: ' +
  26391. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  26392. strBuf.push('#');
  26393. break;
  26394. }
  26395. var x = toHexDigit(ch);
  26396. if (x !== -1) {
  26397. previousCh = ch;
  26398. ch = this.nextChar();
  26399. var x2 = toHexDigit(ch);
  26400. if (x2 === -1) {
  26401. warn('Lexer_getName: Illegal digit (' +
  26402. String.fromCharCode(ch) +') in hexadecimal number.');
  26403. strBuf.push('#', String.fromCharCode(previousCh));
  26404. if (specialChars[ch]) {
  26405. break;
  26406. }
  26407. strBuf.push(String.fromCharCode(ch));
  26408. continue;
  26409. }
  26410. strBuf.push(String.fromCharCode((x << 4) | x2));
  26411. } else {
  26412. strBuf.push('#', String.fromCharCode(ch));
  26413. }
  26414. } else {
  26415. strBuf.push(String.fromCharCode(ch));
  26416. }
  26417. }
  26418. if (strBuf.length > 127) {
  26419. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  26420. }
  26421. return Name.get(strBuf.join(''));
  26422. },
  26423. getHexString: function Lexer_getHexString() {
  26424. var strBuf = this.strBuf;
  26425. strBuf.length = 0;
  26426. var ch = this.currentChar;
  26427. var isFirstHex = true;
  26428. var firstDigit;
  26429. var secondDigit;
  26430. while (true) {
  26431. if (ch < 0) {
  26432. warn('Unterminated hex string');
  26433. break;
  26434. } else if (ch === 0x3E) { // '>'
  26435. this.nextChar();
  26436. break;
  26437. } else if (specialChars[ch] === 1) {
  26438. ch = this.nextChar();
  26439. continue;
  26440. } else {
  26441. if (isFirstHex) {
  26442. firstDigit = toHexDigit(ch);
  26443. if (firstDigit === -1) {
  26444. warn('Ignoring invalid character "' + ch + '" in hex string');
  26445. ch = this.nextChar();
  26446. continue;
  26447. }
  26448. } else {
  26449. secondDigit = toHexDigit(ch);
  26450. if (secondDigit === -1) {
  26451. warn('Ignoring invalid character "' + ch + '" in hex string');
  26452. ch = this.nextChar();
  26453. continue;
  26454. }
  26455. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  26456. }
  26457. isFirstHex = !isFirstHex;
  26458. ch = this.nextChar();
  26459. }
  26460. }
  26461. return strBuf.join('');
  26462. },
  26463. getObj: function Lexer_getObj() {
  26464. // skip whitespace and comments
  26465. var comment = false;
  26466. var ch = this.currentChar;
  26467. while (true) {
  26468. if (ch < 0) {
  26469. return EOF;
  26470. }
  26471. if (comment) {
  26472. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  26473. comment = false;
  26474. }
  26475. } else if (ch === 0x25) { // '%'
  26476. comment = true;
  26477. } else if (specialChars[ch] !== 1) {
  26478. break;
  26479. }
  26480. ch = this.nextChar();
  26481. }
  26482. // start reading token
  26483. switch (ch | 0) {
  26484. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  26485. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  26486. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  26487. return this.getNumber();
  26488. case 0x28: // '('
  26489. return this.getString();
  26490. case 0x2F: // '/'
  26491. return this.getName();
  26492. // array punctuation
  26493. case 0x5B: // '['
  26494. this.nextChar();
  26495. return Cmd.get('[');
  26496. case 0x5D: // ']'
  26497. this.nextChar();
  26498. return Cmd.get(']');
  26499. // hex string or dict punctuation
  26500. case 0x3C: // '<'
  26501. ch = this.nextChar();
  26502. if (ch === 0x3C) {
  26503. // dict punctuation
  26504. this.nextChar();
  26505. return Cmd.get('<<');
  26506. }
  26507. return this.getHexString();
  26508. // dict punctuation
  26509. case 0x3E: // '>'
  26510. ch = this.nextChar();
  26511. if (ch === 0x3E) {
  26512. this.nextChar();
  26513. return Cmd.get('>>');
  26514. }
  26515. return Cmd.get('>');
  26516. case 0x7B: // '{'
  26517. this.nextChar();
  26518. return Cmd.get('{');
  26519. case 0x7D: // '}'
  26520. this.nextChar();
  26521. return Cmd.get('}');
  26522. case 0x29: // ')'
  26523. error('Illegal character: ' + ch);
  26524. break;
  26525. }
  26526. // command
  26527. var str = String.fromCharCode(ch);
  26528. var knownCommands = this.knownCommands;
  26529. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26530. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26531. // stop if known command is found and next character does not make
  26532. // the str a command
  26533. var possibleCommand = str + String.fromCharCode(ch);
  26534. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  26535. break;
  26536. }
  26537. if (str.length === 128) {
  26538. error('Command token too long: ' + str.length);
  26539. }
  26540. str = possibleCommand;
  26541. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26542. }
  26543. if (str === 'true') {
  26544. return true;
  26545. }
  26546. if (str === 'false') {
  26547. return false;
  26548. }
  26549. if (str === 'null') {
  26550. return null;
  26551. }
  26552. return Cmd.get(str);
  26553. },
  26554. skipToNextLine: function Lexer_skipToNextLine() {
  26555. var ch = this.currentChar;
  26556. while (ch >= 0) {
  26557. if (ch === 0x0D) { // CR
  26558. ch = this.nextChar();
  26559. if (ch === 0x0A) { // LF
  26560. this.nextChar();
  26561. }
  26562. break;
  26563. } else if (ch === 0x0A) { // LF
  26564. this.nextChar();
  26565. break;
  26566. }
  26567. ch = this.nextChar();
  26568. }
  26569. }
  26570. };
  26571. return Lexer;
  26572. })();
  26573. var Linearization = {
  26574. create: function LinearizationCreate(stream) {
  26575. function getInt(name, allowZeroValue) {
  26576. var obj = linDict.get(name);
  26577. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  26578. return obj;
  26579. }
  26580. throw new Error('The "' + name + '" parameter in the linearization ' +
  26581. 'dictionary is invalid.');
  26582. }
  26583. function getHints() {
  26584. var hints = linDict.get('H'), hintsLength, item;
  26585. if (isArray(hints) &&
  26586. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  26587. for (var index = 0; index < hintsLength; index++) {
  26588. if (!(isInt(item = hints[index]) && item > 0)) {
  26589. throw new Error('Hint (' + index +
  26590. ') in the linearization dictionary is invalid.');
  26591. }
  26592. }
  26593. return hints;
  26594. }
  26595. throw new Error('Hint array in the linearization dictionary is invalid.');
  26596. }
  26597. var parser = new Parser(new Lexer(stream), false, null);
  26598. var obj1 = parser.getObj();
  26599. var obj2 = parser.getObj();
  26600. var obj3 = parser.getObj();
  26601. var linDict = parser.getObj();
  26602. var obj, length;
  26603. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  26604. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  26605. return null; // No valid linearization dictionary found.
  26606. } else if ((length = getInt('L')) !== stream.length) {
  26607. throw new Error('The "L" parameter in the linearization dictionary ' +
  26608. 'does not equal the stream length.');
  26609. }
  26610. return {
  26611. length: length,
  26612. hints: getHints(),
  26613. objectNumberFirst: getInt('O'),
  26614. endFirst: getInt('E'),
  26615. numPages: getInt('N'),
  26616. mainXRefEntriesOffset: getInt('T'),
  26617. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  26618. };
  26619. }
  26620. };
  26621. exports.EOF = EOF;
  26622. exports.Lexer = Lexer;
  26623. exports.Linearization = Linearization;
  26624. exports.Parser = Parser;
  26625. exports.isEOF = isEOF;
  26626. // TODO refactor to remove dependency on stream.js
  26627. coreStream._setCoreParser(exports);
  26628. }));
  26629. (function (root, factory) {
  26630. {
  26631. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  26632. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  26633. }
  26634. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  26635. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26636. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  26637. var ImageKind = sharedUtil.ImageKind;
  26638. var OPS = sharedUtil.OPS;
  26639. var TextRenderingMode = sharedUtil.TextRenderingMode;
  26640. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  26641. var Util = sharedUtil.Util;
  26642. var assert = sharedUtil.assert;
  26643. var info = sharedUtil.info;
  26644. var isNum = sharedUtil.isNum;
  26645. var isArray = sharedUtil.isArray;
  26646. var error = sharedUtil.error;
  26647. var shadow = sharedUtil.shadow;
  26648. var warn = sharedUtil.warn;
  26649. var TilingPattern = displayPatternHelper.TilingPattern;
  26650. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  26651. var WebGLUtils = displayWebGL.WebGLUtils;
  26652. // <canvas> contexts store most of the state we need natively.
  26653. // However, PDF needs a bit more state, which we store here.
  26654. // Minimal font size that would be used during canvas fillText operations.
  26655. var MIN_FONT_SIZE = 16;
  26656. // Maximum font size that would be used during canvas fillText operations.
  26657. var MAX_FONT_SIZE = 100;
  26658. var MAX_GROUP_SIZE = 4096;
  26659. // Heuristic value used when enforcing minimum line widths.
  26660. var MIN_WIDTH_FACTOR = 0.65;
  26661. var COMPILE_TYPE3_GLYPHS = true;
  26662. var MAX_SIZE_TO_COMPILE = 1000;
  26663. var FULL_CHUNK_HEIGHT = 16;
  26664. function createScratchCanvas(width, height) {
  26665. var canvas = document.createElement('canvas');
  26666. canvas.width = width;
  26667. canvas.height = height;
  26668. return canvas;
  26669. }
  26670. function addContextCurrentTransform(ctx) {
  26671. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  26672. if (!ctx.mozCurrentTransform) {
  26673. ctx._originalSave = ctx.save;
  26674. ctx._originalRestore = ctx.restore;
  26675. ctx._originalRotate = ctx.rotate;
  26676. ctx._originalScale = ctx.scale;
  26677. ctx._originalTranslate = ctx.translate;
  26678. ctx._originalTransform = ctx.transform;
  26679. ctx._originalSetTransform = ctx.setTransform;
  26680. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  26681. ctx._transformStack = [];
  26682. Object.defineProperty(ctx, 'mozCurrentTransform', {
  26683. get: function getCurrentTransform() {
  26684. return this._transformMatrix;
  26685. }
  26686. });
  26687. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  26688. get: function getCurrentTransformInverse() {
  26689. // Calculation done using WolframAlpha:
  26690. // http://www.wolframalpha.com/input/?
  26691. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  26692. var m = this._transformMatrix;
  26693. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  26694. var ad_bc = a * d - b * c;
  26695. var bc_ad = b * c - a * d;
  26696. return [
  26697. d / ad_bc,
  26698. b / bc_ad,
  26699. c / bc_ad,
  26700. a / ad_bc,
  26701. (d * e - c * f) / bc_ad,
  26702. (b * e - a * f) / ad_bc
  26703. ];
  26704. }
  26705. });
  26706. ctx.save = function ctxSave() {
  26707. var old = this._transformMatrix;
  26708. this._transformStack.push(old);
  26709. this._transformMatrix = old.slice(0, 6);
  26710. this._originalSave();
  26711. };
  26712. ctx.restore = function ctxRestore() {
  26713. var prev = this._transformStack.pop();
  26714. if (prev) {
  26715. this._transformMatrix = prev;
  26716. this._originalRestore();
  26717. }
  26718. };
  26719. ctx.translate = function ctxTranslate(x, y) {
  26720. var m = this._transformMatrix;
  26721. m[4] = m[0] * x + m[2] * y + m[4];
  26722. m[5] = m[1] * x + m[3] * y + m[5];
  26723. this._originalTranslate(x, y);
  26724. };
  26725. ctx.scale = function ctxScale(x, y) {
  26726. var m = this._transformMatrix;
  26727. m[0] = m[0] * x;
  26728. m[1] = m[1] * x;
  26729. m[2] = m[2] * y;
  26730. m[3] = m[3] * y;
  26731. this._originalScale(x, y);
  26732. };
  26733. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  26734. var m = this._transformMatrix;
  26735. this._transformMatrix = [
  26736. m[0] * a + m[2] * b,
  26737. m[1] * a + m[3] * b,
  26738. m[0] * c + m[2] * d,
  26739. m[1] * c + m[3] * d,
  26740. m[0] * e + m[2] * f + m[4],
  26741. m[1] * e + m[3] * f + m[5]
  26742. ];
  26743. ctx._originalTransform(a, b, c, d, e, f);
  26744. };
  26745. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  26746. this._transformMatrix = [a, b, c, d, e, f];
  26747. ctx._originalSetTransform(a, b, c, d, e, f);
  26748. };
  26749. ctx.rotate = function ctxRotate(angle) {
  26750. var cosValue = Math.cos(angle);
  26751. var sinValue = Math.sin(angle);
  26752. var m = this._transformMatrix;
  26753. this._transformMatrix = [
  26754. m[0] * cosValue + m[2] * sinValue,
  26755. m[1] * cosValue + m[3] * sinValue,
  26756. m[0] * (-sinValue) + m[2] * cosValue,
  26757. m[1] * (-sinValue) + m[3] * cosValue,
  26758. m[4],
  26759. m[5]
  26760. ];
  26761. this._originalRotate(angle);
  26762. };
  26763. }
  26764. }
  26765. var CachedCanvases = (function CachedCanvasesClosure() {
  26766. function CachedCanvases() {
  26767. this.cache = Object.create(null);
  26768. }
  26769. CachedCanvases.prototype = {
  26770. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  26771. trackTransform) {
  26772. var canvasEntry;
  26773. if (this.cache[id] !== undefined) {
  26774. canvasEntry = this.cache[id];
  26775. canvasEntry.canvas.width = width;
  26776. canvasEntry.canvas.height = height;
  26777. // reset canvas transform for emulated mozCurrentTransform, if needed
  26778. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  26779. } else {
  26780. var canvas = createScratchCanvas(width, height);
  26781. var ctx = canvas.getContext('2d');
  26782. if (trackTransform) {
  26783. addContextCurrentTransform(ctx);
  26784. }
  26785. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  26786. }
  26787. return canvasEntry;
  26788. },
  26789. clear: function () {
  26790. for (var id in this.cache) {
  26791. var canvasEntry = this.cache[id];
  26792. // Zeroing the width and height causes Firefox to release graphics
  26793. // resources immediately, which can greatly reduce memory consumption.
  26794. canvasEntry.canvas.width = 0;
  26795. canvasEntry.canvas.height = 0;
  26796. delete this.cache[id];
  26797. }
  26798. }
  26799. };
  26800. return CachedCanvases;
  26801. })();
  26802. function compileType3Glyph(imgData) {
  26803. var POINT_TO_PROCESS_LIMIT = 1000;
  26804. var width = imgData.width, height = imgData.height;
  26805. var i, j, j0, width1 = width + 1;
  26806. var points = new Uint8Array(width1 * (height + 1));
  26807. var POINT_TYPES =
  26808. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  26809. // decodes bit-packed mask data
  26810. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  26811. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  26812. for (i = 0, ii = data0.length; i < ii; i++) {
  26813. var mask = 128, elem = data0[i];
  26814. while (mask > 0) {
  26815. data[pos++] = (elem & mask) ? 0 : 255;
  26816. mask >>= 1;
  26817. }
  26818. }
  26819. // finding iteresting points: every point is located between mask pixels,
  26820. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  26821. // will have flags assigned based on neighboring mask pixels:
  26822. // 4 | 8
  26823. // --P--
  26824. // 2 | 1
  26825. // We are interested only in points with the flags:
  26826. // - outside corners: 1, 2, 4, 8;
  26827. // - inside corners: 7, 11, 13, 14;
  26828. // - and, intersections: 5, 10.
  26829. var count = 0;
  26830. pos = 0;
  26831. if (data[pos] !== 0) {
  26832. points[0] = 1;
  26833. ++count;
  26834. }
  26835. for (j = 1; j < width; j++) {
  26836. if (data[pos] !== data[pos + 1]) {
  26837. points[j] = data[pos] ? 2 : 1;
  26838. ++count;
  26839. }
  26840. pos++;
  26841. }
  26842. if (data[pos] !== 0) {
  26843. points[j] = 2;
  26844. ++count;
  26845. }
  26846. for (i = 1; i < height; i++) {
  26847. pos = i * lineSize;
  26848. j0 = i * width1;
  26849. if (data[pos - lineSize] !== data[pos]) {
  26850. points[j0] = data[pos] ? 1 : 8;
  26851. ++count;
  26852. }
  26853. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  26854. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  26855. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  26856. for (j = 1; j < width; j++) {
  26857. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  26858. (data[pos - lineSize + 1] ? 8 : 0);
  26859. if (POINT_TYPES[sum]) {
  26860. points[j0 + j] = POINT_TYPES[sum];
  26861. ++count;
  26862. }
  26863. pos++;
  26864. }
  26865. if (data[pos - lineSize] !== data[pos]) {
  26866. points[j0 + j] = data[pos] ? 2 : 4;
  26867. ++count;
  26868. }
  26869. if (count > POINT_TO_PROCESS_LIMIT) {
  26870. return null;
  26871. }
  26872. }
  26873. pos = lineSize * (height - 1);
  26874. j0 = i * width1;
  26875. if (data[pos] !== 0) {
  26876. points[j0] = 8;
  26877. ++count;
  26878. }
  26879. for (j = 1; j < width; j++) {
  26880. if (data[pos] !== data[pos + 1]) {
  26881. points[j0 + j] = data[pos] ? 4 : 8;
  26882. ++count;
  26883. }
  26884. pos++;
  26885. }
  26886. if (data[pos] !== 0) {
  26887. points[j0 + j] = 4;
  26888. ++count;
  26889. }
  26890. if (count > POINT_TO_PROCESS_LIMIT) {
  26891. return null;
  26892. }
  26893. // building outlines
  26894. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  26895. var outlines = [];
  26896. for (i = 0; count && i <= height; i++) {
  26897. var p = i * width1;
  26898. var end = p + width;
  26899. while (p < end && !points[p]) {
  26900. p++;
  26901. }
  26902. if (p === end) {
  26903. continue;
  26904. }
  26905. var coords = [p % width1, i];
  26906. var type = points[p], p0 = p, pp;
  26907. do {
  26908. var step = steps[type];
  26909. do {
  26910. p += step;
  26911. } while (!points[p]);
  26912. pp = points[p];
  26913. if (pp !== 5 && pp !== 10) {
  26914. // set new direction
  26915. type = pp;
  26916. // delete mark
  26917. points[p] = 0;
  26918. } else { // type is 5 or 10, ie, a crossing
  26919. // set new direction
  26920. type = pp & ((0x33 * type) >> 4);
  26921. // set new type for "future hit"
  26922. points[p] &= (type >> 2 | type << 2);
  26923. }
  26924. coords.push(p % width1);
  26925. coords.push((p / width1) | 0);
  26926. --count;
  26927. } while (p0 !== p);
  26928. outlines.push(coords);
  26929. --i;
  26930. }
  26931. var drawOutline = function(c) {
  26932. c.save();
  26933. // the path shall be painted in [0..1]x[0..1] space
  26934. c.scale(1 / width, -1 / height);
  26935. c.translate(0, -height);
  26936. c.beginPath();
  26937. for (var i = 0, ii = outlines.length; i < ii; i++) {
  26938. var o = outlines[i];
  26939. c.moveTo(o[0], o[1]);
  26940. for (var j = 2, jj = o.length; j < jj; j += 2) {
  26941. c.lineTo(o[j], o[j+1]);
  26942. }
  26943. }
  26944. c.fill();
  26945. c.beginPath();
  26946. c.restore();
  26947. };
  26948. return drawOutline;
  26949. }
  26950. var CanvasExtraState = (function CanvasExtraStateClosure() {
  26951. function CanvasExtraState(old) {
  26952. // Are soft masks and alpha values shapes or opacities?
  26953. this.alphaIsShape = false;
  26954. this.fontSize = 0;
  26955. this.fontSizeScale = 1;
  26956. this.textMatrix = IDENTITY_MATRIX;
  26957. this.textMatrixScale = 1;
  26958. this.fontMatrix = FONT_IDENTITY_MATRIX;
  26959. this.leading = 0;
  26960. // Current point (in user coordinates)
  26961. this.x = 0;
  26962. this.y = 0;
  26963. // Start of text line (in text coordinates)
  26964. this.lineX = 0;
  26965. this.lineY = 0;
  26966. // Character and word spacing
  26967. this.charSpacing = 0;
  26968. this.wordSpacing = 0;
  26969. this.textHScale = 1;
  26970. this.textRenderingMode = TextRenderingMode.FILL;
  26971. this.textRise = 0;
  26972. // Default fore and background colors
  26973. this.fillColor = '#000000';
  26974. this.strokeColor = '#000000';
  26975. this.patternFill = false;
  26976. // Note: fill alpha applies to all non-stroking operations
  26977. this.fillAlpha = 1;
  26978. this.strokeAlpha = 1;
  26979. this.lineWidth = 1;
  26980. this.activeSMask = null; // nonclonable field (see the save method below)
  26981. this.old = old;
  26982. }
  26983. CanvasExtraState.prototype = {
  26984. clone: function CanvasExtraState_clone() {
  26985. return Object.create(this);
  26986. },
  26987. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  26988. this.x = x;
  26989. this.y = y;
  26990. }
  26991. };
  26992. return CanvasExtraState;
  26993. })();
  26994. var CanvasGraphics = (function CanvasGraphicsClosure() {
  26995. // Defines the time the executeOperatorList is going to be executing
  26996. // before it stops and shedules a continue of execution.
  26997. var EXECUTION_TIME = 15;
  26998. // Defines the number of steps before checking the execution time
  26999. var EXECUTION_STEPS = 10;
  27000. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  27001. this.ctx = canvasCtx;
  27002. this.current = new CanvasExtraState();
  27003. this.stateStack = [];
  27004. this.pendingClip = null;
  27005. this.pendingEOFill = false;
  27006. this.res = null;
  27007. this.xobjs = null;
  27008. this.commonObjs = commonObjs;
  27009. this.objs = objs;
  27010. this.imageLayer = imageLayer;
  27011. this.groupStack = [];
  27012. this.processingType3 = null;
  27013. // Patterns are painted relative to the initial page/form transform, see pdf
  27014. // spec 8.7.2 NOTE 1.
  27015. this.baseTransform = null;
  27016. this.baseTransformStack = [];
  27017. this.groupLevel = 0;
  27018. this.smaskStack = [];
  27019. this.smaskCounter = 0;
  27020. this.tempSMask = null;
  27021. this.cachedCanvases = new CachedCanvases();
  27022. if (canvasCtx) {
  27023. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  27024. // the transformation must already be set in canvasCtx._transformMatrix.
  27025. addContextCurrentTransform(canvasCtx);
  27026. }
  27027. this.cachedGetSinglePixelWidth = null;
  27028. }
  27029. function putBinaryImageData(ctx, imgData) {
  27030. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  27031. ctx.putImageData(imgData, 0, 0);
  27032. return;
  27033. }
  27034. // Put the image data to the canvas in chunks, rather than putting the
  27035. // whole image at once. This saves JS memory, because the ImageData object
  27036. // is smaller. It also possibly saves C++ memory within the implementation
  27037. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  27038. // the data passed to putImageData()). |n| shouldn't be too small, however,
  27039. // because too many putImageData() calls will slow things down.
  27040. //
  27041. // Note: as written, if the last chunk is partial, the putImageData() call
  27042. // will (conceptually) put pixels past the bounds of the canvas. But
  27043. // that's ok; any such pixels are ignored.
  27044. var height = imgData.height, width = imgData.width;
  27045. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  27046. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  27047. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  27048. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  27049. var srcPos = 0, destPos;
  27050. var src = imgData.data;
  27051. var dest = chunkImgData.data;
  27052. var i, j, thisChunkHeight, elemsInThisChunk;
  27053. // There are multiple forms in which the pixel data can be passed, and
  27054. // imgData.kind tells us which one this is.
  27055. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  27056. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  27057. var srcLength = src.byteLength;
  27058. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  27059. new Uint32ArrayView(dest);
  27060. var dest32DataLength = dest32.length;
  27061. var fullSrcDiff = (width + 7) >> 3;
  27062. var white = 0xFFFFFFFF;
  27063. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  27064. 0xFF000000 : 0x000000FF;
  27065. for (i = 0; i < totalChunks; i++) {
  27066. thisChunkHeight =
  27067. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  27068. destPos = 0;
  27069. for (j = 0; j < thisChunkHeight; j++) {
  27070. var srcDiff = srcLength - srcPos;
  27071. var k = 0;
  27072. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  27073. var kEndUnrolled = kEnd & ~7;
  27074. var mask = 0;
  27075. var srcByte = 0;
  27076. for (; k < kEndUnrolled; k += 8) {
  27077. srcByte = src[srcPos++];
  27078. dest32[destPos++] = (srcByte & 128) ? white : black;
  27079. dest32[destPos++] = (srcByte & 64) ? white : black;
  27080. dest32[destPos++] = (srcByte & 32) ? white : black;
  27081. dest32[destPos++] = (srcByte & 16) ? white : black;
  27082. dest32[destPos++] = (srcByte & 8) ? white : black;
  27083. dest32[destPos++] = (srcByte & 4) ? white : black;
  27084. dest32[destPos++] = (srcByte & 2) ? white : black;
  27085. dest32[destPos++] = (srcByte & 1) ? white : black;
  27086. }
  27087. for (; k < kEnd; k++) {
  27088. if (mask === 0) {
  27089. srcByte = src[srcPos++];
  27090. mask = 128;
  27091. }
  27092. dest32[destPos++] = (srcByte & mask) ? white : black;
  27093. mask >>= 1;
  27094. }
  27095. }
  27096. // We ran out of input. Make all remaining pixels transparent.
  27097. while (destPos < dest32DataLength) {
  27098. dest32[destPos++] = 0;
  27099. }
  27100. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27101. }
  27102. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  27103. // RGBA, 32-bits per pixel.
  27104. j = 0;
  27105. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  27106. for (i = 0; i < fullChunks; i++) {
  27107. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  27108. srcPos += elemsInThisChunk;
  27109. ctx.putImageData(chunkImgData, 0, j);
  27110. j += FULL_CHUNK_HEIGHT;
  27111. }
  27112. if (i < totalChunks) {
  27113. elemsInThisChunk = width * partialChunkHeight * 4;
  27114. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  27115. ctx.putImageData(chunkImgData, 0, j);
  27116. }
  27117. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  27118. // RGB, 24-bits per pixel.
  27119. thisChunkHeight = FULL_CHUNK_HEIGHT;
  27120. elemsInThisChunk = width * thisChunkHeight;
  27121. for (i = 0; i < totalChunks; i++) {
  27122. if (i >= fullChunks) {
  27123. thisChunkHeight = partialChunkHeight;
  27124. elemsInThisChunk = width * thisChunkHeight;
  27125. }
  27126. destPos = 0;
  27127. for (j = elemsInThisChunk; j--;) {
  27128. dest[destPos++] = src[srcPos++];
  27129. dest[destPos++] = src[srcPos++];
  27130. dest[destPos++] = src[srcPos++];
  27131. dest[destPos++] = 255;
  27132. }
  27133. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27134. }
  27135. } else {
  27136. error('bad image kind: ' + imgData.kind);
  27137. }
  27138. }
  27139. function putBinaryImageMask(ctx, imgData) {
  27140. var height = imgData.height, width = imgData.width;
  27141. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  27142. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  27143. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  27144. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  27145. var srcPos = 0;
  27146. var src = imgData.data;
  27147. var dest = chunkImgData.data;
  27148. for (var i = 0; i < totalChunks; i++) {
  27149. var thisChunkHeight =
  27150. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  27151. // Expand the mask so it can be used by the canvas. Any required
  27152. // inversion has already been handled.
  27153. var destPos = 3; // alpha component offset
  27154. for (var j = 0; j < thisChunkHeight; j++) {
  27155. var mask = 0;
  27156. for (var k = 0; k < width; k++) {
  27157. if (!mask) {
  27158. var elem = src[srcPos++];
  27159. mask = 128;
  27160. }
  27161. dest[destPos] = (elem & mask) ? 0 : 255;
  27162. destPos += 4;
  27163. mask >>= 1;
  27164. }
  27165. }
  27166. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27167. }
  27168. }
  27169. function copyCtxState(sourceCtx, destCtx) {
  27170. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  27171. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  27172. 'globalCompositeOperation', 'font'];
  27173. for (var i = 0, ii = properties.length; i < ii; i++) {
  27174. var property = properties[i];
  27175. if (sourceCtx[property] !== undefined) {
  27176. destCtx[property] = sourceCtx[property];
  27177. }
  27178. }
  27179. if (sourceCtx.setLineDash !== undefined) {
  27180. destCtx.setLineDash(sourceCtx.getLineDash());
  27181. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  27182. } else if (sourceCtx.mozDashOffset !== undefined) {
  27183. destCtx.mozDash = sourceCtx.mozDash;
  27184. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  27185. }
  27186. }
  27187. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  27188. var length = bytes.length;
  27189. for (var i = 3; i < length; i += 4) {
  27190. var alpha = bytes[i];
  27191. if (alpha === 0) {
  27192. bytes[i - 3] = r0;
  27193. bytes[i - 2] = g0;
  27194. bytes[i - 1] = b0;
  27195. } else if (alpha < 255) {
  27196. var alpha_ = 255 - alpha;
  27197. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  27198. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  27199. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  27200. }
  27201. }
  27202. }
  27203. function composeSMaskAlpha(maskData, layerData, transferMap) {
  27204. var length = maskData.length;
  27205. var scale = 1 / 255;
  27206. for (var i = 3; i < length; i += 4) {
  27207. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  27208. layerData[i] = (layerData[i] * alpha * scale) | 0;
  27209. }
  27210. }
  27211. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  27212. var length = maskData.length;
  27213. for (var i = 3; i < length; i += 4) {
  27214. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  27215. (maskData[i - 2] * 152) + // * 0.59 ....
  27216. (maskData[i - 1] * 28); // * 0.11 ....
  27217. layerData[i] = transferMap ?
  27218. (layerData[i] * transferMap[y >> 8]) >> 8 :
  27219. (layerData[i] * y) >> 16;
  27220. }
  27221. }
  27222. function genericComposeSMask(maskCtx, layerCtx, width, height,
  27223. subtype, backdrop, transferMap) {
  27224. var hasBackdrop = !!backdrop;
  27225. var r0 = hasBackdrop ? backdrop[0] : 0;
  27226. var g0 = hasBackdrop ? backdrop[1] : 0;
  27227. var b0 = hasBackdrop ? backdrop[2] : 0;
  27228. var composeFn;
  27229. if (subtype === 'Luminosity') {
  27230. composeFn = composeSMaskLuminosity;
  27231. } else {
  27232. composeFn = composeSMaskAlpha;
  27233. }
  27234. // processing image in chunks to save memory
  27235. var PIXELS_TO_PROCESS = 1048576;
  27236. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  27237. for (var row = 0; row < height; row += chunkSize) {
  27238. var chunkHeight = Math.min(chunkSize, height - row);
  27239. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  27240. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  27241. if (hasBackdrop) {
  27242. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  27243. }
  27244. composeFn(maskData.data, layerData.data, transferMap);
  27245. maskCtx.putImageData(layerData, 0, row);
  27246. }
  27247. }
  27248. function composeSMask(ctx, smask, layerCtx) {
  27249. var mask = smask.canvas;
  27250. var maskCtx = smask.context;
  27251. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  27252. smask.offsetX, smask.offsetY);
  27253. var backdrop = smask.backdrop || null;
  27254. if (!smask.transferMap && WebGLUtils.isEnabled) {
  27255. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  27256. {subtype: smask.subtype, backdrop: backdrop});
  27257. ctx.setTransform(1, 0, 0, 1, 0, 0);
  27258. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  27259. return;
  27260. }
  27261. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  27262. smask.subtype, backdrop, smask.transferMap);
  27263. ctx.drawImage(mask, 0, 0);
  27264. }
  27265. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  27266. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  27267. var NORMAL_CLIP = {};
  27268. var EO_CLIP = {};
  27269. CanvasGraphics.prototype = {
  27270. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  27271. transparency) {
  27272. // For pdfs that use blend modes we have to clear the canvas else certain
  27273. // blend modes can look wrong since we'd be blending with a white
  27274. // backdrop. The problem with a transparent backdrop though is we then
  27275. // don't get sub pixel anti aliasing on text, creating temporary
  27276. // transparent canvas when we have blend modes.
  27277. var width = this.ctx.canvas.width;
  27278. var height = this.ctx.canvas.height;
  27279. this.ctx.save();
  27280. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  27281. this.ctx.fillRect(0, 0, width, height);
  27282. this.ctx.restore();
  27283. if (transparency) {
  27284. var transparentCanvas = this.cachedCanvases.getCanvas(
  27285. 'transparent', width, height, true);
  27286. this.compositeCtx = this.ctx;
  27287. this.transparentCanvas = transparentCanvas.canvas;
  27288. this.ctx = transparentCanvas.context;
  27289. this.ctx.save();
  27290. // The transform can be applied before rendering, transferring it to
  27291. // the new canvas.
  27292. this.ctx.transform.apply(this.ctx,
  27293. this.compositeCtx.mozCurrentTransform);
  27294. }
  27295. this.ctx.save();
  27296. if (transform) {
  27297. this.ctx.transform.apply(this.ctx, transform);
  27298. }
  27299. this.ctx.transform.apply(this.ctx, viewport.transform);
  27300. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  27301. if (this.imageLayer) {
  27302. this.imageLayer.beginLayout();
  27303. }
  27304. },
  27305. executeOperatorList: function CanvasGraphics_executeOperatorList(
  27306. operatorList,
  27307. executionStartIdx, continueCallback,
  27308. stepper) {
  27309. var argsArray = operatorList.argsArray;
  27310. var fnArray = operatorList.fnArray;
  27311. var i = executionStartIdx || 0;
  27312. var argsArrayLen = argsArray.length;
  27313. // Sometimes the OperatorList to execute is empty.
  27314. if (argsArrayLen === i) {
  27315. return i;
  27316. }
  27317. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  27318. typeof continueCallback === 'function');
  27319. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  27320. var steps = 0;
  27321. var commonObjs = this.commonObjs;
  27322. var objs = this.objs;
  27323. var fnId;
  27324. while (true) {
  27325. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  27326. stepper.breakIt(i, continueCallback);
  27327. return i;
  27328. }
  27329. fnId = fnArray[i];
  27330. if (fnId !== OPS.dependency) {
  27331. this[fnId].apply(this, argsArray[i]);
  27332. } else {
  27333. var deps = argsArray[i];
  27334. for (var n = 0, nn = deps.length; n < nn; n++) {
  27335. var depObjId = deps[n];
  27336. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  27337. var objsPool = common ? commonObjs : objs;
  27338. // If the promise isn't resolved yet, add the continueCallback
  27339. // to the promise and bail out.
  27340. if (!objsPool.isResolved(depObjId)) {
  27341. objsPool.get(depObjId, continueCallback);
  27342. return i;
  27343. }
  27344. }
  27345. }
  27346. i++;
  27347. // If the entire operatorList was executed, stop as were done.
  27348. if (i === argsArrayLen) {
  27349. return i;
  27350. }
  27351. // If the execution took longer then a certain amount of time and
  27352. // `continueCallback` is specified, interrupt the execution.
  27353. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  27354. if (Date.now() > endTime) {
  27355. continueCallback();
  27356. return i;
  27357. }
  27358. steps = 0;
  27359. }
  27360. // If the operatorList isn't executed completely yet OR the execution
  27361. // time was short enough, do another execution round.
  27362. }
  27363. },
  27364. endDrawing: function CanvasGraphics_endDrawing() {
  27365. this.ctx.restore();
  27366. if (this.transparentCanvas) {
  27367. this.ctx = this.compositeCtx;
  27368. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  27369. this.transparentCanvas = null;
  27370. }
  27371. this.cachedCanvases.clear();
  27372. WebGLUtils.clear();
  27373. if (this.imageLayer) {
  27374. this.imageLayer.endLayout();
  27375. }
  27376. },
  27377. // Graphics state
  27378. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  27379. this.current.lineWidth = width;
  27380. this.ctx.lineWidth = width;
  27381. },
  27382. setLineCap: function CanvasGraphics_setLineCap(style) {
  27383. this.ctx.lineCap = LINE_CAP_STYLES[style];
  27384. },
  27385. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  27386. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  27387. },
  27388. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  27389. this.ctx.miterLimit = limit;
  27390. },
  27391. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  27392. var ctx = this.ctx;
  27393. if (ctx.setLineDash !== undefined) {
  27394. ctx.setLineDash(dashArray);
  27395. ctx.lineDashOffset = dashPhase;
  27396. } else {
  27397. ctx.mozDash = dashArray;
  27398. ctx.mozDashOffset = dashPhase;
  27399. }
  27400. },
  27401. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  27402. // Maybe if we one day fully support color spaces this will be important
  27403. // for now we can ignore.
  27404. // TODO set rendering intent?
  27405. },
  27406. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  27407. // There's no way to control this with canvas, but we can safely ignore.
  27408. // TODO set flatness?
  27409. },
  27410. setGState: function CanvasGraphics_setGState(states) {
  27411. for (var i = 0, ii = states.length; i < ii; i++) {
  27412. var state = states[i];
  27413. var key = state[0];
  27414. var value = state[1];
  27415. switch (key) {
  27416. case 'LW':
  27417. this.setLineWidth(value);
  27418. break;
  27419. case 'LC':
  27420. this.setLineCap(value);
  27421. break;
  27422. case 'LJ':
  27423. this.setLineJoin(value);
  27424. break;
  27425. case 'ML':
  27426. this.setMiterLimit(value);
  27427. break;
  27428. case 'D':
  27429. this.setDash(value[0], value[1]);
  27430. break;
  27431. case 'RI':
  27432. this.setRenderingIntent(value);
  27433. break;
  27434. case 'FL':
  27435. this.setFlatness(value);
  27436. break;
  27437. case 'Font':
  27438. this.setFont(value[0], value[1]);
  27439. break;
  27440. case 'CA':
  27441. this.current.strokeAlpha = state[1];
  27442. break;
  27443. case 'ca':
  27444. this.current.fillAlpha = state[1];
  27445. this.ctx.globalAlpha = state[1];
  27446. break;
  27447. case 'BM':
  27448. if (value && value.name && (value.name !== 'Normal')) {
  27449. var mode = value.name.replace(/([A-Z])/g,
  27450. function(c) {
  27451. return '-' + c.toLowerCase();
  27452. }
  27453. ).substring(1);
  27454. this.ctx.globalCompositeOperation = mode;
  27455. if (this.ctx.globalCompositeOperation !== mode) {
  27456. warn('globalCompositeOperation "' + mode +
  27457. '" is not supported');
  27458. }
  27459. } else {
  27460. this.ctx.globalCompositeOperation = 'source-over';
  27461. }
  27462. break;
  27463. case 'SMask':
  27464. if (this.current.activeSMask) {
  27465. this.endSMaskGroup();
  27466. }
  27467. this.current.activeSMask = value ? this.tempSMask : null;
  27468. if (this.current.activeSMask) {
  27469. this.beginSMaskGroup();
  27470. }
  27471. this.tempSMask = null;
  27472. break;
  27473. }
  27474. }
  27475. },
  27476. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  27477. var activeSMask = this.current.activeSMask;
  27478. var drawnWidth = activeSMask.canvas.width;
  27479. var drawnHeight = activeSMask.canvas.height;
  27480. var cacheId = 'smaskGroupAt' + this.groupLevel;
  27481. var scratchCanvas = this.cachedCanvases.getCanvas(
  27482. cacheId, drawnWidth, drawnHeight, true);
  27483. var currentCtx = this.ctx;
  27484. var currentTransform = currentCtx.mozCurrentTransform;
  27485. this.ctx.save();
  27486. var groupCtx = scratchCanvas.context;
  27487. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  27488. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  27489. groupCtx.transform.apply(groupCtx, currentTransform);
  27490. copyCtxState(currentCtx, groupCtx);
  27491. this.ctx = groupCtx;
  27492. this.setGState([
  27493. ['BM', 'Normal'],
  27494. ['ca', 1],
  27495. ['CA', 1]
  27496. ]);
  27497. this.groupStack.push(currentCtx);
  27498. this.groupLevel++;
  27499. },
  27500. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  27501. var groupCtx = this.ctx;
  27502. this.groupLevel--;
  27503. this.ctx = this.groupStack.pop();
  27504. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  27505. this.ctx.restore();
  27506. copyCtxState(groupCtx, this.ctx);
  27507. },
  27508. save: function CanvasGraphics_save() {
  27509. this.ctx.save();
  27510. var old = this.current;
  27511. this.stateStack.push(old);
  27512. this.current = old.clone();
  27513. this.current.activeSMask = null;
  27514. },
  27515. restore: function CanvasGraphics_restore() {
  27516. if (this.stateStack.length !== 0) {
  27517. if (this.current.activeSMask !== null) {
  27518. this.endSMaskGroup();
  27519. }
  27520. this.current = this.stateStack.pop();
  27521. this.ctx.restore();
  27522. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  27523. this.pendingClip = null;
  27524. this.cachedGetSinglePixelWidth = null;
  27525. }
  27526. },
  27527. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  27528. this.ctx.transform(a, b, c, d, e, f);
  27529. this.cachedGetSinglePixelWidth = null;
  27530. },
  27531. // Path
  27532. constructPath: function CanvasGraphics_constructPath(ops, args) {
  27533. var ctx = this.ctx;
  27534. var current = this.current;
  27535. var x = current.x, y = current.y;
  27536. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  27537. switch (ops[i] | 0) {
  27538. case OPS.rectangle:
  27539. x = args[j++];
  27540. y = args[j++];
  27541. var width = args[j++];
  27542. var height = args[j++];
  27543. if (width === 0) {
  27544. width = this.getSinglePixelWidth();
  27545. }
  27546. if (height === 0) {
  27547. height = this.getSinglePixelWidth();
  27548. }
  27549. var xw = x + width;
  27550. var yh = y + height;
  27551. this.ctx.moveTo(x, y);
  27552. this.ctx.lineTo(xw, y);
  27553. this.ctx.lineTo(xw, yh);
  27554. this.ctx.lineTo(x, yh);
  27555. this.ctx.lineTo(x, y);
  27556. this.ctx.closePath();
  27557. break;
  27558. case OPS.moveTo:
  27559. x = args[j++];
  27560. y = args[j++];
  27561. ctx.moveTo(x, y);
  27562. break;
  27563. case OPS.lineTo:
  27564. x = args[j++];
  27565. y = args[j++];
  27566. ctx.lineTo(x, y);
  27567. break;
  27568. case OPS.curveTo:
  27569. x = args[j + 4];
  27570. y = args[j + 5];
  27571. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  27572. x, y);
  27573. j += 6;
  27574. break;
  27575. case OPS.curveTo2:
  27576. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  27577. args[j + 2], args[j + 3]);
  27578. x = args[j + 2];
  27579. y = args[j + 3];
  27580. j += 4;
  27581. break;
  27582. case OPS.curveTo3:
  27583. x = args[j + 2];
  27584. y = args[j + 3];
  27585. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  27586. j += 4;
  27587. break;
  27588. case OPS.closePath:
  27589. ctx.closePath();
  27590. break;
  27591. }
  27592. }
  27593. current.setCurrentPoint(x, y);
  27594. },
  27595. closePath: function CanvasGraphics_closePath() {
  27596. this.ctx.closePath();
  27597. },
  27598. stroke: function CanvasGraphics_stroke(consumePath) {
  27599. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  27600. var ctx = this.ctx;
  27601. var strokeColor = this.current.strokeColor;
  27602. // Prevent drawing too thin lines by enforcing a minimum line width.
  27603. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  27604. this.current.lineWidth);
  27605. // For stroke we want to temporarily change the global alpha to the
  27606. // stroking alpha.
  27607. ctx.globalAlpha = this.current.strokeAlpha;
  27608. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  27609. strokeColor.type === 'Pattern') {
  27610. // for patterns, we transform to pattern space, calculate
  27611. // the pattern, call stroke, and restore to user space
  27612. ctx.save();
  27613. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  27614. ctx.stroke();
  27615. ctx.restore();
  27616. } else {
  27617. ctx.stroke();
  27618. }
  27619. if (consumePath) {
  27620. this.consumePath();
  27621. }
  27622. // Restore the global alpha to the fill alpha
  27623. ctx.globalAlpha = this.current.fillAlpha;
  27624. },
  27625. closeStroke: function CanvasGraphics_closeStroke() {
  27626. this.closePath();
  27627. this.stroke();
  27628. },
  27629. fill: function CanvasGraphics_fill(consumePath) {
  27630. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  27631. var ctx = this.ctx;
  27632. var fillColor = this.current.fillColor;
  27633. var isPatternFill = this.current.patternFill;
  27634. var needRestore = false;
  27635. if (isPatternFill) {
  27636. ctx.save();
  27637. if (this.baseTransform) {
  27638. ctx.setTransform.apply(ctx, this.baseTransform);
  27639. }
  27640. ctx.fillStyle = fillColor.getPattern(ctx, this);
  27641. needRestore = true;
  27642. }
  27643. if (this.pendingEOFill) {
  27644. if (ctx.mozFillRule !== undefined) {
  27645. ctx.mozFillRule = 'evenodd';
  27646. ctx.fill();
  27647. ctx.mozFillRule = 'nonzero';
  27648. } else {
  27649. ctx.fill('evenodd');
  27650. }
  27651. this.pendingEOFill = false;
  27652. } else {
  27653. ctx.fill();
  27654. }
  27655. if (needRestore) {
  27656. ctx.restore();
  27657. }
  27658. if (consumePath) {
  27659. this.consumePath();
  27660. }
  27661. },
  27662. eoFill: function CanvasGraphics_eoFill() {
  27663. this.pendingEOFill = true;
  27664. this.fill();
  27665. },
  27666. fillStroke: function CanvasGraphics_fillStroke() {
  27667. this.fill(false);
  27668. this.stroke(false);
  27669. this.consumePath();
  27670. },
  27671. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  27672. this.pendingEOFill = true;
  27673. this.fillStroke();
  27674. },
  27675. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  27676. this.closePath();
  27677. this.fillStroke();
  27678. },
  27679. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  27680. this.pendingEOFill = true;
  27681. this.closePath();
  27682. this.fillStroke();
  27683. },
  27684. endPath: function CanvasGraphics_endPath() {
  27685. this.consumePath();
  27686. },
  27687. // Clipping
  27688. clip: function CanvasGraphics_clip() {
  27689. this.pendingClip = NORMAL_CLIP;
  27690. },
  27691. eoClip: function CanvasGraphics_eoClip() {
  27692. this.pendingClip = EO_CLIP;
  27693. },
  27694. // Text
  27695. beginText: function CanvasGraphics_beginText() {
  27696. this.current.textMatrix = IDENTITY_MATRIX;
  27697. this.current.textMatrixScale = 1;
  27698. this.current.x = this.current.lineX = 0;
  27699. this.current.y = this.current.lineY = 0;
  27700. },
  27701. endText: function CanvasGraphics_endText() {
  27702. var paths = this.pendingTextPaths;
  27703. var ctx = this.ctx;
  27704. if (paths === undefined) {
  27705. ctx.beginPath();
  27706. return;
  27707. }
  27708. ctx.save();
  27709. ctx.beginPath();
  27710. for (var i = 0; i < paths.length; i++) {
  27711. var path = paths[i];
  27712. ctx.setTransform.apply(ctx, path.transform);
  27713. ctx.translate(path.x, path.y);
  27714. path.addToPath(ctx, path.fontSize);
  27715. }
  27716. ctx.restore();
  27717. ctx.clip();
  27718. ctx.beginPath();
  27719. delete this.pendingTextPaths;
  27720. },
  27721. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  27722. this.current.charSpacing = spacing;
  27723. },
  27724. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  27725. this.current.wordSpacing = spacing;
  27726. },
  27727. setHScale: function CanvasGraphics_setHScale(scale) {
  27728. this.current.textHScale = scale / 100;
  27729. },
  27730. setLeading: function CanvasGraphics_setLeading(leading) {
  27731. this.current.leading = -leading;
  27732. },
  27733. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  27734. var fontObj = this.commonObjs.get(fontRefName);
  27735. var current = this.current;
  27736. if (!fontObj) {
  27737. error('Can\'t find font for ' + fontRefName);
  27738. }
  27739. current.fontMatrix = (fontObj.fontMatrix ?
  27740. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  27741. // A valid matrix needs all main diagonal elements to be non-zero
  27742. // This also ensures we bypass FF bugzilla bug #719844.
  27743. if (current.fontMatrix[0] === 0 ||
  27744. current.fontMatrix[3] === 0) {
  27745. warn('Invalid font matrix for font ' + fontRefName);
  27746. }
  27747. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  27748. // and in some docs this can be negative (inverted x-y axes).
  27749. if (size < 0) {
  27750. size = -size;
  27751. current.fontDirection = -1;
  27752. } else {
  27753. current.fontDirection = 1;
  27754. }
  27755. this.current.font = fontObj;
  27756. this.current.fontSize = size;
  27757. if (fontObj.isType3Font) {
  27758. return; // we don't need ctx.font for Type3 fonts
  27759. }
  27760. var name = fontObj.loadedName || 'sans-serif';
  27761. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  27762. (fontObj.bold ? 'bold' : 'normal');
  27763. var italic = fontObj.italic ? 'italic' : 'normal';
  27764. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  27765. // Some font backends cannot handle fonts below certain size.
  27766. // Keeping the font at minimal size and using the fontSizeScale to change
  27767. // the current transformation matrix before the fillText/strokeText.
  27768. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  27769. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  27770. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  27771. this.current.fontSizeScale = size / browserFontSize;
  27772. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  27773. this.ctx.font = rule;
  27774. },
  27775. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  27776. this.current.textRenderingMode = mode;
  27777. },
  27778. setTextRise: function CanvasGraphics_setTextRise(rise) {
  27779. this.current.textRise = rise;
  27780. },
  27781. moveText: function CanvasGraphics_moveText(x, y) {
  27782. this.current.x = this.current.lineX += x;
  27783. this.current.y = this.current.lineY += y;
  27784. },
  27785. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  27786. this.setLeading(-y);
  27787. this.moveText(x, y);
  27788. },
  27789. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  27790. this.current.textMatrix = [a, b, c, d, e, f];
  27791. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  27792. this.current.x = this.current.lineX = 0;
  27793. this.current.y = this.current.lineY = 0;
  27794. },
  27795. nextLine: function CanvasGraphics_nextLine() {
  27796. this.moveText(0, this.current.leading);
  27797. },
  27798. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  27799. var ctx = this.ctx;
  27800. var current = this.current;
  27801. var font = current.font;
  27802. var textRenderingMode = current.textRenderingMode;
  27803. var fontSize = current.fontSize / current.fontSizeScale;
  27804. var fillStrokeMode = textRenderingMode &
  27805. TextRenderingMode.FILL_STROKE_MASK;
  27806. var isAddToPathSet = !!(textRenderingMode &
  27807. TextRenderingMode.ADD_TO_PATH_FLAG);
  27808. var addToPath;
  27809. if (font.disableFontFace || isAddToPathSet) {
  27810. addToPath = font.getPathGenerator(this.commonObjs, character);
  27811. }
  27812. if (font.disableFontFace) {
  27813. ctx.save();
  27814. ctx.translate(x, y);
  27815. ctx.beginPath();
  27816. addToPath(ctx, fontSize);
  27817. if (fillStrokeMode === TextRenderingMode.FILL ||
  27818. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27819. ctx.fill();
  27820. }
  27821. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27822. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27823. ctx.stroke();
  27824. }
  27825. ctx.restore();
  27826. } else {
  27827. if (fillStrokeMode === TextRenderingMode.FILL ||
  27828. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27829. ctx.fillText(character, x, y);
  27830. }
  27831. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27832. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27833. ctx.strokeText(character, x, y);
  27834. }
  27835. }
  27836. if (isAddToPathSet) {
  27837. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  27838. paths.push({
  27839. transform: ctx.mozCurrentTransform,
  27840. x: x,
  27841. y: y,
  27842. fontSize: fontSize,
  27843. addToPath: addToPath
  27844. });
  27845. }
  27846. },
  27847. get isFontSubpixelAAEnabled() {
  27848. // Checks if anti-aliasing is enabled when scaled text is painted.
  27849. // On Windows GDI scaled fonts looks bad.
  27850. var ctx = document.createElement('canvas').getContext('2d');
  27851. ctx.scale(1.5, 1);
  27852. ctx.fillText('I', 0, 10);
  27853. var data = ctx.getImageData(0, 0, 10, 10).data;
  27854. var enabled = false;
  27855. for (var i = 3; i < data.length; i += 4) {
  27856. if (data[i] > 0 && data[i] < 255) {
  27857. enabled = true;
  27858. break;
  27859. }
  27860. }
  27861. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  27862. },
  27863. showText: function CanvasGraphics_showText(glyphs) {
  27864. var current = this.current;
  27865. var font = current.font;
  27866. if (font.isType3Font) {
  27867. return this.showType3Text(glyphs);
  27868. }
  27869. var fontSize = current.fontSize;
  27870. if (fontSize === 0) {
  27871. return;
  27872. }
  27873. var ctx = this.ctx;
  27874. var fontSizeScale = current.fontSizeScale;
  27875. var charSpacing = current.charSpacing;
  27876. var wordSpacing = current.wordSpacing;
  27877. var fontDirection = current.fontDirection;
  27878. var textHScale = current.textHScale * fontDirection;
  27879. var glyphsLength = glyphs.length;
  27880. var vertical = font.vertical;
  27881. var spacingDir = vertical ? 1 : -1;
  27882. var defaultVMetrics = font.defaultVMetrics;
  27883. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  27884. var simpleFillText =
  27885. current.textRenderingMode === TextRenderingMode.FILL &&
  27886. !font.disableFontFace;
  27887. ctx.save();
  27888. ctx.transform.apply(ctx, current.textMatrix);
  27889. ctx.translate(current.x, current.y + current.textRise);
  27890. if (current.patternFill) {
  27891. // TODO: Some shading patterns are not applied correctly to text,
  27892. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  27893. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  27894. }
  27895. if (fontDirection > 0) {
  27896. ctx.scale(textHScale, -1);
  27897. } else {
  27898. ctx.scale(textHScale, 1);
  27899. }
  27900. var lineWidth = current.lineWidth;
  27901. var scale = current.textMatrixScale;
  27902. if (scale === 0 || lineWidth === 0) {
  27903. var fillStrokeMode = current.textRenderingMode &
  27904. TextRenderingMode.FILL_STROKE_MASK;
  27905. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27906. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27907. this.cachedGetSinglePixelWidth = null;
  27908. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  27909. }
  27910. } else {
  27911. lineWidth /= scale;
  27912. }
  27913. if (fontSizeScale !== 1.0) {
  27914. ctx.scale(fontSizeScale, fontSizeScale);
  27915. lineWidth /= fontSizeScale;
  27916. }
  27917. ctx.lineWidth = lineWidth;
  27918. var x = 0, i;
  27919. for (i = 0; i < glyphsLength; ++i) {
  27920. var glyph = glyphs[i];
  27921. if (isNum(glyph)) {
  27922. x += spacingDir * glyph * fontSize / 1000;
  27923. continue;
  27924. }
  27925. var restoreNeeded = false;
  27926. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  27927. var character = glyph.fontChar;
  27928. var accent = glyph.accent;
  27929. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  27930. var width = glyph.width;
  27931. if (vertical) {
  27932. var vmetric, vx, vy;
  27933. vmetric = glyph.vmetric || defaultVMetrics;
  27934. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  27935. vx = -vx * widthAdvanceScale;
  27936. vy = vmetric[2] * widthAdvanceScale;
  27937. width = vmetric ? -vmetric[0] : width;
  27938. scaledX = vx / fontSizeScale;
  27939. scaledY = (x + vy) / fontSizeScale;
  27940. } else {
  27941. scaledX = x / fontSizeScale;
  27942. scaledY = 0;
  27943. }
  27944. if (font.remeasure && width > 0) {
  27945. // Some standard fonts may not have the exact width: rescale per
  27946. // character if measured width is greater than expected glyph width
  27947. // and subpixel-aa is enabled, otherwise just center the glyph.
  27948. var measuredWidth = ctx.measureText(character).width * 1000 /
  27949. fontSize * fontSizeScale;
  27950. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  27951. var characterScaleX = width / measuredWidth;
  27952. restoreNeeded = true;
  27953. ctx.save();
  27954. ctx.scale(characterScaleX, 1);
  27955. scaledX /= characterScaleX;
  27956. } else if (width !== measuredWidth) {
  27957. scaledX += (width - measuredWidth) / 2000 *
  27958. fontSize / fontSizeScale;
  27959. }
  27960. }
  27961. if (simpleFillText && !accent) {
  27962. // common case
  27963. ctx.fillText(character, scaledX, scaledY);
  27964. } else {
  27965. this.paintChar(character, scaledX, scaledY);
  27966. if (accent) {
  27967. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  27968. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  27969. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  27970. }
  27971. }
  27972. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  27973. x += charWidth;
  27974. if (restoreNeeded) {
  27975. ctx.restore();
  27976. }
  27977. }
  27978. if (vertical) {
  27979. current.y -= x * textHScale;
  27980. } else {
  27981. current.x += x * textHScale;
  27982. }
  27983. ctx.restore();
  27984. },
  27985. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  27986. // Type3 fonts - each glyph is a "mini-PDF"
  27987. var ctx = this.ctx;
  27988. var current = this.current;
  27989. var font = current.font;
  27990. var fontSize = current.fontSize;
  27991. var fontDirection = current.fontDirection;
  27992. var spacingDir = font.vertical ? 1 : -1;
  27993. var charSpacing = current.charSpacing;
  27994. var wordSpacing = current.wordSpacing;
  27995. var textHScale = current.textHScale * fontDirection;
  27996. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  27997. var glyphsLength = glyphs.length;
  27998. var isTextInvisible =
  27999. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  28000. var i, glyph, width, spacingLength;
  28001. if (isTextInvisible || fontSize === 0) {
  28002. return;
  28003. }
  28004. this.cachedGetSinglePixelWidth = null;
  28005. ctx.save();
  28006. ctx.transform.apply(ctx, current.textMatrix);
  28007. ctx.translate(current.x, current.y);
  28008. ctx.scale(textHScale, fontDirection);
  28009. for (i = 0; i < glyphsLength; ++i) {
  28010. glyph = glyphs[i];
  28011. if (isNum(glyph)) {
  28012. spacingLength = spacingDir * glyph * fontSize / 1000;
  28013. this.ctx.translate(spacingLength, 0);
  28014. current.x += spacingLength * textHScale;
  28015. continue;
  28016. }
  28017. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  28018. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  28019. if (!operatorList) {
  28020. warn('Type3 character \"' + glyph.operatorListId +
  28021. '\" is not available');
  28022. continue;
  28023. }
  28024. this.processingType3 = glyph;
  28025. this.save();
  28026. ctx.scale(fontSize, fontSize);
  28027. ctx.transform.apply(ctx, fontMatrix);
  28028. this.executeOperatorList(operatorList);
  28029. this.restore();
  28030. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  28031. width = transformed[0] * fontSize + spacing;
  28032. ctx.translate(width, 0);
  28033. current.x += width * textHScale;
  28034. }
  28035. ctx.restore();
  28036. this.processingType3 = null;
  28037. },
  28038. // Type3 fonts
  28039. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  28040. // We can safely ignore this since the width should be the same
  28041. // as the width in the Widths array.
  28042. },
  28043. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  28044. yWidth,
  28045. llx,
  28046. lly,
  28047. urx,
  28048. ury) {
  28049. // TODO According to the spec we're also suppose to ignore any operators
  28050. // that set color or include images while processing this type3 font.
  28051. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  28052. this.clip();
  28053. this.endPath();
  28054. },
  28055. // Color
  28056. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  28057. var pattern;
  28058. if (IR[0] === 'TilingPattern') {
  28059. var color = IR[1];
  28060. var baseTransform = this.baseTransform ||
  28061. this.ctx.mozCurrentTransform.slice();
  28062. var self = this;
  28063. var canvasGraphicsFactory = {
  28064. createCanvasGraphics: function (ctx) {
  28065. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  28066. }
  28067. };
  28068. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  28069. baseTransform);
  28070. } else {
  28071. pattern = getShadingPatternFromIR(IR);
  28072. }
  28073. return pattern;
  28074. },
  28075. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  28076. this.current.strokeColor = this.getColorN_Pattern(arguments);
  28077. },
  28078. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  28079. this.current.fillColor = this.getColorN_Pattern(arguments);
  28080. this.current.patternFill = true;
  28081. },
  28082. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  28083. var color = Util.makeCssRgb(r, g, b);
  28084. this.ctx.strokeStyle = color;
  28085. this.current.strokeColor = color;
  28086. },
  28087. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  28088. var color = Util.makeCssRgb(r, g, b);
  28089. this.ctx.fillStyle = color;
  28090. this.current.fillColor = color;
  28091. this.current.patternFill = false;
  28092. },
  28093. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  28094. var ctx = this.ctx;
  28095. this.save();
  28096. var pattern = getShadingPatternFromIR(patternIR);
  28097. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  28098. var inv = ctx.mozCurrentTransformInverse;
  28099. if (inv) {
  28100. var canvas = ctx.canvas;
  28101. var width = canvas.width;
  28102. var height = canvas.height;
  28103. var bl = Util.applyTransform([0, 0], inv);
  28104. var br = Util.applyTransform([0, height], inv);
  28105. var ul = Util.applyTransform([width, 0], inv);
  28106. var ur = Util.applyTransform([width, height], inv);
  28107. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  28108. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  28109. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  28110. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  28111. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  28112. } else {
  28113. // HACK to draw the gradient onto an infinite rectangle.
  28114. // PDF gradients are drawn across the entire image while
  28115. // Canvas only allows gradients to be drawn in a rectangle
  28116. // The following bug should allow us to remove this.
  28117. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  28118. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  28119. }
  28120. this.restore();
  28121. },
  28122. // Images
  28123. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  28124. error('Should not call beginInlineImage');
  28125. },
  28126. beginImageData: function CanvasGraphics_beginImageData() {
  28127. error('Should not call beginImageData');
  28128. },
  28129. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  28130. bbox) {
  28131. this.save();
  28132. this.baseTransformStack.push(this.baseTransform);
  28133. if (isArray(matrix) && 6 === matrix.length) {
  28134. this.transform.apply(this, matrix);
  28135. }
  28136. this.baseTransform = this.ctx.mozCurrentTransform;
  28137. if (isArray(bbox) && 4 === bbox.length) {
  28138. var width = bbox[2] - bbox[0];
  28139. var height = bbox[3] - bbox[1];
  28140. this.ctx.rect(bbox[0], bbox[1], width, height);
  28141. this.clip();
  28142. this.endPath();
  28143. }
  28144. },
  28145. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  28146. this.restore();
  28147. this.baseTransform = this.baseTransformStack.pop();
  28148. },
  28149. beginGroup: function CanvasGraphics_beginGroup(group) {
  28150. this.save();
  28151. var currentCtx = this.ctx;
  28152. // TODO non-isolated groups - according to Rik at adobe non-isolated
  28153. // group results aren't usually that different and they even have tools
  28154. // that ignore this setting. Notes from Rik on implmenting:
  28155. // - When you encounter an transparency group, create a new canvas with
  28156. // the dimensions of the bbox
  28157. // - copy the content from the previous canvas to the new canvas
  28158. // - draw as usual
  28159. // - remove the backdrop alpha:
  28160. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  28161. // value of your transparency group and 'alphaBackdrop' the alpha of the
  28162. // backdrop
  28163. // - remove background color:
  28164. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  28165. if (!group.isolated) {
  28166. info('TODO: Support non-isolated groups.');
  28167. }
  28168. // TODO knockout - supposedly possible with the clever use of compositing
  28169. // modes.
  28170. if (group.knockout) {
  28171. warn('Knockout groups not supported.');
  28172. }
  28173. var currentTransform = currentCtx.mozCurrentTransform;
  28174. if (group.matrix) {
  28175. currentCtx.transform.apply(currentCtx, group.matrix);
  28176. }
  28177. assert(group.bbox, 'Bounding box is required.');
  28178. // Based on the current transform figure out how big the bounding box
  28179. // will actually be.
  28180. var bounds = Util.getAxialAlignedBoundingBox(
  28181. group.bbox,
  28182. currentCtx.mozCurrentTransform);
  28183. // Clip the bounding box to the current canvas.
  28184. var canvasBounds = [0,
  28185. 0,
  28186. currentCtx.canvas.width,
  28187. currentCtx.canvas.height];
  28188. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  28189. // Use ceil in case we're between sizes so we don't create canvas that is
  28190. // too small and make the canvas at least 1x1 pixels.
  28191. var offsetX = Math.floor(bounds[0]);
  28192. var offsetY = Math.floor(bounds[1]);
  28193. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  28194. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  28195. var scaleX = 1, scaleY = 1;
  28196. if (drawnWidth > MAX_GROUP_SIZE) {
  28197. scaleX = drawnWidth / MAX_GROUP_SIZE;
  28198. drawnWidth = MAX_GROUP_SIZE;
  28199. }
  28200. if (drawnHeight > MAX_GROUP_SIZE) {
  28201. scaleY = drawnHeight / MAX_GROUP_SIZE;
  28202. drawnHeight = MAX_GROUP_SIZE;
  28203. }
  28204. var cacheId = 'groupAt' + this.groupLevel;
  28205. if (group.smask) {
  28206. // Using two cache entries is case if masks are used one after another.
  28207. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  28208. }
  28209. var scratchCanvas = this.cachedCanvases.getCanvas(
  28210. cacheId, drawnWidth, drawnHeight, true);
  28211. var groupCtx = scratchCanvas.context;
  28212. // Since we created a new canvas that is just the size of the bounding box
  28213. // we have to translate the group ctx.
  28214. groupCtx.scale(1 / scaleX, 1 / scaleY);
  28215. groupCtx.translate(-offsetX, -offsetY);
  28216. groupCtx.transform.apply(groupCtx, currentTransform);
  28217. if (group.smask) {
  28218. // Saving state and cached mask to be used in setGState.
  28219. this.smaskStack.push({
  28220. canvas: scratchCanvas.canvas,
  28221. context: groupCtx,
  28222. offsetX: offsetX,
  28223. offsetY: offsetY,
  28224. scaleX: scaleX,
  28225. scaleY: scaleY,
  28226. subtype: group.smask.subtype,
  28227. backdrop: group.smask.backdrop,
  28228. transferMap: group.smask.transferMap || null
  28229. });
  28230. } else {
  28231. // Setup the current ctx so when the group is popped we draw it at the
  28232. // right location.
  28233. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  28234. currentCtx.translate(offsetX, offsetY);
  28235. currentCtx.scale(scaleX, scaleY);
  28236. }
  28237. // The transparency group inherits all off the current graphics state
  28238. // except the blend mode, soft mask, and alpha constants.
  28239. copyCtxState(currentCtx, groupCtx);
  28240. this.ctx = groupCtx;
  28241. this.setGState([
  28242. ['BM', 'Normal'],
  28243. ['ca', 1],
  28244. ['CA', 1]
  28245. ]);
  28246. this.groupStack.push(currentCtx);
  28247. this.groupLevel++;
  28248. },
  28249. endGroup: function CanvasGraphics_endGroup(group) {
  28250. this.groupLevel--;
  28251. var groupCtx = this.ctx;
  28252. this.ctx = this.groupStack.pop();
  28253. // Turn off image smoothing to avoid sub pixel interpolation which can
  28254. // look kind of blurry for some pdfs.
  28255. if (this.ctx.imageSmoothingEnabled !== undefined) {
  28256. this.ctx.imageSmoothingEnabled = false;
  28257. } else {
  28258. this.ctx.mozImageSmoothingEnabled = false;
  28259. }
  28260. if (group.smask) {
  28261. this.tempSMask = this.smaskStack.pop();
  28262. } else {
  28263. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  28264. }
  28265. this.restore();
  28266. },
  28267. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  28268. this.save();
  28269. this.current = new CanvasExtraState();
  28270. if (this.baseTransform) {
  28271. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  28272. }
  28273. },
  28274. endAnnotations: function CanvasGraphics_endAnnotations() {
  28275. this.restore();
  28276. },
  28277. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  28278. matrix) {
  28279. this.save();
  28280. if (isArray(rect) && 4 === rect.length) {
  28281. var width = rect[2] - rect[0];
  28282. var height = rect[3] - rect[1];
  28283. this.ctx.rect(rect[0], rect[1], width, height);
  28284. this.clip();
  28285. this.endPath();
  28286. }
  28287. this.transform.apply(this, transform);
  28288. this.transform.apply(this, matrix);
  28289. },
  28290. endAnnotation: function CanvasGraphics_endAnnotation() {
  28291. this.restore();
  28292. },
  28293. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  28294. var domImage = this.objs.get(objId);
  28295. if (!domImage) {
  28296. warn('Dependent image isn\'t ready yet');
  28297. return;
  28298. }
  28299. this.save();
  28300. var ctx = this.ctx;
  28301. // scale the image to the unit square
  28302. ctx.scale(1 / w, -1 / h);
  28303. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  28304. 0, -h, w, h);
  28305. if (this.imageLayer) {
  28306. var currentTransform = ctx.mozCurrentTransformInverse;
  28307. var position = this.getCanvasPosition(0, 0);
  28308. this.imageLayer.appendImage({
  28309. objId: objId,
  28310. left: position[0],
  28311. top: position[1],
  28312. width: w / currentTransform[0],
  28313. height: h / currentTransform[3]
  28314. });
  28315. }
  28316. this.restore();
  28317. },
  28318. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  28319. var ctx = this.ctx;
  28320. var width = img.width, height = img.height;
  28321. var fillColor = this.current.fillColor;
  28322. var isPatternFill = this.current.patternFill;
  28323. var glyph = this.processingType3;
  28324. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  28325. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  28326. glyph.compiled =
  28327. compileType3Glyph({data: img.data, width: width, height: height});
  28328. } else {
  28329. glyph.compiled = null;
  28330. }
  28331. }
  28332. if (glyph && glyph.compiled) {
  28333. glyph.compiled(ctx);
  28334. return;
  28335. }
  28336. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28337. width, height);
  28338. var maskCtx = maskCanvas.context;
  28339. maskCtx.save();
  28340. putBinaryImageMask(maskCtx, img);
  28341. maskCtx.globalCompositeOperation = 'source-in';
  28342. maskCtx.fillStyle = isPatternFill ?
  28343. fillColor.getPattern(maskCtx, this) : fillColor;
  28344. maskCtx.fillRect(0, 0, width, height);
  28345. maskCtx.restore();
  28346. this.paintInlineImageXObject(maskCanvas.canvas);
  28347. },
  28348. paintImageMaskXObjectRepeat:
  28349. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  28350. scaleY, positions) {
  28351. var width = imgData.width;
  28352. var height = imgData.height;
  28353. var fillColor = this.current.fillColor;
  28354. var isPatternFill = this.current.patternFill;
  28355. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28356. width, height);
  28357. var maskCtx = maskCanvas.context;
  28358. maskCtx.save();
  28359. putBinaryImageMask(maskCtx, imgData);
  28360. maskCtx.globalCompositeOperation = 'source-in';
  28361. maskCtx.fillStyle = isPatternFill ?
  28362. fillColor.getPattern(maskCtx, this) : fillColor;
  28363. maskCtx.fillRect(0, 0, width, height);
  28364. maskCtx.restore();
  28365. var ctx = this.ctx;
  28366. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  28367. ctx.save();
  28368. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  28369. ctx.scale(1, -1);
  28370. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  28371. 0, -1, 1, 1);
  28372. ctx.restore();
  28373. }
  28374. },
  28375. paintImageMaskXObjectGroup:
  28376. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  28377. var ctx = this.ctx;
  28378. var fillColor = this.current.fillColor;
  28379. var isPatternFill = this.current.patternFill;
  28380. for (var i = 0, ii = images.length; i < ii; i++) {
  28381. var image = images[i];
  28382. var width = image.width, height = image.height;
  28383. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28384. width, height);
  28385. var maskCtx = maskCanvas.context;
  28386. maskCtx.save();
  28387. putBinaryImageMask(maskCtx, image);
  28388. maskCtx.globalCompositeOperation = 'source-in';
  28389. maskCtx.fillStyle = isPatternFill ?
  28390. fillColor.getPattern(maskCtx, this) : fillColor;
  28391. maskCtx.fillRect(0, 0, width, height);
  28392. maskCtx.restore();
  28393. ctx.save();
  28394. ctx.transform.apply(ctx, image.transform);
  28395. ctx.scale(1, -1);
  28396. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  28397. 0, -1, 1, 1);
  28398. ctx.restore();
  28399. }
  28400. },
  28401. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  28402. var imgData = this.objs.get(objId);
  28403. if (!imgData) {
  28404. warn('Dependent image isn\'t ready yet');
  28405. return;
  28406. }
  28407. this.paintInlineImageXObject(imgData);
  28408. },
  28409. paintImageXObjectRepeat:
  28410. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  28411. positions) {
  28412. var imgData = this.objs.get(objId);
  28413. if (!imgData) {
  28414. warn('Dependent image isn\'t ready yet');
  28415. return;
  28416. }
  28417. var width = imgData.width;
  28418. var height = imgData.height;
  28419. var map = [];
  28420. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  28421. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  28422. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  28423. }
  28424. this.paintInlineImageXObjectGroup(imgData, map);
  28425. },
  28426. paintInlineImageXObject:
  28427. function CanvasGraphics_paintInlineImageXObject(imgData) {
  28428. var width = imgData.width;
  28429. var height = imgData.height;
  28430. var ctx = this.ctx;
  28431. this.save();
  28432. // scale the image to the unit square
  28433. ctx.scale(1 / width, -1 / height);
  28434. var currentTransform = ctx.mozCurrentTransformInverse;
  28435. var a = currentTransform[0], b = currentTransform[1];
  28436. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  28437. var c = currentTransform[2], d = currentTransform[3];
  28438. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  28439. var imgToPaint, tmpCanvas;
  28440. // instanceof HTMLElement does not work in jsdom node.js module
  28441. if (imgData instanceof HTMLElement || !imgData.data) {
  28442. imgToPaint = imgData;
  28443. } else {
  28444. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  28445. width, height);
  28446. var tmpCtx = tmpCanvas.context;
  28447. putBinaryImageData(tmpCtx, imgData);
  28448. imgToPaint = tmpCanvas.canvas;
  28449. }
  28450. var paintWidth = width, paintHeight = height;
  28451. var tmpCanvasId = 'prescale1';
  28452. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  28453. // pixels during drawImage operation, painting on the temporary canvas(es)
  28454. // that are twice smaller in size
  28455. while ((widthScale > 2 && paintWidth > 1) ||
  28456. (heightScale > 2 && paintHeight > 1)) {
  28457. var newWidth = paintWidth, newHeight = paintHeight;
  28458. if (widthScale > 2 && paintWidth > 1) {
  28459. newWidth = Math.ceil(paintWidth / 2);
  28460. widthScale /= paintWidth / newWidth;
  28461. }
  28462. if (heightScale > 2 && paintHeight > 1) {
  28463. newHeight = Math.ceil(paintHeight / 2);
  28464. heightScale /= paintHeight / newHeight;
  28465. }
  28466. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  28467. newWidth, newHeight);
  28468. tmpCtx = tmpCanvas.context;
  28469. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  28470. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  28471. 0, 0, newWidth, newHeight);
  28472. imgToPaint = tmpCanvas.canvas;
  28473. paintWidth = newWidth;
  28474. paintHeight = newHeight;
  28475. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  28476. }
  28477. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  28478. 0, -height, width, height);
  28479. if (this.imageLayer) {
  28480. var position = this.getCanvasPosition(0, -height);
  28481. this.imageLayer.appendImage({
  28482. imgData: imgData,
  28483. left: position[0],
  28484. top: position[1],
  28485. width: width / currentTransform[0],
  28486. height: height / currentTransform[3]
  28487. });
  28488. }
  28489. this.restore();
  28490. },
  28491. paintInlineImageXObjectGroup:
  28492. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  28493. var ctx = this.ctx;
  28494. var w = imgData.width;
  28495. var h = imgData.height;
  28496. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  28497. var tmpCtx = tmpCanvas.context;
  28498. putBinaryImageData(tmpCtx, imgData);
  28499. for (var i = 0, ii = map.length; i < ii; i++) {
  28500. var entry = map[i];
  28501. ctx.save();
  28502. ctx.transform.apply(ctx, entry.transform);
  28503. ctx.scale(1, -1);
  28504. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  28505. 0, -1, 1, 1);
  28506. if (this.imageLayer) {
  28507. var position = this.getCanvasPosition(entry.x, entry.y);
  28508. this.imageLayer.appendImage({
  28509. imgData: imgData,
  28510. left: position[0],
  28511. top: position[1],
  28512. width: w,
  28513. height: h
  28514. });
  28515. }
  28516. ctx.restore();
  28517. }
  28518. },
  28519. paintSolidColorImageMask:
  28520. function CanvasGraphics_paintSolidColorImageMask() {
  28521. this.ctx.fillRect(0, 0, 1, 1);
  28522. },
  28523. paintXObject: function CanvasGraphics_paintXObject() {
  28524. warn('Unsupported \'paintXObject\' command.');
  28525. },
  28526. // Marked content
  28527. markPoint: function CanvasGraphics_markPoint(tag) {
  28528. // TODO Marked content.
  28529. },
  28530. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  28531. // TODO Marked content.
  28532. },
  28533. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  28534. // TODO Marked content.
  28535. },
  28536. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  28537. tag, properties) {
  28538. // TODO Marked content.
  28539. },
  28540. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  28541. // TODO Marked content.
  28542. },
  28543. // Compatibility
  28544. beginCompat: function CanvasGraphics_beginCompat() {
  28545. // TODO ignore undefined operators (should we do that anyway?)
  28546. },
  28547. endCompat: function CanvasGraphics_endCompat() {
  28548. // TODO stop ignoring undefined operators
  28549. },
  28550. // Helper functions
  28551. consumePath: function CanvasGraphics_consumePath() {
  28552. var ctx = this.ctx;
  28553. if (this.pendingClip) {
  28554. if (this.pendingClip === EO_CLIP) {
  28555. if (ctx.mozFillRule !== undefined) {
  28556. ctx.mozFillRule = 'evenodd';
  28557. ctx.clip();
  28558. ctx.mozFillRule = 'nonzero';
  28559. } else {
  28560. ctx.clip('evenodd');
  28561. }
  28562. } else {
  28563. ctx.clip();
  28564. }
  28565. this.pendingClip = null;
  28566. }
  28567. ctx.beginPath();
  28568. },
  28569. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  28570. if (this.cachedGetSinglePixelWidth === null) {
  28571. var inverse = this.ctx.mozCurrentTransformInverse;
  28572. // max of the current horizontal and vertical scale
  28573. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  28574. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  28575. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  28576. }
  28577. return this.cachedGetSinglePixelWidth;
  28578. },
  28579. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  28580. var transform = this.ctx.mozCurrentTransform;
  28581. return [
  28582. transform[0] * x + transform[2] * y + transform[4],
  28583. transform[1] * x + transform[3] * y + transform[5]
  28584. ];
  28585. }
  28586. };
  28587. for (var op in OPS) {
  28588. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  28589. }
  28590. return CanvasGraphics;
  28591. })();
  28592. exports.CanvasGraphics = CanvasGraphics;
  28593. exports.createScratchCanvas = createScratchCanvas;
  28594. }));
  28595. (function (root, factory) {
  28596. {
  28597. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  28598. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  28599. }
  28600. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  28601. var Util = sharedUtil.Util;
  28602. var assert = sharedUtil.assert;
  28603. var error = sharedUtil.error;
  28604. var isInt = sharedUtil.isInt;
  28605. var isString = sharedUtil.isString;
  28606. var warn = sharedUtil.warn;
  28607. var isName = corePrimitives.isName;
  28608. var isCmd = corePrimitives.isCmd;
  28609. var isStream = corePrimitives.isStream;
  28610. var StringStream = coreStream.StringStream;
  28611. var Lexer = coreParser.Lexer;
  28612. var isEOF = coreParser.isEOF;
  28613. var BUILT_IN_CMAPS = [
  28614. // << Start unicode maps.
  28615. 'Adobe-GB1-UCS2',
  28616. 'Adobe-CNS1-UCS2',
  28617. 'Adobe-Japan1-UCS2',
  28618. 'Adobe-Korea1-UCS2',
  28619. // >> End unicode maps.
  28620. '78-EUC-H',
  28621. '78-EUC-V',
  28622. '78-H',
  28623. '78-RKSJ-H',
  28624. '78-RKSJ-V',
  28625. '78-V',
  28626. '78ms-RKSJ-H',
  28627. '78ms-RKSJ-V',
  28628. '83pv-RKSJ-H',
  28629. '90ms-RKSJ-H',
  28630. '90ms-RKSJ-V',
  28631. '90msp-RKSJ-H',
  28632. '90msp-RKSJ-V',
  28633. '90pv-RKSJ-H',
  28634. '90pv-RKSJ-V',
  28635. 'Add-H',
  28636. 'Add-RKSJ-H',
  28637. 'Add-RKSJ-V',
  28638. 'Add-V',
  28639. 'Adobe-CNS1-0',
  28640. 'Adobe-CNS1-1',
  28641. 'Adobe-CNS1-2',
  28642. 'Adobe-CNS1-3',
  28643. 'Adobe-CNS1-4',
  28644. 'Adobe-CNS1-5',
  28645. 'Adobe-CNS1-6',
  28646. 'Adobe-GB1-0',
  28647. 'Adobe-GB1-1',
  28648. 'Adobe-GB1-2',
  28649. 'Adobe-GB1-3',
  28650. 'Adobe-GB1-4',
  28651. 'Adobe-GB1-5',
  28652. 'Adobe-Japan1-0',
  28653. 'Adobe-Japan1-1',
  28654. 'Adobe-Japan1-2',
  28655. 'Adobe-Japan1-3',
  28656. 'Adobe-Japan1-4',
  28657. 'Adobe-Japan1-5',
  28658. 'Adobe-Japan1-6',
  28659. 'Adobe-Korea1-0',
  28660. 'Adobe-Korea1-1',
  28661. 'Adobe-Korea1-2',
  28662. 'B5-H',
  28663. 'B5-V',
  28664. 'B5pc-H',
  28665. 'B5pc-V',
  28666. 'CNS-EUC-H',
  28667. 'CNS-EUC-V',
  28668. 'CNS1-H',
  28669. 'CNS1-V',
  28670. 'CNS2-H',
  28671. 'CNS2-V',
  28672. 'ETHK-B5-H',
  28673. 'ETHK-B5-V',
  28674. 'ETen-B5-H',
  28675. 'ETen-B5-V',
  28676. 'ETenms-B5-H',
  28677. 'ETenms-B5-V',
  28678. 'EUC-H',
  28679. 'EUC-V',
  28680. 'Ext-H',
  28681. 'Ext-RKSJ-H',
  28682. 'Ext-RKSJ-V',
  28683. 'Ext-V',
  28684. 'GB-EUC-H',
  28685. 'GB-EUC-V',
  28686. 'GB-H',
  28687. 'GB-V',
  28688. 'GBK-EUC-H',
  28689. 'GBK-EUC-V',
  28690. 'GBK2K-H',
  28691. 'GBK2K-V',
  28692. 'GBKp-EUC-H',
  28693. 'GBKp-EUC-V',
  28694. 'GBT-EUC-H',
  28695. 'GBT-EUC-V',
  28696. 'GBT-H',
  28697. 'GBT-V',
  28698. 'GBTpc-EUC-H',
  28699. 'GBTpc-EUC-V',
  28700. 'GBpc-EUC-H',
  28701. 'GBpc-EUC-V',
  28702. 'H',
  28703. 'HKdla-B5-H',
  28704. 'HKdla-B5-V',
  28705. 'HKdlb-B5-H',
  28706. 'HKdlb-B5-V',
  28707. 'HKgccs-B5-H',
  28708. 'HKgccs-B5-V',
  28709. 'HKm314-B5-H',
  28710. 'HKm314-B5-V',
  28711. 'HKm471-B5-H',
  28712. 'HKm471-B5-V',
  28713. 'HKscs-B5-H',
  28714. 'HKscs-B5-V',
  28715. 'Hankaku',
  28716. 'Hiragana',
  28717. 'KSC-EUC-H',
  28718. 'KSC-EUC-V',
  28719. 'KSC-H',
  28720. 'KSC-Johab-H',
  28721. 'KSC-Johab-V',
  28722. 'KSC-V',
  28723. 'KSCms-UHC-H',
  28724. 'KSCms-UHC-HW-H',
  28725. 'KSCms-UHC-HW-V',
  28726. 'KSCms-UHC-V',
  28727. 'KSCpc-EUC-H',
  28728. 'KSCpc-EUC-V',
  28729. 'Katakana',
  28730. 'NWP-H',
  28731. 'NWP-V',
  28732. 'RKSJ-H',
  28733. 'RKSJ-V',
  28734. 'Roman',
  28735. 'UniCNS-UCS2-H',
  28736. 'UniCNS-UCS2-V',
  28737. 'UniCNS-UTF16-H',
  28738. 'UniCNS-UTF16-V',
  28739. 'UniCNS-UTF32-H',
  28740. 'UniCNS-UTF32-V',
  28741. 'UniCNS-UTF8-H',
  28742. 'UniCNS-UTF8-V',
  28743. 'UniGB-UCS2-H',
  28744. 'UniGB-UCS2-V',
  28745. 'UniGB-UTF16-H',
  28746. 'UniGB-UTF16-V',
  28747. 'UniGB-UTF32-H',
  28748. 'UniGB-UTF32-V',
  28749. 'UniGB-UTF8-H',
  28750. 'UniGB-UTF8-V',
  28751. 'UniJIS-UCS2-H',
  28752. 'UniJIS-UCS2-HW-H',
  28753. 'UniJIS-UCS2-HW-V',
  28754. 'UniJIS-UCS2-V',
  28755. 'UniJIS-UTF16-H',
  28756. 'UniJIS-UTF16-V',
  28757. 'UniJIS-UTF32-H',
  28758. 'UniJIS-UTF32-V',
  28759. 'UniJIS-UTF8-H',
  28760. 'UniJIS-UTF8-V',
  28761. 'UniJIS2004-UTF16-H',
  28762. 'UniJIS2004-UTF16-V',
  28763. 'UniJIS2004-UTF32-H',
  28764. 'UniJIS2004-UTF32-V',
  28765. 'UniJIS2004-UTF8-H',
  28766. 'UniJIS2004-UTF8-V',
  28767. 'UniJISPro-UCS2-HW-V',
  28768. 'UniJISPro-UCS2-V',
  28769. 'UniJISPro-UTF8-V',
  28770. 'UniJISX0213-UTF32-H',
  28771. 'UniJISX0213-UTF32-V',
  28772. 'UniJISX02132004-UTF32-H',
  28773. 'UniJISX02132004-UTF32-V',
  28774. 'UniKS-UCS2-H',
  28775. 'UniKS-UCS2-V',
  28776. 'UniKS-UTF16-H',
  28777. 'UniKS-UTF16-V',
  28778. 'UniKS-UTF32-H',
  28779. 'UniKS-UTF32-V',
  28780. 'UniKS-UTF8-H',
  28781. 'UniKS-UTF8-V',
  28782. 'V',
  28783. 'WP-Symbol'];
  28784. // CMap, not to be confused with TrueType's cmap.
  28785. var CMap = (function CMapClosure() {
  28786. function CMap(builtInCMap) {
  28787. // Codespace ranges are stored as follows:
  28788. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  28789. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  28790. this.codespaceRanges = [[], [], [], []];
  28791. this.numCodespaceRanges = 0;
  28792. // Map entries have one of two forms.
  28793. // - cid chars are 16-bit unsigned integers, stored as integers.
  28794. // - bf chars are variable-length byte sequences, stored as strings, with
  28795. // one byte per character.
  28796. this._map = [];
  28797. this.name = '';
  28798. this.vertical = false;
  28799. this.useCMap = null;
  28800. this.builtInCMap = builtInCMap;
  28801. }
  28802. CMap.prototype = {
  28803. addCodespaceRange: function(n, low, high) {
  28804. this.codespaceRanges[n - 1].push(low, high);
  28805. this.numCodespaceRanges++;
  28806. },
  28807. mapCidRange: function(low, high, dstLow) {
  28808. while (low <= high) {
  28809. this._map[low++] = dstLow++;
  28810. }
  28811. },
  28812. mapBfRange: function(low, high, dstLow) {
  28813. var lastByte = dstLow.length - 1;
  28814. while (low <= high) {
  28815. this._map[low++] = dstLow;
  28816. // Only the last byte has to be incremented.
  28817. dstLow = dstLow.substr(0, lastByte) +
  28818. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  28819. }
  28820. },
  28821. mapBfRangeToArray: function(low, high, array) {
  28822. var i = 0, ii = array.length;
  28823. while (low <= high && i < ii) {
  28824. this._map[low] = array[i++];
  28825. ++low;
  28826. }
  28827. },
  28828. // This is used for both bf and cid chars.
  28829. mapOne: function(src, dst) {
  28830. this._map[src] = dst;
  28831. },
  28832. lookup: function(code) {
  28833. return this._map[code];
  28834. },
  28835. contains: function(code) {
  28836. return this._map[code] !== undefined;
  28837. },
  28838. forEach: function(callback) {
  28839. // Most maps have fewer than 65536 entries, and for those we use normal
  28840. // array iteration. But really sparse tables are possible -- e.g. with
  28841. // indices in the *billions*. For such tables we use for..in, which isn't
  28842. // ideal because it stringifies the indices for all present elements, but
  28843. // it does avoid iterating over every undefined entry.
  28844. var map = this._map;
  28845. var length = map.length;
  28846. var i;
  28847. if (length <= 0x10000) {
  28848. for (i = 0; i < length; i++) {
  28849. if (map[i] !== undefined) {
  28850. callback(i, map[i]);
  28851. }
  28852. }
  28853. } else {
  28854. for (i in this._map) {
  28855. callback(i, map[i]);
  28856. }
  28857. }
  28858. },
  28859. charCodeOf: function(value) {
  28860. return this._map.indexOf(value);
  28861. },
  28862. getMap: function() {
  28863. return this._map;
  28864. },
  28865. readCharCode: function(str, offset, out) {
  28866. var c = 0;
  28867. var codespaceRanges = this.codespaceRanges;
  28868. var codespaceRangesLen = this.codespaceRanges.length;
  28869. // 9.7.6.2 CMap Mapping
  28870. // The code length is at most 4.
  28871. for (var n = 0; n < codespaceRangesLen; n++) {
  28872. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  28873. // Check each codespace range to see if it falls within.
  28874. var codespaceRange = codespaceRanges[n];
  28875. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  28876. var low = codespaceRange[k++];
  28877. var high = codespaceRange[k++];
  28878. if (c >= low && c <= high) {
  28879. out.charcode = c;
  28880. out.length = n + 1;
  28881. return;
  28882. }
  28883. }
  28884. }
  28885. out.charcode = 0;
  28886. out.length = 1;
  28887. },
  28888. get length() {
  28889. return this._map.length;
  28890. },
  28891. get isIdentityCMap() {
  28892. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  28893. return false;
  28894. }
  28895. if (this._map.length !== 0x10000) {
  28896. return false;
  28897. }
  28898. for (var i = 0; i < 0x10000; i++) {
  28899. if (this._map[i] !== i) {
  28900. return false;
  28901. }
  28902. }
  28903. return true;
  28904. }
  28905. };
  28906. return CMap;
  28907. })();
  28908. // A special case of CMap, where the _map array implicitly has a length of
  28909. // 65536 and each element is equal to its index.
  28910. var IdentityCMap = (function IdentityCMapClosure() {
  28911. function IdentityCMap(vertical, n) {
  28912. CMap.call(this);
  28913. this.vertical = vertical;
  28914. this.addCodespaceRange(n, 0, 0xffff);
  28915. }
  28916. Util.inherit(IdentityCMap, CMap, {});
  28917. IdentityCMap.prototype = {
  28918. addCodespaceRange: CMap.prototype.addCodespaceRange,
  28919. mapCidRange: function(low, high, dstLow) {
  28920. error('should not call mapCidRange');
  28921. },
  28922. mapBfRange: function(low, high, dstLow) {
  28923. error('should not call mapBfRange');
  28924. },
  28925. mapBfRangeToArray: function(low, high, array) {
  28926. error('should not call mapBfRangeToArray');
  28927. },
  28928. mapOne: function(src, dst) {
  28929. error('should not call mapCidOne');
  28930. },
  28931. lookup: function(code) {
  28932. return (isInt(code) && code <= 0xffff) ? code : undefined;
  28933. },
  28934. contains: function(code) {
  28935. return isInt(code) && code <= 0xffff;
  28936. },
  28937. forEach: function(callback) {
  28938. for (var i = 0; i <= 0xffff; i++) {
  28939. callback(i, i);
  28940. }
  28941. },
  28942. charCodeOf: function(value) {
  28943. return (isInt(value) && value <= 0xffff) ? value : -1;
  28944. },
  28945. getMap: function() {
  28946. // Sometimes identity maps must be instantiated, but it's rare.
  28947. var map = new Array(0x10000);
  28948. for (var i = 0; i <= 0xffff; i++) {
  28949. map[i] = i;
  28950. }
  28951. return map;
  28952. },
  28953. readCharCode: CMap.prototype.readCharCode,
  28954. get length() {
  28955. return 0x10000;
  28956. },
  28957. get isIdentityCMap() {
  28958. error('should not access .isIdentityCMap');
  28959. }
  28960. };
  28961. return IdentityCMap;
  28962. })();
  28963. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  28964. function fetchBinaryData(url) {
  28965. var nonBinaryRequest = PDFJS.disableWorker;
  28966. var request = new XMLHttpRequest();
  28967. request.open('GET', url, false);
  28968. if (!nonBinaryRequest) {
  28969. try {
  28970. request.responseType = 'arraybuffer';
  28971. nonBinaryRequest = request.responseType !== 'arraybuffer';
  28972. } catch (e) {
  28973. nonBinaryRequest = true;
  28974. }
  28975. }
  28976. if (nonBinaryRequest && request.overrideMimeType) {
  28977. request.overrideMimeType('text/plain; charset=x-user-defined');
  28978. }
  28979. request.send(null);
  28980. if (nonBinaryRequest ? !request.responseText : !request.response) {
  28981. error('Unable to get binary cMap at: ' + url);
  28982. }
  28983. if (nonBinaryRequest) {
  28984. var data = Array.prototype.map.call(request.responseText, function (ch) {
  28985. return ch.charCodeAt(0) & 255;
  28986. });
  28987. return new Uint8Array(data);
  28988. }
  28989. return new Uint8Array(request.response);
  28990. }
  28991. function hexToInt(a, size) {
  28992. var n = 0;
  28993. for (var i = 0; i <= size; i++) {
  28994. n = (n << 8) | a[i];
  28995. }
  28996. return n >>> 0;
  28997. }
  28998. function hexToStr(a, size) {
  28999. // This code is hot. Special-case some common values to avoid creating an
  29000. // object with subarray().
  29001. if (size === 1) {
  29002. return String.fromCharCode(a[0], a[1]);
  29003. }
  29004. if (size === 3) {
  29005. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29006. }
  29007. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29008. }
  29009. function addHex(a, b, size) {
  29010. var c = 0;
  29011. for (var i = size; i >= 0; i--) {
  29012. c += a[i] + b[i];
  29013. a[i] = c & 255;
  29014. c >>= 8;
  29015. }
  29016. }
  29017. function incHex(a, size) {
  29018. var c = 1;
  29019. for (var i = size; i >= 0 && c > 0; i--) {
  29020. c += a[i];
  29021. a[i] = c & 255;
  29022. c >>= 8;
  29023. }
  29024. }
  29025. var MAX_NUM_SIZE = 16;
  29026. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29027. function BinaryCMapStream(data) {
  29028. this.buffer = data;
  29029. this.pos = 0;
  29030. this.end = data.length;
  29031. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29032. }
  29033. BinaryCMapStream.prototype = {
  29034. readByte: function () {
  29035. if (this.pos >= this.end) {
  29036. return -1;
  29037. }
  29038. return this.buffer[this.pos++];
  29039. },
  29040. readNumber: function () {
  29041. var n = 0;
  29042. var last;
  29043. do {
  29044. var b = this.readByte();
  29045. if (b < 0) {
  29046. error('unexpected EOF in bcmap');
  29047. }
  29048. last = !(b & 0x80);
  29049. n = (n << 7) | (b & 0x7F);
  29050. } while (!last);
  29051. return n;
  29052. },
  29053. readSigned: function () {
  29054. var n = this.readNumber();
  29055. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29056. },
  29057. readHex: function (num, size) {
  29058. num.set(this.buffer.subarray(this.pos,
  29059. this.pos + size + 1));
  29060. this.pos += size + 1;
  29061. },
  29062. readHexNumber: function (num, size) {
  29063. var last;
  29064. var stack = this.tmpBuf, sp = 0;
  29065. do {
  29066. var b = this.readByte();
  29067. if (b < 0) {
  29068. error('unexpected EOF in bcmap');
  29069. }
  29070. last = !(b & 0x80);
  29071. stack[sp++] = b & 0x7F;
  29072. } while (!last);
  29073. var i = size, buffer = 0, bufferSize = 0;
  29074. while (i >= 0) {
  29075. while (bufferSize < 8 && stack.length > 0) {
  29076. buffer = (stack[--sp] << bufferSize) | buffer;
  29077. bufferSize += 7;
  29078. }
  29079. num[i] = buffer & 255;
  29080. i--;
  29081. buffer >>= 8;
  29082. bufferSize -= 8;
  29083. }
  29084. },
  29085. readHexSigned: function (num, size) {
  29086. this.readHexNumber(num, size);
  29087. var sign = num[size] & 1 ? 255 : 0;
  29088. var c = 0;
  29089. for (var i = 0; i <= size; i++) {
  29090. c = ((c & 1) << 8) | num[i];
  29091. num[i] = (c >> 1) ^ sign;
  29092. }
  29093. },
  29094. readString: function () {
  29095. var len = this.readNumber();
  29096. var s = '';
  29097. for (var i = 0; i < len; i++) {
  29098. s += String.fromCharCode(this.readNumber());
  29099. }
  29100. return s;
  29101. }
  29102. };
  29103. function processBinaryCMap(url, cMap, extend) {
  29104. var data = fetchBinaryData(url);
  29105. var stream = new BinaryCMapStream(data);
  29106. var header = stream.readByte();
  29107. cMap.vertical = !!(header & 1);
  29108. var useCMap = null;
  29109. var start = new Uint8Array(MAX_NUM_SIZE);
  29110. var end = new Uint8Array(MAX_NUM_SIZE);
  29111. var char = new Uint8Array(MAX_NUM_SIZE);
  29112. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29113. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29114. var code;
  29115. var b;
  29116. while ((b = stream.readByte()) >= 0) {
  29117. var type = b >> 5;
  29118. if (type === 7) { // metadata, e.g. comment or usecmap
  29119. switch (b & 0x1F) {
  29120. case 0:
  29121. stream.readString(); // skipping comment
  29122. break;
  29123. case 1:
  29124. useCMap = stream.readString();
  29125. break;
  29126. }
  29127. continue;
  29128. }
  29129. var sequence = !!(b & 0x10);
  29130. var dataSize = b & 15;
  29131. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29132. var ucs2DataSize = 1;
  29133. var subitemsCount = stream.readNumber();
  29134. var i;
  29135. switch (type) {
  29136. case 0: // codespacerange
  29137. stream.readHex(start, dataSize);
  29138. stream.readHexNumber(end, dataSize);
  29139. addHex(end, start, dataSize);
  29140. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29141. hexToInt(end, dataSize));
  29142. for (i = 1; i < subitemsCount; i++) {
  29143. incHex(end, dataSize);
  29144. stream.readHexNumber(start, dataSize);
  29145. addHex(start, end, dataSize);
  29146. stream.readHexNumber(end, dataSize);
  29147. addHex(end, start, dataSize);
  29148. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29149. hexToInt(end, dataSize));
  29150. }
  29151. break;
  29152. case 1: // notdefrange
  29153. stream.readHex(start, dataSize);
  29154. stream.readHexNumber(end, dataSize);
  29155. addHex(end, start, dataSize);
  29156. code = stream.readNumber();
  29157. // undefined range, skipping
  29158. for (i = 1; i < subitemsCount; i++) {
  29159. incHex(end, dataSize);
  29160. stream.readHexNumber(start, dataSize);
  29161. addHex(start, end, dataSize);
  29162. stream.readHexNumber(end, dataSize);
  29163. addHex(end, start, dataSize);
  29164. code = stream.readNumber();
  29165. // nop
  29166. }
  29167. break;
  29168. case 2: // cidchar
  29169. stream.readHex(char, dataSize);
  29170. code = stream.readNumber();
  29171. cMap.mapOne(hexToInt(char, dataSize), code);
  29172. for (i = 1; i < subitemsCount; i++) {
  29173. incHex(char, dataSize);
  29174. if (!sequence) {
  29175. stream.readHexNumber(tmp, dataSize);
  29176. addHex(char, tmp, dataSize);
  29177. }
  29178. code = stream.readSigned() + (code + 1);
  29179. cMap.mapOne(hexToInt(char, dataSize), code);
  29180. }
  29181. break;
  29182. case 3: // cidrange
  29183. stream.readHex(start, dataSize);
  29184. stream.readHexNumber(end, dataSize);
  29185. addHex(end, start, dataSize);
  29186. code = stream.readNumber();
  29187. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29188. code);
  29189. for (i = 1; i < subitemsCount; i++) {
  29190. incHex(end, dataSize);
  29191. if (!sequence) {
  29192. stream.readHexNumber(start, dataSize);
  29193. addHex(start, end, dataSize);
  29194. } else {
  29195. start.set(end);
  29196. }
  29197. stream.readHexNumber(end, dataSize);
  29198. addHex(end, start, dataSize);
  29199. code = stream.readNumber();
  29200. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29201. code);
  29202. }
  29203. break;
  29204. case 4: // bfchar
  29205. stream.readHex(char, ucs2DataSize);
  29206. stream.readHex(charCode, dataSize);
  29207. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29208. hexToStr(charCode, dataSize));
  29209. for (i = 1; i < subitemsCount; i++) {
  29210. incHex(char, ucs2DataSize);
  29211. if (!sequence) {
  29212. stream.readHexNumber(tmp, ucs2DataSize);
  29213. addHex(char, tmp, ucs2DataSize);
  29214. }
  29215. incHex(charCode, dataSize);
  29216. stream.readHexSigned(tmp, dataSize);
  29217. addHex(charCode, tmp, dataSize);
  29218. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29219. hexToStr(charCode, dataSize));
  29220. }
  29221. break;
  29222. case 5: // bfrange
  29223. stream.readHex(start, ucs2DataSize);
  29224. stream.readHexNumber(end, ucs2DataSize);
  29225. addHex(end, start, ucs2DataSize);
  29226. stream.readHex(charCode, dataSize);
  29227. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29228. hexToInt(end, ucs2DataSize),
  29229. hexToStr(charCode, dataSize));
  29230. for (i = 1; i < subitemsCount; i++) {
  29231. incHex(end, ucs2DataSize);
  29232. if (!sequence) {
  29233. stream.readHexNumber(start, ucs2DataSize);
  29234. addHex(start, end, ucs2DataSize);
  29235. } else {
  29236. start.set(end);
  29237. }
  29238. stream.readHexNumber(end, ucs2DataSize);
  29239. addHex(end, start, ucs2DataSize);
  29240. stream.readHex(charCode, dataSize);
  29241. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29242. hexToInt(end, ucs2DataSize),
  29243. hexToStr(charCode, dataSize));
  29244. }
  29245. break;
  29246. default:
  29247. error('Unknown type: ' + type);
  29248. break;
  29249. }
  29250. }
  29251. if (useCMap) {
  29252. extend(useCMap);
  29253. }
  29254. return cMap;
  29255. }
  29256. function BinaryCMapReader() {}
  29257. BinaryCMapReader.prototype = {
  29258. read: processBinaryCMap
  29259. };
  29260. return BinaryCMapReader;
  29261. })();
  29262. var CMapFactory = (function CMapFactoryClosure() {
  29263. function strToInt(str) {
  29264. var a = 0;
  29265. for (var i = 0; i < str.length; i++) {
  29266. a = (a << 8) | str.charCodeAt(i);
  29267. }
  29268. return a >>> 0;
  29269. }
  29270. function expectString(obj) {
  29271. if (!isString(obj)) {
  29272. error('Malformed CMap: expected string.');
  29273. }
  29274. }
  29275. function expectInt(obj) {
  29276. if (!isInt(obj)) {
  29277. error('Malformed CMap: expected int.');
  29278. }
  29279. }
  29280. function parseBfChar(cMap, lexer) {
  29281. while (true) {
  29282. var obj = lexer.getObj();
  29283. if (isEOF(obj)) {
  29284. break;
  29285. }
  29286. if (isCmd(obj, 'endbfchar')) {
  29287. return;
  29288. }
  29289. expectString(obj);
  29290. var src = strToInt(obj);
  29291. obj = lexer.getObj();
  29292. // TODO are /dstName used?
  29293. expectString(obj);
  29294. var dst = obj;
  29295. cMap.mapOne(src, dst);
  29296. }
  29297. }
  29298. function parseBfRange(cMap, lexer) {
  29299. while (true) {
  29300. var obj = lexer.getObj();
  29301. if (isEOF(obj)) {
  29302. break;
  29303. }
  29304. if (isCmd(obj, 'endbfrange')) {
  29305. return;
  29306. }
  29307. expectString(obj);
  29308. var low = strToInt(obj);
  29309. obj = lexer.getObj();
  29310. expectString(obj);
  29311. var high = strToInt(obj);
  29312. obj = lexer.getObj();
  29313. if (isInt(obj) || isString(obj)) {
  29314. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  29315. cMap.mapBfRange(low, high, dstLow);
  29316. } else if (isCmd(obj, '[')) {
  29317. obj = lexer.getObj();
  29318. var array = [];
  29319. while (!isCmd(obj, ']') && !isEOF(obj)) {
  29320. array.push(obj);
  29321. obj = lexer.getObj();
  29322. }
  29323. cMap.mapBfRangeToArray(low, high, array);
  29324. } else {
  29325. break;
  29326. }
  29327. }
  29328. error('Invalid bf range.');
  29329. }
  29330. function parseCidChar(cMap, lexer) {
  29331. while (true) {
  29332. var obj = lexer.getObj();
  29333. if (isEOF(obj)) {
  29334. break;
  29335. }
  29336. if (isCmd(obj, 'endcidchar')) {
  29337. return;
  29338. }
  29339. expectString(obj);
  29340. var src = strToInt(obj);
  29341. obj = lexer.getObj();
  29342. expectInt(obj);
  29343. var dst = obj;
  29344. cMap.mapOne(src, dst);
  29345. }
  29346. }
  29347. function parseCidRange(cMap, lexer) {
  29348. while (true) {
  29349. var obj = lexer.getObj();
  29350. if (isEOF(obj)) {
  29351. break;
  29352. }
  29353. if (isCmd(obj, 'endcidrange')) {
  29354. return;
  29355. }
  29356. expectString(obj);
  29357. var low = strToInt(obj);
  29358. obj = lexer.getObj();
  29359. expectString(obj);
  29360. var high = strToInt(obj);
  29361. obj = lexer.getObj();
  29362. expectInt(obj);
  29363. var dstLow = obj;
  29364. cMap.mapCidRange(low, high, dstLow);
  29365. }
  29366. }
  29367. function parseCodespaceRange(cMap, lexer) {
  29368. while (true) {
  29369. var obj = lexer.getObj();
  29370. if (isEOF(obj)) {
  29371. break;
  29372. }
  29373. if (isCmd(obj, 'endcodespacerange')) {
  29374. return;
  29375. }
  29376. if (!isString(obj)) {
  29377. break;
  29378. }
  29379. var low = strToInt(obj);
  29380. obj = lexer.getObj();
  29381. if (!isString(obj)) {
  29382. break;
  29383. }
  29384. var high = strToInt(obj);
  29385. cMap.addCodespaceRange(obj.length, low, high);
  29386. }
  29387. error('Invalid codespace range.');
  29388. }
  29389. function parseWMode(cMap, lexer) {
  29390. var obj = lexer.getObj();
  29391. if (isInt(obj)) {
  29392. cMap.vertical = !!obj;
  29393. }
  29394. }
  29395. function parseCMapName(cMap, lexer) {
  29396. var obj = lexer.getObj();
  29397. if (isName(obj) && isString(obj.name)) {
  29398. cMap.name = obj.name;
  29399. }
  29400. }
  29401. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  29402. var previous;
  29403. var embededUseCMap;
  29404. objLoop: while (true) {
  29405. var obj = lexer.getObj();
  29406. if (isEOF(obj)) {
  29407. break;
  29408. } else if (isName(obj)) {
  29409. if (obj.name === 'WMode') {
  29410. parseWMode(cMap, lexer);
  29411. } else if (obj.name === 'CMapName') {
  29412. parseCMapName(cMap, lexer);
  29413. }
  29414. previous = obj;
  29415. } else if (isCmd(obj)) {
  29416. switch (obj.cmd) {
  29417. case 'endcmap':
  29418. break objLoop;
  29419. case 'usecmap':
  29420. if (isName(previous)) {
  29421. embededUseCMap = previous.name;
  29422. }
  29423. break;
  29424. case 'begincodespacerange':
  29425. parseCodespaceRange(cMap, lexer);
  29426. break;
  29427. case 'beginbfchar':
  29428. parseBfChar(cMap, lexer);
  29429. break;
  29430. case 'begincidchar':
  29431. parseCidChar(cMap, lexer);
  29432. break;
  29433. case 'beginbfrange':
  29434. parseBfRange(cMap, lexer);
  29435. break;
  29436. case 'begincidrange':
  29437. parseCidRange(cMap, lexer);
  29438. break;
  29439. }
  29440. }
  29441. }
  29442. if (!useCMap && embededUseCMap) {
  29443. // Load the usecmap definition from the file only if there wasn't one
  29444. // specified.
  29445. useCMap = embededUseCMap;
  29446. }
  29447. if (useCMap) {
  29448. extendCMap(cMap, builtInCMapParams, useCMap);
  29449. }
  29450. }
  29451. function extendCMap(cMap, builtInCMapParams, useCMap) {
  29452. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  29453. // If there aren't any code space ranges defined clone all the parent ones
  29454. // into this cMap.
  29455. if (cMap.numCodespaceRanges === 0) {
  29456. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  29457. for (var i = 0; i < useCodespaceRanges.length; i++) {
  29458. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  29459. }
  29460. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  29461. }
  29462. // Merge the map into the current one, making sure not to override
  29463. // any previously defined entries.
  29464. cMap.useCMap.forEach(function(key, value) {
  29465. if (!cMap.contains(key)) {
  29466. cMap.mapOne(key, cMap.useCMap.lookup(key));
  29467. }
  29468. });
  29469. }
  29470. function parseBinaryCMap(name, builtInCMapParams) {
  29471. var url = builtInCMapParams.url + name + '.bcmap';
  29472. var cMap = new CMap(true);
  29473. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  29474. extendCMap(cMap, builtInCMapParams, useCMap);
  29475. });
  29476. return cMap;
  29477. }
  29478. function createBuiltInCMap(name, builtInCMapParams) {
  29479. if (name === 'Identity-H') {
  29480. return new IdentityCMap(false, 2);
  29481. } else if (name === 'Identity-V') {
  29482. return new IdentityCMap(true, 2);
  29483. }
  29484. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  29485. error('Unknown cMap name: ' + name);
  29486. }
  29487. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  29488. if (builtInCMapParams.packed) {
  29489. return parseBinaryCMap(name, builtInCMapParams);
  29490. }
  29491. var request = new XMLHttpRequest();
  29492. var url = builtInCMapParams.url + name;
  29493. request.open('GET', url, false);
  29494. request.send(null);
  29495. if (!request.responseText) {
  29496. error('Unable to get cMap at: ' + url);
  29497. }
  29498. var cMap = new CMap(true);
  29499. var lexer = new Lexer(new StringStream(request.responseText));
  29500. parseCMap(cMap, lexer, builtInCMapParams, null);
  29501. return cMap;
  29502. }
  29503. return {
  29504. create: function (encoding, builtInCMapParams, useCMap) {
  29505. if (isName(encoding)) {
  29506. return createBuiltInCMap(encoding.name, builtInCMapParams);
  29507. } else if (isStream(encoding)) {
  29508. var cMap = new CMap();
  29509. var lexer = new Lexer(encoding);
  29510. try {
  29511. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  29512. } catch (e) {
  29513. warn('Invalid CMap data. ' + e);
  29514. }
  29515. if (cMap.isIdentityCMap) {
  29516. return createBuiltInCMap(cMap.name, builtInCMapParams);
  29517. }
  29518. return cMap;
  29519. }
  29520. error('Encoding required.');
  29521. }
  29522. };
  29523. })();
  29524. exports.CMap = CMap;
  29525. exports.CMapFactory = CMapFactory;
  29526. exports.IdentityCMap = IdentityCMap;
  29527. }));
  29528. (function (root, factory) {
  29529. {
  29530. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29531. root.pdfjsCoreParser);
  29532. }
  29533. }(this, function (exports, sharedUtil, coreParser) {
  29534. var error = sharedUtil.error;
  29535. var EOF = coreParser.EOF;
  29536. var Lexer = coreParser.Lexer;
  29537. var PostScriptParser = (function PostScriptParserClosure() {
  29538. function PostScriptParser(lexer) {
  29539. this.lexer = lexer;
  29540. this.operators = [];
  29541. this.token = null;
  29542. this.prev = null;
  29543. }
  29544. PostScriptParser.prototype = {
  29545. nextToken: function PostScriptParser_nextToken() {
  29546. this.prev = this.token;
  29547. this.token = this.lexer.getToken();
  29548. },
  29549. accept: function PostScriptParser_accept(type) {
  29550. if (this.token.type === type) {
  29551. this.nextToken();
  29552. return true;
  29553. }
  29554. return false;
  29555. },
  29556. expect: function PostScriptParser_expect(type) {
  29557. if (this.accept(type)) {
  29558. return true;
  29559. }
  29560. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29561. type + '.');
  29562. },
  29563. parse: function PostScriptParser_parse() {
  29564. this.nextToken();
  29565. this.expect(PostScriptTokenTypes.LBRACE);
  29566. this.parseBlock();
  29567. this.expect(PostScriptTokenTypes.RBRACE);
  29568. return this.operators;
  29569. },
  29570. parseBlock: function PostScriptParser_parseBlock() {
  29571. while (true) {
  29572. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29573. this.operators.push(this.prev.value);
  29574. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29575. this.operators.push(this.prev.value);
  29576. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29577. this.parseCondition();
  29578. } else {
  29579. return;
  29580. }
  29581. }
  29582. },
  29583. parseCondition: function PostScriptParser_parseCondition() {
  29584. // Add two place holders that will be updated later
  29585. var conditionLocation = this.operators.length;
  29586. this.operators.push(null, null);
  29587. this.parseBlock();
  29588. this.expect(PostScriptTokenTypes.RBRACE);
  29589. if (this.accept(PostScriptTokenTypes.IF)) {
  29590. // The true block is right after the 'if' so it just falls through on
  29591. // true else it jumps and skips the true block.
  29592. this.operators[conditionLocation] = this.operators.length;
  29593. this.operators[conditionLocation + 1] = 'jz';
  29594. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29595. var jumpLocation = this.operators.length;
  29596. this.operators.push(null, null);
  29597. var endOfTrue = this.operators.length;
  29598. this.parseBlock();
  29599. this.expect(PostScriptTokenTypes.RBRACE);
  29600. this.expect(PostScriptTokenTypes.IFELSE);
  29601. // The jump is added at the end of the true block to skip the false
  29602. // block.
  29603. this.operators[jumpLocation] = this.operators.length;
  29604. this.operators[jumpLocation + 1] = 'j';
  29605. this.operators[conditionLocation] = endOfTrue;
  29606. this.operators[conditionLocation + 1] = 'jz';
  29607. } else {
  29608. error('PS Function: error parsing conditional.');
  29609. }
  29610. }
  29611. };
  29612. return PostScriptParser;
  29613. })();
  29614. var PostScriptTokenTypes = {
  29615. LBRACE: 0,
  29616. RBRACE: 1,
  29617. NUMBER: 2,
  29618. OPERATOR: 3,
  29619. IF: 4,
  29620. IFELSE: 5
  29621. };
  29622. var PostScriptToken = (function PostScriptTokenClosure() {
  29623. function PostScriptToken(type, value) {
  29624. this.type = type;
  29625. this.value = value;
  29626. }
  29627. var opCache = Object.create(null);
  29628. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29629. var opValue = opCache[op];
  29630. if (opValue) {
  29631. return opValue;
  29632. }
  29633. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29634. };
  29635. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29636. '{');
  29637. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29638. '}');
  29639. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29640. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29641. 'IFELSE');
  29642. return PostScriptToken;
  29643. })();
  29644. var PostScriptLexer = (function PostScriptLexerClosure() {
  29645. function PostScriptLexer(stream) {
  29646. this.stream = stream;
  29647. this.nextChar();
  29648. this.strBuf = [];
  29649. }
  29650. PostScriptLexer.prototype = {
  29651. nextChar: function PostScriptLexer_nextChar() {
  29652. return (this.currentChar = this.stream.getByte());
  29653. },
  29654. getToken: function PostScriptLexer_getToken() {
  29655. var comment = false;
  29656. var ch = this.currentChar;
  29657. // skip comments
  29658. while (true) {
  29659. if (ch < 0) {
  29660. return EOF;
  29661. }
  29662. if (comment) {
  29663. if (ch === 0x0A || ch === 0x0D) {
  29664. comment = false;
  29665. }
  29666. } else if (ch === 0x25) { // '%'
  29667. comment = true;
  29668. } else if (!Lexer.isSpace(ch)) {
  29669. break;
  29670. }
  29671. ch = this.nextChar();
  29672. }
  29673. switch (ch | 0) {
  29674. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29675. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29676. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29677. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29678. this.getNumber());
  29679. case 0x7B: // '{'
  29680. this.nextChar();
  29681. return PostScriptToken.LBRACE;
  29682. case 0x7D: // '}'
  29683. this.nextChar();
  29684. return PostScriptToken.RBRACE;
  29685. }
  29686. // operator
  29687. var strBuf = this.strBuf;
  29688. strBuf.length = 0;
  29689. strBuf[0] = String.fromCharCode(ch);
  29690. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29691. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29692. strBuf.push(String.fromCharCode(ch));
  29693. }
  29694. var str = strBuf.join('');
  29695. switch (str.toLowerCase()) {
  29696. case 'if':
  29697. return PostScriptToken.IF;
  29698. case 'ifelse':
  29699. return PostScriptToken.IFELSE;
  29700. default:
  29701. return PostScriptToken.getOperator(str);
  29702. }
  29703. },
  29704. getNumber: function PostScriptLexer_getNumber() {
  29705. var ch = this.currentChar;
  29706. var strBuf = this.strBuf;
  29707. strBuf.length = 0;
  29708. strBuf[0] = String.fromCharCode(ch);
  29709. while ((ch = this.nextChar()) >= 0) {
  29710. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29711. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29712. strBuf.push(String.fromCharCode(ch));
  29713. } else {
  29714. break;
  29715. }
  29716. }
  29717. var value = parseFloat(strBuf.join(''));
  29718. if (isNaN(value)) {
  29719. error('Invalid floating point number: ' + value);
  29720. }
  29721. return value;
  29722. }
  29723. };
  29724. return PostScriptLexer;
  29725. })();
  29726. exports.PostScriptLexer = PostScriptLexer;
  29727. exports.PostScriptParser = PostScriptParser;
  29728. }));
  29729. (function (root, factory) {
  29730. {
  29731. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  29732. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  29733. root.pdfjsDisplayMetadata, root.pdfjsSharedGlobal);
  29734. }
  29735. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  29736. displayMetadata, sharedGlobal, amdRequire) {
  29737. var InvalidPDFException = sharedUtil.InvalidPDFException;
  29738. var MessageHandler = sharedUtil.MessageHandler;
  29739. var MissingPDFException = sharedUtil.MissingPDFException;
  29740. var PasswordResponses = sharedUtil.PasswordResponses;
  29741. var PasswordException = sharedUtil.PasswordException;
  29742. var StatTimer = sharedUtil.StatTimer;
  29743. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  29744. var UnknownErrorException = sharedUtil.UnknownErrorException;
  29745. var Util = sharedUtil.Util;
  29746. var createPromiseCapability = sharedUtil.createPromiseCapability;
  29747. var combineUrl = sharedUtil.combineUrl;
  29748. var error = sharedUtil.error;
  29749. var deprecated = sharedUtil.deprecated;
  29750. var info = sharedUtil.info;
  29751. var isArrayBuffer = sharedUtil.isArrayBuffer;
  29752. var isSameOrigin = sharedUtil.isSameOrigin;
  29753. var loadJpegStream = sharedUtil.loadJpegStream;
  29754. var stringToBytes = sharedUtil.stringToBytes;
  29755. var warn = sharedUtil.warn;
  29756. var FontFaceObject = displayFontLoader.FontFaceObject;
  29757. var FontLoader = displayFontLoader.FontLoader;
  29758. var CanvasGraphics = displayCanvas.CanvasGraphics;
  29759. var createScratchCanvas = displayCanvas.createScratchCanvas;
  29760. var Metadata = displayMetadata.Metadata;
  29761. var PDFJS = sharedGlobal.PDFJS;
  29762. var globalScope = sharedGlobal.globalScope;
  29763. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  29764. /**
  29765. * The maximum allowed image size in total pixels e.g. width * height. Images
  29766. * above this value will not be drawn. Use -1 for no limit.
  29767. * @var {number}
  29768. */
  29769. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  29770. -1 : PDFJS.maxImageSize);
  29771. /**
  29772. * The url of where the predefined Adobe CMaps are located. Include trailing
  29773. * slash.
  29774. * @var {string}
  29775. */
  29776. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  29777. /**
  29778. * Specifies if CMaps are binary packed.
  29779. * @var {boolean}
  29780. */
  29781. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  29782. /**
  29783. * By default fonts are converted to OpenType fonts and loaded via font face
  29784. * rules. If disabled, the font will be rendered using a built in font renderer
  29785. * that constructs the glyphs with primitive path commands.
  29786. * @var {boolean}
  29787. */
  29788. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  29789. false : PDFJS.disableFontFace);
  29790. /**
  29791. * Path for image resources, mainly for annotation icons. Include trailing
  29792. * slash.
  29793. * @var {string}
  29794. */
  29795. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  29796. '' : PDFJS.imageResourcesPath);
  29797. /**
  29798. * Disable the web worker and run all code on the main thread. This will happen
  29799. * automatically if the browser doesn't support workers or sending typed arrays
  29800. * to workers.
  29801. * @var {boolean}
  29802. */
  29803. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  29804. false : PDFJS.disableWorker);
  29805. /**
  29806. * Path and filename of the worker file. Required when the worker is enabled in
  29807. * development mode. If unspecified in the production build, the worker will be
  29808. * loaded based on the location of the pdf.js file. It is recommended that
  29809. * the workerSrc is set in a custom application to prevent issues caused by
  29810. * third-party frameworks and libraries.
  29811. * @var {string}
  29812. */
  29813. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  29814. /**
  29815. * Disable range request loading of PDF files. When enabled and if the server
  29816. * supports partial content requests then the PDF will be fetched in chunks.
  29817. * Enabled (false) by default.
  29818. * @var {boolean}
  29819. */
  29820. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  29821. false : PDFJS.disableRange);
  29822. /**
  29823. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  29824. * in chunks. This default behavior can be disabled.
  29825. * @var {boolean}
  29826. */
  29827. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  29828. false : PDFJS.disableStream);
  29829. /**
  29830. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  29831. * will automatically keep fetching more data even if it isn't needed to display
  29832. * the current page. This default behavior can be disabled.
  29833. *
  29834. * NOTE: It is also necessary to disable streaming, see above,
  29835. * in order for disabling of pre-fetching to work correctly.
  29836. * @var {boolean}
  29837. */
  29838. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  29839. false : PDFJS.disableAutoFetch);
  29840. /**
  29841. * Enables special hooks for debugging PDF.js.
  29842. * @var {boolean}
  29843. */
  29844. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  29845. /**
  29846. * Enables transfer usage in postMessage for ArrayBuffers.
  29847. * @var {boolean}
  29848. */
  29849. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  29850. true : PDFJS.postMessageTransfers);
  29851. /**
  29852. * Disables URL.createObjectURL usage.
  29853. * @var {boolean}
  29854. */
  29855. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  29856. false : PDFJS.disableCreateObjectURL);
  29857. /**
  29858. * Disables WebGL usage.
  29859. * @var {boolean}
  29860. */
  29861. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  29862. true : PDFJS.disableWebGL);
  29863. /**
  29864. * Disables fullscreen support, and by extension Presentation Mode,
  29865. * in browsers which support the fullscreen API.
  29866. * @var {boolean}
  29867. */
  29868. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  29869. false : PDFJS.disableFullscreen);
  29870. /**
  29871. * Enables CSS only zooming.
  29872. * @var {boolean}
  29873. */
  29874. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  29875. false : PDFJS.useOnlyCssZoom);
  29876. /**
  29877. * Controls the logging level.
  29878. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  29879. * - errors
  29880. * - warnings [default]
  29881. * - infos
  29882. * @var {number}
  29883. */
  29884. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  29885. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  29886. /**
  29887. * The maximum supported canvas size in total pixels e.g. width * height.
  29888. * The default value is 4096 * 4096. Use -1 for no limit.
  29889. * @var {number}
  29890. */
  29891. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  29892. 16777216 : PDFJS.maxCanvasPixels);
  29893. /**
  29894. * (Deprecated) Opens external links in a new window if enabled.
  29895. * The default behavior opens external links in the PDF.js window.
  29896. *
  29897. * NOTE: This property has been deprecated, please use
  29898. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  29899. * @var {boolean}
  29900. */
  29901. PDFJS.openExternalLinksInNewWindow = (
  29902. PDFJS.openExternalLinksInNewWindow === undefined ?
  29903. false : PDFJS.openExternalLinksInNewWindow);
  29904. /**
  29905. * Specifies the |target| attribute for external links.
  29906. * The constants from PDFJS.LinkTarget should be used:
  29907. * - NONE [default]
  29908. * - SELF
  29909. * - BLANK
  29910. * - PARENT
  29911. * - TOP
  29912. * @var {number}
  29913. */
  29914. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  29915. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  29916. /**
  29917. * Specifies the |rel| attribute for external links. Defaults to stripping
  29918. * the referrer.
  29919. * @var {string}
  29920. */
  29921. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  29922. 'noreferrer' : PDFJS.externalLinkRel);
  29923. /**
  29924. * Determines if we can eval strings as JS. Primarily used to improve
  29925. * performance for font rendering.
  29926. * @var {boolean}
  29927. */
  29928. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  29929. true : PDFJS.isEvalSupported);
  29930. /**
  29931. * Document initialization / loading parameters object.
  29932. *
  29933. * @typedef {Object} DocumentInitParameters
  29934. * @property {string} url - The URL of the PDF.
  29935. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  29936. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  29937. * use atob() to convert it to a binary string first.
  29938. * @property {Object} httpHeaders - Basic authentication headers.
  29939. * @property {boolean} withCredentials - Indicates whether or not cross-site
  29940. * Access-Control requests should be made using credentials such as cookies
  29941. * or authorization headers. The default is false.
  29942. * @property {string} password - For decrypting password-protected PDFs.
  29943. * @property {TypedArray} initialData - A typed array with the first portion or
  29944. * all of the pdf data. Used by the extension since some data is already
  29945. * loaded before the switch to range requests.
  29946. * @property {number} length - The PDF file length. It's used for progress
  29947. * reports and range requests operations.
  29948. * @property {PDFDataRangeTransport} range
  29949. * @property {number} rangeChunkSize - Optional parameter to specify
  29950. * maximum number of bytes fetched per range request. The default value is
  29951. * 2^16 = 65536.
  29952. * @property {PDFWorker} worker - The worker that will be used for the loading
  29953. * and parsing of the PDF data.
  29954. */
  29955. /**
  29956. * @typedef {Object} PDFDocumentStats
  29957. * @property {Array} streamTypes - Used stream types in the document (an item
  29958. * is set to true if specific stream ID was used in the document).
  29959. * @property {Array} fontTypes - Used font type in the document (an item is set
  29960. * to true if specific font ID was used in the document).
  29961. */
  29962. /**
  29963. * This is the main entry point for loading a PDF and interacting with it.
  29964. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  29965. * is used, which means it must follow the same origin rules that any XHR does
  29966. * e.g. No cross domain requests without CORS.
  29967. *
  29968. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  29969. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  29970. * already populated with data or parameter object.
  29971. *
  29972. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  29973. * if you want to manually serve range requests for data in the PDF.
  29974. *
  29975. * @param {function} passwordCallback (deprecated) It is used to request a
  29976. * password if wrong or no password was provided. The callback receives two
  29977. * parameters: function that needs to be called with new password and reason
  29978. * (see {PasswordResponses}).
  29979. *
  29980. * @param {function} progressCallback (deprecated) It is used to be able to
  29981. * monitor the loading progress of the PDF file (necessary to implement e.g.
  29982. * a loading bar). The callback receives an {Object} with the properties:
  29983. * {number} loaded and {number} total.
  29984. *
  29985. * @return {PDFDocumentLoadingTask}
  29986. */
  29987. PDFJS.getDocument = function getDocument(src,
  29988. pdfDataRangeTransport,
  29989. passwordCallback,
  29990. progressCallback) {
  29991. var task = new PDFDocumentLoadingTask();
  29992. // Support of the obsolete arguments (for compatibility with API v1.0)
  29993. if (arguments.length > 1) {
  29994. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  29995. 'passwordCallback or progressCallback argument');
  29996. }
  29997. if (pdfDataRangeTransport) {
  29998. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  29999. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  30000. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  30001. pdfDataRangeTransport.length = src.length;
  30002. pdfDataRangeTransport.initialData = src.initialData;
  30003. if (!pdfDataRangeTransport.abort) {
  30004. pdfDataRangeTransport.abort = function () {};
  30005. }
  30006. }
  30007. src = Object.create(src);
  30008. src.range = pdfDataRangeTransport;
  30009. }
  30010. task.onPassword = passwordCallback || null;
  30011. task.onProgress = progressCallback || null;
  30012. var source;
  30013. if (typeof src === 'string') {
  30014. source = { url: src };
  30015. } else if (isArrayBuffer(src)) {
  30016. source = { data: src };
  30017. } else if (src instanceof PDFDataRangeTransport) {
  30018. source = { range: src };
  30019. } else {
  30020. if (typeof src !== 'object') {
  30021. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  30022. 'string or a parameter object');
  30023. }
  30024. if (!src.url && !src.data && !src.range) {
  30025. error('Invalid parameter object: need either .data, .range or .url');
  30026. }
  30027. source = src;
  30028. }
  30029. var params = {};
  30030. var rangeTransport = null;
  30031. var worker = null;
  30032. for (var key in source) {
  30033. if (key === 'url' && typeof window !== 'undefined') {
  30034. // The full path is required in the 'url' field.
  30035. params[key] = combineUrl(window.location.href, source[key]);
  30036. continue;
  30037. } else if (key === 'range') {
  30038. rangeTransport = source[key];
  30039. continue;
  30040. } else if (key === 'worker') {
  30041. worker = source[key];
  30042. continue;
  30043. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  30044. // Converting string or array-like data to Uint8Array.
  30045. var pdfBytes = source[key];
  30046. if (typeof pdfBytes === 'string') {
  30047. params[key] = stringToBytes(pdfBytes);
  30048. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  30049. !isNaN(pdfBytes.length)) {
  30050. params[key] = new Uint8Array(pdfBytes);
  30051. } else if (isArrayBuffer(pdfBytes)) {
  30052. params[key] = new Uint8Array(pdfBytes);
  30053. } else {
  30054. error('Invalid PDF binary data: either typed array, string or ' +
  30055. 'array-like object is expected in the data property.');
  30056. }
  30057. continue;
  30058. }
  30059. params[key] = source[key];
  30060. }
  30061. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  30062. if (!worker) {
  30063. // Worker was not provided -- creating and owning our own.
  30064. worker = new PDFWorker();
  30065. task._worker = worker;
  30066. }
  30067. var docId = task.docId;
  30068. worker.promise.then(function () {
  30069. if (task.destroyed) {
  30070. throw new Error('Loading aborted');
  30071. }
  30072. return _fetchDocument(worker, params, rangeTransport, docId).then(
  30073. function (workerId) {
  30074. if (task.destroyed) {
  30075. throw new Error('Loading aborted');
  30076. }
  30077. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  30078. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  30079. task._transport = transport;
  30080. messageHandler.send('Ready', null);
  30081. });
  30082. }).catch(task._capability.reject);
  30083. return task;
  30084. };
  30085. /**
  30086. * Starts fetching of specified PDF document/data.
  30087. * @param {PDFWorker} worker
  30088. * @param {Object} source
  30089. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  30090. * @param {string} docId Unique document id, used as MessageHandler id.
  30091. * @returns {Promise} The promise, which is resolved when worker id of
  30092. * MessageHandler is known.
  30093. * @private
  30094. */
  30095. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  30096. if (worker.destroyed) {
  30097. return Promise.reject(new Error('Worker was destroyed'));
  30098. }
  30099. source.disableAutoFetch = PDFJS.disableAutoFetch;
  30100. source.disableStream = PDFJS.disableStream;
  30101. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  30102. if (pdfDataRangeTransport) {
  30103. source.length = pdfDataRangeTransport.length;
  30104. source.initialData = pdfDataRangeTransport.initialData;
  30105. }
  30106. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  30107. docId: docId,
  30108. source: source,
  30109. disableRange: PDFJS.disableRange,
  30110. maxImageSize: PDFJS.maxImageSize,
  30111. cMapUrl: PDFJS.cMapUrl,
  30112. cMapPacked: PDFJS.cMapPacked,
  30113. disableFontFace: PDFJS.disableFontFace,
  30114. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  30115. verbosity: PDFJS.verbosity
  30116. }).then(function (workerId) {
  30117. if (worker.destroyed) {
  30118. throw new Error('Worker was destroyed');
  30119. }
  30120. return workerId;
  30121. });
  30122. }
  30123. /**
  30124. * PDF document loading operation.
  30125. * @class
  30126. * @alias PDFDocumentLoadingTask
  30127. */
  30128. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  30129. var nextDocumentId = 0;
  30130. /** @constructs PDFDocumentLoadingTask */
  30131. function PDFDocumentLoadingTask() {
  30132. this._capability = createPromiseCapability();
  30133. this._transport = null;
  30134. this._worker = null;
  30135. /**
  30136. * Unique document loading task id -- used in MessageHandlers.
  30137. * @type {string}
  30138. */
  30139. this.docId = 'd' + (nextDocumentId++);
  30140. /**
  30141. * Shows if loading task is destroyed.
  30142. * @type {boolean}
  30143. */
  30144. this.destroyed = false;
  30145. /**
  30146. * Callback to request a password if wrong or no password was provided.
  30147. * The callback receives two parameters: function that needs to be called
  30148. * with new password and reason (see {PasswordResponses}).
  30149. */
  30150. this.onPassword = null;
  30151. /**
  30152. * Callback to be able to monitor the loading progress of the PDF file
  30153. * (necessary to implement e.g. a loading bar). The callback receives
  30154. * an {Object} with the properties: {number} loaded and {number} total.
  30155. */
  30156. this.onProgress = null;
  30157. /**
  30158. * Callback to when unsupported feature is used. The callback receives
  30159. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  30160. */
  30161. this.onUnsupportedFeature = null;
  30162. }
  30163. PDFDocumentLoadingTask.prototype =
  30164. /** @lends PDFDocumentLoadingTask.prototype */ {
  30165. /**
  30166. * @return {Promise}
  30167. */
  30168. get promise() {
  30169. return this._capability.promise;
  30170. },
  30171. /**
  30172. * Aborts all network requests and destroys worker.
  30173. * @return {Promise} A promise that is resolved after destruction activity
  30174. * is completed.
  30175. */
  30176. destroy: function () {
  30177. this.destroyed = true;
  30178. var transportDestroyed = !this._transport ? Promise.resolve() :
  30179. this._transport.destroy();
  30180. return transportDestroyed.then(function () {
  30181. this._transport = null;
  30182. if (this._worker) {
  30183. this._worker.destroy();
  30184. this._worker = null;
  30185. }
  30186. }.bind(this));
  30187. },
  30188. /**
  30189. * Registers callbacks to indicate the document loading completion.
  30190. *
  30191. * @param {function} onFulfilled The callback for the loading completion.
  30192. * @param {function} onRejected The callback for the loading failure.
  30193. * @return {Promise} A promise that is resolved after the onFulfilled or
  30194. * onRejected callback.
  30195. */
  30196. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  30197. return this.promise.then.apply(this.promise, arguments);
  30198. }
  30199. };
  30200. return PDFDocumentLoadingTask;
  30201. })();
  30202. /**
  30203. * Abstract class to support range requests file loading.
  30204. * @class
  30205. * @alias PDFJS.PDFDataRangeTransport
  30206. * @param {number} length
  30207. * @param {Uint8Array} initialData
  30208. */
  30209. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  30210. function PDFDataRangeTransport(length, initialData) {
  30211. this.length = length;
  30212. this.initialData = initialData;
  30213. this._rangeListeners = [];
  30214. this._progressListeners = [];
  30215. this._progressiveReadListeners = [];
  30216. this._readyCapability = createPromiseCapability();
  30217. }
  30218. PDFDataRangeTransport.prototype =
  30219. /** @lends PDFDataRangeTransport.prototype */ {
  30220. addRangeListener:
  30221. function PDFDataRangeTransport_addRangeListener(listener) {
  30222. this._rangeListeners.push(listener);
  30223. },
  30224. addProgressListener:
  30225. function PDFDataRangeTransport_addProgressListener(listener) {
  30226. this._progressListeners.push(listener);
  30227. },
  30228. addProgressiveReadListener:
  30229. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  30230. this._progressiveReadListeners.push(listener);
  30231. },
  30232. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  30233. var listeners = this._rangeListeners;
  30234. for (var i = 0, n = listeners.length; i < n; ++i) {
  30235. listeners[i](begin, chunk);
  30236. }
  30237. },
  30238. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  30239. this._readyCapability.promise.then(function () {
  30240. var listeners = this._progressListeners;
  30241. for (var i = 0, n = listeners.length; i < n; ++i) {
  30242. listeners[i](loaded);
  30243. }
  30244. }.bind(this));
  30245. },
  30246. onDataProgressiveRead:
  30247. function PDFDataRangeTransport_onDataProgress(chunk) {
  30248. this._readyCapability.promise.then(function () {
  30249. var listeners = this._progressiveReadListeners;
  30250. for (var i = 0, n = listeners.length; i < n; ++i) {
  30251. listeners[i](chunk);
  30252. }
  30253. }.bind(this));
  30254. },
  30255. transportReady: function PDFDataRangeTransport_transportReady() {
  30256. this._readyCapability.resolve();
  30257. },
  30258. requestDataRange:
  30259. function PDFDataRangeTransport_requestDataRange(begin, end) {
  30260. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  30261. },
  30262. abort: function PDFDataRangeTransport_abort() {
  30263. }
  30264. };
  30265. return PDFDataRangeTransport;
  30266. })();
  30267. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  30268. /**
  30269. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  30270. * properties that can be read synchronously.
  30271. * @class
  30272. * @alias PDFDocumentProxy
  30273. */
  30274. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  30275. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  30276. this.pdfInfo = pdfInfo;
  30277. this.transport = transport;
  30278. this.loadingTask = loadingTask;
  30279. }
  30280. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  30281. /**
  30282. * @return {number} Total number of pages the PDF contains.
  30283. */
  30284. get numPages() {
  30285. return this.pdfInfo.numPages;
  30286. },
  30287. /**
  30288. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  30289. * unique.
  30290. */
  30291. get fingerprint() {
  30292. return this.pdfInfo.fingerprint;
  30293. },
  30294. /**
  30295. * @param {number} pageNumber The page number to get. The first page is 1.
  30296. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  30297. * object.
  30298. */
  30299. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  30300. return this.transport.getPage(pageNumber);
  30301. },
  30302. /**
  30303. * @param {{num: number, gen: number}} ref The page reference. Must have
  30304. * the 'num' and 'gen' properties.
  30305. * @return {Promise} A promise that is resolved with the page index that is
  30306. * associated with the reference.
  30307. */
  30308. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  30309. return this.transport.getPageIndex(ref);
  30310. },
  30311. /**
  30312. * @return {Promise} A promise that is resolved with a lookup table for
  30313. * mapping named destinations to reference numbers.
  30314. *
  30315. * This can be slow for large documents: use getDestination instead
  30316. */
  30317. getDestinations: function PDFDocumentProxy_getDestinations() {
  30318. return this.transport.getDestinations();
  30319. },
  30320. /**
  30321. * @param {string} id The named destination to get.
  30322. * @return {Promise} A promise that is resolved with all information
  30323. * of the given named destination.
  30324. */
  30325. getDestination: function PDFDocumentProxy_getDestination(id) {
  30326. return this.transport.getDestination(id);
  30327. },
  30328. /**
  30329. * @return {Promise} A promise that is resolved with:
  30330. * an Array containing the pageLabels that correspond to the pageIndexes,
  30331. * or `null` when no pageLabels are present in the PDF file.
  30332. */
  30333. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  30334. return this.transport.getPageLabels();
  30335. },
  30336. /**
  30337. * @return {Promise} A promise that is resolved with a lookup table for
  30338. * mapping named attachments to their content.
  30339. */
  30340. getAttachments: function PDFDocumentProxy_getAttachments() {
  30341. return this.transport.getAttachments();
  30342. },
  30343. /**
  30344. * @return {Promise} A promise that is resolved with an array of all the
  30345. * JavaScript strings in the name tree.
  30346. */
  30347. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  30348. return this.transport.getJavaScript();
  30349. },
  30350. /**
  30351. * @return {Promise} A promise that is resolved with an {Array} that is a
  30352. * tree outline (if it has one) of the PDF. The tree is in the format of:
  30353. * [
  30354. * {
  30355. * title: string,
  30356. * bold: boolean,
  30357. * italic: boolean,
  30358. * color: rgb Uint8Array,
  30359. * dest: dest obj,
  30360. * url: string,
  30361. * items: array of more items like this
  30362. * },
  30363. * ...
  30364. * ].
  30365. */
  30366. getOutline: function PDFDocumentProxy_getOutline() {
  30367. return this.transport.getOutline();
  30368. },
  30369. /**
  30370. * @return {Promise} A promise that is resolved with an {Object} that has
  30371. * info and metadata properties. Info is an {Object} filled with anything
  30372. * available in the information dictionary and similarly metadata is a
  30373. * {Metadata} object with information from the metadata section of the PDF.
  30374. */
  30375. getMetadata: function PDFDocumentProxy_getMetadata() {
  30376. return this.transport.getMetadata();
  30377. },
  30378. /**
  30379. * @return {Promise} A promise that is resolved with a TypedArray that has
  30380. * the raw data from the PDF.
  30381. */
  30382. getData: function PDFDocumentProxy_getData() {
  30383. return this.transport.getData();
  30384. },
  30385. /**
  30386. * @return {Promise} A promise that is resolved when the document's data
  30387. * is loaded. It is resolved with an {Object} that contains the length
  30388. * property that indicates size of the PDF data in bytes.
  30389. */
  30390. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  30391. return this.transport.downloadInfoCapability.promise;
  30392. },
  30393. /**
  30394. * @return {Promise} A promise this is resolved with current stats about
  30395. * document structures (see {@link PDFDocumentStats}).
  30396. */
  30397. getStats: function PDFDocumentProxy_getStats() {
  30398. return this.transport.getStats();
  30399. },
  30400. /**
  30401. * Cleans up resources allocated by the document, e.g. created @font-face.
  30402. */
  30403. cleanup: function PDFDocumentProxy_cleanup() {
  30404. this.transport.startCleanup();
  30405. },
  30406. /**
  30407. * Destroys current document instance and terminates worker.
  30408. */
  30409. destroy: function PDFDocumentProxy_destroy() {
  30410. return this.loadingTask.destroy();
  30411. }
  30412. };
  30413. return PDFDocumentProxy;
  30414. })();
  30415. /**
  30416. * Page getTextContent parameters.
  30417. *
  30418. * @typedef {Object} getTextContentParameters
  30419. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  30420. * whitespace with standard spaces (0x20). The default value is `false`.
  30421. */
  30422. /**
  30423. * Page text content.
  30424. *
  30425. * @typedef {Object} TextContent
  30426. * @property {array} items - array of {@link TextItem}
  30427. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  30428. * name.
  30429. */
  30430. /**
  30431. * Page text content part.
  30432. *
  30433. * @typedef {Object} TextItem
  30434. * @property {string} str - text content.
  30435. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  30436. * @property {array} transform - transformation matrix.
  30437. * @property {number} width - width in device space.
  30438. * @property {number} height - height in device space.
  30439. * @property {string} fontName - font name used by pdf.js for converted font.
  30440. */
  30441. /**
  30442. * Text style.
  30443. *
  30444. * @typedef {Object} TextStyle
  30445. * @property {number} ascent - font ascent.
  30446. * @property {number} descent - font descent.
  30447. * @property {boolean} vertical - text is in vertical mode.
  30448. * @property {string} fontFamily - possible font family
  30449. */
  30450. /**
  30451. * Page annotation parameters.
  30452. *
  30453. * @typedef {Object} GetAnnotationsParameters
  30454. * @param {string} intent - Determines the annotations that will be fetched,
  30455. * can be either 'display' (viewable annotations) or 'print'
  30456. * (printable annotations).
  30457. * If the parameter is omitted, all annotations are fetched.
  30458. */
  30459. /**
  30460. * Page render parameters.
  30461. *
  30462. * @typedef {Object} RenderParameters
  30463. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  30464. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  30465. * calling of PDFPage.getViewport method.
  30466. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  30467. * (default value is 'display').
  30468. * @property {Array} transform - (optional) Additional transform, applied
  30469. * just before viewport transform.
  30470. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  30471. * endLayout and appendImage functions.
  30472. * @property {function} continueCallback - (deprecated) A function that will be
  30473. * called each time the rendering is paused. To continue
  30474. * rendering call the function that is the first argument
  30475. * to the callback.
  30476. */
  30477. /**
  30478. * PDF page operator list.
  30479. *
  30480. * @typedef {Object} PDFOperatorList
  30481. * @property {Array} fnArray - Array containing the operator functions.
  30482. * @property {Array} argsArray - Array containing the arguments of the
  30483. * functions.
  30484. */
  30485. /**
  30486. * Proxy to a PDFPage in the worker thread.
  30487. * @class
  30488. * @alias PDFPageProxy
  30489. */
  30490. var PDFPageProxy = (function PDFPageProxyClosure() {
  30491. function PDFPageProxy(pageIndex, pageInfo, transport) {
  30492. this.pageIndex = pageIndex;
  30493. this.pageInfo = pageInfo;
  30494. this.transport = transport;
  30495. this.stats = new StatTimer();
  30496. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  30497. this.commonObjs = transport.commonObjs;
  30498. this.objs = new PDFObjects();
  30499. this.cleanupAfterRender = false;
  30500. this.pendingCleanup = false;
  30501. this.intentStates = Object.create(null);
  30502. this.destroyed = false;
  30503. }
  30504. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  30505. /**
  30506. * @return {number} Page number of the page. First page is 1.
  30507. */
  30508. get pageNumber() {
  30509. return this.pageIndex + 1;
  30510. },
  30511. /**
  30512. * @return {number} The number of degrees the page is rotated clockwise.
  30513. */
  30514. get rotate() {
  30515. return this.pageInfo.rotate;
  30516. },
  30517. /**
  30518. * @return {Object} The reference that points to this page. It has 'num' and
  30519. * 'gen' properties.
  30520. */
  30521. get ref() {
  30522. return this.pageInfo.ref;
  30523. },
  30524. /**
  30525. * @return {Array} An array of the visible portion of the PDF page in the
  30526. * user space units - [x1, y1, x2, y2].
  30527. */
  30528. get view() {
  30529. return this.pageInfo.view;
  30530. },
  30531. /**
  30532. * @param {number} scale The desired scale of the viewport.
  30533. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  30534. * defaults to the page rotation.
  30535. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  30536. * along with transforms required for rendering.
  30537. */
  30538. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  30539. if (arguments.length < 2) {
  30540. rotate = this.rotate;
  30541. }
  30542. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  30543. },
  30544. /**
  30545. * @param {GetAnnotationsParameters} params - Annotation parameters.
  30546. * @return {Promise} A promise that is resolved with an {Array} of the
  30547. * annotation objects.
  30548. */
  30549. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  30550. var intent = (params && params.intent) || null;
  30551. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  30552. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  30553. intent);
  30554. this.annotationsIntent = intent;
  30555. }
  30556. return this.annotationsPromise;
  30557. },
  30558. /**
  30559. * Begins the process of rendering a page to the desired context.
  30560. * @param {RenderParameters} params Page render parameters.
  30561. * @return {RenderTask} An object that contains the promise, which
  30562. * is resolved when the page finishes rendering.
  30563. */
  30564. render: function PDFPageProxy_render(params) {
  30565. var stats = this.stats;
  30566. stats.time('Overall');
  30567. // If there was a pending destroy cancel it so no cleanup happens during
  30568. // this call to render.
  30569. this.pendingCleanup = false;
  30570. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  30571. if (!this.intentStates[renderingIntent]) {
  30572. this.intentStates[renderingIntent] = Object.create(null);
  30573. }
  30574. var intentState = this.intentStates[renderingIntent];
  30575. // If there's no displayReadyCapability yet, then the operatorList
  30576. // was never requested before. Make the request and create the promise.
  30577. if (!intentState.displayReadyCapability) {
  30578. intentState.receivingOperatorList = true;
  30579. intentState.displayReadyCapability = createPromiseCapability();
  30580. intentState.operatorList = {
  30581. fnArray: [],
  30582. argsArray: [],
  30583. lastChunk: false
  30584. };
  30585. this.stats.time('Page Request');
  30586. this.transport.messageHandler.send('RenderPageRequest', {
  30587. pageIndex: this.pageNumber - 1,
  30588. intent: renderingIntent
  30589. });
  30590. }
  30591. var internalRenderTask = new InternalRenderTask(complete, params,
  30592. this.objs,
  30593. this.commonObjs,
  30594. intentState.operatorList,
  30595. this.pageNumber);
  30596. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  30597. if (!intentState.renderTasks) {
  30598. intentState.renderTasks = [];
  30599. }
  30600. intentState.renderTasks.push(internalRenderTask);
  30601. var renderTask = internalRenderTask.task;
  30602. // Obsolete parameter support
  30603. if (params.continueCallback) {
  30604. deprecated('render is used with continueCallback parameter');
  30605. renderTask.onContinue = params.continueCallback;
  30606. }
  30607. var self = this;
  30608. intentState.displayReadyCapability.promise.then(
  30609. function pageDisplayReadyPromise(transparency) {
  30610. if (self.pendingCleanup) {
  30611. complete();
  30612. return;
  30613. }
  30614. stats.time('Rendering');
  30615. internalRenderTask.initalizeGraphics(transparency);
  30616. internalRenderTask.operatorListChanged();
  30617. },
  30618. function pageDisplayReadPromiseError(reason) {
  30619. complete(reason);
  30620. }
  30621. );
  30622. function complete(error) {
  30623. var i = intentState.renderTasks.indexOf(internalRenderTask);
  30624. if (i >= 0) {
  30625. intentState.renderTasks.splice(i, 1);
  30626. }
  30627. if (self.cleanupAfterRender) {
  30628. self.pendingCleanup = true;
  30629. }
  30630. self._tryCleanup();
  30631. if (error) {
  30632. internalRenderTask.capability.reject(error);
  30633. } else {
  30634. internalRenderTask.capability.resolve();
  30635. }
  30636. stats.timeEnd('Rendering');
  30637. stats.timeEnd('Overall');
  30638. }
  30639. return renderTask;
  30640. },
  30641. /**
  30642. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  30643. * object that represents page's operator list.
  30644. */
  30645. getOperatorList: function PDFPageProxy_getOperatorList() {
  30646. function operatorListChanged() {
  30647. if (intentState.operatorList.lastChunk) {
  30648. intentState.opListReadCapability.resolve(intentState.operatorList);
  30649. var i = intentState.renderTasks.indexOf(opListTask);
  30650. if (i >= 0) {
  30651. intentState.renderTasks.splice(i, 1);
  30652. }
  30653. }
  30654. }
  30655. var renderingIntent = 'oplist';
  30656. if (!this.intentStates[renderingIntent]) {
  30657. this.intentStates[renderingIntent] = Object.create(null);
  30658. }
  30659. var intentState = this.intentStates[renderingIntent];
  30660. var opListTask;
  30661. if (!intentState.opListReadCapability) {
  30662. opListTask = {};
  30663. opListTask.operatorListChanged = operatorListChanged;
  30664. intentState.receivingOperatorList = true;
  30665. intentState.opListReadCapability = createPromiseCapability();
  30666. intentState.renderTasks = [];
  30667. intentState.renderTasks.push(opListTask);
  30668. intentState.operatorList = {
  30669. fnArray: [],
  30670. argsArray: [],
  30671. lastChunk: false
  30672. };
  30673. this.transport.messageHandler.send('RenderPageRequest', {
  30674. pageIndex: this.pageIndex,
  30675. intent: renderingIntent
  30676. });
  30677. }
  30678. return intentState.opListReadCapability.promise;
  30679. },
  30680. /**
  30681. * @param {getTextContentParameters} params - getTextContent parameters.
  30682. * @return {Promise} That is resolved a {@link TextContent}
  30683. * object that represent the page text content.
  30684. */
  30685. getTextContent: function PDFPageProxy_getTextContent(params) {
  30686. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  30687. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  30688. pageIndex: this.pageNumber - 1,
  30689. normalizeWhitespace: normalizeWhitespace,
  30690. });
  30691. },
  30692. /**
  30693. * Destroys page object.
  30694. */
  30695. _destroy: function PDFPageProxy_destroy() {
  30696. this.destroyed = true;
  30697. this.transport.pageCache[this.pageIndex] = null;
  30698. var waitOn = [];
  30699. Object.keys(this.intentStates).forEach(function(intent) {
  30700. if (intent === 'oplist') {
  30701. // Avoid errors below, since the renderTasks are just stubs.
  30702. return;
  30703. }
  30704. var intentState = this.intentStates[intent];
  30705. intentState.renderTasks.forEach(function(renderTask) {
  30706. var renderCompleted = renderTask.capability.promise.
  30707. catch(function () {}); // ignoring failures
  30708. waitOn.push(renderCompleted);
  30709. renderTask.cancel();
  30710. });
  30711. }, this);
  30712. this.objs.clear();
  30713. this.annotationsPromise = null;
  30714. this.pendingCleanup = false;
  30715. return Promise.all(waitOn);
  30716. },
  30717. /**
  30718. * Cleans up resources allocated by the page. (deprecated)
  30719. */
  30720. destroy: function() {
  30721. deprecated('page destroy method, use cleanup() instead');
  30722. this.cleanup();
  30723. },
  30724. /**
  30725. * Cleans up resources allocated by the page.
  30726. */
  30727. cleanup: function PDFPageProxy_cleanup() {
  30728. this.pendingCleanup = true;
  30729. this._tryCleanup();
  30730. },
  30731. /**
  30732. * For internal use only. Attempts to clean up if rendering is in a state
  30733. * where that's possible.
  30734. * @ignore
  30735. */
  30736. _tryCleanup: function PDFPageProxy_tryCleanup() {
  30737. if (!this.pendingCleanup ||
  30738. Object.keys(this.intentStates).some(function(intent) {
  30739. var intentState = this.intentStates[intent];
  30740. return (intentState.renderTasks.length !== 0 ||
  30741. intentState.receivingOperatorList);
  30742. }, this)) {
  30743. return;
  30744. }
  30745. Object.keys(this.intentStates).forEach(function(intent) {
  30746. delete this.intentStates[intent];
  30747. }, this);
  30748. this.objs.clear();
  30749. this.annotationsPromise = null;
  30750. this.pendingCleanup = false;
  30751. },
  30752. /**
  30753. * For internal use only.
  30754. * @ignore
  30755. */
  30756. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  30757. intent) {
  30758. var intentState = this.intentStates[intent];
  30759. // TODO Refactor RenderPageRequest to separate rendering
  30760. // and operator list logic
  30761. if (intentState.displayReadyCapability) {
  30762. intentState.displayReadyCapability.resolve(transparency);
  30763. }
  30764. },
  30765. /**
  30766. * For internal use only.
  30767. * @ignore
  30768. */
  30769. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  30770. intent) {
  30771. var intentState = this.intentStates[intent];
  30772. var i, ii;
  30773. // Add the new chunk to the current operator list.
  30774. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  30775. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  30776. intentState.operatorList.argsArray.push(
  30777. operatorListChunk.argsArray[i]);
  30778. }
  30779. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  30780. // Notify all the rendering tasks there are more operators to be consumed.
  30781. for (i = 0; i < intentState.renderTasks.length; i++) {
  30782. intentState.renderTasks[i].operatorListChanged();
  30783. }
  30784. if (operatorListChunk.lastChunk) {
  30785. intentState.receivingOperatorList = false;
  30786. this._tryCleanup();
  30787. }
  30788. }
  30789. };
  30790. return PDFPageProxy;
  30791. })();
  30792. /**
  30793. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  30794. * WorkerTransport for them. If creation of a web worker is not possible,
  30795. * a "fake" worker will be used instead.
  30796. * @class
  30797. */
  30798. var PDFWorker = (function PDFWorkerClosure() {
  30799. var nextFakeWorkerId = 0;
  30800. function getWorkerSrc() {
  30801. if (PDFJS.workerSrc) {
  30802. return PDFJS.workerSrc;
  30803. }
  30804. if (pdfjsFilePath) {
  30805. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  30806. }
  30807. error('No PDFJS.workerSrc specified');
  30808. }
  30809. // Loads worker code into main thread.
  30810. function setupFakeWorkerGlobal() {
  30811. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  30812. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  30813. // In the developer build load worker_loader which in turn loads all the
  30814. // other files and resolves the promise. In production only the
  30815. // pdf.worker.js file is needed.
  30816. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  30817. }
  30818. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  30819. }
  30820. function createCDNWrapper(url) {
  30821. // We will rely on blob URL's property to specify origin.
  30822. // We want this function to fail in case if createObjectURL or Blob do not
  30823. // exist or fail for some reason -- our Worker creation will fail anyway.
  30824. var wrapper = 'importScripts(\'' + url + '\');';
  30825. return URL.createObjectURL(new Blob([wrapper]));
  30826. }
  30827. function PDFWorker(name) {
  30828. this.name = name;
  30829. this.destroyed = false;
  30830. this._readyCapability = createPromiseCapability();
  30831. this._port = null;
  30832. this._webWorker = null;
  30833. this._messageHandler = null;
  30834. this._initialize();
  30835. }
  30836. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  30837. get promise() {
  30838. return this._readyCapability.promise;
  30839. },
  30840. get port() {
  30841. return this._port;
  30842. },
  30843. get messageHandler() {
  30844. return this._messageHandler;
  30845. },
  30846. _initialize: function PDFWorker_initialize() {
  30847. // If worker support isn't disabled explicit and the browser has worker
  30848. // support, create a new web worker and test if it/the browser fulfills
  30849. // all requirements to run parts of pdf.js in a web worker.
  30850. // Right now, the requirement is, that an Uint8Array is still an
  30851. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  30852. // Either workers are disabled, not supported or have thrown an exception.
  30853. // Thus, we fallback to a faked worker.
  30854. this._setupFakeWorker();
  30855. },
  30856. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  30857. if (!globalScope.PDFJS.disableWorker) {
  30858. warn('Setting up fake worker.');
  30859. globalScope.PDFJS.disableWorker = true;
  30860. }
  30861. setupFakeWorkerGlobal().then(function () {
  30862. if (this.destroyed) {
  30863. this._readyCapability.reject(new Error('Worker was destroyed'));
  30864. return;
  30865. }
  30866. // If we don't use a worker, just post/sendMessage to the main thread.
  30867. var port = {
  30868. _listeners: [],
  30869. postMessage: function (obj) {
  30870. var e = {data: obj};
  30871. this._listeners.forEach(function (listener) {
  30872. listener.call(this, e);
  30873. }, this);
  30874. },
  30875. addEventListener: function (name, listener) {
  30876. this._listeners.push(listener);
  30877. },
  30878. removeEventListener: function (name, listener) {
  30879. var i = this._listeners.indexOf(listener);
  30880. this._listeners.splice(i, 1);
  30881. },
  30882. terminate: function () {}
  30883. };
  30884. this._port = port;
  30885. // All fake workers use the same port, making id unique.
  30886. var id = 'fake' + (nextFakeWorkerId++);
  30887. // If the main thread is our worker, setup the handling for the
  30888. // messages -- the main thread sends to it self.
  30889. var workerHandler = new MessageHandler(id + '_worker', id, port);
  30890. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  30891. var messageHandler = new MessageHandler(id, id + '_worker', port);
  30892. this._messageHandler = messageHandler;
  30893. this._readyCapability.resolve();
  30894. }.bind(this));
  30895. },
  30896. /**
  30897. * Destroys the worker instance.
  30898. */
  30899. destroy: function PDFWorker_destroy() {
  30900. this.destroyed = true;
  30901. if (this._webWorker) {
  30902. // We need to terminate only web worker created resource.
  30903. this._webWorker.terminate();
  30904. this._webWorker = null;
  30905. }
  30906. this._port = null;
  30907. if (this._messageHandler) {
  30908. this._messageHandler.destroy();
  30909. this._messageHandler = null;
  30910. }
  30911. }
  30912. };
  30913. return PDFWorker;
  30914. })();
  30915. PDFJS.PDFWorker = PDFWorker;
  30916. /**
  30917. * For internal use only.
  30918. * @ignore
  30919. */
  30920. var WorkerTransport = (function WorkerTransportClosure() {
  30921. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  30922. this.messageHandler = messageHandler;
  30923. this.loadingTask = loadingTask;
  30924. this.pdfDataRangeTransport = pdfDataRangeTransport;
  30925. this.commonObjs = new PDFObjects();
  30926. this.fontLoader = new FontLoader(loadingTask.docId);
  30927. this.destroyed = false;
  30928. this.destroyCapability = null;
  30929. this.pageCache = [];
  30930. this.pagePromises = [];
  30931. this.downloadInfoCapability = createPromiseCapability();
  30932. this.setupMessageHandler();
  30933. }
  30934. WorkerTransport.prototype = {
  30935. destroy: function WorkerTransport_destroy() {
  30936. if (this.destroyCapability) {
  30937. return this.destroyCapability.promise;
  30938. }
  30939. this.destroyed = true;
  30940. this.destroyCapability = createPromiseCapability();
  30941. var waitOn = [];
  30942. // We need to wait for all renderings to be completed, e.g.
  30943. // timeout/rAF can take a long time.
  30944. this.pageCache.forEach(function (page) {
  30945. if (page) {
  30946. waitOn.push(page._destroy());
  30947. }
  30948. });
  30949. this.pageCache = [];
  30950. this.pagePromises = [];
  30951. var self = this;
  30952. // We also need to wait for the worker to finish its long running tasks.
  30953. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  30954. waitOn.push(terminated);
  30955. Promise.all(waitOn).then(function () {
  30956. self.fontLoader.clear();
  30957. if (self.pdfDataRangeTransport) {
  30958. self.pdfDataRangeTransport.abort();
  30959. self.pdfDataRangeTransport = null;
  30960. }
  30961. if (self.messageHandler) {
  30962. self.messageHandler.destroy();
  30963. self.messageHandler = null;
  30964. }
  30965. self.destroyCapability.resolve();
  30966. }, this.destroyCapability.reject);
  30967. return this.destroyCapability.promise;
  30968. },
  30969. setupMessageHandler:
  30970. function WorkerTransport_setupMessageHandler() {
  30971. var messageHandler = this.messageHandler;
  30972. function updatePassword(password) {
  30973. messageHandler.send('UpdatePassword', password);
  30974. }
  30975. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  30976. if (pdfDataRangeTransport) {
  30977. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  30978. messageHandler.send('OnDataRange', {
  30979. begin: begin,
  30980. chunk: chunk
  30981. });
  30982. });
  30983. pdfDataRangeTransport.addProgressListener(function(loaded) {
  30984. messageHandler.send('OnDataProgress', {
  30985. loaded: loaded
  30986. });
  30987. });
  30988. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  30989. messageHandler.send('OnDataRange', {
  30990. chunk: chunk
  30991. });
  30992. });
  30993. messageHandler.on('RequestDataRange',
  30994. function transportDataRange(data) {
  30995. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  30996. }, this);
  30997. }
  30998. messageHandler.on('GetDoc', function transportDoc(data) {
  30999. var pdfInfo = data.pdfInfo;
  31000. this.numPages = data.pdfInfo.numPages;
  31001. var loadingTask = this.loadingTask;
  31002. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  31003. this.pdfDocument = pdfDocument;
  31004. loadingTask._capability.resolve(pdfDocument);
  31005. }, this);
  31006. messageHandler.on('NeedPassword',
  31007. function transportNeedPassword(exception) {
  31008. var loadingTask = this.loadingTask;
  31009. if (loadingTask.onPassword) {
  31010. return loadingTask.onPassword(updatePassword,
  31011. PasswordResponses.NEED_PASSWORD);
  31012. }
  31013. loadingTask._capability.reject(
  31014. new PasswordException(exception.message, exception.code));
  31015. }, this);
  31016. messageHandler.on('IncorrectPassword',
  31017. function transportIncorrectPassword(exception) {
  31018. var loadingTask = this.loadingTask;
  31019. if (loadingTask.onPassword) {
  31020. return loadingTask.onPassword(updatePassword,
  31021. PasswordResponses.INCORRECT_PASSWORD);
  31022. }
  31023. loadingTask._capability.reject(
  31024. new PasswordException(exception.message, exception.code));
  31025. }, this);
  31026. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  31027. this.loadingTask._capability.reject(
  31028. new InvalidPDFException(exception.message));
  31029. }, this);
  31030. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  31031. this.loadingTask._capability.reject(
  31032. new MissingPDFException(exception.message));
  31033. }, this);
  31034. messageHandler.on('UnexpectedResponse',
  31035. function transportUnexpectedResponse(exception) {
  31036. this.loadingTask._capability.reject(
  31037. new UnexpectedResponseException(exception.message, exception.status));
  31038. }, this);
  31039. messageHandler.on('UnknownError',
  31040. function transportUnknownError(exception) {
  31041. this.loadingTask._capability.reject(
  31042. new UnknownErrorException(exception.message, exception.details));
  31043. }, this);
  31044. messageHandler.on('DataLoaded', function transportPage(data) {
  31045. this.downloadInfoCapability.resolve(data);
  31046. }, this);
  31047. messageHandler.on('PDFManagerReady', function transportPage(data) {
  31048. if (this.pdfDataRangeTransport) {
  31049. this.pdfDataRangeTransport.transportReady();
  31050. }
  31051. }, this);
  31052. messageHandler.on('StartRenderPage', function transportRender(data) {
  31053. if (this.destroyed) {
  31054. return; // Ignore any pending requests if the worker was terminated.
  31055. }
  31056. var page = this.pageCache[data.pageIndex];
  31057. page.stats.timeEnd('Page Request');
  31058. page._startRenderPage(data.transparency, data.intent);
  31059. }, this);
  31060. messageHandler.on('RenderPageChunk', function transportRender(data) {
  31061. if (this.destroyed) {
  31062. return; // Ignore any pending requests if the worker was terminated.
  31063. }
  31064. var page = this.pageCache[data.pageIndex];
  31065. page._renderPageChunk(data.operatorList, data.intent);
  31066. }, this);
  31067. messageHandler.on('commonobj', function transportObj(data) {
  31068. if (this.destroyed) {
  31069. return; // Ignore any pending requests if the worker was terminated.
  31070. }
  31071. var id = data[0];
  31072. var type = data[1];
  31073. if (this.commonObjs.hasData(id)) {
  31074. return;
  31075. }
  31076. switch (type) {
  31077. case 'Font':
  31078. var exportedData = data[2];
  31079. var font;
  31080. if ('error' in exportedData) {
  31081. var error = exportedData.error;
  31082. warn('Error during font loading: ' + error);
  31083. this.commonObjs.resolve(id, error);
  31084. break;
  31085. } else {
  31086. font = new FontFaceObject(exportedData);
  31087. }
  31088. this.fontLoader.bind(
  31089. [font],
  31090. function fontReady(fontObjs) {
  31091. this.commonObjs.resolve(id, font);
  31092. }.bind(this)
  31093. );
  31094. break;
  31095. case 'FontPath':
  31096. this.commonObjs.resolve(id, data[2]);
  31097. break;
  31098. default:
  31099. error('Got unknown common object type ' + type);
  31100. }
  31101. }, this);
  31102. messageHandler.on('obj', function transportObj(data) {
  31103. if (this.destroyed) {
  31104. return; // Ignore any pending requests if the worker was terminated.
  31105. }
  31106. var id = data[0];
  31107. var pageIndex = data[1];
  31108. var type = data[2];
  31109. var pageProxy = this.pageCache[pageIndex];
  31110. var imageData;
  31111. if (pageProxy.objs.hasData(id)) {
  31112. return;
  31113. }
  31114. switch (type) {
  31115. case 'JpegStream':
  31116. imageData = data[3];
  31117. loadJpegStream(id, imageData, pageProxy.objs);
  31118. break;
  31119. case 'Image':
  31120. imageData = data[3];
  31121. pageProxy.objs.resolve(id, imageData);
  31122. // heuristics that will allow not to store large data
  31123. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  31124. if (imageData && 'data' in imageData &&
  31125. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  31126. pageProxy.cleanupAfterRender = true;
  31127. }
  31128. break;
  31129. default:
  31130. error('Got unknown object type ' + type);
  31131. }
  31132. }, this);
  31133. messageHandler.on('DocProgress', function transportDocProgress(data) {
  31134. if (this.destroyed) {
  31135. return; // Ignore any pending requests if the worker was terminated.
  31136. }
  31137. var loadingTask = this.loadingTask;
  31138. if (loadingTask.onProgress) {
  31139. loadingTask.onProgress({
  31140. loaded: data.loaded,
  31141. total: data.total
  31142. });
  31143. }
  31144. }, this);
  31145. messageHandler.on('PageError', function transportError(data) {
  31146. if (this.destroyed) {
  31147. return; // Ignore any pending requests if the worker was terminated.
  31148. }
  31149. var page = this.pageCache[data.pageNum - 1];
  31150. var intentState = page.intentStates[data.intent];
  31151. if (intentState.displayReadyCapability) {
  31152. intentState.displayReadyCapability.reject(data.error);
  31153. } else {
  31154. error(data.error);
  31155. }
  31156. }, this);
  31157. messageHandler.on('UnsupportedFeature',
  31158. function transportUnsupportedFeature(data) {
  31159. if (this.destroyed) {
  31160. return; // Ignore any pending requests if the worker was terminated.
  31161. }
  31162. var featureId = data.featureId;
  31163. var loadingTask = this.loadingTask;
  31164. if (loadingTask.onUnsupportedFeature) {
  31165. loadingTask.onUnsupportedFeature(featureId);
  31166. }
  31167. PDFJS.UnsupportedManager.notify(featureId);
  31168. }, this);
  31169. messageHandler.on('JpegDecode', function(data) {
  31170. if (this.destroyed) {
  31171. return Promise.reject('Worker was terminated');
  31172. }
  31173. var imageUrl = data[0];
  31174. var components = data[1];
  31175. if (components !== 3 && components !== 1) {
  31176. return Promise.reject(
  31177. new Error('Only 3 components or 1 component can be returned'));
  31178. }
  31179. return new Promise(function (resolve, reject) {
  31180. var img = new Image();
  31181. img.onload = function () {
  31182. var width = img.width;
  31183. var height = img.height;
  31184. var size = width * height;
  31185. var rgbaLength = size * 4;
  31186. var buf = new Uint8Array(size * components);
  31187. var tmpCanvas = createScratchCanvas(width, height);
  31188. var tmpCtx = tmpCanvas.getContext('2d');
  31189. tmpCtx.drawImage(img, 0, 0);
  31190. var data = tmpCtx.getImageData(0, 0, width, height).data;
  31191. var i, j;
  31192. if (components === 3) {
  31193. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  31194. buf[j] = data[i];
  31195. buf[j + 1] = data[i + 1];
  31196. buf[j + 2] = data[i + 2];
  31197. }
  31198. } else if (components === 1) {
  31199. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  31200. buf[j] = data[i];
  31201. }
  31202. }
  31203. resolve({ data: buf, width: width, height: height});
  31204. };
  31205. img.onerror = function () {
  31206. reject(new Error('JpegDecode failed to load image'));
  31207. };
  31208. img.src = imageUrl;
  31209. });
  31210. }, this);
  31211. },
  31212. getData: function WorkerTransport_getData() {
  31213. return this.messageHandler.sendWithPromise('GetData', null);
  31214. },
  31215. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  31216. if (pageNumber <= 0 || pageNumber > this.numPages ||
  31217. (pageNumber|0) !== pageNumber) {
  31218. return Promise.reject(new Error('Invalid page request'));
  31219. }
  31220. var pageIndex = pageNumber - 1;
  31221. if (pageIndex in this.pagePromises) {
  31222. return this.pagePromises[pageIndex];
  31223. }
  31224. var promise = this.messageHandler.sendWithPromise('GetPage', {
  31225. pageIndex: pageIndex
  31226. }).then(function (pageInfo) {
  31227. if (this.destroyed) {
  31228. throw new Error('Transport destroyed');
  31229. }
  31230. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  31231. this.pageCache[pageIndex] = page;
  31232. return page;
  31233. }.bind(this));
  31234. this.pagePromises[pageIndex] = promise;
  31235. return promise;
  31236. },
  31237. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  31238. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  31239. },
  31240. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  31241. return this.messageHandler.sendWithPromise('GetAnnotations', {
  31242. pageIndex: pageIndex,
  31243. intent: intent,
  31244. });
  31245. },
  31246. getDestinations: function WorkerTransport_getDestinations() {
  31247. return this.messageHandler.sendWithPromise('GetDestinations', null);
  31248. },
  31249. getDestination: function WorkerTransport_getDestination(id) {
  31250. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  31251. },
  31252. getPageLabels: function WorkerTransport_getPageLabels() {
  31253. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  31254. },
  31255. getAttachments: function WorkerTransport_getAttachments() {
  31256. return this.messageHandler.sendWithPromise('GetAttachments', null);
  31257. },
  31258. getJavaScript: function WorkerTransport_getJavaScript() {
  31259. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  31260. },
  31261. getOutline: function WorkerTransport_getOutline() {
  31262. return this.messageHandler.sendWithPromise('GetOutline', null);
  31263. },
  31264. getMetadata: function WorkerTransport_getMetadata() {
  31265. return this.messageHandler.sendWithPromise('GetMetadata', null).
  31266. then(function transportMetadata(results) {
  31267. return {
  31268. info: results[0],
  31269. metadata: (results[1] ? new Metadata(results[1]) : null)
  31270. };
  31271. });
  31272. },
  31273. getStats: function WorkerTransport_getStats() {
  31274. return this.messageHandler.sendWithPromise('GetStats', null);
  31275. },
  31276. startCleanup: function WorkerTransport_startCleanup() {
  31277. this.messageHandler.sendWithPromise('Cleanup', null).
  31278. then(function endCleanup() {
  31279. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  31280. var page = this.pageCache[i];
  31281. if (page) {
  31282. page.cleanup();
  31283. }
  31284. }
  31285. this.commonObjs.clear();
  31286. this.fontLoader.clear();
  31287. }.bind(this));
  31288. }
  31289. };
  31290. return WorkerTransport;
  31291. })();
  31292. /**
  31293. * A PDF document and page is built of many objects. E.g. there are objects
  31294. * for fonts, images, rendering code and such. These objects might get processed
  31295. * inside of a worker. The `PDFObjects` implements some basic functions to
  31296. * manage these objects.
  31297. * @ignore
  31298. */
  31299. var PDFObjects = (function PDFObjectsClosure() {
  31300. function PDFObjects() {
  31301. this.objs = Object.create(null);
  31302. }
  31303. PDFObjects.prototype = {
  31304. /**
  31305. * Internal function.
  31306. * Ensures there is an object defined for `objId`.
  31307. */
  31308. ensureObj: function PDFObjects_ensureObj(objId) {
  31309. if (this.objs[objId]) {
  31310. return this.objs[objId];
  31311. }
  31312. var obj = {
  31313. capability: createPromiseCapability(),
  31314. data: null,
  31315. resolved: false
  31316. };
  31317. this.objs[objId] = obj;
  31318. return obj;
  31319. },
  31320. /**
  31321. * If called *without* callback, this returns the data of `objId` but the
  31322. * object needs to be resolved. If it isn't, this function throws.
  31323. *
  31324. * If called *with* a callback, the callback is called with the data of the
  31325. * object once the object is resolved. That means, if you call this
  31326. * function and the object is already resolved, the callback gets called
  31327. * right away.
  31328. */
  31329. get: function PDFObjects_get(objId, callback) {
  31330. // If there is a callback, then the get can be async and the object is
  31331. // not required to be resolved right now
  31332. if (callback) {
  31333. this.ensureObj(objId).capability.promise.then(callback);
  31334. return null;
  31335. }
  31336. // If there isn't a callback, the user expects to get the resolved data
  31337. // directly.
  31338. var obj = this.objs[objId];
  31339. // If there isn't an object yet or the object isn't resolved, then the
  31340. // data isn't ready yet!
  31341. if (!obj || !obj.resolved) {
  31342. error('Requesting object that isn\'t resolved yet ' + objId);
  31343. }
  31344. return obj.data;
  31345. },
  31346. /**
  31347. * Resolves the object `objId` with optional `data`.
  31348. */
  31349. resolve: function PDFObjects_resolve(objId, data) {
  31350. var obj = this.ensureObj(objId);
  31351. obj.resolved = true;
  31352. obj.data = data;
  31353. obj.capability.resolve(data);
  31354. },
  31355. isResolved: function PDFObjects_isResolved(objId) {
  31356. var objs = this.objs;
  31357. if (!objs[objId]) {
  31358. return false;
  31359. } else {
  31360. return objs[objId].resolved;
  31361. }
  31362. },
  31363. hasData: function PDFObjects_hasData(objId) {
  31364. return this.isResolved(objId);
  31365. },
  31366. /**
  31367. * Returns the data of `objId` if object exists, null otherwise.
  31368. */
  31369. getData: function PDFObjects_getData(objId) {
  31370. var objs = this.objs;
  31371. if (!objs[objId] || !objs[objId].resolved) {
  31372. return null;
  31373. } else {
  31374. return objs[objId].data;
  31375. }
  31376. },
  31377. clear: function PDFObjects_clear() {
  31378. this.objs = Object.create(null);
  31379. }
  31380. };
  31381. return PDFObjects;
  31382. })();
  31383. /**
  31384. * Allows controlling of the rendering tasks.
  31385. * @class
  31386. * @alias RenderTask
  31387. */
  31388. var RenderTask = (function RenderTaskClosure() {
  31389. function RenderTask(internalRenderTask) {
  31390. this._internalRenderTask = internalRenderTask;
  31391. /**
  31392. * Callback for incremental rendering -- a function that will be called
  31393. * each time the rendering is paused. To continue rendering call the
  31394. * function that is the first argument to the callback.
  31395. * @type {function}
  31396. */
  31397. this.onContinue = null;
  31398. }
  31399. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  31400. /**
  31401. * Promise for rendering task completion.
  31402. * @return {Promise}
  31403. */
  31404. get promise() {
  31405. return this._internalRenderTask.capability.promise;
  31406. },
  31407. /**
  31408. * Cancels the rendering task. If the task is currently rendering it will
  31409. * not be cancelled until graphics pauses with a timeout. The promise that
  31410. * this object extends will resolved when cancelled.
  31411. */
  31412. cancel: function RenderTask_cancel() {
  31413. this._internalRenderTask.cancel();
  31414. },
  31415. /**
  31416. * Registers callbacks to indicate the rendering task completion.
  31417. *
  31418. * @param {function} onFulfilled The callback for the rendering completion.
  31419. * @param {function} onRejected The callback for the rendering failure.
  31420. * @return {Promise} A promise that is resolved after the onFulfilled or
  31421. * onRejected callback.
  31422. */
  31423. then: function RenderTask_then(onFulfilled, onRejected) {
  31424. return this.promise.then.apply(this.promise, arguments);
  31425. }
  31426. };
  31427. return RenderTask;
  31428. })();
  31429. /**
  31430. * For internal use only.
  31431. * @ignore
  31432. */
  31433. var InternalRenderTask = (function InternalRenderTaskClosure() {
  31434. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  31435. pageNumber) {
  31436. this.callback = callback;
  31437. this.params = params;
  31438. this.objs = objs;
  31439. this.commonObjs = commonObjs;
  31440. this.operatorListIdx = null;
  31441. this.operatorList = operatorList;
  31442. this.pageNumber = pageNumber;
  31443. this.running = false;
  31444. this.graphicsReadyCallback = null;
  31445. this.graphicsReady = false;
  31446. this.useRequestAnimationFrame = false;
  31447. this.cancelled = false;
  31448. this.capability = createPromiseCapability();
  31449. this.task = new RenderTask(this);
  31450. // caching this-bound methods
  31451. this._continueBound = this._continue.bind(this);
  31452. this._scheduleNextBound = this._scheduleNext.bind(this);
  31453. this._nextBound = this._next.bind(this);
  31454. }
  31455. InternalRenderTask.prototype = {
  31456. initalizeGraphics:
  31457. function InternalRenderTask_initalizeGraphics(transparency) {
  31458. if (this.cancelled) {
  31459. return;
  31460. }
  31461. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  31462. globalScope.StepperManager.enabled) {
  31463. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  31464. this.stepper.init(this.operatorList);
  31465. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  31466. }
  31467. var params = this.params;
  31468. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  31469. this.objs, params.imageLayer);
  31470. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  31471. this.operatorListIdx = 0;
  31472. this.graphicsReady = true;
  31473. if (this.graphicsReadyCallback) {
  31474. this.graphicsReadyCallback();
  31475. }
  31476. },
  31477. cancel: function InternalRenderTask_cancel() {
  31478. this.running = false;
  31479. this.cancelled = true;
  31480. this.callback('cancelled');
  31481. },
  31482. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  31483. if (!this.graphicsReady) {
  31484. if (!this.graphicsReadyCallback) {
  31485. this.graphicsReadyCallback = this._continueBound;
  31486. }
  31487. return;
  31488. }
  31489. if (this.stepper) {
  31490. this.stepper.updateOperatorList(this.operatorList);
  31491. }
  31492. if (this.running) {
  31493. return;
  31494. }
  31495. this._continue();
  31496. },
  31497. _continue: function InternalRenderTask__continue() {
  31498. this.running = true;
  31499. if (this.cancelled) {
  31500. return;
  31501. }
  31502. if (this.task.onContinue) {
  31503. this.task.onContinue.call(this.task, this._scheduleNextBound);
  31504. } else {
  31505. this._scheduleNext();
  31506. }
  31507. },
  31508. _scheduleNext: function InternalRenderTask__scheduleNext() {
  31509. if (this.useRequestAnimationFrame) {
  31510. window.requestAnimationFrame(this._nextBound);
  31511. } else {
  31512. Promise.resolve(undefined).then(this._nextBound);
  31513. }
  31514. },
  31515. _next: function InternalRenderTask__next() {
  31516. if (this.cancelled) {
  31517. return;
  31518. }
  31519. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  31520. this.operatorListIdx,
  31521. this._continueBound,
  31522. this.stepper);
  31523. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  31524. this.running = false;
  31525. if (this.operatorList.lastChunk) {
  31526. this.gfx.endDrawing();
  31527. this.callback();
  31528. }
  31529. }
  31530. }
  31531. };
  31532. return InternalRenderTask;
  31533. })();
  31534. /**
  31535. * (Deprecated) Global observer of unsupported feature usages. Use
  31536. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  31537. */
  31538. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  31539. var listeners = [];
  31540. return {
  31541. listen: function (cb) {
  31542. deprecated('Global UnsupportedManager.listen is used: ' +
  31543. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  31544. listeners.push(cb);
  31545. },
  31546. notify: function (featureId) {
  31547. for (var i = 0, ii = listeners.length; i < ii; i++) {
  31548. listeners[i](featureId);
  31549. }
  31550. }
  31551. };
  31552. })();
  31553. exports.getDocument = PDFJS.getDocument;
  31554. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  31555. exports.PDFDocumentProxy = PDFDocumentProxy;
  31556. exports.PDFPageProxy = PDFPageProxy;
  31557. }));
  31558. (function (root, factory) {
  31559. {
  31560. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  31561. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  31562. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  31563. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  31564. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
  31565. }
  31566. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  31567. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer,
  31568. coreEncodings, coreStandardFonts, coreUnicode) {
  31569. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  31570. var FontType = sharedUtil.FontType;
  31571. var Util = sharedUtil.Util;
  31572. var assert = sharedUtil.assert;
  31573. var bytesToString = sharedUtil.bytesToString;
  31574. var error = sharedUtil.error;
  31575. var info = sharedUtil.info;
  31576. var isArray = sharedUtil.isArray;
  31577. var isInt = sharedUtil.isInt;
  31578. var isNum = sharedUtil.isNum;
  31579. var readUint32 = sharedUtil.readUint32;
  31580. var shadow = sharedUtil.shadow;
  31581. var stringToBytes = sharedUtil.stringToBytes;
  31582. var string32 = sharedUtil.string32;
  31583. var warn = sharedUtil.warn;
  31584. var Name = corePrimitives.Name;
  31585. var Stream = coreStream.Stream;
  31586. var Lexer = coreParser.Lexer;
  31587. var CMapFactory = coreCMap.CMapFactory;
  31588. var IdentityCMap = coreCMap.IdentityCMap;
  31589. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  31590. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  31591. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  31592. var ExpertCharset = coreCharsets.ExpertCharset;
  31593. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  31594. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  31595. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  31596. var StandardEncoding = coreEncodings.StandardEncoding;
  31597. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  31598. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  31599. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  31600. var ExpertEncoding = coreEncodings.ExpertEncoding;
  31601. var getEncoding = coreEncodings.getEncoding;
  31602. var getStdFontMap = coreStandardFonts.getStdFontMap;
  31603. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  31604. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  31605. var getSupplementalGlyphMapForArialBlack =
  31606. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  31607. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  31608. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  31609. // Unicode Private Use Area
  31610. var PRIVATE_USE_OFFSET_START = 0xE000;
  31611. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  31612. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  31613. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  31614. // except for Type 3 fonts
  31615. var PDF_GLYPH_SPACE_UNITS = 1000;
  31616. // Hinting is currently disabled due to unknown problems on windows
  31617. // in tracemonkey and various other pdfs with type1 fonts.
  31618. var HINTING_ENABLED = false;
  31619. // Accented charactars are not displayed properly on windows, using this flag
  31620. // to control analysis of seac charstrings.
  31621. var SEAC_ANALYSIS_ENABLED = false;
  31622. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  31623. var MAX_SUBR_NESTING = 10;
  31624. var FontFlags = {
  31625. FixedPitch: 1,
  31626. Serif: 2,
  31627. Symbolic: 4,
  31628. Script: 8,
  31629. Nonsymbolic: 32,
  31630. Italic: 64,
  31631. AllCap: 65536,
  31632. SmallCap: 131072,
  31633. ForceBold: 262144
  31634. };
  31635. var MacStandardGlyphOrdering = [
  31636. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  31637. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  31638. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  31639. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  31640. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  31641. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  31642. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  31643. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  31644. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  31645. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  31646. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  31647. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  31648. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  31649. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  31650. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  31651. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  31652. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  31653. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  31654. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  31655. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  31656. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  31657. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  31658. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  31659. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  31660. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  31661. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  31662. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  31663. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  31664. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  31665. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  31666. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  31667. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  31668. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  31669. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  31670. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  31671. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  31672. function adjustWidths(properties) {
  31673. if (!properties.fontMatrix) {
  31674. return;
  31675. }
  31676. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  31677. return;
  31678. }
  31679. // adjusting width to fontMatrix scale
  31680. var scale = 0.001 / properties.fontMatrix[0];
  31681. var glyphsWidths = properties.widths;
  31682. for (var glyph in glyphsWidths) {
  31683. glyphsWidths[glyph] *= scale;
  31684. }
  31685. properties.defaultWidth *= scale;
  31686. }
  31687. function getFontType(type, subtype) {
  31688. switch (type) {
  31689. case 'Type1':
  31690. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  31691. case 'CIDFontType0':
  31692. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  31693. FontType.CIDFONTTYPE0;
  31694. case 'OpenType':
  31695. return FontType.OPENTYPE;
  31696. case 'TrueType':
  31697. return FontType.TRUETYPE;
  31698. case 'CIDFontType2':
  31699. return FontType.CIDFONTTYPE2;
  31700. case 'MMType1':
  31701. return FontType.MMTYPE1;
  31702. case 'Type0':
  31703. return FontType.TYPE0;
  31704. default:
  31705. return FontType.UNKNOWN;
  31706. }
  31707. }
  31708. var Glyph = (function GlyphClosure() {
  31709. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  31710. isSpace) {
  31711. this.fontChar = fontChar;
  31712. this.unicode = unicode;
  31713. this.accent = accent;
  31714. this.width = width;
  31715. this.vmetric = vmetric;
  31716. this.operatorListId = operatorListId;
  31717. this.isSpace = isSpace;
  31718. }
  31719. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  31720. vmetric, operatorListId, isSpace) {
  31721. return this.fontChar === fontChar &&
  31722. this.unicode === unicode &&
  31723. this.accent === accent &&
  31724. this.width === width &&
  31725. this.vmetric === vmetric &&
  31726. this.operatorListId === operatorListId &&
  31727. this.isSpace === isSpace;
  31728. };
  31729. return Glyph;
  31730. })();
  31731. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  31732. function ToUnicodeMap(cmap) {
  31733. // The elements of this._map can be integers or strings, depending on how
  31734. // |cmap| was created.
  31735. this._map = cmap;
  31736. }
  31737. ToUnicodeMap.prototype = {
  31738. get length() {
  31739. return this._map.length;
  31740. },
  31741. forEach: function(callback) {
  31742. for (var charCode in this._map) {
  31743. callback(charCode, this._map[charCode].charCodeAt(0));
  31744. }
  31745. },
  31746. has: function(i) {
  31747. return this._map[i] !== undefined;
  31748. },
  31749. get: function(i) {
  31750. return this._map[i];
  31751. },
  31752. charCodeOf: function(v) {
  31753. return this._map.indexOf(v);
  31754. }
  31755. };
  31756. return ToUnicodeMap;
  31757. })();
  31758. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  31759. function IdentityToUnicodeMap(firstChar, lastChar) {
  31760. this.firstChar = firstChar;
  31761. this.lastChar = lastChar;
  31762. }
  31763. IdentityToUnicodeMap.prototype = {
  31764. get length() {
  31765. return (this.lastChar + 1) - this.firstChar;
  31766. },
  31767. forEach: function (callback) {
  31768. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  31769. callback(i, i);
  31770. }
  31771. },
  31772. has: function (i) {
  31773. return this.firstChar <= i && i <= this.lastChar;
  31774. },
  31775. get: function (i) {
  31776. if (this.firstChar <= i && i <= this.lastChar) {
  31777. return String.fromCharCode(i);
  31778. }
  31779. return undefined;
  31780. },
  31781. charCodeOf: function (v) {
  31782. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  31783. }
  31784. };
  31785. return IdentityToUnicodeMap;
  31786. })();
  31787. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  31788. function writeInt16(dest, offset, num) {
  31789. dest[offset] = (num >> 8) & 0xFF;
  31790. dest[offset + 1] = num & 0xFF;
  31791. }
  31792. function writeInt32(dest, offset, num) {
  31793. dest[offset] = (num >> 24) & 0xFF;
  31794. dest[offset + 1] = (num >> 16) & 0xFF;
  31795. dest[offset + 2] = (num >> 8) & 0xFF;
  31796. dest[offset + 3] = num & 0xFF;
  31797. }
  31798. function writeData(dest, offset, data) {
  31799. var i, ii;
  31800. if (data instanceof Uint8Array) {
  31801. dest.set(data, offset);
  31802. } else if (typeof data === 'string') {
  31803. for (i = 0, ii = data.length; i < ii; i++) {
  31804. dest[offset++] = data.charCodeAt(i) & 0xFF;
  31805. }
  31806. } else {
  31807. // treating everything else as array
  31808. for (i = 0, ii = data.length; i < ii; i++) {
  31809. dest[offset++] = data[i] & 0xFF;
  31810. }
  31811. }
  31812. }
  31813. function OpenTypeFileBuilder(sfnt) {
  31814. this.sfnt = sfnt;
  31815. this.tables = Object.create(null);
  31816. }
  31817. OpenTypeFileBuilder.getSearchParams =
  31818. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  31819. var maxPower2 = 1, log2 = 0;
  31820. while ((maxPower2 ^ entriesCount) > maxPower2) {
  31821. maxPower2 <<= 1;
  31822. log2++;
  31823. }
  31824. var searchRange = maxPower2 * entrySize;
  31825. return {
  31826. range: searchRange,
  31827. entry: log2,
  31828. rangeShift: entrySize * entriesCount - searchRange
  31829. };
  31830. };
  31831. var OTF_HEADER_SIZE = 12;
  31832. var OTF_TABLE_ENTRY_SIZE = 16;
  31833. OpenTypeFileBuilder.prototype = {
  31834. toArray: function OpenTypeFileBuilder_toArray() {
  31835. var sfnt = this.sfnt;
  31836. // Tables needs to be written by ascendant alphabetic order
  31837. var tables = this.tables;
  31838. var tablesNames = Object.keys(tables);
  31839. tablesNames.sort();
  31840. var numTables = tablesNames.length;
  31841. var i, j, jj, table, tableName;
  31842. // layout the tables data
  31843. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  31844. var tableOffsets = [offset];
  31845. for (i = 0; i < numTables; i++) {
  31846. table = tables[tablesNames[i]];
  31847. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  31848. offset += paddedLength;
  31849. tableOffsets.push(offset);
  31850. }
  31851. var file = new Uint8Array(offset);
  31852. // write the table data first (mostly for checksum)
  31853. for (i = 0; i < numTables; i++) {
  31854. table = tables[tablesNames[i]];
  31855. writeData(file, tableOffsets[i], table);
  31856. }
  31857. // sfnt version (4 bytes)
  31858. if (sfnt === 'true') {
  31859. // Windows hates the Mac TrueType sfnt version number
  31860. sfnt = string32(0x00010000);
  31861. }
  31862. file[0] = sfnt.charCodeAt(0) & 0xFF;
  31863. file[1] = sfnt.charCodeAt(1) & 0xFF;
  31864. file[2] = sfnt.charCodeAt(2) & 0xFF;
  31865. file[3] = sfnt.charCodeAt(3) & 0xFF;
  31866. // numTables (2 bytes)
  31867. writeInt16(file, 4, numTables);
  31868. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  31869. // searchRange (2 bytes)
  31870. writeInt16(file, 6, searchParams.range);
  31871. // entrySelector (2 bytes)
  31872. writeInt16(file, 8, searchParams.entry);
  31873. // rangeShift (2 bytes)
  31874. writeInt16(file, 10, searchParams.rangeShift);
  31875. offset = OTF_HEADER_SIZE;
  31876. // writing table entries
  31877. for (i = 0; i < numTables; i++) {
  31878. tableName = tablesNames[i];
  31879. file[offset] = tableName.charCodeAt(0) & 0xFF;
  31880. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  31881. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  31882. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  31883. // checksum
  31884. var checksum = 0;
  31885. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  31886. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  31887. (file[j + 2] << 8) + file[j + 3];
  31888. checksum = (checksum + quad) | 0;
  31889. }
  31890. writeInt32(file, offset + 4, checksum);
  31891. // offset
  31892. writeInt32(file, offset + 8, tableOffsets[i]);
  31893. // length
  31894. writeInt32(file, offset + 12, tables[tableName].length);
  31895. offset += OTF_TABLE_ENTRY_SIZE;
  31896. }
  31897. return file;
  31898. },
  31899. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  31900. if (tag in this.tables) {
  31901. throw new Error('Table ' + tag + ' already exists');
  31902. }
  31903. this.tables[tag] = data;
  31904. }
  31905. };
  31906. return OpenTypeFileBuilder;
  31907. })();
  31908. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  31909. // issues when they are painted on the canvas, e.g. complex-script shaping or
  31910. // control/whitespace characters. The ranges are listed in pairs: the first item
  31911. // is a code of the first problematic code, the second one is the next
  31912. // non-problematic code. The ranges must be in sorted order.
  31913. var ProblematicCharRanges = new Int32Array([
  31914. // Control characters.
  31915. 0x0000, 0x0020,
  31916. 0x007F, 0x00A1,
  31917. 0x00AD, 0x00AE,
  31918. // Chars that is used in complex-script shaping.
  31919. 0x0600, 0x0780,
  31920. 0x08A0, 0x10A0,
  31921. 0x1780, 0x1800,
  31922. // General punctuation chars.
  31923. 0x2000, 0x2010,
  31924. 0x2011, 0x2012,
  31925. 0x2028, 0x2030,
  31926. 0x205F, 0x2070,
  31927. 0x25CC, 0x25CD,
  31928. // Chars that is used in complex-script shaping.
  31929. 0xAA60, 0xAA80,
  31930. // Specials Unicode block.
  31931. 0xFFF0, 0x10000
  31932. ]);
  31933. /**
  31934. * 'Font' is the class the outside world should use, it encapsulate all the font
  31935. * decoding logics whatever type it is (assuming the font type is supported).
  31936. *
  31937. * For example to read a Type1 font and to attach it to the document:
  31938. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  31939. * type1Font.bind();
  31940. */
  31941. var Font = (function FontClosure() {
  31942. function Font(name, file, properties) {
  31943. var charCode, glyphName, fontChar;
  31944. this.name = name;
  31945. this.loadedName = properties.loadedName;
  31946. this.isType3Font = properties.isType3Font;
  31947. this.sizes = [];
  31948. this.glyphCache = Object.create(null);
  31949. var names = name.split('+');
  31950. names = names.length > 1 ? names[1] : names[0];
  31951. names = names.split(/[-,_]/g)[0];
  31952. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  31953. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  31954. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  31955. var type = properties.type;
  31956. var subtype = properties.subtype;
  31957. this.type = type;
  31958. this.fallbackName = (this.isMonospace ? 'monospace' :
  31959. (this.isSerifFont ? 'serif' : 'sans-serif'));
  31960. this.differences = properties.differences;
  31961. this.widths = properties.widths;
  31962. this.defaultWidth = properties.defaultWidth;
  31963. this.composite = properties.composite;
  31964. this.wideChars = properties.wideChars;
  31965. this.cMap = properties.cMap;
  31966. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  31967. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  31968. this.fontMatrix = properties.fontMatrix;
  31969. this.bbox = properties.bbox;
  31970. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  31971. this.toFontChar = [];
  31972. if (properties.type === 'Type3') {
  31973. for (charCode = 0; charCode < 256; charCode++) {
  31974. this.toFontChar[charCode] = (this.differences[charCode] ||
  31975. properties.defaultEncoding[charCode]);
  31976. }
  31977. this.fontType = FontType.TYPE3;
  31978. return;
  31979. }
  31980. this.cidEncoding = properties.cidEncoding;
  31981. this.vertical = properties.vertical;
  31982. if (this.vertical) {
  31983. this.vmetrics = properties.vmetrics;
  31984. this.defaultVMetrics = properties.defaultVMetrics;
  31985. }
  31986. var glyphsUnicodeMap;
  31987. if (!file || file.isEmpty) {
  31988. if (file) {
  31989. // Some bad PDF generators will include empty font files,
  31990. // attempting to recover by assuming that no file exists.
  31991. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  31992. }
  31993. this.missingFile = true;
  31994. // The file data is not specified. Trying to fix the font name
  31995. // to be used with the canvas.font.
  31996. var fontName = name.replace(/[,_]/g, '-');
  31997. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  31998. var isStandardFont = !!stdFontMap[fontName] ||
  31999. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32000. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32001. this.bold = (fontName.search(/bold/gi) !== -1);
  32002. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32003. (fontName.search(/italic/gi) !== -1));
  32004. // Use 'name' instead of 'fontName' here because the original
  32005. // name ArialBlack for example will be replaced by Helvetica.
  32006. this.black = (name.search(/Black/g) !== -1);
  32007. // if at least one width is present, remeasure all chars when exists
  32008. this.remeasure = Object.keys(this.widths).length > 0;
  32009. if (isStandardFont && type === 'CIDFontType2' &&
  32010. properties.cidEncoding.indexOf('Identity-') === 0) {
  32011. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  32012. // Standard fonts might be embedded as CID font without glyph mapping.
  32013. // Building one based on GlyphMapForStandardFonts.
  32014. var map = [];
  32015. for (charCode in GlyphMapForStandardFonts) {
  32016. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32017. }
  32018. if (/ArialBlack/i.test(name)) {
  32019. var SupplementalGlyphMapForArialBlack =
  32020. getSupplementalGlyphMapForArialBlack();
  32021. for (charCode in SupplementalGlyphMapForArialBlack) {
  32022. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32023. }
  32024. }
  32025. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32026. if (!isIdentityUnicode) {
  32027. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32028. map[+charCode] = unicodeCharCode;
  32029. });
  32030. }
  32031. this.toFontChar = map;
  32032. this.toUnicode = new ToUnicodeMap(map);
  32033. } else if (/Symbol/i.test(fontName)) {
  32034. var symbols = SymbolSetEncoding;
  32035. glyphsUnicodeMap = getGlyphsUnicode();
  32036. for (charCode in symbols) {
  32037. fontChar = glyphsUnicodeMap[symbols[charCode]];
  32038. if (!fontChar) {
  32039. continue;
  32040. }
  32041. this.toFontChar[charCode] = fontChar;
  32042. }
  32043. for (charCode in properties.differences) {
  32044. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  32045. if (!fontChar) {
  32046. continue;
  32047. }
  32048. this.toFontChar[charCode] = fontChar;
  32049. }
  32050. } else if (/Dingbats/i.test(fontName)) {
  32051. glyphsUnicodeMap = getDingbatsGlyphsUnicode();
  32052. if (/Wingdings/i.test(name)) {
  32053. warn('Wingdings font without embedded font file, ' +
  32054. 'falling back to the ZapfDingbats encoding.');
  32055. }
  32056. var dingbats = ZapfDingbatsEncoding;
  32057. for (charCode in dingbats) {
  32058. fontChar = glyphsUnicodeMap[dingbats[charCode]];
  32059. if (!fontChar) {
  32060. continue;
  32061. }
  32062. this.toFontChar[charCode] = fontChar;
  32063. }
  32064. for (charCode in properties.differences) {
  32065. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  32066. if (!fontChar) {
  32067. continue;
  32068. }
  32069. this.toFontChar[charCode] = fontChar;
  32070. }
  32071. } else if (isStandardFont) {
  32072. this.toFontChar = [];
  32073. glyphsUnicodeMap = getGlyphsUnicode();
  32074. for (charCode in properties.defaultEncoding) {
  32075. glyphName = (properties.differences[charCode] ||
  32076. properties.defaultEncoding[charCode]);
  32077. this.toFontChar[charCode] = glyphsUnicodeMap[glyphName];
  32078. }
  32079. } else {
  32080. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  32081. glyphsUnicodeMap = getGlyphsUnicode();
  32082. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32083. if (notCidFont) {
  32084. glyphName = (properties.differences[charCode] ||
  32085. properties.defaultEncoding[charCode]);
  32086. unicodeCharCode = (glyphsUnicodeMap[glyphName] || unicodeCharCode);
  32087. }
  32088. this.toFontChar[charCode] = unicodeCharCode;
  32089. }.bind(this));
  32090. }
  32091. this.loadedName = fontName.split('-')[0];
  32092. this.loading = false;
  32093. this.fontType = getFontType(type, subtype);
  32094. return;
  32095. }
  32096. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32097. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32098. // Some TrueType fonts by mistake claim Type1C
  32099. if (isTrueTypeFile(file)) {
  32100. subtype = 'TrueType';
  32101. } else {
  32102. type = 'Type1';
  32103. }
  32104. }
  32105. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32106. type = 'CIDFontType0';
  32107. }
  32108. if (subtype === 'OpenType') {
  32109. type = 'OpenType';
  32110. }
  32111. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32112. if (type === 'CIDFontType0') {
  32113. if (isType1File(file)) {
  32114. subtype = 'CIDFontType0';
  32115. } else if (isOpenTypeFile(file)) {
  32116. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  32117. type = subtype = 'OpenType';
  32118. } else {
  32119. subtype = 'CIDFontType0C';
  32120. }
  32121. }
  32122. var data;
  32123. switch (type) {
  32124. case 'MMType1':
  32125. info('MMType1 font (' + name + '), falling back to Type1.');
  32126. /* falls through */
  32127. case 'Type1':
  32128. case 'CIDFontType0':
  32129. this.mimetype = 'font/opentype';
  32130. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32131. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32132. adjustWidths(properties);
  32133. // Wrap the CFF data inside an OTF font file
  32134. data = this.convert(name, cff, properties);
  32135. break;
  32136. case 'OpenType':
  32137. case 'TrueType':
  32138. case 'CIDFontType2':
  32139. this.mimetype = 'font/opentype';
  32140. // Repair the TrueType file. It is can be damaged in the point of
  32141. // view of the sanitizer
  32142. data = this.checkAndRepair(name, file, properties);
  32143. if (this.isOpenType) {
  32144. adjustWidths(properties);
  32145. type = 'OpenType';
  32146. }
  32147. break;
  32148. default:
  32149. error('Font ' + type + ' is not supported');
  32150. break;
  32151. }
  32152. this.data = data;
  32153. this.fontType = getFontType(type, subtype);
  32154. // Transfer some properties again that could change during font conversion
  32155. this.fontMatrix = properties.fontMatrix;
  32156. this.widths = properties.widths;
  32157. this.defaultWidth = properties.defaultWidth;
  32158. this.encoding = properties.baseEncoding;
  32159. this.seacMap = properties.seacMap;
  32160. this.loading = true;
  32161. }
  32162. Font.getFontID = (function () {
  32163. var ID = 1;
  32164. return function Font_getFontID() {
  32165. return String(ID++);
  32166. };
  32167. })();
  32168. function int16(b0, b1) {
  32169. return (b0 << 8) + b1;
  32170. }
  32171. function int32(b0, b1, b2, b3) {
  32172. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32173. }
  32174. function string16(value) {
  32175. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32176. }
  32177. function safeString16(value) {
  32178. // clamp value to the 16-bit int range
  32179. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32180. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32181. }
  32182. function isTrueTypeFile(file) {
  32183. var header = file.peekBytes(4);
  32184. return readUint32(header, 0) === 0x00010000;
  32185. }
  32186. function isOpenTypeFile(file) {
  32187. var header = file.peekBytes(4);
  32188. return bytesToString(header) === 'OTTO';
  32189. }
  32190. function isType1File(file) {
  32191. var header = file.peekBytes(2);
  32192. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32193. if (header[0] === 0x25 && header[1] === 0x21) {
  32194. return true;
  32195. }
  32196. // ... obviously some fonts violate that part of the specification,
  32197. // please refer to the comment in |Type1Font| below.
  32198. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32199. return true;
  32200. }
  32201. return false;
  32202. }
  32203. /**
  32204. * Helper function for |adjustMapping|.
  32205. * @return {boolean}
  32206. */
  32207. function isProblematicUnicodeLocation(code) {
  32208. // Using binary search to find a range start.
  32209. var i = 0, j = ProblematicCharRanges.length - 1;
  32210. while (i < j) {
  32211. var c = (i + j + 1) >> 1;
  32212. if (code < ProblematicCharRanges[c]) {
  32213. j = c - 1;
  32214. } else {
  32215. i = c;
  32216. }
  32217. }
  32218. // Even index means code in problematic range.
  32219. return !(i & 1);
  32220. }
  32221. /**
  32222. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32223. * with their unicode value. It also moves char codes that are in known
  32224. * problematic locations.
  32225. * @return {Object} Two properties:
  32226. * 'toFontChar' - maps original char codes(the value that will be read
  32227. * from commands such as show text) to the char codes that will be used in the
  32228. * font that we build
  32229. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32230. */
  32231. function adjustMapping(charCodeToGlyphId, properties) {
  32232. var toUnicode = properties.toUnicode;
  32233. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32234. var isIdentityUnicode =
  32235. properties.toUnicode instanceof IdentityToUnicodeMap;
  32236. var newMap = Object.create(null);
  32237. var toFontChar = [];
  32238. var usedFontCharCodes = [];
  32239. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32240. for (var originalCharCode in charCodeToGlyphId) {
  32241. originalCharCode |= 0;
  32242. var glyphId = charCodeToGlyphId[originalCharCode];
  32243. var fontCharCode = originalCharCode;
  32244. // First try to map the value to a unicode position if a non identity map
  32245. // was created.
  32246. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32247. var unicode = toUnicode.get(fontCharCode);
  32248. // TODO: Try to map ligatures to the correct spot.
  32249. if (unicode.length === 1) {
  32250. fontCharCode = unicode.charCodeAt(0);
  32251. }
  32252. }
  32253. // Try to move control characters, special characters and already mapped
  32254. // characters to the private use area since they will not be drawn by
  32255. // canvas if left in their current position. Also, move characters if the
  32256. // font was symbolic and there is only an identity unicode map since the
  32257. // characters probably aren't in the correct position (fixes an issue
  32258. // with firefox and thuluthfont).
  32259. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32260. isProblematicUnicodeLocation(fontCharCode) ||
  32261. (isSymbolic && isIdentityUnicode)) &&
  32262. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32263. // Loop to try and find a free spot in the private use area.
  32264. do {
  32265. fontCharCode = nextAvailableFontCharCode++;
  32266. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32267. fontCharCode = 0xF020;
  32268. nextAvailableFontCharCode = fontCharCode + 1;
  32269. }
  32270. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32271. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32272. }
  32273. newMap[fontCharCode] = glyphId;
  32274. toFontChar[originalCharCode] = fontCharCode;
  32275. usedFontCharCodes[fontCharCode] = true;
  32276. }
  32277. return {
  32278. toFontChar: toFontChar,
  32279. charCodeToGlyphId: newMap,
  32280. nextAvailableFontCharCode: nextAvailableFontCharCode
  32281. };
  32282. }
  32283. function getRanges(glyphs, numGlyphs) {
  32284. // Array.sort() sorts by characters, not numerically, so convert to an
  32285. // array of characters.
  32286. var codes = [];
  32287. for (var charCode in glyphs) {
  32288. // Remove an invalid glyph ID mappings to make OTS happy.
  32289. if (glyphs[charCode] >= numGlyphs) {
  32290. continue;
  32291. }
  32292. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32293. }
  32294. codes.sort(function fontGetRangesSort(a, b) {
  32295. return a.fontCharCode - b.fontCharCode;
  32296. });
  32297. // Split the sorted codes into ranges.
  32298. var ranges = [];
  32299. var length = codes.length;
  32300. for (var n = 0; n < length; ) {
  32301. var start = codes[n].fontCharCode;
  32302. var codeIndices = [codes[n].glyphId];
  32303. ++n;
  32304. var end = start;
  32305. while (n < length && end + 1 === codes[n].fontCharCode) {
  32306. codeIndices.push(codes[n].glyphId);
  32307. ++end;
  32308. ++n;
  32309. if (end === 0xFFFF) {
  32310. break;
  32311. }
  32312. }
  32313. ranges.push([start, end, codeIndices]);
  32314. }
  32315. return ranges;
  32316. }
  32317. function createCmapTable(glyphs, numGlyphs) {
  32318. var ranges = getRanges(glyphs, numGlyphs);
  32319. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32320. var cmap = '\x00\x00' + // version
  32321. string16(numTables) + // numTables
  32322. '\x00\x03' + // platformID
  32323. '\x00\x01' + // encodingID
  32324. string32(4 + numTables * 8); // start of the table record
  32325. var i, ii, j, jj;
  32326. for (i = ranges.length - 1; i >= 0; --i) {
  32327. if (ranges[i][0] <= 0xFFFF) { break; }
  32328. }
  32329. var bmpLength = i + 1;
  32330. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32331. ranges[i][1] = 0xFFFE;
  32332. }
  32333. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32334. var segCount = bmpLength + trailingRangesCount;
  32335. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32336. // Fill up the 4 parallel arrays describing the segments.
  32337. var startCount = '';
  32338. var endCount = '';
  32339. var idDeltas = '';
  32340. var idRangeOffsets = '';
  32341. var glyphsIds = '';
  32342. var bias = 0;
  32343. var range, start, end, codes;
  32344. for (i = 0, ii = bmpLength; i < ii; i++) {
  32345. range = ranges[i];
  32346. start = range[0];
  32347. end = range[1];
  32348. startCount += string16(start);
  32349. endCount += string16(end);
  32350. codes = range[2];
  32351. var contiguous = true;
  32352. for (j = 1, jj = codes.length; j < jj; ++j) {
  32353. if (codes[j] !== codes[j - 1] + 1) {
  32354. contiguous = false;
  32355. break;
  32356. }
  32357. }
  32358. if (!contiguous) {
  32359. var offset = (segCount - i) * 2 + bias * 2;
  32360. bias += (end - start + 1);
  32361. idDeltas += string16(0);
  32362. idRangeOffsets += string16(offset);
  32363. for (j = 0, jj = codes.length; j < jj; ++j) {
  32364. glyphsIds += string16(codes[j]);
  32365. }
  32366. } else {
  32367. var startCode = codes[0];
  32368. idDeltas += string16((startCode - start) & 0xFFFF);
  32369. idRangeOffsets += string16(0);
  32370. }
  32371. }
  32372. if (trailingRangesCount > 0) {
  32373. endCount += '\xFF\xFF';
  32374. startCount += '\xFF\xFF';
  32375. idDeltas += '\x00\x01';
  32376. idRangeOffsets += '\x00\x00';
  32377. }
  32378. var format314 = '\x00\x00' + // language
  32379. string16(2 * segCount) +
  32380. string16(searchParams.range) +
  32381. string16(searchParams.entry) +
  32382. string16(searchParams.rangeShift) +
  32383. endCount + '\x00\x00' + startCount +
  32384. idDeltas + idRangeOffsets + glyphsIds;
  32385. var format31012 = '';
  32386. var header31012 = '';
  32387. if (numTables > 1) {
  32388. cmap += '\x00\x03' + // platformID
  32389. '\x00\x0A' + // encodingID
  32390. string32(4 + numTables * 8 +
  32391. 4 + format314.length); // start of the table record
  32392. format31012 = '';
  32393. for (i = 0, ii = ranges.length; i < ii; i++) {
  32394. range = ranges[i];
  32395. start = range[0];
  32396. codes = range[2];
  32397. var code = codes[0];
  32398. for (j = 1, jj = codes.length; j < jj; ++j) {
  32399. if (codes[j] !== codes[j - 1] + 1) {
  32400. end = range[0] + j - 1;
  32401. format31012 += string32(start) + // startCharCode
  32402. string32(end) + // endCharCode
  32403. string32(code); // startGlyphID
  32404. start = end + 1;
  32405. code = codes[j];
  32406. }
  32407. }
  32408. format31012 += string32(start) + // startCharCode
  32409. string32(range[1]) + // endCharCode
  32410. string32(code); // startGlyphID
  32411. }
  32412. header31012 = '\x00\x0C' + // format
  32413. '\x00\x00' + // reserved
  32414. string32(format31012.length + 16) + // length
  32415. '\x00\x00\x00\x00' + // language
  32416. string32(format31012.length / 12); // nGroups
  32417. }
  32418. return cmap + '\x00\x04' + // format
  32419. string16(format314.length + 4) + // length
  32420. format314 + header31012 + format31012;
  32421. }
  32422. function validateOS2Table(os2) {
  32423. var stream = new Stream(os2.data);
  32424. var version = stream.getUint16();
  32425. // TODO verify all OS/2 tables fields, but currently we validate only those
  32426. // that give us issues
  32427. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32428. var selection = stream.getUint16();
  32429. if (version < 4 && (selection & 0x0300)) {
  32430. return false;
  32431. }
  32432. var firstChar = stream.getUint16();
  32433. var lastChar = stream.getUint16();
  32434. if (firstChar > lastChar) {
  32435. return false;
  32436. }
  32437. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32438. var usWinAscent = stream.getUint16();
  32439. if (usWinAscent === 0) { // makes font unreadable by windows
  32440. return false;
  32441. }
  32442. // OS/2 appears to be valid, resetting some fields
  32443. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32444. return true;
  32445. }
  32446. function createOS2Table(properties, charstrings, override) {
  32447. override = override || {
  32448. unitsPerEm: 0,
  32449. yMax: 0,
  32450. yMin: 0,
  32451. ascent: 0,
  32452. descent: 0
  32453. };
  32454. var ulUnicodeRange1 = 0;
  32455. var ulUnicodeRange2 = 0;
  32456. var ulUnicodeRange3 = 0;
  32457. var ulUnicodeRange4 = 0;
  32458. var firstCharIndex = null;
  32459. var lastCharIndex = 0;
  32460. if (charstrings) {
  32461. for (var code in charstrings) {
  32462. code |= 0;
  32463. if (firstCharIndex > code || !firstCharIndex) {
  32464. firstCharIndex = code;
  32465. }
  32466. if (lastCharIndex < code) {
  32467. lastCharIndex = code;
  32468. }
  32469. var position = getUnicodeRangeFor(code);
  32470. if (position < 32) {
  32471. ulUnicodeRange1 |= 1 << position;
  32472. } else if (position < 64) {
  32473. ulUnicodeRange2 |= 1 << position - 32;
  32474. } else if (position < 96) {
  32475. ulUnicodeRange3 |= 1 << position - 64;
  32476. } else if (position < 123) {
  32477. ulUnicodeRange4 |= 1 << position - 96;
  32478. } else {
  32479. error('Unicode ranges Bits > 123 are reserved for internal usage');
  32480. }
  32481. }
  32482. } else {
  32483. // TODO
  32484. firstCharIndex = 0;
  32485. lastCharIndex = 255;
  32486. }
  32487. var bbox = properties.bbox || [0, 0, 0, 0];
  32488. var unitsPerEm = (override.unitsPerEm ||
  32489. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  32490. // if the font units differ to the PDF glyph space units
  32491. // then scale up the values
  32492. var scale = (properties.ascentScaled ? 1.0 :
  32493. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  32494. var typoAscent = (override.ascent ||
  32495. Math.round(scale * (properties.ascent || bbox[3])));
  32496. var typoDescent = (override.descent ||
  32497. Math.round(scale * (properties.descent || bbox[1])));
  32498. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  32499. typoDescent = -typoDescent; // fixing incorrect descent
  32500. }
  32501. var winAscent = override.yMax || typoAscent;
  32502. var winDescent = -override.yMin || -typoDescent;
  32503. return '\x00\x03' + // version
  32504. '\x02\x24' + // xAvgCharWidth
  32505. '\x01\xF4' + // usWeightClass
  32506. '\x00\x05' + // usWidthClass
  32507. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  32508. '\x02\x8A' + // ySubscriptXSize
  32509. '\x02\xBB' + // ySubscriptYSize
  32510. '\x00\x00' + // ySubscriptXOffset
  32511. '\x00\x8C' + // ySubscriptYOffset
  32512. '\x02\x8A' + // ySuperScriptXSize
  32513. '\x02\xBB' + // ySuperScriptYSize
  32514. '\x00\x00' + // ySuperScriptXOffset
  32515. '\x01\xDF' + // ySuperScriptYOffset
  32516. '\x00\x31' + // yStrikeOutSize
  32517. '\x01\x02' + // yStrikeOutPosition
  32518. '\x00\x00' + // sFamilyClass
  32519. '\x00\x00\x06' +
  32520. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  32521. '\x00\x00\x00\x00\x00\x00' + // Panose
  32522. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  32523. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  32524. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  32525. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  32526. '\x2A\x32\x31\x2A' + // achVendID
  32527. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  32528. string16(firstCharIndex ||
  32529. properties.firstChar) + // usFirstCharIndex
  32530. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  32531. string16(typoAscent) + // sTypoAscender
  32532. string16(typoDescent) + // sTypoDescender
  32533. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  32534. string16(winAscent) + // usWinAscent
  32535. string16(winDescent) + // usWinDescent
  32536. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  32537. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  32538. string16(properties.xHeight) + // sxHeight
  32539. string16(properties.capHeight) + // sCapHeight
  32540. string16(0) + // usDefaultChar
  32541. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  32542. '\x00\x03'; // usMaxContext
  32543. }
  32544. function createPostTable(properties) {
  32545. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  32546. return ('\x00\x03\x00\x00' + // Version number
  32547. string32(angle) + // italicAngle
  32548. '\x00\x00' + // underlinePosition
  32549. '\x00\x00' + // underlineThickness
  32550. string32(properties.fixedPitch) + // isFixedPitch
  32551. '\x00\x00\x00\x00' + // minMemType42
  32552. '\x00\x00\x00\x00' + // maxMemType42
  32553. '\x00\x00\x00\x00' + // minMemType1
  32554. '\x00\x00\x00\x00'); // maxMemType1
  32555. }
  32556. function createNameTable(name, proto) {
  32557. if (!proto) {
  32558. proto = [[], []]; // no strings and unicode strings
  32559. }
  32560. var strings = [
  32561. proto[0][0] || 'Original licence', // 0.Copyright
  32562. proto[0][1] || name, // 1.Font family
  32563. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  32564. proto[0][3] || 'uniqueID', // 3.Unique ID
  32565. proto[0][4] || name, // 4.Full font name
  32566. proto[0][5] || 'Version 0.11', // 5.Version
  32567. proto[0][6] || '', // 6.Postscript name
  32568. proto[0][7] || 'Unknown', // 7.Trademark
  32569. proto[0][8] || 'Unknown', // 8.Manufacturer
  32570. proto[0][9] || 'Unknown' // 9.Designer
  32571. ];
  32572. // Mac want 1-byte per character strings while Windows want
  32573. // 2-bytes per character, so duplicate the names table
  32574. var stringsUnicode = [];
  32575. var i, ii, j, jj, str;
  32576. for (i = 0, ii = strings.length; i < ii; i++) {
  32577. str = proto[1][i] || strings[i];
  32578. var strBufUnicode = [];
  32579. for (j = 0, jj = str.length; j < jj; j++) {
  32580. strBufUnicode.push(string16(str.charCodeAt(j)));
  32581. }
  32582. stringsUnicode.push(strBufUnicode.join(''));
  32583. }
  32584. var names = [strings, stringsUnicode];
  32585. var platforms = ['\x00\x01', '\x00\x03'];
  32586. var encodings = ['\x00\x00', '\x00\x01'];
  32587. var languages = ['\x00\x00', '\x04\x09'];
  32588. var namesRecordCount = strings.length * platforms.length;
  32589. var nameTable =
  32590. '\x00\x00' + // format
  32591. string16(namesRecordCount) + // Number of names Record
  32592. string16(namesRecordCount * 12 + 6); // Storage
  32593. // Build the name records field
  32594. var strOffset = 0;
  32595. for (i = 0, ii = platforms.length; i < ii; i++) {
  32596. var strs = names[i];
  32597. for (j = 0, jj = strs.length; j < jj; j++) {
  32598. str = strs[j];
  32599. var nameRecord =
  32600. platforms[i] + // platform ID
  32601. encodings[i] + // encoding ID
  32602. languages[i] + // language ID
  32603. string16(j) + // name ID
  32604. string16(str.length) +
  32605. string16(strOffset);
  32606. nameTable += nameRecord;
  32607. strOffset += str.length;
  32608. }
  32609. }
  32610. nameTable += strings.join('') + stringsUnicode.join('');
  32611. return nameTable;
  32612. }
  32613. Font.prototype = {
  32614. name: null,
  32615. font: null,
  32616. mimetype: null,
  32617. encoding: null,
  32618. get renderer() {
  32619. var renderer = FontRendererFactory.create(this);
  32620. return shadow(this, 'renderer', renderer);
  32621. },
  32622. exportData: function Font_exportData() {
  32623. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  32624. var data = {};
  32625. for (var i in this) {
  32626. if (this.hasOwnProperty(i)) {
  32627. data[i] = this[i];
  32628. }
  32629. }
  32630. return data;
  32631. },
  32632. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  32633. function readTableEntry(file) {
  32634. var tag = bytesToString(file.getBytes(4));
  32635. var checksum = file.getInt32();
  32636. var offset = file.getInt32() >>> 0;
  32637. var length = file.getInt32() >>> 0;
  32638. // Read the table associated data
  32639. var previousPosition = file.pos;
  32640. file.pos = file.start ? file.start : 0;
  32641. file.skip(offset);
  32642. var data = file.getBytes(length);
  32643. file.pos = previousPosition;
  32644. if (tag === 'head') {
  32645. // clearing checksum adjustment
  32646. data[8] = data[9] = data[10] = data[11] = 0;
  32647. data[17] |= 0x20; //Set font optimized for cleartype flag
  32648. }
  32649. return {
  32650. tag: tag,
  32651. checksum: checksum,
  32652. length: length,
  32653. offset: offset,
  32654. data: data
  32655. };
  32656. }
  32657. function readOpenTypeHeader(ttf) {
  32658. return {
  32659. version: bytesToString(ttf.getBytes(4)),
  32660. numTables: ttf.getUint16(),
  32661. searchRange: ttf.getUint16(),
  32662. entrySelector: ttf.getUint16(),
  32663. rangeShift: ttf.getUint16()
  32664. };
  32665. }
  32666. /**
  32667. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  32668. * PDF spec
  32669. */
  32670. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  32671. if (!cmap) {
  32672. warn('No cmap table available.');
  32673. return {
  32674. platformId: -1,
  32675. encodingId: -1,
  32676. mappings: [],
  32677. hasShortCmap: false
  32678. };
  32679. }
  32680. var segment;
  32681. var start = (font.start ? font.start : 0) + cmap.offset;
  32682. font.pos = start;
  32683. var version = font.getUint16();
  32684. var numTables = font.getUint16();
  32685. var potentialTable;
  32686. var canBreak = false;
  32687. // There's an order of preference in terms of which cmap subtable to
  32688. // use:
  32689. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  32690. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  32691. // The following takes advantage of the fact that the tables are sorted
  32692. // to work.
  32693. for (var i = 0; i < numTables; i++) {
  32694. var platformId = font.getUint16();
  32695. var encodingId = font.getUint16();
  32696. var offset = font.getInt32() >>> 0;
  32697. var useTable = false;
  32698. if (platformId === 0 && encodingId === 0) {
  32699. useTable = true;
  32700. // Continue the loop since there still may be a higher priority
  32701. // table.
  32702. } else if (platformId === 1 && encodingId === 0) {
  32703. useTable = true;
  32704. // Continue the loop since there still may be a higher priority
  32705. // table.
  32706. } else if (platformId === 3 && encodingId === 1 &&
  32707. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  32708. useTable = true;
  32709. if (!isSymbolicFont) {
  32710. canBreak = true;
  32711. }
  32712. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  32713. useTable = true;
  32714. canBreak = true;
  32715. }
  32716. if (useTable) {
  32717. potentialTable = {
  32718. platformId: platformId,
  32719. encodingId: encodingId,
  32720. offset: offset
  32721. };
  32722. }
  32723. if (canBreak) {
  32724. break;
  32725. }
  32726. }
  32727. if (potentialTable) {
  32728. font.pos = start + potentialTable.offset;
  32729. }
  32730. if (!potentialTable || font.peekByte() === -1) {
  32731. warn('Could not find a preferred cmap table.');
  32732. return {
  32733. platformId: -1,
  32734. encodingId: -1,
  32735. mappings: [],
  32736. hasShortCmap: false
  32737. };
  32738. }
  32739. var format = font.getUint16();
  32740. var length = font.getUint16();
  32741. var language = font.getUint16();
  32742. var hasShortCmap = false;
  32743. var mappings = [];
  32744. var j, glyphId;
  32745. // TODO(mack): refactor this cmap subtable reading logic out
  32746. if (format === 0) {
  32747. for (j = 0; j < 256; j++) {
  32748. var index = font.getByte();
  32749. if (!index) {
  32750. continue;
  32751. }
  32752. mappings.push({
  32753. charCode: j,
  32754. glyphId: index
  32755. });
  32756. }
  32757. hasShortCmap = true;
  32758. } else if (format === 4) {
  32759. // re-creating the table in format 4 since the encoding
  32760. // might be changed
  32761. var segCount = (font.getUint16() >> 1);
  32762. font.getBytes(6); // skipping range fields
  32763. var segIndex, segments = [];
  32764. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32765. segments.push({ end: font.getUint16() });
  32766. }
  32767. font.getUint16();
  32768. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32769. segments[segIndex].start = font.getUint16();
  32770. }
  32771. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32772. segments[segIndex].delta = font.getUint16();
  32773. }
  32774. var offsetsCount = 0;
  32775. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32776. segment = segments[segIndex];
  32777. var rangeOffset = font.getUint16();
  32778. if (!rangeOffset) {
  32779. segment.offsetIndex = -1;
  32780. continue;
  32781. }
  32782. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  32783. segment.offsetIndex = offsetIndex;
  32784. offsetsCount = Math.max(offsetsCount, offsetIndex +
  32785. segment.end - segment.start + 1);
  32786. }
  32787. var offsets = [];
  32788. for (j = 0; j < offsetsCount; j++) {
  32789. offsets.push(font.getUint16());
  32790. }
  32791. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32792. segment = segments[segIndex];
  32793. start = segment.start;
  32794. var end = segment.end;
  32795. var delta = segment.delta;
  32796. offsetIndex = segment.offsetIndex;
  32797. for (j = start; j <= end; j++) {
  32798. if (j === 0xFFFF) {
  32799. continue;
  32800. }
  32801. glyphId = (offsetIndex < 0 ?
  32802. j : offsets[offsetIndex + j - start]);
  32803. glyphId = (glyphId + delta) & 0xFFFF;
  32804. if (glyphId === 0) {
  32805. continue;
  32806. }
  32807. mappings.push({
  32808. charCode: j,
  32809. glyphId: glyphId
  32810. });
  32811. }
  32812. }
  32813. } else if (format === 6) {
  32814. // Format 6 is a 2-bytes dense mapping, which means the font data
  32815. // lives glue together even if they are pretty far in the unicode
  32816. // table. (This looks weird, so I can have missed something), this
  32817. // works on Linux but seems to fails on Mac so let's rewrite the
  32818. // cmap table to a 3-1-4 style
  32819. var firstCode = font.getUint16();
  32820. var entryCount = font.getUint16();
  32821. for (j = 0; j < entryCount; j++) {
  32822. glyphId = font.getUint16();
  32823. var charCode = firstCode + j;
  32824. mappings.push({
  32825. charCode: charCode,
  32826. glyphId: glyphId
  32827. });
  32828. }
  32829. } else {
  32830. warn('cmap table has unsupported format: ' + format);
  32831. return {
  32832. platformId: -1,
  32833. encodingId: -1,
  32834. mappings: [],
  32835. hasShortCmap: false
  32836. };
  32837. }
  32838. // removing duplicate entries
  32839. mappings.sort(function (a, b) {
  32840. return a.charCode - b.charCode;
  32841. });
  32842. for (i = 1; i < mappings.length; i++) {
  32843. if (mappings[i - 1].charCode === mappings[i].charCode) {
  32844. mappings.splice(i, 1);
  32845. i--;
  32846. }
  32847. }
  32848. return {
  32849. platformId: potentialTable.platformId,
  32850. encodingId: potentialTable.encodingId,
  32851. mappings: mappings,
  32852. hasShortCmap: hasShortCmap
  32853. };
  32854. }
  32855. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  32856. if (!header) {
  32857. if (metrics) {
  32858. metrics.data = null;
  32859. }
  32860. return;
  32861. }
  32862. font.pos = (font.start ? font.start : 0) + header.offset;
  32863. font.pos += header.length - 2;
  32864. var numOfMetrics = font.getUint16();
  32865. if (numOfMetrics > numGlyphs) {
  32866. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  32867. 'greater than the numGlyphs (' + numGlyphs + ')');
  32868. // Reduce numOfMetrics if it is greater than numGlyphs
  32869. numOfMetrics = numGlyphs;
  32870. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  32871. header.data[35] = numOfMetrics & 0x00ff;
  32872. }
  32873. var numOfSidebearings = numGlyphs - numOfMetrics;
  32874. var numMissing = numOfSidebearings -
  32875. ((metrics.length - numOfMetrics * 4) >> 1);
  32876. if (numMissing > 0) {
  32877. // For each missing glyph, we set both the width and lsb to 0 (zero).
  32878. // Since we need to add two properties for each glyph, this explains
  32879. // the use of |numMissing * 2| when initializing the typed array.
  32880. var entries = new Uint8Array(metrics.length + numMissing * 2);
  32881. entries.set(metrics.data);
  32882. metrics.data = entries;
  32883. }
  32884. }
  32885. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  32886. hintsValid) {
  32887. if (sourceEnd - sourceStart <= 12) {
  32888. // glyph with data less than 12 is invalid one
  32889. return 0;
  32890. }
  32891. var glyf = source.subarray(sourceStart, sourceEnd);
  32892. var contoursCount = (glyf[0] << 8) | glyf[1];
  32893. if (contoursCount & 0x8000) {
  32894. // complex glyph, writing as is
  32895. dest.set(glyf, destStart);
  32896. return glyf.length;
  32897. }
  32898. var i, j = 10, flagsCount = 0;
  32899. for (i = 0; i < contoursCount; i++) {
  32900. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  32901. flagsCount = endPoint + 1;
  32902. j += 2;
  32903. }
  32904. // skipping instructions
  32905. var instructionsStart = j;
  32906. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  32907. j += 2 + instructionsLength;
  32908. var instructionsEnd = j;
  32909. // validating flags
  32910. var coordinatesLength = 0;
  32911. for (i = 0; i < flagsCount; i++) {
  32912. var flag = glyf[j++];
  32913. if (flag & 0xC0) {
  32914. // reserved flags must be zero, cleaning up
  32915. glyf[j - 1] = flag & 0x3F;
  32916. }
  32917. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  32918. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  32919. coordinatesLength += xyLength;
  32920. if (flag & 8) {
  32921. var repeat = glyf[j++];
  32922. i += repeat;
  32923. coordinatesLength += repeat * xyLength;
  32924. }
  32925. }
  32926. // glyph without coordinates will be rejected
  32927. if (coordinatesLength === 0) {
  32928. return 0;
  32929. }
  32930. var glyphDataLength = j + coordinatesLength;
  32931. if (glyphDataLength > glyf.length) {
  32932. // not enough data for coordinates
  32933. return 0;
  32934. }
  32935. if (!hintsValid && instructionsLength > 0) {
  32936. dest.set(glyf.subarray(0, instructionsStart), destStart);
  32937. dest.set([0, 0], destStart + instructionsStart);
  32938. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  32939. destStart + instructionsStart + 2);
  32940. glyphDataLength -= instructionsLength;
  32941. if (glyf.length - glyphDataLength > 3) {
  32942. glyphDataLength = (glyphDataLength + 3) & ~3;
  32943. }
  32944. return glyphDataLength;
  32945. }
  32946. if (glyf.length - glyphDataLength > 3) {
  32947. // truncating and aligning to 4 bytes the long glyph data
  32948. glyphDataLength = (glyphDataLength + 3) & ~3;
  32949. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  32950. return glyphDataLength;
  32951. }
  32952. // glyph data is fine
  32953. dest.set(glyf, destStart);
  32954. return glyf.length;
  32955. }
  32956. function sanitizeHead(head, numGlyphs, locaLength) {
  32957. var data = head.data;
  32958. // Validate version:
  32959. // Should always be 0x00010000
  32960. var version = int32(data[0], data[1], data[2], data[3]);
  32961. if (version >> 16 !== 1) {
  32962. info('Attempting to fix invalid version in head table: ' + version);
  32963. data[0] = 0;
  32964. data[1] = 1;
  32965. data[2] = 0;
  32966. data[3] = 0;
  32967. }
  32968. var indexToLocFormat = int16(data[50], data[51]);
  32969. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  32970. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  32971. indexToLocFormat);
  32972. // The value of indexToLocFormat should be 0 if the loca table
  32973. // consists of short offsets, and should be 1 if the loca table
  32974. // consists of long offsets.
  32975. //
  32976. // The number of entries in the loca table should be numGlyphs + 1.
  32977. //
  32978. // Using this information, we can work backwards to deduce if the
  32979. // size of each offset in the loca table, and thus figure out the
  32980. // appropriate value for indexToLocFormat.
  32981. var numGlyphsPlusOne = numGlyphs + 1;
  32982. if (locaLength === numGlyphsPlusOne << 1) {
  32983. // 0x0000 indicates the loca table consists of short offsets
  32984. data[50] = 0;
  32985. data[51] = 0;
  32986. } else if (locaLength === numGlyphsPlusOne << 2) {
  32987. // 0x0001 indicates the loca table consists of long offsets
  32988. data[50] = 0;
  32989. data[51] = 1;
  32990. } else {
  32991. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  32992. }
  32993. }
  32994. }
  32995. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  32996. isGlyphLocationsLong, hintsValid,
  32997. dupFirstEntry) {
  32998. var itemSize, itemDecode, itemEncode;
  32999. if (isGlyphLocationsLong) {
  33000. itemSize = 4;
  33001. itemDecode = function fontItemDecodeLong(data, offset) {
  33002. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33003. (data[offset + 2] << 8) | data[offset + 3];
  33004. };
  33005. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33006. data[offset] = (value >>> 24) & 0xFF;
  33007. data[offset + 1] = (value >> 16) & 0xFF;
  33008. data[offset + 2] = (value >> 8) & 0xFF;
  33009. data[offset + 3] = value & 0xFF;
  33010. };
  33011. } else {
  33012. itemSize = 2;
  33013. itemDecode = function fontItemDecode(data, offset) {
  33014. return (data[offset] << 9) | (data[offset + 1] << 1);
  33015. };
  33016. itemEncode = function fontItemEncode(data, offset, value) {
  33017. data[offset] = (value >> 9) & 0xFF;
  33018. data[offset + 1] = (value >> 1) & 0xFF;
  33019. };
  33020. }
  33021. var locaData = loca.data;
  33022. var locaDataSize = itemSize * (1 + numGlyphs);
  33023. // is loca.data too short or long?
  33024. if (locaData.length !== locaDataSize) {
  33025. locaData = new Uint8Array(locaDataSize);
  33026. locaData.set(loca.data.subarray(0, locaDataSize));
  33027. loca.data = locaData;
  33028. }
  33029. // removing the invalid glyphs
  33030. var oldGlyfData = glyf.data;
  33031. var oldGlyfDataLength = oldGlyfData.length;
  33032. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33033. var startOffset = itemDecode(locaData, 0);
  33034. var writeOffset = 0;
  33035. var missingGlyphData = Object.create(null);
  33036. itemEncode(locaData, 0, writeOffset);
  33037. var i, j;
  33038. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33039. var endOffset = itemDecode(locaData, j);
  33040. if (endOffset > oldGlyfDataLength &&
  33041. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33042. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33043. // the glyf table size, which makes last glyph out of range.
  33044. endOffset = oldGlyfDataLength;
  33045. }
  33046. if (endOffset > oldGlyfDataLength) {
  33047. // glyph end offset points outside glyf data, rejecting the glyph
  33048. itemEncode(locaData, j, writeOffset);
  33049. startOffset = endOffset;
  33050. continue;
  33051. }
  33052. if (startOffset === endOffset) {
  33053. missingGlyphData[i] = true;
  33054. }
  33055. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33056. newGlyfData, writeOffset, hintsValid);
  33057. writeOffset += newLength;
  33058. itemEncode(locaData, j, writeOffset);
  33059. startOffset = endOffset;
  33060. }
  33061. if (writeOffset === 0) {
  33062. // glyf table cannot be empty -- redoing the glyf and loca tables
  33063. // to have single glyph with one point
  33064. var simpleGlyph = new Uint8Array(
  33065. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33066. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33067. itemEncode(locaData, j, simpleGlyph.length);
  33068. }
  33069. glyf.data = simpleGlyph;
  33070. return missingGlyphData;
  33071. }
  33072. if (dupFirstEntry) {
  33073. var firstEntryLength = itemDecode(locaData, itemSize);
  33074. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33075. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33076. } else {
  33077. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33078. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33079. }
  33080. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33081. itemEncode(loca.data, locaData.length - itemSize,
  33082. writeOffset + firstEntryLength);
  33083. } else {
  33084. glyf.data = newGlyfData.subarray(0, writeOffset);
  33085. }
  33086. return missingGlyphData;
  33087. }
  33088. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33089. var start = (font.start ? font.start : 0) + post.offset;
  33090. font.pos = start;
  33091. var length = post.length, end = start + length;
  33092. var version = font.getInt32();
  33093. // skip rest to the tables
  33094. font.getBytes(28);
  33095. var glyphNames;
  33096. var valid = true;
  33097. var i;
  33098. switch (version) {
  33099. case 0x00010000:
  33100. glyphNames = MacStandardGlyphOrdering;
  33101. break;
  33102. case 0x00020000:
  33103. var numGlyphs = font.getUint16();
  33104. if (numGlyphs !== maxpNumGlyphs) {
  33105. valid = false;
  33106. break;
  33107. }
  33108. var glyphNameIndexes = [];
  33109. for (i = 0; i < numGlyphs; ++i) {
  33110. var index = font.getUint16();
  33111. if (index >= 32768) {
  33112. valid = false;
  33113. break;
  33114. }
  33115. glyphNameIndexes.push(index);
  33116. }
  33117. if (!valid) {
  33118. break;
  33119. }
  33120. var customNames = [];
  33121. var strBuf = [];
  33122. while (font.pos < end) {
  33123. var stringLength = font.getByte();
  33124. strBuf.length = stringLength;
  33125. for (i = 0; i < stringLength; ++i) {
  33126. strBuf[i] = String.fromCharCode(font.getByte());
  33127. }
  33128. customNames.push(strBuf.join(''));
  33129. }
  33130. glyphNames = [];
  33131. for (i = 0; i < numGlyphs; ++i) {
  33132. var j = glyphNameIndexes[i];
  33133. if (j < 258) {
  33134. glyphNames.push(MacStandardGlyphOrdering[j]);
  33135. continue;
  33136. }
  33137. glyphNames.push(customNames[j - 258]);
  33138. }
  33139. break;
  33140. case 0x00030000:
  33141. break;
  33142. default:
  33143. warn('Unknown/unsupported post table version ' + version);
  33144. valid = false;
  33145. if (properties.defaultEncoding) {
  33146. glyphNames = properties.defaultEncoding;
  33147. }
  33148. break;
  33149. }
  33150. properties.glyphNames = glyphNames;
  33151. return valid;
  33152. }
  33153. function readNameTable(nameTable) {
  33154. var start = (font.start ? font.start : 0) + nameTable.offset;
  33155. font.pos = start;
  33156. var names = [[], []];
  33157. var length = nameTable.length, end = start + length;
  33158. var format = font.getUint16();
  33159. var FORMAT_0_HEADER_LENGTH = 6;
  33160. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33161. // unsupported name table format or table "too" small
  33162. return names;
  33163. }
  33164. var numRecords = font.getUint16();
  33165. var stringsStart = font.getUint16();
  33166. var records = [];
  33167. var NAME_RECORD_LENGTH = 12;
  33168. var i, ii;
  33169. for (i = 0; i < numRecords &&
  33170. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33171. var r = {
  33172. platform: font.getUint16(),
  33173. encoding: font.getUint16(),
  33174. language: font.getUint16(),
  33175. name: font.getUint16(),
  33176. length: font.getUint16(),
  33177. offset: font.getUint16()
  33178. };
  33179. // using only Macintosh and Windows platform/encoding names
  33180. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33181. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33182. records.push(r);
  33183. }
  33184. }
  33185. for (i = 0, ii = records.length; i < ii; i++) {
  33186. var record = records[i];
  33187. if (record.length <= 0) {
  33188. continue; // Nothing to process, ignoring.
  33189. }
  33190. var pos = start + stringsStart + record.offset;
  33191. if (pos + record.length > end) {
  33192. continue; // outside of name table, ignoring
  33193. }
  33194. font.pos = pos;
  33195. var nameIndex = record.name;
  33196. if (record.encoding) {
  33197. // unicode
  33198. var str = '';
  33199. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33200. str += String.fromCharCode(font.getUint16());
  33201. }
  33202. names[1][nameIndex] = str;
  33203. } else {
  33204. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33205. }
  33206. }
  33207. return names;
  33208. }
  33209. var TTOpsStackDeltas = [
  33210. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33211. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33212. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33213. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33214. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33215. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33216. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33217. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33218. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33219. // 0xC0-DF == -1 and 0xE0-FF == -2
  33220. function sanitizeTTProgram(table, ttContext) {
  33221. var data = table.data;
  33222. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33223. var stack = [];
  33224. var callstack = [];
  33225. var functionsCalled = [];
  33226. var tooComplexToFollowFunctions =
  33227. ttContext.tooComplexToFollowFunctions;
  33228. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33229. for (var ii = data.length; i < ii;) {
  33230. var op = data[i++];
  33231. // The TrueType instruction set docs can be found at
  33232. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33233. if (op === 0x40) { // NPUSHB - pushes n bytes
  33234. n = data[i++];
  33235. if (inFDEF || inELSE) {
  33236. i += n;
  33237. } else {
  33238. for (j = 0; j < n; j++) {
  33239. stack.push(data[i++]);
  33240. }
  33241. }
  33242. } else if (op === 0x41) { // NPUSHW - pushes n words
  33243. n = data[i++];
  33244. if (inFDEF || inELSE) {
  33245. i += n * 2;
  33246. } else {
  33247. for (j = 0; j < n; j++) {
  33248. b = data[i++];
  33249. stack.push((b << 8) | data[i++]);
  33250. }
  33251. }
  33252. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33253. n = op - 0xB0 + 1;
  33254. if (inFDEF || inELSE) {
  33255. i += n;
  33256. } else {
  33257. for (j = 0; j < n; j++) {
  33258. stack.push(data[i++]);
  33259. }
  33260. }
  33261. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33262. n = op - 0xB8 + 1;
  33263. if (inFDEF || inELSE) {
  33264. i += n * 2;
  33265. } else {
  33266. for (j = 0; j < n; j++) {
  33267. b = data[i++];
  33268. stack.push((b << 8) | data[i++]);
  33269. }
  33270. }
  33271. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33272. if (!inFDEF && !inELSE) {
  33273. // collecting inforamtion about which functions are used
  33274. funcId = stack[stack.length - 1];
  33275. ttContext.functionsUsed[funcId] = true;
  33276. if (funcId in ttContext.functionsStackDeltas) {
  33277. stack.length += ttContext.functionsStackDeltas[funcId];
  33278. } else if (funcId in ttContext.functionsDefined &&
  33279. functionsCalled.indexOf(funcId) < 0) {
  33280. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33281. functionsCalled.push(funcId);
  33282. pc = ttContext.functionsDefined[funcId];
  33283. if (!pc) {
  33284. warn('TT: CALL non-existent function');
  33285. ttContext.hintsValid = false;
  33286. return;
  33287. }
  33288. data = pc.data;
  33289. i = pc.i;
  33290. }
  33291. }
  33292. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33293. if (inFDEF || inELSE) {
  33294. warn('TT: nested FDEFs not allowed');
  33295. tooComplexToFollowFunctions = true;
  33296. }
  33297. inFDEF = true;
  33298. // collecting inforamtion about which functions are defined
  33299. lastDeff = i;
  33300. funcId = stack.pop();
  33301. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33302. } else if (op === 0x2D) { // ENDF - end of function
  33303. if (inFDEF) {
  33304. inFDEF = false;
  33305. lastEndf = i;
  33306. } else {
  33307. pc = callstack.pop();
  33308. if (!pc) {
  33309. warn('TT: ENDF bad stack');
  33310. ttContext.hintsValid = false;
  33311. return;
  33312. }
  33313. funcId = functionsCalled.pop();
  33314. data = pc.data;
  33315. i = pc.i;
  33316. ttContext.functionsStackDeltas[funcId] =
  33317. stack.length - pc.stackTop;
  33318. }
  33319. } else if (op === 0x89) { // IDEF - instruction definition
  33320. if (inFDEF || inELSE) {
  33321. warn('TT: nested IDEFs not allowed');
  33322. tooComplexToFollowFunctions = true;
  33323. }
  33324. inFDEF = true;
  33325. // recording it as a function to track ENDF
  33326. lastDeff = i;
  33327. } else if (op === 0x58) { // IF
  33328. ++ifLevel;
  33329. } else if (op === 0x1B) { // ELSE
  33330. inELSE = ifLevel;
  33331. } else if (op === 0x59) { // EIF
  33332. if (inELSE === ifLevel) {
  33333. inELSE = 0;
  33334. }
  33335. --ifLevel;
  33336. } else if (op === 0x1C) { // JMPR
  33337. if (!inFDEF && !inELSE) {
  33338. var offset = stack[stack.length - 1];
  33339. // only jumping forward to prevent infinite loop
  33340. if (offset > 0) {
  33341. i += offset - 1;
  33342. }
  33343. }
  33344. }
  33345. // Adjusting stack not extactly, but just enough to get function id
  33346. if (!inFDEF && !inELSE) {
  33347. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33348. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33349. if (op >= 0x71 && op <= 0x75) {
  33350. n = stack.pop();
  33351. if (n === n) {
  33352. stackDelta = -n * 2;
  33353. }
  33354. }
  33355. while (stackDelta < 0 && stack.length > 0) {
  33356. stack.pop();
  33357. stackDelta++;
  33358. }
  33359. while (stackDelta > 0) {
  33360. stack.push(NaN); // pushing any number into stack
  33361. stackDelta--;
  33362. }
  33363. }
  33364. }
  33365. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33366. var content = [data];
  33367. if (i > data.length) {
  33368. content.push(new Uint8Array(i - data.length));
  33369. }
  33370. if (lastDeff > lastEndf) {
  33371. warn('TT: complementing a missing function tail');
  33372. // new function definition started, but not finished
  33373. // complete function by [CLEAR, ENDF]
  33374. content.push(new Uint8Array([0x22, 0x2D]));
  33375. }
  33376. foldTTTable(table, content);
  33377. }
  33378. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33379. if (ttContext.tooComplexToFollowFunctions) {
  33380. return;
  33381. }
  33382. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33383. warn('TT: more functions defined than expected');
  33384. ttContext.hintsValid = false;
  33385. return;
  33386. }
  33387. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33388. if (j > maxFunctionDefs) {
  33389. warn('TT: invalid function id: ' + j);
  33390. ttContext.hintsValid = false;
  33391. return;
  33392. }
  33393. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33394. warn('TT: undefined function: ' + j);
  33395. ttContext.hintsValid = false;
  33396. return;
  33397. }
  33398. }
  33399. }
  33400. function foldTTTable(table, content) {
  33401. if (content.length > 1) {
  33402. // concatenating the content items
  33403. var newLength = 0;
  33404. var j, jj;
  33405. for (j = 0, jj = content.length; j < jj; j++) {
  33406. newLength += content[j].length;
  33407. }
  33408. newLength = (newLength + 3) & ~3;
  33409. var result = new Uint8Array(newLength);
  33410. var pos = 0;
  33411. for (j = 0, jj = content.length; j < jj; j++) {
  33412. result.set(content[j], pos);
  33413. pos += content[j].length;
  33414. }
  33415. table.data = result;
  33416. table.length = newLength;
  33417. }
  33418. }
  33419. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33420. var ttContext = {
  33421. functionsDefined: [],
  33422. functionsUsed: [],
  33423. functionsStackDeltas: [],
  33424. tooComplexToFollowFunctions: false,
  33425. hintsValid: true
  33426. };
  33427. if (fpgm) {
  33428. sanitizeTTProgram(fpgm, ttContext);
  33429. }
  33430. if (prep) {
  33431. sanitizeTTProgram(prep, ttContext);
  33432. }
  33433. if (fpgm) {
  33434. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33435. }
  33436. if (cvt && (cvt.length & 1)) {
  33437. var cvtData = new Uint8Array(cvt.length + 1);
  33438. cvtData.set(cvt.data);
  33439. cvt.data = cvtData;
  33440. }
  33441. return ttContext.hintsValid;
  33442. }
  33443. // The following steps modify the original font data, making copy
  33444. font = new Stream(new Uint8Array(font.getBytes()));
  33445. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33446. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33447. var header = readOpenTypeHeader(font);
  33448. var numTables = header.numTables;
  33449. var cff, cffFile;
  33450. var tables = Object.create(null);
  33451. tables['OS/2'] = null;
  33452. tables['cmap'] = null;
  33453. tables['head'] = null;
  33454. tables['hhea'] = null;
  33455. tables['hmtx'] = null;
  33456. tables['maxp'] = null;
  33457. tables['name'] = null;
  33458. tables['post'] = null;
  33459. var table;
  33460. for (var i = 0; i < numTables; i++) {
  33461. table = readTableEntry(font);
  33462. if (VALID_TABLES.indexOf(table.tag) < 0) {
  33463. continue; // skipping table if it's not a required or optional table
  33464. }
  33465. if (table.length === 0) {
  33466. continue; // skipping empty tables
  33467. }
  33468. tables[table.tag] = table;
  33469. }
  33470. var isTrueType = !tables['CFF '];
  33471. if (!isTrueType) {
  33472. // OpenType font
  33473. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  33474. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  33475. !tables['post']) {
  33476. // no major tables: throwing everything at CFFFont
  33477. cffFile = new Stream(tables['CFF '].data);
  33478. cff = new CFFFont(cffFile, properties);
  33479. adjustWidths(properties);
  33480. return this.convert(name, cff, properties);
  33481. }
  33482. delete tables['glyf'];
  33483. delete tables['loca'];
  33484. delete tables['fpgm'];
  33485. delete tables['prep'];
  33486. delete tables['cvt '];
  33487. this.isOpenType = true;
  33488. } else {
  33489. if (!tables['loca']) {
  33490. error('Required "loca" table is not found');
  33491. }
  33492. if (!tables['glyf']) {
  33493. warn('Required "glyf" table is not found -- trying to recover.');
  33494. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  33495. tables['glyf'] = {
  33496. tag: 'glyf',
  33497. data: new Uint8Array(0),
  33498. };
  33499. }
  33500. this.isOpenType = false;
  33501. }
  33502. if (!tables['maxp']) {
  33503. error('Required "maxp" table is not found');
  33504. }
  33505. font.pos = (font.start || 0) + tables['maxp'].offset;
  33506. var version = font.getInt32();
  33507. var numGlyphs = font.getUint16();
  33508. var maxFunctionDefs = 0;
  33509. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  33510. // maxZones can be invalid
  33511. font.pos += 8;
  33512. var maxZones = font.getUint16();
  33513. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  33514. tables['maxp'].data[14] = 0;
  33515. tables['maxp'].data[15] = 2;
  33516. }
  33517. font.pos += 4;
  33518. maxFunctionDefs = font.getUint16();
  33519. }
  33520. var dupFirstEntry = false;
  33521. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  33522. properties.toUnicode.get(0) > '\u0000') {
  33523. // oracle's defect (see 3427), duplicating first entry
  33524. dupFirstEntry = true;
  33525. numGlyphs++;
  33526. tables['maxp'].data[4] = numGlyphs >> 8;
  33527. tables['maxp'].data[5] = numGlyphs & 255;
  33528. }
  33529. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  33530. tables['cvt '], maxFunctionDefs);
  33531. if (!hintsValid) {
  33532. delete tables['fpgm'];
  33533. delete tables['prep'];
  33534. delete tables['cvt '];
  33535. }
  33536. // Ensure the hmtx table contains the advance width and
  33537. // sidebearings information for numGlyphs in the maxp table
  33538. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  33539. if (!tables['head']) {
  33540. error('Required "head" table is not found');
  33541. }
  33542. sanitizeHead(tables['head'], numGlyphs,
  33543. isTrueType ? tables['loca'].length : 0);
  33544. var missingGlyphs = Object.create(null);
  33545. if (isTrueType) {
  33546. var isGlyphLocationsLong = int16(tables['head'].data[50],
  33547. tables['head'].data[51]);
  33548. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  33549. numGlyphs, isGlyphLocationsLong,
  33550. hintsValid, dupFirstEntry);
  33551. }
  33552. if (!tables['hhea']) {
  33553. error('Required "hhea" table is not found');
  33554. }
  33555. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  33556. // Sometimes it's 0. That needs to be fixed
  33557. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  33558. tables['hhea'].data[10] = 0xFF;
  33559. tables['hhea'].data[11] = 0xFF;
  33560. }
  33561. // Extract some more font properties from the OpenType head and
  33562. // hhea tables; yMin and descent value are always negative.
  33563. var metricsOverride = {
  33564. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  33565. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  33566. yMin: int16(tables['head'].data[38], tables['head'].data[39]) - 0x10000,
  33567. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  33568. descent: int16(tables['hhea'].data[6], tables['hhea'].data[7]) - 0x10000
  33569. };
  33570. // PDF FontDescriptor metrics lie -- using data from actual font.
  33571. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  33572. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  33573. // The 'post' table has glyphs names.
  33574. if (tables['post']) {
  33575. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  33576. if (!valid) {
  33577. tables['post'] = null;
  33578. }
  33579. }
  33580. var charCodeToGlyphId = [], charCode;
  33581. var toUnicode = properties.toUnicode, widths = properties.widths;
  33582. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  33583. toUnicode.length === 0x10000);
  33584. // Helper function to try to skip mapping of empty glyphs.
  33585. // Note: In some cases, just relying on the glyph data doesn't work,
  33586. // hence we also use a few heuristics to fix various PDF files.
  33587. function hasGlyph(glyphId, charCode, widthCode) {
  33588. if (!missingGlyphs[glyphId]) {
  33589. return true;
  33590. }
  33591. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  33592. return true;
  33593. }
  33594. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  33595. return true;
  33596. }
  33597. return false;
  33598. }
  33599. if (properties.type === 'CIDFontType2') {
  33600. var cidToGidMap = properties.cidToGidMap || [];
  33601. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  33602. properties.cMap.forEach(function(charCode, cid) {
  33603. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  33604. var glyphId = -1;
  33605. if (isCidToGidMapEmpty) {
  33606. glyphId = charCode;
  33607. } else if (cidToGidMap[cid] !== undefined) {
  33608. glyphId = cidToGidMap[cid];
  33609. }
  33610. if (glyphId >= 0 && glyphId < numGlyphs &&
  33611. hasGlyph(glyphId, charCode, cid)) {
  33612. charCodeToGlyphId[charCode] = glyphId;
  33613. }
  33614. });
  33615. if (dupFirstEntry) {
  33616. charCodeToGlyphId[0] = numGlyphs - 1;
  33617. }
  33618. } else {
  33619. // Most of the following logic in this code branch is based on the
  33620. // 9.6.6.4 of the PDF spec.
  33621. var hasEncoding =
  33622. properties.differences.length > 0 || !!properties.baseEncodingName;
  33623. var cmapTable =
  33624. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  33625. var cmapPlatformId = cmapTable.platformId;
  33626. var cmapEncodingId = cmapTable.encodingId;
  33627. var cmapMappings = cmapTable.mappings;
  33628. var cmapMappingsLength = cmapMappings.length;
  33629. // The spec seems to imply that if the font is symbolic the encoding
  33630. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  33631. // where the the font is symbolic and it has an encoding.
  33632. if (hasEncoding &&
  33633. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  33634. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  33635. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  33636. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  33637. // When no preferred cmap table was found and |baseEncodingName| is
  33638. // one of the predefined encodings, we seem to obtain a better
  33639. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  33640. // TODO: Note that this is a hack which should be removed as soon as
  33641. // we have proper support for more exotic cmap tables.
  33642. var baseEncoding = [];
  33643. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  33644. properties.baseEncodingName === 'WinAnsiEncoding') {
  33645. baseEncoding = getEncoding(properties.baseEncodingName);
  33646. }
  33647. var glyphsUnicodeMap = getGlyphsUnicode();
  33648. for (charCode = 0; charCode < 256; charCode++) {
  33649. var glyphName;
  33650. if (this.differences && charCode in this.differences) {
  33651. glyphName = this.differences[charCode];
  33652. } else if (charCode in baseEncoding &&
  33653. baseEncoding[charCode] !== '') {
  33654. glyphName = baseEncoding[charCode];
  33655. } else {
  33656. glyphName = StandardEncoding[charCode];
  33657. }
  33658. if (!glyphName) {
  33659. continue;
  33660. }
  33661. var unicodeOrCharCode, isUnicode = false;
  33662. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  33663. unicodeOrCharCode = glyphsUnicodeMap[glyphName];
  33664. isUnicode = true;
  33665. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  33666. // TODO: the encoding needs to be updated with mac os table.
  33667. unicodeOrCharCode = MacRomanEncoding.indexOf(glyphName);
  33668. }
  33669. var found = false;
  33670. for (i = 0; i < cmapMappingsLength; ++i) {
  33671. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  33672. continue;
  33673. }
  33674. var code = isUnicode ? charCode : unicodeOrCharCode;
  33675. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  33676. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  33677. found = true;
  33678. break;
  33679. }
  33680. }
  33681. if (!found && properties.glyphNames) {
  33682. // Try to map using the post table.
  33683. var glyphId = properties.glyphNames.indexOf(glyphName);
  33684. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  33685. charCodeToGlyphId[charCode] = glyphId;
  33686. found = true;
  33687. }
  33688. }
  33689. if (!found) {
  33690. charCodeToGlyphId[charCode] = 0; // notdef
  33691. }
  33692. }
  33693. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  33694. // Default Unicode semantics, use the charcodes as is.
  33695. for (i = 0; i < cmapMappingsLength; ++i) {
  33696. charCodeToGlyphId[cmapMappings[i].charCode] =
  33697. cmapMappings[i].glyphId;
  33698. }
  33699. } else {
  33700. // For (3, 0) cmap tables:
  33701. // The charcode key being stored in charCodeToGlyphId is the lower
  33702. // byte of the two-byte charcodes of the cmap table since according to
  33703. // the spec: 'each byte from the string shall be prepended with the
  33704. // high byte of the range [of charcodes in the cmap table], to form
  33705. // a two-byte character, which shall be used to select the
  33706. // associated glyph description from the subtable'.
  33707. //
  33708. // For (1, 0) cmap tables:
  33709. // 'single bytes from the string shall be used to look up the
  33710. // associated glyph descriptions from the subtable'. This means
  33711. // charcodes in the cmap will be single bytes, so no-op since
  33712. // glyph.charCode & 0xFF === glyph.charCode
  33713. for (i = 0; i < cmapMappingsLength; ++i) {
  33714. charCode = cmapMappings[i].charCode & 0xFF;
  33715. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  33716. }
  33717. }
  33718. }
  33719. if (charCodeToGlyphId.length === 0) {
  33720. // defines at least one glyph
  33721. charCodeToGlyphId[0] = 0;
  33722. }
  33723. // Converting glyphs and ids into font's cmap table
  33724. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  33725. this.toFontChar = newMapping.toFontChar;
  33726. tables['cmap'] = {
  33727. tag: 'cmap',
  33728. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  33729. };
  33730. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  33731. tables['OS/2'] = {
  33732. tag: 'OS/2',
  33733. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  33734. metricsOverride)
  33735. };
  33736. }
  33737. // Rewrite the 'post' table if needed
  33738. if (!tables['post']) {
  33739. tables['post'] = {
  33740. tag: 'post',
  33741. data: createPostTable(properties)
  33742. };
  33743. }
  33744. if (!isTrueType) {
  33745. try {
  33746. // Trying to repair CFF file
  33747. cffFile = new Stream(tables['CFF '].data);
  33748. var parser = new CFFParser(cffFile, properties);
  33749. cff = parser.parse();
  33750. var compiler = new CFFCompiler(cff);
  33751. tables['CFF '].data = compiler.compile();
  33752. } catch (e) {
  33753. warn('Failed to compile font ' + properties.loadedName);
  33754. }
  33755. }
  33756. // Re-creating 'name' table
  33757. if (!tables['name']) {
  33758. tables['name'] = {
  33759. tag: 'name',
  33760. data: createNameTable(this.name)
  33761. };
  33762. } else {
  33763. // ... using existing 'name' table as prototype
  33764. var namePrototype = readNameTable(tables['name']);
  33765. tables['name'].data = createNameTable(name, namePrototype);
  33766. }
  33767. var builder = new OpenTypeFileBuilder(header.version);
  33768. for (var tableTag in tables) {
  33769. builder.addTable(tableTag, tables[tableTag].data);
  33770. }
  33771. return builder.toArray();
  33772. },
  33773. convert: function Font_convert(fontName, font, properties) {
  33774. // TODO: Check the charstring widths to determine this.
  33775. properties.fixedPitch = false;
  33776. var mapping = font.getGlyphMapping(properties);
  33777. var newMapping = adjustMapping(mapping, properties);
  33778. this.toFontChar = newMapping.toFontChar;
  33779. var numGlyphs = font.numGlyphs;
  33780. function getCharCodes(charCodeToGlyphId, glyphId) {
  33781. var charCodes = null;
  33782. for (var charCode in charCodeToGlyphId) {
  33783. if (glyphId === charCodeToGlyphId[charCode]) {
  33784. if (!charCodes) {
  33785. charCodes = [];
  33786. }
  33787. charCodes.push(charCode | 0);
  33788. }
  33789. }
  33790. return charCodes;
  33791. }
  33792. function createCharCode(charCodeToGlyphId, glyphId) {
  33793. for (var charCode in charCodeToGlyphId) {
  33794. if (glyphId === charCodeToGlyphId[charCode]) {
  33795. return charCode | 0;
  33796. }
  33797. }
  33798. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  33799. glyphId;
  33800. return newMapping.nextAvailableFontCharCode++;
  33801. }
  33802. var seacs = font.seacs;
  33803. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  33804. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  33805. var charset = font.getCharset();
  33806. var seacMap = Object.create(null);
  33807. for (var glyphId in seacs) {
  33808. glyphId |= 0;
  33809. var seac = seacs[glyphId];
  33810. var baseGlyphName = StandardEncoding[seac[2]];
  33811. var accentGlyphName = StandardEncoding[seac[3]];
  33812. var baseGlyphId = charset.indexOf(baseGlyphName);
  33813. var accentGlyphId = charset.indexOf(accentGlyphName);
  33814. if (baseGlyphId < 0 || accentGlyphId < 0) {
  33815. continue;
  33816. }
  33817. var accentOffset = {
  33818. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  33819. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  33820. };
  33821. var charCodes = getCharCodes(mapping, glyphId);
  33822. if (!charCodes) {
  33823. // There's no point in mapping it if the char code was never mapped
  33824. // to begin with.
  33825. continue;
  33826. }
  33827. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  33828. var charCode = charCodes[i];
  33829. // Find a fontCharCode that maps to the base and accent glyphs.
  33830. // If one doesn't exists, create it.
  33831. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  33832. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  33833. baseGlyphId);
  33834. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  33835. accentGlyphId);
  33836. seacMap[charCode] = {
  33837. baseFontCharCode: baseFontCharCode,
  33838. accentFontCharCode: accentFontCharCode,
  33839. accentOffset: accentOffset
  33840. };
  33841. }
  33842. }
  33843. properties.seacMap = seacMap;
  33844. }
  33845. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  33846. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  33847. // PostScript Font Program
  33848. builder.addTable('CFF ', font.data);
  33849. // OS/2 and Windows Specific metrics
  33850. builder.addTable('OS/2', createOS2Table(properties,
  33851. newMapping.charCodeToGlyphId));
  33852. // Character to glyphs mapping
  33853. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  33854. numGlyphs));
  33855. // Font header
  33856. builder.addTable('head',
  33857. '\x00\x01\x00\x00' + // Version number
  33858. '\x00\x00\x10\x00' + // fontRevision
  33859. '\x00\x00\x00\x00' + // checksumAdjustement
  33860. '\x5F\x0F\x3C\xF5' + // magicNumber
  33861. '\x00\x00' + // Flags
  33862. safeString16(unitsPerEm) + // unitsPerEM
  33863. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  33864. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  33865. '\x00\x00' + // xMin
  33866. safeString16(properties.descent) + // yMin
  33867. '\x0F\xFF' + // xMax
  33868. safeString16(properties.ascent) + // yMax
  33869. string16(properties.italicAngle ? 2 : 0) + // macStyle
  33870. '\x00\x11' + // lowestRecPPEM
  33871. '\x00\x00' + // fontDirectionHint
  33872. '\x00\x00' + // indexToLocFormat
  33873. '\x00\x00'); // glyphDataFormat
  33874. // Horizontal header
  33875. builder.addTable('hhea',
  33876. '\x00\x01\x00\x00' + // Version number
  33877. safeString16(properties.ascent) + // Typographic Ascent
  33878. safeString16(properties.descent) + // Typographic Descent
  33879. '\x00\x00' + // Line Gap
  33880. '\xFF\xFF' + // advanceWidthMax
  33881. '\x00\x00' + // minLeftSidebearing
  33882. '\x00\x00' + // minRightSidebearing
  33883. '\x00\x00' + // xMaxExtent
  33884. safeString16(properties.capHeight) + // caretSlopeRise
  33885. safeString16(Math.tan(properties.italicAngle) *
  33886. properties.xHeight) + // caretSlopeRun
  33887. '\x00\x00' + // caretOffset
  33888. '\x00\x00' + // -reserved-
  33889. '\x00\x00' + // -reserved-
  33890. '\x00\x00' + // -reserved-
  33891. '\x00\x00' + // -reserved-
  33892. '\x00\x00' + // metricDataFormat
  33893. string16(numGlyphs)); // Number of HMetrics
  33894. // Horizontal metrics
  33895. builder.addTable('hmtx', (function fontFieldsHmtx() {
  33896. var charstrings = font.charstrings;
  33897. var cffWidths = font.cff ? font.cff.widths : null;
  33898. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  33899. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  33900. var width = 0;
  33901. if (charstrings) {
  33902. var charstring = charstrings[i - 1];
  33903. width = 'width' in charstring ? charstring.width : 0;
  33904. } else if (cffWidths) {
  33905. width = Math.ceil(cffWidths[i] || 0);
  33906. }
  33907. hmtx += string16(width) + string16(0);
  33908. }
  33909. return hmtx;
  33910. })());
  33911. // Maximum profile
  33912. builder.addTable('maxp',
  33913. '\x00\x00\x50\x00' + // Version number
  33914. string16(numGlyphs)); // Num of glyphs
  33915. // Naming tables
  33916. builder.addTable('name', createNameTable(fontName));
  33917. // PostScript informations
  33918. builder.addTable('post', createPostTable(properties));
  33919. return builder.toArray();
  33920. },
  33921. /**
  33922. * Builds a char code to unicode map based on section 9.10 of the spec.
  33923. * @param {Object} properties Font properties object.
  33924. * @return {Object} A ToUnicodeMap object.
  33925. */
  33926. buildToUnicode: function Font_buildToUnicode(properties) {
  33927. // Section 9.10.2 Mapping Character Codes to Unicode Values
  33928. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  33929. return properties.toUnicode;
  33930. }
  33931. // According to the spec if the font is a simple font we should only map
  33932. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  33933. // the differences array only contains adobe standard or symbol set names,
  33934. // in pratice it seems better to always try to create a toUnicode
  33935. // map based of the default encoding.
  33936. var toUnicode, charcode;
  33937. if (!properties.composite /* is simple font */) {
  33938. toUnicode = [];
  33939. var encoding = properties.defaultEncoding.slice();
  33940. var baseEncodingName = properties.baseEncodingName;
  33941. // Merge in the differences array.
  33942. var differences = properties.differences;
  33943. for (charcode in differences) {
  33944. encoding[charcode] = differences[charcode];
  33945. }
  33946. var glyphsUnicodeMap = getGlyphsUnicode();
  33947. for (charcode in encoding) {
  33948. // a) Map the character code to a character name.
  33949. var glyphName = encoding[charcode];
  33950. // b) Look up the character name in the Adobe Glyph List (see the
  33951. // Bibliography) to obtain the corresponding Unicode value.
  33952. if (glyphName === '') {
  33953. continue;
  33954. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  33955. // (undocumented) c) Few heuristics to recognize unknown glyphs
  33956. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  33957. var code = 0;
  33958. switch (glyphName[0]) {
  33959. case 'G': // Gxx glyph
  33960. if (glyphName.length === 3) {
  33961. code = parseInt(glyphName.substr(1), 16);
  33962. }
  33963. break;
  33964. case 'g': // g00xx glyph
  33965. if (glyphName.length === 5) {
  33966. code = parseInt(glyphName.substr(1), 16);
  33967. }
  33968. break;
  33969. case 'C': // Cddd glyph
  33970. case 'c': // cddd glyph
  33971. if (glyphName.length >= 3) {
  33972. code = +glyphName.substr(1);
  33973. }
  33974. break;
  33975. }
  33976. if (code) {
  33977. // If |baseEncodingName| is one the predefined encodings,
  33978. // and |code| equals |charcode|, using the glyph defined in the
  33979. // baseEncoding seems to yield a better |toUnicode| mapping
  33980. // (fixes issue 5070).
  33981. if (baseEncodingName && code === +charcode) {
  33982. var baseEncoding = getEncoding(baseEncodingName);
  33983. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  33984. toUnicode[charcode] =
  33985. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  33986. continue;
  33987. }
  33988. }
  33989. toUnicode[charcode] = String.fromCharCode(code);
  33990. }
  33991. continue;
  33992. }
  33993. toUnicode[charcode] =
  33994. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  33995. }
  33996. return new ToUnicodeMap(toUnicode);
  33997. }
  33998. // If the font is a composite font that uses one of the predefined CMaps
  33999. // listed in Table 118 (except Identity–H and Identity–V) or whose
  34000. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  34001. // Adobe-Korea1 character collection:
  34002. if (properties.composite && (
  34003. (properties.cMap.builtInCMap &&
  34004. !(properties.cMap instanceof IdentityCMap)) ||
  34005. (properties.cidSystemInfo.registry === 'Adobe' &&
  34006. (properties.cidSystemInfo.ordering === 'GB1' ||
  34007. properties.cidSystemInfo.ordering === 'CNS1' ||
  34008. properties.cidSystemInfo.ordering === 'Japan1' ||
  34009. properties.cidSystemInfo.ordering === 'Korea1')))) {
  34010. // Then:
  34011. // a) Map the character code to a character identifier (CID) according
  34012. // to the font’s CMap.
  34013. // b) Obtain the registry and ordering of the character collection used
  34014. // by the font’s CMap (for example, Adobe and Japan1) from its
  34015. // CIDSystemInfo dictionary.
  34016. var registry = properties.cidSystemInfo.registry;
  34017. var ordering = properties.cidSystemInfo.ordering;
  34018. // c) Construct a second CMap name by concatenating the registry and
  34019. // ordering obtained in step (b) in the format registry–ordering–UCS2
  34020. // (for example, Adobe–Japan1–UCS2).
  34021. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  34022. // d) Obtain the CMap with the name constructed in step (c) (available
  34023. // from the ASN Web site; see the Bibliography).
  34024. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  34025. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  34026. var cMap = properties.cMap;
  34027. toUnicode = [];
  34028. cMap.forEach(function(charcode, cid) {
  34029. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34030. // e) Map the CID obtained in step (a) according to the CMap obtained
  34031. // in step (d), producing a Unicode value.
  34032. var ucs2 = ucs2CMap.lookup(cid);
  34033. if (ucs2) {
  34034. toUnicode[charcode] =
  34035. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  34036. ucs2.charCodeAt(1));
  34037. }
  34038. });
  34039. return new ToUnicodeMap(toUnicode);
  34040. }
  34041. // The viewer's choice, just use an identity map.
  34042. return new IdentityToUnicodeMap(properties.firstChar,
  34043. properties.lastChar);
  34044. },
  34045. get spaceWidth() {
  34046. if ('_shadowWidth' in this) {
  34047. return this._shadowWidth;
  34048. }
  34049. // trying to estimate space character width
  34050. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34051. var width;
  34052. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34053. var glyphName = possibleSpaceReplacements[i];
  34054. // if possible, getting width by glyph name
  34055. if (glyphName in this.widths) {
  34056. width = this.widths[glyphName];
  34057. break;
  34058. }
  34059. var glyphsUnicodeMap = getGlyphsUnicode();
  34060. var glyphUnicode = glyphsUnicodeMap[glyphName];
  34061. // finding the charcode via unicodeToCID map
  34062. var charcode = 0;
  34063. if (this.composite) {
  34064. if (this.cMap.contains(glyphUnicode)) {
  34065. charcode = this.cMap.lookup(glyphUnicode);
  34066. }
  34067. }
  34068. // ... via toUnicode map
  34069. if (!charcode && this.toUnicode) {
  34070. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34071. }
  34072. // setting it to unicode if negative or undefined
  34073. if (charcode <= 0) {
  34074. charcode = glyphUnicode;
  34075. }
  34076. // trying to get width via charcode
  34077. width = this.widths[charcode];
  34078. if (width) {
  34079. break; // the non-zero width found
  34080. }
  34081. }
  34082. width = width || this.defaultWidth;
  34083. // Do not shadow the property here. See discussion:
  34084. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34085. this._shadowWidth = width;
  34086. return width;
  34087. },
  34088. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34089. var fontCharCode, width, operatorListId;
  34090. var widthCode = charcode;
  34091. if (this.cMap && this.cMap.contains(charcode)) {
  34092. widthCode = this.cMap.lookup(charcode);
  34093. }
  34094. width = this.widths[widthCode];
  34095. width = isNum(width) ? width : this.defaultWidth;
  34096. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34097. var unicode = this.toUnicode.get(charcode) || charcode;
  34098. if (typeof unicode === 'number') {
  34099. unicode = String.fromCharCode(unicode);
  34100. }
  34101. // First try the toFontChar map, if it's not there then try falling
  34102. // back to the char code.
  34103. fontCharCode = this.toFontChar[charcode] || charcode;
  34104. if (this.missingFile) {
  34105. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34106. }
  34107. if (this.isType3Font) {
  34108. // Font char code in this case is actually a glyph name.
  34109. operatorListId = fontCharCode;
  34110. }
  34111. var accent = null;
  34112. if (this.seacMap && this.seacMap[charcode]) {
  34113. var seac = this.seacMap[charcode];
  34114. fontCharCode = seac.baseFontCharCode;
  34115. accent = {
  34116. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34117. offset: seac.accentOffset
  34118. };
  34119. }
  34120. var fontChar = String.fromCharCode(fontCharCode);
  34121. var glyph = this.glyphCache[charcode];
  34122. if (!glyph ||
  34123. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34124. operatorListId, isSpace)) {
  34125. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34126. operatorListId, isSpace);
  34127. this.glyphCache[charcode] = glyph;
  34128. }
  34129. return glyph;
  34130. },
  34131. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34132. var charsCache = this.charsCache;
  34133. var glyphs, glyph, charcode;
  34134. // if we translated this string before, just grab it from the cache
  34135. if (charsCache) {
  34136. glyphs = charsCache[chars];
  34137. if (glyphs) {
  34138. return glyphs;
  34139. }
  34140. }
  34141. // lazily create the translation cache
  34142. if (!charsCache) {
  34143. charsCache = this.charsCache = Object.create(null);
  34144. }
  34145. glyphs = [];
  34146. var charsCacheKey = chars;
  34147. var i = 0, ii;
  34148. if (this.cMap) {
  34149. // composite fonts have multi-byte strings convert the string from
  34150. // single-byte to multi-byte
  34151. var c = Object.create(null);
  34152. while (i < chars.length) {
  34153. this.cMap.readCharCode(chars, i, c);
  34154. charcode = c.charcode;
  34155. var length = c.length;
  34156. i += length;
  34157. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34158. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34159. glyph = this.charToGlyph(charcode, isSpace);
  34160. glyphs.push(glyph);
  34161. }
  34162. } else {
  34163. for (i = 0, ii = chars.length; i < ii; ++i) {
  34164. charcode = chars.charCodeAt(i);
  34165. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34166. glyphs.push(glyph);
  34167. }
  34168. }
  34169. // Enter the translated string into the cache
  34170. return (charsCache[charsCacheKey] = glyphs);
  34171. }
  34172. };
  34173. return Font;
  34174. })();
  34175. var ErrorFont = (function ErrorFontClosure() {
  34176. function ErrorFont(error) {
  34177. this.error = error;
  34178. this.loadedName = 'g_font_error';
  34179. this.loading = false;
  34180. }
  34181. ErrorFont.prototype = {
  34182. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34183. return [];
  34184. },
  34185. exportData: function ErrorFont_exportData() {
  34186. return {error: this.error};
  34187. }
  34188. };
  34189. return ErrorFont;
  34190. })();
  34191. /**
  34192. * Shared logic for building a char code to glyph id mapping for Type1 and
  34193. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34194. * @param {Object} properties Font properties object.
  34195. * @param {Object} builtInEncoding The encoding contained within the actual font
  34196. * data.
  34197. * @param {Array} Array of glyph names where the index is the glyph ID.
  34198. * @returns {Object} A char code to glyph ID map.
  34199. */
  34200. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34201. var charCodeToGlyphId = Object.create(null);
  34202. var glyphId, charCode, baseEncoding;
  34203. if (properties.baseEncodingName) {
  34204. // If a valid base encoding name was used, the mapping is initialized with
  34205. // that.
  34206. baseEncoding = getEncoding(properties.baseEncodingName);
  34207. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34208. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34209. if (glyphId >= 0) {
  34210. charCodeToGlyphId[charCode] = glyphId;
  34211. } else {
  34212. charCodeToGlyphId[charCode] = 0; // notdef
  34213. }
  34214. }
  34215. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34216. // For a symbolic font the encoding should be the fonts built-in
  34217. // encoding.
  34218. for (charCode in builtInEncoding) {
  34219. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34220. }
  34221. } else {
  34222. // For non-symbolic fonts that don't have a base encoding the standard
  34223. // encoding should be used.
  34224. baseEncoding = StandardEncoding;
  34225. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34226. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34227. if (glyphId >= 0) {
  34228. charCodeToGlyphId[charCode] = glyphId;
  34229. } else {
  34230. charCodeToGlyphId[charCode] = 0; // notdef
  34231. }
  34232. }
  34233. }
  34234. // Lastly, merge in the differences.
  34235. var differences = properties.differences;
  34236. if (differences) {
  34237. for (charCode in differences) {
  34238. var glyphName = differences[charCode];
  34239. glyphId = glyphNames.indexOf(glyphName);
  34240. if (glyphId >= 0) {
  34241. charCodeToGlyphId[charCode] = glyphId;
  34242. } else {
  34243. charCodeToGlyphId[charCode] = 0; // notdef
  34244. }
  34245. }
  34246. }
  34247. return charCodeToGlyphId;
  34248. }
  34249. /*
  34250. * CharStrings are encoded following the the CharString Encoding sequence
  34251. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  34252. * The value in a byte indicates a command, a number, or subsequent bytes
  34253. * that are to be interpreted in a special way.
  34254. *
  34255. * CharString Number Encoding:
  34256. * A CharString byte containing the values from 32 through 255 inclusive
  34257. * indicate an integer. These values are decoded in four ranges.
  34258. *
  34259. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  34260. * indicate the integer v - 139. Thus, the integer values from -107 through
  34261. * 107 inclusive may be encoded in single byte.
  34262. *
  34263. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  34264. * indicates an integer involving the next byte, w, according to the formula:
  34265. * [(v - 247) x 256] + w + 108
  34266. *
  34267. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  34268. * indicates an integer involving the next byte, w, according to the formula:
  34269. * -[(v - 251) * 256] - w - 108
  34270. *
  34271. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  34272. * are a two complement signed integer. The first of these bytes contains the
  34273. * highest order bits, the second byte contains the next higher order bits
  34274. * and the fourth byte contain the lowest order bits.
  34275. *
  34276. *
  34277. * CharString Command Encoding:
  34278. * CharStrings commands are encoded in 1 or 2 bytes.
  34279. *
  34280. * Single byte commands are encoded in 1 byte that contains a value between
  34281. * 0 and 31 inclusive.
  34282. * If a command byte contains the value 12, then the value in the next byte
  34283. * indicates a command. This "escape" mechanism allows many extra commands
  34284. * to be encoded and this encoding technique helps to minimize the length of
  34285. * the charStrings.
  34286. */
  34287. var Type1CharString = (function Type1CharStringClosure() {
  34288. var COMMAND_MAP = {
  34289. 'hstem': [1],
  34290. 'vstem': [3],
  34291. 'vmoveto': [4],
  34292. 'rlineto': [5],
  34293. 'hlineto': [6],
  34294. 'vlineto': [7],
  34295. 'rrcurveto': [8],
  34296. 'callsubr': [10],
  34297. 'flex': [12, 35],
  34298. 'drop' : [12, 18],
  34299. 'endchar': [14],
  34300. 'rmoveto': [21],
  34301. 'hmoveto': [22],
  34302. 'vhcurveto': [30],
  34303. 'hvcurveto': [31]
  34304. };
  34305. function Type1CharString() {
  34306. this.width = 0;
  34307. this.lsb = 0;
  34308. this.flexing = false;
  34309. this.output = [];
  34310. this.stack = [];
  34311. }
  34312. Type1CharString.prototype = {
  34313. convert: function Type1CharString_convert(encoded, subrs) {
  34314. var count = encoded.length;
  34315. var error = false;
  34316. var wx, sbx, subrNumber;
  34317. for (var i = 0; i < count; i++) {
  34318. var value = encoded[i];
  34319. if (value < 32) {
  34320. if (value === 12) {
  34321. value = (value << 8) + encoded[++i];
  34322. }
  34323. switch (value) {
  34324. case 1: // hstem
  34325. if (!HINTING_ENABLED) {
  34326. this.stack = [];
  34327. break;
  34328. }
  34329. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34330. break;
  34331. case 3: // vstem
  34332. if (!HINTING_ENABLED) {
  34333. this.stack = [];
  34334. break;
  34335. }
  34336. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34337. break;
  34338. case 4: // vmoveto
  34339. if (this.flexing) {
  34340. if (this.stack.length < 1) {
  34341. error = true;
  34342. break;
  34343. }
  34344. // Add the dx for flex and but also swap the values so they are
  34345. // the right order.
  34346. var dy = this.stack.pop();
  34347. this.stack.push(0, dy);
  34348. break;
  34349. }
  34350. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  34351. break;
  34352. case 5: // rlineto
  34353. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  34354. break;
  34355. case 6: // hlineto
  34356. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  34357. break;
  34358. case 7: // vlineto
  34359. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  34360. break;
  34361. case 8: // rrcurveto
  34362. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  34363. break;
  34364. case 9: // closepath
  34365. // closepath is a Type1 command that does not take argument and is
  34366. // useless in Type2 and it can simply be ignored.
  34367. this.stack = [];
  34368. break;
  34369. case 10: // callsubr
  34370. if (this.stack.length < 1) {
  34371. error = true;
  34372. break;
  34373. }
  34374. subrNumber = this.stack.pop();
  34375. error = this.convert(subrs[subrNumber], subrs);
  34376. break;
  34377. case 11: // return
  34378. return error;
  34379. case 13: // hsbw
  34380. if (this.stack.length < 2) {
  34381. error = true;
  34382. break;
  34383. }
  34384. // To convert to type2 we have to move the width value to the
  34385. // first part of the charstring and then use hmoveto with lsb.
  34386. wx = this.stack.pop();
  34387. sbx = this.stack.pop();
  34388. this.lsb = sbx;
  34389. this.width = wx;
  34390. this.stack.push(wx, sbx);
  34391. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  34392. break;
  34393. case 14: // endchar
  34394. this.output.push(COMMAND_MAP.endchar[0]);
  34395. break;
  34396. case 21: // rmoveto
  34397. if (this.flexing) {
  34398. break;
  34399. }
  34400. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  34401. break;
  34402. case 22: // hmoveto
  34403. if (this.flexing) {
  34404. // Add the dy for flex.
  34405. this.stack.push(0);
  34406. break;
  34407. }
  34408. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  34409. break;
  34410. case 30: // vhcurveto
  34411. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  34412. break;
  34413. case 31: // hvcurveto
  34414. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  34415. break;
  34416. case (12 << 8) + 0: // dotsection
  34417. // dotsection is a Type1 command to specify some hinting feature
  34418. // for dots that do not take a parameter and it can safely be
  34419. // ignored for Type2.
  34420. this.stack = [];
  34421. break;
  34422. case (12 << 8) + 1: // vstem3
  34423. if (!HINTING_ENABLED) {
  34424. this.stack = [];
  34425. break;
  34426. }
  34427. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  34428. // multiple parameters, so instead of returning [vh]stem3 take a
  34429. // shortcut and return [vhstem] instead.
  34430. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34431. break;
  34432. case (12 << 8) + 2: // hstem3
  34433. if (!HINTING_ENABLED) {
  34434. this.stack = [];
  34435. break;
  34436. }
  34437. // See vstem3.
  34438. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34439. break;
  34440. case (12 << 8) + 6: // seac
  34441. // seac is like type 2's special endchar but it doesn't use the
  34442. // first argument asb, so remove it.
  34443. if (SEAC_ANALYSIS_ENABLED) {
  34444. this.seac = this.stack.splice(-4, 4);
  34445. error = this.executeCommand(0, COMMAND_MAP.endchar);
  34446. } else {
  34447. error = this.executeCommand(4, COMMAND_MAP.endchar);
  34448. }
  34449. break;
  34450. case (12 << 8) + 7: // sbw
  34451. if (this.stack.length < 4) {
  34452. error = true;
  34453. break;
  34454. }
  34455. // To convert to type2 we have to move the width value to the
  34456. // first part of the charstring and then use rmoveto with
  34457. // (dx, dy). The height argument will not be used for vmtx and
  34458. // vhea tables reconstruction -- ignoring it.
  34459. var wy = this.stack.pop();
  34460. wx = this.stack.pop();
  34461. var sby = this.stack.pop();
  34462. sbx = this.stack.pop();
  34463. this.lsb = sbx;
  34464. this.width = wx;
  34465. this.stack.push(wx, sbx, sby);
  34466. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  34467. break;
  34468. case (12 << 8) + 12: // div
  34469. if (this.stack.length < 2) {
  34470. error = true;
  34471. break;
  34472. }
  34473. var num2 = this.stack.pop();
  34474. var num1 = this.stack.pop();
  34475. this.stack.push(num1 / num2);
  34476. break;
  34477. case (12 << 8) + 16: // callothersubr
  34478. if (this.stack.length < 2) {
  34479. error = true;
  34480. break;
  34481. }
  34482. subrNumber = this.stack.pop();
  34483. var numArgs = this.stack.pop();
  34484. if (subrNumber === 0 && numArgs === 3) {
  34485. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  34486. this.stack.push(
  34487. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  34488. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  34489. flexArgs[4], // bcp2x
  34490. flexArgs[5], // bcp2y
  34491. flexArgs[6], // p2x
  34492. flexArgs[7], // p2y
  34493. flexArgs[8], // bcp3x
  34494. flexArgs[9], // bcp3y
  34495. flexArgs[10], // bcp4x
  34496. flexArgs[11], // bcp4y
  34497. flexArgs[12], // p3x
  34498. flexArgs[13], // p3y
  34499. flexArgs[14] // flexDepth
  34500. // 15 = finalx unused by flex
  34501. // 16 = finaly unused by flex
  34502. );
  34503. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  34504. this.flexing = false;
  34505. this.stack.push(flexArgs[15], flexArgs[16]);
  34506. } else if (subrNumber === 1 && numArgs === 0) {
  34507. this.flexing = true;
  34508. }
  34509. break;
  34510. case (12 << 8) + 17: // pop
  34511. // Ignore this since it is only used with othersubr.
  34512. break;
  34513. case (12 << 8) + 33: // setcurrentpoint
  34514. // Ignore for now.
  34515. this.stack = [];
  34516. break;
  34517. default:
  34518. warn('Unknown type 1 charstring command of "' + value + '"');
  34519. break;
  34520. }
  34521. if (error) {
  34522. break;
  34523. }
  34524. continue;
  34525. } else if (value <= 246) {
  34526. value = value - 139;
  34527. } else if (value <= 250) {
  34528. value = ((value - 247) * 256) + encoded[++i] + 108;
  34529. } else if (value <= 254) {
  34530. value = -((value - 251) * 256) - encoded[++i] - 108;
  34531. } else {
  34532. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  34533. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  34534. }
  34535. this.stack.push(value);
  34536. }
  34537. return error;
  34538. },
  34539. executeCommand: function(howManyArgs, command, keepStack) {
  34540. var stackLength = this.stack.length;
  34541. if (howManyArgs > stackLength) {
  34542. return true;
  34543. }
  34544. var start = stackLength - howManyArgs;
  34545. for (var i = start; i < stackLength; i++) {
  34546. var value = this.stack[i];
  34547. if (value === (value | 0)) { // int
  34548. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  34549. } else { // fixed point
  34550. value = (65536 * value) | 0;
  34551. this.output.push(255,
  34552. (value >> 24) & 0xFF,
  34553. (value >> 16) & 0xFF,
  34554. (value >> 8) & 0xFF,
  34555. value & 0xFF);
  34556. }
  34557. }
  34558. this.output.push.apply(this.output, command);
  34559. if (keepStack) {
  34560. this.stack.splice(start, howManyArgs);
  34561. } else {
  34562. this.stack.length = 0;
  34563. }
  34564. return false;
  34565. }
  34566. };
  34567. return Type1CharString;
  34568. })();
  34569. /*
  34570. * Type1Parser encapsulate the needed code for parsing a Type1 font
  34571. * program. Some of its logic depends on the Type2 charstrings
  34572. * structure.
  34573. * Note: this doesn't really parse the font since that would require evaluation
  34574. * of PostScript, but it is possible in most cases to extract what we need
  34575. * without a full parse.
  34576. */
  34577. var Type1Parser = (function Type1ParserClosure() {
  34578. /*
  34579. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  34580. * of Plaintext Bytes. The function took a key as a parameter which can be
  34581. * for decrypting the eexec block of for decoding charStrings.
  34582. */
  34583. var EEXEC_ENCRYPT_KEY = 55665;
  34584. var CHAR_STRS_ENCRYPT_KEY = 4330;
  34585. function isHexDigit(code) {
  34586. return code >= 48 && code <= 57 || // '0'-'9'
  34587. code >= 65 && code <= 70 || // 'A'-'F'
  34588. code >= 97 && code <= 102; // 'a'-'f'
  34589. }
  34590. function decrypt(data, key, discardNumber) {
  34591. if (discardNumber >= data.length) {
  34592. return new Uint8Array(0);
  34593. }
  34594. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  34595. for (i = 0; i < discardNumber; i++) {
  34596. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  34597. }
  34598. var count = data.length - discardNumber;
  34599. var decrypted = new Uint8Array(count);
  34600. for (i = discardNumber, j = 0; j < count; i++, j++) {
  34601. var value = data[i];
  34602. decrypted[j] = value ^ (r >> 8);
  34603. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34604. }
  34605. return decrypted;
  34606. }
  34607. function decryptAscii(data, key, discardNumber) {
  34608. var r = key | 0, c1 = 52845, c2 = 22719;
  34609. var count = data.length, maybeLength = count >>> 1;
  34610. var decrypted = new Uint8Array(maybeLength);
  34611. var i, j;
  34612. for (i = 0, j = 0; i < count; i++) {
  34613. var digit1 = data[i];
  34614. if (!isHexDigit(digit1)) {
  34615. continue;
  34616. }
  34617. i++;
  34618. var digit2;
  34619. while (i < count && !isHexDigit(digit2 = data[i])) {
  34620. i++;
  34621. }
  34622. if (i < count) {
  34623. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  34624. decrypted[j++] = value ^ (r >> 8);
  34625. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34626. }
  34627. }
  34628. return Array.prototype.slice.call(decrypted, discardNumber, j);
  34629. }
  34630. function isSpecial(c) {
  34631. return c === 0x2F || // '/'
  34632. c === 0x5B || c === 0x5D || // '[', ']'
  34633. c === 0x7B || c === 0x7D || // '{', '}'
  34634. c === 0x28 || c === 0x29; // '(', ')'
  34635. }
  34636. function Type1Parser(stream, encrypted) {
  34637. if (encrypted) {
  34638. var data = stream.getBytes();
  34639. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  34640. isHexDigit(data[2]) && isHexDigit(data[3]));
  34641. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  34642. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  34643. }
  34644. this.stream = stream;
  34645. this.nextChar();
  34646. }
  34647. Type1Parser.prototype = {
  34648. readNumberArray: function Type1Parser_readNumberArray() {
  34649. this.getToken(); // read '[' or '{' (arrays can start with either)
  34650. var array = [];
  34651. while (true) {
  34652. var token = this.getToken();
  34653. if (token === null || token === ']' || token === '}') {
  34654. break;
  34655. }
  34656. array.push(parseFloat(token || 0));
  34657. }
  34658. return array;
  34659. },
  34660. readNumber: function Type1Parser_readNumber() {
  34661. var token = this.getToken();
  34662. return parseFloat(token || 0);
  34663. },
  34664. readInt: function Type1Parser_readInt() {
  34665. // Use '| 0' to prevent setting a double into length such as the double
  34666. // does not flow into the loop variable.
  34667. var token = this.getToken();
  34668. return parseInt(token || 0, 10) | 0;
  34669. },
  34670. readBoolean: function Type1Parser_readBoolean() {
  34671. var token = this.getToken();
  34672. // Use 1 and 0 since that's what type2 charstrings use.
  34673. return token === 'true' ? 1 : 0;
  34674. },
  34675. nextChar : function Type1_nextChar() {
  34676. return (this.currentChar = this.stream.getByte());
  34677. },
  34678. getToken: function Type1Parser_getToken() {
  34679. // Eat whitespace and comments.
  34680. var comment = false;
  34681. var ch = this.currentChar;
  34682. while (true) {
  34683. if (ch === -1) {
  34684. return null;
  34685. }
  34686. if (comment) {
  34687. if (ch === 0x0A || ch === 0x0D) {
  34688. comment = false;
  34689. }
  34690. } else if (ch === 0x25) { // '%'
  34691. comment = true;
  34692. } else if (!Lexer.isSpace(ch)) {
  34693. break;
  34694. }
  34695. ch = this.nextChar();
  34696. }
  34697. if (isSpecial(ch)) {
  34698. this.nextChar();
  34699. return String.fromCharCode(ch);
  34700. }
  34701. var token = '';
  34702. do {
  34703. token += String.fromCharCode(ch);
  34704. ch = this.nextChar();
  34705. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  34706. return token;
  34707. },
  34708. /*
  34709. * Returns an object containing a Subrs array and a CharStrings
  34710. * array extracted from and eexec encrypted block of data
  34711. */
  34712. extractFontProgram: function Type1Parser_extractFontProgram() {
  34713. var stream = this.stream;
  34714. var subrs = [], charstrings = [];
  34715. var privateData = Object.create(null);
  34716. privateData['lenIV'] = 4;
  34717. var program = {
  34718. subrs: [],
  34719. charstrings: [],
  34720. properties: {
  34721. 'privateData': privateData
  34722. }
  34723. };
  34724. var token, length, data, lenIV, encoded;
  34725. while ((token = this.getToken()) !== null) {
  34726. if (token !== '/') {
  34727. continue;
  34728. }
  34729. token = this.getToken();
  34730. switch (token) {
  34731. case 'CharStrings':
  34732. // The number immediately following CharStrings must be greater or
  34733. // equal to the number of CharStrings.
  34734. this.getToken();
  34735. this.getToken(); // read in 'dict'
  34736. this.getToken(); // read in 'dup'
  34737. this.getToken(); // read in 'begin'
  34738. while(true) {
  34739. token = this.getToken();
  34740. if (token === null || token === 'end') {
  34741. break;
  34742. }
  34743. if (token !== '/') {
  34744. continue;
  34745. }
  34746. var glyph = this.getToken();
  34747. length = this.readInt();
  34748. this.getToken(); // read in 'RD' or '-|'
  34749. data = stream.makeSubStream(stream.pos, length);
  34750. lenIV = program.properties.privateData['lenIV'];
  34751. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  34752. // Skip past the required space and binary data.
  34753. stream.skip(length);
  34754. this.nextChar();
  34755. token = this.getToken(); // read in 'ND' or '|-'
  34756. if (token === 'noaccess') {
  34757. this.getToken(); // read in 'def'
  34758. }
  34759. charstrings.push({
  34760. glyph: glyph,
  34761. encoded: encoded
  34762. });
  34763. }
  34764. break;
  34765. case 'Subrs':
  34766. var num = this.readInt();
  34767. this.getToken(); // read in 'array'
  34768. while ((token = this.getToken()) === 'dup') {
  34769. var index = this.readInt();
  34770. length = this.readInt();
  34771. this.getToken(); // read in 'RD' or '-|'
  34772. data = stream.makeSubStream(stream.pos, length);
  34773. lenIV = program.properties.privateData['lenIV'];
  34774. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  34775. // Skip past the required space and binary data.
  34776. stream.skip(length);
  34777. this.nextChar();
  34778. token = this.getToken(); // read in 'NP' or '|'
  34779. if (token === 'noaccess') {
  34780. this.getToken(); // read in 'put'
  34781. }
  34782. subrs[index] = encoded;
  34783. }
  34784. break;
  34785. case 'BlueValues':
  34786. case 'OtherBlues':
  34787. case 'FamilyBlues':
  34788. case 'FamilyOtherBlues':
  34789. var blueArray = this.readNumberArray();
  34790. // *Blue* values may contain invalid data: disables reading of
  34791. // those values when hinting is disabled.
  34792. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  34793. HINTING_ENABLED) {
  34794. program.properties.privateData[token] = blueArray;
  34795. }
  34796. break;
  34797. case 'StemSnapH':
  34798. case 'StemSnapV':
  34799. program.properties.privateData[token] = this.readNumberArray();
  34800. break;
  34801. case 'StdHW':
  34802. case 'StdVW':
  34803. program.properties.privateData[token] =
  34804. this.readNumberArray()[0];
  34805. break;
  34806. case 'BlueShift':
  34807. case 'lenIV':
  34808. case 'BlueFuzz':
  34809. case 'BlueScale':
  34810. case 'LanguageGroup':
  34811. case 'ExpansionFactor':
  34812. program.properties.privateData[token] = this.readNumber();
  34813. break;
  34814. case 'ForceBold':
  34815. program.properties.privateData[token] = this.readBoolean();
  34816. break;
  34817. }
  34818. }
  34819. for (var i = 0; i < charstrings.length; i++) {
  34820. glyph = charstrings[i].glyph;
  34821. encoded = charstrings[i].encoded;
  34822. var charString = new Type1CharString();
  34823. var error = charString.convert(encoded, subrs);
  34824. var output = charString.output;
  34825. if (error) {
  34826. // It seems when FreeType encounters an error while evaluating a glyph
  34827. // that it completely ignores the glyph so we'll mimic that behaviour
  34828. // here and put an endchar to make the validator happy.
  34829. output = [14];
  34830. }
  34831. program.charstrings.push({
  34832. glyphName: glyph,
  34833. charstring: output,
  34834. width: charString.width,
  34835. lsb: charString.lsb,
  34836. seac: charString.seac
  34837. });
  34838. }
  34839. return program;
  34840. },
  34841. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  34842. var token;
  34843. while ((token = this.getToken()) !== null) {
  34844. if (token !== '/') {
  34845. continue;
  34846. }
  34847. token = this.getToken();
  34848. switch (token) {
  34849. case 'FontMatrix':
  34850. var matrix = this.readNumberArray();
  34851. properties.fontMatrix = matrix;
  34852. break;
  34853. case 'Encoding':
  34854. var encodingArg = this.getToken();
  34855. var encoding;
  34856. if (!/^\d+$/.test(encodingArg)) {
  34857. // encoding name is specified
  34858. encoding = getEncoding(encodingArg);
  34859. } else {
  34860. encoding = [];
  34861. var size = parseInt(encodingArg, 10) | 0;
  34862. this.getToken(); // read in 'array'
  34863. for (var j = 0; j < size; j++) {
  34864. token = this.getToken();
  34865. // skipping till first dup or def (e.g. ignoring for statement)
  34866. while (token !== 'dup' && token !== 'def') {
  34867. token = this.getToken();
  34868. if (token === null) {
  34869. return; // invalid header
  34870. }
  34871. }
  34872. if (token === 'def') {
  34873. break; // read all array data
  34874. }
  34875. var index = this.readInt();
  34876. this.getToken(); // read in '/'
  34877. var glyph = this.getToken();
  34878. encoding[index] = glyph;
  34879. this.getToken(); // read the in 'put'
  34880. }
  34881. }
  34882. properties.builtInEncoding = encoding;
  34883. break;
  34884. case 'FontBBox':
  34885. var fontBBox = this.readNumberArray();
  34886. // adjusting ascent/descent
  34887. properties.ascent = fontBBox[3];
  34888. properties.descent = fontBBox[1];
  34889. properties.ascentScaled = true;
  34890. break;
  34891. }
  34892. }
  34893. }
  34894. };
  34895. return Type1Parser;
  34896. })();
  34897. /**
  34898. * The CFF class takes a Type1 file and wrap it into a
  34899. * 'Compact Font Format' which itself embed Type2 charstrings.
  34900. */
  34901. var CFFStandardStrings = [
  34902. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  34903. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  34904. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  34905. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  34906. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  34907. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  34908. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  34909. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  34910. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  34911. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  34912. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  34913. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  34914. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  34915. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  34916. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  34917. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  34918. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  34919. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  34920. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  34921. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  34922. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  34923. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  34924. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  34925. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  34926. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  34927. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  34928. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  34929. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  34930. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  34931. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  34932. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  34933. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  34934. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  34935. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  34936. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  34937. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  34938. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  34939. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  34940. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  34941. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  34942. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  34943. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  34944. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  34945. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  34946. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  34947. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  34948. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  34949. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  34950. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  34951. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  34952. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  34953. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  34954. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  34955. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  34956. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  34957. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  34958. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  34959. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  34960. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  34961. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  34962. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  34963. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  34964. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  34965. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  34966. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  34967. ];
  34968. // Type1Font is also a CIDFontType0.
  34969. var Type1Font = function Type1Font(name, file, properties) {
  34970. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  34971. // Also, length1 and length2 might be off by 6 bytes as well.
  34972. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  34973. var PFB_HEADER_SIZE = 6;
  34974. var headerBlockLength = properties.length1;
  34975. var eexecBlockLength = properties.length2;
  34976. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  34977. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  34978. if (pfbHeaderPresent) {
  34979. file.skip(PFB_HEADER_SIZE);
  34980. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  34981. (pfbHeader[3] << 8) | pfbHeader[2];
  34982. }
  34983. // Get the data block containing glyphs and subrs informations
  34984. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  34985. var headerBlockParser = new Type1Parser(headerBlock);
  34986. headerBlockParser.extractFontHeader(properties);
  34987. if (pfbHeaderPresent) {
  34988. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  34989. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  34990. (pfbHeader[3] << 8) | pfbHeader[2];
  34991. }
  34992. // Decrypt the data blocks and retrieve it's content
  34993. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  34994. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  34995. var data = eexecBlockParser.extractFontProgram();
  34996. for (var info in data.properties) {
  34997. properties[info] = data.properties[info];
  34998. }
  34999. var charstrings = data.charstrings;
  35000. var type2Charstrings = this.getType2Charstrings(charstrings);
  35001. var subrs = this.getType2Subrs(data.subrs);
  35002. this.charstrings = charstrings;
  35003. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  35004. subrs, properties);
  35005. this.seacs = this.getSeacs(data.charstrings);
  35006. };
  35007. Type1Font.prototype = {
  35008. get numGlyphs() {
  35009. return this.charstrings.length + 1;
  35010. },
  35011. getCharset: function Type1Font_getCharset() {
  35012. var charset = ['.notdef'];
  35013. var charstrings = this.charstrings;
  35014. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35015. charset.push(charstrings[glyphId].glyphName);
  35016. }
  35017. return charset;
  35018. },
  35019. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  35020. var charstrings = this.charstrings;
  35021. var glyphNames = ['.notdef'], glyphId;
  35022. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35023. glyphNames.push(charstrings[glyphId].glyphName);
  35024. }
  35025. var encoding = properties.builtInEncoding;
  35026. if (encoding) {
  35027. var builtInEncoding = Object.create(null);
  35028. for (var charCode in encoding) {
  35029. glyphId = glyphNames.indexOf(encoding[charCode]);
  35030. if (glyphId >= 0) {
  35031. builtInEncoding[charCode] = glyphId;
  35032. }
  35033. }
  35034. }
  35035. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  35036. },
  35037. getSeacs: function Type1Font_getSeacs(charstrings) {
  35038. var i, ii;
  35039. var seacMap = [];
  35040. for (i = 0, ii = charstrings.length; i < ii; i++) {
  35041. var charstring = charstrings[i];
  35042. if (charstring.seac) {
  35043. // Offset by 1 for .notdef
  35044. seacMap[i + 1] = charstring.seac;
  35045. }
  35046. }
  35047. return seacMap;
  35048. },
  35049. getType2Charstrings: function Type1Font_getType2Charstrings(
  35050. type1Charstrings) {
  35051. var type2Charstrings = [];
  35052. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  35053. type2Charstrings.push(type1Charstrings[i].charstring);
  35054. }
  35055. return type2Charstrings;
  35056. },
  35057. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  35058. var bias = 0;
  35059. var count = type1Subrs.length;
  35060. if (count < 1133) {
  35061. bias = 107;
  35062. } else if (count < 33769) {
  35063. bias = 1131;
  35064. } else {
  35065. bias = 32768;
  35066. }
  35067. // Add a bunch of empty subrs to deal with the Type2 bias
  35068. var type2Subrs = [];
  35069. var i;
  35070. for (i = 0; i < bias; i++) {
  35071. type2Subrs.push([0x0B]);
  35072. }
  35073. for (i = 0; i < count; i++) {
  35074. type2Subrs.push(type1Subrs[i]);
  35075. }
  35076. return type2Subrs;
  35077. },
  35078. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  35079. var cff = new CFF();
  35080. cff.header = new CFFHeader(1, 0, 4, 4);
  35081. cff.names = [name];
  35082. var topDict = new CFFTopDict();
  35083. // CFF strings IDs 0...390 are predefined names, so refering
  35084. // to entries in our own String INDEX starts at SID 391.
  35085. topDict.setByName('version', 391);
  35086. topDict.setByName('Notice', 392);
  35087. topDict.setByName('FullName', 393);
  35088. topDict.setByName('FamilyName', 394);
  35089. topDict.setByName('Weight', 395);
  35090. topDict.setByName('Encoding', null); // placeholder
  35091. topDict.setByName('FontMatrix', properties.fontMatrix);
  35092. topDict.setByName('FontBBox', properties.bbox);
  35093. topDict.setByName('charset', null); // placeholder
  35094. topDict.setByName('CharStrings', null); // placeholder
  35095. topDict.setByName('Private', null); // placeholder
  35096. cff.topDict = topDict;
  35097. var strings = new CFFStrings();
  35098. strings.add('Version 0.11'); // Version
  35099. strings.add('See original notice'); // Notice
  35100. strings.add(name); // FullName
  35101. strings.add(name); // FamilyName
  35102. strings.add('Medium'); // Weight
  35103. cff.strings = strings;
  35104. cff.globalSubrIndex = new CFFIndex();
  35105. var count = glyphs.length;
  35106. var charsetArray = [0];
  35107. var i, ii;
  35108. for (i = 0; i < count; i++) {
  35109. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  35110. // TODO: Insert the string and correctly map it. Previously it was
  35111. // thought mapping names that aren't in the standard strings to .notdef
  35112. // was fine, however in issue818 when mapping them all to .notdef the
  35113. // adieresis glyph no longer worked.
  35114. if (index === -1) {
  35115. index = 0;
  35116. }
  35117. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  35118. }
  35119. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  35120. var charStringsIndex = new CFFIndex();
  35121. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  35122. for (i = 0; i < count; i++) {
  35123. charStringsIndex.add(glyphs[i]);
  35124. }
  35125. cff.charStrings = charStringsIndex;
  35126. var privateDict = new CFFPrivateDict();
  35127. privateDict.setByName('Subrs', null); // placeholder
  35128. var fields = [
  35129. 'BlueValues',
  35130. 'OtherBlues',
  35131. 'FamilyBlues',
  35132. 'FamilyOtherBlues',
  35133. 'StemSnapH',
  35134. 'StemSnapV',
  35135. 'BlueShift',
  35136. 'BlueFuzz',
  35137. 'BlueScale',
  35138. 'LanguageGroup',
  35139. 'ExpansionFactor',
  35140. 'ForceBold',
  35141. 'StdHW',
  35142. 'StdVW'
  35143. ];
  35144. for (i = 0, ii = fields.length; i < ii; i++) {
  35145. var field = fields[i];
  35146. if (!(field in properties.privateData)) {
  35147. continue;
  35148. }
  35149. var value = properties.privateData[field];
  35150. if (isArray(value)) {
  35151. // All of the private dictionary array data in CFF must be stored as
  35152. // "delta-encoded" numbers.
  35153. for (var j = value.length - 1; j > 0; j--) {
  35154. value[j] -= value[j - 1]; // ... difference from previous value
  35155. }
  35156. }
  35157. privateDict.setByName(field, value);
  35158. }
  35159. cff.topDict.privateDict = privateDict;
  35160. var subrIndex = new CFFIndex();
  35161. for (i = 0, ii = subrs.length; i < ii; i++) {
  35162. subrIndex.add(subrs[i]);
  35163. }
  35164. privateDict.subrsIndex = subrIndex;
  35165. var compiler = new CFFCompiler(cff);
  35166. return compiler.compile();
  35167. }
  35168. };
  35169. var CFFFont = (function CFFFontClosure() {
  35170. function CFFFont(file, properties) {
  35171. this.properties = properties;
  35172. var parser = new CFFParser(file, properties);
  35173. this.cff = parser.parse();
  35174. var compiler = new CFFCompiler(this.cff);
  35175. this.seacs = this.cff.seacs;
  35176. try {
  35177. this.data = compiler.compile();
  35178. } catch (e) {
  35179. warn('Failed to compile font ' + properties.loadedName);
  35180. // There may have just been an issue with the compiler, set the data
  35181. // anyway and hope the font loaded.
  35182. this.data = file;
  35183. }
  35184. }
  35185. CFFFont.prototype = {
  35186. get numGlyphs() {
  35187. return this.cff.charStrings.count;
  35188. },
  35189. getCharset: function CFFFont_getCharset() {
  35190. return this.cff.charset.charset;
  35191. },
  35192. getGlyphMapping: function CFFFont_getGlyphMapping() {
  35193. var cff = this.cff;
  35194. var properties = this.properties;
  35195. var charsets = cff.charset.charset;
  35196. var charCodeToGlyphId;
  35197. var glyphId;
  35198. if (properties.composite) {
  35199. charCodeToGlyphId = Object.create(null);
  35200. if (cff.isCIDFont) {
  35201. // If the font is actually a CID font then we should use the charset
  35202. // to map CIDs to GIDs.
  35203. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  35204. var cid = charsets[glyphId];
  35205. var charCode = properties.cMap.charCodeOf(cid);
  35206. charCodeToGlyphId[charCode] = glyphId;
  35207. }
  35208. } else {
  35209. // If it is NOT actually a CID font then CIDs should be mapped
  35210. // directly to GIDs.
  35211. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  35212. charCodeToGlyphId[glyphId] = glyphId;
  35213. }
  35214. }
  35215. return charCodeToGlyphId;
  35216. }
  35217. var encoding = cff.encoding ? cff.encoding.encoding : null;
  35218. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  35219. return charCodeToGlyphId;
  35220. }
  35221. };
  35222. return CFFFont;
  35223. })();
  35224. var CFFParser = (function CFFParserClosure() {
  35225. var CharstringValidationData = [
  35226. null,
  35227. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  35228. null,
  35229. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  35230. { id: 'vmoveto', min: 1, stackClearing: true },
  35231. { id: 'rlineto', min: 2, resetStack: true },
  35232. { id: 'hlineto', min: 1, resetStack: true },
  35233. { id: 'vlineto', min: 1, resetStack: true },
  35234. { id: 'rrcurveto', min: 6, resetStack: true },
  35235. null,
  35236. { id: 'callsubr', min: 1, undefStack: true },
  35237. { id: 'return', min: 0, undefStack: true },
  35238. null, // 12
  35239. null,
  35240. { id: 'endchar', min: 0, stackClearing: true },
  35241. null,
  35242. null,
  35243. null,
  35244. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  35245. { id: 'hintmask', min: 0, stackClearing: true },
  35246. { id: 'cntrmask', min: 0, stackClearing: true },
  35247. { id: 'rmoveto', min: 2, stackClearing: true },
  35248. { id: 'hmoveto', min: 1, stackClearing: true },
  35249. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  35250. { id: 'rcurveline', min: 8, resetStack: true },
  35251. { id: 'rlinecurve', min: 8, resetStack: true },
  35252. { id: 'vvcurveto', min: 4, resetStack: true },
  35253. { id: 'hhcurveto', min: 4, resetStack: true },
  35254. null, // shortint
  35255. { id: 'callgsubr', min: 1, undefStack: true },
  35256. { id: 'vhcurveto', min: 4, resetStack: true },
  35257. { id: 'hvcurveto', min: 4, resetStack: true }
  35258. ];
  35259. var CharstringValidationData12 = [
  35260. null,
  35261. null,
  35262. null,
  35263. { id: 'and', min: 2, stackDelta: -1 },
  35264. { id: 'or', min: 2, stackDelta: -1 },
  35265. { id: 'not', min: 1, stackDelta: 0 },
  35266. null,
  35267. null,
  35268. null,
  35269. { id: 'abs', min: 1, stackDelta: 0 },
  35270. { id: 'add', min: 2, stackDelta: -1,
  35271. stackFn: function stack_div(stack, index) {
  35272. stack[index - 2] = stack[index - 2] + stack[index - 1];
  35273. }
  35274. },
  35275. { id: 'sub', min: 2, stackDelta: -1,
  35276. stackFn: function stack_div(stack, index) {
  35277. stack[index - 2] = stack[index - 2] - stack[index - 1];
  35278. }
  35279. },
  35280. { id: 'div', min: 2, stackDelta: -1,
  35281. stackFn: function stack_div(stack, index) {
  35282. stack[index - 2] = stack[index - 2] / stack[index - 1];
  35283. }
  35284. },
  35285. null,
  35286. { id: 'neg', min: 1, stackDelta: 0,
  35287. stackFn: function stack_div(stack, index) {
  35288. stack[index - 1] = -stack[index - 1];
  35289. }
  35290. },
  35291. { id: 'eq', min: 2, stackDelta: -1 },
  35292. null,
  35293. null,
  35294. { id: 'drop', min: 1, stackDelta: -1 },
  35295. null,
  35296. { id: 'put', min: 2, stackDelta: -2 },
  35297. { id: 'get', min: 1, stackDelta: 0 },
  35298. { id: 'ifelse', min: 4, stackDelta: -3 },
  35299. { id: 'random', min: 0, stackDelta: 1 },
  35300. { id: 'mul', min: 2, stackDelta: -1,
  35301. stackFn: function stack_div(stack, index) {
  35302. stack[index - 2] = stack[index - 2] * stack[index - 1];
  35303. }
  35304. },
  35305. null,
  35306. { id: 'sqrt', min: 1, stackDelta: 0 },
  35307. { id: 'dup', min: 1, stackDelta: 1 },
  35308. { id: 'exch', min: 2, stackDelta: 0 },
  35309. { id: 'index', min: 2, stackDelta: 0 },
  35310. { id: 'roll', min: 3, stackDelta: -2 },
  35311. null,
  35312. null,
  35313. null,
  35314. { id: 'hflex', min: 7, resetStack: true },
  35315. { id: 'flex', min: 13, resetStack: true },
  35316. { id: 'hflex1', min: 9, resetStack: true },
  35317. { id: 'flex1', min: 11, resetStack: true }
  35318. ];
  35319. function CFFParser(file, properties) {
  35320. this.bytes = file.getBytes();
  35321. this.properties = properties;
  35322. }
  35323. CFFParser.prototype = {
  35324. parse: function CFFParser_parse() {
  35325. var properties = this.properties;
  35326. var cff = new CFF();
  35327. this.cff = cff;
  35328. // The first five sections must be in order, all the others are reached
  35329. // via offsets contained in one of the below.
  35330. var header = this.parseHeader();
  35331. var nameIndex = this.parseIndex(header.endPos);
  35332. var topDictIndex = this.parseIndex(nameIndex.endPos);
  35333. var stringIndex = this.parseIndex(topDictIndex.endPos);
  35334. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  35335. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  35336. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  35337. cff.header = header.obj;
  35338. cff.names = this.parseNameIndex(nameIndex.obj);
  35339. cff.strings = this.parseStringIndex(stringIndex.obj);
  35340. cff.topDict = topDict;
  35341. cff.globalSubrIndex = globalSubrIndex.obj;
  35342. this.parsePrivateDict(cff.topDict);
  35343. cff.isCIDFont = topDict.hasName('ROS');
  35344. var charStringOffset = topDict.getByName('CharStrings');
  35345. var charStringIndex = this.parseIndex(charStringOffset).obj;
  35346. var fontMatrix = topDict.getByName('FontMatrix');
  35347. if (fontMatrix) {
  35348. properties.fontMatrix = fontMatrix;
  35349. }
  35350. var fontBBox = topDict.getByName('FontBBox');
  35351. if (fontBBox) {
  35352. // adjusting ascent/descent
  35353. properties.ascent = fontBBox[3];
  35354. properties.descent = fontBBox[1];
  35355. properties.ascentScaled = true;
  35356. }
  35357. var charset, encoding;
  35358. if (cff.isCIDFont) {
  35359. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  35360. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  35361. var dictRaw = fdArrayIndex.get(i);
  35362. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  35363. cff.strings);
  35364. this.parsePrivateDict(fontDict);
  35365. cff.fdArray.push(fontDict);
  35366. }
  35367. // cid fonts don't have an encoding
  35368. encoding = null;
  35369. charset = this.parseCharsets(topDict.getByName('charset'),
  35370. charStringIndex.count, cff.strings, true);
  35371. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  35372. charStringIndex.count);
  35373. } else {
  35374. charset = this.parseCharsets(topDict.getByName('charset'),
  35375. charStringIndex.count, cff.strings, false);
  35376. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  35377. properties,
  35378. cff.strings, charset.charset);
  35379. }
  35380. cff.charset = charset;
  35381. cff.encoding = encoding;
  35382. var charStringsAndSeacs = this.parseCharStrings(
  35383. charStringIndex,
  35384. topDict.privateDict.subrsIndex,
  35385. globalSubrIndex.obj,
  35386. cff.fdSelect,
  35387. cff.fdArray);
  35388. cff.charStrings = charStringsAndSeacs.charStrings;
  35389. cff.seacs = charStringsAndSeacs.seacs;
  35390. cff.widths = charStringsAndSeacs.widths;
  35391. return cff;
  35392. },
  35393. parseHeader: function CFFParser_parseHeader() {
  35394. var bytes = this.bytes;
  35395. var bytesLength = bytes.length;
  35396. var offset = 0;
  35397. // Prevent an infinite loop, by checking that the offset is within the
  35398. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  35399. while (offset < bytesLength && bytes[offset] !== 1) {
  35400. ++offset;
  35401. }
  35402. if (offset >= bytesLength) {
  35403. error('Invalid CFF header');
  35404. } else if (offset !== 0) {
  35405. info('cff data is shifted');
  35406. bytes = bytes.subarray(offset);
  35407. this.bytes = bytes;
  35408. }
  35409. var major = bytes[0];
  35410. var minor = bytes[1];
  35411. var hdrSize = bytes[2];
  35412. var offSize = bytes[3];
  35413. var header = new CFFHeader(major, minor, hdrSize, offSize);
  35414. return { obj: header, endPos: hdrSize };
  35415. },
  35416. parseDict: function CFFParser_parseDict(dict) {
  35417. var pos = 0;
  35418. function parseOperand() {
  35419. var value = dict[pos++];
  35420. if (value === 30) {
  35421. return parseFloatOperand(pos);
  35422. } else if (value === 28) {
  35423. value = dict[pos++];
  35424. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  35425. return value;
  35426. } else if (value === 29) {
  35427. value = dict[pos++];
  35428. value = (value << 8) | dict[pos++];
  35429. value = (value << 8) | dict[pos++];
  35430. value = (value << 8) | dict[pos++];
  35431. return value;
  35432. } else if (value >= 32 && value <= 246) {
  35433. return value - 139;
  35434. } else if (value >= 247 && value <= 250) {
  35435. return ((value - 247) * 256) + dict[pos++] + 108;
  35436. } else if (value >= 251 && value <= 254) {
  35437. return -((value - 251) * 256) - dict[pos++] - 108;
  35438. } else {
  35439. error('255 is not a valid DICT command');
  35440. }
  35441. return -1;
  35442. }
  35443. function parseFloatOperand() {
  35444. var str = '';
  35445. var eof = 15;
  35446. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  35447. '9', '.', 'E', 'E-', null, '-'];
  35448. var length = dict.length;
  35449. while (pos < length) {
  35450. var b = dict[pos++];
  35451. var b1 = b >> 4;
  35452. var b2 = b & 15;
  35453. if (b1 === eof) {
  35454. break;
  35455. }
  35456. str += lookup[b1];
  35457. if (b2 === eof) {
  35458. break;
  35459. }
  35460. str += lookup[b2];
  35461. }
  35462. return parseFloat(str);
  35463. }
  35464. var operands = [];
  35465. var entries = [];
  35466. pos = 0;
  35467. var end = dict.length;
  35468. while (pos < end) {
  35469. var b = dict[pos];
  35470. if (b <= 21) {
  35471. if (b === 12) {
  35472. b = (b << 8) | dict[++pos];
  35473. }
  35474. entries.push([b, operands]);
  35475. operands = [];
  35476. ++pos;
  35477. } else {
  35478. operands.push(parseOperand());
  35479. }
  35480. }
  35481. return entries;
  35482. },
  35483. parseIndex: function CFFParser_parseIndex(pos) {
  35484. var cffIndex = new CFFIndex();
  35485. var bytes = this.bytes;
  35486. var count = (bytes[pos++] << 8) | bytes[pos++];
  35487. var offsets = [];
  35488. var end = pos;
  35489. var i, ii;
  35490. if (count !== 0) {
  35491. var offsetSize = bytes[pos++];
  35492. // add 1 for offset to determine size of last object
  35493. var startPos = pos + ((count + 1) * offsetSize) - 1;
  35494. for (i = 0, ii = count + 1; i < ii; ++i) {
  35495. var offset = 0;
  35496. for (var j = 0; j < offsetSize; ++j) {
  35497. offset <<= 8;
  35498. offset += bytes[pos++];
  35499. }
  35500. offsets.push(startPos + offset);
  35501. }
  35502. end = offsets[count];
  35503. }
  35504. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  35505. var offsetStart = offsets[i];
  35506. var offsetEnd = offsets[i + 1];
  35507. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  35508. }
  35509. return {obj: cffIndex, endPos: end};
  35510. },
  35511. parseNameIndex: function CFFParser_parseNameIndex(index) {
  35512. var names = [];
  35513. for (var i = 0, ii = index.count; i < ii; ++i) {
  35514. var name = index.get(i);
  35515. // OTS doesn't allow names to be over 127 characters.
  35516. var length = Math.min(name.length, 127);
  35517. var data = [];
  35518. // OTS also only permits certain characters in the name.
  35519. for (var j = 0; j < length; ++j) {
  35520. var c = name[j];
  35521. if (j === 0 && c === 0) {
  35522. data[j] = c;
  35523. continue;
  35524. }
  35525. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  35526. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  35527. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  35528. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  35529. data[j] = 95;
  35530. continue;
  35531. }
  35532. data[j] = c;
  35533. }
  35534. names.push(bytesToString(data));
  35535. }
  35536. return names;
  35537. },
  35538. parseStringIndex: function CFFParser_parseStringIndex(index) {
  35539. var strings = new CFFStrings();
  35540. for (var i = 0, ii = index.count; i < ii; ++i) {
  35541. var data = index.get(i);
  35542. strings.add(bytesToString(data));
  35543. }
  35544. return strings;
  35545. },
  35546. createDict: function CFFParser_createDict(Type, dict, strings) {
  35547. var cffDict = new Type(strings);
  35548. for (var i = 0, ii = dict.length; i < ii; ++i) {
  35549. var pair = dict[i];
  35550. var key = pair[0];
  35551. var value = pair[1];
  35552. cffDict.setByKey(key, value);
  35553. }
  35554. return cffDict;
  35555. },
  35556. parseCharString: function CFFParser_parseCharString(state, data,
  35557. localSubrIndex,
  35558. globalSubrIndex) {
  35559. if (state.callDepth > MAX_SUBR_NESTING) {
  35560. return false;
  35561. }
  35562. var stackSize = state.stackSize;
  35563. var stack = state.stack;
  35564. var length = data.length;
  35565. for (var j = 0; j < length;) {
  35566. var value = data[j++];
  35567. var validationCommand = null;
  35568. if (value === 12) {
  35569. var q = data[j++];
  35570. if (q === 0) {
  35571. // The CFF specification state that the 'dotsection' command
  35572. // (12, 0) is deprecated and treated as a no-op, but all Type2
  35573. // charstrings processors should support them. Unfortunately
  35574. // the font sanitizer don't. As a workaround the sequence (12, 0)
  35575. // is replaced by a useless (0, hmoveto).
  35576. data[j - 2] = 139;
  35577. data[j - 1] = 22;
  35578. stackSize = 0;
  35579. } else {
  35580. validationCommand = CharstringValidationData12[q];
  35581. }
  35582. } else if (value === 28) { // number (16 bit)
  35583. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  35584. j += 2;
  35585. stackSize++;
  35586. } else if (value === 14) {
  35587. if (stackSize >= 4) {
  35588. stackSize -= 4;
  35589. if (SEAC_ANALYSIS_ENABLED) {
  35590. state.seac = stack.slice(stackSize, stackSize + 4);
  35591. return false;
  35592. }
  35593. }
  35594. validationCommand = CharstringValidationData[value];
  35595. } else if (value >= 32 && value <= 246) { // number
  35596. stack[stackSize] = value - 139;
  35597. stackSize++;
  35598. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  35599. stack[stackSize] = (value < 251 ?
  35600. ((value - 247) << 8) + data[j] + 108 :
  35601. -((value - 251) << 8) - data[j] - 108);
  35602. j++;
  35603. stackSize++;
  35604. } else if (value === 255) { // number (32 bit)
  35605. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  35606. (data[j + 2] << 8) | data[j + 3]) / 65536;
  35607. j += 4;
  35608. stackSize++;
  35609. } else if (value === 19 || value === 20) {
  35610. state.hints += stackSize >> 1;
  35611. // skipping right amount of hints flag data
  35612. j += (state.hints + 7) >> 3;
  35613. stackSize %= 2;
  35614. validationCommand = CharstringValidationData[value];
  35615. } else if (value === 10 || value === 29) {
  35616. var subrsIndex;
  35617. if (value === 10) {
  35618. subrsIndex = localSubrIndex;
  35619. } else {
  35620. subrsIndex = globalSubrIndex;
  35621. }
  35622. if (!subrsIndex) {
  35623. validationCommand = CharstringValidationData[value];
  35624. warn('Missing subrsIndex for ' + validationCommand.id);
  35625. return false;
  35626. }
  35627. var bias = 32768;
  35628. if (subrsIndex.count < 1240) {
  35629. bias = 107;
  35630. } else if (subrsIndex.count < 33900) {
  35631. bias = 1131;
  35632. }
  35633. var subrNumber = stack[--stackSize] + bias;
  35634. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  35635. validationCommand = CharstringValidationData[value];
  35636. warn('Out of bounds subrIndex for ' + validationCommand.id);
  35637. return false;
  35638. }
  35639. state.stackSize = stackSize;
  35640. state.callDepth++;
  35641. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  35642. localSubrIndex, globalSubrIndex);
  35643. if (!valid) {
  35644. return false;
  35645. }
  35646. state.callDepth--;
  35647. stackSize = state.stackSize;
  35648. continue;
  35649. } else if (value === 11) {
  35650. state.stackSize = stackSize;
  35651. return true;
  35652. } else {
  35653. validationCommand = CharstringValidationData[value];
  35654. }
  35655. if (validationCommand) {
  35656. if (validationCommand.stem) {
  35657. state.hints += stackSize >> 1;
  35658. }
  35659. if ('min' in validationCommand) {
  35660. if (!state.undefStack && stackSize < validationCommand.min) {
  35661. warn('Not enough parameters for ' + validationCommand.id +
  35662. '; actual: ' + stackSize +
  35663. ', expected: ' + validationCommand.min);
  35664. return false;
  35665. }
  35666. }
  35667. if (state.firstStackClearing && validationCommand.stackClearing) {
  35668. state.firstStackClearing = false;
  35669. // the optional character width can be found before the first
  35670. // stack-clearing command arguments
  35671. stackSize -= validationCommand.min;
  35672. if (stackSize >= 2 && validationCommand.stem) {
  35673. // there are even amount of arguments for stem commands
  35674. stackSize %= 2;
  35675. } else if (stackSize > 1) {
  35676. warn('Found too many parameters for stack-clearing command');
  35677. }
  35678. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  35679. state.width = stack[stackSize - 1];
  35680. }
  35681. }
  35682. if ('stackDelta' in validationCommand) {
  35683. if ('stackFn' in validationCommand) {
  35684. validationCommand.stackFn(stack, stackSize);
  35685. }
  35686. stackSize += validationCommand.stackDelta;
  35687. } else if (validationCommand.stackClearing) {
  35688. stackSize = 0;
  35689. } else if (validationCommand.resetStack) {
  35690. stackSize = 0;
  35691. state.undefStack = false;
  35692. } else if (validationCommand.undefStack) {
  35693. stackSize = 0;
  35694. state.undefStack = true;
  35695. state.firstStackClearing = false;
  35696. }
  35697. }
  35698. }
  35699. state.stackSize = stackSize;
  35700. return true;
  35701. },
  35702. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  35703. localSubrIndex,
  35704. globalSubrIndex,
  35705. fdSelect,
  35706. fdArray) {
  35707. var seacs = [];
  35708. var widths = [];
  35709. var count = charStrings.count;
  35710. for (var i = 0; i < count; i++) {
  35711. var charstring = charStrings.get(i);
  35712. var state = {
  35713. callDepth: 0,
  35714. stackSize: 0,
  35715. stack: [],
  35716. undefStack: true,
  35717. hints: 0,
  35718. firstStackClearing: true,
  35719. seac: null,
  35720. width: null
  35721. };
  35722. var valid = true;
  35723. var localSubrToUse = null;
  35724. if (fdSelect && fdArray.length) {
  35725. var fdIndex = fdSelect.getFDIndex(i);
  35726. if (fdIndex === -1) {
  35727. warn('Glyph index is not in fd select.');
  35728. valid = false;
  35729. }
  35730. if (fdIndex >= fdArray.length) {
  35731. warn('Invalid fd index for glyph index.');
  35732. valid = false;
  35733. }
  35734. if (valid) {
  35735. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  35736. }
  35737. } else if (localSubrIndex) {
  35738. localSubrToUse = localSubrIndex;
  35739. }
  35740. if (valid) {
  35741. valid = this.parseCharString(state, charstring, localSubrToUse,
  35742. globalSubrIndex);
  35743. }
  35744. if (state.width !== null) {
  35745. widths[i] = state.width;
  35746. }
  35747. if (state.seac !== null) {
  35748. seacs[i] = state.seac;
  35749. }
  35750. if (!valid) {
  35751. // resetting invalid charstring to single 'endchar'
  35752. charStrings.set(i, new Uint8Array([14]));
  35753. }
  35754. }
  35755. return { charStrings: charStrings, seacs: seacs, widths: widths };
  35756. },
  35757. emptyPrivateDictionary:
  35758. function CFFParser_emptyPrivateDictionary(parentDict) {
  35759. var privateDict = this.createDict(CFFPrivateDict, [],
  35760. parentDict.strings);
  35761. parentDict.setByKey(18, [0, 0]);
  35762. parentDict.privateDict = privateDict;
  35763. },
  35764. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  35765. // no private dict, do nothing
  35766. if (!parentDict.hasName('Private')) {
  35767. this.emptyPrivateDictionary(parentDict);
  35768. return;
  35769. }
  35770. var privateOffset = parentDict.getByName('Private');
  35771. // make sure the params are formatted correctly
  35772. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  35773. parentDict.removeByName('Private');
  35774. return;
  35775. }
  35776. var size = privateOffset[0];
  35777. var offset = privateOffset[1];
  35778. // remove empty dicts or ones that refer to invalid location
  35779. if (size === 0 || offset >= this.bytes.length) {
  35780. this.emptyPrivateDictionary(parentDict);
  35781. return;
  35782. }
  35783. var privateDictEnd = offset + size;
  35784. var dictData = this.bytes.subarray(offset, privateDictEnd);
  35785. var dict = this.parseDict(dictData);
  35786. var privateDict = this.createDict(CFFPrivateDict, dict,
  35787. parentDict.strings);
  35788. parentDict.privateDict = privateDict;
  35789. // Parse the Subrs index also since it's relative to the private dict.
  35790. if (!privateDict.getByName('Subrs')) {
  35791. return;
  35792. }
  35793. var subrsOffset = privateDict.getByName('Subrs');
  35794. var relativeOffset = offset + subrsOffset;
  35795. // Validate the offset.
  35796. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  35797. this.emptyPrivateDictionary(parentDict);
  35798. return;
  35799. }
  35800. var subrsIndex = this.parseIndex(relativeOffset);
  35801. privateDict.subrsIndex = subrsIndex.obj;
  35802. },
  35803. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  35804. if (pos === 0) {
  35805. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  35806. ISOAdobeCharset);
  35807. } else if (pos === 1) {
  35808. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  35809. ExpertCharset);
  35810. } else if (pos === 2) {
  35811. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  35812. ExpertSubsetCharset);
  35813. }
  35814. var bytes = this.bytes;
  35815. var start = pos;
  35816. var format = bytes[pos++];
  35817. var charset = ['.notdef'];
  35818. var id, count, i;
  35819. // subtract 1 for the .notdef glyph
  35820. length -= 1;
  35821. switch (format) {
  35822. case 0:
  35823. for (i = 0; i < length; i++) {
  35824. id = (bytes[pos++] << 8) | bytes[pos++];
  35825. charset.push(cid ? id : strings.get(id));
  35826. }
  35827. break;
  35828. case 1:
  35829. while (charset.length <= length) {
  35830. id = (bytes[pos++] << 8) | bytes[pos++];
  35831. count = bytes[pos++];
  35832. for (i = 0; i <= count; i++) {
  35833. charset.push(cid ? id++ : strings.get(id++));
  35834. }
  35835. }
  35836. break;
  35837. case 2:
  35838. while (charset.length <= length) {
  35839. id = (bytes[pos++] << 8) | bytes[pos++];
  35840. count = (bytes[pos++] << 8) | bytes[pos++];
  35841. for (i = 0; i <= count; i++) {
  35842. charset.push(cid ? id++ : strings.get(id++));
  35843. }
  35844. }
  35845. break;
  35846. default:
  35847. error('Unknown charset format');
  35848. }
  35849. // Raw won't be needed if we actually compile the charset.
  35850. var end = pos;
  35851. var raw = bytes.subarray(start, end);
  35852. return new CFFCharset(false, format, charset, raw);
  35853. },
  35854. parseEncoding: function CFFParser_parseEncoding(pos,
  35855. properties,
  35856. strings,
  35857. charset) {
  35858. var encoding = Object.create(null);
  35859. var bytes = this.bytes;
  35860. var predefined = false;
  35861. var hasSupplement = false;
  35862. var format, i, ii;
  35863. var raw = null;
  35864. function readSupplement() {
  35865. var supplementsCount = bytes[pos++];
  35866. for (i = 0; i < supplementsCount; i++) {
  35867. var code = bytes[pos++];
  35868. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  35869. encoding[code] = charset.indexOf(strings.get(sid));
  35870. }
  35871. }
  35872. if (pos === 0 || pos === 1) {
  35873. predefined = true;
  35874. format = pos;
  35875. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  35876. for (i = 0, ii = charset.length; i < ii; i++) {
  35877. var index = baseEncoding.indexOf(charset[i]);
  35878. if (index !== -1) {
  35879. encoding[index] = i;
  35880. }
  35881. }
  35882. } else {
  35883. var dataStart = pos;
  35884. format = bytes[pos++];
  35885. switch (format & 0x7f) {
  35886. case 0:
  35887. var glyphsCount = bytes[pos++];
  35888. for (i = 1; i <= glyphsCount; i++) {
  35889. encoding[bytes[pos++]] = i;
  35890. }
  35891. break;
  35892. case 1:
  35893. var rangesCount = bytes[pos++];
  35894. var gid = 1;
  35895. for (i = 0; i < rangesCount; i++) {
  35896. var start = bytes[pos++];
  35897. var left = bytes[pos++];
  35898. for (var j = start; j <= start + left; j++) {
  35899. encoding[j] = gid++;
  35900. }
  35901. }
  35902. break;
  35903. default:
  35904. error('Unknow encoding format: ' + format + ' in CFF');
  35905. break;
  35906. }
  35907. var dataEnd = pos;
  35908. if (format & 0x80) {
  35909. // The font sanitizer does not support CFF encoding with a
  35910. // supplement, since the encoding is not really used to map
  35911. // between gid to glyph, let's overwrite what is declared in
  35912. // the top dictionary to let the sanitizer think the font use
  35913. // StandardEncoding, that's a lie but that's ok.
  35914. bytes[dataStart] &= 0x7f;
  35915. readSupplement();
  35916. hasSupplement = true;
  35917. }
  35918. raw = bytes.subarray(dataStart, dataEnd);
  35919. }
  35920. format = format & 0x7f;
  35921. return new CFFEncoding(predefined, format, encoding, raw);
  35922. },
  35923. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  35924. var start = pos;
  35925. var bytes = this.bytes;
  35926. var format = bytes[pos++];
  35927. var fdSelect = [];
  35928. var i;
  35929. switch (format) {
  35930. case 0:
  35931. for (i = 0; i < length; ++i) {
  35932. var id = bytes[pos++];
  35933. fdSelect.push(id);
  35934. }
  35935. break;
  35936. case 3:
  35937. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  35938. for (i = 0; i < rangesCount; ++i) {
  35939. var first = (bytes[pos++] << 8) | bytes[pos++];
  35940. var fdIndex = bytes[pos++];
  35941. var next = (bytes[pos] << 8) | bytes[pos + 1];
  35942. for (var j = first; j < next; ++j) {
  35943. fdSelect.push(fdIndex);
  35944. }
  35945. }
  35946. // Advance past the sentinel(next).
  35947. pos += 2;
  35948. break;
  35949. default:
  35950. error('Unknown fdselect format ' + format);
  35951. break;
  35952. }
  35953. var end = pos;
  35954. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  35955. }
  35956. };
  35957. return CFFParser;
  35958. })();
  35959. // Compact Font Format
  35960. var CFF = (function CFFClosure() {
  35961. function CFF() {
  35962. this.header = null;
  35963. this.names = [];
  35964. this.topDict = null;
  35965. this.strings = new CFFStrings();
  35966. this.globalSubrIndex = null;
  35967. // The following could really be per font, but since we only have one font
  35968. // store them here.
  35969. this.encoding = null;
  35970. this.charset = null;
  35971. this.charStrings = null;
  35972. this.fdArray = [];
  35973. this.fdSelect = null;
  35974. this.isCIDFont = false;
  35975. }
  35976. return CFF;
  35977. })();
  35978. var CFFHeader = (function CFFHeaderClosure() {
  35979. function CFFHeader(major, minor, hdrSize, offSize) {
  35980. this.major = major;
  35981. this.minor = minor;
  35982. this.hdrSize = hdrSize;
  35983. this.offSize = offSize;
  35984. }
  35985. return CFFHeader;
  35986. })();
  35987. var CFFStrings = (function CFFStringsClosure() {
  35988. function CFFStrings() {
  35989. this.strings = [];
  35990. }
  35991. CFFStrings.prototype = {
  35992. get: function CFFStrings_get(index) {
  35993. if (index >= 0 && index <= 390) {
  35994. return CFFStandardStrings[index];
  35995. }
  35996. if (index - 391 <= this.strings.length) {
  35997. return this.strings[index - 391];
  35998. }
  35999. return CFFStandardStrings[0];
  36000. },
  36001. add: function CFFStrings_add(value) {
  36002. this.strings.push(value);
  36003. },
  36004. get count() {
  36005. return this.strings.length;
  36006. }
  36007. };
  36008. return CFFStrings;
  36009. })();
  36010. var CFFIndex = (function CFFIndexClosure() {
  36011. function CFFIndex() {
  36012. this.objects = [];
  36013. this.length = 0;
  36014. }
  36015. CFFIndex.prototype = {
  36016. add: function CFFIndex_add(data) {
  36017. this.length += data.length;
  36018. this.objects.push(data);
  36019. },
  36020. set: function CFFIndex_set(index, data) {
  36021. this.length += data.length - this.objects[index].length;
  36022. this.objects[index] = data;
  36023. },
  36024. get: function CFFIndex_get(index) {
  36025. return this.objects[index];
  36026. },
  36027. get count() {
  36028. return this.objects.length;
  36029. }
  36030. };
  36031. return CFFIndex;
  36032. })();
  36033. var CFFDict = (function CFFDictClosure() {
  36034. function CFFDict(tables, strings) {
  36035. this.keyToNameMap = tables.keyToNameMap;
  36036. this.nameToKeyMap = tables.nameToKeyMap;
  36037. this.defaults = tables.defaults;
  36038. this.types = tables.types;
  36039. this.opcodes = tables.opcodes;
  36040. this.order = tables.order;
  36041. this.strings = strings;
  36042. this.values = Object.create(null);
  36043. }
  36044. CFFDict.prototype = {
  36045. // value should always be an array
  36046. setByKey: function CFFDict_setByKey(key, value) {
  36047. if (!(key in this.keyToNameMap)) {
  36048. return false;
  36049. }
  36050. // ignore empty values
  36051. if (value.length === 0) {
  36052. return true;
  36053. }
  36054. var type = this.types[key];
  36055. // remove the array wrapping these types of values
  36056. if (type === 'num' || type === 'sid' || type === 'offset') {
  36057. value = value[0];
  36058. }
  36059. this.values[key] = value;
  36060. return true;
  36061. },
  36062. setByName: function CFFDict_setByName(name, value) {
  36063. if (!(name in this.nameToKeyMap)) {
  36064. error('Invalid dictionary name "' + name + '"');
  36065. }
  36066. this.values[this.nameToKeyMap[name]] = value;
  36067. },
  36068. hasName: function CFFDict_hasName(name) {
  36069. return this.nameToKeyMap[name] in this.values;
  36070. },
  36071. getByName: function CFFDict_getByName(name) {
  36072. if (!(name in this.nameToKeyMap)) {
  36073. error('Invalid dictionary name "' + name + '"');
  36074. }
  36075. var key = this.nameToKeyMap[name];
  36076. if (!(key in this.values)) {
  36077. return this.defaults[key];
  36078. }
  36079. return this.values[key];
  36080. },
  36081. removeByName: function CFFDict_removeByName(name) {
  36082. delete this.values[this.nameToKeyMap[name]];
  36083. }
  36084. };
  36085. CFFDict.createTables = function CFFDict_createTables(layout) {
  36086. var tables = {
  36087. keyToNameMap: {},
  36088. nameToKeyMap: {},
  36089. defaults: {},
  36090. types: {},
  36091. opcodes: {},
  36092. order: []
  36093. };
  36094. for (var i = 0, ii = layout.length; i < ii; ++i) {
  36095. var entry = layout[i];
  36096. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  36097. tables.keyToNameMap[key] = entry[1];
  36098. tables.nameToKeyMap[entry[1]] = key;
  36099. tables.types[key] = entry[2];
  36100. tables.defaults[key] = entry[3];
  36101. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  36102. tables.order.push(key);
  36103. }
  36104. return tables;
  36105. };
  36106. return CFFDict;
  36107. })();
  36108. var CFFTopDict = (function CFFTopDictClosure() {
  36109. var layout = [
  36110. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  36111. [[12, 20], 'SyntheticBase', 'num', null],
  36112. [0, 'version', 'sid', null],
  36113. [1, 'Notice', 'sid', null],
  36114. [[12, 0], 'Copyright', 'sid', null],
  36115. [2, 'FullName', 'sid', null],
  36116. [3, 'FamilyName', 'sid', null],
  36117. [4, 'Weight', 'sid', null],
  36118. [[12, 1], 'isFixedPitch', 'num', 0],
  36119. [[12, 2], 'ItalicAngle', 'num', 0],
  36120. [[12, 3], 'UnderlinePosition', 'num', -100],
  36121. [[12, 4], 'UnderlineThickness', 'num', 50],
  36122. [[12, 5], 'PaintType', 'num', 0],
  36123. [[12, 6], 'CharstringType', 'num', 2],
  36124. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  36125. [0.001, 0, 0, 0.001, 0, 0]],
  36126. [13, 'UniqueID', 'num', null],
  36127. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  36128. [[12, 8], 'StrokeWidth', 'num', 0],
  36129. [14, 'XUID', 'array', null],
  36130. [15, 'charset', 'offset', 0],
  36131. [16, 'Encoding', 'offset', 0],
  36132. [17, 'CharStrings', 'offset', 0],
  36133. [18, 'Private', ['offset', 'offset'], null],
  36134. [[12, 21], 'PostScript', 'sid', null],
  36135. [[12, 22], 'BaseFontName', 'sid', null],
  36136. [[12, 23], 'BaseFontBlend', 'delta', null],
  36137. [[12, 31], 'CIDFontVersion', 'num', 0],
  36138. [[12, 32], 'CIDFontRevision', 'num', 0],
  36139. [[12, 33], 'CIDFontType', 'num', 0],
  36140. [[12, 34], 'CIDCount', 'num', 8720],
  36141. [[12, 35], 'UIDBase', 'num', null],
  36142. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  36143. // before FDArray.
  36144. [[12, 37], 'FDSelect', 'offset', null],
  36145. [[12, 36], 'FDArray', 'offset', null],
  36146. [[12, 38], 'FontName', 'sid', null]
  36147. ];
  36148. var tables = null;
  36149. function CFFTopDict(strings) {
  36150. if (tables === null) {
  36151. tables = CFFDict.createTables(layout);
  36152. }
  36153. CFFDict.call(this, tables, strings);
  36154. this.privateDict = null;
  36155. }
  36156. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  36157. return CFFTopDict;
  36158. })();
  36159. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  36160. var layout = [
  36161. [6, 'BlueValues', 'delta', null],
  36162. [7, 'OtherBlues', 'delta', null],
  36163. [8, 'FamilyBlues', 'delta', null],
  36164. [9, 'FamilyOtherBlues', 'delta', null],
  36165. [[12, 9], 'BlueScale', 'num', 0.039625],
  36166. [[12, 10], 'BlueShift', 'num', 7],
  36167. [[12, 11], 'BlueFuzz', 'num', 1],
  36168. [10, 'StdHW', 'num', null],
  36169. [11, 'StdVW', 'num', null],
  36170. [[12, 12], 'StemSnapH', 'delta', null],
  36171. [[12, 13], 'StemSnapV', 'delta', null],
  36172. [[12, 14], 'ForceBold', 'num', 0],
  36173. [[12, 17], 'LanguageGroup', 'num', 0],
  36174. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  36175. [[12, 19], 'initialRandomSeed', 'num', 0],
  36176. [20, 'defaultWidthX', 'num', 0],
  36177. [21, 'nominalWidthX', 'num', 0],
  36178. [19, 'Subrs', 'offset', null]
  36179. ];
  36180. var tables = null;
  36181. function CFFPrivateDict(strings) {
  36182. if (tables === null) {
  36183. tables = CFFDict.createTables(layout);
  36184. }
  36185. CFFDict.call(this, tables, strings);
  36186. this.subrsIndex = null;
  36187. }
  36188. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  36189. return CFFPrivateDict;
  36190. })();
  36191. var CFFCharsetPredefinedTypes = {
  36192. ISO_ADOBE: 0,
  36193. EXPERT: 1,
  36194. EXPERT_SUBSET: 2
  36195. };
  36196. var CFFCharset = (function CFFCharsetClosure() {
  36197. function CFFCharset(predefined, format, charset, raw) {
  36198. this.predefined = predefined;
  36199. this.format = format;
  36200. this.charset = charset;
  36201. this.raw = raw;
  36202. }
  36203. return CFFCharset;
  36204. })();
  36205. var CFFEncoding = (function CFFEncodingClosure() {
  36206. function CFFEncoding(predefined, format, encoding, raw) {
  36207. this.predefined = predefined;
  36208. this.format = format;
  36209. this.encoding = encoding;
  36210. this.raw = raw;
  36211. }
  36212. return CFFEncoding;
  36213. })();
  36214. var CFFFDSelect = (function CFFFDSelectClosure() {
  36215. function CFFFDSelect(fdSelect, raw) {
  36216. this.fdSelect = fdSelect;
  36217. this.raw = raw;
  36218. }
  36219. CFFFDSelect.prototype = {
  36220. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  36221. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  36222. return -1;
  36223. }
  36224. return this.fdSelect[glyphIndex];
  36225. }
  36226. };
  36227. return CFFFDSelect;
  36228. })();
  36229. // Helper class to keep track of where an offset is within the data and helps
  36230. // filling in that offset once it's known.
  36231. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  36232. function CFFOffsetTracker() {
  36233. this.offsets = Object.create(null);
  36234. }
  36235. CFFOffsetTracker.prototype = {
  36236. isTracking: function CFFOffsetTracker_isTracking(key) {
  36237. return key in this.offsets;
  36238. },
  36239. track: function CFFOffsetTracker_track(key, location) {
  36240. if (key in this.offsets) {
  36241. error('Already tracking location of ' + key);
  36242. }
  36243. this.offsets[key] = location;
  36244. },
  36245. offset: function CFFOffsetTracker_offset(value) {
  36246. for (var key in this.offsets) {
  36247. this.offsets[key] += value;
  36248. }
  36249. },
  36250. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  36251. values,
  36252. output) {
  36253. if (!(key in this.offsets)) {
  36254. error('Not tracking location of ' + key);
  36255. }
  36256. var data = output.data;
  36257. var dataOffset = this.offsets[key];
  36258. var size = 5;
  36259. for (var i = 0, ii = values.length; i < ii; ++i) {
  36260. var offset0 = i * size + dataOffset;
  36261. var offset1 = offset0 + 1;
  36262. var offset2 = offset0 + 2;
  36263. var offset3 = offset0 + 3;
  36264. var offset4 = offset0 + 4;
  36265. // It's easy to screw up offsets so perform this sanity check.
  36266. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  36267. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  36268. error('writing to an offset that is not empty');
  36269. }
  36270. var value = values[i];
  36271. data[offset0] = 0x1d;
  36272. data[offset1] = (value >> 24) & 0xFF;
  36273. data[offset2] = (value >> 16) & 0xFF;
  36274. data[offset3] = (value >> 8) & 0xFF;
  36275. data[offset4] = value & 0xFF;
  36276. }
  36277. }
  36278. };
  36279. return CFFOffsetTracker;
  36280. })();
  36281. // Takes a CFF and converts it to the binary representation.
  36282. var CFFCompiler = (function CFFCompilerClosure() {
  36283. function CFFCompiler(cff) {
  36284. this.cff = cff;
  36285. }
  36286. CFFCompiler.prototype = {
  36287. compile: function CFFCompiler_compile() {
  36288. var cff = this.cff;
  36289. var output = {
  36290. data: [],
  36291. length: 0,
  36292. add: function CFFCompiler_add(data) {
  36293. this.data = this.data.concat(data);
  36294. this.length = this.data.length;
  36295. }
  36296. };
  36297. // Compile the five entries that must be in order.
  36298. var header = this.compileHeader(cff.header);
  36299. output.add(header);
  36300. var nameIndex = this.compileNameIndex(cff.names);
  36301. output.add(nameIndex);
  36302. if (cff.isCIDFont) {
  36303. // The spec is unclear on how font matrices should relate to each other
  36304. // when there is one in the main top dict and the sub top dicts.
  36305. // Windows handles this differently than linux and osx so we have to
  36306. // normalize to work on all.
  36307. // Rules based off of some mailing list discussions:
  36308. // - If main font has a matrix and subfont doesn't, use the main matrix.
  36309. // - If no main font matrix and there is a subfont matrix, use the
  36310. // subfont matrix.
  36311. // - If both have matrices, concat together.
  36312. // - If neither have matrices, use default.
  36313. // To make this work on all platforms we move the top matrix into each
  36314. // sub top dict and concat if necessary.
  36315. if (cff.topDict.hasName('FontMatrix')) {
  36316. var base = cff.topDict.getByName('FontMatrix');
  36317. cff.topDict.removeByName('FontMatrix');
  36318. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  36319. var subDict = cff.fdArray[i];
  36320. var matrix = base.slice(0);
  36321. if (subDict.hasName('FontMatrix')) {
  36322. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  36323. }
  36324. subDict.setByName('FontMatrix', matrix);
  36325. }
  36326. }
  36327. }
  36328. var compiled = this.compileTopDicts([cff.topDict],
  36329. output.length,
  36330. cff.isCIDFont);
  36331. output.add(compiled.output);
  36332. var topDictTracker = compiled.trackers[0];
  36333. var stringIndex = this.compileStringIndex(cff.strings.strings);
  36334. output.add(stringIndex);
  36335. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  36336. output.add(globalSubrIndex);
  36337. // Now start on the other entries that have no specfic order.
  36338. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  36339. if (cff.encoding.predefined) {
  36340. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  36341. output);
  36342. } else {
  36343. var encoding = this.compileEncoding(cff.encoding);
  36344. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  36345. output.add(encoding);
  36346. }
  36347. }
  36348. if (cff.charset && cff.topDict.hasName('charset')) {
  36349. if (cff.charset.predefined) {
  36350. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  36351. output);
  36352. } else {
  36353. var charset = this.compileCharset(cff.charset);
  36354. topDictTracker.setEntryLocation('charset', [output.length], output);
  36355. output.add(charset);
  36356. }
  36357. }
  36358. var charStrings = this.compileCharStrings(cff.charStrings);
  36359. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  36360. output.add(charStrings);
  36361. if (cff.isCIDFont) {
  36362. // For some reason FDSelect must be in front of FDArray on windows. OSX
  36363. // and linux don't seem to care.
  36364. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  36365. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  36366. output.add(fdSelect);
  36367. // It is unclear if the sub font dictionary can have CID related
  36368. // dictionary keys, but the sanitizer doesn't like them so remove them.
  36369. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  36370. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  36371. output.add(compiled.output);
  36372. var fontDictTrackers = compiled.trackers;
  36373. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  36374. }
  36375. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  36376. // If the font data ends with INDEX whose object data is zero-length,
  36377. // the sanitizer will bail out. Add a dummy byte to avoid that.
  36378. output.add([0]);
  36379. return output.data;
  36380. },
  36381. encodeNumber: function CFFCompiler_encodeNumber(value) {
  36382. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  36383. return this.encodeInteger(value);
  36384. } else {
  36385. return this.encodeFloat(value);
  36386. }
  36387. },
  36388. encodeFloat: function CFFCompiler_encodeFloat(num) {
  36389. var value = num.toString();
  36390. // rounding inaccurate doubles
  36391. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36392. if (m) {
  36393. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36394. value = (Math.round(num * epsilon) / epsilon).toString();
  36395. }
  36396. var nibbles = '';
  36397. var i, ii;
  36398. for (i = 0, ii = value.length; i < ii; ++i) {
  36399. var a = value[i];
  36400. if (a === 'e') {
  36401. nibbles += value[++i] === '-' ? 'c' : 'b';
  36402. } else if (a === '.') {
  36403. nibbles += 'a';
  36404. } else if (a === '-') {
  36405. nibbles += 'e';
  36406. } else {
  36407. nibbles += a;
  36408. }
  36409. }
  36410. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  36411. var out = [30];
  36412. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  36413. out.push(parseInt(nibbles.substr(i, 2), 16));
  36414. }
  36415. return out;
  36416. },
  36417. encodeInteger: function CFFCompiler_encodeInteger(value) {
  36418. var code;
  36419. if (value >= -107 && value <= 107) {
  36420. code = [value + 139];
  36421. } else if (value >= 108 && value <= 1131) {
  36422. value = [value - 108];
  36423. code = [(value >> 8) + 247, value & 0xFF];
  36424. } else if (value >= -1131 && value <= -108) {
  36425. value = -value - 108;
  36426. code = [(value >> 8) + 251, value & 0xFF];
  36427. } else if (value >= -32768 && value <= 32767) {
  36428. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  36429. } else {
  36430. code = [0x1d,
  36431. (value >> 24) & 0xFF,
  36432. (value >> 16) & 0xFF,
  36433. (value >> 8) & 0xFF,
  36434. value & 0xFF];
  36435. }
  36436. return code;
  36437. },
  36438. compileHeader: function CFFCompiler_compileHeader(header) {
  36439. return [
  36440. header.major,
  36441. header.minor,
  36442. header.hdrSize,
  36443. header.offSize
  36444. ];
  36445. },
  36446. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  36447. var nameIndex = new CFFIndex();
  36448. for (var i = 0, ii = names.length; i < ii; ++i) {
  36449. nameIndex.add(stringToBytes(names[i]));
  36450. }
  36451. return this.compileIndex(nameIndex);
  36452. },
  36453. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  36454. length,
  36455. removeCidKeys) {
  36456. var fontDictTrackers = [];
  36457. var fdArrayIndex = new CFFIndex();
  36458. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36459. var fontDict = dicts[i];
  36460. if (removeCidKeys) {
  36461. fontDict.removeByName('CIDFontVersion');
  36462. fontDict.removeByName('CIDFontRevision');
  36463. fontDict.removeByName('CIDFontType');
  36464. fontDict.removeByName('CIDCount');
  36465. fontDict.removeByName('UIDBase');
  36466. }
  36467. var fontDictTracker = new CFFOffsetTracker();
  36468. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  36469. fontDictTrackers.push(fontDictTracker);
  36470. fdArrayIndex.add(fontDictData);
  36471. fontDictTracker.offset(length);
  36472. }
  36473. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  36474. return {
  36475. trackers: fontDictTrackers,
  36476. output: fdArrayIndex
  36477. };
  36478. },
  36479. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  36480. trackers,
  36481. output) {
  36482. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36483. var fontDict = dicts[i];
  36484. assert(fontDict.privateDict && fontDict.hasName('Private'),
  36485. 'There must be an private dictionary.');
  36486. var privateDict = fontDict.privateDict;
  36487. var privateDictTracker = new CFFOffsetTracker();
  36488. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  36489. var outputLength = output.length;
  36490. privateDictTracker.offset(outputLength);
  36491. if (!privateDictData.length) {
  36492. // The private dictionary was empty, set the output length to zero to
  36493. // ensure the offset length isn't out of bounds in the eyes of the
  36494. // sanitizer.
  36495. outputLength = 0;
  36496. }
  36497. trackers[i].setEntryLocation('Private',
  36498. [privateDictData.length, outputLength],
  36499. output);
  36500. output.add(privateDictData);
  36501. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  36502. var subrs = this.compileIndex(privateDict.subrsIndex);
  36503. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  36504. output);
  36505. output.add(subrs);
  36506. }
  36507. }
  36508. },
  36509. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  36510. var out = [];
  36511. // The dictionary keys must be in a certain order.
  36512. var order = dict.order;
  36513. for (var i = 0; i < order.length; ++i) {
  36514. var key = order[i];
  36515. if (!(key in dict.values)) {
  36516. continue;
  36517. }
  36518. var values = dict.values[key];
  36519. var types = dict.types[key];
  36520. if (!isArray(types)) {
  36521. types = [types];
  36522. }
  36523. if (!isArray(values)) {
  36524. values = [values];
  36525. }
  36526. // Remove any empty dict values.
  36527. if (values.length === 0) {
  36528. continue;
  36529. }
  36530. for (var j = 0, jj = types.length; j < jj; ++j) {
  36531. var type = types[j];
  36532. var value = values[j];
  36533. switch (type) {
  36534. case 'num':
  36535. case 'sid':
  36536. out = out.concat(this.encodeNumber(value));
  36537. break;
  36538. case 'offset':
  36539. // For offsets we just insert a 32bit integer so we don't have to
  36540. // deal with figuring out the length of the offset when it gets
  36541. // replaced later on by the compiler.
  36542. var name = dict.keyToNameMap[key];
  36543. // Some offsets have the offset and the length, so just record the
  36544. // position of the first one.
  36545. if (!offsetTracker.isTracking(name)) {
  36546. offsetTracker.track(name, out.length);
  36547. }
  36548. out = out.concat([0x1d, 0, 0, 0, 0]);
  36549. break;
  36550. case 'array':
  36551. case 'delta':
  36552. out = out.concat(this.encodeNumber(value));
  36553. for (var k = 1, kk = values.length; k < kk; ++k) {
  36554. out = out.concat(this.encodeNumber(values[k]));
  36555. }
  36556. break;
  36557. default:
  36558. error('Unknown data type of ' + type);
  36559. break;
  36560. }
  36561. }
  36562. out = out.concat(dict.opcodes[key]);
  36563. }
  36564. return out;
  36565. },
  36566. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  36567. var stringIndex = new CFFIndex();
  36568. for (var i = 0, ii = strings.length; i < ii; ++i) {
  36569. stringIndex.add(stringToBytes(strings[i]));
  36570. }
  36571. return this.compileIndex(stringIndex);
  36572. },
  36573. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  36574. var globalSubrIndex = this.cff.globalSubrIndex;
  36575. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  36576. },
  36577. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  36578. return this.compileIndex(charStrings);
  36579. },
  36580. compileCharset: function CFFCompiler_compileCharset(charset) {
  36581. return this.compileTypedArray(charset.raw);
  36582. },
  36583. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  36584. return this.compileTypedArray(encoding.raw);
  36585. },
  36586. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  36587. return this.compileTypedArray(fdSelect);
  36588. },
  36589. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  36590. var out = [];
  36591. for (var i = 0, ii = data.length; i < ii; ++i) {
  36592. out[i] = data[i];
  36593. }
  36594. return out;
  36595. },
  36596. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  36597. trackers = trackers || [];
  36598. var objects = index.objects;
  36599. // First 2 bytes contains the number of objects contained into this index
  36600. var count = objects.length;
  36601. // If there is no object, just create an index. This technically
  36602. // should just be [0, 0] but OTS has an issue with that.
  36603. if (count === 0) {
  36604. return [0, 0, 0];
  36605. }
  36606. var data = [(count >> 8) & 0xFF, count & 0xff];
  36607. var lastOffset = 1, i;
  36608. for (i = 0; i < count; ++i) {
  36609. lastOffset += objects[i].length;
  36610. }
  36611. var offsetSize;
  36612. if (lastOffset < 0x100) {
  36613. offsetSize = 1;
  36614. } else if (lastOffset < 0x10000) {
  36615. offsetSize = 2;
  36616. } else if (lastOffset < 0x1000000) {
  36617. offsetSize = 3;
  36618. } else {
  36619. offsetSize = 4;
  36620. }
  36621. // Next byte contains the offset size use to reference object in the file
  36622. data.push(offsetSize);
  36623. // Add another offset after this one because we need a new offset
  36624. var relativeOffset = 1;
  36625. for (i = 0; i < count + 1; i++) {
  36626. if (offsetSize === 1) {
  36627. data.push(relativeOffset & 0xFF);
  36628. } else if (offsetSize === 2) {
  36629. data.push((relativeOffset >> 8) & 0xFF,
  36630. relativeOffset & 0xFF);
  36631. } else if (offsetSize === 3) {
  36632. data.push((relativeOffset >> 16) & 0xFF,
  36633. (relativeOffset >> 8) & 0xFF,
  36634. relativeOffset & 0xFF);
  36635. } else {
  36636. data.push((relativeOffset >>> 24) & 0xFF,
  36637. (relativeOffset >> 16) & 0xFF,
  36638. (relativeOffset >> 8) & 0xFF,
  36639. relativeOffset & 0xFF);
  36640. }
  36641. if (objects[i]) {
  36642. relativeOffset += objects[i].length;
  36643. }
  36644. }
  36645. for (i = 0; i < count; i++) {
  36646. // Notify the tracker where the object will be offset in the data.
  36647. if (trackers[i]) {
  36648. trackers[i].offset(data.length);
  36649. }
  36650. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  36651. data.push(objects[i][j]);
  36652. }
  36653. }
  36654. return data;
  36655. }
  36656. };
  36657. return CFFCompiler;
  36658. })();
  36659. function _enableSeacAnalysis(enabled) {
  36660. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  36661. }
  36662. // Workaround for seac on Windows.
  36663. (function checkSeacSupport() {
  36664. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  36665. SEAC_ANALYSIS_ENABLED = true;
  36666. }
  36667. })();
  36668. // Workaround for Private Use Area characters in Chrome on Windows
  36669. // http://code.google.com/p/chromium/issues/detail?id=122465
  36670. // https://github.com/mozilla/pdf.js/issues/1689
  36671. (function checkChromeWindows() {
  36672. if (typeof navigator !== 'undefined' &&
  36673. /Windows.*Chrome/.test(navigator.userAgent)) {
  36674. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  36675. }
  36676. })();
  36677. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  36678. exports.CFFCompiler = CFFCompiler;
  36679. exports.CFFIndex = CFFIndex;
  36680. exports.CFFParser = CFFParser;
  36681. exports.CFFStrings = CFFStrings;
  36682. exports.ErrorFont = ErrorFont;
  36683. exports.FontFlags = FontFlags;
  36684. exports.Font = Font;
  36685. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  36686. exports.ToUnicodeMap = ToUnicodeMap;
  36687. exports.Type1Parser = Type1Parser;
  36688. exports.getFontType = getFontType;
  36689. exports._enableSeacAnalysis = _enableSeacAnalysis;
  36690. // TODO refactor to remove cyclic dependency on font_renderer.js
  36691. coreFontRenderer._setCoreFonts(exports);
  36692. }));
  36693. (function (root, factory) {
  36694. {
  36695. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  36696. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  36697. }
  36698. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  36699. var error = sharedUtil.error;
  36700. var info = sharedUtil.info;
  36701. var isArray = sharedUtil.isArray;
  36702. var isBool = sharedUtil.isBool;
  36703. var isDict = corePrimitives.isDict;
  36704. var isStream = corePrimitives.isStream;
  36705. var PostScriptLexer = corePsParser.PostScriptLexer;
  36706. var PostScriptParser = corePsParser.PostScriptParser;
  36707. var PDFFunction = (function PDFFunctionClosure() {
  36708. var CONSTRUCT_SAMPLED = 0;
  36709. var CONSTRUCT_INTERPOLATED = 2;
  36710. var CONSTRUCT_STICHED = 3;
  36711. var CONSTRUCT_POSTSCRIPT = 4;
  36712. return {
  36713. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  36714. str) {
  36715. var i, ii;
  36716. var length = 1;
  36717. for (i = 0, ii = size.length; i < ii; i++) {
  36718. length *= size[i];
  36719. }
  36720. length *= outputSize;
  36721. var array = new Array(length);
  36722. var codeSize = 0;
  36723. var codeBuf = 0;
  36724. // 32 is a valid bps so shifting won't work
  36725. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  36726. var strBytes = str.getBytes((length * bps + 7) / 8);
  36727. var strIdx = 0;
  36728. for (i = 0; i < length; i++) {
  36729. while (codeSize < bps) {
  36730. codeBuf <<= 8;
  36731. codeBuf |= strBytes[strIdx++];
  36732. codeSize += 8;
  36733. }
  36734. codeSize -= bps;
  36735. array[i] = (codeBuf >> codeSize) * sampleMul;
  36736. codeBuf &= (1 << codeSize) - 1;
  36737. }
  36738. return array;
  36739. },
  36740. getIR: function PDFFunction_getIR(xref, fn) {
  36741. var dict = fn.dict;
  36742. if (!dict) {
  36743. dict = fn;
  36744. }
  36745. var types = [this.constructSampled,
  36746. null,
  36747. this.constructInterpolated,
  36748. this.constructStiched,
  36749. this.constructPostScript];
  36750. var typeNum = dict.get('FunctionType');
  36751. var typeFn = types[typeNum];
  36752. if (!typeFn) {
  36753. error('Unknown type of function');
  36754. }
  36755. return typeFn.call(this, fn, dict, xref);
  36756. },
  36757. fromIR: function PDFFunction_fromIR(IR) {
  36758. var type = IR[0];
  36759. switch (type) {
  36760. case CONSTRUCT_SAMPLED:
  36761. return this.constructSampledFromIR(IR);
  36762. case CONSTRUCT_INTERPOLATED:
  36763. return this.constructInterpolatedFromIR(IR);
  36764. case CONSTRUCT_STICHED:
  36765. return this.constructStichedFromIR(IR);
  36766. //case CONSTRUCT_POSTSCRIPT:
  36767. default:
  36768. return this.constructPostScriptFromIR(IR);
  36769. }
  36770. },
  36771. parse: function PDFFunction_parse(xref, fn) {
  36772. var IR = this.getIR(xref, fn);
  36773. return this.fromIR(IR);
  36774. },
  36775. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  36776. if (!isArray(fnObj)) {
  36777. // not an array -- parsing as regular function
  36778. return this.parse(xref, fnObj);
  36779. }
  36780. var fnArray = [];
  36781. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  36782. var obj = xref.fetchIfRef(fnObj[j]);
  36783. fnArray.push(PDFFunction.parse(xref, obj));
  36784. }
  36785. return function (src, srcOffset, dest, destOffset) {
  36786. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  36787. fnArray[i](src, srcOffset, dest, destOffset + i);
  36788. }
  36789. };
  36790. },
  36791. constructSampled: function PDFFunction_constructSampled(str, dict) {
  36792. function toMultiArray(arr) {
  36793. var inputLength = arr.length;
  36794. var out = [];
  36795. var index = 0;
  36796. for (var i = 0; i < inputLength; i += 2) {
  36797. out[index] = [arr[i], arr[i + 1]];
  36798. ++index;
  36799. }
  36800. return out;
  36801. }
  36802. var domain = dict.get('Domain');
  36803. var range = dict.get('Range');
  36804. if (!domain || !range) {
  36805. error('No domain or range');
  36806. }
  36807. var inputSize = domain.length / 2;
  36808. var outputSize = range.length / 2;
  36809. domain = toMultiArray(domain);
  36810. range = toMultiArray(range);
  36811. var size = dict.get('Size');
  36812. var bps = dict.get('BitsPerSample');
  36813. var order = dict.get('Order') || 1;
  36814. if (order !== 1) {
  36815. // No description how cubic spline interpolation works in PDF32000:2008
  36816. // As in poppler, ignoring order, linear interpolation may work as good
  36817. info('No support for cubic spline interpolation: ' + order);
  36818. }
  36819. var encode = dict.get('Encode');
  36820. if (!encode) {
  36821. encode = [];
  36822. for (var i = 0; i < inputSize; ++i) {
  36823. encode.push(0);
  36824. encode.push(size[i] - 1);
  36825. }
  36826. }
  36827. encode = toMultiArray(encode);
  36828. var decode = dict.get('Decode');
  36829. if (!decode) {
  36830. decode = range;
  36831. } else {
  36832. decode = toMultiArray(decode);
  36833. }
  36834. var samples = this.getSampleArray(size, outputSize, bps, str);
  36835. return [
  36836. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  36837. outputSize, Math.pow(2, bps) - 1, range
  36838. ];
  36839. },
  36840. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  36841. // See chapter 3, page 109 of the PDF reference
  36842. function interpolate(x, xmin, xmax, ymin, ymax) {
  36843. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  36844. }
  36845. return function constructSampledFromIRResult(src, srcOffset,
  36846. dest, destOffset) {
  36847. // See chapter 3, page 110 of the PDF reference.
  36848. var m = IR[1];
  36849. var domain = IR[2];
  36850. var encode = IR[3];
  36851. var decode = IR[4];
  36852. var samples = IR[5];
  36853. var size = IR[6];
  36854. var n = IR[7];
  36855. //var mask = IR[8];
  36856. var range = IR[9];
  36857. // Building the cube vertices: its part and sample index
  36858. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  36859. var cubeVertices = 1 << m;
  36860. var cubeN = new Float64Array(cubeVertices);
  36861. var cubeVertex = new Uint32Array(cubeVertices);
  36862. var i, j;
  36863. for (j = 0; j < cubeVertices; j++) {
  36864. cubeN[j] = 1;
  36865. }
  36866. var k = n, pos = 1;
  36867. // Map x_i to y_j for 0 <= i < m using the sampled function.
  36868. for (i = 0; i < m; ++i) {
  36869. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  36870. var domain_2i = domain[i][0];
  36871. var domain_2i_1 = domain[i][1];
  36872. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  36873. domain_2i_1);
  36874. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  36875. // Encode_2i, Encode_2i+1)
  36876. var e = interpolate(xi, domain_2i, domain_2i_1,
  36877. encode[i][0], encode[i][1]);
  36878. // e_i' = min(max(e_i, 0), Size_i - 1)
  36879. var size_i = size[i];
  36880. e = Math.min(Math.max(e, 0), size_i - 1);
  36881. // Adjusting the cube: N and vertex sample index
  36882. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  36883. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  36884. var n1 = e - e0; // (e - e0) / (e1 - e0);
  36885. var offset0 = e0 * k;
  36886. var offset1 = offset0 + k; // e1 * k
  36887. for (j = 0; j < cubeVertices; j++) {
  36888. if (j & pos) {
  36889. cubeN[j] *= n1;
  36890. cubeVertex[j] += offset1;
  36891. } else {
  36892. cubeN[j] *= n0;
  36893. cubeVertex[j] += offset0;
  36894. }
  36895. }
  36896. k *= size_i;
  36897. pos <<= 1;
  36898. }
  36899. for (j = 0; j < n; ++j) {
  36900. // Sum all cube vertices' samples portions
  36901. var rj = 0;
  36902. for (i = 0; i < cubeVertices; i++) {
  36903. rj += samples[cubeVertex[i] + j] * cubeN[i];
  36904. }
  36905. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  36906. // Decode_2j, Decode_2j+1)
  36907. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  36908. // y_j = min(max(r_j, range_2j), range_2j+1)
  36909. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  36910. range[j][1]);
  36911. }
  36912. };
  36913. },
  36914. constructInterpolated: function PDFFunction_constructInterpolated(str,
  36915. dict) {
  36916. var c0 = dict.get('C0') || [0];
  36917. var c1 = dict.get('C1') || [1];
  36918. var n = dict.get('N');
  36919. if (!isArray(c0) || !isArray(c1)) {
  36920. error('Illegal dictionary for interpolated function');
  36921. }
  36922. var length = c0.length;
  36923. var diff = [];
  36924. for (var i = 0; i < length; ++i) {
  36925. diff.push(c1[i] - c0[i]);
  36926. }
  36927. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  36928. },
  36929. constructInterpolatedFromIR:
  36930. function PDFFunction_constructInterpolatedFromIR(IR) {
  36931. var c0 = IR[1];
  36932. var diff = IR[2];
  36933. var n = IR[3];
  36934. var length = diff.length;
  36935. return function constructInterpolatedFromIRResult(src, srcOffset,
  36936. dest, destOffset) {
  36937. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  36938. for (var j = 0; j < length; ++j) {
  36939. dest[destOffset + j] = c0[j] + (x * diff[j]);
  36940. }
  36941. };
  36942. },
  36943. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  36944. var domain = dict.get('Domain');
  36945. if (!domain) {
  36946. error('No domain');
  36947. }
  36948. var inputSize = domain.length / 2;
  36949. if (inputSize !== 1) {
  36950. error('Bad domain for stiched function');
  36951. }
  36952. var fnRefs = dict.get('Functions');
  36953. var fns = [];
  36954. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  36955. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  36956. }
  36957. var bounds = dict.get('Bounds');
  36958. var encode = dict.get('Encode');
  36959. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  36960. },
  36961. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  36962. var domain = IR[1];
  36963. var bounds = IR[2];
  36964. var encode = IR[3];
  36965. var fnsIR = IR[4];
  36966. var fns = [];
  36967. var tmpBuf = new Float32Array(1);
  36968. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  36969. fns.push(PDFFunction.fromIR(fnsIR[i]));
  36970. }
  36971. return function constructStichedFromIRResult(src, srcOffset,
  36972. dest, destOffset) {
  36973. var clip = function constructStichedFromIRClip(v, min, max) {
  36974. if (v > max) {
  36975. v = max;
  36976. } else if (v < min) {
  36977. v = min;
  36978. }
  36979. return v;
  36980. };
  36981. // clip to domain
  36982. var v = clip(src[srcOffset], domain[0], domain[1]);
  36983. // calulate which bound the value is in
  36984. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  36985. if (v < bounds[i]) {
  36986. break;
  36987. }
  36988. }
  36989. // encode value into domain of function
  36990. var dmin = domain[0];
  36991. if (i > 0) {
  36992. dmin = bounds[i - 1];
  36993. }
  36994. var dmax = domain[1];
  36995. if (i < bounds.length) {
  36996. dmax = bounds[i];
  36997. }
  36998. var rmin = encode[2 * i];
  36999. var rmax = encode[2 * i + 1];
  37000. // Prevent the value from becoming NaN as a result
  37001. // of division by zero (fixes issue6113.pdf).
  37002. tmpBuf[0] = dmin === dmax ? rmin :
  37003. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  37004. // call the appropriate function
  37005. fns[i](tmpBuf, 0, dest, destOffset);
  37006. };
  37007. },
  37008. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  37009. xref) {
  37010. var domain = dict.get('Domain');
  37011. var range = dict.get('Range');
  37012. if (!domain) {
  37013. error('No domain.');
  37014. }
  37015. if (!range) {
  37016. error('No range.');
  37017. }
  37018. var lexer = new PostScriptLexer(fn);
  37019. var parser = new PostScriptParser(lexer);
  37020. var code = parser.parse();
  37021. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  37022. },
  37023. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  37024. IR) {
  37025. var domain = IR[1];
  37026. var range = IR[2];
  37027. var code = IR[3];
  37028. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  37029. if (compiled) {
  37030. // Compiled function consists of simple expressions such as addition,
  37031. // subtraction, Math.max, and also contains 'var' and 'return'
  37032. // statements. See the generation in the PostScriptCompiler below.
  37033. /*jshint -W054 */
  37034. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  37035. }
  37036. info('Unable to compile PS function');
  37037. var numOutputs = range.length >> 1;
  37038. var numInputs = domain.length >> 1;
  37039. var evaluator = new PostScriptEvaluator(code);
  37040. // Cache the values for a big speed up, the cache size is limited though
  37041. // since the number of possible values can be huge from a PS function.
  37042. var cache = Object.create(null);
  37043. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  37044. // seen in our tests.
  37045. var MAX_CACHE_SIZE = 2048 * 4;
  37046. var cache_available = MAX_CACHE_SIZE;
  37047. var tmpBuf = new Float32Array(numInputs);
  37048. return function constructPostScriptFromIRResult(src, srcOffset,
  37049. dest, destOffset) {
  37050. var i, value;
  37051. var key = '';
  37052. var input = tmpBuf;
  37053. for (i = 0; i < numInputs; i++) {
  37054. value = src[srcOffset + i];
  37055. input[i] = value;
  37056. key += value + '_';
  37057. }
  37058. var cachedValue = cache[key];
  37059. if (cachedValue !== undefined) {
  37060. dest.set(cachedValue, destOffset);
  37061. return;
  37062. }
  37063. var output = new Float32Array(numOutputs);
  37064. var stack = evaluator.execute(input);
  37065. var stackIndex = stack.length - numOutputs;
  37066. for (i = 0; i < numOutputs; i++) {
  37067. value = stack[stackIndex + i];
  37068. var bound = range[i * 2];
  37069. if (value < bound) {
  37070. value = bound;
  37071. } else {
  37072. bound = range[i * 2 +1];
  37073. if (value > bound) {
  37074. value = bound;
  37075. }
  37076. }
  37077. output[i] = value;
  37078. }
  37079. if (cache_available > 0) {
  37080. cache_available--;
  37081. cache[key] = output;
  37082. }
  37083. dest.set(output, destOffset);
  37084. };
  37085. }
  37086. };
  37087. })();
  37088. function isPDFFunction(v) {
  37089. var fnDict;
  37090. if (typeof v !== 'object') {
  37091. return false;
  37092. } else if (isDict(v)) {
  37093. fnDict = v;
  37094. } else if (isStream(v)) {
  37095. fnDict = v.dict;
  37096. } else {
  37097. return false;
  37098. }
  37099. return fnDict.has('FunctionType');
  37100. }
  37101. var PostScriptStack = (function PostScriptStackClosure() {
  37102. var MAX_STACK_SIZE = 100;
  37103. function PostScriptStack(initialStack) {
  37104. this.stack = !initialStack ? [] :
  37105. Array.prototype.slice.call(initialStack, 0);
  37106. }
  37107. PostScriptStack.prototype = {
  37108. push: function PostScriptStack_push(value) {
  37109. if (this.stack.length >= MAX_STACK_SIZE) {
  37110. error('PostScript function stack overflow.');
  37111. }
  37112. this.stack.push(value);
  37113. },
  37114. pop: function PostScriptStack_pop() {
  37115. if (this.stack.length <= 0) {
  37116. error('PostScript function stack underflow.');
  37117. }
  37118. return this.stack.pop();
  37119. },
  37120. copy: function PostScriptStack_copy(n) {
  37121. if (this.stack.length + n >= MAX_STACK_SIZE) {
  37122. error('PostScript function stack overflow.');
  37123. }
  37124. var stack = this.stack;
  37125. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  37126. stack.push(stack[i]);
  37127. }
  37128. },
  37129. index: function PostScriptStack_index(n) {
  37130. this.push(this.stack[this.stack.length - n - 1]);
  37131. },
  37132. // rotate the last n stack elements p times
  37133. roll: function PostScriptStack_roll(n, p) {
  37134. var stack = this.stack;
  37135. var l = stack.length - n;
  37136. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  37137. for (i = l, j = r; i < j; i++, j--) {
  37138. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37139. }
  37140. for (i = l, j = c - 1; i < j; i++, j--) {
  37141. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37142. }
  37143. for (i = c, j = r; i < j; i++, j--) {
  37144. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37145. }
  37146. }
  37147. };
  37148. return PostScriptStack;
  37149. })();
  37150. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  37151. function PostScriptEvaluator(operators) {
  37152. this.operators = operators;
  37153. }
  37154. PostScriptEvaluator.prototype = {
  37155. execute: function PostScriptEvaluator_execute(initialStack) {
  37156. var stack = new PostScriptStack(initialStack);
  37157. var counter = 0;
  37158. var operators = this.operators;
  37159. var length = operators.length;
  37160. var operator, a, b;
  37161. while (counter < length) {
  37162. operator = operators[counter++];
  37163. if (typeof operator === 'number') {
  37164. // Operator is really an operand and should be pushed to the stack.
  37165. stack.push(operator);
  37166. continue;
  37167. }
  37168. switch (operator) {
  37169. // non standard ps operators
  37170. case 'jz': // jump if false
  37171. b = stack.pop();
  37172. a = stack.pop();
  37173. if (!a) {
  37174. counter = b;
  37175. }
  37176. break;
  37177. case 'j': // jump
  37178. a = stack.pop();
  37179. counter = a;
  37180. break;
  37181. // all ps operators in alphabetical order (excluding if/ifelse)
  37182. case 'abs':
  37183. a = stack.pop();
  37184. stack.push(Math.abs(a));
  37185. break;
  37186. case 'add':
  37187. b = stack.pop();
  37188. a = stack.pop();
  37189. stack.push(a + b);
  37190. break;
  37191. case 'and':
  37192. b = stack.pop();
  37193. a = stack.pop();
  37194. if (isBool(a) && isBool(b)) {
  37195. stack.push(a && b);
  37196. } else {
  37197. stack.push(a & b);
  37198. }
  37199. break;
  37200. case 'atan':
  37201. a = stack.pop();
  37202. stack.push(Math.atan(a));
  37203. break;
  37204. case 'bitshift':
  37205. b = stack.pop();
  37206. a = stack.pop();
  37207. if (a > 0) {
  37208. stack.push(a << b);
  37209. } else {
  37210. stack.push(a >> b);
  37211. }
  37212. break;
  37213. case 'ceiling':
  37214. a = stack.pop();
  37215. stack.push(Math.ceil(a));
  37216. break;
  37217. case 'copy':
  37218. a = stack.pop();
  37219. stack.copy(a);
  37220. break;
  37221. case 'cos':
  37222. a = stack.pop();
  37223. stack.push(Math.cos(a));
  37224. break;
  37225. case 'cvi':
  37226. a = stack.pop() | 0;
  37227. stack.push(a);
  37228. break;
  37229. case 'cvr':
  37230. // noop
  37231. break;
  37232. case 'div':
  37233. b = stack.pop();
  37234. a = stack.pop();
  37235. stack.push(a / b);
  37236. break;
  37237. case 'dup':
  37238. stack.copy(1);
  37239. break;
  37240. case 'eq':
  37241. b = stack.pop();
  37242. a = stack.pop();
  37243. stack.push(a === b);
  37244. break;
  37245. case 'exch':
  37246. stack.roll(2, 1);
  37247. break;
  37248. case 'exp':
  37249. b = stack.pop();
  37250. a = stack.pop();
  37251. stack.push(Math.pow(a, b));
  37252. break;
  37253. case 'false':
  37254. stack.push(false);
  37255. break;
  37256. case 'floor':
  37257. a = stack.pop();
  37258. stack.push(Math.floor(a));
  37259. break;
  37260. case 'ge':
  37261. b = stack.pop();
  37262. a = stack.pop();
  37263. stack.push(a >= b);
  37264. break;
  37265. case 'gt':
  37266. b = stack.pop();
  37267. a = stack.pop();
  37268. stack.push(a > b);
  37269. break;
  37270. case 'idiv':
  37271. b = stack.pop();
  37272. a = stack.pop();
  37273. stack.push((a / b) | 0);
  37274. break;
  37275. case 'index':
  37276. a = stack.pop();
  37277. stack.index(a);
  37278. break;
  37279. case 'le':
  37280. b = stack.pop();
  37281. a = stack.pop();
  37282. stack.push(a <= b);
  37283. break;
  37284. case 'ln':
  37285. a = stack.pop();
  37286. stack.push(Math.log(a));
  37287. break;
  37288. case 'log':
  37289. a = stack.pop();
  37290. stack.push(Math.log(a) / Math.LN10);
  37291. break;
  37292. case 'lt':
  37293. b = stack.pop();
  37294. a = stack.pop();
  37295. stack.push(a < b);
  37296. break;
  37297. case 'mod':
  37298. b = stack.pop();
  37299. a = stack.pop();
  37300. stack.push(a % b);
  37301. break;
  37302. case 'mul':
  37303. b = stack.pop();
  37304. a = stack.pop();
  37305. stack.push(a * b);
  37306. break;
  37307. case 'ne':
  37308. b = stack.pop();
  37309. a = stack.pop();
  37310. stack.push(a !== b);
  37311. break;
  37312. case 'neg':
  37313. a = stack.pop();
  37314. stack.push(-a);
  37315. break;
  37316. case 'not':
  37317. a = stack.pop();
  37318. if (isBool(a)) {
  37319. stack.push(!a);
  37320. } else {
  37321. stack.push(~a);
  37322. }
  37323. break;
  37324. case 'or':
  37325. b = stack.pop();
  37326. a = stack.pop();
  37327. if (isBool(a) && isBool(b)) {
  37328. stack.push(a || b);
  37329. } else {
  37330. stack.push(a | b);
  37331. }
  37332. break;
  37333. case 'pop':
  37334. stack.pop();
  37335. break;
  37336. case 'roll':
  37337. b = stack.pop();
  37338. a = stack.pop();
  37339. stack.roll(a, b);
  37340. break;
  37341. case 'round':
  37342. a = stack.pop();
  37343. stack.push(Math.round(a));
  37344. break;
  37345. case 'sin':
  37346. a = stack.pop();
  37347. stack.push(Math.sin(a));
  37348. break;
  37349. case 'sqrt':
  37350. a = stack.pop();
  37351. stack.push(Math.sqrt(a));
  37352. break;
  37353. case 'sub':
  37354. b = stack.pop();
  37355. a = stack.pop();
  37356. stack.push(a - b);
  37357. break;
  37358. case 'true':
  37359. stack.push(true);
  37360. break;
  37361. case 'truncate':
  37362. a = stack.pop();
  37363. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  37364. stack.push(a);
  37365. break;
  37366. case 'xor':
  37367. b = stack.pop();
  37368. a = stack.pop();
  37369. if (isBool(a) && isBool(b)) {
  37370. stack.push(a !== b);
  37371. } else {
  37372. stack.push(a ^ b);
  37373. }
  37374. break;
  37375. default:
  37376. error('Unknown operator ' + operator);
  37377. break;
  37378. }
  37379. }
  37380. return stack.stack;
  37381. }
  37382. };
  37383. return PostScriptEvaluator;
  37384. })();
  37385. // Most of the PDFs functions consist of simple operations such as:
  37386. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  37387. //
  37388. // We can compile most of such programs, and at the same moment, we can
  37389. // optimize some expressions using basic math properties. Keeping track of
  37390. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  37391. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  37392. function AstNode(type) {
  37393. this.type = type;
  37394. }
  37395. AstNode.prototype.visit = function (visitor) {
  37396. throw new Error('abstract method');
  37397. };
  37398. function AstArgument(index, min, max) {
  37399. AstNode.call(this, 'args');
  37400. this.index = index;
  37401. this.min = min;
  37402. this.max = max;
  37403. }
  37404. AstArgument.prototype = Object.create(AstNode.prototype);
  37405. AstArgument.prototype.visit = function (visitor) {
  37406. visitor.visitArgument(this);
  37407. };
  37408. function AstLiteral(number) {
  37409. AstNode.call(this, 'literal');
  37410. this.number = number;
  37411. this.min = number;
  37412. this.max = number;
  37413. }
  37414. AstLiteral.prototype = Object.create(AstNode.prototype);
  37415. AstLiteral.prototype.visit = function (visitor) {
  37416. visitor.visitLiteral(this);
  37417. };
  37418. function AstBinaryOperation(op, arg1, arg2, min, max) {
  37419. AstNode.call(this, 'binary');
  37420. this.op = op;
  37421. this.arg1 = arg1;
  37422. this.arg2 = arg2;
  37423. this.min = min;
  37424. this.max = max;
  37425. }
  37426. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  37427. AstBinaryOperation.prototype.visit = function (visitor) {
  37428. visitor.visitBinaryOperation(this);
  37429. };
  37430. function AstMin(arg, max) {
  37431. AstNode.call(this, 'max');
  37432. this.arg = arg;
  37433. this.min = arg.min;
  37434. this.max = max;
  37435. }
  37436. AstMin.prototype = Object.create(AstNode.prototype);
  37437. AstMin.prototype.visit = function (visitor) {
  37438. visitor.visitMin(this);
  37439. };
  37440. function AstVariable(index, min, max) {
  37441. AstNode.call(this, 'var');
  37442. this.index = index;
  37443. this.min = min;
  37444. this.max = max;
  37445. }
  37446. AstVariable.prototype = Object.create(AstNode.prototype);
  37447. AstVariable.prototype.visit = function (visitor) {
  37448. visitor.visitVariable(this);
  37449. };
  37450. function AstVariableDefinition(variable, arg) {
  37451. AstNode.call(this, 'definition');
  37452. this.variable = variable;
  37453. this.arg = arg;
  37454. }
  37455. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  37456. AstVariableDefinition.prototype.visit = function (visitor) {
  37457. visitor.visitVariableDefinition(this);
  37458. };
  37459. function ExpressionBuilderVisitor() {
  37460. this.parts = [];
  37461. }
  37462. ExpressionBuilderVisitor.prototype = {
  37463. visitArgument: function (arg) {
  37464. this.parts.push('Math.max(', arg.min, ', Math.min(',
  37465. arg.max, ', src[srcOffset + ', arg.index, ']))');
  37466. },
  37467. visitVariable: function (variable) {
  37468. this.parts.push('v', variable.index);
  37469. },
  37470. visitLiteral: function (literal) {
  37471. this.parts.push(literal.number);
  37472. },
  37473. visitBinaryOperation: function (operation) {
  37474. this.parts.push('(');
  37475. operation.arg1.visit(this);
  37476. this.parts.push(' ', operation.op, ' ');
  37477. operation.arg2.visit(this);
  37478. this.parts.push(')');
  37479. },
  37480. visitVariableDefinition: function (definition) {
  37481. this.parts.push('var ');
  37482. definition.variable.visit(this);
  37483. this.parts.push(' = ');
  37484. definition.arg.visit(this);
  37485. this.parts.push(';');
  37486. },
  37487. visitMin: function (max) {
  37488. this.parts.push('Math.min(');
  37489. max.arg.visit(this);
  37490. this.parts.push(', ', max.max, ')');
  37491. },
  37492. toString: function () {
  37493. return this.parts.join('');
  37494. }
  37495. };
  37496. function buildAddOperation(num1, num2) {
  37497. if (num2.type === 'literal' && num2.number === 0) {
  37498. // optimization: second operand is 0
  37499. return num1;
  37500. }
  37501. if (num1.type === 'literal' && num1.number === 0) {
  37502. // optimization: first operand is 0
  37503. return num2;
  37504. }
  37505. if (num2.type === 'literal' && num1.type === 'literal') {
  37506. // optimization: operands operand are literals
  37507. return new AstLiteral(num1.number + num2.number);
  37508. }
  37509. return new AstBinaryOperation('+', num1, num2,
  37510. num1.min + num2.min, num1.max + num2.max);
  37511. }
  37512. function buildMulOperation(num1, num2) {
  37513. if (num2.type === 'literal') {
  37514. // optimization: second operands is a literal...
  37515. if (num2.number === 0) {
  37516. return new AstLiteral(0); // and it's 0
  37517. } else if (num2.number === 1) {
  37518. return num1; // and it's 1
  37519. } else if (num1.type === 'literal') {
  37520. // ... and first operands is a literal too
  37521. return new AstLiteral(num1.number * num2.number);
  37522. }
  37523. }
  37524. if (num1.type === 'literal') {
  37525. // optimization: first operands is a literal...
  37526. if (num1.number === 0) {
  37527. return new AstLiteral(0); // and it's 0
  37528. } else if (num1.number === 1) {
  37529. return num2; // and it's 1
  37530. }
  37531. }
  37532. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  37533. num1.max * num2.min, num1.max * num2.max);
  37534. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  37535. num1.max * num2.min, num1.max * num2.max);
  37536. return new AstBinaryOperation('*', num1, num2, min, max);
  37537. }
  37538. function buildSubOperation(num1, num2) {
  37539. if (num2.type === 'literal') {
  37540. // optimization: second operands is a literal...
  37541. if (num2.number === 0) {
  37542. return num1; // ... and it's 0
  37543. } else if (num1.type === 'literal') {
  37544. // ... and first operands is a literal too
  37545. return new AstLiteral(num1.number - num2.number);
  37546. }
  37547. }
  37548. if (num2.type === 'binary' && num2.op === '-' &&
  37549. num1.type === 'literal' && num1.number === 1 &&
  37550. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  37551. // optimization for case: 1 - (1 - x)
  37552. return num2.arg2;
  37553. }
  37554. return new AstBinaryOperation('-', num1, num2,
  37555. num1.min - num2.max, num1.max - num2.min);
  37556. }
  37557. function buildMinOperation(num1, max) {
  37558. if (num1.min >= max) {
  37559. // optimization: num1 min value is not less than required max
  37560. return new AstLiteral(max); // just returning max
  37561. } else if (num1.max <= max) {
  37562. // optimization: num1 max value is not greater than required max
  37563. return num1; // just returning an argument
  37564. }
  37565. return new AstMin(num1, max);
  37566. }
  37567. function PostScriptCompiler() {}
  37568. PostScriptCompiler.prototype = {
  37569. compile: function PostScriptCompiler_compile(code, domain, range) {
  37570. var stack = [];
  37571. var i, ii;
  37572. var instructions = [];
  37573. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  37574. var lastRegister = 0;
  37575. var n, j;
  37576. var num1, num2, ast1, ast2, tmpVar, item;
  37577. for (i = 0; i < inputSize; i++) {
  37578. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  37579. }
  37580. for (i = 0, ii = code.length; i < ii; i++) {
  37581. item = code[i];
  37582. if (typeof item === 'number') {
  37583. stack.push(new AstLiteral(item));
  37584. continue;
  37585. }
  37586. switch (item) {
  37587. case 'add':
  37588. if (stack.length < 2) {
  37589. return null;
  37590. }
  37591. num2 = stack.pop();
  37592. num1 = stack.pop();
  37593. stack.push(buildAddOperation(num1, num2));
  37594. break;
  37595. case 'cvr':
  37596. if (stack.length < 1) {
  37597. return null;
  37598. }
  37599. break;
  37600. case 'mul':
  37601. if (stack.length < 2) {
  37602. return null;
  37603. }
  37604. num2 = stack.pop();
  37605. num1 = stack.pop();
  37606. stack.push(buildMulOperation(num1, num2));
  37607. break;
  37608. case 'sub':
  37609. if (stack.length < 2) {
  37610. return null;
  37611. }
  37612. num2 = stack.pop();
  37613. num1 = stack.pop();
  37614. stack.push(buildSubOperation(num1, num2));
  37615. break;
  37616. case 'exch':
  37617. if (stack.length < 2) {
  37618. return null;
  37619. }
  37620. ast1 = stack.pop(); ast2 = stack.pop();
  37621. stack.push(ast1, ast2);
  37622. break;
  37623. case 'pop':
  37624. if (stack.length < 1) {
  37625. return null;
  37626. }
  37627. stack.pop();
  37628. break;
  37629. case 'index':
  37630. if (stack.length < 1) {
  37631. return null;
  37632. }
  37633. num1 = stack.pop();
  37634. if (num1.type !== 'literal') {
  37635. return null;
  37636. }
  37637. n = num1.number;
  37638. if (n < 0 || (n|0) !== n || stack.length < n) {
  37639. return null;
  37640. }
  37641. ast1 = stack[stack.length - n - 1];
  37642. if (ast1.type === 'literal' || ast1.type === 'var') {
  37643. stack.push(ast1);
  37644. break;
  37645. }
  37646. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37647. stack[stack.length - n - 1] = tmpVar;
  37648. stack.push(tmpVar);
  37649. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37650. break;
  37651. case 'dup':
  37652. if (stack.length < 1) {
  37653. return null;
  37654. }
  37655. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  37656. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  37657. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  37658. // special case of the commands sequence for the min operation
  37659. num1 = stack.pop();
  37660. stack.push(buildMinOperation(num1, code[i + 1]));
  37661. i += 6;
  37662. break;
  37663. }
  37664. ast1 = stack[stack.length - 1];
  37665. if (ast1.type === 'literal' || ast1.type === 'var') {
  37666. // we don't have to save into intermediate variable a literal or
  37667. // variable.
  37668. stack.push(ast1);
  37669. break;
  37670. }
  37671. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37672. stack[stack.length - 1] = tmpVar;
  37673. stack.push(tmpVar);
  37674. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37675. break;
  37676. case 'roll':
  37677. if (stack.length < 2) {
  37678. return null;
  37679. }
  37680. num2 = stack.pop();
  37681. num1 = stack.pop();
  37682. if (num2.type !== 'literal' || num1.type !== 'literal') {
  37683. // both roll operands must be numbers
  37684. return null;
  37685. }
  37686. j = num2.number;
  37687. n = num1.number;
  37688. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  37689. // ... and integers
  37690. return null;
  37691. }
  37692. j = ((j % n) + n) % n;
  37693. if (j === 0) {
  37694. break; // just skipping -- there are nothing to rotate
  37695. }
  37696. Array.prototype.push.apply(stack,
  37697. stack.splice(stack.length - n, n - j));
  37698. break;
  37699. default:
  37700. return null; // unsupported operator
  37701. }
  37702. }
  37703. if (stack.length !== outputSize) {
  37704. return null;
  37705. }
  37706. var result = [];
  37707. instructions.forEach(function (instruction) {
  37708. var statementBuilder = new ExpressionBuilderVisitor();
  37709. instruction.visit(statementBuilder);
  37710. result.push(statementBuilder.toString());
  37711. });
  37712. stack.forEach(function (expr, i) {
  37713. var statementBuilder = new ExpressionBuilderVisitor();
  37714. expr.visit(statementBuilder);
  37715. var min = range[i * 2], max = range[i * 2 + 1];
  37716. var out = [statementBuilder.toString()];
  37717. if (min > expr.min) {
  37718. out.unshift('Math.max(', min, ', ');
  37719. out.push(')');
  37720. }
  37721. if (max < expr.max) {
  37722. out.unshift('Math.min(', max, ', ');
  37723. out.push(')');
  37724. }
  37725. out.unshift('dest[destOffset + ', i, '] = ');
  37726. out.push(';');
  37727. result.push(out.join(''));
  37728. });
  37729. return result.join('\n');
  37730. }
  37731. };
  37732. return PostScriptCompiler;
  37733. })();
  37734. exports.isPDFFunction = isPDFFunction;
  37735. exports.PDFFunction = PDFFunction;
  37736. exports.PostScriptEvaluator = PostScriptEvaluator;
  37737. exports.PostScriptCompiler = PostScriptCompiler;
  37738. }));
  37739. (function (root, factory) {
  37740. {
  37741. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  37742. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  37743. }
  37744. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  37745. coreStream) {
  37746. var error = sharedUtil.error;
  37747. var info = sharedUtil.info;
  37748. var isArray = sharedUtil.isArray;
  37749. var isString = sharedUtil.isString;
  37750. var shadow = sharedUtil.shadow;
  37751. var warn = sharedUtil.warn;
  37752. var isDict = corePrimitives.isDict;
  37753. var isName = corePrimitives.isName;
  37754. var isStream = corePrimitives.isStream;
  37755. var PDFFunction = coreFunction.PDFFunction;
  37756. var coreImage; // see _setCoreImage below
  37757. var PDFImage; // = coreImage.PDFImage;
  37758. var ColorSpace = (function ColorSpaceClosure() {
  37759. // Constructor should define this.numComps, this.defaultColor, this.name
  37760. function ColorSpace() {
  37761. error('should not call ColorSpace constructor');
  37762. }
  37763. ColorSpace.prototype = {
  37764. /**
  37765. * Converts the color value to the RGB color. The color components are
  37766. * located in the src array starting from the srcOffset. Returns the array
  37767. * of the rgb components, each value ranging from [0,255].
  37768. */
  37769. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  37770. var rgb = new Uint8Array(3);
  37771. this.getRgbItem(src, srcOffset, rgb, 0);
  37772. return rgb;
  37773. },
  37774. /**
  37775. * Converts the color value to the RGB color, similar to the getRgb method.
  37776. * The result placed into the dest array starting from the destOffset.
  37777. */
  37778. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  37779. dest, destOffset) {
  37780. error('Should not call ColorSpace.getRgbItem');
  37781. },
  37782. /**
  37783. * Converts the specified number of the color values to the RGB colors.
  37784. * The colors are located in the src array starting from the srcOffset.
  37785. * The result is placed into the dest array starting from the destOffset.
  37786. * The src array items shall be in [0,2^bits) range, the dest array items
  37787. * will be in [0,255] range. alpha01 indicates how many alpha components
  37788. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  37789. * array).
  37790. */
  37791. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  37792. dest, destOffset, bits,
  37793. alpha01) {
  37794. error('Should not call ColorSpace.getRgbBuffer');
  37795. },
  37796. /**
  37797. * Determines the number of bytes required to store the result of the
  37798. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  37799. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  37800. */
  37801. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  37802. alpha01) {
  37803. error('Should not call ColorSpace.getOutputLength');
  37804. },
  37805. /**
  37806. * Returns true if source data will be equal the result/output data.
  37807. */
  37808. isPassthrough: function ColorSpace_isPassthrough(bits) {
  37809. return false;
  37810. },
  37811. /**
  37812. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  37813. * how many alpha components there are in the dest array; it will be either
  37814. * 0 (RGB array) or 1 (RGBA array).
  37815. */
  37816. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  37817. originalHeight, width, height,
  37818. actualHeight, bpc, comps, alpha01) {
  37819. var count = originalWidth * originalHeight;
  37820. var rgbBuf = null;
  37821. var numComponentColors = 1 << bpc;
  37822. var needsResizing = originalHeight !== height || originalWidth !== width;
  37823. var i, ii;
  37824. if (this.isPassthrough(bpc)) {
  37825. rgbBuf = comps;
  37826. } else if (this.numComps === 1 && count > numComponentColors &&
  37827. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  37828. // Optimization: create a color map when there is just one component and
  37829. // we are converting more colors than the size of the color map. We
  37830. // don't build the map if the colorspace is gray or rgb since those
  37831. // methods are faster than building a map. This mainly offers big speed
  37832. // ups for indexed and alternate colorspaces.
  37833. //
  37834. // TODO it may be worth while to cache the color map. While running
  37835. // testing I never hit a cache so I will leave that out for now (perhaps
  37836. // we are reparsing colorspaces too much?).
  37837. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  37838. new Uint16Array(numComponentColors);
  37839. var key;
  37840. for (i = 0; i < numComponentColors; i++) {
  37841. allColors[i] = i;
  37842. }
  37843. var colorMap = new Uint8Array(numComponentColors * 3);
  37844. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  37845. /* alpha01 = */ 0);
  37846. var destPos, rgbPos;
  37847. if (!needsResizing) {
  37848. // Fill in the RGB values directly into |dest|.
  37849. destPos = 0;
  37850. for (i = 0; i < count; ++i) {
  37851. key = comps[i] * 3;
  37852. dest[destPos++] = colorMap[key];
  37853. dest[destPos++] = colorMap[key + 1];
  37854. dest[destPos++] = colorMap[key + 2];
  37855. destPos += alpha01;
  37856. }
  37857. } else {
  37858. rgbBuf = new Uint8Array(count * 3);
  37859. rgbPos = 0;
  37860. for (i = 0; i < count; ++i) {
  37861. key = comps[i] * 3;
  37862. rgbBuf[rgbPos++] = colorMap[key];
  37863. rgbBuf[rgbPos++] = colorMap[key + 1];
  37864. rgbBuf[rgbPos++] = colorMap[key + 2];
  37865. }
  37866. }
  37867. } else {
  37868. if (!needsResizing) {
  37869. // Fill in the RGB values directly into |dest|.
  37870. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  37871. alpha01);
  37872. } else {
  37873. rgbBuf = new Uint8Array(count * 3);
  37874. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  37875. /* alpha01 = */ 0);
  37876. }
  37877. }
  37878. if (rgbBuf) {
  37879. if (needsResizing) {
  37880. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  37881. height, dest, alpha01);
  37882. } else {
  37883. rgbPos = 0;
  37884. destPos = 0;
  37885. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  37886. dest[destPos++] = rgbBuf[rgbPos++];
  37887. dest[destPos++] = rgbBuf[rgbPos++];
  37888. dest[destPos++] = rgbBuf[rgbPos++];
  37889. destPos += alpha01;
  37890. }
  37891. }
  37892. }
  37893. },
  37894. /**
  37895. * True if the colorspace has components in the default range of [0, 1].
  37896. * This should be true for all colorspaces except for lab color spaces
  37897. * which are [0,100], [-128, 127], [-128, 127].
  37898. */
  37899. usesZeroToOneRange: true
  37900. };
  37901. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  37902. var IR = ColorSpace.parseToIR(cs, xref, res);
  37903. if (IR instanceof AlternateCS) {
  37904. return IR;
  37905. }
  37906. return ColorSpace.fromIR(IR);
  37907. };
  37908. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  37909. var name = isArray(IR) ? IR[0] : IR;
  37910. var whitePoint, blackPoint, gamma;
  37911. switch (name) {
  37912. case 'DeviceGrayCS':
  37913. return this.singletons.gray;
  37914. case 'DeviceRgbCS':
  37915. return this.singletons.rgb;
  37916. case 'DeviceCmykCS':
  37917. return this.singletons.cmyk;
  37918. case 'CalGrayCS':
  37919. whitePoint = IR[1];
  37920. blackPoint = IR[2];
  37921. gamma = IR[3];
  37922. return new CalGrayCS(whitePoint, blackPoint, gamma);
  37923. case 'CalRGBCS':
  37924. whitePoint = IR[1];
  37925. blackPoint = IR[2];
  37926. gamma = IR[3];
  37927. var matrix = IR[4];
  37928. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  37929. case 'PatternCS':
  37930. var basePatternCS = IR[1];
  37931. if (basePatternCS) {
  37932. basePatternCS = ColorSpace.fromIR(basePatternCS);
  37933. }
  37934. return new PatternCS(basePatternCS);
  37935. case 'IndexedCS':
  37936. var baseIndexedCS = IR[1];
  37937. var hiVal = IR[2];
  37938. var lookup = IR[3];
  37939. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  37940. case 'AlternateCS':
  37941. var numComps = IR[1];
  37942. var alt = IR[2];
  37943. var tintFnIR = IR[3];
  37944. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  37945. PDFFunction.fromIR(tintFnIR));
  37946. case 'LabCS':
  37947. whitePoint = IR[1];
  37948. blackPoint = IR[2];
  37949. var range = IR[3];
  37950. return new LabCS(whitePoint, blackPoint, range);
  37951. default:
  37952. error('Unknown name ' + name);
  37953. }
  37954. return null;
  37955. };
  37956. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  37957. if (isName(cs)) {
  37958. var colorSpaces = res.get('ColorSpace');
  37959. if (isDict(colorSpaces)) {
  37960. var refcs = colorSpaces.get(cs.name);
  37961. if (refcs) {
  37962. cs = refcs;
  37963. }
  37964. }
  37965. }
  37966. cs = xref.fetchIfRef(cs);
  37967. var mode;
  37968. if (isName(cs)) {
  37969. mode = cs.name;
  37970. this.mode = mode;
  37971. switch (mode) {
  37972. case 'DeviceGray':
  37973. case 'G':
  37974. return 'DeviceGrayCS';
  37975. case 'DeviceRGB':
  37976. case 'RGB':
  37977. return 'DeviceRgbCS';
  37978. case 'DeviceCMYK':
  37979. case 'CMYK':
  37980. return 'DeviceCmykCS';
  37981. case 'Pattern':
  37982. return ['PatternCS', null];
  37983. default:
  37984. error('unrecognized colorspace ' + mode);
  37985. }
  37986. } else if (isArray(cs)) {
  37987. mode = xref.fetchIfRef(cs[0]).name;
  37988. this.mode = mode;
  37989. var numComps, params, alt, whitePoint, blackPoint, gamma;
  37990. switch (mode) {
  37991. case 'DeviceGray':
  37992. case 'G':
  37993. return 'DeviceGrayCS';
  37994. case 'DeviceRGB':
  37995. case 'RGB':
  37996. return 'DeviceRgbCS';
  37997. case 'DeviceCMYK':
  37998. case 'CMYK':
  37999. return 'DeviceCmykCS';
  38000. case 'CalGray':
  38001. params = xref.fetchIfRef(cs[1]);
  38002. whitePoint = params.get('WhitePoint');
  38003. blackPoint = params.get('BlackPoint');
  38004. gamma = params.get('Gamma');
  38005. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38006. case 'CalRGB':
  38007. params = xref.fetchIfRef(cs[1]);
  38008. whitePoint = params.get('WhitePoint');
  38009. blackPoint = params.get('BlackPoint');
  38010. gamma = params.get('Gamma');
  38011. var matrix = params.get('Matrix');
  38012. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38013. case 'ICCBased':
  38014. var stream = xref.fetchIfRef(cs[1]);
  38015. var dict = stream.dict;
  38016. numComps = dict.get('N');
  38017. alt = dict.get('Alternate');
  38018. if (alt) {
  38019. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38020. // Parse the /Alternate CS to ensure that the number of components
  38021. // are correct, and also (indirectly) that it is not a PatternCS.
  38022. var altCS = ColorSpace.fromIR(altIR);
  38023. if (altCS.numComps === numComps) {
  38024. return altIR;
  38025. }
  38026. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38027. }
  38028. if (numComps === 1) {
  38029. return 'DeviceGrayCS';
  38030. } else if (numComps === 3) {
  38031. return 'DeviceRgbCS';
  38032. } else if (numComps === 4) {
  38033. return 'DeviceCmykCS';
  38034. }
  38035. break;
  38036. case 'Pattern':
  38037. var basePatternCS = cs[1] || null;
  38038. if (basePatternCS) {
  38039. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38040. }
  38041. return ['PatternCS', basePatternCS];
  38042. case 'Indexed':
  38043. case 'I':
  38044. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38045. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38046. var lookup = xref.fetchIfRef(cs[3]);
  38047. if (isStream(lookup)) {
  38048. lookup = lookup.getBytes();
  38049. }
  38050. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38051. case 'Separation':
  38052. case 'DeviceN':
  38053. var name = xref.fetchIfRef(cs[1]);
  38054. numComps = 1;
  38055. if (isName(name)) {
  38056. numComps = 1;
  38057. } else if (isArray(name)) {
  38058. numComps = name.length;
  38059. }
  38060. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38061. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38062. return ['AlternateCS', numComps, alt, tintFnIR];
  38063. case 'Lab':
  38064. params = xref.fetchIfRef(cs[1]);
  38065. whitePoint = params.get('WhitePoint');
  38066. blackPoint = params.get('BlackPoint');
  38067. var range = params.get('Range');
  38068. return ['LabCS', whitePoint, blackPoint, range];
  38069. default:
  38070. error('unimplemented color space object "' + mode + '"');
  38071. }
  38072. } else {
  38073. error('unrecognized color space object: "' + cs + '"');
  38074. }
  38075. return null;
  38076. };
  38077. /**
  38078. * Checks if a decode map matches the default decode map for a color space.
  38079. * This handles the general decode maps where there are two values per
  38080. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38081. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38082. * slightly different.
  38083. * @param {Array} decode Decode map (usually from an image).
  38084. * @param {Number} n Number of components the color space has.
  38085. */
  38086. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38087. if (!isArray(decode)) {
  38088. return true;
  38089. }
  38090. if (n * 2 !== decode.length) {
  38091. warn('The decode map is not the correct length');
  38092. return true;
  38093. }
  38094. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38095. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38096. return false;
  38097. }
  38098. }
  38099. return true;
  38100. };
  38101. ColorSpace.singletons = {
  38102. get gray() {
  38103. return shadow(this, 'gray', new DeviceGrayCS());
  38104. },
  38105. get rgb() {
  38106. return shadow(this, 'rgb', new DeviceRgbCS());
  38107. },
  38108. get cmyk() {
  38109. return shadow(this, 'cmyk', new DeviceCmykCS());
  38110. }
  38111. };
  38112. return ColorSpace;
  38113. })();
  38114. /**
  38115. * Alternate color space handles both Separation and DeviceN color spaces. A
  38116. * Separation color space is actually just a DeviceN with one color component.
  38117. * Both color spaces use a tinting function to convert colors to a base color
  38118. * space.
  38119. */
  38120. var AlternateCS = (function AlternateCSClosure() {
  38121. function AlternateCS(numComps, base, tintFn) {
  38122. this.name = 'Alternate';
  38123. this.numComps = numComps;
  38124. this.defaultColor = new Float32Array(numComps);
  38125. for (var i = 0; i < numComps; ++i) {
  38126. this.defaultColor[i] = 1;
  38127. }
  38128. this.base = base;
  38129. this.tintFn = tintFn;
  38130. this.tmpBuf = new Float32Array(base.numComps);
  38131. }
  38132. AlternateCS.prototype = {
  38133. getRgb: ColorSpace.prototype.getRgb,
  38134. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38135. dest, destOffset) {
  38136. var tmpBuf = this.tmpBuf;
  38137. this.tintFn(src, srcOffset, tmpBuf, 0);
  38138. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38139. },
  38140. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38141. dest, destOffset, bits,
  38142. alpha01) {
  38143. var tintFn = this.tintFn;
  38144. var base = this.base;
  38145. var scale = 1 / ((1 << bits) - 1);
  38146. var baseNumComps = base.numComps;
  38147. var usesZeroToOneRange = base.usesZeroToOneRange;
  38148. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38149. alpha01 === 0;
  38150. var pos = isPassthrough ? destOffset : 0;
  38151. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38152. var numComps = this.numComps;
  38153. var scaled = new Float32Array(numComps);
  38154. var tinted = new Float32Array(baseNumComps);
  38155. var i, j;
  38156. if (usesZeroToOneRange) {
  38157. for (i = 0; i < count; i++) {
  38158. for (j = 0; j < numComps; j++) {
  38159. scaled[j] = src[srcOffset++] * scale;
  38160. }
  38161. tintFn(scaled, 0, tinted, 0);
  38162. for (j = 0; j < baseNumComps; j++) {
  38163. baseBuf[pos++] = tinted[j] * 255;
  38164. }
  38165. }
  38166. } else {
  38167. for (i = 0; i < count; i++) {
  38168. for (j = 0; j < numComps; j++) {
  38169. scaled[j] = src[srcOffset++] * scale;
  38170. }
  38171. tintFn(scaled, 0, tinted, 0);
  38172. base.getRgbItem(tinted, 0, baseBuf, pos);
  38173. pos += baseNumComps;
  38174. }
  38175. }
  38176. if (!isPassthrough) {
  38177. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38178. }
  38179. },
  38180. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38181. alpha01) {
  38182. return this.base.getOutputLength(inputLength *
  38183. this.base.numComps / this.numComps,
  38184. alpha01);
  38185. },
  38186. isPassthrough: ColorSpace.prototype.isPassthrough,
  38187. fillRgb: ColorSpace.prototype.fillRgb,
  38188. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38189. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38190. },
  38191. usesZeroToOneRange: true
  38192. };
  38193. return AlternateCS;
  38194. })();
  38195. var PatternCS = (function PatternCSClosure() {
  38196. function PatternCS(baseCS) {
  38197. this.name = 'Pattern';
  38198. this.base = baseCS;
  38199. }
  38200. PatternCS.prototype = {};
  38201. return PatternCS;
  38202. })();
  38203. var IndexedCS = (function IndexedCSClosure() {
  38204. function IndexedCS(base, highVal, lookup) {
  38205. this.name = 'Indexed';
  38206. this.numComps = 1;
  38207. this.defaultColor = new Uint8Array([0]);
  38208. this.base = base;
  38209. this.highVal = highVal;
  38210. var baseNumComps = base.numComps;
  38211. var length = baseNumComps * highVal;
  38212. var lookupArray;
  38213. if (isStream(lookup)) {
  38214. lookupArray = new Uint8Array(length);
  38215. var bytes = lookup.getBytes(length);
  38216. lookupArray.set(bytes);
  38217. } else if (isString(lookup)) {
  38218. lookupArray = new Uint8Array(length);
  38219. for (var i = 0; i < length; ++i) {
  38220. lookupArray[i] = lookup.charCodeAt(i);
  38221. }
  38222. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38223. lookupArray = lookup;
  38224. } else {
  38225. error('Unrecognized lookup table: ' + lookup);
  38226. }
  38227. this.lookup = lookupArray;
  38228. }
  38229. IndexedCS.prototype = {
  38230. getRgb: ColorSpace.prototype.getRgb,
  38231. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38232. dest, destOffset) {
  38233. var numComps = this.base.numComps;
  38234. var start = src[srcOffset] * numComps;
  38235. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38236. },
  38237. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38238. dest, destOffset, bits,
  38239. alpha01) {
  38240. var base = this.base;
  38241. var numComps = base.numComps;
  38242. var outputDelta = base.getOutputLength(numComps, alpha01);
  38243. var lookup = this.lookup;
  38244. for (var i = 0; i < count; ++i) {
  38245. var lookupPos = src[srcOffset++] * numComps;
  38246. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38247. destOffset += outputDelta;
  38248. }
  38249. },
  38250. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38251. return this.base.getOutputLength(inputLength * this.base.numComps,
  38252. alpha01);
  38253. },
  38254. isPassthrough: ColorSpace.prototype.isPassthrough,
  38255. fillRgb: ColorSpace.prototype.fillRgb,
  38256. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38257. // indexed color maps shouldn't be changed
  38258. return true;
  38259. },
  38260. usesZeroToOneRange: true
  38261. };
  38262. return IndexedCS;
  38263. })();
  38264. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38265. function DeviceGrayCS() {
  38266. this.name = 'DeviceGray';
  38267. this.numComps = 1;
  38268. this.defaultColor = new Float32Array([0]);
  38269. }
  38270. DeviceGrayCS.prototype = {
  38271. getRgb: ColorSpace.prototype.getRgb,
  38272. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38273. dest, destOffset) {
  38274. var c = (src[srcOffset] * 255) | 0;
  38275. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38276. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38277. },
  38278. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38279. dest, destOffset, bits,
  38280. alpha01) {
  38281. var scale = 255 / ((1 << bits) - 1);
  38282. var j = srcOffset, q = destOffset;
  38283. for (var i = 0; i < count; ++i) {
  38284. var c = (scale * src[j++]) | 0;
  38285. dest[q++] = c;
  38286. dest[q++] = c;
  38287. dest[q++] = c;
  38288. q += alpha01;
  38289. }
  38290. },
  38291. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38292. alpha01) {
  38293. return inputLength * (3 + alpha01);
  38294. },
  38295. isPassthrough: ColorSpace.prototype.isPassthrough,
  38296. fillRgb: ColorSpace.prototype.fillRgb,
  38297. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38298. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38299. },
  38300. usesZeroToOneRange: true
  38301. };
  38302. return DeviceGrayCS;
  38303. })();
  38304. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38305. function DeviceRgbCS() {
  38306. this.name = 'DeviceRGB';
  38307. this.numComps = 3;
  38308. this.defaultColor = new Float32Array([0, 0, 0]);
  38309. }
  38310. DeviceRgbCS.prototype = {
  38311. getRgb: ColorSpace.prototype.getRgb,
  38312. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38313. dest, destOffset) {
  38314. var r = (src[srcOffset] * 255) | 0;
  38315. var g = (src[srcOffset + 1] * 255) | 0;
  38316. var b = (src[srcOffset + 2] * 255) | 0;
  38317. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38318. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38319. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38320. },
  38321. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38322. dest, destOffset, bits,
  38323. alpha01) {
  38324. if (bits === 8 && alpha01 === 0) {
  38325. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38326. return;
  38327. }
  38328. var scale = 255 / ((1 << bits) - 1);
  38329. var j = srcOffset, q = destOffset;
  38330. for (var i = 0; i < count; ++i) {
  38331. dest[q++] = (scale * src[j++]) | 0;
  38332. dest[q++] = (scale * src[j++]) | 0;
  38333. dest[q++] = (scale * src[j++]) | 0;
  38334. q += alpha01;
  38335. }
  38336. },
  38337. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38338. alpha01) {
  38339. return (inputLength * (3 + alpha01) / 3) | 0;
  38340. },
  38341. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38342. return bits === 8;
  38343. },
  38344. fillRgb: ColorSpace.prototype.fillRgb,
  38345. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38346. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38347. },
  38348. usesZeroToOneRange: true
  38349. };
  38350. return DeviceRgbCS;
  38351. })();
  38352. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38353. // The coefficients below was found using numerical analysis: the method of
  38354. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38355. // where color_value is the tabular value from the table of sampled RGB colors
  38356. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38357. // CMYK color conversion using the estimation below:
  38358. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38359. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38360. var c = src[srcOffset + 0] * srcScale;
  38361. var m = src[srcOffset + 1] * srcScale;
  38362. var y = src[srcOffset + 2] * srcScale;
  38363. var k = src[srcOffset + 3] * srcScale;
  38364. var r =
  38365. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38366. 18.82290502165302 * y + 212.25662451639585 * k +
  38367. -285.2331026137004) +
  38368. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38369. -17.873870861415444 * k - 5.497006427196366) +
  38370. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38371. 17.5119270841813) +
  38372. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38373. var g =
  38374. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38375. 6.871425592049007 * y + 31.159100130055922 * k +
  38376. -79.2970844816548) +
  38377. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38378. 131.35250912493976 * k - 190.9453302588951) +
  38379. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38380. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38381. var b =
  38382. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38383. 30.89978309703729 * y - 0.23883238689178934 * k +
  38384. -14.183576799673286) +
  38385. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38386. 50.606957656360734 * k - 112.23884253719248) +
  38387. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38388. -193.58209356861505) +
  38389. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38390. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38391. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38392. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38393. }
  38394. function DeviceCmykCS() {
  38395. this.name = 'DeviceCMYK';
  38396. this.numComps = 4;
  38397. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38398. }
  38399. DeviceCmykCS.prototype = {
  38400. getRgb: ColorSpace.prototype.getRgb,
  38401. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38402. dest, destOffset) {
  38403. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38404. },
  38405. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38406. dest, destOffset, bits,
  38407. alpha01) {
  38408. var scale = 1 / ((1 << bits) - 1);
  38409. for (var i = 0; i < count; i++) {
  38410. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38411. srcOffset += 4;
  38412. destOffset += 3 + alpha01;
  38413. }
  38414. },
  38415. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38416. alpha01) {
  38417. return (inputLength / 4 * (3 + alpha01)) | 0;
  38418. },
  38419. isPassthrough: ColorSpace.prototype.isPassthrough,
  38420. fillRgb: ColorSpace.prototype.fillRgb,
  38421. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38422. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38423. },
  38424. usesZeroToOneRange: true
  38425. };
  38426. return DeviceCmykCS;
  38427. })();
  38428. //
  38429. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38430. //
  38431. var CalGrayCS = (function CalGrayCSClosure() {
  38432. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38433. this.name = 'CalGray';
  38434. this.numComps = 1;
  38435. this.defaultColor = new Float32Array([0]);
  38436. if (!whitePoint) {
  38437. error('WhitePoint missing - required for color space CalGray');
  38438. }
  38439. blackPoint = blackPoint || [0, 0, 0];
  38440. gamma = gamma || 1;
  38441. // Translate arguments to spec variables.
  38442. this.XW = whitePoint[0];
  38443. this.YW = whitePoint[1];
  38444. this.ZW = whitePoint[2];
  38445. this.XB = blackPoint[0];
  38446. this.YB = blackPoint[1];
  38447. this.ZB = blackPoint[2];
  38448. this.G = gamma;
  38449. // Validate variables as per spec.
  38450. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38451. error('Invalid WhitePoint components for ' + this.name +
  38452. ', no fallback available');
  38453. }
  38454. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38455. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38456. this.XB = this.YB = this.ZB = 0;
  38457. }
  38458. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38459. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38460. ', ZB: ' + this.ZB + ', only default values are supported.');
  38461. }
  38462. if (this.G < 1) {
  38463. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38464. ', falling back to default');
  38465. this.G = 1;
  38466. }
  38467. }
  38468. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38469. // A represents a gray component of a calibrated gray space.
  38470. // A <---> AG in the spec
  38471. var A = src[srcOffset] * scale;
  38472. var AG = Math.pow(A, cs.G);
  38473. // Computes L as per spec. ( = cs.YW * AG )
  38474. // Except if other than default BlackPoint values are used.
  38475. var L = cs.YW * AG;
  38476. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38477. // Convert values to rgb range [0, 255].
  38478. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38479. dest[destOffset] = val;
  38480. dest[destOffset + 1] = val;
  38481. dest[destOffset + 2] = val;
  38482. }
  38483. CalGrayCS.prototype = {
  38484. getRgb: ColorSpace.prototype.getRgb,
  38485. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38486. dest, destOffset) {
  38487. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38488. },
  38489. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38490. dest, destOffset, bits,
  38491. alpha01) {
  38492. var scale = 1 / ((1 << bits) - 1);
  38493. for (var i = 0; i < count; ++i) {
  38494. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38495. srcOffset += 1;
  38496. destOffset += 3 + alpha01;
  38497. }
  38498. },
  38499. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38500. return inputLength * (3 + alpha01);
  38501. },
  38502. isPassthrough: ColorSpace.prototype.isPassthrough,
  38503. fillRgb: ColorSpace.prototype.fillRgb,
  38504. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38505. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38506. },
  38507. usesZeroToOneRange: true
  38508. };
  38509. return CalGrayCS;
  38510. })();
  38511. //
  38512. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38513. //
  38514. var CalRGBCS = (function CalRGBCSClosure() {
  38515. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38516. // matrices.
  38517. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38518. 0.8951, 0.2664, -0.1614,
  38519. -0.7502, 1.7135, 0.0367,
  38520. 0.0389, -0.0685, 1.0296]);
  38521. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38522. 0.9869929, -0.1470543, 0.1599627,
  38523. 0.4323053, 0.5183603, 0.0492912,
  38524. -0.0085287, 0.0400428, 0.9684867]);
  38525. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38526. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38527. 3.2404542, -1.5371385, -0.4985314,
  38528. -0.9692660, 1.8760108, 0.0415560,
  38529. 0.0556434, -0.2040259, 1.0572252]);
  38530. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38531. var tempNormalizeMatrix = new Float32Array(3);
  38532. var tempConvertMatrix1 = new Float32Array(3);
  38533. var tempConvertMatrix2 = new Float32Array(3);
  38534. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38535. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38536. this.name = 'CalRGB';
  38537. this.numComps = 3;
  38538. this.defaultColor = new Float32Array(3);
  38539. if (!whitePoint) {
  38540. error('WhitePoint missing - required for color space CalRGB');
  38541. }
  38542. blackPoint = blackPoint || new Float32Array(3);
  38543. gamma = gamma || new Float32Array([1, 1, 1]);
  38544. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38545. // Translate arguments to spec variables.
  38546. var XW = whitePoint[0];
  38547. var YW = whitePoint[1];
  38548. var ZW = whitePoint[2];
  38549. this.whitePoint = whitePoint;
  38550. var XB = blackPoint[0];
  38551. var YB = blackPoint[1];
  38552. var ZB = blackPoint[2];
  38553. this.blackPoint = blackPoint;
  38554. this.GR = gamma[0];
  38555. this.GG = gamma[1];
  38556. this.GB = gamma[2];
  38557. this.MXA = matrix[0];
  38558. this.MYA = matrix[1];
  38559. this.MZA = matrix[2];
  38560. this.MXB = matrix[3];
  38561. this.MYB = matrix[4];
  38562. this.MZB = matrix[5];
  38563. this.MXC = matrix[6];
  38564. this.MYC = matrix[7];
  38565. this.MZC = matrix[8];
  38566. // Validate variables as per spec.
  38567. if (XW < 0 || ZW < 0 || YW !== 1) {
  38568. error('Invalid WhitePoint components for ' + this.name +
  38569. ', no fallback available');
  38570. }
  38571. if (XB < 0 || YB < 0 || ZB < 0) {
  38572. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38573. ', ' + ZB + '], falling back to default');
  38574. this.blackPoint = new Float32Array(3);
  38575. }
  38576. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38577. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38578. '] for ' + this.name + ', falling back to default');
  38579. this.GR = this.GG = this.GB = 1;
  38580. }
  38581. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38582. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38583. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  38584. info('Invalid Matrix for ' + this.name + ' [' +
  38585. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  38586. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  38587. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  38588. '], falling back to default');
  38589. this.MXA = this.MYB = this.MZC = 1;
  38590. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  38591. }
  38592. }
  38593. function matrixProduct(a, b, result) {
  38594. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  38595. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  38596. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  38597. }
  38598. function convertToFlat(sourceWhitePoint, LMS, result) {
  38599. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  38600. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  38601. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  38602. }
  38603. function convertToD65(sourceWhitePoint, LMS, result) {
  38604. var D65X = 0.95047;
  38605. var D65Y = 1;
  38606. var D65Z = 1.08883;
  38607. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  38608. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  38609. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  38610. }
  38611. function sRGBTransferFunction(color) {
  38612. // See http://en.wikipedia.org/wiki/SRGB.
  38613. if (color <= 0.0031308){
  38614. return adjustToRange(0, 1, 12.92 * color);
  38615. }
  38616. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  38617. }
  38618. function adjustToRange(min, max, value) {
  38619. return Math.max(min, Math.min(max, value));
  38620. }
  38621. function decodeL(L) {
  38622. if (L < 0) {
  38623. return -decodeL(-L);
  38624. }
  38625. if (L > 8.0) {
  38626. return Math.pow(((L + 16) / 116), 3);
  38627. }
  38628. return L * DECODE_L_CONSTANT;
  38629. }
  38630. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  38631. // In case the blackPoint is already the default blackPoint then there is
  38632. // no need to do compensation.
  38633. if (sourceBlackPoint[0] === 0 &&
  38634. sourceBlackPoint[1] === 0 &&
  38635. sourceBlackPoint[2] === 0) {
  38636. result[0] = XYZ_Flat[0];
  38637. result[1] = XYZ_Flat[1];
  38638. result[2] = XYZ_Flat[2];
  38639. return;
  38640. }
  38641. // For the blackPoint calculation details, please see
  38642. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38643. // AdobeBPC.pdf.
  38644. // The destination blackPoint is the default blackPoint [0, 0, 0].
  38645. var zeroDecodeL = decodeL(0);
  38646. var X_DST = zeroDecodeL;
  38647. var X_SRC = decodeL(sourceBlackPoint[0]);
  38648. var Y_DST = zeroDecodeL;
  38649. var Y_SRC = decodeL(sourceBlackPoint[1]);
  38650. var Z_DST = zeroDecodeL;
  38651. var Z_SRC = decodeL(sourceBlackPoint[2]);
  38652. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  38653. var X_Offset = 1 - X_Scale;
  38654. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  38655. var Y_Offset = 1 - Y_Scale;
  38656. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  38657. var Z_Offset = 1 - Z_Scale;
  38658. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  38659. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  38660. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  38661. }
  38662. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  38663. // In case the whitePoint is already flat then there is no need to do
  38664. // normalization.
  38665. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  38666. result[0] = XYZ_In[0];
  38667. result[1] = XYZ_In[1];
  38668. result[2] = XYZ_In[2];
  38669. return;
  38670. }
  38671. var LMS = result;
  38672. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38673. var LMS_Flat = tempNormalizeMatrix;
  38674. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  38675. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  38676. }
  38677. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  38678. var LMS = result;
  38679. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38680. var LMS_D65 = tempNormalizeMatrix;
  38681. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  38682. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  38683. }
  38684. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38685. // A, B and C represent a red, green and blue components of a calibrated
  38686. // rgb space.
  38687. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  38688. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  38689. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  38690. // A <---> AGR in the spec
  38691. // B <---> BGG in the spec
  38692. // C <---> CGB in the spec
  38693. var AGR = Math.pow(A, cs.GR);
  38694. var BGG = Math.pow(B, cs.GG);
  38695. var CGB = Math.pow(C, cs.GB);
  38696. // Computes intermediate variables L, M, N as per spec.
  38697. // To decode X, Y, Z values map L, M, N directly to them.
  38698. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  38699. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  38700. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  38701. // The following calculations are based on this document:
  38702. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38703. // AdobeBPC.pdf.
  38704. var XYZ = tempConvertMatrix1;
  38705. XYZ[0] = X;
  38706. XYZ[1] = Y;
  38707. XYZ[2] = Z;
  38708. var XYZ_Flat = tempConvertMatrix2;
  38709. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  38710. var XYZ_Black = tempConvertMatrix1;
  38711. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  38712. var XYZ_D65 = tempConvertMatrix2;
  38713. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  38714. var SRGB = tempConvertMatrix1;
  38715. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  38716. var sR = sRGBTransferFunction(SRGB[0]);
  38717. var sG = sRGBTransferFunction(SRGB[1]);
  38718. var sB = sRGBTransferFunction(SRGB[2]);
  38719. // Convert the values to rgb range [0, 255].
  38720. dest[destOffset] = Math.round(sR * 255);
  38721. dest[destOffset + 1] = Math.round(sG * 255);
  38722. dest[destOffset + 2] = Math.round(sB * 255);
  38723. }
  38724. CalRGBCS.prototype = {
  38725. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  38726. var rgb = new Uint8Array(3);
  38727. this.getRgbItem(src, srcOffset, rgb, 0);
  38728. return rgb;
  38729. },
  38730. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  38731. dest, destOffset) {
  38732. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38733. },
  38734. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  38735. dest, destOffset, bits,
  38736. alpha01) {
  38737. var scale = 1 / ((1 << bits) - 1);
  38738. for (var i = 0; i < count; ++i) {
  38739. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38740. srcOffset += 3;
  38741. destOffset += 3 + alpha01;
  38742. }
  38743. },
  38744. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  38745. return (inputLength * (3 + alpha01) / 3) | 0;
  38746. },
  38747. isPassthrough: ColorSpace.prototype.isPassthrough,
  38748. fillRgb: ColorSpace.prototype.fillRgb,
  38749. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  38750. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38751. },
  38752. usesZeroToOneRange: true
  38753. };
  38754. return CalRGBCS;
  38755. })();
  38756. //
  38757. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  38758. //
  38759. var LabCS = (function LabCSClosure() {
  38760. function LabCS(whitePoint, blackPoint, range) {
  38761. this.name = 'Lab';
  38762. this.numComps = 3;
  38763. this.defaultColor = new Float32Array([0, 0, 0]);
  38764. if (!whitePoint) {
  38765. error('WhitePoint missing - required for color space Lab');
  38766. }
  38767. blackPoint = blackPoint || [0, 0, 0];
  38768. range = range || [-100, 100, -100, 100];
  38769. // Translate args to spec variables
  38770. this.XW = whitePoint[0];
  38771. this.YW = whitePoint[1];
  38772. this.ZW = whitePoint[2];
  38773. this.amin = range[0];
  38774. this.amax = range[1];
  38775. this.bmin = range[2];
  38776. this.bmax = range[3];
  38777. // These are here just for completeness - the spec doesn't offer any
  38778. // formulas that use BlackPoint in Lab
  38779. this.XB = blackPoint[0];
  38780. this.YB = blackPoint[1];
  38781. this.ZB = blackPoint[2];
  38782. // Validate vars as per spec
  38783. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38784. error('Invalid WhitePoint components, no fallback available');
  38785. }
  38786. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38787. info('Invalid BlackPoint, falling back to default');
  38788. this.XB = this.YB = this.ZB = 0;
  38789. }
  38790. if (this.amin > this.amax || this.bmin > this.bmax) {
  38791. info('Invalid Range, falling back to defaults');
  38792. this.amin = -100;
  38793. this.amax = 100;
  38794. this.bmin = -100;
  38795. this.bmax = 100;
  38796. }
  38797. }
  38798. // Function g(x) from spec
  38799. function fn_g(x) {
  38800. if (x >= 6 / 29) {
  38801. return x * x * x;
  38802. } else {
  38803. return (108 / 841) * (x - 4 / 29);
  38804. }
  38805. }
  38806. function decode(value, high1, low2, high2) {
  38807. return low2 + (value) * (high2 - low2) / (high1);
  38808. }
  38809. // If decoding is needed maxVal should be 2^bits per component - 1.
  38810. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  38811. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  38812. // not the usual [0, 1]. If a command like setFillColor is used the src
  38813. // values will already be within the correct range. However, if we are
  38814. // converting an image we have to map the values to the correct range given
  38815. // above.
  38816. // Ls,as,bs <---> L*,a*,b* in the spec
  38817. var Ls = src[srcOffset];
  38818. var as = src[srcOffset + 1];
  38819. var bs = src[srcOffset + 2];
  38820. if (maxVal !== false) {
  38821. Ls = decode(Ls, maxVal, 0, 100);
  38822. as = decode(as, maxVal, cs.amin, cs.amax);
  38823. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  38824. }
  38825. // Adjust limits of 'as' and 'bs'
  38826. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  38827. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  38828. // Computes intermediate variables X,Y,Z as per spec
  38829. var M = (Ls + 16) / 116;
  38830. var L = M + (as / 500);
  38831. var N = M - (bs / 200);
  38832. var X = cs.XW * fn_g(L);
  38833. var Y = cs.YW * fn_g(M);
  38834. var Z = cs.ZW * fn_g(N);
  38835. var r, g, b;
  38836. // Using different conversions for D50 and D65 white points,
  38837. // per http://www.color.org/srgb.pdf
  38838. if (cs.ZW < 1) {
  38839. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  38840. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  38841. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  38842. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  38843. } else {
  38844. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  38845. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  38846. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  38847. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  38848. }
  38849. // clamp color values to [0,1] range then convert to [0,255] range.
  38850. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  38851. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  38852. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  38853. }
  38854. LabCS.prototype = {
  38855. getRgb: ColorSpace.prototype.getRgb,
  38856. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  38857. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  38858. },
  38859. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  38860. dest, destOffset, bits,
  38861. alpha01) {
  38862. var maxVal = (1 << bits) - 1;
  38863. for (var i = 0; i < count; i++) {
  38864. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  38865. srcOffset += 3;
  38866. destOffset += 3 + alpha01;
  38867. }
  38868. },
  38869. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  38870. return (inputLength * (3 + alpha01) / 3) | 0;
  38871. },
  38872. isPassthrough: ColorSpace.prototype.isPassthrough,
  38873. fillRgb: ColorSpace.prototype.fillRgb,
  38874. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  38875. // XXX: Decoding is handled with the lab conversion because of the strange
  38876. // ranges that are used.
  38877. return true;
  38878. },
  38879. usesZeroToOneRange: false
  38880. };
  38881. return LabCS;
  38882. })();
  38883. // TODO refactor to remove dependency on image.js
  38884. function _setCoreImage(coreImage_) {
  38885. coreImage = coreImage_;
  38886. PDFImage = coreImage_.PDFImage;
  38887. }
  38888. exports._setCoreImage = _setCoreImage;
  38889. exports.ColorSpace = ColorSpace;
  38890. // TODO refactor to remove dependency on colorspace.js
  38891. coreStream._setCoreColorSpace(exports);
  38892. }));
  38893. (function (root, factory) {
  38894. {
  38895. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  38896. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  38897. root.pdfjsCoreJpx);
  38898. }
  38899. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  38900. coreStream, coreJpx) {
  38901. var ImageKind = sharedUtil.ImageKind;
  38902. var assert = sharedUtil.assert;
  38903. var error = sharedUtil.error;
  38904. var info = sharedUtil.info;
  38905. var isArray = sharedUtil.isArray;
  38906. var warn = sharedUtil.warn;
  38907. var Name = corePrimitives.Name;
  38908. var isStream = corePrimitives.isStream;
  38909. var ColorSpace = coreColorSpace.ColorSpace;
  38910. var DecodeStream = coreStream.DecodeStream;
  38911. var Stream = coreStream.Stream;
  38912. var JpegStream = coreStream.JpegStream;
  38913. var JpxImage = coreJpx.JpxImage;
  38914. var PDFImage = (function PDFImageClosure() {
  38915. /**
  38916. * Decode the image in the main thread if it supported. Resovles the promise
  38917. * when the image data is ready.
  38918. */
  38919. function handleImageData(handler, xref, res, image) {
  38920. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  38921. // For natively supported jpegs send them to the main thread for decoding.
  38922. var dict = image.dict;
  38923. var colorSpace = dict.get('ColorSpace', 'CS');
  38924. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  38925. var numComps = colorSpace.numComps;
  38926. var decodePromise = handler.sendWithPromise('JpegDecode',
  38927. [image.getIR(), numComps]);
  38928. return decodePromise.then(function (message) {
  38929. var data = message.data;
  38930. return new Stream(data, 0, data.length, image.dict);
  38931. });
  38932. } else {
  38933. return Promise.resolve(image);
  38934. }
  38935. }
  38936. /**
  38937. * Decode and clamp a value. The formula is different from the spec because we
  38938. * don't decode to float range [0,1], we decode it in the [0,max] range.
  38939. */
  38940. function decodeAndClamp(value, addend, coefficient, max) {
  38941. value = addend + value * coefficient;
  38942. // Clamp the value to the range
  38943. return (value < 0 ? 0 : (value > max ? max : value));
  38944. }
  38945. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  38946. this.image = image;
  38947. var dict = image.dict;
  38948. if (dict.has('Filter')) {
  38949. var filter = dict.get('Filter').name;
  38950. if (filter === 'JPXDecode') {
  38951. var jpxImage = new JpxImage();
  38952. jpxImage.parseImageProperties(image.stream);
  38953. image.stream.reset();
  38954. image.bitsPerComponent = jpxImage.bitsPerComponent;
  38955. image.numComps = jpxImage.componentsCount;
  38956. } else if (filter === 'JBIG2Decode') {
  38957. image.bitsPerComponent = 1;
  38958. image.numComps = 1;
  38959. }
  38960. }
  38961. // TODO cache rendered images?
  38962. this.width = dict.get('Width', 'W');
  38963. this.height = dict.get('Height', 'H');
  38964. if (this.width < 1 || this.height < 1) {
  38965. error('Invalid image width: ' + this.width + ' or height: ' +
  38966. this.height);
  38967. }
  38968. this.interpolate = dict.get('Interpolate', 'I') || false;
  38969. this.imageMask = dict.get('ImageMask', 'IM') || false;
  38970. this.matte = dict.get('Matte') || false;
  38971. var bitsPerComponent = image.bitsPerComponent;
  38972. if (!bitsPerComponent) {
  38973. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  38974. if (!bitsPerComponent) {
  38975. if (this.imageMask) {
  38976. bitsPerComponent = 1;
  38977. } else {
  38978. error('Bits per component missing in image: ' + this.imageMask);
  38979. }
  38980. }
  38981. }
  38982. this.bpc = bitsPerComponent;
  38983. if (!this.imageMask) {
  38984. var colorSpace = dict.get('ColorSpace', 'CS');
  38985. if (!colorSpace) {
  38986. info('JPX images (which do not require color spaces)');
  38987. switch (image.numComps) {
  38988. case 1:
  38989. colorSpace = Name.get('DeviceGray');
  38990. break;
  38991. case 3:
  38992. colorSpace = Name.get('DeviceRGB');
  38993. break;
  38994. case 4:
  38995. colorSpace = Name.get('DeviceCMYK');
  38996. break;
  38997. default:
  38998. error('JPX images with ' + this.numComps +
  38999. ' color components not supported.');
  39000. }
  39001. }
  39002. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39003. this.numComps = this.colorSpace.numComps;
  39004. }
  39005. this.decode = dict.get('Decode', 'D');
  39006. this.needsDecode = false;
  39007. if (this.decode &&
  39008. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39009. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39010. this.needsDecode = true;
  39011. // Do some preprocessing to avoid more math.
  39012. var max = (1 << bitsPerComponent) - 1;
  39013. this.decodeCoefficients = [];
  39014. this.decodeAddends = [];
  39015. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39016. var dmin = this.decode[i];
  39017. var dmax = this.decode[i + 1];
  39018. this.decodeCoefficients[j] = dmax - dmin;
  39019. this.decodeAddends[j] = max * dmin;
  39020. }
  39021. }
  39022. if (smask) {
  39023. this.smask = new PDFImage(xref, res, smask, false);
  39024. } else if (mask) {
  39025. if (isStream(mask)) {
  39026. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39027. if (!imageMask) {
  39028. warn('Ignoring /Mask in image without /ImageMask.');
  39029. } else {
  39030. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39031. }
  39032. } else {
  39033. // Color key mask (just an array).
  39034. this.mask = mask;
  39035. }
  39036. }
  39037. }
  39038. /**
  39039. * Handles processing of image data and returns the Promise that is resolved
  39040. * with a PDFImage when the image is ready to be used.
  39041. */
  39042. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39043. res, image, inline) {
  39044. var imagePromise = handleImageData(handler, xref, res, image);
  39045. var smaskPromise;
  39046. var maskPromise;
  39047. var smask = image.dict.get('SMask');
  39048. var mask = image.dict.get('Mask');
  39049. if (smask) {
  39050. smaskPromise = handleImageData(handler, xref, res, smask);
  39051. maskPromise = Promise.resolve(null);
  39052. } else {
  39053. smaskPromise = Promise.resolve(null);
  39054. if (mask) {
  39055. if (isStream(mask)) {
  39056. maskPromise = handleImageData(handler, xref, res, mask);
  39057. } else if (isArray(mask)) {
  39058. maskPromise = Promise.resolve(mask);
  39059. } else {
  39060. warn('Unsupported mask format.');
  39061. maskPromise = Promise.resolve(null);
  39062. }
  39063. } else {
  39064. maskPromise = Promise.resolve(null);
  39065. }
  39066. }
  39067. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39068. function(results) {
  39069. var imageData = results[0];
  39070. var smaskData = results[1];
  39071. var maskData = results[2];
  39072. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39073. });
  39074. };
  39075. /**
  39076. * Resize an image using the nearest neighbor algorithm. Currently only
  39077. * supports one and three component images.
  39078. * @param {TypedArray} pixels The original image with one component.
  39079. * @param {Number} bpc Number of bits per component.
  39080. * @param {Number} components Number of color components, 1 or 3 is supported.
  39081. * @param {Number} w1 Original width.
  39082. * @param {Number} h1 Original height.
  39083. * @param {Number} w2 New width.
  39084. * @param {Number} h2 New height.
  39085. * @param {TypedArray} dest (Optional) The destination buffer.
  39086. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39087. * @return {TypedArray} Resized image data.
  39088. */
  39089. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39090. w1, h1, w2, h2, dest, alpha01) {
  39091. if (components !== 1 && components !== 3) {
  39092. error('Unsupported component count for resizing.');
  39093. }
  39094. var length = w2 * h2 * components;
  39095. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39096. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39097. var xRatio = w1 / w2;
  39098. var yRatio = h1 / h2;
  39099. var i, j, py, newIndex = 0, oldIndex;
  39100. var xScaled = new Uint16Array(w2);
  39101. var w1Scanline = w1 * components;
  39102. if (alpha01 !== 1) {
  39103. alpha01 = 0;
  39104. }
  39105. for (j = 0; j < w2; j++) {
  39106. xScaled[j] = Math.floor(j * xRatio) * components;
  39107. }
  39108. if (components === 1) {
  39109. for (i = 0; i < h2; i++) {
  39110. py = Math.floor(i * yRatio) * w1Scanline;
  39111. for (j = 0; j < w2; j++) {
  39112. oldIndex = py + xScaled[j];
  39113. temp[newIndex++] = pixels[oldIndex];
  39114. }
  39115. }
  39116. } else if (components === 3) {
  39117. for (i = 0; i < h2; i++) {
  39118. py = Math.floor(i * yRatio) * w1Scanline;
  39119. for (j = 0; j < w2; j++) {
  39120. oldIndex = py + xScaled[j];
  39121. temp[newIndex++] = pixels[oldIndex++];
  39122. temp[newIndex++] = pixels[oldIndex++];
  39123. temp[newIndex++] = pixels[oldIndex++];
  39124. newIndex += alpha01;
  39125. }
  39126. }
  39127. }
  39128. return temp;
  39129. };
  39130. PDFImage.createMask =
  39131. function PDFImage_createMask(imgArray, width, height,
  39132. imageIsFromDecodeStream, inverseDecode) {
  39133. // |imgArray| might not contain full data for every pixel of the mask, so
  39134. // we need to distinguish between |computedLength| and |actualLength|.
  39135. // In particular, if inverseDecode is true, then the array we return must
  39136. // have a length of |computedLength|.
  39137. var computedLength = ((width + 7) >> 3) * height;
  39138. var actualLength = imgArray.byteLength;
  39139. var haveFullData = computedLength === actualLength;
  39140. var data, i;
  39141. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39142. // imgArray came from a DecodeStream and its data is in an appropriate
  39143. // form, so we can just transfer it.
  39144. data = imgArray;
  39145. } else if (!inverseDecode) {
  39146. data = new Uint8Array(actualLength);
  39147. data.set(imgArray);
  39148. } else {
  39149. data = new Uint8Array(computedLength);
  39150. data.set(imgArray);
  39151. for (i = actualLength; i < computedLength; i++) {
  39152. data[i] = 0xff;
  39153. }
  39154. }
  39155. // If necessary, invert the original mask data (but not any extra we might
  39156. // have added above). It's safe to modify the array -- whether it's the
  39157. // original or a copy, we're about to transfer it anyway, so nothing else
  39158. // in this thread can be relying on its contents.
  39159. if (inverseDecode) {
  39160. for (i = 0; i < actualLength; i++) {
  39161. data[i] = ~data[i];
  39162. }
  39163. }
  39164. return {data: data, width: width, height: height};
  39165. };
  39166. PDFImage.prototype = {
  39167. get drawWidth() {
  39168. return Math.max(this.width,
  39169. this.smask && this.smask.width || 0,
  39170. this.mask && this.mask.width || 0);
  39171. },
  39172. get drawHeight() {
  39173. return Math.max(this.height,
  39174. this.smask && this.smask.height || 0,
  39175. this.mask && this.mask.height || 0);
  39176. },
  39177. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39178. var bpc = this.bpc;
  39179. var numComps = this.numComps;
  39180. var decodeAddends = this.decodeAddends;
  39181. var decodeCoefficients = this.decodeCoefficients;
  39182. var max = (1 << bpc) - 1;
  39183. var i, ii;
  39184. if (bpc === 1) {
  39185. // If the buffer needed decode that means it just needs to be inverted.
  39186. for (i = 0, ii = buffer.length; i < ii; i++) {
  39187. buffer[i] = +!(buffer[i]);
  39188. }
  39189. return;
  39190. }
  39191. var index = 0;
  39192. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39193. for (var j = 0; j < numComps; j++) {
  39194. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39195. decodeCoefficients[j], max);
  39196. index++;
  39197. }
  39198. }
  39199. },
  39200. getComponents: function PDFImage_getComponents(buffer) {
  39201. var bpc = this.bpc;
  39202. // This image doesn't require any extra work.
  39203. if (bpc === 8) {
  39204. return buffer;
  39205. }
  39206. var width = this.width;
  39207. var height = this.height;
  39208. var numComps = this.numComps;
  39209. var length = width * height * numComps;
  39210. var bufferPos = 0;
  39211. var output = (bpc <= 8 ? new Uint8Array(length) :
  39212. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39213. var rowComps = width * numComps;
  39214. var max = (1 << bpc) - 1;
  39215. var i = 0, ii, buf;
  39216. if (bpc === 1) {
  39217. // Optimization for reading 1 bpc images.
  39218. var mask, loop1End, loop2End;
  39219. for (var j = 0; j < height; j++) {
  39220. loop1End = i + (rowComps & ~7);
  39221. loop2End = i + rowComps;
  39222. // unroll loop for all full bytes
  39223. while (i < loop1End) {
  39224. buf = buffer[bufferPos++];
  39225. output[i] = (buf >> 7) & 1;
  39226. output[i + 1] = (buf >> 6) & 1;
  39227. output[i + 2] = (buf >> 5) & 1;
  39228. output[i + 3] = (buf >> 4) & 1;
  39229. output[i + 4] = (buf >> 3) & 1;
  39230. output[i + 5] = (buf >> 2) & 1;
  39231. output[i + 6] = (buf >> 1) & 1;
  39232. output[i + 7] = buf & 1;
  39233. i += 8;
  39234. }
  39235. // handle remaing bits
  39236. if (i < loop2End) {
  39237. buf = buffer[bufferPos++];
  39238. mask = 128;
  39239. while (i < loop2End) {
  39240. output[i++] = +!!(buf & mask);
  39241. mask >>= 1;
  39242. }
  39243. }
  39244. }
  39245. } else {
  39246. // The general case that handles all other bpc values.
  39247. var bits = 0;
  39248. buf = 0;
  39249. for (i = 0, ii = length; i < ii; ++i) {
  39250. if (i % rowComps === 0) {
  39251. buf = 0;
  39252. bits = 0;
  39253. }
  39254. while (bits < bpc) {
  39255. buf = (buf << 8) | buffer[bufferPos++];
  39256. bits += 8;
  39257. }
  39258. var remainingBits = bits - bpc;
  39259. var value = buf >> remainingBits;
  39260. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39261. buf = buf & ((1 << remainingBits) - 1);
  39262. bits = remainingBits;
  39263. }
  39264. }
  39265. return output;
  39266. },
  39267. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39268. actualHeight, image) {
  39269. var smask = this.smask;
  39270. var mask = this.mask;
  39271. var alphaBuf, sw, sh, i, ii, j;
  39272. if (smask) {
  39273. sw = smask.width;
  39274. sh = smask.height;
  39275. alphaBuf = new Uint8Array(sw * sh);
  39276. smask.fillGrayBuffer(alphaBuf);
  39277. if (sw !== width || sh !== height) {
  39278. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39279. height);
  39280. }
  39281. } else if (mask) {
  39282. if (mask instanceof PDFImage) {
  39283. sw = mask.width;
  39284. sh = mask.height;
  39285. alphaBuf = new Uint8Array(sw * sh);
  39286. mask.numComps = 1;
  39287. mask.fillGrayBuffer(alphaBuf);
  39288. // Need to invert values in rgbaBuf
  39289. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39290. alphaBuf[i] = 255 - alphaBuf[i];
  39291. }
  39292. if (sw !== width || sh !== height) {
  39293. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39294. height);
  39295. }
  39296. } else if (isArray(mask)) {
  39297. // Color key mask: if any of the compontents are outside the range
  39298. // then they should be painted.
  39299. alphaBuf = new Uint8Array(width * height);
  39300. var numComps = this.numComps;
  39301. for (i = 0, ii = width * height; i < ii; ++i) {
  39302. var opacity = 0;
  39303. var imageOffset = i * numComps;
  39304. for (j = 0; j < numComps; ++j) {
  39305. var color = image[imageOffset + j];
  39306. var maskOffset = j * 2;
  39307. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39308. opacity = 255;
  39309. break;
  39310. }
  39311. }
  39312. alphaBuf[i] = opacity;
  39313. }
  39314. } else {
  39315. error('Unknown mask format.');
  39316. }
  39317. }
  39318. if (alphaBuf) {
  39319. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39320. rgbaBuf[j] = alphaBuf[i];
  39321. }
  39322. } else {
  39323. // No mask.
  39324. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39325. rgbaBuf[j] = 255;
  39326. }
  39327. }
  39328. },
  39329. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39330. var matte = this.smask && this.smask.matte;
  39331. if (!matte) {
  39332. return;
  39333. }
  39334. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39335. var matteR = matteRgb[0];
  39336. var matteG = matteRgb[1];
  39337. var matteB = matteRgb[2];
  39338. var length = width * height * 4;
  39339. var r, g, b;
  39340. for (var i = 0; i < length; i += 4) {
  39341. var alpha = buffer[i + 3];
  39342. if (alpha === 0) {
  39343. // according formula we have to get Infinity in all components
  39344. // making it white (typical paper color) should be okay
  39345. buffer[i] = 255;
  39346. buffer[i + 1] = 255;
  39347. buffer[i + 2] = 255;
  39348. continue;
  39349. }
  39350. var k = 255 / alpha;
  39351. r = (buffer[i] - matteR) * k + matteR;
  39352. g = (buffer[i + 1] - matteG) * k + matteG;
  39353. b = (buffer[i + 2] - matteB) * k + matteB;
  39354. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39355. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39356. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39357. }
  39358. },
  39359. createImageData: function PDFImage_createImageData(forceRGBA) {
  39360. var drawWidth = this.drawWidth;
  39361. var drawHeight = this.drawHeight;
  39362. var imgData = { // other fields are filled in below
  39363. width: drawWidth,
  39364. height: drawHeight
  39365. };
  39366. var numComps = this.numComps;
  39367. var originalWidth = this.width;
  39368. var originalHeight = this.height;
  39369. var bpc = this.bpc;
  39370. // Rows start at byte boundary.
  39371. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39372. var imgArray;
  39373. if (!forceRGBA) {
  39374. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39375. // without any complications, we pass a same-sized copy to the main
  39376. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39377. // of memory for many scanned documents. It's also much faster.
  39378. //
  39379. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39380. // complications, we avoid expanding by 1.333x to RGBA form.
  39381. var kind;
  39382. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39383. kind = ImageKind.GRAYSCALE_1BPP;
  39384. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39385. !this.needsDecode) {
  39386. kind = ImageKind.RGB_24BPP;
  39387. }
  39388. if (kind && !this.smask && !this.mask &&
  39389. drawWidth === originalWidth && drawHeight === originalHeight) {
  39390. imgData.kind = kind;
  39391. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39392. // If imgArray came from a DecodeStream, we're safe to transfer it
  39393. // (and thus detach its underlying buffer) because it will constitute
  39394. // the entire DecodeStream's data. But if it came from a Stream, we
  39395. // need to copy it because it'll only be a portion of the Stream's
  39396. // data, and the rest will be read later on.
  39397. if (this.image instanceof DecodeStream) {
  39398. imgData.data = imgArray;
  39399. } else {
  39400. var newArray = new Uint8Array(imgArray.length);
  39401. newArray.set(imgArray);
  39402. imgData.data = newArray;
  39403. }
  39404. if (this.needsDecode) {
  39405. // Invert the buffer (which must be grayscale if we reached here).
  39406. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39407. var buffer = imgData.data;
  39408. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39409. buffer[i] ^= 0xff;
  39410. }
  39411. }
  39412. return imgData;
  39413. }
  39414. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39415. (this.colorSpace.name === 'DeviceGray' ||
  39416. this.colorSpace.name === 'DeviceRGB' ||
  39417. this.colorSpace.name === 'DeviceCMYK')) {
  39418. imgData.kind = ImageKind.RGB_24BPP;
  39419. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39420. drawWidth, drawHeight, true);
  39421. return imgData;
  39422. }
  39423. }
  39424. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39425. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39426. var actualHeight = 0 | (imgArray.length / rowBytes *
  39427. drawHeight / originalHeight);
  39428. var comps = this.getComponents(imgArray);
  39429. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39430. // more compact RGB_24BPP form if allowable.
  39431. var alpha01, maybeUndoPreblend;
  39432. if (!forceRGBA && !this.smask && !this.mask) {
  39433. imgData.kind = ImageKind.RGB_24BPP;
  39434. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39435. alpha01 = 0;
  39436. maybeUndoPreblend = false;
  39437. } else {
  39438. imgData.kind = ImageKind.RGBA_32BPP;
  39439. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39440. alpha01 = 1;
  39441. maybeUndoPreblend = true;
  39442. // Color key masking (opacity) must be performed before decoding.
  39443. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39444. comps);
  39445. }
  39446. if (this.needsDecode) {
  39447. this.decodeBuffer(comps);
  39448. }
  39449. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39450. drawWidth, drawHeight, actualHeight, bpc, comps,
  39451. alpha01);
  39452. if (maybeUndoPreblend) {
  39453. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39454. }
  39455. return imgData;
  39456. },
  39457. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39458. var numComps = this.numComps;
  39459. if (numComps !== 1) {
  39460. error('Reading gray scale from a color image: ' + numComps);
  39461. }
  39462. var width = this.width;
  39463. var height = this.height;
  39464. var bpc = this.bpc;
  39465. // rows start at byte boundary
  39466. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39467. var imgArray = this.getImageBytes(height * rowBytes);
  39468. var comps = this.getComponents(imgArray);
  39469. var i, length;
  39470. if (bpc === 1) {
  39471. // inline decoding (= inversion) for 1 bpc images
  39472. length = width * height;
  39473. if (this.needsDecode) {
  39474. // invert and scale to {0, 255}
  39475. for (i = 0; i < length; ++i) {
  39476. buffer[i] = (comps[i] - 1) & 255;
  39477. }
  39478. } else {
  39479. // scale to {0, 255}
  39480. for (i = 0; i < length; ++i) {
  39481. buffer[i] = (-comps[i]) & 255;
  39482. }
  39483. }
  39484. return;
  39485. }
  39486. if (this.needsDecode) {
  39487. this.decodeBuffer(comps);
  39488. }
  39489. length = width * height;
  39490. // we aren't using a colorspace so we need to scale the value
  39491. var scale = 255 / ((1 << bpc) - 1);
  39492. for (i = 0; i < length; ++i) {
  39493. buffer[i] = (scale * comps[i]) | 0;
  39494. }
  39495. },
  39496. getImageBytes: function PDFImage_getImageBytes(length,
  39497. drawWidth, drawHeight,
  39498. forceRGB) {
  39499. this.image.reset();
  39500. this.image.drawWidth = drawWidth || this.width;
  39501. this.image.drawHeight = drawHeight || this.height;
  39502. this.image.forceRGB = !!forceRGB;
  39503. return this.image.getBytes(length);
  39504. }
  39505. };
  39506. return PDFImage;
  39507. })();
  39508. exports.PDFImage = PDFImage;
  39509. // TODO refactor to remove dependency on colorspace.js
  39510. coreColorSpace._setCoreImage(exports);
  39511. }));
  39512. (function (root, factory) {
  39513. {
  39514. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  39515. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  39516. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  39517. }
  39518. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  39519. coreChunkedStream, coreColorSpace) {
  39520. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39521. var MissingDataException = sharedUtil.MissingDataException;
  39522. var XRefParseException = sharedUtil.XRefParseException;
  39523. var assert = sharedUtil.assert;
  39524. var bytesToString = sharedUtil.bytesToString;
  39525. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39526. var error = sharedUtil.error;
  39527. var info = sharedUtil.info;
  39528. var isArray = sharedUtil.isArray;
  39529. var isInt = sharedUtil.isInt;
  39530. var isString = sharedUtil.isString;
  39531. var shadow = sharedUtil.shadow;
  39532. var stringToPDFString = sharedUtil.stringToPDFString;
  39533. var stringToUTF8String = sharedUtil.stringToUTF8String;
  39534. var warn = sharedUtil.warn;
  39535. var isValidUrl = sharedUtil.isValidUrl;
  39536. var Util = sharedUtil.Util;
  39537. var Ref = corePrimitives.Ref;
  39538. var RefSet = corePrimitives.RefSet;
  39539. var RefSetCache = corePrimitives.RefSetCache;
  39540. var isName = corePrimitives.isName;
  39541. var isCmd = corePrimitives.isCmd;
  39542. var isDict = corePrimitives.isDict;
  39543. var isRef = corePrimitives.isRef;
  39544. var isStream = corePrimitives.isStream;
  39545. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  39546. var Lexer = coreParser.Lexer;
  39547. var Parser = coreParser.Parser;
  39548. var ChunkedStream = coreChunkedStream.ChunkedStream;
  39549. var ColorSpace = coreColorSpace.ColorSpace;
  39550. var Catalog = (function CatalogClosure() {
  39551. function Catalog(pdfManager, xref, pageFactory) {
  39552. this.pdfManager = pdfManager;
  39553. this.xref = xref;
  39554. this.catDict = xref.getCatalogObj();
  39555. this.fontCache = new RefSetCache();
  39556. assert(isDict(this.catDict),
  39557. 'catalog object is not a dictionary');
  39558. // TODO refactor to move getPage() to the PDFDocument.
  39559. this.pageFactory = pageFactory;
  39560. this.pagePromises = [];
  39561. }
  39562. Catalog.prototype = {
  39563. get metadata() {
  39564. var streamRef = this.catDict.getRaw('Metadata');
  39565. if (!isRef(streamRef)) {
  39566. return shadow(this, 'metadata', null);
  39567. }
  39568. var encryptMetadata = (!this.xref.encrypt ? false :
  39569. this.xref.encrypt.encryptMetadata);
  39570. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  39571. var metadata;
  39572. if (stream && isDict(stream.dict)) {
  39573. var type = stream.dict.get('Type');
  39574. var subtype = stream.dict.get('Subtype');
  39575. if (isName(type) && isName(subtype) &&
  39576. type.name === 'Metadata' && subtype.name === 'XML') {
  39577. // XXX: This should examine the charset the XML document defines,
  39578. // however since there are currently no real means to decode
  39579. // arbitrary charsets, let's just hope that the author of the PDF
  39580. // was reasonable enough to stick with the XML default charset,
  39581. // which is UTF-8.
  39582. try {
  39583. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  39584. } catch (e) {
  39585. info('Skipping invalid metadata.');
  39586. }
  39587. }
  39588. }
  39589. return shadow(this, 'metadata', metadata);
  39590. },
  39591. get toplevelPagesDict() {
  39592. var pagesObj = this.catDict.get('Pages');
  39593. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  39594. // shadow the prototype getter
  39595. return shadow(this, 'toplevelPagesDict', pagesObj);
  39596. },
  39597. get documentOutline() {
  39598. var obj = null;
  39599. try {
  39600. obj = this.readDocumentOutline();
  39601. } catch (ex) {
  39602. if (ex instanceof MissingDataException) {
  39603. throw ex;
  39604. }
  39605. warn('Unable to read document outline');
  39606. }
  39607. return shadow(this, 'documentOutline', obj);
  39608. },
  39609. readDocumentOutline: function Catalog_readDocumentOutline() {
  39610. var obj = this.catDict.get('Outlines');
  39611. if (!isDict(obj)) {
  39612. return null;
  39613. }
  39614. obj = obj.getRaw('First');
  39615. if (!isRef(obj)) {
  39616. return null;
  39617. }
  39618. var root = { items: [] };
  39619. var queue = [{obj: obj, parent: root}];
  39620. // To avoid recursion, keep track of the already processed items.
  39621. var processed = new RefSet();
  39622. processed.put(obj);
  39623. var xref = this.xref, blackColor = new Uint8Array(3);
  39624. while (queue.length > 0) {
  39625. var i = queue.shift();
  39626. var outlineDict = xref.fetchIfRef(i.obj);
  39627. if (outlineDict === null) {
  39628. continue;
  39629. }
  39630. assert(outlineDict.has('Title'), 'Invalid outline item');
  39631. var actionDict = outlineDict.get('A'), dest = null, url = null;
  39632. if (actionDict) {
  39633. var destEntry = actionDict.get('D');
  39634. if (destEntry) {
  39635. dest = destEntry;
  39636. } else {
  39637. var uriEntry = actionDict.get('URI');
  39638. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  39639. url = uriEntry;
  39640. }
  39641. }
  39642. } else if (outlineDict.has('Dest')) {
  39643. dest = outlineDict.getRaw('Dest');
  39644. if (isName(dest)) {
  39645. dest = dest.name;
  39646. }
  39647. }
  39648. var title = outlineDict.get('Title');
  39649. var flags = outlineDict.get('F') || 0;
  39650. var color = outlineDict.get('C'), rgbColor = blackColor;
  39651. // We only need to parse the color when it's valid, and non-default.
  39652. if (isArray(color) && color.length === 3 &&
  39653. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  39654. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  39655. }
  39656. var outlineItem = {
  39657. dest: dest,
  39658. url: url,
  39659. title: stringToPDFString(title),
  39660. color: rgbColor,
  39661. count: outlineDict.get('Count'),
  39662. bold: !!(flags & 2),
  39663. italic: !!(flags & 1),
  39664. items: []
  39665. };
  39666. i.parent.items.push(outlineItem);
  39667. obj = outlineDict.getRaw('First');
  39668. if (isRef(obj) && !processed.has(obj)) {
  39669. queue.push({obj: obj, parent: outlineItem});
  39670. processed.put(obj);
  39671. }
  39672. obj = outlineDict.getRaw('Next');
  39673. if (isRef(obj) && !processed.has(obj)) {
  39674. queue.push({obj: obj, parent: i.parent});
  39675. processed.put(obj);
  39676. }
  39677. }
  39678. return (root.items.length > 0 ? root.items : null);
  39679. },
  39680. get numPages() {
  39681. var obj = this.toplevelPagesDict.get('Count');
  39682. assert(
  39683. isInt(obj),
  39684. 'page count in top level pages object is not an integer'
  39685. );
  39686. // shadow the prototype getter
  39687. return shadow(this, 'num', obj);
  39688. },
  39689. get destinations() {
  39690. function fetchDestination(dest) {
  39691. return isDict(dest) ? dest.get('D') : dest;
  39692. }
  39693. var xref = this.xref;
  39694. var dests = {}, nameTreeRef, nameDictionaryRef;
  39695. var obj = this.catDict.get('Names');
  39696. if (obj && obj.has('Dests')) {
  39697. nameTreeRef = obj.getRaw('Dests');
  39698. } else if (this.catDict.has('Dests')) {
  39699. nameDictionaryRef = this.catDict.get('Dests');
  39700. }
  39701. if (nameDictionaryRef) {
  39702. // reading simple destination dictionary
  39703. obj = nameDictionaryRef;
  39704. obj.forEach(function catalogForEach(key, value) {
  39705. if (!value) {
  39706. return;
  39707. }
  39708. dests[key] = fetchDestination(value);
  39709. });
  39710. }
  39711. if (nameTreeRef) {
  39712. var nameTree = new NameTree(nameTreeRef, xref);
  39713. var names = nameTree.getAll();
  39714. for (var name in names) {
  39715. dests[name] = fetchDestination(names[name]);
  39716. }
  39717. }
  39718. return shadow(this, 'destinations', dests);
  39719. },
  39720. getDestination: function Catalog_getDestination(destinationId) {
  39721. function fetchDestination(dest) {
  39722. return isDict(dest) ? dest.get('D') : dest;
  39723. }
  39724. var xref = this.xref;
  39725. var dest = null, nameTreeRef, nameDictionaryRef;
  39726. var obj = this.catDict.get('Names');
  39727. if (obj && obj.has('Dests')) {
  39728. nameTreeRef = obj.getRaw('Dests');
  39729. } else if (this.catDict.has('Dests')) {
  39730. nameDictionaryRef = this.catDict.get('Dests');
  39731. }
  39732. if (nameDictionaryRef) { // Simple destination dictionary.
  39733. var value = nameDictionaryRef.get(destinationId);
  39734. if (value) {
  39735. dest = fetchDestination(value);
  39736. }
  39737. }
  39738. if (nameTreeRef) {
  39739. var nameTree = new NameTree(nameTreeRef, xref);
  39740. dest = fetchDestination(nameTree.get(destinationId));
  39741. }
  39742. return dest;
  39743. },
  39744. get pageLabels() {
  39745. var obj = null;
  39746. try {
  39747. obj = this.readPageLabels();
  39748. } catch (ex) {
  39749. if (ex instanceof MissingDataException) {
  39750. throw ex;
  39751. }
  39752. warn('Unable to read page labels.');
  39753. }
  39754. return shadow(this, 'pageLabels', obj);
  39755. },
  39756. readPageLabels: function Catalog_readPageLabels() {
  39757. var obj = this.catDict.getRaw('PageLabels');
  39758. if (!obj) {
  39759. return null;
  39760. }
  39761. var pageLabels = new Array(this.numPages);
  39762. var style = null;
  39763. var prefix = '';
  39764. var start = 1;
  39765. var numberTree = new NumberTree(obj, this.xref);
  39766. var nums = numberTree.getAll();
  39767. var currentLabel = '', currentIndex = 1;
  39768. for (var i = 0, ii = this.numPages; i < ii; i++) {
  39769. if (i in nums) {
  39770. var labelDict = nums[i];
  39771. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  39772. var type = labelDict.get('Type');
  39773. assert(!type || (isName(type) && type.name === 'PageLabel'),
  39774. 'Invalid type in PageLabel dictionary.');
  39775. var s = labelDict.get('S');
  39776. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  39777. style = (s ? s.name : null);
  39778. prefix = labelDict.get('P') || '';
  39779. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  39780. start = labelDict.get('St') || 1;
  39781. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  39782. currentIndex = start;
  39783. }
  39784. switch (style) {
  39785. case 'D':
  39786. currentLabel = currentIndex;
  39787. break;
  39788. case 'R':
  39789. case 'r':
  39790. currentLabel = Util.toRoman(currentIndex, style === 'r');
  39791. break;
  39792. case 'A':
  39793. case 'a':
  39794. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  39795. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  39796. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  39797. var letterIndex = currentIndex - 1;
  39798. var character = String.fromCharCode(baseCharCode +
  39799. (letterIndex % LIMIT));
  39800. var charBuf = [];
  39801. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  39802. charBuf.push(character);
  39803. }
  39804. currentLabel = charBuf.join('');
  39805. break;
  39806. default:
  39807. assert(!style,
  39808. 'Invalid style "' + style + '" in PageLabel dictionary.');
  39809. }
  39810. pageLabels[i] = prefix + currentLabel;
  39811. currentLabel = '';
  39812. currentIndex++;
  39813. }
  39814. return pageLabels;
  39815. },
  39816. get attachments() {
  39817. var xref = this.xref;
  39818. var attachments = null, nameTreeRef;
  39819. var obj = this.catDict.get('Names');
  39820. if (obj) {
  39821. nameTreeRef = obj.getRaw('EmbeddedFiles');
  39822. }
  39823. if (nameTreeRef) {
  39824. var nameTree = new NameTree(nameTreeRef, xref);
  39825. var names = nameTree.getAll();
  39826. for (var name in names) {
  39827. var fs = new FileSpec(names[name], xref);
  39828. if (!attachments) {
  39829. attachments = Object.create(null);
  39830. }
  39831. attachments[stringToPDFString(name)] = fs.serializable;
  39832. }
  39833. }
  39834. return shadow(this, 'attachments', attachments);
  39835. },
  39836. get javaScript() {
  39837. var xref = this.xref;
  39838. var obj = this.catDict.get('Names');
  39839. var javaScript = [];
  39840. function appendIfJavaScriptDict(jsDict) {
  39841. var type = jsDict.get('S');
  39842. if (!isName(type) || type.name !== 'JavaScript') {
  39843. return;
  39844. }
  39845. var js = jsDict.get('JS');
  39846. if (isStream(js)) {
  39847. js = bytesToString(js.getBytes());
  39848. } else if (!isString(js)) {
  39849. return;
  39850. }
  39851. javaScript.push(stringToPDFString(js));
  39852. }
  39853. if (obj && obj.has('JavaScript')) {
  39854. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  39855. var names = nameTree.getAll();
  39856. for (var name in names) {
  39857. // We don't really use the JavaScript right now. This code is
  39858. // defensive so we don't cause errors on document load.
  39859. var jsDict = names[name];
  39860. if (isDict(jsDict)) {
  39861. appendIfJavaScriptDict(jsDict);
  39862. }
  39863. }
  39864. }
  39865. // Append OpenAction actions to javaScript array
  39866. var openactionDict = this.catDict.get('OpenAction');
  39867. if (isDict(openactionDict, 'Action')) {
  39868. var actionType = openactionDict.get('S');
  39869. if (isName(actionType) && actionType.name === 'Named') {
  39870. // The named Print action is not a part of the PDF 1.7 specification,
  39871. // but is supported by many PDF readers/writers (including Adobe's).
  39872. var action = openactionDict.get('N');
  39873. if (isName(action) && action.name === 'Print') {
  39874. javaScript.push('print({});');
  39875. }
  39876. } else {
  39877. appendIfJavaScriptDict(openactionDict);
  39878. }
  39879. }
  39880. return shadow(this, 'javaScript', javaScript);
  39881. },
  39882. cleanup: function Catalog_cleanup() {
  39883. var promises = [];
  39884. this.fontCache.forEach(function (promise) {
  39885. promises.push(promise);
  39886. });
  39887. return Promise.all(promises).then(function (translatedFonts) {
  39888. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  39889. var font = translatedFonts[i].dict;
  39890. delete font.translated;
  39891. }
  39892. this.fontCache.clear();
  39893. }.bind(this));
  39894. },
  39895. getPage: function Catalog_getPage(pageIndex) {
  39896. if (!(pageIndex in this.pagePromises)) {
  39897. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  39898. function (a) {
  39899. var dict = a[0];
  39900. var ref = a[1];
  39901. return this.pageFactory.createPage(pageIndex, dict, ref,
  39902. this.fontCache);
  39903. }.bind(this)
  39904. );
  39905. }
  39906. return this.pagePromises[pageIndex];
  39907. },
  39908. getPageDict: function Catalog_getPageDict(pageIndex) {
  39909. var capability = createPromiseCapability();
  39910. var nodesToVisit = [this.catDict.getRaw('Pages')];
  39911. var currentPageIndex = 0;
  39912. var xref = this.xref;
  39913. var checkAllKids = false;
  39914. function next() {
  39915. while (nodesToVisit.length) {
  39916. var currentNode = nodesToVisit.pop();
  39917. if (isRef(currentNode)) {
  39918. xref.fetchAsync(currentNode).then(function (obj) {
  39919. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  39920. if (pageIndex === currentPageIndex) {
  39921. capability.resolve([obj, currentNode]);
  39922. } else {
  39923. currentPageIndex++;
  39924. next();
  39925. }
  39926. return;
  39927. }
  39928. nodesToVisit.push(obj);
  39929. next();
  39930. }, capability.reject);
  39931. return;
  39932. }
  39933. // Must be a child page dictionary.
  39934. assert(
  39935. isDict(currentNode),
  39936. 'page dictionary kid reference points to wrong type of object'
  39937. );
  39938. var count = currentNode.get('Count');
  39939. // If the current node doesn't have any children, avoid getting stuck
  39940. // in an empty node further down in the tree (see issue5644.pdf).
  39941. if (count === 0) {
  39942. checkAllKids = true;
  39943. }
  39944. // Skip nodes where the page can't be.
  39945. if (currentPageIndex + count <= pageIndex) {
  39946. currentPageIndex += count;
  39947. continue;
  39948. }
  39949. var kids = currentNode.get('Kids');
  39950. assert(isArray(kids), 'page dictionary kids object is not an array');
  39951. if (!checkAllKids && count === kids.length) {
  39952. // Nodes that don't have the page have been skipped and this is the
  39953. // bottom of the tree which means the page requested must be a
  39954. // descendant of this pages node. Ideally we would just resolve the
  39955. // promise with the page ref here, but there is the case where more
  39956. // pages nodes could link to single a page (see issue 3666 pdf). To
  39957. // handle this push it back on the queue so if it is a pages node it
  39958. // will be descended into.
  39959. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  39960. currentPageIndex = pageIndex;
  39961. continue;
  39962. } else {
  39963. for (var last = kids.length - 1; last >= 0; last--) {
  39964. nodesToVisit.push(kids[last]);
  39965. }
  39966. }
  39967. }
  39968. capability.reject('Page index ' + pageIndex + ' not found.');
  39969. }
  39970. next();
  39971. return capability.promise;
  39972. },
  39973. getPageIndex: function Catalog_getPageIndex(ref) {
  39974. // The page tree nodes have the count of all the leaves below them. To get
  39975. // how many pages are before we just have to walk up the tree and keep
  39976. // adding the count of siblings to the left of the node.
  39977. var xref = this.xref;
  39978. function pagesBeforeRef(kidRef) {
  39979. var total = 0;
  39980. var parentRef;
  39981. return xref.fetchAsync(kidRef).then(function (node) {
  39982. if (!node) {
  39983. return null;
  39984. }
  39985. parentRef = node.getRaw('Parent');
  39986. return node.getAsync('Parent');
  39987. }).then(function (parent) {
  39988. if (!parent) {
  39989. return null;
  39990. }
  39991. return parent.getAsync('Kids');
  39992. }).then(function (kids) {
  39993. if (!kids) {
  39994. return null;
  39995. }
  39996. var kidPromises = [];
  39997. var found = false;
  39998. for (var i = 0; i < kids.length; i++) {
  39999. var kid = kids[i];
  40000. assert(isRef(kid), 'kids must be a ref');
  40001. if (kid.num === kidRef.num) {
  40002. found = true;
  40003. break;
  40004. }
  40005. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  40006. if (kid.has('Count')) {
  40007. var count = kid.get('Count');
  40008. total += count;
  40009. } else { // page leaf node
  40010. total++;
  40011. }
  40012. }));
  40013. }
  40014. if (!found) {
  40015. error('kid ref not found in parents kids');
  40016. }
  40017. return Promise.all(kidPromises).then(function () {
  40018. return [total, parentRef];
  40019. });
  40020. });
  40021. }
  40022. var total = 0;
  40023. function next(ref) {
  40024. return pagesBeforeRef(ref).then(function (args) {
  40025. if (!args) {
  40026. return total;
  40027. }
  40028. var count = args[0];
  40029. var parentRef = args[1];
  40030. total += count;
  40031. return next(parentRef);
  40032. });
  40033. }
  40034. return next(ref);
  40035. }
  40036. };
  40037. return Catalog;
  40038. })();
  40039. var XRef = (function XRefClosure() {
  40040. function XRef(stream, password) {
  40041. this.stream = stream;
  40042. this.entries = [];
  40043. this.xrefstms = Object.create(null);
  40044. // prepare the XRef cache
  40045. this.cache = [];
  40046. this.password = password;
  40047. this.stats = {
  40048. streamTypes: [],
  40049. fontTypes: []
  40050. };
  40051. }
  40052. XRef.prototype = {
  40053. setStartXRef: function XRef_setStartXRef(startXRef) {
  40054. // Store the starting positions of xref tables as we process them
  40055. // so we can recover from missing data errors
  40056. this.startXRefQueue = [startXRef];
  40057. },
  40058. parse: function XRef_parse(recoveryMode) {
  40059. var trailerDict;
  40060. if (!recoveryMode) {
  40061. trailerDict = this.readXRef();
  40062. } else {
  40063. warn('Indexing all PDF objects');
  40064. trailerDict = this.indexObjects();
  40065. }
  40066. trailerDict.assignXref(this);
  40067. this.trailer = trailerDict;
  40068. var encrypt = trailerDict.get('Encrypt');
  40069. if (encrypt) {
  40070. var ids = trailerDict.get('ID');
  40071. var fileId = (ids && ids.length) ? ids[0] : '';
  40072. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  40073. this.password);
  40074. }
  40075. // get the root dictionary (catalog) object
  40076. if (!(this.root = trailerDict.get('Root'))) {
  40077. error('Invalid root reference');
  40078. }
  40079. },
  40080. processXRefTable: function XRef_processXRefTable(parser) {
  40081. if (!('tableState' in this)) {
  40082. // Stores state of the table as we process it so we can resume
  40083. // from middle of table in case of missing data error
  40084. this.tableState = {
  40085. entryNum: 0,
  40086. streamPos: parser.lexer.stream.pos,
  40087. parserBuf1: parser.buf1,
  40088. parserBuf2: parser.buf2
  40089. };
  40090. }
  40091. var obj = this.readXRefTable(parser);
  40092. // Sanity check
  40093. if (!isCmd(obj, 'trailer')) {
  40094. error('Invalid XRef table: could not find trailer dictionary');
  40095. }
  40096. // Read trailer dictionary, e.g.
  40097. // trailer
  40098. // << /Size 22
  40099. // /Root 20R
  40100. // /Info 10R
  40101. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  40102. // >>
  40103. // The parser goes through the entire stream << ... >> and provides
  40104. // a getter interface for the key-value table
  40105. var dict = parser.getObj();
  40106. // The pdflib PDF generator can generate a nested trailer dictionary
  40107. if (!isDict(dict) && dict.dict) {
  40108. dict = dict.dict;
  40109. }
  40110. if (!isDict(dict)) {
  40111. error('Invalid XRef table: could not parse trailer dictionary');
  40112. }
  40113. delete this.tableState;
  40114. return dict;
  40115. },
  40116. readXRefTable: function XRef_readXRefTable(parser) {
  40117. // Example of cross-reference table:
  40118. // xref
  40119. // 0 1 <-- subsection header (first obj #, obj count)
  40120. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  40121. // 23 2 <-- subsection header ... and so on ...
  40122. // 0000025518 00002 n
  40123. // 0000025635 00000 n
  40124. // trailer
  40125. // ...
  40126. var stream = parser.lexer.stream;
  40127. var tableState = this.tableState;
  40128. stream.pos = tableState.streamPos;
  40129. parser.buf1 = tableState.parserBuf1;
  40130. parser.buf2 = tableState.parserBuf2;
  40131. // Outer loop is over subsection headers
  40132. var obj;
  40133. while (true) {
  40134. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  40135. if (isCmd(obj = parser.getObj(), 'trailer')) {
  40136. break;
  40137. }
  40138. tableState.firstEntryNum = obj;
  40139. tableState.entryCount = parser.getObj();
  40140. }
  40141. var first = tableState.firstEntryNum;
  40142. var count = tableState.entryCount;
  40143. if (!isInt(first) || !isInt(count)) {
  40144. error('Invalid XRef table: wrong types in subsection header');
  40145. }
  40146. // Inner loop is over objects themselves
  40147. for (var i = tableState.entryNum; i < count; i++) {
  40148. tableState.streamPos = stream.pos;
  40149. tableState.entryNum = i;
  40150. tableState.parserBuf1 = parser.buf1;
  40151. tableState.parserBuf2 = parser.buf2;
  40152. var entry = {};
  40153. entry.offset = parser.getObj();
  40154. entry.gen = parser.getObj();
  40155. var type = parser.getObj();
  40156. if (isCmd(type, 'f')) {
  40157. entry.free = true;
  40158. } else if (isCmd(type, 'n')) {
  40159. entry.uncompressed = true;
  40160. }
  40161. // Validate entry obj
  40162. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  40163. !(entry.free || entry.uncompressed)) {
  40164. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  40165. }
  40166. if (!this.entries[i + first]) {
  40167. this.entries[i + first] = entry;
  40168. }
  40169. }
  40170. tableState.entryNum = 0;
  40171. tableState.streamPos = stream.pos;
  40172. tableState.parserBuf1 = parser.buf1;
  40173. tableState.parserBuf2 = parser.buf2;
  40174. delete tableState.firstEntryNum;
  40175. delete tableState.entryCount;
  40176. }
  40177. // Per issue 3248: hp scanners generate bad XRef
  40178. if (first === 1 && this.entries[1] && this.entries[1].free) {
  40179. // shifting the entries
  40180. this.entries.shift();
  40181. }
  40182. // Sanity check: as per spec, first object must be free
  40183. if (this.entries[0] && !this.entries[0].free) {
  40184. error('Invalid XRef table: unexpected first object');
  40185. }
  40186. return obj;
  40187. },
  40188. processXRefStream: function XRef_processXRefStream(stream) {
  40189. if (!('streamState' in this)) {
  40190. // Stores state of the stream as we process it so we can resume
  40191. // from middle of stream in case of missing data error
  40192. var streamParameters = stream.dict;
  40193. var byteWidths = streamParameters.get('W');
  40194. var range = streamParameters.get('Index');
  40195. if (!range) {
  40196. range = [0, streamParameters.get('Size')];
  40197. }
  40198. this.streamState = {
  40199. entryRanges: range,
  40200. byteWidths: byteWidths,
  40201. entryNum: 0,
  40202. streamPos: stream.pos
  40203. };
  40204. }
  40205. this.readXRefStream(stream);
  40206. delete this.streamState;
  40207. return stream.dict;
  40208. },
  40209. readXRefStream: function XRef_readXRefStream(stream) {
  40210. var i, j;
  40211. var streamState = this.streamState;
  40212. stream.pos = streamState.streamPos;
  40213. var byteWidths = streamState.byteWidths;
  40214. var typeFieldWidth = byteWidths[0];
  40215. var offsetFieldWidth = byteWidths[1];
  40216. var generationFieldWidth = byteWidths[2];
  40217. var entryRanges = streamState.entryRanges;
  40218. while (entryRanges.length > 0) {
  40219. var first = entryRanges[0];
  40220. var n = entryRanges[1];
  40221. if (!isInt(first) || !isInt(n)) {
  40222. error('Invalid XRef range fields: ' + first + ', ' + n);
  40223. }
  40224. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  40225. !isInt(generationFieldWidth)) {
  40226. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  40227. }
  40228. for (i = streamState.entryNum; i < n; ++i) {
  40229. streamState.entryNum = i;
  40230. streamState.streamPos = stream.pos;
  40231. var type = 0, offset = 0, generation = 0;
  40232. for (j = 0; j < typeFieldWidth; ++j) {
  40233. type = (type << 8) | stream.getByte();
  40234. }
  40235. // if type field is absent, its default value is 1
  40236. if (typeFieldWidth === 0) {
  40237. type = 1;
  40238. }
  40239. for (j = 0; j < offsetFieldWidth; ++j) {
  40240. offset = (offset << 8) | stream.getByte();
  40241. }
  40242. for (j = 0; j < generationFieldWidth; ++j) {
  40243. generation = (generation << 8) | stream.getByte();
  40244. }
  40245. var entry = {};
  40246. entry.offset = offset;
  40247. entry.gen = generation;
  40248. switch (type) {
  40249. case 0:
  40250. entry.free = true;
  40251. break;
  40252. case 1:
  40253. entry.uncompressed = true;
  40254. break;
  40255. case 2:
  40256. break;
  40257. default:
  40258. error('Invalid XRef entry type: ' + type);
  40259. }
  40260. if (!this.entries[first + i]) {
  40261. this.entries[first + i] = entry;
  40262. }
  40263. }
  40264. streamState.entryNum = 0;
  40265. streamState.streamPos = stream.pos;
  40266. entryRanges.splice(0, 2);
  40267. }
  40268. },
  40269. indexObjects: function XRef_indexObjects() {
  40270. // Simple scan through the PDF content to find objects,
  40271. // trailers and XRef streams.
  40272. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  40273. var PERCENT = 0x25, LT = 0x3C;
  40274. function readToken(data, offset) {
  40275. var token = '', ch = data[offset];
  40276. while (ch !== LF && ch !== CR && ch !== LT) {
  40277. if (++offset >= data.length) {
  40278. break;
  40279. }
  40280. token += String.fromCharCode(ch);
  40281. ch = data[offset];
  40282. }
  40283. return token;
  40284. }
  40285. function skipUntil(data, offset, what) {
  40286. var length = what.length, dataLength = data.length;
  40287. var skipped = 0;
  40288. // finding byte sequence
  40289. while (offset < dataLength) {
  40290. var i = 0;
  40291. while (i < length && data[offset + i] === what[i]) {
  40292. ++i;
  40293. }
  40294. if (i >= length) {
  40295. break; // sequence found
  40296. }
  40297. offset++;
  40298. skipped++;
  40299. }
  40300. return skipped;
  40301. }
  40302. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  40303. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  40304. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  40305. 101, 102]);
  40306. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  40307. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  40308. // Clear out any existing entries, since they may be bogus.
  40309. this.entries.length = 0;
  40310. var stream = this.stream;
  40311. stream.pos = 0;
  40312. var buffer = stream.getBytes();
  40313. var position = stream.start, length = buffer.length;
  40314. var trailers = [], xrefStms = [];
  40315. while (position < length) {
  40316. var ch = buffer[position];
  40317. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  40318. ++position;
  40319. continue;
  40320. }
  40321. if (ch === PERCENT) { // %-comment
  40322. do {
  40323. ++position;
  40324. if (position >= length) {
  40325. break;
  40326. }
  40327. ch = buffer[position];
  40328. } while (ch !== LF && ch !== CR);
  40329. continue;
  40330. }
  40331. var token = readToken(buffer, position);
  40332. var m;
  40333. if (token.indexOf('xref') === 0 &&
  40334. (token.length === 4 || /\s/.test(token[4]))) {
  40335. position += skipUntil(buffer, position, trailerBytes);
  40336. trailers.push(position);
  40337. position += skipUntil(buffer, position, startxrefBytes);
  40338. } else if ((m = objRegExp.exec(token))) {
  40339. if (typeof this.entries[m[1]] === 'undefined') {
  40340. this.entries[m[1]] = {
  40341. offset: position - stream.start,
  40342. gen: m[2] | 0,
  40343. uncompressed: true
  40344. };
  40345. }
  40346. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  40347. var content = buffer.subarray(position, position + contentLength);
  40348. // checking XRef stream suspect
  40349. // (it shall have '/XRef' and next char is not a letter)
  40350. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  40351. if (xrefTagOffset < contentLength &&
  40352. content[xrefTagOffset + 5] < 64) {
  40353. xrefStms.push(position - stream.start);
  40354. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  40355. }
  40356. position += contentLength;
  40357. } else if (token.indexOf('trailer') === 0 &&
  40358. (token.length === 7 || /\s/.test(token[7]))) {
  40359. trailers.push(position);
  40360. position += skipUntil(buffer, position, startxrefBytes);
  40361. } else {
  40362. position += token.length + 1;
  40363. }
  40364. }
  40365. // reading XRef streams
  40366. var i, ii;
  40367. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  40368. this.startXRefQueue.push(xrefStms[i]);
  40369. this.readXRef(/* recoveryMode */ true);
  40370. }
  40371. // finding main trailer
  40372. var dict;
  40373. for (i = 0, ii = trailers.length; i < ii; ++i) {
  40374. stream.pos = trailers[i];
  40375. var parser = new Parser(new Lexer(stream), true, this);
  40376. var obj = parser.getObj();
  40377. if (!isCmd(obj, 'trailer')) {
  40378. continue;
  40379. }
  40380. // read the trailer dictionary
  40381. if (!isDict(dict = parser.getObj())) {
  40382. continue;
  40383. }
  40384. // taking the first one with 'ID'
  40385. if (dict.has('ID')) {
  40386. return dict;
  40387. }
  40388. }
  40389. // no tailer with 'ID', taking last one (if exists)
  40390. if (dict) {
  40391. return dict;
  40392. }
  40393. // nothing helps
  40394. // calling error() would reject worker with an UnknownErrorException.
  40395. throw new InvalidPDFException('Invalid PDF structure');
  40396. },
  40397. readXRef: function XRef_readXRef(recoveryMode) {
  40398. var stream = this.stream;
  40399. try {
  40400. while (this.startXRefQueue.length) {
  40401. var startXRef = this.startXRefQueue[0];
  40402. stream.pos = startXRef + stream.start;
  40403. var parser = new Parser(new Lexer(stream), true, this);
  40404. var obj = parser.getObj();
  40405. var dict;
  40406. // Get dictionary
  40407. if (isCmd(obj, 'xref')) {
  40408. // Parse end-of-file XRef
  40409. dict = this.processXRefTable(parser);
  40410. if (!this.topDict) {
  40411. this.topDict = dict;
  40412. }
  40413. // Recursively get other XRefs 'XRefStm', if any
  40414. obj = dict.get('XRefStm');
  40415. if (isInt(obj)) {
  40416. var pos = obj;
  40417. // ignore previously loaded xref streams
  40418. // (possible infinite recursion)
  40419. if (!(pos in this.xrefstms)) {
  40420. this.xrefstms[pos] = 1;
  40421. this.startXRefQueue.push(pos);
  40422. }
  40423. }
  40424. } else if (isInt(obj)) {
  40425. // Parse in-stream XRef
  40426. if (!isInt(parser.getObj()) ||
  40427. !isCmd(parser.getObj(), 'obj') ||
  40428. !isStream(obj = parser.getObj())) {
  40429. error('Invalid XRef stream');
  40430. }
  40431. dict = this.processXRefStream(obj);
  40432. if (!this.topDict) {
  40433. this.topDict = dict;
  40434. }
  40435. if (!dict) {
  40436. error('Failed to read XRef stream');
  40437. }
  40438. } else {
  40439. error('Invalid XRef stream header');
  40440. }
  40441. // Recursively get previous dictionary, if any
  40442. obj = dict.get('Prev');
  40443. if (isInt(obj)) {
  40444. this.startXRefQueue.push(obj);
  40445. } else if (isRef(obj)) {
  40446. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  40447. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  40448. this.startXRefQueue.push(obj.num);
  40449. }
  40450. this.startXRefQueue.shift();
  40451. }
  40452. return this.topDict;
  40453. } catch (e) {
  40454. if (e instanceof MissingDataException) {
  40455. throw e;
  40456. }
  40457. info('(while reading XRef): ' + e);
  40458. }
  40459. if (recoveryMode) {
  40460. return;
  40461. }
  40462. throw new XRefParseException();
  40463. },
  40464. getEntry: function XRef_getEntry(i) {
  40465. var xrefEntry = this.entries[i];
  40466. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  40467. return xrefEntry;
  40468. }
  40469. return null;
  40470. },
  40471. fetchIfRef: function XRef_fetchIfRef(obj) {
  40472. if (!isRef(obj)) {
  40473. return obj;
  40474. }
  40475. return this.fetch(obj);
  40476. },
  40477. fetch: function XRef_fetch(ref, suppressEncryption) {
  40478. assert(isRef(ref), 'ref object is not a reference');
  40479. var num = ref.num;
  40480. if (num in this.cache) {
  40481. var cacheEntry = this.cache[num];
  40482. return cacheEntry;
  40483. }
  40484. var xrefEntry = this.getEntry(num);
  40485. // the referenced entry can be free
  40486. if (xrefEntry === null) {
  40487. return (this.cache[num] = null);
  40488. }
  40489. if (xrefEntry.uncompressed) {
  40490. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  40491. } else {
  40492. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  40493. }
  40494. if (isDict(xrefEntry)){
  40495. xrefEntry.objId = ref.toString();
  40496. } else if (isStream(xrefEntry)) {
  40497. xrefEntry.dict.objId = ref.toString();
  40498. }
  40499. return xrefEntry;
  40500. },
  40501. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  40502. suppressEncryption) {
  40503. var gen = ref.gen;
  40504. var num = ref.num;
  40505. if (xrefEntry.gen !== gen) {
  40506. error('inconsistent generation in XRef');
  40507. }
  40508. var stream = this.stream.makeSubStream(xrefEntry.offset +
  40509. this.stream.start);
  40510. var parser = new Parser(new Lexer(stream), true, this);
  40511. var obj1 = parser.getObj();
  40512. var obj2 = parser.getObj();
  40513. var obj3 = parser.getObj();
  40514. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  40515. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  40516. !isCmd(obj3)) {
  40517. error('bad XRef entry');
  40518. }
  40519. if (!isCmd(obj3, 'obj')) {
  40520. // some bad PDFs use "obj1234" and really mean 1234
  40521. if (obj3.cmd.indexOf('obj') === 0) {
  40522. num = parseInt(obj3.cmd.substring(3), 10);
  40523. if (!isNaN(num)) {
  40524. return num;
  40525. }
  40526. }
  40527. error('bad XRef entry');
  40528. }
  40529. if (this.encrypt && !suppressEncryption) {
  40530. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  40531. } else {
  40532. xrefEntry = parser.getObj();
  40533. }
  40534. if (!isStream(xrefEntry)) {
  40535. this.cache[num] = xrefEntry;
  40536. }
  40537. return xrefEntry;
  40538. },
  40539. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  40540. suppressEncryption) {
  40541. var tableOffset = xrefEntry.offset;
  40542. var stream = this.fetch(new Ref(tableOffset, 0));
  40543. if (!isStream(stream)) {
  40544. error('bad ObjStm stream');
  40545. }
  40546. var first = stream.dict.get('First');
  40547. var n = stream.dict.get('N');
  40548. if (!isInt(first) || !isInt(n)) {
  40549. error('invalid first and n parameters for ObjStm stream');
  40550. }
  40551. var parser = new Parser(new Lexer(stream), false, this);
  40552. parser.allowStreams = true;
  40553. var i, entries = [], num, nums = [];
  40554. // read the object numbers to populate cache
  40555. for (i = 0; i < n; ++i) {
  40556. num = parser.getObj();
  40557. if (!isInt(num)) {
  40558. error('invalid object number in the ObjStm stream: ' + num);
  40559. }
  40560. nums.push(num);
  40561. var offset = parser.getObj();
  40562. if (!isInt(offset)) {
  40563. error('invalid object offset in the ObjStm stream: ' + offset);
  40564. }
  40565. }
  40566. // read stream objects for cache
  40567. for (i = 0; i < n; ++i) {
  40568. entries.push(parser.getObj());
  40569. num = nums[i];
  40570. var entry = this.entries[num];
  40571. if (entry && entry.offset === tableOffset && entry.gen === i) {
  40572. this.cache[num] = entries[i];
  40573. }
  40574. }
  40575. xrefEntry = entries[xrefEntry.gen];
  40576. if (xrefEntry === undefined) {
  40577. error('bad XRef entry for compressed object');
  40578. }
  40579. return xrefEntry;
  40580. },
  40581. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  40582. if (!isRef(obj)) {
  40583. return Promise.resolve(obj);
  40584. }
  40585. return this.fetchAsync(obj);
  40586. },
  40587. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  40588. var streamManager = this.stream.manager;
  40589. var xref = this;
  40590. return new Promise(function tryFetch(resolve, reject) {
  40591. try {
  40592. resolve(xref.fetch(ref, suppressEncryption));
  40593. } catch (e) {
  40594. if (e instanceof MissingDataException) {
  40595. streamManager.requestRange(e.begin, e.end).then(function () {
  40596. tryFetch(resolve, reject);
  40597. }, reject);
  40598. return;
  40599. }
  40600. reject(e);
  40601. }
  40602. });
  40603. },
  40604. getCatalogObj: function XRef_getCatalogObj() {
  40605. return this.root;
  40606. }
  40607. };
  40608. return XRef;
  40609. })();
  40610. /**
  40611. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  40612. * see the specification (7.9.6 and 7.9.7) for additional details.
  40613. * TODO: implement all the Dict functions and make this more efficient.
  40614. */
  40615. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  40616. function NameOrNumberTree(root, xref) {
  40617. throw new Error('Cannot initialize NameOrNumberTree.');
  40618. }
  40619. NameOrNumberTree.prototype = {
  40620. getAll: function NameOrNumberTree_getAll() {
  40621. var dict = Object.create(null);
  40622. if (!this.root) {
  40623. return dict;
  40624. }
  40625. var xref = this.xref;
  40626. // Reading Name/Number tree.
  40627. var processed = new RefSet();
  40628. processed.put(this.root);
  40629. var queue = [this.root];
  40630. while (queue.length > 0) {
  40631. var i, n;
  40632. var obj = xref.fetchIfRef(queue.shift());
  40633. if (!isDict(obj)) {
  40634. continue;
  40635. }
  40636. if (obj.has('Kids')) {
  40637. var kids = obj.get('Kids');
  40638. for (i = 0, n = kids.length; i < n; i++) {
  40639. var kid = kids[i];
  40640. assert(!processed.has(kid),
  40641. 'Duplicate entry in "' + this._type + '" tree.');
  40642. queue.push(kid);
  40643. processed.put(kid);
  40644. }
  40645. continue;
  40646. }
  40647. var entries = obj.get(this._type);
  40648. if (isArray(entries)) {
  40649. for (i = 0, n = entries.length; i < n; i += 2) {
  40650. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  40651. }
  40652. }
  40653. }
  40654. return dict;
  40655. },
  40656. get: function NameOrNumberTree_get(key) {
  40657. if (!this.root) {
  40658. return null;
  40659. }
  40660. var xref = this.xref;
  40661. var kidsOrEntries = xref.fetchIfRef(this.root);
  40662. var loopCount = 0;
  40663. var MAX_LEVELS = 10;
  40664. var l, r, m;
  40665. // Perform a binary search to quickly find the entry that
  40666. // contains the key we are looking for.
  40667. while (kidsOrEntries.has('Kids')) {
  40668. if (++loopCount > MAX_LEVELS) {
  40669. warn('Search depth limit reached for "' + this._type + '" tree.');
  40670. return null;
  40671. }
  40672. var kids = kidsOrEntries.get('Kids');
  40673. if (!isArray(kids)) {
  40674. return null;
  40675. }
  40676. l = 0;
  40677. r = kids.length - 1;
  40678. while (l <= r) {
  40679. m = (l + r) >> 1;
  40680. var kid = xref.fetchIfRef(kids[m]);
  40681. var limits = kid.get('Limits');
  40682. if (key < xref.fetchIfRef(limits[0])) {
  40683. r = m - 1;
  40684. } else if (key > xref.fetchIfRef(limits[1])) {
  40685. l = m + 1;
  40686. } else {
  40687. kidsOrEntries = xref.fetchIfRef(kids[m]);
  40688. break;
  40689. }
  40690. }
  40691. if (l > r) {
  40692. return null;
  40693. }
  40694. }
  40695. // If we get here, then we have found the right entry. Now go through the
  40696. // entries in the dictionary until we find the key we're looking for.
  40697. var entries = kidsOrEntries.get(this._type);
  40698. if (isArray(entries)) {
  40699. // Perform a binary search to reduce the lookup time.
  40700. l = 0;
  40701. r = entries.length - 2;
  40702. while (l <= r) {
  40703. // Check only even indices (0, 2, 4, ...) because the
  40704. // odd indices contain the actual data.
  40705. m = (l + r) & ~1;
  40706. var currentKey = xref.fetchIfRef(entries[m]);
  40707. if (key < currentKey) {
  40708. r = m - 2;
  40709. } else if (key > currentKey) {
  40710. l = m + 2;
  40711. } else {
  40712. return xref.fetchIfRef(entries[m + 1]);
  40713. }
  40714. }
  40715. }
  40716. return null;
  40717. }
  40718. };
  40719. return NameOrNumberTree;
  40720. })();
  40721. var NameTree = (function NameTreeClosure() {
  40722. function NameTree(root, xref) {
  40723. this.root = root;
  40724. this.xref = xref;
  40725. this._type = 'Names';
  40726. }
  40727. Util.inherit(NameTree, NameOrNumberTree, {});
  40728. return NameTree;
  40729. })();
  40730. var NumberTree = (function NumberTreeClosure() {
  40731. function NumberTree(root, xref) {
  40732. this.root = root;
  40733. this.xref = xref;
  40734. this._type = 'Nums';
  40735. }
  40736. Util.inherit(NumberTree, NameOrNumberTree, {});
  40737. return NumberTree;
  40738. })();
  40739. /**
  40740. * "A PDF file can refer to the contents of another file by using a File
  40741. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  40742. * NOTE: Only embedded files are supported (as part of the attachments support)
  40743. * TODO: support the 'URL' file system (with caching if !/V), portable
  40744. * collections attributes and related files (/RF)
  40745. */
  40746. var FileSpec = (function FileSpecClosure() {
  40747. function FileSpec(root, xref) {
  40748. if (!root || !isDict(root)) {
  40749. return;
  40750. }
  40751. this.xref = xref;
  40752. this.root = root;
  40753. if (root.has('FS')) {
  40754. this.fs = root.get('FS');
  40755. }
  40756. this.description = root.has('Desc') ?
  40757. stringToPDFString(root.get('Desc')) :
  40758. '';
  40759. if (root.has('RF')) {
  40760. warn('Related file specifications are not supported');
  40761. }
  40762. this.contentAvailable = true;
  40763. if (!root.has('EF')) {
  40764. this.contentAvailable = false;
  40765. warn('Non-embedded file specifications are not supported');
  40766. }
  40767. }
  40768. function pickPlatformItem(dict) {
  40769. // Look for the filename in this order:
  40770. // UF, F, Unix, Mac, DOS
  40771. if (dict.has('UF')) {
  40772. return dict.get('UF');
  40773. } else if (dict.has('F')) {
  40774. return dict.get('F');
  40775. } else if (dict.has('Unix')) {
  40776. return dict.get('Unix');
  40777. } else if (dict.has('Mac')) {
  40778. return dict.get('Mac');
  40779. } else if (dict.has('DOS')) {
  40780. return dict.get('DOS');
  40781. } else {
  40782. return null;
  40783. }
  40784. }
  40785. FileSpec.prototype = {
  40786. get filename() {
  40787. if (!this._filename && this.root) {
  40788. var filename = pickPlatformItem(this.root) || 'unnamed';
  40789. this._filename = stringToPDFString(filename).
  40790. replace(/\\\\/g, '\\').
  40791. replace(/\\\//g, '/').
  40792. replace(/\\/g, '/');
  40793. }
  40794. return this._filename;
  40795. },
  40796. get content() {
  40797. if (!this.contentAvailable) {
  40798. return null;
  40799. }
  40800. if (!this.contentRef && this.root) {
  40801. this.contentRef = pickPlatformItem(this.root.get('EF'));
  40802. }
  40803. var content = null;
  40804. if (this.contentRef) {
  40805. var xref = this.xref;
  40806. var fileObj = xref.fetchIfRef(this.contentRef);
  40807. if (fileObj && isStream(fileObj)) {
  40808. content = fileObj.getBytes();
  40809. } else {
  40810. warn('Embedded file specification points to non-existing/invalid ' +
  40811. 'content');
  40812. }
  40813. } else {
  40814. warn('Embedded file specification does not have a content');
  40815. }
  40816. return content;
  40817. },
  40818. get serializable() {
  40819. return {
  40820. filename: this.filename,
  40821. content: this.content
  40822. };
  40823. }
  40824. };
  40825. return FileSpec;
  40826. })();
  40827. /**
  40828. * A helper for loading missing data in object graphs. It traverses the graph
  40829. * depth first and queues up any objects that have missing data. Once it has
  40830. * has traversed as many objects that are available it attempts to bundle the
  40831. * missing data requests and then resume from the nodes that weren't ready.
  40832. *
  40833. * NOTE: It provides protection from circular references by keeping track of
  40834. * of loaded references. However, you must be careful not to load any graphs
  40835. * that have references to the catalog or other pages since that will cause the
  40836. * entire PDF document object graph to be traversed.
  40837. */
  40838. var ObjectLoader = (function() {
  40839. function mayHaveChildren(value) {
  40840. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  40841. }
  40842. function addChildren(node, nodesToVisit) {
  40843. var value;
  40844. if (isDict(node) || isStream(node)) {
  40845. var map;
  40846. if (isDict(node)) {
  40847. map = node.map;
  40848. } else {
  40849. map = node.dict.map;
  40850. }
  40851. for (var key in map) {
  40852. value = map[key];
  40853. if (mayHaveChildren(value)) {
  40854. nodesToVisit.push(value);
  40855. }
  40856. }
  40857. } else if (isArray(node)) {
  40858. for (var i = 0, ii = node.length; i < ii; i++) {
  40859. value = node[i];
  40860. if (mayHaveChildren(value)) {
  40861. nodesToVisit.push(value);
  40862. }
  40863. }
  40864. }
  40865. }
  40866. function ObjectLoader(obj, keys, xref) {
  40867. this.obj = obj;
  40868. this.keys = keys;
  40869. this.xref = xref;
  40870. this.refSet = null;
  40871. this.capability = null;
  40872. }
  40873. ObjectLoader.prototype = {
  40874. load: function ObjectLoader_load() {
  40875. var keys = this.keys;
  40876. this.capability = createPromiseCapability();
  40877. // Don't walk the graph if all the data is already loaded.
  40878. if (!(this.xref.stream instanceof ChunkedStream) ||
  40879. this.xref.stream.getMissingChunks().length === 0) {
  40880. this.capability.resolve();
  40881. return this.capability.promise;
  40882. }
  40883. this.refSet = new RefSet();
  40884. // Setup the initial nodes to visit.
  40885. var nodesToVisit = [];
  40886. for (var i = 0; i < keys.length; i++) {
  40887. nodesToVisit.push(this.obj[keys[i]]);
  40888. }
  40889. this._walk(nodesToVisit);
  40890. return this.capability.promise;
  40891. },
  40892. _walk: function ObjectLoader_walk(nodesToVisit) {
  40893. var nodesToRevisit = [];
  40894. var pendingRequests = [];
  40895. // DFS walk of the object graph.
  40896. while (nodesToVisit.length) {
  40897. var currentNode = nodesToVisit.pop();
  40898. // Only references or chunked streams can cause missing data exceptions.
  40899. if (isRef(currentNode)) {
  40900. // Skip nodes that have already been visited.
  40901. if (this.refSet.has(currentNode)) {
  40902. continue;
  40903. }
  40904. try {
  40905. var ref = currentNode;
  40906. this.refSet.put(ref);
  40907. currentNode = this.xref.fetch(currentNode);
  40908. } catch (e) {
  40909. if (!(e instanceof MissingDataException)) {
  40910. throw e;
  40911. }
  40912. nodesToRevisit.push(currentNode);
  40913. pendingRequests.push({ begin: e.begin, end: e.end });
  40914. }
  40915. }
  40916. if (currentNode && currentNode.getBaseStreams) {
  40917. var baseStreams = currentNode.getBaseStreams();
  40918. var foundMissingData = false;
  40919. for (var i = 0; i < baseStreams.length; i++) {
  40920. var stream = baseStreams[i];
  40921. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  40922. foundMissingData = true;
  40923. pendingRequests.push({
  40924. begin: stream.start,
  40925. end: stream.end
  40926. });
  40927. }
  40928. }
  40929. if (foundMissingData) {
  40930. nodesToRevisit.push(currentNode);
  40931. }
  40932. }
  40933. addChildren(currentNode, nodesToVisit);
  40934. }
  40935. if (pendingRequests.length) {
  40936. this.xref.stream.manager.requestRanges(pendingRequests).then(
  40937. function pendingRequestCallback() {
  40938. nodesToVisit = nodesToRevisit;
  40939. for (var i = 0; i < nodesToRevisit.length; i++) {
  40940. var node = nodesToRevisit[i];
  40941. // Remove any reference nodes from the currrent refset so they
  40942. // aren't skipped when we revist them.
  40943. if (isRef(node)) {
  40944. this.refSet.remove(node);
  40945. }
  40946. }
  40947. this._walk(nodesToVisit);
  40948. }.bind(this), this.capability.reject);
  40949. return;
  40950. }
  40951. // Everything is loaded.
  40952. this.refSet = null;
  40953. this.capability.resolve();
  40954. }
  40955. };
  40956. return ObjectLoader;
  40957. })();
  40958. exports.Catalog = Catalog;
  40959. exports.ObjectLoader = ObjectLoader;
  40960. exports.XRef = XRef;
  40961. exports.FileSpec = FileSpec;
  40962. }));
  40963. (function (root, factory) {
  40964. {
  40965. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  40966. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  40967. root.pdfjsCoreColorSpace);
  40968. }
  40969. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  40970. coreColorSpace) {
  40971. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  40972. var MissingDataException = sharedUtil.MissingDataException;
  40973. var Util = sharedUtil.Util;
  40974. var assert = sharedUtil.assert;
  40975. var error = sharedUtil.error;
  40976. var info = sharedUtil.info;
  40977. var warn = sharedUtil.warn;
  40978. var isStream = corePrimitives.isStream;
  40979. var PDFFunction = coreFunction.PDFFunction;
  40980. var ColorSpace = coreColorSpace.ColorSpace;
  40981. var ShadingType = {
  40982. FUNCTION_BASED: 1,
  40983. AXIAL: 2,
  40984. RADIAL: 3,
  40985. FREE_FORM_MESH: 4,
  40986. LATTICE_FORM_MESH: 5,
  40987. COONS_PATCH_MESH: 6,
  40988. TENSOR_PATCH_MESH: 7
  40989. };
  40990. var Pattern = (function PatternClosure() {
  40991. // Constructor should define this.getPattern
  40992. function Pattern() {
  40993. error('should not call Pattern constructor');
  40994. }
  40995. Pattern.prototype = {
  40996. // Input: current Canvas context
  40997. // Output: the appropriate fillStyle or strokeStyle
  40998. getPattern: function Pattern_getPattern(ctx) {
  40999. error('Should not call Pattern.getStyle: ' + ctx);
  41000. }
  41001. };
  41002. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41003. res, handler) {
  41004. var dict = isStream(shading) ? shading.dict : shading;
  41005. var type = dict.get('ShadingType');
  41006. try {
  41007. switch (type) {
  41008. case ShadingType.AXIAL:
  41009. case ShadingType.RADIAL:
  41010. // Both radial and axial shadings are handled by RadialAxial shading.
  41011. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41012. case ShadingType.FREE_FORM_MESH:
  41013. case ShadingType.LATTICE_FORM_MESH:
  41014. case ShadingType.COONS_PATCH_MESH:
  41015. case ShadingType.TENSOR_PATCH_MESH:
  41016. return new Shadings.Mesh(shading, matrix, xref, res);
  41017. default:
  41018. throw new Error('Unsupported ShadingType: ' + type);
  41019. }
  41020. } catch (ex) {
  41021. if (ex instanceof MissingDataException) {
  41022. throw ex;
  41023. }
  41024. handler.send('UnsupportedFeature',
  41025. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41026. warn(ex);
  41027. return new Shadings.Dummy();
  41028. }
  41029. };
  41030. return Pattern;
  41031. })();
  41032. var Shadings = {};
  41033. // A small number to offset the first/last color stops so we can insert ones to
  41034. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41035. Shadings.SMALL_NUMBER = 1e-6;
  41036. // Radial and axial shading have very similar implementations
  41037. // If needed, the implementations can be broken into two classes
  41038. Shadings.RadialAxial = (function RadialAxialClosure() {
  41039. function RadialAxial(dict, matrix, xref, res) {
  41040. this.matrix = matrix;
  41041. this.coordsArr = dict.get('Coords');
  41042. this.shadingType = dict.get('ShadingType');
  41043. this.type = 'Pattern';
  41044. var cs = dict.get('ColorSpace', 'CS');
  41045. cs = ColorSpace.parse(cs, xref, res);
  41046. this.cs = cs;
  41047. var t0 = 0.0, t1 = 1.0;
  41048. if (dict.has('Domain')) {
  41049. var domainArr = dict.get('Domain');
  41050. t0 = domainArr[0];
  41051. t1 = domainArr[1];
  41052. }
  41053. var extendStart = false, extendEnd = false;
  41054. if (dict.has('Extend')) {
  41055. var extendArr = dict.get('Extend');
  41056. extendStart = extendArr[0];
  41057. extendEnd = extendArr[1];
  41058. }
  41059. if (this.shadingType === ShadingType.RADIAL &&
  41060. (!extendStart || !extendEnd)) {
  41061. // Radial gradient only currently works if either circle is fully within
  41062. // the other circle.
  41063. var x1 = this.coordsArr[0];
  41064. var y1 = this.coordsArr[1];
  41065. var r1 = this.coordsArr[2];
  41066. var x2 = this.coordsArr[3];
  41067. var y2 = this.coordsArr[4];
  41068. var r2 = this.coordsArr[5];
  41069. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  41070. if (r1 <= r2 + distance &&
  41071. r2 <= r1 + distance) {
  41072. warn('Unsupported radial gradient.');
  41073. }
  41074. }
  41075. this.extendStart = extendStart;
  41076. this.extendEnd = extendEnd;
  41077. var fnObj = dict.get('Function');
  41078. var fn = PDFFunction.parseArray(xref, fnObj);
  41079. // 10 samples seems good enough for now, but probably won't work
  41080. // if there are sharp color changes. Ideally, we would implement
  41081. // the spec faithfully and add lossless optimizations.
  41082. var diff = t1 - t0;
  41083. var step = diff / 10;
  41084. var colorStops = this.colorStops = [];
  41085. // Protect against bad domains so we don't end up in an infinte loop below.
  41086. if (t0 >= t1 || step <= 0) {
  41087. // Acrobat doesn't seem to handle these cases so we'll ignore for
  41088. // now.
  41089. info('Bad shading domain.');
  41090. return;
  41091. }
  41092. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  41093. var rgbColor;
  41094. for (var i = t0; i <= t1; i += step) {
  41095. ratio[0] = i;
  41096. fn(ratio, 0, color, 0);
  41097. rgbColor = cs.getRgb(color, 0);
  41098. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41099. colorStops.push([(i - t0) / diff, cssColor]);
  41100. }
  41101. var background = 'transparent';
  41102. if (dict.has('Background')) {
  41103. rgbColor = cs.getRgb(dict.get('Background'), 0);
  41104. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41105. }
  41106. if (!extendStart) {
  41107. // Insert a color stop at the front and offset the first real color stop
  41108. // so it doesn't conflict with the one we insert.
  41109. colorStops.unshift([0, background]);
  41110. colorStops[1][0] += Shadings.SMALL_NUMBER;
  41111. }
  41112. if (!extendEnd) {
  41113. // Same idea as above in extendStart but for the end.
  41114. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  41115. colorStops.push([1, background]);
  41116. }
  41117. this.colorStops = colorStops;
  41118. }
  41119. RadialAxial.prototype = {
  41120. getIR: function RadialAxial_getIR() {
  41121. var coordsArr = this.coordsArr;
  41122. var shadingType = this.shadingType;
  41123. var type, p0, p1, r0, r1;
  41124. if (shadingType === ShadingType.AXIAL) {
  41125. p0 = [coordsArr[0], coordsArr[1]];
  41126. p1 = [coordsArr[2], coordsArr[3]];
  41127. r0 = null;
  41128. r1 = null;
  41129. type = 'axial';
  41130. } else if (shadingType === ShadingType.RADIAL) {
  41131. p0 = [coordsArr[0], coordsArr[1]];
  41132. p1 = [coordsArr[3], coordsArr[4]];
  41133. r0 = coordsArr[2];
  41134. r1 = coordsArr[5];
  41135. type = 'radial';
  41136. } else {
  41137. error('getPattern type unknown: ' + shadingType);
  41138. }
  41139. var matrix = this.matrix;
  41140. if (matrix) {
  41141. p0 = Util.applyTransform(p0, matrix);
  41142. p1 = Util.applyTransform(p1, matrix);
  41143. if (shadingType === ShadingType.RADIAL) {
  41144. var scale = Util.singularValueDecompose2dScale(matrix);
  41145. r0 *= scale[0];
  41146. r1 *= scale[1];
  41147. }
  41148. }
  41149. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  41150. }
  41151. };
  41152. return RadialAxial;
  41153. })();
  41154. // All mesh shading. For now, they will be presented as set of the triangles
  41155. // to be drawn on the canvas and rgb color for each vertex.
  41156. Shadings.Mesh = (function MeshClosure() {
  41157. function MeshStreamReader(stream, context) {
  41158. this.stream = stream;
  41159. this.context = context;
  41160. this.buffer = 0;
  41161. this.bufferLength = 0;
  41162. var numComps = context.numComps;
  41163. this.tmpCompsBuf = new Float32Array(numComps);
  41164. var csNumComps = context.colorSpace.numComps;
  41165. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  41166. this.tmpCompsBuf;
  41167. }
  41168. MeshStreamReader.prototype = {
  41169. get hasData() {
  41170. if (this.stream.end) {
  41171. return this.stream.pos < this.stream.end;
  41172. }
  41173. if (this.bufferLength > 0) {
  41174. return true;
  41175. }
  41176. var nextByte = this.stream.getByte();
  41177. if (nextByte < 0) {
  41178. return false;
  41179. }
  41180. this.buffer = nextByte;
  41181. this.bufferLength = 8;
  41182. return true;
  41183. },
  41184. readBits: function MeshStreamReader_readBits(n) {
  41185. var buffer = this.buffer;
  41186. var bufferLength = this.bufferLength;
  41187. if (n === 32) {
  41188. if (bufferLength === 0) {
  41189. return ((this.stream.getByte() << 24) |
  41190. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  41191. this.stream.getByte()) >>> 0;
  41192. }
  41193. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  41194. (this.stream.getByte() << 8) | this.stream.getByte();
  41195. var nextByte = this.stream.getByte();
  41196. this.buffer = nextByte & ((1 << bufferLength) - 1);
  41197. return ((buffer << (8 - bufferLength)) |
  41198. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  41199. }
  41200. if (n === 8 && bufferLength === 0) {
  41201. return this.stream.getByte();
  41202. }
  41203. while (bufferLength < n) {
  41204. buffer = (buffer << 8) | this.stream.getByte();
  41205. bufferLength += 8;
  41206. }
  41207. bufferLength -= n;
  41208. this.bufferLength = bufferLength;
  41209. this.buffer = buffer & ((1 << bufferLength) - 1);
  41210. return buffer >> bufferLength;
  41211. },
  41212. align: function MeshStreamReader_align() {
  41213. this.buffer = 0;
  41214. this.bufferLength = 0;
  41215. },
  41216. readFlag: function MeshStreamReader_readFlag() {
  41217. return this.readBits(this.context.bitsPerFlag);
  41218. },
  41219. readCoordinate: function MeshStreamReader_readCoordinate() {
  41220. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  41221. var xi = this.readBits(bitsPerCoordinate);
  41222. var yi = this.readBits(bitsPerCoordinate);
  41223. var decode = this.context.decode;
  41224. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  41225. 2.3283064365386963e-10; // 2 ^ -32
  41226. return [
  41227. xi * scale * (decode[1] - decode[0]) + decode[0],
  41228. yi * scale * (decode[3] - decode[2]) + decode[2]
  41229. ];
  41230. },
  41231. readComponents: function MeshStreamReader_readComponents() {
  41232. var numComps = this.context.numComps;
  41233. var bitsPerComponent = this.context.bitsPerComponent;
  41234. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  41235. 2.3283064365386963e-10; // 2 ^ -32
  41236. var decode = this.context.decode;
  41237. var components = this.tmpCompsBuf;
  41238. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  41239. var ci = this.readBits(bitsPerComponent);
  41240. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  41241. }
  41242. var color = this.tmpCsCompsBuf;
  41243. if (this.context.colorFn) {
  41244. this.context.colorFn(components, 0, color, 0);
  41245. }
  41246. return this.context.colorSpace.getRgb(color, 0);
  41247. }
  41248. };
  41249. function decodeType4Shading(mesh, reader) {
  41250. var coords = mesh.coords;
  41251. var colors = mesh.colors;
  41252. var operators = [];
  41253. var ps = []; // not maintaining cs since that will match ps
  41254. var verticesLeft = 0; // assuming we have all data to start a new triangle
  41255. while (reader.hasData) {
  41256. var f = reader.readFlag();
  41257. var coord = reader.readCoordinate();
  41258. var color = reader.readComponents();
  41259. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  41260. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  41261. switch (f) {
  41262. case 0:
  41263. verticesLeft = 3;
  41264. break;
  41265. case 1:
  41266. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  41267. verticesLeft = 1;
  41268. break;
  41269. case 2:
  41270. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  41271. verticesLeft = 1;
  41272. break;
  41273. }
  41274. operators.push(f);
  41275. }
  41276. ps.push(coords.length);
  41277. coords.push(coord);
  41278. colors.push(color);
  41279. verticesLeft--;
  41280. reader.align();
  41281. }
  41282. mesh.figures.push({
  41283. type: 'triangles',
  41284. coords: new Int32Array(ps),
  41285. colors: new Int32Array(ps),
  41286. });
  41287. }
  41288. function decodeType5Shading(mesh, reader, verticesPerRow) {
  41289. var coords = mesh.coords;
  41290. var colors = mesh.colors;
  41291. var ps = []; // not maintaining cs since that will match ps
  41292. while (reader.hasData) {
  41293. var coord = reader.readCoordinate();
  41294. var color = reader.readComponents();
  41295. ps.push(coords.length);
  41296. coords.push(coord);
  41297. colors.push(color);
  41298. }
  41299. mesh.figures.push({
  41300. type: 'lattice',
  41301. coords: new Int32Array(ps),
  41302. colors: new Int32Array(ps),
  41303. verticesPerRow: verticesPerRow
  41304. });
  41305. }
  41306. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  41307. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  41308. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  41309. var getB = (function getBClosure() {
  41310. function buildB(count) {
  41311. var lut = [];
  41312. for (var i = 0; i <= count; i++) {
  41313. var t = i / count, t_ = 1 - t;
  41314. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  41315. 3 * t * t * t_, t * t * t]));
  41316. }
  41317. return lut;
  41318. }
  41319. var cache = [];
  41320. return function getB(count) {
  41321. if (!cache[count]) {
  41322. cache[count] = buildB(count);
  41323. }
  41324. return cache[count];
  41325. };
  41326. })();
  41327. function buildFigureFromPatch(mesh, index) {
  41328. var figure = mesh.figures[index];
  41329. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  41330. var coords = mesh.coords, colors = mesh.colors;
  41331. var pi = figure.coords;
  41332. var ci = figure.colors;
  41333. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  41334. coords[pi[12]][0], coords[pi[15]][0]);
  41335. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  41336. coords[pi[12]][1], coords[pi[15]][1]);
  41337. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  41338. coords[pi[12]][0], coords[pi[15]][0]);
  41339. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  41340. coords[pi[12]][1], coords[pi[15]][1]);
  41341. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  41342. (mesh.bounds[2] - mesh.bounds[0]));
  41343. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41344. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  41345. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  41346. (mesh.bounds[3] - mesh.bounds[1]));
  41347. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41348. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  41349. var verticesPerRow = splitXBy + 1;
  41350. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  41351. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  41352. var k = 0;
  41353. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  41354. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  41355. c2 = colors[ci[2]], c3 = colors[ci[3]];
  41356. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  41357. for (var row = 0; row <= splitYBy; row++) {
  41358. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  41359. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  41360. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  41361. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  41362. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  41363. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  41364. for (var col = 0; col <= splitXBy; col++, k++) {
  41365. if ((row === 0 || row === splitYBy) &&
  41366. (col === 0 || col === splitXBy)) {
  41367. continue;
  41368. }
  41369. var x = 0, y = 0;
  41370. var q = 0;
  41371. for (var i = 0; i <= 3; i++) {
  41372. for (var j = 0; j <= 3; j++, q++) {
  41373. var m = bRow[row][i] * bCol[col][j];
  41374. x += coords[pi[q]][0] * m;
  41375. y += coords[pi[q]][1] * m;
  41376. }
  41377. }
  41378. figureCoords[k] = coords.length;
  41379. coords.push([x, y]);
  41380. figureColors[k] = colors.length;
  41381. var newColor = new Uint8Array(3);
  41382. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  41383. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  41384. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  41385. colors.push(newColor);
  41386. }
  41387. }
  41388. figureCoords[0] = pi[0];
  41389. figureColors[0] = ci[0];
  41390. figureCoords[splitXBy] = pi[3];
  41391. figureColors[splitXBy] = ci[1];
  41392. figureCoords[verticesPerRow * splitYBy] = pi[12];
  41393. figureColors[verticesPerRow * splitYBy] = ci[2];
  41394. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  41395. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  41396. mesh.figures[index] = {
  41397. type: 'lattice',
  41398. coords: figureCoords,
  41399. colors: figureColors,
  41400. verticesPerRow: verticesPerRow
  41401. };
  41402. }
  41403. function decodeType6Shading(mesh, reader) {
  41404. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  41405. var coords = mesh.coords;
  41406. var colors = mesh.colors;
  41407. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41408. var cs = new Int32Array(4); // c00, c30, c03, c33
  41409. while (reader.hasData) {
  41410. var f = reader.readFlag();
  41411. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  41412. var i, ii;
  41413. var pi = coords.length;
  41414. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  41415. coords.push(reader.readCoordinate());
  41416. }
  41417. var ci = colors.length;
  41418. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41419. colors.push(reader.readComponents());
  41420. }
  41421. var tmp1, tmp2, tmp3, tmp4;
  41422. switch (f) {
  41423. case 0:
  41424. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41425. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  41426. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  41427. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41428. cs[2] = ci + 1; cs[3] = ci + 2;
  41429. cs[0] = ci; cs[1] = ci + 3;
  41430. break;
  41431. case 1:
  41432. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41433. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41434. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41435. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41436. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41437. tmp1 = cs[2]; tmp2 = cs[3];
  41438. cs[2] = tmp2; cs[3] = ci;
  41439. cs[0] = tmp1; cs[1] = ci + 1;
  41440. break;
  41441. case 2:
  41442. tmp1 = ps[15];
  41443. tmp2 = ps[11];
  41444. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41445. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41446. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41447. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41448. tmp1 = cs[3];
  41449. cs[2] = cs[1]; cs[3] = ci;
  41450. cs[0] = tmp1; cs[1] = ci + 1;
  41451. break;
  41452. case 3:
  41453. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41454. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41455. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  41456. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41457. cs[2] = cs[0]; cs[3] = ci;
  41458. cs[0] = cs[1]; cs[1] = ci + 1;
  41459. break;
  41460. }
  41461. // set p11, p12, p21, p22
  41462. ps[5] = coords.length;
  41463. coords.push([
  41464. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  41465. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  41466. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41467. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  41468. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  41469. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  41470. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41471. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  41472. ]);
  41473. ps[6] = coords.length;
  41474. coords.push([
  41475. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  41476. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  41477. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41478. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  41479. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  41480. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  41481. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41482. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  41483. ]);
  41484. ps[9] = coords.length;
  41485. coords.push([
  41486. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  41487. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  41488. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41489. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  41490. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  41491. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  41492. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41493. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  41494. ]);
  41495. ps[10] = coords.length;
  41496. coords.push([
  41497. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  41498. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  41499. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41500. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  41501. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  41502. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  41503. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41504. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  41505. ]);
  41506. mesh.figures.push({
  41507. type: 'patch',
  41508. coords: new Int32Array(ps), // making copies of ps and cs
  41509. colors: new Int32Array(cs)
  41510. });
  41511. }
  41512. }
  41513. function decodeType7Shading(mesh, reader) {
  41514. var coords = mesh.coords;
  41515. var colors = mesh.colors;
  41516. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41517. var cs = new Int32Array(4); // c00, c30, c03, c33
  41518. while (reader.hasData) {
  41519. var f = reader.readFlag();
  41520. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  41521. var i, ii;
  41522. var pi = coords.length;
  41523. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  41524. coords.push(reader.readCoordinate());
  41525. }
  41526. var ci = colors.length;
  41527. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41528. colors.push(reader.readComponents());
  41529. }
  41530. var tmp1, tmp2, tmp3, tmp4;
  41531. switch (f) {
  41532. case 0:
  41533. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41534. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  41535. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  41536. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41537. cs[2] = ci + 1; cs[3] = ci + 2;
  41538. cs[0] = ci; cs[1] = ci + 3;
  41539. break;
  41540. case 1:
  41541. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41542. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41543. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41544. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41545. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41546. tmp1 = cs[2]; tmp2 = cs[3];
  41547. cs[2] = tmp2; cs[3] = ci;
  41548. cs[0] = tmp1; cs[1] = ci + 1;
  41549. break;
  41550. case 2:
  41551. tmp1 = ps[15];
  41552. tmp2 = ps[11];
  41553. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41554. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41555. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41556. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41557. tmp1 = cs[3];
  41558. cs[2] = cs[1]; cs[3] = ci;
  41559. cs[0] = tmp1; cs[1] = ci + 1;
  41560. break;
  41561. case 3:
  41562. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41563. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41564. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41565. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41566. cs[2] = cs[0]; cs[3] = ci;
  41567. cs[0] = cs[1]; cs[1] = ci + 1;
  41568. break;
  41569. }
  41570. mesh.figures.push({
  41571. type: 'patch',
  41572. coords: new Int32Array(ps), // making copies of ps and cs
  41573. colors: new Int32Array(cs)
  41574. });
  41575. }
  41576. }
  41577. function updateBounds(mesh) {
  41578. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  41579. maxX = minX, maxY = minY;
  41580. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  41581. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  41582. minX = minX > x ? x : minX;
  41583. minY = minY > y ? y : minY;
  41584. maxX = maxX < x ? x : maxX;
  41585. maxY = maxY < y ? y : maxY;
  41586. }
  41587. mesh.bounds = [minX, minY, maxX, maxY];
  41588. }
  41589. function packData(mesh) {
  41590. var i, ii, j, jj;
  41591. var coords = mesh.coords;
  41592. var coordsPacked = new Float32Array(coords.length * 2);
  41593. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  41594. var xy = coords[i];
  41595. coordsPacked[j++] = xy[0];
  41596. coordsPacked[j++] = xy[1];
  41597. }
  41598. mesh.coords = coordsPacked;
  41599. var colors = mesh.colors;
  41600. var colorsPacked = new Uint8Array(colors.length * 3);
  41601. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  41602. var c = colors[i];
  41603. colorsPacked[j++] = c[0];
  41604. colorsPacked[j++] = c[1];
  41605. colorsPacked[j++] = c[2];
  41606. }
  41607. mesh.colors = colorsPacked;
  41608. var figures = mesh.figures;
  41609. for (i = 0, ii = figures.length; i < ii; i++) {
  41610. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  41611. for (j = 0, jj = ps.length; j < jj; j++) {
  41612. ps[j] *= 2;
  41613. cs[j] *= 3;
  41614. }
  41615. }
  41616. }
  41617. function Mesh(stream, matrix, xref, res) {
  41618. assert(isStream(stream), 'Mesh data is not a stream');
  41619. var dict = stream.dict;
  41620. this.matrix = matrix;
  41621. this.shadingType = dict.get('ShadingType');
  41622. this.type = 'Pattern';
  41623. this.bbox = dict.get('BBox');
  41624. var cs = dict.get('ColorSpace', 'CS');
  41625. cs = ColorSpace.parse(cs, xref, res);
  41626. this.cs = cs;
  41627. this.background = dict.has('Background') ?
  41628. cs.getRgb(dict.get('Background'), 0) : null;
  41629. var fnObj = dict.get('Function');
  41630. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  41631. this.coords = [];
  41632. this.colors = [];
  41633. this.figures = [];
  41634. var decodeContext = {
  41635. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  41636. bitsPerComponent: dict.get('BitsPerComponent'),
  41637. bitsPerFlag: dict.get('BitsPerFlag'),
  41638. decode: dict.get('Decode'),
  41639. colorFn: fn,
  41640. colorSpace: cs,
  41641. numComps: fn ? 1 : cs.numComps
  41642. };
  41643. var reader = new MeshStreamReader(stream, decodeContext);
  41644. var patchMesh = false;
  41645. switch (this.shadingType) {
  41646. case ShadingType.FREE_FORM_MESH:
  41647. decodeType4Shading(this, reader);
  41648. break;
  41649. case ShadingType.LATTICE_FORM_MESH:
  41650. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  41651. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  41652. decodeType5Shading(this, reader, verticesPerRow);
  41653. break;
  41654. case ShadingType.COONS_PATCH_MESH:
  41655. decodeType6Shading(this, reader);
  41656. patchMesh = true;
  41657. break;
  41658. case ShadingType.TENSOR_PATCH_MESH:
  41659. decodeType7Shading(this, reader);
  41660. patchMesh = true;
  41661. break;
  41662. default:
  41663. error('Unsupported mesh type.');
  41664. break;
  41665. }
  41666. if (patchMesh) {
  41667. // dirty bounds calculation for determining, how dense shall be triangles
  41668. updateBounds(this);
  41669. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  41670. buildFigureFromPatch(this, i);
  41671. }
  41672. }
  41673. // calculate bounds
  41674. updateBounds(this);
  41675. packData(this);
  41676. }
  41677. Mesh.prototype = {
  41678. getIR: function Mesh_getIR() {
  41679. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  41680. this.bounds, this.matrix, this.bbox, this.background];
  41681. }
  41682. };
  41683. return Mesh;
  41684. })();
  41685. Shadings.Dummy = (function DummyClosure() {
  41686. function Dummy() {
  41687. this.type = 'Pattern';
  41688. }
  41689. Dummy.prototype = {
  41690. getIR: function Dummy_getIR() {
  41691. return ['Dummy'];
  41692. }
  41693. };
  41694. return Dummy;
  41695. })();
  41696. function getTilingPatternIR(operatorList, dict, args) {
  41697. var matrix = dict.get('Matrix');
  41698. var bbox = dict.get('BBox');
  41699. var xstep = dict.get('XStep');
  41700. var ystep = dict.get('YStep');
  41701. var paintType = dict.get('PaintType');
  41702. var tilingType = dict.get('TilingType');
  41703. return [
  41704. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  41705. paintType, tilingType
  41706. ];
  41707. }
  41708. exports.Pattern = Pattern;
  41709. exports.getTilingPatternIR = getTilingPatternIR;
  41710. }));
  41711. (function (root, factory) {
  41712. {
  41713. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  41714. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  41715. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  41716. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  41717. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  41718. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  41719. root.pdfjsCoreUnicode);
  41720. }
  41721. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  41722. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  41723. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  41724. coreEncodings, coreStandardFonts, coreUnicode) {
  41725. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  41726. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  41727. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41728. var ImageKind = sharedUtil.ImageKind;
  41729. var OPS = sharedUtil.OPS;
  41730. var TextRenderingMode = sharedUtil.TextRenderingMode;
  41731. var Util = sharedUtil.Util;
  41732. var assert = sharedUtil.assert;
  41733. var createPromiseCapability = sharedUtil.createPromiseCapability;
  41734. var error = sharedUtil.error;
  41735. var info = sharedUtil.info;
  41736. var isArray = sharedUtil.isArray;
  41737. var isNum = sharedUtil.isNum;
  41738. var isString = sharedUtil.isString;
  41739. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  41740. var warn = sharedUtil.warn;
  41741. var Dict = corePrimitives.Dict;
  41742. var Name = corePrimitives.Name;
  41743. var isCmd = corePrimitives.isCmd;
  41744. var isDict = corePrimitives.isDict;
  41745. var isName = corePrimitives.isName;
  41746. var isRef = corePrimitives.isRef;
  41747. var isStream = corePrimitives.isStream;
  41748. var DecodeStream = coreStream.DecodeStream;
  41749. var JpegStream = coreStream.JpegStream;
  41750. var Lexer = coreParser.Lexer;
  41751. var Parser = coreParser.Parser;
  41752. var isEOF = coreParser.isEOF;
  41753. var PDFImage = coreImage.PDFImage;
  41754. var ColorSpace = coreColorSpace.ColorSpace;
  41755. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  41756. var ErrorFont = coreFonts.ErrorFont;
  41757. var FontFlags = coreFonts.FontFlags;
  41758. var Font = coreFonts.Font;
  41759. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  41760. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  41761. var getFontType = coreFonts.getFontType;
  41762. var isPDFFunction = coreFunction.isPDFFunction;
  41763. var PDFFunction = coreFunction.PDFFunction;
  41764. var Pattern = corePattern.Pattern;
  41765. var getTilingPatternIR = corePattern.getTilingPatternIR;
  41766. var CMapFactory = coreCMap.CMapFactory;
  41767. var IdentityCMap = coreCMap.IdentityCMap;
  41768. var getMetrics = coreMetrics.getMetrics;
  41769. var bidi = coreBidi.bidi;
  41770. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  41771. var StandardEncoding = coreEncodings.StandardEncoding;
  41772. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  41773. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  41774. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  41775. var getEncoding = coreEncodings.getEncoding;
  41776. var getStdFontMap = coreStandardFonts.getStdFontMap;
  41777. var getSerifFonts = coreStandardFonts.getSerifFonts;
  41778. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  41779. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  41780. var reverseIfRtl = coreUnicode.reverseIfRtl;
  41781. var PartialEvaluator = (function PartialEvaluatorClosure() {
  41782. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  41783. uniquePrefix, idCounters, fontCache) {
  41784. this.pdfManager = pdfManager;
  41785. this.xref = xref;
  41786. this.handler = handler;
  41787. this.pageIndex = pageIndex;
  41788. this.uniquePrefix = uniquePrefix;
  41789. this.idCounters = idCounters;
  41790. this.fontCache = fontCache;
  41791. }
  41792. // Trying to minimize Date.now() usage and check every 100 time
  41793. var TIME_SLOT_DURATION_MS = 20;
  41794. var CHECK_TIME_EVERY = 100;
  41795. function TimeSlotManager() {
  41796. this.reset();
  41797. }
  41798. TimeSlotManager.prototype = {
  41799. check: function TimeSlotManager_check() {
  41800. if (++this.checked < CHECK_TIME_EVERY) {
  41801. return false;
  41802. }
  41803. this.checked = 0;
  41804. return this.endTime <= Date.now();
  41805. },
  41806. reset: function TimeSlotManager_reset() {
  41807. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  41808. this.checked = 0;
  41809. }
  41810. };
  41811. var deferred = Promise.resolve();
  41812. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  41813. PartialEvaluator.prototype = {
  41814. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  41815. if (!isDict(resources)) {
  41816. return false;
  41817. }
  41818. var processed = Object.create(null);
  41819. if (resources.objId) {
  41820. processed[resources.objId] = true;
  41821. }
  41822. var nodes = [resources], xref = this.xref;
  41823. while (nodes.length) {
  41824. var key, i, ii;
  41825. var node = nodes.shift();
  41826. // First check the current resources for blend modes.
  41827. var graphicStates = node.get('ExtGState');
  41828. if (isDict(graphicStates)) {
  41829. var graphicStatesKeys = graphicStates.getKeys();
  41830. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  41831. key = graphicStatesKeys[i];
  41832. var graphicState = graphicStates.get(key);
  41833. var bm = graphicState.get('BM');
  41834. if (isName(bm) && bm.name !== 'Normal') {
  41835. return true;
  41836. }
  41837. }
  41838. }
  41839. // Descend into the XObjects to look for more resources and blend modes.
  41840. var xObjects = node.get('XObject');
  41841. if (!isDict(xObjects)) {
  41842. continue;
  41843. }
  41844. var xObjectsKeys = xObjects.getKeys();
  41845. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  41846. key = xObjectsKeys[i];
  41847. var xObject = xObjects.getRaw(key);
  41848. if (isRef(xObject)) {
  41849. if (processed[xObject.toString()]) {
  41850. // The XObject has already been processed, and by avoiding a
  41851. // redundant `xref.fetch` we can *significantly* reduce the load
  41852. // time for badly generated PDF files (fixes issue6961.pdf).
  41853. continue;
  41854. }
  41855. xObject = xref.fetch(xObject);
  41856. }
  41857. if (!isStream(xObject)) {
  41858. continue;
  41859. }
  41860. if (xObject.dict.objId) {
  41861. if (processed[xObject.dict.objId]) {
  41862. // stream has objId and is processed already
  41863. continue;
  41864. }
  41865. processed[xObject.dict.objId] = true;
  41866. }
  41867. var xResources = xObject.dict.get('Resources');
  41868. // Checking objId to detect an infinite loop.
  41869. if (isDict(xResources) &&
  41870. (!xResources.objId || !processed[xResources.objId])) {
  41871. nodes.push(xResources);
  41872. if (xResources.objId) {
  41873. processed[xResources.objId] = true;
  41874. }
  41875. }
  41876. }
  41877. }
  41878. return false;
  41879. },
  41880. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  41881. xobj, smask,
  41882. operatorList,
  41883. task,
  41884. initialState) {
  41885. var matrix = xobj.dict.getArray('Matrix');
  41886. var bbox = xobj.dict.getArray('BBox');
  41887. var group = xobj.dict.get('Group');
  41888. if (group) {
  41889. var groupOptions = {
  41890. matrix: matrix,
  41891. bbox: bbox,
  41892. smask: smask,
  41893. isolated: false,
  41894. knockout: false
  41895. };
  41896. var groupSubtype = group.get('S');
  41897. var colorSpace;
  41898. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  41899. groupOptions.isolated = (group.get('I') || false);
  41900. groupOptions.knockout = (group.get('K') || false);
  41901. colorSpace = (group.has('CS') ?
  41902. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  41903. }
  41904. if (smask && smask.backdrop) {
  41905. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  41906. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  41907. }
  41908. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  41909. }
  41910. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  41911. return this.getOperatorList(xobj, task,
  41912. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  41913. then(function () {
  41914. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  41915. if (group) {
  41916. operatorList.addOp(OPS.endGroup, [groupOptions]);
  41917. }
  41918. });
  41919. },
  41920. buildPaintImageXObject:
  41921. function PartialEvaluator_buildPaintImageXObject(resources, image,
  41922. inline, operatorList,
  41923. cacheKey, imageCache) {
  41924. var self = this;
  41925. var dict = image.dict;
  41926. var w = dict.get('Width', 'W');
  41927. var h = dict.get('Height', 'H');
  41928. if (!(w && isNum(w)) || !(h && isNum(h))) {
  41929. warn('Image dimensions are missing, or not numbers.');
  41930. return;
  41931. }
  41932. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  41933. warn('Image exceeded maximum allowed size and was removed.');
  41934. return;
  41935. }
  41936. var imageMask = (dict.get('ImageMask', 'IM') || false);
  41937. var imgData, args;
  41938. if (imageMask) {
  41939. // This depends on a tmpCanvas being filled with the
  41940. // current fillStyle, such that processing the pixel
  41941. // data can't be done here. Instead of creating a
  41942. // complete PDFImage, only read the information needed
  41943. // for later.
  41944. var width = dict.get('Width', 'W');
  41945. var height = dict.get('Height', 'H');
  41946. var bitStrideLength = (width + 7) >> 3;
  41947. var imgArray = image.getBytes(bitStrideLength * height);
  41948. var decode = dict.get('Decode', 'D');
  41949. var inverseDecode = (!!decode && decode[0] > 0);
  41950. imgData = PDFImage.createMask(imgArray, width, height,
  41951. image instanceof DecodeStream,
  41952. inverseDecode);
  41953. imgData.cached = true;
  41954. args = [imgData];
  41955. operatorList.addOp(OPS.paintImageMaskXObject, args);
  41956. if (cacheKey) {
  41957. imageCache[cacheKey] = {
  41958. fn: OPS.paintImageMaskXObject,
  41959. args: args
  41960. };
  41961. }
  41962. return;
  41963. }
  41964. var softMask = (dict.get('SMask', 'SM') || false);
  41965. var mask = (dict.get('Mask') || false);
  41966. var SMALL_IMAGE_DIMENSIONS = 200;
  41967. // Inlining small images into the queue as RGB data
  41968. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  41969. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  41970. var imageObj = new PDFImage(this.xref, resources, image,
  41971. inline, null, null);
  41972. // We force the use of RGBA_32BPP images here, because we can't handle
  41973. // any other kind.
  41974. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  41975. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  41976. return;
  41977. }
  41978. // If there is no imageMask, create the PDFImage and a lot
  41979. // of image processing can be done here.
  41980. var uniquePrefix = (this.uniquePrefix || '');
  41981. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  41982. operatorList.addDependency(objId);
  41983. args = [objId, w, h];
  41984. if (!softMask && !mask && image instanceof JpegStream &&
  41985. image.isNativelySupported(this.xref, resources)) {
  41986. // These JPEGs don't need any more processing so we can just send it.
  41987. operatorList.addOp(OPS.paintJpegXObject, args);
  41988. this.handler.send('obj',
  41989. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  41990. return;
  41991. }
  41992. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  41993. then(function(imageObj) {
  41994. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  41995. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  41996. [imgData.data.buffer]);
  41997. }).then(undefined, function (reason) {
  41998. warn('Unable to decode image: ' + reason);
  41999. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  42000. });
  42001. operatorList.addOp(OPS.paintImageXObject, args);
  42002. if (cacheKey) {
  42003. imageCache[cacheKey] = {
  42004. fn: OPS.paintImageXObject,
  42005. args: args
  42006. };
  42007. }
  42008. },
  42009. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  42010. operatorList, task,
  42011. stateManager) {
  42012. var smaskContent = smask.get('G');
  42013. var smaskOptions = {
  42014. subtype: smask.get('S').name,
  42015. backdrop: smask.get('BC')
  42016. };
  42017. // The SMask might have a alpha/luminosity value transfer function --
  42018. // we will build a map of integer values in range 0..255 to be fast.
  42019. var transferObj = smask.get('TR');
  42020. if (isPDFFunction(transferObj)) {
  42021. var transferFn = PDFFunction.parse(this.xref, transferObj);
  42022. var transferMap = new Uint8Array(256);
  42023. var tmp = new Float32Array(1);
  42024. for (var i = 0; i < 256; i++) {
  42025. tmp[0] = i / 255;
  42026. transferFn(tmp, 0, tmp, 0);
  42027. transferMap[i] = (tmp[0] * 255) | 0;
  42028. }
  42029. smaskOptions.transferMap = transferMap;
  42030. }
  42031. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  42032. operatorList, task, stateManager.state.clone());
  42033. },
  42034. handleTilingType:
  42035. function PartialEvaluator_handleTilingType(fn, args, resources,
  42036. pattern, patternDict,
  42037. operatorList, task) {
  42038. // Create an IR of the pattern code.
  42039. var tilingOpList = new OperatorList();
  42040. // Merge the available resources, to prevent issues when the patternDict
  42041. // is missing some /Resources entries (fixes issue6541.pdf).
  42042. var resourcesArray = [patternDict.get('Resources'), resources];
  42043. var patternResources = Dict.merge(this.xref, resourcesArray);
  42044. return this.getOperatorList(pattern, task, patternResources,
  42045. tilingOpList).then(function () {
  42046. // Add the dependencies to the parent operator list so they are
  42047. // resolved before sub operator list is executed synchronously.
  42048. operatorList.addDependencies(tilingOpList.dependencies);
  42049. operatorList.addOp(fn, getTilingPatternIR({
  42050. fnArray: tilingOpList.fnArray,
  42051. argsArray: tilingOpList.argsArray
  42052. }, patternDict, args));
  42053. });
  42054. },
  42055. handleSetFont:
  42056. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  42057. operatorList, task, state) {
  42058. // TODO(mack): Not needed?
  42059. var fontName;
  42060. if (fontArgs) {
  42061. fontArgs = fontArgs.slice();
  42062. fontName = fontArgs[0].name;
  42063. }
  42064. var self = this;
  42065. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  42066. function (translated) {
  42067. if (!translated.font.isType3Font) {
  42068. return translated;
  42069. }
  42070. return translated.loadType3Data(self, resources, operatorList, task).
  42071. then(function () {
  42072. return translated;
  42073. }, function (reason) {
  42074. // Error in the font data -- sending unsupported feature notification.
  42075. self.handler.send('UnsupportedFeature',
  42076. {featureId: UNSUPPORTED_FEATURES.font});
  42077. return new TranslatedFont('g_font_error',
  42078. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  42079. });
  42080. }).then(function (translated) {
  42081. state.font = translated.font;
  42082. translated.send(self.handler);
  42083. return translated.loadedName;
  42084. });
  42085. },
  42086. handleText: function PartialEvaluator_handleText(chars, state) {
  42087. var font = state.font;
  42088. var glyphs = font.charsToGlyphs(chars);
  42089. var isAddToPathSet = !!(state.textRenderingMode &
  42090. TextRenderingMode.ADD_TO_PATH_FLAG);
  42091. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  42092. var buildPath = function (fontChar) {
  42093. if (!font.renderer.hasBuiltPath(fontChar)) {
  42094. var path = font.renderer.getPathJs(fontChar);
  42095. this.handler.send('commonobj', [
  42096. font.loadedName + '_path_' + fontChar,
  42097. 'FontPath',
  42098. path
  42099. ]);
  42100. }
  42101. }.bind(this);
  42102. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  42103. var glyph = glyphs[i];
  42104. buildPath(glyph.fontChar);
  42105. // If the glyph has an accent we need to build a path for its
  42106. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  42107. var accent = glyph.accent;
  42108. if (accent && accent.fontChar) {
  42109. buildPath(accent.fontChar);
  42110. }
  42111. }
  42112. }
  42113. return glyphs;
  42114. },
  42115. setGState: function PartialEvaluator_setGState(resources, gState,
  42116. operatorList, task,
  42117. xref, stateManager) {
  42118. // This array holds the converted/processed state data.
  42119. var gStateObj = [];
  42120. var gStateKeys = gState.getKeys();
  42121. var self = this;
  42122. var promise = Promise.resolve();
  42123. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  42124. var key = gStateKeys[i];
  42125. var value = gState.get(key);
  42126. switch (key) {
  42127. case 'Type':
  42128. break;
  42129. case 'LW':
  42130. case 'LC':
  42131. case 'LJ':
  42132. case 'ML':
  42133. case 'D':
  42134. case 'RI':
  42135. case 'FL':
  42136. case 'CA':
  42137. case 'ca':
  42138. gStateObj.push([key, value]);
  42139. break;
  42140. case 'Font':
  42141. promise = promise.then(function () {
  42142. return self.handleSetFont(resources, null, value[0], operatorList,
  42143. task, stateManager.state).
  42144. then(function (loadedName) {
  42145. operatorList.addDependency(loadedName);
  42146. gStateObj.push([key, [loadedName, value[1]]]);
  42147. });
  42148. });
  42149. break;
  42150. case 'BM':
  42151. gStateObj.push([key, value]);
  42152. break;
  42153. case 'SMask':
  42154. if (isName(value) && value.name === 'None') {
  42155. gStateObj.push([key, false]);
  42156. break;
  42157. }
  42158. if (isDict(value)) {
  42159. promise = promise.then(function (dict) {
  42160. return self.handleSMask(dict, resources, operatorList,
  42161. task, stateManager);
  42162. }.bind(this, value));
  42163. gStateObj.push([key, true]);
  42164. } else {
  42165. warn('Unsupported SMask type');
  42166. }
  42167. break;
  42168. // Only generate info log messages for the following since
  42169. // they are unlikely to have a big impact on the rendering.
  42170. case 'OP':
  42171. case 'op':
  42172. case 'OPM':
  42173. case 'BG':
  42174. case 'BG2':
  42175. case 'UCR':
  42176. case 'UCR2':
  42177. case 'TR':
  42178. case 'TR2':
  42179. case 'HT':
  42180. case 'SM':
  42181. case 'SA':
  42182. case 'AIS':
  42183. case 'TK':
  42184. // TODO implement these operators.
  42185. info('graphic state operator ' + key);
  42186. break;
  42187. default:
  42188. info('Unknown graphic state operator ' + key);
  42189. break;
  42190. }
  42191. }
  42192. return promise.then(function () {
  42193. if (gStateObj.length > 0) {
  42194. operatorList.addOp(OPS.setGState, [gStateObj]);
  42195. }
  42196. });
  42197. },
  42198. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  42199. resources) {
  42200. function errorFont() {
  42201. return Promise.resolve(new TranslatedFont('g_font_error',
  42202. new ErrorFont('Font ' + fontName + ' is not available'), font));
  42203. }
  42204. var fontRef;
  42205. if (font) { // Loading by ref.
  42206. assert(isRef(font));
  42207. fontRef = font;
  42208. } else { // Loading by name.
  42209. var fontRes = resources.get('Font');
  42210. if (fontRes) {
  42211. fontRef = fontRes.getRaw(fontName);
  42212. } else {
  42213. warn('fontRes not available');
  42214. return errorFont();
  42215. }
  42216. }
  42217. if (!fontRef) {
  42218. warn('fontRef not available');
  42219. return errorFont();
  42220. }
  42221. if (this.fontCache.has(fontRef)) {
  42222. return this.fontCache.get(fontRef);
  42223. }
  42224. font = xref.fetchIfRef(fontRef);
  42225. if (!isDict(font)) {
  42226. return errorFont();
  42227. }
  42228. // We are holding font.translated references just for fontRef that are not
  42229. // dictionaries (Dict). See explanation below.
  42230. if (font.translated) {
  42231. return font.translated;
  42232. }
  42233. var fontCapability = createPromiseCapability();
  42234. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  42235. var descriptor = preEvaluatedFont.descriptor;
  42236. var fontID = fontRef.num + '_' + fontRef.gen;
  42237. if (isDict(descriptor)) {
  42238. if (!descriptor.fontAliases) {
  42239. descriptor.fontAliases = Object.create(null);
  42240. }
  42241. var fontAliases = descriptor.fontAliases;
  42242. var hash = preEvaluatedFont.hash;
  42243. if (fontAliases[hash]) {
  42244. var aliasFontRef = fontAliases[hash].aliasRef;
  42245. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  42246. this.fontCache.putAlias(fontRef, aliasFontRef);
  42247. return this.fontCache.get(fontRef);
  42248. }
  42249. }
  42250. if (!fontAliases[hash]) {
  42251. fontAliases[hash] = {
  42252. fontID: Font.getFontID()
  42253. };
  42254. }
  42255. fontAliases[hash].aliasRef = fontRef;
  42256. fontID = fontAliases[hash].fontID;
  42257. }
  42258. // Workaround for bad PDF generators that don't reference fonts
  42259. // properly, i.e. by not using an object identifier.
  42260. // Check if the fontRef is a Dict (as opposed to a standard object),
  42261. // in which case we don't cache the font and instead reference it by
  42262. // fontName in font.loadedName below.
  42263. var fontRefIsDict = isDict(fontRef);
  42264. if (!fontRefIsDict) {
  42265. this.fontCache.put(fontRef, fontCapability.promise);
  42266. }
  42267. // Keep track of each font we translated so the caller can
  42268. // load them asynchronously before calling display on a page.
  42269. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  42270. fontName.replace(/\W/g, '') : fontID);
  42271. font.translated = fontCapability.promise;
  42272. // TODO move promises into translate font
  42273. var translatedPromise;
  42274. try {
  42275. translatedPromise = Promise.resolve(
  42276. this.translateFont(preEvaluatedFont, xref));
  42277. } catch (e) {
  42278. translatedPromise = Promise.reject(e);
  42279. }
  42280. var self = this;
  42281. translatedPromise.then(function (translatedFont) {
  42282. if (translatedFont.fontType !== undefined) {
  42283. var xrefFontStats = xref.stats.fontTypes;
  42284. xrefFontStats[translatedFont.fontType] = true;
  42285. }
  42286. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42287. translatedFont, font));
  42288. }, function (reason) {
  42289. // TODO fontCapability.reject?
  42290. // Error in the font data -- sending unsupported feature notification.
  42291. self.handler.send('UnsupportedFeature',
  42292. {featureId: UNSUPPORTED_FEATURES.font});
  42293. try {
  42294. // error, but it's still nice to have font type reported
  42295. var descriptor = preEvaluatedFont.descriptor;
  42296. var fontFile3 = descriptor && descriptor.get('FontFile3');
  42297. var subtype = fontFile3 && fontFile3.get('Subtype');
  42298. var fontType = getFontType(preEvaluatedFont.type,
  42299. subtype && subtype.name);
  42300. var xrefFontStats = xref.stats.fontTypes;
  42301. xrefFontStats[fontType] = true;
  42302. } catch (ex) { }
  42303. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42304. new ErrorFont(reason instanceof Error ? reason.message : reason),
  42305. font));
  42306. });
  42307. return fontCapability.promise;
  42308. },
  42309. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  42310. var lastIndex = operatorList.length - 1;
  42311. if (!args) {
  42312. args = [];
  42313. }
  42314. if (lastIndex < 0 ||
  42315. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  42316. operatorList.addOp(OPS.constructPath, [[fn], args]);
  42317. } else {
  42318. var opArgs = operatorList.argsArray[lastIndex];
  42319. opArgs[0].push(fn);
  42320. Array.prototype.push.apply(opArgs[1], args);
  42321. }
  42322. },
  42323. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  42324. cs, patterns, resources, task, xref) {
  42325. // compile tiling patterns
  42326. var patternName = args[args.length - 1];
  42327. // SCN/scn applies patterns along with normal colors
  42328. var pattern;
  42329. if (isName(patternName) &&
  42330. (pattern = patterns.get(patternName.name))) {
  42331. var dict = (isStream(pattern) ? pattern.dict : pattern);
  42332. var typeNum = dict.get('PatternType');
  42333. if (typeNum === TILING_PATTERN) {
  42334. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  42335. return this.handleTilingType(fn, color, resources, pattern,
  42336. dict, operatorList, task);
  42337. } else if (typeNum === SHADING_PATTERN) {
  42338. var shading = dict.get('Shading');
  42339. var matrix = dict.get('Matrix');
  42340. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  42341. this.handler);
  42342. operatorList.addOp(fn, pattern.getIR());
  42343. return Promise.resolve();
  42344. } else {
  42345. return Promise.reject('Unknown PatternType: ' + typeNum);
  42346. }
  42347. }
  42348. // TODO shall we fail here?
  42349. operatorList.addOp(fn, args);
  42350. return Promise.resolve();
  42351. },
  42352. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  42353. task,
  42354. resources,
  42355. operatorList,
  42356. initialState) {
  42357. var self = this;
  42358. var xref = this.xref;
  42359. var imageCache = Object.create(null);
  42360. assert(operatorList);
  42361. resources = (resources || Dict.empty);
  42362. var xobjs = (resources.get('XObject') || Dict.empty);
  42363. var patterns = (resources.get('Pattern') || Dict.empty);
  42364. var stateManager = new StateManager(initialState || new EvalState());
  42365. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42366. var timeSlotManager = new TimeSlotManager();
  42367. return new Promise(function next(resolve, reject) {
  42368. task.ensureNotTerminated();
  42369. timeSlotManager.reset();
  42370. var stop, operation = {}, i, ii, cs;
  42371. while (!(stop = timeSlotManager.check())) {
  42372. // The arguments parsed by read() are used beyond this loop, so we
  42373. // cannot reuse the same array on each iteration. Therefore we pass
  42374. // in |null| as the initial value (see the comment on
  42375. // EvaluatorPreprocessor_read() for why).
  42376. operation.args = null;
  42377. if (!(preprocessor.read(operation))) {
  42378. break;
  42379. }
  42380. var args = operation.args;
  42381. var fn = operation.fn;
  42382. switch (fn | 0) {
  42383. case OPS.paintXObject:
  42384. if (args[0].code) {
  42385. break;
  42386. }
  42387. // eagerly compile XForm objects
  42388. var name = args[0].name;
  42389. if (!name) {
  42390. warn('XObject must be referred to by name.');
  42391. continue;
  42392. }
  42393. if (imageCache[name] !== undefined) {
  42394. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  42395. args = null;
  42396. continue;
  42397. }
  42398. var xobj = xobjs.get(name);
  42399. if (xobj) {
  42400. assert(isStream(xobj), 'XObject should be a stream');
  42401. var type = xobj.dict.get('Subtype');
  42402. assert(isName(type),
  42403. 'XObject should have a Name subtype');
  42404. if (type.name === 'Form') {
  42405. stateManager.save();
  42406. return self.buildFormXObject(resources, xobj, null,
  42407. operatorList, task,
  42408. stateManager.state.clone()).
  42409. then(function () {
  42410. stateManager.restore();
  42411. next(resolve, reject);
  42412. }, reject);
  42413. } else if (type.name === 'Image') {
  42414. self.buildPaintImageXObject(resources, xobj, false,
  42415. operatorList, name, imageCache);
  42416. args = null;
  42417. continue;
  42418. } else if (type.name === 'PS') {
  42419. // PostScript XObjects are unused when viewing documents.
  42420. // See section 4.7.1 of Adobe's PDF reference.
  42421. info('Ignored XObject subtype PS');
  42422. continue;
  42423. } else {
  42424. error('Unhandled XObject subtype ' + type.name);
  42425. }
  42426. }
  42427. break;
  42428. case OPS.setFont:
  42429. var fontSize = args[1];
  42430. // eagerly collect all fonts
  42431. return self.handleSetFont(resources, args, null, operatorList,
  42432. task, stateManager.state).
  42433. then(function (loadedName) {
  42434. operatorList.addDependency(loadedName);
  42435. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  42436. next(resolve, reject);
  42437. }, reject);
  42438. case OPS.endInlineImage:
  42439. var cacheKey = args[0].cacheKey;
  42440. if (cacheKey) {
  42441. var cacheEntry = imageCache[cacheKey];
  42442. if (cacheEntry !== undefined) {
  42443. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  42444. args = null;
  42445. continue;
  42446. }
  42447. }
  42448. self.buildPaintImageXObject(resources, args[0], true,
  42449. operatorList, cacheKey, imageCache);
  42450. args = null;
  42451. continue;
  42452. case OPS.showText:
  42453. args[0] = self.handleText(args[0], stateManager.state);
  42454. break;
  42455. case OPS.showSpacedText:
  42456. var arr = args[0];
  42457. var combinedGlyphs = [];
  42458. var arrLength = arr.length;
  42459. var state = stateManager.state;
  42460. for (i = 0; i < arrLength; ++i) {
  42461. var arrItem = arr[i];
  42462. if (isString(arrItem)) {
  42463. Array.prototype.push.apply(combinedGlyphs,
  42464. self.handleText(arrItem, state));
  42465. } else if (isNum(arrItem)) {
  42466. combinedGlyphs.push(arrItem);
  42467. }
  42468. }
  42469. args[0] = combinedGlyphs;
  42470. fn = OPS.showText;
  42471. break;
  42472. case OPS.nextLineShowText:
  42473. operatorList.addOp(OPS.nextLine);
  42474. args[0] = self.handleText(args[0], stateManager.state);
  42475. fn = OPS.showText;
  42476. break;
  42477. case OPS.nextLineSetSpacingShowText:
  42478. operatorList.addOp(OPS.nextLine);
  42479. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  42480. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  42481. args[0] = self.handleText(args[0], stateManager.state);
  42482. fn = OPS.showText;
  42483. break;
  42484. case OPS.setTextRenderingMode:
  42485. stateManager.state.textRenderingMode = args[0];
  42486. break;
  42487. case OPS.setFillColorSpace:
  42488. stateManager.state.fillColorSpace =
  42489. ColorSpace.parse(args[0], xref, resources);
  42490. continue;
  42491. case OPS.setStrokeColorSpace:
  42492. stateManager.state.strokeColorSpace =
  42493. ColorSpace.parse(args[0], xref, resources);
  42494. continue;
  42495. case OPS.setFillColor:
  42496. cs = stateManager.state.fillColorSpace;
  42497. args = cs.getRgb(args, 0);
  42498. fn = OPS.setFillRGBColor;
  42499. break;
  42500. case OPS.setStrokeColor:
  42501. cs = stateManager.state.strokeColorSpace;
  42502. args = cs.getRgb(args, 0);
  42503. fn = OPS.setStrokeRGBColor;
  42504. break;
  42505. case OPS.setFillGray:
  42506. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  42507. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42508. fn = OPS.setFillRGBColor;
  42509. break;
  42510. case OPS.setStrokeGray:
  42511. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  42512. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42513. fn = OPS.setStrokeRGBColor;
  42514. break;
  42515. case OPS.setFillCMYKColor:
  42516. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  42517. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42518. fn = OPS.setFillRGBColor;
  42519. break;
  42520. case OPS.setStrokeCMYKColor:
  42521. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  42522. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42523. fn = OPS.setStrokeRGBColor;
  42524. break;
  42525. case OPS.setFillRGBColor:
  42526. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  42527. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42528. break;
  42529. case OPS.setStrokeRGBColor:
  42530. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  42531. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42532. break;
  42533. case OPS.setFillColorN:
  42534. cs = stateManager.state.fillColorSpace;
  42535. if (cs.name === 'Pattern') {
  42536. return self.handleColorN(operatorList, OPS.setFillColorN,
  42537. args, cs, patterns, resources, task, xref).then(function() {
  42538. next(resolve, reject);
  42539. }, reject);
  42540. }
  42541. args = cs.getRgb(args, 0);
  42542. fn = OPS.setFillRGBColor;
  42543. break;
  42544. case OPS.setStrokeColorN:
  42545. cs = stateManager.state.strokeColorSpace;
  42546. if (cs.name === 'Pattern') {
  42547. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  42548. args, cs, patterns, resources, task, xref).then(function() {
  42549. next(resolve, reject);
  42550. }, reject);
  42551. }
  42552. args = cs.getRgb(args, 0);
  42553. fn = OPS.setStrokeRGBColor;
  42554. break;
  42555. case OPS.shadingFill:
  42556. var shadingRes = resources.get('Shading');
  42557. if (!shadingRes) {
  42558. error('No shading resource found');
  42559. }
  42560. var shading = shadingRes.get(args[0].name);
  42561. if (!shading) {
  42562. error('No shading object found');
  42563. }
  42564. var shadingFill = Pattern.parseShading(shading, null, xref,
  42565. resources, self.handler);
  42566. var patternIR = shadingFill.getIR();
  42567. args = [patternIR];
  42568. fn = OPS.shadingFill;
  42569. break;
  42570. case OPS.setGState:
  42571. var dictName = args[0];
  42572. var extGState = resources.get('ExtGState');
  42573. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42574. break;
  42575. }
  42576. var gState = extGState.get(dictName.name);
  42577. return self.setGState(resources, gState, operatorList, task,
  42578. xref, stateManager).then(function() {
  42579. next(resolve, reject);
  42580. }, reject);
  42581. case OPS.moveTo:
  42582. case OPS.lineTo:
  42583. case OPS.curveTo:
  42584. case OPS.curveTo2:
  42585. case OPS.curveTo3:
  42586. case OPS.closePath:
  42587. self.buildPath(operatorList, fn, args);
  42588. continue;
  42589. case OPS.rectangle:
  42590. self.buildPath(operatorList, fn, args);
  42591. continue;
  42592. case OPS.markPoint:
  42593. case OPS.markPointProps:
  42594. case OPS.beginMarkedContent:
  42595. case OPS.beginMarkedContentProps:
  42596. case OPS.endMarkedContent:
  42597. case OPS.beginCompat:
  42598. case OPS.endCompat:
  42599. // Ignore operators where the corresponding handlers are known to
  42600. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  42601. // serialization errors and is also a bit more efficient.
  42602. // We could also try to serialize all objects in a general way,
  42603. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  42604. // but doing so is meaningless without knowing the semantics.
  42605. continue;
  42606. default:
  42607. // Note: Ignore the operator if it has `Dict` arguments, since
  42608. // those are non-serializable, otherwise postMessage will throw
  42609. // "An object could not be cloned.".
  42610. if (args !== null) {
  42611. for (i = 0, ii = args.length; i < ii; i++) {
  42612. if (args[i] instanceof Dict) {
  42613. break;
  42614. }
  42615. }
  42616. if (i < ii) {
  42617. warn('getOperatorList - ignoring operator: ' + fn);
  42618. continue;
  42619. }
  42620. }
  42621. }
  42622. operatorList.addOp(fn, args);
  42623. }
  42624. if (stop) {
  42625. deferred.then(function () {
  42626. next(resolve, reject);
  42627. }, reject);
  42628. return;
  42629. }
  42630. // Some PDFs don't close all restores inside object/form.
  42631. // Closing those for them.
  42632. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  42633. operatorList.addOp(OPS.restore, []);
  42634. }
  42635. resolve();
  42636. });
  42637. },
  42638. getTextContent:
  42639. function PartialEvaluator_getTextContent(stream, task, resources,
  42640. stateManager,
  42641. normalizeWhitespace) {
  42642. stateManager = (stateManager || new StateManager(new TextState()));
  42643. var WhitespaceRegexp = /\s/g;
  42644. var textContent = {
  42645. items: [],
  42646. styles: Object.create(null)
  42647. };
  42648. var textContentItem = {
  42649. initialized: false,
  42650. str: [],
  42651. width: 0,
  42652. height: 0,
  42653. vertical: false,
  42654. lastAdvanceWidth: 0,
  42655. lastAdvanceHeight: 0,
  42656. textAdvanceScale: 0,
  42657. spaceWidth: 0,
  42658. fakeSpaceMin: Infinity,
  42659. fakeMultiSpaceMin: Infinity,
  42660. fakeMultiSpaceMax: -0,
  42661. textRunBreakAllowed: false,
  42662. transform: null,
  42663. fontName: null
  42664. };
  42665. var SPACE_FACTOR = 0.3;
  42666. var MULTI_SPACE_FACTOR = 1.5;
  42667. var MULTI_SPACE_FACTOR_MAX = 4;
  42668. var self = this;
  42669. var xref = this.xref;
  42670. resources = (xref.fetchIfRef(resources) || Dict.empty);
  42671. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  42672. var xobjs = null;
  42673. var xobjsCache = Object.create(null);
  42674. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42675. var textState;
  42676. function ensureTextContentItem() {
  42677. if (textContentItem.initialized) {
  42678. return textContentItem;
  42679. }
  42680. var font = textState.font;
  42681. if (!(font.loadedName in textContent.styles)) {
  42682. textContent.styles[font.loadedName] = {
  42683. fontFamily: font.fallbackName,
  42684. ascent: font.ascent,
  42685. descent: font.descent,
  42686. vertical: font.vertical
  42687. };
  42688. }
  42689. textContentItem.fontName = font.loadedName;
  42690. // 9.4.4 Text Space Details
  42691. var tsm = [textState.fontSize * textState.textHScale, 0,
  42692. 0, textState.fontSize,
  42693. 0, textState.textRise];
  42694. if (font.isType3Font &&
  42695. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  42696. textState.fontSize === 1) {
  42697. var glyphHeight = font.bbox[3] - font.bbox[1];
  42698. if (glyphHeight > 0) {
  42699. glyphHeight = glyphHeight * textState.fontMatrix[3];
  42700. tsm[3] *= glyphHeight;
  42701. }
  42702. }
  42703. var trm = Util.transform(textState.ctm,
  42704. Util.transform(textState.textMatrix, tsm));
  42705. textContentItem.transform = trm;
  42706. if (!font.vertical) {
  42707. textContentItem.width = 0;
  42708. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  42709. textContentItem.vertical = false;
  42710. } else {
  42711. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  42712. textContentItem.height = 0;
  42713. textContentItem.vertical = true;
  42714. }
  42715. var a = textState.textLineMatrix[0];
  42716. var b = textState.textLineMatrix[1];
  42717. var scaleLineX = Math.sqrt(a * a + b * b);
  42718. a = textState.ctm[0];
  42719. b = textState.ctm[1];
  42720. var scaleCtmX = Math.sqrt(a * a + b * b);
  42721. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  42722. textContentItem.lastAdvanceWidth = 0;
  42723. textContentItem.lastAdvanceHeight = 0;
  42724. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  42725. if (spaceWidth) {
  42726. textContentItem.spaceWidth = spaceWidth;
  42727. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  42728. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  42729. textContentItem.fakeMultiSpaceMax =
  42730. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  42731. // It's okay for monospace fonts to fake as much space as needed.
  42732. textContentItem.textRunBreakAllowed = !font.isMonospace;
  42733. } else {
  42734. textContentItem.spaceWidth = 0;
  42735. textContentItem.fakeSpaceMin = Infinity;
  42736. textContentItem.fakeMultiSpaceMin = Infinity;
  42737. textContentItem.fakeMultiSpaceMax = 0;
  42738. textContentItem.textRunBreakAllowed = false;
  42739. }
  42740. textContentItem.initialized = true;
  42741. return textContentItem;
  42742. }
  42743. function replaceWhitespace(str) {
  42744. // Replaces all whitespaces with standard spaces (0x20), to avoid
  42745. // alignment issues between the textLayer and the canvas if the text
  42746. // contains e.g. tabs (fixes issue6612.pdf).
  42747. var i = 0, ii = str.length, code;
  42748. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  42749. i++;
  42750. }
  42751. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  42752. }
  42753. function runBidiTransform(textChunk) {
  42754. var str = textChunk.str.join('');
  42755. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  42756. return {
  42757. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  42758. bidiResult.str),
  42759. dir: bidiResult.dir,
  42760. width: textChunk.width,
  42761. height: textChunk.height,
  42762. transform: textChunk.transform,
  42763. fontName: textChunk.fontName
  42764. };
  42765. }
  42766. function handleSetFont(fontName, fontRef) {
  42767. return self.loadFont(fontName, fontRef, xref, resources).
  42768. then(function (translated) {
  42769. textState.font = translated.font;
  42770. textState.fontMatrix = translated.font.fontMatrix ||
  42771. FONT_IDENTITY_MATRIX;
  42772. });
  42773. }
  42774. function buildTextContentItem(chars) {
  42775. var font = textState.font;
  42776. var textChunk = ensureTextContentItem();
  42777. var width = 0;
  42778. var height = 0;
  42779. var glyphs = font.charsToGlyphs(chars);
  42780. var defaultVMetrics = font.defaultVMetrics;
  42781. for (var i = 0; i < glyphs.length; i++) {
  42782. var glyph = glyphs[i];
  42783. var vMetricX = null;
  42784. var vMetricY = null;
  42785. var glyphWidth = null;
  42786. if (font.vertical) {
  42787. if (glyph.vmetric) {
  42788. glyphWidth = glyph.vmetric[0];
  42789. vMetricX = glyph.vmetric[1];
  42790. vMetricY = glyph.vmetric[2];
  42791. } else {
  42792. glyphWidth = glyph.width;
  42793. vMetricX = glyph.width * 0.5;
  42794. vMetricY = defaultVMetrics[2];
  42795. }
  42796. } else {
  42797. glyphWidth = glyph.width;
  42798. }
  42799. var glyphUnicode = glyph.unicode;
  42800. var NormalizedUnicodes = getNormalizedUnicodes();
  42801. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  42802. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  42803. }
  42804. glyphUnicode = reverseIfRtl(glyphUnicode);
  42805. // The following will calculate the x and y of the individual glyphs.
  42806. // if (font.vertical) {
  42807. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  42808. // textState.fontMatrix[0];
  42809. // tsm[5] -= vMetricY * textState.fontSize *
  42810. // textState.fontMatrix[0];
  42811. // }
  42812. // var trm = Util.transform(textState.textMatrix, tsm);
  42813. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  42814. // var x = pt[0];
  42815. // var y = pt[1];
  42816. var charSpacing = textState.charSpacing;
  42817. if (glyph.isSpace) {
  42818. var wordSpacing = textState.wordSpacing;
  42819. charSpacing += wordSpacing;
  42820. if (wordSpacing > 0) {
  42821. addFakeSpaces(wordSpacing, textChunk.str);
  42822. }
  42823. }
  42824. var tx = 0;
  42825. var ty = 0;
  42826. if (!font.vertical) {
  42827. var w0 = glyphWidth * textState.fontMatrix[0];
  42828. tx = (w0 * textState.fontSize + charSpacing) *
  42829. textState.textHScale;
  42830. width += tx;
  42831. } else {
  42832. var w1 = glyphWidth * textState.fontMatrix[0];
  42833. ty = w1 * textState.fontSize + charSpacing;
  42834. height += ty;
  42835. }
  42836. textState.translateTextMatrix(tx, ty);
  42837. textChunk.str.push(glyphUnicode);
  42838. }
  42839. if (!font.vertical) {
  42840. textChunk.lastAdvanceWidth = width;
  42841. textChunk.width += width * textChunk.textAdvanceScale;
  42842. } else {
  42843. textChunk.lastAdvanceHeight = height;
  42844. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  42845. }
  42846. return textChunk;
  42847. }
  42848. function addFakeSpaces(width, strBuf) {
  42849. if (width < textContentItem.fakeSpaceMin) {
  42850. return;
  42851. }
  42852. if (width < textContentItem.fakeMultiSpaceMin) {
  42853. strBuf.push(' ');
  42854. return;
  42855. }
  42856. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  42857. while (fakeSpaces-- > 0) {
  42858. strBuf.push(' ');
  42859. }
  42860. }
  42861. function flushTextContentItem() {
  42862. if (!textContentItem.initialized) {
  42863. return;
  42864. }
  42865. textContent.items.push(runBidiTransform(textContentItem));
  42866. textContentItem.initialized = false;
  42867. textContentItem.str.length = 0;
  42868. }
  42869. var timeSlotManager = new TimeSlotManager();
  42870. return new Promise(function next(resolve, reject) {
  42871. task.ensureNotTerminated();
  42872. timeSlotManager.reset();
  42873. var stop, operation = {}, args = [];
  42874. while (!(stop = timeSlotManager.check())) {
  42875. // The arguments parsed by read() are not used beyond this loop, so
  42876. // we can reuse the same array on every iteration, thus avoiding
  42877. // unnecessary allocations.
  42878. args.length = 0;
  42879. operation.args = args;
  42880. if (!(preprocessor.read(operation))) {
  42881. break;
  42882. }
  42883. textState = stateManager.state;
  42884. var fn = operation.fn;
  42885. args = operation.args;
  42886. var advance;
  42887. switch (fn | 0) {
  42888. case OPS.setFont:
  42889. flushTextContentItem();
  42890. textState.fontSize = args[1];
  42891. return handleSetFont(args[0].name).then(function() {
  42892. next(resolve, reject);
  42893. }, reject);
  42894. case OPS.setTextRise:
  42895. flushTextContentItem();
  42896. textState.textRise = args[0];
  42897. break;
  42898. case OPS.setHScale:
  42899. flushTextContentItem();
  42900. textState.textHScale = args[0] / 100;
  42901. break;
  42902. case OPS.setLeading:
  42903. flushTextContentItem();
  42904. textState.leading = args[0];
  42905. break;
  42906. case OPS.moveText:
  42907. // Optimization to treat same line movement as advance
  42908. var isSameTextLine = !textState.font ? false :
  42909. ((textState.font.vertical ? args[0] : args[1]) === 0);
  42910. advance = args[0] - args[1];
  42911. if (isSameTextLine && textContentItem.initialized &&
  42912. advance > 0 &&
  42913. advance <= textContentItem.fakeMultiSpaceMax) {
  42914. textState.translateTextLineMatrix(args[0], args[1]);
  42915. textContentItem.width +=
  42916. (args[0] - textContentItem.lastAdvanceWidth);
  42917. textContentItem.height +=
  42918. (args[1] - textContentItem.lastAdvanceHeight);
  42919. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  42920. (args[1] - textContentItem.lastAdvanceHeight);
  42921. addFakeSpaces(diff, textContentItem.str);
  42922. break;
  42923. }
  42924. flushTextContentItem();
  42925. textState.translateTextLineMatrix(args[0], args[1]);
  42926. textState.textMatrix = textState.textLineMatrix.slice();
  42927. break;
  42928. case OPS.setLeadingMoveText:
  42929. flushTextContentItem();
  42930. textState.leading = -args[1];
  42931. textState.translateTextLineMatrix(args[0], args[1]);
  42932. textState.textMatrix = textState.textLineMatrix.slice();
  42933. break;
  42934. case OPS.nextLine:
  42935. flushTextContentItem();
  42936. textState.carriageReturn();
  42937. break;
  42938. case OPS.setTextMatrix:
  42939. flushTextContentItem();
  42940. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  42941. args[4], args[5]);
  42942. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  42943. args[4], args[5]);
  42944. break;
  42945. case OPS.setCharSpacing:
  42946. textState.charSpacing = args[0];
  42947. break;
  42948. case OPS.setWordSpacing:
  42949. textState.wordSpacing = args[0];
  42950. break;
  42951. case OPS.beginText:
  42952. flushTextContentItem();
  42953. textState.textMatrix = IDENTITY_MATRIX.slice();
  42954. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  42955. break;
  42956. case OPS.showSpacedText:
  42957. var items = args[0];
  42958. var offset;
  42959. for (var j = 0, jj = items.length; j < jj; j++) {
  42960. if (typeof items[j] === 'string') {
  42961. buildTextContentItem(items[j]);
  42962. } else {
  42963. ensureTextContentItem();
  42964. // PDF Specification 5.3.2 states:
  42965. // The number is expressed in thousandths of a unit of text
  42966. // space.
  42967. // This amount is subtracted from the current horizontal or
  42968. // vertical coordinate, depending on the writing mode.
  42969. // In the default coordinate system, a positive adjustment
  42970. // has the effect of moving the next glyph painted either to
  42971. // the left or down by the given amount.
  42972. advance = items[j] * textState.fontSize / 1000;
  42973. var breakTextRun = false;
  42974. if (textState.font.vertical) {
  42975. offset = advance *
  42976. (textState.textHScale * textState.textMatrix[2] +
  42977. textState.textMatrix[3]);
  42978. textState.translateTextMatrix(0, advance);
  42979. breakTextRun = textContentItem.textRunBreakAllowed &&
  42980. advance > textContentItem.fakeMultiSpaceMax;
  42981. if (!breakTextRun) {
  42982. // Value needs to be added to height to paint down.
  42983. textContentItem.height += offset;
  42984. }
  42985. } else {
  42986. advance = -advance;
  42987. offset = advance * (
  42988. textState.textHScale * textState.textMatrix[0] +
  42989. textState.textMatrix[1]);
  42990. textState.translateTextMatrix(advance, 0);
  42991. breakTextRun = textContentItem.textRunBreakAllowed &&
  42992. advance > textContentItem.fakeMultiSpaceMax;
  42993. if (!breakTextRun) {
  42994. // Value needs to be subtracted from width to paint left.
  42995. textContentItem.width += offset;
  42996. }
  42997. }
  42998. if (breakTextRun) {
  42999. flushTextContentItem();
  43000. } else if (advance > 0) {
  43001. addFakeSpaces(advance, textContentItem.str);
  43002. }
  43003. }
  43004. }
  43005. break;
  43006. case OPS.showText:
  43007. buildTextContentItem(args[0]);
  43008. break;
  43009. case OPS.nextLineShowText:
  43010. flushTextContentItem();
  43011. textState.carriageReturn();
  43012. buildTextContentItem(args[0]);
  43013. break;
  43014. case OPS.nextLineSetSpacingShowText:
  43015. flushTextContentItem();
  43016. textState.wordSpacing = args[0];
  43017. textState.charSpacing = args[1];
  43018. textState.carriageReturn();
  43019. buildTextContentItem(args[2]);
  43020. break;
  43021. case OPS.paintXObject:
  43022. flushTextContentItem();
  43023. if (args[0].code) {
  43024. break;
  43025. }
  43026. if (!xobjs) {
  43027. xobjs = (resources.get('XObject') || Dict.empty);
  43028. }
  43029. var name = args[0].name;
  43030. if (xobjsCache.key === name) {
  43031. if (xobjsCache.texts) {
  43032. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  43033. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  43034. }
  43035. break;
  43036. }
  43037. var xobj = xobjs.get(name);
  43038. if (!xobj) {
  43039. break;
  43040. }
  43041. assert(isStream(xobj), 'XObject should be a stream');
  43042. var type = xobj.dict.get('Subtype');
  43043. assert(isName(type),
  43044. 'XObject should have a Name subtype');
  43045. if ('Form' !== type.name) {
  43046. xobjsCache.key = name;
  43047. xobjsCache.texts = null;
  43048. break;
  43049. }
  43050. stateManager.save();
  43051. var matrix = xobj.dict.get('Matrix');
  43052. if (isArray(matrix) && matrix.length === 6) {
  43053. stateManager.transform(matrix);
  43054. }
  43055. return self.getTextContent(xobj, task,
  43056. xobj.dict.get('Resources') || resources, stateManager,
  43057. normalizeWhitespace).then(function (formTextContent) {
  43058. Util.appendToArray(textContent.items, formTextContent.items);
  43059. Util.extendObj(textContent.styles, formTextContent.styles);
  43060. stateManager.restore();
  43061. xobjsCache.key = name;
  43062. xobjsCache.texts = formTextContent;
  43063. next(resolve, reject);
  43064. }, reject);
  43065. case OPS.setGState:
  43066. flushTextContentItem();
  43067. var dictName = args[0];
  43068. var extGState = resources.get('ExtGState');
  43069. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43070. break;
  43071. }
  43072. var gsStateMap = extGState.get(dictName.name);
  43073. var gsStateFont = null;
  43074. for (var key in gsStateMap) {
  43075. if (key === 'Font') {
  43076. assert(!gsStateFont);
  43077. gsStateFont = gsStateMap[key];
  43078. }
  43079. }
  43080. if (gsStateFont) {
  43081. textState.fontSize = gsStateFont[1];
  43082. return handleSetFont(gsStateFont[0]).then(function() {
  43083. next(resolve, reject);
  43084. }, reject);
  43085. }
  43086. break;
  43087. } // switch
  43088. } // while
  43089. if (stop) {
  43090. deferred.then(function () {
  43091. next(resolve, reject);
  43092. }, reject);
  43093. return;
  43094. }
  43095. flushTextContentItem();
  43096. resolve(textContent);
  43097. });
  43098. },
  43099. extractDataStructures: function
  43100. partialEvaluatorExtractDataStructures(dict, baseDict,
  43101. xref, properties) {
  43102. // 9.10.2
  43103. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  43104. if (toUnicode) {
  43105. properties.toUnicode = this.readToUnicode(toUnicode);
  43106. }
  43107. if (properties.composite) {
  43108. // CIDSystemInfo helps to match CID to glyphs
  43109. var cidSystemInfo = dict.get('CIDSystemInfo');
  43110. if (isDict(cidSystemInfo)) {
  43111. properties.cidSystemInfo = {
  43112. registry: cidSystemInfo.get('Registry'),
  43113. ordering: cidSystemInfo.get('Ordering'),
  43114. supplement: cidSystemInfo.get('Supplement')
  43115. };
  43116. }
  43117. var cidToGidMap = dict.get('CIDToGIDMap');
  43118. if (isStream(cidToGidMap)) {
  43119. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  43120. }
  43121. }
  43122. // Based on 9.6.6 of the spec the encoding can come from multiple places
  43123. // and depends on the font type. The base encoding and differences are
  43124. // read here, but the encoding that is actually used is chosen during
  43125. // glyph mapping in the font.
  43126. // TODO: Loading the built in encoding in the font would allow the
  43127. // differences to be merged in here not require us to hold on to it.
  43128. var differences = [];
  43129. var baseEncodingName = null;
  43130. var encoding;
  43131. if (dict.has('Encoding')) {
  43132. encoding = dict.get('Encoding');
  43133. if (isDict(encoding)) {
  43134. baseEncodingName = encoding.get('BaseEncoding');
  43135. baseEncodingName = (isName(baseEncodingName) ?
  43136. baseEncodingName.name : null);
  43137. // Load the differences between the base and original
  43138. if (encoding.has('Differences')) {
  43139. var diffEncoding = encoding.get('Differences');
  43140. var index = 0;
  43141. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  43142. var data = xref.fetchIfRef(diffEncoding[j]);
  43143. if (isNum(data)) {
  43144. index = data;
  43145. } else if (isName(data)) {
  43146. differences[index++] = data.name;
  43147. } else {
  43148. error('Invalid entry in \'Differences\' array: ' + data);
  43149. }
  43150. }
  43151. }
  43152. } else if (isName(encoding)) {
  43153. baseEncodingName = encoding.name;
  43154. } else {
  43155. error('Encoding is not a Name nor a Dict');
  43156. }
  43157. // According to table 114 if the encoding is a named encoding it must be
  43158. // one of these predefined encodings.
  43159. if ((baseEncodingName !== 'MacRomanEncoding' &&
  43160. baseEncodingName !== 'MacExpertEncoding' &&
  43161. baseEncodingName !== 'WinAnsiEncoding')) {
  43162. baseEncodingName = null;
  43163. }
  43164. }
  43165. if (baseEncodingName) {
  43166. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  43167. } else {
  43168. encoding = (properties.type === 'TrueType' ?
  43169. WinAnsiEncoding : StandardEncoding);
  43170. // The Symbolic attribute can be misused for regular fonts
  43171. // Heuristic: we have to check if the font is a standard one also
  43172. if (!!(properties.flags & FontFlags.Symbolic)) {
  43173. encoding = MacRomanEncoding;
  43174. if (!properties.file) {
  43175. if (/Symbol/i.test(properties.name)) {
  43176. encoding = SymbolSetEncoding;
  43177. } else if (/Dingbats/i.test(properties.name)) {
  43178. encoding = ZapfDingbatsEncoding;
  43179. }
  43180. }
  43181. }
  43182. properties.defaultEncoding = encoding;
  43183. }
  43184. properties.differences = differences;
  43185. properties.baseEncodingName = baseEncodingName;
  43186. properties.dict = dict;
  43187. },
  43188. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  43189. var cmap, cmapObj = toUnicode;
  43190. if (isName(cmapObj)) {
  43191. cmap = CMapFactory.create(cmapObj,
  43192. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43193. if (cmap instanceof IdentityCMap) {
  43194. return new IdentityToUnicodeMap(0, 0xFFFF);
  43195. }
  43196. return new ToUnicodeMap(cmap.getMap());
  43197. } else if (isStream(cmapObj)) {
  43198. cmap = CMapFactory.create(cmapObj,
  43199. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43200. if (cmap instanceof IdentityCMap) {
  43201. return new IdentityToUnicodeMap(0, 0xFFFF);
  43202. }
  43203. var map = new Array(cmap.length);
  43204. // Convert UTF-16BE
  43205. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  43206. // to iterate over all keys.
  43207. cmap.forEach(function(charCode, token) {
  43208. var str = [];
  43209. for (var k = 0; k < token.length; k += 2) {
  43210. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43211. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  43212. str.push(w1);
  43213. continue;
  43214. }
  43215. k += 2;
  43216. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43217. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  43218. }
  43219. map[charCode] = String.fromCharCode.apply(String, str);
  43220. });
  43221. return new ToUnicodeMap(map);
  43222. }
  43223. return null;
  43224. },
  43225. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  43226. // Extract the encoding from the CIDToGIDMap
  43227. var glyphsData = cidToGidStream.getBytes();
  43228. // Set encoding 0 to later verify the font has an encoding
  43229. var result = [];
  43230. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  43231. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  43232. if (glyphID === 0) {
  43233. continue;
  43234. }
  43235. var code = j >> 1;
  43236. result[code] = glyphID;
  43237. }
  43238. return result;
  43239. },
  43240. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  43241. descriptor,
  43242. properties) {
  43243. var glyphsWidths = [];
  43244. var defaultWidth = 0;
  43245. var glyphsVMetrics = [];
  43246. var defaultVMetrics;
  43247. var i, ii, j, jj, start, code, widths;
  43248. if (properties.composite) {
  43249. defaultWidth = dict.get('DW') || 1000;
  43250. widths = dict.get('W');
  43251. if (widths) {
  43252. for (i = 0, ii = widths.length; i < ii; i++) {
  43253. start = widths[i++];
  43254. code = xref.fetchIfRef(widths[i]);
  43255. if (isArray(code)) {
  43256. for (j = 0, jj = code.length; j < jj; j++) {
  43257. glyphsWidths[start++] = code[j];
  43258. }
  43259. } else {
  43260. var width = widths[++i];
  43261. for (j = start; j <= code; j++) {
  43262. glyphsWidths[j] = width;
  43263. }
  43264. }
  43265. }
  43266. }
  43267. if (properties.vertical) {
  43268. var vmetrics = (dict.get('DW2') || [880, -1000]);
  43269. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  43270. vmetrics = dict.get('W2');
  43271. if (vmetrics) {
  43272. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  43273. start = vmetrics[i++];
  43274. code = xref.fetchIfRef(vmetrics[i]);
  43275. if (isArray(code)) {
  43276. for (j = 0, jj = code.length; j < jj; j++) {
  43277. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  43278. }
  43279. } else {
  43280. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  43281. for (j = start; j <= code; j++) {
  43282. glyphsVMetrics[j] = vmetric;
  43283. }
  43284. }
  43285. }
  43286. }
  43287. }
  43288. } else {
  43289. var firstChar = properties.firstChar;
  43290. widths = dict.get('Widths');
  43291. if (widths) {
  43292. j = firstChar;
  43293. for (i = 0, ii = widths.length; i < ii; i++) {
  43294. glyphsWidths[j++] = widths[i];
  43295. }
  43296. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  43297. } else {
  43298. // Trying get the BaseFont metrics (see comment above).
  43299. var baseFontName = dict.get('BaseFont');
  43300. if (isName(baseFontName)) {
  43301. var metrics = this.getBaseFontMetrics(baseFontName.name);
  43302. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  43303. properties);
  43304. defaultWidth = metrics.defaultWidth;
  43305. }
  43306. }
  43307. }
  43308. // Heuristic: detection of monospace font by checking all non-zero widths
  43309. var isMonospace = true;
  43310. var firstWidth = defaultWidth;
  43311. for (var glyph in glyphsWidths) {
  43312. var glyphWidth = glyphsWidths[glyph];
  43313. if (!glyphWidth) {
  43314. continue;
  43315. }
  43316. if (!firstWidth) {
  43317. firstWidth = glyphWidth;
  43318. continue;
  43319. }
  43320. if (firstWidth !== glyphWidth) {
  43321. isMonospace = false;
  43322. break;
  43323. }
  43324. }
  43325. if (isMonospace) {
  43326. properties.flags |= FontFlags.FixedPitch;
  43327. }
  43328. properties.defaultWidth = defaultWidth;
  43329. properties.widths = glyphsWidths;
  43330. properties.defaultVMetrics = defaultVMetrics;
  43331. properties.vmetrics = glyphsVMetrics;
  43332. },
  43333. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  43334. // Simulating descriptor flags attribute
  43335. var fontNameWoStyle = baseFontName.split('-')[0];
  43336. return (fontNameWoStyle in getSerifFonts()) ||
  43337. (fontNameWoStyle.search(/serif/gi) !== -1);
  43338. },
  43339. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  43340. var defaultWidth = 0;
  43341. var widths = [];
  43342. var monospace = false;
  43343. var stdFontMap = getStdFontMap();
  43344. var lookupName = (stdFontMap[name] || name);
  43345. var Metrics = getMetrics();
  43346. if (!(lookupName in Metrics)) {
  43347. // Use default fonts for looking up font metrics if the passed
  43348. // font is not a base font
  43349. if (this.isSerifFont(name)) {
  43350. lookupName = 'Times-Roman';
  43351. } else {
  43352. lookupName = 'Helvetica';
  43353. }
  43354. }
  43355. var glyphWidths = Metrics[lookupName];
  43356. if (isNum(glyphWidths)) {
  43357. defaultWidth = glyphWidths;
  43358. monospace = true;
  43359. } else {
  43360. widths = glyphWidths(); // expand lazy widths array
  43361. }
  43362. return {
  43363. defaultWidth: defaultWidth,
  43364. monospace: monospace,
  43365. widths: widths
  43366. };
  43367. },
  43368. buildCharCodeToWidth:
  43369. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  43370. properties) {
  43371. var widths = Object.create(null);
  43372. var differences = properties.differences;
  43373. var encoding = properties.defaultEncoding;
  43374. for (var charCode = 0; charCode < 256; charCode++) {
  43375. if (charCode in differences &&
  43376. widthsByGlyphName[differences[charCode]]) {
  43377. widths[charCode] = widthsByGlyphName[differences[charCode]];
  43378. continue;
  43379. }
  43380. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  43381. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  43382. continue;
  43383. }
  43384. }
  43385. return widths;
  43386. },
  43387. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  43388. var baseDict = dict;
  43389. var type = dict.get('Subtype');
  43390. assert(isName(type), 'invalid font Subtype');
  43391. var composite = false;
  43392. var uint8array;
  43393. if (type.name === 'Type0') {
  43394. // If font is a composite
  43395. // - get the descendant font
  43396. // - set the type according to the descendant font
  43397. // - get the FontDescriptor from the descendant font
  43398. var df = dict.get('DescendantFonts');
  43399. if (!df) {
  43400. error('Descendant fonts are not specified');
  43401. }
  43402. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  43403. type = dict.get('Subtype');
  43404. assert(isName(type), 'invalid font Subtype');
  43405. composite = true;
  43406. }
  43407. var descriptor = dict.get('FontDescriptor');
  43408. if (descriptor) {
  43409. var hash = new MurmurHash3_64();
  43410. var encoding = baseDict.getRaw('Encoding');
  43411. if (isName(encoding)) {
  43412. hash.update(encoding.name);
  43413. } else if (isRef(encoding)) {
  43414. hash.update(encoding.num + '_' + encoding.gen);
  43415. } else if (isDict(encoding)) {
  43416. var keys = encoding.getKeys();
  43417. for (var i = 0, ii = keys.length; i < ii; i++) {
  43418. var entry = encoding.getRaw(keys[i]);
  43419. if (isName(entry)) {
  43420. hash.update(entry.name);
  43421. } else if (isRef(entry)) {
  43422. hash.update(entry.num + '_' + entry.gen);
  43423. } else if (isArray(entry)) { // 'Differences' entry.
  43424. // Ideally we should check the contents of the array, but to avoid
  43425. // parsing it here and then again in |extractDataStructures|,
  43426. // we only use the array length for now (fixes bug1157493.pdf).
  43427. hash.update(entry.length.toString());
  43428. }
  43429. }
  43430. }
  43431. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  43432. if (isStream(toUnicode)) {
  43433. var stream = toUnicode.str || toUnicode;
  43434. uint8array = stream.buffer ?
  43435. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  43436. new Uint8Array(stream.bytes.buffer,
  43437. stream.start, stream.end - stream.start);
  43438. hash.update(uint8array);
  43439. } else if (isName(toUnicode)) {
  43440. hash.update(toUnicode.name);
  43441. }
  43442. var widths = dict.get('Widths') || baseDict.get('Widths');
  43443. if (widths) {
  43444. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  43445. hash.update(uint8array);
  43446. }
  43447. }
  43448. return {
  43449. descriptor: descriptor,
  43450. dict: dict,
  43451. baseDict: baseDict,
  43452. composite: composite,
  43453. type: type.name,
  43454. hash: hash ? hash.hexdigest() : ''
  43455. };
  43456. },
  43457. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  43458. xref) {
  43459. var baseDict = preEvaluatedFont.baseDict;
  43460. var dict = preEvaluatedFont.dict;
  43461. var composite = preEvaluatedFont.composite;
  43462. var descriptor = preEvaluatedFont.descriptor;
  43463. var type = preEvaluatedFont.type;
  43464. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  43465. var properties;
  43466. if (!descriptor) {
  43467. if (type === 'Type3') {
  43468. // FontDescriptor is only required for Type3 fonts when the document
  43469. // is a tagged pdf. Create a barbebones one to get by.
  43470. descriptor = new Dict(null);
  43471. descriptor.set('FontName', Name.get(type));
  43472. descriptor.set('FontBBox', dict.get('FontBBox'));
  43473. } else {
  43474. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  43475. // FontDescriptor was not required.
  43476. // This case is here for compatibility.
  43477. var baseFontName = dict.get('BaseFont');
  43478. if (!isName(baseFontName)) {
  43479. error('Base font is not specified');
  43480. }
  43481. // Using base font name as a font name.
  43482. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  43483. var metrics = this.getBaseFontMetrics(baseFontName);
  43484. // Simulating descriptor flags attribute
  43485. var fontNameWoStyle = baseFontName.split('-')[0];
  43486. var flags =
  43487. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  43488. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  43489. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  43490. FontFlags.Nonsymbolic);
  43491. properties = {
  43492. type: type,
  43493. name: baseFontName,
  43494. widths: metrics.widths,
  43495. defaultWidth: metrics.defaultWidth,
  43496. flags: flags,
  43497. firstChar: 0,
  43498. lastChar: maxCharIndex
  43499. };
  43500. this.extractDataStructures(dict, dict, xref, properties);
  43501. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  43502. properties);
  43503. return new Font(baseFontName, null, properties);
  43504. }
  43505. }
  43506. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  43507. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  43508. // to ignore this rule when a variant of a standart font is used.
  43509. // TODO Fill the width array depending on which of the base font this is
  43510. // a variant.
  43511. var firstChar = (dict.get('FirstChar') || 0);
  43512. var lastChar = (dict.get('LastChar') || maxCharIndex);
  43513. var fontName = descriptor.get('FontName');
  43514. var baseFont = dict.get('BaseFont');
  43515. // Some bad PDFs have a string as the font name.
  43516. if (isString(fontName)) {
  43517. fontName = Name.get(fontName);
  43518. }
  43519. if (isString(baseFont)) {
  43520. baseFont = Name.get(baseFont);
  43521. }
  43522. if (type !== 'Type3') {
  43523. var fontNameStr = fontName && fontName.name;
  43524. var baseFontStr = baseFont && baseFont.name;
  43525. if (fontNameStr !== baseFontStr) {
  43526. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  43527. '" but should be the same as the Font\'s BaseFont "' +
  43528. baseFontStr + '"');
  43529. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  43530. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  43531. if (fontNameStr && baseFontStr &&
  43532. baseFontStr.indexOf(fontNameStr) === 0) {
  43533. fontName = baseFont;
  43534. }
  43535. }
  43536. }
  43537. fontName = (fontName || baseFont);
  43538. assert(isName(fontName), 'invalid font name');
  43539. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  43540. if (fontFile) {
  43541. if (fontFile.dict) {
  43542. var subtype = fontFile.dict.get('Subtype');
  43543. if (subtype) {
  43544. subtype = subtype.name;
  43545. }
  43546. var length1 = fontFile.dict.get('Length1');
  43547. var length2 = fontFile.dict.get('Length2');
  43548. }
  43549. }
  43550. properties = {
  43551. type: type,
  43552. name: fontName.name,
  43553. subtype: subtype,
  43554. file: fontFile,
  43555. length1: length1,
  43556. length2: length2,
  43557. loadedName: baseDict.loadedName,
  43558. composite: composite,
  43559. wideChars: composite,
  43560. fixedPitch: false,
  43561. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  43562. firstChar: firstChar || 0,
  43563. lastChar: (lastChar || maxCharIndex),
  43564. bbox: descriptor.get('FontBBox'),
  43565. ascent: descriptor.get('Ascent'),
  43566. descent: descriptor.get('Descent'),
  43567. xHeight: descriptor.get('XHeight'),
  43568. capHeight: descriptor.get('CapHeight'),
  43569. flags: descriptor.get('Flags'),
  43570. italicAngle: descriptor.get('ItalicAngle'),
  43571. coded: false
  43572. };
  43573. if (composite) {
  43574. var cidEncoding = baseDict.get('Encoding');
  43575. if (isName(cidEncoding)) {
  43576. properties.cidEncoding = cidEncoding.name;
  43577. }
  43578. properties.cMap = CMapFactory.create(cidEncoding,
  43579. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43580. properties.vertical = properties.cMap.vertical;
  43581. }
  43582. this.extractDataStructures(dict, baseDict, xref, properties);
  43583. this.extractWidths(dict, xref, descriptor, properties);
  43584. if (type === 'Type3') {
  43585. properties.isType3Font = true;
  43586. }
  43587. return new Font(fontName.name, fontFile, properties);
  43588. }
  43589. };
  43590. return PartialEvaluator;
  43591. })();
  43592. var TranslatedFont = (function TranslatedFontClosure() {
  43593. function TranslatedFont(loadedName, font, dict) {
  43594. this.loadedName = loadedName;
  43595. this.font = font;
  43596. this.dict = dict;
  43597. this.type3Loaded = null;
  43598. this.sent = false;
  43599. }
  43600. TranslatedFont.prototype = {
  43601. send: function (handler) {
  43602. if (this.sent) {
  43603. return;
  43604. }
  43605. var fontData = this.font.exportData();
  43606. handler.send('commonobj', [
  43607. this.loadedName,
  43608. 'Font',
  43609. fontData
  43610. ]);
  43611. this.sent = true;
  43612. },
  43613. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  43614. assert(this.font.isType3Font);
  43615. if (this.type3Loaded) {
  43616. return this.type3Loaded;
  43617. }
  43618. var translatedFont = this.font;
  43619. var loadCharProcsPromise = Promise.resolve();
  43620. var charProcs = this.dict.get('CharProcs');
  43621. var fontResources = this.dict.get('Resources') || resources;
  43622. var charProcKeys = charProcs.getKeys();
  43623. var charProcOperatorList = Object.create(null);
  43624. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  43625. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  43626. var glyphStream = charProcs.get(key);
  43627. var operatorList = new OperatorList();
  43628. return evaluator.getOperatorList(glyphStream, task, fontResources,
  43629. operatorList).then(function () {
  43630. charProcOperatorList[key] = operatorList.getIR();
  43631. // Add the dependencies to the parent operator list so they are
  43632. // resolved before sub operator list is executed synchronously.
  43633. parentOperatorList.addDependencies(operatorList.dependencies);
  43634. }, function (reason) {
  43635. warn('Type3 font resource \"' + key + '\" is not available');
  43636. var operatorList = new OperatorList();
  43637. charProcOperatorList[key] = operatorList.getIR();
  43638. });
  43639. }.bind(this, charProcKeys[i]));
  43640. }
  43641. this.type3Loaded = loadCharProcsPromise.then(function () {
  43642. translatedFont.charProcOperatorList = charProcOperatorList;
  43643. });
  43644. return this.type3Loaded;
  43645. }
  43646. };
  43647. return TranslatedFont;
  43648. })();
  43649. var OperatorList = (function OperatorListClosure() {
  43650. var CHUNK_SIZE = 1000;
  43651. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  43652. function getTransfers(queue) {
  43653. var transfers = [];
  43654. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43655. for (var i = 0, ii = queue.length; i < ii; i++) {
  43656. switch (fnArray[i]) {
  43657. case OPS.paintInlineImageXObject:
  43658. case OPS.paintInlineImageXObjectGroup:
  43659. case OPS.paintImageMaskXObject:
  43660. var arg = argsArray[i][0]; // first param in imgData
  43661. if (!arg.cached) {
  43662. transfers.push(arg.data.buffer);
  43663. }
  43664. break;
  43665. }
  43666. }
  43667. return transfers;
  43668. }
  43669. function OperatorList(intent, messageHandler, pageIndex) {
  43670. this.messageHandler = messageHandler;
  43671. this.fnArray = [];
  43672. this.argsArray = [];
  43673. this.dependencies = Object.create(null);
  43674. this._totalLength = 0;
  43675. this.pageIndex = pageIndex;
  43676. this.intent = intent;
  43677. }
  43678. OperatorList.prototype = {
  43679. get length() {
  43680. return this.argsArray.length;
  43681. },
  43682. /**
  43683. * @returns {number} The total length of the entire operator list,
  43684. * since `this.length === 0` after flushing.
  43685. */
  43686. get totalLength() {
  43687. return (this._totalLength + this.length);
  43688. },
  43689. addOp: function(fn, args) {
  43690. this.fnArray.push(fn);
  43691. this.argsArray.push(args);
  43692. if (this.messageHandler) {
  43693. if (this.fnArray.length >= CHUNK_SIZE) {
  43694. this.flush();
  43695. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  43696. (fn === OPS.restore || fn === OPS.endText)) {
  43697. // heuristic to flush on boundary of restore or endText
  43698. this.flush();
  43699. }
  43700. }
  43701. },
  43702. addDependency: function(dependency) {
  43703. if (dependency in this.dependencies) {
  43704. return;
  43705. }
  43706. this.dependencies[dependency] = true;
  43707. this.addOp(OPS.dependency, [dependency]);
  43708. },
  43709. addDependencies: function(dependencies) {
  43710. for (var key in dependencies) {
  43711. this.addDependency(key);
  43712. }
  43713. },
  43714. addOpList: function(opList) {
  43715. Util.extendObj(this.dependencies, opList.dependencies);
  43716. for (var i = 0, ii = opList.length; i < ii; i++) {
  43717. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  43718. }
  43719. },
  43720. getIR: function() {
  43721. return {
  43722. fnArray: this.fnArray,
  43723. argsArray: this.argsArray,
  43724. length: this.length
  43725. };
  43726. },
  43727. flush: function(lastChunk) {
  43728. if (this.intent !== 'oplist') {
  43729. new QueueOptimizer().optimize(this);
  43730. }
  43731. var transfers = getTransfers(this);
  43732. var length = this.length;
  43733. this._totalLength += length;
  43734. this.messageHandler.send('RenderPageChunk', {
  43735. operatorList: {
  43736. fnArray: this.fnArray,
  43737. argsArray: this.argsArray,
  43738. lastChunk: lastChunk,
  43739. length: length
  43740. },
  43741. pageIndex: this.pageIndex,
  43742. intent: this.intent
  43743. }, transfers);
  43744. this.dependencies = Object.create(null);
  43745. this.fnArray.length = 0;
  43746. this.argsArray.length = 0;
  43747. }
  43748. };
  43749. return OperatorList;
  43750. })();
  43751. var StateManager = (function StateManagerClosure() {
  43752. function StateManager(initialState) {
  43753. this.state = initialState;
  43754. this.stateStack = [];
  43755. }
  43756. StateManager.prototype = {
  43757. save: function () {
  43758. var old = this.state;
  43759. this.stateStack.push(this.state);
  43760. this.state = old.clone();
  43761. },
  43762. restore: function () {
  43763. var prev = this.stateStack.pop();
  43764. if (prev) {
  43765. this.state = prev;
  43766. }
  43767. },
  43768. transform: function (args) {
  43769. this.state.ctm = Util.transform(this.state.ctm, args);
  43770. }
  43771. };
  43772. return StateManager;
  43773. })();
  43774. var TextState = (function TextStateClosure() {
  43775. function TextState() {
  43776. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43777. this.fontSize = 0;
  43778. this.font = null;
  43779. this.fontMatrix = FONT_IDENTITY_MATRIX;
  43780. this.textMatrix = IDENTITY_MATRIX.slice();
  43781. this.textLineMatrix = IDENTITY_MATRIX.slice();
  43782. this.charSpacing = 0;
  43783. this.wordSpacing = 0;
  43784. this.leading = 0;
  43785. this.textHScale = 1;
  43786. this.textRise = 0;
  43787. }
  43788. TextState.prototype = {
  43789. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43790. var m = this.textMatrix;
  43791. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43792. },
  43793. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43794. var m = this.textLineMatrix;
  43795. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43796. },
  43797. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  43798. var m = this.textMatrix;
  43799. m[4] = m[0] * x + m[2] * y + m[4];
  43800. m[5] = m[1] * x + m[3] * y + m[5];
  43801. },
  43802. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  43803. var m = this.textLineMatrix;
  43804. m[4] = m[0] * x + m[2] * y + m[4];
  43805. m[5] = m[1] * x + m[3] * y + m[5];
  43806. },
  43807. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  43808. // 9.4.4 Text Space Details
  43809. var tsm = [this.fontSize * this.textHScale, 0,
  43810. 0, this.fontSize,
  43811. 0, this.textRise];
  43812. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  43813. },
  43814. carriageReturn: function TextState_carriageReturn() {
  43815. this.translateTextLineMatrix(0, -this.leading);
  43816. this.textMatrix = this.textLineMatrix.slice();
  43817. },
  43818. clone: function TextState_clone() {
  43819. var clone = Object.create(this);
  43820. clone.textMatrix = this.textMatrix.slice();
  43821. clone.textLineMatrix = this.textLineMatrix.slice();
  43822. clone.fontMatrix = this.fontMatrix.slice();
  43823. return clone;
  43824. }
  43825. };
  43826. return TextState;
  43827. })();
  43828. var EvalState = (function EvalStateClosure() {
  43829. function EvalState() {
  43830. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43831. this.font = null;
  43832. this.textRenderingMode = TextRenderingMode.FILL;
  43833. this.fillColorSpace = ColorSpace.singletons.gray;
  43834. this.strokeColorSpace = ColorSpace.singletons.gray;
  43835. }
  43836. EvalState.prototype = {
  43837. clone: function CanvasExtraState_clone() {
  43838. return Object.create(this);
  43839. },
  43840. };
  43841. return EvalState;
  43842. })();
  43843. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  43844. // Specifies properties for each command
  43845. //
  43846. // If variableArgs === true: [0, `numArgs`] expected
  43847. // If variableArgs === false: exactly `numArgs` expected
  43848. var getOPMap = getLookupTableFactory(function (t) {
  43849. // Graphic state
  43850. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  43851. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  43852. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  43853. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  43854. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  43855. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  43856. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  43857. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  43858. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  43859. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  43860. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  43861. // Path
  43862. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  43863. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  43864. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  43865. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  43866. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  43867. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  43868. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  43869. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  43870. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  43871. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  43872. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  43873. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  43874. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  43875. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  43876. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  43877. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  43878. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  43879. // Clipping
  43880. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  43881. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  43882. // Text
  43883. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  43884. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  43885. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  43886. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  43887. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  43888. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  43889. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  43890. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  43891. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  43892. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  43893. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  43894. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  43895. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  43896. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  43897. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  43898. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  43899. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  43900. variableArgs: false };
  43901. // Type3 fonts
  43902. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  43903. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  43904. variableArgs: false };
  43905. // Color
  43906. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  43907. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  43908. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  43909. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  43910. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  43911. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  43912. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  43913. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  43914. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  43915. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  43916. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  43917. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  43918. // Shading
  43919. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  43920. // Images
  43921. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  43922. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  43923. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  43924. // XObjects
  43925. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  43926. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  43927. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  43928. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  43929. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  43930. variableArgs: false };
  43931. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  43932. // Compatibility
  43933. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  43934. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  43935. // (reserved partial commands for the lexer)
  43936. t['BM'] = null;
  43937. t['BD'] = null;
  43938. t['true'] = null;
  43939. t['fa'] = null;
  43940. t['fal'] = null;
  43941. t['fals'] = null;
  43942. t['false'] = null;
  43943. t['nu'] = null;
  43944. t['nul'] = null;
  43945. t['null'] = null;
  43946. });
  43947. function EvaluatorPreprocessor(stream, xref, stateManager) {
  43948. this.opMap = getOPMap();
  43949. // TODO(mduan): pass array of knownCommands rather than this.opMap
  43950. // dictionary
  43951. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  43952. this.stateManager = stateManager;
  43953. this.nonProcessedArgs = [];
  43954. }
  43955. EvaluatorPreprocessor.prototype = {
  43956. get savedStatesDepth() {
  43957. return this.stateManager.stateStack.length;
  43958. },
  43959. // |operation| is an object with two fields:
  43960. //
  43961. // - |fn| is an out param.
  43962. //
  43963. // - |args| is an inout param. On entry, it should have one of two values.
  43964. //
  43965. // - An empty array. This indicates that the caller is providing the
  43966. // array in which the args will be stored in. The caller should use
  43967. // this value if it can reuse a single array for each call to read().
  43968. //
  43969. // - |null|. This indicates that the caller needs this function to create
  43970. // the array in which any args are stored in. If there are zero args,
  43971. // this function will leave |operation.args| as |null| (thus avoiding
  43972. // allocations that would occur if we used an empty array to represent
  43973. // zero arguments). Otherwise, it will replace |null| with a new array
  43974. // containing the arguments. The caller should use this value if it
  43975. // cannot reuse an array for each call to read().
  43976. //
  43977. // These two modes are present because this function is very hot and so
  43978. // avoiding allocations where possible is worthwhile.
  43979. //
  43980. read: function EvaluatorPreprocessor_read(operation) {
  43981. var args = operation.args;
  43982. while (true) {
  43983. var obj = this.parser.getObj();
  43984. if (isCmd(obj)) {
  43985. var cmd = obj.cmd;
  43986. // Check that the command is valid
  43987. var opSpec = this.opMap[cmd];
  43988. if (!opSpec) {
  43989. warn('Unknown command "' + cmd + '"');
  43990. continue;
  43991. }
  43992. var fn = opSpec.id;
  43993. var numArgs = opSpec.numArgs;
  43994. var argsLength = args !== null ? args.length : 0;
  43995. if (!opSpec.variableArgs) {
  43996. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  43997. if (argsLength !== numArgs) {
  43998. var nonProcessedArgs = this.nonProcessedArgs;
  43999. while (argsLength > numArgs) {
  44000. nonProcessedArgs.push(args.shift());
  44001. argsLength--;
  44002. }
  44003. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  44004. if (!args) {
  44005. args = [];
  44006. }
  44007. args.unshift(nonProcessedArgs.pop());
  44008. argsLength++;
  44009. }
  44010. }
  44011. if (argsLength < numArgs) {
  44012. // If we receive too few args, it's not possible to possible
  44013. // to execute the command, so skip the command
  44014. info('Command ' + fn + ': because expected ' +
  44015. numArgs + ' args, but received ' + argsLength +
  44016. ' args; skipping');
  44017. args = null;
  44018. continue;
  44019. }
  44020. } else if (argsLength > numArgs) {
  44021. info('Command ' + fn + ': expected [0,' + numArgs +
  44022. '] args, but received ' + argsLength + ' args');
  44023. }
  44024. // TODO figure out how to type-check vararg functions
  44025. this.preprocessCommand(fn, args);
  44026. operation.fn = fn;
  44027. operation.args = args;
  44028. return true;
  44029. } else {
  44030. if (isEOF(obj)) {
  44031. return false; // no more commands
  44032. }
  44033. // argument
  44034. if (obj !== null) {
  44035. if (!args) {
  44036. args = [];
  44037. }
  44038. args.push(obj);
  44039. assert(args.length <= 33, 'Too many arguments');
  44040. }
  44041. }
  44042. }
  44043. },
  44044. preprocessCommand:
  44045. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  44046. switch (fn | 0) {
  44047. case OPS.save:
  44048. this.stateManager.save();
  44049. break;
  44050. case OPS.restore:
  44051. this.stateManager.restore();
  44052. break;
  44053. case OPS.transform:
  44054. this.stateManager.transform(args);
  44055. break;
  44056. }
  44057. }
  44058. };
  44059. return EvaluatorPreprocessor;
  44060. })();
  44061. var QueueOptimizer = (function QueueOptimizerClosure() {
  44062. function addState(parentState, pattern, fn) {
  44063. var state = parentState;
  44064. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  44065. var item = pattern[i];
  44066. state = (state[item] || (state[item] = []));
  44067. }
  44068. state[pattern[pattern.length - 1]] = fn;
  44069. }
  44070. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44071. argsArray) {
  44072. // Handles special case of mainly LaTeX documents which use image masks to
  44073. // draw lines with the current fill style.
  44074. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  44075. // have been found at iFirstSave.
  44076. var iFirstPIMXO = iFirstSave + 2;
  44077. for (var i = 0; i < count; i++) {
  44078. var arg = argsArray[iFirstPIMXO + 4 * i];
  44079. var imageMask = arg.length === 1 && arg[0];
  44080. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  44081. (!imageMask.data.length ||
  44082. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  44083. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  44084. continue;
  44085. }
  44086. break;
  44087. }
  44088. return count - i;
  44089. }
  44090. var InitialState = [];
  44091. // This replaces (save, transform, paintInlineImageXObject, restore)+
  44092. // sequences with one |paintInlineImageXObjectGroup| operation.
  44093. addState(InitialState,
  44094. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  44095. function foundInlineImageGroup(context) {
  44096. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  44097. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  44098. var MAX_WIDTH = 1000;
  44099. var IMAGE_PADDING = 1;
  44100. var fnArray = context.fnArray, argsArray = context.argsArray;
  44101. var curr = context.iCurr;
  44102. var iFirstSave = curr - 3;
  44103. var iFirstTransform = curr - 2;
  44104. var iFirstPIIXO = curr - 1;
  44105. // Look for the quartets.
  44106. var i = iFirstSave + 4;
  44107. var ii = fnArray.length;
  44108. while (i + 3 < ii) {
  44109. if (fnArray[i] !== OPS.save ||
  44110. fnArray[i + 1] !== OPS.transform ||
  44111. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  44112. fnArray[i + 3] !== OPS.restore) {
  44113. break; // ops don't match
  44114. }
  44115. i += 4;
  44116. }
  44117. // At this point, i is the index of the first op past the last valid
  44118. // quartet.
  44119. var count = Math.min((i - iFirstSave) / 4,
  44120. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  44121. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  44122. return i;
  44123. }
  44124. // assuming that heights of those image is too small (~1 pixel)
  44125. // packing as much as possible by lines
  44126. var maxX = 0;
  44127. var map = [], maxLineHeight = 0;
  44128. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  44129. var q;
  44130. for (q = 0; q < count; q++) {
  44131. var transform = argsArray[iFirstTransform + (q << 2)];
  44132. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  44133. if (currentX + img.width > MAX_WIDTH) {
  44134. // starting new line
  44135. maxX = Math.max(maxX, currentX);
  44136. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  44137. currentX = 0;
  44138. maxLineHeight = 0;
  44139. }
  44140. map.push({
  44141. transform: transform,
  44142. x: currentX, y: currentY,
  44143. w: img.width, h: img.height
  44144. });
  44145. currentX += img.width + 2 * IMAGE_PADDING;
  44146. maxLineHeight = Math.max(maxLineHeight, img.height);
  44147. }
  44148. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  44149. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  44150. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  44151. var imgRowSize = imgWidth << 2;
  44152. for (q = 0; q < count; q++) {
  44153. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  44154. // Copy image by lines and extends pixels into padding.
  44155. var rowSize = map[q].w << 2;
  44156. var dataOffset = 0;
  44157. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  44158. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  44159. for (var k = 0, kk = map[q].h; k < kk; k++) {
  44160. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  44161. dataOffset += rowSize;
  44162. offset += imgRowSize;
  44163. }
  44164. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  44165. while (offset >= 0) {
  44166. data[offset - 4] = data[offset];
  44167. data[offset - 3] = data[offset + 1];
  44168. data[offset - 2] = data[offset + 2];
  44169. data[offset - 1] = data[offset + 3];
  44170. data[offset + rowSize] = data[offset + rowSize - 4];
  44171. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  44172. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  44173. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  44174. offset -= imgRowSize;
  44175. }
  44176. }
  44177. // Replace queue items.
  44178. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  44179. argsArray.splice(iFirstSave, count * 4,
  44180. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  44181. data: imgData }, map]);
  44182. return iFirstSave + 1;
  44183. });
  44184. // This replaces (save, transform, paintImageMaskXObject, restore)+
  44185. // sequences with one |paintImageMaskXObjectGroup| or one
  44186. // |paintImageMaskXObjectRepeat| operation.
  44187. addState(InitialState,
  44188. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  44189. function foundImageMaskGroup(context) {
  44190. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  44191. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  44192. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  44193. var fnArray = context.fnArray, argsArray = context.argsArray;
  44194. var curr = context.iCurr;
  44195. var iFirstSave = curr - 3;
  44196. var iFirstTransform = curr - 2;
  44197. var iFirstPIMXO = curr - 1;
  44198. // Look for the quartets.
  44199. var i = iFirstSave + 4;
  44200. var ii = fnArray.length;
  44201. while (i + 3 < ii) {
  44202. if (fnArray[i] !== OPS.save ||
  44203. fnArray[i + 1] !== OPS.transform ||
  44204. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  44205. fnArray[i + 3] !== OPS.restore) {
  44206. break; // ops don't match
  44207. }
  44208. i += 4;
  44209. }
  44210. // At this point, i is the index of the first op past the last valid
  44211. // quartet.
  44212. var count = (i - iFirstSave) / 4;
  44213. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44214. argsArray);
  44215. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  44216. return i;
  44217. }
  44218. var q;
  44219. var isSameImage = false;
  44220. var iTransform, transformArgs;
  44221. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  44222. if (argsArray[iFirstTransform][1] === 0 &&
  44223. argsArray[iFirstTransform][2] === 0) {
  44224. isSameImage = true;
  44225. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44226. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44227. iTransform = iFirstTransform + 4;
  44228. var iPIMXO = iFirstPIMXO + 4;
  44229. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  44230. transformArgs = argsArray[iTransform];
  44231. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  44232. transformArgs[0] !== firstTransformArg0 ||
  44233. transformArgs[1] !== 0 ||
  44234. transformArgs[2] !== 0 ||
  44235. transformArgs[3] !== firstTransformArg3) {
  44236. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  44237. isSameImage = false;
  44238. } else {
  44239. count = q;
  44240. }
  44241. break; // different image or transform
  44242. }
  44243. }
  44244. }
  44245. if (isSameImage) {
  44246. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  44247. var positions = new Float32Array(count * 2);
  44248. iTransform = iFirstTransform;
  44249. for (q = 0; q < count; q++, iTransform += 4) {
  44250. transformArgs = argsArray[iTransform];
  44251. positions[(q << 1)] = transformArgs[4];
  44252. positions[(q << 1) + 1] = transformArgs[5];
  44253. }
  44254. // Replace queue items.
  44255. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  44256. argsArray.splice(iFirstSave, count * 4,
  44257. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  44258. } else {
  44259. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  44260. var images = [];
  44261. for (q = 0; q < count; q++) {
  44262. transformArgs = argsArray[iFirstTransform + (q << 2)];
  44263. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  44264. images.push({ data: maskParams.data, width: maskParams.width,
  44265. height: maskParams.height,
  44266. transform: transformArgs });
  44267. }
  44268. // Replace queue items.
  44269. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  44270. argsArray.splice(iFirstSave, count * 4, [images]);
  44271. }
  44272. return iFirstSave + 1;
  44273. });
  44274. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  44275. // with one paintImageXObjectRepeat operation, if the |transform| and
  44276. // |paintImageXObjectRepeat| ops are appropriate.
  44277. addState(InitialState,
  44278. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  44279. function (context) {
  44280. var MIN_IMAGES_IN_BLOCK = 3;
  44281. var MAX_IMAGES_IN_BLOCK = 1000;
  44282. var fnArray = context.fnArray, argsArray = context.argsArray;
  44283. var curr = context.iCurr;
  44284. var iFirstSave = curr - 3;
  44285. var iFirstTransform = curr - 2;
  44286. var iFirstPIXO = curr - 1;
  44287. var iFirstRestore = curr;
  44288. if (argsArray[iFirstTransform][1] !== 0 ||
  44289. argsArray[iFirstTransform][2] !== 0) {
  44290. return iFirstRestore + 1; // transform has the wrong form
  44291. }
  44292. // Look for the quartets.
  44293. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  44294. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44295. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44296. var i = iFirstSave + 4;
  44297. var ii = fnArray.length;
  44298. while (i + 3 < ii) {
  44299. if (fnArray[i] !== OPS.save ||
  44300. fnArray[i + 1] !== OPS.transform ||
  44301. fnArray[i + 2] !== OPS.paintImageXObject ||
  44302. fnArray[i + 3] !== OPS.restore) {
  44303. break; // ops don't match
  44304. }
  44305. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  44306. argsArray[i + 1][1] !== 0 ||
  44307. argsArray[i + 1][2] !== 0 ||
  44308. argsArray[i + 1][3] !== firstTransformArg3) {
  44309. break; // transforms don't match
  44310. }
  44311. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  44312. break; // images don't match
  44313. }
  44314. i += 4;
  44315. }
  44316. // At this point, i is the index of the first op past the last valid
  44317. // quartet.
  44318. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  44319. if (count < MIN_IMAGES_IN_BLOCK) {
  44320. return i;
  44321. }
  44322. // Extract the (x,y) positions from all of the matching transforms.
  44323. var positions = new Float32Array(count * 2);
  44324. var iTransform = iFirstTransform;
  44325. for (var q = 0; q < count; q++, iTransform += 4) {
  44326. var transformArgs = argsArray[iTransform];
  44327. positions[(q << 1)] = transformArgs[4];
  44328. positions[(q << 1) + 1] = transformArgs[5];
  44329. }
  44330. // Replace queue items.
  44331. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  44332. positions];
  44333. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  44334. argsArray.splice(iFirstSave, count * 4, args);
  44335. return iFirstSave + 1;
  44336. });
  44337. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  44338. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  44339. // sequences, if the font for each one is the same.
  44340. addState(InitialState,
  44341. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  44342. function (context) {
  44343. var MIN_CHARS_IN_BLOCK = 3;
  44344. var MAX_CHARS_IN_BLOCK = 1000;
  44345. var fnArray = context.fnArray, argsArray = context.argsArray;
  44346. var curr = context.iCurr;
  44347. var iFirstBeginText = curr - 4;
  44348. var iFirstSetFont = curr - 3;
  44349. var iFirstSetTextMatrix = curr - 2;
  44350. var iFirstShowText = curr - 1;
  44351. var iFirstEndText = curr;
  44352. // Look for the quintets.
  44353. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  44354. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  44355. var i = iFirstBeginText + 5;
  44356. var ii = fnArray.length;
  44357. while (i + 4 < ii) {
  44358. if (fnArray[i] !== OPS.beginText ||
  44359. fnArray[i + 1] !== OPS.setFont ||
  44360. fnArray[i + 2] !== OPS.setTextMatrix ||
  44361. fnArray[i + 3] !== OPS.showText ||
  44362. fnArray[i + 4] !== OPS.endText) {
  44363. break; // ops don't match
  44364. }
  44365. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  44366. argsArray[i + 1][1] !== firstSetFontArg1) {
  44367. break; // fonts don't match
  44368. }
  44369. i += 5;
  44370. }
  44371. // At this point, i is the index of the first op past the last valid
  44372. // quintet.
  44373. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  44374. if (count < MIN_CHARS_IN_BLOCK) {
  44375. return i;
  44376. }
  44377. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  44378. // showText, endText), include that as well. (E.g. <something> might be
  44379. // |dependency|.)
  44380. var iFirst = iFirstBeginText;
  44381. if (iFirstBeginText >= 4 &&
  44382. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  44383. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  44384. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  44385. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  44386. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  44387. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  44388. count++;
  44389. iFirst -= 5;
  44390. }
  44391. // Remove (endText, beginText, setFont) trios.
  44392. var iEndText = iFirst + 4;
  44393. for (var q = 1; q < count; q++) {
  44394. fnArray.splice(iEndText, 3);
  44395. argsArray.splice(iEndText, 3);
  44396. iEndText += 2;
  44397. }
  44398. return iEndText + 1;
  44399. });
  44400. function QueueOptimizer() {}
  44401. QueueOptimizer.prototype = {
  44402. optimize: function QueueOptimizer_optimize(queue) {
  44403. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44404. var context = {
  44405. iCurr: 0,
  44406. fnArray: fnArray,
  44407. argsArray: argsArray
  44408. };
  44409. var state;
  44410. var i = 0, ii = fnArray.length;
  44411. while (i < ii) {
  44412. state = (state || InitialState)[fnArray[i]];
  44413. if (typeof state === 'function') { // we found some handler
  44414. context.iCurr = i;
  44415. // state() returns the index of the first non-matching op (if we
  44416. // didn't match) or the first op past the modified ops (if we did
  44417. // match and replace).
  44418. i = state(context);
  44419. state = undefined; // reset the state machine
  44420. ii = context.fnArray.length;
  44421. } else {
  44422. i++;
  44423. }
  44424. }
  44425. }
  44426. };
  44427. return QueueOptimizer;
  44428. })();
  44429. exports.OperatorList = OperatorList;
  44430. exports.PartialEvaluator = PartialEvaluator;
  44431. }));
  44432. (function (root, factory) {
  44433. {
  44434. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  44435. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  44436. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  44437. }
  44438. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  44439. coreColorSpace, coreObj, coreEvaluator) {
  44440. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  44441. var AnnotationFlag = sharedUtil.AnnotationFlag;
  44442. var AnnotationType = sharedUtil.AnnotationType;
  44443. var OPS = sharedUtil.OPS;
  44444. var Util = sharedUtil.Util;
  44445. var isArray = sharedUtil.isArray;
  44446. var isInt = sharedUtil.isInt;
  44447. var isValidUrl = sharedUtil.isValidUrl;
  44448. var stringToBytes = sharedUtil.stringToBytes;
  44449. var stringToPDFString = sharedUtil.stringToPDFString;
  44450. var stringToUTF8String = sharedUtil.stringToUTF8String;
  44451. var warn = sharedUtil.warn;
  44452. var Dict = corePrimitives.Dict;
  44453. var isDict = corePrimitives.isDict;
  44454. var isName = corePrimitives.isName;
  44455. var Stream = coreStream.Stream;
  44456. var ColorSpace = coreColorSpace.ColorSpace;
  44457. var ObjectLoader = coreObj.ObjectLoader;
  44458. var FileSpec = coreObj.FileSpec;
  44459. var OperatorList = coreEvaluator.OperatorList;
  44460. /**
  44461. * @class
  44462. * @alias AnnotationFactory
  44463. */
  44464. function AnnotationFactory() {}
  44465. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  44466. /**
  44467. * @param {XRef} xref
  44468. * @param {Object} ref
  44469. * @returns {Annotation}
  44470. */
  44471. create: function AnnotationFactory_create(xref, ref) {
  44472. var dict = xref.fetchIfRef(ref);
  44473. if (!isDict(dict)) {
  44474. return;
  44475. }
  44476. // Determine the annotation's subtype.
  44477. var subtype = dict.get('Subtype');
  44478. subtype = isName(subtype) ? subtype.name : '';
  44479. // Return the right annotation object based on the subtype and field type.
  44480. var parameters = {
  44481. xref: xref,
  44482. dict: dict,
  44483. ref: ref
  44484. };
  44485. switch (subtype) {
  44486. case 'Link':
  44487. return new LinkAnnotation(parameters);
  44488. case 'Text':
  44489. return new TextAnnotation(parameters);
  44490. case 'Widget':
  44491. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44492. if (isName(fieldType) && fieldType.name === 'Tx') {
  44493. return new TextWidgetAnnotation(parameters);
  44494. }
  44495. return new WidgetAnnotation(parameters);
  44496. case 'Popup':
  44497. return new PopupAnnotation(parameters);
  44498. case 'Highlight':
  44499. return new HighlightAnnotation(parameters);
  44500. case 'Underline':
  44501. return new UnderlineAnnotation(parameters);
  44502. case 'Squiggly':
  44503. return new SquigglyAnnotation(parameters);
  44504. case 'StrikeOut':
  44505. return new StrikeOutAnnotation(parameters);
  44506. case 'FileAttachment':
  44507. return new FileAttachmentAnnotation(parameters);
  44508. default:
  44509. warn('Unimplemented annotation type "' + subtype + '", ' +
  44510. 'falling back to base annotation');
  44511. return new Annotation(parameters);
  44512. }
  44513. }
  44514. };
  44515. var Annotation = (function AnnotationClosure() {
  44516. // 12.5.5: Algorithm: Appearance streams
  44517. function getTransformMatrix(rect, bbox, matrix) {
  44518. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  44519. var minX = bounds[0];
  44520. var minY = bounds[1];
  44521. var maxX = bounds[2];
  44522. var maxY = bounds[3];
  44523. if (minX === maxX || minY === maxY) {
  44524. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  44525. // just apply the transform for rect
  44526. return [1, 0, 0, 1, rect[0], rect[1]];
  44527. }
  44528. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  44529. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  44530. return [
  44531. xRatio,
  44532. 0,
  44533. 0,
  44534. yRatio,
  44535. rect[0] - minX * xRatio,
  44536. rect[1] - minY * yRatio
  44537. ];
  44538. }
  44539. function getDefaultAppearance(dict) {
  44540. var appearanceState = dict.get('AP');
  44541. if (!isDict(appearanceState)) {
  44542. return;
  44543. }
  44544. var appearance;
  44545. var appearances = appearanceState.get('N');
  44546. if (isDict(appearances)) {
  44547. var as = dict.get('AS');
  44548. if (as && appearances.has(as.name)) {
  44549. appearance = appearances.get(as.name);
  44550. }
  44551. } else {
  44552. appearance = appearances;
  44553. }
  44554. return appearance;
  44555. }
  44556. function Annotation(params) {
  44557. var dict = params.dict;
  44558. this.setFlags(dict.get('F'));
  44559. this.setRectangle(dict.get('Rect'));
  44560. this.setColor(dict.get('C'));
  44561. this.setBorderStyle(dict);
  44562. this.appearance = getDefaultAppearance(dict);
  44563. // Expose public properties using a data object.
  44564. this.data = {};
  44565. this.data.id = params.ref.toString();
  44566. this.data.subtype = dict.get('Subtype').name;
  44567. this.data.annotationFlags = this.flags;
  44568. this.data.rect = this.rectangle;
  44569. this.data.color = this.color;
  44570. this.data.borderStyle = this.borderStyle;
  44571. this.data.hasAppearance = !!this.appearance;
  44572. }
  44573. Annotation.prototype = {
  44574. /**
  44575. * @return {boolean}
  44576. */
  44577. get viewable() {
  44578. if (this.flags) {
  44579. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44580. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  44581. !this.hasFlag(AnnotationFlag.NOVIEW);
  44582. }
  44583. return true;
  44584. },
  44585. /**
  44586. * @return {boolean}
  44587. */
  44588. get printable() {
  44589. if (this.flags) {
  44590. return this.hasFlag(AnnotationFlag.PRINT) &&
  44591. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44592. !this.hasFlag(AnnotationFlag.HIDDEN);
  44593. }
  44594. return false;
  44595. },
  44596. /**
  44597. * Set the flags.
  44598. *
  44599. * @public
  44600. * @memberof Annotation
  44601. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  44602. * characteristics
  44603. * @see {@link shared/util.js}
  44604. */
  44605. setFlags: function Annotation_setFlags(flags) {
  44606. if (isInt(flags)) {
  44607. this.flags = flags;
  44608. } else {
  44609. this.flags = 0;
  44610. }
  44611. },
  44612. /**
  44613. * Check if a provided flag is set.
  44614. *
  44615. * @public
  44616. * @memberof Annotation
  44617. * @param {number} flag - Hexadecimal representation for an annotation
  44618. * characteristic
  44619. * @return {boolean}
  44620. * @see {@link shared/util.js}
  44621. */
  44622. hasFlag: function Annotation_hasFlag(flag) {
  44623. if (this.flags) {
  44624. return (this.flags & flag) > 0;
  44625. }
  44626. return false;
  44627. },
  44628. /**
  44629. * Set the rectangle.
  44630. *
  44631. * @public
  44632. * @memberof Annotation
  44633. * @param {Array} rectangle - The rectangle array with exactly four entries
  44634. */
  44635. setRectangle: function Annotation_setRectangle(rectangle) {
  44636. if (isArray(rectangle) && rectangle.length === 4) {
  44637. this.rectangle = Util.normalizeRect(rectangle);
  44638. } else {
  44639. this.rectangle = [0, 0, 0, 0];
  44640. }
  44641. },
  44642. /**
  44643. * Set the color and take care of color space conversion.
  44644. *
  44645. * @public
  44646. * @memberof Annotation
  44647. * @param {Array} color - The color array containing either 0
  44648. * (transparent), 1 (grayscale), 3 (RGB) or
  44649. * 4 (CMYK) elements
  44650. */
  44651. setColor: function Annotation_setColor(color) {
  44652. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  44653. if (!isArray(color)) {
  44654. this.color = rgbColor;
  44655. return;
  44656. }
  44657. switch (color.length) {
  44658. case 0: // Transparent, which we indicate with a null value
  44659. this.color = null;
  44660. break;
  44661. case 1: // Convert grayscale to RGB
  44662. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  44663. this.color = rgbColor;
  44664. break;
  44665. case 3: // Convert RGB percentages to RGB
  44666. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  44667. this.color = rgbColor;
  44668. break;
  44669. case 4: // Convert CMYK to RGB
  44670. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  44671. this.color = rgbColor;
  44672. break;
  44673. default:
  44674. this.color = rgbColor;
  44675. break;
  44676. }
  44677. },
  44678. /**
  44679. * Set the border style (as AnnotationBorderStyle object).
  44680. *
  44681. * @public
  44682. * @memberof Annotation
  44683. * @param {Dict} borderStyle - The border style dictionary
  44684. */
  44685. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  44686. this.borderStyle = new AnnotationBorderStyle();
  44687. if (!isDict(borderStyle)) {
  44688. return;
  44689. }
  44690. if (borderStyle.has('BS')) {
  44691. var dict = borderStyle.get('BS');
  44692. var dictType;
  44693. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  44694. dictType.name === 'Border')) {
  44695. this.borderStyle.setWidth(dict.get('W'));
  44696. this.borderStyle.setStyle(dict.get('S'));
  44697. this.borderStyle.setDashArray(dict.get('D'));
  44698. }
  44699. } else if (borderStyle.has('Border')) {
  44700. var array = borderStyle.get('Border');
  44701. if (isArray(array) && array.length >= 3) {
  44702. this.borderStyle.setHorizontalCornerRadius(array[0]);
  44703. this.borderStyle.setVerticalCornerRadius(array[1]);
  44704. this.borderStyle.setWidth(array[2]);
  44705. if (array.length === 4) { // Dash array available
  44706. this.borderStyle.setDashArray(array[3]);
  44707. }
  44708. }
  44709. } else {
  44710. // There are no border entries in the dictionary. According to the
  44711. // specification, we should draw a solid border of width 1 in that
  44712. // case, but Adobe Reader did not implement that part of the
  44713. // specification and instead draws no border at all, so we do the same.
  44714. // See also https://github.com/mozilla/pdf.js/issues/6179.
  44715. this.borderStyle.setWidth(0);
  44716. }
  44717. },
  44718. /**
  44719. * Prepare the annotation for working with a popup in the display layer.
  44720. *
  44721. * @private
  44722. * @memberof Annotation
  44723. * @param {Dict} dict - The annotation's data dictionary
  44724. */
  44725. _preparePopup: function Annotation_preparePopup(dict) {
  44726. if (!dict.has('C')) {
  44727. // Fall back to the default background color.
  44728. this.data.color = null;
  44729. }
  44730. this.data.hasPopup = dict.has('Popup');
  44731. this.data.title = stringToPDFString(dict.get('T') || '');
  44732. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  44733. },
  44734. loadResources: function Annotation_loadResources(keys) {
  44735. return new Promise(function (resolve, reject) {
  44736. this.appearance.dict.getAsync('Resources').then(function (resources) {
  44737. if (!resources) {
  44738. resolve();
  44739. return;
  44740. }
  44741. var objectLoader = new ObjectLoader(resources.map,
  44742. keys,
  44743. resources.xref);
  44744. objectLoader.load().then(function() {
  44745. resolve(resources);
  44746. }, reject);
  44747. }, reject);
  44748. }.bind(this));
  44749. },
  44750. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  44751. if (!this.appearance) {
  44752. return Promise.resolve(new OperatorList());
  44753. }
  44754. var data = this.data;
  44755. var appearanceDict = this.appearance.dict;
  44756. var resourcesPromise = this.loadResources([
  44757. 'ExtGState',
  44758. 'ColorSpace',
  44759. 'Pattern',
  44760. 'Shading',
  44761. 'XObject',
  44762. 'Font'
  44763. // ProcSet
  44764. // Properties
  44765. ]);
  44766. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  44767. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  44768. var transform = getTransformMatrix(data.rect, bbox, matrix);
  44769. var self = this;
  44770. return resourcesPromise.then(function(resources) {
  44771. var opList = new OperatorList();
  44772. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  44773. return evaluator.getOperatorList(self.appearance, task,
  44774. resources, opList).
  44775. then(function () {
  44776. opList.addOp(OPS.endAnnotation, []);
  44777. self.appearance.reset();
  44778. return opList;
  44779. });
  44780. });
  44781. }
  44782. };
  44783. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  44784. annotations, opList, partialEvaluator, task, intent) {
  44785. var annotationPromises = [];
  44786. for (var i = 0, n = annotations.length; i < n; ++i) {
  44787. if ((intent === 'display' && annotations[i].viewable) ||
  44788. (intent === 'print' && annotations[i].printable)) {
  44789. annotationPromises.push(
  44790. annotations[i].getOperatorList(partialEvaluator, task));
  44791. }
  44792. }
  44793. return Promise.all(annotationPromises).then(function(operatorLists) {
  44794. opList.addOp(OPS.beginAnnotations, []);
  44795. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  44796. opList.addOpList(operatorLists[i]);
  44797. }
  44798. opList.addOp(OPS.endAnnotations, []);
  44799. });
  44800. };
  44801. return Annotation;
  44802. })();
  44803. /**
  44804. * Contains all data regarding an annotation's border style.
  44805. *
  44806. * @class
  44807. */
  44808. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  44809. /**
  44810. * @constructor
  44811. * @private
  44812. */
  44813. function AnnotationBorderStyle() {
  44814. this.width = 1;
  44815. this.style = AnnotationBorderStyleType.SOLID;
  44816. this.dashArray = [3];
  44817. this.horizontalCornerRadius = 0;
  44818. this.verticalCornerRadius = 0;
  44819. }
  44820. AnnotationBorderStyle.prototype = {
  44821. /**
  44822. * Set the width.
  44823. *
  44824. * @public
  44825. * @memberof AnnotationBorderStyle
  44826. * @param {integer} width - The width
  44827. */
  44828. setWidth: function AnnotationBorderStyle_setWidth(width) {
  44829. if (width === (width | 0)) {
  44830. this.width = width;
  44831. }
  44832. },
  44833. /**
  44834. * Set the style.
  44835. *
  44836. * @public
  44837. * @memberof AnnotationBorderStyle
  44838. * @param {Object} style - The style object
  44839. * @see {@link shared/util.js}
  44840. */
  44841. setStyle: function AnnotationBorderStyle_setStyle(style) {
  44842. if (!style) {
  44843. return;
  44844. }
  44845. switch (style.name) {
  44846. case 'S':
  44847. this.style = AnnotationBorderStyleType.SOLID;
  44848. break;
  44849. case 'D':
  44850. this.style = AnnotationBorderStyleType.DASHED;
  44851. break;
  44852. case 'B':
  44853. this.style = AnnotationBorderStyleType.BEVELED;
  44854. break;
  44855. case 'I':
  44856. this.style = AnnotationBorderStyleType.INSET;
  44857. break;
  44858. case 'U':
  44859. this.style = AnnotationBorderStyleType.UNDERLINE;
  44860. break;
  44861. default:
  44862. break;
  44863. }
  44864. },
  44865. /**
  44866. * Set the dash array.
  44867. *
  44868. * @public
  44869. * @memberof AnnotationBorderStyle
  44870. * @param {Array} dashArray - The dash array with at least one element
  44871. */
  44872. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  44873. // We validate the dash array, but we do not use it because CSS does not
  44874. // allow us to change spacing of dashes. For more information, visit
  44875. // http://www.w3.org/TR/css3-background/#the-border-style.
  44876. if (isArray(dashArray) && dashArray.length > 0) {
  44877. // According to the PDF specification: the elements in a dashArray
  44878. // shall be numbers that are nonnegative and not all equal to zero.
  44879. var isValid = true;
  44880. var allZeros = true;
  44881. for (var i = 0, len = dashArray.length; i < len; i++) {
  44882. var element = dashArray[i];
  44883. var validNumber = (+element >= 0);
  44884. if (!validNumber) {
  44885. isValid = false;
  44886. break;
  44887. } else if (element > 0) {
  44888. allZeros = false;
  44889. }
  44890. }
  44891. if (isValid && !allZeros) {
  44892. this.dashArray = dashArray;
  44893. } else {
  44894. this.width = 0; // Adobe behavior when the array is invalid.
  44895. }
  44896. } else if (dashArray) {
  44897. this.width = 0; // Adobe behavior when the array is invalid.
  44898. }
  44899. },
  44900. /**
  44901. * Set the horizontal corner radius (from a Border dictionary).
  44902. *
  44903. * @public
  44904. * @memberof AnnotationBorderStyle
  44905. * @param {integer} radius - The horizontal corner radius
  44906. */
  44907. setHorizontalCornerRadius:
  44908. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  44909. if (radius === (radius | 0)) {
  44910. this.horizontalCornerRadius = radius;
  44911. }
  44912. },
  44913. /**
  44914. * Set the vertical corner radius (from a Border dictionary).
  44915. *
  44916. * @public
  44917. * @memberof AnnotationBorderStyle
  44918. * @param {integer} radius - The vertical corner radius
  44919. */
  44920. setVerticalCornerRadius:
  44921. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  44922. if (radius === (radius | 0)) {
  44923. this.verticalCornerRadius = radius;
  44924. }
  44925. }
  44926. };
  44927. return AnnotationBorderStyle;
  44928. })();
  44929. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  44930. function WidgetAnnotation(params) {
  44931. Annotation.call(this, params);
  44932. var dict = params.dict;
  44933. var data = this.data;
  44934. data.annotationType = AnnotationType.WIDGET;
  44935. data.fieldValue = stringToPDFString(
  44936. Util.getInheritableProperty(dict, 'V') || '');
  44937. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  44938. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  44939. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44940. data.fieldType = isName(fieldType) ? fieldType.name : '';
  44941. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  44942. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  44943. // Hide unsupported Widget signatures.
  44944. if (data.fieldType === 'Sig') {
  44945. warn('unimplemented annotation type: Widget signature');
  44946. this.setFlags(AnnotationFlag.HIDDEN);
  44947. }
  44948. // Building the full field name by collecting the field and
  44949. // its ancestors 'T' data and joining them using '.'.
  44950. var fieldName = [];
  44951. var namedItem = dict;
  44952. var ref = params.ref;
  44953. while (namedItem) {
  44954. var parent = namedItem.get('Parent');
  44955. var parentRef = namedItem.getRaw('Parent');
  44956. var name = namedItem.get('T');
  44957. if (name) {
  44958. fieldName.unshift(stringToPDFString(name));
  44959. } else if (parent && ref) {
  44960. // The field name is absent, that means more than one field
  44961. // with the same name may exist. Replacing the empty name
  44962. // with the '`' plus index in the parent's 'Kids' array.
  44963. // This is not in the PDF spec but necessary to id the
  44964. // the input controls.
  44965. var kids = parent.get('Kids');
  44966. var j, jj;
  44967. for (j = 0, jj = kids.length; j < jj; j++) {
  44968. var kidRef = kids[j];
  44969. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  44970. break;
  44971. }
  44972. }
  44973. fieldName.unshift('`' + j);
  44974. }
  44975. namedItem = parent;
  44976. ref = parentRef;
  44977. }
  44978. data.fullName = fieldName.join('.');
  44979. }
  44980. Util.inherit(WidgetAnnotation, Annotation, {});
  44981. return WidgetAnnotation;
  44982. })();
  44983. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  44984. function TextWidgetAnnotation(params) {
  44985. WidgetAnnotation.call(this, params);
  44986. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  44987. }
  44988. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  44989. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  44990. task) {
  44991. if (this.appearance) {
  44992. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  44993. }
  44994. var opList = new OperatorList();
  44995. var data = this.data;
  44996. // Even if there is an appearance stream, ignore it. This is the
  44997. // behaviour used by Adobe Reader.
  44998. if (!data.defaultAppearance) {
  44999. return Promise.resolve(opList);
  45000. }
  45001. var stream = new Stream(stringToBytes(data.defaultAppearance));
  45002. return evaluator.getOperatorList(stream, task,
  45003. this.fieldResources, opList).
  45004. then(function () {
  45005. return opList;
  45006. });
  45007. }
  45008. });
  45009. return TextWidgetAnnotation;
  45010. })();
  45011. var TextAnnotation = (function TextAnnotationClosure() {
  45012. var DEFAULT_ICON_SIZE = 22; // px
  45013. function TextAnnotation(parameters) {
  45014. Annotation.call(this, parameters);
  45015. this.data.annotationType = AnnotationType.TEXT;
  45016. if (this.data.hasAppearance) {
  45017. this.data.name = 'NoIcon';
  45018. } else {
  45019. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  45020. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  45021. this.data.name = parameters.dict.has('Name') ?
  45022. parameters.dict.get('Name').name : 'Note';
  45023. }
  45024. this._preparePopup(parameters.dict);
  45025. }
  45026. Util.inherit(TextAnnotation, Annotation, {});
  45027. return TextAnnotation;
  45028. })();
  45029. var LinkAnnotation = (function LinkAnnotationClosure() {
  45030. function LinkAnnotation(params) {
  45031. Annotation.call(this, params);
  45032. var dict = params.dict;
  45033. var data = this.data;
  45034. data.annotationType = AnnotationType.LINK;
  45035. var action = dict.get('A');
  45036. if (action && isDict(action)) {
  45037. var linkType = action.get('S').name;
  45038. if (linkType === 'URI') {
  45039. var url = action.get('URI');
  45040. if (isName(url)) {
  45041. // Some bad PDFs do not put parentheses around relative URLs.
  45042. url = '/' + url.name;
  45043. } else if (url) {
  45044. url = addDefaultProtocolToUrl(url);
  45045. }
  45046. // TODO: pdf spec mentions urls can be relative to a Base
  45047. // entry in the dictionary.
  45048. if (!isValidUrl(url, false)) {
  45049. url = '';
  45050. }
  45051. // According to ISO 32000-1:2008, section 12.6.4.7,
  45052. // URI should to be encoded in 7-bit ASCII.
  45053. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  45054. try {
  45055. data.url = stringToUTF8String(url);
  45056. } catch (e) {
  45057. // Fall back to a simple copy.
  45058. data.url = url;
  45059. }
  45060. } else if (linkType === 'GoTo') {
  45061. data.dest = action.get('D');
  45062. } else if (linkType === 'GoToR') {
  45063. var urlDict = action.get('F');
  45064. if (isDict(urlDict)) {
  45065. // We assume that the 'url' is a Filspec dictionary
  45066. // and fetch the url without checking any further
  45067. url = urlDict.get('F') || '';
  45068. }
  45069. // TODO: pdf reference says that GoToR
  45070. // can also have 'NewWindow' attribute
  45071. if (!isValidUrl(url, false)) {
  45072. url = '';
  45073. }
  45074. data.url = url;
  45075. data.dest = action.get('D');
  45076. } else if (linkType === 'Named') {
  45077. data.action = action.get('N').name;
  45078. } else {
  45079. warn('unrecognized link type: ' + linkType);
  45080. }
  45081. } else if (dict.has('Dest')) {
  45082. // simple destination link
  45083. var dest = dict.get('Dest');
  45084. data.dest = isName(dest) ? dest.name : dest;
  45085. }
  45086. }
  45087. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  45088. function addDefaultProtocolToUrl(url) {
  45089. if (url && url.indexOf('www.') === 0) {
  45090. return ('http://' + url);
  45091. }
  45092. return url;
  45093. }
  45094. Util.inherit(LinkAnnotation, Annotation, {});
  45095. return LinkAnnotation;
  45096. })();
  45097. var PopupAnnotation = (function PopupAnnotationClosure() {
  45098. function PopupAnnotation(parameters) {
  45099. Annotation.call(this, parameters);
  45100. this.data.annotationType = AnnotationType.POPUP;
  45101. var dict = parameters.dict;
  45102. var parentItem = dict.get('Parent');
  45103. if (!parentItem) {
  45104. warn('Popup annotation has a missing or invalid parent annotation.');
  45105. return;
  45106. }
  45107. this.data.parentId = dict.getRaw('Parent').toString();
  45108. this.data.title = stringToPDFString(parentItem.get('T') || '');
  45109. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  45110. if (!parentItem.has('C')) {
  45111. // Fall back to the default background color.
  45112. this.data.color = null;
  45113. } else {
  45114. this.setColor(parentItem.get('C'));
  45115. this.data.color = this.color;
  45116. }
  45117. }
  45118. Util.inherit(PopupAnnotation, Annotation, {});
  45119. return PopupAnnotation;
  45120. })();
  45121. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  45122. function HighlightAnnotation(parameters) {
  45123. Annotation.call(this, parameters);
  45124. this.data.annotationType = AnnotationType.HIGHLIGHT;
  45125. this._preparePopup(parameters.dict);
  45126. // PDF viewers completely ignore any border styles.
  45127. this.data.borderStyle.setWidth(0);
  45128. }
  45129. Util.inherit(HighlightAnnotation, Annotation, {});
  45130. return HighlightAnnotation;
  45131. })();
  45132. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  45133. function UnderlineAnnotation(parameters) {
  45134. Annotation.call(this, parameters);
  45135. this.data.annotationType = AnnotationType.UNDERLINE;
  45136. this._preparePopup(parameters.dict);
  45137. // PDF viewers completely ignore any border styles.
  45138. this.data.borderStyle.setWidth(0);
  45139. }
  45140. Util.inherit(UnderlineAnnotation, Annotation, {});
  45141. return UnderlineAnnotation;
  45142. })();
  45143. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  45144. function SquigglyAnnotation(parameters) {
  45145. Annotation.call(this, parameters);
  45146. this.data.annotationType = AnnotationType.SQUIGGLY;
  45147. this._preparePopup(parameters.dict);
  45148. // PDF viewers completely ignore any border styles.
  45149. this.data.borderStyle.setWidth(0);
  45150. }
  45151. Util.inherit(SquigglyAnnotation, Annotation, {});
  45152. return SquigglyAnnotation;
  45153. })();
  45154. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  45155. function StrikeOutAnnotation(parameters) {
  45156. Annotation.call(this, parameters);
  45157. this.data.annotationType = AnnotationType.STRIKEOUT;
  45158. this._preparePopup(parameters.dict);
  45159. // PDF viewers completely ignore any border styles.
  45160. this.data.borderStyle.setWidth(0);
  45161. }
  45162. Util.inherit(StrikeOutAnnotation, Annotation, {});
  45163. return StrikeOutAnnotation;
  45164. })();
  45165. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  45166. function FileAttachmentAnnotation(parameters) {
  45167. Annotation.call(this, parameters);
  45168. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  45169. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  45170. this.data.file = file.serializable;
  45171. this._preparePopup(parameters.dict);
  45172. }
  45173. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  45174. return FileAttachmentAnnotation;
  45175. })();
  45176. exports.Annotation = Annotation;
  45177. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  45178. exports.AnnotationFactory = AnnotationFactory;
  45179. }));
  45180. (function (root, factory) {
  45181. {
  45182. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  45183. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  45184. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  45185. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  45186. }
  45187. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  45188. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  45189. var MissingDataException = sharedUtil.MissingDataException;
  45190. var Util = sharedUtil.Util;
  45191. var assert = sharedUtil.assert;
  45192. var error = sharedUtil.error;
  45193. var info = sharedUtil.info;
  45194. var isArray = sharedUtil.isArray;
  45195. var isArrayBuffer = sharedUtil.isArrayBuffer;
  45196. var isString = sharedUtil.isString;
  45197. var shadow = sharedUtil.shadow;
  45198. var stringToBytes = sharedUtil.stringToBytes;
  45199. var stringToPDFString = sharedUtil.stringToPDFString;
  45200. var warn = sharedUtil.warn;
  45201. var Dict = corePrimitives.Dict;
  45202. var isDict = corePrimitives.isDict;
  45203. var isName = corePrimitives.isName;
  45204. var isStream = corePrimitives.isStream;
  45205. var NullStream = coreStream.NullStream;
  45206. var Stream = coreStream.Stream;
  45207. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  45208. var Catalog = coreObj.Catalog;
  45209. var ObjectLoader = coreObj.ObjectLoader;
  45210. var XRef = coreObj.XRef;
  45211. var Lexer = coreParser.Lexer;
  45212. var Linearization = coreParser.Linearization;
  45213. var calculateMD5 = coreCrypto.calculateMD5;
  45214. var OperatorList = coreEvaluator.OperatorList;
  45215. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  45216. var Annotation = coreAnnotation.Annotation;
  45217. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  45218. var Page = (function PageClosure() {
  45219. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  45220. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  45221. this.pdfManager = pdfManager;
  45222. this.pageIndex = pageIndex;
  45223. this.pageDict = pageDict;
  45224. this.xref = xref;
  45225. this.ref = ref;
  45226. this.fontCache = fontCache;
  45227. this.idCounters = {
  45228. obj: 0
  45229. };
  45230. this.resourcesPromise = null;
  45231. }
  45232. Page.prototype = {
  45233. getPageProp: function Page_getPageProp(key) {
  45234. return this.pageDict.get(key);
  45235. },
  45236. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  45237. var dict = this.pageDict, valueArray = null, loopCount = 0;
  45238. var MAX_LOOP_COUNT = 100;
  45239. // Always walk up the entire parent chain, to be able to find
  45240. // e.g. \Resources placed on multiple levels of the tree.
  45241. while (dict) {
  45242. var value = dict.get(key);
  45243. if (value) {
  45244. if (!valueArray) {
  45245. valueArray = [];
  45246. }
  45247. valueArray.push(value);
  45248. }
  45249. if (++loopCount > MAX_LOOP_COUNT) {
  45250. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  45251. break;
  45252. }
  45253. dict = dict.get('Parent');
  45254. }
  45255. if (!valueArray) {
  45256. return Dict.empty;
  45257. }
  45258. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  45259. loopCount > MAX_LOOP_COUNT) {
  45260. return valueArray[0];
  45261. }
  45262. return Dict.merge(this.xref, valueArray);
  45263. },
  45264. get content() {
  45265. return this.getPageProp('Contents');
  45266. },
  45267. get resources() {
  45268. // For robustness: The spec states that a \Resources entry has to be
  45269. // present, but can be empty. Some document omit it still, in this case
  45270. // we return an empty dictionary.
  45271. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  45272. },
  45273. get mediaBox() {
  45274. var obj = this.getInheritedPageProp('MediaBox');
  45275. // Reset invalid media box to letter size.
  45276. if (!isArray(obj) || obj.length !== 4) {
  45277. obj = LETTER_SIZE_MEDIABOX;
  45278. }
  45279. return shadow(this, 'mediaBox', obj);
  45280. },
  45281. get view() {
  45282. var mediaBox = this.mediaBox;
  45283. var cropBox = this.getInheritedPageProp('CropBox');
  45284. if (!isArray(cropBox) || cropBox.length !== 4) {
  45285. return shadow(this, 'view', mediaBox);
  45286. }
  45287. // From the spec, 6th ed., p.963:
  45288. // "The crop, bleed, trim, and art boxes should not ordinarily
  45289. // extend beyond the boundaries of the media box. If they do, they are
  45290. // effectively reduced to their intersection with the media box."
  45291. cropBox = Util.intersect(cropBox, mediaBox);
  45292. if (!cropBox) {
  45293. return shadow(this, 'view', mediaBox);
  45294. }
  45295. return shadow(this, 'view', cropBox);
  45296. },
  45297. get rotate() {
  45298. var rotate = this.getInheritedPageProp('Rotate') || 0;
  45299. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  45300. if (rotate % 90 !== 0) {
  45301. rotate = 0;
  45302. } else if (rotate >= 360) {
  45303. rotate = rotate % 360;
  45304. } else if (rotate < 0) {
  45305. // The spec doesn't cover negatives, assume its counterclockwise
  45306. // rotation. The following is the other implementation of modulo.
  45307. rotate = ((rotate % 360) + 360) % 360;
  45308. }
  45309. return shadow(this, 'rotate', rotate);
  45310. },
  45311. getContentStream: function Page_getContentStream() {
  45312. var content = this.content;
  45313. var stream;
  45314. if (isArray(content)) {
  45315. // fetching items
  45316. var xref = this.xref;
  45317. var i, n = content.length;
  45318. var streams = [];
  45319. for (i = 0; i < n; ++i) {
  45320. streams.push(xref.fetchIfRef(content[i]));
  45321. }
  45322. stream = new StreamsSequenceStream(streams);
  45323. } else if (isStream(content)) {
  45324. stream = content;
  45325. } else {
  45326. // replacing non-existent page content with empty one
  45327. stream = new NullStream();
  45328. }
  45329. return stream;
  45330. },
  45331. loadResources: function Page_loadResources(keys) {
  45332. if (!this.resourcesPromise) {
  45333. // TODO: add async getInheritedPageProp and remove this.
  45334. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  45335. }
  45336. return this.resourcesPromise.then(function resourceSuccess() {
  45337. var objectLoader = new ObjectLoader(this.resources.map,
  45338. keys,
  45339. this.xref);
  45340. return objectLoader.load();
  45341. }.bind(this));
  45342. },
  45343. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  45344. var self = this;
  45345. var pdfManager = this.pdfManager;
  45346. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45347. []);
  45348. var resourcesPromise = this.loadResources([
  45349. 'ExtGState',
  45350. 'ColorSpace',
  45351. 'Pattern',
  45352. 'Shading',
  45353. 'XObject',
  45354. 'Font'
  45355. // ProcSet
  45356. // Properties
  45357. ]);
  45358. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  45359. handler, this.pageIndex,
  45360. 'p' + this.pageIndex + '_',
  45361. this.idCounters,
  45362. this.fontCache);
  45363. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  45364. var pageListPromise = dataPromises.then(function(data) {
  45365. var contentStream = data[0];
  45366. var opList = new OperatorList(intent, handler, self.pageIndex);
  45367. handler.send('StartRenderPage', {
  45368. transparency: partialEvaluator.hasBlendModes(self.resources),
  45369. pageIndex: self.pageIndex,
  45370. intent: intent
  45371. });
  45372. return partialEvaluator.getOperatorList(contentStream, task,
  45373. self.resources, opList).then(function () {
  45374. return opList;
  45375. });
  45376. });
  45377. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  45378. return Promise.all([pageListPromise, annotationsPromise]).then(
  45379. function(datas) {
  45380. var pageOpList = datas[0];
  45381. var annotations = datas[1];
  45382. if (annotations.length === 0) {
  45383. pageOpList.flush(true);
  45384. return pageOpList;
  45385. }
  45386. var annotationsReadyPromise = Annotation.appendToOperatorList(
  45387. annotations, pageOpList, partialEvaluator, task, intent);
  45388. return annotationsReadyPromise.then(function () {
  45389. pageOpList.flush(true);
  45390. return pageOpList;
  45391. });
  45392. });
  45393. },
  45394. extractTextContent: function Page_extractTextContent(task,
  45395. normalizeWhitespace) {
  45396. var handler = {
  45397. on: function nullHandlerOn() {},
  45398. send: function nullHandlerSend() {}
  45399. };
  45400. var self = this;
  45401. var pdfManager = this.pdfManager;
  45402. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45403. []);
  45404. var resourcesPromise = this.loadResources([
  45405. 'ExtGState',
  45406. 'XObject',
  45407. 'Font'
  45408. ]);
  45409. var dataPromises = Promise.all([contentStreamPromise,
  45410. resourcesPromise]);
  45411. return dataPromises.then(function(data) {
  45412. var contentStream = data[0];
  45413. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  45414. handler, self.pageIndex,
  45415. 'p' + self.pageIndex + '_',
  45416. self.idCounters,
  45417. self.fontCache);
  45418. return partialEvaluator.getTextContent(contentStream,
  45419. task,
  45420. self.resources,
  45421. /* stateManager = */ null,
  45422. normalizeWhitespace);
  45423. });
  45424. },
  45425. getAnnotationsData: function Page_getAnnotationsData(intent) {
  45426. var annotations = this.annotations;
  45427. var annotationsData = [];
  45428. for (var i = 0, n = annotations.length; i < n; ++i) {
  45429. if (intent) {
  45430. if (!(intent === 'display' && annotations[i].viewable) &&
  45431. !(intent === 'print' && annotations[i].printable)) {
  45432. continue;
  45433. }
  45434. }
  45435. annotationsData.push(annotations[i].data);
  45436. }
  45437. return annotationsData;
  45438. },
  45439. get annotations() {
  45440. var annotations = [];
  45441. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  45442. var annotationFactory = new AnnotationFactory();
  45443. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  45444. var annotationRef = annotationRefs[i];
  45445. var annotation = annotationFactory.create(this.xref, annotationRef);
  45446. if (annotation) {
  45447. annotations.push(annotation);
  45448. }
  45449. }
  45450. return shadow(this, 'annotations', annotations);
  45451. }
  45452. };
  45453. return Page;
  45454. })();
  45455. /**
  45456. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  45457. * `PDFDoc`, this one doesn't have any job management code.
  45458. * Right now there exists one PDFDocument on the main thread + one object
  45459. * for each worker. If there is no worker support enabled, there are two
  45460. * `PDFDocument` objects on the main thread created.
  45461. */
  45462. var PDFDocument = (function PDFDocumentClosure() {
  45463. var FINGERPRINT_FIRST_BYTES = 1024;
  45464. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  45465. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  45466. function PDFDocument(pdfManager, arg, password) {
  45467. if (isStream(arg)) {
  45468. init.call(this, pdfManager, arg, password);
  45469. } else if (isArrayBuffer(arg)) {
  45470. init.call(this, pdfManager, new Stream(arg), password);
  45471. } else {
  45472. error('PDFDocument: Unknown argument type');
  45473. }
  45474. }
  45475. function init(pdfManager, stream, password) {
  45476. assert(stream.length > 0, 'stream must have data');
  45477. this.pdfManager = pdfManager;
  45478. this.stream = stream;
  45479. var xref = new XRef(this.stream, password, pdfManager);
  45480. this.xref = xref;
  45481. }
  45482. function find(stream, needle, limit, backwards) {
  45483. var pos = stream.pos;
  45484. var end = stream.end;
  45485. var strBuf = [];
  45486. if (pos + limit > end) {
  45487. limit = end - pos;
  45488. }
  45489. for (var n = 0; n < limit; ++n) {
  45490. strBuf.push(String.fromCharCode(stream.getByte()));
  45491. }
  45492. var str = strBuf.join('');
  45493. stream.pos = pos;
  45494. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  45495. if (index === -1) {
  45496. return false; /* not found */
  45497. }
  45498. stream.pos += index;
  45499. return true; /* found */
  45500. }
  45501. var DocumentInfoValidators = {
  45502. get entries() {
  45503. // Lazily build this since all the validation functions below are not
  45504. // defined until after this file loads.
  45505. return shadow(this, 'entries', {
  45506. Title: isString,
  45507. Author: isString,
  45508. Subject: isString,
  45509. Keywords: isString,
  45510. Creator: isString,
  45511. Producer: isString,
  45512. CreationDate: isString,
  45513. ModDate: isString,
  45514. Trapped: isName
  45515. });
  45516. }
  45517. };
  45518. PDFDocument.prototype = {
  45519. parse: function PDFDocument_parse(recoveryMode) {
  45520. this.setup(recoveryMode);
  45521. var version = this.catalog.catDict.get('Version');
  45522. if (isName(version)) {
  45523. this.pdfFormatVersion = version.name;
  45524. }
  45525. try {
  45526. // checking if AcroForm is present
  45527. this.acroForm = this.catalog.catDict.get('AcroForm');
  45528. if (this.acroForm) {
  45529. this.xfa = this.acroForm.get('XFA');
  45530. var fields = this.acroForm.get('Fields');
  45531. if ((!fields || !isArray(fields) || fields.length === 0) &&
  45532. !this.xfa) {
  45533. // no fields and no XFA -- not a form (?)
  45534. this.acroForm = null;
  45535. }
  45536. }
  45537. } catch (ex) {
  45538. info('Something wrong with AcroForm entry');
  45539. this.acroForm = null;
  45540. }
  45541. },
  45542. get linearization() {
  45543. var linearization = null;
  45544. if (this.stream.length) {
  45545. try {
  45546. linearization = Linearization.create(this.stream);
  45547. } catch (err) {
  45548. if (err instanceof MissingDataException) {
  45549. throw err;
  45550. }
  45551. info(err);
  45552. }
  45553. }
  45554. // shadow the prototype getter with a data property
  45555. return shadow(this, 'linearization', linearization);
  45556. },
  45557. get startXRef() {
  45558. var stream = this.stream;
  45559. var startXRef = 0;
  45560. var linearization = this.linearization;
  45561. if (linearization) {
  45562. // Find end of first obj.
  45563. stream.reset();
  45564. if (find(stream, 'endobj', 1024)) {
  45565. startXRef = stream.pos + 6;
  45566. }
  45567. } else {
  45568. // Find startxref by jumping backward from the end of the file.
  45569. var step = 1024;
  45570. var found = false, pos = stream.end;
  45571. while (!found && pos > 0) {
  45572. pos -= step - 'startxref'.length;
  45573. if (pos < 0) {
  45574. pos = 0;
  45575. }
  45576. stream.pos = pos;
  45577. found = find(stream, 'startxref', step, true);
  45578. }
  45579. if (found) {
  45580. stream.skip(9);
  45581. var ch;
  45582. do {
  45583. ch = stream.getByte();
  45584. } while (Lexer.isSpace(ch));
  45585. var str = '';
  45586. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  45587. str += String.fromCharCode(ch);
  45588. ch = stream.getByte();
  45589. }
  45590. startXRef = parseInt(str, 10);
  45591. if (isNaN(startXRef)) {
  45592. startXRef = 0;
  45593. }
  45594. }
  45595. }
  45596. // shadow the prototype getter with a data property
  45597. return shadow(this, 'startXRef', startXRef);
  45598. },
  45599. get mainXRefEntriesOffset() {
  45600. var mainXRefEntriesOffset = 0;
  45601. var linearization = this.linearization;
  45602. if (linearization) {
  45603. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  45604. }
  45605. // shadow the prototype getter with a data property
  45606. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  45607. },
  45608. // Find the header, remove leading garbage and setup the stream
  45609. // starting from the header.
  45610. checkHeader: function PDFDocument_checkHeader() {
  45611. var stream = this.stream;
  45612. stream.reset();
  45613. if (find(stream, '%PDF-', 1024)) {
  45614. // Found the header, trim off any garbage before it.
  45615. stream.moveStart();
  45616. // Reading file format version
  45617. var MAX_VERSION_LENGTH = 12;
  45618. var version = '', ch;
  45619. while ((ch = stream.getByte()) > 0x20) { // SPACE
  45620. if (version.length >= MAX_VERSION_LENGTH) {
  45621. break;
  45622. }
  45623. version += String.fromCharCode(ch);
  45624. }
  45625. if (!this.pdfFormatVersion) {
  45626. // removing "%PDF-"-prefix
  45627. this.pdfFormatVersion = version.substring(5);
  45628. }
  45629. return;
  45630. }
  45631. // May not be a PDF file, continue anyway.
  45632. },
  45633. parseStartXRef: function PDFDocument_parseStartXRef() {
  45634. var startXRef = this.startXRef;
  45635. this.xref.setStartXRef(startXRef);
  45636. },
  45637. setup: function PDFDocument_setup(recoveryMode) {
  45638. this.xref.parse(recoveryMode);
  45639. var self = this;
  45640. var pageFactory = {
  45641. createPage: function (pageIndex, dict, ref, fontCache) {
  45642. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  45643. fontCache);
  45644. }
  45645. };
  45646. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  45647. },
  45648. get numPages() {
  45649. var linearization = this.linearization;
  45650. var num = linearization ? linearization.numPages : this.catalog.numPages;
  45651. // shadow the prototype getter
  45652. return shadow(this, 'numPages', num);
  45653. },
  45654. get documentInfo() {
  45655. var docInfo = {
  45656. PDFFormatVersion: this.pdfFormatVersion,
  45657. IsAcroFormPresent: !!this.acroForm,
  45658. IsXFAPresent: !!this.xfa
  45659. };
  45660. var infoDict;
  45661. try {
  45662. infoDict = this.xref.trailer.get('Info');
  45663. } catch (err) {
  45664. info('The document information dictionary is invalid.');
  45665. }
  45666. if (infoDict) {
  45667. var validEntries = DocumentInfoValidators.entries;
  45668. // Only fill the document info with valid entries from the spec.
  45669. for (var key in validEntries) {
  45670. if (infoDict.has(key)) {
  45671. var value = infoDict.get(key);
  45672. // Make sure the value conforms to the spec.
  45673. if (validEntries[key](value)) {
  45674. docInfo[key] = (typeof value !== 'string' ?
  45675. value : stringToPDFString(value));
  45676. } else {
  45677. info('Bad value in document info for "' + key + '"');
  45678. }
  45679. }
  45680. }
  45681. }
  45682. return shadow(this, 'documentInfo', docInfo);
  45683. },
  45684. get fingerprint() {
  45685. var xref = this.xref, hash, fileID = '';
  45686. var idArray = xref.trailer.get('ID');
  45687. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  45688. idArray[0] !== EMPTY_FINGERPRINT) {
  45689. hash = stringToBytes(idArray[0]);
  45690. } else {
  45691. if (this.stream.ensureRange) {
  45692. this.stream.ensureRange(0,
  45693. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  45694. }
  45695. hash = calculateMD5(this.stream.bytes.subarray(0,
  45696. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  45697. }
  45698. for (var i = 0, n = hash.length; i < n; i++) {
  45699. var hex = hash[i].toString(16);
  45700. fileID += hex.length === 1 ? '0' + hex : hex;
  45701. }
  45702. return shadow(this, 'fingerprint', fileID);
  45703. },
  45704. getPage: function PDFDocument_getPage(pageIndex) {
  45705. return this.catalog.getPage(pageIndex);
  45706. },
  45707. cleanup: function PDFDocument_cleanup() {
  45708. return this.catalog.cleanup();
  45709. }
  45710. };
  45711. return PDFDocument;
  45712. })();
  45713. exports.Page = Page;
  45714. exports.PDFDocument = PDFDocument;
  45715. }));
  45716. (function (root, factory) {
  45717. {
  45718. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  45719. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  45720. root.pdfjsCoreDocument);
  45721. }
  45722. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  45723. coreDocument) {
  45724. var NotImplementedException = sharedUtil.NotImplementedException;
  45725. var MissingDataException = sharedUtil.MissingDataException;
  45726. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45727. var Util = sharedUtil.Util;
  45728. var Stream = coreStream.Stream;
  45729. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  45730. var PDFDocument = coreDocument.PDFDocument;
  45731. var BasePdfManager = (function BasePdfManagerClosure() {
  45732. function BasePdfManager() {
  45733. throw new Error('Cannot initialize BaseManagerManager');
  45734. }
  45735. BasePdfManager.prototype = {
  45736. get docId() {
  45737. return this._docId;
  45738. },
  45739. onLoadedStream: function BasePdfManager_onLoadedStream() {
  45740. throw new NotImplementedException();
  45741. },
  45742. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  45743. return this.ensure(this.pdfDocument, prop, args);
  45744. },
  45745. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  45746. return this.ensure(this.pdfDocument.xref, prop, args);
  45747. },
  45748. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  45749. return this.ensure(this.pdfDocument.catalog, prop, args);
  45750. },
  45751. getPage: function BasePdfManager_getPage(pageIndex) {
  45752. return this.pdfDocument.getPage(pageIndex);
  45753. },
  45754. cleanup: function BasePdfManager_cleanup() {
  45755. return this.pdfDocument.cleanup();
  45756. },
  45757. ensure: function BasePdfManager_ensure(obj, prop, args) {
  45758. return new NotImplementedException();
  45759. },
  45760. requestRange: function BasePdfManager_requestRange(begin, end) {
  45761. return new NotImplementedException();
  45762. },
  45763. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  45764. return new NotImplementedException();
  45765. },
  45766. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  45767. return new NotImplementedException();
  45768. },
  45769. updatePassword: function BasePdfManager_updatePassword(password) {
  45770. this.pdfDocument.xref.password = this.password = password;
  45771. if (this._passwordChangedCapability) {
  45772. this._passwordChangedCapability.resolve();
  45773. }
  45774. },
  45775. passwordChanged: function BasePdfManager_passwordChanged() {
  45776. this._passwordChangedCapability = createPromiseCapability();
  45777. return this._passwordChangedCapability.promise;
  45778. },
  45779. terminate: function BasePdfManager_terminate() {
  45780. return new NotImplementedException();
  45781. }
  45782. };
  45783. return BasePdfManager;
  45784. })();
  45785. var LocalPdfManager = (function LocalPdfManagerClosure() {
  45786. function LocalPdfManager(docId, data, password) {
  45787. this._docId = docId;
  45788. var stream = new Stream(data);
  45789. this.pdfDocument = new PDFDocument(this, stream, password);
  45790. this._loadedStreamCapability = createPromiseCapability();
  45791. this._loadedStreamCapability.resolve(stream);
  45792. }
  45793. Util.inherit(LocalPdfManager, BasePdfManager, {
  45794. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  45795. return new Promise(function (resolve, reject) {
  45796. try {
  45797. var value = obj[prop];
  45798. var result;
  45799. if (typeof value === 'function') {
  45800. result = value.apply(obj, args);
  45801. } else {
  45802. result = value;
  45803. }
  45804. resolve(result);
  45805. } catch (e) {
  45806. reject(e);
  45807. }
  45808. });
  45809. },
  45810. requestRange: function LocalPdfManager_requestRange(begin, end) {
  45811. return Promise.resolve();
  45812. },
  45813. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  45814. return;
  45815. },
  45816. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  45817. return this._loadedStreamCapability.promise;
  45818. },
  45819. terminate: function LocalPdfManager_terminate() {
  45820. return;
  45821. }
  45822. });
  45823. return LocalPdfManager;
  45824. })();
  45825. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  45826. function NetworkPdfManager(docId, pdfNetworkStream, args) {
  45827. this._docId = docId;
  45828. this.msgHandler = args.msgHandler;
  45829. var params = {
  45830. msgHandler: args.msgHandler,
  45831. url: args.url,
  45832. length: args.length,
  45833. disableAutoFetch: args.disableAutoFetch,
  45834. rangeChunkSize: args.rangeChunkSize
  45835. };
  45836. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  45837. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  45838. args.password);
  45839. }
  45840. Util.inherit(NetworkPdfManager, BasePdfManager, {
  45841. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  45842. var pdfManager = this;
  45843. return new Promise(function (resolve, reject) {
  45844. function ensureHelper() {
  45845. try {
  45846. var result;
  45847. var value = obj[prop];
  45848. if (typeof value === 'function') {
  45849. result = value.apply(obj, args);
  45850. } else {
  45851. result = value;
  45852. }
  45853. resolve(result);
  45854. } catch(e) {
  45855. if (!(e instanceof MissingDataException)) {
  45856. reject(e);
  45857. return;
  45858. }
  45859. pdfManager.streamManager.requestRange(e.begin, e.end).
  45860. then(ensureHelper, reject);
  45861. }
  45862. }
  45863. ensureHelper();
  45864. });
  45865. },
  45866. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  45867. return this.streamManager.requestRange(begin, end);
  45868. },
  45869. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  45870. this.streamManager.requestAllChunks();
  45871. },
  45872. sendProgressiveData:
  45873. function NetworkPdfManager_sendProgressiveData(chunk) {
  45874. this.streamManager.onReceiveData({ chunk: chunk });
  45875. },
  45876. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  45877. return this.streamManager.onLoadedStream();
  45878. },
  45879. terminate: function NetworkPdfManager_terminate() {
  45880. this.streamManager.abort();
  45881. }
  45882. });
  45883. return NetworkPdfManager;
  45884. })();
  45885. exports.LocalPdfManager = LocalPdfManager;
  45886. exports.NetworkPdfManager = NetworkPdfManager;
  45887. }));
  45888. (function (root, factory) {
  45889. {
  45890. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  45891. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  45892. root.pdfjsSharedGlobal);
  45893. }
  45894. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  45895. sharedGlobal) {
  45896. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  45897. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45898. var MessageHandler = sharedUtil.MessageHandler;
  45899. var MissingPDFException = sharedUtil.MissingPDFException;
  45900. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  45901. var PasswordException = sharedUtil.PasswordException;
  45902. var PasswordResponses = sharedUtil.PasswordResponses;
  45903. var UnknownErrorException = sharedUtil.UnknownErrorException;
  45904. var XRefParseException = sharedUtil.XRefParseException;
  45905. var arrayByteLength = sharedUtil.arrayByteLength;
  45906. var arraysToBytes = sharedUtil.arraysToBytes;
  45907. var assert = sharedUtil.assert;
  45908. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45909. var error = sharedUtil.error;
  45910. var info = sharedUtil.info;
  45911. var warn = sharedUtil.warn;
  45912. var Ref = corePrimitives.Ref;
  45913. var LocalPdfManager = corePdfManager.LocalPdfManager;
  45914. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  45915. var globalScope = sharedGlobal.globalScope;
  45916. var PDFJS = sharedGlobal.PDFJS;
  45917. var WorkerTask = (function WorkerTaskClosure() {
  45918. function WorkerTask(name) {
  45919. this.name = name;
  45920. this.terminated = false;
  45921. this._capability = createPromiseCapability();
  45922. }
  45923. WorkerTask.prototype = {
  45924. get finished() {
  45925. return this._capability.promise;
  45926. },
  45927. finish: function () {
  45928. this._capability.resolve();
  45929. },
  45930. terminate: function () {
  45931. this.terminated = true;
  45932. },
  45933. ensureNotTerminated: function () {
  45934. if (this.terminated) {
  45935. throw new Error('Worker task was terminated');
  45936. }
  45937. }
  45938. };
  45939. return WorkerTask;
  45940. })();
  45941. /** @implements {IPDFStream} */
  45942. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  45943. function PDFWorkerStream(params, msgHandler) {
  45944. this._queuedChunks = [];
  45945. var initialData = params.initialData;
  45946. if (initialData && initialData.length > 0) {
  45947. this._queuedChunks.push(initialData);
  45948. }
  45949. this._msgHandler = msgHandler;
  45950. this._isRangeSupported = !(params.disableRange);
  45951. this._isStreamingSupported = !(params.disableStream);
  45952. this._contentLength = params.length;
  45953. this._fullRequestReader = null;
  45954. this._rangeReaders = [];
  45955. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  45956. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  45957. }
  45958. PDFWorkerStream.prototype = {
  45959. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  45960. if (args.begin === undefined) {
  45961. if (this._fullRequestReader) {
  45962. this._fullRequestReader._enqueue(args.chunk);
  45963. } else {
  45964. this._queuedChunks.push(args.chunk);
  45965. }
  45966. } else {
  45967. var found = this._rangeReaders.some(function (rangeReader) {
  45968. if (rangeReader._begin !== args.begin) {
  45969. return false;
  45970. }
  45971. rangeReader._enqueue(args.chunk);
  45972. return true;
  45973. });
  45974. assert(found);
  45975. }
  45976. },
  45977. _onProgress: function PDFWorkerStream_onProgress(evt) {
  45978. if (this._rangeReaders.length > 0) {
  45979. // Reporting to first range reader.
  45980. var firstReader = this._rangeReaders[0];
  45981. if (firstReader.onProgress) {
  45982. firstReader.onProgress({loaded: evt.loaded});
  45983. }
  45984. }
  45985. },
  45986. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  45987. var i = this._rangeReaders.indexOf(reader);
  45988. if (i >= 0) {
  45989. this._rangeReaders.splice(i, 1);
  45990. }
  45991. },
  45992. getFullReader: function PDFWorkerStream_getFullReader() {
  45993. assert(!this._fullRequestReader);
  45994. var queuedChunks = this._queuedChunks;
  45995. this._queuedChunks = null;
  45996. return new PDFWorkerStreamReader(this, queuedChunks);
  45997. },
  45998. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  45999. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  46000. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  46001. this._rangeReaders.push(reader);
  46002. return reader;
  46003. },
  46004. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  46005. if (this._fullRequestReader) {
  46006. this._fullRequestReader.cancel(reason);
  46007. }
  46008. var readers = this._rangeReaders.slice(0);
  46009. readers.forEach(function (rangeReader) {
  46010. rangeReader.cancel(reason);
  46011. });
  46012. }
  46013. };
  46014. /** @implements {IPDFStreamReader} */
  46015. function PDFWorkerStreamReader(stream, queuedChunks) {
  46016. this._stream = stream;
  46017. this._done = false;
  46018. this._queuedChunks = queuedChunks || [];
  46019. this._requests = [];
  46020. this._headersReady = Promise.resolve();
  46021. stream._fullRequestReader = this;
  46022. this.onProgress = null; // not used
  46023. }
  46024. PDFWorkerStreamReader.prototype = {
  46025. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  46026. if (this._done) {
  46027. return; // ignore new data
  46028. }
  46029. if (this._requests.length > 0) {
  46030. var requestCapability = this._requests.shift();
  46031. requestCapability.resolve({value: chunk, done: false});
  46032. return;
  46033. }
  46034. this._queuedChunks.push(chunk);
  46035. },
  46036. get headersReady() {
  46037. return this._headersReady;
  46038. },
  46039. get isRangeSupported() {
  46040. return this._stream._isRangeSupported;
  46041. },
  46042. get isStreamingSupported() {
  46043. return this._stream._isStreamingSupported;
  46044. },
  46045. get contentLength() {
  46046. return this._stream._contentLength;
  46047. },
  46048. read: function PDFWorkerStreamReader_read() {
  46049. if (this._queuedChunks.length > 0) {
  46050. var chunk = this._queuedChunks.shift();
  46051. return Promise.resolve({value: chunk, done: false});
  46052. }
  46053. if (this._done) {
  46054. return Promise.resolve({value: undefined, done: true});
  46055. }
  46056. var requestCapability = createPromiseCapability();
  46057. this._requests.push(requestCapability);
  46058. return requestCapability.promise;
  46059. },
  46060. cancel: function PDFWorkerStreamReader_cancel(reason) {
  46061. this._done = true;
  46062. this._requests.forEach(function (requestCapability) {
  46063. requestCapability.resolve({value: undefined, done: true});
  46064. });
  46065. this._requests = [];
  46066. }
  46067. };
  46068. /** @implements {IPDFStreamRangeReader} */
  46069. function PDFWorkerStreamRangeReader(stream, begin, end) {
  46070. this._stream = stream;
  46071. this._begin = begin;
  46072. this._end = end;
  46073. this._queuedChunk = null;
  46074. this._requests = [];
  46075. this._done = false;
  46076. this.onProgress = null;
  46077. }
  46078. PDFWorkerStreamRangeReader.prototype = {
  46079. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  46080. if (this._done) {
  46081. return; // ignore new data
  46082. }
  46083. if (this._requests.length === 0) {
  46084. this._queuedChunk = chunk;
  46085. } else {
  46086. var requestsCapability = this._requests.shift();
  46087. requestsCapability.resolve({value: chunk, done: false});
  46088. this._requests.forEach(function (requestCapability) {
  46089. requestCapability.resolve({value: undefined, done: true});
  46090. });
  46091. this._requests = [];
  46092. }
  46093. this._done = true;
  46094. this._stream._removeRangeReader(this);
  46095. },
  46096. get isStreamingSupported() {
  46097. return false;
  46098. },
  46099. read: function PDFWorkerStreamRangeReader_read() {
  46100. if (this._queuedChunk) {
  46101. return Promise.resolve({value: this._queuedChunk, done: false});
  46102. }
  46103. if (this._done) {
  46104. return Promise.resolve({value: undefined, done: true});
  46105. }
  46106. var requestCapability = createPromiseCapability();
  46107. this._requests.push(requestCapability);
  46108. return requestCapability.promise;
  46109. },
  46110. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  46111. this._done = true;
  46112. this._requests.forEach(function (requestCapability) {
  46113. requestCapability.resolve({value: undefined, done: true});
  46114. });
  46115. this._requests = [];
  46116. this._stream._removeRangeReader(this);
  46117. }
  46118. };
  46119. return PDFWorkerStream;
  46120. })();
  46121. /** @type IPDFStream */
  46122. var PDFNetworkStream;
  46123. /**
  46124. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  46125. * @param {IPDFStream} cls - the PDF data transport.
  46126. */
  46127. function setPDFNetworkStreamClass(cls) {
  46128. PDFNetworkStream = cls;
  46129. }
  46130. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  46131. setup: function wphSetup(handler, port) {
  46132. var testMessageProcessed = false;
  46133. handler.on('test', function wphSetupTest(data) {
  46134. if (testMessageProcessed) {
  46135. return; // we already processed 'test' message once
  46136. }
  46137. testMessageProcessed = true;
  46138. // check if Uint8Array can be sent to worker
  46139. if (!(data instanceof Uint8Array)) {
  46140. handler.send('test', 'main', false);
  46141. return;
  46142. }
  46143. // making sure postMessage transfers are working
  46144. var supportTransfers = data[0] === 255;
  46145. handler.postMessageTransfers = supportTransfers;
  46146. // check if the response property is supported by xhr
  46147. var xhr = new XMLHttpRequest();
  46148. var responseExists = 'response' in xhr;
  46149. // check if the property is actually implemented
  46150. try {
  46151. var dummy = xhr.responseType;
  46152. } catch (e) {
  46153. responseExists = false;
  46154. }
  46155. if (!responseExists) {
  46156. handler.send('test', false);
  46157. return;
  46158. }
  46159. handler.send('test', {
  46160. supportTypedArray: true,
  46161. supportTransfers: supportTransfers
  46162. });
  46163. });
  46164. handler.on('GetDocRequest', function wphSetupDoc(data) {
  46165. return WorkerMessageHandler.createDocumentHandler(data, port);
  46166. });
  46167. },
  46168. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  46169. // This context is actually holds references on pdfManager and handler,
  46170. // until the latter is destroyed.
  46171. var pdfManager;
  46172. var terminated = false;
  46173. var cancelXHRs = null;
  46174. var WorkerTasks = [];
  46175. var docId = docParams.docId;
  46176. var workerHandlerName = docParams.docId + '_worker';
  46177. var handler = new MessageHandler(workerHandlerName, docId, port);
  46178. function ensureNotTerminated() {
  46179. if (terminated) {
  46180. throw new Error('Worker was terminated');
  46181. }
  46182. }
  46183. function startWorkerTask(task) {
  46184. WorkerTasks.push(task);
  46185. }
  46186. function finishWorkerTask(task) {
  46187. task.finish();
  46188. var i = WorkerTasks.indexOf(task);
  46189. WorkerTasks.splice(i, 1);
  46190. }
  46191. function loadDocument(recoveryMode) {
  46192. var loadDocumentCapability = createPromiseCapability();
  46193. var parseSuccess = function parseSuccess() {
  46194. var numPagesPromise = pdfManager.ensureDoc('numPages');
  46195. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  46196. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  46197. Promise.all([numPagesPromise, fingerprintPromise,
  46198. encryptedPromise]).then(function onDocReady(results) {
  46199. var doc = {
  46200. numPages: results[0],
  46201. fingerprint: results[1],
  46202. encrypted: !!results[2],
  46203. };
  46204. loadDocumentCapability.resolve(doc);
  46205. },
  46206. parseFailure);
  46207. };
  46208. var parseFailure = function parseFailure(e) {
  46209. loadDocumentCapability.reject(e);
  46210. };
  46211. pdfManager.ensureDoc('checkHeader', []).then(function() {
  46212. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  46213. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  46214. parseSuccess, parseFailure);
  46215. }, parseFailure);
  46216. }, parseFailure);
  46217. return loadDocumentCapability.promise;
  46218. }
  46219. function getPdfManager(data) {
  46220. var pdfManagerCapability = createPromiseCapability();
  46221. var pdfManager;
  46222. var source = data.source;
  46223. if (source.data) {
  46224. try {
  46225. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  46226. pdfManagerCapability.resolve(pdfManager);
  46227. } catch (ex) {
  46228. pdfManagerCapability.reject(ex);
  46229. }
  46230. }
  46231. var pdfStream;
  46232. try {
  46233. if (source.chunkedViewerLoading) {
  46234. pdfStream = new PDFWorkerStream(source, handler);
  46235. } else {
  46236. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  46237. pdfStream = new PDFNetworkStream(data);
  46238. }
  46239. } catch (ex) {
  46240. pdfManagerCapability.reject(ex);
  46241. return pdfManagerCapability.promise;
  46242. }
  46243. var fullRequest = pdfStream.getFullReader();
  46244. fullRequest.headersReady.then(function () {
  46245. if (!fullRequest.isStreamingSupported ||
  46246. !fullRequest.isRangeSupported) {
  46247. // If stream or range are disabled, it's our only way to report
  46248. // loading progress.
  46249. fullRequest.onProgress = function (evt) {
  46250. handler.send('DocProgress', {
  46251. loaded: evt.loaded,
  46252. total: evt.total
  46253. });
  46254. };
  46255. }
  46256. if (!fullRequest.isRangeSupported) {
  46257. return;
  46258. }
  46259. // We don't need auto-fetch when streaming is enabled.
  46260. var disableAutoFetch = source.disableAutoFetch ||
  46261. fullRequest.isStreamingSupported;
  46262. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  46263. msgHandler: handler,
  46264. url: source.url,
  46265. password: source.password,
  46266. length: fullRequest.contentLength,
  46267. disableAutoFetch: disableAutoFetch,
  46268. rangeChunkSize: source.rangeChunkSize
  46269. });
  46270. pdfManagerCapability.resolve(pdfManager);
  46271. cancelXHRs = null;
  46272. }).catch(function (reason) {
  46273. pdfManagerCapability.reject(reason);
  46274. cancelXHRs = null;
  46275. });
  46276. var cachedChunks = [], loaded = 0;
  46277. var flushChunks = function () {
  46278. var pdfFile = arraysToBytes(cachedChunks);
  46279. if (source.length && pdfFile.length !== source.length) {
  46280. warn('reported HTTP length is different from actual');
  46281. }
  46282. // the data is array, instantiating directly from it
  46283. try {
  46284. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  46285. pdfManagerCapability.resolve(pdfManager);
  46286. } catch (ex) {
  46287. pdfManagerCapability.reject(ex);
  46288. }
  46289. cachedChunks = [];
  46290. };
  46291. var readPromise = new Promise(function (resolve, reject) {
  46292. var readChunk = function (chunk) {
  46293. try {
  46294. ensureNotTerminated();
  46295. if (chunk.done) {
  46296. if (!pdfManager) {
  46297. flushChunks();
  46298. }
  46299. cancelXHRs = null;
  46300. return;
  46301. }
  46302. var data = chunk.value;
  46303. loaded += arrayByteLength(data);
  46304. if (!fullRequest.isStreamingSupported) {
  46305. handler.send('DocProgress', {
  46306. loaded: loaded,
  46307. total: Math.max(loaded, fullRequest.contentLength || 0)
  46308. });
  46309. }
  46310. if (pdfManager) {
  46311. pdfManager.sendProgressiveData(data);
  46312. } else {
  46313. cachedChunks.push(data);
  46314. }
  46315. fullRequest.read().then(readChunk, reject);
  46316. } catch (e) {
  46317. reject(e);
  46318. }
  46319. };
  46320. fullRequest.read().then(readChunk, reject);
  46321. });
  46322. readPromise.catch(function (e) {
  46323. pdfManagerCapability.reject(e);
  46324. cancelXHRs = null;
  46325. });
  46326. cancelXHRs = function () {
  46327. pdfStream.cancelAllRequests('abort');
  46328. };
  46329. return pdfManagerCapability.promise;
  46330. }
  46331. var setupDoc = function(data) {
  46332. var onSuccess = function(doc) {
  46333. ensureNotTerminated();
  46334. handler.send('GetDoc', { pdfInfo: doc });
  46335. };
  46336. var onFailure = function(e) {
  46337. if (e instanceof PasswordException) {
  46338. if (e.code === PasswordResponses.NEED_PASSWORD) {
  46339. handler.send('NeedPassword', e);
  46340. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  46341. handler.send('IncorrectPassword', e);
  46342. }
  46343. } else if (e instanceof InvalidPDFException) {
  46344. handler.send('InvalidPDF', e);
  46345. } else if (e instanceof MissingPDFException) {
  46346. handler.send('MissingPDF', e);
  46347. } else if (e instanceof UnexpectedResponseException) {
  46348. handler.send('UnexpectedResponse', e);
  46349. } else {
  46350. handler.send('UnknownError',
  46351. new UnknownErrorException(e.message, e.toString()));
  46352. }
  46353. };
  46354. ensureNotTerminated();
  46355. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  46356. -1 : data.maxImageSize;
  46357. PDFJS.disableFontFace = data.disableFontFace;
  46358. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  46359. PDFJS.verbosity = data.verbosity;
  46360. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  46361. null : data.cMapUrl;
  46362. PDFJS.cMapPacked = data.cMapPacked === true;
  46363. getPdfManager(data).then(function (newPdfManager) {
  46364. if (terminated) {
  46365. // We were in a process of setting up the manager, but it got
  46366. // terminated in the middle.
  46367. newPdfManager.terminate();
  46368. throw new Error('Worker was terminated');
  46369. }
  46370. pdfManager = newPdfManager;
  46371. handler.send('PDFManagerReady', null);
  46372. pdfManager.onLoadedStream().then(function(stream) {
  46373. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  46374. });
  46375. }).then(function pdfManagerReady() {
  46376. ensureNotTerminated();
  46377. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  46378. ensureNotTerminated();
  46379. // Try again with recoveryMode == true
  46380. if (!(ex instanceof XRefParseException)) {
  46381. if (ex instanceof PasswordException) {
  46382. // after password exception prepare to receive a new password
  46383. // to repeat loading
  46384. pdfManager.passwordChanged().then(pdfManagerReady);
  46385. }
  46386. onFailure(ex);
  46387. return;
  46388. }
  46389. pdfManager.requestLoadedStream();
  46390. pdfManager.onLoadedStream().then(function() {
  46391. ensureNotTerminated();
  46392. loadDocument(true).then(onSuccess, onFailure);
  46393. });
  46394. }, onFailure);
  46395. }, onFailure);
  46396. };
  46397. handler.on('GetPage', function wphSetupGetPage(data) {
  46398. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46399. var rotatePromise = pdfManager.ensure(page, 'rotate');
  46400. var refPromise = pdfManager.ensure(page, 'ref');
  46401. var viewPromise = pdfManager.ensure(page, 'view');
  46402. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  46403. function(results) {
  46404. return {
  46405. rotate: results[0],
  46406. ref: results[1],
  46407. view: results[2]
  46408. };
  46409. });
  46410. });
  46411. });
  46412. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  46413. var ref = new Ref(data.ref.num, data.ref.gen);
  46414. var catalog = pdfManager.pdfDocument.catalog;
  46415. return catalog.getPageIndex(ref);
  46416. });
  46417. handler.on('GetDestinations',
  46418. function wphSetupGetDestinations(data) {
  46419. return pdfManager.ensureCatalog('destinations');
  46420. }
  46421. );
  46422. handler.on('GetDestination',
  46423. function wphSetupGetDestination(data) {
  46424. return pdfManager.ensureCatalog('getDestination', [data.id]);
  46425. }
  46426. );
  46427. handler.on('GetPageLabels',
  46428. function wphSetupGetPageLabels(data) {
  46429. return pdfManager.ensureCatalog('pageLabels');
  46430. }
  46431. );
  46432. handler.on('GetAttachments',
  46433. function wphSetupGetAttachments(data) {
  46434. return pdfManager.ensureCatalog('attachments');
  46435. }
  46436. );
  46437. handler.on('GetJavaScript',
  46438. function wphSetupGetJavaScript(data) {
  46439. return pdfManager.ensureCatalog('javaScript');
  46440. }
  46441. );
  46442. handler.on('GetOutline',
  46443. function wphSetupGetOutline(data) {
  46444. return pdfManager.ensureCatalog('documentOutline');
  46445. }
  46446. );
  46447. handler.on('GetMetadata',
  46448. function wphSetupGetMetadata(data) {
  46449. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  46450. pdfManager.ensureCatalog('metadata')]);
  46451. }
  46452. );
  46453. handler.on('GetData', function wphSetupGetData(data) {
  46454. pdfManager.requestLoadedStream();
  46455. return pdfManager.onLoadedStream().then(function(stream) {
  46456. return stream.bytes;
  46457. });
  46458. });
  46459. handler.on('GetStats',
  46460. function wphSetupGetStats(data) {
  46461. return pdfManager.pdfDocument.xref.stats;
  46462. }
  46463. );
  46464. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  46465. pdfManager.updatePassword(data);
  46466. });
  46467. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  46468. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46469. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  46470. });
  46471. });
  46472. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  46473. var pageIndex = data.pageIndex;
  46474. pdfManager.getPage(pageIndex).then(function(page) {
  46475. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  46476. startWorkerTask(task);
  46477. var pageNum = pageIndex + 1;
  46478. var start = Date.now();
  46479. // Pre compile the pdf page and fetch the fonts/images.
  46480. page.getOperatorList(handler, task, data.intent).then(
  46481. function(operatorList) {
  46482. finishWorkerTask(task);
  46483. info('page=' + pageNum + ' - getOperatorList: time=' +
  46484. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  46485. }, function(e) {
  46486. finishWorkerTask(task);
  46487. if (task.terminated) {
  46488. return; // ignoring errors from the terminated thread
  46489. }
  46490. // For compatibility with older behavior, generating unknown
  46491. // unsupported feature notification on errors.
  46492. handler.send('UnsupportedFeature',
  46493. {featureId: UNSUPPORTED_FEATURES.unknown});
  46494. var minimumStackMessage =
  46495. 'worker.js: while trying to getPage() and getOperatorList()';
  46496. var wrappedException;
  46497. // Turn the error into an obj that can be serialized
  46498. if (typeof e === 'string') {
  46499. wrappedException = {
  46500. message: e,
  46501. stack: minimumStackMessage
  46502. };
  46503. } else if (typeof e === 'object') {
  46504. wrappedException = {
  46505. message: e.message || e.toString(),
  46506. stack: e.stack || minimumStackMessage
  46507. };
  46508. } else {
  46509. wrappedException = {
  46510. message: 'Unknown exception type: ' + (typeof e),
  46511. stack: minimumStackMessage
  46512. };
  46513. }
  46514. handler.send('PageError', {
  46515. pageNum: pageNum,
  46516. error: wrappedException,
  46517. intent: data.intent
  46518. });
  46519. });
  46520. });
  46521. }, this);
  46522. handler.on('GetTextContent', function wphExtractText(data) {
  46523. var pageIndex = data.pageIndex;
  46524. var normalizeWhitespace = data.normalizeWhitespace;
  46525. return pdfManager.getPage(pageIndex).then(function(page) {
  46526. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  46527. startWorkerTask(task);
  46528. var pageNum = pageIndex + 1;
  46529. var start = Date.now();
  46530. return page.extractTextContent(task, normalizeWhitespace).then(
  46531. function(textContent) {
  46532. finishWorkerTask(task);
  46533. info('text indexing: page=' + pageNum + ' - time=' +
  46534. (Date.now() - start) + 'ms');
  46535. return textContent;
  46536. }, function (reason) {
  46537. finishWorkerTask(task);
  46538. if (task.terminated) {
  46539. return; // ignoring errors from the terminated thread
  46540. }
  46541. throw reason;
  46542. });
  46543. });
  46544. });
  46545. handler.on('Cleanup', function wphCleanup(data) {
  46546. return pdfManager.cleanup();
  46547. });
  46548. handler.on('Terminate', function wphTerminate(data) {
  46549. terminated = true;
  46550. if (pdfManager) {
  46551. pdfManager.terminate();
  46552. pdfManager = null;
  46553. }
  46554. if (cancelXHRs) {
  46555. cancelXHRs();
  46556. }
  46557. var waitOn = [];
  46558. WorkerTasks.forEach(function (task) {
  46559. waitOn.push(task.finished);
  46560. task.terminate();
  46561. });
  46562. return Promise.all(waitOn).then(function () {
  46563. // Notice that even if we destroying handler, resolved response promise
  46564. // must be sent back.
  46565. handler.destroy();
  46566. handler = null;
  46567. });
  46568. });
  46569. handler.on('Ready', function wphReady(data) {
  46570. setupDoc(docParams);
  46571. docParams = null; // we don't need docParams anymore -- saving memory.
  46572. });
  46573. return workerHandlerName;
  46574. }
  46575. };
  46576. function initializeWorker() {
  46577. if (!('console' in globalScope)) {
  46578. var consoleTimer = {};
  46579. var workerConsole = {
  46580. log: function log() {
  46581. var args = Array.prototype.slice.call(arguments);
  46582. globalScope.postMessage({
  46583. targetName: 'main',
  46584. action: 'console_log',
  46585. data: args
  46586. });
  46587. },
  46588. error: function error() {
  46589. var args = Array.prototype.slice.call(arguments);
  46590. globalScope.postMessage({
  46591. targetName: 'main',
  46592. action: 'console_error',
  46593. data: args
  46594. });
  46595. throw 'pdf.js execution error';
  46596. },
  46597. time: function time(name) {
  46598. consoleTimer[name] = Date.now();
  46599. },
  46600. timeEnd: function timeEnd(name) {
  46601. var time = consoleTimer[name];
  46602. if (!time) {
  46603. error('Unknown timer name ' + name);
  46604. }
  46605. this.log('Timer:', name, Date.now() - time);
  46606. }
  46607. };
  46608. globalScope.console = workerConsole;
  46609. }
  46610. var handler = new MessageHandler('worker', 'main', self);
  46611. WorkerMessageHandler.setup(handler, self);
  46612. handler.send('ready', null);
  46613. }
  46614. // Worker thread (and not node.js)?
  46615. if (typeof window === 'undefined' &&
  46616. !(typeof module !== 'undefined' && module.require)) {
  46617. initializeWorker();
  46618. }
  46619. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  46620. exports.WorkerTask = WorkerTask;
  46621. exports.WorkerMessageHandler = WorkerMessageHandler;
  46622. }));
  46623. var NetworkManager = (function NetworkManagerClosure() {
  46624. var OK_RESPONSE = 200;
  46625. var PARTIAL_CONTENT_RESPONSE = 206;
  46626. function NetworkManager(url, args) {
  46627. this.url = url;
  46628. args = args || {};
  46629. this.isHttp = /^https?:/i.test(url);
  46630. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  46631. this.withCredentials = args.withCredentials || false;
  46632. this.getXhr = args.getXhr ||
  46633. function NetworkManager_getXhr() {
  46634. return new XMLHttpRequest();
  46635. };
  46636. this.currXhrId = 0;
  46637. this.pendingRequests = Object.create(null);
  46638. this.loadedRequests = Object.create(null);
  46639. }
  46640. function getArrayBuffer(xhr) {
  46641. var data = xhr.response;
  46642. if (typeof data !== 'string') {
  46643. return data;
  46644. }
  46645. var length = data.length;
  46646. var array = new Uint8Array(length);
  46647. for (var i = 0; i < length; i++) {
  46648. array[i] = data.charCodeAt(i) & 0xFF;
  46649. }
  46650. return array.buffer;
  46651. }
  46652. var supportsMozChunked = (function supportsMozChunkedClosure() {
  46653. try {
  46654. var x = new XMLHttpRequest();
  46655. // Firefox 37- required .open() to be called before setting responseType.
  46656. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  46657. // Even though the URL is not visited, .open() could fail if the URL is
  46658. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  46659. // When this error occurs, this feature detection method will mistakenly
  46660. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  46661. x.open('GET', 'https://example.com');
  46662. x.responseType = 'moz-chunked-arraybuffer';
  46663. return x.responseType === 'moz-chunked-arraybuffer';
  46664. } catch (e) {
  46665. return false;
  46666. }
  46667. })();
  46668. NetworkManager.prototype = {
  46669. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  46670. var args = {
  46671. begin: begin,
  46672. end: end
  46673. };
  46674. for (var prop in listeners) {
  46675. args[prop] = listeners[prop];
  46676. }
  46677. return this.request(args);
  46678. },
  46679. requestFull: function NetworkManager_requestFull(listeners) {
  46680. return this.request(listeners);
  46681. },
  46682. request: function NetworkManager_request(args) {
  46683. var xhr = this.getXhr();
  46684. var xhrId = this.currXhrId++;
  46685. var pendingRequest = this.pendingRequests[xhrId] = {
  46686. xhr: xhr
  46687. };
  46688. xhr.open('GET', this.url);
  46689. xhr.withCredentials = this.withCredentials;
  46690. for (var property in this.httpHeaders) {
  46691. var value = this.httpHeaders[property];
  46692. if (typeof value === 'undefined') {
  46693. continue;
  46694. }
  46695. xhr.setRequestHeader(property, value);
  46696. }
  46697. if (this.isHttp && 'begin' in args && 'end' in args) {
  46698. var rangeStr = args.begin + '-' + (args.end - 1);
  46699. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  46700. pendingRequest.expectedStatus = 206;
  46701. } else {
  46702. pendingRequest.expectedStatus = 200;
  46703. }
  46704. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  46705. if (useMozChunkedLoading) {
  46706. xhr.responseType = 'moz-chunked-arraybuffer';
  46707. pendingRequest.onProgressiveData = args.onProgressiveData;
  46708. pendingRequest.mozChunked = true;
  46709. } else {
  46710. xhr.responseType = 'arraybuffer';
  46711. }
  46712. if (args.onError) {
  46713. xhr.onerror = function(evt) {
  46714. args.onError(xhr.status);
  46715. };
  46716. }
  46717. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  46718. xhr.onprogress = this.onProgress.bind(this, xhrId);
  46719. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  46720. pendingRequest.onDone = args.onDone;
  46721. pendingRequest.onError = args.onError;
  46722. pendingRequest.onProgress = args.onProgress;
  46723. xhr.send(null);
  46724. return xhrId;
  46725. },
  46726. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  46727. var pendingRequest = this.pendingRequests[xhrId];
  46728. if (!pendingRequest) {
  46729. // Maybe abortRequest was called...
  46730. return;
  46731. }
  46732. if (pendingRequest.mozChunked) {
  46733. var chunk = getArrayBuffer(pendingRequest.xhr);
  46734. pendingRequest.onProgressiveData(chunk);
  46735. }
  46736. var onProgress = pendingRequest.onProgress;
  46737. if (onProgress) {
  46738. onProgress(evt);
  46739. }
  46740. },
  46741. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  46742. var pendingRequest = this.pendingRequests[xhrId];
  46743. if (!pendingRequest) {
  46744. // Maybe abortRequest was called...
  46745. return;
  46746. }
  46747. var xhr = pendingRequest.xhr;
  46748. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  46749. pendingRequest.onHeadersReceived();
  46750. delete pendingRequest.onHeadersReceived;
  46751. }
  46752. if (xhr.readyState !== 4) {
  46753. return;
  46754. }
  46755. if (!(xhrId in this.pendingRequests)) {
  46756. // The XHR request might have been aborted in onHeadersReceived()
  46757. // callback, in which case we should abort request
  46758. return;
  46759. }
  46760. delete this.pendingRequests[xhrId];
  46761. // success status == 0 can be on ftp, file and other protocols
  46762. if (xhr.status === 0 && this.isHttp) {
  46763. if (pendingRequest.onError) {
  46764. pendingRequest.onError(xhr.status);
  46765. }
  46766. return;
  46767. }
  46768. var xhrStatus = xhr.status || OK_RESPONSE;
  46769. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  46770. // "A server MAY ignore the Range header". This means it's possible to
  46771. // get a 200 rather than a 206 response from a range request.
  46772. var ok_response_on_range_request =
  46773. xhrStatus === OK_RESPONSE &&
  46774. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  46775. if (!ok_response_on_range_request &&
  46776. xhrStatus !== pendingRequest.expectedStatus) {
  46777. if (pendingRequest.onError) {
  46778. pendingRequest.onError(xhr.status);
  46779. }
  46780. return;
  46781. }
  46782. this.loadedRequests[xhrId] = true;
  46783. var chunk = getArrayBuffer(xhr);
  46784. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  46785. var rangeHeader = xhr.getResponseHeader('Content-Range');
  46786. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  46787. var begin = parseInt(matches[1], 10);
  46788. pendingRequest.onDone({
  46789. begin: begin,
  46790. chunk: chunk
  46791. });
  46792. } else if (pendingRequest.onProgressiveData) {
  46793. pendingRequest.onDone(null);
  46794. } else if (chunk) {
  46795. pendingRequest.onDone({
  46796. begin: 0,
  46797. chunk: chunk
  46798. });
  46799. } else if (pendingRequest.onError) {
  46800. pendingRequest.onError(xhr.status);
  46801. }
  46802. },
  46803. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  46804. for (var xhrId in this.pendingRequests) {
  46805. return true;
  46806. }
  46807. return false;
  46808. },
  46809. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  46810. return this.pendingRequests[xhrId].xhr;
  46811. },
  46812. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  46813. return !!(this.pendingRequests[xhrId].onProgressiveData);
  46814. },
  46815. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  46816. return xhrId in this.pendingRequests;
  46817. },
  46818. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  46819. return xhrId in this.loadedRequests;
  46820. },
  46821. abortAllRequests: function NetworkManager_abortAllRequests() {
  46822. for (var xhrId in this.pendingRequests) {
  46823. this.abortRequest(xhrId | 0);
  46824. }
  46825. },
  46826. abortRequest: function NetworkManager_abortRequest(xhrId) {
  46827. var xhr = this.pendingRequests[xhrId].xhr;
  46828. delete this.pendingRequests[xhrId];
  46829. xhr.abort();
  46830. }
  46831. };
  46832. return NetworkManager;
  46833. })();
  46834. (function (root, factory) {
  46835. {
  46836. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  46837. root.pdfjsCoreWorker);
  46838. }
  46839. }(this, function (exports, sharedUtil, coreWorker) {
  46840. var assert = sharedUtil.assert;
  46841. var createPromiseCapability = sharedUtil.createPromiseCapability;
  46842. var isInt = sharedUtil.isInt;
  46843. var MissingPDFException = sharedUtil.MissingPDFException;
  46844. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  46845. /** @implements {IPDFStream} */
  46846. function PDFNetworkStream(options) {
  46847. this._options = options;
  46848. var source = options.source;
  46849. this._manager = new NetworkManager(source.url, {
  46850. httpHeaders: source.httpHeaders,
  46851. withCredentials: source.withCredentials
  46852. });
  46853. this._rangeChunkSize = source.rangeChunkSize;
  46854. this._fullRequestReader = null;
  46855. this._rangeRequestReaders = [];
  46856. }
  46857. PDFNetworkStream.prototype = {
  46858. _onRangeRequestReaderClosed:
  46859. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  46860. var i = this._rangeRequestReaders.indexOf(reader);
  46861. if (i >= 0) {
  46862. this._rangeRequestReaders.splice(i, 1);
  46863. }
  46864. },
  46865. getFullReader: function PDFNetworkStream_getFullReader() {
  46866. assert(!this._fullRequestReader);
  46867. this._fullRequestReader =
  46868. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  46869. return this._fullRequestReader;
  46870. },
  46871. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  46872. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  46873. begin, end);
  46874. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  46875. this._rangeRequestReaders.push(reader);
  46876. return reader;
  46877. },
  46878. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  46879. if (this._fullRequestReader) {
  46880. this._fullRequestReader.cancel(reason);
  46881. }
  46882. var readers = this._rangeRequestReaders.slice(0);
  46883. readers.forEach(function (reader) {
  46884. reader.cancel(reason);
  46885. });
  46886. }
  46887. };
  46888. /** @implements {IPDFStreamReader} */
  46889. function PDFNetworkStreamFullRequestReader(manager, options) {
  46890. this._manager = manager;
  46891. var source = options.source;
  46892. var args = {
  46893. onHeadersReceived: this._onHeadersReceived.bind(this),
  46894. onProgressiveData: source.disableStream ? null :
  46895. this._onProgressiveData.bind(this),
  46896. onDone: this._onDone.bind(this),
  46897. onError: this._onError.bind(this),
  46898. onProgress: this._onProgress.bind(this)
  46899. };
  46900. this._url = source.url;
  46901. this._fullRequestId = manager.requestFull(args);
  46902. this._headersReceivedCapability = createPromiseCapability();
  46903. this._disableRange = options.disableRange || false;
  46904. this._contentLength = source.length; // optional
  46905. this._rangeChunkSize = source.rangeChunkSize;
  46906. if (!this._rangeChunkSize && !this._disableRange) {
  46907. this._disableRange = true;
  46908. }
  46909. this._isStreamingSupported = false;
  46910. this._isRangeSupported = false;
  46911. this._cachedChunks = [];
  46912. this._requests = [];
  46913. this._done = false;
  46914. this._storedError = undefined;
  46915. this.onProgress = null;
  46916. }
  46917. PDFNetworkStreamFullRequestReader.prototype = {
  46918. _validateRangeRequestCapabilities: function
  46919. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  46920. if (this._disableRange) {
  46921. return false;
  46922. }
  46923. var networkManager = this._manager;
  46924. var fullRequestXhrId = this._fullRequestId;
  46925. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  46926. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  46927. return false;
  46928. }
  46929. var contentEncoding =
  46930. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  46931. if (contentEncoding !== 'identity') {
  46932. return false;
  46933. }
  46934. var length = fullRequestXhr.getResponseHeader('Content-Length');
  46935. length = parseInt(length, 10);
  46936. if (!isInt(length)) {
  46937. return false;
  46938. }
  46939. this._contentLength = length; // setting right content length
  46940. if (length <= 2 * this._rangeChunkSize) {
  46941. // The file size is smaller than the size of two chunks, so it does
  46942. // not make any sense to abort the request and retry with a range
  46943. // request.
  46944. return false;
  46945. }
  46946. return true;
  46947. },
  46948. _onHeadersReceived:
  46949. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  46950. if (this._validateRangeRequestCapabilities()) {
  46951. this._isRangeSupported = true;
  46952. }
  46953. var networkManager = this._manager;
  46954. var fullRequestXhrId = this._fullRequestId;
  46955. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  46956. // We can continue fetching when progressive loading is enabled,
  46957. // and we don't need the autoFetch feature.
  46958. this._isStreamingSupported = true;
  46959. } else if (this._isRangeSupported) {
  46960. // NOTE: by cancelling the full request, and then issuing range
  46961. // requests, there will be an issue for sites where you can only
  46962. // request the pdf once. However, if this is the case, then the
  46963. // server should not be returning that it can support range
  46964. // requests.
  46965. networkManager.abortRequest(fullRequestXhrId);
  46966. }
  46967. this._headersReceivedCapability.resolve();
  46968. },
  46969. _onProgressiveData:
  46970. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  46971. if (this._requests.length > 0) {
  46972. var requestCapability = this._requests.shift();
  46973. requestCapability.resolve({value: chunk, done: false});
  46974. } else {
  46975. this._cachedChunks.push(chunk);
  46976. }
  46977. },
  46978. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  46979. if (args) {
  46980. this._onProgressiveData(args.chunk);
  46981. }
  46982. this._done = true;
  46983. if (this._cachedChunks.length > 0) {
  46984. return;
  46985. }
  46986. this._requests.forEach(function (requestCapability) {
  46987. requestCapability.resolve({value: undefined, done: true});
  46988. });
  46989. this._requests = [];
  46990. },
  46991. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  46992. var url = this._url;
  46993. var exception;
  46994. if (status === 404 || status === 0 && /^file:/.test(url)) {
  46995. exception = new MissingPDFException('Missing PDF "' + url + '".');
  46996. } else {
  46997. exception = new UnexpectedResponseException(
  46998. 'Unexpected server response (' + status +
  46999. ') while retrieving PDF "' + url + '".', status);
  47000. }
  47001. this._storedError = exception;
  47002. this._headersReceivedCapability.reject(exception);
  47003. this._requests.forEach(function (requestCapability) {
  47004. requestCapability.reject(exception);
  47005. });
  47006. this._requests = [];
  47007. this._cachedChunks = [];
  47008. },
  47009. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  47010. if (this.onProgress) {
  47011. this.onProgress({
  47012. loaded: data.loaded,
  47013. total: data.lengthComputable ? data.total : this._contentLength
  47014. });
  47015. }
  47016. },
  47017. get isRangeSupported() {
  47018. return this._isRangeSupported;
  47019. },
  47020. get isStreamingSupported() {
  47021. return this._isStreamingSupported;
  47022. },
  47023. get contentLength() {
  47024. return this._contentLength;
  47025. },
  47026. get headersReady() {
  47027. return this._headersReceivedCapability.promise;
  47028. },
  47029. read: function PDFNetworkStreamFullRequestReader_read() {
  47030. if (this._storedError) {
  47031. return Promise.reject(this._storedError);
  47032. }
  47033. if (this._cachedChunks.length > 0) {
  47034. var chunk = this._cachedChunks.shift();
  47035. return Promise.resolve(chunk);
  47036. }
  47037. if (this._done) {
  47038. return Promise.resolve({value: undefined, done: true});
  47039. }
  47040. var requestCapability = createPromiseCapability();
  47041. this._requests.push(requestCapability);
  47042. return requestCapability.promise;
  47043. },
  47044. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  47045. this._done = true;
  47046. this._headersReceivedCapability.reject(reason);
  47047. this._requests.forEach(function (requestCapability) {
  47048. requestCapability.resolve({value: undefined, done: true});
  47049. });
  47050. this._requests = [];
  47051. if (this._manager.isPendingRequest(this._fullRequestId)) {
  47052. this._manager.abortRequest(this._fullRequestId);
  47053. }
  47054. this._fullRequestReader = null;
  47055. }
  47056. };
  47057. /** @implements {IPDFStreamRangeReader} */
  47058. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  47059. this._manager = manager;
  47060. var args = {
  47061. onDone: this._onDone.bind(this),
  47062. onProgress: this._onProgress.bind(this)
  47063. };
  47064. this._requestId = manager.requestRange(begin, end, args);
  47065. this._requests = [];
  47066. this._queuedChunk = null;
  47067. this._done = false;
  47068. this.onProgress = null;
  47069. this.onClosed = null;
  47070. }
  47071. PDFNetworkStreamRangeRequestReader.prototype = {
  47072. _close: function PDFNetworkStreamRangeRequestReader_close() {
  47073. if (this.onClosed) {
  47074. this.onClosed(this);
  47075. }
  47076. },
  47077. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  47078. var chunk = data.chunk;
  47079. if (this._requests.length > 0) {
  47080. var requestCapability = this._requests.shift();
  47081. requestCapability.resolve({value: chunk, done: false});
  47082. } else {
  47083. this._queuedChunk = chunk;
  47084. }
  47085. this._done = true;
  47086. this._requests.forEach(function (requestCapability) {
  47087. requestCapability.resolve({value: undefined, done: true});
  47088. });
  47089. this._requests = [];
  47090. this._close();
  47091. },
  47092. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  47093. if (!this.isStreamingSupported && this.onProgress) {
  47094. this.onProgress({
  47095. loaded: evt.loaded
  47096. });
  47097. }
  47098. },
  47099. get isStreamingSupported() {
  47100. return false; // TODO allow progressive range bytes loading
  47101. },
  47102. read: function PDFNetworkStreamRangeRequestReader_read() {
  47103. if (this._queuedChunk !== null) {
  47104. var chunk = this._queuedChunk;
  47105. this._queuedChunk = null;
  47106. return Promise.resolve({value: chunk, done: false});
  47107. }
  47108. if (this._done) {
  47109. return Promise.resolve({value: undefined, done: true});
  47110. }
  47111. var requestCapability = createPromiseCapability();
  47112. this._requests.push(requestCapability);
  47113. return requestCapability.promise;
  47114. },
  47115. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  47116. this._done = true;
  47117. this._requests.forEach(function (requestCapability) {
  47118. requestCapability.resolve({value: undefined, done: true});
  47119. });
  47120. this._requests = [];
  47121. if (this._manager.isPendingRequest(this._requestId)) {
  47122. this._manager.abortRequest(this._requestId);
  47123. }
  47124. this._close();
  47125. }
  47126. };
  47127. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  47128. exports.PDFNetworkStream = PDFNetworkStream;
  47129. exports.NetworkManager = NetworkManager;
  47130. }));
  47131. }).call(pdfjsLibs);
  47132. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  47133. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  47134. exports.PDFDataRangeTransport =
  47135. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  47136. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  47137. exports.AnnotationLayer =
  47138. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  47139. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  47140. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  47141. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  47142. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  47143. exports.UnexpectedResponseException =
  47144. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  47145. }));