2
0

pdf.combined.js 1.5 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688
  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. /* globals PDFJS, global */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window :
  20. typeof global !== 'undefined' ? global : this).PDFJS = {};
  21. }
  22. PDFJS.version = '1.3.133';
  23. PDFJS.build = '8558948';
  24. (function pdfjsWrapper() {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. (function (root, factory) {
  28. {
  29. factory((root.pdfjsSharedGlobal = {}));
  30. }
  31. }(this, function (exports) {
  32. var globalScope = (typeof window !== 'undefined') ? window :
  33. (typeof global !== 'undefined') ? global :
  34. (typeof self !== 'undefined') ? self : this;
  35. var isWorker = (typeof window === 'undefined');
  36. // The global PDFJS object exposes the API
  37. // In production, it will be declared outside a global wrapper
  38. // In development, it will be declared here
  39. if (!globalScope.PDFJS) {
  40. globalScope.PDFJS = {};
  41. }
  42. globalScope.PDFJS.pdfBug = false;
  43. exports.globalScope = globalScope;
  44. exports.isWorker = isWorker;
  45. exports.PDFJS = globalScope.PDFJS;
  46. }));
  47. (function (root, factory) {
  48. {
  49. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  50. }
  51. }(this, function (exports, sharedGlobal) {
  52. var PDFJS = sharedGlobal.PDFJS;
  53. var globalScope = sharedGlobal.globalScope;
  54. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  55. var TextRenderingMode = {
  56. FILL: 0,
  57. STROKE: 1,
  58. FILL_STROKE: 2,
  59. INVISIBLE: 3,
  60. FILL_ADD_TO_PATH: 4,
  61. STROKE_ADD_TO_PATH: 5,
  62. FILL_STROKE_ADD_TO_PATH: 6,
  63. ADD_TO_PATH: 7,
  64. FILL_STROKE_MASK: 3,
  65. ADD_TO_PATH_FLAG: 4
  66. };
  67. var ImageKind = {
  68. GRAYSCALE_1BPP: 1,
  69. RGB_24BPP: 2,
  70. RGBA_32BPP: 3
  71. };
  72. var AnnotationType = {
  73. TEXT: 1,
  74. LINK: 2,
  75. FREETEXT: 3,
  76. LINE: 4,
  77. SQUARE: 5,
  78. CIRCLE: 6,
  79. POLYGON: 7,
  80. POLYLINE: 8,
  81. HIGHLIGHT: 9,
  82. UNDERLINE: 10,
  83. SQUIGGLY: 11,
  84. STRIKEOUT: 12,
  85. STAMP: 13,
  86. CARET: 14,
  87. INK: 15,
  88. POPUP: 16,
  89. FILEATTACHMENT: 17,
  90. SOUND: 18,
  91. MOVIE: 19,
  92. WIDGET: 20,
  93. SCREEN: 21,
  94. PRINTERMARK: 22,
  95. TRAPNET: 23,
  96. WATERMARK: 24,
  97. THREED: 25,
  98. REDACT: 26
  99. };
  100. var AnnotationFlag = {
  101. INVISIBLE: 0x01,
  102. HIDDEN: 0x02,
  103. PRINT: 0x04,
  104. NOZOOM: 0x08,
  105. NOROTATE: 0x10,
  106. NOVIEW: 0x20,
  107. READONLY: 0x40,
  108. LOCKED: 0x80,
  109. TOGGLENOVIEW: 0x100,
  110. LOCKEDCONTENTS: 0x200
  111. };
  112. var AnnotationBorderStyleType = {
  113. SOLID: 1,
  114. DASHED: 2,
  115. BEVELED: 3,
  116. INSET: 4,
  117. UNDERLINE: 5
  118. };
  119. var StreamType = {
  120. UNKNOWN: 0,
  121. FLATE: 1,
  122. LZW: 2,
  123. DCT: 3,
  124. JPX: 4,
  125. JBIG: 5,
  126. A85: 6,
  127. AHX: 7,
  128. CCF: 8,
  129. RL: 9
  130. };
  131. var FontType = {
  132. UNKNOWN: 0,
  133. TYPE1: 1,
  134. TYPE1C: 2,
  135. CIDFONTTYPE0: 3,
  136. CIDFONTTYPE0C: 4,
  137. TRUETYPE: 5,
  138. CIDFONTTYPE2: 6,
  139. TYPE3: 7,
  140. OPENTYPE: 8,
  141. TYPE0: 9,
  142. MMTYPE1: 10
  143. };
  144. PDFJS.VERBOSITY_LEVELS = {
  145. errors: 0,
  146. warnings: 1,
  147. infos: 5
  148. };
  149. // All the possible operations for an operator list.
  150. var OPS = PDFJS.OPS = {
  151. // Intentionally start from 1 so it is easy to spot bad operators that will be
  152. // 0's.
  153. dependency: 1,
  154. setLineWidth: 2,
  155. setLineCap: 3,
  156. setLineJoin: 4,
  157. setMiterLimit: 5,
  158. setDash: 6,
  159. setRenderingIntent: 7,
  160. setFlatness: 8,
  161. setGState: 9,
  162. save: 10,
  163. restore: 11,
  164. transform: 12,
  165. moveTo: 13,
  166. lineTo: 14,
  167. curveTo: 15,
  168. curveTo2: 16,
  169. curveTo3: 17,
  170. closePath: 18,
  171. rectangle: 19,
  172. stroke: 20,
  173. closeStroke: 21,
  174. fill: 22,
  175. eoFill: 23,
  176. fillStroke: 24,
  177. eoFillStroke: 25,
  178. closeFillStroke: 26,
  179. closeEOFillStroke: 27,
  180. endPath: 28,
  181. clip: 29,
  182. eoClip: 30,
  183. beginText: 31,
  184. endText: 32,
  185. setCharSpacing: 33,
  186. setWordSpacing: 34,
  187. setHScale: 35,
  188. setLeading: 36,
  189. setFont: 37,
  190. setTextRenderingMode: 38,
  191. setTextRise: 39,
  192. moveText: 40,
  193. setLeadingMoveText: 41,
  194. setTextMatrix: 42,
  195. nextLine: 43,
  196. showText: 44,
  197. showSpacedText: 45,
  198. nextLineShowText: 46,
  199. nextLineSetSpacingShowText: 47,
  200. setCharWidth: 48,
  201. setCharWidthAndBounds: 49,
  202. setStrokeColorSpace: 50,
  203. setFillColorSpace: 51,
  204. setStrokeColor: 52,
  205. setStrokeColorN: 53,
  206. setFillColor: 54,
  207. setFillColorN: 55,
  208. setStrokeGray: 56,
  209. setFillGray: 57,
  210. setStrokeRGBColor: 58,
  211. setFillRGBColor: 59,
  212. setStrokeCMYKColor: 60,
  213. setFillCMYKColor: 61,
  214. shadingFill: 62,
  215. beginInlineImage: 63,
  216. beginImageData: 64,
  217. endInlineImage: 65,
  218. paintXObject: 66,
  219. markPoint: 67,
  220. markPointProps: 68,
  221. beginMarkedContent: 69,
  222. beginMarkedContentProps: 70,
  223. endMarkedContent: 71,
  224. beginCompat: 72,
  225. endCompat: 73,
  226. paintFormXObjectBegin: 74,
  227. paintFormXObjectEnd: 75,
  228. beginGroup: 76,
  229. endGroup: 77,
  230. beginAnnotations: 78,
  231. endAnnotations: 79,
  232. beginAnnotation: 80,
  233. endAnnotation: 81,
  234. paintJpegXObject: 82,
  235. paintImageMaskXObject: 83,
  236. paintImageMaskXObjectGroup: 84,
  237. paintImageXObject: 85,
  238. paintInlineImageXObject: 86,
  239. paintInlineImageXObjectGroup: 87,
  240. paintImageXObjectRepeat: 88,
  241. paintImageMaskXObjectRepeat: 89,
  242. paintSolidColorImageMask: 90,
  243. constructPath: 91
  244. };
  245. // A notice for devs. These are good for things that are helpful to devs, such
  246. // as warning that Workers were disabled, which is important to devs but not
  247. // end users.
  248. function info(msg) {
  249. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  250. console.log('Info: ' + msg);
  251. }
  252. }
  253. // Non-fatal warnings.
  254. function warn(msg) {
  255. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  256. console.log('Warning: ' + msg);
  257. }
  258. }
  259. // Deprecated API function -- treated as warnings.
  260. function deprecated(details) {
  261. warn('Deprecated API usage: ' + details);
  262. }
  263. // Fatal errors that should trigger the fallback UI and halt execution by
  264. // throwing an exception.
  265. function error(msg) {
  266. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  267. console.log('Error: ' + msg);
  268. console.log(backtrace());
  269. }
  270. throw new Error(msg);
  271. }
  272. function backtrace() {
  273. try {
  274. throw new Error();
  275. } catch (e) {
  276. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  277. }
  278. }
  279. function assert(cond, msg) {
  280. if (!cond) {
  281. error(msg);
  282. }
  283. }
  284. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  285. unknown: 'unknown',
  286. forms: 'forms',
  287. javaScript: 'javaScript',
  288. smask: 'smask',
  289. shadingPattern: 'shadingPattern',
  290. font: 'font'
  291. };
  292. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  293. // absolute URL, it will be returned as is.
  294. function combineUrl(baseUrl, url) {
  295. if (!url) {
  296. return baseUrl;
  297. }
  298. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  299. return url;
  300. }
  301. var i;
  302. if (url.charAt(0) === '/') {
  303. // absolute path
  304. i = baseUrl.indexOf('://');
  305. if (url.charAt(1) === '/') {
  306. ++i;
  307. } else {
  308. i = baseUrl.indexOf('/', i + 3);
  309. }
  310. return baseUrl.substring(0, i) + url;
  311. } else {
  312. // relative path
  313. var pathLength = baseUrl.length;
  314. i = baseUrl.lastIndexOf('#');
  315. pathLength = i >= 0 ? i : pathLength;
  316. i = baseUrl.lastIndexOf('?', pathLength);
  317. pathLength = i >= 0 ? i : pathLength;
  318. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  319. return baseUrl.substring(0, prefixLength + 1) + url;
  320. }
  321. }
  322. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  323. function isValidUrl(url, allowRelative) {
  324. if (!url) {
  325. return false;
  326. }
  327. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  328. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  329. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  330. if (!protocol) {
  331. return allowRelative;
  332. }
  333. protocol = protocol[0].toLowerCase();
  334. switch (protocol) {
  335. case 'http':
  336. case 'https':
  337. case 'ftp':
  338. case 'mailto':
  339. case 'tel':
  340. return true;
  341. default:
  342. return false;
  343. }
  344. }
  345. PDFJS.isValidUrl = isValidUrl;
  346. function shadow(obj, prop, value) {
  347. Object.defineProperty(obj, prop, { value: value,
  348. enumerable: true,
  349. configurable: true,
  350. writable: false });
  351. return value;
  352. }
  353. PDFJS.shadow = shadow;
  354. var LinkTarget = PDFJS.LinkTarget = {
  355. NONE: 0, // Default value.
  356. SELF: 1,
  357. BLANK: 2,
  358. PARENT: 3,
  359. TOP: 4,
  360. };
  361. var LinkTargetStringMap = [
  362. '',
  363. '_self',
  364. '_blank',
  365. '_parent',
  366. '_top'
  367. ];
  368. function isExternalLinkTargetSet() {
  369. if (PDFJS.openExternalLinksInNewWindow) {
  370. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  371. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  372. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  373. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  374. }
  375. // Reset the deprecated parameter, to suppress further warnings.
  376. PDFJS.openExternalLinksInNewWindow = false;
  377. }
  378. switch (PDFJS.externalLinkTarget) {
  379. case LinkTarget.NONE:
  380. return false;
  381. case LinkTarget.SELF:
  382. case LinkTarget.BLANK:
  383. case LinkTarget.PARENT:
  384. case LinkTarget.TOP:
  385. return true;
  386. }
  387. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  388. // Reset the external link target, to suppress further warnings.
  389. PDFJS.externalLinkTarget = LinkTarget.NONE;
  390. return false;
  391. }
  392. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  393. var PasswordResponses = PDFJS.PasswordResponses = {
  394. NEED_PASSWORD: 1,
  395. INCORRECT_PASSWORD: 2
  396. };
  397. var PasswordException = (function PasswordExceptionClosure() {
  398. function PasswordException(msg, code) {
  399. this.name = 'PasswordException';
  400. this.message = msg;
  401. this.code = code;
  402. }
  403. PasswordException.prototype = new Error();
  404. PasswordException.constructor = PasswordException;
  405. return PasswordException;
  406. })();
  407. PDFJS.PasswordException = PasswordException;
  408. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  409. function UnknownErrorException(msg, details) {
  410. this.name = 'UnknownErrorException';
  411. this.message = msg;
  412. this.details = details;
  413. }
  414. UnknownErrorException.prototype = new Error();
  415. UnknownErrorException.constructor = UnknownErrorException;
  416. return UnknownErrorException;
  417. })();
  418. PDFJS.UnknownErrorException = UnknownErrorException;
  419. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  420. function InvalidPDFException(msg) {
  421. this.name = 'InvalidPDFException';
  422. this.message = msg;
  423. }
  424. InvalidPDFException.prototype = new Error();
  425. InvalidPDFException.constructor = InvalidPDFException;
  426. return InvalidPDFException;
  427. })();
  428. PDFJS.InvalidPDFException = InvalidPDFException;
  429. var MissingPDFException = (function MissingPDFExceptionClosure() {
  430. function MissingPDFException(msg) {
  431. this.name = 'MissingPDFException';
  432. this.message = msg;
  433. }
  434. MissingPDFException.prototype = new Error();
  435. MissingPDFException.constructor = MissingPDFException;
  436. return MissingPDFException;
  437. })();
  438. PDFJS.MissingPDFException = MissingPDFException;
  439. var UnexpectedResponseException =
  440. (function UnexpectedResponseExceptionClosure() {
  441. function UnexpectedResponseException(msg, status) {
  442. this.name = 'UnexpectedResponseException';
  443. this.message = msg;
  444. this.status = status;
  445. }
  446. UnexpectedResponseException.prototype = new Error();
  447. UnexpectedResponseException.constructor = UnexpectedResponseException;
  448. return UnexpectedResponseException;
  449. })();
  450. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  451. var NotImplementedException = (function NotImplementedExceptionClosure() {
  452. function NotImplementedException(msg) {
  453. this.message = msg;
  454. }
  455. NotImplementedException.prototype = new Error();
  456. NotImplementedException.prototype.name = 'NotImplementedException';
  457. NotImplementedException.constructor = NotImplementedException;
  458. return NotImplementedException;
  459. })();
  460. var MissingDataException = (function MissingDataExceptionClosure() {
  461. function MissingDataException(begin, end) {
  462. this.begin = begin;
  463. this.end = end;
  464. this.message = 'Missing data [' + begin + ', ' + end + ')';
  465. }
  466. MissingDataException.prototype = new Error();
  467. MissingDataException.prototype.name = 'MissingDataException';
  468. MissingDataException.constructor = MissingDataException;
  469. return MissingDataException;
  470. })();
  471. var XRefParseException = (function XRefParseExceptionClosure() {
  472. function XRefParseException(msg) {
  473. this.message = msg;
  474. }
  475. XRefParseException.prototype = new Error();
  476. XRefParseException.prototype.name = 'XRefParseException';
  477. XRefParseException.constructor = XRefParseException;
  478. return XRefParseException;
  479. })();
  480. function bytesToString(bytes) {
  481. assert(bytes !== null && typeof bytes === 'object' &&
  482. bytes.length !== undefined, 'Invalid argument for bytesToString');
  483. var length = bytes.length;
  484. var MAX_ARGUMENT_COUNT = 8192;
  485. if (length < MAX_ARGUMENT_COUNT) {
  486. return String.fromCharCode.apply(null, bytes);
  487. }
  488. var strBuf = [];
  489. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  490. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  491. var chunk = bytes.subarray(i, chunkEnd);
  492. strBuf.push(String.fromCharCode.apply(null, chunk));
  493. }
  494. return strBuf.join('');
  495. }
  496. function stringToBytes(str) {
  497. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  498. var length = str.length;
  499. var bytes = new Uint8Array(length);
  500. for (var i = 0; i < length; ++i) {
  501. bytes[i] = str.charCodeAt(i) & 0xFF;
  502. }
  503. return bytes;
  504. }
  505. function string32(value) {
  506. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  507. (value >> 8) & 0xff, value & 0xff);
  508. }
  509. function log2(x) {
  510. var n = 1, i = 0;
  511. while (x > n) {
  512. n <<= 1;
  513. i++;
  514. }
  515. return i;
  516. }
  517. function readInt8(data, start) {
  518. return (data[start] << 24) >> 24;
  519. }
  520. function readUint16(data, offset) {
  521. return (data[offset] << 8) | data[offset + 1];
  522. }
  523. function readUint32(data, offset) {
  524. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  525. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  526. }
  527. // Lazy test the endianness of the platform
  528. // NOTE: This will be 'true' for simulated TypedArrays
  529. function isLittleEndian() {
  530. var buffer8 = new Uint8Array(2);
  531. buffer8[0] = 1;
  532. var buffer16 = new Uint16Array(buffer8.buffer);
  533. return (buffer16[0] === 1);
  534. }
  535. Object.defineProperty(PDFJS, 'isLittleEndian', {
  536. configurable: true,
  537. get: function PDFJS_isLittleEndian() {
  538. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  539. }
  540. });
  541. // Lazy test if the userAgent support CanvasTypedArrays
  542. function hasCanvasTypedArrays() {
  543. var canvas = document.createElement('canvas');
  544. canvas.width = canvas.height = 1;
  545. var ctx = canvas.getContext('2d');
  546. var imageData = ctx.createImageData(1, 1);
  547. return (typeof imageData.data.buffer !== 'undefined');
  548. }
  549. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  550. configurable: true,
  551. get: function PDFJS_hasCanvasTypedArrays() {
  552. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  553. }
  554. });
  555. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  556. function Uint32ArrayView(buffer, length) {
  557. this.buffer = buffer;
  558. this.byteLength = buffer.length;
  559. this.length = length === undefined ? (this.byteLength >> 2) : length;
  560. ensureUint32ArrayViewProps(this.length);
  561. }
  562. Uint32ArrayView.prototype = Object.create(null);
  563. var uint32ArrayViewSetters = 0;
  564. function createUint32ArrayProp(index) {
  565. return {
  566. get: function () {
  567. var buffer = this.buffer, offset = index << 2;
  568. return (buffer[offset] | (buffer[offset + 1] << 8) |
  569. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  570. },
  571. set: function (value) {
  572. var buffer = this.buffer, offset = index << 2;
  573. buffer[offset] = value & 255;
  574. buffer[offset + 1] = (value >> 8) & 255;
  575. buffer[offset + 2] = (value >> 16) & 255;
  576. buffer[offset + 3] = (value >>> 24) & 255;
  577. }
  578. };
  579. }
  580. function ensureUint32ArrayViewProps(length) {
  581. while (uint32ArrayViewSetters < length) {
  582. Object.defineProperty(Uint32ArrayView.prototype,
  583. uint32ArrayViewSetters,
  584. createUint32ArrayProp(uint32ArrayViewSetters));
  585. uint32ArrayViewSetters++;
  586. }
  587. }
  588. return Uint32ArrayView;
  589. })();
  590. exports.Uint32ArrayView = Uint32ArrayView;
  591. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  592. var Util = PDFJS.Util = (function UtilClosure() {
  593. function Util() {}
  594. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  595. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  596. // creating many intermediate strings.
  597. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  598. rgbBuf[1] = r;
  599. rgbBuf[3] = g;
  600. rgbBuf[5] = b;
  601. return rgbBuf.join('');
  602. };
  603. // Concatenates two transformation matrices together and returns the result.
  604. Util.transform = function Util_transform(m1, m2) {
  605. return [
  606. m1[0] * m2[0] + m1[2] * m2[1],
  607. m1[1] * m2[0] + m1[3] * m2[1],
  608. m1[0] * m2[2] + m1[2] * m2[3],
  609. m1[1] * m2[2] + m1[3] * m2[3],
  610. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  611. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  612. ];
  613. };
  614. // For 2d affine transforms
  615. Util.applyTransform = function Util_applyTransform(p, m) {
  616. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  617. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  618. return [xt, yt];
  619. };
  620. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  621. var d = m[0] * m[3] - m[1] * m[2];
  622. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  623. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  624. return [xt, yt];
  625. };
  626. // Applies the transform to the rectangle and finds the minimum axially
  627. // aligned bounding box.
  628. Util.getAxialAlignedBoundingBox =
  629. function Util_getAxialAlignedBoundingBox(r, m) {
  630. var p1 = Util.applyTransform(r, m);
  631. var p2 = Util.applyTransform(r.slice(2, 4), m);
  632. var p3 = Util.applyTransform([r[0], r[3]], m);
  633. var p4 = Util.applyTransform([r[2], r[1]], m);
  634. return [
  635. Math.min(p1[0], p2[0], p3[0], p4[0]),
  636. Math.min(p1[1], p2[1], p3[1], p4[1]),
  637. Math.max(p1[0], p2[0], p3[0], p4[0]),
  638. Math.max(p1[1], p2[1], p3[1], p4[1])
  639. ];
  640. };
  641. Util.inverseTransform = function Util_inverseTransform(m) {
  642. var d = m[0] * m[3] - m[1] * m[2];
  643. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  644. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  645. };
  646. // Apply a generic 3d matrix M on a 3-vector v:
  647. // | a b c | | X |
  648. // | d e f | x | Y |
  649. // | g h i | | Z |
  650. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  651. // with v as [X,Y,Z]
  652. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  653. return [
  654. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  655. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  656. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  657. ];
  658. };
  659. // This calculation uses Singular Value Decomposition.
  660. // The SVD can be represented with formula A = USV. We are interested in the
  661. // matrix S here because it represents the scale values.
  662. Util.singularValueDecompose2dScale =
  663. function Util_singularValueDecompose2dScale(m) {
  664. var transpose = [m[0], m[2], m[1], m[3]];
  665. // Multiply matrix m with its transpose.
  666. var a = m[0] * transpose[0] + m[1] * transpose[2];
  667. var b = m[0] * transpose[1] + m[1] * transpose[3];
  668. var c = m[2] * transpose[0] + m[3] * transpose[2];
  669. var d = m[2] * transpose[1] + m[3] * transpose[3];
  670. // Solve the second degree polynomial to get roots.
  671. var first = (a + d) / 2;
  672. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  673. var sx = first + second || 1;
  674. var sy = first - second || 1;
  675. // Scale values are the square roots of the eigenvalues.
  676. return [Math.sqrt(sx), Math.sqrt(sy)];
  677. };
  678. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  679. // For coordinate systems whose origin lies in the bottom-left, this
  680. // means normalization to (BL,TR) ordering. For systems with origin in the
  681. // top-left, this means (TL,BR) ordering.
  682. Util.normalizeRect = function Util_normalizeRect(rect) {
  683. var r = rect.slice(0); // clone rect
  684. if (rect[0] > rect[2]) {
  685. r[0] = rect[2];
  686. r[2] = rect[0];
  687. }
  688. if (rect[1] > rect[3]) {
  689. r[1] = rect[3];
  690. r[3] = rect[1];
  691. }
  692. return r;
  693. };
  694. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  695. // intersection of rect1 and rect2. If no intersection, returns 'false'
  696. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  697. Util.intersect = function Util_intersect(rect1, rect2) {
  698. function compare(a, b) {
  699. return a - b;
  700. }
  701. // Order points along the axes
  702. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  703. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  704. result = [];
  705. rect1 = Util.normalizeRect(rect1);
  706. rect2 = Util.normalizeRect(rect2);
  707. // X: first and second points belong to different rectangles?
  708. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  709. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  710. // Intersection must be between second and third points
  711. result[0] = orderedX[1];
  712. result[2] = orderedX[2];
  713. } else {
  714. return false;
  715. }
  716. // Y: first and second points belong to different rectangles?
  717. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  718. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  719. // Intersection must be between second and third points
  720. result[1] = orderedY[1];
  721. result[3] = orderedY[2];
  722. } else {
  723. return false;
  724. }
  725. return result;
  726. };
  727. Util.sign = function Util_sign(num) {
  728. return num < 0 ? -1 : 1;
  729. };
  730. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  731. Array.prototype.push.apply(arr1, arr2);
  732. };
  733. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  734. Array.prototype.unshift.apply(arr1, arr2);
  735. };
  736. Util.extendObj = function extendObj(obj1, obj2) {
  737. for (var key in obj2) {
  738. obj1[key] = obj2[key];
  739. }
  740. };
  741. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  742. name) {
  743. while (dict && !dict.has(name)) {
  744. dict = dict.get('Parent');
  745. }
  746. if (!dict) {
  747. return null;
  748. }
  749. return dict.get(name);
  750. };
  751. Util.inherit = function Util_inherit(sub, base, prototype) {
  752. sub.prototype = Object.create(base.prototype);
  753. sub.prototype.constructor = sub;
  754. for (var prop in prototype) {
  755. sub.prototype[prop] = prototype[prop];
  756. }
  757. };
  758. Util.loadScript = function Util_loadScript(src, callback) {
  759. var script = document.createElement('script');
  760. var loaded = false;
  761. script.setAttribute('src', src);
  762. if (callback) {
  763. script.onload = function() {
  764. if (!loaded) {
  765. callback();
  766. }
  767. loaded = true;
  768. };
  769. }
  770. document.getElementsByTagName('head')[0].appendChild(script);
  771. };
  772. return Util;
  773. })();
  774. /**
  775. * PDF page viewport created based on scale, rotation and offset.
  776. * @class
  777. * @alias PDFJS.PageViewport
  778. */
  779. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  780. /**
  781. * @constructor
  782. * @private
  783. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  784. * @param scale {number} scale of the viewport.
  785. * @param rotation {number} rotations of the viewport in degrees.
  786. * @param offsetX {number} offset X
  787. * @param offsetY {number} offset Y
  788. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  789. */
  790. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  791. this.viewBox = viewBox;
  792. this.scale = scale;
  793. this.rotation = rotation;
  794. this.offsetX = offsetX;
  795. this.offsetY = offsetY;
  796. // creating transform to convert pdf coordinate system to the normal
  797. // canvas like coordinates taking in account scale and rotation
  798. var centerX = (viewBox[2] + viewBox[0]) / 2;
  799. var centerY = (viewBox[3] + viewBox[1]) / 2;
  800. var rotateA, rotateB, rotateC, rotateD;
  801. rotation = rotation % 360;
  802. rotation = rotation < 0 ? rotation + 360 : rotation;
  803. switch (rotation) {
  804. case 180:
  805. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  806. break;
  807. case 90:
  808. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  809. break;
  810. case 270:
  811. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  812. break;
  813. //case 0:
  814. default:
  815. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  816. break;
  817. }
  818. if (dontFlip) {
  819. rotateC = -rotateC; rotateD = -rotateD;
  820. }
  821. var offsetCanvasX, offsetCanvasY;
  822. var width, height;
  823. if (rotateA === 0) {
  824. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  825. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  826. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  827. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  828. } else {
  829. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  830. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  831. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  832. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  833. }
  834. // creating transform for the following operations:
  835. // translate(-centerX, -centerY), rotate and flip vertically,
  836. // scale, and translate(offsetCanvasX, offsetCanvasY)
  837. this.transform = [
  838. rotateA * scale,
  839. rotateB * scale,
  840. rotateC * scale,
  841. rotateD * scale,
  842. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  843. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  844. ];
  845. this.width = width;
  846. this.height = height;
  847. this.fontScale = scale;
  848. }
  849. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  850. /**
  851. * Clones viewport with additional properties.
  852. * @param args {Object} (optional) If specified, may contain the 'scale' or
  853. * 'rotation' properties to override the corresponding properties in
  854. * the cloned viewport.
  855. * @returns {PDFJS.PageViewport} Cloned viewport.
  856. */
  857. clone: function PageViewPort_clone(args) {
  858. args = args || {};
  859. var scale = 'scale' in args ? args.scale : this.scale;
  860. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  861. return new PageViewport(this.viewBox.slice(), scale, rotation,
  862. this.offsetX, this.offsetY, args.dontFlip);
  863. },
  864. /**
  865. * Converts PDF point to the viewport coordinates. For examples, useful for
  866. * converting PDF location into canvas pixel coordinates.
  867. * @param x {number} X coordinate.
  868. * @param y {number} Y coordinate.
  869. * @returns {Object} Object that contains 'x' and 'y' properties of the
  870. * point in the viewport coordinate space.
  871. * @see {@link convertToPdfPoint}
  872. * @see {@link convertToViewportRectangle}
  873. */
  874. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  875. return Util.applyTransform([x, y], this.transform);
  876. },
  877. /**
  878. * Converts PDF rectangle to the viewport coordinates.
  879. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  880. * @returns {Array} Contains corresponding coordinates of the rectangle
  881. * in the viewport coordinate space.
  882. * @see {@link convertToViewportPoint}
  883. */
  884. convertToViewportRectangle:
  885. function PageViewport_convertToViewportRectangle(rect) {
  886. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  887. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  888. return [tl[0], tl[1], br[0], br[1]];
  889. },
  890. /**
  891. * Converts viewport coordinates to the PDF location. For examples, useful
  892. * for converting canvas pixel location into PDF one.
  893. * @param x {number} X coordinate.
  894. * @param y {number} Y coordinate.
  895. * @returns {Object} Object that contains 'x' and 'y' properties of the
  896. * point in the PDF coordinate space.
  897. * @see {@link convertToViewportPoint}
  898. */
  899. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  900. return Util.applyInverseTransform([x, y], this.transform);
  901. }
  902. };
  903. return PageViewport;
  904. })();
  905. var PDFStringTranslateTable = [
  906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  907. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  912. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  913. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  914. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  915. ];
  916. function stringToPDFString(str) {
  917. var i, n = str.length, strBuf = [];
  918. if (str[0] === '\xFE' && str[1] === '\xFF') {
  919. // UTF16BE BOM
  920. for (i = 2; i < n; i += 2) {
  921. strBuf.push(String.fromCharCode(
  922. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  923. }
  924. } else {
  925. for (i = 0; i < n; ++i) {
  926. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  927. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  928. }
  929. }
  930. return strBuf.join('');
  931. }
  932. function stringToUTF8String(str) {
  933. return decodeURIComponent(escape(str));
  934. }
  935. function utf8StringToString(str) {
  936. return unescape(encodeURIComponent(str));
  937. }
  938. function isEmptyObj(obj) {
  939. for (var key in obj) {
  940. return false;
  941. }
  942. return true;
  943. }
  944. function isBool(v) {
  945. return typeof v === 'boolean';
  946. }
  947. function isInt(v) {
  948. return typeof v === 'number' && ((v | 0) === v);
  949. }
  950. function isNum(v) {
  951. return typeof v === 'number';
  952. }
  953. function isString(v) {
  954. return typeof v === 'string';
  955. }
  956. function isArray(v) {
  957. return v instanceof Array;
  958. }
  959. function isArrayBuffer(v) {
  960. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  961. }
  962. /**
  963. * Promise Capability object.
  964. *
  965. * @typedef {Object} PromiseCapability
  966. * @property {Promise} promise - A promise object.
  967. * @property {function} resolve - Fullfills the promise.
  968. * @property {function} reject - Rejects the promise.
  969. */
  970. /**
  971. * Creates a promise capability object.
  972. * @alias PDFJS.createPromiseCapability
  973. *
  974. * @return {PromiseCapability} A capability object contains:
  975. * - a Promise, resolve and reject methods.
  976. */
  977. function createPromiseCapability() {
  978. var capability = {};
  979. capability.promise = new Promise(function (resolve, reject) {
  980. capability.resolve = resolve;
  981. capability.reject = reject;
  982. });
  983. return capability;
  984. }
  985. PDFJS.createPromiseCapability = createPromiseCapability;
  986. /**
  987. * Polyfill for Promises:
  988. * The following promise implementation tries to generally implement the
  989. * Promise/A+ spec. Some notable differences from other promise libaries are:
  990. * - There currently isn't a seperate deferred and promise object.
  991. * - Unhandled rejections eventually show an error if they aren't handled.
  992. *
  993. * Based off of the work in:
  994. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  995. */
  996. (function PromiseClosure() {
  997. if (globalScope.Promise) {
  998. // Promises existing in the DOM/Worker, checking presence of all/resolve
  999. if (typeof globalScope.Promise.all !== 'function') {
  1000. globalScope.Promise.all = function (iterable) {
  1001. var count = 0, results = [], resolve, reject;
  1002. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1003. resolve = resolve_;
  1004. reject = reject_;
  1005. });
  1006. iterable.forEach(function (p, i) {
  1007. count++;
  1008. p.then(function (result) {
  1009. results[i] = result;
  1010. count--;
  1011. if (count === 0) {
  1012. resolve(results);
  1013. }
  1014. }, reject);
  1015. });
  1016. if (count === 0) {
  1017. resolve(results);
  1018. }
  1019. return promise;
  1020. };
  1021. }
  1022. if (typeof globalScope.Promise.resolve !== 'function') {
  1023. globalScope.Promise.resolve = function (value) {
  1024. return new globalScope.Promise(function (resolve) { resolve(value); });
  1025. };
  1026. }
  1027. if (typeof globalScope.Promise.reject !== 'function') {
  1028. globalScope.Promise.reject = function (reason) {
  1029. return new globalScope.Promise(function (resolve, reject) {
  1030. reject(reason);
  1031. });
  1032. };
  1033. }
  1034. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1035. globalScope.Promise.prototype.catch = function (onReject) {
  1036. return globalScope.Promise.prototype.then(undefined, onReject);
  1037. };
  1038. }
  1039. return;
  1040. }
  1041. var STATUS_PENDING = 0;
  1042. var STATUS_RESOLVED = 1;
  1043. var STATUS_REJECTED = 2;
  1044. // In an attempt to avoid silent exceptions, unhandled rejections are
  1045. // tracked and if they aren't handled in a certain amount of time an
  1046. // error is logged.
  1047. var REJECTION_TIMEOUT = 500;
  1048. var HandlerManager = {
  1049. handlers: [],
  1050. running: false,
  1051. unhandledRejections: [],
  1052. pendingRejectionCheck: false,
  1053. scheduleHandlers: function scheduleHandlers(promise) {
  1054. if (promise._status === STATUS_PENDING) {
  1055. return;
  1056. }
  1057. this.handlers = this.handlers.concat(promise._handlers);
  1058. promise._handlers = [];
  1059. if (this.running) {
  1060. return;
  1061. }
  1062. this.running = true;
  1063. setTimeout(this.runHandlers.bind(this), 0);
  1064. },
  1065. runHandlers: function runHandlers() {
  1066. var RUN_TIMEOUT = 1; // ms
  1067. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1068. while (this.handlers.length > 0) {
  1069. var handler = this.handlers.shift();
  1070. var nextStatus = handler.thisPromise._status;
  1071. var nextValue = handler.thisPromise._value;
  1072. try {
  1073. if (nextStatus === STATUS_RESOLVED) {
  1074. if (typeof handler.onResolve === 'function') {
  1075. nextValue = handler.onResolve(nextValue);
  1076. }
  1077. } else if (typeof handler.onReject === 'function') {
  1078. nextValue = handler.onReject(nextValue);
  1079. nextStatus = STATUS_RESOLVED;
  1080. if (handler.thisPromise._unhandledRejection) {
  1081. this.removeUnhandeledRejection(handler.thisPromise);
  1082. }
  1083. }
  1084. } catch (ex) {
  1085. nextStatus = STATUS_REJECTED;
  1086. nextValue = ex;
  1087. }
  1088. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1089. if (Date.now() >= timeoutAt) {
  1090. break;
  1091. }
  1092. }
  1093. if (this.handlers.length > 0) {
  1094. setTimeout(this.runHandlers.bind(this), 0);
  1095. return;
  1096. }
  1097. this.running = false;
  1098. },
  1099. addUnhandledRejection: function addUnhandledRejection(promise) {
  1100. this.unhandledRejections.push({
  1101. promise: promise,
  1102. time: Date.now()
  1103. });
  1104. this.scheduleRejectionCheck();
  1105. },
  1106. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1107. promise._unhandledRejection = false;
  1108. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1109. if (this.unhandledRejections[i].promise === promise) {
  1110. this.unhandledRejections.splice(i);
  1111. i--;
  1112. }
  1113. }
  1114. },
  1115. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1116. if (this.pendingRejectionCheck) {
  1117. return;
  1118. }
  1119. this.pendingRejectionCheck = true;
  1120. setTimeout(function rejectionCheck() {
  1121. this.pendingRejectionCheck = false;
  1122. var now = Date.now();
  1123. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1124. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1125. var unhandled = this.unhandledRejections[i].promise._value;
  1126. var msg = 'Unhandled rejection: ' + unhandled;
  1127. if (unhandled.stack) {
  1128. msg += '\n' + unhandled.stack;
  1129. }
  1130. warn(msg);
  1131. this.unhandledRejections.splice(i);
  1132. i--;
  1133. }
  1134. }
  1135. if (this.unhandledRejections.length) {
  1136. this.scheduleRejectionCheck();
  1137. }
  1138. }.bind(this), REJECTION_TIMEOUT);
  1139. }
  1140. };
  1141. function Promise(resolver) {
  1142. this._status = STATUS_PENDING;
  1143. this._handlers = [];
  1144. try {
  1145. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1146. } catch (e) {
  1147. this._reject(e);
  1148. }
  1149. }
  1150. /**
  1151. * Builds a promise that is resolved when all the passed in promises are
  1152. * resolved.
  1153. * @param {array} array of data and/or promises to wait for.
  1154. * @return {Promise} New dependant promise.
  1155. */
  1156. Promise.all = function Promise_all(promises) {
  1157. var resolveAll, rejectAll;
  1158. var deferred = new Promise(function (resolve, reject) {
  1159. resolveAll = resolve;
  1160. rejectAll = reject;
  1161. });
  1162. var unresolved = promises.length;
  1163. var results = [];
  1164. if (unresolved === 0) {
  1165. resolveAll(results);
  1166. return deferred;
  1167. }
  1168. function reject(reason) {
  1169. if (deferred._status === STATUS_REJECTED) {
  1170. return;
  1171. }
  1172. results = [];
  1173. rejectAll(reason);
  1174. }
  1175. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1176. var promise = promises[i];
  1177. var resolve = (function(i) {
  1178. return function(value) {
  1179. if (deferred._status === STATUS_REJECTED) {
  1180. return;
  1181. }
  1182. results[i] = value;
  1183. unresolved--;
  1184. if (unresolved === 0) {
  1185. resolveAll(results);
  1186. }
  1187. };
  1188. })(i);
  1189. if (Promise.isPromise(promise)) {
  1190. promise.then(resolve, reject);
  1191. } else {
  1192. resolve(promise);
  1193. }
  1194. }
  1195. return deferred;
  1196. };
  1197. /**
  1198. * Checks if the value is likely a promise (has a 'then' function).
  1199. * @return {boolean} true if value is thenable
  1200. */
  1201. Promise.isPromise = function Promise_isPromise(value) {
  1202. return value && typeof value.then === 'function';
  1203. };
  1204. /**
  1205. * Creates resolved promise
  1206. * @param value resolve value
  1207. * @returns {Promise}
  1208. */
  1209. Promise.resolve = function Promise_resolve(value) {
  1210. return new Promise(function (resolve) { resolve(value); });
  1211. };
  1212. /**
  1213. * Creates rejected promise
  1214. * @param reason rejection value
  1215. * @returns {Promise}
  1216. */
  1217. Promise.reject = function Promise_reject(reason) {
  1218. return new Promise(function (resolve, reject) { reject(reason); });
  1219. };
  1220. Promise.prototype = {
  1221. _status: null,
  1222. _value: null,
  1223. _handlers: null,
  1224. _unhandledRejection: null,
  1225. _updateStatus: function Promise__updateStatus(status, value) {
  1226. if (this._status === STATUS_RESOLVED ||
  1227. this._status === STATUS_REJECTED) {
  1228. return;
  1229. }
  1230. if (status === STATUS_RESOLVED &&
  1231. Promise.isPromise(value)) {
  1232. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1233. this._updateStatus.bind(this, STATUS_REJECTED));
  1234. return;
  1235. }
  1236. this._status = status;
  1237. this._value = value;
  1238. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1239. this._unhandledRejection = true;
  1240. HandlerManager.addUnhandledRejection(this);
  1241. }
  1242. HandlerManager.scheduleHandlers(this);
  1243. },
  1244. _resolve: function Promise_resolve(value) {
  1245. this._updateStatus(STATUS_RESOLVED, value);
  1246. },
  1247. _reject: function Promise_reject(reason) {
  1248. this._updateStatus(STATUS_REJECTED, reason);
  1249. },
  1250. then: function Promise_then(onResolve, onReject) {
  1251. var nextPromise = new Promise(function (resolve, reject) {
  1252. this.resolve = resolve;
  1253. this.reject = reject;
  1254. });
  1255. this._handlers.push({
  1256. thisPromise: this,
  1257. onResolve: onResolve,
  1258. onReject: onReject,
  1259. nextPromise: nextPromise
  1260. });
  1261. HandlerManager.scheduleHandlers(this);
  1262. return nextPromise;
  1263. },
  1264. catch: function Promise_catch(onReject) {
  1265. return this.then(undefined, onReject);
  1266. }
  1267. };
  1268. globalScope.Promise = Promise;
  1269. })();
  1270. var StatTimer = (function StatTimerClosure() {
  1271. function rpad(str, pad, length) {
  1272. while (str.length < length) {
  1273. str += pad;
  1274. }
  1275. return str;
  1276. }
  1277. function StatTimer() {
  1278. this.started = {};
  1279. this.times = [];
  1280. this.enabled = true;
  1281. }
  1282. StatTimer.prototype = {
  1283. time: function StatTimer_time(name) {
  1284. if (!this.enabled) {
  1285. return;
  1286. }
  1287. if (name in this.started) {
  1288. warn('Timer is already running for ' + name);
  1289. }
  1290. this.started[name] = Date.now();
  1291. },
  1292. timeEnd: function StatTimer_timeEnd(name) {
  1293. if (!this.enabled) {
  1294. return;
  1295. }
  1296. if (!(name in this.started)) {
  1297. warn('Timer has not been started for ' + name);
  1298. }
  1299. this.times.push({
  1300. 'name': name,
  1301. 'start': this.started[name],
  1302. 'end': Date.now()
  1303. });
  1304. // Remove timer from started so it can be called again.
  1305. delete this.started[name];
  1306. },
  1307. toString: function StatTimer_toString() {
  1308. var i, ii;
  1309. var times = this.times;
  1310. var out = '';
  1311. // Find the longest name for padding purposes.
  1312. var longest = 0;
  1313. for (i = 0, ii = times.length; i < ii; ++i) {
  1314. var name = times[i]['name'];
  1315. if (name.length > longest) {
  1316. longest = name.length;
  1317. }
  1318. }
  1319. for (i = 0, ii = times.length; i < ii; ++i) {
  1320. var span = times[i];
  1321. var duration = span.end - span.start;
  1322. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1323. }
  1324. return out;
  1325. }
  1326. };
  1327. return StatTimer;
  1328. })();
  1329. PDFJS.createBlob = function createBlob(data, contentType) {
  1330. if (typeof Blob !== 'undefined') {
  1331. return new Blob([data], { type: contentType });
  1332. }
  1333. // Blob builder is deprecated in FF14 and removed in FF18.
  1334. var bb = new MozBlobBuilder();
  1335. bb.append(data);
  1336. return bb.getBlob(contentType);
  1337. };
  1338. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1339. // Blob/createObjectURL is not available, falling back to data schema.
  1340. var digits =
  1341. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1342. return function createObjectURL(data, contentType) {
  1343. if (!PDFJS.disableCreateObjectURL &&
  1344. typeof URL !== 'undefined' && URL.createObjectURL) {
  1345. var blob = PDFJS.createBlob(data, contentType);
  1346. return URL.createObjectURL(blob);
  1347. }
  1348. var buffer = 'data:' + contentType + ';base64,';
  1349. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1350. var b1 = data[i] & 0xFF;
  1351. var b2 = data[i + 1] & 0xFF;
  1352. var b3 = data[i + 2] & 0xFF;
  1353. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1354. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1355. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1356. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1357. }
  1358. return buffer;
  1359. };
  1360. })();
  1361. function MessageHandler(sourceName, targetName, comObj) {
  1362. this.sourceName = sourceName;
  1363. this.targetName = targetName;
  1364. this.comObj = comObj;
  1365. this.callbackIndex = 1;
  1366. this.postMessageTransfers = true;
  1367. var callbacksCapabilities = this.callbacksCapabilities = {};
  1368. var ah = this.actionHandler = {};
  1369. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1370. var data = event.data;
  1371. if (data.targetName !== this.sourceName) {
  1372. return;
  1373. }
  1374. if (data.isReply) {
  1375. var callbackId = data.callbackId;
  1376. if (data.callbackId in callbacksCapabilities) {
  1377. var callback = callbacksCapabilities[callbackId];
  1378. delete callbacksCapabilities[callbackId];
  1379. if ('error' in data) {
  1380. callback.reject(data.error);
  1381. } else {
  1382. callback.resolve(data.data);
  1383. }
  1384. } else {
  1385. error('Cannot resolve callback ' + callbackId);
  1386. }
  1387. } else if (data.action in ah) {
  1388. var action = ah[data.action];
  1389. if (data.callbackId) {
  1390. var sourceName = this.sourceName;
  1391. var targetName = data.sourceName;
  1392. Promise.resolve().then(function () {
  1393. return action[0].call(action[1], data.data);
  1394. }).then(function (result) {
  1395. comObj.postMessage({
  1396. sourceName: sourceName,
  1397. targetName: targetName,
  1398. isReply: true,
  1399. callbackId: data.callbackId,
  1400. data: result
  1401. });
  1402. }, function (reason) {
  1403. if (reason instanceof Error) {
  1404. // Serialize error to avoid "DataCloneError"
  1405. reason = reason + '';
  1406. }
  1407. comObj.postMessage({
  1408. sourceName: sourceName,
  1409. targetName: targetName,
  1410. isReply: true,
  1411. callbackId: data.callbackId,
  1412. error: reason
  1413. });
  1414. });
  1415. } else {
  1416. action[0].call(action[1], data.data);
  1417. }
  1418. } else {
  1419. error('Unknown action from worker: ' + data.action);
  1420. }
  1421. }.bind(this);
  1422. comObj.addEventListener('message', this._onComObjOnMessage);
  1423. }
  1424. MessageHandler.prototype = {
  1425. on: function messageHandlerOn(actionName, handler, scope) {
  1426. var ah = this.actionHandler;
  1427. if (ah[actionName]) {
  1428. error('There is already an actionName called "' + actionName + '"');
  1429. }
  1430. ah[actionName] = [handler, scope];
  1431. },
  1432. /**
  1433. * Sends a message to the comObj to invoke the action with the supplied data.
  1434. * @param {String} actionName Action to call.
  1435. * @param {JSON} data JSON data to send.
  1436. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1437. */
  1438. send: function messageHandlerSend(actionName, data, transfers) {
  1439. var message = {
  1440. sourceName: this.sourceName,
  1441. targetName: this.targetName,
  1442. action: actionName,
  1443. data: data
  1444. };
  1445. this.postMessage(message, transfers);
  1446. },
  1447. /**
  1448. * Sends a message to the comObj to invoke the action with the supplied data.
  1449. * Expects that other side will callback with the response.
  1450. * @param {String} actionName Action to call.
  1451. * @param {JSON} data JSON data to send.
  1452. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1453. * @returns {Promise} Promise to be resolved with response data.
  1454. */
  1455. sendWithPromise:
  1456. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1457. var callbackId = this.callbackIndex++;
  1458. var message = {
  1459. sourceName: this.sourceName,
  1460. targetName: this.targetName,
  1461. action: actionName,
  1462. data: data,
  1463. callbackId: callbackId
  1464. };
  1465. var capability = createPromiseCapability();
  1466. this.callbacksCapabilities[callbackId] = capability;
  1467. try {
  1468. this.postMessage(message, transfers);
  1469. } catch (e) {
  1470. capability.reject(e);
  1471. }
  1472. return capability.promise;
  1473. },
  1474. /**
  1475. * Sends raw message to the comObj.
  1476. * @private
  1477. * @param message {Object} Raw message.
  1478. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1479. */
  1480. postMessage: function (message, transfers) {
  1481. if (transfers && this.postMessageTransfers) {
  1482. this.comObj.postMessage(message, transfers);
  1483. } else {
  1484. this.comObj.postMessage(message);
  1485. }
  1486. },
  1487. destroy: function () {
  1488. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1489. }
  1490. };
  1491. function loadJpegStream(id, imageUrl, objs) {
  1492. var img = new Image();
  1493. img.onload = (function loadJpegStream_onloadClosure() {
  1494. objs.resolve(id, img);
  1495. });
  1496. img.onerror = (function loadJpegStream_onerrorClosure() {
  1497. objs.resolve(id, null);
  1498. warn('Error during JPEG image loading');
  1499. });
  1500. img.src = imageUrl;
  1501. }
  1502. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1503. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1504. exports.OPS = OPS;
  1505. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1506. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1507. exports.AnnotationFlag = AnnotationFlag;
  1508. exports.AnnotationType = AnnotationType;
  1509. exports.FontType = FontType;
  1510. exports.ImageKind = ImageKind;
  1511. exports.InvalidPDFException = InvalidPDFException;
  1512. exports.LinkTarget = LinkTarget;
  1513. exports.LinkTargetStringMap = LinkTargetStringMap;
  1514. exports.MessageHandler = MessageHandler;
  1515. exports.MissingDataException = MissingDataException;
  1516. exports.MissingPDFException = MissingPDFException;
  1517. exports.NotImplementedException = NotImplementedException;
  1518. exports.PasswordException = PasswordException;
  1519. exports.PasswordResponses = PasswordResponses;
  1520. exports.StatTimer = StatTimer;
  1521. exports.StreamType = StreamType;
  1522. exports.TextRenderingMode = TextRenderingMode;
  1523. exports.UnexpectedResponseException = UnexpectedResponseException;
  1524. exports.UnknownErrorException = UnknownErrorException;
  1525. exports.Util = Util;
  1526. exports.XRefParseException = XRefParseException;
  1527. exports.assert = assert;
  1528. exports.bytesToString = bytesToString;
  1529. exports.combineUrl = combineUrl;
  1530. exports.createPromiseCapability = createPromiseCapability;
  1531. exports.deprecated = deprecated;
  1532. exports.error = error;
  1533. exports.info = info;
  1534. exports.isArray = isArray;
  1535. exports.isArrayBuffer = isArrayBuffer;
  1536. exports.isBool = isBool;
  1537. exports.isEmptyObj = isEmptyObj;
  1538. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1539. exports.isInt = isInt;
  1540. exports.isNum = isNum;
  1541. exports.isString = isString;
  1542. exports.isValidUrl = isValidUrl;
  1543. exports.loadJpegStream = loadJpegStream;
  1544. exports.log2 = log2;
  1545. exports.readInt8 = readInt8;
  1546. exports.readUint16 = readUint16;
  1547. exports.readUint32 = readUint32;
  1548. exports.shadow = shadow;
  1549. exports.string32 = string32;
  1550. exports.stringToBytes = stringToBytes;
  1551. exports.stringToPDFString = stringToPDFString;
  1552. exports.stringToUTF8String = stringToUTF8String;
  1553. exports.utf8StringToString = utf8StringToString;
  1554. exports.warn = warn;
  1555. }));
  1556. (function (root, factory) {
  1557. {
  1558. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  1559. }
  1560. }(this, function (exports, sharedGlobal) {
  1561. var PDFJS = sharedGlobal.PDFJS;
  1562. /**
  1563. * Optimised CSS custom property getter/setter.
  1564. * @class
  1565. */
  1566. var CustomStyle = (function CustomStyleClosure() {
  1567. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  1568. // animate-css-transforms-firefox-webkit.html
  1569. // in some versions of IE9 it is critical that ms appear in this list
  1570. // before Moz
  1571. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  1572. var _cache = {};
  1573. function CustomStyle() {}
  1574. CustomStyle.getProp = function get(propName, element) {
  1575. // check cache only when no element is given
  1576. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  1577. return _cache[propName];
  1578. }
  1579. element = element || document.documentElement;
  1580. var style = element.style, prefixed, uPropName;
  1581. // test standard property first
  1582. if (typeof style[propName] === 'string') {
  1583. return (_cache[propName] = propName);
  1584. }
  1585. // capitalize
  1586. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  1587. // test vendor specific properties
  1588. for (var i = 0, l = prefixes.length; i < l; i++) {
  1589. prefixed = prefixes[i] + uPropName;
  1590. if (typeof style[prefixed] === 'string') {
  1591. return (_cache[propName] = prefixed);
  1592. }
  1593. }
  1594. //if all fails then set to undefined
  1595. return (_cache[propName] = 'undefined');
  1596. };
  1597. CustomStyle.setProp = function set(propName, element, str) {
  1598. var prop = this.getProp(propName);
  1599. if (prop !== 'undefined') {
  1600. element.style[prop] = str;
  1601. }
  1602. };
  1603. return CustomStyle;
  1604. })();
  1605. PDFJS.CustomStyle = CustomStyle;
  1606. exports.CustomStyle = CustomStyle;
  1607. }));
  1608. (function (root, factory) {
  1609. {
  1610. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  1611. root.pdfjsDisplayDOMUtils);
  1612. }
  1613. }(this, function (exports, sharedUtil, displayDOMUtils) {
  1614. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  1615. var AnnotationType = sharedUtil.AnnotationType;
  1616. var Util = sharedUtil.Util;
  1617. var isExternalLinkTargetSet = sharedUtil.isExternalLinkTargetSet;
  1618. var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
  1619. var warn = sharedUtil.warn;
  1620. var CustomStyle = displayDOMUtils.CustomStyle;
  1621. /**
  1622. * @typedef {Object} AnnotationElementParameters
  1623. * @property {Object} data
  1624. * @property {HTMLDivElement} layer
  1625. * @property {PDFPage} page
  1626. * @property {PageViewport} viewport
  1627. * @property {IPDFLinkService} linkService
  1628. */
  1629. /**
  1630. * @class
  1631. * @alias AnnotationElementFactory
  1632. */
  1633. function AnnotationElementFactory() {}
  1634. AnnotationElementFactory.prototype =
  1635. /** @lends AnnotationElementFactory.prototype */ {
  1636. /**
  1637. * @param {AnnotationElementParameters} parameters
  1638. * @returns {AnnotationElement}
  1639. */
  1640. create: function AnnotationElementFactory_create(parameters) {
  1641. var subtype = parameters.data.annotationType;
  1642. switch (subtype) {
  1643. case AnnotationType.LINK:
  1644. return new LinkAnnotationElement(parameters);
  1645. case AnnotationType.TEXT:
  1646. return new TextAnnotationElement(parameters);
  1647. case AnnotationType.WIDGET:
  1648. return new WidgetAnnotationElement(parameters);
  1649. case AnnotationType.POPUP:
  1650. return new PopupAnnotationElement(parameters);
  1651. default:
  1652. throw new Error('Unimplemented annotation type "' + subtype + '"');
  1653. }
  1654. }
  1655. };
  1656. /**
  1657. * @class
  1658. * @alias AnnotationElement
  1659. */
  1660. var AnnotationElement = (function AnnotationElementClosure() {
  1661. function AnnotationElement(parameters) {
  1662. this.data = parameters.data;
  1663. this.layer = parameters.layer;
  1664. this.page = parameters.page;
  1665. this.viewport = parameters.viewport;
  1666. this.linkService = parameters.linkService;
  1667. this.container = this._createContainer();
  1668. }
  1669. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  1670. /**
  1671. * Create an empty container for the annotation's HTML element.
  1672. *
  1673. * @private
  1674. * @memberof AnnotationElement
  1675. * @returns {HTMLSectionElement}
  1676. */
  1677. _createContainer: function AnnotationElement_createContainer() {
  1678. var data = this.data, page = this.page, viewport = this.viewport;
  1679. var container = document.createElement('section');
  1680. var width = data.rect[2] - data.rect[0];
  1681. var height = data.rect[3] - data.rect[1];
  1682. container.setAttribute('data-annotation-id', data.id);
  1683. // Do *not* modify `data.rect`, since that will corrupt the annotation
  1684. // position on subsequent calls to `_createContainer` (see issue 6804).
  1685. var rect = Util.normalizeRect([
  1686. data.rect[0],
  1687. page.view[3] - data.rect[1] + page.view[1],
  1688. data.rect[2],
  1689. page.view[3] - data.rect[3] + page.view[1]
  1690. ]);
  1691. CustomStyle.setProp('transform', container,
  1692. 'matrix(' + viewport.transform.join(',') + ')');
  1693. CustomStyle.setProp('transformOrigin', container,
  1694. -rect[0] + 'px ' + -rect[1] + 'px');
  1695. if (data.borderStyle.width > 0) {
  1696. container.style.borderWidth = data.borderStyle.width + 'px';
  1697. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  1698. // Underline styles only have a bottom border, so we do not need
  1699. // to adjust for all borders. This yields a similar result as
  1700. // Adobe Acrobat/Reader.
  1701. width = width - 2 * data.borderStyle.width;
  1702. height = height - 2 * data.borderStyle.width;
  1703. }
  1704. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  1705. var verticalRadius = data.borderStyle.verticalCornerRadius;
  1706. if (horizontalRadius > 0 || verticalRadius > 0) {
  1707. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  1708. CustomStyle.setProp('borderRadius', container, radius);
  1709. }
  1710. switch (data.borderStyle.style) {
  1711. case AnnotationBorderStyleType.SOLID:
  1712. container.style.borderStyle = 'solid';
  1713. break;
  1714. case AnnotationBorderStyleType.DASHED:
  1715. container.style.borderStyle = 'dashed';
  1716. break;
  1717. case AnnotationBorderStyleType.BEVELED:
  1718. warn('Unimplemented border style: beveled');
  1719. break;
  1720. case AnnotationBorderStyleType.INSET:
  1721. warn('Unimplemented border style: inset');
  1722. break;
  1723. case AnnotationBorderStyleType.UNDERLINE:
  1724. container.style.borderBottomStyle = 'solid';
  1725. break;
  1726. default:
  1727. break;
  1728. }
  1729. if (data.color) {
  1730. container.style.borderColor =
  1731. Util.makeCssRgb(data.color[0] | 0,
  1732. data.color[1] | 0,
  1733. data.color[2] | 0);
  1734. } else {
  1735. // Transparent (invisible) border, so do not draw it at all.
  1736. container.style.borderWidth = 0;
  1737. }
  1738. }
  1739. container.style.left = rect[0] + 'px';
  1740. container.style.top = rect[1] + 'px';
  1741. container.style.width = width + 'px';
  1742. container.style.height = height + 'px';
  1743. return container;
  1744. },
  1745. /**
  1746. * Render the annotation's HTML element in the empty container.
  1747. *
  1748. * @public
  1749. * @memberof AnnotationElement
  1750. */
  1751. render: function AnnotationElement_render() {
  1752. throw new Error('Abstract method AnnotationElement.render called');
  1753. }
  1754. };
  1755. return AnnotationElement;
  1756. })();
  1757. /**
  1758. * @class
  1759. * @alias LinkAnnotationElement
  1760. */
  1761. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  1762. function LinkAnnotationElement(parameters) {
  1763. AnnotationElement.call(this, parameters);
  1764. }
  1765. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  1766. /**
  1767. * Render the link annotation's HTML element in the empty container.
  1768. *
  1769. * @public
  1770. * @memberof LinkAnnotationElement
  1771. * @returns {HTMLSectionElement}
  1772. */
  1773. render: function LinkAnnotationElement_render() {
  1774. this.container.className = 'linkAnnotation';
  1775. var link = document.createElement('a');
  1776. link.href = link.title = this.data.url || '';
  1777. if (this.data.url && isExternalLinkTargetSet()) {
  1778. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  1779. }
  1780. // Strip referrer from the URL.
  1781. if (this.data.url) {
  1782. link.rel = PDFJS.externalLinkRel;
  1783. }
  1784. if (!this.data.url) {
  1785. if (this.data.action) {
  1786. this._bindNamedAction(link, this.data.action);
  1787. } else {
  1788. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  1789. }
  1790. }
  1791. this.container.appendChild(link);
  1792. return this.container;
  1793. },
  1794. /**
  1795. * Bind internal links to the link element.
  1796. *
  1797. * @private
  1798. * @param {Object} link
  1799. * @param {Object} destination
  1800. * @memberof LinkAnnotationElement
  1801. */
  1802. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  1803. var self = this;
  1804. link.href = this.linkService.getDestinationHash(destination);
  1805. link.onclick = function() {
  1806. if (destination) {
  1807. self.linkService.navigateTo(destination);
  1808. }
  1809. return false;
  1810. };
  1811. if (destination) {
  1812. link.className = 'internalLink';
  1813. }
  1814. },
  1815. /**
  1816. * Bind named actions to the link element.
  1817. *
  1818. * @private
  1819. * @param {Object} link
  1820. * @param {Object} action
  1821. * @memberof LinkAnnotationElement
  1822. */
  1823. _bindNamedAction:
  1824. function LinkAnnotationElement_bindNamedAction(link, action) {
  1825. var self = this;
  1826. link.href = this.linkService.getAnchorUrl('');
  1827. link.onclick = function() {
  1828. self.linkService.executeNamedAction(action);
  1829. return false;
  1830. };
  1831. link.className = 'internalLink';
  1832. }
  1833. });
  1834. return LinkAnnotationElement;
  1835. })();
  1836. /**
  1837. * @class
  1838. * @alias TextAnnotationElement
  1839. */
  1840. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  1841. function TextAnnotationElement(parameters) {
  1842. AnnotationElement.call(this, parameters);
  1843. }
  1844. Util.inherit(TextAnnotationElement, AnnotationElement, {
  1845. /**
  1846. * Render the text annotation's HTML element in the empty container.
  1847. *
  1848. * @public
  1849. * @memberof TextAnnotationElement
  1850. * @returns {HTMLSectionElement}
  1851. */
  1852. render: function TextAnnotationElement_render() {
  1853. this.container.className = 'textAnnotation';
  1854. var image = document.createElement('img');
  1855. image.style.height = this.container.style.height;
  1856. image.style.width = this.container.style.width;
  1857. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  1858. this.data.name.toLowerCase() + '.svg';
  1859. image.alt = '[{{type}} Annotation]';
  1860. image.dataset.l10nId = 'text_annotation_type';
  1861. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  1862. if (!this.data.hasPopup) {
  1863. var popupElement = new PopupElement({
  1864. container: this.container,
  1865. trigger: image,
  1866. color: this.data.color,
  1867. title: this.data.title,
  1868. contents: this.data.contents,
  1869. hideWrapper: true
  1870. });
  1871. var popup = popupElement.render();
  1872. // Position the popup next to the Text annotation's container.
  1873. popup.style.left = image.style.width;
  1874. this.container.appendChild(popup);
  1875. }
  1876. this.container.appendChild(image);
  1877. return this.container;
  1878. }
  1879. });
  1880. return TextAnnotationElement;
  1881. })();
  1882. /**
  1883. * @class
  1884. * @alias WidgetAnnotationElement
  1885. */
  1886. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  1887. function WidgetAnnotationElement(parameters) {
  1888. AnnotationElement.call(this, parameters);
  1889. }
  1890. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  1891. /**
  1892. * Render the widget annotation's HTML element in the empty container.
  1893. *
  1894. * @public
  1895. * @memberof WidgetAnnotationElement
  1896. * @returns {HTMLSectionElement}
  1897. */
  1898. render: function WidgetAnnotationElement_render() {
  1899. var content = document.createElement('div');
  1900. content.textContent = this.data.fieldValue;
  1901. var textAlignment = this.data.textAlignment;
  1902. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  1903. content.style.verticalAlign = 'middle';
  1904. content.style.display = 'table-cell';
  1905. var font = (this.data.fontRefName ?
  1906. this.page.commonObjs.getData(this.data.fontRefName) : null);
  1907. this._setTextStyle(content, font);
  1908. this.container.appendChild(content);
  1909. return this.container;
  1910. },
  1911. /**
  1912. * Apply text styles to the text in the element.
  1913. *
  1914. * @private
  1915. * @param {HTMLDivElement} element
  1916. * @param {Object} font
  1917. * @memberof WidgetAnnotationElement
  1918. */
  1919. _setTextStyle:
  1920. function WidgetAnnotationElement_setTextStyle(element, font) {
  1921. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  1922. var style = element.style;
  1923. style.fontSize = this.data.fontSize + 'px';
  1924. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  1925. if (!font) {
  1926. return;
  1927. }
  1928. style.fontWeight = (font.black ?
  1929. (font.bold ? '900' : 'bold') :
  1930. (font.bold ? 'bold' : 'normal'));
  1931. style.fontStyle = (font.italic ? 'italic' : 'normal');
  1932. // Use a reasonable default font if the font doesn't specify a fallback.
  1933. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  1934. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  1935. style.fontFamily = fontFamily + fallbackName;
  1936. }
  1937. });
  1938. return WidgetAnnotationElement;
  1939. })();
  1940. /**
  1941. * @class
  1942. * @alias PopupAnnotationElement
  1943. */
  1944. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  1945. function PopupAnnotationElement(parameters) {
  1946. AnnotationElement.call(this, parameters);
  1947. }
  1948. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  1949. /**
  1950. * Render the popup annotation's HTML element in the empty container.
  1951. *
  1952. * @public
  1953. * @memberof PopupAnnotationElement
  1954. * @returns {HTMLSectionElement}
  1955. */
  1956. render: function PopupAnnotationElement_render() {
  1957. this.container.className = 'popupAnnotation';
  1958. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  1959. var parentElement = this.layer.querySelector(selector);
  1960. if (!parentElement) {
  1961. return this.container;
  1962. }
  1963. var popup = new PopupElement({
  1964. container: this.container,
  1965. trigger: parentElement,
  1966. color: this.data.color,
  1967. title: this.data.title,
  1968. contents: this.data.contents
  1969. });
  1970. // Position the popup next to the parent annotation's container.
  1971. // PDF viewers ignore a popup annotation's rectangle.
  1972. var parentLeft = parseFloat(parentElement.style.left);
  1973. var parentWidth = parseFloat(parentElement.style.width);
  1974. CustomStyle.setProp('transformOrigin', this.container,
  1975. -(parentLeft + parentWidth) + 'px -' +
  1976. parentElement.style.top);
  1977. this.container.style.left = (parentLeft + parentWidth) + 'px';
  1978. this.container.appendChild(popup.render());
  1979. return this.container;
  1980. }
  1981. });
  1982. return PopupAnnotationElement;
  1983. })();
  1984. /**
  1985. * @class
  1986. * @alias PopupElement
  1987. */
  1988. var PopupElement = (function PopupElementClosure() {
  1989. var BACKGROUND_ENLIGHT = 0.7;
  1990. function PopupElement(parameters) {
  1991. this.container = parameters.container;
  1992. this.trigger = parameters.trigger;
  1993. this.color = parameters.color;
  1994. this.title = parameters.title;
  1995. this.contents = parameters.contents;
  1996. this.hideWrapper = parameters.hideWrapper || false;
  1997. this.pinned = false;
  1998. }
  1999. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  2000. /**
  2001. * Render the popup's HTML element.
  2002. *
  2003. * @public
  2004. * @memberof PopupElement
  2005. * @returns {HTMLSectionElement}
  2006. */
  2007. render: function PopupElement_render() {
  2008. var wrapper = document.createElement('div');
  2009. wrapper.className = 'popupWrapper';
  2010. // For Popup annotations we hide the entire section because it contains
  2011. // only the popup. However, for Text annotations without a separate Popup
  2012. // annotation, we cannot hide the entire container as the image would
  2013. // disappear too. In that special case, hiding the wrapper suffices.
  2014. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  2015. this.hideElement.setAttribute('hidden', true);
  2016. var popup = document.createElement('div');
  2017. popup.className = 'popup';
  2018. var color = this.color;
  2019. if (color) {
  2020. // Enlighten the color.
  2021. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  2022. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  2023. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  2024. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  2025. }
  2026. var contents = this._formatContents(this.contents);
  2027. var title = document.createElement('h1');
  2028. title.textContent = this.title;
  2029. // Attach the event listeners to the trigger element.
  2030. this.trigger.addEventListener('click', this._toggle.bind(this));
  2031. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  2032. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  2033. popup.addEventListener('click', this._hide.bind(this, true));
  2034. popup.appendChild(title);
  2035. popup.appendChild(contents);
  2036. wrapper.appendChild(popup);
  2037. return wrapper;
  2038. },
  2039. /**
  2040. * Format the contents of the popup by adding newlines where necessary.
  2041. *
  2042. * @private
  2043. * @param {string} contents
  2044. * @memberof PopupElement
  2045. * @returns {HTMLParagraphElement}
  2046. */
  2047. _formatContents: function PopupElement_formatContents(contents) {
  2048. var p = document.createElement('p');
  2049. var lines = contents.split(/(?:\r\n?|\n)/);
  2050. for (var i = 0, ii = lines.length; i < ii; ++i) {
  2051. var line = lines[i];
  2052. p.appendChild(document.createTextNode(line));
  2053. if (i < (ii - 1)) {
  2054. p.appendChild(document.createElement('br'));
  2055. }
  2056. }
  2057. return p;
  2058. },
  2059. /**
  2060. * Toggle the visibility of the popup.
  2061. *
  2062. * @private
  2063. * @memberof PopupElement
  2064. */
  2065. _toggle: function PopupElement_toggle() {
  2066. if (this.pinned) {
  2067. this._hide(true);
  2068. } else {
  2069. this._show(true);
  2070. }
  2071. },
  2072. /**
  2073. * Show the popup.
  2074. *
  2075. * @private
  2076. * @param {boolean} pin
  2077. * @memberof PopupElement
  2078. */
  2079. _show: function PopupElement_show(pin) {
  2080. if (pin) {
  2081. this.pinned = true;
  2082. }
  2083. if (this.hideElement.hasAttribute('hidden')) {
  2084. this.hideElement.removeAttribute('hidden');
  2085. this.container.style.zIndex += 1;
  2086. }
  2087. },
  2088. /**
  2089. * Hide the popup.
  2090. *
  2091. * @private
  2092. * @param {boolean} unpin
  2093. * @memberof PopupElement
  2094. */
  2095. _hide: function PopupElement_hide(unpin) {
  2096. if (unpin) {
  2097. this.pinned = false;
  2098. }
  2099. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  2100. this.hideElement.setAttribute('hidden', true);
  2101. this.container.style.zIndex -= 1;
  2102. }
  2103. }
  2104. };
  2105. return PopupElement;
  2106. })();
  2107. /**
  2108. * @typedef {Object} AnnotationLayerParameters
  2109. * @property {PageViewport} viewport
  2110. * @property {HTMLDivElement} div
  2111. * @property {Array} annotations
  2112. * @property {PDFPage} page
  2113. * @property {IPDFLinkService} linkService
  2114. */
  2115. /**
  2116. * @class
  2117. * @alias AnnotationLayer
  2118. */
  2119. var AnnotationLayer = (function AnnotationLayerClosure() {
  2120. return {
  2121. /**
  2122. * Render a new annotation layer with all annotation elements.
  2123. *
  2124. * @public
  2125. * @param {AnnotationLayerParameters} parameters
  2126. * @memberof AnnotationLayer
  2127. */
  2128. render: function AnnotationLayer_render(parameters) {
  2129. var annotationElementFactory = new AnnotationElementFactory();
  2130. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  2131. var data = parameters.annotations[i];
  2132. if (!data || !data.hasHtml) {
  2133. continue;
  2134. }
  2135. var properties = {
  2136. data: data,
  2137. layer: parameters.div,
  2138. page: parameters.page,
  2139. viewport: parameters.viewport,
  2140. linkService: parameters.linkService
  2141. };
  2142. var element = annotationElementFactory.create(properties);
  2143. parameters.div.appendChild(element.render());
  2144. }
  2145. },
  2146. /**
  2147. * Update the annotation elements on existing annotation layer.
  2148. *
  2149. * @public
  2150. * @param {AnnotationLayerParameters} parameters
  2151. * @memberof AnnotationLayer
  2152. */
  2153. update: function AnnotationLayer_update(parameters) {
  2154. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  2155. var data = parameters.annotations[i];
  2156. var element = parameters.div.querySelector(
  2157. '[data-annotation-id="' + data.id + '"]');
  2158. if (element) {
  2159. CustomStyle.setProp('transform', element,
  2160. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  2161. }
  2162. }
  2163. parameters.div.removeAttribute('hidden');
  2164. }
  2165. };
  2166. })();
  2167. PDFJS.AnnotationLayer = AnnotationLayer;
  2168. exports.AnnotationLayer = AnnotationLayer;
  2169. }));
  2170. (function (root, factory) {
  2171. {
  2172. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  2173. root.pdfjsSharedGlobal);
  2174. }
  2175. }(this, function (exports, sharedUtil, sharedGlobal) {
  2176. var assert = sharedUtil.assert;
  2177. var bytesToString = sharedUtil.bytesToString;
  2178. var string32 = sharedUtil.string32;
  2179. var shadow = sharedUtil.shadow;
  2180. var warn = sharedUtil.warn;
  2181. var PDFJS = sharedGlobal.PDFJS;
  2182. var globalScope = sharedGlobal.globalScope;
  2183. var isWorker = sharedGlobal.isWorker;
  2184. function FontLoader(docId) {
  2185. this.docId = docId;
  2186. this.styleElement = null;
  2187. this.nativeFontFaces = [];
  2188. this.loadTestFontId = 0;
  2189. this.loadingContext = {
  2190. requests: [],
  2191. nextRequestId: 0
  2192. };
  2193. }
  2194. FontLoader.prototype = {
  2195. insertRule: function fontLoaderInsertRule(rule) {
  2196. var styleElement = this.styleElement;
  2197. if (!styleElement) {
  2198. styleElement = this.styleElement = document.createElement('style');
  2199. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  2200. document.documentElement.getElementsByTagName('head')[0].appendChild(
  2201. styleElement);
  2202. }
  2203. var styleSheet = styleElement.sheet;
  2204. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  2205. },
  2206. clear: function fontLoaderClear() {
  2207. var styleElement = this.styleElement;
  2208. if (styleElement) {
  2209. styleElement.parentNode.removeChild(styleElement);
  2210. styleElement = this.styleElement = null;
  2211. }
  2212. this.nativeFontFaces.forEach(function(nativeFontFace) {
  2213. document.fonts.delete(nativeFontFace);
  2214. });
  2215. this.nativeFontFaces.length = 0;
  2216. },
  2217. get loadTestFont() {
  2218. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  2219. // height.
  2220. return shadow(this, 'loadTestFont', atob(
  2221. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  2222. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  2223. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  2224. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  2225. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  2226. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  2227. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  2228. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  2229. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  2230. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  2231. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  2232. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  2233. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  2234. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  2235. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  2236. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  2237. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  2238. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  2239. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  2240. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  2241. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  2242. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  2243. ));
  2244. },
  2245. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  2246. this.nativeFontFaces.push(nativeFontFace);
  2247. document.fonts.add(nativeFontFace);
  2248. },
  2249. bind: function fontLoaderBind(fonts, callback) {
  2250. assert(!isWorker, 'bind() shall be called from main thread');
  2251. var rules = [];
  2252. var fontsToLoad = [];
  2253. var fontLoadPromises = [];
  2254. var getNativeFontPromise = function(nativeFontFace) {
  2255. // Return a promise that is always fulfilled, even when the font fails to
  2256. // load.
  2257. return nativeFontFace.loaded.catch(function(e) {
  2258. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  2259. });
  2260. };
  2261. for (var i = 0, ii = fonts.length; i < ii; i++) {
  2262. var font = fonts[i];
  2263. // Add the font to the DOM only once or skip if the font
  2264. // is already loaded.
  2265. if (font.attached || font.loading === false) {
  2266. continue;
  2267. }
  2268. font.attached = true;
  2269. if (FontLoader.isFontLoadingAPISupported) {
  2270. var nativeFontFace = font.createNativeFontFace();
  2271. if (nativeFontFace) {
  2272. this.addNativeFontFace(nativeFontFace);
  2273. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  2274. }
  2275. } else {
  2276. var rule = font.createFontFaceRule();
  2277. if (rule) {
  2278. this.insertRule(rule);
  2279. rules.push(rule);
  2280. fontsToLoad.push(font);
  2281. }
  2282. }
  2283. }
  2284. var request = this.queueLoadingCallback(callback);
  2285. if (FontLoader.isFontLoadingAPISupported) {
  2286. Promise.all(fontLoadPromises).then(function() {
  2287. request.complete();
  2288. });
  2289. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  2290. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  2291. } else {
  2292. request.complete();
  2293. }
  2294. },
  2295. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  2296. function LoadLoader_completeRequest() {
  2297. assert(!request.end, 'completeRequest() cannot be called twice');
  2298. request.end = Date.now();
  2299. // sending all completed requests in order how they were queued
  2300. while (context.requests.length > 0 && context.requests[0].end) {
  2301. var otherRequest = context.requests.shift();
  2302. setTimeout(otherRequest.callback, 0);
  2303. }
  2304. }
  2305. var context = this.loadingContext;
  2306. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  2307. var request = {
  2308. id: requestId,
  2309. complete: LoadLoader_completeRequest,
  2310. callback: callback,
  2311. started: Date.now()
  2312. };
  2313. context.requests.push(request);
  2314. return request;
  2315. },
  2316. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  2317. fonts,
  2318. request) {
  2319. /** Hack begin */
  2320. // There's currently no event when a font has finished downloading so the
  2321. // following code is a dirty hack to 'guess' when a font is
  2322. // ready. It's assumed fonts are loaded in order, so add a known test
  2323. // font after the desired fonts and then test for the loading of that
  2324. // test font.
  2325. function int32(data, offset) {
  2326. return (data.charCodeAt(offset) << 24) |
  2327. (data.charCodeAt(offset + 1) << 16) |
  2328. (data.charCodeAt(offset + 2) << 8) |
  2329. (data.charCodeAt(offset + 3) & 0xff);
  2330. }
  2331. function spliceString(s, offset, remove, insert) {
  2332. var chunk1 = s.substr(0, offset);
  2333. var chunk2 = s.substr(offset + remove);
  2334. return chunk1 + insert + chunk2;
  2335. }
  2336. var i, ii;
  2337. var canvas = document.createElement('canvas');
  2338. canvas.width = 1;
  2339. canvas.height = 1;
  2340. var ctx = canvas.getContext('2d');
  2341. var called = 0;
  2342. function isFontReady(name, callback) {
  2343. called++;
  2344. // With setTimeout clamping this gives the font ~100ms to load.
  2345. if(called > 30) {
  2346. warn('Load test font never loaded.');
  2347. callback();
  2348. return;
  2349. }
  2350. ctx.font = '30px ' + name;
  2351. ctx.fillText('.', 0, 20);
  2352. var imageData = ctx.getImageData(0, 0, 1, 1);
  2353. if (imageData.data[3] > 0) {
  2354. callback();
  2355. return;
  2356. }
  2357. setTimeout(isFontReady.bind(null, name, callback));
  2358. }
  2359. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  2360. // Chromium seems to cache fonts based on a hash of the actual font data,
  2361. // so the font must be modified for each load test else it will appear to
  2362. // be loaded already.
  2363. // TODO: This could maybe be made faster by avoiding the btoa of the full
  2364. // font by splitting it in chunks before hand and padding the font id.
  2365. var data = this.loadTestFont;
  2366. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  2367. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  2368. loadTestFontId);
  2369. // CFF checksum is important for IE, adjusting it
  2370. var CFF_CHECKSUM_OFFSET = 16;
  2371. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  2372. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  2373. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  2374. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  2375. }
  2376. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  2377. checksum = (checksum - XXXX_VALUE +
  2378. int32(loadTestFontId + 'XXX', i)) | 0;
  2379. }
  2380. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  2381. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  2382. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  2383. url + '}';
  2384. this.insertRule(rule);
  2385. var names = [];
  2386. for (i = 0, ii = fonts.length; i < ii; i++) {
  2387. names.push(fonts[i].loadedName);
  2388. }
  2389. names.push(loadTestFontId);
  2390. var div = document.createElement('div');
  2391. div.setAttribute('style',
  2392. 'visibility: hidden;' +
  2393. 'width: 10px; height: 10px;' +
  2394. 'position: absolute; top: 0px; left: 0px;');
  2395. for (i = 0, ii = names.length; i < ii; ++i) {
  2396. var span = document.createElement('span');
  2397. span.textContent = 'Hi';
  2398. span.style.fontFamily = names[i];
  2399. div.appendChild(span);
  2400. }
  2401. document.body.appendChild(div);
  2402. isFontReady(loadTestFontId, function() {
  2403. document.body.removeChild(div);
  2404. request.complete();
  2405. });
  2406. /** Hack end */
  2407. }
  2408. };
  2409. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  2410. typeof document !== 'undefined' && !!document.fonts);
  2411. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  2412. get: function () {
  2413. var supported = false;
  2414. // User agent string sniffing is bad, but there is no reliable way to tell
  2415. // if font is fully loaded and ready to be used with canvas.
  2416. var userAgent = window.navigator.userAgent;
  2417. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  2418. if (m && m[1] >= 14) {
  2419. supported = true;
  2420. }
  2421. // TODO other browsers
  2422. if (userAgent === 'node') {
  2423. supported = true;
  2424. }
  2425. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  2426. },
  2427. enumerable: true,
  2428. configurable: true
  2429. });
  2430. var FontFaceObject = (function FontFaceObjectClosure() {
  2431. function FontFaceObject(translatedData) {
  2432. this.compiledGlyphs = {};
  2433. // importing translated data
  2434. for (var i in translatedData) {
  2435. this[i] = translatedData[i];
  2436. }
  2437. }
  2438. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  2439. get: function () {
  2440. var evalSupport = false;
  2441. if (PDFJS.isEvalSupported) {
  2442. try {
  2443. /* jshint evil: true */
  2444. new Function('');
  2445. evalSupport = true;
  2446. } catch (e) {}
  2447. }
  2448. return shadow(this, 'isEvalSupported', evalSupport);
  2449. },
  2450. enumerable: true,
  2451. configurable: true
  2452. });
  2453. FontFaceObject.prototype = {
  2454. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  2455. if (!this.data) {
  2456. return null;
  2457. }
  2458. if (PDFJS.disableFontFace) {
  2459. this.disableFontFace = true;
  2460. return null;
  2461. }
  2462. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  2463. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  2464. globalScope['FontInspector'].enabled) {
  2465. globalScope['FontInspector'].fontAdded(this);
  2466. }
  2467. return nativeFontFace;
  2468. },
  2469. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  2470. if (!this.data) {
  2471. return null;
  2472. }
  2473. if (PDFJS.disableFontFace) {
  2474. this.disableFontFace = true;
  2475. return null;
  2476. }
  2477. var data = bytesToString(new Uint8Array(this.data));
  2478. var fontName = this.loadedName;
  2479. // Add the font-face rule to the document
  2480. var url = ('url(data:' + this.mimetype + ';base64,' +
  2481. window.btoa(data) + ');');
  2482. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  2483. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  2484. globalScope['FontInspector'].enabled) {
  2485. globalScope['FontInspector'].fontAdded(this, url);
  2486. }
  2487. return rule;
  2488. },
  2489. getPathGenerator:
  2490. function FontFaceObject_getPathGenerator(objs, character) {
  2491. if (!(character in this.compiledGlyphs)) {
  2492. var cmds = objs.get(this.loadedName + '_path_' + character);
  2493. var current, i, len;
  2494. // If we can, compile cmds into JS for MAXIMUM SPEED
  2495. if (FontFaceObject.isEvalSupported) {
  2496. var args, js = '';
  2497. for (i = 0, len = cmds.length; i < len; i++) {
  2498. current = cmds[i];
  2499. if (current.args !== undefined) {
  2500. args = current.args.join(',');
  2501. } else {
  2502. args = '';
  2503. }
  2504. js += 'c.' + current.cmd + '(' + args + ');\n';
  2505. }
  2506. /* jshint -W054 */
  2507. this.compiledGlyphs[character] = new Function('c', 'size', js);
  2508. } else {
  2509. // But fall back on using Function.prototype.apply() if we're
  2510. // blocked from using eval() for whatever reason (like CSP policies)
  2511. this.compiledGlyphs[character] = function(c, size) {
  2512. for (i = 0, len = cmds.length; i < len; i++) {
  2513. current = cmds[i];
  2514. if (current.cmd === 'scale') {
  2515. current.args = [size, -size];
  2516. }
  2517. c[current.cmd].apply(c, current.args);
  2518. }
  2519. };
  2520. }
  2521. }
  2522. return this.compiledGlyphs[character];
  2523. }
  2524. };
  2525. return FontFaceObject;
  2526. })();
  2527. exports.FontFaceObject = FontFaceObject;
  2528. exports.FontLoader = FontLoader;
  2529. }));
  2530. (function (root, factory) {
  2531. {
  2532. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  2533. }
  2534. }(this, function (exports, sharedUtil) {
  2535. var error = sharedUtil.error;
  2536. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2537. function fixMetadata(meta) {
  2538. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2539. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2540. function(code, d1, d2, d3) {
  2541. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2542. });
  2543. var chars = '';
  2544. for (var i = 0; i < bytes.length; i += 2) {
  2545. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2546. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2547. code !== 38 && false ? String.fromCharCode(code) :
  2548. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2549. }
  2550. return '>' + chars;
  2551. });
  2552. }
  2553. function Metadata(meta) {
  2554. if (typeof meta === 'string') {
  2555. // Ghostscript produces invalid metadata
  2556. meta = fixMetadata(meta);
  2557. var parser = new DOMParser();
  2558. meta = parser.parseFromString(meta, 'application/xml');
  2559. } else if (!(meta instanceof Document)) {
  2560. error('Metadata: Invalid metadata object');
  2561. }
  2562. this.metaDocument = meta;
  2563. this.metadata = {};
  2564. this.parse();
  2565. }
  2566. Metadata.prototype = {
  2567. parse: function Metadata_parse() {
  2568. var doc = this.metaDocument;
  2569. var rdf = doc.documentElement;
  2570. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2571. rdf = rdf.firstChild;
  2572. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2573. rdf = rdf.nextSibling;
  2574. }
  2575. }
  2576. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2577. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2578. return;
  2579. }
  2580. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2581. for (i = 0, length = children.length; i < length; i++) {
  2582. desc = children[i];
  2583. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2584. continue;
  2585. }
  2586. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2587. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2588. entry = desc.childNodes[ii];
  2589. name = entry.nodeName.toLowerCase();
  2590. this.metadata[name] = entry.textContent.trim();
  2591. }
  2592. }
  2593. }
  2594. },
  2595. get: function Metadata_get(name) {
  2596. return this.metadata[name] || null;
  2597. },
  2598. has: function Metadata_has(name) {
  2599. return typeof this.metadata[name] !== 'undefined';
  2600. }
  2601. };
  2602. return Metadata;
  2603. })();
  2604. exports.Metadata = Metadata;
  2605. }));
  2606. (function (root, factory) {
  2607. {
  2608. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil);
  2609. }
  2610. }(this, function (exports, sharedUtil) {
  2611. var createPromiseCapability = sharedUtil.createPromiseCapability;
  2612. /**
  2613. * Text layer render parameters.
  2614. *
  2615. * @typedef {Object} TextLayerRenderParameters
  2616. * @property {TextContent} textContent - Text content to render (the object is
  2617. * returned by the page's getTextContent() method).
  2618. * @property {HTMLElement} container - HTML element that will contain text runs.
  2619. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  2620. * layout the text runs.
  2621. * @property {Array} textDivs - (optional) HTML elements that are correspond
  2622. * the text items of the textContent input. This is output and shall be
  2623. * initially be set to empty array.
  2624. * @property {number} timeout - (optional) Delay in milliseconds before
  2625. * rendering of the text runs occurs.
  2626. */
  2627. var renderTextLayer = (function renderTextLayerClosure() {
  2628. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  2629. var NonWhitespaceRegexp = /\S/;
  2630. function isAllWhitespace(str) {
  2631. return !NonWhitespaceRegexp.test(str);
  2632. }
  2633. function appendText(textDivs, viewport, geom, styles) {
  2634. var style = styles[geom.fontName];
  2635. var textDiv = document.createElement('div');
  2636. textDivs.push(textDiv);
  2637. if (isAllWhitespace(geom.str)) {
  2638. textDiv.dataset.isWhitespace = true;
  2639. return;
  2640. }
  2641. var tx = PDFJS.Util.transform(viewport.transform, geom.transform);
  2642. var angle = Math.atan2(tx[1], tx[0]);
  2643. if (style.vertical) {
  2644. angle += Math.PI / 2;
  2645. }
  2646. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  2647. var fontAscent = fontHeight;
  2648. if (style.ascent) {
  2649. fontAscent = style.ascent * fontAscent;
  2650. } else if (style.descent) {
  2651. fontAscent = (1 + style.descent) * fontAscent;
  2652. }
  2653. var left;
  2654. var top;
  2655. if (angle === 0) {
  2656. left = tx[4];
  2657. top = tx[5] - fontAscent;
  2658. } else {
  2659. left = tx[4] + (fontAscent * Math.sin(angle));
  2660. top = tx[5] - (fontAscent * Math.cos(angle));
  2661. }
  2662. textDiv.style.left = left + 'px';
  2663. textDiv.style.top = top + 'px';
  2664. textDiv.style.fontSize = fontHeight + 'px';
  2665. textDiv.style.fontFamily = style.fontFamily;
  2666. textDiv.textContent = geom.str;
  2667. // |fontName| is only used by the Font Inspector. This test will succeed
  2668. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  2669. // not worth the effort to do a more accurate test.
  2670. if (PDFJS.pdfBug) {
  2671. textDiv.dataset.fontName = geom.fontName;
  2672. }
  2673. // Storing into dataset will convert number into string.
  2674. if (angle !== 0) {
  2675. textDiv.dataset.angle = angle * (180 / Math.PI);
  2676. }
  2677. // We don't bother scaling single-char text divs, because it has very
  2678. // little effect on text highlighting. This makes scrolling on docs with
  2679. // lots of such divs a lot faster.
  2680. if (geom.str.length > 1) {
  2681. if (style.vertical) {
  2682. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  2683. } else {
  2684. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  2685. }
  2686. }
  2687. }
  2688. function render(task) {
  2689. if (task._canceled) {
  2690. return;
  2691. }
  2692. var textLayerFrag = task._container;
  2693. var textDivs = task._textDivs;
  2694. var capability = task._capability;
  2695. var textDivsLength = textDivs.length;
  2696. // No point in rendering many divs as it would make the browser
  2697. // unusable even after the divs are rendered.
  2698. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  2699. capability.resolve();
  2700. return;
  2701. }
  2702. var canvas = document.createElement('canvas');
  2703. var ctx = canvas.getContext('2d', {alpha: false});
  2704. var lastFontSize;
  2705. var lastFontFamily;
  2706. for (var i = 0; i < textDivsLength; i++) {
  2707. var textDiv = textDivs[i];
  2708. if (textDiv.dataset.isWhitespace !== undefined) {
  2709. continue;
  2710. }
  2711. var fontSize = textDiv.style.fontSize;
  2712. var fontFamily = textDiv.style.fontFamily;
  2713. // Only build font string and set to context if different from last.
  2714. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  2715. ctx.font = fontSize + ' ' + fontFamily;
  2716. lastFontSize = fontSize;
  2717. lastFontFamily = fontFamily;
  2718. }
  2719. var width = ctx.measureText(textDiv.textContent).width;
  2720. if (width > 0) {
  2721. textLayerFrag.appendChild(textDiv);
  2722. var transform;
  2723. if (textDiv.dataset.canvasWidth !== undefined) {
  2724. // Dataset values come of type string.
  2725. var textScale = textDiv.dataset.canvasWidth / width;
  2726. transform = 'scaleX(' + textScale + ')';
  2727. } else {
  2728. transform = '';
  2729. }
  2730. var rotation = textDiv.dataset.angle;
  2731. if (rotation) {
  2732. transform = 'rotate(' + rotation + 'deg) ' + transform;
  2733. }
  2734. if (transform) {
  2735. PDFJS.CustomStyle.setProp('transform' , textDiv, transform);
  2736. }
  2737. }
  2738. }
  2739. capability.resolve();
  2740. }
  2741. /**
  2742. * Text layer rendering task.
  2743. *
  2744. * @param {TextContent} textContent
  2745. * @param {HTMLElement} container
  2746. * @param {PDFJS.PageViewport} viewport
  2747. * @param {Array} textDivs
  2748. * @private
  2749. */
  2750. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  2751. this._textContent = textContent;
  2752. this._container = container;
  2753. this._viewport = viewport;
  2754. textDivs = textDivs || [];
  2755. this._textDivs = textDivs;
  2756. this._canceled = false;
  2757. this._capability = createPromiseCapability();
  2758. this._renderTimer = null;
  2759. }
  2760. TextLayerRenderTask.prototype = {
  2761. get promise() {
  2762. return this._capability.promise;
  2763. },
  2764. cancel: function TextLayer_cancel() {
  2765. this._canceled = true;
  2766. if (this._renderTimer !== null) {
  2767. clearTimeout(this._renderTimer);
  2768. this._renderTimer = null;
  2769. }
  2770. this._capability.reject('canceled');
  2771. },
  2772. _render: function TextLayer_render(timeout) {
  2773. var textItems = this._textContent.items;
  2774. var styles = this._textContent.styles;
  2775. var textDivs = this._textDivs;
  2776. var viewport = this._viewport;
  2777. for (var i = 0, len = textItems.length; i < len; i++) {
  2778. appendText(textDivs, viewport, textItems[i], styles);
  2779. }
  2780. if (!timeout) { // Render right away
  2781. render(this);
  2782. } else { // Schedule
  2783. var self = this;
  2784. this._renderTimer = setTimeout(function() {
  2785. render(self);
  2786. self._renderTimer = null;
  2787. }, timeout);
  2788. }
  2789. }
  2790. };
  2791. /**
  2792. * Starts rendering of the text layer.
  2793. *
  2794. * @param {TextLayerRenderParameters} renderParameters
  2795. * @returns {TextLayerRenderTask}
  2796. */
  2797. function renderTextLayer(renderParameters) {
  2798. var task = new TextLayerRenderTask(renderParameters.textContent,
  2799. renderParameters.container,
  2800. renderParameters.viewport,
  2801. renderParameters.textDivs);
  2802. task._render(renderParameters.timeout);
  2803. return task;
  2804. }
  2805. return renderTextLayer;
  2806. })();
  2807. PDFJS.renderTextLayer = renderTextLayer;
  2808. exports.renderTextLayer = renderTextLayer;
  2809. }));
  2810. (function (root, factory) {
  2811. {
  2812. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  2813. }
  2814. }(this, function (exports, sharedUtil) {
  2815. var shadow = sharedUtil.shadow;
  2816. var WebGLUtils = (function WebGLUtilsClosure() {
  2817. function loadShader(gl, code, shaderType) {
  2818. var shader = gl.createShader(shaderType);
  2819. gl.shaderSource(shader, code);
  2820. gl.compileShader(shader);
  2821. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  2822. if (!compiled) {
  2823. var errorMsg = gl.getShaderInfoLog(shader);
  2824. throw new Error('Error during shader compilation: ' + errorMsg);
  2825. }
  2826. return shader;
  2827. }
  2828. function createVertexShader(gl, code) {
  2829. return loadShader(gl, code, gl.VERTEX_SHADER);
  2830. }
  2831. function createFragmentShader(gl, code) {
  2832. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  2833. }
  2834. function createProgram(gl, shaders) {
  2835. var program = gl.createProgram();
  2836. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  2837. gl.attachShader(program, shaders[i]);
  2838. }
  2839. gl.linkProgram(program);
  2840. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  2841. if (!linked) {
  2842. var errorMsg = gl.getProgramInfoLog(program);
  2843. throw new Error('Error during program linking: ' + errorMsg);
  2844. }
  2845. return program;
  2846. }
  2847. function createTexture(gl, image, textureId) {
  2848. gl.activeTexture(textureId);
  2849. var texture = gl.createTexture();
  2850. gl.bindTexture(gl.TEXTURE_2D, texture);
  2851. // Set the parameters so we can render any size image.
  2852. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  2853. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  2854. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  2855. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  2856. // Upload the image into the texture.
  2857. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  2858. return texture;
  2859. }
  2860. var currentGL, currentCanvas;
  2861. function generateGL() {
  2862. if (currentGL) {
  2863. return;
  2864. }
  2865. currentCanvas = document.createElement('canvas');
  2866. currentGL = currentCanvas.getContext('webgl',
  2867. { premultipliedalpha: false });
  2868. }
  2869. var smaskVertexShaderCode = '\
  2870. attribute vec2 a_position; \
  2871. attribute vec2 a_texCoord; \
  2872. \
  2873. uniform vec2 u_resolution; \
  2874. \
  2875. varying vec2 v_texCoord; \
  2876. \
  2877. void main() { \
  2878. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  2879. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  2880. \
  2881. v_texCoord = a_texCoord; \
  2882. } ';
  2883. var smaskFragmentShaderCode = '\
  2884. precision mediump float; \
  2885. \
  2886. uniform vec4 u_backdrop; \
  2887. uniform int u_subtype; \
  2888. uniform sampler2D u_image; \
  2889. uniform sampler2D u_mask; \
  2890. \
  2891. varying vec2 v_texCoord; \
  2892. \
  2893. void main() { \
  2894. vec4 imageColor = texture2D(u_image, v_texCoord); \
  2895. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  2896. if (u_backdrop.a > 0.0) { \
  2897. maskColor.rgb = maskColor.rgb * maskColor.a + \
  2898. u_backdrop.rgb * (1.0 - maskColor.a); \
  2899. } \
  2900. float lum; \
  2901. if (u_subtype == 0) { \
  2902. lum = maskColor.a; \
  2903. } else { \
  2904. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  2905. maskColor.b * 0.11; \
  2906. } \
  2907. imageColor.a *= lum; \
  2908. imageColor.rgb *= imageColor.a; \
  2909. gl_FragColor = imageColor; \
  2910. } ';
  2911. var smaskCache = null;
  2912. function initSmaskGL() {
  2913. var canvas, gl;
  2914. generateGL();
  2915. canvas = currentCanvas;
  2916. currentCanvas = null;
  2917. gl = currentGL;
  2918. currentGL = null;
  2919. // setup a GLSL program
  2920. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  2921. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  2922. var program = createProgram(gl, [vertexShader, fragmentShader]);
  2923. gl.useProgram(program);
  2924. var cache = {};
  2925. cache.gl = gl;
  2926. cache.canvas = canvas;
  2927. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  2928. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  2929. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  2930. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  2931. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  2932. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  2933. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  2934. // provide texture coordinates for the rectangle.
  2935. var texCoordBuffer = gl.createBuffer();
  2936. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  2937. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  2938. 0.0, 0.0,
  2939. 1.0, 0.0,
  2940. 0.0, 1.0,
  2941. 0.0, 1.0,
  2942. 1.0, 0.0,
  2943. 1.0, 1.0]), gl.STATIC_DRAW);
  2944. gl.enableVertexAttribArray(texCoordLocation);
  2945. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  2946. gl.uniform1i(texLayerLocation, 0);
  2947. gl.uniform1i(texMaskLocation, 1);
  2948. smaskCache = cache;
  2949. }
  2950. function composeSMask(layer, mask, properties) {
  2951. var width = layer.width, height = layer.height;
  2952. if (!smaskCache) {
  2953. initSmaskGL();
  2954. }
  2955. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  2956. canvas.width = width;
  2957. canvas.height = height;
  2958. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  2959. gl.uniform2f(cache.resolutionLocation, width, height);
  2960. if (properties.backdrop) {
  2961. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  2962. properties.backdrop[1], properties.backdrop[2], 1);
  2963. } else {
  2964. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  2965. }
  2966. gl.uniform1i(cache.subtypeLocation,
  2967. properties.subtype === 'Luminosity' ? 1 : 0);
  2968. // Create a textures
  2969. var texture = createTexture(gl, layer, gl.TEXTURE0);
  2970. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  2971. // Create a buffer and put a single clipspace rectangle in
  2972. // it (2 triangles)
  2973. var buffer = gl.createBuffer();
  2974. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  2975. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  2976. 0, 0,
  2977. width, 0,
  2978. 0, height,
  2979. 0, height,
  2980. width, 0,
  2981. width, height]), gl.STATIC_DRAW);
  2982. gl.enableVertexAttribArray(cache.positionLocation);
  2983. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  2984. // draw
  2985. gl.clearColor(0, 0, 0, 0);
  2986. gl.enable(gl.BLEND);
  2987. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2988. gl.clear(gl.COLOR_BUFFER_BIT);
  2989. gl.drawArrays(gl.TRIANGLES, 0, 6);
  2990. gl.flush();
  2991. gl.deleteTexture(texture);
  2992. gl.deleteTexture(maskTexture);
  2993. gl.deleteBuffer(buffer);
  2994. return canvas;
  2995. }
  2996. var figuresVertexShaderCode = '\
  2997. attribute vec2 a_position; \
  2998. attribute vec3 a_color; \
  2999. \
  3000. uniform vec2 u_resolution; \
  3001. uniform vec2 u_scale; \
  3002. uniform vec2 u_offset; \
  3003. \
  3004. varying vec4 v_color; \
  3005. \
  3006. void main() { \
  3007. vec2 position = (a_position + u_offset) * u_scale; \
  3008. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  3009. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  3010. \
  3011. v_color = vec4(a_color / 255.0, 1.0); \
  3012. } ';
  3013. var figuresFragmentShaderCode = '\
  3014. precision mediump float; \
  3015. \
  3016. varying vec4 v_color; \
  3017. \
  3018. void main() { \
  3019. gl_FragColor = v_color; \
  3020. } ';
  3021. var figuresCache = null;
  3022. function initFiguresGL() {
  3023. var canvas, gl;
  3024. generateGL();
  3025. canvas = currentCanvas;
  3026. currentCanvas = null;
  3027. gl = currentGL;
  3028. currentGL = null;
  3029. // setup a GLSL program
  3030. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  3031. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  3032. var program = createProgram(gl, [vertexShader, fragmentShader]);
  3033. gl.useProgram(program);
  3034. var cache = {};
  3035. cache.gl = gl;
  3036. cache.canvas = canvas;
  3037. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  3038. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  3039. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  3040. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  3041. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  3042. figuresCache = cache;
  3043. }
  3044. function drawFigures(width, height, backgroundColor, figures, context) {
  3045. if (!figuresCache) {
  3046. initFiguresGL();
  3047. }
  3048. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  3049. canvas.width = width;
  3050. canvas.height = height;
  3051. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  3052. gl.uniform2f(cache.resolutionLocation, width, height);
  3053. // count triangle points
  3054. var count = 0;
  3055. var i, ii, rows;
  3056. for (i = 0, ii = figures.length; i < ii; i++) {
  3057. switch (figures[i].type) {
  3058. case 'lattice':
  3059. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  3060. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  3061. break;
  3062. case 'triangles':
  3063. count += figures[i].coords.length;
  3064. break;
  3065. }
  3066. }
  3067. // transfer data
  3068. var coords = new Float32Array(count * 2);
  3069. var colors = new Uint8Array(count * 3);
  3070. var coordsMap = context.coords, colorsMap = context.colors;
  3071. var pIndex = 0, cIndex = 0;
  3072. for (i = 0, ii = figures.length; i < ii; i++) {
  3073. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  3074. switch (figure.type) {
  3075. case 'lattice':
  3076. var cols = figure.verticesPerRow;
  3077. rows = (ps.length / cols) | 0;
  3078. for (var row = 1; row < rows; row++) {
  3079. var offset = row * cols + 1;
  3080. for (var col = 1; col < cols; col++, offset++) {
  3081. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  3082. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  3083. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  3084. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  3085. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  3086. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  3087. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  3088. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  3089. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  3090. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  3091. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  3092. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  3093. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  3094. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  3095. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  3096. coords[pIndex + 6] = coords[pIndex + 2];
  3097. coords[pIndex + 7] = coords[pIndex + 3];
  3098. coords[pIndex + 8] = coords[pIndex + 4];
  3099. coords[pIndex + 9] = coords[pIndex + 5];
  3100. coords[pIndex + 10] = coordsMap[ps[offset]];
  3101. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  3102. colors[cIndex + 9] = colors[cIndex + 3];
  3103. colors[cIndex + 10] = colors[cIndex + 4];
  3104. colors[cIndex + 11] = colors[cIndex + 5];
  3105. colors[cIndex + 12] = colors[cIndex + 6];
  3106. colors[cIndex + 13] = colors[cIndex + 7];
  3107. colors[cIndex + 14] = colors[cIndex + 8];
  3108. colors[cIndex + 15] = colorsMap[cs[offset]];
  3109. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  3110. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  3111. pIndex += 12;
  3112. cIndex += 18;
  3113. }
  3114. }
  3115. break;
  3116. case 'triangles':
  3117. for (var j = 0, jj = ps.length; j < jj; j++) {
  3118. coords[pIndex] = coordsMap[ps[j]];
  3119. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  3120. colors[cIndex] = colorsMap[cs[j]];
  3121. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  3122. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  3123. pIndex += 2;
  3124. cIndex += 3;
  3125. }
  3126. break;
  3127. }
  3128. }
  3129. // draw
  3130. if (backgroundColor) {
  3131. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  3132. backgroundColor[2] / 255, 1.0);
  3133. } else {
  3134. gl.clearColor(0, 0, 0, 0);
  3135. }
  3136. gl.clear(gl.COLOR_BUFFER_BIT);
  3137. var coordsBuffer = gl.createBuffer();
  3138. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  3139. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  3140. gl.enableVertexAttribArray(cache.positionLocation);
  3141. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  3142. var colorsBuffer = gl.createBuffer();
  3143. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  3144. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  3145. gl.enableVertexAttribArray(cache.colorLocation);
  3146. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  3147. 0, 0);
  3148. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  3149. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  3150. gl.drawArrays(gl.TRIANGLES, 0, count);
  3151. gl.flush();
  3152. gl.deleteBuffer(coordsBuffer);
  3153. gl.deleteBuffer(colorsBuffer);
  3154. return canvas;
  3155. }
  3156. function cleanup() {
  3157. if (smaskCache && smaskCache.canvas) {
  3158. smaskCache.canvas.width = 0;
  3159. smaskCache.canvas.height = 0;
  3160. }
  3161. if (figuresCache && figuresCache.canvas) {
  3162. figuresCache.canvas.width = 0;
  3163. figuresCache.canvas.height = 0;
  3164. }
  3165. smaskCache = null;
  3166. figuresCache = null;
  3167. }
  3168. return {
  3169. get isEnabled() {
  3170. if (PDFJS.disableWebGL) {
  3171. return false;
  3172. }
  3173. var enabled = false;
  3174. try {
  3175. generateGL();
  3176. enabled = !!currentGL;
  3177. } catch (e) { }
  3178. return shadow(this, 'isEnabled', enabled);
  3179. },
  3180. composeSMask: composeSMask,
  3181. drawFigures: drawFigures,
  3182. clear: cleanup
  3183. };
  3184. })();
  3185. exports.WebGLUtils = WebGLUtils;
  3186. }));
  3187. (function (root, factory) {
  3188. {
  3189. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  3190. root.pdfjsDisplayWebGL);
  3191. }
  3192. }(this, function (exports, sharedUtil, displayWebGL) {
  3193. var Util = sharedUtil.Util;
  3194. var info = sharedUtil.info;
  3195. var isArray = sharedUtil.isArray;
  3196. var error = sharedUtil.error;
  3197. var WebGLUtils = displayWebGL.WebGLUtils;
  3198. var ShadingIRs = {};
  3199. ShadingIRs.RadialAxial = {
  3200. fromIR: function RadialAxial_fromIR(raw) {
  3201. var type = raw[1];
  3202. var colorStops = raw[2];
  3203. var p0 = raw[3];
  3204. var p1 = raw[4];
  3205. var r0 = raw[5];
  3206. var r1 = raw[6];
  3207. return {
  3208. type: 'Pattern',
  3209. getPattern: function RadialAxial_getPattern(ctx) {
  3210. var grad;
  3211. if (type === 'axial') {
  3212. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  3213. } else if (type === 'radial') {
  3214. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  3215. }
  3216. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  3217. var c = colorStops[i];
  3218. grad.addColorStop(c[0], c[1]);
  3219. }
  3220. return grad;
  3221. }
  3222. };
  3223. }
  3224. };
  3225. var createMeshCanvas = (function createMeshCanvasClosure() {
  3226. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  3227. // Very basic Gouraud-shaded triangle rasterization algorithm.
  3228. var coords = context.coords, colors = context.colors;
  3229. var bytes = data.data, rowSize = data.width * 4;
  3230. var tmp;
  3231. if (coords[p1 + 1] > coords[p2 + 1]) {
  3232. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  3233. }
  3234. if (coords[p2 + 1] > coords[p3 + 1]) {
  3235. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  3236. }
  3237. if (coords[p1 + 1] > coords[p2 + 1]) {
  3238. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  3239. }
  3240. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  3241. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  3242. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  3243. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  3244. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  3245. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  3246. if (y1 >= y3) {
  3247. return;
  3248. }
  3249. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  3250. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  3251. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  3252. var minY = Math.round(y1), maxY = Math.round(y3);
  3253. var xa, car, cag, cab;
  3254. var xb, cbr, cbg, cbb;
  3255. var k;
  3256. for (var y = minY; y <= maxY; y++) {
  3257. if (y < y2) {
  3258. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  3259. xa = x1 - (x1 - x2) * k;
  3260. car = c1r - (c1r - c2r) * k;
  3261. cag = c1g - (c1g - c2g) * k;
  3262. cab = c1b - (c1b - c2b) * k;
  3263. } else {
  3264. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  3265. xa = x2 - (x2 - x3) * k;
  3266. car = c2r - (c2r - c3r) * k;
  3267. cag = c2g - (c2g - c3g) * k;
  3268. cab = c2b - (c2b - c3b) * k;
  3269. }
  3270. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  3271. xb = x1 - (x1 - x3) * k;
  3272. cbr = c1r - (c1r - c3r) * k;
  3273. cbg = c1g - (c1g - c3g) * k;
  3274. cbb = c1b - (c1b - c3b) * k;
  3275. var x1_ = Math.round(Math.min(xa, xb));
  3276. var x2_ = Math.round(Math.max(xa, xb));
  3277. var j = rowSize * y + x1_ * 4;
  3278. for (var x = x1_; x <= x2_; x++) {
  3279. k = (xa - x) / (xa - xb);
  3280. k = k < 0 ? 0 : k > 1 ? 1 : k;
  3281. bytes[j++] = (car - (car - cbr) * k) | 0;
  3282. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  3283. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  3284. bytes[j++] = 255;
  3285. }
  3286. }
  3287. }
  3288. function drawFigure(data, figure, context) {
  3289. var ps = figure.coords;
  3290. var cs = figure.colors;
  3291. var i, ii;
  3292. switch (figure.type) {
  3293. case 'lattice':
  3294. var verticesPerRow = figure.verticesPerRow;
  3295. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  3296. var cols = verticesPerRow - 1;
  3297. for (i = 0; i < rows; i++) {
  3298. var q = i * verticesPerRow;
  3299. for (var j = 0; j < cols; j++, q++) {
  3300. drawTriangle(data, context,
  3301. ps[q], ps[q + 1], ps[q + verticesPerRow],
  3302. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  3303. drawTriangle(data, context,
  3304. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  3305. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  3306. }
  3307. }
  3308. break;
  3309. case 'triangles':
  3310. for (i = 0, ii = ps.length; i < ii; i += 3) {
  3311. drawTriangle(data, context,
  3312. ps[i], ps[i + 1], ps[i + 2],
  3313. cs[i], cs[i + 1], cs[i + 2]);
  3314. }
  3315. break;
  3316. default:
  3317. error('illigal figure');
  3318. break;
  3319. }
  3320. }
  3321. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  3322. backgroundColor, cachedCanvases) {
  3323. // we will increase scale on some weird factor to let antialiasing take
  3324. // care of "rough" edges
  3325. var EXPECTED_SCALE = 1.1;
  3326. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  3327. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  3328. var offsetX = Math.floor(bounds[0]);
  3329. var offsetY = Math.floor(bounds[1]);
  3330. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  3331. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  3332. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  3333. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  3334. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  3335. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  3336. var scaleX = boundsWidth / width;
  3337. var scaleY = boundsHeight / height;
  3338. var context = {
  3339. coords: coords,
  3340. colors: colors,
  3341. offsetX: -offsetX,
  3342. offsetY: -offsetY,
  3343. scaleX: 1 / scaleX,
  3344. scaleY: 1 / scaleY
  3345. };
  3346. var canvas, tmpCanvas, i, ii;
  3347. if (WebGLUtils.isEnabled) {
  3348. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  3349. figures, context);
  3350. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  3351. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  3352. tmpCanvas.context.drawImage(canvas, 0, 0);
  3353. canvas = tmpCanvas.canvas;
  3354. } else {
  3355. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  3356. var tmpCtx = tmpCanvas.context;
  3357. var data = tmpCtx.createImageData(width, height);
  3358. if (backgroundColor) {
  3359. var bytes = data.data;
  3360. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  3361. bytes[i] = backgroundColor[0];
  3362. bytes[i + 1] = backgroundColor[1];
  3363. bytes[i + 2] = backgroundColor[2];
  3364. bytes[i + 3] = 255;
  3365. }
  3366. }
  3367. for (i = 0; i < figures.length; i++) {
  3368. drawFigure(data, figures[i], context);
  3369. }
  3370. tmpCtx.putImageData(data, 0, 0);
  3371. canvas = tmpCanvas.canvas;
  3372. }
  3373. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  3374. scaleX: scaleX, scaleY: scaleY};
  3375. }
  3376. return createMeshCanvas;
  3377. })();
  3378. ShadingIRs.Mesh = {
  3379. fromIR: function Mesh_fromIR(raw) {
  3380. //var type = raw[1];
  3381. var coords = raw[2];
  3382. var colors = raw[3];
  3383. var figures = raw[4];
  3384. var bounds = raw[5];
  3385. var matrix = raw[6];
  3386. //var bbox = raw[7];
  3387. var background = raw[8];
  3388. return {
  3389. type: 'Pattern',
  3390. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  3391. var scale;
  3392. if (shadingFill) {
  3393. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  3394. } else {
  3395. // Obtain scale from matrix and current transformation matrix.
  3396. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  3397. if (matrix) {
  3398. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  3399. scale = [scale[0] * matrixScale[0],
  3400. scale[1] * matrixScale[1]];
  3401. }
  3402. }
  3403. // Rasterizing on the main thread since sending/queue large canvases
  3404. // might cause OOM.
  3405. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  3406. colors, figures, shadingFill ? null : background,
  3407. owner.cachedCanvases);
  3408. if (!shadingFill) {
  3409. ctx.setTransform.apply(ctx, owner.baseTransform);
  3410. if (matrix) {
  3411. ctx.transform.apply(ctx, matrix);
  3412. }
  3413. }
  3414. ctx.translate(temporaryPatternCanvas.offsetX,
  3415. temporaryPatternCanvas.offsetY);
  3416. ctx.scale(temporaryPatternCanvas.scaleX,
  3417. temporaryPatternCanvas.scaleY);
  3418. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  3419. }
  3420. };
  3421. }
  3422. };
  3423. ShadingIRs.Dummy = {
  3424. fromIR: function Dummy_fromIR() {
  3425. return {
  3426. type: 'Pattern',
  3427. getPattern: function Dummy_fromIR_getPattern() {
  3428. return 'hotpink';
  3429. }
  3430. };
  3431. }
  3432. };
  3433. function getShadingPatternFromIR(raw) {
  3434. var shadingIR = ShadingIRs[raw[0]];
  3435. if (!shadingIR) {
  3436. error('Unknown IR type: ' + raw[0]);
  3437. }
  3438. return shadingIR.fromIR(raw);
  3439. }
  3440. var TilingPattern = (function TilingPatternClosure() {
  3441. var PaintType = {
  3442. COLORED: 1,
  3443. UNCOLORED: 2
  3444. };
  3445. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  3446. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  3447. this.operatorList = IR[2];
  3448. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  3449. this.bbox = IR[4];
  3450. this.xstep = IR[5];
  3451. this.ystep = IR[6];
  3452. this.paintType = IR[7];
  3453. this.tilingType = IR[8];
  3454. this.color = color;
  3455. this.canvasGraphicsFactory = canvasGraphicsFactory;
  3456. this.baseTransform = baseTransform;
  3457. this.type = 'Pattern';
  3458. this.ctx = ctx;
  3459. }
  3460. TilingPattern.prototype = {
  3461. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  3462. var operatorList = this.operatorList;
  3463. var bbox = this.bbox;
  3464. var xstep = this.xstep;
  3465. var ystep = this.ystep;
  3466. var paintType = this.paintType;
  3467. var tilingType = this.tilingType;
  3468. var color = this.color;
  3469. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  3470. info('TilingType: ' + tilingType);
  3471. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  3472. var topLeft = [x0, y0];
  3473. // we want the canvas to be as large as the step size
  3474. var botRight = [x0 + xstep, y0 + ystep];
  3475. var width = botRight[0] - topLeft[0];
  3476. var height = botRight[1] - topLeft[1];
  3477. // Obtain scale from matrix and current transformation matrix.
  3478. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  3479. var curMatrixScale = Util.singularValueDecompose2dScale(
  3480. this.baseTransform);
  3481. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  3482. matrixScale[1] * curMatrixScale[1]];
  3483. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  3484. // Use width and height values that are as close as possible to the end
  3485. // result when the pattern is used. Too low value makes the pattern look
  3486. // blurry. Too large value makes it look too crispy.
  3487. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  3488. MAX_PATTERN_SIZE);
  3489. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  3490. MAX_PATTERN_SIZE);
  3491. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  3492. width, height, true);
  3493. var tmpCtx = tmpCanvas.context;
  3494. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  3495. graphics.groupLevel = owner.groupLevel;
  3496. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  3497. this.setScale(width, height, xstep, ystep);
  3498. this.transformToScale(graphics);
  3499. // transform coordinates to pattern space
  3500. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  3501. graphics.transform.apply(graphics, tmpTranslate);
  3502. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  3503. graphics.executeOperatorList(operatorList);
  3504. return tmpCanvas.canvas;
  3505. },
  3506. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  3507. this.scale = [width / xstep, height / ystep];
  3508. },
  3509. transformToScale: function TilingPattern_transformToScale(graphics) {
  3510. var scale = this.scale;
  3511. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  3512. graphics.transform.apply(graphics, tmpScale);
  3513. },
  3514. scaleToContext: function TilingPattern_scaleToContext() {
  3515. var scale = this.scale;
  3516. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  3517. },
  3518. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  3519. if (bbox && isArray(bbox) && bbox.length === 4) {
  3520. var bboxWidth = x1 - x0;
  3521. var bboxHeight = y1 - y0;
  3522. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  3523. graphics.clip();
  3524. graphics.endPath();
  3525. }
  3526. },
  3527. setFillAndStrokeStyleToContext:
  3528. function setFillAndStrokeStyleToContext(context, paintType, color) {
  3529. switch (paintType) {
  3530. case PaintType.COLORED:
  3531. var ctx = this.ctx;
  3532. context.fillStyle = ctx.fillStyle;
  3533. context.strokeStyle = ctx.strokeStyle;
  3534. break;
  3535. case PaintType.UNCOLORED:
  3536. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  3537. context.fillStyle = cssColor;
  3538. context.strokeStyle = cssColor;
  3539. break;
  3540. default:
  3541. error('Unsupported paint type: ' + paintType);
  3542. }
  3543. },
  3544. getPattern: function TilingPattern_getPattern(ctx, owner) {
  3545. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  3546. ctx = this.ctx;
  3547. ctx.setTransform.apply(ctx, this.baseTransform);
  3548. ctx.transform.apply(ctx, this.matrix);
  3549. this.scaleToContext();
  3550. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  3551. }
  3552. };
  3553. return TilingPattern;
  3554. })();
  3555. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  3556. exports.TilingPattern = TilingPattern;
  3557. }));
  3558. (function (root, factory) {
  3559. {
  3560. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  3561. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  3562. }
  3563. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  3564. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  3565. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  3566. var ImageKind = sharedUtil.ImageKind;
  3567. var OPS = sharedUtil.OPS;
  3568. var TextRenderingMode = sharedUtil.TextRenderingMode;
  3569. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  3570. var Util = sharedUtil.Util;
  3571. var assert = sharedUtil.assert;
  3572. var info = sharedUtil.info;
  3573. var isNum = sharedUtil.isNum;
  3574. var isArray = sharedUtil.isArray;
  3575. var error = sharedUtil.error;
  3576. var shadow = sharedUtil.shadow;
  3577. var warn = sharedUtil.warn;
  3578. var TilingPattern = displayPatternHelper.TilingPattern;
  3579. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  3580. var WebGLUtils = displayWebGL.WebGLUtils;
  3581. // <canvas> contexts store most of the state we need natively.
  3582. // However, PDF needs a bit more state, which we store here.
  3583. // Minimal font size that would be used during canvas fillText operations.
  3584. var MIN_FONT_SIZE = 16;
  3585. // Maximum font size that would be used during canvas fillText operations.
  3586. var MAX_FONT_SIZE = 100;
  3587. var MAX_GROUP_SIZE = 4096;
  3588. // Heuristic value used when enforcing minimum line widths.
  3589. var MIN_WIDTH_FACTOR = 0.65;
  3590. var COMPILE_TYPE3_GLYPHS = true;
  3591. var MAX_SIZE_TO_COMPILE = 1000;
  3592. var FULL_CHUNK_HEIGHT = 16;
  3593. function createScratchCanvas(width, height) {
  3594. var canvas = document.createElement('canvas');
  3595. canvas.width = width;
  3596. canvas.height = height;
  3597. return canvas;
  3598. }
  3599. function addContextCurrentTransform(ctx) {
  3600. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  3601. if (!ctx.mozCurrentTransform) {
  3602. ctx._originalSave = ctx.save;
  3603. ctx._originalRestore = ctx.restore;
  3604. ctx._originalRotate = ctx.rotate;
  3605. ctx._originalScale = ctx.scale;
  3606. ctx._originalTranslate = ctx.translate;
  3607. ctx._originalTransform = ctx.transform;
  3608. ctx._originalSetTransform = ctx.setTransform;
  3609. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3610. ctx._transformStack = [];
  3611. Object.defineProperty(ctx, 'mozCurrentTransform', {
  3612. get: function getCurrentTransform() {
  3613. return this._transformMatrix;
  3614. }
  3615. });
  3616. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  3617. get: function getCurrentTransformInverse() {
  3618. // Calculation done using WolframAlpha:
  3619. // http://www.wolframalpha.com/input/?
  3620. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  3621. var m = this._transformMatrix;
  3622. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  3623. var ad_bc = a * d - b * c;
  3624. var bc_ad = b * c - a * d;
  3625. return [
  3626. d / ad_bc,
  3627. b / bc_ad,
  3628. c / bc_ad,
  3629. a / ad_bc,
  3630. (d * e - c * f) / bc_ad,
  3631. (b * e - a * f) / ad_bc
  3632. ];
  3633. }
  3634. });
  3635. ctx.save = function ctxSave() {
  3636. var old = this._transformMatrix;
  3637. this._transformStack.push(old);
  3638. this._transformMatrix = old.slice(0, 6);
  3639. this._originalSave();
  3640. };
  3641. ctx.restore = function ctxRestore() {
  3642. var prev = this._transformStack.pop();
  3643. if (prev) {
  3644. this._transformMatrix = prev;
  3645. this._originalRestore();
  3646. }
  3647. };
  3648. ctx.translate = function ctxTranslate(x, y) {
  3649. var m = this._transformMatrix;
  3650. m[4] = m[0] * x + m[2] * y + m[4];
  3651. m[5] = m[1] * x + m[3] * y + m[5];
  3652. this._originalTranslate(x, y);
  3653. };
  3654. ctx.scale = function ctxScale(x, y) {
  3655. var m = this._transformMatrix;
  3656. m[0] = m[0] * x;
  3657. m[1] = m[1] * x;
  3658. m[2] = m[2] * y;
  3659. m[3] = m[3] * y;
  3660. this._originalScale(x, y);
  3661. };
  3662. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3663. var m = this._transformMatrix;
  3664. this._transformMatrix = [
  3665. m[0] * a + m[2] * b,
  3666. m[1] * a + m[3] * b,
  3667. m[0] * c + m[2] * d,
  3668. m[1] * c + m[3] * d,
  3669. m[0] * e + m[2] * f + m[4],
  3670. m[1] * e + m[3] * f + m[5]
  3671. ];
  3672. ctx._originalTransform(a, b, c, d, e, f);
  3673. };
  3674. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3675. this._transformMatrix = [a, b, c, d, e, f];
  3676. ctx._originalSetTransform(a, b, c, d, e, f);
  3677. };
  3678. ctx.rotate = function ctxRotate(angle) {
  3679. var cosValue = Math.cos(angle);
  3680. var sinValue = Math.sin(angle);
  3681. var m = this._transformMatrix;
  3682. this._transformMatrix = [
  3683. m[0] * cosValue + m[2] * sinValue,
  3684. m[1] * cosValue + m[3] * sinValue,
  3685. m[0] * (-sinValue) + m[2] * cosValue,
  3686. m[1] * (-sinValue) + m[3] * cosValue,
  3687. m[4],
  3688. m[5]
  3689. ];
  3690. this._originalRotate(angle);
  3691. };
  3692. }
  3693. }
  3694. var CachedCanvases = (function CachedCanvasesClosure() {
  3695. function CachedCanvases() {
  3696. this.cache = Object.create(null);
  3697. }
  3698. CachedCanvases.prototype = {
  3699. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3700. trackTransform) {
  3701. var canvasEntry;
  3702. if (this.cache[id] !== undefined) {
  3703. canvasEntry = this.cache[id];
  3704. canvasEntry.canvas.width = width;
  3705. canvasEntry.canvas.height = height;
  3706. // reset canvas transform for emulated mozCurrentTransform, if needed
  3707. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3708. } else {
  3709. var canvas = createScratchCanvas(width, height);
  3710. var ctx = canvas.getContext('2d');
  3711. if (trackTransform) {
  3712. addContextCurrentTransform(ctx);
  3713. }
  3714. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3715. }
  3716. return canvasEntry;
  3717. },
  3718. clear: function () {
  3719. for (var id in this.cache) {
  3720. var canvasEntry = this.cache[id];
  3721. // Zeroing the width and height causes Firefox to release graphics
  3722. // resources immediately, which can greatly reduce memory consumption.
  3723. canvasEntry.canvas.width = 0;
  3724. canvasEntry.canvas.height = 0;
  3725. delete this.cache[id];
  3726. }
  3727. }
  3728. };
  3729. return CachedCanvases;
  3730. })();
  3731. function compileType3Glyph(imgData) {
  3732. var POINT_TO_PROCESS_LIMIT = 1000;
  3733. var width = imgData.width, height = imgData.height;
  3734. var i, j, j0, width1 = width + 1;
  3735. var points = new Uint8Array(width1 * (height + 1));
  3736. var POINT_TYPES =
  3737. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3738. // decodes bit-packed mask data
  3739. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3740. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3741. for (i = 0, ii = data0.length; i < ii; i++) {
  3742. var mask = 128, elem = data0[i];
  3743. while (mask > 0) {
  3744. data[pos++] = (elem & mask) ? 0 : 255;
  3745. mask >>= 1;
  3746. }
  3747. }
  3748. // finding iteresting points: every point is located between mask pixels,
  3749. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3750. // will have flags assigned based on neighboring mask pixels:
  3751. // 4 | 8
  3752. // --P--
  3753. // 2 | 1
  3754. // We are interested only in points with the flags:
  3755. // - outside corners: 1, 2, 4, 8;
  3756. // - inside corners: 7, 11, 13, 14;
  3757. // - and, intersections: 5, 10.
  3758. var count = 0;
  3759. pos = 0;
  3760. if (data[pos] !== 0) {
  3761. points[0] = 1;
  3762. ++count;
  3763. }
  3764. for (j = 1; j < width; j++) {
  3765. if (data[pos] !== data[pos + 1]) {
  3766. points[j] = data[pos] ? 2 : 1;
  3767. ++count;
  3768. }
  3769. pos++;
  3770. }
  3771. if (data[pos] !== 0) {
  3772. points[j] = 2;
  3773. ++count;
  3774. }
  3775. for (i = 1; i < height; i++) {
  3776. pos = i * lineSize;
  3777. j0 = i * width1;
  3778. if (data[pos - lineSize] !== data[pos]) {
  3779. points[j0] = data[pos] ? 1 : 8;
  3780. ++count;
  3781. }
  3782. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3783. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3784. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3785. for (j = 1; j < width; j++) {
  3786. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3787. (data[pos - lineSize + 1] ? 8 : 0);
  3788. if (POINT_TYPES[sum]) {
  3789. points[j0 + j] = POINT_TYPES[sum];
  3790. ++count;
  3791. }
  3792. pos++;
  3793. }
  3794. if (data[pos - lineSize] !== data[pos]) {
  3795. points[j0 + j] = data[pos] ? 2 : 4;
  3796. ++count;
  3797. }
  3798. if (count > POINT_TO_PROCESS_LIMIT) {
  3799. return null;
  3800. }
  3801. }
  3802. pos = lineSize * (height - 1);
  3803. j0 = i * width1;
  3804. if (data[pos] !== 0) {
  3805. points[j0] = 8;
  3806. ++count;
  3807. }
  3808. for (j = 1; j < width; j++) {
  3809. if (data[pos] !== data[pos + 1]) {
  3810. points[j0 + j] = data[pos] ? 4 : 8;
  3811. ++count;
  3812. }
  3813. pos++;
  3814. }
  3815. if (data[pos] !== 0) {
  3816. points[j0 + j] = 4;
  3817. ++count;
  3818. }
  3819. if (count > POINT_TO_PROCESS_LIMIT) {
  3820. return null;
  3821. }
  3822. // building outlines
  3823. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3824. var outlines = [];
  3825. for (i = 0; count && i <= height; i++) {
  3826. var p = i * width1;
  3827. var end = p + width;
  3828. while (p < end && !points[p]) {
  3829. p++;
  3830. }
  3831. if (p === end) {
  3832. continue;
  3833. }
  3834. var coords = [p % width1, i];
  3835. var type = points[p], p0 = p, pp;
  3836. do {
  3837. var step = steps[type];
  3838. do {
  3839. p += step;
  3840. } while (!points[p]);
  3841. pp = points[p];
  3842. if (pp !== 5 && pp !== 10) {
  3843. // set new direction
  3844. type = pp;
  3845. // delete mark
  3846. points[p] = 0;
  3847. } else { // type is 5 or 10, ie, a crossing
  3848. // set new direction
  3849. type = pp & ((0x33 * type) >> 4);
  3850. // set new type for "future hit"
  3851. points[p] &= (type >> 2 | type << 2);
  3852. }
  3853. coords.push(p % width1);
  3854. coords.push((p / width1) | 0);
  3855. --count;
  3856. } while (p0 !== p);
  3857. outlines.push(coords);
  3858. --i;
  3859. }
  3860. var drawOutline = function(c) {
  3861. c.save();
  3862. // the path shall be painted in [0..1]x[0..1] space
  3863. c.scale(1 / width, -1 / height);
  3864. c.translate(0, -height);
  3865. c.beginPath();
  3866. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3867. var o = outlines[i];
  3868. c.moveTo(o[0], o[1]);
  3869. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3870. c.lineTo(o[j], o[j+1]);
  3871. }
  3872. }
  3873. c.fill();
  3874. c.beginPath();
  3875. c.restore();
  3876. };
  3877. return drawOutline;
  3878. }
  3879. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3880. function CanvasExtraState(old) {
  3881. // Are soft masks and alpha values shapes or opacities?
  3882. this.alphaIsShape = false;
  3883. this.fontSize = 0;
  3884. this.fontSizeScale = 1;
  3885. this.textMatrix = IDENTITY_MATRIX;
  3886. this.textMatrixScale = 1;
  3887. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3888. this.leading = 0;
  3889. // Current point (in user coordinates)
  3890. this.x = 0;
  3891. this.y = 0;
  3892. // Start of text line (in text coordinates)
  3893. this.lineX = 0;
  3894. this.lineY = 0;
  3895. // Character and word spacing
  3896. this.charSpacing = 0;
  3897. this.wordSpacing = 0;
  3898. this.textHScale = 1;
  3899. this.textRenderingMode = TextRenderingMode.FILL;
  3900. this.textRise = 0;
  3901. // Default fore and background colors
  3902. this.fillColor = '#000000';
  3903. this.strokeColor = '#000000';
  3904. this.patternFill = false;
  3905. // Note: fill alpha applies to all non-stroking operations
  3906. this.fillAlpha = 1;
  3907. this.strokeAlpha = 1;
  3908. this.lineWidth = 1;
  3909. this.activeSMask = null; // nonclonable field (see the save method below)
  3910. this.old = old;
  3911. }
  3912. CanvasExtraState.prototype = {
  3913. clone: function CanvasExtraState_clone() {
  3914. return Object.create(this);
  3915. },
  3916. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3917. this.x = x;
  3918. this.y = y;
  3919. }
  3920. };
  3921. return CanvasExtraState;
  3922. })();
  3923. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3924. // Defines the time the executeOperatorList is going to be executing
  3925. // before it stops and shedules a continue of execution.
  3926. var EXECUTION_TIME = 15;
  3927. // Defines the number of steps before checking the execution time
  3928. var EXECUTION_STEPS = 10;
  3929. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3930. this.ctx = canvasCtx;
  3931. this.current = new CanvasExtraState();
  3932. this.stateStack = [];
  3933. this.pendingClip = null;
  3934. this.pendingEOFill = false;
  3935. this.res = null;
  3936. this.xobjs = null;
  3937. this.commonObjs = commonObjs;
  3938. this.objs = objs;
  3939. this.imageLayer = imageLayer;
  3940. this.groupStack = [];
  3941. this.processingType3 = null;
  3942. // Patterns are painted relative to the initial page/form transform, see pdf
  3943. // spec 8.7.2 NOTE 1.
  3944. this.baseTransform = null;
  3945. this.baseTransformStack = [];
  3946. this.groupLevel = 0;
  3947. this.smaskStack = [];
  3948. this.smaskCounter = 0;
  3949. this.tempSMask = null;
  3950. this.cachedCanvases = new CachedCanvases();
  3951. if (canvasCtx) {
  3952. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3953. // the transformation must already be set in canvasCtx._transformMatrix.
  3954. addContextCurrentTransform(canvasCtx);
  3955. }
  3956. this.cachedGetSinglePixelWidth = null;
  3957. }
  3958. function putBinaryImageData(ctx, imgData) {
  3959. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3960. ctx.putImageData(imgData, 0, 0);
  3961. return;
  3962. }
  3963. // Put the image data to the canvas in chunks, rather than putting the
  3964. // whole image at once. This saves JS memory, because the ImageData object
  3965. // is smaller. It also possibly saves C++ memory within the implementation
  3966. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3967. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3968. // because too many putImageData() calls will slow things down.
  3969. //
  3970. // Note: as written, if the last chunk is partial, the putImageData() call
  3971. // will (conceptually) put pixels past the bounds of the canvas. But
  3972. // that's ok; any such pixels are ignored.
  3973. var height = imgData.height, width = imgData.width;
  3974. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3975. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3976. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3977. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3978. var srcPos = 0, destPos;
  3979. var src = imgData.data;
  3980. var dest = chunkImgData.data;
  3981. var i, j, thisChunkHeight, elemsInThisChunk;
  3982. // There are multiple forms in which the pixel data can be passed, and
  3983. // imgData.kind tells us which one this is.
  3984. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3985. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3986. var srcLength = src.byteLength;
  3987. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3988. new Uint32ArrayView(dest);
  3989. var dest32DataLength = dest32.length;
  3990. var fullSrcDiff = (width + 7) >> 3;
  3991. var white = 0xFFFFFFFF;
  3992. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3993. 0xFF000000 : 0x000000FF;
  3994. for (i = 0; i < totalChunks; i++) {
  3995. thisChunkHeight =
  3996. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3997. destPos = 0;
  3998. for (j = 0; j < thisChunkHeight; j++) {
  3999. var srcDiff = srcLength - srcPos;
  4000. var k = 0;
  4001. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  4002. var kEndUnrolled = kEnd & ~7;
  4003. var mask = 0;
  4004. var srcByte = 0;
  4005. for (; k < kEndUnrolled; k += 8) {
  4006. srcByte = src[srcPos++];
  4007. dest32[destPos++] = (srcByte & 128) ? white : black;
  4008. dest32[destPos++] = (srcByte & 64) ? white : black;
  4009. dest32[destPos++] = (srcByte & 32) ? white : black;
  4010. dest32[destPos++] = (srcByte & 16) ? white : black;
  4011. dest32[destPos++] = (srcByte & 8) ? white : black;
  4012. dest32[destPos++] = (srcByte & 4) ? white : black;
  4013. dest32[destPos++] = (srcByte & 2) ? white : black;
  4014. dest32[destPos++] = (srcByte & 1) ? white : black;
  4015. }
  4016. for (; k < kEnd; k++) {
  4017. if (mask === 0) {
  4018. srcByte = src[srcPos++];
  4019. mask = 128;
  4020. }
  4021. dest32[destPos++] = (srcByte & mask) ? white : black;
  4022. mask >>= 1;
  4023. }
  4024. }
  4025. // We ran out of input. Make all remaining pixels transparent.
  4026. while (destPos < dest32DataLength) {
  4027. dest32[destPos++] = 0;
  4028. }
  4029. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4030. }
  4031. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  4032. // RGBA, 32-bits per pixel.
  4033. j = 0;
  4034. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4035. for (i = 0; i < fullChunks; i++) {
  4036. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4037. srcPos += elemsInThisChunk;
  4038. ctx.putImageData(chunkImgData, 0, j);
  4039. j += FULL_CHUNK_HEIGHT;
  4040. }
  4041. if (i < totalChunks) {
  4042. elemsInThisChunk = width * partialChunkHeight * 4;
  4043. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4044. ctx.putImageData(chunkImgData, 0, j);
  4045. }
  4046. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  4047. // RGB, 24-bits per pixel.
  4048. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4049. elemsInThisChunk = width * thisChunkHeight;
  4050. for (i = 0; i < totalChunks; i++) {
  4051. if (i >= fullChunks) {
  4052. thisChunkHeight = partialChunkHeight;
  4053. elemsInThisChunk = width * thisChunkHeight;
  4054. }
  4055. destPos = 0;
  4056. for (j = elemsInThisChunk; j--;) {
  4057. dest[destPos++] = src[srcPos++];
  4058. dest[destPos++] = src[srcPos++];
  4059. dest[destPos++] = src[srcPos++];
  4060. dest[destPos++] = 255;
  4061. }
  4062. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4063. }
  4064. } else {
  4065. error('bad image kind: ' + imgData.kind);
  4066. }
  4067. }
  4068. function putBinaryImageMask(ctx, imgData) {
  4069. var height = imgData.height, width = imgData.width;
  4070. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4071. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4072. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4073. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4074. var srcPos = 0;
  4075. var src = imgData.data;
  4076. var dest = chunkImgData.data;
  4077. for (var i = 0; i < totalChunks; i++) {
  4078. var thisChunkHeight =
  4079. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4080. // Expand the mask so it can be used by the canvas. Any required
  4081. // inversion has already been handled.
  4082. var destPos = 3; // alpha component offset
  4083. for (var j = 0; j < thisChunkHeight; j++) {
  4084. var mask = 0;
  4085. for (var k = 0; k < width; k++) {
  4086. if (!mask) {
  4087. var elem = src[srcPos++];
  4088. mask = 128;
  4089. }
  4090. dest[destPos] = (elem & mask) ? 0 : 255;
  4091. destPos += 4;
  4092. mask >>= 1;
  4093. }
  4094. }
  4095. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4096. }
  4097. }
  4098. function copyCtxState(sourceCtx, destCtx) {
  4099. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  4100. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  4101. 'globalCompositeOperation', 'font'];
  4102. for (var i = 0, ii = properties.length; i < ii; i++) {
  4103. var property = properties[i];
  4104. if (sourceCtx[property] !== undefined) {
  4105. destCtx[property] = sourceCtx[property];
  4106. }
  4107. }
  4108. if (sourceCtx.setLineDash !== undefined) {
  4109. destCtx.setLineDash(sourceCtx.getLineDash());
  4110. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4111. } else if (sourceCtx.mozDashOffset !== undefined) {
  4112. destCtx.mozDash = sourceCtx.mozDash;
  4113. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  4114. }
  4115. }
  4116. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4117. var length = bytes.length;
  4118. for (var i = 3; i < length; i += 4) {
  4119. var alpha = bytes[i];
  4120. if (alpha === 0) {
  4121. bytes[i - 3] = r0;
  4122. bytes[i - 2] = g0;
  4123. bytes[i - 1] = b0;
  4124. } else if (alpha < 255) {
  4125. var alpha_ = 255 - alpha;
  4126. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  4127. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  4128. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  4129. }
  4130. }
  4131. }
  4132. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4133. var length = maskData.length;
  4134. var scale = 1 / 255;
  4135. for (var i = 3; i < length; i += 4) {
  4136. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4137. layerData[i] = (layerData[i] * alpha * scale) | 0;
  4138. }
  4139. }
  4140. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4141. var length = maskData.length;
  4142. for (var i = 3; i < length; i += 4) {
  4143. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  4144. (maskData[i - 2] * 152) + // * 0.59 ....
  4145. (maskData[i - 1] * 28); // * 0.11 ....
  4146. layerData[i] = transferMap ?
  4147. (layerData[i] * transferMap[y >> 8]) >> 8 :
  4148. (layerData[i] * y) >> 16;
  4149. }
  4150. }
  4151. function genericComposeSMask(maskCtx, layerCtx, width, height,
  4152. subtype, backdrop, transferMap) {
  4153. var hasBackdrop = !!backdrop;
  4154. var r0 = hasBackdrop ? backdrop[0] : 0;
  4155. var g0 = hasBackdrop ? backdrop[1] : 0;
  4156. var b0 = hasBackdrop ? backdrop[2] : 0;
  4157. var composeFn;
  4158. if (subtype === 'Luminosity') {
  4159. composeFn = composeSMaskLuminosity;
  4160. } else {
  4161. composeFn = composeSMaskAlpha;
  4162. }
  4163. // processing image in chunks to save memory
  4164. var PIXELS_TO_PROCESS = 1048576;
  4165. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4166. for (var row = 0; row < height; row += chunkSize) {
  4167. var chunkHeight = Math.min(chunkSize, height - row);
  4168. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  4169. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  4170. if (hasBackdrop) {
  4171. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4172. }
  4173. composeFn(maskData.data, layerData.data, transferMap);
  4174. maskCtx.putImageData(layerData, 0, row);
  4175. }
  4176. }
  4177. function composeSMask(ctx, smask, layerCtx) {
  4178. var mask = smask.canvas;
  4179. var maskCtx = smask.context;
  4180. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  4181. smask.offsetX, smask.offsetY);
  4182. var backdrop = smask.backdrop || null;
  4183. if (!smask.transferMap && WebGLUtils.isEnabled) {
  4184. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  4185. {subtype: smask.subtype, backdrop: backdrop});
  4186. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4187. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  4188. return;
  4189. }
  4190. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  4191. smask.subtype, backdrop, smask.transferMap);
  4192. ctx.drawImage(mask, 0, 0);
  4193. }
  4194. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  4195. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  4196. var NORMAL_CLIP = {};
  4197. var EO_CLIP = {};
  4198. CanvasGraphics.prototype = {
  4199. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  4200. transparency) {
  4201. // For pdfs that use blend modes we have to clear the canvas else certain
  4202. // blend modes can look wrong since we'd be blending with a white
  4203. // backdrop. The problem with a transparent backdrop though is we then
  4204. // don't get sub pixel anti aliasing on text, creating temporary
  4205. // transparent canvas when we have blend modes.
  4206. var width = this.ctx.canvas.width;
  4207. var height = this.ctx.canvas.height;
  4208. this.ctx.save();
  4209. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  4210. this.ctx.fillRect(0, 0, width, height);
  4211. this.ctx.restore();
  4212. if (transparency) {
  4213. var transparentCanvas = this.cachedCanvases.getCanvas(
  4214. 'transparent', width, height, true);
  4215. this.compositeCtx = this.ctx;
  4216. this.transparentCanvas = transparentCanvas.canvas;
  4217. this.ctx = transparentCanvas.context;
  4218. this.ctx.save();
  4219. // The transform can be applied before rendering, transferring it to
  4220. // the new canvas.
  4221. this.ctx.transform.apply(this.ctx,
  4222. this.compositeCtx.mozCurrentTransform);
  4223. }
  4224. this.ctx.save();
  4225. if (transform) {
  4226. this.ctx.transform.apply(this.ctx, transform);
  4227. }
  4228. this.ctx.transform.apply(this.ctx, viewport.transform);
  4229. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4230. if (this.imageLayer) {
  4231. this.imageLayer.beginLayout();
  4232. }
  4233. },
  4234. executeOperatorList: function CanvasGraphics_executeOperatorList(
  4235. operatorList,
  4236. executionStartIdx, continueCallback,
  4237. stepper) {
  4238. var argsArray = operatorList.argsArray;
  4239. var fnArray = operatorList.fnArray;
  4240. var i = executionStartIdx || 0;
  4241. var argsArrayLen = argsArray.length;
  4242. // Sometimes the OperatorList to execute is empty.
  4243. if (argsArrayLen === i) {
  4244. return i;
  4245. }
  4246. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  4247. typeof continueCallback === 'function');
  4248. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4249. var steps = 0;
  4250. var commonObjs = this.commonObjs;
  4251. var objs = this.objs;
  4252. var fnId;
  4253. while (true) {
  4254. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4255. stepper.breakIt(i, continueCallback);
  4256. return i;
  4257. }
  4258. fnId = fnArray[i];
  4259. if (fnId !== OPS.dependency) {
  4260. this[fnId].apply(this, argsArray[i]);
  4261. } else {
  4262. var deps = argsArray[i];
  4263. for (var n = 0, nn = deps.length; n < nn; n++) {
  4264. var depObjId = deps[n];
  4265. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  4266. var objsPool = common ? commonObjs : objs;
  4267. // If the promise isn't resolved yet, add the continueCallback
  4268. // to the promise and bail out.
  4269. if (!objsPool.isResolved(depObjId)) {
  4270. objsPool.get(depObjId, continueCallback);
  4271. return i;
  4272. }
  4273. }
  4274. }
  4275. i++;
  4276. // If the entire operatorList was executed, stop as were done.
  4277. if (i === argsArrayLen) {
  4278. return i;
  4279. }
  4280. // If the execution took longer then a certain amount of time and
  4281. // `continueCallback` is specified, interrupt the execution.
  4282. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4283. if (Date.now() > endTime) {
  4284. continueCallback();
  4285. return i;
  4286. }
  4287. steps = 0;
  4288. }
  4289. // If the operatorList isn't executed completely yet OR the execution
  4290. // time was short enough, do another execution round.
  4291. }
  4292. },
  4293. endDrawing: function CanvasGraphics_endDrawing() {
  4294. this.ctx.restore();
  4295. if (this.transparentCanvas) {
  4296. this.ctx = this.compositeCtx;
  4297. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4298. this.transparentCanvas = null;
  4299. }
  4300. this.cachedCanvases.clear();
  4301. WebGLUtils.clear();
  4302. if (this.imageLayer) {
  4303. this.imageLayer.endLayout();
  4304. }
  4305. },
  4306. // Graphics state
  4307. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4308. this.current.lineWidth = width;
  4309. this.ctx.lineWidth = width;
  4310. },
  4311. setLineCap: function CanvasGraphics_setLineCap(style) {
  4312. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4313. },
  4314. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4315. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4316. },
  4317. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4318. this.ctx.miterLimit = limit;
  4319. },
  4320. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4321. var ctx = this.ctx;
  4322. if (ctx.setLineDash !== undefined) {
  4323. ctx.setLineDash(dashArray);
  4324. ctx.lineDashOffset = dashPhase;
  4325. } else {
  4326. ctx.mozDash = dashArray;
  4327. ctx.mozDashOffset = dashPhase;
  4328. }
  4329. },
  4330. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  4331. // Maybe if we one day fully support color spaces this will be important
  4332. // for now we can ignore.
  4333. // TODO set rendering intent?
  4334. },
  4335. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  4336. // There's no way to control this with canvas, but we can safely ignore.
  4337. // TODO set flatness?
  4338. },
  4339. setGState: function CanvasGraphics_setGState(states) {
  4340. for (var i = 0, ii = states.length; i < ii; i++) {
  4341. var state = states[i];
  4342. var key = state[0];
  4343. var value = state[1];
  4344. switch (key) {
  4345. case 'LW':
  4346. this.setLineWidth(value);
  4347. break;
  4348. case 'LC':
  4349. this.setLineCap(value);
  4350. break;
  4351. case 'LJ':
  4352. this.setLineJoin(value);
  4353. break;
  4354. case 'ML':
  4355. this.setMiterLimit(value);
  4356. break;
  4357. case 'D':
  4358. this.setDash(value[0], value[1]);
  4359. break;
  4360. case 'RI':
  4361. this.setRenderingIntent(value);
  4362. break;
  4363. case 'FL':
  4364. this.setFlatness(value);
  4365. break;
  4366. case 'Font':
  4367. this.setFont(value[0], value[1]);
  4368. break;
  4369. case 'CA':
  4370. this.current.strokeAlpha = state[1];
  4371. break;
  4372. case 'ca':
  4373. this.current.fillAlpha = state[1];
  4374. this.ctx.globalAlpha = state[1];
  4375. break;
  4376. case 'BM':
  4377. if (value && value.name && (value.name !== 'Normal')) {
  4378. var mode = value.name.replace(/([A-Z])/g,
  4379. function(c) {
  4380. return '-' + c.toLowerCase();
  4381. }
  4382. ).substring(1);
  4383. this.ctx.globalCompositeOperation = mode;
  4384. if (this.ctx.globalCompositeOperation !== mode) {
  4385. warn('globalCompositeOperation "' + mode +
  4386. '" is not supported');
  4387. }
  4388. } else {
  4389. this.ctx.globalCompositeOperation = 'source-over';
  4390. }
  4391. break;
  4392. case 'SMask':
  4393. if (this.current.activeSMask) {
  4394. this.endSMaskGroup();
  4395. }
  4396. this.current.activeSMask = value ? this.tempSMask : null;
  4397. if (this.current.activeSMask) {
  4398. this.beginSMaskGroup();
  4399. }
  4400. this.tempSMask = null;
  4401. break;
  4402. }
  4403. }
  4404. },
  4405. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4406. var activeSMask = this.current.activeSMask;
  4407. var drawnWidth = activeSMask.canvas.width;
  4408. var drawnHeight = activeSMask.canvas.height;
  4409. var cacheId = 'smaskGroupAt' + this.groupLevel;
  4410. var scratchCanvas = this.cachedCanvases.getCanvas(
  4411. cacheId, drawnWidth, drawnHeight, true);
  4412. var currentCtx = this.ctx;
  4413. var currentTransform = currentCtx.mozCurrentTransform;
  4414. this.ctx.save();
  4415. var groupCtx = scratchCanvas.context;
  4416. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4417. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4418. groupCtx.transform.apply(groupCtx, currentTransform);
  4419. copyCtxState(currentCtx, groupCtx);
  4420. this.ctx = groupCtx;
  4421. this.setGState([
  4422. ['BM', 'Normal'],
  4423. ['ca', 1],
  4424. ['CA', 1]
  4425. ]);
  4426. this.groupStack.push(currentCtx);
  4427. this.groupLevel++;
  4428. },
  4429. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4430. var groupCtx = this.ctx;
  4431. this.groupLevel--;
  4432. this.ctx = this.groupStack.pop();
  4433. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  4434. this.ctx.restore();
  4435. copyCtxState(groupCtx, this.ctx);
  4436. },
  4437. save: function CanvasGraphics_save() {
  4438. this.ctx.save();
  4439. var old = this.current;
  4440. this.stateStack.push(old);
  4441. this.current = old.clone();
  4442. this.current.activeSMask = null;
  4443. },
  4444. restore: function CanvasGraphics_restore() {
  4445. if (this.stateStack.length !== 0) {
  4446. if (this.current.activeSMask !== null) {
  4447. this.endSMaskGroup();
  4448. }
  4449. this.current = this.stateStack.pop();
  4450. this.ctx.restore();
  4451. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  4452. this.pendingClip = null;
  4453. this.cachedGetSinglePixelWidth = null;
  4454. }
  4455. },
  4456. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4457. this.ctx.transform(a, b, c, d, e, f);
  4458. this.cachedGetSinglePixelWidth = null;
  4459. },
  4460. // Path
  4461. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4462. var ctx = this.ctx;
  4463. var current = this.current;
  4464. var x = current.x, y = current.y;
  4465. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4466. switch (ops[i] | 0) {
  4467. case OPS.rectangle:
  4468. x = args[j++];
  4469. y = args[j++];
  4470. var width = args[j++];
  4471. var height = args[j++];
  4472. if (width === 0) {
  4473. width = this.getSinglePixelWidth();
  4474. }
  4475. if (height === 0) {
  4476. height = this.getSinglePixelWidth();
  4477. }
  4478. var xw = x + width;
  4479. var yh = y + height;
  4480. this.ctx.moveTo(x, y);
  4481. this.ctx.lineTo(xw, y);
  4482. this.ctx.lineTo(xw, yh);
  4483. this.ctx.lineTo(x, yh);
  4484. this.ctx.lineTo(x, y);
  4485. this.ctx.closePath();
  4486. break;
  4487. case OPS.moveTo:
  4488. x = args[j++];
  4489. y = args[j++];
  4490. ctx.moveTo(x, y);
  4491. break;
  4492. case OPS.lineTo:
  4493. x = args[j++];
  4494. y = args[j++];
  4495. ctx.lineTo(x, y);
  4496. break;
  4497. case OPS.curveTo:
  4498. x = args[j + 4];
  4499. y = args[j + 5];
  4500. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  4501. x, y);
  4502. j += 6;
  4503. break;
  4504. case OPS.curveTo2:
  4505. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  4506. args[j + 2], args[j + 3]);
  4507. x = args[j + 2];
  4508. y = args[j + 3];
  4509. j += 4;
  4510. break;
  4511. case OPS.curveTo3:
  4512. x = args[j + 2];
  4513. y = args[j + 3];
  4514. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4515. j += 4;
  4516. break;
  4517. case OPS.closePath:
  4518. ctx.closePath();
  4519. break;
  4520. }
  4521. }
  4522. current.setCurrentPoint(x, y);
  4523. },
  4524. closePath: function CanvasGraphics_closePath() {
  4525. this.ctx.closePath();
  4526. },
  4527. stroke: function CanvasGraphics_stroke(consumePath) {
  4528. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4529. var ctx = this.ctx;
  4530. var strokeColor = this.current.strokeColor;
  4531. // Prevent drawing too thin lines by enforcing a minimum line width.
  4532. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  4533. this.current.lineWidth);
  4534. // For stroke we want to temporarily change the global alpha to the
  4535. // stroking alpha.
  4536. ctx.globalAlpha = this.current.strokeAlpha;
  4537. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  4538. strokeColor.type === 'Pattern') {
  4539. // for patterns, we transform to pattern space, calculate
  4540. // the pattern, call stroke, and restore to user space
  4541. ctx.save();
  4542. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4543. ctx.stroke();
  4544. ctx.restore();
  4545. } else {
  4546. ctx.stroke();
  4547. }
  4548. if (consumePath) {
  4549. this.consumePath();
  4550. }
  4551. // Restore the global alpha to the fill alpha
  4552. ctx.globalAlpha = this.current.fillAlpha;
  4553. },
  4554. closeStroke: function CanvasGraphics_closeStroke() {
  4555. this.closePath();
  4556. this.stroke();
  4557. },
  4558. fill: function CanvasGraphics_fill(consumePath) {
  4559. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4560. var ctx = this.ctx;
  4561. var fillColor = this.current.fillColor;
  4562. var isPatternFill = this.current.patternFill;
  4563. var needRestore = false;
  4564. if (isPatternFill) {
  4565. ctx.save();
  4566. if (this.baseTransform) {
  4567. ctx.setTransform.apply(ctx, this.baseTransform);
  4568. }
  4569. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4570. needRestore = true;
  4571. }
  4572. if (this.pendingEOFill) {
  4573. if (ctx.mozFillRule !== undefined) {
  4574. ctx.mozFillRule = 'evenodd';
  4575. ctx.fill();
  4576. ctx.mozFillRule = 'nonzero';
  4577. } else {
  4578. ctx.fill('evenodd');
  4579. }
  4580. this.pendingEOFill = false;
  4581. } else {
  4582. ctx.fill();
  4583. }
  4584. if (needRestore) {
  4585. ctx.restore();
  4586. }
  4587. if (consumePath) {
  4588. this.consumePath();
  4589. }
  4590. },
  4591. eoFill: function CanvasGraphics_eoFill() {
  4592. this.pendingEOFill = true;
  4593. this.fill();
  4594. },
  4595. fillStroke: function CanvasGraphics_fillStroke() {
  4596. this.fill(false);
  4597. this.stroke(false);
  4598. this.consumePath();
  4599. },
  4600. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4601. this.pendingEOFill = true;
  4602. this.fillStroke();
  4603. },
  4604. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4605. this.closePath();
  4606. this.fillStroke();
  4607. },
  4608. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4609. this.pendingEOFill = true;
  4610. this.closePath();
  4611. this.fillStroke();
  4612. },
  4613. endPath: function CanvasGraphics_endPath() {
  4614. this.consumePath();
  4615. },
  4616. // Clipping
  4617. clip: function CanvasGraphics_clip() {
  4618. this.pendingClip = NORMAL_CLIP;
  4619. },
  4620. eoClip: function CanvasGraphics_eoClip() {
  4621. this.pendingClip = EO_CLIP;
  4622. },
  4623. // Text
  4624. beginText: function CanvasGraphics_beginText() {
  4625. this.current.textMatrix = IDENTITY_MATRIX;
  4626. this.current.textMatrixScale = 1;
  4627. this.current.x = this.current.lineX = 0;
  4628. this.current.y = this.current.lineY = 0;
  4629. },
  4630. endText: function CanvasGraphics_endText() {
  4631. var paths = this.pendingTextPaths;
  4632. var ctx = this.ctx;
  4633. if (paths === undefined) {
  4634. ctx.beginPath();
  4635. return;
  4636. }
  4637. ctx.save();
  4638. ctx.beginPath();
  4639. for (var i = 0; i < paths.length; i++) {
  4640. var path = paths[i];
  4641. ctx.setTransform.apply(ctx, path.transform);
  4642. ctx.translate(path.x, path.y);
  4643. path.addToPath(ctx, path.fontSize);
  4644. }
  4645. ctx.restore();
  4646. ctx.clip();
  4647. ctx.beginPath();
  4648. delete this.pendingTextPaths;
  4649. },
  4650. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4651. this.current.charSpacing = spacing;
  4652. },
  4653. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4654. this.current.wordSpacing = spacing;
  4655. },
  4656. setHScale: function CanvasGraphics_setHScale(scale) {
  4657. this.current.textHScale = scale / 100;
  4658. },
  4659. setLeading: function CanvasGraphics_setLeading(leading) {
  4660. this.current.leading = -leading;
  4661. },
  4662. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4663. var fontObj = this.commonObjs.get(fontRefName);
  4664. var current = this.current;
  4665. if (!fontObj) {
  4666. error('Can\'t find font for ' + fontRefName);
  4667. }
  4668. current.fontMatrix = (fontObj.fontMatrix ?
  4669. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  4670. // A valid matrix needs all main diagonal elements to be non-zero
  4671. // This also ensures we bypass FF bugzilla bug #719844.
  4672. if (current.fontMatrix[0] === 0 ||
  4673. current.fontMatrix[3] === 0) {
  4674. warn('Invalid font matrix for font ' + fontRefName);
  4675. }
  4676. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4677. // and in some docs this can be negative (inverted x-y axes).
  4678. if (size < 0) {
  4679. size = -size;
  4680. current.fontDirection = -1;
  4681. } else {
  4682. current.fontDirection = 1;
  4683. }
  4684. this.current.font = fontObj;
  4685. this.current.fontSize = size;
  4686. if (fontObj.isType3Font) {
  4687. return; // we don't need ctx.font for Type3 fonts
  4688. }
  4689. var name = fontObj.loadedName || 'sans-serif';
  4690. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  4691. (fontObj.bold ? 'bold' : 'normal');
  4692. var italic = fontObj.italic ? 'italic' : 'normal';
  4693. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4694. // Some font backends cannot handle fonts below certain size.
  4695. // Keeping the font at minimal size and using the fontSizeScale to change
  4696. // the current transformation matrix before the fillText/strokeText.
  4697. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4698. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4699. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4700. this.current.fontSizeScale = size / browserFontSize;
  4701. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4702. this.ctx.font = rule;
  4703. },
  4704. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4705. this.current.textRenderingMode = mode;
  4706. },
  4707. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4708. this.current.textRise = rise;
  4709. },
  4710. moveText: function CanvasGraphics_moveText(x, y) {
  4711. this.current.x = this.current.lineX += x;
  4712. this.current.y = this.current.lineY += y;
  4713. },
  4714. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4715. this.setLeading(-y);
  4716. this.moveText(x, y);
  4717. },
  4718. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4719. this.current.textMatrix = [a, b, c, d, e, f];
  4720. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4721. this.current.x = this.current.lineX = 0;
  4722. this.current.y = this.current.lineY = 0;
  4723. },
  4724. nextLine: function CanvasGraphics_nextLine() {
  4725. this.moveText(0, this.current.leading);
  4726. },
  4727. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4728. var ctx = this.ctx;
  4729. var current = this.current;
  4730. var font = current.font;
  4731. var textRenderingMode = current.textRenderingMode;
  4732. var fontSize = current.fontSize / current.fontSizeScale;
  4733. var fillStrokeMode = textRenderingMode &
  4734. TextRenderingMode.FILL_STROKE_MASK;
  4735. var isAddToPathSet = !!(textRenderingMode &
  4736. TextRenderingMode.ADD_TO_PATH_FLAG);
  4737. var addToPath;
  4738. if (font.disableFontFace || isAddToPathSet) {
  4739. addToPath = font.getPathGenerator(this.commonObjs, character);
  4740. }
  4741. if (font.disableFontFace) {
  4742. ctx.save();
  4743. ctx.translate(x, y);
  4744. ctx.beginPath();
  4745. addToPath(ctx, fontSize);
  4746. if (fillStrokeMode === TextRenderingMode.FILL ||
  4747. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4748. ctx.fill();
  4749. }
  4750. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4751. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4752. ctx.stroke();
  4753. }
  4754. ctx.restore();
  4755. } else {
  4756. if (fillStrokeMode === TextRenderingMode.FILL ||
  4757. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4758. ctx.fillText(character, x, y);
  4759. }
  4760. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4761. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4762. ctx.strokeText(character, x, y);
  4763. }
  4764. }
  4765. if (isAddToPathSet) {
  4766. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4767. paths.push({
  4768. transform: ctx.mozCurrentTransform,
  4769. x: x,
  4770. y: y,
  4771. fontSize: fontSize,
  4772. addToPath: addToPath
  4773. });
  4774. }
  4775. },
  4776. get isFontSubpixelAAEnabled() {
  4777. // Checks if anti-aliasing is enabled when scaled text is painted.
  4778. // On Windows GDI scaled fonts looks bad.
  4779. var ctx = document.createElement('canvas').getContext('2d');
  4780. ctx.scale(1.5, 1);
  4781. ctx.fillText('I', 0, 10);
  4782. var data = ctx.getImageData(0, 0, 10, 10).data;
  4783. var enabled = false;
  4784. for (var i = 3; i < data.length; i += 4) {
  4785. if (data[i] > 0 && data[i] < 255) {
  4786. enabled = true;
  4787. break;
  4788. }
  4789. }
  4790. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4791. },
  4792. showText: function CanvasGraphics_showText(glyphs) {
  4793. var current = this.current;
  4794. var font = current.font;
  4795. if (font.isType3Font) {
  4796. return this.showType3Text(glyphs);
  4797. }
  4798. var fontSize = current.fontSize;
  4799. if (fontSize === 0) {
  4800. return;
  4801. }
  4802. var ctx = this.ctx;
  4803. var fontSizeScale = current.fontSizeScale;
  4804. var charSpacing = current.charSpacing;
  4805. var wordSpacing = current.wordSpacing;
  4806. var fontDirection = current.fontDirection;
  4807. var textHScale = current.textHScale * fontDirection;
  4808. var glyphsLength = glyphs.length;
  4809. var vertical = font.vertical;
  4810. var spacingDir = vertical ? 1 : -1;
  4811. var defaultVMetrics = font.defaultVMetrics;
  4812. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4813. var simpleFillText =
  4814. current.textRenderingMode === TextRenderingMode.FILL &&
  4815. !font.disableFontFace;
  4816. ctx.save();
  4817. ctx.transform.apply(ctx, current.textMatrix);
  4818. ctx.translate(current.x, current.y + current.textRise);
  4819. if (fontDirection > 0) {
  4820. ctx.scale(textHScale, -1);
  4821. } else {
  4822. ctx.scale(textHScale, 1);
  4823. }
  4824. var lineWidth = current.lineWidth;
  4825. var scale = current.textMatrixScale;
  4826. if (scale === 0 || lineWidth === 0) {
  4827. var fillStrokeMode = current.textRenderingMode &
  4828. TextRenderingMode.FILL_STROKE_MASK;
  4829. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4830. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4831. this.cachedGetSinglePixelWidth = null;
  4832. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4833. }
  4834. } else {
  4835. lineWidth /= scale;
  4836. }
  4837. if (fontSizeScale !== 1.0) {
  4838. ctx.scale(fontSizeScale, fontSizeScale);
  4839. lineWidth /= fontSizeScale;
  4840. }
  4841. ctx.lineWidth = lineWidth;
  4842. var x = 0, i;
  4843. for (i = 0; i < glyphsLength; ++i) {
  4844. var glyph = glyphs[i];
  4845. if (isNum(glyph)) {
  4846. x += spacingDir * glyph * fontSize / 1000;
  4847. continue;
  4848. }
  4849. var restoreNeeded = false;
  4850. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4851. var character = glyph.fontChar;
  4852. var accent = glyph.accent;
  4853. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4854. var width = glyph.width;
  4855. if (vertical) {
  4856. var vmetric, vx, vy;
  4857. vmetric = glyph.vmetric || defaultVMetrics;
  4858. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4859. vx = -vx * widthAdvanceScale;
  4860. vy = vmetric[2] * widthAdvanceScale;
  4861. width = vmetric ? -vmetric[0] : width;
  4862. scaledX = vx / fontSizeScale;
  4863. scaledY = (x + vy) / fontSizeScale;
  4864. } else {
  4865. scaledX = x / fontSizeScale;
  4866. scaledY = 0;
  4867. }
  4868. if (font.remeasure && width > 0) {
  4869. // Some standard fonts may not have the exact width: rescale per
  4870. // character if measured width is greater than expected glyph width
  4871. // and subpixel-aa is enabled, otherwise just center the glyph.
  4872. var measuredWidth = ctx.measureText(character).width * 1000 /
  4873. fontSize * fontSizeScale;
  4874. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  4875. var characterScaleX = width / measuredWidth;
  4876. restoreNeeded = true;
  4877. ctx.save();
  4878. ctx.scale(characterScaleX, 1);
  4879. scaledX /= characterScaleX;
  4880. } else if (width !== measuredWidth) {
  4881. scaledX += (width - measuredWidth) / 2000 *
  4882. fontSize / fontSizeScale;
  4883. }
  4884. }
  4885. if (simpleFillText && !accent) {
  4886. // common case
  4887. ctx.fillText(character, scaledX, scaledY);
  4888. } else {
  4889. this.paintChar(character, scaledX, scaledY);
  4890. if (accent) {
  4891. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4892. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4893. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4894. }
  4895. }
  4896. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4897. x += charWidth;
  4898. if (restoreNeeded) {
  4899. ctx.restore();
  4900. }
  4901. }
  4902. if (vertical) {
  4903. current.y -= x * textHScale;
  4904. } else {
  4905. current.x += x * textHScale;
  4906. }
  4907. ctx.restore();
  4908. },
  4909. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4910. // Type3 fonts - each glyph is a "mini-PDF"
  4911. var ctx = this.ctx;
  4912. var current = this.current;
  4913. var font = current.font;
  4914. var fontSize = current.fontSize;
  4915. var fontDirection = current.fontDirection;
  4916. var spacingDir = font.vertical ? 1 : -1;
  4917. var charSpacing = current.charSpacing;
  4918. var wordSpacing = current.wordSpacing;
  4919. var textHScale = current.textHScale * fontDirection;
  4920. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4921. var glyphsLength = glyphs.length;
  4922. var isTextInvisible =
  4923. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4924. var i, glyph, width, spacingLength;
  4925. if (isTextInvisible || fontSize === 0) {
  4926. return;
  4927. }
  4928. this.cachedGetSinglePixelWidth = null;
  4929. ctx.save();
  4930. ctx.transform.apply(ctx, current.textMatrix);
  4931. ctx.translate(current.x, current.y);
  4932. ctx.scale(textHScale, fontDirection);
  4933. for (i = 0; i < glyphsLength; ++i) {
  4934. glyph = glyphs[i];
  4935. if (isNum(glyph)) {
  4936. spacingLength = spacingDir * glyph * fontSize / 1000;
  4937. this.ctx.translate(spacingLength, 0);
  4938. current.x += spacingLength * textHScale;
  4939. continue;
  4940. }
  4941. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4942. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4943. if (!operatorList) {
  4944. warn('Type3 character \"' + glyph.operatorListId +
  4945. '\" is not available');
  4946. continue;
  4947. }
  4948. this.processingType3 = glyph;
  4949. this.save();
  4950. ctx.scale(fontSize, fontSize);
  4951. ctx.transform.apply(ctx, fontMatrix);
  4952. this.executeOperatorList(operatorList);
  4953. this.restore();
  4954. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4955. width = transformed[0] * fontSize + spacing;
  4956. ctx.translate(width, 0);
  4957. current.x += width * textHScale;
  4958. }
  4959. ctx.restore();
  4960. this.processingType3 = null;
  4961. },
  4962. // Type3 fonts
  4963. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4964. // We can safely ignore this since the width should be the same
  4965. // as the width in the Widths array.
  4966. },
  4967. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4968. yWidth,
  4969. llx,
  4970. lly,
  4971. urx,
  4972. ury) {
  4973. // TODO According to the spec we're also suppose to ignore any operators
  4974. // that set color or include images while processing this type3 font.
  4975. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4976. this.clip();
  4977. this.endPath();
  4978. },
  4979. // Color
  4980. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4981. var pattern;
  4982. if (IR[0] === 'TilingPattern') {
  4983. var color = IR[1];
  4984. var baseTransform = this.baseTransform ||
  4985. this.ctx.mozCurrentTransform.slice();
  4986. var self = this;
  4987. var canvasGraphicsFactory = {
  4988. createCanvasGraphics: function (ctx) {
  4989. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  4990. }
  4991. };
  4992. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  4993. baseTransform);
  4994. } else {
  4995. pattern = getShadingPatternFromIR(IR);
  4996. }
  4997. return pattern;
  4998. },
  4999. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  5000. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5001. },
  5002. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  5003. this.current.fillColor = this.getColorN_Pattern(arguments);
  5004. this.current.patternFill = true;
  5005. },
  5006. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  5007. var color = Util.makeCssRgb(r, g, b);
  5008. this.ctx.strokeStyle = color;
  5009. this.current.strokeColor = color;
  5010. },
  5011. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  5012. var color = Util.makeCssRgb(r, g, b);
  5013. this.ctx.fillStyle = color;
  5014. this.current.fillColor = color;
  5015. this.current.patternFill = false;
  5016. },
  5017. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  5018. var ctx = this.ctx;
  5019. this.save();
  5020. var pattern = getShadingPatternFromIR(patternIR);
  5021. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  5022. var inv = ctx.mozCurrentTransformInverse;
  5023. if (inv) {
  5024. var canvas = ctx.canvas;
  5025. var width = canvas.width;
  5026. var height = canvas.height;
  5027. var bl = Util.applyTransform([0, 0], inv);
  5028. var br = Util.applyTransform([0, height], inv);
  5029. var ul = Util.applyTransform([width, 0], inv);
  5030. var ur = Util.applyTransform([width, height], inv);
  5031. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5032. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5033. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5034. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5035. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5036. } else {
  5037. // HACK to draw the gradient onto an infinite rectangle.
  5038. // PDF gradients are drawn across the entire image while
  5039. // Canvas only allows gradients to be drawn in a rectangle
  5040. // The following bug should allow us to remove this.
  5041. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  5042. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5043. }
  5044. this.restore();
  5045. },
  5046. // Images
  5047. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  5048. error('Should not call beginInlineImage');
  5049. },
  5050. beginImageData: function CanvasGraphics_beginImageData() {
  5051. error('Should not call beginImageData');
  5052. },
  5053. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  5054. bbox) {
  5055. this.save();
  5056. this.baseTransformStack.push(this.baseTransform);
  5057. if (isArray(matrix) && 6 === matrix.length) {
  5058. this.transform.apply(this, matrix);
  5059. }
  5060. this.baseTransform = this.ctx.mozCurrentTransform;
  5061. if (isArray(bbox) && 4 === bbox.length) {
  5062. var width = bbox[2] - bbox[0];
  5063. var height = bbox[3] - bbox[1];
  5064. this.ctx.rect(bbox[0], bbox[1], width, height);
  5065. this.clip();
  5066. this.endPath();
  5067. }
  5068. },
  5069. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  5070. this.restore();
  5071. this.baseTransform = this.baseTransformStack.pop();
  5072. },
  5073. beginGroup: function CanvasGraphics_beginGroup(group) {
  5074. this.save();
  5075. var currentCtx = this.ctx;
  5076. // TODO non-isolated groups - according to Rik at adobe non-isolated
  5077. // group results aren't usually that different and they even have tools
  5078. // that ignore this setting. Notes from Rik on implmenting:
  5079. // - When you encounter an transparency group, create a new canvas with
  5080. // the dimensions of the bbox
  5081. // - copy the content from the previous canvas to the new canvas
  5082. // - draw as usual
  5083. // - remove the backdrop alpha:
  5084. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  5085. // value of your transparency group and 'alphaBackdrop' the alpha of the
  5086. // backdrop
  5087. // - remove background color:
  5088. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  5089. if (!group.isolated) {
  5090. info('TODO: Support non-isolated groups.');
  5091. }
  5092. // TODO knockout - supposedly possible with the clever use of compositing
  5093. // modes.
  5094. if (group.knockout) {
  5095. warn('Knockout groups not supported.');
  5096. }
  5097. var currentTransform = currentCtx.mozCurrentTransform;
  5098. if (group.matrix) {
  5099. currentCtx.transform.apply(currentCtx, group.matrix);
  5100. }
  5101. assert(group.bbox, 'Bounding box is required.');
  5102. // Based on the current transform figure out how big the bounding box
  5103. // will actually be.
  5104. var bounds = Util.getAxialAlignedBoundingBox(
  5105. group.bbox,
  5106. currentCtx.mozCurrentTransform);
  5107. // Clip the bounding box to the current canvas.
  5108. var canvasBounds = [0,
  5109. 0,
  5110. currentCtx.canvas.width,
  5111. currentCtx.canvas.height];
  5112. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5113. // Use ceil in case we're between sizes so we don't create canvas that is
  5114. // too small and make the canvas at least 1x1 pixels.
  5115. var offsetX = Math.floor(bounds[0]);
  5116. var offsetY = Math.floor(bounds[1]);
  5117. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5118. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5119. var scaleX = 1, scaleY = 1;
  5120. if (drawnWidth > MAX_GROUP_SIZE) {
  5121. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5122. drawnWidth = MAX_GROUP_SIZE;
  5123. }
  5124. if (drawnHeight > MAX_GROUP_SIZE) {
  5125. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5126. drawnHeight = MAX_GROUP_SIZE;
  5127. }
  5128. var cacheId = 'groupAt' + this.groupLevel;
  5129. if (group.smask) {
  5130. // Using two cache entries is case if masks are used one after another.
  5131. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  5132. }
  5133. var scratchCanvas = this.cachedCanvases.getCanvas(
  5134. cacheId, drawnWidth, drawnHeight, true);
  5135. var groupCtx = scratchCanvas.context;
  5136. // Since we created a new canvas that is just the size of the bounding box
  5137. // we have to translate the group ctx.
  5138. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5139. groupCtx.translate(-offsetX, -offsetY);
  5140. groupCtx.transform.apply(groupCtx, currentTransform);
  5141. if (group.smask) {
  5142. // Saving state and cached mask to be used in setGState.
  5143. this.smaskStack.push({
  5144. canvas: scratchCanvas.canvas,
  5145. context: groupCtx,
  5146. offsetX: offsetX,
  5147. offsetY: offsetY,
  5148. scaleX: scaleX,
  5149. scaleY: scaleY,
  5150. subtype: group.smask.subtype,
  5151. backdrop: group.smask.backdrop,
  5152. transferMap: group.smask.transferMap || null
  5153. });
  5154. } else {
  5155. // Setup the current ctx so when the group is popped we draw it at the
  5156. // right location.
  5157. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5158. currentCtx.translate(offsetX, offsetY);
  5159. currentCtx.scale(scaleX, scaleY);
  5160. }
  5161. // The transparency group inherits all off the current graphics state
  5162. // except the blend mode, soft mask, and alpha constants.
  5163. copyCtxState(currentCtx, groupCtx);
  5164. this.ctx = groupCtx;
  5165. this.setGState([
  5166. ['BM', 'Normal'],
  5167. ['ca', 1],
  5168. ['CA', 1]
  5169. ]);
  5170. this.groupStack.push(currentCtx);
  5171. this.groupLevel++;
  5172. },
  5173. endGroup: function CanvasGraphics_endGroup(group) {
  5174. this.groupLevel--;
  5175. var groupCtx = this.ctx;
  5176. this.ctx = this.groupStack.pop();
  5177. // Turn off image smoothing to avoid sub pixel interpolation which can
  5178. // look kind of blurry for some pdfs.
  5179. if (this.ctx.imageSmoothingEnabled !== undefined) {
  5180. this.ctx.imageSmoothingEnabled = false;
  5181. } else {
  5182. this.ctx.mozImageSmoothingEnabled = false;
  5183. }
  5184. if (group.smask) {
  5185. this.tempSMask = this.smaskStack.pop();
  5186. } else {
  5187. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5188. }
  5189. this.restore();
  5190. },
  5191. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  5192. this.save();
  5193. this.current = new CanvasExtraState();
  5194. if (this.baseTransform) {
  5195. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5196. }
  5197. },
  5198. endAnnotations: function CanvasGraphics_endAnnotations() {
  5199. this.restore();
  5200. },
  5201. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  5202. matrix) {
  5203. this.save();
  5204. if (isArray(rect) && 4 === rect.length) {
  5205. var width = rect[2] - rect[0];
  5206. var height = rect[3] - rect[1];
  5207. this.ctx.rect(rect[0], rect[1], width, height);
  5208. this.clip();
  5209. this.endPath();
  5210. }
  5211. this.transform.apply(this, transform);
  5212. this.transform.apply(this, matrix);
  5213. },
  5214. endAnnotation: function CanvasGraphics_endAnnotation() {
  5215. this.restore();
  5216. },
  5217. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  5218. var domImage = this.objs.get(objId);
  5219. if (!domImage) {
  5220. warn('Dependent image isn\'t ready yet');
  5221. return;
  5222. }
  5223. this.save();
  5224. var ctx = this.ctx;
  5225. // scale the image to the unit square
  5226. ctx.scale(1 / w, -1 / h);
  5227. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  5228. 0, -h, w, h);
  5229. if (this.imageLayer) {
  5230. var currentTransform = ctx.mozCurrentTransformInverse;
  5231. var position = this.getCanvasPosition(0, 0);
  5232. this.imageLayer.appendImage({
  5233. objId: objId,
  5234. left: position[0],
  5235. top: position[1],
  5236. width: w / currentTransform[0],
  5237. height: h / currentTransform[3]
  5238. });
  5239. }
  5240. this.restore();
  5241. },
  5242. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  5243. var ctx = this.ctx;
  5244. var width = img.width, height = img.height;
  5245. var fillColor = this.current.fillColor;
  5246. var isPatternFill = this.current.patternFill;
  5247. var glyph = this.processingType3;
  5248. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5249. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5250. glyph.compiled =
  5251. compileType3Glyph({data: img.data, width: width, height: height});
  5252. } else {
  5253. glyph.compiled = null;
  5254. }
  5255. }
  5256. if (glyph && glyph.compiled) {
  5257. glyph.compiled(ctx);
  5258. return;
  5259. }
  5260. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5261. width, height);
  5262. var maskCtx = maskCanvas.context;
  5263. maskCtx.save();
  5264. putBinaryImageMask(maskCtx, img);
  5265. maskCtx.globalCompositeOperation = 'source-in';
  5266. maskCtx.fillStyle = isPatternFill ?
  5267. fillColor.getPattern(maskCtx, this) : fillColor;
  5268. maskCtx.fillRect(0, 0, width, height);
  5269. maskCtx.restore();
  5270. this.paintInlineImageXObject(maskCanvas.canvas);
  5271. },
  5272. paintImageMaskXObjectRepeat:
  5273. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  5274. scaleY, positions) {
  5275. var width = imgData.width;
  5276. var height = imgData.height;
  5277. var fillColor = this.current.fillColor;
  5278. var isPatternFill = this.current.patternFill;
  5279. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5280. width, height);
  5281. var maskCtx = maskCanvas.context;
  5282. maskCtx.save();
  5283. putBinaryImageMask(maskCtx, imgData);
  5284. maskCtx.globalCompositeOperation = 'source-in';
  5285. maskCtx.fillStyle = isPatternFill ?
  5286. fillColor.getPattern(maskCtx, this) : fillColor;
  5287. maskCtx.fillRect(0, 0, width, height);
  5288. maskCtx.restore();
  5289. var ctx = this.ctx;
  5290. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5291. ctx.save();
  5292. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  5293. ctx.scale(1, -1);
  5294. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  5295. 0, -1, 1, 1);
  5296. ctx.restore();
  5297. }
  5298. },
  5299. paintImageMaskXObjectGroup:
  5300. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  5301. var ctx = this.ctx;
  5302. var fillColor = this.current.fillColor;
  5303. var isPatternFill = this.current.patternFill;
  5304. for (var i = 0, ii = images.length; i < ii; i++) {
  5305. var image = images[i];
  5306. var width = image.width, height = image.height;
  5307. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5308. width, height);
  5309. var maskCtx = maskCanvas.context;
  5310. maskCtx.save();
  5311. putBinaryImageMask(maskCtx, image);
  5312. maskCtx.globalCompositeOperation = 'source-in';
  5313. maskCtx.fillStyle = isPatternFill ?
  5314. fillColor.getPattern(maskCtx, this) : fillColor;
  5315. maskCtx.fillRect(0, 0, width, height);
  5316. maskCtx.restore();
  5317. ctx.save();
  5318. ctx.transform.apply(ctx, image.transform);
  5319. ctx.scale(1, -1);
  5320. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  5321. 0, -1, 1, 1);
  5322. ctx.restore();
  5323. }
  5324. },
  5325. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5326. var imgData = this.objs.get(objId);
  5327. if (!imgData) {
  5328. warn('Dependent image isn\'t ready yet');
  5329. return;
  5330. }
  5331. this.paintInlineImageXObject(imgData);
  5332. },
  5333. paintImageXObjectRepeat:
  5334. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  5335. positions) {
  5336. var imgData = this.objs.get(objId);
  5337. if (!imgData) {
  5338. warn('Dependent image isn\'t ready yet');
  5339. return;
  5340. }
  5341. var width = imgData.width;
  5342. var height = imgData.height;
  5343. var map = [];
  5344. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5345. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  5346. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  5347. }
  5348. this.paintInlineImageXObjectGroup(imgData, map);
  5349. },
  5350. paintInlineImageXObject:
  5351. function CanvasGraphics_paintInlineImageXObject(imgData) {
  5352. var width = imgData.width;
  5353. var height = imgData.height;
  5354. var ctx = this.ctx;
  5355. this.save();
  5356. // scale the image to the unit square
  5357. ctx.scale(1 / width, -1 / height);
  5358. var currentTransform = ctx.mozCurrentTransformInverse;
  5359. var a = currentTransform[0], b = currentTransform[1];
  5360. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  5361. var c = currentTransform[2], d = currentTransform[3];
  5362. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  5363. var imgToPaint, tmpCanvas;
  5364. // instanceof HTMLElement does not work in jsdom node.js module
  5365. if (imgData instanceof HTMLElement || !imgData.data) {
  5366. imgToPaint = imgData;
  5367. } else {
  5368. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  5369. width, height);
  5370. var tmpCtx = tmpCanvas.context;
  5371. putBinaryImageData(tmpCtx, imgData);
  5372. imgToPaint = tmpCanvas.canvas;
  5373. }
  5374. var paintWidth = width, paintHeight = height;
  5375. var tmpCanvasId = 'prescale1';
  5376. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  5377. // pixels during drawImage operation, painting on the temporary canvas(es)
  5378. // that are twice smaller in size
  5379. while ((widthScale > 2 && paintWidth > 1) ||
  5380. (heightScale > 2 && paintHeight > 1)) {
  5381. var newWidth = paintWidth, newHeight = paintHeight;
  5382. if (widthScale > 2 && paintWidth > 1) {
  5383. newWidth = Math.ceil(paintWidth / 2);
  5384. widthScale /= paintWidth / newWidth;
  5385. }
  5386. if (heightScale > 2 && paintHeight > 1) {
  5387. newHeight = Math.ceil(paintHeight / 2);
  5388. heightScale /= paintHeight / newHeight;
  5389. }
  5390. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  5391. newWidth, newHeight);
  5392. tmpCtx = tmpCanvas.context;
  5393. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5394. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  5395. 0, 0, newWidth, newHeight);
  5396. imgToPaint = tmpCanvas.canvas;
  5397. paintWidth = newWidth;
  5398. paintHeight = newHeight;
  5399. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  5400. }
  5401. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  5402. 0, -height, width, height);
  5403. if (this.imageLayer) {
  5404. var position = this.getCanvasPosition(0, -height);
  5405. this.imageLayer.appendImage({
  5406. imgData: imgData,
  5407. left: position[0],
  5408. top: position[1],
  5409. width: width / currentTransform[0],
  5410. height: height / currentTransform[3]
  5411. });
  5412. }
  5413. this.restore();
  5414. },
  5415. paintInlineImageXObjectGroup:
  5416. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5417. var ctx = this.ctx;
  5418. var w = imgData.width;
  5419. var h = imgData.height;
  5420. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  5421. var tmpCtx = tmpCanvas.context;
  5422. putBinaryImageData(tmpCtx, imgData);
  5423. for (var i = 0, ii = map.length; i < ii; i++) {
  5424. var entry = map[i];
  5425. ctx.save();
  5426. ctx.transform.apply(ctx, entry.transform);
  5427. ctx.scale(1, -1);
  5428. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  5429. 0, -1, 1, 1);
  5430. if (this.imageLayer) {
  5431. var position = this.getCanvasPosition(entry.x, entry.y);
  5432. this.imageLayer.appendImage({
  5433. imgData: imgData,
  5434. left: position[0],
  5435. top: position[1],
  5436. width: w,
  5437. height: h
  5438. });
  5439. }
  5440. ctx.restore();
  5441. }
  5442. },
  5443. paintSolidColorImageMask:
  5444. function CanvasGraphics_paintSolidColorImageMask() {
  5445. this.ctx.fillRect(0, 0, 1, 1);
  5446. },
  5447. paintXObject: function CanvasGraphics_paintXObject() {
  5448. warn('Unsupported \'paintXObject\' command.');
  5449. },
  5450. // Marked content
  5451. markPoint: function CanvasGraphics_markPoint(tag) {
  5452. // TODO Marked content.
  5453. },
  5454. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  5455. // TODO Marked content.
  5456. },
  5457. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  5458. // TODO Marked content.
  5459. },
  5460. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  5461. tag, properties) {
  5462. // TODO Marked content.
  5463. },
  5464. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  5465. // TODO Marked content.
  5466. },
  5467. // Compatibility
  5468. beginCompat: function CanvasGraphics_beginCompat() {
  5469. // TODO ignore undefined operators (should we do that anyway?)
  5470. },
  5471. endCompat: function CanvasGraphics_endCompat() {
  5472. // TODO stop ignoring undefined operators
  5473. },
  5474. // Helper functions
  5475. consumePath: function CanvasGraphics_consumePath() {
  5476. var ctx = this.ctx;
  5477. if (this.pendingClip) {
  5478. if (this.pendingClip === EO_CLIP) {
  5479. if (ctx.mozFillRule !== undefined) {
  5480. ctx.mozFillRule = 'evenodd';
  5481. ctx.clip();
  5482. ctx.mozFillRule = 'nonzero';
  5483. } else {
  5484. ctx.clip('evenodd');
  5485. }
  5486. } else {
  5487. ctx.clip();
  5488. }
  5489. this.pendingClip = null;
  5490. }
  5491. ctx.beginPath();
  5492. },
  5493. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  5494. if (this.cachedGetSinglePixelWidth === null) {
  5495. var inverse = this.ctx.mozCurrentTransformInverse;
  5496. // max of the current horizontal and vertical scale
  5497. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  5498. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  5499. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  5500. }
  5501. return this.cachedGetSinglePixelWidth;
  5502. },
  5503. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5504. var transform = this.ctx.mozCurrentTransform;
  5505. return [
  5506. transform[0] * x + transform[2] * y + transform[4],
  5507. transform[1] * x + transform[3] * y + transform[5]
  5508. ];
  5509. }
  5510. };
  5511. for (var op in OPS) {
  5512. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  5513. }
  5514. return CanvasGraphics;
  5515. })();
  5516. exports.CanvasGraphics = CanvasGraphics;
  5517. exports.createScratchCanvas = createScratchCanvas;
  5518. }));
  5519. (function (root, factory) {
  5520. {
  5521. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  5522. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  5523. root.pdfjsSharedGlobal);
  5524. }
  5525. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  5526. sharedGlobal, amdRequire) {
  5527. var InvalidPDFException = sharedUtil.InvalidPDFException;
  5528. var MessageHandler = sharedUtil.MessageHandler;
  5529. var MissingPDFException = sharedUtil.MissingPDFException;
  5530. var PasswordResponses = sharedUtil.PasswordResponses;
  5531. var PasswordException = sharedUtil.PasswordException;
  5532. var StatTimer = sharedUtil.StatTimer;
  5533. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  5534. var UnknownErrorException = sharedUtil.UnknownErrorException;
  5535. var Util = sharedUtil.Util;
  5536. var createPromiseCapability = sharedUtil.createPromiseCapability;
  5537. var combineUrl = sharedUtil.combineUrl;
  5538. var error = sharedUtil.error;
  5539. var deprecated = sharedUtil.deprecated;
  5540. var info = sharedUtil.info;
  5541. var isArrayBuffer = sharedUtil.isArrayBuffer;
  5542. var loadJpegStream = sharedUtil.loadJpegStream;
  5543. var stringToBytes = sharedUtil.stringToBytes;
  5544. var warn = sharedUtil.warn;
  5545. var FontFaceObject = displayFontLoader.FontFaceObject;
  5546. var FontLoader = displayFontLoader.FontLoader;
  5547. var CanvasGraphics = displayCanvas.CanvasGraphics;
  5548. var createScratchCanvas = displayCanvas.createScratchCanvas;
  5549. var PDFJS = sharedGlobal.PDFJS;
  5550. var globalScope = sharedGlobal.globalScope;
  5551. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  5552. /**
  5553. * The maximum allowed image size in total pixels e.g. width * height. Images
  5554. * above this value will not be drawn. Use -1 for no limit.
  5555. * @var {number}
  5556. */
  5557. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  5558. -1 : PDFJS.maxImageSize);
  5559. /**
  5560. * The url of where the predefined Adobe CMaps are located. Include trailing
  5561. * slash.
  5562. * @var {string}
  5563. */
  5564. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  5565. /**
  5566. * Specifies if CMaps are binary packed.
  5567. * @var {boolean}
  5568. */
  5569. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  5570. /**
  5571. * By default fonts are converted to OpenType fonts and loaded via font face
  5572. * rules. If disabled, the font will be rendered using a built in font renderer
  5573. * that constructs the glyphs with primitive path commands.
  5574. * @var {boolean}
  5575. */
  5576. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  5577. false : PDFJS.disableFontFace);
  5578. /**
  5579. * Path for image resources, mainly for annotation icons. Include trailing
  5580. * slash.
  5581. * @var {string}
  5582. */
  5583. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  5584. '' : PDFJS.imageResourcesPath);
  5585. /**
  5586. * Disable the web worker and run all code on the main thread. This will happen
  5587. * automatically if the browser doesn't support workers or sending typed arrays
  5588. * to workers.
  5589. * @var {boolean}
  5590. */
  5591. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  5592. false : PDFJS.disableWorker);
  5593. /**
  5594. * Path and filename of the worker file. Required when the worker is enabled in
  5595. * development mode. If unspecified in the production build, the worker will be
  5596. * loaded based on the location of the pdf.js file. It is recommended that
  5597. * the workerSrc is set in a custom application to prevent issues caused by
  5598. * third-party frameworks and libraries.
  5599. * @var {string}
  5600. */
  5601. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  5602. /**
  5603. * Disable range request loading of PDF files. When enabled and if the server
  5604. * supports partial content requests then the PDF will be fetched in chunks.
  5605. * Enabled (false) by default.
  5606. * @var {boolean}
  5607. */
  5608. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  5609. false : PDFJS.disableRange);
  5610. /**
  5611. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  5612. * in chunks. This default behavior can be disabled.
  5613. * @var {boolean}
  5614. */
  5615. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  5616. false : PDFJS.disableStream);
  5617. /**
  5618. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  5619. * will automatically keep fetching more data even if it isn't needed to display
  5620. * the current page. This default behavior can be disabled.
  5621. *
  5622. * NOTE: It is also necessary to disable streaming, see above,
  5623. * in order for disabling of pre-fetching to work correctly.
  5624. * @var {boolean}
  5625. */
  5626. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  5627. false : PDFJS.disableAutoFetch);
  5628. /**
  5629. * Enables special hooks for debugging PDF.js.
  5630. * @var {boolean}
  5631. */
  5632. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  5633. /**
  5634. * Enables transfer usage in postMessage for ArrayBuffers.
  5635. * @var {boolean}
  5636. */
  5637. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  5638. true : PDFJS.postMessageTransfers);
  5639. /**
  5640. * Disables URL.createObjectURL usage.
  5641. * @var {boolean}
  5642. */
  5643. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  5644. false : PDFJS.disableCreateObjectURL);
  5645. /**
  5646. * Disables WebGL usage.
  5647. * @var {boolean}
  5648. */
  5649. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  5650. true : PDFJS.disableWebGL);
  5651. /**
  5652. * Disables fullscreen support, and by extension Presentation Mode,
  5653. * in browsers which support the fullscreen API.
  5654. * @var {boolean}
  5655. */
  5656. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  5657. false : PDFJS.disableFullscreen);
  5658. /**
  5659. * Enables CSS only zooming.
  5660. * @var {boolean}
  5661. */
  5662. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  5663. false : PDFJS.useOnlyCssZoom);
  5664. /**
  5665. * Controls the logging level.
  5666. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  5667. * - errors
  5668. * - warnings [default]
  5669. * - infos
  5670. * @var {number}
  5671. */
  5672. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  5673. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  5674. /**
  5675. * The maximum supported canvas size in total pixels e.g. width * height.
  5676. * The default value is 4096 * 4096. Use -1 for no limit.
  5677. * @var {number}
  5678. */
  5679. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  5680. 16777216 : PDFJS.maxCanvasPixels);
  5681. /**
  5682. * (Deprecated) Opens external links in a new window if enabled.
  5683. * The default behavior opens external links in the PDF.js window.
  5684. *
  5685. * NOTE: This property has been deprecated, please use
  5686. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  5687. * @var {boolean}
  5688. */
  5689. PDFJS.openExternalLinksInNewWindow = (
  5690. PDFJS.openExternalLinksInNewWindow === undefined ?
  5691. false : PDFJS.openExternalLinksInNewWindow);
  5692. /**
  5693. * Specifies the |target| attribute for external links.
  5694. * The constants from PDFJS.LinkTarget should be used:
  5695. * - NONE [default]
  5696. * - SELF
  5697. * - BLANK
  5698. * - PARENT
  5699. * - TOP
  5700. * @var {number}
  5701. */
  5702. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  5703. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  5704. /**
  5705. * Specifies the |rel| attribute for external links. Defaults to stripping
  5706. * the referrer.
  5707. * @var {string}
  5708. */
  5709. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  5710. 'noreferrer' : PDFJS.externalLinkRel);
  5711. /**
  5712. * Determines if we can eval strings as JS. Primarily used to improve
  5713. * performance for font rendering.
  5714. * @var {boolean}
  5715. */
  5716. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  5717. true : PDFJS.isEvalSupported);
  5718. /**
  5719. * Document initialization / loading parameters object.
  5720. *
  5721. * @typedef {Object} DocumentInitParameters
  5722. * @property {string} url - The URL of the PDF.
  5723. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  5724. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  5725. * use atob() to convert it to a binary string first.
  5726. * @property {Object} httpHeaders - Basic authentication headers.
  5727. * @property {boolean} withCredentials - Indicates whether or not cross-site
  5728. * Access-Control requests should be made using credentials such as cookies
  5729. * or authorization headers. The default is false.
  5730. * @property {string} password - For decrypting password-protected PDFs.
  5731. * @property {TypedArray} initialData - A typed array with the first portion or
  5732. * all of the pdf data. Used by the extension since some data is already
  5733. * loaded before the switch to range requests.
  5734. * @property {number} length - The PDF file length. It's used for progress
  5735. * reports and range requests operations.
  5736. * @property {PDFDataRangeTransport} range
  5737. * @property {number} rangeChunkSize - Optional parameter to specify
  5738. * maximum number of bytes fetched per range request. The default value is
  5739. * 2^16 = 65536.
  5740. * @property {PDFWorker} worker - The worker that will be used for the loading
  5741. * and parsing of the PDF data.
  5742. */
  5743. /**
  5744. * @typedef {Object} PDFDocumentStats
  5745. * @property {Array} streamTypes - Used stream types in the document (an item
  5746. * is set to true if specific stream ID was used in the document).
  5747. * @property {Array} fontTypes - Used font type in the document (an item is set
  5748. * to true if specific font ID was used in the document).
  5749. */
  5750. /**
  5751. * This is the main entry point for loading a PDF and interacting with it.
  5752. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  5753. * is used, which means it must follow the same origin rules that any XHR does
  5754. * e.g. No cross domain requests without CORS.
  5755. *
  5756. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  5757. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  5758. * already populated with data or parameter object.
  5759. *
  5760. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  5761. * if you want to manually serve range requests for data in the PDF.
  5762. *
  5763. * @param {function} passwordCallback (deprecated) It is used to request a
  5764. * password if wrong or no password was provided. The callback receives two
  5765. * parameters: function that needs to be called with new password and reason
  5766. * (see {PasswordResponses}).
  5767. *
  5768. * @param {function} progressCallback (deprecated) It is used to be able to
  5769. * monitor the loading progress of the PDF file (necessary to implement e.g.
  5770. * a loading bar). The callback receives an {Object} with the properties:
  5771. * {number} loaded and {number} total.
  5772. *
  5773. * @return {PDFDocumentLoadingTask}
  5774. */
  5775. PDFJS.getDocument = function getDocument(src,
  5776. pdfDataRangeTransport,
  5777. passwordCallback,
  5778. progressCallback) {
  5779. var task = new PDFDocumentLoadingTask();
  5780. // Support of the obsolete arguments (for compatibility with API v1.0)
  5781. if (arguments.length > 1) {
  5782. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  5783. 'passwordCallback or progressCallback argument');
  5784. }
  5785. if (pdfDataRangeTransport) {
  5786. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  5787. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  5788. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  5789. pdfDataRangeTransport.length = src.length;
  5790. pdfDataRangeTransport.initialData = src.initialData;
  5791. if (!pdfDataRangeTransport.abort) {
  5792. pdfDataRangeTransport.abort = function () {};
  5793. }
  5794. }
  5795. src = Object.create(src);
  5796. src.range = pdfDataRangeTransport;
  5797. }
  5798. task.onPassword = passwordCallback || null;
  5799. task.onProgress = progressCallback || null;
  5800. var source;
  5801. if (typeof src === 'string') {
  5802. source = { url: src };
  5803. } else if (isArrayBuffer(src)) {
  5804. source = { data: src };
  5805. } else if (src instanceof PDFDataRangeTransport) {
  5806. source = { range: src };
  5807. } else {
  5808. if (typeof src !== 'object') {
  5809. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  5810. 'string or a parameter object');
  5811. }
  5812. if (!src.url && !src.data && !src.range) {
  5813. error('Invalid parameter object: need either .data, .range or .url');
  5814. }
  5815. source = src;
  5816. }
  5817. var params = {};
  5818. var rangeTransport = null;
  5819. var worker = null;
  5820. for (var key in source) {
  5821. if (key === 'url' && typeof window !== 'undefined') {
  5822. // The full path is required in the 'url' field.
  5823. params[key] = combineUrl(window.location.href, source[key]);
  5824. continue;
  5825. } else if (key === 'range') {
  5826. rangeTransport = source[key];
  5827. continue;
  5828. } else if (key === 'worker') {
  5829. worker = source[key];
  5830. continue;
  5831. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  5832. // Converting string or array-like data to Uint8Array.
  5833. var pdfBytes = source[key];
  5834. if (typeof pdfBytes === 'string') {
  5835. params[key] = stringToBytes(pdfBytes);
  5836. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  5837. !isNaN(pdfBytes.length)) {
  5838. params[key] = new Uint8Array(pdfBytes);
  5839. } else if (isArrayBuffer(pdfBytes)) {
  5840. params[key] = new Uint8Array(pdfBytes);
  5841. } else {
  5842. error('Invalid PDF binary data: either typed array, string or ' +
  5843. 'array-like object is expected in the data property.');
  5844. }
  5845. continue;
  5846. }
  5847. params[key] = source[key];
  5848. }
  5849. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  5850. if (!worker) {
  5851. // Worker was not provided -- creating and owning our own.
  5852. worker = new PDFWorker();
  5853. task._worker = worker;
  5854. }
  5855. var docId = task.docId;
  5856. worker.promise.then(function () {
  5857. if (task.destroyed) {
  5858. throw new Error('Loading aborted');
  5859. }
  5860. return _fetchDocument(worker, params, rangeTransport, docId).then(
  5861. function (workerId) {
  5862. if (task.destroyed) {
  5863. throw new Error('Loading aborted');
  5864. }
  5865. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  5866. messageHandler.send('Ready', null);
  5867. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  5868. task._transport = transport;
  5869. });
  5870. }, task._capability.reject);
  5871. return task;
  5872. };
  5873. /**
  5874. * Starts fetching of specified PDF document/data.
  5875. * @param {PDFWorker} worker
  5876. * @param {Object} source
  5877. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  5878. * @param {string} docId Unique document id, used as MessageHandler id.
  5879. * @returns {Promise} The promise, which is resolved when worker id of
  5880. * MessageHandler is known.
  5881. * @private
  5882. */
  5883. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  5884. if (worker.destroyed) {
  5885. return Promise.reject(new Error('Worker was destroyed'));
  5886. }
  5887. source.disableAutoFetch = PDFJS.disableAutoFetch;
  5888. source.disableStream = PDFJS.disableStream;
  5889. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  5890. if (pdfDataRangeTransport) {
  5891. source.length = pdfDataRangeTransport.length;
  5892. source.initialData = pdfDataRangeTransport.initialData;
  5893. }
  5894. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  5895. docId: docId,
  5896. source: source,
  5897. disableRange: PDFJS.disableRange,
  5898. maxImageSize: PDFJS.maxImageSize,
  5899. cMapUrl: PDFJS.cMapUrl,
  5900. cMapPacked: PDFJS.cMapPacked,
  5901. disableFontFace: PDFJS.disableFontFace,
  5902. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  5903. verbosity: PDFJS.verbosity
  5904. }).then(function (workerId) {
  5905. if (worker.destroyed) {
  5906. throw new Error('Worker was destroyed');
  5907. }
  5908. return workerId;
  5909. });
  5910. }
  5911. /**
  5912. * PDF document loading operation.
  5913. * @class
  5914. * @alias PDFDocumentLoadingTask
  5915. */
  5916. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  5917. var nextDocumentId = 0;
  5918. /** @constructs PDFDocumentLoadingTask */
  5919. function PDFDocumentLoadingTask() {
  5920. this._capability = createPromiseCapability();
  5921. this._transport = null;
  5922. this._worker = null;
  5923. /**
  5924. * Unique document loading task id -- used in MessageHandlers.
  5925. * @type {string}
  5926. */
  5927. this.docId = 'd' + (nextDocumentId++);
  5928. /**
  5929. * Shows if loading task is destroyed.
  5930. * @type {boolean}
  5931. */
  5932. this.destroyed = false;
  5933. /**
  5934. * Callback to request a password if wrong or no password was provided.
  5935. * The callback receives two parameters: function that needs to be called
  5936. * with new password and reason (see {PasswordResponses}).
  5937. */
  5938. this.onPassword = null;
  5939. /**
  5940. * Callback to be able to monitor the loading progress of the PDF file
  5941. * (necessary to implement e.g. a loading bar). The callback receives
  5942. * an {Object} with the properties: {number} loaded and {number} total.
  5943. */
  5944. this.onProgress = null;
  5945. /**
  5946. * Callback to when unsupported feature is used. The callback receives
  5947. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  5948. */
  5949. this.onUnsupportedFeature = null;
  5950. }
  5951. PDFDocumentLoadingTask.prototype =
  5952. /** @lends PDFDocumentLoadingTask.prototype */ {
  5953. /**
  5954. * @return {Promise}
  5955. */
  5956. get promise() {
  5957. return this._capability.promise;
  5958. },
  5959. /**
  5960. * Aborts all network requests and destroys worker.
  5961. * @return {Promise} A promise that is resolved after destruction activity
  5962. * is completed.
  5963. */
  5964. destroy: function () {
  5965. this.destroyed = true;
  5966. var transportDestroyed = !this._transport ? Promise.resolve() :
  5967. this._transport.destroy();
  5968. return transportDestroyed.then(function () {
  5969. this._transport = null;
  5970. if (this._worker) {
  5971. this._worker.destroy();
  5972. this._worker = null;
  5973. }
  5974. }.bind(this));
  5975. },
  5976. /**
  5977. * Registers callbacks to indicate the document loading completion.
  5978. *
  5979. * @param {function} onFulfilled The callback for the loading completion.
  5980. * @param {function} onRejected The callback for the loading failure.
  5981. * @return {Promise} A promise that is resolved after the onFulfilled or
  5982. * onRejected callback.
  5983. */
  5984. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  5985. return this.promise.then.apply(this.promise, arguments);
  5986. }
  5987. };
  5988. return PDFDocumentLoadingTask;
  5989. })();
  5990. /**
  5991. * Abstract class to support range requests file loading.
  5992. * @class
  5993. * @alias PDFJS.PDFDataRangeTransport
  5994. * @param {number} length
  5995. * @param {Uint8Array} initialData
  5996. */
  5997. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  5998. function PDFDataRangeTransport(length, initialData) {
  5999. this.length = length;
  6000. this.initialData = initialData;
  6001. this._rangeListeners = [];
  6002. this._progressListeners = [];
  6003. this._progressiveReadListeners = [];
  6004. this._readyCapability = createPromiseCapability();
  6005. }
  6006. PDFDataRangeTransport.prototype =
  6007. /** @lends PDFDataRangeTransport.prototype */ {
  6008. addRangeListener:
  6009. function PDFDataRangeTransport_addRangeListener(listener) {
  6010. this._rangeListeners.push(listener);
  6011. },
  6012. addProgressListener:
  6013. function PDFDataRangeTransport_addProgressListener(listener) {
  6014. this._progressListeners.push(listener);
  6015. },
  6016. addProgressiveReadListener:
  6017. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  6018. this._progressiveReadListeners.push(listener);
  6019. },
  6020. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  6021. var listeners = this._rangeListeners;
  6022. for (var i = 0, n = listeners.length; i < n; ++i) {
  6023. listeners[i](begin, chunk);
  6024. }
  6025. },
  6026. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  6027. this._readyCapability.promise.then(function () {
  6028. var listeners = this._progressListeners;
  6029. for (var i = 0, n = listeners.length; i < n; ++i) {
  6030. listeners[i](loaded);
  6031. }
  6032. }.bind(this));
  6033. },
  6034. onDataProgressiveRead:
  6035. function PDFDataRangeTransport_onDataProgress(chunk) {
  6036. this._readyCapability.promise.then(function () {
  6037. var listeners = this._progressiveReadListeners;
  6038. for (var i = 0, n = listeners.length; i < n; ++i) {
  6039. listeners[i](chunk);
  6040. }
  6041. }.bind(this));
  6042. },
  6043. transportReady: function PDFDataRangeTransport_transportReady() {
  6044. this._readyCapability.resolve();
  6045. },
  6046. requestDataRange:
  6047. function PDFDataRangeTransport_requestDataRange(begin, end) {
  6048. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  6049. },
  6050. abort: function PDFDataRangeTransport_abort() {
  6051. }
  6052. };
  6053. return PDFDataRangeTransport;
  6054. })();
  6055. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  6056. /**
  6057. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  6058. * properties that can be read synchronously.
  6059. * @class
  6060. * @alias PDFDocumentProxy
  6061. */
  6062. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  6063. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  6064. this.pdfInfo = pdfInfo;
  6065. this.transport = transport;
  6066. this.loadingTask = loadingTask;
  6067. }
  6068. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  6069. /**
  6070. * @return {number} Total number of pages the PDF contains.
  6071. */
  6072. get numPages() {
  6073. return this.pdfInfo.numPages;
  6074. },
  6075. /**
  6076. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  6077. * unique.
  6078. */
  6079. get fingerprint() {
  6080. return this.pdfInfo.fingerprint;
  6081. },
  6082. /**
  6083. * @param {number} pageNumber The page number to get. The first page is 1.
  6084. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  6085. * object.
  6086. */
  6087. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  6088. return this.transport.getPage(pageNumber);
  6089. },
  6090. /**
  6091. * @param {{num: number, gen: number}} ref The page reference. Must have
  6092. * the 'num' and 'gen' properties.
  6093. * @return {Promise} A promise that is resolved with the page index that is
  6094. * associated with the reference.
  6095. */
  6096. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  6097. return this.transport.getPageIndex(ref);
  6098. },
  6099. /**
  6100. * @return {Promise} A promise that is resolved with a lookup table for
  6101. * mapping named destinations to reference numbers.
  6102. *
  6103. * This can be slow for large documents: use getDestination instead
  6104. */
  6105. getDestinations: function PDFDocumentProxy_getDestinations() {
  6106. return this.transport.getDestinations();
  6107. },
  6108. /**
  6109. * @param {string} id The named destination to get.
  6110. * @return {Promise} A promise that is resolved with all information
  6111. * of the given named destination.
  6112. */
  6113. getDestination: function PDFDocumentProxy_getDestination(id) {
  6114. return this.transport.getDestination(id);
  6115. },
  6116. /**
  6117. * @return {Promise} A promise that is resolved with a lookup table for
  6118. * mapping named attachments to their content.
  6119. */
  6120. getAttachments: function PDFDocumentProxy_getAttachments() {
  6121. return this.transport.getAttachments();
  6122. },
  6123. /**
  6124. * @return {Promise} A promise that is resolved with an array of all the
  6125. * JavaScript strings in the name tree.
  6126. */
  6127. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  6128. return this.transport.getJavaScript();
  6129. },
  6130. /**
  6131. * @return {Promise} A promise that is resolved with an {Array} that is a
  6132. * tree outline (if it has one) of the PDF. The tree is in the format of:
  6133. * [
  6134. * {
  6135. * title: string,
  6136. * bold: boolean,
  6137. * italic: boolean,
  6138. * color: rgb array,
  6139. * dest: dest obj,
  6140. * items: array of more items like this
  6141. * },
  6142. * ...
  6143. * ].
  6144. */
  6145. getOutline: function PDFDocumentProxy_getOutline() {
  6146. return this.transport.getOutline();
  6147. },
  6148. /**
  6149. * @return {Promise} A promise that is resolved with an {Object} that has
  6150. * info and metadata properties. Info is an {Object} filled with anything
  6151. * available in the information dictionary and similarly metadata is a
  6152. * {Metadata} object with information from the metadata section of the PDF.
  6153. */
  6154. getMetadata: function PDFDocumentProxy_getMetadata() {
  6155. return this.transport.getMetadata();
  6156. },
  6157. /**
  6158. * @return {Promise} A promise that is resolved with a TypedArray that has
  6159. * the raw data from the PDF.
  6160. */
  6161. getData: function PDFDocumentProxy_getData() {
  6162. return this.transport.getData();
  6163. },
  6164. /**
  6165. * @return {Promise} A promise that is resolved when the document's data
  6166. * is loaded. It is resolved with an {Object} that contains the length
  6167. * property that indicates size of the PDF data in bytes.
  6168. */
  6169. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  6170. return this.transport.downloadInfoCapability.promise;
  6171. },
  6172. /**
  6173. * @return {Promise} A promise this is resolved with current stats about
  6174. * document structures (see {@link PDFDocumentStats}).
  6175. */
  6176. getStats: function PDFDocumentProxy_getStats() {
  6177. return this.transport.getStats();
  6178. },
  6179. /**
  6180. * Cleans up resources allocated by the document, e.g. created @font-face.
  6181. */
  6182. cleanup: function PDFDocumentProxy_cleanup() {
  6183. this.transport.startCleanup();
  6184. },
  6185. /**
  6186. * Destroys current document instance and terminates worker.
  6187. */
  6188. destroy: function PDFDocumentProxy_destroy() {
  6189. return this.loadingTask.destroy();
  6190. }
  6191. };
  6192. return PDFDocumentProxy;
  6193. })();
  6194. /**
  6195. * Page getTextContent parameters.
  6196. *
  6197. * @typedef {Object} getTextContentParameters
  6198. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  6199. * whitespace with standard spaces (0x20). The default value is `false`.
  6200. */
  6201. /**
  6202. * Page text content.
  6203. *
  6204. * @typedef {Object} TextContent
  6205. * @property {array} items - array of {@link TextItem}
  6206. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  6207. * name.
  6208. */
  6209. /**
  6210. * Page text content part.
  6211. *
  6212. * @typedef {Object} TextItem
  6213. * @property {string} str - text content.
  6214. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  6215. * @property {array} transform - transformation matrix.
  6216. * @property {number} width - width in device space.
  6217. * @property {number} height - height in device space.
  6218. * @property {string} fontName - font name used by pdf.js for converted font.
  6219. */
  6220. /**
  6221. * Text style.
  6222. *
  6223. * @typedef {Object} TextStyle
  6224. * @property {number} ascent - font ascent.
  6225. * @property {number} descent - font descent.
  6226. * @property {boolean} vertical - text is in vertical mode.
  6227. * @property {string} fontFamily - possible font family
  6228. */
  6229. /**
  6230. * Page annotation parameters.
  6231. *
  6232. * @typedef {Object} GetAnnotationsParameters
  6233. * @param {string} intent - Determines the annotations that will be fetched,
  6234. * can be either 'display' (viewable annotations) or 'print'
  6235. * (printable annotations).
  6236. * If the parameter is omitted, all annotations are fetched.
  6237. */
  6238. /**
  6239. * Page render parameters.
  6240. *
  6241. * @typedef {Object} RenderParameters
  6242. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  6243. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  6244. * calling of PDFPage.getViewport method.
  6245. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  6246. * (default value is 'display').
  6247. * @property {Array} transform - (optional) Additional transform, applied
  6248. * just before viewport transform.
  6249. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  6250. * endLayout and appendImage functions.
  6251. * @property {function} continueCallback - (deprecated) A function that will be
  6252. * called each time the rendering is paused. To continue
  6253. * rendering call the function that is the first argument
  6254. * to the callback.
  6255. */
  6256. /**
  6257. * PDF page operator list.
  6258. *
  6259. * @typedef {Object} PDFOperatorList
  6260. * @property {Array} fnArray - Array containing the operator functions.
  6261. * @property {Array} argsArray - Array containing the arguments of the
  6262. * functions.
  6263. */
  6264. /**
  6265. * Proxy to a PDFPage in the worker thread.
  6266. * @class
  6267. * @alias PDFPageProxy
  6268. */
  6269. var PDFPageProxy = (function PDFPageProxyClosure() {
  6270. function PDFPageProxy(pageIndex, pageInfo, transport) {
  6271. this.pageIndex = pageIndex;
  6272. this.pageInfo = pageInfo;
  6273. this.transport = transport;
  6274. this.stats = new StatTimer();
  6275. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  6276. this.commonObjs = transport.commonObjs;
  6277. this.objs = new PDFObjects();
  6278. this.cleanupAfterRender = false;
  6279. this.pendingCleanup = false;
  6280. this.intentStates = {};
  6281. this.destroyed = false;
  6282. }
  6283. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  6284. /**
  6285. * @return {number} Page number of the page. First page is 1.
  6286. */
  6287. get pageNumber() {
  6288. return this.pageIndex + 1;
  6289. },
  6290. /**
  6291. * @return {number} The number of degrees the page is rotated clockwise.
  6292. */
  6293. get rotate() {
  6294. return this.pageInfo.rotate;
  6295. },
  6296. /**
  6297. * @return {Object} The reference that points to this page. It has 'num' and
  6298. * 'gen' properties.
  6299. */
  6300. get ref() {
  6301. return this.pageInfo.ref;
  6302. },
  6303. /**
  6304. * @return {Array} An array of the visible portion of the PDF page in the
  6305. * user space units - [x1, y1, x2, y2].
  6306. */
  6307. get view() {
  6308. return this.pageInfo.view;
  6309. },
  6310. /**
  6311. * @param {number} scale The desired scale of the viewport.
  6312. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  6313. * defaults to the page rotation.
  6314. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  6315. * along with transforms required for rendering.
  6316. */
  6317. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  6318. if (arguments.length < 2) {
  6319. rotate = this.rotate;
  6320. }
  6321. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  6322. },
  6323. /**
  6324. * @param {GetAnnotationsParameters} params - Annotation parameters.
  6325. * @return {Promise} A promise that is resolved with an {Array} of the
  6326. * annotation objects.
  6327. */
  6328. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  6329. var intent = (params && params.intent) || null;
  6330. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  6331. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  6332. intent);
  6333. this.annotationsIntent = intent;
  6334. }
  6335. return this.annotationsPromise;
  6336. },
  6337. /**
  6338. * Begins the process of rendering a page to the desired context.
  6339. * @param {RenderParameters} params Page render parameters.
  6340. * @return {RenderTask} An object that contains the promise, which
  6341. * is resolved when the page finishes rendering.
  6342. */
  6343. render: function PDFPageProxy_render(params) {
  6344. var stats = this.stats;
  6345. stats.time('Overall');
  6346. // If there was a pending destroy cancel it so no cleanup happens during
  6347. // this call to render.
  6348. this.pendingCleanup = false;
  6349. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  6350. if (!this.intentStates[renderingIntent]) {
  6351. this.intentStates[renderingIntent] = {};
  6352. }
  6353. var intentState = this.intentStates[renderingIntent];
  6354. // If there's no displayReadyCapability yet, then the operatorList
  6355. // was never requested before. Make the request and create the promise.
  6356. if (!intentState.displayReadyCapability) {
  6357. intentState.receivingOperatorList = true;
  6358. intentState.displayReadyCapability = createPromiseCapability();
  6359. intentState.operatorList = {
  6360. fnArray: [],
  6361. argsArray: [],
  6362. lastChunk: false
  6363. };
  6364. this.stats.time('Page Request');
  6365. this.transport.messageHandler.send('RenderPageRequest', {
  6366. pageIndex: this.pageNumber - 1,
  6367. intent: renderingIntent
  6368. });
  6369. }
  6370. var internalRenderTask = new InternalRenderTask(complete, params,
  6371. this.objs,
  6372. this.commonObjs,
  6373. intentState.operatorList,
  6374. this.pageNumber);
  6375. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  6376. if (!intentState.renderTasks) {
  6377. intentState.renderTasks = [];
  6378. }
  6379. intentState.renderTasks.push(internalRenderTask);
  6380. var renderTask = internalRenderTask.task;
  6381. // Obsolete parameter support
  6382. if (params.continueCallback) {
  6383. deprecated('render is used with continueCallback parameter');
  6384. renderTask.onContinue = params.continueCallback;
  6385. }
  6386. var self = this;
  6387. intentState.displayReadyCapability.promise.then(
  6388. function pageDisplayReadyPromise(transparency) {
  6389. if (self.pendingCleanup) {
  6390. complete();
  6391. return;
  6392. }
  6393. stats.time('Rendering');
  6394. internalRenderTask.initalizeGraphics(transparency);
  6395. internalRenderTask.operatorListChanged();
  6396. },
  6397. function pageDisplayReadPromiseError(reason) {
  6398. complete(reason);
  6399. }
  6400. );
  6401. function complete(error) {
  6402. var i = intentState.renderTasks.indexOf(internalRenderTask);
  6403. if (i >= 0) {
  6404. intentState.renderTasks.splice(i, 1);
  6405. }
  6406. if (self.cleanupAfterRender) {
  6407. self.pendingCleanup = true;
  6408. }
  6409. self._tryCleanup();
  6410. if (error) {
  6411. internalRenderTask.capability.reject(error);
  6412. } else {
  6413. internalRenderTask.capability.resolve();
  6414. }
  6415. stats.timeEnd('Rendering');
  6416. stats.timeEnd('Overall');
  6417. }
  6418. return renderTask;
  6419. },
  6420. /**
  6421. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  6422. * object that represents page's operator list.
  6423. */
  6424. getOperatorList: function PDFPageProxy_getOperatorList() {
  6425. function operatorListChanged() {
  6426. if (intentState.operatorList.lastChunk) {
  6427. intentState.opListReadCapability.resolve(intentState.operatorList);
  6428. }
  6429. }
  6430. var renderingIntent = 'oplist';
  6431. if (!this.intentStates[renderingIntent]) {
  6432. this.intentStates[renderingIntent] = {};
  6433. }
  6434. var intentState = this.intentStates[renderingIntent];
  6435. if (!intentState.opListReadCapability) {
  6436. var opListTask = {};
  6437. opListTask.operatorListChanged = operatorListChanged;
  6438. intentState.receivingOperatorList = true;
  6439. intentState.opListReadCapability = createPromiseCapability();
  6440. intentState.renderTasks = [];
  6441. intentState.renderTasks.push(opListTask);
  6442. intentState.operatorList = {
  6443. fnArray: [],
  6444. argsArray: [],
  6445. lastChunk: false
  6446. };
  6447. this.transport.messageHandler.send('RenderPageRequest', {
  6448. pageIndex: this.pageIndex,
  6449. intent: renderingIntent
  6450. });
  6451. }
  6452. return intentState.opListReadCapability.promise;
  6453. },
  6454. /**
  6455. * @param {getTextContentParameters} params - getTextContent parameters.
  6456. * @return {Promise} That is resolved a {@link TextContent}
  6457. * object that represent the page text content.
  6458. */
  6459. getTextContent: function PDFPageProxy_getTextContent(params) {
  6460. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  6461. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  6462. pageIndex: this.pageNumber - 1,
  6463. normalizeWhitespace: normalizeWhitespace,
  6464. });
  6465. },
  6466. /**
  6467. * Destroys page object.
  6468. */
  6469. _destroy: function PDFPageProxy_destroy() {
  6470. this.destroyed = true;
  6471. this.transport.pageCache[this.pageIndex] = null;
  6472. var waitOn = [];
  6473. Object.keys(this.intentStates).forEach(function(intent) {
  6474. var intentState = this.intentStates[intent];
  6475. intentState.renderTasks.forEach(function(renderTask) {
  6476. var renderCompleted = renderTask.capability.promise.
  6477. catch(function () {}); // ignoring failures
  6478. waitOn.push(renderCompleted);
  6479. renderTask.cancel();
  6480. });
  6481. }, this);
  6482. this.objs.clear();
  6483. this.annotationsPromise = null;
  6484. this.pendingCleanup = false;
  6485. return Promise.all(waitOn);
  6486. },
  6487. /**
  6488. * Cleans up resources allocated by the page. (deprecated)
  6489. */
  6490. destroy: function() {
  6491. deprecated('page destroy method, use cleanup() instead');
  6492. this.cleanup();
  6493. },
  6494. /**
  6495. * Cleans up resources allocated by the page.
  6496. */
  6497. cleanup: function PDFPageProxy_cleanup() {
  6498. this.pendingCleanup = true;
  6499. this._tryCleanup();
  6500. },
  6501. /**
  6502. * For internal use only. Attempts to clean up if rendering is in a state
  6503. * where that's possible.
  6504. * @ignore
  6505. */
  6506. _tryCleanup: function PDFPageProxy_tryCleanup() {
  6507. if (!this.pendingCleanup ||
  6508. Object.keys(this.intentStates).some(function(intent) {
  6509. var intentState = this.intentStates[intent];
  6510. return (intentState.renderTasks.length !== 0 ||
  6511. intentState.receivingOperatorList);
  6512. }, this)) {
  6513. return;
  6514. }
  6515. Object.keys(this.intentStates).forEach(function(intent) {
  6516. delete this.intentStates[intent];
  6517. }, this);
  6518. this.objs.clear();
  6519. this.annotationsPromise = null;
  6520. this.pendingCleanup = false;
  6521. },
  6522. /**
  6523. * For internal use only.
  6524. * @ignore
  6525. */
  6526. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  6527. intent) {
  6528. var intentState = this.intentStates[intent];
  6529. // TODO Refactor RenderPageRequest to separate rendering
  6530. // and operator list logic
  6531. if (intentState.displayReadyCapability) {
  6532. intentState.displayReadyCapability.resolve(transparency);
  6533. }
  6534. },
  6535. /**
  6536. * For internal use only.
  6537. * @ignore
  6538. */
  6539. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  6540. intent) {
  6541. var intentState = this.intentStates[intent];
  6542. var i, ii;
  6543. // Add the new chunk to the current operator list.
  6544. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  6545. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  6546. intentState.operatorList.argsArray.push(
  6547. operatorListChunk.argsArray[i]);
  6548. }
  6549. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  6550. // Notify all the rendering tasks there are more operators to be consumed.
  6551. for (i = 0; i < intentState.renderTasks.length; i++) {
  6552. intentState.renderTasks[i].operatorListChanged();
  6553. }
  6554. if (operatorListChunk.lastChunk) {
  6555. intentState.receivingOperatorList = false;
  6556. this._tryCleanup();
  6557. }
  6558. }
  6559. };
  6560. return PDFPageProxy;
  6561. })();
  6562. /**
  6563. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  6564. * WorkerTransport for them. If creation of a web worker is not possible,
  6565. * a "fake" worker will be used instead.
  6566. * @class
  6567. */
  6568. var PDFWorker = (function PDFWorkerClosure() {
  6569. var nextFakeWorkerId = 0;
  6570. // Loads worker code into main thread.
  6571. function setupFakeWorkerGlobal() {
  6572. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  6573. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  6574. // In the developer build load worker_loader which in turn loads all the
  6575. // other files and resolves the promise. In production only the
  6576. // pdf.worker.js file is needed.
  6577. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  6578. }
  6579. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  6580. }
  6581. function PDFWorker(name) {
  6582. this.name = name;
  6583. this.destroyed = false;
  6584. this._readyCapability = createPromiseCapability();
  6585. this._port = null;
  6586. this._webWorker = null;
  6587. this._messageHandler = null;
  6588. this._initialize();
  6589. }
  6590. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  6591. get promise() {
  6592. return this._readyCapability.promise;
  6593. },
  6594. get port() {
  6595. return this._port;
  6596. },
  6597. get messageHandler() {
  6598. return this._messageHandler;
  6599. },
  6600. _initialize: function PDFWorker_initialize() {
  6601. // If worker support isn't disabled explicit and the browser has worker
  6602. // support, create a new web worker and test if it/the browser fullfills
  6603. // all requirements to run parts of pdf.js in a web worker.
  6604. // Right now, the requirement is, that an Uint8Array is still an
  6605. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  6606. // Either workers are disabled, not supported or have thrown an exception.
  6607. // Thus, we fallback to a faked worker.
  6608. this._setupFakeWorker();
  6609. },
  6610. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  6611. if (!globalScope.PDFJS.disableWorker) {
  6612. warn('Setting up fake worker.');
  6613. globalScope.PDFJS.disableWorker = true;
  6614. }
  6615. setupFakeWorkerGlobal().then(function () {
  6616. if (this.destroyed) {
  6617. this._readyCapability.reject(new Error('Worker was destroyed'));
  6618. return;
  6619. }
  6620. // If we don't use a worker, just post/sendMessage to the main thread.
  6621. var port = {
  6622. _listeners: [],
  6623. postMessage: function (obj) {
  6624. var e = {data: obj};
  6625. this._listeners.forEach(function (listener) {
  6626. listener.call(this, e);
  6627. }, this);
  6628. },
  6629. addEventListener: function (name, listener) {
  6630. this._listeners.push(listener);
  6631. },
  6632. removeEventListener: function (name, listener) {
  6633. var i = this._listeners.indexOf(listener);
  6634. this._listeners.splice(i, 1);
  6635. },
  6636. terminate: function () {}
  6637. };
  6638. this._port = port;
  6639. // All fake workers use the same port, making id unique.
  6640. var id = 'fake' + (nextFakeWorkerId++);
  6641. // If the main thread is our worker, setup the handling for the
  6642. // messages -- the main thread sends to it self.
  6643. var workerHandler = new MessageHandler(id + '_worker', id, port);
  6644. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  6645. var messageHandler = new MessageHandler(id, id + '_worker', port);
  6646. this._messageHandler = messageHandler;
  6647. this._readyCapability.resolve();
  6648. }.bind(this));
  6649. },
  6650. /**
  6651. * Destroys the worker instance.
  6652. */
  6653. destroy: function PDFWorker_destroy() {
  6654. this.destroyed = true;
  6655. if (this._webWorker) {
  6656. // We need to terminate only web worker created resource.
  6657. this._webWorker.terminate();
  6658. this._webWorker = null;
  6659. }
  6660. this._port = null;
  6661. if (this._messageHandler) {
  6662. this._messageHandler.destroy();
  6663. this._messageHandler = null;
  6664. }
  6665. }
  6666. };
  6667. return PDFWorker;
  6668. })();
  6669. PDFJS.PDFWorker = PDFWorker;
  6670. /**
  6671. * For internal use only.
  6672. * @ignore
  6673. */
  6674. var WorkerTransport = (function WorkerTransportClosure() {
  6675. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  6676. this.messageHandler = messageHandler;
  6677. this.loadingTask = loadingTask;
  6678. this.pdfDataRangeTransport = pdfDataRangeTransport;
  6679. this.commonObjs = new PDFObjects();
  6680. this.fontLoader = new FontLoader(loadingTask.docId);
  6681. this.destroyed = false;
  6682. this.destroyCapability = null;
  6683. this.pageCache = [];
  6684. this.pagePromises = [];
  6685. this.downloadInfoCapability = createPromiseCapability();
  6686. this.setupMessageHandler();
  6687. }
  6688. WorkerTransport.prototype = {
  6689. destroy: function WorkerTransport_destroy() {
  6690. if (this.destroyCapability) {
  6691. return this.destroyCapability.promise;
  6692. }
  6693. this.destroyed = true;
  6694. this.destroyCapability = createPromiseCapability();
  6695. var waitOn = [];
  6696. // We need to wait for all renderings to be completed, e.g.
  6697. // timeout/rAF can take a long time.
  6698. this.pageCache.forEach(function (page) {
  6699. if (page) {
  6700. waitOn.push(page._destroy());
  6701. }
  6702. });
  6703. this.pageCache = [];
  6704. this.pagePromises = [];
  6705. var self = this;
  6706. // We also need to wait for the worker to finish its long running tasks.
  6707. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  6708. waitOn.push(terminated);
  6709. Promise.all(waitOn).then(function () {
  6710. self.fontLoader.clear();
  6711. if (self.pdfDataRangeTransport) {
  6712. self.pdfDataRangeTransport.abort();
  6713. self.pdfDataRangeTransport = null;
  6714. }
  6715. if (self.messageHandler) {
  6716. self.messageHandler.destroy();
  6717. self.messageHandler = null;
  6718. }
  6719. self.destroyCapability.resolve();
  6720. }, this.destroyCapability.reject);
  6721. return this.destroyCapability.promise;
  6722. },
  6723. setupMessageHandler:
  6724. function WorkerTransport_setupMessageHandler() {
  6725. var messageHandler = this.messageHandler;
  6726. function updatePassword(password) {
  6727. messageHandler.send('UpdatePassword', password);
  6728. }
  6729. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  6730. if (pdfDataRangeTransport) {
  6731. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  6732. messageHandler.send('OnDataRange', {
  6733. begin: begin,
  6734. chunk: chunk
  6735. });
  6736. });
  6737. pdfDataRangeTransport.addProgressListener(function(loaded) {
  6738. messageHandler.send('OnDataProgress', {
  6739. loaded: loaded
  6740. });
  6741. });
  6742. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  6743. messageHandler.send('OnDataRange', {
  6744. chunk: chunk
  6745. });
  6746. });
  6747. messageHandler.on('RequestDataRange',
  6748. function transportDataRange(data) {
  6749. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  6750. }, this);
  6751. }
  6752. messageHandler.on('GetDoc', function transportDoc(data) {
  6753. var pdfInfo = data.pdfInfo;
  6754. this.numPages = data.pdfInfo.numPages;
  6755. var loadingTask = this.loadingTask;
  6756. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  6757. this.pdfDocument = pdfDocument;
  6758. loadingTask._capability.resolve(pdfDocument);
  6759. }, this);
  6760. messageHandler.on('NeedPassword',
  6761. function transportNeedPassword(exception) {
  6762. var loadingTask = this.loadingTask;
  6763. if (loadingTask.onPassword) {
  6764. return loadingTask.onPassword(updatePassword,
  6765. PasswordResponses.NEED_PASSWORD);
  6766. }
  6767. loadingTask._capability.reject(
  6768. new PasswordException(exception.message, exception.code));
  6769. }, this);
  6770. messageHandler.on('IncorrectPassword',
  6771. function transportIncorrectPassword(exception) {
  6772. var loadingTask = this.loadingTask;
  6773. if (loadingTask.onPassword) {
  6774. return loadingTask.onPassword(updatePassword,
  6775. PasswordResponses.INCORRECT_PASSWORD);
  6776. }
  6777. loadingTask._capability.reject(
  6778. new PasswordException(exception.message, exception.code));
  6779. }, this);
  6780. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  6781. this.loadingTask._capability.reject(
  6782. new InvalidPDFException(exception.message));
  6783. }, this);
  6784. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  6785. this.loadingTask._capability.reject(
  6786. new MissingPDFException(exception.message));
  6787. }, this);
  6788. messageHandler.on('UnexpectedResponse',
  6789. function transportUnexpectedResponse(exception) {
  6790. this.loadingTask._capability.reject(
  6791. new UnexpectedResponseException(exception.message, exception.status));
  6792. }, this);
  6793. messageHandler.on('UnknownError',
  6794. function transportUnknownError(exception) {
  6795. this.loadingTask._capability.reject(
  6796. new UnknownErrorException(exception.message, exception.details));
  6797. }, this);
  6798. messageHandler.on('DataLoaded', function transportPage(data) {
  6799. this.downloadInfoCapability.resolve(data);
  6800. }, this);
  6801. messageHandler.on('PDFManagerReady', function transportPage(data) {
  6802. if (this.pdfDataRangeTransport) {
  6803. this.pdfDataRangeTransport.transportReady();
  6804. }
  6805. }, this);
  6806. messageHandler.on('StartRenderPage', function transportRender(data) {
  6807. if (this.destroyed) {
  6808. return; // Ignore any pending requests if the worker was terminated.
  6809. }
  6810. var page = this.pageCache[data.pageIndex];
  6811. page.stats.timeEnd('Page Request');
  6812. page._startRenderPage(data.transparency, data.intent);
  6813. }, this);
  6814. messageHandler.on('RenderPageChunk', function transportRender(data) {
  6815. if (this.destroyed) {
  6816. return; // Ignore any pending requests if the worker was terminated.
  6817. }
  6818. var page = this.pageCache[data.pageIndex];
  6819. page._renderPageChunk(data.operatorList, data.intent);
  6820. }, this);
  6821. messageHandler.on('commonobj', function transportObj(data) {
  6822. if (this.destroyed) {
  6823. return; // Ignore any pending requests if the worker was terminated.
  6824. }
  6825. var id = data[0];
  6826. var type = data[1];
  6827. if (this.commonObjs.hasData(id)) {
  6828. return;
  6829. }
  6830. switch (type) {
  6831. case 'Font':
  6832. var exportedData = data[2];
  6833. var font;
  6834. if ('error' in exportedData) {
  6835. var error = exportedData.error;
  6836. warn('Error during font loading: ' + error);
  6837. this.commonObjs.resolve(id, error);
  6838. break;
  6839. } else {
  6840. font = new FontFaceObject(exportedData);
  6841. }
  6842. this.fontLoader.bind(
  6843. [font],
  6844. function fontReady(fontObjs) {
  6845. this.commonObjs.resolve(id, font);
  6846. }.bind(this)
  6847. );
  6848. break;
  6849. case 'FontPath':
  6850. this.commonObjs.resolve(id, data[2]);
  6851. break;
  6852. default:
  6853. error('Got unknown common object type ' + type);
  6854. }
  6855. }, this);
  6856. messageHandler.on('obj', function transportObj(data) {
  6857. if (this.destroyed) {
  6858. return; // Ignore any pending requests if the worker was terminated.
  6859. }
  6860. var id = data[0];
  6861. var pageIndex = data[1];
  6862. var type = data[2];
  6863. var pageProxy = this.pageCache[pageIndex];
  6864. var imageData;
  6865. if (pageProxy.objs.hasData(id)) {
  6866. return;
  6867. }
  6868. switch (type) {
  6869. case 'JpegStream':
  6870. imageData = data[3];
  6871. loadJpegStream(id, imageData, pageProxy.objs);
  6872. break;
  6873. case 'Image':
  6874. imageData = data[3];
  6875. pageProxy.objs.resolve(id, imageData);
  6876. // heuristics that will allow not to store large data
  6877. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  6878. if (imageData && 'data' in imageData &&
  6879. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  6880. pageProxy.cleanupAfterRender = true;
  6881. }
  6882. break;
  6883. default:
  6884. error('Got unknown object type ' + type);
  6885. }
  6886. }, this);
  6887. messageHandler.on('DocProgress', function transportDocProgress(data) {
  6888. if (this.destroyed) {
  6889. return; // Ignore any pending requests if the worker was terminated.
  6890. }
  6891. var loadingTask = this.loadingTask;
  6892. if (loadingTask.onProgress) {
  6893. loadingTask.onProgress({
  6894. loaded: data.loaded,
  6895. total: data.total
  6896. });
  6897. }
  6898. }, this);
  6899. messageHandler.on('PageError', function transportError(data) {
  6900. if (this.destroyed) {
  6901. return; // Ignore any pending requests if the worker was terminated.
  6902. }
  6903. var page = this.pageCache[data.pageNum - 1];
  6904. var intentState = page.intentStates[data.intent];
  6905. if (intentState.displayReadyCapability) {
  6906. intentState.displayReadyCapability.reject(data.error);
  6907. } else {
  6908. error(data.error);
  6909. }
  6910. }, this);
  6911. messageHandler.on('UnsupportedFeature',
  6912. function transportUnsupportedFeature(data) {
  6913. if (this.destroyed) {
  6914. return; // Ignore any pending requests if the worker was terminated.
  6915. }
  6916. var featureId = data.featureId;
  6917. var loadingTask = this.loadingTask;
  6918. if (loadingTask.onUnsupportedFeature) {
  6919. loadingTask.onUnsupportedFeature(featureId);
  6920. }
  6921. PDFJS.UnsupportedManager.notify(featureId);
  6922. }, this);
  6923. messageHandler.on('JpegDecode', function(data) {
  6924. if (this.destroyed) {
  6925. return Promise.reject('Worker was terminated');
  6926. }
  6927. var imageUrl = data[0];
  6928. var components = data[1];
  6929. if (components !== 3 && components !== 1) {
  6930. return Promise.reject(
  6931. new Error('Only 3 components or 1 component can be returned'));
  6932. }
  6933. return new Promise(function (resolve, reject) {
  6934. var img = new Image();
  6935. img.onload = function () {
  6936. var width = img.width;
  6937. var height = img.height;
  6938. var size = width * height;
  6939. var rgbaLength = size * 4;
  6940. var buf = new Uint8Array(size * components);
  6941. var tmpCanvas = createScratchCanvas(width, height);
  6942. var tmpCtx = tmpCanvas.getContext('2d');
  6943. tmpCtx.drawImage(img, 0, 0);
  6944. var data = tmpCtx.getImageData(0, 0, width, height).data;
  6945. var i, j;
  6946. if (components === 3) {
  6947. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  6948. buf[j] = data[i];
  6949. buf[j + 1] = data[i + 1];
  6950. buf[j + 2] = data[i + 2];
  6951. }
  6952. } else if (components === 1) {
  6953. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  6954. buf[j] = data[i];
  6955. }
  6956. }
  6957. resolve({ data: buf, width: width, height: height});
  6958. };
  6959. img.onerror = function () {
  6960. reject(new Error('JpegDecode failed to load image'));
  6961. };
  6962. img.src = imageUrl;
  6963. });
  6964. }, this);
  6965. },
  6966. getData: function WorkerTransport_getData() {
  6967. return this.messageHandler.sendWithPromise('GetData', null);
  6968. },
  6969. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  6970. if (pageNumber <= 0 || pageNumber > this.numPages ||
  6971. (pageNumber|0) !== pageNumber) {
  6972. return Promise.reject(new Error('Invalid page request'));
  6973. }
  6974. var pageIndex = pageNumber - 1;
  6975. if (pageIndex in this.pagePromises) {
  6976. return this.pagePromises[pageIndex];
  6977. }
  6978. var promise = this.messageHandler.sendWithPromise('GetPage', {
  6979. pageIndex: pageIndex
  6980. }).then(function (pageInfo) {
  6981. if (this.destroyed) {
  6982. throw new Error('Transport destroyed');
  6983. }
  6984. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  6985. this.pageCache[pageIndex] = page;
  6986. return page;
  6987. }.bind(this));
  6988. this.pagePromises[pageIndex] = promise;
  6989. return promise;
  6990. },
  6991. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  6992. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  6993. },
  6994. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  6995. return this.messageHandler.sendWithPromise('GetAnnotations', {
  6996. pageIndex: pageIndex,
  6997. intent: intent,
  6998. });
  6999. },
  7000. getDestinations: function WorkerTransport_getDestinations() {
  7001. return this.messageHandler.sendWithPromise('GetDestinations', null);
  7002. },
  7003. getDestination: function WorkerTransport_getDestination(id) {
  7004. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  7005. },
  7006. getAttachments: function WorkerTransport_getAttachments() {
  7007. return this.messageHandler.sendWithPromise('GetAttachments', null);
  7008. },
  7009. getJavaScript: function WorkerTransport_getJavaScript() {
  7010. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  7011. },
  7012. getOutline: function WorkerTransport_getOutline() {
  7013. return this.messageHandler.sendWithPromise('GetOutline', null);
  7014. },
  7015. getMetadata: function WorkerTransport_getMetadata() {
  7016. return this.messageHandler.sendWithPromise('GetMetadata', null).
  7017. then(function transportMetadata(results) {
  7018. return {
  7019. info: results[0],
  7020. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  7021. };
  7022. });
  7023. },
  7024. getStats: function WorkerTransport_getStats() {
  7025. return this.messageHandler.sendWithPromise('GetStats', null);
  7026. },
  7027. startCleanup: function WorkerTransport_startCleanup() {
  7028. this.messageHandler.sendWithPromise('Cleanup', null).
  7029. then(function endCleanup() {
  7030. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  7031. var page = this.pageCache[i];
  7032. if (page) {
  7033. page.cleanup();
  7034. }
  7035. }
  7036. this.commonObjs.clear();
  7037. this.fontLoader.clear();
  7038. }.bind(this));
  7039. }
  7040. };
  7041. return WorkerTransport;
  7042. })();
  7043. /**
  7044. * A PDF document and page is built of many objects. E.g. there are objects
  7045. * for fonts, images, rendering code and such. These objects might get processed
  7046. * inside of a worker. The `PDFObjects` implements some basic functions to
  7047. * manage these objects.
  7048. * @ignore
  7049. */
  7050. var PDFObjects = (function PDFObjectsClosure() {
  7051. function PDFObjects() {
  7052. this.objs = {};
  7053. }
  7054. PDFObjects.prototype = {
  7055. /**
  7056. * Internal function.
  7057. * Ensures there is an object defined for `objId`.
  7058. */
  7059. ensureObj: function PDFObjects_ensureObj(objId) {
  7060. if (this.objs[objId]) {
  7061. return this.objs[objId];
  7062. }
  7063. var obj = {
  7064. capability: createPromiseCapability(),
  7065. data: null,
  7066. resolved: false
  7067. };
  7068. this.objs[objId] = obj;
  7069. return obj;
  7070. },
  7071. /**
  7072. * If called *without* callback, this returns the data of `objId` but the
  7073. * object needs to be resolved. If it isn't, this function throws.
  7074. *
  7075. * If called *with* a callback, the callback is called with the data of the
  7076. * object once the object is resolved. That means, if you call this
  7077. * function and the object is already resolved, the callback gets called
  7078. * right away.
  7079. */
  7080. get: function PDFObjects_get(objId, callback) {
  7081. // If there is a callback, then the get can be async and the object is
  7082. // not required to be resolved right now
  7083. if (callback) {
  7084. this.ensureObj(objId).capability.promise.then(callback);
  7085. return null;
  7086. }
  7087. // If there isn't a callback, the user expects to get the resolved data
  7088. // directly.
  7089. var obj = this.objs[objId];
  7090. // If there isn't an object yet or the object isn't resolved, then the
  7091. // data isn't ready yet!
  7092. if (!obj || !obj.resolved) {
  7093. error('Requesting object that isn\'t resolved yet ' + objId);
  7094. }
  7095. return obj.data;
  7096. },
  7097. /**
  7098. * Resolves the object `objId` with optional `data`.
  7099. */
  7100. resolve: function PDFObjects_resolve(objId, data) {
  7101. var obj = this.ensureObj(objId);
  7102. obj.resolved = true;
  7103. obj.data = data;
  7104. obj.capability.resolve(data);
  7105. },
  7106. isResolved: function PDFObjects_isResolved(objId) {
  7107. var objs = this.objs;
  7108. if (!objs[objId]) {
  7109. return false;
  7110. } else {
  7111. return objs[objId].resolved;
  7112. }
  7113. },
  7114. hasData: function PDFObjects_hasData(objId) {
  7115. return this.isResolved(objId);
  7116. },
  7117. /**
  7118. * Returns the data of `objId` if object exists, null otherwise.
  7119. */
  7120. getData: function PDFObjects_getData(objId) {
  7121. var objs = this.objs;
  7122. if (!objs[objId] || !objs[objId].resolved) {
  7123. return null;
  7124. } else {
  7125. return objs[objId].data;
  7126. }
  7127. },
  7128. clear: function PDFObjects_clear() {
  7129. this.objs = {};
  7130. }
  7131. };
  7132. return PDFObjects;
  7133. })();
  7134. /**
  7135. * Allows controlling of the rendering tasks.
  7136. * @class
  7137. * @alias RenderTask
  7138. */
  7139. var RenderTask = (function RenderTaskClosure() {
  7140. function RenderTask(internalRenderTask) {
  7141. this._internalRenderTask = internalRenderTask;
  7142. /**
  7143. * Callback for incremental rendering -- a function that will be called
  7144. * each time the rendering is paused. To continue rendering call the
  7145. * function that is the first argument to the callback.
  7146. * @type {function}
  7147. */
  7148. this.onContinue = null;
  7149. }
  7150. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  7151. /**
  7152. * Promise for rendering task completion.
  7153. * @return {Promise}
  7154. */
  7155. get promise() {
  7156. return this._internalRenderTask.capability.promise;
  7157. },
  7158. /**
  7159. * Cancels the rendering task. If the task is currently rendering it will
  7160. * not be cancelled until graphics pauses with a timeout. The promise that
  7161. * this object extends will resolved when cancelled.
  7162. */
  7163. cancel: function RenderTask_cancel() {
  7164. this._internalRenderTask.cancel();
  7165. },
  7166. /**
  7167. * Registers callbacks to indicate the rendering task completion.
  7168. *
  7169. * @param {function} onFulfilled The callback for the rendering completion.
  7170. * @param {function} onRejected The callback for the rendering failure.
  7171. * @return {Promise} A promise that is resolved after the onFulfilled or
  7172. * onRejected callback.
  7173. */
  7174. then: function RenderTask_then(onFulfilled, onRejected) {
  7175. return this.promise.then.apply(this.promise, arguments);
  7176. }
  7177. };
  7178. return RenderTask;
  7179. })();
  7180. /**
  7181. * For internal use only.
  7182. * @ignore
  7183. */
  7184. var InternalRenderTask = (function InternalRenderTaskClosure() {
  7185. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  7186. pageNumber) {
  7187. this.callback = callback;
  7188. this.params = params;
  7189. this.objs = objs;
  7190. this.commonObjs = commonObjs;
  7191. this.operatorListIdx = null;
  7192. this.operatorList = operatorList;
  7193. this.pageNumber = pageNumber;
  7194. this.running = false;
  7195. this.graphicsReadyCallback = null;
  7196. this.graphicsReady = false;
  7197. this.useRequestAnimationFrame = false;
  7198. this.cancelled = false;
  7199. this.capability = createPromiseCapability();
  7200. this.task = new RenderTask(this);
  7201. // caching this-bound methods
  7202. this._continueBound = this._continue.bind(this);
  7203. this._scheduleNextBound = this._scheduleNext.bind(this);
  7204. this._nextBound = this._next.bind(this);
  7205. }
  7206. InternalRenderTask.prototype = {
  7207. initalizeGraphics:
  7208. function InternalRenderTask_initalizeGraphics(transparency) {
  7209. if (this.cancelled) {
  7210. return;
  7211. }
  7212. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  7213. globalScope.StepperManager.enabled) {
  7214. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  7215. this.stepper.init(this.operatorList);
  7216. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  7217. }
  7218. var params = this.params;
  7219. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  7220. this.objs, params.imageLayer);
  7221. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  7222. this.operatorListIdx = 0;
  7223. this.graphicsReady = true;
  7224. if (this.graphicsReadyCallback) {
  7225. this.graphicsReadyCallback();
  7226. }
  7227. },
  7228. cancel: function InternalRenderTask_cancel() {
  7229. this.running = false;
  7230. this.cancelled = true;
  7231. this.callback('cancelled');
  7232. },
  7233. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  7234. if (!this.graphicsReady) {
  7235. if (!this.graphicsReadyCallback) {
  7236. this.graphicsReadyCallback = this._continueBound;
  7237. }
  7238. return;
  7239. }
  7240. if (this.stepper) {
  7241. this.stepper.updateOperatorList(this.operatorList);
  7242. }
  7243. if (this.running) {
  7244. return;
  7245. }
  7246. this._continue();
  7247. },
  7248. _continue: function InternalRenderTask__continue() {
  7249. this.running = true;
  7250. if (this.cancelled) {
  7251. return;
  7252. }
  7253. if (this.task.onContinue) {
  7254. this.task.onContinue.call(this.task, this._scheduleNextBound);
  7255. } else {
  7256. this._scheduleNext();
  7257. }
  7258. },
  7259. _scheduleNext: function InternalRenderTask__scheduleNext() {
  7260. if (this.useRequestAnimationFrame) {
  7261. window.requestAnimationFrame(this._nextBound);
  7262. } else {
  7263. Promise.resolve(undefined).then(this._nextBound);
  7264. }
  7265. },
  7266. _next: function InternalRenderTask__next() {
  7267. if (this.cancelled) {
  7268. return;
  7269. }
  7270. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  7271. this.operatorListIdx,
  7272. this._continueBound,
  7273. this.stepper);
  7274. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  7275. this.running = false;
  7276. if (this.operatorList.lastChunk) {
  7277. this.gfx.endDrawing();
  7278. this.callback();
  7279. }
  7280. }
  7281. }
  7282. };
  7283. return InternalRenderTask;
  7284. })();
  7285. /**
  7286. * (Deprecated) Global observer of unsupported feature usages. Use
  7287. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  7288. */
  7289. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  7290. var listeners = [];
  7291. return {
  7292. listen: function (cb) {
  7293. deprecated('Global UnsupportedManager.listen is used: ' +
  7294. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  7295. listeners.push(cb);
  7296. },
  7297. notify: function (featureId) {
  7298. for (var i = 0, ii = listeners.length; i < ii; i++) {
  7299. listeners[i](featureId);
  7300. }
  7301. }
  7302. };
  7303. })();
  7304. exports.getDocument = PDFJS.getDocument;
  7305. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  7306. exports.PDFDocumentProxy = PDFDocumentProxy;
  7307. exports.PDFPageProxy = PDFPageProxy;
  7308. }));
  7309. (function (root, factory) {
  7310. {
  7311. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  7312. }
  7313. }(this, function (exports, sharedUtil) {
  7314. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  7315. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  7316. var ImageKind = sharedUtil.ImageKind;
  7317. var OPS = sharedUtil.OPS;
  7318. var Util = sharedUtil.Util;
  7319. var isNum = sharedUtil.isNum;
  7320. var isArray = sharedUtil.isArray;
  7321. var warn = sharedUtil.warn;
  7322. var SVG_DEFAULTS = {
  7323. fontStyle: 'normal',
  7324. fontWeight: 'normal',
  7325. fillColor: '#000000'
  7326. };
  7327. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  7328. var PNG_HEADER =
  7329. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  7330. var CHUNK_WRAPPER_SIZE = 12;
  7331. var crcTable = new Int32Array(256);
  7332. for (var i = 0; i < 256; i++) {
  7333. var c = i;
  7334. for (var h = 0; h < 8; h++) {
  7335. if (c & 1) {
  7336. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  7337. } else {
  7338. c = (c >> 1) & 0x7fffffff;
  7339. }
  7340. }
  7341. crcTable[i] = c;
  7342. }
  7343. function crc32(data, start, end) {
  7344. var crc = -1;
  7345. for (var i = start; i < end; i++) {
  7346. var a = (crc ^ data[i]) & 0xff;
  7347. var b = crcTable[a];
  7348. crc = (crc >>> 8) ^ b;
  7349. }
  7350. return crc ^ -1;
  7351. }
  7352. function writePngChunk(type, body, data, offset) {
  7353. var p = offset;
  7354. var len = body.length;
  7355. data[p] = len >> 24 & 0xff;
  7356. data[p + 1] = len >> 16 & 0xff;
  7357. data[p + 2] = len >> 8 & 0xff;
  7358. data[p + 3] = len & 0xff;
  7359. p += 4;
  7360. data[p] = type.charCodeAt(0) & 0xff;
  7361. data[p + 1] = type.charCodeAt(1) & 0xff;
  7362. data[p + 2] = type.charCodeAt(2) & 0xff;
  7363. data[p + 3] = type.charCodeAt(3) & 0xff;
  7364. p += 4;
  7365. data.set(body, p);
  7366. p += body.length;
  7367. var crc = crc32(data, offset + 4, p);
  7368. data[p] = crc >> 24 & 0xff;
  7369. data[p + 1] = crc >> 16 & 0xff;
  7370. data[p + 2] = crc >> 8 & 0xff;
  7371. data[p + 3] = crc & 0xff;
  7372. }
  7373. function adler32(data, start, end) {
  7374. var a = 1;
  7375. var b = 0;
  7376. for (var i = start; i < end; ++i) {
  7377. a = (a + (data[i] & 0xff)) % 65521;
  7378. b = (b + a) % 65521;
  7379. }
  7380. return (b << 16) | a;
  7381. }
  7382. function encode(imgData, kind) {
  7383. var width = imgData.width;
  7384. var height = imgData.height;
  7385. var bitDepth, colorType, lineSize;
  7386. var bytes = imgData.data;
  7387. switch (kind) {
  7388. case ImageKind.GRAYSCALE_1BPP:
  7389. colorType = 0;
  7390. bitDepth = 1;
  7391. lineSize = (width + 7) >> 3;
  7392. break;
  7393. case ImageKind.RGB_24BPP:
  7394. colorType = 2;
  7395. bitDepth = 8;
  7396. lineSize = width * 3;
  7397. break;
  7398. case ImageKind.RGBA_32BPP:
  7399. colorType = 6;
  7400. bitDepth = 8;
  7401. lineSize = width * 4;
  7402. break;
  7403. default:
  7404. throw new Error('invalid format');
  7405. }
  7406. // prefix every row with predictor 0
  7407. var literals = new Uint8Array((1 + lineSize) * height);
  7408. var offsetLiterals = 0, offsetBytes = 0;
  7409. var y, i;
  7410. for (y = 0; y < height; ++y) {
  7411. literals[offsetLiterals++] = 0; // no prediction
  7412. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  7413. offsetLiterals);
  7414. offsetBytes += lineSize;
  7415. offsetLiterals += lineSize;
  7416. }
  7417. if (kind === ImageKind.GRAYSCALE_1BPP) {
  7418. // inverting for B/W
  7419. offsetLiterals = 0;
  7420. for (y = 0; y < height; y++) {
  7421. offsetLiterals++; // skipping predictor
  7422. for (i = 0; i < lineSize; i++) {
  7423. literals[offsetLiterals++] ^= 0xFF;
  7424. }
  7425. }
  7426. }
  7427. var ihdr = new Uint8Array([
  7428. width >> 24 & 0xff,
  7429. width >> 16 & 0xff,
  7430. width >> 8 & 0xff,
  7431. width & 0xff,
  7432. height >> 24 & 0xff,
  7433. height >> 16 & 0xff,
  7434. height >> 8 & 0xff,
  7435. height & 0xff,
  7436. bitDepth, // bit depth
  7437. colorType, // color type
  7438. 0x00, // compression method
  7439. 0x00, // filter method
  7440. 0x00 // interlace method
  7441. ]);
  7442. var len = literals.length;
  7443. var maxBlockLength = 0xFFFF;
  7444. var deflateBlocks = Math.ceil(len / maxBlockLength);
  7445. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  7446. var pi = 0;
  7447. idat[pi++] = 0x78; // compression method and flags
  7448. idat[pi++] = 0x9c; // flags
  7449. var pos = 0;
  7450. while (len > maxBlockLength) {
  7451. // writing non-final DEFLATE blocks type 0 and length of 65535
  7452. idat[pi++] = 0x00;
  7453. idat[pi++] = 0xff;
  7454. idat[pi++] = 0xff;
  7455. idat[pi++] = 0x00;
  7456. idat[pi++] = 0x00;
  7457. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  7458. pi += maxBlockLength;
  7459. pos += maxBlockLength;
  7460. len -= maxBlockLength;
  7461. }
  7462. // writing non-final DEFLATE blocks type 0
  7463. idat[pi++] = 0x01;
  7464. idat[pi++] = len & 0xff;
  7465. idat[pi++] = len >> 8 & 0xff;
  7466. idat[pi++] = (~len & 0xffff) & 0xff;
  7467. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  7468. idat.set(literals.subarray(pos), pi);
  7469. pi += literals.length - pos;
  7470. var adler = adler32(literals, 0, literals.length); // checksum
  7471. idat[pi++] = adler >> 24 & 0xff;
  7472. idat[pi++] = adler >> 16 & 0xff;
  7473. idat[pi++] = adler >> 8 & 0xff;
  7474. idat[pi++] = adler & 0xff;
  7475. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  7476. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  7477. ihdr.length + idat.length;
  7478. var data = new Uint8Array(pngLength);
  7479. var offset = 0;
  7480. data.set(PNG_HEADER, offset);
  7481. offset += PNG_HEADER.length;
  7482. writePngChunk('IHDR', ihdr, data, offset);
  7483. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  7484. writePngChunk('IDATA', idat, data, offset);
  7485. offset += CHUNK_WRAPPER_SIZE + idat.length;
  7486. writePngChunk('IEND', new Uint8Array(0), data, offset);
  7487. return PDFJS.createObjectURL(data, 'image/png');
  7488. }
  7489. return function convertImgDataToPng(imgData) {
  7490. var kind = (imgData.kind === undefined ?
  7491. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  7492. return encode(imgData, kind);
  7493. };
  7494. })();
  7495. var SVGExtraState = (function SVGExtraStateClosure() {
  7496. function SVGExtraState() {
  7497. this.fontSizeScale = 1;
  7498. this.fontWeight = SVG_DEFAULTS.fontWeight;
  7499. this.fontSize = 0;
  7500. this.textMatrix = IDENTITY_MATRIX;
  7501. this.fontMatrix = FONT_IDENTITY_MATRIX;
  7502. this.leading = 0;
  7503. // Current point (in user coordinates)
  7504. this.x = 0;
  7505. this.y = 0;
  7506. // Start of text line (in text coordinates)
  7507. this.lineX = 0;
  7508. this.lineY = 0;
  7509. // Character and word spacing
  7510. this.charSpacing = 0;
  7511. this.wordSpacing = 0;
  7512. this.textHScale = 1;
  7513. this.textRise = 0;
  7514. // Default foreground and background colors
  7515. this.fillColor = SVG_DEFAULTS.fillColor;
  7516. this.strokeColor = '#000000';
  7517. this.fillAlpha = 1;
  7518. this.strokeAlpha = 1;
  7519. this.lineWidth = 1;
  7520. this.lineJoin = '';
  7521. this.lineCap = '';
  7522. this.miterLimit = 0;
  7523. this.dashArray = [];
  7524. this.dashPhase = 0;
  7525. this.dependencies = [];
  7526. // Clipping
  7527. this.clipId = '';
  7528. this.pendingClip = false;
  7529. this.maskId = '';
  7530. }
  7531. SVGExtraState.prototype = {
  7532. clone: function SVGExtraState_clone() {
  7533. return Object.create(this);
  7534. },
  7535. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  7536. this.x = x;
  7537. this.y = y;
  7538. }
  7539. };
  7540. return SVGExtraState;
  7541. })();
  7542. var SVGGraphics = (function SVGGraphicsClosure() {
  7543. function createScratchSVG(width, height) {
  7544. var NS = 'http://www.w3.org/2000/svg';
  7545. var svg = document.createElementNS(NS, 'svg:svg');
  7546. svg.setAttributeNS(null, 'version', '1.1');
  7547. svg.setAttributeNS(null, 'width', width + 'px');
  7548. svg.setAttributeNS(null, 'height', height + 'px');
  7549. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  7550. return svg;
  7551. }
  7552. function opListToTree(opList) {
  7553. var opTree = [];
  7554. var tmp = [];
  7555. var opListLen = opList.length;
  7556. for (var x = 0; x < opListLen; x++) {
  7557. if (opList[x].fn === 'save') {
  7558. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  7559. tmp.push(opTree);
  7560. opTree = opTree[opTree.length - 1].items;
  7561. continue;
  7562. }
  7563. if(opList[x].fn === 'restore') {
  7564. opTree = tmp.pop();
  7565. } else {
  7566. opTree.push(opList[x]);
  7567. }
  7568. }
  7569. return opTree;
  7570. }
  7571. /**
  7572. * Formats float number.
  7573. * @param value {number} number to format.
  7574. * @returns {string}
  7575. */
  7576. function pf(value) {
  7577. if (value === (value | 0)) { // integer number
  7578. return value.toString();
  7579. }
  7580. var s = value.toFixed(10);
  7581. var i = s.length - 1;
  7582. if (s[i] !== '0') {
  7583. return s;
  7584. }
  7585. // removing trailing zeros
  7586. do {
  7587. i--;
  7588. } while (s[i] === '0');
  7589. return s.substr(0, s[i] === '.' ? i : i + 1);
  7590. }
  7591. /**
  7592. * Formats transform matrix. The standard rotation, scale and translate
  7593. * matrices are replaced by their shorter forms, and for identity matrix
  7594. * returns empty string to save the memory.
  7595. * @param m {Array} matrix to format.
  7596. * @returns {string}
  7597. */
  7598. function pm(m) {
  7599. if (m[4] === 0 && m[5] === 0) {
  7600. if (m[1] === 0 && m[2] === 0) {
  7601. if (m[0] === 1 && m[3] === 1) {
  7602. return '';
  7603. }
  7604. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  7605. }
  7606. if (m[0] === m[3] && m[1] === -m[2]) {
  7607. var a = Math.acos(m[0]) * 180 / Math.PI;
  7608. return 'rotate(' + pf(a) + ')';
  7609. }
  7610. } else {
  7611. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  7612. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  7613. }
  7614. }
  7615. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  7616. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  7617. }
  7618. function SVGGraphics(commonObjs, objs) {
  7619. this.current = new SVGExtraState();
  7620. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  7621. this.transformStack = [];
  7622. this.extraStack = [];
  7623. this.commonObjs = commonObjs;
  7624. this.objs = objs;
  7625. this.pendingEOFill = false;
  7626. this.embedFonts = false;
  7627. this.embeddedFonts = {};
  7628. this.cssStyle = null;
  7629. }
  7630. var NS = 'http://www.w3.org/2000/svg';
  7631. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  7632. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  7633. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  7634. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  7635. var clipCount = 0;
  7636. var maskCount = 0;
  7637. SVGGraphics.prototype = {
  7638. save: function SVGGraphics_save() {
  7639. this.transformStack.push(this.transformMatrix);
  7640. var old = this.current;
  7641. this.extraStack.push(old);
  7642. this.current = old.clone();
  7643. },
  7644. restore: function SVGGraphics_restore() {
  7645. this.transformMatrix = this.transformStack.pop();
  7646. this.current = this.extraStack.pop();
  7647. this.tgrp = document.createElementNS(NS, 'svg:g');
  7648. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7649. this.pgrp.appendChild(this.tgrp);
  7650. },
  7651. group: function SVGGraphics_group(items) {
  7652. this.save();
  7653. this.executeOpTree(items);
  7654. this.restore();
  7655. },
  7656. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  7657. var fnArray = operatorList.fnArray;
  7658. var fnArrayLen = fnArray.length;
  7659. var argsArray = operatorList.argsArray;
  7660. var self = this;
  7661. for (var i = 0; i < fnArrayLen; i++) {
  7662. if (OPS.dependency === fnArray[i]) {
  7663. var deps = argsArray[i];
  7664. for (var n = 0, nn = deps.length; n < nn; n++) {
  7665. var obj = deps[n];
  7666. var common = obj.substring(0, 2) === 'g_';
  7667. var promise;
  7668. if (common) {
  7669. promise = new Promise(function(resolve) {
  7670. self.commonObjs.get(obj, resolve);
  7671. });
  7672. } else {
  7673. promise = new Promise(function(resolve) {
  7674. self.objs.get(obj, resolve);
  7675. });
  7676. }
  7677. this.current.dependencies.push(promise);
  7678. }
  7679. }
  7680. }
  7681. return Promise.all(this.current.dependencies);
  7682. },
  7683. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  7684. var transformMatrix = [a, b, c, d, e, f];
  7685. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  7686. transformMatrix);
  7687. this.tgrp = document.createElementNS(NS, 'svg:g');
  7688. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7689. },
  7690. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  7691. this.svg = createScratchSVG(viewport.width, viewport.height);
  7692. this.viewport = viewport;
  7693. return this.loadDependencies(operatorList).then(function () {
  7694. this.transformMatrix = IDENTITY_MATRIX;
  7695. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  7696. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  7697. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  7698. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7699. this.defs = document.createElementNS(NS, 'svg:defs');
  7700. this.pgrp.appendChild(this.defs);
  7701. this.pgrp.appendChild(this.tgrp);
  7702. this.svg.appendChild(this.pgrp);
  7703. var opTree = this.convertOpList(operatorList);
  7704. this.executeOpTree(opTree);
  7705. return this.svg;
  7706. }.bind(this));
  7707. },
  7708. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  7709. var argsArray = operatorList.argsArray;
  7710. var fnArray = operatorList.fnArray;
  7711. var fnArrayLen = fnArray.length;
  7712. var REVOPS = [];
  7713. var opList = [];
  7714. for (var op in OPS) {
  7715. REVOPS[OPS[op]] = op;
  7716. }
  7717. for (var x = 0; x < fnArrayLen; x++) {
  7718. var fnId = fnArray[x];
  7719. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  7720. }
  7721. return opListToTree(opList);
  7722. },
  7723. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  7724. var opTreeLen = opTree.length;
  7725. for(var x = 0; x < opTreeLen; x++) {
  7726. var fn = opTree[x].fn;
  7727. var fnId = opTree[x].fnId;
  7728. var args = opTree[x].args;
  7729. switch (fnId | 0) {
  7730. case OPS.beginText:
  7731. this.beginText();
  7732. break;
  7733. case OPS.setLeading:
  7734. this.setLeading(args);
  7735. break;
  7736. case OPS.setLeadingMoveText:
  7737. this.setLeadingMoveText(args[0], args[1]);
  7738. break;
  7739. case OPS.setFont:
  7740. this.setFont(args);
  7741. break;
  7742. case OPS.showText:
  7743. this.showText(args[0]);
  7744. break;
  7745. case OPS.showSpacedText:
  7746. this.showText(args[0]);
  7747. break;
  7748. case OPS.endText:
  7749. this.endText();
  7750. break;
  7751. case OPS.moveText:
  7752. this.moveText(args[0], args[1]);
  7753. break;
  7754. case OPS.setCharSpacing:
  7755. this.setCharSpacing(args[0]);
  7756. break;
  7757. case OPS.setWordSpacing:
  7758. this.setWordSpacing(args[0]);
  7759. break;
  7760. case OPS.setHScale:
  7761. this.setHScale(args[0]);
  7762. break;
  7763. case OPS.setTextMatrix:
  7764. this.setTextMatrix(args[0], args[1], args[2],
  7765. args[3], args[4], args[5]);
  7766. break;
  7767. case OPS.setLineWidth:
  7768. this.setLineWidth(args[0]);
  7769. break;
  7770. case OPS.setLineJoin:
  7771. this.setLineJoin(args[0]);
  7772. break;
  7773. case OPS.setLineCap:
  7774. this.setLineCap(args[0]);
  7775. break;
  7776. case OPS.setMiterLimit:
  7777. this.setMiterLimit(args[0]);
  7778. break;
  7779. case OPS.setFillRGBColor:
  7780. this.setFillRGBColor(args[0], args[1], args[2]);
  7781. break;
  7782. case OPS.setStrokeRGBColor:
  7783. this.setStrokeRGBColor(args[0], args[1], args[2]);
  7784. break;
  7785. case OPS.setDash:
  7786. this.setDash(args[0], args[1]);
  7787. break;
  7788. case OPS.setGState:
  7789. this.setGState(args[0]);
  7790. break;
  7791. case OPS.fill:
  7792. this.fill();
  7793. break;
  7794. case OPS.eoFill:
  7795. this.eoFill();
  7796. break;
  7797. case OPS.stroke:
  7798. this.stroke();
  7799. break;
  7800. case OPS.fillStroke:
  7801. this.fillStroke();
  7802. break;
  7803. case OPS.eoFillStroke:
  7804. this.eoFillStroke();
  7805. break;
  7806. case OPS.clip:
  7807. this.clip('nonzero');
  7808. break;
  7809. case OPS.eoClip:
  7810. this.clip('evenodd');
  7811. break;
  7812. case OPS.paintSolidColorImageMask:
  7813. this.paintSolidColorImageMask();
  7814. break;
  7815. case OPS.paintJpegXObject:
  7816. this.paintJpegXObject(args[0], args[1], args[2]);
  7817. break;
  7818. case OPS.paintImageXObject:
  7819. this.paintImageXObject(args[0]);
  7820. break;
  7821. case OPS.paintInlineImageXObject:
  7822. this.paintInlineImageXObject(args[0]);
  7823. break;
  7824. case OPS.paintImageMaskXObject:
  7825. this.paintImageMaskXObject(args[0]);
  7826. break;
  7827. case OPS.paintFormXObjectBegin:
  7828. this.paintFormXObjectBegin(args[0], args[1]);
  7829. break;
  7830. case OPS.paintFormXObjectEnd:
  7831. this.paintFormXObjectEnd();
  7832. break;
  7833. case OPS.closePath:
  7834. this.closePath();
  7835. break;
  7836. case OPS.closeStroke:
  7837. this.closeStroke();
  7838. break;
  7839. case OPS.closeFillStroke:
  7840. this.closeFillStroke();
  7841. break;
  7842. case OPS.nextLine:
  7843. this.nextLine();
  7844. break;
  7845. case OPS.transform:
  7846. this.transform(args[0], args[1], args[2], args[3],
  7847. args[4], args[5]);
  7848. break;
  7849. case OPS.constructPath:
  7850. this.constructPath(args[0], args[1]);
  7851. break;
  7852. case OPS.endPath:
  7853. this.endPath();
  7854. break;
  7855. case 92:
  7856. this.group(opTree[x].items);
  7857. break;
  7858. default:
  7859. warn('Unimplemented method '+ fn);
  7860. break;
  7861. }
  7862. }
  7863. },
  7864. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  7865. this.current.wordSpacing = wordSpacing;
  7866. },
  7867. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  7868. this.current.charSpacing = charSpacing;
  7869. },
  7870. nextLine: function SVGGraphics_nextLine() {
  7871. this.moveText(0, this.current.leading);
  7872. },
  7873. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  7874. var current = this.current;
  7875. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  7876. this.current.x = this.current.lineX = 0;
  7877. this.current.y = this.current.lineY = 0;
  7878. current.xcoords = [];
  7879. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7880. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7881. current.tspan.setAttributeNS(null, 'font-size',
  7882. pf(current.fontSize) + 'px');
  7883. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7884. current.txtElement = document.createElementNS(NS, 'svg:text');
  7885. current.txtElement.appendChild(current.tspan);
  7886. },
  7887. beginText: function SVGGraphics_beginText() {
  7888. this.current.x = this.current.lineX = 0;
  7889. this.current.y = this.current.lineY = 0;
  7890. this.current.textMatrix = IDENTITY_MATRIX;
  7891. this.current.lineMatrix = IDENTITY_MATRIX;
  7892. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  7893. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  7894. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  7895. this.current.xcoords = [];
  7896. },
  7897. moveText: function SVGGraphics_moveText(x, y) {
  7898. var current = this.current;
  7899. this.current.x = this.current.lineX += x;
  7900. this.current.y = this.current.lineY += y;
  7901. current.xcoords = [];
  7902. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7903. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7904. current.tspan.setAttributeNS(null, 'font-size',
  7905. pf(current.fontSize) + 'px');
  7906. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7907. },
  7908. showText: function SVGGraphics_showText(glyphs) {
  7909. var current = this.current;
  7910. var font = current.font;
  7911. var fontSize = current.fontSize;
  7912. if (fontSize === 0) {
  7913. return;
  7914. }
  7915. var charSpacing = current.charSpacing;
  7916. var wordSpacing = current.wordSpacing;
  7917. var fontDirection = current.fontDirection;
  7918. var textHScale = current.textHScale * fontDirection;
  7919. var glyphsLength = glyphs.length;
  7920. var vertical = font.vertical;
  7921. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  7922. var x = 0, i;
  7923. for (i = 0; i < glyphsLength; ++i) {
  7924. var glyph = glyphs[i];
  7925. if (glyph === null) {
  7926. // word break
  7927. x += fontDirection * wordSpacing;
  7928. continue;
  7929. } else if (isNum(glyph)) {
  7930. x += -glyph * fontSize * 0.001;
  7931. continue;
  7932. }
  7933. current.xcoords.push(current.x + x * textHScale);
  7934. var width = glyph.width;
  7935. var character = glyph.fontChar;
  7936. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  7937. x += charWidth;
  7938. current.tspan.textContent += character;
  7939. }
  7940. if (vertical) {
  7941. current.y -= x * textHScale;
  7942. } else {
  7943. current.x += x * textHScale;
  7944. }
  7945. current.tspan.setAttributeNS(null, 'x',
  7946. current.xcoords.map(pf).join(' '));
  7947. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7948. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7949. current.tspan.setAttributeNS(null, 'font-size',
  7950. pf(current.fontSize) + 'px');
  7951. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  7952. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  7953. }
  7954. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  7955. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  7956. }
  7957. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  7958. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  7959. }
  7960. current.txtElement.setAttributeNS(null, 'transform',
  7961. pm(current.textMatrix) +
  7962. ' scale(1, -1)' );
  7963. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  7964. current.txtElement.appendChild(current.tspan);
  7965. current.txtgrp.appendChild(current.txtElement);
  7966. this.tgrp.appendChild(current.txtElement);
  7967. },
  7968. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  7969. this.setLeading(-y);
  7970. this.moveText(x, y);
  7971. },
  7972. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  7973. if (!this.cssStyle) {
  7974. this.cssStyle = document.createElementNS(NS, 'svg:style');
  7975. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  7976. this.defs.appendChild(this.cssStyle);
  7977. }
  7978. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  7979. this.cssStyle.textContent +=
  7980. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  7981. ' src: url(' + url + '); }\n';
  7982. },
  7983. setFont: function SVGGraphics_setFont(details) {
  7984. var current = this.current;
  7985. var fontObj = this.commonObjs.get(details[0]);
  7986. var size = details[1];
  7987. this.current.font = fontObj;
  7988. if (this.embedFonts && fontObj.data &&
  7989. !this.embeddedFonts[fontObj.loadedName]) {
  7990. this.addFontStyle(fontObj);
  7991. this.embeddedFonts[fontObj.loadedName] = fontObj;
  7992. }
  7993. current.fontMatrix = (fontObj.fontMatrix ?
  7994. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  7995. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  7996. (fontObj.bold ? 'bold' : 'normal');
  7997. var italic = fontObj.italic ? 'italic' : 'normal';
  7998. if (size < 0) {
  7999. size = -size;
  8000. current.fontDirection = -1;
  8001. } else {
  8002. current.fontDirection = 1;
  8003. }
  8004. current.fontSize = size;
  8005. current.fontFamily = fontObj.loadedName;
  8006. current.fontWeight = bold;
  8007. current.fontStyle = italic;
  8008. current.tspan = document.createElementNS(NS, 'svg:tspan');
  8009. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  8010. current.xcoords = [];
  8011. },
  8012. endText: function SVGGraphics_endText() {
  8013. if (this.current.pendingClip) {
  8014. this.cgrp.appendChild(this.tgrp);
  8015. this.pgrp.appendChild(this.cgrp);
  8016. } else {
  8017. this.pgrp.appendChild(this.tgrp);
  8018. }
  8019. this.tgrp = document.createElementNS(NS, 'svg:g');
  8020. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  8021. },
  8022. // Path properties
  8023. setLineWidth: function SVGGraphics_setLineWidth(width) {
  8024. this.current.lineWidth = width;
  8025. },
  8026. setLineCap: function SVGGraphics_setLineCap(style) {
  8027. this.current.lineCap = LINE_CAP_STYLES[style];
  8028. },
  8029. setLineJoin: function SVGGraphics_setLineJoin(style) {
  8030. this.current.lineJoin = LINE_JOIN_STYLES[style];
  8031. },
  8032. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  8033. this.current.miterLimit = limit;
  8034. },
  8035. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  8036. var color = Util.makeCssRgb(r, g, b);
  8037. this.current.strokeColor = color;
  8038. },
  8039. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  8040. var color = Util.makeCssRgb(r, g, b);
  8041. this.current.fillColor = color;
  8042. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  8043. this.current.xcoords = [];
  8044. },
  8045. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  8046. this.current.dashArray = dashArray;
  8047. this.current.dashPhase = dashPhase;
  8048. },
  8049. constructPath: function SVGGraphics_constructPath(ops, args) {
  8050. var current = this.current;
  8051. var x = current.x, y = current.y;
  8052. current.path = document.createElementNS(NS, 'svg:path');
  8053. var d = [];
  8054. var opLength = ops.length;
  8055. for (var i = 0, j = 0; i < opLength; i++) {
  8056. switch (ops[i] | 0) {
  8057. case OPS.rectangle:
  8058. x = args[j++];
  8059. y = args[j++];
  8060. var width = args[j++];
  8061. var height = args[j++];
  8062. var xw = x + width;
  8063. var yh = y + height;
  8064. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  8065. 'L', pf(x), pf(yh), 'Z');
  8066. break;
  8067. case OPS.moveTo:
  8068. x = args[j++];
  8069. y = args[j++];
  8070. d.push('M', pf(x), pf(y));
  8071. break;
  8072. case OPS.lineTo:
  8073. x = args[j++];
  8074. y = args[j++];
  8075. d.push('L', pf(x) , pf(y));
  8076. break;
  8077. case OPS.curveTo:
  8078. x = args[j + 4];
  8079. y = args[j + 5];
  8080. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  8081. pf(args[j + 3]), pf(x), pf(y));
  8082. j += 6;
  8083. break;
  8084. case OPS.curveTo2:
  8085. x = args[j + 2];
  8086. y = args[j + 3];
  8087. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  8088. pf(args[j + 2]), pf(args[j + 3]));
  8089. j += 4;
  8090. break;
  8091. case OPS.curveTo3:
  8092. x = args[j + 2];
  8093. y = args[j + 3];
  8094. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  8095. pf(x), pf(y));
  8096. j += 4;
  8097. break;
  8098. case OPS.closePath:
  8099. d.push('Z');
  8100. break;
  8101. }
  8102. }
  8103. current.path.setAttributeNS(null, 'd', d.join(' '));
  8104. current.path.setAttributeNS(null, 'stroke-miterlimit',
  8105. pf(current.miterLimit));
  8106. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  8107. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  8108. current.path.setAttributeNS(null, 'stroke-width',
  8109. pf(current.lineWidth) + 'px');
  8110. current.path.setAttributeNS(null, 'stroke-dasharray',
  8111. current.dashArray.map(pf).join(' '));
  8112. current.path.setAttributeNS(null, 'stroke-dashoffset',
  8113. pf(current.dashPhase) + 'px');
  8114. current.path.setAttributeNS(null, 'fill', 'none');
  8115. this.tgrp.appendChild(current.path);
  8116. if (current.pendingClip) {
  8117. this.cgrp.appendChild(this.tgrp);
  8118. this.pgrp.appendChild(this.cgrp);
  8119. } else {
  8120. this.pgrp.appendChild(this.tgrp);
  8121. }
  8122. // Saving a reference in current.element so that it can be addressed
  8123. // in 'fill' and 'stroke'
  8124. current.element = current.path;
  8125. current.setCurrentPoint(x, y);
  8126. },
  8127. endPath: function SVGGraphics_endPath() {
  8128. var current = this.current;
  8129. if (current.pendingClip) {
  8130. this.cgrp.appendChild(this.tgrp);
  8131. this.pgrp.appendChild(this.cgrp);
  8132. } else {
  8133. this.pgrp.appendChild(this.tgrp);
  8134. }
  8135. this.tgrp = document.createElementNS(NS, 'svg:g');
  8136. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  8137. },
  8138. clip: function SVGGraphics_clip(type) {
  8139. var current = this.current;
  8140. // Add current path to clipping path
  8141. current.clipId = 'clippath' + clipCount;
  8142. clipCount++;
  8143. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  8144. this.clippath.setAttributeNS(null, 'id', current.clipId);
  8145. var clipElement = current.element.cloneNode();
  8146. if (type === 'evenodd') {
  8147. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  8148. } else {
  8149. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  8150. }
  8151. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  8152. this.clippath.appendChild(clipElement);
  8153. this.defs.appendChild(this.clippath);
  8154. // Create a new group with that attribute
  8155. current.pendingClip = true;
  8156. this.cgrp = document.createElementNS(NS, 'svg:g');
  8157. this.cgrp.setAttributeNS(null, 'clip-path',
  8158. 'url(#' + current.clipId + ')');
  8159. this.pgrp.appendChild(this.cgrp);
  8160. },
  8161. closePath: function SVGGraphics_closePath() {
  8162. var current = this.current;
  8163. var d = current.path.getAttributeNS(null, 'd');
  8164. d += 'Z';
  8165. current.path.setAttributeNS(null, 'd', d);
  8166. },
  8167. setLeading: function SVGGraphics_setLeading(leading) {
  8168. this.current.leading = -leading;
  8169. },
  8170. setTextRise: function SVGGraphics_setTextRise(textRise) {
  8171. this.current.textRise = textRise;
  8172. },
  8173. setHScale: function SVGGraphics_setHScale(scale) {
  8174. this.current.textHScale = scale / 100;
  8175. },
  8176. setGState: function SVGGraphics_setGState(states) {
  8177. for (var i = 0, ii = states.length; i < ii; i++) {
  8178. var state = states[i];
  8179. var key = state[0];
  8180. var value = state[1];
  8181. switch (key) {
  8182. case 'LW':
  8183. this.setLineWidth(value);
  8184. break;
  8185. case 'LC':
  8186. this.setLineCap(value);
  8187. break;
  8188. case 'LJ':
  8189. this.setLineJoin(value);
  8190. break;
  8191. case 'ML':
  8192. this.setMiterLimit(value);
  8193. break;
  8194. case 'D':
  8195. this.setDash(value[0], value[1]);
  8196. break;
  8197. case 'RI':
  8198. break;
  8199. case 'FL':
  8200. break;
  8201. case 'Font':
  8202. this.setFont(value);
  8203. break;
  8204. case 'CA':
  8205. break;
  8206. case 'ca':
  8207. break;
  8208. case 'BM':
  8209. break;
  8210. case 'SMask':
  8211. break;
  8212. }
  8213. }
  8214. },
  8215. fill: function SVGGraphics_fill() {
  8216. var current = this.current;
  8217. current.element.setAttributeNS(null, 'fill', current.fillColor);
  8218. },
  8219. stroke: function SVGGraphics_stroke() {
  8220. var current = this.current;
  8221. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  8222. current.element.setAttributeNS(null, 'fill', 'none');
  8223. },
  8224. eoFill: function SVGGraphics_eoFill() {
  8225. var current = this.current;
  8226. current.element.setAttributeNS(null, 'fill', current.fillColor);
  8227. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  8228. },
  8229. fillStroke: function SVGGraphics_fillStroke() {
  8230. // Order is important since stroke wants fill to be none.
  8231. // First stroke, then if fill needed, it will be overwritten.
  8232. this.stroke();
  8233. this.fill();
  8234. },
  8235. eoFillStroke: function SVGGraphics_eoFillStroke() {
  8236. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  8237. this.fillStroke();
  8238. },
  8239. closeStroke: function SVGGraphics_closeStroke() {
  8240. this.closePath();
  8241. this.stroke();
  8242. },
  8243. closeFillStroke: function SVGGraphics_closeFillStroke() {
  8244. this.closePath();
  8245. this.fillStroke();
  8246. },
  8247. paintSolidColorImageMask:
  8248. function SVGGraphics_paintSolidColorImageMask() {
  8249. var current = this.current;
  8250. var rect = document.createElementNS(NS, 'svg:rect');
  8251. rect.setAttributeNS(null, 'x', '0');
  8252. rect.setAttributeNS(null, 'y', '0');
  8253. rect.setAttributeNS(null, 'width', '1px');
  8254. rect.setAttributeNS(null, 'height', '1px');
  8255. rect.setAttributeNS(null, 'fill', current.fillColor);
  8256. this.tgrp.appendChild(rect);
  8257. },
  8258. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  8259. var current = this.current;
  8260. var imgObj = this.objs.get(objId);
  8261. var imgEl = document.createElementNS(NS, 'svg:image');
  8262. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  8263. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  8264. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  8265. imgEl.setAttributeNS(null, 'x', '0');
  8266. imgEl.setAttributeNS(null, 'y', pf(-h));
  8267. imgEl.setAttributeNS(null, 'transform',
  8268. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  8269. this.tgrp.appendChild(imgEl);
  8270. if (current.pendingClip) {
  8271. this.cgrp.appendChild(this.tgrp);
  8272. this.pgrp.appendChild(this.cgrp);
  8273. } else {
  8274. this.pgrp.appendChild(this.tgrp);
  8275. }
  8276. },
  8277. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  8278. var imgData = this.objs.get(objId);
  8279. if (!imgData) {
  8280. warn('Dependent image isn\'t ready yet');
  8281. return;
  8282. }
  8283. this.paintInlineImageXObject(imgData);
  8284. },
  8285. paintInlineImageXObject:
  8286. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  8287. var current = this.current;
  8288. var width = imgData.width;
  8289. var height = imgData.height;
  8290. var imgSrc = convertImgDataToPng(imgData);
  8291. var cliprect = document.createElementNS(NS, 'svg:rect');
  8292. cliprect.setAttributeNS(null, 'x', '0');
  8293. cliprect.setAttributeNS(null, 'y', '0');
  8294. cliprect.setAttributeNS(null, 'width', pf(width));
  8295. cliprect.setAttributeNS(null, 'height', pf(height));
  8296. current.element = cliprect;
  8297. this.clip('nonzero');
  8298. var imgEl = document.createElementNS(NS, 'svg:image');
  8299. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  8300. imgEl.setAttributeNS(null, 'x', '0');
  8301. imgEl.setAttributeNS(null, 'y', pf(-height));
  8302. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  8303. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  8304. imgEl.setAttributeNS(null, 'transform',
  8305. 'scale(' + pf(1 / width) + ' ' +
  8306. pf(-1 / height) + ')');
  8307. if (mask) {
  8308. mask.appendChild(imgEl);
  8309. } else {
  8310. this.tgrp.appendChild(imgEl);
  8311. }
  8312. if (current.pendingClip) {
  8313. this.cgrp.appendChild(this.tgrp);
  8314. this.pgrp.appendChild(this.cgrp);
  8315. } else {
  8316. this.pgrp.appendChild(this.tgrp);
  8317. }
  8318. },
  8319. paintImageMaskXObject:
  8320. function SVGGraphics_paintImageMaskXObject(imgData) {
  8321. var current = this.current;
  8322. var width = imgData.width;
  8323. var height = imgData.height;
  8324. var fillColor = current.fillColor;
  8325. current.maskId = 'mask' + maskCount++;
  8326. var mask = document.createElementNS(NS, 'svg:mask');
  8327. mask.setAttributeNS(null, 'id', current.maskId);
  8328. var rect = document.createElementNS(NS, 'svg:rect');
  8329. rect.setAttributeNS(null, 'x', '0');
  8330. rect.setAttributeNS(null, 'y', '0');
  8331. rect.setAttributeNS(null, 'width', pf(width));
  8332. rect.setAttributeNS(null, 'height', pf(height));
  8333. rect.setAttributeNS(null, 'fill', fillColor);
  8334. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  8335. this.defs.appendChild(mask);
  8336. this.tgrp.appendChild(rect);
  8337. this.paintInlineImageXObject(imgData, mask);
  8338. },
  8339. paintFormXObjectBegin:
  8340. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  8341. this.save();
  8342. if (isArray(matrix) && matrix.length === 6) {
  8343. this.transform(matrix[0], matrix[1], matrix[2],
  8344. matrix[3], matrix[4], matrix[5]);
  8345. }
  8346. if (isArray(bbox) && bbox.length === 4) {
  8347. var width = bbox[2] - bbox[0];
  8348. var height = bbox[3] - bbox[1];
  8349. var cliprect = document.createElementNS(NS, 'svg:rect');
  8350. cliprect.setAttributeNS(null, 'x', bbox[0]);
  8351. cliprect.setAttributeNS(null, 'y', bbox[1]);
  8352. cliprect.setAttributeNS(null, 'width', pf(width));
  8353. cliprect.setAttributeNS(null, 'height', pf(height));
  8354. this.current.element = cliprect;
  8355. this.clip('nonzero');
  8356. this.endPath();
  8357. }
  8358. },
  8359. paintFormXObjectEnd:
  8360. function SVGGraphics_paintFormXObjectEnd() {
  8361. this.restore();
  8362. }
  8363. };
  8364. return SVGGraphics;
  8365. })();
  8366. PDFJS.SVGGraphics = SVGGraphics;
  8367. exports.SVGGraphics = SVGGraphics;
  8368. }));
  8369. var NetworkManager = (function NetworkManagerClosure() {
  8370. var OK_RESPONSE = 200;
  8371. var PARTIAL_CONTENT_RESPONSE = 206;
  8372. function NetworkManager(url, args) {
  8373. this.url = url;
  8374. args = args || {};
  8375. this.isHttp = /^https?:/i.test(url);
  8376. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8377. this.withCredentials = args.withCredentials || false;
  8378. this.getXhr = args.getXhr ||
  8379. function NetworkManager_getXhr() {
  8380. return new XMLHttpRequest();
  8381. };
  8382. this.currXhrId = 0;
  8383. this.pendingRequests = {};
  8384. this.loadedRequests = {};
  8385. }
  8386. function getArrayBuffer(xhr) {
  8387. var data = xhr.response;
  8388. if (typeof data !== 'string') {
  8389. return data;
  8390. }
  8391. var length = data.length;
  8392. var array = new Uint8Array(length);
  8393. for (var i = 0; i < length; i++) {
  8394. array[i] = data.charCodeAt(i) & 0xFF;
  8395. }
  8396. return array.buffer;
  8397. }
  8398. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8399. try {
  8400. var x = new XMLHttpRequest();
  8401. // Firefox 37- required .open() to be called before setting responseType.
  8402. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8403. // Even though the URL is not visited, .open() could fail if the URL is
  8404. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8405. // When this error occurs, this feature detection method will mistakenly
  8406. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8407. x.open('GET', 'https://example.com');
  8408. x.responseType = 'moz-chunked-arraybuffer';
  8409. return x.responseType === 'moz-chunked-arraybuffer';
  8410. } catch (e) {
  8411. return false;
  8412. }
  8413. })();
  8414. NetworkManager.prototype = {
  8415. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8416. var args = {
  8417. begin: begin,
  8418. end: end
  8419. };
  8420. for (var prop in listeners) {
  8421. args[prop] = listeners[prop];
  8422. }
  8423. return this.request(args);
  8424. },
  8425. requestFull: function NetworkManager_requestFull(listeners) {
  8426. return this.request(listeners);
  8427. },
  8428. request: function NetworkManager_request(args) {
  8429. var xhr = this.getXhr();
  8430. var xhrId = this.currXhrId++;
  8431. var pendingRequest = this.pendingRequests[xhrId] = {
  8432. xhr: xhr
  8433. };
  8434. xhr.open('GET', this.url);
  8435. xhr.withCredentials = this.withCredentials;
  8436. for (var property in this.httpHeaders) {
  8437. var value = this.httpHeaders[property];
  8438. if (typeof value === 'undefined') {
  8439. continue;
  8440. }
  8441. xhr.setRequestHeader(property, value);
  8442. }
  8443. if (this.isHttp && 'begin' in args && 'end' in args) {
  8444. var rangeStr = args.begin + '-' + (args.end - 1);
  8445. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8446. pendingRequest.expectedStatus = 206;
  8447. } else {
  8448. pendingRequest.expectedStatus = 200;
  8449. }
  8450. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8451. if (useMozChunkedLoading) {
  8452. xhr.responseType = 'moz-chunked-arraybuffer';
  8453. pendingRequest.onProgressiveData = args.onProgressiveData;
  8454. pendingRequest.mozChunked = true;
  8455. } else {
  8456. xhr.responseType = 'arraybuffer';
  8457. }
  8458. if (args.onError) {
  8459. xhr.onerror = function(evt) {
  8460. args.onError(xhr.status);
  8461. };
  8462. }
  8463. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8464. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8465. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8466. pendingRequest.onDone = args.onDone;
  8467. pendingRequest.onError = args.onError;
  8468. pendingRequest.onProgress = args.onProgress;
  8469. xhr.send(null);
  8470. return xhrId;
  8471. },
  8472. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8473. var pendingRequest = this.pendingRequests[xhrId];
  8474. if (!pendingRequest) {
  8475. // Maybe abortRequest was called...
  8476. return;
  8477. }
  8478. if (pendingRequest.mozChunked) {
  8479. var chunk = getArrayBuffer(pendingRequest.xhr);
  8480. pendingRequest.onProgressiveData(chunk);
  8481. }
  8482. var onProgress = pendingRequest.onProgress;
  8483. if (onProgress) {
  8484. onProgress(evt);
  8485. }
  8486. },
  8487. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8488. var pendingRequest = this.pendingRequests[xhrId];
  8489. if (!pendingRequest) {
  8490. // Maybe abortRequest was called...
  8491. return;
  8492. }
  8493. var xhr = pendingRequest.xhr;
  8494. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8495. pendingRequest.onHeadersReceived();
  8496. delete pendingRequest.onHeadersReceived;
  8497. }
  8498. if (xhr.readyState !== 4) {
  8499. return;
  8500. }
  8501. if (!(xhrId in this.pendingRequests)) {
  8502. // The XHR request might have been aborted in onHeadersReceived()
  8503. // callback, in which case we should abort request
  8504. return;
  8505. }
  8506. delete this.pendingRequests[xhrId];
  8507. // success status == 0 can be on ftp, file and other protocols
  8508. if (xhr.status === 0 && this.isHttp) {
  8509. if (pendingRequest.onError) {
  8510. pendingRequest.onError(xhr.status);
  8511. }
  8512. return;
  8513. }
  8514. var xhrStatus = xhr.status || OK_RESPONSE;
  8515. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8516. // "A server MAY ignore the Range header". This means it's possible to
  8517. // get a 200 rather than a 206 response from a range request.
  8518. var ok_response_on_range_request =
  8519. xhrStatus === OK_RESPONSE &&
  8520. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8521. if (!ok_response_on_range_request &&
  8522. xhrStatus !== pendingRequest.expectedStatus) {
  8523. if (pendingRequest.onError) {
  8524. pendingRequest.onError(xhr.status);
  8525. }
  8526. return;
  8527. }
  8528. this.loadedRequests[xhrId] = true;
  8529. var chunk = getArrayBuffer(xhr);
  8530. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8531. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8532. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8533. var begin = parseInt(matches[1], 10);
  8534. pendingRequest.onDone({
  8535. begin: begin,
  8536. chunk: chunk
  8537. });
  8538. } else if (pendingRequest.onProgressiveData) {
  8539. pendingRequest.onDone(null);
  8540. } else if (chunk) {
  8541. pendingRequest.onDone({
  8542. begin: 0,
  8543. chunk: chunk
  8544. });
  8545. } else if (pendingRequest.onError) {
  8546. pendingRequest.onError(xhr.status);
  8547. }
  8548. },
  8549. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8550. for (var xhrId in this.pendingRequests) {
  8551. return true;
  8552. }
  8553. return false;
  8554. },
  8555. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8556. return this.pendingRequests[xhrId].xhr;
  8557. },
  8558. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8559. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8560. },
  8561. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8562. return xhrId in this.pendingRequests;
  8563. },
  8564. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8565. return xhrId in this.loadedRequests;
  8566. },
  8567. abortAllRequests: function NetworkManager_abortAllRequests() {
  8568. for (var xhrId in this.pendingRequests) {
  8569. this.abortRequest(xhrId | 0);
  8570. }
  8571. },
  8572. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8573. var xhr = this.pendingRequests[xhrId].xhr;
  8574. delete this.pendingRequests[xhrId];
  8575. xhr.abort();
  8576. }
  8577. };
  8578. return NetworkManager;
  8579. })();
  8580. (function (root, factory) {
  8581. {
  8582. factory((root.pdfjsCoreArithmeticDecoder = {}));
  8583. }
  8584. }(this, function (exports) {
  8585. /* This class implements the QM Coder decoding as defined in
  8586. * JPEG 2000 Part I Final Committee Draft Version 1.0
  8587. * Annex C.3 Arithmetic decoding procedure
  8588. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  8589. *
  8590. * The arithmetic decoder is used in conjunction with context models to decode
  8591. * JPEG2000 and JBIG2 streams.
  8592. */
  8593. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  8594. // Table C-2
  8595. var QeTable = [
  8596. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  8597. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  8598. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  8599. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  8600. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  8601. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  8602. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  8603. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  8604. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  8605. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  8606. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  8607. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  8608. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  8609. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  8610. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  8611. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  8612. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  8613. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  8614. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  8615. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  8616. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  8617. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  8618. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  8619. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  8620. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  8621. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  8622. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  8623. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  8624. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  8625. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  8626. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  8627. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  8628. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  8629. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  8630. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  8631. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  8632. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  8633. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  8634. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  8635. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  8636. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  8637. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  8638. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  8639. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  8640. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  8641. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  8642. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  8643. ];
  8644. // C.3.5 Initialisation of the decoder (INITDEC)
  8645. function ArithmeticDecoder(data, start, end) {
  8646. this.data = data;
  8647. this.bp = start;
  8648. this.dataEnd = end;
  8649. this.chigh = data[start];
  8650. this.clow = 0;
  8651. this.byteIn();
  8652. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  8653. this.clow = (this.clow << 7) & 0xFFFF;
  8654. this.ct -= 7;
  8655. this.a = 0x8000;
  8656. }
  8657. ArithmeticDecoder.prototype = {
  8658. // C.3.4 Compressed data input (BYTEIN)
  8659. byteIn: function ArithmeticDecoder_byteIn() {
  8660. var data = this.data;
  8661. var bp = this.bp;
  8662. if (data[bp] === 0xFF) {
  8663. var b1 = data[bp + 1];
  8664. if (b1 > 0x8F) {
  8665. this.clow += 0xFF00;
  8666. this.ct = 8;
  8667. } else {
  8668. bp++;
  8669. this.clow += (data[bp] << 9);
  8670. this.ct = 7;
  8671. this.bp = bp;
  8672. }
  8673. } else {
  8674. bp++;
  8675. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  8676. this.ct = 8;
  8677. this.bp = bp;
  8678. }
  8679. if (this.clow > 0xFFFF) {
  8680. this.chigh += (this.clow >> 16);
  8681. this.clow &= 0xFFFF;
  8682. }
  8683. },
  8684. // C.3.2 Decoding a decision (DECODE)
  8685. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  8686. // contexts are packed into 1 byte:
  8687. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  8688. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  8689. var qeTableIcx = QeTable[cx_index];
  8690. var qeIcx = qeTableIcx.qe;
  8691. var d;
  8692. var a = this.a - qeIcx;
  8693. if (this.chigh < qeIcx) {
  8694. // exchangeLps
  8695. if (a < qeIcx) {
  8696. a = qeIcx;
  8697. d = cx_mps;
  8698. cx_index = qeTableIcx.nmps;
  8699. } else {
  8700. a = qeIcx;
  8701. d = 1 ^ cx_mps;
  8702. if (qeTableIcx.switchFlag === 1) {
  8703. cx_mps = d;
  8704. }
  8705. cx_index = qeTableIcx.nlps;
  8706. }
  8707. } else {
  8708. this.chigh -= qeIcx;
  8709. if ((a & 0x8000) !== 0) {
  8710. this.a = a;
  8711. return cx_mps;
  8712. }
  8713. // exchangeMps
  8714. if (a < qeIcx) {
  8715. d = 1 ^ cx_mps;
  8716. if (qeTableIcx.switchFlag === 1) {
  8717. cx_mps = d;
  8718. }
  8719. cx_index = qeTableIcx.nlps;
  8720. } else {
  8721. d = cx_mps;
  8722. cx_index = qeTableIcx.nmps;
  8723. }
  8724. }
  8725. // C.3.3 renormD;
  8726. do {
  8727. if (this.ct === 0) {
  8728. this.byteIn();
  8729. }
  8730. a <<= 1;
  8731. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  8732. this.clow = (this.clow << 1) & 0xFFFF;
  8733. this.ct--;
  8734. } while ((a & 0x8000) === 0);
  8735. this.a = a;
  8736. contexts[pos] = cx_index << 1 | cx_mps;
  8737. return d;
  8738. }
  8739. };
  8740. return ArithmeticDecoder;
  8741. })();
  8742. exports.ArithmeticDecoder = ArithmeticDecoder;
  8743. }));
  8744. (function (root, factory) {
  8745. {
  8746. factory((root.pdfjsCoreCharsets = {}));
  8747. }
  8748. }(this, function (exports) {
  8749. var ISOAdobeCharset = [
  8750. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  8751. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  8752. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  8753. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  8754. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  8755. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8756. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  8757. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  8758. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  8759. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8760. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  8761. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  8762. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  8763. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  8764. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  8765. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  8766. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  8767. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  8768. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  8769. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  8770. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  8771. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  8772. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  8773. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  8774. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  8775. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  8776. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  8777. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  8778. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  8779. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  8780. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  8781. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  8782. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  8783. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  8784. ];
  8785. var ExpertCharset = [
  8786. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  8787. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  8788. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  8789. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  8790. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  8791. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  8792. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  8793. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  8794. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8795. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8796. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8797. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  8798. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  8799. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  8800. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  8801. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  8802. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  8803. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  8804. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  8805. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  8806. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  8807. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  8808. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8809. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8810. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8811. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8812. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8813. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8814. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  8815. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  8816. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  8817. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  8818. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  8819. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  8820. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  8821. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  8822. 'Ydieresissmall'
  8823. ];
  8824. var ExpertSubsetCharset = [
  8825. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  8826. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  8827. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  8828. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  8829. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  8830. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  8831. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  8832. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8833. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8834. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8835. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  8836. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  8837. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  8838. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8839. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8840. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8841. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8842. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8843. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8844. 'periodinferior', 'commainferior'
  8845. ];
  8846. exports.ISOAdobeCharset = ISOAdobeCharset;
  8847. exports.ExpertCharset = ExpertCharset;
  8848. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  8849. }));
  8850. (function (root, factory) {
  8851. {
  8852. factory((root.pdfjsCoreGlyphList = {}));
  8853. }
  8854. }(this, function (exports) {
  8855. var GlyphsUnicode = {
  8856. A: 0x0041,
  8857. AE: 0x00C6,
  8858. AEacute: 0x01FC,
  8859. AEmacron: 0x01E2,
  8860. AEsmall: 0xF7E6,
  8861. Aacute: 0x00C1,
  8862. Aacutesmall: 0xF7E1,
  8863. Abreve: 0x0102,
  8864. Abreveacute: 0x1EAE,
  8865. Abrevecyrillic: 0x04D0,
  8866. Abrevedotbelow: 0x1EB6,
  8867. Abrevegrave: 0x1EB0,
  8868. Abrevehookabove: 0x1EB2,
  8869. Abrevetilde: 0x1EB4,
  8870. Acaron: 0x01CD,
  8871. Acircle: 0x24B6,
  8872. Acircumflex: 0x00C2,
  8873. Acircumflexacute: 0x1EA4,
  8874. Acircumflexdotbelow: 0x1EAC,
  8875. Acircumflexgrave: 0x1EA6,
  8876. Acircumflexhookabove: 0x1EA8,
  8877. Acircumflexsmall: 0xF7E2,
  8878. Acircumflextilde: 0x1EAA,
  8879. Acute: 0xF6C9,
  8880. Acutesmall: 0xF7B4,
  8881. Acyrillic: 0x0410,
  8882. Adblgrave: 0x0200,
  8883. Adieresis: 0x00C4,
  8884. Adieresiscyrillic: 0x04D2,
  8885. Adieresismacron: 0x01DE,
  8886. Adieresissmall: 0xF7E4,
  8887. Adotbelow: 0x1EA0,
  8888. Adotmacron: 0x01E0,
  8889. Agrave: 0x00C0,
  8890. Agravesmall: 0xF7E0,
  8891. Ahookabove: 0x1EA2,
  8892. Aiecyrillic: 0x04D4,
  8893. Ainvertedbreve: 0x0202,
  8894. Alpha: 0x0391,
  8895. Alphatonos: 0x0386,
  8896. Amacron: 0x0100,
  8897. Amonospace: 0xFF21,
  8898. Aogonek: 0x0104,
  8899. Aring: 0x00C5,
  8900. Aringacute: 0x01FA,
  8901. Aringbelow: 0x1E00,
  8902. Aringsmall: 0xF7E5,
  8903. Asmall: 0xF761,
  8904. Atilde: 0x00C3,
  8905. Atildesmall: 0xF7E3,
  8906. Aybarmenian: 0x0531,
  8907. B: 0x0042,
  8908. Bcircle: 0x24B7,
  8909. Bdotaccent: 0x1E02,
  8910. Bdotbelow: 0x1E04,
  8911. Becyrillic: 0x0411,
  8912. Benarmenian: 0x0532,
  8913. Beta: 0x0392,
  8914. Bhook: 0x0181,
  8915. Blinebelow: 0x1E06,
  8916. Bmonospace: 0xFF22,
  8917. Brevesmall: 0xF6F4,
  8918. Bsmall: 0xF762,
  8919. Btopbar: 0x0182,
  8920. C: 0x0043,
  8921. Caarmenian: 0x053E,
  8922. Cacute: 0x0106,
  8923. Caron: 0xF6CA,
  8924. Caronsmall: 0xF6F5,
  8925. Ccaron: 0x010C,
  8926. Ccedilla: 0x00C7,
  8927. Ccedillaacute: 0x1E08,
  8928. Ccedillasmall: 0xF7E7,
  8929. Ccircle: 0x24B8,
  8930. Ccircumflex: 0x0108,
  8931. Cdot: 0x010A,
  8932. Cdotaccent: 0x010A,
  8933. Cedillasmall: 0xF7B8,
  8934. Chaarmenian: 0x0549,
  8935. Cheabkhasiancyrillic: 0x04BC,
  8936. Checyrillic: 0x0427,
  8937. Chedescenderabkhasiancyrillic: 0x04BE,
  8938. Chedescendercyrillic: 0x04B6,
  8939. Chedieresiscyrillic: 0x04F4,
  8940. Cheharmenian: 0x0543,
  8941. Chekhakassiancyrillic: 0x04CB,
  8942. Cheverticalstrokecyrillic: 0x04B8,
  8943. Chi: 0x03A7,
  8944. Chook: 0x0187,
  8945. Circumflexsmall: 0xF6F6,
  8946. Cmonospace: 0xFF23,
  8947. Coarmenian: 0x0551,
  8948. Csmall: 0xF763,
  8949. D: 0x0044,
  8950. DZ: 0x01F1,
  8951. DZcaron: 0x01C4,
  8952. Daarmenian: 0x0534,
  8953. Dafrican: 0x0189,
  8954. Dcaron: 0x010E,
  8955. Dcedilla: 0x1E10,
  8956. Dcircle: 0x24B9,
  8957. Dcircumflexbelow: 0x1E12,
  8958. Dcroat: 0x0110,
  8959. Ddotaccent: 0x1E0A,
  8960. Ddotbelow: 0x1E0C,
  8961. Decyrillic: 0x0414,
  8962. Deicoptic: 0x03EE,
  8963. Delta: 0x2206,
  8964. Deltagreek: 0x0394,
  8965. Dhook: 0x018A,
  8966. Dieresis: 0xF6CB,
  8967. DieresisAcute: 0xF6CC,
  8968. DieresisGrave: 0xF6CD,
  8969. Dieresissmall: 0xF7A8,
  8970. Digammagreek: 0x03DC,
  8971. Djecyrillic: 0x0402,
  8972. Dlinebelow: 0x1E0E,
  8973. Dmonospace: 0xFF24,
  8974. Dotaccentsmall: 0xF6F7,
  8975. Dslash: 0x0110,
  8976. Dsmall: 0xF764,
  8977. Dtopbar: 0x018B,
  8978. Dz: 0x01F2,
  8979. Dzcaron: 0x01C5,
  8980. Dzeabkhasiancyrillic: 0x04E0,
  8981. Dzecyrillic: 0x0405,
  8982. Dzhecyrillic: 0x040F,
  8983. E: 0x0045,
  8984. Eacute: 0x00C9,
  8985. Eacutesmall: 0xF7E9,
  8986. Ebreve: 0x0114,
  8987. Ecaron: 0x011A,
  8988. Ecedillabreve: 0x1E1C,
  8989. Echarmenian: 0x0535,
  8990. Ecircle: 0x24BA,
  8991. Ecircumflex: 0x00CA,
  8992. Ecircumflexacute: 0x1EBE,
  8993. Ecircumflexbelow: 0x1E18,
  8994. Ecircumflexdotbelow: 0x1EC6,
  8995. Ecircumflexgrave: 0x1EC0,
  8996. Ecircumflexhookabove: 0x1EC2,
  8997. Ecircumflexsmall: 0xF7EA,
  8998. Ecircumflextilde: 0x1EC4,
  8999. Ecyrillic: 0x0404,
  9000. Edblgrave: 0x0204,
  9001. Edieresis: 0x00CB,
  9002. Edieresissmall: 0xF7EB,
  9003. Edot: 0x0116,
  9004. Edotaccent: 0x0116,
  9005. Edotbelow: 0x1EB8,
  9006. Efcyrillic: 0x0424,
  9007. Egrave: 0x00C8,
  9008. Egravesmall: 0xF7E8,
  9009. Eharmenian: 0x0537,
  9010. Ehookabove: 0x1EBA,
  9011. Eightroman: 0x2167,
  9012. Einvertedbreve: 0x0206,
  9013. Eiotifiedcyrillic: 0x0464,
  9014. Elcyrillic: 0x041B,
  9015. Elevenroman: 0x216A,
  9016. Emacron: 0x0112,
  9017. Emacronacute: 0x1E16,
  9018. Emacrongrave: 0x1E14,
  9019. Emcyrillic: 0x041C,
  9020. Emonospace: 0xFF25,
  9021. Encyrillic: 0x041D,
  9022. Endescendercyrillic: 0x04A2,
  9023. Eng: 0x014A,
  9024. Enghecyrillic: 0x04A4,
  9025. Enhookcyrillic: 0x04C7,
  9026. Eogonek: 0x0118,
  9027. Eopen: 0x0190,
  9028. Epsilon: 0x0395,
  9029. Epsilontonos: 0x0388,
  9030. Ercyrillic: 0x0420,
  9031. Ereversed: 0x018E,
  9032. Ereversedcyrillic: 0x042D,
  9033. Escyrillic: 0x0421,
  9034. Esdescendercyrillic: 0x04AA,
  9035. Esh: 0x01A9,
  9036. Esmall: 0xF765,
  9037. Eta: 0x0397,
  9038. Etarmenian: 0x0538,
  9039. Etatonos: 0x0389,
  9040. Eth: 0x00D0,
  9041. Ethsmall: 0xF7F0,
  9042. Etilde: 0x1EBC,
  9043. Etildebelow: 0x1E1A,
  9044. Euro: 0x20AC,
  9045. Ezh: 0x01B7,
  9046. Ezhcaron: 0x01EE,
  9047. Ezhreversed: 0x01B8,
  9048. F: 0x0046,
  9049. Fcircle: 0x24BB,
  9050. Fdotaccent: 0x1E1E,
  9051. Feharmenian: 0x0556,
  9052. Feicoptic: 0x03E4,
  9053. Fhook: 0x0191,
  9054. Fitacyrillic: 0x0472,
  9055. Fiveroman: 0x2164,
  9056. Fmonospace: 0xFF26,
  9057. Fourroman: 0x2163,
  9058. Fsmall: 0xF766,
  9059. G: 0x0047,
  9060. GBsquare: 0x3387,
  9061. Gacute: 0x01F4,
  9062. Gamma: 0x0393,
  9063. Gammaafrican: 0x0194,
  9064. Gangiacoptic: 0x03EA,
  9065. Gbreve: 0x011E,
  9066. Gcaron: 0x01E6,
  9067. Gcedilla: 0x0122,
  9068. Gcircle: 0x24BC,
  9069. Gcircumflex: 0x011C,
  9070. Gcommaaccent: 0x0122,
  9071. Gdot: 0x0120,
  9072. Gdotaccent: 0x0120,
  9073. Gecyrillic: 0x0413,
  9074. Ghadarmenian: 0x0542,
  9075. Ghemiddlehookcyrillic: 0x0494,
  9076. Ghestrokecyrillic: 0x0492,
  9077. Gheupturncyrillic: 0x0490,
  9078. Ghook: 0x0193,
  9079. Gimarmenian: 0x0533,
  9080. Gjecyrillic: 0x0403,
  9081. Gmacron: 0x1E20,
  9082. Gmonospace: 0xFF27,
  9083. Grave: 0xF6CE,
  9084. Gravesmall: 0xF760,
  9085. Gsmall: 0xF767,
  9086. Gsmallhook: 0x029B,
  9087. Gstroke: 0x01E4,
  9088. H: 0x0048,
  9089. H18533: 0x25CF,
  9090. H18543: 0x25AA,
  9091. H18551: 0x25AB,
  9092. H22073: 0x25A1,
  9093. HPsquare: 0x33CB,
  9094. Haabkhasiancyrillic: 0x04A8,
  9095. Hadescendercyrillic: 0x04B2,
  9096. Hardsigncyrillic: 0x042A,
  9097. Hbar: 0x0126,
  9098. Hbrevebelow: 0x1E2A,
  9099. Hcedilla: 0x1E28,
  9100. Hcircle: 0x24BD,
  9101. Hcircumflex: 0x0124,
  9102. Hdieresis: 0x1E26,
  9103. Hdotaccent: 0x1E22,
  9104. Hdotbelow: 0x1E24,
  9105. Hmonospace: 0xFF28,
  9106. Hoarmenian: 0x0540,
  9107. Horicoptic: 0x03E8,
  9108. Hsmall: 0xF768,
  9109. Hungarumlaut: 0xF6CF,
  9110. Hungarumlautsmall: 0xF6F8,
  9111. Hzsquare: 0x3390,
  9112. I: 0x0049,
  9113. IAcyrillic: 0x042F,
  9114. IJ: 0x0132,
  9115. IUcyrillic: 0x042E,
  9116. Iacute: 0x00CD,
  9117. Iacutesmall: 0xF7ED,
  9118. Ibreve: 0x012C,
  9119. Icaron: 0x01CF,
  9120. Icircle: 0x24BE,
  9121. Icircumflex: 0x00CE,
  9122. Icircumflexsmall: 0xF7EE,
  9123. Icyrillic: 0x0406,
  9124. Idblgrave: 0x0208,
  9125. Idieresis: 0x00CF,
  9126. Idieresisacute: 0x1E2E,
  9127. Idieresiscyrillic: 0x04E4,
  9128. Idieresissmall: 0xF7EF,
  9129. Idot: 0x0130,
  9130. Idotaccent: 0x0130,
  9131. Idotbelow: 0x1ECA,
  9132. Iebrevecyrillic: 0x04D6,
  9133. Iecyrillic: 0x0415,
  9134. Ifraktur: 0x2111,
  9135. Igrave: 0x00CC,
  9136. Igravesmall: 0xF7EC,
  9137. Ihookabove: 0x1EC8,
  9138. Iicyrillic: 0x0418,
  9139. Iinvertedbreve: 0x020A,
  9140. Iishortcyrillic: 0x0419,
  9141. Imacron: 0x012A,
  9142. Imacroncyrillic: 0x04E2,
  9143. Imonospace: 0xFF29,
  9144. Iniarmenian: 0x053B,
  9145. Iocyrillic: 0x0401,
  9146. Iogonek: 0x012E,
  9147. Iota: 0x0399,
  9148. Iotaafrican: 0x0196,
  9149. Iotadieresis: 0x03AA,
  9150. Iotatonos: 0x038A,
  9151. Ismall: 0xF769,
  9152. Istroke: 0x0197,
  9153. Itilde: 0x0128,
  9154. Itildebelow: 0x1E2C,
  9155. Izhitsacyrillic: 0x0474,
  9156. Izhitsadblgravecyrillic: 0x0476,
  9157. J: 0x004A,
  9158. Jaarmenian: 0x0541,
  9159. Jcircle: 0x24BF,
  9160. Jcircumflex: 0x0134,
  9161. Jecyrillic: 0x0408,
  9162. Jheharmenian: 0x054B,
  9163. Jmonospace: 0xFF2A,
  9164. Jsmall: 0xF76A,
  9165. K: 0x004B,
  9166. KBsquare: 0x3385,
  9167. KKsquare: 0x33CD,
  9168. Kabashkircyrillic: 0x04A0,
  9169. Kacute: 0x1E30,
  9170. Kacyrillic: 0x041A,
  9171. Kadescendercyrillic: 0x049A,
  9172. Kahookcyrillic: 0x04C3,
  9173. Kappa: 0x039A,
  9174. Kastrokecyrillic: 0x049E,
  9175. Kaverticalstrokecyrillic: 0x049C,
  9176. Kcaron: 0x01E8,
  9177. Kcedilla: 0x0136,
  9178. Kcircle: 0x24C0,
  9179. Kcommaaccent: 0x0136,
  9180. Kdotbelow: 0x1E32,
  9181. Keharmenian: 0x0554,
  9182. Kenarmenian: 0x053F,
  9183. Khacyrillic: 0x0425,
  9184. Kheicoptic: 0x03E6,
  9185. Khook: 0x0198,
  9186. Kjecyrillic: 0x040C,
  9187. Klinebelow: 0x1E34,
  9188. Kmonospace: 0xFF2B,
  9189. Koppacyrillic: 0x0480,
  9190. Koppagreek: 0x03DE,
  9191. Ksicyrillic: 0x046E,
  9192. Ksmall: 0xF76B,
  9193. L: 0x004C,
  9194. LJ: 0x01C7,
  9195. LL: 0xF6BF,
  9196. Lacute: 0x0139,
  9197. Lambda: 0x039B,
  9198. Lcaron: 0x013D,
  9199. Lcedilla: 0x013B,
  9200. Lcircle: 0x24C1,
  9201. Lcircumflexbelow: 0x1E3C,
  9202. Lcommaaccent: 0x013B,
  9203. Ldot: 0x013F,
  9204. Ldotaccent: 0x013F,
  9205. Ldotbelow: 0x1E36,
  9206. Ldotbelowmacron: 0x1E38,
  9207. Liwnarmenian: 0x053C,
  9208. Lj: 0x01C8,
  9209. Ljecyrillic: 0x0409,
  9210. Llinebelow: 0x1E3A,
  9211. Lmonospace: 0xFF2C,
  9212. Lslash: 0x0141,
  9213. Lslashsmall: 0xF6F9,
  9214. Lsmall: 0xF76C,
  9215. M: 0x004D,
  9216. MBsquare: 0x3386,
  9217. Macron: 0xF6D0,
  9218. Macronsmall: 0xF7AF,
  9219. Macute: 0x1E3E,
  9220. Mcircle: 0x24C2,
  9221. Mdotaccent: 0x1E40,
  9222. Mdotbelow: 0x1E42,
  9223. Menarmenian: 0x0544,
  9224. Mmonospace: 0xFF2D,
  9225. Msmall: 0xF76D,
  9226. Mturned: 0x019C,
  9227. Mu: 0x039C,
  9228. N: 0x004E,
  9229. NJ: 0x01CA,
  9230. Nacute: 0x0143,
  9231. Ncaron: 0x0147,
  9232. Ncedilla: 0x0145,
  9233. Ncircle: 0x24C3,
  9234. Ncircumflexbelow: 0x1E4A,
  9235. Ncommaaccent: 0x0145,
  9236. Ndotaccent: 0x1E44,
  9237. Ndotbelow: 0x1E46,
  9238. Nhookleft: 0x019D,
  9239. Nineroman: 0x2168,
  9240. Nj: 0x01CB,
  9241. Njecyrillic: 0x040A,
  9242. Nlinebelow: 0x1E48,
  9243. Nmonospace: 0xFF2E,
  9244. Nowarmenian: 0x0546,
  9245. Nsmall: 0xF76E,
  9246. Ntilde: 0x00D1,
  9247. Ntildesmall: 0xF7F1,
  9248. Nu: 0x039D,
  9249. O: 0x004F,
  9250. OE: 0x0152,
  9251. OEsmall: 0xF6FA,
  9252. Oacute: 0x00D3,
  9253. Oacutesmall: 0xF7F3,
  9254. Obarredcyrillic: 0x04E8,
  9255. Obarreddieresiscyrillic: 0x04EA,
  9256. Obreve: 0x014E,
  9257. Ocaron: 0x01D1,
  9258. Ocenteredtilde: 0x019F,
  9259. Ocircle: 0x24C4,
  9260. Ocircumflex: 0x00D4,
  9261. Ocircumflexacute: 0x1ED0,
  9262. Ocircumflexdotbelow: 0x1ED8,
  9263. Ocircumflexgrave: 0x1ED2,
  9264. Ocircumflexhookabove: 0x1ED4,
  9265. Ocircumflexsmall: 0xF7F4,
  9266. Ocircumflextilde: 0x1ED6,
  9267. Ocyrillic: 0x041E,
  9268. Odblacute: 0x0150,
  9269. Odblgrave: 0x020C,
  9270. Odieresis: 0x00D6,
  9271. Odieresiscyrillic: 0x04E6,
  9272. Odieresissmall: 0xF7F6,
  9273. Odotbelow: 0x1ECC,
  9274. Ogoneksmall: 0xF6FB,
  9275. Ograve: 0x00D2,
  9276. Ogravesmall: 0xF7F2,
  9277. Oharmenian: 0x0555,
  9278. Ohm: 0x2126,
  9279. Ohookabove: 0x1ECE,
  9280. Ohorn: 0x01A0,
  9281. Ohornacute: 0x1EDA,
  9282. Ohorndotbelow: 0x1EE2,
  9283. Ohorngrave: 0x1EDC,
  9284. Ohornhookabove: 0x1EDE,
  9285. Ohorntilde: 0x1EE0,
  9286. Ohungarumlaut: 0x0150,
  9287. Oi: 0x01A2,
  9288. Oinvertedbreve: 0x020E,
  9289. Omacron: 0x014C,
  9290. Omacronacute: 0x1E52,
  9291. Omacrongrave: 0x1E50,
  9292. Omega: 0x2126,
  9293. Omegacyrillic: 0x0460,
  9294. Omegagreek: 0x03A9,
  9295. Omegaroundcyrillic: 0x047A,
  9296. Omegatitlocyrillic: 0x047C,
  9297. Omegatonos: 0x038F,
  9298. Omicron: 0x039F,
  9299. Omicrontonos: 0x038C,
  9300. Omonospace: 0xFF2F,
  9301. Oneroman: 0x2160,
  9302. Oogonek: 0x01EA,
  9303. Oogonekmacron: 0x01EC,
  9304. Oopen: 0x0186,
  9305. Oslash: 0x00D8,
  9306. Oslashacute: 0x01FE,
  9307. Oslashsmall: 0xF7F8,
  9308. Osmall: 0xF76F,
  9309. Ostrokeacute: 0x01FE,
  9310. Otcyrillic: 0x047E,
  9311. Otilde: 0x00D5,
  9312. Otildeacute: 0x1E4C,
  9313. Otildedieresis: 0x1E4E,
  9314. Otildesmall: 0xF7F5,
  9315. P: 0x0050,
  9316. Pacute: 0x1E54,
  9317. Pcircle: 0x24C5,
  9318. Pdotaccent: 0x1E56,
  9319. Pecyrillic: 0x041F,
  9320. Peharmenian: 0x054A,
  9321. Pemiddlehookcyrillic: 0x04A6,
  9322. Phi: 0x03A6,
  9323. Phook: 0x01A4,
  9324. Pi: 0x03A0,
  9325. Piwrarmenian: 0x0553,
  9326. Pmonospace: 0xFF30,
  9327. Psi: 0x03A8,
  9328. Psicyrillic: 0x0470,
  9329. Psmall: 0xF770,
  9330. Q: 0x0051,
  9331. Qcircle: 0x24C6,
  9332. Qmonospace: 0xFF31,
  9333. Qsmall: 0xF771,
  9334. R: 0x0052,
  9335. Raarmenian: 0x054C,
  9336. Racute: 0x0154,
  9337. Rcaron: 0x0158,
  9338. Rcedilla: 0x0156,
  9339. Rcircle: 0x24C7,
  9340. Rcommaaccent: 0x0156,
  9341. Rdblgrave: 0x0210,
  9342. Rdotaccent: 0x1E58,
  9343. Rdotbelow: 0x1E5A,
  9344. Rdotbelowmacron: 0x1E5C,
  9345. Reharmenian: 0x0550,
  9346. Rfraktur: 0x211C,
  9347. Rho: 0x03A1,
  9348. Ringsmall: 0xF6FC,
  9349. Rinvertedbreve: 0x0212,
  9350. Rlinebelow: 0x1E5E,
  9351. Rmonospace: 0xFF32,
  9352. Rsmall: 0xF772,
  9353. Rsmallinverted: 0x0281,
  9354. Rsmallinvertedsuperior: 0x02B6,
  9355. S: 0x0053,
  9356. SF010000: 0x250C,
  9357. SF020000: 0x2514,
  9358. SF030000: 0x2510,
  9359. SF040000: 0x2518,
  9360. SF050000: 0x253C,
  9361. SF060000: 0x252C,
  9362. SF070000: 0x2534,
  9363. SF080000: 0x251C,
  9364. SF090000: 0x2524,
  9365. SF100000: 0x2500,
  9366. SF110000: 0x2502,
  9367. SF190000: 0x2561,
  9368. SF200000: 0x2562,
  9369. SF210000: 0x2556,
  9370. SF220000: 0x2555,
  9371. SF230000: 0x2563,
  9372. SF240000: 0x2551,
  9373. SF250000: 0x2557,
  9374. SF260000: 0x255D,
  9375. SF270000: 0x255C,
  9376. SF280000: 0x255B,
  9377. SF360000: 0x255E,
  9378. SF370000: 0x255F,
  9379. SF380000: 0x255A,
  9380. SF390000: 0x2554,
  9381. SF400000: 0x2569,
  9382. SF410000: 0x2566,
  9383. SF420000: 0x2560,
  9384. SF430000: 0x2550,
  9385. SF440000: 0x256C,
  9386. SF450000: 0x2567,
  9387. SF460000: 0x2568,
  9388. SF470000: 0x2564,
  9389. SF480000: 0x2565,
  9390. SF490000: 0x2559,
  9391. SF500000: 0x2558,
  9392. SF510000: 0x2552,
  9393. SF520000: 0x2553,
  9394. SF530000: 0x256B,
  9395. SF540000: 0x256A,
  9396. Sacute: 0x015A,
  9397. Sacutedotaccent: 0x1E64,
  9398. Sampigreek: 0x03E0,
  9399. Scaron: 0x0160,
  9400. Scarondotaccent: 0x1E66,
  9401. Scaronsmall: 0xF6FD,
  9402. Scedilla: 0x015E,
  9403. Schwa: 0x018F,
  9404. Schwacyrillic: 0x04D8,
  9405. Schwadieresiscyrillic: 0x04DA,
  9406. Scircle: 0x24C8,
  9407. Scircumflex: 0x015C,
  9408. Scommaaccent: 0x0218,
  9409. Sdotaccent: 0x1E60,
  9410. Sdotbelow: 0x1E62,
  9411. Sdotbelowdotaccent: 0x1E68,
  9412. Seharmenian: 0x054D,
  9413. Sevenroman: 0x2166,
  9414. Shaarmenian: 0x0547,
  9415. Shacyrillic: 0x0428,
  9416. Shchacyrillic: 0x0429,
  9417. Sheicoptic: 0x03E2,
  9418. Shhacyrillic: 0x04BA,
  9419. Shimacoptic: 0x03EC,
  9420. Sigma: 0x03A3,
  9421. Sixroman: 0x2165,
  9422. Smonospace: 0xFF33,
  9423. Softsigncyrillic: 0x042C,
  9424. Ssmall: 0xF773,
  9425. Stigmagreek: 0x03DA,
  9426. T: 0x0054,
  9427. Tau: 0x03A4,
  9428. Tbar: 0x0166,
  9429. Tcaron: 0x0164,
  9430. Tcedilla: 0x0162,
  9431. Tcircle: 0x24C9,
  9432. Tcircumflexbelow: 0x1E70,
  9433. Tcommaaccent: 0x0162,
  9434. Tdotaccent: 0x1E6A,
  9435. Tdotbelow: 0x1E6C,
  9436. Tecyrillic: 0x0422,
  9437. Tedescendercyrillic: 0x04AC,
  9438. Tenroman: 0x2169,
  9439. Tetsecyrillic: 0x04B4,
  9440. Theta: 0x0398,
  9441. Thook: 0x01AC,
  9442. Thorn: 0x00DE,
  9443. Thornsmall: 0xF7FE,
  9444. Threeroman: 0x2162,
  9445. Tildesmall: 0xF6FE,
  9446. Tiwnarmenian: 0x054F,
  9447. Tlinebelow: 0x1E6E,
  9448. Tmonospace: 0xFF34,
  9449. Toarmenian: 0x0539,
  9450. Tonefive: 0x01BC,
  9451. Tonesix: 0x0184,
  9452. Tonetwo: 0x01A7,
  9453. Tretroflexhook: 0x01AE,
  9454. Tsecyrillic: 0x0426,
  9455. Tshecyrillic: 0x040B,
  9456. Tsmall: 0xF774,
  9457. Twelveroman: 0x216B,
  9458. Tworoman: 0x2161,
  9459. U: 0x0055,
  9460. Uacute: 0x00DA,
  9461. Uacutesmall: 0xF7FA,
  9462. Ubreve: 0x016C,
  9463. Ucaron: 0x01D3,
  9464. Ucircle: 0x24CA,
  9465. Ucircumflex: 0x00DB,
  9466. Ucircumflexbelow: 0x1E76,
  9467. Ucircumflexsmall: 0xF7FB,
  9468. Ucyrillic: 0x0423,
  9469. Udblacute: 0x0170,
  9470. Udblgrave: 0x0214,
  9471. Udieresis: 0x00DC,
  9472. Udieresisacute: 0x01D7,
  9473. Udieresisbelow: 0x1E72,
  9474. Udieresiscaron: 0x01D9,
  9475. Udieresiscyrillic: 0x04F0,
  9476. Udieresisgrave: 0x01DB,
  9477. Udieresismacron: 0x01D5,
  9478. Udieresissmall: 0xF7FC,
  9479. Udotbelow: 0x1EE4,
  9480. Ugrave: 0x00D9,
  9481. Ugravesmall: 0xF7F9,
  9482. Uhookabove: 0x1EE6,
  9483. Uhorn: 0x01AF,
  9484. Uhornacute: 0x1EE8,
  9485. Uhorndotbelow: 0x1EF0,
  9486. Uhorngrave: 0x1EEA,
  9487. Uhornhookabove: 0x1EEC,
  9488. Uhorntilde: 0x1EEE,
  9489. Uhungarumlaut: 0x0170,
  9490. Uhungarumlautcyrillic: 0x04F2,
  9491. Uinvertedbreve: 0x0216,
  9492. Ukcyrillic: 0x0478,
  9493. Umacron: 0x016A,
  9494. Umacroncyrillic: 0x04EE,
  9495. Umacrondieresis: 0x1E7A,
  9496. Umonospace: 0xFF35,
  9497. Uogonek: 0x0172,
  9498. Upsilon: 0x03A5,
  9499. Upsilon1: 0x03D2,
  9500. Upsilonacutehooksymbolgreek: 0x03D3,
  9501. Upsilonafrican: 0x01B1,
  9502. Upsilondieresis: 0x03AB,
  9503. Upsilondieresishooksymbolgreek: 0x03D4,
  9504. Upsilonhooksymbol: 0x03D2,
  9505. Upsilontonos: 0x038E,
  9506. Uring: 0x016E,
  9507. Ushortcyrillic: 0x040E,
  9508. Usmall: 0xF775,
  9509. Ustraightcyrillic: 0x04AE,
  9510. Ustraightstrokecyrillic: 0x04B0,
  9511. Utilde: 0x0168,
  9512. Utildeacute: 0x1E78,
  9513. Utildebelow: 0x1E74,
  9514. V: 0x0056,
  9515. Vcircle: 0x24CB,
  9516. Vdotbelow: 0x1E7E,
  9517. Vecyrillic: 0x0412,
  9518. Vewarmenian: 0x054E,
  9519. Vhook: 0x01B2,
  9520. Vmonospace: 0xFF36,
  9521. Voarmenian: 0x0548,
  9522. Vsmall: 0xF776,
  9523. Vtilde: 0x1E7C,
  9524. W: 0x0057,
  9525. Wacute: 0x1E82,
  9526. Wcircle: 0x24CC,
  9527. Wcircumflex: 0x0174,
  9528. Wdieresis: 0x1E84,
  9529. Wdotaccent: 0x1E86,
  9530. Wdotbelow: 0x1E88,
  9531. Wgrave: 0x1E80,
  9532. Wmonospace: 0xFF37,
  9533. Wsmall: 0xF777,
  9534. X: 0x0058,
  9535. Xcircle: 0x24CD,
  9536. Xdieresis: 0x1E8C,
  9537. Xdotaccent: 0x1E8A,
  9538. Xeharmenian: 0x053D,
  9539. Xi: 0x039E,
  9540. Xmonospace: 0xFF38,
  9541. Xsmall: 0xF778,
  9542. Y: 0x0059,
  9543. Yacute: 0x00DD,
  9544. Yacutesmall: 0xF7FD,
  9545. Yatcyrillic: 0x0462,
  9546. Ycircle: 0x24CE,
  9547. Ycircumflex: 0x0176,
  9548. Ydieresis: 0x0178,
  9549. Ydieresissmall: 0xF7FF,
  9550. Ydotaccent: 0x1E8E,
  9551. Ydotbelow: 0x1EF4,
  9552. Yericyrillic: 0x042B,
  9553. Yerudieresiscyrillic: 0x04F8,
  9554. Ygrave: 0x1EF2,
  9555. Yhook: 0x01B3,
  9556. Yhookabove: 0x1EF6,
  9557. Yiarmenian: 0x0545,
  9558. Yicyrillic: 0x0407,
  9559. Yiwnarmenian: 0x0552,
  9560. Ymonospace: 0xFF39,
  9561. Ysmall: 0xF779,
  9562. Ytilde: 0x1EF8,
  9563. Yusbigcyrillic: 0x046A,
  9564. Yusbigiotifiedcyrillic: 0x046C,
  9565. Yuslittlecyrillic: 0x0466,
  9566. Yuslittleiotifiedcyrillic: 0x0468,
  9567. Z: 0x005A,
  9568. Zaarmenian: 0x0536,
  9569. Zacute: 0x0179,
  9570. Zcaron: 0x017D,
  9571. Zcaronsmall: 0xF6FF,
  9572. Zcircle: 0x24CF,
  9573. Zcircumflex: 0x1E90,
  9574. Zdot: 0x017B,
  9575. Zdotaccent: 0x017B,
  9576. Zdotbelow: 0x1E92,
  9577. Zecyrillic: 0x0417,
  9578. Zedescendercyrillic: 0x0498,
  9579. Zedieresiscyrillic: 0x04DE,
  9580. Zeta: 0x0396,
  9581. Zhearmenian: 0x053A,
  9582. Zhebrevecyrillic: 0x04C1,
  9583. Zhecyrillic: 0x0416,
  9584. Zhedescendercyrillic: 0x0496,
  9585. Zhedieresiscyrillic: 0x04DC,
  9586. Zlinebelow: 0x1E94,
  9587. Zmonospace: 0xFF3A,
  9588. Zsmall: 0xF77A,
  9589. Zstroke: 0x01B5,
  9590. a: 0x0061,
  9591. aabengali: 0x0986,
  9592. aacute: 0x00E1,
  9593. aadeva: 0x0906,
  9594. aagujarati: 0x0A86,
  9595. aagurmukhi: 0x0A06,
  9596. aamatragurmukhi: 0x0A3E,
  9597. aarusquare: 0x3303,
  9598. aavowelsignbengali: 0x09BE,
  9599. aavowelsigndeva: 0x093E,
  9600. aavowelsigngujarati: 0x0ABE,
  9601. abbreviationmarkarmenian: 0x055F,
  9602. abbreviationsigndeva: 0x0970,
  9603. abengali: 0x0985,
  9604. abopomofo: 0x311A,
  9605. abreve: 0x0103,
  9606. abreveacute: 0x1EAF,
  9607. abrevecyrillic: 0x04D1,
  9608. abrevedotbelow: 0x1EB7,
  9609. abrevegrave: 0x1EB1,
  9610. abrevehookabove: 0x1EB3,
  9611. abrevetilde: 0x1EB5,
  9612. acaron: 0x01CE,
  9613. acircle: 0x24D0,
  9614. acircumflex: 0x00E2,
  9615. acircumflexacute: 0x1EA5,
  9616. acircumflexdotbelow: 0x1EAD,
  9617. acircumflexgrave: 0x1EA7,
  9618. acircumflexhookabove: 0x1EA9,
  9619. acircumflextilde: 0x1EAB,
  9620. acute: 0x00B4,
  9621. acutebelowcmb: 0x0317,
  9622. acutecmb: 0x0301,
  9623. acutecomb: 0x0301,
  9624. acutedeva: 0x0954,
  9625. acutelowmod: 0x02CF,
  9626. acutetonecmb: 0x0341,
  9627. acyrillic: 0x0430,
  9628. adblgrave: 0x0201,
  9629. addakgurmukhi: 0x0A71,
  9630. adeva: 0x0905,
  9631. adieresis: 0x00E4,
  9632. adieresiscyrillic: 0x04D3,
  9633. adieresismacron: 0x01DF,
  9634. adotbelow: 0x1EA1,
  9635. adotmacron: 0x01E1,
  9636. ae: 0x00E6,
  9637. aeacute: 0x01FD,
  9638. aekorean: 0x3150,
  9639. aemacron: 0x01E3,
  9640. afii00208: 0x2015,
  9641. afii08941: 0x20A4,
  9642. afii10017: 0x0410,
  9643. afii10018: 0x0411,
  9644. afii10019: 0x0412,
  9645. afii10020: 0x0413,
  9646. afii10021: 0x0414,
  9647. afii10022: 0x0415,
  9648. afii10023: 0x0401,
  9649. afii10024: 0x0416,
  9650. afii10025: 0x0417,
  9651. afii10026: 0x0418,
  9652. afii10027: 0x0419,
  9653. afii10028: 0x041A,
  9654. afii10029: 0x041B,
  9655. afii10030: 0x041C,
  9656. afii10031: 0x041D,
  9657. afii10032: 0x041E,
  9658. afii10033: 0x041F,
  9659. afii10034: 0x0420,
  9660. afii10035: 0x0421,
  9661. afii10036: 0x0422,
  9662. afii10037: 0x0423,
  9663. afii10038: 0x0424,
  9664. afii10039: 0x0425,
  9665. afii10040: 0x0426,
  9666. afii10041: 0x0427,
  9667. afii10042: 0x0428,
  9668. afii10043: 0x0429,
  9669. afii10044: 0x042A,
  9670. afii10045: 0x042B,
  9671. afii10046: 0x042C,
  9672. afii10047: 0x042D,
  9673. afii10048: 0x042E,
  9674. afii10049: 0x042F,
  9675. afii10050: 0x0490,
  9676. afii10051: 0x0402,
  9677. afii10052: 0x0403,
  9678. afii10053: 0x0404,
  9679. afii10054: 0x0405,
  9680. afii10055: 0x0406,
  9681. afii10056: 0x0407,
  9682. afii10057: 0x0408,
  9683. afii10058: 0x0409,
  9684. afii10059: 0x040A,
  9685. afii10060: 0x040B,
  9686. afii10061: 0x040C,
  9687. afii10062: 0x040E,
  9688. afii10063: 0xF6C4,
  9689. afii10064: 0xF6C5,
  9690. afii10065: 0x0430,
  9691. afii10066: 0x0431,
  9692. afii10067: 0x0432,
  9693. afii10068: 0x0433,
  9694. afii10069: 0x0434,
  9695. afii10070: 0x0435,
  9696. afii10071: 0x0451,
  9697. afii10072: 0x0436,
  9698. afii10073: 0x0437,
  9699. afii10074: 0x0438,
  9700. afii10075: 0x0439,
  9701. afii10076: 0x043A,
  9702. afii10077: 0x043B,
  9703. afii10078: 0x043C,
  9704. afii10079: 0x043D,
  9705. afii10080: 0x043E,
  9706. afii10081: 0x043F,
  9707. afii10082: 0x0440,
  9708. afii10083: 0x0441,
  9709. afii10084: 0x0442,
  9710. afii10085: 0x0443,
  9711. afii10086: 0x0444,
  9712. afii10087: 0x0445,
  9713. afii10088: 0x0446,
  9714. afii10089: 0x0447,
  9715. afii10090: 0x0448,
  9716. afii10091: 0x0449,
  9717. afii10092: 0x044A,
  9718. afii10093: 0x044B,
  9719. afii10094: 0x044C,
  9720. afii10095: 0x044D,
  9721. afii10096: 0x044E,
  9722. afii10097: 0x044F,
  9723. afii10098: 0x0491,
  9724. afii10099: 0x0452,
  9725. afii10100: 0x0453,
  9726. afii10101: 0x0454,
  9727. afii10102: 0x0455,
  9728. afii10103: 0x0456,
  9729. afii10104: 0x0457,
  9730. afii10105: 0x0458,
  9731. afii10106: 0x0459,
  9732. afii10107: 0x045A,
  9733. afii10108: 0x045B,
  9734. afii10109: 0x045C,
  9735. afii10110: 0x045E,
  9736. afii10145: 0x040F,
  9737. afii10146: 0x0462,
  9738. afii10147: 0x0472,
  9739. afii10148: 0x0474,
  9740. afii10192: 0xF6C6,
  9741. afii10193: 0x045F,
  9742. afii10194: 0x0463,
  9743. afii10195: 0x0473,
  9744. afii10196: 0x0475,
  9745. afii10831: 0xF6C7,
  9746. afii10832: 0xF6C8,
  9747. afii10846: 0x04D9,
  9748. afii299: 0x200E,
  9749. afii300: 0x200F,
  9750. afii301: 0x200D,
  9751. afii57381: 0x066A,
  9752. afii57388: 0x060C,
  9753. afii57392: 0x0660,
  9754. afii57393: 0x0661,
  9755. afii57394: 0x0662,
  9756. afii57395: 0x0663,
  9757. afii57396: 0x0664,
  9758. afii57397: 0x0665,
  9759. afii57398: 0x0666,
  9760. afii57399: 0x0667,
  9761. afii57400: 0x0668,
  9762. afii57401: 0x0669,
  9763. afii57403: 0x061B,
  9764. afii57407: 0x061F,
  9765. afii57409: 0x0621,
  9766. afii57410: 0x0622,
  9767. afii57411: 0x0623,
  9768. afii57412: 0x0624,
  9769. afii57413: 0x0625,
  9770. afii57414: 0x0626,
  9771. afii57415: 0x0627,
  9772. afii57416: 0x0628,
  9773. afii57417: 0x0629,
  9774. afii57418: 0x062A,
  9775. afii57419: 0x062B,
  9776. afii57420: 0x062C,
  9777. afii57421: 0x062D,
  9778. afii57422: 0x062E,
  9779. afii57423: 0x062F,
  9780. afii57424: 0x0630,
  9781. afii57425: 0x0631,
  9782. afii57426: 0x0632,
  9783. afii57427: 0x0633,
  9784. afii57428: 0x0634,
  9785. afii57429: 0x0635,
  9786. afii57430: 0x0636,
  9787. afii57431: 0x0637,
  9788. afii57432: 0x0638,
  9789. afii57433: 0x0639,
  9790. afii57434: 0x063A,
  9791. afii57440: 0x0640,
  9792. afii57441: 0x0641,
  9793. afii57442: 0x0642,
  9794. afii57443: 0x0643,
  9795. afii57444: 0x0644,
  9796. afii57445: 0x0645,
  9797. afii57446: 0x0646,
  9798. afii57448: 0x0648,
  9799. afii57449: 0x0649,
  9800. afii57450: 0x064A,
  9801. afii57451: 0x064B,
  9802. afii57452: 0x064C,
  9803. afii57453: 0x064D,
  9804. afii57454: 0x064E,
  9805. afii57455: 0x064F,
  9806. afii57456: 0x0650,
  9807. afii57457: 0x0651,
  9808. afii57458: 0x0652,
  9809. afii57470: 0x0647,
  9810. afii57505: 0x06A4,
  9811. afii57506: 0x067E,
  9812. afii57507: 0x0686,
  9813. afii57508: 0x0698,
  9814. afii57509: 0x06AF,
  9815. afii57511: 0x0679,
  9816. afii57512: 0x0688,
  9817. afii57513: 0x0691,
  9818. afii57514: 0x06BA,
  9819. afii57519: 0x06D2,
  9820. afii57534: 0x06D5,
  9821. afii57636: 0x20AA,
  9822. afii57645: 0x05BE,
  9823. afii57658: 0x05C3,
  9824. afii57664: 0x05D0,
  9825. afii57665: 0x05D1,
  9826. afii57666: 0x05D2,
  9827. afii57667: 0x05D3,
  9828. afii57668: 0x05D4,
  9829. afii57669: 0x05D5,
  9830. afii57670: 0x05D6,
  9831. afii57671: 0x05D7,
  9832. afii57672: 0x05D8,
  9833. afii57673: 0x05D9,
  9834. afii57674: 0x05DA,
  9835. afii57675: 0x05DB,
  9836. afii57676: 0x05DC,
  9837. afii57677: 0x05DD,
  9838. afii57678: 0x05DE,
  9839. afii57679: 0x05DF,
  9840. afii57680: 0x05E0,
  9841. afii57681: 0x05E1,
  9842. afii57682: 0x05E2,
  9843. afii57683: 0x05E3,
  9844. afii57684: 0x05E4,
  9845. afii57685: 0x05E5,
  9846. afii57686: 0x05E6,
  9847. afii57687: 0x05E7,
  9848. afii57688: 0x05E8,
  9849. afii57689: 0x05E9,
  9850. afii57690: 0x05EA,
  9851. afii57694: 0xFB2A,
  9852. afii57695: 0xFB2B,
  9853. afii57700: 0xFB4B,
  9854. afii57705: 0xFB1F,
  9855. afii57716: 0x05F0,
  9856. afii57717: 0x05F1,
  9857. afii57718: 0x05F2,
  9858. afii57723: 0xFB35,
  9859. afii57793: 0x05B4,
  9860. afii57794: 0x05B5,
  9861. afii57795: 0x05B6,
  9862. afii57796: 0x05BB,
  9863. afii57797: 0x05B8,
  9864. afii57798: 0x05B7,
  9865. afii57799: 0x05B0,
  9866. afii57800: 0x05B2,
  9867. afii57801: 0x05B1,
  9868. afii57802: 0x05B3,
  9869. afii57803: 0x05C2,
  9870. afii57804: 0x05C1,
  9871. afii57806: 0x05B9,
  9872. afii57807: 0x05BC,
  9873. afii57839: 0x05BD,
  9874. afii57841: 0x05BF,
  9875. afii57842: 0x05C0,
  9876. afii57929: 0x02BC,
  9877. afii61248: 0x2105,
  9878. afii61289: 0x2113,
  9879. afii61352: 0x2116,
  9880. afii61573: 0x202C,
  9881. afii61574: 0x202D,
  9882. afii61575: 0x202E,
  9883. afii61664: 0x200C,
  9884. afii63167: 0x066D,
  9885. afii64937: 0x02BD,
  9886. agrave: 0x00E0,
  9887. agujarati: 0x0A85,
  9888. agurmukhi: 0x0A05,
  9889. ahiragana: 0x3042,
  9890. ahookabove: 0x1EA3,
  9891. aibengali: 0x0990,
  9892. aibopomofo: 0x311E,
  9893. aideva: 0x0910,
  9894. aiecyrillic: 0x04D5,
  9895. aigujarati: 0x0A90,
  9896. aigurmukhi: 0x0A10,
  9897. aimatragurmukhi: 0x0A48,
  9898. ainarabic: 0x0639,
  9899. ainfinalarabic: 0xFECA,
  9900. aininitialarabic: 0xFECB,
  9901. ainmedialarabic: 0xFECC,
  9902. ainvertedbreve: 0x0203,
  9903. aivowelsignbengali: 0x09C8,
  9904. aivowelsigndeva: 0x0948,
  9905. aivowelsigngujarati: 0x0AC8,
  9906. akatakana: 0x30A2,
  9907. akatakanahalfwidth: 0xFF71,
  9908. akorean: 0x314F,
  9909. alef: 0x05D0,
  9910. alefarabic: 0x0627,
  9911. alefdageshhebrew: 0xFB30,
  9912. aleffinalarabic: 0xFE8E,
  9913. alefhamzaabovearabic: 0x0623,
  9914. alefhamzaabovefinalarabic: 0xFE84,
  9915. alefhamzabelowarabic: 0x0625,
  9916. alefhamzabelowfinalarabic: 0xFE88,
  9917. alefhebrew: 0x05D0,
  9918. aleflamedhebrew: 0xFB4F,
  9919. alefmaddaabovearabic: 0x0622,
  9920. alefmaddaabovefinalarabic: 0xFE82,
  9921. alefmaksuraarabic: 0x0649,
  9922. alefmaksurafinalarabic: 0xFEF0,
  9923. alefmaksurainitialarabic: 0xFEF3,
  9924. alefmaksuramedialarabic: 0xFEF4,
  9925. alefpatahhebrew: 0xFB2E,
  9926. alefqamatshebrew: 0xFB2F,
  9927. aleph: 0x2135,
  9928. allequal: 0x224C,
  9929. alpha: 0x03B1,
  9930. alphatonos: 0x03AC,
  9931. amacron: 0x0101,
  9932. amonospace: 0xFF41,
  9933. ampersand: 0x0026,
  9934. ampersandmonospace: 0xFF06,
  9935. ampersandsmall: 0xF726,
  9936. amsquare: 0x33C2,
  9937. anbopomofo: 0x3122,
  9938. angbopomofo: 0x3124,
  9939. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  9940. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  9941. angkhankhuthai: 0x0E5A,
  9942. angle: 0x2220,
  9943. anglebracketleft: 0x3008,
  9944. anglebracketleftvertical: 0xFE3F,
  9945. anglebracketright: 0x3009,
  9946. anglebracketrightvertical: 0xFE40,
  9947. angleleft: 0x2329,
  9948. angleright: 0x232A,
  9949. angstrom: 0x212B,
  9950. anoteleia: 0x0387,
  9951. anudattadeva: 0x0952,
  9952. anusvarabengali: 0x0982,
  9953. anusvaradeva: 0x0902,
  9954. anusvaragujarati: 0x0A82,
  9955. aogonek: 0x0105,
  9956. apaatosquare: 0x3300,
  9957. aparen: 0x249C,
  9958. apostrophearmenian: 0x055A,
  9959. apostrophemod: 0x02BC,
  9960. apple: 0xF8FF,
  9961. approaches: 0x2250,
  9962. approxequal: 0x2248,
  9963. approxequalorimage: 0x2252,
  9964. approximatelyequal: 0x2245,
  9965. araeaekorean: 0x318E,
  9966. araeakorean: 0x318D,
  9967. arc: 0x2312,
  9968. arighthalfring: 0x1E9A,
  9969. aring: 0x00E5,
  9970. aringacute: 0x01FB,
  9971. aringbelow: 0x1E01,
  9972. arrowboth: 0x2194,
  9973. arrowdashdown: 0x21E3,
  9974. arrowdashleft: 0x21E0,
  9975. arrowdashright: 0x21E2,
  9976. arrowdashup: 0x21E1,
  9977. arrowdblboth: 0x21D4,
  9978. arrowdbldown: 0x21D3,
  9979. arrowdblleft: 0x21D0,
  9980. arrowdblright: 0x21D2,
  9981. arrowdblup: 0x21D1,
  9982. arrowdown: 0x2193,
  9983. arrowdownleft: 0x2199,
  9984. arrowdownright: 0x2198,
  9985. arrowdownwhite: 0x21E9,
  9986. arrowheaddownmod: 0x02C5,
  9987. arrowheadleftmod: 0x02C2,
  9988. arrowheadrightmod: 0x02C3,
  9989. arrowheadupmod: 0x02C4,
  9990. arrowhorizex: 0xF8E7,
  9991. arrowleft: 0x2190,
  9992. arrowleftdbl: 0x21D0,
  9993. arrowleftdblstroke: 0x21CD,
  9994. arrowleftoverright: 0x21C6,
  9995. arrowleftwhite: 0x21E6,
  9996. arrowright: 0x2192,
  9997. arrowrightdblstroke: 0x21CF,
  9998. arrowrightheavy: 0x279E,
  9999. arrowrightoverleft: 0x21C4,
  10000. arrowrightwhite: 0x21E8,
  10001. arrowtableft: 0x21E4,
  10002. arrowtabright: 0x21E5,
  10003. arrowup: 0x2191,
  10004. arrowupdn: 0x2195,
  10005. arrowupdnbse: 0x21A8,
  10006. arrowupdownbase: 0x21A8,
  10007. arrowupleft: 0x2196,
  10008. arrowupleftofdown: 0x21C5,
  10009. arrowupright: 0x2197,
  10010. arrowupwhite: 0x21E7,
  10011. arrowvertex: 0xF8E6,
  10012. asciicircum: 0x005E,
  10013. asciicircummonospace: 0xFF3E,
  10014. asciitilde: 0x007E,
  10015. asciitildemonospace: 0xFF5E,
  10016. ascript: 0x0251,
  10017. ascriptturned: 0x0252,
  10018. asmallhiragana: 0x3041,
  10019. asmallkatakana: 0x30A1,
  10020. asmallkatakanahalfwidth: 0xFF67,
  10021. asterisk: 0x002A,
  10022. asteriskaltonearabic: 0x066D,
  10023. asteriskarabic: 0x066D,
  10024. asteriskmath: 0x2217,
  10025. asteriskmonospace: 0xFF0A,
  10026. asterisksmall: 0xFE61,
  10027. asterism: 0x2042,
  10028. asuperior: 0xF6E9,
  10029. asymptoticallyequal: 0x2243,
  10030. at: 0x0040,
  10031. atilde: 0x00E3,
  10032. atmonospace: 0xFF20,
  10033. atsmall: 0xFE6B,
  10034. aturned: 0x0250,
  10035. aubengali: 0x0994,
  10036. aubopomofo: 0x3120,
  10037. audeva: 0x0914,
  10038. augujarati: 0x0A94,
  10039. augurmukhi: 0x0A14,
  10040. aulengthmarkbengali: 0x09D7,
  10041. aumatragurmukhi: 0x0A4C,
  10042. auvowelsignbengali: 0x09CC,
  10043. auvowelsigndeva: 0x094C,
  10044. auvowelsigngujarati: 0x0ACC,
  10045. avagrahadeva: 0x093D,
  10046. aybarmenian: 0x0561,
  10047. ayin: 0x05E2,
  10048. ayinaltonehebrew: 0xFB20,
  10049. ayinhebrew: 0x05E2,
  10050. b: 0x0062,
  10051. babengali: 0x09AC,
  10052. backslash: 0x005C,
  10053. backslashmonospace: 0xFF3C,
  10054. badeva: 0x092C,
  10055. bagujarati: 0x0AAC,
  10056. bagurmukhi: 0x0A2C,
  10057. bahiragana: 0x3070,
  10058. bahtthai: 0x0E3F,
  10059. bakatakana: 0x30D0,
  10060. bar: 0x007C,
  10061. barmonospace: 0xFF5C,
  10062. bbopomofo: 0x3105,
  10063. bcircle: 0x24D1,
  10064. bdotaccent: 0x1E03,
  10065. bdotbelow: 0x1E05,
  10066. beamedsixteenthnotes: 0x266C,
  10067. because: 0x2235,
  10068. becyrillic: 0x0431,
  10069. beharabic: 0x0628,
  10070. behfinalarabic: 0xFE90,
  10071. behinitialarabic: 0xFE91,
  10072. behiragana: 0x3079,
  10073. behmedialarabic: 0xFE92,
  10074. behmeeminitialarabic: 0xFC9F,
  10075. behmeemisolatedarabic: 0xFC08,
  10076. behnoonfinalarabic: 0xFC6D,
  10077. bekatakana: 0x30D9,
  10078. benarmenian: 0x0562,
  10079. bet: 0x05D1,
  10080. beta: 0x03B2,
  10081. betasymbolgreek: 0x03D0,
  10082. betdagesh: 0xFB31,
  10083. betdageshhebrew: 0xFB31,
  10084. bethebrew: 0x05D1,
  10085. betrafehebrew: 0xFB4C,
  10086. bhabengali: 0x09AD,
  10087. bhadeva: 0x092D,
  10088. bhagujarati: 0x0AAD,
  10089. bhagurmukhi: 0x0A2D,
  10090. bhook: 0x0253,
  10091. bihiragana: 0x3073,
  10092. bikatakana: 0x30D3,
  10093. bilabialclick: 0x0298,
  10094. bindigurmukhi: 0x0A02,
  10095. birusquare: 0x3331,
  10096. blackcircle: 0x25CF,
  10097. blackdiamond: 0x25C6,
  10098. blackdownpointingtriangle: 0x25BC,
  10099. blackleftpointingpointer: 0x25C4,
  10100. blackleftpointingtriangle: 0x25C0,
  10101. blacklenticularbracketleft: 0x3010,
  10102. blacklenticularbracketleftvertical: 0xFE3B,
  10103. blacklenticularbracketright: 0x3011,
  10104. blacklenticularbracketrightvertical: 0xFE3C,
  10105. blacklowerlefttriangle: 0x25E3,
  10106. blacklowerrighttriangle: 0x25E2,
  10107. blackrectangle: 0x25AC,
  10108. blackrightpointingpointer: 0x25BA,
  10109. blackrightpointingtriangle: 0x25B6,
  10110. blacksmallsquare: 0x25AA,
  10111. blacksmilingface: 0x263B,
  10112. blacksquare: 0x25A0,
  10113. blackstar: 0x2605,
  10114. blackupperlefttriangle: 0x25E4,
  10115. blackupperrighttriangle: 0x25E5,
  10116. blackuppointingsmalltriangle: 0x25B4,
  10117. blackuppointingtriangle: 0x25B2,
  10118. blank: 0x2423,
  10119. blinebelow: 0x1E07,
  10120. block: 0x2588,
  10121. bmonospace: 0xFF42,
  10122. bobaimaithai: 0x0E1A,
  10123. bohiragana: 0x307C,
  10124. bokatakana: 0x30DC,
  10125. bparen: 0x249D,
  10126. bqsquare: 0x33C3,
  10127. braceex: 0xF8F4,
  10128. braceleft: 0x007B,
  10129. braceleftbt: 0xF8F3,
  10130. braceleftmid: 0xF8F2,
  10131. braceleftmonospace: 0xFF5B,
  10132. braceleftsmall: 0xFE5B,
  10133. bracelefttp: 0xF8F1,
  10134. braceleftvertical: 0xFE37,
  10135. braceright: 0x007D,
  10136. bracerightbt: 0xF8FE,
  10137. bracerightmid: 0xF8FD,
  10138. bracerightmonospace: 0xFF5D,
  10139. bracerightsmall: 0xFE5C,
  10140. bracerighttp: 0xF8FC,
  10141. bracerightvertical: 0xFE38,
  10142. bracketleft: 0x005B,
  10143. bracketleftbt: 0xF8F0,
  10144. bracketleftex: 0xF8EF,
  10145. bracketleftmonospace: 0xFF3B,
  10146. bracketlefttp: 0xF8EE,
  10147. bracketright: 0x005D,
  10148. bracketrightbt: 0xF8FB,
  10149. bracketrightex: 0xF8FA,
  10150. bracketrightmonospace: 0xFF3D,
  10151. bracketrighttp: 0xF8F9,
  10152. breve: 0x02D8,
  10153. brevebelowcmb: 0x032E,
  10154. brevecmb: 0x0306,
  10155. breveinvertedbelowcmb: 0x032F,
  10156. breveinvertedcmb: 0x0311,
  10157. breveinverteddoublecmb: 0x0361,
  10158. bridgebelowcmb: 0x032A,
  10159. bridgeinvertedbelowcmb: 0x033A,
  10160. brokenbar: 0x00A6,
  10161. bstroke: 0x0180,
  10162. bsuperior: 0xF6EA,
  10163. btopbar: 0x0183,
  10164. buhiragana: 0x3076,
  10165. bukatakana: 0x30D6,
  10166. bullet: 0x2022,
  10167. bulletinverse: 0x25D8,
  10168. bulletoperator: 0x2219,
  10169. bullseye: 0x25CE,
  10170. c: 0x0063,
  10171. caarmenian: 0x056E,
  10172. cabengali: 0x099A,
  10173. cacute: 0x0107,
  10174. cadeva: 0x091A,
  10175. cagujarati: 0x0A9A,
  10176. cagurmukhi: 0x0A1A,
  10177. calsquare: 0x3388,
  10178. candrabindubengali: 0x0981,
  10179. candrabinducmb: 0x0310,
  10180. candrabindudeva: 0x0901,
  10181. candrabindugujarati: 0x0A81,
  10182. capslock: 0x21EA,
  10183. careof: 0x2105,
  10184. caron: 0x02C7,
  10185. caronbelowcmb: 0x032C,
  10186. caroncmb: 0x030C,
  10187. carriagereturn: 0x21B5,
  10188. cbopomofo: 0x3118,
  10189. ccaron: 0x010D,
  10190. ccedilla: 0x00E7,
  10191. ccedillaacute: 0x1E09,
  10192. ccircle: 0x24D2,
  10193. ccircumflex: 0x0109,
  10194. ccurl: 0x0255,
  10195. cdot: 0x010B,
  10196. cdotaccent: 0x010B,
  10197. cdsquare: 0x33C5,
  10198. cedilla: 0x00B8,
  10199. cedillacmb: 0x0327,
  10200. cent: 0x00A2,
  10201. centigrade: 0x2103,
  10202. centinferior: 0xF6DF,
  10203. centmonospace: 0xFFE0,
  10204. centoldstyle: 0xF7A2,
  10205. centsuperior: 0xF6E0,
  10206. chaarmenian: 0x0579,
  10207. chabengali: 0x099B,
  10208. chadeva: 0x091B,
  10209. chagujarati: 0x0A9B,
  10210. chagurmukhi: 0x0A1B,
  10211. chbopomofo: 0x3114,
  10212. cheabkhasiancyrillic: 0x04BD,
  10213. checkmark: 0x2713,
  10214. checyrillic: 0x0447,
  10215. chedescenderabkhasiancyrillic: 0x04BF,
  10216. chedescendercyrillic: 0x04B7,
  10217. chedieresiscyrillic: 0x04F5,
  10218. cheharmenian: 0x0573,
  10219. chekhakassiancyrillic: 0x04CC,
  10220. cheverticalstrokecyrillic: 0x04B9,
  10221. chi: 0x03C7,
  10222. chieuchacirclekorean: 0x3277,
  10223. chieuchaparenkorean: 0x3217,
  10224. chieuchcirclekorean: 0x3269,
  10225. chieuchkorean: 0x314A,
  10226. chieuchparenkorean: 0x3209,
  10227. chochangthai: 0x0E0A,
  10228. chochanthai: 0x0E08,
  10229. chochingthai: 0x0E09,
  10230. chochoethai: 0x0E0C,
  10231. chook: 0x0188,
  10232. cieucacirclekorean: 0x3276,
  10233. cieucaparenkorean: 0x3216,
  10234. cieuccirclekorean: 0x3268,
  10235. cieuckorean: 0x3148,
  10236. cieucparenkorean: 0x3208,
  10237. cieucuparenkorean: 0x321C,
  10238. circle: 0x25CB,
  10239. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  10240. circlemultiply: 0x2297,
  10241. circleot: 0x2299,
  10242. circleplus: 0x2295,
  10243. circlepostalmark: 0x3036,
  10244. circlewithlefthalfblack: 0x25D0,
  10245. circlewithrighthalfblack: 0x25D1,
  10246. circumflex: 0x02C6,
  10247. circumflexbelowcmb: 0x032D,
  10248. circumflexcmb: 0x0302,
  10249. clear: 0x2327,
  10250. clickalveolar: 0x01C2,
  10251. clickdental: 0x01C0,
  10252. clicklateral: 0x01C1,
  10253. clickretroflex: 0x01C3,
  10254. club: 0x2663,
  10255. clubsuitblack: 0x2663,
  10256. clubsuitwhite: 0x2667,
  10257. cmcubedsquare: 0x33A4,
  10258. cmonospace: 0xFF43,
  10259. cmsquaredsquare: 0x33A0,
  10260. coarmenian: 0x0581,
  10261. colon: 0x003A,
  10262. colonmonetary: 0x20A1,
  10263. colonmonospace: 0xFF1A,
  10264. colonsign: 0x20A1,
  10265. colonsmall: 0xFE55,
  10266. colontriangularhalfmod: 0x02D1,
  10267. colontriangularmod: 0x02D0,
  10268. comma: 0x002C,
  10269. commaabovecmb: 0x0313,
  10270. commaaboverightcmb: 0x0315,
  10271. commaaccent: 0xF6C3,
  10272. commaarabic: 0x060C,
  10273. commaarmenian: 0x055D,
  10274. commainferior: 0xF6E1,
  10275. commamonospace: 0xFF0C,
  10276. commareversedabovecmb: 0x0314,
  10277. commareversedmod: 0x02BD,
  10278. commasmall: 0xFE50,
  10279. commasuperior: 0xF6E2,
  10280. commaturnedabovecmb: 0x0312,
  10281. commaturnedmod: 0x02BB,
  10282. compass: 0x263C,
  10283. congruent: 0x2245,
  10284. contourintegral: 0x222E,
  10285. control: 0x2303,
  10286. controlACK: 0x0006,
  10287. controlBEL: 0x0007,
  10288. controlBS: 0x0008,
  10289. controlCAN: 0x0018,
  10290. controlCR: 0x000D,
  10291. controlDC1: 0x0011,
  10292. controlDC2: 0x0012,
  10293. controlDC3: 0x0013,
  10294. controlDC4: 0x0014,
  10295. controlDEL: 0x007F,
  10296. controlDLE: 0x0010,
  10297. controlEM: 0x0019,
  10298. controlENQ: 0x0005,
  10299. controlEOT: 0x0004,
  10300. controlESC: 0x001B,
  10301. controlETB: 0x0017,
  10302. controlETX: 0x0003,
  10303. controlFF: 0x000C,
  10304. controlFS: 0x001C,
  10305. controlGS: 0x001D,
  10306. controlHT: 0x0009,
  10307. controlLF: 0x000A,
  10308. controlNAK: 0x0015,
  10309. controlRS: 0x001E,
  10310. controlSI: 0x000F,
  10311. controlSO: 0x000E,
  10312. controlSOT: 0x0002,
  10313. controlSTX: 0x0001,
  10314. controlSUB: 0x001A,
  10315. controlSYN: 0x0016,
  10316. controlUS: 0x001F,
  10317. controlVT: 0x000B,
  10318. copyright: 0x00A9,
  10319. copyrightsans: 0xF8E9,
  10320. copyrightserif: 0xF6D9,
  10321. cornerbracketleft: 0x300C,
  10322. cornerbracketlefthalfwidth: 0xFF62,
  10323. cornerbracketleftvertical: 0xFE41,
  10324. cornerbracketright: 0x300D,
  10325. cornerbracketrighthalfwidth: 0xFF63,
  10326. cornerbracketrightvertical: 0xFE42,
  10327. corporationsquare: 0x337F,
  10328. cosquare: 0x33C7,
  10329. coverkgsquare: 0x33C6,
  10330. cparen: 0x249E,
  10331. cruzeiro: 0x20A2,
  10332. cstretched: 0x0297,
  10333. curlyand: 0x22CF,
  10334. curlyor: 0x22CE,
  10335. currency: 0x00A4,
  10336. cyrBreve: 0xF6D1,
  10337. cyrFlex: 0xF6D2,
  10338. cyrbreve: 0xF6D4,
  10339. cyrflex: 0xF6D5,
  10340. d: 0x0064,
  10341. daarmenian: 0x0564,
  10342. dabengali: 0x09A6,
  10343. dadarabic: 0x0636,
  10344. dadeva: 0x0926,
  10345. dadfinalarabic: 0xFEBE,
  10346. dadinitialarabic: 0xFEBF,
  10347. dadmedialarabic: 0xFEC0,
  10348. dagesh: 0x05BC,
  10349. dageshhebrew: 0x05BC,
  10350. dagger: 0x2020,
  10351. daggerdbl: 0x2021,
  10352. dagujarati: 0x0AA6,
  10353. dagurmukhi: 0x0A26,
  10354. dahiragana: 0x3060,
  10355. dakatakana: 0x30C0,
  10356. dalarabic: 0x062F,
  10357. dalet: 0x05D3,
  10358. daletdagesh: 0xFB33,
  10359. daletdageshhebrew: 0xFB33,
  10360. dalethebrew: 0x05D3,
  10361. dalfinalarabic: 0xFEAA,
  10362. dammaarabic: 0x064F,
  10363. dammalowarabic: 0x064F,
  10364. dammatanaltonearabic: 0x064C,
  10365. dammatanarabic: 0x064C,
  10366. danda: 0x0964,
  10367. dargahebrew: 0x05A7,
  10368. dargalefthebrew: 0x05A7,
  10369. dasiapneumatacyrilliccmb: 0x0485,
  10370. dblGrave: 0xF6D3,
  10371. dblanglebracketleft: 0x300A,
  10372. dblanglebracketleftvertical: 0xFE3D,
  10373. dblanglebracketright: 0x300B,
  10374. dblanglebracketrightvertical: 0xFE3E,
  10375. dblarchinvertedbelowcmb: 0x032B,
  10376. dblarrowleft: 0x21D4,
  10377. dblarrowright: 0x21D2,
  10378. dbldanda: 0x0965,
  10379. dblgrave: 0xF6D6,
  10380. dblgravecmb: 0x030F,
  10381. dblintegral: 0x222C,
  10382. dbllowline: 0x2017,
  10383. dbllowlinecmb: 0x0333,
  10384. dbloverlinecmb: 0x033F,
  10385. dblprimemod: 0x02BA,
  10386. dblverticalbar: 0x2016,
  10387. dblverticallineabovecmb: 0x030E,
  10388. dbopomofo: 0x3109,
  10389. dbsquare: 0x33C8,
  10390. dcaron: 0x010F,
  10391. dcedilla: 0x1E11,
  10392. dcircle: 0x24D3,
  10393. dcircumflexbelow: 0x1E13,
  10394. dcroat: 0x0111,
  10395. ddabengali: 0x09A1,
  10396. ddadeva: 0x0921,
  10397. ddagujarati: 0x0AA1,
  10398. ddagurmukhi: 0x0A21,
  10399. ddalarabic: 0x0688,
  10400. ddalfinalarabic: 0xFB89,
  10401. dddhadeva: 0x095C,
  10402. ddhabengali: 0x09A2,
  10403. ddhadeva: 0x0922,
  10404. ddhagujarati: 0x0AA2,
  10405. ddhagurmukhi: 0x0A22,
  10406. ddotaccent: 0x1E0B,
  10407. ddotbelow: 0x1E0D,
  10408. decimalseparatorarabic: 0x066B,
  10409. decimalseparatorpersian: 0x066B,
  10410. decyrillic: 0x0434,
  10411. degree: 0x00B0,
  10412. dehihebrew: 0x05AD,
  10413. dehiragana: 0x3067,
  10414. deicoptic: 0x03EF,
  10415. dekatakana: 0x30C7,
  10416. deleteleft: 0x232B,
  10417. deleteright: 0x2326,
  10418. delta: 0x03B4,
  10419. deltaturned: 0x018D,
  10420. denominatorminusonenumeratorbengali: 0x09F8,
  10421. dezh: 0x02A4,
  10422. dhabengali: 0x09A7,
  10423. dhadeva: 0x0927,
  10424. dhagujarati: 0x0AA7,
  10425. dhagurmukhi: 0x0A27,
  10426. dhook: 0x0257,
  10427. dialytikatonos: 0x0385,
  10428. dialytikatonoscmb: 0x0344,
  10429. diamond: 0x2666,
  10430. diamondsuitwhite: 0x2662,
  10431. dieresis: 0x00A8,
  10432. dieresisacute: 0xF6D7,
  10433. dieresisbelowcmb: 0x0324,
  10434. dieresiscmb: 0x0308,
  10435. dieresisgrave: 0xF6D8,
  10436. dieresistonos: 0x0385,
  10437. dihiragana: 0x3062,
  10438. dikatakana: 0x30C2,
  10439. dittomark: 0x3003,
  10440. divide: 0x00F7,
  10441. divides: 0x2223,
  10442. divisionslash: 0x2215,
  10443. djecyrillic: 0x0452,
  10444. dkshade: 0x2593,
  10445. dlinebelow: 0x1E0F,
  10446. dlsquare: 0x3397,
  10447. dmacron: 0x0111,
  10448. dmonospace: 0xFF44,
  10449. dnblock: 0x2584,
  10450. dochadathai: 0x0E0E,
  10451. dodekthai: 0x0E14,
  10452. dohiragana: 0x3069,
  10453. dokatakana: 0x30C9,
  10454. dollar: 0x0024,
  10455. dollarinferior: 0xF6E3,
  10456. dollarmonospace: 0xFF04,
  10457. dollaroldstyle: 0xF724,
  10458. dollarsmall: 0xFE69,
  10459. dollarsuperior: 0xF6E4,
  10460. dong: 0x20AB,
  10461. dorusquare: 0x3326,
  10462. dotaccent: 0x02D9,
  10463. dotaccentcmb: 0x0307,
  10464. dotbelowcmb: 0x0323,
  10465. dotbelowcomb: 0x0323,
  10466. dotkatakana: 0x30FB,
  10467. dotlessi: 0x0131,
  10468. dotlessj: 0xF6BE,
  10469. dotlessjstrokehook: 0x0284,
  10470. dotmath: 0x22C5,
  10471. dottedcircle: 0x25CC,
  10472. doubleyodpatah: 0xFB1F,
  10473. doubleyodpatahhebrew: 0xFB1F,
  10474. downtackbelowcmb: 0x031E,
  10475. downtackmod: 0x02D5,
  10476. dparen: 0x249F,
  10477. dsuperior: 0xF6EB,
  10478. dtail: 0x0256,
  10479. dtopbar: 0x018C,
  10480. duhiragana: 0x3065,
  10481. dukatakana: 0x30C5,
  10482. dz: 0x01F3,
  10483. dzaltone: 0x02A3,
  10484. dzcaron: 0x01C6,
  10485. dzcurl: 0x02A5,
  10486. dzeabkhasiancyrillic: 0x04E1,
  10487. dzecyrillic: 0x0455,
  10488. dzhecyrillic: 0x045F,
  10489. e: 0x0065,
  10490. eacute: 0x00E9,
  10491. earth: 0x2641,
  10492. ebengali: 0x098F,
  10493. ebopomofo: 0x311C,
  10494. ebreve: 0x0115,
  10495. ecandradeva: 0x090D,
  10496. ecandragujarati: 0x0A8D,
  10497. ecandravowelsigndeva: 0x0945,
  10498. ecandravowelsigngujarati: 0x0AC5,
  10499. ecaron: 0x011B,
  10500. ecedillabreve: 0x1E1D,
  10501. echarmenian: 0x0565,
  10502. echyiwnarmenian: 0x0587,
  10503. ecircle: 0x24D4,
  10504. ecircumflex: 0x00EA,
  10505. ecircumflexacute: 0x1EBF,
  10506. ecircumflexbelow: 0x1E19,
  10507. ecircumflexdotbelow: 0x1EC7,
  10508. ecircumflexgrave: 0x1EC1,
  10509. ecircumflexhookabove: 0x1EC3,
  10510. ecircumflextilde: 0x1EC5,
  10511. ecyrillic: 0x0454,
  10512. edblgrave: 0x0205,
  10513. edeva: 0x090F,
  10514. edieresis: 0x00EB,
  10515. edot: 0x0117,
  10516. edotaccent: 0x0117,
  10517. edotbelow: 0x1EB9,
  10518. eegurmukhi: 0x0A0F,
  10519. eematragurmukhi: 0x0A47,
  10520. efcyrillic: 0x0444,
  10521. egrave: 0x00E8,
  10522. egujarati: 0x0A8F,
  10523. eharmenian: 0x0567,
  10524. ehbopomofo: 0x311D,
  10525. ehiragana: 0x3048,
  10526. ehookabove: 0x1EBB,
  10527. eibopomofo: 0x311F,
  10528. eight: 0x0038,
  10529. eightarabic: 0x0668,
  10530. eightbengali: 0x09EE,
  10531. eightcircle: 0x2467,
  10532. eightcircleinversesansserif: 0x2791,
  10533. eightdeva: 0x096E,
  10534. eighteencircle: 0x2471,
  10535. eighteenparen: 0x2485,
  10536. eighteenperiod: 0x2499,
  10537. eightgujarati: 0x0AEE,
  10538. eightgurmukhi: 0x0A6E,
  10539. eighthackarabic: 0x0668,
  10540. eighthangzhou: 0x3028,
  10541. eighthnotebeamed: 0x266B,
  10542. eightideographicparen: 0x3227,
  10543. eightinferior: 0x2088,
  10544. eightmonospace: 0xFF18,
  10545. eightoldstyle: 0xF738,
  10546. eightparen: 0x247B,
  10547. eightperiod: 0x248F,
  10548. eightpersian: 0x06F8,
  10549. eightroman: 0x2177,
  10550. eightsuperior: 0x2078,
  10551. eightthai: 0x0E58,
  10552. einvertedbreve: 0x0207,
  10553. eiotifiedcyrillic: 0x0465,
  10554. ekatakana: 0x30A8,
  10555. ekatakanahalfwidth: 0xFF74,
  10556. ekonkargurmukhi: 0x0A74,
  10557. ekorean: 0x3154,
  10558. elcyrillic: 0x043B,
  10559. element: 0x2208,
  10560. elevencircle: 0x246A,
  10561. elevenparen: 0x247E,
  10562. elevenperiod: 0x2492,
  10563. elevenroman: 0x217A,
  10564. ellipsis: 0x2026,
  10565. ellipsisvertical: 0x22EE,
  10566. emacron: 0x0113,
  10567. emacronacute: 0x1E17,
  10568. emacrongrave: 0x1E15,
  10569. emcyrillic: 0x043C,
  10570. emdash: 0x2014,
  10571. emdashvertical: 0xFE31,
  10572. emonospace: 0xFF45,
  10573. emphasismarkarmenian: 0x055B,
  10574. emptyset: 0x2205,
  10575. enbopomofo: 0x3123,
  10576. encyrillic: 0x043D,
  10577. endash: 0x2013,
  10578. endashvertical: 0xFE32,
  10579. endescendercyrillic: 0x04A3,
  10580. eng: 0x014B,
  10581. engbopomofo: 0x3125,
  10582. enghecyrillic: 0x04A5,
  10583. enhookcyrillic: 0x04C8,
  10584. enspace: 0x2002,
  10585. eogonek: 0x0119,
  10586. eokorean: 0x3153,
  10587. eopen: 0x025B,
  10588. eopenclosed: 0x029A,
  10589. eopenreversed: 0x025C,
  10590. eopenreversedclosed: 0x025E,
  10591. eopenreversedhook: 0x025D,
  10592. eparen: 0x24A0,
  10593. epsilon: 0x03B5,
  10594. epsilontonos: 0x03AD,
  10595. equal: 0x003D,
  10596. equalmonospace: 0xFF1D,
  10597. equalsmall: 0xFE66,
  10598. equalsuperior: 0x207C,
  10599. equivalence: 0x2261,
  10600. erbopomofo: 0x3126,
  10601. ercyrillic: 0x0440,
  10602. ereversed: 0x0258,
  10603. ereversedcyrillic: 0x044D,
  10604. escyrillic: 0x0441,
  10605. esdescendercyrillic: 0x04AB,
  10606. esh: 0x0283,
  10607. eshcurl: 0x0286,
  10608. eshortdeva: 0x090E,
  10609. eshortvowelsigndeva: 0x0946,
  10610. eshreversedloop: 0x01AA,
  10611. eshsquatreversed: 0x0285,
  10612. esmallhiragana: 0x3047,
  10613. esmallkatakana: 0x30A7,
  10614. esmallkatakanahalfwidth: 0xFF6A,
  10615. estimated: 0x212E,
  10616. esuperior: 0xF6EC,
  10617. eta: 0x03B7,
  10618. etarmenian: 0x0568,
  10619. etatonos: 0x03AE,
  10620. eth: 0x00F0,
  10621. etilde: 0x1EBD,
  10622. etildebelow: 0x1E1B,
  10623. etnahtafoukhhebrew: 0x0591,
  10624. etnahtafoukhlefthebrew: 0x0591,
  10625. etnahtahebrew: 0x0591,
  10626. etnahtalefthebrew: 0x0591,
  10627. eturned: 0x01DD,
  10628. eukorean: 0x3161,
  10629. euro: 0x20AC,
  10630. evowelsignbengali: 0x09C7,
  10631. evowelsigndeva: 0x0947,
  10632. evowelsigngujarati: 0x0AC7,
  10633. exclam: 0x0021,
  10634. exclamarmenian: 0x055C,
  10635. exclamdbl: 0x203C,
  10636. exclamdown: 0x00A1,
  10637. exclamdownsmall: 0xF7A1,
  10638. exclammonospace: 0xFF01,
  10639. exclamsmall: 0xF721,
  10640. existential: 0x2203,
  10641. ezh: 0x0292,
  10642. ezhcaron: 0x01EF,
  10643. ezhcurl: 0x0293,
  10644. ezhreversed: 0x01B9,
  10645. ezhtail: 0x01BA,
  10646. f: 0x0066,
  10647. fadeva: 0x095E,
  10648. fagurmukhi: 0x0A5E,
  10649. fahrenheit: 0x2109,
  10650. fathaarabic: 0x064E,
  10651. fathalowarabic: 0x064E,
  10652. fathatanarabic: 0x064B,
  10653. fbopomofo: 0x3108,
  10654. fcircle: 0x24D5,
  10655. fdotaccent: 0x1E1F,
  10656. feharabic: 0x0641,
  10657. feharmenian: 0x0586,
  10658. fehfinalarabic: 0xFED2,
  10659. fehinitialarabic: 0xFED3,
  10660. fehmedialarabic: 0xFED4,
  10661. feicoptic: 0x03E5,
  10662. female: 0x2640,
  10663. ff: 0xFB00,
  10664. ffi: 0xFB03,
  10665. ffl: 0xFB04,
  10666. fi: 0xFB01,
  10667. fifteencircle: 0x246E,
  10668. fifteenparen: 0x2482,
  10669. fifteenperiod: 0x2496,
  10670. figuredash: 0x2012,
  10671. filledbox: 0x25A0,
  10672. filledrect: 0x25AC,
  10673. finalkaf: 0x05DA,
  10674. finalkafdagesh: 0xFB3A,
  10675. finalkafdageshhebrew: 0xFB3A,
  10676. finalkafhebrew: 0x05DA,
  10677. finalmem: 0x05DD,
  10678. finalmemhebrew: 0x05DD,
  10679. finalnun: 0x05DF,
  10680. finalnunhebrew: 0x05DF,
  10681. finalpe: 0x05E3,
  10682. finalpehebrew: 0x05E3,
  10683. finaltsadi: 0x05E5,
  10684. finaltsadihebrew: 0x05E5,
  10685. firsttonechinese: 0x02C9,
  10686. fisheye: 0x25C9,
  10687. fitacyrillic: 0x0473,
  10688. five: 0x0035,
  10689. fivearabic: 0x0665,
  10690. fivebengali: 0x09EB,
  10691. fivecircle: 0x2464,
  10692. fivecircleinversesansserif: 0x278E,
  10693. fivedeva: 0x096B,
  10694. fiveeighths: 0x215D,
  10695. fivegujarati: 0x0AEB,
  10696. fivegurmukhi: 0x0A6B,
  10697. fivehackarabic: 0x0665,
  10698. fivehangzhou: 0x3025,
  10699. fiveideographicparen: 0x3224,
  10700. fiveinferior: 0x2085,
  10701. fivemonospace: 0xFF15,
  10702. fiveoldstyle: 0xF735,
  10703. fiveparen: 0x2478,
  10704. fiveperiod: 0x248C,
  10705. fivepersian: 0x06F5,
  10706. fiveroman: 0x2174,
  10707. fivesuperior: 0x2075,
  10708. fivethai: 0x0E55,
  10709. fl: 0xFB02,
  10710. florin: 0x0192,
  10711. fmonospace: 0xFF46,
  10712. fmsquare: 0x3399,
  10713. fofanthai: 0x0E1F,
  10714. fofathai: 0x0E1D,
  10715. fongmanthai: 0x0E4F,
  10716. forall: 0x2200,
  10717. four: 0x0034,
  10718. fourarabic: 0x0664,
  10719. fourbengali: 0x09EA,
  10720. fourcircle: 0x2463,
  10721. fourcircleinversesansserif: 0x278D,
  10722. fourdeva: 0x096A,
  10723. fourgujarati: 0x0AEA,
  10724. fourgurmukhi: 0x0A6A,
  10725. fourhackarabic: 0x0664,
  10726. fourhangzhou: 0x3024,
  10727. fourideographicparen: 0x3223,
  10728. fourinferior: 0x2084,
  10729. fourmonospace: 0xFF14,
  10730. fournumeratorbengali: 0x09F7,
  10731. fouroldstyle: 0xF734,
  10732. fourparen: 0x2477,
  10733. fourperiod: 0x248B,
  10734. fourpersian: 0x06F4,
  10735. fourroman: 0x2173,
  10736. foursuperior: 0x2074,
  10737. fourteencircle: 0x246D,
  10738. fourteenparen: 0x2481,
  10739. fourteenperiod: 0x2495,
  10740. fourthai: 0x0E54,
  10741. fourthtonechinese: 0x02CB,
  10742. fparen: 0x24A1,
  10743. fraction: 0x2044,
  10744. franc: 0x20A3,
  10745. g: 0x0067,
  10746. gabengali: 0x0997,
  10747. gacute: 0x01F5,
  10748. gadeva: 0x0917,
  10749. gafarabic: 0x06AF,
  10750. gaffinalarabic: 0xFB93,
  10751. gafinitialarabic: 0xFB94,
  10752. gafmedialarabic: 0xFB95,
  10753. gagujarati: 0x0A97,
  10754. gagurmukhi: 0x0A17,
  10755. gahiragana: 0x304C,
  10756. gakatakana: 0x30AC,
  10757. gamma: 0x03B3,
  10758. gammalatinsmall: 0x0263,
  10759. gammasuperior: 0x02E0,
  10760. gangiacoptic: 0x03EB,
  10761. gbopomofo: 0x310D,
  10762. gbreve: 0x011F,
  10763. gcaron: 0x01E7,
  10764. gcedilla: 0x0123,
  10765. gcircle: 0x24D6,
  10766. gcircumflex: 0x011D,
  10767. gcommaaccent: 0x0123,
  10768. gdot: 0x0121,
  10769. gdotaccent: 0x0121,
  10770. gecyrillic: 0x0433,
  10771. gehiragana: 0x3052,
  10772. gekatakana: 0x30B2,
  10773. geometricallyequal: 0x2251,
  10774. gereshaccenthebrew: 0x059C,
  10775. gereshhebrew: 0x05F3,
  10776. gereshmuqdamhebrew: 0x059D,
  10777. germandbls: 0x00DF,
  10778. gershayimaccenthebrew: 0x059E,
  10779. gershayimhebrew: 0x05F4,
  10780. getamark: 0x3013,
  10781. ghabengali: 0x0998,
  10782. ghadarmenian: 0x0572,
  10783. ghadeva: 0x0918,
  10784. ghagujarati: 0x0A98,
  10785. ghagurmukhi: 0x0A18,
  10786. ghainarabic: 0x063A,
  10787. ghainfinalarabic: 0xFECE,
  10788. ghaininitialarabic: 0xFECF,
  10789. ghainmedialarabic: 0xFED0,
  10790. ghemiddlehookcyrillic: 0x0495,
  10791. ghestrokecyrillic: 0x0493,
  10792. gheupturncyrillic: 0x0491,
  10793. ghhadeva: 0x095A,
  10794. ghhagurmukhi: 0x0A5A,
  10795. ghook: 0x0260,
  10796. ghzsquare: 0x3393,
  10797. gihiragana: 0x304E,
  10798. gikatakana: 0x30AE,
  10799. gimarmenian: 0x0563,
  10800. gimel: 0x05D2,
  10801. gimeldagesh: 0xFB32,
  10802. gimeldageshhebrew: 0xFB32,
  10803. gimelhebrew: 0x05D2,
  10804. gjecyrillic: 0x0453,
  10805. glottalinvertedstroke: 0x01BE,
  10806. glottalstop: 0x0294,
  10807. glottalstopinverted: 0x0296,
  10808. glottalstopmod: 0x02C0,
  10809. glottalstopreversed: 0x0295,
  10810. glottalstopreversedmod: 0x02C1,
  10811. glottalstopreversedsuperior: 0x02E4,
  10812. glottalstopstroke: 0x02A1,
  10813. glottalstopstrokereversed: 0x02A2,
  10814. gmacron: 0x1E21,
  10815. gmonospace: 0xFF47,
  10816. gohiragana: 0x3054,
  10817. gokatakana: 0x30B4,
  10818. gparen: 0x24A2,
  10819. gpasquare: 0x33AC,
  10820. gradient: 0x2207,
  10821. grave: 0x0060,
  10822. gravebelowcmb: 0x0316,
  10823. gravecmb: 0x0300,
  10824. gravecomb: 0x0300,
  10825. gravedeva: 0x0953,
  10826. gravelowmod: 0x02CE,
  10827. gravemonospace: 0xFF40,
  10828. gravetonecmb: 0x0340,
  10829. greater: 0x003E,
  10830. greaterequal: 0x2265,
  10831. greaterequalorless: 0x22DB,
  10832. greatermonospace: 0xFF1E,
  10833. greaterorequivalent: 0x2273,
  10834. greaterorless: 0x2277,
  10835. greateroverequal: 0x2267,
  10836. greatersmall: 0xFE65,
  10837. gscript: 0x0261,
  10838. gstroke: 0x01E5,
  10839. guhiragana: 0x3050,
  10840. guillemotleft: 0x00AB,
  10841. guillemotright: 0x00BB,
  10842. guilsinglleft: 0x2039,
  10843. guilsinglright: 0x203A,
  10844. gukatakana: 0x30B0,
  10845. guramusquare: 0x3318,
  10846. gysquare: 0x33C9,
  10847. h: 0x0068,
  10848. haabkhasiancyrillic: 0x04A9,
  10849. haaltonearabic: 0x06C1,
  10850. habengali: 0x09B9,
  10851. hadescendercyrillic: 0x04B3,
  10852. hadeva: 0x0939,
  10853. hagujarati: 0x0AB9,
  10854. hagurmukhi: 0x0A39,
  10855. haharabic: 0x062D,
  10856. hahfinalarabic: 0xFEA2,
  10857. hahinitialarabic: 0xFEA3,
  10858. hahiragana: 0x306F,
  10859. hahmedialarabic: 0xFEA4,
  10860. haitusquare: 0x332A,
  10861. hakatakana: 0x30CF,
  10862. hakatakanahalfwidth: 0xFF8A,
  10863. halantgurmukhi: 0x0A4D,
  10864. hamzaarabic: 0x0621,
  10865. hamzalowarabic: 0x0621,
  10866. hangulfiller: 0x3164,
  10867. hardsigncyrillic: 0x044A,
  10868. harpoonleftbarbup: 0x21BC,
  10869. harpoonrightbarbup: 0x21C0,
  10870. hasquare: 0x33CA,
  10871. hatafpatah: 0x05B2,
  10872. hatafpatah16: 0x05B2,
  10873. hatafpatah23: 0x05B2,
  10874. hatafpatah2f: 0x05B2,
  10875. hatafpatahhebrew: 0x05B2,
  10876. hatafpatahnarrowhebrew: 0x05B2,
  10877. hatafpatahquarterhebrew: 0x05B2,
  10878. hatafpatahwidehebrew: 0x05B2,
  10879. hatafqamats: 0x05B3,
  10880. hatafqamats1b: 0x05B3,
  10881. hatafqamats28: 0x05B3,
  10882. hatafqamats34: 0x05B3,
  10883. hatafqamatshebrew: 0x05B3,
  10884. hatafqamatsnarrowhebrew: 0x05B3,
  10885. hatafqamatsquarterhebrew: 0x05B3,
  10886. hatafqamatswidehebrew: 0x05B3,
  10887. hatafsegol: 0x05B1,
  10888. hatafsegol17: 0x05B1,
  10889. hatafsegol24: 0x05B1,
  10890. hatafsegol30: 0x05B1,
  10891. hatafsegolhebrew: 0x05B1,
  10892. hatafsegolnarrowhebrew: 0x05B1,
  10893. hatafsegolquarterhebrew: 0x05B1,
  10894. hatafsegolwidehebrew: 0x05B1,
  10895. hbar: 0x0127,
  10896. hbopomofo: 0x310F,
  10897. hbrevebelow: 0x1E2B,
  10898. hcedilla: 0x1E29,
  10899. hcircle: 0x24D7,
  10900. hcircumflex: 0x0125,
  10901. hdieresis: 0x1E27,
  10902. hdotaccent: 0x1E23,
  10903. hdotbelow: 0x1E25,
  10904. he: 0x05D4,
  10905. heart: 0x2665,
  10906. heartsuitblack: 0x2665,
  10907. heartsuitwhite: 0x2661,
  10908. hedagesh: 0xFB34,
  10909. hedageshhebrew: 0xFB34,
  10910. hehaltonearabic: 0x06C1,
  10911. heharabic: 0x0647,
  10912. hehebrew: 0x05D4,
  10913. hehfinalaltonearabic: 0xFBA7,
  10914. hehfinalalttwoarabic: 0xFEEA,
  10915. hehfinalarabic: 0xFEEA,
  10916. hehhamzaabovefinalarabic: 0xFBA5,
  10917. hehhamzaaboveisolatedarabic: 0xFBA4,
  10918. hehinitialaltonearabic: 0xFBA8,
  10919. hehinitialarabic: 0xFEEB,
  10920. hehiragana: 0x3078,
  10921. hehmedialaltonearabic: 0xFBA9,
  10922. hehmedialarabic: 0xFEEC,
  10923. heiseierasquare: 0x337B,
  10924. hekatakana: 0x30D8,
  10925. hekatakanahalfwidth: 0xFF8D,
  10926. hekutaarusquare: 0x3336,
  10927. henghook: 0x0267,
  10928. herutusquare: 0x3339,
  10929. het: 0x05D7,
  10930. hethebrew: 0x05D7,
  10931. hhook: 0x0266,
  10932. hhooksuperior: 0x02B1,
  10933. hieuhacirclekorean: 0x327B,
  10934. hieuhaparenkorean: 0x321B,
  10935. hieuhcirclekorean: 0x326D,
  10936. hieuhkorean: 0x314E,
  10937. hieuhparenkorean: 0x320D,
  10938. hihiragana: 0x3072,
  10939. hikatakana: 0x30D2,
  10940. hikatakanahalfwidth: 0xFF8B,
  10941. hiriq: 0x05B4,
  10942. hiriq14: 0x05B4,
  10943. hiriq21: 0x05B4,
  10944. hiriq2d: 0x05B4,
  10945. hiriqhebrew: 0x05B4,
  10946. hiriqnarrowhebrew: 0x05B4,
  10947. hiriqquarterhebrew: 0x05B4,
  10948. hiriqwidehebrew: 0x05B4,
  10949. hlinebelow: 0x1E96,
  10950. hmonospace: 0xFF48,
  10951. hoarmenian: 0x0570,
  10952. hohipthai: 0x0E2B,
  10953. hohiragana: 0x307B,
  10954. hokatakana: 0x30DB,
  10955. hokatakanahalfwidth: 0xFF8E,
  10956. holam: 0x05B9,
  10957. holam19: 0x05B9,
  10958. holam26: 0x05B9,
  10959. holam32: 0x05B9,
  10960. holamhebrew: 0x05B9,
  10961. holamnarrowhebrew: 0x05B9,
  10962. holamquarterhebrew: 0x05B9,
  10963. holamwidehebrew: 0x05B9,
  10964. honokhukthai: 0x0E2E,
  10965. hookabovecomb: 0x0309,
  10966. hookcmb: 0x0309,
  10967. hookpalatalizedbelowcmb: 0x0321,
  10968. hookretroflexbelowcmb: 0x0322,
  10969. hoonsquare: 0x3342,
  10970. horicoptic: 0x03E9,
  10971. horizontalbar: 0x2015,
  10972. horncmb: 0x031B,
  10973. hotsprings: 0x2668,
  10974. house: 0x2302,
  10975. hparen: 0x24A3,
  10976. hsuperior: 0x02B0,
  10977. hturned: 0x0265,
  10978. huhiragana: 0x3075,
  10979. huiitosquare: 0x3333,
  10980. hukatakana: 0x30D5,
  10981. hukatakanahalfwidth: 0xFF8C,
  10982. hungarumlaut: 0x02DD,
  10983. hungarumlautcmb: 0x030B,
  10984. hv: 0x0195,
  10985. hyphen: 0x002D,
  10986. hypheninferior: 0xF6E5,
  10987. hyphenmonospace: 0xFF0D,
  10988. hyphensmall: 0xFE63,
  10989. hyphensuperior: 0xF6E6,
  10990. hyphentwo: 0x2010,
  10991. i: 0x0069,
  10992. iacute: 0x00ED,
  10993. iacyrillic: 0x044F,
  10994. ibengali: 0x0987,
  10995. ibopomofo: 0x3127,
  10996. ibreve: 0x012D,
  10997. icaron: 0x01D0,
  10998. icircle: 0x24D8,
  10999. icircumflex: 0x00EE,
  11000. icyrillic: 0x0456,
  11001. idblgrave: 0x0209,
  11002. ideographearthcircle: 0x328F,
  11003. ideographfirecircle: 0x328B,
  11004. ideographicallianceparen: 0x323F,
  11005. ideographiccallparen: 0x323A,
  11006. ideographiccentrecircle: 0x32A5,
  11007. ideographicclose: 0x3006,
  11008. ideographiccomma: 0x3001,
  11009. ideographiccommaleft: 0xFF64,
  11010. ideographiccongratulationparen: 0x3237,
  11011. ideographiccorrectcircle: 0x32A3,
  11012. ideographicearthparen: 0x322F,
  11013. ideographicenterpriseparen: 0x323D,
  11014. ideographicexcellentcircle: 0x329D,
  11015. ideographicfestivalparen: 0x3240,
  11016. ideographicfinancialcircle: 0x3296,
  11017. ideographicfinancialparen: 0x3236,
  11018. ideographicfireparen: 0x322B,
  11019. ideographichaveparen: 0x3232,
  11020. ideographichighcircle: 0x32A4,
  11021. ideographiciterationmark: 0x3005,
  11022. ideographiclaborcircle: 0x3298,
  11023. ideographiclaborparen: 0x3238,
  11024. ideographicleftcircle: 0x32A7,
  11025. ideographiclowcircle: 0x32A6,
  11026. ideographicmedicinecircle: 0x32A9,
  11027. ideographicmetalparen: 0x322E,
  11028. ideographicmoonparen: 0x322A,
  11029. ideographicnameparen: 0x3234,
  11030. ideographicperiod: 0x3002,
  11031. ideographicprintcircle: 0x329E,
  11032. ideographicreachparen: 0x3243,
  11033. ideographicrepresentparen: 0x3239,
  11034. ideographicresourceparen: 0x323E,
  11035. ideographicrightcircle: 0x32A8,
  11036. ideographicsecretcircle: 0x3299,
  11037. ideographicselfparen: 0x3242,
  11038. ideographicsocietyparen: 0x3233,
  11039. ideographicspace: 0x3000,
  11040. ideographicspecialparen: 0x3235,
  11041. ideographicstockparen: 0x3231,
  11042. ideographicstudyparen: 0x323B,
  11043. ideographicsunparen: 0x3230,
  11044. ideographicsuperviseparen: 0x323C,
  11045. ideographicwaterparen: 0x322C,
  11046. ideographicwoodparen: 0x322D,
  11047. ideographiczero: 0x3007,
  11048. ideographmetalcircle: 0x328E,
  11049. ideographmooncircle: 0x328A,
  11050. ideographnamecircle: 0x3294,
  11051. ideographsuncircle: 0x3290,
  11052. ideographwatercircle: 0x328C,
  11053. ideographwoodcircle: 0x328D,
  11054. ideva: 0x0907,
  11055. idieresis: 0x00EF,
  11056. idieresisacute: 0x1E2F,
  11057. idieresiscyrillic: 0x04E5,
  11058. idotbelow: 0x1ECB,
  11059. iebrevecyrillic: 0x04D7,
  11060. iecyrillic: 0x0435,
  11061. ieungacirclekorean: 0x3275,
  11062. ieungaparenkorean: 0x3215,
  11063. ieungcirclekorean: 0x3267,
  11064. ieungkorean: 0x3147,
  11065. ieungparenkorean: 0x3207,
  11066. igrave: 0x00EC,
  11067. igujarati: 0x0A87,
  11068. igurmukhi: 0x0A07,
  11069. ihiragana: 0x3044,
  11070. ihookabove: 0x1EC9,
  11071. iibengali: 0x0988,
  11072. iicyrillic: 0x0438,
  11073. iideva: 0x0908,
  11074. iigujarati: 0x0A88,
  11075. iigurmukhi: 0x0A08,
  11076. iimatragurmukhi: 0x0A40,
  11077. iinvertedbreve: 0x020B,
  11078. iishortcyrillic: 0x0439,
  11079. iivowelsignbengali: 0x09C0,
  11080. iivowelsigndeva: 0x0940,
  11081. iivowelsigngujarati: 0x0AC0,
  11082. ij: 0x0133,
  11083. ikatakana: 0x30A4,
  11084. ikatakanahalfwidth: 0xFF72,
  11085. ikorean: 0x3163,
  11086. ilde: 0x02DC,
  11087. iluyhebrew: 0x05AC,
  11088. imacron: 0x012B,
  11089. imacroncyrillic: 0x04E3,
  11090. imageorapproximatelyequal: 0x2253,
  11091. imatragurmukhi: 0x0A3F,
  11092. imonospace: 0xFF49,
  11093. increment: 0x2206,
  11094. infinity: 0x221E,
  11095. iniarmenian: 0x056B,
  11096. integral: 0x222B,
  11097. integralbottom: 0x2321,
  11098. integralbt: 0x2321,
  11099. integralex: 0xF8F5,
  11100. integraltop: 0x2320,
  11101. integraltp: 0x2320,
  11102. intersection: 0x2229,
  11103. intisquare: 0x3305,
  11104. invbullet: 0x25D8,
  11105. invcircle: 0x25D9,
  11106. invsmileface: 0x263B,
  11107. iocyrillic: 0x0451,
  11108. iogonek: 0x012F,
  11109. iota: 0x03B9,
  11110. iotadieresis: 0x03CA,
  11111. iotadieresistonos: 0x0390,
  11112. iotalatin: 0x0269,
  11113. iotatonos: 0x03AF,
  11114. iparen: 0x24A4,
  11115. irigurmukhi: 0x0A72,
  11116. ismallhiragana: 0x3043,
  11117. ismallkatakana: 0x30A3,
  11118. ismallkatakanahalfwidth: 0xFF68,
  11119. issharbengali: 0x09FA,
  11120. istroke: 0x0268,
  11121. isuperior: 0xF6ED,
  11122. iterationhiragana: 0x309D,
  11123. iterationkatakana: 0x30FD,
  11124. itilde: 0x0129,
  11125. itildebelow: 0x1E2D,
  11126. iubopomofo: 0x3129,
  11127. iucyrillic: 0x044E,
  11128. ivowelsignbengali: 0x09BF,
  11129. ivowelsigndeva: 0x093F,
  11130. ivowelsigngujarati: 0x0ABF,
  11131. izhitsacyrillic: 0x0475,
  11132. izhitsadblgravecyrillic: 0x0477,
  11133. j: 0x006A,
  11134. jaarmenian: 0x0571,
  11135. jabengali: 0x099C,
  11136. jadeva: 0x091C,
  11137. jagujarati: 0x0A9C,
  11138. jagurmukhi: 0x0A1C,
  11139. jbopomofo: 0x3110,
  11140. jcaron: 0x01F0,
  11141. jcircle: 0x24D9,
  11142. jcircumflex: 0x0135,
  11143. jcrossedtail: 0x029D,
  11144. jdotlessstroke: 0x025F,
  11145. jecyrillic: 0x0458,
  11146. jeemarabic: 0x062C,
  11147. jeemfinalarabic: 0xFE9E,
  11148. jeeminitialarabic: 0xFE9F,
  11149. jeemmedialarabic: 0xFEA0,
  11150. jeharabic: 0x0698,
  11151. jehfinalarabic: 0xFB8B,
  11152. jhabengali: 0x099D,
  11153. jhadeva: 0x091D,
  11154. jhagujarati: 0x0A9D,
  11155. jhagurmukhi: 0x0A1D,
  11156. jheharmenian: 0x057B,
  11157. jis: 0x3004,
  11158. jmonospace: 0xFF4A,
  11159. jparen: 0x24A5,
  11160. jsuperior: 0x02B2,
  11161. k: 0x006B,
  11162. kabashkircyrillic: 0x04A1,
  11163. kabengali: 0x0995,
  11164. kacute: 0x1E31,
  11165. kacyrillic: 0x043A,
  11166. kadescendercyrillic: 0x049B,
  11167. kadeva: 0x0915,
  11168. kaf: 0x05DB,
  11169. kafarabic: 0x0643,
  11170. kafdagesh: 0xFB3B,
  11171. kafdageshhebrew: 0xFB3B,
  11172. kaffinalarabic: 0xFEDA,
  11173. kafhebrew: 0x05DB,
  11174. kafinitialarabic: 0xFEDB,
  11175. kafmedialarabic: 0xFEDC,
  11176. kafrafehebrew: 0xFB4D,
  11177. kagujarati: 0x0A95,
  11178. kagurmukhi: 0x0A15,
  11179. kahiragana: 0x304B,
  11180. kahookcyrillic: 0x04C4,
  11181. kakatakana: 0x30AB,
  11182. kakatakanahalfwidth: 0xFF76,
  11183. kappa: 0x03BA,
  11184. kappasymbolgreek: 0x03F0,
  11185. kapyeounmieumkorean: 0x3171,
  11186. kapyeounphieuphkorean: 0x3184,
  11187. kapyeounpieupkorean: 0x3178,
  11188. kapyeounssangpieupkorean: 0x3179,
  11189. karoriisquare: 0x330D,
  11190. kashidaautoarabic: 0x0640,
  11191. kashidaautonosidebearingarabic: 0x0640,
  11192. kasmallkatakana: 0x30F5,
  11193. kasquare: 0x3384,
  11194. kasraarabic: 0x0650,
  11195. kasratanarabic: 0x064D,
  11196. kastrokecyrillic: 0x049F,
  11197. katahiraprolongmarkhalfwidth: 0xFF70,
  11198. kaverticalstrokecyrillic: 0x049D,
  11199. kbopomofo: 0x310E,
  11200. kcalsquare: 0x3389,
  11201. kcaron: 0x01E9,
  11202. kcedilla: 0x0137,
  11203. kcircle: 0x24DA,
  11204. kcommaaccent: 0x0137,
  11205. kdotbelow: 0x1E33,
  11206. keharmenian: 0x0584,
  11207. kehiragana: 0x3051,
  11208. kekatakana: 0x30B1,
  11209. kekatakanahalfwidth: 0xFF79,
  11210. kenarmenian: 0x056F,
  11211. kesmallkatakana: 0x30F6,
  11212. kgreenlandic: 0x0138,
  11213. khabengali: 0x0996,
  11214. khacyrillic: 0x0445,
  11215. khadeva: 0x0916,
  11216. khagujarati: 0x0A96,
  11217. khagurmukhi: 0x0A16,
  11218. khaharabic: 0x062E,
  11219. khahfinalarabic: 0xFEA6,
  11220. khahinitialarabic: 0xFEA7,
  11221. khahmedialarabic: 0xFEA8,
  11222. kheicoptic: 0x03E7,
  11223. khhadeva: 0x0959,
  11224. khhagurmukhi: 0x0A59,
  11225. khieukhacirclekorean: 0x3278,
  11226. khieukhaparenkorean: 0x3218,
  11227. khieukhcirclekorean: 0x326A,
  11228. khieukhkorean: 0x314B,
  11229. khieukhparenkorean: 0x320A,
  11230. khokhaithai: 0x0E02,
  11231. khokhonthai: 0x0E05,
  11232. khokhuatthai: 0x0E03,
  11233. khokhwaithai: 0x0E04,
  11234. khomutthai: 0x0E5B,
  11235. khook: 0x0199,
  11236. khorakhangthai: 0x0E06,
  11237. khzsquare: 0x3391,
  11238. kihiragana: 0x304D,
  11239. kikatakana: 0x30AD,
  11240. kikatakanahalfwidth: 0xFF77,
  11241. kiroguramusquare: 0x3315,
  11242. kiromeetorusquare: 0x3316,
  11243. kirosquare: 0x3314,
  11244. kiyeokacirclekorean: 0x326E,
  11245. kiyeokaparenkorean: 0x320E,
  11246. kiyeokcirclekorean: 0x3260,
  11247. kiyeokkorean: 0x3131,
  11248. kiyeokparenkorean: 0x3200,
  11249. kiyeoksioskorean: 0x3133,
  11250. kjecyrillic: 0x045C,
  11251. klinebelow: 0x1E35,
  11252. klsquare: 0x3398,
  11253. kmcubedsquare: 0x33A6,
  11254. kmonospace: 0xFF4B,
  11255. kmsquaredsquare: 0x33A2,
  11256. kohiragana: 0x3053,
  11257. kohmsquare: 0x33C0,
  11258. kokaithai: 0x0E01,
  11259. kokatakana: 0x30B3,
  11260. kokatakanahalfwidth: 0xFF7A,
  11261. kooposquare: 0x331E,
  11262. koppacyrillic: 0x0481,
  11263. koreanstandardsymbol: 0x327F,
  11264. koroniscmb: 0x0343,
  11265. kparen: 0x24A6,
  11266. kpasquare: 0x33AA,
  11267. ksicyrillic: 0x046F,
  11268. ktsquare: 0x33CF,
  11269. kturned: 0x029E,
  11270. kuhiragana: 0x304F,
  11271. kukatakana: 0x30AF,
  11272. kukatakanahalfwidth: 0xFF78,
  11273. kvsquare: 0x33B8,
  11274. kwsquare: 0x33BE,
  11275. l: 0x006C,
  11276. labengali: 0x09B2,
  11277. lacute: 0x013A,
  11278. ladeva: 0x0932,
  11279. lagujarati: 0x0AB2,
  11280. lagurmukhi: 0x0A32,
  11281. lakkhangyaothai: 0x0E45,
  11282. lamaleffinalarabic: 0xFEFC,
  11283. lamalefhamzaabovefinalarabic: 0xFEF8,
  11284. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  11285. lamalefhamzabelowfinalarabic: 0xFEFA,
  11286. lamalefhamzabelowisolatedarabic: 0xFEF9,
  11287. lamalefisolatedarabic: 0xFEFB,
  11288. lamalefmaddaabovefinalarabic: 0xFEF6,
  11289. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  11290. lamarabic: 0x0644,
  11291. lambda: 0x03BB,
  11292. lambdastroke: 0x019B,
  11293. lamed: 0x05DC,
  11294. lameddagesh: 0xFB3C,
  11295. lameddageshhebrew: 0xFB3C,
  11296. lamedhebrew: 0x05DC,
  11297. lamfinalarabic: 0xFEDE,
  11298. lamhahinitialarabic: 0xFCCA,
  11299. laminitialarabic: 0xFEDF,
  11300. lamjeeminitialarabic: 0xFCC9,
  11301. lamkhahinitialarabic: 0xFCCB,
  11302. lamlamhehisolatedarabic: 0xFDF2,
  11303. lammedialarabic: 0xFEE0,
  11304. lammeemhahinitialarabic: 0xFD88,
  11305. lammeeminitialarabic: 0xFCCC,
  11306. largecircle: 0x25EF,
  11307. lbar: 0x019A,
  11308. lbelt: 0x026C,
  11309. lbopomofo: 0x310C,
  11310. lcaron: 0x013E,
  11311. lcedilla: 0x013C,
  11312. lcircle: 0x24DB,
  11313. lcircumflexbelow: 0x1E3D,
  11314. lcommaaccent: 0x013C,
  11315. ldot: 0x0140,
  11316. ldotaccent: 0x0140,
  11317. ldotbelow: 0x1E37,
  11318. ldotbelowmacron: 0x1E39,
  11319. leftangleabovecmb: 0x031A,
  11320. lefttackbelowcmb: 0x0318,
  11321. less: 0x003C,
  11322. lessequal: 0x2264,
  11323. lessequalorgreater: 0x22DA,
  11324. lessmonospace: 0xFF1C,
  11325. lessorequivalent: 0x2272,
  11326. lessorgreater: 0x2276,
  11327. lessoverequal: 0x2266,
  11328. lesssmall: 0xFE64,
  11329. lezh: 0x026E,
  11330. lfblock: 0x258C,
  11331. lhookretroflex: 0x026D,
  11332. lira: 0x20A4,
  11333. liwnarmenian: 0x056C,
  11334. lj: 0x01C9,
  11335. ljecyrillic: 0x0459,
  11336. ll: 0xF6C0,
  11337. lladeva: 0x0933,
  11338. llagujarati: 0x0AB3,
  11339. llinebelow: 0x1E3B,
  11340. llladeva: 0x0934,
  11341. llvocalicbengali: 0x09E1,
  11342. llvocalicdeva: 0x0961,
  11343. llvocalicvowelsignbengali: 0x09E3,
  11344. llvocalicvowelsigndeva: 0x0963,
  11345. lmiddletilde: 0x026B,
  11346. lmonospace: 0xFF4C,
  11347. lmsquare: 0x33D0,
  11348. lochulathai: 0x0E2C,
  11349. logicaland: 0x2227,
  11350. logicalnot: 0x00AC,
  11351. logicalnotreversed: 0x2310,
  11352. logicalor: 0x2228,
  11353. lolingthai: 0x0E25,
  11354. longs: 0x017F,
  11355. lowlinecenterline: 0xFE4E,
  11356. lowlinecmb: 0x0332,
  11357. lowlinedashed: 0xFE4D,
  11358. lozenge: 0x25CA,
  11359. lparen: 0x24A7,
  11360. lslash: 0x0142,
  11361. lsquare: 0x2113,
  11362. lsuperior: 0xF6EE,
  11363. ltshade: 0x2591,
  11364. luthai: 0x0E26,
  11365. lvocalicbengali: 0x098C,
  11366. lvocalicdeva: 0x090C,
  11367. lvocalicvowelsignbengali: 0x09E2,
  11368. lvocalicvowelsigndeva: 0x0962,
  11369. lxsquare: 0x33D3,
  11370. m: 0x006D,
  11371. mabengali: 0x09AE,
  11372. macron: 0x00AF,
  11373. macronbelowcmb: 0x0331,
  11374. macroncmb: 0x0304,
  11375. macronlowmod: 0x02CD,
  11376. macronmonospace: 0xFFE3,
  11377. macute: 0x1E3F,
  11378. madeva: 0x092E,
  11379. magujarati: 0x0AAE,
  11380. magurmukhi: 0x0A2E,
  11381. mahapakhhebrew: 0x05A4,
  11382. mahapakhlefthebrew: 0x05A4,
  11383. mahiragana: 0x307E,
  11384. maichattawalowleftthai: 0xF895,
  11385. maichattawalowrightthai: 0xF894,
  11386. maichattawathai: 0x0E4B,
  11387. maichattawaupperleftthai: 0xF893,
  11388. maieklowleftthai: 0xF88C,
  11389. maieklowrightthai: 0xF88B,
  11390. maiekthai: 0x0E48,
  11391. maiekupperleftthai: 0xF88A,
  11392. maihanakatleftthai: 0xF884,
  11393. maihanakatthai: 0x0E31,
  11394. maitaikhuleftthai: 0xF889,
  11395. maitaikhuthai: 0x0E47,
  11396. maitholowleftthai: 0xF88F,
  11397. maitholowrightthai: 0xF88E,
  11398. maithothai: 0x0E49,
  11399. maithoupperleftthai: 0xF88D,
  11400. maitrilowleftthai: 0xF892,
  11401. maitrilowrightthai: 0xF891,
  11402. maitrithai: 0x0E4A,
  11403. maitriupperleftthai: 0xF890,
  11404. maiyamokthai: 0x0E46,
  11405. makatakana: 0x30DE,
  11406. makatakanahalfwidth: 0xFF8F,
  11407. male: 0x2642,
  11408. mansyonsquare: 0x3347,
  11409. maqafhebrew: 0x05BE,
  11410. mars: 0x2642,
  11411. masoracirclehebrew: 0x05AF,
  11412. masquare: 0x3383,
  11413. mbopomofo: 0x3107,
  11414. mbsquare: 0x33D4,
  11415. mcircle: 0x24DC,
  11416. mcubedsquare: 0x33A5,
  11417. mdotaccent: 0x1E41,
  11418. mdotbelow: 0x1E43,
  11419. meemarabic: 0x0645,
  11420. meemfinalarabic: 0xFEE2,
  11421. meeminitialarabic: 0xFEE3,
  11422. meemmedialarabic: 0xFEE4,
  11423. meemmeeminitialarabic: 0xFCD1,
  11424. meemmeemisolatedarabic: 0xFC48,
  11425. meetorusquare: 0x334D,
  11426. mehiragana: 0x3081,
  11427. meizierasquare: 0x337E,
  11428. mekatakana: 0x30E1,
  11429. mekatakanahalfwidth: 0xFF92,
  11430. mem: 0x05DE,
  11431. memdagesh: 0xFB3E,
  11432. memdageshhebrew: 0xFB3E,
  11433. memhebrew: 0x05DE,
  11434. menarmenian: 0x0574,
  11435. merkhahebrew: 0x05A5,
  11436. merkhakefulahebrew: 0x05A6,
  11437. merkhakefulalefthebrew: 0x05A6,
  11438. merkhalefthebrew: 0x05A5,
  11439. mhook: 0x0271,
  11440. mhzsquare: 0x3392,
  11441. middledotkatakanahalfwidth: 0xFF65,
  11442. middot: 0x00B7,
  11443. mieumacirclekorean: 0x3272,
  11444. mieumaparenkorean: 0x3212,
  11445. mieumcirclekorean: 0x3264,
  11446. mieumkorean: 0x3141,
  11447. mieumpansioskorean: 0x3170,
  11448. mieumparenkorean: 0x3204,
  11449. mieumpieupkorean: 0x316E,
  11450. mieumsioskorean: 0x316F,
  11451. mihiragana: 0x307F,
  11452. mikatakana: 0x30DF,
  11453. mikatakanahalfwidth: 0xFF90,
  11454. minus: 0x2212,
  11455. minusbelowcmb: 0x0320,
  11456. minuscircle: 0x2296,
  11457. minusmod: 0x02D7,
  11458. minusplus: 0x2213,
  11459. minute: 0x2032,
  11460. miribaarusquare: 0x334A,
  11461. mirisquare: 0x3349,
  11462. mlonglegturned: 0x0270,
  11463. mlsquare: 0x3396,
  11464. mmcubedsquare: 0x33A3,
  11465. mmonospace: 0xFF4D,
  11466. mmsquaredsquare: 0x339F,
  11467. mohiragana: 0x3082,
  11468. mohmsquare: 0x33C1,
  11469. mokatakana: 0x30E2,
  11470. mokatakanahalfwidth: 0xFF93,
  11471. molsquare: 0x33D6,
  11472. momathai: 0x0E21,
  11473. moverssquare: 0x33A7,
  11474. moverssquaredsquare: 0x33A8,
  11475. mparen: 0x24A8,
  11476. mpasquare: 0x33AB,
  11477. mssquare: 0x33B3,
  11478. msuperior: 0xF6EF,
  11479. mturned: 0x026F,
  11480. mu: 0x00B5,
  11481. mu1: 0x00B5,
  11482. muasquare: 0x3382,
  11483. muchgreater: 0x226B,
  11484. muchless: 0x226A,
  11485. mufsquare: 0x338C,
  11486. mugreek: 0x03BC,
  11487. mugsquare: 0x338D,
  11488. muhiragana: 0x3080,
  11489. mukatakana: 0x30E0,
  11490. mukatakanahalfwidth: 0xFF91,
  11491. mulsquare: 0x3395,
  11492. multiply: 0x00D7,
  11493. mumsquare: 0x339B,
  11494. munahhebrew: 0x05A3,
  11495. munahlefthebrew: 0x05A3,
  11496. musicalnote: 0x266A,
  11497. musicalnotedbl: 0x266B,
  11498. musicflatsign: 0x266D,
  11499. musicsharpsign: 0x266F,
  11500. mussquare: 0x33B2,
  11501. muvsquare: 0x33B6,
  11502. muwsquare: 0x33BC,
  11503. mvmegasquare: 0x33B9,
  11504. mvsquare: 0x33B7,
  11505. mwmegasquare: 0x33BF,
  11506. mwsquare: 0x33BD,
  11507. n: 0x006E,
  11508. nabengali: 0x09A8,
  11509. nabla: 0x2207,
  11510. nacute: 0x0144,
  11511. nadeva: 0x0928,
  11512. nagujarati: 0x0AA8,
  11513. nagurmukhi: 0x0A28,
  11514. nahiragana: 0x306A,
  11515. nakatakana: 0x30CA,
  11516. nakatakanahalfwidth: 0xFF85,
  11517. napostrophe: 0x0149,
  11518. nasquare: 0x3381,
  11519. nbopomofo: 0x310B,
  11520. nbspace: 0x00A0,
  11521. ncaron: 0x0148,
  11522. ncedilla: 0x0146,
  11523. ncircle: 0x24DD,
  11524. ncircumflexbelow: 0x1E4B,
  11525. ncommaaccent: 0x0146,
  11526. ndotaccent: 0x1E45,
  11527. ndotbelow: 0x1E47,
  11528. nehiragana: 0x306D,
  11529. nekatakana: 0x30CD,
  11530. nekatakanahalfwidth: 0xFF88,
  11531. newsheqelsign: 0x20AA,
  11532. nfsquare: 0x338B,
  11533. ngabengali: 0x0999,
  11534. ngadeva: 0x0919,
  11535. ngagujarati: 0x0A99,
  11536. ngagurmukhi: 0x0A19,
  11537. ngonguthai: 0x0E07,
  11538. nhiragana: 0x3093,
  11539. nhookleft: 0x0272,
  11540. nhookretroflex: 0x0273,
  11541. nieunacirclekorean: 0x326F,
  11542. nieunaparenkorean: 0x320F,
  11543. nieuncieuckorean: 0x3135,
  11544. nieuncirclekorean: 0x3261,
  11545. nieunhieuhkorean: 0x3136,
  11546. nieunkorean: 0x3134,
  11547. nieunpansioskorean: 0x3168,
  11548. nieunparenkorean: 0x3201,
  11549. nieunsioskorean: 0x3167,
  11550. nieuntikeutkorean: 0x3166,
  11551. nihiragana: 0x306B,
  11552. nikatakana: 0x30CB,
  11553. nikatakanahalfwidth: 0xFF86,
  11554. nikhahitleftthai: 0xF899,
  11555. nikhahitthai: 0x0E4D,
  11556. nine: 0x0039,
  11557. ninearabic: 0x0669,
  11558. ninebengali: 0x09EF,
  11559. ninecircle: 0x2468,
  11560. ninecircleinversesansserif: 0x2792,
  11561. ninedeva: 0x096F,
  11562. ninegujarati: 0x0AEF,
  11563. ninegurmukhi: 0x0A6F,
  11564. ninehackarabic: 0x0669,
  11565. ninehangzhou: 0x3029,
  11566. nineideographicparen: 0x3228,
  11567. nineinferior: 0x2089,
  11568. ninemonospace: 0xFF19,
  11569. nineoldstyle: 0xF739,
  11570. nineparen: 0x247C,
  11571. nineperiod: 0x2490,
  11572. ninepersian: 0x06F9,
  11573. nineroman: 0x2178,
  11574. ninesuperior: 0x2079,
  11575. nineteencircle: 0x2472,
  11576. nineteenparen: 0x2486,
  11577. nineteenperiod: 0x249A,
  11578. ninethai: 0x0E59,
  11579. nj: 0x01CC,
  11580. njecyrillic: 0x045A,
  11581. nkatakana: 0x30F3,
  11582. nkatakanahalfwidth: 0xFF9D,
  11583. nlegrightlong: 0x019E,
  11584. nlinebelow: 0x1E49,
  11585. nmonospace: 0xFF4E,
  11586. nmsquare: 0x339A,
  11587. nnabengali: 0x09A3,
  11588. nnadeva: 0x0923,
  11589. nnagujarati: 0x0AA3,
  11590. nnagurmukhi: 0x0A23,
  11591. nnnadeva: 0x0929,
  11592. nohiragana: 0x306E,
  11593. nokatakana: 0x30CE,
  11594. nokatakanahalfwidth: 0xFF89,
  11595. nonbreakingspace: 0x00A0,
  11596. nonenthai: 0x0E13,
  11597. nonuthai: 0x0E19,
  11598. noonarabic: 0x0646,
  11599. noonfinalarabic: 0xFEE6,
  11600. noonghunnaarabic: 0x06BA,
  11601. noonghunnafinalarabic: 0xFB9F,
  11602. nooninitialarabic: 0xFEE7,
  11603. noonjeeminitialarabic: 0xFCD2,
  11604. noonjeemisolatedarabic: 0xFC4B,
  11605. noonmedialarabic: 0xFEE8,
  11606. noonmeeminitialarabic: 0xFCD5,
  11607. noonmeemisolatedarabic: 0xFC4E,
  11608. noonnoonfinalarabic: 0xFC8D,
  11609. notcontains: 0x220C,
  11610. notelement: 0x2209,
  11611. notelementof: 0x2209,
  11612. notequal: 0x2260,
  11613. notgreater: 0x226F,
  11614. notgreaternorequal: 0x2271,
  11615. notgreaternorless: 0x2279,
  11616. notidentical: 0x2262,
  11617. notless: 0x226E,
  11618. notlessnorequal: 0x2270,
  11619. notparallel: 0x2226,
  11620. notprecedes: 0x2280,
  11621. notsubset: 0x2284,
  11622. notsucceeds: 0x2281,
  11623. notsuperset: 0x2285,
  11624. nowarmenian: 0x0576,
  11625. nparen: 0x24A9,
  11626. nssquare: 0x33B1,
  11627. nsuperior: 0x207F,
  11628. ntilde: 0x00F1,
  11629. nu: 0x03BD,
  11630. nuhiragana: 0x306C,
  11631. nukatakana: 0x30CC,
  11632. nukatakanahalfwidth: 0xFF87,
  11633. nuktabengali: 0x09BC,
  11634. nuktadeva: 0x093C,
  11635. nuktagujarati: 0x0ABC,
  11636. nuktagurmukhi: 0x0A3C,
  11637. numbersign: 0x0023,
  11638. numbersignmonospace: 0xFF03,
  11639. numbersignsmall: 0xFE5F,
  11640. numeralsigngreek: 0x0374,
  11641. numeralsignlowergreek: 0x0375,
  11642. numero: 0x2116,
  11643. nun: 0x05E0,
  11644. nundagesh: 0xFB40,
  11645. nundageshhebrew: 0xFB40,
  11646. nunhebrew: 0x05E0,
  11647. nvsquare: 0x33B5,
  11648. nwsquare: 0x33BB,
  11649. nyabengali: 0x099E,
  11650. nyadeva: 0x091E,
  11651. nyagujarati: 0x0A9E,
  11652. nyagurmukhi: 0x0A1E,
  11653. o: 0x006F,
  11654. oacute: 0x00F3,
  11655. oangthai: 0x0E2D,
  11656. obarred: 0x0275,
  11657. obarredcyrillic: 0x04E9,
  11658. obarreddieresiscyrillic: 0x04EB,
  11659. obengali: 0x0993,
  11660. obopomofo: 0x311B,
  11661. obreve: 0x014F,
  11662. ocandradeva: 0x0911,
  11663. ocandragujarati: 0x0A91,
  11664. ocandravowelsigndeva: 0x0949,
  11665. ocandravowelsigngujarati: 0x0AC9,
  11666. ocaron: 0x01D2,
  11667. ocircle: 0x24DE,
  11668. ocircumflex: 0x00F4,
  11669. ocircumflexacute: 0x1ED1,
  11670. ocircumflexdotbelow: 0x1ED9,
  11671. ocircumflexgrave: 0x1ED3,
  11672. ocircumflexhookabove: 0x1ED5,
  11673. ocircumflextilde: 0x1ED7,
  11674. ocyrillic: 0x043E,
  11675. odblacute: 0x0151,
  11676. odblgrave: 0x020D,
  11677. odeva: 0x0913,
  11678. odieresis: 0x00F6,
  11679. odieresiscyrillic: 0x04E7,
  11680. odotbelow: 0x1ECD,
  11681. oe: 0x0153,
  11682. oekorean: 0x315A,
  11683. ogonek: 0x02DB,
  11684. ogonekcmb: 0x0328,
  11685. ograve: 0x00F2,
  11686. ogujarati: 0x0A93,
  11687. oharmenian: 0x0585,
  11688. ohiragana: 0x304A,
  11689. ohookabove: 0x1ECF,
  11690. ohorn: 0x01A1,
  11691. ohornacute: 0x1EDB,
  11692. ohorndotbelow: 0x1EE3,
  11693. ohorngrave: 0x1EDD,
  11694. ohornhookabove: 0x1EDF,
  11695. ohorntilde: 0x1EE1,
  11696. ohungarumlaut: 0x0151,
  11697. oi: 0x01A3,
  11698. oinvertedbreve: 0x020F,
  11699. okatakana: 0x30AA,
  11700. okatakanahalfwidth: 0xFF75,
  11701. okorean: 0x3157,
  11702. olehebrew: 0x05AB,
  11703. omacron: 0x014D,
  11704. omacronacute: 0x1E53,
  11705. omacrongrave: 0x1E51,
  11706. omdeva: 0x0950,
  11707. omega: 0x03C9,
  11708. omega1: 0x03D6,
  11709. omegacyrillic: 0x0461,
  11710. omegalatinclosed: 0x0277,
  11711. omegaroundcyrillic: 0x047B,
  11712. omegatitlocyrillic: 0x047D,
  11713. omegatonos: 0x03CE,
  11714. omgujarati: 0x0AD0,
  11715. omicron: 0x03BF,
  11716. omicrontonos: 0x03CC,
  11717. omonospace: 0xFF4F,
  11718. one: 0x0031,
  11719. onearabic: 0x0661,
  11720. onebengali: 0x09E7,
  11721. onecircle: 0x2460,
  11722. onecircleinversesansserif: 0x278A,
  11723. onedeva: 0x0967,
  11724. onedotenleader: 0x2024,
  11725. oneeighth: 0x215B,
  11726. onefitted: 0xF6DC,
  11727. onegujarati: 0x0AE7,
  11728. onegurmukhi: 0x0A67,
  11729. onehackarabic: 0x0661,
  11730. onehalf: 0x00BD,
  11731. onehangzhou: 0x3021,
  11732. oneideographicparen: 0x3220,
  11733. oneinferior: 0x2081,
  11734. onemonospace: 0xFF11,
  11735. onenumeratorbengali: 0x09F4,
  11736. oneoldstyle: 0xF731,
  11737. oneparen: 0x2474,
  11738. oneperiod: 0x2488,
  11739. onepersian: 0x06F1,
  11740. onequarter: 0x00BC,
  11741. oneroman: 0x2170,
  11742. onesuperior: 0x00B9,
  11743. onethai: 0x0E51,
  11744. onethird: 0x2153,
  11745. oogonek: 0x01EB,
  11746. oogonekmacron: 0x01ED,
  11747. oogurmukhi: 0x0A13,
  11748. oomatragurmukhi: 0x0A4B,
  11749. oopen: 0x0254,
  11750. oparen: 0x24AA,
  11751. openbullet: 0x25E6,
  11752. option: 0x2325,
  11753. ordfeminine: 0x00AA,
  11754. ordmasculine: 0x00BA,
  11755. orthogonal: 0x221F,
  11756. oshortdeva: 0x0912,
  11757. oshortvowelsigndeva: 0x094A,
  11758. oslash: 0x00F8,
  11759. oslashacute: 0x01FF,
  11760. osmallhiragana: 0x3049,
  11761. osmallkatakana: 0x30A9,
  11762. osmallkatakanahalfwidth: 0xFF6B,
  11763. ostrokeacute: 0x01FF,
  11764. osuperior: 0xF6F0,
  11765. otcyrillic: 0x047F,
  11766. otilde: 0x00F5,
  11767. otildeacute: 0x1E4D,
  11768. otildedieresis: 0x1E4F,
  11769. oubopomofo: 0x3121,
  11770. overline: 0x203E,
  11771. overlinecenterline: 0xFE4A,
  11772. overlinecmb: 0x0305,
  11773. overlinedashed: 0xFE49,
  11774. overlinedblwavy: 0xFE4C,
  11775. overlinewavy: 0xFE4B,
  11776. overscore: 0x00AF,
  11777. ovowelsignbengali: 0x09CB,
  11778. ovowelsigndeva: 0x094B,
  11779. ovowelsigngujarati: 0x0ACB,
  11780. p: 0x0070,
  11781. paampssquare: 0x3380,
  11782. paasentosquare: 0x332B,
  11783. pabengali: 0x09AA,
  11784. pacute: 0x1E55,
  11785. padeva: 0x092A,
  11786. pagedown: 0x21DF,
  11787. pageup: 0x21DE,
  11788. pagujarati: 0x0AAA,
  11789. pagurmukhi: 0x0A2A,
  11790. pahiragana: 0x3071,
  11791. paiyannoithai: 0x0E2F,
  11792. pakatakana: 0x30D1,
  11793. palatalizationcyrilliccmb: 0x0484,
  11794. palochkacyrillic: 0x04C0,
  11795. pansioskorean: 0x317F,
  11796. paragraph: 0x00B6,
  11797. parallel: 0x2225,
  11798. parenleft: 0x0028,
  11799. parenleftaltonearabic: 0xFD3E,
  11800. parenleftbt: 0xF8ED,
  11801. parenleftex: 0xF8EC,
  11802. parenleftinferior: 0x208D,
  11803. parenleftmonospace: 0xFF08,
  11804. parenleftsmall: 0xFE59,
  11805. parenleftsuperior: 0x207D,
  11806. parenlefttp: 0xF8EB,
  11807. parenleftvertical: 0xFE35,
  11808. parenright: 0x0029,
  11809. parenrightaltonearabic: 0xFD3F,
  11810. parenrightbt: 0xF8F8,
  11811. parenrightex: 0xF8F7,
  11812. parenrightinferior: 0x208E,
  11813. parenrightmonospace: 0xFF09,
  11814. parenrightsmall: 0xFE5A,
  11815. parenrightsuperior: 0x207E,
  11816. parenrighttp: 0xF8F6,
  11817. parenrightvertical: 0xFE36,
  11818. partialdiff: 0x2202,
  11819. paseqhebrew: 0x05C0,
  11820. pashtahebrew: 0x0599,
  11821. pasquare: 0x33A9,
  11822. patah: 0x05B7,
  11823. patah11: 0x05B7,
  11824. patah1d: 0x05B7,
  11825. patah2a: 0x05B7,
  11826. patahhebrew: 0x05B7,
  11827. patahnarrowhebrew: 0x05B7,
  11828. patahquarterhebrew: 0x05B7,
  11829. patahwidehebrew: 0x05B7,
  11830. pazerhebrew: 0x05A1,
  11831. pbopomofo: 0x3106,
  11832. pcircle: 0x24DF,
  11833. pdotaccent: 0x1E57,
  11834. pe: 0x05E4,
  11835. pecyrillic: 0x043F,
  11836. pedagesh: 0xFB44,
  11837. pedageshhebrew: 0xFB44,
  11838. peezisquare: 0x333B,
  11839. pefinaldageshhebrew: 0xFB43,
  11840. peharabic: 0x067E,
  11841. peharmenian: 0x057A,
  11842. pehebrew: 0x05E4,
  11843. pehfinalarabic: 0xFB57,
  11844. pehinitialarabic: 0xFB58,
  11845. pehiragana: 0x307A,
  11846. pehmedialarabic: 0xFB59,
  11847. pekatakana: 0x30DA,
  11848. pemiddlehookcyrillic: 0x04A7,
  11849. perafehebrew: 0xFB4E,
  11850. percent: 0x0025,
  11851. percentarabic: 0x066A,
  11852. percentmonospace: 0xFF05,
  11853. percentsmall: 0xFE6A,
  11854. period: 0x002E,
  11855. periodarmenian: 0x0589,
  11856. periodcentered: 0x00B7,
  11857. periodhalfwidth: 0xFF61,
  11858. periodinferior: 0xF6E7,
  11859. periodmonospace: 0xFF0E,
  11860. periodsmall: 0xFE52,
  11861. periodsuperior: 0xF6E8,
  11862. perispomenigreekcmb: 0x0342,
  11863. perpendicular: 0x22A5,
  11864. perthousand: 0x2030,
  11865. peseta: 0x20A7,
  11866. pfsquare: 0x338A,
  11867. phabengali: 0x09AB,
  11868. phadeva: 0x092B,
  11869. phagujarati: 0x0AAB,
  11870. phagurmukhi: 0x0A2B,
  11871. phi: 0x03C6,
  11872. phi1: 0x03D5,
  11873. phieuphacirclekorean: 0x327A,
  11874. phieuphaparenkorean: 0x321A,
  11875. phieuphcirclekorean: 0x326C,
  11876. phieuphkorean: 0x314D,
  11877. phieuphparenkorean: 0x320C,
  11878. philatin: 0x0278,
  11879. phinthuthai: 0x0E3A,
  11880. phisymbolgreek: 0x03D5,
  11881. phook: 0x01A5,
  11882. phophanthai: 0x0E1E,
  11883. phophungthai: 0x0E1C,
  11884. phosamphaothai: 0x0E20,
  11885. pi: 0x03C0,
  11886. pieupacirclekorean: 0x3273,
  11887. pieupaparenkorean: 0x3213,
  11888. pieupcieuckorean: 0x3176,
  11889. pieupcirclekorean: 0x3265,
  11890. pieupkiyeokkorean: 0x3172,
  11891. pieupkorean: 0x3142,
  11892. pieupparenkorean: 0x3205,
  11893. pieupsioskiyeokkorean: 0x3174,
  11894. pieupsioskorean: 0x3144,
  11895. pieupsiostikeutkorean: 0x3175,
  11896. pieupthieuthkorean: 0x3177,
  11897. pieuptikeutkorean: 0x3173,
  11898. pihiragana: 0x3074,
  11899. pikatakana: 0x30D4,
  11900. pisymbolgreek: 0x03D6,
  11901. piwrarmenian: 0x0583,
  11902. plus: 0x002B,
  11903. plusbelowcmb: 0x031F,
  11904. pluscircle: 0x2295,
  11905. plusminus: 0x00B1,
  11906. plusmod: 0x02D6,
  11907. plusmonospace: 0xFF0B,
  11908. plussmall: 0xFE62,
  11909. plussuperior: 0x207A,
  11910. pmonospace: 0xFF50,
  11911. pmsquare: 0x33D8,
  11912. pohiragana: 0x307D,
  11913. pointingindexdownwhite: 0x261F,
  11914. pointingindexleftwhite: 0x261C,
  11915. pointingindexrightwhite: 0x261E,
  11916. pointingindexupwhite: 0x261D,
  11917. pokatakana: 0x30DD,
  11918. poplathai: 0x0E1B,
  11919. postalmark: 0x3012,
  11920. postalmarkface: 0x3020,
  11921. pparen: 0x24AB,
  11922. precedes: 0x227A,
  11923. prescription: 0x211E,
  11924. primemod: 0x02B9,
  11925. primereversed: 0x2035,
  11926. product: 0x220F,
  11927. projective: 0x2305,
  11928. prolongedkana: 0x30FC,
  11929. propellor: 0x2318,
  11930. propersubset: 0x2282,
  11931. propersuperset: 0x2283,
  11932. proportion: 0x2237,
  11933. proportional: 0x221D,
  11934. psi: 0x03C8,
  11935. psicyrillic: 0x0471,
  11936. psilipneumatacyrilliccmb: 0x0486,
  11937. pssquare: 0x33B0,
  11938. puhiragana: 0x3077,
  11939. pukatakana: 0x30D7,
  11940. pvsquare: 0x33B4,
  11941. pwsquare: 0x33BA,
  11942. q: 0x0071,
  11943. qadeva: 0x0958,
  11944. qadmahebrew: 0x05A8,
  11945. qafarabic: 0x0642,
  11946. qaffinalarabic: 0xFED6,
  11947. qafinitialarabic: 0xFED7,
  11948. qafmedialarabic: 0xFED8,
  11949. qamats: 0x05B8,
  11950. qamats10: 0x05B8,
  11951. qamats1a: 0x05B8,
  11952. qamats1c: 0x05B8,
  11953. qamats27: 0x05B8,
  11954. qamats29: 0x05B8,
  11955. qamats33: 0x05B8,
  11956. qamatsde: 0x05B8,
  11957. qamatshebrew: 0x05B8,
  11958. qamatsnarrowhebrew: 0x05B8,
  11959. qamatsqatanhebrew: 0x05B8,
  11960. qamatsqatannarrowhebrew: 0x05B8,
  11961. qamatsqatanquarterhebrew: 0x05B8,
  11962. qamatsqatanwidehebrew: 0x05B8,
  11963. qamatsquarterhebrew: 0x05B8,
  11964. qamatswidehebrew: 0x05B8,
  11965. qarneyparahebrew: 0x059F,
  11966. qbopomofo: 0x3111,
  11967. qcircle: 0x24E0,
  11968. qhook: 0x02A0,
  11969. qmonospace: 0xFF51,
  11970. qof: 0x05E7,
  11971. qofdagesh: 0xFB47,
  11972. qofdageshhebrew: 0xFB47,
  11973. qofhebrew: 0x05E7,
  11974. qparen: 0x24AC,
  11975. quarternote: 0x2669,
  11976. qubuts: 0x05BB,
  11977. qubuts18: 0x05BB,
  11978. qubuts25: 0x05BB,
  11979. qubuts31: 0x05BB,
  11980. qubutshebrew: 0x05BB,
  11981. qubutsnarrowhebrew: 0x05BB,
  11982. qubutsquarterhebrew: 0x05BB,
  11983. qubutswidehebrew: 0x05BB,
  11984. question: 0x003F,
  11985. questionarabic: 0x061F,
  11986. questionarmenian: 0x055E,
  11987. questiondown: 0x00BF,
  11988. questiondownsmall: 0xF7BF,
  11989. questiongreek: 0x037E,
  11990. questionmonospace: 0xFF1F,
  11991. questionsmall: 0xF73F,
  11992. quotedbl: 0x0022,
  11993. quotedblbase: 0x201E,
  11994. quotedblleft: 0x201C,
  11995. quotedblmonospace: 0xFF02,
  11996. quotedblprime: 0x301E,
  11997. quotedblprimereversed: 0x301D,
  11998. quotedblright: 0x201D,
  11999. quoteleft: 0x2018,
  12000. quoteleftreversed: 0x201B,
  12001. quotereversed: 0x201B,
  12002. quoteright: 0x2019,
  12003. quoterightn: 0x0149,
  12004. quotesinglbase: 0x201A,
  12005. quotesingle: 0x0027,
  12006. quotesinglemonospace: 0xFF07,
  12007. r: 0x0072,
  12008. raarmenian: 0x057C,
  12009. rabengali: 0x09B0,
  12010. racute: 0x0155,
  12011. radeva: 0x0930,
  12012. radical: 0x221A,
  12013. radicalex: 0xF8E5,
  12014. radoverssquare: 0x33AE,
  12015. radoverssquaredsquare: 0x33AF,
  12016. radsquare: 0x33AD,
  12017. rafe: 0x05BF,
  12018. rafehebrew: 0x05BF,
  12019. ragujarati: 0x0AB0,
  12020. ragurmukhi: 0x0A30,
  12021. rahiragana: 0x3089,
  12022. rakatakana: 0x30E9,
  12023. rakatakanahalfwidth: 0xFF97,
  12024. ralowerdiagonalbengali: 0x09F1,
  12025. ramiddlediagonalbengali: 0x09F0,
  12026. ramshorn: 0x0264,
  12027. ratio: 0x2236,
  12028. rbopomofo: 0x3116,
  12029. rcaron: 0x0159,
  12030. rcedilla: 0x0157,
  12031. rcircle: 0x24E1,
  12032. rcommaaccent: 0x0157,
  12033. rdblgrave: 0x0211,
  12034. rdotaccent: 0x1E59,
  12035. rdotbelow: 0x1E5B,
  12036. rdotbelowmacron: 0x1E5D,
  12037. referencemark: 0x203B,
  12038. reflexsubset: 0x2286,
  12039. reflexsuperset: 0x2287,
  12040. registered: 0x00AE,
  12041. registersans: 0xF8E8,
  12042. registerserif: 0xF6DA,
  12043. reharabic: 0x0631,
  12044. reharmenian: 0x0580,
  12045. rehfinalarabic: 0xFEAE,
  12046. rehiragana: 0x308C,
  12047. rekatakana: 0x30EC,
  12048. rekatakanahalfwidth: 0xFF9A,
  12049. resh: 0x05E8,
  12050. reshdageshhebrew: 0xFB48,
  12051. reshhebrew: 0x05E8,
  12052. reversedtilde: 0x223D,
  12053. reviahebrew: 0x0597,
  12054. reviamugrashhebrew: 0x0597,
  12055. revlogicalnot: 0x2310,
  12056. rfishhook: 0x027E,
  12057. rfishhookreversed: 0x027F,
  12058. rhabengali: 0x09DD,
  12059. rhadeva: 0x095D,
  12060. rho: 0x03C1,
  12061. rhook: 0x027D,
  12062. rhookturned: 0x027B,
  12063. rhookturnedsuperior: 0x02B5,
  12064. rhosymbolgreek: 0x03F1,
  12065. rhotichookmod: 0x02DE,
  12066. rieulacirclekorean: 0x3271,
  12067. rieulaparenkorean: 0x3211,
  12068. rieulcirclekorean: 0x3263,
  12069. rieulhieuhkorean: 0x3140,
  12070. rieulkiyeokkorean: 0x313A,
  12071. rieulkiyeoksioskorean: 0x3169,
  12072. rieulkorean: 0x3139,
  12073. rieulmieumkorean: 0x313B,
  12074. rieulpansioskorean: 0x316C,
  12075. rieulparenkorean: 0x3203,
  12076. rieulphieuphkorean: 0x313F,
  12077. rieulpieupkorean: 0x313C,
  12078. rieulpieupsioskorean: 0x316B,
  12079. rieulsioskorean: 0x313D,
  12080. rieulthieuthkorean: 0x313E,
  12081. rieultikeutkorean: 0x316A,
  12082. rieulyeorinhieuhkorean: 0x316D,
  12083. rightangle: 0x221F,
  12084. righttackbelowcmb: 0x0319,
  12085. righttriangle: 0x22BF,
  12086. rihiragana: 0x308A,
  12087. rikatakana: 0x30EA,
  12088. rikatakanahalfwidth: 0xFF98,
  12089. ring: 0x02DA,
  12090. ringbelowcmb: 0x0325,
  12091. ringcmb: 0x030A,
  12092. ringhalfleft: 0x02BF,
  12093. ringhalfleftarmenian: 0x0559,
  12094. ringhalfleftbelowcmb: 0x031C,
  12095. ringhalfleftcentered: 0x02D3,
  12096. ringhalfright: 0x02BE,
  12097. ringhalfrightbelowcmb: 0x0339,
  12098. ringhalfrightcentered: 0x02D2,
  12099. rinvertedbreve: 0x0213,
  12100. rittorusquare: 0x3351,
  12101. rlinebelow: 0x1E5F,
  12102. rlongleg: 0x027C,
  12103. rlonglegturned: 0x027A,
  12104. rmonospace: 0xFF52,
  12105. rohiragana: 0x308D,
  12106. rokatakana: 0x30ED,
  12107. rokatakanahalfwidth: 0xFF9B,
  12108. roruathai: 0x0E23,
  12109. rparen: 0x24AD,
  12110. rrabengali: 0x09DC,
  12111. rradeva: 0x0931,
  12112. rragurmukhi: 0x0A5C,
  12113. rreharabic: 0x0691,
  12114. rrehfinalarabic: 0xFB8D,
  12115. rrvocalicbengali: 0x09E0,
  12116. rrvocalicdeva: 0x0960,
  12117. rrvocalicgujarati: 0x0AE0,
  12118. rrvocalicvowelsignbengali: 0x09C4,
  12119. rrvocalicvowelsigndeva: 0x0944,
  12120. rrvocalicvowelsigngujarati: 0x0AC4,
  12121. rsuperior: 0xF6F1,
  12122. rtblock: 0x2590,
  12123. rturned: 0x0279,
  12124. rturnedsuperior: 0x02B4,
  12125. ruhiragana: 0x308B,
  12126. rukatakana: 0x30EB,
  12127. rukatakanahalfwidth: 0xFF99,
  12128. rupeemarkbengali: 0x09F2,
  12129. rupeesignbengali: 0x09F3,
  12130. rupiah: 0xF6DD,
  12131. ruthai: 0x0E24,
  12132. rvocalicbengali: 0x098B,
  12133. rvocalicdeva: 0x090B,
  12134. rvocalicgujarati: 0x0A8B,
  12135. rvocalicvowelsignbengali: 0x09C3,
  12136. rvocalicvowelsigndeva: 0x0943,
  12137. rvocalicvowelsigngujarati: 0x0AC3,
  12138. s: 0x0073,
  12139. sabengali: 0x09B8,
  12140. sacute: 0x015B,
  12141. sacutedotaccent: 0x1E65,
  12142. sadarabic: 0x0635,
  12143. sadeva: 0x0938,
  12144. sadfinalarabic: 0xFEBA,
  12145. sadinitialarabic: 0xFEBB,
  12146. sadmedialarabic: 0xFEBC,
  12147. sagujarati: 0x0AB8,
  12148. sagurmukhi: 0x0A38,
  12149. sahiragana: 0x3055,
  12150. sakatakana: 0x30B5,
  12151. sakatakanahalfwidth: 0xFF7B,
  12152. sallallahoualayhewasallamarabic: 0xFDFA,
  12153. samekh: 0x05E1,
  12154. samekhdagesh: 0xFB41,
  12155. samekhdageshhebrew: 0xFB41,
  12156. samekhhebrew: 0x05E1,
  12157. saraaathai: 0x0E32,
  12158. saraaethai: 0x0E41,
  12159. saraaimaimalaithai: 0x0E44,
  12160. saraaimaimuanthai: 0x0E43,
  12161. saraamthai: 0x0E33,
  12162. saraathai: 0x0E30,
  12163. saraethai: 0x0E40,
  12164. saraiileftthai: 0xF886,
  12165. saraiithai: 0x0E35,
  12166. saraileftthai: 0xF885,
  12167. saraithai: 0x0E34,
  12168. saraothai: 0x0E42,
  12169. saraueeleftthai: 0xF888,
  12170. saraueethai: 0x0E37,
  12171. saraueleftthai: 0xF887,
  12172. sarauethai: 0x0E36,
  12173. sarauthai: 0x0E38,
  12174. sarauuthai: 0x0E39,
  12175. sbopomofo: 0x3119,
  12176. scaron: 0x0161,
  12177. scarondotaccent: 0x1E67,
  12178. scedilla: 0x015F,
  12179. schwa: 0x0259,
  12180. schwacyrillic: 0x04D9,
  12181. schwadieresiscyrillic: 0x04DB,
  12182. schwahook: 0x025A,
  12183. scircle: 0x24E2,
  12184. scircumflex: 0x015D,
  12185. scommaaccent: 0x0219,
  12186. sdotaccent: 0x1E61,
  12187. sdotbelow: 0x1E63,
  12188. sdotbelowdotaccent: 0x1E69,
  12189. seagullbelowcmb: 0x033C,
  12190. second: 0x2033,
  12191. secondtonechinese: 0x02CA,
  12192. section: 0x00A7,
  12193. seenarabic: 0x0633,
  12194. seenfinalarabic: 0xFEB2,
  12195. seeninitialarabic: 0xFEB3,
  12196. seenmedialarabic: 0xFEB4,
  12197. segol: 0x05B6,
  12198. segol13: 0x05B6,
  12199. segol1f: 0x05B6,
  12200. segol2c: 0x05B6,
  12201. segolhebrew: 0x05B6,
  12202. segolnarrowhebrew: 0x05B6,
  12203. segolquarterhebrew: 0x05B6,
  12204. segoltahebrew: 0x0592,
  12205. segolwidehebrew: 0x05B6,
  12206. seharmenian: 0x057D,
  12207. sehiragana: 0x305B,
  12208. sekatakana: 0x30BB,
  12209. sekatakanahalfwidth: 0xFF7E,
  12210. semicolon: 0x003B,
  12211. semicolonarabic: 0x061B,
  12212. semicolonmonospace: 0xFF1B,
  12213. semicolonsmall: 0xFE54,
  12214. semivoicedmarkkana: 0x309C,
  12215. semivoicedmarkkanahalfwidth: 0xFF9F,
  12216. sentisquare: 0x3322,
  12217. sentosquare: 0x3323,
  12218. seven: 0x0037,
  12219. sevenarabic: 0x0667,
  12220. sevenbengali: 0x09ED,
  12221. sevencircle: 0x2466,
  12222. sevencircleinversesansserif: 0x2790,
  12223. sevendeva: 0x096D,
  12224. seveneighths: 0x215E,
  12225. sevengujarati: 0x0AED,
  12226. sevengurmukhi: 0x0A6D,
  12227. sevenhackarabic: 0x0667,
  12228. sevenhangzhou: 0x3027,
  12229. sevenideographicparen: 0x3226,
  12230. seveninferior: 0x2087,
  12231. sevenmonospace: 0xFF17,
  12232. sevenoldstyle: 0xF737,
  12233. sevenparen: 0x247A,
  12234. sevenperiod: 0x248E,
  12235. sevenpersian: 0x06F7,
  12236. sevenroman: 0x2176,
  12237. sevensuperior: 0x2077,
  12238. seventeencircle: 0x2470,
  12239. seventeenparen: 0x2484,
  12240. seventeenperiod: 0x2498,
  12241. seventhai: 0x0E57,
  12242. sfthyphen: 0x00AD,
  12243. shaarmenian: 0x0577,
  12244. shabengali: 0x09B6,
  12245. shacyrillic: 0x0448,
  12246. shaddaarabic: 0x0651,
  12247. shaddadammaarabic: 0xFC61,
  12248. shaddadammatanarabic: 0xFC5E,
  12249. shaddafathaarabic: 0xFC60,
  12250. shaddakasraarabic: 0xFC62,
  12251. shaddakasratanarabic: 0xFC5F,
  12252. shade: 0x2592,
  12253. shadedark: 0x2593,
  12254. shadelight: 0x2591,
  12255. shademedium: 0x2592,
  12256. shadeva: 0x0936,
  12257. shagujarati: 0x0AB6,
  12258. shagurmukhi: 0x0A36,
  12259. shalshelethebrew: 0x0593,
  12260. shbopomofo: 0x3115,
  12261. shchacyrillic: 0x0449,
  12262. sheenarabic: 0x0634,
  12263. sheenfinalarabic: 0xFEB6,
  12264. sheeninitialarabic: 0xFEB7,
  12265. sheenmedialarabic: 0xFEB8,
  12266. sheicoptic: 0x03E3,
  12267. sheqel: 0x20AA,
  12268. sheqelhebrew: 0x20AA,
  12269. sheva: 0x05B0,
  12270. sheva115: 0x05B0,
  12271. sheva15: 0x05B0,
  12272. sheva22: 0x05B0,
  12273. sheva2e: 0x05B0,
  12274. shevahebrew: 0x05B0,
  12275. shevanarrowhebrew: 0x05B0,
  12276. shevaquarterhebrew: 0x05B0,
  12277. shevawidehebrew: 0x05B0,
  12278. shhacyrillic: 0x04BB,
  12279. shimacoptic: 0x03ED,
  12280. shin: 0x05E9,
  12281. shindagesh: 0xFB49,
  12282. shindageshhebrew: 0xFB49,
  12283. shindageshshindot: 0xFB2C,
  12284. shindageshshindothebrew: 0xFB2C,
  12285. shindageshsindot: 0xFB2D,
  12286. shindageshsindothebrew: 0xFB2D,
  12287. shindothebrew: 0x05C1,
  12288. shinhebrew: 0x05E9,
  12289. shinshindot: 0xFB2A,
  12290. shinshindothebrew: 0xFB2A,
  12291. shinsindot: 0xFB2B,
  12292. shinsindothebrew: 0xFB2B,
  12293. shook: 0x0282,
  12294. sigma: 0x03C3,
  12295. sigma1: 0x03C2,
  12296. sigmafinal: 0x03C2,
  12297. sigmalunatesymbolgreek: 0x03F2,
  12298. sihiragana: 0x3057,
  12299. sikatakana: 0x30B7,
  12300. sikatakanahalfwidth: 0xFF7C,
  12301. siluqhebrew: 0x05BD,
  12302. siluqlefthebrew: 0x05BD,
  12303. similar: 0x223C,
  12304. sindothebrew: 0x05C2,
  12305. siosacirclekorean: 0x3274,
  12306. siosaparenkorean: 0x3214,
  12307. sioscieuckorean: 0x317E,
  12308. sioscirclekorean: 0x3266,
  12309. sioskiyeokkorean: 0x317A,
  12310. sioskorean: 0x3145,
  12311. siosnieunkorean: 0x317B,
  12312. siosparenkorean: 0x3206,
  12313. siospieupkorean: 0x317D,
  12314. siostikeutkorean: 0x317C,
  12315. six: 0x0036,
  12316. sixarabic: 0x0666,
  12317. sixbengali: 0x09EC,
  12318. sixcircle: 0x2465,
  12319. sixcircleinversesansserif: 0x278F,
  12320. sixdeva: 0x096C,
  12321. sixgujarati: 0x0AEC,
  12322. sixgurmukhi: 0x0A6C,
  12323. sixhackarabic: 0x0666,
  12324. sixhangzhou: 0x3026,
  12325. sixideographicparen: 0x3225,
  12326. sixinferior: 0x2086,
  12327. sixmonospace: 0xFF16,
  12328. sixoldstyle: 0xF736,
  12329. sixparen: 0x2479,
  12330. sixperiod: 0x248D,
  12331. sixpersian: 0x06F6,
  12332. sixroman: 0x2175,
  12333. sixsuperior: 0x2076,
  12334. sixteencircle: 0x246F,
  12335. sixteencurrencydenominatorbengali: 0x09F9,
  12336. sixteenparen: 0x2483,
  12337. sixteenperiod: 0x2497,
  12338. sixthai: 0x0E56,
  12339. slash: 0x002F,
  12340. slashmonospace: 0xFF0F,
  12341. slong: 0x017F,
  12342. slongdotaccent: 0x1E9B,
  12343. smileface: 0x263A,
  12344. smonospace: 0xFF53,
  12345. sofpasuqhebrew: 0x05C3,
  12346. softhyphen: 0x00AD,
  12347. softsigncyrillic: 0x044C,
  12348. sohiragana: 0x305D,
  12349. sokatakana: 0x30BD,
  12350. sokatakanahalfwidth: 0xFF7F,
  12351. soliduslongoverlaycmb: 0x0338,
  12352. solidusshortoverlaycmb: 0x0337,
  12353. sorusithai: 0x0E29,
  12354. sosalathai: 0x0E28,
  12355. sosothai: 0x0E0B,
  12356. sosuathai: 0x0E2A,
  12357. space: 0x0020,
  12358. spacehackarabic: 0x0020,
  12359. spade: 0x2660,
  12360. spadesuitblack: 0x2660,
  12361. spadesuitwhite: 0x2664,
  12362. sparen: 0x24AE,
  12363. squarebelowcmb: 0x033B,
  12364. squarecc: 0x33C4,
  12365. squarecm: 0x339D,
  12366. squarediagonalcrosshatchfill: 0x25A9,
  12367. squarehorizontalfill: 0x25A4,
  12368. squarekg: 0x338F,
  12369. squarekm: 0x339E,
  12370. squarekmcapital: 0x33CE,
  12371. squareln: 0x33D1,
  12372. squarelog: 0x33D2,
  12373. squaremg: 0x338E,
  12374. squaremil: 0x33D5,
  12375. squaremm: 0x339C,
  12376. squaremsquared: 0x33A1,
  12377. squareorthogonalcrosshatchfill: 0x25A6,
  12378. squareupperlefttolowerrightfill: 0x25A7,
  12379. squareupperrighttolowerleftfill: 0x25A8,
  12380. squareverticalfill: 0x25A5,
  12381. squarewhitewithsmallblack: 0x25A3,
  12382. srsquare: 0x33DB,
  12383. ssabengali: 0x09B7,
  12384. ssadeva: 0x0937,
  12385. ssagujarati: 0x0AB7,
  12386. ssangcieuckorean: 0x3149,
  12387. ssanghieuhkorean: 0x3185,
  12388. ssangieungkorean: 0x3180,
  12389. ssangkiyeokkorean: 0x3132,
  12390. ssangnieunkorean: 0x3165,
  12391. ssangpieupkorean: 0x3143,
  12392. ssangsioskorean: 0x3146,
  12393. ssangtikeutkorean: 0x3138,
  12394. ssuperior: 0xF6F2,
  12395. sterling: 0x00A3,
  12396. sterlingmonospace: 0xFFE1,
  12397. strokelongoverlaycmb: 0x0336,
  12398. strokeshortoverlaycmb: 0x0335,
  12399. subset: 0x2282,
  12400. subsetnotequal: 0x228A,
  12401. subsetorequal: 0x2286,
  12402. succeeds: 0x227B,
  12403. suchthat: 0x220B,
  12404. suhiragana: 0x3059,
  12405. sukatakana: 0x30B9,
  12406. sukatakanahalfwidth: 0xFF7D,
  12407. sukunarabic: 0x0652,
  12408. summation: 0x2211,
  12409. sun: 0x263C,
  12410. superset: 0x2283,
  12411. supersetnotequal: 0x228B,
  12412. supersetorequal: 0x2287,
  12413. svsquare: 0x33DC,
  12414. syouwaerasquare: 0x337C,
  12415. t: 0x0074,
  12416. tabengali: 0x09A4,
  12417. tackdown: 0x22A4,
  12418. tackleft: 0x22A3,
  12419. tadeva: 0x0924,
  12420. tagujarati: 0x0AA4,
  12421. tagurmukhi: 0x0A24,
  12422. taharabic: 0x0637,
  12423. tahfinalarabic: 0xFEC2,
  12424. tahinitialarabic: 0xFEC3,
  12425. tahiragana: 0x305F,
  12426. tahmedialarabic: 0xFEC4,
  12427. taisyouerasquare: 0x337D,
  12428. takatakana: 0x30BF,
  12429. takatakanahalfwidth: 0xFF80,
  12430. tatweelarabic: 0x0640,
  12431. tau: 0x03C4,
  12432. tav: 0x05EA,
  12433. tavdages: 0xFB4A,
  12434. tavdagesh: 0xFB4A,
  12435. tavdageshhebrew: 0xFB4A,
  12436. tavhebrew: 0x05EA,
  12437. tbar: 0x0167,
  12438. tbopomofo: 0x310A,
  12439. tcaron: 0x0165,
  12440. tccurl: 0x02A8,
  12441. tcedilla: 0x0163,
  12442. tcheharabic: 0x0686,
  12443. tchehfinalarabic: 0xFB7B,
  12444. tchehinitialarabic: 0xFB7C,
  12445. tchehmedialarabic: 0xFB7D,
  12446. tcircle: 0x24E3,
  12447. tcircumflexbelow: 0x1E71,
  12448. tcommaaccent: 0x0163,
  12449. tdieresis: 0x1E97,
  12450. tdotaccent: 0x1E6B,
  12451. tdotbelow: 0x1E6D,
  12452. tecyrillic: 0x0442,
  12453. tedescendercyrillic: 0x04AD,
  12454. teharabic: 0x062A,
  12455. tehfinalarabic: 0xFE96,
  12456. tehhahinitialarabic: 0xFCA2,
  12457. tehhahisolatedarabic: 0xFC0C,
  12458. tehinitialarabic: 0xFE97,
  12459. tehiragana: 0x3066,
  12460. tehjeeminitialarabic: 0xFCA1,
  12461. tehjeemisolatedarabic: 0xFC0B,
  12462. tehmarbutaarabic: 0x0629,
  12463. tehmarbutafinalarabic: 0xFE94,
  12464. tehmedialarabic: 0xFE98,
  12465. tehmeeminitialarabic: 0xFCA4,
  12466. tehmeemisolatedarabic: 0xFC0E,
  12467. tehnoonfinalarabic: 0xFC73,
  12468. tekatakana: 0x30C6,
  12469. tekatakanahalfwidth: 0xFF83,
  12470. telephone: 0x2121,
  12471. telephoneblack: 0x260E,
  12472. telishagedolahebrew: 0x05A0,
  12473. telishaqetanahebrew: 0x05A9,
  12474. tencircle: 0x2469,
  12475. tenideographicparen: 0x3229,
  12476. tenparen: 0x247D,
  12477. tenperiod: 0x2491,
  12478. tenroman: 0x2179,
  12479. tesh: 0x02A7,
  12480. tet: 0x05D8,
  12481. tetdagesh: 0xFB38,
  12482. tetdageshhebrew: 0xFB38,
  12483. tethebrew: 0x05D8,
  12484. tetsecyrillic: 0x04B5,
  12485. tevirhebrew: 0x059B,
  12486. tevirlefthebrew: 0x059B,
  12487. thabengali: 0x09A5,
  12488. thadeva: 0x0925,
  12489. thagujarati: 0x0AA5,
  12490. thagurmukhi: 0x0A25,
  12491. thalarabic: 0x0630,
  12492. thalfinalarabic: 0xFEAC,
  12493. thanthakhatlowleftthai: 0xF898,
  12494. thanthakhatlowrightthai: 0xF897,
  12495. thanthakhatthai: 0x0E4C,
  12496. thanthakhatupperleftthai: 0xF896,
  12497. theharabic: 0x062B,
  12498. thehfinalarabic: 0xFE9A,
  12499. thehinitialarabic: 0xFE9B,
  12500. thehmedialarabic: 0xFE9C,
  12501. thereexists: 0x2203,
  12502. therefore: 0x2234,
  12503. theta: 0x03B8,
  12504. theta1: 0x03D1,
  12505. thetasymbolgreek: 0x03D1,
  12506. thieuthacirclekorean: 0x3279,
  12507. thieuthaparenkorean: 0x3219,
  12508. thieuthcirclekorean: 0x326B,
  12509. thieuthkorean: 0x314C,
  12510. thieuthparenkorean: 0x320B,
  12511. thirteencircle: 0x246C,
  12512. thirteenparen: 0x2480,
  12513. thirteenperiod: 0x2494,
  12514. thonangmonthothai: 0x0E11,
  12515. thook: 0x01AD,
  12516. thophuthaothai: 0x0E12,
  12517. thorn: 0x00FE,
  12518. thothahanthai: 0x0E17,
  12519. thothanthai: 0x0E10,
  12520. thothongthai: 0x0E18,
  12521. thothungthai: 0x0E16,
  12522. thousandcyrillic: 0x0482,
  12523. thousandsseparatorarabic: 0x066C,
  12524. thousandsseparatorpersian: 0x066C,
  12525. three: 0x0033,
  12526. threearabic: 0x0663,
  12527. threebengali: 0x09E9,
  12528. threecircle: 0x2462,
  12529. threecircleinversesansserif: 0x278C,
  12530. threedeva: 0x0969,
  12531. threeeighths: 0x215C,
  12532. threegujarati: 0x0AE9,
  12533. threegurmukhi: 0x0A69,
  12534. threehackarabic: 0x0663,
  12535. threehangzhou: 0x3023,
  12536. threeideographicparen: 0x3222,
  12537. threeinferior: 0x2083,
  12538. threemonospace: 0xFF13,
  12539. threenumeratorbengali: 0x09F6,
  12540. threeoldstyle: 0xF733,
  12541. threeparen: 0x2476,
  12542. threeperiod: 0x248A,
  12543. threepersian: 0x06F3,
  12544. threequarters: 0x00BE,
  12545. threequartersemdash: 0xF6DE,
  12546. threeroman: 0x2172,
  12547. threesuperior: 0x00B3,
  12548. threethai: 0x0E53,
  12549. thzsquare: 0x3394,
  12550. tihiragana: 0x3061,
  12551. tikatakana: 0x30C1,
  12552. tikatakanahalfwidth: 0xFF81,
  12553. tikeutacirclekorean: 0x3270,
  12554. tikeutaparenkorean: 0x3210,
  12555. tikeutcirclekorean: 0x3262,
  12556. tikeutkorean: 0x3137,
  12557. tikeutparenkorean: 0x3202,
  12558. tilde: 0x02DC,
  12559. tildebelowcmb: 0x0330,
  12560. tildecmb: 0x0303,
  12561. tildecomb: 0x0303,
  12562. tildedoublecmb: 0x0360,
  12563. tildeoperator: 0x223C,
  12564. tildeoverlaycmb: 0x0334,
  12565. tildeverticalcmb: 0x033E,
  12566. timescircle: 0x2297,
  12567. tipehahebrew: 0x0596,
  12568. tipehalefthebrew: 0x0596,
  12569. tippigurmukhi: 0x0A70,
  12570. titlocyrilliccmb: 0x0483,
  12571. tiwnarmenian: 0x057F,
  12572. tlinebelow: 0x1E6F,
  12573. tmonospace: 0xFF54,
  12574. toarmenian: 0x0569,
  12575. tohiragana: 0x3068,
  12576. tokatakana: 0x30C8,
  12577. tokatakanahalfwidth: 0xFF84,
  12578. tonebarextrahighmod: 0x02E5,
  12579. tonebarextralowmod: 0x02E9,
  12580. tonebarhighmod: 0x02E6,
  12581. tonebarlowmod: 0x02E8,
  12582. tonebarmidmod: 0x02E7,
  12583. tonefive: 0x01BD,
  12584. tonesix: 0x0185,
  12585. tonetwo: 0x01A8,
  12586. tonos: 0x0384,
  12587. tonsquare: 0x3327,
  12588. topatakthai: 0x0E0F,
  12589. tortoiseshellbracketleft: 0x3014,
  12590. tortoiseshellbracketleftsmall: 0xFE5D,
  12591. tortoiseshellbracketleftvertical: 0xFE39,
  12592. tortoiseshellbracketright: 0x3015,
  12593. tortoiseshellbracketrightsmall: 0xFE5E,
  12594. tortoiseshellbracketrightvertical: 0xFE3A,
  12595. totaothai: 0x0E15,
  12596. tpalatalhook: 0x01AB,
  12597. tparen: 0x24AF,
  12598. trademark: 0x2122,
  12599. trademarksans: 0xF8EA,
  12600. trademarkserif: 0xF6DB,
  12601. tretroflexhook: 0x0288,
  12602. triagdn: 0x25BC,
  12603. triaglf: 0x25C4,
  12604. triagrt: 0x25BA,
  12605. triagup: 0x25B2,
  12606. ts: 0x02A6,
  12607. tsadi: 0x05E6,
  12608. tsadidagesh: 0xFB46,
  12609. tsadidageshhebrew: 0xFB46,
  12610. tsadihebrew: 0x05E6,
  12611. tsecyrillic: 0x0446,
  12612. tsere: 0x05B5,
  12613. tsere12: 0x05B5,
  12614. tsere1e: 0x05B5,
  12615. tsere2b: 0x05B5,
  12616. tserehebrew: 0x05B5,
  12617. tserenarrowhebrew: 0x05B5,
  12618. tserequarterhebrew: 0x05B5,
  12619. tserewidehebrew: 0x05B5,
  12620. tshecyrillic: 0x045B,
  12621. tsuperior: 0xF6F3,
  12622. ttabengali: 0x099F,
  12623. ttadeva: 0x091F,
  12624. ttagujarati: 0x0A9F,
  12625. ttagurmukhi: 0x0A1F,
  12626. tteharabic: 0x0679,
  12627. ttehfinalarabic: 0xFB67,
  12628. ttehinitialarabic: 0xFB68,
  12629. ttehmedialarabic: 0xFB69,
  12630. tthabengali: 0x09A0,
  12631. tthadeva: 0x0920,
  12632. tthagujarati: 0x0AA0,
  12633. tthagurmukhi: 0x0A20,
  12634. tturned: 0x0287,
  12635. tuhiragana: 0x3064,
  12636. tukatakana: 0x30C4,
  12637. tukatakanahalfwidth: 0xFF82,
  12638. tusmallhiragana: 0x3063,
  12639. tusmallkatakana: 0x30C3,
  12640. tusmallkatakanahalfwidth: 0xFF6F,
  12641. twelvecircle: 0x246B,
  12642. twelveparen: 0x247F,
  12643. twelveperiod: 0x2493,
  12644. twelveroman: 0x217B,
  12645. twentycircle: 0x2473,
  12646. twentyhangzhou: 0x5344,
  12647. twentyparen: 0x2487,
  12648. twentyperiod: 0x249B,
  12649. two: 0x0032,
  12650. twoarabic: 0x0662,
  12651. twobengali: 0x09E8,
  12652. twocircle: 0x2461,
  12653. twocircleinversesansserif: 0x278B,
  12654. twodeva: 0x0968,
  12655. twodotenleader: 0x2025,
  12656. twodotleader: 0x2025,
  12657. twodotleadervertical: 0xFE30,
  12658. twogujarati: 0x0AE8,
  12659. twogurmukhi: 0x0A68,
  12660. twohackarabic: 0x0662,
  12661. twohangzhou: 0x3022,
  12662. twoideographicparen: 0x3221,
  12663. twoinferior: 0x2082,
  12664. twomonospace: 0xFF12,
  12665. twonumeratorbengali: 0x09F5,
  12666. twooldstyle: 0xF732,
  12667. twoparen: 0x2475,
  12668. twoperiod: 0x2489,
  12669. twopersian: 0x06F2,
  12670. tworoman: 0x2171,
  12671. twostroke: 0x01BB,
  12672. twosuperior: 0x00B2,
  12673. twothai: 0x0E52,
  12674. twothirds: 0x2154,
  12675. u: 0x0075,
  12676. uacute: 0x00FA,
  12677. ubar: 0x0289,
  12678. ubengali: 0x0989,
  12679. ubopomofo: 0x3128,
  12680. ubreve: 0x016D,
  12681. ucaron: 0x01D4,
  12682. ucircle: 0x24E4,
  12683. ucircumflex: 0x00FB,
  12684. ucircumflexbelow: 0x1E77,
  12685. ucyrillic: 0x0443,
  12686. udattadeva: 0x0951,
  12687. udblacute: 0x0171,
  12688. udblgrave: 0x0215,
  12689. udeva: 0x0909,
  12690. udieresis: 0x00FC,
  12691. udieresisacute: 0x01D8,
  12692. udieresisbelow: 0x1E73,
  12693. udieresiscaron: 0x01DA,
  12694. udieresiscyrillic: 0x04F1,
  12695. udieresisgrave: 0x01DC,
  12696. udieresismacron: 0x01D6,
  12697. udotbelow: 0x1EE5,
  12698. ugrave: 0x00F9,
  12699. ugujarati: 0x0A89,
  12700. ugurmukhi: 0x0A09,
  12701. uhiragana: 0x3046,
  12702. uhookabove: 0x1EE7,
  12703. uhorn: 0x01B0,
  12704. uhornacute: 0x1EE9,
  12705. uhorndotbelow: 0x1EF1,
  12706. uhorngrave: 0x1EEB,
  12707. uhornhookabove: 0x1EED,
  12708. uhorntilde: 0x1EEF,
  12709. uhungarumlaut: 0x0171,
  12710. uhungarumlautcyrillic: 0x04F3,
  12711. uinvertedbreve: 0x0217,
  12712. ukatakana: 0x30A6,
  12713. ukatakanahalfwidth: 0xFF73,
  12714. ukcyrillic: 0x0479,
  12715. ukorean: 0x315C,
  12716. umacron: 0x016B,
  12717. umacroncyrillic: 0x04EF,
  12718. umacrondieresis: 0x1E7B,
  12719. umatragurmukhi: 0x0A41,
  12720. umonospace: 0xFF55,
  12721. underscore: 0x005F,
  12722. underscoredbl: 0x2017,
  12723. underscoremonospace: 0xFF3F,
  12724. underscorevertical: 0xFE33,
  12725. underscorewavy: 0xFE4F,
  12726. union: 0x222A,
  12727. universal: 0x2200,
  12728. uogonek: 0x0173,
  12729. uparen: 0x24B0,
  12730. upblock: 0x2580,
  12731. upperdothebrew: 0x05C4,
  12732. upsilon: 0x03C5,
  12733. upsilondieresis: 0x03CB,
  12734. upsilondieresistonos: 0x03B0,
  12735. upsilonlatin: 0x028A,
  12736. upsilontonos: 0x03CD,
  12737. uptackbelowcmb: 0x031D,
  12738. uptackmod: 0x02D4,
  12739. uragurmukhi: 0x0A73,
  12740. uring: 0x016F,
  12741. ushortcyrillic: 0x045E,
  12742. usmallhiragana: 0x3045,
  12743. usmallkatakana: 0x30A5,
  12744. usmallkatakanahalfwidth: 0xFF69,
  12745. ustraightcyrillic: 0x04AF,
  12746. ustraightstrokecyrillic: 0x04B1,
  12747. utilde: 0x0169,
  12748. utildeacute: 0x1E79,
  12749. utildebelow: 0x1E75,
  12750. uubengali: 0x098A,
  12751. uudeva: 0x090A,
  12752. uugujarati: 0x0A8A,
  12753. uugurmukhi: 0x0A0A,
  12754. uumatragurmukhi: 0x0A42,
  12755. uuvowelsignbengali: 0x09C2,
  12756. uuvowelsigndeva: 0x0942,
  12757. uuvowelsigngujarati: 0x0AC2,
  12758. uvowelsignbengali: 0x09C1,
  12759. uvowelsigndeva: 0x0941,
  12760. uvowelsigngujarati: 0x0AC1,
  12761. v: 0x0076,
  12762. vadeva: 0x0935,
  12763. vagujarati: 0x0AB5,
  12764. vagurmukhi: 0x0A35,
  12765. vakatakana: 0x30F7,
  12766. vav: 0x05D5,
  12767. vavdagesh: 0xFB35,
  12768. vavdagesh65: 0xFB35,
  12769. vavdageshhebrew: 0xFB35,
  12770. vavhebrew: 0x05D5,
  12771. vavholam: 0xFB4B,
  12772. vavholamhebrew: 0xFB4B,
  12773. vavvavhebrew: 0x05F0,
  12774. vavyodhebrew: 0x05F1,
  12775. vcircle: 0x24E5,
  12776. vdotbelow: 0x1E7F,
  12777. vecyrillic: 0x0432,
  12778. veharabic: 0x06A4,
  12779. vehfinalarabic: 0xFB6B,
  12780. vehinitialarabic: 0xFB6C,
  12781. vehmedialarabic: 0xFB6D,
  12782. vekatakana: 0x30F9,
  12783. venus: 0x2640,
  12784. verticalbar: 0x007C,
  12785. verticallineabovecmb: 0x030D,
  12786. verticallinebelowcmb: 0x0329,
  12787. verticallinelowmod: 0x02CC,
  12788. verticallinemod: 0x02C8,
  12789. vewarmenian: 0x057E,
  12790. vhook: 0x028B,
  12791. vikatakana: 0x30F8,
  12792. viramabengali: 0x09CD,
  12793. viramadeva: 0x094D,
  12794. viramagujarati: 0x0ACD,
  12795. visargabengali: 0x0983,
  12796. visargadeva: 0x0903,
  12797. visargagujarati: 0x0A83,
  12798. vmonospace: 0xFF56,
  12799. voarmenian: 0x0578,
  12800. voicediterationhiragana: 0x309E,
  12801. voicediterationkatakana: 0x30FE,
  12802. voicedmarkkana: 0x309B,
  12803. voicedmarkkanahalfwidth: 0xFF9E,
  12804. vokatakana: 0x30FA,
  12805. vparen: 0x24B1,
  12806. vtilde: 0x1E7D,
  12807. vturned: 0x028C,
  12808. vuhiragana: 0x3094,
  12809. vukatakana: 0x30F4,
  12810. w: 0x0077,
  12811. wacute: 0x1E83,
  12812. waekorean: 0x3159,
  12813. wahiragana: 0x308F,
  12814. wakatakana: 0x30EF,
  12815. wakatakanahalfwidth: 0xFF9C,
  12816. wakorean: 0x3158,
  12817. wasmallhiragana: 0x308E,
  12818. wasmallkatakana: 0x30EE,
  12819. wattosquare: 0x3357,
  12820. wavedash: 0x301C,
  12821. wavyunderscorevertical: 0xFE34,
  12822. wawarabic: 0x0648,
  12823. wawfinalarabic: 0xFEEE,
  12824. wawhamzaabovearabic: 0x0624,
  12825. wawhamzaabovefinalarabic: 0xFE86,
  12826. wbsquare: 0x33DD,
  12827. wcircle: 0x24E6,
  12828. wcircumflex: 0x0175,
  12829. wdieresis: 0x1E85,
  12830. wdotaccent: 0x1E87,
  12831. wdotbelow: 0x1E89,
  12832. wehiragana: 0x3091,
  12833. weierstrass: 0x2118,
  12834. wekatakana: 0x30F1,
  12835. wekorean: 0x315E,
  12836. weokorean: 0x315D,
  12837. wgrave: 0x1E81,
  12838. whitebullet: 0x25E6,
  12839. whitecircle: 0x25CB,
  12840. whitecircleinverse: 0x25D9,
  12841. whitecornerbracketleft: 0x300E,
  12842. whitecornerbracketleftvertical: 0xFE43,
  12843. whitecornerbracketright: 0x300F,
  12844. whitecornerbracketrightvertical: 0xFE44,
  12845. whitediamond: 0x25C7,
  12846. whitediamondcontainingblacksmalldiamond: 0x25C8,
  12847. whitedownpointingsmalltriangle: 0x25BF,
  12848. whitedownpointingtriangle: 0x25BD,
  12849. whiteleftpointingsmalltriangle: 0x25C3,
  12850. whiteleftpointingtriangle: 0x25C1,
  12851. whitelenticularbracketleft: 0x3016,
  12852. whitelenticularbracketright: 0x3017,
  12853. whiterightpointingsmalltriangle: 0x25B9,
  12854. whiterightpointingtriangle: 0x25B7,
  12855. whitesmallsquare: 0x25AB,
  12856. whitesmilingface: 0x263A,
  12857. whitesquare: 0x25A1,
  12858. whitestar: 0x2606,
  12859. whitetelephone: 0x260F,
  12860. whitetortoiseshellbracketleft: 0x3018,
  12861. whitetortoiseshellbracketright: 0x3019,
  12862. whiteuppointingsmalltriangle: 0x25B5,
  12863. whiteuppointingtriangle: 0x25B3,
  12864. wihiragana: 0x3090,
  12865. wikatakana: 0x30F0,
  12866. wikorean: 0x315F,
  12867. wmonospace: 0xFF57,
  12868. wohiragana: 0x3092,
  12869. wokatakana: 0x30F2,
  12870. wokatakanahalfwidth: 0xFF66,
  12871. won: 0x20A9,
  12872. wonmonospace: 0xFFE6,
  12873. wowaenthai: 0x0E27,
  12874. wparen: 0x24B2,
  12875. wring: 0x1E98,
  12876. wsuperior: 0x02B7,
  12877. wturned: 0x028D,
  12878. wynn: 0x01BF,
  12879. x: 0x0078,
  12880. xabovecmb: 0x033D,
  12881. xbopomofo: 0x3112,
  12882. xcircle: 0x24E7,
  12883. xdieresis: 0x1E8D,
  12884. xdotaccent: 0x1E8B,
  12885. xeharmenian: 0x056D,
  12886. xi: 0x03BE,
  12887. xmonospace: 0xFF58,
  12888. xparen: 0x24B3,
  12889. xsuperior: 0x02E3,
  12890. y: 0x0079,
  12891. yaadosquare: 0x334E,
  12892. yabengali: 0x09AF,
  12893. yacute: 0x00FD,
  12894. yadeva: 0x092F,
  12895. yaekorean: 0x3152,
  12896. yagujarati: 0x0AAF,
  12897. yagurmukhi: 0x0A2F,
  12898. yahiragana: 0x3084,
  12899. yakatakana: 0x30E4,
  12900. yakatakanahalfwidth: 0xFF94,
  12901. yakorean: 0x3151,
  12902. yamakkanthai: 0x0E4E,
  12903. yasmallhiragana: 0x3083,
  12904. yasmallkatakana: 0x30E3,
  12905. yasmallkatakanahalfwidth: 0xFF6C,
  12906. yatcyrillic: 0x0463,
  12907. ycircle: 0x24E8,
  12908. ycircumflex: 0x0177,
  12909. ydieresis: 0x00FF,
  12910. ydotaccent: 0x1E8F,
  12911. ydotbelow: 0x1EF5,
  12912. yeharabic: 0x064A,
  12913. yehbarreearabic: 0x06D2,
  12914. yehbarreefinalarabic: 0xFBAF,
  12915. yehfinalarabic: 0xFEF2,
  12916. yehhamzaabovearabic: 0x0626,
  12917. yehhamzaabovefinalarabic: 0xFE8A,
  12918. yehhamzaaboveinitialarabic: 0xFE8B,
  12919. yehhamzaabovemedialarabic: 0xFE8C,
  12920. yehinitialarabic: 0xFEF3,
  12921. yehmedialarabic: 0xFEF4,
  12922. yehmeeminitialarabic: 0xFCDD,
  12923. yehmeemisolatedarabic: 0xFC58,
  12924. yehnoonfinalarabic: 0xFC94,
  12925. yehthreedotsbelowarabic: 0x06D1,
  12926. yekorean: 0x3156,
  12927. yen: 0x00A5,
  12928. yenmonospace: 0xFFE5,
  12929. yeokorean: 0x3155,
  12930. yeorinhieuhkorean: 0x3186,
  12931. yerahbenyomohebrew: 0x05AA,
  12932. yerahbenyomolefthebrew: 0x05AA,
  12933. yericyrillic: 0x044B,
  12934. yerudieresiscyrillic: 0x04F9,
  12935. yesieungkorean: 0x3181,
  12936. yesieungpansioskorean: 0x3183,
  12937. yesieungsioskorean: 0x3182,
  12938. yetivhebrew: 0x059A,
  12939. ygrave: 0x1EF3,
  12940. yhook: 0x01B4,
  12941. yhookabove: 0x1EF7,
  12942. yiarmenian: 0x0575,
  12943. yicyrillic: 0x0457,
  12944. yikorean: 0x3162,
  12945. yinyang: 0x262F,
  12946. yiwnarmenian: 0x0582,
  12947. ymonospace: 0xFF59,
  12948. yod: 0x05D9,
  12949. yoddagesh: 0xFB39,
  12950. yoddageshhebrew: 0xFB39,
  12951. yodhebrew: 0x05D9,
  12952. yodyodhebrew: 0x05F2,
  12953. yodyodpatahhebrew: 0xFB1F,
  12954. yohiragana: 0x3088,
  12955. yoikorean: 0x3189,
  12956. yokatakana: 0x30E8,
  12957. yokatakanahalfwidth: 0xFF96,
  12958. yokorean: 0x315B,
  12959. yosmallhiragana: 0x3087,
  12960. yosmallkatakana: 0x30E7,
  12961. yosmallkatakanahalfwidth: 0xFF6E,
  12962. yotgreek: 0x03F3,
  12963. yoyaekorean: 0x3188,
  12964. yoyakorean: 0x3187,
  12965. yoyakthai: 0x0E22,
  12966. yoyingthai: 0x0E0D,
  12967. yparen: 0x24B4,
  12968. ypogegrammeni: 0x037A,
  12969. ypogegrammenigreekcmb: 0x0345,
  12970. yr: 0x01A6,
  12971. yring: 0x1E99,
  12972. ysuperior: 0x02B8,
  12973. ytilde: 0x1EF9,
  12974. yturned: 0x028E,
  12975. yuhiragana: 0x3086,
  12976. yuikorean: 0x318C,
  12977. yukatakana: 0x30E6,
  12978. yukatakanahalfwidth: 0xFF95,
  12979. yukorean: 0x3160,
  12980. yusbigcyrillic: 0x046B,
  12981. yusbigiotifiedcyrillic: 0x046D,
  12982. yuslittlecyrillic: 0x0467,
  12983. yuslittleiotifiedcyrillic: 0x0469,
  12984. yusmallhiragana: 0x3085,
  12985. yusmallkatakana: 0x30E5,
  12986. yusmallkatakanahalfwidth: 0xFF6D,
  12987. yuyekorean: 0x318B,
  12988. yuyeokorean: 0x318A,
  12989. yyabengali: 0x09DF,
  12990. yyadeva: 0x095F,
  12991. z: 0x007A,
  12992. zaarmenian: 0x0566,
  12993. zacute: 0x017A,
  12994. zadeva: 0x095B,
  12995. zagurmukhi: 0x0A5B,
  12996. zaharabic: 0x0638,
  12997. zahfinalarabic: 0xFEC6,
  12998. zahinitialarabic: 0xFEC7,
  12999. zahiragana: 0x3056,
  13000. zahmedialarabic: 0xFEC8,
  13001. zainarabic: 0x0632,
  13002. zainfinalarabic: 0xFEB0,
  13003. zakatakana: 0x30B6,
  13004. zaqefgadolhebrew: 0x0595,
  13005. zaqefqatanhebrew: 0x0594,
  13006. zarqahebrew: 0x0598,
  13007. zayin: 0x05D6,
  13008. zayindagesh: 0xFB36,
  13009. zayindageshhebrew: 0xFB36,
  13010. zayinhebrew: 0x05D6,
  13011. zbopomofo: 0x3117,
  13012. zcaron: 0x017E,
  13013. zcircle: 0x24E9,
  13014. zcircumflex: 0x1E91,
  13015. zcurl: 0x0291,
  13016. zdot: 0x017C,
  13017. zdotaccent: 0x017C,
  13018. zdotbelow: 0x1E93,
  13019. zecyrillic: 0x0437,
  13020. zedescendercyrillic: 0x0499,
  13021. zedieresiscyrillic: 0x04DF,
  13022. zehiragana: 0x305C,
  13023. zekatakana: 0x30BC,
  13024. zero: 0x0030,
  13025. zeroarabic: 0x0660,
  13026. zerobengali: 0x09E6,
  13027. zerodeva: 0x0966,
  13028. zerogujarati: 0x0AE6,
  13029. zerogurmukhi: 0x0A66,
  13030. zerohackarabic: 0x0660,
  13031. zeroinferior: 0x2080,
  13032. zeromonospace: 0xFF10,
  13033. zerooldstyle: 0xF730,
  13034. zeropersian: 0x06F0,
  13035. zerosuperior: 0x2070,
  13036. zerothai: 0x0E50,
  13037. zerowidthjoiner: 0xFEFF,
  13038. zerowidthnonjoiner: 0x200C,
  13039. zerowidthspace: 0x200B,
  13040. zeta: 0x03B6,
  13041. zhbopomofo: 0x3113,
  13042. zhearmenian: 0x056A,
  13043. zhebrevecyrillic: 0x04C2,
  13044. zhecyrillic: 0x0436,
  13045. zhedescendercyrillic: 0x0497,
  13046. zhedieresiscyrillic: 0x04DD,
  13047. zihiragana: 0x3058,
  13048. zikatakana: 0x30B8,
  13049. zinorhebrew: 0x05AE,
  13050. zlinebelow: 0x1E95,
  13051. zmonospace: 0xFF5A,
  13052. zohiragana: 0x305E,
  13053. zokatakana: 0x30BE,
  13054. zparen: 0x24B5,
  13055. zretroflexhook: 0x0290,
  13056. zstroke: 0x01B6,
  13057. zuhiragana: 0x305A,
  13058. zukatakana: 0x30BA,
  13059. '.notdef': 0x0000
  13060. };
  13061. var DingbatsGlyphsUnicode = {
  13062. space: 0x0020,
  13063. a1: 0x2701,
  13064. a2: 0x2702,
  13065. a202: 0x2703,
  13066. a3: 0x2704,
  13067. a4: 0x260E,
  13068. a5: 0x2706,
  13069. a119: 0x2707,
  13070. a118: 0x2708,
  13071. a117: 0x2709,
  13072. a11: 0x261B,
  13073. a12: 0x261E,
  13074. a13: 0x270C,
  13075. a14: 0x270D,
  13076. a15: 0x270E,
  13077. a16: 0x270F,
  13078. a105: 0x2710,
  13079. a17: 0x2711,
  13080. a18: 0x2712,
  13081. a19: 0x2713,
  13082. a20: 0x2714,
  13083. a21: 0x2715,
  13084. a22: 0x2716,
  13085. a23: 0x2717,
  13086. a24: 0x2718,
  13087. a25: 0x2719,
  13088. a26: 0x271A,
  13089. a27: 0x271B,
  13090. a28: 0x271C,
  13091. a6: 0x271D,
  13092. a7: 0x271E,
  13093. a8: 0x271F,
  13094. a9: 0x2720,
  13095. a10: 0x2721,
  13096. a29: 0x2722,
  13097. a30: 0x2723,
  13098. a31: 0x2724,
  13099. a32: 0x2725,
  13100. a33: 0x2726,
  13101. a34: 0x2727,
  13102. a35: 0x2605,
  13103. a36: 0x2729,
  13104. a37: 0x272A,
  13105. a38: 0x272B,
  13106. a39: 0x272C,
  13107. a40: 0x272D,
  13108. a41: 0x272E,
  13109. a42: 0x272F,
  13110. a43: 0x2730,
  13111. a44: 0x2731,
  13112. a45: 0x2732,
  13113. a46: 0x2733,
  13114. a47: 0x2734,
  13115. a48: 0x2735,
  13116. a49: 0x2736,
  13117. a50: 0x2737,
  13118. a51: 0x2738,
  13119. a52: 0x2739,
  13120. a53: 0x273A,
  13121. a54: 0x273B,
  13122. a55: 0x273C,
  13123. a56: 0x273D,
  13124. a57: 0x273E,
  13125. a58: 0x273F,
  13126. a59: 0x2740,
  13127. a60: 0x2741,
  13128. a61: 0x2742,
  13129. a62: 0x2743,
  13130. a63: 0x2744,
  13131. a64: 0x2745,
  13132. a65: 0x2746,
  13133. a66: 0x2747,
  13134. a67: 0x2748,
  13135. a68: 0x2749,
  13136. a69: 0x274A,
  13137. a70: 0x274B,
  13138. a71: 0x25CF,
  13139. a72: 0x274D,
  13140. a73: 0x25A0,
  13141. a74: 0x274F,
  13142. a203: 0x2750,
  13143. a75: 0x2751,
  13144. a204: 0x2752,
  13145. a76: 0x25B2,
  13146. a77: 0x25BC,
  13147. a78: 0x25C6,
  13148. a79: 0x2756,
  13149. a81: 0x25D7,
  13150. a82: 0x2758,
  13151. a83: 0x2759,
  13152. a84: 0x275A,
  13153. a97: 0x275B,
  13154. a98: 0x275C,
  13155. a99: 0x275D,
  13156. a100: 0x275E,
  13157. a101: 0x2761,
  13158. a102: 0x2762,
  13159. a103: 0x2763,
  13160. a104: 0x2764,
  13161. a106: 0x2765,
  13162. a107: 0x2766,
  13163. a108: 0x2767,
  13164. a112: 0x2663,
  13165. a111: 0x2666,
  13166. a110: 0x2665,
  13167. a109: 0x2660,
  13168. a120: 0x2460,
  13169. a121: 0x2461,
  13170. a122: 0x2462,
  13171. a123: 0x2463,
  13172. a124: 0x2464,
  13173. a125: 0x2465,
  13174. a126: 0x2466,
  13175. a127: 0x2467,
  13176. a128: 0x2468,
  13177. a129: 0x2469,
  13178. a130: 0x2776,
  13179. a131: 0x2777,
  13180. a132: 0x2778,
  13181. a133: 0x2779,
  13182. a134: 0x277A,
  13183. a135: 0x277B,
  13184. a136: 0x277C,
  13185. a137: 0x277D,
  13186. a138: 0x277E,
  13187. a139: 0x277F,
  13188. a140: 0x2780,
  13189. a141: 0x2781,
  13190. a142: 0x2782,
  13191. a143: 0x2783,
  13192. a144: 0x2784,
  13193. a145: 0x2785,
  13194. a146: 0x2786,
  13195. a147: 0x2787,
  13196. a148: 0x2788,
  13197. a149: 0x2789,
  13198. a150: 0x278A,
  13199. a151: 0x278B,
  13200. a152: 0x278C,
  13201. a153: 0x278D,
  13202. a154: 0x278E,
  13203. a155: 0x278F,
  13204. a156: 0x2790,
  13205. a157: 0x2791,
  13206. a158: 0x2792,
  13207. a159: 0x2793,
  13208. a160: 0x2794,
  13209. a161: 0x2192,
  13210. a163: 0x2194,
  13211. a164: 0x2195,
  13212. a196: 0x2798,
  13213. a165: 0x2799,
  13214. a192: 0x279A,
  13215. a166: 0x279B,
  13216. a167: 0x279C,
  13217. a168: 0x279D,
  13218. a169: 0x279E,
  13219. a170: 0x279F,
  13220. a171: 0x27A0,
  13221. a172: 0x27A1,
  13222. a173: 0x27A2,
  13223. a162: 0x27A3,
  13224. a174: 0x27A4,
  13225. a175: 0x27A5,
  13226. a176: 0x27A6,
  13227. a177: 0x27A7,
  13228. a178: 0x27A8,
  13229. a179: 0x27A9,
  13230. a193: 0x27AA,
  13231. a180: 0x27AB,
  13232. a199: 0x27AC,
  13233. a181: 0x27AD,
  13234. a200: 0x27AE,
  13235. a182: 0x27AF,
  13236. a201: 0x27B1,
  13237. a183: 0x27B2,
  13238. a184: 0x27B3,
  13239. a197: 0x27B4,
  13240. a185: 0x27B5,
  13241. a194: 0x27B6,
  13242. a198: 0x27B7,
  13243. a186: 0x27B8,
  13244. a195: 0x27B9,
  13245. a187: 0x27BA,
  13246. a188: 0x27BB,
  13247. a189: 0x27BC,
  13248. a190: 0x27BD,
  13249. a191: 0x27BE,
  13250. a89: 0x2768, // 0xF8D7
  13251. a90: 0x2769, // 0xF8D8
  13252. a93: 0x276A, // 0xF8D9
  13253. a94: 0x276B, // 0xF8DA
  13254. a91: 0x276C, // 0xF8DB
  13255. a92: 0x276D, // 0xF8DC
  13256. a205: 0x276E, // 0xF8DD
  13257. a85: 0x276F, // 0xF8DE
  13258. a206: 0x2770, // 0xF8DF
  13259. a86: 0x2771, // 0xF8E0
  13260. a87: 0x2772, // 0xF8E1
  13261. a88: 0x2773, // 0xF8E2
  13262. a95: 0x2774, // 0xF8E3
  13263. a96: 0x2775, // 0xF8E4
  13264. '.notdef': 0x0000
  13265. };
  13266. exports.GlyphsUnicode = GlyphsUnicode;
  13267. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  13268. }));
  13269. (function (root, factory) {
  13270. {
  13271. factory((root.pdfjsCoreJpg = {}));
  13272. }
  13273. }(this, function (exports) {
  13274. /*
  13275. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  13276. version was created by github user notmasteryet
  13277. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  13278. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  13279. - The JFIF specification can be found in the JPEG File Interchange Format
  13280. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  13281. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  13282. in PostScript Level 2, Technical Note #5116
  13283. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  13284. */
  13285. var JpegImage = (function jpegImage() {
  13286. var dctZigZag = new Uint8Array([
  13287. 0,
  13288. 1, 8,
  13289. 16, 9, 2,
  13290. 3, 10, 17, 24,
  13291. 32, 25, 18, 11, 4,
  13292. 5, 12, 19, 26, 33, 40,
  13293. 48, 41, 34, 27, 20, 13, 6,
  13294. 7, 14, 21, 28, 35, 42, 49, 56,
  13295. 57, 50, 43, 36, 29, 22, 15,
  13296. 23, 30, 37, 44, 51, 58,
  13297. 59, 52, 45, 38, 31,
  13298. 39, 46, 53, 60,
  13299. 61, 54, 47,
  13300. 55, 62,
  13301. 63
  13302. ]);
  13303. var dctCos1 = 4017; // cos(pi/16)
  13304. var dctSin1 = 799; // sin(pi/16)
  13305. var dctCos3 = 3406; // cos(3*pi/16)
  13306. var dctSin3 = 2276; // sin(3*pi/16)
  13307. var dctCos6 = 1567; // cos(6*pi/16)
  13308. var dctSin6 = 3784; // sin(6*pi/16)
  13309. var dctSqrt2 = 5793; // sqrt(2)
  13310. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  13311. function constructor() {
  13312. }
  13313. function buildHuffmanTable(codeLengths, values) {
  13314. var k = 0, code = [], i, j, length = 16;
  13315. while (length > 0 && !codeLengths[length - 1]) {
  13316. length--;
  13317. }
  13318. code.push({children: [], index: 0});
  13319. var p = code[0], q;
  13320. for (i = 0; i < length; i++) {
  13321. for (j = 0; j < codeLengths[i]; j++) {
  13322. p = code.pop();
  13323. p.children[p.index] = values[k];
  13324. while (p.index > 0) {
  13325. p = code.pop();
  13326. }
  13327. p.index++;
  13328. code.push(p);
  13329. while (code.length <= i) {
  13330. code.push(q = {children: [], index: 0});
  13331. p.children[p.index] = q.children;
  13332. p = q;
  13333. }
  13334. k++;
  13335. }
  13336. if (i + 1 < length) {
  13337. // p here points to last code
  13338. code.push(q = {children: [], index: 0});
  13339. p.children[p.index] = q.children;
  13340. p = q;
  13341. }
  13342. }
  13343. return code[0].children;
  13344. }
  13345. function getBlockBufferOffset(component, row, col) {
  13346. return 64 * ((component.blocksPerLine + 1) * row + col);
  13347. }
  13348. function decodeScan(data, offset, frame, components, resetInterval,
  13349. spectralStart, spectralEnd, successivePrev, successive) {
  13350. var mcusPerLine = frame.mcusPerLine;
  13351. var progressive = frame.progressive;
  13352. var startOffset = offset, bitsData = 0, bitsCount = 0;
  13353. function readBit() {
  13354. if (bitsCount > 0) {
  13355. bitsCount--;
  13356. return (bitsData >> bitsCount) & 1;
  13357. }
  13358. bitsData = data[offset++];
  13359. if (bitsData === 0xFF) {
  13360. var nextByte = data[offset++];
  13361. if (nextByte) {
  13362. throw 'unexpected marker: ' +
  13363. ((bitsData << 8) | nextByte).toString(16);
  13364. }
  13365. // unstuff 0
  13366. }
  13367. bitsCount = 7;
  13368. return bitsData >>> 7;
  13369. }
  13370. function decodeHuffman(tree) {
  13371. var node = tree;
  13372. while (true) {
  13373. node = node[readBit()];
  13374. if (typeof node === 'number') {
  13375. return node;
  13376. }
  13377. if (typeof node !== 'object') {
  13378. throw 'invalid huffman sequence';
  13379. }
  13380. }
  13381. }
  13382. function receive(length) {
  13383. var n = 0;
  13384. while (length > 0) {
  13385. n = (n << 1) | readBit();
  13386. length--;
  13387. }
  13388. return n;
  13389. }
  13390. function receiveAndExtend(length) {
  13391. if (length === 1) {
  13392. return readBit() === 1 ? 1 : -1;
  13393. }
  13394. var n = receive(length);
  13395. if (n >= 1 << (length - 1)) {
  13396. return n;
  13397. }
  13398. return n + (-1 << length) + 1;
  13399. }
  13400. function decodeBaseline(component, offset) {
  13401. var t = decodeHuffman(component.huffmanTableDC);
  13402. var diff = t === 0 ? 0 : receiveAndExtend(t);
  13403. component.blockData[offset] = (component.pred += diff);
  13404. var k = 1;
  13405. while (k < 64) {
  13406. var rs = decodeHuffman(component.huffmanTableAC);
  13407. var s = rs & 15, r = rs >> 4;
  13408. if (s === 0) {
  13409. if (r < 15) {
  13410. break;
  13411. }
  13412. k += 16;
  13413. continue;
  13414. }
  13415. k += r;
  13416. var z = dctZigZag[k];
  13417. component.blockData[offset + z] = receiveAndExtend(s);
  13418. k++;
  13419. }
  13420. }
  13421. function decodeDCFirst(component, offset) {
  13422. var t = decodeHuffman(component.huffmanTableDC);
  13423. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  13424. component.blockData[offset] = (component.pred += diff);
  13425. }
  13426. function decodeDCSuccessive(component, offset) {
  13427. component.blockData[offset] |= readBit() << successive;
  13428. }
  13429. var eobrun = 0;
  13430. function decodeACFirst(component, offset) {
  13431. if (eobrun > 0) {
  13432. eobrun--;
  13433. return;
  13434. }
  13435. var k = spectralStart, e = spectralEnd;
  13436. while (k <= e) {
  13437. var rs = decodeHuffman(component.huffmanTableAC);
  13438. var s = rs & 15, r = rs >> 4;
  13439. if (s === 0) {
  13440. if (r < 15) {
  13441. eobrun = receive(r) + (1 << r) - 1;
  13442. break;
  13443. }
  13444. k += 16;
  13445. continue;
  13446. }
  13447. k += r;
  13448. var z = dctZigZag[k];
  13449. component.blockData[offset + z] =
  13450. receiveAndExtend(s) * (1 << successive);
  13451. k++;
  13452. }
  13453. }
  13454. var successiveACState = 0, successiveACNextValue;
  13455. function decodeACSuccessive(component, offset) {
  13456. var k = spectralStart;
  13457. var e = spectralEnd;
  13458. var r = 0;
  13459. var s;
  13460. var rs;
  13461. while (k <= e) {
  13462. var z = dctZigZag[k];
  13463. switch (successiveACState) {
  13464. case 0: // initial state
  13465. rs = decodeHuffman(component.huffmanTableAC);
  13466. s = rs & 15;
  13467. r = rs >> 4;
  13468. if (s === 0) {
  13469. if (r < 15) {
  13470. eobrun = receive(r) + (1 << r);
  13471. successiveACState = 4;
  13472. } else {
  13473. r = 16;
  13474. successiveACState = 1;
  13475. }
  13476. } else {
  13477. if (s !== 1) {
  13478. throw 'invalid ACn encoding';
  13479. }
  13480. successiveACNextValue = receiveAndExtend(s);
  13481. successiveACState = r ? 2 : 3;
  13482. }
  13483. continue;
  13484. case 1: // skipping r zero items
  13485. case 2:
  13486. if (component.blockData[offset + z]) {
  13487. component.blockData[offset + z] += (readBit() << successive);
  13488. } else {
  13489. r--;
  13490. if (r === 0) {
  13491. successiveACState = successiveACState === 2 ? 3 : 0;
  13492. }
  13493. }
  13494. break;
  13495. case 3: // set value for a zero item
  13496. if (component.blockData[offset + z]) {
  13497. component.blockData[offset + z] += (readBit() << successive);
  13498. } else {
  13499. component.blockData[offset + z] =
  13500. successiveACNextValue << successive;
  13501. successiveACState = 0;
  13502. }
  13503. break;
  13504. case 4: // eob
  13505. if (component.blockData[offset + z]) {
  13506. component.blockData[offset + z] += (readBit() << successive);
  13507. }
  13508. break;
  13509. }
  13510. k++;
  13511. }
  13512. if (successiveACState === 4) {
  13513. eobrun--;
  13514. if (eobrun === 0) {
  13515. successiveACState = 0;
  13516. }
  13517. }
  13518. }
  13519. function decodeMcu(component, decode, mcu, row, col) {
  13520. var mcuRow = (mcu / mcusPerLine) | 0;
  13521. var mcuCol = mcu % mcusPerLine;
  13522. var blockRow = mcuRow * component.v + row;
  13523. var blockCol = mcuCol * component.h + col;
  13524. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13525. decode(component, offset);
  13526. }
  13527. function decodeBlock(component, decode, mcu) {
  13528. var blockRow = (mcu / component.blocksPerLine) | 0;
  13529. var blockCol = mcu % component.blocksPerLine;
  13530. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13531. decode(component, offset);
  13532. }
  13533. var componentsLength = components.length;
  13534. var component, i, j, k, n;
  13535. var decodeFn;
  13536. if (progressive) {
  13537. if (spectralStart === 0) {
  13538. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  13539. } else {
  13540. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  13541. }
  13542. } else {
  13543. decodeFn = decodeBaseline;
  13544. }
  13545. var mcu = 0, marker;
  13546. var mcuExpected;
  13547. if (componentsLength === 1) {
  13548. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  13549. } else {
  13550. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  13551. }
  13552. if (!resetInterval) {
  13553. resetInterval = mcuExpected;
  13554. }
  13555. var h, v;
  13556. while (mcu < mcuExpected) {
  13557. // reset interval stuff
  13558. for (i = 0; i < componentsLength; i++) {
  13559. components[i].pred = 0;
  13560. }
  13561. eobrun = 0;
  13562. if (componentsLength === 1) {
  13563. component = components[0];
  13564. for (n = 0; n < resetInterval; n++) {
  13565. decodeBlock(component, decodeFn, mcu);
  13566. mcu++;
  13567. }
  13568. } else {
  13569. for (n = 0; n < resetInterval; n++) {
  13570. for (i = 0; i < componentsLength; i++) {
  13571. component = components[i];
  13572. h = component.h;
  13573. v = component.v;
  13574. for (j = 0; j < v; j++) {
  13575. for (k = 0; k < h; k++) {
  13576. decodeMcu(component, decodeFn, mcu, j, k);
  13577. }
  13578. }
  13579. }
  13580. mcu++;
  13581. }
  13582. }
  13583. // find marker
  13584. bitsCount = 0;
  13585. marker = (data[offset] << 8) | data[offset + 1];
  13586. if (marker <= 0xFF00) {
  13587. throw 'marker was not found';
  13588. }
  13589. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  13590. offset += 2;
  13591. } else {
  13592. break;
  13593. }
  13594. }
  13595. return offset - startOffset;
  13596. }
  13597. // A port of poppler's IDCT method which in turn is taken from:
  13598. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  13599. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  13600. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  13601. // 988-991.
  13602. function quantizeAndInverse(component, blockBufferOffset, p) {
  13603. var qt = component.quantizationTable, blockData = component.blockData;
  13604. var v0, v1, v2, v3, v4, v5, v6, v7;
  13605. var p0, p1, p2, p3, p4, p5, p6, p7;
  13606. var t;
  13607. // inverse DCT on rows
  13608. for (var row = 0; row < 64; row += 8) {
  13609. // gather block data
  13610. p0 = blockData[blockBufferOffset + row];
  13611. p1 = blockData[blockBufferOffset + row + 1];
  13612. p2 = blockData[blockBufferOffset + row + 2];
  13613. p3 = blockData[blockBufferOffset + row + 3];
  13614. p4 = blockData[blockBufferOffset + row + 4];
  13615. p5 = blockData[blockBufferOffset + row + 5];
  13616. p6 = blockData[blockBufferOffset + row + 6];
  13617. p7 = blockData[blockBufferOffset + row + 7];
  13618. // dequant p0
  13619. p0 *= qt[row];
  13620. // check for all-zero AC coefficients
  13621. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  13622. t = (dctSqrt2 * p0 + 512) >> 10;
  13623. p[row] = t;
  13624. p[row + 1] = t;
  13625. p[row + 2] = t;
  13626. p[row + 3] = t;
  13627. p[row + 4] = t;
  13628. p[row + 5] = t;
  13629. p[row + 6] = t;
  13630. p[row + 7] = t;
  13631. continue;
  13632. }
  13633. // dequant p1 ... p7
  13634. p1 *= qt[row + 1];
  13635. p2 *= qt[row + 2];
  13636. p3 *= qt[row + 3];
  13637. p4 *= qt[row + 4];
  13638. p5 *= qt[row + 5];
  13639. p6 *= qt[row + 6];
  13640. p7 *= qt[row + 7];
  13641. // stage 4
  13642. v0 = (dctSqrt2 * p0 + 128) >> 8;
  13643. v1 = (dctSqrt2 * p4 + 128) >> 8;
  13644. v2 = p2;
  13645. v3 = p6;
  13646. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  13647. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  13648. v5 = p3 << 4;
  13649. v6 = p5 << 4;
  13650. // stage 3
  13651. v0 = (v0 + v1 + 1) >> 1;
  13652. v1 = v0 - v1;
  13653. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  13654. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  13655. v3 = t;
  13656. v4 = (v4 + v6 + 1) >> 1;
  13657. v6 = v4 - v6;
  13658. v7 = (v7 + v5 + 1) >> 1;
  13659. v5 = v7 - v5;
  13660. // stage 2
  13661. v0 = (v0 + v3 + 1) >> 1;
  13662. v3 = v0 - v3;
  13663. v1 = (v1 + v2 + 1) >> 1;
  13664. v2 = v1 - v2;
  13665. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  13666. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  13667. v7 = t;
  13668. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  13669. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  13670. v6 = t;
  13671. // stage 1
  13672. p[row] = v0 + v7;
  13673. p[row + 7] = v0 - v7;
  13674. p[row + 1] = v1 + v6;
  13675. p[row + 6] = v1 - v6;
  13676. p[row + 2] = v2 + v5;
  13677. p[row + 5] = v2 - v5;
  13678. p[row + 3] = v3 + v4;
  13679. p[row + 4] = v3 - v4;
  13680. }
  13681. // inverse DCT on columns
  13682. for (var col = 0; col < 8; ++col) {
  13683. p0 = p[col];
  13684. p1 = p[col + 8];
  13685. p2 = p[col + 16];
  13686. p3 = p[col + 24];
  13687. p4 = p[col + 32];
  13688. p5 = p[col + 40];
  13689. p6 = p[col + 48];
  13690. p7 = p[col + 56];
  13691. // check for all-zero AC coefficients
  13692. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  13693. t = (dctSqrt2 * p0 + 8192) >> 14;
  13694. // convert to 8 bit
  13695. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  13696. blockData[blockBufferOffset + col] = t;
  13697. blockData[blockBufferOffset + col + 8] = t;
  13698. blockData[blockBufferOffset + col + 16] = t;
  13699. blockData[blockBufferOffset + col + 24] = t;
  13700. blockData[blockBufferOffset + col + 32] = t;
  13701. blockData[blockBufferOffset + col + 40] = t;
  13702. blockData[blockBufferOffset + col + 48] = t;
  13703. blockData[blockBufferOffset + col + 56] = t;
  13704. continue;
  13705. }
  13706. // stage 4
  13707. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  13708. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  13709. v2 = p2;
  13710. v3 = p6;
  13711. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  13712. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  13713. v5 = p3;
  13714. v6 = p5;
  13715. // stage 3
  13716. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  13717. // converting to UInt8 range later.
  13718. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  13719. v1 = v0 - v1;
  13720. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  13721. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  13722. v3 = t;
  13723. v4 = (v4 + v6 + 1) >> 1;
  13724. v6 = v4 - v6;
  13725. v7 = (v7 + v5 + 1) >> 1;
  13726. v5 = v7 - v5;
  13727. // stage 2
  13728. v0 = (v0 + v3 + 1) >> 1;
  13729. v3 = v0 - v3;
  13730. v1 = (v1 + v2 + 1) >> 1;
  13731. v2 = v1 - v2;
  13732. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  13733. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  13734. v7 = t;
  13735. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  13736. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  13737. v6 = t;
  13738. // stage 1
  13739. p0 = v0 + v7;
  13740. p7 = v0 - v7;
  13741. p1 = v1 + v6;
  13742. p6 = v1 - v6;
  13743. p2 = v2 + v5;
  13744. p5 = v2 - v5;
  13745. p3 = v3 + v4;
  13746. p4 = v3 - v4;
  13747. // convert to 8-bit integers
  13748. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  13749. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  13750. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  13751. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  13752. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  13753. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  13754. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  13755. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  13756. // store block data
  13757. blockData[blockBufferOffset + col] = p0;
  13758. blockData[blockBufferOffset + col + 8] = p1;
  13759. blockData[blockBufferOffset + col + 16] = p2;
  13760. blockData[blockBufferOffset + col + 24] = p3;
  13761. blockData[blockBufferOffset + col + 32] = p4;
  13762. blockData[blockBufferOffset + col + 40] = p5;
  13763. blockData[blockBufferOffset + col + 48] = p6;
  13764. blockData[blockBufferOffset + col + 56] = p7;
  13765. }
  13766. }
  13767. function buildComponentData(frame, component) {
  13768. var blocksPerLine = component.blocksPerLine;
  13769. var blocksPerColumn = component.blocksPerColumn;
  13770. var computationBuffer = new Int16Array(64);
  13771. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  13772. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  13773. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13774. quantizeAndInverse(component, offset, computationBuffer);
  13775. }
  13776. }
  13777. return component.blockData;
  13778. }
  13779. function clamp0to255(a) {
  13780. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  13781. }
  13782. constructor.prototype = {
  13783. parse: function parse(data) {
  13784. function readUint16() {
  13785. var value = (data[offset] << 8) | data[offset + 1];
  13786. offset += 2;
  13787. return value;
  13788. }
  13789. function readDataBlock() {
  13790. var length = readUint16();
  13791. var array = data.subarray(offset, offset + length - 2);
  13792. offset += array.length;
  13793. return array;
  13794. }
  13795. function prepareComponents(frame) {
  13796. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  13797. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  13798. for (var i = 0; i < frame.components.length; i++) {
  13799. component = frame.components[i];
  13800. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  13801. component.h / frame.maxH);
  13802. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  13803. component.v / frame.maxV);
  13804. var blocksPerLineForMcu = mcusPerLine * component.h;
  13805. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  13806. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  13807. (blocksPerLineForMcu + 1);
  13808. component.blockData = new Int16Array(blocksBufferSize);
  13809. component.blocksPerLine = blocksPerLine;
  13810. component.blocksPerColumn = blocksPerColumn;
  13811. }
  13812. frame.mcusPerLine = mcusPerLine;
  13813. frame.mcusPerColumn = mcusPerColumn;
  13814. }
  13815. var offset = 0;
  13816. var jfif = null;
  13817. var adobe = null;
  13818. var frame, resetInterval;
  13819. var quantizationTables = [];
  13820. var huffmanTablesAC = [], huffmanTablesDC = [];
  13821. var fileMarker = readUint16();
  13822. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  13823. throw 'SOI not found';
  13824. }
  13825. fileMarker = readUint16();
  13826. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  13827. var i, j, l;
  13828. switch(fileMarker) {
  13829. case 0xFFE0: // APP0 (Application Specific)
  13830. case 0xFFE1: // APP1
  13831. case 0xFFE2: // APP2
  13832. case 0xFFE3: // APP3
  13833. case 0xFFE4: // APP4
  13834. case 0xFFE5: // APP5
  13835. case 0xFFE6: // APP6
  13836. case 0xFFE7: // APP7
  13837. case 0xFFE8: // APP8
  13838. case 0xFFE9: // APP9
  13839. case 0xFFEA: // APP10
  13840. case 0xFFEB: // APP11
  13841. case 0xFFEC: // APP12
  13842. case 0xFFED: // APP13
  13843. case 0xFFEE: // APP14
  13844. case 0xFFEF: // APP15
  13845. case 0xFFFE: // COM (Comment)
  13846. var appData = readDataBlock();
  13847. if (fileMarker === 0xFFE0) {
  13848. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  13849. appData[2] === 0x49 && appData[3] === 0x46 &&
  13850. appData[4] === 0) { // 'JFIF\x00'
  13851. jfif = {
  13852. version: { major: appData[5], minor: appData[6] },
  13853. densityUnits: appData[7],
  13854. xDensity: (appData[8] << 8) | appData[9],
  13855. yDensity: (appData[10] << 8) | appData[11],
  13856. thumbWidth: appData[12],
  13857. thumbHeight: appData[13],
  13858. thumbData: appData.subarray(14, 14 +
  13859. 3 * appData[12] * appData[13])
  13860. };
  13861. }
  13862. }
  13863. // TODO APP1 - Exif
  13864. if (fileMarker === 0xFFEE) {
  13865. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  13866. appData[2] === 0x6F && appData[3] === 0x62 &&
  13867. appData[4] === 0x65) { // 'Adobe'
  13868. adobe = {
  13869. version: (appData[5] << 8) | appData[6],
  13870. flags0: (appData[7] << 8) | appData[8],
  13871. flags1: (appData[9] << 8) | appData[10],
  13872. transformCode: appData[11]
  13873. };
  13874. }
  13875. }
  13876. break;
  13877. case 0xFFDB: // DQT (Define Quantization Tables)
  13878. var quantizationTablesLength = readUint16();
  13879. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  13880. var z;
  13881. while (offset < quantizationTablesEnd) {
  13882. var quantizationTableSpec = data[offset++];
  13883. var tableData = new Uint16Array(64);
  13884. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  13885. for (j = 0; j < 64; j++) {
  13886. z = dctZigZag[j];
  13887. tableData[z] = data[offset++];
  13888. }
  13889. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  13890. for (j = 0; j < 64; j++) {
  13891. z = dctZigZag[j];
  13892. tableData[z] = readUint16();
  13893. }
  13894. } else {
  13895. throw 'DQT: invalid table spec';
  13896. }
  13897. quantizationTables[quantizationTableSpec & 15] = tableData;
  13898. }
  13899. break;
  13900. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  13901. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  13902. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  13903. if (frame) {
  13904. throw 'Only single frame JPEGs supported';
  13905. }
  13906. readUint16(); // skip data length
  13907. frame = {};
  13908. frame.extended = (fileMarker === 0xFFC1);
  13909. frame.progressive = (fileMarker === 0xFFC2);
  13910. frame.precision = data[offset++];
  13911. frame.scanLines = readUint16();
  13912. frame.samplesPerLine = readUint16();
  13913. frame.components = [];
  13914. frame.componentIds = {};
  13915. var componentsCount = data[offset++], componentId;
  13916. var maxH = 0, maxV = 0;
  13917. for (i = 0; i < componentsCount; i++) {
  13918. componentId = data[offset];
  13919. var h = data[offset + 1] >> 4;
  13920. var v = data[offset + 1] & 15;
  13921. if (maxH < h) {
  13922. maxH = h;
  13923. }
  13924. if (maxV < v) {
  13925. maxV = v;
  13926. }
  13927. var qId = data[offset + 2];
  13928. l = frame.components.push({
  13929. h: h,
  13930. v: v,
  13931. quantizationTable: quantizationTables[qId]
  13932. });
  13933. frame.componentIds[componentId] = l - 1;
  13934. offset += 3;
  13935. }
  13936. frame.maxH = maxH;
  13937. frame.maxV = maxV;
  13938. prepareComponents(frame);
  13939. break;
  13940. case 0xFFC4: // DHT (Define Huffman Tables)
  13941. var huffmanLength = readUint16();
  13942. for (i = 2; i < huffmanLength;) {
  13943. var huffmanTableSpec = data[offset++];
  13944. var codeLengths = new Uint8Array(16);
  13945. var codeLengthSum = 0;
  13946. for (j = 0; j < 16; j++, offset++) {
  13947. codeLengthSum += (codeLengths[j] = data[offset]);
  13948. }
  13949. var huffmanValues = new Uint8Array(codeLengthSum);
  13950. for (j = 0; j < codeLengthSum; j++, offset++) {
  13951. huffmanValues[j] = data[offset];
  13952. }
  13953. i += 17 + codeLengthSum;
  13954. ((huffmanTableSpec >> 4) === 0 ?
  13955. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  13956. buildHuffmanTable(codeLengths, huffmanValues);
  13957. }
  13958. break;
  13959. case 0xFFDD: // DRI (Define Restart Interval)
  13960. readUint16(); // skip data length
  13961. resetInterval = readUint16();
  13962. break;
  13963. case 0xFFDA: // SOS (Start of Scan)
  13964. var scanLength = readUint16();
  13965. var selectorsCount = data[offset++];
  13966. var components = [], component;
  13967. for (i = 0; i < selectorsCount; i++) {
  13968. var componentIndex = frame.componentIds[data[offset++]];
  13969. component = frame.components[componentIndex];
  13970. var tableSpec = data[offset++];
  13971. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  13972. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  13973. components.push(component);
  13974. }
  13975. var spectralStart = data[offset++];
  13976. var spectralEnd = data[offset++];
  13977. var successiveApproximation = data[offset++];
  13978. var processed = decodeScan(data, offset,
  13979. frame, components, resetInterval,
  13980. spectralStart, spectralEnd,
  13981. successiveApproximation >> 4, successiveApproximation & 15);
  13982. offset += processed;
  13983. break;
  13984. case 0xFFFF: // Fill bytes
  13985. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  13986. offset--;
  13987. }
  13988. break;
  13989. default:
  13990. if (data[offset - 3] === 0xFF &&
  13991. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  13992. // could be incorrect encoding -- last 0xFF byte of the previous
  13993. // block was eaten by the encoder
  13994. offset -= 3;
  13995. break;
  13996. }
  13997. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  13998. }
  13999. fileMarker = readUint16();
  14000. }
  14001. this.width = frame.samplesPerLine;
  14002. this.height = frame.scanLines;
  14003. this.jfif = jfif;
  14004. this.adobe = adobe;
  14005. this.components = [];
  14006. for (i = 0; i < frame.components.length; i++) {
  14007. component = frame.components[i];
  14008. this.components.push({
  14009. output: buildComponentData(frame, component),
  14010. scaleX: component.h / frame.maxH,
  14011. scaleY: component.v / frame.maxV,
  14012. blocksPerLine: component.blocksPerLine,
  14013. blocksPerColumn: component.blocksPerColumn
  14014. });
  14015. }
  14016. this.numComponents = this.components.length;
  14017. },
  14018. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  14019. var scaleX = this.width / width, scaleY = this.height / height;
  14020. var component, componentScaleX, componentScaleY, blocksPerScanline;
  14021. var x, y, i, j, k;
  14022. var index;
  14023. var offset = 0;
  14024. var output;
  14025. var numComponents = this.components.length;
  14026. var dataLength = width * height * numComponents;
  14027. var data = new Uint8Array(dataLength);
  14028. var xScaleBlockOffset = new Uint32Array(width);
  14029. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  14030. for (i = 0; i < numComponents; i++) {
  14031. component = this.components[i];
  14032. componentScaleX = component.scaleX * scaleX;
  14033. componentScaleY = component.scaleY * scaleY;
  14034. offset = i;
  14035. output = component.output;
  14036. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  14037. // precalculate the xScaleBlockOffset
  14038. for (x = 0; x < width; x++) {
  14039. j = 0 | (x * componentScaleX);
  14040. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  14041. }
  14042. // linearize the blocks of the component
  14043. for (y = 0; y < height; y++) {
  14044. j = 0 | (y * componentScaleY);
  14045. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  14046. for (x = 0; x < width; x++) {
  14047. data[offset] = output[index + xScaleBlockOffset[x]];
  14048. offset += numComponents;
  14049. }
  14050. }
  14051. }
  14052. // decodeTransform contains pairs of multiplier (-256..256) and additive
  14053. var transform = this.decodeTransform;
  14054. if (transform) {
  14055. for (i = 0; i < dataLength;) {
  14056. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  14057. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  14058. }
  14059. }
  14060. }
  14061. return data;
  14062. },
  14063. _isColorConversionNeeded: function isColorConversionNeeded() {
  14064. if (this.adobe && this.adobe.transformCode) {
  14065. // The adobe transform marker overrides any previous setting
  14066. return true;
  14067. } else if (this.numComponents === 3) {
  14068. return true;
  14069. } else {
  14070. return false;
  14071. }
  14072. },
  14073. _convertYccToRgb: function convertYccToRgb(data) {
  14074. var Y, Cb, Cr;
  14075. for (var i = 0, length = data.length; i < length; i += 3) {
  14076. Y = data[i ];
  14077. Cb = data[i + 1];
  14078. Cr = data[i + 2];
  14079. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  14080. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  14081. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  14082. }
  14083. return data;
  14084. },
  14085. _convertYcckToRgb: function convertYcckToRgb(data) {
  14086. var Y, Cb, Cr, k;
  14087. var offset = 0;
  14088. for (var i = 0, length = data.length; i < length; i += 4) {
  14089. Y = data[i];
  14090. Cb = data[i + 1];
  14091. Cr = data[i + 2];
  14092. k = data[i + 3];
  14093. var r = -122.67195406894 +
  14094. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  14095. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  14096. 0.154362151871126) +
  14097. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  14098. 0.00477271405408747 * k + 1.53380253221734) +
  14099. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  14100. 0.48357088451265) +
  14101. k * (-0.000336197177618394 * k + 0.484791561490776);
  14102. var g = 107.268039397724 +
  14103. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  14104. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  14105. 0.176491792462875) +
  14106. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  14107. 0.000770482631801132 * k - 0.151051492775562) +
  14108. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  14109. 0.25802910206845) +
  14110. k * (-0.000318913117588328 * k - 0.213742400323665);
  14111. var b = -20.810012546947 +
  14112. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  14113. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  14114. 0.814272968359295) +
  14115. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  14116. 0.000560833691242812 * k - 0.195152027534049) +
  14117. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  14118. 0.116935020465145) +
  14119. k * (-0.000343531996510555 * k + 0.24165260232407);
  14120. data[offset++] = clamp0to255(r);
  14121. data[offset++] = clamp0to255(g);
  14122. data[offset++] = clamp0to255(b);
  14123. }
  14124. return data;
  14125. },
  14126. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  14127. var Y, Cb, Cr;
  14128. for (var i = 0, length = data.length; i < length; i += 4) {
  14129. Y = data[i];
  14130. Cb = data[i + 1];
  14131. Cr = data[i + 2];
  14132. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  14133. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  14134. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  14135. // K in data[i + 3] is unchanged
  14136. }
  14137. return data;
  14138. },
  14139. _convertCmykToRgb: function convertCmykToRgb(data) {
  14140. var c, m, y, k;
  14141. var offset = 0;
  14142. var min = -255 * 255 * 255;
  14143. var scale = 1 / 255 / 255;
  14144. for (var i = 0, length = data.length; i < length; i += 4) {
  14145. c = data[i];
  14146. m = data[i + 1];
  14147. y = data[i + 2];
  14148. k = data[i + 3];
  14149. var r =
  14150. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  14151. 18.82290502165302 * y + 212.25662451639585 * k -
  14152. 72734.4411664936) +
  14153. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  14154. 17.873870861415444 * k - 1401.7366389350734) +
  14155. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  14156. 4465.541406466231) -
  14157. k * (21.86122147463605 * k + 48317.86113160301);
  14158. var g =
  14159. c * (8.841041422036149 * c + 60.118027045597366 * m +
  14160. 6.871425592049007 * y + 31.159100130055922 * k -
  14161. 20220.756542821975) +
  14162. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  14163. 131.35250912493976 * k - 48691.05921601825) +
  14164. y * (4.444339102852739 * y + 9.8632861493405 * k -
  14165. 6341.191035517494) -
  14166. k * (20.737325471181034 * k + 47890.15695978492);
  14167. var b =
  14168. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  14169. 30.89978309703729 * y - 0.23883238689178934 * k -
  14170. 3616.812083916688) +
  14171. m * (10.49593273432072 * m + 63.02378494754052 * y +
  14172. 50.606957656360734 * k - 28620.90484698408) +
  14173. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  14174. 49363.43385999684) -
  14175. k * (22.33816807309886 * k + 45932.16563550634);
  14176. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  14177. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  14178. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  14179. }
  14180. return data;
  14181. },
  14182. getData: function getData(width, height, forceRGBoutput) {
  14183. if (this.numComponents > 4) {
  14184. throw 'Unsupported color mode';
  14185. }
  14186. // type of data: Uint8Array(width * height * numComponents)
  14187. var data = this._getLinearizedBlockData(width, height);
  14188. if (this.numComponents === 3) {
  14189. return this._convertYccToRgb(data);
  14190. } else if (this.numComponents === 4) {
  14191. if (this._isColorConversionNeeded()) {
  14192. if (forceRGBoutput) {
  14193. return this._convertYcckToRgb(data);
  14194. } else {
  14195. return this._convertYcckToCmyk(data);
  14196. }
  14197. } else if (forceRGBoutput) {
  14198. return this._convertCmykToRgb(data);
  14199. }
  14200. }
  14201. return data;
  14202. }
  14203. };
  14204. return constructor;
  14205. })();
  14206. exports.JpegImage = JpegImage;
  14207. }));
  14208. (function (root, factory) {
  14209. {
  14210. factory((root.pdfjsCoreMetrics = {}));
  14211. }
  14212. }(this, function (exports) {
  14213. // The Metrics object contains glyph widths (in glyph space units).
  14214. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  14215. // space unit corresponds to 1/1000th of text space unit.
  14216. var Metrics = {
  14217. 'Courier': 600,
  14218. 'Courier-Bold': 600,
  14219. 'Courier-BoldOblique': 600,
  14220. 'Courier-Oblique': 600,
  14221. 'Helvetica' : {
  14222. 'space': 278,
  14223. 'exclam': 278,
  14224. 'quotedbl': 355,
  14225. 'numbersign': 556,
  14226. 'dollar': 556,
  14227. 'percent': 889,
  14228. 'ampersand': 667,
  14229. 'quoteright': 222,
  14230. 'parenleft': 333,
  14231. 'parenright': 333,
  14232. 'asterisk': 389,
  14233. 'plus': 584,
  14234. 'comma': 278,
  14235. 'hyphen': 333,
  14236. 'period': 278,
  14237. 'slash': 278,
  14238. 'zero': 556,
  14239. 'one': 556,
  14240. 'two': 556,
  14241. 'three': 556,
  14242. 'four': 556,
  14243. 'five': 556,
  14244. 'six': 556,
  14245. 'seven': 556,
  14246. 'eight': 556,
  14247. 'nine': 556,
  14248. 'colon': 278,
  14249. 'semicolon': 278,
  14250. 'less': 584,
  14251. 'equal': 584,
  14252. 'greater': 584,
  14253. 'question': 556,
  14254. 'at': 1015,
  14255. 'A': 667,
  14256. 'B': 667,
  14257. 'C': 722,
  14258. 'D': 722,
  14259. 'E': 667,
  14260. 'F': 611,
  14261. 'G': 778,
  14262. 'H': 722,
  14263. 'I': 278,
  14264. 'J': 500,
  14265. 'K': 667,
  14266. 'L': 556,
  14267. 'M': 833,
  14268. 'N': 722,
  14269. 'O': 778,
  14270. 'P': 667,
  14271. 'Q': 778,
  14272. 'R': 722,
  14273. 'S': 667,
  14274. 'T': 611,
  14275. 'U': 722,
  14276. 'V': 667,
  14277. 'W': 944,
  14278. 'X': 667,
  14279. 'Y': 667,
  14280. 'Z': 611,
  14281. 'bracketleft': 278,
  14282. 'backslash': 278,
  14283. 'bracketright': 278,
  14284. 'asciicircum': 469,
  14285. 'underscore': 556,
  14286. 'quoteleft': 222,
  14287. 'a': 556,
  14288. 'b': 556,
  14289. 'c': 500,
  14290. 'd': 556,
  14291. 'e': 556,
  14292. 'f': 278,
  14293. 'g': 556,
  14294. 'h': 556,
  14295. 'i': 222,
  14296. 'j': 222,
  14297. 'k': 500,
  14298. 'l': 222,
  14299. 'm': 833,
  14300. 'n': 556,
  14301. 'o': 556,
  14302. 'p': 556,
  14303. 'q': 556,
  14304. 'r': 333,
  14305. 's': 500,
  14306. 't': 278,
  14307. 'u': 556,
  14308. 'v': 500,
  14309. 'w': 722,
  14310. 'x': 500,
  14311. 'y': 500,
  14312. 'z': 500,
  14313. 'braceleft': 334,
  14314. 'bar': 260,
  14315. 'braceright': 334,
  14316. 'asciitilde': 584,
  14317. 'exclamdown': 333,
  14318. 'cent': 556,
  14319. 'sterling': 556,
  14320. 'fraction': 167,
  14321. 'yen': 556,
  14322. 'florin': 556,
  14323. 'section': 556,
  14324. 'currency': 556,
  14325. 'quotesingle': 191,
  14326. 'quotedblleft': 333,
  14327. 'guillemotleft': 556,
  14328. 'guilsinglleft': 333,
  14329. 'guilsinglright': 333,
  14330. 'fi': 500,
  14331. 'fl': 500,
  14332. 'endash': 556,
  14333. 'dagger': 556,
  14334. 'daggerdbl': 556,
  14335. 'periodcentered': 278,
  14336. 'paragraph': 537,
  14337. 'bullet': 350,
  14338. 'quotesinglbase': 222,
  14339. 'quotedblbase': 333,
  14340. 'quotedblright': 333,
  14341. 'guillemotright': 556,
  14342. 'ellipsis': 1000,
  14343. 'perthousand': 1000,
  14344. 'questiondown': 611,
  14345. 'grave': 333,
  14346. 'acute': 333,
  14347. 'circumflex': 333,
  14348. 'tilde': 333,
  14349. 'macron': 333,
  14350. 'breve': 333,
  14351. 'dotaccent': 333,
  14352. 'dieresis': 333,
  14353. 'ring': 333,
  14354. 'cedilla': 333,
  14355. 'hungarumlaut': 333,
  14356. 'ogonek': 333,
  14357. 'caron': 333,
  14358. 'emdash': 1000,
  14359. 'AE': 1000,
  14360. 'ordfeminine': 370,
  14361. 'Lslash': 556,
  14362. 'Oslash': 778,
  14363. 'OE': 1000,
  14364. 'ordmasculine': 365,
  14365. 'ae': 889,
  14366. 'dotlessi': 278,
  14367. 'lslash': 222,
  14368. 'oslash': 611,
  14369. 'oe': 944,
  14370. 'germandbls': 611,
  14371. 'Idieresis': 278,
  14372. 'eacute': 556,
  14373. 'abreve': 556,
  14374. 'uhungarumlaut': 556,
  14375. 'ecaron': 556,
  14376. 'Ydieresis': 667,
  14377. 'divide': 584,
  14378. 'Yacute': 667,
  14379. 'Acircumflex': 667,
  14380. 'aacute': 556,
  14381. 'Ucircumflex': 722,
  14382. 'yacute': 500,
  14383. 'scommaaccent': 500,
  14384. 'ecircumflex': 556,
  14385. 'Uring': 722,
  14386. 'Udieresis': 722,
  14387. 'aogonek': 556,
  14388. 'Uacute': 722,
  14389. 'uogonek': 556,
  14390. 'Edieresis': 667,
  14391. 'Dcroat': 722,
  14392. 'commaaccent': 250,
  14393. 'copyright': 737,
  14394. 'Emacron': 667,
  14395. 'ccaron': 500,
  14396. 'aring': 556,
  14397. 'Ncommaaccent': 722,
  14398. 'lacute': 222,
  14399. 'agrave': 556,
  14400. 'Tcommaaccent': 611,
  14401. 'Cacute': 722,
  14402. 'atilde': 556,
  14403. 'Edotaccent': 667,
  14404. 'scaron': 500,
  14405. 'scedilla': 500,
  14406. 'iacute': 278,
  14407. 'lozenge': 471,
  14408. 'Rcaron': 722,
  14409. 'Gcommaaccent': 778,
  14410. 'ucircumflex': 556,
  14411. 'acircumflex': 556,
  14412. 'Amacron': 667,
  14413. 'rcaron': 333,
  14414. 'ccedilla': 500,
  14415. 'Zdotaccent': 611,
  14416. 'Thorn': 667,
  14417. 'Omacron': 778,
  14418. 'Racute': 722,
  14419. 'Sacute': 667,
  14420. 'dcaron': 643,
  14421. 'Umacron': 722,
  14422. 'uring': 556,
  14423. 'threesuperior': 333,
  14424. 'Ograve': 778,
  14425. 'Agrave': 667,
  14426. 'Abreve': 667,
  14427. 'multiply': 584,
  14428. 'uacute': 556,
  14429. 'Tcaron': 611,
  14430. 'partialdiff': 476,
  14431. 'ydieresis': 500,
  14432. 'Nacute': 722,
  14433. 'icircumflex': 278,
  14434. 'Ecircumflex': 667,
  14435. 'adieresis': 556,
  14436. 'edieresis': 556,
  14437. 'cacute': 500,
  14438. 'nacute': 556,
  14439. 'umacron': 556,
  14440. 'Ncaron': 722,
  14441. 'Iacute': 278,
  14442. 'plusminus': 584,
  14443. 'brokenbar': 260,
  14444. 'registered': 737,
  14445. 'Gbreve': 778,
  14446. 'Idotaccent': 278,
  14447. 'summation': 600,
  14448. 'Egrave': 667,
  14449. 'racute': 333,
  14450. 'omacron': 556,
  14451. 'Zacute': 611,
  14452. 'Zcaron': 611,
  14453. 'greaterequal': 549,
  14454. 'Eth': 722,
  14455. 'Ccedilla': 722,
  14456. 'lcommaaccent': 222,
  14457. 'tcaron': 317,
  14458. 'eogonek': 556,
  14459. 'Uogonek': 722,
  14460. 'Aacute': 667,
  14461. 'Adieresis': 667,
  14462. 'egrave': 556,
  14463. 'zacute': 500,
  14464. 'iogonek': 222,
  14465. 'Oacute': 778,
  14466. 'oacute': 556,
  14467. 'amacron': 556,
  14468. 'sacute': 500,
  14469. 'idieresis': 278,
  14470. 'Ocircumflex': 778,
  14471. 'Ugrave': 722,
  14472. 'Delta': 612,
  14473. 'thorn': 556,
  14474. 'twosuperior': 333,
  14475. 'Odieresis': 778,
  14476. 'mu': 556,
  14477. 'igrave': 278,
  14478. 'ohungarumlaut': 556,
  14479. 'Eogonek': 667,
  14480. 'dcroat': 556,
  14481. 'threequarters': 834,
  14482. 'Scedilla': 667,
  14483. 'lcaron': 299,
  14484. 'Kcommaaccent': 667,
  14485. 'Lacute': 556,
  14486. 'trademark': 1000,
  14487. 'edotaccent': 556,
  14488. 'Igrave': 278,
  14489. 'Imacron': 278,
  14490. 'Lcaron': 556,
  14491. 'onehalf': 834,
  14492. 'lessequal': 549,
  14493. 'ocircumflex': 556,
  14494. 'ntilde': 556,
  14495. 'Uhungarumlaut': 722,
  14496. 'Eacute': 667,
  14497. 'emacron': 556,
  14498. 'gbreve': 556,
  14499. 'onequarter': 834,
  14500. 'Scaron': 667,
  14501. 'Scommaaccent': 667,
  14502. 'Ohungarumlaut': 778,
  14503. 'degree': 400,
  14504. 'ograve': 556,
  14505. 'Ccaron': 722,
  14506. 'ugrave': 556,
  14507. 'radical': 453,
  14508. 'Dcaron': 722,
  14509. 'rcommaaccent': 333,
  14510. 'Ntilde': 722,
  14511. 'otilde': 556,
  14512. 'Rcommaaccent': 722,
  14513. 'Lcommaaccent': 556,
  14514. 'Atilde': 667,
  14515. 'Aogonek': 667,
  14516. 'Aring': 667,
  14517. 'Otilde': 778,
  14518. 'zdotaccent': 500,
  14519. 'Ecaron': 667,
  14520. 'Iogonek': 278,
  14521. 'kcommaaccent': 500,
  14522. 'minus': 584,
  14523. 'Icircumflex': 278,
  14524. 'ncaron': 556,
  14525. 'tcommaaccent': 278,
  14526. 'logicalnot': 584,
  14527. 'odieresis': 556,
  14528. 'udieresis': 556,
  14529. 'notequal': 549,
  14530. 'gcommaaccent': 556,
  14531. 'eth': 556,
  14532. 'zcaron': 500,
  14533. 'ncommaaccent': 556,
  14534. 'onesuperior': 333,
  14535. 'imacron': 278,
  14536. 'Euro': 556
  14537. },
  14538. 'Helvetica-Bold': {
  14539. 'space': 278,
  14540. 'exclam': 333,
  14541. 'quotedbl': 474,
  14542. 'numbersign': 556,
  14543. 'dollar': 556,
  14544. 'percent': 889,
  14545. 'ampersand': 722,
  14546. 'quoteright': 278,
  14547. 'parenleft': 333,
  14548. 'parenright': 333,
  14549. 'asterisk': 389,
  14550. 'plus': 584,
  14551. 'comma': 278,
  14552. 'hyphen': 333,
  14553. 'period': 278,
  14554. 'slash': 278,
  14555. 'zero': 556,
  14556. 'one': 556,
  14557. 'two': 556,
  14558. 'three': 556,
  14559. 'four': 556,
  14560. 'five': 556,
  14561. 'six': 556,
  14562. 'seven': 556,
  14563. 'eight': 556,
  14564. 'nine': 556,
  14565. 'colon': 333,
  14566. 'semicolon': 333,
  14567. 'less': 584,
  14568. 'equal': 584,
  14569. 'greater': 584,
  14570. 'question': 611,
  14571. 'at': 975,
  14572. 'A': 722,
  14573. 'B': 722,
  14574. 'C': 722,
  14575. 'D': 722,
  14576. 'E': 667,
  14577. 'F': 611,
  14578. 'G': 778,
  14579. 'H': 722,
  14580. 'I': 278,
  14581. 'J': 556,
  14582. 'K': 722,
  14583. 'L': 611,
  14584. 'M': 833,
  14585. 'N': 722,
  14586. 'O': 778,
  14587. 'P': 667,
  14588. 'Q': 778,
  14589. 'R': 722,
  14590. 'S': 667,
  14591. 'T': 611,
  14592. 'U': 722,
  14593. 'V': 667,
  14594. 'W': 944,
  14595. 'X': 667,
  14596. 'Y': 667,
  14597. 'Z': 611,
  14598. 'bracketleft': 333,
  14599. 'backslash': 278,
  14600. 'bracketright': 333,
  14601. 'asciicircum': 584,
  14602. 'underscore': 556,
  14603. 'quoteleft': 278,
  14604. 'a': 556,
  14605. 'b': 611,
  14606. 'c': 556,
  14607. 'd': 611,
  14608. 'e': 556,
  14609. 'f': 333,
  14610. 'g': 611,
  14611. 'h': 611,
  14612. 'i': 278,
  14613. 'j': 278,
  14614. 'k': 556,
  14615. 'l': 278,
  14616. 'm': 889,
  14617. 'n': 611,
  14618. 'o': 611,
  14619. 'p': 611,
  14620. 'q': 611,
  14621. 'r': 389,
  14622. 's': 556,
  14623. 't': 333,
  14624. 'u': 611,
  14625. 'v': 556,
  14626. 'w': 778,
  14627. 'x': 556,
  14628. 'y': 556,
  14629. 'z': 500,
  14630. 'braceleft': 389,
  14631. 'bar': 280,
  14632. 'braceright': 389,
  14633. 'asciitilde': 584,
  14634. 'exclamdown': 333,
  14635. 'cent': 556,
  14636. 'sterling': 556,
  14637. 'fraction': 167,
  14638. 'yen': 556,
  14639. 'florin': 556,
  14640. 'section': 556,
  14641. 'currency': 556,
  14642. 'quotesingle': 238,
  14643. 'quotedblleft': 500,
  14644. 'guillemotleft': 556,
  14645. 'guilsinglleft': 333,
  14646. 'guilsinglright': 333,
  14647. 'fi': 611,
  14648. 'fl': 611,
  14649. 'endash': 556,
  14650. 'dagger': 556,
  14651. 'daggerdbl': 556,
  14652. 'periodcentered': 278,
  14653. 'paragraph': 556,
  14654. 'bullet': 350,
  14655. 'quotesinglbase': 278,
  14656. 'quotedblbase': 500,
  14657. 'quotedblright': 500,
  14658. 'guillemotright': 556,
  14659. 'ellipsis': 1000,
  14660. 'perthousand': 1000,
  14661. 'questiondown': 611,
  14662. 'grave': 333,
  14663. 'acute': 333,
  14664. 'circumflex': 333,
  14665. 'tilde': 333,
  14666. 'macron': 333,
  14667. 'breve': 333,
  14668. 'dotaccent': 333,
  14669. 'dieresis': 333,
  14670. 'ring': 333,
  14671. 'cedilla': 333,
  14672. 'hungarumlaut': 333,
  14673. 'ogonek': 333,
  14674. 'caron': 333,
  14675. 'emdash': 1000,
  14676. 'AE': 1000,
  14677. 'ordfeminine': 370,
  14678. 'Lslash': 611,
  14679. 'Oslash': 778,
  14680. 'OE': 1000,
  14681. 'ordmasculine': 365,
  14682. 'ae': 889,
  14683. 'dotlessi': 278,
  14684. 'lslash': 278,
  14685. 'oslash': 611,
  14686. 'oe': 944,
  14687. 'germandbls': 611,
  14688. 'Idieresis': 278,
  14689. 'eacute': 556,
  14690. 'abreve': 556,
  14691. 'uhungarumlaut': 611,
  14692. 'ecaron': 556,
  14693. 'Ydieresis': 667,
  14694. 'divide': 584,
  14695. 'Yacute': 667,
  14696. 'Acircumflex': 722,
  14697. 'aacute': 556,
  14698. 'Ucircumflex': 722,
  14699. 'yacute': 556,
  14700. 'scommaaccent': 556,
  14701. 'ecircumflex': 556,
  14702. 'Uring': 722,
  14703. 'Udieresis': 722,
  14704. 'aogonek': 556,
  14705. 'Uacute': 722,
  14706. 'uogonek': 611,
  14707. 'Edieresis': 667,
  14708. 'Dcroat': 722,
  14709. 'commaaccent': 250,
  14710. 'copyright': 737,
  14711. 'Emacron': 667,
  14712. 'ccaron': 556,
  14713. 'aring': 556,
  14714. 'Ncommaaccent': 722,
  14715. 'lacute': 278,
  14716. 'agrave': 556,
  14717. 'Tcommaaccent': 611,
  14718. 'Cacute': 722,
  14719. 'atilde': 556,
  14720. 'Edotaccent': 667,
  14721. 'scaron': 556,
  14722. 'scedilla': 556,
  14723. 'iacute': 278,
  14724. 'lozenge': 494,
  14725. 'Rcaron': 722,
  14726. 'Gcommaaccent': 778,
  14727. 'ucircumflex': 611,
  14728. 'acircumflex': 556,
  14729. 'Amacron': 722,
  14730. 'rcaron': 389,
  14731. 'ccedilla': 556,
  14732. 'Zdotaccent': 611,
  14733. 'Thorn': 667,
  14734. 'Omacron': 778,
  14735. 'Racute': 722,
  14736. 'Sacute': 667,
  14737. 'dcaron': 743,
  14738. 'Umacron': 722,
  14739. 'uring': 611,
  14740. 'threesuperior': 333,
  14741. 'Ograve': 778,
  14742. 'Agrave': 722,
  14743. 'Abreve': 722,
  14744. 'multiply': 584,
  14745. 'uacute': 611,
  14746. 'Tcaron': 611,
  14747. 'partialdiff': 494,
  14748. 'ydieresis': 556,
  14749. 'Nacute': 722,
  14750. 'icircumflex': 278,
  14751. 'Ecircumflex': 667,
  14752. 'adieresis': 556,
  14753. 'edieresis': 556,
  14754. 'cacute': 556,
  14755. 'nacute': 611,
  14756. 'umacron': 611,
  14757. 'Ncaron': 722,
  14758. 'Iacute': 278,
  14759. 'plusminus': 584,
  14760. 'brokenbar': 280,
  14761. 'registered': 737,
  14762. 'Gbreve': 778,
  14763. 'Idotaccent': 278,
  14764. 'summation': 600,
  14765. 'Egrave': 667,
  14766. 'racute': 389,
  14767. 'omacron': 611,
  14768. 'Zacute': 611,
  14769. 'Zcaron': 611,
  14770. 'greaterequal': 549,
  14771. 'Eth': 722,
  14772. 'Ccedilla': 722,
  14773. 'lcommaaccent': 278,
  14774. 'tcaron': 389,
  14775. 'eogonek': 556,
  14776. 'Uogonek': 722,
  14777. 'Aacute': 722,
  14778. 'Adieresis': 722,
  14779. 'egrave': 556,
  14780. 'zacute': 500,
  14781. 'iogonek': 278,
  14782. 'Oacute': 778,
  14783. 'oacute': 611,
  14784. 'amacron': 556,
  14785. 'sacute': 556,
  14786. 'idieresis': 278,
  14787. 'Ocircumflex': 778,
  14788. 'Ugrave': 722,
  14789. 'Delta': 612,
  14790. 'thorn': 611,
  14791. 'twosuperior': 333,
  14792. 'Odieresis': 778,
  14793. 'mu': 611,
  14794. 'igrave': 278,
  14795. 'ohungarumlaut': 611,
  14796. 'Eogonek': 667,
  14797. 'dcroat': 611,
  14798. 'threequarters': 834,
  14799. 'Scedilla': 667,
  14800. 'lcaron': 400,
  14801. 'Kcommaaccent': 722,
  14802. 'Lacute': 611,
  14803. 'trademark': 1000,
  14804. 'edotaccent': 556,
  14805. 'Igrave': 278,
  14806. 'Imacron': 278,
  14807. 'Lcaron': 611,
  14808. 'onehalf': 834,
  14809. 'lessequal': 549,
  14810. 'ocircumflex': 611,
  14811. 'ntilde': 611,
  14812. 'Uhungarumlaut': 722,
  14813. 'Eacute': 667,
  14814. 'emacron': 556,
  14815. 'gbreve': 611,
  14816. 'onequarter': 834,
  14817. 'Scaron': 667,
  14818. 'Scommaaccent': 667,
  14819. 'Ohungarumlaut': 778,
  14820. 'degree': 400,
  14821. 'ograve': 611,
  14822. 'Ccaron': 722,
  14823. 'ugrave': 611,
  14824. 'radical': 549,
  14825. 'Dcaron': 722,
  14826. 'rcommaaccent': 389,
  14827. 'Ntilde': 722,
  14828. 'otilde': 611,
  14829. 'Rcommaaccent': 722,
  14830. 'Lcommaaccent': 611,
  14831. 'Atilde': 722,
  14832. 'Aogonek': 722,
  14833. 'Aring': 722,
  14834. 'Otilde': 778,
  14835. 'zdotaccent': 500,
  14836. 'Ecaron': 667,
  14837. 'Iogonek': 278,
  14838. 'kcommaaccent': 556,
  14839. 'minus': 584,
  14840. 'Icircumflex': 278,
  14841. 'ncaron': 611,
  14842. 'tcommaaccent': 333,
  14843. 'logicalnot': 584,
  14844. 'odieresis': 611,
  14845. 'udieresis': 611,
  14846. 'notequal': 549,
  14847. 'gcommaaccent': 611,
  14848. 'eth': 611,
  14849. 'zcaron': 500,
  14850. 'ncommaaccent': 611,
  14851. 'onesuperior': 333,
  14852. 'imacron': 278,
  14853. 'Euro': 556
  14854. },
  14855. 'Helvetica-BoldOblique': {
  14856. 'space': 278,
  14857. 'exclam': 333,
  14858. 'quotedbl': 474,
  14859. 'numbersign': 556,
  14860. 'dollar': 556,
  14861. 'percent': 889,
  14862. 'ampersand': 722,
  14863. 'quoteright': 278,
  14864. 'parenleft': 333,
  14865. 'parenright': 333,
  14866. 'asterisk': 389,
  14867. 'plus': 584,
  14868. 'comma': 278,
  14869. 'hyphen': 333,
  14870. 'period': 278,
  14871. 'slash': 278,
  14872. 'zero': 556,
  14873. 'one': 556,
  14874. 'two': 556,
  14875. 'three': 556,
  14876. 'four': 556,
  14877. 'five': 556,
  14878. 'six': 556,
  14879. 'seven': 556,
  14880. 'eight': 556,
  14881. 'nine': 556,
  14882. 'colon': 333,
  14883. 'semicolon': 333,
  14884. 'less': 584,
  14885. 'equal': 584,
  14886. 'greater': 584,
  14887. 'question': 611,
  14888. 'at': 975,
  14889. 'A': 722,
  14890. 'B': 722,
  14891. 'C': 722,
  14892. 'D': 722,
  14893. 'E': 667,
  14894. 'F': 611,
  14895. 'G': 778,
  14896. 'H': 722,
  14897. 'I': 278,
  14898. 'J': 556,
  14899. 'K': 722,
  14900. 'L': 611,
  14901. 'M': 833,
  14902. 'N': 722,
  14903. 'O': 778,
  14904. 'P': 667,
  14905. 'Q': 778,
  14906. 'R': 722,
  14907. 'S': 667,
  14908. 'T': 611,
  14909. 'U': 722,
  14910. 'V': 667,
  14911. 'W': 944,
  14912. 'X': 667,
  14913. 'Y': 667,
  14914. 'Z': 611,
  14915. 'bracketleft': 333,
  14916. 'backslash': 278,
  14917. 'bracketright': 333,
  14918. 'asciicircum': 584,
  14919. 'underscore': 556,
  14920. 'quoteleft': 278,
  14921. 'a': 556,
  14922. 'b': 611,
  14923. 'c': 556,
  14924. 'd': 611,
  14925. 'e': 556,
  14926. 'f': 333,
  14927. 'g': 611,
  14928. 'h': 611,
  14929. 'i': 278,
  14930. 'j': 278,
  14931. 'k': 556,
  14932. 'l': 278,
  14933. 'm': 889,
  14934. 'n': 611,
  14935. 'o': 611,
  14936. 'p': 611,
  14937. 'q': 611,
  14938. 'r': 389,
  14939. 's': 556,
  14940. 't': 333,
  14941. 'u': 611,
  14942. 'v': 556,
  14943. 'w': 778,
  14944. 'x': 556,
  14945. 'y': 556,
  14946. 'z': 500,
  14947. 'braceleft': 389,
  14948. 'bar': 280,
  14949. 'braceright': 389,
  14950. 'asciitilde': 584,
  14951. 'exclamdown': 333,
  14952. 'cent': 556,
  14953. 'sterling': 556,
  14954. 'fraction': 167,
  14955. 'yen': 556,
  14956. 'florin': 556,
  14957. 'section': 556,
  14958. 'currency': 556,
  14959. 'quotesingle': 238,
  14960. 'quotedblleft': 500,
  14961. 'guillemotleft': 556,
  14962. 'guilsinglleft': 333,
  14963. 'guilsinglright': 333,
  14964. 'fi': 611,
  14965. 'fl': 611,
  14966. 'endash': 556,
  14967. 'dagger': 556,
  14968. 'daggerdbl': 556,
  14969. 'periodcentered': 278,
  14970. 'paragraph': 556,
  14971. 'bullet': 350,
  14972. 'quotesinglbase': 278,
  14973. 'quotedblbase': 500,
  14974. 'quotedblright': 500,
  14975. 'guillemotright': 556,
  14976. 'ellipsis': 1000,
  14977. 'perthousand': 1000,
  14978. 'questiondown': 611,
  14979. 'grave': 333,
  14980. 'acute': 333,
  14981. 'circumflex': 333,
  14982. 'tilde': 333,
  14983. 'macron': 333,
  14984. 'breve': 333,
  14985. 'dotaccent': 333,
  14986. 'dieresis': 333,
  14987. 'ring': 333,
  14988. 'cedilla': 333,
  14989. 'hungarumlaut': 333,
  14990. 'ogonek': 333,
  14991. 'caron': 333,
  14992. 'emdash': 1000,
  14993. 'AE': 1000,
  14994. 'ordfeminine': 370,
  14995. 'Lslash': 611,
  14996. 'Oslash': 778,
  14997. 'OE': 1000,
  14998. 'ordmasculine': 365,
  14999. 'ae': 889,
  15000. 'dotlessi': 278,
  15001. 'lslash': 278,
  15002. 'oslash': 611,
  15003. 'oe': 944,
  15004. 'germandbls': 611,
  15005. 'Idieresis': 278,
  15006. 'eacute': 556,
  15007. 'abreve': 556,
  15008. 'uhungarumlaut': 611,
  15009. 'ecaron': 556,
  15010. 'Ydieresis': 667,
  15011. 'divide': 584,
  15012. 'Yacute': 667,
  15013. 'Acircumflex': 722,
  15014. 'aacute': 556,
  15015. 'Ucircumflex': 722,
  15016. 'yacute': 556,
  15017. 'scommaaccent': 556,
  15018. 'ecircumflex': 556,
  15019. 'Uring': 722,
  15020. 'Udieresis': 722,
  15021. 'aogonek': 556,
  15022. 'Uacute': 722,
  15023. 'uogonek': 611,
  15024. 'Edieresis': 667,
  15025. 'Dcroat': 722,
  15026. 'commaaccent': 250,
  15027. 'copyright': 737,
  15028. 'Emacron': 667,
  15029. 'ccaron': 556,
  15030. 'aring': 556,
  15031. 'Ncommaaccent': 722,
  15032. 'lacute': 278,
  15033. 'agrave': 556,
  15034. 'Tcommaaccent': 611,
  15035. 'Cacute': 722,
  15036. 'atilde': 556,
  15037. 'Edotaccent': 667,
  15038. 'scaron': 556,
  15039. 'scedilla': 556,
  15040. 'iacute': 278,
  15041. 'lozenge': 494,
  15042. 'Rcaron': 722,
  15043. 'Gcommaaccent': 778,
  15044. 'ucircumflex': 611,
  15045. 'acircumflex': 556,
  15046. 'Amacron': 722,
  15047. 'rcaron': 389,
  15048. 'ccedilla': 556,
  15049. 'Zdotaccent': 611,
  15050. 'Thorn': 667,
  15051. 'Omacron': 778,
  15052. 'Racute': 722,
  15053. 'Sacute': 667,
  15054. 'dcaron': 743,
  15055. 'Umacron': 722,
  15056. 'uring': 611,
  15057. 'threesuperior': 333,
  15058. 'Ograve': 778,
  15059. 'Agrave': 722,
  15060. 'Abreve': 722,
  15061. 'multiply': 584,
  15062. 'uacute': 611,
  15063. 'Tcaron': 611,
  15064. 'partialdiff': 494,
  15065. 'ydieresis': 556,
  15066. 'Nacute': 722,
  15067. 'icircumflex': 278,
  15068. 'Ecircumflex': 667,
  15069. 'adieresis': 556,
  15070. 'edieresis': 556,
  15071. 'cacute': 556,
  15072. 'nacute': 611,
  15073. 'umacron': 611,
  15074. 'Ncaron': 722,
  15075. 'Iacute': 278,
  15076. 'plusminus': 584,
  15077. 'brokenbar': 280,
  15078. 'registered': 737,
  15079. 'Gbreve': 778,
  15080. 'Idotaccent': 278,
  15081. 'summation': 600,
  15082. 'Egrave': 667,
  15083. 'racute': 389,
  15084. 'omacron': 611,
  15085. 'Zacute': 611,
  15086. 'Zcaron': 611,
  15087. 'greaterequal': 549,
  15088. 'Eth': 722,
  15089. 'Ccedilla': 722,
  15090. 'lcommaaccent': 278,
  15091. 'tcaron': 389,
  15092. 'eogonek': 556,
  15093. 'Uogonek': 722,
  15094. 'Aacute': 722,
  15095. 'Adieresis': 722,
  15096. 'egrave': 556,
  15097. 'zacute': 500,
  15098. 'iogonek': 278,
  15099. 'Oacute': 778,
  15100. 'oacute': 611,
  15101. 'amacron': 556,
  15102. 'sacute': 556,
  15103. 'idieresis': 278,
  15104. 'Ocircumflex': 778,
  15105. 'Ugrave': 722,
  15106. 'Delta': 612,
  15107. 'thorn': 611,
  15108. 'twosuperior': 333,
  15109. 'Odieresis': 778,
  15110. 'mu': 611,
  15111. 'igrave': 278,
  15112. 'ohungarumlaut': 611,
  15113. 'Eogonek': 667,
  15114. 'dcroat': 611,
  15115. 'threequarters': 834,
  15116. 'Scedilla': 667,
  15117. 'lcaron': 400,
  15118. 'Kcommaaccent': 722,
  15119. 'Lacute': 611,
  15120. 'trademark': 1000,
  15121. 'edotaccent': 556,
  15122. 'Igrave': 278,
  15123. 'Imacron': 278,
  15124. 'Lcaron': 611,
  15125. 'onehalf': 834,
  15126. 'lessequal': 549,
  15127. 'ocircumflex': 611,
  15128. 'ntilde': 611,
  15129. 'Uhungarumlaut': 722,
  15130. 'Eacute': 667,
  15131. 'emacron': 556,
  15132. 'gbreve': 611,
  15133. 'onequarter': 834,
  15134. 'Scaron': 667,
  15135. 'Scommaaccent': 667,
  15136. 'Ohungarumlaut': 778,
  15137. 'degree': 400,
  15138. 'ograve': 611,
  15139. 'Ccaron': 722,
  15140. 'ugrave': 611,
  15141. 'radical': 549,
  15142. 'Dcaron': 722,
  15143. 'rcommaaccent': 389,
  15144. 'Ntilde': 722,
  15145. 'otilde': 611,
  15146. 'Rcommaaccent': 722,
  15147. 'Lcommaaccent': 611,
  15148. 'Atilde': 722,
  15149. 'Aogonek': 722,
  15150. 'Aring': 722,
  15151. 'Otilde': 778,
  15152. 'zdotaccent': 500,
  15153. 'Ecaron': 667,
  15154. 'Iogonek': 278,
  15155. 'kcommaaccent': 556,
  15156. 'minus': 584,
  15157. 'Icircumflex': 278,
  15158. 'ncaron': 611,
  15159. 'tcommaaccent': 333,
  15160. 'logicalnot': 584,
  15161. 'odieresis': 611,
  15162. 'udieresis': 611,
  15163. 'notequal': 549,
  15164. 'gcommaaccent': 611,
  15165. 'eth': 611,
  15166. 'zcaron': 500,
  15167. 'ncommaaccent': 611,
  15168. 'onesuperior': 333,
  15169. 'imacron': 278,
  15170. 'Euro': 556
  15171. },
  15172. 'Helvetica-Oblique' : {
  15173. 'space': 278,
  15174. 'exclam': 278,
  15175. 'quotedbl': 355,
  15176. 'numbersign': 556,
  15177. 'dollar': 556,
  15178. 'percent': 889,
  15179. 'ampersand': 667,
  15180. 'quoteright': 222,
  15181. 'parenleft': 333,
  15182. 'parenright': 333,
  15183. 'asterisk': 389,
  15184. 'plus': 584,
  15185. 'comma': 278,
  15186. 'hyphen': 333,
  15187. 'period': 278,
  15188. 'slash': 278,
  15189. 'zero': 556,
  15190. 'one': 556,
  15191. 'two': 556,
  15192. 'three': 556,
  15193. 'four': 556,
  15194. 'five': 556,
  15195. 'six': 556,
  15196. 'seven': 556,
  15197. 'eight': 556,
  15198. 'nine': 556,
  15199. 'colon': 278,
  15200. 'semicolon': 278,
  15201. 'less': 584,
  15202. 'equal': 584,
  15203. 'greater': 584,
  15204. 'question': 556,
  15205. 'at': 1015,
  15206. 'A': 667,
  15207. 'B': 667,
  15208. 'C': 722,
  15209. 'D': 722,
  15210. 'E': 667,
  15211. 'F': 611,
  15212. 'G': 778,
  15213. 'H': 722,
  15214. 'I': 278,
  15215. 'J': 500,
  15216. 'K': 667,
  15217. 'L': 556,
  15218. 'M': 833,
  15219. 'N': 722,
  15220. 'O': 778,
  15221. 'P': 667,
  15222. 'Q': 778,
  15223. 'R': 722,
  15224. 'S': 667,
  15225. 'T': 611,
  15226. 'U': 722,
  15227. 'V': 667,
  15228. 'W': 944,
  15229. 'X': 667,
  15230. 'Y': 667,
  15231. 'Z': 611,
  15232. 'bracketleft': 278,
  15233. 'backslash': 278,
  15234. 'bracketright': 278,
  15235. 'asciicircum': 469,
  15236. 'underscore': 556,
  15237. 'quoteleft': 222,
  15238. 'a': 556,
  15239. 'b': 556,
  15240. 'c': 500,
  15241. 'd': 556,
  15242. 'e': 556,
  15243. 'f': 278,
  15244. 'g': 556,
  15245. 'h': 556,
  15246. 'i': 222,
  15247. 'j': 222,
  15248. 'k': 500,
  15249. 'l': 222,
  15250. 'm': 833,
  15251. 'n': 556,
  15252. 'o': 556,
  15253. 'p': 556,
  15254. 'q': 556,
  15255. 'r': 333,
  15256. 's': 500,
  15257. 't': 278,
  15258. 'u': 556,
  15259. 'v': 500,
  15260. 'w': 722,
  15261. 'x': 500,
  15262. 'y': 500,
  15263. 'z': 500,
  15264. 'braceleft': 334,
  15265. 'bar': 260,
  15266. 'braceright': 334,
  15267. 'asciitilde': 584,
  15268. 'exclamdown': 333,
  15269. 'cent': 556,
  15270. 'sterling': 556,
  15271. 'fraction': 167,
  15272. 'yen': 556,
  15273. 'florin': 556,
  15274. 'section': 556,
  15275. 'currency': 556,
  15276. 'quotesingle': 191,
  15277. 'quotedblleft': 333,
  15278. 'guillemotleft': 556,
  15279. 'guilsinglleft': 333,
  15280. 'guilsinglright': 333,
  15281. 'fi': 500,
  15282. 'fl': 500,
  15283. 'endash': 556,
  15284. 'dagger': 556,
  15285. 'daggerdbl': 556,
  15286. 'periodcentered': 278,
  15287. 'paragraph': 537,
  15288. 'bullet': 350,
  15289. 'quotesinglbase': 222,
  15290. 'quotedblbase': 333,
  15291. 'quotedblright': 333,
  15292. 'guillemotright': 556,
  15293. 'ellipsis': 1000,
  15294. 'perthousand': 1000,
  15295. 'questiondown': 611,
  15296. 'grave': 333,
  15297. 'acute': 333,
  15298. 'circumflex': 333,
  15299. 'tilde': 333,
  15300. 'macron': 333,
  15301. 'breve': 333,
  15302. 'dotaccent': 333,
  15303. 'dieresis': 333,
  15304. 'ring': 333,
  15305. 'cedilla': 333,
  15306. 'hungarumlaut': 333,
  15307. 'ogonek': 333,
  15308. 'caron': 333,
  15309. 'emdash': 1000,
  15310. 'AE': 1000,
  15311. 'ordfeminine': 370,
  15312. 'Lslash': 556,
  15313. 'Oslash': 778,
  15314. 'OE': 1000,
  15315. 'ordmasculine': 365,
  15316. 'ae': 889,
  15317. 'dotlessi': 278,
  15318. 'lslash': 222,
  15319. 'oslash': 611,
  15320. 'oe': 944,
  15321. 'germandbls': 611,
  15322. 'Idieresis': 278,
  15323. 'eacute': 556,
  15324. 'abreve': 556,
  15325. 'uhungarumlaut': 556,
  15326. 'ecaron': 556,
  15327. 'Ydieresis': 667,
  15328. 'divide': 584,
  15329. 'Yacute': 667,
  15330. 'Acircumflex': 667,
  15331. 'aacute': 556,
  15332. 'Ucircumflex': 722,
  15333. 'yacute': 500,
  15334. 'scommaaccent': 500,
  15335. 'ecircumflex': 556,
  15336. 'Uring': 722,
  15337. 'Udieresis': 722,
  15338. 'aogonek': 556,
  15339. 'Uacute': 722,
  15340. 'uogonek': 556,
  15341. 'Edieresis': 667,
  15342. 'Dcroat': 722,
  15343. 'commaaccent': 250,
  15344. 'copyright': 737,
  15345. 'Emacron': 667,
  15346. 'ccaron': 500,
  15347. 'aring': 556,
  15348. 'Ncommaaccent': 722,
  15349. 'lacute': 222,
  15350. 'agrave': 556,
  15351. 'Tcommaaccent': 611,
  15352. 'Cacute': 722,
  15353. 'atilde': 556,
  15354. 'Edotaccent': 667,
  15355. 'scaron': 500,
  15356. 'scedilla': 500,
  15357. 'iacute': 278,
  15358. 'lozenge': 471,
  15359. 'Rcaron': 722,
  15360. 'Gcommaaccent': 778,
  15361. 'ucircumflex': 556,
  15362. 'acircumflex': 556,
  15363. 'Amacron': 667,
  15364. 'rcaron': 333,
  15365. 'ccedilla': 500,
  15366. 'Zdotaccent': 611,
  15367. 'Thorn': 667,
  15368. 'Omacron': 778,
  15369. 'Racute': 722,
  15370. 'Sacute': 667,
  15371. 'dcaron': 643,
  15372. 'Umacron': 722,
  15373. 'uring': 556,
  15374. 'threesuperior': 333,
  15375. 'Ograve': 778,
  15376. 'Agrave': 667,
  15377. 'Abreve': 667,
  15378. 'multiply': 584,
  15379. 'uacute': 556,
  15380. 'Tcaron': 611,
  15381. 'partialdiff': 476,
  15382. 'ydieresis': 500,
  15383. 'Nacute': 722,
  15384. 'icircumflex': 278,
  15385. 'Ecircumflex': 667,
  15386. 'adieresis': 556,
  15387. 'edieresis': 556,
  15388. 'cacute': 500,
  15389. 'nacute': 556,
  15390. 'umacron': 556,
  15391. 'Ncaron': 722,
  15392. 'Iacute': 278,
  15393. 'plusminus': 584,
  15394. 'brokenbar': 260,
  15395. 'registered': 737,
  15396. 'Gbreve': 778,
  15397. 'Idotaccent': 278,
  15398. 'summation': 600,
  15399. 'Egrave': 667,
  15400. 'racute': 333,
  15401. 'omacron': 556,
  15402. 'Zacute': 611,
  15403. 'Zcaron': 611,
  15404. 'greaterequal': 549,
  15405. 'Eth': 722,
  15406. 'Ccedilla': 722,
  15407. 'lcommaaccent': 222,
  15408. 'tcaron': 317,
  15409. 'eogonek': 556,
  15410. 'Uogonek': 722,
  15411. 'Aacute': 667,
  15412. 'Adieresis': 667,
  15413. 'egrave': 556,
  15414. 'zacute': 500,
  15415. 'iogonek': 222,
  15416. 'Oacute': 778,
  15417. 'oacute': 556,
  15418. 'amacron': 556,
  15419. 'sacute': 500,
  15420. 'idieresis': 278,
  15421. 'Ocircumflex': 778,
  15422. 'Ugrave': 722,
  15423. 'Delta': 612,
  15424. 'thorn': 556,
  15425. 'twosuperior': 333,
  15426. 'Odieresis': 778,
  15427. 'mu': 556,
  15428. 'igrave': 278,
  15429. 'ohungarumlaut': 556,
  15430. 'Eogonek': 667,
  15431. 'dcroat': 556,
  15432. 'threequarters': 834,
  15433. 'Scedilla': 667,
  15434. 'lcaron': 299,
  15435. 'Kcommaaccent': 667,
  15436. 'Lacute': 556,
  15437. 'trademark': 1000,
  15438. 'edotaccent': 556,
  15439. 'Igrave': 278,
  15440. 'Imacron': 278,
  15441. 'Lcaron': 556,
  15442. 'onehalf': 834,
  15443. 'lessequal': 549,
  15444. 'ocircumflex': 556,
  15445. 'ntilde': 556,
  15446. 'Uhungarumlaut': 722,
  15447. 'Eacute': 667,
  15448. 'emacron': 556,
  15449. 'gbreve': 556,
  15450. 'onequarter': 834,
  15451. 'Scaron': 667,
  15452. 'Scommaaccent': 667,
  15453. 'Ohungarumlaut': 778,
  15454. 'degree': 400,
  15455. 'ograve': 556,
  15456. 'Ccaron': 722,
  15457. 'ugrave': 556,
  15458. 'radical': 453,
  15459. 'Dcaron': 722,
  15460. 'rcommaaccent': 333,
  15461. 'Ntilde': 722,
  15462. 'otilde': 556,
  15463. 'Rcommaaccent': 722,
  15464. 'Lcommaaccent': 556,
  15465. 'Atilde': 667,
  15466. 'Aogonek': 667,
  15467. 'Aring': 667,
  15468. 'Otilde': 778,
  15469. 'zdotaccent': 500,
  15470. 'Ecaron': 667,
  15471. 'Iogonek': 278,
  15472. 'kcommaaccent': 500,
  15473. 'minus': 584,
  15474. 'Icircumflex': 278,
  15475. 'ncaron': 556,
  15476. 'tcommaaccent': 278,
  15477. 'logicalnot': 584,
  15478. 'odieresis': 556,
  15479. 'udieresis': 556,
  15480. 'notequal': 549,
  15481. 'gcommaaccent': 556,
  15482. 'eth': 556,
  15483. 'zcaron': 500,
  15484. 'ncommaaccent': 556,
  15485. 'onesuperior': 333,
  15486. 'imacron': 278,
  15487. 'Euro': 556
  15488. },
  15489. 'Symbol': {
  15490. 'space': 250,
  15491. 'exclam': 333,
  15492. 'universal': 713,
  15493. 'numbersign': 500,
  15494. 'existential': 549,
  15495. 'percent': 833,
  15496. 'ampersand': 778,
  15497. 'suchthat': 439,
  15498. 'parenleft': 333,
  15499. 'parenright': 333,
  15500. 'asteriskmath': 500,
  15501. 'plus': 549,
  15502. 'comma': 250,
  15503. 'minus': 549,
  15504. 'period': 250,
  15505. 'slash': 278,
  15506. 'zero': 500,
  15507. 'one': 500,
  15508. 'two': 500,
  15509. 'three': 500,
  15510. 'four': 500,
  15511. 'five': 500,
  15512. 'six': 500,
  15513. 'seven': 500,
  15514. 'eight': 500,
  15515. 'nine': 500,
  15516. 'colon': 278,
  15517. 'semicolon': 278,
  15518. 'less': 549,
  15519. 'equal': 549,
  15520. 'greater': 549,
  15521. 'question': 444,
  15522. 'congruent': 549,
  15523. 'Alpha': 722,
  15524. 'Beta': 667,
  15525. 'Chi': 722,
  15526. 'Delta': 612,
  15527. 'Epsilon': 611,
  15528. 'Phi': 763,
  15529. 'Gamma': 603,
  15530. 'Eta': 722,
  15531. 'Iota': 333,
  15532. 'theta1': 631,
  15533. 'Kappa': 722,
  15534. 'Lambda': 686,
  15535. 'Mu': 889,
  15536. 'Nu': 722,
  15537. 'Omicron': 722,
  15538. 'Pi': 768,
  15539. 'Theta': 741,
  15540. 'Rho': 556,
  15541. 'Sigma': 592,
  15542. 'Tau': 611,
  15543. 'Upsilon': 690,
  15544. 'sigma1': 439,
  15545. 'Omega': 768,
  15546. 'Xi': 645,
  15547. 'Psi': 795,
  15548. 'Zeta': 611,
  15549. 'bracketleft': 333,
  15550. 'therefore': 863,
  15551. 'bracketright': 333,
  15552. 'perpendicular': 658,
  15553. 'underscore': 500,
  15554. 'radicalex': 500,
  15555. 'alpha': 631,
  15556. 'beta': 549,
  15557. 'chi': 549,
  15558. 'delta': 494,
  15559. 'epsilon': 439,
  15560. 'phi': 521,
  15561. 'gamma': 411,
  15562. 'eta': 603,
  15563. 'iota': 329,
  15564. 'phi1': 603,
  15565. 'kappa': 549,
  15566. 'lambda': 549,
  15567. 'mu': 576,
  15568. 'nu': 521,
  15569. 'omicron': 549,
  15570. 'pi': 549,
  15571. 'theta': 521,
  15572. 'rho': 549,
  15573. 'sigma': 603,
  15574. 'tau': 439,
  15575. 'upsilon': 576,
  15576. 'omega1': 713,
  15577. 'omega': 686,
  15578. 'xi': 493,
  15579. 'psi': 686,
  15580. 'zeta': 494,
  15581. 'braceleft': 480,
  15582. 'bar': 200,
  15583. 'braceright': 480,
  15584. 'similar': 549,
  15585. 'Euro': 750,
  15586. 'Upsilon1': 620,
  15587. 'minute': 247,
  15588. 'lessequal': 549,
  15589. 'fraction': 167,
  15590. 'infinity': 713,
  15591. 'florin': 500,
  15592. 'club': 753,
  15593. 'diamond': 753,
  15594. 'heart': 753,
  15595. 'spade': 753,
  15596. 'arrowboth': 1042,
  15597. 'arrowleft': 987,
  15598. 'arrowup': 603,
  15599. 'arrowright': 987,
  15600. 'arrowdown': 603,
  15601. 'degree': 400,
  15602. 'plusminus': 549,
  15603. 'second': 411,
  15604. 'greaterequal': 549,
  15605. 'multiply': 549,
  15606. 'proportional': 713,
  15607. 'partialdiff': 494,
  15608. 'bullet': 460,
  15609. 'divide': 549,
  15610. 'notequal': 549,
  15611. 'equivalence': 549,
  15612. 'approxequal': 549,
  15613. 'ellipsis': 1000,
  15614. 'arrowvertex': 603,
  15615. 'arrowhorizex': 1000,
  15616. 'carriagereturn': 658,
  15617. 'aleph': 823,
  15618. 'Ifraktur': 686,
  15619. 'Rfraktur': 795,
  15620. 'weierstrass': 987,
  15621. 'circlemultiply': 768,
  15622. 'circleplus': 768,
  15623. 'emptyset': 823,
  15624. 'intersection': 768,
  15625. 'union': 768,
  15626. 'propersuperset': 713,
  15627. 'reflexsuperset': 713,
  15628. 'notsubset': 713,
  15629. 'propersubset': 713,
  15630. 'reflexsubset': 713,
  15631. 'element': 713,
  15632. 'notelement': 713,
  15633. 'angle': 768,
  15634. 'gradient': 713,
  15635. 'registerserif': 790,
  15636. 'copyrightserif': 790,
  15637. 'trademarkserif': 890,
  15638. 'product': 823,
  15639. 'radical': 549,
  15640. 'dotmath': 250,
  15641. 'logicalnot': 713,
  15642. 'logicaland': 603,
  15643. 'logicalor': 603,
  15644. 'arrowdblboth': 1042,
  15645. 'arrowdblleft': 987,
  15646. 'arrowdblup': 603,
  15647. 'arrowdblright': 987,
  15648. 'arrowdbldown': 603,
  15649. 'lozenge': 494,
  15650. 'angleleft': 329,
  15651. 'registersans': 790,
  15652. 'copyrightsans': 790,
  15653. 'trademarksans': 786,
  15654. 'summation': 713,
  15655. 'parenlefttp': 384,
  15656. 'parenleftex': 384,
  15657. 'parenleftbt': 384,
  15658. 'bracketlefttp': 384,
  15659. 'bracketleftex': 384,
  15660. 'bracketleftbt': 384,
  15661. 'bracelefttp': 494,
  15662. 'braceleftmid': 494,
  15663. 'braceleftbt': 494,
  15664. 'braceex': 494,
  15665. 'angleright': 329,
  15666. 'integral': 274,
  15667. 'integraltp': 686,
  15668. 'integralex': 686,
  15669. 'integralbt': 686,
  15670. 'parenrighttp': 384,
  15671. 'parenrightex': 384,
  15672. 'parenrightbt': 384,
  15673. 'bracketrighttp': 384,
  15674. 'bracketrightex': 384,
  15675. 'bracketrightbt': 384,
  15676. 'bracerighttp': 494,
  15677. 'bracerightmid': 494,
  15678. 'bracerightbt': 494,
  15679. 'apple': 790
  15680. },
  15681. 'Times-Roman': {
  15682. 'space': 250,
  15683. 'exclam': 333,
  15684. 'quotedbl': 408,
  15685. 'numbersign': 500,
  15686. 'dollar': 500,
  15687. 'percent': 833,
  15688. 'ampersand': 778,
  15689. 'quoteright': 333,
  15690. 'parenleft': 333,
  15691. 'parenright': 333,
  15692. 'asterisk': 500,
  15693. 'plus': 564,
  15694. 'comma': 250,
  15695. 'hyphen': 333,
  15696. 'period': 250,
  15697. 'slash': 278,
  15698. 'zero': 500,
  15699. 'one': 500,
  15700. 'two': 500,
  15701. 'three': 500,
  15702. 'four': 500,
  15703. 'five': 500,
  15704. 'six': 500,
  15705. 'seven': 500,
  15706. 'eight': 500,
  15707. 'nine': 500,
  15708. 'colon': 278,
  15709. 'semicolon': 278,
  15710. 'less': 564,
  15711. 'equal': 564,
  15712. 'greater': 564,
  15713. 'question': 444,
  15714. 'at': 921,
  15715. 'A': 722,
  15716. 'B': 667,
  15717. 'C': 667,
  15718. 'D': 722,
  15719. 'E': 611,
  15720. 'F': 556,
  15721. 'G': 722,
  15722. 'H': 722,
  15723. 'I': 333,
  15724. 'J': 389,
  15725. 'K': 722,
  15726. 'L': 611,
  15727. 'M': 889,
  15728. 'N': 722,
  15729. 'O': 722,
  15730. 'P': 556,
  15731. 'Q': 722,
  15732. 'R': 667,
  15733. 'S': 556,
  15734. 'T': 611,
  15735. 'U': 722,
  15736. 'V': 722,
  15737. 'W': 944,
  15738. 'X': 722,
  15739. 'Y': 722,
  15740. 'Z': 611,
  15741. 'bracketleft': 333,
  15742. 'backslash': 278,
  15743. 'bracketright': 333,
  15744. 'asciicircum': 469,
  15745. 'underscore': 500,
  15746. 'quoteleft': 333,
  15747. 'a': 444,
  15748. 'b': 500,
  15749. 'c': 444,
  15750. 'd': 500,
  15751. 'e': 444,
  15752. 'f': 333,
  15753. 'g': 500,
  15754. 'h': 500,
  15755. 'i': 278,
  15756. 'j': 278,
  15757. 'k': 500,
  15758. 'l': 278,
  15759. 'm': 778,
  15760. 'n': 500,
  15761. 'o': 500,
  15762. 'p': 500,
  15763. 'q': 500,
  15764. 'r': 333,
  15765. 's': 389,
  15766. 't': 278,
  15767. 'u': 500,
  15768. 'v': 500,
  15769. 'w': 722,
  15770. 'x': 500,
  15771. 'y': 500,
  15772. 'z': 444,
  15773. 'braceleft': 480,
  15774. 'bar': 200,
  15775. 'braceright': 480,
  15776. 'asciitilde': 541,
  15777. 'exclamdown': 333,
  15778. 'cent': 500,
  15779. 'sterling': 500,
  15780. 'fraction': 167,
  15781. 'yen': 500,
  15782. 'florin': 500,
  15783. 'section': 500,
  15784. 'currency': 500,
  15785. 'quotesingle': 180,
  15786. 'quotedblleft': 444,
  15787. 'guillemotleft': 500,
  15788. 'guilsinglleft': 333,
  15789. 'guilsinglright': 333,
  15790. 'fi': 556,
  15791. 'fl': 556,
  15792. 'endash': 500,
  15793. 'dagger': 500,
  15794. 'daggerdbl': 500,
  15795. 'periodcentered': 250,
  15796. 'paragraph': 453,
  15797. 'bullet': 350,
  15798. 'quotesinglbase': 333,
  15799. 'quotedblbase': 444,
  15800. 'quotedblright': 444,
  15801. 'guillemotright': 500,
  15802. 'ellipsis': 1000,
  15803. 'perthousand': 1000,
  15804. 'questiondown': 444,
  15805. 'grave': 333,
  15806. 'acute': 333,
  15807. 'circumflex': 333,
  15808. 'tilde': 333,
  15809. 'macron': 333,
  15810. 'breve': 333,
  15811. 'dotaccent': 333,
  15812. 'dieresis': 333,
  15813. 'ring': 333,
  15814. 'cedilla': 333,
  15815. 'hungarumlaut': 333,
  15816. 'ogonek': 333,
  15817. 'caron': 333,
  15818. 'emdash': 1000,
  15819. 'AE': 889,
  15820. 'ordfeminine': 276,
  15821. 'Lslash': 611,
  15822. 'Oslash': 722,
  15823. 'OE': 889,
  15824. 'ordmasculine': 310,
  15825. 'ae': 667,
  15826. 'dotlessi': 278,
  15827. 'lslash': 278,
  15828. 'oslash': 500,
  15829. 'oe': 722,
  15830. 'germandbls': 500,
  15831. 'Idieresis': 333,
  15832. 'eacute': 444,
  15833. 'abreve': 444,
  15834. 'uhungarumlaut': 500,
  15835. 'ecaron': 444,
  15836. 'Ydieresis': 722,
  15837. 'divide': 564,
  15838. 'Yacute': 722,
  15839. 'Acircumflex': 722,
  15840. 'aacute': 444,
  15841. 'Ucircumflex': 722,
  15842. 'yacute': 500,
  15843. 'scommaaccent': 389,
  15844. 'ecircumflex': 444,
  15845. 'Uring': 722,
  15846. 'Udieresis': 722,
  15847. 'aogonek': 444,
  15848. 'Uacute': 722,
  15849. 'uogonek': 500,
  15850. 'Edieresis': 611,
  15851. 'Dcroat': 722,
  15852. 'commaaccent': 250,
  15853. 'copyright': 760,
  15854. 'Emacron': 611,
  15855. 'ccaron': 444,
  15856. 'aring': 444,
  15857. 'Ncommaaccent': 722,
  15858. 'lacute': 278,
  15859. 'agrave': 444,
  15860. 'Tcommaaccent': 611,
  15861. 'Cacute': 667,
  15862. 'atilde': 444,
  15863. 'Edotaccent': 611,
  15864. 'scaron': 389,
  15865. 'scedilla': 389,
  15866. 'iacute': 278,
  15867. 'lozenge': 471,
  15868. 'Rcaron': 667,
  15869. 'Gcommaaccent': 722,
  15870. 'ucircumflex': 500,
  15871. 'acircumflex': 444,
  15872. 'Amacron': 722,
  15873. 'rcaron': 333,
  15874. 'ccedilla': 444,
  15875. 'Zdotaccent': 611,
  15876. 'Thorn': 556,
  15877. 'Omacron': 722,
  15878. 'Racute': 667,
  15879. 'Sacute': 556,
  15880. 'dcaron': 588,
  15881. 'Umacron': 722,
  15882. 'uring': 500,
  15883. 'threesuperior': 300,
  15884. 'Ograve': 722,
  15885. 'Agrave': 722,
  15886. 'Abreve': 722,
  15887. 'multiply': 564,
  15888. 'uacute': 500,
  15889. 'Tcaron': 611,
  15890. 'partialdiff': 476,
  15891. 'ydieresis': 500,
  15892. 'Nacute': 722,
  15893. 'icircumflex': 278,
  15894. 'Ecircumflex': 611,
  15895. 'adieresis': 444,
  15896. 'edieresis': 444,
  15897. 'cacute': 444,
  15898. 'nacute': 500,
  15899. 'umacron': 500,
  15900. 'Ncaron': 722,
  15901. 'Iacute': 333,
  15902. 'plusminus': 564,
  15903. 'brokenbar': 200,
  15904. 'registered': 760,
  15905. 'Gbreve': 722,
  15906. 'Idotaccent': 333,
  15907. 'summation': 600,
  15908. 'Egrave': 611,
  15909. 'racute': 333,
  15910. 'omacron': 500,
  15911. 'Zacute': 611,
  15912. 'Zcaron': 611,
  15913. 'greaterequal': 549,
  15914. 'Eth': 722,
  15915. 'Ccedilla': 667,
  15916. 'lcommaaccent': 278,
  15917. 'tcaron': 326,
  15918. 'eogonek': 444,
  15919. 'Uogonek': 722,
  15920. 'Aacute': 722,
  15921. 'Adieresis': 722,
  15922. 'egrave': 444,
  15923. 'zacute': 444,
  15924. 'iogonek': 278,
  15925. 'Oacute': 722,
  15926. 'oacute': 500,
  15927. 'amacron': 444,
  15928. 'sacute': 389,
  15929. 'idieresis': 278,
  15930. 'Ocircumflex': 722,
  15931. 'Ugrave': 722,
  15932. 'Delta': 612,
  15933. 'thorn': 500,
  15934. 'twosuperior': 300,
  15935. 'Odieresis': 722,
  15936. 'mu': 500,
  15937. 'igrave': 278,
  15938. 'ohungarumlaut': 500,
  15939. 'Eogonek': 611,
  15940. 'dcroat': 500,
  15941. 'threequarters': 750,
  15942. 'Scedilla': 556,
  15943. 'lcaron': 344,
  15944. 'Kcommaaccent': 722,
  15945. 'Lacute': 611,
  15946. 'trademark': 980,
  15947. 'edotaccent': 444,
  15948. 'Igrave': 333,
  15949. 'Imacron': 333,
  15950. 'Lcaron': 611,
  15951. 'onehalf': 750,
  15952. 'lessequal': 549,
  15953. 'ocircumflex': 500,
  15954. 'ntilde': 500,
  15955. 'Uhungarumlaut': 722,
  15956. 'Eacute': 611,
  15957. 'emacron': 444,
  15958. 'gbreve': 500,
  15959. 'onequarter': 750,
  15960. 'Scaron': 556,
  15961. 'Scommaaccent': 556,
  15962. 'Ohungarumlaut': 722,
  15963. 'degree': 400,
  15964. 'ograve': 500,
  15965. 'Ccaron': 667,
  15966. 'ugrave': 500,
  15967. 'radical': 453,
  15968. 'Dcaron': 722,
  15969. 'rcommaaccent': 333,
  15970. 'Ntilde': 722,
  15971. 'otilde': 500,
  15972. 'Rcommaaccent': 667,
  15973. 'Lcommaaccent': 611,
  15974. 'Atilde': 722,
  15975. 'Aogonek': 722,
  15976. 'Aring': 722,
  15977. 'Otilde': 722,
  15978. 'zdotaccent': 444,
  15979. 'Ecaron': 611,
  15980. 'Iogonek': 333,
  15981. 'kcommaaccent': 500,
  15982. 'minus': 564,
  15983. 'Icircumflex': 333,
  15984. 'ncaron': 500,
  15985. 'tcommaaccent': 278,
  15986. 'logicalnot': 564,
  15987. 'odieresis': 500,
  15988. 'udieresis': 500,
  15989. 'notequal': 549,
  15990. 'gcommaaccent': 500,
  15991. 'eth': 500,
  15992. 'zcaron': 444,
  15993. 'ncommaaccent': 500,
  15994. 'onesuperior': 300,
  15995. 'imacron': 278,
  15996. 'Euro': 500
  15997. },
  15998. 'Times-Bold': {
  15999. 'space': 250,
  16000. 'exclam': 333,
  16001. 'quotedbl': 555,
  16002. 'numbersign': 500,
  16003. 'dollar': 500,
  16004. 'percent': 1000,
  16005. 'ampersand': 833,
  16006. 'quoteright': 333,
  16007. 'parenleft': 333,
  16008. 'parenright': 333,
  16009. 'asterisk': 500,
  16010. 'plus': 570,
  16011. 'comma': 250,
  16012. 'hyphen': 333,
  16013. 'period': 250,
  16014. 'slash': 278,
  16015. 'zero': 500,
  16016. 'one': 500,
  16017. 'two': 500,
  16018. 'three': 500,
  16019. 'four': 500,
  16020. 'five': 500,
  16021. 'six': 500,
  16022. 'seven': 500,
  16023. 'eight': 500,
  16024. 'nine': 500,
  16025. 'colon': 333,
  16026. 'semicolon': 333,
  16027. 'less': 570,
  16028. 'equal': 570,
  16029. 'greater': 570,
  16030. 'question': 500,
  16031. 'at': 930,
  16032. 'A': 722,
  16033. 'B': 667,
  16034. 'C': 722,
  16035. 'D': 722,
  16036. 'E': 667,
  16037. 'F': 611,
  16038. 'G': 778,
  16039. 'H': 778,
  16040. 'I': 389,
  16041. 'J': 500,
  16042. 'K': 778,
  16043. 'L': 667,
  16044. 'M': 944,
  16045. 'N': 722,
  16046. 'O': 778,
  16047. 'P': 611,
  16048. 'Q': 778,
  16049. 'R': 722,
  16050. 'S': 556,
  16051. 'T': 667,
  16052. 'U': 722,
  16053. 'V': 722,
  16054. 'W': 1000,
  16055. 'X': 722,
  16056. 'Y': 722,
  16057. 'Z': 667,
  16058. 'bracketleft': 333,
  16059. 'backslash': 278,
  16060. 'bracketright': 333,
  16061. 'asciicircum': 581,
  16062. 'underscore': 500,
  16063. 'quoteleft': 333,
  16064. 'a': 500,
  16065. 'b': 556,
  16066. 'c': 444,
  16067. 'd': 556,
  16068. 'e': 444,
  16069. 'f': 333,
  16070. 'g': 500,
  16071. 'h': 556,
  16072. 'i': 278,
  16073. 'j': 333,
  16074. 'k': 556,
  16075. 'l': 278,
  16076. 'm': 833,
  16077. 'n': 556,
  16078. 'o': 500,
  16079. 'p': 556,
  16080. 'q': 556,
  16081. 'r': 444,
  16082. 's': 389,
  16083. 't': 333,
  16084. 'u': 556,
  16085. 'v': 500,
  16086. 'w': 722,
  16087. 'x': 500,
  16088. 'y': 500,
  16089. 'z': 444,
  16090. 'braceleft': 394,
  16091. 'bar': 220,
  16092. 'braceright': 394,
  16093. 'asciitilde': 520,
  16094. 'exclamdown': 333,
  16095. 'cent': 500,
  16096. 'sterling': 500,
  16097. 'fraction': 167,
  16098. 'yen': 500,
  16099. 'florin': 500,
  16100. 'section': 500,
  16101. 'currency': 500,
  16102. 'quotesingle': 278,
  16103. 'quotedblleft': 500,
  16104. 'guillemotleft': 500,
  16105. 'guilsinglleft': 333,
  16106. 'guilsinglright': 333,
  16107. 'fi': 556,
  16108. 'fl': 556,
  16109. 'endash': 500,
  16110. 'dagger': 500,
  16111. 'daggerdbl': 500,
  16112. 'periodcentered': 250,
  16113. 'paragraph': 540,
  16114. 'bullet': 350,
  16115. 'quotesinglbase': 333,
  16116. 'quotedblbase': 500,
  16117. 'quotedblright': 500,
  16118. 'guillemotright': 500,
  16119. 'ellipsis': 1000,
  16120. 'perthousand': 1000,
  16121. 'questiondown': 500,
  16122. 'grave': 333,
  16123. 'acute': 333,
  16124. 'circumflex': 333,
  16125. 'tilde': 333,
  16126. 'macron': 333,
  16127. 'breve': 333,
  16128. 'dotaccent': 333,
  16129. 'dieresis': 333,
  16130. 'ring': 333,
  16131. 'cedilla': 333,
  16132. 'hungarumlaut': 333,
  16133. 'ogonek': 333,
  16134. 'caron': 333,
  16135. 'emdash': 1000,
  16136. 'AE': 1000,
  16137. 'ordfeminine': 300,
  16138. 'Lslash': 667,
  16139. 'Oslash': 778,
  16140. 'OE': 1000,
  16141. 'ordmasculine': 330,
  16142. 'ae': 722,
  16143. 'dotlessi': 278,
  16144. 'lslash': 278,
  16145. 'oslash': 500,
  16146. 'oe': 722,
  16147. 'germandbls': 556,
  16148. 'Idieresis': 389,
  16149. 'eacute': 444,
  16150. 'abreve': 500,
  16151. 'uhungarumlaut': 556,
  16152. 'ecaron': 444,
  16153. 'Ydieresis': 722,
  16154. 'divide': 570,
  16155. 'Yacute': 722,
  16156. 'Acircumflex': 722,
  16157. 'aacute': 500,
  16158. 'Ucircumflex': 722,
  16159. 'yacute': 500,
  16160. 'scommaaccent': 389,
  16161. 'ecircumflex': 444,
  16162. 'Uring': 722,
  16163. 'Udieresis': 722,
  16164. 'aogonek': 500,
  16165. 'Uacute': 722,
  16166. 'uogonek': 556,
  16167. 'Edieresis': 667,
  16168. 'Dcroat': 722,
  16169. 'commaaccent': 250,
  16170. 'copyright': 747,
  16171. 'Emacron': 667,
  16172. 'ccaron': 444,
  16173. 'aring': 500,
  16174. 'Ncommaaccent': 722,
  16175. 'lacute': 278,
  16176. 'agrave': 500,
  16177. 'Tcommaaccent': 667,
  16178. 'Cacute': 722,
  16179. 'atilde': 500,
  16180. 'Edotaccent': 667,
  16181. 'scaron': 389,
  16182. 'scedilla': 389,
  16183. 'iacute': 278,
  16184. 'lozenge': 494,
  16185. 'Rcaron': 722,
  16186. 'Gcommaaccent': 778,
  16187. 'ucircumflex': 556,
  16188. 'acircumflex': 500,
  16189. 'Amacron': 722,
  16190. 'rcaron': 444,
  16191. 'ccedilla': 444,
  16192. 'Zdotaccent': 667,
  16193. 'Thorn': 611,
  16194. 'Omacron': 778,
  16195. 'Racute': 722,
  16196. 'Sacute': 556,
  16197. 'dcaron': 672,
  16198. 'Umacron': 722,
  16199. 'uring': 556,
  16200. 'threesuperior': 300,
  16201. 'Ograve': 778,
  16202. 'Agrave': 722,
  16203. 'Abreve': 722,
  16204. 'multiply': 570,
  16205. 'uacute': 556,
  16206. 'Tcaron': 667,
  16207. 'partialdiff': 494,
  16208. 'ydieresis': 500,
  16209. 'Nacute': 722,
  16210. 'icircumflex': 278,
  16211. 'Ecircumflex': 667,
  16212. 'adieresis': 500,
  16213. 'edieresis': 444,
  16214. 'cacute': 444,
  16215. 'nacute': 556,
  16216. 'umacron': 556,
  16217. 'Ncaron': 722,
  16218. 'Iacute': 389,
  16219. 'plusminus': 570,
  16220. 'brokenbar': 220,
  16221. 'registered': 747,
  16222. 'Gbreve': 778,
  16223. 'Idotaccent': 389,
  16224. 'summation': 600,
  16225. 'Egrave': 667,
  16226. 'racute': 444,
  16227. 'omacron': 500,
  16228. 'Zacute': 667,
  16229. 'Zcaron': 667,
  16230. 'greaterequal': 549,
  16231. 'Eth': 722,
  16232. 'Ccedilla': 722,
  16233. 'lcommaaccent': 278,
  16234. 'tcaron': 416,
  16235. 'eogonek': 444,
  16236. 'Uogonek': 722,
  16237. 'Aacute': 722,
  16238. 'Adieresis': 722,
  16239. 'egrave': 444,
  16240. 'zacute': 444,
  16241. 'iogonek': 278,
  16242. 'Oacute': 778,
  16243. 'oacute': 500,
  16244. 'amacron': 500,
  16245. 'sacute': 389,
  16246. 'idieresis': 278,
  16247. 'Ocircumflex': 778,
  16248. 'Ugrave': 722,
  16249. 'Delta': 612,
  16250. 'thorn': 556,
  16251. 'twosuperior': 300,
  16252. 'Odieresis': 778,
  16253. 'mu': 556,
  16254. 'igrave': 278,
  16255. 'ohungarumlaut': 500,
  16256. 'Eogonek': 667,
  16257. 'dcroat': 556,
  16258. 'threequarters': 750,
  16259. 'Scedilla': 556,
  16260. 'lcaron': 394,
  16261. 'Kcommaaccent': 778,
  16262. 'Lacute': 667,
  16263. 'trademark': 1000,
  16264. 'edotaccent': 444,
  16265. 'Igrave': 389,
  16266. 'Imacron': 389,
  16267. 'Lcaron': 667,
  16268. 'onehalf': 750,
  16269. 'lessequal': 549,
  16270. 'ocircumflex': 500,
  16271. 'ntilde': 556,
  16272. 'Uhungarumlaut': 722,
  16273. 'Eacute': 667,
  16274. 'emacron': 444,
  16275. 'gbreve': 500,
  16276. 'onequarter': 750,
  16277. 'Scaron': 556,
  16278. 'Scommaaccent': 556,
  16279. 'Ohungarumlaut': 778,
  16280. 'degree': 400,
  16281. 'ograve': 500,
  16282. 'Ccaron': 722,
  16283. 'ugrave': 556,
  16284. 'radical': 549,
  16285. 'Dcaron': 722,
  16286. 'rcommaaccent': 444,
  16287. 'Ntilde': 722,
  16288. 'otilde': 500,
  16289. 'Rcommaaccent': 722,
  16290. 'Lcommaaccent': 667,
  16291. 'Atilde': 722,
  16292. 'Aogonek': 722,
  16293. 'Aring': 722,
  16294. 'Otilde': 778,
  16295. 'zdotaccent': 444,
  16296. 'Ecaron': 667,
  16297. 'Iogonek': 389,
  16298. 'kcommaaccent': 556,
  16299. 'minus': 570,
  16300. 'Icircumflex': 389,
  16301. 'ncaron': 556,
  16302. 'tcommaaccent': 333,
  16303. 'logicalnot': 570,
  16304. 'odieresis': 500,
  16305. 'udieresis': 556,
  16306. 'notequal': 549,
  16307. 'gcommaaccent': 500,
  16308. 'eth': 500,
  16309. 'zcaron': 444,
  16310. 'ncommaaccent': 556,
  16311. 'onesuperior': 300,
  16312. 'imacron': 278,
  16313. 'Euro': 500
  16314. },
  16315. 'Times-BoldItalic': {
  16316. 'space': 250,
  16317. 'exclam': 389,
  16318. 'quotedbl': 555,
  16319. 'numbersign': 500,
  16320. 'dollar': 500,
  16321. 'percent': 833,
  16322. 'ampersand': 778,
  16323. 'quoteright': 333,
  16324. 'parenleft': 333,
  16325. 'parenright': 333,
  16326. 'asterisk': 500,
  16327. 'plus': 570,
  16328. 'comma': 250,
  16329. 'hyphen': 333,
  16330. 'period': 250,
  16331. 'slash': 278,
  16332. 'zero': 500,
  16333. 'one': 500,
  16334. 'two': 500,
  16335. 'three': 500,
  16336. 'four': 500,
  16337. 'five': 500,
  16338. 'six': 500,
  16339. 'seven': 500,
  16340. 'eight': 500,
  16341. 'nine': 500,
  16342. 'colon': 333,
  16343. 'semicolon': 333,
  16344. 'less': 570,
  16345. 'equal': 570,
  16346. 'greater': 570,
  16347. 'question': 500,
  16348. 'at': 832,
  16349. 'A': 667,
  16350. 'B': 667,
  16351. 'C': 667,
  16352. 'D': 722,
  16353. 'E': 667,
  16354. 'F': 667,
  16355. 'G': 722,
  16356. 'H': 778,
  16357. 'I': 389,
  16358. 'J': 500,
  16359. 'K': 667,
  16360. 'L': 611,
  16361. 'M': 889,
  16362. 'N': 722,
  16363. 'O': 722,
  16364. 'P': 611,
  16365. 'Q': 722,
  16366. 'R': 667,
  16367. 'S': 556,
  16368. 'T': 611,
  16369. 'U': 722,
  16370. 'V': 667,
  16371. 'W': 889,
  16372. 'X': 667,
  16373. 'Y': 611,
  16374. 'Z': 611,
  16375. 'bracketleft': 333,
  16376. 'backslash': 278,
  16377. 'bracketright': 333,
  16378. 'asciicircum': 570,
  16379. 'underscore': 500,
  16380. 'quoteleft': 333,
  16381. 'a': 500,
  16382. 'b': 500,
  16383. 'c': 444,
  16384. 'd': 500,
  16385. 'e': 444,
  16386. 'f': 333,
  16387. 'g': 500,
  16388. 'h': 556,
  16389. 'i': 278,
  16390. 'j': 278,
  16391. 'k': 500,
  16392. 'l': 278,
  16393. 'm': 778,
  16394. 'n': 556,
  16395. 'o': 500,
  16396. 'p': 500,
  16397. 'q': 500,
  16398. 'r': 389,
  16399. 's': 389,
  16400. 't': 278,
  16401. 'u': 556,
  16402. 'v': 444,
  16403. 'w': 667,
  16404. 'x': 500,
  16405. 'y': 444,
  16406. 'z': 389,
  16407. 'braceleft': 348,
  16408. 'bar': 220,
  16409. 'braceright': 348,
  16410. 'asciitilde': 570,
  16411. 'exclamdown': 389,
  16412. 'cent': 500,
  16413. 'sterling': 500,
  16414. 'fraction': 167,
  16415. 'yen': 500,
  16416. 'florin': 500,
  16417. 'section': 500,
  16418. 'currency': 500,
  16419. 'quotesingle': 278,
  16420. 'quotedblleft': 500,
  16421. 'guillemotleft': 500,
  16422. 'guilsinglleft': 333,
  16423. 'guilsinglright': 333,
  16424. 'fi': 556,
  16425. 'fl': 556,
  16426. 'endash': 500,
  16427. 'dagger': 500,
  16428. 'daggerdbl': 500,
  16429. 'periodcentered': 250,
  16430. 'paragraph': 500,
  16431. 'bullet': 350,
  16432. 'quotesinglbase': 333,
  16433. 'quotedblbase': 500,
  16434. 'quotedblright': 500,
  16435. 'guillemotright': 500,
  16436. 'ellipsis': 1000,
  16437. 'perthousand': 1000,
  16438. 'questiondown': 500,
  16439. 'grave': 333,
  16440. 'acute': 333,
  16441. 'circumflex': 333,
  16442. 'tilde': 333,
  16443. 'macron': 333,
  16444. 'breve': 333,
  16445. 'dotaccent': 333,
  16446. 'dieresis': 333,
  16447. 'ring': 333,
  16448. 'cedilla': 333,
  16449. 'hungarumlaut': 333,
  16450. 'ogonek': 333,
  16451. 'caron': 333,
  16452. 'emdash': 1000,
  16453. 'AE': 944,
  16454. 'ordfeminine': 266,
  16455. 'Lslash': 611,
  16456. 'Oslash': 722,
  16457. 'OE': 944,
  16458. 'ordmasculine': 300,
  16459. 'ae': 722,
  16460. 'dotlessi': 278,
  16461. 'lslash': 278,
  16462. 'oslash': 500,
  16463. 'oe': 722,
  16464. 'germandbls': 500,
  16465. 'Idieresis': 389,
  16466. 'eacute': 444,
  16467. 'abreve': 500,
  16468. 'uhungarumlaut': 556,
  16469. 'ecaron': 444,
  16470. 'Ydieresis': 611,
  16471. 'divide': 570,
  16472. 'Yacute': 611,
  16473. 'Acircumflex': 667,
  16474. 'aacute': 500,
  16475. 'Ucircumflex': 722,
  16476. 'yacute': 444,
  16477. 'scommaaccent': 389,
  16478. 'ecircumflex': 444,
  16479. 'Uring': 722,
  16480. 'Udieresis': 722,
  16481. 'aogonek': 500,
  16482. 'Uacute': 722,
  16483. 'uogonek': 556,
  16484. 'Edieresis': 667,
  16485. 'Dcroat': 722,
  16486. 'commaaccent': 250,
  16487. 'copyright': 747,
  16488. 'Emacron': 667,
  16489. 'ccaron': 444,
  16490. 'aring': 500,
  16491. 'Ncommaaccent': 722,
  16492. 'lacute': 278,
  16493. 'agrave': 500,
  16494. 'Tcommaaccent': 611,
  16495. 'Cacute': 667,
  16496. 'atilde': 500,
  16497. 'Edotaccent': 667,
  16498. 'scaron': 389,
  16499. 'scedilla': 389,
  16500. 'iacute': 278,
  16501. 'lozenge': 494,
  16502. 'Rcaron': 667,
  16503. 'Gcommaaccent': 722,
  16504. 'ucircumflex': 556,
  16505. 'acircumflex': 500,
  16506. 'Amacron': 667,
  16507. 'rcaron': 389,
  16508. 'ccedilla': 444,
  16509. 'Zdotaccent': 611,
  16510. 'Thorn': 611,
  16511. 'Omacron': 722,
  16512. 'Racute': 667,
  16513. 'Sacute': 556,
  16514. 'dcaron': 608,
  16515. 'Umacron': 722,
  16516. 'uring': 556,
  16517. 'threesuperior': 300,
  16518. 'Ograve': 722,
  16519. 'Agrave': 667,
  16520. 'Abreve': 667,
  16521. 'multiply': 570,
  16522. 'uacute': 556,
  16523. 'Tcaron': 611,
  16524. 'partialdiff': 494,
  16525. 'ydieresis': 444,
  16526. 'Nacute': 722,
  16527. 'icircumflex': 278,
  16528. 'Ecircumflex': 667,
  16529. 'adieresis': 500,
  16530. 'edieresis': 444,
  16531. 'cacute': 444,
  16532. 'nacute': 556,
  16533. 'umacron': 556,
  16534. 'Ncaron': 722,
  16535. 'Iacute': 389,
  16536. 'plusminus': 570,
  16537. 'brokenbar': 220,
  16538. 'registered': 747,
  16539. 'Gbreve': 722,
  16540. 'Idotaccent': 389,
  16541. 'summation': 600,
  16542. 'Egrave': 667,
  16543. 'racute': 389,
  16544. 'omacron': 500,
  16545. 'Zacute': 611,
  16546. 'Zcaron': 611,
  16547. 'greaterequal': 549,
  16548. 'Eth': 722,
  16549. 'Ccedilla': 667,
  16550. 'lcommaaccent': 278,
  16551. 'tcaron': 366,
  16552. 'eogonek': 444,
  16553. 'Uogonek': 722,
  16554. 'Aacute': 667,
  16555. 'Adieresis': 667,
  16556. 'egrave': 444,
  16557. 'zacute': 389,
  16558. 'iogonek': 278,
  16559. 'Oacute': 722,
  16560. 'oacute': 500,
  16561. 'amacron': 500,
  16562. 'sacute': 389,
  16563. 'idieresis': 278,
  16564. 'Ocircumflex': 722,
  16565. 'Ugrave': 722,
  16566. 'Delta': 612,
  16567. 'thorn': 500,
  16568. 'twosuperior': 300,
  16569. 'Odieresis': 722,
  16570. 'mu': 576,
  16571. 'igrave': 278,
  16572. 'ohungarumlaut': 500,
  16573. 'Eogonek': 667,
  16574. 'dcroat': 500,
  16575. 'threequarters': 750,
  16576. 'Scedilla': 556,
  16577. 'lcaron': 382,
  16578. 'Kcommaaccent': 667,
  16579. 'Lacute': 611,
  16580. 'trademark': 1000,
  16581. 'edotaccent': 444,
  16582. 'Igrave': 389,
  16583. 'Imacron': 389,
  16584. 'Lcaron': 611,
  16585. 'onehalf': 750,
  16586. 'lessequal': 549,
  16587. 'ocircumflex': 500,
  16588. 'ntilde': 556,
  16589. 'Uhungarumlaut': 722,
  16590. 'Eacute': 667,
  16591. 'emacron': 444,
  16592. 'gbreve': 500,
  16593. 'onequarter': 750,
  16594. 'Scaron': 556,
  16595. 'Scommaaccent': 556,
  16596. 'Ohungarumlaut': 722,
  16597. 'degree': 400,
  16598. 'ograve': 500,
  16599. 'Ccaron': 667,
  16600. 'ugrave': 556,
  16601. 'radical': 549,
  16602. 'Dcaron': 722,
  16603. 'rcommaaccent': 389,
  16604. 'Ntilde': 722,
  16605. 'otilde': 500,
  16606. 'Rcommaaccent': 667,
  16607. 'Lcommaaccent': 611,
  16608. 'Atilde': 667,
  16609. 'Aogonek': 667,
  16610. 'Aring': 667,
  16611. 'Otilde': 722,
  16612. 'zdotaccent': 389,
  16613. 'Ecaron': 667,
  16614. 'Iogonek': 389,
  16615. 'kcommaaccent': 500,
  16616. 'minus': 606,
  16617. 'Icircumflex': 389,
  16618. 'ncaron': 556,
  16619. 'tcommaaccent': 278,
  16620. 'logicalnot': 606,
  16621. 'odieresis': 500,
  16622. 'udieresis': 556,
  16623. 'notequal': 549,
  16624. 'gcommaaccent': 500,
  16625. 'eth': 500,
  16626. 'zcaron': 389,
  16627. 'ncommaaccent': 556,
  16628. 'onesuperior': 300,
  16629. 'imacron': 278,
  16630. 'Euro': 500
  16631. },
  16632. 'Times-Italic': {
  16633. 'space': 250,
  16634. 'exclam': 333,
  16635. 'quotedbl': 420,
  16636. 'numbersign': 500,
  16637. 'dollar': 500,
  16638. 'percent': 833,
  16639. 'ampersand': 778,
  16640. 'quoteright': 333,
  16641. 'parenleft': 333,
  16642. 'parenright': 333,
  16643. 'asterisk': 500,
  16644. 'plus': 675,
  16645. 'comma': 250,
  16646. 'hyphen': 333,
  16647. 'period': 250,
  16648. 'slash': 278,
  16649. 'zero': 500,
  16650. 'one': 500,
  16651. 'two': 500,
  16652. 'three': 500,
  16653. 'four': 500,
  16654. 'five': 500,
  16655. 'six': 500,
  16656. 'seven': 500,
  16657. 'eight': 500,
  16658. 'nine': 500,
  16659. 'colon': 333,
  16660. 'semicolon': 333,
  16661. 'less': 675,
  16662. 'equal': 675,
  16663. 'greater': 675,
  16664. 'question': 500,
  16665. 'at': 920,
  16666. 'A': 611,
  16667. 'B': 611,
  16668. 'C': 667,
  16669. 'D': 722,
  16670. 'E': 611,
  16671. 'F': 611,
  16672. 'G': 722,
  16673. 'H': 722,
  16674. 'I': 333,
  16675. 'J': 444,
  16676. 'K': 667,
  16677. 'L': 556,
  16678. 'M': 833,
  16679. 'N': 667,
  16680. 'O': 722,
  16681. 'P': 611,
  16682. 'Q': 722,
  16683. 'R': 611,
  16684. 'S': 500,
  16685. 'T': 556,
  16686. 'U': 722,
  16687. 'V': 611,
  16688. 'W': 833,
  16689. 'X': 611,
  16690. 'Y': 556,
  16691. 'Z': 556,
  16692. 'bracketleft': 389,
  16693. 'backslash': 278,
  16694. 'bracketright': 389,
  16695. 'asciicircum': 422,
  16696. 'underscore': 500,
  16697. 'quoteleft': 333,
  16698. 'a': 500,
  16699. 'b': 500,
  16700. 'c': 444,
  16701. 'd': 500,
  16702. 'e': 444,
  16703. 'f': 278,
  16704. 'g': 500,
  16705. 'h': 500,
  16706. 'i': 278,
  16707. 'j': 278,
  16708. 'k': 444,
  16709. 'l': 278,
  16710. 'm': 722,
  16711. 'n': 500,
  16712. 'o': 500,
  16713. 'p': 500,
  16714. 'q': 500,
  16715. 'r': 389,
  16716. 's': 389,
  16717. 't': 278,
  16718. 'u': 500,
  16719. 'v': 444,
  16720. 'w': 667,
  16721. 'x': 444,
  16722. 'y': 444,
  16723. 'z': 389,
  16724. 'braceleft': 400,
  16725. 'bar': 275,
  16726. 'braceright': 400,
  16727. 'asciitilde': 541,
  16728. 'exclamdown': 389,
  16729. 'cent': 500,
  16730. 'sterling': 500,
  16731. 'fraction': 167,
  16732. 'yen': 500,
  16733. 'florin': 500,
  16734. 'section': 500,
  16735. 'currency': 500,
  16736. 'quotesingle': 214,
  16737. 'quotedblleft': 556,
  16738. 'guillemotleft': 500,
  16739. 'guilsinglleft': 333,
  16740. 'guilsinglright': 333,
  16741. 'fi': 500,
  16742. 'fl': 500,
  16743. 'endash': 500,
  16744. 'dagger': 500,
  16745. 'daggerdbl': 500,
  16746. 'periodcentered': 250,
  16747. 'paragraph': 523,
  16748. 'bullet': 350,
  16749. 'quotesinglbase': 333,
  16750. 'quotedblbase': 556,
  16751. 'quotedblright': 556,
  16752. 'guillemotright': 500,
  16753. 'ellipsis': 889,
  16754. 'perthousand': 1000,
  16755. 'questiondown': 500,
  16756. 'grave': 333,
  16757. 'acute': 333,
  16758. 'circumflex': 333,
  16759. 'tilde': 333,
  16760. 'macron': 333,
  16761. 'breve': 333,
  16762. 'dotaccent': 333,
  16763. 'dieresis': 333,
  16764. 'ring': 333,
  16765. 'cedilla': 333,
  16766. 'hungarumlaut': 333,
  16767. 'ogonek': 333,
  16768. 'caron': 333,
  16769. 'emdash': 889,
  16770. 'AE': 889,
  16771. 'ordfeminine': 276,
  16772. 'Lslash': 556,
  16773. 'Oslash': 722,
  16774. 'OE': 944,
  16775. 'ordmasculine': 310,
  16776. 'ae': 667,
  16777. 'dotlessi': 278,
  16778. 'lslash': 278,
  16779. 'oslash': 500,
  16780. 'oe': 667,
  16781. 'germandbls': 500,
  16782. 'Idieresis': 333,
  16783. 'eacute': 444,
  16784. 'abreve': 500,
  16785. 'uhungarumlaut': 500,
  16786. 'ecaron': 444,
  16787. 'Ydieresis': 556,
  16788. 'divide': 675,
  16789. 'Yacute': 556,
  16790. 'Acircumflex': 611,
  16791. 'aacute': 500,
  16792. 'Ucircumflex': 722,
  16793. 'yacute': 444,
  16794. 'scommaaccent': 389,
  16795. 'ecircumflex': 444,
  16796. 'Uring': 722,
  16797. 'Udieresis': 722,
  16798. 'aogonek': 500,
  16799. 'Uacute': 722,
  16800. 'uogonek': 500,
  16801. 'Edieresis': 611,
  16802. 'Dcroat': 722,
  16803. 'commaaccent': 250,
  16804. 'copyright': 760,
  16805. 'Emacron': 611,
  16806. 'ccaron': 444,
  16807. 'aring': 500,
  16808. 'Ncommaaccent': 667,
  16809. 'lacute': 278,
  16810. 'agrave': 500,
  16811. 'Tcommaaccent': 556,
  16812. 'Cacute': 667,
  16813. 'atilde': 500,
  16814. 'Edotaccent': 611,
  16815. 'scaron': 389,
  16816. 'scedilla': 389,
  16817. 'iacute': 278,
  16818. 'lozenge': 471,
  16819. 'Rcaron': 611,
  16820. 'Gcommaaccent': 722,
  16821. 'ucircumflex': 500,
  16822. 'acircumflex': 500,
  16823. 'Amacron': 611,
  16824. 'rcaron': 389,
  16825. 'ccedilla': 444,
  16826. 'Zdotaccent': 556,
  16827. 'Thorn': 611,
  16828. 'Omacron': 722,
  16829. 'Racute': 611,
  16830. 'Sacute': 500,
  16831. 'dcaron': 544,
  16832. 'Umacron': 722,
  16833. 'uring': 500,
  16834. 'threesuperior': 300,
  16835. 'Ograve': 722,
  16836. 'Agrave': 611,
  16837. 'Abreve': 611,
  16838. 'multiply': 675,
  16839. 'uacute': 500,
  16840. 'Tcaron': 556,
  16841. 'partialdiff': 476,
  16842. 'ydieresis': 444,
  16843. 'Nacute': 667,
  16844. 'icircumflex': 278,
  16845. 'Ecircumflex': 611,
  16846. 'adieresis': 500,
  16847. 'edieresis': 444,
  16848. 'cacute': 444,
  16849. 'nacute': 500,
  16850. 'umacron': 500,
  16851. 'Ncaron': 667,
  16852. 'Iacute': 333,
  16853. 'plusminus': 675,
  16854. 'brokenbar': 275,
  16855. 'registered': 760,
  16856. 'Gbreve': 722,
  16857. 'Idotaccent': 333,
  16858. 'summation': 600,
  16859. 'Egrave': 611,
  16860. 'racute': 389,
  16861. 'omacron': 500,
  16862. 'Zacute': 556,
  16863. 'Zcaron': 556,
  16864. 'greaterequal': 549,
  16865. 'Eth': 722,
  16866. 'Ccedilla': 667,
  16867. 'lcommaaccent': 278,
  16868. 'tcaron': 300,
  16869. 'eogonek': 444,
  16870. 'Uogonek': 722,
  16871. 'Aacute': 611,
  16872. 'Adieresis': 611,
  16873. 'egrave': 444,
  16874. 'zacute': 389,
  16875. 'iogonek': 278,
  16876. 'Oacute': 722,
  16877. 'oacute': 500,
  16878. 'amacron': 500,
  16879. 'sacute': 389,
  16880. 'idieresis': 278,
  16881. 'Ocircumflex': 722,
  16882. 'Ugrave': 722,
  16883. 'Delta': 612,
  16884. 'thorn': 500,
  16885. 'twosuperior': 300,
  16886. 'Odieresis': 722,
  16887. 'mu': 500,
  16888. 'igrave': 278,
  16889. 'ohungarumlaut': 500,
  16890. 'Eogonek': 611,
  16891. 'dcroat': 500,
  16892. 'threequarters': 750,
  16893. 'Scedilla': 500,
  16894. 'lcaron': 300,
  16895. 'Kcommaaccent': 667,
  16896. 'Lacute': 556,
  16897. 'trademark': 980,
  16898. 'edotaccent': 444,
  16899. 'Igrave': 333,
  16900. 'Imacron': 333,
  16901. 'Lcaron': 611,
  16902. 'onehalf': 750,
  16903. 'lessequal': 549,
  16904. 'ocircumflex': 500,
  16905. 'ntilde': 500,
  16906. 'Uhungarumlaut': 722,
  16907. 'Eacute': 611,
  16908. 'emacron': 444,
  16909. 'gbreve': 500,
  16910. 'onequarter': 750,
  16911. 'Scaron': 500,
  16912. 'Scommaaccent': 500,
  16913. 'Ohungarumlaut': 722,
  16914. 'degree': 400,
  16915. 'ograve': 500,
  16916. 'Ccaron': 667,
  16917. 'ugrave': 500,
  16918. 'radical': 453,
  16919. 'Dcaron': 722,
  16920. 'rcommaaccent': 389,
  16921. 'Ntilde': 667,
  16922. 'otilde': 500,
  16923. 'Rcommaaccent': 611,
  16924. 'Lcommaaccent': 556,
  16925. 'Atilde': 611,
  16926. 'Aogonek': 611,
  16927. 'Aring': 611,
  16928. 'Otilde': 722,
  16929. 'zdotaccent': 389,
  16930. 'Ecaron': 611,
  16931. 'Iogonek': 333,
  16932. 'kcommaaccent': 444,
  16933. 'minus': 675,
  16934. 'Icircumflex': 333,
  16935. 'ncaron': 500,
  16936. 'tcommaaccent': 278,
  16937. 'logicalnot': 675,
  16938. 'odieresis': 500,
  16939. 'udieresis': 500,
  16940. 'notequal': 549,
  16941. 'gcommaaccent': 500,
  16942. 'eth': 500,
  16943. 'zcaron': 389,
  16944. 'ncommaaccent': 500,
  16945. 'onesuperior': 300,
  16946. 'imacron': 278,
  16947. 'Euro': 500
  16948. },
  16949. 'ZapfDingbats': {
  16950. 'space': 278,
  16951. 'a1': 974,
  16952. 'a2': 961,
  16953. 'a202': 974,
  16954. 'a3': 980,
  16955. 'a4': 719,
  16956. 'a5': 789,
  16957. 'a119': 790,
  16958. 'a118': 791,
  16959. 'a117': 690,
  16960. 'a11': 960,
  16961. 'a12': 939,
  16962. 'a13': 549,
  16963. 'a14': 855,
  16964. 'a15': 911,
  16965. 'a16': 933,
  16966. 'a105': 911,
  16967. 'a17': 945,
  16968. 'a18': 974,
  16969. 'a19': 755,
  16970. 'a20': 846,
  16971. 'a21': 762,
  16972. 'a22': 761,
  16973. 'a23': 571,
  16974. 'a24': 677,
  16975. 'a25': 763,
  16976. 'a26': 760,
  16977. 'a27': 759,
  16978. 'a28': 754,
  16979. 'a6': 494,
  16980. 'a7': 552,
  16981. 'a8': 537,
  16982. 'a9': 577,
  16983. 'a10': 692,
  16984. 'a29': 786,
  16985. 'a30': 788,
  16986. 'a31': 788,
  16987. 'a32': 790,
  16988. 'a33': 793,
  16989. 'a34': 794,
  16990. 'a35': 816,
  16991. 'a36': 823,
  16992. 'a37': 789,
  16993. 'a38': 841,
  16994. 'a39': 823,
  16995. 'a40': 833,
  16996. 'a41': 816,
  16997. 'a42': 831,
  16998. 'a43': 923,
  16999. 'a44': 744,
  17000. 'a45': 723,
  17001. 'a46': 749,
  17002. 'a47': 790,
  17003. 'a48': 792,
  17004. 'a49': 695,
  17005. 'a50': 776,
  17006. 'a51': 768,
  17007. 'a52': 792,
  17008. 'a53': 759,
  17009. 'a54': 707,
  17010. 'a55': 708,
  17011. 'a56': 682,
  17012. 'a57': 701,
  17013. 'a58': 826,
  17014. 'a59': 815,
  17015. 'a60': 789,
  17016. 'a61': 789,
  17017. 'a62': 707,
  17018. 'a63': 687,
  17019. 'a64': 696,
  17020. 'a65': 689,
  17021. 'a66': 786,
  17022. 'a67': 787,
  17023. 'a68': 713,
  17024. 'a69': 791,
  17025. 'a70': 785,
  17026. 'a71': 791,
  17027. 'a72': 873,
  17028. 'a73': 761,
  17029. 'a74': 762,
  17030. 'a203': 762,
  17031. 'a75': 759,
  17032. 'a204': 759,
  17033. 'a76': 892,
  17034. 'a77': 892,
  17035. 'a78': 788,
  17036. 'a79': 784,
  17037. 'a81': 438,
  17038. 'a82': 138,
  17039. 'a83': 277,
  17040. 'a84': 415,
  17041. 'a97': 392,
  17042. 'a98': 392,
  17043. 'a99': 668,
  17044. 'a100': 668,
  17045. 'a89': 390,
  17046. 'a90': 390,
  17047. 'a93': 317,
  17048. 'a94': 317,
  17049. 'a91': 276,
  17050. 'a92': 276,
  17051. 'a205': 509,
  17052. 'a85': 509,
  17053. 'a206': 410,
  17054. 'a86': 410,
  17055. 'a87': 234,
  17056. 'a88': 234,
  17057. 'a95': 334,
  17058. 'a96': 334,
  17059. 'a101': 732,
  17060. 'a102': 544,
  17061. 'a103': 544,
  17062. 'a104': 910,
  17063. 'a106': 667,
  17064. 'a107': 760,
  17065. 'a108': 760,
  17066. 'a112': 776,
  17067. 'a111': 595,
  17068. 'a110': 694,
  17069. 'a109': 626,
  17070. 'a120': 788,
  17071. 'a121': 788,
  17072. 'a122': 788,
  17073. 'a123': 788,
  17074. 'a124': 788,
  17075. 'a125': 788,
  17076. 'a126': 788,
  17077. 'a127': 788,
  17078. 'a128': 788,
  17079. 'a129': 788,
  17080. 'a130': 788,
  17081. 'a131': 788,
  17082. 'a132': 788,
  17083. 'a133': 788,
  17084. 'a134': 788,
  17085. 'a135': 788,
  17086. 'a136': 788,
  17087. 'a137': 788,
  17088. 'a138': 788,
  17089. 'a139': 788,
  17090. 'a140': 788,
  17091. 'a141': 788,
  17092. 'a142': 788,
  17093. 'a143': 788,
  17094. 'a144': 788,
  17095. 'a145': 788,
  17096. 'a146': 788,
  17097. 'a147': 788,
  17098. 'a148': 788,
  17099. 'a149': 788,
  17100. 'a150': 788,
  17101. 'a151': 788,
  17102. 'a152': 788,
  17103. 'a153': 788,
  17104. 'a154': 788,
  17105. 'a155': 788,
  17106. 'a156': 788,
  17107. 'a157': 788,
  17108. 'a158': 788,
  17109. 'a159': 788,
  17110. 'a160': 894,
  17111. 'a161': 838,
  17112. 'a163': 1016,
  17113. 'a164': 458,
  17114. 'a196': 748,
  17115. 'a165': 924,
  17116. 'a192': 748,
  17117. 'a166': 918,
  17118. 'a167': 927,
  17119. 'a168': 928,
  17120. 'a169': 928,
  17121. 'a170': 834,
  17122. 'a171': 873,
  17123. 'a172': 828,
  17124. 'a173': 924,
  17125. 'a162': 924,
  17126. 'a174': 917,
  17127. 'a175': 930,
  17128. 'a176': 931,
  17129. 'a177': 463,
  17130. 'a178': 883,
  17131. 'a179': 836,
  17132. 'a193': 836,
  17133. 'a180': 867,
  17134. 'a199': 867,
  17135. 'a181': 696,
  17136. 'a200': 696,
  17137. 'a182': 874,
  17138. 'a201': 874,
  17139. 'a183': 760,
  17140. 'a184': 946,
  17141. 'a197': 771,
  17142. 'a185': 865,
  17143. 'a194': 771,
  17144. 'a198': 888,
  17145. 'a186': 967,
  17146. 'a195': 888,
  17147. 'a187': 831,
  17148. 'a188': 873,
  17149. 'a189': 927,
  17150. 'a190': 970,
  17151. 'a191': 918
  17152. }
  17153. };
  17154. exports.Metrics = Metrics;
  17155. }));
  17156. (function (root, factory) {
  17157. {
  17158. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  17159. }
  17160. }(this, function (exports, sharedGlobal) {
  17161. var PDFJS = sharedGlobal.PDFJS;
  17162. var bidi = PDFJS.bidi = (function bidiClosure() {
  17163. // Character types for symbols from 0000 to 00FF.
  17164. var baseTypes = [
  17165. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  17166. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  17167. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  17168. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  17169. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  17170. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17171. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  17172. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17173. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17174. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  17175. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  17176. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  17177. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  17178. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  17179. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17180. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17181. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17182. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17183. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  17184. ];
  17185. // Character types for symbols from 0600 to 06FF
  17186. var arabicTypes = [
  17187. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17188. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  17189. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17190. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17191. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17192. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17193. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  17194. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  17195. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  17196. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  17197. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17198. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17199. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17200. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17201. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17202. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17203. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17204. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17205. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  17206. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  17207. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17208. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  17209. ];
  17210. function isOdd(i) {
  17211. return (i & 1) !== 0;
  17212. }
  17213. function isEven(i) {
  17214. return (i & 1) === 0;
  17215. }
  17216. function findUnequal(arr, start, value) {
  17217. for (var j = start, jj = arr.length; j < jj; ++j) {
  17218. if (arr[j] !== value) {
  17219. return j;
  17220. }
  17221. }
  17222. return j;
  17223. }
  17224. function setValues(arr, start, end, value) {
  17225. for (var j = start; j < end; ++j) {
  17226. arr[j] = value;
  17227. }
  17228. }
  17229. function reverseValues(arr, start, end) {
  17230. for (var i = start, j = end - 1; i < j; ++i, --j) {
  17231. var temp = arr[i];
  17232. arr[i] = arr[j];
  17233. arr[j] = temp;
  17234. }
  17235. }
  17236. function createBidiText(str, isLTR, vertical) {
  17237. return {
  17238. str: str,
  17239. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  17240. };
  17241. }
  17242. // These are used in bidi(), which is called frequently. We re-use them on
  17243. // each call to avoid unnecessary allocations.
  17244. var chars = [];
  17245. var types = [];
  17246. function bidi(str, startLevel, vertical) {
  17247. var isLTR = true;
  17248. var strLength = str.length;
  17249. if (strLength === 0 || vertical) {
  17250. return createBidiText(str, isLTR, vertical);
  17251. }
  17252. // Get types and fill arrays
  17253. chars.length = strLength;
  17254. types.length = strLength;
  17255. var numBidi = 0;
  17256. var i, ii;
  17257. for (i = 0; i < strLength; ++i) {
  17258. chars[i] = str.charAt(i);
  17259. var charCode = str.charCodeAt(i);
  17260. var charType = 'L';
  17261. if (charCode <= 0x00ff) {
  17262. charType = baseTypes[charCode];
  17263. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  17264. charType = 'R';
  17265. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  17266. charType = arabicTypes[charCode & 0xff];
  17267. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  17268. charType = 'AL';
  17269. }
  17270. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  17271. numBidi++;
  17272. }
  17273. types[i] = charType;
  17274. }
  17275. // Detect the bidi method
  17276. // - If there are no rtl characters then no bidi needed
  17277. // - If less than 30% chars are rtl then string is primarily ltr
  17278. // - If more than 30% chars are rtl then string is primarily rtl
  17279. if (numBidi === 0) {
  17280. isLTR = true;
  17281. return createBidiText(str, isLTR);
  17282. }
  17283. if (startLevel === -1) {
  17284. if ((strLength / numBidi) < 0.3) {
  17285. isLTR = true;
  17286. startLevel = 0;
  17287. } else {
  17288. isLTR = false;
  17289. startLevel = 1;
  17290. }
  17291. }
  17292. var levels = [];
  17293. for (i = 0; i < strLength; ++i) {
  17294. levels[i] = startLevel;
  17295. }
  17296. /*
  17297. X1-X10: skip most of this, since we are NOT doing the embeddings.
  17298. */
  17299. var e = (isOdd(startLevel) ? 'R' : 'L');
  17300. var sor = e;
  17301. var eor = sor;
  17302. /*
  17303. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  17304. type of the NSM to the type of the previous character. If the NSM is at the
  17305. start of the level run, it will get the type of sor.
  17306. */
  17307. var lastType = sor;
  17308. for (i = 0; i < strLength; ++i) {
  17309. if (types[i] === 'NSM') {
  17310. types[i] = lastType;
  17311. } else {
  17312. lastType = types[i];
  17313. }
  17314. }
  17315. /*
  17316. W2. Search backwards from each instance of a European number until the
  17317. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  17318. the type of the European number to Arabic number.
  17319. */
  17320. lastType = sor;
  17321. var t;
  17322. for (i = 0; i < strLength; ++i) {
  17323. t = types[i];
  17324. if (t === 'EN') {
  17325. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  17326. } else if (t === 'R' || t === 'L' || t === 'AL') {
  17327. lastType = t;
  17328. }
  17329. }
  17330. /*
  17331. W3. Change all ALs to R.
  17332. */
  17333. for (i = 0; i < strLength; ++i) {
  17334. t = types[i];
  17335. if (t === 'AL') {
  17336. types[i] = 'R';
  17337. }
  17338. }
  17339. /*
  17340. W4. A single European separator between two European numbers changes to a
  17341. European number. A single common separator between two numbers of the same
  17342. type changes to that type:
  17343. */
  17344. for (i = 1; i < strLength - 1; ++i) {
  17345. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  17346. types[i] = 'EN';
  17347. }
  17348. if (types[i] === 'CS' &&
  17349. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  17350. types[i + 1] === types[i - 1]) {
  17351. types[i] = types[i - 1];
  17352. }
  17353. }
  17354. /*
  17355. W5. A sequence of European terminators adjacent to European numbers changes
  17356. to all European numbers:
  17357. */
  17358. for (i = 0; i < strLength; ++i) {
  17359. if (types[i] === 'EN') {
  17360. // do before
  17361. var j;
  17362. for (j = i - 1; j >= 0; --j) {
  17363. if (types[j] !== 'ET') {
  17364. break;
  17365. }
  17366. types[j] = 'EN';
  17367. }
  17368. // do after
  17369. for (j = i + 1; j < strLength; --j) {
  17370. if (types[j] !== 'ET') {
  17371. break;
  17372. }
  17373. types[j] = 'EN';
  17374. }
  17375. }
  17376. }
  17377. /*
  17378. W6. Otherwise, separators and terminators change to Other Neutral:
  17379. */
  17380. for (i = 0; i < strLength; ++i) {
  17381. t = types[i];
  17382. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  17383. types[i] = 'ON';
  17384. }
  17385. }
  17386. /*
  17387. W7. Search backwards from each instance of a European number until the
  17388. first strong type (R, L, or sor) is found. If an L is found, then change
  17389. the type of the European number to L.
  17390. */
  17391. lastType = sor;
  17392. for (i = 0; i < strLength; ++i) {
  17393. t = types[i];
  17394. if (t === 'EN') {
  17395. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  17396. } else if (t === 'R' || t === 'L') {
  17397. lastType = t;
  17398. }
  17399. }
  17400. /*
  17401. N1. A sequence of neutrals takes the direction of the surrounding strong
  17402. text if the text on both sides has the same direction. European and Arabic
  17403. numbers are treated as though they were R. Start-of-level-run (sor) and
  17404. end-of-level-run (eor) are used at level run boundaries.
  17405. */
  17406. for (i = 0; i < strLength; ++i) {
  17407. if (types[i] === 'ON') {
  17408. var end = findUnequal(types, i + 1, 'ON');
  17409. var before = sor;
  17410. if (i > 0) {
  17411. before = types[i - 1];
  17412. }
  17413. var after = eor;
  17414. if (end + 1 < strLength) {
  17415. after = types[end + 1];
  17416. }
  17417. if (before !== 'L') {
  17418. before = 'R';
  17419. }
  17420. if (after !== 'L') {
  17421. after = 'R';
  17422. }
  17423. if (before === after) {
  17424. setValues(types, i, end, before);
  17425. }
  17426. i = end - 1; // reset to end (-1 so next iteration is ok)
  17427. }
  17428. }
  17429. /*
  17430. N2. Any remaining neutrals take the embedding direction.
  17431. */
  17432. for (i = 0; i < strLength; ++i) {
  17433. if (types[i] === 'ON') {
  17434. types[i] = e;
  17435. }
  17436. }
  17437. /*
  17438. I1. For all characters with an even (left-to-right) embedding direction,
  17439. those of type R go up one level and those of type AN or EN go up two
  17440. levels.
  17441. I2. For all characters with an odd (right-to-left) embedding direction,
  17442. those of type L, EN or AN go up one level.
  17443. */
  17444. for (i = 0; i < strLength; ++i) {
  17445. t = types[i];
  17446. if (isEven(levels[i])) {
  17447. if (t === 'R') {
  17448. levels[i] += 1;
  17449. } else if (t === 'AN' || t === 'EN') {
  17450. levels[i] += 2;
  17451. }
  17452. } else { // isOdd
  17453. if (t === 'L' || t === 'AN' || t === 'EN') {
  17454. levels[i] += 1;
  17455. }
  17456. }
  17457. }
  17458. /*
  17459. L1. On each line, reset the embedding level of the following characters to
  17460. the paragraph embedding level:
  17461. segment separators,
  17462. paragraph separators,
  17463. any sequence of whitespace characters preceding a segment separator or
  17464. paragraph separator, and any sequence of white space characters at the end
  17465. of the line.
  17466. */
  17467. // don't bother as text is only single line
  17468. /*
  17469. L2. From the highest level found in the text to the lowest odd level on
  17470. each line, reverse any contiguous sequence of characters that are at that
  17471. level or higher.
  17472. */
  17473. // find highest level & lowest odd level
  17474. var highestLevel = -1;
  17475. var lowestOddLevel = 99;
  17476. var level;
  17477. for (i = 0, ii = levels.length; i < ii; ++i) {
  17478. level = levels[i];
  17479. if (highestLevel < level) {
  17480. highestLevel = level;
  17481. }
  17482. if (lowestOddLevel > level && isOdd(level)) {
  17483. lowestOddLevel = level;
  17484. }
  17485. }
  17486. // now reverse between those limits
  17487. for (level = highestLevel; level >= lowestOddLevel; --level) {
  17488. // find segments to reverse
  17489. var start = -1;
  17490. for (i = 0, ii = levels.length; i < ii; ++i) {
  17491. if (levels[i] < level) {
  17492. if (start >= 0) {
  17493. reverseValues(chars, start, i);
  17494. start = -1;
  17495. }
  17496. } else if (start < 0) {
  17497. start = i;
  17498. }
  17499. }
  17500. if (start >= 0) {
  17501. reverseValues(chars, start, levels.length);
  17502. }
  17503. }
  17504. /*
  17505. L3. Combining marks applied to a right-to-left base character will at this
  17506. point precede their base character. If the rendering engine expects them to
  17507. follow the base characters in the final display process, then the ordering
  17508. of the marks and the base character must be reversed.
  17509. */
  17510. // don't bother for now
  17511. /*
  17512. L4. A character that possesses the mirrored property as specified by
  17513. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  17514. directionality of that character is R.
  17515. */
  17516. // don't mirror as characters are already mirrored in the pdf
  17517. // Finally, return string
  17518. for (i = 0, ii = chars.length; i < ii; ++i) {
  17519. var ch = chars[i];
  17520. if (ch === '<' || ch === '>') {
  17521. chars[i] = '';
  17522. }
  17523. }
  17524. return createBidiText(chars.join(''), isLTR);
  17525. }
  17526. return bidi;
  17527. })();
  17528. exports.bidi = bidi;
  17529. }));
  17530. (function (root, factory) {
  17531. {
  17532. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  17533. }
  17534. }(this, function (exports, sharedUtil) {
  17535. var MissingDataException = sharedUtil.MissingDataException;
  17536. var assert = sharedUtil.assert;
  17537. var createPromiseCapability = sharedUtil.createPromiseCapability;
  17538. var isInt = sharedUtil.isInt;
  17539. var isEmptyObj = sharedUtil.isEmptyObj;
  17540. var ChunkedStream = (function ChunkedStreamClosure() {
  17541. function ChunkedStream(length, chunkSize, manager) {
  17542. this.bytes = new Uint8Array(length);
  17543. this.start = 0;
  17544. this.pos = 0;
  17545. this.end = length;
  17546. this.chunkSize = chunkSize;
  17547. this.loadedChunks = [];
  17548. this.numChunksLoaded = 0;
  17549. this.numChunks = Math.ceil(length / chunkSize);
  17550. this.manager = manager;
  17551. this.progressiveDataLength = 0;
  17552. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  17553. }
  17554. // required methods for a stream. if a particular stream does not
  17555. // implement these, an error should be thrown
  17556. ChunkedStream.prototype = {
  17557. getMissingChunks: function ChunkedStream_getMissingChunks() {
  17558. var chunks = [];
  17559. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  17560. if (!this.loadedChunks[chunk]) {
  17561. chunks.push(chunk);
  17562. }
  17563. }
  17564. return chunks;
  17565. },
  17566. getBaseStreams: function ChunkedStream_getBaseStreams() {
  17567. return [this];
  17568. },
  17569. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  17570. return this.numChunksLoaded === this.numChunks;
  17571. },
  17572. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  17573. var end = begin + chunk.byteLength;
  17574. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  17575. // Using this.length is inaccurate here since this.start can be moved
  17576. // See ChunkedStream.moveStart()
  17577. var length = this.bytes.length;
  17578. assert(end % this.chunkSize === 0 || end === length,
  17579. 'Bad end offset: ' + end);
  17580. this.bytes.set(new Uint8Array(chunk), begin);
  17581. var chunkSize = this.chunkSize;
  17582. var beginChunk = Math.floor(begin / chunkSize);
  17583. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  17584. var curChunk;
  17585. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  17586. if (!this.loadedChunks[curChunk]) {
  17587. this.loadedChunks[curChunk] = true;
  17588. ++this.numChunksLoaded;
  17589. }
  17590. }
  17591. },
  17592. onReceiveProgressiveData:
  17593. function ChunkedStream_onReceiveProgressiveData(data) {
  17594. var position = this.progressiveDataLength;
  17595. var beginChunk = Math.floor(position / this.chunkSize);
  17596. this.bytes.set(new Uint8Array(data), position);
  17597. position += data.byteLength;
  17598. this.progressiveDataLength = position;
  17599. var endChunk = position >= this.end ? this.numChunks :
  17600. Math.floor(position / this.chunkSize);
  17601. var curChunk;
  17602. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  17603. if (!this.loadedChunks[curChunk]) {
  17604. this.loadedChunks[curChunk] = true;
  17605. ++this.numChunksLoaded;
  17606. }
  17607. }
  17608. },
  17609. ensureByte: function ChunkedStream_ensureByte(pos) {
  17610. var chunk = Math.floor(pos / this.chunkSize);
  17611. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  17612. return;
  17613. }
  17614. if (!this.loadedChunks[chunk]) {
  17615. throw new MissingDataException(pos, pos + 1);
  17616. }
  17617. this.lastSuccessfulEnsureByteChunk = chunk;
  17618. },
  17619. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  17620. if (begin >= end) {
  17621. return;
  17622. }
  17623. if (end <= this.progressiveDataLength) {
  17624. return;
  17625. }
  17626. var chunkSize = this.chunkSize;
  17627. var beginChunk = Math.floor(begin / chunkSize);
  17628. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  17629. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17630. if (!this.loadedChunks[chunk]) {
  17631. throw new MissingDataException(begin, end);
  17632. }
  17633. }
  17634. },
  17635. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  17636. var chunk, numChunks = this.numChunks;
  17637. for (var i = 0; i < numChunks; ++i) {
  17638. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  17639. if (!this.loadedChunks[chunk]) {
  17640. return chunk;
  17641. }
  17642. }
  17643. return null;
  17644. },
  17645. hasChunk: function ChunkedStream_hasChunk(chunk) {
  17646. return !!this.loadedChunks[chunk];
  17647. },
  17648. get length() {
  17649. return this.end - this.start;
  17650. },
  17651. get isEmpty() {
  17652. return this.length === 0;
  17653. },
  17654. getByte: function ChunkedStream_getByte() {
  17655. var pos = this.pos;
  17656. if (pos >= this.end) {
  17657. return -1;
  17658. }
  17659. this.ensureByte(pos);
  17660. return this.bytes[this.pos++];
  17661. },
  17662. getUint16: function ChunkedStream_getUint16() {
  17663. var b0 = this.getByte();
  17664. var b1 = this.getByte();
  17665. if (b0 === -1 || b1 === -1) {
  17666. return -1;
  17667. }
  17668. return (b0 << 8) + b1;
  17669. },
  17670. getInt32: function ChunkedStream_getInt32() {
  17671. var b0 = this.getByte();
  17672. var b1 = this.getByte();
  17673. var b2 = this.getByte();
  17674. var b3 = this.getByte();
  17675. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17676. },
  17677. // returns subarray of original buffer
  17678. // should only be read
  17679. getBytes: function ChunkedStream_getBytes(length) {
  17680. var bytes = this.bytes;
  17681. var pos = this.pos;
  17682. var strEnd = this.end;
  17683. if (!length) {
  17684. this.ensureRange(pos, strEnd);
  17685. return bytes.subarray(pos, strEnd);
  17686. }
  17687. var end = pos + length;
  17688. if (end > strEnd) {
  17689. end = strEnd;
  17690. }
  17691. this.ensureRange(pos, end);
  17692. this.pos = end;
  17693. return bytes.subarray(pos, end);
  17694. },
  17695. peekByte: function ChunkedStream_peekByte() {
  17696. var peekedByte = this.getByte();
  17697. this.pos--;
  17698. return peekedByte;
  17699. },
  17700. peekBytes: function ChunkedStream_peekBytes(length) {
  17701. var bytes = this.getBytes(length);
  17702. this.pos -= bytes.length;
  17703. return bytes;
  17704. },
  17705. getByteRange: function ChunkedStream_getBytes(begin, end) {
  17706. this.ensureRange(begin, end);
  17707. return this.bytes.subarray(begin, end);
  17708. },
  17709. skip: function ChunkedStream_skip(n) {
  17710. if (!n) {
  17711. n = 1;
  17712. }
  17713. this.pos += n;
  17714. },
  17715. reset: function ChunkedStream_reset() {
  17716. this.pos = this.start;
  17717. },
  17718. moveStart: function ChunkedStream_moveStart() {
  17719. this.start = this.pos;
  17720. },
  17721. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  17722. this.ensureRange(start, start + length);
  17723. function ChunkedStreamSubstream() {}
  17724. ChunkedStreamSubstream.prototype = Object.create(this);
  17725. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  17726. var chunkSize = this.chunkSize;
  17727. var beginChunk = Math.floor(this.start / chunkSize);
  17728. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  17729. var missingChunks = [];
  17730. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17731. if (!this.loadedChunks[chunk]) {
  17732. missingChunks.push(chunk);
  17733. }
  17734. }
  17735. return missingChunks;
  17736. };
  17737. var subStream = new ChunkedStreamSubstream();
  17738. subStream.pos = subStream.start = start;
  17739. subStream.end = start + length || this.end;
  17740. subStream.dict = dict;
  17741. return subStream;
  17742. },
  17743. isStream: true
  17744. };
  17745. return ChunkedStream;
  17746. })();
  17747. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  17748. function ChunkedStreamManager(length, chunkSize, url, args) {
  17749. this.stream = new ChunkedStream(length, chunkSize, this);
  17750. this.length = length;
  17751. this.chunkSize = chunkSize;
  17752. this.url = url;
  17753. this.disableAutoFetch = args.disableAutoFetch;
  17754. var msgHandler = this.msgHandler = args.msgHandler;
  17755. if (args.chunkedViewerLoading) {
  17756. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  17757. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  17758. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  17759. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  17760. };
  17761. } else {
  17762. var getXhr = function getXhr() {
  17763. return new XMLHttpRequest();
  17764. };
  17765. this.networkManager = new NetworkManager(this.url, {
  17766. getXhr: getXhr,
  17767. httpHeaders: args.httpHeaders,
  17768. withCredentials: args.withCredentials
  17769. });
  17770. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  17771. this.networkManager.requestRange(begin, end, {
  17772. onDone: this.onReceiveData.bind(this),
  17773. onProgress: this.onProgress.bind(this)
  17774. });
  17775. };
  17776. }
  17777. this.currRequestId = 0;
  17778. this.chunksNeededByRequest = {};
  17779. this.requestsByChunk = {};
  17780. this.promisesByRequest = {};
  17781. this.progressiveDataLength = 0;
  17782. this._loadedStreamCapability = createPromiseCapability();
  17783. if (args.initialData) {
  17784. this.onReceiveData({chunk: args.initialData});
  17785. }
  17786. }
  17787. ChunkedStreamManager.prototype = {
  17788. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  17789. return this._loadedStreamCapability.promise;
  17790. },
  17791. // Get all the chunks that are not yet loaded and groups them into
  17792. // contiguous ranges to load in as few requests as possible
  17793. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  17794. var missingChunks = this.stream.getMissingChunks();
  17795. this._requestChunks(missingChunks);
  17796. return this._loadedStreamCapability.promise;
  17797. },
  17798. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  17799. var requestId = this.currRequestId++;
  17800. var chunksNeeded;
  17801. var i, ii;
  17802. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  17803. for (i = 0, ii = chunks.length; i < ii; i++) {
  17804. if (!this.stream.hasChunk(chunks[i])) {
  17805. chunksNeeded[chunks[i]] = true;
  17806. }
  17807. }
  17808. if (isEmptyObj(chunksNeeded)) {
  17809. return Promise.resolve();
  17810. }
  17811. var capability = createPromiseCapability();
  17812. this.promisesByRequest[requestId] = capability;
  17813. var chunksToRequest = [];
  17814. for (var chunk in chunksNeeded) {
  17815. chunk = chunk | 0;
  17816. if (!(chunk in this.requestsByChunk)) {
  17817. this.requestsByChunk[chunk] = [];
  17818. chunksToRequest.push(chunk);
  17819. }
  17820. this.requestsByChunk[chunk].push(requestId);
  17821. }
  17822. if (!chunksToRequest.length) {
  17823. return capability.promise;
  17824. }
  17825. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  17826. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  17827. var groupedChunk = groupedChunksToRequest[i];
  17828. var begin = groupedChunk.beginChunk * this.chunkSize;
  17829. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  17830. this.sendRequest(begin, end);
  17831. }
  17832. return capability.promise;
  17833. },
  17834. getStream: function ChunkedStreamManager_getStream() {
  17835. return this.stream;
  17836. },
  17837. // Loads any chunks in the requested range that are not yet loaded
  17838. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  17839. end = Math.min(end, this.length);
  17840. var beginChunk = this.getBeginChunk(begin);
  17841. var endChunk = this.getEndChunk(end);
  17842. var chunks = [];
  17843. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17844. chunks.push(chunk);
  17845. }
  17846. return this._requestChunks(chunks);
  17847. },
  17848. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  17849. ranges = ranges || [];
  17850. var chunksToRequest = [];
  17851. for (var i = 0; i < ranges.length; i++) {
  17852. var beginChunk = this.getBeginChunk(ranges[i].begin);
  17853. var endChunk = this.getEndChunk(ranges[i].end);
  17854. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17855. if (chunksToRequest.indexOf(chunk) < 0) {
  17856. chunksToRequest.push(chunk);
  17857. }
  17858. }
  17859. }
  17860. chunksToRequest.sort(function(a, b) { return a - b; });
  17861. return this._requestChunks(chunksToRequest);
  17862. },
  17863. // Groups a sorted array of chunks into as few contiguous larger
  17864. // chunks as possible
  17865. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  17866. var groupedChunks = [];
  17867. var beginChunk = -1;
  17868. var prevChunk = -1;
  17869. for (var i = 0; i < chunks.length; ++i) {
  17870. var chunk = chunks[i];
  17871. if (beginChunk < 0) {
  17872. beginChunk = chunk;
  17873. }
  17874. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  17875. groupedChunks.push({ beginChunk: beginChunk,
  17876. endChunk: prevChunk + 1 });
  17877. beginChunk = chunk;
  17878. }
  17879. if (i + 1 === chunks.length) {
  17880. groupedChunks.push({ beginChunk: beginChunk,
  17881. endChunk: chunk + 1 });
  17882. }
  17883. prevChunk = chunk;
  17884. }
  17885. return groupedChunks;
  17886. },
  17887. onProgress: function ChunkedStreamManager_onProgress(args) {
  17888. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  17889. args.loaded);
  17890. this.msgHandler.send('DocProgress', {
  17891. loaded: bytesLoaded,
  17892. total: this.length
  17893. });
  17894. },
  17895. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  17896. var chunk = args.chunk;
  17897. var isProgressive = args.begin === undefined;
  17898. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  17899. var end = begin + chunk.byteLength;
  17900. var beginChunk = Math.floor(begin / this.chunkSize);
  17901. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  17902. Math.ceil(end / this.chunkSize);
  17903. if (isProgressive) {
  17904. this.stream.onReceiveProgressiveData(chunk);
  17905. this.progressiveDataLength = end;
  17906. } else {
  17907. this.stream.onReceiveData(begin, chunk);
  17908. }
  17909. if (this.stream.allChunksLoaded()) {
  17910. this._loadedStreamCapability.resolve(this.stream);
  17911. }
  17912. var loadedRequests = [];
  17913. var i, requestId;
  17914. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  17915. // The server might return more chunks than requested
  17916. var requestIds = this.requestsByChunk[chunk] || [];
  17917. delete this.requestsByChunk[chunk];
  17918. for (i = 0; i < requestIds.length; ++i) {
  17919. requestId = requestIds[i];
  17920. var chunksNeeded = this.chunksNeededByRequest[requestId];
  17921. if (chunk in chunksNeeded) {
  17922. delete chunksNeeded[chunk];
  17923. }
  17924. if (!isEmptyObj(chunksNeeded)) {
  17925. continue;
  17926. }
  17927. loadedRequests.push(requestId);
  17928. }
  17929. }
  17930. // If there are no pending requests, automatically fetch the next
  17931. // unfetched chunk of the PDF
  17932. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  17933. var nextEmptyChunk;
  17934. if (this.stream.numChunksLoaded === 1) {
  17935. // This is a special optimization so that after fetching the first
  17936. // chunk, rather than fetching the second chunk, we fetch the last
  17937. // chunk.
  17938. var lastChunk = this.stream.numChunks - 1;
  17939. if (!this.stream.hasChunk(lastChunk)) {
  17940. nextEmptyChunk = lastChunk;
  17941. }
  17942. } else {
  17943. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  17944. }
  17945. if (isInt(nextEmptyChunk)) {
  17946. this._requestChunks([nextEmptyChunk]);
  17947. }
  17948. }
  17949. for (i = 0; i < loadedRequests.length; ++i) {
  17950. requestId = loadedRequests[i];
  17951. var capability = this.promisesByRequest[requestId];
  17952. delete this.promisesByRequest[requestId];
  17953. capability.resolve();
  17954. }
  17955. this.msgHandler.send('DocProgress', {
  17956. loaded: this.stream.numChunksLoaded * this.chunkSize,
  17957. total: this.length
  17958. });
  17959. },
  17960. onError: function ChunkedStreamManager_onError(err) {
  17961. this._loadedStreamCapability.reject(err);
  17962. },
  17963. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  17964. var chunk = Math.floor(begin / this.chunkSize);
  17965. return chunk;
  17966. },
  17967. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  17968. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  17969. return chunk;
  17970. },
  17971. abort: function ChunkedStreamManager_abort() {
  17972. if (this.networkManager) {
  17973. this.networkManager.abortAllRequests();
  17974. }
  17975. for(var requestId in this.promisesByRequest) {
  17976. var capability = this.promisesByRequest[requestId];
  17977. capability.reject(new Error('Request was aborted'));
  17978. }
  17979. }
  17980. };
  17981. return ChunkedStreamManager;
  17982. })();
  17983. exports.ChunkedStream = ChunkedStream;
  17984. exports.ChunkedStreamManager = ChunkedStreamManager;
  17985. }));
  17986. (function (root, factory) {
  17987. {
  17988. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  17989. root.pdfjsCoreArithmeticDecoder);
  17990. }
  17991. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  17992. var error = sharedUtil.error;
  17993. var log2 = sharedUtil.log2;
  17994. var readInt8 = sharedUtil.readInt8;
  17995. var readUint16 = sharedUtil.readUint16;
  17996. var readUint32 = sharedUtil.readUint32;
  17997. var shadow = sharedUtil.shadow;
  17998. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  17999. var Jbig2Image = (function Jbig2ImageClosure() {
  18000. // Utility data structures
  18001. function ContextCache() {}
  18002. ContextCache.prototype = {
  18003. getContexts: function(id) {
  18004. if (id in this) {
  18005. return this[id];
  18006. }
  18007. return (this[id] = new Int8Array(1 << 16));
  18008. }
  18009. };
  18010. function DecodingContext(data, start, end) {
  18011. this.data = data;
  18012. this.start = start;
  18013. this.end = end;
  18014. }
  18015. DecodingContext.prototype = {
  18016. get decoder() {
  18017. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  18018. return shadow(this, 'decoder', decoder);
  18019. },
  18020. get contextCache() {
  18021. var cache = new ContextCache();
  18022. return shadow(this, 'contextCache', cache);
  18023. }
  18024. };
  18025. // Annex A. Arithmetic Integer Decoding Procedure
  18026. // A.2 Procedure for decoding values
  18027. function decodeInteger(contextCache, procedure, decoder) {
  18028. var contexts = contextCache.getContexts(procedure);
  18029. var prev = 1;
  18030. function readBits(length) {
  18031. var v = 0;
  18032. for (var i = 0; i < length; i++) {
  18033. var bit = decoder.readBit(contexts, prev);
  18034. prev = (prev < 256 ? (prev << 1) | bit :
  18035. (((prev << 1) | bit) & 511) | 256);
  18036. v = (v << 1) | bit;
  18037. }
  18038. return v >>> 0;
  18039. }
  18040. var sign = readBits(1);
  18041. var value = readBits(1) ?
  18042. (readBits(1) ?
  18043. (readBits(1) ?
  18044. (readBits(1) ?
  18045. (readBits(1) ?
  18046. (readBits(32) + 4436) :
  18047. readBits(12) + 340) :
  18048. readBits(8) + 84) :
  18049. readBits(6) + 20) :
  18050. readBits(4) + 4) :
  18051. readBits(2);
  18052. return (sign === 0 ? value : (value > 0 ? -value : null));
  18053. }
  18054. // A.3 The IAID decoding procedure
  18055. function decodeIAID(contextCache, decoder, codeLength) {
  18056. var contexts = contextCache.getContexts('IAID');
  18057. var prev = 1;
  18058. for (var i = 0; i < codeLength; i++) {
  18059. var bit = decoder.readBit(contexts, prev);
  18060. prev = (prev << 1) | bit;
  18061. }
  18062. if (codeLength < 31) {
  18063. return prev & ((1 << codeLength) - 1);
  18064. }
  18065. return prev & 0x7FFFFFFF;
  18066. }
  18067. // 7.3 Segment types
  18068. var SegmentTypes = [
  18069. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  18070. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  18071. null, null, null, null, null, 'patternDictionary', null, null, null,
  18072. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  18073. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  18074. null, null, null, null, null, 'IntermediateGenericRegion', null,
  18075. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  18076. 'IntermediateGenericRefinementRegion', null,
  18077. 'ImmediateGenericRefinementRegion',
  18078. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  18079. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  18080. 'Tables', null, null, null, null, null, null, null, null,
  18081. 'Extension'
  18082. ];
  18083. var CodingTemplates = [
  18084. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  18085. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  18086. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  18087. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  18088. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  18089. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  18090. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  18091. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  18092. {x: -1, y: 0}],
  18093. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  18094. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  18095. ];
  18096. var RefinementTemplates = [
  18097. {
  18098. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  18099. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  18100. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  18101. },
  18102. {
  18103. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  18104. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  18105. {x: 0, y: 1}, {x: 1, y: 1}]
  18106. }
  18107. ];
  18108. // See 6.2.5.7 Decoding the bitmap.
  18109. var ReusedContexts = [
  18110. 0x9B25, // 10011 0110010 0101
  18111. 0x0795, // 0011 110010 101
  18112. 0x00E5, // 001 11001 01
  18113. 0x0195 // 011001 0101
  18114. ];
  18115. var RefinementReusedContexts = [
  18116. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  18117. 0x0008 // '0000' + '001000'
  18118. ];
  18119. function decodeBitmapTemplate0(width, height, decodingContext) {
  18120. var decoder = decodingContext.decoder;
  18121. var contexts = decodingContext.contextCache.getContexts('GB');
  18122. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  18123. // ...ooooo....
  18124. // ..ooooooo... Context template for current pixel (X)
  18125. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  18126. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  18127. for (i = 0; i < height; i++) {
  18128. row = bitmap[i] = new Uint8Array(width);
  18129. row1 = (i < 1) ? row : bitmap[i - 1];
  18130. row2 = (i < 2) ? row : bitmap[i - 2];
  18131. // At the beginning of each row:
  18132. // Fill contextLabel with pixels that are above/right of (X)
  18133. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  18134. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  18135. (row1[3] << 4);
  18136. for (j = 0; j < width; j++) {
  18137. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  18138. // At each pixel: Clear contextLabel pixels that are shifted
  18139. // out of the context, then add new ones.
  18140. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  18141. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  18142. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  18143. }
  18144. }
  18145. return bitmap;
  18146. }
  18147. // 6.2 Generic Region Decoding Procedure
  18148. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  18149. decodingContext) {
  18150. if (mmr) {
  18151. error('JBIG2 error: MMR encoding is not supported');
  18152. }
  18153. // Use optimized version for the most common case
  18154. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  18155. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  18156. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  18157. return decodeBitmapTemplate0(width, height, decodingContext);
  18158. }
  18159. var useskip = !!skip;
  18160. var template = CodingTemplates[templateIndex].concat(at);
  18161. // Sorting is non-standard, and it is not required. But sorting increases
  18162. // the number of template bits that can be reused from the previous
  18163. // contextLabel in the main loop.
  18164. template.sort(function (a, b) {
  18165. return (a.y - b.y) || (a.x - b.x);
  18166. });
  18167. var templateLength = template.length;
  18168. var templateX = new Int8Array(templateLength);
  18169. var templateY = new Int8Array(templateLength);
  18170. var changingTemplateEntries = [];
  18171. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  18172. var c, k;
  18173. for (k = 0; k < templateLength; k++) {
  18174. templateX[k] = template[k].x;
  18175. templateY[k] = template[k].y;
  18176. minX = Math.min(minX, template[k].x);
  18177. maxX = Math.max(maxX, template[k].x);
  18178. minY = Math.min(minY, template[k].y);
  18179. // Check if the template pixel appears in two consecutive context labels,
  18180. // so it can be reused. Otherwise, we add it to the list of changing
  18181. // template entries.
  18182. if (k < templateLength - 1 &&
  18183. template[k].y === template[k + 1].y &&
  18184. template[k].x === template[k + 1].x - 1) {
  18185. reuseMask |= 1 << (templateLength - 1 - k);
  18186. } else {
  18187. changingTemplateEntries.push(k);
  18188. }
  18189. }
  18190. var changingEntriesLength = changingTemplateEntries.length;
  18191. var changingTemplateX = new Int8Array(changingEntriesLength);
  18192. var changingTemplateY = new Int8Array(changingEntriesLength);
  18193. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  18194. for (c = 0; c < changingEntriesLength; c++) {
  18195. k = changingTemplateEntries[c];
  18196. changingTemplateX[c] = template[k].x;
  18197. changingTemplateY[c] = template[k].y;
  18198. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  18199. }
  18200. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  18201. var sbb_left = -minX;
  18202. var sbb_top = -minY;
  18203. var sbb_right = width - maxX;
  18204. var pseudoPixelContext = ReusedContexts[templateIndex];
  18205. var row = new Uint8Array(width);
  18206. var bitmap = [];
  18207. var decoder = decodingContext.decoder;
  18208. var contexts = decodingContext.contextCache.getContexts('GB');
  18209. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  18210. for (var i = 0; i < height; i++) {
  18211. if (prediction) {
  18212. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  18213. ltp ^= sltp;
  18214. if (ltp) {
  18215. bitmap.push(row); // duplicate previous row
  18216. continue;
  18217. }
  18218. }
  18219. row = new Uint8Array(row);
  18220. bitmap.push(row);
  18221. for (j = 0; j < width; j++) {
  18222. if (useskip && skip[i][j]) {
  18223. row[j] = 0;
  18224. continue;
  18225. }
  18226. // Are we in the middle of a scanline, so we can reuse contextLabel
  18227. // bits?
  18228. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  18229. // If yes, we can just shift the bits that are reusable and only
  18230. // fetch the remaining ones.
  18231. contextLabel = (contextLabel << 1) & reuseMask;
  18232. for (k = 0; k < changingEntriesLength; k++) {
  18233. i0 = i + changingTemplateY[k];
  18234. j0 = j + changingTemplateX[k];
  18235. bit = bitmap[i0][j0];
  18236. if (bit) {
  18237. bit = changingTemplateBit[k];
  18238. contextLabel |= bit;
  18239. }
  18240. }
  18241. } else {
  18242. // compute the contextLabel from scratch
  18243. contextLabel = 0;
  18244. shift = templateLength - 1;
  18245. for (k = 0; k < templateLength; k++, shift--) {
  18246. j0 = j + templateX[k];
  18247. if (j0 >= 0 && j0 < width) {
  18248. i0 = i + templateY[k];
  18249. if (i0 >= 0) {
  18250. bit = bitmap[i0][j0];
  18251. if (bit) {
  18252. contextLabel |= bit << shift;
  18253. }
  18254. }
  18255. }
  18256. }
  18257. }
  18258. var pixel = decoder.readBit(contexts, contextLabel);
  18259. row[j] = pixel;
  18260. }
  18261. }
  18262. return bitmap;
  18263. }
  18264. // 6.3.2 Generic Refinement Region Decoding Procedure
  18265. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  18266. offsetX, offsetY, prediction, at,
  18267. decodingContext) {
  18268. var codingTemplate = RefinementTemplates[templateIndex].coding;
  18269. if (templateIndex === 0) {
  18270. codingTemplate = codingTemplate.concat([at[0]]);
  18271. }
  18272. var codingTemplateLength = codingTemplate.length;
  18273. var codingTemplateX = new Int32Array(codingTemplateLength);
  18274. var codingTemplateY = new Int32Array(codingTemplateLength);
  18275. var k;
  18276. for (k = 0; k < codingTemplateLength; k++) {
  18277. codingTemplateX[k] = codingTemplate[k].x;
  18278. codingTemplateY[k] = codingTemplate[k].y;
  18279. }
  18280. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  18281. if (templateIndex === 0) {
  18282. referenceTemplate = referenceTemplate.concat([at[1]]);
  18283. }
  18284. var referenceTemplateLength = referenceTemplate.length;
  18285. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  18286. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  18287. for (k = 0; k < referenceTemplateLength; k++) {
  18288. referenceTemplateX[k] = referenceTemplate[k].x;
  18289. referenceTemplateY[k] = referenceTemplate[k].y;
  18290. }
  18291. var referenceWidth = referenceBitmap[0].length;
  18292. var referenceHeight = referenceBitmap.length;
  18293. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  18294. var bitmap = [];
  18295. var decoder = decodingContext.decoder;
  18296. var contexts = decodingContext.contextCache.getContexts('GR');
  18297. var ltp = 0;
  18298. for (var i = 0; i < height; i++) {
  18299. if (prediction) {
  18300. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  18301. ltp ^= sltp;
  18302. if (ltp) {
  18303. error('JBIG2 error: prediction is not supported');
  18304. }
  18305. }
  18306. var row = new Uint8Array(width);
  18307. bitmap.push(row);
  18308. for (var j = 0; j < width; j++) {
  18309. var i0, j0;
  18310. var contextLabel = 0;
  18311. for (k = 0; k < codingTemplateLength; k++) {
  18312. i0 = i + codingTemplateY[k];
  18313. j0 = j + codingTemplateX[k];
  18314. if (i0 < 0 || j0 < 0 || j0 >= width) {
  18315. contextLabel <<= 1; // out of bound pixel
  18316. } else {
  18317. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  18318. }
  18319. }
  18320. for (k = 0; k < referenceTemplateLength; k++) {
  18321. i0 = i + referenceTemplateY[k] + offsetY;
  18322. j0 = j + referenceTemplateX[k] + offsetX;
  18323. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  18324. j0 >= referenceWidth) {
  18325. contextLabel <<= 1; // out of bound pixel
  18326. } else {
  18327. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  18328. }
  18329. }
  18330. var pixel = decoder.readBit(contexts, contextLabel);
  18331. row[j] = pixel;
  18332. }
  18333. }
  18334. return bitmap;
  18335. }
  18336. // 6.5.5 Decoding the symbol dictionary
  18337. function decodeSymbolDictionary(huffman, refinement, symbols,
  18338. numberOfNewSymbols, numberOfExportedSymbols,
  18339. huffmanTables, templateIndex, at,
  18340. refinementTemplateIndex, refinementAt,
  18341. decodingContext) {
  18342. if (huffman) {
  18343. error('JBIG2 error: huffman is not supported');
  18344. }
  18345. var newSymbols = [];
  18346. var currentHeight = 0;
  18347. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  18348. var decoder = decodingContext.decoder;
  18349. var contextCache = decodingContext.contextCache;
  18350. while (newSymbols.length < numberOfNewSymbols) {
  18351. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  18352. currentHeight += deltaHeight;
  18353. var currentWidth = 0;
  18354. var totalWidth = 0;
  18355. while (true) {
  18356. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  18357. if (deltaWidth === null) {
  18358. break; // OOB
  18359. }
  18360. currentWidth += deltaWidth;
  18361. totalWidth += currentWidth;
  18362. var bitmap;
  18363. if (refinement) {
  18364. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  18365. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  18366. if (numberOfInstances > 1) {
  18367. bitmap = decodeTextRegion(huffman, refinement,
  18368. currentWidth, currentHeight, 0,
  18369. numberOfInstances, 1, //strip size
  18370. symbols.concat(newSymbols),
  18371. symbolCodeLength,
  18372. 0, //transposed
  18373. 0, //ds offset
  18374. 1, //top left 7.4.3.1.1
  18375. 0, //OR operator
  18376. huffmanTables,
  18377. refinementTemplateIndex, refinementAt,
  18378. decodingContext);
  18379. } else {
  18380. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  18381. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  18382. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  18383. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  18384. newSymbols[symbolId - symbols.length]);
  18385. bitmap = decodeRefinement(currentWidth, currentHeight,
  18386. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  18387. decodingContext);
  18388. }
  18389. } else {
  18390. // 6.5.8.1 Direct-coded symbol bitmap
  18391. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  18392. templateIndex, false, null, at, decodingContext);
  18393. }
  18394. newSymbols.push(bitmap);
  18395. }
  18396. }
  18397. // 6.5.10 Exported symbols
  18398. var exportedSymbols = [];
  18399. var flags = [], currentFlag = false;
  18400. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  18401. while (flags.length < totalSymbolsLength) {
  18402. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  18403. while (runLength--) {
  18404. flags.push(currentFlag);
  18405. }
  18406. currentFlag = !currentFlag;
  18407. }
  18408. for (var i = 0, ii = symbols.length; i < ii; i++) {
  18409. if (flags[i]) {
  18410. exportedSymbols.push(symbols[i]);
  18411. }
  18412. }
  18413. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  18414. if (flags[i]) {
  18415. exportedSymbols.push(newSymbols[j]);
  18416. }
  18417. }
  18418. return exportedSymbols;
  18419. }
  18420. function decodeTextRegion(huffman, refinement, width, height,
  18421. defaultPixelValue, numberOfSymbolInstances,
  18422. stripSize, inputSymbols, symbolCodeLength,
  18423. transposed, dsOffset, referenceCorner,
  18424. combinationOperator, huffmanTables,
  18425. refinementTemplateIndex, refinementAt,
  18426. decodingContext) {
  18427. if (huffman) {
  18428. error('JBIG2 error: huffman is not supported');
  18429. }
  18430. // Prepare bitmap
  18431. var bitmap = [];
  18432. var i, row;
  18433. for (i = 0; i < height; i++) {
  18434. row = new Uint8Array(width);
  18435. if (defaultPixelValue) {
  18436. for (var j = 0; j < width; j++) {
  18437. row[j] = defaultPixelValue;
  18438. }
  18439. }
  18440. bitmap.push(row);
  18441. }
  18442. var decoder = decodingContext.decoder;
  18443. var contextCache = decodingContext.contextCache;
  18444. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  18445. var firstS = 0;
  18446. i = 0;
  18447. while (i < numberOfSymbolInstances) {
  18448. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  18449. stripT += deltaT;
  18450. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  18451. firstS += deltaFirstS;
  18452. var currentS = firstS;
  18453. do {
  18454. var currentT = (stripSize === 1 ? 0 :
  18455. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  18456. var t = stripSize * stripT + currentT;
  18457. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  18458. var applyRefinement = (refinement &&
  18459. decodeInteger(contextCache, 'IARI', decoder));
  18460. var symbolBitmap = inputSymbols[symbolId];
  18461. var symbolWidth = symbolBitmap[0].length;
  18462. var symbolHeight = symbolBitmap.length;
  18463. if (applyRefinement) {
  18464. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  18465. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  18466. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  18467. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  18468. symbolWidth += rdw;
  18469. symbolHeight += rdh;
  18470. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  18471. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  18472. (rdh >> 1) + rdy, false, refinementAt,
  18473. decodingContext);
  18474. }
  18475. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  18476. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  18477. var s2, t2, symbolRow;
  18478. if (transposed) {
  18479. // Place Symbol Bitmap from T1,S1
  18480. for (s2 = 0; s2 < symbolHeight; s2++) {
  18481. row = bitmap[offsetS + s2];
  18482. if (!row) {
  18483. continue;
  18484. }
  18485. symbolRow = symbolBitmap[s2];
  18486. // To ignore Parts of Symbol bitmap which goes
  18487. // outside bitmap region
  18488. var maxWidth = Math.min(width - offsetT, symbolWidth);
  18489. switch (combinationOperator) {
  18490. case 0: // OR
  18491. for (t2 = 0; t2 < maxWidth; t2++) {
  18492. row[offsetT + t2] |= symbolRow[t2];
  18493. }
  18494. break;
  18495. case 2: // XOR
  18496. for (t2 = 0; t2 < maxWidth; t2++) {
  18497. row[offsetT + t2] ^= symbolRow[t2];
  18498. }
  18499. break;
  18500. default:
  18501. error('JBIG2 error: operator ' + combinationOperator +
  18502. ' is not supported');
  18503. }
  18504. }
  18505. currentS += symbolHeight - 1;
  18506. } else {
  18507. for (t2 = 0; t2 < symbolHeight; t2++) {
  18508. row = bitmap[offsetT + t2];
  18509. if (!row) {
  18510. continue;
  18511. }
  18512. symbolRow = symbolBitmap[t2];
  18513. switch (combinationOperator) {
  18514. case 0: // OR
  18515. for (s2 = 0; s2 < symbolWidth; s2++) {
  18516. row[offsetS + s2] |= symbolRow[s2];
  18517. }
  18518. break;
  18519. case 2: // XOR
  18520. for (s2 = 0; s2 < symbolWidth; s2++) {
  18521. row[offsetS + s2] ^= symbolRow[s2];
  18522. }
  18523. break;
  18524. default:
  18525. error('JBIG2 error: operator ' + combinationOperator +
  18526. ' is not supported');
  18527. }
  18528. }
  18529. currentS += symbolWidth - 1;
  18530. }
  18531. i++;
  18532. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  18533. if (deltaS === null) {
  18534. break; // OOB
  18535. }
  18536. currentS += deltaS + dsOffset;
  18537. } while (true);
  18538. }
  18539. return bitmap;
  18540. }
  18541. function readSegmentHeader(data, start) {
  18542. var segmentHeader = {};
  18543. segmentHeader.number = readUint32(data, start);
  18544. var flags = data[start + 4];
  18545. var segmentType = flags & 0x3F;
  18546. if (!SegmentTypes[segmentType]) {
  18547. error('JBIG2 error: invalid segment type: ' + segmentType);
  18548. }
  18549. segmentHeader.type = segmentType;
  18550. segmentHeader.typeName = SegmentTypes[segmentType];
  18551. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  18552. var pageAssociationFieldSize = !!(flags & 0x40);
  18553. var referredFlags = data[start + 5];
  18554. var referredToCount = (referredFlags >> 5) & 7;
  18555. var retainBits = [referredFlags & 31];
  18556. var position = start + 6;
  18557. if (referredFlags === 7) {
  18558. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  18559. position += 3;
  18560. var bytes = (referredToCount + 7) >> 3;
  18561. retainBits[0] = data[position++];
  18562. while (--bytes > 0) {
  18563. retainBits.push(data[position++]);
  18564. }
  18565. } else if (referredFlags === 5 || referredFlags === 6) {
  18566. error('JBIG2 error: invalid referred-to flags');
  18567. }
  18568. segmentHeader.retainBits = retainBits;
  18569. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  18570. (segmentHeader.number <= 65536 ? 2 : 4));
  18571. var referredTo = [];
  18572. var i, ii;
  18573. for (i = 0; i < referredToCount; i++) {
  18574. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  18575. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  18576. readUint32(data, position)));
  18577. referredTo.push(number);
  18578. position += referredToSegmentNumberSize;
  18579. }
  18580. segmentHeader.referredTo = referredTo;
  18581. if (!pageAssociationFieldSize) {
  18582. segmentHeader.pageAssociation = data[position++];
  18583. } else {
  18584. segmentHeader.pageAssociation = readUint32(data, position);
  18585. position += 4;
  18586. }
  18587. segmentHeader.length = readUint32(data, position);
  18588. position += 4;
  18589. if (segmentHeader.length === 0xFFFFFFFF) {
  18590. // 7.2.7 Segment data length, unknown segment length
  18591. if (segmentType === 38) { // ImmediateGenericRegion
  18592. var genericRegionInfo = readRegionSegmentInformation(data, position);
  18593. var genericRegionSegmentFlags = data[position +
  18594. RegionSegmentInformationFieldLength];
  18595. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  18596. // searching for the segment end
  18597. var searchPatternLength = 6;
  18598. var searchPattern = new Uint8Array(searchPatternLength);
  18599. if (!genericRegionMmr) {
  18600. searchPattern[0] = 0xFF;
  18601. searchPattern[1] = 0xAC;
  18602. }
  18603. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  18604. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  18605. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  18606. searchPattern[5] = genericRegionInfo.height & 0xFF;
  18607. for (i = position, ii = data.length; i < ii; i++) {
  18608. var j = 0;
  18609. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  18610. j++;
  18611. }
  18612. if (j === searchPatternLength) {
  18613. segmentHeader.length = i + searchPatternLength;
  18614. break;
  18615. }
  18616. }
  18617. if (segmentHeader.length === 0xFFFFFFFF) {
  18618. error('JBIG2 error: segment end was not found');
  18619. }
  18620. } else {
  18621. error('JBIG2 error: invalid unknown segment length');
  18622. }
  18623. }
  18624. segmentHeader.headerEnd = position;
  18625. return segmentHeader;
  18626. }
  18627. function readSegments(header, data, start, end) {
  18628. var segments = [];
  18629. var position = start;
  18630. while (position < end) {
  18631. var segmentHeader = readSegmentHeader(data, position);
  18632. position = segmentHeader.headerEnd;
  18633. var segment = {
  18634. header: segmentHeader,
  18635. data: data
  18636. };
  18637. if (!header.randomAccess) {
  18638. segment.start = position;
  18639. position += segmentHeader.length;
  18640. segment.end = position;
  18641. }
  18642. segments.push(segment);
  18643. if (segmentHeader.type === 51) {
  18644. break; // end of file is found
  18645. }
  18646. }
  18647. if (header.randomAccess) {
  18648. for (var i = 0, ii = segments.length; i < ii; i++) {
  18649. segments[i].start = position;
  18650. position += segments[i].header.length;
  18651. segments[i].end = position;
  18652. }
  18653. }
  18654. return segments;
  18655. }
  18656. // 7.4.1 Region segment information field
  18657. function readRegionSegmentInformation(data, start) {
  18658. return {
  18659. width: readUint32(data, start),
  18660. height: readUint32(data, start + 4),
  18661. x: readUint32(data, start + 8),
  18662. y: readUint32(data, start + 12),
  18663. combinationOperator: data[start + 16] & 7
  18664. };
  18665. }
  18666. var RegionSegmentInformationFieldLength = 17;
  18667. function processSegment(segment, visitor) {
  18668. var header = segment.header;
  18669. var data = segment.data, position = segment.start, end = segment.end;
  18670. var args, at, i, atLength;
  18671. switch (header.type) {
  18672. case 0: // SymbolDictionary
  18673. // 7.4.2 Symbol dictionary segment syntax
  18674. var dictionary = {};
  18675. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  18676. dictionary.huffman = !!(dictionaryFlags & 1);
  18677. dictionary.refinement = !!(dictionaryFlags & 2);
  18678. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  18679. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  18680. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  18681. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  18682. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  18683. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  18684. dictionary.template = (dictionaryFlags >> 10) & 3;
  18685. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  18686. position += 2;
  18687. if (!dictionary.huffman) {
  18688. atLength = dictionary.template === 0 ? 4 : 1;
  18689. at = [];
  18690. for (i = 0; i < atLength; i++) {
  18691. at.push({
  18692. x: readInt8(data, position),
  18693. y: readInt8(data, position + 1)
  18694. });
  18695. position += 2;
  18696. }
  18697. dictionary.at = at;
  18698. }
  18699. if (dictionary.refinement && !dictionary.refinementTemplate) {
  18700. at = [];
  18701. for (i = 0; i < 2; i++) {
  18702. at.push({
  18703. x: readInt8(data, position),
  18704. y: readInt8(data, position + 1)
  18705. });
  18706. position += 2;
  18707. }
  18708. dictionary.refinementAt = at;
  18709. }
  18710. dictionary.numberOfExportedSymbols = readUint32(data, position);
  18711. position += 4;
  18712. dictionary.numberOfNewSymbols = readUint32(data, position);
  18713. position += 4;
  18714. args = [dictionary, header.number, header.referredTo,
  18715. data, position, end];
  18716. break;
  18717. case 6: // ImmediateTextRegion
  18718. case 7: // ImmediateLosslessTextRegion
  18719. var textRegion = {};
  18720. textRegion.info = readRegionSegmentInformation(data, position);
  18721. position += RegionSegmentInformationFieldLength;
  18722. var textRegionSegmentFlags = readUint16(data, position);
  18723. position += 2;
  18724. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  18725. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  18726. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  18727. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  18728. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  18729. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  18730. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  18731. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  18732. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  18733. if (textRegion.huffman) {
  18734. var textRegionHuffmanFlags = readUint16(data, position);
  18735. position += 2;
  18736. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  18737. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  18738. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  18739. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  18740. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  18741. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  18742. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  18743. textRegion.huffmanRefinementSizeSelector =
  18744. !!(textRegionHuffmanFlags & 14);
  18745. }
  18746. if (textRegion.refinement && !textRegion.refinementTemplate) {
  18747. at = [];
  18748. for (i = 0; i < 2; i++) {
  18749. at.push({
  18750. x: readInt8(data, position),
  18751. y: readInt8(data, position + 1)
  18752. });
  18753. position += 2;
  18754. }
  18755. textRegion.refinementAt = at;
  18756. }
  18757. textRegion.numberOfSymbolInstances = readUint32(data, position);
  18758. position += 4;
  18759. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  18760. if (textRegion.huffman) {
  18761. error('JBIG2 error: huffman is not supported');
  18762. }
  18763. args = [textRegion, header.referredTo, data, position, end];
  18764. break;
  18765. case 38: // ImmediateGenericRegion
  18766. case 39: // ImmediateLosslessGenericRegion
  18767. var genericRegion = {};
  18768. genericRegion.info = readRegionSegmentInformation(data, position);
  18769. position += RegionSegmentInformationFieldLength;
  18770. var genericRegionSegmentFlags = data[position++];
  18771. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  18772. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  18773. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  18774. if (!genericRegion.mmr) {
  18775. atLength = genericRegion.template === 0 ? 4 : 1;
  18776. at = [];
  18777. for (i = 0; i < atLength; i++) {
  18778. at.push({
  18779. x: readInt8(data, position),
  18780. y: readInt8(data, position + 1)
  18781. });
  18782. position += 2;
  18783. }
  18784. genericRegion.at = at;
  18785. }
  18786. args = [genericRegion, data, position, end];
  18787. break;
  18788. case 48: // PageInformation
  18789. var pageInfo = {
  18790. width: readUint32(data, position),
  18791. height: readUint32(data, position + 4),
  18792. resolutionX: readUint32(data, position + 8),
  18793. resolutionY: readUint32(data, position + 12)
  18794. };
  18795. if (pageInfo.height === 0xFFFFFFFF) {
  18796. delete pageInfo.height;
  18797. }
  18798. var pageSegmentFlags = data[position + 16];
  18799. var pageStripingInformation = readUint16(data, position + 17);
  18800. pageInfo.lossless = !!(pageSegmentFlags & 1);
  18801. pageInfo.refinement = !!(pageSegmentFlags & 2);
  18802. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  18803. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  18804. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  18805. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  18806. args = [pageInfo];
  18807. break;
  18808. case 49: // EndOfPage
  18809. break;
  18810. case 50: // EndOfStripe
  18811. break;
  18812. case 51: // EndOfFile
  18813. break;
  18814. case 62: // 7.4.15 defines 2 extension types which
  18815. // are comments and can be ignored.
  18816. break;
  18817. default:
  18818. error('JBIG2 error: segment type ' + header.typeName + '(' +
  18819. header.type + ') is not implemented');
  18820. }
  18821. var callbackName = 'on' + header.typeName;
  18822. if (callbackName in visitor) {
  18823. visitor[callbackName].apply(visitor, args);
  18824. }
  18825. }
  18826. function processSegments(segments, visitor) {
  18827. for (var i = 0, ii = segments.length; i < ii; i++) {
  18828. processSegment(segments[i], visitor);
  18829. }
  18830. }
  18831. function parseJbig2(data, start, end) {
  18832. var position = start;
  18833. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  18834. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  18835. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  18836. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  18837. error('JBIG2 error: invalid header');
  18838. }
  18839. var header = {};
  18840. position += 8;
  18841. var flags = data[position++];
  18842. header.randomAccess = !(flags & 1);
  18843. if (!(flags & 2)) {
  18844. header.numberOfPages = readUint32(data, position);
  18845. position += 4;
  18846. }
  18847. var segments = readSegments(header, data, position, end);
  18848. error('Not implemented');
  18849. // processSegments(segments, new SimpleSegmentVisitor());
  18850. }
  18851. function parseJbig2Chunks(chunks) {
  18852. var visitor = new SimpleSegmentVisitor();
  18853. for (var i = 0, ii = chunks.length; i < ii; i++) {
  18854. var chunk = chunks[i];
  18855. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  18856. processSegments(segments, visitor);
  18857. }
  18858. return visitor.buffer;
  18859. }
  18860. function SimpleSegmentVisitor() {}
  18861. SimpleSegmentVisitor.prototype = {
  18862. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  18863. this.currentPageInfo = info;
  18864. var rowSize = (info.width + 7) >> 3;
  18865. var buffer = new Uint8Array(rowSize * info.height);
  18866. // The contents of ArrayBuffers are initialized to 0.
  18867. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  18868. if (info.defaultPixelValue) {
  18869. for (var i = 0, ii = buffer.length; i < ii; i++) {
  18870. buffer[i] = 0xFF;
  18871. }
  18872. }
  18873. this.buffer = buffer;
  18874. },
  18875. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  18876. var pageInfo = this.currentPageInfo;
  18877. var width = regionInfo.width, height = regionInfo.height;
  18878. var rowSize = (pageInfo.width + 7) >> 3;
  18879. var combinationOperator = pageInfo.combinationOperatorOverride ?
  18880. regionInfo.combinationOperator : pageInfo.combinationOperator;
  18881. var buffer = this.buffer;
  18882. var mask0 = 128 >> (regionInfo.x & 7);
  18883. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  18884. var i, j, mask, offset;
  18885. switch (combinationOperator) {
  18886. case 0: // OR
  18887. for (i = 0; i < height; i++) {
  18888. mask = mask0;
  18889. offset = offset0;
  18890. for (j = 0; j < width; j++) {
  18891. if (bitmap[i][j]) {
  18892. buffer[offset] |= mask;
  18893. }
  18894. mask >>= 1;
  18895. if (!mask) {
  18896. mask = 128;
  18897. offset++;
  18898. }
  18899. }
  18900. offset0 += rowSize;
  18901. }
  18902. break;
  18903. case 2: // XOR
  18904. for (i = 0; i < height; i++) {
  18905. mask = mask0;
  18906. offset = offset0;
  18907. for (j = 0; j < width; j++) {
  18908. if (bitmap[i][j]) {
  18909. buffer[offset] ^= mask;
  18910. }
  18911. mask >>= 1;
  18912. if (!mask) {
  18913. mask = 128;
  18914. offset++;
  18915. }
  18916. }
  18917. offset0 += rowSize;
  18918. }
  18919. break;
  18920. default:
  18921. error('JBIG2 error: operator ' + combinationOperator +
  18922. ' is not supported');
  18923. }
  18924. },
  18925. onImmediateGenericRegion:
  18926. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  18927. start, end) {
  18928. var regionInfo = region.info;
  18929. var decodingContext = new DecodingContext(data, start, end);
  18930. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  18931. region.template, region.prediction, null,
  18932. region.at, decodingContext);
  18933. this.drawBitmap(regionInfo, bitmap);
  18934. },
  18935. onImmediateLosslessGenericRegion:
  18936. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  18937. this.onImmediateGenericRegion.apply(this, arguments);
  18938. },
  18939. onSymbolDictionary:
  18940. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  18941. currentSegment,
  18942. referredSegments,
  18943. data, start, end) {
  18944. var huffmanTables;
  18945. if (dictionary.huffman) {
  18946. error('JBIG2 error: huffman is not supported');
  18947. }
  18948. // Combines exported symbols from all referred segments
  18949. var symbols = this.symbols;
  18950. if (!symbols) {
  18951. this.symbols = symbols = {};
  18952. }
  18953. var inputSymbols = [];
  18954. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  18955. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  18956. }
  18957. var decodingContext = new DecodingContext(data, start, end);
  18958. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  18959. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  18960. dictionary.numberOfExportedSymbols, huffmanTables,
  18961. dictionary.template, dictionary.at,
  18962. dictionary.refinementTemplate, dictionary.refinementAt,
  18963. decodingContext);
  18964. },
  18965. onImmediateTextRegion:
  18966. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  18967. referredSegments,
  18968. data, start, end) {
  18969. var regionInfo = region.info;
  18970. var huffmanTables;
  18971. // Combines exported symbols from all referred segments
  18972. var symbols = this.symbols;
  18973. var inputSymbols = [];
  18974. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  18975. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  18976. }
  18977. var symbolCodeLength = log2(inputSymbols.length);
  18978. var decodingContext = new DecodingContext(data, start, end);
  18979. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  18980. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  18981. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  18982. symbolCodeLength, region.transposed, region.dsOffset,
  18983. region.referenceCorner, region.combinationOperator, huffmanTables,
  18984. region.refinementTemplate, region.refinementAt, decodingContext);
  18985. this.drawBitmap(regionInfo, bitmap);
  18986. },
  18987. onImmediateLosslessTextRegion:
  18988. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  18989. this.onImmediateTextRegion.apply(this, arguments);
  18990. }
  18991. };
  18992. function Jbig2Image() {}
  18993. Jbig2Image.prototype = {
  18994. parseChunks: function Jbig2Image_parseChunks(chunks) {
  18995. return parseJbig2Chunks(chunks);
  18996. }
  18997. };
  18998. return Jbig2Image;
  18999. })();
  19000. exports.Jbig2Image = Jbig2Image;
  19001. }));
  19002. (function (root, factory) {
  19003. {
  19004. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  19005. root.pdfjsCoreArithmeticDecoder);
  19006. }
  19007. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  19008. var info = sharedUtil.info;
  19009. var log2 = sharedUtil.log2;
  19010. var readUint16 = sharedUtil.readUint16;
  19011. var readUint32 = sharedUtil.readUint32;
  19012. var warn = sharedUtil.warn;
  19013. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  19014. var JpxImage = (function JpxImageClosure() {
  19015. // Table E.1
  19016. var SubbandsGainLog2 = {
  19017. 'LL': 0,
  19018. 'LH': 1,
  19019. 'HL': 1,
  19020. 'HH': 2
  19021. };
  19022. function JpxImage() {
  19023. this.failOnCorruptedImage = false;
  19024. }
  19025. JpxImage.prototype = {
  19026. parse: function JpxImage_parse(data) {
  19027. var head = readUint16(data, 0);
  19028. // No box header, immediate start of codestream (SOC)
  19029. if (head === 0xFF4F) {
  19030. this.parseCodestream(data, 0, data.length);
  19031. return;
  19032. }
  19033. var position = 0, length = data.length;
  19034. while (position < length) {
  19035. var headerSize = 8;
  19036. var lbox = readUint32(data, position);
  19037. var tbox = readUint32(data, position + 4);
  19038. position += headerSize;
  19039. if (lbox === 1) {
  19040. // XLBox: read UInt64 according to spec.
  19041. // JavaScript's int precision of 53 bit should be sufficient here.
  19042. lbox = readUint32(data, position) * 4294967296 +
  19043. readUint32(data, position + 4);
  19044. position += 8;
  19045. headerSize += 8;
  19046. }
  19047. if (lbox === 0) {
  19048. lbox = length - position + headerSize;
  19049. }
  19050. if (lbox < headerSize) {
  19051. throw new Error('JPX Error: Invalid box field size');
  19052. }
  19053. var dataLength = lbox - headerSize;
  19054. var jumpDataLength = true;
  19055. switch (tbox) {
  19056. case 0x6A703268: // 'jp2h'
  19057. jumpDataLength = false; // parsing child boxes
  19058. break;
  19059. case 0x636F6C72: // 'colr'
  19060. // Colorspaces are not used, the CS from the PDF is used.
  19061. var method = data[position];
  19062. if (method === 1) {
  19063. // enumerated colorspace
  19064. var colorspace = readUint32(data, position + 3);
  19065. switch (colorspace) {
  19066. case 16: // this indicates a sRGB colorspace
  19067. case 17: // this indicates a grayscale colorspace
  19068. case 18: // this indicates a YUV colorspace
  19069. break;
  19070. default:
  19071. warn('Unknown colorspace ' + colorspace);
  19072. break;
  19073. }
  19074. } else if (method === 2) {
  19075. info('ICC profile not supported');
  19076. }
  19077. break;
  19078. case 0x6A703263: // 'jp2c'
  19079. this.parseCodestream(data, position, position + dataLength);
  19080. break;
  19081. case 0x6A502020: // 'jP\024\024'
  19082. if (0x0d0a870a !== readUint32(data, position)) {
  19083. warn('Invalid JP2 signature');
  19084. }
  19085. break;
  19086. // The following header types are valid but currently not used:
  19087. case 0x6A501A1A: // 'jP\032\032'
  19088. case 0x66747970: // 'ftyp'
  19089. case 0x72726571: // 'rreq'
  19090. case 0x72657320: // 'res '
  19091. case 0x69686472: // 'ihdr'
  19092. break;
  19093. default:
  19094. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  19095. (tbox >> 16) & 0xFF,
  19096. (tbox >> 8) & 0xFF,
  19097. tbox & 0xFF);
  19098. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  19099. break;
  19100. }
  19101. if (jumpDataLength) {
  19102. position += dataLength;
  19103. }
  19104. }
  19105. },
  19106. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  19107. var newByte = stream.getByte();
  19108. while (newByte >= 0) {
  19109. var oldByte = newByte;
  19110. newByte = stream.getByte();
  19111. var code = (oldByte << 8) | newByte;
  19112. // Image and tile size (SIZ)
  19113. if (code === 0xFF51) {
  19114. stream.skip(4);
  19115. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  19116. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  19117. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  19118. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  19119. stream.skip(16);
  19120. var Csiz = stream.getUint16(); // Byte 36
  19121. this.width = Xsiz - XOsiz;
  19122. this.height = Ysiz - YOsiz;
  19123. this.componentsCount = Csiz;
  19124. // Results are always returned as Uint8Arrays
  19125. this.bitsPerComponent = 8;
  19126. return;
  19127. }
  19128. }
  19129. throw new Error('JPX Error: No size marker found in JPX stream');
  19130. },
  19131. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  19132. var context = {};
  19133. try {
  19134. var doNotRecover = false;
  19135. var position = start;
  19136. while (position + 1 < end) {
  19137. var code = readUint16(data, position);
  19138. position += 2;
  19139. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  19140. switch (code) {
  19141. case 0xFF4F: // Start of codestream (SOC)
  19142. context.mainHeader = true;
  19143. break;
  19144. case 0xFFD9: // End of codestream (EOC)
  19145. break;
  19146. case 0xFF51: // Image and tile size (SIZ)
  19147. length = readUint16(data, position);
  19148. var siz = {};
  19149. siz.Xsiz = readUint32(data, position + 4);
  19150. siz.Ysiz = readUint32(data, position + 8);
  19151. siz.XOsiz = readUint32(data, position + 12);
  19152. siz.YOsiz = readUint32(data, position + 16);
  19153. siz.XTsiz = readUint32(data, position + 20);
  19154. siz.YTsiz = readUint32(data, position + 24);
  19155. siz.XTOsiz = readUint32(data, position + 28);
  19156. siz.YTOsiz = readUint32(data, position + 32);
  19157. var componentsCount = readUint16(data, position + 36);
  19158. siz.Csiz = componentsCount;
  19159. var components = [];
  19160. j = position + 38;
  19161. for (var i = 0; i < componentsCount; i++) {
  19162. var component = {
  19163. precision: (data[j] & 0x7F) + 1,
  19164. isSigned: !!(data[j] & 0x80),
  19165. XRsiz: data[j + 1],
  19166. YRsiz: data[j + 1]
  19167. };
  19168. calculateComponentDimensions(component, siz);
  19169. components.push(component);
  19170. }
  19171. context.SIZ = siz;
  19172. context.components = components;
  19173. calculateTileGrids(context, components);
  19174. context.QCC = [];
  19175. context.COC = [];
  19176. break;
  19177. case 0xFF5C: // Quantization default (QCD)
  19178. length = readUint16(data, position);
  19179. var qcd = {};
  19180. j = position + 2;
  19181. sqcd = data[j++];
  19182. switch (sqcd & 0x1F) {
  19183. case 0:
  19184. spqcdSize = 8;
  19185. scalarExpounded = true;
  19186. break;
  19187. case 1:
  19188. spqcdSize = 16;
  19189. scalarExpounded = false;
  19190. break;
  19191. case 2:
  19192. spqcdSize = 16;
  19193. scalarExpounded = true;
  19194. break;
  19195. default:
  19196. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  19197. }
  19198. qcd.noQuantization = (spqcdSize === 8);
  19199. qcd.scalarExpounded = scalarExpounded;
  19200. qcd.guardBits = sqcd >> 5;
  19201. spqcds = [];
  19202. while (j < length + position) {
  19203. var spqcd = {};
  19204. if (spqcdSize === 8) {
  19205. spqcd.epsilon = data[j++] >> 3;
  19206. spqcd.mu = 0;
  19207. } else {
  19208. spqcd.epsilon = data[j] >> 3;
  19209. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  19210. j += 2;
  19211. }
  19212. spqcds.push(spqcd);
  19213. }
  19214. qcd.SPqcds = spqcds;
  19215. if (context.mainHeader) {
  19216. context.QCD = qcd;
  19217. } else {
  19218. context.currentTile.QCD = qcd;
  19219. context.currentTile.QCC = [];
  19220. }
  19221. break;
  19222. case 0xFF5D: // Quantization component (QCC)
  19223. length = readUint16(data, position);
  19224. var qcc = {};
  19225. j = position + 2;
  19226. var cqcc;
  19227. if (context.SIZ.Csiz < 257) {
  19228. cqcc = data[j++];
  19229. } else {
  19230. cqcc = readUint16(data, j);
  19231. j += 2;
  19232. }
  19233. sqcd = data[j++];
  19234. switch (sqcd & 0x1F) {
  19235. case 0:
  19236. spqcdSize = 8;
  19237. scalarExpounded = true;
  19238. break;
  19239. case 1:
  19240. spqcdSize = 16;
  19241. scalarExpounded = false;
  19242. break;
  19243. case 2:
  19244. spqcdSize = 16;
  19245. scalarExpounded = true;
  19246. break;
  19247. default:
  19248. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  19249. }
  19250. qcc.noQuantization = (spqcdSize === 8);
  19251. qcc.scalarExpounded = scalarExpounded;
  19252. qcc.guardBits = sqcd >> 5;
  19253. spqcds = [];
  19254. while (j < (length + position)) {
  19255. spqcd = {};
  19256. if (spqcdSize === 8) {
  19257. spqcd.epsilon = data[j++] >> 3;
  19258. spqcd.mu = 0;
  19259. } else {
  19260. spqcd.epsilon = data[j] >> 3;
  19261. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  19262. j += 2;
  19263. }
  19264. spqcds.push(spqcd);
  19265. }
  19266. qcc.SPqcds = spqcds;
  19267. if (context.mainHeader) {
  19268. context.QCC[cqcc] = qcc;
  19269. } else {
  19270. context.currentTile.QCC[cqcc] = qcc;
  19271. }
  19272. break;
  19273. case 0xFF52: // Coding style default (COD)
  19274. length = readUint16(data, position);
  19275. var cod = {};
  19276. j = position + 2;
  19277. var scod = data[j++];
  19278. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  19279. cod.sopMarkerUsed = !!(scod & 2);
  19280. cod.ephMarkerUsed = !!(scod & 4);
  19281. cod.progressionOrder = data[j++];
  19282. cod.layersCount = readUint16(data, j);
  19283. j += 2;
  19284. cod.multipleComponentTransform = data[j++];
  19285. cod.decompositionLevelsCount = data[j++];
  19286. cod.xcb = (data[j++] & 0xF) + 2;
  19287. cod.ycb = (data[j++] & 0xF) + 2;
  19288. var blockStyle = data[j++];
  19289. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  19290. cod.resetContextProbabilities = !!(blockStyle & 2);
  19291. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  19292. cod.verticalyStripe = !!(blockStyle & 8);
  19293. cod.predictableTermination = !!(blockStyle & 16);
  19294. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  19295. cod.reversibleTransformation = data[j++];
  19296. if (cod.entropyCoderWithCustomPrecincts) {
  19297. var precinctsSizes = [];
  19298. while (j < length + position) {
  19299. var precinctsSize = data[j++];
  19300. precinctsSizes.push({
  19301. PPx: precinctsSize & 0xF,
  19302. PPy: precinctsSize >> 4
  19303. });
  19304. }
  19305. cod.precinctsSizes = precinctsSizes;
  19306. }
  19307. var unsupported = [];
  19308. if (cod.selectiveArithmeticCodingBypass) {
  19309. unsupported.push('selectiveArithmeticCodingBypass');
  19310. }
  19311. if (cod.resetContextProbabilities) {
  19312. unsupported.push('resetContextProbabilities');
  19313. }
  19314. if (cod.terminationOnEachCodingPass) {
  19315. unsupported.push('terminationOnEachCodingPass');
  19316. }
  19317. if (cod.verticalyStripe) {
  19318. unsupported.push('verticalyStripe');
  19319. }
  19320. if (cod.predictableTermination) {
  19321. unsupported.push('predictableTermination');
  19322. }
  19323. if (unsupported.length > 0) {
  19324. doNotRecover = true;
  19325. throw new Error('JPX Error: Unsupported COD options (' +
  19326. unsupported.join(', ') + ')');
  19327. }
  19328. if (context.mainHeader) {
  19329. context.COD = cod;
  19330. } else {
  19331. context.currentTile.COD = cod;
  19332. context.currentTile.COC = [];
  19333. }
  19334. break;
  19335. case 0xFF90: // Start of tile-part (SOT)
  19336. length = readUint16(data, position);
  19337. tile = {};
  19338. tile.index = readUint16(data, position + 2);
  19339. tile.length = readUint32(data, position + 4);
  19340. tile.dataEnd = tile.length + position - 2;
  19341. tile.partIndex = data[position + 8];
  19342. tile.partsCount = data[position + 9];
  19343. context.mainHeader = false;
  19344. if (tile.partIndex === 0) {
  19345. // reset component specific settings
  19346. tile.COD = context.COD;
  19347. tile.COC = context.COC.slice(0); // clone of the global COC
  19348. tile.QCD = context.QCD;
  19349. tile.QCC = context.QCC.slice(0); // clone of the global COC
  19350. }
  19351. context.currentTile = tile;
  19352. break;
  19353. case 0xFF93: // Start of data (SOD)
  19354. tile = context.currentTile;
  19355. if (tile.partIndex === 0) {
  19356. initializeTile(context, tile.index);
  19357. buildPackets(context);
  19358. }
  19359. // moving to the end of the data
  19360. length = tile.dataEnd - position;
  19361. parseTilePackets(context, data, position, length);
  19362. break;
  19363. case 0xFF55: // Tile-part lengths, main header (TLM)
  19364. case 0xFF57: // Packet length, main header (PLM)
  19365. case 0xFF58: // Packet length, tile-part header (PLT)
  19366. case 0xFF64: // Comment (COM)
  19367. length = readUint16(data, position);
  19368. // skipping content
  19369. break;
  19370. case 0xFF53: // Coding style component (COC)
  19371. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  19372. 'not implemented');
  19373. default:
  19374. throw new Error('JPX Error: Unknown codestream code: ' +
  19375. code.toString(16));
  19376. }
  19377. position += length;
  19378. }
  19379. } catch (e) {
  19380. if (doNotRecover || this.failOnCorruptedImage) {
  19381. throw e;
  19382. } else {
  19383. warn('Trying to recover from ' + e.message);
  19384. }
  19385. }
  19386. this.tiles = transformComponents(context);
  19387. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  19388. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  19389. this.componentsCount = context.SIZ.Csiz;
  19390. }
  19391. };
  19392. function calculateComponentDimensions(component, siz) {
  19393. // Section B.2 Component mapping
  19394. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  19395. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  19396. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  19397. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  19398. component.width = component.x1 - component.x0;
  19399. component.height = component.y1 - component.y0;
  19400. }
  19401. function calculateTileGrids(context, components) {
  19402. var siz = context.SIZ;
  19403. // Section B.3 Division into tile and tile-components
  19404. var tile, tiles = [];
  19405. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  19406. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  19407. for (var q = 0; q < numYtiles; q++) {
  19408. for (var p = 0; p < numXtiles; p++) {
  19409. tile = {};
  19410. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  19411. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  19412. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  19413. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  19414. tile.width = tile.tx1 - tile.tx0;
  19415. tile.height = tile.ty1 - tile.ty0;
  19416. tile.components = [];
  19417. tiles.push(tile);
  19418. }
  19419. }
  19420. context.tiles = tiles;
  19421. var componentsCount = siz.Csiz;
  19422. for (var i = 0, ii = componentsCount; i < ii; i++) {
  19423. var component = components[i];
  19424. for (var j = 0, jj = tiles.length; j < jj; j++) {
  19425. var tileComponent = {};
  19426. tile = tiles[j];
  19427. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  19428. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  19429. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  19430. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  19431. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  19432. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  19433. tile.components[i] = tileComponent;
  19434. }
  19435. }
  19436. }
  19437. function getBlocksDimensions(context, component, r) {
  19438. var codOrCoc = component.codingStyleParameters;
  19439. var result = {};
  19440. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  19441. result.PPx = 15;
  19442. result.PPy = 15;
  19443. } else {
  19444. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  19445. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  19446. }
  19447. // calculate codeblock size as described in section B.7
  19448. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  19449. Math.min(codOrCoc.xcb, result.PPx));
  19450. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  19451. Math.min(codOrCoc.ycb, result.PPy));
  19452. return result;
  19453. }
  19454. function buildPrecincts(context, resolution, dimensions) {
  19455. // Section B.6 Division resolution to precincts
  19456. var precinctWidth = 1 << dimensions.PPx;
  19457. var precinctHeight = 1 << dimensions.PPy;
  19458. // Jasper introduces codeblock groups for mapping each subband codeblocks
  19459. // to precincts. Precinct partition divides a resolution according to width
  19460. // and height parameters. The subband that belongs to the resolution level
  19461. // has a different size than the level, unless it is the zero resolution.
  19462. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  19463. // The precinct partitioning for a particular subband is derived from a
  19464. // partitioning of its parent LL band (i.e., the LL band at the next higher
  19465. // resolution level)... The LL band associated with each resolution level is
  19466. // divided into precincts... Each of the resulting precinct regions is then
  19467. // mapped into its child subbands (if any) at the next lower resolution
  19468. // level. This is accomplished by using the coordinate transformation
  19469. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  19470. // coordinates of a point in the LL band and child subband, respectively.
  19471. var isZeroRes = resolution.resLevel === 0;
  19472. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  19473. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  19474. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  19475. Math.ceil(resolution.trx1 / precinctWidth) -
  19476. Math.floor(resolution.trx0 / precinctWidth) : 0);
  19477. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  19478. Math.ceil(resolution.try1 / precinctHeight) -
  19479. Math.floor(resolution.try0 / precinctHeight) : 0);
  19480. var numprecincts = numprecinctswide * numprecinctshigh;
  19481. resolution.precinctParameters = {
  19482. precinctWidth: precinctWidth,
  19483. precinctHeight: precinctHeight,
  19484. numprecinctswide: numprecinctswide,
  19485. numprecinctshigh: numprecinctshigh,
  19486. numprecincts: numprecincts,
  19487. precinctWidthInSubband: precinctWidthInSubband,
  19488. precinctHeightInSubband: precinctHeightInSubband
  19489. };
  19490. }
  19491. function buildCodeblocks(context, subband, dimensions) {
  19492. // Section B.7 Division sub-band into code-blocks
  19493. var xcb_ = dimensions.xcb_;
  19494. var ycb_ = dimensions.ycb_;
  19495. var codeblockWidth = 1 << xcb_;
  19496. var codeblockHeight = 1 << ycb_;
  19497. var cbx0 = subband.tbx0 >> xcb_;
  19498. var cby0 = subband.tby0 >> ycb_;
  19499. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  19500. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  19501. var precinctParameters = subband.resolution.precinctParameters;
  19502. var codeblocks = [];
  19503. var precincts = [];
  19504. var i, j, codeblock, precinctNumber;
  19505. for (j = cby0; j < cby1; j++) {
  19506. for (i = cbx0; i < cbx1; i++) {
  19507. codeblock = {
  19508. cbx: i,
  19509. cby: j,
  19510. tbx0: codeblockWidth * i,
  19511. tby0: codeblockHeight * j,
  19512. tbx1: codeblockWidth * (i + 1),
  19513. tby1: codeblockHeight * (j + 1)
  19514. };
  19515. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  19516. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  19517. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  19518. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  19519. // Calculate precinct number for this codeblock, codeblock position
  19520. // should be relative to its subband, use actual dimension and position
  19521. // See comment about codeblock group width and height
  19522. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  19523. precinctParameters.precinctWidthInSubband);
  19524. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  19525. precinctParameters.precinctHeightInSubband);
  19526. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  19527. codeblock.precinctNumber = precinctNumber;
  19528. codeblock.subbandType = subband.type;
  19529. codeblock.Lblock = 3;
  19530. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  19531. codeblock.tby1_ <= codeblock.tby0_) {
  19532. continue;
  19533. }
  19534. codeblocks.push(codeblock);
  19535. // building precinct for the sub-band
  19536. var precinct = precincts[precinctNumber];
  19537. if (precinct !== undefined) {
  19538. if (i < precinct.cbxMin) {
  19539. precinct.cbxMin = i;
  19540. } else if (i > precinct.cbxMax) {
  19541. precinct.cbxMax = i;
  19542. }
  19543. if (j < precinct.cbyMin) {
  19544. precinct.cbxMin = j;
  19545. } else if (j > precinct.cbyMax) {
  19546. precinct.cbyMax = j;
  19547. }
  19548. } else {
  19549. precincts[precinctNumber] = precinct = {
  19550. cbxMin: i,
  19551. cbyMin: j,
  19552. cbxMax: i,
  19553. cbyMax: j
  19554. };
  19555. }
  19556. codeblock.precinct = precinct;
  19557. }
  19558. }
  19559. subband.codeblockParameters = {
  19560. codeblockWidth: xcb_,
  19561. codeblockHeight: ycb_,
  19562. numcodeblockwide: cbx1 - cbx0 + 1,
  19563. numcodeblockhigh: cby1 - cby0 + 1
  19564. };
  19565. subband.codeblocks = codeblocks;
  19566. subband.precincts = precincts;
  19567. }
  19568. function createPacket(resolution, precinctNumber, layerNumber) {
  19569. var precinctCodeblocks = [];
  19570. // Section B.10.8 Order of info in packet
  19571. var subbands = resolution.subbands;
  19572. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  19573. for (var i = 0, ii = subbands.length; i < ii; i++) {
  19574. var subband = subbands[i];
  19575. var codeblocks = subband.codeblocks;
  19576. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  19577. var codeblock = codeblocks[j];
  19578. if (codeblock.precinctNumber !== precinctNumber) {
  19579. continue;
  19580. }
  19581. precinctCodeblocks.push(codeblock);
  19582. }
  19583. }
  19584. return {
  19585. layerNumber: layerNumber,
  19586. codeblocks: precinctCodeblocks
  19587. };
  19588. }
  19589. function LayerResolutionComponentPositionIterator(context) {
  19590. var siz = context.SIZ;
  19591. var tileIndex = context.currentTile.index;
  19592. var tile = context.tiles[tileIndex];
  19593. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19594. var componentsCount = siz.Csiz;
  19595. var maxDecompositionLevelsCount = 0;
  19596. for (var q = 0; q < componentsCount; q++) {
  19597. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19598. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  19599. }
  19600. var l = 0, r = 0, i = 0, k = 0;
  19601. this.nextPacket = function JpxImage_nextPacket() {
  19602. // Section B.12.1.1 Layer-resolution-component-position
  19603. for (; l < layersCount; l++) {
  19604. for (; r <= maxDecompositionLevelsCount; r++) {
  19605. for (; i < componentsCount; i++) {
  19606. var component = tile.components[i];
  19607. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19608. continue;
  19609. }
  19610. var resolution = component.resolutions[r];
  19611. var numprecincts = resolution.precinctParameters.numprecincts;
  19612. for (; k < numprecincts;) {
  19613. var packet = createPacket(resolution, k, l);
  19614. k++;
  19615. return packet;
  19616. }
  19617. k = 0;
  19618. }
  19619. i = 0;
  19620. }
  19621. r = 0;
  19622. }
  19623. throw new Error('JPX Error: Out of packets');
  19624. };
  19625. }
  19626. function ResolutionLayerComponentPositionIterator(context) {
  19627. var siz = context.SIZ;
  19628. var tileIndex = context.currentTile.index;
  19629. var tile = context.tiles[tileIndex];
  19630. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19631. var componentsCount = siz.Csiz;
  19632. var maxDecompositionLevelsCount = 0;
  19633. for (var q = 0; q < componentsCount; q++) {
  19634. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19635. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  19636. }
  19637. var r = 0, l = 0, i = 0, k = 0;
  19638. this.nextPacket = function JpxImage_nextPacket() {
  19639. // Section B.12.1.2 Resolution-layer-component-position
  19640. for (; r <= maxDecompositionLevelsCount; r++) {
  19641. for (; l < layersCount; l++) {
  19642. for (; i < componentsCount; i++) {
  19643. var component = tile.components[i];
  19644. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19645. continue;
  19646. }
  19647. var resolution = component.resolutions[r];
  19648. var numprecincts = resolution.precinctParameters.numprecincts;
  19649. for (; k < numprecincts;) {
  19650. var packet = createPacket(resolution, k, l);
  19651. k++;
  19652. return packet;
  19653. }
  19654. k = 0;
  19655. }
  19656. i = 0;
  19657. }
  19658. l = 0;
  19659. }
  19660. throw new Error('JPX Error: Out of packets');
  19661. };
  19662. }
  19663. function ResolutionPositionComponentLayerIterator(context) {
  19664. var siz = context.SIZ;
  19665. var tileIndex = context.currentTile.index;
  19666. var tile = context.tiles[tileIndex];
  19667. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19668. var componentsCount = siz.Csiz;
  19669. var l, r, c, p;
  19670. var maxDecompositionLevelsCount = 0;
  19671. for (c = 0; c < componentsCount; c++) {
  19672. var component = tile.components[c];
  19673. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19674. component.codingStyleParameters.decompositionLevelsCount);
  19675. }
  19676. var maxNumPrecinctsInLevel = new Int32Array(
  19677. maxDecompositionLevelsCount + 1);
  19678. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  19679. var maxNumPrecincts = 0;
  19680. for (c = 0; c < componentsCount; ++c) {
  19681. var resolutions = tile.components[c].resolutions;
  19682. if (r < resolutions.length) {
  19683. maxNumPrecincts = Math.max(maxNumPrecincts,
  19684. resolutions[r].precinctParameters.numprecincts);
  19685. }
  19686. }
  19687. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  19688. }
  19689. l = 0;
  19690. r = 0;
  19691. c = 0;
  19692. p = 0;
  19693. this.nextPacket = function JpxImage_nextPacket() {
  19694. // Section B.12.1.3 Resolution-position-component-layer
  19695. for (; r <= maxDecompositionLevelsCount; r++) {
  19696. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  19697. for (; c < componentsCount; c++) {
  19698. var component = tile.components[c];
  19699. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19700. continue;
  19701. }
  19702. var resolution = component.resolutions[r];
  19703. var numprecincts = resolution.precinctParameters.numprecincts;
  19704. if (p >= numprecincts) {
  19705. continue;
  19706. }
  19707. for (; l < layersCount;) {
  19708. var packet = createPacket(resolution, p, l);
  19709. l++;
  19710. return packet;
  19711. }
  19712. l = 0;
  19713. }
  19714. c = 0;
  19715. }
  19716. p = 0;
  19717. }
  19718. throw new Error('JPX Error: Out of packets');
  19719. };
  19720. }
  19721. function PositionComponentResolutionLayerIterator(context) {
  19722. var siz = context.SIZ;
  19723. var tileIndex = context.currentTile.index;
  19724. var tile = context.tiles[tileIndex];
  19725. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19726. var componentsCount = siz.Csiz;
  19727. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  19728. var precinctsIterationSizes = precinctsSizes;
  19729. var l = 0, r = 0, c = 0, px = 0, py = 0;
  19730. this.nextPacket = function JpxImage_nextPacket() {
  19731. // Section B.12.1.4 Position-component-resolution-layer
  19732. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  19733. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  19734. for (; c < componentsCount; c++) {
  19735. var component = tile.components[c];
  19736. var decompositionLevelsCount =
  19737. component.codingStyleParameters.decompositionLevelsCount;
  19738. for (; r <= decompositionLevelsCount; r++) {
  19739. var resolution = component.resolutions[r];
  19740. var sizeInImageScale =
  19741. precinctsSizes.components[c].resolutions[r];
  19742. var k = getPrecinctIndexIfExist(
  19743. px,
  19744. py,
  19745. sizeInImageScale,
  19746. precinctsIterationSizes,
  19747. resolution);
  19748. if (k === null) {
  19749. continue;
  19750. }
  19751. for (; l < layersCount;) {
  19752. var packet = createPacket(resolution, k, l);
  19753. l++;
  19754. return packet;
  19755. }
  19756. l = 0;
  19757. }
  19758. r = 0;
  19759. }
  19760. c = 0;
  19761. }
  19762. px = 0;
  19763. }
  19764. throw new Error('JPX Error: Out of packets');
  19765. };
  19766. }
  19767. function ComponentPositionResolutionLayerIterator(context) {
  19768. var siz = context.SIZ;
  19769. var tileIndex = context.currentTile.index;
  19770. var tile = context.tiles[tileIndex];
  19771. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19772. var componentsCount = siz.Csiz;
  19773. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  19774. var l = 0, r = 0, c = 0, px = 0, py = 0;
  19775. this.nextPacket = function JpxImage_nextPacket() {
  19776. // Section B.12.1.5 Component-position-resolution-layer
  19777. for (; c < componentsCount; ++c) {
  19778. var component = tile.components[c];
  19779. var precinctsIterationSizes = precinctsSizes.components[c];
  19780. var decompositionLevelsCount =
  19781. component.codingStyleParameters.decompositionLevelsCount;
  19782. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  19783. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  19784. for (; r <= decompositionLevelsCount; r++) {
  19785. var resolution = component.resolutions[r];
  19786. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  19787. var k = getPrecinctIndexIfExist(
  19788. px,
  19789. py,
  19790. sizeInImageScale,
  19791. precinctsIterationSizes,
  19792. resolution);
  19793. if (k === null) {
  19794. continue;
  19795. }
  19796. for (; l < layersCount;) {
  19797. var packet = createPacket(resolution, k, l);
  19798. l++;
  19799. return packet;
  19800. }
  19801. l = 0;
  19802. }
  19803. r = 0;
  19804. }
  19805. px = 0;
  19806. }
  19807. py = 0;
  19808. }
  19809. throw new Error('JPX Error: Out of packets');
  19810. };
  19811. }
  19812. function getPrecinctIndexIfExist(
  19813. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  19814. var posX = pxIndex * precinctIterationSizes.minWidth;
  19815. var posY = pyIndex * precinctIterationSizes.minHeight;
  19816. if (posX % sizeInImageScale.width !== 0 ||
  19817. posY % sizeInImageScale.height !== 0) {
  19818. return null;
  19819. }
  19820. var startPrecinctRowIndex =
  19821. (posY / sizeInImageScale.width) *
  19822. resolution.precinctParameters.numprecinctswide;
  19823. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  19824. }
  19825. function getPrecinctSizesInImageScale(tile) {
  19826. var componentsCount = tile.components.length;
  19827. var minWidth = Number.MAX_VALUE;
  19828. var minHeight = Number.MAX_VALUE;
  19829. var maxNumWide = 0;
  19830. var maxNumHigh = 0;
  19831. var sizePerComponent = new Array(componentsCount);
  19832. for (var c = 0; c < componentsCount; c++) {
  19833. var component = tile.components[c];
  19834. var decompositionLevelsCount =
  19835. component.codingStyleParameters.decompositionLevelsCount;
  19836. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  19837. var minWidthCurrentComponent = Number.MAX_VALUE;
  19838. var minHeightCurrentComponent = Number.MAX_VALUE;
  19839. var maxNumWideCurrentComponent = 0;
  19840. var maxNumHighCurrentComponent = 0;
  19841. var scale = 1;
  19842. for (var r = decompositionLevelsCount; r >= 0; --r) {
  19843. var resolution = component.resolutions[r];
  19844. var widthCurrentResolution =
  19845. scale * resolution.precinctParameters.precinctWidth;
  19846. var heightCurrentResolution =
  19847. scale * resolution.precinctParameters.precinctHeight;
  19848. minWidthCurrentComponent = Math.min(
  19849. minWidthCurrentComponent,
  19850. widthCurrentResolution);
  19851. minHeightCurrentComponent = Math.min(
  19852. minHeightCurrentComponent,
  19853. heightCurrentResolution);
  19854. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  19855. resolution.precinctParameters.numprecinctswide);
  19856. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  19857. resolution.precinctParameters.numprecinctshigh);
  19858. sizePerResolution[r] = {
  19859. width: widthCurrentResolution,
  19860. height: heightCurrentResolution
  19861. };
  19862. scale <<= 1;
  19863. }
  19864. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  19865. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  19866. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  19867. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  19868. sizePerComponent[c] = {
  19869. resolutions: sizePerResolution,
  19870. minWidth: minWidthCurrentComponent,
  19871. minHeight: minHeightCurrentComponent,
  19872. maxNumWide: maxNumWideCurrentComponent,
  19873. maxNumHigh: maxNumHighCurrentComponent
  19874. };
  19875. }
  19876. return {
  19877. components: sizePerComponent,
  19878. minWidth: minWidth,
  19879. minHeight: minHeight,
  19880. maxNumWide: maxNumWide,
  19881. maxNumHigh: maxNumHigh
  19882. };
  19883. }
  19884. function buildPackets(context) {
  19885. var siz = context.SIZ;
  19886. var tileIndex = context.currentTile.index;
  19887. var tile = context.tiles[tileIndex];
  19888. var componentsCount = siz.Csiz;
  19889. // Creating resolutions and sub-bands for each component
  19890. for (var c = 0; c < componentsCount; c++) {
  19891. var component = tile.components[c];
  19892. var decompositionLevelsCount =
  19893. component.codingStyleParameters.decompositionLevelsCount;
  19894. // Section B.5 Resolution levels and sub-bands
  19895. var resolutions = [];
  19896. var subbands = [];
  19897. for (var r = 0; r <= decompositionLevelsCount; r++) {
  19898. var blocksDimensions = getBlocksDimensions(context, component, r);
  19899. var resolution = {};
  19900. var scale = 1 << (decompositionLevelsCount - r);
  19901. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  19902. resolution.try0 = Math.ceil(component.tcy0 / scale);
  19903. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  19904. resolution.try1 = Math.ceil(component.tcy1 / scale);
  19905. resolution.resLevel = r;
  19906. buildPrecincts(context, resolution, blocksDimensions);
  19907. resolutions.push(resolution);
  19908. var subband;
  19909. if (r === 0) {
  19910. // one sub-band (LL) with last decomposition
  19911. subband = {};
  19912. subband.type = 'LL';
  19913. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  19914. subband.tby0 = Math.ceil(component.tcy0 / scale);
  19915. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  19916. subband.tby1 = Math.ceil(component.tcy1 / scale);
  19917. subband.resolution = resolution;
  19918. buildCodeblocks(context, subband, blocksDimensions);
  19919. subbands.push(subband);
  19920. resolution.subbands = [subband];
  19921. } else {
  19922. var bscale = 1 << (decompositionLevelsCount - r + 1);
  19923. var resolutionSubbands = [];
  19924. // three sub-bands (HL, LH and HH) with rest of decompositions
  19925. subband = {};
  19926. subband.type = 'HL';
  19927. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  19928. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  19929. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  19930. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  19931. subband.resolution = resolution;
  19932. buildCodeblocks(context, subband, blocksDimensions);
  19933. subbands.push(subband);
  19934. resolutionSubbands.push(subband);
  19935. subband = {};
  19936. subband.type = 'LH';
  19937. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  19938. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  19939. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  19940. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  19941. subband.resolution = resolution;
  19942. buildCodeblocks(context, subband, blocksDimensions);
  19943. subbands.push(subband);
  19944. resolutionSubbands.push(subband);
  19945. subband = {};
  19946. subband.type = 'HH';
  19947. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  19948. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  19949. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  19950. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  19951. subband.resolution = resolution;
  19952. buildCodeblocks(context, subband, blocksDimensions);
  19953. subbands.push(subband);
  19954. resolutionSubbands.push(subband);
  19955. resolution.subbands = resolutionSubbands;
  19956. }
  19957. }
  19958. component.resolutions = resolutions;
  19959. component.subbands = subbands;
  19960. }
  19961. // Generate the packets sequence
  19962. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  19963. switch (progressionOrder) {
  19964. case 0:
  19965. tile.packetsIterator =
  19966. new LayerResolutionComponentPositionIterator(context);
  19967. break;
  19968. case 1:
  19969. tile.packetsIterator =
  19970. new ResolutionLayerComponentPositionIterator(context);
  19971. break;
  19972. case 2:
  19973. tile.packetsIterator =
  19974. new ResolutionPositionComponentLayerIterator(context);
  19975. break;
  19976. case 3:
  19977. tile.packetsIterator =
  19978. new PositionComponentResolutionLayerIterator(context);
  19979. break;
  19980. case 4:
  19981. tile.packetsIterator =
  19982. new ComponentPositionResolutionLayerIterator(context);
  19983. break;
  19984. default:
  19985. throw new Error('JPX Error: Unsupported progression order ' +
  19986. progressionOrder);
  19987. }
  19988. }
  19989. function parseTilePackets(context, data, offset, dataLength) {
  19990. var position = 0;
  19991. var buffer, bufferSize = 0, skipNextBit = false;
  19992. function readBits(count) {
  19993. while (bufferSize < count) {
  19994. var b = data[offset + position];
  19995. position++;
  19996. if (skipNextBit) {
  19997. buffer = (buffer << 7) | b;
  19998. bufferSize += 7;
  19999. skipNextBit = false;
  20000. } else {
  20001. buffer = (buffer << 8) | b;
  20002. bufferSize += 8;
  20003. }
  20004. if (b === 0xFF) {
  20005. skipNextBit = true;
  20006. }
  20007. }
  20008. bufferSize -= count;
  20009. return (buffer >>> bufferSize) & ((1 << count) - 1);
  20010. }
  20011. function skipMarkerIfEqual(value) {
  20012. if (data[offset + position - 1] === 0xFF &&
  20013. data[offset + position] === value) {
  20014. skipBytes(1);
  20015. return true;
  20016. } else if (data[offset + position] === 0xFF &&
  20017. data[offset + position + 1] === value) {
  20018. skipBytes(2);
  20019. return true;
  20020. }
  20021. return false;
  20022. }
  20023. function skipBytes(count) {
  20024. position += count;
  20025. }
  20026. function alignToByte() {
  20027. bufferSize = 0;
  20028. if (skipNextBit) {
  20029. position++;
  20030. skipNextBit = false;
  20031. }
  20032. }
  20033. function readCodingpasses() {
  20034. if (readBits(1) === 0) {
  20035. return 1;
  20036. }
  20037. if (readBits(1) === 0) {
  20038. return 2;
  20039. }
  20040. var value = readBits(2);
  20041. if (value < 3) {
  20042. return value + 3;
  20043. }
  20044. value = readBits(5);
  20045. if (value < 31) {
  20046. return value + 6;
  20047. }
  20048. value = readBits(7);
  20049. return value + 37;
  20050. }
  20051. var tileIndex = context.currentTile.index;
  20052. var tile = context.tiles[tileIndex];
  20053. var sopMarkerUsed = context.COD.sopMarkerUsed;
  20054. var ephMarkerUsed = context.COD.ephMarkerUsed;
  20055. var packetsIterator = tile.packetsIterator;
  20056. while (position < dataLength) {
  20057. alignToByte();
  20058. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  20059. // Skip also marker segment length and packet sequence ID
  20060. skipBytes(4);
  20061. }
  20062. var packet = packetsIterator.nextPacket();
  20063. if (!readBits(1)) {
  20064. continue;
  20065. }
  20066. var layerNumber = packet.layerNumber;
  20067. var queue = [], codeblock;
  20068. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  20069. codeblock = packet.codeblocks[i];
  20070. var precinct = codeblock.precinct;
  20071. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  20072. var codeblockRow = codeblock.cby - precinct.cbyMin;
  20073. var codeblockIncluded = false;
  20074. var firstTimeInclusion = false;
  20075. var valueReady;
  20076. if (codeblock['included'] !== undefined) {
  20077. codeblockIncluded = !!readBits(1);
  20078. } else {
  20079. // reading inclusion tree
  20080. precinct = codeblock.precinct;
  20081. var inclusionTree, zeroBitPlanesTree;
  20082. if (precinct['inclusionTree'] !== undefined) {
  20083. inclusionTree = precinct.inclusionTree;
  20084. } else {
  20085. // building inclusion and zero bit-planes trees
  20086. var width = precinct.cbxMax - precinct.cbxMin + 1;
  20087. var height = precinct.cbyMax - precinct.cbyMin + 1;
  20088. inclusionTree = new InclusionTree(width, height, layerNumber);
  20089. zeroBitPlanesTree = new TagTree(width, height);
  20090. precinct.inclusionTree = inclusionTree;
  20091. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  20092. }
  20093. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  20094. while (true) {
  20095. if (readBits(1)) {
  20096. valueReady = !inclusionTree.nextLevel();
  20097. if (valueReady) {
  20098. codeblock.included = true;
  20099. codeblockIncluded = firstTimeInclusion = true;
  20100. break;
  20101. }
  20102. } else {
  20103. inclusionTree.incrementValue(layerNumber);
  20104. break;
  20105. }
  20106. }
  20107. }
  20108. }
  20109. if (!codeblockIncluded) {
  20110. continue;
  20111. }
  20112. if (firstTimeInclusion) {
  20113. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  20114. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  20115. while (true) {
  20116. if (readBits(1)) {
  20117. valueReady = !zeroBitPlanesTree.nextLevel();
  20118. if (valueReady) {
  20119. break;
  20120. }
  20121. } else {
  20122. zeroBitPlanesTree.incrementValue();
  20123. }
  20124. }
  20125. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  20126. }
  20127. var codingpasses = readCodingpasses();
  20128. while (readBits(1)) {
  20129. codeblock.Lblock++;
  20130. }
  20131. var codingpassesLog2 = log2(codingpasses);
  20132. // rounding down log2
  20133. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  20134. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  20135. var codedDataLength = readBits(bits);
  20136. queue.push({
  20137. codeblock: codeblock,
  20138. codingpasses: codingpasses,
  20139. dataLength: codedDataLength
  20140. });
  20141. }
  20142. alignToByte();
  20143. if (ephMarkerUsed) {
  20144. skipMarkerIfEqual(0x92);
  20145. }
  20146. while (queue.length > 0) {
  20147. var packetItem = queue.shift();
  20148. codeblock = packetItem.codeblock;
  20149. if (codeblock['data'] === undefined) {
  20150. codeblock.data = [];
  20151. }
  20152. codeblock.data.push({
  20153. data: data,
  20154. start: offset + position,
  20155. end: offset + position + packetItem.dataLength,
  20156. codingpasses: packetItem.codingpasses
  20157. });
  20158. position += packetItem.dataLength;
  20159. }
  20160. }
  20161. return position;
  20162. }
  20163. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  20164. delta, mb, reversible, segmentationSymbolUsed) {
  20165. var x0 = subband.tbx0;
  20166. var y0 = subband.tby0;
  20167. var width = subband.tbx1 - subband.tbx0;
  20168. var codeblocks = subband.codeblocks;
  20169. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  20170. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  20171. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  20172. var codeblock = codeblocks[i];
  20173. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  20174. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  20175. if (blockWidth === 0 || blockHeight === 0) {
  20176. continue;
  20177. }
  20178. if (codeblock['data'] === undefined) {
  20179. continue;
  20180. }
  20181. var bitModel, currentCodingpassType;
  20182. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  20183. codeblock.zeroBitPlanes, mb);
  20184. currentCodingpassType = 2; // first bit plane starts from cleanup
  20185. // collect data
  20186. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  20187. var j, jj, dataItem;
  20188. for (j = 0, jj = data.length; j < jj; j++) {
  20189. dataItem = data[j];
  20190. totalLength += dataItem.end - dataItem.start;
  20191. codingpasses += dataItem.codingpasses;
  20192. }
  20193. var encodedData = new Uint8Array(totalLength);
  20194. var position = 0;
  20195. for (j = 0, jj = data.length; j < jj; j++) {
  20196. dataItem = data[j];
  20197. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  20198. encodedData.set(chunk, position);
  20199. position += chunk.length;
  20200. }
  20201. // decoding the item
  20202. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  20203. bitModel.setDecoder(decoder);
  20204. for (j = 0; j < codingpasses; j++) {
  20205. switch (currentCodingpassType) {
  20206. case 0:
  20207. bitModel.runSignificancePropogationPass();
  20208. break;
  20209. case 1:
  20210. bitModel.runMagnitudeRefinementPass();
  20211. break;
  20212. case 2:
  20213. bitModel.runCleanupPass();
  20214. if (segmentationSymbolUsed) {
  20215. bitModel.checkSegmentationSymbol();
  20216. }
  20217. break;
  20218. }
  20219. currentCodingpassType = (currentCodingpassType + 1) % 3;
  20220. }
  20221. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  20222. var sign = bitModel.coefficentsSign;
  20223. var magnitude = bitModel.coefficentsMagnitude;
  20224. var bitsDecoded = bitModel.bitsDecoded;
  20225. var magnitudeCorrection = reversible ? 0 : 0.5;
  20226. var k, n, nb;
  20227. position = 0;
  20228. // Do the interleaving of Section F.3.3 here, so we do not need
  20229. // to copy later. LL level is not interleaved, just copied.
  20230. var interleave = (subband.type !== 'LL');
  20231. for (j = 0; j < blockHeight; j++) {
  20232. var row = (offset / width) | 0; // row in the non-interleaved subband
  20233. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  20234. for (k = 0; k < blockWidth; k++) {
  20235. n = magnitude[position];
  20236. if (n !== 0) {
  20237. n = (n + magnitudeCorrection) * delta;
  20238. if (sign[position] !== 0) {
  20239. n = -n;
  20240. }
  20241. nb = bitsDecoded[position];
  20242. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  20243. if (reversible && (nb >= mb)) {
  20244. coefficients[pos] = n;
  20245. } else {
  20246. coefficients[pos] = n * (1 << (mb - nb));
  20247. }
  20248. }
  20249. offset++;
  20250. position++;
  20251. }
  20252. offset += width - blockWidth;
  20253. }
  20254. }
  20255. }
  20256. function transformTile(context, tile, c) {
  20257. var component = tile.components[c];
  20258. var codingStyleParameters = component.codingStyleParameters;
  20259. var quantizationParameters = component.quantizationParameters;
  20260. var decompositionLevelsCount =
  20261. codingStyleParameters.decompositionLevelsCount;
  20262. var spqcds = quantizationParameters.SPqcds;
  20263. var scalarExpounded = quantizationParameters.scalarExpounded;
  20264. var guardBits = quantizationParameters.guardBits;
  20265. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  20266. var precision = context.components[c].precision;
  20267. var reversible = codingStyleParameters.reversibleTransformation;
  20268. var transform = (reversible ? new ReversibleTransform() :
  20269. new IrreversibleTransform());
  20270. var subbandCoefficients = [];
  20271. var b = 0;
  20272. for (var i = 0; i <= decompositionLevelsCount; i++) {
  20273. var resolution = component.resolutions[i];
  20274. var width = resolution.trx1 - resolution.trx0;
  20275. var height = resolution.try1 - resolution.try0;
  20276. // Allocate space for the whole sublevel.
  20277. var coefficients = new Float32Array(width * height);
  20278. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  20279. var mu, epsilon;
  20280. if (!scalarExpounded) {
  20281. // formula E-5
  20282. mu = spqcds[0].mu;
  20283. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  20284. } else {
  20285. mu = spqcds[b].mu;
  20286. epsilon = spqcds[b].epsilon;
  20287. b++;
  20288. }
  20289. var subband = resolution.subbands[j];
  20290. var gainLog2 = SubbandsGainLog2[subband.type];
  20291. // calulate quantization coefficient (Section E.1.1.1)
  20292. var delta = (reversible ? 1 :
  20293. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  20294. var mb = (guardBits + epsilon - 1);
  20295. // In the first resolution level, copyCoefficients will fill the
  20296. // whole array with coefficients. In the succeding passes,
  20297. // copyCoefficients will consecutively fill in the values that belong
  20298. // to the interleaved positions of the HL, LH, and HH coefficients.
  20299. // The LL coefficients will then be interleaved in Transform.iterate().
  20300. copyCoefficients(coefficients, width, height, subband, delta, mb,
  20301. reversible, segmentationSymbolUsed);
  20302. }
  20303. subbandCoefficients.push({
  20304. width: width,
  20305. height: height,
  20306. items: coefficients
  20307. });
  20308. }
  20309. var result = transform.calculate(subbandCoefficients,
  20310. component.tcx0, component.tcy0);
  20311. return {
  20312. left: component.tcx0,
  20313. top: component.tcy0,
  20314. width: result.width,
  20315. height: result.height,
  20316. items: result.items
  20317. };
  20318. }
  20319. function transformComponents(context) {
  20320. var siz = context.SIZ;
  20321. var components = context.components;
  20322. var componentsCount = siz.Csiz;
  20323. var resultImages = [];
  20324. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  20325. var tile = context.tiles[i];
  20326. var transformedTiles = [];
  20327. var c;
  20328. for (c = 0; c < componentsCount; c++) {
  20329. transformedTiles[c] = transformTile(context, tile, c);
  20330. }
  20331. var tile0 = transformedTiles[0];
  20332. var out = new Uint8Array(tile0.items.length * componentsCount);
  20333. var result = {
  20334. left: tile0.left,
  20335. top: tile0.top,
  20336. width: tile0.width,
  20337. height: tile0.height,
  20338. items: out
  20339. };
  20340. // Section G.2.2 Inverse multi component transform
  20341. var shift, offset, max, min, maxK;
  20342. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  20343. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  20344. var fourComponents = componentsCount === 4;
  20345. var y0items = transformedTiles[0].items;
  20346. var y1items = transformedTiles[1].items;
  20347. var y2items = transformedTiles[2].items;
  20348. var y3items = fourComponents ? transformedTiles[3].items : null;
  20349. // HACK: The multiple component transform formulas below assume that
  20350. // all components have the same precision. With this in mind, we
  20351. // compute shift and offset only once.
  20352. shift = components[0].precision - 8;
  20353. offset = (128 << shift) + 0.5;
  20354. max = 255 * (1 << shift);
  20355. maxK = max * 0.5;
  20356. min = -maxK;
  20357. var component0 = tile.components[0];
  20358. var alpha01 = componentsCount - 3;
  20359. jj = y0items.length;
  20360. if (!component0.codingStyleParameters.reversibleTransformation) {
  20361. // inverse irreversible multiple component transform
  20362. for (j = 0; j < jj; j++, pos += alpha01) {
  20363. y0 = y0items[j] + offset;
  20364. y1 = y1items[j];
  20365. y2 = y2items[j];
  20366. r = y0 + 1.402 * y2;
  20367. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  20368. b = y0 + 1.772 * y1;
  20369. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  20370. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  20371. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  20372. }
  20373. } else {
  20374. // inverse reversible multiple component transform
  20375. for (j = 0; j < jj; j++, pos += alpha01) {
  20376. y0 = y0items[j] + offset;
  20377. y1 = y1items[j];
  20378. y2 = y2items[j];
  20379. g = y0 - ((y2 + y1) >> 2);
  20380. r = g + y2;
  20381. b = g + y1;
  20382. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  20383. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  20384. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  20385. }
  20386. }
  20387. if (fourComponents) {
  20388. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  20389. k = y3items[j];
  20390. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  20391. }
  20392. }
  20393. } else { // no multi-component transform
  20394. for (c = 0; c < componentsCount; c++) {
  20395. var items = transformedTiles[c].items;
  20396. shift = components[c].precision - 8;
  20397. offset = (128 << shift) + 0.5;
  20398. max = (127.5 * (1 << shift));
  20399. min = -max;
  20400. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  20401. val = items[j];
  20402. out[pos] = val <= min ? 0 :
  20403. val >= max ? 255 : (val + offset) >> shift;
  20404. pos += componentsCount;
  20405. }
  20406. }
  20407. }
  20408. resultImages.push(result);
  20409. }
  20410. return resultImages;
  20411. }
  20412. function initializeTile(context, tileIndex) {
  20413. var siz = context.SIZ;
  20414. var componentsCount = siz.Csiz;
  20415. var tile = context.tiles[tileIndex];
  20416. for (var c = 0; c < componentsCount; c++) {
  20417. var component = tile.components[c];
  20418. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  20419. context.currentTile.QCC[c] : context.currentTile.QCD);
  20420. component.quantizationParameters = qcdOrQcc;
  20421. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  20422. context.currentTile.COC[c] : context.currentTile.COD);
  20423. component.codingStyleParameters = codOrCoc;
  20424. }
  20425. tile.codingStyleDefaultParameters = context.currentTile.COD;
  20426. }
  20427. // Section B.10.2 Tag trees
  20428. var TagTree = (function TagTreeClosure() {
  20429. function TagTree(width, height) {
  20430. var levelsLength = log2(Math.max(width, height)) + 1;
  20431. this.levels = [];
  20432. for (var i = 0; i < levelsLength; i++) {
  20433. var level = {
  20434. width: width,
  20435. height: height,
  20436. items: []
  20437. };
  20438. this.levels.push(level);
  20439. width = Math.ceil(width / 2);
  20440. height = Math.ceil(height / 2);
  20441. }
  20442. }
  20443. TagTree.prototype = {
  20444. reset: function TagTree_reset(i, j) {
  20445. var currentLevel = 0, value = 0, level;
  20446. while (currentLevel < this.levels.length) {
  20447. level = this.levels[currentLevel];
  20448. var index = i + j * level.width;
  20449. if (level.items[index] !== undefined) {
  20450. value = level.items[index];
  20451. break;
  20452. }
  20453. level.index = index;
  20454. i >>= 1;
  20455. j >>= 1;
  20456. currentLevel++;
  20457. }
  20458. currentLevel--;
  20459. level = this.levels[currentLevel];
  20460. level.items[level.index] = value;
  20461. this.currentLevel = currentLevel;
  20462. delete this.value;
  20463. },
  20464. incrementValue: function TagTree_incrementValue() {
  20465. var level = this.levels[this.currentLevel];
  20466. level.items[level.index]++;
  20467. },
  20468. nextLevel: function TagTree_nextLevel() {
  20469. var currentLevel = this.currentLevel;
  20470. var level = this.levels[currentLevel];
  20471. var value = level.items[level.index];
  20472. currentLevel--;
  20473. if (currentLevel < 0) {
  20474. this.value = value;
  20475. return false;
  20476. }
  20477. this.currentLevel = currentLevel;
  20478. level = this.levels[currentLevel];
  20479. level.items[level.index] = value;
  20480. return true;
  20481. }
  20482. };
  20483. return TagTree;
  20484. })();
  20485. var InclusionTree = (function InclusionTreeClosure() {
  20486. function InclusionTree(width, height, defaultValue) {
  20487. var levelsLength = log2(Math.max(width, height)) + 1;
  20488. this.levels = [];
  20489. for (var i = 0; i < levelsLength; i++) {
  20490. var items = new Uint8Array(width * height);
  20491. for (var j = 0, jj = items.length; j < jj; j++) {
  20492. items[j] = defaultValue;
  20493. }
  20494. var level = {
  20495. width: width,
  20496. height: height,
  20497. items: items
  20498. };
  20499. this.levels.push(level);
  20500. width = Math.ceil(width / 2);
  20501. height = Math.ceil(height / 2);
  20502. }
  20503. }
  20504. InclusionTree.prototype = {
  20505. reset: function InclusionTree_reset(i, j, stopValue) {
  20506. var currentLevel = 0;
  20507. while (currentLevel < this.levels.length) {
  20508. var level = this.levels[currentLevel];
  20509. var index = i + j * level.width;
  20510. level.index = index;
  20511. var value = level.items[index];
  20512. if (value === 0xFF) {
  20513. break;
  20514. }
  20515. if (value > stopValue) {
  20516. this.currentLevel = currentLevel;
  20517. // already know about this one, propagating the value to top levels
  20518. this.propagateValues();
  20519. return false;
  20520. }
  20521. i >>= 1;
  20522. j >>= 1;
  20523. currentLevel++;
  20524. }
  20525. this.currentLevel = currentLevel - 1;
  20526. return true;
  20527. },
  20528. incrementValue: function InclusionTree_incrementValue(stopValue) {
  20529. var level = this.levels[this.currentLevel];
  20530. level.items[level.index] = stopValue + 1;
  20531. this.propagateValues();
  20532. },
  20533. propagateValues: function InclusionTree_propagateValues() {
  20534. var levelIndex = this.currentLevel;
  20535. var level = this.levels[levelIndex];
  20536. var currentValue = level.items[level.index];
  20537. while (--levelIndex >= 0) {
  20538. level = this.levels[levelIndex];
  20539. level.items[level.index] = currentValue;
  20540. }
  20541. },
  20542. nextLevel: function InclusionTree_nextLevel() {
  20543. var currentLevel = this.currentLevel;
  20544. var level = this.levels[currentLevel];
  20545. var value = level.items[level.index];
  20546. level.items[level.index] = 0xFF;
  20547. currentLevel--;
  20548. if (currentLevel < 0) {
  20549. return false;
  20550. }
  20551. this.currentLevel = currentLevel;
  20552. level = this.levels[currentLevel];
  20553. level.items[level.index] = value;
  20554. return true;
  20555. }
  20556. };
  20557. return InclusionTree;
  20558. })();
  20559. // Section D. Coefficient bit modeling
  20560. var BitModel = (function BitModelClosure() {
  20561. var UNIFORM_CONTEXT = 17;
  20562. var RUNLENGTH_CONTEXT = 18;
  20563. // Table D-1
  20564. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  20565. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  20566. var LLAndLHContextsLabel = new Uint8Array([
  20567. 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,
  20568. 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,
  20569. 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
  20570. ]);
  20571. var HLContextLabel = new Uint8Array([
  20572. 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,
  20573. 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,
  20574. 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
  20575. ]);
  20576. var HHContextLabel = new Uint8Array([
  20577. 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,
  20578. 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,
  20579. 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
  20580. ]);
  20581. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  20582. this.width = width;
  20583. this.height = height;
  20584. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  20585. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  20586. var coefficientCount = width * height;
  20587. // coefficients outside the encoding region treated as insignificant
  20588. // add border state cells for significanceState
  20589. this.neighborsSignificance = new Uint8Array(coefficientCount);
  20590. this.coefficentsSign = new Uint8Array(coefficientCount);
  20591. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  20592. mb > 6 ? new Uint16Array(coefficientCount) :
  20593. new Uint8Array(coefficientCount);
  20594. this.processingFlags = new Uint8Array(coefficientCount);
  20595. var bitsDecoded = new Uint8Array(coefficientCount);
  20596. if (zeroBitPlanes !== 0) {
  20597. for (var i = 0; i < coefficientCount; i++) {
  20598. bitsDecoded[i] = zeroBitPlanes;
  20599. }
  20600. }
  20601. this.bitsDecoded = bitsDecoded;
  20602. this.reset();
  20603. }
  20604. BitModel.prototype = {
  20605. setDecoder: function BitModel_setDecoder(decoder) {
  20606. this.decoder = decoder;
  20607. },
  20608. reset: function BitModel_reset() {
  20609. // We have 17 contexts that are accessed via context labels,
  20610. // plus the uniform and runlength context.
  20611. this.contexts = new Int8Array(19);
  20612. // Contexts are packed into 1 byte:
  20613. // highest 7 bits carry the index, lowest bit carries mps
  20614. this.contexts[0] = (4 << 1) | 0;
  20615. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  20616. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  20617. },
  20618. setNeighborsSignificance:
  20619. function BitModel_setNeighborsSignificance(row, column, index) {
  20620. var neighborsSignificance = this.neighborsSignificance;
  20621. var width = this.width, height = this.height;
  20622. var left = (column > 0);
  20623. var right = (column + 1 < width);
  20624. var i;
  20625. if (row > 0) {
  20626. i = index - width;
  20627. if (left) {
  20628. neighborsSignificance[i - 1] += 0x10;
  20629. }
  20630. if (right) {
  20631. neighborsSignificance[i + 1] += 0x10;
  20632. }
  20633. neighborsSignificance[i] += 0x04;
  20634. }
  20635. if (row + 1 < height) {
  20636. i = index + width;
  20637. if (left) {
  20638. neighborsSignificance[i - 1] += 0x10;
  20639. }
  20640. if (right) {
  20641. neighborsSignificance[i + 1] += 0x10;
  20642. }
  20643. neighborsSignificance[i] += 0x04;
  20644. }
  20645. if (left) {
  20646. neighborsSignificance[index - 1] += 0x01;
  20647. }
  20648. if (right) {
  20649. neighborsSignificance[index + 1] += 0x01;
  20650. }
  20651. neighborsSignificance[index] |= 0x80;
  20652. },
  20653. runSignificancePropogationPass:
  20654. function BitModel_runSignificancePropogationPass() {
  20655. var decoder = this.decoder;
  20656. var width = this.width, height = this.height;
  20657. var coefficentsMagnitude = this.coefficentsMagnitude;
  20658. var coefficentsSign = this.coefficentsSign;
  20659. var neighborsSignificance = this.neighborsSignificance;
  20660. var processingFlags = this.processingFlags;
  20661. var contexts = this.contexts;
  20662. var labels = this.contextLabelTable;
  20663. var bitsDecoded = this.bitsDecoded;
  20664. var processedInverseMask = ~1;
  20665. var processedMask = 1;
  20666. var firstMagnitudeBitMask = 2;
  20667. for (var i0 = 0; i0 < height; i0 += 4) {
  20668. for (var j = 0; j < width; j++) {
  20669. var index = i0 * width + j;
  20670. for (var i1 = 0; i1 < 4; i1++, index += width) {
  20671. var i = i0 + i1;
  20672. if (i >= height) {
  20673. break;
  20674. }
  20675. // clear processed flag first
  20676. processingFlags[index] &= processedInverseMask;
  20677. if (coefficentsMagnitude[index] ||
  20678. !neighborsSignificance[index]) {
  20679. continue;
  20680. }
  20681. var contextLabel = labels[neighborsSignificance[index]];
  20682. var decision = decoder.readBit(contexts, contextLabel);
  20683. if (decision) {
  20684. var sign = this.decodeSignBit(i, j, index);
  20685. coefficentsSign[index] = sign;
  20686. coefficentsMagnitude[index] = 1;
  20687. this.setNeighborsSignificance(i, j, index);
  20688. processingFlags[index] |= firstMagnitudeBitMask;
  20689. }
  20690. bitsDecoded[index]++;
  20691. processingFlags[index] |= processedMask;
  20692. }
  20693. }
  20694. }
  20695. },
  20696. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  20697. var width = this.width, height = this.height;
  20698. var coefficentsMagnitude = this.coefficentsMagnitude;
  20699. var coefficentsSign = this.coefficentsSign;
  20700. var contribution, sign0, sign1, significance1;
  20701. var contextLabel, decoded;
  20702. // calculate horizontal contribution
  20703. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  20704. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  20705. sign1 = coefficentsSign[index + 1];
  20706. if (significance1) {
  20707. sign0 = coefficentsSign[index - 1];
  20708. contribution = 1 - sign1 - sign0;
  20709. } else {
  20710. contribution = 1 - sign1 - sign1;
  20711. }
  20712. } else if (significance1) {
  20713. sign0 = coefficentsSign[index - 1];
  20714. contribution = 1 - sign0 - sign0;
  20715. } else {
  20716. contribution = 0;
  20717. }
  20718. var horizontalContribution = 3 * contribution;
  20719. // calculate vertical contribution and combine with the horizontal
  20720. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  20721. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  20722. sign1 = coefficentsSign[index + width];
  20723. if (significance1) {
  20724. sign0 = coefficentsSign[index - width];
  20725. contribution = 1 - sign1 - sign0 + horizontalContribution;
  20726. } else {
  20727. contribution = 1 - sign1 - sign1 + horizontalContribution;
  20728. }
  20729. } else if (significance1) {
  20730. sign0 = coefficentsSign[index - width];
  20731. contribution = 1 - sign0 - sign0 + horizontalContribution;
  20732. } else {
  20733. contribution = horizontalContribution;
  20734. }
  20735. if (contribution >= 0) {
  20736. contextLabel = 9 + contribution;
  20737. decoded = this.decoder.readBit(this.contexts, contextLabel);
  20738. } else {
  20739. contextLabel = 9 - contribution;
  20740. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  20741. }
  20742. return decoded;
  20743. },
  20744. runMagnitudeRefinementPass:
  20745. function BitModel_runMagnitudeRefinementPass() {
  20746. var decoder = this.decoder;
  20747. var width = this.width, height = this.height;
  20748. var coefficentsMagnitude = this.coefficentsMagnitude;
  20749. var neighborsSignificance = this.neighborsSignificance;
  20750. var contexts = this.contexts;
  20751. var bitsDecoded = this.bitsDecoded;
  20752. var processingFlags = this.processingFlags;
  20753. var processedMask = 1;
  20754. var firstMagnitudeBitMask = 2;
  20755. var length = width * height;
  20756. var width4 = width * 4;
  20757. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  20758. indexNext = Math.min(length, index0 + width4);
  20759. for (var j = 0; j < width; j++) {
  20760. for (var index = index0 + j; index < indexNext; index += width) {
  20761. // significant but not those that have just become
  20762. if (!coefficentsMagnitude[index] ||
  20763. (processingFlags[index] & processedMask) !== 0) {
  20764. continue;
  20765. }
  20766. var contextLabel = 16;
  20767. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  20768. processingFlags[index] ^= firstMagnitudeBitMask;
  20769. // first refinement
  20770. var significance = neighborsSignificance[index] & 127;
  20771. contextLabel = significance === 0 ? 15 : 14;
  20772. }
  20773. var bit = decoder.readBit(contexts, contextLabel);
  20774. coefficentsMagnitude[index] =
  20775. (coefficentsMagnitude[index] << 1) | bit;
  20776. bitsDecoded[index]++;
  20777. processingFlags[index] |= processedMask;
  20778. }
  20779. }
  20780. }
  20781. },
  20782. runCleanupPass: function BitModel_runCleanupPass() {
  20783. var decoder = this.decoder;
  20784. var width = this.width, height = this.height;
  20785. var neighborsSignificance = this.neighborsSignificance;
  20786. var coefficentsMagnitude = this.coefficentsMagnitude;
  20787. var coefficentsSign = this.coefficentsSign;
  20788. var contexts = this.contexts;
  20789. var labels = this.contextLabelTable;
  20790. var bitsDecoded = this.bitsDecoded;
  20791. var processingFlags = this.processingFlags;
  20792. var processedMask = 1;
  20793. var firstMagnitudeBitMask = 2;
  20794. var oneRowDown = width;
  20795. var twoRowsDown = width * 2;
  20796. var threeRowsDown = width * 3;
  20797. var iNext;
  20798. for (var i0 = 0; i0 < height; i0 = iNext) {
  20799. iNext = Math.min(i0 + 4, height);
  20800. var indexBase = i0 * width;
  20801. var checkAllEmpty = i0 + 3 < height;
  20802. for (var j = 0; j < width; j++) {
  20803. var index0 = indexBase + j;
  20804. // using the property: labels[neighborsSignificance[index]] === 0
  20805. // when neighborsSignificance[index] === 0
  20806. var allEmpty = (checkAllEmpty &&
  20807. processingFlags[index0] === 0 &&
  20808. processingFlags[index0 + oneRowDown] === 0 &&
  20809. processingFlags[index0 + twoRowsDown] === 0 &&
  20810. processingFlags[index0 + threeRowsDown] === 0 &&
  20811. neighborsSignificance[index0] === 0 &&
  20812. neighborsSignificance[index0 + oneRowDown] === 0 &&
  20813. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  20814. neighborsSignificance[index0 + threeRowsDown] === 0);
  20815. var i1 = 0, index = index0;
  20816. var i = i0, sign;
  20817. if (allEmpty) {
  20818. var hasSignificantCoefficent =
  20819. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  20820. if (!hasSignificantCoefficent) {
  20821. bitsDecoded[index0]++;
  20822. bitsDecoded[index0 + oneRowDown]++;
  20823. bitsDecoded[index0 + twoRowsDown]++;
  20824. bitsDecoded[index0 + threeRowsDown]++;
  20825. continue; // next column
  20826. }
  20827. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  20828. decoder.readBit(contexts, UNIFORM_CONTEXT);
  20829. if (i1 !== 0) {
  20830. i = i0 + i1;
  20831. index += i1 * width;
  20832. }
  20833. sign = this.decodeSignBit(i, j, index);
  20834. coefficentsSign[index] = sign;
  20835. coefficentsMagnitude[index] = 1;
  20836. this.setNeighborsSignificance(i, j, index);
  20837. processingFlags[index] |= firstMagnitudeBitMask;
  20838. index = index0;
  20839. for (var i2 = i0; i2 <= i; i2++, index += width) {
  20840. bitsDecoded[index]++;
  20841. }
  20842. i1++;
  20843. }
  20844. for (i = i0 + i1; i < iNext; i++, index += width) {
  20845. if (coefficentsMagnitude[index] ||
  20846. (processingFlags[index] & processedMask) !== 0) {
  20847. continue;
  20848. }
  20849. var contextLabel = labels[neighborsSignificance[index]];
  20850. var decision = decoder.readBit(contexts, contextLabel);
  20851. if (decision === 1) {
  20852. sign = this.decodeSignBit(i, j, index);
  20853. coefficentsSign[index] = sign;
  20854. coefficentsMagnitude[index] = 1;
  20855. this.setNeighborsSignificance(i, j, index);
  20856. processingFlags[index] |= firstMagnitudeBitMask;
  20857. }
  20858. bitsDecoded[index]++;
  20859. }
  20860. }
  20861. }
  20862. },
  20863. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  20864. var decoder = this.decoder;
  20865. var contexts = this.contexts;
  20866. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  20867. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  20868. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  20869. decoder.readBit(contexts, UNIFORM_CONTEXT);
  20870. if (symbol !== 0xA) {
  20871. throw new Error('JPX Error: Invalid segmentation symbol');
  20872. }
  20873. }
  20874. };
  20875. return BitModel;
  20876. })();
  20877. // Section F, Discrete wavelet transformation
  20878. var Transform = (function TransformClosure() {
  20879. function Transform() {}
  20880. Transform.prototype.calculate =
  20881. function transformCalculate(subbands, u0, v0) {
  20882. var ll = subbands[0];
  20883. for (var i = 1, ii = subbands.length; i < ii; i++) {
  20884. ll = this.iterate(ll, subbands[i], u0, v0);
  20885. }
  20886. return ll;
  20887. };
  20888. Transform.prototype.extend = function extend(buffer, offset, size) {
  20889. // Section F.3.7 extending... using max extension of 4
  20890. var i1 = offset - 1, j1 = offset + 1;
  20891. var i2 = offset + size - 2, j2 = offset + size;
  20892. buffer[i1--] = buffer[j1++];
  20893. buffer[j2++] = buffer[i2--];
  20894. buffer[i1--] = buffer[j1++];
  20895. buffer[j2++] = buffer[i2--];
  20896. buffer[i1--] = buffer[j1++];
  20897. buffer[j2++] = buffer[i2--];
  20898. buffer[i1] = buffer[j1];
  20899. buffer[j2] = buffer[i2];
  20900. };
  20901. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  20902. u0, v0) {
  20903. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  20904. var width = hl_lh_hh.width;
  20905. var height = hl_lh_hh.height;
  20906. var items = hl_lh_hh.items;
  20907. var i, j, k, l, u, v;
  20908. // Interleave LL according to Section F.3.3
  20909. for (k = 0, i = 0; i < llHeight; i++) {
  20910. l = i * 2 * width;
  20911. for (j = 0; j < llWidth; j++, k++, l += 2) {
  20912. items[l] = llItems[k];
  20913. }
  20914. }
  20915. // The LL band is not needed anymore.
  20916. llItems = ll.items = null;
  20917. var bufferPadding = 4;
  20918. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  20919. // Section F.3.4 HOR_SR
  20920. if (width === 1) {
  20921. // if width = 1, when u0 even keep items as is, when odd divide by 2
  20922. if ((u0 & 1) !== 0) {
  20923. for (v = 0, k = 0; v < height; v++, k += width) {
  20924. items[k] *= 0.5;
  20925. }
  20926. }
  20927. } else {
  20928. for (v = 0, k = 0; v < height; v++, k += width) {
  20929. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  20930. this.extend(rowBuffer, bufferPadding, width);
  20931. this.filter(rowBuffer, bufferPadding, width);
  20932. items.set(
  20933. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  20934. k);
  20935. }
  20936. }
  20937. // Accesses to the items array can take long, because it may not fit into
  20938. // CPU cache and has to be fetched from main memory. Since subsequent
  20939. // accesses to the items array are not local when reading columns, we
  20940. // have a cache miss every time. To reduce cache misses, get up to
  20941. // 'numBuffers' items at a time and store them into the individual
  20942. // buffers. The colBuffers should be small enough to fit into CPU cache.
  20943. var numBuffers = 16;
  20944. var colBuffers = [];
  20945. for (i = 0; i < numBuffers; i++) {
  20946. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  20947. }
  20948. var b, currentBuffer = 0;
  20949. ll = bufferPadding + height;
  20950. // Section F.3.5 VER_SR
  20951. if (height === 1) {
  20952. // if height = 1, when v0 even keep items as is, when odd divide by 2
  20953. if ((v0 & 1) !== 0) {
  20954. for (u = 0; u < width; u++) {
  20955. items[u] *= 0.5;
  20956. }
  20957. }
  20958. } else {
  20959. for (u = 0; u < width; u++) {
  20960. // if we ran out of buffers, copy several image columns at once
  20961. if (currentBuffer === 0) {
  20962. numBuffers = Math.min(width - u, numBuffers);
  20963. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  20964. for (b = 0; b < numBuffers; b++) {
  20965. colBuffers[b][l] = items[k + b];
  20966. }
  20967. }
  20968. currentBuffer = numBuffers;
  20969. }
  20970. currentBuffer--;
  20971. var buffer = colBuffers[currentBuffer];
  20972. this.extend(buffer, bufferPadding, height);
  20973. this.filter(buffer, bufferPadding, height);
  20974. // If this is last buffer in this group of buffers, flush all buffers.
  20975. if (currentBuffer === 0) {
  20976. k = u - numBuffers + 1;
  20977. for (l = bufferPadding; l < ll; k += width, l++) {
  20978. for (b = 0; b < numBuffers; b++) {
  20979. items[k + b] = colBuffers[b][l];
  20980. }
  20981. }
  20982. }
  20983. }
  20984. }
  20985. return {
  20986. width: width,
  20987. height: height,
  20988. items: items
  20989. };
  20990. };
  20991. return Transform;
  20992. })();
  20993. // Section 3.8.2 Irreversible 9-7 filter
  20994. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  20995. function IrreversibleTransform() {
  20996. Transform.call(this);
  20997. }
  20998. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  20999. IrreversibleTransform.prototype.filter =
  21000. function irreversibleTransformFilter(x, offset, length) {
  21001. var len = length >> 1;
  21002. offset = offset | 0;
  21003. var j, n, current, next;
  21004. var alpha = -1.586134342059924;
  21005. var beta = -0.052980118572961;
  21006. var gamma = 0.882911075530934;
  21007. var delta = 0.443506852043971;
  21008. var K = 1.230174104914001;
  21009. var K_ = 1 / K;
  21010. // step 1 is combined with step 3
  21011. // step 2
  21012. j = offset - 3;
  21013. for (n = len + 4; n--; j += 2) {
  21014. x[j] *= K_;
  21015. }
  21016. // step 1 & 3
  21017. j = offset - 2;
  21018. current = delta * x[j -1];
  21019. for (n = len + 3; n--; j += 2) {
  21020. next = delta * x[j + 1];
  21021. x[j] = K * x[j] - current - next;
  21022. if (n--) {
  21023. j += 2;
  21024. current = delta * x[j + 1];
  21025. x[j] = K * x[j] - current - next;
  21026. } else {
  21027. break;
  21028. }
  21029. }
  21030. // step 4
  21031. j = offset - 1;
  21032. current = gamma * x[j - 1];
  21033. for (n = len + 2; n--; j += 2) {
  21034. next = gamma * x[j + 1];
  21035. x[j] -= current + next;
  21036. if (n--) {
  21037. j += 2;
  21038. current = gamma * x[j + 1];
  21039. x[j] -= current + next;
  21040. } else {
  21041. break;
  21042. }
  21043. }
  21044. // step 5
  21045. j = offset;
  21046. current = beta * x[j - 1];
  21047. for (n = len + 1; n--; j += 2) {
  21048. next = beta * x[j + 1];
  21049. x[j] -= current + next;
  21050. if (n--) {
  21051. j += 2;
  21052. current = beta * x[j + 1];
  21053. x[j] -= current + next;
  21054. } else {
  21055. break;
  21056. }
  21057. }
  21058. // step 6
  21059. if (len !== 0) {
  21060. j = offset + 1;
  21061. current = alpha * x[j - 1];
  21062. for (n = len; n--; j += 2) {
  21063. next = alpha * x[j + 1];
  21064. x[j] -= current + next;
  21065. if (n--) {
  21066. j += 2;
  21067. current = alpha * x[j + 1];
  21068. x[j] -= current + next;
  21069. } else {
  21070. break;
  21071. }
  21072. }
  21073. }
  21074. };
  21075. return IrreversibleTransform;
  21076. })();
  21077. // Section 3.8.1 Reversible 5-3 filter
  21078. var ReversibleTransform = (function ReversibleTransformClosure() {
  21079. function ReversibleTransform() {
  21080. Transform.call(this);
  21081. }
  21082. ReversibleTransform.prototype = Object.create(Transform.prototype);
  21083. ReversibleTransform.prototype.filter =
  21084. function reversibleTransformFilter(x, offset, length) {
  21085. var len = length >> 1;
  21086. offset = offset | 0;
  21087. var j, n;
  21088. for (j = offset, n = len + 1; n--; j += 2) {
  21089. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  21090. }
  21091. for (j = offset + 1, n = len; n--; j += 2) {
  21092. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  21093. }
  21094. };
  21095. return ReversibleTransform;
  21096. })();
  21097. return JpxImage;
  21098. })();
  21099. exports.JpxImage = JpxImage;
  21100. }));
  21101. (function (root, factory) {
  21102. {
  21103. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  21104. }
  21105. }(this, function (exports, sharedUtil) {
  21106. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  21107. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  21108. // Workaround for missing math precison in JS.
  21109. var MASK_HIGH = 0xffff0000;
  21110. var MASK_LOW = 0xffff;
  21111. function MurmurHash3_64 (seed) {
  21112. var SEED = 0xc3d2e1f0;
  21113. this.h1 = seed ? seed & 0xffffffff : SEED;
  21114. this.h2 = seed ? seed & 0xffffffff : SEED;
  21115. }
  21116. var alwaysUseUint32ArrayView = false;
  21117. // old webkits have issues with non-aligned arrays
  21118. try {
  21119. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  21120. } catch (e) {
  21121. alwaysUseUint32ArrayView = true;
  21122. }
  21123. MurmurHash3_64.prototype = {
  21124. update: function MurmurHash3_64_update(input) {
  21125. var useUint32ArrayView = alwaysUseUint32ArrayView;
  21126. var i;
  21127. if (typeof input === 'string') {
  21128. var data = new Uint8Array(input.length * 2);
  21129. var length = 0;
  21130. for (i = 0; i < input.length; i++) {
  21131. var code = input.charCodeAt(i);
  21132. if (code <= 0xff) {
  21133. data[length++] = code;
  21134. }
  21135. else {
  21136. data[length++] = code >>> 8;
  21137. data[length++] = code & 0xff;
  21138. }
  21139. }
  21140. } else if (input instanceof Uint8Array) {
  21141. data = input;
  21142. length = data.length;
  21143. } else if (typeof input === 'object' && ('length' in input)) {
  21144. // processing regular arrays as well, e.g. for IE9
  21145. data = input;
  21146. length = data.length;
  21147. useUint32ArrayView = true;
  21148. } else {
  21149. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  21150. 'Input must be a string or array.');
  21151. }
  21152. var blockCounts = length >> 2;
  21153. var tailLength = length - blockCounts * 4;
  21154. // we don't care about endianness here
  21155. var dataUint32 = useUint32ArrayView ?
  21156. new Uint32ArrayView(data, blockCounts) :
  21157. new Uint32Array(data.buffer, 0, blockCounts);
  21158. var k1 = 0;
  21159. var k2 = 0;
  21160. var h1 = this.h1;
  21161. var h2 = this.h2;
  21162. var C1 = 0xcc9e2d51;
  21163. var C2 = 0x1b873593;
  21164. var C1_LOW = C1 & MASK_LOW;
  21165. var C2_LOW = C2 & MASK_LOW;
  21166. for (i = 0; i < blockCounts; i++) {
  21167. if (i & 1) {
  21168. k1 = dataUint32[i];
  21169. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  21170. k1 = k1 << 15 | k1 >>> 17;
  21171. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  21172. h1 ^= k1;
  21173. h1 = h1 << 13 | h1 >>> 19;
  21174. h1 = h1 * 5 + 0xe6546b64;
  21175. } else {
  21176. k2 = dataUint32[i];
  21177. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  21178. k2 = k2 << 15 | k2 >>> 17;
  21179. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  21180. h2 ^= k2;
  21181. h2 = h2 << 13 | h2 >>> 19;
  21182. h2 = h2 * 5 + 0xe6546b64;
  21183. }
  21184. }
  21185. k1 = 0;
  21186. switch (tailLength) {
  21187. case 3:
  21188. k1 ^= data[blockCounts * 4 + 2] << 16;
  21189. /* falls through */
  21190. case 2:
  21191. k1 ^= data[blockCounts * 4 + 1] << 8;
  21192. /* falls through */
  21193. case 1:
  21194. k1 ^= data[blockCounts * 4];
  21195. /* falls through */
  21196. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  21197. k1 = k1 << 15 | k1 >>> 17;
  21198. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  21199. if (blockCounts & 1) {
  21200. h1 ^= k1;
  21201. } else {
  21202. h2 ^= k1;
  21203. }
  21204. }
  21205. this.h1 = h1;
  21206. this.h2 = h2;
  21207. return this;
  21208. },
  21209. hexdigest: function MurmurHash3_64_hexdigest () {
  21210. var h1 = this.h1;
  21211. var h2 = this.h2;
  21212. h1 ^= h2 >>> 1;
  21213. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  21214. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  21215. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  21216. h1 ^= h2 >>> 1;
  21217. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  21218. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  21219. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  21220. h1 ^= h2 >>> 1;
  21221. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  21222. var hex = (arr[i] >>> 0).toString(16);
  21223. while (hex.length < 8) {
  21224. hex = '0' + hex;
  21225. }
  21226. str += hex;
  21227. }
  21228. return str;
  21229. }
  21230. };
  21231. return MurmurHash3_64;
  21232. })();
  21233. exports.MurmurHash3_64 = MurmurHash3_64;
  21234. }));
  21235. (function (root, factory) {
  21236. {
  21237. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  21238. }
  21239. }(this, function (exports, sharedUtil) {
  21240. var isArray = sharedUtil.isArray;
  21241. var Name = (function NameClosure() {
  21242. function Name(name) {
  21243. this.name = name;
  21244. }
  21245. Name.prototype = {};
  21246. var nameCache = {};
  21247. Name.get = function Name_get(name) {
  21248. var nameValue = nameCache[name];
  21249. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  21250. };
  21251. return Name;
  21252. })();
  21253. var Cmd = (function CmdClosure() {
  21254. function Cmd(cmd) {
  21255. this.cmd = cmd;
  21256. }
  21257. Cmd.prototype = {};
  21258. var cmdCache = {};
  21259. Cmd.get = function Cmd_get(cmd) {
  21260. var cmdValue = cmdCache[cmd];
  21261. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  21262. };
  21263. return Cmd;
  21264. })();
  21265. var Dict = (function DictClosure() {
  21266. var nonSerializable = function nonSerializableClosure() {
  21267. return nonSerializable; // creating closure on some variable
  21268. };
  21269. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  21270. 'Background': true,
  21271. 'ExtGState': true,
  21272. 'Halftone': true,
  21273. 'Layout': true,
  21274. 'Mask': true,
  21275. 'Pagination': true,
  21276. 'Printing': true
  21277. };
  21278. function isRecursionAllowedFor(dict) {
  21279. if (!isName(dict.Type)) {
  21280. return true;
  21281. }
  21282. var dictType = dict.Type.name;
  21283. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  21284. }
  21285. // xref is optional
  21286. function Dict(xref) {
  21287. // Map should only be used internally, use functions below to access.
  21288. this.map = Object.create(null);
  21289. this.xref = xref;
  21290. this.objId = null;
  21291. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  21292. }
  21293. Dict.prototype = {
  21294. assignXref: function Dict_assignXref(newXref) {
  21295. this.xref = newXref;
  21296. },
  21297. // automatically dereferences Ref objects
  21298. get: function Dict_get(key1, key2, key3) {
  21299. var value;
  21300. var xref = this.xref;
  21301. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  21302. typeof key2 === 'undefined') {
  21303. return xref ? xref.fetchIfRef(value) : value;
  21304. }
  21305. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  21306. typeof key3 === 'undefined') {
  21307. return xref ? xref.fetchIfRef(value) : value;
  21308. }
  21309. value = this.map[key3] || null;
  21310. return xref ? xref.fetchIfRef(value) : value;
  21311. },
  21312. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21313. getAsync: function Dict_getAsync(key1, key2, key3) {
  21314. var value;
  21315. var xref = this.xref;
  21316. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  21317. typeof key2 === 'undefined') {
  21318. if (xref) {
  21319. return xref.fetchIfRefAsync(value);
  21320. }
  21321. return Promise.resolve(value);
  21322. }
  21323. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  21324. typeof key3 === 'undefined') {
  21325. if (xref) {
  21326. return xref.fetchIfRefAsync(value);
  21327. }
  21328. return Promise.resolve(value);
  21329. }
  21330. value = this.map[key3] || null;
  21331. if (xref) {
  21332. return xref.fetchIfRefAsync(value);
  21333. }
  21334. return Promise.resolve(value);
  21335. },
  21336. // Same as get(), but dereferences all elements if the result is an Array.
  21337. getArray: function Dict_getArray(key1, key2, key3) {
  21338. var value = this.get(key1, key2, key3);
  21339. var xref = this.xref;
  21340. if (!isArray(value) || !xref) {
  21341. return value;
  21342. }
  21343. value = value.slice(); // Ensure that we don't modify the Dict data.
  21344. for (var i = 0, ii = value.length; i < ii; i++) {
  21345. if (!isRef(value[i])) {
  21346. continue;
  21347. }
  21348. value[i] = xref.fetch(value[i]);
  21349. }
  21350. return value;
  21351. },
  21352. // no dereferencing
  21353. getRaw: function Dict_getRaw(key) {
  21354. return this.map[key];
  21355. },
  21356. // creates new map and dereferences all Refs
  21357. getAll: function Dict_getAll() {
  21358. var all = Object.create(null);
  21359. var queue = null;
  21360. var key, obj;
  21361. for (key in this.map) {
  21362. obj = this.get(key);
  21363. if (obj instanceof Dict) {
  21364. if (isRecursionAllowedFor(obj)) {
  21365. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  21366. } else {
  21367. all[key] = this.getRaw(key);
  21368. }
  21369. } else {
  21370. all[key] = obj;
  21371. }
  21372. }
  21373. if (!queue) {
  21374. return all;
  21375. }
  21376. // trying to take cyclic references into the account
  21377. var processed = Object.create(null);
  21378. while (queue.length > 0) {
  21379. var item = queue.shift();
  21380. var itemObj = item.obj;
  21381. var objId = itemObj.objId;
  21382. if (objId && objId in processed) {
  21383. item.target[item.key] = processed[objId];
  21384. continue;
  21385. }
  21386. var dereferenced = Object.create(null);
  21387. for (key in itemObj.map) {
  21388. obj = itemObj.get(key);
  21389. if (obj instanceof Dict) {
  21390. if (isRecursionAllowedFor(obj)) {
  21391. queue.push({target: dereferenced, key: key, obj: obj});
  21392. } else {
  21393. dereferenced[key] = itemObj.getRaw(key);
  21394. }
  21395. } else {
  21396. dereferenced[key] = obj;
  21397. }
  21398. }
  21399. if (objId) {
  21400. processed[objId] = dereferenced;
  21401. }
  21402. item.target[item.key] = dereferenced;
  21403. }
  21404. return all;
  21405. },
  21406. getKeys: function Dict_getKeys() {
  21407. return Object.keys(this.map);
  21408. },
  21409. set: function Dict_set(key, value) {
  21410. this.map[key] = value;
  21411. },
  21412. has: function Dict_has(key) {
  21413. return key in this.map;
  21414. },
  21415. forEach: function Dict_forEach(callback) {
  21416. for (var key in this.map) {
  21417. callback(key, this.get(key));
  21418. }
  21419. }
  21420. };
  21421. Dict.empty = new Dict(null);
  21422. Dict.merge = function Dict_merge(xref, dictArray) {
  21423. var mergedDict = new Dict(xref);
  21424. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21425. var dict = dictArray[i];
  21426. if (!isDict(dict)) {
  21427. continue;
  21428. }
  21429. for (var keyName in dict.map) {
  21430. if (mergedDict.map[keyName]) {
  21431. continue;
  21432. }
  21433. mergedDict.map[keyName] = dict.map[keyName];
  21434. }
  21435. }
  21436. return mergedDict;
  21437. };
  21438. return Dict;
  21439. })();
  21440. var Ref = (function RefClosure() {
  21441. function Ref(num, gen) {
  21442. this.num = num;
  21443. this.gen = gen;
  21444. }
  21445. Ref.prototype = {
  21446. toString: function Ref_toString() {
  21447. // This function is hot, so we make the string as compact as possible.
  21448. // |this.gen| is almost always zero, so we treat that case specially.
  21449. var str = this.num + 'R';
  21450. if (this.gen !== 0) {
  21451. str += this.gen;
  21452. }
  21453. return str;
  21454. }
  21455. };
  21456. return Ref;
  21457. })();
  21458. // The reference is identified by number and generation.
  21459. // This structure stores only one instance of the reference.
  21460. var RefSet = (function RefSetClosure() {
  21461. function RefSet() {
  21462. this.dict = {};
  21463. }
  21464. RefSet.prototype = {
  21465. has: function RefSet_has(ref) {
  21466. return ref.toString() in this.dict;
  21467. },
  21468. put: function RefSet_put(ref) {
  21469. this.dict[ref.toString()] = true;
  21470. },
  21471. remove: function RefSet_remove(ref) {
  21472. delete this.dict[ref.toString()];
  21473. }
  21474. };
  21475. return RefSet;
  21476. })();
  21477. var RefSetCache = (function RefSetCacheClosure() {
  21478. function RefSetCache() {
  21479. this.dict = Object.create(null);
  21480. }
  21481. RefSetCache.prototype = {
  21482. get: function RefSetCache_get(ref) {
  21483. return this.dict[ref.toString()];
  21484. },
  21485. has: function RefSetCache_has(ref) {
  21486. return ref.toString() in this.dict;
  21487. },
  21488. put: function RefSetCache_put(ref, obj) {
  21489. this.dict[ref.toString()] = obj;
  21490. },
  21491. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21492. this.dict[ref.toString()] = this.get(aliasRef);
  21493. },
  21494. forEach: function RefSetCache_forEach(fn, thisArg) {
  21495. for (var i in this.dict) {
  21496. fn.call(thisArg, this.dict[i]);
  21497. }
  21498. },
  21499. clear: function RefSetCache_clear() {
  21500. this.dict = Object.create(null);
  21501. }
  21502. };
  21503. return RefSetCache;
  21504. })();
  21505. function isName(v) {
  21506. return v instanceof Name;
  21507. }
  21508. function isCmd(v, cmd) {
  21509. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21510. }
  21511. function isDict(v, type) {
  21512. if (!(v instanceof Dict)) {
  21513. return false;
  21514. }
  21515. if (!type) {
  21516. return true;
  21517. }
  21518. var dictType = v.get('Type');
  21519. return isName(dictType) && dictType.name === type;
  21520. }
  21521. function isRef(v) {
  21522. return v instanceof Ref;
  21523. }
  21524. function isStream(v) {
  21525. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21526. }
  21527. exports.Cmd = Cmd;
  21528. exports.Dict = Dict;
  21529. exports.Name = Name;
  21530. exports.Ref = Ref;
  21531. exports.RefSet = RefSet;
  21532. exports.RefSetCache = RefSetCache;
  21533. exports.isCmd = isCmd;
  21534. exports.isDict = isDict;
  21535. exports.isName = isName;
  21536. exports.isRef = isRef;
  21537. exports.isStream = isStream;
  21538. }));
  21539. (function (root, factory) {
  21540. {
  21541. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  21542. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  21543. root.pdfjsCoreJpx);
  21544. }
  21545. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  21546. coreJpx) {
  21547. var Util = sharedUtil.Util;
  21548. var error = sharedUtil.error;
  21549. var info = sharedUtil.info;
  21550. var isArray = sharedUtil.isArray;
  21551. var shadow = sharedUtil.shadow;
  21552. var warn = sharedUtil.warn;
  21553. var Dict = corePrimitives.Dict;
  21554. var Jbig2Image = coreJbig2.Jbig2Image;
  21555. var JpegImage = coreJpg.JpegImage;
  21556. var JpxImage = coreJpx.JpxImage;
  21557. var coreParser; // see _setCoreParser below
  21558. var EOF; // = coreParser.EOF;
  21559. var Lexer; // = coreParser.Lexer;
  21560. var coreColorSpace; // see _setCoreColorSpace below
  21561. var ColorSpace; // = coreColorSpace.ColorSpace;
  21562. var Stream = (function StreamClosure() {
  21563. function Stream(arrayBuffer, start, length, dict) {
  21564. this.bytes = (arrayBuffer instanceof Uint8Array ?
  21565. arrayBuffer : new Uint8Array(arrayBuffer));
  21566. this.start = start || 0;
  21567. this.pos = this.start;
  21568. this.end = (start + length) || this.bytes.length;
  21569. this.dict = dict;
  21570. }
  21571. // required methods for a stream. if a particular stream does not
  21572. // implement these, an error should be thrown
  21573. Stream.prototype = {
  21574. get length() {
  21575. return this.end - this.start;
  21576. },
  21577. get isEmpty() {
  21578. return this.length === 0;
  21579. },
  21580. getByte: function Stream_getByte() {
  21581. if (this.pos >= this.end) {
  21582. return -1;
  21583. }
  21584. return this.bytes[this.pos++];
  21585. },
  21586. getUint16: function Stream_getUint16() {
  21587. var b0 = this.getByte();
  21588. var b1 = this.getByte();
  21589. if (b0 === -1 || b1 === -1) {
  21590. return -1;
  21591. }
  21592. return (b0 << 8) + b1;
  21593. },
  21594. getInt32: function Stream_getInt32() {
  21595. var b0 = this.getByte();
  21596. var b1 = this.getByte();
  21597. var b2 = this.getByte();
  21598. var b3 = this.getByte();
  21599. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21600. },
  21601. // returns subarray of original buffer
  21602. // should only be read
  21603. getBytes: function Stream_getBytes(length) {
  21604. var bytes = this.bytes;
  21605. var pos = this.pos;
  21606. var strEnd = this.end;
  21607. if (!length) {
  21608. return bytes.subarray(pos, strEnd);
  21609. }
  21610. var end = pos + length;
  21611. if (end > strEnd) {
  21612. end = strEnd;
  21613. }
  21614. this.pos = end;
  21615. return bytes.subarray(pos, end);
  21616. },
  21617. peekByte: function Stream_peekByte() {
  21618. var peekedByte = this.getByte();
  21619. this.pos--;
  21620. return peekedByte;
  21621. },
  21622. peekBytes: function Stream_peekBytes(length) {
  21623. var bytes = this.getBytes(length);
  21624. this.pos -= bytes.length;
  21625. return bytes;
  21626. },
  21627. skip: function Stream_skip(n) {
  21628. if (!n) {
  21629. n = 1;
  21630. }
  21631. this.pos += n;
  21632. },
  21633. reset: function Stream_reset() {
  21634. this.pos = this.start;
  21635. },
  21636. moveStart: function Stream_moveStart() {
  21637. this.start = this.pos;
  21638. },
  21639. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  21640. return new Stream(this.bytes.buffer, start, length, dict);
  21641. },
  21642. isStream: true
  21643. };
  21644. return Stream;
  21645. })();
  21646. var StringStream = (function StringStreamClosure() {
  21647. function StringStream(str) {
  21648. var length = str.length;
  21649. var bytes = new Uint8Array(length);
  21650. for (var n = 0; n < length; ++n) {
  21651. bytes[n] = str.charCodeAt(n);
  21652. }
  21653. Stream.call(this, bytes);
  21654. }
  21655. StringStream.prototype = Stream.prototype;
  21656. return StringStream;
  21657. })();
  21658. // super class for the decoding streams
  21659. var DecodeStream = (function DecodeStreamClosure() {
  21660. // Lots of DecodeStreams are created whose buffers are never used. For these
  21661. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  21662. // having special cases that would be required if we used |null| for an empty
  21663. // buffer.
  21664. var emptyBuffer = new Uint8Array(0);
  21665. function DecodeStream(maybeMinBufferLength) {
  21666. this.pos = 0;
  21667. this.bufferLength = 0;
  21668. this.eof = false;
  21669. this.buffer = emptyBuffer;
  21670. this.minBufferLength = 512;
  21671. if (maybeMinBufferLength) {
  21672. // Compute the first power of two that is as big as maybeMinBufferLength.
  21673. while (this.minBufferLength < maybeMinBufferLength) {
  21674. this.minBufferLength *= 2;
  21675. }
  21676. }
  21677. }
  21678. DecodeStream.prototype = {
  21679. get isEmpty() {
  21680. while (!this.eof && this.bufferLength === 0) {
  21681. this.readBlock();
  21682. }
  21683. return this.bufferLength === 0;
  21684. },
  21685. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  21686. var buffer = this.buffer;
  21687. if (requested <= buffer.byteLength) {
  21688. return buffer;
  21689. }
  21690. var size = this.minBufferLength;
  21691. while (size < requested) {
  21692. size *= 2;
  21693. }
  21694. var buffer2 = new Uint8Array(size);
  21695. buffer2.set(buffer);
  21696. return (this.buffer = buffer2);
  21697. },
  21698. getByte: function DecodeStream_getByte() {
  21699. var pos = this.pos;
  21700. while (this.bufferLength <= pos) {
  21701. if (this.eof) {
  21702. return -1;
  21703. }
  21704. this.readBlock();
  21705. }
  21706. return this.buffer[this.pos++];
  21707. },
  21708. getUint16: function DecodeStream_getUint16() {
  21709. var b0 = this.getByte();
  21710. var b1 = this.getByte();
  21711. if (b0 === -1 || b1 === -1) {
  21712. return -1;
  21713. }
  21714. return (b0 << 8) + b1;
  21715. },
  21716. getInt32: function DecodeStream_getInt32() {
  21717. var b0 = this.getByte();
  21718. var b1 = this.getByte();
  21719. var b2 = this.getByte();
  21720. var b3 = this.getByte();
  21721. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21722. },
  21723. getBytes: function DecodeStream_getBytes(length) {
  21724. var end, pos = this.pos;
  21725. if (length) {
  21726. this.ensureBuffer(pos + length);
  21727. end = pos + length;
  21728. while (!this.eof && this.bufferLength < end) {
  21729. this.readBlock();
  21730. }
  21731. var bufEnd = this.bufferLength;
  21732. if (end > bufEnd) {
  21733. end = bufEnd;
  21734. }
  21735. } else {
  21736. while (!this.eof) {
  21737. this.readBlock();
  21738. }
  21739. end = this.bufferLength;
  21740. }
  21741. this.pos = end;
  21742. return this.buffer.subarray(pos, end);
  21743. },
  21744. peekByte: function DecodeStream_peekByte() {
  21745. var peekedByte = this.getByte();
  21746. this.pos--;
  21747. return peekedByte;
  21748. },
  21749. peekBytes: function DecodeStream_peekBytes(length) {
  21750. var bytes = this.getBytes(length);
  21751. this.pos -= bytes.length;
  21752. return bytes;
  21753. },
  21754. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  21755. var end = start + length;
  21756. while (this.bufferLength <= end && !this.eof) {
  21757. this.readBlock();
  21758. }
  21759. return new Stream(this.buffer, start, length, dict);
  21760. },
  21761. skip: function DecodeStream_skip(n) {
  21762. if (!n) {
  21763. n = 1;
  21764. }
  21765. this.pos += n;
  21766. },
  21767. reset: function DecodeStream_reset() {
  21768. this.pos = 0;
  21769. },
  21770. getBaseStreams: function DecodeStream_getBaseStreams() {
  21771. if (this.str && this.str.getBaseStreams) {
  21772. return this.str.getBaseStreams();
  21773. }
  21774. return [];
  21775. }
  21776. };
  21777. return DecodeStream;
  21778. })();
  21779. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  21780. function StreamsSequenceStream(streams) {
  21781. this.streams = streams;
  21782. DecodeStream.call(this, /* maybeLength = */ null);
  21783. }
  21784. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  21785. StreamsSequenceStream.prototype.readBlock =
  21786. function streamSequenceStreamReadBlock() {
  21787. var streams = this.streams;
  21788. if (streams.length === 0) {
  21789. this.eof = true;
  21790. return;
  21791. }
  21792. var stream = streams.shift();
  21793. var chunk = stream.getBytes();
  21794. var bufferLength = this.bufferLength;
  21795. var newLength = bufferLength + chunk.length;
  21796. var buffer = this.ensureBuffer(newLength);
  21797. buffer.set(chunk, bufferLength);
  21798. this.bufferLength = newLength;
  21799. };
  21800. StreamsSequenceStream.prototype.getBaseStreams =
  21801. function StreamsSequenceStream_getBaseStreams() {
  21802. var baseStreams = [];
  21803. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  21804. var stream = this.streams[i];
  21805. if (stream.getBaseStreams) {
  21806. Util.appendToArray(baseStreams, stream.getBaseStreams());
  21807. }
  21808. }
  21809. return baseStreams;
  21810. };
  21811. return StreamsSequenceStream;
  21812. })();
  21813. var FlateStream = (function FlateStreamClosure() {
  21814. var codeLenCodeMap = new Int32Array([
  21815. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  21816. ]);
  21817. var lengthDecode = new Int32Array([
  21818. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  21819. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  21820. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  21821. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  21822. ]);
  21823. var distDecode = new Int32Array([
  21824. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  21825. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  21826. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  21827. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  21828. ]);
  21829. var fixedLitCodeTab = [new Int32Array([
  21830. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  21831. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  21832. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  21833. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  21834. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  21835. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  21836. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  21837. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  21838. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  21839. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  21840. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  21841. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  21842. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  21843. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  21844. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  21845. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  21846. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  21847. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  21848. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  21849. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  21850. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  21851. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  21852. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  21853. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  21854. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  21855. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  21856. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  21857. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  21858. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  21859. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  21860. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  21861. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  21862. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  21863. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  21864. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  21865. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  21866. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  21867. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  21868. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  21869. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  21870. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  21871. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  21872. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  21873. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  21874. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  21875. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  21876. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  21877. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  21878. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  21879. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  21880. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  21881. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  21882. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  21883. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  21884. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  21885. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  21886. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  21887. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  21888. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  21889. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  21890. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  21891. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  21892. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  21893. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  21894. ]), 9];
  21895. var fixedDistCodeTab = [new Int32Array([
  21896. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  21897. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  21898. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  21899. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  21900. ]), 5];
  21901. function FlateStream(str, maybeLength) {
  21902. this.str = str;
  21903. this.dict = str.dict;
  21904. var cmf = str.getByte();
  21905. var flg = str.getByte();
  21906. if (cmf === -1 || flg === -1) {
  21907. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  21908. }
  21909. if ((cmf & 0x0f) !== 0x08) {
  21910. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  21911. }
  21912. if ((((cmf << 8) + flg) % 31) !== 0) {
  21913. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  21914. }
  21915. if (flg & 0x20) {
  21916. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  21917. }
  21918. this.codeSize = 0;
  21919. this.codeBuf = 0;
  21920. DecodeStream.call(this, maybeLength);
  21921. }
  21922. FlateStream.prototype = Object.create(DecodeStream.prototype);
  21923. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  21924. var str = this.str;
  21925. var codeSize = this.codeSize;
  21926. var codeBuf = this.codeBuf;
  21927. var b;
  21928. while (codeSize < bits) {
  21929. if ((b = str.getByte()) === -1) {
  21930. error('Bad encoding in flate stream');
  21931. }
  21932. codeBuf |= b << codeSize;
  21933. codeSize += 8;
  21934. }
  21935. b = codeBuf & ((1 << bits) - 1);
  21936. this.codeBuf = codeBuf >> bits;
  21937. this.codeSize = codeSize -= bits;
  21938. return b;
  21939. };
  21940. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  21941. var str = this.str;
  21942. var codes = table[0];
  21943. var maxLen = table[1];
  21944. var codeSize = this.codeSize;
  21945. var codeBuf = this.codeBuf;
  21946. var b;
  21947. while (codeSize < maxLen) {
  21948. if ((b = str.getByte()) === -1) {
  21949. // premature end of stream. code might however still be valid.
  21950. // codeSize < codeLen check below guards against incomplete codeVal.
  21951. break;
  21952. }
  21953. codeBuf |= (b << codeSize);
  21954. codeSize += 8;
  21955. }
  21956. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  21957. var codeLen = code >> 16;
  21958. var codeVal = code & 0xffff;
  21959. if (codeLen < 1 || codeSize < codeLen) {
  21960. error('Bad encoding in flate stream');
  21961. }
  21962. this.codeBuf = (codeBuf >> codeLen);
  21963. this.codeSize = (codeSize - codeLen);
  21964. return codeVal;
  21965. };
  21966. FlateStream.prototype.generateHuffmanTable =
  21967. function flateStreamGenerateHuffmanTable(lengths) {
  21968. var n = lengths.length;
  21969. // find max code length
  21970. var maxLen = 0;
  21971. var i;
  21972. for (i = 0; i < n; ++i) {
  21973. if (lengths[i] > maxLen) {
  21974. maxLen = lengths[i];
  21975. }
  21976. }
  21977. // build the table
  21978. var size = 1 << maxLen;
  21979. var codes = new Int32Array(size);
  21980. for (var len = 1, code = 0, skip = 2;
  21981. len <= maxLen;
  21982. ++len, code <<= 1, skip <<= 1) {
  21983. for (var val = 0; val < n; ++val) {
  21984. if (lengths[val] === len) {
  21985. // bit-reverse the code
  21986. var code2 = 0;
  21987. var t = code;
  21988. for (i = 0; i < len; ++i) {
  21989. code2 = (code2 << 1) | (t & 1);
  21990. t >>= 1;
  21991. }
  21992. // fill the table entries
  21993. for (i = code2; i < size; i += skip) {
  21994. codes[i] = (len << 16) | val;
  21995. }
  21996. ++code;
  21997. }
  21998. }
  21999. }
  22000. return [codes, maxLen];
  22001. };
  22002. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  22003. var buffer, len;
  22004. var str = this.str;
  22005. // read block header
  22006. var hdr = this.getBits(3);
  22007. if (hdr & 1) {
  22008. this.eof = true;
  22009. }
  22010. hdr >>= 1;
  22011. if (hdr === 0) { // uncompressed block
  22012. var b;
  22013. if ((b = str.getByte()) === -1) {
  22014. error('Bad block header in flate stream');
  22015. }
  22016. var blockLen = b;
  22017. if ((b = str.getByte()) === -1) {
  22018. error('Bad block header in flate stream');
  22019. }
  22020. blockLen |= (b << 8);
  22021. if ((b = str.getByte()) === -1) {
  22022. error('Bad block header in flate stream');
  22023. }
  22024. var check = b;
  22025. if ((b = str.getByte()) === -1) {
  22026. error('Bad block header in flate stream');
  22027. }
  22028. check |= (b << 8);
  22029. if (check !== (~blockLen & 0xffff) &&
  22030. (blockLen !== 0 || check !== 0)) {
  22031. // Ignoring error for bad "empty" block (see issue 1277)
  22032. error('Bad uncompressed block length in flate stream');
  22033. }
  22034. this.codeBuf = 0;
  22035. this.codeSize = 0;
  22036. var bufferLength = this.bufferLength;
  22037. buffer = this.ensureBuffer(bufferLength + blockLen);
  22038. var end = bufferLength + blockLen;
  22039. this.bufferLength = end;
  22040. if (blockLen === 0) {
  22041. if (str.peekByte() === -1) {
  22042. this.eof = true;
  22043. }
  22044. } else {
  22045. for (var n = bufferLength; n < end; ++n) {
  22046. if ((b = str.getByte()) === -1) {
  22047. this.eof = true;
  22048. break;
  22049. }
  22050. buffer[n] = b;
  22051. }
  22052. }
  22053. return;
  22054. }
  22055. var litCodeTable;
  22056. var distCodeTable;
  22057. if (hdr === 1) { // compressed block, fixed codes
  22058. litCodeTable = fixedLitCodeTab;
  22059. distCodeTable = fixedDistCodeTab;
  22060. } else if (hdr === 2) { // compressed block, dynamic codes
  22061. var numLitCodes = this.getBits(5) + 257;
  22062. var numDistCodes = this.getBits(5) + 1;
  22063. var numCodeLenCodes = this.getBits(4) + 4;
  22064. // build the code lengths code table
  22065. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  22066. var i;
  22067. for (i = 0; i < numCodeLenCodes; ++i) {
  22068. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  22069. }
  22070. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  22071. // build the literal and distance code tables
  22072. len = 0;
  22073. i = 0;
  22074. var codes = numLitCodes + numDistCodes;
  22075. var codeLengths = new Uint8Array(codes);
  22076. var bitsLength, bitsOffset, what;
  22077. while (i < codes) {
  22078. var code = this.getCode(codeLenCodeTab);
  22079. if (code === 16) {
  22080. bitsLength = 2; bitsOffset = 3; what = len;
  22081. } else if (code === 17) {
  22082. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  22083. } else if (code === 18) {
  22084. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  22085. } else {
  22086. codeLengths[i++] = len = code;
  22087. continue;
  22088. }
  22089. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  22090. while (repeatLength-- > 0) {
  22091. codeLengths[i++] = what;
  22092. }
  22093. }
  22094. litCodeTable =
  22095. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  22096. distCodeTable =
  22097. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  22098. } else {
  22099. error('Unknown block type in flate stream');
  22100. }
  22101. buffer = this.buffer;
  22102. var limit = buffer ? buffer.length : 0;
  22103. var pos = this.bufferLength;
  22104. while (true) {
  22105. var code1 = this.getCode(litCodeTable);
  22106. if (code1 < 256) {
  22107. if (pos + 1 >= limit) {
  22108. buffer = this.ensureBuffer(pos + 1);
  22109. limit = buffer.length;
  22110. }
  22111. buffer[pos++] = code1;
  22112. continue;
  22113. }
  22114. if (code1 === 256) {
  22115. this.bufferLength = pos;
  22116. return;
  22117. }
  22118. code1 -= 257;
  22119. code1 = lengthDecode[code1];
  22120. var code2 = code1 >> 16;
  22121. if (code2 > 0) {
  22122. code2 = this.getBits(code2);
  22123. }
  22124. len = (code1 & 0xffff) + code2;
  22125. code1 = this.getCode(distCodeTable);
  22126. code1 = distDecode[code1];
  22127. code2 = code1 >> 16;
  22128. if (code2 > 0) {
  22129. code2 = this.getBits(code2);
  22130. }
  22131. var dist = (code1 & 0xffff) + code2;
  22132. if (pos + len >= limit) {
  22133. buffer = this.ensureBuffer(pos + len);
  22134. limit = buffer.length;
  22135. }
  22136. for (var k = 0; k < len; ++k, ++pos) {
  22137. buffer[pos] = buffer[pos - dist];
  22138. }
  22139. }
  22140. };
  22141. return FlateStream;
  22142. })();
  22143. var PredictorStream = (function PredictorStreamClosure() {
  22144. function PredictorStream(str, maybeLength, params) {
  22145. var predictor = this.predictor = params.get('Predictor') || 1;
  22146. if (predictor <= 1) {
  22147. return str; // no prediction
  22148. }
  22149. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  22150. error('Unsupported predictor: ' + predictor);
  22151. }
  22152. if (predictor === 2) {
  22153. this.readBlock = this.readBlockTiff;
  22154. } else {
  22155. this.readBlock = this.readBlockPng;
  22156. }
  22157. this.str = str;
  22158. this.dict = str.dict;
  22159. var colors = this.colors = params.get('Colors') || 1;
  22160. var bits = this.bits = params.get('BitsPerComponent') || 8;
  22161. var columns = this.columns = params.get('Columns') || 1;
  22162. this.pixBytes = (colors * bits + 7) >> 3;
  22163. this.rowBytes = (columns * colors * bits + 7) >> 3;
  22164. DecodeStream.call(this, maybeLength);
  22165. return this;
  22166. }
  22167. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  22168. PredictorStream.prototype.readBlockTiff =
  22169. function predictorStreamReadBlockTiff() {
  22170. var rowBytes = this.rowBytes;
  22171. var bufferLength = this.bufferLength;
  22172. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  22173. var bits = this.bits;
  22174. var colors = this.colors;
  22175. var rawBytes = this.str.getBytes(rowBytes);
  22176. this.eof = !rawBytes.length;
  22177. if (this.eof) {
  22178. return;
  22179. }
  22180. var inbuf = 0, outbuf = 0;
  22181. var inbits = 0, outbits = 0;
  22182. var pos = bufferLength;
  22183. var i;
  22184. if (bits === 1) {
  22185. for (i = 0; i < rowBytes; ++i) {
  22186. var c = rawBytes[i];
  22187. inbuf = (inbuf << 8) | c;
  22188. // bitwise addition is exclusive or
  22189. // first shift inbuf and then add
  22190. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  22191. // truncate inbuf (assumes colors < 16)
  22192. inbuf &= 0xFFFF;
  22193. }
  22194. } else if (bits === 8) {
  22195. for (i = 0; i < colors; ++i) {
  22196. buffer[pos++] = rawBytes[i];
  22197. }
  22198. for (; i < rowBytes; ++i) {
  22199. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  22200. pos++;
  22201. }
  22202. } else {
  22203. var compArray = new Uint8Array(colors + 1);
  22204. var bitMask = (1 << bits) - 1;
  22205. var j = 0, k = bufferLength;
  22206. var columns = this.columns;
  22207. for (i = 0; i < columns; ++i) {
  22208. for (var kk = 0; kk < colors; ++kk) {
  22209. if (inbits < bits) {
  22210. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  22211. inbits += 8;
  22212. }
  22213. compArray[kk] = (compArray[kk] +
  22214. (inbuf >> (inbits - bits))) & bitMask;
  22215. inbits -= bits;
  22216. outbuf = (outbuf << bits) | compArray[kk];
  22217. outbits += bits;
  22218. if (outbits >= 8) {
  22219. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  22220. outbits -= 8;
  22221. }
  22222. }
  22223. }
  22224. if (outbits > 0) {
  22225. buffer[k++] = (outbuf << (8 - outbits)) +
  22226. (inbuf & ((1 << (8 - outbits)) - 1));
  22227. }
  22228. }
  22229. this.bufferLength += rowBytes;
  22230. };
  22231. PredictorStream.prototype.readBlockPng =
  22232. function predictorStreamReadBlockPng() {
  22233. var rowBytes = this.rowBytes;
  22234. var pixBytes = this.pixBytes;
  22235. var predictor = this.str.getByte();
  22236. var rawBytes = this.str.getBytes(rowBytes);
  22237. this.eof = !rawBytes.length;
  22238. if (this.eof) {
  22239. return;
  22240. }
  22241. var bufferLength = this.bufferLength;
  22242. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  22243. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  22244. if (prevRow.length === 0) {
  22245. prevRow = new Uint8Array(rowBytes);
  22246. }
  22247. var i, j = bufferLength, up, c;
  22248. switch (predictor) {
  22249. case 0:
  22250. for (i = 0; i < rowBytes; ++i) {
  22251. buffer[j++] = rawBytes[i];
  22252. }
  22253. break;
  22254. case 1:
  22255. for (i = 0; i < pixBytes; ++i) {
  22256. buffer[j++] = rawBytes[i];
  22257. }
  22258. for (; i < rowBytes; ++i) {
  22259. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  22260. j++;
  22261. }
  22262. break;
  22263. case 2:
  22264. for (i = 0; i < rowBytes; ++i) {
  22265. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  22266. }
  22267. break;
  22268. case 3:
  22269. for (i = 0; i < pixBytes; ++i) {
  22270. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  22271. }
  22272. for (; i < rowBytes; ++i) {
  22273. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  22274. rawBytes[i]) & 0xFF;
  22275. j++;
  22276. }
  22277. break;
  22278. case 4:
  22279. // we need to save the up left pixels values. the simplest way
  22280. // is to create a new buffer
  22281. for (i = 0; i < pixBytes; ++i) {
  22282. up = prevRow[i];
  22283. c = rawBytes[i];
  22284. buffer[j++] = up + c;
  22285. }
  22286. for (; i < rowBytes; ++i) {
  22287. up = prevRow[i];
  22288. var upLeft = prevRow[i - pixBytes];
  22289. var left = buffer[j - pixBytes];
  22290. var p = left + up - upLeft;
  22291. var pa = p - left;
  22292. if (pa < 0) {
  22293. pa = -pa;
  22294. }
  22295. var pb = p - up;
  22296. if (pb < 0) {
  22297. pb = -pb;
  22298. }
  22299. var pc = p - upLeft;
  22300. if (pc < 0) {
  22301. pc = -pc;
  22302. }
  22303. c = rawBytes[i];
  22304. if (pa <= pb && pa <= pc) {
  22305. buffer[j++] = left + c;
  22306. } else if (pb <= pc) {
  22307. buffer[j++] = up + c;
  22308. } else {
  22309. buffer[j++] = upLeft + c;
  22310. }
  22311. }
  22312. break;
  22313. default:
  22314. error('Unsupported predictor: ' + predictor);
  22315. }
  22316. this.bufferLength += rowBytes;
  22317. };
  22318. return PredictorStream;
  22319. })();
  22320. /**
  22321. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  22322. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  22323. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  22324. * a library to decode these images and the stream behaves like all the other
  22325. * DecodeStreams.
  22326. */
  22327. var JpegStream = (function JpegStreamClosure() {
  22328. function JpegStream(stream, maybeLength, dict, xref) {
  22329. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  22330. // Note: this seems to mainly affect inline images.
  22331. var ch;
  22332. while ((ch = stream.getByte()) !== -1) {
  22333. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  22334. stream.skip(-1); // Reset the stream position to the SOI.
  22335. break;
  22336. }
  22337. }
  22338. this.stream = stream;
  22339. this.maybeLength = maybeLength;
  22340. this.dict = dict;
  22341. DecodeStream.call(this, maybeLength);
  22342. }
  22343. JpegStream.prototype = Object.create(DecodeStream.prototype);
  22344. Object.defineProperty(JpegStream.prototype, 'bytes', {
  22345. get: function JpegStream_bytes() {
  22346. // If this.maybeLength is null, we'll get the entire stream.
  22347. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22348. },
  22349. configurable: true
  22350. });
  22351. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  22352. if (this.bufferLength) {
  22353. return;
  22354. }
  22355. try {
  22356. var jpegImage = new JpegImage();
  22357. // checking if values needs to be transformed before conversion
  22358. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  22359. var decodeArr = this.dict.get('Decode');
  22360. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  22361. var decodeArrLength = decodeArr.length;
  22362. var transform = new Int32Array(decodeArrLength);
  22363. var transformNeeded = false;
  22364. var maxValue = (1 << bitsPerComponent) - 1;
  22365. for (var i = 0; i < decodeArrLength; i += 2) {
  22366. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  22367. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  22368. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  22369. transformNeeded = true;
  22370. }
  22371. }
  22372. if (transformNeeded) {
  22373. jpegImage.decodeTransform = transform;
  22374. }
  22375. }
  22376. jpegImage.parse(this.bytes);
  22377. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  22378. this.forceRGB);
  22379. this.buffer = data;
  22380. this.bufferLength = data.length;
  22381. this.eof = true;
  22382. } catch (e) {
  22383. error('JPEG error: ' + e);
  22384. }
  22385. };
  22386. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  22387. this.ensureBuffer();
  22388. return this.buffer;
  22389. };
  22390. JpegStream.prototype.getIR = function JpegStream_getIR() {
  22391. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  22392. };
  22393. /**
  22394. * Checks if the image can be decoded and displayed by the browser without any
  22395. * further processing such as color space conversions.
  22396. */
  22397. JpegStream.prototype.isNativelySupported =
  22398. function JpegStream_isNativelySupported(xref, res) {
  22399. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  22400. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  22401. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  22402. };
  22403. /**
  22404. * Checks if the image can be decoded by the browser.
  22405. */
  22406. JpegStream.prototype.isNativelyDecodable =
  22407. function JpegStream_isNativelyDecodable(xref, res) {
  22408. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  22409. return (cs.numComps === 1 || cs.numComps === 3) &&
  22410. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  22411. };
  22412. return JpegStream;
  22413. })();
  22414. /**
  22415. * For JPEG 2000's we use a library to decode these images and
  22416. * the stream behaves like all the other DecodeStreams.
  22417. */
  22418. var JpxStream = (function JpxStreamClosure() {
  22419. function JpxStream(stream, maybeLength, dict) {
  22420. this.stream = stream;
  22421. this.maybeLength = maybeLength;
  22422. this.dict = dict;
  22423. DecodeStream.call(this, maybeLength);
  22424. }
  22425. JpxStream.prototype = Object.create(DecodeStream.prototype);
  22426. Object.defineProperty(JpxStream.prototype, 'bytes', {
  22427. get: function JpxStream_bytes() {
  22428. // If this.maybeLength is null, we'll get the entire stream.
  22429. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22430. },
  22431. configurable: true
  22432. });
  22433. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  22434. if (this.bufferLength) {
  22435. return;
  22436. }
  22437. var jpxImage = new JpxImage();
  22438. jpxImage.parse(this.bytes);
  22439. var width = jpxImage.width;
  22440. var height = jpxImage.height;
  22441. var componentsCount = jpxImage.componentsCount;
  22442. var tileCount = jpxImage.tiles.length;
  22443. if (tileCount === 1) {
  22444. this.buffer = jpxImage.tiles[0].items;
  22445. } else {
  22446. var data = new Uint8Array(width * height * componentsCount);
  22447. for (var k = 0; k < tileCount; k++) {
  22448. var tileComponents = jpxImage.tiles[k];
  22449. var tileWidth = tileComponents.width;
  22450. var tileHeight = tileComponents.height;
  22451. var tileLeft = tileComponents.left;
  22452. var tileTop = tileComponents.top;
  22453. var src = tileComponents.items;
  22454. var srcPosition = 0;
  22455. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  22456. var imgRowSize = width * componentsCount;
  22457. var tileRowSize = tileWidth * componentsCount;
  22458. for (var j = 0; j < tileHeight; j++) {
  22459. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  22460. data.set(rowBytes, dataPosition);
  22461. srcPosition += tileRowSize;
  22462. dataPosition += imgRowSize;
  22463. }
  22464. }
  22465. this.buffer = data;
  22466. }
  22467. this.bufferLength = this.buffer.length;
  22468. this.eof = true;
  22469. };
  22470. return JpxStream;
  22471. })();
  22472. /**
  22473. * For JBIG2's we use a library to decode these images and
  22474. * the stream behaves like all the other DecodeStreams.
  22475. */
  22476. var Jbig2Stream = (function Jbig2StreamClosure() {
  22477. function Jbig2Stream(stream, maybeLength, dict) {
  22478. this.stream = stream;
  22479. this.maybeLength = maybeLength;
  22480. this.dict = dict;
  22481. DecodeStream.call(this, maybeLength);
  22482. }
  22483. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  22484. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  22485. get: function Jbig2Stream_bytes() {
  22486. // If this.maybeLength is null, we'll get the entire stream.
  22487. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22488. },
  22489. configurable: true
  22490. });
  22491. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  22492. if (this.bufferLength) {
  22493. return;
  22494. }
  22495. var jbig2Image = new Jbig2Image();
  22496. var chunks = [], xref = this.dict.xref;
  22497. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  22498. // According to the PDF specification, DecodeParms can be either
  22499. // a dictionary, or an array whose elements are dictionaries.
  22500. if (isArray(decodeParams)) {
  22501. if (decodeParams.length > 1) {
  22502. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  22503. 'not supported.');
  22504. }
  22505. decodeParams = xref.fetchIfRef(decodeParams[0]);
  22506. }
  22507. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  22508. var globalsStream = decodeParams.get('JBIG2Globals');
  22509. var globals = globalsStream.getBytes();
  22510. chunks.push({data: globals, start: 0, end: globals.length});
  22511. }
  22512. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  22513. var data = jbig2Image.parseChunks(chunks);
  22514. var dataLength = data.length;
  22515. // JBIG2 had black as 1 and white as 0, inverting the colors
  22516. for (var i = 0; i < dataLength; i++) {
  22517. data[i] ^= 0xFF;
  22518. }
  22519. this.buffer = data;
  22520. this.bufferLength = dataLength;
  22521. this.eof = true;
  22522. };
  22523. return Jbig2Stream;
  22524. })();
  22525. var DecryptStream = (function DecryptStreamClosure() {
  22526. function DecryptStream(str, maybeLength, decrypt) {
  22527. this.str = str;
  22528. this.dict = str.dict;
  22529. this.decrypt = decrypt;
  22530. this.nextChunk = null;
  22531. this.initialized = false;
  22532. DecodeStream.call(this, maybeLength);
  22533. }
  22534. var chunkSize = 512;
  22535. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  22536. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  22537. var chunk;
  22538. if (this.initialized) {
  22539. chunk = this.nextChunk;
  22540. } else {
  22541. chunk = this.str.getBytes(chunkSize);
  22542. this.initialized = true;
  22543. }
  22544. if (!chunk || chunk.length === 0) {
  22545. this.eof = true;
  22546. return;
  22547. }
  22548. this.nextChunk = this.str.getBytes(chunkSize);
  22549. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  22550. var decrypt = this.decrypt;
  22551. chunk = decrypt(chunk, !hasMoreData);
  22552. var bufferLength = this.bufferLength;
  22553. var i, n = chunk.length;
  22554. var buffer = this.ensureBuffer(bufferLength + n);
  22555. for (i = 0; i < n; i++) {
  22556. buffer[bufferLength++] = chunk[i];
  22557. }
  22558. this.bufferLength = bufferLength;
  22559. };
  22560. return DecryptStream;
  22561. })();
  22562. var Ascii85Stream = (function Ascii85StreamClosure() {
  22563. function Ascii85Stream(str, maybeLength) {
  22564. this.str = str;
  22565. this.dict = str.dict;
  22566. this.input = new Uint8Array(5);
  22567. // Most streams increase in size when decoded, but Ascii85 streams
  22568. // typically shrink by ~20%.
  22569. if (maybeLength) {
  22570. maybeLength = 0.8 * maybeLength;
  22571. }
  22572. DecodeStream.call(this, maybeLength);
  22573. }
  22574. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  22575. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  22576. var TILDA_CHAR = 0x7E; // '~'
  22577. var Z_LOWER_CHAR = 0x7A; // 'z'
  22578. var EOF = -1;
  22579. var str = this.str;
  22580. var c = str.getByte();
  22581. while (Lexer.isSpace(c)) {
  22582. c = str.getByte();
  22583. }
  22584. if (c === EOF || c === TILDA_CHAR) {
  22585. this.eof = true;
  22586. return;
  22587. }
  22588. var bufferLength = this.bufferLength, buffer;
  22589. var i;
  22590. // special code for z
  22591. if (c === Z_LOWER_CHAR) {
  22592. buffer = this.ensureBuffer(bufferLength + 4);
  22593. for (i = 0; i < 4; ++i) {
  22594. buffer[bufferLength + i] = 0;
  22595. }
  22596. this.bufferLength += 4;
  22597. } else {
  22598. var input = this.input;
  22599. input[0] = c;
  22600. for (i = 1; i < 5; ++i) {
  22601. c = str.getByte();
  22602. while (Lexer.isSpace(c)) {
  22603. c = str.getByte();
  22604. }
  22605. input[i] = c;
  22606. if (c === EOF || c === TILDA_CHAR) {
  22607. break;
  22608. }
  22609. }
  22610. buffer = this.ensureBuffer(bufferLength + i - 1);
  22611. this.bufferLength += i - 1;
  22612. // partial ending;
  22613. if (i < 5) {
  22614. for (; i < 5; ++i) {
  22615. input[i] = 0x21 + 84;
  22616. }
  22617. this.eof = true;
  22618. }
  22619. var t = 0;
  22620. for (i = 0; i < 5; ++i) {
  22621. t = t * 85 + (input[i] - 0x21);
  22622. }
  22623. for (i = 3; i >= 0; --i) {
  22624. buffer[bufferLength + i] = t & 0xFF;
  22625. t >>= 8;
  22626. }
  22627. }
  22628. };
  22629. return Ascii85Stream;
  22630. })();
  22631. var AsciiHexStream = (function AsciiHexStreamClosure() {
  22632. function AsciiHexStream(str, maybeLength) {
  22633. this.str = str;
  22634. this.dict = str.dict;
  22635. this.firstDigit = -1;
  22636. // Most streams increase in size when decoded, but AsciiHex streams shrink
  22637. // by 50%.
  22638. if (maybeLength) {
  22639. maybeLength = 0.5 * maybeLength;
  22640. }
  22641. DecodeStream.call(this, maybeLength);
  22642. }
  22643. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  22644. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  22645. var UPSTREAM_BLOCK_SIZE = 8000;
  22646. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  22647. if (!bytes.length) {
  22648. this.eof = true;
  22649. return;
  22650. }
  22651. var maxDecodeLength = (bytes.length + 1) >> 1;
  22652. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  22653. var bufferLength = this.bufferLength;
  22654. var firstDigit = this.firstDigit;
  22655. for (var i = 0, ii = bytes.length; i < ii; i++) {
  22656. var ch = bytes[i], digit;
  22657. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  22658. digit = ch & 0x0F;
  22659. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  22660. // 'A'-'Z', 'a'-'z'
  22661. digit = (ch & 0x0F) + 9;
  22662. } else if (ch === 0x3E) { // '>'
  22663. this.eof = true;
  22664. break;
  22665. } else { // probably whitespace
  22666. continue; // ignoring
  22667. }
  22668. if (firstDigit < 0) {
  22669. firstDigit = digit;
  22670. } else {
  22671. buffer[bufferLength++] = (firstDigit << 4) | digit;
  22672. firstDigit = -1;
  22673. }
  22674. }
  22675. if (firstDigit >= 0 && this.eof) {
  22676. // incomplete byte
  22677. buffer[bufferLength++] = (firstDigit << 4);
  22678. firstDigit = -1;
  22679. }
  22680. this.firstDigit = firstDigit;
  22681. this.bufferLength = bufferLength;
  22682. };
  22683. return AsciiHexStream;
  22684. })();
  22685. var RunLengthStream = (function RunLengthStreamClosure() {
  22686. function RunLengthStream(str, maybeLength) {
  22687. this.str = str;
  22688. this.dict = str.dict;
  22689. DecodeStream.call(this, maybeLength);
  22690. }
  22691. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  22692. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  22693. // The repeatHeader has following format. The first byte defines type of run
  22694. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  22695. // (in addition to the second byte from the header), n = 129 through 255 -
  22696. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  22697. var repeatHeader = this.str.getBytes(2);
  22698. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  22699. this.eof = true;
  22700. return;
  22701. }
  22702. var buffer;
  22703. var bufferLength = this.bufferLength;
  22704. var n = repeatHeader[0];
  22705. if (n < 128) {
  22706. // copy n bytes
  22707. buffer = this.ensureBuffer(bufferLength + n + 1);
  22708. buffer[bufferLength++] = repeatHeader[1];
  22709. if (n > 0) {
  22710. var source = this.str.getBytes(n);
  22711. buffer.set(source, bufferLength);
  22712. bufferLength += n;
  22713. }
  22714. } else {
  22715. n = 257 - n;
  22716. var b = repeatHeader[1];
  22717. buffer = this.ensureBuffer(bufferLength + n + 1);
  22718. for (var i = 0; i < n; i++) {
  22719. buffer[bufferLength++] = b;
  22720. }
  22721. }
  22722. this.bufferLength = bufferLength;
  22723. };
  22724. return RunLengthStream;
  22725. })();
  22726. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  22727. var ccittEOL = -2;
  22728. var twoDimPass = 0;
  22729. var twoDimHoriz = 1;
  22730. var twoDimVert0 = 2;
  22731. var twoDimVertR1 = 3;
  22732. var twoDimVertL1 = 4;
  22733. var twoDimVertR2 = 5;
  22734. var twoDimVertL2 = 6;
  22735. var twoDimVertR3 = 7;
  22736. var twoDimVertL3 = 8;
  22737. var twoDimTable = [
  22738. [-1, -1], [-1, -1], // 000000x
  22739. [7, twoDimVertL3], // 0000010
  22740. [7, twoDimVertR3], // 0000011
  22741. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  22742. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  22743. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  22744. [4, twoDimPass], [4, twoDimPass],
  22745. [4, twoDimPass], [4, twoDimPass],
  22746. [4, twoDimPass], [4, twoDimPass],
  22747. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  22748. [3, twoDimHoriz], [3, twoDimHoriz],
  22749. [3, twoDimHoriz], [3, twoDimHoriz],
  22750. [3, twoDimHoriz], [3, twoDimHoriz],
  22751. [3, twoDimHoriz], [3, twoDimHoriz],
  22752. [3, twoDimHoriz], [3, twoDimHoriz],
  22753. [3, twoDimHoriz], [3, twoDimHoriz],
  22754. [3, twoDimHoriz], [3, twoDimHoriz],
  22755. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  22756. [3, twoDimVertL1], [3, twoDimVertL1],
  22757. [3, twoDimVertL1], [3, twoDimVertL1],
  22758. [3, twoDimVertL1], [3, twoDimVertL1],
  22759. [3, twoDimVertL1], [3, twoDimVertL1],
  22760. [3, twoDimVertL1], [3, twoDimVertL1],
  22761. [3, twoDimVertL1], [3, twoDimVertL1],
  22762. [3, twoDimVertL1], [3, twoDimVertL1],
  22763. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  22764. [3, twoDimVertR1], [3, twoDimVertR1],
  22765. [3, twoDimVertR1], [3, twoDimVertR1],
  22766. [3, twoDimVertR1], [3, twoDimVertR1],
  22767. [3, twoDimVertR1], [3, twoDimVertR1],
  22768. [3, twoDimVertR1], [3, twoDimVertR1],
  22769. [3, twoDimVertR1], [3, twoDimVertR1],
  22770. [3, twoDimVertR1], [3, twoDimVertR1],
  22771. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  22772. [1, twoDimVert0], [1, twoDimVert0],
  22773. [1, twoDimVert0], [1, twoDimVert0],
  22774. [1, twoDimVert0], [1, twoDimVert0],
  22775. [1, twoDimVert0], [1, twoDimVert0],
  22776. [1, twoDimVert0], [1, twoDimVert0],
  22777. [1, twoDimVert0], [1, twoDimVert0],
  22778. [1, twoDimVert0], [1, twoDimVert0],
  22779. [1, twoDimVert0], [1, twoDimVert0],
  22780. [1, twoDimVert0], [1, twoDimVert0],
  22781. [1, twoDimVert0], [1, twoDimVert0],
  22782. [1, twoDimVert0], [1, twoDimVert0],
  22783. [1, twoDimVert0], [1, twoDimVert0],
  22784. [1, twoDimVert0], [1, twoDimVert0],
  22785. [1, twoDimVert0], [1, twoDimVert0],
  22786. [1, twoDimVert0], [1, twoDimVert0],
  22787. [1, twoDimVert0], [1, twoDimVert0],
  22788. [1, twoDimVert0], [1, twoDimVert0],
  22789. [1, twoDimVert0], [1, twoDimVert0],
  22790. [1, twoDimVert0], [1, twoDimVert0],
  22791. [1, twoDimVert0], [1, twoDimVert0],
  22792. [1, twoDimVert0], [1, twoDimVert0],
  22793. [1, twoDimVert0], [1, twoDimVert0],
  22794. [1, twoDimVert0], [1, twoDimVert0],
  22795. [1, twoDimVert0], [1, twoDimVert0],
  22796. [1, twoDimVert0], [1, twoDimVert0],
  22797. [1, twoDimVert0], [1, twoDimVert0],
  22798. [1, twoDimVert0], [1, twoDimVert0],
  22799. [1, twoDimVert0], [1, twoDimVert0],
  22800. [1, twoDimVert0], [1, twoDimVert0],
  22801. [1, twoDimVert0], [1, twoDimVert0],
  22802. [1, twoDimVert0], [1, twoDimVert0]
  22803. ];
  22804. var whiteTable1 = [
  22805. [-1, -1], // 00000
  22806. [12, ccittEOL], // 00001
  22807. [-1, -1], [-1, -1], // 0001x
  22808. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  22809. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  22810. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  22811. [11, 1792], [11, 1792], // 1000x
  22812. [12, 1984], // 10010
  22813. [12, 2048], // 10011
  22814. [12, 2112], // 10100
  22815. [12, 2176], // 10101
  22816. [12, 2240], // 10110
  22817. [12, 2304], // 10111
  22818. [11, 1856], [11, 1856], // 1100x
  22819. [11, 1920], [11, 1920], // 1101x
  22820. [12, 2368], // 11100
  22821. [12, 2432], // 11101
  22822. [12, 2496], // 11110
  22823. [12, 2560] // 11111
  22824. ];
  22825. var whiteTable2 = [
  22826. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  22827. [8, 29], [8, 29], // 00000010x
  22828. [8, 30], [8, 30], // 00000011x
  22829. [8, 45], [8, 45], // 00000100x
  22830. [8, 46], [8, 46], // 00000101x
  22831. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  22832. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  22833. [8, 47], [8, 47], // 00001010x
  22834. [8, 48], [8, 48], // 00001011x
  22835. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  22836. [6, 13], [6, 13], [6, 13], [6, 13],
  22837. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  22838. [8, 33], [8, 33], // 00010010x
  22839. [8, 34], [8, 34], // 00010011x
  22840. [8, 35], [8, 35], // 00010100x
  22841. [8, 36], [8, 36], // 00010101x
  22842. [8, 37], [8, 37], // 00010110x
  22843. [8, 38], [8, 38], // 00010111x
  22844. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  22845. [8, 31], [8, 31], // 00011010x
  22846. [8, 32], [8, 32], // 00011011x
  22847. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  22848. [6, 1], [6, 1], [6, 1], [6, 1],
  22849. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  22850. [6, 12], [6, 12], [6, 12], [6, 12],
  22851. [8, 53], [8, 53], // 00100100x
  22852. [8, 54], [8, 54], // 00100101x
  22853. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  22854. [8, 39], [8, 39], // 00101000x
  22855. [8, 40], [8, 40], // 00101001x
  22856. [8, 41], [8, 41], // 00101010x
  22857. [8, 42], [8, 42], // 00101011x
  22858. [8, 43], [8, 43], // 00101100x
  22859. [8, 44], [8, 44], // 00101101x
  22860. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  22861. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  22862. [8, 61], [8, 61], // 00110010x
  22863. [8, 62], [8, 62], // 00110011x
  22864. [8, 63], [8, 63], // 00110100x
  22865. [8, 0], [8, 0], // 00110101x
  22866. [8, 320], [8, 320], // 00110110x
  22867. [8, 384], [8, 384], // 00110111x
  22868. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  22869. [5, 10], [5, 10], [5, 10], [5, 10],
  22870. [5, 10], [5, 10], [5, 10], [5, 10],
  22871. [5, 10], [5, 10], [5, 10], [5, 10],
  22872. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  22873. [5, 11], [5, 11], [5, 11], [5, 11],
  22874. [5, 11], [5, 11], [5, 11], [5, 11],
  22875. [5, 11], [5, 11], [5, 11], [5, 11],
  22876. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  22877. [8, 59], [8, 59], // 01001010x
  22878. [8, 60], [8, 60], // 01001011x
  22879. [9, 1472], // 010011000
  22880. [9, 1536], // 010011001
  22881. [9, 1600], // 010011010
  22882. [9, 1728], // 010011011
  22883. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  22884. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  22885. [8, 49], [8, 49], // 01010010x
  22886. [8, 50], [8, 50], // 01010011x
  22887. [8, 51], [8, 51], // 01010100x
  22888. [8, 52], [8, 52], // 01010101x
  22889. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  22890. [8, 55], [8, 55], // 01011000x
  22891. [8, 56], [8, 56], // 01011001x
  22892. [8, 57], [8, 57], // 01011010x
  22893. [8, 58], [8, 58], // 01011011x
  22894. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  22895. [6, 192], [6, 192], [6, 192], [6, 192],
  22896. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  22897. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  22898. [8, 448], [8, 448], // 01100100x
  22899. [8, 512], [8, 512], // 01100101x
  22900. [9, 704], // 011001100
  22901. [9, 768], // 011001101
  22902. [8, 640], [8, 640], // 01100111x
  22903. [8, 576], [8, 576], // 01101000x
  22904. [9, 832], // 011010010
  22905. [9, 896], // 011010011
  22906. [9, 960], // 011010100
  22907. [9, 1024], // 011010101
  22908. [9, 1088], // 011010110
  22909. [9, 1152], // 011010111
  22910. [9, 1216], // 011011000
  22911. [9, 1280], // 011011001
  22912. [9, 1344], // 011011010
  22913. [9, 1408], // 011011011
  22914. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  22915. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  22916. [4, 2], [4, 2], [4, 2], [4, 2],
  22917. [4, 2], [4, 2], [4, 2], [4, 2],
  22918. [4, 2], [4, 2], [4, 2], [4, 2],
  22919. [4, 2], [4, 2], [4, 2], [4, 2],
  22920. [4, 2], [4, 2], [4, 2], [4, 2],
  22921. [4, 2], [4, 2], [4, 2], [4, 2],
  22922. [4, 2], [4, 2], [4, 2], [4, 2],
  22923. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  22924. [4, 3], [4, 3], [4, 3], [4, 3],
  22925. [4, 3], [4, 3], [4, 3], [4, 3],
  22926. [4, 3], [4, 3], [4, 3], [4, 3],
  22927. [4, 3], [4, 3], [4, 3], [4, 3],
  22928. [4, 3], [4, 3], [4, 3], [4, 3],
  22929. [4, 3], [4, 3], [4, 3], [4, 3],
  22930. [4, 3], [4, 3], [4, 3], [4, 3],
  22931. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  22932. [5, 128], [5, 128], [5, 128], [5, 128],
  22933. [5, 128], [5, 128], [5, 128], [5, 128],
  22934. [5, 128], [5, 128], [5, 128], [5, 128],
  22935. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  22936. [5, 8], [5, 8], [5, 8], [5, 8],
  22937. [5, 8], [5, 8], [5, 8], [5, 8],
  22938. [5, 8], [5, 8], [5, 8], [5, 8],
  22939. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  22940. [5, 9], [5, 9], [5, 9], [5, 9],
  22941. [5, 9], [5, 9], [5, 9], [5, 9],
  22942. [5, 9], [5, 9], [5, 9], [5, 9],
  22943. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  22944. [6, 16], [6, 16], [6, 16], [6, 16],
  22945. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  22946. [6, 17], [6, 17], [6, 17], [6, 17],
  22947. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  22948. [4, 4], [4, 4], [4, 4], [4, 4],
  22949. [4, 4], [4, 4], [4, 4], [4, 4],
  22950. [4, 4], [4, 4], [4, 4], [4, 4],
  22951. [4, 4], [4, 4], [4, 4], [4, 4],
  22952. [4, 4], [4, 4], [4, 4], [4, 4],
  22953. [4, 4], [4, 4], [4, 4], [4, 4],
  22954. [4, 4], [4, 4], [4, 4], [4, 4],
  22955. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  22956. [4, 5], [4, 5], [4, 5], [4, 5],
  22957. [4, 5], [4, 5], [4, 5], [4, 5],
  22958. [4, 5], [4, 5], [4, 5], [4, 5],
  22959. [4, 5], [4, 5], [4, 5], [4, 5],
  22960. [4, 5], [4, 5], [4, 5], [4, 5],
  22961. [4, 5], [4, 5], [4, 5], [4, 5],
  22962. [4, 5], [4, 5], [4, 5], [4, 5],
  22963. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  22964. [6, 14], [6, 14], [6, 14], [6, 14],
  22965. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  22966. [6, 15], [6, 15], [6, 15], [6, 15],
  22967. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  22968. [5, 64], [5, 64], [5, 64], [5, 64],
  22969. [5, 64], [5, 64], [5, 64], [5, 64],
  22970. [5, 64], [5, 64], [5, 64], [5, 64],
  22971. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  22972. [4, 6], [4, 6], [4, 6], [4, 6],
  22973. [4, 6], [4, 6], [4, 6], [4, 6],
  22974. [4, 6], [4, 6], [4, 6], [4, 6],
  22975. [4, 6], [4, 6], [4, 6], [4, 6],
  22976. [4, 6], [4, 6], [4, 6], [4, 6],
  22977. [4, 6], [4, 6], [4, 6], [4, 6],
  22978. [4, 6], [4, 6], [4, 6], [4, 6],
  22979. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  22980. [4, 7], [4, 7], [4, 7], [4, 7],
  22981. [4, 7], [4, 7], [4, 7], [4, 7],
  22982. [4, 7], [4, 7], [4, 7], [4, 7],
  22983. [4, 7], [4, 7], [4, 7], [4, 7],
  22984. [4, 7], [4, 7], [4, 7], [4, 7],
  22985. [4, 7], [4, 7], [4, 7], [4, 7],
  22986. [4, 7], [4, 7], [4, 7], [4, 7]
  22987. ];
  22988. var blackTable1 = [
  22989. [-1, -1], [-1, -1], // 000000000000x
  22990. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  22991. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  22992. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  22993. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  22994. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  22995. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  22996. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  22997. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  22998. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  22999. [12, 1984], [12, 1984], // 000000010010x
  23000. [12, 2048], [12, 2048], // 000000010011x
  23001. [12, 2112], [12, 2112], // 000000010100x
  23002. [12, 2176], [12, 2176], // 000000010101x
  23003. [12, 2240], [12, 2240], // 000000010110x
  23004. [12, 2304], [12, 2304], // 000000010111x
  23005. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  23006. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  23007. [12, 2368], [12, 2368], // 000000011100x
  23008. [12, 2432], [12, 2432], // 000000011101x
  23009. [12, 2496], [12, 2496], // 000000011110x
  23010. [12, 2560], [12, 2560], // 000000011111x
  23011. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  23012. [10, 18], [10, 18], [10, 18], [10, 18],
  23013. [12, 52], [12, 52], // 000000100100x
  23014. [13, 640], // 0000001001010
  23015. [13, 704], // 0000001001011
  23016. [13, 768], // 0000001001100
  23017. [13, 832], // 0000001001101
  23018. [12, 55], [12, 55], // 000000100111x
  23019. [12, 56], [12, 56], // 000000101000x
  23020. [13, 1280], // 0000001010010
  23021. [13, 1344], // 0000001010011
  23022. [13, 1408], // 0000001010100
  23023. [13, 1472], // 0000001010101
  23024. [12, 59], [12, 59], // 000000101011x
  23025. [12, 60], [12, 60], // 000000101100x
  23026. [13, 1536], // 0000001011010
  23027. [13, 1600], // 0000001011011
  23028. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  23029. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  23030. [13, 1664], // 0000001100100
  23031. [13, 1728], // 0000001100101
  23032. [12, 320], [12, 320], // 000000110011x
  23033. [12, 384], [12, 384], // 000000110100x
  23034. [12, 448], [12, 448], // 000000110101x
  23035. [13, 512], // 0000001101100
  23036. [13, 576], // 0000001101101
  23037. [12, 53], [12, 53], // 000000110111x
  23038. [12, 54], [12, 54], // 000000111000x
  23039. [13, 896], // 0000001110010
  23040. [13, 960], // 0000001110011
  23041. [13, 1024], // 0000001110100
  23042. [13, 1088], // 0000001110101
  23043. [13, 1152], // 0000001110110
  23044. [13, 1216], // 0000001110111
  23045. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  23046. [10, 64], [10, 64], [10, 64], [10, 64]
  23047. ];
  23048. var blackTable2 = [
  23049. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  23050. [8, 13], [8, 13], [8, 13], [8, 13],
  23051. [8, 13], [8, 13], [8, 13], [8, 13],
  23052. [8, 13], [8, 13], [8, 13], [8, 13],
  23053. [11, 23], [11, 23], // 00000101000x
  23054. [12, 50], // 000001010010
  23055. [12, 51], // 000001010011
  23056. [12, 44], // 000001010100
  23057. [12, 45], // 000001010101
  23058. [12, 46], // 000001010110
  23059. [12, 47], // 000001010111
  23060. [12, 57], // 000001011000
  23061. [12, 58], // 000001011001
  23062. [12, 61], // 000001011010
  23063. [12, 256], // 000001011011
  23064. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  23065. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  23066. [12, 48], // 000001100100
  23067. [12, 49], // 000001100101
  23068. [12, 62], // 000001100110
  23069. [12, 63], // 000001100111
  23070. [12, 30], // 000001101000
  23071. [12, 31], // 000001101001
  23072. [12, 32], // 000001101010
  23073. [12, 33], // 000001101011
  23074. [12, 40], // 000001101100
  23075. [12, 41], // 000001101101
  23076. [11, 22], [11, 22], // 00000110111x
  23077. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  23078. [8, 14], [8, 14], [8, 14], [8, 14],
  23079. [8, 14], [8, 14], [8, 14], [8, 14],
  23080. [8, 14], [8, 14], [8, 14], [8, 14],
  23081. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  23082. [7, 10], [7, 10], [7, 10], [7, 10],
  23083. [7, 10], [7, 10], [7, 10], [7, 10],
  23084. [7, 10], [7, 10], [7, 10], [7, 10],
  23085. [7, 10], [7, 10], [7, 10], [7, 10],
  23086. [7, 10], [7, 10], [7, 10], [7, 10],
  23087. [7, 10], [7, 10], [7, 10], [7, 10],
  23088. [7, 10], [7, 10], [7, 10], [7, 10],
  23089. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  23090. [7, 11], [7, 11], [7, 11], [7, 11],
  23091. [7, 11], [7, 11], [7, 11], [7, 11],
  23092. [7, 11], [7, 11], [7, 11], [7, 11],
  23093. [7, 11], [7, 11], [7, 11], [7, 11],
  23094. [7, 11], [7, 11], [7, 11], [7, 11],
  23095. [7, 11], [7, 11], [7, 11], [7, 11],
  23096. [7, 11], [7, 11], [7, 11], [7, 11],
  23097. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  23098. [9, 15], [9, 15], [9, 15], [9, 15],
  23099. [12, 128], // 000011001000
  23100. [12, 192], // 000011001001
  23101. [12, 26], // 000011001010
  23102. [12, 27], // 000011001011
  23103. [12, 28], // 000011001100
  23104. [12, 29], // 000011001101
  23105. [11, 19], [11, 19], // 00001100111x
  23106. [11, 20], [11, 20], // 00001101000x
  23107. [12, 34], // 000011010010
  23108. [12, 35], // 000011010011
  23109. [12, 36], // 000011010100
  23110. [12, 37], // 000011010101
  23111. [12, 38], // 000011010110
  23112. [12, 39], // 000011010111
  23113. [11, 21], [11, 21], // 00001101100x
  23114. [12, 42], // 000011011010
  23115. [12, 43], // 000011011011
  23116. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  23117. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  23118. [7, 12], [7, 12], [7, 12], [7, 12],
  23119. [7, 12], [7, 12], [7, 12], [7, 12],
  23120. [7, 12], [7, 12], [7, 12], [7, 12],
  23121. [7, 12], [7, 12], [7, 12], [7, 12],
  23122. [7, 12], [7, 12], [7, 12], [7, 12],
  23123. [7, 12], [7, 12], [7, 12], [7, 12],
  23124. [7, 12], [7, 12], [7, 12], [7, 12]
  23125. ];
  23126. var blackTable3 = [
  23127. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  23128. [6, 9], // 000100
  23129. [6, 8], // 000101
  23130. [5, 7], [5, 7], // 00011x
  23131. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  23132. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  23133. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  23134. [3, 1], [3, 1], [3, 1], [3, 1],
  23135. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  23136. [3, 4], [3, 4], [3, 4], [3, 4],
  23137. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  23138. [2, 3], [2, 3], [2, 3], [2, 3],
  23139. [2, 3], [2, 3], [2, 3], [2, 3],
  23140. [2, 3], [2, 3], [2, 3], [2, 3],
  23141. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  23142. [2, 2], [2, 2], [2, 2], [2, 2],
  23143. [2, 2], [2, 2], [2, 2], [2, 2],
  23144. [2, 2], [2, 2], [2, 2], [2, 2]
  23145. ];
  23146. function CCITTFaxStream(str, maybeLength, params) {
  23147. this.str = str;
  23148. this.dict = str.dict;
  23149. params = params || Dict.empty;
  23150. this.encoding = params.get('K') || 0;
  23151. this.eoline = params.get('EndOfLine') || false;
  23152. this.byteAlign = params.get('EncodedByteAlign') || false;
  23153. this.columns = params.get('Columns') || 1728;
  23154. this.rows = params.get('Rows') || 0;
  23155. var eoblock = params.get('EndOfBlock');
  23156. if (eoblock === null || eoblock === undefined) {
  23157. eoblock = true;
  23158. }
  23159. this.eoblock = eoblock;
  23160. this.black = params.get('BlackIs1') || false;
  23161. this.codingLine = new Uint32Array(this.columns + 1);
  23162. this.refLine = new Uint32Array(this.columns + 2);
  23163. this.codingLine[0] = this.columns;
  23164. this.codingPos = 0;
  23165. this.row = 0;
  23166. this.nextLine2D = this.encoding < 0;
  23167. this.inputBits = 0;
  23168. this.inputBuf = 0;
  23169. this.outputBits = 0;
  23170. var code1;
  23171. while ((code1 = this.lookBits(12)) === 0) {
  23172. this.eatBits(1);
  23173. }
  23174. if (code1 === 1) {
  23175. this.eatBits(12);
  23176. }
  23177. if (this.encoding > 0) {
  23178. this.nextLine2D = !this.lookBits(1);
  23179. this.eatBits(1);
  23180. }
  23181. DecodeStream.call(this, maybeLength);
  23182. }
  23183. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  23184. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  23185. while (!this.eof) {
  23186. var c = this.lookChar();
  23187. this.ensureBuffer(this.bufferLength + 1);
  23188. this.buffer[this.bufferLength++] = c;
  23189. }
  23190. };
  23191. CCITTFaxStream.prototype.addPixels =
  23192. function ccittFaxStreamAddPixels(a1, blackPixels) {
  23193. var codingLine = this.codingLine;
  23194. var codingPos = this.codingPos;
  23195. if (a1 > codingLine[codingPos]) {
  23196. if (a1 > this.columns) {
  23197. info('row is wrong length');
  23198. this.err = true;
  23199. a1 = this.columns;
  23200. }
  23201. if ((codingPos & 1) ^ blackPixels) {
  23202. ++codingPos;
  23203. }
  23204. codingLine[codingPos] = a1;
  23205. }
  23206. this.codingPos = codingPos;
  23207. };
  23208. CCITTFaxStream.prototype.addPixelsNeg =
  23209. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  23210. var codingLine = this.codingLine;
  23211. var codingPos = this.codingPos;
  23212. if (a1 > codingLine[codingPos]) {
  23213. if (a1 > this.columns) {
  23214. info('row is wrong length');
  23215. this.err = true;
  23216. a1 = this.columns;
  23217. }
  23218. if ((codingPos & 1) ^ blackPixels) {
  23219. ++codingPos;
  23220. }
  23221. codingLine[codingPos] = a1;
  23222. } else if (a1 < codingLine[codingPos]) {
  23223. if (a1 < 0) {
  23224. info('invalid code');
  23225. this.err = true;
  23226. a1 = 0;
  23227. }
  23228. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  23229. --codingPos;
  23230. }
  23231. codingLine[codingPos] = a1;
  23232. }
  23233. this.codingPos = codingPos;
  23234. };
  23235. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  23236. var refLine = this.refLine;
  23237. var codingLine = this.codingLine;
  23238. var columns = this.columns;
  23239. var refPos, blackPixels, bits, i;
  23240. if (this.outputBits === 0) {
  23241. if (this.eof) {
  23242. return null;
  23243. }
  23244. this.err = false;
  23245. var code1, code2, code3;
  23246. if (this.nextLine2D) {
  23247. for (i = 0; codingLine[i] < columns; ++i) {
  23248. refLine[i] = codingLine[i];
  23249. }
  23250. refLine[i++] = columns;
  23251. refLine[i] = columns;
  23252. codingLine[0] = 0;
  23253. this.codingPos = 0;
  23254. refPos = 0;
  23255. blackPixels = 0;
  23256. while (codingLine[this.codingPos] < columns) {
  23257. code1 = this.getTwoDimCode();
  23258. switch (code1) {
  23259. case twoDimPass:
  23260. this.addPixels(refLine[refPos + 1], blackPixels);
  23261. if (refLine[refPos + 1] < columns) {
  23262. refPos += 2;
  23263. }
  23264. break;
  23265. case twoDimHoriz:
  23266. code1 = code2 = 0;
  23267. if (blackPixels) {
  23268. do {
  23269. code1 += (code3 = this.getBlackCode());
  23270. } while (code3 >= 64);
  23271. do {
  23272. code2 += (code3 = this.getWhiteCode());
  23273. } while (code3 >= 64);
  23274. } else {
  23275. do {
  23276. code1 += (code3 = this.getWhiteCode());
  23277. } while (code3 >= 64);
  23278. do {
  23279. code2 += (code3 = this.getBlackCode());
  23280. } while (code3 >= 64);
  23281. }
  23282. this.addPixels(codingLine[this.codingPos] +
  23283. code1, blackPixels);
  23284. if (codingLine[this.codingPos] < columns) {
  23285. this.addPixels(codingLine[this.codingPos] + code2,
  23286. blackPixels ^ 1);
  23287. }
  23288. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23289. refLine[refPos] < columns) {
  23290. refPos += 2;
  23291. }
  23292. break;
  23293. case twoDimVertR3:
  23294. this.addPixels(refLine[refPos] + 3, blackPixels);
  23295. blackPixels ^= 1;
  23296. if (codingLine[this.codingPos] < columns) {
  23297. ++refPos;
  23298. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23299. refLine[refPos] < columns) {
  23300. refPos += 2;
  23301. }
  23302. }
  23303. break;
  23304. case twoDimVertR2:
  23305. this.addPixels(refLine[refPos] + 2, blackPixels);
  23306. blackPixels ^= 1;
  23307. if (codingLine[this.codingPos] < columns) {
  23308. ++refPos;
  23309. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23310. refLine[refPos] < columns) {
  23311. refPos += 2;
  23312. }
  23313. }
  23314. break;
  23315. case twoDimVertR1:
  23316. this.addPixels(refLine[refPos] + 1, blackPixels);
  23317. blackPixels ^= 1;
  23318. if (codingLine[this.codingPos] < columns) {
  23319. ++refPos;
  23320. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23321. refLine[refPos] < columns) {
  23322. refPos += 2;
  23323. }
  23324. }
  23325. break;
  23326. case twoDimVert0:
  23327. this.addPixels(refLine[refPos], blackPixels);
  23328. blackPixels ^= 1;
  23329. if (codingLine[this.codingPos] < columns) {
  23330. ++refPos;
  23331. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23332. refLine[refPos] < columns) {
  23333. refPos += 2;
  23334. }
  23335. }
  23336. break;
  23337. case twoDimVertL3:
  23338. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  23339. blackPixels ^= 1;
  23340. if (codingLine[this.codingPos] < columns) {
  23341. if (refPos > 0) {
  23342. --refPos;
  23343. } else {
  23344. ++refPos;
  23345. }
  23346. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23347. refLine[refPos] < columns) {
  23348. refPos += 2;
  23349. }
  23350. }
  23351. break;
  23352. case twoDimVertL2:
  23353. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  23354. blackPixels ^= 1;
  23355. if (codingLine[this.codingPos] < columns) {
  23356. if (refPos > 0) {
  23357. --refPos;
  23358. } else {
  23359. ++refPos;
  23360. }
  23361. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23362. refLine[refPos] < columns) {
  23363. refPos += 2;
  23364. }
  23365. }
  23366. break;
  23367. case twoDimVertL1:
  23368. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  23369. blackPixels ^= 1;
  23370. if (codingLine[this.codingPos] < columns) {
  23371. if (refPos > 0) {
  23372. --refPos;
  23373. } else {
  23374. ++refPos;
  23375. }
  23376. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23377. refLine[refPos] < columns) {
  23378. refPos += 2;
  23379. }
  23380. }
  23381. break;
  23382. case EOF:
  23383. this.addPixels(columns, 0);
  23384. this.eof = true;
  23385. break;
  23386. default:
  23387. info('bad 2d code');
  23388. this.addPixels(columns, 0);
  23389. this.err = true;
  23390. }
  23391. }
  23392. } else {
  23393. codingLine[0] = 0;
  23394. this.codingPos = 0;
  23395. blackPixels = 0;
  23396. while (codingLine[this.codingPos] < columns) {
  23397. code1 = 0;
  23398. if (blackPixels) {
  23399. do {
  23400. code1 += (code3 = this.getBlackCode());
  23401. } while (code3 >= 64);
  23402. } else {
  23403. do {
  23404. code1 += (code3 = this.getWhiteCode());
  23405. } while (code3 >= 64);
  23406. }
  23407. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  23408. blackPixels ^= 1;
  23409. }
  23410. }
  23411. var gotEOL = false;
  23412. if (this.byteAlign) {
  23413. this.inputBits &= ~7;
  23414. }
  23415. if (!this.eoblock && this.row === this.rows - 1) {
  23416. this.eof = true;
  23417. } else {
  23418. code1 = this.lookBits(12);
  23419. if (this.eoline) {
  23420. while (code1 !== EOF && code1 !== 1) {
  23421. this.eatBits(1);
  23422. code1 = this.lookBits(12);
  23423. }
  23424. } else {
  23425. while (code1 === 0) {
  23426. this.eatBits(1);
  23427. code1 = this.lookBits(12);
  23428. }
  23429. }
  23430. if (code1 === 1) {
  23431. this.eatBits(12);
  23432. gotEOL = true;
  23433. } else if (code1 === EOF) {
  23434. this.eof = true;
  23435. }
  23436. }
  23437. if (!this.eof && this.encoding > 0) {
  23438. this.nextLine2D = !this.lookBits(1);
  23439. this.eatBits(1);
  23440. }
  23441. if (this.eoblock && gotEOL && this.byteAlign) {
  23442. code1 = this.lookBits(12);
  23443. if (code1 === 1) {
  23444. this.eatBits(12);
  23445. if (this.encoding > 0) {
  23446. this.lookBits(1);
  23447. this.eatBits(1);
  23448. }
  23449. if (this.encoding >= 0) {
  23450. for (i = 0; i < 4; ++i) {
  23451. code1 = this.lookBits(12);
  23452. if (code1 !== 1) {
  23453. info('bad rtc code: ' + code1);
  23454. }
  23455. this.eatBits(12);
  23456. if (this.encoding > 0) {
  23457. this.lookBits(1);
  23458. this.eatBits(1);
  23459. }
  23460. }
  23461. }
  23462. this.eof = true;
  23463. }
  23464. } else if (this.err && this.eoline) {
  23465. while (true) {
  23466. code1 = this.lookBits(13);
  23467. if (code1 === EOF) {
  23468. this.eof = true;
  23469. return null;
  23470. }
  23471. if ((code1 >> 1) === 1) {
  23472. break;
  23473. }
  23474. this.eatBits(1);
  23475. }
  23476. this.eatBits(12);
  23477. if (this.encoding > 0) {
  23478. this.eatBits(1);
  23479. this.nextLine2D = !(code1 & 1);
  23480. }
  23481. }
  23482. if (codingLine[0] > 0) {
  23483. this.outputBits = codingLine[this.codingPos = 0];
  23484. } else {
  23485. this.outputBits = codingLine[this.codingPos = 1];
  23486. }
  23487. this.row++;
  23488. }
  23489. var c;
  23490. if (this.outputBits >= 8) {
  23491. c = (this.codingPos & 1) ? 0 : 0xFF;
  23492. this.outputBits -= 8;
  23493. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  23494. this.codingPos++;
  23495. this.outputBits = (codingLine[this.codingPos] -
  23496. codingLine[this.codingPos - 1]);
  23497. }
  23498. } else {
  23499. bits = 8;
  23500. c = 0;
  23501. do {
  23502. if (this.outputBits > bits) {
  23503. c <<= bits;
  23504. if (!(this.codingPos & 1)) {
  23505. c |= 0xFF >> (8 - bits);
  23506. }
  23507. this.outputBits -= bits;
  23508. bits = 0;
  23509. } else {
  23510. c <<= this.outputBits;
  23511. if (!(this.codingPos & 1)) {
  23512. c |= 0xFF >> (8 - this.outputBits);
  23513. }
  23514. bits -= this.outputBits;
  23515. this.outputBits = 0;
  23516. if (codingLine[this.codingPos] < columns) {
  23517. this.codingPos++;
  23518. this.outputBits = (codingLine[this.codingPos] -
  23519. codingLine[this.codingPos - 1]);
  23520. } else if (bits > 0) {
  23521. c <<= bits;
  23522. bits = 0;
  23523. }
  23524. }
  23525. } while (bits);
  23526. }
  23527. if (this.black) {
  23528. c ^= 0xFF;
  23529. }
  23530. return c;
  23531. };
  23532. // This functions returns the code found from the table.
  23533. // The start and end parameters set the boundaries for searching the table.
  23534. // The limit parameter is optional. Function returns an array with three
  23535. // values. The first array element indicates whether a valid code is being
  23536. // returned. The second array element is the actual code. The third array
  23537. // element indicates whether EOF was reached.
  23538. CCITTFaxStream.prototype.findTableCode =
  23539. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  23540. var limitValue = limit || 0;
  23541. for (var i = start; i <= end; ++i) {
  23542. var code = this.lookBits(i);
  23543. if (code === EOF) {
  23544. return [true, 1, false];
  23545. }
  23546. if (i < end) {
  23547. code <<= end - i;
  23548. }
  23549. if (!limitValue || code >= limitValue) {
  23550. var p = table[code - limitValue];
  23551. if (p[0] === i) {
  23552. this.eatBits(i);
  23553. return [true, p[1], true];
  23554. }
  23555. }
  23556. }
  23557. return [false, 0, false];
  23558. };
  23559. CCITTFaxStream.prototype.getTwoDimCode =
  23560. function ccittFaxStreamGetTwoDimCode() {
  23561. var code = 0;
  23562. var p;
  23563. if (this.eoblock) {
  23564. code = this.lookBits(7);
  23565. p = twoDimTable[code];
  23566. if (p && p[0] > 0) {
  23567. this.eatBits(p[0]);
  23568. return p[1];
  23569. }
  23570. } else {
  23571. var result = this.findTableCode(1, 7, twoDimTable);
  23572. if (result[0] && result[2]) {
  23573. return result[1];
  23574. }
  23575. }
  23576. info('Bad two dim code');
  23577. return EOF;
  23578. };
  23579. CCITTFaxStream.prototype.getWhiteCode =
  23580. function ccittFaxStreamGetWhiteCode() {
  23581. var code = 0;
  23582. var p;
  23583. if (this.eoblock) {
  23584. code = this.lookBits(12);
  23585. if (code === EOF) {
  23586. return 1;
  23587. }
  23588. if ((code >> 5) === 0) {
  23589. p = whiteTable1[code];
  23590. } else {
  23591. p = whiteTable2[code >> 3];
  23592. }
  23593. if (p[0] > 0) {
  23594. this.eatBits(p[0]);
  23595. return p[1];
  23596. }
  23597. } else {
  23598. var result = this.findTableCode(1, 9, whiteTable2);
  23599. if (result[0]) {
  23600. return result[1];
  23601. }
  23602. result = this.findTableCode(11, 12, whiteTable1);
  23603. if (result[0]) {
  23604. return result[1];
  23605. }
  23606. }
  23607. info('bad white code');
  23608. this.eatBits(1);
  23609. return 1;
  23610. };
  23611. CCITTFaxStream.prototype.getBlackCode =
  23612. function ccittFaxStreamGetBlackCode() {
  23613. var code, p;
  23614. if (this.eoblock) {
  23615. code = this.lookBits(13);
  23616. if (code === EOF) {
  23617. return 1;
  23618. }
  23619. if ((code >> 7) === 0) {
  23620. p = blackTable1[code];
  23621. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  23622. p = blackTable2[(code >> 1) - 64];
  23623. } else {
  23624. p = blackTable3[code >> 7];
  23625. }
  23626. if (p[0] > 0) {
  23627. this.eatBits(p[0]);
  23628. return p[1];
  23629. }
  23630. } else {
  23631. var result = this.findTableCode(2, 6, blackTable3);
  23632. if (result[0]) {
  23633. return result[1];
  23634. }
  23635. result = this.findTableCode(7, 12, blackTable2, 64);
  23636. if (result[0]) {
  23637. return result[1];
  23638. }
  23639. result = this.findTableCode(10, 13, blackTable1);
  23640. if (result[0]) {
  23641. return result[1];
  23642. }
  23643. }
  23644. info('bad black code');
  23645. this.eatBits(1);
  23646. return 1;
  23647. };
  23648. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  23649. var c;
  23650. while (this.inputBits < n) {
  23651. if ((c = this.str.getByte()) === -1) {
  23652. if (this.inputBits === 0) {
  23653. return EOF;
  23654. }
  23655. return ((this.inputBuf << (n - this.inputBits)) &
  23656. (0xFFFF >> (16 - n)));
  23657. }
  23658. this.inputBuf = (this.inputBuf << 8) + c;
  23659. this.inputBits += 8;
  23660. }
  23661. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  23662. };
  23663. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  23664. if ((this.inputBits -= n) < 0) {
  23665. this.inputBits = 0;
  23666. }
  23667. };
  23668. return CCITTFaxStream;
  23669. })();
  23670. var LZWStream = (function LZWStreamClosure() {
  23671. function LZWStream(str, maybeLength, earlyChange) {
  23672. this.str = str;
  23673. this.dict = str.dict;
  23674. this.cachedData = 0;
  23675. this.bitsCached = 0;
  23676. var maxLzwDictionarySize = 4096;
  23677. var lzwState = {
  23678. earlyChange: earlyChange,
  23679. codeLength: 9,
  23680. nextCode: 258,
  23681. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  23682. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  23683. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  23684. currentSequence: new Uint8Array(maxLzwDictionarySize),
  23685. currentSequenceLength: 0
  23686. };
  23687. for (var i = 0; i < 256; ++i) {
  23688. lzwState.dictionaryValues[i] = i;
  23689. lzwState.dictionaryLengths[i] = 1;
  23690. }
  23691. this.lzwState = lzwState;
  23692. DecodeStream.call(this, maybeLength);
  23693. }
  23694. LZWStream.prototype = Object.create(DecodeStream.prototype);
  23695. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  23696. var bitsCached = this.bitsCached;
  23697. var cachedData = this.cachedData;
  23698. while (bitsCached < n) {
  23699. var c = this.str.getByte();
  23700. if (c === -1) {
  23701. this.eof = true;
  23702. return null;
  23703. }
  23704. cachedData = (cachedData << 8) | c;
  23705. bitsCached += 8;
  23706. }
  23707. this.bitsCached = (bitsCached -= n);
  23708. this.cachedData = cachedData;
  23709. this.lastCode = null;
  23710. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  23711. };
  23712. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  23713. var blockSize = 512;
  23714. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  23715. var i, j, q;
  23716. var lzwState = this.lzwState;
  23717. if (!lzwState) {
  23718. return; // eof was found
  23719. }
  23720. var earlyChange = lzwState.earlyChange;
  23721. var nextCode = lzwState.nextCode;
  23722. var dictionaryValues = lzwState.dictionaryValues;
  23723. var dictionaryLengths = lzwState.dictionaryLengths;
  23724. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  23725. var codeLength = lzwState.codeLength;
  23726. var prevCode = lzwState.prevCode;
  23727. var currentSequence = lzwState.currentSequence;
  23728. var currentSequenceLength = lzwState.currentSequenceLength;
  23729. var decodedLength = 0;
  23730. var currentBufferLength = this.bufferLength;
  23731. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  23732. for (i = 0; i < blockSize; i++) {
  23733. var code = this.readBits(codeLength);
  23734. var hasPrev = currentSequenceLength > 0;
  23735. if (code < 256) {
  23736. currentSequence[0] = code;
  23737. currentSequenceLength = 1;
  23738. } else if (code >= 258) {
  23739. if (code < nextCode) {
  23740. currentSequenceLength = dictionaryLengths[code];
  23741. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  23742. currentSequence[j] = dictionaryValues[q];
  23743. q = dictionaryPrevCodes[q];
  23744. }
  23745. } else {
  23746. currentSequence[currentSequenceLength++] = currentSequence[0];
  23747. }
  23748. } else if (code === 256) {
  23749. codeLength = 9;
  23750. nextCode = 258;
  23751. currentSequenceLength = 0;
  23752. continue;
  23753. } else {
  23754. this.eof = true;
  23755. delete this.lzwState;
  23756. break;
  23757. }
  23758. if (hasPrev) {
  23759. dictionaryPrevCodes[nextCode] = prevCode;
  23760. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  23761. dictionaryValues[nextCode] = currentSequence[0];
  23762. nextCode++;
  23763. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  23764. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  23765. 0.6931471805599453 + 1, 12) | 0;
  23766. }
  23767. prevCode = code;
  23768. decodedLength += currentSequenceLength;
  23769. if (estimatedDecodedSize < decodedLength) {
  23770. do {
  23771. estimatedDecodedSize += decodedSizeDelta;
  23772. } while (estimatedDecodedSize < decodedLength);
  23773. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  23774. }
  23775. for (j = 0; j < currentSequenceLength; j++) {
  23776. buffer[currentBufferLength++] = currentSequence[j];
  23777. }
  23778. }
  23779. lzwState.nextCode = nextCode;
  23780. lzwState.codeLength = codeLength;
  23781. lzwState.prevCode = prevCode;
  23782. lzwState.currentSequenceLength = currentSequenceLength;
  23783. this.bufferLength = currentBufferLength;
  23784. };
  23785. return LZWStream;
  23786. })();
  23787. var NullStream = (function NullStreamClosure() {
  23788. function NullStream() {
  23789. Stream.call(this, new Uint8Array(0));
  23790. }
  23791. NullStream.prototype = Stream.prototype;
  23792. return NullStream;
  23793. })();
  23794. // TODO refactor to remove dependency on parser.js
  23795. function _setCoreParser(coreParser_) {
  23796. coreParser = coreParser_;
  23797. EOF = coreParser_.EOF;
  23798. Lexer = coreParser_.Lexer;
  23799. }
  23800. exports._setCoreParser = _setCoreParser;
  23801. // TODO refactor to remove dependency on colorspace.js
  23802. function _setCoreColorSpace(coreColorSpace_) {
  23803. coreColorSpace = coreColorSpace_;
  23804. ColorSpace = coreColorSpace_.ColorSpace;
  23805. }
  23806. exports._setCoreColorSpace = _setCoreColorSpace;
  23807. exports.Ascii85Stream = Ascii85Stream;
  23808. exports.AsciiHexStream = AsciiHexStream;
  23809. exports.CCITTFaxStream = CCITTFaxStream;
  23810. exports.DecryptStream = DecryptStream;
  23811. exports.DecodeStream = DecodeStream;
  23812. exports.FlateStream = FlateStream;
  23813. exports.Jbig2Stream = Jbig2Stream;
  23814. exports.JpegStream = JpegStream;
  23815. exports.JpxStream = JpxStream;
  23816. exports.NullStream = NullStream;
  23817. exports.PredictorStream = PredictorStream;
  23818. exports.RunLengthStream = RunLengthStream;
  23819. exports.Stream = Stream;
  23820. exports.StreamsSequenceStream = StreamsSequenceStream;
  23821. exports.StringStream = StringStream;
  23822. exports.LZWStream = LZWStream;
  23823. }));
  23824. (function (root, factory) {
  23825. {
  23826. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  23827. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23828. }
  23829. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23830. var PasswordException = sharedUtil.PasswordException;
  23831. var PasswordResponses = sharedUtil.PasswordResponses;
  23832. var bytesToString = sharedUtil.bytesToString;
  23833. var error = sharedUtil.error;
  23834. var isInt = sharedUtil.isInt;
  23835. var stringToBytes = sharedUtil.stringToBytes;
  23836. var utf8StringToString = sharedUtil.utf8StringToString;
  23837. var warn = sharedUtil.warn;
  23838. var Name = corePrimitives.Name;
  23839. var isName = corePrimitives.isName;
  23840. var DecryptStream = coreStream.DecryptStream;
  23841. var ARCFourCipher = (function ARCFourCipherClosure() {
  23842. function ARCFourCipher(key) {
  23843. this.a = 0;
  23844. this.b = 0;
  23845. var s = new Uint8Array(256);
  23846. var i, j = 0, tmp, keyLength = key.length;
  23847. for (i = 0; i < 256; ++i) {
  23848. s[i] = i;
  23849. }
  23850. for (i = 0; i < 256; ++i) {
  23851. tmp = s[i];
  23852. j = (j + tmp + key[i % keyLength]) & 0xFF;
  23853. s[i] = s[j];
  23854. s[j] = tmp;
  23855. }
  23856. this.s = s;
  23857. }
  23858. ARCFourCipher.prototype = {
  23859. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  23860. var i, n = data.length, tmp, tmp2;
  23861. var a = this.a, b = this.b, s = this.s;
  23862. var output = new Uint8Array(n);
  23863. for (i = 0; i < n; ++i) {
  23864. a = (a + 1) & 0xFF;
  23865. tmp = s[a];
  23866. b = (b + tmp) & 0xFF;
  23867. tmp2 = s[b];
  23868. s[a] = tmp2;
  23869. s[b] = tmp;
  23870. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  23871. }
  23872. this.a = a;
  23873. this.b = b;
  23874. return output;
  23875. }
  23876. };
  23877. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  23878. return ARCFourCipher;
  23879. })();
  23880. var calculateMD5 = (function calculateMD5Closure() {
  23881. var r = new Uint8Array([
  23882. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23883. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23884. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23885. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23886. var k = new Int32Array([
  23887. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23888. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23889. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23890. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23891. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23892. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23893. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23894. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23895. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23896. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23897. -145523070, -1120210379, 718787259, -343485551]);
  23898. function hash(data, offset, length) {
  23899. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23900. // pre-processing
  23901. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23902. var padded = new Uint8Array(paddedLength);
  23903. var i, j, n;
  23904. for (i = 0; i < length; ++i) {
  23905. padded[i] = data[offset++];
  23906. }
  23907. padded[i++] = 0x80;
  23908. n = paddedLength - 8;
  23909. while (i < n) {
  23910. padded[i++] = 0;
  23911. }
  23912. padded[i++] = (length << 3) & 0xFF;
  23913. padded[i++] = (length >> 5) & 0xFF;
  23914. padded[i++] = (length >> 13) & 0xFF;
  23915. padded[i++] = (length >> 21) & 0xFF;
  23916. padded[i++] = (length >>> 29) & 0xFF;
  23917. padded[i++] = 0;
  23918. padded[i++] = 0;
  23919. padded[i++] = 0;
  23920. var w = new Int32Array(16);
  23921. for (i = 0; i < paddedLength;) {
  23922. for (j = 0; j < 16; ++j, i += 4) {
  23923. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23924. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23925. }
  23926. var a = h0, b = h1, c = h2, d = h3, f, g;
  23927. for (j = 0; j < 64; ++j) {
  23928. if (j < 16) {
  23929. f = (b & c) | ((~b) & d);
  23930. g = j;
  23931. } else if (j < 32) {
  23932. f = (d & b) | ((~d) & c);
  23933. g = (5 * j + 1) & 15;
  23934. } else if (j < 48) {
  23935. f = b ^ c ^ d;
  23936. g = (3 * j + 5) & 15;
  23937. } else {
  23938. f = c ^ (b | (~d));
  23939. g = (7 * j) & 15;
  23940. }
  23941. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23942. d = c;
  23943. c = b;
  23944. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23945. a = tmp;
  23946. }
  23947. h0 = (h0 + a) | 0;
  23948. h1 = (h1 + b) | 0;
  23949. h2 = (h2 + c) | 0;
  23950. h3 = (h3 + d) | 0;
  23951. }
  23952. return new Uint8Array([
  23953. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23954. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23955. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23956. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23957. ]);
  23958. }
  23959. return hash;
  23960. })();
  23961. var Word64 = (function Word64Closure() {
  23962. function Word64(highInteger, lowInteger) {
  23963. this.high = highInteger | 0;
  23964. this.low = lowInteger | 0;
  23965. }
  23966. Word64.prototype = {
  23967. and: function Word64_and(word) {
  23968. this.high &= word.high;
  23969. this.low &= word.low;
  23970. },
  23971. xor: function Word64_xor(word) {
  23972. this.high ^= word.high;
  23973. this.low ^= word.low;
  23974. },
  23975. or: function Word64_or(word) {
  23976. this.high |= word.high;
  23977. this.low |= word.low;
  23978. },
  23979. shiftRight: function Word64_shiftRight(places) {
  23980. if (places >= 32) {
  23981. this.low = (this.high >>> (places - 32)) | 0;
  23982. this.high = 0;
  23983. } else {
  23984. this.low = (this.low >>> places) | (this.high << (32 - places));
  23985. this.high = (this.high >>> places) | 0;
  23986. }
  23987. },
  23988. shiftLeft: function Word64_shiftLeft(places) {
  23989. if (places >= 32) {
  23990. this.high = this.low << (places - 32);
  23991. this.low = 0;
  23992. } else {
  23993. this.high = (this.high << places) | (this.low >>> (32 - places));
  23994. this.low = this.low << places;
  23995. }
  23996. },
  23997. rotateRight: function Word64_rotateRight(places) {
  23998. var low, high;
  23999. if (places & 32) {
  24000. high = this.low;
  24001. low = this.high;
  24002. } else {
  24003. low = this.low;
  24004. high = this.high;
  24005. }
  24006. places &= 31;
  24007. this.low = (low >>> places) | (high << (32 - places));
  24008. this.high = (high >>> places) | (low << (32 - places));
  24009. },
  24010. not: function Word64_not() {
  24011. this.high = ~this.high;
  24012. this.low = ~this.low;
  24013. },
  24014. add: function Word64_add(word) {
  24015. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  24016. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  24017. if (lowAdd > 0xFFFFFFFF) {
  24018. highAdd += 1;
  24019. }
  24020. this.low = lowAdd | 0;
  24021. this.high = highAdd | 0;
  24022. },
  24023. copyTo: function Word64_copyTo(bytes, offset) {
  24024. bytes[offset] = (this.high >>> 24) & 0xFF;
  24025. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  24026. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  24027. bytes[offset + 3] = this.high & 0xFF;
  24028. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  24029. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  24030. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  24031. bytes[offset + 7] = this.low & 0xFF;
  24032. },
  24033. assign: function Word64_assign(word) {
  24034. this.high = word.high;
  24035. this.low = word.low;
  24036. }
  24037. };
  24038. return Word64;
  24039. })();
  24040. var calculateSHA256 = (function calculateSHA256Closure() {
  24041. function rotr(x, n) {
  24042. return (x >>> n) | (x << 32 - n);
  24043. }
  24044. function ch(x, y, z) {
  24045. return (x & y) ^ (~x & z);
  24046. }
  24047. function maj(x, y, z) {
  24048. return (x & y) ^ (x & z) ^ (y & z);
  24049. }
  24050. function sigma(x) {
  24051. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  24052. }
  24053. function sigmaPrime(x) {
  24054. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  24055. }
  24056. function littleSigma(x) {
  24057. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  24058. }
  24059. function littleSigmaPrime(x) {
  24060. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  24061. }
  24062. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  24063. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  24064. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  24065. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  24066. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  24067. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  24068. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  24069. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  24070. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  24071. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  24072. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  24073. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  24074. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  24075. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24076. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  24077. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  24078. function hash(data, offset, length) {
  24079. // initial hash values
  24080. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  24081. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  24082. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  24083. // pre-processing
  24084. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  24085. var padded = new Uint8Array(paddedLength);
  24086. var i, j, n;
  24087. for (i = 0; i < length; ++i) {
  24088. padded[i] = data[offset++];
  24089. }
  24090. padded[i++] = 0x80;
  24091. n = paddedLength - 8;
  24092. while (i < n) {
  24093. padded[i++] = 0;
  24094. }
  24095. padded[i++] = 0;
  24096. padded[i++] = 0;
  24097. padded[i++] = 0;
  24098. padded[i++] = (length >>> 29) & 0xFF;
  24099. padded[i++] = (length >> 21) & 0xFF;
  24100. padded[i++] = (length >> 13) & 0xFF;
  24101. padded[i++] = (length >> 5) & 0xFF;
  24102. padded[i++] = (length << 3) & 0xFF;
  24103. var w = new Uint32Array(64);
  24104. // for each 512 bit block
  24105. for (i = 0; i < paddedLength;) {
  24106. for (j = 0; j < 16; ++j) {
  24107. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  24108. (padded[i + 2] << 8) | (padded[i + 3]));
  24109. i += 4;
  24110. }
  24111. for (j = 16; j < 64; ++j) {
  24112. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  24113. littleSigma(w[j - 15]) + w[j - 16] | 0;
  24114. }
  24115. var a = h0, b = h1, c = h2, d = h3, e = h4,
  24116. f = h5, g = h6, h = h7, t1, t2;
  24117. for (j = 0; j < 64; ++j) {
  24118. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  24119. t2 = sigma(a) + maj(a, b, c);
  24120. h = g;
  24121. g = f;
  24122. f = e;
  24123. e = (d + t1) | 0;
  24124. d = c;
  24125. c = b;
  24126. b = a;
  24127. a = (t1 + t2) | 0;
  24128. }
  24129. h0 = (h0 + a) | 0;
  24130. h1 = (h1 + b) | 0;
  24131. h2 = (h2 + c) | 0;
  24132. h3 = (h3 + d) | 0;
  24133. h4 = (h4 + e) | 0;
  24134. h5 = (h5 + f) | 0;
  24135. h6 = (h6 + g) | 0;
  24136. h7 = (h7 + h) | 0;
  24137. }
  24138. return new Uint8Array([
  24139. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  24140. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  24141. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  24142. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  24143. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  24144. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  24145. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  24146. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  24147. ]);
  24148. }
  24149. return hash;
  24150. })();
  24151. var calculateSHA512 = (function calculateSHA512Closure() {
  24152. function ch(result, x, y, z, tmp) {
  24153. result.assign(x);
  24154. result.and(y);
  24155. tmp.assign(x);
  24156. tmp.not();
  24157. tmp.and(z);
  24158. result.xor(tmp);
  24159. }
  24160. function maj(result, x, y, z, tmp) {
  24161. result.assign(x);
  24162. result.and(y);
  24163. tmp.assign(x);
  24164. tmp.and(z);
  24165. result.xor(tmp);
  24166. tmp.assign(y);
  24167. tmp.and(z);
  24168. result.xor(tmp);
  24169. }
  24170. function sigma(result, x, tmp) {
  24171. result.assign(x);
  24172. result.rotateRight(28);
  24173. tmp.assign(x);
  24174. tmp.rotateRight(34);
  24175. result.xor(tmp);
  24176. tmp.assign(x);
  24177. tmp.rotateRight(39);
  24178. result.xor(tmp);
  24179. }
  24180. function sigmaPrime(result, x, tmp) {
  24181. result.assign(x);
  24182. result.rotateRight(14);
  24183. tmp.assign(x);
  24184. tmp.rotateRight(18);
  24185. result.xor(tmp);
  24186. tmp.assign(x);
  24187. tmp.rotateRight(41);
  24188. result.xor(tmp);
  24189. }
  24190. function littleSigma(result, x, tmp) {
  24191. result.assign(x);
  24192. result.rotateRight(1);
  24193. tmp.assign(x);
  24194. tmp.rotateRight(8);
  24195. result.xor(tmp);
  24196. tmp.assign(x);
  24197. tmp.shiftRight(7);
  24198. result.xor(tmp);
  24199. }
  24200. function littleSigmaPrime(result, x, tmp) {
  24201. result.assign(x);
  24202. result.rotateRight(19);
  24203. tmp.assign(x);
  24204. tmp.rotateRight(61);
  24205. result.xor(tmp);
  24206. tmp.assign(x);
  24207. tmp.shiftRight(6);
  24208. result.xor(tmp);
  24209. }
  24210. var k = [
  24211. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  24212. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  24213. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  24214. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  24215. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  24216. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  24217. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  24218. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  24219. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  24220. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  24221. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  24222. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  24223. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  24224. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  24225. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  24226. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  24227. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  24228. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  24229. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  24230. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  24231. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  24232. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  24233. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  24234. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  24235. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  24236. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  24237. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  24238. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  24239. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  24240. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  24241. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  24242. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  24243. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  24244. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  24245. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  24246. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  24247. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  24248. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  24249. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  24250. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  24251. function hash(data, offset, length, mode384) {
  24252. mode384 = !!mode384;
  24253. // initial hash values
  24254. var h0, h1, h2, h3, h4, h5, h6, h7;
  24255. if (!mode384) {
  24256. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  24257. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  24258. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  24259. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  24260. h4 = new Word64(0x510e527f, 0xade682d1);
  24261. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  24262. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  24263. h7 = new Word64(0x5be0cd19, 0x137e2179);
  24264. }
  24265. else {
  24266. // SHA384 is exactly the same
  24267. // except with different starting values and a trimmed result
  24268. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  24269. h1 = new Word64(0x629a292a, 0x367cd507);
  24270. h2 = new Word64(0x9159015a, 0x3070dd17);
  24271. h3 = new Word64(0x152fecd8, 0xf70e5939);
  24272. h4 = new Word64(0x67332667, 0xffc00b31);
  24273. h5 = new Word64(0x8eb44a87, 0x68581511);
  24274. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  24275. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  24276. }
  24277. // pre-processing
  24278. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  24279. var padded = new Uint8Array(paddedLength);
  24280. var i, j, n;
  24281. for (i = 0; i < length; ++i) {
  24282. padded[i] = data[offset++];
  24283. }
  24284. padded[i++] = 0x80;
  24285. n = paddedLength - 16;
  24286. while (i < n) {
  24287. padded[i++] = 0;
  24288. }
  24289. padded[i++] = 0;
  24290. padded[i++] = 0;
  24291. padded[i++] = 0;
  24292. padded[i++] = 0;
  24293. padded[i++] = 0;
  24294. padded[i++] = 0;
  24295. padded[i++] = 0;
  24296. padded[i++] = 0;
  24297. padded[i++] = 0;
  24298. padded[i++] = 0;
  24299. padded[i++] = 0;
  24300. padded[i++] = (length >>> 29) & 0xFF;
  24301. padded[i++] = (length >> 21) & 0xFF;
  24302. padded[i++] = (length >> 13) & 0xFF;
  24303. padded[i++] = (length >> 5) & 0xFF;
  24304. padded[i++] = (length << 3) & 0xFF;
  24305. var w = new Array(80);
  24306. for (i = 0; i < 80; i++) {
  24307. w[i] = new Word64(0, 0);
  24308. }
  24309. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  24310. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  24311. var g = new Word64(0, 0), h = new Word64(0, 0);
  24312. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  24313. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  24314. // for each 1024 bit block
  24315. for (i = 0; i < paddedLength;) {
  24316. for (j = 0; j < 16; ++j) {
  24317. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  24318. (padded[i + 2] << 8) | (padded[i + 3]);
  24319. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  24320. (padded[i + 6]) << 8 | (padded[i + 7]);
  24321. i += 8;
  24322. }
  24323. for (j = 16; j < 80; ++j) {
  24324. tmp3 = w[j];
  24325. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  24326. tmp3.add(w[j - 7]);
  24327. littleSigma(tmp1, w[j - 15], tmp2);
  24328. tmp3.add(tmp1);
  24329. tmp3.add(w[j - 16]);
  24330. }
  24331. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  24332. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  24333. for (j = 0; j < 80; ++j) {
  24334. t1.assign(h);
  24335. sigmaPrime(tmp1, e, tmp2);
  24336. t1.add(tmp1);
  24337. ch(tmp1, e, f, g, tmp2);
  24338. t1.add(tmp1);
  24339. t1.add(k[j]);
  24340. t1.add(w[j]);
  24341. sigma(t2, a, tmp2);
  24342. maj(tmp1, a, b, c, tmp2);
  24343. t2.add(tmp1);
  24344. tmp3 = h;
  24345. h = g;
  24346. g = f;
  24347. f = e;
  24348. d.add(t1);
  24349. e = d;
  24350. d = c;
  24351. c = b;
  24352. b = a;
  24353. tmp3.assign(t1);
  24354. tmp3.add(t2);
  24355. a = tmp3;
  24356. }
  24357. h0.add(a);
  24358. h1.add(b);
  24359. h2.add(c);
  24360. h3.add(d);
  24361. h4.add(e);
  24362. h5.add(f);
  24363. h6.add(g);
  24364. h7.add(h);
  24365. }
  24366. var result;
  24367. if (!mode384) {
  24368. result = new Uint8Array(64);
  24369. h0.copyTo(result,0);
  24370. h1.copyTo(result,8);
  24371. h2.copyTo(result,16);
  24372. h3.copyTo(result,24);
  24373. h4.copyTo(result,32);
  24374. h5.copyTo(result,40);
  24375. h6.copyTo(result,48);
  24376. h7.copyTo(result,56);
  24377. }
  24378. else {
  24379. result = new Uint8Array(48);
  24380. h0.copyTo(result,0);
  24381. h1.copyTo(result,8);
  24382. h2.copyTo(result,16);
  24383. h3.copyTo(result,24);
  24384. h4.copyTo(result,32);
  24385. h5.copyTo(result,40);
  24386. }
  24387. return result;
  24388. }
  24389. return hash;
  24390. })();
  24391. var calculateSHA384 = (function calculateSHA384Closure() {
  24392. function hash(data, offset, length) {
  24393. return calculateSHA512(data, offset, length, true);
  24394. }
  24395. return hash;
  24396. })();
  24397. var NullCipher = (function NullCipherClosure() {
  24398. function NullCipher() {
  24399. }
  24400. NullCipher.prototype = {
  24401. decryptBlock: function NullCipher_decryptBlock(data) {
  24402. return data;
  24403. }
  24404. };
  24405. return NullCipher;
  24406. })();
  24407. var AES128Cipher = (function AES128CipherClosure() {
  24408. var rcon = new Uint8Array([
  24409. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24410. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24411. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24412. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24413. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24414. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24415. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24416. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24417. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24418. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24419. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24420. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24421. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24422. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24423. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24424. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24425. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24426. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24427. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24428. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24429. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24430. 0x74, 0xe8, 0xcb, 0x8d]);
  24431. var s = new Uint8Array([
  24432. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24433. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24434. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24435. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24436. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24437. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24438. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24439. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24440. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24441. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24442. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24443. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24444. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24445. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24446. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24447. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24448. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24449. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24450. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24451. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24452. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24453. 0xb0, 0x54, 0xbb, 0x16]);
  24454. var inv_s = new Uint8Array([
  24455. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24456. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24457. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24458. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24459. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24460. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24461. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24462. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24463. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24464. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24465. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24466. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24467. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24468. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24469. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24470. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24471. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24472. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24473. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24474. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24475. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24476. 0x55, 0x21, 0x0c, 0x7d]);
  24477. var mixCol = new Uint8Array(256);
  24478. for (var i = 0; i < 256; i++) {
  24479. if (i < 128) {
  24480. mixCol[i] = i << 1;
  24481. } else {
  24482. mixCol[i] = (i << 1) ^ 0x1b;
  24483. }
  24484. }
  24485. var mix = new Uint32Array([
  24486. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24487. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24488. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24489. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24490. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24491. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24492. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24493. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24494. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24495. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24496. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24497. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24498. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24499. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24500. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24501. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24502. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24503. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24504. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24505. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24506. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24507. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24508. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24509. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24510. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24511. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24512. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24513. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24514. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24515. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24516. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24517. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24518. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24519. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24520. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24521. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24522. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24523. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24524. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24525. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24526. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24527. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24528. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24529. function expandKey128(cipherKey) {
  24530. var b = 176, result = new Uint8Array(b);
  24531. result.set(cipherKey);
  24532. for (var j = 16, i = 1; j < b; ++i) {
  24533. // RotWord
  24534. var t1 = result[j - 3], t2 = result[j - 2],
  24535. t3 = result[j - 1], t4 = result[j - 4];
  24536. // SubWord
  24537. t1 = s[t1];
  24538. t2 = s[t2];
  24539. t3 = s[t3];
  24540. t4 = s[t4];
  24541. // Rcon
  24542. t1 = t1 ^ rcon[i];
  24543. for (var n = 0; n < 4; ++n) {
  24544. result[j] = (t1 ^= result[j - 16]);
  24545. j++;
  24546. result[j] = (t2 ^= result[j - 16]);
  24547. j++;
  24548. result[j] = (t3 ^= result[j - 16]);
  24549. j++;
  24550. result[j] = (t4 ^= result[j - 16]);
  24551. j++;
  24552. }
  24553. }
  24554. return result;
  24555. }
  24556. function decrypt128(input, key) {
  24557. var state = new Uint8Array(16);
  24558. state.set(input);
  24559. var i, j, k;
  24560. var t, u, v;
  24561. // AddRoundKey
  24562. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24563. state[j] ^= key[k];
  24564. }
  24565. for (i = 9; i >= 1; --i) {
  24566. // InvShiftRows
  24567. t = state[13];
  24568. state[13] = state[9];
  24569. state[9] = state[5];
  24570. state[5] = state[1];
  24571. state[1] = t;
  24572. t = state[14];
  24573. u = state[10];
  24574. state[14] = state[6];
  24575. state[10] = state[2];
  24576. state[6] = t;
  24577. state[2] = u;
  24578. t = state[15];
  24579. u = state[11];
  24580. v = state[7];
  24581. state[15] = state[3];
  24582. state[11] = t;
  24583. state[7] = u;
  24584. state[3] = v;
  24585. // InvSubBytes
  24586. for (j = 0; j < 16; ++j) {
  24587. state[j] = inv_s[state[j]];
  24588. }
  24589. // AddRoundKey
  24590. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24591. state[j] ^= key[k];
  24592. }
  24593. // InvMixColumns
  24594. for (j = 0; j < 16; j += 4) {
  24595. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24596. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24597. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24598. (s3 >>> 24) ^ (s3 << 8));
  24599. state[j] = (t >>> 24) & 0xFF;
  24600. state[j + 1] = (t >> 16) & 0xFF;
  24601. state[j + 2] = (t >> 8) & 0xFF;
  24602. state[j + 3] = t & 0xFF;
  24603. }
  24604. }
  24605. // InvShiftRows
  24606. t = state[13];
  24607. state[13] = state[9];
  24608. state[9] = state[5];
  24609. state[5] = state[1];
  24610. state[1] = t;
  24611. t = state[14];
  24612. u = state[10];
  24613. state[14] = state[6];
  24614. state[10] = state[2];
  24615. state[6] = t;
  24616. state[2] = u;
  24617. t = state[15];
  24618. u = state[11];
  24619. v = state[7];
  24620. state[15] = state[3];
  24621. state[11] = t;
  24622. state[7] = u;
  24623. state[3] = v;
  24624. for (j = 0; j < 16; ++j) {
  24625. // InvSubBytes
  24626. state[j] = inv_s[state[j]];
  24627. // AddRoundKey
  24628. state[j] ^= key[j];
  24629. }
  24630. return state;
  24631. }
  24632. function encrypt128(input, key) {
  24633. var t, u, v, k;
  24634. var state = new Uint8Array(16);
  24635. state.set(input);
  24636. for (j = 0; j < 16; ++j) {
  24637. // AddRoundKey
  24638. state[j] ^= key[j];
  24639. }
  24640. for (i = 1; i < 10; i++) {
  24641. //SubBytes
  24642. for (j = 0; j < 16; ++j) {
  24643. state[j] = s[state[j]];
  24644. }
  24645. //ShiftRows
  24646. v = state[1];
  24647. state[1] = state[5];
  24648. state[5] = state[9];
  24649. state[9] = state[13];
  24650. state[13] = v;
  24651. v = state[2];
  24652. u = state[6];
  24653. state[2] = state[10];
  24654. state[6] = state[14];
  24655. state[10] = v;
  24656. state[14] = u;
  24657. v = state[3];
  24658. u = state[7];
  24659. t = state[11];
  24660. state[3] = state[15];
  24661. state[7] = v;
  24662. state[11] = u;
  24663. state[15] = t;
  24664. //MixColumns
  24665. for (var j = 0; j < 16; j += 4) {
  24666. var s0 = state[j + 0], s1 = state[j + 1];
  24667. var s2 = state[j + 2], s3 = state[j + 3];
  24668. t = s0 ^ s1 ^ s2 ^ s3;
  24669. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24670. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24671. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24672. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24673. }
  24674. //AddRoundKey
  24675. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24676. state[j] ^= key[k];
  24677. }
  24678. }
  24679. //SubBytes
  24680. for (j = 0; j < 16; ++j) {
  24681. state[j] = s[state[j]];
  24682. }
  24683. //ShiftRows
  24684. v = state[1];
  24685. state[1] = state[5];
  24686. state[5] = state[9];
  24687. state[9] = state[13];
  24688. state[13] = v;
  24689. v = state[2];
  24690. u = state[6];
  24691. state[2] = state[10];
  24692. state[6] = state[14];
  24693. state[10] = v;
  24694. state[14] = u;
  24695. v = state[3];
  24696. u = state[7];
  24697. t = state[11];
  24698. state[3] = state[15];
  24699. state[7] = v;
  24700. state[11] = u;
  24701. state[15] = t;
  24702. //AddRoundKey
  24703. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24704. state[j] ^= key[k];
  24705. }
  24706. return state;
  24707. }
  24708. function AES128Cipher(key) {
  24709. this.key = expandKey128(key);
  24710. this.buffer = new Uint8Array(16);
  24711. this.bufferPosition = 0;
  24712. }
  24713. function decryptBlock2(data, finalize) {
  24714. var i, j, ii, sourceLength = data.length,
  24715. buffer = this.buffer, bufferLength = this.bufferPosition,
  24716. result = [], iv = this.iv;
  24717. for (i = 0; i < sourceLength; ++i) {
  24718. buffer[bufferLength] = data[i];
  24719. ++bufferLength;
  24720. if (bufferLength < 16) {
  24721. continue;
  24722. }
  24723. // buffer is full, decrypting
  24724. var plain = decrypt128(buffer, this.key);
  24725. // xor-ing the IV vector to get plain text
  24726. for (j = 0; j < 16; ++j) {
  24727. plain[j] ^= iv[j];
  24728. }
  24729. iv = buffer;
  24730. result.push(plain);
  24731. buffer = new Uint8Array(16);
  24732. bufferLength = 0;
  24733. }
  24734. // saving incomplete buffer
  24735. this.buffer = buffer;
  24736. this.bufferLength = bufferLength;
  24737. this.iv = iv;
  24738. if (result.length === 0) {
  24739. return new Uint8Array([]);
  24740. }
  24741. // combining plain text blocks into one
  24742. var outputLength = 16 * result.length;
  24743. if (finalize) {
  24744. // undo a padding that is described in RFC 2898
  24745. var lastBlock = result[result.length - 1];
  24746. var psLen = lastBlock[15];
  24747. if (psLen <= 16) {
  24748. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24749. if (lastBlock[i] !== psLen) {
  24750. // Invalid padding, assume that the block has no padding.
  24751. psLen = 0;
  24752. break;
  24753. }
  24754. }
  24755. outputLength -= psLen;
  24756. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24757. }
  24758. }
  24759. var output = new Uint8Array(outputLength);
  24760. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24761. output.set(result[i], j);
  24762. }
  24763. return output;
  24764. }
  24765. AES128Cipher.prototype = {
  24766. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  24767. var i, sourceLength = data.length;
  24768. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24769. // waiting for IV values -- they are at the start of the stream
  24770. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  24771. buffer[bufferLength] = data[i];
  24772. }
  24773. if (bufferLength < 16) {
  24774. // need more data
  24775. this.bufferLength = bufferLength;
  24776. return new Uint8Array([]);
  24777. }
  24778. this.iv = buffer;
  24779. this.buffer = new Uint8Array(16);
  24780. this.bufferLength = 0;
  24781. // starting decryption
  24782. this.decryptBlock = decryptBlock2;
  24783. return this.decryptBlock(data.subarray(16), finalize);
  24784. },
  24785. encrypt: function AES128Cipher_encrypt(data, iv) {
  24786. var i, j, ii, sourceLength = data.length,
  24787. buffer = this.buffer, bufferLength = this.bufferPosition,
  24788. result = [];
  24789. if (!iv) {
  24790. iv = new Uint8Array(16);
  24791. }
  24792. for (i = 0; i < sourceLength; ++i) {
  24793. buffer[bufferLength] = data[i];
  24794. ++bufferLength;
  24795. if (bufferLength < 16) {
  24796. continue;
  24797. }
  24798. for (j = 0; j < 16; ++j) {
  24799. buffer[j] ^= iv[j];
  24800. }
  24801. // buffer is full, encrypting
  24802. var cipher = encrypt128(buffer, this.key);
  24803. iv = cipher;
  24804. result.push(cipher);
  24805. buffer = new Uint8Array(16);
  24806. bufferLength = 0;
  24807. }
  24808. // saving incomplete buffer
  24809. this.buffer = buffer;
  24810. this.bufferLength = bufferLength;
  24811. this.iv = iv;
  24812. if (result.length === 0) {
  24813. return new Uint8Array([]);
  24814. }
  24815. // combining plain text blocks into one
  24816. var outputLength = 16 * result.length;
  24817. var output = new Uint8Array(outputLength);
  24818. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24819. output.set(result[i], j);
  24820. }
  24821. return output;
  24822. }
  24823. };
  24824. return AES128Cipher;
  24825. })();
  24826. var AES256Cipher = (function AES256CipherClosure() {
  24827. var rcon = new Uint8Array([
  24828. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24829. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24830. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24831. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24832. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24833. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24834. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24835. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24836. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24837. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24838. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24839. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24840. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24841. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24842. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24843. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24844. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24845. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24846. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24847. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24848. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24849. 0x74, 0xe8, 0xcb, 0x8d]);
  24850. var s = new Uint8Array([
  24851. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24852. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24853. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24854. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24855. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24856. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24857. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24858. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24859. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24860. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24861. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24862. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24863. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24864. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24865. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24866. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24867. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24868. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24869. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24870. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24871. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24872. 0xb0, 0x54, 0xbb, 0x16]);
  24873. var inv_s = new Uint8Array([
  24874. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24875. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24876. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24877. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24878. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24879. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24880. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24881. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24882. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24883. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24884. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24885. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24886. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24887. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24888. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24889. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24890. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24891. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24892. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24893. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24894. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24895. 0x55, 0x21, 0x0c, 0x7d]);
  24896. var mixCol = new Uint8Array(256);
  24897. for (var i = 0; i < 256; i++) {
  24898. if (i < 128) {
  24899. mixCol[i] = i << 1;
  24900. } else {
  24901. mixCol[i] = (i << 1) ^ 0x1b;
  24902. }
  24903. }
  24904. var mix = new Uint32Array([
  24905. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24906. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24907. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24908. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24909. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24910. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24911. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24912. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24913. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24914. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24915. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24916. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24917. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24918. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24919. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24920. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24921. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24922. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24923. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24924. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24925. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24926. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24927. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24928. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24929. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24930. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24931. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24932. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24933. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24934. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24935. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24936. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24937. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24938. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24939. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24940. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24941. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24942. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24943. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24944. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24945. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24946. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24947. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24948. function expandKey256(cipherKey) {
  24949. var b = 240, result = new Uint8Array(b);
  24950. var r = 1;
  24951. result.set(cipherKey);
  24952. for (var j = 32, i = 1; j < b; ++i) {
  24953. if (j % 32 === 16) {
  24954. t1 = s[t1];
  24955. t2 = s[t2];
  24956. t3 = s[t3];
  24957. t4 = s[t4];
  24958. } else if (j % 32 === 0) {
  24959. // RotWord
  24960. var t1 = result[j - 3], t2 = result[j - 2],
  24961. t3 = result[j - 1], t4 = result[j - 4];
  24962. // SubWord
  24963. t1 = s[t1];
  24964. t2 = s[t2];
  24965. t3 = s[t3];
  24966. t4 = s[t4];
  24967. // Rcon
  24968. t1 = t1 ^ r;
  24969. if ((r <<= 1) >= 256) {
  24970. r = (r ^ 0x1b) & 0xFF;
  24971. }
  24972. }
  24973. for (var n = 0; n < 4; ++n) {
  24974. result[j] = (t1 ^= result[j - 32]);
  24975. j++;
  24976. result[j] = (t2 ^= result[j - 32]);
  24977. j++;
  24978. result[j] = (t3 ^= result[j - 32]);
  24979. j++;
  24980. result[j] = (t4 ^= result[j - 32]);
  24981. j++;
  24982. }
  24983. }
  24984. return result;
  24985. }
  24986. function decrypt256(input, key) {
  24987. var state = new Uint8Array(16);
  24988. state.set(input);
  24989. var i, j, k;
  24990. var t, u, v;
  24991. // AddRoundKey
  24992. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24993. state[j] ^= key[k];
  24994. }
  24995. for (i = 13; i >= 1; --i) {
  24996. // InvShiftRows
  24997. t = state[13];
  24998. state[13] = state[9];
  24999. state[9] = state[5];
  25000. state[5] = state[1];
  25001. state[1] = t;
  25002. t = state[14];
  25003. u = state[10];
  25004. state[14] = state[6];
  25005. state[10] = state[2];
  25006. state[6] = t;
  25007. state[2] = u;
  25008. t = state[15];
  25009. u = state[11];
  25010. v = state[7];
  25011. state[15] = state[3];
  25012. state[11] = t;
  25013. state[7] = u;
  25014. state[3] = v;
  25015. // InvSubBytes
  25016. for (j = 0; j < 16; ++j) {
  25017. state[j] = inv_s[state[j]];
  25018. }
  25019. // AddRoundKey
  25020. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25021. state[j] ^= key[k];
  25022. }
  25023. // InvMixColumns
  25024. for (j = 0; j < 16; j += 4) {
  25025. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25026. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25027. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25028. (s3 >>> 24) ^ (s3 << 8));
  25029. state[j] = (t >>> 24) & 0xFF;
  25030. state[j + 1] = (t >> 16) & 0xFF;
  25031. state[j + 2] = (t >> 8) & 0xFF;
  25032. state[j + 3] = t & 0xFF;
  25033. }
  25034. }
  25035. // InvShiftRows
  25036. t = state[13];
  25037. state[13] = state[9];
  25038. state[9] = state[5];
  25039. state[5] = state[1];
  25040. state[1] = t;
  25041. t = state[14];
  25042. u = state[10];
  25043. state[14] = state[6];
  25044. state[10] = state[2];
  25045. state[6] = t;
  25046. state[2] = u;
  25047. t = state[15];
  25048. u = state[11];
  25049. v = state[7];
  25050. state[15] = state[3];
  25051. state[11] = t;
  25052. state[7] = u;
  25053. state[3] = v;
  25054. for (j = 0; j < 16; ++j) {
  25055. // InvSubBytes
  25056. state[j] = inv_s[state[j]];
  25057. // AddRoundKey
  25058. state[j] ^= key[j];
  25059. }
  25060. return state;
  25061. }
  25062. function encrypt256(input, key) {
  25063. var t, u, v, k;
  25064. var state = new Uint8Array(16);
  25065. state.set(input);
  25066. for (j = 0; j < 16; ++j) {
  25067. // AddRoundKey
  25068. state[j] ^= key[j];
  25069. }
  25070. for (i = 1; i < 14; i++) {
  25071. //SubBytes
  25072. for (j = 0; j < 16; ++j) {
  25073. state[j] = s[state[j]];
  25074. }
  25075. //ShiftRows
  25076. v = state[1];
  25077. state[1] = state[5];
  25078. state[5] = state[9];
  25079. state[9] = state[13];
  25080. state[13] = v;
  25081. v = state[2];
  25082. u = state[6];
  25083. state[2] = state[10];
  25084. state[6] = state[14];
  25085. state[10] = v;
  25086. state[14] = u;
  25087. v = state[3];
  25088. u = state[7];
  25089. t = state[11];
  25090. state[3] = state[15];
  25091. state[7] = v;
  25092. state[11] = u;
  25093. state[15] = t;
  25094. //MixColumns
  25095. for (var j = 0; j < 16; j += 4) {
  25096. var s0 = state[j + 0], s1 = state[j + 1];
  25097. var s2 = state[j + 2], s3 = state[j + 3];
  25098. t = s0 ^ s1 ^ s2 ^ s3;
  25099. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25100. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25101. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25102. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25103. }
  25104. //AddRoundKey
  25105. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25106. state[j] ^= key[k];
  25107. }
  25108. }
  25109. //SubBytes
  25110. for (j = 0; j < 16; ++j) {
  25111. state[j] = s[state[j]];
  25112. }
  25113. //ShiftRows
  25114. v = state[1];
  25115. state[1] = state[5];
  25116. state[5] = state[9];
  25117. state[9] = state[13];
  25118. state[13] = v;
  25119. v = state[2];
  25120. u = state[6];
  25121. state[2] = state[10];
  25122. state[6] = state[14];
  25123. state[10] = v;
  25124. state[14] = u;
  25125. v = state[3];
  25126. u = state[7];
  25127. t = state[11];
  25128. state[3] = state[15];
  25129. state[7] = v;
  25130. state[11] = u;
  25131. state[15] = t;
  25132. //AddRoundKey
  25133. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25134. state[j] ^= key[k];
  25135. }
  25136. return state;
  25137. }
  25138. function AES256Cipher(key) {
  25139. this.key = expandKey256(key);
  25140. this.buffer = new Uint8Array(16);
  25141. this.bufferPosition = 0;
  25142. }
  25143. function decryptBlock2(data, finalize) {
  25144. var i, j, ii, sourceLength = data.length,
  25145. buffer = this.buffer, bufferLength = this.bufferPosition,
  25146. result = [], iv = this.iv;
  25147. for (i = 0; i < sourceLength; ++i) {
  25148. buffer[bufferLength] = data[i];
  25149. ++bufferLength;
  25150. if (bufferLength < 16) {
  25151. continue;
  25152. }
  25153. // buffer is full, decrypting
  25154. var plain = decrypt256(buffer, this.key);
  25155. // xor-ing the IV vector to get plain text
  25156. for (j = 0; j < 16; ++j) {
  25157. plain[j] ^= iv[j];
  25158. }
  25159. iv = buffer;
  25160. result.push(plain);
  25161. buffer = new Uint8Array(16);
  25162. bufferLength = 0;
  25163. }
  25164. // saving incomplete buffer
  25165. this.buffer = buffer;
  25166. this.bufferLength = bufferLength;
  25167. this.iv = iv;
  25168. if (result.length === 0) {
  25169. return new Uint8Array([]);
  25170. }
  25171. // combining plain text blocks into one
  25172. var outputLength = 16 * result.length;
  25173. if (finalize) {
  25174. // undo a padding that is described in RFC 2898
  25175. var lastBlock = result[result.length - 1];
  25176. var psLen = lastBlock[15];
  25177. if (psLen <= 16) {
  25178. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25179. if (lastBlock[i] !== psLen) {
  25180. // Invalid padding, assume that the block has no padding.
  25181. psLen = 0;
  25182. break;
  25183. }
  25184. }
  25185. outputLength -= psLen;
  25186. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25187. }
  25188. }
  25189. var output = new Uint8Array(outputLength);
  25190. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25191. output.set(result[i], j);
  25192. }
  25193. return output;
  25194. }
  25195. AES256Cipher.prototype = {
  25196. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  25197. var i, sourceLength = data.length;
  25198. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25199. // if not supplied an IV wait for IV values
  25200. // they are at the start of the stream
  25201. if (iv) {
  25202. this.iv = iv;
  25203. } else {
  25204. for (i = 0; bufferLength < 16 &&
  25205. i < sourceLength; ++i, ++bufferLength) {
  25206. buffer[bufferLength] = data[i];
  25207. }
  25208. if (bufferLength < 16) {
  25209. //need more data
  25210. this.bufferLength = bufferLength;
  25211. return new Uint8Array([]);
  25212. }
  25213. this.iv = buffer;
  25214. data = data.subarray(16);
  25215. }
  25216. this.buffer = new Uint8Array(16);
  25217. this.bufferLength = 0;
  25218. // starting decryption
  25219. this.decryptBlock = decryptBlock2;
  25220. return this.decryptBlock(data, finalize);
  25221. },
  25222. encrypt: function AES256Cipher_encrypt(data, iv) {
  25223. var i, j, ii, sourceLength = data.length,
  25224. buffer = this.buffer, bufferLength = this.bufferPosition,
  25225. result = [];
  25226. if (!iv) {
  25227. iv = new Uint8Array(16);
  25228. }
  25229. for (i = 0; i < sourceLength; ++i) {
  25230. buffer[bufferLength] = data[i];
  25231. ++bufferLength;
  25232. if (bufferLength < 16) {
  25233. continue;
  25234. }
  25235. for (j = 0; j < 16; ++j) {
  25236. buffer[j] ^= iv[j];
  25237. }
  25238. // buffer is full, encrypting
  25239. var cipher = encrypt256(buffer, this.key);
  25240. this.iv = cipher;
  25241. result.push(cipher);
  25242. buffer = new Uint8Array(16);
  25243. bufferLength = 0;
  25244. }
  25245. // saving incomplete buffer
  25246. this.buffer = buffer;
  25247. this.bufferLength = bufferLength;
  25248. this.iv = iv;
  25249. if (result.length === 0) {
  25250. return new Uint8Array([]);
  25251. }
  25252. // combining plain text blocks into one
  25253. var outputLength = 16 * result.length;
  25254. var output = new Uint8Array(outputLength);
  25255. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25256. output.set(result[i], j);
  25257. }
  25258. return output;
  25259. }
  25260. };
  25261. return AES256Cipher;
  25262. })();
  25263. var PDF17 = (function PDF17Closure() {
  25264. function compareByteArrays(array1, array2) {
  25265. if (array1.length !== array2.length) {
  25266. return false;
  25267. }
  25268. for (var i = 0; i < array1.length; i++) {
  25269. if (array1[i] !== array2[i]) {
  25270. return false;
  25271. }
  25272. }
  25273. return true;
  25274. }
  25275. function PDF17() {
  25276. }
  25277. PDF17.prototype = {
  25278. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  25279. ownerValidationSalt,
  25280. userBytes,
  25281. ownerPassword) {
  25282. var hashData = new Uint8Array(password.length + 56);
  25283. hashData.set(password, 0);
  25284. hashData.set(ownerValidationSalt, password.length);
  25285. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25286. var result = calculateSHA256(hashData, 0, hashData.length);
  25287. return compareByteArrays(result, ownerPassword);
  25288. },
  25289. checkUserPassword: function PDF17_checkUserPassword(password,
  25290. userValidationSalt,
  25291. userPassword) {
  25292. var hashData = new Uint8Array(password.length + 8);
  25293. hashData.set(password, 0);
  25294. hashData.set(userValidationSalt, password.length);
  25295. var result = calculateSHA256(hashData, 0, hashData.length);
  25296. return compareByteArrays(result, userPassword);
  25297. },
  25298. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  25299. ownerEncryption) {
  25300. var hashData = new Uint8Array(password.length + 56);
  25301. hashData.set(password, 0);
  25302. hashData.set(ownerKeySalt, password.length);
  25303. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25304. var key = calculateSHA256(hashData, 0, hashData.length);
  25305. var cipher = new AES256Cipher(key);
  25306. return cipher.decryptBlock(ownerEncryption,
  25307. false,
  25308. new Uint8Array(16));
  25309. },
  25310. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  25311. userEncryption) {
  25312. var hashData = new Uint8Array(password.length + 8);
  25313. hashData.set(password, 0);
  25314. hashData.set(userKeySalt, password.length);
  25315. //key is the decryption key for the UE string
  25316. var key = calculateSHA256(hashData, 0, hashData.length);
  25317. var cipher = new AES256Cipher(key);
  25318. return cipher.decryptBlock(userEncryption,
  25319. false,
  25320. new Uint8Array(16));
  25321. }
  25322. };
  25323. return PDF17;
  25324. })();
  25325. var PDF20 = (function PDF20Closure() {
  25326. function concatArrays(array1, array2) {
  25327. var t = new Uint8Array(array1.length + array2.length);
  25328. t.set(array1, 0);
  25329. t.set(array2, array1.length);
  25330. return t;
  25331. }
  25332. function calculatePDF20Hash(password, input, userBytes) {
  25333. //This refers to Algorithm 2.B as defined in ISO 32000-2
  25334. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  25335. var e = [0];
  25336. var i = 0;
  25337. while (i < 64 || e[e.length - 1] > i - 32) {
  25338. var arrayLength = password.length + k.length + userBytes.length;
  25339. var k1 = new Uint8Array(arrayLength * 64);
  25340. var array = concatArrays(password, k);
  25341. array = concatArrays(array, userBytes);
  25342. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  25343. k1.set(array, pos);
  25344. }
  25345. //AES128 CBC NO PADDING with
  25346. //first 16 bytes of k as the key and the second 16 as the iv.
  25347. var cipher = new AES128Cipher(k.subarray(0, 16));
  25348. e = cipher.encrypt(k1, k.subarray(16, 32));
  25349. //Now we have to take the first 16 bytes of an unsigned
  25350. //big endian integer... and compute the remainder
  25351. //modulo 3.... That is a fairly large number and
  25352. //JavaScript isn't going to handle that well...
  25353. //So we're using a trick that allows us to perform
  25354. //modulo math byte by byte
  25355. var remainder = 0;
  25356. for (var z = 0; z < 16; z++) {
  25357. remainder *= (256 % 3);
  25358. remainder %= 3;
  25359. remainder += ((e[z] >>> 0) % 3);
  25360. remainder %= 3;
  25361. }
  25362. if (remainder === 0) {
  25363. k = calculateSHA256(e, 0, e.length);
  25364. }
  25365. else if (remainder === 1) {
  25366. k = calculateSHA384(e, 0, e.length);
  25367. }
  25368. else if (remainder === 2) {
  25369. k = calculateSHA512(e, 0, e.length);
  25370. }
  25371. i++;
  25372. }
  25373. return k.subarray(0, 32);
  25374. }
  25375. function PDF20() {
  25376. }
  25377. function compareByteArrays(array1, array2) {
  25378. if (array1.length !== array2.length) {
  25379. return false;
  25380. }
  25381. for (var i = 0; i < array1.length; i++) {
  25382. if (array1[i] !== array2[i]) {
  25383. return false;
  25384. }
  25385. }
  25386. return true;
  25387. }
  25388. PDF20.prototype = {
  25389. hash: function PDF20_hash(password, concatBytes, userBytes) {
  25390. return calculatePDF20Hash(password, concatBytes, userBytes);
  25391. },
  25392. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  25393. ownerValidationSalt,
  25394. userBytes,
  25395. ownerPassword) {
  25396. var hashData = new Uint8Array(password.length + 56);
  25397. hashData.set(password, 0);
  25398. hashData.set(ownerValidationSalt, password.length);
  25399. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25400. var result = calculatePDF20Hash(password, hashData, userBytes);
  25401. return compareByteArrays(result, ownerPassword);
  25402. },
  25403. checkUserPassword: function PDF20_checkUserPassword(password,
  25404. userValidationSalt,
  25405. userPassword) {
  25406. var hashData = new Uint8Array(password.length + 8);
  25407. hashData.set(password, 0);
  25408. hashData.set(userValidationSalt, password.length);
  25409. var result = calculatePDF20Hash(password, hashData, []);
  25410. return compareByteArrays(result, userPassword);
  25411. },
  25412. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  25413. ownerEncryption) {
  25414. var hashData = new Uint8Array(password.length + 56);
  25415. hashData.set(password, 0);
  25416. hashData.set(ownerKeySalt, password.length);
  25417. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25418. var key = calculatePDF20Hash(password, hashData, userBytes);
  25419. var cipher = new AES256Cipher(key);
  25420. return cipher.decryptBlock(ownerEncryption,
  25421. false,
  25422. new Uint8Array(16));
  25423. },
  25424. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  25425. userEncryption) {
  25426. var hashData = new Uint8Array(password.length + 8);
  25427. hashData.set(password, 0);
  25428. hashData.set(userKeySalt, password.length);
  25429. //key is the decryption key for the UE string
  25430. var key = calculatePDF20Hash(password, hashData, []);
  25431. var cipher = new AES256Cipher(key);
  25432. return cipher.decryptBlock(userEncryption,
  25433. false,
  25434. new Uint8Array(16));
  25435. }
  25436. };
  25437. return PDF20;
  25438. })();
  25439. var CipherTransform = (function CipherTransformClosure() {
  25440. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  25441. this.stringCipherConstructor = stringCipherConstructor;
  25442. this.streamCipherConstructor = streamCipherConstructor;
  25443. }
  25444. CipherTransform.prototype = {
  25445. createStream: function CipherTransform_createStream(stream, length) {
  25446. var cipher = new this.streamCipherConstructor();
  25447. return new DecryptStream(stream, length,
  25448. function cipherTransformDecryptStream(data, finalize) {
  25449. return cipher.decryptBlock(data, finalize);
  25450. }
  25451. );
  25452. },
  25453. decryptString: function CipherTransform_decryptString(s) {
  25454. var cipher = new this.stringCipherConstructor();
  25455. var data = stringToBytes(s);
  25456. data = cipher.decryptBlock(data, true);
  25457. return bytesToString(data);
  25458. }
  25459. };
  25460. return CipherTransform;
  25461. })();
  25462. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  25463. var defaultPasswordBytes = new Uint8Array([
  25464. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  25465. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  25466. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  25467. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  25468. function createEncryptionKey20(revision, password, ownerPassword,
  25469. ownerValidationSalt, ownerKeySalt, uBytes,
  25470. userPassword, userValidationSalt, userKeySalt,
  25471. ownerEncryption, userEncryption, perms) {
  25472. if (password) {
  25473. var passwordLength = Math.min(127, password.length);
  25474. password = password.subarray(0, passwordLength);
  25475. } else {
  25476. password = [];
  25477. }
  25478. var pdfAlgorithm;
  25479. if (revision === 6) {
  25480. pdfAlgorithm = new PDF20();
  25481. } else {
  25482. pdfAlgorithm = new PDF17();
  25483. }
  25484. if (pdfAlgorithm) {
  25485. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  25486. userPassword)) {
  25487. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  25488. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  25489. ownerValidationSalt,
  25490. uBytes,
  25491. ownerPassword)) {
  25492. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  25493. ownerEncryption);
  25494. }
  25495. }
  25496. return null;
  25497. }
  25498. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  25499. flags, revision, keyLength, encryptMetadata) {
  25500. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  25501. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  25502. if (password) {
  25503. n = Math.min(32, password.length);
  25504. for (; i < n; ++i) {
  25505. hashData[i] = password[i];
  25506. }
  25507. }
  25508. j = 0;
  25509. while (i < 32) {
  25510. hashData[i++] = defaultPasswordBytes[j++];
  25511. }
  25512. // as now the padded password in the hashData[0..i]
  25513. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  25514. hashData[i++] = ownerPassword[j];
  25515. }
  25516. hashData[i++] = flags & 0xFF;
  25517. hashData[i++] = (flags >> 8) & 0xFF;
  25518. hashData[i++] = (flags >> 16) & 0xFF;
  25519. hashData[i++] = (flags >>> 24) & 0xFF;
  25520. for (j = 0, n = fileId.length; j < n; ++j) {
  25521. hashData[i++] = fileId[j];
  25522. }
  25523. if (revision >= 4 && !encryptMetadata) {
  25524. hashData[i++] = 0xFF;
  25525. hashData[i++] = 0xFF;
  25526. hashData[i++] = 0xFF;
  25527. hashData[i++] = 0xFF;
  25528. }
  25529. var hash = calculateMD5(hashData, 0, i);
  25530. var keyLengthInBytes = keyLength >> 3;
  25531. if (revision >= 3) {
  25532. for (j = 0; j < 50; ++j) {
  25533. hash = calculateMD5(hash, 0, keyLengthInBytes);
  25534. }
  25535. }
  25536. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  25537. var cipher, checkData;
  25538. if (revision >= 3) {
  25539. for (i = 0; i < 32; ++i) {
  25540. hashData[i] = defaultPasswordBytes[i];
  25541. }
  25542. for (j = 0, n = fileId.length; j < n; ++j) {
  25543. hashData[i++] = fileId[j];
  25544. }
  25545. cipher = new ARCFourCipher(encryptionKey);
  25546. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  25547. n = encryptionKey.length;
  25548. var derivedKey = new Uint8Array(n), k;
  25549. for (j = 1; j <= 19; ++j) {
  25550. for (k = 0; k < n; ++k) {
  25551. derivedKey[k] = encryptionKey[k] ^ j;
  25552. }
  25553. cipher = new ARCFourCipher(derivedKey);
  25554. checkData = cipher.encryptBlock(checkData);
  25555. }
  25556. for (j = 0, n = checkData.length; j < n; ++j) {
  25557. if (userPassword[j] !== checkData[j]) {
  25558. return null;
  25559. }
  25560. }
  25561. } else {
  25562. cipher = new ARCFourCipher(encryptionKey);
  25563. checkData = cipher.encryptBlock(defaultPasswordBytes);
  25564. for (j = 0, n = checkData.length; j < n; ++j) {
  25565. if (userPassword[j] !== checkData[j]) {
  25566. return null;
  25567. }
  25568. }
  25569. }
  25570. return encryptionKey;
  25571. }
  25572. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  25573. var hashData = new Uint8Array(32), i = 0, j, n;
  25574. n = Math.min(32, password.length);
  25575. for (; i < n; ++i) {
  25576. hashData[i] = password[i];
  25577. }
  25578. j = 0;
  25579. while (i < 32) {
  25580. hashData[i++] = defaultPasswordBytes[j++];
  25581. }
  25582. var hash = calculateMD5(hashData, 0, i);
  25583. var keyLengthInBytes = keyLength >> 3;
  25584. if (revision >= 3) {
  25585. for (j = 0; j < 50; ++j) {
  25586. hash = calculateMD5(hash, 0, hash.length);
  25587. }
  25588. }
  25589. var cipher, userPassword;
  25590. if (revision >= 3) {
  25591. userPassword = ownerPassword;
  25592. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  25593. for (j = 19; j >= 0; j--) {
  25594. for (k = 0; k < keyLengthInBytes; ++k) {
  25595. derivedKey[k] = hash[k] ^ j;
  25596. }
  25597. cipher = new ARCFourCipher(derivedKey);
  25598. userPassword = cipher.encryptBlock(userPassword);
  25599. }
  25600. } else {
  25601. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  25602. userPassword = cipher.encryptBlock(ownerPassword);
  25603. }
  25604. return userPassword;
  25605. }
  25606. var identityName = Name.get('Identity');
  25607. function CipherTransformFactory(dict, fileId, password) {
  25608. var filter = dict.get('Filter');
  25609. if (!isName(filter) || filter.name !== 'Standard') {
  25610. error('unknown encryption method');
  25611. }
  25612. this.dict = dict;
  25613. var algorithm = dict.get('V');
  25614. if (!isInt(algorithm) ||
  25615. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  25616. algorithm !== 5)) {
  25617. error('unsupported encryption algorithm');
  25618. }
  25619. this.algorithm = algorithm;
  25620. var keyLength = dict.get('Length') || 40;
  25621. if (!isInt(keyLength) ||
  25622. keyLength < 40 || (keyLength % 8) !== 0) {
  25623. error('invalid key length');
  25624. }
  25625. // prepare keys
  25626. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  25627. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  25628. var flags = dict.get('P');
  25629. var revision = dict.get('R');
  25630. // meaningful when V is 4 or 5
  25631. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  25632. dict.get('EncryptMetadata') !== false);
  25633. this.encryptMetadata = encryptMetadata;
  25634. var fileIdBytes = stringToBytes(fileId);
  25635. var passwordBytes;
  25636. if (password) {
  25637. if (revision === 6) {
  25638. try {
  25639. password = utf8StringToString(password);
  25640. } catch (ex) {
  25641. warn('CipherTransformFactory: ' +
  25642. 'Unable to convert UTF8 encoded password.');
  25643. }
  25644. }
  25645. passwordBytes = stringToBytes(password);
  25646. }
  25647. var encryptionKey;
  25648. if (algorithm !== 5) {
  25649. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  25650. ownerPassword, userPassword, flags,
  25651. revision, keyLength, encryptMetadata);
  25652. }
  25653. else {
  25654. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  25655. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  25656. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  25657. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  25658. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  25659. var ownerEncryption = stringToBytes(dict.get('OE'));
  25660. var userEncryption = stringToBytes(dict.get('UE'));
  25661. var perms = stringToBytes(dict.get('Perms'));
  25662. encryptionKey =
  25663. createEncryptionKey20(revision, passwordBytes,
  25664. ownerPassword, ownerValidationSalt,
  25665. ownerKeySalt, uBytes,
  25666. userPassword, userValidationSalt,
  25667. userKeySalt, ownerEncryption,
  25668. userEncryption, perms);
  25669. }
  25670. if (!encryptionKey && !password) {
  25671. throw new PasswordException('No password given',
  25672. PasswordResponses.NEED_PASSWORD);
  25673. } else if (!encryptionKey && password) {
  25674. // Attempting use the password as an owner password
  25675. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  25676. revision, keyLength);
  25677. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  25678. ownerPassword, userPassword, flags,
  25679. revision, keyLength, encryptMetadata);
  25680. }
  25681. if (!encryptionKey) {
  25682. throw new PasswordException('Incorrect Password',
  25683. PasswordResponses.INCORRECT_PASSWORD);
  25684. }
  25685. this.encryptionKey = encryptionKey;
  25686. if (algorithm >= 4) {
  25687. this.cf = dict.get('CF');
  25688. this.stmf = dict.get('StmF') || identityName;
  25689. this.strf = dict.get('StrF') || identityName;
  25690. this.eff = dict.get('EFF') || this.stmf;
  25691. }
  25692. }
  25693. function buildObjectKey(num, gen, encryptionKey, isAes) {
  25694. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  25695. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  25696. key[i] = encryptionKey[i];
  25697. }
  25698. key[i++] = num & 0xFF;
  25699. key[i++] = (num >> 8) & 0xFF;
  25700. key[i++] = (num >> 16) & 0xFF;
  25701. key[i++] = gen & 0xFF;
  25702. key[i++] = (gen >> 8) & 0xFF;
  25703. if (isAes) {
  25704. key[i++] = 0x73;
  25705. key[i++] = 0x41;
  25706. key[i++] = 0x6C;
  25707. key[i++] = 0x54;
  25708. }
  25709. var hash = calculateMD5(key, 0, i);
  25710. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  25711. }
  25712. function buildCipherConstructor(cf, name, num, gen, key) {
  25713. var cryptFilter = cf.get(name.name);
  25714. var cfm;
  25715. if (cryptFilter !== null && cryptFilter !== undefined) {
  25716. cfm = cryptFilter.get('CFM');
  25717. }
  25718. if (!cfm || cfm.name === 'None') {
  25719. return function cipherTransformFactoryBuildCipherConstructorNone() {
  25720. return new NullCipher();
  25721. };
  25722. }
  25723. if ('V2' === cfm.name) {
  25724. return function cipherTransformFactoryBuildCipherConstructorV2() {
  25725. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  25726. };
  25727. }
  25728. if ('AESV2' === cfm.name) {
  25729. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  25730. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  25731. };
  25732. }
  25733. if ('AESV3' === cfm.name) {
  25734. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  25735. return new AES256Cipher(key);
  25736. };
  25737. }
  25738. error('Unknown crypto method');
  25739. }
  25740. CipherTransformFactory.prototype = {
  25741. createCipherTransform:
  25742. function CipherTransformFactory_createCipherTransform(num, gen) {
  25743. if (this.algorithm === 4 || this.algorithm === 5) {
  25744. return new CipherTransform(
  25745. buildCipherConstructor(this.cf, this.stmf,
  25746. num, gen, this.encryptionKey),
  25747. buildCipherConstructor(this.cf, this.strf,
  25748. num, gen, this.encryptionKey));
  25749. }
  25750. // algorithms 1 and 2
  25751. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  25752. var cipherConstructor = function buildCipherCipherConstructor() {
  25753. return new ARCFourCipher(key);
  25754. };
  25755. return new CipherTransform(cipherConstructor, cipherConstructor);
  25756. }
  25757. };
  25758. return CipherTransformFactory;
  25759. })();
  25760. exports.AES128Cipher = AES128Cipher;
  25761. exports.AES256Cipher = AES256Cipher;
  25762. exports.ARCFourCipher = ARCFourCipher;
  25763. exports.CipherTransformFactory = CipherTransformFactory;
  25764. exports.PDF17 = PDF17;
  25765. exports.PDF20 = PDF20;
  25766. exports.calculateMD5 = calculateMD5;
  25767. exports.calculateSHA256 = calculateSHA256;
  25768. exports.calculateSHA384 = calculateSHA384;
  25769. exports.calculateSHA512 = calculateSHA512;
  25770. }));
  25771. (function (root, factory) {
  25772. {
  25773. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  25774. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  25775. }
  25776. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  25777. var Util = sharedUtil.Util;
  25778. var bytesToString = sharedUtil.bytesToString;
  25779. var error = sharedUtil.error;
  25780. var Stream = coreStream.Stream;
  25781. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  25782. var coreFonts; // see _setCoreFonts below
  25783. var CFFParser; // = coreFonts.CFFParser;
  25784. var Encodings; // = coreFonts.Encodings;
  25785. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25786. function getLong(data, offset) {
  25787. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25788. (data[offset + 2] << 8) | data[offset + 3];
  25789. }
  25790. function getUshort(data, offset) {
  25791. return (data[offset] << 8) | data[offset + 1];
  25792. }
  25793. function parseCmap(data, start, end) {
  25794. var offset = (getUshort(data, start + 2) === 1 ?
  25795. getLong(data, start + 8) : getLong(data, start + 16));
  25796. var format = getUshort(data, start + offset);
  25797. var length, ranges, p, i;
  25798. if (format === 4) {
  25799. length = getUshort(data, start + offset + 2);
  25800. var segCount = getUshort(data, start + offset + 6) >> 1;
  25801. p = start + offset + 14;
  25802. ranges = [];
  25803. for (i = 0; i < segCount; i++, p += 2) {
  25804. ranges[i] = {end: getUshort(data, p)};
  25805. }
  25806. p += 2;
  25807. for (i = 0; i < segCount; i++, p += 2) {
  25808. ranges[i].start = getUshort(data, p);
  25809. }
  25810. for (i = 0; i < segCount; i++, p += 2) {
  25811. ranges[i].idDelta = getUshort(data, p);
  25812. }
  25813. for (i = 0; i < segCount; i++, p += 2) {
  25814. var idOffset = getUshort(data, p);
  25815. if (idOffset === 0) {
  25816. continue;
  25817. }
  25818. ranges[i].ids = [];
  25819. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25820. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25821. idOffset += 2;
  25822. }
  25823. }
  25824. return ranges;
  25825. } else if (format === 12) {
  25826. length = getLong(data, start + offset + 4);
  25827. var groups = getLong(data, start + offset + 12);
  25828. p = start + offset + 16;
  25829. ranges = [];
  25830. for (i = 0; i < groups; i++) {
  25831. ranges.push({
  25832. start: getLong(data, p),
  25833. end: getLong(data, p + 4),
  25834. idDelta: getLong(data, p + 8) - getLong(data, p)
  25835. });
  25836. p += 12;
  25837. }
  25838. return ranges;
  25839. }
  25840. error('not supported cmap: ' + format);
  25841. }
  25842. function parseCff(data, start, end) {
  25843. var properties = {};
  25844. var parser = new CFFParser(new Stream(data, start, end - start),
  25845. properties);
  25846. var cff = parser.parse();
  25847. return {
  25848. glyphs: cff.charStrings.objects,
  25849. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25850. cff.topDict.privateDict.subrsIndex.objects),
  25851. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25852. };
  25853. }
  25854. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25855. var itemSize, itemDecode;
  25856. if (isGlyphLocationsLong) {
  25857. itemSize = 4;
  25858. itemDecode = function fontItemDecodeLong(data, offset) {
  25859. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25860. (data[offset + 2] << 8) | data[offset + 3];
  25861. };
  25862. } else {
  25863. itemSize = 2;
  25864. itemDecode = function fontItemDecode(data, offset) {
  25865. return (data[offset] << 9) | (data[offset + 1] << 1);
  25866. };
  25867. }
  25868. var glyphs = [];
  25869. var startOffset = itemDecode(loca, 0);
  25870. for (var j = itemSize; j < loca.length; j += itemSize) {
  25871. var endOffset = itemDecode(loca, j);
  25872. glyphs.push(glyf.subarray(startOffset, endOffset));
  25873. startOffset = endOffset;
  25874. }
  25875. return glyphs;
  25876. }
  25877. function lookupCmap(ranges, unicode) {
  25878. var code = unicode.charCodeAt(0);
  25879. var l = 0, r = ranges.length - 1;
  25880. while (l < r) {
  25881. var c = (l + r + 1) >> 1;
  25882. if (code < ranges[c].start) {
  25883. r = c - 1;
  25884. } else {
  25885. l = c;
  25886. }
  25887. }
  25888. if (ranges[l].start <= code && code <= ranges[l].end) {
  25889. return (ranges[l].idDelta + (ranges[l].ids ?
  25890. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25891. }
  25892. return 0;
  25893. }
  25894. function compileGlyf(code, cmds, font) {
  25895. function moveTo(x, y) {
  25896. cmds.push({cmd: 'moveTo', args: [x, y]});
  25897. }
  25898. function lineTo(x, y) {
  25899. cmds.push({cmd: 'lineTo', args: [x, y]});
  25900. }
  25901. function quadraticCurveTo(xa, ya, x, y) {
  25902. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25903. }
  25904. var i = 0;
  25905. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25906. var flags;
  25907. var x = 0, y = 0;
  25908. i += 10;
  25909. if (numberOfContours < 0) {
  25910. // composite glyph
  25911. do {
  25912. flags = (code[i] << 8) | code[i + 1];
  25913. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25914. i += 4;
  25915. var arg1, arg2;
  25916. if ((flags & 0x01)) {
  25917. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25918. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25919. i += 4;
  25920. } else {
  25921. arg1 = code[i++]; arg2 = code[i++];
  25922. }
  25923. if ((flags & 0x02)) {
  25924. x = arg1;
  25925. y = arg2;
  25926. } else {
  25927. x = 0; y = 0; // TODO "they are points" ?
  25928. }
  25929. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25930. if ((flags & 0x08)) {
  25931. scaleX =
  25932. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25933. i += 2;
  25934. } else if ((flags & 0x40)) {
  25935. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25936. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25937. i += 4;
  25938. } else if ((flags & 0x80)) {
  25939. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25940. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25941. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25942. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25943. i += 8;
  25944. }
  25945. var subglyph = font.glyphs[glyphIndex];
  25946. if (subglyph) {
  25947. cmds.push({cmd: 'save'});
  25948. cmds.push({cmd: 'transform',
  25949. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25950. compileGlyf(subglyph, cmds, font);
  25951. cmds.push({cmd: 'restore'});
  25952. }
  25953. } while ((flags & 0x20));
  25954. } else {
  25955. // simple glyph
  25956. var endPtsOfContours = [];
  25957. var j, jj;
  25958. for (j = 0; j < numberOfContours; j++) {
  25959. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25960. i += 2;
  25961. }
  25962. var instructionLength = (code[i] << 8) | code[i + 1];
  25963. i += 2 + instructionLength; // skipping the instructions
  25964. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25965. var points = [];
  25966. while (points.length < numberOfPoints) {
  25967. flags = code[i++];
  25968. var repeat = 1;
  25969. if ((flags & 0x08)) {
  25970. repeat += code[i++];
  25971. }
  25972. while (repeat-- > 0) {
  25973. points.push({flags: flags});
  25974. }
  25975. }
  25976. for (j = 0; j < numberOfPoints; j++) {
  25977. switch (points[j].flags & 0x12) {
  25978. case 0x00:
  25979. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25980. i += 2;
  25981. break;
  25982. case 0x02:
  25983. x -= code[i++];
  25984. break;
  25985. case 0x12:
  25986. x += code[i++];
  25987. break;
  25988. }
  25989. points[j].x = x;
  25990. }
  25991. for (j = 0; j < numberOfPoints; j++) {
  25992. switch (points[j].flags & 0x24) {
  25993. case 0x00:
  25994. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25995. i += 2;
  25996. break;
  25997. case 0x04:
  25998. y -= code[i++];
  25999. break;
  26000. case 0x24:
  26001. y += code[i++];
  26002. break;
  26003. }
  26004. points[j].y = y;
  26005. }
  26006. var startPoint = 0;
  26007. for (i = 0; i < numberOfContours; i++) {
  26008. var endPoint = endPtsOfContours[i];
  26009. // contours might have implicit points, which is located in the middle
  26010. // between two neighboring off-curve points
  26011. var contour = points.slice(startPoint, endPoint + 1);
  26012. if ((contour[0].flags & 1)) {
  26013. contour.push(contour[0]); // using start point at the contour end
  26014. } else if ((contour[contour.length - 1].flags & 1)) {
  26015. // first is off-curve point, trying to use one from the end
  26016. contour.unshift(contour[contour.length - 1]);
  26017. } else {
  26018. // start and end are off-curve points, creating implicit one
  26019. var p = {
  26020. flags: 1,
  26021. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26022. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26023. };
  26024. contour.unshift(p);
  26025. contour.push(p);
  26026. }
  26027. moveTo(contour[0].x, contour[0].y);
  26028. for (j = 1, jj = contour.length; j < jj; j++) {
  26029. if ((contour[j].flags & 1)) {
  26030. lineTo(contour[j].x, contour[j].y);
  26031. } else if ((contour[j + 1].flags & 1)){
  26032. quadraticCurveTo(contour[j].x, contour[j].y,
  26033. contour[j + 1].x, contour[j + 1].y);
  26034. j++;
  26035. } else {
  26036. quadraticCurveTo(contour[j].x, contour[j].y,
  26037. (contour[j].x + contour[j + 1].x) / 2,
  26038. (contour[j].y + contour[j + 1].y) / 2);
  26039. }
  26040. }
  26041. startPoint = endPoint + 1;
  26042. }
  26043. }
  26044. }
  26045. function compileCharString(code, cmds, font) {
  26046. var stack = [];
  26047. var x = 0, y = 0;
  26048. var stems = 0;
  26049. function moveTo(x, y) {
  26050. cmds.push({cmd: 'moveTo', args: [x, y]});
  26051. }
  26052. function lineTo(x, y) {
  26053. cmds.push({cmd: 'lineTo', args: [x, y]});
  26054. }
  26055. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26056. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26057. }
  26058. function parse(code) {
  26059. var i = 0;
  26060. while (i < code.length) {
  26061. var stackClean = false;
  26062. var v = code[i++];
  26063. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26064. switch (v) {
  26065. case 1: // hstem
  26066. stems += stack.length >> 1;
  26067. stackClean = true;
  26068. break;
  26069. case 3: // vstem
  26070. stems += stack.length >> 1;
  26071. stackClean = true;
  26072. break;
  26073. case 4: // vmoveto
  26074. y += stack.pop();
  26075. moveTo(x, y);
  26076. stackClean = true;
  26077. break;
  26078. case 5: // rlineto
  26079. while (stack.length > 0) {
  26080. x += stack.shift();
  26081. y += stack.shift();
  26082. lineTo(x, y);
  26083. }
  26084. break;
  26085. case 6: // hlineto
  26086. while (stack.length > 0) {
  26087. x += stack.shift();
  26088. lineTo(x, y);
  26089. if (stack.length === 0) {
  26090. break;
  26091. }
  26092. y += stack.shift();
  26093. lineTo(x, y);
  26094. }
  26095. break;
  26096. case 7: // vlineto
  26097. while (stack.length > 0) {
  26098. y += stack.shift();
  26099. lineTo(x, y);
  26100. if (stack.length === 0) {
  26101. break;
  26102. }
  26103. x += stack.shift();
  26104. lineTo(x, y);
  26105. }
  26106. break;
  26107. case 8: // rrcurveto
  26108. while (stack.length > 0) {
  26109. xa = x + stack.shift(); ya = y + stack.shift();
  26110. xb = xa + stack.shift(); yb = ya + stack.shift();
  26111. x = xb + stack.shift(); y = yb + stack.shift();
  26112. bezierCurveTo(xa, ya, xb, yb, x, y);
  26113. }
  26114. break;
  26115. case 10: // callsubr
  26116. n = stack.pop() + font.subrsBias;
  26117. subrCode = font.subrs[n];
  26118. if (subrCode) {
  26119. parse(subrCode);
  26120. }
  26121. break;
  26122. case 11: // return
  26123. return;
  26124. case 12:
  26125. v = code[i++];
  26126. switch (v) {
  26127. case 34: // flex
  26128. xa = x + stack.shift();
  26129. xb = xa + stack.shift(); y1 = y + stack.shift();
  26130. x = xb + stack.shift();
  26131. bezierCurveTo(xa, y, xb, y1, x, y1);
  26132. xa = x + stack.shift();
  26133. xb = xa + stack.shift();
  26134. x = xb + stack.shift();
  26135. bezierCurveTo(xa, y1, xb, y, x, y);
  26136. break;
  26137. case 35: // flex
  26138. xa = x + stack.shift(); ya = y + stack.shift();
  26139. xb = xa + stack.shift(); yb = ya + stack.shift();
  26140. x = xb + stack.shift(); y = yb + stack.shift();
  26141. bezierCurveTo(xa, ya, xb, yb, x, y);
  26142. xa = x + stack.shift(); ya = y + stack.shift();
  26143. xb = xa + stack.shift(); yb = ya + stack.shift();
  26144. x = xb + stack.shift(); y = yb + stack.shift();
  26145. bezierCurveTo(xa, ya, xb, yb, x, y);
  26146. stack.pop(); // fd
  26147. break;
  26148. case 36: // hflex1
  26149. xa = x + stack.shift(); y1 = y + stack.shift();
  26150. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26151. x = xb + stack.shift();
  26152. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26153. xa = x + stack.shift();
  26154. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26155. x = xb + stack.shift();
  26156. bezierCurveTo(xa, y2, xb, y3, x, y);
  26157. break;
  26158. case 37: // flex1
  26159. var x0 = x, y0 = y;
  26160. xa = x + stack.shift(); ya = y + stack.shift();
  26161. xb = xa + stack.shift(); yb = ya + stack.shift();
  26162. x = xb + stack.shift(); y = yb + stack.shift();
  26163. bezierCurveTo(xa, ya, xb, yb, x, y);
  26164. xa = x + stack.shift(); ya = y + stack.shift();
  26165. xb = xa + stack.shift(); yb = ya + stack.shift();
  26166. x = xb; y = yb;
  26167. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  26168. x += stack.shift();
  26169. } else {
  26170. y += stack.shift();
  26171. }
  26172. bezierCurveTo(xa, ya, xb, yb, x, y);
  26173. break;
  26174. default:
  26175. error('unknown operator: 12 ' + v);
  26176. }
  26177. break;
  26178. case 14: // endchar
  26179. if (stack.length >= 4) {
  26180. var achar = stack.pop();
  26181. var bchar = stack.pop();
  26182. y = stack.pop();
  26183. x = stack.pop();
  26184. cmds.push({cmd: 'save'});
  26185. cmds.push({cmd: 'translate', args: [x, y]});
  26186. var gid = lookupCmap(font.cmap, String.fromCharCode(
  26187. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  26188. compileCharString(font.glyphs[gid], cmds, font);
  26189. cmds.push({cmd: 'restore'});
  26190. gid = lookupCmap(font.cmap, String.fromCharCode(
  26191. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  26192. compileCharString(font.glyphs[gid], cmds, font);
  26193. }
  26194. return;
  26195. case 18: // hstemhm
  26196. stems += stack.length >> 1;
  26197. stackClean = true;
  26198. break;
  26199. case 19: // hintmask
  26200. stems += stack.length >> 1;
  26201. i += (stems + 7) >> 3;
  26202. stackClean = true;
  26203. break;
  26204. case 20: // cntrmask
  26205. stems += stack.length >> 1;
  26206. i += (stems + 7) >> 3;
  26207. stackClean = true;
  26208. break;
  26209. case 21: // rmoveto
  26210. y += stack.pop();
  26211. x += stack.pop();
  26212. moveTo(x, y);
  26213. stackClean = true;
  26214. break;
  26215. case 22: // hmoveto
  26216. x += stack.pop();
  26217. moveTo(x, y);
  26218. stackClean = true;
  26219. break;
  26220. case 23: // vstemhm
  26221. stems += stack.length >> 1;
  26222. stackClean = true;
  26223. break;
  26224. case 24: // rcurveline
  26225. while (stack.length > 2) {
  26226. xa = x + stack.shift(); ya = y + stack.shift();
  26227. xb = xa + stack.shift(); yb = ya + stack.shift();
  26228. x = xb + stack.shift(); y = yb + stack.shift();
  26229. bezierCurveTo(xa, ya, xb, yb, x, y);
  26230. }
  26231. x += stack.shift();
  26232. y += stack.shift();
  26233. lineTo(x, y);
  26234. break;
  26235. case 25: // rlinecurve
  26236. while (stack.length > 6) {
  26237. x += stack.shift();
  26238. y += stack.shift();
  26239. lineTo(x, y);
  26240. }
  26241. xa = x + stack.shift(); ya = y + stack.shift();
  26242. xb = xa + stack.shift(); yb = ya + stack.shift();
  26243. x = xb + stack.shift(); y = yb + stack.shift();
  26244. bezierCurveTo(xa, ya, xb, yb, x, y);
  26245. break;
  26246. case 26: // vvcurveto
  26247. if (stack.length % 2) {
  26248. x += stack.shift();
  26249. }
  26250. while (stack.length > 0) {
  26251. xa = x; ya = y + stack.shift();
  26252. xb = xa + stack.shift(); yb = ya + stack.shift();
  26253. x = xb; y = yb + stack.shift();
  26254. bezierCurveTo(xa, ya, xb, yb, x, y);
  26255. }
  26256. break;
  26257. case 27: // hhcurveto
  26258. if (stack.length % 2) {
  26259. y += stack.shift();
  26260. }
  26261. while (stack.length > 0) {
  26262. xa = x + stack.shift(); ya = y;
  26263. xb = xa + stack.shift(); yb = ya + stack.shift();
  26264. x = xb + stack.shift(); y = yb;
  26265. bezierCurveTo(xa, ya, xb, yb, x, y);
  26266. }
  26267. break;
  26268. case 28:
  26269. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  26270. i += 2;
  26271. break;
  26272. case 29: // callgsubr
  26273. n = stack.pop() + font.gsubrsBias;
  26274. subrCode = font.gsubrs[n];
  26275. if (subrCode) {
  26276. parse(subrCode);
  26277. }
  26278. break;
  26279. case 30: // vhcurveto
  26280. while (stack.length > 0) {
  26281. xa = x; ya = y + stack.shift();
  26282. xb = xa + stack.shift(); yb = ya + stack.shift();
  26283. x = xb + stack.shift();
  26284. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26285. bezierCurveTo(xa, ya, xb, yb, x, y);
  26286. if (stack.length === 0) {
  26287. break;
  26288. }
  26289. xa = x + stack.shift(); ya = y;
  26290. xb = xa + stack.shift(); yb = ya + stack.shift();
  26291. y = yb + stack.shift();
  26292. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26293. bezierCurveTo(xa, ya, xb, yb, x, y);
  26294. }
  26295. break;
  26296. case 31: // hvcurveto
  26297. while (stack.length > 0) {
  26298. xa = x + stack.shift(); ya = y;
  26299. xb = xa + stack.shift(); yb = ya + stack.shift();
  26300. y = yb + stack.shift();
  26301. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26302. bezierCurveTo(xa, ya, xb, yb, x, y);
  26303. if (stack.length === 0) {
  26304. break;
  26305. }
  26306. xa = x; ya = y + stack.shift();
  26307. xb = xa + stack.shift(); yb = ya + stack.shift();
  26308. x = xb + stack.shift();
  26309. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26310. bezierCurveTo(xa, ya, xb, yb, x, y);
  26311. }
  26312. break;
  26313. default:
  26314. if (v < 32) {
  26315. error('unknown operator: ' + v);
  26316. }
  26317. if (v < 247) {
  26318. stack.push(v - 139);
  26319. } else if (v < 251) {
  26320. stack.push((v - 247) * 256 + code[i++] + 108);
  26321. } else if (v < 255) {
  26322. stack.push(-(v - 251) * 256 - code[i++] - 108);
  26323. } else {
  26324. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  26325. (code[i + 2] << 8) | code[i + 3]) / 65536);
  26326. i += 4;
  26327. }
  26328. break;
  26329. }
  26330. if (stackClean) {
  26331. stack.length = 0;
  26332. }
  26333. }
  26334. }
  26335. parse(code);
  26336. }
  26337. var noop = '';
  26338. function CompiledFont(fontMatrix) {
  26339. this.compiledGlyphs = {};
  26340. this.fontMatrix = fontMatrix;
  26341. }
  26342. CompiledFont.prototype = {
  26343. getPathJs: function (unicode) {
  26344. var gid = lookupCmap(this.cmap, unicode);
  26345. var fn = this.compiledGlyphs[gid];
  26346. if (!fn) {
  26347. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  26348. }
  26349. return fn;
  26350. },
  26351. compileGlyph: function (code) {
  26352. if (!code || code.length === 0 || code[0] === 14) {
  26353. return noop;
  26354. }
  26355. var cmds = [];
  26356. cmds.push({cmd: 'save'});
  26357. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  26358. cmds.push({cmd: 'scale', args: ['size', '-size']});
  26359. this.compileGlyphImpl(code, cmds);
  26360. cmds.push({cmd: 'restore'});
  26361. return cmds;
  26362. },
  26363. compileGlyphImpl: function () {
  26364. error('Children classes should implement this.');
  26365. },
  26366. hasBuiltPath: function (unicode) {
  26367. var gid = lookupCmap(this.cmap, unicode);
  26368. return gid in this.compiledGlyphs;
  26369. }
  26370. };
  26371. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  26372. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  26373. CompiledFont.call(this, fontMatrix);
  26374. this.glyphs = glyphs;
  26375. this.cmap = cmap;
  26376. this.compiledGlyphs = [];
  26377. }
  26378. Util.inherit(TrueTypeCompiled, CompiledFont, {
  26379. compileGlyphImpl: function (code, cmds) {
  26380. compileGlyf(code, cmds, this);
  26381. }
  26382. });
  26383. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  26384. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  26385. CompiledFont.call(this, fontMatrix);
  26386. this.glyphs = cffInfo.glyphs;
  26387. this.gsubrs = cffInfo.gsubrs || [];
  26388. this.subrs = cffInfo.subrs || [];
  26389. this.cmap = cmap;
  26390. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  26391. this.compiledGlyphs = [];
  26392. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  26393. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  26394. this.subrsBias = (this.subrs.length < 1240 ?
  26395. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  26396. }
  26397. Util.inherit(Type2Compiled, CompiledFont, {
  26398. compileGlyphImpl: function (code, cmds) {
  26399. compileCharString(code, cmds, this);
  26400. }
  26401. });
  26402. return {
  26403. create: function FontRendererFactory_create(font) {
  26404. var data = new Uint8Array(font.data);
  26405. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  26406. var numTables = getUshort(data, 4);
  26407. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  26408. var tag = bytesToString(data.subarray(p, p + 4));
  26409. var offset = getLong(data, p + 8);
  26410. var length = getLong(data, p + 12);
  26411. switch (tag) {
  26412. case 'cmap':
  26413. cmap = parseCmap(data, offset, offset + length);
  26414. break;
  26415. case 'glyf':
  26416. glyf = data.subarray(offset, offset + length);
  26417. break;
  26418. case 'loca':
  26419. loca = data.subarray(offset, offset + length);
  26420. break;
  26421. case 'head':
  26422. unitsPerEm = getUshort(data, offset + 18);
  26423. indexToLocFormat = getUshort(data, offset + 50);
  26424. break;
  26425. case 'CFF ':
  26426. cff = parseCff(data, offset, offset + length);
  26427. break;
  26428. }
  26429. }
  26430. if (glyf) {
  26431. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  26432. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  26433. return new TrueTypeCompiled(
  26434. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  26435. } else {
  26436. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  26437. }
  26438. }
  26439. };
  26440. })();
  26441. // TODO refactor to remove cyclic dependency on fonts.js
  26442. function _setCoreFonts(coreFonts_) {
  26443. coreFonts = coreFonts_;
  26444. Encodings = coreFonts_.Encodings;
  26445. CFFParser = coreFonts_.CFFParser;
  26446. }
  26447. exports._setCoreFonts = _setCoreFonts;
  26448. exports.FontRendererFactory = FontRendererFactory;
  26449. }));
  26450. (function (root, factory) {
  26451. {
  26452. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  26453. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  26454. }
  26455. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  26456. var MissingDataException = sharedUtil.MissingDataException;
  26457. var StreamType = sharedUtil.StreamType;
  26458. var assert = sharedUtil.assert;
  26459. var error = sharedUtil.error;
  26460. var info = sharedUtil.info;
  26461. var isArray = sharedUtil.isArray;
  26462. var isInt = sharedUtil.isInt;
  26463. var isNum = sharedUtil.isNum;
  26464. var isString = sharedUtil.isString;
  26465. var warn = sharedUtil.warn;
  26466. var Cmd = corePrimitives.Cmd;
  26467. var Dict = corePrimitives.Dict;
  26468. var Name = corePrimitives.Name;
  26469. var Ref = corePrimitives.Ref;
  26470. var isCmd = corePrimitives.isCmd;
  26471. var isDict = corePrimitives.isDict;
  26472. var isName = corePrimitives.isName;
  26473. var Ascii85Stream = coreStream.Ascii85Stream;
  26474. var AsciiHexStream = coreStream.AsciiHexStream;
  26475. var CCITTFaxStream = coreStream.CCITTFaxStream;
  26476. var FlateStream = coreStream.FlateStream;
  26477. var Jbig2Stream = coreStream.Jbig2Stream;
  26478. var JpegStream = coreStream.JpegStream;
  26479. var JpxStream = coreStream.JpxStream;
  26480. var LZWStream = coreStream.LZWStream;
  26481. var NullStream = coreStream.NullStream;
  26482. var PredictorStream = coreStream.PredictorStream;
  26483. var RunLengthStream = coreStream.RunLengthStream;
  26484. var EOF = {};
  26485. function isEOF(v) {
  26486. return (v === EOF);
  26487. }
  26488. var MAX_LENGTH_TO_CACHE = 1000;
  26489. var Parser = (function ParserClosure() {
  26490. function Parser(lexer, allowStreams, xref) {
  26491. this.lexer = lexer;
  26492. this.allowStreams = allowStreams;
  26493. this.xref = xref;
  26494. this.imageCache = {};
  26495. this.refill();
  26496. }
  26497. Parser.prototype = {
  26498. refill: function Parser_refill() {
  26499. this.buf1 = this.lexer.getObj();
  26500. this.buf2 = this.lexer.getObj();
  26501. },
  26502. shift: function Parser_shift() {
  26503. if (isCmd(this.buf2, 'ID')) {
  26504. this.buf1 = this.buf2;
  26505. this.buf2 = null;
  26506. } else {
  26507. this.buf1 = this.buf2;
  26508. this.buf2 = this.lexer.getObj();
  26509. }
  26510. },
  26511. tryShift: function Parser_tryShift() {
  26512. try {
  26513. this.shift();
  26514. return true;
  26515. } catch (e) {
  26516. if (e instanceof MissingDataException) {
  26517. throw e;
  26518. }
  26519. // Upon failure, the caller should reset this.lexer.pos to a known good
  26520. // state and call this.shift() twice to reset the buffers.
  26521. return false;
  26522. }
  26523. },
  26524. getObj: function Parser_getObj(cipherTransform) {
  26525. var buf1 = this.buf1;
  26526. this.shift();
  26527. if (buf1 instanceof Cmd) {
  26528. switch (buf1.cmd) {
  26529. case 'BI': // inline image
  26530. return this.makeInlineImage(cipherTransform);
  26531. case '[': // array
  26532. var array = [];
  26533. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  26534. array.push(this.getObj(cipherTransform));
  26535. }
  26536. if (isEOF(this.buf1)) {
  26537. error('End of file inside array');
  26538. }
  26539. this.shift();
  26540. return array;
  26541. case '<<': // dictionary or stream
  26542. var dict = new Dict(this.xref);
  26543. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  26544. if (!isName(this.buf1)) {
  26545. info('Malformed dictionary: key must be a name object');
  26546. this.shift();
  26547. continue;
  26548. }
  26549. var key = this.buf1.name;
  26550. this.shift();
  26551. if (isEOF(this.buf1)) {
  26552. break;
  26553. }
  26554. dict.set(key, this.getObj(cipherTransform));
  26555. }
  26556. if (isEOF(this.buf1)) {
  26557. error('End of file inside dictionary');
  26558. }
  26559. // Stream objects are not allowed inside content streams or
  26560. // object streams.
  26561. if (isCmd(this.buf2, 'stream')) {
  26562. return (this.allowStreams ?
  26563. this.makeStream(dict, cipherTransform) : dict);
  26564. }
  26565. this.shift();
  26566. return dict;
  26567. default: // simple object
  26568. return buf1;
  26569. }
  26570. }
  26571. if (isInt(buf1)) { // indirect reference or integer
  26572. var num = buf1;
  26573. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  26574. var ref = new Ref(num, this.buf1);
  26575. this.shift();
  26576. this.shift();
  26577. return ref;
  26578. }
  26579. return num;
  26580. }
  26581. if (isString(buf1)) { // string
  26582. var str = buf1;
  26583. if (cipherTransform) {
  26584. str = cipherTransform.decryptString(str);
  26585. }
  26586. return str;
  26587. }
  26588. // simple object
  26589. return buf1;
  26590. },
  26591. /**
  26592. * Find the end of the stream by searching for the /EI\s/.
  26593. * @returns {number} The inline stream length.
  26594. */
  26595. findDefaultInlineStreamEnd:
  26596. function Parser_findDefaultInlineStreamEnd(stream) {
  26597. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  26598. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  26599. while ((ch = stream.getByte()) !== -1) {
  26600. if (state === 0) {
  26601. state = (ch === E) ? 1 : 0;
  26602. } else if (state === 1) {
  26603. state = (ch === I) ? 2 : 0;
  26604. } else {
  26605. assert(state === 2);
  26606. if (ch === SPACE || ch === LF || ch === CR) {
  26607. // Let's check the next five bytes are ASCII... just be sure.
  26608. n = 5;
  26609. followingBytes = stream.peekBytes(n);
  26610. for (i = 0; i < n; i++) {
  26611. ch = followingBytes[i];
  26612. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  26613. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  26614. // it's binary stuff. Resetting the state.
  26615. state = 0;
  26616. break;
  26617. }
  26618. }
  26619. if (state === 2) {
  26620. break; // Finished!
  26621. }
  26622. } else {
  26623. state = 0;
  26624. }
  26625. }
  26626. }
  26627. return ((stream.pos - 4) - startPos);
  26628. },
  26629. /**
  26630. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  26631. * @returns {number} The inline stream length.
  26632. */
  26633. findDCTDecodeInlineStreamEnd:
  26634. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  26635. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  26636. while ((b = stream.getByte()) !== -1) {
  26637. if (b !== 0xFF) { // Not a valid marker.
  26638. continue;
  26639. }
  26640. switch (stream.getByte()) {
  26641. case 0x00: // Byte stuffing.
  26642. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  26643. break;
  26644. case 0xFF: // Fill byte.
  26645. // Avoid skipping a valid marker, resetting the stream position.
  26646. stream.skip(-1);
  26647. break;
  26648. case 0xD9: // EOI
  26649. foundEOI = true;
  26650. break;
  26651. case 0xC0: // SOF0
  26652. case 0xC1: // SOF1
  26653. case 0xC2: // SOF2
  26654. case 0xC3: // SOF3
  26655. case 0xC5: // SOF5
  26656. case 0xC6: // SOF6
  26657. case 0xC7: // SOF7
  26658. case 0xC9: // SOF9
  26659. case 0xCA: // SOF10
  26660. case 0xCB: // SOF11
  26661. case 0xCD: // SOF13
  26662. case 0xCE: // SOF14
  26663. case 0xCF: // SOF15
  26664. case 0xC4: // DHT
  26665. case 0xCC: // DAC
  26666. case 0xDA: // SOS
  26667. case 0xDB: // DQT
  26668. case 0xDC: // DNL
  26669. case 0xDD: // DRI
  26670. case 0xDE: // DHP
  26671. case 0xDF: // EXP
  26672. case 0xE0: // APP0
  26673. case 0xE1: // APP1
  26674. case 0xE2: // APP2
  26675. case 0xE3: // APP3
  26676. case 0xE4: // APP4
  26677. case 0xE5: // APP5
  26678. case 0xE6: // APP6
  26679. case 0xE7: // APP7
  26680. case 0xE8: // APP8
  26681. case 0xE9: // APP9
  26682. case 0xEA: // APP10
  26683. case 0xEB: // APP11
  26684. case 0xEC: // APP12
  26685. case 0xED: // APP13
  26686. case 0xEE: // APP14
  26687. case 0xEF: // APP15
  26688. case 0xFE: // COM
  26689. // The marker should be followed by the length of the segment.
  26690. markerLength = stream.getUint16();
  26691. if (markerLength > 2) {
  26692. // |markerLength| contains the byte length of the marker segment,
  26693. // including its own length (2 bytes) and excluding the marker.
  26694. stream.skip(markerLength - 2); // Jump to the next marker.
  26695. } else {
  26696. // The marker length is invalid, resetting the stream position.
  26697. stream.skip(-2);
  26698. }
  26699. break;
  26700. }
  26701. if (foundEOI) {
  26702. break;
  26703. }
  26704. }
  26705. length = stream.pos - startPos;
  26706. if (b === -1) {
  26707. warn('Inline DCTDecode image stream: ' +
  26708. 'EOI marker not found, searching for /EI/ instead.');
  26709. stream.skip(-length); // Reset the stream position.
  26710. return this.findDefaultInlineStreamEnd(stream);
  26711. }
  26712. this.inlineStreamSkipEI(stream);
  26713. return length;
  26714. },
  26715. /**
  26716. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  26717. * @returns {number} The inline stream length.
  26718. */
  26719. findASCII85DecodeInlineStreamEnd:
  26720. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  26721. var TILDE = 0x7E, GT = 0x3E;
  26722. var startPos = stream.pos, ch, length;
  26723. while ((ch = stream.getByte()) !== -1) {
  26724. if (ch === TILDE && stream.peekByte() === GT) {
  26725. stream.skip();
  26726. break;
  26727. }
  26728. }
  26729. length = stream.pos - startPos;
  26730. if (ch === -1) {
  26731. warn('Inline ASCII85Decode image stream: ' +
  26732. 'EOD marker not found, searching for /EI/ instead.');
  26733. stream.skip(-length); // Reset the stream position.
  26734. return this.findDefaultInlineStreamEnd(stream);
  26735. }
  26736. this.inlineStreamSkipEI(stream);
  26737. return length;
  26738. },
  26739. /**
  26740. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  26741. * @returns {number} The inline stream length.
  26742. */
  26743. findASCIIHexDecodeInlineStreamEnd:
  26744. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  26745. var GT = 0x3E;
  26746. var startPos = stream.pos, ch, length;
  26747. while ((ch = stream.getByte()) !== -1) {
  26748. if (ch === GT) {
  26749. break;
  26750. }
  26751. }
  26752. length = stream.pos - startPos;
  26753. if (ch === -1) {
  26754. warn('Inline ASCIIHexDecode image stream: ' +
  26755. 'EOD marker not found, searching for /EI/ instead.');
  26756. stream.skip(-length); // Reset the stream position.
  26757. return this.findDefaultInlineStreamEnd(stream);
  26758. }
  26759. this.inlineStreamSkipEI(stream);
  26760. return length;
  26761. },
  26762. /**
  26763. * Skip over the /EI/ for streams where we search for an EOD marker.
  26764. */
  26765. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  26766. var E = 0x45, I = 0x49;
  26767. var state = 0, ch;
  26768. while ((ch = stream.getByte()) !== -1) {
  26769. if (state === 0) {
  26770. state = (ch === E) ? 1 : 0;
  26771. } else if (state === 1) {
  26772. state = (ch === I) ? 2 : 0;
  26773. } else if (state === 2) {
  26774. break;
  26775. }
  26776. }
  26777. },
  26778. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  26779. var lexer = this.lexer;
  26780. var stream = lexer.stream;
  26781. // Parse dictionary.
  26782. var dict = new Dict(this.xref);
  26783. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  26784. if (!isName(this.buf1)) {
  26785. error('Dictionary key must be a name object');
  26786. }
  26787. var key = this.buf1.name;
  26788. this.shift();
  26789. if (isEOF(this.buf1)) {
  26790. break;
  26791. }
  26792. dict.set(key, this.getObj(cipherTransform));
  26793. }
  26794. // Extract the name of the first (i.e. the current) image filter.
  26795. var filter = dict.get('Filter', 'F'), filterName;
  26796. if (isName(filter)) {
  26797. filterName = filter.name;
  26798. } else if (isArray(filter) && isName(filter[0])) {
  26799. filterName = filter[0].name;
  26800. }
  26801. // Parse image stream.
  26802. var startPos = stream.pos, length, i, ii;
  26803. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  26804. length = this.findDCTDecodeInlineStreamEnd(stream);
  26805. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  26806. length = this.findASCII85DecodeInlineStreamEnd(stream);
  26807. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  26808. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  26809. } else {
  26810. length = this.findDefaultInlineStreamEnd(stream);
  26811. }
  26812. var imageStream = stream.makeSubStream(startPos, length, dict);
  26813. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  26814. // adler32 checksum.
  26815. var adler32;
  26816. if (length < MAX_LENGTH_TO_CACHE) {
  26817. var imageBytes = imageStream.getBytes();
  26818. imageStream.reset();
  26819. var a = 1;
  26820. var b = 0;
  26821. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  26822. // No modulo required in the loop if imageBytes.length < 5552.
  26823. a += imageBytes[i] & 0xff;
  26824. b += a;
  26825. }
  26826. adler32 = ((b % 65521) << 16) | (a % 65521);
  26827. if (this.imageCache.adler32 === adler32) {
  26828. this.buf2 = Cmd.get('EI');
  26829. this.shift();
  26830. this.imageCache[adler32].reset();
  26831. return this.imageCache[adler32];
  26832. }
  26833. }
  26834. if (cipherTransform) {
  26835. imageStream = cipherTransform.createStream(imageStream, length);
  26836. }
  26837. imageStream = this.filter(imageStream, dict, length);
  26838. imageStream.dict = dict;
  26839. if (adler32 !== undefined) {
  26840. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  26841. this.imageCache[adler32] = imageStream;
  26842. }
  26843. this.buf2 = Cmd.get('EI');
  26844. this.shift();
  26845. return imageStream;
  26846. },
  26847. makeStream: function Parser_makeStream(dict, cipherTransform) {
  26848. var lexer = this.lexer;
  26849. var stream = lexer.stream;
  26850. // get stream start position
  26851. lexer.skipToNextLine();
  26852. var pos = stream.pos - 1;
  26853. // get length
  26854. var length = dict.get('Length');
  26855. if (!isInt(length)) {
  26856. info('Bad ' + length + ' attribute in stream');
  26857. length = 0;
  26858. }
  26859. // skip over the stream data
  26860. stream.pos = pos + length;
  26861. lexer.nextChar();
  26862. // Shift '>>' and check whether the new object marks the end of the stream
  26863. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26864. this.shift(); // 'stream'
  26865. } else {
  26866. // bad stream length, scanning for endstream
  26867. stream.pos = pos;
  26868. var SCAN_BLOCK_SIZE = 2048;
  26869. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26870. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26871. 0x61, 0x6D];
  26872. var skipped = 0, found = false, i, j;
  26873. while (stream.pos < stream.end) {
  26874. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26875. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26876. if (scanLength <= 0) {
  26877. break;
  26878. }
  26879. found = false;
  26880. for (i = 0, j = 0; i < scanLength; i++) {
  26881. var b = scanBytes[i];
  26882. if (b !== ENDSTREAM_SIGNATURE[j]) {
  26883. i -= j;
  26884. j = 0;
  26885. } else {
  26886. j++;
  26887. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26888. i++;
  26889. found = true;
  26890. break;
  26891. }
  26892. }
  26893. }
  26894. if (found) {
  26895. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  26896. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  26897. break;
  26898. }
  26899. skipped += scanLength;
  26900. stream.pos += scanLength;
  26901. }
  26902. if (!found) {
  26903. error('Missing endstream');
  26904. }
  26905. length = skipped;
  26906. lexer.nextChar();
  26907. this.shift();
  26908. this.shift();
  26909. }
  26910. this.shift(); // 'endstream'
  26911. stream = stream.makeSubStream(pos, length, dict);
  26912. if (cipherTransform) {
  26913. stream = cipherTransform.createStream(stream, length);
  26914. }
  26915. stream = this.filter(stream, dict, length);
  26916. stream.dict = dict;
  26917. return stream;
  26918. },
  26919. filter: function Parser_filter(stream, dict, length) {
  26920. var filter = dict.get('Filter', 'F');
  26921. var params = dict.get('DecodeParms', 'DP');
  26922. if (isName(filter)) {
  26923. return this.makeFilter(stream, filter.name, length, params);
  26924. }
  26925. var maybeLength = length;
  26926. if (isArray(filter)) {
  26927. var filterArray = filter;
  26928. var paramsArray = params;
  26929. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26930. filter = filterArray[i];
  26931. if (!isName(filter)) {
  26932. error('Bad filter name: ' + filter);
  26933. }
  26934. params = null;
  26935. if (isArray(paramsArray) && (i in paramsArray)) {
  26936. params = paramsArray[i];
  26937. }
  26938. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26939. // after the first stream the length variable is invalid
  26940. maybeLength = null;
  26941. }
  26942. }
  26943. return stream;
  26944. },
  26945. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26946. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26947. warn('Empty "' + name + '" stream.');
  26948. return new NullStream(stream);
  26949. }
  26950. try {
  26951. if (params && this.xref) {
  26952. params = this.xref.fetchIfRef(params);
  26953. }
  26954. var xrefStreamStats = this.xref.stats.streamTypes;
  26955. if (name === 'FlateDecode' || name === 'Fl') {
  26956. xrefStreamStats[StreamType.FLATE] = true;
  26957. if (params) {
  26958. return new PredictorStream(new FlateStream(stream, maybeLength),
  26959. maybeLength, params);
  26960. }
  26961. return new FlateStream(stream, maybeLength);
  26962. }
  26963. if (name === 'LZWDecode' || name === 'LZW') {
  26964. xrefStreamStats[StreamType.LZW] = true;
  26965. var earlyChange = 1;
  26966. if (params) {
  26967. if (params.has('EarlyChange')) {
  26968. earlyChange = params.get('EarlyChange');
  26969. }
  26970. return new PredictorStream(
  26971. new LZWStream(stream, maybeLength, earlyChange),
  26972. maybeLength, params);
  26973. }
  26974. return new LZWStream(stream, maybeLength, earlyChange);
  26975. }
  26976. if (name === 'DCTDecode' || name === 'DCT') {
  26977. xrefStreamStats[StreamType.DCT] = true;
  26978. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26979. }
  26980. if (name === 'JPXDecode' || name === 'JPX') {
  26981. xrefStreamStats[StreamType.JPX] = true;
  26982. return new JpxStream(stream, maybeLength, stream.dict);
  26983. }
  26984. if (name === 'ASCII85Decode' || name === 'A85') {
  26985. xrefStreamStats[StreamType.A85] = true;
  26986. return new Ascii85Stream(stream, maybeLength);
  26987. }
  26988. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26989. xrefStreamStats[StreamType.AHX] = true;
  26990. return new AsciiHexStream(stream, maybeLength);
  26991. }
  26992. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26993. xrefStreamStats[StreamType.CCF] = true;
  26994. return new CCITTFaxStream(stream, maybeLength, params);
  26995. }
  26996. if (name === 'RunLengthDecode' || name === 'RL') {
  26997. xrefStreamStats[StreamType.RL] = true;
  26998. return new RunLengthStream(stream, maybeLength);
  26999. }
  27000. if (name === 'JBIG2Decode') {
  27001. xrefStreamStats[StreamType.JBIG] = true;
  27002. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27003. }
  27004. warn('filter "' + name + '" not supported yet');
  27005. return stream;
  27006. } catch (ex) {
  27007. if (ex instanceof MissingDataException) {
  27008. throw ex;
  27009. }
  27010. warn('Invalid stream: \"' + ex + '\"');
  27011. return new NullStream(stream);
  27012. }
  27013. }
  27014. };
  27015. return Parser;
  27016. })();
  27017. var Lexer = (function LexerClosure() {
  27018. function Lexer(stream, knownCommands) {
  27019. this.stream = stream;
  27020. this.nextChar();
  27021. // While lexing, we build up many strings one char at a time. Using += for
  27022. // this can result in lots of garbage strings. It's better to build an
  27023. // array of single-char strings and then join() them together at the end.
  27024. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27025. // purpose uses less memory than using a new array for each string.
  27026. this.strBuf = [];
  27027. // The PDFs might have "glued" commands with other commands, operands or
  27028. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27029. // commands and their prefixes. The prefixes are built the following way:
  27030. // if there a command that is a prefix of the other valid command or
  27031. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27032. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27033. // other commands or literals as a prefix. The knowCommands is optional.
  27034. this.knownCommands = knownCommands;
  27035. }
  27036. Lexer.isSpace = function Lexer_isSpace(ch) {
  27037. // Space is one of the following characters: SPACE, TAB, CR or LF.
  27038. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  27039. };
  27040. // A '1' in this array means the character is white space. A '1' or
  27041. // '2' means the character ends a name or command.
  27042. var specialChars = [
  27043. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27045. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27059. ];
  27060. function toHexDigit(ch) {
  27061. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27062. return ch & 0x0F;
  27063. }
  27064. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27065. // 'A'-'F', 'a'-'f'
  27066. return (ch & 0x0F) + 9;
  27067. }
  27068. return -1;
  27069. }
  27070. Lexer.prototype = {
  27071. nextChar: function Lexer_nextChar() {
  27072. return (this.currentChar = this.stream.getByte());
  27073. },
  27074. peekChar: function Lexer_peekChar() {
  27075. return this.stream.peekByte();
  27076. },
  27077. getNumber: function Lexer_getNumber() {
  27078. var ch = this.currentChar;
  27079. var eNotation = false;
  27080. var divideBy = 0; // different from 0 if it's a floating point value
  27081. var sign = 1;
  27082. if (ch === 0x2D) { // '-'
  27083. sign = -1;
  27084. ch = this.nextChar();
  27085. if (ch === 0x2D) { // '-'
  27086. // Ignore double negative (this is consistent with Adobe Reader).
  27087. ch = this.nextChar();
  27088. }
  27089. } else if (ch === 0x2B) { // '+'
  27090. ch = this.nextChar();
  27091. }
  27092. if (ch === 0x2E) { // '.'
  27093. divideBy = 10;
  27094. ch = this.nextChar();
  27095. }
  27096. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27097. error('Invalid number: ' + String.fromCharCode(ch));
  27098. return 0;
  27099. }
  27100. var baseValue = ch - 0x30; // '0'
  27101. var powerValue = 0;
  27102. var powerValueSign = 1;
  27103. while ((ch = this.nextChar()) >= 0) {
  27104. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27105. var currentDigit = ch - 0x30; // '0'
  27106. if (eNotation) { // We are after an 'e' or 'E'
  27107. powerValue = powerValue * 10 + currentDigit;
  27108. } else {
  27109. if (divideBy !== 0) { // We are after a point
  27110. divideBy *= 10;
  27111. }
  27112. baseValue = baseValue * 10 + currentDigit;
  27113. }
  27114. } else if (ch === 0x2E) { // '.'
  27115. if (divideBy === 0) {
  27116. divideBy = 1;
  27117. } else {
  27118. // A number can have only one '.'
  27119. break;
  27120. }
  27121. } else if (ch === 0x2D) { // '-'
  27122. // ignore minus signs in the middle of numbers to match
  27123. // Adobe's behavior
  27124. warn('Badly formated number');
  27125. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27126. // 'E' can be either a scientific notation or the beginning of a new
  27127. // operator
  27128. ch = this.peekChar();
  27129. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27130. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27131. this.nextChar(); // Consume the sign character
  27132. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27133. // The 'E' must be the beginning of a new operator
  27134. break;
  27135. }
  27136. eNotation = true;
  27137. } else {
  27138. // the last character doesn't belong to us
  27139. break;
  27140. }
  27141. }
  27142. if (divideBy !== 0) {
  27143. baseValue /= divideBy;
  27144. }
  27145. if (eNotation) {
  27146. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27147. }
  27148. return sign * baseValue;
  27149. },
  27150. getString: function Lexer_getString() {
  27151. var numParen = 1;
  27152. var done = false;
  27153. var strBuf = this.strBuf;
  27154. strBuf.length = 0;
  27155. var ch = this.nextChar();
  27156. while (true) {
  27157. var charBuffered = false;
  27158. switch (ch | 0) {
  27159. case -1:
  27160. warn('Unterminated string');
  27161. done = true;
  27162. break;
  27163. case 0x28: // '('
  27164. ++numParen;
  27165. strBuf.push('(');
  27166. break;
  27167. case 0x29: // ')'
  27168. if (--numParen === 0) {
  27169. this.nextChar(); // consume strings ')'
  27170. done = true;
  27171. } else {
  27172. strBuf.push(')');
  27173. }
  27174. break;
  27175. case 0x5C: // '\\'
  27176. ch = this.nextChar();
  27177. switch (ch) {
  27178. case -1:
  27179. warn('Unterminated string');
  27180. done = true;
  27181. break;
  27182. case 0x6E: // 'n'
  27183. strBuf.push('\n');
  27184. break;
  27185. case 0x72: // 'r'
  27186. strBuf.push('\r');
  27187. break;
  27188. case 0x74: // 't'
  27189. strBuf.push('\t');
  27190. break;
  27191. case 0x62: // 'b'
  27192. strBuf.push('\b');
  27193. break;
  27194. case 0x66: // 'f'
  27195. strBuf.push('\f');
  27196. break;
  27197. case 0x5C: // '\'
  27198. case 0x28: // '('
  27199. case 0x29: // ')'
  27200. strBuf.push(String.fromCharCode(ch));
  27201. break;
  27202. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  27203. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  27204. var x = ch & 0x0F;
  27205. ch = this.nextChar();
  27206. charBuffered = true;
  27207. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27208. x = (x << 3) + (ch & 0x0F);
  27209. ch = this.nextChar();
  27210. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27211. charBuffered = false;
  27212. x = (x << 3) + (ch & 0x0F);
  27213. }
  27214. }
  27215. strBuf.push(String.fromCharCode(x));
  27216. break;
  27217. case 0x0D: // CR
  27218. if (this.peekChar() === 0x0A) { // LF
  27219. this.nextChar();
  27220. }
  27221. break;
  27222. case 0x0A: // LF
  27223. break;
  27224. default:
  27225. strBuf.push(String.fromCharCode(ch));
  27226. break;
  27227. }
  27228. break;
  27229. default:
  27230. strBuf.push(String.fromCharCode(ch));
  27231. break;
  27232. }
  27233. if (done) {
  27234. break;
  27235. }
  27236. if (!charBuffered) {
  27237. ch = this.nextChar();
  27238. }
  27239. }
  27240. return strBuf.join('');
  27241. },
  27242. getName: function Lexer_getName() {
  27243. var ch, previousCh;
  27244. var strBuf = this.strBuf;
  27245. strBuf.length = 0;
  27246. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27247. if (ch === 0x23) { // '#'
  27248. ch = this.nextChar();
  27249. if (specialChars[ch]) {
  27250. warn('Lexer_getName: ' +
  27251. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  27252. strBuf.push('#');
  27253. break;
  27254. }
  27255. var x = toHexDigit(ch);
  27256. if (x !== -1) {
  27257. previousCh = ch;
  27258. ch = this.nextChar();
  27259. var x2 = toHexDigit(ch);
  27260. if (x2 === -1) {
  27261. warn('Lexer_getName: Illegal digit (' +
  27262. String.fromCharCode(ch) +') in hexadecimal number.');
  27263. strBuf.push('#', String.fromCharCode(previousCh));
  27264. if (specialChars[ch]) {
  27265. break;
  27266. }
  27267. strBuf.push(String.fromCharCode(ch));
  27268. continue;
  27269. }
  27270. strBuf.push(String.fromCharCode((x << 4) | x2));
  27271. } else {
  27272. strBuf.push('#', String.fromCharCode(ch));
  27273. }
  27274. } else {
  27275. strBuf.push(String.fromCharCode(ch));
  27276. }
  27277. }
  27278. if (strBuf.length > 127) {
  27279. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  27280. }
  27281. return Name.get(strBuf.join(''));
  27282. },
  27283. getHexString: function Lexer_getHexString() {
  27284. var strBuf = this.strBuf;
  27285. strBuf.length = 0;
  27286. var ch = this.currentChar;
  27287. var isFirstHex = true;
  27288. var firstDigit;
  27289. var secondDigit;
  27290. while (true) {
  27291. if (ch < 0) {
  27292. warn('Unterminated hex string');
  27293. break;
  27294. } else if (ch === 0x3E) { // '>'
  27295. this.nextChar();
  27296. break;
  27297. } else if (specialChars[ch] === 1) {
  27298. ch = this.nextChar();
  27299. continue;
  27300. } else {
  27301. if (isFirstHex) {
  27302. firstDigit = toHexDigit(ch);
  27303. if (firstDigit === -1) {
  27304. warn('Ignoring invalid character "' + ch + '" in hex string');
  27305. ch = this.nextChar();
  27306. continue;
  27307. }
  27308. } else {
  27309. secondDigit = toHexDigit(ch);
  27310. if (secondDigit === -1) {
  27311. warn('Ignoring invalid character "' + ch + '" in hex string');
  27312. ch = this.nextChar();
  27313. continue;
  27314. }
  27315. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  27316. }
  27317. isFirstHex = !isFirstHex;
  27318. ch = this.nextChar();
  27319. }
  27320. }
  27321. return strBuf.join('');
  27322. },
  27323. getObj: function Lexer_getObj() {
  27324. // skip whitespace and comments
  27325. var comment = false;
  27326. var ch = this.currentChar;
  27327. while (true) {
  27328. if (ch < 0) {
  27329. return EOF;
  27330. }
  27331. if (comment) {
  27332. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  27333. comment = false;
  27334. }
  27335. } else if (ch === 0x25) { // '%'
  27336. comment = true;
  27337. } else if (specialChars[ch] !== 1) {
  27338. break;
  27339. }
  27340. ch = this.nextChar();
  27341. }
  27342. // start reading token
  27343. switch (ch | 0) {
  27344. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  27345. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  27346. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  27347. return this.getNumber();
  27348. case 0x28: // '('
  27349. return this.getString();
  27350. case 0x2F: // '/'
  27351. return this.getName();
  27352. // array punctuation
  27353. case 0x5B: // '['
  27354. this.nextChar();
  27355. return Cmd.get('[');
  27356. case 0x5D: // ']'
  27357. this.nextChar();
  27358. return Cmd.get(']');
  27359. // hex string or dict punctuation
  27360. case 0x3C: // '<'
  27361. ch = this.nextChar();
  27362. if (ch === 0x3C) {
  27363. // dict punctuation
  27364. this.nextChar();
  27365. return Cmd.get('<<');
  27366. }
  27367. return this.getHexString();
  27368. // dict punctuation
  27369. case 0x3E: // '>'
  27370. ch = this.nextChar();
  27371. if (ch === 0x3E) {
  27372. this.nextChar();
  27373. return Cmd.get('>>');
  27374. }
  27375. return Cmd.get('>');
  27376. case 0x7B: // '{'
  27377. this.nextChar();
  27378. return Cmd.get('{');
  27379. case 0x7D: // '}'
  27380. this.nextChar();
  27381. return Cmd.get('}');
  27382. case 0x29: // ')'
  27383. error('Illegal character: ' + ch);
  27384. break;
  27385. }
  27386. // command
  27387. var str = String.fromCharCode(ch);
  27388. var knownCommands = this.knownCommands;
  27389. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27390. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27391. // stop if known command is found and next character does not make
  27392. // the str a command
  27393. var possibleCommand = str + String.fromCharCode(ch);
  27394. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  27395. break;
  27396. }
  27397. if (str.length === 128) {
  27398. error('Command token too long: ' + str.length);
  27399. }
  27400. str = possibleCommand;
  27401. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27402. }
  27403. if (str === 'true') {
  27404. return true;
  27405. }
  27406. if (str === 'false') {
  27407. return false;
  27408. }
  27409. if (str === 'null') {
  27410. return null;
  27411. }
  27412. return Cmd.get(str);
  27413. },
  27414. skipToNextLine: function Lexer_skipToNextLine() {
  27415. var ch = this.currentChar;
  27416. while (ch >= 0) {
  27417. if (ch === 0x0D) { // CR
  27418. ch = this.nextChar();
  27419. if (ch === 0x0A) { // LF
  27420. this.nextChar();
  27421. }
  27422. break;
  27423. } else if (ch === 0x0A) { // LF
  27424. this.nextChar();
  27425. break;
  27426. }
  27427. ch = this.nextChar();
  27428. }
  27429. }
  27430. };
  27431. return Lexer;
  27432. })();
  27433. var Linearization = {
  27434. create: function LinearizationCreate(stream) {
  27435. function getInt(name, allowZeroValue) {
  27436. var obj = linDict.get(name);
  27437. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  27438. return obj;
  27439. }
  27440. throw new Error('The "' + name + '" parameter in the linearization ' +
  27441. 'dictionary is invalid.');
  27442. }
  27443. function getHints() {
  27444. var hints = linDict.get('H'), hintsLength, item;
  27445. if (isArray(hints) &&
  27446. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  27447. for (var index = 0; index < hintsLength; index++) {
  27448. if (!(isInt(item = hints[index]) && item > 0)) {
  27449. throw new Error('Hint (' + index +
  27450. ') in the linearization dictionary is invalid.');
  27451. }
  27452. }
  27453. return hints;
  27454. }
  27455. throw new Error('Hint array in the linearization dictionary is invalid.');
  27456. }
  27457. var parser = new Parser(new Lexer(stream), false, null);
  27458. var obj1 = parser.getObj();
  27459. var obj2 = parser.getObj();
  27460. var obj3 = parser.getObj();
  27461. var linDict = parser.getObj();
  27462. var obj, length;
  27463. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  27464. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  27465. return null; // No valid linearization dictionary found.
  27466. } else if ((length = getInt('L')) !== stream.length) {
  27467. throw new Error('The "L" parameter in the linearization dictionary ' +
  27468. 'does not equal the stream length.');
  27469. }
  27470. return {
  27471. length: length,
  27472. hints: getHints(),
  27473. objectNumberFirst: getInt('O'),
  27474. endFirst: getInt('E'),
  27475. numPages: getInt('N'),
  27476. mainXRefEntriesOffset: getInt('T'),
  27477. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  27478. };
  27479. }
  27480. };
  27481. exports.EOF = EOF;
  27482. exports.Lexer = Lexer;
  27483. exports.Linearization = Linearization;
  27484. exports.Parser = Parser;
  27485. exports.isEOF = isEOF;
  27486. // TODO refactor to remove dependency on stream.js
  27487. coreStream._setCoreParser(exports);
  27488. }));
  27489. (function (root, factory) {
  27490. {
  27491. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  27492. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  27493. }
  27494. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  27495. var Util = sharedUtil.Util;
  27496. var assert = sharedUtil.assert;
  27497. var error = sharedUtil.error;
  27498. var isInt = sharedUtil.isInt;
  27499. var isString = sharedUtil.isString;
  27500. var warn = sharedUtil.warn;
  27501. var isName = corePrimitives.isName;
  27502. var isCmd = corePrimitives.isCmd;
  27503. var isStream = corePrimitives.isStream;
  27504. var StringStream = coreStream.StringStream;
  27505. var Lexer = coreParser.Lexer;
  27506. var isEOF = coreParser.isEOF;
  27507. var BUILT_IN_CMAPS = [
  27508. // << Start unicode maps.
  27509. 'Adobe-GB1-UCS2',
  27510. 'Adobe-CNS1-UCS2',
  27511. 'Adobe-Japan1-UCS2',
  27512. 'Adobe-Korea1-UCS2',
  27513. // >> End unicode maps.
  27514. '78-EUC-H',
  27515. '78-EUC-V',
  27516. '78-H',
  27517. '78-RKSJ-H',
  27518. '78-RKSJ-V',
  27519. '78-V',
  27520. '78ms-RKSJ-H',
  27521. '78ms-RKSJ-V',
  27522. '83pv-RKSJ-H',
  27523. '90ms-RKSJ-H',
  27524. '90ms-RKSJ-V',
  27525. '90msp-RKSJ-H',
  27526. '90msp-RKSJ-V',
  27527. '90pv-RKSJ-H',
  27528. '90pv-RKSJ-V',
  27529. 'Add-H',
  27530. 'Add-RKSJ-H',
  27531. 'Add-RKSJ-V',
  27532. 'Add-V',
  27533. 'Adobe-CNS1-0',
  27534. 'Adobe-CNS1-1',
  27535. 'Adobe-CNS1-2',
  27536. 'Adobe-CNS1-3',
  27537. 'Adobe-CNS1-4',
  27538. 'Adobe-CNS1-5',
  27539. 'Adobe-CNS1-6',
  27540. 'Adobe-GB1-0',
  27541. 'Adobe-GB1-1',
  27542. 'Adobe-GB1-2',
  27543. 'Adobe-GB1-3',
  27544. 'Adobe-GB1-4',
  27545. 'Adobe-GB1-5',
  27546. 'Adobe-Japan1-0',
  27547. 'Adobe-Japan1-1',
  27548. 'Adobe-Japan1-2',
  27549. 'Adobe-Japan1-3',
  27550. 'Adobe-Japan1-4',
  27551. 'Adobe-Japan1-5',
  27552. 'Adobe-Japan1-6',
  27553. 'Adobe-Korea1-0',
  27554. 'Adobe-Korea1-1',
  27555. 'Adobe-Korea1-2',
  27556. 'B5-H',
  27557. 'B5-V',
  27558. 'B5pc-H',
  27559. 'B5pc-V',
  27560. 'CNS-EUC-H',
  27561. 'CNS-EUC-V',
  27562. 'CNS1-H',
  27563. 'CNS1-V',
  27564. 'CNS2-H',
  27565. 'CNS2-V',
  27566. 'ETHK-B5-H',
  27567. 'ETHK-B5-V',
  27568. 'ETen-B5-H',
  27569. 'ETen-B5-V',
  27570. 'ETenms-B5-H',
  27571. 'ETenms-B5-V',
  27572. 'EUC-H',
  27573. 'EUC-V',
  27574. 'Ext-H',
  27575. 'Ext-RKSJ-H',
  27576. 'Ext-RKSJ-V',
  27577. 'Ext-V',
  27578. 'GB-EUC-H',
  27579. 'GB-EUC-V',
  27580. 'GB-H',
  27581. 'GB-V',
  27582. 'GBK-EUC-H',
  27583. 'GBK-EUC-V',
  27584. 'GBK2K-H',
  27585. 'GBK2K-V',
  27586. 'GBKp-EUC-H',
  27587. 'GBKp-EUC-V',
  27588. 'GBT-EUC-H',
  27589. 'GBT-EUC-V',
  27590. 'GBT-H',
  27591. 'GBT-V',
  27592. 'GBTpc-EUC-H',
  27593. 'GBTpc-EUC-V',
  27594. 'GBpc-EUC-H',
  27595. 'GBpc-EUC-V',
  27596. 'H',
  27597. 'HKdla-B5-H',
  27598. 'HKdla-B5-V',
  27599. 'HKdlb-B5-H',
  27600. 'HKdlb-B5-V',
  27601. 'HKgccs-B5-H',
  27602. 'HKgccs-B5-V',
  27603. 'HKm314-B5-H',
  27604. 'HKm314-B5-V',
  27605. 'HKm471-B5-H',
  27606. 'HKm471-B5-V',
  27607. 'HKscs-B5-H',
  27608. 'HKscs-B5-V',
  27609. 'Hankaku',
  27610. 'Hiragana',
  27611. 'KSC-EUC-H',
  27612. 'KSC-EUC-V',
  27613. 'KSC-H',
  27614. 'KSC-Johab-H',
  27615. 'KSC-Johab-V',
  27616. 'KSC-V',
  27617. 'KSCms-UHC-H',
  27618. 'KSCms-UHC-HW-H',
  27619. 'KSCms-UHC-HW-V',
  27620. 'KSCms-UHC-V',
  27621. 'KSCpc-EUC-H',
  27622. 'KSCpc-EUC-V',
  27623. 'Katakana',
  27624. 'NWP-H',
  27625. 'NWP-V',
  27626. 'RKSJ-H',
  27627. 'RKSJ-V',
  27628. 'Roman',
  27629. 'UniCNS-UCS2-H',
  27630. 'UniCNS-UCS2-V',
  27631. 'UniCNS-UTF16-H',
  27632. 'UniCNS-UTF16-V',
  27633. 'UniCNS-UTF32-H',
  27634. 'UniCNS-UTF32-V',
  27635. 'UniCNS-UTF8-H',
  27636. 'UniCNS-UTF8-V',
  27637. 'UniGB-UCS2-H',
  27638. 'UniGB-UCS2-V',
  27639. 'UniGB-UTF16-H',
  27640. 'UniGB-UTF16-V',
  27641. 'UniGB-UTF32-H',
  27642. 'UniGB-UTF32-V',
  27643. 'UniGB-UTF8-H',
  27644. 'UniGB-UTF8-V',
  27645. 'UniJIS-UCS2-H',
  27646. 'UniJIS-UCS2-HW-H',
  27647. 'UniJIS-UCS2-HW-V',
  27648. 'UniJIS-UCS2-V',
  27649. 'UniJIS-UTF16-H',
  27650. 'UniJIS-UTF16-V',
  27651. 'UniJIS-UTF32-H',
  27652. 'UniJIS-UTF32-V',
  27653. 'UniJIS-UTF8-H',
  27654. 'UniJIS-UTF8-V',
  27655. 'UniJIS2004-UTF16-H',
  27656. 'UniJIS2004-UTF16-V',
  27657. 'UniJIS2004-UTF32-H',
  27658. 'UniJIS2004-UTF32-V',
  27659. 'UniJIS2004-UTF8-H',
  27660. 'UniJIS2004-UTF8-V',
  27661. 'UniJISPro-UCS2-HW-V',
  27662. 'UniJISPro-UCS2-V',
  27663. 'UniJISPro-UTF8-V',
  27664. 'UniJISX0213-UTF32-H',
  27665. 'UniJISX0213-UTF32-V',
  27666. 'UniJISX02132004-UTF32-H',
  27667. 'UniJISX02132004-UTF32-V',
  27668. 'UniKS-UCS2-H',
  27669. 'UniKS-UCS2-V',
  27670. 'UniKS-UTF16-H',
  27671. 'UniKS-UTF16-V',
  27672. 'UniKS-UTF32-H',
  27673. 'UniKS-UTF32-V',
  27674. 'UniKS-UTF8-H',
  27675. 'UniKS-UTF8-V',
  27676. 'V',
  27677. 'WP-Symbol'];
  27678. // CMap, not to be confused with TrueType's cmap.
  27679. var CMap = (function CMapClosure() {
  27680. function CMap(builtInCMap) {
  27681. // Codespace ranges are stored as follows:
  27682. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  27683. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  27684. this.codespaceRanges = [[], [], [], []];
  27685. this.numCodespaceRanges = 0;
  27686. // Map entries have one of two forms.
  27687. // - cid chars are 16-bit unsigned integers, stored as integers.
  27688. // - bf chars are variable-length byte sequences, stored as strings, with
  27689. // one byte per character.
  27690. this._map = [];
  27691. this.name = '';
  27692. this.vertical = false;
  27693. this.useCMap = null;
  27694. this.builtInCMap = builtInCMap;
  27695. }
  27696. CMap.prototype = {
  27697. addCodespaceRange: function(n, low, high) {
  27698. this.codespaceRanges[n - 1].push(low, high);
  27699. this.numCodespaceRanges++;
  27700. },
  27701. mapCidRange: function(low, high, dstLow) {
  27702. while (low <= high) {
  27703. this._map[low++] = dstLow++;
  27704. }
  27705. },
  27706. mapBfRange: function(low, high, dstLow) {
  27707. var lastByte = dstLow.length - 1;
  27708. while (low <= high) {
  27709. this._map[low++] = dstLow;
  27710. // Only the last byte has to be incremented.
  27711. dstLow = dstLow.substr(0, lastByte) +
  27712. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  27713. }
  27714. },
  27715. mapBfRangeToArray: function(low, high, array) {
  27716. var i = 0, ii = array.length;
  27717. while (low <= high && i < ii) {
  27718. this._map[low] = array[i++];
  27719. ++low;
  27720. }
  27721. },
  27722. // This is used for both bf and cid chars.
  27723. mapOne: function(src, dst) {
  27724. this._map[src] = dst;
  27725. },
  27726. lookup: function(code) {
  27727. return this._map[code];
  27728. },
  27729. contains: function(code) {
  27730. return this._map[code] !== undefined;
  27731. },
  27732. forEach: function(callback) {
  27733. // Most maps have fewer than 65536 entries, and for those we use normal
  27734. // array iteration. But really sparse tables are possible -- e.g. with
  27735. // indices in the *billions*. For such tables we use for..in, which isn't
  27736. // ideal because it stringifies the indices for all present elements, but
  27737. // it does avoid iterating over every undefined entry.
  27738. var map = this._map;
  27739. var length = map.length;
  27740. var i;
  27741. if (length <= 0x10000) {
  27742. for (i = 0; i < length; i++) {
  27743. if (map[i] !== undefined) {
  27744. callback(i, map[i]);
  27745. }
  27746. }
  27747. } else {
  27748. for (i in this._map) {
  27749. callback(i, map[i]);
  27750. }
  27751. }
  27752. },
  27753. charCodeOf: function(value) {
  27754. return this._map.indexOf(value);
  27755. },
  27756. getMap: function() {
  27757. return this._map;
  27758. },
  27759. readCharCode: function(str, offset, out) {
  27760. var c = 0;
  27761. var codespaceRanges = this.codespaceRanges;
  27762. var codespaceRangesLen = this.codespaceRanges.length;
  27763. // 9.7.6.2 CMap Mapping
  27764. // The code length is at most 4.
  27765. for (var n = 0; n < codespaceRangesLen; n++) {
  27766. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  27767. // Check each codespace range to see if it falls within.
  27768. var codespaceRange = codespaceRanges[n];
  27769. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  27770. var low = codespaceRange[k++];
  27771. var high = codespaceRange[k++];
  27772. if (c >= low && c <= high) {
  27773. out.charcode = c;
  27774. out.length = n + 1;
  27775. return;
  27776. }
  27777. }
  27778. }
  27779. out.charcode = 0;
  27780. out.length = 1;
  27781. },
  27782. get length() {
  27783. return this._map.length;
  27784. },
  27785. get isIdentityCMap() {
  27786. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  27787. return false;
  27788. }
  27789. if (this._map.length !== 0x10000) {
  27790. return false;
  27791. }
  27792. for (var i = 0; i < 0x10000; i++) {
  27793. if (this._map[i] !== i) {
  27794. return false;
  27795. }
  27796. }
  27797. return true;
  27798. }
  27799. };
  27800. return CMap;
  27801. })();
  27802. // A special case of CMap, where the _map array implicitly has a length of
  27803. // 65536 and each element is equal to its index.
  27804. var IdentityCMap = (function IdentityCMapClosure() {
  27805. function IdentityCMap(vertical, n) {
  27806. CMap.call(this);
  27807. this.vertical = vertical;
  27808. this.addCodespaceRange(n, 0, 0xffff);
  27809. }
  27810. Util.inherit(IdentityCMap, CMap, {});
  27811. IdentityCMap.prototype = {
  27812. addCodespaceRange: CMap.prototype.addCodespaceRange,
  27813. mapCidRange: function(low, high, dstLow) {
  27814. error('should not call mapCidRange');
  27815. },
  27816. mapBfRange: function(low, high, dstLow) {
  27817. error('should not call mapBfRange');
  27818. },
  27819. mapBfRangeToArray: function(low, high, array) {
  27820. error('should not call mapBfRangeToArray');
  27821. },
  27822. mapOne: function(src, dst) {
  27823. error('should not call mapCidOne');
  27824. },
  27825. lookup: function(code) {
  27826. return (isInt(code) && code <= 0xffff) ? code : undefined;
  27827. },
  27828. contains: function(code) {
  27829. return isInt(code) && code <= 0xffff;
  27830. },
  27831. forEach: function(callback) {
  27832. for (var i = 0; i <= 0xffff; i++) {
  27833. callback(i, i);
  27834. }
  27835. },
  27836. charCodeOf: function(value) {
  27837. return (isInt(value) && value <= 0xffff) ? value : -1;
  27838. },
  27839. getMap: function() {
  27840. // Sometimes identity maps must be instantiated, but it's rare.
  27841. var map = new Array(0x10000);
  27842. for (var i = 0; i <= 0xffff; i++) {
  27843. map[i] = i;
  27844. }
  27845. return map;
  27846. },
  27847. readCharCode: CMap.prototype.readCharCode,
  27848. get length() {
  27849. return 0x10000;
  27850. },
  27851. get isIdentityCMap() {
  27852. error('should not access .isIdentityCMap');
  27853. }
  27854. };
  27855. return IdentityCMap;
  27856. })();
  27857. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  27858. function fetchBinaryData(url) {
  27859. var nonBinaryRequest = PDFJS.disableWorker;
  27860. var request = new XMLHttpRequest();
  27861. request.open('GET', url, false);
  27862. if (!nonBinaryRequest) {
  27863. try {
  27864. request.responseType = 'arraybuffer';
  27865. nonBinaryRequest = request.responseType !== 'arraybuffer';
  27866. } catch (e) {
  27867. nonBinaryRequest = true;
  27868. }
  27869. }
  27870. if (nonBinaryRequest && request.overrideMimeType) {
  27871. request.overrideMimeType('text/plain; charset=x-user-defined');
  27872. }
  27873. request.send(null);
  27874. if (nonBinaryRequest ? !request.responseText : !request.response) {
  27875. error('Unable to get binary cMap at: ' + url);
  27876. }
  27877. if (nonBinaryRequest) {
  27878. var data = Array.prototype.map.call(request.responseText, function (ch) {
  27879. return ch.charCodeAt(0) & 255;
  27880. });
  27881. return new Uint8Array(data);
  27882. }
  27883. return new Uint8Array(request.response);
  27884. }
  27885. function hexToInt(a, size) {
  27886. var n = 0;
  27887. for (var i = 0; i <= size; i++) {
  27888. n = (n << 8) | a[i];
  27889. }
  27890. return n >>> 0;
  27891. }
  27892. function hexToStr(a, size) {
  27893. // This code is hot. Special-case some common values to avoid creating an
  27894. // object with subarray().
  27895. if (size === 1) {
  27896. return String.fromCharCode(a[0], a[1]);
  27897. }
  27898. if (size === 3) {
  27899. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  27900. }
  27901. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  27902. }
  27903. function addHex(a, b, size) {
  27904. var c = 0;
  27905. for (var i = size; i >= 0; i--) {
  27906. c += a[i] + b[i];
  27907. a[i] = c & 255;
  27908. c >>= 8;
  27909. }
  27910. }
  27911. function incHex(a, size) {
  27912. var c = 1;
  27913. for (var i = size; i >= 0 && c > 0; i--) {
  27914. c += a[i];
  27915. a[i] = c & 255;
  27916. c >>= 8;
  27917. }
  27918. }
  27919. var MAX_NUM_SIZE = 16;
  27920. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  27921. function BinaryCMapStream(data) {
  27922. this.buffer = data;
  27923. this.pos = 0;
  27924. this.end = data.length;
  27925. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  27926. }
  27927. BinaryCMapStream.prototype = {
  27928. readByte: function () {
  27929. if (this.pos >= this.end) {
  27930. return -1;
  27931. }
  27932. return this.buffer[this.pos++];
  27933. },
  27934. readNumber: function () {
  27935. var n = 0;
  27936. var last;
  27937. do {
  27938. var b = this.readByte();
  27939. if (b < 0) {
  27940. error('unexpected EOF in bcmap');
  27941. }
  27942. last = !(b & 0x80);
  27943. n = (n << 7) | (b & 0x7F);
  27944. } while (!last);
  27945. return n;
  27946. },
  27947. readSigned: function () {
  27948. var n = this.readNumber();
  27949. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  27950. },
  27951. readHex: function (num, size) {
  27952. num.set(this.buffer.subarray(this.pos,
  27953. this.pos + size + 1));
  27954. this.pos += size + 1;
  27955. },
  27956. readHexNumber: function (num, size) {
  27957. var last;
  27958. var stack = this.tmpBuf, sp = 0;
  27959. do {
  27960. var b = this.readByte();
  27961. if (b < 0) {
  27962. error('unexpected EOF in bcmap');
  27963. }
  27964. last = !(b & 0x80);
  27965. stack[sp++] = b & 0x7F;
  27966. } while (!last);
  27967. var i = size, buffer = 0, bufferSize = 0;
  27968. while (i >= 0) {
  27969. while (bufferSize < 8 && stack.length > 0) {
  27970. buffer = (stack[--sp] << bufferSize) | buffer;
  27971. bufferSize += 7;
  27972. }
  27973. num[i] = buffer & 255;
  27974. i--;
  27975. buffer >>= 8;
  27976. bufferSize -= 8;
  27977. }
  27978. },
  27979. readHexSigned: function (num, size) {
  27980. this.readHexNumber(num, size);
  27981. var sign = num[size] & 1 ? 255 : 0;
  27982. var c = 0;
  27983. for (var i = 0; i <= size; i++) {
  27984. c = ((c & 1) << 8) | num[i];
  27985. num[i] = (c >> 1) ^ sign;
  27986. }
  27987. },
  27988. readString: function () {
  27989. var len = this.readNumber();
  27990. var s = '';
  27991. for (var i = 0; i < len; i++) {
  27992. s += String.fromCharCode(this.readNumber());
  27993. }
  27994. return s;
  27995. }
  27996. };
  27997. function processBinaryCMap(url, cMap, extend) {
  27998. var data = fetchBinaryData(url);
  27999. var stream = new BinaryCMapStream(data);
  28000. var header = stream.readByte();
  28001. cMap.vertical = !!(header & 1);
  28002. var useCMap = null;
  28003. var start = new Uint8Array(MAX_NUM_SIZE);
  28004. var end = new Uint8Array(MAX_NUM_SIZE);
  28005. var char = new Uint8Array(MAX_NUM_SIZE);
  28006. var charCode = new Uint8Array(MAX_NUM_SIZE);
  28007. var tmp = new Uint8Array(MAX_NUM_SIZE);
  28008. var code;
  28009. var b;
  28010. while ((b = stream.readByte()) >= 0) {
  28011. var type = b >> 5;
  28012. if (type === 7) { // metadata, e.g. comment or usecmap
  28013. switch (b & 0x1F) {
  28014. case 0:
  28015. stream.readString(); // skipping comment
  28016. break;
  28017. case 1:
  28018. useCMap = stream.readString();
  28019. break;
  28020. }
  28021. continue;
  28022. }
  28023. var sequence = !!(b & 0x10);
  28024. var dataSize = b & 15;
  28025. assert(dataSize + 1 <= MAX_NUM_SIZE);
  28026. var ucs2DataSize = 1;
  28027. var subitemsCount = stream.readNumber();
  28028. var i;
  28029. switch (type) {
  28030. case 0: // codespacerange
  28031. stream.readHex(start, dataSize);
  28032. stream.readHexNumber(end, dataSize);
  28033. addHex(end, start, dataSize);
  28034. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  28035. hexToInt(end, dataSize));
  28036. for (i = 1; i < subitemsCount; i++) {
  28037. incHex(end, dataSize);
  28038. stream.readHexNumber(start, dataSize);
  28039. addHex(start, end, dataSize);
  28040. stream.readHexNumber(end, dataSize);
  28041. addHex(end, start, dataSize);
  28042. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  28043. hexToInt(end, dataSize));
  28044. }
  28045. break;
  28046. case 1: // notdefrange
  28047. stream.readHex(start, dataSize);
  28048. stream.readHexNumber(end, dataSize);
  28049. addHex(end, start, dataSize);
  28050. code = stream.readNumber();
  28051. // undefined range, skipping
  28052. for (i = 1; i < subitemsCount; i++) {
  28053. incHex(end, dataSize);
  28054. stream.readHexNumber(start, dataSize);
  28055. addHex(start, end, dataSize);
  28056. stream.readHexNumber(end, dataSize);
  28057. addHex(end, start, dataSize);
  28058. code = stream.readNumber();
  28059. // nop
  28060. }
  28061. break;
  28062. case 2: // cidchar
  28063. stream.readHex(char, dataSize);
  28064. code = stream.readNumber();
  28065. cMap.mapOne(hexToInt(char, dataSize), code);
  28066. for (i = 1; i < subitemsCount; i++) {
  28067. incHex(char, dataSize);
  28068. if (!sequence) {
  28069. stream.readHexNumber(tmp, dataSize);
  28070. addHex(char, tmp, dataSize);
  28071. }
  28072. code = stream.readSigned() + (code + 1);
  28073. cMap.mapOne(hexToInt(char, dataSize), code);
  28074. }
  28075. break;
  28076. case 3: // cidrange
  28077. stream.readHex(start, dataSize);
  28078. stream.readHexNumber(end, dataSize);
  28079. addHex(end, start, dataSize);
  28080. code = stream.readNumber();
  28081. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  28082. code);
  28083. for (i = 1; i < subitemsCount; i++) {
  28084. incHex(end, dataSize);
  28085. if (!sequence) {
  28086. stream.readHexNumber(start, dataSize);
  28087. addHex(start, end, dataSize);
  28088. } else {
  28089. start.set(end);
  28090. }
  28091. stream.readHexNumber(end, dataSize);
  28092. addHex(end, start, dataSize);
  28093. code = stream.readNumber();
  28094. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  28095. code);
  28096. }
  28097. break;
  28098. case 4: // bfchar
  28099. stream.readHex(char, ucs2DataSize);
  28100. stream.readHex(charCode, dataSize);
  28101. cMap.mapOne(hexToInt(char, ucs2DataSize),
  28102. hexToStr(charCode, dataSize));
  28103. for (i = 1; i < subitemsCount; i++) {
  28104. incHex(char, ucs2DataSize);
  28105. if (!sequence) {
  28106. stream.readHexNumber(tmp, ucs2DataSize);
  28107. addHex(char, tmp, ucs2DataSize);
  28108. }
  28109. incHex(charCode, dataSize);
  28110. stream.readHexSigned(tmp, dataSize);
  28111. addHex(charCode, tmp, dataSize);
  28112. cMap.mapOne(hexToInt(char, ucs2DataSize),
  28113. hexToStr(charCode, dataSize));
  28114. }
  28115. break;
  28116. case 5: // bfrange
  28117. stream.readHex(start, ucs2DataSize);
  28118. stream.readHexNumber(end, ucs2DataSize);
  28119. addHex(end, start, ucs2DataSize);
  28120. stream.readHex(charCode, dataSize);
  28121. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  28122. hexToInt(end, ucs2DataSize),
  28123. hexToStr(charCode, dataSize));
  28124. for (i = 1; i < subitemsCount; i++) {
  28125. incHex(end, ucs2DataSize);
  28126. if (!sequence) {
  28127. stream.readHexNumber(start, ucs2DataSize);
  28128. addHex(start, end, ucs2DataSize);
  28129. } else {
  28130. start.set(end);
  28131. }
  28132. stream.readHexNumber(end, ucs2DataSize);
  28133. addHex(end, start, ucs2DataSize);
  28134. stream.readHex(charCode, dataSize);
  28135. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  28136. hexToInt(end, ucs2DataSize),
  28137. hexToStr(charCode, dataSize));
  28138. }
  28139. break;
  28140. default:
  28141. error('Unknown type: ' + type);
  28142. break;
  28143. }
  28144. }
  28145. if (useCMap) {
  28146. extend(useCMap);
  28147. }
  28148. return cMap;
  28149. }
  28150. function BinaryCMapReader() {}
  28151. BinaryCMapReader.prototype = {
  28152. read: processBinaryCMap
  28153. };
  28154. return BinaryCMapReader;
  28155. })();
  28156. var CMapFactory = (function CMapFactoryClosure() {
  28157. function strToInt(str) {
  28158. var a = 0;
  28159. for (var i = 0; i < str.length; i++) {
  28160. a = (a << 8) | str.charCodeAt(i);
  28161. }
  28162. return a >>> 0;
  28163. }
  28164. function expectString(obj) {
  28165. if (!isString(obj)) {
  28166. error('Malformed CMap: expected string.');
  28167. }
  28168. }
  28169. function expectInt(obj) {
  28170. if (!isInt(obj)) {
  28171. error('Malformed CMap: expected int.');
  28172. }
  28173. }
  28174. function parseBfChar(cMap, lexer) {
  28175. while (true) {
  28176. var obj = lexer.getObj();
  28177. if (isEOF(obj)) {
  28178. break;
  28179. }
  28180. if (isCmd(obj, 'endbfchar')) {
  28181. return;
  28182. }
  28183. expectString(obj);
  28184. var src = strToInt(obj);
  28185. obj = lexer.getObj();
  28186. // TODO are /dstName used?
  28187. expectString(obj);
  28188. var dst = obj;
  28189. cMap.mapOne(src, dst);
  28190. }
  28191. }
  28192. function parseBfRange(cMap, lexer) {
  28193. while (true) {
  28194. var obj = lexer.getObj();
  28195. if (isEOF(obj)) {
  28196. break;
  28197. }
  28198. if (isCmd(obj, 'endbfrange')) {
  28199. return;
  28200. }
  28201. expectString(obj);
  28202. var low = strToInt(obj);
  28203. obj = lexer.getObj();
  28204. expectString(obj);
  28205. var high = strToInt(obj);
  28206. obj = lexer.getObj();
  28207. if (isInt(obj) || isString(obj)) {
  28208. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  28209. cMap.mapBfRange(low, high, dstLow);
  28210. } else if (isCmd(obj, '[')) {
  28211. obj = lexer.getObj();
  28212. var array = [];
  28213. while (!isCmd(obj, ']') && !isEOF(obj)) {
  28214. array.push(obj);
  28215. obj = lexer.getObj();
  28216. }
  28217. cMap.mapBfRangeToArray(low, high, array);
  28218. } else {
  28219. break;
  28220. }
  28221. }
  28222. error('Invalid bf range.');
  28223. }
  28224. function parseCidChar(cMap, lexer) {
  28225. while (true) {
  28226. var obj = lexer.getObj();
  28227. if (isEOF(obj)) {
  28228. break;
  28229. }
  28230. if (isCmd(obj, 'endcidchar')) {
  28231. return;
  28232. }
  28233. expectString(obj);
  28234. var src = strToInt(obj);
  28235. obj = lexer.getObj();
  28236. expectInt(obj);
  28237. var dst = obj;
  28238. cMap.mapOne(src, dst);
  28239. }
  28240. }
  28241. function parseCidRange(cMap, lexer) {
  28242. while (true) {
  28243. var obj = lexer.getObj();
  28244. if (isEOF(obj)) {
  28245. break;
  28246. }
  28247. if (isCmd(obj, 'endcidrange')) {
  28248. return;
  28249. }
  28250. expectString(obj);
  28251. var low = strToInt(obj);
  28252. obj = lexer.getObj();
  28253. expectString(obj);
  28254. var high = strToInt(obj);
  28255. obj = lexer.getObj();
  28256. expectInt(obj);
  28257. var dstLow = obj;
  28258. cMap.mapCidRange(low, high, dstLow);
  28259. }
  28260. }
  28261. function parseCodespaceRange(cMap, lexer) {
  28262. while (true) {
  28263. var obj = lexer.getObj();
  28264. if (isEOF(obj)) {
  28265. break;
  28266. }
  28267. if (isCmd(obj, 'endcodespacerange')) {
  28268. return;
  28269. }
  28270. if (!isString(obj)) {
  28271. break;
  28272. }
  28273. var low = strToInt(obj);
  28274. obj = lexer.getObj();
  28275. if (!isString(obj)) {
  28276. break;
  28277. }
  28278. var high = strToInt(obj);
  28279. cMap.addCodespaceRange(obj.length, low, high);
  28280. }
  28281. error('Invalid codespace range.');
  28282. }
  28283. function parseWMode(cMap, lexer) {
  28284. var obj = lexer.getObj();
  28285. if (isInt(obj)) {
  28286. cMap.vertical = !!obj;
  28287. }
  28288. }
  28289. function parseCMapName(cMap, lexer) {
  28290. var obj = lexer.getObj();
  28291. if (isName(obj) && isString(obj.name)) {
  28292. cMap.name = obj.name;
  28293. }
  28294. }
  28295. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  28296. var previous;
  28297. var embededUseCMap;
  28298. objLoop: while (true) {
  28299. var obj = lexer.getObj();
  28300. if (isEOF(obj)) {
  28301. break;
  28302. } else if (isName(obj)) {
  28303. if (obj.name === 'WMode') {
  28304. parseWMode(cMap, lexer);
  28305. } else if (obj.name === 'CMapName') {
  28306. parseCMapName(cMap, lexer);
  28307. }
  28308. previous = obj;
  28309. } else if (isCmd(obj)) {
  28310. switch (obj.cmd) {
  28311. case 'endcmap':
  28312. break objLoop;
  28313. case 'usecmap':
  28314. if (isName(previous)) {
  28315. embededUseCMap = previous.name;
  28316. }
  28317. break;
  28318. case 'begincodespacerange':
  28319. parseCodespaceRange(cMap, lexer);
  28320. break;
  28321. case 'beginbfchar':
  28322. parseBfChar(cMap, lexer);
  28323. break;
  28324. case 'begincidchar':
  28325. parseCidChar(cMap, lexer);
  28326. break;
  28327. case 'beginbfrange':
  28328. parseBfRange(cMap, lexer);
  28329. break;
  28330. case 'begincidrange':
  28331. parseCidRange(cMap, lexer);
  28332. break;
  28333. }
  28334. }
  28335. }
  28336. if (!useCMap && embededUseCMap) {
  28337. // Load the usecmap definition from the file only if there wasn't one
  28338. // specified.
  28339. useCMap = embededUseCMap;
  28340. }
  28341. if (useCMap) {
  28342. extendCMap(cMap, builtInCMapParams, useCMap);
  28343. }
  28344. }
  28345. function extendCMap(cMap, builtInCMapParams, useCMap) {
  28346. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  28347. // If there aren't any code space ranges defined clone all the parent ones
  28348. // into this cMap.
  28349. if (cMap.numCodespaceRanges === 0) {
  28350. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  28351. for (var i = 0; i < useCodespaceRanges.length; i++) {
  28352. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  28353. }
  28354. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  28355. }
  28356. // Merge the map into the current one, making sure not to override
  28357. // any previously defined entries.
  28358. cMap.useCMap.forEach(function(key, value) {
  28359. if (!cMap.contains(key)) {
  28360. cMap.mapOne(key, cMap.useCMap.lookup(key));
  28361. }
  28362. });
  28363. }
  28364. function parseBinaryCMap(name, builtInCMapParams) {
  28365. var url = builtInCMapParams.url + name + '.bcmap';
  28366. var cMap = new CMap(true);
  28367. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  28368. extendCMap(cMap, builtInCMapParams, useCMap);
  28369. });
  28370. return cMap;
  28371. }
  28372. function createBuiltInCMap(name, builtInCMapParams) {
  28373. if (name === 'Identity-H') {
  28374. return new IdentityCMap(false, 2);
  28375. } else if (name === 'Identity-V') {
  28376. return new IdentityCMap(true, 2);
  28377. }
  28378. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  28379. error('Unknown cMap name: ' + name);
  28380. }
  28381. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  28382. if (builtInCMapParams.packed) {
  28383. return parseBinaryCMap(name, builtInCMapParams);
  28384. }
  28385. var request = new XMLHttpRequest();
  28386. var url = builtInCMapParams.url + name;
  28387. request.open('GET', url, false);
  28388. request.send(null);
  28389. if (!request.responseText) {
  28390. error('Unable to get cMap at: ' + url);
  28391. }
  28392. var cMap = new CMap(true);
  28393. var lexer = new Lexer(new StringStream(request.responseText));
  28394. parseCMap(cMap, lexer, builtInCMapParams, null);
  28395. return cMap;
  28396. }
  28397. return {
  28398. create: function (encoding, builtInCMapParams, useCMap) {
  28399. if (isName(encoding)) {
  28400. return createBuiltInCMap(encoding.name, builtInCMapParams);
  28401. } else if (isStream(encoding)) {
  28402. var cMap = new CMap();
  28403. var lexer = new Lexer(encoding);
  28404. try {
  28405. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  28406. } catch (e) {
  28407. warn('Invalid CMap data. ' + e);
  28408. }
  28409. if (cMap.isIdentityCMap) {
  28410. return createBuiltInCMap(cMap.name, builtInCMapParams);
  28411. }
  28412. return cMap;
  28413. }
  28414. error('Encoding required.');
  28415. }
  28416. };
  28417. })();
  28418. exports.CMap = CMap;
  28419. exports.CMapFactory = CMapFactory;
  28420. exports.IdentityCMap = IdentityCMap;
  28421. }));
  28422. (function (root, factory) {
  28423. {
  28424. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  28425. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  28426. root.pdfjsCoreChunkedStream);
  28427. }
  28428. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  28429. coreChunkedStream) {
  28430. var InvalidPDFException = sharedUtil.InvalidPDFException;
  28431. var MissingDataException = sharedUtil.MissingDataException;
  28432. var XRefParseException = sharedUtil.XRefParseException;
  28433. var assert = sharedUtil.assert;
  28434. var bytesToString = sharedUtil.bytesToString;
  28435. var createPromiseCapability = sharedUtil.createPromiseCapability;
  28436. var error = sharedUtil.error;
  28437. var info = sharedUtil.info;
  28438. var isArray = sharedUtil.isArray;
  28439. var isInt = sharedUtil.isInt;
  28440. var isString = sharedUtil.isString;
  28441. var shadow = sharedUtil.shadow;
  28442. var stringToPDFString = sharedUtil.stringToPDFString;
  28443. var stringToUTF8String = sharedUtil.stringToUTF8String;
  28444. var warn = sharedUtil.warn;
  28445. var Ref = corePrimitives.Ref;
  28446. var RefSet = corePrimitives.RefSet;
  28447. var RefSetCache = corePrimitives.RefSetCache;
  28448. var isName = corePrimitives.isName;
  28449. var isCmd = corePrimitives.isCmd;
  28450. var isDict = corePrimitives.isDict;
  28451. var isRef = corePrimitives.isRef;
  28452. var isStream = corePrimitives.isStream;
  28453. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  28454. var Lexer = coreParser.Lexer;
  28455. var Parser = coreParser.Parser;
  28456. var ChunkedStream = coreChunkedStream.ChunkedStream;
  28457. var Catalog = (function CatalogClosure() {
  28458. function Catalog(pdfManager, xref, pageFactory) {
  28459. this.pdfManager = pdfManager;
  28460. this.xref = xref;
  28461. this.catDict = xref.getCatalogObj();
  28462. this.fontCache = new RefSetCache();
  28463. assert(isDict(this.catDict),
  28464. 'catalog object is not a dictionary');
  28465. // TODO refactor to move getPage() to the PDFDocument.
  28466. this.pageFactory = pageFactory;
  28467. this.pagePromises = [];
  28468. }
  28469. Catalog.prototype = {
  28470. get metadata() {
  28471. var streamRef = this.catDict.getRaw('Metadata');
  28472. if (!isRef(streamRef)) {
  28473. return shadow(this, 'metadata', null);
  28474. }
  28475. var encryptMetadata = (!this.xref.encrypt ? false :
  28476. this.xref.encrypt.encryptMetadata);
  28477. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  28478. var metadata;
  28479. if (stream && isDict(stream.dict)) {
  28480. var type = stream.dict.get('Type');
  28481. var subtype = stream.dict.get('Subtype');
  28482. if (isName(type) && isName(subtype) &&
  28483. type.name === 'Metadata' && subtype.name === 'XML') {
  28484. // XXX: This should examine the charset the XML document defines,
  28485. // however since there are currently no real means to decode
  28486. // arbitrary charsets, let's just hope that the author of the PDF
  28487. // was reasonable enough to stick with the XML default charset,
  28488. // which is UTF-8.
  28489. try {
  28490. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  28491. } catch (e) {
  28492. info('Skipping invalid metadata.');
  28493. }
  28494. }
  28495. }
  28496. return shadow(this, 'metadata', metadata);
  28497. },
  28498. get toplevelPagesDict() {
  28499. var pagesObj = this.catDict.get('Pages');
  28500. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  28501. // shadow the prototype getter
  28502. return shadow(this, 'toplevelPagesDict', pagesObj);
  28503. },
  28504. get documentOutline() {
  28505. var obj = null;
  28506. try {
  28507. obj = this.readDocumentOutline();
  28508. } catch (ex) {
  28509. if (ex instanceof MissingDataException) {
  28510. throw ex;
  28511. }
  28512. warn('Unable to read document outline');
  28513. }
  28514. return shadow(this, 'documentOutline', obj);
  28515. },
  28516. readDocumentOutline: function Catalog_readDocumentOutline() {
  28517. var xref = this.xref;
  28518. var obj = this.catDict.get('Outlines');
  28519. var root = { items: [] };
  28520. if (isDict(obj)) {
  28521. obj = obj.getRaw('First');
  28522. var processed = new RefSet();
  28523. if (isRef(obj)) {
  28524. var queue = [{obj: obj, parent: root}];
  28525. // to avoid recursion keeping track of the items
  28526. // in the processed dictionary
  28527. processed.put(obj);
  28528. while (queue.length > 0) {
  28529. var i = queue.shift();
  28530. var outlineDict = xref.fetchIfRef(i.obj);
  28531. if (outlineDict === null) {
  28532. continue;
  28533. }
  28534. if (!outlineDict.has('Title')) {
  28535. error('Invalid outline item');
  28536. }
  28537. var dest = outlineDict.get('A');
  28538. if (dest) {
  28539. dest = dest.get('D');
  28540. } else if (outlineDict.has('Dest')) {
  28541. dest = outlineDict.getRaw('Dest');
  28542. if (isName(dest)) {
  28543. dest = dest.name;
  28544. }
  28545. }
  28546. var title = outlineDict.get('Title');
  28547. var outlineItem = {
  28548. dest: dest,
  28549. title: stringToPDFString(title),
  28550. color: outlineDict.get('C') || [0, 0, 0],
  28551. count: outlineDict.get('Count'),
  28552. bold: !!(outlineDict.get('F') & 2),
  28553. italic: !!(outlineDict.get('F') & 1),
  28554. items: []
  28555. };
  28556. i.parent.items.push(outlineItem);
  28557. obj = outlineDict.getRaw('First');
  28558. if (isRef(obj) && !processed.has(obj)) {
  28559. queue.push({obj: obj, parent: outlineItem});
  28560. processed.put(obj);
  28561. }
  28562. obj = outlineDict.getRaw('Next');
  28563. if (isRef(obj) && !processed.has(obj)) {
  28564. queue.push({obj: obj, parent: i.parent});
  28565. processed.put(obj);
  28566. }
  28567. }
  28568. }
  28569. }
  28570. return (root.items.length > 0 ? root.items : null);
  28571. },
  28572. get numPages() {
  28573. var obj = this.toplevelPagesDict.get('Count');
  28574. assert(
  28575. isInt(obj),
  28576. 'page count in top level pages object is not an integer'
  28577. );
  28578. // shadow the prototype getter
  28579. return shadow(this, 'num', obj);
  28580. },
  28581. get destinations() {
  28582. function fetchDestination(dest) {
  28583. return isDict(dest) ? dest.get('D') : dest;
  28584. }
  28585. var xref = this.xref;
  28586. var dests = {}, nameTreeRef, nameDictionaryRef;
  28587. var obj = this.catDict.get('Names');
  28588. if (obj && obj.has('Dests')) {
  28589. nameTreeRef = obj.getRaw('Dests');
  28590. } else if (this.catDict.has('Dests')) {
  28591. nameDictionaryRef = this.catDict.get('Dests');
  28592. }
  28593. if (nameDictionaryRef) {
  28594. // reading simple destination dictionary
  28595. obj = nameDictionaryRef;
  28596. obj.forEach(function catalogForEach(key, value) {
  28597. if (!value) {
  28598. return;
  28599. }
  28600. dests[key] = fetchDestination(value);
  28601. });
  28602. }
  28603. if (nameTreeRef) {
  28604. var nameTree = new NameTree(nameTreeRef, xref);
  28605. var names = nameTree.getAll();
  28606. for (var name in names) {
  28607. if (!names.hasOwnProperty(name)) {
  28608. continue;
  28609. }
  28610. dests[name] = fetchDestination(names[name]);
  28611. }
  28612. }
  28613. return shadow(this, 'destinations', dests);
  28614. },
  28615. getDestination: function Catalog_getDestination(destinationId) {
  28616. function fetchDestination(dest) {
  28617. return isDict(dest) ? dest.get('D') : dest;
  28618. }
  28619. var xref = this.xref;
  28620. var dest = null, nameTreeRef, nameDictionaryRef;
  28621. var obj = this.catDict.get('Names');
  28622. if (obj && obj.has('Dests')) {
  28623. nameTreeRef = obj.getRaw('Dests');
  28624. } else if (this.catDict.has('Dests')) {
  28625. nameDictionaryRef = this.catDict.get('Dests');
  28626. }
  28627. if (nameDictionaryRef) { // Simple destination dictionary.
  28628. var value = nameDictionaryRef.get(destinationId);
  28629. if (value) {
  28630. dest = fetchDestination(value);
  28631. }
  28632. }
  28633. if (nameTreeRef) {
  28634. var nameTree = new NameTree(nameTreeRef, xref);
  28635. dest = fetchDestination(nameTree.get(destinationId));
  28636. }
  28637. return dest;
  28638. },
  28639. get attachments() {
  28640. var xref = this.xref;
  28641. var attachments = null, nameTreeRef;
  28642. var obj = this.catDict.get('Names');
  28643. if (obj) {
  28644. nameTreeRef = obj.getRaw('EmbeddedFiles');
  28645. }
  28646. if (nameTreeRef) {
  28647. var nameTree = new NameTree(nameTreeRef, xref);
  28648. var names = nameTree.getAll();
  28649. for (var name in names) {
  28650. if (!names.hasOwnProperty(name)) {
  28651. continue;
  28652. }
  28653. var fs = new FileSpec(names[name], xref);
  28654. if (!attachments) {
  28655. attachments = {};
  28656. }
  28657. attachments[stringToPDFString(name)] = fs.serializable;
  28658. }
  28659. }
  28660. return shadow(this, 'attachments', attachments);
  28661. },
  28662. get javaScript() {
  28663. var xref = this.xref;
  28664. var obj = this.catDict.get('Names');
  28665. var javaScript = [];
  28666. function appendIfJavaScriptDict(jsDict) {
  28667. var type = jsDict.get('S');
  28668. if (!isName(type) || type.name !== 'JavaScript') {
  28669. return;
  28670. }
  28671. var js = jsDict.get('JS');
  28672. if (isStream(js)) {
  28673. js = bytesToString(js.getBytes());
  28674. } else if (!isString(js)) {
  28675. return;
  28676. }
  28677. javaScript.push(stringToPDFString(js));
  28678. }
  28679. if (obj && obj.has('JavaScript')) {
  28680. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  28681. var names = nameTree.getAll();
  28682. for (var name in names) {
  28683. if (!names.hasOwnProperty(name)) {
  28684. continue;
  28685. }
  28686. // We don't really use the JavaScript right now. This code is
  28687. // defensive so we don't cause errors on document load.
  28688. var jsDict = names[name];
  28689. if (isDict(jsDict)) {
  28690. appendIfJavaScriptDict(jsDict);
  28691. }
  28692. }
  28693. }
  28694. // Append OpenAction actions to javaScript array
  28695. var openactionDict = this.catDict.get('OpenAction');
  28696. if (isDict(openactionDict, 'Action')) {
  28697. var actionType = openactionDict.get('S');
  28698. if (isName(actionType) && actionType.name === 'Named') {
  28699. // The named Print action is not a part of the PDF 1.7 specification,
  28700. // but is supported by many PDF readers/writers (including Adobe's).
  28701. var action = openactionDict.get('N');
  28702. if (isName(action) && action.name === 'Print') {
  28703. javaScript.push('print({});');
  28704. }
  28705. } else {
  28706. appendIfJavaScriptDict(openactionDict);
  28707. }
  28708. }
  28709. return shadow(this, 'javaScript', javaScript);
  28710. },
  28711. cleanup: function Catalog_cleanup() {
  28712. var promises = [];
  28713. this.fontCache.forEach(function (promise) {
  28714. promises.push(promise);
  28715. });
  28716. return Promise.all(promises).then(function (translatedFonts) {
  28717. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  28718. var font = translatedFonts[i].dict;
  28719. delete font.translated;
  28720. }
  28721. this.fontCache.clear();
  28722. }.bind(this));
  28723. },
  28724. getPage: function Catalog_getPage(pageIndex) {
  28725. if (!(pageIndex in this.pagePromises)) {
  28726. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  28727. function (a) {
  28728. var dict = a[0];
  28729. var ref = a[1];
  28730. return this.pageFactory.createPage(pageIndex, dict, ref,
  28731. this.fontCache);
  28732. }.bind(this)
  28733. );
  28734. }
  28735. return this.pagePromises[pageIndex];
  28736. },
  28737. getPageDict: function Catalog_getPageDict(pageIndex) {
  28738. var capability = createPromiseCapability();
  28739. var nodesToVisit = [this.catDict.getRaw('Pages')];
  28740. var currentPageIndex = 0;
  28741. var xref = this.xref;
  28742. var checkAllKids = false;
  28743. function next() {
  28744. while (nodesToVisit.length) {
  28745. var currentNode = nodesToVisit.pop();
  28746. if (isRef(currentNode)) {
  28747. xref.fetchAsync(currentNode).then(function (obj) {
  28748. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  28749. if (pageIndex === currentPageIndex) {
  28750. capability.resolve([obj, currentNode]);
  28751. } else {
  28752. currentPageIndex++;
  28753. next();
  28754. }
  28755. return;
  28756. }
  28757. nodesToVisit.push(obj);
  28758. next();
  28759. }, capability.reject);
  28760. return;
  28761. }
  28762. // Must be a child page dictionary.
  28763. assert(
  28764. isDict(currentNode),
  28765. 'page dictionary kid reference points to wrong type of object'
  28766. );
  28767. var count = currentNode.get('Count');
  28768. // If the current node doesn't have any children, avoid getting stuck
  28769. // in an empty node further down in the tree (see issue5644.pdf).
  28770. if (count === 0) {
  28771. checkAllKids = true;
  28772. }
  28773. // Skip nodes where the page can't be.
  28774. if (currentPageIndex + count <= pageIndex) {
  28775. currentPageIndex += count;
  28776. continue;
  28777. }
  28778. var kids = currentNode.get('Kids');
  28779. assert(isArray(kids), 'page dictionary kids object is not an array');
  28780. if (!checkAllKids && count === kids.length) {
  28781. // Nodes that don't have the page have been skipped and this is the
  28782. // bottom of the tree which means the page requested must be a
  28783. // descendant of this pages node. Ideally we would just resolve the
  28784. // promise with the page ref here, but there is the case where more
  28785. // pages nodes could link to single a page (see issue 3666 pdf). To
  28786. // handle this push it back on the queue so if it is a pages node it
  28787. // will be descended into.
  28788. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  28789. currentPageIndex = pageIndex;
  28790. continue;
  28791. } else {
  28792. for (var last = kids.length - 1; last >= 0; last--) {
  28793. nodesToVisit.push(kids[last]);
  28794. }
  28795. }
  28796. }
  28797. capability.reject('Page index ' + pageIndex + ' not found.');
  28798. }
  28799. next();
  28800. return capability.promise;
  28801. },
  28802. getPageIndex: function Catalog_getPageIndex(ref) {
  28803. // The page tree nodes have the count of all the leaves below them. To get
  28804. // how many pages are before we just have to walk up the tree and keep
  28805. // adding the count of siblings to the left of the node.
  28806. var xref = this.xref;
  28807. function pagesBeforeRef(kidRef) {
  28808. var total = 0;
  28809. var parentRef;
  28810. return xref.fetchAsync(kidRef).then(function (node) {
  28811. if (!node) {
  28812. return null;
  28813. }
  28814. parentRef = node.getRaw('Parent');
  28815. return node.getAsync('Parent');
  28816. }).then(function (parent) {
  28817. if (!parent) {
  28818. return null;
  28819. }
  28820. return parent.getAsync('Kids');
  28821. }).then(function (kids) {
  28822. if (!kids) {
  28823. return null;
  28824. }
  28825. var kidPromises = [];
  28826. var found = false;
  28827. for (var i = 0; i < kids.length; i++) {
  28828. var kid = kids[i];
  28829. assert(isRef(kid), 'kids must be a ref');
  28830. if (kid.num === kidRef.num) {
  28831. found = true;
  28832. break;
  28833. }
  28834. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  28835. if (kid.has('Count')) {
  28836. var count = kid.get('Count');
  28837. total += count;
  28838. } else { // page leaf node
  28839. total++;
  28840. }
  28841. }));
  28842. }
  28843. if (!found) {
  28844. error('kid ref not found in parents kids');
  28845. }
  28846. return Promise.all(kidPromises).then(function () {
  28847. return [total, parentRef];
  28848. });
  28849. });
  28850. }
  28851. var total = 0;
  28852. function next(ref) {
  28853. return pagesBeforeRef(ref).then(function (args) {
  28854. if (!args) {
  28855. return total;
  28856. }
  28857. var count = args[0];
  28858. var parentRef = args[1];
  28859. total += count;
  28860. return next(parentRef);
  28861. });
  28862. }
  28863. return next(ref);
  28864. }
  28865. };
  28866. return Catalog;
  28867. })();
  28868. var XRef = (function XRefClosure() {
  28869. function XRef(stream, password) {
  28870. this.stream = stream;
  28871. this.entries = [];
  28872. this.xrefstms = {};
  28873. // prepare the XRef cache
  28874. this.cache = [];
  28875. this.password = password;
  28876. this.stats = {
  28877. streamTypes: [],
  28878. fontTypes: []
  28879. };
  28880. }
  28881. XRef.prototype = {
  28882. setStartXRef: function XRef_setStartXRef(startXRef) {
  28883. // Store the starting positions of xref tables as we process them
  28884. // so we can recover from missing data errors
  28885. this.startXRefQueue = [startXRef];
  28886. },
  28887. parse: function XRef_parse(recoveryMode) {
  28888. var trailerDict;
  28889. if (!recoveryMode) {
  28890. trailerDict = this.readXRef();
  28891. } else {
  28892. warn('Indexing all PDF objects');
  28893. trailerDict = this.indexObjects();
  28894. }
  28895. trailerDict.assignXref(this);
  28896. this.trailer = trailerDict;
  28897. var encrypt = trailerDict.get('Encrypt');
  28898. if (encrypt) {
  28899. var ids = trailerDict.get('ID');
  28900. var fileId = (ids && ids.length) ? ids[0] : '';
  28901. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  28902. this.password);
  28903. }
  28904. // get the root dictionary (catalog) object
  28905. if (!(this.root = trailerDict.get('Root'))) {
  28906. error('Invalid root reference');
  28907. }
  28908. },
  28909. processXRefTable: function XRef_processXRefTable(parser) {
  28910. if (!('tableState' in this)) {
  28911. // Stores state of the table as we process it so we can resume
  28912. // from middle of table in case of missing data error
  28913. this.tableState = {
  28914. entryNum: 0,
  28915. streamPos: parser.lexer.stream.pos,
  28916. parserBuf1: parser.buf1,
  28917. parserBuf2: parser.buf2
  28918. };
  28919. }
  28920. var obj = this.readXRefTable(parser);
  28921. // Sanity check
  28922. if (!isCmd(obj, 'trailer')) {
  28923. error('Invalid XRef table: could not find trailer dictionary');
  28924. }
  28925. // Read trailer dictionary, e.g.
  28926. // trailer
  28927. // << /Size 22
  28928. // /Root 20R
  28929. // /Info 10R
  28930. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  28931. // >>
  28932. // The parser goes through the entire stream << ... >> and provides
  28933. // a getter interface for the key-value table
  28934. var dict = parser.getObj();
  28935. // The pdflib PDF generator can generate a nested trailer dictionary
  28936. if (!isDict(dict) && dict.dict) {
  28937. dict = dict.dict;
  28938. }
  28939. if (!isDict(dict)) {
  28940. error('Invalid XRef table: could not parse trailer dictionary');
  28941. }
  28942. delete this.tableState;
  28943. return dict;
  28944. },
  28945. readXRefTable: function XRef_readXRefTable(parser) {
  28946. // Example of cross-reference table:
  28947. // xref
  28948. // 0 1 <-- subsection header (first obj #, obj count)
  28949. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  28950. // 23 2 <-- subsection header ... and so on ...
  28951. // 0000025518 00002 n
  28952. // 0000025635 00000 n
  28953. // trailer
  28954. // ...
  28955. var stream = parser.lexer.stream;
  28956. var tableState = this.tableState;
  28957. stream.pos = tableState.streamPos;
  28958. parser.buf1 = tableState.parserBuf1;
  28959. parser.buf2 = tableState.parserBuf2;
  28960. // Outer loop is over subsection headers
  28961. var obj;
  28962. while (true) {
  28963. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  28964. if (isCmd(obj = parser.getObj(), 'trailer')) {
  28965. break;
  28966. }
  28967. tableState.firstEntryNum = obj;
  28968. tableState.entryCount = parser.getObj();
  28969. }
  28970. var first = tableState.firstEntryNum;
  28971. var count = tableState.entryCount;
  28972. if (!isInt(first) || !isInt(count)) {
  28973. error('Invalid XRef table: wrong types in subsection header');
  28974. }
  28975. // Inner loop is over objects themselves
  28976. for (var i = tableState.entryNum; i < count; i++) {
  28977. tableState.streamPos = stream.pos;
  28978. tableState.entryNum = i;
  28979. tableState.parserBuf1 = parser.buf1;
  28980. tableState.parserBuf2 = parser.buf2;
  28981. var entry = {};
  28982. entry.offset = parser.getObj();
  28983. entry.gen = parser.getObj();
  28984. var type = parser.getObj();
  28985. if (isCmd(type, 'f')) {
  28986. entry.free = true;
  28987. } else if (isCmd(type, 'n')) {
  28988. entry.uncompressed = true;
  28989. }
  28990. // Validate entry obj
  28991. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  28992. !(entry.free || entry.uncompressed)) {
  28993. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  28994. }
  28995. if (!this.entries[i + first]) {
  28996. this.entries[i + first] = entry;
  28997. }
  28998. }
  28999. tableState.entryNum = 0;
  29000. tableState.streamPos = stream.pos;
  29001. tableState.parserBuf1 = parser.buf1;
  29002. tableState.parserBuf2 = parser.buf2;
  29003. delete tableState.firstEntryNum;
  29004. delete tableState.entryCount;
  29005. }
  29006. // Per issue 3248: hp scanners generate bad XRef
  29007. if (first === 1 && this.entries[1] && this.entries[1].free) {
  29008. // shifting the entries
  29009. this.entries.shift();
  29010. }
  29011. // Sanity check: as per spec, first object must be free
  29012. if (this.entries[0] && !this.entries[0].free) {
  29013. error('Invalid XRef table: unexpected first object');
  29014. }
  29015. return obj;
  29016. },
  29017. processXRefStream: function XRef_processXRefStream(stream) {
  29018. if (!('streamState' in this)) {
  29019. // Stores state of the stream as we process it so we can resume
  29020. // from middle of stream in case of missing data error
  29021. var streamParameters = stream.dict;
  29022. var byteWidths = streamParameters.get('W');
  29023. var range = streamParameters.get('Index');
  29024. if (!range) {
  29025. range = [0, streamParameters.get('Size')];
  29026. }
  29027. this.streamState = {
  29028. entryRanges: range,
  29029. byteWidths: byteWidths,
  29030. entryNum: 0,
  29031. streamPos: stream.pos
  29032. };
  29033. }
  29034. this.readXRefStream(stream);
  29035. delete this.streamState;
  29036. return stream.dict;
  29037. },
  29038. readXRefStream: function XRef_readXRefStream(stream) {
  29039. var i, j;
  29040. var streamState = this.streamState;
  29041. stream.pos = streamState.streamPos;
  29042. var byteWidths = streamState.byteWidths;
  29043. var typeFieldWidth = byteWidths[0];
  29044. var offsetFieldWidth = byteWidths[1];
  29045. var generationFieldWidth = byteWidths[2];
  29046. var entryRanges = streamState.entryRanges;
  29047. while (entryRanges.length > 0) {
  29048. var first = entryRanges[0];
  29049. var n = entryRanges[1];
  29050. if (!isInt(first) || !isInt(n)) {
  29051. error('Invalid XRef range fields: ' + first + ', ' + n);
  29052. }
  29053. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  29054. !isInt(generationFieldWidth)) {
  29055. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  29056. }
  29057. for (i = streamState.entryNum; i < n; ++i) {
  29058. streamState.entryNum = i;
  29059. streamState.streamPos = stream.pos;
  29060. var type = 0, offset = 0, generation = 0;
  29061. for (j = 0; j < typeFieldWidth; ++j) {
  29062. type = (type << 8) | stream.getByte();
  29063. }
  29064. // if type field is absent, its default value is 1
  29065. if (typeFieldWidth === 0) {
  29066. type = 1;
  29067. }
  29068. for (j = 0; j < offsetFieldWidth; ++j) {
  29069. offset = (offset << 8) | stream.getByte();
  29070. }
  29071. for (j = 0; j < generationFieldWidth; ++j) {
  29072. generation = (generation << 8) | stream.getByte();
  29073. }
  29074. var entry = {};
  29075. entry.offset = offset;
  29076. entry.gen = generation;
  29077. switch (type) {
  29078. case 0:
  29079. entry.free = true;
  29080. break;
  29081. case 1:
  29082. entry.uncompressed = true;
  29083. break;
  29084. case 2:
  29085. break;
  29086. default:
  29087. error('Invalid XRef entry type: ' + type);
  29088. }
  29089. if (!this.entries[first + i]) {
  29090. this.entries[first + i] = entry;
  29091. }
  29092. }
  29093. streamState.entryNum = 0;
  29094. streamState.streamPos = stream.pos;
  29095. entryRanges.splice(0, 2);
  29096. }
  29097. },
  29098. indexObjects: function XRef_indexObjects() {
  29099. // Simple scan through the PDF content to find objects,
  29100. // trailers and XRef streams.
  29101. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  29102. var PERCENT = 0x25, LT = 0x3C;
  29103. function readToken(data, offset) {
  29104. var token = '', ch = data[offset];
  29105. while (ch !== LF && ch !== CR && ch !== LT) {
  29106. if (++offset >= data.length) {
  29107. break;
  29108. }
  29109. token += String.fromCharCode(ch);
  29110. ch = data[offset];
  29111. }
  29112. return token;
  29113. }
  29114. function skipUntil(data, offset, what) {
  29115. var length = what.length, dataLength = data.length;
  29116. var skipped = 0;
  29117. // finding byte sequence
  29118. while (offset < dataLength) {
  29119. var i = 0;
  29120. while (i < length && data[offset + i] === what[i]) {
  29121. ++i;
  29122. }
  29123. if (i >= length) {
  29124. break; // sequence found
  29125. }
  29126. offset++;
  29127. skipped++;
  29128. }
  29129. return skipped;
  29130. }
  29131. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  29132. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  29133. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  29134. 101, 102]);
  29135. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  29136. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  29137. // Clear out any existing entries, since they may be bogus.
  29138. this.entries.length = 0;
  29139. var stream = this.stream;
  29140. stream.pos = 0;
  29141. var buffer = stream.getBytes();
  29142. var position = stream.start, length = buffer.length;
  29143. var trailers = [], xrefStms = [];
  29144. while (position < length) {
  29145. var ch = buffer[position];
  29146. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  29147. ++position;
  29148. continue;
  29149. }
  29150. if (ch === PERCENT) { // %-comment
  29151. do {
  29152. ++position;
  29153. if (position >= length) {
  29154. break;
  29155. }
  29156. ch = buffer[position];
  29157. } while (ch !== LF && ch !== CR);
  29158. continue;
  29159. }
  29160. var token = readToken(buffer, position);
  29161. var m;
  29162. if (token.indexOf('xref') === 0 &&
  29163. (token.length === 4 || /\s/.test(token[4]))) {
  29164. position += skipUntil(buffer, position, trailerBytes);
  29165. trailers.push(position);
  29166. position += skipUntil(buffer, position, startxrefBytes);
  29167. } else if ((m = objRegExp.exec(token))) {
  29168. if (typeof this.entries[m[1]] === 'undefined') {
  29169. this.entries[m[1]] = {
  29170. offset: position - stream.start,
  29171. gen: m[2] | 0,
  29172. uncompressed: true
  29173. };
  29174. }
  29175. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  29176. var content = buffer.subarray(position, position + contentLength);
  29177. // checking XRef stream suspect
  29178. // (it shall have '/XRef' and next char is not a letter)
  29179. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  29180. if (xrefTagOffset < contentLength &&
  29181. content[xrefTagOffset + 5] < 64) {
  29182. xrefStms.push(position - stream.start);
  29183. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  29184. }
  29185. position += contentLength;
  29186. } else if (token.indexOf('trailer') === 0 &&
  29187. (token.length === 7 || /\s/.test(token[7]))) {
  29188. trailers.push(position);
  29189. position += skipUntil(buffer, position, startxrefBytes);
  29190. } else {
  29191. position += token.length + 1;
  29192. }
  29193. }
  29194. // reading XRef streams
  29195. var i, ii;
  29196. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  29197. this.startXRefQueue.push(xrefStms[i]);
  29198. this.readXRef(/* recoveryMode */ true);
  29199. }
  29200. // finding main trailer
  29201. var dict;
  29202. for (i = 0, ii = trailers.length; i < ii; ++i) {
  29203. stream.pos = trailers[i];
  29204. var parser = new Parser(new Lexer(stream), true, this);
  29205. var obj = parser.getObj();
  29206. if (!isCmd(obj, 'trailer')) {
  29207. continue;
  29208. }
  29209. // read the trailer dictionary
  29210. if (!isDict(dict = parser.getObj())) {
  29211. continue;
  29212. }
  29213. // taking the first one with 'ID'
  29214. if (dict.has('ID')) {
  29215. return dict;
  29216. }
  29217. }
  29218. // no tailer with 'ID', taking last one (if exists)
  29219. if (dict) {
  29220. return dict;
  29221. }
  29222. // nothing helps
  29223. // calling error() would reject worker with an UnknownErrorException.
  29224. throw new InvalidPDFException('Invalid PDF structure');
  29225. },
  29226. readXRef: function XRef_readXRef(recoveryMode) {
  29227. var stream = this.stream;
  29228. try {
  29229. while (this.startXRefQueue.length) {
  29230. var startXRef = this.startXRefQueue[0];
  29231. stream.pos = startXRef + stream.start;
  29232. var parser = new Parser(new Lexer(stream), true, this);
  29233. var obj = parser.getObj();
  29234. var dict;
  29235. // Get dictionary
  29236. if (isCmd(obj, 'xref')) {
  29237. // Parse end-of-file XRef
  29238. dict = this.processXRefTable(parser);
  29239. if (!this.topDict) {
  29240. this.topDict = dict;
  29241. }
  29242. // Recursively get other XRefs 'XRefStm', if any
  29243. obj = dict.get('XRefStm');
  29244. if (isInt(obj)) {
  29245. var pos = obj;
  29246. // ignore previously loaded xref streams
  29247. // (possible infinite recursion)
  29248. if (!(pos in this.xrefstms)) {
  29249. this.xrefstms[pos] = 1;
  29250. this.startXRefQueue.push(pos);
  29251. }
  29252. }
  29253. } else if (isInt(obj)) {
  29254. // Parse in-stream XRef
  29255. if (!isInt(parser.getObj()) ||
  29256. !isCmd(parser.getObj(), 'obj') ||
  29257. !isStream(obj = parser.getObj())) {
  29258. error('Invalid XRef stream');
  29259. }
  29260. dict = this.processXRefStream(obj);
  29261. if (!this.topDict) {
  29262. this.topDict = dict;
  29263. }
  29264. if (!dict) {
  29265. error('Failed to read XRef stream');
  29266. }
  29267. } else {
  29268. error('Invalid XRef stream header');
  29269. }
  29270. // Recursively get previous dictionary, if any
  29271. obj = dict.get('Prev');
  29272. if (isInt(obj)) {
  29273. this.startXRefQueue.push(obj);
  29274. } else if (isRef(obj)) {
  29275. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  29276. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  29277. this.startXRefQueue.push(obj.num);
  29278. }
  29279. this.startXRefQueue.shift();
  29280. }
  29281. return this.topDict;
  29282. } catch (e) {
  29283. if (e instanceof MissingDataException) {
  29284. throw e;
  29285. }
  29286. info('(while reading XRef): ' + e);
  29287. }
  29288. if (recoveryMode) {
  29289. return;
  29290. }
  29291. throw new XRefParseException();
  29292. },
  29293. getEntry: function XRef_getEntry(i) {
  29294. var xrefEntry = this.entries[i];
  29295. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  29296. return xrefEntry;
  29297. }
  29298. return null;
  29299. },
  29300. fetchIfRef: function XRef_fetchIfRef(obj) {
  29301. if (!isRef(obj)) {
  29302. return obj;
  29303. }
  29304. return this.fetch(obj);
  29305. },
  29306. fetch: function XRef_fetch(ref, suppressEncryption) {
  29307. assert(isRef(ref), 'ref object is not a reference');
  29308. var num = ref.num;
  29309. if (num in this.cache) {
  29310. var cacheEntry = this.cache[num];
  29311. return cacheEntry;
  29312. }
  29313. var xrefEntry = this.getEntry(num);
  29314. // the referenced entry can be free
  29315. if (xrefEntry === null) {
  29316. return (this.cache[num] = null);
  29317. }
  29318. if (xrefEntry.uncompressed) {
  29319. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  29320. } else {
  29321. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  29322. }
  29323. if (isDict(xrefEntry)){
  29324. xrefEntry.objId = ref.toString();
  29325. } else if (isStream(xrefEntry)) {
  29326. xrefEntry.dict.objId = ref.toString();
  29327. }
  29328. return xrefEntry;
  29329. },
  29330. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  29331. suppressEncryption) {
  29332. var gen = ref.gen;
  29333. var num = ref.num;
  29334. if (xrefEntry.gen !== gen) {
  29335. error('inconsistent generation in XRef');
  29336. }
  29337. var stream = this.stream.makeSubStream(xrefEntry.offset +
  29338. this.stream.start);
  29339. var parser = new Parser(new Lexer(stream), true, this);
  29340. var obj1 = parser.getObj();
  29341. var obj2 = parser.getObj();
  29342. var obj3 = parser.getObj();
  29343. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  29344. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  29345. !isCmd(obj3)) {
  29346. error('bad XRef entry');
  29347. }
  29348. if (!isCmd(obj3, 'obj')) {
  29349. // some bad PDFs use "obj1234" and really mean 1234
  29350. if (obj3.cmd.indexOf('obj') === 0) {
  29351. num = parseInt(obj3.cmd.substring(3), 10);
  29352. if (!isNaN(num)) {
  29353. return num;
  29354. }
  29355. }
  29356. error('bad XRef entry');
  29357. }
  29358. if (this.encrypt && !suppressEncryption) {
  29359. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  29360. } else {
  29361. xrefEntry = parser.getObj();
  29362. }
  29363. if (!isStream(xrefEntry)) {
  29364. this.cache[num] = xrefEntry;
  29365. }
  29366. return xrefEntry;
  29367. },
  29368. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  29369. suppressEncryption) {
  29370. var tableOffset = xrefEntry.offset;
  29371. var stream = this.fetch(new Ref(tableOffset, 0));
  29372. if (!isStream(stream)) {
  29373. error('bad ObjStm stream');
  29374. }
  29375. var first = stream.dict.get('First');
  29376. var n = stream.dict.get('N');
  29377. if (!isInt(first) || !isInt(n)) {
  29378. error('invalid first and n parameters for ObjStm stream');
  29379. }
  29380. var parser = new Parser(new Lexer(stream), false, this);
  29381. parser.allowStreams = true;
  29382. var i, entries = [], num, nums = [];
  29383. // read the object numbers to populate cache
  29384. for (i = 0; i < n; ++i) {
  29385. num = parser.getObj();
  29386. if (!isInt(num)) {
  29387. error('invalid object number in the ObjStm stream: ' + num);
  29388. }
  29389. nums.push(num);
  29390. var offset = parser.getObj();
  29391. if (!isInt(offset)) {
  29392. error('invalid object offset in the ObjStm stream: ' + offset);
  29393. }
  29394. }
  29395. // read stream objects for cache
  29396. for (i = 0; i < n; ++i) {
  29397. entries.push(parser.getObj());
  29398. num = nums[i];
  29399. var entry = this.entries[num];
  29400. if (entry && entry.offset === tableOffset && entry.gen === i) {
  29401. this.cache[num] = entries[i];
  29402. }
  29403. }
  29404. xrefEntry = entries[xrefEntry.gen];
  29405. if (xrefEntry === undefined) {
  29406. error('bad XRef entry for compressed object');
  29407. }
  29408. return xrefEntry;
  29409. },
  29410. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  29411. if (!isRef(obj)) {
  29412. return Promise.resolve(obj);
  29413. }
  29414. return this.fetchAsync(obj);
  29415. },
  29416. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  29417. var streamManager = this.stream.manager;
  29418. var xref = this;
  29419. return new Promise(function tryFetch(resolve, reject) {
  29420. try {
  29421. resolve(xref.fetch(ref, suppressEncryption));
  29422. } catch (e) {
  29423. if (e instanceof MissingDataException) {
  29424. streamManager.requestRange(e.begin, e.end).then(function () {
  29425. tryFetch(resolve, reject);
  29426. }, reject);
  29427. return;
  29428. }
  29429. reject(e);
  29430. }
  29431. });
  29432. },
  29433. getCatalogObj: function XRef_getCatalogObj() {
  29434. return this.root;
  29435. }
  29436. };
  29437. return XRef;
  29438. })();
  29439. /**
  29440. * A NameTree is like a Dict but has some advantageous properties, see the
  29441. * spec (7.9.6) for more details.
  29442. * TODO: implement all the Dict functions and make this more efficent.
  29443. */
  29444. var NameTree = (function NameTreeClosure() {
  29445. function NameTree(root, xref) {
  29446. this.root = root;
  29447. this.xref = xref;
  29448. }
  29449. NameTree.prototype = {
  29450. getAll: function NameTree_getAll() {
  29451. var dict = {};
  29452. if (!this.root) {
  29453. return dict;
  29454. }
  29455. var xref = this.xref;
  29456. // reading name tree
  29457. var processed = new RefSet();
  29458. processed.put(this.root);
  29459. var queue = [this.root];
  29460. while (queue.length > 0) {
  29461. var i, n;
  29462. var obj = xref.fetchIfRef(queue.shift());
  29463. if (!isDict(obj)) {
  29464. continue;
  29465. }
  29466. if (obj.has('Kids')) {
  29467. var kids = obj.get('Kids');
  29468. for (i = 0, n = kids.length; i < n; i++) {
  29469. var kid = kids[i];
  29470. if (processed.has(kid)) {
  29471. error('invalid destinations');
  29472. }
  29473. queue.push(kid);
  29474. processed.put(kid);
  29475. }
  29476. continue;
  29477. }
  29478. var names = obj.get('Names');
  29479. if (names) {
  29480. for (i = 0, n = names.length; i < n; i += 2) {
  29481. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  29482. }
  29483. }
  29484. }
  29485. return dict;
  29486. },
  29487. get: function NameTree_get(destinationId) {
  29488. if (!this.root) {
  29489. return null;
  29490. }
  29491. var xref = this.xref;
  29492. var kidsOrNames = xref.fetchIfRef(this.root);
  29493. var loopCount = 0;
  29494. var MAX_NAMES_LEVELS = 10;
  29495. var l, r, m;
  29496. // Perform a binary search to quickly find the entry that
  29497. // contains the named destination we are looking for.
  29498. while (kidsOrNames.has('Kids')) {
  29499. loopCount++;
  29500. if (loopCount > MAX_NAMES_LEVELS) {
  29501. warn('Search depth limit for named destionations has been reached.');
  29502. return null;
  29503. }
  29504. var kids = kidsOrNames.get('Kids');
  29505. if (!isArray(kids)) {
  29506. return null;
  29507. }
  29508. l = 0;
  29509. r = kids.length - 1;
  29510. while (l <= r) {
  29511. m = (l + r) >> 1;
  29512. var kid = xref.fetchIfRef(kids[m]);
  29513. var limits = kid.get('Limits');
  29514. if (destinationId < xref.fetchIfRef(limits[0])) {
  29515. r = m - 1;
  29516. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  29517. l = m + 1;
  29518. } else {
  29519. kidsOrNames = xref.fetchIfRef(kids[m]);
  29520. break;
  29521. }
  29522. }
  29523. if (l > r) {
  29524. return null;
  29525. }
  29526. }
  29527. // If we get here, then we have found the right entry. Now
  29528. // go through the named destinations in the Named dictionary
  29529. // until we find the exact destination we're looking for.
  29530. var names = kidsOrNames.get('Names');
  29531. if (isArray(names)) {
  29532. // Perform a binary search to reduce the lookup time.
  29533. l = 0;
  29534. r = names.length - 2;
  29535. while (l <= r) {
  29536. // Check only even indices (0, 2, 4, ...) because the
  29537. // odd indices contain the actual D array.
  29538. m = (l + r) & ~1;
  29539. if (destinationId < xref.fetchIfRef(names[m])) {
  29540. r = m - 2;
  29541. } else if (destinationId > xref.fetchIfRef(names[m])) {
  29542. l = m + 2;
  29543. } else {
  29544. return xref.fetchIfRef(names[m + 1]);
  29545. }
  29546. }
  29547. }
  29548. return null;
  29549. }
  29550. };
  29551. return NameTree;
  29552. })();
  29553. /**
  29554. * "A PDF file can refer to the contents of another file by using a File
  29555. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  29556. * NOTE: Only embedded files are supported (as part of the attachments support)
  29557. * TODO: support the 'URL' file system (with caching if !/V), portable
  29558. * collections attributes and related files (/RF)
  29559. */
  29560. var FileSpec = (function FileSpecClosure() {
  29561. function FileSpec(root, xref) {
  29562. if (!root || !isDict(root)) {
  29563. return;
  29564. }
  29565. this.xref = xref;
  29566. this.root = root;
  29567. if (root.has('FS')) {
  29568. this.fs = root.get('FS');
  29569. }
  29570. this.description = root.has('Desc') ?
  29571. stringToPDFString(root.get('Desc')) :
  29572. '';
  29573. if (root.has('RF')) {
  29574. warn('Related file specifications are not supported');
  29575. }
  29576. this.contentAvailable = true;
  29577. if (!root.has('EF')) {
  29578. this.contentAvailable = false;
  29579. warn('Non-embedded file specifications are not supported');
  29580. }
  29581. }
  29582. function pickPlatformItem(dict) {
  29583. // Look for the filename in this order:
  29584. // UF, F, Unix, Mac, DOS
  29585. if (dict.has('UF')) {
  29586. return dict.get('UF');
  29587. } else if (dict.has('F')) {
  29588. return dict.get('F');
  29589. } else if (dict.has('Unix')) {
  29590. return dict.get('Unix');
  29591. } else if (dict.has('Mac')) {
  29592. return dict.get('Mac');
  29593. } else if (dict.has('DOS')) {
  29594. return dict.get('DOS');
  29595. } else {
  29596. return null;
  29597. }
  29598. }
  29599. FileSpec.prototype = {
  29600. get filename() {
  29601. if (!this._filename && this.root) {
  29602. var filename = pickPlatformItem(this.root) || 'unnamed';
  29603. this._filename = stringToPDFString(filename).
  29604. replace(/\\\\/g, '\\').
  29605. replace(/\\\//g, '/').
  29606. replace(/\\/g, '/');
  29607. }
  29608. return this._filename;
  29609. },
  29610. get content() {
  29611. if (!this.contentAvailable) {
  29612. return null;
  29613. }
  29614. if (!this.contentRef && this.root) {
  29615. this.contentRef = pickPlatformItem(this.root.get('EF'));
  29616. }
  29617. var content = null;
  29618. if (this.contentRef) {
  29619. var xref = this.xref;
  29620. var fileObj = xref.fetchIfRef(this.contentRef);
  29621. if (fileObj && isStream(fileObj)) {
  29622. content = fileObj.getBytes();
  29623. } else {
  29624. warn('Embedded file specification points to non-existing/invalid ' +
  29625. 'content');
  29626. }
  29627. } else {
  29628. warn('Embedded file specification does not have a content');
  29629. }
  29630. return content;
  29631. },
  29632. get serializable() {
  29633. return {
  29634. filename: this.filename,
  29635. content: this.content
  29636. };
  29637. }
  29638. };
  29639. return FileSpec;
  29640. })();
  29641. /**
  29642. * A helper for loading missing data in object graphs. It traverses the graph
  29643. * depth first and queues up any objects that have missing data. Once it has
  29644. * has traversed as many objects that are available it attempts to bundle the
  29645. * missing data requests and then resume from the nodes that weren't ready.
  29646. *
  29647. * NOTE: It provides protection from circular references by keeping track of
  29648. * of loaded references. However, you must be careful not to load any graphs
  29649. * that have references to the catalog or other pages since that will cause the
  29650. * entire PDF document object graph to be traversed.
  29651. */
  29652. var ObjectLoader = (function() {
  29653. function mayHaveChildren(value) {
  29654. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  29655. }
  29656. function addChildren(node, nodesToVisit) {
  29657. var value;
  29658. if (isDict(node) || isStream(node)) {
  29659. var map;
  29660. if (isDict(node)) {
  29661. map = node.map;
  29662. } else {
  29663. map = node.dict.map;
  29664. }
  29665. for (var key in map) {
  29666. value = map[key];
  29667. if (mayHaveChildren(value)) {
  29668. nodesToVisit.push(value);
  29669. }
  29670. }
  29671. } else if (isArray(node)) {
  29672. for (var i = 0, ii = node.length; i < ii; i++) {
  29673. value = node[i];
  29674. if (mayHaveChildren(value)) {
  29675. nodesToVisit.push(value);
  29676. }
  29677. }
  29678. }
  29679. }
  29680. function ObjectLoader(obj, keys, xref) {
  29681. this.obj = obj;
  29682. this.keys = keys;
  29683. this.xref = xref;
  29684. this.refSet = null;
  29685. this.capability = null;
  29686. }
  29687. ObjectLoader.prototype = {
  29688. load: function ObjectLoader_load() {
  29689. var keys = this.keys;
  29690. this.capability = createPromiseCapability();
  29691. // Don't walk the graph if all the data is already loaded.
  29692. if (!(this.xref.stream instanceof ChunkedStream) ||
  29693. this.xref.stream.getMissingChunks().length === 0) {
  29694. this.capability.resolve();
  29695. return this.capability.promise;
  29696. }
  29697. this.refSet = new RefSet();
  29698. // Setup the initial nodes to visit.
  29699. var nodesToVisit = [];
  29700. for (var i = 0; i < keys.length; i++) {
  29701. nodesToVisit.push(this.obj[keys[i]]);
  29702. }
  29703. this._walk(nodesToVisit);
  29704. return this.capability.promise;
  29705. },
  29706. _walk: function ObjectLoader_walk(nodesToVisit) {
  29707. var nodesToRevisit = [];
  29708. var pendingRequests = [];
  29709. // DFS walk of the object graph.
  29710. while (nodesToVisit.length) {
  29711. var currentNode = nodesToVisit.pop();
  29712. // Only references or chunked streams can cause missing data exceptions.
  29713. if (isRef(currentNode)) {
  29714. // Skip nodes that have already been visited.
  29715. if (this.refSet.has(currentNode)) {
  29716. continue;
  29717. }
  29718. try {
  29719. var ref = currentNode;
  29720. this.refSet.put(ref);
  29721. currentNode = this.xref.fetch(currentNode);
  29722. } catch (e) {
  29723. if (!(e instanceof MissingDataException)) {
  29724. throw e;
  29725. }
  29726. nodesToRevisit.push(currentNode);
  29727. pendingRequests.push({ begin: e.begin, end: e.end });
  29728. }
  29729. }
  29730. if (currentNode && currentNode.getBaseStreams) {
  29731. var baseStreams = currentNode.getBaseStreams();
  29732. var foundMissingData = false;
  29733. for (var i = 0; i < baseStreams.length; i++) {
  29734. var stream = baseStreams[i];
  29735. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  29736. foundMissingData = true;
  29737. pendingRequests.push({
  29738. begin: stream.start,
  29739. end: stream.end
  29740. });
  29741. }
  29742. }
  29743. if (foundMissingData) {
  29744. nodesToRevisit.push(currentNode);
  29745. }
  29746. }
  29747. addChildren(currentNode, nodesToVisit);
  29748. }
  29749. if (pendingRequests.length) {
  29750. this.xref.stream.manager.requestRanges(pendingRequests).then(
  29751. function pendingRequestCallback() {
  29752. nodesToVisit = nodesToRevisit;
  29753. for (var i = 0; i < nodesToRevisit.length; i++) {
  29754. var node = nodesToRevisit[i];
  29755. // Remove any reference nodes from the currrent refset so they
  29756. // aren't skipped when we revist them.
  29757. if (isRef(node)) {
  29758. this.refSet.remove(node);
  29759. }
  29760. }
  29761. this._walk(nodesToVisit);
  29762. }.bind(this), this.capability.reject);
  29763. return;
  29764. }
  29765. // Everything is loaded.
  29766. this.refSet = null;
  29767. this.capability.resolve();
  29768. }
  29769. };
  29770. return ObjectLoader;
  29771. })();
  29772. exports.Catalog = Catalog;
  29773. exports.ObjectLoader = ObjectLoader;
  29774. exports.XRef = XRef;
  29775. }));
  29776. (function (root, factory) {
  29777. {
  29778. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29779. root.pdfjsCoreParser);
  29780. }
  29781. }(this, function (exports, sharedUtil, coreParser) {
  29782. var error = sharedUtil.error;
  29783. var EOF = coreParser.EOF;
  29784. var Lexer = coreParser.Lexer;
  29785. var PostScriptParser = (function PostScriptParserClosure() {
  29786. function PostScriptParser(lexer) {
  29787. this.lexer = lexer;
  29788. this.operators = [];
  29789. this.token = null;
  29790. this.prev = null;
  29791. }
  29792. PostScriptParser.prototype = {
  29793. nextToken: function PostScriptParser_nextToken() {
  29794. this.prev = this.token;
  29795. this.token = this.lexer.getToken();
  29796. },
  29797. accept: function PostScriptParser_accept(type) {
  29798. if (this.token.type === type) {
  29799. this.nextToken();
  29800. return true;
  29801. }
  29802. return false;
  29803. },
  29804. expect: function PostScriptParser_expect(type) {
  29805. if (this.accept(type)) {
  29806. return true;
  29807. }
  29808. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29809. type + '.');
  29810. },
  29811. parse: function PostScriptParser_parse() {
  29812. this.nextToken();
  29813. this.expect(PostScriptTokenTypes.LBRACE);
  29814. this.parseBlock();
  29815. this.expect(PostScriptTokenTypes.RBRACE);
  29816. return this.operators;
  29817. },
  29818. parseBlock: function PostScriptParser_parseBlock() {
  29819. while (true) {
  29820. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29821. this.operators.push(this.prev.value);
  29822. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29823. this.operators.push(this.prev.value);
  29824. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29825. this.parseCondition();
  29826. } else {
  29827. return;
  29828. }
  29829. }
  29830. },
  29831. parseCondition: function PostScriptParser_parseCondition() {
  29832. // Add two place holders that will be updated later
  29833. var conditionLocation = this.operators.length;
  29834. this.operators.push(null, null);
  29835. this.parseBlock();
  29836. this.expect(PostScriptTokenTypes.RBRACE);
  29837. if (this.accept(PostScriptTokenTypes.IF)) {
  29838. // The true block is right after the 'if' so it just falls through on
  29839. // true else it jumps and skips the true block.
  29840. this.operators[conditionLocation] = this.operators.length;
  29841. this.operators[conditionLocation + 1] = 'jz';
  29842. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29843. var jumpLocation = this.operators.length;
  29844. this.operators.push(null, null);
  29845. var endOfTrue = this.operators.length;
  29846. this.parseBlock();
  29847. this.expect(PostScriptTokenTypes.RBRACE);
  29848. this.expect(PostScriptTokenTypes.IFELSE);
  29849. // The jump is added at the end of the true block to skip the false
  29850. // block.
  29851. this.operators[jumpLocation] = this.operators.length;
  29852. this.operators[jumpLocation + 1] = 'j';
  29853. this.operators[conditionLocation] = endOfTrue;
  29854. this.operators[conditionLocation + 1] = 'jz';
  29855. } else {
  29856. error('PS Function: error parsing conditional.');
  29857. }
  29858. }
  29859. };
  29860. return PostScriptParser;
  29861. })();
  29862. var PostScriptTokenTypes = {
  29863. LBRACE: 0,
  29864. RBRACE: 1,
  29865. NUMBER: 2,
  29866. OPERATOR: 3,
  29867. IF: 4,
  29868. IFELSE: 5
  29869. };
  29870. var PostScriptToken = (function PostScriptTokenClosure() {
  29871. function PostScriptToken(type, value) {
  29872. this.type = type;
  29873. this.value = value;
  29874. }
  29875. var opCache = {};
  29876. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29877. var opValue = opCache[op];
  29878. if (opValue) {
  29879. return opValue;
  29880. }
  29881. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29882. };
  29883. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29884. '{');
  29885. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29886. '}');
  29887. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29888. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29889. 'IFELSE');
  29890. return PostScriptToken;
  29891. })();
  29892. var PostScriptLexer = (function PostScriptLexerClosure() {
  29893. function PostScriptLexer(stream) {
  29894. this.stream = stream;
  29895. this.nextChar();
  29896. this.strBuf = [];
  29897. }
  29898. PostScriptLexer.prototype = {
  29899. nextChar: function PostScriptLexer_nextChar() {
  29900. return (this.currentChar = this.stream.getByte());
  29901. },
  29902. getToken: function PostScriptLexer_getToken() {
  29903. var comment = false;
  29904. var ch = this.currentChar;
  29905. // skip comments
  29906. while (true) {
  29907. if (ch < 0) {
  29908. return EOF;
  29909. }
  29910. if (comment) {
  29911. if (ch === 0x0A || ch === 0x0D) {
  29912. comment = false;
  29913. }
  29914. } else if (ch === 0x25) { // '%'
  29915. comment = true;
  29916. } else if (!Lexer.isSpace(ch)) {
  29917. break;
  29918. }
  29919. ch = this.nextChar();
  29920. }
  29921. switch (ch | 0) {
  29922. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29923. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29924. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29925. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29926. this.getNumber());
  29927. case 0x7B: // '{'
  29928. this.nextChar();
  29929. return PostScriptToken.LBRACE;
  29930. case 0x7D: // '}'
  29931. this.nextChar();
  29932. return PostScriptToken.RBRACE;
  29933. }
  29934. // operator
  29935. var strBuf = this.strBuf;
  29936. strBuf.length = 0;
  29937. strBuf[0] = String.fromCharCode(ch);
  29938. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29939. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29940. strBuf.push(String.fromCharCode(ch));
  29941. }
  29942. var str = strBuf.join('');
  29943. switch (str.toLowerCase()) {
  29944. case 'if':
  29945. return PostScriptToken.IF;
  29946. case 'ifelse':
  29947. return PostScriptToken.IFELSE;
  29948. default:
  29949. return PostScriptToken.getOperator(str);
  29950. }
  29951. },
  29952. getNumber: function PostScriptLexer_getNumber() {
  29953. var ch = this.currentChar;
  29954. var strBuf = this.strBuf;
  29955. strBuf.length = 0;
  29956. strBuf[0] = String.fromCharCode(ch);
  29957. while ((ch = this.nextChar()) >= 0) {
  29958. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29959. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29960. strBuf.push(String.fromCharCode(ch));
  29961. } else {
  29962. break;
  29963. }
  29964. }
  29965. var value = parseFloat(strBuf.join(''));
  29966. if (isNaN(value)) {
  29967. error('Invalid floating point number: ' + value);
  29968. }
  29969. return value;
  29970. }
  29971. };
  29972. return PostScriptLexer;
  29973. })();
  29974. exports.PostScriptLexer = PostScriptLexer;
  29975. exports.PostScriptParser = PostScriptParser;
  29976. }));
  29977. (function (root, factory) {
  29978. {
  29979. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  29980. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  29981. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  29982. root.pdfjsCoreFontRenderer);
  29983. }
  29984. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  29985. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  29986. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  29987. var FontType = sharedUtil.FontType;
  29988. var Util = sharedUtil.Util;
  29989. var assert = sharedUtil.assert;
  29990. var bytesToString = sharedUtil.bytesToString;
  29991. var error = sharedUtil.error;
  29992. var info = sharedUtil.info;
  29993. var isArray = sharedUtil.isArray;
  29994. var isInt = sharedUtil.isInt;
  29995. var isNum = sharedUtil.isNum;
  29996. var readUint32 = sharedUtil.readUint32;
  29997. var shadow = sharedUtil.shadow;
  29998. var stringToBytes = sharedUtil.stringToBytes;
  29999. var string32 = sharedUtil.string32;
  30000. var warn = sharedUtil.warn;
  30001. var Name = corePrimitives.Name;
  30002. var Stream = coreStream.Stream;
  30003. var Lexer = coreParser.Lexer;
  30004. var CMapFactory = coreCMap.CMapFactory;
  30005. var IdentityCMap = coreCMap.IdentityCMap;
  30006. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  30007. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  30008. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  30009. var ExpertCharset = coreCharsets.ExpertCharset;
  30010. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  30011. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30012. // Unicode Private Use Area
  30013. var PRIVATE_USE_OFFSET_START = 0xE000;
  30014. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30015. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30016. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30017. // except for Type 3 fonts
  30018. var PDF_GLYPH_SPACE_UNITS = 1000;
  30019. // Hinting is currently disabled due to unknown problems on windows
  30020. // in tracemonkey and various other pdfs with type1 fonts.
  30021. var HINTING_ENABLED = false;
  30022. // Accented charactars are not displayed properly on windows, using this flag
  30023. // to control analysis of seac charstrings.
  30024. var SEAC_ANALYSIS_ENABLED = false;
  30025. var FontFlags = {
  30026. FixedPitch: 1,
  30027. Serif: 2,
  30028. Symbolic: 4,
  30029. Script: 8,
  30030. Nonsymbolic: 32,
  30031. Italic: 64,
  30032. AllCap: 65536,
  30033. SmallCap: 131072,
  30034. ForceBold: 262144
  30035. };
  30036. var Encodings = {
  30037. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30038. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30039. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  30040. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  30041. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  30042. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  30043. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  30044. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  30045. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  30046. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  30047. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  30048. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  30049. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  30050. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  30051. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  30052. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  30053. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  30054. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  30055. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  30056. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30057. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  30058. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  30059. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  30060. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  30061. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  30062. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  30063. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  30064. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  30065. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  30066. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  30067. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  30068. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  30069. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  30070. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  30071. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  30072. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  30073. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  30074. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  30075. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  30076. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  30077. 'Ydieresissmall'],
  30078. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30079. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30080. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  30081. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  30082. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  30083. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  30084. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  30085. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  30086. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  30087. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  30088. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  30089. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  30090. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  30091. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  30092. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  30093. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  30094. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  30095. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  30096. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  30097. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  30098. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  30099. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  30100. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  30101. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  30102. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  30103. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  30104. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  30105. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  30106. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  30107. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  30108. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  30109. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  30110. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  30111. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  30112. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  30113. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  30114. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  30115. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  30116. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  30117. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  30118. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30119. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30120. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30121. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30122. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30123. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30124. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30125. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30126. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30127. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30128. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30129. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  30130. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  30131. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  30132. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30133. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  30134. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  30135. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  30136. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  30137. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  30138. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  30139. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  30140. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  30141. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  30142. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  30143. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  30144. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  30145. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  30146. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  30147. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  30148. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  30149. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  30150. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  30151. 'ogonek', 'caron'],
  30152. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30153. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30154. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30155. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  30156. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30157. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30158. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30159. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30160. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30161. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  30162. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  30163. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30164. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30165. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  30166. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  30167. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  30168. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  30169. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  30170. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  30171. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  30172. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  30173. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  30174. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  30175. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  30176. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  30177. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30178. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30179. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30180. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30181. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30182. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30183. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30184. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30185. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30186. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30187. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30188. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30189. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  30190. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  30191. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  30192. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  30193. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  30194. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  30195. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  30196. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  30197. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  30198. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  30199. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  30200. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  30201. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  30202. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  30203. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  30204. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  30205. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  30206. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  30207. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  30208. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  30209. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  30210. 'ydieresis'],
  30211. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30212. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30213. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  30214. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  30215. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  30216. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  30217. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  30218. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  30219. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  30220. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  30221. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  30222. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  30223. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  30224. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  30225. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  30226. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30227. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  30228. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  30229. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  30230. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  30231. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  30232. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  30233. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  30234. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  30235. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  30236. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  30237. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  30238. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  30239. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  30240. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  30241. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  30242. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  30243. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  30244. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  30245. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  30246. 'bracerightbt'],
  30247. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30248. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30249. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  30250. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  30251. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  30252. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  30253. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  30254. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  30255. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  30256. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  30257. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  30258. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  30259. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  30260. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  30261. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  30262. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  30263. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  30264. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  30265. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  30266. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  30267. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  30268. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  30269. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  30270. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  30271. };
  30272. /**
  30273. * Hold a map of decoded fonts and of the standard fourteen Type1
  30274. * fonts and their acronyms.
  30275. */
  30276. var stdFontMap = {
  30277. 'ArialNarrow': 'Helvetica',
  30278. 'ArialNarrow-Bold': 'Helvetica-Bold',
  30279. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  30280. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  30281. 'ArialBlack': 'Helvetica',
  30282. 'ArialBlack-Bold': 'Helvetica-Bold',
  30283. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  30284. 'ArialBlack-Italic': 'Helvetica-Oblique',
  30285. 'Arial': 'Helvetica',
  30286. 'Arial-Bold': 'Helvetica-Bold',
  30287. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  30288. 'Arial-Italic': 'Helvetica-Oblique',
  30289. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  30290. 'Arial-BoldMT': 'Helvetica-Bold',
  30291. 'Arial-ItalicMT': 'Helvetica-Oblique',
  30292. 'ArialMT': 'Helvetica',
  30293. 'Courier-Bold': 'Courier-Bold',
  30294. 'Courier-BoldItalic': 'Courier-BoldOblique',
  30295. 'Courier-Italic': 'Courier-Oblique',
  30296. 'CourierNew': 'Courier',
  30297. 'CourierNew-Bold': 'Courier-Bold',
  30298. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  30299. 'CourierNew-Italic': 'Courier-Oblique',
  30300. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  30301. 'CourierNewPS-BoldMT': 'Courier-Bold',
  30302. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  30303. 'CourierNewPSMT': 'Courier',
  30304. 'Helvetica': 'Helvetica',
  30305. 'Helvetica-Bold': 'Helvetica-Bold',
  30306. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  30307. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  30308. 'Helvetica-Italic': 'Helvetica-Oblique',
  30309. 'Helvetica-Oblique':'Helvetica-Oblique',
  30310. 'Symbol-Bold': 'Symbol',
  30311. 'Symbol-BoldItalic': 'Symbol',
  30312. 'Symbol-Italic': 'Symbol',
  30313. 'TimesNewRoman': 'Times-Roman',
  30314. 'TimesNewRoman-Bold': 'Times-Bold',
  30315. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  30316. 'TimesNewRoman-Italic': 'Times-Italic',
  30317. 'TimesNewRomanPS': 'Times-Roman',
  30318. 'TimesNewRomanPS-Bold': 'Times-Bold',
  30319. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  30320. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  30321. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  30322. 'TimesNewRomanPS-Italic': 'Times-Italic',
  30323. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  30324. 'TimesNewRomanPSMT': 'Times-Roman',
  30325. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  30326. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  30327. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  30328. };
  30329. /**
  30330. * Holds the map of the non-standard fonts that might be included as a standard
  30331. * fonts without glyph data.
  30332. */
  30333. var nonStdFontMap = {
  30334. 'CenturyGothic': 'Helvetica',
  30335. 'CenturyGothic-Bold': 'Helvetica-Bold',
  30336. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  30337. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  30338. 'ComicSansMS': 'Comic Sans MS',
  30339. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  30340. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  30341. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  30342. 'LucidaConsole': 'Courier',
  30343. 'LucidaConsole-Bold': 'Courier-Bold',
  30344. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  30345. 'LucidaConsole-Italic': 'Courier-Oblique',
  30346. 'MS-Gothic': 'MS Gothic',
  30347. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  30348. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  30349. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  30350. 'MS-Mincho': 'MS Mincho',
  30351. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  30352. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  30353. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  30354. 'MS-PGothic': 'MS PGothic',
  30355. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  30356. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  30357. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  30358. 'MS-PMincho': 'MS PMincho',
  30359. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  30360. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  30361. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  30362. 'Wingdings': 'ZapfDingbats'
  30363. };
  30364. var serifFonts = {
  30365. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  30366. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  30367. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  30368. 'Arno': true, 'Aster': true, 'Aurora': true,
  30369. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  30370. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  30371. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  30372. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  30373. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  30374. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  30375. 'Cartier': true, 'Caslon': true, 'Catull': true,
  30376. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  30377. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  30378. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  30379. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  30380. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  30381. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  30382. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  30383. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  30384. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  30385. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  30386. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  30387. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  30388. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  30389. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  30390. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  30391. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  30392. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  30393. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  30394. 'Miller': true, 'Minion': true, 'Modern': true,
  30395. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  30396. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  30397. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  30398. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  30399. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  30400. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  30401. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  30402. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  30403. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  30404. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  30405. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  30406. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  30407. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  30408. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  30409. };
  30410. var symbolsFonts = {
  30411. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  30412. };
  30413. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  30414. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  30415. // glyphs, but common for some set of the standard fonts.
  30416. var GlyphMapForStandardFonts = {
  30417. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  30418. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  30419. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  30420. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  30421. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  30422. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  30423. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  30424. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  30425. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  30426. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  30427. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  30428. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  30429. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  30430. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  30431. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  30432. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  30433. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  30434. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  30435. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  30436. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  30437. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  30438. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  30439. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  30440. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  30441. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  30442. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  30443. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  30444. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  30445. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  30446. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  30447. '298': 380, '305': 963,
  30448. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  30449. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  30450. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  30451. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  30452. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  30453. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  30454. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  30455. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  30456. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  30457. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  30458. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  30459. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  30460. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  30461. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  30462. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  30463. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  30464. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  30465. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  30466. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  30467. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  30468. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  30469. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  30470. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  30471. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  30472. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  30473. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  30474. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  30475. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  30476. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  30477. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  30478. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  30479. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  30480. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  30481. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  30482. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  30483. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  30484. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  30485. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  30486. };
  30487. // The glyph map for ArialBlack differs slightly from the glyph map used for
  30488. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  30489. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  30490. var SupplementalGlyphMapForArialBlack = {
  30491. '227': 322, '264': 261, '291': 346,
  30492. };
  30493. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  30494. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  30495. // to the similar equivalents in the normal characters range.
  30496. var SpecialPUASymbols = {
  30497. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  30498. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  30499. '63720': 0x00AE, // registersans (0xF8E8) => registered
  30500. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  30501. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  30502. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  30503. '63729': 0x23A7, // bracelefttp (0xF8F1)
  30504. '63730': 0x23A8, // braceleftmid (0xF8F2)
  30505. '63731': 0x23A9, // braceleftbt (0xF8F3)
  30506. '63740': 0x23AB, // bracerighttp (0xF8FC)
  30507. '63741': 0x23AC, // bracerightmid (0xF8FD)
  30508. '63742': 0x23AD, // bracerightbt (0xF8FE)
  30509. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  30510. '63727': 0x23A2, // bracketleftex (0xF8EF)
  30511. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  30512. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  30513. '63738': 0x23A5, // bracketrightex (0xF8FA)
  30514. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  30515. '63723': 0x239B, // parenlefttp (0xF8EB)
  30516. '63724': 0x239C, // parenleftex (0xF8EC)
  30517. '63725': 0x239D, // parenleftbt (0xF8ED)
  30518. '63734': 0x239E, // parenrighttp (0xF8F6)
  30519. '63735': 0x239F, // parenrightex (0xF8F7)
  30520. '63736': 0x23A0, // parenrightbt (0xF8F8)
  30521. };
  30522. function mapSpecialUnicodeValues(code) {
  30523. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  30524. return 0;
  30525. } else if (code >= 0xF600 && code <= 0xF8FF) {
  30526. return (SpecialPUASymbols[code] || code);
  30527. }
  30528. return code;
  30529. }
  30530. var UnicodeRanges = [
  30531. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  30532. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  30533. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  30534. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  30535. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  30536. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  30537. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  30538. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  30539. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  30540. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  30541. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  30542. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  30543. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  30544. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  30545. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  30546. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  30547. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  30548. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  30549. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  30550. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  30551. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  30552. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  30553. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  30554. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  30555. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  30556. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  30557. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  30558. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  30559. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  30560. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  30561. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  30562. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  30563. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  30564. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  30565. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  30566. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  30567. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  30568. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  30569. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  30570. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  30571. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  30572. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  30573. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  30574. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  30575. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  30576. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  30577. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  30578. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  30579. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  30580. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  30581. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  30582. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  30583. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  30584. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  30585. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  30586. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  30587. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  30588. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  30589. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  30590. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  30591. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  30592. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  30593. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  30594. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  30595. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  30596. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  30597. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  30598. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  30599. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  30600. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  30601. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  30602. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  30603. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  30604. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  30605. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  30606. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  30607. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  30608. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  30609. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  30610. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  30611. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  30612. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  30613. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  30614. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  30615. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  30616. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  30617. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  30618. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  30619. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  30620. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  30621. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  30622. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  30623. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  30624. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  30625. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  30626. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  30627. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  30628. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  30629. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  30630. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  30631. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  30632. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  30633. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  30634. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  30635. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  30636. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  30637. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  30638. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  30639. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  30640. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  30641. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  30642. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  30643. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  30644. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  30645. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  30646. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  30647. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  30648. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  30649. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  30650. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  30651. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  30652. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  30653. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  30654. ];
  30655. var MacStandardGlyphOrdering = [
  30656. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30657. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30658. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30659. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30660. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30661. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30662. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30663. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30664. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30665. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30666. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30667. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30668. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30669. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30670. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30671. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30672. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30673. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30674. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30675. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30676. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30677. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30678. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30679. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30680. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30681. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30682. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30683. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30684. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30685. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30686. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30687. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30688. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30689. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30690. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30691. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30692. function getUnicodeRangeFor(value) {
  30693. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  30694. var range = UnicodeRanges[i];
  30695. if (value >= range.begin && value < range.end) {
  30696. return i;
  30697. }
  30698. }
  30699. return -1;
  30700. }
  30701. function isRTLRangeFor(value) {
  30702. var range = UnicodeRanges[13];
  30703. if (value >= range.begin && value < range.end) {
  30704. return true;
  30705. }
  30706. range = UnicodeRanges[11];
  30707. if (value >= range.begin && value < range.end) {
  30708. return true;
  30709. }
  30710. return false;
  30711. }
  30712. // The normalization table is obtained by filtering the Unicode characters
  30713. // database with <compat> entries.
  30714. var NormalizedUnicodes = {
  30715. '\u00A8': '\u0020\u0308',
  30716. '\u00AF': '\u0020\u0304',
  30717. '\u00B4': '\u0020\u0301',
  30718. '\u00B5': '\u03BC',
  30719. '\u00B8': '\u0020\u0327',
  30720. '\u0132': '\u0049\u004A',
  30721. '\u0133': '\u0069\u006A',
  30722. '\u013F': '\u004C\u00B7',
  30723. '\u0140': '\u006C\u00B7',
  30724. '\u0149': '\u02BC\u006E',
  30725. '\u017F': '\u0073',
  30726. '\u01C4': '\u0044\u017D',
  30727. '\u01C5': '\u0044\u017E',
  30728. '\u01C6': '\u0064\u017E',
  30729. '\u01C7': '\u004C\u004A',
  30730. '\u01C8': '\u004C\u006A',
  30731. '\u01C9': '\u006C\u006A',
  30732. '\u01CA': '\u004E\u004A',
  30733. '\u01CB': '\u004E\u006A',
  30734. '\u01CC': '\u006E\u006A',
  30735. '\u01F1': '\u0044\u005A',
  30736. '\u01F2': '\u0044\u007A',
  30737. '\u01F3': '\u0064\u007A',
  30738. '\u02D8': '\u0020\u0306',
  30739. '\u02D9': '\u0020\u0307',
  30740. '\u02DA': '\u0020\u030A',
  30741. '\u02DB': '\u0020\u0328',
  30742. '\u02DC': '\u0020\u0303',
  30743. '\u02DD': '\u0020\u030B',
  30744. '\u037A': '\u0020\u0345',
  30745. '\u0384': '\u0020\u0301',
  30746. '\u03D0': '\u03B2',
  30747. '\u03D1': '\u03B8',
  30748. '\u03D2': '\u03A5',
  30749. '\u03D5': '\u03C6',
  30750. '\u03D6': '\u03C0',
  30751. '\u03F0': '\u03BA',
  30752. '\u03F1': '\u03C1',
  30753. '\u03F2': '\u03C2',
  30754. '\u03F4': '\u0398',
  30755. '\u03F5': '\u03B5',
  30756. '\u03F9': '\u03A3',
  30757. '\u0587': '\u0565\u0582',
  30758. '\u0675': '\u0627\u0674',
  30759. '\u0676': '\u0648\u0674',
  30760. '\u0677': '\u06C7\u0674',
  30761. '\u0678': '\u064A\u0674',
  30762. '\u0E33': '\u0E4D\u0E32',
  30763. '\u0EB3': '\u0ECD\u0EB2',
  30764. '\u0EDC': '\u0EAB\u0E99',
  30765. '\u0EDD': '\u0EAB\u0EA1',
  30766. '\u0F77': '\u0FB2\u0F81',
  30767. '\u0F79': '\u0FB3\u0F81',
  30768. '\u1E9A': '\u0061\u02BE',
  30769. '\u1FBD': '\u0020\u0313',
  30770. '\u1FBF': '\u0020\u0313',
  30771. '\u1FC0': '\u0020\u0342',
  30772. '\u1FFE': '\u0020\u0314',
  30773. '\u2002': '\u0020',
  30774. '\u2003': '\u0020',
  30775. '\u2004': '\u0020',
  30776. '\u2005': '\u0020',
  30777. '\u2006': '\u0020',
  30778. '\u2008': '\u0020',
  30779. '\u2009': '\u0020',
  30780. '\u200A': '\u0020',
  30781. '\u2017': '\u0020\u0333',
  30782. '\u2024': '\u002E',
  30783. '\u2025': '\u002E\u002E',
  30784. '\u2026': '\u002E\u002E\u002E',
  30785. '\u2033': '\u2032\u2032',
  30786. '\u2034': '\u2032\u2032\u2032',
  30787. '\u2036': '\u2035\u2035',
  30788. '\u2037': '\u2035\u2035\u2035',
  30789. '\u203C': '\u0021\u0021',
  30790. '\u203E': '\u0020\u0305',
  30791. '\u2047': '\u003F\u003F',
  30792. '\u2048': '\u003F\u0021',
  30793. '\u2049': '\u0021\u003F',
  30794. '\u2057': '\u2032\u2032\u2032\u2032',
  30795. '\u205F': '\u0020',
  30796. '\u20A8': '\u0052\u0073',
  30797. '\u2100': '\u0061\u002F\u0063',
  30798. '\u2101': '\u0061\u002F\u0073',
  30799. '\u2103': '\u00B0\u0043',
  30800. '\u2105': '\u0063\u002F\u006F',
  30801. '\u2106': '\u0063\u002F\u0075',
  30802. '\u2107': '\u0190',
  30803. '\u2109': '\u00B0\u0046',
  30804. '\u2116': '\u004E\u006F',
  30805. '\u2121': '\u0054\u0045\u004C',
  30806. '\u2135': '\u05D0',
  30807. '\u2136': '\u05D1',
  30808. '\u2137': '\u05D2',
  30809. '\u2138': '\u05D3',
  30810. '\u213B': '\u0046\u0041\u0058',
  30811. '\u2160': '\u0049',
  30812. '\u2161': '\u0049\u0049',
  30813. '\u2162': '\u0049\u0049\u0049',
  30814. '\u2163': '\u0049\u0056',
  30815. '\u2164': '\u0056',
  30816. '\u2165': '\u0056\u0049',
  30817. '\u2166': '\u0056\u0049\u0049',
  30818. '\u2167': '\u0056\u0049\u0049\u0049',
  30819. '\u2168': '\u0049\u0058',
  30820. '\u2169': '\u0058',
  30821. '\u216A': '\u0058\u0049',
  30822. '\u216B': '\u0058\u0049\u0049',
  30823. '\u216C': '\u004C',
  30824. '\u216D': '\u0043',
  30825. '\u216E': '\u0044',
  30826. '\u216F': '\u004D',
  30827. '\u2170': '\u0069',
  30828. '\u2171': '\u0069\u0069',
  30829. '\u2172': '\u0069\u0069\u0069',
  30830. '\u2173': '\u0069\u0076',
  30831. '\u2174': '\u0076',
  30832. '\u2175': '\u0076\u0069',
  30833. '\u2176': '\u0076\u0069\u0069',
  30834. '\u2177': '\u0076\u0069\u0069\u0069',
  30835. '\u2178': '\u0069\u0078',
  30836. '\u2179': '\u0078',
  30837. '\u217A': '\u0078\u0069',
  30838. '\u217B': '\u0078\u0069\u0069',
  30839. '\u217C': '\u006C',
  30840. '\u217D': '\u0063',
  30841. '\u217E': '\u0064',
  30842. '\u217F': '\u006D',
  30843. '\u222C': '\u222B\u222B',
  30844. '\u222D': '\u222B\u222B\u222B',
  30845. '\u222F': '\u222E\u222E',
  30846. '\u2230': '\u222E\u222E\u222E',
  30847. '\u2474': '\u0028\u0031\u0029',
  30848. '\u2475': '\u0028\u0032\u0029',
  30849. '\u2476': '\u0028\u0033\u0029',
  30850. '\u2477': '\u0028\u0034\u0029',
  30851. '\u2478': '\u0028\u0035\u0029',
  30852. '\u2479': '\u0028\u0036\u0029',
  30853. '\u247A': '\u0028\u0037\u0029',
  30854. '\u247B': '\u0028\u0038\u0029',
  30855. '\u247C': '\u0028\u0039\u0029',
  30856. '\u247D': '\u0028\u0031\u0030\u0029',
  30857. '\u247E': '\u0028\u0031\u0031\u0029',
  30858. '\u247F': '\u0028\u0031\u0032\u0029',
  30859. '\u2480': '\u0028\u0031\u0033\u0029',
  30860. '\u2481': '\u0028\u0031\u0034\u0029',
  30861. '\u2482': '\u0028\u0031\u0035\u0029',
  30862. '\u2483': '\u0028\u0031\u0036\u0029',
  30863. '\u2484': '\u0028\u0031\u0037\u0029',
  30864. '\u2485': '\u0028\u0031\u0038\u0029',
  30865. '\u2486': '\u0028\u0031\u0039\u0029',
  30866. '\u2487': '\u0028\u0032\u0030\u0029',
  30867. '\u2488': '\u0031\u002E',
  30868. '\u2489': '\u0032\u002E',
  30869. '\u248A': '\u0033\u002E',
  30870. '\u248B': '\u0034\u002E',
  30871. '\u248C': '\u0035\u002E',
  30872. '\u248D': '\u0036\u002E',
  30873. '\u248E': '\u0037\u002E',
  30874. '\u248F': '\u0038\u002E',
  30875. '\u2490': '\u0039\u002E',
  30876. '\u2491': '\u0031\u0030\u002E',
  30877. '\u2492': '\u0031\u0031\u002E',
  30878. '\u2493': '\u0031\u0032\u002E',
  30879. '\u2494': '\u0031\u0033\u002E',
  30880. '\u2495': '\u0031\u0034\u002E',
  30881. '\u2496': '\u0031\u0035\u002E',
  30882. '\u2497': '\u0031\u0036\u002E',
  30883. '\u2498': '\u0031\u0037\u002E',
  30884. '\u2499': '\u0031\u0038\u002E',
  30885. '\u249A': '\u0031\u0039\u002E',
  30886. '\u249B': '\u0032\u0030\u002E',
  30887. '\u249C': '\u0028\u0061\u0029',
  30888. '\u249D': '\u0028\u0062\u0029',
  30889. '\u249E': '\u0028\u0063\u0029',
  30890. '\u249F': '\u0028\u0064\u0029',
  30891. '\u24A0': '\u0028\u0065\u0029',
  30892. '\u24A1': '\u0028\u0066\u0029',
  30893. '\u24A2': '\u0028\u0067\u0029',
  30894. '\u24A3': '\u0028\u0068\u0029',
  30895. '\u24A4': '\u0028\u0069\u0029',
  30896. '\u24A5': '\u0028\u006A\u0029',
  30897. '\u24A6': '\u0028\u006B\u0029',
  30898. '\u24A7': '\u0028\u006C\u0029',
  30899. '\u24A8': '\u0028\u006D\u0029',
  30900. '\u24A9': '\u0028\u006E\u0029',
  30901. '\u24AA': '\u0028\u006F\u0029',
  30902. '\u24AB': '\u0028\u0070\u0029',
  30903. '\u24AC': '\u0028\u0071\u0029',
  30904. '\u24AD': '\u0028\u0072\u0029',
  30905. '\u24AE': '\u0028\u0073\u0029',
  30906. '\u24AF': '\u0028\u0074\u0029',
  30907. '\u24B0': '\u0028\u0075\u0029',
  30908. '\u24B1': '\u0028\u0076\u0029',
  30909. '\u24B2': '\u0028\u0077\u0029',
  30910. '\u24B3': '\u0028\u0078\u0029',
  30911. '\u24B4': '\u0028\u0079\u0029',
  30912. '\u24B5': '\u0028\u007A\u0029',
  30913. '\u2A0C': '\u222B\u222B\u222B\u222B',
  30914. '\u2A74': '\u003A\u003A\u003D',
  30915. '\u2A75': '\u003D\u003D',
  30916. '\u2A76': '\u003D\u003D\u003D',
  30917. '\u2E9F': '\u6BCD',
  30918. '\u2EF3': '\u9F9F',
  30919. '\u2F00': '\u4E00',
  30920. '\u2F01': '\u4E28',
  30921. '\u2F02': '\u4E36',
  30922. '\u2F03': '\u4E3F',
  30923. '\u2F04': '\u4E59',
  30924. '\u2F05': '\u4E85',
  30925. '\u2F06': '\u4E8C',
  30926. '\u2F07': '\u4EA0',
  30927. '\u2F08': '\u4EBA',
  30928. '\u2F09': '\u513F',
  30929. '\u2F0A': '\u5165',
  30930. '\u2F0B': '\u516B',
  30931. '\u2F0C': '\u5182',
  30932. '\u2F0D': '\u5196',
  30933. '\u2F0E': '\u51AB',
  30934. '\u2F0F': '\u51E0',
  30935. '\u2F10': '\u51F5',
  30936. '\u2F11': '\u5200',
  30937. '\u2F12': '\u529B',
  30938. '\u2F13': '\u52F9',
  30939. '\u2F14': '\u5315',
  30940. '\u2F15': '\u531A',
  30941. '\u2F16': '\u5338',
  30942. '\u2F17': '\u5341',
  30943. '\u2F18': '\u535C',
  30944. '\u2F19': '\u5369',
  30945. '\u2F1A': '\u5382',
  30946. '\u2F1B': '\u53B6',
  30947. '\u2F1C': '\u53C8',
  30948. '\u2F1D': '\u53E3',
  30949. '\u2F1E': '\u56D7',
  30950. '\u2F1F': '\u571F',
  30951. '\u2F20': '\u58EB',
  30952. '\u2F21': '\u5902',
  30953. '\u2F22': '\u590A',
  30954. '\u2F23': '\u5915',
  30955. '\u2F24': '\u5927',
  30956. '\u2F25': '\u5973',
  30957. '\u2F26': '\u5B50',
  30958. '\u2F27': '\u5B80',
  30959. '\u2F28': '\u5BF8',
  30960. '\u2F29': '\u5C0F',
  30961. '\u2F2A': '\u5C22',
  30962. '\u2F2B': '\u5C38',
  30963. '\u2F2C': '\u5C6E',
  30964. '\u2F2D': '\u5C71',
  30965. '\u2F2E': '\u5DDB',
  30966. '\u2F2F': '\u5DE5',
  30967. '\u2F30': '\u5DF1',
  30968. '\u2F31': '\u5DFE',
  30969. '\u2F32': '\u5E72',
  30970. '\u2F33': '\u5E7A',
  30971. '\u2F34': '\u5E7F',
  30972. '\u2F35': '\u5EF4',
  30973. '\u2F36': '\u5EFE',
  30974. '\u2F37': '\u5F0B',
  30975. '\u2F38': '\u5F13',
  30976. '\u2F39': '\u5F50',
  30977. '\u2F3A': '\u5F61',
  30978. '\u2F3B': '\u5F73',
  30979. '\u2F3C': '\u5FC3',
  30980. '\u2F3D': '\u6208',
  30981. '\u2F3E': '\u6236',
  30982. '\u2F3F': '\u624B',
  30983. '\u2F40': '\u652F',
  30984. '\u2F41': '\u6534',
  30985. '\u2F42': '\u6587',
  30986. '\u2F43': '\u6597',
  30987. '\u2F44': '\u65A4',
  30988. '\u2F45': '\u65B9',
  30989. '\u2F46': '\u65E0',
  30990. '\u2F47': '\u65E5',
  30991. '\u2F48': '\u66F0',
  30992. '\u2F49': '\u6708',
  30993. '\u2F4A': '\u6728',
  30994. '\u2F4B': '\u6B20',
  30995. '\u2F4C': '\u6B62',
  30996. '\u2F4D': '\u6B79',
  30997. '\u2F4E': '\u6BB3',
  30998. '\u2F4F': '\u6BCB',
  30999. '\u2F50': '\u6BD4',
  31000. '\u2F51': '\u6BDB',
  31001. '\u2F52': '\u6C0F',
  31002. '\u2F53': '\u6C14',
  31003. '\u2F54': '\u6C34',
  31004. '\u2F55': '\u706B',
  31005. '\u2F56': '\u722A',
  31006. '\u2F57': '\u7236',
  31007. '\u2F58': '\u723B',
  31008. '\u2F59': '\u723F',
  31009. '\u2F5A': '\u7247',
  31010. '\u2F5B': '\u7259',
  31011. '\u2F5C': '\u725B',
  31012. '\u2F5D': '\u72AC',
  31013. '\u2F5E': '\u7384',
  31014. '\u2F5F': '\u7389',
  31015. '\u2F60': '\u74DC',
  31016. '\u2F61': '\u74E6',
  31017. '\u2F62': '\u7518',
  31018. '\u2F63': '\u751F',
  31019. '\u2F64': '\u7528',
  31020. '\u2F65': '\u7530',
  31021. '\u2F66': '\u758B',
  31022. '\u2F67': '\u7592',
  31023. '\u2F68': '\u7676',
  31024. '\u2F69': '\u767D',
  31025. '\u2F6A': '\u76AE',
  31026. '\u2F6B': '\u76BF',
  31027. '\u2F6C': '\u76EE',
  31028. '\u2F6D': '\u77DB',
  31029. '\u2F6E': '\u77E2',
  31030. '\u2F6F': '\u77F3',
  31031. '\u2F70': '\u793A',
  31032. '\u2F71': '\u79B8',
  31033. '\u2F72': '\u79BE',
  31034. '\u2F73': '\u7A74',
  31035. '\u2F74': '\u7ACB',
  31036. '\u2F75': '\u7AF9',
  31037. '\u2F76': '\u7C73',
  31038. '\u2F77': '\u7CF8',
  31039. '\u2F78': '\u7F36',
  31040. '\u2F79': '\u7F51',
  31041. '\u2F7A': '\u7F8A',
  31042. '\u2F7B': '\u7FBD',
  31043. '\u2F7C': '\u8001',
  31044. '\u2F7D': '\u800C',
  31045. '\u2F7E': '\u8012',
  31046. '\u2F7F': '\u8033',
  31047. '\u2F80': '\u807F',
  31048. '\u2F81': '\u8089',
  31049. '\u2F82': '\u81E3',
  31050. '\u2F83': '\u81EA',
  31051. '\u2F84': '\u81F3',
  31052. '\u2F85': '\u81FC',
  31053. '\u2F86': '\u820C',
  31054. '\u2F87': '\u821B',
  31055. '\u2F88': '\u821F',
  31056. '\u2F89': '\u826E',
  31057. '\u2F8A': '\u8272',
  31058. '\u2F8B': '\u8278',
  31059. '\u2F8C': '\u864D',
  31060. '\u2F8D': '\u866B',
  31061. '\u2F8E': '\u8840',
  31062. '\u2F8F': '\u884C',
  31063. '\u2F90': '\u8863',
  31064. '\u2F91': '\u897E',
  31065. '\u2F92': '\u898B',
  31066. '\u2F93': '\u89D2',
  31067. '\u2F94': '\u8A00',
  31068. '\u2F95': '\u8C37',
  31069. '\u2F96': '\u8C46',
  31070. '\u2F97': '\u8C55',
  31071. '\u2F98': '\u8C78',
  31072. '\u2F99': '\u8C9D',
  31073. '\u2F9A': '\u8D64',
  31074. '\u2F9B': '\u8D70',
  31075. '\u2F9C': '\u8DB3',
  31076. '\u2F9D': '\u8EAB',
  31077. '\u2F9E': '\u8ECA',
  31078. '\u2F9F': '\u8F9B',
  31079. '\u2FA0': '\u8FB0',
  31080. '\u2FA1': '\u8FB5',
  31081. '\u2FA2': '\u9091',
  31082. '\u2FA3': '\u9149',
  31083. '\u2FA4': '\u91C6',
  31084. '\u2FA5': '\u91CC',
  31085. '\u2FA6': '\u91D1',
  31086. '\u2FA7': '\u9577',
  31087. '\u2FA8': '\u9580',
  31088. '\u2FA9': '\u961C',
  31089. '\u2FAA': '\u96B6',
  31090. '\u2FAB': '\u96B9',
  31091. '\u2FAC': '\u96E8',
  31092. '\u2FAD': '\u9751',
  31093. '\u2FAE': '\u975E',
  31094. '\u2FAF': '\u9762',
  31095. '\u2FB0': '\u9769',
  31096. '\u2FB1': '\u97CB',
  31097. '\u2FB2': '\u97ED',
  31098. '\u2FB3': '\u97F3',
  31099. '\u2FB4': '\u9801',
  31100. '\u2FB5': '\u98A8',
  31101. '\u2FB6': '\u98DB',
  31102. '\u2FB7': '\u98DF',
  31103. '\u2FB8': '\u9996',
  31104. '\u2FB9': '\u9999',
  31105. '\u2FBA': '\u99AC',
  31106. '\u2FBB': '\u9AA8',
  31107. '\u2FBC': '\u9AD8',
  31108. '\u2FBD': '\u9ADF',
  31109. '\u2FBE': '\u9B25',
  31110. '\u2FBF': '\u9B2F',
  31111. '\u2FC0': '\u9B32',
  31112. '\u2FC1': '\u9B3C',
  31113. '\u2FC2': '\u9B5A',
  31114. '\u2FC3': '\u9CE5',
  31115. '\u2FC4': '\u9E75',
  31116. '\u2FC5': '\u9E7F',
  31117. '\u2FC6': '\u9EA5',
  31118. '\u2FC7': '\u9EBB',
  31119. '\u2FC8': '\u9EC3',
  31120. '\u2FC9': '\u9ECD',
  31121. '\u2FCA': '\u9ED1',
  31122. '\u2FCB': '\u9EF9',
  31123. '\u2FCC': '\u9EFD',
  31124. '\u2FCD': '\u9F0E',
  31125. '\u2FCE': '\u9F13',
  31126. '\u2FCF': '\u9F20',
  31127. '\u2FD0': '\u9F3B',
  31128. '\u2FD1': '\u9F4A',
  31129. '\u2FD2': '\u9F52',
  31130. '\u2FD3': '\u9F8D',
  31131. '\u2FD4': '\u9F9C',
  31132. '\u2FD5': '\u9FA0',
  31133. '\u3036': '\u3012',
  31134. '\u3038': '\u5341',
  31135. '\u3039': '\u5344',
  31136. '\u303A': '\u5345',
  31137. '\u309B': '\u0020\u3099',
  31138. '\u309C': '\u0020\u309A',
  31139. '\u3131': '\u1100',
  31140. '\u3132': '\u1101',
  31141. '\u3133': '\u11AA',
  31142. '\u3134': '\u1102',
  31143. '\u3135': '\u11AC',
  31144. '\u3136': '\u11AD',
  31145. '\u3137': '\u1103',
  31146. '\u3138': '\u1104',
  31147. '\u3139': '\u1105',
  31148. '\u313A': '\u11B0',
  31149. '\u313B': '\u11B1',
  31150. '\u313C': '\u11B2',
  31151. '\u313D': '\u11B3',
  31152. '\u313E': '\u11B4',
  31153. '\u313F': '\u11B5',
  31154. '\u3140': '\u111A',
  31155. '\u3141': '\u1106',
  31156. '\u3142': '\u1107',
  31157. '\u3143': '\u1108',
  31158. '\u3144': '\u1121',
  31159. '\u3145': '\u1109',
  31160. '\u3146': '\u110A',
  31161. '\u3147': '\u110B',
  31162. '\u3148': '\u110C',
  31163. '\u3149': '\u110D',
  31164. '\u314A': '\u110E',
  31165. '\u314B': '\u110F',
  31166. '\u314C': '\u1110',
  31167. '\u314D': '\u1111',
  31168. '\u314E': '\u1112',
  31169. '\u314F': '\u1161',
  31170. '\u3150': '\u1162',
  31171. '\u3151': '\u1163',
  31172. '\u3152': '\u1164',
  31173. '\u3153': '\u1165',
  31174. '\u3154': '\u1166',
  31175. '\u3155': '\u1167',
  31176. '\u3156': '\u1168',
  31177. '\u3157': '\u1169',
  31178. '\u3158': '\u116A',
  31179. '\u3159': '\u116B',
  31180. '\u315A': '\u116C',
  31181. '\u315B': '\u116D',
  31182. '\u315C': '\u116E',
  31183. '\u315D': '\u116F',
  31184. '\u315E': '\u1170',
  31185. '\u315F': '\u1171',
  31186. '\u3160': '\u1172',
  31187. '\u3161': '\u1173',
  31188. '\u3162': '\u1174',
  31189. '\u3163': '\u1175',
  31190. '\u3164': '\u1160',
  31191. '\u3165': '\u1114',
  31192. '\u3166': '\u1115',
  31193. '\u3167': '\u11C7',
  31194. '\u3168': '\u11C8',
  31195. '\u3169': '\u11CC',
  31196. '\u316A': '\u11CE',
  31197. '\u316B': '\u11D3',
  31198. '\u316C': '\u11D7',
  31199. '\u316D': '\u11D9',
  31200. '\u316E': '\u111C',
  31201. '\u316F': '\u11DD',
  31202. '\u3170': '\u11DF',
  31203. '\u3171': '\u111D',
  31204. '\u3172': '\u111E',
  31205. '\u3173': '\u1120',
  31206. '\u3174': '\u1122',
  31207. '\u3175': '\u1123',
  31208. '\u3176': '\u1127',
  31209. '\u3177': '\u1129',
  31210. '\u3178': '\u112B',
  31211. '\u3179': '\u112C',
  31212. '\u317A': '\u112D',
  31213. '\u317B': '\u112E',
  31214. '\u317C': '\u112F',
  31215. '\u317D': '\u1132',
  31216. '\u317E': '\u1136',
  31217. '\u317F': '\u1140',
  31218. '\u3180': '\u1147',
  31219. '\u3181': '\u114C',
  31220. '\u3182': '\u11F1',
  31221. '\u3183': '\u11F2',
  31222. '\u3184': '\u1157',
  31223. '\u3185': '\u1158',
  31224. '\u3186': '\u1159',
  31225. '\u3187': '\u1184',
  31226. '\u3188': '\u1185',
  31227. '\u3189': '\u1188',
  31228. '\u318A': '\u1191',
  31229. '\u318B': '\u1192',
  31230. '\u318C': '\u1194',
  31231. '\u318D': '\u119E',
  31232. '\u318E': '\u11A1',
  31233. '\u3200': '\u0028\u1100\u0029',
  31234. '\u3201': '\u0028\u1102\u0029',
  31235. '\u3202': '\u0028\u1103\u0029',
  31236. '\u3203': '\u0028\u1105\u0029',
  31237. '\u3204': '\u0028\u1106\u0029',
  31238. '\u3205': '\u0028\u1107\u0029',
  31239. '\u3206': '\u0028\u1109\u0029',
  31240. '\u3207': '\u0028\u110B\u0029',
  31241. '\u3208': '\u0028\u110C\u0029',
  31242. '\u3209': '\u0028\u110E\u0029',
  31243. '\u320A': '\u0028\u110F\u0029',
  31244. '\u320B': '\u0028\u1110\u0029',
  31245. '\u320C': '\u0028\u1111\u0029',
  31246. '\u320D': '\u0028\u1112\u0029',
  31247. '\u320E': '\u0028\u1100\u1161\u0029',
  31248. '\u320F': '\u0028\u1102\u1161\u0029',
  31249. '\u3210': '\u0028\u1103\u1161\u0029',
  31250. '\u3211': '\u0028\u1105\u1161\u0029',
  31251. '\u3212': '\u0028\u1106\u1161\u0029',
  31252. '\u3213': '\u0028\u1107\u1161\u0029',
  31253. '\u3214': '\u0028\u1109\u1161\u0029',
  31254. '\u3215': '\u0028\u110B\u1161\u0029',
  31255. '\u3216': '\u0028\u110C\u1161\u0029',
  31256. '\u3217': '\u0028\u110E\u1161\u0029',
  31257. '\u3218': '\u0028\u110F\u1161\u0029',
  31258. '\u3219': '\u0028\u1110\u1161\u0029',
  31259. '\u321A': '\u0028\u1111\u1161\u0029',
  31260. '\u321B': '\u0028\u1112\u1161\u0029',
  31261. '\u321C': '\u0028\u110C\u116E\u0029',
  31262. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  31263. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  31264. '\u3220': '\u0028\u4E00\u0029',
  31265. '\u3221': '\u0028\u4E8C\u0029',
  31266. '\u3222': '\u0028\u4E09\u0029',
  31267. '\u3223': '\u0028\u56DB\u0029',
  31268. '\u3224': '\u0028\u4E94\u0029',
  31269. '\u3225': '\u0028\u516D\u0029',
  31270. '\u3226': '\u0028\u4E03\u0029',
  31271. '\u3227': '\u0028\u516B\u0029',
  31272. '\u3228': '\u0028\u4E5D\u0029',
  31273. '\u3229': '\u0028\u5341\u0029',
  31274. '\u322A': '\u0028\u6708\u0029',
  31275. '\u322B': '\u0028\u706B\u0029',
  31276. '\u322C': '\u0028\u6C34\u0029',
  31277. '\u322D': '\u0028\u6728\u0029',
  31278. '\u322E': '\u0028\u91D1\u0029',
  31279. '\u322F': '\u0028\u571F\u0029',
  31280. '\u3230': '\u0028\u65E5\u0029',
  31281. '\u3231': '\u0028\u682A\u0029',
  31282. '\u3232': '\u0028\u6709\u0029',
  31283. '\u3233': '\u0028\u793E\u0029',
  31284. '\u3234': '\u0028\u540D\u0029',
  31285. '\u3235': '\u0028\u7279\u0029',
  31286. '\u3236': '\u0028\u8CA1\u0029',
  31287. '\u3237': '\u0028\u795D\u0029',
  31288. '\u3238': '\u0028\u52B4\u0029',
  31289. '\u3239': '\u0028\u4EE3\u0029',
  31290. '\u323A': '\u0028\u547C\u0029',
  31291. '\u323B': '\u0028\u5B66\u0029',
  31292. '\u323C': '\u0028\u76E3\u0029',
  31293. '\u323D': '\u0028\u4F01\u0029',
  31294. '\u323E': '\u0028\u8CC7\u0029',
  31295. '\u323F': '\u0028\u5354\u0029',
  31296. '\u3240': '\u0028\u796D\u0029',
  31297. '\u3241': '\u0028\u4F11\u0029',
  31298. '\u3242': '\u0028\u81EA\u0029',
  31299. '\u3243': '\u0028\u81F3\u0029',
  31300. '\u32C0': '\u0031\u6708',
  31301. '\u32C1': '\u0032\u6708',
  31302. '\u32C2': '\u0033\u6708',
  31303. '\u32C3': '\u0034\u6708',
  31304. '\u32C4': '\u0035\u6708',
  31305. '\u32C5': '\u0036\u6708',
  31306. '\u32C6': '\u0037\u6708',
  31307. '\u32C7': '\u0038\u6708',
  31308. '\u32C8': '\u0039\u6708',
  31309. '\u32C9': '\u0031\u0030\u6708',
  31310. '\u32CA': '\u0031\u0031\u6708',
  31311. '\u32CB': '\u0031\u0032\u6708',
  31312. '\u3358': '\u0030\u70B9',
  31313. '\u3359': '\u0031\u70B9',
  31314. '\u335A': '\u0032\u70B9',
  31315. '\u335B': '\u0033\u70B9',
  31316. '\u335C': '\u0034\u70B9',
  31317. '\u335D': '\u0035\u70B9',
  31318. '\u335E': '\u0036\u70B9',
  31319. '\u335F': '\u0037\u70B9',
  31320. '\u3360': '\u0038\u70B9',
  31321. '\u3361': '\u0039\u70B9',
  31322. '\u3362': '\u0031\u0030\u70B9',
  31323. '\u3363': '\u0031\u0031\u70B9',
  31324. '\u3364': '\u0031\u0032\u70B9',
  31325. '\u3365': '\u0031\u0033\u70B9',
  31326. '\u3366': '\u0031\u0034\u70B9',
  31327. '\u3367': '\u0031\u0035\u70B9',
  31328. '\u3368': '\u0031\u0036\u70B9',
  31329. '\u3369': '\u0031\u0037\u70B9',
  31330. '\u336A': '\u0031\u0038\u70B9',
  31331. '\u336B': '\u0031\u0039\u70B9',
  31332. '\u336C': '\u0032\u0030\u70B9',
  31333. '\u336D': '\u0032\u0031\u70B9',
  31334. '\u336E': '\u0032\u0032\u70B9',
  31335. '\u336F': '\u0032\u0033\u70B9',
  31336. '\u3370': '\u0032\u0034\u70B9',
  31337. '\u33E0': '\u0031\u65E5',
  31338. '\u33E1': '\u0032\u65E5',
  31339. '\u33E2': '\u0033\u65E5',
  31340. '\u33E3': '\u0034\u65E5',
  31341. '\u33E4': '\u0035\u65E5',
  31342. '\u33E5': '\u0036\u65E5',
  31343. '\u33E6': '\u0037\u65E5',
  31344. '\u33E7': '\u0038\u65E5',
  31345. '\u33E8': '\u0039\u65E5',
  31346. '\u33E9': '\u0031\u0030\u65E5',
  31347. '\u33EA': '\u0031\u0031\u65E5',
  31348. '\u33EB': '\u0031\u0032\u65E5',
  31349. '\u33EC': '\u0031\u0033\u65E5',
  31350. '\u33ED': '\u0031\u0034\u65E5',
  31351. '\u33EE': '\u0031\u0035\u65E5',
  31352. '\u33EF': '\u0031\u0036\u65E5',
  31353. '\u33F0': '\u0031\u0037\u65E5',
  31354. '\u33F1': '\u0031\u0038\u65E5',
  31355. '\u33F2': '\u0031\u0039\u65E5',
  31356. '\u33F3': '\u0032\u0030\u65E5',
  31357. '\u33F4': '\u0032\u0031\u65E5',
  31358. '\u33F5': '\u0032\u0032\u65E5',
  31359. '\u33F6': '\u0032\u0033\u65E5',
  31360. '\u33F7': '\u0032\u0034\u65E5',
  31361. '\u33F8': '\u0032\u0035\u65E5',
  31362. '\u33F9': '\u0032\u0036\u65E5',
  31363. '\u33FA': '\u0032\u0037\u65E5',
  31364. '\u33FB': '\u0032\u0038\u65E5',
  31365. '\u33FC': '\u0032\u0039\u65E5',
  31366. '\u33FD': '\u0033\u0030\u65E5',
  31367. '\u33FE': '\u0033\u0031\u65E5',
  31368. '\uFB00': '\u0066\u0066',
  31369. '\uFB01': '\u0066\u0069',
  31370. '\uFB02': '\u0066\u006C',
  31371. '\uFB03': '\u0066\u0066\u0069',
  31372. '\uFB04': '\u0066\u0066\u006C',
  31373. '\uFB05': '\u017F\u0074',
  31374. '\uFB06': '\u0073\u0074',
  31375. '\uFB13': '\u0574\u0576',
  31376. '\uFB14': '\u0574\u0565',
  31377. '\uFB15': '\u0574\u056B',
  31378. '\uFB16': '\u057E\u0576',
  31379. '\uFB17': '\u0574\u056D',
  31380. '\uFB4F': '\u05D0\u05DC',
  31381. '\uFB50': '\u0671',
  31382. '\uFB51': '\u0671',
  31383. '\uFB52': '\u067B',
  31384. '\uFB53': '\u067B',
  31385. '\uFB54': '\u067B',
  31386. '\uFB55': '\u067B',
  31387. '\uFB56': '\u067E',
  31388. '\uFB57': '\u067E',
  31389. '\uFB58': '\u067E',
  31390. '\uFB59': '\u067E',
  31391. '\uFB5A': '\u0680',
  31392. '\uFB5B': '\u0680',
  31393. '\uFB5C': '\u0680',
  31394. '\uFB5D': '\u0680',
  31395. '\uFB5E': '\u067A',
  31396. '\uFB5F': '\u067A',
  31397. '\uFB60': '\u067A',
  31398. '\uFB61': '\u067A',
  31399. '\uFB62': '\u067F',
  31400. '\uFB63': '\u067F',
  31401. '\uFB64': '\u067F',
  31402. '\uFB65': '\u067F',
  31403. '\uFB66': '\u0679',
  31404. '\uFB67': '\u0679',
  31405. '\uFB68': '\u0679',
  31406. '\uFB69': '\u0679',
  31407. '\uFB6A': '\u06A4',
  31408. '\uFB6B': '\u06A4',
  31409. '\uFB6C': '\u06A4',
  31410. '\uFB6D': '\u06A4',
  31411. '\uFB6E': '\u06A6',
  31412. '\uFB6F': '\u06A6',
  31413. '\uFB70': '\u06A6',
  31414. '\uFB71': '\u06A6',
  31415. '\uFB72': '\u0684',
  31416. '\uFB73': '\u0684',
  31417. '\uFB74': '\u0684',
  31418. '\uFB75': '\u0684',
  31419. '\uFB76': '\u0683',
  31420. '\uFB77': '\u0683',
  31421. '\uFB78': '\u0683',
  31422. '\uFB79': '\u0683',
  31423. '\uFB7A': '\u0686',
  31424. '\uFB7B': '\u0686',
  31425. '\uFB7C': '\u0686',
  31426. '\uFB7D': '\u0686',
  31427. '\uFB7E': '\u0687',
  31428. '\uFB7F': '\u0687',
  31429. '\uFB80': '\u0687',
  31430. '\uFB81': '\u0687',
  31431. '\uFB82': '\u068D',
  31432. '\uFB83': '\u068D',
  31433. '\uFB84': '\u068C',
  31434. '\uFB85': '\u068C',
  31435. '\uFB86': '\u068E',
  31436. '\uFB87': '\u068E',
  31437. '\uFB88': '\u0688',
  31438. '\uFB89': '\u0688',
  31439. '\uFB8A': '\u0698',
  31440. '\uFB8B': '\u0698',
  31441. '\uFB8C': '\u0691',
  31442. '\uFB8D': '\u0691',
  31443. '\uFB8E': '\u06A9',
  31444. '\uFB8F': '\u06A9',
  31445. '\uFB90': '\u06A9',
  31446. '\uFB91': '\u06A9',
  31447. '\uFB92': '\u06AF',
  31448. '\uFB93': '\u06AF',
  31449. '\uFB94': '\u06AF',
  31450. '\uFB95': '\u06AF',
  31451. '\uFB96': '\u06B3',
  31452. '\uFB97': '\u06B3',
  31453. '\uFB98': '\u06B3',
  31454. '\uFB99': '\u06B3',
  31455. '\uFB9A': '\u06B1',
  31456. '\uFB9B': '\u06B1',
  31457. '\uFB9C': '\u06B1',
  31458. '\uFB9D': '\u06B1',
  31459. '\uFB9E': '\u06BA',
  31460. '\uFB9F': '\u06BA',
  31461. '\uFBA0': '\u06BB',
  31462. '\uFBA1': '\u06BB',
  31463. '\uFBA2': '\u06BB',
  31464. '\uFBA3': '\u06BB',
  31465. '\uFBA4': '\u06C0',
  31466. '\uFBA5': '\u06C0',
  31467. '\uFBA6': '\u06C1',
  31468. '\uFBA7': '\u06C1',
  31469. '\uFBA8': '\u06C1',
  31470. '\uFBA9': '\u06C1',
  31471. '\uFBAA': '\u06BE',
  31472. '\uFBAB': '\u06BE',
  31473. '\uFBAC': '\u06BE',
  31474. '\uFBAD': '\u06BE',
  31475. '\uFBAE': '\u06D2',
  31476. '\uFBAF': '\u06D2',
  31477. '\uFBB0': '\u06D3',
  31478. '\uFBB1': '\u06D3',
  31479. '\uFBD3': '\u06AD',
  31480. '\uFBD4': '\u06AD',
  31481. '\uFBD5': '\u06AD',
  31482. '\uFBD6': '\u06AD',
  31483. '\uFBD7': '\u06C7',
  31484. '\uFBD8': '\u06C7',
  31485. '\uFBD9': '\u06C6',
  31486. '\uFBDA': '\u06C6',
  31487. '\uFBDB': '\u06C8',
  31488. '\uFBDC': '\u06C8',
  31489. '\uFBDD': '\u0677',
  31490. '\uFBDE': '\u06CB',
  31491. '\uFBDF': '\u06CB',
  31492. '\uFBE0': '\u06C5',
  31493. '\uFBE1': '\u06C5',
  31494. '\uFBE2': '\u06C9',
  31495. '\uFBE3': '\u06C9',
  31496. '\uFBE4': '\u06D0',
  31497. '\uFBE5': '\u06D0',
  31498. '\uFBE6': '\u06D0',
  31499. '\uFBE7': '\u06D0',
  31500. '\uFBE8': '\u0649',
  31501. '\uFBE9': '\u0649',
  31502. '\uFBEA': '\u0626\u0627',
  31503. '\uFBEB': '\u0626\u0627',
  31504. '\uFBEC': '\u0626\u06D5',
  31505. '\uFBED': '\u0626\u06D5',
  31506. '\uFBEE': '\u0626\u0648',
  31507. '\uFBEF': '\u0626\u0648',
  31508. '\uFBF0': '\u0626\u06C7',
  31509. '\uFBF1': '\u0626\u06C7',
  31510. '\uFBF2': '\u0626\u06C6',
  31511. '\uFBF3': '\u0626\u06C6',
  31512. '\uFBF4': '\u0626\u06C8',
  31513. '\uFBF5': '\u0626\u06C8',
  31514. '\uFBF6': '\u0626\u06D0',
  31515. '\uFBF7': '\u0626\u06D0',
  31516. '\uFBF8': '\u0626\u06D0',
  31517. '\uFBF9': '\u0626\u0649',
  31518. '\uFBFA': '\u0626\u0649',
  31519. '\uFBFB': '\u0626\u0649',
  31520. '\uFBFC': '\u06CC',
  31521. '\uFBFD': '\u06CC',
  31522. '\uFBFE': '\u06CC',
  31523. '\uFBFF': '\u06CC',
  31524. '\uFC00': '\u0626\u062C',
  31525. '\uFC01': '\u0626\u062D',
  31526. '\uFC02': '\u0626\u0645',
  31527. '\uFC03': '\u0626\u0649',
  31528. '\uFC04': '\u0626\u064A',
  31529. '\uFC05': '\u0628\u062C',
  31530. '\uFC06': '\u0628\u062D',
  31531. '\uFC07': '\u0628\u062E',
  31532. '\uFC08': '\u0628\u0645',
  31533. '\uFC09': '\u0628\u0649',
  31534. '\uFC0A': '\u0628\u064A',
  31535. '\uFC0B': '\u062A\u062C',
  31536. '\uFC0C': '\u062A\u062D',
  31537. '\uFC0D': '\u062A\u062E',
  31538. '\uFC0E': '\u062A\u0645',
  31539. '\uFC0F': '\u062A\u0649',
  31540. '\uFC10': '\u062A\u064A',
  31541. '\uFC11': '\u062B\u062C',
  31542. '\uFC12': '\u062B\u0645',
  31543. '\uFC13': '\u062B\u0649',
  31544. '\uFC14': '\u062B\u064A',
  31545. '\uFC15': '\u062C\u062D',
  31546. '\uFC16': '\u062C\u0645',
  31547. '\uFC17': '\u062D\u062C',
  31548. '\uFC18': '\u062D\u0645',
  31549. '\uFC19': '\u062E\u062C',
  31550. '\uFC1A': '\u062E\u062D',
  31551. '\uFC1B': '\u062E\u0645',
  31552. '\uFC1C': '\u0633\u062C',
  31553. '\uFC1D': '\u0633\u062D',
  31554. '\uFC1E': '\u0633\u062E',
  31555. '\uFC1F': '\u0633\u0645',
  31556. '\uFC20': '\u0635\u062D',
  31557. '\uFC21': '\u0635\u0645',
  31558. '\uFC22': '\u0636\u062C',
  31559. '\uFC23': '\u0636\u062D',
  31560. '\uFC24': '\u0636\u062E',
  31561. '\uFC25': '\u0636\u0645',
  31562. '\uFC26': '\u0637\u062D',
  31563. '\uFC27': '\u0637\u0645',
  31564. '\uFC28': '\u0638\u0645',
  31565. '\uFC29': '\u0639\u062C',
  31566. '\uFC2A': '\u0639\u0645',
  31567. '\uFC2B': '\u063A\u062C',
  31568. '\uFC2C': '\u063A\u0645',
  31569. '\uFC2D': '\u0641\u062C',
  31570. '\uFC2E': '\u0641\u062D',
  31571. '\uFC2F': '\u0641\u062E',
  31572. '\uFC30': '\u0641\u0645',
  31573. '\uFC31': '\u0641\u0649',
  31574. '\uFC32': '\u0641\u064A',
  31575. '\uFC33': '\u0642\u062D',
  31576. '\uFC34': '\u0642\u0645',
  31577. '\uFC35': '\u0642\u0649',
  31578. '\uFC36': '\u0642\u064A',
  31579. '\uFC37': '\u0643\u0627',
  31580. '\uFC38': '\u0643\u062C',
  31581. '\uFC39': '\u0643\u062D',
  31582. '\uFC3A': '\u0643\u062E',
  31583. '\uFC3B': '\u0643\u0644',
  31584. '\uFC3C': '\u0643\u0645',
  31585. '\uFC3D': '\u0643\u0649',
  31586. '\uFC3E': '\u0643\u064A',
  31587. '\uFC3F': '\u0644\u062C',
  31588. '\uFC40': '\u0644\u062D',
  31589. '\uFC41': '\u0644\u062E',
  31590. '\uFC42': '\u0644\u0645',
  31591. '\uFC43': '\u0644\u0649',
  31592. '\uFC44': '\u0644\u064A',
  31593. '\uFC45': '\u0645\u062C',
  31594. '\uFC46': '\u0645\u062D',
  31595. '\uFC47': '\u0645\u062E',
  31596. '\uFC48': '\u0645\u0645',
  31597. '\uFC49': '\u0645\u0649',
  31598. '\uFC4A': '\u0645\u064A',
  31599. '\uFC4B': '\u0646\u062C',
  31600. '\uFC4C': '\u0646\u062D',
  31601. '\uFC4D': '\u0646\u062E',
  31602. '\uFC4E': '\u0646\u0645',
  31603. '\uFC4F': '\u0646\u0649',
  31604. '\uFC50': '\u0646\u064A',
  31605. '\uFC51': '\u0647\u062C',
  31606. '\uFC52': '\u0647\u0645',
  31607. '\uFC53': '\u0647\u0649',
  31608. '\uFC54': '\u0647\u064A',
  31609. '\uFC55': '\u064A\u062C',
  31610. '\uFC56': '\u064A\u062D',
  31611. '\uFC57': '\u064A\u062E',
  31612. '\uFC58': '\u064A\u0645',
  31613. '\uFC59': '\u064A\u0649',
  31614. '\uFC5A': '\u064A\u064A',
  31615. '\uFC5B': '\u0630\u0670',
  31616. '\uFC5C': '\u0631\u0670',
  31617. '\uFC5D': '\u0649\u0670',
  31618. '\uFC5E': '\u0020\u064C\u0651',
  31619. '\uFC5F': '\u0020\u064D\u0651',
  31620. '\uFC60': '\u0020\u064E\u0651',
  31621. '\uFC61': '\u0020\u064F\u0651',
  31622. '\uFC62': '\u0020\u0650\u0651',
  31623. '\uFC63': '\u0020\u0651\u0670',
  31624. '\uFC64': '\u0626\u0631',
  31625. '\uFC65': '\u0626\u0632',
  31626. '\uFC66': '\u0626\u0645',
  31627. '\uFC67': '\u0626\u0646',
  31628. '\uFC68': '\u0626\u0649',
  31629. '\uFC69': '\u0626\u064A',
  31630. '\uFC6A': '\u0628\u0631',
  31631. '\uFC6B': '\u0628\u0632',
  31632. '\uFC6C': '\u0628\u0645',
  31633. '\uFC6D': '\u0628\u0646',
  31634. '\uFC6E': '\u0628\u0649',
  31635. '\uFC6F': '\u0628\u064A',
  31636. '\uFC70': '\u062A\u0631',
  31637. '\uFC71': '\u062A\u0632',
  31638. '\uFC72': '\u062A\u0645',
  31639. '\uFC73': '\u062A\u0646',
  31640. '\uFC74': '\u062A\u0649',
  31641. '\uFC75': '\u062A\u064A',
  31642. '\uFC76': '\u062B\u0631',
  31643. '\uFC77': '\u062B\u0632',
  31644. '\uFC78': '\u062B\u0645',
  31645. '\uFC79': '\u062B\u0646',
  31646. '\uFC7A': '\u062B\u0649',
  31647. '\uFC7B': '\u062B\u064A',
  31648. '\uFC7C': '\u0641\u0649',
  31649. '\uFC7D': '\u0641\u064A',
  31650. '\uFC7E': '\u0642\u0649',
  31651. '\uFC7F': '\u0642\u064A',
  31652. '\uFC80': '\u0643\u0627',
  31653. '\uFC81': '\u0643\u0644',
  31654. '\uFC82': '\u0643\u0645',
  31655. '\uFC83': '\u0643\u0649',
  31656. '\uFC84': '\u0643\u064A',
  31657. '\uFC85': '\u0644\u0645',
  31658. '\uFC86': '\u0644\u0649',
  31659. '\uFC87': '\u0644\u064A',
  31660. '\uFC88': '\u0645\u0627',
  31661. '\uFC89': '\u0645\u0645',
  31662. '\uFC8A': '\u0646\u0631',
  31663. '\uFC8B': '\u0646\u0632',
  31664. '\uFC8C': '\u0646\u0645',
  31665. '\uFC8D': '\u0646\u0646',
  31666. '\uFC8E': '\u0646\u0649',
  31667. '\uFC8F': '\u0646\u064A',
  31668. '\uFC90': '\u0649\u0670',
  31669. '\uFC91': '\u064A\u0631',
  31670. '\uFC92': '\u064A\u0632',
  31671. '\uFC93': '\u064A\u0645',
  31672. '\uFC94': '\u064A\u0646',
  31673. '\uFC95': '\u064A\u0649',
  31674. '\uFC96': '\u064A\u064A',
  31675. '\uFC97': '\u0626\u062C',
  31676. '\uFC98': '\u0626\u062D',
  31677. '\uFC99': '\u0626\u062E',
  31678. '\uFC9A': '\u0626\u0645',
  31679. '\uFC9B': '\u0626\u0647',
  31680. '\uFC9C': '\u0628\u062C',
  31681. '\uFC9D': '\u0628\u062D',
  31682. '\uFC9E': '\u0628\u062E',
  31683. '\uFC9F': '\u0628\u0645',
  31684. '\uFCA0': '\u0628\u0647',
  31685. '\uFCA1': '\u062A\u062C',
  31686. '\uFCA2': '\u062A\u062D',
  31687. '\uFCA3': '\u062A\u062E',
  31688. '\uFCA4': '\u062A\u0645',
  31689. '\uFCA5': '\u062A\u0647',
  31690. '\uFCA6': '\u062B\u0645',
  31691. '\uFCA7': '\u062C\u062D',
  31692. '\uFCA8': '\u062C\u0645',
  31693. '\uFCA9': '\u062D\u062C',
  31694. '\uFCAA': '\u062D\u0645',
  31695. '\uFCAB': '\u062E\u062C',
  31696. '\uFCAC': '\u062E\u0645',
  31697. '\uFCAD': '\u0633\u062C',
  31698. '\uFCAE': '\u0633\u062D',
  31699. '\uFCAF': '\u0633\u062E',
  31700. '\uFCB0': '\u0633\u0645',
  31701. '\uFCB1': '\u0635\u062D',
  31702. '\uFCB2': '\u0635\u062E',
  31703. '\uFCB3': '\u0635\u0645',
  31704. '\uFCB4': '\u0636\u062C',
  31705. '\uFCB5': '\u0636\u062D',
  31706. '\uFCB6': '\u0636\u062E',
  31707. '\uFCB7': '\u0636\u0645',
  31708. '\uFCB8': '\u0637\u062D',
  31709. '\uFCB9': '\u0638\u0645',
  31710. '\uFCBA': '\u0639\u062C',
  31711. '\uFCBB': '\u0639\u0645',
  31712. '\uFCBC': '\u063A\u062C',
  31713. '\uFCBD': '\u063A\u0645',
  31714. '\uFCBE': '\u0641\u062C',
  31715. '\uFCBF': '\u0641\u062D',
  31716. '\uFCC0': '\u0641\u062E',
  31717. '\uFCC1': '\u0641\u0645',
  31718. '\uFCC2': '\u0642\u062D',
  31719. '\uFCC3': '\u0642\u0645',
  31720. '\uFCC4': '\u0643\u062C',
  31721. '\uFCC5': '\u0643\u062D',
  31722. '\uFCC6': '\u0643\u062E',
  31723. '\uFCC7': '\u0643\u0644',
  31724. '\uFCC8': '\u0643\u0645',
  31725. '\uFCC9': '\u0644\u062C',
  31726. '\uFCCA': '\u0644\u062D',
  31727. '\uFCCB': '\u0644\u062E',
  31728. '\uFCCC': '\u0644\u0645',
  31729. '\uFCCD': '\u0644\u0647',
  31730. '\uFCCE': '\u0645\u062C',
  31731. '\uFCCF': '\u0645\u062D',
  31732. '\uFCD0': '\u0645\u062E',
  31733. '\uFCD1': '\u0645\u0645',
  31734. '\uFCD2': '\u0646\u062C',
  31735. '\uFCD3': '\u0646\u062D',
  31736. '\uFCD4': '\u0646\u062E',
  31737. '\uFCD5': '\u0646\u0645',
  31738. '\uFCD6': '\u0646\u0647',
  31739. '\uFCD7': '\u0647\u062C',
  31740. '\uFCD8': '\u0647\u0645',
  31741. '\uFCD9': '\u0647\u0670',
  31742. '\uFCDA': '\u064A\u062C',
  31743. '\uFCDB': '\u064A\u062D',
  31744. '\uFCDC': '\u064A\u062E',
  31745. '\uFCDD': '\u064A\u0645',
  31746. '\uFCDE': '\u064A\u0647',
  31747. '\uFCDF': '\u0626\u0645',
  31748. '\uFCE0': '\u0626\u0647',
  31749. '\uFCE1': '\u0628\u0645',
  31750. '\uFCE2': '\u0628\u0647',
  31751. '\uFCE3': '\u062A\u0645',
  31752. '\uFCE4': '\u062A\u0647',
  31753. '\uFCE5': '\u062B\u0645',
  31754. '\uFCE6': '\u062B\u0647',
  31755. '\uFCE7': '\u0633\u0645',
  31756. '\uFCE8': '\u0633\u0647',
  31757. '\uFCE9': '\u0634\u0645',
  31758. '\uFCEA': '\u0634\u0647',
  31759. '\uFCEB': '\u0643\u0644',
  31760. '\uFCEC': '\u0643\u0645',
  31761. '\uFCED': '\u0644\u0645',
  31762. '\uFCEE': '\u0646\u0645',
  31763. '\uFCEF': '\u0646\u0647',
  31764. '\uFCF0': '\u064A\u0645',
  31765. '\uFCF1': '\u064A\u0647',
  31766. '\uFCF2': '\u0640\u064E\u0651',
  31767. '\uFCF3': '\u0640\u064F\u0651',
  31768. '\uFCF4': '\u0640\u0650\u0651',
  31769. '\uFCF5': '\u0637\u0649',
  31770. '\uFCF6': '\u0637\u064A',
  31771. '\uFCF7': '\u0639\u0649',
  31772. '\uFCF8': '\u0639\u064A',
  31773. '\uFCF9': '\u063A\u0649',
  31774. '\uFCFA': '\u063A\u064A',
  31775. '\uFCFB': '\u0633\u0649',
  31776. '\uFCFC': '\u0633\u064A',
  31777. '\uFCFD': '\u0634\u0649',
  31778. '\uFCFE': '\u0634\u064A',
  31779. '\uFCFF': '\u062D\u0649',
  31780. '\uFD00': '\u062D\u064A',
  31781. '\uFD01': '\u062C\u0649',
  31782. '\uFD02': '\u062C\u064A',
  31783. '\uFD03': '\u062E\u0649',
  31784. '\uFD04': '\u062E\u064A',
  31785. '\uFD05': '\u0635\u0649',
  31786. '\uFD06': '\u0635\u064A',
  31787. '\uFD07': '\u0636\u0649',
  31788. '\uFD08': '\u0636\u064A',
  31789. '\uFD09': '\u0634\u062C',
  31790. '\uFD0A': '\u0634\u062D',
  31791. '\uFD0B': '\u0634\u062E',
  31792. '\uFD0C': '\u0634\u0645',
  31793. '\uFD0D': '\u0634\u0631',
  31794. '\uFD0E': '\u0633\u0631',
  31795. '\uFD0F': '\u0635\u0631',
  31796. '\uFD10': '\u0636\u0631',
  31797. '\uFD11': '\u0637\u0649',
  31798. '\uFD12': '\u0637\u064A',
  31799. '\uFD13': '\u0639\u0649',
  31800. '\uFD14': '\u0639\u064A',
  31801. '\uFD15': '\u063A\u0649',
  31802. '\uFD16': '\u063A\u064A',
  31803. '\uFD17': '\u0633\u0649',
  31804. '\uFD18': '\u0633\u064A',
  31805. '\uFD19': '\u0634\u0649',
  31806. '\uFD1A': '\u0634\u064A',
  31807. '\uFD1B': '\u062D\u0649',
  31808. '\uFD1C': '\u062D\u064A',
  31809. '\uFD1D': '\u062C\u0649',
  31810. '\uFD1E': '\u062C\u064A',
  31811. '\uFD1F': '\u062E\u0649',
  31812. '\uFD20': '\u062E\u064A',
  31813. '\uFD21': '\u0635\u0649',
  31814. '\uFD22': '\u0635\u064A',
  31815. '\uFD23': '\u0636\u0649',
  31816. '\uFD24': '\u0636\u064A',
  31817. '\uFD25': '\u0634\u062C',
  31818. '\uFD26': '\u0634\u062D',
  31819. '\uFD27': '\u0634\u062E',
  31820. '\uFD28': '\u0634\u0645',
  31821. '\uFD29': '\u0634\u0631',
  31822. '\uFD2A': '\u0633\u0631',
  31823. '\uFD2B': '\u0635\u0631',
  31824. '\uFD2C': '\u0636\u0631',
  31825. '\uFD2D': '\u0634\u062C',
  31826. '\uFD2E': '\u0634\u062D',
  31827. '\uFD2F': '\u0634\u062E',
  31828. '\uFD30': '\u0634\u0645',
  31829. '\uFD31': '\u0633\u0647',
  31830. '\uFD32': '\u0634\u0647',
  31831. '\uFD33': '\u0637\u0645',
  31832. '\uFD34': '\u0633\u062C',
  31833. '\uFD35': '\u0633\u062D',
  31834. '\uFD36': '\u0633\u062E',
  31835. '\uFD37': '\u0634\u062C',
  31836. '\uFD38': '\u0634\u062D',
  31837. '\uFD39': '\u0634\u062E',
  31838. '\uFD3A': '\u0637\u0645',
  31839. '\uFD3B': '\u0638\u0645',
  31840. '\uFD3C': '\u0627\u064B',
  31841. '\uFD3D': '\u0627\u064B',
  31842. '\uFD50': '\u062A\u062C\u0645',
  31843. '\uFD51': '\u062A\u062D\u062C',
  31844. '\uFD52': '\u062A\u062D\u062C',
  31845. '\uFD53': '\u062A\u062D\u0645',
  31846. '\uFD54': '\u062A\u062E\u0645',
  31847. '\uFD55': '\u062A\u0645\u062C',
  31848. '\uFD56': '\u062A\u0645\u062D',
  31849. '\uFD57': '\u062A\u0645\u062E',
  31850. '\uFD58': '\u062C\u0645\u062D',
  31851. '\uFD59': '\u062C\u0645\u062D',
  31852. '\uFD5A': '\u062D\u0645\u064A',
  31853. '\uFD5B': '\u062D\u0645\u0649',
  31854. '\uFD5C': '\u0633\u062D\u062C',
  31855. '\uFD5D': '\u0633\u062C\u062D',
  31856. '\uFD5E': '\u0633\u062C\u0649',
  31857. '\uFD5F': '\u0633\u0645\u062D',
  31858. '\uFD60': '\u0633\u0645\u062D',
  31859. '\uFD61': '\u0633\u0645\u062C',
  31860. '\uFD62': '\u0633\u0645\u0645',
  31861. '\uFD63': '\u0633\u0645\u0645',
  31862. '\uFD64': '\u0635\u062D\u062D',
  31863. '\uFD65': '\u0635\u062D\u062D',
  31864. '\uFD66': '\u0635\u0645\u0645',
  31865. '\uFD67': '\u0634\u062D\u0645',
  31866. '\uFD68': '\u0634\u062D\u0645',
  31867. '\uFD69': '\u0634\u062C\u064A',
  31868. '\uFD6A': '\u0634\u0645\u062E',
  31869. '\uFD6B': '\u0634\u0645\u062E',
  31870. '\uFD6C': '\u0634\u0645\u0645',
  31871. '\uFD6D': '\u0634\u0645\u0645',
  31872. '\uFD6E': '\u0636\u062D\u0649',
  31873. '\uFD6F': '\u0636\u062E\u0645',
  31874. '\uFD70': '\u0636\u062E\u0645',
  31875. '\uFD71': '\u0637\u0645\u062D',
  31876. '\uFD72': '\u0637\u0645\u062D',
  31877. '\uFD73': '\u0637\u0645\u0645',
  31878. '\uFD74': '\u0637\u0645\u064A',
  31879. '\uFD75': '\u0639\u062C\u0645',
  31880. '\uFD76': '\u0639\u0645\u0645',
  31881. '\uFD77': '\u0639\u0645\u0645',
  31882. '\uFD78': '\u0639\u0645\u0649',
  31883. '\uFD79': '\u063A\u0645\u0645',
  31884. '\uFD7A': '\u063A\u0645\u064A',
  31885. '\uFD7B': '\u063A\u0645\u0649',
  31886. '\uFD7C': '\u0641\u062E\u0645',
  31887. '\uFD7D': '\u0641\u062E\u0645',
  31888. '\uFD7E': '\u0642\u0645\u062D',
  31889. '\uFD7F': '\u0642\u0645\u0645',
  31890. '\uFD80': '\u0644\u062D\u0645',
  31891. '\uFD81': '\u0644\u062D\u064A',
  31892. '\uFD82': '\u0644\u062D\u0649',
  31893. '\uFD83': '\u0644\u062C\u062C',
  31894. '\uFD84': '\u0644\u062C\u062C',
  31895. '\uFD85': '\u0644\u062E\u0645',
  31896. '\uFD86': '\u0644\u062E\u0645',
  31897. '\uFD87': '\u0644\u0645\u062D',
  31898. '\uFD88': '\u0644\u0645\u062D',
  31899. '\uFD89': '\u0645\u062D\u062C',
  31900. '\uFD8A': '\u0645\u062D\u0645',
  31901. '\uFD8B': '\u0645\u062D\u064A',
  31902. '\uFD8C': '\u0645\u062C\u062D',
  31903. '\uFD8D': '\u0645\u062C\u0645',
  31904. '\uFD8E': '\u0645\u062E\u062C',
  31905. '\uFD8F': '\u0645\u062E\u0645',
  31906. '\uFD92': '\u0645\u062C\u062E',
  31907. '\uFD93': '\u0647\u0645\u062C',
  31908. '\uFD94': '\u0647\u0645\u0645',
  31909. '\uFD95': '\u0646\u062D\u0645',
  31910. '\uFD96': '\u0646\u062D\u0649',
  31911. '\uFD97': '\u0646\u062C\u0645',
  31912. '\uFD98': '\u0646\u062C\u0645',
  31913. '\uFD99': '\u0646\u062C\u0649',
  31914. '\uFD9A': '\u0646\u0645\u064A',
  31915. '\uFD9B': '\u0646\u0645\u0649',
  31916. '\uFD9C': '\u064A\u0645\u0645',
  31917. '\uFD9D': '\u064A\u0645\u0645',
  31918. '\uFD9E': '\u0628\u062E\u064A',
  31919. '\uFD9F': '\u062A\u062C\u064A',
  31920. '\uFDA0': '\u062A\u062C\u0649',
  31921. '\uFDA1': '\u062A\u062E\u064A',
  31922. '\uFDA2': '\u062A\u062E\u0649',
  31923. '\uFDA3': '\u062A\u0645\u064A',
  31924. '\uFDA4': '\u062A\u0645\u0649',
  31925. '\uFDA5': '\u062C\u0645\u064A',
  31926. '\uFDA6': '\u062C\u062D\u0649',
  31927. '\uFDA7': '\u062C\u0645\u0649',
  31928. '\uFDA8': '\u0633\u062E\u0649',
  31929. '\uFDA9': '\u0635\u062D\u064A',
  31930. '\uFDAA': '\u0634\u062D\u064A',
  31931. '\uFDAB': '\u0636\u062D\u064A',
  31932. '\uFDAC': '\u0644\u062C\u064A',
  31933. '\uFDAD': '\u0644\u0645\u064A',
  31934. '\uFDAE': '\u064A\u062D\u064A',
  31935. '\uFDAF': '\u064A\u062C\u064A',
  31936. '\uFDB0': '\u064A\u0645\u064A',
  31937. '\uFDB1': '\u0645\u0645\u064A',
  31938. '\uFDB2': '\u0642\u0645\u064A',
  31939. '\uFDB3': '\u0646\u062D\u064A',
  31940. '\uFDB4': '\u0642\u0645\u062D',
  31941. '\uFDB5': '\u0644\u062D\u0645',
  31942. '\uFDB6': '\u0639\u0645\u064A',
  31943. '\uFDB7': '\u0643\u0645\u064A',
  31944. '\uFDB8': '\u0646\u062C\u062D',
  31945. '\uFDB9': '\u0645\u062E\u064A',
  31946. '\uFDBA': '\u0644\u062C\u0645',
  31947. '\uFDBB': '\u0643\u0645\u0645',
  31948. '\uFDBC': '\u0644\u062C\u0645',
  31949. '\uFDBD': '\u0646\u062C\u062D',
  31950. '\uFDBE': '\u062C\u062D\u064A',
  31951. '\uFDBF': '\u062D\u062C\u064A',
  31952. '\uFDC0': '\u0645\u062C\u064A',
  31953. '\uFDC1': '\u0641\u0645\u064A',
  31954. '\uFDC2': '\u0628\u062D\u064A',
  31955. '\uFDC3': '\u0643\u0645\u0645',
  31956. '\uFDC4': '\u0639\u062C\u0645',
  31957. '\uFDC5': '\u0635\u0645\u0645',
  31958. '\uFDC6': '\u0633\u062E\u064A',
  31959. '\uFDC7': '\u0646\u062C\u064A',
  31960. '\uFE49': '\u203E',
  31961. '\uFE4A': '\u203E',
  31962. '\uFE4B': '\u203E',
  31963. '\uFE4C': '\u203E',
  31964. '\uFE4D': '\u005F',
  31965. '\uFE4E': '\u005F',
  31966. '\uFE4F': '\u005F',
  31967. '\uFE80': '\u0621',
  31968. '\uFE81': '\u0622',
  31969. '\uFE82': '\u0622',
  31970. '\uFE83': '\u0623',
  31971. '\uFE84': '\u0623',
  31972. '\uFE85': '\u0624',
  31973. '\uFE86': '\u0624',
  31974. '\uFE87': '\u0625',
  31975. '\uFE88': '\u0625',
  31976. '\uFE89': '\u0626',
  31977. '\uFE8A': '\u0626',
  31978. '\uFE8B': '\u0626',
  31979. '\uFE8C': '\u0626',
  31980. '\uFE8D': '\u0627',
  31981. '\uFE8E': '\u0627',
  31982. '\uFE8F': '\u0628',
  31983. '\uFE90': '\u0628',
  31984. '\uFE91': '\u0628',
  31985. '\uFE92': '\u0628',
  31986. '\uFE93': '\u0629',
  31987. '\uFE94': '\u0629',
  31988. '\uFE95': '\u062A',
  31989. '\uFE96': '\u062A',
  31990. '\uFE97': '\u062A',
  31991. '\uFE98': '\u062A',
  31992. '\uFE99': '\u062B',
  31993. '\uFE9A': '\u062B',
  31994. '\uFE9B': '\u062B',
  31995. '\uFE9C': '\u062B',
  31996. '\uFE9D': '\u062C',
  31997. '\uFE9E': '\u062C',
  31998. '\uFE9F': '\u062C',
  31999. '\uFEA0': '\u062C',
  32000. '\uFEA1': '\u062D',
  32001. '\uFEA2': '\u062D',
  32002. '\uFEA3': '\u062D',
  32003. '\uFEA4': '\u062D',
  32004. '\uFEA5': '\u062E',
  32005. '\uFEA6': '\u062E',
  32006. '\uFEA7': '\u062E',
  32007. '\uFEA8': '\u062E',
  32008. '\uFEA9': '\u062F',
  32009. '\uFEAA': '\u062F',
  32010. '\uFEAB': '\u0630',
  32011. '\uFEAC': '\u0630',
  32012. '\uFEAD': '\u0631',
  32013. '\uFEAE': '\u0631',
  32014. '\uFEAF': '\u0632',
  32015. '\uFEB0': '\u0632',
  32016. '\uFEB1': '\u0633',
  32017. '\uFEB2': '\u0633',
  32018. '\uFEB3': '\u0633',
  32019. '\uFEB4': '\u0633',
  32020. '\uFEB5': '\u0634',
  32021. '\uFEB6': '\u0634',
  32022. '\uFEB7': '\u0634',
  32023. '\uFEB8': '\u0634',
  32024. '\uFEB9': '\u0635',
  32025. '\uFEBA': '\u0635',
  32026. '\uFEBB': '\u0635',
  32027. '\uFEBC': '\u0635',
  32028. '\uFEBD': '\u0636',
  32029. '\uFEBE': '\u0636',
  32030. '\uFEBF': '\u0636',
  32031. '\uFEC0': '\u0636',
  32032. '\uFEC1': '\u0637',
  32033. '\uFEC2': '\u0637',
  32034. '\uFEC3': '\u0637',
  32035. '\uFEC4': '\u0637',
  32036. '\uFEC5': '\u0638',
  32037. '\uFEC6': '\u0638',
  32038. '\uFEC7': '\u0638',
  32039. '\uFEC8': '\u0638',
  32040. '\uFEC9': '\u0639',
  32041. '\uFECA': '\u0639',
  32042. '\uFECB': '\u0639',
  32043. '\uFECC': '\u0639',
  32044. '\uFECD': '\u063A',
  32045. '\uFECE': '\u063A',
  32046. '\uFECF': '\u063A',
  32047. '\uFED0': '\u063A',
  32048. '\uFED1': '\u0641',
  32049. '\uFED2': '\u0641',
  32050. '\uFED3': '\u0641',
  32051. '\uFED4': '\u0641',
  32052. '\uFED5': '\u0642',
  32053. '\uFED6': '\u0642',
  32054. '\uFED7': '\u0642',
  32055. '\uFED8': '\u0642',
  32056. '\uFED9': '\u0643',
  32057. '\uFEDA': '\u0643',
  32058. '\uFEDB': '\u0643',
  32059. '\uFEDC': '\u0643',
  32060. '\uFEDD': '\u0644',
  32061. '\uFEDE': '\u0644',
  32062. '\uFEDF': '\u0644',
  32063. '\uFEE0': '\u0644',
  32064. '\uFEE1': '\u0645',
  32065. '\uFEE2': '\u0645',
  32066. '\uFEE3': '\u0645',
  32067. '\uFEE4': '\u0645',
  32068. '\uFEE5': '\u0646',
  32069. '\uFEE6': '\u0646',
  32070. '\uFEE7': '\u0646',
  32071. '\uFEE8': '\u0646',
  32072. '\uFEE9': '\u0647',
  32073. '\uFEEA': '\u0647',
  32074. '\uFEEB': '\u0647',
  32075. '\uFEEC': '\u0647',
  32076. '\uFEED': '\u0648',
  32077. '\uFEEE': '\u0648',
  32078. '\uFEEF': '\u0649',
  32079. '\uFEF0': '\u0649',
  32080. '\uFEF1': '\u064A',
  32081. '\uFEF2': '\u064A',
  32082. '\uFEF3': '\u064A',
  32083. '\uFEF4': '\u064A',
  32084. '\uFEF5': '\u0644\u0622',
  32085. '\uFEF6': '\u0644\u0622',
  32086. '\uFEF7': '\u0644\u0623',
  32087. '\uFEF8': '\u0644\u0623',
  32088. '\uFEF9': '\u0644\u0625',
  32089. '\uFEFA': '\u0644\u0625',
  32090. '\uFEFB': '\u0644\u0627',
  32091. '\uFEFC': '\u0644\u0627'
  32092. };
  32093. function reverseIfRtl(chars) {
  32094. var charsLength = chars.length;
  32095. //reverse an arabic ligature
  32096. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  32097. return chars;
  32098. }
  32099. var s = '';
  32100. for (var ii = charsLength - 1; ii >= 0; ii--) {
  32101. s += chars[ii];
  32102. }
  32103. return s;
  32104. }
  32105. function adjustWidths(properties) {
  32106. if (!properties.fontMatrix) {
  32107. return;
  32108. }
  32109. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  32110. return;
  32111. }
  32112. // adjusting width to fontMatrix scale
  32113. var scale = 0.001 / properties.fontMatrix[0];
  32114. var glyphsWidths = properties.widths;
  32115. for (var glyph in glyphsWidths) {
  32116. glyphsWidths[glyph] *= scale;
  32117. }
  32118. properties.defaultWidth *= scale;
  32119. }
  32120. function getFontType(type, subtype) {
  32121. switch (type) {
  32122. case 'Type1':
  32123. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  32124. case 'CIDFontType0':
  32125. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  32126. FontType.CIDFONTTYPE0;
  32127. case 'OpenType':
  32128. return FontType.OPENTYPE;
  32129. case 'TrueType':
  32130. return FontType.TRUETYPE;
  32131. case 'CIDFontType2':
  32132. return FontType.CIDFONTTYPE2;
  32133. case 'MMType1':
  32134. return FontType.MMTYPE1;
  32135. case 'Type0':
  32136. return FontType.TYPE0;
  32137. default:
  32138. return FontType.UNKNOWN;
  32139. }
  32140. }
  32141. var Glyph = (function GlyphClosure() {
  32142. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  32143. isSpace) {
  32144. this.fontChar = fontChar;
  32145. this.unicode = unicode;
  32146. this.accent = accent;
  32147. this.width = width;
  32148. this.vmetric = vmetric;
  32149. this.operatorListId = operatorListId;
  32150. this.isSpace = isSpace;
  32151. }
  32152. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  32153. vmetric, operatorListId, isSpace) {
  32154. return this.fontChar === fontChar &&
  32155. this.unicode === unicode &&
  32156. this.accent === accent &&
  32157. this.width === width &&
  32158. this.vmetric === vmetric &&
  32159. this.operatorListId === operatorListId &&
  32160. this.isSpace === isSpace;
  32161. };
  32162. return Glyph;
  32163. })();
  32164. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  32165. function ToUnicodeMap(cmap) {
  32166. // The elements of this._map can be integers or strings, depending on how
  32167. // |cmap| was created.
  32168. this._map = cmap;
  32169. }
  32170. ToUnicodeMap.prototype = {
  32171. get length() {
  32172. return this._map.length;
  32173. },
  32174. forEach: function(callback) {
  32175. for (var charCode in this._map) {
  32176. callback(charCode, this._map[charCode].charCodeAt(0));
  32177. }
  32178. },
  32179. has: function(i) {
  32180. return this._map[i] !== undefined;
  32181. },
  32182. get: function(i) {
  32183. return this._map[i];
  32184. },
  32185. charCodeOf: function(v) {
  32186. return this._map.indexOf(v);
  32187. }
  32188. };
  32189. return ToUnicodeMap;
  32190. })();
  32191. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  32192. function IdentityToUnicodeMap(firstChar, lastChar) {
  32193. this.firstChar = firstChar;
  32194. this.lastChar = lastChar;
  32195. }
  32196. IdentityToUnicodeMap.prototype = {
  32197. get length() {
  32198. return (this.lastChar + 1) - this.firstChar;
  32199. },
  32200. forEach: function (callback) {
  32201. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  32202. callback(i, i);
  32203. }
  32204. },
  32205. has: function (i) {
  32206. return this.firstChar <= i && i <= this.lastChar;
  32207. },
  32208. get: function (i) {
  32209. if (this.firstChar <= i && i <= this.lastChar) {
  32210. return String.fromCharCode(i);
  32211. }
  32212. return undefined;
  32213. },
  32214. charCodeOf: function (v) {
  32215. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  32216. }
  32217. };
  32218. return IdentityToUnicodeMap;
  32219. })();
  32220. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  32221. function writeInt16(dest, offset, num) {
  32222. dest[offset] = (num >> 8) & 0xFF;
  32223. dest[offset + 1] = num & 0xFF;
  32224. }
  32225. function writeInt32(dest, offset, num) {
  32226. dest[offset] = (num >> 24) & 0xFF;
  32227. dest[offset + 1] = (num >> 16) & 0xFF;
  32228. dest[offset + 2] = (num >> 8) & 0xFF;
  32229. dest[offset + 3] = num & 0xFF;
  32230. }
  32231. function writeData(dest, offset, data) {
  32232. var i, ii;
  32233. if (data instanceof Uint8Array) {
  32234. dest.set(data, offset);
  32235. } else if (typeof data === 'string') {
  32236. for (i = 0, ii = data.length; i < ii; i++) {
  32237. dest[offset++] = data.charCodeAt(i) & 0xFF;
  32238. }
  32239. } else {
  32240. // treating everything else as array
  32241. for (i = 0, ii = data.length; i < ii; i++) {
  32242. dest[offset++] = data[i] & 0xFF;
  32243. }
  32244. }
  32245. }
  32246. function OpenTypeFileBuilder(sfnt) {
  32247. this.sfnt = sfnt;
  32248. this.tables = Object.create(null);
  32249. }
  32250. OpenTypeFileBuilder.getSearchParams =
  32251. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  32252. var maxPower2 = 1, log2 = 0;
  32253. while ((maxPower2 ^ entriesCount) > maxPower2) {
  32254. maxPower2 <<= 1;
  32255. log2++;
  32256. }
  32257. var searchRange = maxPower2 * entrySize;
  32258. return {
  32259. range: searchRange,
  32260. entry: log2,
  32261. rangeShift: entrySize * entriesCount - searchRange
  32262. };
  32263. };
  32264. var OTF_HEADER_SIZE = 12;
  32265. var OTF_TABLE_ENTRY_SIZE = 16;
  32266. OpenTypeFileBuilder.prototype = {
  32267. toArray: function OpenTypeFileBuilder_toArray() {
  32268. var sfnt = this.sfnt;
  32269. // Tables needs to be written by ascendant alphabetic order
  32270. var tables = this.tables;
  32271. var tablesNames = Object.keys(tables);
  32272. tablesNames.sort();
  32273. var numTables = tablesNames.length;
  32274. var i, j, jj, table, tableName;
  32275. // layout the tables data
  32276. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  32277. var tableOffsets = [offset];
  32278. for (i = 0; i < numTables; i++) {
  32279. table = tables[tablesNames[i]];
  32280. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  32281. offset += paddedLength;
  32282. tableOffsets.push(offset);
  32283. }
  32284. var file = new Uint8Array(offset);
  32285. // write the table data first (mostly for checksum)
  32286. for (i = 0; i < numTables; i++) {
  32287. table = tables[tablesNames[i]];
  32288. writeData(file, tableOffsets[i], table);
  32289. }
  32290. // sfnt version (4 bytes)
  32291. if (sfnt === 'true') {
  32292. // Windows hates the Mac TrueType sfnt version number
  32293. sfnt = string32(0x00010000);
  32294. }
  32295. file[0] = sfnt.charCodeAt(0) & 0xFF;
  32296. file[1] = sfnt.charCodeAt(1) & 0xFF;
  32297. file[2] = sfnt.charCodeAt(2) & 0xFF;
  32298. file[3] = sfnt.charCodeAt(3) & 0xFF;
  32299. // numTables (2 bytes)
  32300. writeInt16(file, 4, numTables);
  32301. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  32302. // searchRange (2 bytes)
  32303. writeInt16(file, 6, searchParams.range);
  32304. // entrySelector (2 bytes)
  32305. writeInt16(file, 8, searchParams.entry);
  32306. // rangeShift (2 bytes)
  32307. writeInt16(file, 10, searchParams.rangeShift);
  32308. offset = OTF_HEADER_SIZE;
  32309. // writing table entries
  32310. for (i = 0; i < numTables; i++) {
  32311. tableName = tablesNames[i];
  32312. file[offset] = tableName.charCodeAt(0) & 0xFF;
  32313. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  32314. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  32315. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  32316. // checksum
  32317. var checksum = 0;
  32318. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  32319. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  32320. (file[j + 2] << 8) + file[j + 3];
  32321. checksum = (checksum + quad) | 0;
  32322. }
  32323. writeInt32(file, offset + 4, checksum);
  32324. // offset
  32325. writeInt32(file, offset + 8, tableOffsets[i]);
  32326. // length
  32327. writeInt32(file, offset + 12, tables[tableName].length);
  32328. offset += OTF_TABLE_ENTRY_SIZE;
  32329. }
  32330. return file;
  32331. },
  32332. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  32333. if (tag in this.tables) {
  32334. throw new Error('Table ' + tag + ' already exists');
  32335. }
  32336. this.tables[tag] = data;
  32337. }
  32338. };
  32339. return OpenTypeFileBuilder;
  32340. })();
  32341. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  32342. // issues when they are painted on the canvas, e.g. complex-script shaping or
  32343. // control/whitespace characters. The ranges are listed in pairs: the first item
  32344. // is a code of the first problematic code, the second one is the next
  32345. // non-problematic code. The ranges must be in sorted order.
  32346. var ProblematicCharRanges = new Int32Array([
  32347. // Control characters.
  32348. 0x0000, 0x0020,
  32349. 0x007F, 0x00A1,
  32350. 0x00AD, 0x00AE,
  32351. // Chars that is used in complex-script shaping.
  32352. 0x0600, 0x0780,
  32353. 0x08A0, 0x10A0,
  32354. 0x1780, 0x1800,
  32355. // General punctuation chars.
  32356. 0x2000, 0x2010,
  32357. 0x2011, 0x2012,
  32358. 0x2028, 0x2030,
  32359. 0x205F, 0x2070,
  32360. 0x25CC, 0x25CD,
  32361. // Chars that is used in complex-script shaping.
  32362. 0xAA60, 0xAA80,
  32363. // Specials Unicode block.
  32364. 0xFFF0, 0x10000
  32365. ]);
  32366. /**
  32367. * 'Font' is the class the outside world should use, it encapsulate all the font
  32368. * decoding logics whatever type it is (assuming the font type is supported).
  32369. *
  32370. * For example to read a Type1 font and to attach it to the document:
  32371. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  32372. * type1Font.bind();
  32373. */
  32374. var Font = (function FontClosure() {
  32375. function Font(name, file, properties) {
  32376. var charCode, glyphName, fontChar;
  32377. this.name = name;
  32378. this.loadedName = properties.loadedName;
  32379. this.isType3Font = properties.isType3Font;
  32380. this.sizes = [];
  32381. this.glyphCache = {};
  32382. var names = name.split('+');
  32383. names = names.length > 1 ? names[1] : names[0];
  32384. names = names.split(/[-,_]/g)[0];
  32385. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  32386. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  32387. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  32388. var type = properties.type;
  32389. var subtype = properties.subtype;
  32390. this.type = type;
  32391. this.fallbackName = (this.isMonospace ? 'monospace' :
  32392. (this.isSerifFont ? 'serif' : 'sans-serif'));
  32393. this.differences = properties.differences;
  32394. this.widths = properties.widths;
  32395. this.defaultWidth = properties.defaultWidth;
  32396. this.composite = properties.composite;
  32397. this.wideChars = properties.wideChars;
  32398. this.cMap = properties.cMap;
  32399. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  32400. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  32401. this.fontMatrix = properties.fontMatrix;
  32402. this.bbox = properties.bbox;
  32403. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  32404. this.toFontChar = [];
  32405. if (properties.type === 'Type3') {
  32406. for (charCode = 0; charCode < 256; charCode++) {
  32407. this.toFontChar[charCode] = (this.differences[charCode] ||
  32408. properties.defaultEncoding[charCode]);
  32409. }
  32410. this.fontType = FontType.TYPE3;
  32411. return;
  32412. }
  32413. this.cidEncoding = properties.cidEncoding;
  32414. this.vertical = properties.vertical;
  32415. if (this.vertical) {
  32416. this.vmetrics = properties.vmetrics;
  32417. this.defaultVMetrics = properties.defaultVMetrics;
  32418. }
  32419. if (!file || file.isEmpty) {
  32420. if (file) {
  32421. // Some bad PDF generators will include empty font files,
  32422. // attempting to recover by assuming that no file exists.
  32423. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  32424. }
  32425. this.missingFile = true;
  32426. // The file data is not specified. Trying to fix the font name
  32427. // to be used with the canvas.font.
  32428. var fontName = name.replace(/[,_]/g, '-');
  32429. var isStandardFont = !!stdFontMap[fontName] ||
  32430. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32431. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32432. this.bold = (fontName.search(/bold/gi) !== -1);
  32433. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32434. (fontName.search(/italic/gi) !== -1));
  32435. // Use 'name' instead of 'fontName' here because the original
  32436. // name ArialBlack for example will be replaced by Helvetica.
  32437. this.black = (name.search(/Black/g) !== -1);
  32438. // if at least one width is present, remeasure all chars when exists
  32439. this.remeasure = Object.keys(this.widths).length > 0;
  32440. if (isStandardFont && type === 'CIDFontType2' &&
  32441. properties.cidEncoding.indexOf('Identity-') === 0) {
  32442. // Standard fonts might be embedded as CID font without glyph mapping.
  32443. // Building one based on GlyphMapForStandardFonts.
  32444. var map = [];
  32445. for (charCode in GlyphMapForStandardFonts) {
  32446. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32447. }
  32448. if (/ArialBlack/i.test(name)) {
  32449. for (charCode in SupplementalGlyphMapForArialBlack) {
  32450. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32451. }
  32452. }
  32453. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32454. if (!isIdentityUnicode) {
  32455. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32456. map[+charCode] = unicodeCharCode;
  32457. });
  32458. }
  32459. this.toFontChar = map;
  32460. this.toUnicode = new ToUnicodeMap(map);
  32461. } else if (/Symbol/i.test(fontName)) {
  32462. var symbols = Encodings.SymbolSetEncoding;
  32463. for (charCode in symbols) {
  32464. fontChar = GlyphsUnicode[symbols[charCode]];
  32465. if (!fontChar) {
  32466. continue;
  32467. }
  32468. this.toFontChar[charCode] = fontChar;
  32469. }
  32470. for (charCode in properties.differences) {
  32471. fontChar = GlyphsUnicode[properties.differences[charCode]];
  32472. if (!fontChar) {
  32473. continue;
  32474. }
  32475. this.toFontChar[charCode] = fontChar;
  32476. }
  32477. } else if (/Dingbats/i.test(fontName)) {
  32478. if (/Wingdings/i.test(name)) {
  32479. warn('Wingdings font without embedded font file, ' +
  32480. 'falling back to the ZapfDingbats encoding.');
  32481. }
  32482. var dingbats = Encodings.ZapfDingbatsEncoding;
  32483. for (charCode in dingbats) {
  32484. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  32485. if (!fontChar) {
  32486. continue;
  32487. }
  32488. this.toFontChar[charCode] = fontChar;
  32489. }
  32490. for (charCode in properties.differences) {
  32491. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  32492. if (!fontChar) {
  32493. continue;
  32494. }
  32495. this.toFontChar[charCode] = fontChar;
  32496. }
  32497. } else if (isStandardFont) {
  32498. this.toFontChar = [];
  32499. for (charCode in properties.defaultEncoding) {
  32500. glyphName = (properties.differences[charCode] ||
  32501. properties.defaultEncoding[charCode]);
  32502. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  32503. }
  32504. } else {
  32505. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  32506. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32507. if (notCidFont) {
  32508. glyphName = (properties.differences[charCode] ||
  32509. properties.defaultEncoding[charCode]);
  32510. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  32511. }
  32512. this.toFontChar[charCode] = unicodeCharCode;
  32513. }.bind(this));
  32514. }
  32515. this.loadedName = fontName.split('-')[0];
  32516. this.loading = false;
  32517. this.fontType = getFontType(type, subtype);
  32518. return;
  32519. }
  32520. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32521. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32522. // Some TrueType fonts by mistake claim Type1C
  32523. if (isTrueTypeFile(file)) {
  32524. subtype = 'TrueType';
  32525. } else {
  32526. type = 'Type1';
  32527. }
  32528. }
  32529. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32530. type = 'CIDFontType0';
  32531. }
  32532. if (subtype === 'OpenType') {
  32533. type = 'OpenType';
  32534. }
  32535. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32536. if (type === 'CIDFontType0') {
  32537. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  32538. }
  32539. var data;
  32540. switch (type) {
  32541. case 'MMType1':
  32542. info('MMType1 font (' + name + '), falling back to Type1.');
  32543. /* falls through */
  32544. case 'Type1':
  32545. case 'CIDFontType0':
  32546. this.mimetype = 'font/opentype';
  32547. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32548. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32549. adjustWidths(properties);
  32550. // Wrap the CFF data inside an OTF font file
  32551. data = this.convert(name, cff, properties);
  32552. break;
  32553. case 'OpenType':
  32554. case 'TrueType':
  32555. case 'CIDFontType2':
  32556. this.mimetype = 'font/opentype';
  32557. // Repair the TrueType file. It is can be damaged in the point of
  32558. // view of the sanitizer
  32559. data = this.checkAndRepair(name, file, properties);
  32560. if (this.isOpenType) {
  32561. adjustWidths(properties);
  32562. type = 'OpenType';
  32563. }
  32564. break;
  32565. default:
  32566. error('Font ' + type + ' is not supported');
  32567. break;
  32568. }
  32569. this.data = data;
  32570. this.fontType = getFontType(type, subtype);
  32571. // Transfer some properties again that could change during font conversion
  32572. this.fontMatrix = properties.fontMatrix;
  32573. this.widths = properties.widths;
  32574. this.defaultWidth = properties.defaultWidth;
  32575. this.encoding = properties.baseEncoding;
  32576. this.seacMap = properties.seacMap;
  32577. this.loading = true;
  32578. }
  32579. Font.getFontID = (function () {
  32580. var ID = 1;
  32581. return function Font_getFontID() {
  32582. return String(ID++);
  32583. };
  32584. })();
  32585. function int16(b0, b1) {
  32586. return (b0 << 8) + b1;
  32587. }
  32588. function int32(b0, b1, b2, b3) {
  32589. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32590. }
  32591. function string16(value) {
  32592. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32593. }
  32594. function safeString16(value) {
  32595. // clamp value to the 16-bit int range
  32596. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32597. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32598. }
  32599. function isTrueTypeFile(file) {
  32600. var header = file.peekBytes(4);
  32601. return readUint32(header, 0) === 0x00010000;
  32602. }
  32603. function isType1File(file) {
  32604. var header = file.peekBytes(2);
  32605. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32606. if (header[0] === 0x25 && header[1] === 0x21) {
  32607. return true;
  32608. }
  32609. // ... obviously some fonts violate that part of the specification,
  32610. // please refer to the comment in |Type1Font| below.
  32611. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32612. return true;
  32613. }
  32614. return false;
  32615. }
  32616. /**
  32617. * Helper function for |adjustMapping|.
  32618. * @return {boolean}
  32619. */
  32620. function isProblematicUnicodeLocation(code) {
  32621. // Using binary search to find a range start.
  32622. var i = 0, j = ProblematicCharRanges.length - 1;
  32623. while (i < j) {
  32624. var c = (i + j + 1) >> 1;
  32625. if (code < ProblematicCharRanges[c]) {
  32626. j = c - 1;
  32627. } else {
  32628. i = c;
  32629. }
  32630. }
  32631. // Even index means code in problematic range.
  32632. return !(i & 1);
  32633. }
  32634. /**
  32635. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32636. * with their unicode value. It also moves char codes that are in known
  32637. * problematic locations.
  32638. * @return {Object} Two properties:
  32639. * 'toFontChar' - maps original char codes(the value that will be read
  32640. * from commands such as show text) to the char codes that will be used in the
  32641. * font that we build
  32642. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32643. */
  32644. function adjustMapping(charCodeToGlyphId, properties) {
  32645. var toUnicode = properties.toUnicode;
  32646. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32647. var isIdentityUnicode =
  32648. properties.toUnicode instanceof IdentityToUnicodeMap;
  32649. var newMap = Object.create(null);
  32650. var toFontChar = [];
  32651. var usedFontCharCodes = [];
  32652. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32653. for (var originalCharCode in charCodeToGlyphId) {
  32654. originalCharCode |= 0;
  32655. var glyphId = charCodeToGlyphId[originalCharCode];
  32656. var fontCharCode = originalCharCode;
  32657. // First try to map the value to a unicode position if a non identity map
  32658. // was created.
  32659. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32660. var unicode = toUnicode.get(fontCharCode);
  32661. // TODO: Try to map ligatures to the correct spot.
  32662. if (unicode.length === 1) {
  32663. fontCharCode = unicode.charCodeAt(0);
  32664. }
  32665. }
  32666. // Try to move control characters, special characters and already mapped
  32667. // characters to the private use area since they will not be drawn by
  32668. // canvas if left in their current position. Also, move characters if the
  32669. // font was symbolic and there is only an identity unicode map since the
  32670. // characters probably aren't in the correct position (fixes an issue
  32671. // with firefox and thuluthfont).
  32672. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32673. isProblematicUnicodeLocation(fontCharCode) ||
  32674. (isSymbolic && isIdentityUnicode)) &&
  32675. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32676. // Loop to try and find a free spot in the private use area.
  32677. do {
  32678. fontCharCode = nextAvailableFontCharCode++;
  32679. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32680. fontCharCode = 0xF020;
  32681. nextAvailableFontCharCode = fontCharCode + 1;
  32682. }
  32683. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32684. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32685. }
  32686. newMap[fontCharCode] = glyphId;
  32687. toFontChar[originalCharCode] = fontCharCode;
  32688. usedFontCharCodes[fontCharCode] = true;
  32689. }
  32690. return {
  32691. toFontChar: toFontChar,
  32692. charCodeToGlyphId: newMap,
  32693. nextAvailableFontCharCode: nextAvailableFontCharCode
  32694. };
  32695. }
  32696. function getRanges(glyphs, numGlyphs) {
  32697. // Array.sort() sorts by characters, not numerically, so convert to an
  32698. // array of characters.
  32699. var codes = [];
  32700. for (var charCode in glyphs) {
  32701. // Remove an invalid glyph ID mappings to make OTS happy.
  32702. if (glyphs[charCode] >= numGlyphs) {
  32703. continue;
  32704. }
  32705. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32706. }
  32707. codes.sort(function fontGetRangesSort(a, b) {
  32708. return a.fontCharCode - b.fontCharCode;
  32709. });
  32710. // Split the sorted codes into ranges.
  32711. var ranges = [];
  32712. var length = codes.length;
  32713. for (var n = 0; n < length; ) {
  32714. var start = codes[n].fontCharCode;
  32715. var codeIndices = [codes[n].glyphId];
  32716. ++n;
  32717. var end = start;
  32718. while (n < length && end + 1 === codes[n].fontCharCode) {
  32719. codeIndices.push(codes[n].glyphId);
  32720. ++end;
  32721. ++n;
  32722. if (end === 0xFFFF) {
  32723. break;
  32724. }
  32725. }
  32726. ranges.push([start, end, codeIndices]);
  32727. }
  32728. return ranges;
  32729. }
  32730. function createCmapTable(glyphs, numGlyphs) {
  32731. var ranges = getRanges(glyphs, numGlyphs);
  32732. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32733. var cmap = '\x00\x00' + // version
  32734. string16(numTables) + // numTables
  32735. '\x00\x03' + // platformID
  32736. '\x00\x01' + // encodingID
  32737. string32(4 + numTables * 8); // start of the table record
  32738. var i, ii, j, jj;
  32739. for (i = ranges.length - 1; i >= 0; --i) {
  32740. if (ranges[i][0] <= 0xFFFF) { break; }
  32741. }
  32742. var bmpLength = i + 1;
  32743. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32744. ranges[i][1] = 0xFFFE;
  32745. }
  32746. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32747. var segCount = bmpLength + trailingRangesCount;
  32748. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32749. // Fill up the 4 parallel arrays describing the segments.
  32750. var startCount = '';
  32751. var endCount = '';
  32752. var idDeltas = '';
  32753. var idRangeOffsets = '';
  32754. var glyphsIds = '';
  32755. var bias = 0;
  32756. var range, start, end, codes;
  32757. for (i = 0, ii = bmpLength; i < ii; i++) {
  32758. range = ranges[i];
  32759. start = range[0];
  32760. end = range[1];
  32761. startCount += string16(start);
  32762. endCount += string16(end);
  32763. codes = range[2];
  32764. var contiguous = true;
  32765. for (j = 1, jj = codes.length; j < jj; ++j) {
  32766. if (codes[j] !== codes[j - 1] + 1) {
  32767. contiguous = false;
  32768. break;
  32769. }
  32770. }
  32771. if (!contiguous) {
  32772. var offset = (segCount - i) * 2 + bias * 2;
  32773. bias += (end - start + 1);
  32774. idDeltas += string16(0);
  32775. idRangeOffsets += string16(offset);
  32776. for (j = 0, jj = codes.length; j < jj; ++j) {
  32777. glyphsIds += string16(codes[j]);
  32778. }
  32779. } else {
  32780. var startCode = codes[0];
  32781. idDeltas += string16((startCode - start) & 0xFFFF);
  32782. idRangeOffsets += string16(0);
  32783. }
  32784. }
  32785. if (trailingRangesCount > 0) {
  32786. endCount += '\xFF\xFF';
  32787. startCount += '\xFF\xFF';
  32788. idDeltas += '\x00\x01';
  32789. idRangeOffsets += '\x00\x00';
  32790. }
  32791. var format314 = '\x00\x00' + // language
  32792. string16(2 * segCount) +
  32793. string16(searchParams.range) +
  32794. string16(searchParams.entry) +
  32795. string16(searchParams.rangeShift) +
  32796. endCount + '\x00\x00' + startCount +
  32797. idDeltas + idRangeOffsets + glyphsIds;
  32798. var format31012 = '';
  32799. var header31012 = '';
  32800. if (numTables > 1) {
  32801. cmap += '\x00\x03' + // platformID
  32802. '\x00\x0A' + // encodingID
  32803. string32(4 + numTables * 8 +
  32804. 4 + format314.length); // start of the table record
  32805. format31012 = '';
  32806. for (i = 0, ii = ranges.length; i < ii; i++) {
  32807. range = ranges[i];
  32808. start = range[0];
  32809. codes = range[2];
  32810. var code = codes[0];
  32811. for (j = 1, jj = codes.length; j < jj; ++j) {
  32812. if (codes[j] !== codes[j - 1] + 1) {
  32813. end = range[0] + j - 1;
  32814. format31012 += string32(start) + // startCharCode
  32815. string32(end) + // endCharCode
  32816. string32(code); // startGlyphID
  32817. start = end + 1;
  32818. code = codes[j];
  32819. }
  32820. }
  32821. format31012 += string32(start) + // startCharCode
  32822. string32(range[1]) + // endCharCode
  32823. string32(code); // startGlyphID
  32824. }
  32825. header31012 = '\x00\x0C' + // format
  32826. '\x00\x00' + // reserved
  32827. string32(format31012.length + 16) + // length
  32828. '\x00\x00\x00\x00' + // language
  32829. string32(format31012.length / 12); // nGroups
  32830. }
  32831. return cmap + '\x00\x04' + // format
  32832. string16(format314.length + 4) + // length
  32833. format314 + header31012 + format31012;
  32834. }
  32835. function validateOS2Table(os2) {
  32836. var stream = new Stream(os2.data);
  32837. var version = stream.getUint16();
  32838. // TODO verify all OS/2 tables fields, but currently we validate only those
  32839. // that give us issues
  32840. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32841. var selection = stream.getUint16();
  32842. if (version < 4 && (selection & 0x0300)) {
  32843. return false;
  32844. }
  32845. var firstChar = stream.getUint16();
  32846. var lastChar = stream.getUint16();
  32847. if (firstChar > lastChar) {
  32848. return false;
  32849. }
  32850. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32851. var usWinAscent = stream.getUint16();
  32852. if (usWinAscent === 0) { // makes font unreadable by windows
  32853. return false;
  32854. }
  32855. // OS/2 appears to be valid, resetting some fields
  32856. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32857. return true;
  32858. }
  32859. function createOS2Table(properties, charstrings, override) {
  32860. override = override || {
  32861. unitsPerEm: 0,
  32862. yMax: 0,
  32863. yMin: 0,
  32864. ascent: 0,
  32865. descent: 0
  32866. };
  32867. var ulUnicodeRange1 = 0;
  32868. var ulUnicodeRange2 = 0;
  32869. var ulUnicodeRange3 = 0;
  32870. var ulUnicodeRange4 = 0;
  32871. var firstCharIndex = null;
  32872. var lastCharIndex = 0;
  32873. if (charstrings) {
  32874. for (var code in charstrings) {
  32875. code |= 0;
  32876. if (firstCharIndex > code || !firstCharIndex) {
  32877. firstCharIndex = code;
  32878. }
  32879. if (lastCharIndex < code) {
  32880. lastCharIndex = code;
  32881. }
  32882. var position = getUnicodeRangeFor(code);
  32883. if (position < 32) {
  32884. ulUnicodeRange1 |= 1 << position;
  32885. } else if (position < 64) {
  32886. ulUnicodeRange2 |= 1 << position - 32;
  32887. } else if (position < 96) {
  32888. ulUnicodeRange3 |= 1 << position - 64;
  32889. } else if (position < 123) {
  32890. ulUnicodeRange4 |= 1 << position - 96;
  32891. } else {
  32892. error('Unicode ranges Bits > 123 are reserved for internal usage');
  32893. }
  32894. }
  32895. } else {
  32896. // TODO
  32897. firstCharIndex = 0;
  32898. lastCharIndex = 255;
  32899. }
  32900. var bbox = properties.bbox || [0, 0, 0, 0];
  32901. var unitsPerEm = (override.unitsPerEm ||
  32902. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  32903. // if the font units differ to the PDF glyph space units
  32904. // then scale up the values
  32905. var scale = (properties.ascentScaled ? 1.0 :
  32906. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  32907. var typoAscent = (override.ascent ||
  32908. Math.round(scale * (properties.ascent || bbox[3])));
  32909. var typoDescent = (override.descent ||
  32910. Math.round(scale * (properties.descent || bbox[1])));
  32911. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  32912. typoDescent = -typoDescent; // fixing incorrect descent
  32913. }
  32914. var winAscent = override.yMax || typoAscent;
  32915. var winDescent = -override.yMin || -typoDescent;
  32916. return '\x00\x03' + // version
  32917. '\x02\x24' + // xAvgCharWidth
  32918. '\x01\xF4' + // usWeightClass
  32919. '\x00\x05' + // usWidthClass
  32920. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  32921. '\x02\x8A' + // ySubscriptXSize
  32922. '\x02\xBB' + // ySubscriptYSize
  32923. '\x00\x00' + // ySubscriptXOffset
  32924. '\x00\x8C' + // ySubscriptYOffset
  32925. '\x02\x8A' + // ySuperScriptXSize
  32926. '\x02\xBB' + // ySuperScriptYSize
  32927. '\x00\x00' + // ySuperScriptXOffset
  32928. '\x01\xDF' + // ySuperScriptYOffset
  32929. '\x00\x31' + // yStrikeOutSize
  32930. '\x01\x02' + // yStrikeOutPosition
  32931. '\x00\x00' + // sFamilyClass
  32932. '\x00\x00\x06' +
  32933. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  32934. '\x00\x00\x00\x00\x00\x00' + // Panose
  32935. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  32936. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  32937. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  32938. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  32939. '\x2A\x32\x31\x2A' + // achVendID
  32940. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  32941. string16(firstCharIndex ||
  32942. properties.firstChar) + // usFirstCharIndex
  32943. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  32944. string16(typoAscent) + // sTypoAscender
  32945. string16(typoDescent) + // sTypoDescender
  32946. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  32947. string16(winAscent) + // usWinAscent
  32948. string16(winDescent) + // usWinDescent
  32949. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  32950. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  32951. string16(properties.xHeight) + // sxHeight
  32952. string16(properties.capHeight) + // sCapHeight
  32953. string16(0) + // usDefaultChar
  32954. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  32955. '\x00\x03'; // usMaxContext
  32956. }
  32957. function createPostTable(properties) {
  32958. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  32959. return ('\x00\x03\x00\x00' + // Version number
  32960. string32(angle) + // italicAngle
  32961. '\x00\x00' + // underlinePosition
  32962. '\x00\x00' + // underlineThickness
  32963. string32(properties.fixedPitch) + // isFixedPitch
  32964. '\x00\x00\x00\x00' + // minMemType42
  32965. '\x00\x00\x00\x00' + // maxMemType42
  32966. '\x00\x00\x00\x00' + // minMemType1
  32967. '\x00\x00\x00\x00'); // maxMemType1
  32968. }
  32969. function createNameTable(name, proto) {
  32970. if (!proto) {
  32971. proto = [[], []]; // no strings and unicode strings
  32972. }
  32973. var strings = [
  32974. proto[0][0] || 'Original licence', // 0.Copyright
  32975. proto[0][1] || name, // 1.Font family
  32976. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  32977. proto[0][3] || 'uniqueID', // 3.Unique ID
  32978. proto[0][4] || name, // 4.Full font name
  32979. proto[0][5] || 'Version 0.11', // 5.Version
  32980. proto[0][6] || '', // 6.Postscript name
  32981. proto[0][7] || 'Unknown', // 7.Trademark
  32982. proto[0][8] || 'Unknown', // 8.Manufacturer
  32983. proto[0][9] || 'Unknown' // 9.Designer
  32984. ];
  32985. // Mac want 1-byte per character strings while Windows want
  32986. // 2-bytes per character, so duplicate the names table
  32987. var stringsUnicode = [];
  32988. var i, ii, j, jj, str;
  32989. for (i = 0, ii = strings.length; i < ii; i++) {
  32990. str = proto[1][i] || strings[i];
  32991. var strBufUnicode = [];
  32992. for (j = 0, jj = str.length; j < jj; j++) {
  32993. strBufUnicode.push(string16(str.charCodeAt(j)));
  32994. }
  32995. stringsUnicode.push(strBufUnicode.join(''));
  32996. }
  32997. var names = [strings, stringsUnicode];
  32998. var platforms = ['\x00\x01', '\x00\x03'];
  32999. var encodings = ['\x00\x00', '\x00\x01'];
  33000. var languages = ['\x00\x00', '\x04\x09'];
  33001. var namesRecordCount = strings.length * platforms.length;
  33002. var nameTable =
  33003. '\x00\x00' + // format
  33004. string16(namesRecordCount) + // Number of names Record
  33005. string16(namesRecordCount * 12 + 6); // Storage
  33006. // Build the name records field
  33007. var strOffset = 0;
  33008. for (i = 0, ii = platforms.length; i < ii; i++) {
  33009. var strs = names[i];
  33010. for (j = 0, jj = strs.length; j < jj; j++) {
  33011. str = strs[j];
  33012. var nameRecord =
  33013. platforms[i] + // platform ID
  33014. encodings[i] + // encoding ID
  33015. languages[i] + // language ID
  33016. string16(j) + // name ID
  33017. string16(str.length) +
  33018. string16(strOffset);
  33019. nameTable += nameRecord;
  33020. strOffset += str.length;
  33021. }
  33022. }
  33023. nameTable += strings.join('') + stringsUnicode.join('');
  33024. return nameTable;
  33025. }
  33026. Font.prototype = {
  33027. name: null,
  33028. font: null,
  33029. mimetype: null,
  33030. encoding: null,
  33031. get renderer() {
  33032. var renderer = FontRendererFactory.create(this);
  33033. return shadow(this, 'renderer', renderer);
  33034. },
  33035. exportData: function Font_exportData() {
  33036. var data = {};
  33037. for (var i in this) {
  33038. if (this.hasOwnProperty(i)) {
  33039. data[i] = this[i];
  33040. }
  33041. }
  33042. return data;
  33043. },
  33044. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  33045. function readTableEntry(file) {
  33046. var tag = bytesToString(file.getBytes(4));
  33047. var checksum = file.getInt32();
  33048. var offset = file.getInt32() >>> 0;
  33049. var length = file.getInt32() >>> 0;
  33050. // Read the table associated data
  33051. var previousPosition = file.pos;
  33052. file.pos = file.start ? file.start : 0;
  33053. file.skip(offset);
  33054. var data = file.getBytes(length);
  33055. file.pos = previousPosition;
  33056. if (tag === 'head') {
  33057. // clearing checksum adjustment
  33058. data[8] = data[9] = data[10] = data[11] = 0;
  33059. data[17] |= 0x20; //Set font optimized for cleartype flag
  33060. }
  33061. return {
  33062. tag: tag,
  33063. checksum: checksum,
  33064. length: length,
  33065. offset: offset,
  33066. data: data
  33067. };
  33068. }
  33069. function readOpenTypeHeader(ttf) {
  33070. return {
  33071. version: bytesToString(ttf.getBytes(4)),
  33072. numTables: ttf.getUint16(),
  33073. searchRange: ttf.getUint16(),
  33074. entrySelector: ttf.getUint16(),
  33075. rangeShift: ttf.getUint16()
  33076. };
  33077. }
  33078. /**
  33079. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  33080. * PDF spec
  33081. */
  33082. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  33083. if (!cmap) {
  33084. warn('No cmap table available.');
  33085. return {
  33086. platformId: -1,
  33087. encodingId: -1,
  33088. mappings: [],
  33089. hasShortCmap: false
  33090. };
  33091. }
  33092. var segment;
  33093. var start = (font.start ? font.start : 0) + cmap.offset;
  33094. font.pos = start;
  33095. var version = font.getUint16();
  33096. var numTables = font.getUint16();
  33097. var potentialTable;
  33098. var canBreak = false;
  33099. // There's an order of preference in terms of which cmap subtable to
  33100. // use:
  33101. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  33102. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  33103. // The following takes advantage of the fact that the tables are sorted
  33104. // to work.
  33105. for (var i = 0; i < numTables; i++) {
  33106. var platformId = font.getUint16();
  33107. var encodingId = font.getUint16();
  33108. var offset = font.getInt32() >>> 0;
  33109. var useTable = false;
  33110. if (platformId === 0 && encodingId === 0) {
  33111. useTable = true;
  33112. // Continue the loop since there still may be a higher priority
  33113. // table.
  33114. } else if (platformId === 1 && encodingId === 0) {
  33115. useTable = true;
  33116. // Continue the loop since there still may be a higher priority
  33117. // table.
  33118. } else if (platformId === 3 && encodingId === 1 &&
  33119. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  33120. useTable = true;
  33121. if (!isSymbolicFont) {
  33122. canBreak = true;
  33123. }
  33124. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  33125. useTable = true;
  33126. canBreak = true;
  33127. }
  33128. if (useTable) {
  33129. potentialTable = {
  33130. platformId: platformId,
  33131. encodingId: encodingId,
  33132. offset: offset
  33133. };
  33134. }
  33135. if (canBreak) {
  33136. break;
  33137. }
  33138. }
  33139. if (potentialTable) {
  33140. font.pos = start + potentialTable.offset;
  33141. }
  33142. if (!potentialTable || font.peekByte() === -1) {
  33143. warn('Could not find a preferred cmap table.');
  33144. return {
  33145. platformId: -1,
  33146. encodingId: -1,
  33147. mappings: [],
  33148. hasShortCmap: false
  33149. };
  33150. }
  33151. var format = font.getUint16();
  33152. var length = font.getUint16();
  33153. var language = font.getUint16();
  33154. var hasShortCmap = false;
  33155. var mappings = [];
  33156. var j, glyphId;
  33157. // TODO(mack): refactor this cmap subtable reading logic out
  33158. if (format === 0) {
  33159. for (j = 0; j < 256; j++) {
  33160. var index = font.getByte();
  33161. if (!index) {
  33162. continue;
  33163. }
  33164. mappings.push({
  33165. charCode: j,
  33166. glyphId: index
  33167. });
  33168. }
  33169. hasShortCmap = true;
  33170. } else if (format === 4) {
  33171. // re-creating the table in format 4 since the encoding
  33172. // might be changed
  33173. var segCount = (font.getUint16() >> 1);
  33174. font.getBytes(6); // skipping range fields
  33175. var segIndex, segments = [];
  33176. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33177. segments.push({ end: font.getUint16() });
  33178. }
  33179. font.getUint16();
  33180. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33181. segments[segIndex].start = font.getUint16();
  33182. }
  33183. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33184. segments[segIndex].delta = font.getUint16();
  33185. }
  33186. var offsetsCount = 0;
  33187. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33188. segment = segments[segIndex];
  33189. var rangeOffset = font.getUint16();
  33190. if (!rangeOffset) {
  33191. segment.offsetIndex = -1;
  33192. continue;
  33193. }
  33194. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  33195. segment.offsetIndex = offsetIndex;
  33196. offsetsCount = Math.max(offsetsCount, offsetIndex +
  33197. segment.end - segment.start + 1);
  33198. }
  33199. var offsets = [];
  33200. for (j = 0; j < offsetsCount; j++) {
  33201. offsets.push(font.getUint16());
  33202. }
  33203. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33204. segment = segments[segIndex];
  33205. start = segment.start;
  33206. var end = segment.end;
  33207. var delta = segment.delta;
  33208. offsetIndex = segment.offsetIndex;
  33209. for (j = start; j <= end; j++) {
  33210. if (j === 0xFFFF) {
  33211. continue;
  33212. }
  33213. glyphId = (offsetIndex < 0 ?
  33214. j : offsets[offsetIndex + j - start]);
  33215. glyphId = (glyphId + delta) & 0xFFFF;
  33216. if (glyphId === 0) {
  33217. continue;
  33218. }
  33219. mappings.push({
  33220. charCode: j,
  33221. glyphId: glyphId
  33222. });
  33223. }
  33224. }
  33225. } else if (format === 6) {
  33226. // Format 6 is a 2-bytes dense mapping, which means the font data
  33227. // lives glue together even if they are pretty far in the unicode
  33228. // table. (This looks weird, so I can have missed something), this
  33229. // works on Linux but seems to fails on Mac so let's rewrite the
  33230. // cmap table to a 3-1-4 style
  33231. var firstCode = font.getUint16();
  33232. var entryCount = font.getUint16();
  33233. for (j = 0; j < entryCount; j++) {
  33234. glyphId = font.getUint16();
  33235. var charCode = firstCode + j;
  33236. mappings.push({
  33237. charCode: charCode,
  33238. glyphId: glyphId
  33239. });
  33240. }
  33241. } else {
  33242. warn('cmap table has unsupported format: ' + format);
  33243. return {
  33244. platformId: -1,
  33245. encodingId: -1,
  33246. mappings: [],
  33247. hasShortCmap: false
  33248. };
  33249. }
  33250. // removing duplicate entries
  33251. mappings.sort(function (a, b) {
  33252. return a.charCode - b.charCode;
  33253. });
  33254. for (i = 1; i < mappings.length; i++) {
  33255. if (mappings[i - 1].charCode === mappings[i].charCode) {
  33256. mappings.splice(i, 1);
  33257. i--;
  33258. }
  33259. }
  33260. return {
  33261. platformId: potentialTable.platformId,
  33262. encodingId: potentialTable.encodingId,
  33263. mappings: mappings,
  33264. hasShortCmap: hasShortCmap
  33265. };
  33266. }
  33267. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  33268. if (!header) {
  33269. if (metrics) {
  33270. metrics.data = null;
  33271. }
  33272. return;
  33273. }
  33274. font.pos = (font.start ? font.start : 0) + header.offset;
  33275. font.pos += header.length - 2;
  33276. var numOfMetrics = font.getUint16();
  33277. if (numOfMetrics > numGlyphs) {
  33278. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  33279. 'greater than the numGlyphs (' + numGlyphs + ')');
  33280. // Reduce numOfMetrics if it is greater than numGlyphs
  33281. numOfMetrics = numGlyphs;
  33282. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  33283. header.data[35] = numOfMetrics & 0x00ff;
  33284. }
  33285. var numOfSidebearings = numGlyphs - numOfMetrics;
  33286. var numMissing = numOfSidebearings -
  33287. ((metrics.length - numOfMetrics * 4) >> 1);
  33288. if (numMissing > 0) {
  33289. // For each missing glyph, we set both the width and lsb to 0 (zero).
  33290. // Since we need to add two properties for each glyph, this explains
  33291. // the use of |numMissing * 2| when initializing the typed array.
  33292. var entries = new Uint8Array(metrics.length + numMissing * 2);
  33293. entries.set(metrics.data);
  33294. metrics.data = entries;
  33295. }
  33296. }
  33297. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  33298. hintsValid) {
  33299. if (sourceEnd - sourceStart <= 12) {
  33300. // glyph with data less than 12 is invalid one
  33301. return 0;
  33302. }
  33303. var glyf = source.subarray(sourceStart, sourceEnd);
  33304. var contoursCount = (glyf[0] << 8) | glyf[1];
  33305. if (contoursCount & 0x8000) {
  33306. // complex glyph, writing as is
  33307. dest.set(glyf, destStart);
  33308. return glyf.length;
  33309. }
  33310. var i, j = 10, flagsCount = 0;
  33311. for (i = 0; i < contoursCount; i++) {
  33312. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  33313. flagsCount = endPoint + 1;
  33314. j += 2;
  33315. }
  33316. // skipping instructions
  33317. var instructionsStart = j;
  33318. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  33319. j += 2 + instructionsLength;
  33320. var instructionsEnd = j;
  33321. // validating flags
  33322. var coordinatesLength = 0;
  33323. for (i = 0; i < flagsCount; i++) {
  33324. var flag = glyf[j++];
  33325. if (flag & 0xC0) {
  33326. // reserved flags must be zero, cleaning up
  33327. glyf[j - 1] = flag & 0x3F;
  33328. }
  33329. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  33330. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  33331. coordinatesLength += xyLength;
  33332. if (flag & 8) {
  33333. var repeat = glyf[j++];
  33334. i += repeat;
  33335. coordinatesLength += repeat * xyLength;
  33336. }
  33337. }
  33338. // glyph without coordinates will be rejected
  33339. if (coordinatesLength === 0) {
  33340. return 0;
  33341. }
  33342. var glyphDataLength = j + coordinatesLength;
  33343. if (glyphDataLength > glyf.length) {
  33344. // not enough data for coordinates
  33345. return 0;
  33346. }
  33347. if (!hintsValid && instructionsLength > 0) {
  33348. dest.set(glyf.subarray(0, instructionsStart), destStart);
  33349. dest.set([0, 0], destStart + instructionsStart);
  33350. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  33351. destStart + instructionsStart + 2);
  33352. glyphDataLength -= instructionsLength;
  33353. if (glyf.length - glyphDataLength > 3) {
  33354. glyphDataLength = (glyphDataLength + 3) & ~3;
  33355. }
  33356. return glyphDataLength;
  33357. }
  33358. if (glyf.length - glyphDataLength > 3) {
  33359. // truncating and aligning to 4 bytes the long glyph data
  33360. glyphDataLength = (glyphDataLength + 3) & ~3;
  33361. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  33362. return glyphDataLength;
  33363. }
  33364. // glyph data is fine
  33365. dest.set(glyf, destStart);
  33366. return glyf.length;
  33367. }
  33368. function sanitizeHead(head, numGlyphs, locaLength) {
  33369. var data = head.data;
  33370. // Validate version:
  33371. // Should always be 0x00010000
  33372. var version = int32(data[0], data[1], data[2], data[3]);
  33373. if (version >> 16 !== 1) {
  33374. info('Attempting to fix invalid version in head table: ' + version);
  33375. data[0] = 0;
  33376. data[1] = 1;
  33377. data[2] = 0;
  33378. data[3] = 0;
  33379. }
  33380. var indexToLocFormat = int16(data[50], data[51]);
  33381. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  33382. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  33383. indexToLocFormat);
  33384. // The value of indexToLocFormat should be 0 if the loca table
  33385. // consists of short offsets, and should be 1 if the loca table
  33386. // consists of long offsets.
  33387. //
  33388. // The number of entries in the loca table should be numGlyphs + 1.
  33389. //
  33390. // Using this information, we can work backwards to deduce if the
  33391. // size of each offset in the loca table, and thus figure out the
  33392. // appropriate value for indexToLocFormat.
  33393. var numGlyphsPlusOne = numGlyphs + 1;
  33394. if (locaLength === numGlyphsPlusOne << 1) {
  33395. // 0x0000 indicates the loca table consists of short offsets
  33396. data[50] = 0;
  33397. data[51] = 0;
  33398. } else if (locaLength === numGlyphsPlusOne << 2) {
  33399. // 0x0001 indicates the loca table consists of long offsets
  33400. data[50] = 0;
  33401. data[51] = 1;
  33402. } else {
  33403. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  33404. }
  33405. }
  33406. }
  33407. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  33408. isGlyphLocationsLong, hintsValid,
  33409. dupFirstEntry) {
  33410. var itemSize, itemDecode, itemEncode;
  33411. if (isGlyphLocationsLong) {
  33412. itemSize = 4;
  33413. itemDecode = function fontItemDecodeLong(data, offset) {
  33414. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33415. (data[offset + 2] << 8) | data[offset + 3];
  33416. };
  33417. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33418. data[offset] = (value >>> 24) & 0xFF;
  33419. data[offset + 1] = (value >> 16) & 0xFF;
  33420. data[offset + 2] = (value >> 8) & 0xFF;
  33421. data[offset + 3] = value & 0xFF;
  33422. };
  33423. } else {
  33424. itemSize = 2;
  33425. itemDecode = function fontItemDecode(data, offset) {
  33426. return (data[offset] << 9) | (data[offset + 1] << 1);
  33427. };
  33428. itemEncode = function fontItemEncode(data, offset, value) {
  33429. data[offset] = (value >> 9) & 0xFF;
  33430. data[offset + 1] = (value >> 1) & 0xFF;
  33431. };
  33432. }
  33433. var locaData = loca.data;
  33434. var locaDataSize = itemSize * (1 + numGlyphs);
  33435. // is loca.data too short or long?
  33436. if (locaData.length !== locaDataSize) {
  33437. locaData = new Uint8Array(locaDataSize);
  33438. locaData.set(loca.data.subarray(0, locaDataSize));
  33439. loca.data = locaData;
  33440. }
  33441. // removing the invalid glyphs
  33442. var oldGlyfData = glyf.data;
  33443. var oldGlyfDataLength = oldGlyfData.length;
  33444. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33445. var startOffset = itemDecode(locaData, 0);
  33446. var writeOffset = 0;
  33447. var missingGlyphData = {};
  33448. itemEncode(locaData, 0, writeOffset);
  33449. var i, j;
  33450. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33451. var endOffset = itemDecode(locaData, j);
  33452. if (endOffset > oldGlyfDataLength &&
  33453. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33454. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33455. // the glyf table size, which makes last glyph out of range.
  33456. endOffset = oldGlyfDataLength;
  33457. }
  33458. if (endOffset > oldGlyfDataLength) {
  33459. // glyph end offset points outside glyf data, rejecting the glyph
  33460. itemEncode(locaData, j, writeOffset);
  33461. startOffset = endOffset;
  33462. continue;
  33463. }
  33464. if (startOffset === endOffset) {
  33465. missingGlyphData[i] = true;
  33466. }
  33467. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33468. newGlyfData, writeOffset, hintsValid);
  33469. writeOffset += newLength;
  33470. itemEncode(locaData, j, writeOffset);
  33471. startOffset = endOffset;
  33472. }
  33473. if (writeOffset === 0) {
  33474. // glyf table cannot be empty -- redoing the glyf and loca tables
  33475. // to have single glyph with one point
  33476. var simpleGlyph = new Uint8Array(
  33477. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33478. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33479. itemEncode(locaData, j, simpleGlyph.length);
  33480. }
  33481. glyf.data = simpleGlyph;
  33482. return missingGlyphData;
  33483. }
  33484. if (dupFirstEntry) {
  33485. var firstEntryLength = itemDecode(locaData, itemSize);
  33486. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33487. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33488. } else {
  33489. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33490. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33491. }
  33492. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33493. itemEncode(loca.data, locaData.length - itemSize,
  33494. writeOffset + firstEntryLength);
  33495. } else {
  33496. glyf.data = newGlyfData.subarray(0, writeOffset);
  33497. }
  33498. return missingGlyphData;
  33499. }
  33500. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33501. var start = (font.start ? font.start : 0) + post.offset;
  33502. font.pos = start;
  33503. var length = post.length, end = start + length;
  33504. var version = font.getInt32();
  33505. // skip rest to the tables
  33506. font.getBytes(28);
  33507. var glyphNames;
  33508. var valid = true;
  33509. var i;
  33510. switch (version) {
  33511. case 0x00010000:
  33512. glyphNames = MacStandardGlyphOrdering;
  33513. break;
  33514. case 0x00020000:
  33515. var numGlyphs = font.getUint16();
  33516. if (numGlyphs !== maxpNumGlyphs) {
  33517. valid = false;
  33518. break;
  33519. }
  33520. var glyphNameIndexes = [];
  33521. for (i = 0; i < numGlyphs; ++i) {
  33522. var index = font.getUint16();
  33523. if (index >= 32768) {
  33524. valid = false;
  33525. break;
  33526. }
  33527. glyphNameIndexes.push(index);
  33528. }
  33529. if (!valid) {
  33530. break;
  33531. }
  33532. var customNames = [];
  33533. var strBuf = [];
  33534. while (font.pos < end) {
  33535. var stringLength = font.getByte();
  33536. strBuf.length = stringLength;
  33537. for (i = 0; i < stringLength; ++i) {
  33538. strBuf[i] = String.fromCharCode(font.getByte());
  33539. }
  33540. customNames.push(strBuf.join(''));
  33541. }
  33542. glyphNames = [];
  33543. for (i = 0; i < numGlyphs; ++i) {
  33544. var j = glyphNameIndexes[i];
  33545. if (j < 258) {
  33546. glyphNames.push(MacStandardGlyphOrdering[j]);
  33547. continue;
  33548. }
  33549. glyphNames.push(customNames[j - 258]);
  33550. }
  33551. break;
  33552. case 0x00030000:
  33553. break;
  33554. default:
  33555. warn('Unknown/unsupported post table version ' + version);
  33556. valid = false;
  33557. if (properties.defaultEncoding) {
  33558. glyphNames = properties.defaultEncoding;
  33559. }
  33560. break;
  33561. }
  33562. properties.glyphNames = glyphNames;
  33563. return valid;
  33564. }
  33565. function readNameTable(nameTable) {
  33566. var start = (font.start ? font.start : 0) + nameTable.offset;
  33567. font.pos = start;
  33568. var names = [[], []];
  33569. var length = nameTable.length, end = start + length;
  33570. var format = font.getUint16();
  33571. var FORMAT_0_HEADER_LENGTH = 6;
  33572. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33573. // unsupported name table format or table "too" small
  33574. return names;
  33575. }
  33576. var numRecords = font.getUint16();
  33577. var stringsStart = font.getUint16();
  33578. var records = [];
  33579. var NAME_RECORD_LENGTH = 12;
  33580. var i, ii;
  33581. for (i = 0; i < numRecords &&
  33582. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33583. var r = {
  33584. platform: font.getUint16(),
  33585. encoding: font.getUint16(),
  33586. language: font.getUint16(),
  33587. name: font.getUint16(),
  33588. length: font.getUint16(),
  33589. offset: font.getUint16()
  33590. };
  33591. // using only Macintosh and Windows platform/encoding names
  33592. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33593. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33594. records.push(r);
  33595. }
  33596. }
  33597. for (i = 0, ii = records.length; i < ii; i++) {
  33598. var record = records[i];
  33599. var pos = start + stringsStart + record.offset;
  33600. if (pos + record.length > end) {
  33601. continue; // outside of name table, ignoring
  33602. }
  33603. font.pos = pos;
  33604. var nameIndex = record.name;
  33605. if (record.encoding) {
  33606. // unicode
  33607. var str = '';
  33608. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33609. str += String.fromCharCode(font.getUint16());
  33610. }
  33611. names[1][nameIndex] = str;
  33612. } else {
  33613. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33614. }
  33615. }
  33616. return names;
  33617. }
  33618. var TTOpsStackDeltas = [
  33619. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33620. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33621. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33622. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33623. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33624. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33625. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33626. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33627. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33628. // 0xC0-DF == -1 and 0xE0-FF == -2
  33629. function sanitizeTTProgram(table, ttContext) {
  33630. var data = table.data;
  33631. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33632. var stack = [];
  33633. var callstack = [];
  33634. var functionsCalled = [];
  33635. var tooComplexToFollowFunctions =
  33636. ttContext.tooComplexToFollowFunctions;
  33637. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33638. for (var ii = data.length; i < ii;) {
  33639. var op = data[i++];
  33640. // The TrueType instruction set docs can be found at
  33641. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33642. if (op === 0x40) { // NPUSHB - pushes n bytes
  33643. n = data[i++];
  33644. if (inFDEF || inELSE) {
  33645. i += n;
  33646. } else {
  33647. for (j = 0; j < n; j++) {
  33648. stack.push(data[i++]);
  33649. }
  33650. }
  33651. } else if (op === 0x41) { // NPUSHW - pushes n words
  33652. n = data[i++];
  33653. if (inFDEF || inELSE) {
  33654. i += n * 2;
  33655. } else {
  33656. for (j = 0; j < n; j++) {
  33657. b = data[i++];
  33658. stack.push((b << 8) | data[i++]);
  33659. }
  33660. }
  33661. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33662. n = op - 0xB0 + 1;
  33663. if (inFDEF || inELSE) {
  33664. i += n;
  33665. } else {
  33666. for (j = 0; j < n; j++) {
  33667. stack.push(data[i++]);
  33668. }
  33669. }
  33670. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33671. n = op - 0xB8 + 1;
  33672. if (inFDEF || inELSE) {
  33673. i += n * 2;
  33674. } else {
  33675. for (j = 0; j < n; j++) {
  33676. b = data[i++];
  33677. stack.push((b << 8) | data[i++]);
  33678. }
  33679. }
  33680. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33681. if (!inFDEF && !inELSE) {
  33682. // collecting inforamtion about which functions are used
  33683. funcId = stack[stack.length - 1];
  33684. ttContext.functionsUsed[funcId] = true;
  33685. if (funcId in ttContext.functionsStackDeltas) {
  33686. stack.length += ttContext.functionsStackDeltas[funcId];
  33687. } else if (funcId in ttContext.functionsDefined &&
  33688. functionsCalled.indexOf(funcId) < 0) {
  33689. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33690. functionsCalled.push(funcId);
  33691. pc = ttContext.functionsDefined[funcId];
  33692. if (!pc) {
  33693. warn('TT: CALL non-existent function');
  33694. ttContext.hintsValid = false;
  33695. return;
  33696. }
  33697. data = pc.data;
  33698. i = pc.i;
  33699. }
  33700. }
  33701. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33702. if (inFDEF || inELSE) {
  33703. warn('TT: nested FDEFs not allowed');
  33704. tooComplexToFollowFunctions = true;
  33705. }
  33706. inFDEF = true;
  33707. // collecting inforamtion about which functions are defined
  33708. lastDeff = i;
  33709. funcId = stack.pop();
  33710. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33711. } else if (op === 0x2D) { // ENDF - end of function
  33712. if (inFDEF) {
  33713. inFDEF = false;
  33714. lastEndf = i;
  33715. } else {
  33716. pc = callstack.pop();
  33717. if (!pc) {
  33718. warn('TT: ENDF bad stack');
  33719. ttContext.hintsValid = false;
  33720. return;
  33721. }
  33722. funcId = functionsCalled.pop();
  33723. data = pc.data;
  33724. i = pc.i;
  33725. ttContext.functionsStackDeltas[funcId] =
  33726. stack.length - pc.stackTop;
  33727. }
  33728. } else if (op === 0x89) { // IDEF - instruction definition
  33729. if (inFDEF || inELSE) {
  33730. warn('TT: nested IDEFs not allowed');
  33731. tooComplexToFollowFunctions = true;
  33732. }
  33733. inFDEF = true;
  33734. // recording it as a function to track ENDF
  33735. lastDeff = i;
  33736. } else if (op === 0x58) { // IF
  33737. ++ifLevel;
  33738. } else if (op === 0x1B) { // ELSE
  33739. inELSE = ifLevel;
  33740. } else if (op === 0x59) { // EIF
  33741. if (inELSE === ifLevel) {
  33742. inELSE = 0;
  33743. }
  33744. --ifLevel;
  33745. } else if (op === 0x1C) { // JMPR
  33746. if (!inFDEF && !inELSE) {
  33747. var offset = stack[stack.length - 1];
  33748. // only jumping forward to prevent infinite loop
  33749. if (offset > 0) {
  33750. i += offset - 1;
  33751. }
  33752. }
  33753. }
  33754. // Adjusting stack not extactly, but just enough to get function id
  33755. if (!inFDEF && !inELSE) {
  33756. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33757. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33758. if (op >= 0x71 && op <= 0x75) {
  33759. n = stack.pop();
  33760. if (n === n) {
  33761. stackDelta = -n * 2;
  33762. }
  33763. }
  33764. while (stackDelta < 0 && stack.length > 0) {
  33765. stack.pop();
  33766. stackDelta++;
  33767. }
  33768. while (stackDelta > 0) {
  33769. stack.push(NaN); // pushing any number into stack
  33770. stackDelta--;
  33771. }
  33772. }
  33773. }
  33774. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33775. var content = [data];
  33776. if (i > data.length) {
  33777. content.push(new Uint8Array(i - data.length));
  33778. }
  33779. if (lastDeff > lastEndf) {
  33780. warn('TT: complementing a missing function tail');
  33781. // new function definition started, but not finished
  33782. // complete function by [CLEAR, ENDF]
  33783. content.push(new Uint8Array([0x22, 0x2D]));
  33784. }
  33785. foldTTTable(table, content);
  33786. }
  33787. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33788. if (ttContext.tooComplexToFollowFunctions) {
  33789. return;
  33790. }
  33791. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33792. warn('TT: more functions defined than expected');
  33793. ttContext.hintsValid = false;
  33794. return;
  33795. }
  33796. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33797. if (j > maxFunctionDefs) {
  33798. warn('TT: invalid function id: ' + j);
  33799. ttContext.hintsValid = false;
  33800. return;
  33801. }
  33802. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33803. warn('TT: undefined function: ' + j);
  33804. ttContext.hintsValid = false;
  33805. return;
  33806. }
  33807. }
  33808. }
  33809. function foldTTTable(table, content) {
  33810. if (content.length > 1) {
  33811. // concatenating the content items
  33812. var newLength = 0;
  33813. var j, jj;
  33814. for (j = 0, jj = content.length; j < jj; j++) {
  33815. newLength += content[j].length;
  33816. }
  33817. newLength = (newLength + 3) & ~3;
  33818. var result = new Uint8Array(newLength);
  33819. var pos = 0;
  33820. for (j = 0, jj = content.length; j < jj; j++) {
  33821. result.set(content[j], pos);
  33822. pos += content[j].length;
  33823. }
  33824. table.data = result;
  33825. table.length = newLength;
  33826. }
  33827. }
  33828. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33829. var ttContext = {
  33830. functionsDefined: [],
  33831. functionsUsed: [],
  33832. functionsStackDeltas: [],
  33833. tooComplexToFollowFunctions: false,
  33834. hintsValid: true
  33835. };
  33836. if (fpgm) {
  33837. sanitizeTTProgram(fpgm, ttContext);
  33838. }
  33839. if (prep) {
  33840. sanitizeTTProgram(prep, ttContext);
  33841. }
  33842. if (fpgm) {
  33843. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33844. }
  33845. if (cvt && (cvt.length & 1)) {
  33846. var cvtData = new Uint8Array(cvt.length + 1);
  33847. cvtData.set(cvt.data);
  33848. cvt.data = cvtData;
  33849. }
  33850. return ttContext.hintsValid;
  33851. }
  33852. // The following steps modify the original font data, making copy
  33853. font = new Stream(new Uint8Array(font.getBytes()));
  33854. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33855. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33856. var header = readOpenTypeHeader(font);
  33857. var numTables = header.numTables;
  33858. var cff, cffFile;
  33859. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  33860. hmtx: null, maxp: null, name: null, post: null };
  33861. var table;
  33862. for (var i = 0; i < numTables; i++) {
  33863. table = readTableEntry(font);
  33864. if (VALID_TABLES.indexOf(table.tag) < 0) {
  33865. continue; // skipping table if it's not a required or optional table
  33866. }
  33867. if (table.length === 0) {
  33868. continue; // skipping empty tables
  33869. }
  33870. tables[table.tag] = table;
  33871. }
  33872. var isTrueType = !tables['CFF '];
  33873. if (!isTrueType) {
  33874. // OpenType font
  33875. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  33876. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  33877. // no major tables: throwing everything at CFFFont
  33878. cffFile = new Stream(tables['CFF '].data);
  33879. cff = new CFFFont(cffFile, properties);
  33880. adjustWidths(properties);
  33881. return this.convert(name, cff, properties);
  33882. }
  33883. delete tables.glyf;
  33884. delete tables.loca;
  33885. delete tables.fpgm;
  33886. delete tables.prep;
  33887. delete tables['cvt '];
  33888. this.isOpenType = true;
  33889. } else {
  33890. if (!tables.glyf || !tables.loca) {
  33891. error('Required "glyf" or "loca" tables are not found');
  33892. }
  33893. this.isOpenType = false;
  33894. }
  33895. if (!tables.maxp) {
  33896. error('Required "maxp" table is not found');
  33897. }
  33898. font.pos = (font.start || 0) + tables.maxp.offset;
  33899. var version = font.getInt32();
  33900. var numGlyphs = font.getUint16();
  33901. var maxFunctionDefs = 0;
  33902. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  33903. // maxZones can be invalid
  33904. font.pos += 8;
  33905. var maxZones = font.getUint16();
  33906. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  33907. tables.maxp.data[14] = 0;
  33908. tables.maxp.data[15] = 2;
  33909. }
  33910. font.pos += 4;
  33911. maxFunctionDefs = font.getUint16();
  33912. }
  33913. var dupFirstEntry = false;
  33914. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  33915. properties.toUnicode.get(0) > '\u0000') {
  33916. // oracle's defect (see 3427), duplicating first entry
  33917. dupFirstEntry = true;
  33918. numGlyphs++;
  33919. tables.maxp.data[4] = numGlyphs >> 8;
  33920. tables.maxp.data[5] = numGlyphs & 255;
  33921. }
  33922. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  33923. tables['cvt '], maxFunctionDefs);
  33924. if (!hintsValid) {
  33925. delete tables.fpgm;
  33926. delete tables.prep;
  33927. delete tables['cvt '];
  33928. }
  33929. // Ensure the hmtx table contains the advance width and
  33930. // sidebearings information for numGlyphs in the maxp table
  33931. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  33932. if (!tables.head) {
  33933. error('Required "head" table is not found');
  33934. }
  33935. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  33936. var missingGlyphs = {};
  33937. if (isTrueType) {
  33938. var isGlyphLocationsLong = int16(tables.head.data[50],
  33939. tables.head.data[51]);
  33940. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  33941. numGlyphs, isGlyphLocationsLong,
  33942. hintsValid, dupFirstEntry);
  33943. }
  33944. if (!tables.hhea) {
  33945. error('Required "hhea" table is not found');
  33946. }
  33947. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  33948. // Sometimes it's 0. That needs to be fixed
  33949. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  33950. tables.hhea.data[10] = 0xFF;
  33951. tables.hhea.data[11] = 0xFF;
  33952. }
  33953. // Extract some more font properties from the OpenType head and
  33954. // hhea tables; yMin and descent value are always negative.
  33955. var metricsOverride = {
  33956. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  33957. yMax: int16(tables.head.data[42], tables.head.data[43]),
  33958. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  33959. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  33960. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  33961. };
  33962. // PDF FontDescriptor metrics lie -- using data from actual font.
  33963. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  33964. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  33965. // The 'post' table has glyphs names.
  33966. if (tables.post) {
  33967. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  33968. if (!valid) {
  33969. tables.post = null;
  33970. }
  33971. }
  33972. var charCodeToGlyphId = [], charCode;
  33973. var toUnicode = properties.toUnicode, widths = properties.widths;
  33974. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  33975. toUnicode.length === 0x10000);
  33976. // Helper function to try to skip mapping of empty glyphs.
  33977. // Note: In some cases, just relying on the glyph data doesn't work,
  33978. // hence we also use a few heuristics to fix various PDF files.
  33979. function hasGlyph(glyphId, charCode, widthCode) {
  33980. if (!missingGlyphs[glyphId]) {
  33981. return true;
  33982. }
  33983. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  33984. return true;
  33985. }
  33986. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  33987. return true;
  33988. }
  33989. return false;
  33990. }
  33991. if (properties.type === 'CIDFontType2') {
  33992. var cidToGidMap = properties.cidToGidMap || [];
  33993. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  33994. properties.cMap.forEach(function(charCode, cid) {
  33995. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  33996. var glyphId = -1;
  33997. if (isCidToGidMapEmpty) {
  33998. glyphId = charCode;
  33999. } else if (cidToGidMap[cid] !== undefined) {
  34000. glyphId = cidToGidMap[cid];
  34001. }
  34002. if (glyphId >= 0 && glyphId < numGlyphs &&
  34003. hasGlyph(glyphId, charCode, cid)) {
  34004. charCodeToGlyphId[charCode] = glyphId;
  34005. }
  34006. });
  34007. if (dupFirstEntry) {
  34008. charCodeToGlyphId[0] = numGlyphs - 1;
  34009. }
  34010. } else {
  34011. // Most of the following logic in this code branch is based on the
  34012. // 9.6.6.4 of the PDF spec.
  34013. var hasEncoding =
  34014. properties.differences.length > 0 || !!properties.baseEncodingName;
  34015. var cmapTable =
  34016. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  34017. var cmapPlatformId = cmapTable.platformId;
  34018. var cmapEncodingId = cmapTable.encodingId;
  34019. var cmapMappings = cmapTable.mappings;
  34020. var cmapMappingsLength = cmapMappings.length;
  34021. // The spec seems to imply that if the font is symbolic the encoding
  34022. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  34023. // where the the font is symbolic and it has an encoding.
  34024. if (hasEncoding &&
  34025. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  34026. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  34027. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  34028. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  34029. // When no preferred cmap table was found and |baseEncodingName| is
  34030. // one of the predefined encodings, we seem to obtain a better
  34031. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  34032. // TODO: Note that this is a hack which should be removed as soon as
  34033. // we have proper support for more exotic cmap tables.
  34034. var baseEncoding = [];
  34035. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  34036. properties.baseEncodingName === 'WinAnsiEncoding') {
  34037. baseEncoding = Encodings[properties.baseEncodingName];
  34038. }
  34039. for (charCode = 0; charCode < 256; charCode++) {
  34040. var glyphName;
  34041. if (this.differences && charCode in this.differences) {
  34042. glyphName = this.differences[charCode];
  34043. } else if (charCode in baseEncoding &&
  34044. baseEncoding[charCode] !== '') {
  34045. glyphName = baseEncoding[charCode];
  34046. } else {
  34047. glyphName = Encodings.StandardEncoding[charCode];
  34048. }
  34049. if (!glyphName) {
  34050. continue;
  34051. }
  34052. var unicodeOrCharCode, isUnicode = false;
  34053. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  34054. unicodeOrCharCode = GlyphsUnicode[glyphName];
  34055. isUnicode = true;
  34056. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  34057. // TODO: the encoding needs to be updated with mac os table.
  34058. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  34059. }
  34060. var found = false;
  34061. for (i = 0; i < cmapMappingsLength; ++i) {
  34062. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  34063. continue;
  34064. }
  34065. var code = isUnicode ? charCode : unicodeOrCharCode;
  34066. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  34067. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34068. found = true;
  34069. break;
  34070. }
  34071. }
  34072. if (!found && properties.glyphNames) {
  34073. // Try to map using the post table.
  34074. var glyphId = properties.glyphNames.indexOf(glyphName);
  34075. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  34076. charCodeToGlyphId[charCode] = glyphId;
  34077. } else {
  34078. charCodeToGlyphId[charCode] = 0; // notdef
  34079. }
  34080. }
  34081. }
  34082. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  34083. // Default Unicode semantics, use the charcodes as is.
  34084. for (i = 0; i < cmapMappingsLength; ++i) {
  34085. charCodeToGlyphId[cmapMappings[i].charCode] =
  34086. cmapMappings[i].glyphId;
  34087. }
  34088. } else {
  34089. // For (3, 0) cmap tables:
  34090. // The charcode key being stored in charCodeToGlyphId is the lower
  34091. // byte of the two-byte charcodes of the cmap table since according to
  34092. // the spec: 'each byte from the string shall be prepended with the
  34093. // high byte of the range [of charcodes in the cmap table], to form
  34094. // a two-byte character, which shall be used to select the
  34095. // associated glyph description from the subtable'.
  34096. //
  34097. // For (1, 0) cmap tables:
  34098. // 'single bytes from the string shall be used to look up the
  34099. // associated glyph descriptions from the subtable'. This means
  34100. // charcodes in the cmap will be single bytes, so no-op since
  34101. // glyph.charCode & 0xFF === glyph.charCode
  34102. for (i = 0; i < cmapMappingsLength; ++i) {
  34103. charCode = cmapMappings[i].charCode & 0xFF;
  34104. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34105. }
  34106. }
  34107. }
  34108. if (charCodeToGlyphId.length === 0) {
  34109. // defines at least one glyph
  34110. charCodeToGlyphId[0] = 0;
  34111. }
  34112. // Converting glyphs and ids into font's cmap table
  34113. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  34114. this.toFontChar = newMapping.toFontChar;
  34115. tables.cmap = {
  34116. tag: 'cmap',
  34117. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  34118. };
  34119. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  34120. tables['OS/2'] = {
  34121. tag: 'OS/2',
  34122. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  34123. metricsOverride)
  34124. };
  34125. }
  34126. // Rewrite the 'post' table if needed
  34127. if (!tables.post) {
  34128. tables.post = {
  34129. tag: 'post',
  34130. data: createPostTable(properties)
  34131. };
  34132. }
  34133. if (!isTrueType) {
  34134. try {
  34135. // Trying to repair CFF file
  34136. cffFile = new Stream(tables['CFF '].data);
  34137. var parser = new CFFParser(cffFile, properties);
  34138. cff = parser.parse();
  34139. var compiler = new CFFCompiler(cff);
  34140. tables['CFF '].data = compiler.compile();
  34141. } catch (e) {
  34142. warn('Failed to compile font ' + properties.loadedName);
  34143. }
  34144. }
  34145. // Re-creating 'name' table
  34146. if (!tables.name) {
  34147. tables.name = {
  34148. tag: 'name',
  34149. data: createNameTable(this.name)
  34150. };
  34151. } else {
  34152. // ... using existing 'name' table as prototype
  34153. var namePrototype = readNameTable(tables.name);
  34154. tables.name.data = createNameTable(name, namePrototype);
  34155. }
  34156. var builder = new OpenTypeFileBuilder(header.version);
  34157. for (var tableTag in tables) {
  34158. builder.addTable(tableTag, tables[tableTag].data);
  34159. }
  34160. return builder.toArray();
  34161. },
  34162. convert: function Font_convert(fontName, font, properties) {
  34163. // TODO: Check the charstring widths to determine this.
  34164. properties.fixedPitch = false;
  34165. var mapping = font.getGlyphMapping(properties);
  34166. var newMapping = adjustMapping(mapping, properties);
  34167. this.toFontChar = newMapping.toFontChar;
  34168. var numGlyphs = font.numGlyphs;
  34169. function getCharCodes(charCodeToGlyphId, glyphId) {
  34170. var charCodes = null;
  34171. for (var charCode in charCodeToGlyphId) {
  34172. if (glyphId === charCodeToGlyphId[charCode]) {
  34173. if (!charCodes) {
  34174. charCodes = [];
  34175. }
  34176. charCodes.push(charCode | 0);
  34177. }
  34178. }
  34179. return charCodes;
  34180. }
  34181. function createCharCode(charCodeToGlyphId, glyphId) {
  34182. for (var charCode in charCodeToGlyphId) {
  34183. if (glyphId === charCodeToGlyphId[charCode]) {
  34184. return charCode | 0;
  34185. }
  34186. }
  34187. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  34188. glyphId;
  34189. return newMapping.nextAvailableFontCharCode++;
  34190. }
  34191. var seacs = font.seacs;
  34192. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  34193. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  34194. var charset = font.getCharset();
  34195. var seacMap = Object.create(null);
  34196. for (var glyphId in seacs) {
  34197. glyphId |= 0;
  34198. var seac = seacs[glyphId];
  34199. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  34200. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  34201. var baseGlyphId = charset.indexOf(baseGlyphName);
  34202. var accentGlyphId = charset.indexOf(accentGlyphName);
  34203. if (baseGlyphId < 0 || accentGlyphId < 0) {
  34204. continue;
  34205. }
  34206. var accentOffset = {
  34207. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  34208. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  34209. };
  34210. var charCodes = getCharCodes(mapping, glyphId);
  34211. if (!charCodes) {
  34212. // There's no point in mapping it if the char code was never mapped
  34213. // to begin with.
  34214. continue;
  34215. }
  34216. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  34217. var charCode = charCodes[i];
  34218. // Find a fontCharCode that maps to the base and accent glyphs.
  34219. // If one doesn't exists, create it.
  34220. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  34221. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  34222. baseGlyphId);
  34223. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  34224. accentGlyphId);
  34225. seacMap[charCode] = {
  34226. baseFontCharCode: baseFontCharCode,
  34227. accentFontCharCode: accentFontCharCode,
  34228. accentOffset: accentOffset
  34229. };
  34230. }
  34231. }
  34232. properties.seacMap = seacMap;
  34233. }
  34234. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  34235. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  34236. // PostScript Font Program
  34237. builder.addTable('CFF ', font.data);
  34238. // OS/2 and Windows Specific metrics
  34239. builder.addTable('OS/2', createOS2Table(properties,
  34240. newMapping.charCodeToGlyphId));
  34241. // Character to glyphs mapping
  34242. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  34243. numGlyphs));
  34244. // Font header
  34245. builder.addTable('head',
  34246. '\x00\x01\x00\x00' + // Version number
  34247. '\x00\x00\x10\x00' + // fontRevision
  34248. '\x00\x00\x00\x00' + // checksumAdjustement
  34249. '\x5F\x0F\x3C\xF5' + // magicNumber
  34250. '\x00\x00' + // Flags
  34251. safeString16(unitsPerEm) + // unitsPerEM
  34252. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  34253. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  34254. '\x00\x00' + // xMin
  34255. safeString16(properties.descent) + // yMin
  34256. '\x0F\xFF' + // xMax
  34257. safeString16(properties.ascent) + // yMax
  34258. string16(properties.italicAngle ? 2 : 0) + // macStyle
  34259. '\x00\x11' + // lowestRecPPEM
  34260. '\x00\x00' + // fontDirectionHint
  34261. '\x00\x00' + // indexToLocFormat
  34262. '\x00\x00'); // glyphDataFormat
  34263. // Horizontal header
  34264. builder.addTable('hhea',
  34265. '\x00\x01\x00\x00' + // Version number
  34266. safeString16(properties.ascent) + // Typographic Ascent
  34267. safeString16(properties.descent) + // Typographic Descent
  34268. '\x00\x00' + // Line Gap
  34269. '\xFF\xFF' + // advanceWidthMax
  34270. '\x00\x00' + // minLeftSidebearing
  34271. '\x00\x00' + // minRightSidebearing
  34272. '\x00\x00' + // xMaxExtent
  34273. safeString16(properties.capHeight) + // caretSlopeRise
  34274. safeString16(Math.tan(properties.italicAngle) *
  34275. properties.xHeight) + // caretSlopeRun
  34276. '\x00\x00' + // caretOffset
  34277. '\x00\x00' + // -reserved-
  34278. '\x00\x00' + // -reserved-
  34279. '\x00\x00' + // -reserved-
  34280. '\x00\x00' + // -reserved-
  34281. '\x00\x00' + // metricDataFormat
  34282. string16(numGlyphs)); // Number of HMetrics
  34283. // Horizontal metrics
  34284. builder.addTable('hmtx', (function fontFieldsHmtx() {
  34285. var charstrings = font.charstrings;
  34286. var cffWidths = font.cff ? font.cff.widths : null;
  34287. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  34288. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  34289. var width = 0;
  34290. if (charstrings) {
  34291. var charstring = charstrings[i - 1];
  34292. width = 'width' in charstring ? charstring.width : 0;
  34293. } else if (cffWidths) {
  34294. width = Math.ceil(cffWidths[i] || 0);
  34295. }
  34296. hmtx += string16(width) + string16(0);
  34297. }
  34298. return hmtx;
  34299. })());
  34300. // Maximum profile
  34301. builder.addTable('maxp',
  34302. '\x00\x00\x50\x00' + // Version number
  34303. string16(numGlyphs)); // Num of glyphs
  34304. // Naming tables
  34305. builder.addTable('name', createNameTable(fontName));
  34306. // PostScript informations
  34307. builder.addTable('post', createPostTable(properties));
  34308. return builder.toArray();
  34309. },
  34310. /**
  34311. * Builds a char code to unicode map based on section 9.10 of the spec.
  34312. * @param {Object} properties Font properties object.
  34313. * @return {Object} A ToUnicodeMap object.
  34314. */
  34315. buildToUnicode: function Font_buildToUnicode(properties) {
  34316. // Section 9.10.2 Mapping Character Codes to Unicode Values
  34317. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  34318. return properties.toUnicode;
  34319. }
  34320. // According to the spec if the font is a simple font we should only map
  34321. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  34322. // the differences array only contains adobe standard or symbol set names,
  34323. // in pratice it seems better to always try to create a toUnicode
  34324. // map based of the default encoding.
  34325. var toUnicode, charcode;
  34326. if (!properties.composite /* is simple font */) {
  34327. toUnicode = [];
  34328. var encoding = properties.defaultEncoding.slice();
  34329. var baseEncodingName = properties.baseEncodingName;
  34330. // Merge in the differences array.
  34331. var differences = properties.differences;
  34332. for (charcode in differences) {
  34333. encoding[charcode] = differences[charcode];
  34334. }
  34335. for (charcode in encoding) {
  34336. // a) Map the character code to a character name.
  34337. var glyphName = encoding[charcode];
  34338. // b) Look up the character name in the Adobe Glyph List (see the
  34339. // Bibliography) to obtain the corresponding Unicode value.
  34340. if (glyphName === '') {
  34341. continue;
  34342. } else if (GlyphsUnicode[glyphName] === undefined) {
  34343. // (undocumented) c) Few heuristics to recognize unknown glyphs
  34344. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  34345. var code = 0;
  34346. switch (glyphName[0]) {
  34347. case 'G': // Gxx glyph
  34348. if (glyphName.length === 3) {
  34349. code = parseInt(glyphName.substr(1), 16);
  34350. }
  34351. break;
  34352. case 'g': // g00xx glyph
  34353. if (glyphName.length === 5) {
  34354. code = parseInt(glyphName.substr(1), 16);
  34355. }
  34356. break;
  34357. case 'C': // Cddd glyph
  34358. case 'c': // cddd glyph
  34359. if (glyphName.length >= 3) {
  34360. code = +glyphName.substr(1);
  34361. }
  34362. break;
  34363. }
  34364. if (code) {
  34365. // If |baseEncodingName| is one the predefined encodings,
  34366. // and |code| equals |charcode|, using the glyph defined in the
  34367. // baseEncoding seems to yield a better |toUnicode| mapping
  34368. // (fixes issue 5070).
  34369. if (baseEncodingName && code === +charcode) {
  34370. var baseEncoding = Encodings[baseEncodingName];
  34371. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  34372. toUnicode[charcode] =
  34373. String.fromCharCode(GlyphsUnicode[glyphName]);
  34374. continue;
  34375. }
  34376. }
  34377. toUnicode[charcode] = String.fromCharCode(code);
  34378. }
  34379. continue;
  34380. }
  34381. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  34382. }
  34383. return new ToUnicodeMap(toUnicode);
  34384. }
  34385. // If the font is a composite font that uses one of the predefined CMaps
  34386. // listed in Table 118 (except Identity–H and Identity–V) or whose
  34387. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  34388. // Adobe-Korea1 character collection:
  34389. if (properties.composite && (
  34390. (properties.cMap.builtInCMap &&
  34391. !(properties.cMap instanceof IdentityCMap)) ||
  34392. (properties.cidSystemInfo.registry === 'Adobe' &&
  34393. (properties.cidSystemInfo.ordering === 'GB1' ||
  34394. properties.cidSystemInfo.ordering === 'CNS1' ||
  34395. properties.cidSystemInfo.ordering === 'Japan1' ||
  34396. properties.cidSystemInfo.ordering === 'Korea1')))) {
  34397. // Then:
  34398. // a) Map the character code to a character identifier (CID) according
  34399. // to the font’s CMap.
  34400. // b) Obtain the registry and ordering of the character collection used
  34401. // by the font’s CMap (for example, Adobe and Japan1) from its
  34402. // CIDSystemInfo dictionary.
  34403. var registry = properties.cidSystemInfo.registry;
  34404. var ordering = properties.cidSystemInfo.ordering;
  34405. // c) Construct a second CMap name by concatenating the registry and
  34406. // ordering obtained in step (b) in the format registry–ordering–UCS2
  34407. // (for example, Adobe–Japan1–UCS2).
  34408. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  34409. // d) Obtain the CMap with the name constructed in step (c) (available
  34410. // from the ASN Web site; see the Bibliography).
  34411. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  34412. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  34413. var cMap = properties.cMap;
  34414. toUnicode = [];
  34415. cMap.forEach(function(charcode, cid) {
  34416. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34417. // e) Map the CID obtained in step (a) according to the CMap obtained
  34418. // in step (d), producing a Unicode value.
  34419. var ucs2 = ucs2CMap.lookup(cid);
  34420. if (ucs2) {
  34421. toUnicode[charcode] =
  34422. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  34423. ucs2.charCodeAt(1));
  34424. }
  34425. });
  34426. return new ToUnicodeMap(toUnicode);
  34427. }
  34428. // The viewer's choice, just use an identity map.
  34429. return new IdentityToUnicodeMap(properties.firstChar,
  34430. properties.lastChar);
  34431. },
  34432. get spaceWidth() {
  34433. if ('_shadowWidth' in this) {
  34434. return this._shadowWidth;
  34435. }
  34436. // trying to estimate space character width
  34437. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34438. var width;
  34439. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34440. var glyphName = possibleSpaceReplacements[i];
  34441. // if possible, getting width by glyph name
  34442. if (glyphName in this.widths) {
  34443. width = this.widths[glyphName];
  34444. break;
  34445. }
  34446. var glyphUnicode = GlyphsUnicode[glyphName];
  34447. // finding the charcode via unicodeToCID map
  34448. var charcode = 0;
  34449. if (this.composite) {
  34450. if (this.cMap.contains(glyphUnicode)) {
  34451. charcode = this.cMap.lookup(glyphUnicode);
  34452. }
  34453. }
  34454. // ... via toUnicode map
  34455. if (!charcode && this.toUnicode) {
  34456. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34457. }
  34458. // setting it to unicode if negative or undefined
  34459. if (charcode <= 0) {
  34460. charcode = glyphUnicode;
  34461. }
  34462. // trying to get width via charcode
  34463. width = this.widths[charcode];
  34464. if (width) {
  34465. break; // the non-zero width found
  34466. }
  34467. }
  34468. width = width || this.defaultWidth;
  34469. // Do not shadow the property here. See discussion:
  34470. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34471. this._shadowWidth = width;
  34472. return width;
  34473. },
  34474. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34475. var fontCharCode, width, operatorListId;
  34476. var widthCode = charcode;
  34477. if (this.cMap && this.cMap.contains(charcode)) {
  34478. widthCode = this.cMap.lookup(charcode);
  34479. }
  34480. width = this.widths[widthCode];
  34481. width = isNum(width) ? width : this.defaultWidth;
  34482. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34483. var unicode = this.toUnicode.get(charcode) || charcode;
  34484. if (typeof unicode === 'number') {
  34485. unicode = String.fromCharCode(unicode);
  34486. }
  34487. // First try the toFontChar map, if it's not there then try falling
  34488. // back to the char code.
  34489. fontCharCode = this.toFontChar[charcode] || charcode;
  34490. if (this.missingFile) {
  34491. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34492. }
  34493. if (this.isType3Font) {
  34494. // Font char code in this case is actually a glyph name.
  34495. operatorListId = fontCharCode;
  34496. }
  34497. var accent = null;
  34498. if (this.seacMap && this.seacMap[charcode]) {
  34499. var seac = this.seacMap[charcode];
  34500. fontCharCode = seac.baseFontCharCode;
  34501. accent = {
  34502. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34503. offset: seac.accentOffset
  34504. };
  34505. }
  34506. var fontChar = String.fromCharCode(fontCharCode);
  34507. var glyph = this.glyphCache[charcode];
  34508. if (!glyph ||
  34509. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34510. operatorListId, isSpace)) {
  34511. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34512. operatorListId, isSpace);
  34513. this.glyphCache[charcode] = glyph;
  34514. }
  34515. return glyph;
  34516. },
  34517. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34518. var charsCache = this.charsCache;
  34519. var glyphs, glyph, charcode;
  34520. // if we translated this string before, just grab it from the cache
  34521. if (charsCache) {
  34522. glyphs = charsCache[chars];
  34523. if (glyphs) {
  34524. return glyphs;
  34525. }
  34526. }
  34527. // lazily create the translation cache
  34528. if (!charsCache) {
  34529. charsCache = this.charsCache = Object.create(null);
  34530. }
  34531. glyphs = [];
  34532. var charsCacheKey = chars;
  34533. var i = 0, ii;
  34534. if (this.cMap) {
  34535. // composite fonts have multi-byte strings convert the string from
  34536. // single-byte to multi-byte
  34537. var c = {};
  34538. while (i < chars.length) {
  34539. this.cMap.readCharCode(chars, i, c);
  34540. charcode = c.charcode;
  34541. var length = c.length;
  34542. i += length;
  34543. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34544. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34545. glyph = this.charToGlyph(charcode, isSpace);
  34546. glyphs.push(glyph);
  34547. }
  34548. } else {
  34549. for (i = 0, ii = chars.length; i < ii; ++i) {
  34550. charcode = chars.charCodeAt(i);
  34551. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34552. glyphs.push(glyph);
  34553. }
  34554. }
  34555. // Enter the translated string into the cache
  34556. return (charsCache[charsCacheKey] = glyphs);
  34557. }
  34558. };
  34559. return Font;
  34560. })();
  34561. var ErrorFont = (function ErrorFontClosure() {
  34562. function ErrorFont(error) {
  34563. this.error = error;
  34564. this.loadedName = 'g_font_error';
  34565. this.loading = false;
  34566. }
  34567. ErrorFont.prototype = {
  34568. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34569. return [];
  34570. },
  34571. exportData: function ErrorFont_exportData() {
  34572. return {error: this.error};
  34573. }
  34574. };
  34575. return ErrorFont;
  34576. })();
  34577. /**
  34578. * Shared logic for building a char code to glyph id mapping for Type1 and
  34579. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34580. * @param {Object} properties Font properties object.
  34581. * @param {Object} builtInEncoding The encoding contained within the actual font
  34582. * data.
  34583. * @param {Array} Array of glyph names where the index is the glyph ID.
  34584. * @returns {Object} A char code to glyph ID map.
  34585. */
  34586. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34587. var charCodeToGlyphId = Object.create(null);
  34588. var glyphId, charCode, baseEncoding;
  34589. if (properties.baseEncodingName) {
  34590. // If a valid base encoding name was used, the mapping is initialized with
  34591. // that.
  34592. baseEncoding = Encodings[properties.baseEncodingName];
  34593. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34594. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34595. if (glyphId >= 0) {
  34596. charCodeToGlyphId[charCode] = glyphId;
  34597. } else {
  34598. charCodeToGlyphId[charCode] = 0; // notdef
  34599. }
  34600. }
  34601. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34602. // For a symbolic font the encoding should be the fonts built-in
  34603. // encoding.
  34604. for (charCode in builtInEncoding) {
  34605. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34606. }
  34607. } else {
  34608. // For non-symbolic fonts that don't have a base encoding the standard
  34609. // encoding should be used.
  34610. baseEncoding = Encodings.StandardEncoding;
  34611. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34612. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34613. if (glyphId >= 0) {
  34614. charCodeToGlyphId[charCode] = glyphId;
  34615. } else {
  34616. charCodeToGlyphId[charCode] = 0; // notdef
  34617. }
  34618. }
  34619. }
  34620. // Lastly, merge in the differences.
  34621. var differences = properties.differences;
  34622. if (differences) {
  34623. for (charCode in differences) {
  34624. var glyphName = differences[charCode];
  34625. glyphId = glyphNames.indexOf(glyphName);
  34626. if (glyphId >= 0) {
  34627. charCodeToGlyphId[charCode] = glyphId;
  34628. } else {
  34629. charCodeToGlyphId[charCode] = 0; // notdef
  34630. }
  34631. }
  34632. }
  34633. return charCodeToGlyphId;
  34634. }
  34635. /*
  34636. * CharStrings are encoded following the the CharString Encoding sequence
  34637. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  34638. * The value in a byte indicates a command, a number, or subsequent bytes
  34639. * that are to be interpreted in a special way.
  34640. *
  34641. * CharString Number Encoding:
  34642. * A CharString byte containing the values from 32 through 255 inclusive
  34643. * indicate an integer. These values are decoded in four ranges.
  34644. *
  34645. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  34646. * indicate the integer v - 139. Thus, the integer values from -107 through
  34647. * 107 inclusive may be encoded in single byte.
  34648. *
  34649. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  34650. * indicates an integer involving the next byte, w, according to the formula:
  34651. * [(v - 247) x 256] + w + 108
  34652. *
  34653. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  34654. * indicates an integer involving the next byte, w, according to the formula:
  34655. * -[(v - 251) * 256] - w - 108
  34656. *
  34657. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  34658. * are a two complement signed integer. The first of these bytes contains the
  34659. * highest order bits, the second byte contains the next higher order bits
  34660. * and the fourth byte contain the lowest order bits.
  34661. *
  34662. *
  34663. * CharString Command Encoding:
  34664. * CharStrings commands are encoded in 1 or 2 bytes.
  34665. *
  34666. * Single byte commands are encoded in 1 byte that contains a value between
  34667. * 0 and 31 inclusive.
  34668. * If a command byte contains the value 12, then the value in the next byte
  34669. * indicates a command. This "escape" mechanism allows many extra commands
  34670. * to be encoded and this encoding technique helps to minimize the length of
  34671. * the charStrings.
  34672. */
  34673. var Type1CharString = (function Type1CharStringClosure() {
  34674. var COMMAND_MAP = {
  34675. 'hstem': [1],
  34676. 'vstem': [3],
  34677. 'vmoveto': [4],
  34678. 'rlineto': [5],
  34679. 'hlineto': [6],
  34680. 'vlineto': [7],
  34681. 'rrcurveto': [8],
  34682. 'callsubr': [10],
  34683. 'flex': [12, 35],
  34684. 'drop' : [12, 18],
  34685. 'endchar': [14],
  34686. 'rmoveto': [21],
  34687. 'hmoveto': [22],
  34688. 'vhcurveto': [30],
  34689. 'hvcurveto': [31]
  34690. };
  34691. function Type1CharString() {
  34692. this.width = 0;
  34693. this.lsb = 0;
  34694. this.flexing = false;
  34695. this.output = [];
  34696. this.stack = [];
  34697. }
  34698. Type1CharString.prototype = {
  34699. convert: function Type1CharString_convert(encoded, subrs) {
  34700. var count = encoded.length;
  34701. var error = false;
  34702. var wx, sbx, subrNumber;
  34703. for (var i = 0; i < count; i++) {
  34704. var value = encoded[i];
  34705. if (value < 32) {
  34706. if (value === 12) {
  34707. value = (value << 8) + encoded[++i];
  34708. }
  34709. switch (value) {
  34710. case 1: // hstem
  34711. if (!HINTING_ENABLED) {
  34712. this.stack = [];
  34713. break;
  34714. }
  34715. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34716. break;
  34717. case 3: // vstem
  34718. if (!HINTING_ENABLED) {
  34719. this.stack = [];
  34720. break;
  34721. }
  34722. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34723. break;
  34724. case 4: // vmoveto
  34725. if (this.flexing) {
  34726. if (this.stack.length < 1) {
  34727. error = true;
  34728. break;
  34729. }
  34730. // Add the dx for flex and but also swap the values so they are
  34731. // the right order.
  34732. var dy = this.stack.pop();
  34733. this.stack.push(0, dy);
  34734. break;
  34735. }
  34736. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  34737. break;
  34738. case 5: // rlineto
  34739. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  34740. break;
  34741. case 6: // hlineto
  34742. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  34743. break;
  34744. case 7: // vlineto
  34745. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  34746. break;
  34747. case 8: // rrcurveto
  34748. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  34749. break;
  34750. case 9: // closepath
  34751. // closepath is a Type1 command that does not take argument and is
  34752. // useless in Type2 and it can simply be ignored.
  34753. this.stack = [];
  34754. break;
  34755. case 10: // callsubr
  34756. if (this.stack.length < 1) {
  34757. error = true;
  34758. break;
  34759. }
  34760. subrNumber = this.stack.pop();
  34761. error = this.convert(subrs[subrNumber], subrs);
  34762. break;
  34763. case 11: // return
  34764. return error;
  34765. case 13: // hsbw
  34766. if (this.stack.length < 2) {
  34767. error = true;
  34768. break;
  34769. }
  34770. // To convert to type2 we have to move the width value to the
  34771. // first part of the charstring and then use hmoveto with lsb.
  34772. wx = this.stack.pop();
  34773. sbx = this.stack.pop();
  34774. this.lsb = sbx;
  34775. this.width = wx;
  34776. this.stack.push(wx, sbx);
  34777. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  34778. break;
  34779. case 14: // endchar
  34780. this.output.push(COMMAND_MAP.endchar[0]);
  34781. break;
  34782. case 21: // rmoveto
  34783. if (this.flexing) {
  34784. break;
  34785. }
  34786. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  34787. break;
  34788. case 22: // hmoveto
  34789. if (this.flexing) {
  34790. // Add the dy for flex.
  34791. this.stack.push(0);
  34792. break;
  34793. }
  34794. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  34795. break;
  34796. case 30: // vhcurveto
  34797. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  34798. break;
  34799. case 31: // hvcurveto
  34800. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  34801. break;
  34802. case (12 << 8) + 0: // dotsection
  34803. // dotsection is a Type1 command to specify some hinting feature
  34804. // for dots that do not take a parameter and it can safely be
  34805. // ignored for Type2.
  34806. this.stack = [];
  34807. break;
  34808. case (12 << 8) + 1: // vstem3
  34809. if (!HINTING_ENABLED) {
  34810. this.stack = [];
  34811. break;
  34812. }
  34813. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  34814. // multiple parameters, so instead of returning [vh]stem3 take a
  34815. // shortcut and return [vhstem] instead.
  34816. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34817. break;
  34818. case (12 << 8) + 2: // hstem3
  34819. if (!HINTING_ENABLED) {
  34820. this.stack = [];
  34821. break;
  34822. }
  34823. // See vstem3.
  34824. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34825. break;
  34826. case (12 << 8) + 6: // seac
  34827. // seac is like type 2's special endchar but it doesn't use the
  34828. // first argument asb, so remove it.
  34829. if (SEAC_ANALYSIS_ENABLED) {
  34830. this.seac = this.stack.splice(-4, 4);
  34831. error = this.executeCommand(0, COMMAND_MAP.endchar);
  34832. } else {
  34833. error = this.executeCommand(4, COMMAND_MAP.endchar);
  34834. }
  34835. break;
  34836. case (12 << 8) + 7: // sbw
  34837. if (this.stack.length < 4) {
  34838. error = true;
  34839. break;
  34840. }
  34841. // To convert to type2 we have to move the width value to the
  34842. // first part of the charstring and then use rmoveto with
  34843. // (dx, dy). The height argument will not be used for vmtx and
  34844. // vhea tables reconstruction -- ignoring it.
  34845. var wy = this.stack.pop();
  34846. wx = this.stack.pop();
  34847. var sby = this.stack.pop();
  34848. sbx = this.stack.pop();
  34849. this.lsb = sbx;
  34850. this.width = wx;
  34851. this.stack.push(wx, sbx, sby);
  34852. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  34853. break;
  34854. case (12 << 8) + 12: // div
  34855. if (this.stack.length < 2) {
  34856. error = true;
  34857. break;
  34858. }
  34859. var num2 = this.stack.pop();
  34860. var num1 = this.stack.pop();
  34861. this.stack.push(num1 / num2);
  34862. break;
  34863. case (12 << 8) + 16: // callothersubr
  34864. if (this.stack.length < 2) {
  34865. error = true;
  34866. break;
  34867. }
  34868. subrNumber = this.stack.pop();
  34869. var numArgs = this.stack.pop();
  34870. if (subrNumber === 0 && numArgs === 3) {
  34871. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  34872. this.stack.push(
  34873. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  34874. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  34875. flexArgs[4], // bcp2x
  34876. flexArgs[5], // bcp2y
  34877. flexArgs[6], // p2x
  34878. flexArgs[7], // p2y
  34879. flexArgs[8], // bcp3x
  34880. flexArgs[9], // bcp3y
  34881. flexArgs[10], // bcp4x
  34882. flexArgs[11], // bcp4y
  34883. flexArgs[12], // p3x
  34884. flexArgs[13], // p3y
  34885. flexArgs[14] // flexDepth
  34886. // 15 = finalx unused by flex
  34887. // 16 = finaly unused by flex
  34888. );
  34889. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  34890. this.flexing = false;
  34891. this.stack.push(flexArgs[15], flexArgs[16]);
  34892. } else if (subrNumber === 1 && numArgs === 0) {
  34893. this.flexing = true;
  34894. }
  34895. break;
  34896. case (12 << 8) + 17: // pop
  34897. // Ignore this since it is only used with othersubr.
  34898. break;
  34899. case (12 << 8) + 33: // setcurrentpoint
  34900. // Ignore for now.
  34901. this.stack = [];
  34902. break;
  34903. default:
  34904. warn('Unknown type 1 charstring command of "' + value + '"');
  34905. break;
  34906. }
  34907. if (error) {
  34908. break;
  34909. }
  34910. continue;
  34911. } else if (value <= 246) {
  34912. value = value - 139;
  34913. } else if (value <= 250) {
  34914. value = ((value - 247) * 256) + encoded[++i] + 108;
  34915. } else if (value <= 254) {
  34916. value = -((value - 251) * 256) - encoded[++i] - 108;
  34917. } else {
  34918. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  34919. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  34920. }
  34921. this.stack.push(value);
  34922. }
  34923. return error;
  34924. },
  34925. executeCommand: function(howManyArgs, command, keepStack) {
  34926. var stackLength = this.stack.length;
  34927. if (howManyArgs > stackLength) {
  34928. return true;
  34929. }
  34930. var start = stackLength - howManyArgs;
  34931. for (var i = start; i < stackLength; i++) {
  34932. var value = this.stack[i];
  34933. if (value === (value | 0)) { // int
  34934. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  34935. } else { // fixed point
  34936. value = (65536 * value) | 0;
  34937. this.output.push(255,
  34938. (value >> 24) & 0xFF,
  34939. (value >> 16) & 0xFF,
  34940. (value >> 8) & 0xFF,
  34941. value & 0xFF);
  34942. }
  34943. }
  34944. this.output.push.apply(this.output, command);
  34945. if (keepStack) {
  34946. this.stack.splice(start, howManyArgs);
  34947. } else {
  34948. this.stack.length = 0;
  34949. }
  34950. return false;
  34951. }
  34952. };
  34953. return Type1CharString;
  34954. })();
  34955. /*
  34956. * Type1Parser encapsulate the needed code for parsing a Type1 font
  34957. * program. Some of its logic depends on the Type2 charstrings
  34958. * structure.
  34959. * Note: this doesn't really parse the font since that would require evaluation
  34960. * of PostScript, but it is possible in most cases to extract what we need
  34961. * without a full parse.
  34962. */
  34963. var Type1Parser = (function Type1ParserClosure() {
  34964. /*
  34965. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  34966. * of Plaintext Bytes. The function took a key as a parameter which can be
  34967. * for decrypting the eexec block of for decoding charStrings.
  34968. */
  34969. var EEXEC_ENCRYPT_KEY = 55665;
  34970. var CHAR_STRS_ENCRYPT_KEY = 4330;
  34971. function isHexDigit(code) {
  34972. return code >= 48 && code <= 57 || // '0'-'9'
  34973. code >= 65 && code <= 70 || // 'A'-'F'
  34974. code >= 97 && code <= 102; // 'a'-'f'
  34975. }
  34976. function decrypt(data, key, discardNumber) {
  34977. var r = key | 0, c1 = 52845, c2 = 22719;
  34978. var count = data.length;
  34979. var decrypted = new Uint8Array(count);
  34980. for (var i = 0; i < count; i++) {
  34981. var value = data[i];
  34982. decrypted[i] = value ^ (r >> 8);
  34983. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34984. }
  34985. return Array.prototype.slice.call(decrypted, discardNumber);
  34986. }
  34987. function decryptAscii(data, key, discardNumber) {
  34988. var r = key | 0, c1 = 52845, c2 = 22719;
  34989. var count = data.length, maybeLength = count >>> 1;
  34990. var decrypted = new Uint8Array(maybeLength);
  34991. var i, j;
  34992. for (i = 0, j = 0; i < count; i++) {
  34993. var digit1 = data[i];
  34994. if (!isHexDigit(digit1)) {
  34995. continue;
  34996. }
  34997. i++;
  34998. var digit2;
  34999. while (i < count && !isHexDigit(digit2 = data[i])) {
  35000. i++;
  35001. }
  35002. if (i < count) {
  35003. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  35004. decrypted[j++] = value ^ (r >> 8);
  35005. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  35006. }
  35007. }
  35008. return Array.prototype.slice.call(decrypted, discardNumber, j);
  35009. }
  35010. function isSpecial(c) {
  35011. return c === 0x2F || // '/'
  35012. c === 0x5B || c === 0x5D || // '[', ']'
  35013. c === 0x7B || c === 0x7D || // '{', '}'
  35014. c === 0x28 || c === 0x29; // '(', ')'
  35015. }
  35016. function Type1Parser(stream, encrypted) {
  35017. if (encrypted) {
  35018. var data = stream.getBytes();
  35019. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  35020. isHexDigit(data[2]) && isHexDigit(data[3]));
  35021. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  35022. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  35023. }
  35024. this.stream = stream;
  35025. this.nextChar();
  35026. }
  35027. Type1Parser.prototype = {
  35028. readNumberArray: function Type1Parser_readNumberArray() {
  35029. this.getToken(); // read '[' or '{' (arrays can start with either)
  35030. var array = [];
  35031. while (true) {
  35032. var token = this.getToken();
  35033. if (token === null || token === ']' || token === '}') {
  35034. break;
  35035. }
  35036. array.push(parseFloat(token || 0));
  35037. }
  35038. return array;
  35039. },
  35040. readNumber: function Type1Parser_readNumber() {
  35041. var token = this.getToken();
  35042. return parseFloat(token || 0);
  35043. },
  35044. readInt: function Type1Parser_readInt() {
  35045. // Use '| 0' to prevent setting a double into length such as the double
  35046. // does not flow into the loop variable.
  35047. var token = this.getToken();
  35048. return parseInt(token || 0, 10) | 0;
  35049. },
  35050. readBoolean: function Type1Parser_readBoolean() {
  35051. var token = this.getToken();
  35052. // Use 1 and 0 since that's what type2 charstrings use.
  35053. return token === 'true' ? 1 : 0;
  35054. },
  35055. nextChar : function Type1_nextChar() {
  35056. return (this.currentChar = this.stream.getByte());
  35057. },
  35058. getToken: function Type1Parser_getToken() {
  35059. // Eat whitespace and comments.
  35060. var comment = false;
  35061. var ch = this.currentChar;
  35062. while (true) {
  35063. if (ch === -1) {
  35064. return null;
  35065. }
  35066. if (comment) {
  35067. if (ch === 0x0A || ch === 0x0D) {
  35068. comment = false;
  35069. }
  35070. } else if (ch === 0x25) { // '%'
  35071. comment = true;
  35072. } else if (!Lexer.isSpace(ch)) {
  35073. break;
  35074. }
  35075. ch = this.nextChar();
  35076. }
  35077. if (isSpecial(ch)) {
  35078. this.nextChar();
  35079. return String.fromCharCode(ch);
  35080. }
  35081. var token = '';
  35082. do {
  35083. token += String.fromCharCode(ch);
  35084. ch = this.nextChar();
  35085. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  35086. return token;
  35087. },
  35088. /*
  35089. * Returns an object containing a Subrs array and a CharStrings
  35090. * array extracted from and eexec encrypted block of data
  35091. */
  35092. extractFontProgram: function Type1Parser_extractFontProgram() {
  35093. var stream = this.stream;
  35094. var subrs = [], charstrings = [];
  35095. var program = {
  35096. subrs: [],
  35097. charstrings: [],
  35098. properties: {
  35099. 'privateData': {
  35100. 'lenIV': 4
  35101. }
  35102. }
  35103. };
  35104. var token, length, data, lenIV, encoded;
  35105. while ((token = this.getToken()) !== null) {
  35106. if (token !== '/') {
  35107. continue;
  35108. }
  35109. token = this.getToken();
  35110. switch (token) {
  35111. case 'CharStrings':
  35112. // The number immediately following CharStrings must be greater or
  35113. // equal to the number of CharStrings.
  35114. this.getToken();
  35115. this.getToken(); // read in 'dict'
  35116. this.getToken(); // read in 'dup'
  35117. this.getToken(); // read in 'begin'
  35118. while(true) {
  35119. token = this.getToken();
  35120. if (token === null || token === 'end') {
  35121. break;
  35122. }
  35123. if (token !== '/') {
  35124. continue;
  35125. }
  35126. var glyph = this.getToken();
  35127. length = this.readInt();
  35128. this.getToken(); // read in 'RD' or '-|'
  35129. data = stream.makeSubStream(stream.pos, length);
  35130. lenIV = program.properties.privateData['lenIV'];
  35131. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35132. // Skip past the required space and binary data.
  35133. stream.skip(length);
  35134. this.nextChar();
  35135. token = this.getToken(); // read in 'ND' or '|-'
  35136. if (token === 'noaccess') {
  35137. this.getToken(); // read in 'def'
  35138. }
  35139. charstrings.push({
  35140. glyph: glyph,
  35141. encoded: encoded
  35142. });
  35143. }
  35144. break;
  35145. case 'Subrs':
  35146. var num = this.readInt();
  35147. this.getToken(); // read in 'array'
  35148. while ((token = this.getToken()) === 'dup') {
  35149. var index = this.readInt();
  35150. length = this.readInt();
  35151. this.getToken(); // read in 'RD' or '-|'
  35152. data = stream.makeSubStream(stream.pos, length);
  35153. lenIV = program.properties.privateData['lenIV'];
  35154. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35155. // Skip past the required space and binary data.
  35156. stream.skip(length);
  35157. this.nextChar();
  35158. token = this.getToken(); // read in 'NP' or '|'
  35159. if (token === 'noaccess') {
  35160. this.getToken(); // read in 'put'
  35161. }
  35162. subrs[index] = encoded;
  35163. }
  35164. break;
  35165. case 'BlueValues':
  35166. case 'OtherBlues':
  35167. case 'FamilyBlues':
  35168. case 'FamilyOtherBlues':
  35169. var blueArray = this.readNumberArray();
  35170. // *Blue* values may contain invalid data: disables reading of
  35171. // those values when hinting is disabled.
  35172. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  35173. HINTING_ENABLED) {
  35174. program.properties.privateData[token] = blueArray;
  35175. }
  35176. break;
  35177. case 'StemSnapH':
  35178. case 'StemSnapV':
  35179. program.properties.privateData[token] = this.readNumberArray();
  35180. break;
  35181. case 'StdHW':
  35182. case 'StdVW':
  35183. program.properties.privateData[token] =
  35184. this.readNumberArray()[0];
  35185. break;
  35186. case 'BlueShift':
  35187. case 'lenIV':
  35188. case 'BlueFuzz':
  35189. case 'BlueScale':
  35190. case 'LanguageGroup':
  35191. case 'ExpansionFactor':
  35192. program.properties.privateData[token] = this.readNumber();
  35193. break;
  35194. case 'ForceBold':
  35195. program.properties.privateData[token] = this.readBoolean();
  35196. break;
  35197. }
  35198. }
  35199. for (var i = 0; i < charstrings.length; i++) {
  35200. glyph = charstrings[i].glyph;
  35201. encoded = charstrings[i].encoded;
  35202. var charString = new Type1CharString();
  35203. var error = charString.convert(encoded, subrs);
  35204. var output = charString.output;
  35205. if (error) {
  35206. // It seems when FreeType encounters an error while evaluating a glyph
  35207. // that it completely ignores the glyph so we'll mimic that behaviour
  35208. // here and put an endchar to make the validator happy.
  35209. output = [14];
  35210. }
  35211. program.charstrings.push({
  35212. glyphName: glyph,
  35213. charstring: output,
  35214. width: charString.width,
  35215. lsb: charString.lsb,
  35216. seac: charString.seac
  35217. });
  35218. }
  35219. return program;
  35220. },
  35221. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  35222. var token;
  35223. while ((token = this.getToken()) !== null) {
  35224. if (token !== '/') {
  35225. continue;
  35226. }
  35227. token = this.getToken();
  35228. switch (token) {
  35229. case 'FontMatrix':
  35230. var matrix = this.readNumberArray();
  35231. properties.fontMatrix = matrix;
  35232. break;
  35233. case 'Encoding':
  35234. var encodingArg = this.getToken();
  35235. var encoding;
  35236. if (!/^\d+$/.test(encodingArg)) {
  35237. // encoding name is specified
  35238. encoding = Encodings[encodingArg];
  35239. } else {
  35240. encoding = [];
  35241. var size = parseInt(encodingArg, 10) | 0;
  35242. this.getToken(); // read in 'array'
  35243. for (var j = 0; j < size; j++) {
  35244. token = this.getToken();
  35245. // skipping till first dup or def (e.g. ignoring for statement)
  35246. while (token !== 'dup' && token !== 'def') {
  35247. token = this.getToken();
  35248. if (token === null) {
  35249. return; // invalid header
  35250. }
  35251. }
  35252. if (token === 'def') {
  35253. break; // read all array data
  35254. }
  35255. var index = this.readInt();
  35256. this.getToken(); // read in '/'
  35257. var glyph = this.getToken();
  35258. encoding[index] = glyph;
  35259. this.getToken(); // read the in 'put'
  35260. }
  35261. }
  35262. properties.builtInEncoding = encoding;
  35263. break;
  35264. case 'FontBBox':
  35265. var fontBBox = this.readNumberArray();
  35266. // adjusting ascent/descent
  35267. properties.ascent = fontBBox[3];
  35268. properties.descent = fontBBox[1];
  35269. properties.ascentScaled = true;
  35270. break;
  35271. }
  35272. }
  35273. }
  35274. };
  35275. return Type1Parser;
  35276. })();
  35277. /**
  35278. * The CFF class takes a Type1 file and wrap it into a
  35279. * 'Compact Font Format' which itself embed Type2 charstrings.
  35280. */
  35281. var CFFStandardStrings = [
  35282. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  35283. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  35284. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  35285. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  35286. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  35287. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  35288. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  35289. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  35290. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  35291. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  35292. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  35293. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  35294. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  35295. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  35296. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  35297. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  35298. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  35299. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  35300. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  35301. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  35302. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  35303. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  35304. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  35305. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  35306. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  35307. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  35308. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  35309. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  35310. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  35311. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  35312. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  35313. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  35314. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  35315. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  35316. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  35317. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  35318. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  35319. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  35320. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  35321. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  35322. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  35323. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  35324. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  35325. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  35326. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  35327. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  35328. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  35329. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  35330. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  35331. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  35332. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  35333. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  35334. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  35335. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  35336. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  35337. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  35338. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  35339. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  35340. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  35341. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  35342. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  35343. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  35344. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  35345. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  35346. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  35347. ];
  35348. // Type1Font is also a CIDFontType0.
  35349. var Type1Font = function Type1Font(name, file, properties) {
  35350. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  35351. // Also, length1 and length2 might be off by 6 bytes as well.
  35352. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  35353. var PFB_HEADER_SIZE = 6;
  35354. var headerBlockLength = properties.length1;
  35355. var eexecBlockLength = properties.length2;
  35356. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  35357. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  35358. if (pfbHeaderPresent) {
  35359. file.skip(PFB_HEADER_SIZE);
  35360. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35361. (pfbHeader[3] << 8) | pfbHeader[2];
  35362. }
  35363. // Get the data block containing glyphs and subrs informations
  35364. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  35365. var headerBlockParser = new Type1Parser(headerBlock);
  35366. headerBlockParser.extractFontHeader(properties);
  35367. if (pfbHeaderPresent) {
  35368. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  35369. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35370. (pfbHeader[3] << 8) | pfbHeader[2];
  35371. }
  35372. // Decrypt the data blocks and retrieve it's content
  35373. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  35374. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  35375. var data = eexecBlockParser.extractFontProgram();
  35376. for (var info in data.properties) {
  35377. properties[info] = data.properties[info];
  35378. }
  35379. var charstrings = data.charstrings;
  35380. var type2Charstrings = this.getType2Charstrings(charstrings);
  35381. var subrs = this.getType2Subrs(data.subrs);
  35382. this.charstrings = charstrings;
  35383. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  35384. subrs, properties);
  35385. this.seacs = this.getSeacs(data.charstrings);
  35386. };
  35387. Type1Font.prototype = {
  35388. get numGlyphs() {
  35389. return this.charstrings.length + 1;
  35390. },
  35391. getCharset: function Type1Font_getCharset() {
  35392. var charset = ['.notdef'];
  35393. var charstrings = this.charstrings;
  35394. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35395. charset.push(charstrings[glyphId].glyphName);
  35396. }
  35397. return charset;
  35398. },
  35399. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  35400. var charstrings = this.charstrings;
  35401. var glyphNames = ['.notdef'], glyphId;
  35402. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35403. glyphNames.push(charstrings[glyphId].glyphName);
  35404. }
  35405. var encoding = properties.builtInEncoding;
  35406. if (encoding) {
  35407. var builtInEncoding = {};
  35408. for (var charCode in encoding) {
  35409. glyphId = glyphNames.indexOf(encoding[charCode]);
  35410. if (glyphId >= 0) {
  35411. builtInEncoding[charCode] = glyphId;
  35412. }
  35413. }
  35414. }
  35415. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  35416. },
  35417. getSeacs: function Type1Font_getSeacs(charstrings) {
  35418. var i, ii;
  35419. var seacMap = [];
  35420. for (i = 0, ii = charstrings.length; i < ii; i++) {
  35421. var charstring = charstrings[i];
  35422. if (charstring.seac) {
  35423. // Offset by 1 for .notdef
  35424. seacMap[i + 1] = charstring.seac;
  35425. }
  35426. }
  35427. return seacMap;
  35428. },
  35429. getType2Charstrings: function Type1Font_getType2Charstrings(
  35430. type1Charstrings) {
  35431. var type2Charstrings = [];
  35432. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  35433. type2Charstrings.push(type1Charstrings[i].charstring);
  35434. }
  35435. return type2Charstrings;
  35436. },
  35437. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  35438. var bias = 0;
  35439. var count = type1Subrs.length;
  35440. if (count < 1133) {
  35441. bias = 107;
  35442. } else if (count < 33769) {
  35443. bias = 1131;
  35444. } else {
  35445. bias = 32768;
  35446. }
  35447. // Add a bunch of empty subrs to deal with the Type2 bias
  35448. var type2Subrs = [];
  35449. var i;
  35450. for (i = 0; i < bias; i++) {
  35451. type2Subrs.push([0x0B]);
  35452. }
  35453. for (i = 0; i < count; i++) {
  35454. type2Subrs.push(type1Subrs[i]);
  35455. }
  35456. return type2Subrs;
  35457. },
  35458. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  35459. var cff = new CFF();
  35460. cff.header = new CFFHeader(1, 0, 4, 4);
  35461. cff.names = [name];
  35462. var topDict = new CFFTopDict();
  35463. // CFF strings IDs 0...390 are predefined names, so refering
  35464. // to entries in our own String INDEX starts at SID 391.
  35465. topDict.setByName('version', 391);
  35466. topDict.setByName('Notice', 392);
  35467. topDict.setByName('FullName', 393);
  35468. topDict.setByName('FamilyName', 394);
  35469. topDict.setByName('Weight', 395);
  35470. topDict.setByName('Encoding', null); // placeholder
  35471. topDict.setByName('FontMatrix', properties.fontMatrix);
  35472. topDict.setByName('FontBBox', properties.bbox);
  35473. topDict.setByName('charset', null); // placeholder
  35474. topDict.setByName('CharStrings', null); // placeholder
  35475. topDict.setByName('Private', null); // placeholder
  35476. cff.topDict = topDict;
  35477. var strings = new CFFStrings();
  35478. strings.add('Version 0.11'); // Version
  35479. strings.add('See original notice'); // Notice
  35480. strings.add(name); // FullName
  35481. strings.add(name); // FamilyName
  35482. strings.add('Medium'); // Weight
  35483. cff.strings = strings;
  35484. cff.globalSubrIndex = new CFFIndex();
  35485. var count = glyphs.length;
  35486. var charsetArray = [0];
  35487. var i, ii;
  35488. for (i = 0; i < count; i++) {
  35489. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  35490. // TODO: Insert the string and correctly map it. Previously it was
  35491. // thought mapping names that aren't in the standard strings to .notdef
  35492. // was fine, however in issue818 when mapping them all to .notdef the
  35493. // adieresis glyph no longer worked.
  35494. if (index === -1) {
  35495. index = 0;
  35496. }
  35497. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  35498. }
  35499. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  35500. var charStringsIndex = new CFFIndex();
  35501. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  35502. for (i = 0; i < count; i++) {
  35503. charStringsIndex.add(glyphs[i]);
  35504. }
  35505. cff.charStrings = charStringsIndex;
  35506. var privateDict = new CFFPrivateDict();
  35507. privateDict.setByName('Subrs', null); // placeholder
  35508. var fields = [
  35509. 'BlueValues',
  35510. 'OtherBlues',
  35511. 'FamilyBlues',
  35512. 'FamilyOtherBlues',
  35513. 'StemSnapH',
  35514. 'StemSnapV',
  35515. 'BlueShift',
  35516. 'BlueFuzz',
  35517. 'BlueScale',
  35518. 'LanguageGroup',
  35519. 'ExpansionFactor',
  35520. 'ForceBold',
  35521. 'StdHW',
  35522. 'StdVW'
  35523. ];
  35524. for (i = 0, ii = fields.length; i < ii; i++) {
  35525. var field = fields[i];
  35526. if (!properties.privateData.hasOwnProperty(field)) {
  35527. continue;
  35528. }
  35529. var value = properties.privateData[field];
  35530. if (isArray(value)) {
  35531. // All of the private dictionary array data in CFF must be stored as
  35532. // "delta-encoded" numbers.
  35533. for (var j = value.length - 1; j > 0; j--) {
  35534. value[j] -= value[j - 1]; // ... difference from previous value
  35535. }
  35536. }
  35537. privateDict.setByName(field, value);
  35538. }
  35539. cff.topDict.privateDict = privateDict;
  35540. var subrIndex = new CFFIndex();
  35541. for (i = 0, ii = subrs.length; i < ii; i++) {
  35542. subrIndex.add(subrs[i]);
  35543. }
  35544. privateDict.subrsIndex = subrIndex;
  35545. var compiler = new CFFCompiler(cff);
  35546. return compiler.compile();
  35547. }
  35548. };
  35549. var CFFFont = (function CFFFontClosure() {
  35550. function CFFFont(file, properties) {
  35551. this.properties = properties;
  35552. var parser = new CFFParser(file, properties);
  35553. this.cff = parser.parse();
  35554. var compiler = new CFFCompiler(this.cff);
  35555. this.seacs = this.cff.seacs;
  35556. try {
  35557. this.data = compiler.compile();
  35558. } catch (e) {
  35559. warn('Failed to compile font ' + properties.loadedName);
  35560. // There may have just been an issue with the compiler, set the data
  35561. // anyway and hope the font loaded.
  35562. this.data = file;
  35563. }
  35564. }
  35565. CFFFont.prototype = {
  35566. get numGlyphs() {
  35567. return this.cff.charStrings.count;
  35568. },
  35569. getCharset: function CFFFont_getCharset() {
  35570. return this.cff.charset.charset;
  35571. },
  35572. getGlyphMapping: function CFFFont_getGlyphMapping() {
  35573. var cff = this.cff;
  35574. var properties = this.properties;
  35575. var charsets = cff.charset.charset;
  35576. var charCodeToGlyphId;
  35577. var glyphId;
  35578. if (properties.composite) {
  35579. charCodeToGlyphId = Object.create(null);
  35580. if (cff.isCIDFont) {
  35581. // If the font is actually a CID font then we should use the charset
  35582. // to map CIDs to GIDs.
  35583. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  35584. var cid = charsets[glyphId];
  35585. var charCode = properties.cMap.charCodeOf(cid);
  35586. charCodeToGlyphId[charCode] = glyphId;
  35587. }
  35588. } else {
  35589. // If it is NOT actually a CID font then CIDs should be mapped
  35590. // directly to GIDs.
  35591. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  35592. charCodeToGlyphId[glyphId] = glyphId;
  35593. }
  35594. }
  35595. return charCodeToGlyphId;
  35596. }
  35597. var encoding = cff.encoding ? cff.encoding.encoding : null;
  35598. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  35599. return charCodeToGlyphId;
  35600. }
  35601. };
  35602. return CFFFont;
  35603. })();
  35604. var CFFParser = (function CFFParserClosure() {
  35605. var CharstringValidationData = [
  35606. null,
  35607. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  35608. null,
  35609. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  35610. { id: 'vmoveto', min: 1, stackClearing: true },
  35611. { id: 'rlineto', min: 2, resetStack: true },
  35612. { id: 'hlineto', min: 1, resetStack: true },
  35613. { id: 'vlineto', min: 1, resetStack: true },
  35614. { id: 'rrcurveto', min: 6, resetStack: true },
  35615. null,
  35616. { id: 'callsubr', min: 1, undefStack: true },
  35617. { id: 'return', min: 0, undefStack: true },
  35618. null, // 12
  35619. null,
  35620. { id: 'endchar', min: 0, stackClearing: true },
  35621. null,
  35622. null,
  35623. null,
  35624. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  35625. { id: 'hintmask', min: 0, stackClearing: true },
  35626. { id: 'cntrmask', min: 0, stackClearing: true },
  35627. { id: 'rmoveto', min: 2, stackClearing: true },
  35628. { id: 'hmoveto', min: 1, stackClearing: true },
  35629. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  35630. { id: 'rcurveline', min: 8, resetStack: true },
  35631. { id: 'rlinecurve', min: 8, resetStack: true },
  35632. { id: 'vvcurveto', min: 4, resetStack: true },
  35633. { id: 'hhcurveto', min: 4, resetStack: true },
  35634. null, // shortint
  35635. { id: 'callgsubr', min: 1, undefStack: true },
  35636. { id: 'vhcurveto', min: 4, resetStack: true },
  35637. { id: 'hvcurveto', min: 4, resetStack: true }
  35638. ];
  35639. var CharstringValidationData12 = [
  35640. null,
  35641. null,
  35642. null,
  35643. { id: 'and', min: 2, stackDelta: -1 },
  35644. { id: 'or', min: 2, stackDelta: -1 },
  35645. { id: 'not', min: 1, stackDelta: 0 },
  35646. null,
  35647. null,
  35648. null,
  35649. { id: 'abs', min: 1, stackDelta: 0 },
  35650. { id: 'add', min: 2, stackDelta: -1,
  35651. stackFn: function stack_div(stack, index) {
  35652. stack[index - 2] = stack[index - 2] + stack[index - 1];
  35653. }
  35654. },
  35655. { id: 'sub', min: 2, stackDelta: -1,
  35656. stackFn: function stack_div(stack, index) {
  35657. stack[index - 2] = stack[index - 2] - stack[index - 1];
  35658. }
  35659. },
  35660. { id: 'div', min: 2, stackDelta: -1,
  35661. stackFn: function stack_div(stack, index) {
  35662. stack[index - 2] = stack[index - 2] / stack[index - 1];
  35663. }
  35664. },
  35665. null,
  35666. { id: 'neg', min: 1, stackDelta: 0,
  35667. stackFn: function stack_div(stack, index) {
  35668. stack[index - 1] = -stack[index - 1];
  35669. }
  35670. },
  35671. { id: 'eq', min: 2, stackDelta: -1 },
  35672. null,
  35673. null,
  35674. { id: 'drop', min: 1, stackDelta: -1 },
  35675. null,
  35676. { id: 'put', min: 2, stackDelta: -2 },
  35677. { id: 'get', min: 1, stackDelta: 0 },
  35678. { id: 'ifelse', min: 4, stackDelta: -3 },
  35679. { id: 'random', min: 0, stackDelta: 1 },
  35680. { id: 'mul', min: 2, stackDelta: -1,
  35681. stackFn: function stack_div(stack, index) {
  35682. stack[index - 2] = stack[index - 2] * stack[index - 1];
  35683. }
  35684. },
  35685. null,
  35686. { id: 'sqrt', min: 1, stackDelta: 0 },
  35687. { id: 'dup', min: 1, stackDelta: 1 },
  35688. { id: 'exch', min: 2, stackDelta: 0 },
  35689. { id: 'index', min: 2, stackDelta: 0 },
  35690. { id: 'roll', min: 3, stackDelta: -2 },
  35691. null,
  35692. null,
  35693. null,
  35694. { id: 'hflex', min: 7, resetStack: true },
  35695. { id: 'flex', min: 13, resetStack: true },
  35696. { id: 'hflex1', min: 9, resetStack: true },
  35697. { id: 'flex1', min: 11, resetStack: true }
  35698. ];
  35699. function CFFParser(file, properties) {
  35700. this.bytes = file.getBytes();
  35701. this.properties = properties;
  35702. }
  35703. CFFParser.prototype = {
  35704. parse: function CFFParser_parse() {
  35705. var properties = this.properties;
  35706. var cff = new CFF();
  35707. this.cff = cff;
  35708. // The first five sections must be in order, all the others are reached
  35709. // via offsets contained in one of the below.
  35710. var header = this.parseHeader();
  35711. var nameIndex = this.parseIndex(header.endPos);
  35712. var topDictIndex = this.parseIndex(nameIndex.endPos);
  35713. var stringIndex = this.parseIndex(topDictIndex.endPos);
  35714. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  35715. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  35716. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  35717. cff.header = header.obj;
  35718. cff.names = this.parseNameIndex(nameIndex.obj);
  35719. cff.strings = this.parseStringIndex(stringIndex.obj);
  35720. cff.topDict = topDict;
  35721. cff.globalSubrIndex = globalSubrIndex.obj;
  35722. this.parsePrivateDict(cff.topDict);
  35723. cff.isCIDFont = topDict.hasName('ROS');
  35724. var charStringOffset = topDict.getByName('CharStrings');
  35725. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  35726. cff.charStrings = charStringsAndSeacs.charStrings;
  35727. cff.seacs = charStringsAndSeacs.seacs;
  35728. cff.widths = charStringsAndSeacs.widths;
  35729. var fontMatrix = topDict.getByName('FontMatrix');
  35730. if (fontMatrix) {
  35731. properties.fontMatrix = fontMatrix;
  35732. }
  35733. var fontBBox = topDict.getByName('FontBBox');
  35734. if (fontBBox) {
  35735. // adjusting ascent/descent
  35736. properties.ascent = fontBBox[3];
  35737. properties.descent = fontBBox[1];
  35738. properties.ascentScaled = true;
  35739. }
  35740. var charset, encoding;
  35741. if (cff.isCIDFont) {
  35742. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  35743. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  35744. var dictRaw = fdArrayIndex.get(i);
  35745. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  35746. cff.strings);
  35747. this.parsePrivateDict(fontDict);
  35748. cff.fdArray.push(fontDict);
  35749. }
  35750. // cid fonts don't have an encoding
  35751. encoding = null;
  35752. charset = this.parseCharsets(topDict.getByName('charset'),
  35753. cff.charStrings.count, cff.strings, true);
  35754. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  35755. cff.charStrings.count);
  35756. } else {
  35757. charset = this.parseCharsets(topDict.getByName('charset'),
  35758. cff.charStrings.count, cff.strings, false);
  35759. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  35760. properties,
  35761. cff.strings, charset.charset);
  35762. }
  35763. cff.charset = charset;
  35764. cff.encoding = encoding;
  35765. return cff;
  35766. },
  35767. parseHeader: function CFFParser_parseHeader() {
  35768. var bytes = this.bytes;
  35769. var bytesLength = bytes.length;
  35770. var offset = 0;
  35771. // Prevent an infinite loop, by checking that the offset is within the
  35772. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  35773. while (offset < bytesLength && bytes[offset] !== 1) {
  35774. ++offset;
  35775. }
  35776. if (offset >= bytesLength) {
  35777. error('Invalid CFF header');
  35778. } else if (offset !== 0) {
  35779. info('cff data is shifted');
  35780. bytes = bytes.subarray(offset);
  35781. this.bytes = bytes;
  35782. }
  35783. var major = bytes[0];
  35784. var minor = bytes[1];
  35785. var hdrSize = bytes[2];
  35786. var offSize = bytes[3];
  35787. var header = new CFFHeader(major, minor, hdrSize, offSize);
  35788. return { obj: header, endPos: hdrSize };
  35789. },
  35790. parseDict: function CFFParser_parseDict(dict) {
  35791. var pos = 0;
  35792. function parseOperand() {
  35793. var value = dict[pos++];
  35794. if (value === 30) {
  35795. return parseFloatOperand(pos);
  35796. } else if (value === 28) {
  35797. value = dict[pos++];
  35798. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  35799. return value;
  35800. } else if (value === 29) {
  35801. value = dict[pos++];
  35802. value = (value << 8) | dict[pos++];
  35803. value = (value << 8) | dict[pos++];
  35804. value = (value << 8) | dict[pos++];
  35805. return value;
  35806. } else if (value >= 32 && value <= 246) {
  35807. return value - 139;
  35808. } else if (value >= 247 && value <= 250) {
  35809. return ((value - 247) * 256) + dict[pos++] + 108;
  35810. } else if (value >= 251 && value <= 254) {
  35811. return -((value - 251) * 256) - dict[pos++] - 108;
  35812. } else {
  35813. error('255 is not a valid DICT command');
  35814. }
  35815. return -1;
  35816. }
  35817. function parseFloatOperand() {
  35818. var str = '';
  35819. var eof = 15;
  35820. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  35821. '9', '.', 'E', 'E-', null, '-'];
  35822. var length = dict.length;
  35823. while (pos < length) {
  35824. var b = dict[pos++];
  35825. var b1 = b >> 4;
  35826. var b2 = b & 15;
  35827. if (b1 === eof) {
  35828. break;
  35829. }
  35830. str += lookup[b1];
  35831. if (b2 === eof) {
  35832. break;
  35833. }
  35834. str += lookup[b2];
  35835. }
  35836. return parseFloat(str);
  35837. }
  35838. var operands = [];
  35839. var entries = [];
  35840. pos = 0;
  35841. var end = dict.length;
  35842. while (pos < end) {
  35843. var b = dict[pos];
  35844. if (b <= 21) {
  35845. if (b === 12) {
  35846. b = (b << 8) | dict[++pos];
  35847. }
  35848. entries.push([b, operands]);
  35849. operands = [];
  35850. ++pos;
  35851. } else {
  35852. operands.push(parseOperand());
  35853. }
  35854. }
  35855. return entries;
  35856. },
  35857. parseIndex: function CFFParser_parseIndex(pos) {
  35858. var cffIndex = new CFFIndex();
  35859. var bytes = this.bytes;
  35860. var count = (bytes[pos++] << 8) | bytes[pos++];
  35861. var offsets = [];
  35862. var end = pos;
  35863. var i, ii;
  35864. if (count !== 0) {
  35865. var offsetSize = bytes[pos++];
  35866. // add 1 for offset to determine size of last object
  35867. var startPos = pos + ((count + 1) * offsetSize) - 1;
  35868. for (i = 0, ii = count + 1; i < ii; ++i) {
  35869. var offset = 0;
  35870. for (var j = 0; j < offsetSize; ++j) {
  35871. offset <<= 8;
  35872. offset += bytes[pos++];
  35873. }
  35874. offsets.push(startPos + offset);
  35875. }
  35876. end = offsets[count];
  35877. }
  35878. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  35879. var offsetStart = offsets[i];
  35880. var offsetEnd = offsets[i + 1];
  35881. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  35882. }
  35883. return {obj: cffIndex, endPos: end};
  35884. },
  35885. parseNameIndex: function CFFParser_parseNameIndex(index) {
  35886. var names = [];
  35887. for (var i = 0, ii = index.count; i < ii; ++i) {
  35888. var name = index.get(i);
  35889. // OTS doesn't allow names to be over 127 characters.
  35890. var length = Math.min(name.length, 127);
  35891. var data = [];
  35892. // OTS also only permits certain characters in the name.
  35893. for (var j = 0; j < length; ++j) {
  35894. var c = name[j];
  35895. if (j === 0 && c === 0) {
  35896. data[j] = c;
  35897. continue;
  35898. }
  35899. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  35900. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  35901. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  35902. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  35903. data[j] = 95;
  35904. continue;
  35905. }
  35906. data[j] = c;
  35907. }
  35908. names.push(bytesToString(data));
  35909. }
  35910. return names;
  35911. },
  35912. parseStringIndex: function CFFParser_parseStringIndex(index) {
  35913. var strings = new CFFStrings();
  35914. for (var i = 0, ii = index.count; i < ii; ++i) {
  35915. var data = index.get(i);
  35916. strings.add(bytesToString(data));
  35917. }
  35918. return strings;
  35919. },
  35920. createDict: function CFFParser_createDict(Type, dict, strings) {
  35921. var cffDict = new Type(strings);
  35922. for (var i = 0, ii = dict.length; i < ii; ++i) {
  35923. var pair = dict[i];
  35924. var key = pair[0];
  35925. var value = pair[1];
  35926. cffDict.setByKey(key, value);
  35927. }
  35928. return cffDict;
  35929. },
  35930. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  35931. var charStrings = this.parseIndex(charStringOffset).obj;
  35932. var seacs = [];
  35933. var widths = [];
  35934. var count = charStrings.count;
  35935. for (var i = 0; i < count; i++) {
  35936. var charstring = charStrings.get(i);
  35937. var stackSize = 0;
  35938. var stack = [];
  35939. var undefStack = true;
  35940. var hints = 0;
  35941. var valid = true;
  35942. var data = charstring;
  35943. var length = data.length;
  35944. var firstStackClearing = true;
  35945. for (var j = 0; j < length;) {
  35946. var value = data[j++];
  35947. var validationCommand = null;
  35948. if (value === 12) {
  35949. var q = data[j++];
  35950. if (q === 0) {
  35951. // The CFF specification state that the 'dotsection' command
  35952. // (12, 0) is deprecated and treated as a no-op, but all Type2
  35953. // charstrings processors should support them. Unfortunately
  35954. // the font sanitizer don't. As a workaround the sequence (12, 0)
  35955. // is replaced by a useless (0, hmoveto).
  35956. data[j - 2] = 139;
  35957. data[j - 1] = 22;
  35958. stackSize = 0;
  35959. } else {
  35960. validationCommand = CharstringValidationData12[q];
  35961. }
  35962. } else if (value === 28) { // number (16 bit)
  35963. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  35964. j += 2;
  35965. stackSize++;
  35966. } else if (value === 14) {
  35967. if (stackSize >= 4) {
  35968. stackSize -= 4;
  35969. if (SEAC_ANALYSIS_ENABLED) {
  35970. seacs[i] = stack.slice(stackSize, stackSize + 4);
  35971. valid = false;
  35972. }
  35973. }
  35974. validationCommand = CharstringValidationData[value];
  35975. } else if (value >= 32 && value <= 246) { // number
  35976. stack[stackSize] = value - 139;
  35977. stackSize++;
  35978. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  35979. stack[stackSize] = (value < 251 ?
  35980. ((value - 247) << 8) + data[j] + 108 :
  35981. -((value - 251) << 8) - data[j] - 108);
  35982. j++;
  35983. stackSize++;
  35984. } else if (value === 255) { // number (32 bit)
  35985. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  35986. (data[j + 2] << 8) | data[j + 3]) / 65536;
  35987. j += 4;
  35988. stackSize++;
  35989. } else if (value === 19 || value === 20) {
  35990. hints += stackSize >> 1;
  35991. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  35992. stackSize %= 2;
  35993. validationCommand = CharstringValidationData[value];
  35994. } else {
  35995. validationCommand = CharstringValidationData[value];
  35996. }
  35997. if (validationCommand) {
  35998. if (validationCommand.stem) {
  35999. hints += stackSize >> 1;
  36000. }
  36001. if ('min' in validationCommand) {
  36002. if (!undefStack && stackSize < validationCommand.min) {
  36003. warn('Not enough parameters for ' + validationCommand.id +
  36004. '; actual: ' + stackSize +
  36005. ', expected: ' + validationCommand.min);
  36006. valid = false;
  36007. break;
  36008. }
  36009. }
  36010. if (firstStackClearing && validationCommand.stackClearing) {
  36011. firstStackClearing = false;
  36012. // the optional character width can be found before the first
  36013. // stack-clearing command arguments
  36014. stackSize -= validationCommand.min;
  36015. if (stackSize >= 2 && validationCommand.stem) {
  36016. // there are even amount of arguments for stem commands
  36017. stackSize %= 2;
  36018. } else if (stackSize > 1) {
  36019. warn('Found too many parameters for stack-clearing command');
  36020. }
  36021. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  36022. widths[i] = stack[stackSize - 1];
  36023. }
  36024. }
  36025. if ('stackDelta' in validationCommand) {
  36026. if ('stackFn' in validationCommand) {
  36027. validationCommand.stackFn(stack, stackSize);
  36028. }
  36029. stackSize += validationCommand.stackDelta;
  36030. } else if (validationCommand.stackClearing) {
  36031. stackSize = 0;
  36032. } else if (validationCommand.resetStack) {
  36033. stackSize = 0;
  36034. undefStack = false;
  36035. } else if (validationCommand.undefStack) {
  36036. stackSize = 0;
  36037. undefStack = true;
  36038. firstStackClearing = false;
  36039. }
  36040. }
  36041. }
  36042. if (!valid) {
  36043. // resetting invalid charstring to single 'endchar'
  36044. charStrings.set(i, new Uint8Array([14]));
  36045. }
  36046. }
  36047. return { charStrings: charStrings, seacs: seacs, widths: widths };
  36048. },
  36049. emptyPrivateDictionary:
  36050. function CFFParser_emptyPrivateDictionary(parentDict) {
  36051. var privateDict = this.createDict(CFFPrivateDict, [],
  36052. parentDict.strings);
  36053. parentDict.setByKey(18, [0, 0]);
  36054. parentDict.privateDict = privateDict;
  36055. },
  36056. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  36057. // no private dict, do nothing
  36058. if (!parentDict.hasName('Private')) {
  36059. this.emptyPrivateDictionary(parentDict);
  36060. return;
  36061. }
  36062. var privateOffset = parentDict.getByName('Private');
  36063. // make sure the params are formatted correctly
  36064. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  36065. parentDict.removeByName('Private');
  36066. return;
  36067. }
  36068. var size = privateOffset[0];
  36069. var offset = privateOffset[1];
  36070. // remove empty dicts or ones that refer to invalid location
  36071. if (size === 0 || offset >= this.bytes.length) {
  36072. this.emptyPrivateDictionary(parentDict);
  36073. return;
  36074. }
  36075. var privateDictEnd = offset + size;
  36076. var dictData = this.bytes.subarray(offset, privateDictEnd);
  36077. var dict = this.parseDict(dictData);
  36078. var privateDict = this.createDict(CFFPrivateDict, dict,
  36079. parentDict.strings);
  36080. parentDict.privateDict = privateDict;
  36081. // Parse the Subrs index also since it's relative to the private dict.
  36082. if (!privateDict.getByName('Subrs')) {
  36083. return;
  36084. }
  36085. var subrsOffset = privateDict.getByName('Subrs');
  36086. var relativeOffset = offset + subrsOffset;
  36087. // Validate the offset.
  36088. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  36089. this.emptyPrivateDictionary(parentDict);
  36090. return;
  36091. }
  36092. var subrsIndex = this.parseIndex(relativeOffset);
  36093. privateDict.subrsIndex = subrsIndex.obj;
  36094. },
  36095. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  36096. if (pos === 0) {
  36097. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  36098. ISOAdobeCharset);
  36099. } else if (pos === 1) {
  36100. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  36101. ExpertCharset);
  36102. } else if (pos === 2) {
  36103. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  36104. ExpertSubsetCharset);
  36105. }
  36106. var bytes = this.bytes;
  36107. var start = pos;
  36108. var format = bytes[pos++];
  36109. var charset = ['.notdef'];
  36110. var id, count, i;
  36111. // subtract 1 for the .notdef glyph
  36112. length -= 1;
  36113. switch (format) {
  36114. case 0:
  36115. for (i = 0; i < length; i++) {
  36116. id = (bytes[pos++] << 8) | bytes[pos++];
  36117. charset.push(cid ? id : strings.get(id));
  36118. }
  36119. break;
  36120. case 1:
  36121. while (charset.length <= length) {
  36122. id = (bytes[pos++] << 8) | bytes[pos++];
  36123. count = bytes[pos++];
  36124. for (i = 0; i <= count; i++) {
  36125. charset.push(cid ? id++ : strings.get(id++));
  36126. }
  36127. }
  36128. break;
  36129. case 2:
  36130. while (charset.length <= length) {
  36131. id = (bytes[pos++] << 8) | bytes[pos++];
  36132. count = (bytes[pos++] << 8) | bytes[pos++];
  36133. for (i = 0; i <= count; i++) {
  36134. charset.push(cid ? id++ : strings.get(id++));
  36135. }
  36136. }
  36137. break;
  36138. default:
  36139. error('Unknown charset format');
  36140. }
  36141. // Raw won't be needed if we actually compile the charset.
  36142. var end = pos;
  36143. var raw = bytes.subarray(start, end);
  36144. return new CFFCharset(false, format, charset, raw);
  36145. },
  36146. parseEncoding: function CFFParser_parseEncoding(pos,
  36147. properties,
  36148. strings,
  36149. charset) {
  36150. var encoding = {};
  36151. var bytes = this.bytes;
  36152. var predefined = false;
  36153. var hasSupplement = false;
  36154. var format, i, ii;
  36155. var raw = null;
  36156. function readSupplement() {
  36157. var supplementsCount = bytes[pos++];
  36158. for (i = 0; i < supplementsCount; i++) {
  36159. var code = bytes[pos++];
  36160. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  36161. encoding[code] = charset.indexOf(strings.get(sid));
  36162. }
  36163. }
  36164. if (pos === 0 || pos === 1) {
  36165. predefined = true;
  36166. format = pos;
  36167. var baseEncoding = pos ? Encodings.ExpertEncoding :
  36168. Encodings.StandardEncoding;
  36169. for (i = 0, ii = charset.length; i < ii; i++) {
  36170. var index = baseEncoding.indexOf(charset[i]);
  36171. if (index !== -1) {
  36172. encoding[index] = i;
  36173. }
  36174. }
  36175. } else {
  36176. var dataStart = pos;
  36177. format = bytes[pos++];
  36178. switch (format & 0x7f) {
  36179. case 0:
  36180. var glyphsCount = bytes[pos++];
  36181. for (i = 1; i <= glyphsCount; i++) {
  36182. encoding[bytes[pos++]] = i;
  36183. }
  36184. break;
  36185. case 1:
  36186. var rangesCount = bytes[pos++];
  36187. var gid = 1;
  36188. for (i = 0; i < rangesCount; i++) {
  36189. var start = bytes[pos++];
  36190. var left = bytes[pos++];
  36191. for (var j = start; j <= start + left; j++) {
  36192. encoding[j] = gid++;
  36193. }
  36194. }
  36195. break;
  36196. default:
  36197. error('Unknow encoding format: ' + format + ' in CFF');
  36198. break;
  36199. }
  36200. var dataEnd = pos;
  36201. if (format & 0x80) {
  36202. // The font sanitizer does not support CFF encoding with a
  36203. // supplement, since the encoding is not really used to map
  36204. // between gid to glyph, let's overwrite what is declared in
  36205. // the top dictionary to let the sanitizer think the font use
  36206. // StandardEncoding, that's a lie but that's ok.
  36207. bytes[dataStart] &= 0x7f;
  36208. readSupplement();
  36209. hasSupplement = true;
  36210. }
  36211. raw = bytes.subarray(dataStart, dataEnd);
  36212. }
  36213. format = format & 0x7f;
  36214. return new CFFEncoding(predefined, format, encoding, raw);
  36215. },
  36216. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  36217. var start = pos;
  36218. var bytes = this.bytes;
  36219. var format = bytes[pos++];
  36220. var fdSelect = [];
  36221. var i;
  36222. switch (format) {
  36223. case 0:
  36224. for (i = 0; i < length; ++i) {
  36225. var id = bytes[pos++];
  36226. fdSelect.push(id);
  36227. }
  36228. break;
  36229. case 3:
  36230. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  36231. for (i = 0; i < rangesCount; ++i) {
  36232. var first = (bytes[pos++] << 8) | bytes[pos++];
  36233. var fdIndex = bytes[pos++];
  36234. var next = (bytes[pos] << 8) | bytes[pos + 1];
  36235. for (var j = first; j < next; ++j) {
  36236. fdSelect.push(fdIndex);
  36237. }
  36238. }
  36239. // Advance past the sentinel(next).
  36240. pos += 2;
  36241. break;
  36242. default:
  36243. error('Unknown fdselect format ' + format);
  36244. break;
  36245. }
  36246. var end = pos;
  36247. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  36248. }
  36249. };
  36250. return CFFParser;
  36251. })();
  36252. // Compact Font Format
  36253. var CFF = (function CFFClosure() {
  36254. function CFF() {
  36255. this.header = null;
  36256. this.names = [];
  36257. this.topDict = null;
  36258. this.strings = new CFFStrings();
  36259. this.globalSubrIndex = null;
  36260. // The following could really be per font, but since we only have one font
  36261. // store them here.
  36262. this.encoding = null;
  36263. this.charset = null;
  36264. this.charStrings = null;
  36265. this.fdArray = [];
  36266. this.fdSelect = null;
  36267. this.isCIDFont = false;
  36268. }
  36269. return CFF;
  36270. })();
  36271. var CFFHeader = (function CFFHeaderClosure() {
  36272. function CFFHeader(major, minor, hdrSize, offSize) {
  36273. this.major = major;
  36274. this.minor = minor;
  36275. this.hdrSize = hdrSize;
  36276. this.offSize = offSize;
  36277. }
  36278. return CFFHeader;
  36279. })();
  36280. var CFFStrings = (function CFFStringsClosure() {
  36281. function CFFStrings() {
  36282. this.strings = [];
  36283. }
  36284. CFFStrings.prototype = {
  36285. get: function CFFStrings_get(index) {
  36286. if (index >= 0 && index <= 390) {
  36287. return CFFStandardStrings[index];
  36288. }
  36289. if (index - 391 <= this.strings.length) {
  36290. return this.strings[index - 391];
  36291. }
  36292. return CFFStandardStrings[0];
  36293. },
  36294. add: function CFFStrings_add(value) {
  36295. this.strings.push(value);
  36296. },
  36297. get count() {
  36298. return this.strings.length;
  36299. }
  36300. };
  36301. return CFFStrings;
  36302. })();
  36303. var CFFIndex = (function CFFIndexClosure() {
  36304. function CFFIndex() {
  36305. this.objects = [];
  36306. this.length = 0;
  36307. }
  36308. CFFIndex.prototype = {
  36309. add: function CFFIndex_add(data) {
  36310. this.length += data.length;
  36311. this.objects.push(data);
  36312. },
  36313. set: function CFFIndex_set(index, data) {
  36314. this.length += data.length - this.objects[index].length;
  36315. this.objects[index] = data;
  36316. },
  36317. get: function CFFIndex_get(index) {
  36318. return this.objects[index];
  36319. },
  36320. get count() {
  36321. return this.objects.length;
  36322. }
  36323. };
  36324. return CFFIndex;
  36325. })();
  36326. var CFFDict = (function CFFDictClosure() {
  36327. function CFFDict(tables, strings) {
  36328. this.keyToNameMap = tables.keyToNameMap;
  36329. this.nameToKeyMap = tables.nameToKeyMap;
  36330. this.defaults = tables.defaults;
  36331. this.types = tables.types;
  36332. this.opcodes = tables.opcodes;
  36333. this.order = tables.order;
  36334. this.strings = strings;
  36335. this.values = {};
  36336. }
  36337. CFFDict.prototype = {
  36338. // value should always be an array
  36339. setByKey: function CFFDict_setByKey(key, value) {
  36340. if (!(key in this.keyToNameMap)) {
  36341. return false;
  36342. }
  36343. // ignore empty values
  36344. if (value.length === 0) {
  36345. return true;
  36346. }
  36347. var type = this.types[key];
  36348. // remove the array wrapping these types of values
  36349. if (type === 'num' || type === 'sid' || type === 'offset') {
  36350. value = value[0];
  36351. }
  36352. this.values[key] = value;
  36353. return true;
  36354. },
  36355. setByName: function CFFDict_setByName(name, value) {
  36356. if (!(name in this.nameToKeyMap)) {
  36357. error('Invalid dictionary name "' + name + '"');
  36358. }
  36359. this.values[this.nameToKeyMap[name]] = value;
  36360. },
  36361. hasName: function CFFDict_hasName(name) {
  36362. return this.nameToKeyMap[name] in this.values;
  36363. },
  36364. getByName: function CFFDict_getByName(name) {
  36365. if (!(name in this.nameToKeyMap)) {
  36366. error('Invalid dictionary name "' + name + '"');
  36367. }
  36368. var key = this.nameToKeyMap[name];
  36369. if (!(key in this.values)) {
  36370. return this.defaults[key];
  36371. }
  36372. return this.values[key];
  36373. },
  36374. removeByName: function CFFDict_removeByName(name) {
  36375. delete this.values[this.nameToKeyMap[name]];
  36376. }
  36377. };
  36378. CFFDict.createTables = function CFFDict_createTables(layout) {
  36379. var tables = {
  36380. keyToNameMap: {},
  36381. nameToKeyMap: {},
  36382. defaults: {},
  36383. types: {},
  36384. opcodes: {},
  36385. order: []
  36386. };
  36387. for (var i = 0, ii = layout.length; i < ii; ++i) {
  36388. var entry = layout[i];
  36389. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  36390. tables.keyToNameMap[key] = entry[1];
  36391. tables.nameToKeyMap[entry[1]] = key;
  36392. tables.types[key] = entry[2];
  36393. tables.defaults[key] = entry[3];
  36394. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  36395. tables.order.push(key);
  36396. }
  36397. return tables;
  36398. };
  36399. return CFFDict;
  36400. })();
  36401. var CFFTopDict = (function CFFTopDictClosure() {
  36402. var layout = [
  36403. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  36404. [[12, 20], 'SyntheticBase', 'num', null],
  36405. [0, 'version', 'sid', null],
  36406. [1, 'Notice', 'sid', null],
  36407. [[12, 0], 'Copyright', 'sid', null],
  36408. [2, 'FullName', 'sid', null],
  36409. [3, 'FamilyName', 'sid', null],
  36410. [4, 'Weight', 'sid', null],
  36411. [[12, 1], 'isFixedPitch', 'num', 0],
  36412. [[12, 2], 'ItalicAngle', 'num', 0],
  36413. [[12, 3], 'UnderlinePosition', 'num', -100],
  36414. [[12, 4], 'UnderlineThickness', 'num', 50],
  36415. [[12, 5], 'PaintType', 'num', 0],
  36416. [[12, 6], 'CharstringType', 'num', 2],
  36417. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  36418. [0.001, 0, 0, 0.001, 0, 0]],
  36419. [13, 'UniqueID', 'num', null],
  36420. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  36421. [[12, 8], 'StrokeWidth', 'num', 0],
  36422. [14, 'XUID', 'array', null],
  36423. [15, 'charset', 'offset', 0],
  36424. [16, 'Encoding', 'offset', 0],
  36425. [17, 'CharStrings', 'offset', 0],
  36426. [18, 'Private', ['offset', 'offset'], null],
  36427. [[12, 21], 'PostScript', 'sid', null],
  36428. [[12, 22], 'BaseFontName', 'sid', null],
  36429. [[12, 23], 'BaseFontBlend', 'delta', null],
  36430. [[12, 31], 'CIDFontVersion', 'num', 0],
  36431. [[12, 32], 'CIDFontRevision', 'num', 0],
  36432. [[12, 33], 'CIDFontType', 'num', 0],
  36433. [[12, 34], 'CIDCount', 'num', 8720],
  36434. [[12, 35], 'UIDBase', 'num', null],
  36435. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  36436. // before FDArray.
  36437. [[12, 37], 'FDSelect', 'offset', null],
  36438. [[12, 36], 'FDArray', 'offset', null],
  36439. [[12, 38], 'FontName', 'sid', null]
  36440. ];
  36441. var tables = null;
  36442. function CFFTopDict(strings) {
  36443. if (tables === null) {
  36444. tables = CFFDict.createTables(layout);
  36445. }
  36446. CFFDict.call(this, tables, strings);
  36447. this.privateDict = null;
  36448. }
  36449. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  36450. return CFFTopDict;
  36451. })();
  36452. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  36453. var layout = [
  36454. [6, 'BlueValues', 'delta', null],
  36455. [7, 'OtherBlues', 'delta', null],
  36456. [8, 'FamilyBlues', 'delta', null],
  36457. [9, 'FamilyOtherBlues', 'delta', null],
  36458. [[12, 9], 'BlueScale', 'num', 0.039625],
  36459. [[12, 10], 'BlueShift', 'num', 7],
  36460. [[12, 11], 'BlueFuzz', 'num', 1],
  36461. [10, 'StdHW', 'num', null],
  36462. [11, 'StdVW', 'num', null],
  36463. [[12, 12], 'StemSnapH', 'delta', null],
  36464. [[12, 13], 'StemSnapV', 'delta', null],
  36465. [[12, 14], 'ForceBold', 'num', 0],
  36466. [[12, 17], 'LanguageGroup', 'num', 0],
  36467. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  36468. [[12, 19], 'initialRandomSeed', 'num', 0],
  36469. [20, 'defaultWidthX', 'num', 0],
  36470. [21, 'nominalWidthX', 'num', 0],
  36471. [19, 'Subrs', 'offset', null]
  36472. ];
  36473. var tables = null;
  36474. function CFFPrivateDict(strings) {
  36475. if (tables === null) {
  36476. tables = CFFDict.createTables(layout);
  36477. }
  36478. CFFDict.call(this, tables, strings);
  36479. this.subrsIndex = null;
  36480. }
  36481. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  36482. return CFFPrivateDict;
  36483. })();
  36484. var CFFCharsetPredefinedTypes = {
  36485. ISO_ADOBE: 0,
  36486. EXPERT: 1,
  36487. EXPERT_SUBSET: 2
  36488. };
  36489. var CFFCharset = (function CFFCharsetClosure() {
  36490. function CFFCharset(predefined, format, charset, raw) {
  36491. this.predefined = predefined;
  36492. this.format = format;
  36493. this.charset = charset;
  36494. this.raw = raw;
  36495. }
  36496. return CFFCharset;
  36497. })();
  36498. var CFFEncoding = (function CFFEncodingClosure() {
  36499. function CFFEncoding(predefined, format, encoding, raw) {
  36500. this.predefined = predefined;
  36501. this.format = format;
  36502. this.encoding = encoding;
  36503. this.raw = raw;
  36504. }
  36505. return CFFEncoding;
  36506. })();
  36507. var CFFFDSelect = (function CFFFDSelectClosure() {
  36508. function CFFFDSelect(fdSelect, raw) {
  36509. this.fdSelect = fdSelect;
  36510. this.raw = raw;
  36511. }
  36512. return CFFFDSelect;
  36513. })();
  36514. // Helper class to keep track of where an offset is within the data and helps
  36515. // filling in that offset once it's known.
  36516. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  36517. function CFFOffsetTracker() {
  36518. this.offsets = {};
  36519. }
  36520. CFFOffsetTracker.prototype = {
  36521. isTracking: function CFFOffsetTracker_isTracking(key) {
  36522. return key in this.offsets;
  36523. },
  36524. track: function CFFOffsetTracker_track(key, location) {
  36525. if (key in this.offsets) {
  36526. error('Already tracking location of ' + key);
  36527. }
  36528. this.offsets[key] = location;
  36529. },
  36530. offset: function CFFOffsetTracker_offset(value) {
  36531. for (var key in this.offsets) {
  36532. this.offsets[key] += value;
  36533. }
  36534. },
  36535. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  36536. values,
  36537. output) {
  36538. if (!(key in this.offsets)) {
  36539. error('Not tracking location of ' + key);
  36540. }
  36541. var data = output.data;
  36542. var dataOffset = this.offsets[key];
  36543. var size = 5;
  36544. for (var i = 0, ii = values.length; i < ii; ++i) {
  36545. var offset0 = i * size + dataOffset;
  36546. var offset1 = offset0 + 1;
  36547. var offset2 = offset0 + 2;
  36548. var offset3 = offset0 + 3;
  36549. var offset4 = offset0 + 4;
  36550. // It's easy to screw up offsets so perform this sanity check.
  36551. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  36552. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  36553. error('writing to an offset that is not empty');
  36554. }
  36555. var value = values[i];
  36556. data[offset0] = 0x1d;
  36557. data[offset1] = (value >> 24) & 0xFF;
  36558. data[offset2] = (value >> 16) & 0xFF;
  36559. data[offset3] = (value >> 8) & 0xFF;
  36560. data[offset4] = value & 0xFF;
  36561. }
  36562. }
  36563. };
  36564. return CFFOffsetTracker;
  36565. })();
  36566. // Takes a CFF and converts it to the binary representation.
  36567. var CFFCompiler = (function CFFCompilerClosure() {
  36568. function CFFCompiler(cff) {
  36569. this.cff = cff;
  36570. }
  36571. CFFCompiler.prototype = {
  36572. compile: function CFFCompiler_compile() {
  36573. var cff = this.cff;
  36574. var output = {
  36575. data: [],
  36576. length: 0,
  36577. add: function CFFCompiler_add(data) {
  36578. this.data = this.data.concat(data);
  36579. this.length = this.data.length;
  36580. }
  36581. };
  36582. // Compile the five entries that must be in order.
  36583. var header = this.compileHeader(cff.header);
  36584. output.add(header);
  36585. var nameIndex = this.compileNameIndex(cff.names);
  36586. output.add(nameIndex);
  36587. if (cff.isCIDFont) {
  36588. // The spec is unclear on how font matrices should relate to each other
  36589. // when there is one in the main top dict and the sub top dicts.
  36590. // Windows handles this differently than linux and osx so we have to
  36591. // normalize to work on all.
  36592. // Rules based off of some mailing list discussions:
  36593. // - If main font has a matrix and subfont doesn't, use the main matrix.
  36594. // - If no main font matrix and there is a subfont matrix, use the
  36595. // subfont matrix.
  36596. // - If both have matrices, concat together.
  36597. // - If neither have matrices, use default.
  36598. // To make this work on all platforms we move the top matrix into each
  36599. // sub top dict and concat if necessary.
  36600. if (cff.topDict.hasName('FontMatrix')) {
  36601. var base = cff.topDict.getByName('FontMatrix');
  36602. cff.topDict.removeByName('FontMatrix');
  36603. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  36604. var subDict = cff.fdArray[i];
  36605. var matrix = base.slice(0);
  36606. if (subDict.hasName('FontMatrix')) {
  36607. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  36608. }
  36609. subDict.setByName('FontMatrix', matrix);
  36610. }
  36611. }
  36612. }
  36613. var compiled = this.compileTopDicts([cff.topDict],
  36614. output.length,
  36615. cff.isCIDFont);
  36616. output.add(compiled.output);
  36617. var topDictTracker = compiled.trackers[0];
  36618. var stringIndex = this.compileStringIndex(cff.strings.strings);
  36619. output.add(stringIndex);
  36620. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  36621. output.add(globalSubrIndex);
  36622. // Now start on the other entries that have no specfic order.
  36623. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  36624. if (cff.encoding.predefined) {
  36625. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  36626. output);
  36627. } else {
  36628. var encoding = this.compileEncoding(cff.encoding);
  36629. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  36630. output.add(encoding);
  36631. }
  36632. }
  36633. if (cff.charset && cff.topDict.hasName('charset')) {
  36634. if (cff.charset.predefined) {
  36635. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  36636. output);
  36637. } else {
  36638. var charset = this.compileCharset(cff.charset);
  36639. topDictTracker.setEntryLocation('charset', [output.length], output);
  36640. output.add(charset);
  36641. }
  36642. }
  36643. var charStrings = this.compileCharStrings(cff.charStrings);
  36644. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  36645. output.add(charStrings);
  36646. if (cff.isCIDFont) {
  36647. // For some reason FDSelect must be in front of FDArray on windows. OSX
  36648. // and linux don't seem to care.
  36649. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  36650. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  36651. output.add(fdSelect);
  36652. // It is unclear if the sub font dictionary can have CID related
  36653. // dictionary keys, but the sanitizer doesn't like them so remove them.
  36654. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  36655. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  36656. output.add(compiled.output);
  36657. var fontDictTrackers = compiled.trackers;
  36658. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  36659. }
  36660. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  36661. // If the font data ends with INDEX whose object data is zero-length,
  36662. // the sanitizer will bail out. Add a dummy byte to avoid that.
  36663. output.add([0]);
  36664. return output.data;
  36665. },
  36666. encodeNumber: function CFFCompiler_encodeNumber(value) {
  36667. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  36668. return this.encodeInteger(value);
  36669. } else {
  36670. return this.encodeFloat(value);
  36671. }
  36672. },
  36673. encodeFloat: function CFFCompiler_encodeFloat(num) {
  36674. var value = num.toString();
  36675. // rounding inaccurate doubles
  36676. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36677. if (m) {
  36678. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36679. value = (Math.round(num * epsilon) / epsilon).toString();
  36680. }
  36681. var nibbles = '';
  36682. var i, ii;
  36683. for (i = 0, ii = value.length; i < ii; ++i) {
  36684. var a = value[i];
  36685. if (a === 'e') {
  36686. nibbles += value[++i] === '-' ? 'c' : 'b';
  36687. } else if (a === '.') {
  36688. nibbles += 'a';
  36689. } else if (a === '-') {
  36690. nibbles += 'e';
  36691. } else {
  36692. nibbles += a;
  36693. }
  36694. }
  36695. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  36696. var out = [30];
  36697. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  36698. out.push(parseInt(nibbles.substr(i, 2), 16));
  36699. }
  36700. return out;
  36701. },
  36702. encodeInteger: function CFFCompiler_encodeInteger(value) {
  36703. var code;
  36704. if (value >= -107 && value <= 107) {
  36705. code = [value + 139];
  36706. } else if (value >= 108 && value <= 1131) {
  36707. value = [value - 108];
  36708. code = [(value >> 8) + 247, value & 0xFF];
  36709. } else if (value >= -1131 && value <= -108) {
  36710. value = -value - 108;
  36711. code = [(value >> 8) + 251, value & 0xFF];
  36712. } else if (value >= -32768 && value <= 32767) {
  36713. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  36714. } else {
  36715. code = [0x1d,
  36716. (value >> 24) & 0xFF,
  36717. (value >> 16) & 0xFF,
  36718. (value >> 8) & 0xFF,
  36719. value & 0xFF];
  36720. }
  36721. return code;
  36722. },
  36723. compileHeader: function CFFCompiler_compileHeader(header) {
  36724. return [
  36725. header.major,
  36726. header.minor,
  36727. header.hdrSize,
  36728. header.offSize
  36729. ];
  36730. },
  36731. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  36732. var nameIndex = new CFFIndex();
  36733. for (var i = 0, ii = names.length; i < ii; ++i) {
  36734. nameIndex.add(stringToBytes(names[i]));
  36735. }
  36736. return this.compileIndex(nameIndex);
  36737. },
  36738. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  36739. length,
  36740. removeCidKeys) {
  36741. var fontDictTrackers = [];
  36742. var fdArrayIndex = new CFFIndex();
  36743. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36744. var fontDict = dicts[i];
  36745. if (removeCidKeys) {
  36746. fontDict.removeByName('CIDFontVersion');
  36747. fontDict.removeByName('CIDFontRevision');
  36748. fontDict.removeByName('CIDFontType');
  36749. fontDict.removeByName('CIDCount');
  36750. fontDict.removeByName('UIDBase');
  36751. }
  36752. var fontDictTracker = new CFFOffsetTracker();
  36753. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  36754. fontDictTrackers.push(fontDictTracker);
  36755. fdArrayIndex.add(fontDictData);
  36756. fontDictTracker.offset(length);
  36757. }
  36758. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  36759. return {
  36760. trackers: fontDictTrackers,
  36761. output: fdArrayIndex
  36762. };
  36763. },
  36764. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  36765. trackers,
  36766. output) {
  36767. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36768. var fontDict = dicts[i];
  36769. assert(fontDict.privateDict && fontDict.hasName('Private'),
  36770. 'There must be an private dictionary.');
  36771. var privateDict = fontDict.privateDict;
  36772. var privateDictTracker = new CFFOffsetTracker();
  36773. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  36774. var outputLength = output.length;
  36775. privateDictTracker.offset(outputLength);
  36776. if (!privateDictData.length) {
  36777. // The private dictionary was empty, set the output length to zero to
  36778. // ensure the offset length isn't out of bounds in the eyes of the
  36779. // sanitizer.
  36780. outputLength = 0;
  36781. }
  36782. trackers[i].setEntryLocation('Private',
  36783. [privateDictData.length, outputLength],
  36784. output);
  36785. output.add(privateDictData);
  36786. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  36787. var subrs = this.compileIndex(privateDict.subrsIndex);
  36788. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  36789. output);
  36790. output.add(subrs);
  36791. }
  36792. }
  36793. },
  36794. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  36795. var out = [];
  36796. // The dictionary keys must be in a certain order.
  36797. var order = dict.order;
  36798. for (var i = 0; i < order.length; ++i) {
  36799. var key = order[i];
  36800. if (!(key in dict.values)) {
  36801. continue;
  36802. }
  36803. var values = dict.values[key];
  36804. var types = dict.types[key];
  36805. if (!isArray(types)) {
  36806. types = [types];
  36807. }
  36808. if (!isArray(values)) {
  36809. values = [values];
  36810. }
  36811. // Remove any empty dict values.
  36812. if (values.length === 0) {
  36813. continue;
  36814. }
  36815. for (var j = 0, jj = types.length; j < jj; ++j) {
  36816. var type = types[j];
  36817. var value = values[j];
  36818. switch (type) {
  36819. case 'num':
  36820. case 'sid':
  36821. out = out.concat(this.encodeNumber(value));
  36822. break;
  36823. case 'offset':
  36824. // For offsets we just insert a 32bit integer so we don't have to
  36825. // deal with figuring out the length of the offset when it gets
  36826. // replaced later on by the compiler.
  36827. var name = dict.keyToNameMap[key];
  36828. // Some offsets have the offset and the length, so just record the
  36829. // position of the first one.
  36830. if (!offsetTracker.isTracking(name)) {
  36831. offsetTracker.track(name, out.length);
  36832. }
  36833. out = out.concat([0x1d, 0, 0, 0, 0]);
  36834. break;
  36835. case 'array':
  36836. case 'delta':
  36837. out = out.concat(this.encodeNumber(value));
  36838. for (var k = 1, kk = values.length; k < kk; ++k) {
  36839. out = out.concat(this.encodeNumber(values[k]));
  36840. }
  36841. break;
  36842. default:
  36843. error('Unknown data type of ' + type);
  36844. break;
  36845. }
  36846. }
  36847. out = out.concat(dict.opcodes[key]);
  36848. }
  36849. return out;
  36850. },
  36851. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  36852. var stringIndex = new CFFIndex();
  36853. for (var i = 0, ii = strings.length; i < ii; ++i) {
  36854. stringIndex.add(stringToBytes(strings[i]));
  36855. }
  36856. return this.compileIndex(stringIndex);
  36857. },
  36858. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  36859. var globalSubrIndex = this.cff.globalSubrIndex;
  36860. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  36861. },
  36862. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  36863. return this.compileIndex(charStrings);
  36864. },
  36865. compileCharset: function CFFCompiler_compileCharset(charset) {
  36866. return this.compileTypedArray(charset.raw);
  36867. },
  36868. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  36869. return this.compileTypedArray(encoding.raw);
  36870. },
  36871. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  36872. return this.compileTypedArray(fdSelect);
  36873. },
  36874. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  36875. var out = [];
  36876. for (var i = 0, ii = data.length; i < ii; ++i) {
  36877. out[i] = data[i];
  36878. }
  36879. return out;
  36880. },
  36881. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  36882. trackers = trackers || [];
  36883. var objects = index.objects;
  36884. // First 2 bytes contains the number of objects contained into this index
  36885. var count = objects.length;
  36886. // If there is no object, just create an index. This technically
  36887. // should just be [0, 0] but OTS has an issue with that.
  36888. if (count === 0) {
  36889. return [0, 0, 0];
  36890. }
  36891. var data = [(count >> 8) & 0xFF, count & 0xff];
  36892. var lastOffset = 1, i;
  36893. for (i = 0; i < count; ++i) {
  36894. lastOffset += objects[i].length;
  36895. }
  36896. var offsetSize;
  36897. if (lastOffset < 0x100) {
  36898. offsetSize = 1;
  36899. } else if (lastOffset < 0x10000) {
  36900. offsetSize = 2;
  36901. } else if (lastOffset < 0x1000000) {
  36902. offsetSize = 3;
  36903. } else {
  36904. offsetSize = 4;
  36905. }
  36906. // Next byte contains the offset size use to reference object in the file
  36907. data.push(offsetSize);
  36908. // Add another offset after this one because we need a new offset
  36909. var relativeOffset = 1;
  36910. for (i = 0; i < count + 1; i++) {
  36911. if (offsetSize === 1) {
  36912. data.push(relativeOffset & 0xFF);
  36913. } else if (offsetSize === 2) {
  36914. data.push((relativeOffset >> 8) & 0xFF,
  36915. relativeOffset & 0xFF);
  36916. } else if (offsetSize === 3) {
  36917. data.push((relativeOffset >> 16) & 0xFF,
  36918. (relativeOffset >> 8) & 0xFF,
  36919. relativeOffset & 0xFF);
  36920. } else {
  36921. data.push((relativeOffset >>> 24) & 0xFF,
  36922. (relativeOffset >> 16) & 0xFF,
  36923. (relativeOffset >> 8) & 0xFF,
  36924. relativeOffset & 0xFF);
  36925. }
  36926. if (objects[i]) {
  36927. relativeOffset += objects[i].length;
  36928. }
  36929. }
  36930. for (i = 0; i < count; i++) {
  36931. // Notify the tracker where the object will be offset in the data.
  36932. if (trackers[i]) {
  36933. trackers[i].offset(data.length);
  36934. }
  36935. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  36936. data.push(objects[i][j]);
  36937. }
  36938. }
  36939. return data;
  36940. }
  36941. };
  36942. return CFFCompiler;
  36943. })();
  36944. function _enableSeacAnalysis(enabled) {
  36945. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  36946. }
  36947. // Workaround for seac on Windows.
  36948. (function checkSeacSupport() {
  36949. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  36950. SEAC_ANALYSIS_ENABLED = true;
  36951. }
  36952. })();
  36953. // Workaround for Private Use Area characters in Chrome on Windows
  36954. // http://code.google.com/p/chromium/issues/detail?id=122465
  36955. // https://github.com/mozilla/pdf.js/issues/1689
  36956. (function checkChromeWindows() {
  36957. if (typeof navigator !== 'undefined' &&
  36958. /Windows.*Chrome/.test(navigator.userAgent)) {
  36959. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  36960. }
  36961. })();
  36962. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  36963. exports.CFFCompiler = CFFCompiler;
  36964. exports.CFFIndex = CFFIndex;
  36965. exports.CFFParser = CFFParser;
  36966. exports.CFFStrings = CFFStrings;
  36967. exports.Encodings = Encodings;
  36968. exports.ErrorFont = ErrorFont;
  36969. exports.FontFlags = FontFlags;
  36970. exports.Font = Font;
  36971. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  36972. exports.NormalizedUnicodes = NormalizedUnicodes;
  36973. exports.ToUnicodeMap = ToUnicodeMap;
  36974. exports.Type1Parser = Type1Parser;
  36975. exports.getFontType = getFontType;
  36976. exports.reverseIfRtl = reverseIfRtl;
  36977. exports.serifFonts = serifFonts;
  36978. exports.symbolsFonts = symbolsFonts;
  36979. exports.stdFontMap = stdFontMap;
  36980. exports._enableSeacAnalysis = _enableSeacAnalysis;
  36981. // TODO refactor to remove cyclic dependency on font_renderer.js
  36982. coreFontRenderer._setCoreFonts(exports);
  36983. }));
  36984. (function (root, factory) {
  36985. {
  36986. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  36987. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  36988. }
  36989. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  36990. var error = sharedUtil.error;
  36991. var info = sharedUtil.info;
  36992. var isArray = sharedUtil.isArray;
  36993. var isBool = sharedUtil.isBool;
  36994. var isDict = corePrimitives.isDict;
  36995. var isStream = corePrimitives.isStream;
  36996. var PostScriptLexer = corePsParser.PostScriptLexer;
  36997. var PostScriptParser = corePsParser.PostScriptParser;
  36998. var PDFFunction = (function PDFFunctionClosure() {
  36999. var CONSTRUCT_SAMPLED = 0;
  37000. var CONSTRUCT_INTERPOLATED = 2;
  37001. var CONSTRUCT_STICHED = 3;
  37002. var CONSTRUCT_POSTSCRIPT = 4;
  37003. return {
  37004. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  37005. str) {
  37006. var i, ii;
  37007. var length = 1;
  37008. for (i = 0, ii = size.length; i < ii; i++) {
  37009. length *= size[i];
  37010. }
  37011. length *= outputSize;
  37012. var array = new Array(length);
  37013. var codeSize = 0;
  37014. var codeBuf = 0;
  37015. // 32 is a valid bps so shifting won't work
  37016. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  37017. var strBytes = str.getBytes((length * bps + 7) / 8);
  37018. var strIdx = 0;
  37019. for (i = 0; i < length; i++) {
  37020. while (codeSize < bps) {
  37021. codeBuf <<= 8;
  37022. codeBuf |= strBytes[strIdx++];
  37023. codeSize += 8;
  37024. }
  37025. codeSize -= bps;
  37026. array[i] = (codeBuf >> codeSize) * sampleMul;
  37027. codeBuf &= (1 << codeSize) - 1;
  37028. }
  37029. return array;
  37030. },
  37031. getIR: function PDFFunction_getIR(xref, fn) {
  37032. var dict = fn.dict;
  37033. if (!dict) {
  37034. dict = fn;
  37035. }
  37036. var types = [this.constructSampled,
  37037. null,
  37038. this.constructInterpolated,
  37039. this.constructStiched,
  37040. this.constructPostScript];
  37041. var typeNum = dict.get('FunctionType');
  37042. var typeFn = types[typeNum];
  37043. if (!typeFn) {
  37044. error('Unknown type of function');
  37045. }
  37046. return typeFn.call(this, fn, dict, xref);
  37047. },
  37048. fromIR: function PDFFunction_fromIR(IR) {
  37049. var type = IR[0];
  37050. switch (type) {
  37051. case CONSTRUCT_SAMPLED:
  37052. return this.constructSampledFromIR(IR);
  37053. case CONSTRUCT_INTERPOLATED:
  37054. return this.constructInterpolatedFromIR(IR);
  37055. case CONSTRUCT_STICHED:
  37056. return this.constructStichedFromIR(IR);
  37057. //case CONSTRUCT_POSTSCRIPT:
  37058. default:
  37059. return this.constructPostScriptFromIR(IR);
  37060. }
  37061. },
  37062. parse: function PDFFunction_parse(xref, fn) {
  37063. var IR = this.getIR(xref, fn);
  37064. return this.fromIR(IR);
  37065. },
  37066. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  37067. if (!isArray(fnObj)) {
  37068. // not an array -- parsing as regular function
  37069. return this.parse(xref, fnObj);
  37070. }
  37071. var fnArray = [];
  37072. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  37073. var obj = xref.fetchIfRef(fnObj[j]);
  37074. fnArray.push(PDFFunction.parse(xref, obj));
  37075. }
  37076. return function (src, srcOffset, dest, destOffset) {
  37077. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  37078. fnArray[i](src, srcOffset, dest, destOffset + i);
  37079. }
  37080. };
  37081. },
  37082. constructSampled: function PDFFunction_constructSampled(str, dict) {
  37083. function toMultiArray(arr) {
  37084. var inputLength = arr.length;
  37085. var out = [];
  37086. var index = 0;
  37087. for (var i = 0; i < inputLength; i += 2) {
  37088. out[index] = [arr[i], arr[i + 1]];
  37089. ++index;
  37090. }
  37091. return out;
  37092. }
  37093. var domain = dict.get('Domain');
  37094. var range = dict.get('Range');
  37095. if (!domain || !range) {
  37096. error('No domain or range');
  37097. }
  37098. var inputSize = domain.length / 2;
  37099. var outputSize = range.length / 2;
  37100. domain = toMultiArray(domain);
  37101. range = toMultiArray(range);
  37102. var size = dict.get('Size');
  37103. var bps = dict.get('BitsPerSample');
  37104. var order = dict.get('Order') || 1;
  37105. if (order !== 1) {
  37106. // No description how cubic spline interpolation works in PDF32000:2008
  37107. // As in poppler, ignoring order, linear interpolation may work as good
  37108. info('No support for cubic spline interpolation: ' + order);
  37109. }
  37110. var encode = dict.get('Encode');
  37111. if (!encode) {
  37112. encode = [];
  37113. for (var i = 0; i < inputSize; ++i) {
  37114. encode.push(0);
  37115. encode.push(size[i] - 1);
  37116. }
  37117. }
  37118. encode = toMultiArray(encode);
  37119. var decode = dict.get('Decode');
  37120. if (!decode) {
  37121. decode = range;
  37122. } else {
  37123. decode = toMultiArray(decode);
  37124. }
  37125. var samples = this.getSampleArray(size, outputSize, bps, str);
  37126. return [
  37127. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  37128. outputSize, Math.pow(2, bps) - 1, range
  37129. ];
  37130. },
  37131. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  37132. // See chapter 3, page 109 of the PDF reference
  37133. function interpolate(x, xmin, xmax, ymin, ymax) {
  37134. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  37135. }
  37136. return function constructSampledFromIRResult(src, srcOffset,
  37137. dest, destOffset) {
  37138. // See chapter 3, page 110 of the PDF reference.
  37139. var m = IR[1];
  37140. var domain = IR[2];
  37141. var encode = IR[3];
  37142. var decode = IR[4];
  37143. var samples = IR[5];
  37144. var size = IR[6];
  37145. var n = IR[7];
  37146. //var mask = IR[8];
  37147. var range = IR[9];
  37148. // Building the cube vertices: its part and sample index
  37149. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  37150. var cubeVertices = 1 << m;
  37151. var cubeN = new Float64Array(cubeVertices);
  37152. var cubeVertex = new Uint32Array(cubeVertices);
  37153. var i, j;
  37154. for (j = 0; j < cubeVertices; j++) {
  37155. cubeN[j] = 1;
  37156. }
  37157. var k = n, pos = 1;
  37158. // Map x_i to y_j for 0 <= i < m using the sampled function.
  37159. for (i = 0; i < m; ++i) {
  37160. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  37161. var domain_2i = domain[i][0];
  37162. var domain_2i_1 = domain[i][1];
  37163. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  37164. domain_2i_1);
  37165. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  37166. // Encode_2i, Encode_2i+1)
  37167. var e = interpolate(xi, domain_2i, domain_2i_1,
  37168. encode[i][0], encode[i][1]);
  37169. // e_i' = min(max(e_i, 0), Size_i - 1)
  37170. var size_i = size[i];
  37171. e = Math.min(Math.max(e, 0), size_i - 1);
  37172. // Adjusting the cube: N and vertex sample index
  37173. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  37174. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  37175. var n1 = e - e0; // (e - e0) / (e1 - e0);
  37176. var offset0 = e0 * k;
  37177. var offset1 = offset0 + k; // e1 * k
  37178. for (j = 0; j < cubeVertices; j++) {
  37179. if (j & pos) {
  37180. cubeN[j] *= n1;
  37181. cubeVertex[j] += offset1;
  37182. } else {
  37183. cubeN[j] *= n0;
  37184. cubeVertex[j] += offset0;
  37185. }
  37186. }
  37187. k *= size_i;
  37188. pos <<= 1;
  37189. }
  37190. for (j = 0; j < n; ++j) {
  37191. // Sum all cube vertices' samples portions
  37192. var rj = 0;
  37193. for (i = 0; i < cubeVertices; i++) {
  37194. rj += samples[cubeVertex[i] + j] * cubeN[i];
  37195. }
  37196. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  37197. // Decode_2j, Decode_2j+1)
  37198. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  37199. // y_j = min(max(r_j, range_2j), range_2j+1)
  37200. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  37201. range[j][1]);
  37202. }
  37203. };
  37204. },
  37205. constructInterpolated: function PDFFunction_constructInterpolated(str,
  37206. dict) {
  37207. var c0 = dict.get('C0') || [0];
  37208. var c1 = dict.get('C1') || [1];
  37209. var n = dict.get('N');
  37210. if (!isArray(c0) || !isArray(c1)) {
  37211. error('Illegal dictionary for interpolated function');
  37212. }
  37213. var length = c0.length;
  37214. var diff = [];
  37215. for (var i = 0; i < length; ++i) {
  37216. diff.push(c1[i] - c0[i]);
  37217. }
  37218. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  37219. },
  37220. constructInterpolatedFromIR:
  37221. function PDFFunction_constructInterpolatedFromIR(IR) {
  37222. var c0 = IR[1];
  37223. var diff = IR[2];
  37224. var n = IR[3];
  37225. var length = diff.length;
  37226. return function constructInterpolatedFromIRResult(src, srcOffset,
  37227. dest, destOffset) {
  37228. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  37229. for (var j = 0; j < length; ++j) {
  37230. dest[destOffset + j] = c0[j] + (x * diff[j]);
  37231. }
  37232. };
  37233. },
  37234. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  37235. var domain = dict.get('Domain');
  37236. if (!domain) {
  37237. error('No domain');
  37238. }
  37239. var inputSize = domain.length / 2;
  37240. if (inputSize !== 1) {
  37241. error('Bad domain for stiched function');
  37242. }
  37243. var fnRefs = dict.get('Functions');
  37244. var fns = [];
  37245. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  37246. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  37247. }
  37248. var bounds = dict.get('Bounds');
  37249. var encode = dict.get('Encode');
  37250. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  37251. },
  37252. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  37253. var domain = IR[1];
  37254. var bounds = IR[2];
  37255. var encode = IR[3];
  37256. var fnsIR = IR[4];
  37257. var fns = [];
  37258. var tmpBuf = new Float32Array(1);
  37259. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  37260. fns.push(PDFFunction.fromIR(fnsIR[i]));
  37261. }
  37262. return function constructStichedFromIRResult(src, srcOffset,
  37263. dest, destOffset) {
  37264. var clip = function constructStichedFromIRClip(v, min, max) {
  37265. if (v > max) {
  37266. v = max;
  37267. } else if (v < min) {
  37268. v = min;
  37269. }
  37270. return v;
  37271. };
  37272. // clip to domain
  37273. var v = clip(src[srcOffset], domain[0], domain[1]);
  37274. // calulate which bound the value is in
  37275. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  37276. if (v < bounds[i]) {
  37277. break;
  37278. }
  37279. }
  37280. // encode value into domain of function
  37281. var dmin = domain[0];
  37282. if (i > 0) {
  37283. dmin = bounds[i - 1];
  37284. }
  37285. var dmax = domain[1];
  37286. if (i < bounds.length) {
  37287. dmax = bounds[i];
  37288. }
  37289. var rmin = encode[2 * i];
  37290. var rmax = encode[2 * i + 1];
  37291. // Prevent the value from becoming NaN as a result
  37292. // of division by zero (fixes issue6113.pdf).
  37293. tmpBuf[0] = dmin === dmax ? rmin :
  37294. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  37295. // call the appropriate function
  37296. fns[i](tmpBuf, 0, dest, destOffset);
  37297. };
  37298. },
  37299. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  37300. xref) {
  37301. var domain = dict.get('Domain');
  37302. var range = dict.get('Range');
  37303. if (!domain) {
  37304. error('No domain.');
  37305. }
  37306. if (!range) {
  37307. error('No range.');
  37308. }
  37309. var lexer = new PostScriptLexer(fn);
  37310. var parser = new PostScriptParser(lexer);
  37311. var code = parser.parse();
  37312. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  37313. },
  37314. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  37315. IR) {
  37316. var domain = IR[1];
  37317. var range = IR[2];
  37318. var code = IR[3];
  37319. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  37320. if (compiled) {
  37321. // Compiled function consists of simple expressions such as addition,
  37322. // subtraction, Math.max, and also contains 'var' and 'return'
  37323. // statements. See the generation in the PostScriptCompiler below.
  37324. /*jshint -W054 */
  37325. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  37326. }
  37327. info('Unable to compile PS function');
  37328. var numOutputs = range.length >> 1;
  37329. var numInputs = domain.length >> 1;
  37330. var evaluator = new PostScriptEvaluator(code);
  37331. // Cache the values for a big speed up, the cache size is limited though
  37332. // since the number of possible values can be huge from a PS function.
  37333. var cache = {};
  37334. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  37335. // seen in our tests.
  37336. var MAX_CACHE_SIZE = 2048 * 4;
  37337. var cache_available = MAX_CACHE_SIZE;
  37338. var tmpBuf = new Float32Array(numInputs);
  37339. return function constructPostScriptFromIRResult(src, srcOffset,
  37340. dest, destOffset) {
  37341. var i, value;
  37342. var key = '';
  37343. var input = tmpBuf;
  37344. for (i = 0; i < numInputs; i++) {
  37345. value = src[srcOffset + i];
  37346. input[i] = value;
  37347. key += value + '_';
  37348. }
  37349. var cachedValue = cache[key];
  37350. if (cachedValue !== undefined) {
  37351. dest.set(cachedValue, destOffset);
  37352. return;
  37353. }
  37354. var output = new Float32Array(numOutputs);
  37355. var stack = evaluator.execute(input);
  37356. var stackIndex = stack.length - numOutputs;
  37357. for (i = 0; i < numOutputs; i++) {
  37358. value = stack[stackIndex + i];
  37359. var bound = range[i * 2];
  37360. if (value < bound) {
  37361. value = bound;
  37362. } else {
  37363. bound = range[i * 2 +1];
  37364. if (value > bound) {
  37365. value = bound;
  37366. }
  37367. }
  37368. output[i] = value;
  37369. }
  37370. if (cache_available > 0) {
  37371. cache_available--;
  37372. cache[key] = output;
  37373. }
  37374. dest.set(output, destOffset);
  37375. };
  37376. }
  37377. };
  37378. })();
  37379. function isPDFFunction(v) {
  37380. var fnDict;
  37381. if (typeof v !== 'object') {
  37382. return false;
  37383. } else if (isDict(v)) {
  37384. fnDict = v;
  37385. } else if (isStream(v)) {
  37386. fnDict = v.dict;
  37387. } else {
  37388. return false;
  37389. }
  37390. return fnDict.has('FunctionType');
  37391. }
  37392. var PostScriptStack = (function PostScriptStackClosure() {
  37393. var MAX_STACK_SIZE = 100;
  37394. function PostScriptStack(initialStack) {
  37395. this.stack = !initialStack ? [] :
  37396. Array.prototype.slice.call(initialStack, 0);
  37397. }
  37398. PostScriptStack.prototype = {
  37399. push: function PostScriptStack_push(value) {
  37400. if (this.stack.length >= MAX_STACK_SIZE) {
  37401. error('PostScript function stack overflow.');
  37402. }
  37403. this.stack.push(value);
  37404. },
  37405. pop: function PostScriptStack_pop() {
  37406. if (this.stack.length <= 0) {
  37407. error('PostScript function stack underflow.');
  37408. }
  37409. return this.stack.pop();
  37410. },
  37411. copy: function PostScriptStack_copy(n) {
  37412. if (this.stack.length + n >= MAX_STACK_SIZE) {
  37413. error('PostScript function stack overflow.');
  37414. }
  37415. var stack = this.stack;
  37416. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  37417. stack.push(stack[i]);
  37418. }
  37419. },
  37420. index: function PostScriptStack_index(n) {
  37421. this.push(this.stack[this.stack.length - n - 1]);
  37422. },
  37423. // rotate the last n stack elements p times
  37424. roll: function PostScriptStack_roll(n, p) {
  37425. var stack = this.stack;
  37426. var l = stack.length - n;
  37427. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  37428. for (i = l, j = r; i < j; i++, j--) {
  37429. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37430. }
  37431. for (i = l, j = c - 1; i < j; i++, j--) {
  37432. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37433. }
  37434. for (i = c, j = r; i < j; i++, j--) {
  37435. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37436. }
  37437. }
  37438. };
  37439. return PostScriptStack;
  37440. })();
  37441. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  37442. function PostScriptEvaluator(operators) {
  37443. this.operators = operators;
  37444. }
  37445. PostScriptEvaluator.prototype = {
  37446. execute: function PostScriptEvaluator_execute(initialStack) {
  37447. var stack = new PostScriptStack(initialStack);
  37448. var counter = 0;
  37449. var operators = this.operators;
  37450. var length = operators.length;
  37451. var operator, a, b;
  37452. while (counter < length) {
  37453. operator = operators[counter++];
  37454. if (typeof operator === 'number') {
  37455. // Operator is really an operand and should be pushed to the stack.
  37456. stack.push(operator);
  37457. continue;
  37458. }
  37459. switch (operator) {
  37460. // non standard ps operators
  37461. case 'jz': // jump if false
  37462. b = stack.pop();
  37463. a = stack.pop();
  37464. if (!a) {
  37465. counter = b;
  37466. }
  37467. break;
  37468. case 'j': // jump
  37469. a = stack.pop();
  37470. counter = a;
  37471. break;
  37472. // all ps operators in alphabetical order (excluding if/ifelse)
  37473. case 'abs':
  37474. a = stack.pop();
  37475. stack.push(Math.abs(a));
  37476. break;
  37477. case 'add':
  37478. b = stack.pop();
  37479. a = stack.pop();
  37480. stack.push(a + b);
  37481. break;
  37482. case 'and':
  37483. b = stack.pop();
  37484. a = stack.pop();
  37485. if (isBool(a) && isBool(b)) {
  37486. stack.push(a && b);
  37487. } else {
  37488. stack.push(a & b);
  37489. }
  37490. break;
  37491. case 'atan':
  37492. a = stack.pop();
  37493. stack.push(Math.atan(a));
  37494. break;
  37495. case 'bitshift':
  37496. b = stack.pop();
  37497. a = stack.pop();
  37498. if (a > 0) {
  37499. stack.push(a << b);
  37500. } else {
  37501. stack.push(a >> b);
  37502. }
  37503. break;
  37504. case 'ceiling':
  37505. a = stack.pop();
  37506. stack.push(Math.ceil(a));
  37507. break;
  37508. case 'copy':
  37509. a = stack.pop();
  37510. stack.copy(a);
  37511. break;
  37512. case 'cos':
  37513. a = stack.pop();
  37514. stack.push(Math.cos(a));
  37515. break;
  37516. case 'cvi':
  37517. a = stack.pop() | 0;
  37518. stack.push(a);
  37519. break;
  37520. case 'cvr':
  37521. // noop
  37522. break;
  37523. case 'div':
  37524. b = stack.pop();
  37525. a = stack.pop();
  37526. stack.push(a / b);
  37527. break;
  37528. case 'dup':
  37529. stack.copy(1);
  37530. break;
  37531. case 'eq':
  37532. b = stack.pop();
  37533. a = stack.pop();
  37534. stack.push(a === b);
  37535. break;
  37536. case 'exch':
  37537. stack.roll(2, 1);
  37538. break;
  37539. case 'exp':
  37540. b = stack.pop();
  37541. a = stack.pop();
  37542. stack.push(Math.pow(a, b));
  37543. break;
  37544. case 'false':
  37545. stack.push(false);
  37546. break;
  37547. case 'floor':
  37548. a = stack.pop();
  37549. stack.push(Math.floor(a));
  37550. break;
  37551. case 'ge':
  37552. b = stack.pop();
  37553. a = stack.pop();
  37554. stack.push(a >= b);
  37555. break;
  37556. case 'gt':
  37557. b = stack.pop();
  37558. a = stack.pop();
  37559. stack.push(a > b);
  37560. break;
  37561. case 'idiv':
  37562. b = stack.pop();
  37563. a = stack.pop();
  37564. stack.push((a / b) | 0);
  37565. break;
  37566. case 'index':
  37567. a = stack.pop();
  37568. stack.index(a);
  37569. break;
  37570. case 'le':
  37571. b = stack.pop();
  37572. a = stack.pop();
  37573. stack.push(a <= b);
  37574. break;
  37575. case 'ln':
  37576. a = stack.pop();
  37577. stack.push(Math.log(a));
  37578. break;
  37579. case 'log':
  37580. a = stack.pop();
  37581. stack.push(Math.log(a) / Math.LN10);
  37582. break;
  37583. case 'lt':
  37584. b = stack.pop();
  37585. a = stack.pop();
  37586. stack.push(a < b);
  37587. break;
  37588. case 'mod':
  37589. b = stack.pop();
  37590. a = stack.pop();
  37591. stack.push(a % b);
  37592. break;
  37593. case 'mul':
  37594. b = stack.pop();
  37595. a = stack.pop();
  37596. stack.push(a * b);
  37597. break;
  37598. case 'ne':
  37599. b = stack.pop();
  37600. a = stack.pop();
  37601. stack.push(a !== b);
  37602. break;
  37603. case 'neg':
  37604. a = stack.pop();
  37605. stack.push(-a);
  37606. break;
  37607. case 'not':
  37608. a = stack.pop();
  37609. if (isBool(a)) {
  37610. stack.push(!a);
  37611. } else {
  37612. stack.push(~a);
  37613. }
  37614. break;
  37615. case 'or':
  37616. b = stack.pop();
  37617. a = stack.pop();
  37618. if (isBool(a) && isBool(b)) {
  37619. stack.push(a || b);
  37620. } else {
  37621. stack.push(a | b);
  37622. }
  37623. break;
  37624. case 'pop':
  37625. stack.pop();
  37626. break;
  37627. case 'roll':
  37628. b = stack.pop();
  37629. a = stack.pop();
  37630. stack.roll(a, b);
  37631. break;
  37632. case 'round':
  37633. a = stack.pop();
  37634. stack.push(Math.round(a));
  37635. break;
  37636. case 'sin':
  37637. a = stack.pop();
  37638. stack.push(Math.sin(a));
  37639. break;
  37640. case 'sqrt':
  37641. a = stack.pop();
  37642. stack.push(Math.sqrt(a));
  37643. break;
  37644. case 'sub':
  37645. b = stack.pop();
  37646. a = stack.pop();
  37647. stack.push(a - b);
  37648. break;
  37649. case 'true':
  37650. stack.push(true);
  37651. break;
  37652. case 'truncate':
  37653. a = stack.pop();
  37654. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  37655. stack.push(a);
  37656. break;
  37657. case 'xor':
  37658. b = stack.pop();
  37659. a = stack.pop();
  37660. if (isBool(a) && isBool(b)) {
  37661. stack.push(a !== b);
  37662. } else {
  37663. stack.push(a ^ b);
  37664. }
  37665. break;
  37666. default:
  37667. error('Unknown operator ' + operator);
  37668. break;
  37669. }
  37670. }
  37671. return stack.stack;
  37672. }
  37673. };
  37674. return PostScriptEvaluator;
  37675. })();
  37676. // Most of the PDFs functions consist of simple operations such as:
  37677. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  37678. //
  37679. // We can compile most of such programs, and at the same moment, we can
  37680. // optimize some expressions using basic math properties. Keeping track of
  37681. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  37682. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  37683. function AstNode(type) {
  37684. this.type = type;
  37685. }
  37686. AstNode.prototype.visit = function (visitor) {
  37687. throw new Error('abstract method');
  37688. };
  37689. function AstArgument(index, min, max) {
  37690. AstNode.call(this, 'args');
  37691. this.index = index;
  37692. this.min = min;
  37693. this.max = max;
  37694. }
  37695. AstArgument.prototype = Object.create(AstNode.prototype);
  37696. AstArgument.prototype.visit = function (visitor) {
  37697. visitor.visitArgument(this);
  37698. };
  37699. function AstLiteral(number) {
  37700. AstNode.call(this, 'literal');
  37701. this.number = number;
  37702. this.min = number;
  37703. this.max = number;
  37704. }
  37705. AstLiteral.prototype = Object.create(AstNode.prototype);
  37706. AstLiteral.prototype.visit = function (visitor) {
  37707. visitor.visitLiteral(this);
  37708. };
  37709. function AstBinaryOperation(op, arg1, arg2, min, max) {
  37710. AstNode.call(this, 'binary');
  37711. this.op = op;
  37712. this.arg1 = arg1;
  37713. this.arg2 = arg2;
  37714. this.min = min;
  37715. this.max = max;
  37716. }
  37717. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  37718. AstBinaryOperation.prototype.visit = function (visitor) {
  37719. visitor.visitBinaryOperation(this);
  37720. };
  37721. function AstMin(arg, max) {
  37722. AstNode.call(this, 'max');
  37723. this.arg = arg;
  37724. this.min = arg.min;
  37725. this.max = max;
  37726. }
  37727. AstMin.prototype = Object.create(AstNode.prototype);
  37728. AstMin.prototype.visit = function (visitor) {
  37729. visitor.visitMin(this);
  37730. };
  37731. function AstVariable(index, min, max) {
  37732. AstNode.call(this, 'var');
  37733. this.index = index;
  37734. this.min = min;
  37735. this.max = max;
  37736. }
  37737. AstVariable.prototype = Object.create(AstNode.prototype);
  37738. AstVariable.prototype.visit = function (visitor) {
  37739. visitor.visitVariable(this);
  37740. };
  37741. function AstVariableDefinition(variable, arg) {
  37742. AstNode.call(this, 'definition');
  37743. this.variable = variable;
  37744. this.arg = arg;
  37745. }
  37746. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  37747. AstVariableDefinition.prototype.visit = function (visitor) {
  37748. visitor.visitVariableDefinition(this);
  37749. };
  37750. function ExpressionBuilderVisitor() {
  37751. this.parts = [];
  37752. }
  37753. ExpressionBuilderVisitor.prototype = {
  37754. visitArgument: function (arg) {
  37755. this.parts.push('Math.max(', arg.min, ', Math.min(',
  37756. arg.max, ', src[srcOffset + ', arg.index, ']))');
  37757. },
  37758. visitVariable: function (variable) {
  37759. this.parts.push('v', variable.index);
  37760. },
  37761. visitLiteral: function (literal) {
  37762. this.parts.push(literal.number);
  37763. },
  37764. visitBinaryOperation: function (operation) {
  37765. this.parts.push('(');
  37766. operation.arg1.visit(this);
  37767. this.parts.push(' ', operation.op, ' ');
  37768. operation.arg2.visit(this);
  37769. this.parts.push(')');
  37770. },
  37771. visitVariableDefinition: function (definition) {
  37772. this.parts.push('var ');
  37773. definition.variable.visit(this);
  37774. this.parts.push(' = ');
  37775. definition.arg.visit(this);
  37776. this.parts.push(';');
  37777. },
  37778. visitMin: function (max) {
  37779. this.parts.push('Math.min(');
  37780. max.arg.visit(this);
  37781. this.parts.push(', ', max.max, ')');
  37782. },
  37783. toString: function () {
  37784. return this.parts.join('');
  37785. }
  37786. };
  37787. function buildAddOperation(num1, num2) {
  37788. if (num2.type === 'literal' && num2.number === 0) {
  37789. // optimization: second operand is 0
  37790. return num1;
  37791. }
  37792. if (num1.type === 'literal' && num1.number === 0) {
  37793. // optimization: first operand is 0
  37794. return num2;
  37795. }
  37796. if (num2.type === 'literal' && num1.type === 'literal') {
  37797. // optimization: operands operand are literals
  37798. return new AstLiteral(num1.number + num2.number);
  37799. }
  37800. return new AstBinaryOperation('+', num1, num2,
  37801. num1.min + num2.min, num1.max + num2.max);
  37802. }
  37803. function buildMulOperation(num1, num2) {
  37804. if (num2.type === 'literal') {
  37805. // optimization: second operands is a literal...
  37806. if (num2.number === 0) {
  37807. return new AstLiteral(0); // and it's 0
  37808. } else if (num2.number === 1) {
  37809. return num1; // and it's 1
  37810. } else if (num1.type === 'literal') {
  37811. // ... and first operands is a literal too
  37812. return new AstLiteral(num1.number * num2.number);
  37813. }
  37814. }
  37815. if (num1.type === 'literal') {
  37816. // optimization: first operands is a literal...
  37817. if (num1.number === 0) {
  37818. return new AstLiteral(0); // and it's 0
  37819. } else if (num1.number === 1) {
  37820. return num2; // and it's 1
  37821. }
  37822. }
  37823. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  37824. num1.max * num2.min, num1.max * num2.max);
  37825. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  37826. num1.max * num2.min, num1.max * num2.max);
  37827. return new AstBinaryOperation('*', num1, num2, min, max);
  37828. }
  37829. function buildSubOperation(num1, num2) {
  37830. if (num2.type === 'literal') {
  37831. // optimization: second operands is a literal...
  37832. if (num2.number === 0) {
  37833. return num1; // ... and it's 0
  37834. } else if (num1.type === 'literal') {
  37835. // ... and first operands is a literal too
  37836. return new AstLiteral(num1.number - num2.number);
  37837. }
  37838. }
  37839. if (num2.type === 'binary' && num2.op === '-' &&
  37840. num1.type === 'literal' && num1.number === 1 &&
  37841. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  37842. // optimization for case: 1 - (1 - x)
  37843. return num2.arg2;
  37844. }
  37845. return new AstBinaryOperation('-', num1, num2,
  37846. num1.min - num2.max, num1.max - num2.min);
  37847. }
  37848. function buildMinOperation(num1, max) {
  37849. if (num1.min >= max) {
  37850. // optimization: num1 min value is not less than required max
  37851. return new AstLiteral(max); // just returning max
  37852. } else if (num1.max <= max) {
  37853. // optimization: num1 max value is not greater than required max
  37854. return num1; // just returning an argument
  37855. }
  37856. return new AstMin(num1, max);
  37857. }
  37858. function PostScriptCompiler() {}
  37859. PostScriptCompiler.prototype = {
  37860. compile: function PostScriptCompiler_compile(code, domain, range) {
  37861. var stack = [];
  37862. var i, ii;
  37863. var instructions = [];
  37864. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  37865. var lastRegister = 0;
  37866. var n, j;
  37867. var num1, num2, ast1, ast2, tmpVar, item;
  37868. for (i = 0; i < inputSize; i++) {
  37869. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  37870. }
  37871. for (i = 0, ii = code.length; i < ii; i++) {
  37872. item = code[i];
  37873. if (typeof item === 'number') {
  37874. stack.push(new AstLiteral(item));
  37875. continue;
  37876. }
  37877. switch (item) {
  37878. case 'add':
  37879. if (stack.length < 2) {
  37880. return null;
  37881. }
  37882. num2 = stack.pop();
  37883. num1 = stack.pop();
  37884. stack.push(buildAddOperation(num1, num2));
  37885. break;
  37886. case 'cvr':
  37887. if (stack.length < 1) {
  37888. return null;
  37889. }
  37890. break;
  37891. case 'mul':
  37892. if (stack.length < 2) {
  37893. return null;
  37894. }
  37895. num2 = stack.pop();
  37896. num1 = stack.pop();
  37897. stack.push(buildMulOperation(num1, num2));
  37898. break;
  37899. case 'sub':
  37900. if (stack.length < 2) {
  37901. return null;
  37902. }
  37903. num2 = stack.pop();
  37904. num1 = stack.pop();
  37905. stack.push(buildSubOperation(num1, num2));
  37906. break;
  37907. case 'exch':
  37908. if (stack.length < 2) {
  37909. return null;
  37910. }
  37911. ast1 = stack.pop(); ast2 = stack.pop();
  37912. stack.push(ast1, ast2);
  37913. break;
  37914. case 'pop':
  37915. if (stack.length < 1) {
  37916. return null;
  37917. }
  37918. stack.pop();
  37919. break;
  37920. case 'index':
  37921. if (stack.length < 1) {
  37922. return null;
  37923. }
  37924. num1 = stack.pop();
  37925. if (num1.type !== 'literal') {
  37926. return null;
  37927. }
  37928. n = num1.number;
  37929. if (n < 0 || (n|0) !== n || stack.length < n) {
  37930. return null;
  37931. }
  37932. ast1 = stack[stack.length - n - 1];
  37933. if (ast1.type === 'literal' || ast1.type === 'var') {
  37934. stack.push(ast1);
  37935. break;
  37936. }
  37937. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37938. stack[stack.length - n - 1] = tmpVar;
  37939. stack.push(tmpVar);
  37940. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37941. break;
  37942. case 'dup':
  37943. if (stack.length < 1) {
  37944. return null;
  37945. }
  37946. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  37947. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  37948. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  37949. // special case of the commands sequence for the min operation
  37950. num1 = stack.pop();
  37951. stack.push(buildMinOperation(num1, code[i + 1]));
  37952. i += 6;
  37953. break;
  37954. }
  37955. ast1 = stack[stack.length - 1];
  37956. if (ast1.type === 'literal' || ast1.type === 'var') {
  37957. // we don't have to save into intermediate variable a literal or
  37958. // variable.
  37959. stack.push(ast1);
  37960. break;
  37961. }
  37962. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37963. stack[stack.length - 1] = tmpVar;
  37964. stack.push(tmpVar);
  37965. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37966. break;
  37967. case 'roll':
  37968. if (stack.length < 2) {
  37969. return null;
  37970. }
  37971. num2 = stack.pop();
  37972. num1 = stack.pop();
  37973. if (num2.type !== 'literal' || num1.type !== 'literal') {
  37974. // both roll operands must be numbers
  37975. return null;
  37976. }
  37977. j = num2.number;
  37978. n = num1.number;
  37979. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  37980. // ... and integers
  37981. return null;
  37982. }
  37983. j = ((j % n) + n) % n;
  37984. if (j === 0) {
  37985. break; // just skipping -- there are nothing to rotate
  37986. }
  37987. Array.prototype.push.apply(stack,
  37988. stack.splice(stack.length - n, n - j));
  37989. break;
  37990. default:
  37991. return null; // unsupported operator
  37992. }
  37993. }
  37994. if (stack.length !== outputSize) {
  37995. return null;
  37996. }
  37997. var result = [];
  37998. instructions.forEach(function (instruction) {
  37999. var statementBuilder = new ExpressionBuilderVisitor();
  38000. instruction.visit(statementBuilder);
  38001. result.push(statementBuilder.toString());
  38002. });
  38003. stack.forEach(function (expr, i) {
  38004. var statementBuilder = new ExpressionBuilderVisitor();
  38005. expr.visit(statementBuilder);
  38006. var min = range[i * 2], max = range[i * 2 + 1];
  38007. var out = [statementBuilder.toString()];
  38008. if (min > expr.min) {
  38009. out.unshift('Math.max(', min, ', ');
  38010. out.push(')');
  38011. }
  38012. if (max < expr.max) {
  38013. out.unshift('Math.min(', max, ', ');
  38014. out.push(')');
  38015. }
  38016. out.unshift('dest[destOffset + ', i, '] = ');
  38017. out.push(';');
  38018. result.push(out.join(''));
  38019. });
  38020. return result.join('\n');
  38021. }
  38022. };
  38023. return PostScriptCompiler;
  38024. })();
  38025. exports.isPDFFunction = isPDFFunction;
  38026. exports.PDFFunction = PDFFunction;
  38027. exports.PostScriptEvaluator = PostScriptEvaluator;
  38028. exports.PostScriptCompiler = PostScriptCompiler;
  38029. }));
  38030. (function (root, factory) {
  38031. {
  38032. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38033. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  38034. }
  38035. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  38036. coreStream) {
  38037. var error = sharedUtil.error;
  38038. var info = sharedUtil.info;
  38039. var isArray = sharedUtil.isArray;
  38040. var isString = sharedUtil.isString;
  38041. var shadow = sharedUtil.shadow;
  38042. var warn = sharedUtil.warn;
  38043. var isDict = corePrimitives.isDict;
  38044. var isName = corePrimitives.isName;
  38045. var isStream = corePrimitives.isStream;
  38046. var PDFFunction = coreFunction.PDFFunction;
  38047. var coreImage; // see _setCoreImage below
  38048. var PDFImage; // = coreImage.PDFImage;
  38049. var ColorSpace = (function ColorSpaceClosure() {
  38050. // Constructor should define this.numComps, this.defaultColor, this.name
  38051. function ColorSpace() {
  38052. error('should not call ColorSpace constructor');
  38053. }
  38054. ColorSpace.prototype = {
  38055. /**
  38056. * Converts the color value to the RGB color. The color components are
  38057. * located in the src array starting from the srcOffset. Returns the array
  38058. * of the rgb components, each value ranging from [0,255].
  38059. */
  38060. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38061. var rgb = new Uint8Array(3);
  38062. this.getRgbItem(src, srcOffset, rgb, 0);
  38063. return rgb;
  38064. },
  38065. /**
  38066. * Converts the color value to the RGB color, similar to the getRgb method.
  38067. * The result placed into the dest array starting from the destOffset.
  38068. */
  38069. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38070. dest, destOffset) {
  38071. error('Should not call ColorSpace.getRgbItem');
  38072. },
  38073. /**
  38074. * Converts the specified number of the color values to the RGB colors.
  38075. * The colors are located in the src array starting from the srcOffset.
  38076. * The result is placed into the dest array starting from the destOffset.
  38077. * The src array items shall be in [0,2^bits) range, the dest array items
  38078. * will be in [0,255] range. alpha01 indicates how many alpha components
  38079. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38080. * array).
  38081. */
  38082. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38083. dest, destOffset, bits,
  38084. alpha01) {
  38085. error('Should not call ColorSpace.getRgbBuffer');
  38086. },
  38087. /**
  38088. * Determines the number of bytes required to store the result of the
  38089. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38090. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38091. */
  38092. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38093. alpha01) {
  38094. error('Should not call ColorSpace.getOutputLength');
  38095. },
  38096. /**
  38097. * Returns true if source data will be equal the result/output data.
  38098. */
  38099. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38100. return false;
  38101. },
  38102. /**
  38103. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38104. * how many alpha components there are in the dest array; it will be either
  38105. * 0 (RGB array) or 1 (RGBA array).
  38106. */
  38107. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38108. originalHeight, width, height,
  38109. actualHeight, bpc, comps, alpha01) {
  38110. var count = originalWidth * originalHeight;
  38111. var rgbBuf = null;
  38112. var numComponentColors = 1 << bpc;
  38113. var needsResizing = originalHeight !== height || originalWidth !== width;
  38114. var i, ii;
  38115. if (this.isPassthrough(bpc)) {
  38116. rgbBuf = comps;
  38117. } else if (this.numComps === 1 && count > numComponentColors &&
  38118. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38119. // Optimization: create a color map when there is just one component and
  38120. // we are converting more colors than the size of the color map. We
  38121. // don't build the map if the colorspace is gray or rgb since those
  38122. // methods are faster than building a map. This mainly offers big speed
  38123. // ups for indexed and alternate colorspaces.
  38124. //
  38125. // TODO it may be worth while to cache the color map. While running
  38126. // testing I never hit a cache so I will leave that out for now (perhaps
  38127. // we are reparsing colorspaces too much?).
  38128. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38129. new Uint16Array(numComponentColors);
  38130. var key;
  38131. for (i = 0; i < numComponentColors; i++) {
  38132. allColors[i] = i;
  38133. }
  38134. var colorMap = new Uint8Array(numComponentColors * 3);
  38135. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38136. /* alpha01 = */ 0);
  38137. var destPos, rgbPos;
  38138. if (!needsResizing) {
  38139. // Fill in the RGB values directly into |dest|.
  38140. destPos = 0;
  38141. for (i = 0; i < count; ++i) {
  38142. key = comps[i] * 3;
  38143. dest[destPos++] = colorMap[key];
  38144. dest[destPos++] = colorMap[key + 1];
  38145. dest[destPos++] = colorMap[key + 2];
  38146. destPos += alpha01;
  38147. }
  38148. } else {
  38149. rgbBuf = new Uint8Array(count * 3);
  38150. rgbPos = 0;
  38151. for (i = 0; i < count; ++i) {
  38152. key = comps[i] * 3;
  38153. rgbBuf[rgbPos++] = colorMap[key];
  38154. rgbBuf[rgbPos++] = colorMap[key + 1];
  38155. rgbBuf[rgbPos++] = colorMap[key + 2];
  38156. }
  38157. }
  38158. } else {
  38159. if (!needsResizing) {
  38160. // Fill in the RGB values directly into |dest|.
  38161. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38162. alpha01);
  38163. } else {
  38164. rgbBuf = new Uint8Array(count * 3);
  38165. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38166. /* alpha01 = */ 0);
  38167. }
  38168. }
  38169. if (rgbBuf) {
  38170. if (needsResizing) {
  38171. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  38172. height, dest, alpha01);
  38173. } else {
  38174. rgbPos = 0;
  38175. destPos = 0;
  38176. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38177. dest[destPos++] = rgbBuf[rgbPos++];
  38178. dest[destPos++] = rgbBuf[rgbPos++];
  38179. dest[destPos++] = rgbBuf[rgbPos++];
  38180. destPos += alpha01;
  38181. }
  38182. }
  38183. }
  38184. },
  38185. /**
  38186. * True if the colorspace has components in the default range of [0, 1].
  38187. * This should be true for all colorspaces except for lab color spaces
  38188. * which are [0,100], [-128, 127], [-128, 127].
  38189. */
  38190. usesZeroToOneRange: true
  38191. };
  38192. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38193. var IR = ColorSpace.parseToIR(cs, xref, res);
  38194. if (IR instanceof AlternateCS) {
  38195. return IR;
  38196. }
  38197. return ColorSpace.fromIR(IR);
  38198. };
  38199. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38200. var name = isArray(IR) ? IR[0] : IR;
  38201. var whitePoint, blackPoint, gamma;
  38202. switch (name) {
  38203. case 'DeviceGrayCS':
  38204. return this.singletons.gray;
  38205. case 'DeviceRgbCS':
  38206. return this.singletons.rgb;
  38207. case 'DeviceCmykCS':
  38208. return this.singletons.cmyk;
  38209. case 'CalGrayCS':
  38210. whitePoint = IR[1].WhitePoint;
  38211. blackPoint = IR[1].BlackPoint;
  38212. gamma = IR[1].Gamma;
  38213. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38214. case 'CalRGBCS':
  38215. whitePoint = IR[1].WhitePoint;
  38216. blackPoint = IR[1].BlackPoint;
  38217. gamma = IR[1].Gamma;
  38218. var matrix = IR[1].Matrix;
  38219. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38220. case 'PatternCS':
  38221. var basePatternCS = IR[1];
  38222. if (basePatternCS) {
  38223. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38224. }
  38225. return new PatternCS(basePatternCS);
  38226. case 'IndexedCS':
  38227. var baseIndexedCS = IR[1];
  38228. var hiVal = IR[2];
  38229. var lookup = IR[3];
  38230. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38231. case 'AlternateCS':
  38232. var numComps = IR[1];
  38233. var alt = IR[2];
  38234. var tintFnIR = IR[3];
  38235. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38236. PDFFunction.fromIR(tintFnIR));
  38237. case 'LabCS':
  38238. whitePoint = IR[1].WhitePoint;
  38239. blackPoint = IR[1].BlackPoint;
  38240. var range = IR[1].Range;
  38241. return new LabCS(whitePoint, blackPoint, range);
  38242. default:
  38243. error('Unknown name ' + name);
  38244. }
  38245. return null;
  38246. };
  38247. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38248. if (isName(cs)) {
  38249. var colorSpaces = res.get('ColorSpace');
  38250. if (isDict(colorSpaces)) {
  38251. var refcs = colorSpaces.get(cs.name);
  38252. if (refcs) {
  38253. cs = refcs;
  38254. }
  38255. }
  38256. }
  38257. cs = xref.fetchIfRef(cs);
  38258. var mode;
  38259. if (isName(cs)) {
  38260. mode = cs.name;
  38261. this.mode = mode;
  38262. switch (mode) {
  38263. case 'DeviceGray':
  38264. case 'G':
  38265. return 'DeviceGrayCS';
  38266. case 'DeviceRGB':
  38267. case 'RGB':
  38268. return 'DeviceRgbCS';
  38269. case 'DeviceCMYK':
  38270. case 'CMYK':
  38271. return 'DeviceCmykCS';
  38272. case 'Pattern':
  38273. return ['PatternCS', null];
  38274. default:
  38275. error('unrecognized colorspace ' + mode);
  38276. }
  38277. } else if (isArray(cs)) {
  38278. mode = xref.fetchIfRef(cs[0]).name;
  38279. this.mode = mode;
  38280. var numComps, params, alt;
  38281. switch (mode) {
  38282. case 'DeviceGray':
  38283. case 'G':
  38284. return 'DeviceGrayCS';
  38285. case 'DeviceRGB':
  38286. case 'RGB':
  38287. return 'DeviceRgbCS';
  38288. case 'DeviceCMYK':
  38289. case 'CMYK':
  38290. return 'DeviceCmykCS';
  38291. case 'CalGray':
  38292. params = xref.fetchIfRef(cs[1]).getAll();
  38293. return ['CalGrayCS', params];
  38294. case 'CalRGB':
  38295. params = xref.fetchIfRef(cs[1]).getAll();
  38296. return ['CalRGBCS', params];
  38297. case 'ICCBased':
  38298. var stream = xref.fetchIfRef(cs[1]);
  38299. var dict = stream.dict;
  38300. numComps = dict.get('N');
  38301. alt = dict.get('Alternate');
  38302. if (alt) {
  38303. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38304. // Parse the /Alternate CS to ensure that the number of components
  38305. // are correct, and also (indirectly) that it is not a PatternCS.
  38306. var altCS = ColorSpace.fromIR(altIR);
  38307. if (altCS.numComps === numComps) {
  38308. return altIR;
  38309. }
  38310. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38311. }
  38312. if (numComps === 1) {
  38313. return 'DeviceGrayCS';
  38314. } else if (numComps === 3) {
  38315. return 'DeviceRgbCS';
  38316. } else if (numComps === 4) {
  38317. return 'DeviceCmykCS';
  38318. }
  38319. break;
  38320. case 'Pattern':
  38321. var basePatternCS = cs[1] || null;
  38322. if (basePatternCS) {
  38323. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38324. }
  38325. return ['PatternCS', basePatternCS];
  38326. case 'Indexed':
  38327. case 'I':
  38328. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38329. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38330. var lookup = xref.fetchIfRef(cs[3]);
  38331. if (isStream(lookup)) {
  38332. lookup = lookup.getBytes();
  38333. }
  38334. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38335. case 'Separation':
  38336. case 'DeviceN':
  38337. var name = xref.fetchIfRef(cs[1]);
  38338. numComps = 1;
  38339. if (isName(name)) {
  38340. numComps = 1;
  38341. } else if (isArray(name)) {
  38342. numComps = name.length;
  38343. }
  38344. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38345. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38346. return ['AlternateCS', numComps, alt, tintFnIR];
  38347. case 'Lab':
  38348. params = xref.fetchIfRef(cs[1]).getAll();
  38349. return ['LabCS', params];
  38350. default:
  38351. error('unimplemented color space object "' + mode + '"');
  38352. }
  38353. } else {
  38354. error('unrecognized color space object: "' + cs + '"');
  38355. }
  38356. return null;
  38357. };
  38358. /**
  38359. * Checks if a decode map matches the default decode map for a color space.
  38360. * This handles the general decode maps where there are two values per
  38361. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38362. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38363. * slightly different.
  38364. * @param {Array} decode Decode map (usually from an image).
  38365. * @param {Number} n Number of components the color space has.
  38366. */
  38367. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38368. if (!isArray(decode)) {
  38369. return true;
  38370. }
  38371. if (n * 2 !== decode.length) {
  38372. warn('The decode map is not the correct length');
  38373. return true;
  38374. }
  38375. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38376. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38377. return false;
  38378. }
  38379. }
  38380. return true;
  38381. };
  38382. ColorSpace.singletons = {
  38383. get gray() {
  38384. return shadow(this, 'gray', new DeviceGrayCS());
  38385. },
  38386. get rgb() {
  38387. return shadow(this, 'rgb', new DeviceRgbCS());
  38388. },
  38389. get cmyk() {
  38390. return shadow(this, 'cmyk', new DeviceCmykCS());
  38391. }
  38392. };
  38393. return ColorSpace;
  38394. })();
  38395. /**
  38396. * Alternate color space handles both Separation and DeviceN color spaces. A
  38397. * Separation color space is actually just a DeviceN with one color component.
  38398. * Both color spaces use a tinting function to convert colors to a base color
  38399. * space.
  38400. */
  38401. var AlternateCS = (function AlternateCSClosure() {
  38402. function AlternateCS(numComps, base, tintFn) {
  38403. this.name = 'Alternate';
  38404. this.numComps = numComps;
  38405. this.defaultColor = new Float32Array(numComps);
  38406. for (var i = 0; i < numComps; ++i) {
  38407. this.defaultColor[i] = 1;
  38408. }
  38409. this.base = base;
  38410. this.tintFn = tintFn;
  38411. this.tmpBuf = new Float32Array(base.numComps);
  38412. }
  38413. AlternateCS.prototype = {
  38414. getRgb: ColorSpace.prototype.getRgb,
  38415. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38416. dest, destOffset) {
  38417. var tmpBuf = this.tmpBuf;
  38418. this.tintFn(src, srcOffset, tmpBuf, 0);
  38419. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38420. },
  38421. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38422. dest, destOffset, bits,
  38423. alpha01) {
  38424. var tintFn = this.tintFn;
  38425. var base = this.base;
  38426. var scale = 1 / ((1 << bits) - 1);
  38427. var baseNumComps = base.numComps;
  38428. var usesZeroToOneRange = base.usesZeroToOneRange;
  38429. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38430. alpha01 === 0;
  38431. var pos = isPassthrough ? destOffset : 0;
  38432. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38433. var numComps = this.numComps;
  38434. var scaled = new Float32Array(numComps);
  38435. var tinted = new Float32Array(baseNumComps);
  38436. var i, j;
  38437. if (usesZeroToOneRange) {
  38438. for (i = 0; i < count; i++) {
  38439. for (j = 0; j < numComps; j++) {
  38440. scaled[j] = src[srcOffset++] * scale;
  38441. }
  38442. tintFn(scaled, 0, tinted, 0);
  38443. for (j = 0; j < baseNumComps; j++) {
  38444. baseBuf[pos++] = tinted[j] * 255;
  38445. }
  38446. }
  38447. } else {
  38448. for (i = 0; i < count; i++) {
  38449. for (j = 0; j < numComps; j++) {
  38450. scaled[j] = src[srcOffset++] * scale;
  38451. }
  38452. tintFn(scaled, 0, tinted, 0);
  38453. base.getRgbItem(tinted, 0, baseBuf, pos);
  38454. pos += baseNumComps;
  38455. }
  38456. }
  38457. if (!isPassthrough) {
  38458. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38459. }
  38460. },
  38461. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38462. alpha01) {
  38463. return this.base.getOutputLength(inputLength *
  38464. this.base.numComps / this.numComps,
  38465. alpha01);
  38466. },
  38467. isPassthrough: ColorSpace.prototype.isPassthrough,
  38468. fillRgb: ColorSpace.prototype.fillRgb,
  38469. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38470. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38471. },
  38472. usesZeroToOneRange: true
  38473. };
  38474. return AlternateCS;
  38475. })();
  38476. var PatternCS = (function PatternCSClosure() {
  38477. function PatternCS(baseCS) {
  38478. this.name = 'Pattern';
  38479. this.base = baseCS;
  38480. }
  38481. PatternCS.prototype = {};
  38482. return PatternCS;
  38483. })();
  38484. var IndexedCS = (function IndexedCSClosure() {
  38485. function IndexedCS(base, highVal, lookup) {
  38486. this.name = 'Indexed';
  38487. this.numComps = 1;
  38488. this.defaultColor = new Uint8Array([0]);
  38489. this.base = base;
  38490. this.highVal = highVal;
  38491. var baseNumComps = base.numComps;
  38492. var length = baseNumComps * highVal;
  38493. var lookupArray;
  38494. if (isStream(lookup)) {
  38495. lookupArray = new Uint8Array(length);
  38496. var bytes = lookup.getBytes(length);
  38497. lookupArray.set(bytes);
  38498. } else if (isString(lookup)) {
  38499. lookupArray = new Uint8Array(length);
  38500. for (var i = 0; i < length; ++i) {
  38501. lookupArray[i] = lookup.charCodeAt(i);
  38502. }
  38503. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38504. lookupArray = lookup;
  38505. } else {
  38506. error('Unrecognized lookup table: ' + lookup);
  38507. }
  38508. this.lookup = lookupArray;
  38509. }
  38510. IndexedCS.prototype = {
  38511. getRgb: ColorSpace.prototype.getRgb,
  38512. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38513. dest, destOffset) {
  38514. var numComps = this.base.numComps;
  38515. var start = src[srcOffset] * numComps;
  38516. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38517. },
  38518. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38519. dest, destOffset, bits,
  38520. alpha01) {
  38521. var base = this.base;
  38522. var numComps = base.numComps;
  38523. var outputDelta = base.getOutputLength(numComps, alpha01);
  38524. var lookup = this.lookup;
  38525. for (var i = 0; i < count; ++i) {
  38526. var lookupPos = src[srcOffset++] * numComps;
  38527. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38528. destOffset += outputDelta;
  38529. }
  38530. },
  38531. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38532. return this.base.getOutputLength(inputLength * this.base.numComps,
  38533. alpha01);
  38534. },
  38535. isPassthrough: ColorSpace.prototype.isPassthrough,
  38536. fillRgb: ColorSpace.prototype.fillRgb,
  38537. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38538. // indexed color maps shouldn't be changed
  38539. return true;
  38540. },
  38541. usesZeroToOneRange: true
  38542. };
  38543. return IndexedCS;
  38544. })();
  38545. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38546. function DeviceGrayCS() {
  38547. this.name = 'DeviceGray';
  38548. this.numComps = 1;
  38549. this.defaultColor = new Float32Array([0]);
  38550. }
  38551. DeviceGrayCS.prototype = {
  38552. getRgb: ColorSpace.prototype.getRgb,
  38553. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38554. dest, destOffset) {
  38555. var c = (src[srcOffset] * 255) | 0;
  38556. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38557. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38558. },
  38559. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38560. dest, destOffset, bits,
  38561. alpha01) {
  38562. var scale = 255 / ((1 << bits) - 1);
  38563. var j = srcOffset, q = destOffset;
  38564. for (var i = 0; i < count; ++i) {
  38565. var c = (scale * src[j++]) | 0;
  38566. dest[q++] = c;
  38567. dest[q++] = c;
  38568. dest[q++] = c;
  38569. q += alpha01;
  38570. }
  38571. },
  38572. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38573. alpha01) {
  38574. return inputLength * (3 + alpha01);
  38575. },
  38576. isPassthrough: ColorSpace.prototype.isPassthrough,
  38577. fillRgb: ColorSpace.prototype.fillRgb,
  38578. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38579. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38580. },
  38581. usesZeroToOneRange: true
  38582. };
  38583. return DeviceGrayCS;
  38584. })();
  38585. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38586. function DeviceRgbCS() {
  38587. this.name = 'DeviceRGB';
  38588. this.numComps = 3;
  38589. this.defaultColor = new Float32Array([0, 0, 0]);
  38590. }
  38591. DeviceRgbCS.prototype = {
  38592. getRgb: ColorSpace.prototype.getRgb,
  38593. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38594. dest, destOffset) {
  38595. var r = (src[srcOffset] * 255) | 0;
  38596. var g = (src[srcOffset + 1] * 255) | 0;
  38597. var b = (src[srcOffset + 2] * 255) | 0;
  38598. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38599. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38600. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38601. },
  38602. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38603. dest, destOffset, bits,
  38604. alpha01) {
  38605. if (bits === 8 && alpha01 === 0) {
  38606. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38607. return;
  38608. }
  38609. var scale = 255 / ((1 << bits) - 1);
  38610. var j = srcOffset, q = destOffset;
  38611. for (var i = 0; i < count; ++i) {
  38612. dest[q++] = (scale * src[j++]) | 0;
  38613. dest[q++] = (scale * src[j++]) | 0;
  38614. dest[q++] = (scale * src[j++]) | 0;
  38615. q += alpha01;
  38616. }
  38617. },
  38618. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38619. alpha01) {
  38620. return (inputLength * (3 + alpha01) / 3) | 0;
  38621. },
  38622. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38623. return bits === 8;
  38624. },
  38625. fillRgb: ColorSpace.prototype.fillRgb,
  38626. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38627. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38628. },
  38629. usesZeroToOneRange: true
  38630. };
  38631. return DeviceRgbCS;
  38632. })();
  38633. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38634. // The coefficients below was found using numerical analysis: the method of
  38635. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38636. // where color_value is the tabular value from the table of sampled RGB colors
  38637. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38638. // CMYK color conversion using the estimation below:
  38639. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38640. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38641. var c = src[srcOffset + 0] * srcScale;
  38642. var m = src[srcOffset + 1] * srcScale;
  38643. var y = src[srcOffset + 2] * srcScale;
  38644. var k = src[srcOffset + 3] * srcScale;
  38645. var r =
  38646. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38647. 18.82290502165302 * y + 212.25662451639585 * k +
  38648. -285.2331026137004) +
  38649. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38650. -17.873870861415444 * k - 5.497006427196366) +
  38651. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38652. 17.5119270841813) +
  38653. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38654. var g =
  38655. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38656. 6.871425592049007 * y + 31.159100130055922 * k +
  38657. -79.2970844816548) +
  38658. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38659. 131.35250912493976 * k - 190.9453302588951) +
  38660. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38661. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38662. var b =
  38663. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38664. 30.89978309703729 * y - 0.23883238689178934 * k +
  38665. -14.183576799673286) +
  38666. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38667. 50.606957656360734 * k - 112.23884253719248) +
  38668. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38669. -193.58209356861505) +
  38670. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38671. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38672. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38673. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38674. }
  38675. function DeviceCmykCS() {
  38676. this.name = 'DeviceCMYK';
  38677. this.numComps = 4;
  38678. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38679. }
  38680. DeviceCmykCS.prototype = {
  38681. getRgb: ColorSpace.prototype.getRgb,
  38682. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38683. dest, destOffset) {
  38684. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38685. },
  38686. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38687. dest, destOffset, bits,
  38688. alpha01) {
  38689. var scale = 1 / ((1 << bits) - 1);
  38690. for (var i = 0; i < count; i++) {
  38691. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38692. srcOffset += 4;
  38693. destOffset += 3 + alpha01;
  38694. }
  38695. },
  38696. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38697. alpha01) {
  38698. return (inputLength / 4 * (3 + alpha01)) | 0;
  38699. },
  38700. isPassthrough: ColorSpace.prototype.isPassthrough,
  38701. fillRgb: ColorSpace.prototype.fillRgb,
  38702. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38703. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38704. },
  38705. usesZeroToOneRange: true
  38706. };
  38707. return DeviceCmykCS;
  38708. })();
  38709. //
  38710. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38711. //
  38712. var CalGrayCS = (function CalGrayCSClosure() {
  38713. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38714. this.name = 'CalGray';
  38715. this.numComps = 1;
  38716. this.defaultColor = new Float32Array([0]);
  38717. if (!whitePoint) {
  38718. error('WhitePoint missing - required for color space CalGray');
  38719. }
  38720. blackPoint = blackPoint || [0, 0, 0];
  38721. gamma = gamma || 1;
  38722. // Translate arguments to spec variables.
  38723. this.XW = whitePoint[0];
  38724. this.YW = whitePoint[1];
  38725. this.ZW = whitePoint[2];
  38726. this.XB = blackPoint[0];
  38727. this.YB = blackPoint[1];
  38728. this.ZB = blackPoint[2];
  38729. this.G = gamma;
  38730. // Validate variables as per spec.
  38731. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38732. error('Invalid WhitePoint components for ' + this.name +
  38733. ', no fallback available');
  38734. }
  38735. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38736. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38737. this.XB = this.YB = this.ZB = 0;
  38738. }
  38739. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38740. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38741. ', ZB: ' + this.ZB + ', only default values are supported.');
  38742. }
  38743. if (this.G < 1) {
  38744. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38745. ', falling back to default');
  38746. this.G = 1;
  38747. }
  38748. }
  38749. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38750. // A represents a gray component of a calibrated gray space.
  38751. // A <---> AG in the spec
  38752. var A = src[srcOffset] * scale;
  38753. var AG = Math.pow(A, cs.G);
  38754. // Computes L as per spec. ( = cs.YW * AG )
  38755. // Except if other than default BlackPoint values are used.
  38756. var L = cs.YW * AG;
  38757. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38758. // Convert values to rgb range [0, 255].
  38759. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38760. dest[destOffset] = val;
  38761. dest[destOffset + 1] = val;
  38762. dest[destOffset + 2] = val;
  38763. }
  38764. CalGrayCS.prototype = {
  38765. getRgb: ColorSpace.prototype.getRgb,
  38766. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38767. dest, destOffset) {
  38768. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38769. },
  38770. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38771. dest, destOffset, bits,
  38772. alpha01) {
  38773. var scale = 1 / ((1 << bits) - 1);
  38774. for (var i = 0; i < count; ++i) {
  38775. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38776. srcOffset += 1;
  38777. destOffset += 3 + alpha01;
  38778. }
  38779. },
  38780. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38781. return inputLength * (3 + alpha01);
  38782. },
  38783. isPassthrough: ColorSpace.prototype.isPassthrough,
  38784. fillRgb: ColorSpace.prototype.fillRgb,
  38785. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38786. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38787. },
  38788. usesZeroToOneRange: true
  38789. };
  38790. return CalGrayCS;
  38791. })();
  38792. //
  38793. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38794. //
  38795. var CalRGBCS = (function CalRGBCSClosure() {
  38796. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38797. // matrices.
  38798. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38799. 0.8951, 0.2664, -0.1614,
  38800. -0.7502, 1.7135, 0.0367,
  38801. 0.0389, -0.0685, 1.0296]);
  38802. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38803. 0.9869929, -0.1470543, 0.1599627,
  38804. 0.4323053, 0.5183603, 0.0492912,
  38805. -0.0085287, 0.0400428, 0.9684867]);
  38806. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38807. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38808. 3.2404542, -1.5371385, -0.4985314,
  38809. -0.9692660, 1.8760108, 0.0415560,
  38810. 0.0556434, -0.2040259, 1.0572252]);
  38811. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38812. var tempNormalizeMatrix = new Float32Array(3);
  38813. var tempConvertMatrix1 = new Float32Array(3);
  38814. var tempConvertMatrix2 = new Float32Array(3);
  38815. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38816. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38817. this.name = 'CalRGB';
  38818. this.numComps = 3;
  38819. this.defaultColor = new Float32Array(3);
  38820. if (!whitePoint) {
  38821. error('WhitePoint missing - required for color space CalRGB');
  38822. }
  38823. blackPoint = blackPoint || new Float32Array(3);
  38824. gamma = gamma || new Float32Array([1, 1, 1]);
  38825. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38826. // Translate arguments to spec variables.
  38827. var XW = whitePoint[0];
  38828. var YW = whitePoint[1];
  38829. var ZW = whitePoint[2];
  38830. this.whitePoint = whitePoint;
  38831. var XB = blackPoint[0];
  38832. var YB = blackPoint[1];
  38833. var ZB = blackPoint[2];
  38834. this.blackPoint = blackPoint;
  38835. this.GR = gamma[0];
  38836. this.GG = gamma[1];
  38837. this.GB = gamma[2];
  38838. this.MXA = matrix[0];
  38839. this.MYA = matrix[1];
  38840. this.MZA = matrix[2];
  38841. this.MXB = matrix[3];
  38842. this.MYB = matrix[4];
  38843. this.MZB = matrix[5];
  38844. this.MXC = matrix[6];
  38845. this.MYC = matrix[7];
  38846. this.MZC = matrix[8];
  38847. // Validate variables as per spec.
  38848. if (XW < 0 || ZW < 0 || YW !== 1) {
  38849. error('Invalid WhitePoint components for ' + this.name +
  38850. ', no fallback available');
  38851. }
  38852. if (XB < 0 || YB < 0 || ZB < 0) {
  38853. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38854. ', ' + ZB + '], falling back to default');
  38855. this.blackPoint = new Float32Array(3);
  38856. }
  38857. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38858. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38859. '] for ' + this.name + ', falling back to default');
  38860. this.GR = this.GG = this.GB = 1;
  38861. }
  38862. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38863. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38864. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  38865. info('Invalid Matrix for ' + this.name + ' [' +
  38866. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  38867. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  38868. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  38869. '], falling back to default');
  38870. this.MXA = this.MYB = this.MZC = 1;
  38871. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  38872. }
  38873. }
  38874. function matrixProduct(a, b, result) {
  38875. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  38876. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  38877. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  38878. }
  38879. function convertToFlat(sourceWhitePoint, LMS, result) {
  38880. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  38881. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  38882. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  38883. }
  38884. function convertToD65(sourceWhitePoint, LMS, result) {
  38885. var D65X = 0.95047;
  38886. var D65Y = 1;
  38887. var D65Z = 1.08883;
  38888. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  38889. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  38890. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  38891. }
  38892. function sRGBTransferFunction(color) {
  38893. // See http://en.wikipedia.org/wiki/SRGB.
  38894. if (color <= 0.0031308){
  38895. return adjustToRange(0, 1, 12.92 * color);
  38896. }
  38897. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  38898. }
  38899. function adjustToRange(min, max, value) {
  38900. return Math.max(min, Math.min(max, value));
  38901. }
  38902. function decodeL(L) {
  38903. if (L < 0) {
  38904. return -decodeL(-L);
  38905. }
  38906. if (L > 8.0) {
  38907. return Math.pow(((L + 16) / 116), 3);
  38908. }
  38909. return L * DECODE_L_CONSTANT;
  38910. }
  38911. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  38912. // In case the blackPoint is already the default blackPoint then there is
  38913. // no need to do compensation.
  38914. if (sourceBlackPoint[0] === 0 &&
  38915. sourceBlackPoint[1] === 0 &&
  38916. sourceBlackPoint[2] === 0) {
  38917. result[0] = XYZ_Flat[0];
  38918. result[1] = XYZ_Flat[1];
  38919. result[2] = XYZ_Flat[2];
  38920. return;
  38921. }
  38922. // For the blackPoint calculation details, please see
  38923. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38924. // AdobeBPC.pdf.
  38925. // The destination blackPoint is the default blackPoint [0, 0, 0].
  38926. var zeroDecodeL = decodeL(0);
  38927. var X_DST = zeroDecodeL;
  38928. var X_SRC = decodeL(sourceBlackPoint[0]);
  38929. var Y_DST = zeroDecodeL;
  38930. var Y_SRC = decodeL(sourceBlackPoint[1]);
  38931. var Z_DST = zeroDecodeL;
  38932. var Z_SRC = decodeL(sourceBlackPoint[2]);
  38933. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  38934. var X_Offset = 1 - X_Scale;
  38935. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  38936. var Y_Offset = 1 - Y_Scale;
  38937. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  38938. var Z_Offset = 1 - Z_Scale;
  38939. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  38940. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  38941. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  38942. }
  38943. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  38944. // In case the whitePoint is already flat then there is no need to do
  38945. // normalization.
  38946. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  38947. result[0] = XYZ_In[0];
  38948. result[1] = XYZ_In[1];
  38949. result[2] = XYZ_In[2];
  38950. return;
  38951. }
  38952. var LMS = result;
  38953. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38954. var LMS_Flat = tempNormalizeMatrix;
  38955. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  38956. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  38957. }
  38958. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  38959. var LMS = result;
  38960. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38961. var LMS_D65 = tempNormalizeMatrix;
  38962. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  38963. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  38964. }
  38965. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38966. // A, B and C represent a red, green and blue components of a calibrated
  38967. // rgb space.
  38968. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  38969. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  38970. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  38971. // A <---> AGR in the spec
  38972. // B <---> BGG in the spec
  38973. // C <---> CGB in the spec
  38974. var AGR = Math.pow(A, cs.GR);
  38975. var BGG = Math.pow(B, cs.GG);
  38976. var CGB = Math.pow(C, cs.GB);
  38977. // Computes intermediate variables L, M, N as per spec.
  38978. // To decode X, Y, Z values map L, M, N directly to them.
  38979. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  38980. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  38981. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  38982. // The following calculations are based on this document:
  38983. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38984. // AdobeBPC.pdf.
  38985. var XYZ = tempConvertMatrix1;
  38986. XYZ[0] = X;
  38987. XYZ[1] = Y;
  38988. XYZ[2] = Z;
  38989. var XYZ_Flat = tempConvertMatrix2;
  38990. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  38991. var XYZ_Black = tempConvertMatrix1;
  38992. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  38993. var XYZ_D65 = tempConvertMatrix2;
  38994. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  38995. var SRGB = tempConvertMatrix1;
  38996. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  38997. var sR = sRGBTransferFunction(SRGB[0]);
  38998. var sG = sRGBTransferFunction(SRGB[1]);
  38999. var sB = sRGBTransferFunction(SRGB[2]);
  39000. // Convert the values to rgb range [0, 255].
  39001. dest[destOffset] = Math.round(sR * 255);
  39002. dest[destOffset + 1] = Math.round(sG * 255);
  39003. dest[destOffset + 2] = Math.round(sB * 255);
  39004. }
  39005. CalRGBCS.prototype = {
  39006. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39007. var rgb = new Uint8Array(3);
  39008. this.getRgbItem(src, srcOffset, rgb, 0);
  39009. return rgb;
  39010. },
  39011. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39012. dest, destOffset) {
  39013. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39014. },
  39015. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39016. dest, destOffset, bits,
  39017. alpha01) {
  39018. var scale = 1 / ((1 << bits) - 1);
  39019. for (var i = 0; i < count; ++i) {
  39020. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39021. srcOffset += 3;
  39022. destOffset += 3 + alpha01;
  39023. }
  39024. },
  39025. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39026. return (inputLength * (3 + alpha01) / 3) | 0;
  39027. },
  39028. isPassthrough: ColorSpace.prototype.isPassthrough,
  39029. fillRgb: ColorSpace.prototype.fillRgb,
  39030. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39031. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39032. },
  39033. usesZeroToOneRange: true
  39034. };
  39035. return CalRGBCS;
  39036. })();
  39037. //
  39038. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39039. //
  39040. var LabCS = (function LabCSClosure() {
  39041. function LabCS(whitePoint, blackPoint, range) {
  39042. this.name = 'Lab';
  39043. this.numComps = 3;
  39044. this.defaultColor = new Float32Array([0, 0, 0]);
  39045. if (!whitePoint) {
  39046. error('WhitePoint missing - required for color space Lab');
  39047. }
  39048. blackPoint = blackPoint || [0, 0, 0];
  39049. range = range || [-100, 100, -100, 100];
  39050. // Translate args to spec variables
  39051. this.XW = whitePoint[0];
  39052. this.YW = whitePoint[1];
  39053. this.ZW = whitePoint[2];
  39054. this.amin = range[0];
  39055. this.amax = range[1];
  39056. this.bmin = range[2];
  39057. this.bmax = range[3];
  39058. // These are here just for completeness - the spec doesn't offer any
  39059. // formulas that use BlackPoint in Lab
  39060. this.XB = blackPoint[0];
  39061. this.YB = blackPoint[1];
  39062. this.ZB = blackPoint[2];
  39063. // Validate vars as per spec
  39064. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39065. error('Invalid WhitePoint components, no fallback available');
  39066. }
  39067. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39068. info('Invalid BlackPoint, falling back to default');
  39069. this.XB = this.YB = this.ZB = 0;
  39070. }
  39071. if (this.amin > this.amax || this.bmin > this.bmax) {
  39072. info('Invalid Range, falling back to defaults');
  39073. this.amin = -100;
  39074. this.amax = 100;
  39075. this.bmin = -100;
  39076. this.bmax = 100;
  39077. }
  39078. }
  39079. // Function g(x) from spec
  39080. function fn_g(x) {
  39081. if (x >= 6 / 29) {
  39082. return x * x * x;
  39083. } else {
  39084. return (108 / 841) * (x - 4 / 29);
  39085. }
  39086. }
  39087. function decode(value, high1, low2, high2) {
  39088. return low2 + (value) * (high2 - low2) / (high1);
  39089. }
  39090. // If decoding is needed maxVal should be 2^bits per component - 1.
  39091. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39092. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39093. // not the usual [0, 1]. If a command like setFillColor is used the src
  39094. // values will already be within the correct range. However, if we are
  39095. // converting an image we have to map the values to the correct range given
  39096. // above.
  39097. // Ls,as,bs <---> L*,a*,b* in the spec
  39098. var Ls = src[srcOffset];
  39099. var as = src[srcOffset + 1];
  39100. var bs = src[srcOffset + 2];
  39101. if (maxVal !== false) {
  39102. Ls = decode(Ls, maxVal, 0, 100);
  39103. as = decode(as, maxVal, cs.amin, cs.amax);
  39104. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39105. }
  39106. // Adjust limits of 'as' and 'bs'
  39107. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39108. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39109. // Computes intermediate variables X,Y,Z as per spec
  39110. var M = (Ls + 16) / 116;
  39111. var L = M + (as / 500);
  39112. var N = M - (bs / 200);
  39113. var X = cs.XW * fn_g(L);
  39114. var Y = cs.YW * fn_g(M);
  39115. var Z = cs.ZW * fn_g(N);
  39116. var r, g, b;
  39117. // Using different conversions for D50 and D65 white points,
  39118. // per http://www.color.org/srgb.pdf
  39119. if (cs.ZW < 1) {
  39120. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39121. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39122. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39123. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39124. } else {
  39125. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39126. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39127. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39128. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39129. }
  39130. // clamp color values to [0,1] range then convert to [0,255] range.
  39131. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39132. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39133. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39134. }
  39135. LabCS.prototype = {
  39136. getRgb: ColorSpace.prototype.getRgb,
  39137. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39138. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39139. },
  39140. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39141. dest, destOffset, bits,
  39142. alpha01) {
  39143. var maxVal = (1 << bits) - 1;
  39144. for (var i = 0; i < count; i++) {
  39145. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39146. srcOffset += 3;
  39147. destOffset += 3 + alpha01;
  39148. }
  39149. },
  39150. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39151. return (inputLength * (3 + alpha01) / 3) | 0;
  39152. },
  39153. isPassthrough: ColorSpace.prototype.isPassthrough,
  39154. fillRgb: ColorSpace.prototype.fillRgb,
  39155. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39156. // XXX: Decoding is handled with the lab conversion because of the strange
  39157. // ranges that are used.
  39158. return true;
  39159. },
  39160. usesZeroToOneRange: false
  39161. };
  39162. return LabCS;
  39163. })();
  39164. // TODO refactor to remove dependency on image.js
  39165. function _setCoreImage(coreImage_) {
  39166. coreImage = coreImage_;
  39167. PDFImage = coreImage_.PDFImage;
  39168. }
  39169. exports._setCoreImage = _setCoreImage;
  39170. exports.ColorSpace = ColorSpace;
  39171. // TODO refactor to remove dependency on colorspace.js
  39172. coreStream._setCoreColorSpace(exports);
  39173. }));
  39174. (function (root, factory) {
  39175. {
  39176. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39177. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39178. root.pdfjsCoreJpx);
  39179. }
  39180. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39181. coreStream, coreJpx) {
  39182. var ImageKind = sharedUtil.ImageKind;
  39183. var assert = sharedUtil.assert;
  39184. var error = sharedUtil.error;
  39185. var info = sharedUtil.info;
  39186. var isArray = sharedUtil.isArray;
  39187. var warn = sharedUtil.warn;
  39188. var Name = corePrimitives.Name;
  39189. var isStream = corePrimitives.isStream;
  39190. var ColorSpace = coreColorSpace.ColorSpace;
  39191. var DecodeStream = coreStream.DecodeStream;
  39192. var Stream = coreStream.Stream;
  39193. var JpegStream = coreStream.JpegStream;
  39194. var JpxImage = coreJpx.JpxImage;
  39195. var PDFImage = (function PDFImageClosure() {
  39196. /**
  39197. * Decode the image in the main thread if it supported. Resovles the promise
  39198. * when the image data is ready.
  39199. */
  39200. function handleImageData(handler, xref, res, image) {
  39201. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  39202. // For natively supported jpegs send them to the main thread for decoding.
  39203. var dict = image.dict;
  39204. var colorSpace = dict.get('ColorSpace', 'CS');
  39205. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39206. var numComps = colorSpace.numComps;
  39207. var decodePromise = handler.sendWithPromise('JpegDecode',
  39208. [image.getIR(), numComps]);
  39209. return decodePromise.then(function (message) {
  39210. var data = message.data;
  39211. return new Stream(data, 0, data.length, image.dict);
  39212. });
  39213. } else {
  39214. return Promise.resolve(image);
  39215. }
  39216. }
  39217. /**
  39218. * Decode and clamp a value. The formula is different from the spec because we
  39219. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39220. */
  39221. function decodeAndClamp(value, addend, coefficient, max) {
  39222. value = addend + value * coefficient;
  39223. // Clamp the value to the range
  39224. return (value < 0 ? 0 : (value > max ? max : value));
  39225. }
  39226. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39227. this.image = image;
  39228. var dict = image.dict;
  39229. if (dict.has('Filter')) {
  39230. var filter = dict.get('Filter').name;
  39231. if (filter === 'JPXDecode') {
  39232. var jpxImage = new JpxImage();
  39233. jpxImage.parseImageProperties(image.stream);
  39234. image.stream.reset();
  39235. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39236. image.numComps = jpxImage.componentsCount;
  39237. } else if (filter === 'JBIG2Decode') {
  39238. image.bitsPerComponent = 1;
  39239. image.numComps = 1;
  39240. }
  39241. }
  39242. // TODO cache rendered images?
  39243. this.width = dict.get('Width', 'W');
  39244. this.height = dict.get('Height', 'H');
  39245. if (this.width < 1 || this.height < 1) {
  39246. error('Invalid image width: ' + this.width + ' or height: ' +
  39247. this.height);
  39248. }
  39249. this.interpolate = dict.get('Interpolate', 'I') || false;
  39250. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39251. this.matte = dict.get('Matte') || false;
  39252. var bitsPerComponent = image.bitsPerComponent;
  39253. if (!bitsPerComponent) {
  39254. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39255. if (!bitsPerComponent) {
  39256. if (this.imageMask) {
  39257. bitsPerComponent = 1;
  39258. } else {
  39259. error('Bits per component missing in image: ' + this.imageMask);
  39260. }
  39261. }
  39262. }
  39263. this.bpc = bitsPerComponent;
  39264. if (!this.imageMask) {
  39265. var colorSpace = dict.get('ColorSpace', 'CS');
  39266. if (!colorSpace) {
  39267. info('JPX images (which do not require color spaces)');
  39268. switch (image.numComps) {
  39269. case 1:
  39270. colorSpace = Name.get('DeviceGray');
  39271. break;
  39272. case 3:
  39273. colorSpace = Name.get('DeviceRGB');
  39274. break;
  39275. case 4:
  39276. colorSpace = Name.get('DeviceCMYK');
  39277. break;
  39278. default:
  39279. error('JPX images with ' + this.numComps +
  39280. ' color components not supported.');
  39281. }
  39282. }
  39283. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39284. this.numComps = this.colorSpace.numComps;
  39285. }
  39286. this.decode = dict.get('Decode', 'D');
  39287. this.needsDecode = false;
  39288. if (this.decode &&
  39289. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39290. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39291. this.needsDecode = true;
  39292. // Do some preprocessing to avoid more math.
  39293. var max = (1 << bitsPerComponent) - 1;
  39294. this.decodeCoefficients = [];
  39295. this.decodeAddends = [];
  39296. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39297. var dmin = this.decode[i];
  39298. var dmax = this.decode[i + 1];
  39299. this.decodeCoefficients[j] = dmax - dmin;
  39300. this.decodeAddends[j] = max * dmin;
  39301. }
  39302. }
  39303. if (smask) {
  39304. this.smask = new PDFImage(xref, res, smask, false);
  39305. } else if (mask) {
  39306. if (isStream(mask)) {
  39307. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39308. if (!imageMask) {
  39309. warn('Ignoring /Mask in image without /ImageMask.');
  39310. } else {
  39311. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39312. }
  39313. } else {
  39314. // Color key mask (just an array).
  39315. this.mask = mask;
  39316. }
  39317. }
  39318. }
  39319. /**
  39320. * Handles processing of image data and returns the Promise that is resolved
  39321. * with a PDFImage when the image is ready to be used.
  39322. */
  39323. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39324. res, image, inline) {
  39325. var imagePromise = handleImageData(handler, xref, res, image);
  39326. var smaskPromise;
  39327. var maskPromise;
  39328. var smask = image.dict.get('SMask');
  39329. var mask = image.dict.get('Mask');
  39330. if (smask) {
  39331. smaskPromise = handleImageData(handler, xref, res, smask);
  39332. maskPromise = Promise.resolve(null);
  39333. } else {
  39334. smaskPromise = Promise.resolve(null);
  39335. if (mask) {
  39336. if (isStream(mask)) {
  39337. maskPromise = handleImageData(handler, xref, res, mask);
  39338. } else if (isArray(mask)) {
  39339. maskPromise = Promise.resolve(mask);
  39340. } else {
  39341. warn('Unsupported mask format.');
  39342. maskPromise = Promise.resolve(null);
  39343. }
  39344. } else {
  39345. maskPromise = Promise.resolve(null);
  39346. }
  39347. }
  39348. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39349. function(results) {
  39350. var imageData = results[0];
  39351. var smaskData = results[1];
  39352. var maskData = results[2];
  39353. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39354. });
  39355. };
  39356. /**
  39357. * Resize an image using the nearest neighbor algorithm. Currently only
  39358. * supports one and three component images.
  39359. * @param {TypedArray} pixels The original image with one component.
  39360. * @param {Number} bpc Number of bits per component.
  39361. * @param {Number} components Number of color components, 1 or 3 is supported.
  39362. * @param {Number} w1 Original width.
  39363. * @param {Number} h1 Original height.
  39364. * @param {Number} w2 New width.
  39365. * @param {Number} h2 New height.
  39366. * @param {TypedArray} dest (Optional) The destination buffer.
  39367. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39368. * @return {TypedArray} Resized image data.
  39369. */
  39370. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39371. w1, h1, w2, h2, dest, alpha01) {
  39372. if (components !== 1 && components !== 3) {
  39373. error('Unsupported component count for resizing.');
  39374. }
  39375. var length = w2 * h2 * components;
  39376. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39377. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39378. var xRatio = w1 / w2;
  39379. var yRatio = h1 / h2;
  39380. var i, j, py, newIndex = 0, oldIndex;
  39381. var xScaled = new Uint16Array(w2);
  39382. var w1Scanline = w1 * components;
  39383. if (alpha01 !== 1) {
  39384. alpha01 = 0;
  39385. }
  39386. for (j = 0; j < w2; j++) {
  39387. xScaled[j] = Math.floor(j * xRatio) * components;
  39388. }
  39389. if (components === 1) {
  39390. for (i = 0; i < h2; i++) {
  39391. py = Math.floor(i * yRatio) * w1Scanline;
  39392. for (j = 0; j < w2; j++) {
  39393. oldIndex = py + xScaled[j];
  39394. temp[newIndex++] = pixels[oldIndex];
  39395. }
  39396. }
  39397. } else if (components === 3) {
  39398. for (i = 0; i < h2; i++) {
  39399. py = Math.floor(i * yRatio) * w1Scanline;
  39400. for (j = 0; j < w2; j++) {
  39401. oldIndex = py + xScaled[j];
  39402. temp[newIndex++] = pixels[oldIndex++];
  39403. temp[newIndex++] = pixels[oldIndex++];
  39404. temp[newIndex++] = pixels[oldIndex++];
  39405. newIndex += alpha01;
  39406. }
  39407. }
  39408. }
  39409. return temp;
  39410. };
  39411. PDFImage.createMask =
  39412. function PDFImage_createMask(imgArray, width, height,
  39413. imageIsFromDecodeStream, inverseDecode) {
  39414. // |imgArray| might not contain full data for every pixel of the mask, so
  39415. // we need to distinguish between |computedLength| and |actualLength|.
  39416. // In particular, if inverseDecode is true, then the array we return must
  39417. // have a length of |computedLength|.
  39418. var computedLength = ((width + 7) >> 3) * height;
  39419. var actualLength = imgArray.byteLength;
  39420. var haveFullData = computedLength === actualLength;
  39421. var data, i;
  39422. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39423. // imgArray came from a DecodeStream and its data is in an appropriate
  39424. // form, so we can just transfer it.
  39425. data = imgArray;
  39426. } else if (!inverseDecode) {
  39427. data = new Uint8Array(actualLength);
  39428. data.set(imgArray);
  39429. } else {
  39430. data = new Uint8Array(computedLength);
  39431. data.set(imgArray);
  39432. for (i = actualLength; i < computedLength; i++) {
  39433. data[i] = 0xff;
  39434. }
  39435. }
  39436. // If necessary, invert the original mask data (but not any extra we might
  39437. // have added above). It's safe to modify the array -- whether it's the
  39438. // original or a copy, we're about to transfer it anyway, so nothing else
  39439. // in this thread can be relying on its contents.
  39440. if (inverseDecode) {
  39441. for (i = 0; i < actualLength; i++) {
  39442. data[i] = ~data[i];
  39443. }
  39444. }
  39445. return {data: data, width: width, height: height};
  39446. };
  39447. PDFImage.prototype = {
  39448. get drawWidth() {
  39449. return Math.max(this.width,
  39450. this.smask && this.smask.width || 0,
  39451. this.mask && this.mask.width || 0);
  39452. },
  39453. get drawHeight() {
  39454. return Math.max(this.height,
  39455. this.smask && this.smask.height || 0,
  39456. this.mask && this.mask.height || 0);
  39457. },
  39458. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39459. var bpc = this.bpc;
  39460. var numComps = this.numComps;
  39461. var decodeAddends = this.decodeAddends;
  39462. var decodeCoefficients = this.decodeCoefficients;
  39463. var max = (1 << bpc) - 1;
  39464. var i, ii;
  39465. if (bpc === 1) {
  39466. // If the buffer needed decode that means it just needs to be inverted.
  39467. for (i = 0, ii = buffer.length; i < ii; i++) {
  39468. buffer[i] = +!(buffer[i]);
  39469. }
  39470. return;
  39471. }
  39472. var index = 0;
  39473. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39474. for (var j = 0; j < numComps; j++) {
  39475. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39476. decodeCoefficients[j], max);
  39477. index++;
  39478. }
  39479. }
  39480. },
  39481. getComponents: function PDFImage_getComponents(buffer) {
  39482. var bpc = this.bpc;
  39483. // This image doesn't require any extra work.
  39484. if (bpc === 8) {
  39485. return buffer;
  39486. }
  39487. var width = this.width;
  39488. var height = this.height;
  39489. var numComps = this.numComps;
  39490. var length = width * height * numComps;
  39491. var bufferPos = 0;
  39492. var output = (bpc <= 8 ? new Uint8Array(length) :
  39493. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39494. var rowComps = width * numComps;
  39495. var max = (1 << bpc) - 1;
  39496. var i = 0, ii, buf;
  39497. if (bpc === 1) {
  39498. // Optimization for reading 1 bpc images.
  39499. var mask, loop1End, loop2End;
  39500. for (var j = 0; j < height; j++) {
  39501. loop1End = i + (rowComps & ~7);
  39502. loop2End = i + rowComps;
  39503. // unroll loop for all full bytes
  39504. while (i < loop1End) {
  39505. buf = buffer[bufferPos++];
  39506. output[i] = (buf >> 7) & 1;
  39507. output[i + 1] = (buf >> 6) & 1;
  39508. output[i + 2] = (buf >> 5) & 1;
  39509. output[i + 3] = (buf >> 4) & 1;
  39510. output[i + 4] = (buf >> 3) & 1;
  39511. output[i + 5] = (buf >> 2) & 1;
  39512. output[i + 6] = (buf >> 1) & 1;
  39513. output[i + 7] = buf & 1;
  39514. i += 8;
  39515. }
  39516. // handle remaing bits
  39517. if (i < loop2End) {
  39518. buf = buffer[bufferPos++];
  39519. mask = 128;
  39520. while (i < loop2End) {
  39521. output[i++] = +!!(buf & mask);
  39522. mask >>= 1;
  39523. }
  39524. }
  39525. }
  39526. } else {
  39527. // The general case that handles all other bpc values.
  39528. var bits = 0;
  39529. buf = 0;
  39530. for (i = 0, ii = length; i < ii; ++i) {
  39531. if (i % rowComps === 0) {
  39532. buf = 0;
  39533. bits = 0;
  39534. }
  39535. while (bits < bpc) {
  39536. buf = (buf << 8) | buffer[bufferPos++];
  39537. bits += 8;
  39538. }
  39539. var remainingBits = bits - bpc;
  39540. var value = buf >> remainingBits;
  39541. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39542. buf = buf & ((1 << remainingBits) - 1);
  39543. bits = remainingBits;
  39544. }
  39545. }
  39546. return output;
  39547. },
  39548. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39549. actualHeight, image) {
  39550. var smask = this.smask;
  39551. var mask = this.mask;
  39552. var alphaBuf, sw, sh, i, ii, j;
  39553. if (smask) {
  39554. sw = smask.width;
  39555. sh = smask.height;
  39556. alphaBuf = new Uint8Array(sw * sh);
  39557. smask.fillGrayBuffer(alphaBuf);
  39558. if (sw !== width || sh !== height) {
  39559. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39560. height);
  39561. }
  39562. } else if (mask) {
  39563. if (mask instanceof PDFImage) {
  39564. sw = mask.width;
  39565. sh = mask.height;
  39566. alphaBuf = new Uint8Array(sw * sh);
  39567. mask.numComps = 1;
  39568. mask.fillGrayBuffer(alphaBuf);
  39569. // Need to invert values in rgbaBuf
  39570. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39571. alphaBuf[i] = 255 - alphaBuf[i];
  39572. }
  39573. if (sw !== width || sh !== height) {
  39574. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39575. height);
  39576. }
  39577. } else if (isArray(mask)) {
  39578. // Color key mask: if any of the compontents are outside the range
  39579. // then they should be painted.
  39580. alphaBuf = new Uint8Array(width * height);
  39581. var numComps = this.numComps;
  39582. for (i = 0, ii = width * height; i < ii; ++i) {
  39583. var opacity = 0;
  39584. var imageOffset = i * numComps;
  39585. for (j = 0; j < numComps; ++j) {
  39586. var color = image[imageOffset + j];
  39587. var maskOffset = j * 2;
  39588. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39589. opacity = 255;
  39590. break;
  39591. }
  39592. }
  39593. alphaBuf[i] = opacity;
  39594. }
  39595. } else {
  39596. error('Unknown mask format.');
  39597. }
  39598. }
  39599. if (alphaBuf) {
  39600. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39601. rgbaBuf[j] = alphaBuf[i];
  39602. }
  39603. } else {
  39604. // No mask.
  39605. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39606. rgbaBuf[j] = 255;
  39607. }
  39608. }
  39609. },
  39610. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39611. var matte = this.smask && this.smask.matte;
  39612. if (!matte) {
  39613. return;
  39614. }
  39615. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39616. var matteR = matteRgb[0];
  39617. var matteG = matteRgb[1];
  39618. var matteB = matteRgb[2];
  39619. var length = width * height * 4;
  39620. var r, g, b;
  39621. for (var i = 0; i < length; i += 4) {
  39622. var alpha = buffer[i + 3];
  39623. if (alpha === 0) {
  39624. // according formula we have to get Infinity in all components
  39625. // making it white (typical paper color) should be okay
  39626. buffer[i] = 255;
  39627. buffer[i + 1] = 255;
  39628. buffer[i + 2] = 255;
  39629. continue;
  39630. }
  39631. var k = 255 / alpha;
  39632. r = (buffer[i] - matteR) * k + matteR;
  39633. g = (buffer[i + 1] - matteG) * k + matteG;
  39634. b = (buffer[i + 2] - matteB) * k + matteB;
  39635. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39636. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39637. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39638. }
  39639. },
  39640. createImageData: function PDFImage_createImageData(forceRGBA) {
  39641. var drawWidth = this.drawWidth;
  39642. var drawHeight = this.drawHeight;
  39643. var imgData = { // other fields are filled in below
  39644. width: drawWidth,
  39645. height: drawHeight
  39646. };
  39647. var numComps = this.numComps;
  39648. var originalWidth = this.width;
  39649. var originalHeight = this.height;
  39650. var bpc = this.bpc;
  39651. // Rows start at byte boundary.
  39652. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39653. var imgArray;
  39654. if (!forceRGBA) {
  39655. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39656. // without any complications, we pass a same-sized copy to the main
  39657. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39658. // of memory for many scanned documents. It's also much faster.
  39659. //
  39660. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39661. // complications, we avoid expanding by 1.333x to RGBA form.
  39662. var kind;
  39663. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39664. kind = ImageKind.GRAYSCALE_1BPP;
  39665. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39666. !this.needsDecode) {
  39667. kind = ImageKind.RGB_24BPP;
  39668. }
  39669. if (kind && !this.smask && !this.mask &&
  39670. drawWidth === originalWidth && drawHeight === originalHeight) {
  39671. imgData.kind = kind;
  39672. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39673. // If imgArray came from a DecodeStream, we're safe to transfer it
  39674. // (and thus neuter it) because it will constitute the entire
  39675. // DecodeStream's data. But if it came from a Stream, we need to
  39676. // copy it because it'll only be a portion of the Stream's data, and
  39677. // the rest will be read later on.
  39678. if (this.image instanceof DecodeStream) {
  39679. imgData.data = imgArray;
  39680. } else {
  39681. var newArray = new Uint8Array(imgArray.length);
  39682. newArray.set(imgArray);
  39683. imgData.data = newArray;
  39684. }
  39685. if (this.needsDecode) {
  39686. // Invert the buffer (which must be grayscale if we reached here).
  39687. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39688. var buffer = imgData.data;
  39689. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39690. buffer[i] ^= 0xff;
  39691. }
  39692. }
  39693. return imgData;
  39694. }
  39695. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39696. (this.colorSpace.name === 'DeviceGray' ||
  39697. this.colorSpace.name === 'DeviceRGB' ||
  39698. this.colorSpace.name === 'DeviceCMYK')) {
  39699. imgData.kind = ImageKind.RGB_24BPP;
  39700. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39701. drawWidth, drawHeight, true);
  39702. return imgData;
  39703. }
  39704. }
  39705. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39706. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39707. var actualHeight = 0 | (imgArray.length / rowBytes *
  39708. drawHeight / originalHeight);
  39709. var comps = this.getComponents(imgArray);
  39710. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39711. // more compact RGB_24BPP form if allowable.
  39712. var alpha01, maybeUndoPreblend;
  39713. if (!forceRGBA && !this.smask && !this.mask) {
  39714. imgData.kind = ImageKind.RGB_24BPP;
  39715. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39716. alpha01 = 0;
  39717. maybeUndoPreblend = false;
  39718. } else {
  39719. imgData.kind = ImageKind.RGBA_32BPP;
  39720. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39721. alpha01 = 1;
  39722. maybeUndoPreblend = true;
  39723. // Color key masking (opacity) must be performed before decoding.
  39724. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39725. comps);
  39726. }
  39727. if (this.needsDecode) {
  39728. this.decodeBuffer(comps);
  39729. }
  39730. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39731. drawWidth, drawHeight, actualHeight, bpc, comps,
  39732. alpha01);
  39733. if (maybeUndoPreblend) {
  39734. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39735. }
  39736. return imgData;
  39737. },
  39738. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39739. var numComps = this.numComps;
  39740. if (numComps !== 1) {
  39741. error('Reading gray scale from a color image: ' + numComps);
  39742. }
  39743. var width = this.width;
  39744. var height = this.height;
  39745. var bpc = this.bpc;
  39746. // rows start at byte boundary
  39747. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39748. var imgArray = this.getImageBytes(height * rowBytes);
  39749. var comps = this.getComponents(imgArray);
  39750. var i, length;
  39751. if (bpc === 1) {
  39752. // inline decoding (= inversion) for 1 bpc images
  39753. length = width * height;
  39754. if (this.needsDecode) {
  39755. // invert and scale to {0, 255}
  39756. for (i = 0; i < length; ++i) {
  39757. buffer[i] = (comps[i] - 1) & 255;
  39758. }
  39759. } else {
  39760. // scale to {0, 255}
  39761. for (i = 0; i < length; ++i) {
  39762. buffer[i] = (-comps[i]) & 255;
  39763. }
  39764. }
  39765. return;
  39766. }
  39767. if (this.needsDecode) {
  39768. this.decodeBuffer(comps);
  39769. }
  39770. length = width * height;
  39771. // we aren't using a colorspace so we need to scale the value
  39772. var scale = 255 / ((1 << bpc) - 1);
  39773. for (i = 0; i < length; ++i) {
  39774. buffer[i] = (scale * comps[i]) | 0;
  39775. }
  39776. },
  39777. getImageBytes: function PDFImage_getImageBytes(length,
  39778. drawWidth, drawHeight,
  39779. forceRGB) {
  39780. this.image.reset();
  39781. this.image.drawWidth = drawWidth || this.width;
  39782. this.image.drawHeight = drawHeight || this.height;
  39783. this.image.forceRGB = !!forceRGB;
  39784. return this.image.getBytes(length);
  39785. }
  39786. };
  39787. return PDFImage;
  39788. })();
  39789. exports.PDFImage = PDFImage;
  39790. // TODO refactor to remove dependency on colorspace.js
  39791. coreColorSpace._setCoreImage(exports);
  39792. }));
  39793. (function (root, factory) {
  39794. {
  39795. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  39796. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  39797. root.pdfjsCoreColorSpace);
  39798. }
  39799. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  39800. coreColorSpace) {
  39801. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39802. var MissingDataException = sharedUtil.MissingDataException;
  39803. var Util = sharedUtil.Util;
  39804. var assert = sharedUtil.assert;
  39805. var error = sharedUtil.error;
  39806. var info = sharedUtil.info;
  39807. var warn = sharedUtil.warn;
  39808. var isStream = corePrimitives.isStream;
  39809. var PDFFunction = coreFunction.PDFFunction;
  39810. var ColorSpace = coreColorSpace.ColorSpace;
  39811. var ShadingType = {
  39812. FUNCTION_BASED: 1,
  39813. AXIAL: 2,
  39814. RADIAL: 3,
  39815. FREE_FORM_MESH: 4,
  39816. LATTICE_FORM_MESH: 5,
  39817. COONS_PATCH_MESH: 6,
  39818. TENSOR_PATCH_MESH: 7
  39819. };
  39820. var Pattern = (function PatternClosure() {
  39821. // Constructor should define this.getPattern
  39822. function Pattern() {
  39823. error('should not call Pattern constructor');
  39824. }
  39825. Pattern.prototype = {
  39826. // Input: current Canvas context
  39827. // Output: the appropriate fillStyle or strokeStyle
  39828. getPattern: function Pattern_getPattern(ctx) {
  39829. error('Should not call Pattern.getStyle: ' + ctx);
  39830. }
  39831. };
  39832. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  39833. res, handler) {
  39834. var dict = isStream(shading) ? shading.dict : shading;
  39835. var type = dict.get('ShadingType');
  39836. try {
  39837. switch (type) {
  39838. case ShadingType.AXIAL:
  39839. case ShadingType.RADIAL:
  39840. // Both radial and axial shadings are handled by RadialAxial shading.
  39841. return new Shadings.RadialAxial(dict, matrix, xref, res);
  39842. case ShadingType.FREE_FORM_MESH:
  39843. case ShadingType.LATTICE_FORM_MESH:
  39844. case ShadingType.COONS_PATCH_MESH:
  39845. case ShadingType.TENSOR_PATCH_MESH:
  39846. return new Shadings.Mesh(shading, matrix, xref, res);
  39847. default:
  39848. throw new Error('Unsupported ShadingType: ' + type);
  39849. }
  39850. } catch (ex) {
  39851. if (ex instanceof MissingDataException) {
  39852. throw ex;
  39853. }
  39854. handler.send('UnsupportedFeature',
  39855. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  39856. warn(ex);
  39857. return new Shadings.Dummy();
  39858. }
  39859. };
  39860. return Pattern;
  39861. })();
  39862. var Shadings = {};
  39863. // A small number to offset the first/last color stops so we can insert ones to
  39864. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  39865. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  39866. // internally so we have to go bigger.
  39867. Shadings.SMALL_NUMBER = 1e-2;
  39868. // Radial and axial shading have very similar implementations
  39869. // If needed, the implementations can be broken into two classes
  39870. Shadings.RadialAxial = (function RadialAxialClosure() {
  39871. function RadialAxial(dict, matrix, xref, res) {
  39872. this.matrix = matrix;
  39873. this.coordsArr = dict.get('Coords');
  39874. this.shadingType = dict.get('ShadingType');
  39875. this.type = 'Pattern';
  39876. var cs = dict.get('ColorSpace', 'CS');
  39877. cs = ColorSpace.parse(cs, xref, res);
  39878. this.cs = cs;
  39879. var t0 = 0.0, t1 = 1.0;
  39880. if (dict.has('Domain')) {
  39881. var domainArr = dict.get('Domain');
  39882. t0 = domainArr[0];
  39883. t1 = domainArr[1];
  39884. }
  39885. var extendStart = false, extendEnd = false;
  39886. if (dict.has('Extend')) {
  39887. var extendArr = dict.get('Extend');
  39888. extendStart = extendArr[0];
  39889. extendEnd = extendArr[1];
  39890. }
  39891. if (this.shadingType === ShadingType.RADIAL &&
  39892. (!extendStart || !extendEnd)) {
  39893. // Radial gradient only currently works if either circle is fully within
  39894. // the other circle.
  39895. var x1 = this.coordsArr[0];
  39896. var y1 = this.coordsArr[1];
  39897. var r1 = this.coordsArr[2];
  39898. var x2 = this.coordsArr[3];
  39899. var y2 = this.coordsArr[4];
  39900. var r2 = this.coordsArr[5];
  39901. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  39902. if (r1 <= r2 + distance &&
  39903. r2 <= r1 + distance) {
  39904. warn('Unsupported radial gradient.');
  39905. }
  39906. }
  39907. this.extendStart = extendStart;
  39908. this.extendEnd = extendEnd;
  39909. var fnObj = dict.get('Function');
  39910. var fn = PDFFunction.parseArray(xref, fnObj);
  39911. // 10 samples seems good enough for now, but probably won't work
  39912. // if there are sharp color changes. Ideally, we would implement
  39913. // the spec faithfully and add lossless optimizations.
  39914. var diff = t1 - t0;
  39915. var step = diff / 10;
  39916. var colorStops = this.colorStops = [];
  39917. // Protect against bad domains so we don't end up in an infinte loop below.
  39918. if (t0 >= t1 || step <= 0) {
  39919. // Acrobat doesn't seem to handle these cases so we'll ignore for
  39920. // now.
  39921. info('Bad shading domain.');
  39922. return;
  39923. }
  39924. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  39925. var rgbColor;
  39926. for (var i = t0; i <= t1; i += step) {
  39927. ratio[0] = i;
  39928. fn(ratio, 0, color, 0);
  39929. rgbColor = cs.getRgb(color, 0);
  39930. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  39931. colorStops.push([(i - t0) / diff, cssColor]);
  39932. }
  39933. var background = 'transparent';
  39934. if (dict.has('Background')) {
  39935. rgbColor = cs.getRgb(dict.get('Background'), 0);
  39936. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  39937. }
  39938. if (!extendStart) {
  39939. // Insert a color stop at the front and offset the first real color stop
  39940. // so it doesn't conflict with the one we insert.
  39941. colorStops.unshift([0, background]);
  39942. colorStops[1][0] += Shadings.SMALL_NUMBER;
  39943. }
  39944. if (!extendEnd) {
  39945. // Same idea as above in extendStart but for the end.
  39946. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  39947. colorStops.push([1, background]);
  39948. }
  39949. this.colorStops = colorStops;
  39950. }
  39951. RadialAxial.prototype = {
  39952. getIR: function RadialAxial_getIR() {
  39953. var coordsArr = this.coordsArr;
  39954. var shadingType = this.shadingType;
  39955. var type, p0, p1, r0, r1;
  39956. if (shadingType === ShadingType.AXIAL) {
  39957. p0 = [coordsArr[0], coordsArr[1]];
  39958. p1 = [coordsArr[2], coordsArr[3]];
  39959. r0 = null;
  39960. r1 = null;
  39961. type = 'axial';
  39962. } else if (shadingType === ShadingType.RADIAL) {
  39963. p0 = [coordsArr[0], coordsArr[1]];
  39964. p1 = [coordsArr[3], coordsArr[4]];
  39965. r0 = coordsArr[2];
  39966. r1 = coordsArr[5];
  39967. type = 'radial';
  39968. } else {
  39969. error('getPattern type unknown: ' + shadingType);
  39970. }
  39971. var matrix = this.matrix;
  39972. if (matrix) {
  39973. p0 = Util.applyTransform(p0, matrix);
  39974. p1 = Util.applyTransform(p1, matrix);
  39975. if (shadingType === ShadingType.RADIAL) {
  39976. var scale = Util.singularValueDecompose2dScale(matrix);
  39977. r0 *= scale[0];
  39978. r1 *= scale[1];
  39979. }
  39980. }
  39981. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  39982. }
  39983. };
  39984. return RadialAxial;
  39985. })();
  39986. // All mesh shading. For now, they will be presented as set of the triangles
  39987. // to be drawn on the canvas and rgb color for each vertex.
  39988. Shadings.Mesh = (function MeshClosure() {
  39989. function MeshStreamReader(stream, context) {
  39990. this.stream = stream;
  39991. this.context = context;
  39992. this.buffer = 0;
  39993. this.bufferLength = 0;
  39994. var numComps = context.numComps;
  39995. this.tmpCompsBuf = new Float32Array(numComps);
  39996. var csNumComps = context.colorSpace.numComps;
  39997. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  39998. this.tmpCompsBuf;
  39999. }
  40000. MeshStreamReader.prototype = {
  40001. get hasData() {
  40002. if (this.stream.end) {
  40003. return this.stream.pos < this.stream.end;
  40004. }
  40005. if (this.bufferLength > 0) {
  40006. return true;
  40007. }
  40008. var nextByte = this.stream.getByte();
  40009. if (nextByte < 0) {
  40010. return false;
  40011. }
  40012. this.buffer = nextByte;
  40013. this.bufferLength = 8;
  40014. return true;
  40015. },
  40016. readBits: function MeshStreamReader_readBits(n) {
  40017. var buffer = this.buffer;
  40018. var bufferLength = this.bufferLength;
  40019. if (n === 32) {
  40020. if (bufferLength === 0) {
  40021. return ((this.stream.getByte() << 24) |
  40022. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  40023. this.stream.getByte()) >>> 0;
  40024. }
  40025. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  40026. (this.stream.getByte() << 8) | this.stream.getByte();
  40027. var nextByte = this.stream.getByte();
  40028. this.buffer = nextByte & ((1 << bufferLength) - 1);
  40029. return ((buffer << (8 - bufferLength)) |
  40030. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  40031. }
  40032. if (n === 8 && bufferLength === 0) {
  40033. return this.stream.getByte();
  40034. }
  40035. while (bufferLength < n) {
  40036. buffer = (buffer << 8) | this.stream.getByte();
  40037. bufferLength += 8;
  40038. }
  40039. bufferLength -= n;
  40040. this.bufferLength = bufferLength;
  40041. this.buffer = buffer & ((1 << bufferLength) - 1);
  40042. return buffer >> bufferLength;
  40043. },
  40044. align: function MeshStreamReader_align() {
  40045. this.buffer = 0;
  40046. this.bufferLength = 0;
  40047. },
  40048. readFlag: function MeshStreamReader_readFlag() {
  40049. return this.readBits(this.context.bitsPerFlag);
  40050. },
  40051. readCoordinate: function MeshStreamReader_readCoordinate() {
  40052. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  40053. var xi = this.readBits(bitsPerCoordinate);
  40054. var yi = this.readBits(bitsPerCoordinate);
  40055. var decode = this.context.decode;
  40056. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  40057. 2.3283064365386963e-10; // 2 ^ -32
  40058. return [
  40059. xi * scale * (decode[1] - decode[0]) + decode[0],
  40060. yi * scale * (decode[3] - decode[2]) + decode[2]
  40061. ];
  40062. },
  40063. readComponents: function MeshStreamReader_readComponents() {
  40064. var numComps = this.context.numComps;
  40065. var bitsPerComponent = this.context.bitsPerComponent;
  40066. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  40067. 2.3283064365386963e-10; // 2 ^ -32
  40068. var decode = this.context.decode;
  40069. var components = this.tmpCompsBuf;
  40070. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  40071. var ci = this.readBits(bitsPerComponent);
  40072. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  40073. }
  40074. var color = this.tmpCsCompsBuf;
  40075. if (this.context.colorFn) {
  40076. this.context.colorFn(components, 0, color, 0);
  40077. }
  40078. return this.context.colorSpace.getRgb(color, 0);
  40079. }
  40080. };
  40081. function decodeType4Shading(mesh, reader) {
  40082. var coords = mesh.coords;
  40083. var colors = mesh.colors;
  40084. var operators = [];
  40085. var ps = []; // not maintaining cs since that will match ps
  40086. var verticesLeft = 0; // assuming we have all data to start a new triangle
  40087. while (reader.hasData) {
  40088. var f = reader.readFlag();
  40089. var coord = reader.readCoordinate();
  40090. var color = reader.readComponents();
  40091. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  40092. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  40093. switch (f) {
  40094. case 0:
  40095. verticesLeft = 3;
  40096. break;
  40097. case 1:
  40098. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  40099. verticesLeft = 1;
  40100. break;
  40101. case 2:
  40102. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  40103. verticesLeft = 1;
  40104. break;
  40105. }
  40106. operators.push(f);
  40107. }
  40108. ps.push(coords.length);
  40109. coords.push(coord);
  40110. colors.push(color);
  40111. verticesLeft--;
  40112. reader.align();
  40113. }
  40114. mesh.figures.push({
  40115. type: 'triangles',
  40116. coords: new Int32Array(ps),
  40117. colors: new Int32Array(ps),
  40118. });
  40119. }
  40120. function decodeType5Shading(mesh, reader, verticesPerRow) {
  40121. var coords = mesh.coords;
  40122. var colors = mesh.colors;
  40123. var ps = []; // not maintaining cs since that will match ps
  40124. while (reader.hasData) {
  40125. var coord = reader.readCoordinate();
  40126. var color = reader.readComponents();
  40127. ps.push(coords.length);
  40128. coords.push(coord);
  40129. colors.push(color);
  40130. }
  40131. mesh.figures.push({
  40132. type: 'lattice',
  40133. coords: new Int32Array(ps),
  40134. colors: new Int32Array(ps),
  40135. verticesPerRow: verticesPerRow
  40136. });
  40137. }
  40138. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  40139. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  40140. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  40141. var getB = (function getBClosure() {
  40142. function buildB(count) {
  40143. var lut = [];
  40144. for (var i = 0; i <= count; i++) {
  40145. var t = i / count, t_ = 1 - t;
  40146. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  40147. 3 * t * t * t_, t * t * t]));
  40148. }
  40149. return lut;
  40150. }
  40151. var cache = [];
  40152. return function getB(count) {
  40153. if (!cache[count]) {
  40154. cache[count] = buildB(count);
  40155. }
  40156. return cache[count];
  40157. };
  40158. })();
  40159. function buildFigureFromPatch(mesh, index) {
  40160. var figure = mesh.figures[index];
  40161. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  40162. var coords = mesh.coords, colors = mesh.colors;
  40163. var pi = figure.coords;
  40164. var ci = figure.colors;
  40165. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  40166. coords[pi[12]][0], coords[pi[15]][0]);
  40167. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  40168. coords[pi[12]][1], coords[pi[15]][1]);
  40169. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  40170. coords[pi[12]][0], coords[pi[15]][0]);
  40171. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  40172. coords[pi[12]][1], coords[pi[15]][1]);
  40173. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  40174. (mesh.bounds[2] - mesh.bounds[0]));
  40175. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  40176. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  40177. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  40178. (mesh.bounds[3] - mesh.bounds[1]));
  40179. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  40180. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  40181. var verticesPerRow = splitXBy + 1;
  40182. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  40183. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  40184. var k = 0;
  40185. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  40186. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  40187. c2 = colors[ci[2]], c3 = colors[ci[3]];
  40188. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  40189. for (var row = 0; row <= splitYBy; row++) {
  40190. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  40191. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  40192. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  40193. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  40194. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  40195. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  40196. for (var col = 0; col <= splitXBy; col++, k++) {
  40197. if ((row === 0 || row === splitYBy) &&
  40198. (col === 0 || col === splitXBy)) {
  40199. continue;
  40200. }
  40201. var x = 0, y = 0;
  40202. var q = 0;
  40203. for (var i = 0; i <= 3; i++) {
  40204. for (var j = 0; j <= 3; j++, q++) {
  40205. var m = bRow[row][i] * bCol[col][j];
  40206. x += coords[pi[q]][0] * m;
  40207. y += coords[pi[q]][1] * m;
  40208. }
  40209. }
  40210. figureCoords[k] = coords.length;
  40211. coords.push([x, y]);
  40212. figureColors[k] = colors.length;
  40213. var newColor = new Uint8Array(3);
  40214. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  40215. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  40216. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  40217. colors.push(newColor);
  40218. }
  40219. }
  40220. figureCoords[0] = pi[0];
  40221. figureColors[0] = ci[0];
  40222. figureCoords[splitXBy] = pi[3];
  40223. figureColors[splitXBy] = ci[1];
  40224. figureCoords[verticesPerRow * splitYBy] = pi[12];
  40225. figureColors[verticesPerRow * splitYBy] = ci[2];
  40226. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  40227. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  40228. mesh.figures[index] = {
  40229. type: 'lattice',
  40230. coords: figureCoords,
  40231. colors: figureColors,
  40232. verticesPerRow: verticesPerRow
  40233. };
  40234. }
  40235. function decodeType6Shading(mesh, reader) {
  40236. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  40237. var coords = mesh.coords;
  40238. var colors = mesh.colors;
  40239. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40240. var cs = new Int32Array(4); // c00, c30, c03, c33
  40241. while (reader.hasData) {
  40242. var f = reader.readFlag();
  40243. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  40244. var i, ii;
  40245. var pi = coords.length;
  40246. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  40247. coords.push(reader.readCoordinate());
  40248. }
  40249. var ci = colors.length;
  40250. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40251. colors.push(reader.readComponents());
  40252. }
  40253. var tmp1, tmp2, tmp3, tmp4;
  40254. switch (f) {
  40255. case 0:
  40256. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40257. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  40258. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  40259. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40260. cs[2] = ci + 1; cs[3] = ci + 2;
  40261. cs[0] = ci; cs[1] = ci + 3;
  40262. break;
  40263. case 1:
  40264. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40265. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40266. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40267. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40268. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40269. tmp1 = cs[2]; tmp2 = cs[3];
  40270. cs[2] = tmp2; cs[3] = ci;
  40271. cs[0] = tmp1; cs[1] = ci + 1;
  40272. break;
  40273. case 2:
  40274. tmp1 = ps[15];
  40275. tmp2 = ps[11];
  40276. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40277. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40278. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40279. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40280. tmp1 = cs[3];
  40281. cs[2] = cs[1]; cs[3] = ci;
  40282. cs[0] = tmp1; cs[1] = ci + 1;
  40283. break;
  40284. case 3:
  40285. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40286. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40287. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  40288. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40289. cs[2] = cs[0]; cs[3] = ci;
  40290. cs[0] = cs[1]; cs[1] = ci + 1;
  40291. break;
  40292. }
  40293. // set p11, p12, p21, p22
  40294. ps[5] = coords.length;
  40295. coords.push([
  40296. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  40297. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  40298. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40299. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  40300. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  40301. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  40302. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40303. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  40304. ]);
  40305. ps[6] = coords.length;
  40306. coords.push([
  40307. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  40308. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  40309. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40310. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  40311. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  40312. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  40313. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40314. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  40315. ]);
  40316. ps[9] = coords.length;
  40317. coords.push([
  40318. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  40319. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  40320. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40321. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  40322. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  40323. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  40324. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40325. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  40326. ]);
  40327. ps[10] = coords.length;
  40328. coords.push([
  40329. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  40330. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  40331. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40332. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  40333. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  40334. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  40335. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40336. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  40337. ]);
  40338. mesh.figures.push({
  40339. type: 'patch',
  40340. coords: new Int32Array(ps), // making copies of ps and cs
  40341. colors: new Int32Array(cs)
  40342. });
  40343. }
  40344. }
  40345. function decodeType7Shading(mesh, reader) {
  40346. var coords = mesh.coords;
  40347. var colors = mesh.colors;
  40348. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40349. var cs = new Int32Array(4); // c00, c30, c03, c33
  40350. while (reader.hasData) {
  40351. var f = reader.readFlag();
  40352. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  40353. var i, ii;
  40354. var pi = coords.length;
  40355. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  40356. coords.push(reader.readCoordinate());
  40357. }
  40358. var ci = colors.length;
  40359. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40360. colors.push(reader.readComponents());
  40361. }
  40362. var tmp1, tmp2, tmp3, tmp4;
  40363. switch (f) {
  40364. case 0:
  40365. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40366. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  40367. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  40368. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40369. cs[2] = ci + 1; cs[3] = ci + 2;
  40370. cs[0] = ci; cs[1] = ci + 3;
  40371. break;
  40372. case 1:
  40373. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40374. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40375. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40376. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40377. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40378. tmp1 = cs[2]; tmp2 = cs[3];
  40379. cs[2] = tmp2; cs[3] = ci;
  40380. cs[0] = tmp1; cs[1] = ci + 1;
  40381. break;
  40382. case 2:
  40383. tmp1 = ps[15];
  40384. tmp2 = ps[11];
  40385. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40386. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40387. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40388. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40389. tmp1 = cs[3];
  40390. cs[2] = cs[1]; cs[3] = ci;
  40391. cs[0] = tmp1; cs[1] = ci + 1;
  40392. break;
  40393. case 3:
  40394. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40395. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40396. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40397. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40398. cs[2] = cs[0]; cs[3] = ci;
  40399. cs[0] = cs[1]; cs[1] = ci + 1;
  40400. break;
  40401. }
  40402. mesh.figures.push({
  40403. type: 'patch',
  40404. coords: new Int32Array(ps), // making copies of ps and cs
  40405. colors: new Int32Array(cs)
  40406. });
  40407. }
  40408. }
  40409. function updateBounds(mesh) {
  40410. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  40411. maxX = minX, maxY = minY;
  40412. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  40413. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  40414. minX = minX > x ? x : minX;
  40415. minY = minY > y ? y : minY;
  40416. maxX = maxX < x ? x : maxX;
  40417. maxY = maxY < y ? y : maxY;
  40418. }
  40419. mesh.bounds = [minX, minY, maxX, maxY];
  40420. }
  40421. function packData(mesh) {
  40422. var i, ii, j, jj;
  40423. var coords = mesh.coords;
  40424. var coordsPacked = new Float32Array(coords.length * 2);
  40425. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  40426. var xy = coords[i];
  40427. coordsPacked[j++] = xy[0];
  40428. coordsPacked[j++] = xy[1];
  40429. }
  40430. mesh.coords = coordsPacked;
  40431. var colors = mesh.colors;
  40432. var colorsPacked = new Uint8Array(colors.length * 3);
  40433. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  40434. var c = colors[i];
  40435. colorsPacked[j++] = c[0];
  40436. colorsPacked[j++] = c[1];
  40437. colorsPacked[j++] = c[2];
  40438. }
  40439. mesh.colors = colorsPacked;
  40440. var figures = mesh.figures;
  40441. for (i = 0, ii = figures.length; i < ii; i++) {
  40442. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  40443. for (j = 0, jj = ps.length; j < jj; j++) {
  40444. ps[j] *= 2;
  40445. cs[j] *= 3;
  40446. }
  40447. }
  40448. }
  40449. function Mesh(stream, matrix, xref, res) {
  40450. assert(isStream(stream), 'Mesh data is not a stream');
  40451. var dict = stream.dict;
  40452. this.matrix = matrix;
  40453. this.shadingType = dict.get('ShadingType');
  40454. this.type = 'Pattern';
  40455. this.bbox = dict.get('BBox');
  40456. var cs = dict.get('ColorSpace', 'CS');
  40457. cs = ColorSpace.parse(cs, xref, res);
  40458. this.cs = cs;
  40459. this.background = dict.has('Background') ?
  40460. cs.getRgb(dict.get('Background'), 0) : null;
  40461. var fnObj = dict.get('Function');
  40462. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  40463. this.coords = [];
  40464. this.colors = [];
  40465. this.figures = [];
  40466. var decodeContext = {
  40467. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  40468. bitsPerComponent: dict.get('BitsPerComponent'),
  40469. bitsPerFlag: dict.get('BitsPerFlag'),
  40470. decode: dict.get('Decode'),
  40471. colorFn: fn,
  40472. colorSpace: cs,
  40473. numComps: fn ? 1 : cs.numComps
  40474. };
  40475. var reader = new MeshStreamReader(stream, decodeContext);
  40476. var patchMesh = false;
  40477. switch (this.shadingType) {
  40478. case ShadingType.FREE_FORM_MESH:
  40479. decodeType4Shading(this, reader);
  40480. break;
  40481. case ShadingType.LATTICE_FORM_MESH:
  40482. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  40483. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  40484. decodeType5Shading(this, reader, verticesPerRow);
  40485. break;
  40486. case ShadingType.COONS_PATCH_MESH:
  40487. decodeType6Shading(this, reader);
  40488. patchMesh = true;
  40489. break;
  40490. case ShadingType.TENSOR_PATCH_MESH:
  40491. decodeType7Shading(this, reader);
  40492. patchMesh = true;
  40493. break;
  40494. default:
  40495. error('Unsupported mesh type.');
  40496. break;
  40497. }
  40498. if (patchMesh) {
  40499. // dirty bounds calculation for determining, how dense shall be triangles
  40500. updateBounds(this);
  40501. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  40502. buildFigureFromPatch(this, i);
  40503. }
  40504. }
  40505. // calculate bounds
  40506. updateBounds(this);
  40507. packData(this);
  40508. }
  40509. Mesh.prototype = {
  40510. getIR: function Mesh_getIR() {
  40511. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  40512. this.bounds, this.matrix, this.bbox, this.background];
  40513. }
  40514. };
  40515. return Mesh;
  40516. })();
  40517. Shadings.Dummy = (function DummyClosure() {
  40518. function Dummy() {
  40519. this.type = 'Pattern';
  40520. }
  40521. Dummy.prototype = {
  40522. getIR: function Dummy_getIR() {
  40523. return ['Dummy'];
  40524. }
  40525. };
  40526. return Dummy;
  40527. })();
  40528. function getTilingPatternIR(operatorList, dict, args) {
  40529. var matrix = dict.get('Matrix');
  40530. var bbox = dict.get('BBox');
  40531. var xstep = dict.get('XStep');
  40532. var ystep = dict.get('YStep');
  40533. var paintType = dict.get('PaintType');
  40534. var tilingType = dict.get('TilingType');
  40535. return [
  40536. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  40537. paintType, tilingType
  40538. ];
  40539. }
  40540. exports.Pattern = Pattern;
  40541. exports.getTilingPatternIR = getTilingPatternIR;
  40542. }));
  40543. (function (root, factory) {
  40544. {
  40545. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  40546. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  40547. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  40548. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  40549. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  40550. }
  40551. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  40552. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  40553. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  40554. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  40555. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  40556. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  40557. var ImageKind = sharedUtil.ImageKind;
  40558. var OPS = sharedUtil.OPS;
  40559. var TextRenderingMode = sharedUtil.TextRenderingMode;
  40560. var Util = sharedUtil.Util;
  40561. var assert = sharedUtil.assert;
  40562. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40563. var error = sharedUtil.error;
  40564. var info = sharedUtil.info;
  40565. var isArray = sharedUtil.isArray;
  40566. var isNum = sharedUtil.isNum;
  40567. var isString = sharedUtil.isString;
  40568. var warn = sharedUtil.warn;
  40569. var Dict = corePrimitives.Dict;
  40570. var Name = corePrimitives.Name;
  40571. var isCmd = corePrimitives.isCmd;
  40572. var isDict = corePrimitives.isDict;
  40573. var isName = corePrimitives.isName;
  40574. var isRef = corePrimitives.isRef;
  40575. var isStream = corePrimitives.isStream;
  40576. var DecodeStream = coreStream.DecodeStream;
  40577. var JpegStream = coreStream.JpegStream;
  40578. var Lexer = coreParser.Lexer;
  40579. var Parser = coreParser.Parser;
  40580. var isEOF = coreParser.isEOF;
  40581. var PDFImage = coreImage.PDFImage;
  40582. var ColorSpace = coreColorSpace.ColorSpace;
  40583. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  40584. var Encodings = coreFonts.Encodings;
  40585. var ErrorFont = coreFonts.ErrorFont;
  40586. var FontFlags = coreFonts.FontFlags;
  40587. var Font = coreFonts.Font;
  40588. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  40589. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  40590. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  40591. var getFontType = coreFonts.getFontType;
  40592. var reverseIfRtl = coreFonts.reverseIfRtl;
  40593. var serifFonts = coreFonts.serifFonts;
  40594. var symbolsFonts = coreFonts.symbolsFonts;
  40595. var stdFontMap = coreFonts.stdFontMap;
  40596. var isPDFFunction = coreFunction.isPDFFunction;
  40597. var PDFFunction = coreFunction.PDFFunction;
  40598. var Pattern = corePattern.Pattern;
  40599. var getTilingPatternIR = corePattern.getTilingPatternIR;
  40600. var CMapFactory = coreCMap.CMapFactory;
  40601. var IdentityCMap = coreCMap.IdentityCMap;
  40602. var Metrics = coreMetrics.Metrics;
  40603. var bidi = coreBidi.bidi;
  40604. var PartialEvaluator = (function PartialEvaluatorClosure() {
  40605. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  40606. uniquePrefix, idCounters, fontCache) {
  40607. this.pdfManager = pdfManager;
  40608. this.xref = xref;
  40609. this.handler = handler;
  40610. this.pageIndex = pageIndex;
  40611. this.uniquePrefix = uniquePrefix;
  40612. this.idCounters = idCounters;
  40613. this.fontCache = fontCache;
  40614. }
  40615. // Trying to minimize Date.now() usage and check every 100 time
  40616. var TIME_SLOT_DURATION_MS = 20;
  40617. var CHECK_TIME_EVERY = 100;
  40618. function TimeSlotManager() {
  40619. this.reset();
  40620. }
  40621. TimeSlotManager.prototype = {
  40622. check: function TimeSlotManager_check() {
  40623. if (++this.checked < CHECK_TIME_EVERY) {
  40624. return false;
  40625. }
  40626. this.checked = 0;
  40627. return this.endTime <= Date.now();
  40628. },
  40629. reset: function TimeSlotManager_reset() {
  40630. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  40631. this.checked = 0;
  40632. }
  40633. };
  40634. var deferred = Promise.resolve();
  40635. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  40636. PartialEvaluator.prototype = {
  40637. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  40638. if (!isDict(resources)) {
  40639. return false;
  40640. }
  40641. var processed = Object.create(null);
  40642. if (resources.objId) {
  40643. processed[resources.objId] = true;
  40644. }
  40645. var nodes = [resources];
  40646. while (nodes.length) {
  40647. var key;
  40648. var node = nodes.shift();
  40649. // First check the current resources for blend modes.
  40650. var graphicStates = node.get('ExtGState');
  40651. if (isDict(graphicStates)) {
  40652. graphicStates = graphicStates.getAll();
  40653. for (key in graphicStates) {
  40654. var graphicState = graphicStates[key];
  40655. var bm = graphicState['BM'];
  40656. if (isName(bm) && bm.name !== 'Normal') {
  40657. return true;
  40658. }
  40659. }
  40660. }
  40661. // Descend into the XObjects to look for more resources and blend modes.
  40662. var xObjects = node.get('XObject');
  40663. if (!isDict(xObjects)) {
  40664. continue;
  40665. }
  40666. xObjects = xObjects.getAll();
  40667. for (key in xObjects) {
  40668. var xObject = xObjects[key];
  40669. if (!isStream(xObject)) {
  40670. continue;
  40671. }
  40672. if (xObject.dict.objId) {
  40673. if (processed[xObject.dict.objId]) {
  40674. // stream has objId and is processed already
  40675. continue;
  40676. }
  40677. processed[xObject.dict.objId] = true;
  40678. }
  40679. var xResources = xObject.dict.get('Resources');
  40680. // Checking objId to detect an infinite loop.
  40681. if (isDict(xResources) &&
  40682. (!xResources.objId || !processed[xResources.objId])) {
  40683. nodes.push(xResources);
  40684. if (xResources.objId) {
  40685. processed[xResources.objId] = true;
  40686. }
  40687. }
  40688. }
  40689. }
  40690. return false;
  40691. },
  40692. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  40693. xobj, smask,
  40694. operatorList,
  40695. task,
  40696. initialState) {
  40697. var matrix = xobj.dict.getArray('Matrix');
  40698. var bbox = xobj.dict.getArray('BBox');
  40699. var group = xobj.dict.get('Group');
  40700. if (group) {
  40701. var groupOptions = {
  40702. matrix: matrix,
  40703. bbox: bbox,
  40704. smask: smask,
  40705. isolated: false,
  40706. knockout: false
  40707. };
  40708. var groupSubtype = group.get('S');
  40709. var colorSpace;
  40710. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  40711. groupOptions.isolated = (group.get('I') || false);
  40712. groupOptions.knockout = (group.get('K') || false);
  40713. colorSpace = (group.has('CS') ?
  40714. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  40715. }
  40716. if (smask && smask.backdrop) {
  40717. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  40718. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  40719. }
  40720. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  40721. }
  40722. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  40723. return this.getOperatorList(xobj, task,
  40724. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  40725. then(function () {
  40726. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  40727. if (group) {
  40728. operatorList.addOp(OPS.endGroup, [groupOptions]);
  40729. }
  40730. });
  40731. },
  40732. buildPaintImageXObject:
  40733. function PartialEvaluator_buildPaintImageXObject(resources, image,
  40734. inline, operatorList,
  40735. cacheKey, imageCache) {
  40736. var self = this;
  40737. var dict = image.dict;
  40738. var w = dict.get('Width', 'W');
  40739. var h = dict.get('Height', 'H');
  40740. if (!(w && isNum(w)) || !(h && isNum(h))) {
  40741. warn('Image dimensions are missing, or not numbers.');
  40742. return;
  40743. }
  40744. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  40745. warn('Image exceeded maximum allowed size and was removed.');
  40746. return;
  40747. }
  40748. var imageMask = (dict.get('ImageMask', 'IM') || false);
  40749. var imgData, args;
  40750. if (imageMask) {
  40751. // This depends on a tmpCanvas being filled with the
  40752. // current fillStyle, such that processing the pixel
  40753. // data can't be done here. Instead of creating a
  40754. // complete PDFImage, only read the information needed
  40755. // for later.
  40756. var width = dict.get('Width', 'W');
  40757. var height = dict.get('Height', 'H');
  40758. var bitStrideLength = (width + 7) >> 3;
  40759. var imgArray = image.getBytes(bitStrideLength * height);
  40760. var decode = dict.get('Decode', 'D');
  40761. var inverseDecode = (!!decode && decode[0] > 0);
  40762. imgData = PDFImage.createMask(imgArray, width, height,
  40763. image instanceof DecodeStream,
  40764. inverseDecode);
  40765. imgData.cached = true;
  40766. args = [imgData];
  40767. operatorList.addOp(OPS.paintImageMaskXObject, args);
  40768. if (cacheKey) {
  40769. imageCache[cacheKey] = {
  40770. fn: OPS.paintImageMaskXObject,
  40771. args: args
  40772. };
  40773. }
  40774. return;
  40775. }
  40776. var softMask = (dict.get('SMask', 'SM') || false);
  40777. var mask = (dict.get('Mask') || false);
  40778. var SMALL_IMAGE_DIMENSIONS = 200;
  40779. // Inlining small images into the queue as RGB data
  40780. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  40781. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  40782. var imageObj = new PDFImage(this.xref, resources, image,
  40783. inline, null, null);
  40784. // We force the use of RGBA_32BPP images here, because we can't handle
  40785. // any other kind.
  40786. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  40787. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  40788. return;
  40789. }
  40790. // If there is no imageMask, create the PDFImage and a lot
  40791. // of image processing can be done here.
  40792. var uniquePrefix = (this.uniquePrefix || '');
  40793. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  40794. operatorList.addDependency(objId);
  40795. args = [objId, w, h];
  40796. if (!softMask && !mask && image instanceof JpegStream &&
  40797. image.isNativelySupported(this.xref, resources)) {
  40798. // These JPEGs don't need any more processing so we can just send it.
  40799. operatorList.addOp(OPS.paintJpegXObject, args);
  40800. this.handler.send('obj',
  40801. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  40802. return;
  40803. }
  40804. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  40805. then(function(imageObj) {
  40806. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  40807. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  40808. [imgData.data.buffer]);
  40809. }).then(undefined, function (reason) {
  40810. warn('Unable to decode image: ' + reason);
  40811. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  40812. });
  40813. operatorList.addOp(OPS.paintImageXObject, args);
  40814. if (cacheKey) {
  40815. imageCache[cacheKey] = {
  40816. fn: OPS.paintImageXObject,
  40817. args: args
  40818. };
  40819. }
  40820. },
  40821. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  40822. operatorList, task,
  40823. stateManager) {
  40824. var smaskContent = smask.get('G');
  40825. var smaskOptions = {
  40826. subtype: smask.get('S').name,
  40827. backdrop: smask.get('BC')
  40828. };
  40829. // The SMask might have a alpha/luminosity value transfer function --
  40830. // we will build a map of integer values in range 0..255 to be fast.
  40831. var transferObj = smask.get('TR');
  40832. if (isPDFFunction(transferObj)) {
  40833. var transferFn = PDFFunction.parse(this.xref, transferObj);
  40834. var transferMap = new Uint8Array(256);
  40835. var tmp = new Float32Array(1);
  40836. for (var i = 0; i < 255; i++) {
  40837. tmp[0] = i / 255;
  40838. transferFn(tmp, 0, tmp, 0);
  40839. transferMap[i] = (tmp[0] * 255) | 0;
  40840. }
  40841. smaskOptions.transferMap = transferMap;
  40842. }
  40843. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  40844. operatorList, task, stateManager.state.clone());
  40845. },
  40846. handleTilingType:
  40847. function PartialEvaluator_handleTilingType(fn, args, resources,
  40848. pattern, patternDict,
  40849. operatorList, task) {
  40850. // Create an IR of the pattern code.
  40851. var tilingOpList = new OperatorList();
  40852. // Merge the available resources, to prevent issues when the patternDict
  40853. // is missing some /Resources entries (fixes issue6541.pdf).
  40854. var resourcesArray = [patternDict.get('Resources'), resources];
  40855. var patternResources = Dict.merge(this.xref, resourcesArray);
  40856. return this.getOperatorList(pattern, task, patternResources,
  40857. tilingOpList).then(function () {
  40858. // Add the dependencies to the parent operator list so they are
  40859. // resolved before sub operator list is executed synchronously.
  40860. operatorList.addDependencies(tilingOpList.dependencies);
  40861. operatorList.addOp(fn, getTilingPatternIR({
  40862. fnArray: tilingOpList.fnArray,
  40863. argsArray: tilingOpList.argsArray
  40864. }, patternDict, args));
  40865. });
  40866. },
  40867. handleSetFont:
  40868. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  40869. operatorList, task, state) {
  40870. // TODO(mack): Not needed?
  40871. var fontName;
  40872. if (fontArgs) {
  40873. fontArgs = fontArgs.slice();
  40874. fontName = fontArgs[0].name;
  40875. }
  40876. var self = this;
  40877. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  40878. function (translated) {
  40879. if (!translated.font.isType3Font) {
  40880. return translated;
  40881. }
  40882. return translated.loadType3Data(self, resources, operatorList, task).
  40883. then(function () {
  40884. return translated;
  40885. }, function (reason) {
  40886. // Error in the font data -- sending unsupported feature notification.
  40887. self.handler.send('UnsupportedFeature',
  40888. {featureId: UNSUPPORTED_FEATURES.font});
  40889. return new TranslatedFont('g_font_error',
  40890. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  40891. });
  40892. }).then(function (translated) {
  40893. state.font = translated.font;
  40894. translated.send(self.handler);
  40895. return translated.loadedName;
  40896. });
  40897. },
  40898. handleText: function PartialEvaluator_handleText(chars, state) {
  40899. var font = state.font;
  40900. var glyphs = font.charsToGlyphs(chars);
  40901. var isAddToPathSet = !!(state.textRenderingMode &
  40902. TextRenderingMode.ADD_TO_PATH_FLAG);
  40903. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  40904. var buildPath = function (fontChar) {
  40905. if (!font.renderer.hasBuiltPath(fontChar)) {
  40906. var path = font.renderer.getPathJs(fontChar);
  40907. this.handler.send('commonobj', [
  40908. font.loadedName + '_path_' + fontChar,
  40909. 'FontPath',
  40910. path
  40911. ]);
  40912. }
  40913. }.bind(this);
  40914. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  40915. var glyph = glyphs[i];
  40916. buildPath(glyph.fontChar);
  40917. // If the glyph has an accent we need to build a path for its
  40918. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  40919. var accent = glyph.accent;
  40920. if (accent && accent.fontChar) {
  40921. buildPath(accent.fontChar);
  40922. }
  40923. }
  40924. }
  40925. return glyphs;
  40926. },
  40927. setGState: function PartialEvaluator_setGState(resources, gState,
  40928. operatorList, task,
  40929. xref, stateManager) {
  40930. // This array holds the converted/processed state data.
  40931. var gStateObj = [];
  40932. var gStateMap = gState.map;
  40933. var self = this;
  40934. var promise = Promise.resolve();
  40935. for (var key in gStateMap) {
  40936. var value = gStateMap[key];
  40937. switch (key) {
  40938. case 'Type':
  40939. break;
  40940. case 'LW':
  40941. case 'LC':
  40942. case 'LJ':
  40943. case 'ML':
  40944. case 'D':
  40945. case 'RI':
  40946. case 'FL':
  40947. case 'CA':
  40948. case 'ca':
  40949. gStateObj.push([key, value]);
  40950. break;
  40951. case 'Font':
  40952. promise = promise.then(function () {
  40953. return self.handleSetFont(resources, null, value[0], operatorList,
  40954. task, stateManager.state).
  40955. then(function (loadedName) {
  40956. operatorList.addDependency(loadedName);
  40957. gStateObj.push([key, [loadedName, value[1]]]);
  40958. });
  40959. });
  40960. break;
  40961. case 'BM':
  40962. gStateObj.push([key, value]);
  40963. break;
  40964. case 'SMask':
  40965. if (isName(value) && value.name === 'None') {
  40966. gStateObj.push([key, false]);
  40967. break;
  40968. }
  40969. var dict = xref.fetchIfRef(value);
  40970. if (isDict(dict)) {
  40971. promise = promise.then(function () {
  40972. return self.handleSMask(dict, resources, operatorList,
  40973. task, stateManager);
  40974. });
  40975. gStateObj.push([key, true]);
  40976. } else {
  40977. warn('Unsupported SMask type');
  40978. }
  40979. break;
  40980. // Only generate info log messages for the following since
  40981. // they are unlikely to have a big impact on the rendering.
  40982. case 'OP':
  40983. case 'op':
  40984. case 'OPM':
  40985. case 'BG':
  40986. case 'BG2':
  40987. case 'UCR':
  40988. case 'UCR2':
  40989. case 'TR':
  40990. case 'TR2':
  40991. case 'HT':
  40992. case 'SM':
  40993. case 'SA':
  40994. case 'AIS':
  40995. case 'TK':
  40996. // TODO implement these operators.
  40997. info('graphic state operator ' + key);
  40998. break;
  40999. default:
  41000. info('Unknown graphic state operator ' + key);
  41001. break;
  41002. }
  41003. }
  41004. return promise.then(function () {
  41005. if (gStateObj.length >= 0) {
  41006. operatorList.addOp(OPS.setGState, [gStateObj]);
  41007. }
  41008. });
  41009. },
  41010. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  41011. resources) {
  41012. function errorFont() {
  41013. return Promise.resolve(new TranslatedFont('g_font_error',
  41014. new ErrorFont('Font ' + fontName + ' is not available'), font));
  41015. }
  41016. var fontRef;
  41017. if (font) { // Loading by ref.
  41018. assert(isRef(font));
  41019. fontRef = font;
  41020. } else { // Loading by name.
  41021. var fontRes = resources.get('Font');
  41022. if (fontRes) {
  41023. fontRef = fontRes.getRaw(fontName);
  41024. } else {
  41025. warn('fontRes not available');
  41026. return errorFont();
  41027. }
  41028. }
  41029. if (!fontRef) {
  41030. warn('fontRef not available');
  41031. return errorFont();
  41032. }
  41033. if (this.fontCache.has(fontRef)) {
  41034. return this.fontCache.get(fontRef);
  41035. }
  41036. font = xref.fetchIfRef(fontRef);
  41037. if (!isDict(font)) {
  41038. return errorFont();
  41039. }
  41040. // We are holding font.translated references just for fontRef that are not
  41041. // dictionaries (Dict). See explanation below.
  41042. if (font.translated) {
  41043. return font.translated;
  41044. }
  41045. var fontCapability = createPromiseCapability();
  41046. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  41047. var descriptor = preEvaluatedFont.descriptor;
  41048. var fontID = fontRef.num + '_' + fontRef.gen;
  41049. if (isDict(descriptor)) {
  41050. if (!descriptor.fontAliases) {
  41051. descriptor.fontAliases = Object.create(null);
  41052. }
  41053. var fontAliases = descriptor.fontAliases;
  41054. var hash = preEvaluatedFont.hash;
  41055. if (fontAliases[hash]) {
  41056. var aliasFontRef = fontAliases[hash].aliasRef;
  41057. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  41058. this.fontCache.putAlias(fontRef, aliasFontRef);
  41059. return this.fontCache.get(fontRef);
  41060. }
  41061. }
  41062. if (!fontAliases[hash]) {
  41063. fontAliases[hash] = {
  41064. fontID: Font.getFontID()
  41065. };
  41066. }
  41067. fontAliases[hash].aliasRef = fontRef;
  41068. fontID = fontAliases[hash].fontID;
  41069. }
  41070. // Workaround for bad PDF generators that don't reference fonts
  41071. // properly, i.e. by not using an object identifier.
  41072. // Check if the fontRef is a Dict (as opposed to a standard object),
  41073. // in which case we don't cache the font and instead reference it by
  41074. // fontName in font.loadedName below.
  41075. var fontRefIsDict = isDict(fontRef);
  41076. if (!fontRefIsDict) {
  41077. this.fontCache.put(fontRef, fontCapability.promise);
  41078. }
  41079. // Keep track of each font we translated so the caller can
  41080. // load them asynchronously before calling display on a page.
  41081. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  41082. fontName.replace(/\W/g, '') : fontID);
  41083. font.translated = fontCapability.promise;
  41084. // TODO move promises into translate font
  41085. var translatedPromise;
  41086. try {
  41087. translatedPromise = Promise.resolve(
  41088. this.translateFont(preEvaluatedFont, xref));
  41089. } catch (e) {
  41090. translatedPromise = Promise.reject(e);
  41091. }
  41092. var self = this;
  41093. translatedPromise.then(function (translatedFont) {
  41094. if (translatedFont.fontType !== undefined) {
  41095. var xrefFontStats = xref.stats.fontTypes;
  41096. xrefFontStats[translatedFont.fontType] = true;
  41097. }
  41098. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41099. translatedFont, font));
  41100. }, function (reason) {
  41101. // TODO fontCapability.reject?
  41102. // Error in the font data -- sending unsupported feature notification.
  41103. self.handler.send('UnsupportedFeature',
  41104. {featureId: UNSUPPORTED_FEATURES.font});
  41105. try {
  41106. // error, but it's still nice to have font type reported
  41107. var descriptor = preEvaluatedFont.descriptor;
  41108. var fontFile3 = descriptor && descriptor.get('FontFile3');
  41109. var subtype = fontFile3 && fontFile3.get('Subtype');
  41110. var fontType = getFontType(preEvaluatedFont.type,
  41111. subtype && subtype.name);
  41112. var xrefFontStats = xref.stats.fontTypes;
  41113. xrefFontStats[fontType] = true;
  41114. } catch (ex) { }
  41115. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41116. new ErrorFont(reason instanceof Error ? reason.message : reason),
  41117. font));
  41118. });
  41119. return fontCapability.promise;
  41120. },
  41121. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  41122. var lastIndex = operatorList.length - 1;
  41123. if (!args) {
  41124. args = [];
  41125. }
  41126. if (lastIndex < 0 ||
  41127. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  41128. operatorList.addOp(OPS.constructPath, [[fn], args]);
  41129. } else {
  41130. var opArgs = operatorList.argsArray[lastIndex];
  41131. opArgs[0].push(fn);
  41132. Array.prototype.push.apply(opArgs[1], args);
  41133. }
  41134. },
  41135. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  41136. cs, patterns, resources, task, xref) {
  41137. // compile tiling patterns
  41138. var patternName = args[args.length - 1];
  41139. // SCN/scn applies patterns along with normal colors
  41140. var pattern;
  41141. if (isName(patternName) &&
  41142. (pattern = patterns.get(patternName.name))) {
  41143. var dict = (isStream(pattern) ? pattern.dict : pattern);
  41144. var typeNum = dict.get('PatternType');
  41145. if (typeNum === TILING_PATTERN) {
  41146. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  41147. return this.handleTilingType(fn, color, resources, pattern,
  41148. dict, operatorList, task);
  41149. } else if (typeNum === SHADING_PATTERN) {
  41150. var shading = dict.get('Shading');
  41151. var matrix = dict.get('Matrix');
  41152. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  41153. this.handler);
  41154. operatorList.addOp(fn, pattern.getIR());
  41155. return Promise.resolve();
  41156. } else {
  41157. return Promise.reject('Unknown PatternType: ' + typeNum);
  41158. }
  41159. }
  41160. // TODO shall we fail here?
  41161. operatorList.addOp(fn, args);
  41162. return Promise.resolve();
  41163. },
  41164. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  41165. task,
  41166. resources,
  41167. operatorList,
  41168. initialState) {
  41169. var self = this;
  41170. var xref = this.xref;
  41171. var imageCache = {};
  41172. assert(operatorList);
  41173. resources = (resources || Dict.empty);
  41174. var xobjs = (resources.get('XObject') || Dict.empty);
  41175. var patterns = (resources.get('Pattern') || Dict.empty);
  41176. var stateManager = new StateManager(initialState || new EvalState());
  41177. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41178. var timeSlotManager = new TimeSlotManager();
  41179. return new Promise(function next(resolve, reject) {
  41180. task.ensureNotTerminated();
  41181. timeSlotManager.reset();
  41182. var stop, operation = {}, i, ii, cs;
  41183. while (!(stop = timeSlotManager.check())) {
  41184. // The arguments parsed by read() are used beyond this loop, so we
  41185. // cannot reuse the same array on each iteration. Therefore we pass
  41186. // in |null| as the initial value (see the comment on
  41187. // EvaluatorPreprocessor_read() for why).
  41188. operation.args = null;
  41189. if (!(preprocessor.read(operation))) {
  41190. break;
  41191. }
  41192. var args = operation.args;
  41193. var fn = operation.fn;
  41194. switch (fn | 0) {
  41195. case OPS.paintXObject:
  41196. if (args[0].code) {
  41197. break;
  41198. }
  41199. // eagerly compile XForm objects
  41200. var name = args[0].name;
  41201. if (!name) {
  41202. warn('XObject must be referred to by name.');
  41203. continue;
  41204. }
  41205. if (imageCache[name] !== undefined) {
  41206. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  41207. args = null;
  41208. continue;
  41209. }
  41210. var xobj = xobjs.get(name);
  41211. if (xobj) {
  41212. assert(isStream(xobj), 'XObject should be a stream');
  41213. var type = xobj.dict.get('Subtype');
  41214. assert(isName(type),
  41215. 'XObject should have a Name subtype');
  41216. if (type.name === 'Form') {
  41217. stateManager.save();
  41218. return self.buildFormXObject(resources, xobj, null,
  41219. operatorList, task,
  41220. stateManager.state.clone()).
  41221. then(function () {
  41222. stateManager.restore();
  41223. next(resolve, reject);
  41224. }, reject);
  41225. } else if (type.name === 'Image') {
  41226. self.buildPaintImageXObject(resources, xobj, false,
  41227. operatorList, name, imageCache);
  41228. args = null;
  41229. continue;
  41230. } else if (type.name === 'PS') {
  41231. // PostScript XObjects are unused when viewing documents.
  41232. // See section 4.7.1 of Adobe's PDF reference.
  41233. info('Ignored XObject subtype PS');
  41234. continue;
  41235. } else {
  41236. error('Unhandled XObject subtype ' + type.name);
  41237. }
  41238. }
  41239. break;
  41240. case OPS.setFont:
  41241. var fontSize = args[1];
  41242. // eagerly collect all fonts
  41243. return self.handleSetFont(resources, args, null, operatorList,
  41244. task, stateManager.state).
  41245. then(function (loadedName) {
  41246. operatorList.addDependency(loadedName);
  41247. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  41248. next(resolve, reject);
  41249. }, reject);
  41250. case OPS.endInlineImage:
  41251. var cacheKey = args[0].cacheKey;
  41252. if (cacheKey) {
  41253. var cacheEntry = imageCache[cacheKey];
  41254. if (cacheEntry !== undefined) {
  41255. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  41256. args = null;
  41257. continue;
  41258. }
  41259. }
  41260. self.buildPaintImageXObject(resources, args[0], true,
  41261. operatorList, cacheKey, imageCache);
  41262. args = null;
  41263. continue;
  41264. case OPS.showText:
  41265. args[0] = self.handleText(args[0], stateManager.state);
  41266. break;
  41267. case OPS.showSpacedText:
  41268. var arr = args[0];
  41269. var combinedGlyphs = [];
  41270. var arrLength = arr.length;
  41271. var state = stateManager.state;
  41272. for (i = 0; i < arrLength; ++i) {
  41273. var arrItem = arr[i];
  41274. if (isString(arrItem)) {
  41275. Array.prototype.push.apply(combinedGlyphs,
  41276. self.handleText(arrItem, state));
  41277. } else if (isNum(arrItem)) {
  41278. combinedGlyphs.push(arrItem);
  41279. }
  41280. }
  41281. args[0] = combinedGlyphs;
  41282. fn = OPS.showText;
  41283. break;
  41284. case OPS.nextLineShowText:
  41285. operatorList.addOp(OPS.nextLine);
  41286. args[0] = self.handleText(args[0], stateManager.state);
  41287. fn = OPS.showText;
  41288. break;
  41289. case OPS.nextLineSetSpacingShowText:
  41290. operatorList.addOp(OPS.nextLine);
  41291. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  41292. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  41293. args[0] = self.handleText(args[0], stateManager.state);
  41294. fn = OPS.showText;
  41295. break;
  41296. case OPS.setTextRenderingMode:
  41297. stateManager.state.textRenderingMode = args[0];
  41298. break;
  41299. case OPS.setFillColorSpace:
  41300. stateManager.state.fillColorSpace =
  41301. ColorSpace.parse(args[0], xref, resources);
  41302. continue;
  41303. case OPS.setStrokeColorSpace:
  41304. stateManager.state.strokeColorSpace =
  41305. ColorSpace.parse(args[0], xref, resources);
  41306. continue;
  41307. case OPS.setFillColor:
  41308. cs = stateManager.state.fillColorSpace;
  41309. args = cs.getRgb(args, 0);
  41310. fn = OPS.setFillRGBColor;
  41311. break;
  41312. case OPS.setStrokeColor:
  41313. cs = stateManager.state.strokeColorSpace;
  41314. args = cs.getRgb(args, 0);
  41315. fn = OPS.setStrokeRGBColor;
  41316. break;
  41317. case OPS.setFillGray:
  41318. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  41319. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41320. fn = OPS.setFillRGBColor;
  41321. break;
  41322. case OPS.setStrokeGray:
  41323. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  41324. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41325. fn = OPS.setStrokeRGBColor;
  41326. break;
  41327. case OPS.setFillCMYKColor:
  41328. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  41329. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41330. fn = OPS.setFillRGBColor;
  41331. break;
  41332. case OPS.setStrokeCMYKColor:
  41333. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  41334. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41335. fn = OPS.setStrokeRGBColor;
  41336. break;
  41337. case OPS.setFillRGBColor:
  41338. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  41339. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41340. break;
  41341. case OPS.setStrokeRGBColor:
  41342. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  41343. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41344. break;
  41345. case OPS.setFillColorN:
  41346. cs = stateManager.state.fillColorSpace;
  41347. if (cs.name === 'Pattern') {
  41348. return self.handleColorN(operatorList, OPS.setFillColorN,
  41349. args, cs, patterns, resources, task, xref).then(function() {
  41350. next(resolve, reject);
  41351. }, reject);
  41352. }
  41353. args = cs.getRgb(args, 0);
  41354. fn = OPS.setFillRGBColor;
  41355. break;
  41356. case OPS.setStrokeColorN:
  41357. cs = stateManager.state.strokeColorSpace;
  41358. if (cs.name === 'Pattern') {
  41359. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  41360. args, cs, patterns, resources, task, xref).then(function() {
  41361. next(resolve, reject);
  41362. }, reject);
  41363. }
  41364. args = cs.getRgb(args, 0);
  41365. fn = OPS.setStrokeRGBColor;
  41366. break;
  41367. case OPS.shadingFill:
  41368. var shadingRes = resources.get('Shading');
  41369. if (!shadingRes) {
  41370. error('No shading resource found');
  41371. }
  41372. var shading = shadingRes.get(args[0].name);
  41373. if (!shading) {
  41374. error('No shading object found');
  41375. }
  41376. var shadingFill = Pattern.parseShading(shading, null, xref,
  41377. resources, self.handler);
  41378. var patternIR = shadingFill.getIR();
  41379. args = [patternIR];
  41380. fn = OPS.shadingFill;
  41381. break;
  41382. case OPS.setGState:
  41383. var dictName = args[0];
  41384. var extGState = resources.get('ExtGState');
  41385. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41386. break;
  41387. }
  41388. var gState = extGState.get(dictName.name);
  41389. return self.setGState(resources, gState, operatorList, task,
  41390. xref, stateManager).then(function() {
  41391. next(resolve, reject);
  41392. }, reject);
  41393. case OPS.moveTo:
  41394. case OPS.lineTo:
  41395. case OPS.curveTo:
  41396. case OPS.curveTo2:
  41397. case OPS.curveTo3:
  41398. case OPS.closePath:
  41399. self.buildPath(operatorList, fn, args);
  41400. continue;
  41401. case OPS.rectangle:
  41402. self.buildPath(operatorList, fn, args);
  41403. continue;
  41404. case OPS.markPoint:
  41405. case OPS.markPointProps:
  41406. case OPS.beginMarkedContent:
  41407. case OPS.beginMarkedContentProps:
  41408. case OPS.endMarkedContent:
  41409. case OPS.beginCompat:
  41410. case OPS.endCompat:
  41411. // Ignore operators where the corresponding handlers are known to
  41412. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  41413. // serialization errors and is also a bit more efficient.
  41414. // We could also try to serialize all objects in a general way,
  41415. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  41416. // but doing so is meaningless without knowing the semantics.
  41417. continue;
  41418. default:
  41419. // Note: Let's hope that the ignored operator does not have any
  41420. // non-serializable arguments, otherwise postMessage will throw
  41421. // "An object could not be cloned.".
  41422. }
  41423. operatorList.addOp(fn, args);
  41424. }
  41425. if (stop) {
  41426. deferred.then(function () {
  41427. next(resolve, reject);
  41428. }, reject);
  41429. return;
  41430. }
  41431. // Some PDFs don't close all restores inside object/form.
  41432. // Closing those for them.
  41433. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  41434. operatorList.addOp(OPS.restore, []);
  41435. }
  41436. resolve();
  41437. });
  41438. },
  41439. getTextContent:
  41440. function PartialEvaluator_getTextContent(stream, task, resources,
  41441. stateManager,
  41442. normalizeWhitespace) {
  41443. stateManager = (stateManager || new StateManager(new TextState()));
  41444. var WhitespaceRegexp = /\s/g;
  41445. var textContent = {
  41446. items: [],
  41447. styles: Object.create(null)
  41448. };
  41449. var textContentItem = {
  41450. initialized: false,
  41451. str: [],
  41452. width: 0,
  41453. height: 0,
  41454. vertical: false,
  41455. lastAdvanceWidth: 0,
  41456. lastAdvanceHeight: 0,
  41457. textAdvanceScale: 0,
  41458. spaceWidth: 0,
  41459. fakeSpaceMin: Infinity,
  41460. fakeMultiSpaceMin: Infinity,
  41461. fakeMultiSpaceMax: -0,
  41462. textRunBreakAllowed: false,
  41463. transform: null,
  41464. fontName: null
  41465. };
  41466. var SPACE_FACTOR = 0.3;
  41467. var MULTI_SPACE_FACTOR = 1.5;
  41468. var MULTI_SPACE_FACTOR_MAX = 4;
  41469. var self = this;
  41470. var xref = this.xref;
  41471. resources = (xref.fetchIfRef(resources) || Dict.empty);
  41472. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  41473. var xobjs = null;
  41474. var xobjsCache = {};
  41475. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41476. var textState;
  41477. function ensureTextContentItem() {
  41478. if (textContentItem.initialized) {
  41479. return textContentItem;
  41480. }
  41481. var font = textState.font;
  41482. if (!(font.loadedName in textContent.styles)) {
  41483. textContent.styles[font.loadedName] = {
  41484. fontFamily: font.fallbackName,
  41485. ascent: font.ascent,
  41486. descent: font.descent,
  41487. vertical: font.vertical
  41488. };
  41489. }
  41490. textContentItem.fontName = font.loadedName;
  41491. // 9.4.4 Text Space Details
  41492. var tsm = [textState.fontSize * textState.textHScale, 0,
  41493. 0, textState.fontSize,
  41494. 0, textState.textRise];
  41495. if (font.isType3Font &&
  41496. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  41497. textState.fontSize === 1) {
  41498. var glyphHeight = font.bbox[3] - font.bbox[1];
  41499. if (glyphHeight > 0) {
  41500. glyphHeight = glyphHeight * textState.fontMatrix[3];
  41501. tsm[3] *= glyphHeight;
  41502. }
  41503. }
  41504. var trm = Util.transform(textState.ctm,
  41505. Util.transform(textState.textMatrix, tsm));
  41506. textContentItem.transform = trm;
  41507. if (!font.vertical) {
  41508. textContentItem.width = 0;
  41509. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  41510. textContentItem.vertical = false;
  41511. } else {
  41512. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  41513. textContentItem.height = 0;
  41514. textContentItem.vertical = true;
  41515. }
  41516. var a = textState.textLineMatrix[0];
  41517. var b = textState.textLineMatrix[1];
  41518. var scaleLineX = Math.sqrt(a * a + b * b);
  41519. a = textState.ctm[0];
  41520. b = textState.ctm[1];
  41521. var scaleCtmX = Math.sqrt(a * a + b * b);
  41522. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  41523. textContentItem.lastAdvanceWidth = 0;
  41524. textContentItem.lastAdvanceHeight = 0;
  41525. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  41526. if (spaceWidth) {
  41527. textContentItem.spaceWidth = spaceWidth;
  41528. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  41529. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  41530. textContentItem.fakeMultiSpaceMax =
  41531. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  41532. // It's okay for monospace fonts to fake as much space as needed.
  41533. textContentItem.textRunBreakAllowed = !font.isMonospace;
  41534. } else {
  41535. textContentItem.spaceWidth = 0;
  41536. textContentItem.fakeSpaceMin = Infinity;
  41537. textContentItem.fakeMultiSpaceMin = Infinity;
  41538. textContentItem.fakeMultiSpaceMax = 0;
  41539. textContentItem.textRunBreakAllowed = false;
  41540. }
  41541. textContentItem.initialized = true;
  41542. return textContentItem;
  41543. }
  41544. function replaceWhitespace(str) {
  41545. // Replaces all whitespaces with standard spaces (0x20), to avoid
  41546. // alignment issues between the textLayer and the canvas if the text
  41547. // contains e.g. tabs (fixes issue6612.pdf).
  41548. var i = 0, ii = str.length, code;
  41549. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  41550. i++;
  41551. }
  41552. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  41553. }
  41554. function runBidiTransform(textChunk) {
  41555. var str = textChunk.str.join('');
  41556. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  41557. return {
  41558. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  41559. bidiResult.str),
  41560. dir: bidiResult.dir,
  41561. width: textChunk.width,
  41562. height: textChunk.height,
  41563. transform: textChunk.transform,
  41564. fontName: textChunk.fontName
  41565. };
  41566. }
  41567. function handleSetFont(fontName, fontRef) {
  41568. return self.loadFont(fontName, fontRef, xref, resources).
  41569. then(function (translated) {
  41570. textState.font = translated.font;
  41571. textState.fontMatrix = translated.font.fontMatrix ||
  41572. FONT_IDENTITY_MATRIX;
  41573. });
  41574. }
  41575. function buildTextContentItem(chars) {
  41576. var font = textState.font;
  41577. var textChunk = ensureTextContentItem();
  41578. var width = 0;
  41579. var height = 0;
  41580. var glyphs = font.charsToGlyphs(chars);
  41581. var defaultVMetrics = font.defaultVMetrics;
  41582. for (var i = 0; i < glyphs.length; i++) {
  41583. var glyph = glyphs[i];
  41584. var vMetricX = null;
  41585. var vMetricY = null;
  41586. var glyphWidth = null;
  41587. if (font.vertical) {
  41588. if (glyph.vmetric) {
  41589. glyphWidth = glyph.vmetric[0];
  41590. vMetricX = glyph.vmetric[1];
  41591. vMetricY = glyph.vmetric[2];
  41592. } else {
  41593. glyphWidth = glyph.width;
  41594. vMetricX = glyph.width * 0.5;
  41595. vMetricY = defaultVMetrics[2];
  41596. }
  41597. } else {
  41598. glyphWidth = glyph.width;
  41599. }
  41600. var glyphUnicode = glyph.unicode;
  41601. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  41602. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  41603. }
  41604. glyphUnicode = reverseIfRtl(glyphUnicode);
  41605. // The following will calculate the x and y of the individual glyphs.
  41606. // if (font.vertical) {
  41607. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  41608. // textState.fontMatrix[0];
  41609. // tsm[5] -= vMetricY * textState.fontSize *
  41610. // textState.fontMatrix[0];
  41611. // }
  41612. // var trm = Util.transform(textState.textMatrix, tsm);
  41613. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  41614. // var x = pt[0];
  41615. // var y = pt[1];
  41616. var charSpacing = textState.charSpacing;
  41617. if (glyph.isSpace) {
  41618. var wordSpacing = textState.wordSpacing;
  41619. charSpacing += wordSpacing;
  41620. if (wordSpacing > 0) {
  41621. addFakeSpaces(wordSpacing, textChunk.str);
  41622. }
  41623. }
  41624. var tx = 0;
  41625. var ty = 0;
  41626. if (!font.vertical) {
  41627. var w0 = glyphWidth * textState.fontMatrix[0];
  41628. tx = (w0 * textState.fontSize + charSpacing) *
  41629. textState.textHScale;
  41630. width += tx;
  41631. } else {
  41632. var w1 = glyphWidth * textState.fontMatrix[0];
  41633. ty = w1 * textState.fontSize + charSpacing;
  41634. height += ty;
  41635. }
  41636. textState.translateTextMatrix(tx, ty);
  41637. textChunk.str.push(glyphUnicode);
  41638. }
  41639. if (!font.vertical) {
  41640. textChunk.lastAdvanceWidth = width;
  41641. textChunk.width += width * textChunk.textAdvanceScale;
  41642. } else {
  41643. textChunk.lastAdvanceHeight = height;
  41644. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  41645. }
  41646. return textChunk;
  41647. }
  41648. function addFakeSpaces(width, strBuf) {
  41649. if (width < textContentItem.fakeSpaceMin) {
  41650. return;
  41651. }
  41652. if (width < textContentItem.fakeMultiSpaceMin) {
  41653. strBuf.push(' ');
  41654. return;
  41655. }
  41656. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  41657. while (fakeSpaces-- > 0) {
  41658. strBuf.push(' ');
  41659. }
  41660. }
  41661. function flushTextContentItem() {
  41662. if (!textContentItem.initialized) {
  41663. return;
  41664. }
  41665. textContent.items.push(runBidiTransform(textContentItem));
  41666. textContentItem.initialized = false;
  41667. textContentItem.str.length = 0;
  41668. }
  41669. var timeSlotManager = new TimeSlotManager();
  41670. return new Promise(function next(resolve, reject) {
  41671. task.ensureNotTerminated();
  41672. timeSlotManager.reset();
  41673. var stop, operation = {}, args = [];
  41674. while (!(stop = timeSlotManager.check())) {
  41675. // The arguments parsed by read() are not used beyond this loop, so
  41676. // we can reuse the same array on every iteration, thus avoiding
  41677. // unnecessary allocations.
  41678. args.length = 0;
  41679. operation.args = args;
  41680. if (!(preprocessor.read(operation))) {
  41681. break;
  41682. }
  41683. textState = stateManager.state;
  41684. var fn = operation.fn;
  41685. args = operation.args;
  41686. var advance;
  41687. switch (fn | 0) {
  41688. case OPS.setFont:
  41689. flushTextContentItem();
  41690. textState.fontSize = args[1];
  41691. return handleSetFont(args[0].name).then(function() {
  41692. next(resolve, reject);
  41693. }, reject);
  41694. case OPS.setTextRise:
  41695. flushTextContentItem();
  41696. textState.textRise = args[0];
  41697. break;
  41698. case OPS.setHScale:
  41699. flushTextContentItem();
  41700. textState.textHScale = args[0] / 100;
  41701. break;
  41702. case OPS.setLeading:
  41703. flushTextContentItem();
  41704. textState.leading = args[0];
  41705. break;
  41706. case OPS.moveText:
  41707. // Optimization to treat same line movement as advance
  41708. var isSameTextLine = !textState.font ? false :
  41709. ((textState.font.vertical ? args[0] : args[1]) === 0);
  41710. advance = args[0] - args[1];
  41711. if (isSameTextLine && textContentItem.initialized &&
  41712. advance > 0 &&
  41713. advance <= textContentItem.fakeMultiSpaceMax) {
  41714. textState.translateTextLineMatrix(args[0], args[1]);
  41715. textContentItem.width +=
  41716. (args[0] - textContentItem.lastAdvanceWidth);
  41717. textContentItem.height +=
  41718. (args[1] - textContentItem.lastAdvanceHeight);
  41719. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  41720. (args[1] - textContentItem.lastAdvanceHeight);
  41721. addFakeSpaces(diff, textContentItem.str);
  41722. break;
  41723. }
  41724. flushTextContentItem();
  41725. textState.translateTextLineMatrix(args[0], args[1]);
  41726. textState.textMatrix = textState.textLineMatrix.slice();
  41727. break;
  41728. case OPS.setLeadingMoveText:
  41729. flushTextContentItem();
  41730. textState.leading = -args[1];
  41731. textState.translateTextLineMatrix(args[0], args[1]);
  41732. textState.textMatrix = textState.textLineMatrix.slice();
  41733. break;
  41734. case OPS.nextLine:
  41735. flushTextContentItem();
  41736. textState.carriageReturn();
  41737. break;
  41738. case OPS.setTextMatrix:
  41739. flushTextContentItem();
  41740. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  41741. args[4], args[5]);
  41742. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  41743. args[4], args[5]);
  41744. break;
  41745. case OPS.setCharSpacing:
  41746. textState.charSpacing = args[0];
  41747. break;
  41748. case OPS.setWordSpacing:
  41749. textState.wordSpacing = args[0];
  41750. break;
  41751. case OPS.beginText:
  41752. flushTextContentItem();
  41753. textState.textMatrix = IDENTITY_MATRIX.slice();
  41754. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  41755. break;
  41756. case OPS.showSpacedText:
  41757. var items = args[0];
  41758. var offset;
  41759. for (var j = 0, jj = items.length; j < jj; j++) {
  41760. if (typeof items[j] === 'string') {
  41761. buildTextContentItem(items[j]);
  41762. } else {
  41763. ensureTextContentItem();
  41764. // PDF Specification 5.3.2 states:
  41765. // The number is expressed in thousandths of a unit of text
  41766. // space.
  41767. // This amount is subtracted from the current horizontal or
  41768. // vertical coordinate, depending on the writing mode.
  41769. // In the default coordinate system, a positive adjustment
  41770. // has the effect of moving the next glyph painted either to
  41771. // the left or down by the given amount.
  41772. advance = items[j] * textState.fontSize / 1000;
  41773. var breakTextRun = false;
  41774. if (textState.font.vertical) {
  41775. offset = advance *
  41776. (textState.textHScale * textState.textMatrix[2] +
  41777. textState.textMatrix[3]);
  41778. textState.translateTextMatrix(0, advance);
  41779. breakTextRun = textContentItem.textRunBreakAllowed &&
  41780. advance > textContentItem.fakeMultiSpaceMax;
  41781. if (!breakTextRun) {
  41782. // Value needs to be added to height to paint down.
  41783. textContentItem.height += offset;
  41784. }
  41785. } else {
  41786. advance = -advance;
  41787. offset = advance * (
  41788. textState.textHScale * textState.textMatrix[0] +
  41789. textState.textMatrix[1]);
  41790. textState.translateTextMatrix(advance, 0);
  41791. breakTextRun = textContentItem.textRunBreakAllowed &&
  41792. advance > textContentItem.fakeMultiSpaceMax;
  41793. if (!breakTextRun) {
  41794. // Value needs to be subtracted from width to paint left.
  41795. textContentItem.width += offset;
  41796. }
  41797. }
  41798. if (breakTextRun) {
  41799. flushTextContentItem();
  41800. } else if (advance > 0) {
  41801. addFakeSpaces(advance, textContentItem.str);
  41802. }
  41803. }
  41804. }
  41805. break;
  41806. case OPS.showText:
  41807. buildTextContentItem(args[0]);
  41808. break;
  41809. case OPS.nextLineShowText:
  41810. flushTextContentItem();
  41811. textState.carriageReturn();
  41812. buildTextContentItem(args[0]);
  41813. break;
  41814. case OPS.nextLineSetSpacingShowText:
  41815. flushTextContentItem();
  41816. textState.wordSpacing = args[0];
  41817. textState.charSpacing = args[1];
  41818. textState.carriageReturn();
  41819. buildTextContentItem(args[2]);
  41820. break;
  41821. case OPS.paintXObject:
  41822. flushTextContentItem();
  41823. if (args[0].code) {
  41824. break;
  41825. }
  41826. if (!xobjs) {
  41827. xobjs = (resources.get('XObject') || Dict.empty);
  41828. }
  41829. var name = args[0].name;
  41830. if (xobjsCache.key === name) {
  41831. if (xobjsCache.texts) {
  41832. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  41833. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  41834. }
  41835. break;
  41836. }
  41837. var xobj = xobjs.get(name);
  41838. if (!xobj) {
  41839. break;
  41840. }
  41841. assert(isStream(xobj), 'XObject should be a stream');
  41842. var type = xobj.dict.get('Subtype');
  41843. assert(isName(type),
  41844. 'XObject should have a Name subtype');
  41845. if ('Form' !== type.name) {
  41846. xobjsCache.key = name;
  41847. xobjsCache.texts = null;
  41848. break;
  41849. }
  41850. stateManager.save();
  41851. var matrix = xobj.dict.get('Matrix');
  41852. if (isArray(matrix) && matrix.length === 6) {
  41853. stateManager.transform(matrix);
  41854. }
  41855. return self.getTextContent(xobj, task,
  41856. xobj.dict.get('Resources') || resources, stateManager,
  41857. normalizeWhitespace).then(function (formTextContent) {
  41858. Util.appendToArray(textContent.items, formTextContent.items);
  41859. Util.extendObj(textContent.styles, formTextContent.styles);
  41860. stateManager.restore();
  41861. xobjsCache.key = name;
  41862. xobjsCache.texts = formTextContent;
  41863. next(resolve, reject);
  41864. }, reject);
  41865. case OPS.setGState:
  41866. flushTextContentItem();
  41867. var dictName = args[0];
  41868. var extGState = resources.get('ExtGState');
  41869. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41870. break;
  41871. }
  41872. var gsStateMap = extGState.get(dictName.name);
  41873. var gsStateFont = null;
  41874. for (var key in gsStateMap) {
  41875. if (key === 'Font') {
  41876. assert(!gsStateFont);
  41877. gsStateFont = gsStateMap[key];
  41878. }
  41879. }
  41880. if (gsStateFont) {
  41881. textState.fontSize = gsStateFont[1];
  41882. return handleSetFont(gsStateFont[0]).then(function() {
  41883. next(resolve, reject);
  41884. }, reject);
  41885. }
  41886. break;
  41887. } // switch
  41888. } // while
  41889. if (stop) {
  41890. deferred.then(function () {
  41891. next(resolve, reject);
  41892. }, reject);
  41893. return;
  41894. }
  41895. flushTextContentItem();
  41896. resolve(textContent);
  41897. });
  41898. },
  41899. extractDataStructures: function
  41900. partialEvaluatorExtractDataStructures(dict, baseDict,
  41901. xref, properties) {
  41902. // 9.10.2
  41903. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  41904. if (toUnicode) {
  41905. properties.toUnicode = this.readToUnicode(toUnicode);
  41906. }
  41907. if (properties.composite) {
  41908. // CIDSystemInfo helps to match CID to glyphs
  41909. var cidSystemInfo = dict.get('CIDSystemInfo');
  41910. if (isDict(cidSystemInfo)) {
  41911. properties.cidSystemInfo = {
  41912. registry: cidSystemInfo.get('Registry'),
  41913. ordering: cidSystemInfo.get('Ordering'),
  41914. supplement: cidSystemInfo.get('Supplement')
  41915. };
  41916. }
  41917. var cidToGidMap = dict.get('CIDToGIDMap');
  41918. if (isStream(cidToGidMap)) {
  41919. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  41920. }
  41921. }
  41922. // Based on 9.6.6 of the spec the encoding can come from multiple places
  41923. // and depends on the font type. The base encoding and differences are
  41924. // read here, but the encoding that is actually used is chosen during
  41925. // glyph mapping in the font.
  41926. // TODO: Loading the built in encoding in the font would allow the
  41927. // differences to be merged in here not require us to hold on to it.
  41928. var differences = [];
  41929. var baseEncodingName = null;
  41930. var encoding;
  41931. if (dict.has('Encoding')) {
  41932. encoding = dict.get('Encoding');
  41933. if (isDict(encoding)) {
  41934. baseEncodingName = encoding.get('BaseEncoding');
  41935. baseEncodingName = (isName(baseEncodingName) ?
  41936. baseEncodingName.name : null);
  41937. // Load the differences between the base and original
  41938. if (encoding.has('Differences')) {
  41939. var diffEncoding = encoding.get('Differences');
  41940. var index = 0;
  41941. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  41942. var data = diffEncoding[j];
  41943. if (isNum(data)) {
  41944. index = data;
  41945. } else if (isName(data)) {
  41946. differences[index++] = data.name;
  41947. } else if (isRef(data)) {
  41948. diffEncoding[j--] = xref.fetch(data);
  41949. continue;
  41950. } else {
  41951. error('Invalid entry in \'Differences\' array: ' + data);
  41952. }
  41953. }
  41954. }
  41955. } else if (isName(encoding)) {
  41956. baseEncodingName = encoding.name;
  41957. } else {
  41958. error('Encoding is not a Name nor a Dict');
  41959. }
  41960. // According to table 114 if the encoding is a named encoding it must be
  41961. // one of these predefined encodings.
  41962. if ((baseEncodingName !== 'MacRomanEncoding' &&
  41963. baseEncodingName !== 'MacExpertEncoding' &&
  41964. baseEncodingName !== 'WinAnsiEncoding')) {
  41965. baseEncodingName = null;
  41966. }
  41967. }
  41968. if (baseEncodingName) {
  41969. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  41970. } else {
  41971. encoding = (properties.type === 'TrueType' ?
  41972. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  41973. // The Symbolic attribute can be misused for regular fonts
  41974. // Heuristic: we have to check if the font is a standard one also
  41975. if (!!(properties.flags & FontFlags.Symbolic)) {
  41976. encoding = Encodings.MacRomanEncoding;
  41977. if (!properties.file) {
  41978. if (/Symbol/i.test(properties.name)) {
  41979. encoding = Encodings.SymbolSetEncoding;
  41980. } else if (/Dingbats/i.test(properties.name)) {
  41981. encoding = Encodings.ZapfDingbatsEncoding;
  41982. }
  41983. }
  41984. }
  41985. properties.defaultEncoding = encoding;
  41986. }
  41987. properties.differences = differences;
  41988. properties.baseEncodingName = baseEncodingName;
  41989. properties.dict = dict;
  41990. },
  41991. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  41992. var cmap, cmapObj = toUnicode;
  41993. if (isName(cmapObj)) {
  41994. cmap = CMapFactory.create(cmapObj,
  41995. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  41996. if (cmap instanceof IdentityCMap) {
  41997. return new IdentityToUnicodeMap(0, 0xFFFF);
  41998. }
  41999. return new ToUnicodeMap(cmap.getMap());
  42000. } else if (isStream(cmapObj)) {
  42001. cmap = CMapFactory.create(cmapObj,
  42002. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42003. if (cmap instanceof IdentityCMap) {
  42004. return new IdentityToUnicodeMap(0, 0xFFFF);
  42005. }
  42006. var map = new Array(cmap.length);
  42007. // Convert UTF-16BE
  42008. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  42009. // to iterate over all keys.
  42010. cmap.forEach(function(charCode, token) {
  42011. var str = [];
  42012. for (var k = 0; k < token.length; k += 2) {
  42013. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42014. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  42015. str.push(w1);
  42016. continue;
  42017. }
  42018. k += 2;
  42019. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42020. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  42021. }
  42022. map[charCode] = String.fromCharCode.apply(String, str);
  42023. });
  42024. return new ToUnicodeMap(map);
  42025. }
  42026. return null;
  42027. },
  42028. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  42029. // Extract the encoding from the CIDToGIDMap
  42030. var glyphsData = cidToGidStream.getBytes();
  42031. // Set encoding 0 to later verify the font has an encoding
  42032. var result = [];
  42033. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  42034. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  42035. if (glyphID === 0) {
  42036. continue;
  42037. }
  42038. var code = j >> 1;
  42039. result[code] = glyphID;
  42040. }
  42041. return result;
  42042. },
  42043. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  42044. descriptor,
  42045. properties) {
  42046. var glyphsWidths = [];
  42047. var defaultWidth = 0;
  42048. var glyphsVMetrics = [];
  42049. var defaultVMetrics;
  42050. var i, ii, j, jj, start, code, widths;
  42051. if (properties.composite) {
  42052. defaultWidth = dict.get('DW') || 1000;
  42053. widths = dict.get('W');
  42054. if (widths) {
  42055. for (i = 0, ii = widths.length; i < ii; i++) {
  42056. start = widths[i++];
  42057. code = xref.fetchIfRef(widths[i]);
  42058. if (isArray(code)) {
  42059. for (j = 0, jj = code.length; j < jj; j++) {
  42060. glyphsWidths[start++] = code[j];
  42061. }
  42062. } else {
  42063. var width = widths[++i];
  42064. for (j = start; j <= code; j++) {
  42065. glyphsWidths[j] = width;
  42066. }
  42067. }
  42068. }
  42069. }
  42070. if (properties.vertical) {
  42071. var vmetrics = (dict.get('DW2') || [880, -1000]);
  42072. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  42073. vmetrics = dict.get('W2');
  42074. if (vmetrics) {
  42075. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  42076. start = vmetrics[i++];
  42077. code = xref.fetchIfRef(vmetrics[i]);
  42078. if (isArray(code)) {
  42079. for (j = 0, jj = code.length; j < jj; j++) {
  42080. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  42081. }
  42082. } else {
  42083. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  42084. for (j = start; j <= code; j++) {
  42085. glyphsVMetrics[j] = vmetric;
  42086. }
  42087. }
  42088. }
  42089. }
  42090. }
  42091. } else {
  42092. var firstChar = properties.firstChar;
  42093. widths = dict.get('Widths');
  42094. if (widths) {
  42095. j = firstChar;
  42096. for (i = 0, ii = widths.length; i < ii; i++) {
  42097. glyphsWidths[j++] = widths[i];
  42098. }
  42099. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  42100. } else {
  42101. // Trying get the BaseFont metrics (see comment above).
  42102. var baseFontName = dict.get('BaseFont');
  42103. if (isName(baseFontName)) {
  42104. var metrics = this.getBaseFontMetrics(baseFontName.name);
  42105. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  42106. properties);
  42107. defaultWidth = metrics.defaultWidth;
  42108. }
  42109. }
  42110. }
  42111. // Heuristic: detection of monospace font by checking all non-zero widths
  42112. var isMonospace = true;
  42113. var firstWidth = defaultWidth;
  42114. for (var glyph in glyphsWidths) {
  42115. var glyphWidth = glyphsWidths[glyph];
  42116. if (!glyphWidth) {
  42117. continue;
  42118. }
  42119. if (!firstWidth) {
  42120. firstWidth = glyphWidth;
  42121. continue;
  42122. }
  42123. if (firstWidth !== glyphWidth) {
  42124. isMonospace = false;
  42125. break;
  42126. }
  42127. }
  42128. if (isMonospace) {
  42129. properties.flags |= FontFlags.FixedPitch;
  42130. }
  42131. properties.defaultWidth = defaultWidth;
  42132. properties.widths = glyphsWidths;
  42133. properties.defaultVMetrics = defaultVMetrics;
  42134. properties.vmetrics = glyphsVMetrics;
  42135. },
  42136. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  42137. // Simulating descriptor flags attribute
  42138. var fontNameWoStyle = baseFontName.split('-')[0];
  42139. return (fontNameWoStyle in serifFonts) ||
  42140. (fontNameWoStyle.search(/serif/gi) !== -1);
  42141. },
  42142. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  42143. var defaultWidth = 0;
  42144. var widths = [];
  42145. var monospace = false;
  42146. var lookupName = (stdFontMap[name] || name);
  42147. if (!(lookupName in Metrics)) {
  42148. // Use default fonts for looking up font metrics if the passed
  42149. // font is not a base font
  42150. if (this.isSerifFont(name)) {
  42151. lookupName = 'Times-Roman';
  42152. } else {
  42153. lookupName = 'Helvetica';
  42154. }
  42155. }
  42156. var glyphWidths = Metrics[lookupName];
  42157. if (isNum(glyphWidths)) {
  42158. defaultWidth = glyphWidths;
  42159. monospace = true;
  42160. } else {
  42161. widths = glyphWidths;
  42162. }
  42163. return {
  42164. defaultWidth: defaultWidth,
  42165. monospace: monospace,
  42166. widths: widths
  42167. };
  42168. },
  42169. buildCharCodeToWidth:
  42170. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  42171. properties) {
  42172. var widths = Object.create(null);
  42173. var differences = properties.differences;
  42174. var encoding = properties.defaultEncoding;
  42175. for (var charCode = 0; charCode < 256; charCode++) {
  42176. if (charCode in differences &&
  42177. widthsByGlyphName[differences[charCode]]) {
  42178. widths[charCode] = widthsByGlyphName[differences[charCode]];
  42179. continue;
  42180. }
  42181. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  42182. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  42183. continue;
  42184. }
  42185. }
  42186. return widths;
  42187. },
  42188. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  42189. var baseDict = dict;
  42190. var type = dict.get('Subtype');
  42191. assert(isName(type), 'invalid font Subtype');
  42192. var composite = false;
  42193. var uint8array;
  42194. if (type.name === 'Type0') {
  42195. // If font is a composite
  42196. // - get the descendant font
  42197. // - set the type according to the descendant font
  42198. // - get the FontDescriptor from the descendant font
  42199. var df = dict.get('DescendantFonts');
  42200. if (!df) {
  42201. error('Descendant fonts are not specified');
  42202. }
  42203. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  42204. type = dict.get('Subtype');
  42205. assert(isName(type), 'invalid font Subtype');
  42206. composite = true;
  42207. }
  42208. var descriptor = dict.get('FontDescriptor');
  42209. if (descriptor) {
  42210. var hash = new MurmurHash3_64();
  42211. var encoding = baseDict.getRaw('Encoding');
  42212. if (isName(encoding)) {
  42213. hash.update(encoding.name);
  42214. } else if (isRef(encoding)) {
  42215. hash.update(encoding.num + '_' + encoding.gen);
  42216. } else if (isDict(encoding)) {
  42217. var keys = encoding.getKeys();
  42218. for (var i = 0, ii = keys.length; i < ii; i++) {
  42219. var entry = encoding.getRaw(keys[i]);
  42220. if (isName(entry)) {
  42221. hash.update(entry.name);
  42222. } else if (isRef(entry)) {
  42223. hash.update(entry.num + '_' + entry.gen);
  42224. } else if (isArray(entry)) { // 'Differences' entry.
  42225. // Ideally we should check the contents of the array, but to avoid
  42226. // parsing it here and then again in |extractDataStructures|,
  42227. // we only use the array length for now (fixes bug1157493.pdf).
  42228. hash.update(entry.length.toString());
  42229. }
  42230. }
  42231. }
  42232. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  42233. if (isStream(toUnicode)) {
  42234. var stream = toUnicode.str || toUnicode;
  42235. uint8array = stream.buffer ?
  42236. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  42237. new Uint8Array(stream.bytes.buffer,
  42238. stream.start, stream.end - stream.start);
  42239. hash.update(uint8array);
  42240. } else if (isName(toUnicode)) {
  42241. hash.update(toUnicode.name);
  42242. }
  42243. var widths = dict.get('Widths') || baseDict.get('Widths');
  42244. if (widths) {
  42245. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  42246. hash.update(uint8array);
  42247. }
  42248. }
  42249. return {
  42250. descriptor: descriptor,
  42251. dict: dict,
  42252. baseDict: baseDict,
  42253. composite: composite,
  42254. type: type.name,
  42255. hash: hash ? hash.hexdigest() : ''
  42256. };
  42257. },
  42258. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  42259. xref) {
  42260. var baseDict = preEvaluatedFont.baseDict;
  42261. var dict = preEvaluatedFont.dict;
  42262. var composite = preEvaluatedFont.composite;
  42263. var descriptor = preEvaluatedFont.descriptor;
  42264. var type = preEvaluatedFont.type;
  42265. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  42266. var properties;
  42267. if (!descriptor) {
  42268. if (type === 'Type3') {
  42269. // FontDescriptor is only required for Type3 fonts when the document
  42270. // is a tagged pdf. Create a barbebones one to get by.
  42271. descriptor = new Dict(null);
  42272. descriptor.set('FontName', Name.get(type));
  42273. descriptor.set('FontBBox', dict.get('FontBBox'));
  42274. } else {
  42275. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  42276. // FontDescriptor was not required.
  42277. // This case is here for compatibility.
  42278. var baseFontName = dict.get('BaseFont');
  42279. if (!isName(baseFontName)) {
  42280. error('Base font is not specified');
  42281. }
  42282. // Using base font name as a font name.
  42283. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  42284. var metrics = this.getBaseFontMetrics(baseFontName);
  42285. // Simulating descriptor flags attribute
  42286. var fontNameWoStyle = baseFontName.split('-')[0];
  42287. var flags =
  42288. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  42289. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  42290. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  42291. FontFlags.Nonsymbolic);
  42292. properties = {
  42293. type: type,
  42294. name: baseFontName,
  42295. widths: metrics.widths,
  42296. defaultWidth: metrics.defaultWidth,
  42297. flags: flags,
  42298. firstChar: 0,
  42299. lastChar: maxCharIndex
  42300. };
  42301. this.extractDataStructures(dict, dict, xref, properties);
  42302. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  42303. properties);
  42304. return new Font(baseFontName, null, properties);
  42305. }
  42306. }
  42307. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  42308. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  42309. // to ignore this rule when a variant of a standart font is used.
  42310. // TODO Fill the width array depending on which of the base font this is
  42311. // a variant.
  42312. var firstChar = (dict.get('FirstChar') || 0);
  42313. var lastChar = (dict.get('LastChar') || maxCharIndex);
  42314. var fontName = descriptor.get('FontName');
  42315. var baseFont = dict.get('BaseFont');
  42316. // Some bad PDFs have a string as the font name.
  42317. if (isString(fontName)) {
  42318. fontName = Name.get(fontName);
  42319. }
  42320. if (isString(baseFont)) {
  42321. baseFont = Name.get(baseFont);
  42322. }
  42323. if (type !== 'Type3') {
  42324. var fontNameStr = fontName && fontName.name;
  42325. var baseFontStr = baseFont && baseFont.name;
  42326. if (fontNameStr !== baseFontStr) {
  42327. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  42328. '" but should be the same as the Font\'s BaseFont "' +
  42329. baseFontStr + '"');
  42330. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  42331. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  42332. if (fontNameStr && baseFontStr &&
  42333. baseFontStr.indexOf(fontNameStr) === 0) {
  42334. fontName = baseFont;
  42335. }
  42336. }
  42337. }
  42338. fontName = (fontName || baseFont);
  42339. assert(isName(fontName), 'invalid font name');
  42340. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  42341. if (fontFile) {
  42342. if (fontFile.dict) {
  42343. var subtype = fontFile.dict.get('Subtype');
  42344. if (subtype) {
  42345. subtype = subtype.name;
  42346. }
  42347. var length1 = fontFile.dict.get('Length1');
  42348. var length2 = fontFile.dict.get('Length2');
  42349. }
  42350. }
  42351. properties = {
  42352. type: type,
  42353. name: fontName.name,
  42354. subtype: subtype,
  42355. file: fontFile,
  42356. length1: length1,
  42357. length2: length2,
  42358. loadedName: baseDict.loadedName,
  42359. composite: composite,
  42360. wideChars: composite,
  42361. fixedPitch: false,
  42362. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  42363. firstChar: firstChar || 0,
  42364. lastChar: (lastChar || maxCharIndex),
  42365. bbox: descriptor.get('FontBBox'),
  42366. ascent: descriptor.get('Ascent'),
  42367. descent: descriptor.get('Descent'),
  42368. xHeight: descriptor.get('XHeight'),
  42369. capHeight: descriptor.get('CapHeight'),
  42370. flags: descriptor.get('Flags'),
  42371. italicAngle: descriptor.get('ItalicAngle'),
  42372. coded: false
  42373. };
  42374. if (composite) {
  42375. var cidEncoding = baseDict.get('Encoding');
  42376. if (isName(cidEncoding)) {
  42377. properties.cidEncoding = cidEncoding.name;
  42378. }
  42379. properties.cMap = CMapFactory.create(cidEncoding,
  42380. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42381. properties.vertical = properties.cMap.vertical;
  42382. }
  42383. this.extractDataStructures(dict, baseDict, xref, properties);
  42384. this.extractWidths(dict, xref, descriptor, properties);
  42385. if (type === 'Type3') {
  42386. properties.isType3Font = true;
  42387. }
  42388. return new Font(fontName.name, fontFile, properties);
  42389. }
  42390. };
  42391. return PartialEvaluator;
  42392. })();
  42393. var TranslatedFont = (function TranslatedFontClosure() {
  42394. function TranslatedFont(loadedName, font, dict) {
  42395. this.loadedName = loadedName;
  42396. this.font = font;
  42397. this.dict = dict;
  42398. this.type3Loaded = null;
  42399. this.sent = false;
  42400. }
  42401. TranslatedFont.prototype = {
  42402. send: function (handler) {
  42403. if (this.sent) {
  42404. return;
  42405. }
  42406. var fontData = this.font.exportData();
  42407. handler.send('commonobj', [
  42408. this.loadedName,
  42409. 'Font',
  42410. fontData
  42411. ]);
  42412. this.sent = true;
  42413. },
  42414. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  42415. assert(this.font.isType3Font);
  42416. if (this.type3Loaded) {
  42417. return this.type3Loaded;
  42418. }
  42419. var translatedFont = this.font;
  42420. var loadCharProcsPromise = Promise.resolve();
  42421. var charProcs = this.dict.get('CharProcs').getAll();
  42422. var fontResources = this.dict.get('Resources') || resources;
  42423. var charProcKeys = Object.keys(charProcs);
  42424. var charProcOperatorList = {};
  42425. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  42426. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  42427. var glyphStream = charProcs[key];
  42428. var operatorList = new OperatorList();
  42429. return evaluator.getOperatorList(glyphStream, task, fontResources,
  42430. operatorList).then(function () {
  42431. charProcOperatorList[key] = operatorList.getIR();
  42432. // Add the dependencies to the parent operator list so they are
  42433. // resolved before sub operator list is executed synchronously.
  42434. parentOperatorList.addDependencies(operatorList.dependencies);
  42435. }, function (reason) {
  42436. warn('Type3 font resource \"' + key + '\" is not available');
  42437. var operatorList = new OperatorList();
  42438. charProcOperatorList[key] = operatorList.getIR();
  42439. });
  42440. }.bind(this, charProcKeys[i]));
  42441. }
  42442. this.type3Loaded = loadCharProcsPromise.then(function () {
  42443. translatedFont.charProcOperatorList = charProcOperatorList;
  42444. });
  42445. return this.type3Loaded;
  42446. }
  42447. };
  42448. return TranslatedFont;
  42449. })();
  42450. var OperatorList = (function OperatorListClosure() {
  42451. var CHUNK_SIZE = 1000;
  42452. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  42453. function getTransfers(queue) {
  42454. var transfers = [];
  42455. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  42456. for (var i = 0, ii = queue.length; i < ii; i++) {
  42457. switch (fnArray[i]) {
  42458. case OPS.paintInlineImageXObject:
  42459. case OPS.paintInlineImageXObjectGroup:
  42460. case OPS.paintImageMaskXObject:
  42461. var arg = argsArray[i][0]; // first param in imgData
  42462. if (!arg.cached) {
  42463. transfers.push(arg.data.buffer);
  42464. }
  42465. break;
  42466. }
  42467. }
  42468. return transfers;
  42469. }
  42470. function OperatorList(intent, messageHandler, pageIndex) {
  42471. this.messageHandler = messageHandler;
  42472. this.fnArray = [];
  42473. this.argsArray = [];
  42474. this.dependencies = {};
  42475. this._totalLength = 0;
  42476. this.pageIndex = pageIndex;
  42477. this.intent = intent;
  42478. }
  42479. OperatorList.prototype = {
  42480. get length() {
  42481. return this.argsArray.length;
  42482. },
  42483. /**
  42484. * @returns {number} The total length of the entire operator list,
  42485. * since `this.length === 0` after flushing.
  42486. */
  42487. get totalLength() {
  42488. return (this._totalLength + this.length);
  42489. },
  42490. addOp: function(fn, args) {
  42491. this.fnArray.push(fn);
  42492. this.argsArray.push(args);
  42493. if (this.messageHandler) {
  42494. if (this.fnArray.length >= CHUNK_SIZE) {
  42495. this.flush();
  42496. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  42497. (fn === OPS.restore || fn === OPS.endText)) {
  42498. // heuristic to flush on boundary of restore or endText
  42499. this.flush();
  42500. }
  42501. }
  42502. },
  42503. addDependency: function(dependency) {
  42504. if (dependency in this.dependencies) {
  42505. return;
  42506. }
  42507. this.dependencies[dependency] = true;
  42508. this.addOp(OPS.dependency, [dependency]);
  42509. },
  42510. addDependencies: function(dependencies) {
  42511. for (var key in dependencies) {
  42512. this.addDependency(key);
  42513. }
  42514. },
  42515. addOpList: function(opList) {
  42516. Util.extendObj(this.dependencies, opList.dependencies);
  42517. for (var i = 0, ii = opList.length; i < ii; i++) {
  42518. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  42519. }
  42520. },
  42521. getIR: function() {
  42522. return {
  42523. fnArray: this.fnArray,
  42524. argsArray: this.argsArray,
  42525. length: this.length
  42526. };
  42527. },
  42528. flush: function(lastChunk) {
  42529. if (this.intent !== 'oplist') {
  42530. new QueueOptimizer().optimize(this);
  42531. }
  42532. var transfers = getTransfers(this);
  42533. var length = this.length;
  42534. this._totalLength += length;
  42535. this.messageHandler.send('RenderPageChunk', {
  42536. operatorList: {
  42537. fnArray: this.fnArray,
  42538. argsArray: this.argsArray,
  42539. lastChunk: lastChunk,
  42540. length: length
  42541. },
  42542. pageIndex: this.pageIndex,
  42543. intent: this.intent
  42544. }, transfers);
  42545. this.dependencies = {};
  42546. this.fnArray.length = 0;
  42547. this.argsArray.length = 0;
  42548. }
  42549. };
  42550. return OperatorList;
  42551. })();
  42552. var StateManager = (function StateManagerClosure() {
  42553. function StateManager(initialState) {
  42554. this.state = initialState;
  42555. this.stateStack = [];
  42556. }
  42557. StateManager.prototype = {
  42558. save: function () {
  42559. var old = this.state;
  42560. this.stateStack.push(this.state);
  42561. this.state = old.clone();
  42562. },
  42563. restore: function () {
  42564. var prev = this.stateStack.pop();
  42565. if (prev) {
  42566. this.state = prev;
  42567. }
  42568. },
  42569. transform: function (args) {
  42570. this.state.ctm = Util.transform(this.state.ctm, args);
  42571. }
  42572. };
  42573. return StateManager;
  42574. })();
  42575. var TextState = (function TextStateClosure() {
  42576. function TextState() {
  42577. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42578. this.fontSize = 0;
  42579. this.font = null;
  42580. this.fontMatrix = FONT_IDENTITY_MATRIX;
  42581. this.textMatrix = IDENTITY_MATRIX.slice();
  42582. this.textLineMatrix = IDENTITY_MATRIX.slice();
  42583. this.charSpacing = 0;
  42584. this.wordSpacing = 0;
  42585. this.leading = 0;
  42586. this.textHScale = 1;
  42587. this.textRise = 0;
  42588. }
  42589. TextState.prototype = {
  42590. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42591. var m = this.textMatrix;
  42592. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42593. },
  42594. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42595. var m = this.textLineMatrix;
  42596. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42597. },
  42598. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  42599. var m = this.textMatrix;
  42600. m[4] = m[0] * x + m[2] * y + m[4];
  42601. m[5] = m[1] * x + m[3] * y + m[5];
  42602. },
  42603. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  42604. var m = this.textLineMatrix;
  42605. m[4] = m[0] * x + m[2] * y + m[4];
  42606. m[5] = m[1] * x + m[3] * y + m[5];
  42607. },
  42608. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  42609. // 9.4.4 Text Space Details
  42610. var tsm = [this.fontSize * this.textHScale, 0,
  42611. 0, this.fontSize,
  42612. 0, this.textRise];
  42613. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  42614. },
  42615. carriageReturn: function TextState_carriageReturn() {
  42616. this.translateTextLineMatrix(0, -this.leading);
  42617. this.textMatrix = this.textLineMatrix.slice();
  42618. },
  42619. clone: function TextState_clone() {
  42620. var clone = Object.create(this);
  42621. clone.textMatrix = this.textMatrix.slice();
  42622. clone.textLineMatrix = this.textLineMatrix.slice();
  42623. clone.fontMatrix = this.fontMatrix.slice();
  42624. return clone;
  42625. }
  42626. };
  42627. return TextState;
  42628. })();
  42629. var EvalState = (function EvalStateClosure() {
  42630. function EvalState() {
  42631. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42632. this.font = null;
  42633. this.textRenderingMode = TextRenderingMode.FILL;
  42634. this.fillColorSpace = ColorSpace.singletons.gray;
  42635. this.strokeColorSpace = ColorSpace.singletons.gray;
  42636. }
  42637. EvalState.prototype = {
  42638. clone: function CanvasExtraState_clone() {
  42639. return Object.create(this);
  42640. },
  42641. };
  42642. return EvalState;
  42643. })();
  42644. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  42645. // Specifies properties for each command
  42646. //
  42647. // If variableArgs === true: [0, `numArgs`] expected
  42648. // If variableArgs === false: exactly `numArgs` expected
  42649. var OP_MAP = {
  42650. // Graphic state
  42651. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  42652. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  42653. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  42654. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  42655. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  42656. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  42657. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  42658. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  42659. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  42660. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  42661. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  42662. // Path
  42663. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  42664. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  42665. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  42666. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  42667. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  42668. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  42669. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  42670. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  42671. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  42672. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42673. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42674. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  42675. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  42676. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  42677. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  42678. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  42679. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  42680. // Clipping
  42681. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  42682. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  42683. // Text
  42684. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  42685. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  42686. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  42687. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  42688. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  42689. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  42690. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  42691. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  42692. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  42693. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  42694. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  42695. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  42696. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  42697. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  42698. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  42699. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  42700. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  42701. variableArgs: false },
  42702. // Type3 fonts
  42703. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  42704. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  42705. // Color
  42706. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  42707. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  42708. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  42709. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  42710. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  42711. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  42712. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  42713. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  42714. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  42715. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  42716. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  42717. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  42718. // Shading
  42719. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  42720. // Images
  42721. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  42722. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  42723. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  42724. // XObjects
  42725. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  42726. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  42727. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  42728. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  42729. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  42730. variableArgs: false },
  42731. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  42732. // Compatibility
  42733. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  42734. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  42735. // (reserved partial commands for the lexer)
  42736. BM: null,
  42737. BD: null,
  42738. 'true': null,
  42739. fa: null,
  42740. fal: null,
  42741. fals: null,
  42742. 'false': null,
  42743. nu: null,
  42744. nul: null,
  42745. 'null': null
  42746. };
  42747. function EvaluatorPreprocessor(stream, xref, stateManager) {
  42748. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  42749. // dictionary
  42750. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  42751. this.stateManager = stateManager;
  42752. this.nonProcessedArgs = [];
  42753. }
  42754. EvaluatorPreprocessor.prototype = {
  42755. get savedStatesDepth() {
  42756. return this.stateManager.stateStack.length;
  42757. },
  42758. // |operation| is an object with two fields:
  42759. //
  42760. // - |fn| is an out param.
  42761. //
  42762. // - |args| is an inout param. On entry, it should have one of two values.
  42763. //
  42764. // - An empty array. This indicates that the caller is providing the
  42765. // array in which the args will be stored in. The caller should use
  42766. // this value if it can reuse a single array for each call to read().
  42767. //
  42768. // - |null|. This indicates that the caller needs this function to create
  42769. // the array in which any args are stored in. If there are zero args,
  42770. // this function will leave |operation.args| as |null| (thus avoiding
  42771. // allocations that would occur if we used an empty array to represent
  42772. // zero arguments). Otherwise, it will replace |null| with a new array
  42773. // containing the arguments. The caller should use this value if it
  42774. // cannot reuse an array for each call to read().
  42775. //
  42776. // These two modes are present because this function is very hot and so
  42777. // avoiding allocations where possible is worthwhile.
  42778. //
  42779. read: function EvaluatorPreprocessor_read(operation) {
  42780. var args = operation.args;
  42781. while (true) {
  42782. var obj = this.parser.getObj();
  42783. if (isCmd(obj)) {
  42784. var cmd = obj.cmd;
  42785. // Check that the command is valid
  42786. var opSpec = OP_MAP[cmd];
  42787. if (!opSpec) {
  42788. warn('Unknown command "' + cmd + '"');
  42789. continue;
  42790. }
  42791. var fn = opSpec.id;
  42792. var numArgs = opSpec.numArgs;
  42793. var argsLength = args !== null ? args.length : 0;
  42794. if (!opSpec.variableArgs) {
  42795. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  42796. if (argsLength !== numArgs) {
  42797. var nonProcessedArgs = this.nonProcessedArgs;
  42798. while (argsLength > numArgs) {
  42799. nonProcessedArgs.push(args.shift());
  42800. argsLength--;
  42801. }
  42802. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  42803. if (!args) {
  42804. args = [];
  42805. }
  42806. args.unshift(nonProcessedArgs.pop());
  42807. argsLength++;
  42808. }
  42809. }
  42810. if (argsLength < numArgs) {
  42811. // If we receive too few args, it's not possible to possible
  42812. // to execute the command, so skip the command
  42813. info('Command ' + fn + ': because expected ' +
  42814. numArgs + ' args, but received ' + argsLength +
  42815. ' args; skipping');
  42816. args = null;
  42817. continue;
  42818. }
  42819. } else if (argsLength > numArgs) {
  42820. info('Command ' + fn + ': expected [0,' + numArgs +
  42821. '] args, but received ' + argsLength + ' args');
  42822. }
  42823. // TODO figure out how to type-check vararg functions
  42824. this.preprocessCommand(fn, args);
  42825. operation.fn = fn;
  42826. operation.args = args;
  42827. return true;
  42828. } else {
  42829. if (isEOF(obj)) {
  42830. return false; // no more commands
  42831. }
  42832. // argument
  42833. if (obj !== null) {
  42834. if (!args) {
  42835. args = [];
  42836. }
  42837. args.push((obj instanceof Dict ? obj.getAll() : obj));
  42838. assert(args.length <= 33, 'Too many arguments');
  42839. }
  42840. }
  42841. }
  42842. },
  42843. preprocessCommand:
  42844. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  42845. switch (fn | 0) {
  42846. case OPS.save:
  42847. this.stateManager.save();
  42848. break;
  42849. case OPS.restore:
  42850. this.stateManager.restore();
  42851. break;
  42852. case OPS.transform:
  42853. this.stateManager.transform(args);
  42854. break;
  42855. }
  42856. }
  42857. };
  42858. return EvaluatorPreprocessor;
  42859. })();
  42860. var QueueOptimizer = (function QueueOptimizerClosure() {
  42861. function addState(parentState, pattern, fn) {
  42862. var state = parentState;
  42863. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  42864. var item = pattern[i];
  42865. state = (state[item] || (state[item] = []));
  42866. }
  42867. state[pattern[pattern.length - 1]] = fn;
  42868. }
  42869. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  42870. argsArray) {
  42871. // Handles special case of mainly LaTeX documents which use image masks to
  42872. // draw lines with the current fill style.
  42873. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  42874. // have been found at iFirstSave.
  42875. var iFirstPIMXO = iFirstSave + 2;
  42876. for (var i = 0; i < count; i++) {
  42877. var arg = argsArray[iFirstPIMXO + 4 * i];
  42878. var imageMask = arg.length === 1 && arg[0];
  42879. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  42880. (!imageMask.data.length ||
  42881. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  42882. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  42883. continue;
  42884. }
  42885. break;
  42886. }
  42887. return count - i;
  42888. }
  42889. var InitialState = [];
  42890. // This replaces (save, transform, paintInlineImageXObject, restore)+
  42891. // sequences with one |paintInlineImageXObjectGroup| operation.
  42892. addState(InitialState,
  42893. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  42894. function foundInlineImageGroup(context) {
  42895. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  42896. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  42897. var MAX_WIDTH = 1000;
  42898. var IMAGE_PADDING = 1;
  42899. var fnArray = context.fnArray, argsArray = context.argsArray;
  42900. var curr = context.iCurr;
  42901. var iFirstSave = curr - 3;
  42902. var iFirstTransform = curr - 2;
  42903. var iFirstPIIXO = curr - 1;
  42904. // Look for the quartets.
  42905. var i = iFirstSave + 4;
  42906. var ii = fnArray.length;
  42907. while (i + 3 < ii) {
  42908. if (fnArray[i] !== OPS.save ||
  42909. fnArray[i + 1] !== OPS.transform ||
  42910. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  42911. fnArray[i + 3] !== OPS.restore) {
  42912. break; // ops don't match
  42913. }
  42914. i += 4;
  42915. }
  42916. // At this point, i is the index of the first op past the last valid
  42917. // quartet.
  42918. var count = Math.min((i - iFirstSave) / 4,
  42919. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  42920. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  42921. return i;
  42922. }
  42923. // assuming that heights of those image is too small (~1 pixel)
  42924. // packing as much as possible by lines
  42925. var maxX = 0;
  42926. var map = [], maxLineHeight = 0;
  42927. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  42928. var q;
  42929. for (q = 0; q < count; q++) {
  42930. var transform = argsArray[iFirstTransform + (q << 2)];
  42931. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  42932. if (currentX + img.width > MAX_WIDTH) {
  42933. // starting new line
  42934. maxX = Math.max(maxX, currentX);
  42935. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  42936. currentX = 0;
  42937. maxLineHeight = 0;
  42938. }
  42939. map.push({
  42940. transform: transform,
  42941. x: currentX, y: currentY,
  42942. w: img.width, h: img.height
  42943. });
  42944. currentX += img.width + 2 * IMAGE_PADDING;
  42945. maxLineHeight = Math.max(maxLineHeight, img.height);
  42946. }
  42947. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  42948. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  42949. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  42950. var imgRowSize = imgWidth << 2;
  42951. for (q = 0; q < count; q++) {
  42952. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  42953. // Copy image by lines and extends pixels into padding.
  42954. var rowSize = map[q].w << 2;
  42955. var dataOffset = 0;
  42956. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  42957. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  42958. for (var k = 0, kk = map[q].h; k < kk; k++) {
  42959. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  42960. dataOffset += rowSize;
  42961. offset += imgRowSize;
  42962. }
  42963. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  42964. while (offset >= 0) {
  42965. data[offset - 4] = data[offset];
  42966. data[offset - 3] = data[offset + 1];
  42967. data[offset - 2] = data[offset + 2];
  42968. data[offset - 1] = data[offset + 3];
  42969. data[offset + rowSize] = data[offset + rowSize - 4];
  42970. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  42971. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  42972. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  42973. offset -= imgRowSize;
  42974. }
  42975. }
  42976. // Replace queue items.
  42977. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  42978. argsArray.splice(iFirstSave, count * 4,
  42979. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  42980. data: imgData }, map]);
  42981. return iFirstSave + 1;
  42982. });
  42983. // This replaces (save, transform, paintImageMaskXObject, restore)+
  42984. // sequences with one |paintImageMaskXObjectGroup| or one
  42985. // |paintImageMaskXObjectRepeat| operation.
  42986. addState(InitialState,
  42987. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  42988. function foundImageMaskGroup(context) {
  42989. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  42990. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  42991. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  42992. var fnArray = context.fnArray, argsArray = context.argsArray;
  42993. var curr = context.iCurr;
  42994. var iFirstSave = curr - 3;
  42995. var iFirstTransform = curr - 2;
  42996. var iFirstPIMXO = curr - 1;
  42997. // Look for the quartets.
  42998. var i = iFirstSave + 4;
  42999. var ii = fnArray.length;
  43000. while (i + 3 < ii) {
  43001. if (fnArray[i] !== OPS.save ||
  43002. fnArray[i + 1] !== OPS.transform ||
  43003. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  43004. fnArray[i + 3] !== OPS.restore) {
  43005. break; // ops don't match
  43006. }
  43007. i += 4;
  43008. }
  43009. // At this point, i is the index of the first op past the last valid
  43010. // quartet.
  43011. var count = (i - iFirstSave) / 4;
  43012. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  43013. argsArray);
  43014. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  43015. return i;
  43016. }
  43017. var q;
  43018. var isSameImage = false;
  43019. var iTransform, transformArgs;
  43020. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  43021. if (argsArray[iFirstTransform][1] === 0 &&
  43022. argsArray[iFirstTransform][2] === 0) {
  43023. isSameImage = true;
  43024. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43025. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43026. iTransform = iFirstTransform + 4;
  43027. var iPIMXO = iFirstPIMXO + 4;
  43028. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  43029. transformArgs = argsArray[iTransform];
  43030. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  43031. transformArgs[0] !== firstTransformArg0 ||
  43032. transformArgs[1] !== 0 ||
  43033. transformArgs[2] !== 0 ||
  43034. transformArgs[3] !== firstTransformArg3) {
  43035. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  43036. isSameImage = false;
  43037. } else {
  43038. count = q;
  43039. }
  43040. break; // different image or transform
  43041. }
  43042. }
  43043. }
  43044. if (isSameImage) {
  43045. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  43046. var positions = new Float32Array(count * 2);
  43047. iTransform = iFirstTransform;
  43048. for (q = 0; q < count; q++, iTransform += 4) {
  43049. transformArgs = argsArray[iTransform];
  43050. positions[(q << 1)] = transformArgs[4];
  43051. positions[(q << 1) + 1] = transformArgs[5];
  43052. }
  43053. // Replace queue items.
  43054. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  43055. argsArray.splice(iFirstSave, count * 4,
  43056. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  43057. } else {
  43058. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  43059. var images = [];
  43060. for (q = 0; q < count; q++) {
  43061. transformArgs = argsArray[iFirstTransform + (q << 2)];
  43062. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  43063. images.push({ data: maskParams.data, width: maskParams.width,
  43064. height: maskParams.height,
  43065. transform: transformArgs });
  43066. }
  43067. // Replace queue items.
  43068. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  43069. argsArray.splice(iFirstSave, count * 4, [images]);
  43070. }
  43071. return iFirstSave + 1;
  43072. });
  43073. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  43074. // with one paintImageXObjectRepeat operation, if the |transform| and
  43075. // |paintImageXObjectRepeat| ops are appropriate.
  43076. addState(InitialState,
  43077. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  43078. function (context) {
  43079. var MIN_IMAGES_IN_BLOCK = 3;
  43080. var MAX_IMAGES_IN_BLOCK = 1000;
  43081. var fnArray = context.fnArray, argsArray = context.argsArray;
  43082. var curr = context.iCurr;
  43083. var iFirstSave = curr - 3;
  43084. var iFirstTransform = curr - 2;
  43085. var iFirstPIXO = curr - 1;
  43086. var iFirstRestore = curr;
  43087. if (argsArray[iFirstTransform][1] !== 0 ||
  43088. argsArray[iFirstTransform][2] !== 0) {
  43089. return iFirstRestore + 1; // transform has the wrong form
  43090. }
  43091. // Look for the quartets.
  43092. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  43093. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43094. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43095. var i = iFirstSave + 4;
  43096. var ii = fnArray.length;
  43097. while (i + 3 < ii) {
  43098. if (fnArray[i] !== OPS.save ||
  43099. fnArray[i + 1] !== OPS.transform ||
  43100. fnArray[i + 2] !== OPS.paintImageXObject ||
  43101. fnArray[i + 3] !== OPS.restore) {
  43102. break; // ops don't match
  43103. }
  43104. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  43105. argsArray[i + 1][1] !== 0 ||
  43106. argsArray[i + 1][2] !== 0 ||
  43107. argsArray[i + 1][3] !== firstTransformArg3) {
  43108. break; // transforms don't match
  43109. }
  43110. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  43111. break; // images don't match
  43112. }
  43113. i += 4;
  43114. }
  43115. // At this point, i is the index of the first op past the last valid
  43116. // quartet.
  43117. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  43118. if (count < MIN_IMAGES_IN_BLOCK) {
  43119. return i;
  43120. }
  43121. // Extract the (x,y) positions from all of the matching transforms.
  43122. var positions = new Float32Array(count * 2);
  43123. var iTransform = iFirstTransform;
  43124. for (var q = 0; q < count; q++, iTransform += 4) {
  43125. var transformArgs = argsArray[iTransform];
  43126. positions[(q << 1)] = transformArgs[4];
  43127. positions[(q << 1) + 1] = transformArgs[5];
  43128. }
  43129. // Replace queue items.
  43130. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  43131. positions];
  43132. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  43133. argsArray.splice(iFirstSave, count * 4, args);
  43134. return iFirstSave + 1;
  43135. });
  43136. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  43137. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  43138. // sequences, if the font for each one is the same.
  43139. addState(InitialState,
  43140. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  43141. function (context) {
  43142. var MIN_CHARS_IN_BLOCK = 3;
  43143. var MAX_CHARS_IN_BLOCK = 1000;
  43144. var fnArray = context.fnArray, argsArray = context.argsArray;
  43145. var curr = context.iCurr;
  43146. var iFirstBeginText = curr - 4;
  43147. var iFirstSetFont = curr - 3;
  43148. var iFirstSetTextMatrix = curr - 2;
  43149. var iFirstShowText = curr - 1;
  43150. var iFirstEndText = curr;
  43151. // Look for the quintets.
  43152. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  43153. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  43154. var i = iFirstBeginText + 5;
  43155. var ii = fnArray.length;
  43156. while (i + 4 < ii) {
  43157. if (fnArray[i] !== OPS.beginText ||
  43158. fnArray[i + 1] !== OPS.setFont ||
  43159. fnArray[i + 2] !== OPS.setTextMatrix ||
  43160. fnArray[i + 3] !== OPS.showText ||
  43161. fnArray[i + 4] !== OPS.endText) {
  43162. break; // ops don't match
  43163. }
  43164. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  43165. argsArray[i + 1][1] !== firstSetFontArg1) {
  43166. break; // fonts don't match
  43167. }
  43168. i += 5;
  43169. }
  43170. // At this point, i is the index of the first op past the last valid
  43171. // quintet.
  43172. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  43173. if (count < MIN_CHARS_IN_BLOCK) {
  43174. return i;
  43175. }
  43176. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  43177. // showText, endText), include that as well. (E.g. <something> might be
  43178. // |dependency|.)
  43179. var iFirst = iFirstBeginText;
  43180. if (iFirstBeginText >= 4 &&
  43181. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  43182. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  43183. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  43184. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  43185. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  43186. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  43187. count++;
  43188. iFirst -= 5;
  43189. }
  43190. // Remove (endText, beginText, setFont) trios.
  43191. var iEndText = iFirst + 4;
  43192. for (var q = 1; q < count; q++) {
  43193. fnArray.splice(iEndText, 3);
  43194. argsArray.splice(iEndText, 3);
  43195. iEndText += 2;
  43196. }
  43197. return iEndText + 1;
  43198. });
  43199. function QueueOptimizer() {}
  43200. QueueOptimizer.prototype = {
  43201. optimize: function QueueOptimizer_optimize(queue) {
  43202. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43203. var context = {
  43204. iCurr: 0,
  43205. fnArray: fnArray,
  43206. argsArray: argsArray
  43207. };
  43208. var state;
  43209. var i = 0, ii = fnArray.length;
  43210. while (i < ii) {
  43211. state = (state || InitialState)[fnArray[i]];
  43212. if (typeof state === 'function') { // we found some handler
  43213. context.iCurr = i;
  43214. // state() returns the index of the first non-matching op (if we
  43215. // didn't match) or the first op past the modified ops (if we did
  43216. // match and replace).
  43217. i = state(context);
  43218. state = undefined; // reset the state machine
  43219. ii = context.fnArray.length;
  43220. } else {
  43221. i++;
  43222. }
  43223. }
  43224. }
  43225. };
  43226. return QueueOptimizer;
  43227. })();
  43228. exports.OperatorList = OperatorList;
  43229. exports.PartialEvaluator = PartialEvaluator;
  43230. }));
  43231. (function (root, factory) {
  43232. {
  43233. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  43234. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  43235. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  43236. }
  43237. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  43238. coreColorSpace, coreObj, coreEvaluator) {
  43239. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  43240. var AnnotationFlag = sharedUtil.AnnotationFlag;
  43241. var AnnotationType = sharedUtil.AnnotationType;
  43242. var OPS = sharedUtil.OPS;
  43243. var Util = sharedUtil.Util;
  43244. var isArray = sharedUtil.isArray;
  43245. var isInt = sharedUtil.isInt;
  43246. var isValidUrl = sharedUtil.isValidUrl;
  43247. var stringToBytes = sharedUtil.stringToBytes;
  43248. var stringToPDFString = sharedUtil.stringToPDFString;
  43249. var stringToUTF8String = sharedUtil.stringToUTF8String;
  43250. var warn = sharedUtil.warn;
  43251. var Dict = corePrimitives.Dict;
  43252. var isDict = corePrimitives.isDict;
  43253. var isName = corePrimitives.isName;
  43254. var Stream = coreStream.Stream;
  43255. var ColorSpace = coreColorSpace.ColorSpace;
  43256. var ObjectLoader = coreObj.ObjectLoader;
  43257. var OperatorList = coreEvaluator.OperatorList;
  43258. /**
  43259. * @class
  43260. * @alias AnnotationFactory
  43261. */
  43262. function AnnotationFactory() {}
  43263. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  43264. /**
  43265. * @param {XRef} xref
  43266. * @param {Object} ref
  43267. * @returns {Annotation}
  43268. */
  43269. create: function AnnotationFactory_create(xref, ref) {
  43270. var dict = xref.fetchIfRef(ref);
  43271. if (!isDict(dict)) {
  43272. return;
  43273. }
  43274. // Determine the annotation's subtype.
  43275. var subtype = dict.get('Subtype');
  43276. subtype = isName(subtype) ? subtype.name : '';
  43277. // Return the right annotation object based on the subtype and field type.
  43278. var parameters = {
  43279. dict: dict,
  43280. ref: ref
  43281. };
  43282. switch (subtype) {
  43283. case 'Link':
  43284. return new LinkAnnotation(parameters);
  43285. case 'Text':
  43286. return new TextAnnotation(parameters);
  43287. case 'Widget':
  43288. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43289. if (isName(fieldType) && fieldType.name === 'Tx') {
  43290. return new TextWidgetAnnotation(parameters);
  43291. }
  43292. return new WidgetAnnotation(parameters);
  43293. case 'Popup':
  43294. return new PopupAnnotation(parameters);
  43295. default:
  43296. warn('Unimplemented annotation type "' + subtype + '", ' +
  43297. 'falling back to base annotation');
  43298. return new Annotation(parameters);
  43299. }
  43300. }
  43301. };
  43302. var Annotation = (function AnnotationClosure() {
  43303. // 12.5.5: Algorithm: Appearance streams
  43304. function getTransformMatrix(rect, bbox, matrix) {
  43305. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  43306. var minX = bounds[0];
  43307. var minY = bounds[1];
  43308. var maxX = bounds[2];
  43309. var maxY = bounds[3];
  43310. if (minX === maxX || minY === maxY) {
  43311. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  43312. // just apply the transform for rect
  43313. return [1, 0, 0, 1, rect[0], rect[1]];
  43314. }
  43315. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  43316. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  43317. return [
  43318. xRatio,
  43319. 0,
  43320. 0,
  43321. yRatio,
  43322. rect[0] - minX * xRatio,
  43323. rect[1] - minY * yRatio
  43324. ];
  43325. }
  43326. function getDefaultAppearance(dict) {
  43327. var appearanceState = dict.get('AP');
  43328. if (!isDict(appearanceState)) {
  43329. return;
  43330. }
  43331. var appearance;
  43332. var appearances = appearanceState.get('N');
  43333. if (isDict(appearances)) {
  43334. var as = dict.get('AS');
  43335. if (as && appearances.has(as.name)) {
  43336. appearance = appearances.get(as.name);
  43337. }
  43338. } else {
  43339. appearance = appearances;
  43340. }
  43341. return appearance;
  43342. }
  43343. function Annotation(params) {
  43344. var dict = params.dict;
  43345. this.setFlags(dict.get('F'));
  43346. this.setRectangle(dict.get('Rect'));
  43347. this.setColor(dict.get('C'));
  43348. this.setBorderStyle(dict);
  43349. this.appearance = getDefaultAppearance(dict);
  43350. // Expose public properties using a data object.
  43351. this.data = {};
  43352. this.data.id = params.ref.toString();
  43353. this.data.subtype = dict.get('Subtype').name;
  43354. this.data.annotationFlags = this.flags;
  43355. this.data.rect = this.rectangle;
  43356. this.data.color = this.color;
  43357. this.data.borderStyle = this.borderStyle;
  43358. this.data.hasAppearance = !!this.appearance;
  43359. }
  43360. Annotation.prototype = {
  43361. /**
  43362. * @return {boolean}
  43363. */
  43364. get viewable() {
  43365. if (this.flags) {
  43366. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43367. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  43368. !this.hasFlag(AnnotationFlag.NOVIEW);
  43369. }
  43370. return true;
  43371. },
  43372. /**
  43373. * @return {boolean}
  43374. */
  43375. get printable() {
  43376. if (this.flags) {
  43377. return this.hasFlag(AnnotationFlag.PRINT) &&
  43378. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43379. !this.hasFlag(AnnotationFlag.HIDDEN);
  43380. }
  43381. return false;
  43382. },
  43383. /**
  43384. * Set the flags.
  43385. *
  43386. * @public
  43387. * @memberof Annotation
  43388. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  43389. * characteristics
  43390. * @see {@link shared/util.js}
  43391. */
  43392. setFlags: function Annotation_setFlags(flags) {
  43393. if (isInt(flags)) {
  43394. this.flags = flags;
  43395. } else {
  43396. this.flags = 0;
  43397. }
  43398. },
  43399. /**
  43400. * Check if a provided flag is set.
  43401. *
  43402. * @public
  43403. * @memberof Annotation
  43404. * @param {number} flag - Hexadecimal representation for an annotation
  43405. * characteristic
  43406. * @return {boolean}
  43407. * @see {@link shared/util.js}
  43408. */
  43409. hasFlag: function Annotation_hasFlag(flag) {
  43410. if (this.flags) {
  43411. return (this.flags & flag) > 0;
  43412. }
  43413. return false;
  43414. },
  43415. /**
  43416. * Set the rectangle.
  43417. *
  43418. * @public
  43419. * @memberof Annotation
  43420. * @param {Array} rectangle - The rectangle array with exactly four entries
  43421. */
  43422. setRectangle: function Annotation_setRectangle(rectangle) {
  43423. if (isArray(rectangle) && rectangle.length === 4) {
  43424. this.rectangle = Util.normalizeRect(rectangle);
  43425. } else {
  43426. this.rectangle = [0, 0, 0, 0];
  43427. }
  43428. },
  43429. /**
  43430. * Set the color and take care of color space conversion.
  43431. *
  43432. * @public
  43433. * @memberof Annotation
  43434. * @param {Array} color - The color array containing either 0
  43435. * (transparent), 1 (grayscale), 3 (RGB) or
  43436. * 4 (CMYK) elements
  43437. */
  43438. setColor: function Annotation_setColor(color) {
  43439. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  43440. if (!isArray(color)) {
  43441. this.color = rgbColor;
  43442. return;
  43443. }
  43444. switch (color.length) {
  43445. case 0: // Transparent, which we indicate with a null value
  43446. this.color = null;
  43447. break;
  43448. case 1: // Convert grayscale to RGB
  43449. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  43450. this.color = rgbColor;
  43451. break;
  43452. case 3: // Convert RGB percentages to RGB
  43453. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  43454. this.color = rgbColor;
  43455. break;
  43456. case 4: // Convert CMYK to RGB
  43457. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  43458. this.color = rgbColor;
  43459. break;
  43460. default:
  43461. this.color = rgbColor;
  43462. break;
  43463. }
  43464. },
  43465. /**
  43466. * Set the border style (as AnnotationBorderStyle object).
  43467. *
  43468. * @public
  43469. * @memberof Annotation
  43470. * @param {Dict} borderStyle - The border style dictionary
  43471. */
  43472. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  43473. this.borderStyle = new AnnotationBorderStyle();
  43474. if (!isDict(borderStyle)) {
  43475. return;
  43476. }
  43477. if (borderStyle.has('BS')) {
  43478. var dict = borderStyle.get('BS');
  43479. var dictType;
  43480. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  43481. dictType.name === 'Border')) {
  43482. this.borderStyle.setWidth(dict.get('W'));
  43483. this.borderStyle.setStyle(dict.get('S'));
  43484. this.borderStyle.setDashArray(dict.get('D'));
  43485. }
  43486. } else if (borderStyle.has('Border')) {
  43487. var array = borderStyle.get('Border');
  43488. if (isArray(array) && array.length >= 3) {
  43489. this.borderStyle.setHorizontalCornerRadius(array[0]);
  43490. this.borderStyle.setVerticalCornerRadius(array[1]);
  43491. this.borderStyle.setWidth(array[2]);
  43492. if (array.length === 4) { // Dash array available
  43493. this.borderStyle.setDashArray(array[3]);
  43494. }
  43495. }
  43496. } else {
  43497. // There are no border entries in the dictionary. According to the
  43498. // specification, we should draw a solid border of width 1 in that
  43499. // case, but Adobe Reader did not implement that part of the
  43500. // specification and instead draws no border at all, so we do the same.
  43501. // See also https://github.com/mozilla/pdf.js/issues/6179.
  43502. this.borderStyle.setWidth(0);
  43503. }
  43504. },
  43505. loadResources: function Annotation_loadResources(keys) {
  43506. return new Promise(function (resolve, reject) {
  43507. this.appearance.dict.getAsync('Resources').then(function (resources) {
  43508. if (!resources) {
  43509. resolve();
  43510. return;
  43511. }
  43512. var objectLoader = new ObjectLoader(resources.map,
  43513. keys,
  43514. resources.xref);
  43515. objectLoader.load().then(function() {
  43516. resolve(resources);
  43517. }, reject);
  43518. }, reject);
  43519. }.bind(this));
  43520. },
  43521. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  43522. if (!this.appearance) {
  43523. return Promise.resolve(new OperatorList());
  43524. }
  43525. var data = this.data;
  43526. var appearanceDict = this.appearance.dict;
  43527. var resourcesPromise = this.loadResources([
  43528. 'ExtGState',
  43529. 'ColorSpace',
  43530. 'Pattern',
  43531. 'Shading',
  43532. 'XObject',
  43533. 'Font'
  43534. // ProcSet
  43535. // Properties
  43536. ]);
  43537. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  43538. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  43539. var transform = getTransformMatrix(data.rect, bbox, matrix);
  43540. var self = this;
  43541. return resourcesPromise.then(function(resources) {
  43542. var opList = new OperatorList();
  43543. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  43544. return evaluator.getOperatorList(self.appearance, task,
  43545. resources, opList).
  43546. then(function () {
  43547. opList.addOp(OPS.endAnnotation, []);
  43548. self.appearance.reset();
  43549. return opList;
  43550. });
  43551. });
  43552. }
  43553. };
  43554. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  43555. annotations, opList, partialEvaluator, task, intent) {
  43556. var annotationPromises = [];
  43557. for (var i = 0, n = annotations.length; i < n; ++i) {
  43558. if ((intent === 'display' && annotations[i].viewable) ||
  43559. (intent === 'print' && annotations[i].printable)) {
  43560. annotationPromises.push(
  43561. annotations[i].getOperatorList(partialEvaluator, task));
  43562. }
  43563. }
  43564. return Promise.all(annotationPromises).then(function(operatorLists) {
  43565. opList.addOp(OPS.beginAnnotations, []);
  43566. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  43567. opList.addOpList(operatorLists[i]);
  43568. }
  43569. opList.addOp(OPS.endAnnotations, []);
  43570. });
  43571. };
  43572. return Annotation;
  43573. })();
  43574. /**
  43575. * Contains all data regarding an annotation's border style.
  43576. *
  43577. * @class
  43578. */
  43579. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  43580. /**
  43581. * @constructor
  43582. * @private
  43583. */
  43584. function AnnotationBorderStyle() {
  43585. this.width = 1;
  43586. this.style = AnnotationBorderStyleType.SOLID;
  43587. this.dashArray = [3];
  43588. this.horizontalCornerRadius = 0;
  43589. this.verticalCornerRadius = 0;
  43590. }
  43591. AnnotationBorderStyle.prototype = {
  43592. /**
  43593. * Set the width.
  43594. *
  43595. * @public
  43596. * @memberof AnnotationBorderStyle
  43597. * @param {integer} width - The width
  43598. */
  43599. setWidth: function AnnotationBorderStyle_setWidth(width) {
  43600. if (width === (width | 0)) {
  43601. this.width = width;
  43602. }
  43603. },
  43604. /**
  43605. * Set the style.
  43606. *
  43607. * @public
  43608. * @memberof AnnotationBorderStyle
  43609. * @param {Object} style - The style object
  43610. * @see {@link shared/util.js}
  43611. */
  43612. setStyle: function AnnotationBorderStyle_setStyle(style) {
  43613. if (!style) {
  43614. return;
  43615. }
  43616. switch (style.name) {
  43617. case 'S':
  43618. this.style = AnnotationBorderStyleType.SOLID;
  43619. break;
  43620. case 'D':
  43621. this.style = AnnotationBorderStyleType.DASHED;
  43622. break;
  43623. case 'B':
  43624. this.style = AnnotationBorderStyleType.BEVELED;
  43625. break;
  43626. case 'I':
  43627. this.style = AnnotationBorderStyleType.INSET;
  43628. break;
  43629. case 'U':
  43630. this.style = AnnotationBorderStyleType.UNDERLINE;
  43631. break;
  43632. default:
  43633. break;
  43634. }
  43635. },
  43636. /**
  43637. * Set the dash array.
  43638. *
  43639. * @public
  43640. * @memberof AnnotationBorderStyle
  43641. * @param {Array} dashArray - The dash array with at least one element
  43642. */
  43643. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  43644. // We validate the dash array, but we do not use it because CSS does not
  43645. // allow us to change spacing of dashes. For more information, visit
  43646. // http://www.w3.org/TR/css3-background/#the-border-style.
  43647. if (isArray(dashArray) && dashArray.length > 0) {
  43648. // According to the PDF specification: the elements in a dashArray
  43649. // shall be numbers that are nonnegative and not all equal to zero.
  43650. var isValid = true;
  43651. var allZeros = true;
  43652. for (var i = 0, len = dashArray.length; i < len; i++) {
  43653. var element = dashArray[i];
  43654. var validNumber = (+element >= 0);
  43655. if (!validNumber) {
  43656. isValid = false;
  43657. break;
  43658. } else if (element > 0) {
  43659. allZeros = false;
  43660. }
  43661. }
  43662. if (isValid && !allZeros) {
  43663. this.dashArray = dashArray;
  43664. } else {
  43665. this.width = 0; // Adobe behavior when the array is invalid.
  43666. }
  43667. } else if (dashArray) {
  43668. this.width = 0; // Adobe behavior when the array is invalid.
  43669. }
  43670. },
  43671. /**
  43672. * Set the horizontal corner radius (from a Border dictionary).
  43673. *
  43674. * @public
  43675. * @memberof AnnotationBorderStyle
  43676. * @param {integer} radius - The horizontal corner radius
  43677. */
  43678. setHorizontalCornerRadius:
  43679. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  43680. if (radius === (radius | 0)) {
  43681. this.horizontalCornerRadius = radius;
  43682. }
  43683. },
  43684. /**
  43685. * Set the vertical corner radius (from a Border dictionary).
  43686. *
  43687. * @public
  43688. * @memberof AnnotationBorderStyle
  43689. * @param {integer} radius - The vertical corner radius
  43690. */
  43691. setVerticalCornerRadius:
  43692. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  43693. if (radius === (radius | 0)) {
  43694. this.verticalCornerRadius = radius;
  43695. }
  43696. }
  43697. };
  43698. return AnnotationBorderStyle;
  43699. })();
  43700. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  43701. function WidgetAnnotation(params) {
  43702. Annotation.call(this, params);
  43703. var dict = params.dict;
  43704. var data = this.data;
  43705. data.annotationType = AnnotationType.WIDGET;
  43706. data.fieldValue = stringToPDFString(
  43707. Util.getInheritableProperty(dict, 'V') || '');
  43708. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  43709. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  43710. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43711. data.fieldType = isName(fieldType) ? fieldType.name : '';
  43712. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  43713. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  43714. // Hide unsupported Widget signatures.
  43715. if (data.fieldType === 'Sig') {
  43716. warn('unimplemented annotation type: Widget signature');
  43717. this.setFlags(AnnotationFlag.HIDDEN);
  43718. }
  43719. // Building the full field name by collecting the field and
  43720. // its ancestors 'T' data and joining them using '.'.
  43721. var fieldName = [];
  43722. var namedItem = dict;
  43723. var ref = params.ref;
  43724. while (namedItem) {
  43725. var parent = namedItem.get('Parent');
  43726. var parentRef = namedItem.getRaw('Parent');
  43727. var name = namedItem.get('T');
  43728. if (name) {
  43729. fieldName.unshift(stringToPDFString(name));
  43730. } else if (parent && ref) {
  43731. // The field name is absent, that means more than one field
  43732. // with the same name may exist. Replacing the empty name
  43733. // with the '`' plus index in the parent's 'Kids' array.
  43734. // This is not in the PDF spec but necessary to id the
  43735. // the input controls.
  43736. var kids = parent.get('Kids');
  43737. var j, jj;
  43738. for (j = 0, jj = kids.length; j < jj; j++) {
  43739. var kidRef = kids[j];
  43740. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  43741. break;
  43742. }
  43743. }
  43744. fieldName.unshift('`' + j);
  43745. }
  43746. namedItem = parent;
  43747. ref = parentRef;
  43748. }
  43749. data.fullName = fieldName.join('.');
  43750. }
  43751. Util.inherit(WidgetAnnotation, Annotation, {});
  43752. return WidgetAnnotation;
  43753. })();
  43754. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  43755. function TextWidgetAnnotation(params) {
  43756. WidgetAnnotation.call(this, params);
  43757. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  43758. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  43759. }
  43760. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  43761. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  43762. task) {
  43763. if (this.appearance) {
  43764. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  43765. }
  43766. var opList = new OperatorList();
  43767. var data = this.data;
  43768. // Even if there is an appearance stream, ignore it. This is the
  43769. // behaviour used by Adobe Reader.
  43770. if (!data.defaultAppearance) {
  43771. return Promise.resolve(opList);
  43772. }
  43773. var stream = new Stream(stringToBytes(data.defaultAppearance));
  43774. return evaluator.getOperatorList(stream, task,
  43775. this.fieldResources, opList).
  43776. then(function () {
  43777. return opList;
  43778. });
  43779. }
  43780. });
  43781. return TextWidgetAnnotation;
  43782. })();
  43783. var TextAnnotation = (function TextAnnotationClosure() {
  43784. var DEFAULT_ICON_SIZE = 22; // px
  43785. function TextAnnotation(parameters) {
  43786. Annotation.call(this, parameters);
  43787. this.data.annotationType = AnnotationType.TEXT;
  43788. this.data.hasHtml = true;
  43789. var dict = parameters.dict;
  43790. if (this.data.hasAppearance) {
  43791. this.data.name = 'NoIcon';
  43792. } else {
  43793. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  43794. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  43795. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  43796. }
  43797. if (!dict.has('C')) {
  43798. // Fall back to the default background color.
  43799. this.data.color = null;
  43800. }
  43801. this.data.hasPopup = dict.has('Popup');
  43802. if (!this.data.hasPopup) {
  43803. // There is no associated Popup annotation, so the Text annotation
  43804. // must create its own popup.
  43805. this.data.title = stringToPDFString(dict.get('T') || '');
  43806. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  43807. this.data.hasHtml = (this.data.title || this.data.contents);
  43808. }
  43809. }
  43810. Util.inherit(TextAnnotation, Annotation, {});
  43811. return TextAnnotation;
  43812. })();
  43813. var LinkAnnotation = (function LinkAnnotationClosure() {
  43814. function LinkAnnotation(params) {
  43815. Annotation.call(this, params);
  43816. var dict = params.dict;
  43817. var data = this.data;
  43818. data.annotationType = AnnotationType.LINK;
  43819. data.hasHtml = true;
  43820. var action = dict.get('A');
  43821. if (action && isDict(action)) {
  43822. var linkType = action.get('S').name;
  43823. if (linkType === 'URI') {
  43824. var url = action.get('URI');
  43825. if (isName(url)) {
  43826. // Some bad PDFs do not put parentheses around relative URLs.
  43827. url = '/' + url.name;
  43828. } else if (url) {
  43829. url = addDefaultProtocolToUrl(url);
  43830. }
  43831. // TODO: pdf spec mentions urls can be relative to a Base
  43832. // entry in the dictionary.
  43833. if (!isValidUrl(url, false)) {
  43834. url = '';
  43835. }
  43836. // According to ISO 32000-1:2008, section 12.6.4.7,
  43837. // URI should to be encoded in 7-bit ASCII.
  43838. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  43839. try {
  43840. data.url = stringToUTF8String(url);
  43841. } catch (e) {
  43842. // Fall back to a simple copy.
  43843. data.url = url;
  43844. }
  43845. } else if (linkType === 'GoTo') {
  43846. data.dest = action.get('D');
  43847. } else if (linkType === 'GoToR') {
  43848. var urlDict = action.get('F');
  43849. if (isDict(urlDict)) {
  43850. // We assume that the 'url' is a Filspec dictionary
  43851. // and fetch the url without checking any further
  43852. url = urlDict.get('F') || '';
  43853. }
  43854. // TODO: pdf reference says that GoToR
  43855. // can also have 'NewWindow' attribute
  43856. if (!isValidUrl(url, false)) {
  43857. url = '';
  43858. }
  43859. data.url = url;
  43860. data.dest = action.get('D');
  43861. } else if (linkType === 'Named') {
  43862. data.action = action.get('N').name;
  43863. } else {
  43864. warn('unrecognized link type: ' + linkType);
  43865. }
  43866. } else if (dict.has('Dest')) {
  43867. // simple destination link
  43868. var dest = dict.get('Dest');
  43869. data.dest = isName(dest) ? dest.name : dest;
  43870. }
  43871. }
  43872. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  43873. function addDefaultProtocolToUrl(url) {
  43874. if (url && url.indexOf('www.') === 0) {
  43875. return ('http://' + url);
  43876. }
  43877. return url;
  43878. }
  43879. Util.inherit(LinkAnnotation, Annotation, {});
  43880. return LinkAnnotation;
  43881. })();
  43882. var PopupAnnotation = (function PopupAnnotationClosure() {
  43883. function PopupAnnotation(parameters) {
  43884. Annotation.call(this, parameters);
  43885. this.data.annotationType = AnnotationType.POPUP;
  43886. var dict = parameters.dict;
  43887. var parentItem = dict.get('Parent');
  43888. if (!parentItem) {
  43889. warn('Popup annotation has a missing or invalid parent annotation.');
  43890. return;
  43891. }
  43892. this.data.parentId = dict.getRaw('Parent').toString();
  43893. this.data.title = stringToPDFString(parentItem.get('T') || '');
  43894. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  43895. if (!parentItem.has('C')) {
  43896. // Fall back to the default background color.
  43897. this.data.color = null;
  43898. } else {
  43899. this.setColor(parentItem.get('C'));
  43900. this.data.color = this.color;
  43901. }
  43902. this.data.hasHtml = (this.data.title || this.data.contents);
  43903. }
  43904. Util.inherit(PopupAnnotation, Annotation, {});
  43905. return PopupAnnotation;
  43906. })();
  43907. exports.Annotation = Annotation;
  43908. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  43909. exports.AnnotationFactory = AnnotationFactory;
  43910. }));
  43911. (function (root, factory) {
  43912. {
  43913. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  43914. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  43915. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  43916. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  43917. }
  43918. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  43919. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  43920. var MissingDataException = sharedUtil.MissingDataException;
  43921. var Util = sharedUtil.Util;
  43922. var assert = sharedUtil.assert;
  43923. var error = sharedUtil.error;
  43924. var info = sharedUtil.info;
  43925. var isArray = sharedUtil.isArray;
  43926. var isArrayBuffer = sharedUtil.isArrayBuffer;
  43927. var isString = sharedUtil.isString;
  43928. var shadow = sharedUtil.shadow;
  43929. var stringToBytes = sharedUtil.stringToBytes;
  43930. var stringToPDFString = sharedUtil.stringToPDFString;
  43931. var warn = sharedUtil.warn;
  43932. var Dict = corePrimitives.Dict;
  43933. var isDict = corePrimitives.isDict;
  43934. var isName = corePrimitives.isName;
  43935. var isStream = corePrimitives.isStream;
  43936. var NullStream = coreStream.NullStream;
  43937. var Stream = coreStream.Stream;
  43938. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  43939. var Catalog = coreObj.Catalog;
  43940. var ObjectLoader = coreObj.ObjectLoader;
  43941. var XRef = coreObj.XRef;
  43942. var Lexer = coreParser.Lexer;
  43943. var Linearization = coreParser.Linearization;
  43944. var calculateMD5 = coreCrypto.calculateMD5;
  43945. var OperatorList = coreEvaluator.OperatorList;
  43946. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  43947. var Annotation = coreAnnotation.Annotation;
  43948. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  43949. var Page = (function PageClosure() {
  43950. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  43951. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  43952. this.pdfManager = pdfManager;
  43953. this.pageIndex = pageIndex;
  43954. this.pageDict = pageDict;
  43955. this.xref = xref;
  43956. this.ref = ref;
  43957. this.fontCache = fontCache;
  43958. this.idCounters = {
  43959. obj: 0
  43960. };
  43961. this.resourcesPromise = null;
  43962. }
  43963. Page.prototype = {
  43964. getPageProp: function Page_getPageProp(key) {
  43965. return this.pageDict.get(key);
  43966. },
  43967. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  43968. var dict = this.pageDict, valueArray = null, loopCount = 0;
  43969. var MAX_LOOP_COUNT = 100;
  43970. // Always walk up the entire parent chain, to be able to find
  43971. // e.g. \Resources placed on multiple levels of the tree.
  43972. while (dict) {
  43973. var value = dict.get(key);
  43974. if (value) {
  43975. if (!valueArray) {
  43976. valueArray = [];
  43977. }
  43978. valueArray.push(value);
  43979. }
  43980. if (++loopCount > MAX_LOOP_COUNT) {
  43981. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  43982. break;
  43983. }
  43984. dict = dict.get('Parent');
  43985. }
  43986. if (!valueArray) {
  43987. return Dict.empty;
  43988. }
  43989. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  43990. loopCount > MAX_LOOP_COUNT) {
  43991. return valueArray[0];
  43992. }
  43993. return Dict.merge(this.xref, valueArray);
  43994. },
  43995. get content() {
  43996. return this.getPageProp('Contents');
  43997. },
  43998. get resources() {
  43999. // For robustness: The spec states that a \Resources entry has to be
  44000. // present, but can be empty. Some document omit it still, in this case
  44001. // we return an empty dictionary.
  44002. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  44003. },
  44004. get mediaBox() {
  44005. var obj = this.getInheritedPageProp('MediaBox');
  44006. // Reset invalid media box to letter size.
  44007. if (!isArray(obj) || obj.length !== 4) {
  44008. obj = LETTER_SIZE_MEDIABOX;
  44009. }
  44010. return shadow(this, 'mediaBox', obj);
  44011. },
  44012. get view() {
  44013. var mediaBox = this.mediaBox;
  44014. var cropBox = this.getInheritedPageProp('CropBox');
  44015. if (!isArray(cropBox) || cropBox.length !== 4) {
  44016. return shadow(this, 'view', mediaBox);
  44017. }
  44018. // From the spec, 6th ed., p.963:
  44019. // "The crop, bleed, trim, and art boxes should not ordinarily
  44020. // extend beyond the boundaries of the media box. If they do, they are
  44021. // effectively reduced to their intersection with the media box."
  44022. cropBox = Util.intersect(cropBox, mediaBox);
  44023. if (!cropBox) {
  44024. return shadow(this, 'view', mediaBox);
  44025. }
  44026. return shadow(this, 'view', cropBox);
  44027. },
  44028. get rotate() {
  44029. var rotate = this.getInheritedPageProp('Rotate') || 0;
  44030. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  44031. if (rotate % 90 !== 0) {
  44032. rotate = 0;
  44033. } else if (rotate >= 360) {
  44034. rotate = rotate % 360;
  44035. } else if (rotate < 0) {
  44036. // The spec doesn't cover negatives, assume its counterclockwise
  44037. // rotation. The following is the other implementation of modulo.
  44038. rotate = ((rotate % 360) + 360) % 360;
  44039. }
  44040. return shadow(this, 'rotate', rotate);
  44041. },
  44042. getContentStream: function Page_getContentStream() {
  44043. var content = this.content;
  44044. var stream;
  44045. if (isArray(content)) {
  44046. // fetching items
  44047. var xref = this.xref;
  44048. var i, n = content.length;
  44049. var streams = [];
  44050. for (i = 0; i < n; ++i) {
  44051. streams.push(xref.fetchIfRef(content[i]));
  44052. }
  44053. stream = new StreamsSequenceStream(streams);
  44054. } else if (isStream(content)) {
  44055. stream = content;
  44056. } else {
  44057. // replacing non-existent page content with empty one
  44058. stream = new NullStream();
  44059. }
  44060. return stream;
  44061. },
  44062. loadResources: function Page_loadResources(keys) {
  44063. if (!this.resourcesPromise) {
  44064. // TODO: add async getInheritedPageProp and remove this.
  44065. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  44066. }
  44067. return this.resourcesPromise.then(function resourceSuccess() {
  44068. var objectLoader = new ObjectLoader(this.resources.map,
  44069. keys,
  44070. this.xref);
  44071. return objectLoader.load();
  44072. }.bind(this));
  44073. },
  44074. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  44075. var self = this;
  44076. var pdfManager = this.pdfManager;
  44077. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44078. []);
  44079. var resourcesPromise = this.loadResources([
  44080. 'ExtGState',
  44081. 'ColorSpace',
  44082. 'Pattern',
  44083. 'Shading',
  44084. 'XObject',
  44085. 'Font'
  44086. // ProcSet
  44087. // Properties
  44088. ]);
  44089. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  44090. handler, this.pageIndex,
  44091. 'p' + this.pageIndex + '_',
  44092. this.idCounters,
  44093. this.fontCache);
  44094. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  44095. var pageListPromise = dataPromises.then(function(data) {
  44096. var contentStream = data[0];
  44097. var opList = new OperatorList(intent, handler, self.pageIndex);
  44098. handler.send('StartRenderPage', {
  44099. transparency: partialEvaluator.hasBlendModes(self.resources),
  44100. pageIndex: self.pageIndex,
  44101. intent: intent
  44102. });
  44103. return partialEvaluator.getOperatorList(contentStream, task,
  44104. self.resources, opList).then(function () {
  44105. return opList;
  44106. });
  44107. });
  44108. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  44109. return Promise.all([pageListPromise, annotationsPromise]).then(
  44110. function(datas) {
  44111. var pageOpList = datas[0];
  44112. var annotations = datas[1];
  44113. if (annotations.length === 0) {
  44114. pageOpList.flush(true);
  44115. return pageOpList;
  44116. }
  44117. var annotationsReadyPromise = Annotation.appendToOperatorList(
  44118. annotations, pageOpList, partialEvaluator, task, intent);
  44119. return annotationsReadyPromise.then(function () {
  44120. pageOpList.flush(true);
  44121. return pageOpList;
  44122. });
  44123. });
  44124. },
  44125. extractTextContent: function Page_extractTextContent(task,
  44126. normalizeWhitespace) {
  44127. var handler = {
  44128. on: function nullHandlerOn() {},
  44129. send: function nullHandlerSend() {}
  44130. };
  44131. var self = this;
  44132. var pdfManager = this.pdfManager;
  44133. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44134. []);
  44135. var resourcesPromise = this.loadResources([
  44136. 'ExtGState',
  44137. 'XObject',
  44138. 'Font'
  44139. ]);
  44140. var dataPromises = Promise.all([contentStreamPromise,
  44141. resourcesPromise]);
  44142. return dataPromises.then(function(data) {
  44143. var contentStream = data[0];
  44144. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  44145. handler, self.pageIndex,
  44146. 'p' + self.pageIndex + '_',
  44147. self.idCounters,
  44148. self.fontCache);
  44149. return partialEvaluator.getTextContent(contentStream,
  44150. task,
  44151. self.resources,
  44152. /* stateManager = */ null,
  44153. normalizeWhitespace);
  44154. });
  44155. },
  44156. getAnnotationsData: function Page_getAnnotationsData(intent) {
  44157. var annotations = this.annotations;
  44158. var annotationsData = [];
  44159. for (var i = 0, n = annotations.length; i < n; ++i) {
  44160. if (intent) {
  44161. if (!(intent === 'display' && annotations[i].viewable) &&
  44162. !(intent === 'print' && annotations[i].printable)) {
  44163. continue;
  44164. }
  44165. }
  44166. annotationsData.push(annotations[i].data);
  44167. }
  44168. return annotationsData;
  44169. },
  44170. get annotations() {
  44171. var annotations = [];
  44172. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  44173. var annotationFactory = new AnnotationFactory();
  44174. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  44175. var annotationRef = annotationRefs[i];
  44176. var annotation = annotationFactory.create(this.xref, annotationRef);
  44177. if (annotation) {
  44178. annotations.push(annotation);
  44179. }
  44180. }
  44181. return shadow(this, 'annotations', annotations);
  44182. }
  44183. };
  44184. return Page;
  44185. })();
  44186. /**
  44187. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  44188. * `PDFDoc`, this one doesn't have any job management code.
  44189. * Right now there exists one PDFDocument on the main thread + one object
  44190. * for each worker. If there is no worker support enabled, there are two
  44191. * `PDFDocument` objects on the main thread created.
  44192. */
  44193. var PDFDocument = (function PDFDocumentClosure() {
  44194. var FINGERPRINT_FIRST_BYTES = 1024;
  44195. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  44196. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  44197. function PDFDocument(pdfManager, arg, password) {
  44198. if (isStream(arg)) {
  44199. init.call(this, pdfManager, arg, password);
  44200. } else if (isArrayBuffer(arg)) {
  44201. init.call(this, pdfManager, new Stream(arg), password);
  44202. } else {
  44203. error('PDFDocument: Unknown argument type');
  44204. }
  44205. }
  44206. function init(pdfManager, stream, password) {
  44207. assert(stream.length > 0, 'stream must have data');
  44208. this.pdfManager = pdfManager;
  44209. this.stream = stream;
  44210. var xref = new XRef(this.stream, password, pdfManager);
  44211. this.xref = xref;
  44212. }
  44213. function find(stream, needle, limit, backwards) {
  44214. var pos = stream.pos;
  44215. var end = stream.end;
  44216. var strBuf = [];
  44217. if (pos + limit > end) {
  44218. limit = end - pos;
  44219. }
  44220. for (var n = 0; n < limit; ++n) {
  44221. strBuf.push(String.fromCharCode(stream.getByte()));
  44222. }
  44223. var str = strBuf.join('');
  44224. stream.pos = pos;
  44225. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  44226. if (index === -1) {
  44227. return false; /* not found */
  44228. }
  44229. stream.pos += index;
  44230. return true; /* found */
  44231. }
  44232. var DocumentInfoValidators = {
  44233. get entries() {
  44234. // Lazily build this since all the validation functions below are not
  44235. // defined until after this file loads.
  44236. return shadow(this, 'entries', {
  44237. Title: isString,
  44238. Author: isString,
  44239. Subject: isString,
  44240. Keywords: isString,
  44241. Creator: isString,
  44242. Producer: isString,
  44243. CreationDate: isString,
  44244. ModDate: isString,
  44245. Trapped: isName
  44246. });
  44247. }
  44248. };
  44249. PDFDocument.prototype = {
  44250. parse: function PDFDocument_parse(recoveryMode) {
  44251. this.setup(recoveryMode);
  44252. var version = this.catalog.catDict.get('Version');
  44253. if (isName(version)) {
  44254. this.pdfFormatVersion = version.name;
  44255. }
  44256. try {
  44257. // checking if AcroForm is present
  44258. this.acroForm = this.catalog.catDict.get('AcroForm');
  44259. if (this.acroForm) {
  44260. this.xfa = this.acroForm.get('XFA');
  44261. var fields = this.acroForm.get('Fields');
  44262. if ((!fields || !isArray(fields) || fields.length === 0) &&
  44263. !this.xfa) {
  44264. // no fields and no XFA -- not a form (?)
  44265. this.acroForm = null;
  44266. }
  44267. }
  44268. } catch (ex) {
  44269. info('Something wrong with AcroForm entry');
  44270. this.acroForm = null;
  44271. }
  44272. },
  44273. get linearization() {
  44274. var linearization = null;
  44275. if (this.stream.length) {
  44276. try {
  44277. linearization = Linearization.create(this.stream);
  44278. } catch (err) {
  44279. if (err instanceof MissingDataException) {
  44280. throw err;
  44281. }
  44282. info(err);
  44283. }
  44284. }
  44285. // shadow the prototype getter with a data property
  44286. return shadow(this, 'linearization', linearization);
  44287. },
  44288. get startXRef() {
  44289. var stream = this.stream;
  44290. var startXRef = 0;
  44291. var linearization = this.linearization;
  44292. if (linearization) {
  44293. // Find end of first obj.
  44294. stream.reset();
  44295. if (find(stream, 'endobj', 1024)) {
  44296. startXRef = stream.pos + 6;
  44297. }
  44298. } else {
  44299. // Find startxref by jumping backward from the end of the file.
  44300. var step = 1024;
  44301. var found = false, pos = stream.end;
  44302. while (!found && pos > 0) {
  44303. pos -= step - 'startxref'.length;
  44304. if (pos < 0) {
  44305. pos = 0;
  44306. }
  44307. stream.pos = pos;
  44308. found = find(stream, 'startxref', step, true);
  44309. }
  44310. if (found) {
  44311. stream.skip(9);
  44312. var ch;
  44313. do {
  44314. ch = stream.getByte();
  44315. } while (Lexer.isSpace(ch));
  44316. var str = '';
  44317. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  44318. str += String.fromCharCode(ch);
  44319. ch = stream.getByte();
  44320. }
  44321. startXRef = parseInt(str, 10);
  44322. if (isNaN(startXRef)) {
  44323. startXRef = 0;
  44324. }
  44325. }
  44326. }
  44327. // shadow the prototype getter with a data property
  44328. return shadow(this, 'startXRef', startXRef);
  44329. },
  44330. get mainXRefEntriesOffset() {
  44331. var mainXRefEntriesOffset = 0;
  44332. var linearization = this.linearization;
  44333. if (linearization) {
  44334. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  44335. }
  44336. // shadow the prototype getter with a data property
  44337. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  44338. },
  44339. // Find the header, remove leading garbage and setup the stream
  44340. // starting from the header.
  44341. checkHeader: function PDFDocument_checkHeader() {
  44342. var stream = this.stream;
  44343. stream.reset();
  44344. if (find(stream, '%PDF-', 1024)) {
  44345. // Found the header, trim off any garbage before it.
  44346. stream.moveStart();
  44347. // Reading file format version
  44348. var MAX_VERSION_LENGTH = 12;
  44349. var version = '', ch;
  44350. while ((ch = stream.getByte()) > 0x20) { // SPACE
  44351. if (version.length >= MAX_VERSION_LENGTH) {
  44352. break;
  44353. }
  44354. version += String.fromCharCode(ch);
  44355. }
  44356. if (!this.pdfFormatVersion) {
  44357. // removing "%PDF-"-prefix
  44358. this.pdfFormatVersion = version.substring(5);
  44359. }
  44360. return;
  44361. }
  44362. // May not be a PDF file, continue anyway.
  44363. },
  44364. parseStartXRef: function PDFDocument_parseStartXRef() {
  44365. var startXRef = this.startXRef;
  44366. this.xref.setStartXRef(startXRef);
  44367. },
  44368. setup: function PDFDocument_setup(recoveryMode) {
  44369. this.xref.parse(recoveryMode);
  44370. var self = this;
  44371. var pageFactory = {
  44372. createPage: function (pageIndex, dict, ref, fontCache) {
  44373. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  44374. fontCache);
  44375. }
  44376. };
  44377. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  44378. },
  44379. get numPages() {
  44380. var linearization = this.linearization;
  44381. var num = linearization ? linearization.numPages : this.catalog.numPages;
  44382. // shadow the prototype getter
  44383. return shadow(this, 'numPages', num);
  44384. },
  44385. get documentInfo() {
  44386. var docInfo = {
  44387. PDFFormatVersion: this.pdfFormatVersion,
  44388. IsAcroFormPresent: !!this.acroForm,
  44389. IsXFAPresent: !!this.xfa
  44390. };
  44391. var infoDict;
  44392. try {
  44393. infoDict = this.xref.trailer.get('Info');
  44394. } catch (err) {
  44395. info('The document information dictionary is invalid.');
  44396. }
  44397. if (infoDict) {
  44398. var validEntries = DocumentInfoValidators.entries;
  44399. // Only fill the document info with valid entries from the spec.
  44400. for (var key in validEntries) {
  44401. if (infoDict.has(key)) {
  44402. var value = infoDict.get(key);
  44403. // Make sure the value conforms to the spec.
  44404. if (validEntries[key](value)) {
  44405. docInfo[key] = (typeof value !== 'string' ?
  44406. value : stringToPDFString(value));
  44407. } else {
  44408. info('Bad value in document info for "' + key + '"');
  44409. }
  44410. }
  44411. }
  44412. }
  44413. return shadow(this, 'documentInfo', docInfo);
  44414. },
  44415. get fingerprint() {
  44416. var xref = this.xref, hash, fileID = '';
  44417. var idArray = xref.trailer.get('ID');
  44418. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  44419. idArray[0] !== EMPTY_FINGERPRINT) {
  44420. hash = stringToBytes(idArray[0]);
  44421. } else {
  44422. if (this.stream.ensureRange) {
  44423. this.stream.ensureRange(0,
  44424. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  44425. }
  44426. hash = calculateMD5(this.stream.bytes.subarray(0,
  44427. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  44428. }
  44429. for (var i = 0, n = hash.length; i < n; i++) {
  44430. var hex = hash[i].toString(16);
  44431. fileID += hex.length === 1 ? '0' + hex : hex;
  44432. }
  44433. return shadow(this, 'fingerprint', fileID);
  44434. },
  44435. getPage: function PDFDocument_getPage(pageIndex) {
  44436. return this.catalog.getPage(pageIndex);
  44437. },
  44438. cleanup: function PDFDocument_cleanup() {
  44439. return this.catalog.cleanup();
  44440. }
  44441. };
  44442. return PDFDocument;
  44443. })();
  44444. exports.Page = Page;
  44445. exports.PDFDocument = PDFDocument;
  44446. }));
  44447. (function (root, factory) {
  44448. {
  44449. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  44450. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  44451. root.pdfjsCoreDocument);
  44452. }
  44453. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  44454. coreDocument) {
  44455. var NotImplementedException = sharedUtil.NotImplementedException;
  44456. var MissingDataException = sharedUtil.MissingDataException;
  44457. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44458. var Util = sharedUtil.Util;
  44459. var Stream = coreStream.Stream;
  44460. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  44461. var PDFDocument = coreDocument.PDFDocument;
  44462. var BasePdfManager = (function BasePdfManagerClosure() {
  44463. function BasePdfManager() {
  44464. throw new Error('Cannot initialize BaseManagerManager');
  44465. }
  44466. BasePdfManager.prototype = {
  44467. get docId() {
  44468. return this._docId;
  44469. },
  44470. onLoadedStream: function BasePdfManager_onLoadedStream() {
  44471. throw new NotImplementedException();
  44472. },
  44473. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  44474. return this.ensure(this.pdfDocument, prop, args);
  44475. },
  44476. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  44477. return this.ensure(this.pdfDocument.xref, prop, args);
  44478. },
  44479. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  44480. return this.ensure(this.pdfDocument.catalog, prop, args);
  44481. },
  44482. getPage: function BasePdfManager_getPage(pageIndex) {
  44483. return this.pdfDocument.getPage(pageIndex);
  44484. },
  44485. cleanup: function BasePdfManager_cleanup() {
  44486. return this.pdfDocument.cleanup();
  44487. },
  44488. ensure: function BasePdfManager_ensure(obj, prop, args) {
  44489. return new NotImplementedException();
  44490. },
  44491. requestRange: function BasePdfManager_requestRange(begin, end) {
  44492. return new NotImplementedException();
  44493. },
  44494. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  44495. return new NotImplementedException();
  44496. },
  44497. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  44498. return new NotImplementedException();
  44499. },
  44500. updatePassword: function BasePdfManager_updatePassword(password) {
  44501. this.pdfDocument.xref.password = this.password = password;
  44502. if (this._passwordChangedCapability) {
  44503. this._passwordChangedCapability.resolve();
  44504. }
  44505. },
  44506. passwordChanged: function BasePdfManager_passwordChanged() {
  44507. this._passwordChangedCapability = createPromiseCapability();
  44508. return this._passwordChangedCapability.promise;
  44509. },
  44510. terminate: function BasePdfManager_terminate() {
  44511. return new NotImplementedException();
  44512. }
  44513. };
  44514. return BasePdfManager;
  44515. })();
  44516. var LocalPdfManager = (function LocalPdfManagerClosure() {
  44517. function LocalPdfManager(docId, data, password) {
  44518. this._docId = docId;
  44519. var stream = new Stream(data);
  44520. this.pdfDocument = new PDFDocument(this, stream, password);
  44521. this._loadedStreamCapability = createPromiseCapability();
  44522. this._loadedStreamCapability.resolve(stream);
  44523. }
  44524. Util.inherit(LocalPdfManager, BasePdfManager, {
  44525. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  44526. return new Promise(function (resolve, reject) {
  44527. try {
  44528. var value = obj[prop];
  44529. var result;
  44530. if (typeof value === 'function') {
  44531. result = value.apply(obj, args);
  44532. } else {
  44533. result = value;
  44534. }
  44535. resolve(result);
  44536. } catch (e) {
  44537. reject(e);
  44538. }
  44539. });
  44540. },
  44541. requestRange: function LocalPdfManager_requestRange(begin, end) {
  44542. return Promise.resolve();
  44543. },
  44544. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  44545. return;
  44546. },
  44547. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  44548. return this._loadedStreamCapability.promise;
  44549. },
  44550. terminate: function LocalPdfManager_terminate() {
  44551. return;
  44552. }
  44553. });
  44554. return LocalPdfManager;
  44555. })();
  44556. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  44557. function NetworkPdfManager(docId, args, msgHandler) {
  44558. this._docId = docId;
  44559. this.msgHandler = msgHandler;
  44560. var params = {
  44561. msgHandler: msgHandler,
  44562. httpHeaders: args.httpHeaders,
  44563. withCredentials: args.withCredentials,
  44564. chunkedViewerLoading: args.chunkedViewerLoading,
  44565. disableAutoFetch: args.disableAutoFetch,
  44566. initialData: args.initialData
  44567. };
  44568. this.streamManager = new ChunkedStreamManager(args.length,
  44569. args.rangeChunkSize,
  44570. args.url, params);
  44571. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  44572. args.password);
  44573. }
  44574. Util.inherit(NetworkPdfManager, BasePdfManager, {
  44575. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  44576. var pdfManager = this;
  44577. return new Promise(function (resolve, reject) {
  44578. function ensureHelper() {
  44579. try {
  44580. var result;
  44581. var value = obj[prop];
  44582. if (typeof value === 'function') {
  44583. result = value.apply(obj, args);
  44584. } else {
  44585. result = value;
  44586. }
  44587. resolve(result);
  44588. } catch(e) {
  44589. if (!(e instanceof MissingDataException)) {
  44590. reject(e);
  44591. return;
  44592. }
  44593. pdfManager.streamManager.requestRange(e.begin, e.end).
  44594. then(ensureHelper, reject);
  44595. }
  44596. }
  44597. ensureHelper();
  44598. });
  44599. },
  44600. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  44601. return this.streamManager.requestRange(begin, end);
  44602. },
  44603. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  44604. this.streamManager.requestAllChunks();
  44605. },
  44606. sendProgressiveData:
  44607. function NetworkPdfManager_sendProgressiveData(chunk) {
  44608. this.streamManager.onReceiveData({ chunk: chunk });
  44609. },
  44610. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  44611. return this.streamManager.onLoadedStream();
  44612. },
  44613. terminate: function NetworkPdfManager_terminate() {
  44614. this.streamManager.abort();
  44615. }
  44616. });
  44617. return NetworkPdfManager;
  44618. })();
  44619. exports.LocalPdfManager = LocalPdfManager;
  44620. exports.NetworkPdfManager = NetworkPdfManager;
  44621. }));
  44622. (function (root, factory) {
  44623. {
  44624. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  44625. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  44626. root.pdfjsSharedGlobal);
  44627. }
  44628. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  44629. sharedGlobal) {
  44630. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  44631. var InvalidPDFException = sharedUtil.InvalidPDFException;
  44632. var MessageHandler = sharedUtil.MessageHandler;
  44633. var MissingPDFException = sharedUtil.MissingPDFException;
  44634. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  44635. var PasswordException = sharedUtil.PasswordException;
  44636. var PasswordResponses = sharedUtil.PasswordResponses;
  44637. var UnknownErrorException = sharedUtil.UnknownErrorException;
  44638. var XRefParseException = sharedUtil.XRefParseException;
  44639. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44640. var error = sharedUtil.error;
  44641. var info = sharedUtil.info;
  44642. var isInt = sharedUtil.isInt;
  44643. var warn = sharedUtil.warn;
  44644. var Ref = corePrimitives.Ref;
  44645. var LocalPdfManager = corePdfManager.LocalPdfManager;
  44646. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  44647. var globalScope = sharedGlobal.globalScope;
  44648. var PDFJS = sharedGlobal.PDFJS;
  44649. var WorkerTask = (function WorkerTaskClosure() {
  44650. function WorkerTask(name) {
  44651. this.name = name;
  44652. this.terminated = false;
  44653. this._capability = createPromiseCapability();
  44654. }
  44655. WorkerTask.prototype = {
  44656. get finished() {
  44657. return this._capability.promise;
  44658. },
  44659. finish: function () {
  44660. this._capability.resolve();
  44661. },
  44662. terminate: function () {
  44663. this.terminated = true;
  44664. },
  44665. ensureNotTerminated: function () {
  44666. if (this.terminated) {
  44667. throw new Error('Worker task was terminated');
  44668. }
  44669. }
  44670. };
  44671. return WorkerTask;
  44672. })();
  44673. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  44674. setup: function wphSetup(handler, port) {
  44675. handler.on('test', function wphSetupTest(data) {
  44676. // check if Uint8Array can be sent to worker
  44677. if (!(data instanceof Uint8Array)) {
  44678. handler.send('test', 'main', false);
  44679. return;
  44680. }
  44681. // making sure postMessage transfers are working
  44682. var supportTransfers = data[0] === 255;
  44683. handler.postMessageTransfers = supportTransfers;
  44684. // check if the response property is supported by xhr
  44685. var xhr = new XMLHttpRequest();
  44686. var responseExists = 'response' in xhr;
  44687. // check if the property is actually implemented
  44688. try {
  44689. var dummy = xhr.responseType;
  44690. } catch (e) {
  44691. responseExists = false;
  44692. }
  44693. if (!responseExists) {
  44694. handler.send('test', false);
  44695. return;
  44696. }
  44697. handler.send('test', {
  44698. supportTypedArray: true,
  44699. supportTransfers: supportTransfers
  44700. });
  44701. });
  44702. handler.on('GetDocRequest', function wphSetupDoc(data) {
  44703. return WorkerMessageHandler.createDocumentHandler(data, port);
  44704. });
  44705. },
  44706. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  44707. // This context is actually holds references on pdfManager and handler,
  44708. // until the latter is destroyed.
  44709. var pdfManager;
  44710. var terminated = false;
  44711. var cancelXHRs = null;
  44712. var WorkerTasks = [];
  44713. var docId = docParams.docId;
  44714. var workerHandlerName = docParams.docId + '_worker';
  44715. var handler = new MessageHandler(workerHandlerName, docId, port);
  44716. function ensureNotTerminated() {
  44717. if (terminated) {
  44718. throw new Error('Worker was terminated');
  44719. }
  44720. }
  44721. function startWorkerTask(task) {
  44722. WorkerTasks.push(task);
  44723. }
  44724. function finishWorkerTask(task) {
  44725. task.finish();
  44726. var i = WorkerTasks.indexOf(task);
  44727. WorkerTasks.splice(i, 1);
  44728. }
  44729. function loadDocument(recoveryMode) {
  44730. var loadDocumentCapability = createPromiseCapability();
  44731. var parseSuccess = function parseSuccess() {
  44732. var numPagesPromise = pdfManager.ensureDoc('numPages');
  44733. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  44734. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  44735. Promise.all([numPagesPromise, fingerprintPromise,
  44736. encryptedPromise]).then(function onDocReady(results) {
  44737. var doc = {
  44738. numPages: results[0],
  44739. fingerprint: results[1],
  44740. encrypted: !!results[2],
  44741. };
  44742. loadDocumentCapability.resolve(doc);
  44743. },
  44744. parseFailure);
  44745. };
  44746. var parseFailure = function parseFailure(e) {
  44747. loadDocumentCapability.reject(e);
  44748. };
  44749. pdfManager.ensureDoc('checkHeader', []).then(function() {
  44750. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  44751. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  44752. parseSuccess, parseFailure);
  44753. }, parseFailure);
  44754. }, parseFailure);
  44755. return loadDocumentCapability.promise;
  44756. }
  44757. function getPdfManager(data) {
  44758. var pdfManagerCapability = createPromiseCapability();
  44759. var pdfManager;
  44760. var source = data.source;
  44761. var disableRange = data.disableRange;
  44762. if (source.data) {
  44763. try {
  44764. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  44765. pdfManagerCapability.resolve(pdfManager);
  44766. } catch (ex) {
  44767. pdfManagerCapability.reject(ex);
  44768. }
  44769. return pdfManagerCapability.promise;
  44770. } else if (source.chunkedViewerLoading) {
  44771. try {
  44772. pdfManager = new NetworkPdfManager(docId, source, handler);
  44773. pdfManagerCapability.resolve(pdfManager);
  44774. } catch (ex) {
  44775. pdfManagerCapability.reject(ex);
  44776. }
  44777. return pdfManagerCapability.promise;
  44778. }
  44779. var networkManager = new NetworkManager(source.url, {
  44780. httpHeaders: source.httpHeaders,
  44781. withCredentials: source.withCredentials
  44782. });
  44783. var cachedChunks = [];
  44784. var fullRequestXhrId = networkManager.requestFull({
  44785. onHeadersReceived: function onHeadersReceived() {
  44786. if (disableRange) {
  44787. return;
  44788. }
  44789. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  44790. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  44791. return;
  44792. }
  44793. var contentEncoding =
  44794. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  44795. if (contentEncoding !== 'identity') {
  44796. return;
  44797. }
  44798. var length = fullRequestXhr.getResponseHeader('Content-Length');
  44799. length = parseInt(length, 10);
  44800. if (!isInt(length)) {
  44801. return;
  44802. }
  44803. source.length = length;
  44804. if (length <= 2 * source.rangeChunkSize) {
  44805. // The file size is smaller than the size of two chunks, so it does
  44806. // not make any sense to abort the request and retry with a range
  44807. // request.
  44808. return;
  44809. }
  44810. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  44811. // We can continue fetching when progressive loading is enabled,
  44812. // and we don't need the autoFetch feature.
  44813. source.disableAutoFetch = true;
  44814. } else {
  44815. // NOTE: by cancelling the full request, and then issuing range
  44816. // requests, there will be an issue for sites where you can only
  44817. // request the pdf once. However, if this is the case, then the
  44818. // server should not be returning that it can support range
  44819. // requests.
  44820. networkManager.abortRequest(fullRequestXhrId);
  44821. }
  44822. try {
  44823. pdfManager = new NetworkPdfManager(docId, source, handler);
  44824. pdfManagerCapability.resolve(pdfManager);
  44825. } catch (ex) {
  44826. pdfManagerCapability.reject(ex);
  44827. }
  44828. cancelXHRs = null;
  44829. },
  44830. onProgressiveData: source.disableStream ? null :
  44831. function onProgressiveData(chunk) {
  44832. if (!pdfManager) {
  44833. cachedChunks.push(chunk);
  44834. return;
  44835. }
  44836. pdfManager.sendProgressiveData(chunk);
  44837. },
  44838. onDone: function onDone(args) {
  44839. if (pdfManager) {
  44840. return; // already processed
  44841. }
  44842. var pdfFile;
  44843. if (args === null) {
  44844. // TODO add some streaming manager, e.g. for unknown length files.
  44845. // The data was returned in the onProgressiveData, combining...
  44846. var pdfFileLength = 0, pos = 0;
  44847. cachedChunks.forEach(function (chunk) {
  44848. pdfFileLength += chunk.byteLength;
  44849. });
  44850. if (source.length && pdfFileLength !== source.length) {
  44851. warn('reported HTTP length is different from actual');
  44852. }
  44853. var pdfFileArray = new Uint8Array(pdfFileLength);
  44854. cachedChunks.forEach(function (chunk) {
  44855. pdfFileArray.set(new Uint8Array(chunk), pos);
  44856. pos += chunk.byteLength;
  44857. });
  44858. pdfFile = pdfFileArray.buffer;
  44859. } else {
  44860. pdfFile = args.chunk;
  44861. }
  44862. // the data is array, instantiating directly from it
  44863. try {
  44864. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  44865. pdfManagerCapability.resolve(pdfManager);
  44866. } catch (ex) {
  44867. pdfManagerCapability.reject(ex);
  44868. }
  44869. cancelXHRs = null;
  44870. },
  44871. onError: function onError(status) {
  44872. var exception;
  44873. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  44874. exception = new MissingPDFException('Missing PDF "' +
  44875. source.url + '".');
  44876. handler.send('MissingPDF', exception);
  44877. } else {
  44878. exception = new UnexpectedResponseException(
  44879. 'Unexpected server response (' + status +
  44880. ') while retrieving PDF "' + source.url + '".', status);
  44881. handler.send('UnexpectedResponse', exception);
  44882. }
  44883. cancelXHRs = null;
  44884. },
  44885. onProgress: function onProgress(evt) {
  44886. handler.send('DocProgress', {
  44887. loaded: evt.loaded,
  44888. total: evt.lengthComputable ? evt.total : source.length
  44889. });
  44890. }
  44891. });
  44892. cancelXHRs = function () {
  44893. networkManager.abortRequest(fullRequestXhrId);
  44894. };
  44895. return pdfManagerCapability.promise;
  44896. }
  44897. var setupDoc = function(data) {
  44898. var onSuccess = function(doc) {
  44899. ensureNotTerminated();
  44900. handler.send('GetDoc', { pdfInfo: doc });
  44901. };
  44902. var onFailure = function(e) {
  44903. if (e instanceof PasswordException) {
  44904. if (e.code === PasswordResponses.NEED_PASSWORD) {
  44905. handler.send('NeedPassword', e);
  44906. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  44907. handler.send('IncorrectPassword', e);
  44908. }
  44909. } else if (e instanceof InvalidPDFException) {
  44910. handler.send('InvalidPDF', e);
  44911. } else if (e instanceof MissingPDFException) {
  44912. handler.send('MissingPDF', e);
  44913. } else if (e instanceof UnexpectedResponseException) {
  44914. handler.send('UnexpectedResponse', e);
  44915. } else {
  44916. handler.send('UnknownError',
  44917. new UnknownErrorException(e.message, e.toString()));
  44918. }
  44919. };
  44920. ensureNotTerminated();
  44921. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  44922. -1 : data.maxImageSize;
  44923. PDFJS.disableFontFace = data.disableFontFace;
  44924. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  44925. PDFJS.verbosity = data.verbosity;
  44926. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  44927. null : data.cMapUrl;
  44928. PDFJS.cMapPacked = data.cMapPacked === true;
  44929. getPdfManager(data).then(function (newPdfManager) {
  44930. if (terminated) {
  44931. // We were in a process of setting up the manager, but it got
  44932. // terminated in the middle.
  44933. newPdfManager.terminate();
  44934. throw new Error('Worker was terminated');
  44935. }
  44936. pdfManager = newPdfManager;
  44937. handler.send('PDFManagerReady', null);
  44938. pdfManager.onLoadedStream().then(function(stream) {
  44939. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  44940. });
  44941. }).then(function pdfManagerReady() {
  44942. ensureNotTerminated();
  44943. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  44944. ensureNotTerminated();
  44945. // Try again with recoveryMode == true
  44946. if (!(ex instanceof XRefParseException)) {
  44947. if (ex instanceof PasswordException) {
  44948. // after password exception prepare to receive a new password
  44949. // to repeat loading
  44950. pdfManager.passwordChanged().then(pdfManagerReady);
  44951. }
  44952. onFailure(ex);
  44953. return;
  44954. }
  44955. pdfManager.requestLoadedStream();
  44956. pdfManager.onLoadedStream().then(function() {
  44957. ensureNotTerminated();
  44958. loadDocument(true).then(onSuccess, onFailure);
  44959. });
  44960. }, onFailure);
  44961. }, onFailure);
  44962. };
  44963. handler.on('GetPage', function wphSetupGetPage(data) {
  44964. return pdfManager.getPage(data.pageIndex).then(function(page) {
  44965. var rotatePromise = pdfManager.ensure(page, 'rotate');
  44966. var refPromise = pdfManager.ensure(page, 'ref');
  44967. var viewPromise = pdfManager.ensure(page, 'view');
  44968. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  44969. function(results) {
  44970. return {
  44971. rotate: results[0],
  44972. ref: results[1],
  44973. view: results[2]
  44974. };
  44975. });
  44976. });
  44977. });
  44978. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  44979. var ref = new Ref(data.ref.num, data.ref.gen);
  44980. var catalog = pdfManager.pdfDocument.catalog;
  44981. return catalog.getPageIndex(ref);
  44982. });
  44983. handler.on('GetDestinations',
  44984. function wphSetupGetDestinations(data) {
  44985. return pdfManager.ensureCatalog('destinations');
  44986. }
  44987. );
  44988. handler.on('GetDestination',
  44989. function wphSetupGetDestination(data) {
  44990. return pdfManager.ensureCatalog('getDestination', [data.id]);
  44991. }
  44992. );
  44993. handler.on('GetAttachments',
  44994. function wphSetupGetAttachments(data) {
  44995. return pdfManager.ensureCatalog('attachments');
  44996. }
  44997. );
  44998. handler.on('GetJavaScript',
  44999. function wphSetupGetJavaScript(data) {
  45000. return pdfManager.ensureCatalog('javaScript');
  45001. }
  45002. );
  45003. handler.on('GetOutline',
  45004. function wphSetupGetOutline(data) {
  45005. return pdfManager.ensureCatalog('documentOutline');
  45006. }
  45007. );
  45008. handler.on('GetMetadata',
  45009. function wphSetupGetMetadata(data) {
  45010. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  45011. pdfManager.ensureCatalog('metadata')]);
  45012. }
  45013. );
  45014. handler.on('GetData', function wphSetupGetData(data) {
  45015. pdfManager.requestLoadedStream();
  45016. return pdfManager.onLoadedStream().then(function(stream) {
  45017. return stream.bytes;
  45018. });
  45019. });
  45020. handler.on('GetStats',
  45021. function wphSetupGetStats(data) {
  45022. return pdfManager.pdfDocument.xref.stats;
  45023. }
  45024. );
  45025. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  45026. pdfManager.updatePassword(data);
  45027. });
  45028. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  45029. return pdfManager.getPage(data.pageIndex).then(function(page) {
  45030. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  45031. });
  45032. });
  45033. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  45034. var pageIndex = data.pageIndex;
  45035. pdfManager.getPage(pageIndex).then(function(page) {
  45036. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  45037. startWorkerTask(task);
  45038. var pageNum = pageIndex + 1;
  45039. var start = Date.now();
  45040. // Pre compile the pdf page and fetch the fonts/images.
  45041. page.getOperatorList(handler, task, data.intent).then(
  45042. function(operatorList) {
  45043. finishWorkerTask(task);
  45044. info('page=' + pageNum + ' - getOperatorList: time=' +
  45045. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  45046. }, function(e) {
  45047. finishWorkerTask(task);
  45048. if (task.terminated) {
  45049. return; // ignoring errors from the terminated thread
  45050. }
  45051. // For compatibility with older behavior, generating unknown
  45052. // unsupported feature notification on errors.
  45053. handler.send('UnsupportedFeature',
  45054. {featureId: UNSUPPORTED_FEATURES.unknown});
  45055. var minimumStackMessage =
  45056. 'worker.js: while trying to getPage() and getOperatorList()';
  45057. var wrappedException;
  45058. // Turn the error into an obj that can be serialized
  45059. if (typeof e === 'string') {
  45060. wrappedException = {
  45061. message: e,
  45062. stack: minimumStackMessage
  45063. };
  45064. } else if (typeof e === 'object') {
  45065. wrappedException = {
  45066. message: e.message || e.toString(),
  45067. stack: e.stack || minimumStackMessage
  45068. };
  45069. } else {
  45070. wrappedException = {
  45071. message: 'Unknown exception type: ' + (typeof e),
  45072. stack: minimumStackMessage
  45073. };
  45074. }
  45075. handler.send('PageError', {
  45076. pageNum: pageNum,
  45077. error: wrappedException,
  45078. intent: data.intent
  45079. });
  45080. });
  45081. });
  45082. }, this);
  45083. handler.on('GetTextContent', function wphExtractText(data) {
  45084. var pageIndex = data.pageIndex;
  45085. var normalizeWhitespace = data.normalizeWhitespace;
  45086. return pdfManager.getPage(pageIndex).then(function(page) {
  45087. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  45088. startWorkerTask(task);
  45089. var pageNum = pageIndex + 1;
  45090. var start = Date.now();
  45091. return page.extractTextContent(task, normalizeWhitespace).then(
  45092. function(textContent) {
  45093. finishWorkerTask(task);
  45094. info('text indexing: page=' + pageNum + ' - time=' +
  45095. (Date.now() - start) + 'ms');
  45096. return textContent;
  45097. }, function (reason) {
  45098. finishWorkerTask(task);
  45099. if (task.terminated) {
  45100. return; // ignoring errors from the terminated thread
  45101. }
  45102. throw reason;
  45103. });
  45104. });
  45105. });
  45106. handler.on('Cleanup', function wphCleanup(data) {
  45107. return pdfManager.cleanup();
  45108. });
  45109. handler.on('Terminate', function wphTerminate(data) {
  45110. terminated = true;
  45111. if (pdfManager) {
  45112. pdfManager.terminate();
  45113. pdfManager = null;
  45114. }
  45115. if (cancelXHRs) {
  45116. cancelXHRs();
  45117. }
  45118. var waitOn = [];
  45119. WorkerTasks.forEach(function (task) {
  45120. waitOn.push(task.finished);
  45121. task.terminate();
  45122. });
  45123. return Promise.all(waitOn).then(function () {
  45124. // Notice that even if we destroying handler, resolved response promise
  45125. // must be sent back.
  45126. handler.destroy();
  45127. handler = null;
  45128. });
  45129. });
  45130. handler.on('Ready', function wphReady(data) {
  45131. setupDoc(docParams);
  45132. docParams = null; // we don't need docParams anymore -- saving memory.
  45133. });
  45134. return workerHandlerName;
  45135. }
  45136. };
  45137. var consoleTimer = {};
  45138. var workerConsole = {
  45139. log: function log() {
  45140. var args = Array.prototype.slice.call(arguments);
  45141. globalScope.postMessage({
  45142. targetName: 'main',
  45143. action: 'console_log',
  45144. data: args
  45145. });
  45146. },
  45147. error: function error() {
  45148. var args = Array.prototype.slice.call(arguments);
  45149. globalScope.postMessage({
  45150. targetName: 'main',
  45151. action: 'console_error',
  45152. data: args
  45153. });
  45154. throw 'pdf.js execution error';
  45155. },
  45156. time: function time(name) {
  45157. consoleTimer[name] = Date.now();
  45158. },
  45159. timeEnd: function timeEnd(name) {
  45160. var time = consoleTimer[name];
  45161. if (!time) {
  45162. error('Unknown timer name ' + name);
  45163. }
  45164. this.log('Timer:', name, Date.now() - time);
  45165. }
  45166. };
  45167. // Worker thread?
  45168. if (typeof window === 'undefined' &&
  45169. !(typeof module !== 'undefined' && module.require)) {
  45170. if (!('console' in globalScope)) {
  45171. globalScope.console = workerConsole;
  45172. }
  45173. var handler = new MessageHandler('worker', 'main', self);
  45174. WorkerMessageHandler.setup(handler, self);
  45175. }
  45176. exports.WorkerTask = WorkerTask;
  45177. exports.WorkerMessageHandler = WorkerMessageHandler;
  45178. }));
  45179. }).call((typeof window === 'undefined') ? this : window);
  45180. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  45181. // workerSrc is not set -- using last script url to define default location
  45182. PDFJS.workerSrc = (function () {
  45183. 'use strict';
  45184. var pdfJsSrc = document.currentScript.src;
  45185. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  45186. })();
  45187. }