2
0

pdf.combined.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926
  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.148';
  23. PDFJS.build = '4e9ea35';
  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.pdfjsCoreArithmeticDecoder = {}));
  30. }
  31. }(this, function (exports) {
  32. /* This class implements the QM Coder decoding as defined in
  33. * JPEG 2000 Part I Final Committee Draft Version 1.0
  34. * Annex C.3 Arithmetic decoding procedure
  35. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  36. *
  37. * The arithmetic decoder is used in conjunction with context models to decode
  38. * JPEG2000 and JBIG2 streams.
  39. */
  40. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  41. // Table C-2
  42. var QeTable = [
  43. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  44. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  45. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  46. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  47. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  48. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  49. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  50. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  51. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  52. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  53. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  54. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  55. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  56. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  57. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  58. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  59. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  60. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  61. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  62. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  63. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  64. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  65. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  66. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  67. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  68. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  69. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  70. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  71. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  72. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  73. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  74. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  75. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  76. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  77. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  78. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  79. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  80. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  81. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  82. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  83. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  84. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  85. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  86. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  87. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  88. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  89. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  90. ];
  91. // C.3.5 Initialisation of the decoder (INITDEC)
  92. function ArithmeticDecoder(data, start, end) {
  93. this.data = data;
  94. this.bp = start;
  95. this.dataEnd = end;
  96. this.chigh = data[start];
  97. this.clow = 0;
  98. this.byteIn();
  99. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  100. this.clow = (this.clow << 7) & 0xFFFF;
  101. this.ct -= 7;
  102. this.a = 0x8000;
  103. }
  104. ArithmeticDecoder.prototype = {
  105. // C.3.4 Compressed data input (BYTEIN)
  106. byteIn: function ArithmeticDecoder_byteIn() {
  107. var data = this.data;
  108. var bp = this.bp;
  109. if (data[bp] === 0xFF) {
  110. var b1 = data[bp + 1];
  111. if (b1 > 0x8F) {
  112. this.clow += 0xFF00;
  113. this.ct = 8;
  114. } else {
  115. bp++;
  116. this.clow += (data[bp] << 9);
  117. this.ct = 7;
  118. this.bp = bp;
  119. }
  120. } else {
  121. bp++;
  122. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  123. this.ct = 8;
  124. this.bp = bp;
  125. }
  126. if (this.clow > 0xFFFF) {
  127. this.chigh += (this.clow >> 16);
  128. this.clow &= 0xFFFF;
  129. }
  130. },
  131. // C.3.2 Decoding a decision (DECODE)
  132. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  133. // contexts are packed into 1 byte:
  134. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  135. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  136. var qeTableIcx = QeTable[cx_index];
  137. var qeIcx = qeTableIcx.qe;
  138. var d;
  139. var a = this.a - qeIcx;
  140. if (this.chigh < qeIcx) {
  141. // exchangeLps
  142. if (a < qeIcx) {
  143. a = qeIcx;
  144. d = cx_mps;
  145. cx_index = qeTableIcx.nmps;
  146. } else {
  147. a = qeIcx;
  148. d = 1 ^ cx_mps;
  149. if (qeTableIcx.switchFlag === 1) {
  150. cx_mps = d;
  151. }
  152. cx_index = qeTableIcx.nlps;
  153. }
  154. } else {
  155. this.chigh -= qeIcx;
  156. if ((a & 0x8000) !== 0) {
  157. this.a = a;
  158. return cx_mps;
  159. }
  160. // exchangeMps
  161. if (a < qeIcx) {
  162. d = 1 ^ cx_mps;
  163. if (qeTableIcx.switchFlag === 1) {
  164. cx_mps = d;
  165. }
  166. cx_index = qeTableIcx.nlps;
  167. } else {
  168. d = cx_mps;
  169. cx_index = qeTableIcx.nmps;
  170. }
  171. }
  172. // C.3.3 renormD;
  173. do {
  174. if (this.ct === 0) {
  175. this.byteIn();
  176. }
  177. a <<= 1;
  178. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  179. this.clow = (this.clow << 1) & 0xFFFF;
  180. this.ct--;
  181. } while ((a & 0x8000) === 0);
  182. this.a = a;
  183. contexts[pos] = cx_index << 1 | cx_mps;
  184. return d;
  185. }
  186. };
  187. return ArithmeticDecoder;
  188. })();
  189. exports.ArithmeticDecoder = ArithmeticDecoder;
  190. }));
  191. (function (root, factory) {
  192. {
  193. factory((root.pdfjsCoreCharsets = {}));
  194. }
  195. }(this, function (exports) {
  196. var ISOAdobeCharset = [
  197. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  198. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  199. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  200. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  201. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  202. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  203. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  204. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  205. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  206. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  207. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  208. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  209. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  210. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  211. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  212. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  213. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  214. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  215. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  216. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  217. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  218. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  219. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  220. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  221. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  222. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  223. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  224. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  225. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  226. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  227. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  228. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  229. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  230. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  231. ];
  232. var ExpertCharset = [
  233. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  234. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  235. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  236. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  237. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  238. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  239. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  240. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  241. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  242. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  243. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  244. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  245. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  246. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  247. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  248. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  249. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  250. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  251. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  252. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  253. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  254. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  255. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  256. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  257. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  258. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  259. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  260. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  261. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  262. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  263. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  264. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  265. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  266. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  267. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  268. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  269. 'Ydieresissmall'
  270. ];
  271. var ExpertSubsetCharset = [
  272. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  273. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  274. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  275. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  276. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  277. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  278. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  279. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  280. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  281. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  282. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  283. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  284. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  285. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  286. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  287. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  288. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  289. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  290. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  291. 'periodinferior', 'commainferior'
  292. ];
  293. exports.ISOAdobeCharset = ISOAdobeCharset;
  294. exports.ExpertCharset = ExpertCharset;
  295. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  296. }));
  297. (function (root, factory) {
  298. {
  299. factory((root.pdfjsCoreGlyphList = {}));
  300. }
  301. }(this, function (exports) {
  302. var GlyphsUnicode = {
  303. A: 0x0041,
  304. AE: 0x00C6,
  305. AEacute: 0x01FC,
  306. AEmacron: 0x01E2,
  307. AEsmall: 0xF7E6,
  308. Aacute: 0x00C1,
  309. Aacutesmall: 0xF7E1,
  310. Abreve: 0x0102,
  311. Abreveacute: 0x1EAE,
  312. Abrevecyrillic: 0x04D0,
  313. Abrevedotbelow: 0x1EB6,
  314. Abrevegrave: 0x1EB0,
  315. Abrevehookabove: 0x1EB2,
  316. Abrevetilde: 0x1EB4,
  317. Acaron: 0x01CD,
  318. Acircle: 0x24B6,
  319. Acircumflex: 0x00C2,
  320. Acircumflexacute: 0x1EA4,
  321. Acircumflexdotbelow: 0x1EAC,
  322. Acircumflexgrave: 0x1EA6,
  323. Acircumflexhookabove: 0x1EA8,
  324. Acircumflexsmall: 0xF7E2,
  325. Acircumflextilde: 0x1EAA,
  326. Acute: 0xF6C9,
  327. Acutesmall: 0xF7B4,
  328. Acyrillic: 0x0410,
  329. Adblgrave: 0x0200,
  330. Adieresis: 0x00C4,
  331. Adieresiscyrillic: 0x04D2,
  332. Adieresismacron: 0x01DE,
  333. Adieresissmall: 0xF7E4,
  334. Adotbelow: 0x1EA0,
  335. Adotmacron: 0x01E0,
  336. Agrave: 0x00C0,
  337. Agravesmall: 0xF7E0,
  338. Ahookabove: 0x1EA2,
  339. Aiecyrillic: 0x04D4,
  340. Ainvertedbreve: 0x0202,
  341. Alpha: 0x0391,
  342. Alphatonos: 0x0386,
  343. Amacron: 0x0100,
  344. Amonospace: 0xFF21,
  345. Aogonek: 0x0104,
  346. Aring: 0x00C5,
  347. Aringacute: 0x01FA,
  348. Aringbelow: 0x1E00,
  349. Aringsmall: 0xF7E5,
  350. Asmall: 0xF761,
  351. Atilde: 0x00C3,
  352. Atildesmall: 0xF7E3,
  353. Aybarmenian: 0x0531,
  354. B: 0x0042,
  355. Bcircle: 0x24B7,
  356. Bdotaccent: 0x1E02,
  357. Bdotbelow: 0x1E04,
  358. Becyrillic: 0x0411,
  359. Benarmenian: 0x0532,
  360. Beta: 0x0392,
  361. Bhook: 0x0181,
  362. Blinebelow: 0x1E06,
  363. Bmonospace: 0xFF22,
  364. Brevesmall: 0xF6F4,
  365. Bsmall: 0xF762,
  366. Btopbar: 0x0182,
  367. C: 0x0043,
  368. Caarmenian: 0x053E,
  369. Cacute: 0x0106,
  370. Caron: 0xF6CA,
  371. Caronsmall: 0xF6F5,
  372. Ccaron: 0x010C,
  373. Ccedilla: 0x00C7,
  374. Ccedillaacute: 0x1E08,
  375. Ccedillasmall: 0xF7E7,
  376. Ccircle: 0x24B8,
  377. Ccircumflex: 0x0108,
  378. Cdot: 0x010A,
  379. Cdotaccent: 0x010A,
  380. Cedillasmall: 0xF7B8,
  381. Chaarmenian: 0x0549,
  382. Cheabkhasiancyrillic: 0x04BC,
  383. Checyrillic: 0x0427,
  384. Chedescenderabkhasiancyrillic: 0x04BE,
  385. Chedescendercyrillic: 0x04B6,
  386. Chedieresiscyrillic: 0x04F4,
  387. Cheharmenian: 0x0543,
  388. Chekhakassiancyrillic: 0x04CB,
  389. Cheverticalstrokecyrillic: 0x04B8,
  390. Chi: 0x03A7,
  391. Chook: 0x0187,
  392. Circumflexsmall: 0xF6F6,
  393. Cmonospace: 0xFF23,
  394. Coarmenian: 0x0551,
  395. Csmall: 0xF763,
  396. D: 0x0044,
  397. DZ: 0x01F1,
  398. DZcaron: 0x01C4,
  399. Daarmenian: 0x0534,
  400. Dafrican: 0x0189,
  401. Dcaron: 0x010E,
  402. Dcedilla: 0x1E10,
  403. Dcircle: 0x24B9,
  404. Dcircumflexbelow: 0x1E12,
  405. Dcroat: 0x0110,
  406. Ddotaccent: 0x1E0A,
  407. Ddotbelow: 0x1E0C,
  408. Decyrillic: 0x0414,
  409. Deicoptic: 0x03EE,
  410. Delta: 0x2206,
  411. Deltagreek: 0x0394,
  412. Dhook: 0x018A,
  413. Dieresis: 0xF6CB,
  414. DieresisAcute: 0xF6CC,
  415. DieresisGrave: 0xF6CD,
  416. Dieresissmall: 0xF7A8,
  417. Digammagreek: 0x03DC,
  418. Djecyrillic: 0x0402,
  419. Dlinebelow: 0x1E0E,
  420. Dmonospace: 0xFF24,
  421. Dotaccentsmall: 0xF6F7,
  422. Dslash: 0x0110,
  423. Dsmall: 0xF764,
  424. Dtopbar: 0x018B,
  425. Dz: 0x01F2,
  426. Dzcaron: 0x01C5,
  427. Dzeabkhasiancyrillic: 0x04E0,
  428. Dzecyrillic: 0x0405,
  429. Dzhecyrillic: 0x040F,
  430. E: 0x0045,
  431. Eacute: 0x00C9,
  432. Eacutesmall: 0xF7E9,
  433. Ebreve: 0x0114,
  434. Ecaron: 0x011A,
  435. Ecedillabreve: 0x1E1C,
  436. Echarmenian: 0x0535,
  437. Ecircle: 0x24BA,
  438. Ecircumflex: 0x00CA,
  439. Ecircumflexacute: 0x1EBE,
  440. Ecircumflexbelow: 0x1E18,
  441. Ecircumflexdotbelow: 0x1EC6,
  442. Ecircumflexgrave: 0x1EC0,
  443. Ecircumflexhookabove: 0x1EC2,
  444. Ecircumflexsmall: 0xF7EA,
  445. Ecircumflextilde: 0x1EC4,
  446. Ecyrillic: 0x0404,
  447. Edblgrave: 0x0204,
  448. Edieresis: 0x00CB,
  449. Edieresissmall: 0xF7EB,
  450. Edot: 0x0116,
  451. Edotaccent: 0x0116,
  452. Edotbelow: 0x1EB8,
  453. Efcyrillic: 0x0424,
  454. Egrave: 0x00C8,
  455. Egravesmall: 0xF7E8,
  456. Eharmenian: 0x0537,
  457. Ehookabove: 0x1EBA,
  458. Eightroman: 0x2167,
  459. Einvertedbreve: 0x0206,
  460. Eiotifiedcyrillic: 0x0464,
  461. Elcyrillic: 0x041B,
  462. Elevenroman: 0x216A,
  463. Emacron: 0x0112,
  464. Emacronacute: 0x1E16,
  465. Emacrongrave: 0x1E14,
  466. Emcyrillic: 0x041C,
  467. Emonospace: 0xFF25,
  468. Encyrillic: 0x041D,
  469. Endescendercyrillic: 0x04A2,
  470. Eng: 0x014A,
  471. Enghecyrillic: 0x04A4,
  472. Enhookcyrillic: 0x04C7,
  473. Eogonek: 0x0118,
  474. Eopen: 0x0190,
  475. Epsilon: 0x0395,
  476. Epsilontonos: 0x0388,
  477. Ercyrillic: 0x0420,
  478. Ereversed: 0x018E,
  479. Ereversedcyrillic: 0x042D,
  480. Escyrillic: 0x0421,
  481. Esdescendercyrillic: 0x04AA,
  482. Esh: 0x01A9,
  483. Esmall: 0xF765,
  484. Eta: 0x0397,
  485. Etarmenian: 0x0538,
  486. Etatonos: 0x0389,
  487. Eth: 0x00D0,
  488. Ethsmall: 0xF7F0,
  489. Etilde: 0x1EBC,
  490. Etildebelow: 0x1E1A,
  491. Euro: 0x20AC,
  492. Ezh: 0x01B7,
  493. Ezhcaron: 0x01EE,
  494. Ezhreversed: 0x01B8,
  495. F: 0x0046,
  496. Fcircle: 0x24BB,
  497. Fdotaccent: 0x1E1E,
  498. Feharmenian: 0x0556,
  499. Feicoptic: 0x03E4,
  500. Fhook: 0x0191,
  501. Fitacyrillic: 0x0472,
  502. Fiveroman: 0x2164,
  503. Fmonospace: 0xFF26,
  504. Fourroman: 0x2163,
  505. Fsmall: 0xF766,
  506. G: 0x0047,
  507. GBsquare: 0x3387,
  508. Gacute: 0x01F4,
  509. Gamma: 0x0393,
  510. Gammaafrican: 0x0194,
  511. Gangiacoptic: 0x03EA,
  512. Gbreve: 0x011E,
  513. Gcaron: 0x01E6,
  514. Gcedilla: 0x0122,
  515. Gcircle: 0x24BC,
  516. Gcircumflex: 0x011C,
  517. Gcommaaccent: 0x0122,
  518. Gdot: 0x0120,
  519. Gdotaccent: 0x0120,
  520. Gecyrillic: 0x0413,
  521. Ghadarmenian: 0x0542,
  522. Ghemiddlehookcyrillic: 0x0494,
  523. Ghestrokecyrillic: 0x0492,
  524. Gheupturncyrillic: 0x0490,
  525. Ghook: 0x0193,
  526. Gimarmenian: 0x0533,
  527. Gjecyrillic: 0x0403,
  528. Gmacron: 0x1E20,
  529. Gmonospace: 0xFF27,
  530. Grave: 0xF6CE,
  531. Gravesmall: 0xF760,
  532. Gsmall: 0xF767,
  533. Gsmallhook: 0x029B,
  534. Gstroke: 0x01E4,
  535. H: 0x0048,
  536. H18533: 0x25CF,
  537. H18543: 0x25AA,
  538. H18551: 0x25AB,
  539. H22073: 0x25A1,
  540. HPsquare: 0x33CB,
  541. Haabkhasiancyrillic: 0x04A8,
  542. Hadescendercyrillic: 0x04B2,
  543. Hardsigncyrillic: 0x042A,
  544. Hbar: 0x0126,
  545. Hbrevebelow: 0x1E2A,
  546. Hcedilla: 0x1E28,
  547. Hcircle: 0x24BD,
  548. Hcircumflex: 0x0124,
  549. Hdieresis: 0x1E26,
  550. Hdotaccent: 0x1E22,
  551. Hdotbelow: 0x1E24,
  552. Hmonospace: 0xFF28,
  553. Hoarmenian: 0x0540,
  554. Horicoptic: 0x03E8,
  555. Hsmall: 0xF768,
  556. Hungarumlaut: 0xF6CF,
  557. Hungarumlautsmall: 0xF6F8,
  558. Hzsquare: 0x3390,
  559. I: 0x0049,
  560. IAcyrillic: 0x042F,
  561. IJ: 0x0132,
  562. IUcyrillic: 0x042E,
  563. Iacute: 0x00CD,
  564. Iacutesmall: 0xF7ED,
  565. Ibreve: 0x012C,
  566. Icaron: 0x01CF,
  567. Icircle: 0x24BE,
  568. Icircumflex: 0x00CE,
  569. Icircumflexsmall: 0xF7EE,
  570. Icyrillic: 0x0406,
  571. Idblgrave: 0x0208,
  572. Idieresis: 0x00CF,
  573. Idieresisacute: 0x1E2E,
  574. Idieresiscyrillic: 0x04E4,
  575. Idieresissmall: 0xF7EF,
  576. Idot: 0x0130,
  577. Idotaccent: 0x0130,
  578. Idotbelow: 0x1ECA,
  579. Iebrevecyrillic: 0x04D6,
  580. Iecyrillic: 0x0415,
  581. Ifraktur: 0x2111,
  582. Igrave: 0x00CC,
  583. Igravesmall: 0xF7EC,
  584. Ihookabove: 0x1EC8,
  585. Iicyrillic: 0x0418,
  586. Iinvertedbreve: 0x020A,
  587. Iishortcyrillic: 0x0419,
  588. Imacron: 0x012A,
  589. Imacroncyrillic: 0x04E2,
  590. Imonospace: 0xFF29,
  591. Iniarmenian: 0x053B,
  592. Iocyrillic: 0x0401,
  593. Iogonek: 0x012E,
  594. Iota: 0x0399,
  595. Iotaafrican: 0x0196,
  596. Iotadieresis: 0x03AA,
  597. Iotatonos: 0x038A,
  598. Ismall: 0xF769,
  599. Istroke: 0x0197,
  600. Itilde: 0x0128,
  601. Itildebelow: 0x1E2C,
  602. Izhitsacyrillic: 0x0474,
  603. Izhitsadblgravecyrillic: 0x0476,
  604. J: 0x004A,
  605. Jaarmenian: 0x0541,
  606. Jcircle: 0x24BF,
  607. Jcircumflex: 0x0134,
  608. Jecyrillic: 0x0408,
  609. Jheharmenian: 0x054B,
  610. Jmonospace: 0xFF2A,
  611. Jsmall: 0xF76A,
  612. K: 0x004B,
  613. KBsquare: 0x3385,
  614. KKsquare: 0x33CD,
  615. Kabashkircyrillic: 0x04A0,
  616. Kacute: 0x1E30,
  617. Kacyrillic: 0x041A,
  618. Kadescendercyrillic: 0x049A,
  619. Kahookcyrillic: 0x04C3,
  620. Kappa: 0x039A,
  621. Kastrokecyrillic: 0x049E,
  622. Kaverticalstrokecyrillic: 0x049C,
  623. Kcaron: 0x01E8,
  624. Kcedilla: 0x0136,
  625. Kcircle: 0x24C0,
  626. Kcommaaccent: 0x0136,
  627. Kdotbelow: 0x1E32,
  628. Keharmenian: 0x0554,
  629. Kenarmenian: 0x053F,
  630. Khacyrillic: 0x0425,
  631. Kheicoptic: 0x03E6,
  632. Khook: 0x0198,
  633. Kjecyrillic: 0x040C,
  634. Klinebelow: 0x1E34,
  635. Kmonospace: 0xFF2B,
  636. Koppacyrillic: 0x0480,
  637. Koppagreek: 0x03DE,
  638. Ksicyrillic: 0x046E,
  639. Ksmall: 0xF76B,
  640. L: 0x004C,
  641. LJ: 0x01C7,
  642. LL: 0xF6BF,
  643. Lacute: 0x0139,
  644. Lambda: 0x039B,
  645. Lcaron: 0x013D,
  646. Lcedilla: 0x013B,
  647. Lcircle: 0x24C1,
  648. Lcircumflexbelow: 0x1E3C,
  649. Lcommaaccent: 0x013B,
  650. Ldot: 0x013F,
  651. Ldotaccent: 0x013F,
  652. Ldotbelow: 0x1E36,
  653. Ldotbelowmacron: 0x1E38,
  654. Liwnarmenian: 0x053C,
  655. Lj: 0x01C8,
  656. Ljecyrillic: 0x0409,
  657. Llinebelow: 0x1E3A,
  658. Lmonospace: 0xFF2C,
  659. Lslash: 0x0141,
  660. Lslashsmall: 0xF6F9,
  661. Lsmall: 0xF76C,
  662. M: 0x004D,
  663. MBsquare: 0x3386,
  664. Macron: 0xF6D0,
  665. Macronsmall: 0xF7AF,
  666. Macute: 0x1E3E,
  667. Mcircle: 0x24C2,
  668. Mdotaccent: 0x1E40,
  669. Mdotbelow: 0x1E42,
  670. Menarmenian: 0x0544,
  671. Mmonospace: 0xFF2D,
  672. Msmall: 0xF76D,
  673. Mturned: 0x019C,
  674. Mu: 0x039C,
  675. N: 0x004E,
  676. NJ: 0x01CA,
  677. Nacute: 0x0143,
  678. Ncaron: 0x0147,
  679. Ncedilla: 0x0145,
  680. Ncircle: 0x24C3,
  681. Ncircumflexbelow: 0x1E4A,
  682. Ncommaaccent: 0x0145,
  683. Ndotaccent: 0x1E44,
  684. Ndotbelow: 0x1E46,
  685. Nhookleft: 0x019D,
  686. Nineroman: 0x2168,
  687. Nj: 0x01CB,
  688. Njecyrillic: 0x040A,
  689. Nlinebelow: 0x1E48,
  690. Nmonospace: 0xFF2E,
  691. Nowarmenian: 0x0546,
  692. Nsmall: 0xF76E,
  693. Ntilde: 0x00D1,
  694. Ntildesmall: 0xF7F1,
  695. Nu: 0x039D,
  696. O: 0x004F,
  697. OE: 0x0152,
  698. OEsmall: 0xF6FA,
  699. Oacute: 0x00D3,
  700. Oacutesmall: 0xF7F3,
  701. Obarredcyrillic: 0x04E8,
  702. Obarreddieresiscyrillic: 0x04EA,
  703. Obreve: 0x014E,
  704. Ocaron: 0x01D1,
  705. Ocenteredtilde: 0x019F,
  706. Ocircle: 0x24C4,
  707. Ocircumflex: 0x00D4,
  708. Ocircumflexacute: 0x1ED0,
  709. Ocircumflexdotbelow: 0x1ED8,
  710. Ocircumflexgrave: 0x1ED2,
  711. Ocircumflexhookabove: 0x1ED4,
  712. Ocircumflexsmall: 0xF7F4,
  713. Ocircumflextilde: 0x1ED6,
  714. Ocyrillic: 0x041E,
  715. Odblacute: 0x0150,
  716. Odblgrave: 0x020C,
  717. Odieresis: 0x00D6,
  718. Odieresiscyrillic: 0x04E6,
  719. Odieresissmall: 0xF7F6,
  720. Odotbelow: 0x1ECC,
  721. Ogoneksmall: 0xF6FB,
  722. Ograve: 0x00D2,
  723. Ogravesmall: 0xF7F2,
  724. Oharmenian: 0x0555,
  725. Ohm: 0x2126,
  726. Ohookabove: 0x1ECE,
  727. Ohorn: 0x01A0,
  728. Ohornacute: 0x1EDA,
  729. Ohorndotbelow: 0x1EE2,
  730. Ohorngrave: 0x1EDC,
  731. Ohornhookabove: 0x1EDE,
  732. Ohorntilde: 0x1EE0,
  733. Ohungarumlaut: 0x0150,
  734. Oi: 0x01A2,
  735. Oinvertedbreve: 0x020E,
  736. Omacron: 0x014C,
  737. Omacronacute: 0x1E52,
  738. Omacrongrave: 0x1E50,
  739. Omega: 0x2126,
  740. Omegacyrillic: 0x0460,
  741. Omegagreek: 0x03A9,
  742. Omegaroundcyrillic: 0x047A,
  743. Omegatitlocyrillic: 0x047C,
  744. Omegatonos: 0x038F,
  745. Omicron: 0x039F,
  746. Omicrontonos: 0x038C,
  747. Omonospace: 0xFF2F,
  748. Oneroman: 0x2160,
  749. Oogonek: 0x01EA,
  750. Oogonekmacron: 0x01EC,
  751. Oopen: 0x0186,
  752. Oslash: 0x00D8,
  753. Oslashacute: 0x01FE,
  754. Oslashsmall: 0xF7F8,
  755. Osmall: 0xF76F,
  756. Ostrokeacute: 0x01FE,
  757. Otcyrillic: 0x047E,
  758. Otilde: 0x00D5,
  759. Otildeacute: 0x1E4C,
  760. Otildedieresis: 0x1E4E,
  761. Otildesmall: 0xF7F5,
  762. P: 0x0050,
  763. Pacute: 0x1E54,
  764. Pcircle: 0x24C5,
  765. Pdotaccent: 0x1E56,
  766. Pecyrillic: 0x041F,
  767. Peharmenian: 0x054A,
  768. Pemiddlehookcyrillic: 0x04A6,
  769. Phi: 0x03A6,
  770. Phook: 0x01A4,
  771. Pi: 0x03A0,
  772. Piwrarmenian: 0x0553,
  773. Pmonospace: 0xFF30,
  774. Psi: 0x03A8,
  775. Psicyrillic: 0x0470,
  776. Psmall: 0xF770,
  777. Q: 0x0051,
  778. Qcircle: 0x24C6,
  779. Qmonospace: 0xFF31,
  780. Qsmall: 0xF771,
  781. R: 0x0052,
  782. Raarmenian: 0x054C,
  783. Racute: 0x0154,
  784. Rcaron: 0x0158,
  785. Rcedilla: 0x0156,
  786. Rcircle: 0x24C7,
  787. Rcommaaccent: 0x0156,
  788. Rdblgrave: 0x0210,
  789. Rdotaccent: 0x1E58,
  790. Rdotbelow: 0x1E5A,
  791. Rdotbelowmacron: 0x1E5C,
  792. Reharmenian: 0x0550,
  793. Rfraktur: 0x211C,
  794. Rho: 0x03A1,
  795. Ringsmall: 0xF6FC,
  796. Rinvertedbreve: 0x0212,
  797. Rlinebelow: 0x1E5E,
  798. Rmonospace: 0xFF32,
  799. Rsmall: 0xF772,
  800. Rsmallinverted: 0x0281,
  801. Rsmallinvertedsuperior: 0x02B6,
  802. S: 0x0053,
  803. SF010000: 0x250C,
  804. SF020000: 0x2514,
  805. SF030000: 0x2510,
  806. SF040000: 0x2518,
  807. SF050000: 0x253C,
  808. SF060000: 0x252C,
  809. SF070000: 0x2534,
  810. SF080000: 0x251C,
  811. SF090000: 0x2524,
  812. SF100000: 0x2500,
  813. SF110000: 0x2502,
  814. SF190000: 0x2561,
  815. SF200000: 0x2562,
  816. SF210000: 0x2556,
  817. SF220000: 0x2555,
  818. SF230000: 0x2563,
  819. SF240000: 0x2551,
  820. SF250000: 0x2557,
  821. SF260000: 0x255D,
  822. SF270000: 0x255C,
  823. SF280000: 0x255B,
  824. SF360000: 0x255E,
  825. SF370000: 0x255F,
  826. SF380000: 0x255A,
  827. SF390000: 0x2554,
  828. SF400000: 0x2569,
  829. SF410000: 0x2566,
  830. SF420000: 0x2560,
  831. SF430000: 0x2550,
  832. SF440000: 0x256C,
  833. SF450000: 0x2567,
  834. SF460000: 0x2568,
  835. SF470000: 0x2564,
  836. SF480000: 0x2565,
  837. SF490000: 0x2559,
  838. SF500000: 0x2558,
  839. SF510000: 0x2552,
  840. SF520000: 0x2553,
  841. SF530000: 0x256B,
  842. SF540000: 0x256A,
  843. Sacute: 0x015A,
  844. Sacutedotaccent: 0x1E64,
  845. Sampigreek: 0x03E0,
  846. Scaron: 0x0160,
  847. Scarondotaccent: 0x1E66,
  848. Scaronsmall: 0xF6FD,
  849. Scedilla: 0x015E,
  850. Schwa: 0x018F,
  851. Schwacyrillic: 0x04D8,
  852. Schwadieresiscyrillic: 0x04DA,
  853. Scircle: 0x24C8,
  854. Scircumflex: 0x015C,
  855. Scommaaccent: 0x0218,
  856. Sdotaccent: 0x1E60,
  857. Sdotbelow: 0x1E62,
  858. Sdotbelowdotaccent: 0x1E68,
  859. Seharmenian: 0x054D,
  860. Sevenroman: 0x2166,
  861. Shaarmenian: 0x0547,
  862. Shacyrillic: 0x0428,
  863. Shchacyrillic: 0x0429,
  864. Sheicoptic: 0x03E2,
  865. Shhacyrillic: 0x04BA,
  866. Shimacoptic: 0x03EC,
  867. Sigma: 0x03A3,
  868. Sixroman: 0x2165,
  869. Smonospace: 0xFF33,
  870. Softsigncyrillic: 0x042C,
  871. Ssmall: 0xF773,
  872. Stigmagreek: 0x03DA,
  873. T: 0x0054,
  874. Tau: 0x03A4,
  875. Tbar: 0x0166,
  876. Tcaron: 0x0164,
  877. Tcedilla: 0x0162,
  878. Tcircle: 0x24C9,
  879. Tcircumflexbelow: 0x1E70,
  880. Tcommaaccent: 0x0162,
  881. Tdotaccent: 0x1E6A,
  882. Tdotbelow: 0x1E6C,
  883. Tecyrillic: 0x0422,
  884. Tedescendercyrillic: 0x04AC,
  885. Tenroman: 0x2169,
  886. Tetsecyrillic: 0x04B4,
  887. Theta: 0x0398,
  888. Thook: 0x01AC,
  889. Thorn: 0x00DE,
  890. Thornsmall: 0xF7FE,
  891. Threeroman: 0x2162,
  892. Tildesmall: 0xF6FE,
  893. Tiwnarmenian: 0x054F,
  894. Tlinebelow: 0x1E6E,
  895. Tmonospace: 0xFF34,
  896. Toarmenian: 0x0539,
  897. Tonefive: 0x01BC,
  898. Tonesix: 0x0184,
  899. Tonetwo: 0x01A7,
  900. Tretroflexhook: 0x01AE,
  901. Tsecyrillic: 0x0426,
  902. Tshecyrillic: 0x040B,
  903. Tsmall: 0xF774,
  904. Twelveroman: 0x216B,
  905. Tworoman: 0x2161,
  906. U: 0x0055,
  907. Uacute: 0x00DA,
  908. Uacutesmall: 0xF7FA,
  909. Ubreve: 0x016C,
  910. Ucaron: 0x01D3,
  911. Ucircle: 0x24CA,
  912. Ucircumflex: 0x00DB,
  913. Ucircumflexbelow: 0x1E76,
  914. Ucircumflexsmall: 0xF7FB,
  915. Ucyrillic: 0x0423,
  916. Udblacute: 0x0170,
  917. Udblgrave: 0x0214,
  918. Udieresis: 0x00DC,
  919. Udieresisacute: 0x01D7,
  920. Udieresisbelow: 0x1E72,
  921. Udieresiscaron: 0x01D9,
  922. Udieresiscyrillic: 0x04F0,
  923. Udieresisgrave: 0x01DB,
  924. Udieresismacron: 0x01D5,
  925. Udieresissmall: 0xF7FC,
  926. Udotbelow: 0x1EE4,
  927. Ugrave: 0x00D9,
  928. Ugravesmall: 0xF7F9,
  929. Uhookabove: 0x1EE6,
  930. Uhorn: 0x01AF,
  931. Uhornacute: 0x1EE8,
  932. Uhorndotbelow: 0x1EF0,
  933. Uhorngrave: 0x1EEA,
  934. Uhornhookabove: 0x1EEC,
  935. Uhorntilde: 0x1EEE,
  936. Uhungarumlaut: 0x0170,
  937. Uhungarumlautcyrillic: 0x04F2,
  938. Uinvertedbreve: 0x0216,
  939. Ukcyrillic: 0x0478,
  940. Umacron: 0x016A,
  941. Umacroncyrillic: 0x04EE,
  942. Umacrondieresis: 0x1E7A,
  943. Umonospace: 0xFF35,
  944. Uogonek: 0x0172,
  945. Upsilon: 0x03A5,
  946. Upsilon1: 0x03D2,
  947. Upsilonacutehooksymbolgreek: 0x03D3,
  948. Upsilonafrican: 0x01B1,
  949. Upsilondieresis: 0x03AB,
  950. Upsilondieresishooksymbolgreek: 0x03D4,
  951. Upsilonhooksymbol: 0x03D2,
  952. Upsilontonos: 0x038E,
  953. Uring: 0x016E,
  954. Ushortcyrillic: 0x040E,
  955. Usmall: 0xF775,
  956. Ustraightcyrillic: 0x04AE,
  957. Ustraightstrokecyrillic: 0x04B0,
  958. Utilde: 0x0168,
  959. Utildeacute: 0x1E78,
  960. Utildebelow: 0x1E74,
  961. V: 0x0056,
  962. Vcircle: 0x24CB,
  963. Vdotbelow: 0x1E7E,
  964. Vecyrillic: 0x0412,
  965. Vewarmenian: 0x054E,
  966. Vhook: 0x01B2,
  967. Vmonospace: 0xFF36,
  968. Voarmenian: 0x0548,
  969. Vsmall: 0xF776,
  970. Vtilde: 0x1E7C,
  971. W: 0x0057,
  972. Wacute: 0x1E82,
  973. Wcircle: 0x24CC,
  974. Wcircumflex: 0x0174,
  975. Wdieresis: 0x1E84,
  976. Wdotaccent: 0x1E86,
  977. Wdotbelow: 0x1E88,
  978. Wgrave: 0x1E80,
  979. Wmonospace: 0xFF37,
  980. Wsmall: 0xF777,
  981. X: 0x0058,
  982. Xcircle: 0x24CD,
  983. Xdieresis: 0x1E8C,
  984. Xdotaccent: 0x1E8A,
  985. Xeharmenian: 0x053D,
  986. Xi: 0x039E,
  987. Xmonospace: 0xFF38,
  988. Xsmall: 0xF778,
  989. Y: 0x0059,
  990. Yacute: 0x00DD,
  991. Yacutesmall: 0xF7FD,
  992. Yatcyrillic: 0x0462,
  993. Ycircle: 0x24CE,
  994. Ycircumflex: 0x0176,
  995. Ydieresis: 0x0178,
  996. Ydieresissmall: 0xF7FF,
  997. Ydotaccent: 0x1E8E,
  998. Ydotbelow: 0x1EF4,
  999. Yericyrillic: 0x042B,
  1000. Yerudieresiscyrillic: 0x04F8,
  1001. Ygrave: 0x1EF2,
  1002. Yhook: 0x01B3,
  1003. Yhookabove: 0x1EF6,
  1004. Yiarmenian: 0x0545,
  1005. Yicyrillic: 0x0407,
  1006. Yiwnarmenian: 0x0552,
  1007. Ymonospace: 0xFF39,
  1008. Ysmall: 0xF779,
  1009. Ytilde: 0x1EF8,
  1010. Yusbigcyrillic: 0x046A,
  1011. Yusbigiotifiedcyrillic: 0x046C,
  1012. Yuslittlecyrillic: 0x0466,
  1013. Yuslittleiotifiedcyrillic: 0x0468,
  1014. Z: 0x005A,
  1015. Zaarmenian: 0x0536,
  1016. Zacute: 0x0179,
  1017. Zcaron: 0x017D,
  1018. Zcaronsmall: 0xF6FF,
  1019. Zcircle: 0x24CF,
  1020. Zcircumflex: 0x1E90,
  1021. Zdot: 0x017B,
  1022. Zdotaccent: 0x017B,
  1023. Zdotbelow: 0x1E92,
  1024. Zecyrillic: 0x0417,
  1025. Zedescendercyrillic: 0x0498,
  1026. Zedieresiscyrillic: 0x04DE,
  1027. Zeta: 0x0396,
  1028. Zhearmenian: 0x053A,
  1029. Zhebrevecyrillic: 0x04C1,
  1030. Zhecyrillic: 0x0416,
  1031. Zhedescendercyrillic: 0x0496,
  1032. Zhedieresiscyrillic: 0x04DC,
  1033. Zlinebelow: 0x1E94,
  1034. Zmonospace: 0xFF3A,
  1035. Zsmall: 0xF77A,
  1036. Zstroke: 0x01B5,
  1037. a: 0x0061,
  1038. aabengali: 0x0986,
  1039. aacute: 0x00E1,
  1040. aadeva: 0x0906,
  1041. aagujarati: 0x0A86,
  1042. aagurmukhi: 0x0A06,
  1043. aamatragurmukhi: 0x0A3E,
  1044. aarusquare: 0x3303,
  1045. aavowelsignbengali: 0x09BE,
  1046. aavowelsigndeva: 0x093E,
  1047. aavowelsigngujarati: 0x0ABE,
  1048. abbreviationmarkarmenian: 0x055F,
  1049. abbreviationsigndeva: 0x0970,
  1050. abengali: 0x0985,
  1051. abopomofo: 0x311A,
  1052. abreve: 0x0103,
  1053. abreveacute: 0x1EAF,
  1054. abrevecyrillic: 0x04D1,
  1055. abrevedotbelow: 0x1EB7,
  1056. abrevegrave: 0x1EB1,
  1057. abrevehookabove: 0x1EB3,
  1058. abrevetilde: 0x1EB5,
  1059. acaron: 0x01CE,
  1060. acircle: 0x24D0,
  1061. acircumflex: 0x00E2,
  1062. acircumflexacute: 0x1EA5,
  1063. acircumflexdotbelow: 0x1EAD,
  1064. acircumflexgrave: 0x1EA7,
  1065. acircumflexhookabove: 0x1EA9,
  1066. acircumflextilde: 0x1EAB,
  1067. acute: 0x00B4,
  1068. acutebelowcmb: 0x0317,
  1069. acutecmb: 0x0301,
  1070. acutecomb: 0x0301,
  1071. acutedeva: 0x0954,
  1072. acutelowmod: 0x02CF,
  1073. acutetonecmb: 0x0341,
  1074. acyrillic: 0x0430,
  1075. adblgrave: 0x0201,
  1076. addakgurmukhi: 0x0A71,
  1077. adeva: 0x0905,
  1078. adieresis: 0x00E4,
  1079. adieresiscyrillic: 0x04D3,
  1080. adieresismacron: 0x01DF,
  1081. adotbelow: 0x1EA1,
  1082. adotmacron: 0x01E1,
  1083. ae: 0x00E6,
  1084. aeacute: 0x01FD,
  1085. aekorean: 0x3150,
  1086. aemacron: 0x01E3,
  1087. afii00208: 0x2015,
  1088. afii08941: 0x20A4,
  1089. afii10017: 0x0410,
  1090. afii10018: 0x0411,
  1091. afii10019: 0x0412,
  1092. afii10020: 0x0413,
  1093. afii10021: 0x0414,
  1094. afii10022: 0x0415,
  1095. afii10023: 0x0401,
  1096. afii10024: 0x0416,
  1097. afii10025: 0x0417,
  1098. afii10026: 0x0418,
  1099. afii10027: 0x0419,
  1100. afii10028: 0x041A,
  1101. afii10029: 0x041B,
  1102. afii10030: 0x041C,
  1103. afii10031: 0x041D,
  1104. afii10032: 0x041E,
  1105. afii10033: 0x041F,
  1106. afii10034: 0x0420,
  1107. afii10035: 0x0421,
  1108. afii10036: 0x0422,
  1109. afii10037: 0x0423,
  1110. afii10038: 0x0424,
  1111. afii10039: 0x0425,
  1112. afii10040: 0x0426,
  1113. afii10041: 0x0427,
  1114. afii10042: 0x0428,
  1115. afii10043: 0x0429,
  1116. afii10044: 0x042A,
  1117. afii10045: 0x042B,
  1118. afii10046: 0x042C,
  1119. afii10047: 0x042D,
  1120. afii10048: 0x042E,
  1121. afii10049: 0x042F,
  1122. afii10050: 0x0490,
  1123. afii10051: 0x0402,
  1124. afii10052: 0x0403,
  1125. afii10053: 0x0404,
  1126. afii10054: 0x0405,
  1127. afii10055: 0x0406,
  1128. afii10056: 0x0407,
  1129. afii10057: 0x0408,
  1130. afii10058: 0x0409,
  1131. afii10059: 0x040A,
  1132. afii10060: 0x040B,
  1133. afii10061: 0x040C,
  1134. afii10062: 0x040E,
  1135. afii10063: 0xF6C4,
  1136. afii10064: 0xF6C5,
  1137. afii10065: 0x0430,
  1138. afii10066: 0x0431,
  1139. afii10067: 0x0432,
  1140. afii10068: 0x0433,
  1141. afii10069: 0x0434,
  1142. afii10070: 0x0435,
  1143. afii10071: 0x0451,
  1144. afii10072: 0x0436,
  1145. afii10073: 0x0437,
  1146. afii10074: 0x0438,
  1147. afii10075: 0x0439,
  1148. afii10076: 0x043A,
  1149. afii10077: 0x043B,
  1150. afii10078: 0x043C,
  1151. afii10079: 0x043D,
  1152. afii10080: 0x043E,
  1153. afii10081: 0x043F,
  1154. afii10082: 0x0440,
  1155. afii10083: 0x0441,
  1156. afii10084: 0x0442,
  1157. afii10085: 0x0443,
  1158. afii10086: 0x0444,
  1159. afii10087: 0x0445,
  1160. afii10088: 0x0446,
  1161. afii10089: 0x0447,
  1162. afii10090: 0x0448,
  1163. afii10091: 0x0449,
  1164. afii10092: 0x044A,
  1165. afii10093: 0x044B,
  1166. afii10094: 0x044C,
  1167. afii10095: 0x044D,
  1168. afii10096: 0x044E,
  1169. afii10097: 0x044F,
  1170. afii10098: 0x0491,
  1171. afii10099: 0x0452,
  1172. afii10100: 0x0453,
  1173. afii10101: 0x0454,
  1174. afii10102: 0x0455,
  1175. afii10103: 0x0456,
  1176. afii10104: 0x0457,
  1177. afii10105: 0x0458,
  1178. afii10106: 0x0459,
  1179. afii10107: 0x045A,
  1180. afii10108: 0x045B,
  1181. afii10109: 0x045C,
  1182. afii10110: 0x045E,
  1183. afii10145: 0x040F,
  1184. afii10146: 0x0462,
  1185. afii10147: 0x0472,
  1186. afii10148: 0x0474,
  1187. afii10192: 0xF6C6,
  1188. afii10193: 0x045F,
  1189. afii10194: 0x0463,
  1190. afii10195: 0x0473,
  1191. afii10196: 0x0475,
  1192. afii10831: 0xF6C7,
  1193. afii10832: 0xF6C8,
  1194. afii10846: 0x04D9,
  1195. afii299: 0x200E,
  1196. afii300: 0x200F,
  1197. afii301: 0x200D,
  1198. afii57381: 0x066A,
  1199. afii57388: 0x060C,
  1200. afii57392: 0x0660,
  1201. afii57393: 0x0661,
  1202. afii57394: 0x0662,
  1203. afii57395: 0x0663,
  1204. afii57396: 0x0664,
  1205. afii57397: 0x0665,
  1206. afii57398: 0x0666,
  1207. afii57399: 0x0667,
  1208. afii57400: 0x0668,
  1209. afii57401: 0x0669,
  1210. afii57403: 0x061B,
  1211. afii57407: 0x061F,
  1212. afii57409: 0x0621,
  1213. afii57410: 0x0622,
  1214. afii57411: 0x0623,
  1215. afii57412: 0x0624,
  1216. afii57413: 0x0625,
  1217. afii57414: 0x0626,
  1218. afii57415: 0x0627,
  1219. afii57416: 0x0628,
  1220. afii57417: 0x0629,
  1221. afii57418: 0x062A,
  1222. afii57419: 0x062B,
  1223. afii57420: 0x062C,
  1224. afii57421: 0x062D,
  1225. afii57422: 0x062E,
  1226. afii57423: 0x062F,
  1227. afii57424: 0x0630,
  1228. afii57425: 0x0631,
  1229. afii57426: 0x0632,
  1230. afii57427: 0x0633,
  1231. afii57428: 0x0634,
  1232. afii57429: 0x0635,
  1233. afii57430: 0x0636,
  1234. afii57431: 0x0637,
  1235. afii57432: 0x0638,
  1236. afii57433: 0x0639,
  1237. afii57434: 0x063A,
  1238. afii57440: 0x0640,
  1239. afii57441: 0x0641,
  1240. afii57442: 0x0642,
  1241. afii57443: 0x0643,
  1242. afii57444: 0x0644,
  1243. afii57445: 0x0645,
  1244. afii57446: 0x0646,
  1245. afii57448: 0x0648,
  1246. afii57449: 0x0649,
  1247. afii57450: 0x064A,
  1248. afii57451: 0x064B,
  1249. afii57452: 0x064C,
  1250. afii57453: 0x064D,
  1251. afii57454: 0x064E,
  1252. afii57455: 0x064F,
  1253. afii57456: 0x0650,
  1254. afii57457: 0x0651,
  1255. afii57458: 0x0652,
  1256. afii57470: 0x0647,
  1257. afii57505: 0x06A4,
  1258. afii57506: 0x067E,
  1259. afii57507: 0x0686,
  1260. afii57508: 0x0698,
  1261. afii57509: 0x06AF,
  1262. afii57511: 0x0679,
  1263. afii57512: 0x0688,
  1264. afii57513: 0x0691,
  1265. afii57514: 0x06BA,
  1266. afii57519: 0x06D2,
  1267. afii57534: 0x06D5,
  1268. afii57636: 0x20AA,
  1269. afii57645: 0x05BE,
  1270. afii57658: 0x05C3,
  1271. afii57664: 0x05D0,
  1272. afii57665: 0x05D1,
  1273. afii57666: 0x05D2,
  1274. afii57667: 0x05D3,
  1275. afii57668: 0x05D4,
  1276. afii57669: 0x05D5,
  1277. afii57670: 0x05D6,
  1278. afii57671: 0x05D7,
  1279. afii57672: 0x05D8,
  1280. afii57673: 0x05D9,
  1281. afii57674: 0x05DA,
  1282. afii57675: 0x05DB,
  1283. afii57676: 0x05DC,
  1284. afii57677: 0x05DD,
  1285. afii57678: 0x05DE,
  1286. afii57679: 0x05DF,
  1287. afii57680: 0x05E0,
  1288. afii57681: 0x05E1,
  1289. afii57682: 0x05E2,
  1290. afii57683: 0x05E3,
  1291. afii57684: 0x05E4,
  1292. afii57685: 0x05E5,
  1293. afii57686: 0x05E6,
  1294. afii57687: 0x05E7,
  1295. afii57688: 0x05E8,
  1296. afii57689: 0x05E9,
  1297. afii57690: 0x05EA,
  1298. afii57694: 0xFB2A,
  1299. afii57695: 0xFB2B,
  1300. afii57700: 0xFB4B,
  1301. afii57705: 0xFB1F,
  1302. afii57716: 0x05F0,
  1303. afii57717: 0x05F1,
  1304. afii57718: 0x05F2,
  1305. afii57723: 0xFB35,
  1306. afii57793: 0x05B4,
  1307. afii57794: 0x05B5,
  1308. afii57795: 0x05B6,
  1309. afii57796: 0x05BB,
  1310. afii57797: 0x05B8,
  1311. afii57798: 0x05B7,
  1312. afii57799: 0x05B0,
  1313. afii57800: 0x05B2,
  1314. afii57801: 0x05B1,
  1315. afii57802: 0x05B3,
  1316. afii57803: 0x05C2,
  1317. afii57804: 0x05C1,
  1318. afii57806: 0x05B9,
  1319. afii57807: 0x05BC,
  1320. afii57839: 0x05BD,
  1321. afii57841: 0x05BF,
  1322. afii57842: 0x05C0,
  1323. afii57929: 0x02BC,
  1324. afii61248: 0x2105,
  1325. afii61289: 0x2113,
  1326. afii61352: 0x2116,
  1327. afii61573: 0x202C,
  1328. afii61574: 0x202D,
  1329. afii61575: 0x202E,
  1330. afii61664: 0x200C,
  1331. afii63167: 0x066D,
  1332. afii64937: 0x02BD,
  1333. agrave: 0x00E0,
  1334. agujarati: 0x0A85,
  1335. agurmukhi: 0x0A05,
  1336. ahiragana: 0x3042,
  1337. ahookabove: 0x1EA3,
  1338. aibengali: 0x0990,
  1339. aibopomofo: 0x311E,
  1340. aideva: 0x0910,
  1341. aiecyrillic: 0x04D5,
  1342. aigujarati: 0x0A90,
  1343. aigurmukhi: 0x0A10,
  1344. aimatragurmukhi: 0x0A48,
  1345. ainarabic: 0x0639,
  1346. ainfinalarabic: 0xFECA,
  1347. aininitialarabic: 0xFECB,
  1348. ainmedialarabic: 0xFECC,
  1349. ainvertedbreve: 0x0203,
  1350. aivowelsignbengali: 0x09C8,
  1351. aivowelsigndeva: 0x0948,
  1352. aivowelsigngujarati: 0x0AC8,
  1353. akatakana: 0x30A2,
  1354. akatakanahalfwidth: 0xFF71,
  1355. akorean: 0x314F,
  1356. alef: 0x05D0,
  1357. alefarabic: 0x0627,
  1358. alefdageshhebrew: 0xFB30,
  1359. aleffinalarabic: 0xFE8E,
  1360. alefhamzaabovearabic: 0x0623,
  1361. alefhamzaabovefinalarabic: 0xFE84,
  1362. alefhamzabelowarabic: 0x0625,
  1363. alefhamzabelowfinalarabic: 0xFE88,
  1364. alefhebrew: 0x05D0,
  1365. aleflamedhebrew: 0xFB4F,
  1366. alefmaddaabovearabic: 0x0622,
  1367. alefmaddaabovefinalarabic: 0xFE82,
  1368. alefmaksuraarabic: 0x0649,
  1369. alefmaksurafinalarabic: 0xFEF0,
  1370. alefmaksurainitialarabic: 0xFEF3,
  1371. alefmaksuramedialarabic: 0xFEF4,
  1372. alefpatahhebrew: 0xFB2E,
  1373. alefqamatshebrew: 0xFB2F,
  1374. aleph: 0x2135,
  1375. allequal: 0x224C,
  1376. alpha: 0x03B1,
  1377. alphatonos: 0x03AC,
  1378. amacron: 0x0101,
  1379. amonospace: 0xFF41,
  1380. ampersand: 0x0026,
  1381. ampersandmonospace: 0xFF06,
  1382. ampersandsmall: 0xF726,
  1383. amsquare: 0x33C2,
  1384. anbopomofo: 0x3122,
  1385. angbopomofo: 0x3124,
  1386. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  1387. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  1388. angkhankhuthai: 0x0E5A,
  1389. angle: 0x2220,
  1390. anglebracketleft: 0x3008,
  1391. anglebracketleftvertical: 0xFE3F,
  1392. anglebracketright: 0x3009,
  1393. anglebracketrightvertical: 0xFE40,
  1394. angleleft: 0x2329,
  1395. angleright: 0x232A,
  1396. angstrom: 0x212B,
  1397. anoteleia: 0x0387,
  1398. anudattadeva: 0x0952,
  1399. anusvarabengali: 0x0982,
  1400. anusvaradeva: 0x0902,
  1401. anusvaragujarati: 0x0A82,
  1402. aogonek: 0x0105,
  1403. apaatosquare: 0x3300,
  1404. aparen: 0x249C,
  1405. apostrophearmenian: 0x055A,
  1406. apostrophemod: 0x02BC,
  1407. apple: 0xF8FF,
  1408. approaches: 0x2250,
  1409. approxequal: 0x2248,
  1410. approxequalorimage: 0x2252,
  1411. approximatelyequal: 0x2245,
  1412. araeaekorean: 0x318E,
  1413. araeakorean: 0x318D,
  1414. arc: 0x2312,
  1415. arighthalfring: 0x1E9A,
  1416. aring: 0x00E5,
  1417. aringacute: 0x01FB,
  1418. aringbelow: 0x1E01,
  1419. arrowboth: 0x2194,
  1420. arrowdashdown: 0x21E3,
  1421. arrowdashleft: 0x21E0,
  1422. arrowdashright: 0x21E2,
  1423. arrowdashup: 0x21E1,
  1424. arrowdblboth: 0x21D4,
  1425. arrowdbldown: 0x21D3,
  1426. arrowdblleft: 0x21D0,
  1427. arrowdblright: 0x21D2,
  1428. arrowdblup: 0x21D1,
  1429. arrowdown: 0x2193,
  1430. arrowdownleft: 0x2199,
  1431. arrowdownright: 0x2198,
  1432. arrowdownwhite: 0x21E9,
  1433. arrowheaddownmod: 0x02C5,
  1434. arrowheadleftmod: 0x02C2,
  1435. arrowheadrightmod: 0x02C3,
  1436. arrowheadupmod: 0x02C4,
  1437. arrowhorizex: 0xF8E7,
  1438. arrowleft: 0x2190,
  1439. arrowleftdbl: 0x21D0,
  1440. arrowleftdblstroke: 0x21CD,
  1441. arrowleftoverright: 0x21C6,
  1442. arrowleftwhite: 0x21E6,
  1443. arrowright: 0x2192,
  1444. arrowrightdblstroke: 0x21CF,
  1445. arrowrightheavy: 0x279E,
  1446. arrowrightoverleft: 0x21C4,
  1447. arrowrightwhite: 0x21E8,
  1448. arrowtableft: 0x21E4,
  1449. arrowtabright: 0x21E5,
  1450. arrowup: 0x2191,
  1451. arrowupdn: 0x2195,
  1452. arrowupdnbse: 0x21A8,
  1453. arrowupdownbase: 0x21A8,
  1454. arrowupleft: 0x2196,
  1455. arrowupleftofdown: 0x21C5,
  1456. arrowupright: 0x2197,
  1457. arrowupwhite: 0x21E7,
  1458. arrowvertex: 0xF8E6,
  1459. asciicircum: 0x005E,
  1460. asciicircummonospace: 0xFF3E,
  1461. asciitilde: 0x007E,
  1462. asciitildemonospace: 0xFF5E,
  1463. ascript: 0x0251,
  1464. ascriptturned: 0x0252,
  1465. asmallhiragana: 0x3041,
  1466. asmallkatakana: 0x30A1,
  1467. asmallkatakanahalfwidth: 0xFF67,
  1468. asterisk: 0x002A,
  1469. asteriskaltonearabic: 0x066D,
  1470. asteriskarabic: 0x066D,
  1471. asteriskmath: 0x2217,
  1472. asteriskmonospace: 0xFF0A,
  1473. asterisksmall: 0xFE61,
  1474. asterism: 0x2042,
  1475. asuperior: 0xF6E9,
  1476. asymptoticallyequal: 0x2243,
  1477. at: 0x0040,
  1478. atilde: 0x00E3,
  1479. atmonospace: 0xFF20,
  1480. atsmall: 0xFE6B,
  1481. aturned: 0x0250,
  1482. aubengali: 0x0994,
  1483. aubopomofo: 0x3120,
  1484. audeva: 0x0914,
  1485. augujarati: 0x0A94,
  1486. augurmukhi: 0x0A14,
  1487. aulengthmarkbengali: 0x09D7,
  1488. aumatragurmukhi: 0x0A4C,
  1489. auvowelsignbengali: 0x09CC,
  1490. auvowelsigndeva: 0x094C,
  1491. auvowelsigngujarati: 0x0ACC,
  1492. avagrahadeva: 0x093D,
  1493. aybarmenian: 0x0561,
  1494. ayin: 0x05E2,
  1495. ayinaltonehebrew: 0xFB20,
  1496. ayinhebrew: 0x05E2,
  1497. b: 0x0062,
  1498. babengali: 0x09AC,
  1499. backslash: 0x005C,
  1500. backslashmonospace: 0xFF3C,
  1501. badeva: 0x092C,
  1502. bagujarati: 0x0AAC,
  1503. bagurmukhi: 0x0A2C,
  1504. bahiragana: 0x3070,
  1505. bahtthai: 0x0E3F,
  1506. bakatakana: 0x30D0,
  1507. bar: 0x007C,
  1508. barmonospace: 0xFF5C,
  1509. bbopomofo: 0x3105,
  1510. bcircle: 0x24D1,
  1511. bdotaccent: 0x1E03,
  1512. bdotbelow: 0x1E05,
  1513. beamedsixteenthnotes: 0x266C,
  1514. because: 0x2235,
  1515. becyrillic: 0x0431,
  1516. beharabic: 0x0628,
  1517. behfinalarabic: 0xFE90,
  1518. behinitialarabic: 0xFE91,
  1519. behiragana: 0x3079,
  1520. behmedialarabic: 0xFE92,
  1521. behmeeminitialarabic: 0xFC9F,
  1522. behmeemisolatedarabic: 0xFC08,
  1523. behnoonfinalarabic: 0xFC6D,
  1524. bekatakana: 0x30D9,
  1525. benarmenian: 0x0562,
  1526. bet: 0x05D1,
  1527. beta: 0x03B2,
  1528. betasymbolgreek: 0x03D0,
  1529. betdagesh: 0xFB31,
  1530. betdageshhebrew: 0xFB31,
  1531. bethebrew: 0x05D1,
  1532. betrafehebrew: 0xFB4C,
  1533. bhabengali: 0x09AD,
  1534. bhadeva: 0x092D,
  1535. bhagujarati: 0x0AAD,
  1536. bhagurmukhi: 0x0A2D,
  1537. bhook: 0x0253,
  1538. bihiragana: 0x3073,
  1539. bikatakana: 0x30D3,
  1540. bilabialclick: 0x0298,
  1541. bindigurmukhi: 0x0A02,
  1542. birusquare: 0x3331,
  1543. blackcircle: 0x25CF,
  1544. blackdiamond: 0x25C6,
  1545. blackdownpointingtriangle: 0x25BC,
  1546. blackleftpointingpointer: 0x25C4,
  1547. blackleftpointingtriangle: 0x25C0,
  1548. blacklenticularbracketleft: 0x3010,
  1549. blacklenticularbracketleftvertical: 0xFE3B,
  1550. blacklenticularbracketright: 0x3011,
  1551. blacklenticularbracketrightvertical: 0xFE3C,
  1552. blacklowerlefttriangle: 0x25E3,
  1553. blacklowerrighttriangle: 0x25E2,
  1554. blackrectangle: 0x25AC,
  1555. blackrightpointingpointer: 0x25BA,
  1556. blackrightpointingtriangle: 0x25B6,
  1557. blacksmallsquare: 0x25AA,
  1558. blacksmilingface: 0x263B,
  1559. blacksquare: 0x25A0,
  1560. blackstar: 0x2605,
  1561. blackupperlefttriangle: 0x25E4,
  1562. blackupperrighttriangle: 0x25E5,
  1563. blackuppointingsmalltriangle: 0x25B4,
  1564. blackuppointingtriangle: 0x25B2,
  1565. blank: 0x2423,
  1566. blinebelow: 0x1E07,
  1567. block: 0x2588,
  1568. bmonospace: 0xFF42,
  1569. bobaimaithai: 0x0E1A,
  1570. bohiragana: 0x307C,
  1571. bokatakana: 0x30DC,
  1572. bparen: 0x249D,
  1573. bqsquare: 0x33C3,
  1574. braceex: 0xF8F4,
  1575. braceleft: 0x007B,
  1576. braceleftbt: 0xF8F3,
  1577. braceleftmid: 0xF8F2,
  1578. braceleftmonospace: 0xFF5B,
  1579. braceleftsmall: 0xFE5B,
  1580. bracelefttp: 0xF8F1,
  1581. braceleftvertical: 0xFE37,
  1582. braceright: 0x007D,
  1583. bracerightbt: 0xF8FE,
  1584. bracerightmid: 0xF8FD,
  1585. bracerightmonospace: 0xFF5D,
  1586. bracerightsmall: 0xFE5C,
  1587. bracerighttp: 0xF8FC,
  1588. bracerightvertical: 0xFE38,
  1589. bracketleft: 0x005B,
  1590. bracketleftbt: 0xF8F0,
  1591. bracketleftex: 0xF8EF,
  1592. bracketleftmonospace: 0xFF3B,
  1593. bracketlefttp: 0xF8EE,
  1594. bracketright: 0x005D,
  1595. bracketrightbt: 0xF8FB,
  1596. bracketrightex: 0xF8FA,
  1597. bracketrightmonospace: 0xFF3D,
  1598. bracketrighttp: 0xF8F9,
  1599. breve: 0x02D8,
  1600. brevebelowcmb: 0x032E,
  1601. brevecmb: 0x0306,
  1602. breveinvertedbelowcmb: 0x032F,
  1603. breveinvertedcmb: 0x0311,
  1604. breveinverteddoublecmb: 0x0361,
  1605. bridgebelowcmb: 0x032A,
  1606. bridgeinvertedbelowcmb: 0x033A,
  1607. brokenbar: 0x00A6,
  1608. bstroke: 0x0180,
  1609. bsuperior: 0xF6EA,
  1610. btopbar: 0x0183,
  1611. buhiragana: 0x3076,
  1612. bukatakana: 0x30D6,
  1613. bullet: 0x2022,
  1614. bulletinverse: 0x25D8,
  1615. bulletoperator: 0x2219,
  1616. bullseye: 0x25CE,
  1617. c: 0x0063,
  1618. caarmenian: 0x056E,
  1619. cabengali: 0x099A,
  1620. cacute: 0x0107,
  1621. cadeva: 0x091A,
  1622. cagujarati: 0x0A9A,
  1623. cagurmukhi: 0x0A1A,
  1624. calsquare: 0x3388,
  1625. candrabindubengali: 0x0981,
  1626. candrabinducmb: 0x0310,
  1627. candrabindudeva: 0x0901,
  1628. candrabindugujarati: 0x0A81,
  1629. capslock: 0x21EA,
  1630. careof: 0x2105,
  1631. caron: 0x02C7,
  1632. caronbelowcmb: 0x032C,
  1633. caroncmb: 0x030C,
  1634. carriagereturn: 0x21B5,
  1635. cbopomofo: 0x3118,
  1636. ccaron: 0x010D,
  1637. ccedilla: 0x00E7,
  1638. ccedillaacute: 0x1E09,
  1639. ccircle: 0x24D2,
  1640. ccircumflex: 0x0109,
  1641. ccurl: 0x0255,
  1642. cdot: 0x010B,
  1643. cdotaccent: 0x010B,
  1644. cdsquare: 0x33C5,
  1645. cedilla: 0x00B8,
  1646. cedillacmb: 0x0327,
  1647. cent: 0x00A2,
  1648. centigrade: 0x2103,
  1649. centinferior: 0xF6DF,
  1650. centmonospace: 0xFFE0,
  1651. centoldstyle: 0xF7A2,
  1652. centsuperior: 0xF6E0,
  1653. chaarmenian: 0x0579,
  1654. chabengali: 0x099B,
  1655. chadeva: 0x091B,
  1656. chagujarati: 0x0A9B,
  1657. chagurmukhi: 0x0A1B,
  1658. chbopomofo: 0x3114,
  1659. cheabkhasiancyrillic: 0x04BD,
  1660. checkmark: 0x2713,
  1661. checyrillic: 0x0447,
  1662. chedescenderabkhasiancyrillic: 0x04BF,
  1663. chedescendercyrillic: 0x04B7,
  1664. chedieresiscyrillic: 0x04F5,
  1665. cheharmenian: 0x0573,
  1666. chekhakassiancyrillic: 0x04CC,
  1667. cheverticalstrokecyrillic: 0x04B9,
  1668. chi: 0x03C7,
  1669. chieuchacirclekorean: 0x3277,
  1670. chieuchaparenkorean: 0x3217,
  1671. chieuchcirclekorean: 0x3269,
  1672. chieuchkorean: 0x314A,
  1673. chieuchparenkorean: 0x3209,
  1674. chochangthai: 0x0E0A,
  1675. chochanthai: 0x0E08,
  1676. chochingthai: 0x0E09,
  1677. chochoethai: 0x0E0C,
  1678. chook: 0x0188,
  1679. cieucacirclekorean: 0x3276,
  1680. cieucaparenkorean: 0x3216,
  1681. cieuccirclekorean: 0x3268,
  1682. cieuckorean: 0x3148,
  1683. cieucparenkorean: 0x3208,
  1684. cieucuparenkorean: 0x321C,
  1685. circle: 0x25CB,
  1686. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  1687. circlemultiply: 0x2297,
  1688. circleot: 0x2299,
  1689. circleplus: 0x2295,
  1690. circlepostalmark: 0x3036,
  1691. circlewithlefthalfblack: 0x25D0,
  1692. circlewithrighthalfblack: 0x25D1,
  1693. circumflex: 0x02C6,
  1694. circumflexbelowcmb: 0x032D,
  1695. circumflexcmb: 0x0302,
  1696. clear: 0x2327,
  1697. clickalveolar: 0x01C2,
  1698. clickdental: 0x01C0,
  1699. clicklateral: 0x01C1,
  1700. clickretroflex: 0x01C3,
  1701. club: 0x2663,
  1702. clubsuitblack: 0x2663,
  1703. clubsuitwhite: 0x2667,
  1704. cmcubedsquare: 0x33A4,
  1705. cmonospace: 0xFF43,
  1706. cmsquaredsquare: 0x33A0,
  1707. coarmenian: 0x0581,
  1708. colon: 0x003A,
  1709. colonmonetary: 0x20A1,
  1710. colonmonospace: 0xFF1A,
  1711. colonsign: 0x20A1,
  1712. colonsmall: 0xFE55,
  1713. colontriangularhalfmod: 0x02D1,
  1714. colontriangularmod: 0x02D0,
  1715. comma: 0x002C,
  1716. commaabovecmb: 0x0313,
  1717. commaaboverightcmb: 0x0315,
  1718. commaaccent: 0xF6C3,
  1719. commaarabic: 0x060C,
  1720. commaarmenian: 0x055D,
  1721. commainferior: 0xF6E1,
  1722. commamonospace: 0xFF0C,
  1723. commareversedabovecmb: 0x0314,
  1724. commareversedmod: 0x02BD,
  1725. commasmall: 0xFE50,
  1726. commasuperior: 0xF6E2,
  1727. commaturnedabovecmb: 0x0312,
  1728. commaturnedmod: 0x02BB,
  1729. compass: 0x263C,
  1730. congruent: 0x2245,
  1731. contourintegral: 0x222E,
  1732. control: 0x2303,
  1733. controlACK: 0x0006,
  1734. controlBEL: 0x0007,
  1735. controlBS: 0x0008,
  1736. controlCAN: 0x0018,
  1737. controlCR: 0x000D,
  1738. controlDC1: 0x0011,
  1739. controlDC2: 0x0012,
  1740. controlDC3: 0x0013,
  1741. controlDC4: 0x0014,
  1742. controlDEL: 0x007F,
  1743. controlDLE: 0x0010,
  1744. controlEM: 0x0019,
  1745. controlENQ: 0x0005,
  1746. controlEOT: 0x0004,
  1747. controlESC: 0x001B,
  1748. controlETB: 0x0017,
  1749. controlETX: 0x0003,
  1750. controlFF: 0x000C,
  1751. controlFS: 0x001C,
  1752. controlGS: 0x001D,
  1753. controlHT: 0x0009,
  1754. controlLF: 0x000A,
  1755. controlNAK: 0x0015,
  1756. controlRS: 0x001E,
  1757. controlSI: 0x000F,
  1758. controlSO: 0x000E,
  1759. controlSOT: 0x0002,
  1760. controlSTX: 0x0001,
  1761. controlSUB: 0x001A,
  1762. controlSYN: 0x0016,
  1763. controlUS: 0x001F,
  1764. controlVT: 0x000B,
  1765. copyright: 0x00A9,
  1766. copyrightsans: 0xF8E9,
  1767. copyrightserif: 0xF6D9,
  1768. cornerbracketleft: 0x300C,
  1769. cornerbracketlefthalfwidth: 0xFF62,
  1770. cornerbracketleftvertical: 0xFE41,
  1771. cornerbracketright: 0x300D,
  1772. cornerbracketrighthalfwidth: 0xFF63,
  1773. cornerbracketrightvertical: 0xFE42,
  1774. corporationsquare: 0x337F,
  1775. cosquare: 0x33C7,
  1776. coverkgsquare: 0x33C6,
  1777. cparen: 0x249E,
  1778. cruzeiro: 0x20A2,
  1779. cstretched: 0x0297,
  1780. curlyand: 0x22CF,
  1781. curlyor: 0x22CE,
  1782. currency: 0x00A4,
  1783. cyrBreve: 0xF6D1,
  1784. cyrFlex: 0xF6D2,
  1785. cyrbreve: 0xF6D4,
  1786. cyrflex: 0xF6D5,
  1787. d: 0x0064,
  1788. daarmenian: 0x0564,
  1789. dabengali: 0x09A6,
  1790. dadarabic: 0x0636,
  1791. dadeva: 0x0926,
  1792. dadfinalarabic: 0xFEBE,
  1793. dadinitialarabic: 0xFEBF,
  1794. dadmedialarabic: 0xFEC0,
  1795. dagesh: 0x05BC,
  1796. dageshhebrew: 0x05BC,
  1797. dagger: 0x2020,
  1798. daggerdbl: 0x2021,
  1799. dagujarati: 0x0AA6,
  1800. dagurmukhi: 0x0A26,
  1801. dahiragana: 0x3060,
  1802. dakatakana: 0x30C0,
  1803. dalarabic: 0x062F,
  1804. dalet: 0x05D3,
  1805. daletdagesh: 0xFB33,
  1806. daletdageshhebrew: 0xFB33,
  1807. dalethebrew: 0x05D3,
  1808. dalfinalarabic: 0xFEAA,
  1809. dammaarabic: 0x064F,
  1810. dammalowarabic: 0x064F,
  1811. dammatanaltonearabic: 0x064C,
  1812. dammatanarabic: 0x064C,
  1813. danda: 0x0964,
  1814. dargahebrew: 0x05A7,
  1815. dargalefthebrew: 0x05A7,
  1816. dasiapneumatacyrilliccmb: 0x0485,
  1817. dblGrave: 0xF6D3,
  1818. dblanglebracketleft: 0x300A,
  1819. dblanglebracketleftvertical: 0xFE3D,
  1820. dblanglebracketright: 0x300B,
  1821. dblanglebracketrightvertical: 0xFE3E,
  1822. dblarchinvertedbelowcmb: 0x032B,
  1823. dblarrowleft: 0x21D4,
  1824. dblarrowright: 0x21D2,
  1825. dbldanda: 0x0965,
  1826. dblgrave: 0xF6D6,
  1827. dblgravecmb: 0x030F,
  1828. dblintegral: 0x222C,
  1829. dbllowline: 0x2017,
  1830. dbllowlinecmb: 0x0333,
  1831. dbloverlinecmb: 0x033F,
  1832. dblprimemod: 0x02BA,
  1833. dblverticalbar: 0x2016,
  1834. dblverticallineabovecmb: 0x030E,
  1835. dbopomofo: 0x3109,
  1836. dbsquare: 0x33C8,
  1837. dcaron: 0x010F,
  1838. dcedilla: 0x1E11,
  1839. dcircle: 0x24D3,
  1840. dcircumflexbelow: 0x1E13,
  1841. dcroat: 0x0111,
  1842. ddabengali: 0x09A1,
  1843. ddadeva: 0x0921,
  1844. ddagujarati: 0x0AA1,
  1845. ddagurmukhi: 0x0A21,
  1846. ddalarabic: 0x0688,
  1847. ddalfinalarabic: 0xFB89,
  1848. dddhadeva: 0x095C,
  1849. ddhabengali: 0x09A2,
  1850. ddhadeva: 0x0922,
  1851. ddhagujarati: 0x0AA2,
  1852. ddhagurmukhi: 0x0A22,
  1853. ddotaccent: 0x1E0B,
  1854. ddotbelow: 0x1E0D,
  1855. decimalseparatorarabic: 0x066B,
  1856. decimalseparatorpersian: 0x066B,
  1857. decyrillic: 0x0434,
  1858. degree: 0x00B0,
  1859. dehihebrew: 0x05AD,
  1860. dehiragana: 0x3067,
  1861. deicoptic: 0x03EF,
  1862. dekatakana: 0x30C7,
  1863. deleteleft: 0x232B,
  1864. deleteright: 0x2326,
  1865. delta: 0x03B4,
  1866. deltaturned: 0x018D,
  1867. denominatorminusonenumeratorbengali: 0x09F8,
  1868. dezh: 0x02A4,
  1869. dhabengali: 0x09A7,
  1870. dhadeva: 0x0927,
  1871. dhagujarati: 0x0AA7,
  1872. dhagurmukhi: 0x0A27,
  1873. dhook: 0x0257,
  1874. dialytikatonos: 0x0385,
  1875. dialytikatonoscmb: 0x0344,
  1876. diamond: 0x2666,
  1877. diamondsuitwhite: 0x2662,
  1878. dieresis: 0x00A8,
  1879. dieresisacute: 0xF6D7,
  1880. dieresisbelowcmb: 0x0324,
  1881. dieresiscmb: 0x0308,
  1882. dieresisgrave: 0xF6D8,
  1883. dieresistonos: 0x0385,
  1884. dihiragana: 0x3062,
  1885. dikatakana: 0x30C2,
  1886. dittomark: 0x3003,
  1887. divide: 0x00F7,
  1888. divides: 0x2223,
  1889. divisionslash: 0x2215,
  1890. djecyrillic: 0x0452,
  1891. dkshade: 0x2593,
  1892. dlinebelow: 0x1E0F,
  1893. dlsquare: 0x3397,
  1894. dmacron: 0x0111,
  1895. dmonospace: 0xFF44,
  1896. dnblock: 0x2584,
  1897. dochadathai: 0x0E0E,
  1898. dodekthai: 0x0E14,
  1899. dohiragana: 0x3069,
  1900. dokatakana: 0x30C9,
  1901. dollar: 0x0024,
  1902. dollarinferior: 0xF6E3,
  1903. dollarmonospace: 0xFF04,
  1904. dollaroldstyle: 0xF724,
  1905. dollarsmall: 0xFE69,
  1906. dollarsuperior: 0xF6E4,
  1907. dong: 0x20AB,
  1908. dorusquare: 0x3326,
  1909. dotaccent: 0x02D9,
  1910. dotaccentcmb: 0x0307,
  1911. dotbelowcmb: 0x0323,
  1912. dotbelowcomb: 0x0323,
  1913. dotkatakana: 0x30FB,
  1914. dotlessi: 0x0131,
  1915. dotlessj: 0xF6BE,
  1916. dotlessjstrokehook: 0x0284,
  1917. dotmath: 0x22C5,
  1918. dottedcircle: 0x25CC,
  1919. doubleyodpatah: 0xFB1F,
  1920. doubleyodpatahhebrew: 0xFB1F,
  1921. downtackbelowcmb: 0x031E,
  1922. downtackmod: 0x02D5,
  1923. dparen: 0x249F,
  1924. dsuperior: 0xF6EB,
  1925. dtail: 0x0256,
  1926. dtopbar: 0x018C,
  1927. duhiragana: 0x3065,
  1928. dukatakana: 0x30C5,
  1929. dz: 0x01F3,
  1930. dzaltone: 0x02A3,
  1931. dzcaron: 0x01C6,
  1932. dzcurl: 0x02A5,
  1933. dzeabkhasiancyrillic: 0x04E1,
  1934. dzecyrillic: 0x0455,
  1935. dzhecyrillic: 0x045F,
  1936. e: 0x0065,
  1937. eacute: 0x00E9,
  1938. earth: 0x2641,
  1939. ebengali: 0x098F,
  1940. ebopomofo: 0x311C,
  1941. ebreve: 0x0115,
  1942. ecandradeva: 0x090D,
  1943. ecandragujarati: 0x0A8D,
  1944. ecandravowelsigndeva: 0x0945,
  1945. ecandravowelsigngujarati: 0x0AC5,
  1946. ecaron: 0x011B,
  1947. ecedillabreve: 0x1E1D,
  1948. echarmenian: 0x0565,
  1949. echyiwnarmenian: 0x0587,
  1950. ecircle: 0x24D4,
  1951. ecircumflex: 0x00EA,
  1952. ecircumflexacute: 0x1EBF,
  1953. ecircumflexbelow: 0x1E19,
  1954. ecircumflexdotbelow: 0x1EC7,
  1955. ecircumflexgrave: 0x1EC1,
  1956. ecircumflexhookabove: 0x1EC3,
  1957. ecircumflextilde: 0x1EC5,
  1958. ecyrillic: 0x0454,
  1959. edblgrave: 0x0205,
  1960. edeva: 0x090F,
  1961. edieresis: 0x00EB,
  1962. edot: 0x0117,
  1963. edotaccent: 0x0117,
  1964. edotbelow: 0x1EB9,
  1965. eegurmukhi: 0x0A0F,
  1966. eematragurmukhi: 0x0A47,
  1967. efcyrillic: 0x0444,
  1968. egrave: 0x00E8,
  1969. egujarati: 0x0A8F,
  1970. eharmenian: 0x0567,
  1971. ehbopomofo: 0x311D,
  1972. ehiragana: 0x3048,
  1973. ehookabove: 0x1EBB,
  1974. eibopomofo: 0x311F,
  1975. eight: 0x0038,
  1976. eightarabic: 0x0668,
  1977. eightbengali: 0x09EE,
  1978. eightcircle: 0x2467,
  1979. eightcircleinversesansserif: 0x2791,
  1980. eightdeva: 0x096E,
  1981. eighteencircle: 0x2471,
  1982. eighteenparen: 0x2485,
  1983. eighteenperiod: 0x2499,
  1984. eightgujarati: 0x0AEE,
  1985. eightgurmukhi: 0x0A6E,
  1986. eighthackarabic: 0x0668,
  1987. eighthangzhou: 0x3028,
  1988. eighthnotebeamed: 0x266B,
  1989. eightideographicparen: 0x3227,
  1990. eightinferior: 0x2088,
  1991. eightmonospace: 0xFF18,
  1992. eightoldstyle: 0xF738,
  1993. eightparen: 0x247B,
  1994. eightperiod: 0x248F,
  1995. eightpersian: 0x06F8,
  1996. eightroman: 0x2177,
  1997. eightsuperior: 0x2078,
  1998. eightthai: 0x0E58,
  1999. einvertedbreve: 0x0207,
  2000. eiotifiedcyrillic: 0x0465,
  2001. ekatakana: 0x30A8,
  2002. ekatakanahalfwidth: 0xFF74,
  2003. ekonkargurmukhi: 0x0A74,
  2004. ekorean: 0x3154,
  2005. elcyrillic: 0x043B,
  2006. element: 0x2208,
  2007. elevencircle: 0x246A,
  2008. elevenparen: 0x247E,
  2009. elevenperiod: 0x2492,
  2010. elevenroman: 0x217A,
  2011. ellipsis: 0x2026,
  2012. ellipsisvertical: 0x22EE,
  2013. emacron: 0x0113,
  2014. emacronacute: 0x1E17,
  2015. emacrongrave: 0x1E15,
  2016. emcyrillic: 0x043C,
  2017. emdash: 0x2014,
  2018. emdashvertical: 0xFE31,
  2019. emonospace: 0xFF45,
  2020. emphasismarkarmenian: 0x055B,
  2021. emptyset: 0x2205,
  2022. enbopomofo: 0x3123,
  2023. encyrillic: 0x043D,
  2024. endash: 0x2013,
  2025. endashvertical: 0xFE32,
  2026. endescendercyrillic: 0x04A3,
  2027. eng: 0x014B,
  2028. engbopomofo: 0x3125,
  2029. enghecyrillic: 0x04A5,
  2030. enhookcyrillic: 0x04C8,
  2031. enspace: 0x2002,
  2032. eogonek: 0x0119,
  2033. eokorean: 0x3153,
  2034. eopen: 0x025B,
  2035. eopenclosed: 0x029A,
  2036. eopenreversed: 0x025C,
  2037. eopenreversedclosed: 0x025E,
  2038. eopenreversedhook: 0x025D,
  2039. eparen: 0x24A0,
  2040. epsilon: 0x03B5,
  2041. epsilontonos: 0x03AD,
  2042. equal: 0x003D,
  2043. equalmonospace: 0xFF1D,
  2044. equalsmall: 0xFE66,
  2045. equalsuperior: 0x207C,
  2046. equivalence: 0x2261,
  2047. erbopomofo: 0x3126,
  2048. ercyrillic: 0x0440,
  2049. ereversed: 0x0258,
  2050. ereversedcyrillic: 0x044D,
  2051. escyrillic: 0x0441,
  2052. esdescendercyrillic: 0x04AB,
  2053. esh: 0x0283,
  2054. eshcurl: 0x0286,
  2055. eshortdeva: 0x090E,
  2056. eshortvowelsigndeva: 0x0946,
  2057. eshreversedloop: 0x01AA,
  2058. eshsquatreversed: 0x0285,
  2059. esmallhiragana: 0x3047,
  2060. esmallkatakana: 0x30A7,
  2061. esmallkatakanahalfwidth: 0xFF6A,
  2062. estimated: 0x212E,
  2063. esuperior: 0xF6EC,
  2064. eta: 0x03B7,
  2065. etarmenian: 0x0568,
  2066. etatonos: 0x03AE,
  2067. eth: 0x00F0,
  2068. etilde: 0x1EBD,
  2069. etildebelow: 0x1E1B,
  2070. etnahtafoukhhebrew: 0x0591,
  2071. etnahtafoukhlefthebrew: 0x0591,
  2072. etnahtahebrew: 0x0591,
  2073. etnahtalefthebrew: 0x0591,
  2074. eturned: 0x01DD,
  2075. eukorean: 0x3161,
  2076. euro: 0x20AC,
  2077. evowelsignbengali: 0x09C7,
  2078. evowelsigndeva: 0x0947,
  2079. evowelsigngujarati: 0x0AC7,
  2080. exclam: 0x0021,
  2081. exclamarmenian: 0x055C,
  2082. exclamdbl: 0x203C,
  2083. exclamdown: 0x00A1,
  2084. exclamdownsmall: 0xF7A1,
  2085. exclammonospace: 0xFF01,
  2086. exclamsmall: 0xF721,
  2087. existential: 0x2203,
  2088. ezh: 0x0292,
  2089. ezhcaron: 0x01EF,
  2090. ezhcurl: 0x0293,
  2091. ezhreversed: 0x01B9,
  2092. ezhtail: 0x01BA,
  2093. f: 0x0066,
  2094. fadeva: 0x095E,
  2095. fagurmukhi: 0x0A5E,
  2096. fahrenheit: 0x2109,
  2097. fathaarabic: 0x064E,
  2098. fathalowarabic: 0x064E,
  2099. fathatanarabic: 0x064B,
  2100. fbopomofo: 0x3108,
  2101. fcircle: 0x24D5,
  2102. fdotaccent: 0x1E1F,
  2103. feharabic: 0x0641,
  2104. feharmenian: 0x0586,
  2105. fehfinalarabic: 0xFED2,
  2106. fehinitialarabic: 0xFED3,
  2107. fehmedialarabic: 0xFED4,
  2108. feicoptic: 0x03E5,
  2109. female: 0x2640,
  2110. ff: 0xFB00,
  2111. ffi: 0xFB03,
  2112. ffl: 0xFB04,
  2113. fi: 0xFB01,
  2114. fifteencircle: 0x246E,
  2115. fifteenparen: 0x2482,
  2116. fifteenperiod: 0x2496,
  2117. figuredash: 0x2012,
  2118. filledbox: 0x25A0,
  2119. filledrect: 0x25AC,
  2120. finalkaf: 0x05DA,
  2121. finalkafdagesh: 0xFB3A,
  2122. finalkafdageshhebrew: 0xFB3A,
  2123. finalkafhebrew: 0x05DA,
  2124. finalmem: 0x05DD,
  2125. finalmemhebrew: 0x05DD,
  2126. finalnun: 0x05DF,
  2127. finalnunhebrew: 0x05DF,
  2128. finalpe: 0x05E3,
  2129. finalpehebrew: 0x05E3,
  2130. finaltsadi: 0x05E5,
  2131. finaltsadihebrew: 0x05E5,
  2132. firsttonechinese: 0x02C9,
  2133. fisheye: 0x25C9,
  2134. fitacyrillic: 0x0473,
  2135. five: 0x0035,
  2136. fivearabic: 0x0665,
  2137. fivebengali: 0x09EB,
  2138. fivecircle: 0x2464,
  2139. fivecircleinversesansserif: 0x278E,
  2140. fivedeva: 0x096B,
  2141. fiveeighths: 0x215D,
  2142. fivegujarati: 0x0AEB,
  2143. fivegurmukhi: 0x0A6B,
  2144. fivehackarabic: 0x0665,
  2145. fivehangzhou: 0x3025,
  2146. fiveideographicparen: 0x3224,
  2147. fiveinferior: 0x2085,
  2148. fivemonospace: 0xFF15,
  2149. fiveoldstyle: 0xF735,
  2150. fiveparen: 0x2478,
  2151. fiveperiod: 0x248C,
  2152. fivepersian: 0x06F5,
  2153. fiveroman: 0x2174,
  2154. fivesuperior: 0x2075,
  2155. fivethai: 0x0E55,
  2156. fl: 0xFB02,
  2157. florin: 0x0192,
  2158. fmonospace: 0xFF46,
  2159. fmsquare: 0x3399,
  2160. fofanthai: 0x0E1F,
  2161. fofathai: 0x0E1D,
  2162. fongmanthai: 0x0E4F,
  2163. forall: 0x2200,
  2164. four: 0x0034,
  2165. fourarabic: 0x0664,
  2166. fourbengali: 0x09EA,
  2167. fourcircle: 0x2463,
  2168. fourcircleinversesansserif: 0x278D,
  2169. fourdeva: 0x096A,
  2170. fourgujarati: 0x0AEA,
  2171. fourgurmukhi: 0x0A6A,
  2172. fourhackarabic: 0x0664,
  2173. fourhangzhou: 0x3024,
  2174. fourideographicparen: 0x3223,
  2175. fourinferior: 0x2084,
  2176. fourmonospace: 0xFF14,
  2177. fournumeratorbengali: 0x09F7,
  2178. fouroldstyle: 0xF734,
  2179. fourparen: 0x2477,
  2180. fourperiod: 0x248B,
  2181. fourpersian: 0x06F4,
  2182. fourroman: 0x2173,
  2183. foursuperior: 0x2074,
  2184. fourteencircle: 0x246D,
  2185. fourteenparen: 0x2481,
  2186. fourteenperiod: 0x2495,
  2187. fourthai: 0x0E54,
  2188. fourthtonechinese: 0x02CB,
  2189. fparen: 0x24A1,
  2190. fraction: 0x2044,
  2191. franc: 0x20A3,
  2192. g: 0x0067,
  2193. gabengali: 0x0997,
  2194. gacute: 0x01F5,
  2195. gadeva: 0x0917,
  2196. gafarabic: 0x06AF,
  2197. gaffinalarabic: 0xFB93,
  2198. gafinitialarabic: 0xFB94,
  2199. gafmedialarabic: 0xFB95,
  2200. gagujarati: 0x0A97,
  2201. gagurmukhi: 0x0A17,
  2202. gahiragana: 0x304C,
  2203. gakatakana: 0x30AC,
  2204. gamma: 0x03B3,
  2205. gammalatinsmall: 0x0263,
  2206. gammasuperior: 0x02E0,
  2207. gangiacoptic: 0x03EB,
  2208. gbopomofo: 0x310D,
  2209. gbreve: 0x011F,
  2210. gcaron: 0x01E7,
  2211. gcedilla: 0x0123,
  2212. gcircle: 0x24D6,
  2213. gcircumflex: 0x011D,
  2214. gcommaaccent: 0x0123,
  2215. gdot: 0x0121,
  2216. gdotaccent: 0x0121,
  2217. gecyrillic: 0x0433,
  2218. gehiragana: 0x3052,
  2219. gekatakana: 0x30B2,
  2220. geometricallyequal: 0x2251,
  2221. gereshaccenthebrew: 0x059C,
  2222. gereshhebrew: 0x05F3,
  2223. gereshmuqdamhebrew: 0x059D,
  2224. germandbls: 0x00DF,
  2225. gershayimaccenthebrew: 0x059E,
  2226. gershayimhebrew: 0x05F4,
  2227. getamark: 0x3013,
  2228. ghabengali: 0x0998,
  2229. ghadarmenian: 0x0572,
  2230. ghadeva: 0x0918,
  2231. ghagujarati: 0x0A98,
  2232. ghagurmukhi: 0x0A18,
  2233. ghainarabic: 0x063A,
  2234. ghainfinalarabic: 0xFECE,
  2235. ghaininitialarabic: 0xFECF,
  2236. ghainmedialarabic: 0xFED0,
  2237. ghemiddlehookcyrillic: 0x0495,
  2238. ghestrokecyrillic: 0x0493,
  2239. gheupturncyrillic: 0x0491,
  2240. ghhadeva: 0x095A,
  2241. ghhagurmukhi: 0x0A5A,
  2242. ghook: 0x0260,
  2243. ghzsquare: 0x3393,
  2244. gihiragana: 0x304E,
  2245. gikatakana: 0x30AE,
  2246. gimarmenian: 0x0563,
  2247. gimel: 0x05D2,
  2248. gimeldagesh: 0xFB32,
  2249. gimeldageshhebrew: 0xFB32,
  2250. gimelhebrew: 0x05D2,
  2251. gjecyrillic: 0x0453,
  2252. glottalinvertedstroke: 0x01BE,
  2253. glottalstop: 0x0294,
  2254. glottalstopinverted: 0x0296,
  2255. glottalstopmod: 0x02C0,
  2256. glottalstopreversed: 0x0295,
  2257. glottalstopreversedmod: 0x02C1,
  2258. glottalstopreversedsuperior: 0x02E4,
  2259. glottalstopstroke: 0x02A1,
  2260. glottalstopstrokereversed: 0x02A2,
  2261. gmacron: 0x1E21,
  2262. gmonospace: 0xFF47,
  2263. gohiragana: 0x3054,
  2264. gokatakana: 0x30B4,
  2265. gparen: 0x24A2,
  2266. gpasquare: 0x33AC,
  2267. gradient: 0x2207,
  2268. grave: 0x0060,
  2269. gravebelowcmb: 0x0316,
  2270. gravecmb: 0x0300,
  2271. gravecomb: 0x0300,
  2272. gravedeva: 0x0953,
  2273. gravelowmod: 0x02CE,
  2274. gravemonospace: 0xFF40,
  2275. gravetonecmb: 0x0340,
  2276. greater: 0x003E,
  2277. greaterequal: 0x2265,
  2278. greaterequalorless: 0x22DB,
  2279. greatermonospace: 0xFF1E,
  2280. greaterorequivalent: 0x2273,
  2281. greaterorless: 0x2277,
  2282. greateroverequal: 0x2267,
  2283. greatersmall: 0xFE65,
  2284. gscript: 0x0261,
  2285. gstroke: 0x01E5,
  2286. guhiragana: 0x3050,
  2287. guillemotleft: 0x00AB,
  2288. guillemotright: 0x00BB,
  2289. guilsinglleft: 0x2039,
  2290. guilsinglright: 0x203A,
  2291. gukatakana: 0x30B0,
  2292. guramusquare: 0x3318,
  2293. gysquare: 0x33C9,
  2294. h: 0x0068,
  2295. haabkhasiancyrillic: 0x04A9,
  2296. haaltonearabic: 0x06C1,
  2297. habengali: 0x09B9,
  2298. hadescendercyrillic: 0x04B3,
  2299. hadeva: 0x0939,
  2300. hagujarati: 0x0AB9,
  2301. hagurmukhi: 0x0A39,
  2302. haharabic: 0x062D,
  2303. hahfinalarabic: 0xFEA2,
  2304. hahinitialarabic: 0xFEA3,
  2305. hahiragana: 0x306F,
  2306. hahmedialarabic: 0xFEA4,
  2307. haitusquare: 0x332A,
  2308. hakatakana: 0x30CF,
  2309. hakatakanahalfwidth: 0xFF8A,
  2310. halantgurmukhi: 0x0A4D,
  2311. hamzaarabic: 0x0621,
  2312. hamzalowarabic: 0x0621,
  2313. hangulfiller: 0x3164,
  2314. hardsigncyrillic: 0x044A,
  2315. harpoonleftbarbup: 0x21BC,
  2316. harpoonrightbarbup: 0x21C0,
  2317. hasquare: 0x33CA,
  2318. hatafpatah: 0x05B2,
  2319. hatafpatah16: 0x05B2,
  2320. hatafpatah23: 0x05B2,
  2321. hatafpatah2f: 0x05B2,
  2322. hatafpatahhebrew: 0x05B2,
  2323. hatafpatahnarrowhebrew: 0x05B2,
  2324. hatafpatahquarterhebrew: 0x05B2,
  2325. hatafpatahwidehebrew: 0x05B2,
  2326. hatafqamats: 0x05B3,
  2327. hatafqamats1b: 0x05B3,
  2328. hatafqamats28: 0x05B3,
  2329. hatafqamats34: 0x05B3,
  2330. hatafqamatshebrew: 0x05B3,
  2331. hatafqamatsnarrowhebrew: 0x05B3,
  2332. hatafqamatsquarterhebrew: 0x05B3,
  2333. hatafqamatswidehebrew: 0x05B3,
  2334. hatafsegol: 0x05B1,
  2335. hatafsegol17: 0x05B1,
  2336. hatafsegol24: 0x05B1,
  2337. hatafsegol30: 0x05B1,
  2338. hatafsegolhebrew: 0x05B1,
  2339. hatafsegolnarrowhebrew: 0x05B1,
  2340. hatafsegolquarterhebrew: 0x05B1,
  2341. hatafsegolwidehebrew: 0x05B1,
  2342. hbar: 0x0127,
  2343. hbopomofo: 0x310F,
  2344. hbrevebelow: 0x1E2B,
  2345. hcedilla: 0x1E29,
  2346. hcircle: 0x24D7,
  2347. hcircumflex: 0x0125,
  2348. hdieresis: 0x1E27,
  2349. hdotaccent: 0x1E23,
  2350. hdotbelow: 0x1E25,
  2351. he: 0x05D4,
  2352. heart: 0x2665,
  2353. heartsuitblack: 0x2665,
  2354. heartsuitwhite: 0x2661,
  2355. hedagesh: 0xFB34,
  2356. hedageshhebrew: 0xFB34,
  2357. hehaltonearabic: 0x06C1,
  2358. heharabic: 0x0647,
  2359. hehebrew: 0x05D4,
  2360. hehfinalaltonearabic: 0xFBA7,
  2361. hehfinalalttwoarabic: 0xFEEA,
  2362. hehfinalarabic: 0xFEEA,
  2363. hehhamzaabovefinalarabic: 0xFBA5,
  2364. hehhamzaaboveisolatedarabic: 0xFBA4,
  2365. hehinitialaltonearabic: 0xFBA8,
  2366. hehinitialarabic: 0xFEEB,
  2367. hehiragana: 0x3078,
  2368. hehmedialaltonearabic: 0xFBA9,
  2369. hehmedialarabic: 0xFEEC,
  2370. heiseierasquare: 0x337B,
  2371. hekatakana: 0x30D8,
  2372. hekatakanahalfwidth: 0xFF8D,
  2373. hekutaarusquare: 0x3336,
  2374. henghook: 0x0267,
  2375. herutusquare: 0x3339,
  2376. het: 0x05D7,
  2377. hethebrew: 0x05D7,
  2378. hhook: 0x0266,
  2379. hhooksuperior: 0x02B1,
  2380. hieuhacirclekorean: 0x327B,
  2381. hieuhaparenkorean: 0x321B,
  2382. hieuhcirclekorean: 0x326D,
  2383. hieuhkorean: 0x314E,
  2384. hieuhparenkorean: 0x320D,
  2385. hihiragana: 0x3072,
  2386. hikatakana: 0x30D2,
  2387. hikatakanahalfwidth: 0xFF8B,
  2388. hiriq: 0x05B4,
  2389. hiriq14: 0x05B4,
  2390. hiriq21: 0x05B4,
  2391. hiriq2d: 0x05B4,
  2392. hiriqhebrew: 0x05B4,
  2393. hiriqnarrowhebrew: 0x05B4,
  2394. hiriqquarterhebrew: 0x05B4,
  2395. hiriqwidehebrew: 0x05B4,
  2396. hlinebelow: 0x1E96,
  2397. hmonospace: 0xFF48,
  2398. hoarmenian: 0x0570,
  2399. hohipthai: 0x0E2B,
  2400. hohiragana: 0x307B,
  2401. hokatakana: 0x30DB,
  2402. hokatakanahalfwidth: 0xFF8E,
  2403. holam: 0x05B9,
  2404. holam19: 0x05B9,
  2405. holam26: 0x05B9,
  2406. holam32: 0x05B9,
  2407. holamhebrew: 0x05B9,
  2408. holamnarrowhebrew: 0x05B9,
  2409. holamquarterhebrew: 0x05B9,
  2410. holamwidehebrew: 0x05B9,
  2411. honokhukthai: 0x0E2E,
  2412. hookabovecomb: 0x0309,
  2413. hookcmb: 0x0309,
  2414. hookpalatalizedbelowcmb: 0x0321,
  2415. hookretroflexbelowcmb: 0x0322,
  2416. hoonsquare: 0x3342,
  2417. horicoptic: 0x03E9,
  2418. horizontalbar: 0x2015,
  2419. horncmb: 0x031B,
  2420. hotsprings: 0x2668,
  2421. house: 0x2302,
  2422. hparen: 0x24A3,
  2423. hsuperior: 0x02B0,
  2424. hturned: 0x0265,
  2425. huhiragana: 0x3075,
  2426. huiitosquare: 0x3333,
  2427. hukatakana: 0x30D5,
  2428. hukatakanahalfwidth: 0xFF8C,
  2429. hungarumlaut: 0x02DD,
  2430. hungarumlautcmb: 0x030B,
  2431. hv: 0x0195,
  2432. hyphen: 0x002D,
  2433. hypheninferior: 0xF6E5,
  2434. hyphenmonospace: 0xFF0D,
  2435. hyphensmall: 0xFE63,
  2436. hyphensuperior: 0xF6E6,
  2437. hyphentwo: 0x2010,
  2438. i: 0x0069,
  2439. iacute: 0x00ED,
  2440. iacyrillic: 0x044F,
  2441. ibengali: 0x0987,
  2442. ibopomofo: 0x3127,
  2443. ibreve: 0x012D,
  2444. icaron: 0x01D0,
  2445. icircle: 0x24D8,
  2446. icircumflex: 0x00EE,
  2447. icyrillic: 0x0456,
  2448. idblgrave: 0x0209,
  2449. ideographearthcircle: 0x328F,
  2450. ideographfirecircle: 0x328B,
  2451. ideographicallianceparen: 0x323F,
  2452. ideographiccallparen: 0x323A,
  2453. ideographiccentrecircle: 0x32A5,
  2454. ideographicclose: 0x3006,
  2455. ideographiccomma: 0x3001,
  2456. ideographiccommaleft: 0xFF64,
  2457. ideographiccongratulationparen: 0x3237,
  2458. ideographiccorrectcircle: 0x32A3,
  2459. ideographicearthparen: 0x322F,
  2460. ideographicenterpriseparen: 0x323D,
  2461. ideographicexcellentcircle: 0x329D,
  2462. ideographicfestivalparen: 0x3240,
  2463. ideographicfinancialcircle: 0x3296,
  2464. ideographicfinancialparen: 0x3236,
  2465. ideographicfireparen: 0x322B,
  2466. ideographichaveparen: 0x3232,
  2467. ideographichighcircle: 0x32A4,
  2468. ideographiciterationmark: 0x3005,
  2469. ideographiclaborcircle: 0x3298,
  2470. ideographiclaborparen: 0x3238,
  2471. ideographicleftcircle: 0x32A7,
  2472. ideographiclowcircle: 0x32A6,
  2473. ideographicmedicinecircle: 0x32A9,
  2474. ideographicmetalparen: 0x322E,
  2475. ideographicmoonparen: 0x322A,
  2476. ideographicnameparen: 0x3234,
  2477. ideographicperiod: 0x3002,
  2478. ideographicprintcircle: 0x329E,
  2479. ideographicreachparen: 0x3243,
  2480. ideographicrepresentparen: 0x3239,
  2481. ideographicresourceparen: 0x323E,
  2482. ideographicrightcircle: 0x32A8,
  2483. ideographicsecretcircle: 0x3299,
  2484. ideographicselfparen: 0x3242,
  2485. ideographicsocietyparen: 0x3233,
  2486. ideographicspace: 0x3000,
  2487. ideographicspecialparen: 0x3235,
  2488. ideographicstockparen: 0x3231,
  2489. ideographicstudyparen: 0x323B,
  2490. ideographicsunparen: 0x3230,
  2491. ideographicsuperviseparen: 0x323C,
  2492. ideographicwaterparen: 0x322C,
  2493. ideographicwoodparen: 0x322D,
  2494. ideographiczero: 0x3007,
  2495. ideographmetalcircle: 0x328E,
  2496. ideographmooncircle: 0x328A,
  2497. ideographnamecircle: 0x3294,
  2498. ideographsuncircle: 0x3290,
  2499. ideographwatercircle: 0x328C,
  2500. ideographwoodcircle: 0x328D,
  2501. ideva: 0x0907,
  2502. idieresis: 0x00EF,
  2503. idieresisacute: 0x1E2F,
  2504. idieresiscyrillic: 0x04E5,
  2505. idotbelow: 0x1ECB,
  2506. iebrevecyrillic: 0x04D7,
  2507. iecyrillic: 0x0435,
  2508. ieungacirclekorean: 0x3275,
  2509. ieungaparenkorean: 0x3215,
  2510. ieungcirclekorean: 0x3267,
  2511. ieungkorean: 0x3147,
  2512. ieungparenkorean: 0x3207,
  2513. igrave: 0x00EC,
  2514. igujarati: 0x0A87,
  2515. igurmukhi: 0x0A07,
  2516. ihiragana: 0x3044,
  2517. ihookabove: 0x1EC9,
  2518. iibengali: 0x0988,
  2519. iicyrillic: 0x0438,
  2520. iideva: 0x0908,
  2521. iigujarati: 0x0A88,
  2522. iigurmukhi: 0x0A08,
  2523. iimatragurmukhi: 0x0A40,
  2524. iinvertedbreve: 0x020B,
  2525. iishortcyrillic: 0x0439,
  2526. iivowelsignbengali: 0x09C0,
  2527. iivowelsigndeva: 0x0940,
  2528. iivowelsigngujarati: 0x0AC0,
  2529. ij: 0x0133,
  2530. ikatakana: 0x30A4,
  2531. ikatakanahalfwidth: 0xFF72,
  2532. ikorean: 0x3163,
  2533. ilde: 0x02DC,
  2534. iluyhebrew: 0x05AC,
  2535. imacron: 0x012B,
  2536. imacroncyrillic: 0x04E3,
  2537. imageorapproximatelyequal: 0x2253,
  2538. imatragurmukhi: 0x0A3F,
  2539. imonospace: 0xFF49,
  2540. increment: 0x2206,
  2541. infinity: 0x221E,
  2542. iniarmenian: 0x056B,
  2543. integral: 0x222B,
  2544. integralbottom: 0x2321,
  2545. integralbt: 0x2321,
  2546. integralex: 0xF8F5,
  2547. integraltop: 0x2320,
  2548. integraltp: 0x2320,
  2549. intersection: 0x2229,
  2550. intisquare: 0x3305,
  2551. invbullet: 0x25D8,
  2552. invcircle: 0x25D9,
  2553. invsmileface: 0x263B,
  2554. iocyrillic: 0x0451,
  2555. iogonek: 0x012F,
  2556. iota: 0x03B9,
  2557. iotadieresis: 0x03CA,
  2558. iotadieresistonos: 0x0390,
  2559. iotalatin: 0x0269,
  2560. iotatonos: 0x03AF,
  2561. iparen: 0x24A4,
  2562. irigurmukhi: 0x0A72,
  2563. ismallhiragana: 0x3043,
  2564. ismallkatakana: 0x30A3,
  2565. ismallkatakanahalfwidth: 0xFF68,
  2566. issharbengali: 0x09FA,
  2567. istroke: 0x0268,
  2568. isuperior: 0xF6ED,
  2569. iterationhiragana: 0x309D,
  2570. iterationkatakana: 0x30FD,
  2571. itilde: 0x0129,
  2572. itildebelow: 0x1E2D,
  2573. iubopomofo: 0x3129,
  2574. iucyrillic: 0x044E,
  2575. ivowelsignbengali: 0x09BF,
  2576. ivowelsigndeva: 0x093F,
  2577. ivowelsigngujarati: 0x0ABF,
  2578. izhitsacyrillic: 0x0475,
  2579. izhitsadblgravecyrillic: 0x0477,
  2580. j: 0x006A,
  2581. jaarmenian: 0x0571,
  2582. jabengali: 0x099C,
  2583. jadeva: 0x091C,
  2584. jagujarati: 0x0A9C,
  2585. jagurmukhi: 0x0A1C,
  2586. jbopomofo: 0x3110,
  2587. jcaron: 0x01F0,
  2588. jcircle: 0x24D9,
  2589. jcircumflex: 0x0135,
  2590. jcrossedtail: 0x029D,
  2591. jdotlessstroke: 0x025F,
  2592. jecyrillic: 0x0458,
  2593. jeemarabic: 0x062C,
  2594. jeemfinalarabic: 0xFE9E,
  2595. jeeminitialarabic: 0xFE9F,
  2596. jeemmedialarabic: 0xFEA0,
  2597. jeharabic: 0x0698,
  2598. jehfinalarabic: 0xFB8B,
  2599. jhabengali: 0x099D,
  2600. jhadeva: 0x091D,
  2601. jhagujarati: 0x0A9D,
  2602. jhagurmukhi: 0x0A1D,
  2603. jheharmenian: 0x057B,
  2604. jis: 0x3004,
  2605. jmonospace: 0xFF4A,
  2606. jparen: 0x24A5,
  2607. jsuperior: 0x02B2,
  2608. k: 0x006B,
  2609. kabashkircyrillic: 0x04A1,
  2610. kabengali: 0x0995,
  2611. kacute: 0x1E31,
  2612. kacyrillic: 0x043A,
  2613. kadescendercyrillic: 0x049B,
  2614. kadeva: 0x0915,
  2615. kaf: 0x05DB,
  2616. kafarabic: 0x0643,
  2617. kafdagesh: 0xFB3B,
  2618. kafdageshhebrew: 0xFB3B,
  2619. kaffinalarabic: 0xFEDA,
  2620. kafhebrew: 0x05DB,
  2621. kafinitialarabic: 0xFEDB,
  2622. kafmedialarabic: 0xFEDC,
  2623. kafrafehebrew: 0xFB4D,
  2624. kagujarati: 0x0A95,
  2625. kagurmukhi: 0x0A15,
  2626. kahiragana: 0x304B,
  2627. kahookcyrillic: 0x04C4,
  2628. kakatakana: 0x30AB,
  2629. kakatakanahalfwidth: 0xFF76,
  2630. kappa: 0x03BA,
  2631. kappasymbolgreek: 0x03F0,
  2632. kapyeounmieumkorean: 0x3171,
  2633. kapyeounphieuphkorean: 0x3184,
  2634. kapyeounpieupkorean: 0x3178,
  2635. kapyeounssangpieupkorean: 0x3179,
  2636. karoriisquare: 0x330D,
  2637. kashidaautoarabic: 0x0640,
  2638. kashidaautonosidebearingarabic: 0x0640,
  2639. kasmallkatakana: 0x30F5,
  2640. kasquare: 0x3384,
  2641. kasraarabic: 0x0650,
  2642. kasratanarabic: 0x064D,
  2643. kastrokecyrillic: 0x049F,
  2644. katahiraprolongmarkhalfwidth: 0xFF70,
  2645. kaverticalstrokecyrillic: 0x049D,
  2646. kbopomofo: 0x310E,
  2647. kcalsquare: 0x3389,
  2648. kcaron: 0x01E9,
  2649. kcedilla: 0x0137,
  2650. kcircle: 0x24DA,
  2651. kcommaaccent: 0x0137,
  2652. kdotbelow: 0x1E33,
  2653. keharmenian: 0x0584,
  2654. kehiragana: 0x3051,
  2655. kekatakana: 0x30B1,
  2656. kekatakanahalfwidth: 0xFF79,
  2657. kenarmenian: 0x056F,
  2658. kesmallkatakana: 0x30F6,
  2659. kgreenlandic: 0x0138,
  2660. khabengali: 0x0996,
  2661. khacyrillic: 0x0445,
  2662. khadeva: 0x0916,
  2663. khagujarati: 0x0A96,
  2664. khagurmukhi: 0x0A16,
  2665. khaharabic: 0x062E,
  2666. khahfinalarabic: 0xFEA6,
  2667. khahinitialarabic: 0xFEA7,
  2668. khahmedialarabic: 0xFEA8,
  2669. kheicoptic: 0x03E7,
  2670. khhadeva: 0x0959,
  2671. khhagurmukhi: 0x0A59,
  2672. khieukhacirclekorean: 0x3278,
  2673. khieukhaparenkorean: 0x3218,
  2674. khieukhcirclekorean: 0x326A,
  2675. khieukhkorean: 0x314B,
  2676. khieukhparenkorean: 0x320A,
  2677. khokhaithai: 0x0E02,
  2678. khokhonthai: 0x0E05,
  2679. khokhuatthai: 0x0E03,
  2680. khokhwaithai: 0x0E04,
  2681. khomutthai: 0x0E5B,
  2682. khook: 0x0199,
  2683. khorakhangthai: 0x0E06,
  2684. khzsquare: 0x3391,
  2685. kihiragana: 0x304D,
  2686. kikatakana: 0x30AD,
  2687. kikatakanahalfwidth: 0xFF77,
  2688. kiroguramusquare: 0x3315,
  2689. kiromeetorusquare: 0x3316,
  2690. kirosquare: 0x3314,
  2691. kiyeokacirclekorean: 0x326E,
  2692. kiyeokaparenkorean: 0x320E,
  2693. kiyeokcirclekorean: 0x3260,
  2694. kiyeokkorean: 0x3131,
  2695. kiyeokparenkorean: 0x3200,
  2696. kiyeoksioskorean: 0x3133,
  2697. kjecyrillic: 0x045C,
  2698. klinebelow: 0x1E35,
  2699. klsquare: 0x3398,
  2700. kmcubedsquare: 0x33A6,
  2701. kmonospace: 0xFF4B,
  2702. kmsquaredsquare: 0x33A2,
  2703. kohiragana: 0x3053,
  2704. kohmsquare: 0x33C0,
  2705. kokaithai: 0x0E01,
  2706. kokatakana: 0x30B3,
  2707. kokatakanahalfwidth: 0xFF7A,
  2708. kooposquare: 0x331E,
  2709. koppacyrillic: 0x0481,
  2710. koreanstandardsymbol: 0x327F,
  2711. koroniscmb: 0x0343,
  2712. kparen: 0x24A6,
  2713. kpasquare: 0x33AA,
  2714. ksicyrillic: 0x046F,
  2715. ktsquare: 0x33CF,
  2716. kturned: 0x029E,
  2717. kuhiragana: 0x304F,
  2718. kukatakana: 0x30AF,
  2719. kukatakanahalfwidth: 0xFF78,
  2720. kvsquare: 0x33B8,
  2721. kwsquare: 0x33BE,
  2722. l: 0x006C,
  2723. labengali: 0x09B2,
  2724. lacute: 0x013A,
  2725. ladeva: 0x0932,
  2726. lagujarati: 0x0AB2,
  2727. lagurmukhi: 0x0A32,
  2728. lakkhangyaothai: 0x0E45,
  2729. lamaleffinalarabic: 0xFEFC,
  2730. lamalefhamzaabovefinalarabic: 0xFEF8,
  2731. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  2732. lamalefhamzabelowfinalarabic: 0xFEFA,
  2733. lamalefhamzabelowisolatedarabic: 0xFEF9,
  2734. lamalefisolatedarabic: 0xFEFB,
  2735. lamalefmaddaabovefinalarabic: 0xFEF6,
  2736. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  2737. lamarabic: 0x0644,
  2738. lambda: 0x03BB,
  2739. lambdastroke: 0x019B,
  2740. lamed: 0x05DC,
  2741. lameddagesh: 0xFB3C,
  2742. lameddageshhebrew: 0xFB3C,
  2743. lamedhebrew: 0x05DC,
  2744. lamfinalarabic: 0xFEDE,
  2745. lamhahinitialarabic: 0xFCCA,
  2746. laminitialarabic: 0xFEDF,
  2747. lamjeeminitialarabic: 0xFCC9,
  2748. lamkhahinitialarabic: 0xFCCB,
  2749. lamlamhehisolatedarabic: 0xFDF2,
  2750. lammedialarabic: 0xFEE0,
  2751. lammeemhahinitialarabic: 0xFD88,
  2752. lammeeminitialarabic: 0xFCCC,
  2753. largecircle: 0x25EF,
  2754. lbar: 0x019A,
  2755. lbelt: 0x026C,
  2756. lbopomofo: 0x310C,
  2757. lcaron: 0x013E,
  2758. lcedilla: 0x013C,
  2759. lcircle: 0x24DB,
  2760. lcircumflexbelow: 0x1E3D,
  2761. lcommaaccent: 0x013C,
  2762. ldot: 0x0140,
  2763. ldotaccent: 0x0140,
  2764. ldotbelow: 0x1E37,
  2765. ldotbelowmacron: 0x1E39,
  2766. leftangleabovecmb: 0x031A,
  2767. lefttackbelowcmb: 0x0318,
  2768. less: 0x003C,
  2769. lessequal: 0x2264,
  2770. lessequalorgreater: 0x22DA,
  2771. lessmonospace: 0xFF1C,
  2772. lessorequivalent: 0x2272,
  2773. lessorgreater: 0x2276,
  2774. lessoverequal: 0x2266,
  2775. lesssmall: 0xFE64,
  2776. lezh: 0x026E,
  2777. lfblock: 0x258C,
  2778. lhookretroflex: 0x026D,
  2779. lira: 0x20A4,
  2780. liwnarmenian: 0x056C,
  2781. lj: 0x01C9,
  2782. ljecyrillic: 0x0459,
  2783. ll: 0xF6C0,
  2784. lladeva: 0x0933,
  2785. llagujarati: 0x0AB3,
  2786. llinebelow: 0x1E3B,
  2787. llladeva: 0x0934,
  2788. llvocalicbengali: 0x09E1,
  2789. llvocalicdeva: 0x0961,
  2790. llvocalicvowelsignbengali: 0x09E3,
  2791. llvocalicvowelsigndeva: 0x0963,
  2792. lmiddletilde: 0x026B,
  2793. lmonospace: 0xFF4C,
  2794. lmsquare: 0x33D0,
  2795. lochulathai: 0x0E2C,
  2796. logicaland: 0x2227,
  2797. logicalnot: 0x00AC,
  2798. logicalnotreversed: 0x2310,
  2799. logicalor: 0x2228,
  2800. lolingthai: 0x0E25,
  2801. longs: 0x017F,
  2802. lowlinecenterline: 0xFE4E,
  2803. lowlinecmb: 0x0332,
  2804. lowlinedashed: 0xFE4D,
  2805. lozenge: 0x25CA,
  2806. lparen: 0x24A7,
  2807. lslash: 0x0142,
  2808. lsquare: 0x2113,
  2809. lsuperior: 0xF6EE,
  2810. ltshade: 0x2591,
  2811. luthai: 0x0E26,
  2812. lvocalicbengali: 0x098C,
  2813. lvocalicdeva: 0x090C,
  2814. lvocalicvowelsignbengali: 0x09E2,
  2815. lvocalicvowelsigndeva: 0x0962,
  2816. lxsquare: 0x33D3,
  2817. m: 0x006D,
  2818. mabengali: 0x09AE,
  2819. macron: 0x00AF,
  2820. macronbelowcmb: 0x0331,
  2821. macroncmb: 0x0304,
  2822. macronlowmod: 0x02CD,
  2823. macronmonospace: 0xFFE3,
  2824. macute: 0x1E3F,
  2825. madeva: 0x092E,
  2826. magujarati: 0x0AAE,
  2827. magurmukhi: 0x0A2E,
  2828. mahapakhhebrew: 0x05A4,
  2829. mahapakhlefthebrew: 0x05A4,
  2830. mahiragana: 0x307E,
  2831. maichattawalowleftthai: 0xF895,
  2832. maichattawalowrightthai: 0xF894,
  2833. maichattawathai: 0x0E4B,
  2834. maichattawaupperleftthai: 0xF893,
  2835. maieklowleftthai: 0xF88C,
  2836. maieklowrightthai: 0xF88B,
  2837. maiekthai: 0x0E48,
  2838. maiekupperleftthai: 0xF88A,
  2839. maihanakatleftthai: 0xF884,
  2840. maihanakatthai: 0x0E31,
  2841. maitaikhuleftthai: 0xF889,
  2842. maitaikhuthai: 0x0E47,
  2843. maitholowleftthai: 0xF88F,
  2844. maitholowrightthai: 0xF88E,
  2845. maithothai: 0x0E49,
  2846. maithoupperleftthai: 0xF88D,
  2847. maitrilowleftthai: 0xF892,
  2848. maitrilowrightthai: 0xF891,
  2849. maitrithai: 0x0E4A,
  2850. maitriupperleftthai: 0xF890,
  2851. maiyamokthai: 0x0E46,
  2852. makatakana: 0x30DE,
  2853. makatakanahalfwidth: 0xFF8F,
  2854. male: 0x2642,
  2855. mansyonsquare: 0x3347,
  2856. maqafhebrew: 0x05BE,
  2857. mars: 0x2642,
  2858. masoracirclehebrew: 0x05AF,
  2859. masquare: 0x3383,
  2860. mbopomofo: 0x3107,
  2861. mbsquare: 0x33D4,
  2862. mcircle: 0x24DC,
  2863. mcubedsquare: 0x33A5,
  2864. mdotaccent: 0x1E41,
  2865. mdotbelow: 0x1E43,
  2866. meemarabic: 0x0645,
  2867. meemfinalarabic: 0xFEE2,
  2868. meeminitialarabic: 0xFEE3,
  2869. meemmedialarabic: 0xFEE4,
  2870. meemmeeminitialarabic: 0xFCD1,
  2871. meemmeemisolatedarabic: 0xFC48,
  2872. meetorusquare: 0x334D,
  2873. mehiragana: 0x3081,
  2874. meizierasquare: 0x337E,
  2875. mekatakana: 0x30E1,
  2876. mekatakanahalfwidth: 0xFF92,
  2877. mem: 0x05DE,
  2878. memdagesh: 0xFB3E,
  2879. memdageshhebrew: 0xFB3E,
  2880. memhebrew: 0x05DE,
  2881. menarmenian: 0x0574,
  2882. merkhahebrew: 0x05A5,
  2883. merkhakefulahebrew: 0x05A6,
  2884. merkhakefulalefthebrew: 0x05A6,
  2885. merkhalefthebrew: 0x05A5,
  2886. mhook: 0x0271,
  2887. mhzsquare: 0x3392,
  2888. middledotkatakanahalfwidth: 0xFF65,
  2889. middot: 0x00B7,
  2890. mieumacirclekorean: 0x3272,
  2891. mieumaparenkorean: 0x3212,
  2892. mieumcirclekorean: 0x3264,
  2893. mieumkorean: 0x3141,
  2894. mieumpansioskorean: 0x3170,
  2895. mieumparenkorean: 0x3204,
  2896. mieumpieupkorean: 0x316E,
  2897. mieumsioskorean: 0x316F,
  2898. mihiragana: 0x307F,
  2899. mikatakana: 0x30DF,
  2900. mikatakanahalfwidth: 0xFF90,
  2901. minus: 0x2212,
  2902. minusbelowcmb: 0x0320,
  2903. minuscircle: 0x2296,
  2904. minusmod: 0x02D7,
  2905. minusplus: 0x2213,
  2906. minute: 0x2032,
  2907. miribaarusquare: 0x334A,
  2908. mirisquare: 0x3349,
  2909. mlonglegturned: 0x0270,
  2910. mlsquare: 0x3396,
  2911. mmcubedsquare: 0x33A3,
  2912. mmonospace: 0xFF4D,
  2913. mmsquaredsquare: 0x339F,
  2914. mohiragana: 0x3082,
  2915. mohmsquare: 0x33C1,
  2916. mokatakana: 0x30E2,
  2917. mokatakanahalfwidth: 0xFF93,
  2918. molsquare: 0x33D6,
  2919. momathai: 0x0E21,
  2920. moverssquare: 0x33A7,
  2921. moverssquaredsquare: 0x33A8,
  2922. mparen: 0x24A8,
  2923. mpasquare: 0x33AB,
  2924. mssquare: 0x33B3,
  2925. msuperior: 0xF6EF,
  2926. mturned: 0x026F,
  2927. mu: 0x00B5,
  2928. mu1: 0x00B5,
  2929. muasquare: 0x3382,
  2930. muchgreater: 0x226B,
  2931. muchless: 0x226A,
  2932. mufsquare: 0x338C,
  2933. mugreek: 0x03BC,
  2934. mugsquare: 0x338D,
  2935. muhiragana: 0x3080,
  2936. mukatakana: 0x30E0,
  2937. mukatakanahalfwidth: 0xFF91,
  2938. mulsquare: 0x3395,
  2939. multiply: 0x00D7,
  2940. mumsquare: 0x339B,
  2941. munahhebrew: 0x05A3,
  2942. munahlefthebrew: 0x05A3,
  2943. musicalnote: 0x266A,
  2944. musicalnotedbl: 0x266B,
  2945. musicflatsign: 0x266D,
  2946. musicsharpsign: 0x266F,
  2947. mussquare: 0x33B2,
  2948. muvsquare: 0x33B6,
  2949. muwsquare: 0x33BC,
  2950. mvmegasquare: 0x33B9,
  2951. mvsquare: 0x33B7,
  2952. mwmegasquare: 0x33BF,
  2953. mwsquare: 0x33BD,
  2954. n: 0x006E,
  2955. nabengali: 0x09A8,
  2956. nabla: 0x2207,
  2957. nacute: 0x0144,
  2958. nadeva: 0x0928,
  2959. nagujarati: 0x0AA8,
  2960. nagurmukhi: 0x0A28,
  2961. nahiragana: 0x306A,
  2962. nakatakana: 0x30CA,
  2963. nakatakanahalfwidth: 0xFF85,
  2964. napostrophe: 0x0149,
  2965. nasquare: 0x3381,
  2966. nbopomofo: 0x310B,
  2967. nbspace: 0x00A0,
  2968. ncaron: 0x0148,
  2969. ncedilla: 0x0146,
  2970. ncircle: 0x24DD,
  2971. ncircumflexbelow: 0x1E4B,
  2972. ncommaaccent: 0x0146,
  2973. ndotaccent: 0x1E45,
  2974. ndotbelow: 0x1E47,
  2975. nehiragana: 0x306D,
  2976. nekatakana: 0x30CD,
  2977. nekatakanahalfwidth: 0xFF88,
  2978. newsheqelsign: 0x20AA,
  2979. nfsquare: 0x338B,
  2980. ngabengali: 0x0999,
  2981. ngadeva: 0x0919,
  2982. ngagujarati: 0x0A99,
  2983. ngagurmukhi: 0x0A19,
  2984. ngonguthai: 0x0E07,
  2985. nhiragana: 0x3093,
  2986. nhookleft: 0x0272,
  2987. nhookretroflex: 0x0273,
  2988. nieunacirclekorean: 0x326F,
  2989. nieunaparenkorean: 0x320F,
  2990. nieuncieuckorean: 0x3135,
  2991. nieuncirclekorean: 0x3261,
  2992. nieunhieuhkorean: 0x3136,
  2993. nieunkorean: 0x3134,
  2994. nieunpansioskorean: 0x3168,
  2995. nieunparenkorean: 0x3201,
  2996. nieunsioskorean: 0x3167,
  2997. nieuntikeutkorean: 0x3166,
  2998. nihiragana: 0x306B,
  2999. nikatakana: 0x30CB,
  3000. nikatakanahalfwidth: 0xFF86,
  3001. nikhahitleftthai: 0xF899,
  3002. nikhahitthai: 0x0E4D,
  3003. nine: 0x0039,
  3004. ninearabic: 0x0669,
  3005. ninebengali: 0x09EF,
  3006. ninecircle: 0x2468,
  3007. ninecircleinversesansserif: 0x2792,
  3008. ninedeva: 0x096F,
  3009. ninegujarati: 0x0AEF,
  3010. ninegurmukhi: 0x0A6F,
  3011. ninehackarabic: 0x0669,
  3012. ninehangzhou: 0x3029,
  3013. nineideographicparen: 0x3228,
  3014. nineinferior: 0x2089,
  3015. ninemonospace: 0xFF19,
  3016. nineoldstyle: 0xF739,
  3017. nineparen: 0x247C,
  3018. nineperiod: 0x2490,
  3019. ninepersian: 0x06F9,
  3020. nineroman: 0x2178,
  3021. ninesuperior: 0x2079,
  3022. nineteencircle: 0x2472,
  3023. nineteenparen: 0x2486,
  3024. nineteenperiod: 0x249A,
  3025. ninethai: 0x0E59,
  3026. nj: 0x01CC,
  3027. njecyrillic: 0x045A,
  3028. nkatakana: 0x30F3,
  3029. nkatakanahalfwidth: 0xFF9D,
  3030. nlegrightlong: 0x019E,
  3031. nlinebelow: 0x1E49,
  3032. nmonospace: 0xFF4E,
  3033. nmsquare: 0x339A,
  3034. nnabengali: 0x09A3,
  3035. nnadeva: 0x0923,
  3036. nnagujarati: 0x0AA3,
  3037. nnagurmukhi: 0x0A23,
  3038. nnnadeva: 0x0929,
  3039. nohiragana: 0x306E,
  3040. nokatakana: 0x30CE,
  3041. nokatakanahalfwidth: 0xFF89,
  3042. nonbreakingspace: 0x00A0,
  3043. nonenthai: 0x0E13,
  3044. nonuthai: 0x0E19,
  3045. noonarabic: 0x0646,
  3046. noonfinalarabic: 0xFEE6,
  3047. noonghunnaarabic: 0x06BA,
  3048. noonghunnafinalarabic: 0xFB9F,
  3049. nooninitialarabic: 0xFEE7,
  3050. noonjeeminitialarabic: 0xFCD2,
  3051. noonjeemisolatedarabic: 0xFC4B,
  3052. noonmedialarabic: 0xFEE8,
  3053. noonmeeminitialarabic: 0xFCD5,
  3054. noonmeemisolatedarabic: 0xFC4E,
  3055. noonnoonfinalarabic: 0xFC8D,
  3056. notcontains: 0x220C,
  3057. notelement: 0x2209,
  3058. notelementof: 0x2209,
  3059. notequal: 0x2260,
  3060. notgreater: 0x226F,
  3061. notgreaternorequal: 0x2271,
  3062. notgreaternorless: 0x2279,
  3063. notidentical: 0x2262,
  3064. notless: 0x226E,
  3065. notlessnorequal: 0x2270,
  3066. notparallel: 0x2226,
  3067. notprecedes: 0x2280,
  3068. notsubset: 0x2284,
  3069. notsucceeds: 0x2281,
  3070. notsuperset: 0x2285,
  3071. nowarmenian: 0x0576,
  3072. nparen: 0x24A9,
  3073. nssquare: 0x33B1,
  3074. nsuperior: 0x207F,
  3075. ntilde: 0x00F1,
  3076. nu: 0x03BD,
  3077. nuhiragana: 0x306C,
  3078. nukatakana: 0x30CC,
  3079. nukatakanahalfwidth: 0xFF87,
  3080. nuktabengali: 0x09BC,
  3081. nuktadeva: 0x093C,
  3082. nuktagujarati: 0x0ABC,
  3083. nuktagurmukhi: 0x0A3C,
  3084. numbersign: 0x0023,
  3085. numbersignmonospace: 0xFF03,
  3086. numbersignsmall: 0xFE5F,
  3087. numeralsigngreek: 0x0374,
  3088. numeralsignlowergreek: 0x0375,
  3089. numero: 0x2116,
  3090. nun: 0x05E0,
  3091. nundagesh: 0xFB40,
  3092. nundageshhebrew: 0xFB40,
  3093. nunhebrew: 0x05E0,
  3094. nvsquare: 0x33B5,
  3095. nwsquare: 0x33BB,
  3096. nyabengali: 0x099E,
  3097. nyadeva: 0x091E,
  3098. nyagujarati: 0x0A9E,
  3099. nyagurmukhi: 0x0A1E,
  3100. o: 0x006F,
  3101. oacute: 0x00F3,
  3102. oangthai: 0x0E2D,
  3103. obarred: 0x0275,
  3104. obarredcyrillic: 0x04E9,
  3105. obarreddieresiscyrillic: 0x04EB,
  3106. obengali: 0x0993,
  3107. obopomofo: 0x311B,
  3108. obreve: 0x014F,
  3109. ocandradeva: 0x0911,
  3110. ocandragujarati: 0x0A91,
  3111. ocandravowelsigndeva: 0x0949,
  3112. ocandravowelsigngujarati: 0x0AC9,
  3113. ocaron: 0x01D2,
  3114. ocircle: 0x24DE,
  3115. ocircumflex: 0x00F4,
  3116. ocircumflexacute: 0x1ED1,
  3117. ocircumflexdotbelow: 0x1ED9,
  3118. ocircumflexgrave: 0x1ED3,
  3119. ocircumflexhookabove: 0x1ED5,
  3120. ocircumflextilde: 0x1ED7,
  3121. ocyrillic: 0x043E,
  3122. odblacute: 0x0151,
  3123. odblgrave: 0x020D,
  3124. odeva: 0x0913,
  3125. odieresis: 0x00F6,
  3126. odieresiscyrillic: 0x04E7,
  3127. odotbelow: 0x1ECD,
  3128. oe: 0x0153,
  3129. oekorean: 0x315A,
  3130. ogonek: 0x02DB,
  3131. ogonekcmb: 0x0328,
  3132. ograve: 0x00F2,
  3133. ogujarati: 0x0A93,
  3134. oharmenian: 0x0585,
  3135. ohiragana: 0x304A,
  3136. ohookabove: 0x1ECF,
  3137. ohorn: 0x01A1,
  3138. ohornacute: 0x1EDB,
  3139. ohorndotbelow: 0x1EE3,
  3140. ohorngrave: 0x1EDD,
  3141. ohornhookabove: 0x1EDF,
  3142. ohorntilde: 0x1EE1,
  3143. ohungarumlaut: 0x0151,
  3144. oi: 0x01A3,
  3145. oinvertedbreve: 0x020F,
  3146. okatakana: 0x30AA,
  3147. okatakanahalfwidth: 0xFF75,
  3148. okorean: 0x3157,
  3149. olehebrew: 0x05AB,
  3150. omacron: 0x014D,
  3151. omacronacute: 0x1E53,
  3152. omacrongrave: 0x1E51,
  3153. omdeva: 0x0950,
  3154. omega: 0x03C9,
  3155. omega1: 0x03D6,
  3156. omegacyrillic: 0x0461,
  3157. omegalatinclosed: 0x0277,
  3158. omegaroundcyrillic: 0x047B,
  3159. omegatitlocyrillic: 0x047D,
  3160. omegatonos: 0x03CE,
  3161. omgujarati: 0x0AD0,
  3162. omicron: 0x03BF,
  3163. omicrontonos: 0x03CC,
  3164. omonospace: 0xFF4F,
  3165. one: 0x0031,
  3166. onearabic: 0x0661,
  3167. onebengali: 0x09E7,
  3168. onecircle: 0x2460,
  3169. onecircleinversesansserif: 0x278A,
  3170. onedeva: 0x0967,
  3171. onedotenleader: 0x2024,
  3172. oneeighth: 0x215B,
  3173. onefitted: 0xF6DC,
  3174. onegujarati: 0x0AE7,
  3175. onegurmukhi: 0x0A67,
  3176. onehackarabic: 0x0661,
  3177. onehalf: 0x00BD,
  3178. onehangzhou: 0x3021,
  3179. oneideographicparen: 0x3220,
  3180. oneinferior: 0x2081,
  3181. onemonospace: 0xFF11,
  3182. onenumeratorbengali: 0x09F4,
  3183. oneoldstyle: 0xF731,
  3184. oneparen: 0x2474,
  3185. oneperiod: 0x2488,
  3186. onepersian: 0x06F1,
  3187. onequarter: 0x00BC,
  3188. oneroman: 0x2170,
  3189. onesuperior: 0x00B9,
  3190. onethai: 0x0E51,
  3191. onethird: 0x2153,
  3192. oogonek: 0x01EB,
  3193. oogonekmacron: 0x01ED,
  3194. oogurmukhi: 0x0A13,
  3195. oomatragurmukhi: 0x0A4B,
  3196. oopen: 0x0254,
  3197. oparen: 0x24AA,
  3198. openbullet: 0x25E6,
  3199. option: 0x2325,
  3200. ordfeminine: 0x00AA,
  3201. ordmasculine: 0x00BA,
  3202. orthogonal: 0x221F,
  3203. oshortdeva: 0x0912,
  3204. oshortvowelsigndeva: 0x094A,
  3205. oslash: 0x00F8,
  3206. oslashacute: 0x01FF,
  3207. osmallhiragana: 0x3049,
  3208. osmallkatakana: 0x30A9,
  3209. osmallkatakanahalfwidth: 0xFF6B,
  3210. ostrokeacute: 0x01FF,
  3211. osuperior: 0xF6F0,
  3212. otcyrillic: 0x047F,
  3213. otilde: 0x00F5,
  3214. otildeacute: 0x1E4D,
  3215. otildedieresis: 0x1E4F,
  3216. oubopomofo: 0x3121,
  3217. overline: 0x203E,
  3218. overlinecenterline: 0xFE4A,
  3219. overlinecmb: 0x0305,
  3220. overlinedashed: 0xFE49,
  3221. overlinedblwavy: 0xFE4C,
  3222. overlinewavy: 0xFE4B,
  3223. overscore: 0x00AF,
  3224. ovowelsignbengali: 0x09CB,
  3225. ovowelsigndeva: 0x094B,
  3226. ovowelsigngujarati: 0x0ACB,
  3227. p: 0x0070,
  3228. paampssquare: 0x3380,
  3229. paasentosquare: 0x332B,
  3230. pabengali: 0x09AA,
  3231. pacute: 0x1E55,
  3232. padeva: 0x092A,
  3233. pagedown: 0x21DF,
  3234. pageup: 0x21DE,
  3235. pagujarati: 0x0AAA,
  3236. pagurmukhi: 0x0A2A,
  3237. pahiragana: 0x3071,
  3238. paiyannoithai: 0x0E2F,
  3239. pakatakana: 0x30D1,
  3240. palatalizationcyrilliccmb: 0x0484,
  3241. palochkacyrillic: 0x04C0,
  3242. pansioskorean: 0x317F,
  3243. paragraph: 0x00B6,
  3244. parallel: 0x2225,
  3245. parenleft: 0x0028,
  3246. parenleftaltonearabic: 0xFD3E,
  3247. parenleftbt: 0xF8ED,
  3248. parenleftex: 0xF8EC,
  3249. parenleftinferior: 0x208D,
  3250. parenleftmonospace: 0xFF08,
  3251. parenleftsmall: 0xFE59,
  3252. parenleftsuperior: 0x207D,
  3253. parenlefttp: 0xF8EB,
  3254. parenleftvertical: 0xFE35,
  3255. parenright: 0x0029,
  3256. parenrightaltonearabic: 0xFD3F,
  3257. parenrightbt: 0xF8F8,
  3258. parenrightex: 0xF8F7,
  3259. parenrightinferior: 0x208E,
  3260. parenrightmonospace: 0xFF09,
  3261. parenrightsmall: 0xFE5A,
  3262. parenrightsuperior: 0x207E,
  3263. parenrighttp: 0xF8F6,
  3264. parenrightvertical: 0xFE36,
  3265. partialdiff: 0x2202,
  3266. paseqhebrew: 0x05C0,
  3267. pashtahebrew: 0x0599,
  3268. pasquare: 0x33A9,
  3269. patah: 0x05B7,
  3270. patah11: 0x05B7,
  3271. patah1d: 0x05B7,
  3272. patah2a: 0x05B7,
  3273. patahhebrew: 0x05B7,
  3274. patahnarrowhebrew: 0x05B7,
  3275. patahquarterhebrew: 0x05B7,
  3276. patahwidehebrew: 0x05B7,
  3277. pazerhebrew: 0x05A1,
  3278. pbopomofo: 0x3106,
  3279. pcircle: 0x24DF,
  3280. pdotaccent: 0x1E57,
  3281. pe: 0x05E4,
  3282. pecyrillic: 0x043F,
  3283. pedagesh: 0xFB44,
  3284. pedageshhebrew: 0xFB44,
  3285. peezisquare: 0x333B,
  3286. pefinaldageshhebrew: 0xFB43,
  3287. peharabic: 0x067E,
  3288. peharmenian: 0x057A,
  3289. pehebrew: 0x05E4,
  3290. pehfinalarabic: 0xFB57,
  3291. pehinitialarabic: 0xFB58,
  3292. pehiragana: 0x307A,
  3293. pehmedialarabic: 0xFB59,
  3294. pekatakana: 0x30DA,
  3295. pemiddlehookcyrillic: 0x04A7,
  3296. perafehebrew: 0xFB4E,
  3297. percent: 0x0025,
  3298. percentarabic: 0x066A,
  3299. percentmonospace: 0xFF05,
  3300. percentsmall: 0xFE6A,
  3301. period: 0x002E,
  3302. periodarmenian: 0x0589,
  3303. periodcentered: 0x00B7,
  3304. periodhalfwidth: 0xFF61,
  3305. periodinferior: 0xF6E7,
  3306. periodmonospace: 0xFF0E,
  3307. periodsmall: 0xFE52,
  3308. periodsuperior: 0xF6E8,
  3309. perispomenigreekcmb: 0x0342,
  3310. perpendicular: 0x22A5,
  3311. perthousand: 0x2030,
  3312. peseta: 0x20A7,
  3313. pfsquare: 0x338A,
  3314. phabengali: 0x09AB,
  3315. phadeva: 0x092B,
  3316. phagujarati: 0x0AAB,
  3317. phagurmukhi: 0x0A2B,
  3318. phi: 0x03C6,
  3319. phi1: 0x03D5,
  3320. phieuphacirclekorean: 0x327A,
  3321. phieuphaparenkorean: 0x321A,
  3322. phieuphcirclekorean: 0x326C,
  3323. phieuphkorean: 0x314D,
  3324. phieuphparenkorean: 0x320C,
  3325. philatin: 0x0278,
  3326. phinthuthai: 0x0E3A,
  3327. phisymbolgreek: 0x03D5,
  3328. phook: 0x01A5,
  3329. phophanthai: 0x0E1E,
  3330. phophungthai: 0x0E1C,
  3331. phosamphaothai: 0x0E20,
  3332. pi: 0x03C0,
  3333. pieupacirclekorean: 0x3273,
  3334. pieupaparenkorean: 0x3213,
  3335. pieupcieuckorean: 0x3176,
  3336. pieupcirclekorean: 0x3265,
  3337. pieupkiyeokkorean: 0x3172,
  3338. pieupkorean: 0x3142,
  3339. pieupparenkorean: 0x3205,
  3340. pieupsioskiyeokkorean: 0x3174,
  3341. pieupsioskorean: 0x3144,
  3342. pieupsiostikeutkorean: 0x3175,
  3343. pieupthieuthkorean: 0x3177,
  3344. pieuptikeutkorean: 0x3173,
  3345. pihiragana: 0x3074,
  3346. pikatakana: 0x30D4,
  3347. pisymbolgreek: 0x03D6,
  3348. piwrarmenian: 0x0583,
  3349. plus: 0x002B,
  3350. plusbelowcmb: 0x031F,
  3351. pluscircle: 0x2295,
  3352. plusminus: 0x00B1,
  3353. plusmod: 0x02D6,
  3354. plusmonospace: 0xFF0B,
  3355. plussmall: 0xFE62,
  3356. plussuperior: 0x207A,
  3357. pmonospace: 0xFF50,
  3358. pmsquare: 0x33D8,
  3359. pohiragana: 0x307D,
  3360. pointingindexdownwhite: 0x261F,
  3361. pointingindexleftwhite: 0x261C,
  3362. pointingindexrightwhite: 0x261E,
  3363. pointingindexupwhite: 0x261D,
  3364. pokatakana: 0x30DD,
  3365. poplathai: 0x0E1B,
  3366. postalmark: 0x3012,
  3367. postalmarkface: 0x3020,
  3368. pparen: 0x24AB,
  3369. precedes: 0x227A,
  3370. prescription: 0x211E,
  3371. primemod: 0x02B9,
  3372. primereversed: 0x2035,
  3373. product: 0x220F,
  3374. projective: 0x2305,
  3375. prolongedkana: 0x30FC,
  3376. propellor: 0x2318,
  3377. propersubset: 0x2282,
  3378. propersuperset: 0x2283,
  3379. proportion: 0x2237,
  3380. proportional: 0x221D,
  3381. psi: 0x03C8,
  3382. psicyrillic: 0x0471,
  3383. psilipneumatacyrilliccmb: 0x0486,
  3384. pssquare: 0x33B0,
  3385. puhiragana: 0x3077,
  3386. pukatakana: 0x30D7,
  3387. pvsquare: 0x33B4,
  3388. pwsquare: 0x33BA,
  3389. q: 0x0071,
  3390. qadeva: 0x0958,
  3391. qadmahebrew: 0x05A8,
  3392. qafarabic: 0x0642,
  3393. qaffinalarabic: 0xFED6,
  3394. qafinitialarabic: 0xFED7,
  3395. qafmedialarabic: 0xFED8,
  3396. qamats: 0x05B8,
  3397. qamats10: 0x05B8,
  3398. qamats1a: 0x05B8,
  3399. qamats1c: 0x05B8,
  3400. qamats27: 0x05B8,
  3401. qamats29: 0x05B8,
  3402. qamats33: 0x05B8,
  3403. qamatsde: 0x05B8,
  3404. qamatshebrew: 0x05B8,
  3405. qamatsnarrowhebrew: 0x05B8,
  3406. qamatsqatanhebrew: 0x05B8,
  3407. qamatsqatannarrowhebrew: 0x05B8,
  3408. qamatsqatanquarterhebrew: 0x05B8,
  3409. qamatsqatanwidehebrew: 0x05B8,
  3410. qamatsquarterhebrew: 0x05B8,
  3411. qamatswidehebrew: 0x05B8,
  3412. qarneyparahebrew: 0x059F,
  3413. qbopomofo: 0x3111,
  3414. qcircle: 0x24E0,
  3415. qhook: 0x02A0,
  3416. qmonospace: 0xFF51,
  3417. qof: 0x05E7,
  3418. qofdagesh: 0xFB47,
  3419. qofdageshhebrew: 0xFB47,
  3420. qofhebrew: 0x05E7,
  3421. qparen: 0x24AC,
  3422. quarternote: 0x2669,
  3423. qubuts: 0x05BB,
  3424. qubuts18: 0x05BB,
  3425. qubuts25: 0x05BB,
  3426. qubuts31: 0x05BB,
  3427. qubutshebrew: 0x05BB,
  3428. qubutsnarrowhebrew: 0x05BB,
  3429. qubutsquarterhebrew: 0x05BB,
  3430. qubutswidehebrew: 0x05BB,
  3431. question: 0x003F,
  3432. questionarabic: 0x061F,
  3433. questionarmenian: 0x055E,
  3434. questiondown: 0x00BF,
  3435. questiondownsmall: 0xF7BF,
  3436. questiongreek: 0x037E,
  3437. questionmonospace: 0xFF1F,
  3438. questionsmall: 0xF73F,
  3439. quotedbl: 0x0022,
  3440. quotedblbase: 0x201E,
  3441. quotedblleft: 0x201C,
  3442. quotedblmonospace: 0xFF02,
  3443. quotedblprime: 0x301E,
  3444. quotedblprimereversed: 0x301D,
  3445. quotedblright: 0x201D,
  3446. quoteleft: 0x2018,
  3447. quoteleftreversed: 0x201B,
  3448. quotereversed: 0x201B,
  3449. quoteright: 0x2019,
  3450. quoterightn: 0x0149,
  3451. quotesinglbase: 0x201A,
  3452. quotesingle: 0x0027,
  3453. quotesinglemonospace: 0xFF07,
  3454. r: 0x0072,
  3455. raarmenian: 0x057C,
  3456. rabengali: 0x09B0,
  3457. racute: 0x0155,
  3458. radeva: 0x0930,
  3459. radical: 0x221A,
  3460. radicalex: 0xF8E5,
  3461. radoverssquare: 0x33AE,
  3462. radoverssquaredsquare: 0x33AF,
  3463. radsquare: 0x33AD,
  3464. rafe: 0x05BF,
  3465. rafehebrew: 0x05BF,
  3466. ragujarati: 0x0AB0,
  3467. ragurmukhi: 0x0A30,
  3468. rahiragana: 0x3089,
  3469. rakatakana: 0x30E9,
  3470. rakatakanahalfwidth: 0xFF97,
  3471. ralowerdiagonalbengali: 0x09F1,
  3472. ramiddlediagonalbengali: 0x09F0,
  3473. ramshorn: 0x0264,
  3474. ratio: 0x2236,
  3475. rbopomofo: 0x3116,
  3476. rcaron: 0x0159,
  3477. rcedilla: 0x0157,
  3478. rcircle: 0x24E1,
  3479. rcommaaccent: 0x0157,
  3480. rdblgrave: 0x0211,
  3481. rdotaccent: 0x1E59,
  3482. rdotbelow: 0x1E5B,
  3483. rdotbelowmacron: 0x1E5D,
  3484. referencemark: 0x203B,
  3485. reflexsubset: 0x2286,
  3486. reflexsuperset: 0x2287,
  3487. registered: 0x00AE,
  3488. registersans: 0xF8E8,
  3489. registerserif: 0xF6DA,
  3490. reharabic: 0x0631,
  3491. reharmenian: 0x0580,
  3492. rehfinalarabic: 0xFEAE,
  3493. rehiragana: 0x308C,
  3494. rekatakana: 0x30EC,
  3495. rekatakanahalfwidth: 0xFF9A,
  3496. resh: 0x05E8,
  3497. reshdageshhebrew: 0xFB48,
  3498. reshhebrew: 0x05E8,
  3499. reversedtilde: 0x223D,
  3500. reviahebrew: 0x0597,
  3501. reviamugrashhebrew: 0x0597,
  3502. revlogicalnot: 0x2310,
  3503. rfishhook: 0x027E,
  3504. rfishhookreversed: 0x027F,
  3505. rhabengali: 0x09DD,
  3506. rhadeva: 0x095D,
  3507. rho: 0x03C1,
  3508. rhook: 0x027D,
  3509. rhookturned: 0x027B,
  3510. rhookturnedsuperior: 0x02B5,
  3511. rhosymbolgreek: 0x03F1,
  3512. rhotichookmod: 0x02DE,
  3513. rieulacirclekorean: 0x3271,
  3514. rieulaparenkorean: 0x3211,
  3515. rieulcirclekorean: 0x3263,
  3516. rieulhieuhkorean: 0x3140,
  3517. rieulkiyeokkorean: 0x313A,
  3518. rieulkiyeoksioskorean: 0x3169,
  3519. rieulkorean: 0x3139,
  3520. rieulmieumkorean: 0x313B,
  3521. rieulpansioskorean: 0x316C,
  3522. rieulparenkorean: 0x3203,
  3523. rieulphieuphkorean: 0x313F,
  3524. rieulpieupkorean: 0x313C,
  3525. rieulpieupsioskorean: 0x316B,
  3526. rieulsioskorean: 0x313D,
  3527. rieulthieuthkorean: 0x313E,
  3528. rieultikeutkorean: 0x316A,
  3529. rieulyeorinhieuhkorean: 0x316D,
  3530. rightangle: 0x221F,
  3531. righttackbelowcmb: 0x0319,
  3532. righttriangle: 0x22BF,
  3533. rihiragana: 0x308A,
  3534. rikatakana: 0x30EA,
  3535. rikatakanahalfwidth: 0xFF98,
  3536. ring: 0x02DA,
  3537. ringbelowcmb: 0x0325,
  3538. ringcmb: 0x030A,
  3539. ringhalfleft: 0x02BF,
  3540. ringhalfleftarmenian: 0x0559,
  3541. ringhalfleftbelowcmb: 0x031C,
  3542. ringhalfleftcentered: 0x02D3,
  3543. ringhalfright: 0x02BE,
  3544. ringhalfrightbelowcmb: 0x0339,
  3545. ringhalfrightcentered: 0x02D2,
  3546. rinvertedbreve: 0x0213,
  3547. rittorusquare: 0x3351,
  3548. rlinebelow: 0x1E5F,
  3549. rlongleg: 0x027C,
  3550. rlonglegturned: 0x027A,
  3551. rmonospace: 0xFF52,
  3552. rohiragana: 0x308D,
  3553. rokatakana: 0x30ED,
  3554. rokatakanahalfwidth: 0xFF9B,
  3555. roruathai: 0x0E23,
  3556. rparen: 0x24AD,
  3557. rrabengali: 0x09DC,
  3558. rradeva: 0x0931,
  3559. rragurmukhi: 0x0A5C,
  3560. rreharabic: 0x0691,
  3561. rrehfinalarabic: 0xFB8D,
  3562. rrvocalicbengali: 0x09E0,
  3563. rrvocalicdeva: 0x0960,
  3564. rrvocalicgujarati: 0x0AE0,
  3565. rrvocalicvowelsignbengali: 0x09C4,
  3566. rrvocalicvowelsigndeva: 0x0944,
  3567. rrvocalicvowelsigngujarati: 0x0AC4,
  3568. rsuperior: 0xF6F1,
  3569. rtblock: 0x2590,
  3570. rturned: 0x0279,
  3571. rturnedsuperior: 0x02B4,
  3572. ruhiragana: 0x308B,
  3573. rukatakana: 0x30EB,
  3574. rukatakanahalfwidth: 0xFF99,
  3575. rupeemarkbengali: 0x09F2,
  3576. rupeesignbengali: 0x09F3,
  3577. rupiah: 0xF6DD,
  3578. ruthai: 0x0E24,
  3579. rvocalicbengali: 0x098B,
  3580. rvocalicdeva: 0x090B,
  3581. rvocalicgujarati: 0x0A8B,
  3582. rvocalicvowelsignbengali: 0x09C3,
  3583. rvocalicvowelsigndeva: 0x0943,
  3584. rvocalicvowelsigngujarati: 0x0AC3,
  3585. s: 0x0073,
  3586. sabengali: 0x09B8,
  3587. sacute: 0x015B,
  3588. sacutedotaccent: 0x1E65,
  3589. sadarabic: 0x0635,
  3590. sadeva: 0x0938,
  3591. sadfinalarabic: 0xFEBA,
  3592. sadinitialarabic: 0xFEBB,
  3593. sadmedialarabic: 0xFEBC,
  3594. sagujarati: 0x0AB8,
  3595. sagurmukhi: 0x0A38,
  3596. sahiragana: 0x3055,
  3597. sakatakana: 0x30B5,
  3598. sakatakanahalfwidth: 0xFF7B,
  3599. sallallahoualayhewasallamarabic: 0xFDFA,
  3600. samekh: 0x05E1,
  3601. samekhdagesh: 0xFB41,
  3602. samekhdageshhebrew: 0xFB41,
  3603. samekhhebrew: 0x05E1,
  3604. saraaathai: 0x0E32,
  3605. saraaethai: 0x0E41,
  3606. saraaimaimalaithai: 0x0E44,
  3607. saraaimaimuanthai: 0x0E43,
  3608. saraamthai: 0x0E33,
  3609. saraathai: 0x0E30,
  3610. saraethai: 0x0E40,
  3611. saraiileftthai: 0xF886,
  3612. saraiithai: 0x0E35,
  3613. saraileftthai: 0xF885,
  3614. saraithai: 0x0E34,
  3615. saraothai: 0x0E42,
  3616. saraueeleftthai: 0xF888,
  3617. saraueethai: 0x0E37,
  3618. saraueleftthai: 0xF887,
  3619. sarauethai: 0x0E36,
  3620. sarauthai: 0x0E38,
  3621. sarauuthai: 0x0E39,
  3622. sbopomofo: 0x3119,
  3623. scaron: 0x0161,
  3624. scarondotaccent: 0x1E67,
  3625. scedilla: 0x015F,
  3626. schwa: 0x0259,
  3627. schwacyrillic: 0x04D9,
  3628. schwadieresiscyrillic: 0x04DB,
  3629. schwahook: 0x025A,
  3630. scircle: 0x24E2,
  3631. scircumflex: 0x015D,
  3632. scommaaccent: 0x0219,
  3633. sdotaccent: 0x1E61,
  3634. sdotbelow: 0x1E63,
  3635. sdotbelowdotaccent: 0x1E69,
  3636. seagullbelowcmb: 0x033C,
  3637. second: 0x2033,
  3638. secondtonechinese: 0x02CA,
  3639. section: 0x00A7,
  3640. seenarabic: 0x0633,
  3641. seenfinalarabic: 0xFEB2,
  3642. seeninitialarabic: 0xFEB3,
  3643. seenmedialarabic: 0xFEB4,
  3644. segol: 0x05B6,
  3645. segol13: 0x05B6,
  3646. segol1f: 0x05B6,
  3647. segol2c: 0x05B6,
  3648. segolhebrew: 0x05B6,
  3649. segolnarrowhebrew: 0x05B6,
  3650. segolquarterhebrew: 0x05B6,
  3651. segoltahebrew: 0x0592,
  3652. segolwidehebrew: 0x05B6,
  3653. seharmenian: 0x057D,
  3654. sehiragana: 0x305B,
  3655. sekatakana: 0x30BB,
  3656. sekatakanahalfwidth: 0xFF7E,
  3657. semicolon: 0x003B,
  3658. semicolonarabic: 0x061B,
  3659. semicolonmonospace: 0xFF1B,
  3660. semicolonsmall: 0xFE54,
  3661. semivoicedmarkkana: 0x309C,
  3662. semivoicedmarkkanahalfwidth: 0xFF9F,
  3663. sentisquare: 0x3322,
  3664. sentosquare: 0x3323,
  3665. seven: 0x0037,
  3666. sevenarabic: 0x0667,
  3667. sevenbengali: 0x09ED,
  3668. sevencircle: 0x2466,
  3669. sevencircleinversesansserif: 0x2790,
  3670. sevendeva: 0x096D,
  3671. seveneighths: 0x215E,
  3672. sevengujarati: 0x0AED,
  3673. sevengurmukhi: 0x0A6D,
  3674. sevenhackarabic: 0x0667,
  3675. sevenhangzhou: 0x3027,
  3676. sevenideographicparen: 0x3226,
  3677. seveninferior: 0x2087,
  3678. sevenmonospace: 0xFF17,
  3679. sevenoldstyle: 0xF737,
  3680. sevenparen: 0x247A,
  3681. sevenperiod: 0x248E,
  3682. sevenpersian: 0x06F7,
  3683. sevenroman: 0x2176,
  3684. sevensuperior: 0x2077,
  3685. seventeencircle: 0x2470,
  3686. seventeenparen: 0x2484,
  3687. seventeenperiod: 0x2498,
  3688. seventhai: 0x0E57,
  3689. sfthyphen: 0x00AD,
  3690. shaarmenian: 0x0577,
  3691. shabengali: 0x09B6,
  3692. shacyrillic: 0x0448,
  3693. shaddaarabic: 0x0651,
  3694. shaddadammaarabic: 0xFC61,
  3695. shaddadammatanarabic: 0xFC5E,
  3696. shaddafathaarabic: 0xFC60,
  3697. shaddakasraarabic: 0xFC62,
  3698. shaddakasratanarabic: 0xFC5F,
  3699. shade: 0x2592,
  3700. shadedark: 0x2593,
  3701. shadelight: 0x2591,
  3702. shademedium: 0x2592,
  3703. shadeva: 0x0936,
  3704. shagujarati: 0x0AB6,
  3705. shagurmukhi: 0x0A36,
  3706. shalshelethebrew: 0x0593,
  3707. shbopomofo: 0x3115,
  3708. shchacyrillic: 0x0449,
  3709. sheenarabic: 0x0634,
  3710. sheenfinalarabic: 0xFEB6,
  3711. sheeninitialarabic: 0xFEB7,
  3712. sheenmedialarabic: 0xFEB8,
  3713. sheicoptic: 0x03E3,
  3714. sheqel: 0x20AA,
  3715. sheqelhebrew: 0x20AA,
  3716. sheva: 0x05B0,
  3717. sheva115: 0x05B0,
  3718. sheva15: 0x05B0,
  3719. sheva22: 0x05B0,
  3720. sheva2e: 0x05B0,
  3721. shevahebrew: 0x05B0,
  3722. shevanarrowhebrew: 0x05B0,
  3723. shevaquarterhebrew: 0x05B0,
  3724. shevawidehebrew: 0x05B0,
  3725. shhacyrillic: 0x04BB,
  3726. shimacoptic: 0x03ED,
  3727. shin: 0x05E9,
  3728. shindagesh: 0xFB49,
  3729. shindageshhebrew: 0xFB49,
  3730. shindageshshindot: 0xFB2C,
  3731. shindageshshindothebrew: 0xFB2C,
  3732. shindageshsindot: 0xFB2D,
  3733. shindageshsindothebrew: 0xFB2D,
  3734. shindothebrew: 0x05C1,
  3735. shinhebrew: 0x05E9,
  3736. shinshindot: 0xFB2A,
  3737. shinshindothebrew: 0xFB2A,
  3738. shinsindot: 0xFB2B,
  3739. shinsindothebrew: 0xFB2B,
  3740. shook: 0x0282,
  3741. sigma: 0x03C3,
  3742. sigma1: 0x03C2,
  3743. sigmafinal: 0x03C2,
  3744. sigmalunatesymbolgreek: 0x03F2,
  3745. sihiragana: 0x3057,
  3746. sikatakana: 0x30B7,
  3747. sikatakanahalfwidth: 0xFF7C,
  3748. siluqhebrew: 0x05BD,
  3749. siluqlefthebrew: 0x05BD,
  3750. similar: 0x223C,
  3751. sindothebrew: 0x05C2,
  3752. siosacirclekorean: 0x3274,
  3753. siosaparenkorean: 0x3214,
  3754. sioscieuckorean: 0x317E,
  3755. sioscirclekorean: 0x3266,
  3756. sioskiyeokkorean: 0x317A,
  3757. sioskorean: 0x3145,
  3758. siosnieunkorean: 0x317B,
  3759. siosparenkorean: 0x3206,
  3760. siospieupkorean: 0x317D,
  3761. siostikeutkorean: 0x317C,
  3762. six: 0x0036,
  3763. sixarabic: 0x0666,
  3764. sixbengali: 0x09EC,
  3765. sixcircle: 0x2465,
  3766. sixcircleinversesansserif: 0x278F,
  3767. sixdeva: 0x096C,
  3768. sixgujarati: 0x0AEC,
  3769. sixgurmukhi: 0x0A6C,
  3770. sixhackarabic: 0x0666,
  3771. sixhangzhou: 0x3026,
  3772. sixideographicparen: 0x3225,
  3773. sixinferior: 0x2086,
  3774. sixmonospace: 0xFF16,
  3775. sixoldstyle: 0xF736,
  3776. sixparen: 0x2479,
  3777. sixperiod: 0x248D,
  3778. sixpersian: 0x06F6,
  3779. sixroman: 0x2175,
  3780. sixsuperior: 0x2076,
  3781. sixteencircle: 0x246F,
  3782. sixteencurrencydenominatorbengali: 0x09F9,
  3783. sixteenparen: 0x2483,
  3784. sixteenperiod: 0x2497,
  3785. sixthai: 0x0E56,
  3786. slash: 0x002F,
  3787. slashmonospace: 0xFF0F,
  3788. slong: 0x017F,
  3789. slongdotaccent: 0x1E9B,
  3790. smileface: 0x263A,
  3791. smonospace: 0xFF53,
  3792. sofpasuqhebrew: 0x05C3,
  3793. softhyphen: 0x00AD,
  3794. softsigncyrillic: 0x044C,
  3795. sohiragana: 0x305D,
  3796. sokatakana: 0x30BD,
  3797. sokatakanahalfwidth: 0xFF7F,
  3798. soliduslongoverlaycmb: 0x0338,
  3799. solidusshortoverlaycmb: 0x0337,
  3800. sorusithai: 0x0E29,
  3801. sosalathai: 0x0E28,
  3802. sosothai: 0x0E0B,
  3803. sosuathai: 0x0E2A,
  3804. space: 0x0020,
  3805. spacehackarabic: 0x0020,
  3806. spade: 0x2660,
  3807. spadesuitblack: 0x2660,
  3808. spadesuitwhite: 0x2664,
  3809. sparen: 0x24AE,
  3810. squarebelowcmb: 0x033B,
  3811. squarecc: 0x33C4,
  3812. squarecm: 0x339D,
  3813. squarediagonalcrosshatchfill: 0x25A9,
  3814. squarehorizontalfill: 0x25A4,
  3815. squarekg: 0x338F,
  3816. squarekm: 0x339E,
  3817. squarekmcapital: 0x33CE,
  3818. squareln: 0x33D1,
  3819. squarelog: 0x33D2,
  3820. squaremg: 0x338E,
  3821. squaremil: 0x33D5,
  3822. squaremm: 0x339C,
  3823. squaremsquared: 0x33A1,
  3824. squareorthogonalcrosshatchfill: 0x25A6,
  3825. squareupperlefttolowerrightfill: 0x25A7,
  3826. squareupperrighttolowerleftfill: 0x25A8,
  3827. squareverticalfill: 0x25A5,
  3828. squarewhitewithsmallblack: 0x25A3,
  3829. srsquare: 0x33DB,
  3830. ssabengali: 0x09B7,
  3831. ssadeva: 0x0937,
  3832. ssagujarati: 0x0AB7,
  3833. ssangcieuckorean: 0x3149,
  3834. ssanghieuhkorean: 0x3185,
  3835. ssangieungkorean: 0x3180,
  3836. ssangkiyeokkorean: 0x3132,
  3837. ssangnieunkorean: 0x3165,
  3838. ssangpieupkorean: 0x3143,
  3839. ssangsioskorean: 0x3146,
  3840. ssangtikeutkorean: 0x3138,
  3841. ssuperior: 0xF6F2,
  3842. sterling: 0x00A3,
  3843. sterlingmonospace: 0xFFE1,
  3844. strokelongoverlaycmb: 0x0336,
  3845. strokeshortoverlaycmb: 0x0335,
  3846. subset: 0x2282,
  3847. subsetnotequal: 0x228A,
  3848. subsetorequal: 0x2286,
  3849. succeeds: 0x227B,
  3850. suchthat: 0x220B,
  3851. suhiragana: 0x3059,
  3852. sukatakana: 0x30B9,
  3853. sukatakanahalfwidth: 0xFF7D,
  3854. sukunarabic: 0x0652,
  3855. summation: 0x2211,
  3856. sun: 0x263C,
  3857. superset: 0x2283,
  3858. supersetnotequal: 0x228B,
  3859. supersetorequal: 0x2287,
  3860. svsquare: 0x33DC,
  3861. syouwaerasquare: 0x337C,
  3862. t: 0x0074,
  3863. tabengali: 0x09A4,
  3864. tackdown: 0x22A4,
  3865. tackleft: 0x22A3,
  3866. tadeva: 0x0924,
  3867. tagujarati: 0x0AA4,
  3868. tagurmukhi: 0x0A24,
  3869. taharabic: 0x0637,
  3870. tahfinalarabic: 0xFEC2,
  3871. tahinitialarabic: 0xFEC3,
  3872. tahiragana: 0x305F,
  3873. tahmedialarabic: 0xFEC4,
  3874. taisyouerasquare: 0x337D,
  3875. takatakana: 0x30BF,
  3876. takatakanahalfwidth: 0xFF80,
  3877. tatweelarabic: 0x0640,
  3878. tau: 0x03C4,
  3879. tav: 0x05EA,
  3880. tavdages: 0xFB4A,
  3881. tavdagesh: 0xFB4A,
  3882. tavdageshhebrew: 0xFB4A,
  3883. tavhebrew: 0x05EA,
  3884. tbar: 0x0167,
  3885. tbopomofo: 0x310A,
  3886. tcaron: 0x0165,
  3887. tccurl: 0x02A8,
  3888. tcedilla: 0x0163,
  3889. tcheharabic: 0x0686,
  3890. tchehfinalarabic: 0xFB7B,
  3891. tchehinitialarabic: 0xFB7C,
  3892. tchehmedialarabic: 0xFB7D,
  3893. tcircle: 0x24E3,
  3894. tcircumflexbelow: 0x1E71,
  3895. tcommaaccent: 0x0163,
  3896. tdieresis: 0x1E97,
  3897. tdotaccent: 0x1E6B,
  3898. tdotbelow: 0x1E6D,
  3899. tecyrillic: 0x0442,
  3900. tedescendercyrillic: 0x04AD,
  3901. teharabic: 0x062A,
  3902. tehfinalarabic: 0xFE96,
  3903. tehhahinitialarabic: 0xFCA2,
  3904. tehhahisolatedarabic: 0xFC0C,
  3905. tehinitialarabic: 0xFE97,
  3906. tehiragana: 0x3066,
  3907. tehjeeminitialarabic: 0xFCA1,
  3908. tehjeemisolatedarabic: 0xFC0B,
  3909. tehmarbutaarabic: 0x0629,
  3910. tehmarbutafinalarabic: 0xFE94,
  3911. tehmedialarabic: 0xFE98,
  3912. tehmeeminitialarabic: 0xFCA4,
  3913. tehmeemisolatedarabic: 0xFC0E,
  3914. tehnoonfinalarabic: 0xFC73,
  3915. tekatakana: 0x30C6,
  3916. tekatakanahalfwidth: 0xFF83,
  3917. telephone: 0x2121,
  3918. telephoneblack: 0x260E,
  3919. telishagedolahebrew: 0x05A0,
  3920. telishaqetanahebrew: 0x05A9,
  3921. tencircle: 0x2469,
  3922. tenideographicparen: 0x3229,
  3923. tenparen: 0x247D,
  3924. tenperiod: 0x2491,
  3925. tenroman: 0x2179,
  3926. tesh: 0x02A7,
  3927. tet: 0x05D8,
  3928. tetdagesh: 0xFB38,
  3929. tetdageshhebrew: 0xFB38,
  3930. tethebrew: 0x05D8,
  3931. tetsecyrillic: 0x04B5,
  3932. tevirhebrew: 0x059B,
  3933. tevirlefthebrew: 0x059B,
  3934. thabengali: 0x09A5,
  3935. thadeva: 0x0925,
  3936. thagujarati: 0x0AA5,
  3937. thagurmukhi: 0x0A25,
  3938. thalarabic: 0x0630,
  3939. thalfinalarabic: 0xFEAC,
  3940. thanthakhatlowleftthai: 0xF898,
  3941. thanthakhatlowrightthai: 0xF897,
  3942. thanthakhatthai: 0x0E4C,
  3943. thanthakhatupperleftthai: 0xF896,
  3944. theharabic: 0x062B,
  3945. thehfinalarabic: 0xFE9A,
  3946. thehinitialarabic: 0xFE9B,
  3947. thehmedialarabic: 0xFE9C,
  3948. thereexists: 0x2203,
  3949. therefore: 0x2234,
  3950. theta: 0x03B8,
  3951. theta1: 0x03D1,
  3952. thetasymbolgreek: 0x03D1,
  3953. thieuthacirclekorean: 0x3279,
  3954. thieuthaparenkorean: 0x3219,
  3955. thieuthcirclekorean: 0x326B,
  3956. thieuthkorean: 0x314C,
  3957. thieuthparenkorean: 0x320B,
  3958. thirteencircle: 0x246C,
  3959. thirteenparen: 0x2480,
  3960. thirteenperiod: 0x2494,
  3961. thonangmonthothai: 0x0E11,
  3962. thook: 0x01AD,
  3963. thophuthaothai: 0x0E12,
  3964. thorn: 0x00FE,
  3965. thothahanthai: 0x0E17,
  3966. thothanthai: 0x0E10,
  3967. thothongthai: 0x0E18,
  3968. thothungthai: 0x0E16,
  3969. thousandcyrillic: 0x0482,
  3970. thousandsseparatorarabic: 0x066C,
  3971. thousandsseparatorpersian: 0x066C,
  3972. three: 0x0033,
  3973. threearabic: 0x0663,
  3974. threebengali: 0x09E9,
  3975. threecircle: 0x2462,
  3976. threecircleinversesansserif: 0x278C,
  3977. threedeva: 0x0969,
  3978. threeeighths: 0x215C,
  3979. threegujarati: 0x0AE9,
  3980. threegurmukhi: 0x0A69,
  3981. threehackarabic: 0x0663,
  3982. threehangzhou: 0x3023,
  3983. threeideographicparen: 0x3222,
  3984. threeinferior: 0x2083,
  3985. threemonospace: 0xFF13,
  3986. threenumeratorbengali: 0x09F6,
  3987. threeoldstyle: 0xF733,
  3988. threeparen: 0x2476,
  3989. threeperiod: 0x248A,
  3990. threepersian: 0x06F3,
  3991. threequarters: 0x00BE,
  3992. threequartersemdash: 0xF6DE,
  3993. threeroman: 0x2172,
  3994. threesuperior: 0x00B3,
  3995. threethai: 0x0E53,
  3996. thzsquare: 0x3394,
  3997. tihiragana: 0x3061,
  3998. tikatakana: 0x30C1,
  3999. tikatakanahalfwidth: 0xFF81,
  4000. tikeutacirclekorean: 0x3270,
  4001. tikeutaparenkorean: 0x3210,
  4002. tikeutcirclekorean: 0x3262,
  4003. tikeutkorean: 0x3137,
  4004. tikeutparenkorean: 0x3202,
  4005. tilde: 0x02DC,
  4006. tildebelowcmb: 0x0330,
  4007. tildecmb: 0x0303,
  4008. tildecomb: 0x0303,
  4009. tildedoublecmb: 0x0360,
  4010. tildeoperator: 0x223C,
  4011. tildeoverlaycmb: 0x0334,
  4012. tildeverticalcmb: 0x033E,
  4013. timescircle: 0x2297,
  4014. tipehahebrew: 0x0596,
  4015. tipehalefthebrew: 0x0596,
  4016. tippigurmukhi: 0x0A70,
  4017. titlocyrilliccmb: 0x0483,
  4018. tiwnarmenian: 0x057F,
  4019. tlinebelow: 0x1E6F,
  4020. tmonospace: 0xFF54,
  4021. toarmenian: 0x0569,
  4022. tohiragana: 0x3068,
  4023. tokatakana: 0x30C8,
  4024. tokatakanahalfwidth: 0xFF84,
  4025. tonebarextrahighmod: 0x02E5,
  4026. tonebarextralowmod: 0x02E9,
  4027. tonebarhighmod: 0x02E6,
  4028. tonebarlowmod: 0x02E8,
  4029. tonebarmidmod: 0x02E7,
  4030. tonefive: 0x01BD,
  4031. tonesix: 0x0185,
  4032. tonetwo: 0x01A8,
  4033. tonos: 0x0384,
  4034. tonsquare: 0x3327,
  4035. topatakthai: 0x0E0F,
  4036. tortoiseshellbracketleft: 0x3014,
  4037. tortoiseshellbracketleftsmall: 0xFE5D,
  4038. tortoiseshellbracketleftvertical: 0xFE39,
  4039. tortoiseshellbracketright: 0x3015,
  4040. tortoiseshellbracketrightsmall: 0xFE5E,
  4041. tortoiseshellbracketrightvertical: 0xFE3A,
  4042. totaothai: 0x0E15,
  4043. tpalatalhook: 0x01AB,
  4044. tparen: 0x24AF,
  4045. trademark: 0x2122,
  4046. trademarksans: 0xF8EA,
  4047. trademarkserif: 0xF6DB,
  4048. tretroflexhook: 0x0288,
  4049. triagdn: 0x25BC,
  4050. triaglf: 0x25C4,
  4051. triagrt: 0x25BA,
  4052. triagup: 0x25B2,
  4053. ts: 0x02A6,
  4054. tsadi: 0x05E6,
  4055. tsadidagesh: 0xFB46,
  4056. tsadidageshhebrew: 0xFB46,
  4057. tsadihebrew: 0x05E6,
  4058. tsecyrillic: 0x0446,
  4059. tsere: 0x05B5,
  4060. tsere12: 0x05B5,
  4061. tsere1e: 0x05B5,
  4062. tsere2b: 0x05B5,
  4063. tserehebrew: 0x05B5,
  4064. tserenarrowhebrew: 0x05B5,
  4065. tserequarterhebrew: 0x05B5,
  4066. tserewidehebrew: 0x05B5,
  4067. tshecyrillic: 0x045B,
  4068. tsuperior: 0xF6F3,
  4069. ttabengali: 0x099F,
  4070. ttadeva: 0x091F,
  4071. ttagujarati: 0x0A9F,
  4072. ttagurmukhi: 0x0A1F,
  4073. tteharabic: 0x0679,
  4074. ttehfinalarabic: 0xFB67,
  4075. ttehinitialarabic: 0xFB68,
  4076. ttehmedialarabic: 0xFB69,
  4077. tthabengali: 0x09A0,
  4078. tthadeva: 0x0920,
  4079. tthagujarati: 0x0AA0,
  4080. tthagurmukhi: 0x0A20,
  4081. tturned: 0x0287,
  4082. tuhiragana: 0x3064,
  4083. tukatakana: 0x30C4,
  4084. tukatakanahalfwidth: 0xFF82,
  4085. tusmallhiragana: 0x3063,
  4086. tusmallkatakana: 0x30C3,
  4087. tusmallkatakanahalfwidth: 0xFF6F,
  4088. twelvecircle: 0x246B,
  4089. twelveparen: 0x247F,
  4090. twelveperiod: 0x2493,
  4091. twelveroman: 0x217B,
  4092. twentycircle: 0x2473,
  4093. twentyhangzhou: 0x5344,
  4094. twentyparen: 0x2487,
  4095. twentyperiod: 0x249B,
  4096. two: 0x0032,
  4097. twoarabic: 0x0662,
  4098. twobengali: 0x09E8,
  4099. twocircle: 0x2461,
  4100. twocircleinversesansserif: 0x278B,
  4101. twodeva: 0x0968,
  4102. twodotenleader: 0x2025,
  4103. twodotleader: 0x2025,
  4104. twodotleadervertical: 0xFE30,
  4105. twogujarati: 0x0AE8,
  4106. twogurmukhi: 0x0A68,
  4107. twohackarabic: 0x0662,
  4108. twohangzhou: 0x3022,
  4109. twoideographicparen: 0x3221,
  4110. twoinferior: 0x2082,
  4111. twomonospace: 0xFF12,
  4112. twonumeratorbengali: 0x09F5,
  4113. twooldstyle: 0xF732,
  4114. twoparen: 0x2475,
  4115. twoperiod: 0x2489,
  4116. twopersian: 0x06F2,
  4117. tworoman: 0x2171,
  4118. twostroke: 0x01BB,
  4119. twosuperior: 0x00B2,
  4120. twothai: 0x0E52,
  4121. twothirds: 0x2154,
  4122. u: 0x0075,
  4123. uacute: 0x00FA,
  4124. ubar: 0x0289,
  4125. ubengali: 0x0989,
  4126. ubopomofo: 0x3128,
  4127. ubreve: 0x016D,
  4128. ucaron: 0x01D4,
  4129. ucircle: 0x24E4,
  4130. ucircumflex: 0x00FB,
  4131. ucircumflexbelow: 0x1E77,
  4132. ucyrillic: 0x0443,
  4133. udattadeva: 0x0951,
  4134. udblacute: 0x0171,
  4135. udblgrave: 0x0215,
  4136. udeva: 0x0909,
  4137. udieresis: 0x00FC,
  4138. udieresisacute: 0x01D8,
  4139. udieresisbelow: 0x1E73,
  4140. udieresiscaron: 0x01DA,
  4141. udieresiscyrillic: 0x04F1,
  4142. udieresisgrave: 0x01DC,
  4143. udieresismacron: 0x01D6,
  4144. udotbelow: 0x1EE5,
  4145. ugrave: 0x00F9,
  4146. ugujarati: 0x0A89,
  4147. ugurmukhi: 0x0A09,
  4148. uhiragana: 0x3046,
  4149. uhookabove: 0x1EE7,
  4150. uhorn: 0x01B0,
  4151. uhornacute: 0x1EE9,
  4152. uhorndotbelow: 0x1EF1,
  4153. uhorngrave: 0x1EEB,
  4154. uhornhookabove: 0x1EED,
  4155. uhorntilde: 0x1EEF,
  4156. uhungarumlaut: 0x0171,
  4157. uhungarumlautcyrillic: 0x04F3,
  4158. uinvertedbreve: 0x0217,
  4159. ukatakana: 0x30A6,
  4160. ukatakanahalfwidth: 0xFF73,
  4161. ukcyrillic: 0x0479,
  4162. ukorean: 0x315C,
  4163. umacron: 0x016B,
  4164. umacroncyrillic: 0x04EF,
  4165. umacrondieresis: 0x1E7B,
  4166. umatragurmukhi: 0x0A41,
  4167. umonospace: 0xFF55,
  4168. underscore: 0x005F,
  4169. underscoredbl: 0x2017,
  4170. underscoremonospace: 0xFF3F,
  4171. underscorevertical: 0xFE33,
  4172. underscorewavy: 0xFE4F,
  4173. union: 0x222A,
  4174. universal: 0x2200,
  4175. uogonek: 0x0173,
  4176. uparen: 0x24B0,
  4177. upblock: 0x2580,
  4178. upperdothebrew: 0x05C4,
  4179. upsilon: 0x03C5,
  4180. upsilondieresis: 0x03CB,
  4181. upsilondieresistonos: 0x03B0,
  4182. upsilonlatin: 0x028A,
  4183. upsilontonos: 0x03CD,
  4184. uptackbelowcmb: 0x031D,
  4185. uptackmod: 0x02D4,
  4186. uragurmukhi: 0x0A73,
  4187. uring: 0x016F,
  4188. ushortcyrillic: 0x045E,
  4189. usmallhiragana: 0x3045,
  4190. usmallkatakana: 0x30A5,
  4191. usmallkatakanahalfwidth: 0xFF69,
  4192. ustraightcyrillic: 0x04AF,
  4193. ustraightstrokecyrillic: 0x04B1,
  4194. utilde: 0x0169,
  4195. utildeacute: 0x1E79,
  4196. utildebelow: 0x1E75,
  4197. uubengali: 0x098A,
  4198. uudeva: 0x090A,
  4199. uugujarati: 0x0A8A,
  4200. uugurmukhi: 0x0A0A,
  4201. uumatragurmukhi: 0x0A42,
  4202. uuvowelsignbengali: 0x09C2,
  4203. uuvowelsigndeva: 0x0942,
  4204. uuvowelsigngujarati: 0x0AC2,
  4205. uvowelsignbengali: 0x09C1,
  4206. uvowelsigndeva: 0x0941,
  4207. uvowelsigngujarati: 0x0AC1,
  4208. v: 0x0076,
  4209. vadeva: 0x0935,
  4210. vagujarati: 0x0AB5,
  4211. vagurmukhi: 0x0A35,
  4212. vakatakana: 0x30F7,
  4213. vav: 0x05D5,
  4214. vavdagesh: 0xFB35,
  4215. vavdagesh65: 0xFB35,
  4216. vavdageshhebrew: 0xFB35,
  4217. vavhebrew: 0x05D5,
  4218. vavholam: 0xFB4B,
  4219. vavholamhebrew: 0xFB4B,
  4220. vavvavhebrew: 0x05F0,
  4221. vavyodhebrew: 0x05F1,
  4222. vcircle: 0x24E5,
  4223. vdotbelow: 0x1E7F,
  4224. vecyrillic: 0x0432,
  4225. veharabic: 0x06A4,
  4226. vehfinalarabic: 0xFB6B,
  4227. vehinitialarabic: 0xFB6C,
  4228. vehmedialarabic: 0xFB6D,
  4229. vekatakana: 0x30F9,
  4230. venus: 0x2640,
  4231. verticalbar: 0x007C,
  4232. verticallineabovecmb: 0x030D,
  4233. verticallinebelowcmb: 0x0329,
  4234. verticallinelowmod: 0x02CC,
  4235. verticallinemod: 0x02C8,
  4236. vewarmenian: 0x057E,
  4237. vhook: 0x028B,
  4238. vikatakana: 0x30F8,
  4239. viramabengali: 0x09CD,
  4240. viramadeva: 0x094D,
  4241. viramagujarati: 0x0ACD,
  4242. visargabengali: 0x0983,
  4243. visargadeva: 0x0903,
  4244. visargagujarati: 0x0A83,
  4245. vmonospace: 0xFF56,
  4246. voarmenian: 0x0578,
  4247. voicediterationhiragana: 0x309E,
  4248. voicediterationkatakana: 0x30FE,
  4249. voicedmarkkana: 0x309B,
  4250. voicedmarkkanahalfwidth: 0xFF9E,
  4251. vokatakana: 0x30FA,
  4252. vparen: 0x24B1,
  4253. vtilde: 0x1E7D,
  4254. vturned: 0x028C,
  4255. vuhiragana: 0x3094,
  4256. vukatakana: 0x30F4,
  4257. w: 0x0077,
  4258. wacute: 0x1E83,
  4259. waekorean: 0x3159,
  4260. wahiragana: 0x308F,
  4261. wakatakana: 0x30EF,
  4262. wakatakanahalfwidth: 0xFF9C,
  4263. wakorean: 0x3158,
  4264. wasmallhiragana: 0x308E,
  4265. wasmallkatakana: 0x30EE,
  4266. wattosquare: 0x3357,
  4267. wavedash: 0x301C,
  4268. wavyunderscorevertical: 0xFE34,
  4269. wawarabic: 0x0648,
  4270. wawfinalarabic: 0xFEEE,
  4271. wawhamzaabovearabic: 0x0624,
  4272. wawhamzaabovefinalarabic: 0xFE86,
  4273. wbsquare: 0x33DD,
  4274. wcircle: 0x24E6,
  4275. wcircumflex: 0x0175,
  4276. wdieresis: 0x1E85,
  4277. wdotaccent: 0x1E87,
  4278. wdotbelow: 0x1E89,
  4279. wehiragana: 0x3091,
  4280. weierstrass: 0x2118,
  4281. wekatakana: 0x30F1,
  4282. wekorean: 0x315E,
  4283. weokorean: 0x315D,
  4284. wgrave: 0x1E81,
  4285. whitebullet: 0x25E6,
  4286. whitecircle: 0x25CB,
  4287. whitecircleinverse: 0x25D9,
  4288. whitecornerbracketleft: 0x300E,
  4289. whitecornerbracketleftvertical: 0xFE43,
  4290. whitecornerbracketright: 0x300F,
  4291. whitecornerbracketrightvertical: 0xFE44,
  4292. whitediamond: 0x25C7,
  4293. whitediamondcontainingblacksmalldiamond: 0x25C8,
  4294. whitedownpointingsmalltriangle: 0x25BF,
  4295. whitedownpointingtriangle: 0x25BD,
  4296. whiteleftpointingsmalltriangle: 0x25C3,
  4297. whiteleftpointingtriangle: 0x25C1,
  4298. whitelenticularbracketleft: 0x3016,
  4299. whitelenticularbracketright: 0x3017,
  4300. whiterightpointingsmalltriangle: 0x25B9,
  4301. whiterightpointingtriangle: 0x25B7,
  4302. whitesmallsquare: 0x25AB,
  4303. whitesmilingface: 0x263A,
  4304. whitesquare: 0x25A1,
  4305. whitestar: 0x2606,
  4306. whitetelephone: 0x260F,
  4307. whitetortoiseshellbracketleft: 0x3018,
  4308. whitetortoiseshellbracketright: 0x3019,
  4309. whiteuppointingsmalltriangle: 0x25B5,
  4310. whiteuppointingtriangle: 0x25B3,
  4311. wihiragana: 0x3090,
  4312. wikatakana: 0x30F0,
  4313. wikorean: 0x315F,
  4314. wmonospace: 0xFF57,
  4315. wohiragana: 0x3092,
  4316. wokatakana: 0x30F2,
  4317. wokatakanahalfwidth: 0xFF66,
  4318. won: 0x20A9,
  4319. wonmonospace: 0xFFE6,
  4320. wowaenthai: 0x0E27,
  4321. wparen: 0x24B2,
  4322. wring: 0x1E98,
  4323. wsuperior: 0x02B7,
  4324. wturned: 0x028D,
  4325. wynn: 0x01BF,
  4326. x: 0x0078,
  4327. xabovecmb: 0x033D,
  4328. xbopomofo: 0x3112,
  4329. xcircle: 0x24E7,
  4330. xdieresis: 0x1E8D,
  4331. xdotaccent: 0x1E8B,
  4332. xeharmenian: 0x056D,
  4333. xi: 0x03BE,
  4334. xmonospace: 0xFF58,
  4335. xparen: 0x24B3,
  4336. xsuperior: 0x02E3,
  4337. y: 0x0079,
  4338. yaadosquare: 0x334E,
  4339. yabengali: 0x09AF,
  4340. yacute: 0x00FD,
  4341. yadeva: 0x092F,
  4342. yaekorean: 0x3152,
  4343. yagujarati: 0x0AAF,
  4344. yagurmukhi: 0x0A2F,
  4345. yahiragana: 0x3084,
  4346. yakatakana: 0x30E4,
  4347. yakatakanahalfwidth: 0xFF94,
  4348. yakorean: 0x3151,
  4349. yamakkanthai: 0x0E4E,
  4350. yasmallhiragana: 0x3083,
  4351. yasmallkatakana: 0x30E3,
  4352. yasmallkatakanahalfwidth: 0xFF6C,
  4353. yatcyrillic: 0x0463,
  4354. ycircle: 0x24E8,
  4355. ycircumflex: 0x0177,
  4356. ydieresis: 0x00FF,
  4357. ydotaccent: 0x1E8F,
  4358. ydotbelow: 0x1EF5,
  4359. yeharabic: 0x064A,
  4360. yehbarreearabic: 0x06D2,
  4361. yehbarreefinalarabic: 0xFBAF,
  4362. yehfinalarabic: 0xFEF2,
  4363. yehhamzaabovearabic: 0x0626,
  4364. yehhamzaabovefinalarabic: 0xFE8A,
  4365. yehhamzaaboveinitialarabic: 0xFE8B,
  4366. yehhamzaabovemedialarabic: 0xFE8C,
  4367. yehinitialarabic: 0xFEF3,
  4368. yehmedialarabic: 0xFEF4,
  4369. yehmeeminitialarabic: 0xFCDD,
  4370. yehmeemisolatedarabic: 0xFC58,
  4371. yehnoonfinalarabic: 0xFC94,
  4372. yehthreedotsbelowarabic: 0x06D1,
  4373. yekorean: 0x3156,
  4374. yen: 0x00A5,
  4375. yenmonospace: 0xFFE5,
  4376. yeokorean: 0x3155,
  4377. yeorinhieuhkorean: 0x3186,
  4378. yerahbenyomohebrew: 0x05AA,
  4379. yerahbenyomolefthebrew: 0x05AA,
  4380. yericyrillic: 0x044B,
  4381. yerudieresiscyrillic: 0x04F9,
  4382. yesieungkorean: 0x3181,
  4383. yesieungpansioskorean: 0x3183,
  4384. yesieungsioskorean: 0x3182,
  4385. yetivhebrew: 0x059A,
  4386. ygrave: 0x1EF3,
  4387. yhook: 0x01B4,
  4388. yhookabove: 0x1EF7,
  4389. yiarmenian: 0x0575,
  4390. yicyrillic: 0x0457,
  4391. yikorean: 0x3162,
  4392. yinyang: 0x262F,
  4393. yiwnarmenian: 0x0582,
  4394. ymonospace: 0xFF59,
  4395. yod: 0x05D9,
  4396. yoddagesh: 0xFB39,
  4397. yoddageshhebrew: 0xFB39,
  4398. yodhebrew: 0x05D9,
  4399. yodyodhebrew: 0x05F2,
  4400. yodyodpatahhebrew: 0xFB1F,
  4401. yohiragana: 0x3088,
  4402. yoikorean: 0x3189,
  4403. yokatakana: 0x30E8,
  4404. yokatakanahalfwidth: 0xFF96,
  4405. yokorean: 0x315B,
  4406. yosmallhiragana: 0x3087,
  4407. yosmallkatakana: 0x30E7,
  4408. yosmallkatakanahalfwidth: 0xFF6E,
  4409. yotgreek: 0x03F3,
  4410. yoyaekorean: 0x3188,
  4411. yoyakorean: 0x3187,
  4412. yoyakthai: 0x0E22,
  4413. yoyingthai: 0x0E0D,
  4414. yparen: 0x24B4,
  4415. ypogegrammeni: 0x037A,
  4416. ypogegrammenigreekcmb: 0x0345,
  4417. yr: 0x01A6,
  4418. yring: 0x1E99,
  4419. ysuperior: 0x02B8,
  4420. ytilde: 0x1EF9,
  4421. yturned: 0x028E,
  4422. yuhiragana: 0x3086,
  4423. yuikorean: 0x318C,
  4424. yukatakana: 0x30E6,
  4425. yukatakanahalfwidth: 0xFF95,
  4426. yukorean: 0x3160,
  4427. yusbigcyrillic: 0x046B,
  4428. yusbigiotifiedcyrillic: 0x046D,
  4429. yuslittlecyrillic: 0x0467,
  4430. yuslittleiotifiedcyrillic: 0x0469,
  4431. yusmallhiragana: 0x3085,
  4432. yusmallkatakana: 0x30E5,
  4433. yusmallkatakanahalfwidth: 0xFF6D,
  4434. yuyekorean: 0x318B,
  4435. yuyeokorean: 0x318A,
  4436. yyabengali: 0x09DF,
  4437. yyadeva: 0x095F,
  4438. z: 0x007A,
  4439. zaarmenian: 0x0566,
  4440. zacute: 0x017A,
  4441. zadeva: 0x095B,
  4442. zagurmukhi: 0x0A5B,
  4443. zaharabic: 0x0638,
  4444. zahfinalarabic: 0xFEC6,
  4445. zahinitialarabic: 0xFEC7,
  4446. zahiragana: 0x3056,
  4447. zahmedialarabic: 0xFEC8,
  4448. zainarabic: 0x0632,
  4449. zainfinalarabic: 0xFEB0,
  4450. zakatakana: 0x30B6,
  4451. zaqefgadolhebrew: 0x0595,
  4452. zaqefqatanhebrew: 0x0594,
  4453. zarqahebrew: 0x0598,
  4454. zayin: 0x05D6,
  4455. zayindagesh: 0xFB36,
  4456. zayindageshhebrew: 0xFB36,
  4457. zayinhebrew: 0x05D6,
  4458. zbopomofo: 0x3117,
  4459. zcaron: 0x017E,
  4460. zcircle: 0x24E9,
  4461. zcircumflex: 0x1E91,
  4462. zcurl: 0x0291,
  4463. zdot: 0x017C,
  4464. zdotaccent: 0x017C,
  4465. zdotbelow: 0x1E93,
  4466. zecyrillic: 0x0437,
  4467. zedescendercyrillic: 0x0499,
  4468. zedieresiscyrillic: 0x04DF,
  4469. zehiragana: 0x305C,
  4470. zekatakana: 0x30BC,
  4471. zero: 0x0030,
  4472. zeroarabic: 0x0660,
  4473. zerobengali: 0x09E6,
  4474. zerodeva: 0x0966,
  4475. zerogujarati: 0x0AE6,
  4476. zerogurmukhi: 0x0A66,
  4477. zerohackarabic: 0x0660,
  4478. zeroinferior: 0x2080,
  4479. zeromonospace: 0xFF10,
  4480. zerooldstyle: 0xF730,
  4481. zeropersian: 0x06F0,
  4482. zerosuperior: 0x2070,
  4483. zerothai: 0x0E50,
  4484. zerowidthjoiner: 0xFEFF,
  4485. zerowidthnonjoiner: 0x200C,
  4486. zerowidthspace: 0x200B,
  4487. zeta: 0x03B6,
  4488. zhbopomofo: 0x3113,
  4489. zhearmenian: 0x056A,
  4490. zhebrevecyrillic: 0x04C2,
  4491. zhecyrillic: 0x0436,
  4492. zhedescendercyrillic: 0x0497,
  4493. zhedieresiscyrillic: 0x04DD,
  4494. zihiragana: 0x3058,
  4495. zikatakana: 0x30B8,
  4496. zinorhebrew: 0x05AE,
  4497. zlinebelow: 0x1E95,
  4498. zmonospace: 0xFF5A,
  4499. zohiragana: 0x305E,
  4500. zokatakana: 0x30BE,
  4501. zparen: 0x24B5,
  4502. zretroflexhook: 0x0290,
  4503. zstroke: 0x01B6,
  4504. zuhiragana: 0x305A,
  4505. zukatakana: 0x30BA,
  4506. '.notdef': 0x0000
  4507. };
  4508. var DingbatsGlyphsUnicode = {
  4509. space: 0x0020,
  4510. a1: 0x2701,
  4511. a2: 0x2702,
  4512. a202: 0x2703,
  4513. a3: 0x2704,
  4514. a4: 0x260E,
  4515. a5: 0x2706,
  4516. a119: 0x2707,
  4517. a118: 0x2708,
  4518. a117: 0x2709,
  4519. a11: 0x261B,
  4520. a12: 0x261E,
  4521. a13: 0x270C,
  4522. a14: 0x270D,
  4523. a15: 0x270E,
  4524. a16: 0x270F,
  4525. a105: 0x2710,
  4526. a17: 0x2711,
  4527. a18: 0x2712,
  4528. a19: 0x2713,
  4529. a20: 0x2714,
  4530. a21: 0x2715,
  4531. a22: 0x2716,
  4532. a23: 0x2717,
  4533. a24: 0x2718,
  4534. a25: 0x2719,
  4535. a26: 0x271A,
  4536. a27: 0x271B,
  4537. a28: 0x271C,
  4538. a6: 0x271D,
  4539. a7: 0x271E,
  4540. a8: 0x271F,
  4541. a9: 0x2720,
  4542. a10: 0x2721,
  4543. a29: 0x2722,
  4544. a30: 0x2723,
  4545. a31: 0x2724,
  4546. a32: 0x2725,
  4547. a33: 0x2726,
  4548. a34: 0x2727,
  4549. a35: 0x2605,
  4550. a36: 0x2729,
  4551. a37: 0x272A,
  4552. a38: 0x272B,
  4553. a39: 0x272C,
  4554. a40: 0x272D,
  4555. a41: 0x272E,
  4556. a42: 0x272F,
  4557. a43: 0x2730,
  4558. a44: 0x2731,
  4559. a45: 0x2732,
  4560. a46: 0x2733,
  4561. a47: 0x2734,
  4562. a48: 0x2735,
  4563. a49: 0x2736,
  4564. a50: 0x2737,
  4565. a51: 0x2738,
  4566. a52: 0x2739,
  4567. a53: 0x273A,
  4568. a54: 0x273B,
  4569. a55: 0x273C,
  4570. a56: 0x273D,
  4571. a57: 0x273E,
  4572. a58: 0x273F,
  4573. a59: 0x2740,
  4574. a60: 0x2741,
  4575. a61: 0x2742,
  4576. a62: 0x2743,
  4577. a63: 0x2744,
  4578. a64: 0x2745,
  4579. a65: 0x2746,
  4580. a66: 0x2747,
  4581. a67: 0x2748,
  4582. a68: 0x2749,
  4583. a69: 0x274A,
  4584. a70: 0x274B,
  4585. a71: 0x25CF,
  4586. a72: 0x274D,
  4587. a73: 0x25A0,
  4588. a74: 0x274F,
  4589. a203: 0x2750,
  4590. a75: 0x2751,
  4591. a204: 0x2752,
  4592. a76: 0x25B2,
  4593. a77: 0x25BC,
  4594. a78: 0x25C6,
  4595. a79: 0x2756,
  4596. a81: 0x25D7,
  4597. a82: 0x2758,
  4598. a83: 0x2759,
  4599. a84: 0x275A,
  4600. a97: 0x275B,
  4601. a98: 0x275C,
  4602. a99: 0x275D,
  4603. a100: 0x275E,
  4604. a101: 0x2761,
  4605. a102: 0x2762,
  4606. a103: 0x2763,
  4607. a104: 0x2764,
  4608. a106: 0x2765,
  4609. a107: 0x2766,
  4610. a108: 0x2767,
  4611. a112: 0x2663,
  4612. a111: 0x2666,
  4613. a110: 0x2665,
  4614. a109: 0x2660,
  4615. a120: 0x2460,
  4616. a121: 0x2461,
  4617. a122: 0x2462,
  4618. a123: 0x2463,
  4619. a124: 0x2464,
  4620. a125: 0x2465,
  4621. a126: 0x2466,
  4622. a127: 0x2467,
  4623. a128: 0x2468,
  4624. a129: 0x2469,
  4625. a130: 0x2776,
  4626. a131: 0x2777,
  4627. a132: 0x2778,
  4628. a133: 0x2779,
  4629. a134: 0x277A,
  4630. a135: 0x277B,
  4631. a136: 0x277C,
  4632. a137: 0x277D,
  4633. a138: 0x277E,
  4634. a139: 0x277F,
  4635. a140: 0x2780,
  4636. a141: 0x2781,
  4637. a142: 0x2782,
  4638. a143: 0x2783,
  4639. a144: 0x2784,
  4640. a145: 0x2785,
  4641. a146: 0x2786,
  4642. a147: 0x2787,
  4643. a148: 0x2788,
  4644. a149: 0x2789,
  4645. a150: 0x278A,
  4646. a151: 0x278B,
  4647. a152: 0x278C,
  4648. a153: 0x278D,
  4649. a154: 0x278E,
  4650. a155: 0x278F,
  4651. a156: 0x2790,
  4652. a157: 0x2791,
  4653. a158: 0x2792,
  4654. a159: 0x2793,
  4655. a160: 0x2794,
  4656. a161: 0x2192,
  4657. a163: 0x2194,
  4658. a164: 0x2195,
  4659. a196: 0x2798,
  4660. a165: 0x2799,
  4661. a192: 0x279A,
  4662. a166: 0x279B,
  4663. a167: 0x279C,
  4664. a168: 0x279D,
  4665. a169: 0x279E,
  4666. a170: 0x279F,
  4667. a171: 0x27A0,
  4668. a172: 0x27A1,
  4669. a173: 0x27A2,
  4670. a162: 0x27A3,
  4671. a174: 0x27A4,
  4672. a175: 0x27A5,
  4673. a176: 0x27A6,
  4674. a177: 0x27A7,
  4675. a178: 0x27A8,
  4676. a179: 0x27A9,
  4677. a193: 0x27AA,
  4678. a180: 0x27AB,
  4679. a199: 0x27AC,
  4680. a181: 0x27AD,
  4681. a200: 0x27AE,
  4682. a182: 0x27AF,
  4683. a201: 0x27B1,
  4684. a183: 0x27B2,
  4685. a184: 0x27B3,
  4686. a197: 0x27B4,
  4687. a185: 0x27B5,
  4688. a194: 0x27B6,
  4689. a198: 0x27B7,
  4690. a186: 0x27B8,
  4691. a195: 0x27B9,
  4692. a187: 0x27BA,
  4693. a188: 0x27BB,
  4694. a189: 0x27BC,
  4695. a190: 0x27BD,
  4696. a191: 0x27BE,
  4697. a89: 0x2768, // 0xF8D7
  4698. a90: 0x2769, // 0xF8D8
  4699. a93: 0x276A, // 0xF8D9
  4700. a94: 0x276B, // 0xF8DA
  4701. a91: 0x276C, // 0xF8DB
  4702. a92: 0x276D, // 0xF8DC
  4703. a205: 0x276E, // 0xF8DD
  4704. a85: 0x276F, // 0xF8DE
  4705. a206: 0x2770, // 0xF8DF
  4706. a86: 0x2771, // 0xF8E0
  4707. a87: 0x2772, // 0xF8E1
  4708. a88: 0x2773, // 0xF8E2
  4709. a95: 0x2774, // 0xF8E3
  4710. a96: 0x2775, // 0xF8E4
  4711. '.notdef': 0x0000
  4712. };
  4713. exports.GlyphsUnicode = GlyphsUnicode;
  4714. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  4715. }));
  4716. (function (root, factory) {
  4717. {
  4718. factory((root.pdfjsCoreJpg = {}));
  4719. }
  4720. }(this, function (exports) {
  4721. /*
  4722. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  4723. version was created by github user notmasteryet
  4724. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  4725. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  4726. - The JFIF specification can be found in the JPEG File Interchange Format
  4727. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  4728. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  4729. in PostScript Level 2, Technical Note #5116
  4730. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  4731. */
  4732. var JpegImage = (function jpegImage() {
  4733. var dctZigZag = new Uint8Array([
  4734. 0,
  4735. 1, 8,
  4736. 16, 9, 2,
  4737. 3, 10, 17, 24,
  4738. 32, 25, 18, 11, 4,
  4739. 5, 12, 19, 26, 33, 40,
  4740. 48, 41, 34, 27, 20, 13, 6,
  4741. 7, 14, 21, 28, 35, 42, 49, 56,
  4742. 57, 50, 43, 36, 29, 22, 15,
  4743. 23, 30, 37, 44, 51, 58,
  4744. 59, 52, 45, 38, 31,
  4745. 39, 46, 53, 60,
  4746. 61, 54, 47,
  4747. 55, 62,
  4748. 63
  4749. ]);
  4750. var dctCos1 = 4017; // cos(pi/16)
  4751. var dctSin1 = 799; // sin(pi/16)
  4752. var dctCos3 = 3406; // cos(3*pi/16)
  4753. var dctSin3 = 2276; // sin(3*pi/16)
  4754. var dctCos6 = 1567; // cos(6*pi/16)
  4755. var dctSin6 = 3784; // sin(6*pi/16)
  4756. var dctSqrt2 = 5793; // sqrt(2)
  4757. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  4758. function constructor() {
  4759. }
  4760. function buildHuffmanTable(codeLengths, values) {
  4761. var k = 0, code = [], i, j, length = 16;
  4762. while (length > 0 && !codeLengths[length - 1]) {
  4763. length--;
  4764. }
  4765. code.push({children: [], index: 0});
  4766. var p = code[0], q;
  4767. for (i = 0; i < length; i++) {
  4768. for (j = 0; j < codeLengths[i]; j++) {
  4769. p = code.pop();
  4770. p.children[p.index] = values[k];
  4771. while (p.index > 0) {
  4772. p = code.pop();
  4773. }
  4774. p.index++;
  4775. code.push(p);
  4776. while (code.length <= i) {
  4777. code.push(q = {children: [], index: 0});
  4778. p.children[p.index] = q.children;
  4779. p = q;
  4780. }
  4781. k++;
  4782. }
  4783. if (i + 1 < length) {
  4784. // p here points to last code
  4785. code.push(q = {children: [], index: 0});
  4786. p.children[p.index] = q.children;
  4787. p = q;
  4788. }
  4789. }
  4790. return code[0].children;
  4791. }
  4792. function getBlockBufferOffset(component, row, col) {
  4793. return 64 * ((component.blocksPerLine + 1) * row + col);
  4794. }
  4795. function decodeScan(data, offset, frame, components, resetInterval,
  4796. spectralStart, spectralEnd, successivePrev, successive) {
  4797. var mcusPerLine = frame.mcusPerLine;
  4798. var progressive = frame.progressive;
  4799. var startOffset = offset, bitsData = 0, bitsCount = 0;
  4800. function readBit() {
  4801. if (bitsCount > 0) {
  4802. bitsCount--;
  4803. return (bitsData >> bitsCount) & 1;
  4804. }
  4805. bitsData = data[offset++];
  4806. if (bitsData === 0xFF) {
  4807. var nextByte = data[offset++];
  4808. if (nextByte) {
  4809. throw 'unexpected marker: ' +
  4810. ((bitsData << 8) | nextByte).toString(16);
  4811. }
  4812. // unstuff 0
  4813. }
  4814. bitsCount = 7;
  4815. return bitsData >>> 7;
  4816. }
  4817. function decodeHuffman(tree) {
  4818. var node = tree;
  4819. while (true) {
  4820. node = node[readBit()];
  4821. if (typeof node === 'number') {
  4822. return node;
  4823. }
  4824. if (typeof node !== 'object') {
  4825. throw 'invalid huffman sequence';
  4826. }
  4827. }
  4828. }
  4829. function receive(length) {
  4830. var n = 0;
  4831. while (length > 0) {
  4832. n = (n << 1) | readBit();
  4833. length--;
  4834. }
  4835. return n;
  4836. }
  4837. function receiveAndExtend(length) {
  4838. if (length === 1) {
  4839. return readBit() === 1 ? 1 : -1;
  4840. }
  4841. var n = receive(length);
  4842. if (n >= 1 << (length - 1)) {
  4843. return n;
  4844. }
  4845. return n + (-1 << length) + 1;
  4846. }
  4847. function decodeBaseline(component, offset) {
  4848. var t = decodeHuffman(component.huffmanTableDC);
  4849. var diff = t === 0 ? 0 : receiveAndExtend(t);
  4850. component.blockData[offset] = (component.pred += diff);
  4851. var k = 1;
  4852. while (k < 64) {
  4853. var rs = decodeHuffman(component.huffmanTableAC);
  4854. var s = rs & 15, r = rs >> 4;
  4855. if (s === 0) {
  4856. if (r < 15) {
  4857. break;
  4858. }
  4859. k += 16;
  4860. continue;
  4861. }
  4862. k += r;
  4863. var z = dctZigZag[k];
  4864. component.blockData[offset + z] = receiveAndExtend(s);
  4865. k++;
  4866. }
  4867. }
  4868. function decodeDCFirst(component, offset) {
  4869. var t = decodeHuffman(component.huffmanTableDC);
  4870. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  4871. component.blockData[offset] = (component.pred += diff);
  4872. }
  4873. function decodeDCSuccessive(component, offset) {
  4874. component.blockData[offset] |= readBit() << successive;
  4875. }
  4876. var eobrun = 0;
  4877. function decodeACFirst(component, offset) {
  4878. if (eobrun > 0) {
  4879. eobrun--;
  4880. return;
  4881. }
  4882. var k = spectralStart, e = spectralEnd;
  4883. while (k <= e) {
  4884. var rs = decodeHuffman(component.huffmanTableAC);
  4885. var s = rs & 15, r = rs >> 4;
  4886. if (s === 0) {
  4887. if (r < 15) {
  4888. eobrun = receive(r) + (1 << r) - 1;
  4889. break;
  4890. }
  4891. k += 16;
  4892. continue;
  4893. }
  4894. k += r;
  4895. var z = dctZigZag[k];
  4896. component.blockData[offset + z] =
  4897. receiveAndExtend(s) * (1 << successive);
  4898. k++;
  4899. }
  4900. }
  4901. var successiveACState = 0, successiveACNextValue;
  4902. function decodeACSuccessive(component, offset) {
  4903. var k = spectralStart;
  4904. var e = spectralEnd;
  4905. var r = 0;
  4906. var s;
  4907. var rs;
  4908. while (k <= e) {
  4909. var z = dctZigZag[k];
  4910. switch (successiveACState) {
  4911. case 0: // initial state
  4912. rs = decodeHuffman(component.huffmanTableAC);
  4913. s = rs & 15;
  4914. r = rs >> 4;
  4915. if (s === 0) {
  4916. if (r < 15) {
  4917. eobrun = receive(r) + (1 << r);
  4918. successiveACState = 4;
  4919. } else {
  4920. r = 16;
  4921. successiveACState = 1;
  4922. }
  4923. } else {
  4924. if (s !== 1) {
  4925. throw 'invalid ACn encoding';
  4926. }
  4927. successiveACNextValue = receiveAndExtend(s);
  4928. successiveACState = r ? 2 : 3;
  4929. }
  4930. continue;
  4931. case 1: // skipping r zero items
  4932. case 2:
  4933. if (component.blockData[offset + z]) {
  4934. component.blockData[offset + z] += (readBit() << successive);
  4935. } else {
  4936. r--;
  4937. if (r === 0) {
  4938. successiveACState = successiveACState === 2 ? 3 : 0;
  4939. }
  4940. }
  4941. break;
  4942. case 3: // set value for a zero item
  4943. if (component.blockData[offset + z]) {
  4944. component.blockData[offset + z] += (readBit() << successive);
  4945. } else {
  4946. component.blockData[offset + z] =
  4947. successiveACNextValue << successive;
  4948. successiveACState = 0;
  4949. }
  4950. break;
  4951. case 4: // eob
  4952. if (component.blockData[offset + z]) {
  4953. component.blockData[offset + z] += (readBit() << successive);
  4954. }
  4955. break;
  4956. }
  4957. k++;
  4958. }
  4959. if (successiveACState === 4) {
  4960. eobrun--;
  4961. if (eobrun === 0) {
  4962. successiveACState = 0;
  4963. }
  4964. }
  4965. }
  4966. function decodeMcu(component, decode, mcu, row, col) {
  4967. var mcuRow = (mcu / mcusPerLine) | 0;
  4968. var mcuCol = mcu % mcusPerLine;
  4969. var blockRow = mcuRow * component.v + row;
  4970. var blockCol = mcuCol * component.h + col;
  4971. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4972. decode(component, offset);
  4973. }
  4974. function decodeBlock(component, decode, mcu) {
  4975. var blockRow = (mcu / component.blocksPerLine) | 0;
  4976. var blockCol = mcu % component.blocksPerLine;
  4977. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4978. decode(component, offset);
  4979. }
  4980. var componentsLength = components.length;
  4981. var component, i, j, k, n;
  4982. var decodeFn;
  4983. if (progressive) {
  4984. if (spectralStart === 0) {
  4985. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  4986. } else {
  4987. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  4988. }
  4989. } else {
  4990. decodeFn = decodeBaseline;
  4991. }
  4992. var mcu = 0, marker;
  4993. var mcuExpected;
  4994. if (componentsLength === 1) {
  4995. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  4996. } else {
  4997. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  4998. }
  4999. if (!resetInterval) {
  5000. resetInterval = mcuExpected;
  5001. }
  5002. var h, v;
  5003. while (mcu < mcuExpected) {
  5004. // reset interval stuff
  5005. for (i = 0; i < componentsLength; i++) {
  5006. components[i].pred = 0;
  5007. }
  5008. eobrun = 0;
  5009. if (componentsLength === 1) {
  5010. component = components[0];
  5011. for (n = 0; n < resetInterval; n++) {
  5012. decodeBlock(component, decodeFn, mcu);
  5013. mcu++;
  5014. }
  5015. } else {
  5016. for (n = 0; n < resetInterval; n++) {
  5017. for (i = 0; i < componentsLength; i++) {
  5018. component = components[i];
  5019. h = component.h;
  5020. v = component.v;
  5021. for (j = 0; j < v; j++) {
  5022. for (k = 0; k < h; k++) {
  5023. decodeMcu(component, decodeFn, mcu, j, k);
  5024. }
  5025. }
  5026. }
  5027. mcu++;
  5028. }
  5029. }
  5030. // find marker
  5031. bitsCount = 0;
  5032. marker = (data[offset] << 8) | data[offset + 1];
  5033. if (marker <= 0xFF00) {
  5034. throw 'marker was not found';
  5035. }
  5036. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  5037. offset += 2;
  5038. } else {
  5039. break;
  5040. }
  5041. }
  5042. return offset - startOffset;
  5043. }
  5044. // A port of poppler's IDCT method which in turn is taken from:
  5045. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  5046. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  5047. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  5048. // 988-991.
  5049. function quantizeAndInverse(component, blockBufferOffset, p) {
  5050. var qt = component.quantizationTable, blockData = component.blockData;
  5051. var v0, v1, v2, v3, v4, v5, v6, v7;
  5052. var p0, p1, p2, p3, p4, p5, p6, p7;
  5053. var t;
  5054. // inverse DCT on rows
  5055. for (var row = 0; row < 64; row += 8) {
  5056. // gather block data
  5057. p0 = blockData[blockBufferOffset + row];
  5058. p1 = blockData[blockBufferOffset + row + 1];
  5059. p2 = blockData[blockBufferOffset + row + 2];
  5060. p3 = blockData[blockBufferOffset + row + 3];
  5061. p4 = blockData[blockBufferOffset + row + 4];
  5062. p5 = blockData[blockBufferOffset + row + 5];
  5063. p6 = blockData[blockBufferOffset + row + 6];
  5064. p7 = blockData[blockBufferOffset + row + 7];
  5065. // dequant p0
  5066. p0 *= qt[row];
  5067. // check for all-zero AC coefficients
  5068. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5069. t = (dctSqrt2 * p0 + 512) >> 10;
  5070. p[row] = t;
  5071. p[row + 1] = t;
  5072. p[row + 2] = t;
  5073. p[row + 3] = t;
  5074. p[row + 4] = t;
  5075. p[row + 5] = t;
  5076. p[row + 6] = t;
  5077. p[row + 7] = t;
  5078. continue;
  5079. }
  5080. // dequant p1 ... p7
  5081. p1 *= qt[row + 1];
  5082. p2 *= qt[row + 2];
  5083. p3 *= qt[row + 3];
  5084. p4 *= qt[row + 4];
  5085. p5 *= qt[row + 5];
  5086. p6 *= qt[row + 6];
  5087. p7 *= qt[row + 7];
  5088. // stage 4
  5089. v0 = (dctSqrt2 * p0 + 128) >> 8;
  5090. v1 = (dctSqrt2 * p4 + 128) >> 8;
  5091. v2 = p2;
  5092. v3 = p6;
  5093. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  5094. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  5095. v5 = p3 << 4;
  5096. v6 = p5 << 4;
  5097. // stage 3
  5098. v0 = (v0 + v1 + 1) >> 1;
  5099. v1 = v0 - v1;
  5100. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  5101. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  5102. v3 = t;
  5103. v4 = (v4 + v6 + 1) >> 1;
  5104. v6 = v4 - v6;
  5105. v7 = (v7 + v5 + 1) >> 1;
  5106. v5 = v7 - v5;
  5107. // stage 2
  5108. v0 = (v0 + v3 + 1) >> 1;
  5109. v3 = v0 - v3;
  5110. v1 = (v1 + v2 + 1) >> 1;
  5111. v2 = v1 - v2;
  5112. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5113. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5114. v7 = t;
  5115. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5116. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5117. v6 = t;
  5118. // stage 1
  5119. p[row] = v0 + v7;
  5120. p[row + 7] = v0 - v7;
  5121. p[row + 1] = v1 + v6;
  5122. p[row + 6] = v1 - v6;
  5123. p[row + 2] = v2 + v5;
  5124. p[row + 5] = v2 - v5;
  5125. p[row + 3] = v3 + v4;
  5126. p[row + 4] = v3 - v4;
  5127. }
  5128. // inverse DCT on columns
  5129. for (var col = 0; col < 8; ++col) {
  5130. p0 = p[col];
  5131. p1 = p[col + 8];
  5132. p2 = p[col + 16];
  5133. p3 = p[col + 24];
  5134. p4 = p[col + 32];
  5135. p5 = p[col + 40];
  5136. p6 = p[col + 48];
  5137. p7 = p[col + 56];
  5138. // check for all-zero AC coefficients
  5139. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5140. t = (dctSqrt2 * p0 + 8192) >> 14;
  5141. // convert to 8 bit
  5142. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  5143. blockData[blockBufferOffset + col] = t;
  5144. blockData[blockBufferOffset + col + 8] = t;
  5145. blockData[blockBufferOffset + col + 16] = t;
  5146. blockData[blockBufferOffset + col + 24] = t;
  5147. blockData[blockBufferOffset + col + 32] = t;
  5148. blockData[blockBufferOffset + col + 40] = t;
  5149. blockData[blockBufferOffset + col + 48] = t;
  5150. blockData[blockBufferOffset + col + 56] = t;
  5151. continue;
  5152. }
  5153. // stage 4
  5154. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  5155. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  5156. v2 = p2;
  5157. v3 = p6;
  5158. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  5159. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  5160. v5 = p3;
  5161. v6 = p5;
  5162. // stage 3
  5163. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  5164. // converting to UInt8 range later.
  5165. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  5166. v1 = v0 - v1;
  5167. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  5168. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  5169. v3 = t;
  5170. v4 = (v4 + v6 + 1) >> 1;
  5171. v6 = v4 - v6;
  5172. v7 = (v7 + v5 + 1) >> 1;
  5173. v5 = v7 - v5;
  5174. // stage 2
  5175. v0 = (v0 + v3 + 1) >> 1;
  5176. v3 = v0 - v3;
  5177. v1 = (v1 + v2 + 1) >> 1;
  5178. v2 = v1 - v2;
  5179. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5180. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5181. v7 = t;
  5182. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5183. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5184. v6 = t;
  5185. // stage 1
  5186. p0 = v0 + v7;
  5187. p7 = v0 - v7;
  5188. p1 = v1 + v6;
  5189. p6 = v1 - v6;
  5190. p2 = v2 + v5;
  5191. p5 = v2 - v5;
  5192. p3 = v3 + v4;
  5193. p4 = v3 - v4;
  5194. // convert to 8-bit integers
  5195. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  5196. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  5197. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  5198. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  5199. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  5200. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  5201. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  5202. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  5203. // store block data
  5204. blockData[blockBufferOffset + col] = p0;
  5205. blockData[blockBufferOffset + col + 8] = p1;
  5206. blockData[blockBufferOffset + col + 16] = p2;
  5207. blockData[blockBufferOffset + col + 24] = p3;
  5208. blockData[blockBufferOffset + col + 32] = p4;
  5209. blockData[blockBufferOffset + col + 40] = p5;
  5210. blockData[blockBufferOffset + col + 48] = p6;
  5211. blockData[blockBufferOffset + col + 56] = p7;
  5212. }
  5213. }
  5214. function buildComponentData(frame, component) {
  5215. var blocksPerLine = component.blocksPerLine;
  5216. var blocksPerColumn = component.blocksPerColumn;
  5217. var computationBuffer = new Int16Array(64);
  5218. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  5219. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  5220. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  5221. quantizeAndInverse(component, offset, computationBuffer);
  5222. }
  5223. }
  5224. return component.blockData;
  5225. }
  5226. function clamp0to255(a) {
  5227. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  5228. }
  5229. constructor.prototype = {
  5230. parse: function parse(data) {
  5231. function readUint16() {
  5232. var value = (data[offset] << 8) | data[offset + 1];
  5233. offset += 2;
  5234. return value;
  5235. }
  5236. function readDataBlock() {
  5237. var length = readUint16();
  5238. var array = data.subarray(offset, offset + length - 2);
  5239. offset += array.length;
  5240. return array;
  5241. }
  5242. function prepareComponents(frame) {
  5243. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  5244. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  5245. for (var i = 0; i < frame.components.length; i++) {
  5246. component = frame.components[i];
  5247. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  5248. component.h / frame.maxH);
  5249. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  5250. component.v / frame.maxV);
  5251. var blocksPerLineForMcu = mcusPerLine * component.h;
  5252. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  5253. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  5254. (blocksPerLineForMcu + 1);
  5255. component.blockData = new Int16Array(blocksBufferSize);
  5256. component.blocksPerLine = blocksPerLine;
  5257. component.blocksPerColumn = blocksPerColumn;
  5258. }
  5259. frame.mcusPerLine = mcusPerLine;
  5260. frame.mcusPerColumn = mcusPerColumn;
  5261. }
  5262. var offset = 0;
  5263. var jfif = null;
  5264. var adobe = null;
  5265. var frame, resetInterval;
  5266. var quantizationTables = [];
  5267. var huffmanTablesAC = [], huffmanTablesDC = [];
  5268. var fileMarker = readUint16();
  5269. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  5270. throw 'SOI not found';
  5271. }
  5272. fileMarker = readUint16();
  5273. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  5274. var i, j, l;
  5275. switch(fileMarker) {
  5276. case 0xFFE0: // APP0 (Application Specific)
  5277. case 0xFFE1: // APP1
  5278. case 0xFFE2: // APP2
  5279. case 0xFFE3: // APP3
  5280. case 0xFFE4: // APP4
  5281. case 0xFFE5: // APP5
  5282. case 0xFFE6: // APP6
  5283. case 0xFFE7: // APP7
  5284. case 0xFFE8: // APP8
  5285. case 0xFFE9: // APP9
  5286. case 0xFFEA: // APP10
  5287. case 0xFFEB: // APP11
  5288. case 0xFFEC: // APP12
  5289. case 0xFFED: // APP13
  5290. case 0xFFEE: // APP14
  5291. case 0xFFEF: // APP15
  5292. case 0xFFFE: // COM (Comment)
  5293. var appData = readDataBlock();
  5294. if (fileMarker === 0xFFE0) {
  5295. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  5296. appData[2] === 0x49 && appData[3] === 0x46 &&
  5297. appData[4] === 0) { // 'JFIF\x00'
  5298. jfif = {
  5299. version: { major: appData[5], minor: appData[6] },
  5300. densityUnits: appData[7],
  5301. xDensity: (appData[8] << 8) | appData[9],
  5302. yDensity: (appData[10] << 8) | appData[11],
  5303. thumbWidth: appData[12],
  5304. thumbHeight: appData[13],
  5305. thumbData: appData.subarray(14, 14 +
  5306. 3 * appData[12] * appData[13])
  5307. };
  5308. }
  5309. }
  5310. // TODO APP1 - Exif
  5311. if (fileMarker === 0xFFEE) {
  5312. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  5313. appData[2] === 0x6F && appData[3] === 0x62 &&
  5314. appData[4] === 0x65) { // 'Adobe'
  5315. adobe = {
  5316. version: (appData[5] << 8) | appData[6],
  5317. flags0: (appData[7] << 8) | appData[8],
  5318. flags1: (appData[9] << 8) | appData[10],
  5319. transformCode: appData[11]
  5320. };
  5321. }
  5322. }
  5323. break;
  5324. case 0xFFDB: // DQT (Define Quantization Tables)
  5325. var quantizationTablesLength = readUint16();
  5326. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  5327. var z;
  5328. while (offset < quantizationTablesEnd) {
  5329. var quantizationTableSpec = data[offset++];
  5330. var tableData = new Uint16Array(64);
  5331. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  5332. for (j = 0; j < 64; j++) {
  5333. z = dctZigZag[j];
  5334. tableData[z] = data[offset++];
  5335. }
  5336. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  5337. for (j = 0; j < 64; j++) {
  5338. z = dctZigZag[j];
  5339. tableData[z] = readUint16();
  5340. }
  5341. } else {
  5342. throw 'DQT: invalid table spec';
  5343. }
  5344. quantizationTables[quantizationTableSpec & 15] = tableData;
  5345. }
  5346. break;
  5347. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  5348. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  5349. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  5350. if (frame) {
  5351. throw 'Only single frame JPEGs supported';
  5352. }
  5353. readUint16(); // skip data length
  5354. frame = {};
  5355. frame.extended = (fileMarker === 0xFFC1);
  5356. frame.progressive = (fileMarker === 0xFFC2);
  5357. frame.precision = data[offset++];
  5358. frame.scanLines = readUint16();
  5359. frame.samplesPerLine = readUint16();
  5360. frame.components = [];
  5361. frame.componentIds = {};
  5362. var componentsCount = data[offset++], componentId;
  5363. var maxH = 0, maxV = 0;
  5364. for (i = 0; i < componentsCount; i++) {
  5365. componentId = data[offset];
  5366. var h = data[offset + 1] >> 4;
  5367. var v = data[offset + 1] & 15;
  5368. if (maxH < h) {
  5369. maxH = h;
  5370. }
  5371. if (maxV < v) {
  5372. maxV = v;
  5373. }
  5374. var qId = data[offset + 2];
  5375. l = frame.components.push({
  5376. h: h,
  5377. v: v,
  5378. quantizationTable: quantizationTables[qId]
  5379. });
  5380. frame.componentIds[componentId] = l - 1;
  5381. offset += 3;
  5382. }
  5383. frame.maxH = maxH;
  5384. frame.maxV = maxV;
  5385. prepareComponents(frame);
  5386. break;
  5387. case 0xFFC4: // DHT (Define Huffman Tables)
  5388. var huffmanLength = readUint16();
  5389. for (i = 2; i < huffmanLength;) {
  5390. var huffmanTableSpec = data[offset++];
  5391. var codeLengths = new Uint8Array(16);
  5392. var codeLengthSum = 0;
  5393. for (j = 0; j < 16; j++, offset++) {
  5394. codeLengthSum += (codeLengths[j] = data[offset]);
  5395. }
  5396. var huffmanValues = new Uint8Array(codeLengthSum);
  5397. for (j = 0; j < codeLengthSum; j++, offset++) {
  5398. huffmanValues[j] = data[offset];
  5399. }
  5400. i += 17 + codeLengthSum;
  5401. ((huffmanTableSpec >> 4) === 0 ?
  5402. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  5403. buildHuffmanTable(codeLengths, huffmanValues);
  5404. }
  5405. break;
  5406. case 0xFFDD: // DRI (Define Restart Interval)
  5407. readUint16(); // skip data length
  5408. resetInterval = readUint16();
  5409. break;
  5410. case 0xFFDA: // SOS (Start of Scan)
  5411. var scanLength = readUint16();
  5412. var selectorsCount = data[offset++];
  5413. var components = [], component;
  5414. for (i = 0; i < selectorsCount; i++) {
  5415. var componentIndex = frame.componentIds[data[offset++]];
  5416. component = frame.components[componentIndex];
  5417. var tableSpec = data[offset++];
  5418. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  5419. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  5420. components.push(component);
  5421. }
  5422. var spectralStart = data[offset++];
  5423. var spectralEnd = data[offset++];
  5424. var successiveApproximation = data[offset++];
  5425. var processed = decodeScan(data, offset,
  5426. frame, components, resetInterval,
  5427. spectralStart, spectralEnd,
  5428. successiveApproximation >> 4, successiveApproximation & 15);
  5429. offset += processed;
  5430. break;
  5431. case 0xFFFF: // Fill bytes
  5432. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  5433. offset--;
  5434. }
  5435. break;
  5436. default:
  5437. if (data[offset - 3] === 0xFF &&
  5438. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  5439. // could be incorrect encoding -- last 0xFF byte of the previous
  5440. // block was eaten by the encoder
  5441. offset -= 3;
  5442. break;
  5443. }
  5444. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  5445. }
  5446. fileMarker = readUint16();
  5447. }
  5448. this.width = frame.samplesPerLine;
  5449. this.height = frame.scanLines;
  5450. this.jfif = jfif;
  5451. this.adobe = adobe;
  5452. this.components = [];
  5453. for (i = 0; i < frame.components.length; i++) {
  5454. component = frame.components[i];
  5455. this.components.push({
  5456. output: buildComponentData(frame, component),
  5457. scaleX: component.h / frame.maxH,
  5458. scaleY: component.v / frame.maxV,
  5459. blocksPerLine: component.blocksPerLine,
  5460. blocksPerColumn: component.blocksPerColumn
  5461. });
  5462. }
  5463. this.numComponents = this.components.length;
  5464. },
  5465. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  5466. var scaleX = this.width / width, scaleY = this.height / height;
  5467. var component, componentScaleX, componentScaleY, blocksPerScanline;
  5468. var x, y, i, j, k;
  5469. var index;
  5470. var offset = 0;
  5471. var output;
  5472. var numComponents = this.components.length;
  5473. var dataLength = width * height * numComponents;
  5474. var data = new Uint8Array(dataLength);
  5475. var xScaleBlockOffset = new Uint32Array(width);
  5476. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  5477. for (i = 0; i < numComponents; i++) {
  5478. component = this.components[i];
  5479. componentScaleX = component.scaleX * scaleX;
  5480. componentScaleY = component.scaleY * scaleY;
  5481. offset = i;
  5482. output = component.output;
  5483. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  5484. // precalculate the xScaleBlockOffset
  5485. for (x = 0; x < width; x++) {
  5486. j = 0 | (x * componentScaleX);
  5487. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  5488. }
  5489. // linearize the blocks of the component
  5490. for (y = 0; y < height; y++) {
  5491. j = 0 | (y * componentScaleY);
  5492. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  5493. for (x = 0; x < width; x++) {
  5494. data[offset] = output[index + xScaleBlockOffset[x]];
  5495. offset += numComponents;
  5496. }
  5497. }
  5498. }
  5499. // decodeTransform contains pairs of multiplier (-256..256) and additive
  5500. var transform = this.decodeTransform;
  5501. if (transform) {
  5502. for (i = 0; i < dataLength;) {
  5503. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  5504. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  5505. }
  5506. }
  5507. }
  5508. return data;
  5509. },
  5510. _isColorConversionNeeded: function isColorConversionNeeded() {
  5511. if (this.adobe && this.adobe.transformCode) {
  5512. // The adobe transform marker overrides any previous setting
  5513. return true;
  5514. } else if (this.numComponents === 3) {
  5515. return true;
  5516. } else {
  5517. return false;
  5518. }
  5519. },
  5520. _convertYccToRgb: function convertYccToRgb(data) {
  5521. var Y, Cb, Cr;
  5522. for (var i = 0, length = data.length; i < length; i += 3) {
  5523. Y = data[i ];
  5524. Cb = data[i + 1];
  5525. Cr = data[i + 2];
  5526. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  5527. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  5528. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  5529. }
  5530. return data;
  5531. },
  5532. _convertYcckToRgb: function convertYcckToRgb(data) {
  5533. var Y, Cb, Cr, k;
  5534. var offset = 0;
  5535. for (var i = 0, length = data.length; i < length; i += 4) {
  5536. Y = data[i];
  5537. Cb = data[i + 1];
  5538. Cr = data[i + 2];
  5539. k = data[i + 3];
  5540. var r = -122.67195406894 +
  5541. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  5542. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  5543. 0.154362151871126) +
  5544. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  5545. 0.00477271405408747 * k + 1.53380253221734) +
  5546. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  5547. 0.48357088451265) +
  5548. k * (-0.000336197177618394 * k + 0.484791561490776);
  5549. var g = 107.268039397724 +
  5550. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  5551. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  5552. 0.176491792462875) +
  5553. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  5554. 0.000770482631801132 * k - 0.151051492775562) +
  5555. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  5556. 0.25802910206845) +
  5557. k * (-0.000318913117588328 * k - 0.213742400323665);
  5558. var b = -20.810012546947 +
  5559. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  5560. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  5561. 0.814272968359295) +
  5562. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  5563. 0.000560833691242812 * k - 0.195152027534049) +
  5564. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  5565. 0.116935020465145) +
  5566. k * (-0.000343531996510555 * k + 0.24165260232407);
  5567. data[offset++] = clamp0to255(r);
  5568. data[offset++] = clamp0to255(g);
  5569. data[offset++] = clamp0to255(b);
  5570. }
  5571. return data;
  5572. },
  5573. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  5574. var Y, Cb, Cr;
  5575. for (var i = 0, length = data.length; i < length; i += 4) {
  5576. Y = data[i];
  5577. Cb = data[i + 1];
  5578. Cr = data[i + 2];
  5579. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  5580. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  5581. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  5582. // K in data[i + 3] is unchanged
  5583. }
  5584. return data;
  5585. },
  5586. _convertCmykToRgb: function convertCmykToRgb(data) {
  5587. var c, m, y, k;
  5588. var offset = 0;
  5589. var min = -255 * 255 * 255;
  5590. var scale = 1 / 255 / 255;
  5591. for (var i = 0, length = data.length; i < length; i += 4) {
  5592. c = data[i];
  5593. m = data[i + 1];
  5594. y = data[i + 2];
  5595. k = data[i + 3];
  5596. var r =
  5597. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  5598. 18.82290502165302 * y + 212.25662451639585 * k -
  5599. 72734.4411664936) +
  5600. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  5601. 17.873870861415444 * k - 1401.7366389350734) +
  5602. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  5603. 4465.541406466231) -
  5604. k * (21.86122147463605 * k + 48317.86113160301);
  5605. var g =
  5606. c * (8.841041422036149 * c + 60.118027045597366 * m +
  5607. 6.871425592049007 * y + 31.159100130055922 * k -
  5608. 20220.756542821975) +
  5609. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  5610. 131.35250912493976 * k - 48691.05921601825) +
  5611. y * (4.444339102852739 * y + 9.8632861493405 * k -
  5612. 6341.191035517494) -
  5613. k * (20.737325471181034 * k + 47890.15695978492);
  5614. var b =
  5615. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  5616. 30.89978309703729 * y - 0.23883238689178934 * k -
  5617. 3616.812083916688) +
  5618. m * (10.49593273432072 * m + 63.02378494754052 * y +
  5619. 50.606957656360734 * k - 28620.90484698408) +
  5620. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  5621. 49363.43385999684) -
  5622. k * (22.33816807309886 * k + 45932.16563550634);
  5623. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  5624. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  5625. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  5626. }
  5627. return data;
  5628. },
  5629. getData: function getData(width, height, forceRGBoutput) {
  5630. if (this.numComponents > 4) {
  5631. throw 'Unsupported color mode';
  5632. }
  5633. // type of data: Uint8Array(width * height * numComponents)
  5634. var data = this._getLinearizedBlockData(width, height);
  5635. if (this.numComponents === 3) {
  5636. return this._convertYccToRgb(data);
  5637. } else if (this.numComponents === 4) {
  5638. if (this._isColorConversionNeeded()) {
  5639. if (forceRGBoutput) {
  5640. return this._convertYcckToRgb(data);
  5641. } else {
  5642. return this._convertYcckToCmyk(data);
  5643. }
  5644. } else if (forceRGBoutput) {
  5645. return this._convertCmykToRgb(data);
  5646. }
  5647. }
  5648. return data;
  5649. }
  5650. };
  5651. return constructor;
  5652. })();
  5653. exports.JpegImage = JpegImage;
  5654. }));
  5655. (function (root, factory) {
  5656. {
  5657. factory((root.pdfjsCoreMetrics = {}));
  5658. }
  5659. }(this, function (exports) {
  5660. // The Metrics object contains glyph widths (in glyph space units).
  5661. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  5662. // space unit corresponds to 1/1000th of text space unit.
  5663. var Metrics = {
  5664. 'Courier': 600,
  5665. 'Courier-Bold': 600,
  5666. 'Courier-BoldOblique': 600,
  5667. 'Courier-Oblique': 600,
  5668. 'Helvetica' : {
  5669. 'space': 278,
  5670. 'exclam': 278,
  5671. 'quotedbl': 355,
  5672. 'numbersign': 556,
  5673. 'dollar': 556,
  5674. 'percent': 889,
  5675. 'ampersand': 667,
  5676. 'quoteright': 222,
  5677. 'parenleft': 333,
  5678. 'parenright': 333,
  5679. 'asterisk': 389,
  5680. 'plus': 584,
  5681. 'comma': 278,
  5682. 'hyphen': 333,
  5683. 'period': 278,
  5684. 'slash': 278,
  5685. 'zero': 556,
  5686. 'one': 556,
  5687. 'two': 556,
  5688. 'three': 556,
  5689. 'four': 556,
  5690. 'five': 556,
  5691. 'six': 556,
  5692. 'seven': 556,
  5693. 'eight': 556,
  5694. 'nine': 556,
  5695. 'colon': 278,
  5696. 'semicolon': 278,
  5697. 'less': 584,
  5698. 'equal': 584,
  5699. 'greater': 584,
  5700. 'question': 556,
  5701. 'at': 1015,
  5702. 'A': 667,
  5703. 'B': 667,
  5704. 'C': 722,
  5705. 'D': 722,
  5706. 'E': 667,
  5707. 'F': 611,
  5708. 'G': 778,
  5709. 'H': 722,
  5710. 'I': 278,
  5711. 'J': 500,
  5712. 'K': 667,
  5713. 'L': 556,
  5714. 'M': 833,
  5715. 'N': 722,
  5716. 'O': 778,
  5717. 'P': 667,
  5718. 'Q': 778,
  5719. 'R': 722,
  5720. 'S': 667,
  5721. 'T': 611,
  5722. 'U': 722,
  5723. 'V': 667,
  5724. 'W': 944,
  5725. 'X': 667,
  5726. 'Y': 667,
  5727. 'Z': 611,
  5728. 'bracketleft': 278,
  5729. 'backslash': 278,
  5730. 'bracketright': 278,
  5731. 'asciicircum': 469,
  5732. 'underscore': 556,
  5733. 'quoteleft': 222,
  5734. 'a': 556,
  5735. 'b': 556,
  5736. 'c': 500,
  5737. 'd': 556,
  5738. 'e': 556,
  5739. 'f': 278,
  5740. 'g': 556,
  5741. 'h': 556,
  5742. 'i': 222,
  5743. 'j': 222,
  5744. 'k': 500,
  5745. 'l': 222,
  5746. 'm': 833,
  5747. 'n': 556,
  5748. 'o': 556,
  5749. 'p': 556,
  5750. 'q': 556,
  5751. 'r': 333,
  5752. 's': 500,
  5753. 't': 278,
  5754. 'u': 556,
  5755. 'v': 500,
  5756. 'w': 722,
  5757. 'x': 500,
  5758. 'y': 500,
  5759. 'z': 500,
  5760. 'braceleft': 334,
  5761. 'bar': 260,
  5762. 'braceright': 334,
  5763. 'asciitilde': 584,
  5764. 'exclamdown': 333,
  5765. 'cent': 556,
  5766. 'sterling': 556,
  5767. 'fraction': 167,
  5768. 'yen': 556,
  5769. 'florin': 556,
  5770. 'section': 556,
  5771. 'currency': 556,
  5772. 'quotesingle': 191,
  5773. 'quotedblleft': 333,
  5774. 'guillemotleft': 556,
  5775. 'guilsinglleft': 333,
  5776. 'guilsinglright': 333,
  5777. 'fi': 500,
  5778. 'fl': 500,
  5779. 'endash': 556,
  5780. 'dagger': 556,
  5781. 'daggerdbl': 556,
  5782. 'periodcentered': 278,
  5783. 'paragraph': 537,
  5784. 'bullet': 350,
  5785. 'quotesinglbase': 222,
  5786. 'quotedblbase': 333,
  5787. 'quotedblright': 333,
  5788. 'guillemotright': 556,
  5789. 'ellipsis': 1000,
  5790. 'perthousand': 1000,
  5791. 'questiondown': 611,
  5792. 'grave': 333,
  5793. 'acute': 333,
  5794. 'circumflex': 333,
  5795. 'tilde': 333,
  5796. 'macron': 333,
  5797. 'breve': 333,
  5798. 'dotaccent': 333,
  5799. 'dieresis': 333,
  5800. 'ring': 333,
  5801. 'cedilla': 333,
  5802. 'hungarumlaut': 333,
  5803. 'ogonek': 333,
  5804. 'caron': 333,
  5805. 'emdash': 1000,
  5806. 'AE': 1000,
  5807. 'ordfeminine': 370,
  5808. 'Lslash': 556,
  5809. 'Oslash': 778,
  5810. 'OE': 1000,
  5811. 'ordmasculine': 365,
  5812. 'ae': 889,
  5813. 'dotlessi': 278,
  5814. 'lslash': 222,
  5815. 'oslash': 611,
  5816. 'oe': 944,
  5817. 'germandbls': 611,
  5818. 'Idieresis': 278,
  5819. 'eacute': 556,
  5820. 'abreve': 556,
  5821. 'uhungarumlaut': 556,
  5822. 'ecaron': 556,
  5823. 'Ydieresis': 667,
  5824. 'divide': 584,
  5825. 'Yacute': 667,
  5826. 'Acircumflex': 667,
  5827. 'aacute': 556,
  5828. 'Ucircumflex': 722,
  5829. 'yacute': 500,
  5830. 'scommaaccent': 500,
  5831. 'ecircumflex': 556,
  5832. 'Uring': 722,
  5833. 'Udieresis': 722,
  5834. 'aogonek': 556,
  5835. 'Uacute': 722,
  5836. 'uogonek': 556,
  5837. 'Edieresis': 667,
  5838. 'Dcroat': 722,
  5839. 'commaaccent': 250,
  5840. 'copyright': 737,
  5841. 'Emacron': 667,
  5842. 'ccaron': 500,
  5843. 'aring': 556,
  5844. 'Ncommaaccent': 722,
  5845. 'lacute': 222,
  5846. 'agrave': 556,
  5847. 'Tcommaaccent': 611,
  5848. 'Cacute': 722,
  5849. 'atilde': 556,
  5850. 'Edotaccent': 667,
  5851. 'scaron': 500,
  5852. 'scedilla': 500,
  5853. 'iacute': 278,
  5854. 'lozenge': 471,
  5855. 'Rcaron': 722,
  5856. 'Gcommaaccent': 778,
  5857. 'ucircumflex': 556,
  5858. 'acircumflex': 556,
  5859. 'Amacron': 667,
  5860. 'rcaron': 333,
  5861. 'ccedilla': 500,
  5862. 'Zdotaccent': 611,
  5863. 'Thorn': 667,
  5864. 'Omacron': 778,
  5865. 'Racute': 722,
  5866. 'Sacute': 667,
  5867. 'dcaron': 643,
  5868. 'Umacron': 722,
  5869. 'uring': 556,
  5870. 'threesuperior': 333,
  5871. 'Ograve': 778,
  5872. 'Agrave': 667,
  5873. 'Abreve': 667,
  5874. 'multiply': 584,
  5875. 'uacute': 556,
  5876. 'Tcaron': 611,
  5877. 'partialdiff': 476,
  5878. 'ydieresis': 500,
  5879. 'Nacute': 722,
  5880. 'icircumflex': 278,
  5881. 'Ecircumflex': 667,
  5882. 'adieresis': 556,
  5883. 'edieresis': 556,
  5884. 'cacute': 500,
  5885. 'nacute': 556,
  5886. 'umacron': 556,
  5887. 'Ncaron': 722,
  5888. 'Iacute': 278,
  5889. 'plusminus': 584,
  5890. 'brokenbar': 260,
  5891. 'registered': 737,
  5892. 'Gbreve': 778,
  5893. 'Idotaccent': 278,
  5894. 'summation': 600,
  5895. 'Egrave': 667,
  5896. 'racute': 333,
  5897. 'omacron': 556,
  5898. 'Zacute': 611,
  5899. 'Zcaron': 611,
  5900. 'greaterequal': 549,
  5901. 'Eth': 722,
  5902. 'Ccedilla': 722,
  5903. 'lcommaaccent': 222,
  5904. 'tcaron': 317,
  5905. 'eogonek': 556,
  5906. 'Uogonek': 722,
  5907. 'Aacute': 667,
  5908. 'Adieresis': 667,
  5909. 'egrave': 556,
  5910. 'zacute': 500,
  5911. 'iogonek': 222,
  5912. 'Oacute': 778,
  5913. 'oacute': 556,
  5914. 'amacron': 556,
  5915. 'sacute': 500,
  5916. 'idieresis': 278,
  5917. 'Ocircumflex': 778,
  5918. 'Ugrave': 722,
  5919. 'Delta': 612,
  5920. 'thorn': 556,
  5921. 'twosuperior': 333,
  5922. 'Odieresis': 778,
  5923. 'mu': 556,
  5924. 'igrave': 278,
  5925. 'ohungarumlaut': 556,
  5926. 'Eogonek': 667,
  5927. 'dcroat': 556,
  5928. 'threequarters': 834,
  5929. 'Scedilla': 667,
  5930. 'lcaron': 299,
  5931. 'Kcommaaccent': 667,
  5932. 'Lacute': 556,
  5933. 'trademark': 1000,
  5934. 'edotaccent': 556,
  5935. 'Igrave': 278,
  5936. 'Imacron': 278,
  5937. 'Lcaron': 556,
  5938. 'onehalf': 834,
  5939. 'lessequal': 549,
  5940. 'ocircumflex': 556,
  5941. 'ntilde': 556,
  5942. 'Uhungarumlaut': 722,
  5943. 'Eacute': 667,
  5944. 'emacron': 556,
  5945. 'gbreve': 556,
  5946. 'onequarter': 834,
  5947. 'Scaron': 667,
  5948. 'Scommaaccent': 667,
  5949. 'Ohungarumlaut': 778,
  5950. 'degree': 400,
  5951. 'ograve': 556,
  5952. 'Ccaron': 722,
  5953. 'ugrave': 556,
  5954. 'radical': 453,
  5955. 'Dcaron': 722,
  5956. 'rcommaaccent': 333,
  5957. 'Ntilde': 722,
  5958. 'otilde': 556,
  5959. 'Rcommaaccent': 722,
  5960. 'Lcommaaccent': 556,
  5961. 'Atilde': 667,
  5962. 'Aogonek': 667,
  5963. 'Aring': 667,
  5964. 'Otilde': 778,
  5965. 'zdotaccent': 500,
  5966. 'Ecaron': 667,
  5967. 'Iogonek': 278,
  5968. 'kcommaaccent': 500,
  5969. 'minus': 584,
  5970. 'Icircumflex': 278,
  5971. 'ncaron': 556,
  5972. 'tcommaaccent': 278,
  5973. 'logicalnot': 584,
  5974. 'odieresis': 556,
  5975. 'udieresis': 556,
  5976. 'notequal': 549,
  5977. 'gcommaaccent': 556,
  5978. 'eth': 556,
  5979. 'zcaron': 500,
  5980. 'ncommaaccent': 556,
  5981. 'onesuperior': 333,
  5982. 'imacron': 278,
  5983. 'Euro': 556
  5984. },
  5985. 'Helvetica-Bold': {
  5986. 'space': 278,
  5987. 'exclam': 333,
  5988. 'quotedbl': 474,
  5989. 'numbersign': 556,
  5990. 'dollar': 556,
  5991. 'percent': 889,
  5992. 'ampersand': 722,
  5993. 'quoteright': 278,
  5994. 'parenleft': 333,
  5995. 'parenright': 333,
  5996. 'asterisk': 389,
  5997. 'plus': 584,
  5998. 'comma': 278,
  5999. 'hyphen': 333,
  6000. 'period': 278,
  6001. 'slash': 278,
  6002. 'zero': 556,
  6003. 'one': 556,
  6004. 'two': 556,
  6005. 'three': 556,
  6006. 'four': 556,
  6007. 'five': 556,
  6008. 'six': 556,
  6009. 'seven': 556,
  6010. 'eight': 556,
  6011. 'nine': 556,
  6012. 'colon': 333,
  6013. 'semicolon': 333,
  6014. 'less': 584,
  6015. 'equal': 584,
  6016. 'greater': 584,
  6017. 'question': 611,
  6018. 'at': 975,
  6019. 'A': 722,
  6020. 'B': 722,
  6021. 'C': 722,
  6022. 'D': 722,
  6023. 'E': 667,
  6024. 'F': 611,
  6025. 'G': 778,
  6026. 'H': 722,
  6027. 'I': 278,
  6028. 'J': 556,
  6029. 'K': 722,
  6030. 'L': 611,
  6031. 'M': 833,
  6032. 'N': 722,
  6033. 'O': 778,
  6034. 'P': 667,
  6035. 'Q': 778,
  6036. 'R': 722,
  6037. 'S': 667,
  6038. 'T': 611,
  6039. 'U': 722,
  6040. 'V': 667,
  6041. 'W': 944,
  6042. 'X': 667,
  6043. 'Y': 667,
  6044. 'Z': 611,
  6045. 'bracketleft': 333,
  6046. 'backslash': 278,
  6047. 'bracketright': 333,
  6048. 'asciicircum': 584,
  6049. 'underscore': 556,
  6050. 'quoteleft': 278,
  6051. 'a': 556,
  6052. 'b': 611,
  6053. 'c': 556,
  6054. 'd': 611,
  6055. 'e': 556,
  6056. 'f': 333,
  6057. 'g': 611,
  6058. 'h': 611,
  6059. 'i': 278,
  6060. 'j': 278,
  6061. 'k': 556,
  6062. 'l': 278,
  6063. 'm': 889,
  6064. 'n': 611,
  6065. 'o': 611,
  6066. 'p': 611,
  6067. 'q': 611,
  6068. 'r': 389,
  6069. 's': 556,
  6070. 't': 333,
  6071. 'u': 611,
  6072. 'v': 556,
  6073. 'w': 778,
  6074. 'x': 556,
  6075. 'y': 556,
  6076. 'z': 500,
  6077. 'braceleft': 389,
  6078. 'bar': 280,
  6079. 'braceright': 389,
  6080. 'asciitilde': 584,
  6081. 'exclamdown': 333,
  6082. 'cent': 556,
  6083. 'sterling': 556,
  6084. 'fraction': 167,
  6085. 'yen': 556,
  6086. 'florin': 556,
  6087. 'section': 556,
  6088. 'currency': 556,
  6089. 'quotesingle': 238,
  6090. 'quotedblleft': 500,
  6091. 'guillemotleft': 556,
  6092. 'guilsinglleft': 333,
  6093. 'guilsinglright': 333,
  6094. 'fi': 611,
  6095. 'fl': 611,
  6096. 'endash': 556,
  6097. 'dagger': 556,
  6098. 'daggerdbl': 556,
  6099. 'periodcentered': 278,
  6100. 'paragraph': 556,
  6101. 'bullet': 350,
  6102. 'quotesinglbase': 278,
  6103. 'quotedblbase': 500,
  6104. 'quotedblright': 500,
  6105. 'guillemotright': 556,
  6106. 'ellipsis': 1000,
  6107. 'perthousand': 1000,
  6108. 'questiondown': 611,
  6109. 'grave': 333,
  6110. 'acute': 333,
  6111. 'circumflex': 333,
  6112. 'tilde': 333,
  6113. 'macron': 333,
  6114. 'breve': 333,
  6115. 'dotaccent': 333,
  6116. 'dieresis': 333,
  6117. 'ring': 333,
  6118. 'cedilla': 333,
  6119. 'hungarumlaut': 333,
  6120. 'ogonek': 333,
  6121. 'caron': 333,
  6122. 'emdash': 1000,
  6123. 'AE': 1000,
  6124. 'ordfeminine': 370,
  6125. 'Lslash': 611,
  6126. 'Oslash': 778,
  6127. 'OE': 1000,
  6128. 'ordmasculine': 365,
  6129. 'ae': 889,
  6130. 'dotlessi': 278,
  6131. 'lslash': 278,
  6132. 'oslash': 611,
  6133. 'oe': 944,
  6134. 'germandbls': 611,
  6135. 'Idieresis': 278,
  6136. 'eacute': 556,
  6137. 'abreve': 556,
  6138. 'uhungarumlaut': 611,
  6139. 'ecaron': 556,
  6140. 'Ydieresis': 667,
  6141. 'divide': 584,
  6142. 'Yacute': 667,
  6143. 'Acircumflex': 722,
  6144. 'aacute': 556,
  6145. 'Ucircumflex': 722,
  6146. 'yacute': 556,
  6147. 'scommaaccent': 556,
  6148. 'ecircumflex': 556,
  6149. 'Uring': 722,
  6150. 'Udieresis': 722,
  6151. 'aogonek': 556,
  6152. 'Uacute': 722,
  6153. 'uogonek': 611,
  6154. 'Edieresis': 667,
  6155. 'Dcroat': 722,
  6156. 'commaaccent': 250,
  6157. 'copyright': 737,
  6158. 'Emacron': 667,
  6159. 'ccaron': 556,
  6160. 'aring': 556,
  6161. 'Ncommaaccent': 722,
  6162. 'lacute': 278,
  6163. 'agrave': 556,
  6164. 'Tcommaaccent': 611,
  6165. 'Cacute': 722,
  6166. 'atilde': 556,
  6167. 'Edotaccent': 667,
  6168. 'scaron': 556,
  6169. 'scedilla': 556,
  6170. 'iacute': 278,
  6171. 'lozenge': 494,
  6172. 'Rcaron': 722,
  6173. 'Gcommaaccent': 778,
  6174. 'ucircumflex': 611,
  6175. 'acircumflex': 556,
  6176. 'Amacron': 722,
  6177. 'rcaron': 389,
  6178. 'ccedilla': 556,
  6179. 'Zdotaccent': 611,
  6180. 'Thorn': 667,
  6181. 'Omacron': 778,
  6182. 'Racute': 722,
  6183. 'Sacute': 667,
  6184. 'dcaron': 743,
  6185. 'Umacron': 722,
  6186. 'uring': 611,
  6187. 'threesuperior': 333,
  6188. 'Ograve': 778,
  6189. 'Agrave': 722,
  6190. 'Abreve': 722,
  6191. 'multiply': 584,
  6192. 'uacute': 611,
  6193. 'Tcaron': 611,
  6194. 'partialdiff': 494,
  6195. 'ydieresis': 556,
  6196. 'Nacute': 722,
  6197. 'icircumflex': 278,
  6198. 'Ecircumflex': 667,
  6199. 'adieresis': 556,
  6200. 'edieresis': 556,
  6201. 'cacute': 556,
  6202. 'nacute': 611,
  6203. 'umacron': 611,
  6204. 'Ncaron': 722,
  6205. 'Iacute': 278,
  6206. 'plusminus': 584,
  6207. 'brokenbar': 280,
  6208. 'registered': 737,
  6209. 'Gbreve': 778,
  6210. 'Idotaccent': 278,
  6211. 'summation': 600,
  6212. 'Egrave': 667,
  6213. 'racute': 389,
  6214. 'omacron': 611,
  6215. 'Zacute': 611,
  6216. 'Zcaron': 611,
  6217. 'greaterequal': 549,
  6218. 'Eth': 722,
  6219. 'Ccedilla': 722,
  6220. 'lcommaaccent': 278,
  6221. 'tcaron': 389,
  6222. 'eogonek': 556,
  6223. 'Uogonek': 722,
  6224. 'Aacute': 722,
  6225. 'Adieresis': 722,
  6226. 'egrave': 556,
  6227. 'zacute': 500,
  6228. 'iogonek': 278,
  6229. 'Oacute': 778,
  6230. 'oacute': 611,
  6231. 'amacron': 556,
  6232. 'sacute': 556,
  6233. 'idieresis': 278,
  6234. 'Ocircumflex': 778,
  6235. 'Ugrave': 722,
  6236. 'Delta': 612,
  6237. 'thorn': 611,
  6238. 'twosuperior': 333,
  6239. 'Odieresis': 778,
  6240. 'mu': 611,
  6241. 'igrave': 278,
  6242. 'ohungarumlaut': 611,
  6243. 'Eogonek': 667,
  6244. 'dcroat': 611,
  6245. 'threequarters': 834,
  6246. 'Scedilla': 667,
  6247. 'lcaron': 400,
  6248. 'Kcommaaccent': 722,
  6249. 'Lacute': 611,
  6250. 'trademark': 1000,
  6251. 'edotaccent': 556,
  6252. 'Igrave': 278,
  6253. 'Imacron': 278,
  6254. 'Lcaron': 611,
  6255. 'onehalf': 834,
  6256. 'lessequal': 549,
  6257. 'ocircumflex': 611,
  6258. 'ntilde': 611,
  6259. 'Uhungarumlaut': 722,
  6260. 'Eacute': 667,
  6261. 'emacron': 556,
  6262. 'gbreve': 611,
  6263. 'onequarter': 834,
  6264. 'Scaron': 667,
  6265. 'Scommaaccent': 667,
  6266. 'Ohungarumlaut': 778,
  6267. 'degree': 400,
  6268. 'ograve': 611,
  6269. 'Ccaron': 722,
  6270. 'ugrave': 611,
  6271. 'radical': 549,
  6272. 'Dcaron': 722,
  6273. 'rcommaaccent': 389,
  6274. 'Ntilde': 722,
  6275. 'otilde': 611,
  6276. 'Rcommaaccent': 722,
  6277. 'Lcommaaccent': 611,
  6278. 'Atilde': 722,
  6279. 'Aogonek': 722,
  6280. 'Aring': 722,
  6281. 'Otilde': 778,
  6282. 'zdotaccent': 500,
  6283. 'Ecaron': 667,
  6284. 'Iogonek': 278,
  6285. 'kcommaaccent': 556,
  6286. 'minus': 584,
  6287. 'Icircumflex': 278,
  6288. 'ncaron': 611,
  6289. 'tcommaaccent': 333,
  6290. 'logicalnot': 584,
  6291. 'odieresis': 611,
  6292. 'udieresis': 611,
  6293. 'notequal': 549,
  6294. 'gcommaaccent': 611,
  6295. 'eth': 611,
  6296. 'zcaron': 500,
  6297. 'ncommaaccent': 611,
  6298. 'onesuperior': 333,
  6299. 'imacron': 278,
  6300. 'Euro': 556
  6301. },
  6302. 'Helvetica-BoldOblique': {
  6303. 'space': 278,
  6304. 'exclam': 333,
  6305. 'quotedbl': 474,
  6306. 'numbersign': 556,
  6307. 'dollar': 556,
  6308. 'percent': 889,
  6309. 'ampersand': 722,
  6310. 'quoteright': 278,
  6311. 'parenleft': 333,
  6312. 'parenright': 333,
  6313. 'asterisk': 389,
  6314. 'plus': 584,
  6315. 'comma': 278,
  6316. 'hyphen': 333,
  6317. 'period': 278,
  6318. 'slash': 278,
  6319. 'zero': 556,
  6320. 'one': 556,
  6321. 'two': 556,
  6322. 'three': 556,
  6323. 'four': 556,
  6324. 'five': 556,
  6325. 'six': 556,
  6326. 'seven': 556,
  6327. 'eight': 556,
  6328. 'nine': 556,
  6329. 'colon': 333,
  6330. 'semicolon': 333,
  6331. 'less': 584,
  6332. 'equal': 584,
  6333. 'greater': 584,
  6334. 'question': 611,
  6335. 'at': 975,
  6336. 'A': 722,
  6337. 'B': 722,
  6338. 'C': 722,
  6339. 'D': 722,
  6340. 'E': 667,
  6341. 'F': 611,
  6342. 'G': 778,
  6343. 'H': 722,
  6344. 'I': 278,
  6345. 'J': 556,
  6346. 'K': 722,
  6347. 'L': 611,
  6348. 'M': 833,
  6349. 'N': 722,
  6350. 'O': 778,
  6351. 'P': 667,
  6352. 'Q': 778,
  6353. 'R': 722,
  6354. 'S': 667,
  6355. 'T': 611,
  6356. 'U': 722,
  6357. 'V': 667,
  6358. 'W': 944,
  6359. 'X': 667,
  6360. 'Y': 667,
  6361. 'Z': 611,
  6362. 'bracketleft': 333,
  6363. 'backslash': 278,
  6364. 'bracketright': 333,
  6365. 'asciicircum': 584,
  6366. 'underscore': 556,
  6367. 'quoteleft': 278,
  6368. 'a': 556,
  6369. 'b': 611,
  6370. 'c': 556,
  6371. 'd': 611,
  6372. 'e': 556,
  6373. 'f': 333,
  6374. 'g': 611,
  6375. 'h': 611,
  6376. 'i': 278,
  6377. 'j': 278,
  6378. 'k': 556,
  6379. 'l': 278,
  6380. 'm': 889,
  6381. 'n': 611,
  6382. 'o': 611,
  6383. 'p': 611,
  6384. 'q': 611,
  6385. 'r': 389,
  6386. 's': 556,
  6387. 't': 333,
  6388. 'u': 611,
  6389. 'v': 556,
  6390. 'w': 778,
  6391. 'x': 556,
  6392. 'y': 556,
  6393. 'z': 500,
  6394. 'braceleft': 389,
  6395. 'bar': 280,
  6396. 'braceright': 389,
  6397. 'asciitilde': 584,
  6398. 'exclamdown': 333,
  6399. 'cent': 556,
  6400. 'sterling': 556,
  6401. 'fraction': 167,
  6402. 'yen': 556,
  6403. 'florin': 556,
  6404. 'section': 556,
  6405. 'currency': 556,
  6406. 'quotesingle': 238,
  6407. 'quotedblleft': 500,
  6408. 'guillemotleft': 556,
  6409. 'guilsinglleft': 333,
  6410. 'guilsinglright': 333,
  6411. 'fi': 611,
  6412. 'fl': 611,
  6413. 'endash': 556,
  6414. 'dagger': 556,
  6415. 'daggerdbl': 556,
  6416. 'periodcentered': 278,
  6417. 'paragraph': 556,
  6418. 'bullet': 350,
  6419. 'quotesinglbase': 278,
  6420. 'quotedblbase': 500,
  6421. 'quotedblright': 500,
  6422. 'guillemotright': 556,
  6423. 'ellipsis': 1000,
  6424. 'perthousand': 1000,
  6425. 'questiondown': 611,
  6426. 'grave': 333,
  6427. 'acute': 333,
  6428. 'circumflex': 333,
  6429. 'tilde': 333,
  6430. 'macron': 333,
  6431. 'breve': 333,
  6432. 'dotaccent': 333,
  6433. 'dieresis': 333,
  6434. 'ring': 333,
  6435. 'cedilla': 333,
  6436. 'hungarumlaut': 333,
  6437. 'ogonek': 333,
  6438. 'caron': 333,
  6439. 'emdash': 1000,
  6440. 'AE': 1000,
  6441. 'ordfeminine': 370,
  6442. 'Lslash': 611,
  6443. 'Oslash': 778,
  6444. 'OE': 1000,
  6445. 'ordmasculine': 365,
  6446. 'ae': 889,
  6447. 'dotlessi': 278,
  6448. 'lslash': 278,
  6449. 'oslash': 611,
  6450. 'oe': 944,
  6451. 'germandbls': 611,
  6452. 'Idieresis': 278,
  6453. 'eacute': 556,
  6454. 'abreve': 556,
  6455. 'uhungarumlaut': 611,
  6456. 'ecaron': 556,
  6457. 'Ydieresis': 667,
  6458. 'divide': 584,
  6459. 'Yacute': 667,
  6460. 'Acircumflex': 722,
  6461. 'aacute': 556,
  6462. 'Ucircumflex': 722,
  6463. 'yacute': 556,
  6464. 'scommaaccent': 556,
  6465. 'ecircumflex': 556,
  6466. 'Uring': 722,
  6467. 'Udieresis': 722,
  6468. 'aogonek': 556,
  6469. 'Uacute': 722,
  6470. 'uogonek': 611,
  6471. 'Edieresis': 667,
  6472. 'Dcroat': 722,
  6473. 'commaaccent': 250,
  6474. 'copyright': 737,
  6475. 'Emacron': 667,
  6476. 'ccaron': 556,
  6477. 'aring': 556,
  6478. 'Ncommaaccent': 722,
  6479. 'lacute': 278,
  6480. 'agrave': 556,
  6481. 'Tcommaaccent': 611,
  6482. 'Cacute': 722,
  6483. 'atilde': 556,
  6484. 'Edotaccent': 667,
  6485. 'scaron': 556,
  6486. 'scedilla': 556,
  6487. 'iacute': 278,
  6488. 'lozenge': 494,
  6489. 'Rcaron': 722,
  6490. 'Gcommaaccent': 778,
  6491. 'ucircumflex': 611,
  6492. 'acircumflex': 556,
  6493. 'Amacron': 722,
  6494. 'rcaron': 389,
  6495. 'ccedilla': 556,
  6496. 'Zdotaccent': 611,
  6497. 'Thorn': 667,
  6498. 'Omacron': 778,
  6499. 'Racute': 722,
  6500. 'Sacute': 667,
  6501. 'dcaron': 743,
  6502. 'Umacron': 722,
  6503. 'uring': 611,
  6504. 'threesuperior': 333,
  6505. 'Ograve': 778,
  6506. 'Agrave': 722,
  6507. 'Abreve': 722,
  6508. 'multiply': 584,
  6509. 'uacute': 611,
  6510. 'Tcaron': 611,
  6511. 'partialdiff': 494,
  6512. 'ydieresis': 556,
  6513. 'Nacute': 722,
  6514. 'icircumflex': 278,
  6515. 'Ecircumflex': 667,
  6516. 'adieresis': 556,
  6517. 'edieresis': 556,
  6518. 'cacute': 556,
  6519. 'nacute': 611,
  6520. 'umacron': 611,
  6521. 'Ncaron': 722,
  6522. 'Iacute': 278,
  6523. 'plusminus': 584,
  6524. 'brokenbar': 280,
  6525. 'registered': 737,
  6526. 'Gbreve': 778,
  6527. 'Idotaccent': 278,
  6528. 'summation': 600,
  6529. 'Egrave': 667,
  6530. 'racute': 389,
  6531. 'omacron': 611,
  6532. 'Zacute': 611,
  6533. 'Zcaron': 611,
  6534. 'greaterequal': 549,
  6535. 'Eth': 722,
  6536. 'Ccedilla': 722,
  6537. 'lcommaaccent': 278,
  6538. 'tcaron': 389,
  6539. 'eogonek': 556,
  6540. 'Uogonek': 722,
  6541. 'Aacute': 722,
  6542. 'Adieresis': 722,
  6543. 'egrave': 556,
  6544. 'zacute': 500,
  6545. 'iogonek': 278,
  6546. 'Oacute': 778,
  6547. 'oacute': 611,
  6548. 'amacron': 556,
  6549. 'sacute': 556,
  6550. 'idieresis': 278,
  6551. 'Ocircumflex': 778,
  6552. 'Ugrave': 722,
  6553. 'Delta': 612,
  6554. 'thorn': 611,
  6555. 'twosuperior': 333,
  6556. 'Odieresis': 778,
  6557. 'mu': 611,
  6558. 'igrave': 278,
  6559. 'ohungarumlaut': 611,
  6560. 'Eogonek': 667,
  6561. 'dcroat': 611,
  6562. 'threequarters': 834,
  6563. 'Scedilla': 667,
  6564. 'lcaron': 400,
  6565. 'Kcommaaccent': 722,
  6566. 'Lacute': 611,
  6567. 'trademark': 1000,
  6568. 'edotaccent': 556,
  6569. 'Igrave': 278,
  6570. 'Imacron': 278,
  6571. 'Lcaron': 611,
  6572. 'onehalf': 834,
  6573. 'lessequal': 549,
  6574. 'ocircumflex': 611,
  6575. 'ntilde': 611,
  6576. 'Uhungarumlaut': 722,
  6577. 'Eacute': 667,
  6578. 'emacron': 556,
  6579. 'gbreve': 611,
  6580. 'onequarter': 834,
  6581. 'Scaron': 667,
  6582. 'Scommaaccent': 667,
  6583. 'Ohungarumlaut': 778,
  6584. 'degree': 400,
  6585. 'ograve': 611,
  6586. 'Ccaron': 722,
  6587. 'ugrave': 611,
  6588. 'radical': 549,
  6589. 'Dcaron': 722,
  6590. 'rcommaaccent': 389,
  6591. 'Ntilde': 722,
  6592. 'otilde': 611,
  6593. 'Rcommaaccent': 722,
  6594. 'Lcommaaccent': 611,
  6595. 'Atilde': 722,
  6596. 'Aogonek': 722,
  6597. 'Aring': 722,
  6598. 'Otilde': 778,
  6599. 'zdotaccent': 500,
  6600. 'Ecaron': 667,
  6601. 'Iogonek': 278,
  6602. 'kcommaaccent': 556,
  6603. 'minus': 584,
  6604. 'Icircumflex': 278,
  6605. 'ncaron': 611,
  6606. 'tcommaaccent': 333,
  6607. 'logicalnot': 584,
  6608. 'odieresis': 611,
  6609. 'udieresis': 611,
  6610. 'notequal': 549,
  6611. 'gcommaaccent': 611,
  6612. 'eth': 611,
  6613. 'zcaron': 500,
  6614. 'ncommaaccent': 611,
  6615. 'onesuperior': 333,
  6616. 'imacron': 278,
  6617. 'Euro': 556
  6618. },
  6619. 'Helvetica-Oblique' : {
  6620. 'space': 278,
  6621. 'exclam': 278,
  6622. 'quotedbl': 355,
  6623. 'numbersign': 556,
  6624. 'dollar': 556,
  6625. 'percent': 889,
  6626. 'ampersand': 667,
  6627. 'quoteright': 222,
  6628. 'parenleft': 333,
  6629. 'parenright': 333,
  6630. 'asterisk': 389,
  6631. 'plus': 584,
  6632. 'comma': 278,
  6633. 'hyphen': 333,
  6634. 'period': 278,
  6635. 'slash': 278,
  6636. 'zero': 556,
  6637. 'one': 556,
  6638. 'two': 556,
  6639. 'three': 556,
  6640. 'four': 556,
  6641. 'five': 556,
  6642. 'six': 556,
  6643. 'seven': 556,
  6644. 'eight': 556,
  6645. 'nine': 556,
  6646. 'colon': 278,
  6647. 'semicolon': 278,
  6648. 'less': 584,
  6649. 'equal': 584,
  6650. 'greater': 584,
  6651. 'question': 556,
  6652. 'at': 1015,
  6653. 'A': 667,
  6654. 'B': 667,
  6655. 'C': 722,
  6656. 'D': 722,
  6657. 'E': 667,
  6658. 'F': 611,
  6659. 'G': 778,
  6660. 'H': 722,
  6661. 'I': 278,
  6662. 'J': 500,
  6663. 'K': 667,
  6664. 'L': 556,
  6665. 'M': 833,
  6666. 'N': 722,
  6667. 'O': 778,
  6668. 'P': 667,
  6669. 'Q': 778,
  6670. 'R': 722,
  6671. 'S': 667,
  6672. 'T': 611,
  6673. 'U': 722,
  6674. 'V': 667,
  6675. 'W': 944,
  6676. 'X': 667,
  6677. 'Y': 667,
  6678. 'Z': 611,
  6679. 'bracketleft': 278,
  6680. 'backslash': 278,
  6681. 'bracketright': 278,
  6682. 'asciicircum': 469,
  6683. 'underscore': 556,
  6684. 'quoteleft': 222,
  6685. 'a': 556,
  6686. 'b': 556,
  6687. 'c': 500,
  6688. 'd': 556,
  6689. 'e': 556,
  6690. 'f': 278,
  6691. 'g': 556,
  6692. 'h': 556,
  6693. 'i': 222,
  6694. 'j': 222,
  6695. 'k': 500,
  6696. 'l': 222,
  6697. 'm': 833,
  6698. 'n': 556,
  6699. 'o': 556,
  6700. 'p': 556,
  6701. 'q': 556,
  6702. 'r': 333,
  6703. 's': 500,
  6704. 't': 278,
  6705. 'u': 556,
  6706. 'v': 500,
  6707. 'w': 722,
  6708. 'x': 500,
  6709. 'y': 500,
  6710. 'z': 500,
  6711. 'braceleft': 334,
  6712. 'bar': 260,
  6713. 'braceright': 334,
  6714. 'asciitilde': 584,
  6715. 'exclamdown': 333,
  6716. 'cent': 556,
  6717. 'sterling': 556,
  6718. 'fraction': 167,
  6719. 'yen': 556,
  6720. 'florin': 556,
  6721. 'section': 556,
  6722. 'currency': 556,
  6723. 'quotesingle': 191,
  6724. 'quotedblleft': 333,
  6725. 'guillemotleft': 556,
  6726. 'guilsinglleft': 333,
  6727. 'guilsinglright': 333,
  6728. 'fi': 500,
  6729. 'fl': 500,
  6730. 'endash': 556,
  6731. 'dagger': 556,
  6732. 'daggerdbl': 556,
  6733. 'periodcentered': 278,
  6734. 'paragraph': 537,
  6735. 'bullet': 350,
  6736. 'quotesinglbase': 222,
  6737. 'quotedblbase': 333,
  6738. 'quotedblright': 333,
  6739. 'guillemotright': 556,
  6740. 'ellipsis': 1000,
  6741. 'perthousand': 1000,
  6742. 'questiondown': 611,
  6743. 'grave': 333,
  6744. 'acute': 333,
  6745. 'circumflex': 333,
  6746. 'tilde': 333,
  6747. 'macron': 333,
  6748. 'breve': 333,
  6749. 'dotaccent': 333,
  6750. 'dieresis': 333,
  6751. 'ring': 333,
  6752. 'cedilla': 333,
  6753. 'hungarumlaut': 333,
  6754. 'ogonek': 333,
  6755. 'caron': 333,
  6756. 'emdash': 1000,
  6757. 'AE': 1000,
  6758. 'ordfeminine': 370,
  6759. 'Lslash': 556,
  6760. 'Oslash': 778,
  6761. 'OE': 1000,
  6762. 'ordmasculine': 365,
  6763. 'ae': 889,
  6764. 'dotlessi': 278,
  6765. 'lslash': 222,
  6766. 'oslash': 611,
  6767. 'oe': 944,
  6768. 'germandbls': 611,
  6769. 'Idieresis': 278,
  6770. 'eacute': 556,
  6771. 'abreve': 556,
  6772. 'uhungarumlaut': 556,
  6773. 'ecaron': 556,
  6774. 'Ydieresis': 667,
  6775. 'divide': 584,
  6776. 'Yacute': 667,
  6777. 'Acircumflex': 667,
  6778. 'aacute': 556,
  6779. 'Ucircumflex': 722,
  6780. 'yacute': 500,
  6781. 'scommaaccent': 500,
  6782. 'ecircumflex': 556,
  6783. 'Uring': 722,
  6784. 'Udieresis': 722,
  6785. 'aogonek': 556,
  6786. 'Uacute': 722,
  6787. 'uogonek': 556,
  6788. 'Edieresis': 667,
  6789. 'Dcroat': 722,
  6790. 'commaaccent': 250,
  6791. 'copyright': 737,
  6792. 'Emacron': 667,
  6793. 'ccaron': 500,
  6794. 'aring': 556,
  6795. 'Ncommaaccent': 722,
  6796. 'lacute': 222,
  6797. 'agrave': 556,
  6798. 'Tcommaaccent': 611,
  6799. 'Cacute': 722,
  6800. 'atilde': 556,
  6801. 'Edotaccent': 667,
  6802. 'scaron': 500,
  6803. 'scedilla': 500,
  6804. 'iacute': 278,
  6805. 'lozenge': 471,
  6806. 'Rcaron': 722,
  6807. 'Gcommaaccent': 778,
  6808. 'ucircumflex': 556,
  6809. 'acircumflex': 556,
  6810. 'Amacron': 667,
  6811. 'rcaron': 333,
  6812. 'ccedilla': 500,
  6813. 'Zdotaccent': 611,
  6814. 'Thorn': 667,
  6815. 'Omacron': 778,
  6816. 'Racute': 722,
  6817. 'Sacute': 667,
  6818. 'dcaron': 643,
  6819. 'Umacron': 722,
  6820. 'uring': 556,
  6821. 'threesuperior': 333,
  6822. 'Ograve': 778,
  6823. 'Agrave': 667,
  6824. 'Abreve': 667,
  6825. 'multiply': 584,
  6826. 'uacute': 556,
  6827. 'Tcaron': 611,
  6828. 'partialdiff': 476,
  6829. 'ydieresis': 500,
  6830. 'Nacute': 722,
  6831. 'icircumflex': 278,
  6832. 'Ecircumflex': 667,
  6833. 'adieresis': 556,
  6834. 'edieresis': 556,
  6835. 'cacute': 500,
  6836. 'nacute': 556,
  6837. 'umacron': 556,
  6838. 'Ncaron': 722,
  6839. 'Iacute': 278,
  6840. 'plusminus': 584,
  6841. 'brokenbar': 260,
  6842. 'registered': 737,
  6843. 'Gbreve': 778,
  6844. 'Idotaccent': 278,
  6845. 'summation': 600,
  6846. 'Egrave': 667,
  6847. 'racute': 333,
  6848. 'omacron': 556,
  6849. 'Zacute': 611,
  6850. 'Zcaron': 611,
  6851. 'greaterequal': 549,
  6852. 'Eth': 722,
  6853. 'Ccedilla': 722,
  6854. 'lcommaaccent': 222,
  6855. 'tcaron': 317,
  6856. 'eogonek': 556,
  6857. 'Uogonek': 722,
  6858. 'Aacute': 667,
  6859. 'Adieresis': 667,
  6860. 'egrave': 556,
  6861. 'zacute': 500,
  6862. 'iogonek': 222,
  6863. 'Oacute': 778,
  6864. 'oacute': 556,
  6865. 'amacron': 556,
  6866. 'sacute': 500,
  6867. 'idieresis': 278,
  6868. 'Ocircumflex': 778,
  6869. 'Ugrave': 722,
  6870. 'Delta': 612,
  6871. 'thorn': 556,
  6872. 'twosuperior': 333,
  6873. 'Odieresis': 778,
  6874. 'mu': 556,
  6875. 'igrave': 278,
  6876. 'ohungarumlaut': 556,
  6877. 'Eogonek': 667,
  6878. 'dcroat': 556,
  6879. 'threequarters': 834,
  6880. 'Scedilla': 667,
  6881. 'lcaron': 299,
  6882. 'Kcommaaccent': 667,
  6883. 'Lacute': 556,
  6884. 'trademark': 1000,
  6885. 'edotaccent': 556,
  6886. 'Igrave': 278,
  6887. 'Imacron': 278,
  6888. 'Lcaron': 556,
  6889. 'onehalf': 834,
  6890. 'lessequal': 549,
  6891. 'ocircumflex': 556,
  6892. 'ntilde': 556,
  6893. 'Uhungarumlaut': 722,
  6894. 'Eacute': 667,
  6895. 'emacron': 556,
  6896. 'gbreve': 556,
  6897. 'onequarter': 834,
  6898. 'Scaron': 667,
  6899. 'Scommaaccent': 667,
  6900. 'Ohungarumlaut': 778,
  6901. 'degree': 400,
  6902. 'ograve': 556,
  6903. 'Ccaron': 722,
  6904. 'ugrave': 556,
  6905. 'radical': 453,
  6906. 'Dcaron': 722,
  6907. 'rcommaaccent': 333,
  6908. 'Ntilde': 722,
  6909. 'otilde': 556,
  6910. 'Rcommaaccent': 722,
  6911. 'Lcommaaccent': 556,
  6912. 'Atilde': 667,
  6913. 'Aogonek': 667,
  6914. 'Aring': 667,
  6915. 'Otilde': 778,
  6916. 'zdotaccent': 500,
  6917. 'Ecaron': 667,
  6918. 'Iogonek': 278,
  6919. 'kcommaaccent': 500,
  6920. 'minus': 584,
  6921. 'Icircumflex': 278,
  6922. 'ncaron': 556,
  6923. 'tcommaaccent': 278,
  6924. 'logicalnot': 584,
  6925. 'odieresis': 556,
  6926. 'udieresis': 556,
  6927. 'notequal': 549,
  6928. 'gcommaaccent': 556,
  6929. 'eth': 556,
  6930. 'zcaron': 500,
  6931. 'ncommaaccent': 556,
  6932. 'onesuperior': 333,
  6933. 'imacron': 278,
  6934. 'Euro': 556
  6935. },
  6936. 'Symbol': {
  6937. 'space': 250,
  6938. 'exclam': 333,
  6939. 'universal': 713,
  6940. 'numbersign': 500,
  6941. 'existential': 549,
  6942. 'percent': 833,
  6943. 'ampersand': 778,
  6944. 'suchthat': 439,
  6945. 'parenleft': 333,
  6946. 'parenright': 333,
  6947. 'asteriskmath': 500,
  6948. 'plus': 549,
  6949. 'comma': 250,
  6950. 'minus': 549,
  6951. 'period': 250,
  6952. 'slash': 278,
  6953. 'zero': 500,
  6954. 'one': 500,
  6955. 'two': 500,
  6956. 'three': 500,
  6957. 'four': 500,
  6958. 'five': 500,
  6959. 'six': 500,
  6960. 'seven': 500,
  6961. 'eight': 500,
  6962. 'nine': 500,
  6963. 'colon': 278,
  6964. 'semicolon': 278,
  6965. 'less': 549,
  6966. 'equal': 549,
  6967. 'greater': 549,
  6968. 'question': 444,
  6969. 'congruent': 549,
  6970. 'Alpha': 722,
  6971. 'Beta': 667,
  6972. 'Chi': 722,
  6973. 'Delta': 612,
  6974. 'Epsilon': 611,
  6975. 'Phi': 763,
  6976. 'Gamma': 603,
  6977. 'Eta': 722,
  6978. 'Iota': 333,
  6979. 'theta1': 631,
  6980. 'Kappa': 722,
  6981. 'Lambda': 686,
  6982. 'Mu': 889,
  6983. 'Nu': 722,
  6984. 'Omicron': 722,
  6985. 'Pi': 768,
  6986. 'Theta': 741,
  6987. 'Rho': 556,
  6988. 'Sigma': 592,
  6989. 'Tau': 611,
  6990. 'Upsilon': 690,
  6991. 'sigma1': 439,
  6992. 'Omega': 768,
  6993. 'Xi': 645,
  6994. 'Psi': 795,
  6995. 'Zeta': 611,
  6996. 'bracketleft': 333,
  6997. 'therefore': 863,
  6998. 'bracketright': 333,
  6999. 'perpendicular': 658,
  7000. 'underscore': 500,
  7001. 'radicalex': 500,
  7002. 'alpha': 631,
  7003. 'beta': 549,
  7004. 'chi': 549,
  7005. 'delta': 494,
  7006. 'epsilon': 439,
  7007. 'phi': 521,
  7008. 'gamma': 411,
  7009. 'eta': 603,
  7010. 'iota': 329,
  7011. 'phi1': 603,
  7012. 'kappa': 549,
  7013. 'lambda': 549,
  7014. 'mu': 576,
  7015. 'nu': 521,
  7016. 'omicron': 549,
  7017. 'pi': 549,
  7018. 'theta': 521,
  7019. 'rho': 549,
  7020. 'sigma': 603,
  7021. 'tau': 439,
  7022. 'upsilon': 576,
  7023. 'omega1': 713,
  7024. 'omega': 686,
  7025. 'xi': 493,
  7026. 'psi': 686,
  7027. 'zeta': 494,
  7028. 'braceleft': 480,
  7029. 'bar': 200,
  7030. 'braceright': 480,
  7031. 'similar': 549,
  7032. 'Euro': 750,
  7033. 'Upsilon1': 620,
  7034. 'minute': 247,
  7035. 'lessequal': 549,
  7036. 'fraction': 167,
  7037. 'infinity': 713,
  7038. 'florin': 500,
  7039. 'club': 753,
  7040. 'diamond': 753,
  7041. 'heart': 753,
  7042. 'spade': 753,
  7043. 'arrowboth': 1042,
  7044. 'arrowleft': 987,
  7045. 'arrowup': 603,
  7046. 'arrowright': 987,
  7047. 'arrowdown': 603,
  7048. 'degree': 400,
  7049. 'plusminus': 549,
  7050. 'second': 411,
  7051. 'greaterequal': 549,
  7052. 'multiply': 549,
  7053. 'proportional': 713,
  7054. 'partialdiff': 494,
  7055. 'bullet': 460,
  7056. 'divide': 549,
  7057. 'notequal': 549,
  7058. 'equivalence': 549,
  7059. 'approxequal': 549,
  7060. 'ellipsis': 1000,
  7061. 'arrowvertex': 603,
  7062. 'arrowhorizex': 1000,
  7063. 'carriagereturn': 658,
  7064. 'aleph': 823,
  7065. 'Ifraktur': 686,
  7066. 'Rfraktur': 795,
  7067. 'weierstrass': 987,
  7068. 'circlemultiply': 768,
  7069. 'circleplus': 768,
  7070. 'emptyset': 823,
  7071. 'intersection': 768,
  7072. 'union': 768,
  7073. 'propersuperset': 713,
  7074. 'reflexsuperset': 713,
  7075. 'notsubset': 713,
  7076. 'propersubset': 713,
  7077. 'reflexsubset': 713,
  7078. 'element': 713,
  7079. 'notelement': 713,
  7080. 'angle': 768,
  7081. 'gradient': 713,
  7082. 'registerserif': 790,
  7083. 'copyrightserif': 790,
  7084. 'trademarkserif': 890,
  7085. 'product': 823,
  7086. 'radical': 549,
  7087. 'dotmath': 250,
  7088. 'logicalnot': 713,
  7089. 'logicaland': 603,
  7090. 'logicalor': 603,
  7091. 'arrowdblboth': 1042,
  7092. 'arrowdblleft': 987,
  7093. 'arrowdblup': 603,
  7094. 'arrowdblright': 987,
  7095. 'arrowdbldown': 603,
  7096. 'lozenge': 494,
  7097. 'angleleft': 329,
  7098. 'registersans': 790,
  7099. 'copyrightsans': 790,
  7100. 'trademarksans': 786,
  7101. 'summation': 713,
  7102. 'parenlefttp': 384,
  7103. 'parenleftex': 384,
  7104. 'parenleftbt': 384,
  7105. 'bracketlefttp': 384,
  7106. 'bracketleftex': 384,
  7107. 'bracketleftbt': 384,
  7108. 'bracelefttp': 494,
  7109. 'braceleftmid': 494,
  7110. 'braceleftbt': 494,
  7111. 'braceex': 494,
  7112. 'angleright': 329,
  7113. 'integral': 274,
  7114. 'integraltp': 686,
  7115. 'integralex': 686,
  7116. 'integralbt': 686,
  7117. 'parenrighttp': 384,
  7118. 'parenrightex': 384,
  7119. 'parenrightbt': 384,
  7120. 'bracketrighttp': 384,
  7121. 'bracketrightex': 384,
  7122. 'bracketrightbt': 384,
  7123. 'bracerighttp': 494,
  7124. 'bracerightmid': 494,
  7125. 'bracerightbt': 494,
  7126. 'apple': 790
  7127. },
  7128. 'Times-Roman': {
  7129. 'space': 250,
  7130. 'exclam': 333,
  7131. 'quotedbl': 408,
  7132. 'numbersign': 500,
  7133. 'dollar': 500,
  7134. 'percent': 833,
  7135. 'ampersand': 778,
  7136. 'quoteright': 333,
  7137. 'parenleft': 333,
  7138. 'parenright': 333,
  7139. 'asterisk': 500,
  7140. 'plus': 564,
  7141. 'comma': 250,
  7142. 'hyphen': 333,
  7143. 'period': 250,
  7144. 'slash': 278,
  7145. 'zero': 500,
  7146. 'one': 500,
  7147. 'two': 500,
  7148. 'three': 500,
  7149. 'four': 500,
  7150. 'five': 500,
  7151. 'six': 500,
  7152. 'seven': 500,
  7153. 'eight': 500,
  7154. 'nine': 500,
  7155. 'colon': 278,
  7156. 'semicolon': 278,
  7157. 'less': 564,
  7158. 'equal': 564,
  7159. 'greater': 564,
  7160. 'question': 444,
  7161. 'at': 921,
  7162. 'A': 722,
  7163. 'B': 667,
  7164. 'C': 667,
  7165. 'D': 722,
  7166. 'E': 611,
  7167. 'F': 556,
  7168. 'G': 722,
  7169. 'H': 722,
  7170. 'I': 333,
  7171. 'J': 389,
  7172. 'K': 722,
  7173. 'L': 611,
  7174. 'M': 889,
  7175. 'N': 722,
  7176. 'O': 722,
  7177. 'P': 556,
  7178. 'Q': 722,
  7179. 'R': 667,
  7180. 'S': 556,
  7181. 'T': 611,
  7182. 'U': 722,
  7183. 'V': 722,
  7184. 'W': 944,
  7185. 'X': 722,
  7186. 'Y': 722,
  7187. 'Z': 611,
  7188. 'bracketleft': 333,
  7189. 'backslash': 278,
  7190. 'bracketright': 333,
  7191. 'asciicircum': 469,
  7192. 'underscore': 500,
  7193. 'quoteleft': 333,
  7194. 'a': 444,
  7195. 'b': 500,
  7196. 'c': 444,
  7197. 'd': 500,
  7198. 'e': 444,
  7199. 'f': 333,
  7200. 'g': 500,
  7201. 'h': 500,
  7202. 'i': 278,
  7203. 'j': 278,
  7204. 'k': 500,
  7205. 'l': 278,
  7206. 'm': 778,
  7207. 'n': 500,
  7208. 'o': 500,
  7209. 'p': 500,
  7210. 'q': 500,
  7211. 'r': 333,
  7212. 's': 389,
  7213. 't': 278,
  7214. 'u': 500,
  7215. 'v': 500,
  7216. 'w': 722,
  7217. 'x': 500,
  7218. 'y': 500,
  7219. 'z': 444,
  7220. 'braceleft': 480,
  7221. 'bar': 200,
  7222. 'braceright': 480,
  7223. 'asciitilde': 541,
  7224. 'exclamdown': 333,
  7225. 'cent': 500,
  7226. 'sterling': 500,
  7227. 'fraction': 167,
  7228. 'yen': 500,
  7229. 'florin': 500,
  7230. 'section': 500,
  7231. 'currency': 500,
  7232. 'quotesingle': 180,
  7233. 'quotedblleft': 444,
  7234. 'guillemotleft': 500,
  7235. 'guilsinglleft': 333,
  7236. 'guilsinglright': 333,
  7237. 'fi': 556,
  7238. 'fl': 556,
  7239. 'endash': 500,
  7240. 'dagger': 500,
  7241. 'daggerdbl': 500,
  7242. 'periodcentered': 250,
  7243. 'paragraph': 453,
  7244. 'bullet': 350,
  7245. 'quotesinglbase': 333,
  7246. 'quotedblbase': 444,
  7247. 'quotedblright': 444,
  7248. 'guillemotright': 500,
  7249. 'ellipsis': 1000,
  7250. 'perthousand': 1000,
  7251. 'questiondown': 444,
  7252. 'grave': 333,
  7253. 'acute': 333,
  7254. 'circumflex': 333,
  7255. 'tilde': 333,
  7256. 'macron': 333,
  7257. 'breve': 333,
  7258. 'dotaccent': 333,
  7259. 'dieresis': 333,
  7260. 'ring': 333,
  7261. 'cedilla': 333,
  7262. 'hungarumlaut': 333,
  7263. 'ogonek': 333,
  7264. 'caron': 333,
  7265. 'emdash': 1000,
  7266. 'AE': 889,
  7267. 'ordfeminine': 276,
  7268. 'Lslash': 611,
  7269. 'Oslash': 722,
  7270. 'OE': 889,
  7271. 'ordmasculine': 310,
  7272. 'ae': 667,
  7273. 'dotlessi': 278,
  7274. 'lslash': 278,
  7275. 'oslash': 500,
  7276. 'oe': 722,
  7277. 'germandbls': 500,
  7278. 'Idieresis': 333,
  7279. 'eacute': 444,
  7280. 'abreve': 444,
  7281. 'uhungarumlaut': 500,
  7282. 'ecaron': 444,
  7283. 'Ydieresis': 722,
  7284. 'divide': 564,
  7285. 'Yacute': 722,
  7286. 'Acircumflex': 722,
  7287. 'aacute': 444,
  7288. 'Ucircumflex': 722,
  7289. 'yacute': 500,
  7290. 'scommaaccent': 389,
  7291. 'ecircumflex': 444,
  7292. 'Uring': 722,
  7293. 'Udieresis': 722,
  7294. 'aogonek': 444,
  7295. 'Uacute': 722,
  7296. 'uogonek': 500,
  7297. 'Edieresis': 611,
  7298. 'Dcroat': 722,
  7299. 'commaaccent': 250,
  7300. 'copyright': 760,
  7301. 'Emacron': 611,
  7302. 'ccaron': 444,
  7303. 'aring': 444,
  7304. 'Ncommaaccent': 722,
  7305. 'lacute': 278,
  7306. 'agrave': 444,
  7307. 'Tcommaaccent': 611,
  7308. 'Cacute': 667,
  7309. 'atilde': 444,
  7310. 'Edotaccent': 611,
  7311. 'scaron': 389,
  7312. 'scedilla': 389,
  7313. 'iacute': 278,
  7314. 'lozenge': 471,
  7315. 'Rcaron': 667,
  7316. 'Gcommaaccent': 722,
  7317. 'ucircumflex': 500,
  7318. 'acircumflex': 444,
  7319. 'Amacron': 722,
  7320. 'rcaron': 333,
  7321. 'ccedilla': 444,
  7322. 'Zdotaccent': 611,
  7323. 'Thorn': 556,
  7324. 'Omacron': 722,
  7325. 'Racute': 667,
  7326. 'Sacute': 556,
  7327. 'dcaron': 588,
  7328. 'Umacron': 722,
  7329. 'uring': 500,
  7330. 'threesuperior': 300,
  7331. 'Ograve': 722,
  7332. 'Agrave': 722,
  7333. 'Abreve': 722,
  7334. 'multiply': 564,
  7335. 'uacute': 500,
  7336. 'Tcaron': 611,
  7337. 'partialdiff': 476,
  7338. 'ydieresis': 500,
  7339. 'Nacute': 722,
  7340. 'icircumflex': 278,
  7341. 'Ecircumflex': 611,
  7342. 'adieresis': 444,
  7343. 'edieresis': 444,
  7344. 'cacute': 444,
  7345. 'nacute': 500,
  7346. 'umacron': 500,
  7347. 'Ncaron': 722,
  7348. 'Iacute': 333,
  7349. 'plusminus': 564,
  7350. 'brokenbar': 200,
  7351. 'registered': 760,
  7352. 'Gbreve': 722,
  7353. 'Idotaccent': 333,
  7354. 'summation': 600,
  7355. 'Egrave': 611,
  7356. 'racute': 333,
  7357. 'omacron': 500,
  7358. 'Zacute': 611,
  7359. 'Zcaron': 611,
  7360. 'greaterequal': 549,
  7361. 'Eth': 722,
  7362. 'Ccedilla': 667,
  7363. 'lcommaaccent': 278,
  7364. 'tcaron': 326,
  7365. 'eogonek': 444,
  7366. 'Uogonek': 722,
  7367. 'Aacute': 722,
  7368. 'Adieresis': 722,
  7369. 'egrave': 444,
  7370. 'zacute': 444,
  7371. 'iogonek': 278,
  7372. 'Oacute': 722,
  7373. 'oacute': 500,
  7374. 'amacron': 444,
  7375. 'sacute': 389,
  7376. 'idieresis': 278,
  7377. 'Ocircumflex': 722,
  7378. 'Ugrave': 722,
  7379. 'Delta': 612,
  7380. 'thorn': 500,
  7381. 'twosuperior': 300,
  7382. 'Odieresis': 722,
  7383. 'mu': 500,
  7384. 'igrave': 278,
  7385. 'ohungarumlaut': 500,
  7386. 'Eogonek': 611,
  7387. 'dcroat': 500,
  7388. 'threequarters': 750,
  7389. 'Scedilla': 556,
  7390. 'lcaron': 344,
  7391. 'Kcommaaccent': 722,
  7392. 'Lacute': 611,
  7393. 'trademark': 980,
  7394. 'edotaccent': 444,
  7395. 'Igrave': 333,
  7396. 'Imacron': 333,
  7397. 'Lcaron': 611,
  7398. 'onehalf': 750,
  7399. 'lessequal': 549,
  7400. 'ocircumflex': 500,
  7401. 'ntilde': 500,
  7402. 'Uhungarumlaut': 722,
  7403. 'Eacute': 611,
  7404. 'emacron': 444,
  7405. 'gbreve': 500,
  7406. 'onequarter': 750,
  7407. 'Scaron': 556,
  7408. 'Scommaaccent': 556,
  7409. 'Ohungarumlaut': 722,
  7410. 'degree': 400,
  7411. 'ograve': 500,
  7412. 'Ccaron': 667,
  7413. 'ugrave': 500,
  7414. 'radical': 453,
  7415. 'Dcaron': 722,
  7416. 'rcommaaccent': 333,
  7417. 'Ntilde': 722,
  7418. 'otilde': 500,
  7419. 'Rcommaaccent': 667,
  7420. 'Lcommaaccent': 611,
  7421. 'Atilde': 722,
  7422. 'Aogonek': 722,
  7423. 'Aring': 722,
  7424. 'Otilde': 722,
  7425. 'zdotaccent': 444,
  7426. 'Ecaron': 611,
  7427. 'Iogonek': 333,
  7428. 'kcommaaccent': 500,
  7429. 'minus': 564,
  7430. 'Icircumflex': 333,
  7431. 'ncaron': 500,
  7432. 'tcommaaccent': 278,
  7433. 'logicalnot': 564,
  7434. 'odieresis': 500,
  7435. 'udieresis': 500,
  7436. 'notequal': 549,
  7437. 'gcommaaccent': 500,
  7438. 'eth': 500,
  7439. 'zcaron': 444,
  7440. 'ncommaaccent': 500,
  7441. 'onesuperior': 300,
  7442. 'imacron': 278,
  7443. 'Euro': 500
  7444. },
  7445. 'Times-Bold': {
  7446. 'space': 250,
  7447. 'exclam': 333,
  7448. 'quotedbl': 555,
  7449. 'numbersign': 500,
  7450. 'dollar': 500,
  7451. 'percent': 1000,
  7452. 'ampersand': 833,
  7453. 'quoteright': 333,
  7454. 'parenleft': 333,
  7455. 'parenright': 333,
  7456. 'asterisk': 500,
  7457. 'plus': 570,
  7458. 'comma': 250,
  7459. 'hyphen': 333,
  7460. 'period': 250,
  7461. 'slash': 278,
  7462. 'zero': 500,
  7463. 'one': 500,
  7464. 'two': 500,
  7465. 'three': 500,
  7466. 'four': 500,
  7467. 'five': 500,
  7468. 'six': 500,
  7469. 'seven': 500,
  7470. 'eight': 500,
  7471. 'nine': 500,
  7472. 'colon': 333,
  7473. 'semicolon': 333,
  7474. 'less': 570,
  7475. 'equal': 570,
  7476. 'greater': 570,
  7477. 'question': 500,
  7478. 'at': 930,
  7479. 'A': 722,
  7480. 'B': 667,
  7481. 'C': 722,
  7482. 'D': 722,
  7483. 'E': 667,
  7484. 'F': 611,
  7485. 'G': 778,
  7486. 'H': 778,
  7487. 'I': 389,
  7488. 'J': 500,
  7489. 'K': 778,
  7490. 'L': 667,
  7491. 'M': 944,
  7492. 'N': 722,
  7493. 'O': 778,
  7494. 'P': 611,
  7495. 'Q': 778,
  7496. 'R': 722,
  7497. 'S': 556,
  7498. 'T': 667,
  7499. 'U': 722,
  7500. 'V': 722,
  7501. 'W': 1000,
  7502. 'X': 722,
  7503. 'Y': 722,
  7504. 'Z': 667,
  7505. 'bracketleft': 333,
  7506. 'backslash': 278,
  7507. 'bracketright': 333,
  7508. 'asciicircum': 581,
  7509. 'underscore': 500,
  7510. 'quoteleft': 333,
  7511. 'a': 500,
  7512. 'b': 556,
  7513. 'c': 444,
  7514. 'd': 556,
  7515. 'e': 444,
  7516. 'f': 333,
  7517. 'g': 500,
  7518. 'h': 556,
  7519. 'i': 278,
  7520. 'j': 333,
  7521. 'k': 556,
  7522. 'l': 278,
  7523. 'm': 833,
  7524. 'n': 556,
  7525. 'o': 500,
  7526. 'p': 556,
  7527. 'q': 556,
  7528. 'r': 444,
  7529. 's': 389,
  7530. 't': 333,
  7531. 'u': 556,
  7532. 'v': 500,
  7533. 'w': 722,
  7534. 'x': 500,
  7535. 'y': 500,
  7536. 'z': 444,
  7537. 'braceleft': 394,
  7538. 'bar': 220,
  7539. 'braceright': 394,
  7540. 'asciitilde': 520,
  7541. 'exclamdown': 333,
  7542. 'cent': 500,
  7543. 'sterling': 500,
  7544. 'fraction': 167,
  7545. 'yen': 500,
  7546. 'florin': 500,
  7547. 'section': 500,
  7548. 'currency': 500,
  7549. 'quotesingle': 278,
  7550. 'quotedblleft': 500,
  7551. 'guillemotleft': 500,
  7552. 'guilsinglleft': 333,
  7553. 'guilsinglright': 333,
  7554. 'fi': 556,
  7555. 'fl': 556,
  7556. 'endash': 500,
  7557. 'dagger': 500,
  7558. 'daggerdbl': 500,
  7559. 'periodcentered': 250,
  7560. 'paragraph': 540,
  7561. 'bullet': 350,
  7562. 'quotesinglbase': 333,
  7563. 'quotedblbase': 500,
  7564. 'quotedblright': 500,
  7565. 'guillemotright': 500,
  7566. 'ellipsis': 1000,
  7567. 'perthousand': 1000,
  7568. 'questiondown': 500,
  7569. 'grave': 333,
  7570. 'acute': 333,
  7571. 'circumflex': 333,
  7572. 'tilde': 333,
  7573. 'macron': 333,
  7574. 'breve': 333,
  7575. 'dotaccent': 333,
  7576. 'dieresis': 333,
  7577. 'ring': 333,
  7578. 'cedilla': 333,
  7579. 'hungarumlaut': 333,
  7580. 'ogonek': 333,
  7581. 'caron': 333,
  7582. 'emdash': 1000,
  7583. 'AE': 1000,
  7584. 'ordfeminine': 300,
  7585. 'Lslash': 667,
  7586. 'Oslash': 778,
  7587. 'OE': 1000,
  7588. 'ordmasculine': 330,
  7589. 'ae': 722,
  7590. 'dotlessi': 278,
  7591. 'lslash': 278,
  7592. 'oslash': 500,
  7593. 'oe': 722,
  7594. 'germandbls': 556,
  7595. 'Idieresis': 389,
  7596. 'eacute': 444,
  7597. 'abreve': 500,
  7598. 'uhungarumlaut': 556,
  7599. 'ecaron': 444,
  7600. 'Ydieresis': 722,
  7601. 'divide': 570,
  7602. 'Yacute': 722,
  7603. 'Acircumflex': 722,
  7604. 'aacute': 500,
  7605. 'Ucircumflex': 722,
  7606. 'yacute': 500,
  7607. 'scommaaccent': 389,
  7608. 'ecircumflex': 444,
  7609. 'Uring': 722,
  7610. 'Udieresis': 722,
  7611. 'aogonek': 500,
  7612. 'Uacute': 722,
  7613. 'uogonek': 556,
  7614. 'Edieresis': 667,
  7615. 'Dcroat': 722,
  7616. 'commaaccent': 250,
  7617. 'copyright': 747,
  7618. 'Emacron': 667,
  7619. 'ccaron': 444,
  7620. 'aring': 500,
  7621. 'Ncommaaccent': 722,
  7622. 'lacute': 278,
  7623. 'agrave': 500,
  7624. 'Tcommaaccent': 667,
  7625. 'Cacute': 722,
  7626. 'atilde': 500,
  7627. 'Edotaccent': 667,
  7628. 'scaron': 389,
  7629. 'scedilla': 389,
  7630. 'iacute': 278,
  7631. 'lozenge': 494,
  7632. 'Rcaron': 722,
  7633. 'Gcommaaccent': 778,
  7634. 'ucircumflex': 556,
  7635. 'acircumflex': 500,
  7636. 'Amacron': 722,
  7637. 'rcaron': 444,
  7638. 'ccedilla': 444,
  7639. 'Zdotaccent': 667,
  7640. 'Thorn': 611,
  7641. 'Omacron': 778,
  7642. 'Racute': 722,
  7643. 'Sacute': 556,
  7644. 'dcaron': 672,
  7645. 'Umacron': 722,
  7646. 'uring': 556,
  7647. 'threesuperior': 300,
  7648. 'Ograve': 778,
  7649. 'Agrave': 722,
  7650. 'Abreve': 722,
  7651. 'multiply': 570,
  7652. 'uacute': 556,
  7653. 'Tcaron': 667,
  7654. 'partialdiff': 494,
  7655. 'ydieresis': 500,
  7656. 'Nacute': 722,
  7657. 'icircumflex': 278,
  7658. 'Ecircumflex': 667,
  7659. 'adieresis': 500,
  7660. 'edieresis': 444,
  7661. 'cacute': 444,
  7662. 'nacute': 556,
  7663. 'umacron': 556,
  7664. 'Ncaron': 722,
  7665. 'Iacute': 389,
  7666. 'plusminus': 570,
  7667. 'brokenbar': 220,
  7668. 'registered': 747,
  7669. 'Gbreve': 778,
  7670. 'Idotaccent': 389,
  7671. 'summation': 600,
  7672. 'Egrave': 667,
  7673. 'racute': 444,
  7674. 'omacron': 500,
  7675. 'Zacute': 667,
  7676. 'Zcaron': 667,
  7677. 'greaterequal': 549,
  7678. 'Eth': 722,
  7679. 'Ccedilla': 722,
  7680. 'lcommaaccent': 278,
  7681. 'tcaron': 416,
  7682. 'eogonek': 444,
  7683. 'Uogonek': 722,
  7684. 'Aacute': 722,
  7685. 'Adieresis': 722,
  7686. 'egrave': 444,
  7687. 'zacute': 444,
  7688. 'iogonek': 278,
  7689. 'Oacute': 778,
  7690. 'oacute': 500,
  7691. 'amacron': 500,
  7692. 'sacute': 389,
  7693. 'idieresis': 278,
  7694. 'Ocircumflex': 778,
  7695. 'Ugrave': 722,
  7696. 'Delta': 612,
  7697. 'thorn': 556,
  7698. 'twosuperior': 300,
  7699. 'Odieresis': 778,
  7700. 'mu': 556,
  7701. 'igrave': 278,
  7702. 'ohungarumlaut': 500,
  7703. 'Eogonek': 667,
  7704. 'dcroat': 556,
  7705. 'threequarters': 750,
  7706. 'Scedilla': 556,
  7707. 'lcaron': 394,
  7708. 'Kcommaaccent': 778,
  7709. 'Lacute': 667,
  7710. 'trademark': 1000,
  7711. 'edotaccent': 444,
  7712. 'Igrave': 389,
  7713. 'Imacron': 389,
  7714. 'Lcaron': 667,
  7715. 'onehalf': 750,
  7716. 'lessequal': 549,
  7717. 'ocircumflex': 500,
  7718. 'ntilde': 556,
  7719. 'Uhungarumlaut': 722,
  7720. 'Eacute': 667,
  7721. 'emacron': 444,
  7722. 'gbreve': 500,
  7723. 'onequarter': 750,
  7724. 'Scaron': 556,
  7725. 'Scommaaccent': 556,
  7726. 'Ohungarumlaut': 778,
  7727. 'degree': 400,
  7728. 'ograve': 500,
  7729. 'Ccaron': 722,
  7730. 'ugrave': 556,
  7731. 'radical': 549,
  7732. 'Dcaron': 722,
  7733. 'rcommaaccent': 444,
  7734. 'Ntilde': 722,
  7735. 'otilde': 500,
  7736. 'Rcommaaccent': 722,
  7737. 'Lcommaaccent': 667,
  7738. 'Atilde': 722,
  7739. 'Aogonek': 722,
  7740. 'Aring': 722,
  7741. 'Otilde': 778,
  7742. 'zdotaccent': 444,
  7743. 'Ecaron': 667,
  7744. 'Iogonek': 389,
  7745. 'kcommaaccent': 556,
  7746. 'minus': 570,
  7747. 'Icircumflex': 389,
  7748. 'ncaron': 556,
  7749. 'tcommaaccent': 333,
  7750. 'logicalnot': 570,
  7751. 'odieresis': 500,
  7752. 'udieresis': 556,
  7753. 'notequal': 549,
  7754. 'gcommaaccent': 500,
  7755. 'eth': 500,
  7756. 'zcaron': 444,
  7757. 'ncommaaccent': 556,
  7758. 'onesuperior': 300,
  7759. 'imacron': 278,
  7760. 'Euro': 500
  7761. },
  7762. 'Times-BoldItalic': {
  7763. 'space': 250,
  7764. 'exclam': 389,
  7765. 'quotedbl': 555,
  7766. 'numbersign': 500,
  7767. 'dollar': 500,
  7768. 'percent': 833,
  7769. 'ampersand': 778,
  7770. 'quoteright': 333,
  7771. 'parenleft': 333,
  7772. 'parenright': 333,
  7773. 'asterisk': 500,
  7774. 'plus': 570,
  7775. 'comma': 250,
  7776. 'hyphen': 333,
  7777. 'period': 250,
  7778. 'slash': 278,
  7779. 'zero': 500,
  7780. 'one': 500,
  7781. 'two': 500,
  7782. 'three': 500,
  7783. 'four': 500,
  7784. 'five': 500,
  7785. 'six': 500,
  7786. 'seven': 500,
  7787. 'eight': 500,
  7788. 'nine': 500,
  7789. 'colon': 333,
  7790. 'semicolon': 333,
  7791. 'less': 570,
  7792. 'equal': 570,
  7793. 'greater': 570,
  7794. 'question': 500,
  7795. 'at': 832,
  7796. 'A': 667,
  7797. 'B': 667,
  7798. 'C': 667,
  7799. 'D': 722,
  7800. 'E': 667,
  7801. 'F': 667,
  7802. 'G': 722,
  7803. 'H': 778,
  7804. 'I': 389,
  7805. 'J': 500,
  7806. 'K': 667,
  7807. 'L': 611,
  7808. 'M': 889,
  7809. 'N': 722,
  7810. 'O': 722,
  7811. 'P': 611,
  7812. 'Q': 722,
  7813. 'R': 667,
  7814. 'S': 556,
  7815. 'T': 611,
  7816. 'U': 722,
  7817. 'V': 667,
  7818. 'W': 889,
  7819. 'X': 667,
  7820. 'Y': 611,
  7821. 'Z': 611,
  7822. 'bracketleft': 333,
  7823. 'backslash': 278,
  7824. 'bracketright': 333,
  7825. 'asciicircum': 570,
  7826. 'underscore': 500,
  7827. 'quoteleft': 333,
  7828. 'a': 500,
  7829. 'b': 500,
  7830. 'c': 444,
  7831. 'd': 500,
  7832. 'e': 444,
  7833. 'f': 333,
  7834. 'g': 500,
  7835. 'h': 556,
  7836. 'i': 278,
  7837. 'j': 278,
  7838. 'k': 500,
  7839. 'l': 278,
  7840. 'm': 778,
  7841. 'n': 556,
  7842. 'o': 500,
  7843. 'p': 500,
  7844. 'q': 500,
  7845. 'r': 389,
  7846. 's': 389,
  7847. 't': 278,
  7848. 'u': 556,
  7849. 'v': 444,
  7850. 'w': 667,
  7851. 'x': 500,
  7852. 'y': 444,
  7853. 'z': 389,
  7854. 'braceleft': 348,
  7855. 'bar': 220,
  7856. 'braceright': 348,
  7857. 'asciitilde': 570,
  7858. 'exclamdown': 389,
  7859. 'cent': 500,
  7860. 'sterling': 500,
  7861. 'fraction': 167,
  7862. 'yen': 500,
  7863. 'florin': 500,
  7864. 'section': 500,
  7865. 'currency': 500,
  7866. 'quotesingle': 278,
  7867. 'quotedblleft': 500,
  7868. 'guillemotleft': 500,
  7869. 'guilsinglleft': 333,
  7870. 'guilsinglright': 333,
  7871. 'fi': 556,
  7872. 'fl': 556,
  7873. 'endash': 500,
  7874. 'dagger': 500,
  7875. 'daggerdbl': 500,
  7876. 'periodcentered': 250,
  7877. 'paragraph': 500,
  7878. 'bullet': 350,
  7879. 'quotesinglbase': 333,
  7880. 'quotedblbase': 500,
  7881. 'quotedblright': 500,
  7882. 'guillemotright': 500,
  7883. 'ellipsis': 1000,
  7884. 'perthousand': 1000,
  7885. 'questiondown': 500,
  7886. 'grave': 333,
  7887. 'acute': 333,
  7888. 'circumflex': 333,
  7889. 'tilde': 333,
  7890. 'macron': 333,
  7891. 'breve': 333,
  7892. 'dotaccent': 333,
  7893. 'dieresis': 333,
  7894. 'ring': 333,
  7895. 'cedilla': 333,
  7896. 'hungarumlaut': 333,
  7897. 'ogonek': 333,
  7898. 'caron': 333,
  7899. 'emdash': 1000,
  7900. 'AE': 944,
  7901. 'ordfeminine': 266,
  7902. 'Lslash': 611,
  7903. 'Oslash': 722,
  7904. 'OE': 944,
  7905. 'ordmasculine': 300,
  7906. 'ae': 722,
  7907. 'dotlessi': 278,
  7908. 'lslash': 278,
  7909. 'oslash': 500,
  7910. 'oe': 722,
  7911. 'germandbls': 500,
  7912. 'Idieresis': 389,
  7913. 'eacute': 444,
  7914. 'abreve': 500,
  7915. 'uhungarumlaut': 556,
  7916. 'ecaron': 444,
  7917. 'Ydieresis': 611,
  7918. 'divide': 570,
  7919. 'Yacute': 611,
  7920. 'Acircumflex': 667,
  7921. 'aacute': 500,
  7922. 'Ucircumflex': 722,
  7923. 'yacute': 444,
  7924. 'scommaaccent': 389,
  7925. 'ecircumflex': 444,
  7926. 'Uring': 722,
  7927. 'Udieresis': 722,
  7928. 'aogonek': 500,
  7929. 'Uacute': 722,
  7930. 'uogonek': 556,
  7931. 'Edieresis': 667,
  7932. 'Dcroat': 722,
  7933. 'commaaccent': 250,
  7934. 'copyright': 747,
  7935. 'Emacron': 667,
  7936. 'ccaron': 444,
  7937. 'aring': 500,
  7938. 'Ncommaaccent': 722,
  7939. 'lacute': 278,
  7940. 'agrave': 500,
  7941. 'Tcommaaccent': 611,
  7942. 'Cacute': 667,
  7943. 'atilde': 500,
  7944. 'Edotaccent': 667,
  7945. 'scaron': 389,
  7946. 'scedilla': 389,
  7947. 'iacute': 278,
  7948. 'lozenge': 494,
  7949. 'Rcaron': 667,
  7950. 'Gcommaaccent': 722,
  7951. 'ucircumflex': 556,
  7952. 'acircumflex': 500,
  7953. 'Amacron': 667,
  7954. 'rcaron': 389,
  7955. 'ccedilla': 444,
  7956. 'Zdotaccent': 611,
  7957. 'Thorn': 611,
  7958. 'Omacron': 722,
  7959. 'Racute': 667,
  7960. 'Sacute': 556,
  7961. 'dcaron': 608,
  7962. 'Umacron': 722,
  7963. 'uring': 556,
  7964. 'threesuperior': 300,
  7965. 'Ograve': 722,
  7966. 'Agrave': 667,
  7967. 'Abreve': 667,
  7968. 'multiply': 570,
  7969. 'uacute': 556,
  7970. 'Tcaron': 611,
  7971. 'partialdiff': 494,
  7972. 'ydieresis': 444,
  7973. 'Nacute': 722,
  7974. 'icircumflex': 278,
  7975. 'Ecircumflex': 667,
  7976. 'adieresis': 500,
  7977. 'edieresis': 444,
  7978. 'cacute': 444,
  7979. 'nacute': 556,
  7980. 'umacron': 556,
  7981. 'Ncaron': 722,
  7982. 'Iacute': 389,
  7983. 'plusminus': 570,
  7984. 'brokenbar': 220,
  7985. 'registered': 747,
  7986. 'Gbreve': 722,
  7987. 'Idotaccent': 389,
  7988. 'summation': 600,
  7989. 'Egrave': 667,
  7990. 'racute': 389,
  7991. 'omacron': 500,
  7992. 'Zacute': 611,
  7993. 'Zcaron': 611,
  7994. 'greaterequal': 549,
  7995. 'Eth': 722,
  7996. 'Ccedilla': 667,
  7997. 'lcommaaccent': 278,
  7998. 'tcaron': 366,
  7999. 'eogonek': 444,
  8000. 'Uogonek': 722,
  8001. 'Aacute': 667,
  8002. 'Adieresis': 667,
  8003. 'egrave': 444,
  8004. 'zacute': 389,
  8005. 'iogonek': 278,
  8006. 'Oacute': 722,
  8007. 'oacute': 500,
  8008. 'amacron': 500,
  8009. 'sacute': 389,
  8010. 'idieresis': 278,
  8011. 'Ocircumflex': 722,
  8012. 'Ugrave': 722,
  8013. 'Delta': 612,
  8014. 'thorn': 500,
  8015. 'twosuperior': 300,
  8016. 'Odieresis': 722,
  8017. 'mu': 576,
  8018. 'igrave': 278,
  8019. 'ohungarumlaut': 500,
  8020. 'Eogonek': 667,
  8021. 'dcroat': 500,
  8022. 'threequarters': 750,
  8023. 'Scedilla': 556,
  8024. 'lcaron': 382,
  8025. 'Kcommaaccent': 667,
  8026. 'Lacute': 611,
  8027. 'trademark': 1000,
  8028. 'edotaccent': 444,
  8029. 'Igrave': 389,
  8030. 'Imacron': 389,
  8031. 'Lcaron': 611,
  8032. 'onehalf': 750,
  8033. 'lessequal': 549,
  8034. 'ocircumflex': 500,
  8035. 'ntilde': 556,
  8036. 'Uhungarumlaut': 722,
  8037. 'Eacute': 667,
  8038. 'emacron': 444,
  8039. 'gbreve': 500,
  8040. 'onequarter': 750,
  8041. 'Scaron': 556,
  8042. 'Scommaaccent': 556,
  8043. 'Ohungarumlaut': 722,
  8044. 'degree': 400,
  8045. 'ograve': 500,
  8046. 'Ccaron': 667,
  8047. 'ugrave': 556,
  8048. 'radical': 549,
  8049. 'Dcaron': 722,
  8050. 'rcommaaccent': 389,
  8051. 'Ntilde': 722,
  8052. 'otilde': 500,
  8053. 'Rcommaaccent': 667,
  8054. 'Lcommaaccent': 611,
  8055. 'Atilde': 667,
  8056. 'Aogonek': 667,
  8057. 'Aring': 667,
  8058. 'Otilde': 722,
  8059. 'zdotaccent': 389,
  8060. 'Ecaron': 667,
  8061. 'Iogonek': 389,
  8062. 'kcommaaccent': 500,
  8063. 'minus': 606,
  8064. 'Icircumflex': 389,
  8065. 'ncaron': 556,
  8066. 'tcommaaccent': 278,
  8067. 'logicalnot': 606,
  8068. 'odieresis': 500,
  8069. 'udieresis': 556,
  8070. 'notequal': 549,
  8071. 'gcommaaccent': 500,
  8072. 'eth': 500,
  8073. 'zcaron': 389,
  8074. 'ncommaaccent': 556,
  8075. 'onesuperior': 300,
  8076. 'imacron': 278,
  8077. 'Euro': 500
  8078. },
  8079. 'Times-Italic': {
  8080. 'space': 250,
  8081. 'exclam': 333,
  8082. 'quotedbl': 420,
  8083. 'numbersign': 500,
  8084. 'dollar': 500,
  8085. 'percent': 833,
  8086. 'ampersand': 778,
  8087. 'quoteright': 333,
  8088. 'parenleft': 333,
  8089. 'parenright': 333,
  8090. 'asterisk': 500,
  8091. 'plus': 675,
  8092. 'comma': 250,
  8093. 'hyphen': 333,
  8094. 'period': 250,
  8095. 'slash': 278,
  8096. 'zero': 500,
  8097. 'one': 500,
  8098. 'two': 500,
  8099. 'three': 500,
  8100. 'four': 500,
  8101. 'five': 500,
  8102. 'six': 500,
  8103. 'seven': 500,
  8104. 'eight': 500,
  8105. 'nine': 500,
  8106. 'colon': 333,
  8107. 'semicolon': 333,
  8108. 'less': 675,
  8109. 'equal': 675,
  8110. 'greater': 675,
  8111. 'question': 500,
  8112. 'at': 920,
  8113. 'A': 611,
  8114. 'B': 611,
  8115. 'C': 667,
  8116. 'D': 722,
  8117. 'E': 611,
  8118. 'F': 611,
  8119. 'G': 722,
  8120. 'H': 722,
  8121. 'I': 333,
  8122. 'J': 444,
  8123. 'K': 667,
  8124. 'L': 556,
  8125. 'M': 833,
  8126. 'N': 667,
  8127. 'O': 722,
  8128. 'P': 611,
  8129. 'Q': 722,
  8130. 'R': 611,
  8131. 'S': 500,
  8132. 'T': 556,
  8133. 'U': 722,
  8134. 'V': 611,
  8135. 'W': 833,
  8136. 'X': 611,
  8137. 'Y': 556,
  8138. 'Z': 556,
  8139. 'bracketleft': 389,
  8140. 'backslash': 278,
  8141. 'bracketright': 389,
  8142. 'asciicircum': 422,
  8143. 'underscore': 500,
  8144. 'quoteleft': 333,
  8145. 'a': 500,
  8146. 'b': 500,
  8147. 'c': 444,
  8148. 'd': 500,
  8149. 'e': 444,
  8150. 'f': 278,
  8151. 'g': 500,
  8152. 'h': 500,
  8153. 'i': 278,
  8154. 'j': 278,
  8155. 'k': 444,
  8156. 'l': 278,
  8157. 'm': 722,
  8158. 'n': 500,
  8159. 'o': 500,
  8160. 'p': 500,
  8161. 'q': 500,
  8162. 'r': 389,
  8163. 's': 389,
  8164. 't': 278,
  8165. 'u': 500,
  8166. 'v': 444,
  8167. 'w': 667,
  8168. 'x': 444,
  8169. 'y': 444,
  8170. 'z': 389,
  8171. 'braceleft': 400,
  8172. 'bar': 275,
  8173. 'braceright': 400,
  8174. 'asciitilde': 541,
  8175. 'exclamdown': 389,
  8176. 'cent': 500,
  8177. 'sterling': 500,
  8178. 'fraction': 167,
  8179. 'yen': 500,
  8180. 'florin': 500,
  8181. 'section': 500,
  8182. 'currency': 500,
  8183. 'quotesingle': 214,
  8184. 'quotedblleft': 556,
  8185. 'guillemotleft': 500,
  8186. 'guilsinglleft': 333,
  8187. 'guilsinglright': 333,
  8188. 'fi': 500,
  8189. 'fl': 500,
  8190. 'endash': 500,
  8191. 'dagger': 500,
  8192. 'daggerdbl': 500,
  8193. 'periodcentered': 250,
  8194. 'paragraph': 523,
  8195. 'bullet': 350,
  8196. 'quotesinglbase': 333,
  8197. 'quotedblbase': 556,
  8198. 'quotedblright': 556,
  8199. 'guillemotright': 500,
  8200. 'ellipsis': 889,
  8201. 'perthousand': 1000,
  8202. 'questiondown': 500,
  8203. 'grave': 333,
  8204. 'acute': 333,
  8205. 'circumflex': 333,
  8206. 'tilde': 333,
  8207. 'macron': 333,
  8208. 'breve': 333,
  8209. 'dotaccent': 333,
  8210. 'dieresis': 333,
  8211. 'ring': 333,
  8212. 'cedilla': 333,
  8213. 'hungarumlaut': 333,
  8214. 'ogonek': 333,
  8215. 'caron': 333,
  8216. 'emdash': 889,
  8217. 'AE': 889,
  8218. 'ordfeminine': 276,
  8219. 'Lslash': 556,
  8220. 'Oslash': 722,
  8221. 'OE': 944,
  8222. 'ordmasculine': 310,
  8223. 'ae': 667,
  8224. 'dotlessi': 278,
  8225. 'lslash': 278,
  8226. 'oslash': 500,
  8227. 'oe': 667,
  8228. 'germandbls': 500,
  8229. 'Idieresis': 333,
  8230. 'eacute': 444,
  8231. 'abreve': 500,
  8232. 'uhungarumlaut': 500,
  8233. 'ecaron': 444,
  8234. 'Ydieresis': 556,
  8235. 'divide': 675,
  8236. 'Yacute': 556,
  8237. 'Acircumflex': 611,
  8238. 'aacute': 500,
  8239. 'Ucircumflex': 722,
  8240. 'yacute': 444,
  8241. 'scommaaccent': 389,
  8242. 'ecircumflex': 444,
  8243. 'Uring': 722,
  8244. 'Udieresis': 722,
  8245. 'aogonek': 500,
  8246. 'Uacute': 722,
  8247. 'uogonek': 500,
  8248. 'Edieresis': 611,
  8249. 'Dcroat': 722,
  8250. 'commaaccent': 250,
  8251. 'copyright': 760,
  8252. 'Emacron': 611,
  8253. 'ccaron': 444,
  8254. 'aring': 500,
  8255. 'Ncommaaccent': 667,
  8256. 'lacute': 278,
  8257. 'agrave': 500,
  8258. 'Tcommaaccent': 556,
  8259. 'Cacute': 667,
  8260. 'atilde': 500,
  8261. 'Edotaccent': 611,
  8262. 'scaron': 389,
  8263. 'scedilla': 389,
  8264. 'iacute': 278,
  8265. 'lozenge': 471,
  8266. 'Rcaron': 611,
  8267. 'Gcommaaccent': 722,
  8268. 'ucircumflex': 500,
  8269. 'acircumflex': 500,
  8270. 'Amacron': 611,
  8271. 'rcaron': 389,
  8272. 'ccedilla': 444,
  8273. 'Zdotaccent': 556,
  8274. 'Thorn': 611,
  8275. 'Omacron': 722,
  8276. 'Racute': 611,
  8277. 'Sacute': 500,
  8278. 'dcaron': 544,
  8279. 'Umacron': 722,
  8280. 'uring': 500,
  8281. 'threesuperior': 300,
  8282. 'Ograve': 722,
  8283. 'Agrave': 611,
  8284. 'Abreve': 611,
  8285. 'multiply': 675,
  8286. 'uacute': 500,
  8287. 'Tcaron': 556,
  8288. 'partialdiff': 476,
  8289. 'ydieresis': 444,
  8290. 'Nacute': 667,
  8291. 'icircumflex': 278,
  8292. 'Ecircumflex': 611,
  8293. 'adieresis': 500,
  8294. 'edieresis': 444,
  8295. 'cacute': 444,
  8296. 'nacute': 500,
  8297. 'umacron': 500,
  8298. 'Ncaron': 667,
  8299. 'Iacute': 333,
  8300. 'plusminus': 675,
  8301. 'brokenbar': 275,
  8302. 'registered': 760,
  8303. 'Gbreve': 722,
  8304. 'Idotaccent': 333,
  8305. 'summation': 600,
  8306. 'Egrave': 611,
  8307. 'racute': 389,
  8308. 'omacron': 500,
  8309. 'Zacute': 556,
  8310. 'Zcaron': 556,
  8311. 'greaterequal': 549,
  8312. 'Eth': 722,
  8313. 'Ccedilla': 667,
  8314. 'lcommaaccent': 278,
  8315. 'tcaron': 300,
  8316. 'eogonek': 444,
  8317. 'Uogonek': 722,
  8318. 'Aacute': 611,
  8319. 'Adieresis': 611,
  8320. 'egrave': 444,
  8321. 'zacute': 389,
  8322. 'iogonek': 278,
  8323. 'Oacute': 722,
  8324. 'oacute': 500,
  8325. 'amacron': 500,
  8326. 'sacute': 389,
  8327. 'idieresis': 278,
  8328. 'Ocircumflex': 722,
  8329. 'Ugrave': 722,
  8330. 'Delta': 612,
  8331. 'thorn': 500,
  8332. 'twosuperior': 300,
  8333. 'Odieresis': 722,
  8334. 'mu': 500,
  8335. 'igrave': 278,
  8336. 'ohungarumlaut': 500,
  8337. 'Eogonek': 611,
  8338. 'dcroat': 500,
  8339. 'threequarters': 750,
  8340. 'Scedilla': 500,
  8341. 'lcaron': 300,
  8342. 'Kcommaaccent': 667,
  8343. 'Lacute': 556,
  8344. 'trademark': 980,
  8345. 'edotaccent': 444,
  8346. 'Igrave': 333,
  8347. 'Imacron': 333,
  8348. 'Lcaron': 611,
  8349. 'onehalf': 750,
  8350. 'lessequal': 549,
  8351. 'ocircumflex': 500,
  8352. 'ntilde': 500,
  8353. 'Uhungarumlaut': 722,
  8354. 'Eacute': 611,
  8355. 'emacron': 444,
  8356. 'gbreve': 500,
  8357. 'onequarter': 750,
  8358. 'Scaron': 500,
  8359. 'Scommaaccent': 500,
  8360. 'Ohungarumlaut': 722,
  8361. 'degree': 400,
  8362. 'ograve': 500,
  8363. 'Ccaron': 667,
  8364. 'ugrave': 500,
  8365. 'radical': 453,
  8366. 'Dcaron': 722,
  8367. 'rcommaaccent': 389,
  8368. 'Ntilde': 667,
  8369. 'otilde': 500,
  8370. 'Rcommaaccent': 611,
  8371. 'Lcommaaccent': 556,
  8372. 'Atilde': 611,
  8373. 'Aogonek': 611,
  8374. 'Aring': 611,
  8375. 'Otilde': 722,
  8376. 'zdotaccent': 389,
  8377. 'Ecaron': 611,
  8378. 'Iogonek': 333,
  8379. 'kcommaaccent': 444,
  8380. 'minus': 675,
  8381. 'Icircumflex': 333,
  8382. 'ncaron': 500,
  8383. 'tcommaaccent': 278,
  8384. 'logicalnot': 675,
  8385. 'odieresis': 500,
  8386. 'udieresis': 500,
  8387. 'notequal': 549,
  8388. 'gcommaaccent': 500,
  8389. 'eth': 500,
  8390. 'zcaron': 389,
  8391. 'ncommaaccent': 500,
  8392. 'onesuperior': 300,
  8393. 'imacron': 278,
  8394. 'Euro': 500
  8395. },
  8396. 'ZapfDingbats': {
  8397. 'space': 278,
  8398. 'a1': 974,
  8399. 'a2': 961,
  8400. 'a202': 974,
  8401. 'a3': 980,
  8402. 'a4': 719,
  8403. 'a5': 789,
  8404. 'a119': 790,
  8405. 'a118': 791,
  8406. 'a117': 690,
  8407. 'a11': 960,
  8408. 'a12': 939,
  8409. 'a13': 549,
  8410. 'a14': 855,
  8411. 'a15': 911,
  8412. 'a16': 933,
  8413. 'a105': 911,
  8414. 'a17': 945,
  8415. 'a18': 974,
  8416. 'a19': 755,
  8417. 'a20': 846,
  8418. 'a21': 762,
  8419. 'a22': 761,
  8420. 'a23': 571,
  8421. 'a24': 677,
  8422. 'a25': 763,
  8423. 'a26': 760,
  8424. 'a27': 759,
  8425. 'a28': 754,
  8426. 'a6': 494,
  8427. 'a7': 552,
  8428. 'a8': 537,
  8429. 'a9': 577,
  8430. 'a10': 692,
  8431. 'a29': 786,
  8432. 'a30': 788,
  8433. 'a31': 788,
  8434. 'a32': 790,
  8435. 'a33': 793,
  8436. 'a34': 794,
  8437. 'a35': 816,
  8438. 'a36': 823,
  8439. 'a37': 789,
  8440. 'a38': 841,
  8441. 'a39': 823,
  8442. 'a40': 833,
  8443. 'a41': 816,
  8444. 'a42': 831,
  8445. 'a43': 923,
  8446. 'a44': 744,
  8447. 'a45': 723,
  8448. 'a46': 749,
  8449. 'a47': 790,
  8450. 'a48': 792,
  8451. 'a49': 695,
  8452. 'a50': 776,
  8453. 'a51': 768,
  8454. 'a52': 792,
  8455. 'a53': 759,
  8456. 'a54': 707,
  8457. 'a55': 708,
  8458. 'a56': 682,
  8459. 'a57': 701,
  8460. 'a58': 826,
  8461. 'a59': 815,
  8462. 'a60': 789,
  8463. 'a61': 789,
  8464. 'a62': 707,
  8465. 'a63': 687,
  8466. 'a64': 696,
  8467. 'a65': 689,
  8468. 'a66': 786,
  8469. 'a67': 787,
  8470. 'a68': 713,
  8471. 'a69': 791,
  8472. 'a70': 785,
  8473. 'a71': 791,
  8474. 'a72': 873,
  8475. 'a73': 761,
  8476. 'a74': 762,
  8477. 'a203': 762,
  8478. 'a75': 759,
  8479. 'a204': 759,
  8480. 'a76': 892,
  8481. 'a77': 892,
  8482. 'a78': 788,
  8483. 'a79': 784,
  8484. 'a81': 438,
  8485. 'a82': 138,
  8486. 'a83': 277,
  8487. 'a84': 415,
  8488. 'a97': 392,
  8489. 'a98': 392,
  8490. 'a99': 668,
  8491. 'a100': 668,
  8492. 'a89': 390,
  8493. 'a90': 390,
  8494. 'a93': 317,
  8495. 'a94': 317,
  8496. 'a91': 276,
  8497. 'a92': 276,
  8498. 'a205': 509,
  8499. 'a85': 509,
  8500. 'a206': 410,
  8501. 'a86': 410,
  8502. 'a87': 234,
  8503. 'a88': 234,
  8504. 'a95': 334,
  8505. 'a96': 334,
  8506. 'a101': 732,
  8507. 'a102': 544,
  8508. 'a103': 544,
  8509. 'a104': 910,
  8510. 'a106': 667,
  8511. 'a107': 760,
  8512. 'a108': 760,
  8513. 'a112': 776,
  8514. 'a111': 595,
  8515. 'a110': 694,
  8516. 'a109': 626,
  8517. 'a120': 788,
  8518. 'a121': 788,
  8519. 'a122': 788,
  8520. 'a123': 788,
  8521. 'a124': 788,
  8522. 'a125': 788,
  8523. 'a126': 788,
  8524. 'a127': 788,
  8525. 'a128': 788,
  8526. 'a129': 788,
  8527. 'a130': 788,
  8528. 'a131': 788,
  8529. 'a132': 788,
  8530. 'a133': 788,
  8531. 'a134': 788,
  8532. 'a135': 788,
  8533. 'a136': 788,
  8534. 'a137': 788,
  8535. 'a138': 788,
  8536. 'a139': 788,
  8537. 'a140': 788,
  8538. 'a141': 788,
  8539. 'a142': 788,
  8540. 'a143': 788,
  8541. 'a144': 788,
  8542. 'a145': 788,
  8543. 'a146': 788,
  8544. 'a147': 788,
  8545. 'a148': 788,
  8546. 'a149': 788,
  8547. 'a150': 788,
  8548. 'a151': 788,
  8549. 'a152': 788,
  8550. 'a153': 788,
  8551. 'a154': 788,
  8552. 'a155': 788,
  8553. 'a156': 788,
  8554. 'a157': 788,
  8555. 'a158': 788,
  8556. 'a159': 788,
  8557. 'a160': 894,
  8558. 'a161': 838,
  8559. 'a163': 1016,
  8560. 'a164': 458,
  8561. 'a196': 748,
  8562. 'a165': 924,
  8563. 'a192': 748,
  8564. 'a166': 918,
  8565. 'a167': 927,
  8566. 'a168': 928,
  8567. 'a169': 928,
  8568. 'a170': 834,
  8569. 'a171': 873,
  8570. 'a172': 828,
  8571. 'a173': 924,
  8572. 'a162': 924,
  8573. 'a174': 917,
  8574. 'a175': 930,
  8575. 'a176': 931,
  8576. 'a177': 463,
  8577. 'a178': 883,
  8578. 'a179': 836,
  8579. 'a193': 836,
  8580. 'a180': 867,
  8581. 'a199': 867,
  8582. 'a181': 696,
  8583. 'a200': 696,
  8584. 'a182': 874,
  8585. 'a201': 874,
  8586. 'a183': 760,
  8587. 'a184': 946,
  8588. 'a197': 771,
  8589. 'a185': 865,
  8590. 'a194': 771,
  8591. 'a198': 888,
  8592. 'a186': 967,
  8593. 'a195': 888,
  8594. 'a187': 831,
  8595. 'a188': 873,
  8596. 'a189': 927,
  8597. 'a190': 970,
  8598. 'a191': 918
  8599. }
  8600. };
  8601. exports.Metrics = Metrics;
  8602. }));
  8603. var NetworkManager = (function NetworkManagerClosure() {
  8604. var OK_RESPONSE = 200;
  8605. var PARTIAL_CONTENT_RESPONSE = 206;
  8606. function NetworkManager(url, args) {
  8607. this.url = url;
  8608. args = args || {};
  8609. this.isHttp = /^https?:/i.test(url);
  8610. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8611. this.withCredentials = args.withCredentials || false;
  8612. this.getXhr = args.getXhr ||
  8613. function NetworkManager_getXhr() {
  8614. return new XMLHttpRequest();
  8615. };
  8616. this.currXhrId = 0;
  8617. this.pendingRequests = {};
  8618. this.loadedRequests = {};
  8619. }
  8620. function getArrayBuffer(xhr) {
  8621. var data = xhr.response;
  8622. if (typeof data !== 'string') {
  8623. return data;
  8624. }
  8625. var length = data.length;
  8626. var array = new Uint8Array(length);
  8627. for (var i = 0; i < length; i++) {
  8628. array[i] = data.charCodeAt(i) & 0xFF;
  8629. }
  8630. return array.buffer;
  8631. }
  8632. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8633. try {
  8634. var x = new XMLHttpRequest();
  8635. // Firefox 37- required .open() to be called before setting responseType.
  8636. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8637. // Even though the URL is not visited, .open() could fail if the URL is
  8638. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8639. // When this error occurs, this feature detection method will mistakenly
  8640. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8641. x.open('GET', 'https://example.com');
  8642. x.responseType = 'moz-chunked-arraybuffer';
  8643. return x.responseType === 'moz-chunked-arraybuffer';
  8644. } catch (e) {
  8645. return false;
  8646. }
  8647. })();
  8648. NetworkManager.prototype = {
  8649. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8650. var args = {
  8651. begin: begin,
  8652. end: end
  8653. };
  8654. for (var prop in listeners) {
  8655. args[prop] = listeners[prop];
  8656. }
  8657. return this.request(args);
  8658. },
  8659. requestFull: function NetworkManager_requestFull(listeners) {
  8660. return this.request(listeners);
  8661. },
  8662. request: function NetworkManager_request(args) {
  8663. var xhr = this.getXhr();
  8664. var xhrId = this.currXhrId++;
  8665. var pendingRequest = this.pendingRequests[xhrId] = {
  8666. xhr: xhr
  8667. };
  8668. xhr.open('GET', this.url);
  8669. xhr.withCredentials = this.withCredentials;
  8670. for (var property in this.httpHeaders) {
  8671. var value = this.httpHeaders[property];
  8672. if (typeof value === 'undefined') {
  8673. continue;
  8674. }
  8675. xhr.setRequestHeader(property, value);
  8676. }
  8677. if (this.isHttp && 'begin' in args && 'end' in args) {
  8678. var rangeStr = args.begin + '-' + (args.end - 1);
  8679. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8680. pendingRequest.expectedStatus = 206;
  8681. } else {
  8682. pendingRequest.expectedStatus = 200;
  8683. }
  8684. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8685. if (useMozChunkedLoading) {
  8686. xhr.responseType = 'moz-chunked-arraybuffer';
  8687. pendingRequest.onProgressiveData = args.onProgressiveData;
  8688. pendingRequest.mozChunked = true;
  8689. } else {
  8690. xhr.responseType = 'arraybuffer';
  8691. }
  8692. if (args.onError) {
  8693. xhr.onerror = function(evt) {
  8694. args.onError(xhr.status);
  8695. };
  8696. }
  8697. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8698. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8699. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8700. pendingRequest.onDone = args.onDone;
  8701. pendingRequest.onError = args.onError;
  8702. pendingRequest.onProgress = args.onProgress;
  8703. xhr.send(null);
  8704. return xhrId;
  8705. },
  8706. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8707. var pendingRequest = this.pendingRequests[xhrId];
  8708. if (!pendingRequest) {
  8709. // Maybe abortRequest was called...
  8710. return;
  8711. }
  8712. if (pendingRequest.mozChunked) {
  8713. var chunk = getArrayBuffer(pendingRequest.xhr);
  8714. pendingRequest.onProgressiveData(chunk);
  8715. }
  8716. var onProgress = pendingRequest.onProgress;
  8717. if (onProgress) {
  8718. onProgress(evt);
  8719. }
  8720. },
  8721. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8722. var pendingRequest = this.pendingRequests[xhrId];
  8723. if (!pendingRequest) {
  8724. // Maybe abortRequest was called...
  8725. return;
  8726. }
  8727. var xhr = pendingRequest.xhr;
  8728. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8729. pendingRequest.onHeadersReceived();
  8730. delete pendingRequest.onHeadersReceived;
  8731. }
  8732. if (xhr.readyState !== 4) {
  8733. return;
  8734. }
  8735. if (!(xhrId in this.pendingRequests)) {
  8736. // The XHR request might have been aborted in onHeadersReceived()
  8737. // callback, in which case we should abort request
  8738. return;
  8739. }
  8740. delete this.pendingRequests[xhrId];
  8741. // success status == 0 can be on ftp, file and other protocols
  8742. if (xhr.status === 0 && this.isHttp) {
  8743. if (pendingRequest.onError) {
  8744. pendingRequest.onError(xhr.status);
  8745. }
  8746. return;
  8747. }
  8748. var xhrStatus = xhr.status || OK_RESPONSE;
  8749. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8750. // "A server MAY ignore the Range header". This means it's possible to
  8751. // get a 200 rather than a 206 response from a range request.
  8752. var ok_response_on_range_request =
  8753. xhrStatus === OK_RESPONSE &&
  8754. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8755. if (!ok_response_on_range_request &&
  8756. xhrStatus !== pendingRequest.expectedStatus) {
  8757. if (pendingRequest.onError) {
  8758. pendingRequest.onError(xhr.status);
  8759. }
  8760. return;
  8761. }
  8762. this.loadedRequests[xhrId] = true;
  8763. var chunk = getArrayBuffer(xhr);
  8764. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8765. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8766. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8767. var begin = parseInt(matches[1], 10);
  8768. pendingRequest.onDone({
  8769. begin: begin,
  8770. chunk: chunk
  8771. });
  8772. } else if (pendingRequest.onProgressiveData) {
  8773. pendingRequest.onDone(null);
  8774. } else if (chunk) {
  8775. pendingRequest.onDone({
  8776. begin: 0,
  8777. chunk: chunk
  8778. });
  8779. } else if (pendingRequest.onError) {
  8780. pendingRequest.onError(xhr.status);
  8781. }
  8782. },
  8783. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8784. for (var xhrId in this.pendingRequests) {
  8785. return true;
  8786. }
  8787. return false;
  8788. },
  8789. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8790. return this.pendingRequests[xhrId].xhr;
  8791. },
  8792. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8793. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8794. },
  8795. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8796. return xhrId in this.pendingRequests;
  8797. },
  8798. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8799. return xhrId in this.loadedRequests;
  8800. },
  8801. abortAllRequests: function NetworkManager_abortAllRequests() {
  8802. for (var xhrId in this.pendingRequests) {
  8803. this.abortRequest(xhrId | 0);
  8804. }
  8805. },
  8806. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8807. var xhr = this.pendingRequests[xhrId].xhr;
  8808. delete this.pendingRequests[xhrId];
  8809. xhr.abort();
  8810. }
  8811. };
  8812. return NetworkManager;
  8813. })();
  8814. (function (root, factory) {
  8815. {
  8816. factory((root.pdfjsCoreNetwork = {}));
  8817. }
  8818. }(this, function (exports) {
  8819. exports.NetworkManager = NetworkManager;
  8820. }));
  8821. (function (root, factory) {
  8822. {
  8823. factory((root.pdfjsSharedGlobal = {}));
  8824. }
  8825. }(this, function (exports) {
  8826. var globalScope = (typeof window !== 'undefined') ? window :
  8827. (typeof global !== 'undefined') ? global :
  8828. (typeof self !== 'undefined') ? self : this;
  8829. var isWorker = (typeof window === 'undefined');
  8830. // The global PDFJS object exposes the API
  8831. // In production, it will be declared outside a global wrapper
  8832. // In development, it will be declared here
  8833. if (!globalScope.PDFJS) {
  8834. globalScope.PDFJS = {};
  8835. }
  8836. globalScope.PDFJS.pdfBug = false;
  8837. exports.globalScope = globalScope;
  8838. exports.isWorker = isWorker;
  8839. exports.PDFJS = globalScope.PDFJS;
  8840. }));
  8841. (function (root, factory) {
  8842. {
  8843. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  8844. }
  8845. }(this, function (exports, sharedGlobal) {
  8846. var PDFJS = sharedGlobal.PDFJS;
  8847. var bidi = PDFJS.bidi = (function bidiClosure() {
  8848. // Character types for symbols from 0000 to 00FF.
  8849. var baseTypes = [
  8850. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  8851. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8852. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  8853. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  8854. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  8855. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8856. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  8857. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8858. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8859. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  8860. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8861. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8862. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  8863. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  8864. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8865. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8866. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8867. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8868. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  8869. ];
  8870. // Character types for symbols from 0600 to 06FF
  8871. var arabicTypes = [
  8872. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8873. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  8874. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8875. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8876. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8877. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8878. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8879. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8880. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  8881. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8882. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8883. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8884. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8885. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8886. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8887. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8888. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8889. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8890. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8891. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  8892. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8893. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  8894. ];
  8895. function isOdd(i) {
  8896. return (i & 1) !== 0;
  8897. }
  8898. function isEven(i) {
  8899. return (i & 1) === 0;
  8900. }
  8901. function findUnequal(arr, start, value) {
  8902. for (var j = start, jj = arr.length; j < jj; ++j) {
  8903. if (arr[j] !== value) {
  8904. return j;
  8905. }
  8906. }
  8907. return j;
  8908. }
  8909. function setValues(arr, start, end, value) {
  8910. for (var j = start; j < end; ++j) {
  8911. arr[j] = value;
  8912. }
  8913. }
  8914. function reverseValues(arr, start, end) {
  8915. for (var i = start, j = end - 1; i < j; ++i, --j) {
  8916. var temp = arr[i];
  8917. arr[i] = arr[j];
  8918. arr[j] = temp;
  8919. }
  8920. }
  8921. function createBidiText(str, isLTR, vertical) {
  8922. return {
  8923. str: str,
  8924. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  8925. };
  8926. }
  8927. // These are used in bidi(), which is called frequently. We re-use them on
  8928. // each call to avoid unnecessary allocations.
  8929. var chars = [];
  8930. var types = [];
  8931. function bidi(str, startLevel, vertical) {
  8932. var isLTR = true;
  8933. var strLength = str.length;
  8934. if (strLength === 0 || vertical) {
  8935. return createBidiText(str, isLTR, vertical);
  8936. }
  8937. // Get types and fill arrays
  8938. chars.length = strLength;
  8939. types.length = strLength;
  8940. var numBidi = 0;
  8941. var i, ii;
  8942. for (i = 0; i < strLength; ++i) {
  8943. chars[i] = str.charAt(i);
  8944. var charCode = str.charCodeAt(i);
  8945. var charType = 'L';
  8946. if (charCode <= 0x00ff) {
  8947. charType = baseTypes[charCode];
  8948. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  8949. charType = 'R';
  8950. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  8951. charType = arabicTypes[charCode & 0xff];
  8952. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  8953. charType = 'AL';
  8954. }
  8955. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  8956. numBidi++;
  8957. }
  8958. types[i] = charType;
  8959. }
  8960. // Detect the bidi method
  8961. // - If there are no rtl characters then no bidi needed
  8962. // - If less than 30% chars are rtl then string is primarily ltr
  8963. // - If more than 30% chars are rtl then string is primarily rtl
  8964. if (numBidi === 0) {
  8965. isLTR = true;
  8966. return createBidiText(str, isLTR);
  8967. }
  8968. if (startLevel === -1) {
  8969. if ((strLength / numBidi) < 0.3) {
  8970. isLTR = true;
  8971. startLevel = 0;
  8972. } else {
  8973. isLTR = false;
  8974. startLevel = 1;
  8975. }
  8976. }
  8977. var levels = [];
  8978. for (i = 0; i < strLength; ++i) {
  8979. levels[i] = startLevel;
  8980. }
  8981. /*
  8982. X1-X10: skip most of this, since we are NOT doing the embeddings.
  8983. */
  8984. var e = (isOdd(startLevel) ? 'R' : 'L');
  8985. var sor = e;
  8986. var eor = sor;
  8987. /*
  8988. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  8989. type of the NSM to the type of the previous character. If the NSM is at the
  8990. start of the level run, it will get the type of sor.
  8991. */
  8992. var lastType = sor;
  8993. for (i = 0; i < strLength; ++i) {
  8994. if (types[i] === 'NSM') {
  8995. types[i] = lastType;
  8996. } else {
  8997. lastType = types[i];
  8998. }
  8999. }
  9000. /*
  9001. W2. Search backwards from each instance of a European number until the
  9002. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  9003. the type of the European number to Arabic number.
  9004. */
  9005. lastType = sor;
  9006. var t;
  9007. for (i = 0; i < strLength; ++i) {
  9008. t = types[i];
  9009. if (t === 'EN') {
  9010. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  9011. } else if (t === 'R' || t === 'L' || t === 'AL') {
  9012. lastType = t;
  9013. }
  9014. }
  9015. /*
  9016. W3. Change all ALs to R.
  9017. */
  9018. for (i = 0; i < strLength; ++i) {
  9019. t = types[i];
  9020. if (t === 'AL') {
  9021. types[i] = 'R';
  9022. }
  9023. }
  9024. /*
  9025. W4. A single European separator between two European numbers changes to a
  9026. European number. A single common separator between two numbers of the same
  9027. type changes to that type:
  9028. */
  9029. for (i = 1; i < strLength - 1; ++i) {
  9030. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  9031. types[i] = 'EN';
  9032. }
  9033. if (types[i] === 'CS' &&
  9034. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  9035. types[i + 1] === types[i - 1]) {
  9036. types[i] = types[i - 1];
  9037. }
  9038. }
  9039. /*
  9040. W5. A sequence of European terminators adjacent to European numbers changes
  9041. to all European numbers:
  9042. */
  9043. for (i = 0; i < strLength; ++i) {
  9044. if (types[i] === 'EN') {
  9045. // do before
  9046. var j;
  9047. for (j = i - 1; j >= 0; --j) {
  9048. if (types[j] !== 'ET') {
  9049. break;
  9050. }
  9051. types[j] = 'EN';
  9052. }
  9053. // do after
  9054. for (j = i + 1; j < strLength; --j) {
  9055. if (types[j] !== 'ET') {
  9056. break;
  9057. }
  9058. types[j] = 'EN';
  9059. }
  9060. }
  9061. }
  9062. /*
  9063. W6. Otherwise, separators and terminators change to Other Neutral:
  9064. */
  9065. for (i = 0; i < strLength; ++i) {
  9066. t = types[i];
  9067. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  9068. types[i] = 'ON';
  9069. }
  9070. }
  9071. /*
  9072. W7. Search backwards from each instance of a European number until the
  9073. first strong type (R, L, or sor) is found. If an L is found, then change
  9074. the type of the European number to L.
  9075. */
  9076. lastType = sor;
  9077. for (i = 0; i < strLength; ++i) {
  9078. t = types[i];
  9079. if (t === 'EN') {
  9080. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  9081. } else if (t === 'R' || t === 'L') {
  9082. lastType = t;
  9083. }
  9084. }
  9085. /*
  9086. N1. A sequence of neutrals takes the direction of the surrounding strong
  9087. text if the text on both sides has the same direction. European and Arabic
  9088. numbers are treated as though they were R. Start-of-level-run (sor) and
  9089. end-of-level-run (eor) are used at level run boundaries.
  9090. */
  9091. for (i = 0; i < strLength; ++i) {
  9092. if (types[i] === 'ON') {
  9093. var end = findUnequal(types, i + 1, 'ON');
  9094. var before = sor;
  9095. if (i > 0) {
  9096. before = types[i - 1];
  9097. }
  9098. var after = eor;
  9099. if (end + 1 < strLength) {
  9100. after = types[end + 1];
  9101. }
  9102. if (before !== 'L') {
  9103. before = 'R';
  9104. }
  9105. if (after !== 'L') {
  9106. after = 'R';
  9107. }
  9108. if (before === after) {
  9109. setValues(types, i, end, before);
  9110. }
  9111. i = end - 1; // reset to end (-1 so next iteration is ok)
  9112. }
  9113. }
  9114. /*
  9115. N2. Any remaining neutrals take the embedding direction.
  9116. */
  9117. for (i = 0; i < strLength; ++i) {
  9118. if (types[i] === 'ON') {
  9119. types[i] = e;
  9120. }
  9121. }
  9122. /*
  9123. I1. For all characters with an even (left-to-right) embedding direction,
  9124. those of type R go up one level and those of type AN or EN go up two
  9125. levels.
  9126. I2. For all characters with an odd (right-to-left) embedding direction,
  9127. those of type L, EN or AN go up one level.
  9128. */
  9129. for (i = 0; i < strLength; ++i) {
  9130. t = types[i];
  9131. if (isEven(levels[i])) {
  9132. if (t === 'R') {
  9133. levels[i] += 1;
  9134. } else if (t === 'AN' || t === 'EN') {
  9135. levels[i] += 2;
  9136. }
  9137. } else { // isOdd
  9138. if (t === 'L' || t === 'AN' || t === 'EN') {
  9139. levels[i] += 1;
  9140. }
  9141. }
  9142. }
  9143. /*
  9144. L1. On each line, reset the embedding level of the following characters to
  9145. the paragraph embedding level:
  9146. segment separators,
  9147. paragraph separators,
  9148. any sequence of whitespace characters preceding a segment separator or
  9149. paragraph separator, and any sequence of white space characters at the end
  9150. of the line.
  9151. */
  9152. // don't bother as text is only single line
  9153. /*
  9154. L2. From the highest level found in the text to the lowest odd level on
  9155. each line, reverse any contiguous sequence of characters that are at that
  9156. level or higher.
  9157. */
  9158. // find highest level & lowest odd level
  9159. var highestLevel = -1;
  9160. var lowestOddLevel = 99;
  9161. var level;
  9162. for (i = 0, ii = levels.length; i < ii; ++i) {
  9163. level = levels[i];
  9164. if (highestLevel < level) {
  9165. highestLevel = level;
  9166. }
  9167. if (lowestOddLevel > level && isOdd(level)) {
  9168. lowestOddLevel = level;
  9169. }
  9170. }
  9171. // now reverse between those limits
  9172. for (level = highestLevel; level >= lowestOddLevel; --level) {
  9173. // find segments to reverse
  9174. var start = -1;
  9175. for (i = 0, ii = levels.length; i < ii; ++i) {
  9176. if (levels[i] < level) {
  9177. if (start >= 0) {
  9178. reverseValues(chars, start, i);
  9179. start = -1;
  9180. }
  9181. } else if (start < 0) {
  9182. start = i;
  9183. }
  9184. }
  9185. if (start >= 0) {
  9186. reverseValues(chars, start, levels.length);
  9187. }
  9188. }
  9189. /*
  9190. L3. Combining marks applied to a right-to-left base character will at this
  9191. point precede their base character. If the rendering engine expects them to
  9192. follow the base characters in the final display process, then the ordering
  9193. of the marks and the base character must be reversed.
  9194. */
  9195. // don't bother for now
  9196. /*
  9197. L4. A character that possesses the mirrored property as specified by
  9198. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  9199. directionality of that character is R.
  9200. */
  9201. // don't mirror as characters are already mirrored in the pdf
  9202. // Finally, return string
  9203. for (i = 0, ii = chars.length; i < ii; ++i) {
  9204. var ch = chars[i];
  9205. if (ch === '<' || ch === '>') {
  9206. chars[i] = '';
  9207. }
  9208. }
  9209. return createBidiText(chars.join(''), isLTR);
  9210. }
  9211. return bidi;
  9212. })();
  9213. exports.bidi = bidi;
  9214. }));
  9215. (function (root, factory) {
  9216. {
  9217. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  9218. }
  9219. }(this, function (exports, sharedGlobal) {
  9220. var PDFJS = sharedGlobal.PDFJS;
  9221. /**
  9222. * Optimised CSS custom property getter/setter.
  9223. * @class
  9224. */
  9225. var CustomStyle = (function CustomStyleClosure() {
  9226. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  9227. // animate-css-transforms-firefox-webkit.html
  9228. // in some versions of IE9 it is critical that ms appear in this list
  9229. // before Moz
  9230. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  9231. var _cache = {};
  9232. function CustomStyle() {}
  9233. CustomStyle.getProp = function get(propName, element) {
  9234. // check cache only when no element is given
  9235. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  9236. return _cache[propName];
  9237. }
  9238. element = element || document.documentElement;
  9239. var style = element.style, prefixed, uPropName;
  9240. // test standard property first
  9241. if (typeof style[propName] === 'string') {
  9242. return (_cache[propName] = propName);
  9243. }
  9244. // capitalize
  9245. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  9246. // test vendor specific properties
  9247. for (var i = 0, l = prefixes.length; i < l; i++) {
  9248. prefixed = prefixes[i] + uPropName;
  9249. if (typeof style[prefixed] === 'string') {
  9250. return (_cache[propName] = prefixed);
  9251. }
  9252. }
  9253. //if all fails then set to undefined
  9254. return (_cache[propName] = 'undefined');
  9255. };
  9256. CustomStyle.setProp = function set(propName, element, str) {
  9257. var prop = this.getProp(propName);
  9258. if (prop !== 'undefined') {
  9259. element.style[prop] = str;
  9260. }
  9261. };
  9262. return CustomStyle;
  9263. })();
  9264. PDFJS.CustomStyle = CustomStyle;
  9265. exports.CustomStyle = CustomStyle;
  9266. }));
  9267. (function (root, factory) {
  9268. {
  9269. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  9270. }
  9271. }(this, function (exports, sharedGlobal) {
  9272. var PDFJS = sharedGlobal.PDFJS;
  9273. var globalScope = sharedGlobal.globalScope;
  9274. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  9275. var TextRenderingMode = {
  9276. FILL: 0,
  9277. STROKE: 1,
  9278. FILL_STROKE: 2,
  9279. INVISIBLE: 3,
  9280. FILL_ADD_TO_PATH: 4,
  9281. STROKE_ADD_TO_PATH: 5,
  9282. FILL_STROKE_ADD_TO_PATH: 6,
  9283. ADD_TO_PATH: 7,
  9284. FILL_STROKE_MASK: 3,
  9285. ADD_TO_PATH_FLAG: 4
  9286. };
  9287. var ImageKind = {
  9288. GRAYSCALE_1BPP: 1,
  9289. RGB_24BPP: 2,
  9290. RGBA_32BPP: 3
  9291. };
  9292. var AnnotationType = {
  9293. TEXT: 1,
  9294. LINK: 2,
  9295. FREETEXT: 3,
  9296. LINE: 4,
  9297. SQUARE: 5,
  9298. CIRCLE: 6,
  9299. POLYGON: 7,
  9300. POLYLINE: 8,
  9301. HIGHLIGHT: 9,
  9302. UNDERLINE: 10,
  9303. SQUIGGLY: 11,
  9304. STRIKEOUT: 12,
  9305. STAMP: 13,
  9306. CARET: 14,
  9307. INK: 15,
  9308. POPUP: 16,
  9309. FILEATTACHMENT: 17,
  9310. SOUND: 18,
  9311. MOVIE: 19,
  9312. WIDGET: 20,
  9313. SCREEN: 21,
  9314. PRINTERMARK: 22,
  9315. TRAPNET: 23,
  9316. WATERMARK: 24,
  9317. THREED: 25,
  9318. REDACT: 26
  9319. };
  9320. var AnnotationFlag = {
  9321. INVISIBLE: 0x01,
  9322. HIDDEN: 0x02,
  9323. PRINT: 0x04,
  9324. NOZOOM: 0x08,
  9325. NOROTATE: 0x10,
  9326. NOVIEW: 0x20,
  9327. READONLY: 0x40,
  9328. LOCKED: 0x80,
  9329. TOGGLENOVIEW: 0x100,
  9330. LOCKEDCONTENTS: 0x200
  9331. };
  9332. var AnnotationBorderStyleType = {
  9333. SOLID: 1,
  9334. DASHED: 2,
  9335. BEVELED: 3,
  9336. INSET: 4,
  9337. UNDERLINE: 5
  9338. };
  9339. var StreamType = {
  9340. UNKNOWN: 0,
  9341. FLATE: 1,
  9342. LZW: 2,
  9343. DCT: 3,
  9344. JPX: 4,
  9345. JBIG: 5,
  9346. A85: 6,
  9347. AHX: 7,
  9348. CCF: 8,
  9349. RL: 9
  9350. };
  9351. var FontType = {
  9352. UNKNOWN: 0,
  9353. TYPE1: 1,
  9354. TYPE1C: 2,
  9355. CIDFONTTYPE0: 3,
  9356. CIDFONTTYPE0C: 4,
  9357. TRUETYPE: 5,
  9358. CIDFONTTYPE2: 6,
  9359. TYPE3: 7,
  9360. OPENTYPE: 8,
  9361. TYPE0: 9,
  9362. MMTYPE1: 10
  9363. };
  9364. PDFJS.VERBOSITY_LEVELS = {
  9365. errors: 0,
  9366. warnings: 1,
  9367. infos: 5
  9368. };
  9369. // All the possible operations for an operator list.
  9370. var OPS = PDFJS.OPS = {
  9371. // Intentionally start from 1 so it is easy to spot bad operators that will be
  9372. // 0's.
  9373. dependency: 1,
  9374. setLineWidth: 2,
  9375. setLineCap: 3,
  9376. setLineJoin: 4,
  9377. setMiterLimit: 5,
  9378. setDash: 6,
  9379. setRenderingIntent: 7,
  9380. setFlatness: 8,
  9381. setGState: 9,
  9382. save: 10,
  9383. restore: 11,
  9384. transform: 12,
  9385. moveTo: 13,
  9386. lineTo: 14,
  9387. curveTo: 15,
  9388. curveTo2: 16,
  9389. curveTo3: 17,
  9390. closePath: 18,
  9391. rectangle: 19,
  9392. stroke: 20,
  9393. closeStroke: 21,
  9394. fill: 22,
  9395. eoFill: 23,
  9396. fillStroke: 24,
  9397. eoFillStroke: 25,
  9398. closeFillStroke: 26,
  9399. closeEOFillStroke: 27,
  9400. endPath: 28,
  9401. clip: 29,
  9402. eoClip: 30,
  9403. beginText: 31,
  9404. endText: 32,
  9405. setCharSpacing: 33,
  9406. setWordSpacing: 34,
  9407. setHScale: 35,
  9408. setLeading: 36,
  9409. setFont: 37,
  9410. setTextRenderingMode: 38,
  9411. setTextRise: 39,
  9412. moveText: 40,
  9413. setLeadingMoveText: 41,
  9414. setTextMatrix: 42,
  9415. nextLine: 43,
  9416. showText: 44,
  9417. showSpacedText: 45,
  9418. nextLineShowText: 46,
  9419. nextLineSetSpacingShowText: 47,
  9420. setCharWidth: 48,
  9421. setCharWidthAndBounds: 49,
  9422. setStrokeColorSpace: 50,
  9423. setFillColorSpace: 51,
  9424. setStrokeColor: 52,
  9425. setStrokeColorN: 53,
  9426. setFillColor: 54,
  9427. setFillColorN: 55,
  9428. setStrokeGray: 56,
  9429. setFillGray: 57,
  9430. setStrokeRGBColor: 58,
  9431. setFillRGBColor: 59,
  9432. setStrokeCMYKColor: 60,
  9433. setFillCMYKColor: 61,
  9434. shadingFill: 62,
  9435. beginInlineImage: 63,
  9436. beginImageData: 64,
  9437. endInlineImage: 65,
  9438. paintXObject: 66,
  9439. markPoint: 67,
  9440. markPointProps: 68,
  9441. beginMarkedContent: 69,
  9442. beginMarkedContentProps: 70,
  9443. endMarkedContent: 71,
  9444. beginCompat: 72,
  9445. endCompat: 73,
  9446. paintFormXObjectBegin: 74,
  9447. paintFormXObjectEnd: 75,
  9448. beginGroup: 76,
  9449. endGroup: 77,
  9450. beginAnnotations: 78,
  9451. endAnnotations: 79,
  9452. beginAnnotation: 80,
  9453. endAnnotation: 81,
  9454. paintJpegXObject: 82,
  9455. paintImageMaskXObject: 83,
  9456. paintImageMaskXObjectGroup: 84,
  9457. paintImageXObject: 85,
  9458. paintInlineImageXObject: 86,
  9459. paintInlineImageXObjectGroup: 87,
  9460. paintImageXObjectRepeat: 88,
  9461. paintImageMaskXObjectRepeat: 89,
  9462. paintSolidColorImageMask: 90,
  9463. constructPath: 91
  9464. };
  9465. // A notice for devs. These are good for things that are helpful to devs, such
  9466. // as warning that Workers were disabled, which is important to devs but not
  9467. // end users.
  9468. function info(msg) {
  9469. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  9470. console.log('Info: ' + msg);
  9471. }
  9472. }
  9473. // Non-fatal warnings.
  9474. function warn(msg) {
  9475. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  9476. console.log('Warning: ' + msg);
  9477. }
  9478. }
  9479. // Deprecated API function -- treated as warnings.
  9480. function deprecated(details) {
  9481. warn('Deprecated API usage: ' + details);
  9482. }
  9483. // Fatal errors that should trigger the fallback UI and halt execution by
  9484. // throwing an exception.
  9485. function error(msg) {
  9486. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  9487. console.log('Error: ' + msg);
  9488. console.log(backtrace());
  9489. }
  9490. throw new Error(msg);
  9491. }
  9492. function backtrace() {
  9493. try {
  9494. throw new Error();
  9495. } catch (e) {
  9496. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  9497. }
  9498. }
  9499. function assert(cond, msg) {
  9500. if (!cond) {
  9501. error(msg);
  9502. }
  9503. }
  9504. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  9505. unknown: 'unknown',
  9506. forms: 'forms',
  9507. javaScript: 'javaScript',
  9508. smask: 'smask',
  9509. shadingPattern: 'shadingPattern',
  9510. font: 'font'
  9511. };
  9512. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  9513. // absolute URL, it will be returned as is.
  9514. function combineUrl(baseUrl, url) {
  9515. if (!url) {
  9516. return baseUrl;
  9517. }
  9518. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  9519. return url;
  9520. }
  9521. var i;
  9522. if (url.charAt(0) === '/') {
  9523. // absolute path
  9524. i = baseUrl.indexOf('://');
  9525. if (url.charAt(1) === '/') {
  9526. ++i;
  9527. } else {
  9528. i = baseUrl.indexOf('/', i + 3);
  9529. }
  9530. return baseUrl.substring(0, i) + url;
  9531. } else {
  9532. // relative path
  9533. var pathLength = baseUrl.length;
  9534. i = baseUrl.lastIndexOf('#');
  9535. pathLength = i >= 0 ? i : pathLength;
  9536. i = baseUrl.lastIndexOf('?', pathLength);
  9537. pathLength = i >= 0 ? i : pathLength;
  9538. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  9539. return baseUrl.substring(0, prefixLength + 1) + url;
  9540. }
  9541. }
  9542. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  9543. function isValidUrl(url, allowRelative) {
  9544. if (!url) {
  9545. return false;
  9546. }
  9547. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  9548. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  9549. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  9550. if (!protocol) {
  9551. return allowRelative;
  9552. }
  9553. protocol = protocol[0].toLowerCase();
  9554. switch (protocol) {
  9555. case 'http':
  9556. case 'https':
  9557. case 'ftp':
  9558. case 'mailto':
  9559. case 'tel':
  9560. return true;
  9561. default:
  9562. return false;
  9563. }
  9564. }
  9565. PDFJS.isValidUrl = isValidUrl;
  9566. function shadow(obj, prop, value) {
  9567. Object.defineProperty(obj, prop, { value: value,
  9568. enumerable: true,
  9569. configurable: true,
  9570. writable: false });
  9571. return value;
  9572. }
  9573. PDFJS.shadow = shadow;
  9574. var LinkTarget = PDFJS.LinkTarget = {
  9575. NONE: 0, // Default value.
  9576. SELF: 1,
  9577. BLANK: 2,
  9578. PARENT: 3,
  9579. TOP: 4,
  9580. };
  9581. var LinkTargetStringMap = [
  9582. '',
  9583. '_self',
  9584. '_blank',
  9585. '_parent',
  9586. '_top'
  9587. ];
  9588. function isExternalLinkTargetSet() {
  9589. if (PDFJS.openExternalLinksInNewWindow) {
  9590. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  9591. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  9592. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  9593. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  9594. }
  9595. // Reset the deprecated parameter, to suppress further warnings.
  9596. PDFJS.openExternalLinksInNewWindow = false;
  9597. }
  9598. switch (PDFJS.externalLinkTarget) {
  9599. case LinkTarget.NONE:
  9600. return false;
  9601. case LinkTarget.SELF:
  9602. case LinkTarget.BLANK:
  9603. case LinkTarget.PARENT:
  9604. case LinkTarget.TOP:
  9605. return true;
  9606. }
  9607. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  9608. // Reset the external link target, to suppress further warnings.
  9609. PDFJS.externalLinkTarget = LinkTarget.NONE;
  9610. return false;
  9611. }
  9612. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  9613. var PasswordResponses = PDFJS.PasswordResponses = {
  9614. NEED_PASSWORD: 1,
  9615. INCORRECT_PASSWORD: 2
  9616. };
  9617. var PasswordException = (function PasswordExceptionClosure() {
  9618. function PasswordException(msg, code) {
  9619. this.name = 'PasswordException';
  9620. this.message = msg;
  9621. this.code = code;
  9622. }
  9623. PasswordException.prototype = new Error();
  9624. PasswordException.constructor = PasswordException;
  9625. return PasswordException;
  9626. })();
  9627. PDFJS.PasswordException = PasswordException;
  9628. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  9629. function UnknownErrorException(msg, details) {
  9630. this.name = 'UnknownErrorException';
  9631. this.message = msg;
  9632. this.details = details;
  9633. }
  9634. UnknownErrorException.prototype = new Error();
  9635. UnknownErrorException.constructor = UnknownErrorException;
  9636. return UnknownErrorException;
  9637. })();
  9638. PDFJS.UnknownErrorException = UnknownErrorException;
  9639. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  9640. function InvalidPDFException(msg) {
  9641. this.name = 'InvalidPDFException';
  9642. this.message = msg;
  9643. }
  9644. InvalidPDFException.prototype = new Error();
  9645. InvalidPDFException.constructor = InvalidPDFException;
  9646. return InvalidPDFException;
  9647. })();
  9648. PDFJS.InvalidPDFException = InvalidPDFException;
  9649. var MissingPDFException = (function MissingPDFExceptionClosure() {
  9650. function MissingPDFException(msg) {
  9651. this.name = 'MissingPDFException';
  9652. this.message = msg;
  9653. }
  9654. MissingPDFException.prototype = new Error();
  9655. MissingPDFException.constructor = MissingPDFException;
  9656. return MissingPDFException;
  9657. })();
  9658. PDFJS.MissingPDFException = MissingPDFException;
  9659. var UnexpectedResponseException =
  9660. (function UnexpectedResponseExceptionClosure() {
  9661. function UnexpectedResponseException(msg, status) {
  9662. this.name = 'UnexpectedResponseException';
  9663. this.message = msg;
  9664. this.status = status;
  9665. }
  9666. UnexpectedResponseException.prototype = new Error();
  9667. UnexpectedResponseException.constructor = UnexpectedResponseException;
  9668. return UnexpectedResponseException;
  9669. })();
  9670. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  9671. var NotImplementedException = (function NotImplementedExceptionClosure() {
  9672. function NotImplementedException(msg) {
  9673. this.message = msg;
  9674. }
  9675. NotImplementedException.prototype = new Error();
  9676. NotImplementedException.prototype.name = 'NotImplementedException';
  9677. NotImplementedException.constructor = NotImplementedException;
  9678. return NotImplementedException;
  9679. })();
  9680. var MissingDataException = (function MissingDataExceptionClosure() {
  9681. function MissingDataException(begin, end) {
  9682. this.begin = begin;
  9683. this.end = end;
  9684. this.message = 'Missing data [' + begin + ', ' + end + ')';
  9685. }
  9686. MissingDataException.prototype = new Error();
  9687. MissingDataException.prototype.name = 'MissingDataException';
  9688. MissingDataException.constructor = MissingDataException;
  9689. return MissingDataException;
  9690. })();
  9691. var XRefParseException = (function XRefParseExceptionClosure() {
  9692. function XRefParseException(msg) {
  9693. this.message = msg;
  9694. }
  9695. XRefParseException.prototype = new Error();
  9696. XRefParseException.prototype.name = 'XRefParseException';
  9697. XRefParseException.constructor = XRefParseException;
  9698. return XRefParseException;
  9699. })();
  9700. function bytesToString(bytes) {
  9701. assert(bytes !== null && typeof bytes === 'object' &&
  9702. bytes.length !== undefined, 'Invalid argument for bytesToString');
  9703. var length = bytes.length;
  9704. var MAX_ARGUMENT_COUNT = 8192;
  9705. if (length < MAX_ARGUMENT_COUNT) {
  9706. return String.fromCharCode.apply(null, bytes);
  9707. }
  9708. var strBuf = [];
  9709. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  9710. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  9711. var chunk = bytes.subarray(i, chunkEnd);
  9712. strBuf.push(String.fromCharCode.apply(null, chunk));
  9713. }
  9714. return strBuf.join('');
  9715. }
  9716. function stringToBytes(str) {
  9717. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  9718. var length = str.length;
  9719. var bytes = new Uint8Array(length);
  9720. for (var i = 0; i < length; ++i) {
  9721. bytes[i] = str.charCodeAt(i) & 0xFF;
  9722. }
  9723. return bytes;
  9724. }
  9725. function string32(value) {
  9726. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  9727. (value >> 8) & 0xff, value & 0xff);
  9728. }
  9729. function log2(x) {
  9730. var n = 1, i = 0;
  9731. while (x > n) {
  9732. n <<= 1;
  9733. i++;
  9734. }
  9735. return i;
  9736. }
  9737. function readInt8(data, start) {
  9738. return (data[start] << 24) >> 24;
  9739. }
  9740. function readUint16(data, offset) {
  9741. return (data[offset] << 8) | data[offset + 1];
  9742. }
  9743. function readUint32(data, offset) {
  9744. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  9745. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  9746. }
  9747. // Lazy test the endianness of the platform
  9748. // NOTE: This will be 'true' for simulated TypedArrays
  9749. function isLittleEndian() {
  9750. var buffer8 = new Uint8Array(2);
  9751. buffer8[0] = 1;
  9752. var buffer16 = new Uint16Array(buffer8.buffer);
  9753. return (buffer16[0] === 1);
  9754. }
  9755. Object.defineProperty(PDFJS, 'isLittleEndian', {
  9756. configurable: true,
  9757. get: function PDFJS_isLittleEndian() {
  9758. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  9759. }
  9760. });
  9761. // Lazy test if the userAgent support CanvasTypedArrays
  9762. function hasCanvasTypedArrays() {
  9763. var canvas = document.createElement('canvas');
  9764. canvas.width = canvas.height = 1;
  9765. var ctx = canvas.getContext('2d');
  9766. var imageData = ctx.createImageData(1, 1);
  9767. return (typeof imageData.data.buffer !== 'undefined');
  9768. }
  9769. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  9770. configurable: true,
  9771. get: function PDFJS_hasCanvasTypedArrays() {
  9772. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  9773. }
  9774. });
  9775. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  9776. function Uint32ArrayView(buffer, length) {
  9777. this.buffer = buffer;
  9778. this.byteLength = buffer.length;
  9779. this.length = length === undefined ? (this.byteLength >> 2) : length;
  9780. ensureUint32ArrayViewProps(this.length);
  9781. }
  9782. Uint32ArrayView.prototype = Object.create(null);
  9783. var uint32ArrayViewSetters = 0;
  9784. function createUint32ArrayProp(index) {
  9785. return {
  9786. get: function () {
  9787. var buffer = this.buffer, offset = index << 2;
  9788. return (buffer[offset] | (buffer[offset + 1] << 8) |
  9789. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  9790. },
  9791. set: function (value) {
  9792. var buffer = this.buffer, offset = index << 2;
  9793. buffer[offset] = value & 255;
  9794. buffer[offset + 1] = (value >> 8) & 255;
  9795. buffer[offset + 2] = (value >> 16) & 255;
  9796. buffer[offset + 3] = (value >>> 24) & 255;
  9797. }
  9798. };
  9799. }
  9800. function ensureUint32ArrayViewProps(length) {
  9801. while (uint32ArrayViewSetters < length) {
  9802. Object.defineProperty(Uint32ArrayView.prototype,
  9803. uint32ArrayViewSetters,
  9804. createUint32ArrayProp(uint32ArrayViewSetters));
  9805. uint32ArrayViewSetters++;
  9806. }
  9807. }
  9808. return Uint32ArrayView;
  9809. })();
  9810. exports.Uint32ArrayView = Uint32ArrayView;
  9811. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  9812. var Util = PDFJS.Util = (function UtilClosure() {
  9813. function Util() {}
  9814. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  9815. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  9816. // creating many intermediate strings.
  9817. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  9818. rgbBuf[1] = r;
  9819. rgbBuf[3] = g;
  9820. rgbBuf[5] = b;
  9821. return rgbBuf.join('');
  9822. };
  9823. // Concatenates two transformation matrices together and returns the result.
  9824. Util.transform = function Util_transform(m1, m2) {
  9825. return [
  9826. m1[0] * m2[0] + m1[2] * m2[1],
  9827. m1[1] * m2[0] + m1[3] * m2[1],
  9828. m1[0] * m2[2] + m1[2] * m2[3],
  9829. m1[1] * m2[2] + m1[3] * m2[3],
  9830. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  9831. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  9832. ];
  9833. };
  9834. // For 2d affine transforms
  9835. Util.applyTransform = function Util_applyTransform(p, m) {
  9836. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  9837. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  9838. return [xt, yt];
  9839. };
  9840. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  9841. var d = m[0] * m[3] - m[1] * m[2];
  9842. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  9843. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  9844. return [xt, yt];
  9845. };
  9846. // Applies the transform to the rectangle and finds the minimum axially
  9847. // aligned bounding box.
  9848. Util.getAxialAlignedBoundingBox =
  9849. function Util_getAxialAlignedBoundingBox(r, m) {
  9850. var p1 = Util.applyTransform(r, m);
  9851. var p2 = Util.applyTransform(r.slice(2, 4), m);
  9852. var p3 = Util.applyTransform([r[0], r[3]], m);
  9853. var p4 = Util.applyTransform([r[2], r[1]], m);
  9854. return [
  9855. Math.min(p1[0], p2[0], p3[0], p4[0]),
  9856. Math.min(p1[1], p2[1], p3[1], p4[1]),
  9857. Math.max(p1[0], p2[0], p3[0], p4[0]),
  9858. Math.max(p1[1], p2[1], p3[1], p4[1])
  9859. ];
  9860. };
  9861. Util.inverseTransform = function Util_inverseTransform(m) {
  9862. var d = m[0] * m[3] - m[1] * m[2];
  9863. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  9864. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  9865. };
  9866. // Apply a generic 3d matrix M on a 3-vector v:
  9867. // | a b c | | X |
  9868. // | d e f | x | Y |
  9869. // | g h i | | Z |
  9870. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  9871. // with v as [X,Y,Z]
  9872. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  9873. return [
  9874. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  9875. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  9876. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  9877. ];
  9878. };
  9879. // This calculation uses Singular Value Decomposition.
  9880. // The SVD can be represented with formula A = USV. We are interested in the
  9881. // matrix S here because it represents the scale values.
  9882. Util.singularValueDecompose2dScale =
  9883. function Util_singularValueDecompose2dScale(m) {
  9884. var transpose = [m[0], m[2], m[1], m[3]];
  9885. // Multiply matrix m with its transpose.
  9886. var a = m[0] * transpose[0] + m[1] * transpose[2];
  9887. var b = m[0] * transpose[1] + m[1] * transpose[3];
  9888. var c = m[2] * transpose[0] + m[3] * transpose[2];
  9889. var d = m[2] * transpose[1] + m[3] * transpose[3];
  9890. // Solve the second degree polynomial to get roots.
  9891. var first = (a + d) / 2;
  9892. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  9893. var sx = first + second || 1;
  9894. var sy = first - second || 1;
  9895. // Scale values are the square roots of the eigenvalues.
  9896. return [Math.sqrt(sx), Math.sqrt(sy)];
  9897. };
  9898. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  9899. // For coordinate systems whose origin lies in the bottom-left, this
  9900. // means normalization to (BL,TR) ordering. For systems with origin in the
  9901. // top-left, this means (TL,BR) ordering.
  9902. Util.normalizeRect = function Util_normalizeRect(rect) {
  9903. var r = rect.slice(0); // clone rect
  9904. if (rect[0] > rect[2]) {
  9905. r[0] = rect[2];
  9906. r[2] = rect[0];
  9907. }
  9908. if (rect[1] > rect[3]) {
  9909. r[1] = rect[3];
  9910. r[3] = rect[1];
  9911. }
  9912. return r;
  9913. };
  9914. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  9915. // intersection of rect1 and rect2. If no intersection, returns 'false'
  9916. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  9917. Util.intersect = function Util_intersect(rect1, rect2) {
  9918. function compare(a, b) {
  9919. return a - b;
  9920. }
  9921. // Order points along the axes
  9922. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  9923. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  9924. result = [];
  9925. rect1 = Util.normalizeRect(rect1);
  9926. rect2 = Util.normalizeRect(rect2);
  9927. // X: first and second points belong to different rectangles?
  9928. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  9929. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  9930. // Intersection must be between second and third points
  9931. result[0] = orderedX[1];
  9932. result[2] = orderedX[2];
  9933. } else {
  9934. return false;
  9935. }
  9936. // Y: first and second points belong to different rectangles?
  9937. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  9938. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  9939. // Intersection must be between second and third points
  9940. result[1] = orderedY[1];
  9941. result[3] = orderedY[2];
  9942. } else {
  9943. return false;
  9944. }
  9945. return result;
  9946. };
  9947. Util.sign = function Util_sign(num) {
  9948. return num < 0 ? -1 : 1;
  9949. };
  9950. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  9951. Array.prototype.push.apply(arr1, arr2);
  9952. };
  9953. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  9954. Array.prototype.unshift.apply(arr1, arr2);
  9955. };
  9956. Util.extendObj = function extendObj(obj1, obj2) {
  9957. for (var key in obj2) {
  9958. obj1[key] = obj2[key];
  9959. }
  9960. };
  9961. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  9962. name) {
  9963. while (dict && !dict.has(name)) {
  9964. dict = dict.get('Parent');
  9965. }
  9966. if (!dict) {
  9967. return null;
  9968. }
  9969. return dict.get(name);
  9970. };
  9971. Util.inherit = function Util_inherit(sub, base, prototype) {
  9972. sub.prototype = Object.create(base.prototype);
  9973. sub.prototype.constructor = sub;
  9974. for (var prop in prototype) {
  9975. sub.prototype[prop] = prototype[prop];
  9976. }
  9977. };
  9978. Util.loadScript = function Util_loadScript(src, callback) {
  9979. var script = document.createElement('script');
  9980. var loaded = false;
  9981. script.setAttribute('src', src);
  9982. if (callback) {
  9983. script.onload = function() {
  9984. if (!loaded) {
  9985. callback();
  9986. }
  9987. loaded = true;
  9988. };
  9989. }
  9990. document.getElementsByTagName('head')[0].appendChild(script);
  9991. };
  9992. return Util;
  9993. })();
  9994. /**
  9995. * PDF page viewport created based on scale, rotation and offset.
  9996. * @class
  9997. * @alias PDFJS.PageViewport
  9998. */
  9999. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  10000. /**
  10001. * @constructor
  10002. * @private
  10003. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  10004. * @param scale {number} scale of the viewport.
  10005. * @param rotation {number} rotations of the viewport in degrees.
  10006. * @param offsetX {number} offset X
  10007. * @param offsetY {number} offset Y
  10008. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  10009. */
  10010. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  10011. this.viewBox = viewBox;
  10012. this.scale = scale;
  10013. this.rotation = rotation;
  10014. this.offsetX = offsetX;
  10015. this.offsetY = offsetY;
  10016. // creating transform to convert pdf coordinate system to the normal
  10017. // canvas like coordinates taking in account scale and rotation
  10018. var centerX = (viewBox[2] + viewBox[0]) / 2;
  10019. var centerY = (viewBox[3] + viewBox[1]) / 2;
  10020. var rotateA, rotateB, rotateC, rotateD;
  10021. rotation = rotation % 360;
  10022. rotation = rotation < 0 ? rotation + 360 : rotation;
  10023. switch (rotation) {
  10024. case 180:
  10025. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  10026. break;
  10027. case 90:
  10028. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  10029. break;
  10030. case 270:
  10031. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  10032. break;
  10033. //case 0:
  10034. default:
  10035. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  10036. break;
  10037. }
  10038. if (dontFlip) {
  10039. rotateC = -rotateC; rotateD = -rotateD;
  10040. }
  10041. var offsetCanvasX, offsetCanvasY;
  10042. var width, height;
  10043. if (rotateA === 0) {
  10044. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  10045. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  10046. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10047. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10048. } else {
  10049. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  10050. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  10051. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10052. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10053. }
  10054. // creating transform for the following operations:
  10055. // translate(-centerX, -centerY), rotate and flip vertically,
  10056. // scale, and translate(offsetCanvasX, offsetCanvasY)
  10057. this.transform = [
  10058. rotateA * scale,
  10059. rotateB * scale,
  10060. rotateC * scale,
  10061. rotateD * scale,
  10062. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  10063. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  10064. ];
  10065. this.width = width;
  10066. this.height = height;
  10067. this.fontScale = scale;
  10068. }
  10069. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  10070. /**
  10071. * Clones viewport with additional properties.
  10072. * @param args {Object} (optional) If specified, may contain the 'scale' or
  10073. * 'rotation' properties to override the corresponding properties in
  10074. * the cloned viewport.
  10075. * @returns {PDFJS.PageViewport} Cloned viewport.
  10076. */
  10077. clone: function PageViewPort_clone(args) {
  10078. args = args || {};
  10079. var scale = 'scale' in args ? args.scale : this.scale;
  10080. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  10081. return new PageViewport(this.viewBox.slice(), scale, rotation,
  10082. this.offsetX, this.offsetY, args.dontFlip);
  10083. },
  10084. /**
  10085. * Converts PDF point to the viewport coordinates. For examples, useful for
  10086. * converting PDF location into canvas pixel coordinates.
  10087. * @param x {number} X coordinate.
  10088. * @param y {number} Y coordinate.
  10089. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10090. * point in the viewport coordinate space.
  10091. * @see {@link convertToPdfPoint}
  10092. * @see {@link convertToViewportRectangle}
  10093. */
  10094. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  10095. return Util.applyTransform([x, y], this.transform);
  10096. },
  10097. /**
  10098. * Converts PDF rectangle to the viewport coordinates.
  10099. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  10100. * @returns {Array} Contains corresponding coordinates of the rectangle
  10101. * in the viewport coordinate space.
  10102. * @see {@link convertToViewportPoint}
  10103. */
  10104. convertToViewportRectangle:
  10105. function PageViewport_convertToViewportRectangle(rect) {
  10106. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  10107. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  10108. return [tl[0], tl[1], br[0], br[1]];
  10109. },
  10110. /**
  10111. * Converts viewport coordinates to the PDF location. For examples, useful
  10112. * for converting canvas pixel location into PDF one.
  10113. * @param x {number} X coordinate.
  10114. * @param y {number} Y coordinate.
  10115. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10116. * point in the PDF coordinate space.
  10117. * @see {@link convertToViewportPoint}
  10118. */
  10119. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  10120. return Util.applyInverseTransform([x, y], this.transform);
  10121. }
  10122. };
  10123. return PageViewport;
  10124. })();
  10125. var PDFStringTranslateTable = [
  10126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10127. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  10128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  10132. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  10133. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  10134. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  10135. ];
  10136. function stringToPDFString(str) {
  10137. var i, n = str.length, strBuf = [];
  10138. if (str[0] === '\xFE' && str[1] === '\xFF') {
  10139. // UTF16BE BOM
  10140. for (i = 2; i < n; i += 2) {
  10141. strBuf.push(String.fromCharCode(
  10142. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  10143. }
  10144. } else {
  10145. for (i = 0; i < n; ++i) {
  10146. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  10147. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  10148. }
  10149. }
  10150. return strBuf.join('');
  10151. }
  10152. function stringToUTF8String(str) {
  10153. return decodeURIComponent(escape(str));
  10154. }
  10155. function utf8StringToString(str) {
  10156. return unescape(encodeURIComponent(str));
  10157. }
  10158. function isEmptyObj(obj) {
  10159. for (var key in obj) {
  10160. return false;
  10161. }
  10162. return true;
  10163. }
  10164. function isBool(v) {
  10165. return typeof v === 'boolean';
  10166. }
  10167. function isInt(v) {
  10168. return typeof v === 'number' && ((v | 0) === v);
  10169. }
  10170. function isNum(v) {
  10171. return typeof v === 'number';
  10172. }
  10173. function isString(v) {
  10174. return typeof v === 'string';
  10175. }
  10176. function isArray(v) {
  10177. return v instanceof Array;
  10178. }
  10179. function isArrayBuffer(v) {
  10180. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  10181. }
  10182. /**
  10183. * Promise Capability object.
  10184. *
  10185. * @typedef {Object} PromiseCapability
  10186. * @property {Promise} promise - A promise object.
  10187. * @property {function} resolve - Fullfills the promise.
  10188. * @property {function} reject - Rejects the promise.
  10189. */
  10190. /**
  10191. * Creates a promise capability object.
  10192. * @alias PDFJS.createPromiseCapability
  10193. *
  10194. * @return {PromiseCapability} A capability object contains:
  10195. * - a Promise, resolve and reject methods.
  10196. */
  10197. function createPromiseCapability() {
  10198. var capability = {};
  10199. capability.promise = new Promise(function (resolve, reject) {
  10200. capability.resolve = resolve;
  10201. capability.reject = reject;
  10202. });
  10203. return capability;
  10204. }
  10205. PDFJS.createPromiseCapability = createPromiseCapability;
  10206. /**
  10207. * Polyfill for Promises:
  10208. * The following promise implementation tries to generally implement the
  10209. * Promise/A+ spec. Some notable differences from other promise libaries are:
  10210. * - There currently isn't a seperate deferred and promise object.
  10211. * - Unhandled rejections eventually show an error if they aren't handled.
  10212. *
  10213. * Based off of the work in:
  10214. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  10215. */
  10216. (function PromiseClosure() {
  10217. if (globalScope.Promise) {
  10218. // Promises existing in the DOM/Worker, checking presence of all/resolve
  10219. if (typeof globalScope.Promise.all !== 'function') {
  10220. globalScope.Promise.all = function (iterable) {
  10221. var count = 0, results = [], resolve, reject;
  10222. var promise = new globalScope.Promise(function (resolve_, reject_) {
  10223. resolve = resolve_;
  10224. reject = reject_;
  10225. });
  10226. iterable.forEach(function (p, i) {
  10227. count++;
  10228. p.then(function (result) {
  10229. results[i] = result;
  10230. count--;
  10231. if (count === 0) {
  10232. resolve(results);
  10233. }
  10234. }, reject);
  10235. });
  10236. if (count === 0) {
  10237. resolve(results);
  10238. }
  10239. return promise;
  10240. };
  10241. }
  10242. if (typeof globalScope.Promise.resolve !== 'function') {
  10243. globalScope.Promise.resolve = function (value) {
  10244. return new globalScope.Promise(function (resolve) { resolve(value); });
  10245. };
  10246. }
  10247. if (typeof globalScope.Promise.reject !== 'function') {
  10248. globalScope.Promise.reject = function (reason) {
  10249. return new globalScope.Promise(function (resolve, reject) {
  10250. reject(reason);
  10251. });
  10252. };
  10253. }
  10254. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  10255. globalScope.Promise.prototype.catch = function (onReject) {
  10256. return globalScope.Promise.prototype.then(undefined, onReject);
  10257. };
  10258. }
  10259. return;
  10260. }
  10261. var STATUS_PENDING = 0;
  10262. var STATUS_RESOLVED = 1;
  10263. var STATUS_REJECTED = 2;
  10264. // In an attempt to avoid silent exceptions, unhandled rejections are
  10265. // tracked and if they aren't handled in a certain amount of time an
  10266. // error is logged.
  10267. var REJECTION_TIMEOUT = 500;
  10268. var HandlerManager = {
  10269. handlers: [],
  10270. running: false,
  10271. unhandledRejections: [],
  10272. pendingRejectionCheck: false,
  10273. scheduleHandlers: function scheduleHandlers(promise) {
  10274. if (promise._status === STATUS_PENDING) {
  10275. return;
  10276. }
  10277. this.handlers = this.handlers.concat(promise._handlers);
  10278. promise._handlers = [];
  10279. if (this.running) {
  10280. return;
  10281. }
  10282. this.running = true;
  10283. setTimeout(this.runHandlers.bind(this), 0);
  10284. },
  10285. runHandlers: function runHandlers() {
  10286. var RUN_TIMEOUT = 1; // ms
  10287. var timeoutAt = Date.now() + RUN_TIMEOUT;
  10288. while (this.handlers.length > 0) {
  10289. var handler = this.handlers.shift();
  10290. var nextStatus = handler.thisPromise._status;
  10291. var nextValue = handler.thisPromise._value;
  10292. try {
  10293. if (nextStatus === STATUS_RESOLVED) {
  10294. if (typeof handler.onResolve === 'function') {
  10295. nextValue = handler.onResolve(nextValue);
  10296. }
  10297. } else if (typeof handler.onReject === 'function') {
  10298. nextValue = handler.onReject(nextValue);
  10299. nextStatus = STATUS_RESOLVED;
  10300. if (handler.thisPromise._unhandledRejection) {
  10301. this.removeUnhandeledRejection(handler.thisPromise);
  10302. }
  10303. }
  10304. } catch (ex) {
  10305. nextStatus = STATUS_REJECTED;
  10306. nextValue = ex;
  10307. }
  10308. handler.nextPromise._updateStatus(nextStatus, nextValue);
  10309. if (Date.now() >= timeoutAt) {
  10310. break;
  10311. }
  10312. }
  10313. if (this.handlers.length > 0) {
  10314. setTimeout(this.runHandlers.bind(this), 0);
  10315. return;
  10316. }
  10317. this.running = false;
  10318. },
  10319. addUnhandledRejection: function addUnhandledRejection(promise) {
  10320. this.unhandledRejections.push({
  10321. promise: promise,
  10322. time: Date.now()
  10323. });
  10324. this.scheduleRejectionCheck();
  10325. },
  10326. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  10327. promise._unhandledRejection = false;
  10328. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10329. if (this.unhandledRejections[i].promise === promise) {
  10330. this.unhandledRejections.splice(i);
  10331. i--;
  10332. }
  10333. }
  10334. },
  10335. scheduleRejectionCheck: function scheduleRejectionCheck() {
  10336. if (this.pendingRejectionCheck) {
  10337. return;
  10338. }
  10339. this.pendingRejectionCheck = true;
  10340. setTimeout(function rejectionCheck() {
  10341. this.pendingRejectionCheck = false;
  10342. var now = Date.now();
  10343. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10344. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  10345. var unhandled = this.unhandledRejections[i].promise._value;
  10346. var msg = 'Unhandled rejection: ' + unhandled;
  10347. if (unhandled.stack) {
  10348. msg += '\n' + unhandled.stack;
  10349. }
  10350. warn(msg);
  10351. this.unhandledRejections.splice(i);
  10352. i--;
  10353. }
  10354. }
  10355. if (this.unhandledRejections.length) {
  10356. this.scheduleRejectionCheck();
  10357. }
  10358. }.bind(this), REJECTION_TIMEOUT);
  10359. }
  10360. };
  10361. function Promise(resolver) {
  10362. this._status = STATUS_PENDING;
  10363. this._handlers = [];
  10364. try {
  10365. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  10366. } catch (e) {
  10367. this._reject(e);
  10368. }
  10369. }
  10370. /**
  10371. * Builds a promise that is resolved when all the passed in promises are
  10372. * resolved.
  10373. * @param {array} array of data and/or promises to wait for.
  10374. * @return {Promise} New dependant promise.
  10375. */
  10376. Promise.all = function Promise_all(promises) {
  10377. var resolveAll, rejectAll;
  10378. var deferred = new Promise(function (resolve, reject) {
  10379. resolveAll = resolve;
  10380. rejectAll = reject;
  10381. });
  10382. var unresolved = promises.length;
  10383. var results = [];
  10384. if (unresolved === 0) {
  10385. resolveAll(results);
  10386. return deferred;
  10387. }
  10388. function reject(reason) {
  10389. if (deferred._status === STATUS_REJECTED) {
  10390. return;
  10391. }
  10392. results = [];
  10393. rejectAll(reason);
  10394. }
  10395. for (var i = 0, ii = promises.length; i < ii; ++i) {
  10396. var promise = promises[i];
  10397. var resolve = (function(i) {
  10398. return function(value) {
  10399. if (deferred._status === STATUS_REJECTED) {
  10400. return;
  10401. }
  10402. results[i] = value;
  10403. unresolved--;
  10404. if (unresolved === 0) {
  10405. resolveAll(results);
  10406. }
  10407. };
  10408. })(i);
  10409. if (Promise.isPromise(promise)) {
  10410. promise.then(resolve, reject);
  10411. } else {
  10412. resolve(promise);
  10413. }
  10414. }
  10415. return deferred;
  10416. };
  10417. /**
  10418. * Checks if the value is likely a promise (has a 'then' function).
  10419. * @return {boolean} true if value is thenable
  10420. */
  10421. Promise.isPromise = function Promise_isPromise(value) {
  10422. return value && typeof value.then === 'function';
  10423. };
  10424. /**
  10425. * Creates resolved promise
  10426. * @param value resolve value
  10427. * @returns {Promise}
  10428. */
  10429. Promise.resolve = function Promise_resolve(value) {
  10430. return new Promise(function (resolve) { resolve(value); });
  10431. };
  10432. /**
  10433. * Creates rejected promise
  10434. * @param reason rejection value
  10435. * @returns {Promise}
  10436. */
  10437. Promise.reject = function Promise_reject(reason) {
  10438. return new Promise(function (resolve, reject) { reject(reason); });
  10439. };
  10440. Promise.prototype = {
  10441. _status: null,
  10442. _value: null,
  10443. _handlers: null,
  10444. _unhandledRejection: null,
  10445. _updateStatus: function Promise__updateStatus(status, value) {
  10446. if (this._status === STATUS_RESOLVED ||
  10447. this._status === STATUS_REJECTED) {
  10448. return;
  10449. }
  10450. if (status === STATUS_RESOLVED &&
  10451. Promise.isPromise(value)) {
  10452. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  10453. this._updateStatus.bind(this, STATUS_REJECTED));
  10454. return;
  10455. }
  10456. this._status = status;
  10457. this._value = value;
  10458. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  10459. this._unhandledRejection = true;
  10460. HandlerManager.addUnhandledRejection(this);
  10461. }
  10462. HandlerManager.scheduleHandlers(this);
  10463. },
  10464. _resolve: function Promise_resolve(value) {
  10465. this._updateStatus(STATUS_RESOLVED, value);
  10466. },
  10467. _reject: function Promise_reject(reason) {
  10468. this._updateStatus(STATUS_REJECTED, reason);
  10469. },
  10470. then: function Promise_then(onResolve, onReject) {
  10471. var nextPromise = new Promise(function (resolve, reject) {
  10472. this.resolve = resolve;
  10473. this.reject = reject;
  10474. });
  10475. this._handlers.push({
  10476. thisPromise: this,
  10477. onResolve: onResolve,
  10478. onReject: onReject,
  10479. nextPromise: nextPromise
  10480. });
  10481. HandlerManager.scheduleHandlers(this);
  10482. return nextPromise;
  10483. },
  10484. catch: function Promise_catch(onReject) {
  10485. return this.then(undefined, onReject);
  10486. }
  10487. };
  10488. globalScope.Promise = Promise;
  10489. })();
  10490. var StatTimer = (function StatTimerClosure() {
  10491. function rpad(str, pad, length) {
  10492. while (str.length < length) {
  10493. str += pad;
  10494. }
  10495. return str;
  10496. }
  10497. function StatTimer() {
  10498. this.started = {};
  10499. this.times = [];
  10500. this.enabled = true;
  10501. }
  10502. StatTimer.prototype = {
  10503. time: function StatTimer_time(name) {
  10504. if (!this.enabled) {
  10505. return;
  10506. }
  10507. if (name in this.started) {
  10508. warn('Timer is already running for ' + name);
  10509. }
  10510. this.started[name] = Date.now();
  10511. },
  10512. timeEnd: function StatTimer_timeEnd(name) {
  10513. if (!this.enabled) {
  10514. return;
  10515. }
  10516. if (!(name in this.started)) {
  10517. warn('Timer has not been started for ' + name);
  10518. }
  10519. this.times.push({
  10520. 'name': name,
  10521. 'start': this.started[name],
  10522. 'end': Date.now()
  10523. });
  10524. // Remove timer from started so it can be called again.
  10525. delete this.started[name];
  10526. },
  10527. toString: function StatTimer_toString() {
  10528. var i, ii;
  10529. var times = this.times;
  10530. var out = '';
  10531. // Find the longest name for padding purposes.
  10532. var longest = 0;
  10533. for (i = 0, ii = times.length; i < ii; ++i) {
  10534. var name = times[i]['name'];
  10535. if (name.length > longest) {
  10536. longest = name.length;
  10537. }
  10538. }
  10539. for (i = 0, ii = times.length; i < ii; ++i) {
  10540. var span = times[i];
  10541. var duration = span.end - span.start;
  10542. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  10543. }
  10544. return out;
  10545. }
  10546. };
  10547. return StatTimer;
  10548. })();
  10549. PDFJS.createBlob = function createBlob(data, contentType) {
  10550. if (typeof Blob !== 'undefined') {
  10551. return new Blob([data], { type: contentType });
  10552. }
  10553. // Blob builder is deprecated in FF14 and removed in FF18.
  10554. var bb = new MozBlobBuilder();
  10555. bb.append(data);
  10556. return bb.getBlob(contentType);
  10557. };
  10558. PDFJS.createObjectURL = (function createObjectURLClosure() {
  10559. // Blob/createObjectURL is not available, falling back to data schema.
  10560. var digits =
  10561. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  10562. return function createObjectURL(data, contentType) {
  10563. if (!PDFJS.disableCreateObjectURL &&
  10564. typeof URL !== 'undefined' && URL.createObjectURL) {
  10565. var blob = PDFJS.createBlob(data, contentType);
  10566. return URL.createObjectURL(blob);
  10567. }
  10568. var buffer = 'data:' + contentType + ';base64,';
  10569. for (var i = 0, ii = data.length; i < ii; i += 3) {
  10570. var b1 = data[i] & 0xFF;
  10571. var b2 = data[i + 1] & 0xFF;
  10572. var b3 = data[i + 2] & 0xFF;
  10573. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  10574. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  10575. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  10576. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  10577. }
  10578. return buffer;
  10579. };
  10580. })();
  10581. function MessageHandler(sourceName, targetName, comObj) {
  10582. this.sourceName = sourceName;
  10583. this.targetName = targetName;
  10584. this.comObj = comObj;
  10585. this.callbackIndex = 1;
  10586. this.postMessageTransfers = true;
  10587. var callbacksCapabilities = this.callbacksCapabilities = {};
  10588. var ah = this.actionHandler = {};
  10589. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  10590. var data = event.data;
  10591. if (data.targetName !== this.sourceName) {
  10592. return;
  10593. }
  10594. if (data.isReply) {
  10595. var callbackId = data.callbackId;
  10596. if (data.callbackId in callbacksCapabilities) {
  10597. var callback = callbacksCapabilities[callbackId];
  10598. delete callbacksCapabilities[callbackId];
  10599. if ('error' in data) {
  10600. callback.reject(data.error);
  10601. } else {
  10602. callback.resolve(data.data);
  10603. }
  10604. } else {
  10605. error('Cannot resolve callback ' + callbackId);
  10606. }
  10607. } else if (data.action in ah) {
  10608. var action = ah[data.action];
  10609. if (data.callbackId) {
  10610. var sourceName = this.sourceName;
  10611. var targetName = data.sourceName;
  10612. Promise.resolve().then(function () {
  10613. return action[0].call(action[1], data.data);
  10614. }).then(function (result) {
  10615. comObj.postMessage({
  10616. sourceName: sourceName,
  10617. targetName: targetName,
  10618. isReply: true,
  10619. callbackId: data.callbackId,
  10620. data: result
  10621. });
  10622. }, function (reason) {
  10623. if (reason instanceof Error) {
  10624. // Serialize error to avoid "DataCloneError"
  10625. reason = reason + '';
  10626. }
  10627. comObj.postMessage({
  10628. sourceName: sourceName,
  10629. targetName: targetName,
  10630. isReply: true,
  10631. callbackId: data.callbackId,
  10632. error: reason
  10633. });
  10634. });
  10635. } else {
  10636. action[0].call(action[1], data.data);
  10637. }
  10638. } else {
  10639. error('Unknown action from worker: ' + data.action);
  10640. }
  10641. }.bind(this);
  10642. comObj.addEventListener('message', this._onComObjOnMessage);
  10643. }
  10644. MessageHandler.prototype = {
  10645. on: function messageHandlerOn(actionName, handler, scope) {
  10646. var ah = this.actionHandler;
  10647. if (ah[actionName]) {
  10648. error('There is already an actionName called "' + actionName + '"');
  10649. }
  10650. ah[actionName] = [handler, scope];
  10651. },
  10652. /**
  10653. * Sends a message to the comObj to invoke the action with the supplied data.
  10654. * @param {String} actionName Action to call.
  10655. * @param {JSON} data JSON data to send.
  10656. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  10657. */
  10658. send: function messageHandlerSend(actionName, data, transfers) {
  10659. var message = {
  10660. sourceName: this.sourceName,
  10661. targetName: this.targetName,
  10662. action: actionName,
  10663. data: data
  10664. };
  10665. this.postMessage(message, transfers);
  10666. },
  10667. /**
  10668. * Sends a message to the comObj to invoke the action with the supplied data.
  10669. * Expects that other side will callback with the response.
  10670. * @param {String} actionName Action to call.
  10671. * @param {JSON} data JSON data to send.
  10672. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  10673. * @returns {Promise} Promise to be resolved with response data.
  10674. */
  10675. sendWithPromise:
  10676. function messageHandlerSendWithPromise(actionName, data, transfers) {
  10677. var callbackId = this.callbackIndex++;
  10678. var message = {
  10679. sourceName: this.sourceName,
  10680. targetName: this.targetName,
  10681. action: actionName,
  10682. data: data,
  10683. callbackId: callbackId
  10684. };
  10685. var capability = createPromiseCapability();
  10686. this.callbacksCapabilities[callbackId] = capability;
  10687. try {
  10688. this.postMessage(message, transfers);
  10689. } catch (e) {
  10690. capability.reject(e);
  10691. }
  10692. return capability.promise;
  10693. },
  10694. /**
  10695. * Sends raw message to the comObj.
  10696. * @private
  10697. * @param message {Object} Raw message.
  10698. * @param transfers List of transfers/ArrayBuffers, or undefined.
  10699. */
  10700. postMessage: function (message, transfers) {
  10701. if (transfers && this.postMessageTransfers) {
  10702. this.comObj.postMessage(message, transfers);
  10703. } else {
  10704. this.comObj.postMessage(message);
  10705. }
  10706. },
  10707. destroy: function () {
  10708. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  10709. }
  10710. };
  10711. function loadJpegStream(id, imageUrl, objs) {
  10712. var img = new Image();
  10713. img.onload = (function loadJpegStream_onloadClosure() {
  10714. objs.resolve(id, img);
  10715. });
  10716. img.onerror = (function loadJpegStream_onerrorClosure() {
  10717. objs.resolve(id, null);
  10718. warn('Error during JPEG image loading');
  10719. });
  10720. img.src = imageUrl;
  10721. }
  10722. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  10723. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  10724. exports.OPS = OPS;
  10725. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  10726. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  10727. exports.AnnotationFlag = AnnotationFlag;
  10728. exports.AnnotationType = AnnotationType;
  10729. exports.FontType = FontType;
  10730. exports.ImageKind = ImageKind;
  10731. exports.InvalidPDFException = InvalidPDFException;
  10732. exports.LinkTarget = LinkTarget;
  10733. exports.LinkTargetStringMap = LinkTargetStringMap;
  10734. exports.MessageHandler = MessageHandler;
  10735. exports.MissingDataException = MissingDataException;
  10736. exports.MissingPDFException = MissingPDFException;
  10737. exports.NotImplementedException = NotImplementedException;
  10738. exports.PasswordException = PasswordException;
  10739. exports.PasswordResponses = PasswordResponses;
  10740. exports.StatTimer = StatTimer;
  10741. exports.StreamType = StreamType;
  10742. exports.TextRenderingMode = TextRenderingMode;
  10743. exports.UnexpectedResponseException = UnexpectedResponseException;
  10744. exports.UnknownErrorException = UnknownErrorException;
  10745. exports.Util = Util;
  10746. exports.XRefParseException = XRefParseException;
  10747. exports.assert = assert;
  10748. exports.bytesToString = bytesToString;
  10749. exports.combineUrl = combineUrl;
  10750. exports.createPromiseCapability = createPromiseCapability;
  10751. exports.deprecated = deprecated;
  10752. exports.error = error;
  10753. exports.info = info;
  10754. exports.isArray = isArray;
  10755. exports.isArrayBuffer = isArrayBuffer;
  10756. exports.isBool = isBool;
  10757. exports.isEmptyObj = isEmptyObj;
  10758. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  10759. exports.isInt = isInt;
  10760. exports.isNum = isNum;
  10761. exports.isString = isString;
  10762. exports.isValidUrl = isValidUrl;
  10763. exports.loadJpegStream = loadJpegStream;
  10764. exports.log2 = log2;
  10765. exports.readInt8 = readInt8;
  10766. exports.readUint16 = readUint16;
  10767. exports.readUint32 = readUint32;
  10768. exports.shadow = shadow;
  10769. exports.string32 = string32;
  10770. exports.stringToBytes = stringToBytes;
  10771. exports.stringToPDFString = stringToPDFString;
  10772. exports.stringToUTF8String = stringToUTF8String;
  10773. exports.utf8StringToString = utf8StringToString;
  10774. exports.warn = warn;
  10775. }));
  10776. (function (root, factory) {
  10777. {
  10778. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  10779. }
  10780. }(this, function (exports, sharedUtil) {
  10781. var MissingDataException = sharedUtil.MissingDataException;
  10782. var assert = sharedUtil.assert;
  10783. var createPromiseCapability = sharedUtil.createPromiseCapability;
  10784. var isInt = sharedUtil.isInt;
  10785. var isEmptyObj = sharedUtil.isEmptyObj;
  10786. var ChunkedStream = (function ChunkedStreamClosure() {
  10787. function ChunkedStream(length, chunkSize, manager) {
  10788. this.bytes = new Uint8Array(length);
  10789. this.start = 0;
  10790. this.pos = 0;
  10791. this.end = length;
  10792. this.chunkSize = chunkSize;
  10793. this.loadedChunks = [];
  10794. this.numChunksLoaded = 0;
  10795. this.numChunks = Math.ceil(length / chunkSize);
  10796. this.manager = manager;
  10797. this.progressiveDataLength = 0;
  10798. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  10799. }
  10800. // required methods for a stream. if a particular stream does not
  10801. // implement these, an error should be thrown
  10802. ChunkedStream.prototype = {
  10803. getMissingChunks: function ChunkedStream_getMissingChunks() {
  10804. var chunks = [];
  10805. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  10806. if (!this.loadedChunks[chunk]) {
  10807. chunks.push(chunk);
  10808. }
  10809. }
  10810. return chunks;
  10811. },
  10812. getBaseStreams: function ChunkedStream_getBaseStreams() {
  10813. return [this];
  10814. },
  10815. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  10816. return this.numChunksLoaded === this.numChunks;
  10817. },
  10818. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  10819. var end = begin + chunk.byteLength;
  10820. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  10821. // Using this.length is inaccurate here since this.start can be moved
  10822. // See ChunkedStream.moveStart()
  10823. var length = this.bytes.length;
  10824. assert(end % this.chunkSize === 0 || end === length,
  10825. 'Bad end offset: ' + end);
  10826. this.bytes.set(new Uint8Array(chunk), begin);
  10827. var chunkSize = this.chunkSize;
  10828. var beginChunk = Math.floor(begin / chunkSize);
  10829. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10830. var curChunk;
  10831. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10832. if (!this.loadedChunks[curChunk]) {
  10833. this.loadedChunks[curChunk] = true;
  10834. ++this.numChunksLoaded;
  10835. }
  10836. }
  10837. },
  10838. onReceiveProgressiveData:
  10839. function ChunkedStream_onReceiveProgressiveData(data) {
  10840. var position = this.progressiveDataLength;
  10841. var beginChunk = Math.floor(position / this.chunkSize);
  10842. this.bytes.set(new Uint8Array(data), position);
  10843. position += data.byteLength;
  10844. this.progressiveDataLength = position;
  10845. var endChunk = position >= this.end ? this.numChunks :
  10846. Math.floor(position / this.chunkSize);
  10847. var curChunk;
  10848. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10849. if (!this.loadedChunks[curChunk]) {
  10850. this.loadedChunks[curChunk] = true;
  10851. ++this.numChunksLoaded;
  10852. }
  10853. }
  10854. },
  10855. ensureByte: function ChunkedStream_ensureByte(pos) {
  10856. var chunk = Math.floor(pos / this.chunkSize);
  10857. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  10858. return;
  10859. }
  10860. if (!this.loadedChunks[chunk]) {
  10861. throw new MissingDataException(pos, pos + 1);
  10862. }
  10863. this.lastSuccessfulEnsureByteChunk = chunk;
  10864. },
  10865. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  10866. if (begin >= end) {
  10867. return;
  10868. }
  10869. if (end <= this.progressiveDataLength) {
  10870. return;
  10871. }
  10872. var chunkSize = this.chunkSize;
  10873. var beginChunk = Math.floor(begin / chunkSize);
  10874. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10875. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10876. if (!this.loadedChunks[chunk]) {
  10877. throw new MissingDataException(begin, end);
  10878. }
  10879. }
  10880. },
  10881. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  10882. var chunk, numChunks = this.numChunks;
  10883. for (var i = 0; i < numChunks; ++i) {
  10884. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  10885. if (!this.loadedChunks[chunk]) {
  10886. return chunk;
  10887. }
  10888. }
  10889. return null;
  10890. },
  10891. hasChunk: function ChunkedStream_hasChunk(chunk) {
  10892. return !!this.loadedChunks[chunk];
  10893. },
  10894. get length() {
  10895. return this.end - this.start;
  10896. },
  10897. get isEmpty() {
  10898. return this.length === 0;
  10899. },
  10900. getByte: function ChunkedStream_getByte() {
  10901. var pos = this.pos;
  10902. if (pos >= this.end) {
  10903. return -1;
  10904. }
  10905. this.ensureByte(pos);
  10906. return this.bytes[this.pos++];
  10907. },
  10908. getUint16: function ChunkedStream_getUint16() {
  10909. var b0 = this.getByte();
  10910. var b1 = this.getByte();
  10911. if (b0 === -1 || b1 === -1) {
  10912. return -1;
  10913. }
  10914. return (b0 << 8) + b1;
  10915. },
  10916. getInt32: function ChunkedStream_getInt32() {
  10917. var b0 = this.getByte();
  10918. var b1 = this.getByte();
  10919. var b2 = this.getByte();
  10920. var b3 = this.getByte();
  10921. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  10922. },
  10923. // returns subarray of original buffer
  10924. // should only be read
  10925. getBytes: function ChunkedStream_getBytes(length) {
  10926. var bytes = this.bytes;
  10927. var pos = this.pos;
  10928. var strEnd = this.end;
  10929. if (!length) {
  10930. this.ensureRange(pos, strEnd);
  10931. return bytes.subarray(pos, strEnd);
  10932. }
  10933. var end = pos + length;
  10934. if (end > strEnd) {
  10935. end = strEnd;
  10936. }
  10937. this.ensureRange(pos, end);
  10938. this.pos = end;
  10939. return bytes.subarray(pos, end);
  10940. },
  10941. peekByte: function ChunkedStream_peekByte() {
  10942. var peekedByte = this.getByte();
  10943. this.pos--;
  10944. return peekedByte;
  10945. },
  10946. peekBytes: function ChunkedStream_peekBytes(length) {
  10947. var bytes = this.getBytes(length);
  10948. this.pos -= bytes.length;
  10949. return bytes;
  10950. },
  10951. getByteRange: function ChunkedStream_getBytes(begin, end) {
  10952. this.ensureRange(begin, end);
  10953. return this.bytes.subarray(begin, end);
  10954. },
  10955. skip: function ChunkedStream_skip(n) {
  10956. if (!n) {
  10957. n = 1;
  10958. }
  10959. this.pos += n;
  10960. },
  10961. reset: function ChunkedStream_reset() {
  10962. this.pos = this.start;
  10963. },
  10964. moveStart: function ChunkedStream_moveStart() {
  10965. this.start = this.pos;
  10966. },
  10967. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  10968. this.ensureRange(start, start + length);
  10969. function ChunkedStreamSubstream() {}
  10970. ChunkedStreamSubstream.prototype = Object.create(this);
  10971. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  10972. var chunkSize = this.chunkSize;
  10973. var beginChunk = Math.floor(this.start / chunkSize);
  10974. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  10975. var missingChunks = [];
  10976. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10977. if (!this.loadedChunks[chunk]) {
  10978. missingChunks.push(chunk);
  10979. }
  10980. }
  10981. return missingChunks;
  10982. };
  10983. var subStream = new ChunkedStreamSubstream();
  10984. subStream.pos = subStream.start = start;
  10985. subStream.end = start + length || this.end;
  10986. subStream.dict = dict;
  10987. return subStream;
  10988. },
  10989. isStream: true
  10990. };
  10991. return ChunkedStream;
  10992. })();
  10993. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  10994. function ChunkedStreamManager(length, chunkSize, url, args) {
  10995. this.stream = new ChunkedStream(length, chunkSize, this);
  10996. this.length = length;
  10997. this.chunkSize = chunkSize;
  10998. this.url = url;
  10999. this.disableAutoFetch = args.disableAutoFetch;
  11000. var msgHandler = this.msgHandler = args.msgHandler;
  11001. if (args.chunkedViewerLoading) {
  11002. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  11003. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  11004. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  11005. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  11006. };
  11007. } else {
  11008. var getXhr = function getXhr() {
  11009. return new XMLHttpRequest();
  11010. };
  11011. this.networkManager = new NetworkManager(this.url, {
  11012. getXhr: getXhr,
  11013. httpHeaders: args.httpHeaders,
  11014. withCredentials: args.withCredentials
  11015. });
  11016. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  11017. this.networkManager.requestRange(begin, end, {
  11018. onDone: this.onReceiveData.bind(this),
  11019. onProgress: this.onProgress.bind(this)
  11020. });
  11021. };
  11022. }
  11023. this.currRequestId = 0;
  11024. this.chunksNeededByRequest = {};
  11025. this.requestsByChunk = {};
  11026. this.promisesByRequest = {};
  11027. this.progressiveDataLength = 0;
  11028. this._loadedStreamCapability = createPromiseCapability();
  11029. if (args.initialData) {
  11030. this.onReceiveData({chunk: args.initialData});
  11031. }
  11032. }
  11033. ChunkedStreamManager.prototype = {
  11034. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  11035. return this._loadedStreamCapability.promise;
  11036. },
  11037. // Get all the chunks that are not yet loaded and groups them into
  11038. // contiguous ranges to load in as few requests as possible
  11039. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  11040. var missingChunks = this.stream.getMissingChunks();
  11041. this._requestChunks(missingChunks);
  11042. return this._loadedStreamCapability.promise;
  11043. },
  11044. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  11045. var requestId = this.currRequestId++;
  11046. var chunksNeeded;
  11047. var i, ii;
  11048. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  11049. for (i = 0, ii = chunks.length; i < ii; i++) {
  11050. if (!this.stream.hasChunk(chunks[i])) {
  11051. chunksNeeded[chunks[i]] = true;
  11052. }
  11053. }
  11054. if (isEmptyObj(chunksNeeded)) {
  11055. return Promise.resolve();
  11056. }
  11057. var capability = createPromiseCapability();
  11058. this.promisesByRequest[requestId] = capability;
  11059. var chunksToRequest = [];
  11060. for (var chunk in chunksNeeded) {
  11061. chunk = chunk | 0;
  11062. if (!(chunk in this.requestsByChunk)) {
  11063. this.requestsByChunk[chunk] = [];
  11064. chunksToRequest.push(chunk);
  11065. }
  11066. this.requestsByChunk[chunk].push(requestId);
  11067. }
  11068. if (!chunksToRequest.length) {
  11069. return capability.promise;
  11070. }
  11071. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11072. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11073. var groupedChunk = groupedChunksToRequest[i];
  11074. var begin = groupedChunk.beginChunk * this.chunkSize;
  11075. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11076. this.sendRequest(begin, end);
  11077. }
  11078. return capability.promise;
  11079. },
  11080. getStream: function ChunkedStreamManager_getStream() {
  11081. return this.stream;
  11082. },
  11083. // Loads any chunks in the requested range that are not yet loaded
  11084. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11085. end = Math.min(end, this.length);
  11086. var beginChunk = this.getBeginChunk(begin);
  11087. var endChunk = this.getEndChunk(end);
  11088. var chunks = [];
  11089. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11090. chunks.push(chunk);
  11091. }
  11092. return this._requestChunks(chunks);
  11093. },
  11094. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11095. ranges = ranges || [];
  11096. var chunksToRequest = [];
  11097. for (var i = 0; i < ranges.length; i++) {
  11098. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11099. var endChunk = this.getEndChunk(ranges[i].end);
  11100. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11101. if (chunksToRequest.indexOf(chunk) < 0) {
  11102. chunksToRequest.push(chunk);
  11103. }
  11104. }
  11105. }
  11106. chunksToRequest.sort(function(a, b) { return a - b; });
  11107. return this._requestChunks(chunksToRequest);
  11108. },
  11109. // Groups a sorted array of chunks into as few contiguous larger
  11110. // chunks as possible
  11111. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11112. var groupedChunks = [];
  11113. var beginChunk = -1;
  11114. var prevChunk = -1;
  11115. for (var i = 0; i < chunks.length; ++i) {
  11116. var chunk = chunks[i];
  11117. if (beginChunk < 0) {
  11118. beginChunk = chunk;
  11119. }
  11120. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11121. groupedChunks.push({ beginChunk: beginChunk,
  11122. endChunk: prevChunk + 1 });
  11123. beginChunk = chunk;
  11124. }
  11125. if (i + 1 === chunks.length) {
  11126. groupedChunks.push({ beginChunk: beginChunk,
  11127. endChunk: chunk + 1 });
  11128. }
  11129. prevChunk = chunk;
  11130. }
  11131. return groupedChunks;
  11132. },
  11133. onProgress: function ChunkedStreamManager_onProgress(args) {
  11134. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11135. args.loaded);
  11136. this.msgHandler.send('DocProgress', {
  11137. loaded: bytesLoaded,
  11138. total: this.length
  11139. });
  11140. },
  11141. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11142. var chunk = args.chunk;
  11143. var isProgressive = args.begin === undefined;
  11144. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11145. var end = begin + chunk.byteLength;
  11146. var beginChunk = Math.floor(begin / this.chunkSize);
  11147. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11148. Math.ceil(end / this.chunkSize);
  11149. if (isProgressive) {
  11150. this.stream.onReceiveProgressiveData(chunk);
  11151. this.progressiveDataLength = end;
  11152. } else {
  11153. this.stream.onReceiveData(begin, chunk);
  11154. }
  11155. if (this.stream.allChunksLoaded()) {
  11156. this._loadedStreamCapability.resolve(this.stream);
  11157. }
  11158. var loadedRequests = [];
  11159. var i, requestId;
  11160. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11161. // The server might return more chunks than requested
  11162. var requestIds = this.requestsByChunk[chunk] || [];
  11163. delete this.requestsByChunk[chunk];
  11164. for (i = 0; i < requestIds.length; ++i) {
  11165. requestId = requestIds[i];
  11166. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11167. if (chunk in chunksNeeded) {
  11168. delete chunksNeeded[chunk];
  11169. }
  11170. if (!isEmptyObj(chunksNeeded)) {
  11171. continue;
  11172. }
  11173. loadedRequests.push(requestId);
  11174. }
  11175. }
  11176. // If there are no pending requests, automatically fetch the next
  11177. // unfetched chunk of the PDF
  11178. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11179. var nextEmptyChunk;
  11180. if (this.stream.numChunksLoaded === 1) {
  11181. // This is a special optimization so that after fetching the first
  11182. // chunk, rather than fetching the second chunk, we fetch the last
  11183. // chunk.
  11184. var lastChunk = this.stream.numChunks - 1;
  11185. if (!this.stream.hasChunk(lastChunk)) {
  11186. nextEmptyChunk = lastChunk;
  11187. }
  11188. } else {
  11189. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11190. }
  11191. if (isInt(nextEmptyChunk)) {
  11192. this._requestChunks([nextEmptyChunk]);
  11193. }
  11194. }
  11195. for (i = 0; i < loadedRequests.length; ++i) {
  11196. requestId = loadedRequests[i];
  11197. var capability = this.promisesByRequest[requestId];
  11198. delete this.promisesByRequest[requestId];
  11199. capability.resolve();
  11200. }
  11201. this.msgHandler.send('DocProgress', {
  11202. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11203. total: this.length
  11204. });
  11205. },
  11206. onError: function ChunkedStreamManager_onError(err) {
  11207. this._loadedStreamCapability.reject(err);
  11208. },
  11209. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11210. var chunk = Math.floor(begin / this.chunkSize);
  11211. return chunk;
  11212. },
  11213. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11214. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11215. return chunk;
  11216. },
  11217. abort: function ChunkedStreamManager_abort() {
  11218. if (this.networkManager) {
  11219. this.networkManager.abortAllRequests();
  11220. }
  11221. for(var requestId in this.promisesByRequest) {
  11222. var capability = this.promisesByRequest[requestId];
  11223. capability.reject(new Error('Request was aborted'));
  11224. }
  11225. }
  11226. };
  11227. return ChunkedStreamManager;
  11228. })();
  11229. exports.ChunkedStream = ChunkedStream;
  11230. exports.ChunkedStreamManager = ChunkedStreamManager;
  11231. }));
  11232. (function (root, factory) {
  11233. {
  11234. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11235. root.pdfjsCoreArithmeticDecoder);
  11236. }
  11237. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11238. var error = sharedUtil.error;
  11239. var log2 = sharedUtil.log2;
  11240. var readInt8 = sharedUtil.readInt8;
  11241. var readUint16 = sharedUtil.readUint16;
  11242. var readUint32 = sharedUtil.readUint32;
  11243. var shadow = sharedUtil.shadow;
  11244. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11245. var Jbig2Image = (function Jbig2ImageClosure() {
  11246. // Utility data structures
  11247. function ContextCache() {}
  11248. ContextCache.prototype = {
  11249. getContexts: function(id) {
  11250. if (id in this) {
  11251. return this[id];
  11252. }
  11253. return (this[id] = new Int8Array(1 << 16));
  11254. }
  11255. };
  11256. function DecodingContext(data, start, end) {
  11257. this.data = data;
  11258. this.start = start;
  11259. this.end = end;
  11260. }
  11261. DecodingContext.prototype = {
  11262. get decoder() {
  11263. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11264. return shadow(this, 'decoder', decoder);
  11265. },
  11266. get contextCache() {
  11267. var cache = new ContextCache();
  11268. return shadow(this, 'contextCache', cache);
  11269. }
  11270. };
  11271. // Annex A. Arithmetic Integer Decoding Procedure
  11272. // A.2 Procedure for decoding values
  11273. function decodeInteger(contextCache, procedure, decoder) {
  11274. var contexts = contextCache.getContexts(procedure);
  11275. var prev = 1;
  11276. function readBits(length) {
  11277. var v = 0;
  11278. for (var i = 0; i < length; i++) {
  11279. var bit = decoder.readBit(contexts, prev);
  11280. prev = (prev < 256 ? (prev << 1) | bit :
  11281. (((prev << 1) | bit) & 511) | 256);
  11282. v = (v << 1) | bit;
  11283. }
  11284. return v >>> 0;
  11285. }
  11286. var sign = readBits(1);
  11287. var value = readBits(1) ?
  11288. (readBits(1) ?
  11289. (readBits(1) ?
  11290. (readBits(1) ?
  11291. (readBits(1) ?
  11292. (readBits(32) + 4436) :
  11293. readBits(12) + 340) :
  11294. readBits(8) + 84) :
  11295. readBits(6) + 20) :
  11296. readBits(4) + 4) :
  11297. readBits(2);
  11298. return (sign === 0 ? value : (value > 0 ? -value : null));
  11299. }
  11300. // A.3 The IAID decoding procedure
  11301. function decodeIAID(contextCache, decoder, codeLength) {
  11302. var contexts = contextCache.getContexts('IAID');
  11303. var prev = 1;
  11304. for (var i = 0; i < codeLength; i++) {
  11305. var bit = decoder.readBit(contexts, prev);
  11306. prev = (prev << 1) | bit;
  11307. }
  11308. if (codeLength < 31) {
  11309. return prev & ((1 << codeLength) - 1);
  11310. }
  11311. return prev & 0x7FFFFFFF;
  11312. }
  11313. // 7.3 Segment types
  11314. var SegmentTypes = [
  11315. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11316. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11317. null, null, null, null, null, 'patternDictionary', null, null, null,
  11318. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11319. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11320. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11321. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11322. 'IntermediateGenericRefinementRegion', null,
  11323. 'ImmediateGenericRefinementRegion',
  11324. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11325. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11326. 'Tables', null, null, null, null, null, null, null, null,
  11327. 'Extension'
  11328. ];
  11329. var CodingTemplates = [
  11330. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11331. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11332. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11333. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11334. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11335. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11336. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11337. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11338. {x: -1, y: 0}],
  11339. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11340. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11341. ];
  11342. var RefinementTemplates = [
  11343. {
  11344. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11345. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11346. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11347. },
  11348. {
  11349. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11350. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11351. {x: 0, y: 1}, {x: 1, y: 1}]
  11352. }
  11353. ];
  11354. // See 6.2.5.7 Decoding the bitmap.
  11355. var ReusedContexts = [
  11356. 0x9B25, // 10011 0110010 0101
  11357. 0x0795, // 0011 110010 101
  11358. 0x00E5, // 001 11001 01
  11359. 0x0195 // 011001 0101
  11360. ];
  11361. var RefinementReusedContexts = [
  11362. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11363. 0x0008 // '0000' + '001000'
  11364. ];
  11365. function decodeBitmapTemplate0(width, height, decodingContext) {
  11366. var decoder = decodingContext.decoder;
  11367. var contexts = decodingContext.contextCache.getContexts('GB');
  11368. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11369. // ...ooooo....
  11370. // ..ooooooo... Context template for current pixel (X)
  11371. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11372. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11373. for (i = 0; i < height; i++) {
  11374. row = bitmap[i] = new Uint8Array(width);
  11375. row1 = (i < 1) ? row : bitmap[i - 1];
  11376. row2 = (i < 2) ? row : bitmap[i - 2];
  11377. // At the beginning of each row:
  11378. // Fill contextLabel with pixels that are above/right of (X)
  11379. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11380. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11381. (row1[3] << 4);
  11382. for (j = 0; j < width; j++) {
  11383. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11384. // At each pixel: Clear contextLabel pixels that are shifted
  11385. // out of the context, then add new ones.
  11386. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11387. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11388. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11389. }
  11390. }
  11391. return bitmap;
  11392. }
  11393. // 6.2 Generic Region Decoding Procedure
  11394. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11395. decodingContext) {
  11396. if (mmr) {
  11397. error('JBIG2 error: MMR encoding is not supported');
  11398. }
  11399. // Use optimized version for the most common case
  11400. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11401. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11402. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11403. return decodeBitmapTemplate0(width, height, decodingContext);
  11404. }
  11405. var useskip = !!skip;
  11406. var template = CodingTemplates[templateIndex].concat(at);
  11407. // Sorting is non-standard, and it is not required. But sorting increases
  11408. // the number of template bits that can be reused from the previous
  11409. // contextLabel in the main loop.
  11410. template.sort(function (a, b) {
  11411. return (a.y - b.y) || (a.x - b.x);
  11412. });
  11413. var templateLength = template.length;
  11414. var templateX = new Int8Array(templateLength);
  11415. var templateY = new Int8Array(templateLength);
  11416. var changingTemplateEntries = [];
  11417. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11418. var c, k;
  11419. for (k = 0; k < templateLength; k++) {
  11420. templateX[k] = template[k].x;
  11421. templateY[k] = template[k].y;
  11422. minX = Math.min(minX, template[k].x);
  11423. maxX = Math.max(maxX, template[k].x);
  11424. minY = Math.min(minY, template[k].y);
  11425. // Check if the template pixel appears in two consecutive context labels,
  11426. // so it can be reused. Otherwise, we add it to the list of changing
  11427. // template entries.
  11428. if (k < templateLength - 1 &&
  11429. template[k].y === template[k + 1].y &&
  11430. template[k].x === template[k + 1].x - 1) {
  11431. reuseMask |= 1 << (templateLength - 1 - k);
  11432. } else {
  11433. changingTemplateEntries.push(k);
  11434. }
  11435. }
  11436. var changingEntriesLength = changingTemplateEntries.length;
  11437. var changingTemplateX = new Int8Array(changingEntriesLength);
  11438. var changingTemplateY = new Int8Array(changingEntriesLength);
  11439. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  11440. for (c = 0; c < changingEntriesLength; c++) {
  11441. k = changingTemplateEntries[c];
  11442. changingTemplateX[c] = template[k].x;
  11443. changingTemplateY[c] = template[k].y;
  11444. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  11445. }
  11446. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  11447. var sbb_left = -minX;
  11448. var sbb_top = -minY;
  11449. var sbb_right = width - maxX;
  11450. var pseudoPixelContext = ReusedContexts[templateIndex];
  11451. var row = new Uint8Array(width);
  11452. var bitmap = [];
  11453. var decoder = decodingContext.decoder;
  11454. var contexts = decodingContext.contextCache.getContexts('GB');
  11455. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  11456. for (var i = 0; i < height; i++) {
  11457. if (prediction) {
  11458. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11459. ltp ^= sltp;
  11460. if (ltp) {
  11461. bitmap.push(row); // duplicate previous row
  11462. continue;
  11463. }
  11464. }
  11465. row = new Uint8Array(row);
  11466. bitmap.push(row);
  11467. for (j = 0; j < width; j++) {
  11468. if (useskip && skip[i][j]) {
  11469. row[j] = 0;
  11470. continue;
  11471. }
  11472. // Are we in the middle of a scanline, so we can reuse contextLabel
  11473. // bits?
  11474. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  11475. // If yes, we can just shift the bits that are reusable and only
  11476. // fetch the remaining ones.
  11477. contextLabel = (contextLabel << 1) & reuseMask;
  11478. for (k = 0; k < changingEntriesLength; k++) {
  11479. i0 = i + changingTemplateY[k];
  11480. j0 = j + changingTemplateX[k];
  11481. bit = bitmap[i0][j0];
  11482. if (bit) {
  11483. bit = changingTemplateBit[k];
  11484. contextLabel |= bit;
  11485. }
  11486. }
  11487. } else {
  11488. // compute the contextLabel from scratch
  11489. contextLabel = 0;
  11490. shift = templateLength - 1;
  11491. for (k = 0; k < templateLength; k++, shift--) {
  11492. j0 = j + templateX[k];
  11493. if (j0 >= 0 && j0 < width) {
  11494. i0 = i + templateY[k];
  11495. if (i0 >= 0) {
  11496. bit = bitmap[i0][j0];
  11497. if (bit) {
  11498. contextLabel |= bit << shift;
  11499. }
  11500. }
  11501. }
  11502. }
  11503. }
  11504. var pixel = decoder.readBit(contexts, contextLabel);
  11505. row[j] = pixel;
  11506. }
  11507. }
  11508. return bitmap;
  11509. }
  11510. // 6.3.2 Generic Refinement Region Decoding Procedure
  11511. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  11512. offsetX, offsetY, prediction, at,
  11513. decodingContext) {
  11514. var codingTemplate = RefinementTemplates[templateIndex].coding;
  11515. if (templateIndex === 0) {
  11516. codingTemplate = codingTemplate.concat([at[0]]);
  11517. }
  11518. var codingTemplateLength = codingTemplate.length;
  11519. var codingTemplateX = new Int32Array(codingTemplateLength);
  11520. var codingTemplateY = new Int32Array(codingTemplateLength);
  11521. var k;
  11522. for (k = 0; k < codingTemplateLength; k++) {
  11523. codingTemplateX[k] = codingTemplate[k].x;
  11524. codingTemplateY[k] = codingTemplate[k].y;
  11525. }
  11526. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  11527. if (templateIndex === 0) {
  11528. referenceTemplate = referenceTemplate.concat([at[1]]);
  11529. }
  11530. var referenceTemplateLength = referenceTemplate.length;
  11531. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  11532. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  11533. for (k = 0; k < referenceTemplateLength; k++) {
  11534. referenceTemplateX[k] = referenceTemplate[k].x;
  11535. referenceTemplateY[k] = referenceTemplate[k].y;
  11536. }
  11537. var referenceWidth = referenceBitmap[0].length;
  11538. var referenceHeight = referenceBitmap.length;
  11539. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  11540. var bitmap = [];
  11541. var decoder = decodingContext.decoder;
  11542. var contexts = decodingContext.contextCache.getContexts('GR');
  11543. var ltp = 0;
  11544. for (var i = 0; i < height; i++) {
  11545. if (prediction) {
  11546. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11547. ltp ^= sltp;
  11548. if (ltp) {
  11549. error('JBIG2 error: prediction is not supported');
  11550. }
  11551. }
  11552. var row = new Uint8Array(width);
  11553. bitmap.push(row);
  11554. for (var j = 0; j < width; j++) {
  11555. var i0, j0;
  11556. var contextLabel = 0;
  11557. for (k = 0; k < codingTemplateLength; k++) {
  11558. i0 = i + codingTemplateY[k];
  11559. j0 = j + codingTemplateX[k];
  11560. if (i0 < 0 || j0 < 0 || j0 >= width) {
  11561. contextLabel <<= 1; // out of bound pixel
  11562. } else {
  11563. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  11564. }
  11565. }
  11566. for (k = 0; k < referenceTemplateLength; k++) {
  11567. i0 = i + referenceTemplateY[k] + offsetY;
  11568. j0 = j + referenceTemplateX[k] + offsetX;
  11569. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  11570. j0 >= referenceWidth) {
  11571. contextLabel <<= 1; // out of bound pixel
  11572. } else {
  11573. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  11574. }
  11575. }
  11576. var pixel = decoder.readBit(contexts, contextLabel);
  11577. row[j] = pixel;
  11578. }
  11579. }
  11580. return bitmap;
  11581. }
  11582. // 6.5.5 Decoding the symbol dictionary
  11583. function decodeSymbolDictionary(huffman, refinement, symbols,
  11584. numberOfNewSymbols, numberOfExportedSymbols,
  11585. huffmanTables, templateIndex, at,
  11586. refinementTemplateIndex, refinementAt,
  11587. decodingContext) {
  11588. if (huffman) {
  11589. error('JBIG2 error: huffman is not supported');
  11590. }
  11591. var newSymbols = [];
  11592. var currentHeight = 0;
  11593. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  11594. var decoder = decodingContext.decoder;
  11595. var contextCache = decodingContext.contextCache;
  11596. while (newSymbols.length < numberOfNewSymbols) {
  11597. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  11598. currentHeight += deltaHeight;
  11599. var currentWidth = 0;
  11600. var totalWidth = 0;
  11601. while (true) {
  11602. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  11603. if (deltaWidth === null) {
  11604. break; // OOB
  11605. }
  11606. currentWidth += deltaWidth;
  11607. totalWidth += currentWidth;
  11608. var bitmap;
  11609. if (refinement) {
  11610. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  11611. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  11612. if (numberOfInstances > 1) {
  11613. bitmap = decodeTextRegion(huffman, refinement,
  11614. currentWidth, currentHeight, 0,
  11615. numberOfInstances, 1, //strip size
  11616. symbols.concat(newSymbols),
  11617. symbolCodeLength,
  11618. 0, //transposed
  11619. 0, //ds offset
  11620. 1, //top left 7.4.3.1.1
  11621. 0, //OR operator
  11622. huffmanTables,
  11623. refinementTemplateIndex, refinementAt,
  11624. decodingContext);
  11625. } else {
  11626. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11627. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11628. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11629. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  11630. newSymbols[symbolId - symbols.length]);
  11631. bitmap = decodeRefinement(currentWidth, currentHeight,
  11632. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  11633. decodingContext);
  11634. }
  11635. } else {
  11636. // 6.5.8.1 Direct-coded symbol bitmap
  11637. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  11638. templateIndex, false, null, at, decodingContext);
  11639. }
  11640. newSymbols.push(bitmap);
  11641. }
  11642. }
  11643. // 6.5.10 Exported symbols
  11644. var exportedSymbols = [];
  11645. var flags = [], currentFlag = false;
  11646. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  11647. while (flags.length < totalSymbolsLength) {
  11648. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  11649. while (runLength--) {
  11650. flags.push(currentFlag);
  11651. }
  11652. currentFlag = !currentFlag;
  11653. }
  11654. for (var i = 0, ii = symbols.length; i < ii; i++) {
  11655. if (flags[i]) {
  11656. exportedSymbols.push(symbols[i]);
  11657. }
  11658. }
  11659. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  11660. if (flags[i]) {
  11661. exportedSymbols.push(newSymbols[j]);
  11662. }
  11663. }
  11664. return exportedSymbols;
  11665. }
  11666. function decodeTextRegion(huffman, refinement, width, height,
  11667. defaultPixelValue, numberOfSymbolInstances,
  11668. stripSize, inputSymbols, symbolCodeLength,
  11669. transposed, dsOffset, referenceCorner,
  11670. combinationOperator, huffmanTables,
  11671. refinementTemplateIndex, refinementAt,
  11672. decodingContext) {
  11673. if (huffman) {
  11674. error('JBIG2 error: huffman is not supported');
  11675. }
  11676. // Prepare bitmap
  11677. var bitmap = [];
  11678. var i, row;
  11679. for (i = 0; i < height; i++) {
  11680. row = new Uint8Array(width);
  11681. if (defaultPixelValue) {
  11682. for (var j = 0; j < width; j++) {
  11683. row[j] = defaultPixelValue;
  11684. }
  11685. }
  11686. bitmap.push(row);
  11687. }
  11688. var decoder = decodingContext.decoder;
  11689. var contextCache = decodingContext.contextCache;
  11690. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11691. var firstS = 0;
  11692. i = 0;
  11693. while (i < numberOfSymbolInstances) {
  11694. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11695. stripT += deltaT;
  11696. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  11697. firstS += deltaFirstS;
  11698. var currentS = firstS;
  11699. do {
  11700. var currentT = (stripSize === 1 ? 0 :
  11701. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  11702. var t = stripSize * stripT + currentT;
  11703. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11704. var applyRefinement = (refinement &&
  11705. decodeInteger(contextCache, 'IARI', decoder));
  11706. var symbolBitmap = inputSymbols[symbolId];
  11707. var symbolWidth = symbolBitmap[0].length;
  11708. var symbolHeight = symbolBitmap.length;
  11709. if (applyRefinement) {
  11710. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  11711. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  11712. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11713. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11714. symbolWidth += rdw;
  11715. symbolHeight += rdh;
  11716. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  11717. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  11718. (rdh >> 1) + rdy, false, refinementAt,
  11719. decodingContext);
  11720. }
  11721. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  11722. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  11723. var s2, t2, symbolRow;
  11724. if (transposed) {
  11725. // Place Symbol Bitmap from T1,S1
  11726. for (s2 = 0; s2 < symbolHeight; s2++) {
  11727. row = bitmap[offsetS + s2];
  11728. if (!row) {
  11729. continue;
  11730. }
  11731. symbolRow = symbolBitmap[s2];
  11732. // To ignore Parts of Symbol bitmap which goes
  11733. // outside bitmap region
  11734. var maxWidth = Math.min(width - offsetT, symbolWidth);
  11735. switch (combinationOperator) {
  11736. case 0: // OR
  11737. for (t2 = 0; t2 < maxWidth; t2++) {
  11738. row[offsetT + t2] |= symbolRow[t2];
  11739. }
  11740. break;
  11741. case 2: // XOR
  11742. for (t2 = 0; t2 < maxWidth; t2++) {
  11743. row[offsetT + t2] ^= symbolRow[t2];
  11744. }
  11745. break;
  11746. default:
  11747. error('JBIG2 error: operator ' + combinationOperator +
  11748. ' is not supported');
  11749. }
  11750. }
  11751. currentS += symbolHeight - 1;
  11752. } else {
  11753. for (t2 = 0; t2 < symbolHeight; t2++) {
  11754. row = bitmap[offsetT + t2];
  11755. if (!row) {
  11756. continue;
  11757. }
  11758. symbolRow = symbolBitmap[t2];
  11759. switch (combinationOperator) {
  11760. case 0: // OR
  11761. for (s2 = 0; s2 < symbolWidth; s2++) {
  11762. row[offsetS + s2] |= symbolRow[s2];
  11763. }
  11764. break;
  11765. case 2: // XOR
  11766. for (s2 = 0; s2 < symbolWidth; s2++) {
  11767. row[offsetS + s2] ^= symbolRow[s2];
  11768. }
  11769. break;
  11770. default:
  11771. error('JBIG2 error: operator ' + combinationOperator +
  11772. ' is not supported');
  11773. }
  11774. }
  11775. currentS += symbolWidth - 1;
  11776. }
  11777. i++;
  11778. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11779. if (deltaS === null) {
  11780. break; // OOB
  11781. }
  11782. currentS += deltaS + dsOffset;
  11783. } while (true);
  11784. }
  11785. return bitmap;
  11786. }
  11787. function readSegmentHeader(data, start) {
  11788. var segmentHeader = {};
  11789. segmentHeader.number = readUint32(data, start);
  11790. var flags = data[start + 4];
  11791. var segmentType = flags & 0x3F;
  11792. if (!SegmentTypes[segmentType]) {
  11793. error('JBIG2 error: invalid segment type: ' + segmentType);
  11794. }
  11795. segmentHeader.type = segmentType;
  11796. segmentHeader.typeName = SegmentTypes[segmentType];
  11797. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11798. var pageAssociationFieldSize = !!(flags & 0x40);
  11799. var referredFlags = data[start + 5];
  11800. var referredToCount = (referredFlags >> 5) & 7;
  11801. var retainBits = [referredFlags & 31];
  11802. var position = start + 6;
  11803. if (referredFlags === 7) {
  11804. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11805. position += 3;
  11806. var bytes = (referredToCount + 7) >> 3;
  11807. retainBits[0] = data[position++];
  11808. while (--bytes > 0) {
  11809. retainBits.push(data[position++]);
  11810. }
  11811. } else if (referredFlags === 5 || referredFlags === 6) {
  11812. error('JBIG2 error: invalid referred-to flags');
  11813. }
  11814. segmentHeader.retainBits = retainBits;
  11815. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11816. (segmentHeader.number <= 65536 ? 2 : 4));
  11817. var referredTo = [];
  11818. var i, ii;
  11819. for (i = 0; i < referredToCount; i++) {
  11820. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11821. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11822. readUint32(data, position)));
  11823. referredTo.push(number);
  11824. position += referredToSegmentNumberSize;
  11825. }
  11826. segmentHeader.referredTo = referredTo;
  11827. if (!pageAssociationFieldSize) {
  11828. segmentHeader.pageAssociation = data[position++];
  11829. } else {
  11830. segmentHeader.pageAssociation = readUint32(data, position);
  11831. position += 4;
  11832. }
  11833. segmentHeader.length = readUint32(data, position);
  11834. position += 4;
  11835. if (segmentHeader.length === 0xFFFFFFFF) {
  11836. // 7.2.7 Segment data length, unknown segment length
  11837. if (segmentType === 38) { // ImmediateGenericRegion
  11838. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11839. var genericRegionSegmentFlags = data[position +
  11840. RegionSegmentInformationFieldLength];
  11841. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11842. // searching for the segment end
  11843. var searchPatternLength = 6;
  11844. var searchPattern = new Uint8Array(searchPatternLength);
  11845. if (!genericRegionMmr) {
  11846. searchPattern[0] = 0xFF;
  11847. searchPattern[1] = 0xAC;
  11848. }
  11849. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11850. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11851. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11852. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11853. for (i = position, ii = data.length; i < ii; i++) {
  11854. var j = 0;
  11855. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11856. j++;
  11857. }
  11858. if (j === searchPatternLength) {
  11859. segmentHeader.length = i + searchPatternLength;
  11860. break;
  11861. }
  11862. }
  11863. if (segmentHeader.length === 0xFFFFFFFF) {
  11864. error('JBIG2 error: segment end was not found');
  11865. }
  11866. } else {
  11867. error('JBIG2 error: invalid unknown segment length');
  11868. }
  11869. }
  11870. segmentHeader.headerEnd = position;
  11871. return segmentHeader;
  11872. }
  11873. function readSegments(header, data, start, end) {
  11874. var segments = [];
  11875. var position = start;
  11876. while (position < end) {
  11877. var segmentHeader = readSegmentHeader(data, position);
  11878. position = segmentHeader.headerEnd;
  11879. var segment = {
  11880. header: segmentHeader,
  11881. data: data
  11882. };
  11883. if (!header.randomAccess) {
  11884. segment.start = position;
  11885. position += segmentHeader.length;
  11886. segment.end = position;
  11887. }
  11888. segments.push(segment);
  11889. if (segmentHeader.type === 51) {
  11890. break; // end of file is found
  11891. }
  11892. }
  11893. if (header.randomAccess) {
  11894. for (var i = 0, ii = segments.length; i < ii; i++) {
  11895. segments[i].start = position;
  11896. position += segments[i].header.length;
  11897. segments[i].end = position;
  11898. }
  11899. }
  11900. return segments;
  11901. }
  11902. // 7.4.1 Region segment information field
  11903. function readRegionSegmentInformation(data, start) {
  11904. return {
  11905. width: readUint32(data, start),
  11906. height: readUint32(data, start + 4),
  11907. x: readUint32(data, start + 8),
  11908. y: readUint32(data, start + 12),
  11909. combinationOperator: data[start + 16] & 7
  11910. };
  11911. }
  11912. var RegionSegmentInformationFieldLength = 17;
  11913. function processSegment(segment, visitor) {
  11914. var header = segment.header;
  11915. var data = segment.data, position = segment.start, end = segment.end;
  11916. var args, at, i, atLength;
  11917. switch (header.type) {
  11918. case 0: // SymbolDictionary
  11919. // 7.4.2 Symbol dictionary segment syntax
  11920. var dictionary = {};
  11921. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11922. dictionary.huffman = !!(dictionaryFlags & 1);
  11923. dictionary.refinement = !!(dictionaryFlags & 2);
  11924. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11925. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11926. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11927. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11928. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11929. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11930. dictionary.template = (dictionaryFlags >> 10) & 3;
  11931. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11932. position += 2;
  11933. if (!dictionary.huffman) {
  11934. atLength = dictionary.template === 0 ? 4 : 1;
  11935. at = [];
  11936. for (i = 0; i < atLength; i++) {
  11937. at.push({
  11938. x: readInt8(data, position),
  11939. y: readInt8(data, position + 1)
  11940. });
  11941. position += 2;
  11942. }
  11943. dictionary.at = at;
  11944. }
  11945. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11946. at = [];
  11947. for (i = 0; i < 2; i++) {
  11948. at.push({
  11949. x: readInt8(data, position),
  11950. y: readInt8(data, position + 1)
  11951. });
  11952. position += 2;
  11953. }
  11954. dictionary.refinementAt = at;
  11955. }
  11956. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11957. position += 4;
  11958. dictionary.numberOfNewSymbols = readUint32(data, position);
  11959. position += 4;
  11960. args = [dictionary, header.number, header.referredTo,
  11961. data, position, end];
  11962. break;
  11963. case 6: // ImmediateTextRegion
  11964. case 7: // ImmediateLosslessTextRegion
  11965. var textRegion = {};
  11966. textRegion.info = readRegionSegmentInformation(data, position);
  11967. position += RegionSegmentInformationFieldLength;
  11968. var textRegionSegmentFlags = readUint16(data, position);
  11969. position += 2;
  11970. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11971. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11972. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11973. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11974. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11975. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11976. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11977. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11978. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11979. if (textRegion.huffman) {
  11980. var textRegionHuffmanFlags = readUint16(data, position);
  11981. position += 2;
  11982. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11983. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11984. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11985. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11986. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11987. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11988. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11989. textRegion.huffmanRefinementSizeSelector =
  11990. !!(textRegionHuffmanFlags & 14);
  11991. }
  11992. if (textRegion.refinement && !textRegion.refinementTemplate) {
  11993. at = [];
  11994. for (i = 0; i < 2; i++) {
  11995. at.push({
  11996. x: readInt8(data, position),
  11997. y: readInt8(data, position + 1)
  11998. });
  11999. position += 2;
  12000. }
  12001. textRegion.refinementAt = at;
  12002. }
  12003. textRegion.numberOfSymbolInstances = readUint32(data, position);
  12004. position += 4;
  12005. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  12006. if (textRegion.huffman) {
  12007. error('JBIG2 error: huffman is not supported');
  12008. }
  12009. args = [textRegion, header.referredTo, data, position, end];
  12010. break;
  12011. case 38: // ImmediateGenericRegion
  12012. case 39: // ImmediateLosslessGenericRegion
  12013. var genericRegion = {};
  12014. genericRegion.info = readRegionSegmentInformation(data, position);
  12015. position += RegionSegmentInformationFieldLength;
  12016. var genericRegionSegmentFlags = data[position++];
  12017. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  12018. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  12019. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  12020. if (!genericRegion.mmr) {
  12021. atLength = genericRegion.template === 0 ? 4 : 1;
  12022. at = [];
  12023. for (i = 0; i < atLength; i++) {
  12024. at.push({
  12025. x: readInt8(data, position),
  12026. y: readInt8(data, position + 1)
  12027. });
  12028. position += 2;
  12029. }
  12030. genericRegion.at = at;
  12031. }
  12032. args = [genericRegion, data, position, end];
  12033. break;
  12034. case 48: // PageInformation
  12035. var pageInfo = {
  12036. width: readUint32(data, position),
  12037. height: readUint32(data, position + 4),
  12038. resolutionX: readUint32(data, position + 8),
  12039. resolutionY: readUint32(data, position + 12)
  12040. };
  12041. if (pageInfo.height === 0xFFFFFFFF) {
  12042. delete pageInfo.height;
  12043. }
  12044. var pageSegmentFlags = data[position + 16];
  12045. var pageStripingInformation = readUint16(data, position + 17);
  12046. pageInfo.lossless = !!(pageSegmentFlags & 1);
  12047. pageInfo.refinement = !!(pageSegmentFlags & 2);
  12048. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  12049. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  12050. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  12051. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  12052. args = [pageInfo];
  12053. break;
  12054. case 49: // EndOfPage
  12055. break;
  12056. case 50: // EndOfStripe
  12057. break;
  12058. case 51: // EndOfFile
  12059. break;
  12060. case 62: // 7.4.15 defines 2 extension types which
  12061. // are comments and can be ignored.
  12062. break;
  12063. default:
  12064. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12065. header.type + ') is not implemented');
  12066. }
  12067. var callbackName = 'on' + header.typeName;
  12068. if (callbackName in visitor) {
  12069. visitor[callbackName].apply(visitor, args);
  12070. }
  12071. }
  12072. function processSegments(segments, visitor) {
  12073. for (var i = 0, ii = segments.length; i < ii; i++) {
  12074. processSegment(segments[i], visitor);
  12075. }
  12076. }
  12077. function parseJbig2(data, start, end) {
  12078. var position = start;
  12079. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12080. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12081. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12082. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12083. error('JBIG2 error: invalid header');
  12084. }
  12085. var header = {};
  12086. position += 8;
  12087. var flags = data[position++];
  12088. header.randomAccess = !(flags & 1);
  12089. if (!(flags & 2)) {
  12090. header.numberOfPages = readUint32(data, position);
  12091. position += 4;
  12092. }
  12093. var segments = readSegments(header, data, position, end);
  12094. error('Not implemented');
  12095. // processSegments(segments, new SimpleSegmentVisitor());
  12096. }
  12097. function parseJbig2Chunks(chunks) {
  12098. var visitor = new SimpleSegmentVisitor();
  12099. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12100. var chunk = chunks[i];
  12101. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12102. processSegments(segments, visitor);
  12103. }
  12104. return visitor.buffer;
  12105. }
  12106. function SimpleSegmentVisitor() {}
  12107. SimpleSegmentVisitor.prototype = {
  12108. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12109. this.currentPageInfo = info;
  12110. var rowSize = (info.width + 7) >> 3;
  12111. var buffer = new Uint8Array(rowSize * info.height);
  12112. // The contents of ArrayBuffers are initialized to 0.
  12113. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12114. if (info.defaultPixelValue) {
  12115. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12116. buffer[i] = 0xFF;
  12117. }
  12118. }
  12119. this.buffer = buffer;
  12120. },
  12121. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12122. var pageInfo = this.currentPageInfo;
  12123. var width = regionInfo.width, height = regionInfo.height;
  12124. var rowSize = (pageInfo.width + 7) >> 3;
  12125. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12126. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12127. var buffer = this.buffer;
  12128. var mask0 = 128 >> (regionInfo.x & 7);
  12129. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12130. var i, j, mask, offset;
  12131. switch (combinationOperator) {
  12132. case 0: // OR
  12133. for (i = 0; i < height; i++) {
  12134. mask = mask0;
  12135. offset = offset0;
  12136. for (j = 0; j < width; j++) {
  12137. if (bitmap[i][j]) {
  12138. buffer[offset] |= mask;
  12139. }
  12140. mask >>= 1;
  12141. if (!mask) {
  12142. mask = 128;
  12143. offset++;
  12144. }
  12145. }
  12146. offset0 += rowSize;
  12147. }
  12148. break;
  12149. case 2: // XOR
  12150. for (i = 0; i < height; i++) {
  12151. mask = mask0;
  12152. offset = offset0;
  12153. for (j = 0; j < width; j++) {
  12154. if (bitmap[i][j]) {
  12155. buffer[offset] ^= mask;
  12156. }
  12157. mask >>= 1;
  12158. if (!mask) {
  12159. mask = 128;
  12160. offset++;
  12161. }
  12162. }
  12163. offset0 += rowSize;
  12164. }
  12165. break;
  12166. default:
  12167. error('JBIG2 error: operator ' + combinationOperator +
  12168. ' is not supported');
  12169. }
  12170. },
  12171. onImmediateGenericRegion:
  12172. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12173. start, end) {
  12174. var regionInfo = region.info;
  12175. var decodingContext = new DecodingContext(data, start, end);
  12176. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12177. region.template, region.prediction, null,
  12178. region.at, decodingContext);
  12179. this.drawBitmap(regionInfo, bitmap);
  12180. },
  12181. onImmediateLosslessGenericRegion:
  12182. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12183. this.onImmediateGenericRegion.apply(this, arguments);
  12184. },
  12185. onSymbolDictionary:
  12186. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12187. currentSegment,
  12188. referredSegments,
  12189. data, start, end) {
  12190. var huffmanTables;
  12191. if (dictionary.huffman) {
  12192. error('JBIG2 error: huffman is not supported');
  12193. }
  12194. // Combines exported symbols from all referred segments
  12195. var symbols = this.symbols;
  12196. if (!symbols) {
  12197. this.symbols = symbols = {};
  12198. }
  12199. var inputSymbols = [];
  12200. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12201. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12202. }
  12203. var decodingContext = new DecodingContext(data, start, end);
  12204. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12205. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12206. dictionary.numberOfExportedSymbols, huffmanTables,
  12207. dictionary.template, dictionary.at,
  12208. dictionary.refinementTemplate, dictionary.refinementAt,
  12209. decodingContext);
  12210. },
  12211. onImmediateTextRegion:
  12212. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12213. referredSegments,
  12214. data, start, end) {
  12215. var regionInfo = region.info;
  12216. var huffmanTables;
  12217. // Combines exported symbols from all referred segments
  12218. var symbols = this.symbols;
  12219. var inputSymbols = [];
  12220. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12221. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12222. }
  12223. var symbolCodeLength = log2(inputSymbols.length);
  12224. var decodingContext = new DecodingContext(data, start, end);
  12225. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12226. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12227. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12228. symbolCodeLength, region.transposed, region.dsOffset,
  12229. region.referenceCorner, region.combinationOperator, huffmanTables,
  12230. region.refinementTemplate, region.refinementAt, decodingContext);
  12231. this.drawBitmap(regionInfo, bitmap);
  12232. },
  12233. onImmediateLosslessTextRegion:
  12234. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12235. this.onImmediateTextRegion.apply(this, arguments);
  12236. }
  12237. };
  12238. function Jbig2Image() {}
  12239. Jbig2Image.prototype = {
  12240. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12241. return parseJbig2Chunks(chunks);
  12242. }
  12243. };
  12244. return Jbig2Image;
  12245. })();
  12246. exports.Jbig2Image = Jbig2Image;
  12247. }));
  12248. (function (root, factory) {
  12249. {
  12250. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12251. root.pdfjsCoreArithmeticDecoder);
  12252. }
  12253. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12254. var info = sharedUtil.info;
  12255. var log2 = sharedUtil.log2;
  12256. var readUint16 = sharedUtil.readUint16;
  12257. var readUint32 = sharedUtil.readUint32;
  12258. var warn = sharedUtil.warn;
  12259. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12260. var JpxImage = (function JpxImageClosure() {
  12261. // Table E.1
  12262. var SubbandsGainLog2 = {
  12263. 'LL': 0,
  12264. 'LH': 1,
  12265. 'HL': 1,
  12266. 'HH': 2
  12267. };
  12268. function JpxImage() {
  12269. this.failOnCorruptedImage = false;
  12270. }
  12271. JpxImage.prototype = {
  12272. parse: function JpxImage_parse(data) {
  12273. var head = readUint16(data, 0);
  12274. // No box header, immediate start of codestream (SOC)
  12275. if (head === 0xFF4F) {
  12276. this.parseCodestream(data, 0, data.length);
  12277. return;
  12278. }
  12279. var position = 0, length = data.length;
  12280. while (position < length) {
  12281. var headerSize = 8;
  12282. var lbox = readUint32(data, position);
  12283. var tbox = readUint32(data, position + 4);
  12284. position += headerSize;
  12285. if (lbox === 1) {
  12286. // XLBox: read UInt64 according to spec.
  12287. // JavaScript's int precision of 53 bit should be sufficient here.
  12288. lbox = readUint32(data, position) * 4294967296 +
  12289. readUint32(data, position + 4);
  12290. position += 8;
  12291. headerSize += 8;
  12292. }
  12293. if (lbox === 0) {
  12294. lbox = length - position + headerSize;
  12295. }
  12296. if (lbox < headerSize) {
  12297. throw new Error('JPX Error: Invalid box field size');
  12298. }
  12299. var dataLength = lbox - headerSize;
  12300. var jumpDataLength = true;
  12301. switch (tbox) {
  12302. case 0x6A703268: // 'jp2h'
  12303. jumpDataLength = false; // parsing child boxes
  12304. break;
  12305. case 0x636F6C72: // 'colr'
  12306. // Colorspaces are not used, the CS from the PDF is used.
  12307. var method = data[position];
  12308. if (method === 1) {
  12309. // enumerated colorspace
  12310. var colorspace = readUint32(data, position + 3);
  12311. switch (colorspace) {
  12312. case 16: // this indicates a sRGB colorspace
  12313. case 17: // this indicates a grayscale colorspace
  12314. case 18: // this indicates a YUV colorspace
  12315. break;
  12316. default:
  12317. warn('Unknown colorspace ' + colorspace);
  12318. break;
  12319. }
  12320. } else if (method === 2) {
  12321. info('ICC profile not supported');
  12322. }
  12323. break;
  12324. case 0x6A703263: // 'jp2c'
  12325. this.parseCodestream(data, position, position + dataLength);
  12326. break;
  12327. case 0x6A502020: // 'jP\024\024'
  12328. if (0x0d0a870a !== readUint32(data, position)) {
  12329. warn('Invalid JP2 signature');
  12330. }
  12331. break;
  12332. // The following header types are valid but currently not used:
  12333. case 0x6A501A1A: // 'jP\032\032'
  12334. case 0x66747970: // 'ftyp'
  12335. case 0x72726571: // 'rreq'
  12336. case 0x72657320: // 'res '
  12337. case 0x69686472: // 'ihdr'
  12338. break;
  12339. default:
  12340. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12341. (tbox >> 16) & 0xFF,
  12342. (tbox >> 8) & 0xFF,
  12343. tbox & 0xFF);
  12344. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12345. break;
  12346. }
  12347. if (jumpDataLength) {
  12348. position += dataLength;
  12349. }
  12350. }
  12351. },
  12352. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12353. var newByte = stream.getByte();
  12354. while (newByte >= 0) {
  12355. var oldByte = newByte;
  12356. newByte = stream.getByte();
  12357. var code = (oldByte << 8) | newByte;
  12358. // Image and tile size (SIZ)
  12359. if (code === 0xFF51) {
  12360. stream.skip(4);
  12361. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12362. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12363. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12364. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12365. stream.skip(16);
  12366. var Csiz = stream.getUint16(); // Byte 36
  12367. this.width = Xsiz - XOsiz;
  12368. this.height = Ysiz - YOsiz;
  12369. this.componentsCount = Csiz;
  12370. // Results are always returned as Uint8Arrays
  12371. this.bitsPerComponent = 8;
  12372. return;
  12373. }
  12374. }
  12375. throw new Error('JPX Error: No size marker found in JPX stream');
  12376. },
  12377. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12378. var context = {};
  12379. try {
  12380. var doNotRecover = false;
  12381. var position = start;
  12382. while (position + 1 < end) {
  12383. var code = readUint16(data, position);
  12384. position += 2;
  12385. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12386. switch (code) {
  12387. case 0xFF4F: // Start of codestream (SOC)
  12388. context.mainHeader = true;
  12389. break;
  12390. case 0xFFD9: // End of codestream (EOC)
  12391. break;
  12392. case 0xFF51: // Image and tile size (SIZ)
  12393. length = readUint16(data, position);
  12394. var siz = {};
  12395. siz.Xsiz = readUint32(data, position + 4);
  12396. siz.Ysiz = readUint32(data, position + 8);
  12397. siz.XOsiz = readUint32(data, position + 12);
  12398. siz.YOsiz = readUint32(data, position + 16);
  12399. siz.XTsiz = readUint32(data, position + 20);
  12400. siz.YTsiz = readUint32(data, position + 24);
  12401. siz.XTOsiz = readUint32(data, position + 28);
  12402. siz.YTOsiz = readUint32(data, position + 32);
  12403. var componentsCount = readUint16(data, position + 36);
  12404. siz.Csiz = componentsCount;
  12405. var components = [];
  12406. j = position + 38;
  12407. for (var i = 0; i < componentsCount; i++) {
  12408. var component = {
  12409. precision: (data[j] & 0x7F) + 1,
  12410. isSigned: !!(data[j] & 0x80),
  12411. XRsiz: data[j + 1],
  12412. YRsiz: data[j + 1]
  12413. };
  12414. calculateComponentDimensions(component, siz);
  12415. components.push(component);
  12416. }
  12417. context.SIZ = siz;
  12418. context.components = components;
  12419. calculateTileGrids(context, components);
  12420. context.QCC = [];
  12421. context.COC = [];
  12422. break;
  12423. case 0xFF5C: // Quantization default (QCD)
  12424. length = readUint16(data, position);
  12425. var qcd = {};
  12426. j = position + 2;
  12427. sqcd = data[j++];
  12428. switch (sqcd & 0x1F) {
  12429. case 0:
  12430. spqcdSize = 8;
  12431. scalarExpounded = true;
  12432. break;
  12433. case 1:
  12434. spqcdSize = 16;
  12435. scalarExpounded = false;
  12436. break;
  12437. case 2:
  12438. spqcdSize = 16;
  12439. scalarExpounded = true;
  12440. break;
  12441. default:
  12442. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12443. }
  12444. qcd.noQuantization = (spqcdSize === 8);
  12445. qcd.scalarExpounded = scalarExpounded;
  12446. qcd.guardBits = sqcd >> 5;
  12447. spqcds = [];
  12448. while (j < length + position) {
  12449. var spqcd = {};
  12450. if (spqcdSize === 8) {
  12451. spqcd.epsilon = data[j++] >> 3;
  12452. spqcd.mu = 0;
  12453. } else {
  12454. spqcd.epsilon = data[j] >> 3;
  12455. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12456. j += 2;
  12457. }
  12458. spqcds.push(spqcd);
  12459. }
  12460. qcd.SPqcds = spqcds;
  12461. if (context.mainHeader) {
  12462. context.QCD = qcd;
  12463. } else {
  12464. context.currentTile.QCD = qcd;
  12465. context.currentTile.QCC = [];
  12466. }
  12467. break;
  12468. case 0xFF5D: // Quantization component (QCC)
  12469. length = readUint16(data, position);
  12470. var qcc = {};
  12471. j = position + 2;
  12472. var cqcc;
  12473. if (context.SIZ.Csiz < 257) {
  12474. cqcc = data[j++];
  12475. } else {
  12476. cqcc = readUint16(data, j);
  12477. j += 2;
  12478. }
  12479. sqcd = data[j++];
  12480. switch (sqcd & 0x1F) {
  12481. case 0:
  12482. spqcdSize = 8;
  12483. scalarExpounded = true;
  12484. break;
  12485. case 1:
  12486. spqcdSize = 16;
  12487. scalarExpounded = false;
  12488. break;
  12489. case 2:
  12490. spqcdSize = 16;
  12491. scalarExpounded = true;
  12492. break;
  12493. default:
  12494. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12495. }
  12496. qcc.noQuantization = (spqcdSize === 8);
  12497. qcc.scalarExpounded = scalarExpounded;
  12498. qcc.guardBits = sqcd >> 5;
  12499. spqcds = [];
  12500. while (j < (length + position)) {
  12501. spqcd = {};
  12502. if (spqcdSize === 8) {
  12503. spqcd.epsilon = data[j++] >> 3;
  12504. spqcd.mu = 0;
  12505. } else {
  12506. spqcd.epsilon = data[j] >> 3;
  12507. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12508. j += 2;
  12509. }
  12510. spqcds.push(spqcd);
  12511. }
  12512. qcc.SPqcds = spqcds;
  12513. if (context.mainHeader) {
  12514. context.QCC[cqcc] = qcc;
  12515. } else {
  12516. context.currentTile.QCC[cqcc] = qcc;
  12517. }
  12518. break;
  12519. case 0xFF52: // Coding style default (COD)
  12520. length = readUint16(data, position);
  12521. var cod = {};
  12522. j = position + 2;
  12523. var scod = data[j++];
  12524. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  12525. cod.sopMarkerUsed = !!(scod & 2);
  12526. cod.ephMarkerUsed = !!(scod & 4);
  12527. cod.progressionOrder = data[j++];
  12528. cod.layersCount = readUint16(data, j);
  12529. j += 2;
  12530. cod.multipleComponentTransform = data[j++];
  12531. cod.decompositionLevelsCount = data[j++];
  12532. cod.xcb = (data[j++] & 0xF) + 2;
  12533. cod.ycb = (data[j++] & 0xF) + 2;
  12534. var blockStyle = data[j++];
  12535. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  12536. cod.resetContextProbabilities = !!(blockStyle & 2);
  12537. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  12538. cod.verticalyStripe = !!(blockStyle & 8);
  12539. cod.predictableTermination = !!(blockStyle & 16);
  12540. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  12541. cod.reversibleTransformation = data[j++];
  12542. if (cod.entropyCoderWithCustomPrecincts) {
  12543. var precinctsSizes = [];
  12544. while (j < length + position) {
  12545. var precinctsSize = data[j++];
  12546. precinctsSizes.push({
  12547. PPx: precinctsSize & 0xF,
  12548. PPy: precinctsSize >> 4
  12549. });
  12550. }
  12551. cod.precinctsSizes = precinctsSizes;
  12552. }
  12553. var unsupported = [];
  12554. if (cod.selectiveArithmeticCodingBypass) {
  12555. unsupported.push('selectiveArithmeticCodingBypass');
  12556. }
  12557. if (cod.resetContextProbabilities) {
  12558. unsupported.push('resetContextProbabilities');
  12559. }
  12560. if (cod.terminationOnEachCodingPass) {
  12561. unsupported.push('terminationOnEachCodingPass');
  12562. }
  12563. if (cod.verticalyStripe) {
  12564. unsupported.push('verticalyStripe');
  12565. }
  12566. if (cod.predictableTermination) {
  12567. unsupported.push('predictableTermination');
  12568. }
  12569. if (unsupported.length > 0) {
  12570. doNotRecover = true;
  12571. throw new Error('JPX Error: Unsupported COD options (' +
  12572. unsupported.join(', ') + ')');
  12573. }
  12574. if (context.mainHeader) {
  12575. context.COD = cod;
  12576. } else {
  12577. context.currentTile.COD = cod;
  12578. context.currentTile.COC = [];
  12579. }
  12580. break;
  12581. case 0xFF90: // Start of tile-part (SOT)
  12582. length = readUint16(data, position);
  12583. tile = {};
  12584. tile.index = readUint16(data, position + 2);
  12585. tile.length = readUint32(data, position + 4);
  12586. tile.dataEnd = tile.length + position - 2;
  12587. tile.partIndex = data[position + 8];
  12588. tile.partsCount = data[position + 9];
  12589. context.mainHeader = false;
  12590. if (tile.partIndex === 0) {
  12591. // reset component specific settings
  12592. tile.COD = context.COD;
  12593. tile.COC = context.COC.slice(0); // clone of the global COC
  12594. tile.QCD = context.QCD;
  12595. tile.QCC = context.QCC.slice(0); // clone of the global COC
  12596. }
  12597. context.currentTile = tile;
  12598. break;
  12599. case 0xFF93: // Start of data (SOD)
  12600. tile = context.currentTile;
  12601. if (tile.partIndex === 0) {
  12602. initializeTile(context, tile.index);
  12603. buildPackets(context);
  12604. }
  12605. // moving to the end of the data
  12606. length = tile.dataEnd - position;
  12607. parseTilePackets(context, data, position, length);
  12608. break;
  12609. case 0xFF55: // Tile-part lengths, main header (TLM)
  12610. case 0xFF57: // Packet length, main header (PLM)
  12611. case 0xFF58: // Packet length, tile-part header (PLT)
  12612. case 0xFF64: // Comment (COM)
  12613. length = readUint16(data, position);
  12614. // skipping content
  12615. break;
  12616. case 0xFF53: // Coding style component (COC)
  12617. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  12618. 'not implemented');
  12619. default:
  12620. throw new Error('JPX Error: Unknown codestream code: ' +
  12621. code.toString(16));
  12622. }
  12623. position += length;
  12624. }
  12625. } catch (e) {
  12626. if (doNotRecover || this.failOnCorruptedImage) {
  12627. throw e;
  12628. } else {
  12629. warn('Trying to recover from ' + e.message);
  12630. }
  12631. }
  12632. this.tiles = transformComponents(context);
  12633. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  12634. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  12635. this.componentsCount = context.SIZ.Csiz;
  12636. }
  12637. };
  12638. function calculateComponentDimensions(component, siz) {
  12639. // Section B.2 Component mapping
  12640. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  12641. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  12642. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  12643. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  12644. component.width = component.x1 - component.x0;
  12645. component.height = component.y1 - component.y0;
  12646. }
  12647. function calculateTileGrids(context, components) {
  12648. var siz = context.SIZ;
  12649. // Section B.3 Division into tile and tile-components
  12650. var tile, tiles = [];
  12651. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12652. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12653. for (var q = 0; q < numYtiles; q++) {
  12654. for (var p = 0; p < numXtiles; p++) {
  12655. tile = {};
  12656. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12657. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12658. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12659. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12660. tile.width = tile.tx1 - tile.tx0;
  12661. tile.height = tile.ty1 - tile.ty0;
  12662. tile.components = [];
  12663. tiles.push(tile);
  12664. }
  12665. }
  12666. context.tiles = tiles;
  12667. var componentsCount = siz.Csiz;
  12668. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12669. var component = components[i];
  12670. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12671. var tileComponent = {};
  12672. tile = tiles[j];
  12673. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12674. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12675. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12676. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12677. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12678. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12679. tile.components[i] = tileComponent;
  12680. }
  12681. }
  12682. }
  12683. function getBlocksDimensions(context, component, r) {
  12684. var codOrCoc = component.codingStyleParameters;
  12685. var result = {};
  12686. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12687. result.PPx = 15;
  12688. result.PPy = 15;
  12689. } else {
  12690. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12691. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12692. }
  12693. // calculate codeblock size as described in section B.7
  12694. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12695. Math.min(codOrCoc.xcb, result.PPx));
  12696. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12697. Math.min(codOrCoc.ycb, result.PPy));
  12698. return result;
  12699. }
  12700. function buildPrecincts(context, resolution, dimensions) {
  12701. // Section B.6 Division resolution to precincts
  12702. var precinctWidth = 1 << dimensions.PPx;
  12703. var precinctHeight = 1 << dimensions.PPy;
  12704. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12705. // to precincts. Precinct partition divides a resolution according to width
  12706. // and height parameters. The subband that belongs to the resolution level
  12707. // has a different size than the level, unless it is the zero resolution.
  12708. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12709. // The precinct partitioning for a particular subband is derived from a
  12710. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12711. // resolution level)... The LL band associated with each resolution level is
  12712. // divided into precincts... Each of the resulting precinct regions is then
  12713. // mapped into its child subbands (if any) at the next lower resolution
  12714. // level. This is accomplished by using the coordinate transformation
  12715. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12716. // coordinates of a point in the LL band and child subband, respectively.
  12717. var isZeroRes = resolution.resLevel === 0;
  12718. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12719. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12720. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12721. Math.ceil(resolution.trx1 / precinctWidth) -
  12722. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12723. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12724. Math.ceil(resolution.try1 / precinctHeight) -
  12725. Math.floor(resolution.try0 / precinctHeight) : 0);
  12726. var numprecincts = numprecinctswide * numprecinctshigh;
  12727. resolution.precinctParameters = {
  12728. precinctWidth: precinctWidth,
  12729. precinctHeight: precinctHeight,
  12730. numprecinctswide: numprecinctswide,
  12731. numprecinctshigh: numprecinctshigh,
  12732. numprecincts: numprecincts,
  12733. precinctWidthInSubband: precinctWidthInSubband,
  12734. precinctHeightInSubband: precinctHeightInSubband
  12735. };
  12736. }
  12737. function buildCodeblocks(context, subband, dimensions) {
  12738. // Section B.7 Division sub-band into code-blocks
  12739. var xcb_ = dimensions.xcb_;
  12740. var ycb_ = dimensions.ycb_;
  12741. var codeblockWidth = 1 << xcb_;
  12742. var codeblockHeight = 1 << ycb_;
  12743. var cbx0 = subband.tbx0 >> xcb_;
  12744. var cby0 = subband.tby0 >> ycb_;
  12745. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12746. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12747. var precinctParameters = subband.resolution.precinctParameters;
  12748. var codeblocks = [];
  12749. var precincts = [];
  12750. var i, j, codeblock, precinctNumber;
  12751. for (j = cby0; j < cby1; j++) {
  12752. for (i = cbx0; i < cbx1; i++) {
  12753. codeblock = {
  12754. cbx: i,
  12755. cby: j,
  12756. tbx0: codeblockWidth * i,
  12757. tby0: codeblockHeight * j,
  12758. tbx1: codeblockWidth * (i + 1),
  12759. tby1: codeblockHeight * (j + 1)
  12760. };
  12761. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12762. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12763. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12764. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12765. // Calculate precinct number for this codeblock, codeblock position
  12766. // should be relative to its subband, use actual dimension and position
  12767. // See comment about codeblock group width and height
  12768. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12769. precinctParameters.precinctWidthInSubband);
  12770. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12771. precinctParameters.precinctHeightInSubband);
  12772. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12773. codeblock.precinctNumber = precinctNumber;
  12774. codeblock.subbandType = subband.type;
  12775. codeblock.Lblock = 3;
  12776. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12777. codeblock.tby1_ <= codeblock.tby0_) {
  12778. continue;
  12779. }
  12780. codeblocks.push(codeblock);
  12781. // building precinct for the sub-band
  12782. var precinct = precincts[precinctNumber];
  12783. if (precinct !== undefined) {
  12784. if (i < precinct.cbxMin) {
  12785. precinct.cbxMin = i;
  12786. } else if (i > precinct.cbxMax) {
  12787. precinct.cbxMax = i;
  12788. }
  12789. if (j < precinct.cbyMin) {
  12790. precinct.cbxMin = j;
  12791. } else if (j > precinct.cbyMax) {
  12792. precinct.cbyMax = j;
  12793. }
  12794. } else {
  12795. precincts[precinctNumber] = precinct = {
  12796. cbxMin: i,
  12797. cbyMin: j,
  12798. cbxMax: i,
  12799. cbyMax: j
  12800. };
  12801. }
  12802. codeblock.precinct = precinct;
  12803. }
  12804. }
  12805. subband.codeblockParameters = {
  12806. codeblockWidth: xcb_,
  12807. codeblockHeight: ycb_,
  12808. numcodeblockwide: cbx1 - cbx0 + 1,
  12809. numcodeblockhigh: cby1 - cby0 + 1
  12810. };
  12811. subband.codeblocks = codeblocks;
  12812. subband.precincts = precincts;
  12813. }
  12814. function createPacket(resolution, precinctNumber, layerNumber) {
  12815. var precinctCodeblocks = [];
  12816. // Section B.10.8 Order of info in packet
  12817. var subbands = resolution.subbands;
  12818. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12819. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12820. var subband = subbands[i];
  12821. var codeblocks = subband.codeblocks;
  12822. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12823. var codeblock = codeblocks[j];
  12824. if (codeblock.precinctNumber !== precinctNumber) {
  12825. continue;
  12826. }
  12827. precinctCodeblocks.push(codeblock);
  12828. }
  12829. }
  12830. return {
  12831. layerNumber: layerNumber,
  12832. codeblocks: precinctCodeblocks
  12833. };
  12834. }
  12835. function LayerResolutionComponentPositionIterator(context) {
  12836. var siz = context.SIZ;
  12837. var tileIndex = context.currentTile.index;
  12838. var tile = context.tiles[tileIndex];
  12839. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12840. var componentsCount = siz.Csiz;
  12841. var maxDecompositionLevelsCount = 0;
  12842. for (var q = 0; q < componentsCount; q++) {
  12843. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12844. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12845. }
  12846. var l = 0, r = 0, i = 0, k = 0;
  12847. this.nextPacket = function JpxImage_nextPacket() {
  12848. // Section B.12.1.1 Layer-resolution-component-position
  12849. for (; l < layersCount; l++) {
  12850. for (; r <= maxDecompositionLevelsCount; r++) {
  12851. for (; i < componentsCount; i++) {
  12852. var component = tile.components[i];
  12853. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12854. continue;
  12855. }
  12856. var resolution = component.resolutions[r];
  12857. var numprecincts = resolution.precinctParameters.numprecincts;
  12858. for (; k < numprecincts;) {
  12859. var packet = createPacket(resolution, k, l);
  12860. k++;
  12861. return packet;
  12862. }
  12863. k = 0;
  12864. }
  12865. i = 0;
  12866. }
  12867. r = 0;
  12868. }
  12869. throw new Error('JPX Error: Out of packets');
  12870. };
  12871. }
  12872. function ResolutionLayerComponentPositionIterator(context) {
  12873. var siz = context.SIZ;
  12874. var tileIndex = context.currentTile.index;
  12875. var tile = context.tiles[tileIndex];
  12876. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12877. var componentsCount = siz.Csiz;
  12878. var maxDecompositionLevelsCount = 0;
  12879. for (var q = 0; q < componentsCount; q++) {
  12880. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12881. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12882. }
  12883. var r = 0, l = 0, i = 0, k = 0;
  12884. this.nextPacket = function JpxImage_nextPacket() {
  12885. // Section B.12.1.2 Resolution-layer-component-position
  12886. for (; r <= maxDecompositionLevelsCount; r++) {
  12887. for (; l < layersCount; l++) {
  12888. for (; i < componentsCount; i++) {
  12889. var component = tile.components[i];
  12890. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12891. continue;
  12892. }
  12893. var resolution = component.resolutions[r];
  12894. var numprecincts = resolution.precinctParameters.numprecincts;
  12895. for (; k < numprecincts;) {
  12896. var packet = createPacket(resolution, k, l);
  12897. k++;
  12898. return packet;
  12899. }
  12900. k = 0;
  12901. }
  12902. i = 0;
  12903. }
  12904. l = 0;
  12905. }
  12906. throw new Error('JPX Error: Out of packets');
  12907. };
  12908. }
  12909. function ResolutionPositionComponentLayerIterator(context) {
  12910. var siz = context.SIZ;
  12911. var tileIndex = context.currentTile.index;
  12912. var tile = context.tiles[tileIndex];
  12913. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12914. var componentsCount = siz.Csiz;
  12915. var l, r, c, p;
  12916. var maxDecompositionLevelsCount = 0;
  12917. for (c = 0; c < componentsCount; c++) {
  12918. var component = tile.components[c];
  12919. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12920. component.codingStyleParameters.decompositionLevelsCount);
  12921. }
  12922. var maxNumPrecinctsInLevel = new Int32Array(
  12923. maxDecompositionLevelsCount + 1);
  12924. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12925. var maxNumPrecincts = 0;
  12926. for (c = 0; c < componentsCount; ++c) {
  12927. var resolutions = tile.components[c].resolutions;
  12928. if (r < resolutions.length) {
  12929. maxNumPrecincts = Math.max(maxNumPrecincts,
  12930. resolutions[r].precinctParameters.numprecincts);
  12931. }
  12932. }
  12933. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12934. }
  12935. l = 0;
  12936. r = 0;
  12937. c = 0;
  12938. p = 0;
  12939. this.nextPacket = function JpxImage_nextPacket() {
  12940. // Section B.12.1.3 Resolution-position-component-layer
  12941. for (; r <= maxDecompositionLevelsCount; r++) {
  12942. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12943. for (; c < componentsCount; c++) {
  12944. var component = tile.components[c];
  12945. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12946. continue;
  12947. }
  12948. var resolution = component.resolutions[r];
  12949. var numprecincts = resolution.precinctParameters.numprecincts;
  12950. if (p >= numprecincts) {
  12951. continue;
  12952. }
  12953. for (; l < layersCount;) {
  12954. var packet = createPacket(resolution, p, l);
  12955. l++;
  12956. return packet;
  12957. }
  12958. l = 0;
  12959. }
  12960. c = 0;
  12961. }
  12962. p = 0;
  12963. }
  12964. throw new Error('JPX Error: Out of packets');
  12965. };
  12966. }
  12967. function PositionComponentResolutionLayerIterator(context) {
  12968. var siz = context.SIZ;
  12969. var tileIndex = context.currentTile.index;
  12970. var tile = context.tiles[tileIndex];
  12971. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12972. var componentsCount = siz.Csiz;
  12973. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12974. var precinctsIterationSizes = precinctsSizes;
  12975. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12976. this.nextPacket = function JpxImage_nextPacket() {
  12977. // Section B.12.1.4 Position-component-resolution-layer
  12978. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12979. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12980. for (; c < componentsCount; c++) {
  12981. var component = tile.components[c];
  12982. var decompositionLevelsCount =
  12983. component.codingStyleParameters.decompositionLevelsCount;
  12984. for (; r <= decompositionLevelsCount; r++) {
  12985. var resolution = component.resolutions[r];
  12986. var sizeInImageScale =
  12987. precinctsSizes.components[c].resolutions[r];
  12988. var k = getPrecinctIndexIfExist(
  12989. px,
  12990. py,
  12991. sizeInImageScale,
  12992. precinctsIterationSizes,
  12993. resolution);
  12994. if (k === null) {
  12995. continue;
  12996. }
  12997. for (; l < layersCount;) {
  12998. var packet = createPacket(resolution, k, l);
  12999. l++;
  13000. return packet;
  13001. }
  13002. l = 0;
  13003. }
  13004. r = 0;
  13005. }
  13006. c = 0;
  13007. }
  13008. px = 0;
  13009. }
  13010. throw new Error('JPX Error: Out of packets');
  13011. };
  13012. }
  13013. function ComponentPositionResolutionLayerIterator(context) {
  13014. var siz = context.SIZ;
  13015. var tileIndex = context.currentTile.index;
  13016. var tile = context.tiles[tileIndex];
  13017. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13018. var componentsCount = siz.Csiz;
  13019. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  13020. var l = 0, r = 0, c = 0, px = 0, py = 0;
  13021. this.nextPacket = function JpxImage_nextPacket() {
  13022. // Section B.12.1.5 Component-position-resolution-layer
  13023. for (; c < componentsCount; ++c) {
  13024. var component = tile.components[c];
  13025. var precinctsIterationSizes = precinctsSizes.components[c];
  13026. var decompositionLevelsCount =
  13027. component.codingStyleParameters.decompositionLevelsCount;
  13028. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  13029. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  13030. for (; r <= decompositionLevelsCount; r++) {
  13031. var resolution = component.resolutions[r];
  13032. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  13033. var k = getPrecinctIndexIfExist(
  13034. px,
  13035. py,
  13036. sizeInImageScale,
  13037. precinctsIterationSizes,
  13038. resolution);
  13039. if (k === null) {
  13040. continue;
  13041. }
  13042. for (; l < layersCount;) {
  13043. var packet = createPacket(resolution, k, l);
  13044. l++;
  13045. return packet;
  13046. }
  13047. l = 0;
  13048. }
  13049. r = 0;
  13050. }
  13051. px = 0;
  13052. }
  13053. py = 0;
  13054. }
  13055. throw new Error('JPX Error: Out of packets');
  13056. };
  13057. }
  13058. function getPrecinctIndexIfExist(
  13059. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13060. var posX = pxIndex * precinctIterationSizes.minWidth;
  13061. var posY = pyIndex * precinctIterationSizes.minHeight;
  13062. if (posX % sizeInImageScale.width !== 0 ||
  13063. posY % sizeInImageScale.height !== 0) {
  13064. return null;
  13065. }
  13066. var startPrecinctRowIndex =
  13067. (posY / sizeInImageScale.width) *
  13068. resolution.precinctParameters.numprecinctswide;
  13069. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13070. }
  13071. function getPrecinctSizesInImageScale(tile) {
  13072. var componentsCount = tile.components.length;
  13073. var minWidth = Number.MAX_VALUE;
  13074. var minHeight = Number.MAX_VALUE;
  13075. var maxNumWide = 0;
  13076. var maxNumHigh = 0;
  13077. var sizePerComponent = new Array(componentsCount);
  13078. for (var c = 0; c < componentsCount; c++) {
  13079. var component = tile.components[c];
  13080. var decompositionLevelsCount =
  13081. component.codingStyleParameters.decompositionLevelsCount;
  13082. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13083. var minWidthCurrentComponent = Number.MAX_VALUE;
  13084. var minHeightCurrentComponent = Number.MAX_VALUE;
  13085. var maxNumWideCurrentComponent = 0;
  13086. var maxNumHighCurrentComponent = 0;
  13087. var scale = 1;
  13088. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13089. var resolution = component.resolutions[r];
  13090. var widthCurrentResolution =
  13091. scale * resolution.precinctParameters.precinctWidth;
  13092. var heightCurrentResolution =
  13093. scale * resolution.precinctParameters.precinctHeight;
  13094. minWidthCurrentComponent = Math.min(
  13095. minWidthCurrentComponent,
  13096. widthCurrentResolution);
  13097. minHeightCurrentComponent = Math.min(
  13098. minHeightCurrentComponent,
  13099. heightCurrentResolution);
  13100. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13101. resolution.precinctParameters.numprecinctswide);
  13102. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13103. resolution.precinctParameters.numprecinctshigh);
  13104. sizePerResolution[r] = {
  13105. width: widthCurrentResolution,
  13106. height: heightCurrentResolution
  13107. };
  13108. scale <<= 1;
  13109. }
  13110. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13111. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13112. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13113. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13114. sizePerComponent[c] = {
  13115. resolutions: sizePerResolution,
  13116. minWidth: minWidthCurrentComponent,
  13117. minHeight: minHeightCurrentComponent,
  13118. maxNumWide: maxNumWideCurrentComponent,
  13119. maxNumHigh: maxNumHighCurrentComponent
  13120. };
  13121. }
  13122. return {
  13123. components: sizePerComponent,
  13124. minWidth: minWidth,
  13125. minHeight: minHeight,
  13126. maxNumWide: maxNumWide,
  13127. maxNumHigh: maxNumHigh
  13128. };
  13129. }
  13130. function buildPackets(context) {
  13131. var siz = context.SIZ;
  13132. var tileIndex = context.currentTile.index;
  13133. var tile = context.tiles[tileIndex];
  13134. var componentsCount = siz.Csiz;
  13135. // Creating resolutions and sub-bands for each component
  13136. for (var c = 0; c < componentsCount; c++) {
  13137. var component = tile.components[c];
  13138. var decompositionLevelsCount =
  13139. component.codingStyleParameters.decompositionLevelsCount;
  13140. // Section B.5 Resolution levels and sub-bands
  13141. var resolutions = [];
  13142. var subbands = [];
  13143. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13144. var blocksDimensions = getBlocksDimensions(context, component, r);
  13145. var resolution = {};
  13146. var scale = 1 << (decompositionLevelsCount - r);
  13147. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13148. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13149. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13150. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13151. resolution.resLevel = r;
  13152. buildPrecincts(context, resolution, blocksDimensions);
  13153. resolutions.push(resolution);
  13154. var subband;
  13155. if (r === 0) {
  13156. // one sub-band (LL) with last decomposition
  13157. subband = {};
  13158. subband.type = 'LL';
  13159. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13160. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13161. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13162. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13163. subband.resolution = resolution;
  13164. buildCodeblocks(context, subband, blocksDimensions);
  13165. subbands.push(subband);
  13166. resolution.subbands = [subband];
  13167. } else {
  13168. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13169. var resolutionSubbands = [];
  13170. // three sub-bands (HL, LH and HH) with rest of decompositions
  13171. subband = {};
  13172. subband.type = 'HL';
  13173. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13174. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13175. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13176. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13177. subband.resolution = resolution;
  13178. buildCodeblocks(context, subband, blocksDimensions);
  13179. subbands.push(subband);
  13180. resolutionSubbands.push(subband);
  13181. subband = {};
  13182. subband.type = 'LH';
  13183. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13184. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13185. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13186. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13187. subband.resolution = resolution;
  13188. buildCodeblocks(context, subband, blocksDimensions);
  13189. subbands.push(subband);
  13190. resolutionSubbands.push(subband);
  13191. subband = {};
  13192. subband.type = 'HH';
  13193. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13194. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13195. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13196. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13197. subband.resolution = resolution;
  13198. buildCodeblocks(context, subband, blocksDimensions);
  13199. subbands.push(subband);
  13200. resolutionSubbands.push(subband);
  13201. resolution.subbands = resolutionSubbands;
  13202. }
  13203. }
  13204. component.resolutions = resolutions;
  13205. component.subbands = subbands;
  13206. }
  13207. // Generate the packets sequence
  13208. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13209. switch (progressionOrder) {
  13210. case 0:
  13211. tile.packetsIterator =
  13212. new LayerResolutionComponentPositionIterator(context);
  13213. break;
  13214. case 1:
  13215. tile.packetsIterator =
  13216. new ResolutionLayerComponentPositionIterator(context);
  13217. break;
  13218. case 2:
  13219. tile.packetsIterator =
  13220. new ResolutionPositionComponentLayerIterator(context);
  13221. break;
  13222. case 3:
  13223. tile.packetsIterator =
  13224. new PositionComponentResolutionLayerIterator(context);
  13225. break;
  13226. case 4:
  13227. tile.packetsIterator =
  13228. new ComponentPositionResolutionLayerIterator(context);
  13229. break;
  13230. default:
  13231. throw new Error('JPX Error: Unsupported progression order ' +
  13232. progressionOrder);
  13233. }
  13234. }
  13235. function parseTilePackets(context, data, offset, dataLength) {
  13236. var position = 0;
  13237. var buffer, bufferSize = 0, skipNextBit = false;
  13238. function readBits(count) {
  13239. while (bufferSize < count) {
  13240. var b = data[offset + position];
  13241. position++;
  13242. if (skipNextBit) {
  13243. buffer = (buffer << 7) | b;
  13244. bufferSize += 7;
  13245. skipNextBit = false;
  13246. } else {
  13247. buffer = (buffer << 8) | b;
  13248. bufferSize += 8;
  13249. }
  13250. if (b === 0xFF) {
  13251. skipNextBit = true;
  13252. }
  13253. }
  13254. bufferSize -= count;
  13255. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13256. }
  13257. function skipMarkerIfEqual(value) {
  13258. if (data[offset + position - 1] === 0xFF &&
  13259. data[offset + position] === value) {
  13260. skipBytes(1);
  13261. return true;
  13262. } else if (data[offset + position] === 0xFF &&
  13263. data[offset + position + 1] === value) {
  13264. skipBytes(2);
  13265. return true;
  13266. }
  13267. return false;
  13268. }
  13269. function skipBytes(count) {
  13270. position += count;
  13271. }
  13272. function alignToByte() {
  13273. bufferSize = 0;
  13274. if (skipNextBit) {
  13275. position++;
  13276. skipNextBit = false;
  13277. }
  13278. }
  13279. function readCodingpasses() {
  13280. if (readBits(1) === 0) {
  13281. return 1;
  13282. }
  13283. if (readBits(1) === 0) {
  13284. return 2;
  13285. }
  13286. var value = readBits(2);
  13287. if (value < 3) {
  13288. return value + 3;
  13289. }
  13290. value = readBits(5);
  13291. if (value < 31) {
  13292. return value + 6;
  13293. }
  13294. value = readBits(7);
  13295. return value + 37;
  13296. }
  13297. var tileIndex = context.currentTile.index;
  13298. var tile = context.tiles[tileIndex];
  13299. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13300. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13301. var packetsIterator = tile.packetsIterator;
  13302. while (position < dataLength) {
  13303. alignToByte();
  13304. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13305. // Skip also marker segment length and packet sequence ID
  13306. skipBytes(4);
  13307. }
  13308. var packet = packetsIterator.nextPacket();
  13309. if (!readBits(1)) {
  13310. continue;
  13311. }
  13312. var layerNumber = packet.layerNumber;
  13313. var queue = [], codeblock;
  13314. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13315. codeblock = packet.codeblocks[i];
  13316. var precinct = codeblock.precinct;
  13317. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13318. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13319. var codeblockIncluded = false;
  13320. var firstTimeInclusion = false;
  13321. var valueReady;
  13322. if (codeblock['included'] !== undefined) {
  13323. codeblockIncluded = !!readBits(1);
  13324. } else {
  13325. // reading inclusion tree
  13326. precinct = codeblock.precinct;
  13327. var inclusionTree, zeroBitPlanesTree;
  13328. if (precinct['inclusionTree'] !== undefined) {
  13329. inclusionTree = precinct.inclusionTree;
  13330. } else {
  13331. // building inclusion and zero bit-planes trees
  13332. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13333. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13334. inclusionTree = new InclusionTree(width, height, layerNumber);
  13335. zeroBitPlanesTree = new TagTree(width, height);
  13336. precinct.inclusionTree = inclusionTree;
  13337. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13338. }
  13339. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13340. while (true) {
  13341. if (readBits(1)) {
  13342. valueReady = !inclusionTree.nextLevel();
  13343. if (valueReady) {
  13344. codeblock.included = true;
  13345. codeblockIncluded = firstTimeInclusion = true;
  13346. break;
  13347. }
  13348. } else {
  13349. inclusionTree.incrementValue(layerNumber);
  13350. break;
  13351. }
  13352. }
  13353. }
  13354. }
  13355. if (!codeblockIncluded) {
  13356. continue;
  13357. }
  13358. if (firstTimeInclusion) {
  13359. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13360. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13361. while (true) {
  13362. if (readBits(1)) {
  13363. valueReady = !zeroBitPlanesTree.nextLevel();
  13364. if (valueReady) {
  13365. break;
  13366. }
  13367. } else {
  13368. zeroBitPlanesTree.incrementValue();
  13369. }
  13370. }
  13371. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13372. }
  13373. var codingpasses = readCodingpasses();
  13374. while (readBits(1)) {
  13375. codeblock.Lblock++;
  13376. }
  13377. var codingpassesLog2 = log2(codingpasses);
  13378. // rounding down log2
  13379. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13380. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13381. var codedDataLength = readBits(bits);
  13382. queue.push({
  13383. codeblock: codeblock,
  13384. codingpasses: codingpasses,
  13385. dataLength: codedDataLength
  13386. });
  13387. }
  13388. alignToByte();
  13389. if (ephMarkerUsed) {
  13390. skipMarkerIfEqual(0x92);
  13391. }
  13392. while (queue.length > 0) {
  13393. var packetItem = queue.shift();
  13394. codeblock = packetItem.codeblock;
  13395. if (codeblock['data'] === undefined) {
  13396. codeblock.data = [];
  13397. }
  13398. codeblock.data.push({
  13399. data: data,
  13400. start: offset + position,
  13401. end: offset + position + packetItem.dataLength,
  13402. codingpasses: packetItem.codingpasses
  13403. });
  13404. position += packetItem.dataLength;
  13405. }
  13406. }
  13407. return position;
  13408. }
  13409. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13410. delta, mb, reversible, segmentationSymbolUsed) {
  13411. var x0 = subband.tbx0;
  13412. var y0 = subband.tby0;
  13413. var width = subband.tbx1 - subband.tbx0;
  13414. var codeblocks = subband.codeblocks;
  13415. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13416. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13417. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13418. var codeblock = codeblocks[i];
  13419. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13420. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13421. if (blockWidth === 0 || blockHeight === 0) {
  13422. continue;
  13423. }
  13424. if (codeblock['data'] === undefined) {
  13425. continue;
  13426. }
  13427. var bitModel, currentCodingpassType;
  13428. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  13429. codeblock.zeroBitPlanes, mb);
  13430. currentCodingpassType = 2; // first bit plane starts from cleanup
  13431. // collect data
  13432. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  13433. var j, jj, dataItem;
  13434. for (j = 0, jj = data.length; j < jj; j++) {
  13435. dataItem = data[j];
  13436. totalLength += dataItem.end - dataItem.start;
  13437. codingpasses += dataItem.codingpasses;
  13438. }
  13439. var encodedData = new Uint8Array(totalLength);
  13440. var position = 0;
  13441. for (j = 0, jj = data.length; j < jj; j++) {
  13442. dataItem = data[j];
  13443. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  13444. encodedData.set(chunk, position);
  13445. position += chunk.length;
  13446. }
  13447. // decoding the item
  13448. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  13449. bitModel.setDecoder(decoder);
  13450. for (j = 0; j < codingpasses; j++) {
  13451. switch (currentCodingpassType) {
  13452. case 0:
  13453. bitModel.runSignificancePropogationPass();
  13454. break;
  13455. case 1:
  13456. bitModel.runMagnitudeRefinementPass();
  13457. break;
  13458. case 2:
  13459. bitModel.runCleanupPass();
  13460. if (segmentationSymbolUsed) {
  13461. bitModel.checkSegmentationSymbol();
  13462. }
  13463. break;
  13464. }
  13465. currentCodingpassType = (currentCodingpassType + 1) % 3;
  13466. }
  13467. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  13468. var sign = bitModel.coefficentsSign;
  13469. var magnitude = bitModel.coefficentsMagnitude;
  13470. var bitsDecoded = bitModel.bitsDecoded;
  13471. var magnitudeCorrection = reversible ? 0 : 0.5;
  13472. var k, n, nb;
  13473. position = 0;
  13474. // Do the interleaving of Section F.3.3 here, so we do not need
  13475. // to copy later. LL level is not interleaved, just copied.
  13476. var interleave = (subband.type !== 'LL');
  13477. for (j = 0; j < blockHeight; j++) {
  13478. var row = (offset / width) | 0; // row in the non-interleaved subband
  13479. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  13480. for (k = 0; k < blockWidth; k++) {
  13481. n = magnitude[position];
  13482. if (n !== 0) {
  13483. n = (n + magnitudeCorrection) * delta;
  13484. if (sign[position] !== 0) {
  13485. n = -n;
  13486. }
  13487. nb = bitsDecoded[position];
  13488. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  13489. if (reversible && (nb >= mb)) {
  13490. coefficients[pos] = n;
  13491. } else {
  13492. coefficients[pos] = n * (1 << (mb - nb));
  13493. }
  13494. }
  13495. offset++;
  13496. position++;
  13497. }
  13498. offset += width - blockWidth;
  13499. }
  13500. }
  13501. }
  13502. function transformTile(context, tile, c) {
  13503. var component = tile.components[c];
  13504. var codingStyleParameters = component.codingStyleParameters;
  13505. var quantizationParameters = component.quantizationParameters;
  13506. var decompositionLevelsCount =
  13507. codingStyleParameters.decompositionLevelsCount;
  13508. var spqcds = quantizationParameters.SPqcds;
  13509. var scalarExpounded = quantizationParameters.scalarExpounded;
  13510. var guardBits = quantizationParameters.guardBits;
  13511. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  13512. var precision = context.components[c].precision;
  13513. var reversible = codingStyleParameters.reversibleTransformation;
  13514. var transform = (reversible ? new ReversibleTransform() :
  13515. new IrreversibleTransform());
  13516. var subbandCoefficients = [];
  13517. var b = 0;
  13518. for (var i = 0; i <= decompositionLevelsCount; i++) {
  13519. var resolution = component.resolutions[i];
  13520. var width = resolution.trx1 - resolution.trx0;
  13521. var height = resolution.try1 - resolution.try0;
  13522. // Allocate space for the whole sublevel.
  13523. var coefficients = new Float32Array(width * height);
  13524. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  13525. var mu, epsilon;
  13526. if (!scalarExpounded) {
  13527. // formula E-5
  13528. mu = spqcds[0].mu;
  13529. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  13530. } else {
  13531. mu = spqcds[b].mu;
  13532. epsilon = spqcds[b].epsilon;
  13533. b++;
  13534. }
  13535. var subband = resolution.subbands[j];
  13536. var gainLog2 = SubbandsGainLog2[subband.type];
  13537. // calulate quantization coefficient (Section E.1.1.1)
  13538. var delta = (reversible ? 1 :
  13539. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  13540. var mb = (guardBits + epsilon - 1);
  13541. // In the first resolution level, copyCoefficients will fill the
  13542. // whole array with coefficients. In the succeding passes,
  13543. // copyCoefficients will consecutively fill in the values that belong
  13544. // to the interleaved positions of the HL, LH, and HH coefficients.
  13545. // The LL coefficients will then be interleaved in Transform.iterate().
  13546. copyCoefficients(coefficients, width, height, subband, delta, mb,
  13547. reversible, segmentationSymbolUsed);
  13548. }
  13549. subbandCoefficients.push({
  13550. width: width,
  13551. height: height,
  13552. items: coefficients
  13553. });
  13554. }
  13555. var result = transform.calculate(subbandCoefficients,
  13556. component.tcx0, component.tcy0);
  13557. return {
  13558. left: component.tcx0,
  13559. top: component.tcy0,
  13560. width: result.width,
  13561. height: result.height,
  13562. items: result.items
  13563. };
  13564. }
  13565. function transformComponents(context) {
  13566. var siz = context.SIZ;
  13567. var components = context.components;
  13568. var componentsCount = siz.Csiz;
  13569. var resultImages = [];
  13570. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  13571. var tile = context.tiles[i];
  13572. var transformedTiles = [];
  13573. var c;
  13574. for (c = 0; c < componentsCount; c++) {
  13575. transformedTiles[c] = transformTile(context, tile, c);
  13576. }
  13577. var tile0 = transformedTiles[0];
  13578. var out = new Uint8Array(tile0.items.length * componentsCount);
  13579. var result = {
  13580. left: tile0.left,
  13581. top: tile0.top,
  13582. width: tile0.width,
  13583. height: tile0.height,
  13584. items: out
  13585. };
  13586. // Section G.2.2 Inverse multi component transform
  13587. var shift, offset, max, min, maxK;
  13588. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  13589. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  13590. var fourComponents = componentsCount === 4;
  13591. var y0items = transformedTiles[0].items;
  13592. var y1items = transformedTiles[1].items;
  13593. var y2items = transformedTiles[2].items;
  13594. var y3items = fourComponents ? transformedTiles[3].items : null;
  13595. // HACK: The multiple component transform formulas below assume that
  13596. // all components have the same precision. With this in mind, we
  13597. // compute shift and offset only once.
  13598. shift = components[0].precision - 8;
  13599. offset = (128 << shift) + 0.5;
  13600. max = 255 * (1 << shift);
  13601. maxK = max * 0.5;
  13602. min = -maxK;
  13603. var component0 = tile.components[0];
  13604. var alpha01 = componentsCount - 3;
  13605. jj = y0items.length;
  13606. if (!component0.codingStyleParameters.reversibleTransformation) {
  13607. // inverse irreversible multiple component transform
  13608. for (j = 0; j < jj; j++, pos += alpha01) {
  13609. y0 = y0items[j] + offset;
  13610. y1 = y1items[j];
  13611. y2 = y2items[j];
  13612. r = y0 + 1.402 * y2;
  13613. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  13614. b = y0 + 1.772 * y1;
  13615. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13616. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13617. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13618. }
  13619. } else {
  13620. // inverse reversible multiple component transform
  13621. for (j = 0; j < jj; j++, pos += alpha01) {
  13622. y0 = y0items[j] + offset;
  13623. y1 = y1items[j];
  13624. y2 = y2items[j];
  13625. g = y0 - ((y2 + y1) >> 2);
  13626. r = g + y2;
  13627. b = g + y1;
  13628. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13629. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13630. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13631. }
  13632. }
  13633. if (fourComponents) {
  13634. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  13635. k = y3items[j];
  13636. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  13637. }
  13638. }
  13639. } else { // no multi-component transform
  13640. for (c = 0; c < componentsCount; c++) {
  13641. var items = transformedTiles[c].items;
  13642. shift = components[c].precision - 8;
  13643. offset = (128 << shift) + 0.5;
  13644. max = (127.5 * (1 << shift));
  13645. min = -max;
  13646. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  13647. val = items[j];
  13648. out[pos] = val <= min ? 0 :
  13649. val >= max ? 255 : (val + offset) >> shift;
  13650. pos += componentsCount;
  13651. }
  13652. }
  13653. }
  13654. resultImages.push(result);
  13655. }
  13656. return resultImages;
  13657. }
  13658. function initializeTile(context, tileIndex) {
  13659. var siz = context.SIZ;
  13660. var componentsCount = siz.Csiz;
  13661. var tile = context.tiles[tileIndex];
  13662. for (var c = 0; c < componentsCount; c++) {
  13663. var component = tile.components[c];
  13664. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13665. context.currentTile.QCC[c] : context.currentTile.QCD);
  13666. component.quantizationParameters = qcdOrQcc;
  13667. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13668. context.currentTile.COC[c] : context.currentTile.COD);
  13669. component.codingStyleParameters = codOrCoc;
  13670. }
  13671. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13672. }
  13673. // Section B.10.2 Tag trees
  13674. var TagTree = (function TagTreeClosure() {
  13675. function TagTree(width, height) {
  13676. var levelsLength = log2(Math.max(width, height)) + 1;
  13677. this.levels = [];
  13678. for (var i = 0; i < levelsLength; i++) {
  13679. var level = {
  13680. width: width,
  13681. height: height,
  13682. items: []
  13683. };
  13684. this.levels.push(level);
  13685. width = Math.ceil(width / 2);
  13686. height = Math.ceil(height / 2);
  13687. }
  13688. }
  13689. TagTree.prototype = {
  13690. reset: function TagTree_reset(i, j) {
  13691. var currentLevel = 0, value = 0, level;
  13692. while (currentLevel < this.levels.length) {
  13693. level = this.levels[currentLevel];
  13694. var index = i + j * level.width;
  13695. if (level.items[index] !== undefined) {
  13696. value = level.items[index];
  13697. break;
  13698. }
  13699. level.index = index;
  13700. i >>= 1;
  13701. j >>= 1;
  13702. currentLevel++;
  13703. }
  13704. currentLevel--;
  13705. level = this.levels[currentLevel];
  13706. level.items[level.index] = value;
  13707. this.currentLevel = currentLevel;
  13708. delete this.value;
  13709. },
  13710. incrementValue: function TagTree_incrementValue() {
  13711. var level = this.levels[this.currentLevel];
  13712. level.items[level.index]++;
  13713. },
  13714. nextLevel: function TagTree_nextLevel() {
  13715. var currentLevel = this.currentLevel;
  13716. var level = this.levels[currentLevel];
  13717. var value = level.items[level.index];
  13718. currentLevel--;
  13719. if (currentLevel < 0) {
  13720. this.value = value;
  13721. return false;
  13722. }
  13723. this.currentLevel = currentLevel;
  13724. level = this.levels[currentLevel];
  13725. level.items[level.index] = value;
  13726. return true;
  13727. }
  13728. };
  13729. return TagTree;
  13730. })();
  13731. var InclusionTree = (function InclusionTreeClosure() {
  13732. function InclusionTree(width, height, defaultValue) {
  13733. var levelsLength = log2(Math.max(width, height)) + 1;
  13734. this.levels = [];
  13735. for (var i = 0; i < levelsLength; i++) {
  13736. var items = new Uint8Array(width * height);
  13737. for (var j = 0, jj = items.length; j < jj; j++) {
  13738. items[j] = defaultValue;
  13739. }
  13740. var level = {
  13741. width: width,
  13742. height: height,
  13743. items: items
  13744. };
  13745. this.levels.push(level);
  13746. width = Math.ceil(width / 2);
  13747. height = Math.ceil(height / 2);
  13748. }
  13749. }
  13750. InclusionTree.prototype = {
  13751. reset: function InclusionTree_reset(i, j, stopValue) {
  13752. var currentLevel = 0;
  13753. while (currentLevel < this.levels.length) {
  13754. var level = this.levels[currentLevel];
  13755. var index = i + j * level.width;
  13756. level.index = index;
  13757. var value = level.items[index];
  13758. if (value === 0xFF) {
  13759. break;
  13760. }
  13761. if (value > stopValue) {
  13762. this.currentLevel = currentLevel;
  13763. // already know about this one, propagating the value to top levels
  13764. this.propagateValues();
  13765. return false;
  13766. }
  13767. i >>= 1;
  13768. j >>= 1;
  13769. currentLevel++;
  13770. }
  13771. this.currentLevel = currentLevel - 1;
  13772. return true;
  13773. },
  13774. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13775. var level = this.levels[this.currentLevel];
  13776. level.items[level.index] = stopValue + 1;
  13777. this.propagateValues();
  13778. },
  13779. propagateValues: function InclusionTree_propagateValues() {
  13780. var levelIndex = this.currentLevel;
  13781. var level = this.levels[levelIndex];
  13782. var currentValue = level.items[level.index];
  13783. while (--levelIndex >= 0) {
  13784. level = this.levels[levelIndex];
  13785. level.items[level.index] = currentValue;
  13786. }
  13787. },
  13788. nextLevel: function InclusionTree_nextLevel() {
  13789. var currentLevel = this.currentLevel;
  13790. var level = this.levels[currentLevel];
  13791. var value = level.items[level.index];
  13792. level.items[level.index] = 0xFF;
  13793. currentLevel--;
  13794. if (currentLevel < 0) {
  13795. return false;
  13796. }
  13797. this.currentLevel = currentLevel;
  13798. level = this.levels[currentLevel];
  13799. level.items[level.index] = value;
  13800. return true;
  13801. }
  13802. };
  13803. return InclusionTree;
  13804. })();
  13805. // Section D. Coefficient bit modeling
  13806. var BitModel = (function BitModelClosure() {
  13807. var UNIFORM_CONTEXT = 17;
  13808. var RUNLENGTH_CONTEXT = 18;
  13809. // Table D-1
  13810. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13811. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13812. var LLAndLHContextsLabel = new Uint8Array([
  13813. 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,
  13814. 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,
  13815. 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
  13816. ]);
  13817. var HLContextLabel = new Uint8Array([
  13818. 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,
  13819. 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,
  13820. 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
  13821. ]);
  13822. var HHContextLabel = new Uint8Array([
  13823. 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,
  13824. 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,
  13825. 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
  13826. ]);
  13827. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13828. this.width = width;
  13829. this.height = height;
  13830. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13831. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13832. var coefficientCount = width * height;
  13833. // coefficients outside the encoding region treated as insignificant
  13834. // add border state cells for significanceState
  13835. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13836. this.coefficentsSign = new Uint8Array(coefficientCount);
  13837. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13838. mb > 6 ? new Uint16Array(coefficientCount) :
  13839. new Uint8Array(coefficientCount);
  13840. this.processingFlags = new Uint8Array(coefficientCount);
  13841. var bitsDecoded = new Uint8Array(coefficientCount);
  13842. if (zeroBitPlanes !== 0) {
  13843. for (var i = 0; i < coefficientCount; i++) {
  13844. bitsDecoded[i] = zeroBitPlanes;
  13845. }
  13846. }
  13847. this.bitsDecoded = bitsDecoded;
  13848. this.reset();
  13849. }
  13850. BitModel.prototype = {
  13851. setDecoder: function BitModel_setDecoder(decoder) {
  13852. this.decoder = decoder;
  13853. },
  13854. reset: function BitModel_reset() {
  13855. // We have 17 contexts that are accessed via context labels,
  13856. // plus the uniform and runlength context.
  13857. this.contexts = new Int8Array(19);
  13858. // Contexts are packed into 1 byte:
  13859. // highest 7 bits carry the index, lowest bit carries mps
  13860. this.contexts[0] = (4 << 1) | 0;
  13861. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13862. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13863. },
  13864. setNeighborsSignificance:
  13865. function BitModel_setNeighborsSignificance(row, column, index) {
  13866. var neighborsSignificance = this.neighborsSignificance;
  13867. var width = this.width, height = this.height;
  13868. var left = (column > 0);
  13869. var right = (column + 1 < width);
  13870. var i;
  13871. if (row > 0) {
  13872. i = index - width;
  13873. if (left) {
  13874. neighborsSignificance[i - 1] += 0x10;
  13875. }
  13876. if (right) {
  13877. neighborsSignificance[i + 1] += 0x10;
  13878. }
  13879. neighborsSignificance[i] += 0x04;
  13880. }
  13881. if (row + 1 < height) {
  13882. i = index + width;
  13883. if (left) {
  13884. neighborsSignificance[i - 1] += 0x10;
  13885. }
  13886. if (right) {
  13887. neighborsSignificance[i + 1] += 0x10;
  13888. }
  13889. neighborsSignificance[i] += 0x04;
  13890. }
  13891. if (left) {
  13892. neighborsSignificance[index - 1] += 0x01;
  13893. }
  13894. if (right) {
  13895. neighborsSignificance[index + 1] += 0x01;
  13896. }
  13897. neighborsSignificance[index] |= 0x80;
  13898. },
  13899. runSignificancePropogationPass:
  13900. function BitModel_runSignificancePropogationPass() {
  13901. var decoder = this.decoder;
  13902. var width = this.width, height = this.height;
  13903. var coefficentsMagnitude = this.coefficentsMagnitude;
  13904. var coefficentsSign = this.coefficentsSign;
  13905. var neighborsSignificance = this.neighborsSignificance;
  13906. var processingFlags = this.processingFlags;
  13907. var contexts = this.contexts;
  13908. var labels = this.contextLabelTable;
  13909. var bitsDecoded = this.bitsDecoded;
  13910. var processedInverseMask = ~1;
  13911. var processedMask = 1;
  13912. var firstMagnitudeBitMask = 2;
  13913. for (var i0 = 0; i0 < height; i0 += 4) {
  13914. for (var j = 0; j < width; j++) {
  13915. var index = i0 * width + j;
  13916. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13917. var i = i0 + i1;
  13918. if (i >= height) {
  13919. break;
  13920. }
  13921. // clear processed flag first
  13922. processingFlags[index] &= processedInverseMask;
  13923. if (coefficentsMagnitude[index] ||
  13924. !neighborsSignificance[index]) {
  13925. continue;
  13926. }
  13927. var contextLabel = labels[neighborsSignificance[index]];
  13928. var decision = decoder.readBit(contexts, contextLabel);
  13929. if (decision) {
  13930. var sign = this.decodeSignBit(i, j, index);
  13931. coefficentsSign[index] = sign;
  13932. coefficentsMagnitude[index] = 1;
  13933. this.setNeighborsSignificance(i, j, index);
  13934. processingFlags[index] |= firstMagnitudeBitMask;
  13935. }
  13936. bitsDecoded[index]++;
  13937. processingFlags[index] |= processedMask;
  13938. }
  13939. }
  13940. }
  13941. },
  13942. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13943. var width = this.width, height = this.height;
  13944. var coefficentsMagnitude = this.coefficentsMagnitude;
  13945. var coefficentsSign = this.coefficentsSign;
  13946. var contribution, sign0, sign1, significance1;
  13947. var contextLabel, decoded;
  13948. // calculate horizontal contribution
  13949. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13950. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13951. sign1 = coefficentsSign[index + 1];
  13952. if (significance1) {
  13953. sign0 = coefficentsSign[index - 1];
  13954. contribution = 1 - sign1 - sign0;
  13955. } else {
  13956. contribution = 1 - sign1 - sign1;
  13957. }
  13958. } else if (significance1) {
  13959. sign0 = coefficentsSign[index - 1];
  13960. contribution = 1 - sign0 - sign0;
  13961. } else {
  13962. contribution = 0;
  13963. }
  13964. var horizontalContribution = 3 * contribution;
  13965. // calculate vertical contribution and combine with the horizontal
  13966. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13967. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13968. sign1 = coefficentsSign[index + width];
  13969. if (significance1) {
  13970. sign0 = coefficentsSign[index - width];
  13971. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13972. } else {
  13973. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13974. }
  13975. } else if (significance1) {
  13976. sign0 = coefficentsSign[index - width];
  13977. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13978. } else {
  13979. contribution = horizontalContribution;
  13980. }
  13981. if (contribution >= 0) {
  13982. contextLabel = 9 + contribution;
  13983. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13984. } else {
  13985. contextLabel = 9 - contribution;
  13986. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13987. }
  13988. return decoded;
  13989. },
  13990. runMagnitudeRefinementPass:
  13991. function BitModel_runMagnitudeRefinementPass() {
  13992. var decoder = this.decoder;
  13993. var width = this.width, height = this.height;
  13994. var coefficentsMagnitude = this.coefficentsMagnitude;
  13995. var neighborsSignificance = this.neighborsSignificance;
  13996. var contexts = this.contexts;
  13997. var bitsDecoded = this.bitsDecoded;
  13998. var processingFlags = this.processingFlags;
  13999. var processedMask = 1;
  14000. var firstMagnitudeBitMask = 2;
  14001. var length = width * height;
  14002. var width4 = width * 4;
  14003. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  14004. indexNext = Math.min(length, index0 + width4);
  14005. for (var j = 0; j < width; j++) {
  14006. for (var index = index0 + j; index < indexNext; index += width) {
  14007. // significant but not those that have just become
  14008. if (!coefficentsMagnitude[index] ||
  14009. (processingFlags[index] & processedMask) !== 0) {
  14010. continue;
  14011. }
  14012. var contextLabel = 16;
  14013. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  14014. processingFlags[index] ^= firstMagnitudeBitMask;
  14015. // first refinement
  14016. var significance = neighborsSignificance[index] & 127;
  14017. contextLabel = significance === 0 ? 15 : 14;
  14018. }
  14019. var bit = decoder.readBit(contexts, contextLabel);
  14020. coefficentsMagnitude[index] =
  14021. (coefficentsMagnitude[index] << 1) | bit;
  14022. bitsDecoded[index]++;
  14023. processingFlags[index] |= processedMask;
  14024. }
  14025. }
  14026. }
  14027. },
  14028. runCleanupPass: function BitModel_runCleanupPass() {
  14029. var decoder = this.decoder;
  14030. var width = this.width, height = this.height;
  14031. var neighborsSignificance = this.neighborsSignificance;
  14032. var coefficentsMagnitude = this.coefficentsMagnitude;
  14033. var coefficentsSign = this.coefficentsSign;
  14034. var contexts = this.contexts;
  14035. var labels = this.contextLabelTable;
  14036. var bitsDecoded = this.bitsDecoded;
  14037. var processingFlags = this.processingFlags;
  14038. var processedMask = 1;
  14039. var firstMagnitudeBitMask = 2;
  14040. var oneRowDown = width;
  14041. var twoRowsDown = width * 2;
  14042. var threeRowsDown = width * 3;
  14043. var iNext;
  14044. for (var i0 = 0; i0 < height; i0 = iNext) {
  14045. iNext = Math.min(i0 + 4, height);
  14046. var indexBase = i0 * width;
  14047. var checkAllEmpty = i0 + 3 < height;
  14048. for (var j = 0; j < width; j++) {
  14049. var index0 = indexBase + j;
  14050. // using the property: labels[neighborsSignificance[index]] === 0
  14051. // when neighborsSignificance[index] === 0
  14052. var allEmpty = (checkAllEmpty &&
  14053. processingFlags[index0] === 0 &&
  14054. processingFlags[index0 + oneRowDown] === 0 &&
  14055. processingFlags[index0 + twoRowsDown] === 0 &&
  14056. processingFlags[index0 + threeRowsDown] === 0 &&
  14057. neighborsSignificance[index0] === 0 &&
  14058. neighborsSignificance[index0 + oneRowDown] === 0 &&
  14059. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14060. neighborsSignificance[index0 + threeRowsDown] === 0);
  14061. var i1 = 0, index = index0;
  14062. var i = i0, sign;
  14063. if (allEmpty) {
  14064. var hasSignificantCoefficent =
  14065. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14066. if (!hasSignificantCoefficent) {
  14067. bitsDecoded[index0]++;
  14068. bitsDecoded[index0 + oneRowDown]++;
  14069. bitsDecoded[index0 + twoRowsDown]++;
  14070. bitsDecoded[index0 + threeRowsDown]++;
  14071. continue; // next column
  14072. }
  14073. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14074. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14075. if (i1 !== 0) {
  14076. i = i0 + i1;
  14077. index += i1 * width;
  14078. }
  14079. sign = this.decodeSignBit(i, j, index);
  14080. coefficentsSign[index] = sign;
  14081. coefficentsMagnitude[index] = 1;
  14082. this.setNeighborsSignificance(i, j, index);
  14083. processingFlags[index] |= firstMagnitudeBitMask;
  14084. index = index0;
  14085. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14086. bitsDecoded[index]++;
  14087. }
  14088. i1++;
  14089. }
  14090. for (i = i0 + i1; i < iNext; i++, index += width) {
  14091. if (coefficentsMagnitude[index] ||
  14092. (processingFlags[index] & processedMask) !== 0) {
  14093. continue;
  14094. }
  14095. var contextLabel = labels[neighborsSignificance[index]];
  14096. var decision = decoder.readBit(contexts, contextLabel);
  14097. if (decision === 1) {
  14098. sign = this.decodeSignBit(i, j, index);
  14099. coefficentsSign[index] = sign;
  14100. coefficentsMagnitude[index] = 1;
  14101. this.setNeighborsSignificance(i, j, index);
  14102. processingFlags[index] |= firstMagnitudeBitMask;
  14103. }
  14104. bitsDecoded[index]++;
  14105. }
  14106. }
  14107. }
  14108. },
  14109. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14110. var decoder = this.decoder;
  14111. var contexts = this.contexts;
  14112. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14113. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14114. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14115. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14116. if (symbol !== 0xA) {
  14117. throw new Error('JPX Error: Invalid segmentation symbol');
  14118. }
  14119. }
  14120. };
  14121. return BitModel;
  14122. })();
  14123. // Section F, Discrete wavelet transformation
  14124. var Transform = (function TransformClosure() {
  14125. function Transform() {}
  14126. Transform.prototype.calculate =
  14127. function transformCalculate(subbands, u0, v0) {
  14128. var ll = subbands[0];
  14129. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14130. ll = this.iterate(ll, subbands[i], u0, v0);
  14131. }
  14132. return ll;
  14133. };
  14134. Transform.prototype.extend = function extend(buffer, offset, size) {
  14135. // Section F.3.7 extending... using max extension of 4
  14136. var i1 = offset - 1, j1 = offset + 1;
  14137. var i2 = offset + size - 2, j2 = offset + size;
  14138. buffer[i1--] = buffer[j1++];
  14139. buffer[j2++] = buffer[i2--];
  14140. buffer[i1--] = buffer[j1++];
  14141. buffer[j2++] = buffer[i2--];
  14142. buffer[i1--] = buffer[j1++];
  14143. buffer[j2++] = buffer[i2--];
  14144. buffer[i1] = buffer[j1];
  14145. buffer[j2] = buffer[i2];
  14146. };
  14147. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14148. u0, v0) {
  14149. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14150. var width = hl_lh_hh.width;
  14151. var height = hl_lh_hh.height;
  14152. var items = hl_lh_hh.items;
  14153. var i, j, k, l, u, v;
  14154. // Interleave LL according to Section F.3.3
  14155. for (k = 0, i = 0; i < llHeight; i++) {
  14156. l = i * 2 * width;
  14157. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14158. items[l] = llItems[k];
  14159. }
  14160. }
  14161. // The LL band is not needed anymore.
  14162. llItems = ll.items = null;
  14163. var bufferPadding = 4;
  14164. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14165. // Section F.3.4 HOR_SR
  14166. if (width === 1) {
  14167. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14168. if ((u0 & 1) !== 0) {
  14169. for (v = 0, k = 0; v < height; v++, k += width) {
  14170. items[k] *= 0.5;
  14171. }
  14172. }
  14173. } else {
  14174. for (v = 0, k = 0; v < height; v++, k += width) {
  14175. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14176. this.extend(rowBuffer, bufferPadding, width);
  14177. this.filter(rowBuffer, bufferPadding, width);
  14178. items.set(
  14179. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14180. k);
  14181. }
  14182. }
  14183. // Accesses to the items array can take long, because it may not fit into
  14184. // CPU cache and has to be fetched from main memory. Since subsequent
  14185. // accesses to the items array are not local when reading columns, we
  14186. // have a cache miss every time. To reduce cache misses, get up to
  14187. // 'numBuffers' items at a time and store them into the individual
  14188. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14189. var numBuffers = 16;
  14190. var colBuffers = [];
  14191. for (i = 0; i < numBuffers; i++) {
  14192. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14193. }
  14194. var b, currentBuffer = 0;
  14195. ll = bufferPadding + height;
  14196. // Section F.3.5 VER_SR
  14197. if (height === 1) {
  14198. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14199. if ((v0 & 1) !== 0) {
  14200. for (u = 0; u < width; u++) {
  14201. items[u] *= 0.5;
  14202. }
  14203. }
  14204. } else {
  14205. for (u = 0; u < width; u++) {
  14206. // if we ran out of buffers, copy several image columns at once
  14207. if (currentBuffer === 0) {
  14208. numBuffers = Math.min(width - u, numBuffers);
  14209. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14210. for (b = 0; b < numBuffers; b++) {
  14211. colBuffers[b][l] = items[k + b];
  14212. }
  14213. }
  14214. currentBuffer = numBuffers;
  14215. }
  14216. currentBuffer--;
  14217. var buffer = colBuffers[currentBuffer];
  14218. this.extend(buffer, bufferPadding, height);
  14219. this.filter(buffer, bufferPadding, height);
  14220. // If this is last buffer in this group of buffers, flush all buffers.
  14221. if (currentBuffer === 0) {
  14222. k = u - numBuffers + 1;
  14223. for (l = bufferPadding; l < ll; k += width, l++) {
  14224. for (b = 0; b < numBuffers; b++) {
  14225. items[k + b] = colBuffers[b][l];
  14226. }
  14227. }
  14228. }
  14229. }
  14230. }
  14231. return {
  14232. width: width,
  14233. height: height,
  14234. items: items
  14235. };
  14236. };
  14237. return Transform;
  14238. })();
  14239. // Section 3.8.2 Irreversible 9-7 filter
  14240. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14241. function IrreversibleTransform() {
  14242. Transform.call(this);
  14243. }
  14244. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14245. IrreversibleTransform.prototype.filter =
  14246. function irreversibleTransformFilter(x, offset, length) {
  14247. var len = length >> 1;
  14248. offset = offset | 0;
  14249. var j, n, current, next;
  14250. var alpha = -1.586134342059924;
  14251. var beta = -0.052980118572961;
  14252. var gamma = 0.882911075530934;
  14253. var delta = 0.443506852043971;
  14254. var K = 1.230174104914001;
  14255. var K_ = 1 / K;
  14256. // step 1 is combined with step 3
  14257. // step 2
  14258. j = offset - 3;
  14259. for (n = len + 4; n--; j += 2) {
  14260. x[j] *= K_;
  14261. }
  14262. // step 1 & 3
  14263. j = offset - 2;
  14264. current = delta * x[j -1];
  14265. for (n = len + 3; n--; j += 2) {
  14266. next = delta * x[j + 1];
  14267. x[j] = K * x[j] - current - next;
  14268. if (n--) {
  14269. j += 2;
  14270. current = delta * x[j + 1];
  14271. x[j] = K * x[j] - current - next;
  14272. } else {
  14273. break;
  14274. }
  14275. }
  14276. // step 4
  14277. j = offset - 1;
  14278. current = gamma * x[j - 1];
  14279. for (n = len + 2; n--; j += 2) {
  14280. next = gamma * x[j + 1];
  14281. x[j] -= current + next;
  14282. if (n--) {
  14283. j += 2;
  14284. current = gamma * x[j + 1];
  14285. x[j] -= current + next;
  14286. } else {
  14287. break;
  14288. }
  14289. }
  14290. // step 5
  14291. j = offset;
  14292. current = beta * x[j - 1];
  14293. for (n = len + 1; n--; j += 2) {
  14294. next = beta * x[j + 1];
  14295. x[j] -= current + next;
  14296. if (n--) {
  14297. j += 2;
  14298. current = beta * x[j + 1];
  14299. x[j] -= current + next;
  14300. } else {
  14301. break;
  14302. }
  14303. }
  14304. // step 6
  14305. if (len !== 0) {
  14306. j = offset + 1;
  14307. current = alpha * x[j - 1];
  14308. for (n = len; n--; j += 2) {
  14309. next = alpha * x[j + 1];
  14310. x[j] -= current + next;
  14311. if (n--) {
  14312. j += 2;
  14313. current = alpha * x[j + 1];
  14314. x[j] -= current + next;
  14315. } else {
  14316. break;
  14317. }
  14318. }
  14319. }
  14320. };
  14321. return IrreversibleTransform;
  14322. })();
  14323. // Section 3.8.1 Reversible 5-3 filter
  14324. var ReversibleTransform = (function ReversibleTransformClosure() {
  14325. function ReversibleTransform() {
  14326. Transform.call(this);
  14327. }
  14328. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14329. ReversibleTransform.prototype.filter =
  14330. function reversibleTransformFilter(x, offset, length) {
  14331. var len = length >> 1;
  14332. offset = offset | 0;
  14333. var j, n;
  14334. for (j = offset, n = len + 1; n--; j += 2) {
  14335. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14336. }
  14337. for (j = offset + 1, n = len; n--; j += 2) {
  14338. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14339. }
  14340. };
  14341. return ReversibleTransform;
  14342. })();
  14343. return JpxImage;
  14344. })();
  14345. exports.JpxImage = JpxImage;
  14346. }));
  14347. (function (root, factory) {
  14348. {
  14349. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14350. }
  14351. }(this, function (exports, sharedUtil) {
  14352. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14353. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14354. // Workaround for missing math precison in JS.
  14355. var MASK_HIGH = 0xffff0000;
  14356. var MASK_LOW = 0xffff;
  14357. function MurmurHash3_64 (seed) {
  14358. var SEED = 0xc3d2e1f0;
  14359. this.h1 = seed ? seed & 0xffffffff : SEED;
  14360. this.h2 = seed ? seed & 0xffffffff : SEED;
  14361. }
  14362. var alwaysUseUint32ArrayView = false;
  14363. // old webkits have issues with non-aligned arrays
  14364. try {
  14365. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14366. } catch (e) {
  14367. alwaysUseUint32ArrayView = true;
  14368. }
  14369. MurmurHash3_64.prototype = {
  14370. update: function MurmurHash3_64_update(input) {
  14371. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14372. var i;
  14373. if (typeof input === 'string') {
  14374. var data = new Uint8Array(input.length * 2);
  14375. var length = 0;
  14376. for (i = 0; i < input.length; i++) {
  14377. var code = input.charCodeAt(i);
  14378. if (code <= 0xff) {
  14379. data[length++] = code;
  14380. }
  14381. else {
  14382. data[length++] = code >>> 8;
  14383. data[length++] = code & 0xff;
  14384. }
  14385. }
  14386. } else if (input instanceof Uint8Array) {
  14387. data = input;
  14388. length = data.length;
  14389. } else if (typeof input === 'object' && ('length' in input)) {
  14390. // processing regular arrays as well, e.g. for IE9
  14391. data = input;
  14392. length = data.length;
  14393. useUint32ArrayView = true;
  14394. } else {
  14395. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14396. 'Input must be a string or array.');
  14397. }
  14398. var blockCounts = length >> 2;
  14399. var tailLength = length - blockCounts * 4;
  14400. // we don't care about endianness here
  14401. var dataUint32 = useUint32ArrayView ?
  14402. new Uint32ArrayView(data, blockCounts) :
  14403. new Uint32Array(data.buffer, 0, blockCounts);
  14404. var k1 = 0;
  14405. var k2 = 0;
  14406. var h1 = this.h1;
  14407. var h2 = this.h2;
  14408. var C1 = 0xcc9e2d51;
  14409. var C2 = 0x1b873593;
  14410. var C1_LOW = C1 & MASK_LOW;
  14411. var C2_LOW = C2 & MASK_LOW;
  14412. for (i = 0; i < blockCounts; i++) {
  14413. if (i & 1) {
  14414. k1 = dataUint32[i];
  14415. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14416. k1 = k1 << 15 | k1 >>> 17;
  14417. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14418. h1 ^= k1;
  14419. h1 = h1 << 13 | h1 >>> 19;
  14420. h1 = h1 * 5 + 0xe6546b64;
  14421. } else {
  14422. k2 = dataUint32[i];
  14423. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14424. k2 = k2 << 15 | k2 >>> 17;
  14425. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14426. h2 ^= k2;
  14427. h2 = h2 << 13 | h2 >>> 19;
  14428. h2 = h2 * 5 + 0xe6546b64;
  14429. }
  14430. }
  14431. k1 = 0;
  14432. switch (tailLength) {
  14433. case 3:
  14434. k1 ^= data[blockCounts * 4 + 2] << 16;
  14435. /* falls through */
  14436. case 2:
  14437. k1 ^= data[blockCounts * 4 + 1] << 8;
  14438. /* falls through */
  14439. case 1:
  14440. k1 ^= data[blockCounts * 4];
  14441. /* falls through */
  14442. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14443. k1 = k1 << 15 | k1 >>> 17;
  14444. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14445. if (blockCounts & 1) {
  14446. h1 ^= k1;
  14447. } else {
  14448. h2 ^= k1;
  14449. }
  14450. }
  14451. this.h1 = h1;
  14452. this.h2 = h2;
  14453. return this;
  14454. },
  14455. hexdigest: function MurmurHash3_64_hexdigest () {
  14456. var h1 = this.h1;
  14457. var h2 = this.h2;
  14458. h1 ^= h2 >>> 1;
  14459. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  14460. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  14461. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  14462. h1 ^= h2 >>> 1;
  14463. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  14464. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  14465. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  14466. h1 ^= h2 >>> 1;
  14467. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  14468. var hex = (arr[i] >>> 0).toString(16);
  14469. while (hex.length < 8) {
  14470. hex = '0' + hex;
  14471. }
  14472. str += hex;
  14473. }
  14474. return str;
  14475. }
  14476. };
  14477. return MurmurHash3_64;
  14478. })();
  14479. exports.MurmurHash3_64 = MurmurHash3_64;
  14480. }));
  14481. (function (root, factory) {
  14482. {
  14483. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  14484. }
  14485. }(this, function (exports, sharedUtil) {
  14486. var isArray = sharedUtil.isArray;
  14487. var Name = (function NameClosure() {
  14488. function Name(name) {
  14489. this.name = name;
  14490. }
  14491. Name.prototype = {};
  14492. var nameCache = {};
  14493. Name.get = function Name_get(name) {
  14494. var nameValue = nameCache[name];
  14495. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  14496. };
  14497. return Name;
  14498. })();
  14499. var Cmd = (function CmdClosure() {
  14500. function Cmd(cmd) {
  14501. this.cmd = cmd;
  14502. }
  14503. Cmd.prototype = {};
  14504. var cmdCache = {};
  14505. Cmd.get = function Cmd_get(cmd) {
  14506. var cmdValue = cmdCache[cmd];
  14507. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  14508. };
  14509. return Cmd;
  14510. })();
  14511. var Dict = (function DictClosure() {
  14512. var nonSerializable = function nonSerializableClosure() {
  14513. return nonSerializable; // creating closure on some variable
  14514. };
  14515. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  14516. 'Background': true,
  14517. 'ExtGState': true,
  14518. 'Halftone': true,
  14519. 'Layout': true,
  14520. 'Mask': true,
  14521. 'Pagination': true,
  14522. 'Printing': true
  14523. };
  14524. function isRecursionAllowedFor(dict) {
  14525. if (!isName(dict.Type)) {
  14526. return true;
  14527. }
  14528. var dictType = dict.Type.name;
  14529. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  14530. }
  14531. // xref is optional
  14532. function Dict(xref) {
  14533. // Map should only be used internally, use functions below to access.
  14534. this.map = Object.create(null);
  14535. this.xref = xref;
  14536. this.objId = null;
  14537. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  14538. }
  14539. Dict.prototype = {
  14540. assignXref: function Dict_assignXref(newXref) {
  14541. this.xref = newXref;
  14542. },
  14543. // automatically dereferences Ref objects
  14544. get: function Dict_get(key1, key2, key3) {
  14545. var value;
  14546. var xref = this.xref;
  14547. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14548. typeof key2 === 'undefined') {
  14549. return xref ? xref.fetchIfRef(value) : value;
  14550. }
  14551. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14552. typeof key3 === 'undefined') {
  14553. return xref ? xref.fetchIfRef(value) : value;
  14554. }
  14555. value = this.map[key3] || null;
  14556. return xref ? xref.fetchIfRef(value) : value;
  14557. },
  14558. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  14559. getAsync: function Dict_getAsync(key1, key2, key3) {
  14560. var value;
  14561. var xref = this.xref;
  14562. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14563. typeof key2 === 'undefined') {
  14564. if (xref) {
  14565. return xref.fetchIfRefAsync(value);
  14566. }
  14567. return Promise.resolve(value);
  14568. }
  14569. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14570. typeof key3 === 'undefined') {
  14571. if (xref) {
  14572. return xref.fetchIfRefAsync(value);
  14573. }
  14574. return Promise.resolve(value);
  14575. }
  14576. value = this.map[key3] || null;
  14577. if (xref) {
  14578. return xref.fetchIfRefAsync(value);
  14579. }
  14580. return Promise.resolve(value);
  14581. },
  14582. // Same as get(), but dereferences all elements if the result is an Array.
  14583. getArray: function Dict_getArray(key1, key2, key3) {
  14584. var value = this.get(key1, key2, key3);
  14585. var xref = this.xref;
  14586. if (!isArray(value) || !xref) {
  14587. return value;
  14588. }
  14589. value = value.slice(); // Ensure that we don't modify the Dict data.
  14590. for (var i = 0, ii = value.length; i < ii; i++) {
  14591. if (!isRef(value[i])) {
  14592. continue;
  14593. }
  14594. value[i] = xref.fetch(value[i]);
  14595. }
  14596. return value;
  14597. },
  14598. // no dereferencing
  14599. getRaw: function Dict_getRaw(key) {
  14600. return this.map[key];
  14601. },
  14602. // creates new map and dereferences all Refs
  14603. getAll: function Dict_getAll() {
  14604. var all = Object.create(null);
  14605. var queue = null;
  14606. var key, obj;
  14607. for (key in this.map) {
  14608. obj = this.get(key);
  14609. if (obj instanceof Dict) {
  14610. if (isRecursionAllowedFor(obj)) {
  14611. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  14612. } else {
  14613. all[key] = this.getRaw(key);
  14614. }
  14615. } else {
  14616. all[key] = obj;
  14617. }
  14618. }
  14619. if (!queue) {
  14620. return all;
  14621. }
  14622. // trying to take cyclic references into the account
  14623. var processed = Object.create(null);
  14624. while (queue.length > 0) {
  14625. var item = queue.shift();
  14626. var itemObj = item.obj;
  14627. var objId = itemObj.objId;
  14628. if (objId && objId in processed) {
  14629. item.target[item.key] = processed[objId];
  14630. continue;
  14631. }
  14632. var dereferenced = Object.create(null);
  14633. for (key in itemObj.map) {
  14634. obj = itemObj.get(key);
  14635. if (obj instanceof Dict) {
  14636. if (isRecursionAllowedFor(obj)) {
  14637. queue.push({target: dereferenced, key: key, obj: obj});
  14638. } else {
  14639. dereferenced[key] = itemObj.getRaw(key);
  14640. }
  14641. } else {
  14642. dereferenced[key] = obj;
  14643. }
  14644. }
  14645. if (objId) {
  14646. processed[objId] = dereferenced;
  14647. }
  14648. item.target[item.key] = dereferenced;
  14649. }
  14650. return all;
  14651. },
  14652. getKeys: function Dict_getKeys() {
  14653. return Object.keys(this.map);
  14654. },
  14655. set: function Dict_set(key, value) {
  14656. this.map[key] = value;
  14657. },
  14658. has: function Dict_has(key) {
  14659. return key in this.map;
  14660. },
  14661. forEach: function Dict_forEach(callback) {
  14662. for (var key in this.map) {
  14663. callback(key, this.get(key));
  14664. }
  14665. }
  14666. };
  14667. Dict.empty = new Dict(null);
  14668. Dict.merge = function Dict_merge(xref, dictArray) {
  14669. var mergedDict = new Dict(xref);
  14670. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  14671. var dict = dictArray[i];
  14672. if (!isDict(dict)) {
  14673. continue;
  14674. }
  14675. for (var keyName in dict.map) {
  14676. if (mergedDict.map[keyName]) {
  14677. continue;
  14678. }
  14679. mergedDict.map[keyName] = dict.map[keyName];
  14680. }
  14681. }
  14682. return mergedDict;
  14683. };
  14684. return Dict;
  14685. })();
  14686. var Ref = (function RefClosure() {
  14687. function Ref(num, gen) {
  14688. this.num = num;
  14689. this.gen = gen;
  14690. }
  14691. Ref.prototype = {
  14692. toString: function Ref_toString() {
  14693. // This function is hot, so we make the string as compact as possible.
  14694. // |this.gen| is almost always zero, so we treat that case specially.
  14695. var str = this.num + 'R';
  14696. if (this.gen !== 0) {
  14697. str += this.gen;
  14698. }
  14699. return str;
  14700. }
  14701. };
  14702. return Ref;
  14703. })();
  14704. // The reference is identified by number and generation.
  14705. // This structure stores only one instance of the reference.
  14706. var RefSet = (function RefSetClosure() {
  14707. function RefSet() {
  14708. this.dict = {};
  14709. }
  14710. RefSet.prototype = {
  14711. has: function RefSet_has(ref) {
  14712. return ref.toString() in this.dict;
  14713. },
  14714. put: function RefSet_put(ref) {
  14715. this.dict[ref.toString()] = true;
  14716. },
  14717. remove: function RefSet_remove(ref) {
  14718. delete this.dict[ref.toString()];
  14719. }
  14720. };
  14721. return RefSet;
  14722. })();
  14723. var RefSetCache = (function RefSetCacheClosure() {
  14724. function RefSetCache() {
  14725. this.dict = Object.create(null);
  14726. }
  14727. RefSetCache.prototype = {
  14728. get: function RefSetCache_get(ref) {
  14729. return this.dict[ref.toString()];
  14730. },
  14731. has: function RefSetCache_has(ref) {
  14732. return ref.toString() in this.dict;
  14733. },
  14734. put: function RefSetCache_put(ref, obj) {
  14735. this.dict[ref.toString()] = obj;
  14736. },
  14737. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  14738. this.dict[ref.toString()] = this.get(aliasRef);
  14739. },
  14740. forEach: function RefSetCache_forEach(fn, thisArg) {
  14741. for (var i in this.dict) {
  14742. fn.call(thisArg, this.dict[i]);
  14743. }
  14744. },
  14745. clear: function RefSetCache_clear() {
  14746. this.dict = Object.create(null);
  14747. }
  14748. };
  14749. return RefSetCache;
  14750. })();
  14751. function isName(v) {
  14752. return v instanceof Name;
  14753. }
  14754. function isCmd(v, cmd) {
  14755. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  14756. }
  14757. function isDict(v, type) {
  14758. if (!(v instanceof Dict)) {
  14759. return false;
  14760. }
  14761. if (!type) {
  14762. return true;
  14763. }
  14764. var dictType = v.get('Type');
  14765. return isName(dictType) && dictType.name === type;
  14766. }
  14767. function isRef(v) {
  14768. return v instanceof Ref;
  14769. }
  14770. function isStream(v) {
  14771. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  14772. }
  14773. exports.Cmd = Cmd;
  14774. exports.Dict = Dict;
  14775. exports.Name = Name;
  14776. exports.Ref = Ref;
  14777. exports.RefSet = RefSet;
  14778. exports.RefSetCache = RefSetCache;
  14779. exports.isCmd = isCmd;
  14780. exports.isDict = isDict;
  14781. exports.isName = isName;
  14782. exports.isRef = isRef;
  14783. exports.isStream = isStream;
  14784. }));
  14785. (function (root, factory) {
  14786. {
  14787. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  14788. root.pdfjsDisplayDOMUtils);
  14789. }
  14790. }(this, function (exports, sharedUtil, displayDOMUtils) {
  14791. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  14792. var AnnotationType = sharedUtil.AnnotationType;
  14793. var Util = sharedUtil.Util;
  14794. var isExternalLinkTargetSet = sharedUtil.isExternalLinkTargetSet;
  14795. var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
  14796. var warn = sharedUtil.warn;
  14797. var CustomStyle = displayDOMUtils.CustomStyle;
  14798. /**
  14799. * @typedef {Object} AnnotationElementParameters
  14800. * @property {Object} data
  14801. * @property {HTMLDivElement} layer
  14802. * @property {PDFPage} page
  14803. * @property {PageViewport} viewport
  14804. * @property {IPDFLinkService} linkService
  14805. */
  14806. /**
  14807. * @class
  14808. * @alias AnnotationElementFactory
  14809. */
  14810. function AnnotationElementFactory() {}
  14811. AnnotationElementFactory.prototype =
  14812. /** @lends AnnotationElementFactory.prototype */ {
  14813. /**
  14814. * @param {AnnotationElementParameters} parameters
  14815. * @returns {AnnotationElement}
  14816. */
  14817. create: function AnnotationElementFactory_create(parameters) {
  14818. var subtype = parameters.data.annotationType;
  14819. switch (subtype) {
  14820. case AnnotationType.LINK:
  14821. return new LinkAnnotationElement(parameters);
  14822. case AnnotationType.TEXT:
  14823. return new TextAnnotationElement(parameters);
  14824. case AnnotationType.WIDGET:
  14825. return new WidgetAnnotationElement(parameters);
  14826. case AnnotationType.POPUP:
  14827. return new PopupAnnotationElement(parameters);
  14828. case AnnotationType.HIGHLIGHT:
  14829. return new HighlightAnnotationElement(parameters);
  14830. case AnnotationType.UNDERLINE:
  14831. return new UnderlineAnnotationElement(parameters);
  14832. case AnnotationType.SQUIGGLY:
  14833. return new SquigglyAnnotationElement(parameters);
  14834. case AnnotationType.STRIKEOUT:
  14835. return new StrikeOutAnnotationElement(parameters);
  14836. default:
  14837. throw new Error('Unimplemented annotation type "' + subtype + '"');
  14838. }
  14839. }
  14840. };
  14841. /**
  14842. * @class
  14843. * @alias AnnotationElement
  14844. */
  14845. var AnnotationElement = (function AnnotationElementClosure() {
  14846. function AnnotationElement(parameters) {
  14847. this.data = parameters.data;
  14848. this.layer = parameters.layer;
  14849. this.page = parameters.page;
  14850. this.viewport = parameters.viewport;
  14851. this.linkService = parameters.linkService;
  14852. this.container = this._createContainer();
  14853. }
  14854. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  14855. /**
  14856. * Create an empty container for the annotation's HTML element.
  14857. *
  14858. * @private
  14859. * @memberof AnnotationElement
  14860. * @returns {HTMLSectionElement}
  14861. */
  14862. _createContainer: function AnnotationElement_createContainer() {
  14863. var data = this.data, page = this.page, viewport = this.viewport;
  14864. var container = document.createElement('section');
  14865. var width = data.rect[2] - data.rect[0];
  14866. var height = data.rect[3] - data.rect[1];
  14867. container.setAttribute('data-annotation-id', data.id);
  14868. // Do *not* modify `data.rect`, since that will corrupt the annotation
  14869. // position on subsequent calls to `_createContainer` (see issue 6804).
  14870. var rect = Util.normalizeRect([
  14871. data.rect[0],
  14872. page.view[3] - data.rect[1] + page.view[1],
  14873. data.rect[2],
  14874. page.view[3] - data.rect[3] + page.view[1]
  14875. ]);
  14876. CustomStyle.setProp('transform', container,
  14877. 'matrix(' + viewport.transform.join(',') + ')');
  14878. CustomStyle.setProp('transformOrigin', container,
  14879. -rect[0] + 'px ' + -rect[1] + 'px');
  14880. if (data.borderStyle.width > 0) {
  14881. container.style.borderWidth = data.borderStyle.width + 'px';
  14882. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  14883. // Underline styles only have a bottom border, so we do not need
  14884. // to adjust for all borders. This yields a similar result as
  14885. // Adobe Acrobat/Reader.
  14886. width = width - 2 * data.borderStyle.width;
  14887. height = height - 2 * data.borderStyle.width;
  14888. }
  14889. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  14890. var verticalRadius = data.borderStyle.verticalCornerRadius;
  14891. if (horizontalRadius > 0 || verticalRadius > 0) {
  14892. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  14893. CustomStyle.setProp('borderRadius', container, radius);
  14894. }
  14895. switch (data.borderStyle.style) {
  14896. case AnnotationBorderStyleType.SOLID:
  14897. container.style.borderStyle = 'solid';
  14898. break;
  14899. case AnnotationBorderStyleType.DASHED:
  14900. container.style.borderStyle = 'dashed';
  14901. break;
  14902. case AnnotationBorderStyleType.BEVELED:
  14903. warn('Unimplemented border style: beveled');
  14904. break;
  14905. case AnnotationBorderStyleType.INSET:
  14906. warn('Unimplemented border style: inset');
  14907. break;
  14908. case AnnotationBorderStyleType.UNDERLINE:
  14909. container.style.borderBottomStyle = 'solid';
  14910. break;
  14911. default:
  14912. break;
  14913. }
  14914. if (data.color) {
  14915. container.style.borderColor =
  14916. Util.makeCssRgb(data.color[0] | 0,
  14917. data.color[1] | 0,
  14918. data.color[2] | 0);
  14919. } else {
  14920. // Transparent (invisible) border, so do not draw it at all.
  14921. container.style.borderWidth = 0;
  14922. }
  14923. }
  14924. container.style.left = rect[0] + 'px';
  14925. container.style.top = rect[1] + 'px';
  14926. container.style.width = width + 'px';
  14927. container.style.height = height + 'px';
  14928. return container;
  14929. },
  14930. /**
  14931. * Render the annotation's HTML element in the empty container.
  14932. *
  14933. * @public
  14934. * @memberof AnnotationElement
  14935. */
  14936. render: function AnnotationElement_render() {
  14937. throw new Error('Abstract method AnnotationElement.render called');
  14938. }
  14939. };
  14940. return AnnotationElement;
  14941. })();
  14942. /**
  14943. * @class
  14944. * @alias LinkAnnotationElement
  14945. */
  14946. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  14947. function LinkAnnotationElement(parameters) {
  14948. AnnotationElement.call(this, parameters);
  14949. }
  14950. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  14951. /**
  14952. * Render the link annotation's HTML element in the empty container.
  14953. *
  14954. * @public
  14955. * @memberof LinkAnnotationElement
  14956. * @returns {HTMLSectionElement}
  14957. */
  14958. render: function LinkAnnotationElement_render() {
  14959. this.container.className = 'linkAnnotation';
  14960. var link = document.createElement('a');
  14961. link.href = link.title = this.data.url || '';
  14962. if (this.data.url && isExternalLinkTargetSet()) {
  14963. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  14964. }
  14965. // Strip referrer from the URL.
  14966. if (this.data.url) {
  14967. link.rel = PDFJS.externalLinkRel;
  14968. }
  14969. if (!this.data.url) {
  14970. if (this.data.action) {
  14971. this._bindNamedAction(link, this.data.action);
  14972. } else {
  14973. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  14974. }
  14975. }
  14976. this.container.appendChild(link);
  14977. return this.container;
  14978. },
  14979. /**
  14980. * Bind internal links to the link element.
  14981. *
  14982. * @private
  14983. * @param {Object} link
  14984. * @param {Object} destination
  14985. * @memberof LinkAnnotationElement
  14986. */
  14987. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  14988. var self = this;
  14989. link.href = this.linkService.getDestinationHash(destination);
  14990. link.onclick = function() {
  14991. if (destination) {
  14992. self.linkService.navigateTo(destination);
  14993. }
  14994. return false;
  14995. };
  14996. if (destination) {
  14997. link.className = 'internalLink';
  14998. }
  14999. },
  15000. /**
  15001. * Bind named actions to the link element.
  15002. *
  15003. * @private
  15004. * @param {Object} link
  15005. * @param {Object} action
  15006. * @memberof LinkAnnotationElement
  15007. */
  15008. _bindNamedAction:
  15009. function LinkAnnotationElement_bindNamedAction(link, action) {
  15010. var self = this;
  15011. link.href = this.linkService.getAnchorUrl('');
  15012. link.onclick = function() {
  15013. self.linkService.executeNamedAction(action);
  15014. return false;
  15015. };
  15016. link.className = 'internalLink';
  15017. }
  15018. });
  15019. return LinkAnnotationElement;
  15020. })();
  15021. /**
  15022. * @class
  15023. * @alias TextAnnotationElement
  15024. */
  15025. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  15026. function TextAnnotationElement(parameters) {
  15027. AnnotationElement.call(this, parameters);
  15028. }
  15029. Util.inherit(TextAnnotationElement, AnnotationElement, {
  15030. /**
  15031. * Render the text annotation's HTML element in the empty container.
  15032. *
  15033. * @public
  15034. * @memberof TextAnnotationElement
  15035. * @returns {HTMLSectionElement}
  15036. */
  15037. render: function TextAnnotationElement_render() {
  15038. this.container.className = 'textAnnotation';
  15039. var image = document.createElement('img');
  15040. image.style.height = this.container.style.height;
  15041. image.style.width = this.container.style.width;
  15042. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  15043. this.data.name.toLowerCase() + '.svg';
  15044. image.alt = '[{{type}} Annotation]';
  15045. image.dataset.l10nId = 'text_annotation_type';
  15046. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  15047. if (!this.data.hasPopup) {
  15048. var popupElement = new PopupElement({
  15049. container: this.container,
  15050. trigger: image,
  15051. color: this.data.color,
  15052. title: this.data.title,
  15053. contents: this.data.contents,
  15054. hideWrapper: true
  15055. });
  15056. var popup = popupElement.render();
  15057. // Position the popup next to the Text annotation's container.
  15058. popup.style.left = image.style.width;
  15059. this.container.appendChild(popup);
  15060. }
  15061. this.container.appendChild(image);
  15062. return this.container;
  15063. }
  15064. });
  15065. return TextAnnotationElement;
  15066. })();
  15067. /**
  15068. * @class
  15069. * @alias WidgetAnnotationElement
  15070. */
  15071. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  15072. function WidgetAnnotationElement(parameters) {
  15073. AnnotationElement.call(this, parameters);
  15074. }
  15075. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  15076. /**
  15077. * Render the widget annotation's HTML element in the empty container.
  15078. *
  15079. * @public
  15080. * @memberof WidgetAnnotationElement
  15081. * @returns {HTMLSectionElement}
  15082. */
  15083. render: function WidgetAnnotationElement_render() {
  15084. var content = document.createElement('div');
  15085. content.textContent = this.data.fieldValue;
  15086. var textAlignment = this.data.textAlignment;
  15087. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  15088. content.style.verticalAlign = 'middle';
  15089. content.style.display = 'table-cell';
  15090. var font = (this.data.fontRefName ?
  15091. this.page.commonObjs.getData(this.data.fontRefName) : null);
  15092. this._setTextStyle(content, font);
  15093. this.container.appendChild(content);
  15094. return this.container;
  15095. },
  15096. /**
  15097. * Apply text styles to the text in the element.
  15098. *
  15099. * @private
  15100. * @param {HTMLDivElement} element
  15101. * @param {Object} font
  15102. * @memberof WidgetAnnotationElement
  15103. */
  15104. _setTextStyle:
  15105. function WidgetAnnotationElement_setTextStyle(element, font) {
  15106. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  15107. var style = element.style;
  15108. style.fontSize = this.data.fontSize + 'px';
  15109. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  15110. if (!font) {
  15111. return;
  15112. }
  15113. style.fontWeight = (font.black ?
  15114. (font.bold ? '900' : 'bold') :
  15115. (font.bold ? 'bold' : 'normal'));
  15116. style.fontStyle = (font.italic ? 'italic' : 'normal');
  15117. // Use a reasonable default font if the font doesn't specify a fallback.
  15118. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  15119. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  15120. style.fontFamily = fontFamily + fallbackName;
  15121. }
  15122. });
  15123. return WidgetAnnotationElement;
  15124. })();
  15125. /**
  15126. * @class
  15127. * @alias PopupAnnotationElement
  15128. */
  15129. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  15130. function PopupAnnotationElement(parameters) {
  15131. AnnotationElement.call(this, parameters);
  15132. }
  15133. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  15134. /**
  15135. * Render the popup annotation's HTML element in the empty container.
  15136. *
  15137. * @public
  15138. * @memberof PopupAnnotationElement
  15139. * @returns {HTMLSectionElement}
  15140. */
  15141. render: function PopupAnnotationElement_render() {
  15142. this.container.className = 'popupAnnotation';
  15143. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  15144. var parentElement = this.layer.querySelector(selector);
  15145. if (!parentElement) {
  15146. return this.container;
  15147. }
  15148. var popup = new PopupElement({
  15149. container: this.container,
  15150. trigger: parentElement,
  15151. color: this.data.color,
  15152. title: this.data.title,
  15153. contents: this.data.contents
  15154. });
  15155. // Position the popup next to the parent annotation's container.
  15156. // PDF viewers ignore a popup annotation's rectangle.
  15157. var parentLeft = parseFloat(parentElement.style.left);
  15158. var parentWidth = parseFloat(parentElement.style.width);
  15159. CustomStyle.setProp('transformOrigin', this.container,
  15160. -(parentLeft + parentWidth) + 'px -' +
  15161. parentElement.style.top);
  15162. this.container.style.left = (parentLeft + parentWidth) + 'px';
  15163. this.container.appendChild(popup.render());
  15164. return this.container;
  15165. }
  15166. });
  15167. return PopupAnnotationElement;
  15168. })();
  15169. /**
  15170. * @class
  15171. * @alias PopupElement
  15172. */
  15173. var PopupElement = (function PopupElementClosure() {
  15174. var BACKGROUND_ENLIGHT = 0.7;
  15175. function PopupElement(parameters) {
  15176. this.container = parameters.container;
  15177. this.trigger = parameters.trigger;
  15178. this.color = parameters.color;
  15179. this.title = parameters.title;
  15180. this.contents = parameters.contents;
  15181. this.hideWrapper = parameters.hideWrapper || false;
  15182. this.pinned = false;
  15183. }
  15184. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  15185. /**
  15186. * Render the popup's HTML element.
  15187. *
  15188. * @public
  15189. * @memberof PopupElement
  15190. * @returns {HTMLSectionElement}
  15191. */
  15192. render: function PopupElement_render() {
  15193. var wrapper = document.createElement('div');
  15194. wrapper.className = 'popupWrapper';
  15195. // For Popup annotations we hide the entire section because it contains
  15196. // only the popup. However, for Text annotations without a separate Popup
  15197. // annotation, we cannot hide the entire container as the image would
  15198. // disappear too. In that special case, hiding the wrapper suffices.
  15199. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  15200. this.hideElement.setAttribute('hidden', true);
  15201. var popup = document.createElement('div');
  15202. popup.className = 'popup';
  15203. var color = this.color;
  15204. if (color) {
  15205. // Enlighten the color.
  15206. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  15207. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  15208. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  15209. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  15210. }
  15211. var contents = this._formatContents(this.contents);
  15212. var title = document.createElement('h1');
  15213. title.textContent = this.title;
  15214. // Attach the event listeners to the trigger element.
  15215. this.trigger.addEventListener('click', this._toggle.bind(this));
  15216. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  15217. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  15218. popup.addEventListener('click', this._hide.bind(this, true));
  15219. popup.appendChild(title);
  15220. popup.appendChild(contents);
  15221. wrapper.appendChild(popup);
  15222. return wrapper;
  15223. },
  15224. /**
  15225. * Format the contents of the popup by adding newlines where necessary.
  15226. *
  15227. * @private
  15228. * @param {string} contents
  15229. * @memberof PopupElement
  15230. * @returns {HTMLParagraphElement}
  15231. */
  15232. _formatContents: function PopupElement_formatContents(contents) {
  15233. var p = document.createElement('p');
  15234. var lines = contents.split(/(?:\r\n?|\n)/);
  15235. for (var i = 0, ii = lines.length; i < ii; ++i) {
  15236. var line = lines[i];
  15237. p.appendChild(document.createTextNode(line));
  15238. if (i < (ii - 1)) {
  15239. p.appendChild(document.createElement('br'));
  15240. }
  15241. }
  15242. return p;
  15243. },
  15244. /**
  15245. * Toggle the visibility of the popup.
  15246. *
  15247. * @private
  15248. * @memberof PopupElement
  15249. */
  15250. _toggle: function PopupElement_toggle() {
  15251. if (this.pinned) {
  15252. this._hide(true);
  15253. } else {
  15254. this._show(true);
  15255. }
  15256. },
  15257. /**
  15258. * Show the popup.
  15259. *
  15260. * @private
  15261. * @param {boolean} pin
  15262. * @memberof PopupElement
  15263. */
  15264. _show: function PopupElement_show(pin) {
  15265. if (pin) {
  15266. this.pinned = true;
  15267. }
  15268. if (this.hideElement.hasAttribute('hidden')) {
  15269. this.hideElement.removeAttribute('hidden');
  15270. this.container.style.zIndex += 1;
  15271. }
  15272. },
  15273. /**
  15274. * Hide the popup.
  15275. *
  15276. * @private
  15277. * @param {boolean} unpin
  15278. * @memberof PopupElement
  15279. */
  15280. _hide: function PopupElement_hide(unpin) {
  15281. if (unpin) {
  15282. this.pinned = false;
  15283. }
  15284. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  15285. this.hideElement.setAttribute('hidden', true);
  15286. this.container.style.zIndex -= 1;
  15287. }
  15288. }
  15289. };
  15290. return PopupElement;
  15291. })();
  15292. /**
  15293. * @class
  15294. * @alias HighlightAnnotationElement
  15295. */
  15296. var HighlightAnnotationElement = (
  15297. function HighlightAnnotationElementClosure() {
  15298. function HighlightAnnotationElement(parameters) {
  15299. AnnotationElement.call(this, parameters);
  15300. }
  15301. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  15302. /**
  15303. * Render the highlight annotation's HTML element in the empty container.
  15304. *
  15305. * @public
  15306. * @memberof HighlightAnnotationElement
  15307. * @returns {HTMLSectionElement}
  15308. */
  15309. render: function HighlightAnnotationElement_render() {
  15310. this.container.className = 'highlightAnnotation';
  15311. return this.container;
  15312. }
  15313. });
  15314. return HighlightAnnotationElement;
  15315. })();
  15316. /**
  15317. * @class
  15318. * @alias UnderlineAnnotationElement
  15319. */
  15320. var UnderlineAnnotationElement = (
  15321. function UnderlineAnnotationElementClosure() {
  15322. function UnderlineAnnotationElement(parameters) {
  15323. AnnotationElement.call(this, parameters);
  15324. }
  15325. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  15326. /**
  15327. * Render the underline annotation's HTML element in the empty container.
  15328. *
  15329. * @public
  15330. * @memberof UnderlineAnnotationElement
  15331. * @returns {HTMLSectionElement}
  15332. */
  15333. render: function UnderlineAnnotationElement_render() {
  15334. this.container.className = 'underlineAnnotation';
  15335. return this.container;
  15336. }
  15337. });
  15338. return UnderlineAnnotationElement;
  15339. })();
  15340. /**
  15341. * @class
  15342. * @alias SquigglyAnnotationElement
  15343. */
  15344. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  15345. function SquigglyAnnotationElement(parameters) {
  15346. AnnotationElement.call(this, parameters);
  15347. }
  15348. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  15349. /**
  15350. * Render the squiggly annotation's HTML element in the empty container.
  15351. *
  15352. * @public
  15353. * @memberof SquigglyAnnotationElement
  15354. * @returns {HTMLSectionElement}
  15355. */
  15356. render: function SquigglyAnnotationElement_render() {
  15357. this.container.className = 'squigglyAnnotation';
  15358. return this.container;
  15359. }
  15360. });
  15361. return SquigglyAnnotationElement;
  15362. })();
  15363. /**
  15364. * @class
  15365. * @alias StrikeOutAnnotationElement
  15366. */
  15367. var StrikeOutAnnotationElement = (
  15368. function StrikeOutAnnotationElementClosure() {
  15369. function StrikeOutAnnotationElement(parameters) {
  15370. AnnotationElement.call(this, parameters);
  15371. }
  15372. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  15373. /**
  15374. * Render the strikeout annotation's HTML element in the empty container.
  15375. *
  15376. * @public
  15377. * @memberof StrikeOutAnnotationElement
  15378. * @returns {HTMLSectionElement}
  15379. */
  15380. render: function StrikeOutAnnotationElement_render() {
  15381. this.container.className = 'strikeoutAnnotation';
  15382. return this.container;
  15383. }
  15384. });
  15385. return StrikeOutAnnotationElement;
  15386. })();
  15387. /**
  15388. * @typedef {Object} AnnotationLayerParameters
  15389. * @property {PageViewport} viewport
  15390. * @property {HTMLDivElement} div
  15391. * @property {Array} annotations
  15392. * @property {PDFPage} page
  15393. * @property {IPDFLinkService} linkService
  15394. */
  15395. /**
  15396. * @class
  15397. * @alias AnnotationLayer
  15398. */
  15399. var AnnotationLayer = (function AnnotationLayerClosure() {
  15400. return {
  15401. /**
  15402. * Render a new annotation layer with all annotation elements.
  15403. *
  15404. * @public
  15405. * @param {AnnotationLayerParameters} parameters
  15406. * @memberof AnnotationLayer
  15407. */
  15408. render: function AnnotationLayer_render(parameters) {
  15409. var annotationElementFactory = new AnnotationElementFactory();
  15410. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  15411. var data = parameters.annotations[i];
  15412. if (!data || !data.hasHtml) {
  15413. continue;
  15414. }
  15415. var properties = {
  15416. data: data,
  15417. layer: parameters.div,
  15418. page: parameters.page,
  15419. viewport: parameters.viewport,
  15420. linkService: parameters.linkService
  15421. };
  15422. var element = annotationElementFactory.create(properties);
  15423. parameters.div.appendChild(element.render());
  15424. }
  15425. },
  15426. /**
  15427. * Update the annotation elements on existing annotation layer.
  15428. *
  15429. * @public
  15430. * @param {AnnotationLayerParameters} parameters
  15431. * @memberof AnnotationLayer
  15432. */
  15433. update: function AnnotationLayer_update(parameters) {
  15434. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  15435. var data = parameters.annotations[i];
  15436. var element = parameters.div.querySelector(
  15437. '[data-annotation-id="' + data.id + '"]');
  15438. if (element) {
  15439. CustomStyle.setProp('transform', element,
  15440. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  15441. }
  15442. }
  15443. parameters.div.removeAttribute('hidden');
  15444. }
  15445. };
  15446. })();
  15447. PDFJS.AnnotationLayer = AnnotationLayer;
  15448. exports.AnnotationLayer = AnnotationLayer;
  15449. }));
  15450. (function (root, factory) {
  15451. {
  15452. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  15453. root.pdfjsSharedGlobal);
  15454. }
  15455. }(this, function (exports, sharedUtil, sharedGlobal) {
  15456. var assert = sharedUtil.assert;
  15457. var bytesToString = sharedUtil.bytesToString;
  15458. var string32 = sharedUtil.string32;
  15459. var shadow = sharedUtil.shadow;
  15460. var warn = sharedUtil.warn;
  15461. var PDFJS = sharedGlobal.PDFJS;
  15462. var globalScope = sharedGlobal.globalScope;
  15463. var isWorker = sharedGlobal.isWorker;
  15464. function FontLoader(docId) {
  15465. this.docId = docId;
  15466. this.styleElement = null;
  15467. this.nativeFontFaces = [];
  15468. this.loadTestFontId = 0;
  15469. this.loadingContext = {
  15470. requests: [],
  15471. nextRequestId: 0
  15472. };
  15473. }
  15474. FontLoader.prototype = {
  15475. insertRule: function fontLoaderInsertRule(rule) {
  15476. var styleElement = this.styleElement;
  15477. if (!styleElement) {
  15478. styleElement = this.styleElement = document.createElement('style');
  15479. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  15480. document.documentElement.getElementsByTagName('head')[0].appendChild(
  15481. styleElement);
  15482. }
  15483. var styleSheet = styleElement.sheet;
  15484. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  15485. },
  15486. clear: function fontLoaderClear() {
  15487. var styleElement = this.styleElement;
  15488. if (styleElement) {
  15489. styleElement.parentNode.removeChild(styleElement);
  15490. styleElement = this.styleElement = null;
  15491. }
  15492. this.nativeFontFaces.forEach(function(nativeFontFace) {
  15493. document.fonts.delete(nativeFontFace);
  15494. });
  15495. this.nativeFontFaces.length = 0;
  15496. },
  15497. get loadTestFont() {
  15498. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  15499. // height.
  15500. return shadow(this, 'loadTestFont', atob(
  15501. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  15502. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  15503. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  15504. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  15505. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  15506. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  15507. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  15508. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  15509. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  15510. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  15511. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  15512. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  15513. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  15514. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  15515. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  15516. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  15517. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  15518. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  15519. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  15520. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  15521. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  15522. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  15523. ));
  15524. },
  15525. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  15526. this.nativeFontFaces.push(nativeFontFace);
  15527. document.fonts.add(nativeFontFace);
  15528. },
  15529. bind: function fontLoaderBind(fonts, callback) {
  15530. assert(!isWorker, 'bind() shall be called from main thread');
  15531. var rules = [];
  15532. var fontsToLoad = [];
  15533. var fontLoadPromises = [];
  15534. var getNativeFontPromise = function(nativeFontFace) {
  15535. // Return a promise that is always fulfilled, even when the font fails to
  15536. // load.
  15537. return nativeFontFace.loaded.catch(function(e) {
  15538. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  15539. });
  15540. };
  15541. for (var i = 0, ii = fonts.length; i < ii; i++) {
  15542. var font = fonts[i];
  15543. // Add the font to the DOM only once or skip if the font
  15544. // is already loaded.
  15545. if (font.attached || font.loading === false) {
  15546. continue;
  15547. }
  15548. font.attached = true;
  15549. if (FontLoader.isFontLoadingAPISupported) {
  15550. var nativeFontFace = font.createNativeFontFace();
  15551. if (nativeFontFace) {
  15552. this.addNativeFontFace(nativeFontFace);
  15553. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  15554. }
  15555. } else {
  15556. var rule = font.createFontFaceRule();
  15557. if (rule) {
  15558. this.insertRule(rule);
  15559. rules.push(rule);
  15560. fontsToLoad.push(font);
  15561. }
  15562. }
  15563. }
  15564. var request = this.queueLoadingCallback(callback);
  15565. if (FontLoader.isFontLoadingAPISupported) {
  15566. Promise.all(fontLoadPromises).then(function() {
  15567. request.complete();
  15568. });
  15569. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  15570. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  15571. } else {
  15572. request.complete();
  15573. }
  15574. },
  15575. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  15576. function LoadLoader_completeRequest() {
  15577. assert(!request.end, 'completeRequest() cannot be called twice');
  15578. request.end = Date.now();
  15579. // sending all completed requests in order how they were queued
  15580. while (context.requests.length > 0 && context.requests[0].end) {
  15581. var otherRequest = context.requests.shift();
  15582. setTimeout(otherRequest.callback, 0);
  15583. }
  15584. }
  15585. var context = this.loadingContext;
  15586. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  15587. var request = {
  15588. id: requestId,
  15589. complete: LoadLoader_completeRequest,
  15590. callback: callback,
  15591. started: Date.now()
  15592. };
  15593. context.requests.push(request);
  15594. return request;
  15595. },
  15596. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  15597. fonts,
  15598. request) {
  15599. /** Hack begin */
  15600. // There's currently no event when a font has finished downloading so the
  15601. // following code is a dirty hack to 'guess' when a font is
  15602. // ready. It's assumed fonts are loaded in order, so add a known test
  15603. // font after the desired fonts and then test for the loading of that
  15604. // test font.
  15605. function int32(data, offset) {
  15606. return (data.charCodeAt(offset) << 24) |
  15607. (data.charCodeAt(offset + 1) << 16) |
  15608. (data.charCodeAt(offset + 2) << 8) |
  15609. (data.charCodeAt(offset + 3) & 0xff);
  15610. }
  15611. function spliceString(s, offset, remove, insert) {
  15612. var chunk1 = s.substr(0, offset);
  15613. var chunk2 = s.substr(offset + remove);
  15614. return chunk1 + insert + chunk2;
  15615. }
  15616. var i, ii;
  15617. var canvas = document.createElement('canvas');
  15618. canvas.width = 1;
  15619. canvas.height = 1;
  15620. var ctx = canvas.getContext('2d');
  15621. var called = 0;
  15622. function isFontReady(name, callback) {
  15623. called++;
  15624. // With setTimeout clamping this gives the font ~100ms to load.
  15625. if(called > 30) {
  15626. warn('Load test font never loaded.');
  15627. callback();
  15628. return;
  15629. }
  15630. ctx.font = '30px ' + name;
  15631. ctx.fillText('.', 0, 20);
  15632. var imageData = ctx.getImageData(0, 0, 1, 1);
  15633. if (imageData.data[3] > 0) {
  15634. callback();
  15635. return;
  15636. }
  15637. setTimeout(isFontReady.bind(null, name, callback));
  15638. }
  15639. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  15640. // Chromium seems to cache fonts based on a hash of the actual font data,
  15641. // so the font must be modified for each load test else it will appear to
  15642. // be loaded already.
  15643. // TODO: This could maybe be made faster by avoiding the btoa of the full
  15644. // font by splitting it in chunks before hand and padding the font id.
  15645. var data = this.loadTestFont;
  15646. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  15647. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  15648. loadTestFontId);
  15649. // CFF checksum is important for IE, adjusting it
  15650. var CFF_CHECKSUM_OFFSET = 16;
  15651. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  15652. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  15653. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  15654. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  15655. }
  15656. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  15657. checksum = (checksum - XXXX_VALUE +
  15658. int32(loadTestFontId + 'XXX', i)) | 0;
  15659. }
  15660. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  15661. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  15662. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  15663. url + '}';
  15664. this.insertRule(rule);
  15665. var names = [];
  15666. for (i = 0, ii = fonts.length; i < ii; i++) {
  15667. names.push(fonts[i].loadedName);
  15668. }
  15669. names.push(loadTestFontId);
  15670. var div = document.createElement('div');
  15671. div.setAttribute('style',
  15672. 'visibility: hidden;' +
  15673. 'width: 10px; height: 10px;' +
  15674. 'position: absolute; top: 0px; left: 0px;');
  15675. for (i = 0, ii = names.length; i < ii; ++i) {
  15676. var span = document.createElement('span');
  15677. span.textContent = 'Hi';
  15678. span.style.fontFamily = names[i];
  15679. div.appendChild(span);
  15680. }
  15681. document.body.appendChild(div);
  15682. isFontReady(loadTestFontId, function() {
  15683. document.body.removeChild(div);
  15684. request.complete();
  15685. });
  15686. /** Hack end */
  15687. }
  15688. };
  15689. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  15690. typeof document !== 'undefined' && !!document.fonts);
  15691. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  15692. get: function () {
  15693. var supported = false;
  15694. // User agent string sniffing is bad, but there is no reliable way to tell
  15695. // if font is fully loaded and ready to be used with canvas.
  15696. var userAgent = window.navigator.userAgent;
  15697. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  15698. if (m && m[1] >= 14) {
  15699. supported = true;
  15700. }
  15701. // TODO other browsers
  15702. if (userAgent === 'node') {
  15703. supported = true;
  15704. }
  15705. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  15706. },
  15707. enumerable: true,
  15708. configurable: true
  15709. });
  15710. var FontFaceObject = (function FontFaceObjectClosure() {
  15711. function FontFaceObject(translatedData) {
  15712. this.compiledGlyphs = {};
  15713. // importing translated data
  15714. for (var i in translatedData) {
  15715. this[i] = translatedData[i];
  15716. }
  15717. }
  15718. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  15719. get: function () {
  15720. var evalSupport = false;
  15721. if (PDFJS.isEvalSupported) {
  15722. try {
  15723. /* jshint evil: true */
  15724. new Function('');
  15725. evalSupport = true;
  15726. } catch (e) {}
  15727. }
  15728. return shadow(this, 'isEvalSupported', evalSupport);
  15729. },
  15730. enumerable: true,
  15731. configurable: true
  15732. });
  15733. FontFaceObject.prototype = {
  15734. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  15735. if (!this.data) {
  15736. return null;
  15737. }
  15738. if (PDFJS.disableFontFace) {
  15739. this.disableFontFace = true;
  15740. return null;
  15741. }
  15742. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  15743. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  15744. globalScope['FontInspector'].enabled) {
  15745. globalScope['FontInspector'].fontAdded(this);
  15746. }
  15747. return nativeFontFace;
  15748. },
  15749. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  15750. if (!this.data) {
  15751. return null;
  15752. }
  15753. if (PDFJS.disableFontFace) {
  15754. this.disableFontFace = true;
  15755. return null;
  15756. }
  15757. var data = bytesToString(new Uint8Array(this.data));
  15758. var fontName = this.loadedName;
  15759. // Add the font-face rule to the document
  15760. var url = ('url(data:' + this.mimetype + ';base64,' +
  15761. window.btoa(data) + ');');
  15762. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  15763. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  15764. globalScope['FontInspector'].enabled) {
  15765. globalScope['FontInspector'].fontAdded(this, url);
  15766. }
  15767. return rule;
  15768. },
  15769. getPathGenerator:
  15770. function FontFaceObject_getPathGenerator(objs, character) {
  15771. if (!(character in this.compiledGlyphs)) {
  15772. var cmds = objs.get(this.loadedName + '_path_' + character);
  15773. var current, i, len;
  15774. // If we can, compile cmds into JS for MAXIMUM SPEED
  15775. if (FontFaceObject.isEvalSupported) {
  15776. var args, js = '';
  15777. for (i = 0, len = cmds.length; i < len; i++) {
  15778. current = cmds[i];
  15779. if (current.args !== undefined) {
  15780. args = current.args.join(',');
  15781. } else {
  15782. args = '';
  15783. }
  15784. js += 'c.' + current.cmd + '(' + args + ');\n';
  15785. }
  15786. /* jshint -W054 */
  15787. this.compiledGlyphs[character] = new Function('c', 'size', js);
  15788. } else {
  15789. // But fall back on using Function.prototype.apply() if we're
  15790. // blocked from using eval() for whatever reason (like CSP policies)
  15791. this.compiledGlyphs[character] = function(c, size) {
  15792. for (i = 0, len = cmds.length; i < len; i++) {
  15793. current = cmds[i];
  15794. if (current.cmd === 'scale') {
  15795. current.args = [size, -size];
  15796. }
  15797. c[current.cmd].apply(c, current.args);
  15798. }
  15799. };
  15800. }
  15801. }
  15802. return this.compiledGlyphs[character];
  15803. }
  15804. };
  15805. return FontFaceObject;
  15806. })();
  15807. exports.FontFaceObject = FontFaceObject;
  15808. exports.FontLoader = FontLoader;
  15809. }));
  15810. (function (root, factory) {
  15811. {
  15812. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  15813. }
  15814. }(this, function (exports, sharedUtil) {
  15815. var error = sharedUtil.error;
  15816. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  15817. function fixMetadata(meta) {
  15818. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  15819. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  15820. function(code, d1, d2, d3) {
  15821. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  15822. });
  15823. var chars = '';
  15824. for (var i = 0; i < bytes.length; i += 2) {
  15825. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  15826. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  15827. code !== 38 && false ? String.fromCharCode(code) :
  15828. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  15829. }
  15830. return '>' + chars;
  15831. });
  15832. }
  15833. function Metadata(meta) {
  15834. if (typeof meta === 'string') {
  15835. // Ghostscript produces invalid metadata
  15836. meta = fixMetadata(meta);
  15837. var parser = new DOMParser();
  15838. meta = parser.parseFromString(meta, 'application/xml');
  15839. } else if (!(meta instanceof Document)) {
  15840. error('Metadata: Invalid metadata object');
  15841. }
  15842. this.metaDocument = meta;
  15843. this.metadata = {};
  15844. this.parse();
  15845. }
  15846. Metadata.prototype = {
  15847. parse: function Metadata_parse() {
  15848. var doc = this.metaDocument;
  15849. var rdf = doc.documentElement;
  15850. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  15851. rdf = rdf.firstChild;
  15852. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  15853. rdf = rdf.nextSibling;
  15854. }
  15855. }
  15856. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  15857. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  15858. return;
  15859. }
  15860. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  15861. for (i = 0, length = children.length; i < length; i++) {
  15862. desc = children[i];
  15863. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  15864. continue;
  15865. }
  15866. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  15867. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  15868. entry = desc.childNodes[ii];
  15869. name = entry.nodeName.toLowerCase();
  15870. this.metadata[name] = entry.textContent.trim();
  15871. }
  15872. }
  15873. }
  15874. },
  15875. get: function Metadata_get(name) {
  15876. return this.metadata[name] || null;
  15877. },
  15878. has: function Metadata_has(name) {
  15879. return typeof this.metadata[name] !== 'undefined';
  15880. }
  15881. };
  15882. return Metadata;
  15883. })();
  15884. exports.Metadata = Metadata;
  15885. }));
  15886. (function (root, factory) {
  15887. {
  15888. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  15889. }
  15890. }(this, function (exports, sharedUtil) {
  15891. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  15892. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  15893. var ImageKind = sharedUtil.ImageKind;
  15894. var OPS = sharedUtil.OPS;
  15895. var Util = sharedUtil.Util;
  15896. var isNum = sharedUtil.isNum;
  15897. var isArray = sharedUtil.isArray;
  15898. var warn = sharedUtil.warn;
  15899. var SVG_DEFAULTS = {
  15900. fontStyle: 'normal',
  15901. fontWeight: 'normal',
  15902. fillColor: '#000000'
  15903. };
  15904. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  15905. var PNG_HEADER =
  15906. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  15907. var CHUNK_WRAPPER_SIZE = 12;
  15908. var crcTable = new Int32Array(256);
  15909. for (var i = 0; i < 256; i++) {
  15910. var c = i;
  15911. for (var h = 0; h < 8; h++) {
  15912. if (c & 1) {
  15913. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  15914. } else {
  15915. c = (c >> 1) & 0x7fffffff;
  15916. }
  15917. }
  15918. crcTable[i] = c;
  15919. }
  15920. function crc32(data, start, end) {
  15921. var crc = -1;
  15922. for (var i = start; i < end; i++) {
  15923. var a = (crc ^ data[i]) & 0xff;
  15924. var b = crcTable[a];
  15925. crc = (crc >>> 8) ^ b;
  15926. }
  15927. return crc ^ -1;
  15928. }
  15929. function writePngChunk(type, body, data, offset) {
  15930. var p = offset;
  15931. var len = body.length;
  15932. data[p] = len >> 24 & 0xff;
  15933. data[p + 1] = len >> 16 & 0xff;
  15934. data[p + 2] = len >> 8 & 0xff;
  15935. data[p + 3] = len & 0xff;
  15936. p += 4;
  15937. data[p] = type.charCodeAt(0) & 0xff;
  15938. data[p + 1] = type.charCodeAt(1) & 0xff;
  15939. data[p + 2] = type.charCodeAt(2) & 0xff;
  15940. data[p + 3] = type.charCodeAt(3) & 0xff;
  15941. p += 4;
  15942. data.set(body, p);
  15943. p += body.length;
  15944. var crc = crc32(data, offset + 4, p);
  15945. data[p] = crc >> 24 & 0xff;
  15946. data[p + 1] = crc >> 16 & 0xff;
  15947. data[p + 2] = crc >> 8 & 0xff;
  15948. data[p + 3] = crc & 0xff;
  15949. }
  15950. function adler32(data, start, end) {
  15951. var a = 1;
  15952. var b = 0;
  15953. for (var i = start; i < end; ++i) {
  15954. a = (a + (data[i] & 0xff)) % 65521;
  15955. b = (b + a) % 65521;
  15956. }
  15957. return (b << 16) | a;
  15958. }
  15959. function encode(imgData, kind) {
  15960. var width = imgData.width;
  15961. var height = imgData.height;
  15962. var bitDepth, colorType, lineSize;
  15963. var bytes = imgData.data;
  15964. switch (kind) {
  15965. case ImageKind.GRAYSCALE_1BPP:
  15966. colorType = 0;
  15967. bitDepth = 1;
  15968. lineSize = (width + 7) >> 3;
  15969. break;
  15970. case ImageKind.RGB_24BPP:
  15971. colorType = 2;
  15972. bitDepth = 8;
  15973. lineSize = width * 3;
  15974. break;
  15975. case ImageKind.RGBA_32BPP:
  15976. colorType = 6;
  15977. bitDepth = 8;
  15978. lineSize = width * 4;
  15979. break;
  15980. default:
  15981. throw new Error('invalid format');
  15982. }
  15983. // prefix every row with predictor 0
  15984. var literals = new Uint8Array((1 + lineSize) * height);
  15985. var offsetLiterals = 0, offsetBytes = 0;
  15986. var y, i;
  15987. for (y = 0; y < height; ++y) {
  15988. literals[offsetLiterals++] = 0; // no prediction
  15989. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  15990. offsetLiterals);
  15991. offsetBytes += lineSize;
  15992. offsetLiterals += lineSize;
  15993. }
  15994. if (kind === ImageKind.GRAYSCALE_1BPP) {
  15995. // inverting for B/W
  15996. offsetLiterals = 0;
  15997. for (y = 0; y < height; y++) {
  15998. offsetLiterals++; // skipping predictor
  15999. for (i = 0; i < lineSize; i++) {
  16000. literals[offsetLiterals++] ^= 0xFF;
  16001. }
  16002. }
  16003. }
  16004. var ihdr = new Uint8Array([
  16005. width >> 24 & 0xff,
  16006. width >> 16 & 0xff,
  16007. width >> 8 & 0xff,
  16008. width & 0xff,
  16009. height >> 24 & 0xff,
  16010. height >> 16 & 0xff,
  16011. height >> 8 & 0xff,
  16012. height & 0xff,
  16013. bitDepth, // bit depth
  16014. colorType, // color type
  16015. 0x00, // compression method
  16016. 0x00, // filter method
  16017. 0x00 // interlace method
  16018. ]);
  16019. var len = literals.length;
  16020. var maxBlockLength = 0xFFFF;
  16021. var deflateBlocks = Math.ceil(len / maxBlockLength);
  16022. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  16023. var pi = 0;
  16024. idat[pi++] = 0x78; // compression method and flags
  16025. idat[pi++] = 0x9c; // flags
  16026. var pos = 0;
  16027. while (len > maxBlockLength) {
  16028. // writing non-final DEFLATE blocks type 0 and length of 65535
  16029. idat[pi++] = 0x00;
  16030. idat[pi++] = 0xff;
  16031. idat[pi++] = 0xff;
  16032. idat[pi++] = 0x00;
  16033. idat[pi++] = 0x00;
  16034. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  16035. pi += maxBlockLength;
  16036. pos += maxBlockLength;
  16037. len -= maxBlockLength;
  16038. }
  16039. // writing non-final DEFLATE blocks type 0
  16040. idat[pi++] = 0x01;
  16041. idat[pi++] = len & 0xff;
  16042. idat[pi++] = len >> 8 & 0xff;
  16043. idat[pi++] = (~len & 0xffff) & 0xff;
  16044. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  16045. idat.set(literals.subarray(pos), pi);
  16046. pi += literals.length - pos;
  16047. var adler = adler32(literals, 0, literals.length); // checksum
  16048. idat[pi++] = adler >> 24 & 0xff;
  16049. idat[pi++] = adler >> 16 & 0xff;
  16050. idat[pi++] = adler >> 8 & 0xff;
  16051. idat[pi++] = adler & 0xff;
  16052. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  16053. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  16054. ihdr.length + idat.length;
  16055. var data = new Uint8Array(pngLength);
  16056. var offset = 0;
  16057. data.set(PNG_HEADER, offset);
  16058. offset += PNG_HEADER.length;
  16059. writePngChunk('IHDR', ihdr, data, offset);
  16060. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  16061. writePngChunk('IDATA', idat, data, offset);
  16062. offset += CHUNK_WRAPPER_SIZE + idat.length;
  16063. writePngChunk('IEND', new Uint8Array(0), data, offset);
  16064. return PDFJS.createObjectURL(data, 'image/png');
  16065. }
  16066. return function convertImgDataToPng(imgData) {
  16067. var kind = (imgData.kind === undefined ?
  16068. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  16069. return encode(imgData, kind);
  16070. };
  16071. })();
  16072. var SVGExtraState = (function SVGExtraStateClosure() {
  16073. function SVGExtraState() {
  16074. this.fontSizeScale = 1;
  16075. this.fontWeight = SVG_DEFAULTS.fontWeight;
  16076. this.fontSize = 0;
  16077. this.textMatrix = IDENTITY_MATRIX;
  16078. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16079. this.leading = 0;
  16080. // Current point (in user coordinates)
  16081. this.x = 0;
  16082. this.y = 0;
  16083. // Start of text line (in text coordinates)
  16084. this.lineX = 0;
  16085. this.lineY = 0;
  16086. // Character and word spacing
  16087. this.charSpacing = 0;
  16088. this.wordSpacing = 0;
  16089. this.textHScale = 1;
  16090. this.textRise = 0;
  16091. // Default foreground and background colors
  16092. this.fillColor = SVG_DEFAULTS.fillColor;
  16093. this.strokeColor = '#000000';
  16094. this.fillAlpha = 1;
  16095. this.strokeAlpha = 1;
  16096. this.lineWidth = 1;
  16097. this.lineJoin = '';
  16098. this.lineCap = '';
  16099. this.miterLimit = 0;
  16100. this.dashArray = [];
  16101. this.dashPhase = 0;
  16102. this.dependencies = [];
  16103. // Clipping
  16104. this.clipId = '';
  16105. this.pendingClip = false;
  16106. this.maskId = '';
  16107. }
  16108. SVGExtraState.prototype = {
  16109. clone: function SVGExtraState_clone() {
  16110. return Object.create(this);
  16111. },
  16112. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  16113. this.x = x;
  16114. this.y = y;
  16115. }
  16116. };
  16117. return SVGExtraState;
  16118. })();
  16119. var SVGGraphics = (function SVGGraphicsClosure() {
  16120. function createScratchSVG(width, height) {
  16121. var NS = 'http://www.w3.org/2000/svg';
  16122. var svg = document.createElementNS(NS, 'svg:svg');
  16123. svg.setAttributeNS(null, 'version', '1.1');
  16124. svg.setAttributeNS(null, 'width', width + 'px');
  16125. svg.setAttributeNS(null, 'height', height + 'px');
  16126. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  16127. return svg;
  16128. }
  16129. function opListToTree(opList) {
  16130. var opTree = [];
  16131. var tmp = [];
  16132. var opListLen = opList.length;
  16133. for (var x = 0; x < opListLen; x++) {
  16134. if (opList[x].fn === 'save') {
  16135. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  16136. tmp.push(opTree);
  16137. opTree = opTree[opTree.length - 1].items;
  16138. continue;
  16139. }
  16140. if(opList[x].fn === 'restore') {
  16141. opTree = tmp.pop();
  16142. } else {
  16143. opTree.push(opList[x]);
  16144. }
  16145. }
  16146. return opTree;
  16147. }
  16148. /**
  16149. * Formats float number.
  16150. * @param value {number} number to format.
  16151. * @returns {string}
  16152. */
  16153. function pf(value) {
  16154. if (value === (value | 0)) { // integer number
  16155. return value.toString();
  16156. }
  16157. var s = value.toFixed(10);
  16158. var i = s.length - 1;
  16159. if (s[i] !== '0') {
  16160. return s;
  16161. }
  16162. // removing trailing zeros
  16163. do {
  16164. i--;
  16165. } while (s[i] === '0');
  16166. return s.substr(0, s[i] === '.' ? i : i + 1);
  16167. }
  16168. /**
  16169. * Formats transform matrix. The standard rotation, scale and translate
  16170. * matrices are replaced by their shorter forms, and for identity matrix
  16171. * returns empty string to save the memory.
  16172. * @param m {Array} matrix to format.
  16173. * @returns {string}
  16174. */
  16175. function pm(m) {
  16176. if (m[4] === 0 && m[5] === 0) {
  16177. if (m[1] === 0 && m[2] === 0) {
  16178. if (m[0] === 1 && m[3] === 1) {
  16179. return '';
  16180. }
  16181. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  16182. }
  16183. if (m[0] === m[3] && m[1] === -m[2]) {
  16184. var a = Math.acos(m[0]) * 180 / Math.PI;
  16185. return 'rotate(' + pf(a) + ')';
  16186. }
  16187. } else {
  16188. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  16189. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  16190. }
  16191. }
  16192. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  16193. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  16194. }
  16195. function SVGGraphics(commonObjs, objs) {
  16196. this.current = new SVGExtraState();
  16197. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  16198. this.transformStack = [];
  16199. this.extraStack = [];
  16200. this.commonObjs = commonObjs;
  16201. this.objs = objs;
  16202. this.pendingEOFill = false;
  16203. this.embedFonts = false;
  16204. this.embeddedFonts = {};
  16205. this.cssStyle = null;
  16206. }
  16207. var NS = 'http://www.w3.org/2000/svg';
  16208. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  16209. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  16210. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  16211. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  16212. var clipCount = 0;
  16213. var maskCount = 0;
  16214. SVGGraphics.prototype = {
  16215. save: function SVGGraphics_save() {
  16216. this.transformStack.push(this.transformMatrix);
  16217. var old = this.current;
  16218. this.extraStack.push(old);
  16219. this.current = old.clone();
  16220. },
  16221. restore: function SVGGraphics_restore() {
  16222. this.transformMatrix = this.transformStack.pop();
  16223. this.current = this.extraStack.pop();
  16224. this.tgrp = document.createElementNS(NS, 'svg:g');
  16225. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16226. this.pgrp.appendChild(this.tgrp);
  16227. },
  16228. group: function SVGGraphics_group(items) {
  16229. this.save();
  16230. this.executeOpTree(items);
  16231. this.restore();
  16232. },
  16233. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  16234. var fnArray = operatorList.fnArray;
  16235. var fnArrayLen = fnArray.length;
  16236. var argsArray = operatorList.argsArray;
  16237. var self = this;
  16238. for (var i = 0; i < fnArrayLen; i++) {
  16239. if (OPS.dependency === fnArray[i]) {
  16240. var deps = argsArray[i];
  16241. for (var n = 0, nn = deps.length; n < nn; n++) {
  16242. var obj = deps[n];
  16243. var common = obj.substring(0, 2) === 'g_';
  16244. var promise;
  16245. if (common) {
  16246. promise = new Promise(function(resolve) {
  16247. self.commonObjs.get(obj, resolve);
  16248. });
  16249. } else {
  16250. promise = new Promise(function(resolve) {
  16251. self.objs.get(obj, resolve);
  16252. });
  16253. }
  16254. this.current.dependencies.push(promise);
  16255. }
  16256. }
  16257. }
  16258. return Promise.all(this.current.dependencies);
  16259. },
  16260. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  16261. var transformMatrix = [a, b, c, d, e, f];
  16262. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  16263. transformMatrix);
  16264. this.tgrp = document.createElementNS(NS, 'svg:g');
  16265. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16266. },
  16267. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  16268. this.svg = createScratchSVG(viewport.width, viewport.height);
  16269. this.viewport = viewport;
  16270. return this.loadDependencies(operatorList).then(function () {
  16271. this.transformMatrix = IDENTITY_MATRIX;
  16272. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  16273. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  16274. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  16275. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16276. this.defs = document.createElementNS(NS, 'svg:defs');
  16277. this.pgrp.appendChild(this.defs);
  16278. this.pgrp.appendChild(this.tgrp);
  16279. this.svg.appendChild(this.pgrp);
  16280. var opTree = this.convertOpList(operatorList);
  16281. this.executeOpTree(opTree);
  16282. return this.svg;
  16283. }.bind(this));
  16284. },
  16285. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  16286. var argsArray = operatorList.argsArray;
  16287. var fnArray = operatorList.fnArray;
  16288. var fnArrayLen = fnArray.length;
  16289. var REVOPS = [];
  16290. var opList = [];
  16291. for (var op in OPS) {
  16292. REVOPS[OPS[op]] = op;
  16293. }
  16294. for (var x = 0; x < fnArrayLen; x++) {
  16295. var fnId = fnArray[x];
  16296. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  16297. }
  16298. return opListToTree(opList);
  16299. },
  16300. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  16301. var opTreeLen = opTree.length;
  16302. for(var x = 0; x < opTreeLen; x++) {
  16303. var fn = opTree[x].fn;
  16304. var fnId = opTree[x].fnId;
  16305. var args = opTree[x].args;
  16306. switch (fnId | 0) {
  16307. case OPS.beginText:
  16308. this.beginText();
  16309. break;
  16310. case OPS.setLeading:
  16311. this.setLeading(args);
  16312. break;
  16313. case OPS.setLeadingMoveText:
  16314. this.setLeadingMoveText(args[0], args[1]);
  16315. break;
  16316. case OPS.setFont:
  16317. this.setFont(args);
  16318. break;
  16319. case OPS.showText:
  16320. this.showText(args[0]);
  16321. break;
  16322. case OPS.showSpacedText:
  16323. this.showText(args[0]);
  16324. break;
  16325. case OPS.endText:
  16326. this.endText();
  16327. break;
  16328. case OPS.moveText:
  16329. this.moveText(args[0], args[1]);
  16330. break;
  16331. case OPS.setCharSpacing:
  16332. this.setCharSpacing(args[0]);
  16333. break;
  16334. case OPS.setWordSpacing:
  16335. this.setWordSpacing(args[0]);
  16336. break;
  16337. case OPS.setHScale:
  16338. this.setHScale(args[0]);
  16339. break;
  16340. case OPS.setTextMatrix:
  16341. this.setTextMatrix(args[0], args[1], args[2],
  16342. args[3], args[4], args[5]);
  16343. break;
  16344. case OPS.setLineWidth:
  16345. this.setLineWidth(args[0]);
  16346. break;
  16347. case OPS.setLineJoin:
  16348. this.setLineJoin(args[0]);
  16349. break;
  16350. case OPS.setLineCap:
  16351. this.setLineCap(args[0]);
  16352. break;
  16353. case OPS.setMiterLimit:
  16354. this.setMiterLimit(args[0]);
  16355. break;
  16356. case OPS.setFillRGBColor:
  16357. this.setFillRGBColor(args[0], args[1], args[2]);
  16358. break;
  16359. case OPS.setStrokeRGBColor:
  16360. this.setStrokeRGBColor(args[0], args[1], args[2]);
  16361. break;
  16362. case OPS.setDash:
  16363. this.setDash(args[0], args[1]);
  16364. break;
  16365. case OPS.setGState:
  16366. this.setGState(args[0]);
  16367. break;
  16368. case OPS.fill:
  16369. this.fill();
  16370. break;
  16371. case OPS.eoFill:
  16372. this.eoFill();
  16373. break;
  16374. case OPS.stroke:
  16375. this.stroke();
  16376. break;
  16377. case OPS.fillStroke:
  16378. this.fillStroke();
  16379. break;
  16380. case OPS.eoFillStroke:
  16381. this.eoFillStroke();
  16382. break;
  16383. case OPS.clip:
  16384. this.clip('nonzero');
  16385. break;
  16386. case OPS.eoClip:
  16387. this.clip('evenodd');
  16388. break;
  16389. case OPS.paintSolidColorImageMask:
  16390. this.paintSolidColorImageMask();
  16391. break;
  16392. case OPS.paintJpegXObject:
  16393. this.paintJpegXObject(args[0], args[1], args[2]);
  16394. break;
  16395. case OPS.paintImageXObject:
  16396. this.paintImageXObject(args[0]);
  16397. break;
  16398. case OPS.paintInlineImageXObject:
  16399. this.paintInlineImageXObject(args[0]);
  16400. break;
  16401. case OPS.paintImageMaskXObject:
  16402. this.paintImageMaskXObject(args[0]);
  16403. break;
  16404. case OPS.paintFormXObjectBegin:
  16405. this.paintFormXObjectBegin(args[0], args[1]);
  16406. break;
  16407. case OPS.paintFormXObjectEnd:
  16408. this.paintFormXObjectEnd();
  16409. break;
  16410. case OPS.closePath:
  16411. this.closePath();
  16412. break;
  16413. case OPS.closeStroke:
  16414. this.closeStroke();
  16415. break;
  16416. case OPS.closeFillStroke:
  16417. this.closeFillStroke();
  16418. break;
  16419. case OPS.nextLine:
  16420. this.nextLine();
  16421. break;
  16422. case OPS.transform:
  16423. this.transform(args[0], args[1], args[2], args[3],
  16424. args[4], args[5]);
  16425. break;
  16426. case OPS.constructPath:
  16427. this.constructPath(args[0], args[1]);
  16428. break;
  16429. case OPS.endPath:
  16430. this.endPath();
  16431. break;
  16432. case 92:
  16433. this.group(opTree[x].items);
  16434. break;
  16435. default:
  16436. warn('Unimplemented method '+ fn);
  16437. break;
  16438. }
  16439. }
  16440. },
  16441. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  16442. this.current.wordSpacing = wordSpacing;
  16443. },
  16444. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  16445. this.current.charSpacing = charSpacing;
  16446. },
  16447. nextLine: function SVGGraphics_nextLine() {
  16448. this.moveText(0, this.current.leading);
  16449. },
  16450. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  16451. var current = this.current;
  16452. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  16453. this.current.x = this.current.lineX = 0;
  16454. this.current.y = this.current.lineY = 0;
  16455. current.xcoords = [];
  16456. current.tspan = document.createElementNS(NS, 'svg:tspan');
  16457. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  16458. current.tspan.setAttributeNS(null, 'font-size',
  16459. pf(current.fontSize) + 'px');
  16460. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  16461. current.txtElement = document.createElementNS(NS, 'svg:text');
  16462. current.txtElement.appendChild(current.tspan);
  16463. },
  16464. beginText: function SVGGraphics_beginText() {
  16465. this.current.x = this.current.lineX = 0;
  16466. this.current.y = this.current.lineY = 0;
  16467. this.current.textMatrix = IDENTITY_MATRIX;
  16468. this.current.lineMatrix = IDENTITY_MATRIX;
  16469. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  16470. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  16471. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  16472. this.current.xcoords = [];
  16473. },
  16474. moveText: function SVGGraphics_moveText(x, y) {
  16475. var current = this.current;
  16476. this.current.x = this.current.lineX += x;
  16477. this.current.y = this.current.lineY += y;
  16478. current.xcoords = [];
  16479. current.tspan = document.createElementNS(NS, 'svg:tspan');
  16480. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  16481. current.tspan.setAttributeNS(null, 'font-size',
  16482. pf(current.fontSize) + 'px');
  16483. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  16484. },
  16485. showText: function SVGGraphics_showText(glyphs) {
  16486. var current = this.current;
  16487. var font = current.font;
  16488. var fontSize = current.fontSize;
  16489. if (fontSize === 0) {
  16490. return;
  16491. }
  16492. var charSpacing = current.charSpacing;
  16493. var wordSpacing = current.wordSpacing;
  16494. var fontDirection = current.fontDirection;
  16495. var textHScale = current.textHScale * fontDirection;
  16496. var glyphsLength = glyphs.length;
  16497. var vertical = font.vertical;
  16498. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  16499. var x = 0, i;
  16500. for (i = 0; i < glyphsLength; ++i) {
  16501. var glyph = glyphs[i];
  16502. if (glyph === null) {
  16503. // word break
  16504. x += fontDirection * wordSpacing;
  16505. continue;
  16506. } else if (isNum(glyph)) {
  16507. x += -glyph * fontSize * 0.001;
  16508. continue;
  16509. }
  16510. current.xcoords.push(current.x + x * textHScale);
  16511. var width = glyph.width;
  16512. var character = glyph.fontChar;
  16513. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  16514. x += charWidth;
  16515. current.tspan.textContent += character;
  16516. }
  16517. if (vertical) {
  16518. current.y -= x * textHScale;
  16519. } else {
  16520. current.x += x * textHScale;
  16521. }
  16522. current.tspan.setAttributeNS(null, 'x',
  16523. current.xcoords.map(pf).join(' '));
  16524. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  16525. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  16526. current.tspan.setAttributeNS(null, 'font-size',
  16527. pf(current.fontSize) + 'px');
  16528. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  16529. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  16530. }
  16531. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  16532. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  16533. }
  16534. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  16535. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  16536. }
  16537. current.txtElement.setAttributeNS(null, 'transform',
  16538. pm(current.textMatrix) +
  16539. ' scale(1, -1)' );
  16540. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  16541. current.txtElement.appendChild(current.tspan);
  16542. current.txtgrp.appendChild(current.txtElement);
  16543. this.tgrp.appendChild(current.txtElement);
  16544. },
  16545. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  16546. this.setLeading(-y);
  16547. this.moveText(x, y);
  16548. },
  16549. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  16550. if (!this.cssStyle) {
  16551. this.cssStyle = document.createElementNS(NS, 'svg:style');
  16552. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  16553. this.defs.appendChild(this.cssStyle);
  16554. }
  16555. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  16556. this.cssStyle.textContent +=
  16557. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  16558. ' src: url(' + url + '); }\n';
  16559. },
  16560. setFont: function SVGGraphics_setFont(details) {
  16561. var current = this.current;
  16562. var fontObj = this.commonObjs.get(details[0]);
  16563. var size = details[1];
  16564. this.current.font = fontObj;
  16565. if (this.embedFonts && fontObj.data &&
  16566. !this.embeddedFonts[fontObj.loadedName]) {
  16567. this.addFontStyle(fontObj);
  16568. this.embeddedFonts[fontObj.loadedName] = fontObj;
  16569. }
  16570. current.fontMatrix = (fontObj.fontMatrix ?
  16571. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  16572. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  16573. (fontObj.bold ? 'bold' : 'normal');
  16574. var italic = fontObj.italic ? 'italic' : 'normal';
  16575. if (size < 0) {
  16576. size = -size;
  16577. current.fontDirection = -1;
  16578. } else {
  16579. current.fontDirection = 1;
  16580. }
  16581. current.fontSize = size;
  16582. current.fontFamily = fontObj.loadedName;
  16583. current.fontWeight = bold;
  16584. current.fontStyle = italic;
  16585. current.tspan = document.createElementNS(NS, 'svg:tspan');
  16586. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  16587. current.xcoords = [];
  16588. },
  16589. endText: function SVGGraphics_endText() {
  16590. if (this.current.pendingClip) {
  16591. this.cgrp.appendChild(this.tgrp);
  16592. this.pgrp.appendChild(this.cgrp);
  16593. } else {
  16594. this.pgrp.appendChild(this.tgrp);
  16595. }
  16596. this.tgrp = document.createElementNS(NS, 'svg:g');
  16597. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16598. },
  16599. // Path properties
  16600. setLineWidth: function SVGGraphics_setLineWidth(width) {
  16601. this.current.lineWidth = width;
  16602. },
  16603. setLineCap: function SVGGraphics_setLineCap(style) {
  16604. this.current.lineCap = LINE_CAP_STYLES[style];
  16605. },
  16606. setLineJoin: function SVGGraphics_setLineJoin(style) {
  16607. this.current.lineJoin = LINE_JOIN_STYLES[style];
  16608. },
  16609. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  16610. this.current.miterLimit = limit;
  16611. },
  16612. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  16613. var color = Util.makeCssRgb(r, g, b);
  16614. this.current.strokeColor = color;
  16615. },
  16616. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  16617. var color = Util.makeCssRgb(r, g, b);
  16618. this.current.fillColor = color;
  16619. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  16620. this.current.xcoords = [];
  16621. },
  16622. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  16623. this.current.dashArray = dashArray;
  16624. this.current.dashPhase = dashPhase;
  16625. },
  16626. constructPath: function SVGGraphics_constructPath(ops, args) {
  16627. var current = this.current;
  16628. var x = current.x, y = current.y;
  16629. current.path = document.createElementNS(NS, 'svg:path');
  16630. var d = [];
  16631. var opLength = ops.length;
  16632. for (var i = 0, j = 0; i < opLength; i++) {
  16633. switch (ops[i] | 0) {
  16634. case OPS.rectangle:
  16635. x = args[j++];
  16636. y = args[j++];
  16637. var width = args[j++];
  16638. var height = args[j++];
  16639. var xw = x + width;
  16640. var yh = y + height;
  16641. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  16642. 'L', pf(x), pf(yh), 'Z');
  16643. break;
  16644. case OPS.moveTo:
  16645. x = args[j++];
  16646. y = args[j++];
  16647. d.push('M', pf(x), pf(y));
  16648. break;
  16649. case OPS.lineTo:
  16650. x = args[j++];
  16651. y = args[j++];
  16652. d.push('L', pf(x) , pf(y));
  16653. break;
  16654. case OPS.curveTo:
  16655. x = args[j + 4];
  16656. y = args[j + 5];
  16657. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  16658. pf(args[j + 3]), pf(x), pf(y));
  16659. j += 6;
  16660. break;
  16661. case OPS.curveTo2:
  16662. x = args[j + 2];
  16663. y = args[j + 3];
  16664. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  16665. pf(args[j + 2]), pf(args[j + 3]));
  16666. j += 4;
  16667. break;
  16668. case OPS.curveTo3:
  16669. x = args[j + 2];
  16670. y = args[j + 3];
  16671. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  16672. pf(x), pf(y));
  16673. j += 4;
  16674. break;
  16675. case OPS.closePath:
  16676. d.push('Z');
  16677. break;
  16678. }
  16679. }
  16680. current.path.setAttributeNS(null, 'd', d.join(' '));
  16681. current.path.setAttributeNS(null, 'stroke-miterlimit',
  16682. pf(current.miterLimit));
  16683. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  16684. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  16685. current.path.setAttributeNS(null, 'stroke-width',
  16686. pf(current.lineWidth) + 'px');
  16687. current.path.setAttributeNS(null, 'stroke-dasharray',
  16688. current.dashArray.map(pf).join(' '));
  16689. current.path.setAttributeNS(null, 'stroke-dashoffset',
  16690. pf(current.dashPhase) + 'px');
  16691. current.path.setAttributeNS(null, 'fill', 'none');
  16692. this.tgrp.appendChild(current.path);
  16693. if (current.pendingClip) {
  16694. this.cgrp.appendChild(this.tgrp);
  16695. this.pgrp.appendChild(this.cgrp);
  16696. } else {
  16697. this.pgrp.appendChild(this.tgrp);
  16698. }
  16699. // Saving a reference in current.element so that it can be addressed
  16700. // in 'fill' and 'stroke'
  16701. current.element = current.path;
  16702. current.setCurrentPoint(x, y);
  16703. },
  16704. endPath: function SVGGraphics_endPath() {
  16705. var current = this.current;
  16706. if (current.pendingClip) {
  16707. this.cgrp.appendChild(this.tgrp);
  16708. this.pgrp.appendChild(this.cgrp);
  16709. } else {
  16710. this.pgrp.appendChild(this.tgrp);
  16711. }
  16712. this.tgrp = document.createElementNS(NS, 'svg:g');
  16713. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16714. },
  16715. clip: function SVGGraphics_clip(type) {
  16716. var current = this.current;
  16717. // Add current path to clipping path
  16718. current.clipId = 'clippath' + clipCount;
  16719. clipCount++;
  16720. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  16721. this.clippath.setAttributeNS(null, 'id', current.clipId);
  16722. var clipElement = current.element.cloneNode();
  16723. if (type === 'evenodd') {
  16724. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  16725. } else {
  16726. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  16727. }
  16728. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  16729. this.clippath.appendChild(clipElement);
  16730. this.defs.appendChild(this.clippath);
  16731. // Create a new group with that attribute
  16732. current.pendingClip = true;
  16733. this.cgrp = document.createElementNS(NS, 'svg:g');
  16734. this.cgrp.setAttributeNS(null, 'clip-path',
  16735. 'url(#' + current.clipId + ')');
  16736. this.pgrp.appendChild(this.cgrp);
  16737. },
  16738. closePath: function SVGGraphics_closePath() {
  16739. var current = this.current;
  16740. var d = current.path.getAttributeNS(null, 'd');
  16741. d += 'Z';
  16742. current.path.setAttributeNS(null, 'd', d);
  16743. },
  16744. setLeading: function SVGGraphics_setLeading(leading) {
  16745. this.current.leading = -leading;
  16746. },
  16747. setTextRise: function SVGGraphics_setTextRise(textRise) {
  16748. this.current.textRise = textRise;
  16749. },
  16750. setHScale: function SVGGraphics_setHScale(scale) {
  16751. this.current.textHScale = scale / 100;
  16752. },
  16753. setGState: function SVGGraphics_setGState(states) {
  16754. for (var i = 0, ii = states.length; i < ii; i++) {
  16755. var state = states[i];
  16756. var key = state[0];
  16757. var value = state[1];
  16758. switch (key) {
  16759. case 'LW':
  16760. this.setLineWidth(value);
  16761. break;
  16762. case 'LC':
  16763. this.setLineCap(value);
  16764. break;
  16765. case 'LJ':
  16766. this.setLineJoin(value);
  16767. break;
  16768. case 'ML':
  16769. this.setMiterLimit(value);
  16770. break;
  16771. case 'D':
  16772. this.setDash(value[0], value[1]);
  16773. break;
  16774. case 'RI':
  16775. break;
  16776. case 'FL':
  16777. break;
  16778. case 'Font':
  16779. this.setFont(value);
  16780. break;
  16781. case 'CA':
  16782. break;
  16783. case 'ca':
  16784. break;
  16785. case 'BM':
  16786. break;
  16787. case 'SMask':
  16788. break;
  16789. }
  16790. }
  16791. },
  16792. fill: function SVGGraphics_fill() {
  16793. var current = this.current;
  16794. current.element.setAttributeNS(null, 'fill', current.fillColor);
  16795. },
  16796. stroke: function SVGGraphics_stroke() {
  16797. var current = this.current;
  16798. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  16799. current.element.setAttributeNS(null, 'fill', 'none');
  16800. },
  16801. eoFill: function SVGGraphics_eoFill() {
  16802. var current = this.current;
  16803. current.element.setAttributeNS(null, 'fill', current.fillColor);
  16804. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  16805. },
  16806. fillStroke: function SVGGraphics_fillStroke() {
  16807. // Order is important since stroke wants fill to be none.
  16808. // First stroke, then if fill needed, it will be overwritten.
  16809. this.stroke();
  16810. this.fill();
  16811. },
  16812. eoFillStroke: function SVGGraphics_eoFillStroke() {
  16813. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  16814. this.fillStroke();
  16815. },
  16816. closeStroke: function SVGGraphics_closeStroke() {
  16817. this.closePath();
  16818. this.stroke();
  16819. },
  16820. closeFillStroke: function SVGGraphics_closeFillStroke() {
  16821. this.closePath();
  16822. this.fillStroke();
  16823. },
  16824. paintSolidColorImageMask:
  16825. function SVGGraphics_paintSolidColorImageMask() {
  16826. var current = this.current;
  16827. var rect = document.createElementNS(NS, 'svg:rect');
  16828. rect.setAttributeNS(null, 'x', '0');
  16829. rect.setAttributeNS(null, 'y', '0');
  16830. rect.setAttributeNS(null, 'width', '1px');
  16831. rect.setAttributeNS(null, 'height', '1px');
  16832. rect.setAttributeNS(null, 'fill', current.fillColor);
  16833. this.tgrp.appendChild(rect);
  16834. },
  16835. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  16836. var current = this.current;
  16837. var imgObj = this.objs.get(objId);
  16838. var imgEl = document.createElementNS(NS, 'svg:image');
  16839. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  16840. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  16841. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  16842. imgEl.setAttributeNS(null, 'x', '0');
  16843. imgEl.setAttributeNS(null, 'y', pf(-h));
  16844. imgEl.setAttributeNS(null, 'transform',
  16845. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  16846. this.tgrp.appendChild(imgEl);
  16847. if (current.pendingClip) {
  16848. this.cgrp.appendChild(this.tgrp);
  16849. this.pgrp.appendChild(this.cgrp);
  16850. } else {
  16851. this.pgrp.appendChild(this.tgrp);
  16852. }
  16853. },
  16854. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  16855. var imgData = this.objs.get(objId);
  16856. if (!imgData) {
  16857. warn('Dependent image isn\'t ready yet');
  16858. return;
  16859. }
  16860. this.paintInlineImageXObject(imgData);
  16861. },
  16862. paintInlineImageXObject:
  16863. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  16864. var current = this.current;
  16865. var width = imgData.width;
  16866. var height = imgData.height;
  16867. var imgSrc = convertImgDataToPng(imgData);
  16868. var cliprect = document.createElementNS(NS, 'svg:rect');
  16869. cliprect.setAttributeNS(null, 'x', '0');
  16870. cliprect.setAttributeNS(null, 'y', '0');
  16871. cliprect.setAttributeNS(null, 'width', pf(width));
  16872. cliprect.setAttributeNS(null, 'height', pf(height));
  16873. current.element = cliprect;
  16874. this.clip('nonzero');
  16875. var imgEl = document.createElementNS(NS, 'svg:image');
  16876. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  16877. imgEl.setAttributeNS(null, 'x', '0');
  16878. imgEl.setAttributeNS(null, 'y', pf(-height));
  16879. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  16880. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  16881. imgEl.setAttributeNS(null, 'transform',
  16882. 'scale(' + pf(1 / width) + ' ' +
  16883. pf(-1 / height) + ')');
  16884. if (mask) {
  16885. mask.appendChild(imgEl);
  16886. } else {
  16887. this.tgrp.appendChild(imgEl);
  16888. }
  16889. if (current.pendingClip) {
  16890. this.cgrp.appendChild(this.tgrp);
  16891. this.pgrp.appendChild(this.cgrp);
  16892. } else {
  16893. this.pgrp.appendChild(this.tgrp);
  16894. }
  16895. },
  16896. paintImageMaskXObject:
  16897. function SVGGraphics_paintImageMaskXObject(imgData) {
  16898. var current = this.current;
  16899. var width = imgData.width;
  16900. var height = imgData.height;
  16901. var fillColor = current.fillColor;
  16902. current.maskId = 'mask' + maskCount++;
  16903. var mask = document.createElementNS(NS, 'svg:mask');
  16904. mask.setAttributeNS(null, 'id', current.maskId);
  16905. var rect = document.createElementNS(NS, 'svg:rect');
  16906. rect.setAttributeNS(null, 'x', '0');
  16907. rect.setAttributeNS(null, 'y', '0');
  16908. rect.setAttributeNS(null, 'width', pf(width));
  16909. rect.setAttributeNS(null, 'height', pf(height));
  16910. rect.setAttributeNS(null, 'fill', fillColor);
  16911. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  16912. this.defs.appendChild(mask);
  16913. this.tgrp.appendChild(rect);
  16914. this.paintInlineImageXObject(imgData, mask);
  16915. },
  16916. paintFormXObjectBegin:
  16917. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  16918. this.save();
  16919. if (isArray(matrix) && matrix.length === 6) {
  16920. this.transform(matrix[0], matrix[1], matrix[2],
  16921. matrix[3], matrix[4], matrix[5]);
  16922. }
  16923. if (isArray(bbox) && bbox.length === 4) {
  16924. var width = bbox[2] - bbox[0];
  16925. var height = bbox[3] - bbox[1];
  16926. var cliprect = document.createElementNS(NS, 'svg:rect');
  16927. cliprect.setAttributeNS(null, 'x', bbox[0]);
  16928. cliprect.setAttributeNS(null, 'y', bbox[1]);
  16929. cliprect.setAttributeNS(null, 'width', pf(width));
  16930. cliprect.setAttributeNS(null, 'height', pf(height));
  16931. this.current.element = cliprect;
  16932. this.clip('nonzero');
  16933. this.endPath();
  16934. }
  16935. },
  16936. paintFormXObjectEnd:
  16937. function SVGGraphics_paintFormXObjectEnd() {
  16938. this.restore();
  16939. }
  16940. };
  16941. return SVGGraphics;
  16942. })();
  16943. PDFJS.SVGGraphics = SVGGraphics;
  16944. exports.SVGGraphics = SVGGraphics;
  16945. }));
  16946. (function (root, factory) {
  16947. {
  16948. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  16949. root.pdfjsDisplayDOMUtils, root.pdfjsSharedGlobal);
  16950. }
  16951. }(this, function (exports, sharedUtil, displayDOMUtils, sharedGlobal) {
  16952. var Util = sharedUtil.Util;
  16953. var createPromiseCapability = sharedUtil.createPromiseCapability;
  16954. var CustomStyle = displayDOMUtils.CustomStyle;
  16955. var PDFJS = sharedGlobal.PDFJS;
  16956. /**
  16957. * Text layer render parameters.
  16958. *
  16959. * @typedef {Object} TextLayerRenderParameters
  16960. * @property {TextContent} textContent - Text content to render (the object is
  16961. * returned by the page's getTextContent() method).
  16962. * @property {HTMLElement} container - HTML element that will contain text runs.
  16963. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  16964. * layout the text runs.
  16965. * @property {Array} textDivs - (optional) HTML elements that are correspond
  16966. * the text items of the textContent input. This is output and shall be
  16967. * initially be set to empty array.
  16968. * @property {number} timeout - (optional) Delay in milliseconds before
  16969. * rendering of the text runs occurs.
  16970. */
  16971. var renderTextLayer = (function renderTextLayerClosure() {
  16972. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  16973. var NonWhitespaceRegexp = /\S/;
  16974. function isAllWhitespace(str) {
  16975. return !NonWhitespaceRegexp.test(str);
  16976. }
  16977. function appendText(textDivs, viewport, geom, styles) {
  16978. var style = styles[geom.fontName];
  16979. var textDiv = document.createElement('div');
  16980. textDivs.push(textDiv);
  16981. if (isAllWhitespace(geom.str)) {
  16982. textDiv.dataset.isWhitespace = true;
  16983. return;
  16984. }
  16985. var tx = Util.transform(viewport.transform, geom.transform);
  16986. var angle = Math.atan2(tx[1], tx[0]);
  16987. if (style.vertical) {
  16988. angle += Math.PI / 2;
  16989. }
  16990. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  16991. var fontAscent = fontHeight;
  16992. if (style.ascent) {
  16993. fontAscent = style.ascent * fontAscent;
  16994. } else if (style.descent) {
  16995. fontAscent = (1 + style.descent) * fontAscent;
  16996. }
  16997. var left;
  16998. var top;
  16999. if (angle === 0) {
  17000. left = tx[4];
  17001. top = tx[5] - fontAscent;
  17002. } else {
  17003. left = tx[4] + (fontAscent * Math.sin(angle));
  17004. top = tx[5] - (fontAscent * Math.cos(angle));
  17005. }
  17006. textDiv.style.left = left + 'px';
  17007. textDiv.style.top = top + 'px';
  17008. textDiv.style.fontSize = fontHeight + 'px';
  17009. textDiv.style.fontFamily = style.fontFamily;
  17010. textDiv.textContent = geom.str;
  17011. // |fontName| is only used by the Font Inspector. This test will succeed
  17012. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  17013. // not worth the effort to do a more accurate test.
  17014. if (PDFJS.pdfBug) {
  17015. textDiv.dataset.fontName = geom.fontName;
  17016. }
  17017. // Storing into dataset will convert number into string.
  17018. if (angle !== 0) {
  17019. textDiv.dataset.angle = angle * (180 / Math.PI);
  17020. }
  17021. // We don't bother scaling single-char text divs, because it has very
  17022. // little effect on text highlighting. This makes scrolling on docs with
  17023. // lots of such divs a lot faster.
  17024. if (geom.str.length > 1) {
  17025. if (style.vertical) {
  17026. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  17027. } else {
  17028. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  17029. }
  17030. }
  17031. }
  17032. function render(task) {
  17033. if (task._canceled) {
  17034. return;
  17035. }
  17036. var textLayerFrag = task._container;
  17037. var textDivs = task._textDivs;
  17038. var capability = task._capability;
  17039. var textDivsLength = textDivs.length;
  17040. // No point in rendering many divs as it would make the browser
  17041. // unusable even after the divs are rendered.
  17042. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  17043. capability.resolve();
  17044. return;
  17045. }
  17046. var canvas = document.createElement('canvas');
  17047. var ctx = canvas.getContext('2d', {alpha: false});
  17048. var lastFontSize;
  17049. var lastFontFamily;
  17050. for (var i = 0; i < textDivsLength; i++) {
  17051. var textDiv = textDivs[i];
  17052. if (textDiv.dataset.isWhitespace !== undefined) {
  17053. continue;
  17054. }
  17055. var fontSize = textDiv.style.fontSize;
  17056. var fontFamily = textDiv.style.fontFamily;
  17057. // Only build font string and set to context if different from last.
  17058. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  17059. ctx.font = fontSize + ' ' + fontFamily;
  17060. lastFontSize = fontSize;
  17061. lastFontFamily = fontFamily;
  17062. }
  17063. var width = ctx.measureText(textDiv.textContent).width;
  17064. if (width > 0) {
  17065. textLayerFrag.appendChild(textDiv);
  17066. var transform;
  17067. if (textDiv.dataset.canvasWidth !== undefined) {
  17068. // Dataset values come of type string.
  17069. var textScale = textDiv.dataset.canvasWidth / width;
  17070. transform = 'scaleX(' + textScale + ')';
  17071. } else {
  17072. transform = '';
  17073. }
  17074. var rotation = textDiv.dataset.angle;
  17075. if (rotation) {
  17076. transform = 'rotate(' + rotation + 'deg) ' + transform;
  17077. }
  17078. if (transform) {
  17079. CustomStyle.setProp('transform' , textDiv, transform);
  17080. }
  17081. }
  17082. }
  17083. capability.resolve();
  17084. }
  17085. /**
  17086. * Text layer rendering task.
  17087. *
  17088. * @param {TextContent} textContent
  17089. * @param {HTMLElement} container
  17090. * @param {PDFJS.PageViewport} viewport
  17091. * @param {Array} textDivs
  17092. * @private
  17093. */
  17094. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  17095. this._textContent = textContent;
  17096. this._container = container;
  17097. this._viewport = viewport;
  17098. textDivs = textDivs || [];
  17099. this._textDivs = textDivs;
  17100. this._canceled = false;
  17101. this._capability = createPromiseCapability();
  17102. this._renderTimer = null;
  17103. }
  17104. TextLayerRenderTask.prototype = {
  17105. get promise() {
  17106. return this._capability.promise;
  17107. },
  17108. cancel: function TextLayer_cancel() {
  17109. this._canceled = true;
  17110. if (this._renderTimer !== null) {
  17111. clearTimeout(this._renderTimer);
  17112. this._renderTimer = null;
  17113. }
  17114. this._capability.reject('canceled');
  17115. },
  17116. _render: function TextLayer_render(timeout) {
  17117. var textItems = this._textContent.items;
  17118. var styles = this._textContent.styles;
  17119. var textDivs = this._textDivs;
  17120. var viewport = this._viewport;
  17121. for (var i = 0, len = textItems.length; i < len; i++) {
  17122. appendText(textDivs, viewport, textItems[i], styles);
  17123. }
  17124. if (!timeout) { // Render right away
  17125. render(this);
  17126. } else { // Schedule
  17127. var self = this;
  17128. this._renderTimer = setTimeout(function() {
  17129. render(self);
  17130. self._renderTimer = null;
  17131. }, timeout);
  17132. }
  17133. }
  17134. };
  17135. /**
  17136. * Starts rendering of the text layer.
  17137. *
  17138. * @param {TextLayerRenderParameters} renderParameters
  17139. * @returns {TextLayerRenderTask}
  17140. */
  17141. function renderTextLayer(renderParameters) {
  17142. var task = new TextLayerRenderTask(renderParameters.textContent,
  17143. renderParameters.container,
  17144. renderParameters.viewport,
  17145. renderParameters.textDivs);
  17146. task._render(renderParameters.timeout);
  17147. return task;
  17148. }
  17149. return renderTextLayer;
  17150. })();
  17151. PDFJS.renderTextLayer = renderTextLayer;
  17152. exports.renderTextLayer = renderTextLayer;
  17153. }));
  17154. (function (root, factory) {
  17155. {
  17156. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  17157. }
  17158. }(this, function (exports, sharedUtil) {
  17159. var shadow = sharedUtil.shadow;
  17160. var WebGLUtils = (function WebGLUtilsClosure() {
  17161. function loadShader(gl, code, shaderType) {
  17162. var shader = gl.createShader(shaderType);
  17163. gl.shaderSource(shader, code);
  17164. gl.compileShader(shader);
  17165. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  17166. if (!compiled) {
  17167. var errorMsg = gl.getShaderInfoLog(shader);
  17168. throw new Error('Error during shader compilation: ' + errorMsg);
  17169. }
  17170. return shader;
  17171. }
  17172. function createVertexShader(gl, code) {
  17173. return loadShader(gl, code, gl.VERTEX_SHADER);
  17174. }
  17175. function createFragmentShader(gl, code) {
  17176. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  17177. }
  17178. function createProgram(gl, shaders) {
  17179. var program = gl.createProgram();
  17180. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  17181. gl.attachShader(program, shaders[i]);
  17182. }
  17183. gl.linkProgram(program);
  17184. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  17185. if (!linked) {
  17186. var errorMsg = gl.getProgramInfoLog(program);
  17187. throw new Error('Error during program linking: ' + errorMsg);
  17188. }
  17189. return program;
  17190. }
  17191. function createTexture(gl, image, textureId) {
  17192. gl.activeTexture(textureId);
  17193. var texture = gl.createTexture();
  17194. gl.bindTexture(gl.TEXTURE_2D, texture);
  17195. // Set the parameters so we can render any size image.
  17196. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  17197. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  17198. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  17199. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  17200. // Upload the image into the texture.
  17201. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  17202. return texture;
  17203. }
  17204. var currentGL, currentCanvas;
  17205. function generateGL() {
  17206. if (currentGL) {
  17207. return;
  17208. }
  17209. currentCanvas = document.createElement('canvas');
  17210. currentGL = currentCanvas.getContext('webgl',
  17211. { premultipliedalpha: false });
  17212. }
  17213. var smaskVertexShaderCode = '\
  17214. attribute vec2 a_position; \
  17215. attribute vec2 a_texCoord; \
  17216. \
  17217. uniform vec2 u_resolution; \
  17218. \
  17219. varying vec2 v_texCoord; \
  17220. \
  17221. void main() { \
  17222. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  17223. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  17224. \
  17225. v_texCoord = a_texCoord; \
  17226. } ';
  17227. var smaskFragmentShaderCode = '\
  17228. precision mediump float; \
  17229. \
  17230. uniform vec4 u_backdrop; \
  17231. uniform int u_subtype; \
  17232. uniform sampler2D u_image; \
  17233. uniform sampler2D u_mask; \
  17234. \
  17235. varying vec2 v_texCoord; \
  17236. \
  17237. void main() { \
  17238. vec4 imageColor = texture2D(u_image, v_texCoord); \
  17239. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  17240. if (u_backdrop.a > 0.0) { \
  17241. maskColor.rgb = maskColor.rgb * maskColor.a + \
  17242. u_backdrop.rgb * (1.0 - maskColor.a); \
  17243. } \
  17244. float lum; \
  17245. if (u_subtype == 0) { \
  17246. lum = maskColor.a; \
  17247. } else { \
  17248. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  17249. maskColor.b * 0.11; \
  17250. } \
  17251. imageColor.a *= lum; \
  17252. imageColor.rgb *= imageColor.a; \
  17253. gl_FragColor = imageColor; \
  17254. } ';
  17255. var smaskCache = null;
  17256. function initSmaskGL() {
  17257. var canvas, gl;
  17258. generateGL();
  17259. canvas = currentCanvas;
  17260. currentCanvas = null;
  17261. gl = currentGL;
  17262. currentGL = null;
  17263. // setup a GLSL program
  17264. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  17265. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  17266. var program = createProgram(gl, [vertexShader, fragmentShader]);
  17267. gl.useProgram(program);
  17268. var cache = {};
  17269. cache.gl = gl;
  17270. cache.canvas = canvas;
  17271. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  17272. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  17273. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  17274. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  17275. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  17276. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  17277. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  17278. // provide texture coordinates for the rectangle.
  17279. var texCoordBuffer = gl.createBuffer();
  17280. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  17281. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  17282. 0.0, 0.0,
  17283. 1.0, 0.0,
  17284. 0.0, 1.0,
  17285. 0.0, 1.0,
  17286. 1.0, 0.0,
  17287. 1.0, 1.0]), gl.STATIC_DRAW);
  17288. gl.enableVertexAttribArray(texCoordLocation);
  17289. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  17290. gl.uniform1i(texLayerLocation, 0);
  17291. gl.uniform1i(texMaskLocation, 1);
  17292. smaskCache = cache;
  17293. }
  17294. function composeSMask(layer, mask, properties) {
  17295. var width = layer.width, height = layer.height;
  17296. if (!smaskCache) {
  17297. initSmaskGL();
  17298. }
  17299. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  17300. canvas.width = width;
  17301. canvas.height = height;
  17302. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  17303. gl.uniform2f(cache.resolutionLocation, width, height);
  17304. if (properties.backdrop) {
  17305. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  17306. properties.backdrop[1], properties.backdrop[2], 1);
  17307. } else {
  17308. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  17309. }
  17310. gl.uniform1i(cache.subtypeLocation,
  17311. properties.subtype === 'Luminosity' ? 1 : 0);
  17312. // Create a textures
  17313. var texture = createTexture(gl, layer, gl.TEXTURE0);
  17314. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  17315. // Create a buffer and put a single clipspace rectangle in
  17316. // it (2 triangles)
  17317. var buffer = gl.createBuffer();
  17318. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  17319. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  17320. 0, 0,
  17321. width, 0,
  17322. 0, height,
  17323. 0, height,
  17324. width, 0,
  17325. width, height]), gl.STATIC_DRAW);
  17326. gl.enableVertexAttribArray(cache.positionLocation);
  17327. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  17328. // draw
  17329. gl.clearColor(0, 0, 0, 0);
  17330. gl.enable(gl.BLEND);
  17331. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  17332. gl.clear(gl.COLOR_BUFFER_BIT);
  17333. gl.drawArrays(gl.TRIANGLES, 0, 6);
  17334. gl.flush();
  17335. gl.deleteTexture(texture);
  17336. gl.deleteTexture(maskTexture);
  17337. gl.deleteBuffer(buffer);
  17338. return canvas;
  17339. }
  17340. var figuresVertexShaderCode = '\
  17341. attribute vec2 a_position; \
  17342. attribute vec3 a_color; \
  17343. \
  17344. uniform vec2 u_resolution; \
  17345. uniform vec2 u_scale; \
  17346. uniform vec2 u_offset; \
  17347. \
  17348. varying vec4 v_color; \
  17349. \
  17350. void main() { \
  17351. vec2 position = (a_position + u_offset) * u_scale; \
  17352. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  17353. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  17354. \
  17355. v_color = vec4(a_color / 255.0, 1.0); \
  17356. } ';
  17357. var figuresFragmentShaderCode = '\
  17358. precision mediump float; \
  17359. \
  17360. varying vec4 v_color; \
  17361. \
  17362. void main() { \
  17363. gl_FragColor = v_color; \
  17364. } ';
  17365. var figuresCache = null;
  17366. function initFiguresGL() {
  17367. var canvas, gl;
  17368. generateGL();
  17369. canvas = currentCanvas;
  17370. currentCanvas = null;
  17371. gl = currentGL;
  17372. currentGL = null;
  17373. // setup a GLSL program
  17374. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  17375. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  17376. var program = createProgram(gl, [vertexShader, fragmentShader]);
  17377. gl.useProgram(program);
  17378. var cache = {};
  17379. cache.gl = gl;
  17380. cache.canvas = canvas;
  17381. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  17382. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  17383. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  17384. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  17385. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  17386. figuresCache = cache;
  17387. }
  17388. function drawFigures(width, height, backgroundColor, figures, context) {
  17389. if (!figuresCache) {
  17390. initFiguresGL();
  17391. }
  17392. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  17393. canvas.width = width;
  17394. canvas.height = height;
  17395. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  17396. gl.uniform2f(cache.resolutionLocation, width, height);
  17397. // count triangle points
  17398. var count = 0;
  17399. var i, ii, rows;
  17400. for (i = 0, ii = figures.length; i < ii; i++) {
  17401. switch (figures[i].type) {
  17402. case 'lattice':
  17403. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  17404. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  17405. break;
  17406. case 'triangles':
  17407. count += figures[i].coords.length;
  17408. break;
  17409. }
  17410. }
  17411. // transfer data
  17412. var coords = new Float32Array(count * 2);
  17413. var colors = new Uint8Array(count * 3);
  17414. var coordsMap = context.coords, colorsMap = context.colors;
  17415. var pIndex = 0, cIndex = 0;
  17416. for (i = 0, ii = figures.length; i < ii; i++) {
  17417. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  17418. switch (figure.type) {
  17419. case 'lattice':
  17420. var cols = figure.verticesPerRow;
  17421. rows = (ps.length / cols) | 0;
  17422. for (var row = 1; row < rows; row++) {
  17423. var offset = row * cols + 1;
  17424. for (var col = 1; col < cols; col++, offset++) {
  17425. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  17426. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  17427. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  17428. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  17429. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  17430. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  17431. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  17432. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  17433. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  17434. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  17435. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  17436. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  17437. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  17438. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  17439. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  17440. coords[pIndex + 6] = coords[pIndex + 2];
  17441. coords[pIndex + 7] = coords[pIndex + 3];
  17442. coords[pIndex + 8] = coords[pIndex + 4];
  17443. coords[pIndex + 9] = coords[pIndex + 5];
  17444. coords[pIndex + 10] = coordsMap[ps[offset]];
  17445. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  17446. colors[cIndex + 9] = colors[cIndex + 3];
  17447. colors[cIndex + 10] = colors[cIndex + 4];
  17448. colors[cIndex + 11] = colors[cIndex + 5];
  17449. colors[cIndex + 12] = colors[cIndex + 6];
  17450. colors[cIndex + 13] = colors[cIndex + 7];
  17451. colors[cIndex + 14] = colors[cIndex + 8];
  17452. colors[cIndex + 15] = colorsMap[cs[offset]];
  17453. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  17454. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  17455. pIndex += 12;
  17456. cIndex += 18;
  17457. }
  17458. }
  17459. break;
  17460. case 'triangles':
  17461. for (var j = 0, jj = ps.length; j < jj; j++) {
  17462. coords[pIndex] = coordsMap[ps[j]];
  17463. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  17464. colors[cIndex] = colorsMap[cs[j]];
  17465. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  17466. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  17467. pIndex += 2;
  17468. cIndex += 3;
  17469. }
  17470. break;
  17471. }
  17472. }
  17473. // draw
  17474. if (backgroundColor) {
  17475. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  17476. backgroundColor[2] / 255, 1.0);
  17477. } else {
  17478. gl.clearColor(0, 0, 0, 0);
  17479. }
  17480. gl.clear(gl.COLOR_BUFFER_BIT);
  17481. var coordsBuffer = gl.createBuffer();
  17482. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  17483. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  17484. gl.enableVertexAttribArray(cache.positionLocation);
  17485. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  17486. var colorsBuffer = gl.createBuffer();
  17487. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  17488. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  17489. gl.enableVertexAttribArray(cache.colorLocation);
  17490. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  17491. 0, 0);
  17492. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  17493. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  17494. gl.drawArrays(gl.TRIANGLES, 0, count);
  17495. gl.flush();
  17496. gl.deleteBuffer(coordsBuffer);
  17497. gl.deleteBuffer(colorsBuffer);
  17498. return canvas;
  17499. }
  17500. function cleanup() {
  17501. if (smaskCache && smaskCache.canvas) {
  17502. smaskCache.canvas.width = 0;
  17503. smaskCache.canvas.height = 0;
  17504. }
  17505. if (figuresCache && figuresCache.canvas) {
  17506. figuresCache.canvas.width = 0;
  17507. figuresCache.canvas.height = 0;
  17508. }
  17509. smaskCache = null;
  17510. figuresCache = null;
  17511. }
  17512. return {
  17513. get isEnabled() {
  17514. if (PDFJS.disableWebGL) {
  17515. return false;
  17516. }
  17517. var enabled = false;
  17518. try {
  17519. generateGL();
  17520. enabled = !!currentGL;
  17521. } catch (e) { }
  17522. return shadow(this, 'isEnabled', enabled);
  17523. },
  17524. composeSMask: composeSMask,
  17525. drawFigures: drawFigures,
  17526. clear: cleanup
  17527. };
  17528. })();
  17529. exports.WebGLUtils = WebGLUtils;
  17530. }));
  17531. (function (root, factory) {
  17532. {
  17533. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  17534. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  17535. root.pdfjsCoreJpx);
  17536. }
  17537. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  17538. coreJpx) {
  17539. var Util = sharedUtil.Util;
  17540. var error = sharedUtil.error;
  17541. var info = sharedUtil.info;
  17542. var isArray = sharedUtil.isArray;
  17543. var shadow = sharedUtil.shadow;
  17544. var warn = sharedUtil.warn;
  17545. var Dict = corePrimitives.Dict;
  17546. var Jbig2Image = coreJbig2.Jbig2Image;
  17547. var JpegImage = coreJpg.JpegImage;
  17548. var JpxImage = coreJpx.JpxImage;
  17549. var coreParser; // see _setCoreParser below
  17550. var EOF; // = coreParser.EOF;
  17551. var Lexer; // = coreParser.Lexer;
  17552. var coreColorSpace; // see _setCoreColorSpace below
  17553. var ColorSpace; // = coreColorSpace.ColorSpace;
  17554. var Stream = (function StreamClosure() {
  17555. function Stream(arrayBuffer, start, length, dict) {
  17556. this.bytes = (arrayBuffer instanceof Uint8Array ?
  17557. arrayBuffer : new Uint8Array(arrayBuffer));
  17558. this.start = start || 0;
  17559. this.pos = this.start;
  17560. this.end = (start + length) || this.bytes.length;
  17561. this.dict = dict;
  17562. }
  17563. // required methods for a stream. if a particular stream does not
  17564. // implement these, an error should be thrown
  17565. Stream.prototype = {
  17566. get length() {
  17567. return this.end - this.start;
  17568. },
  17569. get isEmpty() {
  17570. return this.length === 0;
  17571. },
  17572. getByte: function Stream_getByte() {
  17573. if (this.pos >= this.end) {
  17574. return -1;
  17575. }
  17576. return this.bytes[this.pos++];
  17577. },
  17578. getUint16: function Stream_getUint16() {
  17579. var b0 = this.getByte();
  17580. var b1 = this.getByte();
  17581. if (b0 === -1 || b1 === -1) {
  17582. return -1;
  17583. }
  17584. return (b0 << 8) + b1;
  17585. },
  17586. getInt32: function Stream_getInt32() {
  17587. var b0 = this.getByte();
  17588. var b1 = this.getByte();
  17589. var b2 = this.getByte();
  17590. var b3 = this.getByte();
  17591. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17592. },
  17593. // returns subarray of original buffer
  17594. // should only be read
  17595. getBytes: function Stream_getBytes(length) {
  17596. var bytes = this.bytes;
  17597. var pos = this.pos;
  17598. var strEnd = this.end;
  17599. if (!length) {
  17600. return bytes.subarray(pos, strEnd);
  17601. }
  17602. var end = pos + length;
  17603. if (end > strEnd) {
  17604. end = strEnd;
  17605. }
  17606. this.pos = end;
  17607. return bytes.subarray(pos, end);
  17608. },
  17609. peekByte: function Stream_peekByte() {
  17610. var peekedByte = this.getByte();
  17611. this.pos--;
  17612. return peekedByte;
  17613. },
  17614. peekBytes: function Stream_peekBytes(length) {
  17615. var bytes = this.getBytes(length);
  17616. this.pos -= bytes.length;
  17617. return bytes;
  17618. },
  17619. skip: function Stream_skip(n) {
  17620. if (!n) {
  17621. n = 1;
  17622. }
  17623. this.pos += n;
  17624. },
  17625. reset: function Stream_reset() {
  17626. this.pos = this.start;
  17627. },
  17628. moveStart: function Stream_moveStart() {
  17629. this.start = this.pos;
  17630. },
  17631. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  17632. return new Stream(this.bytes.buffer, start, length, dict);
  17633. },
  17634. isStream: true
  17635. };
  17636. return Stream;
  17637. })();
  17638. var StringStream = (function StringStreamClosure() {
  17639. function StringStream(str) {
  17640. var length = str.length;
  17641. var bytes = new Uint8Array(length);
  17642. for (var n = 0; n < length; ++n) {
  17643. bytes[n] = str.charCodeAt(n);
  17644. }
  17645. Stream.call(this, bytes);
  17646. }
  17647. StringStream.prototype = Stream.prototype;
  17648. return StringStream;
  17649. })();
  17650. // super class for the decoding streams
  17651. var DecodeStream = (function DecodeStreamClosure() {
  17652. // Lots of DecodeStreams are created whose buffers are never used. For these
  17653. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  17654. // having special cases that would be required if we used |null| for an empty
  17655. // buffer.
  17656. var emptyBuffer = new Uint8Array(0);
  17657. function DecodeStream(maybeMinBufferLength) {
  17658. this.pos = 0;
  17659. this.bufferLength = 0;
  17660. this.eof = false;
  17661. this.buffer = emptyBuffer;
  17662. this.minBufferLength = 512;
  17663. if (maybeMinBufferLength) {
  17664. // Compute the first power of two that is as big as maybeMinBufferLength.
  17665. while (this.minBufferLength < maybeMinBufferLength) {
  17666. this.minBufferLength *= 2;
  17667. }
  17668. }
  17669. }
  17670. DecodeStream.prototype = {
  17671. get isEmpty() {
  17672. while (!this.eof && this.bufferLength === 0) {
  17673. this.readBlock();
  17674. }
  17675. return this.bufferLength === 0;
  17676. },
  17677. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  17678. var buffer = this.buffer;
  17679. if (requested <= buffer.byteLength) {
  17680. return buffer;
  17681. }
  17682. var size = this.minBufferLength;
  17683. while (size < requested) {
  17684. size *= 2;
  17685. }
  17686. var buffer2 = new Uint8Array(size);
  17687. buffer2.set(buffer);
  17688. return (this.buffer = buffer2);
  17689. },
  17690. getByte: function DecodeStream_getByte() {
  17691. var pos = this.pos;
  17692. while (this.bufferLength <= pos) {
  17693. if (this.eof) {
  17694. return -1;
  17695. }
  17696. this.readBlock();
  17697. }
  17698. return this.buffer[this.pos++];
  17699. },
  17700. getUint16: function DecodeStream_getUint16() {
  17701. var b0 = this.getByte();
  17702. var b1 = this.getByte();
  17703. if (b0 === -1 || b1 === -1) {
  17704. return -1;
  17705. }
  17706. return (b0 << 8) + b1;
  17707. },
  17708. getInt32: function DecodeStream_getInt32() {
  17709. var b0 = this.getByte();
  17710. var b1 = this.getByte();
  17711. var b2 = this.getByte();
  17712. var b3 = this.getByte();
  17713. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17714. },
  17715. getBytes: function DecodeStream_getBytes(length) {
  17716. var end, pos = this.pos;
  17717. if (length) {
  17718. this.ensureBuffer(pos + length);
  17719. end = pos + length;
  17720. while (!this.eof && this.bufferLength < end) {
  17721. this.readBlock();
  17722. }
  17723. var bufEnd = this.bufferLength;
  17724. if (end > bufEnd) {
  17725. end = bufEnd;
  17726. }
  17727. } else {
  17728. while (!this.eof) {
  17729. this.readBlock();
  17730. }
  17731. end = this.bufferLength;
  17732. }
  17733. this.pos = end;
  17734. return this.buffer.subarray(pos, end);
  17735. },
  17736. peekByte: function DecodeStream_peekByte() {
  17737. var peekedByte = this.getByte();
  17738. this.pos--;
  17739. return peekedByte;
  17740. },
  17741. peekBytes: function DecodeStream_peekBytes(length) {
  17742. var bytes = this.getBytes(length);
  17743. this.pos -= bytes.length;
  17744. return bytes;
  17745. },
  17746. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  17747. var end = start + length;
  17748. while (this.bufferLength <= end && !this.eof) {
  17749. this.readBlock();
  17750. }
  17751. return new Stream(this.buffer, start, length, dict);
  17752. },
  17753. skip: function DecodeStream_skip(n) {
  17754. if (!n) {
  17755. n = 1;
  17756. }
  17757. this.pos += n;
  17758. },
  17759. reset: function DecodeStream_reset() {
  17760. this.pos = 0;
  17761. },
  17762. getBaseStreams: function DecodeStream_getBaseStreams() {
  17763. if (this.str && this.str.getBaseStreams) {
  17764. return this.str.getBaseStreams();
  17765. }
  17766. return [];
  17767. }
  17768. };
  17769. return DecodeStream;
  17770. })();
  17771. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  17772. function StreamsSequenceStream(streams) {
  17773. this.streams = streams;
  17774. DecodeStream.call(this, /* maybeLength = */ null);
  17775. }
  17776. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  17777. StreamsSequenceStream.prototype.readBlock =
  17778. function streamSequenceStreamReadBlock() {
  17779. var streams = this.streams;
  17780. if (streams.length === 0) {
  17781. this.eof = true;
  17782. return;
  17783. }
  17784. var stream = streams.shift();
  17785. var chunk = stream.getBytes();
  17786. var bufferLength = this.bufferLength;
  17787. var newLength = bufferLength + chunk.length;
  17788. var buffer = this.ensureBuffer(newLength);
  17789. buffer.set(chunk, bufferLength);
  17790. this.bufferLength = newLength;
  17791. };
  17792. StreamsSequenceStream.prototype.getBaseStreams =
  17793. function StreamsSequenceStream_getBaseStreams() {
  17794. var baseStreams = [];
  17795. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  17796. var stream = this.streams[i];
  17797. if (stream.getBaseStreams) {
  17798. Util.appendToArray(baseStreams, stream.getBaseStreams());
  17799. }
  17800. }
  17801. return baseStreams;
  17802. };
  17803. return StreamsSequenceStream;
  17804. })();
  17805. var FlateStream = (function FlateStreamClosure() {
  17806. var codeLenCodeMap = new Int32Array([
  17807. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  17808. ]);
  17809. var lengthDecode = new Int32Array([
  17810. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  17811. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  17812. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  17813. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  17814. ]);
  17815. var distDecode = new Int32Array([
  17816. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  17817. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  17818. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  17819. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  17820. ]);
  17821. var fixedLitCodeTab = [new Int32Array([
  17822. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  17823. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  17824. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  17825. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  17826. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  17827. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  17828. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  17829. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  17830. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  17831. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  17832. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  17833. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  17834. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  17835. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  17836. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  17837. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  17838. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  17839. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  17840. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  17841. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  17842. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  17843. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  17844. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  17845. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  17846. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  17847. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  17848. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  17849. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  17850. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  17851. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  17852. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  17853. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  17854. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  17855. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  17856. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  17857. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  17858. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  17859. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  17860. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  17861. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  17862. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  17863. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  17864. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  17865. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  17866. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  17867. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  17868. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  17869. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  17870. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  17871. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  17872. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  17873. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  17874. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  17875. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  17876. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  17877. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  17878. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  17879. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  17880. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  17881. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  17882. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  17883. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  17884. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  17885. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  17886. ]), 9];
  17887. var fixedDistCodeTab = [new Int32Array([
  17888. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  17889. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  17890. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  17891. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  17892. ]), 5];
  17893. function FlateStream(str, maybeLength) {
  17894. this.str = str;
  17895. this.dict = str.dict;
  17896. var cmf = str.getByte();
  17897. var flg = str.getByte();
  17898. if (cmf === -1 || flg === -1) {
  17899. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  17900. }
  17901. if ((cmf & 0x0f) !== 0x08) {
  17902. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  17903. }
  17904. if ((((cmf << 8) + flg) % 31) !== 0) {
  17905. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  17906. }
  17907. if (flg & 0x20) {
  17908. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  17909. }
  17910. this.codeSize = 0;
  17911. this.codeBuf = 0;
  17912. DecodeStream.call(this, maybeLength);
  17913. }
  17914. FlateStream.prototype = Object.create(DecodeStream.prototype);
  17915. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  17916. var str = this.str;
  17917. var codeSize = this.codeSize;
  17918. var codeBuf = this.codeBuf;
  17919. var b;
  17920. while (codeSize < bits) {
  17921. if ((b = str.getByte()) === -1) {
  17922. error('Bad encoding in flate stream');
  17923. }
  17924. codeBuf |= b << codeSize;
  17925. codeSize += 8;
  17926. }
  17927. b = codeBuf & ((1 << bits) - 1);
  17928. this.codeBuf = codeBuf >> bits;
  17929. this.codeSize = codeSize -= bits;
  17930. return b;
  17931. };
  17932. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  17933. var str = this.str;
  17934. var codes = table[0];
  17935. var maxLen = table[1];
  17936. var codeSize = this.codeSize;
  17937. var codeBuf = this.codeBuf;
  17938. var b;
  17939. while (codeSize < maxLen) {
  17940. if ((b = str.getByte()) === -1) {
  17941. // premature end of stream. code might however still be valid.
  17942. // codeSize < codeLen check below guards against incomplete codeVal.
  17943. break;
  17944. }
  17945. codeBuf |= (b << codeSize);
  17946. codeSize += 8;
  17947. }
  17948. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  17949. var codeLen = code >> 16;
  17950. var codeVal = code & 0xffff;
  17951. if (codeLen < 1 || codeSize < codeLen) {
  17952. error('Bad encoding in flate stream');
  17953. }
  17954. this.codeBuf = (codeBuf >> codeLen);
  17955. this.codeSize = (codeSize - codeLen);
  17956. return codeVal;
  17957. };
  17958. FlateStream.prototype.generateHuffmanTable =
  17959. function flateStreamGenerateHuffmanTable(lengths) {
  17960. var n = lengths.length;
  17961. // find max code length
  17962. var maxLen = 0;
  17963. var i;
  17964. for (i = 0; i < n; ++i) {
  17965. if (lengths[i] > maxLen) {
  17966. maxLen = lengths[i];
  17967. }
  17968. }
  17969. // build the table
  17970. var size = 1 << maxLen;
  17971. var codes = new Int32Array(size);
  17972. for (var len = 1, code = 0, skip = 2;
  17973. len <= maxLen;
  17974. ++len, code <<= 1, skip <<= 1) {
  17975. for (var val = 0; val < n; ++val) {
  17976. if (lengths[val] === len) {
  17977. // bit-reverse the code
  17978. var code2 = 0;
  17979. var t = code;
  17980. for (i = 0; i < len; ++i) {
  17981. code2 = (code2 << 1) | (t & 1);
  17982. t >>= 1;
  17983. }
  17984. // fill the table entries
  17985. for (i = code2; i < size; i += skip) {
  17986. codes[i] = (len << 16) | val;
  17987. }
  17988. ++code;
  17989. }
  17990. }
  17991. }
  17992. return [codes, maxLen];
  17993. };
  17994. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  17995. var buffer, len;
  17996. var str = this.str;
  17997. // read block header
  17998. var hdr = this.getBits(3);
  17999. if (hdr & 1) {
  18000. this.eof = true;
  18001. }
  18002. hdr >>= 1;
  18003. if (hdr === 0) { // uncompressed block
  18004. var b;
  18005. if ((b = str.getByte()) === -1) {
  18006. error('Bad block header in flate stream');
  18007. }
  18008. var blockLen = b;
  18009. if ((b = str.getByte()) === -1) {
  18010. error('Bad block header in flate stream');
  18011. }
  18012. blockLen |= (b << 8);
  18013. if ((b = str.getByte()) === -1) {
  18014. error('Bad block header in flate stream');
  18015. }
  18016. var check = b;
  18017. if ((b = str.getByte()) === -1) {
  18018. error('Bad block header in flate stream');
  18019. }
  18020. check |= (b << 8);
  18021. if (check !== (~blockLen & 0xffff) &&
  18022. (blockLen !== 0 || check !== 0)) {
  18023. // Ignoring error for bad "empty" block (see issue 1277)
  18024. error('Bad uncompressed block length in flate stream');
  18025. }
  18026. this.codeBuf = 0;
  18027. this.codeSize = 0;
  18028. var bufferLength = this.bufferLength;
  18029. buffer = this.ensureBuffer(bufferLength + blockLen);
  18030. var end = bufferLength + blockLen;
  18031. this.bufferLength = end;
  18032. if (blockLen === 0) {
  18033. if (str.peekByte() === -1) {
  18034. this.eof = true;
  18035. }
  18036. } else {
  18037. for (var n = bufferLength; n < end; ++n) {
  18038. if ((b = str.getByte()) === -1) {
  18039. this.eof = true;
  18040. break;
  18041. }
  18042. buffer[n] = b;
  18043. }
  18044. }
  18045. return;
  18046. }
  18047. var litCodeTable;
  18048. var distCodeTable;
  18049. if (hdr === 1) { // compressed block, fixed codes
  18050. litCodeTable = fixedLitCodeTab;
  18051. distCodeTable = fixedDistCodeTab;
  18052. } else if (hdr === 2) { // compressed block, dynamic codes
  18053. var numLitCodes = this.getBits(5) + 257;
  18054. var numDistCodes = this.getBits(5) + 1;
  18055. var numCodeLenCodes = this.getBits(4) + 4;
  18056. // build the code lengths code table
  18057. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  18058. var i;
  18059. for (i = 0; i < numCodeLenCodes; ++i) {
  18060. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  18061. }
  18062. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  18063. // build the literal and distance code tables
  18064. len = 0;
  18065. i = 0;
  18066. var codes = numLitCodes + numDistCodes;
  18067. var codeLengths = new Uint8Array(codes);
  18068. var bitsLength, bitsOffset, what;
  18069. while (i < codes) {
  18070. var code = this.getCode(codeLenCodeTab);
  18071. if (code === 16) {
  18072. bitsLength = 2; bitsOffset = 3; what = len;
  18073. } else if (code === 17) {
  18074. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  18075. } else if (code === 18) {
  18076. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  18077. } else {
  18078. codeLengths[i++] = len = code;
  18079. continue;
  18080. }
  18081. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  18082. while (repeatLength-- > 0) {
  18083. codeLengths[i++] = what;
  18084. }
  18085. }
  18086. litCodeTable =
  18087. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  18088. distCodeTable =
  18089. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  18090. } else {
  18091. error('Unknown block type in flate stream');
  18092. }
  18093. buffer = this.buffer;
  18094. var limit = buffer ? buffer.length : 0;
  18095. var pos = this.bufferLength;
  18096. while (true) {
  18097. var code1 = this.getCode(litCodeTable);
  18098. if (code1 < 256) {
  18099. if (pos + 1 >= limit) {
  18100. buffer = this.ensureBuffer(pos + 1);
  18101. limit = buffer.length;
  18102. }
  18103. buffer[pos++] = code1;
  18104. continue;
  18105. }
  18106. if (code1 === 256) {
  18107. this.bufferLength = pos;
  18108. return;
  18109. }
  18110. code1 -= 257;
  18111. code1 = lengthDecode[code1];
  18112. var code2 = code1 >> 16;
  18113. if (code2 > 0) {
  18114. code2 = this.getBits(code2);
  18115. }
  18116. len = (code1 & 0xffff) + code2;
  18117. code1 = this.getCode(distCodeTable);
  18118. code1 = distDecode[code1];
  18119. code2 = code1 >> 16;
  18120. if (code2 > 0) {
  18121. code2 = this.getBits(code2);
  18122. }
  18123. var dist = (code1 & 0xffff) + code2;
  18124. if (pos + len >= limit) {
  18125. buffer = this.ensureBuffer(pos + len);
  18126. limit = buffer.length;
  18127. }
  18128. for (var k = 0; k < len; ++k, ++pos) {
  18129. buffer[pos] = buffer[pos - dist];
  18130. }
  18131. }
  18132. };
  18133. return FlateStream;
  18134. })();
  18135. var PredictorStream = (function PredictorStreamClosure() {
  18136. function PredictorStream(str, maybeLength, params) {
  18137. var predictor = this.predictor = params.get('Predictor') || 1;
  18138. if (predictor <= 1) {
  18139. return str; // no prediction
  18140. }
  18141. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  18142. error('Unsupported predictor: ' + predictor);
  18143. }
  18144. if (predictor === 2) {
  18145. this.readBlock = this.readBlockTiff;
  18146. } else {
  18147. this.readBlock = this.readBlockPng;
  18148. }
  18149. this.str = str;
  18150. this.dict = str.dict;
  18151. var colors = this.colors = params.get('Colors') || 1;
  18152. var bits = this.bits = params.get('BitsPerComponent') || 8;
  18153. var columns = this.columns = params.get('Columns') || 1;
  18154. this.pixBytes = (colors * bits + 7) >> 3;
  18155. this.rowBytes = (columns * colors * bits + 7) >> 3;
  18156. DecodeStream.call(this, maybeLength);
  18157. return this;
  18158. }
  18159. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  18160. PredictorStream.prototype.readBlockTiff =
  18161. function predictorStreamReadBlockTiff() {
  18162. var rowBytes = this.rowBytes;
  18163. var bufferLength = this.bufferLength;
  18164. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18165. var bits = this.bits;
  18166. var colors = this.colors;
  18167. var rawBytes = this.str.getBytes(rowBytes);
  18168. this.eof = !rawBytes.length;
  18169. if (this.eof) {
  18170. return;
  18171. }
  18172. var inbuf = 0, outbuf = 0;
  18173. var inbits = 0, outbits = 0;
  18174. var pos = bufferLength;
  18175. var i;
  18176. if (bits === 1) {
  18177. for (i = 0; i < rowBytes; ++i) {
  18178. var c = rawBytes[i];
  18179. inbuf = (inbuf << 8) | c;
  18180. // bitwise addition is exclusive or
  18181. // first shift inbuf and then add
  18182. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  18183. // truncate inbuf (assumes colors < 16)
  18184. inbuf &= 0xFFFF;
  18185. }
  18186. } else if (bits === 8) {
  18187. for (i = 0; i < colors; ++i) {
  18188. buffer[pos++] = rawBytes[i];
  18189. }
  18190. for (; i < rowBytes; ++i) {
  18191. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  18192. pos++;
  18193. }
  18194. } else {
  18195. var compArray = new Uint8Array(colors + 1);
  18196. var bitMask = (1 << bits) - 1;
  18197. var j = 0, k = bufferLength;
  18198. var columns = this.columns;
  18199. for (i = 0; i < columns; ++i) {
  18200. for (var kk = 0; kk < colors; ++kk) {
  18201. if (inbits < bits) {
  18202. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  18203. inbits += 8;
  18204. }
  18205. compArray[kk] = (compArray[kk] +
  18206. (inbuf >> (inbits - bits))) & bitMask;
  18207. inbits -= bits;
  18208. outbuf = (outbuf << bits) | compArray[kk];
  18209. outbits += bits;
  18210. if (outbits >= 8) {
  18211. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  18212. outbits -= 8;
  18213. }
  18214. }
  18215. }
  18216. if (outbits > 0) {
  18217. buffer[k++] = (outbuf << (8 - outbits)) +
  18218. (inbuf & ((1 << (8 - outbits)) - 1));
  18219. }
  18220. }
  18221. this.bufferLength += rowBytes;
  18222. };
  18223. PredictorStream.prototype.readBlockPng =
  18224. function predictorStreamReadBlockPng() {
  18225. var rowBytes = this.rowBytes;
  18226. var pixBytes = this.pixBytes;
  18227. var predictor = this.str.getByte();
  18228. var rawBytes = this.str.getBytes(rowBytes);
  18229. this.eof = !rawBytes.length;
  18230. if (this.eof) {
  18231. return;
  18232. }
  18233. var bufferLength = this.bufferLength;
  18234. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18235. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  18236. if (prevRow.length === 0) {
  18237. prevRow = new Uint8Array(rowBytes);
  18238. }
  18239. var i, j = bufferLength, up, c;
  18240. switch (predictor) {
  18241. case 0:
  18242. for (i = 0; i < rowBytes; ++i) {
  18243. buffer[j++] = rawBytes[i];
  18244. }
  18245. break;
  18246. case 1:
  18247. for (i = 0; i < pixBytes; ++i) {
  18248. buffer[j++] = rawBytes[i];
  18249. }
  18250. for (; i < rowBytes; ++i) {
  18251. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  18252. j++;
  18253. }
  18254. break;
  18255. case 2:
  18256. for (i = 0; i < rowBytes; ++i) {
  18257. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  18258. }
  18259. break;
  18260. case 3:
  18261. for (i = 0; i < pixBytes; ++i) {
  18262. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  18263. }
  18264. for (; i < rowBytes; ++i) {
  18265. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  18266. rawBytes[i]) & 0xFF;
  18267. j++;
  18268. }
  18269. break;
  18270. case 4:
  18271. // we need to save the up left pixels values. the simplest way
  18272. // is to create a new buffer
  18273. for (i = 0; i < pixBytes; ++i) {
  18274. up = prevRow[i];
  18275. c = rawBytes[i];
  18276. buffer[j++] = up + c;
  18277. }
  18278. for (; i < rowBytes; ++i) {
  18279. up = prevRow[i];
  18280. var upLeft = prevRow[i - pixBytes];
  18281. var left = buffer[j - pixBytes];
  18282. var p = left + up - upLeft;
  18283. var pa = p - left;
  18284. if (pa < 0) {
  18285. pa = -pa;
  18286. }
  18287. var pb = p - up;
  18288. if (pb < 0) {
  18289. pb = -pb;
  18290. }
  18291. var pc = p - upLeft;
  18292. if (pc < 0) {
  18293. pc = -pc;
  18294. }
  18295. c = rawBytes[i];
  18296. if (pa <= pb && pa <= pc) {
  18297. buffer[j++] = left + c;
  18298. } else if (pb <= pc) {
  18299. buffer[j++] = up + c;
  18300. } else {
  18301. buffer[j++] = upLeft + c;
  18302. }
  18303. }
  18304. break;
  18305. default:
  18306. error('Unsupported predictor: ' + predictor);
  18307. }
  18308. this.bufferLength += rowBytes;
  18309. };
  18310. return PredictorStream;
  18311. })();
  18312. /**
  18313. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  18314. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  18315. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  18316. * a library to decode these images and the stream behaves like all the other
  18317. * DecodeStreams.
  18318. */
  18319. var JpegStream = (function JpegStreamClosure() {
  18320. function JpegStream(stream, maybeLength, dict, xref) {
  18321. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  18322. // Note: this seems to mainly affect inline images.
  18323. var ch;
  18324. while ((ch = stream.getByte()) !== -1) {
  18325. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  18326. stream.skip(-1); // Reset the stream position to the SOI.
  18327. break;
  18328. }
  18329. }
  18330. this.stream = stream;
  18331. this.maybeLength = maybeLength;
  18332. this.dict = dict;
  18333. DecodeStream.call(this, maybeLength);
  18334. }
  18335. JpegStream.prototype = Object.create(DecodeStream.prototype);
  18336. Object.defineProperty(JpegStream.prototype, 'bytes', {
  18337. get: function JpegStream_bytes() {
  18338. // If this.maybeLength is null, we'll get the entire stream.
  18339. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18340. },
  18341. configurable: true
  18342. });
  18343. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  18344. if (this.bufferLength) {
  18345. return;
  18346. }
  18347. try {
  18348. var jpegImage = new JpegImage();
  18349. // checking if values needs to be transformed before conversion
  18350. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  18351. var decodeArr = this.dict.get('Decode');
  18352. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  18353. var decodeArrLength = decodeArr.length;
  18354. var transform = new Int32Array(decodeArrLength);
  18355. var transformNeeded = false;
  18356. var maxValue = (1 << bitsPerComponent) - 1;
  18357. for (var i = 0; i < decodeArrLength; i += 2) {
  18358. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  18359. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  18360. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  18361. transformNeeded = true;
  18362. }
  18363. }
  18364. if (transformNeeded) {
  18365. jpegImage.decodeTransform = transform;
  18366. }
  18367. }
  18368. jpegImage.parse(this.bytes);
  18369. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  18370. this.forceRGB);
  18371. this.buffer = data;
  18372. this.bufferLength = data.length;
  18373. this.eof = true;
  18374. } catch (e) {
  18375. error('JPEG error: ' + e);
  18376. }
  18377. };
  18378. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  18379. this.ensureBuffer();
  18380. return this.buffer;
  18381. };
  18382. JpegStream.prototype.getIR = function JpegStream_getIR() {
  18383. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  18384. };
  18385. /**
  18386. * Checks if the image can be decoded and displayed by the browser without any
  18387. * further processing such as color space conversions.
  18388. */
  18389. JpegStream.prototype.isNativelySupported =
  18390. function JpegStream_isNativelySupported(xref, res) {
  18391. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18392. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  18393. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18394. };
  18395. /**
  18396. * Checks if the image can be decoded by the browser.
  18397. */
  18398. JpegStream.prototype.isNativelyDecodable =
  18399. function JpegStream_isNativelyDecodable(xref, res) {
  18400. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18401. return (cs.numComps === 1 || cs.numComps === 3) &&
  18402. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18403. };
  18404. return JpegStream;
  18405. })();
  18406. /**
  18407. * For JPEG 2000's we use a library to decode these images and
  18408. * the stream behaves like all the other DecodeStreams.
  18409. */
  18410. var JpxStream = (function JpxStreamClosure() {
  18411. function JpxStream(stream, maybeLength, dict) {
  18412. this.stream = stream;
  18413. this.maybeLength = maybeLength;
  18414. this.dict = dict;
  18415. DecodeStream.call(this, maybeLength);
  18416. }
  18417. JpxStream.prototype = Object.create(DecodeStream.prototype);
  18418. Object.defineProperty(JpxStream.prototype, 'bytes', {
  18419. get: function JpxStream_bytes() {
  18420. // If this.maybeLength is null, we'll get the entire stream.
  18421. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18422. },
  18423. configurable: true
  18424. });
  18425. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  18426. if (this.bufferLength) {
  18427. return;
  18428. }
  18429. var jpxImage = new JpxImage();
  18430. jpxImage.parse(this.bytes);
  18431. var width = jpxImage.width;
  18432. var height = jpxImage.height;
  18433. var componentsCount = jpxImage.componentsCount;
  18434. var tileCount = jpxImage.tiles.length;
  18435. if (tileCount === 1) {
  18436. this.buffer = jpxImage.tiles[0].items;
  18437. } else {
  18438. var data = new Uint8Array(width * height * componentsCount);
  18439. for (var k = 0; k < tileCount; k++) {
  18440. var tileComponents = jpxImage.tiles[k];
  18441. var tileWidth = tileComponents.width;
  18442. var tileHeight = tileComponents.height;
  18443. var tileLeft = tileComponents.left;
  18444. var tileTop = tileComponents.top;
  18445. var src = tileComponents.items;
  18446. var srcPosition = 0;
  18447. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  18448. var imgRowSize = width * componentsCount;
  18449. var tileRowSize = tileWidth * componentsCount;
  18450. for (var j = 0; j < tileHeight; j++) {
  18451. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  18452. data.set(rowBytes, dataPosition);
  18453. srcPosition += tileRowSize;
  18454. dataPosition += imgRowSize;
  18455. }
  18456. }
  18457. this.buffer = data;
  18458. }
  18459. this.bufferLength = this.buffer.length;
  18460. this.eof = true;
  18461. };
  18462. return JpxStream;
  18463. })();
  18464. /**
  18465. * For JBIG2's we use a library to decode these images and
  18466. * the stream behaves like all the other DecodeStreams.
  18467. */
  18468. var Jbig2Stream = (function Jbig2StreamClosure() {
  18469. function Jbig2Stream(stream, maybeLength, dict) {
  18470. this.stream = stream;
  18471. this.maybeLength = maybeLength;
  18472. this.dict = dict;
  18473. DecodeStream.call(this, maybeLength);
  18474. }
  18475. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  18476. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  18477. get: function Jbig2Stream_bytes() {
  18478. // If this.maybeLength is null, we'll get the entire stream.
  18479. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18480. },
  18481. configurable: true
  18482. });
  18483. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  18484. if (this.bufferLength) {
  18485. return;
  18486. }
  18487. var jbig2Image = new Jbig2Image();
  18488. var chunks = [], xref = this.dict.xref;
  18489. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  18490. // According to the PDF specification, DecodeParms can be either
  18491. // a dictionary, or an array whose elements are dictionaries.
  18492. if (isArray(decodeParams)) {
  18493. if (decodeParams.length > 1) {
  18494. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  18495. 'not supported.');
  18496. }
  18497. decodeParams = xref.fetchIfRef(decodeParams[0]);
  18498. }
  18499. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  18500. var globalsStream = decodeParams.get('JBIG2Globals');
  18501. var globals = globalsStream.getBytes();
  18502. chunks.push({data: globals, start: 0, end: globals.length});
  18503. }
  18504. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  18505. var data = jbig2Image.parseChunks(chunks);
  18506. var dataLength = data.length;
  18507. // JBIG2 had black as 1 and white as 0, inverting the colors
  18508. for (var i = 0; i < dataLength; i++) {
  18509. data[i] ^= 0xFF;
  18510. }
  18511. this.buffer = data;
  18512. this.bufferLength = dataLength;
  18513. this.eof = true;
  18514. };
  18515. return Jbig2Stream;
  18516. })();
  18517. var DecryptStream = (function DecryptStreamClosure() {
  18518. function DecryptStream(str, maybeLength, decrypt) {
  18519. this.str = str;
  18520. this.dict = str.dict;
  18521. this.decrypt = decrypt;
  18522. this.nextChunk = null;
  18523. this.initialized = false;
  18524. DecodeStream.call(this, maybeLength);
  18525. }
  18526. var chunkSize = 512;
  18527. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  18528. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  18529. var chunk;
  18530. if (this.initialized) {
  18531. chunk = this.nextChunk;
  18532. } else {
  18533. chunk = this.str.getBytes(chunkSize);
  18534. this.initialized = true;
  18535. }
  18536. if (!chunk || chunk.length === 0) {
  18537. this.eof = true;
  18538. return;
  18539. }
  18540. this.nextChunk = this.str.getBytes(chunkSize);
  18541. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  18542. var decrypt = this.decrypt;
  18543. chunk = decrypt(chunk, !hasMoreData);
  18544. var bufferLength = this.bufferLength;
  18545. var i, n = chunk.length;
  18546. var buffer = this.ensureBuffer(bufferLength + n);
  18547. for (i = 0; i < n; i++) {
  18548. buffer[bufferLength++] = chunk[i];
  18549. }
  18550. this.bufferLength = bufferLength;
  18551. };
  18552. return DecryptStream;
  18553. })();
  18554. var Ascii85Stream = (function Ascii85StreamClosure() {
  18555. function Ascii85Stream(str, maybeLength) {
  18556. this.str = str;
  18557. this.dict = str.dict;
  18558. this.input = new Uint8Array(5);
  18559. // Most streams increase in size when decoded, but Ascii85 streams
  18560. // typically shrink by ~20%.
  18561. if (maybeLength) {
  18562. maybeLength = 0.8 * maybeLength;
  18563. }
  18564. DecodeStream.call(this, maybeLength);
  18565. }
  18566. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  18567. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  18568. var TILDA_CHAR = 0x7E; // '~'
  18569. var Z_LOWER_CHAR = 0x7A; // 'z'
  18570. var EOF = -1;
  18571. var str = this.str;
  18572. var c = str.getByte();
  18573. while (Lexer.isSpace(c)) {
  18574. c = str.getByte();
  18575. }
  18576. if (c === EOF || c === TILDA_CHAR) {
  18577. this.eof = true;
  18578. return;
  18579. }
  18580. var bufferLength = this.bufferLength, buffer;
  18581. var i;
  18582. // special code for z
  18583. if (c === Z_LOWER_CHAR) {
  18584. buffer = this.ensureBuffer(bufferLength + 4);
  18585. for (i = 0; i < 4; ++i) {
  18586. buffer[bufferLength + i] = 0;
  18587. }
  18588. this.bufferLength += 4;
  18589. } else {
  18590. var input = this.input;
  18591. input[0] = c;
  18592. for (i = 1; i < 5; ++i) {
  18593. c = str.getByte();
  18594. while (Lexer.isSpace(c)) {
  18595. c = str.getByte();
  18596. }
  18597. input[i] = c;
  18598. if (c === EOF || c === TILDA_CHAR) {
  18599. break;
  18600. }
  18601. }
  18602. buffer = this.ensureBuffer(bufferLength + i - 1);
  18603. this.bufferLength += i - 1;
  18604. // partial ending;
  18605. if (i < 5) {
  18606. for (; i < 5; ++i) {
  18607. input[i] = 0x21 + 84;
  18608. }
  18609. this.eof = true;
  18610. }
  18611. var t = 0;
  18612. for (i = 0; i < 5; ++i) {
  18613. t = t * 85 + (input[i] - 0x21);
  18614. }
  18615. for (i = 3; i >= 0; --i) {
  18616. buffer[bufferLength + i] = t & 0xFF;
  18617. t >>= 8;
  18618. }
  18619. }
  18620. };
  18621. return Ascii85Stream;
  18622. })();
  18623. var AsciiHexStream = (function AsciiHexStreamClosure() {
  18624. function AsciiHexStream(str, maybeLength) {
  18625. this.str = str;
  18626. this.dict = str.dict;
  18627. this.firstDigit = -1;
  18628. // Most streams increase in size when decoded, but AsciiHex streams shrink
  18629. // by 50%.
  18630. if (maybeLength) {
  18631. maybeLength = 0.5 * maybeLength;
  18632. }
  18633. DecodeStream.call(this, maybeLength);
  18634. }
  18635. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  18636. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  18637. var UPSTREAM_BLOCK_SIZE = 8000;
  18638. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  18639. if (!bytes.length) {
  18640. this.eof = true;
  18641. return;
  18642. }
  18643. var maxDecodeLength = (bytes.length + 1) >> 1;
  18644. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  18645. var bufferLength = this.bufferLength;
  18646. var firstDigit = this.firstDigit;
  18647. for (var i = 0, ii = bytes.length; i < ii; i++) {
  18648. var ch = bytes[i], digit;
  18649. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  18650. digit = ch & 0x0F;
  18651. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  18652. // 'A'-'Z', 'a'-'z'
  18653. digit = (ch & 0x0F) + 9;
  18654. } else if (ch === 0x3E) { // '>'
  18655. this.eof = true;
  18656. break;
  18657. } else { // probably whitespace
  18658. continue; // ignoring
  18659. }
  18660. if (firstDigit < 0) {
  18661. firstDigit = digit;
  18662. } else {
  18663. buffer[bufferLength++] = (firstDigit << 4) | digit;
  18664. firstDigit = -1;
  18665. }
  18666. }
  18667. if (firstDigit >= 0 && this.eof) {
  18668. // incomplete byte
  18669. buffer[bufferLength++] = (firstDigit << 4);
  18670. firstDigit = -1;
  18671. }
  18672. this.firstDigit = firstDigit;
  18673. this.bufferLength = bufferLength;
  18674. };
  18675. return AsciiHexStream;
  18676. })();
  18677. var RunLengthStream = (function RunLengthStreamClosure() {
  18678. function RunLengthStream(str, maybeLength) {
  18679. this.str = str;
  18680. this.dict = str.dict;
  18681. DecodeStream.call(this, maybeLength);
  18682. }
  18683. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  18684. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  18685. // The repeatHeader has following format. The first byte defines type of run
  18686. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  18687. // (in addition to the second byte from the header), n = 129 through 255 -
  18688. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  18689. var repeatHeader = this.str.getBytes(2);
  18690. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  18691. this.eof = true;
  18692. return;
  18693. }
  18694. var buffer;
  18695. var bufferLength = this.bufferLength;
  18696. var n = repeatHeader[0];
  18697. if (n < 128) {
  18698. // copy n bytes
  18699. buffer = this.ensureBuffer(bufferLength + n + 1);
  18700. buffer[bufferLength++] = repeatHeader[1];
  18701. if (n > 0) {
  18702. var source = this.str.getBytes(n);
  18703. buffer.set(source, bufferLength);
  18704. bufferLength += n;
  18705. }
  18706. } else {
  18707. n = 257 - n;
  18708. var b = repeatHeader[1];
  18709. buffer = this.ensureBuffer(bufferLength + n + 1);
  18710. for (var i = 0; i < n; i++) {
  18711. buffer[bufferLength++] = b;
  18712. }
  18713. }
  18714. this.bufferLength = bufferLength;
  18715. };
  18716. return RunLengthStream;
  18717. })();
  18718. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  18719. var ccittEOL = -2;
  18720. var twoDimPass = 0;
  18721. var twoDimHoriz = 1;
  18722. var twoDimVert0 = 2;
  18723. var twoDimVertR1 = 3;
  18724. var twoDimVertL1 = 4;
  18725. var twoDimVertR2 = 5;
  18726. var twoDimVertL2 = 6;
  18727. var twoDimVertR3 = 7;
  18728. var twoDimVertL3 = 8;
  18729. var twoDimTable = [
  18730. [-1, -1], [-1, -1], // 000000x
  18731. [7, twoDimVertL3], // 0000010
  18732. [7, twoDimVertR3], // 0000011
  18733. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  18734. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  18735. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  18736. [4, twoDimPass], [4, twoDimPass],
  18737. [4, twoDimPass], [4, twoDimPass],
  18738. [4, twoDimPass], [4, twoDimPass],
  18739. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  18740. [3, twoDimHoriz], [3, twoDimHoriz],
  18741. [3, twoDimHoriz], [3, twoDimHoriz],
  18742. [3, twoDimHoriz], [3, twoDimHoriz],
  18743. [3, twoDimHoriz], [3, twoDimHoriz],
  18744. [3, twoDimHoriz], [3, twoDimHoriz],
  18745. [3, twoDimHoriz], [3, twoDimHoriz],
  18746. [3, twoDimHoriz], [3, twoDimHoriz],
  18747. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  18748. [3, twoDimVertL1], [3, twoDimVertL1],
  18749. [3, twoDimVertL1], [3, twoDimVertL1],
  18750. [3, twoDimVertL1], [3, twoDimVertL1],
  18751. [3, twoDimVertL1], [3, twoDimVertL1],
  18752. [3, twoDimVertL1], [3, twoDimVertL1],
  18753. [3, twoDimVertL1], [3, twoDimVertL1],
  18754. [3, twoDimVertL1], [3, twoDimVertL1],
  18755. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  18756. [3, twoDimVertR1], [3, twoDimVertR1],
  18757. [3, twoDimVertR1], [3, twoDimVertR1],
  18758. [3, twoDimVertR1], [3, twoDimVertR1],
  18759. [3, twoDimVertR1], [3, twoDimVertR1],
  18760. [3, twoDimVertR1], [3, twoDimVertR1],
  18761. [3, twoDimVertR1], [3, twoDimVertR1],
  18762. [3, twoDimVertR1], [3, twoDimVertR1],
  18763. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  18764. [1, twoDimVert0], [1, twoDimVert0],
  18765. [1, twoDimVert0], [1, twoDimVert0],
  18766. [1, twoDimVert0], [1, twoDimVert0],
  18767. [1, twoDimVert0], [1, twoDimVert0],
  18768. [1, twoDimVert0], [1, twoDimVert0],
  18769. [1, twoDimVert0], [1, twoDimVert0],
  18770. [1, twoDimVert0], [1, twoDimVert0],
  18771. [1, twoDimVert0], [1, twoDimVert0],
  18772. [1, twoDimVert0], [1, twoDimVert0],
  18773. [1, twoDimVert0], [1, twoDimVert0],
  18774. [1, twoDimVert0], [1, twoDimVert0],
  18775. [1, twoDimVert0], [1, twoDimVert0],
  18776. [1, twoDimVert0], [1, twoDimVert0],
  18777. [1, twoDimVert0], [1, twoDimVert0],
  18778. [1, twoDimVert0], [1, twoDimVert0],
  18779. [1, twoDimVert0], [1, twoDimVert0],
  18780. [1, twoDimVert0], [1, twoDimVert0],
  18781. [1, twoDimVert0], [1, twoDimVert0],
  18782. [1, twoDimVert0], [1, twoDimVert0],
  18783. [1, twoDimVert0], [1, twoDimVert0],
  18784. [1, twoDimVert0], [1, twoDimVert0],
  18785. [1, twoDimVert0], [1, twoDimVert0],
  18786. [1, twoDimVert0], [1, twoDimVert0],
  18787. [1, twoDimVert0], [1, twoDimVert0],
  18788. [1, twoDimVert0], [1, twoDimVert0],
  18789. [1, twoDimVert0], [1, twoDimVert0],
  18790. [1, twoDimVert0], [1, twoDimVert0],
  18791. [1, twoDimVert0], [1, twoDimVert0],
  18792. [1, twoDimVert0], [1, twoDimVert0],
  18793. [1, twoDimVert0], [1, twoDimVert0],
  18794. [1, twoDimVert0], [1, twoDimVert0]
  18795. ];
  18796. var whiteTable1 = [
  18797. [-1, -1], // 00000
  18798. [12, ccittEOL], // 00001
  18799. [-1, -1], [-1, -1], // 0001x
  18800. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  18801. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  18802. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  18803. [11, 1792], [11, 1792], // 1000x
  18804. [12, 1984], // 10010
  18805. [12, 2048], // 10011
  18806. [12, 2112], // 10100
  18807. [12, 2176], // 10101
  18808. [12, 2240], // 10110
  18809. [12, 2304], // 10111
  18810. [11, 1856], [11, 1856], // 1100x
  18811. [11, 1920], [11, 1920], // 1101x
  18812. [12, 2368], // 11100
  18813. [12, 2432], // 11101
  18814. [12, 2496], // 11110
  18815. [12, 2560] // 11111
  18816. ];
  18817. var whiteTable2 = [
  18818. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  18819. [8, 29], [8, 29], // 00000010x
  18820. [8, 30], [8, 30], // 00000011x
  18821. [8, 45], [8, 45], // 00000100x
  18822. [8, 46], [8, 46], // 00000101x
  18823. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  18824. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  18825. [8, 47], [8, 47], // 00001010x
  18826. [8, 48], [8, 48], // 00001011x
  18827. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  18828. [6, 13], [6, 13], [6, 13], [6, 13],
  18829. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  18830. [8, 33], [8, 33], // 00010010x
  18831. [8, 34], [8, 34], // 00010011x
  18832. [8, 35], [8, 35], // 00010100x
  18833. [8, 36], [8, 36], // 00010101x
  18834. [8, 37], [8, 37], // 00010110x
  18835. [8, 38], [8, 38], // 00010111x
  18836. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  18837. [8, 31], [8, 31], // 00011010x
  18838. [8, 32], [8, 32], // 00011011x
  18839. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  18840. [6, 1], [6, 1], [6, 1], [6, 1],
  18841. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  18842. [6, 12], [6, 12], [6, 12], [6, 12],
  18843. [8, 53], [8, 53], // 00100100x
  18844. [8, 54], [8, 54], // 00100101x
  18845. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  18846. [8, 39], [8, 39], // 00101000x
  18847. [8, 40], [8, 40], // 00101001x
  18848. [8, 41], [8, 41], // 00101010x
  18849. [8, 42], [8, 42], // 00101011x
  18850. [8, 43], [8, 43], // 00101100x
  18851. [8, 44], [8, 44], // 00101101x
  18852. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  18853. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  18854. [8, 61], [8, 61], // 00110010x
  18855. [8, 62], [8, 62], // 00110011x
  18856. [8, 63], [8, 63], // 00110100x
  18857. [8, 0], [8, 0], // 00110101x
  18858. [8, 320], [8, 320], // 00110110x
  18859. [8, 384], [8, 384], // 00110111x
  18860. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  18861. [5, 10], [5, 10], [5, 10], [5, 10],
  18862. [5, 10], [5, 10], [5, 10], [5, 10],
  18863. [5, 10], [5, 10], [5, 10], [5, 10],
  18864. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  18865. [5, 11], [5, 11], [5, 11], [5, 11],
  18866. [5, 11], [5, 11], [5, 11], [5, 11],
  18867. [5, 11], [5, 11], [5, 11], [5, 11],
  18868. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  18869. [8, 59], [8, 59], // 01001010x
  18870. [8, 60], [8, 60], // 01001011x
  18871. [9, 1472], // 010011000
  18872. [9, 1536], // 010011001
  18873. [9, 1600], // 010011010
  18874. [9, 1728], // 010011011
  18875. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  18876. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  18877. [8, 49], [8, 49], // 01010010x
  18878. [8, 50], [8, 50], // 01010011x
  18879. [8, 51], [8, 51], // 01010100x
  18880. [8, 52], [8, 52], // 01010101x
  18881. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  18882. [8, 55], [8, 55], // 01011000x
  18883. [8, 56], [8, 56], // 01011001x
  18884. [8, 57], [8, 57], // 01011010x
  18885. [8, 58], [8, 58], // 01011011x
  18886. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  18887. [6, 192], [6, 192], [6, 192], [6, 192],
  18888. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  18889. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  18890. [8, 448], [8, 448], // 01100100x
  18891. [8, 512], [8, 512], // 01100101x
  18892. [9, 704], // 011001100
  18893. [9, 768], // 011001101
  18894. [8, 640], [8, 640], // 01100111x
  18895. [8, 576], [8, 576], // 01101000x
  18896. [9, 832], // 011010010
  18897. [9, 896], // 011010011
  18898. [9, 960], // 011010100
  18899. [9, 1024], // 011010101
  18900. [9, 1088], // 011010110
  18901. [9, 1152], // 011010111
  18902. [9, 1216], // 011011000
  18903. [9, 1280], // 011011001
  18904. [9, 1344], // 011011010
  18905. [9, 1408], // 011011011
  18906. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  18907. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  18908. [4, 2], [4, 2], [4, 2], [4, 2],
  18909. [4, 2], [4, 2], [4, 2], [4, 2],
  18910. [4, 2], [4, 2], [4, 2], [4, 2],
  18911. [4, 2], [4, 2], [4, 2], [4, 2],
  18912. [4, 2], [4, 2], [4, 2], [4, 2],
  18913. [4, 2], [4, 2], [4, 2], [4, 2],
  18914. [4, 2], [4, 2], [4, 2], [4, 2],
  18915. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  18916. [4, 3], [4, 3], [4, 3], [4, 3],
  18917. [4, 3], [4, 3], [4, 3], [4, 3],
  18918. [4, 3], [4, 3], [4, 3], [4, 3],
  18919. [4, 3], [4, 3], [4, 3], [4, 3],
  18920. [4, 3], [4, 3], [4, 3], [4, 3],
  18921. [4, 3], [4, 3], [4, 3], [4, 3],
  18922. [4, 3], [4, 3], [4, 3], [4, 3],
  18923. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  18924. [5, 128], [5, 128], [5, 128], [5, 128],
  18925. [5, 128], [5, 128], [5, 128], [5, 128],
  18926. [5, 128], [5, 128], [5, 128], [5, 128],
  18927. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  18928. [5, 8], [5, 8], [5, 8], [5, 8],
  18929. [5, 8], [5, 8], [5, 8], [5, 8],
  18930. [5, 8], [5, 8], [5, 8], [5, 8],
  18931. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  18932. [5, 9], [5, 9], [5, 9], [5, 9],
  18933. [5, 9], [5, 9], [5, 9], [5, 9],
  18934. [5, 9], [5, 9], [5, 9], [5, 9],
  18935. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  18936. [6, 16], [6, 16], [6, 16], [6, 16],
  18937. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  18938. [6, 17], [6, 17], [6, 17], [6, 17],
  18939. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  18940. [4, 4], [4, 4], [4, 4], [4, 4],
  18941. [4, 4], [4, 4], [4, 4], [4, 4],
  18942. [4, 4], [4, 4], [4, 4], [4, 4],
  18943. [4, 4], [4, 4], [4, 4], [4, 4],
  18944. [4, 4], [4, 4], [4, 4], [4, 4],
  18945. [4, 4], [4, 4], [4, 4], [4, 4],
  18946. [4, 4], [4, 4], [4, 4], [4, 4],
  18947. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  18948. [4, 5], [4, 5], [4, 5], [4, 5],
  18949. [4, 5], [4, 5], [4, 5], [4, 5],
  18950. [4, 5], [4, 5], [4, 5], [4, 5],
  18951. [4, 5], [4, 5], [4, 5], [4, 5],
  18952. [4, 5], [4, 5], [4, 5], [4, 5],
  18953. [4, 5], [4, 5], [4, 5], [4, 5],
  18954. [4, 5], [4, 5], [4, 5], [4, 5],
  18955. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  18956. [6, 14], [6, 14], [6, 14], [6, 14],
  18957. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  18958. [6, 15], [6, 15], [6, 15], [6, 15],
  18959. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  18960. [5, 64], [5, 64], [5, 64], [5, 64],
  18961. [5, 64], [5, 64], [5, 64], [5, 64],
  18962. [5, 64], [5, 64], [5, 64], [5, 64],
  18963. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  18964. [4, 6], [4, 6], [4, 6], [4, 6],
  18965. [4, 6], [4, 6], [4, 6], [4, 6],
  18966. [4, 6], [4, 6], [4, 6], [4, 6],
  18967. [4, 6], [4, 6], [4, 6], [4, 6],
  18968. [4, 6], [4, 6], [4, 6], [4, 6],
  18969. [4, 6], [4, 6], [4, 6], [4, 6],
  18970. [4, 6], [4, 6], [4, 6], [4, 6],
  18971. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  18972. [4, 7], [4, 7], [4, 7], [4, 7],
  18973. [4, 7], [4, 7], [4, 7], [4, 7],
  18974. [4, 7], [4, 7], [4, 7], [4, 7],
  18975. [4, 7], [4, 7], [4, 7], [4, 7],
  18976. [4, 7], [4, 7], [4, 7], [4, 7],
  18977. [4, 7], [4, 7], [4, 7], [4, 7],
  18978. [4, 7], [4, 7], [4, 7], [4, 7]
  18979. ];
  18980. var blackTable1 = [
  18981. [-1, -1], [-1, -1], // 000000000000x
  18982. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  18983. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  18984. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  18985. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  18986. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  18987. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  18988. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  18989. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  18990. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  18991. [12, 1984], [12, 1984], // 000000010010x
  18992. [12, 2048], [12, 2048], // 000000010011x
  18993. [12, 2112], [12, 2112], // 000000010100x
  18994. [12, 2176], [12, 2176], // 000000010101x
  18995. [12, 2240], [12, 2240], // 000000010110x
  18996. [12, 2304], [12, 2304], // 000000010111x
  18997. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  18998. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  18999. [12, 2368], [12, 2368], // 000000011100x
  19000. [12, 2432], [12, 2432], // 000000011101x
  19001. [12, 2496], [12, 2496], // 000000011110x
  19002. [12, 2560], [12, 2560], // 000000011111x
  19003. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  19004. [10, 18], [10, 18], [10, 18], [10, 18],
  19005. [12, 52], [12, 52], // 000000100100x
  19006. [13, 640], // 0000001001010
  19007. [13, 704], // 0000001001011
  19008. [13, 768], // 0000001001100
  19009. [13, 832], // 0000001001101
  19010. [12, 55], [12, 55], // 000000100111x
  19011. [12, 56], [12, 56], // 000000101000x
  19012. [13, 1280], // 0000001010010
  19013. [13, 1344], // 0000001010011
  19014. [13, 1408], // 0000001010100
  19015. [13, 1472], // 0000001010101
  19016. [12, 59], [12, 59], // 000000101011x
  19017. [12, 60], [12, 60], // 000000101100x
  19018. [13, 1536], // 0000001011010
  19019. [13, 1600], // 0000001011011
  19020. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  19021. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  19022. [13, 1664], // 0000001100100
  19023. [13, 1728], // 0000001100101
  19024. [12, 320], [12, 320], // 000000110011x
  19025. [12, 384], [12, 384], // 000000110100x
  19026. [12, 448], [12, 448], // 000000110101x
  19027. [13, 512], // 0000001101100
  19028. [13, 576], // 0000001101101
  19029. [12, 53], [12, 53], // 000000110111x
  19030. [12, 54], [12, 54], // 000000111000x
  19031. [13, 896], // 0000001110010
  19032. [13, 960], // 0000001110011
  19033. [13, 1024], // 0000001110100
  19034. [13, 1088], // 0000001110101
  19035. [13, 1152], // 0000001110110
  19036. [13, 1216], // 0000001110111
  19037. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  19038. [10, 64], [10, 64], [10, 64], [10, 64]
  19039. ];
  19040. var blackTable2 = [
  19041. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  19042. [8, 13], [8, 13], [8, 13], [8, 13],
  19043. [8, 13], [8, 13], [8, 13], [8, 13],
  19044. [8, 13], [8, 13], [8, 13], [8, 13],
  19045. [11, 23], [11, 23], // 00000101000x
  19046. [12, 50], // 000001010010
  19047. [12, 51], // 000001010011
  19048. [12, 44], // 000001010100
  19049. [12, 45], // 000001010101
  19050. [12, 46], // 000001010110
  19051. [12, 47], // 000001010111
  19052. [12, 57], // 000001011000
  19053. [12, 58], // 000001011001
  19054. [12, 61], // 000001011010
  19055. [12, 256], // 000001011011
  19056. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  19057. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  19058. [12, 48], // 000001100100
  19059. [12, 49], // 000001100101
  19060. [12, 62], // 000001100110
  19061. [12, 63], // 000001100111
  19062. [12, 30], // 000001101000
  19063. [12, 31], // 000001101001
  19064. [12, 32], // 000001101010
  19065. [12, 33], // 000001101011
  19066. [12, 40], // 000001101100
  19067. [12, 41], // 000001101101
  19068. [11, 22], [11, 22], // 00000110111x
  19069. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  19070. [8, 14], [8, 14], [8, 14], [8, 14],
  19071. [8, 14], [8, 14], [8, 14], [8, 14],
  19072. [8, 14], [8, 14], [8, 14], [8, 14],
  19073. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  19074. [7, 10], [7, 10], [7, 10], [7, 10],
  19075. [7, 10], [7, 10], [7, 10], [7, 10],
  19076. [7, 10], [7, 10], [7, 10], [7, 10],
  19077. [7, 10], [7, 10], [7, 10], [7, 10],
  19078. [7, 10], [7, 10], [7, 10], [7, 10],
  19079. [7, 10], [7, 10], [7, 10], [7, 10],
  19080. [7, 10], [7, 10], [7, 10], [7, 10],
  19081. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  19082. [7, 11], [7, 11], [7, 11], [7, 11],
  19083. [7, 11], [7, 11], [7, 11], [7, 11],
  19084. [7, 11], [7, 11], [7, 11], [7, 11],
  19085. [7, 11], [7, 11], [7, 11], [7, 11],
  19086. [7, 11], [7, 11], [7, 11], [7, 11],
  19087. [7, 11], [7, 11], [7, 11], [7, 11],
  19088. [7, 11], [7, 11], [7, 11], [7, 11],
  19089. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  19090. [9, 15], [9, 15], [9, 15], [9, 15],
  19091. [12, 128], // 000011001000
  19092. [12, 192], // 000011001001
  19093. [12, 26], // 000011001010
  19094. [12, 27], // 000011001011
  19095. [12, 28], // 000011001100
  19096. [12, 29], // 000011001101
  19097. [11, 19], [11, 19], // 00001100111x
  19098. [11, 20], [11, 20], // 00001101000x
  19099. [12, 34], // 000011010010
  19100. [12, 35], // 000011010011
  19101. [12, 36], // 000011010100
  19102. [12, 37], // 000011010101
  19103. [12, 38], // 000011010110
  19104. [12, 39], // 000011010111
  19105. [11, 21], [11, 21], // 00001101100x
  19106. [12, 42], // 000011011010
  19107. [12, 43], // 000011011011
  19108. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  19109. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  19110. [7, 12], [7, 12], [7, 12], [7, 12],
  19111. [7, 12], [7, 12], [7, 12], [7, 12],
  19112. [7, 12], [7, 12], [7, 12], [7, 12],
  19113. [7, 12], [7, 12], [7, 12], [7, 12],
  19114. [7, 12], [7, 12], [7, 12], [7, 12],
  19115. [7, 12], [7, 12], [7, 12], [7, 12],
  19116. [7, 12], [7, 12], [7, 12], [7, 12]
  19117. ];
  19118. var blackTable3 = [
  19119. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  19120. [6, 9], // 000100
  19121. [6, 8], // 000101
  19122. [5, 7], [5, 7], // 00011x
  19123. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  19124. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  19125. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  19126. [3, 1], [3, 1], [3, 1], [3, 1],
  19127. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  19128. [3, 4], [3, 4], [3, 4], [3, 4],
  19129. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  19130. [2, 3], [2, 3], [2, 3], [2, 3],
  19131. [2, 3], [2, 3], [2, 3], [2, 3],
  19132. [2, 3], [2, 3], [2, 3], [2, 3],
  19133. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  19134. [2, 2], [2, 2], [2, 2], [2, 2],
  19135. [2, 2], [2, 2], [2, 2], [2, 2],
  19136. [2, 2], [2, 2], [2, 2], [2, 2]
  19137. ];
  19138. function CCITTFaxStream(str, maybeLength, params) {
  19139. this.str = str;
  19140. this.dict = str.dict;
  19141. params = params || Dict.empty;
  19142. this.encoding = params.get('K') || 0;
  19143. this.eoline = params.get('EndOfLine') || false;
  19144. this.byteAlign = params.get('EncodedByteAlign') || false;
  19145. this.columns = params.get('Columns') || 1728;
  19146. this.rows = params.get('Rows') || 0;
  19147. var eoblock = params.get('EndOfBlock');
  19148. if (eoblock === null || eoblock === undefined) {
  19149. eoblock = true;
  19150. }
  19151. this.eoblock = eoblock;
  19152. this.black = params.get('BlackIs1') || false;
  19153. this.codingLine = new Uint32Array(this.columns + 1);
  19154. this.refLine = new Uint32Array(this.columns + 2);
  19155. this.codingLine[0] = this.columns;
  19156. this.codingPos = 0;
  19157. this.row = 0;
  19158. this.nextLine2D = this.encoding < 0;
  19159. this.inputBits = 0;
  19160. this.inputBuf = 0;
  19161. this.outputBits = 0;
  19162. var code1;
  19163. while ((code1 = this.lookBits(12)) === 0) {
  19164. this.eatBits(1);
  19165. }
  19166. if (code1 === 1) {
  19167. this.eatBits(12);
  19168. }
  19169. if (this.encoding > 0) {
  19170. this.nextLine2D = !this.lookBits(1);
  19171. this.eatBits(1);
  19172. }
  19173. DecodeStream.call(this, maybeLength);
  19174. }
  19175. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  19176. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  19177. while (!this.eof) {
  19178. var c = this.lookChar();
  19179. this.ensureBuffer(this.bufferLength + 1);
  19180. this.buffer[this.bufferLength++] = c;
  19181. }
  19182. };
  19183. CCITTFaxStream.prototype.addPixels =
  19184. function ccittFaxStreamAddPixels(a1, blackPixels) {
  19185. var codingLine = this.codingLine;
  19186. var codingPos = this.codingPos;
  19187. if (a1 > codingLine[codingPos]) {
  19188. if (a1 > this.columns) {
  19189. info('row is wrong length');
  19190. this.err = true;
  19191. a1 = this.columns;
  19192. }
  19193. if ((codingPos & 1) ^ blackPixels) {
  19194. ++codingPos;
  19195. }
  19196. codingLine[codingPos] = a1;
  19197. }
  19198. this.codingPos = codingPos;
  19199. };
  19200. CCITTFaxStream.prototype.addPixelsNeg =
  19201. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  19202. var codingLine = this.codingLine;
  19203. var codingPos = this.codingPos;
  19204. if (a1 > codingLine[codingPos]) {
  19205. if (a1 > this.columns) {
  19206. info('row is wrong length');
  19207. this.err = true;
  19208. a1 = this.columns;
  19209. }
  19210. if ((codingPos & 1) ^ blackPixels) {
  19211. ++codingPos;
  19212. }
  19213. codingLine[codingPos] = a1;
  19214. } else if (a1 < codingLine[codingPos]) {
  19215. if (a1 < 0) {
  19216. info('invalid code');
  19217. this.err = true;
  19218. a1 = 0;
  19219. }
  19220. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  19221. --codingPos;
  19222. }
  19223. codingLine[codingPos] = a1;
  19224. }
  19225. this.codingPos = codingPos;
  19226. };
  19227. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  19228. var refLine = this.refLine;
  19229. var codingLine = this.codingLine;
  19230. var columns = this.columns;
  19231. var refPos, blackPixels, bits, i;
  19232. if (this.outputBits === 0) {
  19233. if (this.eof) {
  19234. return null;
  19235. }
  19236. this.err = false;
  19237. var code1, code2, code3;
  19238. if (this.nextLine2D) {
  19239. for (i = 0; codingLine[i] < columns; ++i) {
  19240. refLine[i] = codingLine[i];
  19241. }
  19242. refLine[i++] = columns;
  19243. refLine[i] = columns;
  19244. codingLine[0] = 0;
  19245. this.codingPos = 0;
  19246. refPos = 0;
  19247. blackPixels = 0;
  19248. while (codingLine[this.codingPos] < columns) {
  19249. code1 = this.getTwoDimCode();
  19250. switch (code1) {
  19251. case twoDimPass:
  19252. this.addPixels(refLine[refPos + 1], blackPixels);
  19253. if (refLine[refPos + 1] < columns) {
  19254. refPos += 2;
  19255. }
  19256. break;
  19257. case twoDimHoriz:
  19258. code1 = code2 = 0;
  19259. if (blackPixels) {
  19260. do {
  19261. code1 += (code3 = this.getBlackCode());
  19262. } while (code3 >= 64);
  19263. do {
  19264. code2 += (code3 = this.getWhiteCode());
  19265. } while (code3 >= 64);
  19266. } else {
  19267. do {
  19268. code1 += (code3 = this.getWhiteCode());
  19269. } while (code3 >= 64);
  19270. do {
  19271. code2 += (code3 = this.getBlackCode());
  19272. } while (code3 >= 64);
  19273. }
  19274. this.addPixels(codingLine[this.codingPos] +
  19275. code1, blackPixels);
  19276. if (codingLine[this.codingPos] < columns) {
  19277. this.addPixels(codingLine[this.codingPos] + code2,
  19278. blackPixels ^ 1);
  19279. }
  19280. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19281. refLine[refPos] < columns) {
  19282. refPos += 2;
  19283. }
  19284. break;
  19285. case twoDimVertR3:
  19286. this.addPixels(refLine[refPos] + 3, blackPixels);
  19287. blackPixels ^= 1;
  19288. if (codingLine[this.codingPos] < columns) {
  19289. ++refPos;
  19290. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19291. refLine[refPos] < columns) {
  19292. refPos += 2;
  19293. }
  19294. }
  19295. break;
  19296. case twoDimVertR2:
  19297. this.addPixels(refLine[refPos] + 2, blackPixels);
  19298. blackPixels ^= 1;
  19299. if (codingLine[this.codingPos] < columns) {
  19300. ++refPos;
  19301. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19302. refLine[refPos] < columns) {
  19303. refPos += 2;
  19304. }
  19305. }
  19306. break;
  19307. case twoDimVertR1:
  19308. this.addPixels(refLine[refPos] + 1, blackPixels);
  19309. blackPixels ^= 1;
  19310. if (codingLine[this.codingPos] < columns) {
  19311. ++refPos;
  19312. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19313. refLine[refPos] < columns) {
  19314. refPos += 2;
  19315. }
  19316. }
  19317. break;
  19318. case twoDimVert0:
  19319. this.addPixels(refLine[refPos], blackPixels);
  19320. blackPixels ^= 1;
  19321. if (codingLine[this.codingPos] < columns) {
  19322. ++refPos;
  19323. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19324. refLine[refPos] < columns) {
  19325. refPos += 2;
  19326. }
  19327. }
  19328. break;
  19329. case twoDimVertL3:
  19330. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  19331. blackPixels ^= 1;
  19332. if (codingLine[this.codingPos] < columns) {
  19333. if (refPos > 0) {
  19334. --refPos;
  19335. } else {
  19336. ++refPos;
  19337. }
  19338. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19339. refLine[refPos] < columns) {
  19340. refPos += 2;
  19341. }
  19342. }
  19343. break;
  19344. case twoDimVertL2:
  19345. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  19346. blackPixels ^= 1;
  19347. if (codingLine[this.codingPos] < columns) {
  19348. if (refPos > 0) {
  19349. --refPos;
  19350. } else {
  19351. ++refPos;
  19352. }
  19353. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19354. refLine[refPos] < columns) {
  19355. refPos += 2;
  19356. }
  19357. }
  19358. break;
  19359. case twoDimVertL1:
  19360. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  19361. blackPixels ^= 1;
  19362. if (codingLine[this.codingPos] < columns) {
  19363. if (refPos > 0) {
  19364. --refPos;
  19365. } else {
  19366. ++refPos;
  19367. }
  19368. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19369. refLine[refPos] < columns) {
  19370. refPos += 2;
  19371. }
  19372. }
  19373. break;
  19374. case EOF:
  19375. this.addPixels(columns, 0);
  19376. this.eof = true;
  19377. break;
  19378. default:
  19379. info('bad 2d code');
  19380. this.addPixels(columns, 0);
  19381. this.err = true;
  19382. }
  19383. }
  19384. } else {
  19385. codingLine[0] = 0;
  19386. this.codingPos = 0;
  19387. blackPixels = 0;
  19388. while (codingLine[this.codingPos] < columns) {
  19389. code1 = 0;
  19390. if (blackPixels) {
  19391. do {
  19392. code1 += (code3 = this.getBlackCode());
  19393. } while (code3 >= 64);
  19394. } else {
  19395. do {
  19396. code1 += (code3 = this.getWhiteCode());
  19397. } while (code3 >= 64);
  19398. }
  19399. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  19400. blackPixels ^= 1;
  19401. }
  19402. }
  19403. var gotEOL = false;
  19404. if (this.byteAlign) {
  19405. this.inputBits &= ~7;
  19406. }
  19407. if (!this.eoblock && this.row === this.rows - 1) {
  19408. this.eof = true;
  19409. } else {
  19410. code1 = this.lookBits(12);
  19411. if (this.eoline) {
  19412. while (code1 !== EOF && code1 !== 1) {
  19413. this.eatBits(1);
  19414. code1 = this.lookBits(12);
  19415. }
  19416. } else {
  19417. while (code1 === 0) {
  19418. this.eatBits(1);
  19419. code1 = this.lookBits(12);
  19420. }
  19421. }
  19422. if (code1 === 1) {
  19423. this.eatBits(12);
  19424. gotEOL = true;
  19425. } else if (code1 === EOF) {
  19426. this.eof = true;
  19427. }
  19428. }
  19429. if (!this.eof && this.encoding > 0) {
  19430. this.nextLine2D = !this.lookBits(1);
  19431. this.eatBits(1);
  19432. }
  19433. if (this.eoblock && gotEOL && this.byteAlign) {
  19434. code1 = this.lookBits(12);
  19435. if (code1 === 1) {
  19436. this.eatBits(12);
  19437. if (this.encoding > 0) {
  19438. this.lookBits(1);
  19439. this.eatBits(1);
  19440. }
  19441. if (this.encoding >= 0) {
  19442. for (i = 0; i < 4; ++i) {
  19443. code1 = this.lookBits(12);
  19444. if (code1 !== 1) {
  19445. info('bad rtc code: ' + code1);
  19446. }
  19447. this.eatBits(12);
  19448. if (this.encoding > 0) {
  19449. this.lookBits(1);
  19450. this.eatBits(1);
  19451. }
  19452. }
  19453. }
  19454. this.eof = true;
  19455. }
  19456. } else if (this.err && this.eoline) {
  19457. while (true) {
  19458. code1 = this.lookBits(13);
  19459. if (code1 === EOF) {
  19460. this.eof = true;
  19461. return null;
  19462. }
  19463. if ((code1 >> 1) === 1) {
  19464. break;
  19465. }
  19466. this.eatBits(1);
  19467. }
  19468. this.eatBits(12);
  19469. if (this.encoding > 0) {
  19470. this.eatBits(1);
  19471. this.nextLine2D = !(code1 & 1);
  19472. }
  19473. }
  19474. if (codingLine[0] > 0) {
  19475. this.outputBits = codingLine[this.codingPos = 0];
  19476. } else {
  19477. this.outputBits = codingLine[this.codingPos = 1];
  19478. }
  19479. this.row++;
  19480. }
  19481. var c;
  19482. if (this.outputBits >= 8) {
  19483. c = (this.codingPos & 1) ? 0 : 0xFF;
  19484. this.outputBits -= 8;
  19485. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  19486. this.codingPos++;
  19487. this.outputBits = (codingLine[this.codingPos] -
  19488. codingLine[this.codingPos - 1]);
  19489. }
  19490. } else {
  19491. bits = 8;
  19492. c = 0;
  19493. do {
  19494. if (this.outputBits > bits) {
  19495. c <<= bits;
  19496. if (!(this.codingPos & 1)) {
  19497. c |= 0xFF >> (8 - bits);
  19498. }
  19499. this.outputBits -= bits;
  19500. bits = 0;
  19501. } else {
  19502. c <<= this.outputBits;
  19503. if (!(this.codingPos & 1)) {
  19504. c |= 0xFF >> (8 - this.outputBits);
  19505. }
  19506. bits -= this.outputBits;
  19507. this.outputBits = 0;
  19508. if (codingLine[this.codingPos] < columns) {
  19509. this.codingPos++;
  19510. this.outputBits = (codingLine[this.codingPos] -
  19511. codingLine[this.codingPos - 1]);
  19512. } else if (bits > 0) {
  19513. c <<= bits;
  19514. bits = 0;
  19515. }
  19516. }
  19517. } while (bits);
  19518. }
  19519. if (this.black) {
  19520. c ^= 0xFF;
  19521. }
  19522. return c;
  19523. };
  19524. // This functions returns the code found from the table.
  19525. // The start and end parameters set the boundaries for searching the table.
  19526. // The limit parameter is optional. Function returns an array with three
  19527. // values. The first array element indicates whether a valid code is being
  19528. // returned. The second array element is the actual code. The third array
  19529. // element indicates whether EOF was reached.
  19530. CCITTFaxStream.prototype.findTableCode =
  19531. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  19532. var limitValue = limit || 0;
  19533. for (var i = start; i <= end; ++i) {
  19534. var code = this.lookBits(i);
  19535. if (code === EOF) {
  19536. return [true, 1, false];
  19537. }
  19538. if (i < end) {
  19539. code <<= end - i;
  19540. }
  19541. if (!limitValue || code >= limitValue) {
  19542. var p = table[code - limitValue];
  19543. if (p[0] === i) {
  19544. this.eatBits(i);
  19545. return [true, p[1], true];
  19546. }
  19547. }
  19548. }
  19549. return [false, 0, false];
  19550. };
  19551. CCITTFaxStream.prototype.getTwoDimCode =
  19552. function ccittFaxStreamGetTwoDimCode() {
  19553. var code = 0;
  19554. var p;
  19555. if (this.eoblock) {
  19556. code = this.lookBits(7);
  19557. p = twoDimTable[code];
  19558. if (p && p[0] > 0) {
  19559. this.eatBits(p[0]);
  19560. return p[1];
  19561. }
  19562. } else {
  19563. var result = this.findTableCode(1, 7, twoDimTable);
  19564. if (result[0] && result[2]) {
  19565. return result[1];
  19566. }
  19567. }
  19568. info('Bad two dim code');
  19569. return EOF;
  19570. };
  19571. CCITTFaxStream.prototype.getWhiteCode =
  19572. function ccittFaxStreamGetWhiteCode() {
  19573. var code = 0;
  19574. var p;
  19575. if (this.eoblock) {
  19576. code = this.lookBits(12);
  19577. if (code === EOF) {
  19578. return 1;
  19579. }
  19580. if ((code >> 5) === 0) {
  19581. p = whiteTable1[code];
  19582. } else {
  19583. p = whiteTable2[code >> 3];
  19584. }
  19585. if (p[0] > 0) {
  19586. this.eatBits(p[0]);
  19587. return p[1];
  19588. }
  19589. } else {
  19590. var result = this.findTableCode(1, 9, whiteTable2);
  19591. if (result[0]) {
  19592. return result[1];
  19593. }
  19594. result = this.findTableCode(11, 12, whiteTable1);
  19595. if (result[0]) {
  19596. return result[1];
  19597. }
  19598. }
  19599. info('bad white code');
  19600. this.eatBits(1);
  19601. return 1;
  19602. };
  19603. CCITTFaxStream.prototype.getBlackCode =
  19604. function ccittFaxStreamGetBlackCode() {
  19605. var code, p;
  19606. if (this.eoblock) {
  19607. code = this.lookBits(13);
  19608. if (code === EOF) {
  19609. return 1;
  19610. }
  19611. if ((code >> 7) === 0) {
  19612. p = blackTable1[code];
  19613. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  19614. p = blackTable2[(code >> 1) - 64];
  19615. } else {
  19616. p = blackTable3[code >> 7];
  19617. }
  19618. if (p[0] > 0) {
  19619. this.eatBits(p[0]);
  19620. return p[1];
  19621. }
  19622. } else {
  19623. var result = this.findTableCode(2, 6, blackTable3);
  19624. if (result[0]) {
  19625. return result[1];
  19626. }
  19627. result = this.findTableCode(7, 12, blackTable2, 64);
  19628. if (result[0]) {
  19629. return result[1];
  19630. }
  19631. result = this.findTableCode(10, 13, blackTable1);
  19632. if (result[0]) {
  19633. return result[1];
  19634. }
  19635. }
  19636. info('bad black code');
  19637. this.eatBits(1);
  19638. return 1;
  19639. };
  19640. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  19641. var c;
  19642. while (this.inputBits < n) {
  19643. if ((c = this.str.getByte()) === -1) {
  19644. if (this.inputBits === 0) {
  19645. return EOF;
  19646. }
  19647. return ((this.inputBuf << (n - this.inputBits)) &
  19648. (0xFFFF >> (16 - n)));
  19649. }
  19650. this.inputBuf = (this.inputBuf << 8) + c;
  19651. this.inputBits += 8;
  19652. }
  19653. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  19654. };
  19655. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  19656. if ((this.inputBits -= n) < 0) {
  19657. this.inputBits = 0;
  19658. }
  19659. };
  19660. return CCITTFaxStream;
  19661. })();
  19662. var LZWStream = (function LZWStreamClosure() {
  19663. function LZWStream(str, maybeLength, earlyChange) {
  19664. this.str = str;
  19665. this.dict = str.dict;
  19666. this.cachedData = 0;
  19667. this.bitsCached = 0;
  19668. var maxLzwDictionarySize = 4096;
  19669. var lzwState = {
  19670. earlyChange: earlyChange,
  19671. codeLength: 9,
  19672. nextCode: 258,
  19673. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  19674. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  19675. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  19676. currentSequence: new Uint8Array(maxLzwDictionarySize),
  19677. currentSequenceLength: 0
  19678. };
  19679. for (var i = 0; i < 256; ++i) {
  19680. lzwState.dictionaryValues[i] = i;
  19681. lzwState.dictionaryLengths[i] = 1;
  19682. }
  19683. this.lzwState = lzwState;
  19684. DecodeStream.call(this, maybeLength);
  19685. }
  19686. LZWStream.prototype = Object.create(DecodeStream.prototype);
  19687. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  19688. var bitsCached = this.bitsCached;
  19689. var cachedData = this.cachedData;
  19690. while (bitsCached < n) {
  19691. var c = this.str.getByte();
  19692. if (c === -1) {
  19693. this.eof = true;
  19694. return null;
  19695. }
  19696. cachedData = (cachedData << 8) | c;
  19697. bitsCached += 8;
  19698. }
  19699. this.bitsCached = (bitsCached -= n);
  19700. this.cachedData = cachedData;
  19701. this.lastCode = null;
  19702. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  19703. };
  19704. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  19705. var blockSize = 512;
  19706. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  19707. var i, j, q;
  19708. var lzwState = this.lzwState;
  19709. if (!lzwState) {
  19710. return; // eof was found
  19711. }
  19712. var earlyChange = lzwState.earlyChange;
  19713. var nextCode = lzwState.nextCode;
  19714. var dictionaryValues = lzwState.dictionaryValues;
  19715. var dictionaryLengths = lzwState.dictionaryLengths;
  19716. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  19717. var codeLength = lzwState.codeLength;
  19718. var prevCode = lzwState.prevCode;
  19719. var currentSequence = lzwState.currentSequence;
  19720. var currentSequenceLength = lzwState.currentSequenceLength;
  19721. var decodedLength = 0;
  19722. var currentBufferLength = this.bufferLength;
  19723. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  19724. for (i = 0; i < blockSize; i++) {
  19725. var code = this.readBits(codeLength);
  19726. var hasPrev = currentSequenceLength > 0;
  19727. if (code < 256) {
  19728. currentSequence[0] = code;
  19729. currentSequenceLength = 1;
  19730. } else if (code >= 258) {
  19731. if (code < nextCode) {
  19732. currentSequenceLength = dictionaryLengths[code];
  19733. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  19734. currentSequence[j] = dictionaryValues[q];
  19735. q = dictionaryPrevCodes[q];
  19736. }
  19737. } else {
  19738. currentSequence[currentSequenceLength++] = currentSequence[0];
  19739. }
  19740. } else if (code === 256) {
  19741. codeLength = 9;
  19742. nextCode = 258;
  19743. currentSequenceLength = 0;
  19744. continue;
  19745. } else {
  19746. this.eof = true;
  19747. delete this.lzwState;
  19748. break;
  19749. }
  19750. if (hasPrev) {
  19751. dictionaryPrevCodes[nextCode] = prevCode;
  19752. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  19753. dictionaryValues[nextCode] = currentSequence[0];
  19754. nextCode++;
  19755. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  19756. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  19757. 0.6931471805599453 + 1, 12) | 0;
  19758. }
  19759. prevCode = code;
  19760. decodedLength += currentSequenceLength;
  19761. if (estimatedDecodedSize < decodedLength) {
  19762. do {
  19763. estimatedDecodedSize += decodedSizeDelta;
  19764. } while (estimatedDecodedSize < decodedLength);
  19765. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  19766. }
  19767. for (j = 0; j < currentSequenceLength; j++) {
  19768. buffer[currentBufferLength++] = currentSequence[j];
  19769. }
  19770. }
  19771. lzwState.nextCode = nextCode;
  19772. lzwState.codeLength = codeLength;
  19773. lzwState.prevCode = prevCode;
  19774. lzwState.currentSequenceLength = currentSequenceLength;
  19775. this.bufferLength = currentBufferLength;
  19776. };
  19777. return LZWStream;
  19778. })();
  19779. var NullStream = (function NullStreamClosure() {
  19780. function NullStream() {
  19781. Stream.call(this, new Uint8Array(0));
  19782. }
  19783. NullStream.prototype = Stream.prototype;
  19784. return NullStream;
  19785. })();
  19786. // TODO refactor to remove dependency on parser.js
  19787. function _setCoreParser(coreParser_) {
  19788. coreParser = coreParser_;
  19789. EOF = coreParser_.EOF;
  19790. Lexer = coreParser_.Lexer;
  19791. }
  19792. exports._setCoreParser = _setCoreParser;
  19793. // TODO refactor to remove dependency on colorspace.js
  19794. function _setCoreColorSpace(coreColorSpace_) {
  19795. coreColorSpace = coreColorSpace_;
  19796. ColorSpace = coreColorSpace_.ColorSpace;
  19797. }
  19798. exports._setCoreColorSpace = _setCoreColorSpace;
  19799. exports.Ascii85Stream = Ascii85Stream;
  19800. exports.AsciiHexStream = AsciiHexStream;
  19801. exports.CCITTFaxStream = CCITTFaxStream;
  19802. exports.DecryptStream = DecryptStream;
  19803. exports.DecodeStream = DecodeStream;
  19804. exports.FlateStream = FlateStream;
  19805. exports.Jbig2Stream = Jbig2Stream;
  19806. exports.JpegStream = JpegStream;
  19807. exports.JpxStream = JpxStream;
  19808. exports.NullStream = NullStream;
  19809. exports.PredictorStream = PredictorStream;
  19810. exports.RunLengthStream = RunLengthStream;
  19811. exports.Stream = Stream;
  19812. exports.StreamsSequenceStream = StreamsSequenceStream;
  19813. exports.StringStream = StringStream;
  19814. exports.LZWStream = LZWStream;
  19815. }));
  19816. (function (root, factory) {
  19817. {
  19818. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  19819. root.pdfjsDisplayWebGL);
  19820. }
  19821. }(this, function (exports, sharedUtil, displayWebGL) {
  19822. var Util = sharedUtil.Util;
  19823. var info = sharedUtil.info;
  19824. var isArray = sharedUtil.isArray;
  19825. var error = sharedUtil.error;
  19826. var WebGLUtils = displayWebGL.WebGLUtils;
  19827. var ShadingIRs = {};
  19828. ShadingIRs.RadialAxial = {
  19829. fromIR: function RadialAxial_fromIR(raw) {
  19830. var type = raw[1];
  19831. var colorStops = raw[2];
  19832. var p0 = raw[3];
  19833. var p1 = raw[4];
  19834. var r0 = raw[5];
  19835. var r1 = raw[6];
  19836. return {
  19837. type: 'Pattern',
  19838. getPattern: function RadialAxial_getPattern(ctx) {
  19839. var grad;
  19840. if (type === 'axial') {
  19841. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  19842. } else if (type === 'radial') {
  19843. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  19844. }
  19845. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  19846. var c = colorStops[i];
  19847. grad.addColorStop(c[0], c[1]);
  19848. }
  19849. return grad;
  19850. }
  19851. };
  19852. }
  19853. };
  19854. var createMeshCanvas = (function createMeshCanvasClosure() {
  19855. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  19856. // Very basic Gouraud-shaded triangle rasterization algorithm.
  19857. var coords = context.coords, colors = context.colors;
  19858. var bytes = data.data, rowSize = data.width * 4;
  19859. var tmp;
  19860. if (coords[p1 + 1] > coords[p2 + 1]) {
  19861. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  19862. }
  19863. if (coords[p2 + 1] > coords[p3 + 1]) {
  19864. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  19865. }
  19866. if (coords[p1 + 1] > coords[p2 + 1]) {
  19867. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  19868. }
  19869. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  19870. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  19871. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  19872. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  19873. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  19874. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  19875. if (y1 >= y3) {
  19876. return;
  19877. }
  19878. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  19879. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  19880. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  19881. var minY = Math.round(y1), maxY = Math.round(y3);
  19882. var xa, car, cag, cab;
  19883. var xb, cbr, cbg, cbb;
  19884. var k;
  19885. for (var y = minY; y <= maxY; y++) {
  19886. if (y < y2) {
  19887. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  19888. xa = x1 - (x1 - x2) * k;
  19889. car = c1r - (c1r - c2r) * k;
  19890. cag = c1g - (c1g - c2g) * k;
  19891. cab = c1b - (c1b - c2b) * k;
  19892. } else {
  19893. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  19894. xa = x2 - (x2 - x3) * k;
  19895. car = c2r - (c2r - c3r) * k;
  19896. cag = c2g - (c2g - c3g) * k;
  19897. cab = c2b - (c2b - c3b) * k;
  19898. }
  19899. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  19900. xb = x1 - (x1 - x3) * k;
  19901. cbr = c1r - (c1r - c3r) * k;
  19902. cbg = c1g - (c1g - c3g) * k;
  19903. cbb = c1b - (c1b - c3b) * k;
  19904. var x1_ = Math.round(Math.min(xa, xb));
  19905. var x2_ = Math.round(Math.max(xa, xb));
  19906. var j = rowSize * y + x1_ * 4;
  19907. for (var x = x1_; x <= x2_; x++) {
  19908. k = (xa - x) / (xa - xb);
  19909. k = k < 0 ? 0 : k > 1 ? 1 : k;
  19910. bytes[j++] = (car - (car - cbr) * k) | 0;
  19911. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  19912. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  19913. bytes[j++] = 255;
  19914. }
  19915. }
  19916. }
  19917. function drawFigure(data, figure, context) {
  19918. var ps = figure.coords;
  19919. var cs = figure.colors;
  19920. var i, ii;
  19921. switch (figure.type) {
  19922. case 'lattice':
  19923. var verticesPerRow = figure.verticesPerRow;
  19924. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  19925. var cols = verticesPerRow - 1;
  19926. for (i = 0; i < rows; i++) {
  19927. var q = i * verticesPerRow;
  19928. for (var j = 0; j < cols; j++, q++) {
  19929. drawTriangle(data, context,
  19930. ps[q], ps[q + 1], ps[q + verticesPerRow],
  19931. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  19932. drawTriangle(data, context,
  19933. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  19934. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  19935. }
  19936. }
  19937. break;
  19938. case 'triangles':
  19939. for (i = 0, ii = ps.length; i < ii; i += 3) {
  19940. drawTriangle(data, context,
  19941. ps[i], ps[i + 1], ps[i + 2],
  19942. cs[i], cs[i + 1], cs[i + 2]);
  19943. }
  19944. break;
  19945. default:
  19946. error('illigal figure');
  19947. break;
  19948. }
  19949. }
  19950. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  19951. backgroundColor, cachedCanvases) {
  19952. // we will increase scale on some weird factor to let antialiasing take
  19953. // care of "rough" edges
  19954. var EXPECTED_SCALE = 1.1;
  19955. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  19956. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  19957. var offsetX = Math.floor(bounds[0]);
  19958. var offsetY = Math.floor(bounds[1]);
  19959. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  19960. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  19961. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  19962. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  19963. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  19964. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  19965. var scaleX = boundsWidth / width;
  19966. var scaleY = boundsHeight / height;
  19967. var context = {
  19968. coords: coords,
  19969. colors: colors,
  19970. offsetX: -offsetX,
  19971. offsetY: -offsetY,
  19972. scaleX: 1 / scaleX,
  19973. scaleY: 1 / scaleY
  19974. };
  19975. var canvas, tmpCanvas, i, ii;
  19976. if (WebGLUtils.isEnabled) {
  19977. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  19978. figures, context);
  19979. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  19980. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  19981. tmpCanvas.context.drawImage(canvas, 0, 0);
  19982. canvas = tmpCanvas.canvas;
  19983. } else {
  19984. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  19985. var tmpCtx = tmpCanvas.context;
  19986. var data = tmpCtx.createImageData(width, height);
  19987. if (backgroundColor) {
  19988. var bytes = data.data;
  19989. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  19990. bytes[i] = backgroundColor[0];
  19991. bytes[i + 1] = backgroundColor[1];
  19992. bytes[i + 2] = backgroundColor[2];
  19993. bytes[i + 3] = 255;
  19994. }
  19995. }
  19996. for (i = 0; i < figures.length; i++) {
  19997. drawFigure(data, figures[i], context);
  19998. }
  19999. tmpCtx.putImageData(data, 0, 0);
  20000. canvas = tmpCanvas.canvas;
  20001. }
  20002. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  20003. scaleX: scaleX, scaleY: scaleY};
  20004. }
  20005. return createMeshCanvas;
  20006. })();
  20007. ShadingIRs.Mesh = {
  20008. fromIR: function Mesh_fromIR(raw) {
  20009. //var type = raw[1];
  20010. var coords = raw[2];
  20011. var colors = raw[3];
  20012. var figures = raw[4];
  20013. var bounds = raw[5];
  20014. var matrix = raw[6];
  20015. //var bbox = raw[7];
  20016. var background = raw[8];
  20017. return {
  20018. type: 'Pattern',
  20019. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  20020. var scale;
  20021. if (shadingFill) {
  20022. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  20023. } else {
  20024. // Obtain scale from matrix and current transformation matrix.
  20025. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  20026. if (matrix) {
  20027. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  20028. scale = [scale[0] * matrixScale[0],
  20029. scale[1] * matrixScale[1]];
  20030. }
  20031. }
  20032. // Rasterizing on the main thread since sending/queue large canvases
  20033. // might cause OOM.
  20034. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  20035. colors, figures, shadingFill ? null : background,
  20036. owner.cachedCanvases);
  20037. if (!shadingFill) {
  20038. ctx.setTransform.apply(ctx, owner.baseTransform);
  20039. if (matrix) {
  20040. ctx.transform.apply(ctx, matrix);
  20041. }
  20042. }
  20043. ctx.translate(temporaryPatternCanvas.offsetX,
  20044. temporaryPatternCanvas.offsetY);
  20045. ctx.scale(temporaryPatternCanvas.scaleX,
  20046. temporaryPatternCanvas.scaleY);
  20047. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  20048. }
  20049. };
  20050. }
  20051. };
  20052. ShadingIRs.Dummy = {
  20053. fromIR: function Dummy_fromIR() {
  20054. return {
  20055. type: 'Pattern',
  20056. getPattern: function Dummy_fromIR_getPattern() {
  20057. return 'hotpink';
  20058. }
  20059. };
  20060. }
  20061. };
  20062. function getShadingPatternFromIR(raw) {
  20063. var shadingIR = ShadingIRs[raw[0]];
  20064. if (!shadingIR) {
  20065. error('Unknown IR type: ' + raw[0]);
  20066. }
  20067. return shadingIR.fromIR(raw);
  20068. }
  20069. var TilingPattern = (function TilingPatternClosure() {
  20070. var PaintType = {
  20071. COLORED: 1,
  20072. UNCOLORED: 2
  20073. };
  20074. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  20075. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  20076. this.operatorList = IR[2];
  20077. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  20078. this.bbox = IR[4];
  20079. this.xstep = IR[5];
  20080. this.ystep = IR[6];
  20081. this.paintType = IR[7];
  20082. this.tilingType = IR[8];
  20083. this.color = color;
  20084. this.canvasGraphicsFactory = canvasGraphicsFactory;
  20085. this.baseTransform = baseTransform;
  20086. this.type = 'Pattern';
  20087. this.ctx = ctx;
  20088. }
  20089. TilingPattern.prototype = {
  20090. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  20091. var operatorList = this.operatorList;
  20092. var bbox = this.bbox;
  20093. var xstep = this.xstep;
  20094. var ystep = this.ystep;
  20095. var paintType = this.paintType;
  20096. var tilingType = this.tilingType;
  20097. var color = this.color;
  20098. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  20099. info('TilingType: ' + tilingType);
  20100. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  20101. var topLeft = [x0, y0];
  20102. // we want the canvas to be as large as the step size
  20103. var botRight = [x0 + xstep, y0 + ystep];
  20104. var width = botRight[0] - topLeft[0];
  20105. var height = botRight[1] - topLeft[1];
  20106. // Obtain scale from matrix and current transformation matrix.
  20107. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  20108. var curMatrixScale = Util.singularValueDecompose2dScale(
  20109. this.baseTransform);
  20110. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  20111. matrixScale[1] * curMatrixScale[1]];
  20112. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  20113. // Use width and height values that are as close as possible to the end
  20114. // result when the pattern is used. Too low value makes the pattern look
  20115. // blurry. Too large value makes it look too crispy.
  20116. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  20117. MAX_PATTERN_SIZE);
  20118. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  20119. MAX_PATTERN_SIZE);
  20120. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  20121. width, height, true);
  20122. var tmpCtx = tmpCanvas.context;
  20123. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  20124. graphics.groupLevel = owner.groupLevel;
  20125. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  20126. this.setScale(width, height, xstep, ystep);
  20127. this.transformToScale(graphics);
  20128. // transform coordinates to pattern space
  20129. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  20130. graphics.transform.apply(graphics, tmpTranslate);
  20131. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  20132. graphics.executeOperatorList(operatorList);
  20133. return tmpCanvas.canvas;
  20134. },
  20135. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  20136. this.scale = [width / xstep, height / ystep];
  20137. },
  20138. transformToScale: function TilingPattern_transformToScale(graphics) {
  20139. var scale = this.scale;
  20140. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  20141. graphics.transform.apply(graphics, tmpScale);
  20142. },
  20143. scaleToContext: function TilingPattern_scaleToContext() {
  20144. var scale = this.scale;
  20145. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  20146. },
  20147. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  20148. if (bbox && isArray(bbox) && bbox.length === 4) {
  20149. var bboxWidth = x1 - x0;
  20150. var bboxHeight = y1 - y0;
  20151. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  20152. graphics.clip();
  20153. graphics.endPath();
  20154. }
  20155. },
  20156. setFillAndStrokeStyleToContext:
  20157. function setFillAndStrokeStyleToContext(context, paintType, color) {
  20158. switch (paintType) {
  20159. case PaintType.COLORED:
  20160. var ctx = this.ctx;
  20161. context.fillStyle = ctx.fillStyle;
  20162. context.strokeStyle = ctx.strokeStyle;
  20163. break;
  20164. case PaintType.UNCOLORED:
  20165. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  20166. context.fillStyle = cssColor;
  20167. context.strokeStyle = cssColor;
  20168. break;
  20169. default:
  20170. error('Unsupported paint type: ' + paintType);
  20171. }
  20172. },
  20173. getPattern: function TilingPattern_getPattern(ctx, owner) {
  20174. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  20175. ctx = this.ctx;
  20176. ctx.setTransform.apply(ctx, this.baseTransform);
  20177. ctx.transform.apply(ctx, this.matrix);
  20178. this.scaleToContext();
  20179. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  20180. }
  20181. };
  20182. return TilingPattern;
  20183. })();
  20184. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  20185. exports.TilingPattern = TilingPattern;
  20186. }));
  20187. (function (root, factory) {
  20188. {
  20189. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  20190. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  20191. }
  20192. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  20193. var PasswordException = sharedUtil.PasswordException;
  20194. var PasswordResponses = sharedUtil.PasswordResponses;
  20195. var bytesToString = sharedUtil.bytesToString;
  20196. var error = sharedUtil.error;
  20197. var isInt = sharedUtil.isInt;
  20198. var stringToBytes = sharedUtil.stringToBytes;
  20199. var utf8StringToString = sharedUtil.utf8StringToString;
  20200. var warn = sharedUtil.warn;
  20201. var Name = corePrimitives.Name;
  20202. var isName = corePrimitives.isName;
  20203. var isDict = corePrimitives.isDict;
  20204. var DecryptStream = coreStream.DecryptStream;
  20205. var ARCFourCipher = (function ARCFourCipherClosure() {
  20206. function ARCFourCipher(key) {
  20207. this.a = 0;
  20208. this.b = 0;
  20209. var s = new Uint8Array(256);
  20210. var i, j = 0, tmp, keyLength = key.length;
  20211. for (i = 0; i < 256; ++i) {
  20212. s[i] = i;
  20213. }
  20214. for (i = 0; i < 256; ++i) {
  20215. tmp = s[i];
  20216. j = (j + tmp + key[i % keyLength]) & 0xFF;
  20217. s[i] = s[j];
  20218. s[j] = tmp;
  20219. }
  20220. this.s = s;
  20221. }
  20222. ARCFourCipher.prototype = {
  20223. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  20224. var i, n = data.length, tmp, tmp2;
  20225. var a = this.a, b = this.b, s = this.s;
  20226. var output = new Uint8Array(n);
  20227. for (i = 0; i < n; ++i) {
  20228. a = (a + 1) & 0xFF;
  20229. tmp = s[a];
  20230. b = (b + tmp) & 0xFF;
  20231. tmp2 = s[b];
  20232. s[a] = tmp2;
  20233. s[b] = tmp;
  20234. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  20235. }
  20236. this.a = a;
  20237. this.b = b;
  20238. return output;
  20239. }
  20240. };
  20241. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  20242. return ARCFourCipher;
  20243. })();
  20244. var calculateMD5 = (function calculateMD5Closure() {
  20245. var r = new Uint8Array([
  20246. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  20247. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  20248. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  20249. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  20250. var k = new Int32Array([
  20251. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  20252. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  20253. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  20254. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  20255. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  20256. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  20257. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  20258. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  20259. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  20260. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  20261. -145523070, -1120210379, 718787259, -343485551]);
  20262. function hash(data, offset, length) {
  20263. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  20264. // pre-processing
  20265. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  20266. var padded = new Uint8Array(paddedLength);
  20267. var i, j, n;
  20268. for (i = 0; i < length; ++i) {
  20269. padded[i] = data[offset++];
  20270. }
  20271. padded[i++] = 0x80;
  20272. n = paddedLength - 8;
  20273. while (i < n) {
  20274. padded[i++] = 0;
  20275. }
  20276. padded[i++] = (length << 3) & 0xFF;
  20277. padded[i++] = (length >> 5) & 0xFF;
  20278. padded[i++] = (length >> 13) & 0xFF;
  20279. padded[i++] = (length >> 21) & 0xFF;
  20280. padded[i++] = (length >>> 29) & 0xFF;
  20281. padded[i++] = 0;
  20282. padded[i++] = 0;
  20283. padded[i++] = 0;
  20284. var w = new Int32Array(16);
  20285. for (i = 0; i < paddedLength;) {
  20286. for (j = 0; j < 16; ++j, i += 4) {
  20287. w[j] = (padded[i] | (padded[i + 1] << 8) |
  20288. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  20289. }
  20290. var a = h0, b = h1, c = h2, d = h3, f, g;
  20291. for (j = 0; j < 64; ++j) {
  20292. if (j < 16) {
  20293. f = (b & c) | ((~b) & d);
  20294. g = j;
  20295. } else if (j < 32) {
  20296. f = (d & b) | ((~d) & c);
  20297. g = (5 * j + 1) & 15;
  20298. } else if (j < 48) {
  20299. f = b ^ c ^ d;
  20300. g = (3 * j + 5) & 15;
  20301. } else {
  20302. f = c ^ (b | (~d));
  20303. g = (7 * j) & 15;
  20304. }
  20305. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  20306. d = c;
  20307. c = b;
  20308. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  20309. a = tmp;
  20310. }
  20311. h0 = (h0 + a) | 0;
  20312. h1 = (h1 + b) | 0;
  20313. h2 = (h2 + c) | 0;
  20314. h3 = (h3 + d) | 0;
  20315. }
  20316. return new Uint8Array([
  20317. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  20318. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  20319. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  20320. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  20321. ]);
  20322. }
  20323. return hash;
  20324. })();
  20325. var Word64 = (function Word64Closure() {
  20326. function Word64(highInteger, lowInteger) {
  20327. this.high = highInteger | 0;
  20328. this.low = lowInteger | 0;
  20329. }
  20330. Word64.prototype = {
  20331. and: function Word64_and(word) {
  20332. this.high &= word.high;
  20333. this.low &= word.low;
  20334. },
  20335. xor: function Word64_xor(word) {
  20336. this.high ^= word.high;
  20337. this.low ^= word.low;
  20338. },
  20339. or: function Word64_or(word) {
  20340. this.high |= word.high;
  20341. this.low |= word.low;
  20342. },
  20343. shiftRight: function Word64_shiftRight(places) {
  20344. if (places >= 32) {
  20345. this.low = (this.high >>> (places - 32)) | 0;
  20346. this.high = 0;
  20347. } else {
  20348. this.low = (this.low >>> places) | (this.high << (32 - places));
  20349. this.high = (this.high >>> places) | 0;
  20350. }
  20351. },
  20352. shiftLeft: function Word64_shiftLeft(places) {
  20353. if (places >= 32) {
  20354. this.high = this.low << (places - 32);
  20355. this.low = 0;
  20356. } else {
  20357. this.high = (this.high << places) | (this.low >>> (32 - places));
  20358. this.low = this.low << places;
  20359. }
  20360. },
  20361. rotateRight: function Word64_rotateRight(places) {
  20362. var low, high;
  20363. if (places & 32) {
  20364. high = this.low;
  20365. low = this.high;
  20366. } else {
  20367. low = this.low;
  20368. high = this.high;
  20369. }
  20370. places &= 31;
  20371. this.low = (low >>> places) | (high << (32 - places));
  20372. this.high = (high >>> places) | (low << (32 - places));
  20373. },
  20374. not: function Word64_not() {
  20375. this.high = ~this.high;
  20376. this.low = ~this.low;
  20377. },
  20378. add: function Word64_add(word) {
  20379. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  20380. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  20381. if (lowAdd > 0xFFFFFFFF) {
  20382. highAdd += 1;
  20383. }
  20384. this.low = lowAdd | 0;
  20385. this.high = highAdd | 0;
  20386. },
  20387. copyTo: function Word64_copyTo(bytes, offset) {
  20388. bytes[offset] = (this.high >>> 24) & 0xFF;
  20389. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  20390. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  20391. bytes[offset + 3] = this.high & 0xFF;
  20392. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  20393. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  20394. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  20395. bytes[offset + 7] = this.low & 0xFF;
  20396. },
  20397. assign: function Word64_assign(word) {
  20398. this.high = word.high;
  20399. this.low = word.low;
  20400. }
  20401. };
  20402. return Word64;
  20403. })();
  20404. var calculateSHA256 = (function calculateSHA256Closure() {
  20405. function rotr(x, n) {
  20406. return (x >>> n) | (x << 32 - n);
  20407. }
  20408. function ch(x, y, z) {
  20409. return (x & y) ^ (~x & z);
  20410. }
  20411. function maj(x, y, z) {
  20412. return (x & y) ^ (x & z) ^ (y & z);
  20413. }
  20414. function sigma(x) {
  20415. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  20416. }
  20417. function sigmaPrime(x) {
  20418. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  20419. }
  20420. function littleSigma(x) {
  20421. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  20422. }
  20423. function littleSigmaPrime(x) {
  20424. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  20425. }
  20426. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  20427. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  20428. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  20429. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  20430. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  20431. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  20432. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  20433. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  20434. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  20435. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  20436. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  20437. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  20438. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  20439. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  20440. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  20441. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  20442. function hash(data, offset, length) {
  20443. // initial hash values
  20444. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  20445. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  20446. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  20447. // pre-processing
  20448. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  20449. var padded = new Uint8Array(paddedLength);
  20450. var i, j, n;
  20451. for (i = 0; i < length; ++i) {
  20452. padded[i] = data[offset++];
  20453. }
  20454. padded[i++] = 0x80;
  20455. n = paddedLength - 8;
  20456. while (i < n) {
  20457. padded[i++] = 0;
  20458. }
  20459. padded[i++] = 0;
  20460. padded[i++] = 0;
  20461. padded[i++] = 0;
  20462. padded[i++] = (length >>> 29) & 0xFF;
  20463. padded[i++] = (length >> 21) & 0xFF;
  20464. padded[i++] = (length >> 13) & 0xFF;
  20465. padded[i++] = (length >> 5) & 0xFF;
  20466. padded[i++] = (length << 3) & 0xFF;
  20467. var w = new Uint32Array(64);
  20468. // for each 512 bit block
  20469. for (i = 0; i < paddedLength;) {
  20470. for (j = 0; j < 16; ++j) {
  20471. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  20472. (padded[i + 2] << 8) | (padded[i + 3]));
  20473. i += 4;
  20474. }
  20475. for (j = 16; j < 64; ++j) {
  20476. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  20477. littleSigma(w[j - 15]) + w[j - 16] | 0;
  20478. }
  20479. var a = h0, b = h1, c = h2, d = h3, e = h4,
  20480. f = h5, g = h6, h = h7, t1, t2;
  20481. for (j = 0; j < 64; ++j) {
  20482. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  20483. t2 = sigma(a) + maj(a, b, c);
  20484. h = g;
  20485. g = f;
  20486. f = e;
  20487. e = (d + t1) | 0;
  20488. d = c;
  20489. c = b;
  20490. b = a;
  20491. a = (t1 + t2) | 0;
  20492. }
  20493. h0 = (h0 + a) | 0;
  20494. h1 = (h1 + b) | 0;
  20495. h2 = (h2 + c) | 0;
  20496. h3 = (h3 + d) | 0;
  20497. h4 = (h4 + e) | 0;
  20498. h5 = (h5 + f) | 0;
  20499. h6 = (h6 + g) | 0;
  20500. h7 = (h7 + h) | 0;
  20501. }
  20502. return new Uint8Array([
  20503. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  20504. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  20505. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  20506. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  20507. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  20508. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  20509. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  20510. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  20511. ]);
  20512. }
  20513. return hash;
  20514. })();
  20515. var calculateSHA512 = (function calculateSHA512Closure() {
  20516. function ch(result, x, y, z, tmp) {
  20517. result.assign(x);
  20518. result.and(y);
  20519. tmp.assign(x);
  20520. tmp.not();
  20521. tmp.and(z);
  20522. result.xor(tmp);
  20523. }
  20524. function maj(result, x, y, z, tmp) {
  20525. result.assign(x);
  20526. result.and(y);
  20527. tmp.assign(x);
  20528. tmp.and(z);
  20529. result.xor(tmp);
  20530. tmp.assign(y);
  20531. tmp.and(z);
  20532. result.xor(tmp);
  20533. }
  20534. function sigma(result, x, tmp) {
  20535. result.assign(x);
  20536. result.rotateRight(28);
  20537. tmp.assign(x);
  20538. tmp.rotateRight(34);
  20539. result.xor(tmp);
  20540. tmp.assign(x);
  20541. tmp.rotateRight(39);
  20542. result.xor(tmp);
  20543. }
  20544. function sigmaPrime(result, x, tmp) {
  20545. result.assign(x);
  20546. result.rotateRight(14);
  20547. tmp.assign(x);
  20548. tmp.rotateRight(18);
  20549. result.xor(tmp);
  20550. tmp.assign(x);
  20551. tmp.rotateRight(41);
  20552. result.xor(tmp);
  20553. }
  20554. function littleSigma(result, x, tmp) {
  20555. result.assign(x);
  20556. result.rotateRight(1);
  20557. tmp.assign(x);
  20558. tmp.rotateRight(8);
  20559. result.xor(tmp);
  20560. tmp.assign(x);
  20561. tmp.shiftRight(7);
  20562. result.xor(tmp);
  20563. }
  20564. function littleSigmaPrime(result, x, tmp) {
  20565. result.assign(x);
  20566. result.rotateRight(19);
  20567. tmp.assign(x);
  20568. tmp.rotateRight(61);
  20569. result.xor(tmp);
  20570. tmp.assign(x);
  20571. tmp.shiftRight(6);
  20572. result.xor(tmp);
  20573. }
  20574. var k = [
  20575. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  20576. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  20577. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  20578. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  20579. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  20580. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  20581. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  20582. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  20583. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  20584. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  20585. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  20586. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  20587. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  20588. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  20589. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  20590. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  20591. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  20592. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  20593. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  20594. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  20595. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  20596. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  20597. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  20598. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  20599. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  20600. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  20601. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  20602. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  20603. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  20604. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  20605. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  20606. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  20607. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  20608. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  20609. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  20610. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  20611. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  20612. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  20613. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  20614. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  20615. function hash(data, offset, length, mode384) {
  20616. mode384 = !!mode384;
  20617. // initial hash values
  20618. var h0, h1, h2, h3, h4, h5, h6, h7;
  20619. if (!mode384) {
  20620. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  20621. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  20622. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  20623. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  20624. h4 = new Word64(0x510e527f, 0xade682d1);
  20625. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  20626. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  20627. h7 = new Word64(0x5be0cd19, 0x137e2179);
  20628. }
  20629. else {
  20630. // SHA384 is exactly the same
  20631. // except with different starting values and a trimmed result
  20632. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  20633. h1 = new Word64(0x629a292a, 0x367cd507);
  20634. h2 = new Word64(0x9159015a, 0x3070dd17);
  20635. h3 = new Word64(0x152fecd8, 0xf70e5939);
  20636. h4 = new Word64(0x67332667, 0xffc00b31);
  20637. h5 = new Word64(0x8eb44a87, 0x68581511);
  20638. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  20639. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  20640. }
  20641. // pre-processing
  20642. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  20643. var padded = new Uint8Array(paddedLength);
  20644. var i, j, n;
  20645. for (i = 0; i < length; ++i) {
  20646. padded[i] = data[offset++];
  20647. }
  20648. padded[i++] = 0x80;
  20649. n = paddedLength - 16;
  20650. while (i < n) {
  20651. padded[i++] = 0;
  20652. }
  20653. padded[i++] = 0;
  20654. padded[i++] = 0;
  20655. padded[i++] = 0;
  20656. padded[i++] = 0;
  20657. padded[i++] = 0;
  20658. padded[i++] = 0;
  20659. padded[i++] = 0;
  20660. padded[i++] = 0;
  20661. padded[i++] = 0;
  20662. padded[i++] = 0;
  20663. padded[i++] = 0;
  20664. padded[i++] = (length >>> 29) & 0xFF;
  20665. padded[i++] = (length >> 21) & 0xFF;
  20666. padded[i++] = (length >> 13) & 0xFF;
  20667. padded[i++] = (length >> 5) & 0xFF;
  20668. padded[i++] = (length << 3) & 0xFF;
  20669. var w = new Array(80);
  20670. for (i = 0; i < 80; i++) {
  20671. w[i] = new Word64(0, 0);
  20672. }
  20673. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  20674. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  20675. var g = new Word64(0, 0), h = new Word64(0, 0);
  20676. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  20677. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  20678. // for each 1024 bit block
  20679. for (i = 0; i < paddedLength;) {
  20680. for (j = 0; j < 16; ++j) {
  20681. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  20682. (padded[i + 2] << 8) | (padded[i + 3]);
  20683. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  20684. (padded[i + 6]) << 8 | (padded[i + 7]);
  20685. i += 8;
  20686. }
  20687. for (j = 16; j < 80; ++j) {
  20688. tmp3 = w[j];
  20689. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  20690. tmp3.add(w[j - 7]);
  20691. littleSigma(tmp1, w[j - 15], tmp2);
  20692. tmp3.add(tmp1);
  20693. tmp3.add(w[j - 16]);
  20694. }
  20695. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  20696. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  20697. for (j = 0; j < 80; ++j) {
  20698. t1.assign(h);
  20699. sigmaPrime(tmp1, e, tmp2);
  20700. t1.add(tmp1);
  20701. ch(tmp1, e, f, g, tmp2);
  20702. t1.add(tmp1);
  20703. t1.add(k[j]);
  20704. t1.add(w[j]);
  20705. sigma(t2, a, tmp2);
  20706. maj(tmp1, a, b, c, tmp2);
  20707. t2.add(tmp1);
  20708. tmp3 = h;
  20709. h = g;
  20710. g = f;
  20711. f = e;
  20712. d.add(t1);
  20713. e = d;
  20714. d = c;
  20715. c = b;
  20716. b = a;
  20717. tmp3.assign(t1);
  20718. tmp3.add(t2);
  20719. a = tmp3;
  20720. }
  20721. h0.add(a);
  20722. h1.add(b);
  20723. h2.add(c);
  20724. h3.add(d);
  20725. h4.add(e);
  20726. h5.add(f);
  20727. h6.add(g);
  20728. h7.add(h);
  20729. }
  20730. var result;
  20731. if (!mode384) {
  20732. result = new Uint8Array(64);
  20733. h0.copyTo(result,0);
  20734. h1.copyTo(result,8);
  20735. h2.copyTo(result,16);
  20736. h3.copyTo(result,24);
  20737. h4.copyTo(result,32);
  20738. h5.copyTo(result,40);
  20739. h6.copyTo(result,48);
  20740. h7.copyTo(result,56);
  20741. }
  20742. else {
  20743. result = new Uint8Array(48);
  20744. h0.copyTo(result,0);
  20745. h1.copyTo(result,8);
  20746. h2.copyTo(result,16);
  20747. h3.copyTo(result,24);
  20748. h4.copyTo(result,32);
  20749. h5.copyTo(result,40);
  20750. }
  20751. return result;
  20752. }
  20753. return hash;
  20754. })();
  20755. var calculateSHA384 = (function calculateSHA384Closure() {
  20756. function hash(data, offset, length) {
  20757. return calculateSHA512(data, offset, length, true);
  20758. }
  20759. return hash;
  20760. })();
  20761. var NullCipher = (function NullCipherClosure() {
  20762. function NullCipher() {
  20763. }
  20764. NullCipher.prototype = {
  20765. decryptBlock: function NullCipher_decryptBlock(data) {
  20766. return data;
  20767. }
  20768. };
  20769. return NullCipher;
  20770. })();
  20771. var AES128Cipher = (function AES128CipherClosure() {
  20772. var rcon = new Uint8Array([
  20773. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20774. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20775. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20776. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20777. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  20778. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  20779. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  20780. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  20781. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  20782. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  20783. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  20784. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  20785. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  20786. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  20787. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  20788. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  20789. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  20790. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20791. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20792. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20793. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20794. 0x74, 0xe8, 0xcb, 0x8d]);
  20795. var s = new Uint8Array([
  20796. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  20797. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  20798. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  20799. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  20800. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  20801. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  20802. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  20803. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  20804. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  20805. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  20806. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  20807. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  20808. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  20809. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  20810. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  20811. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  20812. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  20813. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  20814. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  20815. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  20816. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  20817. 0xb0, 0x54, 0xbb, 0x16]);
  20818. var inv_s = new Uint8Array([
  20819. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  20820. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  20821. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  20822. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  20823. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  20824. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  20825. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  20826. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  20827. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  20828. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  20829. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  20830. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  20831. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  20832. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  20833. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  20834. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  20835. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  20836. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  20837. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  20838. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  20839. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  20840. 0x55, 0x21, 0x0c, 0x7d]);
  20841. var mixCol = new Uint8Array(256);
  20842. for (var i = 0; i < 256; i++) {
  20843. if (i < 128) {
  20844. mixCol[i] = i << 1;
  20845. } else {
  20846. mixCol[i] = (i << 1) ^ 0x1b;
  20847. }
  20848. }
  20849. var mix = new Uint32Array([
  20850. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  20851. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  20852. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  20853. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  20854. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  20855. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  20856. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  20857. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  20858. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  20859. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  20860. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  20861. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  20862. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  20863. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  20864. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  20865. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  20866. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  20867. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  20868. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  20869. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  20870. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  20871. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  20872. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  20873. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  20874. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  20875. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  20876. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  20877. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  20878. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  20879. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  20880. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  20881. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  20882. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  20883. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  20884. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  20885. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  20886. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  20887. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  20888. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  20889. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  20890. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  20891. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  20892. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  20893. function expandKey128(cipherKey) {
  20894. var b = 176, result = new Uint8Array(b);
  20895. result.set(cipherKey);
  20896. for (var j = 16, i = 1; j < b; ++i) {
  20897. // RotWord
  20898. var t1 = result[j - 3], t2 = result[j - 2],
  20899. t3 = result[j - 1], t4 = result[j - 4];
  20900. // SubWord
  20901. t1 = s[t1];
  20902. t2 = s[t2];
  20903. t3 = s[t3];
  20904. t4 = s[t4];
  20905. // Rcon
  20906. t1 = t1 ^ rcon[i];
  20907. for (var n = 0; n < 4; ++n) {
  20908. result[j] = (t1 ^= result[j - 16]);
  20909. j++;
  20910. result[j] = (t2 ^= result[j - 16]);
  20911. j++;
  20912. result[j] = (t3 ^= result[j - 16]);
  20913. j++;
  20914. result[j] = (t4 ^= result[j - 16]);
  20915. j++;
  20916. }
  20917. }
  20918. return result;
  20919. }
  20920. function decrypt128(input, key) {
  20921. var state = new Uint8Array(16);
  20922. state.set(input);
  20923. var i, j, k;
  20924. var t, u, v;
  20925. // AddRoundKey
  20926. for (j = 0, k = 160; j < 16; ++j, ++k) {
  20927. state[j] ^= key[k];
  20928. }
  20929. for (i = 9; i >= 1; --i) {
  20930. // InvShiftRows
  20931. t = state[13];
  20932. state[13] = state[9];
  20933. state[9] = state[5];
  20934. state[5] = state[1];
  20935. state[1] = t;
  20936. t = state[14];
  20937. u = state[10];
  20938. state[14] = state[6];
  20939. state[10] = state[2];
  20940. state[6] = t;
  20941. state[2] = u;
  20942. t = state[15];
  20943. u = state[11];
  20944. v = state[7];
  20945. state[15] = state[3];
  20946. state[11] = t;
  20947. state[7] = u;
  20948. state[3] = v;
  20949. // InvSubBytes
  20950. for (j = 0; j < 16; ++j) {
  20951. state[j] = inv_s[state[j]];
  20952. }
  20953. // AddRoundKey
  20954. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20955. state[j] ^= key[k];
  20956. }
  20957. // InvMixColumns
  20958. for (j = 0; j < 16; j += 4) {
  20959. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  20960. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  20961. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  20962. (s3 >>> 24) ^ (s3 << 8));
  20963. state[j] = (t >>> 24) & 0xFF;
  20964. state[j + 1] = (t >> 16) & 0xFF;
  20965. state[j + 2] = (t >> 8) & 0xFF;
  20966. state[j + 3] = t & 0xFF;
  20967. }
  20968. }
  20969. // InvShiftRows
  20970. t = state[13];
  20971. state[13] = state[9];
  20972. state[9] = state[5];
  20973. state[5] = state[1];
  20974. state[1] = t;
  20975. t = state[14];
  20976. u = state[10];
  20977. state[14] = state[6];
  20978. state[10] = state[2];
  20979. state[6] = t;
  20980. state[2] = u;
  20981. t = state[15];
  20982. u = state[11];
  20983. v = state[7];
  20984. state[15] = state[3];
  20985. state[11] = t;
  20986. state[7] = u;
  20987. state[3] = v;
  20988. for (j = 0; j < 16; ++j) {
  20989. // InvSubBytes
  20990. state[j] = inv_s[state[j]];
  20991. // AddRoundKey
  20992. state[j] ^= key[j];
  20993. }
  20994. return state;
  20995. }
  20996. function encrypt128(input, key) {
  20997. var t, u, v, k;
  20998. var state = new Uint8Array(16);
  20999. state.set(input);
  21000. for (j = 0; j < 16; ++j) {
  21001. // AddRoundKey
  21002. state[j] ^= key[j];
  21003. }
  21004. for (i = 1; i < 10; i++) {
  21005. //SubBytes
  21006. for (j = 0; j < 16; ++j) {
  21007. state[j] = s[state[j]];
  21008. }
  21009. //ShiftRows
  21010. v = state[1];
  21011. state[1] = state[5];
  21012. state[5] = state[9];
  21013. state[9] = state[13];
  21014. state[13] = v;
  21015. v = state[2];
  21016. u = state[6];
  21017. state[2] = state[10];
  21018. state[6] = state[14];
  21019. state[10] = v;
  21020. state[14] = u;
  21021. v = state[3];
  21022. u = state[7];
  21023. t = state[11];
  21024. state[3] = state[15];
  21025. state[7] = v;
  21026. state[11] = u;
  21027. state[15] = t;
  21028. //MixColumns
  21029. for (var j = 0; j < 16; j += 4) {
  21030. var s0 = state[j + 0], s1 = state[j + 1];
  21031. var s2 = state[j + 2], s3 = state[j + 3];
  21032. t = s0 ^ s1 ^ s2 ^ s3;
  21033. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  21034. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  21035. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  21036. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  21037. }
  21038. //AddRoundKey
  21039. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21040. state[j] ^= key[k];
  21041. }
  21042. }
  21043. //SubBytes
  21044. for (j = 0; j < 16; ++j) {
  21045. state[j] = s[state[j]];
  21046. }
  21047. //ShiftRows
  21048. v = state[1];
  21049. state[1] = state[5];
  21050. state[5] = state[9];
  21051. state[9] = state[13];
  21052. state[13] = v;
  21053. v = state[2];
  21054. u = state[6];
  21055. state[2] = state[10];
  21056. state[6] = state[14];
  21057. state[10] = v;
  21058. state[14] = u;
  21059. v = state[3];
  21060. u = state[7];
  21061. t = state[11];
  21062. state[3] = state[15];
  21063. state[7] = v;
  21064. state[11] = u;
  21065. state[15] = t;
  21066. //AddRoundKey
  21067. for (j = 0, k = 160; j < 16; ++j, ++k) {
  21068. state[j] ^= key[k];
  21069. }
  21070. return state;
  21071. }
  21072. function AES128Cipher(key) {
  21073. this.key = expandKey128(key);
  21074. this.buffer = new Uint8Array(16);
  21075. this.bufferPosition = 0;
  21076. }
  21077. function decryptBlock2(data, finalize) {
  21078. var i, j, ii, sourceLength = data.length,
  21079. buffer = this.buffer, bufferLength = this.bufferPosition,
  21080. result = [], iv = this.iv;
  21081. for (i = 0; i < sourceLength; ++i) {
  21082. buffer[bufferLength] = data[i];
  21083. ++bufferLength;
  21084. if (bufferLength < 16) {
  21085. continue;
  21086. }
  21087. // buffer is full, decrypting
  21088. var plain = decrypt128(buffer, this.key);
  21089. // xor-ing the IV vector to get plain text
  21090. for (j = 0; j < 16; ++j) {
  21091. plain[j] ^= iv[j];
  21092. }
  21093. iv = buffer;
  21094. result.push(plain);
  21095. buffer = new Uint8Array(16);
  21096. bufferLength = 0;
  21097. }
  21098. // saving incomplete buffer
  21099. this.buffer = buffer;
  21100. this.bufferLength = bufferLength;
  21101. this.iv = iv;
  21102. if (result.length === 0) {
  21103. return new Uint8Array([]);
  21104. }
  21105. // combining plain text blocks into one
  21106. var outputLength = 16 * result.length;
  21107. if (finalize) {
  21108. // undo a padding that is described in RFC 2898
  21109. var lastBlock = result[result.length - 1];
  21110. var psLen = lastBlock[15];
  21111. if (psLen <= 16) {
  21112. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  21113. if (lastBlock[i] !== psLen) {
  21114. // Invalid padding, assume that the block has no padding.
  21115. psLen = 0;
  21116. break;
  21117. }
  21118. }
  21119. outputLength -= psLen;
  21120. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  21121. }
  21122. }
  21123. var output = new Uint8Array(outputLength);
  21124. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21125. output.set(result[i], j);
  21126. }
  21127. return output;
  21128. }
  21129. AES128Cipher.prototype = {
  21130. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  21131. var i, sourceLength = data.length;
  21132. var buffer = this.buffer, bufferLength = this.bufferPosition;
  21133. // waiting for IV values -- they are at the start of the stream
  21134. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  21135. buffer[bufferLength] = data[i];
  21136. }
  21137. if (bufferLength < 16) {
  21138. // need more data
  21139. this.bufferLength = bufferLength;
  21140. return new Uint8Array([]);
  21141. }
  21142. this.iv = buffer;
  21143. this.buffer = new Uint8Array(16);
  21144. this.bufferLength = 0;
  21145. // starting decryption
  21146. this.decryptBlock = decryptBlock2;
  21147. return this.decryptBlock(data.subarray(16), finalize);
  21148. },
  21149. encrypt: function AES128Cipher_encrypt(data, iv) {
  21150. var i, j, ii, sourceLength = data.length,
  21151. buffer = this.buffer, bufferLength = this.bufferPosition,
  21152. result = [];
  21153. if (!iv) {
  21154. iv = new Uint8Array(16);
  21155. }
  21156. for (i = 0; i < sourceLength; ++i) {
  21157. buffer[bufferLength] = data[i];
  21158. ++bufferLength;
  21159. if (bufferLength < 16) {
  21160. continue;
  21161. }
  21162. for (j = 0; j < 16; ++j) {
  21163. buffer[j] ^= iv[j];
  21164. }
  21165. // buffer is full, encrypting
  21166. var cipher = encrypt128(buffer, this.key);
  21167. iv = cipher;
  21168. result.push(cipher);
  21169. buffer = new Uint8Array(16);
  21170. bufferLength = 0;
  21171. }
  21172. // saving incomplete buffer
  21173. this.buffer = buffer;
  21174. this.bufferLength = bufferLength;
  21175. this.iv = iv;
  21176. if (result.length === 0) {
  21177. return new Uint8Array([]);
  21178. }
  21179. // combining plain text blocks into one
  21180. var outputLength = 16 * result.length;
  21181. var output = new Uint8Array(outputLength);
  21182. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21183. output.set(result[i], j);
  21184. }
  21185. return output;
  21186. }
  21187. };
  21188. return AES128Cipher;
  21189. })();
  21190. var AES256Cipher = (function AES256CipherClosure() {
  21191. var rcon = new Uint8Array([
  21192. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21193. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21194. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21195. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21196. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21197. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21198. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21199. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21200. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21201. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21202. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21203. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21204. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21205. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21206. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21207. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21208. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21209. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21210. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21211. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21212. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21213. 0x74, 0xe8, 0xcb, 0x8d]);
  21214. var s = new Uint8Array([
  21215. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21216. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21217. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21218. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21219. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21220. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21221. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21222. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21223. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21224. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21225. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21226. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21227. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21228. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21229. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21230. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21231. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21232. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21233. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21234. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21235. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21236. 0xb0, 0x54, 0xbb, 0x16]);
  21237. var inv_s = new Uint8Array([
  21238. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21239. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21240. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21241. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21242. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21243. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21244. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21245. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21246. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21247. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21248. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21249. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21250. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21251. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21252. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21253. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21254. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21255. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21256. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21257. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  21258. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  21259. 0x55, 0x21, 0x0c, 0x7d]);
  21260. var mixCol = new Uint8Array(256);
  21261. for (var i = 0; i < 256; i++) {
  21262. if (i < 128) {
  21263. mixCol[i] = i << 1;
  21264. } else {
  21265. mixCol[i] = (i << 1) ^ 0x1b;
  21266. }
  21267. }
  21268. var mix = new Uint32Array([
  21269. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  21270. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  21271. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  21272. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  21273. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  21274. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  21275. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  21276. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  21277. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  21278. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  21279. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  21280. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  21281. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  21282. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  21283. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  21284. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  21285. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  21286. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  21287. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  21288. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  21289. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  21290. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  21291. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  21292. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  21293. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  21294. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  21295. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  21296. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  21297. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  21298. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  21299. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  21300. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  21301. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  21302. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  21303. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  21304. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  21305. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  21306. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  21307. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  21308. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  21309. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  21310. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  21311. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  21312. function expandKey256(cipherKey) {
  21313. var b = 240, result = new Uint8Array(b);
  21314. var r = 1;
  21315. result.set(cipherKey);
  21316. for (var j = 32, i = 1; j < b; ++i) {
  21317. if (j % 32 === 16) {
  21318. t1 = s[t1];
  21319. t2 = s[t2];
  21320. t3 = s[t3];
  21321. t4 = s[t4];
  21322. } else if (j % 32 === 0) {
  21323. // RotWord
  21324. var t1 = result[j - 3], t2 = result[j - 2],
  21325. t3 = result[j - 1], t4 = result[j - 4];
  21326. // SubWord
  21327. t1 = s[t1];
  21328. t2 = s[t2];
  21329. t3 = s[t3];
  21330. t4 = s[t4];
  21331. // Rcon
  21332. t1 = t1 ^ r;
  21333. if ((r <<= 1) >= 256) {
  21334. r = (r ^ 0x1b) & 0xFF;
  21335. }
  21336. }
  21337. for (var n = 0; n < 4; ++n) {
  21338. result[j] = (t1 ^= result[j - 32]);
  21339. j++;
  21340. result[j] = (t2 ^= result[j - 32]);
  21341. j++;
  21342. result[j] = (t3 ^= result[j - 32]);
  21343. j++;
  21344. result[j] = (t4 ^= result[j - 32]);
  21345. j++;
  21346. }
  21347. }
  21348. return result;
  21349. }
  21350. function decrypt256(input, key) {
  21351. var state = new Uint8Array(16);
  21352. state.set(input);
  21353. var i, j, k;
  21354. var t, u, v;
  21355. // AddRoundKey
  21356. for (j = 0, k = 224; j < 16; ++j, ++k) {
  21357. state[j] ^= key[k];
  21358. }
  21359. for (i = 13; i >= 1; --i) {
  21360. // InvShiftRows
  21361. t = state[13];
  21362. state[13] = state[9];
  21363. state[9] = state[5];
  21364. state[5] = state[1];
  21365. state[1] = t;
  21366. t = state[14];
  21367. u = state[10];
  21368. state[14] = state[6];
  21369. state[10] = state[2];
  21370. state[6] = t;
  21371. state[2] = u;
  21372. t = state[15];
  21373. u = state[11];
  21374. v = state[7];
  21375. state[15] = state[3];
  21376. state[11] = t;
  21377. state[7] = u;
  21378. state[3] = v;
  21379. // InvSubBytes
  21380. for (j = 0; j < 16; ++j) {
  21381. state[j] = inv_s[state[j]];
  21382. }
  21383. // AddRoundKey
  21384. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21385. state[j] ^= key[k];
  21386. }
  21387. // InvMixColumns
  21388. for (j = 0; j < 16; j += 4) {
  21389. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  21390. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  21391. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  21392. (s3 >>> 24) ^ (s3 << 8));
  21393. state[j] = (t >>> 24) & 0xFF;
  21394. state[j + 1] = (t >> 16) & 0xFF;
  21395. state[j + 2] = (t >> 8) & 0xFF;
  21396. state[j + 3] = t & 0xFF;
  21397. }
  21398. }
  21399. // InvShiftRows
  21400. t = state[13];
  21401. state[13] = state[9];
  21402. state[9] = state[5];
  21403. state[5] = state[1];
  21404. state[1] = t;
  21405. t = state[14];
  21406. u = state[10];
  21407. state[14] = state[6];
  21408. state[10] = state[2];
  21409. state[6] = t;
  21410. state[2] = u;
  21411. t = state[15];
  21412. u = state[11];
  21413. v = state[7];
  21414. state[15] = state[3];
  21415. state[11] = t;
  21416. state[7] = u;
  21417. state[3] = v;
  21418. for (j = 0; j < 16; ++j) {
  21419. // InvSubBytes
  21420. state[j] = inv_s[state[j]];
  21421. // AddRoundKey
  21422. state[j] ^= key[j];
  21423. }
  21424. return state;
  21425. }
  21426. function encrypt256(input, key) {
  21427. var t, u, v, k;
  21428. var state = new Uint8Array(16);
  21429. state.set(input);
  21430. for (j = 0; j < 16; ++j) {
  21431. // AddRoundKey
  21432. state[j] ^= key[j];
  21433. }
  21434. for (i = 1; i < 14; i++) {
  21435. //SubBytes
  21436. for (j = 0; j < 16; ++j) {
  21437. state[j] = s[state[j]];
  21438. }
  21439. //ShiftRows
  21440. v = state[1];
  21441. state[1] = state[5];
  21442. state[5] = state[9];
  21443. state[9] = state[13];
  21444. state[13] = v;
  21445. v = state[2];
  21446. u = state[6];
  21447. state[2] = state[10];
  21448. state[6] = state[14];
  21449. state[10] = v;
  21450. state[14] = u;
  21451. v = state[3];
  21452. u = state[7];
  21453. t = state[11];
  21454. state[3] = state[15];
  21455. state[7] = v;
  21456. state[11] = u;
  21457. state[15] = t;
  21458. //MixColumns
  21459. for (var j = 0; j < 16; j += 4) {
  21460. var s0 = state[j + 0], s1 = state[j + 1];
  21461. var s2 = state[j + 2], s3 = state[j + 3];
  21462. t = s0 ^ s1 ^ s2 ^ s3;
  21463. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  21464. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  21465. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  21466. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  21467. }
  21468. //AddRoundKey
  21469. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21470. state[j] ^= key[k];
  21471. }
  21472. }
  21473. //SubBytes
  21474. for (j = 0; j < 16; ++j) {
  21475. state[j] = s[state[j]];
  21476. }
  21477. //ShiftRows
  21478. v = state[1];
  21479. state[1] = state[5];
  21480. state[5] = state[9];
  21481. state[9] = state[13];
  21482. state[13] = v;
  21483. v = state[2];
  21484. u = state[6];
  21485. state[2] = state[10];
  21486. state[6] = state[14];
  21487. state[10] = v;
  21488. state[14] = u;
  21489. v = state[3];
  21490. u = state[7];
  21491. t = state[11];
  21492. state[3] = state[15];
  21493. state[7] = v;
  21494. state[11] = u;
  21495. state[15] = t;
  21496. //AddRoundKey
  21497. for (j = 0, k = 224; j < 16; ++j, ++k) {
  21498. state[j] ^= key[k];
  21499. }
  21500. return state;
  21501. }
  21502. function AES256Cipher(key) {
  21503. this.key = expandKey256(key);
  21504. this.buffer = new Uint8Array(16);
  21505. this.bufferPosition = 0;
  21506. }
  21507. function decryptBlock2(data, finalize) {
  21508. var i, j, ii, sourceLength = data.length,
  21509. buffer = this.buffer, bufferLength = this.bufferPosition,
  21510. result = [], iv = this.iv;
  21511. for (i = 0; i < sourceLength; ++i) {
  21512. buffer[bufferLength] = data[i];
  21513. ++bufferLength;
  21514. if (bufferLength < 16) {
  21515. continue;
  21516. }
  21517. // buffer is full, decrypting
  21518. var plain = decrypt256(buffer, this.key);
  21519. // xor-ing the IV vector to get plain text
  21520. for (j = 0; j < 16; ++j) {
  21521. plain[j] ^= iv[j];
  21522. }
  21523. iv = buffer;
  21524. result.push(plain);
  21525. buffer = new Uint8Array(16);
  21526. bufferLength = 0;
  21527. }
  21528. // saving incomplete buffer
  21529. this.buffer = buffer;
  21530. this.bufferLength = bufferLength;
  21531. this.iv = iv;
  21532. if (result.length === 0) {
  21533. return new Uint8Array([]);
  21534. }
  21535. // combining plain text blocks into one
  21536. var outputLength = 16 * result.length;
  21537. if (finalize) {
  21538. // undo a padding that is described in RFC 2898
  21539. var lastBlock = result[result.length - 1];
  21540. var psLen = lastBlock[15];
  21541. if (psLen <= 16) {
  21542. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  21543. if (lastBlock[i] !== psLen) {
  21544. // Invalid padding, assume that the block has no padding.
  21545. psLen = 0;
  21546. break;
  21547. }
  21548. }
  21549. outputLength -= psLen;
  21550. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  21551. }
  21552. }
  21553. var output = new Uint8Array(outputLength);
  21554. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21555. output.set(result[i], j);
  21556. }
  21557. return output;
  21558. }
  21559. AES256Cipher.prototype = {
  21560. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  21561. var i, sourceLength = data.length;
  21562. var buffer = this.buffer, bufferLength = this.bufferPosition;
  21563. // if not supplied an IV wait for IV values
  21564. // they are at the start of the stream
  21565. if (iv) {
  21566. this.iv = iv;
  21567. } else {
  21568. for (i = 0; bufferLength < 16 &&
  21569. i < sourceLength; ++i, ++bufferLength) {
  21570. buffer[bufferLength] = data[i];
  21571. }
  21572. if (bufferLength < 16) {
  21573. //need more data
  21574. this.bufferLength = bufferLength;
  21575. return new Uint8Array([]);
  21576. }
  21577. this.iv = buffer;
  21578. data = data.subarray(16);
  21579. }
  21580. this.buffer = new Uint8Array(16);
  21581. this.bufferLength = 0;
  21582. // starting decryption
  21583. this.decryptBlock = decryptBlock2;
  21584. return this.decryptBlock(data, finalize);
  21585. },
  21586. encrypt: function AES256Cipher_encrypt(data, iv) {
  21587. var i, j, ii, sourceLength = data.length,
  21588. buffer = this.buffer, bufferLength = this.bufferPosition,
  21589. result = [];
  21590. if (!iv) {
  21591. iv = new Uint8Array(16);
  21592. }
  21593. for (i = 0; i < sourceLength; ++i) {
  21594. buffer[bufferLength] = data[i];
  21595. ++bufferLength;
  21596. if (bufferLength < 16) {
  21597. continue;
  21598. }
  21599. for (j = 0; j < 16; ++j) {
  21600. buffer[j] ^= iv[j];
  21601. }
  21602. // buffer is full, encrypting
  21603. var cipher = encrypt256(buffer, this.key);
  21604. this.iv = cipher;
  21605. result.push(cipher);
  21606. buffer = new Uint8Array(16);
  21607. bufferLength = 0;
  21608. }
  21609. // saving incomplete buffer
  21610. this.buffer = buffer;
  21611. this.bufferLength = bufferLength;
  21612. this.iv = iv;
  21613. if (result.length === 0) {
  21614. return new Uint8Array([]);
  21615. }
  21616. // combining plain text blocks into one
  21617. var outputLength = 16 * result.length;
  21618. var output = new Uint8Array(outputLength);
  21619. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21620. output.set(result[i], j);
  21621. }
  21622. return output;
  21623. }
  21624. };
  21625. return AES256Cipher;
  21626. })();
  21627. var PDF17 = (function PDF17Closure() {
  21628. function compareByteArrays(array1, array2) {
  21629. if (array1.length !== array2.length) {
  21630. return false;
  21631. }
  21632. for (var i = 0; i < array1.length; i++) {
  21633. if (array1[i] !== array2[i]) {
  21634. return false;
  21635. }
  21636. }
  21637. return true;
  21638. }
  21639. function PDF17() {
  21640. }
  21641. PDF17.prototype = {
  21642. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  21643. ownerValidationSalt,
  21644. userBytes,
  21645. ownerPassword) {
  21646. var hashData = new Uint8Array(password.length + 56);
  21647. hashData.set(password, 0);
  21648. hashData.set(ownerValidationSalt, password.length);
  21649. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  21650. var result = calculateSHA256(hashData, 0, hashData.length);
  21651. return compareByteArrays(result, ownerPassword);
  21652. },
  21653. checkUserPassword: function PDF17_checkUserPassword(password,
  21654. userValidationSalt,
  21655. userPassword) {
  21656. var hashData = new Uint8Array(password.length + 8);
  21657. hashData.set(password, 0);
  21658. hashData.set(userValidationSalt, password.length);
  21659. var result = calculateSHA256(hashData, 0, hashData.length);
  21660. return compareByteArrays(result, userPassword);
  21661. },
  21662. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  21663. ownerEncryption) {
  21664. var hashData = new Uint8Array(password.length + 56);
  21665. hashData.set(password, 0);
  21666. hashData.set(ownerKeySalt, password.length);
  21667. hashData.set(userBytes, password.length + ownerKeySalt.length);
  21668. var key = calculateSHA256(hashData, 0, hashData.length);
  21669. var cipher = new AES256Cipher(key);
  21670. return cipher.decryptBlock(ownerEncryption,
  21671. false,
  21672. new Uint8Array(16));
  21673. },
  21674. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  21675. userEncryption) {
  21676. var hashData = new Uint8Array(password.length + 8);
  21677. hashData.set(password, 0);
  21678. hashData.set(userKeySalt, password.length);
  21679. //key is the decryption key for the UE string
  21680. var key = calculateSHA256(hashData, 0, hashData.length);
  21681. var cipher = new AES256Cipher(key);
  21682. return cipher.decryptBlock(userEncryption,
  21683. false,
  21684. new Uint8Array(16));
  21685. }
  21686. };
  21687. return PDF17;
  21688. })();
  21689. var PDF20 = (function PDF20Closure() {
  21690. function concatArrays(array1, array2) {
  21691. var t = new Uint8Array(array1.length + array2.length);
  21692. t.set(array1, 0);
  21693. t.set(array2, array1.length);
  21694. return t;
  21695. }
  21696. function calculatePDF20Hash(password, input, userBytes) {
  21697. //This refers to Algorithm 2.B as defined in ISO 32000-2
  21698. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  21699. var e = [0];
  21700. var i = 0;
  21701. while (i < 64 || e[e.length - 1] > i - 32) {
  21702. var arrayLength = password.length + k.length + userBytes.length;
  21703. var k1 = new Uint8Array(arrayLength * 64);
  21704. var array = concatArrays(password, k);
  21705. array = concatArrays(array, userBytes);
  21706. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  21707. k1.set(array, pos);
  21708. }
  21709. //AES128 CBC NO PADDING with
  21710. //first 16 bytes of k as the key and the second 16 as the iv.
  21711. var cipher = new AES128Cipher(k.subarray(0, 16));
  21712. e = cipher.encrypt(k1, k.subarray(16, 32));
  21713. //Now we have to take the first 16 bytes of an unsigned
  21714. //big endian integer... and compute the remainder
  21715. //modulo 3.... That is a fairly large number and
  21716. //JavaScript isn't going to handle that well...
  21717. //So we're using a trick that allows us to perform
  21718. //modulo math byte by byte
  21719. var remainder = 0;
  21720. for (var z = 0; z < 16; z++) {
  21721. remainder *= (256 % 3);
  21722. remainder %= 3;
  21723. remainder += ((e[z] >>> 0) % 3);
  21724. remainder %= 3;
  21725. }
  21726. if (remainder === 0) {
  21727. k = calculateSHA256(e, 0, e.length);
  21728. }
  21729. else if (remainder === 1) {
  21730. k = calculateSHA384(e, 0, e.length);
  21731. }
  21732. else if (remainder === 2) {
  21733. k = calculateSHA512(e, 0, e.length);
  21734. }
  21735. i++;
  21736. }
  21737. return k.subarray(0, 32);
  21738. }
  21739. function PDF20() {
  21740. }
  21741. function compareByteArrays(array1, array2) {
  21742. if (array1.length !== array2.length) {
  21743. return false;
  21744. }
  21745. for (var i = 0; i < array1.length; i++) {
  21746. if (array1[i] !== array2[i]) {
  21747. return false;
  21748. }
  21749. }
  21750. return true;
  21751. }
  21752. PDF20.prototype = {
  21753. hash: function PDF20_hash(password, concatBytes, userBytes) {
  21754. return calculatePDF20Hash(password, concatBytes, userBytes);
  21755. },
  21756. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  21757. ownerValidationSalt,
  21758. userBytes,
  21759. ownerPassword) {
  21760. var hashData = new Uint8Array(password.length + 56);
  21761. hashData.set(password, 0);
  21762. hashData.set(ownerValidationSalt, password.length);
  21763. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  21764. var result = calculatePDF20Hash(password, hashData, userBytes);
  21765. return compareByteArrays(result, ownerPassword);
  21766. },
  21767. checkUserPassword: function PDF20_checkUserPassword(password,
  21768. userValidationSalt,
  21769. userPassword) {
  21770. var hashData = new Uint8Array(password.length + 8);
  21771. hashData.set(password, 0);
  21772. hashData.set(userValidationSalt, password.length);
  21773. var result = calculatePDF20Hash(password, hashData, []);
  21774. return compareByteArrays(result, userPassword);
  21775. },
  21776. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  21777. ownerEncryption) {
  21778. var hashData = new Uint8Array(password.length + 56);
  21779. hashData.set(password, 0);
  21780. hashData.set(ownerKeySalt, password.length);
  21781. hashData.set(userBytes, password.length + ownerKeySalt.length);
  21782. var key = calculatePDF20Hash(password, hashData, userBytes);
  21783. var cipher = new AES256Cipher(key);
  21784. return cipher.decryptBlock(ownerEncryption,
  21785. false,
  21786. new Uint8Array(16));
  21787. },
  21788. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  21789. userEncryption) {
  21790. var hashData = new Uint8Array(password.length + 8);
  21791. hashData.set(password, 0);
  21792. hashData.set(userKeySalt, password.length);
  21793. //key is the decryption key for the UE string
  21794. var key = calculatePDF20Hash(password, hashData, []);
  21795. var cipher = new AES256Cipher(key);
  21796. return cipher.decryptBlock(userEncryption,
  21797. false,
  21798. new Uint8Array(16));
  21799. }
  21800. };
  21801. return PDF20;
  21802. })();
  21803. var CipherTransform = (function CipherTransformClosure() {
  21804. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  21805. this.stringCipherConstructor = stringCipherConstructor;
  21806. this.streamCipherConstructor = streamCipherConstructor;
  21807. }
  21808. CipherTransform.prototype = {
  21809. createStream: function CipherTransform_createStream(stream, length) {
  21810. var cipher = new this.streamCipherConstructor();
  21811. return new DecryptStream(stream, length,
  21812. function cipherTransformDecryptStream(data, finalize) {
  21813. return cipher.decryptBlock(data, finalize);
  21814. }
  21815. );
  21816. },
  21817. decryptString: function CipherTransform_decryptString(s) {
  21818. var cipher = new this.stringCipherConstructor();
  21819. var data = stringToBytes(s);
  21820. data = cipher.decryptBlock(data, true);
  21821. return bytesToString(data);
  21822. }
  21823. };
  21824. return CipherTransform;
  21825. })();
  21826. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  21827. var defaultPasswordBytes = new Uint8Array([
  21828. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  21829. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  21830. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  21831. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  21832. function createEncryptionKey20(revision, password, ownerPassword,
  21833. ownerValidationSalt, ownerKeySalt, uBytes,
  21834. userPassword, userValidationSalt, userKeySalt,
  21835. ownerEncryption, userEncryption, perms) {
  21836. if (password) {
  21837. var passwordLength = Math.min(127, password.length);
  21838. password = password.subarray(0, passwordLength);
  21839. } else {
  21840. password = [];
  21841. }
  21842. var pdfAlgorithm;
  21843. if (revision === 6) {
  21844. pdfAlgorithm = new PDF20();
  21845. } else {
  21846. pdfAlgorithm = new PDF17();
  21847. }
  21848. if (pdfAlgorithm) {
  21849. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  21850. userPassword)) {
  21851. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  21852. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  21853. ownerValidationSalt,
  21854. uBytes,
  21855. ownerPassword)) {
  21856. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  21857. ownerEncryption);
  21858. }
  21859. }
  21860. return null;
  21861. }
  21862. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  21863. flags, revision, keyLength, encryptMetadata) {
  21864. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  21865. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  21866. if (password) {
  21867. n = Math.min(32, password.length);
  21868. for (; i < n; ++i) {
  21869. hashData[i] = password[i];
  21870. }
  21871. }
  21872. j = 0;
  21873. while (i < 32) {
  21874. hashData[i++] = defaultPasswordBytes[j++];
  21875. }
  21876. // as now the padded password in the hashData[0..i]
  21877. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  21878. hashData[i++] = ownerPassword[j];
  21879. }
  21880. hashData[i++] = flags & 0xFF;
  21881. hashData[i++] = (flags >> 8) & 0xFF;
  21882. hashData[i++] = (flags >> 16) & 0xFF;
  21883. hashData[i++] = (flags >>> 24) & 0xFF;
  21884. for (j = 0, n = fileId.length; j < n; ++j) {
  21885. hashData[i++] = fileId[j];
  21886. }
  21887. if (revision >= 4 && !encryptMetadata) {
  21888. hashData[i++] = 0xFF;
  21889. hashData[i++] = 0xFF;
  21890. hashData[i++] = 0xFF;
  21891. hashData[i++] = 0xFF;
  21892. }
  21893. var hash = calculateMD5(hashData, 0, i);
  21894. var keyLengthInBytes = keyLength >> 3;
  21895. if (revision >= 3) {
  21896. for (j = 0; j < 50; ++j) {
  21897. hash = calculateMD5(hash, 0, keyLengthInBytes);
  21898. }
  21899. }
  21900. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  21901. var cipher, checkData;
  21902. if (revision >= 3) {
  21903. for (i = 0; i < 32; ++i) {
  21904. hashData[i] = defaultPasswordBytes[i];
  21905. }
  21906. for (j = 0, n = fileId.length; j < n; ++j) {
  21907. hashData[i++] = fileId[j];
  21908. }
  21909. cipher = new ARCFourCipher(encryptionKey);
  21910. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  21911. n = encryptionKey.length;
  21912. var derivedKey = new Uint8Array(n), k;
  21913. for (j = 1; j <= 19; ++j) {
  21914. for (k = 0; k < n; ++k) {
  21915. derivedKey[k] = encryptionKey[k] ^ j;
  21916. }
  21917. cipher = new ARCFourCipher(derivedKey);
  21918. checkData = cipher.encryptBlock(checkData);
  21919. }
  21920. for (j = 0, n = checkData.length; j < n; ++j) {
  21921. if (userPassword[j] !== checkData[j]) {
  21922. return null;
  21923. }
  21924. }
  21925. } else {
  21926. cipher = new ARCFourCipher(encryptionKey);
  21927. checkData = cipher.encryptBlock(defaultPasswordBytes);
  21928. for (j = 0, n = checkData.length; j < n; ++j) {
  21929. if (userPassword[j] !== checkData[j]) {
  21930. return null;
  21931. }
  21932. }
  21933. }
  21934. return encryptionKey;
  21935. }
  21936. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  21937. var hashData = new Uint8Array(32), i = 0, j, n;
  21938. n = Math.min(32, password.length);
  21939. for (; i < n; ++i) {
  21940. hashData[i] = password[i];
  21941. }
  21942. j = 0;
  21943. while (i < 32) {
  21944. hashData[i++] = defaultPasswordBytes[j++];
  21945. }
  21946. var hash = calculateMD5(hashData, 0, i);
  21947. var keyLengthInBytes = keyLength >> 3;
  21948. if (revision >= 3) {
  21949. for (j = 0; j < 50; ++j) {
  21950. hash = calculateMD5(hash, 0, hash.length);
  21951. }
  21952. }
  21953. var cipher, userPassword;
  21954. if (revision >= 3) {
  21955. userPassword = ownerPassword;
  21956. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  21957. for (j = 19; j >= 0; j--) {
  21958. for (k = 0; k < keyLengthInBytes; ++k) {
  21959. derivedKey[k] = hash[k] ^ j;
  21960. }
  21961. cipher = new ARCFourCipher(derivedKey);
  21962. userPassword = cipher.encryptBlock(userPassword);
  21963. }
  21964. } else {
  21965. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  21966. userPassword = cipher.encryptBlock(ownerPassword);
  21967. }
  21968. return userPassword;
  21969. }
  21970. var identityName = Name.get('Identity');
  21971. function CipherTransformFactory(dict, fileId, password) {
  21972. var filter = dict.get('Filter');
  21973. if (!isName(filter) || filter.name !== 'Standard') {
  21974. error('unknown encryption method');
  21975. }
  21976. this.dict = dict;
  21977. var algorithm = dict.get('V');
  21978. if (!isInt(algorithm) ||
  21979. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  21980. algorithm !== 5)) {
  21981. error('unsupported encryption algorithm');
  21982. }
  21983. this.algorithm = algorithm;
  21984. var keyLength = dict.get('Length');
  21985. if (!keyLength) {
  21986. // Spec asks to rely on encryption dictionary's Length entry, however
  21987. // some PDFs don't have it. Trying to recover.
  21988. if (algorithm <= 3) {
  21989. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  21990. keyLength = 40;
  21991. } else {
  21992. // Trying to find default handler -- it usually has Length.
  21993. var cfDict = dict.get('CF');
  21994. var streamCryptoName = dict.get('StmF');
  21995. if (isDict(cfDict) && isName(streamCryptoName)) {
  21996. var handlerDict = cfDict.get(streamCryptoName.name);
  21997. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  21998. if (keyLength < 40) {
  21999. // Sometimes it's incorrect value of bits, generators specify bytes.
  22000. keyLength <<= 3;
  22001. }
  22002. }
  22003. }
  22004. }
  22005. if (!isInt(keyLength) ||
  22006. keyLength < 40 || (keyLength % 8) !== 0) {
  22007. error('invalid key length');
  22008. }
  22009. // prepare keys
  22010. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  22011. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  22012. var flags = dict.get('P');
  22013. var revision = dict.get('R');
  22014. // meaningful when V is 4 or 5
  22015. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  22016. dict.get('EncryptMetadata') !== false);
  22017. this.encryptMetadata = encryptMetadata;
  22018. var fileIdBytes = stringToBytes(fileId);
  22019. var passwordBytes;
  22020. if (password) {
  22021. if (revision === 6) {
  22022. try {
  22023. password = utf8StringToString(password);
  22024. } catch (ex) {
  22025. warn('CipherTransformFactory: ' +
  22026. 'Unable to convert UTF8 encoded password.');
  22027. }
  22028. }
  22029. passwordBytes = stringToBytes(password);
  22030. }
  22031. var encryptionKey;
  22032. if (algorithm !== 5) {
  22033. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  22034. ownerPassword, userPassword, flags,
  22035. revision, keyLength, encryptMetadata);
  22036. }
  22037. else {
  22038. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  22039. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  22040. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  22041. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  22042. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  22043. var ownerEncryption = stringToBytes(dict.get('OE'));
  22044. var userEncryption = stringToBytes(dict.get('UE'));
  22045. var perms = stringToBytes(dict.get('Perms'));
  22046. encryptionKey =
  22047. createEncryptionKey20(revision, passwordBytes,
  22048. ownerPassword, ownerValidationSalt,
  22049. ownerKeySalt, uBytes,
  22050. userPassword, userValidationSalt,
  22051. userKeySalt, ownerEncryption,
  22052. userEncryption, perms);
  22053. }
  22054. if (!encryptionKey && !password) {
  22055. throw new PasswordException('No password given',
  22056. PasswordResponses.NEED_PASSWORD);
  22057. } else if (!encryptionKey && password) {
  22058. // Attempting use the password as an owner password
  22059. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  22060. revision, keyLength);
  22061. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  22062. ownerPassword, userPassword, flags,
  22063. revision, keyLength, encryptMetadata);
  22064. }
  22065. if (!encryptionKey) {
  22066. throw new PasswordException('Incorrect Password',
  22067. PasswordResponses.INCORRECT_PASSWORD);
  22068. }
  22069. this.encryptionKey = encryptionKey;
  22070. if (algorithm >= 4) {
  22071. this.cf = dict.get('CF');
  22072. this.stmf = dict.get('StmF') || identityName;
  22073. this.strf = dict.get('StrF') || identityName;
  22074. this.eff = dict.get('EFF') || this.stmf;
  22075. }
  22076. }
  22077. function buildObjectKey(num, gen, encryptionKey, isAes) {
  22078. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  22079. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  22080. key[i] = encryptionKey[i];
  22081. }
  22082. key[i++] = num & 0xFF;
  22083. key[i++] = (num >> 8) & 0xFF;
  22084. key[i++] = (num >> 16) & 0xFF;
  22085. key[i++] = gen & 0xFF;
  22086. key[i++] = (gen >> 8) & 0xFF;
  22087. if (isAes) {
  22088. key[i++] = 0x73;
  22089. key[i++] = 0x41;
  22090. key[i++] = 0x6C;
  22091. key[i++] = 0x54;
  22092. }
  22093. var hash = calculateMD5(key, 0, i);
  22094. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  22095. }
  22096. function buildCipherConstructor(cf, name, num, gen, key) {
  22097. var cryptFilter = cf.get(name.name);
  22098. var cfm;
  22099. if (cryptFilter !== null && cryptFilter !== undefined) {
  22100. cfm = cryptFilter.get('CFM');
  22101. }
  22102. if (!cfm || cfm.name === 'None') {
  22103. return function cipherTransformFactoryBuildCipherConstructorNone() {
  22104. return new NullCipher();
  22105. };
  22106. }
  22107. if ('V2' === cfm.name) {
  22108. return function cipherTransformFactoryBuildCipherConstructorV2() {
  22109. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  22110. };
  22111. }
  22112. if ('AESV2' === cfm.name) {
  22113. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  22114. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  22115. };
  22116. }
  22117. if ('AESV3' === cfm.name) {
  22118. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  22119. return new AES256Cipher(key);
  22120. };
  22121. }
  22122. error('Unknown crypto method');
  22123. }
  22124. CipherTransformFactory.prototype = {
  22125. createCipherTransform:
  22126. function CipherTransformFactory_createCipherTransform(num, gen) {
  22127. if (this.algorithm === 4 || this.algorithm === 5) {
  22128. return new CipherTransform(
  22129. buildCipherConstructor(this.cf, this.stmf,
  22130. num, gen, this.encryptionKey),
  22131. buildCipherConstructor(this.cf, this.strf,
  22132. num, gen, this.encryptionKey));
  22133. }
  22134. // algorithms 1 and 2
  22135. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  22136. var cipherConstructor = function buildCipherCipherConstructor() {
  22137. return new ARCFourCipher(key);
  22138. };
  22139. return new CipherTransform(cipherConstructor, cipherConstructor);
  22140. }
  22141. };
  22142. return CipherTransformFactory;
  22143. })();
  22144. exports.AES128Cipher = AES128Cipher;
  22145. exports.AES256Cipher = AES256Cipher;
  22146. exports.ARCFourCipher = ARCFourCipher;
  22147. exports.CipherTransformFactory = CipherTransformFactory;
  22148. exports.PDF17 = PDF17;
  22149. exports.PDF20 = PDF20;
  22150. exports.calculateMD5 = calculateMD5;
  22151. exports.calculateSHA256 = calculateSHA256;
  22152. exports.calculateSHA384 = calculateSHA384;
  22153. exports.calculateSHA512 = calculateSHA512;
  22154. }));
  22155. (function (root, factory) {
  22156. {
  22157. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  22158. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  22159. }
  22160. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  22161. var Util = sharedUtil.Util;
  22162. var bytesToString = sharedUtil.bytesToString;
  22163. var error = sharedUtil.error;
  22164. var Stream = coreStream.Stream;
  22165. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  22166. var coreFonts; // see _setCoreFonts below
  22167. var CFFParser; // = coreFonts.CFFParser;
  22168. var Encodings; // = coreFonts.Encodings;
  22169. var FontRendererFactory = (function FontRendererFactoryClosure() {
  22170. function getLong(data, offset) {
  22171. return (data[offset] << 24) | (data[offset + 1] << 16) |
  22172. (data[offset + 2] << 8) | data[offset + 3];
  22173. }
  22174. function getUshort(data, offset) {
  22175. return (data[offset] << 8) | data[offset + 1];
  22176. }
  22177. function parseCmap(data, start, end) {
  22178. var offset = (getUshort(data, start + 2) === 1 ?
  22179. getLong(data, start + 8) : getLong(data, start + 16));
  22180. var format = getUshort(data, start + offset);
  22181. var length, ranges, p, i;
  22182. if (format === 4) {
  22183. length = getUshort(data, start + offset + 2);
  22184. var segCount = getUshort(data, start + offset + 6) >> 1;
  22185. p = start + offset + 14;
  22186. ranges = [];
  22187. for (i = 0; i < segCount; i++, p += 2) {
  22188. ranges[i] = {end: getUshort(data, p)};
  22189. }
  22190. p += 2;
  22191. for (i = 0; i < segCount; i++, p += 2) {
  22192. ranges[i].start = getUshort(data, p);
  22193. }
  22194. for (i = 0; i < segCount; i++, p += 2) {
  22195. ranges[i].idDelta = getUshort(data, p);
  22196. }
  22197. for (i = 0; i < segCount; i++, p += 2) {
  22198. var idOffset = getUshort(data, p);
  22199. if (idOffset === 0) {
  22200. continue;
  22201. }
  22202. ranges[i].ids = [];
  22203. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  22204. ranges[i].ids[j] = getUshort(data, p + idOffset);
  22205. idOffset += 2;
  22206. }
  22207. }
  22208. return ranges;
  22209. } else if (format === 12) {
  22210. length = getLong(data, start + offset + 4);
  22211. var groups = getLong(data, start + offset + 12);
  22212. p = start + offset + 16;
  22213. ranges = [];
  22214. for (i = 0; i < groups; i++) {
  22215. ranges.push({
  22216. start: getLong(data, p),
  22217. end: getLong(data, p + 4),
  22218. idDelta: getLong(data, p + 8) - getLong(data, p)
  22219. });
  22220. p += 12;
  22221. }
  22222. return ranges;
  22223. }
  22224. error('not supported cmap: ' + format);
  22225. }
  22226. function parseCff(data, start, end) {
  22227. var properties = {};
  22228. var parser = new CFFParser(new Stream(data, start, end - start),
  22229. properties);
  22230. var cff = parser.parse();
  22231. return {
  22232. glyphs: cff.charStrings.objects,
  22233. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  22234. cff.topDict.privateDict.subrsIndex.objects),
  22235. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  22236. };
  22237. }
  22238. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  22239. var itemSize, itemDecode;
  22240. if (isGlyphLocationsLong) {
  22241. itemSize = 4;
  22242. itemDecode = function fontItemDecodeLong(data, offset) {
  22243. return (data[offset] << 24) | (data[offset + 1] << 16) |
  22244. (data[offset + 2] << 8) | data[offset + 3];
  22245. };
  22246. } else {
  22247. itemSize = 2;
  22248. itemDecode = function fontItemDecode(data, offset) {
  22249. return (data[offset] << 9) | (data[offset + 1] << 1);
  22250. };
  22251. }
  22252. var glyphs = [];
  22253. var startOffset = itemDecode(loca, 0);
  22254. for (var j = itemSize; j < loca.length; j += itemSize) {
  22255. var endOffset = itemDecode(loca, j);
  22256. glyphs.push(glyf.subarray(startOffset, endOffset));
  22257. startOffset = endOffset;
  22258. }
  22259. return glyphs;
  22260. }
  22261. function lookupCmap(ranges, unicode) {
  22262. var code = unicode.charCodeAt(0);
  22263. var l = 0, r = ranges.length - 1;
  22264. while (l < r) {
  22265. var c = (l + r + 1) >> 1;
  22266. if (code < ranges[c].start) {
  22267. r = c - 1;
  22268. } else {
  22269. l = c;
  22270. }
  22271. }
  22272. if (ranges[l].start <= code && code <= ranges[l].end) {
  22273. return (ranges[l].idDelta + (ranges[l].ids ?
  22274. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  22275. }
  22276. return 0;
  22277. }
  22278. function compileGlyf(code, cmds, font) {
  22279. function moveTo(x, y) {
  22280. cmds.push({cmd: 'moveTo', args: [x, y]});
  22281. }
  22282. function lineTo(x, y) {
  22283. cmds.push({cmd: 'lineTo', args: [x, y]});
  22284. }
  22285. function quadraticCurveTo(xa, ya, x, y) {
  22286. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  22287. }
  22288. var i = 0;
  22289. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22290. var flags;
  22291. var x = 0, y = 0;
  22292. i += 10;
  22293. if (numberOfContours < 0) {
  22294. // composite glyph
  22295. do {
  22296. flags = (code[i] << 8) | code[i + 1];
  22297. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  22298. i += 4;
  22299. var arg1, arg2;
  22300. if ((flags & 0x01)) {
  22301. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22302. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  22303. i += 4;
  22304. } else {
  22305. arg1 = code[i++]; arg2 = code[i++];
  22306. }
  22307. if ((flags & 0x02)) {
  22308. x = arg1;
  22309. y = arg2;
  22310. } else {
  22311. x = 0; y = 0; // TODO "they are points" ?
  22312. }
  22313. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  22314. if ((flags & 0x08)) {
  22315. scaleX =
  22316. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  22317. i += 2;
  22318. } else if ((flags & 0x40)) {
  22319. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  22320. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  22321. i += 4;
  22322. } else if ((flags & 0x80)) {
  22323. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  22324. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  22325. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  22326. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  22327. i += 8;
  22328. }
  22329. var subglyph = font.glyphs[glyphIndex];
  22330. if (subglyph) {
  22331. cmds.push({cmd: 'save'});
  22332. cmds.push({cmd: 'transform',
  22333. args: [scaleX, scale01, scale10, scaleY, x, y]});
  22334. compileGlyf(subglyph, cmds, font);
  22335. cmds.push({cmd: 'restore'});
  22336. }
  22337. } while ((flags & 0x20));
  22338. } else {
  22339. // simple glyph
  22340. var endPtsOfContours = [];
  22341. var j, jj;
  22342. for (j = 0; j < numberOfContours; j++) {
  22343. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  22344. i += 2;
  22345. }
  22346. var instructionLength = (code[i] << 8) | code[i + 1];
  22347. i += 2 + instructionLength; // skipping the instructions
  22348. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  22349. var points = [];
  22350. while (points.length < numberOfPoints) {
  22351. flags = code[i++];
  22352. var repeat = 1;
  22353. if ((flags & 0x08)) {
  22354. repeat += code[i++];
  22355. }
  22356. while (repeat-- > 0) {
  22357. points.push({flags: flags});
  22358. }
  22359. }
  22360. for (j = 0; j < numberOfPoints; j++) {
  22361. switch (points[j].flags & 0x12) {
  22362. case 0x00:
  22363. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22364. i += 2;
  22365. break;
  22366. case 0x02:
  22367. x -= code[i++];
  22368. break;
  22369. case 0x12:
  22370. x += code[i++];
  22371. break;
  22372. }
  22373. points[j].x = x;
  22374. }
  22375. for (j = 0; j < numberOfPoints; j++) {
  22376. switch (points[j].flags & 0x24) {
  22377. case 0x00:
  22378. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22379. i += 2;
  22380. break;
  22381. case 0x04:
  22382. y -= code[i++];
  22383. break;
  22384. case 0x24:
  22385. y += code[i++];
  22386. break;
  22387. }
  22388. points[j].y = y;
  22389. }
  22390. var startPoint = 0;
  22391. for (i = 0; i < numberOfContours; i++) {
  22392. var endPoint = endPtsOfContours[i];
  22393. // contours might have implicit points, which is located in the middle
  22394. // between two neighboring off-curve points
  22395. var contour = points.slice(startPoint, endPoint + 1);
  22396. if ((contour[0].flags & 1)) {
  22397. contour.push(contour[0]); // using start point at the contour end
  22398. } else if ((contour[contour.length - 1].flags & 1)) {
  22399. // first is off-curve point, trying to use one from the end
  22400. contour.unshift(contour[contour.length - 1]);
  22401. } else {
  22402. // start and end are off-curve points, creating implicit one
  22403. var p = {
  22404. flags: 1,
  22405. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  22406. y: (contour[0].y + contour[contour.length - 1].y) / 2
  22407. };
  22408. contour.unshift(p);
  22409. contour.push(p);
  22410. }
  22411. moveTo(contour[0].x, contour[0].y);
  22412. for (j = 1, jj = contour.length; j < jj; j++) {
  22413. if ((contour[j].flags & 1)) {
  22414. lineTo(contour[j].x, contour[j].y);
  22415. } else if ((contour[j + 1].flags & 1)){
  22416. quadraticCurveTo(contour[j].x, contour[j].y,
  22417. contour[j + 1].x, contour[j + 1].y);
  22418. j++;
  22419. } else {
  22420. quadraticCurveTo(contour[j].x, contour[j].y,
  22421. (contour[j].x + contour[j + 1].x) / 2,
  22422. (contour[j].y + contour[j + 1].y) / 2);
  22423. }
  22424. }
  22425. startPoint = endPoint + 1;
  22426. }
  22427. }
  22428. }
  22429. function compileCharString(code, cmds, font) {
  22430. var stack = [];
  22431. var x = 0, y = 0;
  22432. var stems = 0;
  22433. function moveTo(x, y) {
  22434. cmds.push({cmd: 'moveTo', args: [x, y]});
  22435. }
  22436. function lineTo(x, y) {
  22437. cmds.push({cmd: 'lineTo', args: [x, y]});
  22438. }
  22439. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  22440. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  22441. }
  22442. function parse(code) {
  22443. var i = 0;
  22444. while (i < code.length) {
  22445. var stackClean = false;
  22446. var v = code[i++];
  22447. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  22448. switch (v) {
  22449. case 1: // hstem
  22450. stems += stack.length >> 1;
  22451. stackClean = true;
  22452. break;
  22453. case 3: // vstem
  22454. stems += stack.length >> 1;
  22455. stackClean = true;
  22456. break;
  22457. case 4: // vmoveto
  22458. y += stack.pop();
  22459. moveTo(x, y);
  22460. stackClean = true;
  22461. break;
  22462. case 5: // rlineto
  22463. while (stack.length > 0) {
  22464. x += stack.shift();
  22465. y += stack.shift();
  22466. lineTo(x, y);
  22467. }
  22468. break;
  22469. case 6: // hlineto
  22470. while (stack.length > 0) {
  22471. x += stack.shift();
  22472. lineTo(x, y);
  22473. if (stack.length === 0) {
  22474. break;
  22475. }
  22476. y += stack.shift();
  22477. lineTo(x, y);
  22478. }
  22479. break;
  22480. case 7: // vlineto
  22481. while (stack.length > 0) {
  22482. y += stack.shift();
  22483. lineTo(x, y);
  22484. if (stack.length === 0) {
  22485. break;
  22486. }
  22487. x += stack.shift();
  22488. lineTo(x, y);
  22489. }
  22490. break;
  22491. case 8: // rrcurveto
  22492. while (stack.length > 0) {
  22493. xa = x + stack.shift(); ya = y + stack.shift();
  22494. xb = xa + stack.shift(); yb = ya + stack.shift();
  22495. x = xb + stack.shift(); y = yb + stack.shift();
  22496. bezierCurveTo(xa, ya, xb, yb, x, y);
  22497. }
  22498. break;
  22499. case 10: // callsubr
  22500. n = stack.pop() + font.subrsBias;
  22501. subrCode = font.subrs[n];
  22502. if (subrCode) {
  22503. parse(subrCode);
  22504. }
  22505. break;
  22506. case 11: // return
  22507. return;
  22508. case 12:
  22509. v = code[i++];
  22510. switch (v) {
  22511. case 34: // flex
  22512. xa = x + stack.shift();
  22513. xb = xa + stack.shift(); y1 = y + stack.shift();
  22514. x = xb + stack.shift();
  22515. bezierCurveTo(xa, y, xb, y1, x, y1);
  22516. xa = x + stack.shift();
  22517. xb = xa + stack.shift();
  22518. x = xb + stack.shift();
  22519. bezierCurveTo(xa, y1, xb, y, x, y);
  22520. break;
  22521. case 35: // flex
  22522. xa = x + stack.shift(); ya = y + stack.shift();
  22523. xb = xa + stack.shift(); yb = ya + stack.shift();
  22524. x = xb + stack.shift(); y = yb + stack.shift();
  22525. bezierCurveTo(xa, ya, xb, yb, x, y);
  22526. xa = x + stack.shift(); ya = y + stack.shift();
  22527. xb = xa + stack.shift(); yb = ya + stack.shift();
  22528. x = xb + stack.shift(); y = yb + stack.shift();
  22529. bezierCurveTo(xa, ya, xb, yb, x, y);
  22530. stack.pop(); // fd
  22531. break;
  22532. case 36: // hflex1
  22533. xa = x + stack.shift(); y1 = y + stack.shift();
  22534. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  22535. x = xb + stack.shift();
  22536. bezierCurveTo(xa, y1, xb, y2, x, y2);
  22537. xa = x + stack.shift();
  22538. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  22539. x = xb + stack.shift();
  22540. bezierCurveTo(xa, y2, xb, y3, x, y);
  22541. break;
  22542. case 37: // flex1
  22543. var x0 = x, y0 = y;
  22544. xa = x + stack.shift(); ya = y + stack.shift();
  22545. xb = xa + stack.shift(); yb = ya + stack.shift();
  22546. x = xb + stack.shift(); y = yb + stack.shift();
  22547. bezierCurveTo(xa, ya, xb, yb, x, y);
  22548. xa = x + stack.shift(); ya = y + stack.shift();
  22549. xb = xa + stack.shift(); yb = ya + stack.shift();
  22550. x = xb; y = yb;
  22551. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  22552. x += stack.shift();
  22553. } else {
  22554. y += stack.shift();
  22555. }
  22556. bezierCurveTo(xa, ya, xb, yb, x, y);
  22557. break;
  22558. default:
  22559. error('unknown operator: 12 ' + v);
  22560. }
  22561. break;
  22562. case 14: // endchar
  22563. if (stack.length >= 4) {
  22564. var achar = stack.pop();
  22565. var bchar = stack.pop();
  22566. y = stack.pop();
  22567. x = stack.pop();
  22568. cmds.push({cmd: 'save'});
  22569. cmds.push({cmd: 'translate', args: [x, y]});
  22570. var gid = lookupCmap(font.cmap, String.fromCharCode(
  22571. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  22572. compileCharString(font.glyphs[gid], cmds, font);
  22573. cmds.push({cmd: 'restore'});
  22574. gid = lookupCmap(font.cmap, String.fromCharCode(
  22575. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  22576. compileCharString(font.glyphs[gid], cmds, font);
  22577. }
  22578. return;
  22579. case 18: // hstemhm
  22580. stems += stack.length >> 1;
  22581. stackClean = true;
  22582. break;
  22583. case 19: // hintmask
  22584. stems += stack.length >> 1;
  22585. i += (stems + 7) >> 3;
  22586. stackClean = true;
  22587. break;
  22588. case 20: // cntrmask
  22589. stems += stack.length >> 1;
  22590. i += (stems + 7) >> 3;
  22591. stackClean = true;
  22592. break;
  22593. case 21: // rmoveto
  22594. y += stack.pop();
  22595. x += stack.pop();
  22596. moveTo(x, y);
  22597. stackClean = true;
  22598. break;
  22599. case 22: // hmoveto
  22600. x += stack.pop();
  22601. moveTo(x, y);
  22602. stackClean = true;
  22603. break;
  22604. case 23: // vstemhm
  22605. stems += stack.length >> 1;
  22606. stackClean = true;
  22607. break;
  22608. case 24: // rcurveline
  22609. while (stack.length > 2) {
  22610. xa = x + stack.shift(); ya = y + stack.shift();
  22611. xb = xa + stack.shift(); yb = ya + stack.shift();
  22612. x = xb + stack.shift(); y = yb + stack.shift();
  22613. bezierCurveTo(xa, ya, xb, yb, x, y);
  22614. }
  22615. x += stack.shift();
  22616. y += stack.shift();
  22617. lineTo(x, y);
  22618. break;
  22619. case 25: // rlinecurve
  22620. while (stack.length > 6) {
  22621. x += stack.shift();
  22622. y += stack.shift();
  22623. lineTo(x, y);
  22624. }
  22625. xa = x + stack.shift(); ya = y + stack.shift();
  22626. xb = xa + stack.shift(); yb = ya + stack.shift();
  22627. x = xb + stack.shift(); y = yb + stack.shift();
  22628. bezierCurveTo(xa, ya, xb, yb, x, y);
  22629. break;
  22630. case 26: // vvcurveto
  22631. if (stack.length % 2) {
  22632. x += stack.shift();
  22633. }
  22634. while (stack.length > 0) {
  22635. xa = x; ya = y + stack.shift();
  22636. xb = xa + stack.shift(); yb = ya + stack.shift();
  22637. x = xb; y = yb + stack.shift();
  22638. bezierCurveTo(xa, ya, xb, yb, x, y);
  22639. }
  22640. break;
  22641. case 27: // hhcurveto
  22642. if (stack.length % 2) {
  22643. y += stack.shift();
  22644. }
  22645. while (stack.length > 0) {
  22646. xa = x + stack.shift(); ya = y;
  22647. xb = xa + stack.shift(); yb = ya + stack.shift();
  22648. x = xb + stack.shift(); y = yb;
  22649. bezierCurveTo(xa, ya, xb, yb, x, y);
  22650. }
  22651. break;
  22652. case 28:
  22653. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  22654. i += 2;
  22655. break;
  22656. case 29: // callgsubr
  22657. n = stack.pop() + font.gsubrsBias;
  22658. subrCode = font.gsubrs[n];
  22659. if (subrCode) {
  22660. parse(subrCode);
  22661. }
  22662. break;
  22663. case 30: // vhcurveto
  22664. while (stack.length > 0) {
  22665. xa = x; ya = y + stack.shift();
  22666. xb = xa + stack.shift(); yb = ya + stack.shift();
  22667. x = xb + stack.shift();
  22668. y = yb + (stack.length === 1 ? stack.shift() : 0);
  22669. bezierCurveTo(xa, ya, xb, yb, x, y);
  22670. if (stack.length === 0) {
  22671. break;
  22672. }
  22673. xa = x + stack.shift(); ya = y;
  22674. xb = xa + stack.shift(); yb = ya + stack.shift();
  22675. y = yb + stack.shift();
  22676. x = xb + (stack.length === 1 ? stack.shift() : 0);
  22677. bezierCurveTo(xa, ya, xb, yb, x, y);
  22678. }
  22679. break;
  22680. case 31: // hvcurveto
  22681. while (stack.length > 0) {
  22682. xa = x + stack.shift(); ya = y;
  22683. xb = xa + stack.shift(); yb = ya + stack.shift();
  22684. y = yb + stack.shift();
  22685. x = xb + (stack.length === 1 ? stack.shift() : 0);
  22686. bezierCurveTo(xa, ya, xb, yb, x, y);
  22687. if (stack.length === 0) {
  22688. break;
  22689. }
  22690. xa = x; ya = y + stack.shift();
  22691. xb = xa + stack.shift(); yb = ya + stack.shift();
  22692. x = xb + stack.shift();
  22693. y = yb + (stack.length === 1 ? stack.shift() : 0);
  22694. bezierCurveTo(xa, ya, xb, yb, x, y);
  22695. }
  22696. break;
  22697. default:
  22698. if (v < 32) {
  22699. error('unknown operator: ' + v);
  22700. }
  22701. if (v < 247) {
  22702. stack.push(v - 139);
  22703. } else if (v < 251) {
  22704. stack.push((v - 247) * 256 + code[i++] + 108);
  22705. } else if (v < 255) {
  22706. stack.push(-(v - 251) * 256 - code[i++] - 108);
  22707. } else {
  22708. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  22709. (code[i + 2] << 8) | code[i + 3]) / 65536);
  22710. i += 4;
  22711. }
  22712. break;
  22713. }
  22714. if (stackClean) {
  22715. stack.length = 0;
  22716. }
  22717. }
  22718. }
  22719. parse(code);
  22720. }
  22721. var noop = '';
  22722. function CompiledFont(fontMatrix) {
  22723. this.compiledGlyphs = {};
  22724. this.fontMatrix = fontMatrix;
  22725. }
  22726. CompiledFont.prototype = {
  22727. getPathJs: function (unicode) {
  22728. var gid = lookupCmap(this.cmap, unicode);
  22729. var fn = this.compiledGlyphs[gid];
  22730. if (!fn) {
  22731. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  22732. }
  22733. return fn;
  22734. },
  22735. compileGlyph: function (code) {
  22736. if (!code || code.length === 0 || code[0] === 14) {
  22737. return noop;
  22738. }
  22739. var cmds = [];
  22740. cmds.push({cmd: 'save'});
  22741. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  22742. cmds.push({cmd: 'scale', args: ['size', '-size']});
  22743. this.compileGlyphImpl(code, cmds);
  22744. cmds.push({cmd: 'restore'});
  22745. return cmds;
  22746. },
  22747. compileGlyphImpl: function () {
  22748. error('Children classes should implement this.');
  22749. },
  22750. hasBuiltPath: function (unicode) {
  22751. var gid = lookupCmap(this.cmap, unicode);
  22752. return gid in this.compiledGlyphs;
  22753. }
  22754. };
  22755. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  22756. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  22757. CompiledFont.call(this, fontMatrix);
  22758. this.glyphs = glyphs;
  22759. this.cmap = cmap;
  22760. this.compiledGlyphs = [];
  22761. }
  22762. Util.inherit(TrueTypeCompiled, CompiledFont, {
  22763. compileGlyphImpl: function (code, cmds) {
  22764. compileGlyf(code, cmds, this);
  22765. }
  22766. });
  22767. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  22768. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  22769. CompiledFont.call(this, fontMatrix);
  22770. this.glyphs = cffInfo.glyphs;
  22771. this.gsubrs = cffInfo.gsubrs || [];
  22772. this.subrs = cffInfo.subrs || [];
  22773. this.cmap = cmap;
  22774. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  22775. this.compiledGlyphs = [];
  22776. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  22777. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  22778. this.subrsBias = (this.subrs.length < 1240 ?
  22779. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  22780. }
  22781. Util.inherit(Type2Compiled, CompiledFont, {
  22782. compileGlyphImpl: function (code, cmds) {
  22783. compileCharString(code, cmds, this);
  22784. }
  22785. });
  22786. return {
  22787. create: function FontRendererFactory_create(font) {
  22788. var data = new Uint8Array(font.data);
  22789. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  22790. var numTables = getUshort(data, 4);
  22791. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  22792. var tag = bytesToString(data.subarray(p, p + 4));
  22793. var offset = getLong(data, p + 8);
  22794. var length = getLong(data, p + 12);
  22795. switch (tag) {
  22796. case 'cmap':
  22797. cmap = parseCmap(data, offset, offset + length);
  22798. break;
  22799. case 'glyf':
  22800. glyf = data.subarray(offset, offset + length);
  22801. break;
  22802. case 'loca':
  22803. loca = data.subarray(offset, offset + length);
  22804. break;
  22805. case 'head':
  22806. unitsPerEm = getUshort(data, offset + 18);
  22807. indexToLocFormat = getUshort(data, offset + 50);
  22808. break;
  22809. case 'CFF ':
  22810. cff = parseCff(data, offset, offset + length);
  22811. break;
  22812. }
  22813. }
  22814. if (glyf) {
  22815. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  22816. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  22817. return new TrueTypeCompiled(
  22818. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  22819. } else {
  22820. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  22821. }
  22822. }
  22823. };
  22824. })();
  22825. // TODO refactor to remove cyclic dependency on fonts.js
  22826. function _setCoreFonts(coreFonts_) {
  22827. coreFonts = coreFonts_;
  22828. Encodings = coreFonts_.Encodings;
  22829. CFFParser = coreFonts_.CFFParser;
  22830. }
  22831. exports._setCoreFonts = _setCoreFonts;
  22832. exports.FontRendererFactory = FontRendererFactory;
  22833. }));
  22834. (function (root, factory) {
  22835. {
  22836. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  22837. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  22838. }
  22839. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  22840. var MissingDataException = sharedUtil.MissingDataException;
  22841. var StreamType = sharedUtil.StreamType;
  22842. var assert = sharedUtil.assert;
  22843. var error = sharedUtil.error;
  22844. var info = sharedUtil.info;
  22845. var isArray = sharedUtil.isArray;
  22846. var isInt = sharedUtil.isInt;
  22847. var isNum = sharedUtil.isNum;
  22848. var isString = sharedUtil.isString;
  22849. var warn = sharedUtil.warn;
  22850. var Cmd = corePrimitives.Cmd;
  22851. var Dict = corePrimitives.Dict;
  22852. var Name = corePrimitives.Name;
  22853. var Ref = corePrimitives.Ref;
  22854. var isCmd = corePrimitives.isCmd;
  22855. var isDict = corePrimitives.isDict;
  22856. var isName = corePrimitives.isName;
  22857. var Ascii85Stream = coreStream.Ascii85Stream;
  22858. var AsciiHexStream = coreStream.AsciiHexStream;
  22859. var CCITTFaxStream = coreStream.CCITTFaxStream;
  22860. var FlateStream = coreStream.FlateStream;
  22861. var Jbig2Stream = coreStream.Jbig2Stream;
  22862. var JpegStream = coreStream.JpegStream;
  22863. var JpxStream = coreStream.JpxStream;
  22864. var LZWStream = coreStream.LZWStream;
  22865. var NullStream = coreStream.NullStream;
  22866. var PredictorStream = coreStream.PredictorStream;
  22867. var RunLengthStream = coreStream.RunLengthStream;
  22868. var EOF = {};
  22869. function isEOF(v) {
  22870. return (v === EOF);
  22871. }
  22872. var MAX_LENGTH_TO_CACHE = 1000;
  22873. var Parser = (function ParserClosure() {
  22874. function Parser(lexer, allowStreams, xref) {
  22875. this.lexer = lexer;
  22876. this.allowStreams = allowStreams;
  22877. this.xref = xref;
  22878. this.imageCache = {};
  22879. this.refill();
  22880. }
  22881. Parser.prototype = {
  22882. refill: function Parser_refill() {
  22883. this.buf1 = this.lexer.getObj();
  22884. this.buf2 = this.lexer.getObj();
  22885. },
  22886. shift: function Parser_shift() {
  22887. if (isCmd(this.buf2, 'ID')) {
  22888. this.buf1 = this.buf2;
  22889. this.buf2 = null;
  22890. } else {
  22891. this.buf1 = this.buf2;
  22892. this.buf2 = this.lexer.getObj();
  22893. }
  22894. },
  22895. tryShift: function Parser_tryShift() {
  22896. try {
  22897. this.shift();
  22898. return true;
  22899. } catch (e) {
  22900. if (e instanceof MissingDataException) {
  22901. throw e;
  22902. }
  22903. // Upon failure, the caller should reset this.lexer.pos to a known good
  22904. // state and call this.shift() twice to reset the buffers.
  22905. return false;
  22906. }
  22907. },
  22908. getObj: function Parser_getObj(cipherTransform) {
  22909. var buf1 = this.buf1;
  22910. this.shift();
  22911. if (buf1 instanceof Cmd) {
  22912. switch (buf1.cmd) {
  22913. case 'BI': // inline image
  22914. return this.makeInlineImage(cipherTransform);
  22915. case '[': // array
  22916. var array = [];
  22917. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  22918. array.push(this.getObj(cipherTransform));
  22919. }
  22920. if (isEOF(this.buf1)) {
  22921. error('End of file inside array');
  22922. }
  22923. this.shift();
  22924. return array;
  22925. case '<<': // dictionary or stream
  22926. var dict = new Dict(this.xref);
  22927. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  22928. if (!isName(this.buf1)) {
  22929. info('Malformed dictionary: key must be a name object');
  22930. this.shift();
  22931. continue;
  22932. }
  22933. var key = this.buf1.name;
  22934. this.shift();
  22935. if (isEOF(this.buf1)) {
  22936. break;
  22937. }
  22938. dict.set(key, this.getObj(cipherTransform));
  22939. }
  22940. if (isEOF(this.buf1)) {
  22941. error('End of file inside dictionary');
  22942. }
  22943. // Stream objects are not allowed inside content streams or
  22944. // object streams.
  22945. if (isCmd(this.buf2, 'stream')) {
  22946. return (this.allowStreams ?
  22947. this.makeStream(dict, cipherTransform) : dict);
  22948. }
  22949. this.shift();
  22950. return dict;
  22951. default: // simple object
  22952. return buf1;
  22953. }
  22954. }
  22955. if (isInt(buf1)) { // indirect reference or integer
  22956. var num = buf1;
  22957. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  22958. var ref = new Ref(num, this.buf1);
  22959. this.shift();
  22960. this.shift();
  22961. return ref;
  22962. }
  22963. return num;
  22964. }
  22965. if (isString(buf1)) { // string
  22966. var str = buf1;
  22967. if (cipherTransform) {
  22968. str = cipherTransform.decryptString(str);
  22969. }
  22970. return str;
  22971. }
  22972. // simple object
  22973. return buf1;
  22974. },
  22975. /**
  22976. * Find the end of the stream by searching for the /EI\s/.
  22977. * @returns {number} The inline stream length.
  22978. */
  22979. findDefaultInlineStreamEnd:
  22980. function Parser_findDefaultInlineStreamEnd(stream) {
  22981. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  22982. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  22983. while ((ch = stream.getByte()) !== -1) {
  22984. if (state === 0) {
  22985. state = (ch === E) ? 1 : 0;
  22986. } else if (state === 1) {
  22987. state = (ch === I) ? 2 : 0;
  22988. } else {
  22989. assert(state === 2);
  22990. if (ch === SPACE || ch === LF || ch === CR) {
  22991. // Let's check the next five bytes are ASCII... just be sure.
  22992. n = 5;
  22993. followingBytes = stream.peekBytes(n);
  22994. for (i = 0; i < n; i++) {
  22995. ch = followingBytes[i];
  22996. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  22997. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  22998. // it's binary stuff. Resetting the state.
  22999. state = 0;
  23000. break;
  23001. }
  23002. }
  23003. if (state === 2) {
  23004. break; // Finished!
  23005. }
  23006. } else {
  23007. state = 0;
  23008. }
  23009. }
  23010. }
  23011. return ((stream.pos - 4) - startPos);
  23012. },
  23013. /**
  23014. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  23015. * @returns {number} The inline stream length.
  23016. */
  23017. findDCTDecodeInlineStreamEnd:
  23018. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  23019. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  23020. while ((b = stream.getByte()) !== -1) {
  23021. if (b !== 0xFF) { // Not a valid marker.
  23022. continue;
  23023. }
  23024. switch (stream.getByte()) {
  23025. case 0x00: // Byte stuffing.
  23026. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  23027. break;
  23028. case 0xFF: // Fill byte.
  23029. // Avoid skipping a valid marker, resetting the stream position.
  23030. stream.skip(-1);
  23031. break;
  23032. case 0xD9: // EOI
  23033. foundEOI = true;
  23034. break;
  23035. case 0xC0: // SOF0
  23036. case 0xC1: // SOF1
  23037. case 0xC2: // SOF2
  23038. case 0xC3: // SOF3
  23039. case 0xC5: // SOF5
  23040. case 0xC6: // SOF6
  23041. case 0xC7: // SOF7
  23042. case 0xC9: // SOF9
  23043. case 0xCA: // SOF10
  23044. case 0xCB: // SOF11
  23045. case 0xCD: // SOF13
  23046. case 0xCE: // SOF14
  23047. case 0xCF: // SOF15
  23048. case 0xC4: // DHT
  23049. case 0xCC: // DAC
  23050. case 0xDA: // SOS
  23051. case 0xDB: // DQT
  23052. case 0xDC: // DNL
  23053. case 0xDD: // DRI
  23054. case 0xDE: // DHP
  23055. case 0xDF: // EXP
  23056. case 0xE0: // APP0
  23057. case 0xE1: // APP1
  23058. case 0xE2: // APP2
  23059. case 0xE3: // APP3
  23060. case 0xE4: // APP4
  23061. case 0xE5: // APP5
  23062. case 0xE6: // APP6
  23063. case 0xE7: // APP7
  23064. case 0xE8: // APP8
  23065. case 0xE9: // APP9
  23066. case 0xEA: // APP10
  23067. case 0xEB: // APP11
  23068. case 0xEC: // APP12
  23069. case 0xED: // APP13
  23070. case 0xEE: // APP14
  23071. case 0xEF: // APP15
  23072. case 0xFE: // COM
  23073. // The marker should be followed by the length of the segment.
  23074. markerLength = stream.getUint16();
  23075. if (markerLength > 2) {
  23076. // |markerLength| contains the byte length of the marker segment,
  23077. // including its own length (2 bytes) and excluding the marker.
  23078. stream.skip(markerLength - 2); // Jump to the next marker.
  23079. } else {
  23080. // The marker length is invalid, resetting the stream position.
  23081. stream.skip(-2);
  23082. }
  23083. break;
  23084. }
  23085. if (foundEOI) {
  23086. break;
  23087. }
  23088. }
  23089. length = stream.pos - startPos;
  23090. if (b === -1) {
  23091. warn('Inline DCTDecode image stream: ' +
  23092. 'EOI marker not found, searching for /EI/ instead.');
  23093. stream.skip(-length); // Reset the stream position.
  23094. return this.findDefaultInlineStreamEnd(stream);
  23095. }
  23096. this.inlineStreamSkipEI(stream);
  23097. return length;
  23098. },
  23099. /**
  23100. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  23101. * @returns {number} The inline stream length.
  23102. */
  23103. findASCII85DecodeInlineStreamEnd:
  23104. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  23105. var TILDE = 0x7E, GT = 0x3E;
  23106. var startPos = stream.pos, ch, length;
  23107. while ((ch = stream.getByte()) !== -1) {
  23108. if (ch === TILDE && stream.peekByte() === GT) {
  23109. stream.skip();
  23110. break;
  23111. }
  23112. }
  23113. length = stream.pos - startPos;
  23114. if (ch === -1) {
  23115. warn('Inline ASCII85Decode image stream: ' +
  23116. 'EOD marker not found, searching for /EI/ instead.');
  23117. stream.skip(-length); // Reset the stream position.
  23118. return this.findDefaultInlineStreamEnd(stream);
  23119. }
  23120. this.inlineStreamSkipEI(stream);
  23121. return length;
  23122. },
  23123. /**
  23124. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  23125. * @returns {number} The inline stream length.
  23126. */
  23127. findASCIIHexDecodeInlineStreamEnd:
  23128. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  23129. var GT = 0x3E;
  23130. var startPos = stream.pos, ch, length;
  23131. while ((ch = stream.getByte()) !== -1) {
  23132. if (ch === GT) {
  23133. break;
  23134. }
  23135. }
  23136. length = stream.pos - startPos;
  23137. if (ch === -1) {
  23138. warn('Inline ASCIIHexDecode image stream: ' +
  23139. 'EOD marker not found, searching for /EI/ instead.');
  23140. stream.skip(-length); // Reset the stream position.
  23141. return this.findDefaultInlineStreamEnd(stream);
  23142. }
  23143. this.inlineStreamSkipEI(stream);
  23144. return length;
  23145. },
  23146. /**
  23147. * Skip over the /EI/ for streams where we search for an EOD marker.
  23148. */
  23149. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  23150. var E = 0x45, I = 0x49;
  23151. var state = 0, ch;
  23152. while ((ch = stream.getByte()) !== -1) {
  23153. if (state === 0) {
  23154. state = (ch === E) ? 1 : 0;
  23155. } else if (state === 1) {
  23156. state = (ch === I) ? 2 : 0;
  23157. } else if (state === 2) {
  23158. break;
  23159. }
  23160. }
  23161. },
  23162. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  23163. var lexer = this.lexer;
  23164. var stream = lexer.stream;
  23165. // Parse dictionary.
  23166. var dict = new Dict(this.xref);
  23167. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  23168. if (!isName(this.buf1)) {
  23169. error('Dictionary key must be a name object');
  23170. }
  23171. var key = this.buf1.name;
  23172. this.shift();
  23173. if (isEOF(this.buf1)) {
  23174. break;
  23175. }
  23176. dict.set(key, this.getObj(cipherTransform));
  23177. }
  23178. // Extract the name of the first (i.e. the current) image filter.
  23179. var filter = dict.get('Filter', 'F'), filterName;
  23180. if (isName(filter)) {
  23181. filterName = filter.name;
  23182. } else if (isArray(filter) && isName(filter[0])) {
  23183. filterName = filter[0].name;
  23184. }
  23185. // Parse image stream.
  23186. var startPos = stream.pos, length, i, ii;
  23187. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  23188. length = this.findDCTDecodeInlineStreamEnd(stream);
  23189. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  23190. length = this.findASCII85DecodeInlineStreamEnd(stream);
  23191. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  23192. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  23193. } else {
  23194. length = this.findDefaultInlineStreamEnd(stream);
  23195. }
  23196. var imageStream = stream.makeSubStream(startPos, length, dict);
  23197. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  23198. // adler32 checksum.
  23199. var adler32;
  23200. if (length < MAX_LENGTH_TO_CACHE) {
  23201. var imageBytes = imageStream.getBytes();
  23202. imageStream.reset();
  23203. var a = 1;
  23204. var b = 0;
  23205. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  23206. // No modulo required in the loop if imageBytes.length < 5552.
  23207. a += imageBytes[i] & 0xff;
  23208. b += a;
  23209. }
  23210. adler32 = ((b % 65521) << 16) | (a % 65521);
  23211. if (this.imageCache.adler32 === adler32) {
  23212. this.buf2 = Cmd.get('EI');
  23213. this.shift();
  23214. this.imageCache[adler32].reset();
  23215. return this.imageCache[adler32];
  23216. }
  23217. }
  23218. if (cipherTransform) {
  23219. imageStream = cipherTransform.createStream(imageStream, length);
  23220. }
  23221. imageStream = this.filter(imageStream, dict, length);
  23222. imageStream.dict = dict;
  23223. if (adler32 !== undefined) {
  23224. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  23225. this.imageCache[adler32] = imageStream;
  23226. }
  23227. this.buf2 = Cmd.get('EI');
  23228. this.shift();
  23229. return imageStream;
  23230. },
  23231. makeStream: function Parser_makeStream(dict, cipherTransform) {
  23232. var lexer = this.lexer;
  23233. var stream = lexer.stream;
  23234. // get stream start position
  23235. lexer.skipToNextLine();
  23236. var pos = stream.pos - 1;
  23237. // get length
  23238. var length = dict.get('Length');
  23239. if (!isInt(length)) {
  23240. info('Bad ' + length + ' attribute in stream');
  23241. length = 0;
  23242. }
  23243. // skip over the stream data
  23244. stream.pos = pos + length;
  23245. lexer.nextChar();
  23246. // Shift '>>' and check whether the new object marks the end of the stream
  23247. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  23248. this.shift(); // 'stream'
  23249. } else {
  23250. // bad stream length, scanning for endstream
  23251. stream.pos = pos;
  23252. var SCAN_BLOCK_SIZE = 2048;
  23253. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  23254. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  23255. 0x61, 0x6D];
  23256. var skipped = 0, found = false, i, j;
  23257. while (stream.pos < stream.end) {
  23258. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  23259. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  23260. if (scanLength <= 0) {
  23261. break;
  23262. }
  23263. found = false;
  23264. for (i = 0, j = 0; i < scanLength; i++) {
  23265. var b = scanBytes[i];
  23266. if (b !== ENDSTREAM_SIGNATURE[j]) {
  23267. i -= j;
  23268. j = 0;
  23269. } else {
  23270. j++;
  23271. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  23272. i++;
  23273. found = true;
  23274. break;
  23275. }
  23276. }
  23277. }
  23278. if (found) {
  23279. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  23280. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  23281. break;
  23282. }
  23283. skipped += scanLength;
  23284. stream.pos += scanLength;
  23285. }
  23286. if (!found) {
  23287. error('Missing endstream');
  23288. }
  23289. length = skipped;
  23290. lexer.nextChar();
  23291. this.shift();
  23292. this.shift();
  23293. }
  23294. this.shift(); // 'endstream'
  23295. stream = stream.makeSubStream(pos, length, dict);
  23296. if (cipherTransform) {
  23297. stream = cipherTransform.createStream(stream, length);
  23298. }
  23299. stream = this.filter(stream, dict, length);
  23300. stream.dict = dict;
  23301. return stream;
  23302. },
  23303. filter: function Parser_filter(stream, dict, length) {
  23304. var filter = dict.get('Filter', 'F');
  23305. var params = dict.get('DecodeParms', 'DP');
  23306. if (isName(filter)) {
  23307. return this.makeFilter(stream, filter.name, length, params);
  23308. }
  23309. var maybeLength = length;
  23310. if (isArray(filter)) {
  23311. var filterArray = filter;
  23312. var paramsArray = params;
  23313. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  23314. filter = filterArray[i];
  23315. if (!isName(filter)) {
  23316. error('Bad filter name: ' + filter);
  23317. }
  23318. params = null;
  23319. if (isArray(paramsArray) && (i in paramsArray)) {
  23320. params = paramsArray[i];
  23321. }
  23322. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  23323. // after the first stream the length variable is invalid
  23324. maybeLength = null;
  23325. }
  23326. }
  23327. return stream;
  23328. },
  23329. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  23330. if (stream.dict.get('Length') === 0 && !maybeLength) {
  23331. warn('Empty "' + name + '" stream.');
  23332. return new NullStream(stream);
  23333. }
  23334. try {
  23335. if (params && this.xref) {
  23336. params = this.xref.fetchIfRef(params);
  23337. }
  23338. var xrefStreamStats = this.xref.stats.streamTypes;
  23339. if (name === 'FlateDecode' || name === 'Fl') {
  23340. xrefStreamStats[StreamType.FLATE] = true;
  23341. if (params) {
  23342. return new PredictorStream(new FlateStream(stream, maybeLength),
  23343. maybeLength, params);
  23344. }
  23345. return new FlateStream(stream, maybeLength);
  23346. }
  23347. if (name === 'LZWDecode' || name === 'LZW') {
  23348. xrefStreamStats[StreamType.LZW] = true;
  23349. var earlyChange = 1;
  23350. if (params) {
  23351. if (params.has('EarlyChange')) {
  23352. earlyChange = params.get('EarlyChange');
  23353. }
  23354. return new PredictorStream(
  23355. new LZWStream(stream, maybeLength, earlyChange),
  23356. maybeLength, params);
  23357. }
  23358. return new LZWStream(stream, maybeLength, earlyChange);
  23359. }
  23360. if (name === 'DCTDecode' || name === 'DCT') {
  23361. xrefStreamStats[StreamType.DCT] = true;
  23362. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  23363. }
  23364. if (name === 'JPXDecode' || name === 'JPX') {
  23365. xrefStreamStats[StreamType.JPX] = true;
  23366. return new JpxStream(stream, maybeLength, stream.dict);
  23367. }
  23368. if (name === 'ASCII85Decode' || name === 'A85') {
  23369. xrefStreamStats[StreamType.A85] = true;
  23370. return new Ascii85Stream(stream, maybeLength);
  23371. }
  23372. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  23373. xrefStreamStats[StreamType.AHX] = true;
  23374. return new AsciiHexStream(stream, maybeLength);
  23375. }
  23376. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  23377. xrefStreamStats[StreamType.CCF] = true;
  23378. return new CCITTFaxStream(stream, maybeLength, params);
  23379. }
  23380. if (name === 'RunLengthDecode' || name === 'RL') {
  23381. xrefStreamStats[StreamType.RL] = true;
  23382. return new RunLengthStream(stream, maybeLength);
  23383. }
  23384. if (name === 'JBIG2Decode') {
  23385. xrefStreamStats[StreamType.JBIG] = true;
  23386. return new Jbig2Stream(stream, maybeLength, stream.dict);
  23387. }
  23388. warn('filter "' + name + '" not supported yet');
  23389. return stream;
  23390. } catch (ex) {
  23391. if (ex instanceof MissingDataException) {
  23392. throw ex;
  23393. }
  23394. warn('Invalid stream: \"' + ex + '\"');
  23395. return new NullStream(stream);
  23396. }
  23397. }
  23398. };
  23399. return Parser;
  23400. })();
  23401. var Lexer = (function LexerClosure() {
  23402. function Lexer(stream, knownCommands) {
  23403. this.stream = stream;
  23404. this.nextChar();
  23405. // While lexing, we build up many strings one char at a time. Using += for
  23406. // this can result in lots of garbage strings. It's better to build an
  23407. // array of single-char strings and then join() them together at the end.
  23408. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  23409. // purpose uses less memory than using a new array for each string.
  23410. this.strBuf = [];
  23411. // The PDFs might have "glued" commands with other commands, operands or
  23412. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  23413. // commands and their prefixes. The prefixes are built the following way:
  23414. // if there a command that is a prefix of the other valid command or
  23415. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  23416. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  23417. // other commands or literals as a prefix. The knowCommands is optional.
  23418. this.knownCommands = knownCommands;
  23419. }
  23420. Lexer.isSpace = function Lexer_isSpace(ch) {
  23421. // Space is one of the following characters: SPACE, TAB, CR or LF.
  23422. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  23423. };
  23424. // A '1' in this array means the character is white space. A '1' or
  23425. // '2' means the character ends a name or command.
  23426. var specialChars = [
  23427. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  23428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  23429. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  23430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  23431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  23432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  23433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  23434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  23435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  23436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  23437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  23438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  23439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  23440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  23441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  23442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  23443. ];
  23444. function toHexDigit(ch) {
  23445. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  23446. return ch & 0x0F;
  23447. }
  23448. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  23449. // 'A'-'F', 'a'-'f'
  23450. return (ch & 0x0F) + 9;
  23451. }
  23452. return -1;
  23453. }
  23454. Lexer.prototype = {
  23455. nextChar: function Lexer_nextChar() {
  23456. return (this.currentChar = this.stream.getByte());
  23457. },
  23458. peekChar: function Lexer_peekChar() {
  23459. return this.stream.peekByte();
  23460. },
  23461. getNumber: function Lexer_getNumber() {
  23462. var ch = this.currentChar;
  23463. var eNotation = false;
  23464. var divideBy = 0; // different from 0 if it's a floating point value
  23465. var sign = 1;
  23466. if (ch === 0x2D) { // '-'
  23467. sign = -1;
  23468. ch = this.nextChar();
  23469. if (ch === 0x2D) { // '-'
  23470. // Ignore double negative (this is consistent with Adobe Reader).
  23471. ch = this.nextChar();
  23472. }
  23473. } else if (ch === 0x2B) { // '+'
  23474. ch = this.nextChar();
  23475. }
  23476. if (ch === 0x2E) { // '.'
  23477. divideBy = 10;
  23478. ch = this.nextChar();
  23479. }
  23480. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  23481. error('Invalid number: ' + String.fromCharCode(ch));
  23482. return 0;
  23483. }
  23484. var baseValue = ch - 0x30; // '0'
  23485. var powerValue = 0;
  23486. var powerValueSign = 1;
  23487. while ((ch = this.nextChar()) >= 0) {
  23488. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  23489. var currentDigit = ch - 0x30; // '0'
  23490. if (eNotation) { // We are after an 'e' or 'E'
  23491. powerValue = powerValue * 10 + currentDigit;
  23492. } else {
  23493. if (divideBy !== 0) { // We are after a point
  23494. divideBy *= 10;
  23495. }
  23496. baseValue = baseValue * 10 + currentDigit;
  23497. }
  23498. } else if (ch === 0x2E) { // '.'
  23499. if (divideBy === 0) {
  23500. divideBy = 1;
  23501. } else {
  23502. // A number can have only one '.'
  23503. break;
  23504. }
  23505. } else if (ch === 0x2D) { // '-'
  23506. // ignore minus signs in the middle of numbers to match
  23507. // Adobe's behavior
  23508. warn('Badly formated number');
  23509. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  23510. // 'E' can be either a scientific notation or the beginning of a new
  23511. // operator
  23512. ch = this.peekChar();
  23513. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  23514. powerValueSign = (ch === 0x2D) ? -1 : 1;
  23515. this.nextChar(); // Consume the sign character
  23516. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  23517. // The 'E' must be the beginning of a new operator
  23518. break;
  23519. }
  23520. eNotation = true;
  23521. } else {
  23522. // the last character doesn't belong to us
  23523. break;
  23524. }
  23525. }
  23526. if (divideBy !== 0) {
  23527. baseValue /= divideBy;
  23528. }
  23529. if (eNotation) {
  23530. baseValue *= Math.pow(10, powerValueSign * powerValue);
  23531. }
  23532. return sign * baseValue;
  23533. },
  23534. getString: function Lexer_getString() {
  23535. var numParen = 1;
  23536. var done = false;
  23537. var strBuf = this.strBuf;
  23538. strBuf.length = 0;
  23539. var ch = this.nextChar();
  23540. while (true) {
  23541. var charBuffered = false;
  23542. switch (ch | 0) {
  23543. case -1:
  23544. warn('Unterminated string');
  23545. done = true;
  23546. break;
  23547. case 0x28: // '('
  23548. ++numParen;
  23549. strBuf.push('(');
  23550. break;
  23551. case 0x29: // ')'
  23552. if (--numParen === 0) {
  23553. this.nextChar(); // consume strings ')'
  23554. done = true;
  23555. } else {
  23556. strBuf.push(')');
  23557. }
  23558. break;
  23559. case 0x5C: // '\\'
  23560. ch = this.nextChar();
  23561. switch (ch) {
  23562. case -1:
  23563. warn('Unterminated string');
  23564. done = true;
  23565. break;
  23566. case 0x6E: // 'n'
  23567. strBuf.push('\n');
  23568. break;
  23569. case 0x72: // 'r'
  23570. strBuf.push('\r');
  23571. break;
  23572. case 0x74: // 't'
  23573. strBuf.push('\t');
  23574. break;
  23575. case 0x62: // 'b'
  23576. strBuf.push('\b');
  23577. break;
  23578. case 0x66: // 'f'
  23579. strBuf.push('\f');
  23580. break;
  23581. case 0x5C: // '\'
  23582. case 0x28: // '('
  23583. case 0x29: // ')'
  23584. strBuf.push(String.fromCharCode(ch));
  23585. break;
  23586. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  23587. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  23588. var x = ch & 0x0F;
  23589. ch = this.nextChar();
  23590. charBuffered = true;
  23591. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  23592. x = (x << 3) + (ch & 0x0F);
  23593. ch = this.nextChar();
  23594. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  23595. charBuffered = false;
  23596. x = (x << 3) + (ch & 0x0F);
  23597. }
  23598. }
  23599. strBuf.push(String.fromCharCode(x));
  23600. break;
  23601. case 0x0D: // CR
  23602. if (this.peekChar() === 0x0A) { // LF
  23603. this.nextChar();
  23604. }
  23605. break;
  23606. case 0x0A: // LF
  23607. break;
  23608. default:
  23609. strBuf.push(String.fromCharCode(ch));
  23610. break;
  23611. }
  23612. break;
  23613. default:
  23614. strBuf.push(String.fromCharCode(ch));
  23615. break;
  23616. }
  23617. if (done) {
  23618. break;
  23619. }
  23620. if (!charBuffered) {
  23621. ch = this.nextChar();
  23622. }
  23623. }
  23624. return strBuf.join('');
  23625. },
  23626. getName: function Lexer_getName() {
  23627. var ch, previousCh;
  23628. var strBuf = this.strBuf;
  23629. strBuf.length = 0;
  23630. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  23631. if (ch === 0x23) { // '#'
  23632. ch = this.nextChar();
  23633. if (specialChars[ch]) {
  23634. warn('Lexer_getName: ' +
  23635. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  23636. strBuf.push('#');
  23637. break;
  23638. }
  23639. var x = toHexDigit(ch);
  23640. if (x !== -1) {
  23641. previousCh = ch;
  23642. ch = this.nextChar();
  23643. var x2 = toHexDigit(ch);
  23644. if (x2 === -1) {
  23645. warn('Lexer_getName: Illegal digit (' +
  23646. String.fromCharCode(ch) +') in hexadecimal number.');
  23647. strBuf.push('#', String.fromCharCode(previousCh));
  23648. if (specialChars[ch]) {
  23649. break;
  23650. }
  23651. strBuf.push(String.fromCharCode(ch));
  23652. continue;
  23653. }
  23654. strBuf.push(String.fromCharCode((x << 4) | x2));
  23655. } else {
  23656. strBuf.push('#', String.fromCharCode(ch));
  23657. }
  23658. } else {
  23659. strBuf.push(String.fromCharCode(ch));
  23660. }
  23661. }
  23662. if (strBuf.length > 127) {
  23663. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  23664. }
  23665. return Name.get(strBuf.join(''));
  23666. },
  23667. getHexString: function Lexer_getHexString() {
  23668. var strBuf = this.strBuf;
  23669. strBuf.length = 0;
  23670. var ch = this.currentChar;
  23671. var isFirstHex = true;
  23672. var firstDigit;
  23673. var secondDigit;
  23674. while (true) {
  23675. if (ch < 0) {
  23676. warn('Unterminated hex string');
  23677. break;
  23678. } else if (ch === 0x3E) { // '>'
  23679. this.nextChar();
  23680. break;
  23681. } else if (specialChars[ch] === 1) {
  23682. ch = this.nextChar();
  23683. continue;
  23684. } else {
  23685. if (isFirstHex) {
  23686. firstDigit = toHexDigit(ch);
  23687. if (firstDigit === -1) {
  23688. warn('Ignoring invalid character "' + ch + '" in hex string');
  23689. ch = this.nextChar();
  23690. continue;
  23691. }
  23692. } else {
  23693. secondDigit = toHexDigit(ch);
  23694. if (secondDigit === -1) {
  23695. warn('Ignoring invalid character "' + ch + '" in hex string');
  23696. ch = this.nextChar();
  23697. continue;
  23698. }
  23699. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  23700. }
  23701. isFirstHex = !isFirstHex;
  23702. ch = this.nextChar();
  23703. }
  23704. }
  23705. return strBuf.join('');
  23706. },
  23707. getObj: function Lexer_getObj() {
  23708. // skip whitespace and comments
  23709. var comment = false;
  23710. var ch = this.currentChar;
  23711. while (true) {
  23712. if (ch < 0) {
  23713. return EOF;
  23714. }
  23715. if (comment) {
  23716. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  23717. comment = false;
  23718. }
  23719. } else if (ch === 0x25) { // '%'
  23720. comment = true;
  23721. } else if (specialChars[ch] !== 1) {
  23722. break;
  23723. }
  23724. ch = this.nextChar();
  23725. }
  23726. // start reading token
  23727. switch (ch | 0) {
  23728. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23729. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23730. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23731. return this.getNumber();
  23732. case 0x28: // '('
  23733. return this.getString();
  23734. case 0x2F: // '/'
  23735. return this.getName();
  23736. // array punctuation
  23737. case 0x5B: // '['
  23738. this.nextChar();
  23739. return Cmd.get('[');
  23740. case 0x5D: // ']'
  23741. this.nextChar();
  23742. return Cmd.get(']');
  23743. // hex string or dict punctuation
  23744. case 0x3C: // '<'
  23745. ch = this.nextChar();
  23746. if (ch === 0x3C) {
  23747. // dict punctuation
  23748. this.nextChar();
  23749. return Cmd.get('<<');
  23750. }
  23751. return this.getHexString();
  23752. // dict punctuation
  23753. case 0x3E: // '>'
  23754. ch = this.nextChar();
  23755. if (ch === 0x3E) {
  23756. this.nextChar();
  23757. return Cmd.get('>>');
  23758. }
  23759. return Cmd.get('>');
  23760. case 0x7B: // '{'
  23761. this.nextChar();
  23762. return Cmd.get('{');
  23763. case 0x7D: // '}'
  23764. this.nextChar();
  23765. return Cmd.get('}');
  23766. case 0x29: // ')'
  23767. error('Illegal character: ' + ch);
  23768. break;
  23769. }
  23770. // command
  23771. var str = String.fromCharCode(ch);
  23772. var knownCommands = this.knownCommands;
  23773. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  23774. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  23775. // stop if known command is found and next character does not make
  23776. // the str a command
  23777. var possibleCommand = str + String.fromCharCode(ch);
  23778. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  23779. break;
  23780. }
  23781. if (str.length === 128) {
  23782. error('Command token too long: ' + str.length);
  23783. }
  23784. str = possibleCommand;
  23785. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  23786. }
  23787. if (str === 'true') {
  23788. return true;
  23789. }
  23790. if (str === 'false') {
  23791. return false;
  23792. }
  23793. if (str === 'null') {
  23794. return null;
  23795. }
  23796. return Cmd.get(str);
  23797. },
  23798. skipToNextLine: function Lexer_skipToNextLine() {
  23799. var ch = this.currentChar;
  23800. while (ch >= 0) {
  23801. if (ch === 0x0D) { // CR
  23802. ch = this.nextChar();
  23803. if (ch === 0x0A) { // LF
  23804. this.nextChar();
  23805. }
  23806. break;
  23807. } else if (ch === 0x0A) { // LF
  23808. this.nextChar();
  23809. break;
  23810. }
  23811. ch = this.nextChar();
  23812. }
  23813. }
  23814. };
  23815. return Lexer;
  23816. })();
  23817. var Linearization = {
  23818. create: function LinearizationCreate(stream) {
  23819. function getInt(name, allowZeroValue) {
  23820. var obj = linDict.get(name);
  23821. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  23822. return obj;
  23823. }
  23824. throw new Error('The "' + name + '" parameter in the linearization ' +
  23825. 'dictionary is invalid.');
  23826. }
  23827. function getHints() {
  23828. var hints = linDict.get('H'), hintsLength, item;
  23829. if (isArray(hints) &&
  23830. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  23831. for (var index = 0; index < hintsLength; index++) {
  23832. if (!(isInt(item = hints[index]) && item > 0)) {
  23833. throw new Error('Hint (' + index +
  23834. ') in the linearization dictionary is invalid.');
  23835. }
  23836. }
  23837. return hints;
  23838. }
  23839. throw new Error('Hint array in the linearization dictionary is invalid.');
  23840. }
  23841. var parser = new Parser(new Lexer(stream), false, null);
  23842. var obj1 = parser.getObj();
  23843. var obj2 = parser.getObj();
  23844. var obj3 = parser.getObj();
  23845. var linDict = parser.getObj();
  23846. var obj, length;
  23847. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  23848. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  23849. return null; // No valid linearization dictionary found.
  23850. } else if ((length = getInt('L')) !== stream.length) {
  23851. throw new Error('The "L" parameter in the linearization dictionary ' +
  23852. 'does not equal the stream length.');
  23853. }
  23854. return {
  23855. length: length,
  23856. hints: getHints(),
  23857. objectNumberFirst: getInt('O'),
  23858. endFirst: getInt('E'),
  23859. numPages: getInt('N'),
  23860. mainXRefEntriesOffset: getInt('T'),
  23861. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  23862. };
  23863. }
  23864. };
  23865. exports.EOF = EOF;
  23866. exports.Lexer = Lexer;
  23867. exports.Linearization = Linearization;
  23868. exports.Parser = Parser;
  23869. exports.isEOF = isEOF;
  23870. // TODO refactor to remove dependency on stream.js
  23871. coreStream._setCoreParser(exports);
  23872. }));
  23873. (function (root, factory) {
  23874. {
  23875. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  23876. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  23877. }
  23878. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  23879. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  23880. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  23881. var ImageKind = sharedUtil.ImageKind;
  23882. var OPS = sharedUtil.OPS;
  23883. var TextRenderingMode = sharedUtil.TextRenderingMode;
  23884. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  23885. var Util = sharedUtil.Util;
  23886. var assert = sharedUtil.assert;
  23887. var info = sharedUtil.info;
  23888. var isNum = sharedUtil.isNum;
  23889. var isArray = sharedUtil.isArray;
  23890. var error = sharedUtil.error;
  23891. var shadow = sharedUtil.shadow;
  23892. var warn = sharedUtil.warn;
  23893. var TilingPattern = displayPatternHelper.TilingPattern;
  23894. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  23895. var WebGLUtils = displayWebGL.WebGLUtils;
  23896. // <canvas> contexts store most of the state we need natively.
  23897. // However, PDF needs a bit more state, which we store here.
  23898. // Minimal font size that would be used during canvas fillText operations.
  23899. var MIN_FONT_SIZE = 16;
  23900. // Maximum font size that would be used during canvas fillText operations.
  23901. var MAX_FONT_SIZE = 100;
  23902. var MAX_GROUP_SIZE = 4096;
  23903. // Heuristic value used when enforcing minimum line widths.
  23904. var MIN_WIDTH_FACTOR = 0.65;
  23905. var COMPILE_TYPE3_GLYPHS = true;
  23906. var MAX_SIZE_TO_COMPILE = 1000;
  23907. var FULL_CHUNK_HEIGHT = 16;
  23908. function createScratchCanvas(width, height) {
  23909. var canvas = document.createElement('canvas');
  23910. canvas.width = width;
  23911. canvas.height = height;
  23912. return canvas;
  23913. }
  23914. function addContextCurrentTransform(ctx) {
  23915. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  23916. if (!ctx.mozCurrentTransform) {
  23917. ctx._originalSave = ctx.save;
  23918. ctx._originalRestore = ctx.restore;
  23919. ctx._originalRotate = ctx.rotate;
  23920. ctx._originalScale = ctx.scale;
  23921. ctx._originalTranslate = ctx.translate;
  23922. ctx._originalTransform = ctx.transform;
  23923. ctx._originalSetTransform = ctx.setTransform;
  23924. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  23925. ctx._transformStack = [];
  23926. Object.defineProperty(ctx, 'mozCurrentTransform', {
  23927. get: function getCurrentTransform() {
  23928. return this._transformMatrix;
  23929. }
  23930. });
  23931. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  23932. get: function getCurrentTransformInverse() {
  23933. // Calculation done using WolframAlpha:
  23934. // http://www.wolframalpha.com/input/?
  23935. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  23936. var m = this._transformMatrix;
  23937. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  23938. var ad_bc = a * d - b * c;
  23939. var bc_ad = b * c - a * d;
  23940. return [
  23941. d / ad_bc,
  23942. b / bc_ad,
  23943. c / bc_ad,
  23944. a / ad_bc,
  23945. (d * e - c * f) / bc_ad,
  23946. (b * e - a * f) / ad_bc
  23947. ];
  23948. }
  23949. });
  23950. ctx.save = function ctxSave() {
  23951. var old = this._transformMatrix;
  23952. this._transformStack.push(old);
  23953. this._transformMatrix = old.slice(0, 6);
  23954. this._originalSave();
  23955. };
  23956. ctx.restore = function ctxRestore() {
  23957. var prev = this._transformStack.pop();
  23958. if (prev) {
  23959. this._transformMatrix = prev;
  23960. this._originalRestore();
  23961. }
  23962. };
  23963. ctx.translate = function ctxTranslate(x, y) {
  23964. var m = this._transformMatrix;
  23965. m[4] = m[0] * x + m[2] * y + m[4];
  23966. m[5] = m[1] * x + m[3] * y + m[5];
  23967. this._originalTranslate(x, y);
  23968. };
  23969. ctx.scale = function ctxScale(x, y) {
  23970. var m = this._transformMatrix;
  23971. m[0] = m[0] * x;
  23972. m[1] = m[1] * x;
  23973. m[2] = m[2] * y;
  23974. m[3] = m[3] * y;
  23975. this._originalScale(x, y);
  23976. };
  23977. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  23978. var m = this._transformMatrix;
  23979. this._transformMatrix = [
  23980. m[0] * a + m[2] * b,
  23981. m[1] * a + m[3] * b,
  23982. m[0] * c + m[2] * d,
  23983. m[1] * c + m[3] * d,
  23984. m[0] * e + m[2] * f + m[4],
  23985. m[1] * e + m[3] * f + m[5]
  23986. ];
  23987. ctx._originalTransform(a, b, c, d, e, f);
  23988. };
  23989. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  23990. this._transformMatrix = [a, b, c, d, e, f];
  23991. ctx._originalSetTransform(a, b, c, d, e, f);
  23992. };
  23993. ctx.rotate = function ctxRotate(angle) {
  23994. var cosValue = Math.cos(angle);
  23995. var sinValue = Math.sin(angle);
  23996. var m = this._transformMatrix;
  23997. this._transformMatrix = [
  23998. m[0] * cosValue + m[2] * sinValue,
  23999. m[1] * cosValue + m[3] * sinValue,
  24000. m[0] * (-sinValue) + m[2] * cosValue,
  24001. m[1] * (-sinValue) + m[3] * cosValue,
  24002. m[4],
  24003. m[5]
  24004. ];
  24005. this._originalRotate(angle);
  24006. };
  24007. }
  24008. }
  24009. var CachedCanvases = (function CachedCanvasesClosure() {
  24010. function CachedCanvases() {
  24011. this.cache = Object.create(null);
  24012. }
  24013. CachedCanvases.prototype = {
  24014. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  24015. trackTransform) {
  24016. var canvasEntry;
  24017. if (this.cache[id] !== undefined) {
  24018. canvasEntry = this.cache[id];
  24019. canvasEntry.canvas.width = width;
  24020. canvasEntry.canvas.height = height;
  24021. // reset canvas transform for emulated mozCurrentTransform, if needed
  24022. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  24023. } else {
  24024. var canvas = createScratchCanvas(width, height);
  24025. var ctx = canvas.getContext('2d');
  24026. if (trackTransform) {
  24027. addContextCurrentTransform(ctx);
  24028. }
  24029. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  24030. }
  24031. return canvasEntry;
  24032. },
  24033. clear: function () {
  24034. for (var id in this.cache) {
  24035. var canvasEntry = this.cache[id];
  24036. // Zeroing the width and height causes Firefox to release graphics
  24037. // resources immediately, which can greatly reduce memory consumption.
  24038. canvasEntry.canvas.width = 0;
  24039. canvasEntry.canvas.height = 0;
  24040. delete this.cache[id];
  24041. }
  24042. }
  24043. };
  24044. return CachedCanvases;
  24045. })();
  24046. function compileType3Glyph(imgData) {
  24047. var POINT_TO_PROCESS_LIMIT = 1000;
  24048. var width = imgData.width, height = imgData.height;
  24049. var i, j, j0, width1 = width + 1;
  24050. var points = new Uint8Array(width1 * (height + 1));
  24051. var POINT_TYPES =
  24052. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  24053. // decodes bit-packed mask data
  24054. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  24055. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  24056. for (i = 0, ii = data0.length; i < ii; i++) {
  24057. var mask = 128, elem = data0[i];
  24058. while (mask > 0) {
  24059. data[pos++] = (elem & mask) ? 0 : 255;
  24060. mask >>= 1;
  24061. }
  24062. }
  24063. // finding iteresting points: every point is located between mask pixels,
  24064. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  24065. // will have flags assigned based on neighboring mask pixels:
  24066. // 4 | 8
  24067. // --P--
  24068. // 2 | 1
  24069. // We are interested only in points with the flags:
  24070. // - outside corners: 1, 2, 4, 8;
  24071. // - inside corners: 7, 11, 13, 14;
  24072. // - and, intersections: 5, 10.
  24073. var count = 0;
  24074. pos = 0;
  24075. if (data[pos] !== 0) {
  24076. points[0] = 1;
  24077. ++count;
  24078. }
  24079. for (j = 1; j < width; j++) {
  24080. if (data[pos] !== data[pos + 1]) {
  24081. points[j] = data[pos] ? 2 : 1;
  24082. ++count;
  24083. }
  24084. pos++;
  24085. }
  24086. if (data[pos] !== 0) {
  24087. points[j] = 2;
  24088. ++count;
  24089. }
  24090. for (i = 1; i < height; i++) {
  24091. pos = i * lineSize;
  24092. j0 = i * width1;
  24093. if (data[pos - lineSize] !== data[pos]) {
  24094. points[j0] = data[pos] ? 1 : 8;
  24095. ++count;
  24096. }
  24097. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  24098. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  24099. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  24100. for (j = 1; j < width; j++) {
  24101. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  24102. (data[pos - lineSize + 1] ? 8 : 0);
  24103. if (POINT_TYPES[sum]) {
  24104. points[j0 + j] = POINT_TYPES[sum];
  24105. ++count;
  24106. }
  24107. pos++;
  24108. }
  24109. if (data[pos - lineSize] !== data[pos]) {
  24110. points[j0 + j] = data[pos] ? 2 : 4;
  24111. ++count;
  24112. }
  24113. if (count > POINT_TO_PROCESS_LIMIT) {
  24114. return null;
  24115. }
  24116. }
  24117. pos = lineSize * (height - 1);
  24118. j0 = i * width1;
  24119. if (data[pos] !== 0) {
  24120. points[j0] = 8;
  24121. ++count;
  24122. }
  24123. for (j = 1; j < width; j++) {
  24124. if (data[pos] !== data[pos + 1]) {
  24125. points[j0 + j] = data[pos] ? 4 : 8;
  24126. ++count;
  24127. }
  24128. pos++;
  24129. }
  24130. if (data[pos] !== 0) {
  24131. points[j0 + j] = 4;
  24132. ++count;
  24133. }
  24134. if (count > POINT_TO_PROCESS_LIMIT) {
  24135. return null;
  24136. }
  24137. // building outlines
  24138. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  24139. var outlines = [];
  24140. for (i = 0; count && i <= height; i++) {
  24141. var p = i * width1;
  24142. var end = p + width;
  24143. while (p < end && !points[p]) {
  24144. p++;
  24145. }
  24146. if (p === end) {
  24147. continue;
  24148. }
  24149. var coords = [p % width1, i];
  24150. var type = points[p], p0 = p, pp;
  24151. do {
  24152. var step = steps[type];
  24153. do {
  24154. p += step;
  24155. } while (!points[p]);
  24156. pp = points[p];
  24157. if (pp !== 5 && pp !== 10) {
  24158. // set new direction
  24159. type = pp;
  24160. // delete mark
  24161. points[p] = 0;
  24162. } else { // type is 5 or 10, ie, a crossing
  24163. // set new direction
  24164. type = pp & ((0x33 * type) >> 4);
  24165. // set new type for "future hit"
  24166. points[p] &= (type >> 2 | type << 2);
  24167. }
  24168. coords.push(p % width1);
  24169. coords.push((p / width1) | 0);
  24170. --count;
  24171. } while (p0 !== p);
  24172. outlines.push(coords);
  24173. --i;
  24174. }
  24175. var drawOutline = function(c) {
  24176. c.save();
  24177. // the path shall be painted in [0..1]x[0..1] space
  24178. c.scale(1 / width, -1 / height);
  24179. c.translate(0, -height);
  24180. c.beginPath();
  24181. for (var i = 0, ii = outlines.length; i < ii; i++) {
  24182. var o = outlines[i];
  24183. c.moveTo(o[0], o[1]);
  24184. for (var j = 2, jj = o.length; j < jj; j += 2) {
  24185. c.lineTo(o[j], o[j+1]);
  24186. }
  24187. }
  24188. c.fill();
  24189. c.beginPath();
  24190. c.restore();
  24191. };
  24192. return drawOutline;
  24193. }
  24194. var CanvasExtraState = (function CanvasExtraStateClosure() {
  24195. function CanvasExtraState(old) {
  24196. // Are soft masks and alpha values shapes or opacities?
  24197. this.alphaIsShape = false;
  24198. this.fontSize = 0;
  24199. this.fontSizeScale = 1;
  24200. this.textMatrix = IDENTITY_MATRIX;
  24201. this.textMatrixScale = 1;
  24202. this.fontMatrix = FONT_IDENTITY_MATRIX;
  24203. this.leading = 0;
  24204. // Current point (in user coordinates)
  24205. this.x = 0;
  24206. this.y = 0;
  24207. // Start of text line (in text coordinates)
  24208. this.lineX = 0;
  24209. this.lineY = 0;
  24210. // Character and word spacing
  24211. this.charSpacing = 0;
  24212. this.wordSpacing = 0;
  24213. this.textHScale = 1;
  24214. this.textRenderingMode = TextRenderingMode.FILL;
  24215. this.textRise = 0;
  24216. // Default fore and background colors
  24217. this.fillColor = '#000000';
  24218. this.strokeColor = '#000000';
  24219. this.patternFill = false;
  24220. // Note: fill alpha applies to all non-stroking operations
  24221. this.fillAlpha = 1;
  24222. this.strokeAlpha = 1;
  24223. this.lineWidth = 1;
  24224. this.activeSMask = null; // nonclonable field (see the save method below)
  24225. this.old = old;
  24226. }
  24227. CanvasExtraState.prototype = {
  24228. clone: function CanvasExtraState_clone() {
  24229. return Object.create(this);
  24230. },
  24231. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  24232. this.x = x;
  24233. this.y = y;
  24234. }
  24235. };
  24236. return CanvasExtraState;
  24237. })();
  24238. var CanvasGraphics = (function CanvasGraphicsClosure() {
  24239. // Defines the time the executeOperatorList is going to be executing
  24240. // before it stops and shedules a continue of execution.
  24241. var EXECUTION_TIME = 15;
  24242. // Defines the number of steps before checking the execution time
  24243. var EXECUTION_STEPS = 10;
  24244. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  24245. this.ctx = canvasCtx;
  24246. this.current = new CanvasExtraState();
  24247. this.stateStack = [];
  24248. this.pendingClip = null;
  24249. this.pendingEOFill = false;
  24250. this.res = null;
  24251. this.xobjs = null;
  24252. this.commonObjs = commonObjs;
  24253. this.objs = objs;
  24254. this.imageLayer = imageLayer;
  24255. this.groupStack = [];
  24256. this.processingType3 = null;
  24257. // Patterns are painted relative to the initial page/form transform, see pdf
  24258. // spec 8.7.2 NOTE 1.
  24259. this.baseTransform = null;
  24260. this.baseTransformStack = [];
  24261. this.groupLevel = 0;
  24262. this.smaskStack = [];
  24263. this.smaskCounter = 0;
  24264. this.tempSMask = null;
  24265. this.cachedCanvases = new CachedCanvases();
  24266. if (canvasCtx) {
  24267. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  24268. // the transformation must already be set in canvasCtx._transformMatrix.
  24269. addContextCurrentTransform(canvasCtx);
  24270. }
  24271. this.cachedGetSinglePixelWidth = null;
  24272. }
  24273. function putBinaryImageData(ctx, imgData) {
  24274. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  24275. ctx.putImageData(imgData, 0, 0);
  24276. return;
  24277. }
  24278. // Put the image data to the canvas in chunks, rather than putting the
  24279. // whole image at once. This saves JS memory, because the ImageData object
  24280. // is smaller. It also possibly saves C++ memory within the implementation
  24281. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  24282. // the data passed to putImageData()). |n| shouldn't be too small, however,
  24283. // because too many putImageData() calls will slow things down.
  24284. //
  24285. // Note: as written, if the last chunk is partial, the putImageData() call
  24286. // will (conceptually) put pixels past the bounds of the canvas. But
  24287. // that's ok; any such pixels are ignored.
  24288. var height = imgData.height, width = imgData.width;
  24289. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  24290. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  24291. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  24292. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  24293. var srcPos = 0, destPos;
  24294. var src = imgData.data;
  24295. var dest = chunkImgData.data;
  24296. var i, j, thisChunkHeight, elemsInThisChunk;
  24297. // There are multiple forms in which the pixel data can be passed, and
  24298. // imgData.kind tells us which one this is.
  24299. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  24300. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  24301. var srcLength = src.byteLength;
  24302. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  24303. new Uint32ArrayView(dest);
  24304. var dest32DataLength = dest32.length;
  24305. var fullSrcDiff = (width + 7) >> 3;
  24306. var white = 0xFFFFFFFF;
  24307. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  24308. 0xFF000000 : 0x000000FF;
  24309. for (i = 0; i < totalChunks; i++) {
  24310. thisChunkHeight =
  24311. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  24312. destPos = 0;
  24313. for (j = 0; j < thisChunkHeight; j++) {
  24314. var srcDiff = srcLength - srcPos;
  24315. var k = 0;
  24316. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  24317. var kEndUnrolled = kEnd & ~7;
  24318. var mask = 0;
  24319. var srcByte = 0;
  24320. for (; k < kEndUnrolled; k += 8) {
  24321. srcByte = src[srcPos++];
  24322. dest32[destPos++] = (srcByte & 128) ? white : black;
  24323. dest32[destPos++] = (srcByte & 64) ? white : black;
  24324. dest32[destPos++] = (srcByte & 32) ? white : black;
  24325. dest32[destPos++] = (srcByte & 16) ? white : black;
  24326. dest32[destPos++] = (srcByte & 8) ? white : black;
  24327. dest32[destPos++] = (srcByte & 4) ? white : black;
  24328. dest32[destPos++] = (srcByte & 2) ? white : black;
  24329. dest32[destPos++] = (srcByte & 1) ? white : black;
  24330. }
  24331. for (; k < kEnd; k++) {
  24332. if (mask === 0) {
  24333. srcByte = src[srcPos++];
  24334. mask = 128;
  24335. }
  24336. dest32[destPos++] = (srcByte & mask) ? white : black;
  24337. mask >>= 1;
  24338. }
  24339. }
  24340. // We ran out of input. Make all remaining pixels transparent.
  24341. while (destPos < dest32DataLength) {
  24342. dest32[destPos++] = 0;
  24343. }
  24344. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  24345. }
  24346. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  24347. // RGBA, 32-bits per pixel.
  24348. j = 0;
  24349. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  24350. for (i = 0; i < fullChunks; i++) {
  24351. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  24352. srcPos += elemsInThisChunk;
  24353. ctx.putImageData(chunkImgData, 0, j);
  24354. j += FULL_CHUNK_HEIGHT;
  24355. }
  24356. if (i < totalChunks) {
  24357. elemsInThisChunk = width * partialChunkHeight * 4;
  24358. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  24359. ctx.putImageData(chunkImgData, 0, j);
  24360. }
  24361. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  24362. // RGB, 24-bits per pixel.
  24363. thisChunkHeight = FULL_CHUNK_HEIGHT;
  24364. elemsInThisChunk = width * thisChunkHeight;
  24365. for (i = 0; i < totalChunks; i++) {
  24366. if (i >= fullChunks) {
  24367. thisChunkHeight = partialChunkHeight;
  24368. elemsInThisChunk = width * thisChunkHeight;
  24369. }
  24370. destPos = 0;
  24371. for (j = elemsInThisChunk; j--;) {
  24372. dest[destPos++] = src[srcPos++];
  24373. dest[destPos++] = src[srcPos++];
  24374. dest[destPos++] = src[srcPos++];
  24375. dest[destPos++] = 255;
  24376. }
  24377. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  24378. }
  24379. } else {
  24380. error('bad image kind: ' + imgData.kind);
  24381. }
  24382. }
  24383. function putBinaryImageMask(ctx, imgData) {
  24384. var height = imgData.height, width = imgData.width;
  24385. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  24386. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  24387. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  24388. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  24389. var srcPos = 0;
  24390. var src = imgData.data;
  24391. var dest = chunkImgData.data;
  24392. for (var i = 0; i < totalChunks; i++) {
  24393. var thisChunkHeight =
  24394. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  24395. // Expand the mask so it can be used by the canvas. Any required
  24396. // inversion has already been handled.
  24397. var destPos = 3; // alpha component offset
  24398. for (var j = 0; j < thisChunkHeight; j++) {
  24399. var mask = 0;
  24400. for (var k = 0; k < width; k++) {
  24401. if (!mask) {
  24402. var elem = src[srcPos++];
  24403. mask = 128;
  24404. }
  24405. dest[destPos] = (elem & mask) ? 0 : 255;
  24406. destPos += 4;
  24407. mask >>= 1;
  24408. }
  24409. }
  24410. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  24411. }
  24412. }
  24413. function copyCtxState(sourceCtx, destCtx) {
  24414. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  24415. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  24416. 'globalCompositeOperation', 'font'];
  24417. for (var i = 0, ii = properties.length; i < ii; i++) {
  24418. var property = properties[i];
  24419. if (sourceCtx[property] !== undefined) {
  24420. destCtx[property] = sourceCtx[property];
  24421. }
  24422. }
  24423. if (sourceCtx.setLineDash !== undefined) {
  24424. destCtx.setLineDash(sourceCtx.getLineDash());
  24425. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  24426. } else if (sourceCtx.mozDashOffset !== undefined) {
  24427. destCtx.mozDash = sourceCtx.mozDash;
  24428. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  24429. }
  24430. }
  24431. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  24432. var length = bytes.length;
  24433. for (var i = 3; i < length; i += 4) {
  24434. var alpha = bytes[i];
  24435. if (alpha === 0) {
  24436. bytes[i - 3] = r0;
  24437. bytes[i - 2] = g0;
  24438. bytes[i - 1] = b0;
  24439. } else if (alpha < 255) {
  24440. var alpha_ = 255 - alpha;
  24441. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  24442. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  24443. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  24444. }
  24445. }
  24446. }
  24447. function composeSMaskAlpha(maskData, layerData, transferMap) {
  24448. var length = maskData.length;
  24449. var scale = 1 / 255;
  24450. for (var i = 3; i < length; i += 4) {
  24451. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  24452. layerData[i] = (layerData[i] * alpha * scale) | 0;
  24453. }
  24454. }
  24455. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  24456. var length = maskData.length;
  24457. for (var i = 3; i < length; i += 4) {
  24458. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  24459. (maskData[i - 2] * 152) + // * 0.59 ....
  24460. (maskData[i - 1] * 28); // * 0.11 ....
  24461. layerData[i] = transferMap ?
  24462. (layerData[i] * transferMap[y >> 8]) >> 8 :
  24463. (layerData[i] * y) >> 16;
  24464. }
  24465. }
  24466. function genericComposeSMask(maskCtx, layerCtx, width, height,
  24467. subtype, backdrop, transferMap) {
  24468. var hasBackdrop = !!backdrop;
  24469. var r0 = hasBackdrop ? backdrop[0] : 0;
  24470. var g0 = hasBackdrop ? backdrop[1] : 0;
  24471. var b0 = hasBackdrop ? backdrop[2] : 0;
  24472. var composeFn;
  24473. if (subtype === 'Luminosity') {
  24474. composeFn = composeSMaskLuminosity;
  24475. } else {
  24476. composeFn = composeSMaskAlpha;
  24477. }
  24478. // processing image in chunks to save memory
  24479. var PIXELS_TO_PROCESS = 1048576;
  24480. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  24481. for (var row = 0; row < height; row += chunkSize) {
  24482. var chunkHeight = Math.min(chunkSize, height - row);
  24483. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  24484. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  24485. if (hasBackdrop) {
  24486. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  24487. }
  24488. composeFn(maskData.data, layerData.data, transferMap);
  24489. maskCtx.putImageData(layerData, 0, row);
  24490. }
  24491. }
  24492. function composeSMask(ctx, smask, layerCtx) {
  24493. var mask = smask.canvas;
  24494. var maskCtx = smask.context;
  24495. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  24496. smask.offsetX, smask.offsetY);
  24497. var backdrop = smask.backdrop || null;
  24498. if (!smask.transferMap && WebGLUtils.isEnabled) {
  24499. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  24500. {subtype: smask.subtype, backdrop: backdrop});
  24501. ctx.setTransform(1, 0, 0, 1, 0, 0);
  24502. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  24503. return;
  24504. }
  24505. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  24506. smask.subtype, backdrop, smask.transferMap);
  24507. ctx.drawImage(mask, 0, 0);
  24508. }
  24509. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  24510. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  24511. var NORMAL_CLIP = {};
  24512. var EO_CLIP = {};
  24513. CanvasGraphics.prototype = {
  24514. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  24515. transparency) {
  24516. // For pdfs that use blend modes we have to clear the canvas else certain
  24517. // blend modes can look wrong since we'd be blending with a white
  24518. // backdrop. The problem with a transparent backdrop though is we then
  24519. // don't get sub pixel anti aliasing on text, creating temporary
  24520. // transparent canvas when we have blend modes.
  24521. var width = this.ctx.canvas.width;
  24522. var height = this.ctx.canvas.height;
  24523. this.ctx.save();
  24524. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  24525. this.ctx.fillRect(0, 0, width, height);
  24526. this.ctx.restore();
  24527. if (transparency) {
  24528. var transparentCanvas = this.cachedCanvases.getCanvas(
  24529. 'transparent', width, height, true);
  24530. this.compositeCtx = this.ctx;
  24531. this.transparentCanvas = transparentCanvas.canvas;
  24532. this.ctx = transparentCanvas.context;
  24533. this.ctx.save();
  24534. // The transform can be applied before rendering, transferring it to
  24535. // the new canvas.
  24536. this.ctx.transform.apply(this.ctx,
  24537. this.compositeCtx.mozCurrentTransform);
  24538. }
  24539. this.ctx.save();
  24540. if (transform) {
  24541. this.ctx.transform.apply(this.ctx, transform);
  24542. }
  24543. this.ctx.transform.apply(this.ctx, viewport.transform);
  24544. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  24545. if (this.imageLayer) {
  24546. this.imageLayer.beginLayout();
  24547. }
  24548. },
  24549. executeOperatorList: function CanvasGraphics_executeOperatorList(
  24550. operatorList,
  24551. executionStartIdx, continueCallback,
  24552. stepper) {
  24553. var argsArray = operatorList.argsArray;
  24554. var fnArray = operatorList.fnArray;
  24555. var i = executionStartIdx || 0;
  24556. var argsArrayLen = argsArray.length;
  24557. // Sometimes the OperatorList to execute is empty.
  24558. if (argsArrayLen === i) {
  24559. return i;
  24560. }
  24561. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  24562. typeof continueCallback === 'function');
  24563. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  24564. var steps = 0;
  24565. var commonObjs = this.commonObjs;
  24566. var objs = this.objs;
  24567. var fnId;
  24568. while (true) {
  24569. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  24570. stepper.breakIt(i, continueCallback);
  24571. return i;
  24572. }
  24573. fnId = fnArray[i];
  24574. if (fnId !== OPS.dependency) {
  24575. this[fnId].apply(this, argsArray[i]);
  24576. } else {
  24577. var deps = argsArray[i];
  24578. for (var n = 0, nn = deps.length; n < nn; n++) {
  24579. var depObjId = deps[n];
  24580. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  24581. var objsPool = common ? commonObjs : objs;
  24582. // If the promise isn't resolved yet, add the continueCallback
  24583. // to the promise and bail out.
  24584. if (!objsPool.isResolved(depObjId)) {
  24585. objsPool.get(depObjId, continueCallback);
  24586. return i;
  24587. }
  24588. }
  24589. }
  24590. i++;
  24591. // If the entire operatorList was executed, stop as were done.
  24592. if (i === argsArrayLen) {
  24593. return i;
  24594. }
  24595. // If the execution took longer then a certain amount of time and
  24596. // `continueCallback` is specified, interrupt the execution.
  24597. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  24598. if (Date.now() > endTime) {
  24599. continueCallback();
  24600. return i;
  24601. }
  24602. steps = 0;
  24603. }
  24604. // If the operatorList isn't executed completely yet OR the execution
  24605. // time was short enough, do another execution round.
  24606. }
  24607. },
  24608. endDrawing: function CanvasGraphics_endDrawing() {
  24609. this.ctx.restore();
  24610. if (this.transparentCanvas) {
  24611. this.ctx = this.compositeCtx;
  24612. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  24613. this.transparentCanvas = null;
  24614. }
  24615. this.cachedCanvases.clear();
  24616. WebGLUtils.clear();
  24617. if (this.imageLayer) {
  24618. this.imageLayer.endLayout();
  24619. }
  24620. },
  24621. // Graphics state
  24622. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  24623. this.current.lineWidth = width;
  24624. this.ctx.lineWidth = width;
  24625. },
  24626. setLineCap: function CanvasGraphics_setLineCap(style) {
  24627. this.ctx.lineCap = LINE_CAP_STYLES[style];
  24628. },
  24629. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  24630. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  24631. },
  24632. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  24633. this.ctx.miterLimit = limit;
  24634. },
  24635. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  24636. var ctx = this.ctx;
  24637. if (ctx.setLineDash !== undefined) {
  24638. ctx.setLineDash(dashArray);
  24639. ctx.lineDashOffset = dashPhase;
  24640. } else {
  24641. ctx.mozDash = dashArray;
  24642. ctx.mozDashOffset = dashPhase;
  24643. }
  24644. },
  24645. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  24646. // Maybe if we one day fully support color spaces this will be important
  24647. // for now we can ignore.
  24648. // TODO set rendering intent?
  24649. },
  24650. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  24651. // There's no way to control this with canvas, but we can safely ignore.
  24652. // TODO set flatness?
  24653. },
  24654. setGState: function CanvasGraphics_setGState(states) {
  24655. for (var i = 0, ii = states.length; i < ii; i++) {
  24656. var state = states[i];
  24657. var key = state[0];
  24658. var value = state[1];
  24659. switch (key) {
  24660. case 'LW':
  24661. this.setLineWidth(value);
  24662. break;
  24663. case 'LC':
  24664. this.setLineCap(value);
  24665. break;
  24666. case 'LJ':
  24667. this.setLineJoin(value);
  24668. break;
  24669. case 'ML':
  24670. this.setMiterLimit(value);
  24671. break;
  24672. case 'D':
  24673. this.setDash(value[0], value[1]);
  24674. break;
  24675. case 'RI':
  24676. this.setRenderingIntent(value);
  24677. break;
  24678. case 'FL':
  24679. this.setFlatness(value);
  24680. break;
  24681. case 'Font':
  24682. this.setFont(value[0], value[1]);
  24683. break;
  24684. case 'CA':
  24685. this.current.strokeAlpha = state[1];
  24686. break;
  24687. case 'ca':
  24688. this.current.fillAlpha = state[1];
  24689. this.ctx.globalAlpha = state[1];
  24690. break;
  24691. case 'BM':
  24692. if (value && value.name && (value.name !== 'Normal')) {
  24693. var mode = value.name.replace(/([A-Z])/g,
  24694. function(c) {
  24695. return '-' + c.toLowerCase();
  24696. }
  24697. ).substring(1);
  24698. this.ctx.globalCompositeOperation = mode;
  24699. if (this.ctx.globalCompositeOperation !== mode) {
  24700. warn('globalCompositeOperation "' + mode +
  24701. '" is not supported');
  24702. }
  24703. } else {
  24704. this.ctx.globalCompositeOperation = 'source-over';
  24705. }
  24706. break;
  24707. case 'SMask':
  24708. if (this.current.activeSMask) {
  24709. this.endSMaskGroup();
  24710. }
  24711. this.current.activeSMask = value ? this.tempSMask : null;
  24712. if (this.current.activeSMask) {
  24713. this.beginSMaskGroup();
  24714. }
  24715. this.tempSMask = null;
  24716. break;
  24717. }
  24718. }
  24719. },
  24720. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  24721. var activeSMask = this.current.activeSMask;
  24722. var drawnWidth = activeSMask.canvas.width;
  24723. var drawnHeight = activeSMask.canvas.height;
  24724. var cacheId = 'smaskGroupAt' + this.groupLevel;
  24725. var scratchCanvas = this.cachedCanvases.getCanvas(
  24726. cacheId, drawnWidth, drawnHeight, true);
  24727. var currentCtx = this.ctx;
  24728. var currentTransform = currentCtx.mozCurrentTransform;
  24729. this.ctx.save();
  24730. var groupCtx = scratchCanvas.context;
  24731. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  24732. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  24733. groupCtx.transform.apply(groupCtx, currentTransform);
  24734. copyCtxState(currentCtx, groupCtx);
  24735. this.ctx = groupCtx;
  24736. this.setGState([
  24737. ['BM', 'Normal'],
  24738. ['ca', 1],
  24739. ['CA', 1]
  24740. ]);
  24741. this.groupStack.push(currentCtx);
  24742. this.groupLevel++;
  24743. },
  24744. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  24745. var groupCtx = this.ctx;
  24746. this.groupLevel--;
  24747. this.ctx = this.groupStack.pop();
  24748. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  24749. this.ctx.restore();
  24750. copyCtxState(groupCtx, this.ctx);
  24751. },
  24752. save: function CanvasGraphics_save() {
  24753. this.ctx.save();
  24754. var old = this.current;
  24755. this.stateStack.push(old);
  24756. this.current = old.clone();
  24757. this.current.activeSMask = null;
  24758. },
  24759. restore: function CanvasGraphics_restore() {
  24760. if (this.stateStack.length !== 0) {
  24761. if (this.current.activeSMask !== null) {
  24762. this.endSMaskGroup();
  24763. }
  24764. this.current = this.stateStack.pop();
  24765. this.ctx.restore();
  24766. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  24767. this.pendingClip = null;
  24768. this.cachedGetSinglePixelWidth = null;
  24769. }
  24770. },
  24771. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  24772. this.ctx.transform(a, b, c, d, e, f);
  24773. this.cachedGetSinglePixelWidth = null;
  24774. },
  24775. // Path
  24776. constructPath: function CanvasGraphics_constructPath(ops, args) {
  24777. var ctx = this.ctx;
  24778. var current = this.current;
  24779. var x = current.x, y = current.y;
  24780. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  24781. switch (ops[i] | 0) {
  24782. case OPS.rectangle:
  24783. x = args[j++];
  24784. y = args[j++];
  24785. var width = args[j++];
  24786. var height = args[j++];
  24787. if (width === 0) {
  24788. width = this.getSinglePixelWidth();
  24789. }
  24790. if (height === 0) {
  24791. height = this.getSinglePixelWidth();
  24792. }
  24793. var xw = x + width;
  24794. var yh = y + height;
  24795. this.ctx.moveTo(x, y);
  24796. this.ctx.lineTo(xw, y);
  24797. this.ctx.lineTo(xw, yh);
  24798. this.ctx.lineTo(x, yh);
  24799. this.ctx.lineTo(x, y);
  24800. this.ctx.closePath();
  24801. break;
  24802. case OPS.moveTo:
  24803. x = args[j++];
  24804. y = args[j++];
  24805. ctx.moveTo(x, y);
  24806. break;
  24807. case OPS.lineTo:
  24808. x = args[j++];
  24809. y = args[j++];
  24810. ctx.lineTo(x, y);
  24811. break;
  24812. case OPS.curveTo:
  24813. x = args[j + 4];
  24814. y = args[j + 5];
  24815. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  24816. x, y);
  24817. j += 6;
  24818. break;
  24819. case OPS.curveTo2:
  24820. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  24821. args[j + 2], args[j + 3]);
  24822. x = args[j + 2];
  24823. y = args[j + 3];
  24824. j += 4;
  24825. break;
  24826. case OPS.curveTo3:
  24827. x = args[j + 2];
  24828. y = args[j + 3];
  24829. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  24830. j += 4;
  24831. break;
  24832. case OPS.closePath:
  24833. ctx.closePath();
  24834. break;
  24835. }
  24836. }
  24837. current.setCurrentPoint(x, y);
  24838. },
  24839. closePath: function CanvasGraphics_closePath() {
  24840. this.ctx.closePath();
  24841. },
  24842. stroke: function CanvasGraphics_stroke(consumePath) {
  24843. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  24844. var ctx = this.ctx;
  24845. var strokeColor = this.current.strokeColor;
  24846. // Prevent drawing too thin lines by enforcing a minimum line width.
  24847. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  24848. this.current.lineWidth);
  24849. // For stroke we want to temporarily change the global alpha to the
  24850. // stroking alpha.
  24851. ctx.globalAlpha = this.current.strokeAlpha;
  24852. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  24853. strokeColor.type === 'Pattern') {
  24854. // for patterns, we transform to pattern space, calculate
  24855. // the pattern, call stroke, and restore to user space
  24856. ctx.save();
  24857. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  24858. ctx.stroke();
  24859. ctx.restore();
  24860. } else {
  24861. ctx.stroke();
  24862. }
  24863. if (consumePath) {
  24864. this.consumePath();
  24865. }
  24866. // Restore the global alpha to the fill alpha
  24867. ctx.globalAlpha = this.current.fillAlpha;
  24868. },
  24869. closeStroke: function CanvasGraphics_closeStroke() {
  24870. this.closePath();
  24871. this.stroke();
  24872. },
  24873. fill: function CanvasGraphics_fill(consumePath) {
  24874. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  24875. var ctx = this.ctx;
  24876. var fillColor = this.current.fillColor;
  24877. var isPatternFill = this.current.patternFill;
  24878. var needRestore = false;
  24879. if (isPatternFill) {
  24880. ctx.save();
  24881. if (this.baseTransform) {
  24882. ctx.setTransform.apply(ctx, this.baseTransform);
  24883. }
  24884. ctx.fillStyle = fillColor.getPattern(ctx, this);
  24885. needRestore = true;
  24886. }
  24887. if (this.pendingEOFill) {
  24888. if (ctx.mozFillRule !== undefined) {
  24889. ctx.mozFillRule = 'evenodd';
  24890. ctx.fill();
  24891. ctx.mozFillRule = 'nonzero';
  24892. } else {
  24893. ctx.fill('evenodd');
  24894. }
  24895. this.pendingEOFill = false;
  24896. } else {
  24897. ctx.fill();
  24898. }
  24899. if (needRestore) {
  24900. ctx.restore();
  24901. }
  24902. if (consumePath) {
  24903. this.consumePath();
  24904. }
  24905. },
  24906. eoFill: function CanvasGraphics_eoFill() {
  24907. this.pendingEOFill = true;
  24908. this.fill();
  24909. },
  24910. fillStroke: function CanvasGraphics_fillStroke() {
  24911. this.fill(false);
  24912. this.stroke(false);
  24913. this.consumePath();
  24914. },
  24915. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  24916. this.pendingEOFill = true;
  24917. this.fillStroke();
  24918. },
  24919. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  24920. this.closePath();
  24921. this.fillStroke();
  24922. },
  24923. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  24924. this.pendingEOFill = true;
  24925. this.closePath();
  24926. this.fillStroke();
  24927. },
  24928. endPath: function CanvasGraphics_endPath() {
  24929. this.consumePath();
  24930. },
  24931. // Clipping
  24932. clip: function CanvasGraphics_clip() {
  24933. this.pendingClip = NORMAL_CLIP;
  24934. },
  24935. eoClip: function CanvasGraphics_eoClip() {
  24936. this.pendingClip = EO_CLIP;
  24937. },
  24938. // Text
  24939. beginText: function CanvasGraphics_beginText() {
  24940. this.current.textMatrix = IDENTITY_MATRIX;
  24941. this.current.textMatrixScale = 1;
  24942. this.current.x = this.current.lineX = 0;
  24943. this.current.y = this.current.lineY = 0;
  24944. },
  24945. endText: function CanvasGraphics_endText() {
  24946. var paths = this.pendingTextPaths;
  24947. var ctx = this.ctx;
  24948. if (paths === undefined) {
  24949. ctx.beginPath();
  24950. return;
  24951. }
  24952. ctx.save();
  24953. ctx.beginPath();
  24954. for (var i = 0; i < paths.length; i++) {
  24955. var path = paths[i];
  24956. ctx.setTransform.apply(ctx, path.transform);
  24957. ctx.translate(path.x, path.y);
  24958. path.addToPath(ctx, path.fontSize);
  24959. }
  24960. ctx.restore();
  24961. ctx.clip();
  24962. ctx.beginPath();
  24963. delete this.pendingTextPaths;
  24964. },
  24965. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  24966. this.current.charSpacing = spacing;
  24967. },
  24968. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  24969. this.current.wordSpacing = spacing;
  24970. },
  24971. setHScale: function CanvasGraphics_setHScale(scale) {
  24972. this.current.textHScale = scale / 100;
  24973. },
  24974. setLeading: function CanvasGraphics_setLeading(leading) {
  24975. this.current.leading = -leading;
  24976. },
  24977. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  24978. var fontObj = this.commonObjs.get(fontRefName);
  24979. var current = this.current;
  24980. if (!fontObj) {
  24981. error('Can\'t find font for ' + fontRefName);
  24982. }
  24983. current.fontMatrix = (fontObj.fontMatrix ?
  24984. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  24985. // A valid matrix needs all main diagonal elements to be non-zero
  24986. // This also ensures we bypass FF bugzilla bug #719844.
  24987. if (current.fontMatrix[0] === 0 ||
  24988. current.fontMatrix[3] === 0) {
  24989. warn('Invalid font matrix for font ' + fontRefName);
  24990. }
  24991. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  24992. // and in some docs this can be negative (inverted x-y axes).
  24993. if (size < 0) {
  24994. size = -size;
  24995. current.fontDirection = -1;
  24996. } else {
  24997. current.fontDirection = 1;
  24998. }
  24999. this.current.font = fontObj;
  25000. this.current.fontSize = size;
  25001. if (fontObj.isType3Font) {
  25002. return; // we don't need ctx.font for Type3 fonts
  25003. }
  25004. var name = fontObj.loadedName || 'sans-serif';
  25005. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  25006. (fontObj.bold ? 'bold' : 'normal');
  25007. var italic = fontObj.italic ? 'italic' : 'normal';
  25008. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  25009. // Some font backends cannot handle fonts below certain size.
  25010. // Keeping the font at minimal size and using the fontSizeScale to change
  25011. // the current transformation matrix before the fillText/strokeText.
  25012. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  25013. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  25014. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  25015. this.current.fontSizeScale = size / browserFontSize;
  25016. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  25017. this.ctx.font = rule;
  25018. },
  25019. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  25020. this.current.textRenderingMode = mode;
  25021. },
  25022. setTextRise: function CanvasGraphics_setTextRise(rise) {
  25023. this.current.textRise = rise;
  25024. },
  25025. moveText: function CanvasGraphics_moveText(x, y) {
  25026. this.current.x = this.current.lineX += x;
  25027. this.current.y = this.current.lineY += y;
  25028. },
  25029. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  25030. this.setLeading(-y);
  25031. this.moveText(x, y);
  25032. },
  25033. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  25034. this.current.textMatrix = [a, b, c, d, e, f];
  25035. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  25036. this.current.x = this.current.lineX = 0;
  25037. this.current.y = this.current.lineY = 0;
  25038. },
  25039. nextLine: function CanvasGraphics_nextLine() {
  25040. this.moveText(0, this.current.leading);
  25041. },
  25042. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  25043. var ctx = this.ctx;
  25044. var current = this.current;
  25045. var font = current.font;
  25046. var textRenderingMode = current.textRenderingMode;
  25047. var fontSize = current.fontSize / current.fontSizeScale;
  25048. var fillStrokeMode = textRenderingMode &
  25049. TextRenderingMode.FILL_STROKE_MASK;
  25050. var isAddToPathSet = !!(textRenderingMode &
  25051. TextRenderingMode.ADD_TO_PATH_FLAG);
  25052. var addToPath;
  25053. if (font.disableFontFace || isAddToPathSet) {
  25054. addToPath = font.getPathGenerator(this.commonObjs, character);
  25055. }
  25056. if (font.disableFontFace) {
  25057. ctx.save();
  25058. ctx.translate(x, y);
  25059. ctx.beginPath();
  25060. addToPath(ctx, fontSize);
  25061. if (fillStrokeMode === TextRenderingMode.FILL ||
  25062. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25063. ctx.fill();
  25064. }
  25065. if (fillStrokeMode === TextRenderingMode.STROKE ||
  25066. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25067. ctx.stroke();
  25068. }
  25069. ctx.restore();
  25070. } else {
  25071. if (fillStrokeMode === TextRenderingMode.FILL ||
  25072. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25073. ctx.fillText(character, x, y);
  25074. }
  25075. if (fillStrokeMode === TextRenderingMode.STROKE ||
  25076. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25077. ctx.strokeText(character, x, y);
  25078. }
  25079. }
  25080. if (isAddToPathSet) {
  25081. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  25082. paths.push({
  25083. transform: ctx.mozCurrentTransform,
  25084. x: x,
  25085. y: y,
  25086. fontSize: fontSize,
  25087. addToPath: addToPath
  25088. });
  25089. }
  25090. },
  25091. get isFontSubpixelAAEnabled() {
  25092. // Checks if anti-aliasing is enabled when scaled text is painted.
  25093. // On Windows GDI scaled fonts looks bad.
  25094. var ctx = document.createElement('canvas').getContext('2d');
  25095. ctx.scale(1.5, 1);
  25096. ctx.fillText('I', 0, 10);
  25097. var data = ctx.getImageData(0, 0, 10, 10).data;
  25098. var enabled = false;
  25099. for (var i = 3; i < data.length; i += 4) {
  25100. if (data[i] > 0 && data[i] < 255) {
  25101. enabled = true;
  25102. break;
  25103. }
  25104. }
  25105. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  25106. },
  25107. showText: function CanvasGraphics_showText(glyphs) {
  25108. var current = this.current;
  25109. var font = current.font;
  25110. if (font.isType3Font) {
  25111. return this.showType3Text(glyphs);
  25112. }
  25113. var fontSize = current.fontSize;
  25114. if (fontSize === 0) {
  25115. return;
  25116. }
  25117. var ctx = this.ctx;
  25118. var fontSizeScale = current.fontSizeScale;
  25119. var charSpacing = current.charSpacing;
  25120. var wordSpacing = current.wordSpacing;
  25121. var fontDirection = current.fontDirection;
  25122. var textHScale = current.textHScale * fontDirection;
  25123. var glyphsLength = glyphs.length;
  25124. var vertical = font.vertical;
  25125. var spacingDir = vertical ? 1 : -1;
  25126. var defaultVMetrics = font.defaultVMetrics;
  25127. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  25128. var simpleFillText =
  25129. current.textRenderingMode === TextRenderingMode.FILL &&
  25130. !font.disableFontFace;
  25131. ctx.save();
  25132. ctx.transform.apply(ctx, current.textMatrix);
  25133. ctx.translate(current.x, current.y + current.textRise);
  25134. if (fontDirection > 0) {
  25135. ctx.scale(textHScale, -1);
  25136. } else {
  25137. ctx.scale(textHScale, 1);
  25138. }
  25139. var lineWidth = current.lineWidth;
  25140. var scale = current.textMatrixScale;
  25141. if (scale === 0 || lineWidth === 0) {
  25142. var fillStrokeMode = current.textRenderingMode &
  25143. TextRenderingMode.FILL_STROKE_MASK;
  25144. if (fillStrokeMode === TextRenderingMode.STROKE ||
  25145. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  25146. this.cachedGetSinglePixelWidth = null;
  25147. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  25148. }
  25149. } else {
  25150. lineWidth /= scale;
  25151. }
  25152. if (fontSizeScale !== 1.0) {
  25153. ctx.scale(fontSizeScale, fontSizeScale);
  25154. lineWidth /= fontSizeScale;
  25155. }
  25156. ctx.lineWidth = lineWidth;
  25157. var x = 0, i;
  25158. for (i = 0; i < glyphsLength; ++i) {
  25159. var glyph = glyphs[i];
  25160. if (isNum(glyph)) {
  25161. x += spacingDir * glyph * fontSize / 1000;
  25162. continue;
  25163. }
  25164. var restoreNeeded = false;
  25165. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  25166. var character = glyph.fontChar;
  25167. var accent = glyph.accent;
  25168. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  25169. var width = glyph.width;
  25170. if (vertical) {
  25171. var vmetric, vx, vy;
  25172. vmetric = glyph.vmetric || defaultVMetrics;
  25173. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  25174. vx = -vx * widthAdvanceScale;
  25175. vy = vmetric[2] * widthAdvanceScale;
  25176. width = vmetric ? -vmetric[0] : width;
  25177. scaledX = vx / fontSizeScale;
  25178. scaledY = (x + vy) / fontSizeScale;
  25179. } else {
  25180. scaledX = x / fontSizeScale;
  25181. scaledY = 0;
  25182. }
  25183. if (font.remeasure && width > 0) {
  25184. // Some standard fonts may not have the exact width: rescale per
  25185. // character if measured width is greater than expected glyph width
  25186. // and subpixel-aa is enabled, otherwise just center the glyph.
  25187. var measuredWidth = ctx.measureText(character).width * 1000 /
  25188. fontSize * fontSizeScale;
  25189. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  25190. var characterScaleX = width / measuredWidth;
  25191. restoreNeeded = true;
  25192. ctx.save();
  25193. ctx.scale(characterScaleX, 1);
  25194. scaledX /= characterScaleX;
  25195. } else if (width !== measuredWidth) {
  25196. scaledX += (width - measuredWidth) / 2000 *
  25197. fontSize / fontSizeScale;
  25198. }
  25199. }
  25200. if (simpleFillText && !accent) {
  25201. // common case
  25202. ctx.fillText(character, scaledX, scaledY);
  25203. } else {
  25204. this.paintChar(character, scaledX, scaledY);
  25205. if (accent) {
  25206. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  25207. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  25208. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  25209. }
  25210. }
  25211. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  25212. x += charWidth;
  25213. if (restoreNeeded) {
  25214. ctx.restore();
  25215. }
  25216. }
  25217. if (vertical) {
  25218. current.y -= x * textHScale;
  25219. } else {
  25220. current.x += x * textHScale;
  25221. }
  25222. ctx.restore();
  25223. },
  25224. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  25225. // Type3 fonts - each glyph is a "mini-PDF"
  25226. var ctx = this.ctx;
  25227. var current = this.current;
  25228. var font = current.font;
  25229. var fontSize = current.fontSize;
  25230. var fontDirection = current.fontDirection;
  25231. var spacingDir = font.vertical ? 1 : -1;
  25232. var charSpacing = current.charSpacing;
  25233. var wordSpacing = current.wordSpacing;
  25234. var textHScale = current.textHScale * fontDirection;
  25235. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  25236. var glyphsLength = glyphs.length;
  25237. var isTextInvisible =
  25238. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  25239. var i, glyph, width, spacingLength;
  25240. if (isTextInvisible || fontSize === 0) {
  25241. return;
  25242. }
  25243. this.cachedGetSinglePixelWidth = null;
  25244. ctx.save();
  25245. ctx.transform.apply(ctx, current.textMatrix);
  25246. ctx.translate(current.x, current.y);
  25247. ctx.scale(textHScale, fontDirection);
  25248. for (i = 0; i < glyphsLength; ++i) {
  25249. glyph = glyphs[i];
  25250. if (isNum(glyph)) {
  25251. spacingLength = spacingDir * glyph * fontSize / 1000;
  25252. this.ctx.translate(spacingLength, 0);
  25253. current.x += spacingLength * textHScale;
  25254. continue;
  25255. }
  25256. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  25257. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  25258. if (!operatorList) {
  25259. warn('Type3 character \"' + glyph.operatorListId +
  25260. '\" is not available');
  25261. continue;
  25262. }
  25263. this.processingType3 = glyph;
  25264. this.save();
  25265. ctx.scale(fontSize, fontSize);
  25266. ctx.transform.apply(ctx, fontMatrix);
  25267. this.executeOperatorList(operatorList);
  25268. this.restore();
  25269. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  25270. width = transformed[0] * fontSize + spacing;
  25271. ctx.translate(width, 0);
  25272. current.x += width * textHScale;
  25273. }
  25274. ctx.restore();
  25275. this.processingType3 = null;
  25276. },
  25277. // Type3 fonts
  25278. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  25279. // We can safely ignore this since the width should be the same
  25280. // as the width in the Widths array.
  25281. },
  25282. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  25283. yWidth,
  25284. llx,
  25285. lly,
  25286. urx,
  25287. ury) {
  25288. // TODO According to the spec we're also suppose to ignore any operators
  25289. // that set color or include images while processing this type3 font.
  25290. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  25291. this.clip();
  25292. this.endPath();
  25293. },
  25294. // Color
  25295. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  25296. var pattern;
  25297. if (IR[0] === 'TilingPattern') {
  25298. var color = IR[1];
  25299. var baseTransform = this.baseTransform ||
  25300. this.ctx.mozCurrentTransform.slice();
  25301. var self = this;
  25302. var canvasGraphicsFactory = {
  25303. createCanvasGraphics: function (ctx) {
  25304. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  25305. }
  25306. };
  25307. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  25308. baseTransform);
  25309. } else {
  25310. pattern = getShadingPatternFromIR(IR);
  25311. }
  25312. return pattern;
  25313. },
  25314. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  25315. this.current.strokeColor = this.getColorN_Pattern(arguments);
  25316. },
  25317. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  25318. this.current.fillColor = this.getColorN_Pattern(arguments);
  25319. this.current.patternFill = true;
  25320. },
  25321. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  25322. var color = Util.makeCssRgb(r, g, b);
  25323. this.ctx.strokeStyle = color;
  25324. this.current.strokeColor = color;
  25325. },
  25326. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  25327. var color = Util.makeCssRgb(r, g, b);
  25328. this.ctx.fillStyle = color;
  25329. this.current.fillColor = color;
  25330. this.current.patternFill = false;
  25331. },
  25332. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  25333. var ctx = this.ctx;
  25334. this.save();
  25335. var pattern = getShadingPatternFromIR(patternIR);
  25336. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  25337. var inv = ctx.mozCurrentTransformInverse;
  25338. if (inv) {
  25339. var canvas = ctx.canvas;
  25340. var width = canvas.width;
  25341. var height = canvas.height;
  25342. var bl = Util.applyTransform([0, 0], inv);
  25343. var br = Util.applyTransform([0, height], inv);
  25344. var ul = Util.applyTransform([width, 0], inv);
  25345. var ur = Util.applyTransform([width, height], inv);
  25346. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  25347. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  25348. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  25349. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  25350. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  25351. } else {
  25352. // HACK to draw the gradient onto an infinite rectangle.
  25353. // PDF gradients are drawn across the entire image while
  25354. // Canvas only allows gradients to be drawn in a rectangle
  25355. // The following bug should allow us to remove this.
  25356. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  25357. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  25358. }
  25359. this.restore();
  25360. },
  25361. // Images
  25362. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  25363. error('Should not call beginInlineImage');
  25364. },
  25365. beginImageData: function CanvasGraphics_beginImageData() {
  25366. error('Should not call beginImageData');
  25367. },
  25368. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  25369. bbox) {
  25370. this.save();
  25371. this.baseTransformStack.push(this.baseTransform);
  25372. if (isArray(matrix) && 6 === matrix.length) {
  25373. this.transform.apply(this, matrix);
  25374. }
  25375. this.baseTransform = this.ctx.mozCurrentTransform;
  25376. if (isArray(bbox) && 4 === bbox.length) {
  25377. var width = bbox[2] - bbox[0];
  25378. var height = bbox[3] - bbox[1];
  25379. this.ctx.rect(bbox[0], bbox[1], width, height);
  25380. this.clip();
  25381. this.endPath();
  25382. }
  25383. },
  25384. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  25385. this.restore();
  25386. this.baseTransform = this.baseTransformStack.pop();
  25387. },
  25388. beginGroup: function CanvasGraphics_beginGroup(group) {
  25389. this.save();
  25390. var currentCtx = this.ctx;
  25391. // TODO non-isolated groups - according to Rik at adobe non-isolated
  25392. // group results aren't usually that different and they even have tools
  25393. // that ignore this setting. Notes from Rik on implmenting:
  25394. // - When you encounter an transparency group, create a new canvas with
  25395. // the dimensions of the bbox
  25396. // - copy the content from the previous canvas to the new canvas
  25397. // - draw as usual
  25398. // - remove the backdrop alpha:
  25399. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  25400. // value of your transparency group and 'alphaBackdrop' the alpha of the
  25401. // backdrop
  25402. // - remove background color:
  25403. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  25404. if (!group.isolated) {
  25405. info('TODO: Support non-isolated groups.');
  25406. }
  25407. // TODO knockout - supposedly possible with the clever use of compositing
  25408. // modes.
  25409. if (group.knockout) {
  25410. warn('Knockout groups not supported.');
  25411. }
  25412. var currentTransform = currentCtx.mozCurrentTransform;
  25413. if (group.matrix) {
  25414. currentCtx.transform.apply(currentCtx, group.matrix);
  25415. }
  25416. assert(group.bbox, 'Bounding box is required.');
  25417. // Based on the current transform figure out how big the bounding box
  25418. // will actually be.
  25419. var bounds = Util.getAxialAlignedBoundingBox(
  25420. group.bbox,
  25421. currentCtx.mozCurrentTransform);
  25422. // Clip the bounding box to the current canvas.
  25423. var canvasBounds = [0,
  25424. 0,
  25425. currentCtx.canvas.width,
  25426. currentCtx.canvas.height];
  25427. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  25428. // Use ceil in case we're between sizes so we don't create canvas that is
  25429. // too small and make the canvas at least 1x1 pixels.
  25430. var offsetX = Math.floor(bounds[0]);
  25431. var offsetY = Math.floor(bounds[1]);
  25432. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  25433. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  25434. var scaleX = 1, scaleY = 1;
  25435. if (drawnWidth > MAX_GROUP_SIZE) {
  25436. scaleX = drawnWidth / MAX_GROUP_SIZE;
  25437. drawnWidth = MAX_GROUP_SIZE;
  25438. }
  25439. if (drawnHeight > MAX_GROUP_SIZE) {
  25440. scaleY = drawnHeight / MAX_GROUP_SIZE;
  25441. drawnHeight = MAX_GROUP_SIZE;
  25442. }
  25443. var cacheId = 'groupAt' + this.groupLevel;
  25444. if (group.smask) {
  25445. // Using two cache entries is case if masks are used one after another.
  25446. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  25447. }
  25448. var scratchCanvas = this.cachedCanvases.getCanvas(
  25449. cacheId, drawnWidth, drawnHeight, true);
  25450. var groupCtx = scratchCanvas.context;
  25451. // Since we created a new canvas that is just the size of the bounding box
  25452. // we have to translate the group ctx.
  25453. groupCtx.scale(1 / scaleX, 1 / scaleY);
  25454. groupCtx.translate(-offsetX, -offsetY);
  25455. groupCtx.transform.apply(groupCtx, currentTransform);
  25456. if (group.smask) {
  25457. // Saving state and cached mask to be used in setGState.
  25458. this.smaskStack.push({
  25459. canvas: scratchCanvas.canvas,
  25460. context: groupCtx,
  25461. offsetX: offsetX,
  25462. offsetY: offsetY,
  25463. scaleX: scaleX,
  25464. scaleY: scaleY,
  25465. subtype: group.smask.subtype,
  25466. backdrop: group.smask.backdrop,
  25467. transferMap: group.smask.transferMap || null
  25468. });
  25469. } else {
  25470. // Setup the current ctx so when the group is popped we draw it at the
  25471. // right location.
  25472. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  25473. currentCtx.translate(offsetX, offsetY);
  25474. currentCtx.scale(scaleX, scaleY);
  25475. }
  25476. // The transparency group inherits all off the current graphics state
  25477. // except the blend mode, soft mask, and alpha constants.
  25478. copyCtxState(currentCtx, groupCtx);
  25479. this.ctx = groupCtx;
  25480. this.setGState([
  25481. ['BM', 'Normal'],
  25482. ['ca', 1],
  25483. ['CA', 1]
  25484. ]);
  25485. this.groupStack.push(currentCtx);
  25486. this.groupLevel++;
  25487. },
  25488. endGroup: function CanvasGraphics_endGroup(group) {
  25489. this.groupLevel--;
  25490. var groupCtx = this.ctx;
  25491. this.ctx = this.groupStack.pop();
  25492. // Turn off image smoothing to avoid sub pixel interpolation which can
  25493. // look kind of blurry for some pdfs.
  25494. if (this.ctx.imageSmoothingEnabled !== undefined) {
  25495. this.ctx.imageSmoothingEnabled = false;
  25496. } else {
  25497. this.ctx.mozImageSmoothingEnabled = false;
  25498. }
  25499. if (group.smask) {
  25500. this.tempSMask = this.smaskStack.pop();
  25501. } else {
  25502. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  25503. }
  25504. this.restore();
  25505. },
  25506. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  25507. this.save();
  25508. this.current = new CanvasExtraState();
  25509. if (this.baseTransform) {
  25510. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  25511. }
  25512. },
  25513. endAnnotations: function CanvasGraphics_endAnnotations() {
  25514. this.restore();
  25515. },
  25516. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  25517. matrix) {
  25518. this.save();
  25519. if (isArray(rect) && 4 === rect.length) {
  25520. var width = rect[2] - rect[0];
  25521. var height = rect[3] - rect[1];
  25522. this.ctx.rect(rect[0], rect[1], width, height);
  25523. this.clip();
  25524. this.endPath();
  25525. }
  25526. this.transform.apply(this, transform);
  25527. this.transform.apply(this, matrix);
  25528. },
  25529. endAnnotation: function CanvasGraphics_endAnnotation() {
  25530. this.restore();
  25531. },
  25532. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  25533. var domImage = this.objs.get(objId);
  25534. if (!domImage) {
  25535. warn('Dependent image isn\'t ready yet');
  25536. return;
  25537. }
  25538. this.save();
  25539. var ctx = this.ctx;
  25540. // scale the image to the unit square
  25541. ctx.scale(1 / w, -1 / h);
  25542. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  25543. 0, -h, w, h);
  25544. if (this.imageLayer) {
  25545. var currentTransform = ctx.mozCurrentTransformInverse;
  25546. var position = this.getCanvasPosition(0, 0);
  25547. this.imageLayer.appendImage({
  25548. objId: objId,
  25549. left: position[0],
  25550. top: position[1],
  25551. width: w / currentTransform[0],
  25552. height: h / currentTransform[3]
  25553. });
  25554. }
  25555. this.restore();
  25556. },
  25557. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  25558. var ctx = this.ctx;
  25559. var width = img.width, height = img.height;
  25560. var fillColor = this.current.fillColor;
  25561. var isPatternFill = this.current.patternFill;
  25562. var glyph = this.processingType3;
  25563. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  25564. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  25565. glyph.compiled =
  25566. compileType3Glyph({data: img.data, width: width, height: height});
  25567. } else {
  25568. glyph.compiled = null;
  25569. }
  25570. }
  25571. if (glyph && glyph.compiled) {
  25572. glyph.compiled(ctx);
  25573. return;
  25574. }
  25575. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  25576. width, height);
  25577. var maskCtx = maskCanvas.context;
  25578. maskCtx.save();
  25579. putBinaryImageMask(maskCtx, img);
  25580. maskCtx.globalCompositeOperation = 'source-in';
  25581. maskCtx.fillStyle = isPatternFill ?
  25582. fillColor.getPattern(maskCtx, this) : fillColor;
  25583. maskCtx.fillRect(0, 0, width, height);
  25584. maskCtx.restore();
  25585. this.paintInlineImageXObject(maskCanvas.canvas);
  25586. },
  25587. paintImageMaskXObjectRepeat:
  25588. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  25589. scaleY, positions) {
  25590. var width = imgData.width;
  25591. var height = imgData.height;
  25592. var fillColor = this.current.fillColor;
  25593. var isPatternFill = this.current.patternFill;
  25594. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  25595. width, height);
  25596. var maskCtx = maskCanvas.context;
  25597. maskCtx.save();
  25598. putBinaryImageMask(maskCtx, imgData);
  25599. maskCtx.globalCompositeOperation = 'source-in';
  25600. maskCtx.fillStyle = isPatternFill ?
  25601. fillColor.getPattern(maskCtx, this) : fillColor;
  25602. maskCtx.fillRect(0, 0, width, height);
  25603. maskCtx.restore();
  25604. var ctx = this.ctx;
  25605. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  25606. ctx.save();
  25607. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  25608. ctx.scale(1, -1);
  25609. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  25610. 0, -1, 1, 1);
  25611. ctx.restore();
  25612. }
  25613. },
  25614. paintImageMaskXObjectGroup:
  25615. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  25616. var ctx = this.ctx;
  25617. var fillColor = this.current.fillColor;
  25618. var isPatternFill = this.current.patternFill;
  25619. for (var i = 0, ii = images.length; i < ii; i++) {
  25620. var image = images[i];
  25621. var width = image.width, height = image.height;
  25622. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  25623. width, height);
  25624. var maskCtx = maskCanvas.context;
  25625. maskCtx.save();
  25626. putBinaryImageMask(maskCtx, image);
  25627. maskCtx.globalCompositeOperation = 'source-in';
  25628. maskCtx.fillStyle = isPatternFill ?
  25629. fillColor.getPattern(maskCtx, this) : fillColor;
  25630. maskCtx.fillRect(0, 0, width, height);
  25631. maskCtx.restore();
  25632. ctx.save();
  25633. ctx.transform.apply(ctx, image.transform);
  25634. ctx.scale(1, -1);
  25635. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  25636. 0, -1, 1, 1);
  25637. ctx.restore();
  25638. }
  25639. },
  25640. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  25641. var imgData = this.objs.get(objId);
  25642. if (!imgData) {
  25643. warn('Dependent image isn\'t ready yet');
  25644. return;
  25645. }
  25646. this.paintInlineImageXObject(imgData);
  25647. },
  25648. paintImageXObjectRepeat:
  25649. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  25650. positions) {
  25651. var imgData = this.objs.get(objId);
  25652. if (!imgData) {
  25653. warn('Dependent image isn\'t ready yet');
  25654. return;
  25655. }
  25656. var width = imgData.width;
  25657. var height = imgData.height;
  25658. var map = [];
  25659. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  25660. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  25661. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  25662. }
  25663. this.paintInlineImageXObjectGroup(imgData, map);
  25664. },
  25665. paintInlineImageXObject:
  25666. function CanvasGraphics_paintInlineImageXObject(imgData) {
  25667. var width = imgData.width;
  25668. var height = imgData.height;
  25669. var ctx = this.ctx;
  25670. this.save();
  25671. // scale the image to the unit square
  25672. ctx.scale(1 / width, -1 / height);
  25673. var currentTransform = ctx.mozCurrentTransformInverse;
  25674. var a = currentTransform[0], b = currentTransform[1];
  25675. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  25676. var c = currentTransform[2], d = currentTransform[3];
  25677. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  25678. var imgToPaint, tmpCanvas;
  25679. // instanceof HTMLElement does not work in jsdom node.js module
  25680. if (imgData instanceof HTMLElement || !imgData.data) {
  25681. imgToPaint = imgData;
  25682. } else {
  25683. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  25684. width, height);
  25685. var tmpCtx = tmpCanvas.context;
  25686. putBinaryImageData(tmpCtx, imgData);
  25687. imgToPaint = tmpCanvas.canvas;
  25688. }
  25689. var paintWidth = width, paintHeight = height;
  25690. var tmpCanvasId = 'prescale1';
  25691. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  25692. // pixels during drawImage operation, painting on the temporary canvas(es)
  25693. // that are twice smaller in size
  25694. while ((widthScale > 2 && paintWidth > 1) ||
  25695. (heightScale > 2 && paintHeight > 1)) {
  25696. var newWidth = paintWidth, newHeight = paintHeight;
  25697. if (widthScale > 2 && paintWidth > 1) {
  25698. newWidth = Math.ceil(paintWidth / 2);
  25699. widthScale /= paintWidth / newWidth;
  25700. }
  25701. if (heightScale > 2 && paintHeight > 1) {
  25702. newHeight = Math.ceil(paintHeight / 2);
  25703. heightScale /= paintHeight / newHeight;
  25704. }
  25705. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  25706. newWidth, newHeight);
  25707. tmpCtx = tmpCanvas.context;
  25708. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  25709. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  25710. 0, 0, newWidth, newHeight);
  25711. imgToPaint = tmpCanvas.canvas;
  25712. paintWidth = newWidth;
  25713. paintHeight = newHeight;
  25714. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  25715. }
  25716. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  25717. 0, -height, width, height);
  25718. if (this.imageLayer) {
  25719. var position = this.getCanvasPosition(0, -height);
  25720. this.imageLayer.appendImage({
  25721. imgData: imgData,
  25722. left: position[0],
  25723. top: position[1],
  25724. width: width / currentTransform[0],
  25725. height: height / currentTransform[3]
  25726. });
  25727. }
  25728. this.restore();
  25729. },
  25730. paintInlineImageXObjectGroup:
  25731. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  25732. var ctx = this.ctx;
  25733. var w = imgData.width;
  25734. var h = imgData.height;
  25735. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  25736. var tmpCtx = tmpCanvas.context;
  25737. putBinaryImageData(tmpCtx, imgData);
  25738. for (var i = 0, ii = map.length; i < ii; i++) {
  25739. var entry = map[i];
  25740. ctx.save();
  25741. ctx.transform.apply(ctx, entry.transform);
  25742. ctx.scale(1, -1);
  25743. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  25744. 0, -1, 1, 1);
  25745. if (this.imageLayer) {
  25746. var position = this.getCanvasPosition(entry.x, entry.y);
  25747. this.imageLayer.appendImage({
  25748. imgData: imgData,
  25749. left: position[0],
  25750. top: position[1],
  25751. width: w,
  25752. height: h
  25753. });
  25754. }
  25755. ctx.restore();
  25756. }
  25757. },
  25758. paintSolidColorImageMask:
  25759. function CanvasGraphics_paintSolidColorImageMask() {
  25760. this.ctx.fillRect(0, 0, 1, 1);
  25761. },
  25762. paintXObject: function CanvasGraphics_paintXObject() {
  25763. warn('Unsupported \'paintXObject\' command.');
  25764. },
  25765. // Marked content
  25766. markPoint: function CanvasGraphics_markPoint(tag) {
  25767. // TODO Marked content.
  25768. },
  25769. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  25770. // TODO Marked content.
  25771. },
  25772. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  25773. // TODO Marked content.
  25774. },
  25775. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  25776. tag, properties) {
  25777. // TODO Marked content.
  25778. },
  25779. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  25780. // TODO Marked content.
  25781. },
  25782. // Compatibility
  25783. beginCompat: function CanvasGraphics_beginCompat() {
  25784. // TODO ignore undefined operators (should we do that anyway?)
  25785. },
  25786. endCompat: function CanvasGraphics_endCompat() {
  25787. // TODO stop ignoring undefined operators
  25788. },
  25789. // Helper functions
  25790. consumePath: function CanvasGraphics_consumePath() {
  25791. var ctx = this.ctx;
  25792. if (this.pendingClip) {
  25793. if (this.pendingClip === EO_CLIP) {
  25794. if (ctx.mozFillRule !== undefined) {
  25795. ctx.mozFillRule = 'evenodd';
  25796. ctx.clip();
  25797. ctx.mozFillRule = 'nonzero';
  25798. } else {
  25799. ctx.clip('evenodd');
  25800. }
  25801. } else {
  25802. ctx.clip();
  25803. }
  25804. this.pendingClip = null;
  25805. }
  25806. ctx.beginPath();
  25807. },
  25808. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  25809. if (this.cachedGetSinglePixelWidth === null) {
  25810. var inverse = this.ctx.mozCurrentTransformInverse;
  25811. // max of the current horizontal and vertical scale
  25812. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  25813. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  25814. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  25815. }
  25816. return this.cachedGetSinglePixelWidth;
  25817. },
  25818. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  25819. var transform = this.ctx.mozCurrentTransform;
  25820. return [
  25821. transform[0] * x + transform[2] * y + transform[4],
  25822. transform[1] * x + transform[3] * y + transform[5]
  25823. ];
  25824. }
  25825. };
  25826. for (var op in OPS) {
  25827. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  25828. }
  25829. return CanvasGraphics;
  25830. })();
  25831. exports.CanvasGraphics = CanvasGraphics;
  25832. exports.createScratchCanvas = createScratchCanvas;
  25833. }));
  25834. (function (root, factory) {
  25835. {
  25836. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  25837. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  25838. }
  25839. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  25840. var Util = sharedUtil.Util;
  25841. var assert = sharedUtil.assert;
  25842. var error = sharedUtil.error;
  25843. var isInt = sharedUtil.isInt;
  25844. var isString = sharedUtil.isString;
  25845. var warn = sharedUtil.warn;
  25846. var isName = corePrimitives.isName;
  25847. var isCmd = corePrimitives.isCmd;
  25848. var isStream = corePrimitives.isStream;
  25849. var StringStream = coreStream.StringStream;
  25850. var Lexer = coreParser.Lexer;
  25851. var isEOF = coreParser.isEOF;
  25852. var BUILT_IN_CMAPS = [
  25853. // << Start unicode maps.
  25854. 'Adobe-GB1-UCS2',
  25855. 'Adobe-CNS1-UCS2',
  25856. 'Adobe-Japan1-UCS2',
  25857. 'Adobe-Korea1-UCS2',
  25858. // >> End unicode maps.
  25859. '78-EUC-H',
  25860. '78-EUC-V',
  25861. '78-H',
  25862. '78-RKSJ-H',
  25863. '78-RKSJ-V',
  25864. '78-V',
  25865. '78ms-RKSJ-H',
  25866. '78ms-RKSJ-V',
  25867. '83pv-RKSJ-H',
  25868. '90ms-RKSJ-H',
  25869. '90ms-RKSJ-V',
  25870. '90msp-RKSJ-H',
  25871. '90msp-RKSJ-V',
  25872. '90pv-RKSJ-H',
  25873. '90pv-RKSJ-V',
  25874. 'Add-H',
  25875. 'Add-RKSJ-H',
  25876. 'Add-RKSJ-V',
  25877. 'Add-V',
  25878. 'Adobe-CNS1-0',
  25879. 'Adobe-CNS1-1',
  25880. 'Adobe-CNS1-2',
  25881. 'Adobe-CNS1-3',
  25882. 'Adobe-CNS1-4',
  25883. 'Adobe-CNS1-5',
  25884. 'Adobe-CNS1-6',
  25885. 'Adobe-GB1-0',
  25886. 'Adobe-GB1-1',
  25887. 'Adobe-GB1-2',
  25888. 'Adobe-GB1-3',
  25889. 'Adobe-GB1-4',
  25890. 'Adobe-GB1-5',
  25891. 'Adobe-Japan1-0',
  25892. 'Adobe-Japan1-1',
  25893. 'Adobe-Japan1-2',
  25894. 'Adobe-Japan1-3',
  25895. 'Adobe-Japan1-4',
  25896. 'Adobe-Japan1-5',
  25897. 'Adobe-Japan1-6',
  25898. 'Adobe-Korea1-0',
  25899. 'Adobe-Korea1-1',
  25900. 'Adobe-Korea1-2',
  25901. 'B5-H',
  25902. 'B5-V',
  25903. 'B5pc-H',
  25904. 'B5pc-V',
  25905. 'CNS-EUC-H',
  25906. 'CNS-EUC-V',
  25907. 'CNS1-H',
  25908. 'CNS1-V',
  25909. 'CNS2-H',
  25910. 'CNS2-V',
  25911. 'ETHK-B5-H',
  25912. 'ETHK-B5-V',
  25913. 'ETen-B5-H',
  25914. 'ETen-B5-V',
  25915. 'ETenms-B5-H',
  25916. 'ETenms-B5-V',
  25917. 'EUC-H',
  25918. 'EUC-V',
  25919. 'Ext-H',
  25920. 'Ext-RKSJ-H',
  25921. 'Ext-RKSJ-V',
  25922. 'Ext-V',
  25923. 'GB-EUC-H',
  25924. 'GB-EUC-V',
  25925. 'GB-H',
  25926. 'GB-V',
  25927. 'GBK-EUC-H',
  25928. 'GBK-EUC-V',
  25929. 'GBK2K-H',
  25930. 'GBK2K-V',
  25931. 'GBKp-EUC-H',
  25932. 'GBKp-EUC-V',
  25933. 'GBT-EUC-H',
  25934. 'GBT-EUC-V',
  25935. 'GBT-H',
  25936. 'GBT-V',
  25937. 'GBTpc-EUC-H',
  25938. 'GBTpc-EUC-V',
  25939. 'GBpc-EUC-H',
  25940. 'GBpc-EUC-V',
  25941. 'H',
  25942. 'HKdla-B5-H',
  25943. 'HKdla-B5-V',
  25944. 'HKdlb-B5-H',
  25945. 'HKdlb-B5-V',
  25946. 'HKgccs-B5-H',
  25947. 'HKgccs-B5-V',
  25948. 'HKm314-B5-H',
  25949. 'HKm314-B5-V',
  25950. 'HKm471-B5-H',
  25951. 'HKm471-B5-V',
  25952. 'HKscs-B5-H',
  25953. 'HKscs-B5-V',
  25954. 'Hankaku',
  25955. 'Hiragana',
  25956. 'KSC-EUC-H',
  25957. 'KSC-EUC-V',
  25958. 'KSC-H',
  25959. 'KSC-Johab-H',
  25960. 'KSC-Johab-V',
  25961. 'KSC-V',
  25962. 'KSCms-UHC-H',
  25963. 'KSCms-UHC-HW-H',
  25964. 'KSCms-UHC-HW-V',
  25965. 'KSCms-UHC-V',
  25966. 'KSCpc-EUC-H',
  25967. 'KSCpc-EUC-V',
  25968. 'Katakana',
  25969. 'NWP-H',
  25970. 'NWP-V',
  25971. 'RKSJ-H',
  25972. 'RKSJ-V',
  25973. 'Roman',
  25974. 'UniCNS-UCS2-H',
  25975. 'UniCNS-UCS2-V',
  25976. 'UniCNS-UTF16-H',
  25977. 'UniCNS-UTF16-V',
  25978. 'UniCNS-UTF32-H',
  25979. 'UniCNS-UTF32-V',
  25980. 'UniCNS-UTF8-H',
  25981. 'UniCNS-UTF8-V',
  25982. 'UniGB-UCS2-H',
  25983. 'UniGB-UCS2-V',
  25984. 'UniGB-UTF16-H',
  25985. 'UniGB-UTF16-V',
  25986. 'UniGB-UTF32-H',
  25987. 'UniGB-UTF32-V',
  25988. 'UniGB-UTF8-H',
  25989. 'UniGB-UTF8-V',
  25990. 'UniJIS-UCS2-H',
  25991. 'UniJIS-UCS2-HW-H',
  25992. 'UniJIS-UCS2-HW-V',
  25993. 'UniJIS-UCS2-V',
  25994. 'UniJIS-UTF16-H',
  25995. 'UniJIS-UTF16-V',
  25996. 'UniJIS-UTF32-H',
  25997. 'UniJIS-UTF32-V',
  25998. 'UniJIS-UTF8-H',
  25999. 'UniJIS-UTF8-V',
  26000. 'UniJIS2004-UTF16-H',
  26001. 'UniJIS2004-UTF16-V',
  26002. 'UniJIS2004-UTF32-H',
  26003. 'UniJIS2004-UTF32-V',
  26004. 'UniJIS2004-UTF8-H',
  26005. 'UniJIS2004-UTF8-V',
  26006. 'UniJISPro-UCS2-HW-V',
  26007. 'UniJISPro-UCS2-V',
  26008. 'UniJISPro-UTF8-V',
  26009. 'UniJISX0213-UTF32-H',
  26010. 'UniJISX0213-UTF32-V',
  26011. 'UniJISX02132004-UTF32-H',
  26012. 'UniJISX02132004-UTF32-V',
  26013. 'UniKS-UCS2-H',
  26014. 'UniKS-UCS2-V',
  26015. 'UniKS-UTF16-H',
  26016. 'UniKS-UTF16-V',
  26017. 'UniKS-UTF32-H',
  26018. 'UniKS-UTF32-V',
  26019. 'UniKS-UTF8-H',
  26020. 'UniKS-UTF8-V',
  26021. 'V',
  26022. 'WP-Symbol'];
  26023. // CMap, not to be confused with TrueType's cmap.
  26024. var CMap = (function CMapClosure() {
  26025. function CMap(builtInCMap) {
  26026. // Codespace ranges are stored as follows:
  26027. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  26028. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  26029. this.codespaceRanges = [[], [], [], []];
  26030. this.numCodespaceRanges = 0;
  26031. // Map entries have one of two forms.
  26032. // - cid chars are 16-bit unsigned integers, stored as integers.
  26033. // - bf chars are variable-length byte sequences, stored as strings, with
  26034. // one byte per character.
  26035. this._map = [];
  26036. this.name = '';
  26037. this.vertical = false;
  26038. this.useCMap = null;
  26039. this.builtInCMap = builtInCMap;
  26040. }
  26041. CMap.prototype = {
  26042. addCodespaceRange: function(n, low, high) {
  26043. this.codespaceRanges[n - 1].push(low, high);
  26044. this.numCodespaceRanges++;
  26045. },
  26046. mapCidRange: function(low, high, dstLow) {
  26047. while (low <= high) {
  26048. this._map[low++] = dstLow++;
  26049. }
  26050. },
  26051. mapBfRange: function(low, high, dstLow) {
  26052. var lastByte = dstLow.length - 1;
  26053. while (low <= high) {
  26054. this._map[low++] = dstLow;
  26055. // Only the last byte has to be incremented.
  26056. dstLow = dstLow.substr(0, lastByte) +
  26057. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  26058. }
  26059. },
  26060. mapBfRangeToArray: function(low, high, array) {
  26061. var i = 0, ii = array.length;
  26062. while (low <= high && i < ii) {
  26063. this._map[low] = array[i++];
  26064. ++low;
  26065. }
  26066. },
  26067. // This is used for both bf and cid chars.
  26068. mapOne: function(src, dst) {
  26069. this._map[src] = dst;
  26070. },
  26071. lookup: function(code) {
  26072. return this._map[code];
  26073. },
  26074. contains: function(code) {
  26075. return this._map[code] !== undefined;
  26076. },
  26077. forEach: function(callback) {
  26078. // Most maps have fewer than 65536 entries, and for those we use normal
  26079. // array iteration. But really sparse tables are possible -- e.g. with
  26080. // indices in the *billions*. For such tables we use for..in, which isn't
  26081. // ideal because it stringifies the indices for all present elements, but
  26082. // it does avoid iterating over every undefined entry.
  26083. var map = this._map;
  26084. var length = map.length;
  26085. var i;
  26086. if (length <= 0x10000) {
  26087. for (i = 0; i < length; i++) {
  26088. if (map[i] !== undefined) {
  26089. callback(i, map[i]);
  26090. }
  26091. }
  26092. } else {
  26093. for (i in this._map) {
  26094. callback(i, map[i]);
  26095. }
  26096. }
  26097. },
  26098. charCodeOf: function(value) {
  26099. return this._map.indexOf(value);
  26100. },
  26101. getMap: function() {
  26102. return this._map;
  26103. },
  26104. readCharCode: function(str, offset, out) {
  26105. var c = 0;
  26106. var codespaceRanges = this.codespaceRanges;
  26107. var codespaceRangesLen = this.codespaceRanges.length;
  26108. // 9.7.6.2 CMap Mapping
  26109. // The code length is at most 4.
  26110. for (var n = 0; n < codespaceRangesLen; n++) {
  26111. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  26112. // Check each codespace range to see if it falls within.
  26113. var codespaceRange = codespaceRanges[n];
  26114. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  26115. var low = codespaceRange[k++];
  26116. var high = codespaceRange[k++];
  26117. if (c >= low && c <= high) {
  26118. out.charcode = c;
  26119. out.length = n + 1;
  26120. return;
  26121. }
  26122. }
  26123. }
  26124. out.charcode = 0;
  26125. out.length = 1;
  26126. },
  26127. get length() {
  26128. return this._map.length;
  26129. },
  26130. get isIdentityCMap() {
  26131. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  26132. return false;
  26133. }
  26134. if (this._map.length !== 0x10000) {
  26135. return false;
  26136. }
  26137. for (var i = 0; i < 0x10000; i++) {
  26138. if (this._map[i] !== i) {
  26139. return false;
  26140. }
  26141. }
  26142. return true;
  26143. }
  26144. };
  26145. return CMap;
  26146. })();
  26147. // A special case of CMap, where the _map array implicitly has a length of
  26148. // 65536 and each element is equal to its index.
  26149. var IdentityCMap = (function IdentityCMapClosure() {
  26150. function IdentityCMap(vertical, n) {
  26151. CMap.call(this);
  26152. this.vertical = vertical;
  26153. this.addCodespaceRange(n, 0, 0xffff);
  26154. }
  26155. Util.inherit(IdentityCMap, CMap, {});
  26156. IdentityCMap.prototype = {
  26157. addCodespaceRange: CMap.prototype.addCodespaceRange,
  26158. mapCidRange: function(low, high, dstLow) {
  26159. error('should not call mapCidRange');
  26160. },
  26161. mapBfRange: function(low, high, dstLow) {
  26162. error('should not call mapBfRange');
  26163. },
  26164. mapBfRangeToArray: function(low, high, array) {
  26165. error('should not call mapBfRangeToArray');
  26166. },
  26167. mapOne: function(src, dst) {
  26168. error('should not call mapCidOne');
  26169. },
  26170. lookup: function(code) {
  26171. return (isInt(code) && code <= 0xffff) ? code : undefined;
  26172. },
  26173. contains: function(code) {
  26174. return isInt(code) && code <= 0xffff;
  26175. },
  26176. forEach: function(callback) {
  26177. for (var i = 0; i <= 0xffff; i++) {
  26178. callback(i, i);
  26179. }
  26180. },
  26181. charCodeOf: function(value) {
  26182. return (isInt(value) && value <= 0xffff) ? value : -1;
  26183. },
  26184. getMap: function() {
  26185. // Sometimes identity maps must be instantiated, but it's rare.
  26186. var map = new Array(0x10000);
  26187. for (var i = 0; i <= 0xffff; i++) {
  26188. map[i] = i;
  26189. }
  26190. return map;
  26191. },
  26192. readCharCode: CMap.prototype.readCharCode,
  26193. get length() {
  26194. return 0x10000;
  26195. },
  26196. get isIdentityCMap() {
  26197. error('should not access .isIdentityCMap');
  26198. }
  26199. };
  26200. return IdentityCMap;
  26201. })();
  26202. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  26203. function fetchBinaryData(url) {
  26204. var nonBinaryRequest = PDFJS.disableWorker;
  26205. var request = new XMLHttpRequest();
  26206. request.open('GET', url, false);
  26207. if (!nonBinaryRequest) {
  26208. try {
  26209. request.responseType = 'arraybuffer';
  26210. nonBinaryRequest = request.responseType !== 'arraybuffer';
  26211. } catch (e) {
  26212. nonBinaryRequest = true;
  26213. }
  26214. }
  26215. if (nonBinaryRequest && request.overrideMimeType) {
  26216. request.overrideMimeType('text/plain; charset=x-user-defined');
  26217. }
  26218. request.send(null);
  26219. if (nonBinaryRequest ? !request.responseText : !request.response) {
  26220. error('Unable to get binary cMap at: ' + url);
  26221. }
  26222. if (nonBinaryRequest) {
  26223. var data = Array.prototype.map.call(request.responseText, function (ch) {
  26224. return ch.charCodeAt(0) & 255;
  26225. });
  26226. return new Uint8Array(data);
  26227. }
  26228. return new Uint8Array(request.response);
  26229. }
  26230. function hexToInt(a, size) {
  26231. var n = 0;
  26232. for (var i = 0; i <= size; i++) {
  26233. n = (n << 8) | a[i];
  26234. }
  26235. return n >>> 0;
  26236. }
  26237. function hexToStr(a, size) {
  26238. // This code is hot. Special-case some common values to avoid creating an
  26239. // object with subarray().
  26240. if (size === 1) {
  26241. return String.fromCharCode(a[0], a[1]);
  26242. }
  26243. if (size === 3) {
  26244. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  26245. }
  26246. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  26247. }
  26248. function addHex(a, b, size) {
  26249. var c = 0;
  26250. for (var i = size; i >= 0; i--) {
  26251. c += a[i] + b[i];
  26252. a[i] = c & 255;
  26253. c >>= 8;
  26254. }
  26255. }
  26256. function incHex(a, size) {
  26257. var c = 1;
  26258. for (var i = size; i >= 0 && c > 0; i--) {
  26259. c += a[i];
  26260. a[i] = c & 255;
  26261. c >>= 8;
  26262. }
  26263. }
  26264. var MAX_NUM_SIZE = 16;
  26265. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  26266. function BinaryCMapStream(data) {
  26267. this.buffer = data;
  26268. this.pos = 0;
  26269. this.end = data.length;
  26270. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  26271. }
  26272. BinaryCMapStream.prototype = {
  26273. readByte: function () {
  26274. if (this.pos >= this.end) {
  26275. return -1;
  26276. }
  26277. return this.buffer[this.pos++];
  26278. },
  26279. readNumber: function () {
  26280. var n = 0;
  26281. var last;
  26282. do {
  26283. var b = this.readByte();
  26284. if (b < 0) {
  26285. error('unexpected EOF in bcmap');
  26286. }
  26287. last = !(b & 0x80);
  26288. n = (n << 7) | (b & 0x7F);
  26289. } while (!last);
  26290. return n;
  26291. },
  26292. readSigned: function () {
  26293. var n = this.readNumber();
  26294. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  26295. },
  26296. readHex: function (num, size) {
  26297. num.set(this.buffer.subarray(this.pos,
  26298. this.pos + size + 1));
  26299. this.pos += size + 1;
  26300. },
  26301. readHexNumber: function (num, size) {
  26302. var last;
  26303. var stack = this.tmpBuf, sp = 0;
  26304. do {
  26305. var b = this.readByte();
  26306. if (b < 0) {
  26307. error('unexpected EOF in bcmap');
  26308. }
  26309. last = !(b & 0x80);
  26310. stack[sp++] = b & 0x7F;
  26311. } while (!last);
  26312. var i = size, buffer = 0, bufferSize = 0;
  26313. while (i >= 0) {
  26314. while (bufferSize < 8 && stack.length > 0) {
  26315. buffer = (stack[--sp] << bufferSize) | buffer;
  26316. bufferSize += 7;
  26317. }
  26318. num[i] = buffer & 255;
  26319. i--;
  26320. buffer >>= 8;
  26321. bufferSize -= 8;
  26322. }
  26323. },
  26324. readHexSigned: function (num, size) {
  26325. this.readHexNumber(num, size);
  26326. var sign = num[size] & 1 ? 255 : 0;
  26327. var c = 0;
  26328. for (var i = 0; i <= size; i++) {
  26329. c = ((c & 1) << 8) | num[i];
  26330. num[i] = (c >> 1) ^ sign;
  26331. }
  26332. },
  26333. readString: function () {
  26334. var len = this.readNumber();
  26335. var s = '';
  26336. for (var i = 0; i < len; i++) {
  26337. s += String.fromCharCode(this.readNumber());
  26338. }
  26339. return s;
  26340. }
  26341. };
  26342. function processBinaryCMap(url, cMap, extend) {
  26343. var data = fetchBinaryData(url);
  26344. var stream = new BinaryCMapStream(data);
  26345. var header = stream.readByte();
  26346. cMap.vertical = !!(header & 1);
  26347. var useCMap = null;
  26348. var start = new Uint8Array(MAX_NUM_SIZE);
  26349. var end = new Uint8Array(MAX_NUM_SIZE);
  26350. var char = new Uint8Array(MAX_NUM_SIZE);
  26351. var charCode = new Uint8Array(MAX_NUM_SIZE);
  26352. var tmp = new Uint8Array(MAX_NUM_SIZE);
  26353. var code;
  26354. var b;
  26355. while ((b = stream.readByte()) >= 0) {
  26356. var type = b >> 5;
  26357. if (type === 7) { // metadata, e.g. comment or usecmap
  26358. switch (b & 0x1F) {
  26359. case 0:
  26360. stream.readString(); // skipping comment
  26361. break;
  26362. case 1:
  26363. useCMap = stream.readString();
  26364. break;
  26365. }
  26366. continue;
  26367. }
  26368. var sequence = !!(b & 0x10);
  26369. var dataSize = b & 15;
  26370. assert(dataSize + 1 <= MAX_NUM_SIZE);
  26371. var ucs2DataSize = 1;
  26372. var subitemsCount = stream.readNumber();
  26373. var i;
  26374. switch (type) {
  26375. case 0: // codespacerange
  26376. stream.readHex(start, dataSize);
  26377. stream.readHexNumber(end, dataSize);
  26378. addHex(end, start, dataSize);
  26379. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26380. hexToInt(end, dataSize));
  26381. for (i = 1; i < subitemsCount; i++) {
  26382. incHex(end, dataSize);
  26383. stream.readHexNumber(start, dataSize);
  26384. addHex(start, end, dataSize);
  26385. stream.readHexNumber(end, dataSize);
  26386. addHex(end, start, dataSize);
  26387. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26388. hexToInt(end, dataSize));
  26389. }
  26390. break;
  26391. case 1: // notdefrange
  26392. stream.readHex(start, dataSize);
  26393. stream.readHexNumber(end, dataSize);
  26394. addHex(end, start, dataSize);
  26395. code = stream.readNumber();
  26396. // undefined range, skipping
  26397. for (i = 1; i < subitemsCount; i++) {
  26398. incHex(end, dataSize);
  26399. stream.readHexNumber(start, dataSize);
  26400. addHex(start, end, dataSize);
  26401. stream.readHexNumber(end, dataSize);
  26402. addHex(end, start, dataSize);
  26403. code = stream.readNumber();
  26404. // nop
  26405. }
  26406. break;
  26407. case 2: // cidchar
  26408. stream.readHex(char, dataSize);
  26409. code = stream.readNumber();
  26410. cMap.mapOne(hexToInt(char, dataSize), code);
  26411. for (i = 1; i < subitemsCount; i++) {
  26412. incHex(char, dataSize);
  26413. if (!sequence) {
  26414. stream.readHexNumber(tmp, dataSize);
  26415. addHex(char, tmp, dataSize);
  26416. }
  26417. code = stream.readSigned() + (code + 1);
  26418. cMap.mapOne(hexToInt(char, dataSize), code);
  26419. }
  26420. break;
  26421. case 3: // cidrange
  26422. stream.readHex(start, dataSize);
  26423. stream.readHexNumber(end, dataSize);
  26424. addHex(end, start, dataSize);
  26425. code = stream.readNumber();
  26426. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  26427. code);
  26428. for (i = 1; i < subitemsCount; i++) {
  26429. incHex(end, dataSize);
  26430. if (!sequence) {
  26431. stream.readHexNumber(start, dataSize);
  26432. addHex(start, end, dataSize);
  26433. } else {
  26434. start.set(end);
  26435. }
  26436. stream.readHexNumber(end, dataSize);
  26437. addHex(end, start, dataSize);
  26438. code = stream.readNumber();
  26439. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  26440. code);
  26441. }
  26442. break;
  26443. case 4: // bfchar
  26444. stream.readHex(char, ucs2DataSize);
  26445. stream.readHex(charCode, dataSize);
  26446. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26447. hexToStr(charCode, dataSize));
  26448. for (i = 1; i < subitemsCount; i++) {
  26449. incHex(char, ucs2DataSize);
  26450. if (!sequence) {
  26451. stream.readHexNumber(tmp, ucs2DataSize);
  26452. addHex(char, tmp, ucs2DataSize);
  26453. }
  26454. incHex(charCode, dataSize);
  26455. stream.readHexSigned(tmp, dataSize);
  26456. addHex(charCode, tmp, dataSize);
  26457. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26458. hexToStr(charCode, dataSize));
  26459. }
  26460. break;
  26461. case 5: // bfrange
  26462. stream.readHex(start, ucs2DataSize);
  26463. stream.readHexNumber(end, ucs2DataSize);
  26464. addHex(end, start, ucs2DataSize);
  26465. stream.readHex(charCode, dataSize);
  26466. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26467. hexToInt(end, ucs2DataSize),
  26468. hexToStr(charCode, dataSize));
  26469. for (i = 1; i < subitemsCount; i++) {
  26470. incHex(end, ucs2DataSize);
  26471. if (!sequence) {
  26472. stream.readHexNumber(start, ucs2DataSize);
  26473. addHex(start, end, ucs2DataSize);
  26474. } else {
  26475. start.set(end);
  26476. }
  26477. stream.readHexNumber(end, ucs2DataSize);
  26478. addHex(end, start, ucs2DataSize);
  26479. stream.readHex(charCode, dataSize);
  26480. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26481. hexToInt(end, ucs2DataSize),
  26482. hexToStr(charCode, dataSize));
  26483. }
  26484. break;
  26485. default:
  26486. error('Unknown type: ' + type);
  26487. break;
  26488. }
  26489. }
  26490. if (useCMap) {
  26491. extend(useCMap);
  26492. }
  26493. return cMap;
  26494. }
  26495. function BinaryCMapReader() {}
  26496. BinaryCMapReader.prototype = {
  26497. read: processBinaryCMap
  26498. };
  26499. return BinaryCMapReader;
  26500. })();
  26501. var CMapFactory = (function CMapFactoryClosure() {
  26502. function strToInt(str) {
  26503. var a = 0;
  26504. for (var i = 0; i < str.length; i++) {
  26505. a = (a << 8) | str.charCodeAt(i);
  26506. }
  26507. return a >>> 0;
  26508. }
  26509. function expectString(obj) {
  26510. if (!isString(obj)) {
  26511. error('Malformed CMap: expected string.');
  26512. }
  26513. }
  26514. function expectInt(obj) {
  26515. if (!isInt(obj)) {
  26516. error('Malformed CMap: expected int.');
  26517. }
  26518. }
  26519. function parseBfChar(cMap, lexer) {
  26520. while (true) {
  26521. var obj = lexer.getObj();
  26522. if (isEOF(obj)) {
  26523. break;
  26524. }
  26525. if (isCmd(obj, 'endbfchar')) {
  26526. return;
  26527. }
  26528. expectString(obj);
  26529. var src = strToInt(obj);
  26530. obj = lexer.getObj();
  26531. // TODO are /dstName used?
  26532. expectString(obj);
  26533. var dst = obj;
  26534. cMap.mapOne(src, dst);
  26535. }
  26536. }
  26537. function parseBfRange(cMap, lexer) {
  26538. while (true) {
  26539. var obj = lexer.getObj();
  26540. if (isEOF(obj)) {
  26541. break;
  26542. }
  26543. if (isCmd(obj, 'endbfrange')) {
  26544. return;
  26545. }
  26546. expectString(obj);
  26547. var low = strToInt(obj);
  26548. obj = lexer.getObj();
  26549. expectString(obj);
  26550. var high = strToInt(obj);
  26551. obj = lexer.getObj();
  26552. if (isInt(obj) || isString(obj)) {
  26553. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  26554. cMap.mapBfRange(low, high, dstLow);
  26555. } else if (isCmd(obj, '[')) {
  26556. obj = lexer.getObj();
  26557. var array = [];
  26558. while (!isCmd(obj, ']') && !isEOF(obj)) {
  26559. array.push(obj);
  26560. obj = lexer.getObj();
  26561. }
  26562. cMap.mapBfRangeToArray(low, high, array);
  26563. } else {
  26564. break;
  26565. }
  26566. }
  26567. error('Invalid bf range.');
  26568. }
  26569. function parseCidChar(cMap, lexer) {
  26570. while (true) {
  26571. var obj = lexer.getObj();
  26572. if (isEOF(obj)) {
  26573. break;
  26574. }
  26575. if (isCmd(obj, 'endcidchar')) {
  26576. return;
  26577. }
  26578. expectString(obj);
  26579. var src = strToInt(obj);
  26580. obj = lexer.getObj();
  26581. expectInt(obj);
  26582. var dst = obj;
  26583. cMap.mapOne(src, dst);
  26584. }
  26585. }
  26586. function parseCidRange(cMap, lexer) {
  26587. while (true) {
  26588. var obj = lexer.getObj();
  26589. if (isEOF(obj)) {
  26590. break;
  26591. }
  26592. if (isCmd(obj, 'endcidrange')) {
  26593. return;
  26594. }
  26595. expectString(obj);
  26596. var low = strToInt(obj);
  26597. obj = lexer.getObj();
  26598. expectString(obj);
  26599. var high = strToInt(obj);
  26600. obj = lexer.getObj();
  26601. expectInt(obj);
  26602. var dstLow = obj;
  26603. cMap.mapCidRange(low, high, dstLow);
  26604. }
  26605. }
  26606. function parseCodespaceRange(cMap, lexer) {
  26607. while (true) {
  26608. var obj = lexer.getObj();
  26609. if (isEOF(obj)) {
  26610. break;
  26611. }
  26612. if (isCmd(obj, 'endcodespacerange')) {
  26613. return;
  26614. }
  26615. if (!isString(obj)) {
  26616. break;
  26617. }
  26618. var low = strToInt(obj);
  26619. obj = lexer.getObj();
  26620. if (!isString(obj)) {
  26621. break;
  26622. }
  26623. var high = strToInt(obj);
  26624. cMap.addCodespaceRange(obj.length, low, high);
  26625. }
  26626. error('Invalid codespace range.');
  26627. }
  26628. function parseWMode(cMap, lexer) {
  26629. var obj = lexer.getObj();
  26630. if (isInt(obj)) {
  26631. cMap.vertical = !!obj;
  26632. }
  26633. }
  26634. function parseCMapName(cMap, lexer) {
  26635. var obj = lexer.getObj();
  26636. if (isName(obj) && isString(obj.name)) {
  26637. cMap.name = obj.name;
  26638. }
  26639. }
  26640. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  26641. var previous;
  26642. var embededUseCMap;
  26643. objLoop: while (true) {
  26644. var obj = lexer.getObj();
  26645. if (isEOF(obj)) {
  26646. break;
  26647. } else if (isName(obj)) {
  26648. if (obj.name === 'WMode') {
  26649. parseWMode(cMap, lexer);
  26650. } else if (obj.name === 'CMapName') {
  26651. parseCMapName(cMap, lexer);
  26652. }
  26653. previous = obj;
  26654. } else if (isCmd(obj)) {
  26655. switch (obj.cmd) {
  26656. case 'endcmap':
  26657. break objLoop;
  26658. case 'usecmap':
  26659. if (isName(previous)) {
  26660. embededUseCMap = previous.name;
  26661. }
  26662. break;
  26663. case 'begincodespacerange':
  26664. parseCodespaceRange(cMap, lexer);
  26665. break;
  26666. case 'beginbfchar':
  26667. parseBfChar(cMap, lexer);
  26668. break;
  26669. case 'begincidchar':
  26670. parseCidChar(cMap, lexer);
  26671. break;
  26672. case 'beginbfrange':
  26673. parseBfRange(cMap, lexer);
  26674. break;
  26675. case 'begincidrange':
  26676. parseCidRange(cMap, lexer);
  26677. break;
  26678. }
  26679. }
  26680. }
  26681. if (!useCMap && embededUseCMap) {
  26682. // Load the usecmap definition from the file only if there wasn't one
  26683. // specified.
  26684. useCMap = embededUseCMap;
  26685. }
  26686. if (useCMap) {
  26687. extendCMap(cMap, builtInCMapParams, useCMap);
  26688. }
  26689. }
  26690. function extendCMap(cMap, builtInCMapParams, useCMap) {
  26691. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  26692. // If there aren't any code space ranges defined clone all the parent ones
  26693. // into this cMap.
  26694. if (cMap.numCodespaceRanges === 0) {
  26695. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  26696. for (var i = 0; i < useCodespaceRanges.length; i++) {
  26697. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  26698. }
  26699. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  26700. }
  26701. // Merge the map into the current one, making sure not to override
  26702. // any previously defined entries.
  26703. cMap.useCMap.forEach(function(key, value) {
  26704. if (!cMap.contains(key)) {
  26705. cMap.mapOne(key, cMap.useCMap.lookup(key));
  26706. }
  26707. });
  26708. }
  26709. function parseBinaryCMap(name, builtInCMapParams) {
  26710. var url = builtInCMapParams.url + name + '.bcmap';
  26711. var cMap = new CMap(true);
  26712. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  26713. extendCMap(cMap, builtInCMapParams, useCMap);
  26714. });
  26715. return cMap;
  26716. }
  26717. function createBuiltInCMap(name, builtInCMapParams) {
  26718. if (name === 'Identity-H') {
  26719. return new IdentityCMap(false, 2);
  26720. } else if (name === 'Identity-V') {
  26721. return new IdentityCMap(true, 2);
  26722. }
  26723. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  26724. error('Unknown cMap name: ' + name);
  26725. }
  26726. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  26727. if (builtInCMapParams.packed) {
  26728. return parseBinaryCMap(name, builtInCMapParams);
  26729. }
  26730. var request = new XMLHttpRequest();
  26731. var url = builtInCMapParams.url + name;
  26732. request.open('GET', url, false);
  26733. request.send(null);
  26734. if (!request.responseText) {
  26735. error('Unable to get cMap at: ' + url);
  26736. }
  26737. var cMap = new CMap(true);
  26738. var lexer = new Lexer(new StringStream(request.responseText));
  26739. parseCMap(cMap, lexer, builtInCMapParams, null);
  26740. return cMap;
  26741. }
  26742. return {
  26743. create: function (encoding, builtInCMapParams, useCMap) {
  26744. if (isName(encoding)) {
  26745. return createBuiltInCMap(encoding.name, builtInCMapParams);
  26746. } else if (isStream(encoding)) {
  26747. var cMap = new CMap();
  26748. var lexer = new Lexer(encoding);
  26749. try {
  26750. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  26751. } catch (e) {
  26752. warn('Invalid CMap data. ' + e);
  26753. }
  26754. if (cMap.isIdentityCMap) {
  26755. return createBuiltInCMap(cMap.name, builtInCMapParams);
  26756. }
  26757. return cMap;
  26758. }
  26759. error('Encoding required.');
  26760. }
  26761. };
  26762. })();
  26763. exports.CMap = CMap;
  26764. exports.CMapFactory = CMapFactory;
  26765. exports.IdentityCMap = IdentityCMap;
  26766. }));
  26767. (function (root, factory) {
  26768. {
  26769. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  26770. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  26771. root.pdfjsCoreChunkedStream);
  26772. }
  26773. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  26774. coreChunkedStream) {
  26775. var InvalidPDFException = sharedUtil.InvalidPDFException;
  26776. var MissingDataException = sharedUtil.MissingDataException;
  26777. var XRefParseException = sharedUtil.XRefParseException;
  26778. var assert = sharedUtil.assert;
  26779. var bytesToString = sharedUtil.bytesToString;
  26780. var createPromiseCapability = sharedUtil.createPromiseCapability;
  26781. var error = sharedUtil.error;
  26782. var info = sharedUtil.info;
  26783. var isArray = sharedUtil.isArray;
  26784. var isInt = sharedUtil.isInt;
  26785. var isString = sharedUtil.isString;
  26786. var shadow = sharedUtil.shadow;
  26787. var stringToPDFString = sharedUtil.stringToPDFString;
  26788. var stringToUTF8String = sharedUtil.stringToUTF8String;
  26789. var warn = sharedUtil.warn;
  26790. var Ref = corePrimitives.Ref;
  26791. var RefSet = corePrimitives.RefSet;
  26792. var RefSetCache = corePrimitives.RefSetCache;
  26793. var isName = corePrimitives.isName;
  26794. var isCmd = corePrimitives.isCmd;
  26795. var isDict = corePrimitives.isDict;
  26796. var isRef = corePrimitives.isRef;
  26797. var isStream = corePrimitives.isStream;
  26798. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  26799. var Lexer = coreParser.Lexer;
  26800. var Parser = coreParser.Parser;
  26801. var ChunkedStream = coreChunkedStream.ChunkedStream;
  26802. var Catalog = (function CatalogClosure() {
  26803. function Catalog(pdfManager, xref, pageFactory) {
  26804. this.pdfManager = pdfManager;
  26805. this.xref = xref;
  26806. this.catDict = xref.getCatalogObj();
  26807. this.fontCache = new RefSetCache();
  26808. assert(isDict(this.catDict),
  26809. 'catalog object is not a dictionary');
  26810. // TODO refactor to move getPage() to the PDFDocument.
  26811. this.pageFactory = pageFactory;
  26812. this.pagePromises = [];
  26813. }
  26814. Catalog.prototype = {
  26815. get metadata() {
  26816. var streamRef = this.catDict.getRaw('Metadata');
  26817. if (!isRef(streamRef)) {
  26818. return shadow(this, 'metadata', null);
  26819. }
  26820. var encryptMetadata = (!this.xref.encrypt ? false :
  26821. this.xref.encrypt.encryptMetadata);
  26822. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  26823. var metadata;
  26824. if (stream && isDict(stream.dict)) {
  26825. var type = stream.dict.get('Type');
  26826. var subtype = stream.dict.get('Subtype');
  26827. if (isName(type) && isName(subtype) &&
  26828. type.name === 'Metadata' && subtype.name === 'XML') {
  26829. // XXX: This should examine the charset the XML document defines,
  26830. // however since there are currently no real means to decode
  26831. // arbitrary charsets, let's just hope that the author of the PDF
  26832. // was reasonable enough to stick with the XML default charset,
  26833. // which is UTF-8.
  26834. try {
  26835. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  26836. } catch (e) {
  26837. info('Skipping invalid metadata.');
  26838. }
  26839. }
  26840. }
  26841. return shadow(this, 'metadata', metadata);
  26842. },
  26843. get toplevelPagesDict() {
  26844. var pagesObj = this.catDict.get('Pages');
  26845. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  26846. // shadow the prototype getter
  26847. return shadow(this, 'toplevelPagesDict', pagesObj);
  26848. },
  26849. get documentOutline() {
  26850. var obj = null;
  26851. try {
  26852. obj = this.readDocumentOutline();
  26853. } catch (ex) {
  26854. if (ex instanceof MissingDataException) {
  26855. throw ex;
  26856. }
  26857. warn('Unable to read document outline');
  26858. }
  26859. return shadow(this, 'documentOutline', obj);
  26860. },
  26861. readDocumentOutline: function Catalog_readDocumentOutline() {
  26862. var xref = this.xref;
  26863. var obj = this.catDict.get('Outlines');
  26864. var root = { items: [] };
  26865. if (isDict(obj)) {
  26866. obj = obj.getRaw('First');
  26867. var processed = new RefSet();
  26868. if (isRef(obj)) {
  26869. var queue = [{obj: obj, parent: root}];
  26870. // to avoid recursion keeping track of the items
  26871. // in the processed dictionary
  26872. processed.put(obj);
  26873. while (queue.length > 0) {
  26874. var i = queue.shift();
  26875. var outlineDict = xref.fetchIfRef(i.obj);
  26876. if (outlineDict === null) {
  26877. continue;
  26878. }
  26879. if (!outlineDict.has('Title')) {
  26880. error('Invalid outline item');
  26881. }
  26882. var dest = outlineDict.get('A');
  26883. if (dest) {
  26884. dest = dest.get('D');
  26885. } else if (outlineDict.has('Dest')) {
  26886. dest = outlineDict.getRaw('Dest');
  26887. if (isName(dest)) {
  26888. dest = dest.name;
  26889. }
  26890. }
  26891. var title = outlineDict.get('Title');
  26892. var outlineItem = {
  26893. dest: dest,
  26894. title: stringToPDFString(title),
  26895. color: outlineDict.get('C') || [0, 0, 0],
  26896. count: outlineDict.get('Count'),
  26897. bold: !!(outlineDict.get('F') & 2),
  26898. italic: !!(outlineDict.get('F') & 1),
  26899. items: []
  26900. };
  26901. i.parent.items.push(outlineItem);
  26902. obj = outlineDict.getRaw('First');
  26903. if (isRef(obj) && !processed.has(obj)) {
  26904. queue.push({obj: obj, parent: outlineItem});
  26905. processed.put(obj);
  26906. }
  26907. obj = outlineDict.getRaw('Next');
  26908. if (isRef(obj) && !processed.has(obj)) {
  26909. queue.push({obj: obj, parent: i.parent});
  26910. processed.put(obj);
  26911. }
  26912. }
  26913. }
  26914. }
  26915. return (root.items.length > 0 ? root.items : null);
  26916. },
  26917. get numPages() {
  26918. var obj = this.toplevelPagesDict.get('Count');
  26919. assert(
  26920. isInt(obj),
  26921. 'page count in top level pages object is not an integer'
  26922. );
  26923. // shadow the prototype getter
  26924. return shadow(this, 'num', obj);
  26925. },
  26926. get destinations() {
  26927. function fetchDestination(dest) {
  26928. return isDict(dest) ? dest.get('D') : dest;
  26929. }
  26930. var xref = this.xref;
  26931. var dests = {}, nameTreeRef, nameDictionaryRef;
  26932. var obj = this.catDict.get('Names');
  26933. if (obj && obj.has('Dests')) {
  26934. nameTreeRef = obj.getRaw('Dests');
  26935. } else if (this.catDict.has('Dests')) {
  26936. nameDictionaryRef = this.catDict.get('Dests');
  26937. }
  26938. if (nameDictionaryRef) {
  26939. // reading simple destination dictionary
  26940. obj = nameDictionaryRef;
  26941. obj.forEach(function catalogForEach(key, value) {
  26942. if (!value) {
  26943. return;
  26944. }
  26945. dests[key] = fetchDestination(value);
  26946. });
  26947. }
  26948. if (nameTreeRef) {
  26949. var nameTree = new NameTree(nameTreeRef, xref);
  26950. var names = nameTree.getAll();
  26951. for (var name in names) {
  26952. if (!names.hasOwnProperty(name)) {
  26953. continue;
  26954. }
  26955. dests[name] = fetchDestination(names[name]);
  26956. }
  26957. }
  26958. return shadow(this, 'destinations', dests);
  26959. },
  26960. getDestination: function Catalog_getDestination(destinationId) {
  26961. function fetchDestination(dest) {
  26962. return isDict(dest) ? dest.get('D') : dest;
  26963. }
  26964. var xref = this.xref;
  26965. var dest = null, nameTreeRef, nameDictionaryRef;
  26966. var obj = this.catDict.get('Names');
  26967. if (obj && obj.has('Dests')) {
  26968. nameTreeRef = obj.getRaw('Dests');
  26969. } else if (this.catDict.has('Dests')) {
  26970. nameDictionaryRef = this.catDict.get('Dests');
  26971. }
  26972. if (nameDictionaryRef) { // Simple destination dictionary.
  26973. var value = nameDictionaryRef.get(destinationId);
  26974. if (value) {
  26975. dest = fetchDestination(value);
  26976. }
  26977. }
  26978. if (nameTreeRef) {
  26979. var nameTree = new NameTree(nameTreeRef, xref);
  26980. dest = fetchDestination(nameTree.get(destinationId));
  26981. }
  26982. return dest;
  26983. },
  26984. get attachments() {
  26985. var xref = this.xref;
  26986. var attachments = null, nameTreeRef;
  26987. var obj = this.catDict.get('Names');
  26988. if (obj) {
  26989. nameTreeRef = obj.getRaw('EmbeddedFiles');
  26990. }
  26991. if (nameTreeRef) {
  26992. var nameTree = new NameTree(nameTreeRef, xref);
  26993. var names = nameTree.getAll();
  26994. for (var name in names) {
  26995. if (!names.hasOwnProperty(name)) {
  26996. continue;
  26997. }
  26998. var fs = new FileSpec(names[name], xref);
  26999. if (!attachments) {
  27000. attachments = {};
  27001. }
  27002. attachments[stringToPDFString(name)] = fs.serializable;
  27003. }
  27004. }
  27005. return shadow(this, 'attachments', attachments);
  27006. },
  27007. get javaScript() {
  27008. var xref = this.xref;
  27009. var obj = this.catDict.get('Names');
  27010. var javaScript = [];
  27011. function appendIfJavaScriptDict(jsDict) {
  27012. var type = jsDict.get('S');
  27013. if (!isName(type) || type.name !== 'JavaScript') {
  27014. return;
  27015. }
  27016. var js = jsDict.get('JS');
  27017. if (isStream(js)) {
  27018. js = bytesToString(js.getBytes());
  27019. } else if (!isString(js)) {
  27020. return;
  27021. }
  27022. javaScript.push(stringToPDFString(js));
  27023. }
  27024. if (obj && obj.has('JavaScript')) {
  27025. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  27026. var names = nameTree.getAll();
  27027. for (var name in names) {
  27028. if (!names.hasOwnProperty(name)) {
  27029. continue;
  27030. }
  27031. // We don't really use the JavaScript right now. This code is
  27032. // defensive so we don't cause errors on document load.
  27033. var jsDict = names[name];
  27034. if (isDict(jsDict)) {
  27035. appendIfJavaScriptDict(jsDict);
  27036. }
  27037. }
  27038. }
  27039. // Append OpenAction actions to javaScript array
  27040. var openactionDict = this.catDict.get('OpenAction');
  27041. if (isDict(openactionDict, 'Action')) {
  27042. var actionType = openactionDict.get('S');
  27043. if (isName(actionType) && actionType.name === 'Named') {
  27044. // The named Print action is not a part of the PDF 1.7 specification,
  27045. // but is supported by many PDF readers/writers (including Adobe's).
  27046. var action = openactionDict.get('N');
  27047. if (isName(action) && action.name === 'Print') {
  27048. javaScript.push('print({});');
  27049. }
  27050. } else {
  27051. appendIfJavaScriptDict(openactionDict);
  27052. }
  27053. }
  27054. return shadow(this, 'javaScript', javaScript);
  27055. },
  27056. cleanup: function Catalog_cleanup() {
  27057. var promises = [];
  27058. this.fontCache.forEach(function (promise) {
  27059. promises.push(promise);
  27060. });
  27061. return Promise.all(promises).then(function (translatedFonts) {
  27062. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  27063. var font = translatedFonts[i].dict;
  27064. delete font.translated;
  27065. }
  27066. this.fontCache.clear();
  27067. }.bind(this));
  27068. },
  27069. getPage: function Catalog_getPage(pageIndex) {
  27070. if (!(pageIndex in this.pagePromises)) {
  27071. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  27072. function (a) {
  27073. var dict = a[0];
  27074. var ref = a[1];
  27075. return this.pageFactory.createPage(pageIndex, dict, ref,
  27076. this.fontCache);
  27077. }.bind(this)
  27078. );
  27079. }
  27080. return this.pagePromises[pageIndex];
  27081. },
  27082. getPageDict: function Catalog_getPageDict(pageIndex) {
  27083. var capability = createPromiseCapability();
  27084. var nodesToVisit = [this.catDict.getRaw('Pages')];
  27085. var currentPageIndex = 0;
  27086. var xref = this.xref;
  27087. var checkAllKids = false;
  27088. function next() {
  27089. while (nodesToVisit.length) {
  27090. var currentNode = nodesToVisit.pop();
  27091. if (isRef(currentNode)) {
  27092. xref.fetchAsync(currentNode).then(function (obj) {
  27093. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  27094. if (pageIndex === currentPageIndex) {
  27095. capability.resolve([obj, currentNode]);
  27096. } else {
  27097. currentPageIndex++;
  27098. next();
  27099. }
  27100. return;
  27101. }
  27102. nodesToVisit.push(obj);
  27103. next();
  27104. }, capability.reject);
  27105. return;
  27106. }
  27107. // Must be a child page dictionary.
  27108. assert(
  27109. isDict(currentNode),
  27110. 'page dictionary kid reference points to wrong type of object'
  27111. );
  27112. var count = currentNode.get('Count');
  27113. // If the current node doesn't have any children, avoid getting stuck
  27114. // in an empty node further down in the tree (see issue5644.pdf).
  27115. if (count === 0) {
  27116. checkAllKids = true;
  27117. }
  27118. // Skip nodes where the page can't be.
  27119. if (currentPageIndex + count <= pageIndex) {
  27120. currentPageIndex += count;
  27121. continue;
  27122. }
  27123. var kids = currentNode.get('Kids');
  27124. assert(isArray(kids), 'page dictionary kids object is not an array');
  27125. if (!checkAllKids && count === kids.length) {
  27126. // Nodes that don't have the page have been skipped and this is the
  27127. // bottom of the tree which means the page requested must be a
  27128. // descendant of this pages node. Ideally we would just resolve the
  27129. // promise with the page ref here, but there is the case where more
  27130. // pages nodes could link to single a page (see issue 3666 pdf). To
  27131. // handle this push it back on the queue so if it is a pages node it
  27132. // will be descended into.
  27133. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  27134. currentPageIndex = pageIndex;
  27135. continue;
  27136. } else {
  27137. for (var last = kids.length - 1; last >= 0; last--) {
  27138. nodesToVisit.push(kids[last]);
  27139. }
  27140. }
  27141. }
  27142. capability.reject('Page index ' + pageIndex + ' not found.');
  27143. }
  27144. next();
  27145. return capability.promise;
  27146. },
  27147. getPageIndex: function Catalog_getPageIndex(ref) {
  27148. // The page tree nodes have the count of all the leaves below them. To get
  27149. // how many pages are before we just have to walk up the tree and keep
  27150. // adding the count of siblings to the left of the node.
  27151. var xref = this.xref;
  27152. function pagesBeforeRef(kidRef) {
  27153. var total = 0;
  27154. var parentRef;
  27155. return xref.fetchAsync(kidRef).then(function (node) {
  27156. if (!node) {
  27157. return null;
  27158. }
  27159. parentRef = node.getRaw('Parent');
  27160. return node.getAsync('Parent');
  27161. }).then(function (parent) {
  27162. if (!parent) {
  27163. return null;
  27164. }
  27165. return parent.getAsync('Kids');
  27166. }).then(function (kids) {
  27167. if (!kids) {
  27168. return null;
  27169. }
  27170. var kidPromises = [];
  27171. var found = false;
  27172. for (var i = 0; i < kids.length; i++) {
  27173. var kid = kids[i];
  27174. assert(isRef(kid), 'kids must be a ref');
  27175. if (kid.num === kidRef.num) {
  27176. found = true;
  27177. break;
  27178. }
  27179. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  27180. if (kid.has('Count')) {
  27181. var count = kid.get('Count');
  27182. total += count;
  27183. } else { // page leaf node
  27184. total++;
  27185. }
  27186. }));
  27187. }
  27188. if (!found) {
  27189. error('kid ref not found in parents kids');
  27190. }
  27191. return Promise.all(kidPromises).then(function () {
  27192. return [total, parentRef];
  27193. });
  27194. });
  27195. }
  27196. var total = 0;
  27197. function next(ref) {
  27198. return pagesBeforeRef(ref).then(function (args) {
  27199. if (!args) {
  27200. return total;
  27201. }
  27202. var count = args[0];
  27203. var parentRef = args[1];
  27204. total += count;
  27205. return next(parentRef);
  27206. });
  27207. }
  27208. return next(ref);
  27209. }
  27210. };
  27211. return Catalog;
  27212. })();
  27213. var XRef = (function XRefClosure() {
  27214. function XRef(stream, password) {
  27215. this.stream = stream;
  27216. this.entries = [];
  27217. this.xrefstms = {};
  27218. // prepare the XRef cache
  27219. this.cache = [];
  27220. this.password = password;
  27221. this.stats = {
  27222. streamTypes: [],
  27223. fontTypes: []
  27224. };
  27225. }
  27226. XRef.prototype = {
  27227. setStartXRef: function XRef_setStartXRef(startXRef) {
  27228. // Store the starting positions of xref tables as we process them
  27229. // so we can recover from missing data errors
  27230. this.startXRefQueue = [startXRef];
  27231. },
  27232. parse: function XRef_parse(recoveryMode) {
  27233. var trailerDict;
  27234. if (!recoveryMode) {
  27235. trailerDict = this.readXRef();
  27236. } else {
  27237. warn('Indexing all PDF objects');
  27238. trailerDict = this.indexObjects();
  27239. }
  27240. trailerDict.assignXref(this);
  27241. this.trailer = trailerDict;
  27242. var encrypt = trailerDict.get('Encrypt');
  27243. if (encrypt) {
  27244. var ids = trailerDict.get('ID');
  27245. var fileId = (ids && ids.length) ? ids[0] : '';
  27246. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  27247. this.password);
  27248. }
  27249. // get the root dictionary (catalog) object
  27250. if (!(this.root = trailerDict.get('Root'))) {
  27251. error('Invalid root reference');
  27252. }
  27253. },
  27254. processXRefTable: function XRef_processXRefTable(parser) {
  27255. if (!('tableState' in this)) {
  27256. // Stores state of the table as we process it so we can resume
  27257. // from middle of table in case of missing data error
  27258. this.tableState = {
  27259. entryNum: 0,
  27260. streamPos: parser.lexer.stream.pos,
  27261. parserBuf1: parser.buf1,
  27262. parserBuf2: parser.buf2
  27263. };
  27264. }
  27265. var obj = this.readXRefTable(parser);
  27266. // Sanity check
  27267. if (!isCmd(obj, 'trailer')) {
  27268. error('Invalid XRef table: could not find trailer dictionary');
  27269. }
  27270. // Read trailer dictionary, e.g.
  27271. // trailer
  27272. // << /Size 22
  27273. // /Root 20R
  27274. // /Info 10R
  27275. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  27276. // >>
  27277. // The parser goes through the entire stream << ... >> and provides
  27278. // a getter interface for the key-value table
  27279. var dict = parser.getObj();
  27280. // The pdflib PDF generator can generate a nested trailer dictionary
  27281. if (!isDict(dict) && dict.dict) {
  27282. dict = dict.dict;
  27283. }
  27284. if (!isDict(dict)) {
  27285. error('Invalid XRef table: could not parse trailer dictionary');
  27286. }
  27287. delete this.tableState;
  27288. return dict;
  27289. },
  27290. readXRefTable: function XRef_readXRefTable(parser) {
  27291. // Example of cross-reference table:
  27292. // xref
  27293. // 0 1 <-- subsection header (first obj #, obj count)
  27294. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  27295. // 23 2 <-- subsection header ... and so on ...
  27296. // 0000025518 00002 n
  27297. // 0000025635 00000 n
  27298. // trailer
  27299. // ...
  27300. var stream = parser.lexer.stream;
  27301. var tableState = this.tableState;
  27302. stream.pos = tableState.streamPos;
  27303. parser.buf1 = tableState.parserBuf1;
  27304. parser.buf2 = tableState.parserBuf2;
  27305. // Outer loop is over subsection headers
  27306. var obj;
  27307. while (true) {
  27308. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  27309. if (isCmd(obj = parser.getObj(), 'trailer')) {
  27310. break;
  27311. }
  27312. tableState.firstEntryNum = obj;
  27313. tableState.entryCount = parser.getObj();
  27314. }
  27315. var first = tableState.firstEntryNum;
  27316. var count = tableState.entryCount;
  27317. if (!isInt(first) || !isInt(count)) {
  27318. error('Invalid XRef table: wrong types in subsection header');
  27319. }
  27320. // Inner loop is over objects themselves
  27321. for (var i = tableState.entryNum; i < count; i++) {
  27322. tableState.streamPos = stream.pos;
  27323. tableState.entryNum = i;
  27324. tableState.parserBuf1 = parser.buf1;
  27325. tableState.parserBuf2 = parser.buf2;
  27326. var entry = {};
  27327. entry.offset = parser.getObj();
  27328. entry.gen = parser.getObj();
  27329. var type = parser.getObj();
  27330. if (isCmd(type, 'f')) {
  27331. entry.free = true;
  27332. } else if (isCmd(type, 'n')) {
  27333. entry.uncompressed = true;
  27334. }
  27335. // Validate entry obj
  27336. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  27337. !(entry.free || entry.uncompressed)) {
  27338. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  27339. }
  27340. if (!this.entries[i + first]) {
  27341. this.entries[i + first] = entry;
  27342. }
  27343. }
  27344. tableState.entryNum = 0;
  27345. tableState.streamPos = stream.pos;
  27346. tableState.parserBuf1 = parser.buf1;
  27347. tableState.parserBuf2 = parser.buf2;
  27348. delete tableState.firstEntryNum;
  27349. delete tableState.entryCount;
  27350. }
  27351. // Per issue 3248: hp scanners generate bad XRef
  27352. if (first === 1 && this.entries[1] && this.entries[1].free) {
  27353. // shifting the entries
  27354. this.entries.shift();
  27355. }
  27356. // Sanity check: as per spec, first object must be free
  27357. if (this.entries[0] && !this.entries[0].free) {
  27358. error('Invalid XRef table: unexpected first object');
  27359. }
  27360. return obj;
  27361. },
  27362. processXRefStream: function XRef_processXRefStream(stream) {
  27363. if (!('streamState' in this)) {
  27364. // Stores state of the stream as we process it so we can resume
  27365. // from middle of stream in case of missing data error
  27366. var streamParameters = stream.dict;
  27367. var byteWidths = streamParameters.get('W');
  27368. var range = streamParameters.get('Index');
  27369. if (!range) {
  27370. range = [0, streamParameters.get('Size')];
  27371. }
  27372. this.streamState = {
  27373. entryRanges: range,
  27374. byteWidths: byteWidths,
  27375. entryNum: 0,
  27376. streamPos: stream.pos
  27377. };
  27378. }
  27379. this.readXRefStream(stream);
  27380. delete this.streamState;
  27381. return stream.dict;
  27382. },
  27383. readXRefStream: function XRef_readXRefStream(stream) {
  27384. var i, j;
  27385. var streamState = this.streamState;
  27386. stream.pos = streamState.streamPos;
  27387. var byteWidths = streamState.byteWidths;
  27388. var typeFieldWidth = byteWidths[0];
  27389. var offsetFieldWidth = byteWidths[1];
  27390. var generationFieldWidth = byteWidths[2];
  27391. var entryRanges = streamState.entryRanges;
  27392. while (entryRanges.length > 0) {
  27393. var first = entryRanges[0];
  27394. var n = entryRanges[1];
  27395. if (!isInt(first) || !isInt(n)) {
  27396. error('Invalid XRef range fields: ' + first + ', ' + n);
  27397. }
  27398. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  27399. !isInt(generationFieldWidth)) {
  27400. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  27401. }
  27402. for (i = streamState.entryNum; i < n; ++i) {
  27403. streamState.entryNum = i;
  27404. streamState.streamPos = stream.pos;
  27405. var type = 0, offset = 0, generation = 0;
  27406. for (j = 0; j < typeFieldWidth; ++j) {
  27407. type = (type << 8) | stream.getByte();
  27408. }
  27409. // if type field is absent, its default value is 1
  27410. if (typeFieldWidth === 0) {
  27411. type = 1;
  27412. }
  27413. for (j = 0; j < offsetFieldWidth; ++j) {
  27414. offset = (offset << 8) | stream.getByte();
  27415. }
  27416. for (j = 0; j < generationFieldWidth; ++j) {
  27417. generation = (generation << 8) | stream.getByte();
  27418. }
  27419. var entry = {};
  27420. entry.offset = offset;
  27421. entry.gen = generation;
  27422. switch (type) {
  27423. case 0:
  27424. entry.free = true;
  27425. break;
  27426. case 1:
  27427. entry.uncompressed = true;
  27428. break;
  27429. case 2:
  27430. break;
  27431. default:
  27432. error('Invalid XRef entry type: ' + type);
  27433. }
  27434. if (!this.entries[first + i]) {
  27435. this.entries[first + i] = entry;
  27436. }
  27437. }
  27438. streamState.entryNum = 0;
  27439. streamState.streamPos = stream.pos;
  27440. entryRanges.splice(0, 2);
  27441. }
  27442. },
  27443. indexObjects: function XRef_indexObjects() {
  27444. // Simple scan through the PDF content to find objects,
  27445. // trailers and XRef streams.
  27446. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  27447. var PERCENT = 0x25, LT = 0x3C;
  27448. function readToken(data, offset) {
  27449. var token = '', ch = data[offset];
  27450. while (ch !== LF && ch !== CR && ch !== LT) {
  27451. if (++offset >= data.length) {
  27452. break;
  27453. }
  27454. token += String.fromCharCode(ch);
  27455. ch = data[offset];
  27456. }
  27457. return token;
  27458. }
  27459. function skipUntil(data, offset, what) {
  27460. var length = what.length, dataLength = data.length;
  27461. var skipped = 0;
  27462. // finding byte sequence
  27463. while (offset < dataLength) {
  27464. var i = 0;
  27465. while (i < length && data[offset + i] === what[i]) {
  27466. ++i;
  27467. }
  27468. if (i >= length) {
  27469. break; // sequence found
  27470. }
  27471. offset++;
  27472. skipped++;
  27473. }
  27474. return skipped;
  27475. }
  27476. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  27477. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  27478. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  27479. 101, 102]);
  27480. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  27481. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  27482. // Clear out any existing entries, since they may be bogus.
  27483. this.entries.length = 0;
  27484. var stream = this.stream;
  27485. stream.pos = 0;
  27486. var buffer = stream.getBytes();
  27487. var position = stream.start, length = buffer.length;
  27488. var trailers = [], xrefStms = [];
  27489. while (position < length) {
  27490. var ch = buffer[position];
  27491. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  27492. ++position;
  27493. continue;
  27494. }
  27495. if (ch === PERCENT) { // %-comment
  27496. do {
  27497. ++position;
  27498. if (position >= length) {
  27499. break;
  27500. }
  27501. ch = buffer[position];
  27502. } while (ch !== LF && ch !== CR);
  27503. continue;
  27504. }
  27505. var token = readToken(buffer, position);
  27506. var m;
  27507. if (token.indexOf('xref') === 0 &&
  27508. (token.length === 4 || /\s/.test(token[4]))) {
  27509. position += skipUntil(buffer, position, trailerBytes);
  27510. trailers.push(position);
  27511. position += skipUntil(buffer, position, startxrefBytes);
  27512. } else if ((m = objRegExp.exec(token))) {
  27513. if (typeof this.entries[m[1]] === 'undefined') {
  27514. this.entries[m[1]] = {
  27515. offset: position - stream.start,
  27516. gen: m[2] | 0,
  27517. uncompressed: true
  27518. };
  27519. }
  27520. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  27521. var content = buffer.subarray(position, position + contentLength);
  27522. // checking XRef stream suspect
  27523. // (it shall have '/XRef' and next char is not a letter)
  27524. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  27525. if (xrefTagOffset < contentLength &&
  27526. content[xrefTagOffset + 5] < 64) {
  27527. xrefStms.push(position - stream.start);
  27528. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  27529. }
  27530. position += contentLength;
  27531. } else if (token.indexOf('trailer') === 0 &&
  27532. (token.length === 7 || /\s/.test(token[7]))) {
  27533. trailers.push(position);
  27534. position += skipUntil(buffer, position, startxrefBytes);
  27535. } else {
  27536. position += token.length + 1;
  27537. }
  27538. }
  27539. // reading XRef streams
  27540. var i, ii;
  27541. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  27542. this.startXRefQueue.push(xrefStms[i]);
  27543. this.readXRef(/* recoveryMode */ true);
  27544. }
  27545. // finding main trailer
  27546. var dict;
  27547. for (i = 0, ii = trailers.length; i < ii; ++i) {
  27548. stream.pos = trailers[i];
  27549. var parser = new Parser(new Lexer(stream), true, this);
  27550. var obj = parser.getObj();
  27551. if (!isCmd(obj, 'trailer')) {
  27552. continue;
  27553. }
  27554. // read the trailer dictionary
  27555. if (!isDict(dict = parser.getObj())) {
  27556. continue;
  27557. }
  27558. // taking the first one with 'ID'
  27559. if (dict.has('ID')) {
  27560. return dict;
  27561. }
  27562. }
  27563. // no tailer with 'ID', taking last one (if exists)
  27564. if (dict) {
  27565. return dict;
  27566. }
  27567. // nothing helps
  27568. // calling error() would reject worker with an UnknownErrorException.
  27569. throw new InvalidPDFException('Invalid PDF structure');
  27570. },
  27571. readXRef: function XRef_readXRef(recoveryMode) {
  27572. var stream = this.stream;
  27573. try {
  27574. while (this.startXRefQueue.length) {
  27575. var startXRef = this.startXRefQueue[0];
  27576. stream.pos = startXRef + stream.start;
  27577. var parser = new Parser(new Lexer(stream), true, this);
  27578. var obj = parser.getObj();
  27579. var dict;
  27580. // Get dictionary
  27581. if (isCmd(obj, 'xref')) {
  27582. // Parse end-of-file XRef
  27583. dict = this.processXRefTable(parser);
  27584. if (!this.topDict) {
  27585. this.topDict = dict;
  27586. }
  27587. // Recursively get other XRefs 'XRefStm', if any
  27588. obj = dict.get('XRefStm');
  27589. if (isInt(obj)) {
  27590. var pos = obj;
  27591. // ignore previously loaded xref streams
  27592. // (possible infinite recursion)
  27593. if (!(pos in this.xrefstms)) {
  27594. this.xrefstms[pos] = 1;
  27595. this.startXRefQueue.push(pos);
  27596. }
  27597. }
  27598. } else if (isInt(obj)) {
  27599. // Parse in-stream XRef
  27600. if (!isInt(parser.getObj()) ||
  27601. !isCmd(parser.getObj(), 'obj') ||
  27602. !isStream(obj = parser.getObj())) {
  27603. error('Invalid XRef stream');
  27604. }
  27605. dict = this.processXRefStream(obj);
  27606. if (!this.topDict) {
  27607. this.topDict = dict;
  27608. }
  27609. if (!dict) {
  27610. error('Failed to read XRef stream');
  27611. }
  27612. } else {
  27613. error('Invalid XRef stream header');
  27614. }
  27615. // Recursively get previous dictionary, if any
  27616. obj = dict.get('Prev');
  27617. if (isInt(obj)) {
  27618. this.startXRefQueue.push(obj);
  27619. } else if (isRef(obj)) {
  27620. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  27621. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  27622. this.startXRefQueue.push(obj.num);
  27623. }
  27624. this.startXRefQueue.shift();
  27625. }
  27626. return this.topDict;
  27627. } catch (e) {
  27628. if (e instanceof MissingDataException) {
  27629. throw e;
  27630. }
  27631. info('(while reading XRef): ' + e);
  27632. }
  27633. if (recoveryMode) {
  27634. return;
  27635. }
  27636. throw new XRefParseException();
  27637. },
  27638. getEntry: function XRef_getEntry(i) {
  27639. var xrefEntry = this.entries[i];
  27640. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  27641. return xrefEntry;
  27642. }
  27643. return null;
  27644. },
  27645. fetchIfRef: function XRef_fetchIfRef(obj) {
  27646. if (!isRef(obj)) {
  27647. return obj;
  27648. }
  27649. return this.fetch(obj);
  27650. },
  27651. fetch: function XRef_fetch(ref, suppressEncryption) {
  27652. assert(isRef(ref), 'ref object is not a reference');
  27653. var num = ref.num;
  27654. if (num in this.cache) {
  27655. var cacheEntry = this.cache[num];
  27656. return cacheEntry;
  27657. }
  27658. var xrefEntry = this.getEntry(num);
  27659. // the referenced entry can be free
  27660. if (xrefEntry === null) {
  27661. return (this.cache[num] = null);
  27662. }
  27663. if (xrefEntry.uncompressed) {
  27664. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  27665. } else {
  27666. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  27667. }
  27668. if (isDict(xrefEntry)){
  27669. xrefEntry.objId = ref.toString();
  27670. } else if (isStream(xrefEntry)) {
  27671. xrefEntry.dict.objId = ref.toString();
  27672. }
  27673. return xrefEntry;
  27674. },
  27675. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  27676. suppressEncryption) {
  27677. var gen = ref.gen;
  27678. var num = ref.num;
  27679. if (xrefEntry.gen !== gen) {
  27680. error('inconsistent generation in XRef');
  27681. }
  27682. var stream = this.stream.makeSubStream(xrefEntry.offset +
  27683. this.stream.start);
  27684. var parser = new Parser(new Lexer(stream), true, this);
  27685. var obj1 = parser.getObj();
  27686. var obj2 = parser.getObj();
  27687. var obj3 = parser.getObj();
  27688. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  27689. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  27690. !isCmd(obj3)) {
  27691. error('bad XRef entry');
  27692. }
  27693. if (!isCmd(obj3, 'obj')) {
  27694. // some bad PDFs use "obj1234" and really mean 1234
  27695. if (obj3.cmd.indexOf('obj') === 0) {
  27696. num = parseInt(obj3.cmd.substring(3), 10);
  27697. if (!isNaN(num)) {
  27698. return num;
  27699. }
  27700. }
  27701. error('bad XRef entry');
  27702. }
  27703. if (this.encrypt && !suppressEncryption) {
  27704. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  27705. } else {
  27706. xrefEntry = parser.getObj();
  27707. }
  27708. if (!isStream(xrefEntry)) {
  27709. this.cache[num] = xrefEntry;
  27710. }
  27711. return xrefEntry;
  27712. },
  27713. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  27714. suppressEncryption) {
  27715. var tableOffset = xrefEntry.offset;
  27716. var stream = this.fetch(new Ref(tableOffset, 0));
  27717. if (!isStream(stream)) {
  27718. error('bad ObjStm stream');
  27719. }
  27720. var first = stream.dict.get('First');
  27721. var n = stream.dict.get('N');
  27722. if (!isInt(first) || !isInt(n)) {
  27723. error('invalid first and n parameters for ObjStm stream');
  27724. }
  27725. var parser = new Parser(new Lexer(stream), false, this);
  27726. parser.allowStreams = true;
  27727. var i, entries = [], num, nums = [];
  27728. // read the object numbers to populate cache
  27729. for (i = 0; i < n; ++i) {
  27730. num = parser.getObj();
  27731. if (!isInt(num)) {
  27732. error('invalid object number in the ObjStm stream: ' + num);
  27733. }
  27734. nums.push(num);
  27735. var offset = parser.getObj();
  27736. if (!isInt(offset)) {
  27737. error('invalid object offset in the ObjStm stream: ' + offset);
  27738. }
  27739. }
  27740. // read stream objects for cache
  27741. for (i = 0; i < n; ++i) {
  27742. entries.push(parser.getObj());
  27743. num = nums[i];
  27744. var entry = this.entries[num];
  27745. if (entry && entry.offset === tableOffset && entry.gen === i) {
  27746. this.cache[num] = entries[i];
  27747. }
  27748. }
  27749. xrefEntry = entries[xrefEntry.gen];
  27750. if (xrefEntry === undefined) {
  27751. error('bad XRef entry for compressed object');
  27752. }
  27753. return xrefEntry;
  27754. },
  27755. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  27756. if (!isRef(obj)) {
  27757. return Promise.resolve(obj);
  27758. }
  27759. return this.fetchAsync(obj);
  27760. },
  27761. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  27762. var streamManager = this.stream.manager;
  27763. var xref = this;
  27764. return new Promise(function tryFetch(resolve, reject) {
  27765. try {
  27766. resolve(xref.fetch(ref, suppressEncryption));
  27767. } catch (e) {
  27768. if (e instanceof MissingDataException) {
  27769. streamManager.requestRange(e.begin, e.end).then(function () {
  27770. tryFetch(resolve, reject);
  27771. }, reject);
  27772. return;
  27773. }
  27774. reject(e);
  27775. }
  27776. });
  27777. },
  27778. getCatalogObj: function XRef_getCatalogObj() {
  27779. return this.root;
  27780. }
  27781. };
  27782. return XRef;
  27783. })();
  27784. /**
  27785. * A NameTree is like a Dict but has some advantageous properties, see the
  27786. * spec (7.9.6) for more details.
  27787. * TODO: implement all the Dict functions and make this more efficent.
  27788. */
  27789. var NameTree = (function NameTreeClosure() {
  27790. function NameTree(root, xref) {
  27791. this.root = root;
  27792. this.xref = xref;
  27793. }
  27794. NameTree.prototype = {
  27795. getAll: function NameTree_getAll() {
  27796. var dict = {};
  27797. if (!this.root) {
  27798. return dict;
  27799. }
  27800. var xref = this.xref;
  27801. // reading name tree
  27802. var processed = new RefSet();
  27803. processed.put(this.root);
  27804. var queue = [this.root];
  27805. while (queue.length > 0) {
  27806. var i, n;
  27807. var obj = xref.fetchIfRef(queue.shift());
  27808. if (!isDict(obj)) {
  27809. continue;
  27810. }
  27811. if (obj.has('Kids')) {
  27812. var kids = obj.get('Kids');
  27813. for (i = 0, n = kids.length; i < n; i++) {
  27814. var kid = kids[i];
  27815. if (processed.has(kid)) {
  27816. error('invalid destinations');
  27817. }
  27818. queue.push(kid);
  27819. processed.put(kid);
  27820. }
  27821. continue;
  27822. }
  27823. var names = obj.get('Names');
  27824. if (names) {
  27825. for (i = 0, n = names.length; i < n; i += 2) {
  27826. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  27827. }
  27828. }
  27829. }
  27830. return dict;
  27831. },
  27832. get: function NameTree_get(destinationId) {
  27833. if (!this.root) {
  27834. return null;
  27835. }
  27836. var xref = this.xref;
  27837. var kidsOrNames = xref.fetchIfRef(this.root);
  27838. var loopCount = 0;
  27839. var MAX_NAMES_LEVELS = 10;
  27840. var l, r, m;
  27841. // Perform a binary search to quickly find the entry that
  27842. // contains the named destination we are looking for.
  27843. while (kidsOrNames.has('Kids')) {
  27844. loopCount++;
  27845. if (loopCount > MAX_NAMES_LEVELS) {
  27846. warn('Search depth limit for named destionations has been reached.');
  27847. return null;
  27848. }
  27849. var kids = kidsOrNames.get('Kids');
  27850. if (!isArray(kids)) {
  27851. return null;
  27852. }
  27853. l = 0;
  27854. r = kids.length - 1;
  27855. while (l <= r) {
  27856. m = (l + r) >> 1;
  27857. var kid = xref.fetchIfRef(kids[m]);
  27858. var limits = kid.get('Limits');
  27859. if (destinationId < xref.fetchIfRef(limits[0])) {
  27860. r = m - 1;
  27861. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  27862. l = m + 1;
  27863. } else {
  27864. kidsOrNames = xref.fetchIfRef(kids[m]);
  27865. break;
  27866. }
  27867. }
  27868. if (l > r) {
  27869. return null;
  27870. }
  27871. }
  27872. // If we get here, then we have found the right entry. Now
  27873. // go through the named destinations in the Named dictionary
  27874. // until we find the exact destination we're looking for.
  27875. var names = kidsOrNames.get('Names');
  27876. if (isArray(names)) {
  27877. // Perform a binary search to reduce the lookup time.
  27878. l = 0;
  27879. r = names.length - 2;
  27880. while (l <= r) {
  27881. // Check only even indices (0, 2, 4, ...) because the
  27882. // odd indices contain the actual D array.
  27883. m = (l + r) & ~1;
  27884. if (destinationId < xref.fetchIfRef(names[m])) {
  27885. r = m - 2;
  27886. } else if (destinationId > xref.fetchIfRef(names[m])) {
  27887. l = m + 2;
  27888. } else {
  27889. return xref.fetchIfRef(names[m + 1]);
  27890. }
  27891. }
  27892. }
  27893. return null;
  27894. }
  27895. };
  27896. return NameTree;
  27897. })();
  27898. /**
  27899. * "A PDF file can refer to the contents of another file by using a File
  27900. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  27901. * NOTE: Only embedded files are supported (as part of the attachments support)
  27902. * TODO: support the 'URL' file system (with caching if !/V), portable
  27903. * collections attributes and related files (/RF)
  27904. */
  27905. var FileSpec = (function FileSpecClosure() {
  27906. function FileSpec(root, xref) {
  27907. if (!root || !isDict(root)) {
  27908. return;
  27909. }
  27910. this.xref = xref;
  27911. this.root = root;
  27912. if (root.has('FS')) {
  27913. this.fs = root.get('FS');
  27914. }
  27915. this.description = root.has('Desc') ?
  27916. stringToPDFString(root.get('Desc')) :
  27917. '';
  27918. if (root.has('RF')) {
  27919. warn('Related file specifications are not supported');
  27920. }
  27921. this.contentAvailable = true;
  27922. if (!root.has('EF')) {
  27923. this.contentAvailable = false;
  27924. warn('Non-embedded file specifications are not supported');
  27925. }
  27926. }
  27927. function pickPlatformItem(dict) {
  27928. // Look for the filename in this order:
  27929. // UF, F, Unix, Mac, DOS
  27930. if (dict.has('UF')) {
  27931. return dict.get('UF');
  27932. } else if (dict.has('F')) {
  27933. return dict.get('F');
  27934. } else if (dict.has('Unix')) {
  27935. return dict.get('Unix');
  27936. } else if (dict.has('Mac')) {
  27937. return dict.get('Mac');
  27938. } else if (dict.has('DOS')) {
  27939. return dict.get('DOS');
  27940. } else {
  27941. return null;
  27942. }
  27943. }
  27944. FileSpec.prototype = {
  27945. get filename() {
  27946. if (!this._filename && this.root) {
  27947. var filename = pickPlatformItem(this.root) || 'unnamed';
  27948. this._filename = stringToPDFString(filename).
  27949. replace(/\\\\/g, '\\').
  27950. replace(/\\\//g, '/').
  27951. replace(/\\/g, '/');
  27952. }
  27953. return this._filename;
  27954. },
  27955. get content() {
  27956. if (!this.contentAvailable) {
  27957. return null;
  27958. }
  27959. if (!this.contentRef && this.root) {
  27960. this.contentRef = pickPlatformItem(this.root.get('EF'));
  27961. }
  27962. var content = null;
  27963. if (this.contentRef) {
  27964. var xref = this.xref;
  27965. var fileObj = xref.fetchIfRef(this.contentRef);
  27966. if (fileObj && isStream(fileObj)) {
  27967. content = fileObj.getBytes();
  27968. } else {
  27969. warn('Embedded file specification points to non-existing/invalid ' +
  27970. 'content');
  27971. }
  27972. } else {
  27973. warn('Embedded file specification does not have a content');
  27974. }
  27975. return content;
  27976. },
  27977. get serializable() {
  27978. return {
  27979. filename: this.filename,
  27980. content: this.content
  27981. };
  27982. }
  27983. };
  27984. return FileSpec;
  27985. })();
  27986. /**
  27987. * A helper for loading missing data in object graphs. It traverses the graph
  27988. * depth first and queues up any objects that have missing data. Once it has
  27989. * has traversed as many objects that are available it attempts to bundle the
  27990. * missing data requests and then resume from the nodes that weren't ready.
  27991. *
  27992. * NOTE: It provides protection from circular references by keeping track of
  27993. * of loaded references. However, you must be careful not to load any graphs
  27994. * that have references to the catalog or other pages since that will cause the
  27995. * entire PDF document object graph to be traversed.
  27996. */
  27997. var ObjectLoader = (function() {
  27998. function mayHaveChildren(value) {
  27999. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  28000. }
  28001. function addChildren(node, nodesToVisit) {
  28002. var value;
  28003. if (isDict(node) || isStream(node)) {
  28004. var map;
  28005. if (isDict(node)) {
  28006. map = node.map;
  28007. } else {
  28008. map = node.dict.map;
  28009. }
  28010. for (var key in map) {
  28011. value = map[key];
  28012. if (mayHaveChildren(value)) {
  28013. nodesToVisit.push(value);
  28014. }
  28015. }
  28016. } else if (isArray(node)) {
  28017. for (var i = 0, ii = node.length; i < ii; i++) {
  28018. value = node[i];
  28019. if (mayHaveChildren(value)) {
  28020. nodesToVisit.push(value);
  28021. }
  28022. }
  28023. }
  28024. }
  28025. function ObjectLoader(obj, keys, xref) {
  28026. this.obj = obj;
  28027. this.keys = keys;
  28028. this.xref = xref;
  28029. this.refSet = null;
  28030. this.capability = null;
  28031. }
  28032. ObjectLoader.prototype = {
  28033. load: function ObjectLoader_load() {
  28034. var keys = this.keys;
  28035. this.capability = createPromiseCapability();
  28036. // Don't walk the graph if all the data is already loaded.
  28037. if (!(this.xref.stream instanceof ChunkedStream) ||
  28038. this.xref.stream.getMissingChunks().length === 0) {
  28039. this.capability.resolve();
  28040. return this.capability.promise;
  28041. }
  28042. this.refSet = new RefSet();
  28043. // Setup the initial nodes to visit.
  28044. var nodesToVisit = [];
  28045. for (var i = 0; i < keys.length; i++) {
  28046. nodesToVisit.push(this.obj[keys[i]]);
  28047. }
  28048. this._walk(nodesToVisit);
  28049. return this.capability.promise;
  28050. },
  28051. _walk: function ObjectLoader_walk(nodesToVisit) {
  28052. var nodesToRevisit = [];
  28053. var pendingRequests = [];
  28054. // DFS walk of the object graph.
  28055. while (nodesToVisit.length) {
  28056. var currentNode = nodesToVisit.pop();
  28057. // Only references or chunked streams can cause missing data exceptions.
  28058. if (isRef(currentNode)) {
  28059. // Skip nodes that have already been visited.
  28060. if (this.refSet.has(currentNode)) {
  28061. continue;
  28062. }
  28063. try {
  28064. var ref = currentNode;
  28065. this.refSet.put(ref);
  28066. currentNode = this.xref.fetch(currentNode);
  28067. } catch (e) {
  28068. if (!(e instanceof MissingDataException)) {
  28069. throw e;
  28070. }
  28071. nodesToRevisit.push(currentNode);
  28072. pendingRequests.push({ begin: e.begin, end: e.end });
  28073. }
  28074. }
  28075. if (currentNode && currentNode.getBaseStreams) {
  28076. var baseStreams = currentNode.getBaseStreams();
  28077. var foundMissingData = false;
  28078. for (var i = 0; i < baseStreams.length; i++) {
  28079. var stream = baseStreams[i];
  28080. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  28081. foundMissingData = true;
  28082. pendingRequests.push({
  28083. begin: stream.start,
  28084. end: stream.end
  28085. });
  28086. }
  28087. }
  28088. if (foundMissingData) {
  28089. nodesToRevisit.push(currentNode);
  28090. }
  28091. }
  28092. addChildren(currentNode, nodesToVisit);
  28093. }
  28094. if (pendingRequests.length) {
  28095. this.xref.stream.manager.requestRanges(pendingRequests).then(
  28096. function pendingRequestCallback() {
  28097. nodesToVisit = nodesToRevisit;
  28098. for (var i = 0; i < nodesToRevisit.length; i++) {
  28099. var node = nodesToRevisit[i];
  28100. // Remove any reference nodes from the currrent refset so they
  28101. // aren't skipped when we revist them.
  28102. if (isRef(node)) {
  28103. this.refSet.remove(node);
  28104. }
  28105. }
  28106. this._walk(nodesToVisit);
  28107. }.bind(this), this.capability.reject);
  28108. return;
  28109. }
  28110. // Everything is loaded.
  28111. this.refSet = null;
  28112. this.capability.resolve();
  28113. }
  28114. };
  28115. return ObjectLoader;
  28116. })();
  28117. exports.Catalog = Catalog;
  28118. exports.ObjectLoader = ObjectLoader;
  28119. exports.XRef = XRef;
  28120. }));
  28121. (function (root, factory) {
  28122. {
  28123. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  28124. root.pdfjsCoreParser);
  28125. }
  28126. }(this, function (exports, sharedUtil, coreParser) {
  28127. var error = sharedUtil.error;
  28128. var EOF = coreParser.EOF;
  28129. var Lexer = coreParser.Lexer;
  28130. var PostScriptParser = (function PostScriptParserClosure() {
  28131. function PostScriptParser(lexer) {
  28132. this.lexer = lexer;
  28133. this.operators = [];
  28134. this.token = null;
  28135. this.prev = null;
  28136. }
  28137. PostScriptParser.prototype = {
  28138. nextToken: function PostScriptParser_nextToken() {
  28139. this.prev = this.token;
  28140. this.token = this.lexer.getToken();
  28141. },
  28142. accept: function PostScriptParser_accept(type) {
  28143. if (this.token.type === type) {
  28144. this.nextToken();
  28145. return true;
  28146. }
  28147. return false;
  28148. },
  28149. expect: function PostScriptParser_expect(type) {
  28150. if (this.accept(type)) {
  28151. return true;
  28152. }
  28153. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  28154. type + '.');
  28155. },
  28156. parse: function PostScriptParser_parse() {
  28157. this.nextToken();
  28158. this.expect(PostScriptTokenTypes.LBRACE);
  28159. this.parseBlock();
  28160. this.expect(PostScriptTokenTypes.RBRACE);
  28161. return this.operators;
  28162. },
  28163. parseBlock: function PostScriptParser_parseBlock() {
  28164. while (true) {
  28165. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  28166. this.operators.push(this.prev.value);
  28167. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  28168. this.operators.push(this.prev.value);
  28169. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28170. this.parseCondition();
  28171. } else {
  28172. return;
  28173. }
  28174. }
  28175. },
  28176. parseCondition: function PostScriptParser_parseCondition() {
  28177. // Add two place holders that will be updated later
  28178. var conditionLocation = this.operators.length;
  28179. this.operators.push(null, null);
  28180. this.parseBlock();
  28181. this.expect(PostScriptTokenTypes.RBRACE);
  28182. if (this.accept(PostScriptTokenTypes.IF)) {
  28183. // The true block is right after the 'if' so it just falls through on
  28184. // true else it jumps and skips the true block.
  28185. this.operators[conditionLocation] = this.operators.length;
  28186. this.operators[conditionLocation + 1] = 'jz';
  28187. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28188. var jumpLocation = this.operators.length;
  28189. this.operators.push(null, null);
  28190. var endOfTrue = this.operators.length;
  28191. this.parseBlock();
  28192. this.expect(PostScriptTokenTypes.RBRACE);
  28193. this.expect(PostScriptTokenTypes.IFELSE);
  28194. // The jump is added at the end of the true block to skip the false
  28195. // block.
  28196. this.operators[jumpLocation] = this.operators.length;
  28197. this.operators[jumpLocation + 1] = 'j';
  28198. this.operators[conditionLocation] = endOfTrue;
  28199. this.operators[conditionLocation + 1] = 'jz';
  28200. } else {
  28201. error('PS Function: error parsing conditional.');
  28202. }
  28203. }
  28204. };
  28205. return PostScriptParser;
  28206. })();
  28207. var PostScriptTokenTypes = {
  28208. LBRACE: 0,
  28209. RBRACE: 1,
  28210. NUMBER: 2,
  28211. OPERATOR: 3,
  28212. IF: 4,
  28213. IFELSE: 5
  28214. };
  28215. var PostScriptToken = (function PostScriptTokenClosure() {
  28216. function PostScriptToken(type, value) {
  28217. this.type = type;
  28218. this.value = value;
  28219. }
  28220. var opCache = {};
  28221. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  28222. var opValue = opCache[op];
  28223. if (opValue) {
  28224. return opValue;
  28225. }
  28226. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  28227. };
  28228. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  28229. '{');
  28230. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  28231. '}');
  28232. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  28233. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  28234. 'IFELSE');
  28235. return PostScriptToken;
  28236. })();
  28237. var PostScriptLexer = (function PostScriptLexerClosure() {
  28238. function PostScriptLexer(stream) {
  28239. this.stream = stream;
  28240. this.nextChar();
  28241. this.strBuf = [];
  28242. }
  28243. PostScriptLexer.prototype = {
  28244. nextChar: function PostScriptLexer_nextChar() {
  28245. return (this.currentChar = this.stream.getByte());
  28246. },
  28247. getToken: function PostScriptLexer_getToken() {
  28248. var comment = false;
  28249. var ch = this.currentChar;
  28250. // skip comments
  28251. while (true) {
  28252. if (ch < 0) {
  28253. return EOF;
  28254. }
  28255. if (comment) {
  28256. if (ch === 0x0A || ch === 0x0D) {
  28257. comment = false;
  28258. }
  28259. } else if (ch === 0x25) { // '%'
  28260. comment = true;
  28261. } else if (!Lexer.isSpace(ch)) {
  28262. break;
  28263. }
  28264. ch = this.nextChar();
  28265. }
  28266. switch (ch | 0) {
  28267. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28268. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28269. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28270. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  28271. this.getNumber());
  28272. case 0x7B: // '{'
  28273. this.nextChar();
  28274. return PostScriptToken.LBRACE;
  28275. case 0x7D: // '}'
  28276. this.nextChar();
  28277. return PostScriptToken.RBRACE;
  28278. }
  28279. // operator
  28280. var strBuf = this.strBuf;
  28281. strBuf.length = 0;
  28282. strBuf[0] = String.fromCharCode(ch);
  28283. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  28284. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  28285. strBuf.push(String.fromCharCode(ch));
  28286. }
  28287. var str = strBuf.join('');
  28288. switch (str.toLowerCase()) {
  28289. case 'if':
  28290. return PostScriptToken.IF;
  28291. case 'ifelse':
  28292. return PostScriptToken.IFELSE;
  28293. default:
  28294. return PostScriptToken.getOperator(str);
  28295. }
  28296. },
  28297. getNumber: function PostScriptLexer_getNumber() {
  28298. var ch = this.currentChar;
  28299. var strBuf = this.strBuf;
  28300. strBuf.length = 0;
  28301. strBuf[0] = String.fromCharCode(ch);
  28302. while ((ch = this.nextChar()) >= 0) {
  28303. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  28304. ch === 0x2D || ch === 0x2E) { // '-', '.'
  28305. strBuf.push(String.fromCharCode(ch));
  28306. } else {
  28307. break;
  28308. }
  28309. }
  28310. var value = parseFloat(strBuf.join(''));
  28311. if (isNaN(value)) {
  28312. error('Invalid floating point number: ' + value);
  28313. }
  28314. return value;
  28315. }
  28316. };
  28317. return PostScriptLexer;
  28318. })();
  28319. exports.PostScriptLexer = PostScriptLexer;
  28320. exports.PostScriptParser = PostScriptParser;
  28321. }));
  28322. (function (root, factory) {
  28323. {
  28324. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  28325. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  28326. root.pdfjsSharedGlobal);
  28327. }
  28328. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  28329. sharedGlobal, amdRequire) {
  28330. var InvalidPDFException = sharedUtil.InvalidPDFException;
  28331. var MessageHandler = sharedUtil.MessageHandler;
  28332. var MissingPDFException = sharedUtil.MissingPDFException;
  28333. var PasswordResponses = sharedUtil.PasswordResponses;
  28334. var PasswordException = sharedUtil.PasswordException;
  28335. var StatTimer = sharedUtil.StatTimer;
  28336. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  28337. var UnknownErrorException = sharedUtil.UnknownErrorException;
  28338. var Util = sharedUtil.Util;
  28339. var createPromiseCapability = sharedUtil.createPromiseCapability;
  28340. var combineUrl = sharedUtil.combineUrl;
  28341. var error = sharedUtil.error;
  28342. var deprecated = sharedUtil.deprecated;
  28343. var info = sharedUtil.info;
  28344. var isArrayBuffer = sharedUtil.isArrayBuffer;
  28345. var loadJpegStream = sharedUtil.loadJpegStream;
  28346. var stringToBytes = sharedUtil.stringToBytes;
  28347. var warn = sharedUtil.warn;
  28348. var FontFaceObject = displayFontLoader.FontFaceObject;
  28349. var FontLoader = displayFontLoader.FontLoader;
  28350. var CanvasGraphics = displayCanvas.CanvasGraphics;
  28351. var createScratchCanvas = displayCanvas.createScratchCanvas;
  28352. var PDFJS = sharedGlobal.PDFJS;
  28353. var globalScope = sharedGlobal.globalScope;
  28354. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  28355. /**
  28356. * The maximum allowed image size in total pixels e.g. width * height. Images
  28357. * above this value will not be drawn. Use -1 for no limit.
  28358. * @var {number}
  28359. */
  28360. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  28361. -1 : PDFJS.maxImageSize);
  28362. /**
  28363. * The url of where the predefined Adobe CMaps are located. Include trailing
  28364. * slash.
  28365. * @var {string}
  28366. */
  28367. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  28368. /**
  28369. * Specifies if CMaps are binary packed.
  28370. * @var {boolean}
  28371. */
  28372. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  28373. /**
  28374. * By default fonts are converted to OpenType fonts and loaded via font face
  28375. * rules. If disabled, the font will be rendered using a built in font renderer
  28376. * that constructs the glyphs with primitive path commands.
  28377. * @var {boolean}
  28378. */
  28379. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  28380. false : PDFJS.disableFontFace);
  28381. /**
  28382. * Path for image resources, mainly for annotation icons. Include trailing
  28383. * slash.
  28384. * @var {string}
  28385. */
  28386. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  28387. '' : PDFJS.imageResourcesPath);
  28388. /**
  28389. * Disable the web worker and run all code on the main thread. This will happen
  28390. * automatically if the browser doesn't support workers or sending typed arrays
  28391. * to workers.
  28392. * @var {boolean}
  28393. */
  28394. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  28395. false : PDFJS.disableWorker);
  28396. /**
  28397. * Path and filename of the worker file. Required when the worker is enabled in
  28398. * development mode. If unspecified in the production build, the worker will be
  28399. * loaded based on the location of the pdf.js file. It is recommended that
  28400. * the workerSrc is set in a custom application to prevent issues caused by
  28401. * third-party frameworks and libraries.
  28402. * @var {string}
  28403. */
  28404. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  28405. /**
  28406. * Disable range request loading of PDF files. When enabled and if the server
  28407. * supports partial content requests then the PDF will be fetched in chunks.
  28408. * Enabled (false) by default.
  28409. * @var {boolean}
  28410. */
  28411. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  28412. false : PDFJS.disableRange);
  28413. /**
  28414. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  28415. * in chunks. This default behavior can be disabled.
  28416. * @var {boolean}
  28417. */
  28418. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  28419. false : PDFJS.disableStream);
  28420. /**
  28421. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  28422. * will automatically keep fetching more data even if it isn't needed to display
  28423. * the current page. This default behavior can be disabled.
  28424. *
  28425. * NOTE: It is also necessary to disable streaming, see above,
  28426. * in order for disabling of pre-fetching to work correctly.
  28427. * @var {boolean}
  28428. */
  28429. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  28430. false : PDFJS.disableAutoFetch);
  28431. /**
  28432. * Enables special hooks for debugging PDF.js.
  28433. * @var {boolean}
  28434. */
  28435. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  28436. /**
  28437. * Enables transfer usage in postMessage for ArrayBuffers.
  28438. * @var {boolean}
  28439. */
  28440. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  28441. true : PDFJS.postMessageTransfers);
  28442. /**
  28443. * Disables URL.createObjectURL usage.
  28444. * @var {boolean}
  28445. */
  28446. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  28447. false : PDFJS.disableCreateObjectURL);
  28448. /**
  28449. * Disables WebGL usage.
  28450. * @var {boolean}
  28451. */
  28452. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  28453. true : PDFJS.disableWebGL);
  28454. /**
  28455. * Disables fullscreen support, and by extension Presentation Mode,
  28456. * in browsers which support the fullscreen API.
  28457. * @var {boolean}
  28458. */
  28459. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  28460. false : PDFJS.disableFullscreen);
  28461. /**
  28462. * Enables CSS only zooming.
  28463. * @var {boolean}
  28464. */
  28465. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  28466. false : PDFJS.useOnlyCssZoom);
  28467. /**
  28468. * Controls the logging level.
  28469. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  28470. * - errors
  28471. * - warnings [default]
  28472. * - infos
  28473. * @var {number}
  28474. */
  28475. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  28476. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  28477. /**
  28478. * The maximum supported canvas size in total pixels e.g. width * height.
  28479. * The default value is 4096 * 4096. Use -1 for no limit.
  28480. * @var {number}
  28481. */
  28482. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  28483. 16777216 : PDFJS.maxCanvasPixels);
  28484. /**
  28485. * (Deprecated) Opens external links in a new window if enabled.
  28486. * The default behavior opens external links in the PDF.js window.
  28487. *
  28488. * NOTE: This property has been deprecated, please use
  28489. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  28490. * @var {boolean}
  28491. */
  28492. PDFJS.openExternalLinksInNewWindow = (
  28493. PDFJS.openExternalLinksInNewWindow === undefined ?
  28494. false : PDFJS.openExternalLinksInNewWindow);
  28495. /**
  28496. * Specifies the |target| attribute for external links.
  28497. * The constants from PDFJS.LinkTarget should be used:
  28498. * - NONE [default]
  28499. * - SELF
  28500. * - BLANK
  28501. * - PARENT
  28502. * - TOP
  28503. * @var {number}
  28504. */
  28505. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  28506. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  28507. /**
  28508. * Specifies the |rel| attribute for external links. Defaults to stripping
  28509. * the referrer.
  28510. * @var {string}
  28511. */
  28512. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  28513. 'noreferrer' : PDFJS.externalLinkRel);
  28514. /**
  28515. * Determines if we can eval strings as JS. Primarily used to improve
  28516. * performance for font rendering.
  28517. * @var {boolean}
  28518. */
  28519. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  28520. true : PDFJS.isEvalSupported);
  28521. /**
  28522. * Document initialization / loading parameters object.
  28523. *
  28524. * @typedef {Object} DocumentInitParameters
  28525. * @property {string} url - The URL of the PDF.
  28526. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  28527. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  28528. * use atob() to convert it to a binary string first.
  28529. * @property {Object} httpHeaders - Basic authentication headers.
  28530. * @property {boolean} withCredentials - Indicates whether or not cross-site
  28531. * Access-Control requests should be made using credentials such as cookies
  28532. * or authorization headers. The default is false.
  28533. * @property {string} password - For decrypting password-protected PDFs.
  28534. * @property {TypedArray} initialData - A typed array with the first portion or
  28535. * all of the pdf data. Used by the extension since some data is already
  28536. * loaded before the switch to range requests.
  28537. * @property {number} length - The PDF file length. It's used for progress
  28538. * reports and range requests operations.
  28539. * @property {PDFDataRangeTransport} range
  28540. * @property {number} rangeChunkSize - Optional parameter to specify
  28541. * maximum number of bytes fetched per range request. The default value is
  28542. * 2^16 = 65536.
  28543. * @property {PDFWorker} worker - The worker that will be used for the loading
  28544. * and parsing of the PDF data.
  28545. */
  28546. /**
  28547. * @typedef {Object} PDFDocumentStats
  28548. * @property {Array} streamTypes - Used stream types in the document (an item
  28549. * is set to true if specific stream ID was used in the document).
  28550. * @property {Array} fontTypes - Used font type in the document (an item is set
  28551. * to true if specific font ID was used in the document).
  28552. */
  28553. /**
  28554. * This is the main entry point for loading a PDF and interacting with it.
  28555. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  28556. * is used, which means it must follow the same origin rules that any XHR does
  28557. * e.g. No cross domain requests without CORS.
  28558. *
  28559. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  28560. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  28561. * already populated with data or parameter object.
  28562. *
  28563. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  28564. * if you want to manually serve range requests for data in the PDF.
  28565. *
  28566. * @param {function} passwordCallback (deprecated) It is used to request a
  28567. * password if wrong or no password was provided. The callback receives two
  28568. * parameters: function that needs to be called with new password and reason
  28569. * (see {PasswordResponses}).
  28570. *
  28571. * @param {function} progressCallback (deprecated) It is used to be able to
  28572. * monitor the loading progress of the PDF file (necessary to implement e.g.
  28573. * a loading bar). The callback receives an {Object} with the properties:
  28574. * {number} loaded and {number} total.
  28575. *
  28576. * @return {PDFDocumentLoadingTask}
  28577. */
  28578. PDFJS.getDocument = function getDocument(src,
  28579. pdfDataRangeTransport,
  28580. passwordCallback,
  28581. progressCallback) {
  28582. var task = new PDFDocumentLoadingTask();
  28583. // Support of the obsolete arguments (for compatibility with API v1.0)
  28584. if (arguments.length > 1) {
  28585. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  28586. 'passwordCallback or progressCallback argument');
  28587. }
  28588. if (pdfDataRangeTransport) {
  28589. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  28590. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  28591. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  28592. pdfDataRangeTransport.length = src.length;
  28593. pdfDataRangeTransport.initialData = src.initialData;
  28594. if (!pdfDataRangeTransport.abort) {
  28595. pdfDataRangeTransport.abort = function () {};
  28596. }
  28597. }
  28598. src = Object.create(src);
  28599. src.range = pdfDataRangeTransport;
  28600. }
  28601. task.onPassword = passwordCallback || null;
  28602. task.onProgress = progressCallback || null;
  28603. var source;
  28604. if (typeof src === 'string') {
  28605. source = { url: src };
  28606. } else if (isArrayBuffer(src)) {
  28607. source = { data: src };
  28608. } else if (src instanceof PDFDataRangeTransport) {
  28609. source = { range: src };
  28610. } else {
  28611. if (typeof src !== 'object') {
  28612. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  28613. 'string or a parameter object');
  28614. }
  28615. if (!src.url && !src.data && !src.range) {
  28616. error('Invalid parameter object: need either .data, .range or .url');
  28617. }
  28618. source = src;
  28619. }
  28620. var params = {};
  28621. var rangeTransport = null;
  28622. var worker = null;
  28623. for (var key in source) {
  28624. if (key === 'url' && typeof window !== 'undefined') {
  28625. // The full path is required in the 'url' field.
  28626. params[key] = combineUrl(window.location.href, source[key]);
  28627. continue;
  28628. } else if (key === 'range') {
  28629. rangeTransport = source[key];
  28630. continue;
  28631. } else if (key === 'worker') {
  28632. worker = source[key];
  28633. continue;
  28634. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  28635. // Converting string or array-like data to Uint8Array.
  28636. var pdfBytes = source[key];
  28637. if (typeof pdfBytes === 'string') {
  28638. params[key] = stringToBytes(pdfBytes);
  28639. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  28640. !isNaN(pdfBytes.length)) {
  28641. params[key] = new Uint8Array(pdfBytes);
  28642. } else if (isArrayBuffer(pdfBytes)) {
  28643. params[key] = new Uint8Array(pdfBytes);
  28644. } else {
  28645. error('Invalid PDF binary data: either typed array, string or ' +
  28646. 'array-like object is expected in the data property.');
  28647. }
  28648. continue;
  28649. }
  28650. params[key] = source[key];
  28651. }
  28652. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  28653. if (!worker) {
  28654. // Worker was not provided -- creating and owning our own.
  28655. worker = new PDFWorker();
  28656. task._worker = worker;
  28657. }
  28658. var docId = task.docId;
  28659. worker.promise.then(function () {
  28660. if (task.destroyed) {
  28661. throw new Error('Loading aborted');
  28662. }
  28663. return _fetchDocument(worker, params, rangeTransport, docId).then(
  28664. function (workerId) {
  28665. if (task.destroyed) {
  28666. throw new Error('Loading aborted');
  28667. }
  28668. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  28669. messageHandler.send('Ready', null);
  28670. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  28671. task._transport = transport;
  28672. });
  28673. }).catch(task._capability.reject);
  28674. return task;
  28675. };
  28676. /**
  28677. * Starts fetching of specified PDF document/data.
  28678. * @param {PDFWorker} worker
  28679. * @param {Object} source
  28680. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  28681. * @param {string} docId Unique document id, used as MessageHandler id.
  28682. * @returns {Promise} The promise, which is resolved when worker id of
  28683. * MessageHandler is known.
  28684. * @private
  28685. */
  28686. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  28687. if (worker.destroyed) {
  28688. return Promise.reject(new Error('Worker was destroyed'));
  28689. }
  28690. source.disableAutoFetch = PDFJS.disableAutoFetch;
  28691. source.disableStream = PDFJS.disableStream;
  28692. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  28693. if (pdfDataRangeTransport) {
  28694. source.length = pdfDataRangeTransport.length;
  28695. source.initialData = pdfDataRangeTransport.initialData;
  28696. }
  28697. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  28698. docId: docId,
  28699. source: source,
  28700. disableRange: PDFJS.disableRange,
  28701. maxImageSize: PDFJS.maxImageSize,
  28702. cMapUrl: PDFJS.cMapUrl,
  28703. cMapPacked: PDFJS.cMapPacked,
  28704. disableFontFace: PDFJS.disableFontFace,
  28705. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  28706. verbosity: PDFJS.verbosity
  28707. }).then(function (workerId) {
  28708. if (worker.destroyed) {
  28709. throw new Error('Worker was destroyed');
  28710. }
  28711. return workerId;
  28712. });
  28713. }
  28714. /**
  28715. * PDF document loading operation.
  28716. * @class
  28717. * @alias PDFDocumentLoadingTask
  28718. */
  28719. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  28720. var nextDocumentId = 0;
  28721. /** @constructs PDFDocumentLoadingTask */
  28722. function PDFDocumentLoadingTask() {
  28723. this._capability = createPromiseCapability();
  28724. this._transport = null;
  28725. this._worker = null;
  28726. /**
  28727. * Unique document loading task id -- used in MessageHandlers.
  28728. * @type {string}
  28729. */
  28730. this.docId = 'd' + (nextDocumentId++);
  28731. /**
  28732. * Shows if loading task is destroyed.
  28733. * @type {boolean}
  28734. */
  28735. this.destroyed = false;
  28736. /**
  28737. * Callback to request a password if wrong or no password was provided.
  28738. * The callback receives two parameters: function that needs to be called
  28739. * with new password and reason (see {PasswordResponses}).
  28740. */
  28741. this.onPassword = null;
  28742. /**
  28743. * Callback to be able to monitor the loading progress of the PDF file
  28744. * (necessary to implement e.g. a loading bar). The callback receives
  28745. * an {Object} with the properties: {number} loaded and {number} total.
  28746. */
  28747. this.onProgress = null;
  28748. /**
  28749. * Callback to when unsupported feature is used. The callback receives
  28750. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  28751. */
  28752. this.onUnsupportedFeature = null;
  28753. }
  28754. PDFDocumentLoadingTask.prototype =
  28755. /** @lends PDFDocumentLoadingTask.prototype */ {
  28756. /**
  28757. * @return {Promise}
  28758. */
  28759. get promise() {
  28760. return this._capability.promise;
  28761. },
  28762. /**
  28763. * Aborts all network requests and destroys worker.
  28764. * @return {Promise} A promise that is resolved after destruction activity
  28765. * is completed.
  28766. */
  28767. destroy: function () {
  28768. this.destroyed = true;
  28769. var transportDestroyed = !this._transport ? Promise.resolve() :
  28770. this._transport.destroy();
  28771. return transportDestroyed.then(function () {
  28772. this._transport = null;
  28773. if (this._worker) {
  28774. this._worker.destroy();
  28775. this._worker = null;
  28776. }
  28777. }.bind(this));
  28778. },
  28779. /**
  28780. * Registers callbacks to indicate the document loading completion.
  28781. *
  28782. * @param {function} onFulfilled The callback for the loading completion.
  28783. * @param {function} onRejected The callback for the loading failure.
  28784. * @return {Promise} A promise that is resolved after the onFulfilled or
  28785. * onRejected callback.
  28786. */
  28787. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  28788. return this.promise.then.apply(this.promise, arguments);
  28789. }
  28790. };
  28791. return PDFDocumentLoadingTask;
  28792. })();
  28793. /**
  28794. * Abstract class to support range requests file loading.
  28795. * @class
  28796. * @alias PDFJS.PDFDataRangeTransport
  28797. * @param {number} length
  28798. * @param {Uint8Array} initialData
  28799. */
  28800. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  28801. function PDFDataRangeTransport(length, initialData) {
  28802. this.length = length;
  28803. this.initialData = initialData;
  28804. this._rangeListeners = [];
  28805. this._progressListeners = [];
  28806. this._progressiveReadListeners = [];
  28807. this._readyCapability = createPromiseCapability();
  28808. }
  28809. PDFDataRangeTransport.prototype =
  28810. /** @lends PDFDataRangeTransport.prototype */ {
  28811. addRangeListener:
  28812. function PDFDataRangeTransport_addRangeListener(listener) {
  28813. this._rangeListeners.push(listener);
  28814. },
  28815. addProgressListener:
  28816. function PDFDataRangeTransport_addProgressListener(listener) {
  28817. this._progressListeners.push(listener);
  28818. },
  28819. addProgressiveReadListener:
  28820. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  28821. this._progressiveReadListeners.push(listener);
  28822. },
  28823. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  28824. var listeners = this._rangeListeners;
  28825. for (var i = 0, n = listeners.length; i < n; ++i) {
  28826. listeners[i](begin, chunk);
  28827. }
  28828. },
  28829. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  28830. this._readyCapability.promise.then(function () {
  28831. var listeners = this._progressListeners;
  28832. for (var i = 0, n = listeners.length; i < n; ++i) {
  28833. listeners[i](loaded);
  28834. }
  28835. }.bind(this));
  28836. },
  28837. onDataProgressiveRead:
  28838. function PDFDataRangeTransport_onDataProgress(chunk) {
  28839. this._readyCapability.promise.then(function () {
  28840. var listeners = this._progressiveReadListeners;
  28841. for (var i = 0, n = listeners.length; i < n; ++i) {
  28842. listeners[i](chunk);
  28843. }
  28844. }.bind(this));
  28845. },
  28846. transportReady: function PDFDataRangeTransport_transportReady() {
  28847. this._readyCapability.resolve();
  28848. },
  28849. requestDataRange:
  28850. function PDFDataRangeTransport_requestDataRange(begin, end) {
  28851. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  28852. },
  28853. abort: function PDFDataRangeTransport_abort() {
  28854. }
  28855. };
  28856. return PDFDataRangeTransport;
  28857. })();
  28858. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  28859. /**
  28860. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  28861. * properties that can be read synchronously.
  28862. * @class
  28863. * @alias PDFDocumentProxy
  28864. */
  28865. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  28866. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  28867. this.pdfInfo = pdfInfo;
  28868. this.transport = transport;
  28869. this.loadingTask = loadingTask;
  28870. }
  28871. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  28872. /**
  28873. * @return {number} Total number of pages the PDF contains.
  28874. */
  28875. get numPages() {
  28876. return this.pdfInfo.numPages;
  28877. },
  28878. /**
  28879. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  28880. * unique.
  28881. */
  28882. get fingerprint() {
  28883. return this.pdfInfo.fingerprint;
  28884. },
  28885. /**
  28886. * @param {number} pageNumber The page number to get. The first page is 1.
  28887. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  28888. * object.
  28889. */
  28890. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  28891. return this.transport.getPage(pageNumber);
  28892. },
  28893. /**
  28894. * @param {{num: number, gen: number}} ref The page reference. Must have
  28895. * the 'num' and 'gen' properties.
  28896. * @return {Promise} A promise that is resolved with the page index that is
  28897. * associated with the reference.
  28898. */
  28899. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  28900. return this.transport.getPageIndex(ref);
  28901. },
  28902. /**
  28903. * @return {Promise} A promise that is resolved with a lookup table for
  28904. * mapping named destinations to reference numbers.
  28905. *
  28906. * This can be slow for large documents: use getDestination instead
  28907. */
  28908. getDestinations: function PDFDocumentProxy_getDestinations() {
  28909. return this.transport.getDestinations();
  28910. },
  28911. /**
  28912. * @param {string} id The named destination to get.
  28913. * @return {Promise} A promise that is resolved with all information
  28914. * of the given named destination.
  28915. */
  28916. getDestination: function PDFDocumentProxy_getDestination(id) {
  28917. return this.transport.getDestination(id);
  28918. },
  28919. /**
  28920. * @return {Promise} A promise that is resolved with a lookup table for
  28921. * mapping named attachments to their content.
  28922. */
  28923. getAttachments: function PDFDocumentProxy_getAttachments() {
  28924. return this.transport.getAttachments();
  28925. },
  28926. /**
  28927. * @return {Promise} A promise that is resolved with an array of all the
  28928. * JavaScript strings in the name tree.
  28929. */
  28930. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  28931. return this.transport.getJavaScript();
  28932. },
  28933. /**
  28934. * @return {Promise} A promise that is resolved with an {Array} that is a
  28935. * tree outline (if it has one) of the PDF. The tree is in the format of:
  28936. * [
  28937. * {
  28938. * title: string,
  28939. * bold: boolean,
  28940. * italic: boolean,
  28941. * color: rgb array,
  28942. * dest: dest obj,
  28943. * items: array of more items like this
  28944. * },
  28945. * ...
  28946. * ].
  28947. */
  28948. getOutline: function PDFDocumentProxy_getOutline() {
  28949. return this.transport.getOutline();
  28950. },
  28951. /**
  28952. * @return {Promise} A promise that is resolved with an {Object} that has
  28953. * info and metadata properties. Info is an {Object} filled with anything
  28954. * available in the information dictionary and similarly metadata is a
  28955. * {Metadata} object with information from the metadata section of the PDF.
  28956. */
  28957. getMetadata: function PDFDocumentProxy_getMetadata() {
  28958. return this.transport.getMetadata();
  28959. },
  28960. /**
  28961. * @return {Promise} A promise that is resolved with a TypedArray that has
  28962. * the raw data from the PDF.
  28963. */
  28964. getData: function PDFDocumentProxy_getData() {
  28965. return this.transport.getData();
  28966. },
  28967. /**
  28968. * @return {Promise} A promise that is resolved when the document's data
  28969. * is loaded. It is resolved with an {Object} that contains the length
  28970. * property that indicates size of the PDF data in bytes.
  28971. */
  28972. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  28973. return this.transport.downloadInfoCapability.promise;
  28974. },
  28975. /**
  28976. * @return {Promise} A promise this is resolved with current stats about
  28977. * document structures (see {@link PDFDocumentStats}).
  28978. */
  28979. getStats: function PDFDocumentProxy_getStats() {
  28980. return this.transport.getStats();
  28981. },
  28982. /**
  28983. * Cleans up resources allocated by the document, e.g. created @font-face.
  28984. */
  28985. cleanup: function PDFDocumentProxy_cleanup() {
  28986. this.transport.startCleanup();
  28987. },
  28988. /**
  28989. * Destroys current document instance and terminates worker.
  28990. */
  28991. destroy: function PDFDocumentProxy_destroy() {
  28992. return this.loadingTask.destroy();
  28993. }
  28994. };
  28995. return PDFDocumentProxy;
  28996. })();
  28997. /**
  28998. * Page getTextContent parameters.
  28999. *
  29000. * @typedef {Object} getTextContentParameters
  29001. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  29002. * whitespace with standard spaces (0x20). The default value is `false`.
  29003. */
  29004. /**
  29005. * Page text content.
  29006. *
  29007. * @typedef {Object} TextContent
  29008. * @property {array} items - array of {@link TextItem}
  29009. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  29010. * name.
  29011. */
  29012. /**
  29013. * Page text content part.
  29014. *
  29015. * @typedef {Object} TextItem
  29016. * @property {string} str - text content.
  29017. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  29018. * @property {array} transform - transformation matrix.
  29019. * @property {number} width - width in device space.
  29020. * @property {number} height - height in device space.
  29021. * @property {string} fontName - font name used by pdf.js for converted font.
  29022. */
  29023. /**
  29024. * Text style.
  29025. *
  29026. * @typedef {Object} TextStyle
  29027. * @property {number} ascent - font ascent.
  29028. * @property {number} descent - font descent.
  29029. * @property {boolean} vertical - text is in vertical mode.
  29030. * @property {string} fontFamily - possible font family
  29031. */
  29032. /**
  29033. * Page annotation parameters.
  29034. *
  29035. * @typedef {Object} GetAnnotationsParameters
  29036. * @param {string} intent - Determines the annotations that will be fetched,
  29037. * can be either 'display' (viewable annotations) or 'print'
  29038. * (printable annotations).
  29039. * If the parameter is omitted, all annotations are fetched.
  29040. */
  29041. /**
  29042. * Page render parameters.
  29043. *
  29044. * @typedef {Object} RenderParameters
  29045. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  29046. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  29047. * calling of PDFPage.getViewport method.
  29048. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  29049. * (default value is 'display').
  29050. * @property {Array} transform - (optional) Additional transform, applied
  29051. * just before viewport transform.
  29052. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  29053. * endLayout and appendImage functions.
  29054. * @property {function} continueCallback - (deprecated) A function that will be
  29055. * called each time the rendering is paused. To continue
  29056. * rendering call the function that is the first argument
  29057. * to the callback.
  29058. */
  29059. /**
  29060. * PDF page operator list.
  29061. *
  29062. * @typedef {Object} PDFOperatorList
  29063. * @property {Array} fnArray - Array containing the operator functions.
  29064. * @property {Array} argsArray - Array containing the arguments of the
  29065. * functions.
  29066. */
  29067. /**
  29068. * Proxy to a PDFPage in the worker thread.
  29069. * @class
  29070. * @alias PDFPageProxy
  29071. */
  29072. var PDFPageProxy = (function PDFPageProxyClosure() {
  29073. function PDFPageProxy(pageIndex, pageInfo, transport) {
  29074. this.pageIndex = pageIndex;
  29075. this.pageInfo = pageInfo;
  29076. this.transport = transport;
  29077. this.stats = new StatTimer();
  29078. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  29079. this.commonObjs = transport.commonObjs;
  29080. this.objs = new PDFObjects();
  29081. this.cleanupAfterRender = false;
  29082. this.pendingCleanup = false;
  29083. this.intentStates = {};
  29084. this.destroyed = false;
  29085. }
  29086. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  29087. /**
  29088. * @return {number} Page number of the page. First page is 1.
  29089. */
  29090. get pageNumber() {
  29091. return this.pageIndex + 1;
  29092. },
  29093. /**
  29094. * @return {number} The number of degrees the page is rotated clockwise.
  29095. */
  29096. get rotate() {
  29097. return this.pageInfo.rotate;
  29098. },
  29099. /**
  29100. * @return {Object} The reference that points to this page. It has 'num' and
  29101. * 'gen' properties.
  29102. */
  29103. get ref() {
  29104. return this.pageInfo.ref;
  29105. },
  29106. /**
  29107. * @return {Array} An array of the visible portion of the PDF page in the
  29108. * user space units - [x1, y1, x2, y2].
  29109. */
  29110. get view() {
  29111. return this.pageInfo.view;
  29112. },
  29113. /**
  29114. * @param {number} scale The desired scale of the viewport.
  29115. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  29116. * defaults to the page rotation.
  29117. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  29118. * along with transforms required for rendering.
  29119. */
  29120. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  29121. if (arguments.length < 2) {
  29122. rotate = this.rotate;
  29123. }
  29124. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  29125. },
  29126. /**
  29127. * @param {GetAnnotationsParameters} params - Annotation parameters.
  29128. * @return {Promise} A promise that is resolved with an {Array} of the
  29129. * annotation objects.
  29130. */
  29131. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  29132. var intent = (params && params.intent) || null;
  29133. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  29134. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  29135. intent);
  29136. this.annotationsIntent = intent;
  29137. }
  29138. return this.annotationsPromise;
  29139. },
  29140. /**
  29141. * Begins the process of rendering a page to the desired context.
  29142. * @param {RenderParameters} params Page render parameters.
  29143. * @return {RenderTask} An object that contains the promise, which
  29144. * is resolved when the page finishes rendering.
  29145. */
  29146. render: function PDFPageProxy_render(params) {
  29147. var stats = this.stats;
  29148. stats.time('Overall');
  29149. // If there was a pending destroy cancel it so no cleanup happens during
  29150. // this call to render.
  29151. this.pendingCleanup = false;
  29152. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  29153. if (!this.intentStates[renderingIntent]) {
  29154. this.intentStates[renderingIntent] = {};
  29155. }
  29156. var intentState = this.intentStates[renderingIntent];
  29157. // If there's no displayReadyCapability yet, then the operatorList
  29158. // was never requested before. Make the request and create the promise.
  29159. if (!intentState.displayReadyCapability) {
  29160. intentState.receivingOperatorList = true;
  29161. intentState.displayReadyCapability = createPromiseCapability();
  29162. intentState.operatorList = {
  29163. fnArray: [],
  29164. argsArray: [],
  29165. lastChunk: false
  29166. };
  29167. this.stats.time('Page Request');
  29168. this.transport.messageHandler.send('RenderPageRequest', {
  29169. pageIndex: this.pageNumber - 1,
  29170. intent: renderingIntent
  29171. });
  29172. }
  29173. var internalRenderTask = new InternalRenderTask(complete, params,
  29174. this.objs,
  29175. this.commonObjs,
  29176. intentState.operatorList,
  29177. this.pageNumber);
  29178. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  29179. if (!intentState.renderTasks) {
  29180. intentState.renderTasks = [];
  29181. }
  29182. intentState.renderTasks.push(internalRenderTask);
  29183. var renderTask = internalRenderTask.task;
  29184. // Obsolete parameter support
  29185. if (params.continueCallback) {
  29186. deprecated('render is used with continueCallback parameter');
  29187. renderTask.onContinue = params.continueCallback;
  29188. }
  29189. var self = this;
  29190. intentState.displayReadyCapability.promise.then(
  29191. function pageDisplayReadyPromise(transparency) {
  29192. if (self.pendingCleanup) {
  29193. complete();
  29194. return;
  29195. }
  29196. stats.time('Rendering');
  29197. internalRenderTask.initalizeGraphics(transparency);
  29198. internalRenderTask.operatorListChanged();
  29199. },
  29200. function pageDisplayReadPromiseError(reason) {
  29201. complete(reason);
  29202. }
  29203. );
  29204. function complete(error) {
  29205. var i = intentState.renderTasks.indexOf(internalRenderTask);
  29206. if (i >= 0) {
  29207. intentState.renderTasks.splice(i, 1);
  29208. }
  29209. if (self.cleanupAfterRender) {
  29210. self.pendingCleanup = true;
  29211. }
  29212. self._tryCleanup();
  29213. if (error) {
  29214. internalRenderTask.capability.reject(error);
  29215. } else {
  29216. internalRenderTask.capability.resolve();
  29217. }
  29218. stats.timeEnd('Rendering');
  29219. stats.timeEnd('Overall');
  29220. }
  29221. return renderTask;
  29222. },
  29223. /**
  29224. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  29225. * object that represents page's operator list.
  29226. */
  29227. getOperatorList: function PDFPageProxy_getOperatorList() {
  29228. function operatorListChanged() {
  29229. if (intentState.operatorList.lastChunk) {
  29230. intentState.opListReadCapability.resolve(intentState.operatorList);
  29231. }
  29232. }
  29233. var renderingIntent = 'oplist';
  29234. if (!this.intentStates[renderingIntent]) {
  29235. this.intentStates[renderingIntent] = {};
  29236. }
  29237. var intentState = this.intentStates[renderingIntent];
  29238. if (!intentState.opListReadCapability) {
  29239. var opListTask = {};
  29240. opListTask.operatorListChanged = operatorListChanged;
  29241. intentState.receivingOperatorList = true;
  29242. intentState.opListReadCapability = createPromiseCapability();
  29243. intentState.renderTasks = [];
  29244. intentState.renderTasks.push(opListTask);
  29245. intentState.operatorList = {
  29246. fnArray: [],
  29247. argsArray: [],
  29248. lastChunk: false
  29249. };
  29250. this.transport.messageHandler.send('RenderPageRequest', {
  29251. pageIndex: this.pageIndex,
  29252. intent: renderingIntent
  29253. });
  29254. }
  29255. return intentState.opListReadCapability.promise;
  29256. },
  29257. /**
  29258. * @param {getTextContentParameters} params - getTextContent parameters.
  29259. * @return {Promise} That is resolved a {@link TextContent}
  29260. * object that represent the page text content.
  29261. */
  29262. getTextContent: function PDFPageProxy_getTextContent(params) {
  29263. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  29264. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  29265. pageIndex: this.pageNumber - 1,
  29266. normalizeWhitespace: normalizeWhitespace,
  29267. });
  29268. },
  29269. /**
  29270. * Destroys page object.
  29271. */
  29272. _destroy: function PDFPageProxy_destroy() {
  29273. this.destroyed = true;
  29274. this.transport.pageCache[this.pageIndex] = null;
  29275. var waitOn = [];
  29276. Object.keys(this.intentStates).forEach(function(intent) {
  29277. var intentState = this.intentStates[intent];
  29278. intentState.renderTasks.forEach(function(renderTask) {
  29279. var renderCompleted = renderTask.capability.promise.
  29280. catch(function () {}); // ignoring failures
  29281. waitOn.push(renderCompleted);
  29282. renderTask.cancel();
  29283. });
  29284. }, this);
  29285. this.objs.clear();
  29286. this.annotationsPromise = null;
  29287. this.pendingCleanup = false;
  29288. return Promise.all(waitOn);
  29289. },
  29290. /**
  29291. * Cleans up resources allocated by the page. (deprecated)
  29292. */
  29293. destroy: function() {
  29294. deprecated('page destroy method, use cleanup() instead');
  29295. this.cleanup();
  29296. },
  29297. /**
  29298. * Cleans up resources allocated by the page.
  29299. */
  29300. cleanup: function PDFPageProxy_cleanup() {
  29301. this.pendingCleanup = true;
  29302. this._tryCleanup();
  29303. },
  29304. /**
  29305. * For internal use only. Attempts to clean up if rendering is in a state
  29306. * where that's possible.
  29307. * @ignore
  29308. */
  29309. _tryCleanup: function PDFPageProxy_tryCleanup() {
  29310. if (!this.pendingCleanup ||
  29311. Object.keys(this.intentStates).some(function(intent) {
  29312. var intentState = this.intentStates[intent];
  29313. return (intentState.renderTasks.length !== 0 ||
  29314. intentState.receivingOperatorList);
  29315. }, this)) {
  29316. return;
  29317. }
  29318. Object.keys(this.intentStates).forEach(function(intent) {
  29319. delete this.intentStates[intent];
  29320. }, this);
  29321. this.objs.clear();
  29322. this.annotationsPromise = null;
  29323. this.pendingCleanup = false;
  29324. },
  29325. /**
  29326. * For internal use only.
  29327. * @ignore
  29328. */
  29329. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  29330. intent) {
  29331. var intentState = this.intentStates[intent];
  29332. // TODO Refactor RenderPageRequest to separate rendering
  29333. // and operator list logic
  29334. if (intentState.displayReadyCapability) {
  29335. intentState.displayReadyCapability.resolve(transparency);
  29336. }
  29337. },
  29338. /**
  29339. * For internal use only.
  29340. * @ignore
  29341. */
  29342. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  29343. intent) {
  29344. var intentState = this.intentStates[intent];
  29345. var i, ii;
  29346. // Add the new chunk to the current operator list.
  29347. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  29348. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  29349. intentState.operatorList.argsArray.push(
  29350. operatorListChunk.argsArray[i]);
  29351. }
  29352. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  29353. // Notify all the rendering tasks there are more operators to be consumed.
  29354. for (i = 0; i < intentState.renderTasks.length; i++) {
  29355. intentState.renderTasks[i].operatorListChanged();
  29356. }
  29357. if (operatorListChunk.lastChunk) {
  29358. intentState.receivingOperatorList = false;
  29359. this._tryCleanup();
  29360. }
  29361. }
  29362. };
  29363. return PDFPageProxy;
  29364. })();
  29365. /**
  29366. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  29367. * WorkerTransport for them. If creation of a web worker is not possible,
  29368. * a "fake" worker will be used instead.
  29369. * @class
  29370. */
  29371. var PDFWorker = (function PDFWorkerClosure() {
  29372. var nextFakeWorkerId = 0;
  29373. // Loads worker code into main thread.
  29374. function setupFakeWorkerGlobal() {
  29375. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  29376. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  29377. // In the developer build load worker_loader which in turn loads all the
  29378. // other files and resolves the promise. In production only the
  29379. // pdf.worker.js file is needed.
  29380. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  29381. }
  29382. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  29383. }
  29384. function PDFWorker(name) {
  29385. this.name = name;
  29386. this.destroyed = false;
  29387. this._readyCapability = createPromiseCapability();
  29388. this._port = null;
  29389. this._webWorker = null;
  29390. this._messageHandler = null;
  29391. this._initialize();
  29392. }
  29393. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  29394. get promise() {
  29395. return this._readyCapability.promise;
  29396. },
  29397. get port() {
  29398. return this._port;
  29399. },
  29400. get messageHandler() {
  29401. return this._messageHandler;
  29402. },
  29403. _initialize: function PDFWorker_initialize() {
  29404. // If worker support isn't disabled explicit and the browser has worker
  29405. // support, create a new web worker and test if it/the browser fullfills
  29406. // all requirements to run parts of pdf.js in a web worker.
  29407. // Right now, the requirement is, that an Uint8Array is still an
  29408. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  29409. // Either workers are disabled, not supported or have thrown an exception.
  29410. // Thus, we fallback to a faked worker.
  29411. this._setupFakeWorker();
  29412. },
  29413. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  29414. if (!globalScope.PDFJS.disableWorker) {
  29415. warn('Setting up fake worker.');
  29416. globalScope.PDFJS.disableWorker = true;
  29417. }
  29418. setupFakeWorkerGlobal().then(function () {
  29419. if (this.destroyed) {
  29420. this._readyCapability.reject(new Error('Worker was destroyed'));
  29421. return;
  29422. }
  29423. // If we don't use a worker, just post/sendMessage to the main thread.
  29424. var port = {
  29425. _listeners: [],
  29426. postMessage: function (obj) {
  29427. var e = {data: obj};
  29428. this._listeners.forEach(function (listener) {
  29429. listener.call(this, e);
  29430. }, this);
  29431. },
  29432. addEventListener: function (name, listener) {
  29433. this._listeners.push(listener);
  29434. },
  29435. removeEventListener: function (name, listener) {
  29436. var i = this._listeners.indexOf(listener);
  29437. this._listeners.splice(i, 1);
  29438. },
  29439. terminate: function () {}
  29440. };
  29441. this._port = port;
  29442. // All fake workers use the same port, making id unique.
  29443. var id = 'fake' + (nextFakeWorkerId++);
  29444. // If the main thread is our worker, setup the handling for the
  29445. // messages -- the main thread sends to it self.
  29446. var workerHandler = new MessageHandler(id + '_worker', id, port);
  29447. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  29448. var messageHandler = new MessageHandler(id, id + '_worker', port);
  29449. this._messageHandler = messageHandler;
  29450. this._readyCapability.resolve();
  29451. }.bind(this));
  29452. },
  29453. /**
  29454. * Destroys the worker instance.
  29455. */
  29456. destroy: function PDFWorker_destroy() {
  29457. this.destroyed = true;
  29458. if (this._webWorker) {
  29459. // We need to terminate only web worker created resource.
  29460. this._webWorker.terminate();
  29461. this._webWorker = null;
  29462. }
  29463. this._port = null;
  29464. if (this._messageHandler) {
  29465. this._messageHandler.destroy();
  29466. this._messageHandler = null;
  29467. }
  29468. }
  29469. };
  29470. return PDFWorker;
  29471. })();
  29472. PDFJS.PDFWorker = PDFWorker;
  29473. /**
  29474. * For internal use only.
  29475. * @ignore
  29476. */
  29477. var WorkerTransport = (function WorkerTransportClosure() {
  29478. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  29479. this.messageHandler = messageHandler;
  29480. this.loadingTask = loadingTask;
  29481. this.pdfDataRangeTransport = pdfDataRangeTransport;
  29482. this.commonObjs = new PDFObjects();
  29483. this.fontLoader = new FontLoader(loadingTask.docId);
  29484. this.destroyed = false;
  29485. this.destroyCapability = null;
  29486. this.pageCache = [];
  29487. this.pagePromises = [];
  29488. this.downloadInfoCapability = createPromiseCapability();
  29489. this.setupMessageHandler();
  29490. }
  29491. WorkerTransport.prototype = {
  29492. destroy: function WorkerTransport_destroy() {
  29493. if (this.destroyCapability) {
  29494. return this.destroyCapability.promise;
  29495. }
  29496. this.destroyed = true;
  29497. this.destroyCapability = createPromiseCapability();
  29498. var waitOn = [];
  29499. // We need to wait for all renderings to be completed, e.g.
  29500. // timeout/rAF can take a long time.
  29501. this.pageCache.forEach(function (page) {
  29502. if (page) {
  29503. waitOn.push(page._destroy());
  29504. }
  29505. });
  29506. this.pageCache = [];
  29507. this.pagePromises = [];
  29508. var self = this;
  29509. // We also need to wait for the worker to finish its long running tasks.
  29510. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  29511. waitOn.push(terminated);
  29512. Promise.all(waitOn).then(function () {
  29513. self.fontLoader.clear();
  29514. if (self.pdfDataRangeTransport) {
  29515. self.pdfDataRangeTransport.abort();
  29516. self.pdfDataRangeTransport = null;
  29517. }
  29518. if (self.messageHandler) {
  29519. self.messageHandler.destroy();
  29520. self.messageHandler = null;
  29521. }
  29522. self.destroyCapability.resolve();
  29523. }, this.destroyCapability.reject);
  29524. return this.destroyCapability.promise;
  29525. },
  29526. setupMessageHandler:
  29527. function WorkerTransport_setupMessageHandler() {
  29528. var messageHandler = this.messageHandler;
  29529. function updatePassword(password) {
  29530. messageHandler.send('UpdatePassword', password);
  29531. }
  29532. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  29533. if (pdfDataRangeTransport) {
  29534. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  29535. messageHandler.send('OnDataRange', {
  29536. begin: begin,
  29537. chunk: chunk
  29538. });
  29539. });
  29540. pdfDataRangeTransport.addProgressListener(function(loaded) {
  29541. messageHandler.send('OnDataProgress', {
  29542. loaded: loaded
  29543. });
  29544. });
  29545. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  29546. messageHandler.send('OnDataRange', {
  29547. chunk: chunk
  29548. });
  29549. });
  29550. messageHandler.on('RequestDataRange',
  29551. function transportDataRange(data) {
  29552. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  29553. }, this);
  29554. }
  29555. messageHandler.on('GetDoc', function transportDoc(data) {
  29556. var pdfInfo = data.pdfInfo;
  29557. this.numPages = data.pdfInfo.numPages;
  29558. var loadingTask = this.loadingTask;
  29559. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  29560. this.pdfDocument = pdfDocument;
  29561. loadingTask._capability.resolve(pdfDocument);
  29562. }, this);
  29563. messageHandler.on('NeedPassword',
  29564. function transportNeedPassword(exception) {
  29565. var loadingTask = this.loadingTask;
  29566. if (loadingTask.onPassword) {
  29567. return loadingTask.onPassword(updatePassword,
  29568. PasswordResponses.NEED_PASSWORD);
  29569. }
  29570. loadingTask._capability.reject(
  29571. new PasswordException(exception.message, exception.code));
  29572. }, this);
  29573. messageHandler.on('IncorrectPassword',
  29574. function transportIncorrectPassword(exception) {
  29575. var loadingTask = this.loadingTask;
  29576. if (loadingTask.onPassword) {
  29577. return loadingTask.onPassword(updatePassword,
  29578. PasswordResponses.INCORRECT_PASSWORD);
  29579. }
  29580. loadingTask._capability.reject(
  29581. new PasswordException(exception.message, exception.code));
  29582. }, this);
  29583. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  29584. this.loadingTask._capability.reject(
  29585. new InvalidPDFException(exception.message));
  29586. }, this);
  29587. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  29588. this.loadingTask._capability.reject(
  29589. new MissingPDFException(exception.message));
  29590. }, this);
  29591. messageHandler.on('UnexpectedResponse',
  29592. function transportUnexpectedResponse(exception) {
  29593. this.loadingTask._capability.reject(
  29594. new UnexpectedResponseException(exception.message, exception.status));
  29595. }, this);
  29596. messageHandler.on('UnknownError',
  29597. function transportUnknownError(exception) {
  29598. this.loadingTask._capability.reject(
  29599. new UnknownErrorException(exception.message, exception.details));
  29600. }, this);
  29601. messageHandler.on('DataLoaded', function transportPage(data) {
  29602. this.downloadInfoCapability.resolve(data);
  29603. }, this);
  29604. messageHandler.on('PDFManagerReady', function transportPage(data) {
  29605. if (this.pdfDataRangeTransport) {
  29606. this.pdfDataRangeTransport.transportReady();
  29607. }
  29608. }, this);
  29609. messageHandler.on('StartRenderPage', function transportRender(data) {
  29610. if (this.destroyed) {
  29611. return; // Ignore any pending requests if the worker was terminated.
  29612. }
  29613. var page = this.pageCache[data.pageIndex];
  29614. page.stats.timeEnd('Page Request');
  29615. page._startRenderPage(data.transparency, data.intent);
  29616. }, this);
  29617. messageHandler.on('RenderPageChunk', function transportRender(data) {
  29618. if (this.destroyed) {
  29619. return; // Ignore any pending requests if the worker was terminated.
  29620. }
  29621. var page = this.pageCache[data.pageIndex];
  29622. page._renderPageChunk(data.operatorList, data.intent);
  29623. }, this);
  29624. messageHandler.on('commonobj', function transportObj(data) {
  29625. if (this.destroyed) {
  29626. return; // Ignore any pending requests if the worker was terminated.
  29627. }
  29628. var id = data[0];
  29629. var type = data[1];
  29630. if (this.commonObjs.hasData(id)) {
  29631. return;
  29632. }
  29633. switch (type) {
  29634. case 'Font':
  29635. var exportedData = data[2];
  29636. var font;
  29637. if ('error' in exportedData) {
  29638. var error = exportedData.error;
  29639. warn('Error during font loading: ' + error);
  29640. this.commonObjs.resolve(id, error);
  29641. break;
  29642. } else {
  29643. font = new FontFaceObject(exportedData);
  29644. }
  29645. this.fontLoader.bind(
  29646. [font],
  29647. function fontReady(fontObjs) {
  29648. this.commonObjs.resolve(id, font);
  29649. }.bind(this)
  29650. );
  29651. break;
  29652. case 'FontPath':
  29653. this.commonObjs.resolve(id, data[2]);
  29654. break;
  29655. default:
  29656. error('Got unknown common object type ' + type);
  29657. }
  29658. }, this);
  29659. messageHandler.on('obj', function transportObj(data) {
  29660. if (this.destroyed) {
  29661. return; // Ignore any pending requests if the worker was terminated.
  29662. }
  29663. var id = data[0];
  29664. var pageIndex = data[1];
  29665. var type = data[2];
  29666. var pageProxy = this.pageCache[pageIndex];
  29667. var imageData;
  29668. if (pageProxy.objs.hasData(id)) {
  29669. return;
  29670. }
  29671. switch (type) {
  29672. case 'JpegStream':
  29673. imageData = data[3];
  29674. loadJpegStream(id, imageData, pageProxy.objs);
  29675. break;
  29676. case 'Image':
  29677. imageData = data[3];
  29678. pageProxy.objs.resolve(id, imageData);
  29679. // heuristics that will allow not to store large data
  29680. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  29681. if (imageData && 'data' in imageData &&
  29682. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  29683. pageProxy.cleanupAfterRender = true;
  29684. }
  29685. break;
  29686. default:
  29687. error('Got unknown object type ' + type);
  29688. }
  29689. }, this);
  29690. messageHandler.on('DocProgress', function transportDocProgress(data) {
  29691. if (this.destroyed) {
  29692. return; // Ignore any pending requests if the worker was terminated.
  29693. }
  29694. var loadingTask = this.loadingTask;
  29695. if (loadingTask.onProgress) {
  29696. loadingTask.onProgress({
  29697. loaded: data.loaded,
  29698. total: data.total
  29699. });
  29700. }
  29701. }, this);
  29702. messageHandler.on('PageError', function transportError(data) {
  29703. if (this.destroyed) {
  29704. return; // Ignore any pending requests if the worker was terminated.
  29705. }
  29706. var page = this.pageCache[data.pageNum - 1];
  29707. var intentState = page.intentStates[data.intent];
  29708. if (intentState.displayReadyCapability) {
  29709. intentState.displayReadyCapability.reject(data.error);
  29710. } else {
  29711. error(data.error);
  29712. }
  29713. }, this);
  29714. messageHandler.on('UnsupportedFeature',
  29715. function transportUnsupportedFeature(data) {
  29716. if (this.destroyed) {
  29717. return; // Ignore any pending requests if the worker was terminated.
  29718. }
  29719. var featureId = data.featureId;
  29720. var loadingTask = this.loadingTask;
  29721. if (loadingTask.onUnsupportedFeature) {
  29722. loadingTask.onUnsupportedFeature(featureId);
  29723. }
  29724. PDFJS.UnsupportedManager.notify(featureId);
  29725. }, this);
  29726. messageHandler.on('JpegDecode', function(data) {
  29727. if (this.destroyed) {
  29728. return Promise.reject('Worker was terminated');
  29729. }
  29730. var imageUrl = data[0];
  29731. var components = data[1];
  29732. if (components !== 3 && components !== 1) {
  29733. return Promise.reject(
  29734. new Error('Only 3 components or 1 component can be returned'));
  29735. }
  29736. return new Promise(function (resolve, reject) {
  29737. var img = new Image();
  29738. img.onload = function () {
  29739. var width = img.width;
  29740. var height = img.height;
  29741. var size = width * height;
  29742. var rgbaLength = size * 4;
  29743. var buf = new Uint8Array(size * components);
  29744. var tmpCanvas = createScratchCanvas(width, height);
  29745. var tmpCtx = tmpCanvas.getContext('2d');
  29746. tmpCtx.drawImage(img, 0, 0);
  29747. var data = tmpCtx.getImageData(0, 0, width, height).data;
  29748. var i, j;
  29749. if (components === 3) {
  29750. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  29751. buf[j] = data[i];
  29752. buf[j + 1] = data[i + 1];
  29753. buf[j + 2] = data[i + 2];
  29754. }
  29755. } else if (components === 1) {
  29756. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  29757. buf[j] = data[i];
  29758. }
  29759. }
  29760. resolve({ data: buf, width: width, height: height});
  29761. };
  29762. img.onerror = function () {
  29763. reject(new Error('JpegDecode failed to load image'));
  29764. };
  29765. img.src = imageUrl;
  29766. });
  29767. }, this);
  29768. },
  29769. getData: function WorkerTransport_getData() {
  29770. return this.messageHandler.sendWithPromise('GetData', null);
  29771. },
  29772. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  29773. if (pageNumber <= 0 || pageNumber > this.numPages ||
  29774. (pageNumber|0) !== pageNumber) {
  29775. return Promise.reject(new Error('Invalid page request'));
  29776. }
  29777. var pageIndex = pageNumber - 1;
  29778. if (pageIndex in this.pagePromises) {
  29779. return this.pagePromises[pageIndex];
  29780. }
  29781. var promise = this.messageHandler.sendWithPromise('GetPage', {
  29782. pageIndex: pageIndex
  29783. }).then(function (pageInfo) {
  29784. if (this.destroyed) {
  29785. throw new Error('Transport destroyed');
  29786. }
  29787. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  29788. this.pageCache[pageIndex] = page;
  29789. return page;
  29790. }.bind(this));
  29791. this.pagePromises[pageIndex] = promise;
  29792. return promise;
  29793. },
  29794. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  29795. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  29796. },
  29797. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  29798. return this.messageHandler.sendWithPromise('GetAnnotations', {
  29799. pageIndex: pageIndex,
  29800. intent: intent,
  29801. });
  29802. },
  29803. getDestinations: function WorkerTransport_getDestinations() {
  29804. return this.messageHandler.sendWithPromise('GetDestinations', null);
  29805. },
  29806. getDestination: function WorkerTransport_getDestination(id) {
  29807. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  29808. },
  29809. getAttachments: function WorkerTransport_getAttachments() {
  29810. return this.messageHandler.sendWithPromise('GetAttachments', null);
  29811. },
  29812. getJavaScript: function WorkerTransport_getJavaScript() {
  29813. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  29814. },
  29815. getOutline: function WorkerTransport_getOutline() {
  29816. return this.messageHandler.sendWithPromise('GetOutline', null);
  29817. },
  29818. getMetadata: function WorkerTransport_getMetadata() {
  29819. return this.messageHandler.sendWithPromise('GetMetadata', null).
  29820. then(function transportMetadata(results) {
  29821. return {
  29822. info: results[0],
  29823. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  29824. };
  29825. });
  29826. },
  29827. getStats: function WorkerTransport_getStats() {
  29828. return this.messageHandler.sendWithPromise('GetStats', null);
  29829. },
  29830. startCleanup: function WorkerTransport_startCleanup() {
  29831. this.messageHandler.sendWithPromise('Cleanup', null).
  29832. then(function endCleanup() {
  29833. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  29834. var page = this.pageCache[i];
  29835. if (page) {
  29836. page.cleanup();
  29837. }
  29838. }
  29839. this.commonObjs.clear();
  29840. this.fontLoader.clear();
  29841. }.bind(this));
  29842. }
  29843. };
  29844. return WorkerTransport;
  29845. })();
  29846. /**
  29847. * A PDF document and page is built of many objects. E.g. there are objects
  29848. * for fonts, images, rendering code and such. These objects might get processed
  29849. * inside of a worker. The `PDFObjects` implements some basic functions to
  29850. * manage these objects.
  29851. * @ignore
  29852. */
  29853. var PDFObjects = (function PDFObjectsClosure() {
  29854. function PDFObjects() {
  29855. this.objs = {};
  29856. }
  29857. PDFObjects.prototype = {
  29858. /**
  29859. * Internal function.
  29860. * Ensures there is an object defined for `objId`.
  29861. */
  29862. ensureObj: function PDFObjects_ensureObj(objId) {
  29863. if (this.objs[objId]) {
  29864. return this.objs[objId];
  29865. }
  29866. var obj = {
  29867. capability: createPromiseCapability(),
  29868. data: null,
  29869. resolved: false
  29870. };
  29871. this.objs[objId] = obj;
  29872. return obj;
  29873. },
  29874. /**
  29875. * If called *without* callback, this returns the data of `objId` but the
  29876. * object needs to be resolved. If it isn't, this function throws.
  29877. *
  29878. * If called *with* a callback, the callback is called with the data of the
  29879. * object once the object is resolved. That means, if you call this
  29880. * function and the object is already resolved, the callback gets called
  29881. * right away.
  29882. */
  29883. get: function PDFObjects_get(objId, callback) {
  29884. // If there is a callback, then the get can be async and the object is
  29885. // not required to be resolved right now
  29886. if (callback) {
  29887. this.ensureObj(objId).capability.promise.then(callback);
  29888. return null;
  29889. }
  29890. // If there isn't a callback, the user expects to get the resolved data
  29891. // directly.
  29892. var obj = this.objs[objId];
  29893. // If there isn't an object yet or the object isn't resolved, then the
  29894. // data isn't ready yet!
  29895. if (!obj || !obj.resolved) {
  29896. error('Requesting object that isn\'t resolved yet ' + objId);
  29897. }
  29898. return obj.data;
  29899. },
  29900. /**
  29901. * Resolves the object `objId` with optional `data`.
  29902. */
  29903. resolve: function PDFObjects_resolve(objId, data) {
  29904. var obj = this.ensureObj(objId);
  29905. obj.resolved = true;
  29906. obj.data = data;
  29907. obj.capability.resolve(data);
  29908. },
  29909. isResolved: function PDFObjects_isResolved(objId) {
  29910. var objs = this.objs;
  29911. if (!objs[objId]) {
  29912. return false;
  29913. } else {
  29914. return objs[objId].resolved;
  29915. }
  29916. },
  29917. hasData: function PDFObjects_hasData(objId) {
  29918. return this.isResolved(objId);
  29919. },
  29920. /**
  29921. * Returns the data of `objId` if object exists, null otherwise.
  29922. */
  29923. getData: function PDFObjects_getData(objId) {
  29924. var objs = this.objs;
  29925. if (!objs[objId] || !objs[objId].resolved) {
  29926. return null;
  29927. } else {
  29928. return objs[objId].data;
  29929. }
  29930. },
  29931. clear: function PDFObjects_clear() {
  29932. this.objs = {};
  29933. }
  29934. };
  29935. return PDFObjects;
  29936. })();
  29937. /**
  29938. * Allows controlling of the rendering tasks.
  29939. * @class
  29940. * @alias RenderTask
  29941. */
  29942. var RenderTask = (function RenderTaskClosure() {
  29943. function RenderTask(internalRenderTask) {
  29944. this._internalRenderTask = internalRenderTask;
  29945. /**
  29946. * Callback for incremental rendering -- a function that will be called
  29947. * each time the rendering is paused. To continue rendering call the
  29948. * function that is the first argument to the callback.
  29949. * @type {function}
  29950. */
  29951. this.onContinue = null;
  29952. }
  29953. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  29954. /**
  29955. * Promise for rendering task completion.
  29956. * @return {Promise}
  29957. */
  29958. get promise() {
  29959. return this._internalRenderTask.capability.promise;
  29960. },
  29961. /**
  29962. * Cancels the rendering task. If the task is currently rendering it will
  29963. * not be cancelled until graphics pauses with a timeout. The promise that
  29964. * this object extends will resolved when cancelled.
  29965. */
  29966. cancel: function RenderTask_cancel() {
  29967. this._internalRenderTask.cancel();
  29968. },
  29969. /**
  29970. * Registers callbacks to indicate the rendering task completion.
  29971. *
  29972. * @param {function} onFulfilled The callback for the rendering completion.
  29973. * @param {function} onRejected The callback for the rendering failure.
  29974. * @return {Promise} A promise that is resolved after the onFulfilled or
  29975. * onRejected callback.
  29976. */
  29977. then: function RenderTask_then(onFulfilled, onRejected) {
  29978. return this.promise.then.apply(this.promise, arguments);
  29979. }
  29980. };
  29981. return RenderTask;
  29982. })();
  29983. /**
  29984. * For internal use only.
  29985. * @ignore
  29986. */
  29987. var InternalRenderTask = (function InternalRenderTaskClosure() {
  29988. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  29989. pageNumber) {
  29990. this.callback = callback;
  29991. this.params = params;
  29992. this.objs = objs;
  29993. this.commonObjs = commonObjs;
  29994. this.operatorListIdx = null;
  29995. this.operatorList = operatorList;
  29996. this.pageNumber = pageNumber;
  29997. this.running = false;
  29998. this.graphicsReadyCallback = null;
  29999. this.graphicsReady = false;
  30000. this.useRequestAnimationFrame = false;
  30001. this.cancelled = false;
  30002. this.capability = createPromiseCapability();
  30003. this.task = new RenderTask(this);
  30004. // caching this-bound methods
  30005. this._continueBound = this._continue.bind(this);
  30006. this._scheduleNextBound = this._scheduleNext.bind(this);
  30007. this._nextBound = this._next.bind(this);
  30008. }
  30009. InternalRenderTask.prototype = {
  30010. initalizeGraphics:
  30011. function InternalRenderTask_initalizeGraphics(transparency) {
  30012. if (this.cancelled) {
  30013. return;
  30014. }
  30015. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  30016. globalScope.StepperManager.enabled) {
  30017. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  30018. this.stepper.init(this.operatorList);
  30019. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  30020. }
  30021. var params = this.params;
  30022. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  30023. this.objs, params.imageLayer);
  30024. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  30025. this.operatorListIdx = 0;
  30026. this.graphicsReady = true;
  30027. if (this.graphicsReadyCallback) {
  30028. this.graphicsReadyCallback();
  30029. }
  30030. },
  30031. cancel: function InternalRenderTask_cancel() {
  30032. this.running = false;
  30033. this.cancelled = true;
  30034. this.callback('cancelled');
  30035. },
  30036. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  30037. if (!this.graphicsReady) {
  30038. if (!this.graphicsReadyCallback) {
  30039. this.graphicsReadyCallback = this._continueBound;
  30040. }
  30041. return;
  30042. }
  30043. if (this.stepper) {
  30044. this.stepper.updateOperatorList(this.operatorList);
  30045. }
  30046. if (this.running) {
  30047. return;
  30048. }
  30049. this._continue();
  30050. },
  30051. _continue: function InternalRenderTask__continue() {
  30052. this.running = true;
  30053. if (this.cancelled) {
  30054. return;
  30055. }
  30056. if (this.task.onContinue) {
  30057. this.task.onContinue.call(this.task, this._scheduleNextBound);
  30058. } else {
  30059. this._scheduleNext();
  30060. }
  30061. },
  30062. _scheduleNext: function InternalRenderTask__scheduleNext() {
  30063. if (this.useRequestAnimationFrame) {
  30064. window.requestAnimationFrame(this._nextBound);
  30065. } else {
  30066. Promise.resolve(undefined).then(this._nextBound);
  30067. }
  30068. },
  30069. _next: function InternalRenderTask__next() {
  30070. if (this.cancelled) {
  30071. return;
  30072. }
  30073. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  30074. this.operatorListIdx,
  30075. this._continueBound,
  30076. this.stepper);
  30077. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  30078. this.running = false;
  30079. if (this.operatorList.lastChunk) {
  30080. this.gfx.endDrawing();
  30081. this.callback();
  30082. }
  30083. }
  30084. }
  30085. };
  30086. return InternalRenderTask;
  30087. })();
  30088. /**
  30089. * (Deprecated) Global observer of unsupported feature usages. Use
  30090. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  30091. */
  30092. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  30093. var listeners = [];
  30094. return {
  30095. listen: function (cb) {
  30096. deprecated('Global UnsupportedManager.listen is used: ' +
  30097. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  30098. listeners.push(cb);
  30099. },
  30100. notify: function (featureId) {
  30101. for (var i = 0, ii = listeners.length; i < ii; i++) {
  30102. listeners[i](featureId);
  30103. }
  30104. }
  30105. };
  30106. })();
  30107. exports.getDocument = PDFJS.getDocument;
  30108. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  30109. exports.PDFDocumentProxy = PDFDocumentProxy;
  30110. exports.PDFPageProxy = PDFPageProxy;
  30111. }));
  30112. (function (root, factory) {
  30113. {
  30114. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  30115. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  30116. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  30117. root.pdfjsCoreFontRenderer);
  30118. }
  30119. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  30120. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  30121. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30122. var FontType = sharedUtil.FontType;
  30123. var Util = sharedUtil.Util;
  30124. var assert = sharedUtil.assert;
  30125. var bytesToString = sharedUtil.bytesToString;
  30126. var error = sharedUtil.error;
  30127. var info = sharedUtil.info;
  30128. var isArray = sharedUtil.isArray;
  30129. var isInt = sharedUtil.isInt;
  30130. var isNum = sharedUtil.isNum;
  30131. var readUint32 = sharedUtil.readUint32;
  30132. var shadow = sharedUtil.shadow;
  30133. var stringToBytes = sharedUtil.stringToBytes;
  30134. var string32 = sharedUtil.string32;
  30135. var warn = sharedUtil.warn;
  30136. var Name = corePrimitives.Name;
  30137. var Stream = coreStream.Stream;
  30138. var Lexer = coreParser.Lexer;
  30139. var CMapFactory = coreCMap.CMapFactory;
  30140. var IdentityCMap = coreCMap.IdentityCMap;
  30141. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  30142. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  30143. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  30144. var ExpertCharset = coreCharsets.ExpertCharset;
  30145. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  30146. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30147. // Unicode Private Use Area
  30148. var PRIVATE_USE_OFFSET_START = 0xE000;
  30149. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30150. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30151. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30152. // except for Type 3 fonts
  30153. var PDF_GLYPH_SPACE_UNITS = 1000;
  30154. // Hinting is currently disabled due to unknown problems on windows
  30155. // in tracemonkey and various other pdfs with type1 fonts.
  30156. var HINTING_ENABLED = false;
  30157. // Accented charactars are not displayed properly on windows, using this flag
  30158. // to control analysis of seac charstrings.
  30159. var SEAC_ANALYSIS_ENABLED = false;
  30160. var FontFlags = {
  30161. FixedPitch: 1,
  30162. Serif: 2,
  30163. Symbolic: 4,
  30164. Script: 8,
  30165. Nonsymbolic: 32,
  30166. Italic: 64,
  30167. AllCap: 65536,
  30168. SmallCap: 131072,
  30169. ForceBold: 262144
  30170. };
  30171. var Encodings = {
  30172. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30173. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30174. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  30175. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  30176. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  30177. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  30178. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  30179. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  30180. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  30181. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  30182. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  30183. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  30184. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  30185. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  30186. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  30187. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  30188. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  30189. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  30190. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  30191. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30192. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  30193. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  30194. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  30195. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  30196. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  30197. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  30198. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  30199. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  30200. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  30201. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  30202. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  30203. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  30204. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  30205. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  30206. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  30207. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  30208. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  30209. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  30210. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  30211. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  30212. 'Ydieresissmall'],
  30213. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30214. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30215. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  30216. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  30217. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  30218. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  30219. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  30220. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  30221. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  30222. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  30223. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  30224. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  30225. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  30226. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  30227. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  30228. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  30229. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  30230. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  30231. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  30232. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  30233. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  30234. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  30235. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  30236. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  30237. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  30238. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  30239. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  30240. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  30241. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  30242. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  30243. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  30244. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  30245. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  30246. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  30247. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  30248. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  30249. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  30250. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  30251. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  30252. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  30253. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30254. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30255. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30256. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30257. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30258. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30259. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30260. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30261. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30262. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30263. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30264. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  30265. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  30266. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  30267. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30268. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  30269. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  30270. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  30271. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  30272. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  30273. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  30274. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  30275. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  30276. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  30277. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  30278. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  30279. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  30280. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  30281. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  30282. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  30283. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  30284. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  30285. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  30286. 'ogonek', 'caron'],
  30287. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30288. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30289. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30290. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  30291. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30292. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30293. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30294. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30295. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30296. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  30297. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  30298. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30299. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30300. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  30301. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  30302. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  30303. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  30304. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  30305. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  30306. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  30307. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  30308. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  30309. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  30310. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  30311. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  30312. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30313. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30314. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30315. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30316. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30317. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30318. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30319. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30320. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30321. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30322. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30323. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30324. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  30325. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  30326. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  30327. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  30328. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  30329. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  30330. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  30331. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  30332. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  30333. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  30334. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  30335. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  30336. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  30337. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  30338. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  30339. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  30340. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  30341. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  30342. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  30343. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  30344. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  30345. 'ydieresis'],
  30346. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30347. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30348. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  30349. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  30350. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  30351. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  30352. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  30353. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  30354. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  30355. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  30356. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  30357. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  30358. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  30359. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  30360. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  30361. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30362. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  30363. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  30364. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  30365. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  30366. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  30367. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  30368. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  30369. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  30370. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  30371. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  30372. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  30373. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  30374. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  30375. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  30376. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  30377. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  30378. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  30379. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  30380. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  30381. 'bracerightbt'],
  30382. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30383. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30384. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  30385. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  30386. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  30387. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  30388. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  30389. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  30390. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  30391. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  30392. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  30393. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  30394. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  30395. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  30396. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  30397. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  30398. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  30399. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  30400. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  30401. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  30402. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  30403. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  30404. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  30405. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  30406. };
  30407. /**
  30408. * Hold a map of decoded fonts and of the standard fourteen Type1
  30409. * fonts and their acronyms.
  30410. */
  30411. var stdFontMap = {
  30412. 'ArialNarrow': 'Helvetica',
  30413. 'ArialNarrow-Bold': 'Helvetica-Bold',
  30414. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  30415. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  30416. 'ArialBlack': 'Helvetica',
  30417. 'ArialBlack-Bold': 'Helvetica-Bold',
  30418. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  30419. 'ArialBlack-Italic': 'Helvetica-Oblique',
  30420. 'Arial': 'Helvetica',
  30421. 'Arial-Bold': 'Helvetica-Bold',
  30422. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  30423. 'Arial-Italic': 'Helvetica-Oblique',
  30424. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  30425. 'Arial-BoldMT': 'Helvetica-Bold',
  30426. 'Arial-ItalicMT': 'Helvetica-Oblique',
  30427. 'ArialMT': 'Helvetica',
  30428. 'Courier-Bold': 'Courier-Bold',
  30429. 'Courier-BoldItalic': 'Courier-BoldOblique',
  30430. 'Courier-Italic': 'Courier-Oblique',
  30431. 'CourierNew': 'Courier',
  30432. 'CourierNew-Bold': 'Courier-Bold',
  30433. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  30434. 'CourierNew-Italic': 'Courier-Oblique',
  30435. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  30436. 'CourierNewPS-BoldMT': 'Courier-Bold',
  30437. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  30438. 'CourierNewPSMT': 'Courier',
  30439. 'Helvetica': 'Helvetica',
  30440. 'Helvetica-Bold': 'Helvetica-Bold',
  30441. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  30442. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  30443. 'Helvetica-Italic': 'Helvetica-Oblique',
  30444. 'Helvetica-Oblique':'Helvetica-Oblique',
  30445. 'Symbol-Bold': 'Symbol',
  30446. 'Symbol-BoldItalic': 'Symbol',
  30447. 'Symbol-Italic': 'Symbol',
  30448. 'TimesNewRoman': 'Times-Roman',
  30449. 'TimesNewRoman-Bold': 'Times-Bold',
  30450. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  30451. 'TimesNewRoman-Italic': 'Times-Italic',
  30452. 'TimesNewRomanPS': 'Times-Roman',
  30453. 'TimesNewRomanPS-Bold': 'Times-Bold',
  30454. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  30455. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  30456. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  30457. 'TimesNewRomanPS-Italic': 'Times-Italic',
  30458. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  30459. 'TimesNewRomanPSMT': 'Times-Roman',
  30460. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  30461. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  30462. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  30463. };
  30464. /**
  30465. * Holds the map of the non-standard fonts that might be included as a standard
  30466. * fonts without glyph data.
  30467. */
  30468. var nonStdFontMap = {
  30469. 'CenturyGothic': 'Helvetica',
  30470. 'CenturyGothic-Bold': 'Helvetica-Bold',
  30471. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  30472. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  30473. 'ComicSansMS': 'Comic Sans MS',
  30474. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  30475. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  30476. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  30477. 'LucidaConsole': 'Courier',
  30478. 'LucidaConsole-Bold': 'Courier-Bold',
  30479. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  30480. 'LucidaConsole-Italic': 'Courier-Oblique',
  30481. 'MS-Gothic': 'MS Gothic',
  30482. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  30483. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  30484. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  30485. 'MS-Mincho': 'MS Mincho',
  30486. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  30487. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  30488. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  30489. 'MS-PGothic': 'MS PGothic',
  30490. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  30491. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  30492. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  30493. 'MS-PMincho': 'MS PMincho',
  30494. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  30495. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  30496. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  30497. 'Wingdings': 'ZapfDingbats'
  30498. };
  30499. var serifFonts = {
  30500. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  30501. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  30502. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  30503. 'Arno': true, 'Aster': true, 'Aurora': true,
  30504. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  30505. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  30506. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  30507. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  30508. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  30509. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  30510. 'Cartier': true, 'Caslon': true, 'Catull': true,
  30511. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  30512. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  30513. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  30514. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  30515. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  30516. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  30517. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  30518. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  30519. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  30520. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  30521. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  30522. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  30523. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  30524. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  30525. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  30526. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  30527. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  30528. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  30529. 'Miller': true, 'Minion': true, 'Modern': true,
  30530. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  30531. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  30532. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  30533. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  30534. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  30535. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  30536. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  30537. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  30538. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  30539. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  30540. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  30541. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  30542. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  30543. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  30544. };
  30545. var symbolsFonts = {
  30546. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  30547. };
  30548. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  30549. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  30550. // glyphs, but common for some set of the standard fonts.
  30551. var GlyphMapForStandardFonts = {
  30552. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  30553. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  30554. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  30555. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  30556. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  30557. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  30558. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  30559. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  30560. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  30561. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  30562. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  30563. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  30564. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  30565. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  30566. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  30567. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  30568. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  30569. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  30570. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  30571. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  30572. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  30573. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  30574. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  30575. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  30576. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  30577. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  30578. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  30579. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  30580. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  30581. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  30582. '298': 380, '305': 963,
  30583. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  30584. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  30585. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  30586. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  30587. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  30588. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  30589. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  30590. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  30591. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  30592. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  30593. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  30594. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  30595. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  30596. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  30597. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  30598. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  30599. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  30600. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  30601. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  30602. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  30603. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  30604. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  30605. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  30606. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  30607. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  30608. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  30609. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  30610. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  30611. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  30612. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  30613. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  30614. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  30615. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  30616. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  30617. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  30618. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  30619. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  30620. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  30621. };
  30622. // The glyph map for ArialBlack differs slightly from the glyph map used for
  30623. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  30624. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  30625. var SupplementalGlyphMapForArialBlack = {
  30626. '227': 322, '264': 261, '291': 346,
  30627. };
  30628. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  30629. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  30630. // to the similar equivalents in the normal characters range.
  30631. var SpecialPUASymbols = {
  30632. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  30633. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  30634. '63720': 0x00AE, // registersans (0xF8E8) => registered
  30635. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  30636. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  30637. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  30638. '63729': 0x23A7, // bracelefttp (0xF8F1)
  30639. '63730': 0x23A8, // braceleftmid (0xF8F2)
  30640. '63731': 0x23A9, // braceleftbt (0xF8F3)
  30641. '63740': 0x23AB, // bracerighttp (0xF8FC)
  30642. '63741': 0x23AC, // bracerightmid (0xF8FD)
  30643. '63742': 0x23AD, // bracerightbt (0xF8FE)
  30644. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  30645. '63727': 0x23A2, // bracketleftex (0xF8EF)
  30646. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  30647. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  30648. '63738': 0x23A5, // bracketrightex (0xF8FA)
  30649. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  30650. '63723': 0x239B, // parenlefttp (0xF8EB)
  30651. '63724': 0x239C, // parenleftex (0xF8EC)
  30652. '63725': 0x239D, // parenleftbt (0xF8ED)
  30653. '63734': 0x239E, // parenrighttp (0xF8F6)
  30654. '63735': 0x239F, // parenrightex (0xF8F7)
  30655. '63736': 0x23A0, // parenrightbt (0xF8F8)
  30656. };
  30657. function mapSpecialUnicodeValues(code) {
  30658. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  30659. return 0;
  30660. } else if (code >= 0xF600 && code <= 0xF8FF) {
  30661. return (SpecialPUASymbols[code] || code);
  30662. }
  30663. return code;
  30664. }
  30665. var UnicodeRanges = [
  30666. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  30667. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  30668. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  30669. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  30670. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  30671. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  30672. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  30673. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  30674. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  30675. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  30676. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  30677. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  30678. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  30679. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  30680. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  30681. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  30682. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  30683. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  30684. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  30685. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  30686. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  30687. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  30688. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  30689. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  30690. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  30691. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  30692. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  30693. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  30694. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  30695. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  30696. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  30697. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  30698. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  30699. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  30700. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  30701. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  30702. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  30703. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  30704. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  30705. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  30706. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  30707. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  30708. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  30709. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  30710. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  30711. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  30712. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  30713. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  30714. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  30715. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  30716. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  30717. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  30718. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  30719. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  30720. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  30721. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  30722. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  30723. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  30724. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  30725. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  30726. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  30727. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  30728. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  30729. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  30730. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  30731. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  30732. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  30733. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  30734. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  30735. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  30736. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  30737. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  30738. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  30739. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  30740. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  30741. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  30742. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  30743. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  30744. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  30745. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  30746. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  30747. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  30748. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  30749. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  30750. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  30751. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  30752. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  30753. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  30754. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  30755. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  30756. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  30757. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  30758. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  30759. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  30760. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  30761. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  30762. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  30763. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  30764. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  30765. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  30766. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  30767. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  30768. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  30769. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  30770. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  30771. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  30772. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  30773. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  30774. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  30775. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  30776. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  30777. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  30778. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  30779. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  30780. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  30781. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  30782. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  30783. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  30784. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  30785. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  30786. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  30787. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  30788. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  30789. ];
  30790. var MacStandardGlyphOrdering = [
  30791. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30792. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30793. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30794. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30795. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30796. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30797. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30798. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30799. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30800. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30801. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30802. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30803. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30804. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30805. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30806. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30807. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30808. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30809. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30810. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30811. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30812. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30813. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30814. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30815. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30816. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30817. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30818. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30819. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30820. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30821. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30822. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30823. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30824. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30825. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30826. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30827. function getUnicodeRangeFor(value) {
  30828. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  30829. var range = UnicodeRanges[i];
  30830. if (value >= range.begin && value < range.end) {
  30831. return i;
  30832. }
  30833. }
  30834. return -1;
  30835. }
  30836. function isRTLRangeFor(value) {
  30837. var range = UnicodeRanges[13];
  30838. if (value >= range.begin && value < range.end) {
  30839. return true;
  30840. }
  30841. range = UnicodeRanges[11];
  30842. if (value >= range.begin && value < range.end) {
  30843. return true;
  30844. }
  30845. return false;
  30846. }
  30847. // The normalization table is obtained by filtering the Unicode characters
  30848. // database with <compat> entries.
  30849. var NormalizedUnicodes = {
  30850. '\u00A8': '\u0020\u0308',
  30851. '\u00AF': '\u0020\u0304',
  30852. '\u00B4': '\u0020\u0301',
  30853. '\u00B5': '\u03BC',
  30854. '\u00B8': '\u0020\u0327',
  30855. '\u0132': '\u0049\u004A',
  30856. '\u0133': '\u0069\u006A',
  30857. '\u013F': '\u004C\u00B7',
  30858. '\u0140': '\u006C\u00B7',
  30859. '\u0149': '\u02BC\u006E',
  30860. '\u017F': '\u0073',
  30861. '\u01C4': '\u0044\u017D',
  30862. '\u01C5': '\u0044\u017E',
  30863. '\u01C6': '\u0064\u017E',
  30864. '\u01C7': '\u004C\u004A',
  30865. '\u01C8': '\u004C\u006A',
  30866. '\u01C9': '\u006C\u006A',
  30867. '\u01CA': '\u004E\u004A',
  30868. '\u01CB': '\u004E\u006A',
  30869. '\u01CC': '\u006E\u006A',
  30870. '\u01F1': '\u0044\u005A',
  30871. '\u01F2': '\u0044\u007A',
  30872. '\u01F3': '\u0064\u007A',
  30873. '\u02D8': '\u0020\u0306',
  30874. '\u02D9': '\u0020\u0307',
  30875. '\u02DA': '\u0020\u030A',
  30876. '\u02DB': '\u0020\u0328',
  30877. '\u02DC': '\u0020\u0303',
  30878. '\u02DD': '\u0020\u030B',
  30879. '\u037A': '\u0020\u0345',
  30880. '\u0384': '\u0020\u0301',
  30881. '\u03D0': '\u03B2',
  30882. '\u03D1': '\u03B8',
  30883. '\u03D2': '\u03A5',
  30884. '\u03D5': '\u03C6',
  30885. '\u03D6': '\u03C0',
  30886. '\u03F0': '\u03BA',
  30887. '\u03F1': '\u03C1',
  30888. '\u03F2': '\u03C2',
  30889. '\u03F4': '\u0398',
  30890. '\u03F5': '\u03B5',
  30891. '\u03F9': '\u03A3',
  30892. '\u0587': '\u0565\u0582',
  30893. '\u0675': '\u0627\u0674',
  30894. '\u0676': '\u0648\u0674',
  30895. '\u0677': '\u06C7\u0674',
  30896. '\u0678': '\u064A\u0674',
  30897. '\u0E33': '\u0E4D\u0E32',
  30898. '\u0EB3': '\u0ECD\u0EB2',
  30899. '\u0EDC': '\u0EAB\u0E99',
  30900. '\u0EDD': '\u0EAB\u0EA1',
  30901. '\u0F77': '\u0FB2\u0F81',
  30902. '\u0F79': '\u0FB3\u0F81',
  30903. '\u1E9A': '\u0061\u02BE',
  30904. '\u1FBD': '\u0020\u0313',
  30905. '\u1FBF': '\u0020\u0313',
  30906. '\u1FC0': '\u0020\u0342',
  30907. '\u1FFE': '\u0020\u0314',
  30908. '\u2002': '\u0020',
  30909. '\u2003': '\u0020',
  30910. '\u2004': '\u0020',
  30911. '\u2005': '\u0020',
  30912. '\u2006': '\u0020',
  30913. '\u2008': '\u0020',
  30914. '\u2009': '\u0020',
  30915. '\u200A': '\u0020',
  30916. '\u2017': '\u0020\u0333',
  30917. '\u2024': '\u002E',
  30918. '\u2025': '\u002E\u002E',
  30919. '\u2026': '\u002E\u002E\u002E',
  30920. '\u2033': '\u2032\u2032',
  30921. '\u2034': '\u2032\u2032\u2032',
  30922. '\u2036': '\u2035\u2035',
  30923. '\u2037': '\u2035\u2035\u2035',
  30924. '\u203C': '\u0021\u0021',
  30925. '\u203E': '\u0020\u0305',
  30926. '\u2047': '\u003F\u003F',
  30927. '\u2048': '\u003F\u0021',
  30928. '\u2049': '\u0021\u003F',
  30929. '\u2057': '\u2032\u2032\u2032\u2032',
  30930. '\u205F': '\u0020',
  30931. '\u20A8': '\u0052\u0073',
  30932. '\u2100': '\u0061\u002F\u0063',
  30933. '\u2101': '\u0061\u002F\u0073',
  30934. '\u2103': '\u00B0\u0043',
  30935. '\u2105': '\u0063\u002F\u006F',
  30936. '\u2106': '\u0063\u002F\u0075',
  30937. '\u2107': '\u0190',
  30938. '\u2109': '\u00B0\u0046',
  30939. '\u2116': '\u004E\u006F',
  30940. '\u2121': '\u0054\u0045\u004C',
  30941. '\u2135': '\u05D0',
  30942. '\u2136': '\u05D1',
  30943. '\u2137': '\u05D2',
  30944. '\u2138': '\u05D3',
  30945. '\u213B': '\u0046\u0041\u0058',
  30946. '\u2160': '\u0049',
  30947. '\u2161': '\u0049\u0049',
  30948. '\u2162': '\u0049\u0049\u0049',
  30949. '\u2163': '\u0049\u0056',
  30950. '\u2164': '\u0056',
  30951. '\u2165': '\u0056\u0049',
  30952. '\u2166': '\u0056\u0049\u0049',
  30953. '\u2167': '\u0056\u0049\u0049\u0049',
  30954. '\u2168': '\u0049\u0058',
  30955. '\u2169': '\u0058',
  30956. '\u216A': '\u0058\u0049',
  30957. '\u216B': '\u0058\u0049\u0049',
  30958. '\u216C': '\u004C',
  30959. '\u216D': '\u0043',
  30960. '\u216E': '\u0044',
  30961. '\u216F': '\u004D',
  30962. '\u2170': '\u0069',
  30963. '\u2171': '\u0069\u0069',
  30964. '\u2172': '\u0069\u0069\u0069',
  30965. '\u2173': '\u0069\u0076',
  30966. '\u2174': '\u0076',
  30967. '\u2175': '\u0076\u0069',
  30968. '\u2176': '\u0076\u0069\u0069',
  30969. '\u2177': '\u0076\u0069\u0069\u0069',
  30970. '\u2178': '\u0069\u0078',
  30971. '\u2179': '\u0078',
  30972. '\u217A': '\u0078\u0069',
  30973. '\u217B': '\u0078\u0069\u0069',
  30974. '\u217C': '\u006C',
  30975. '\u217D': '\u0063',
  30976. '\u217E': '\u0064',
  30977. '\u217F': '\u006D',
  30978. '\u222C': '\u222B\u222B',
  30979. '\u222D': '\u222B\u222B\u222B',
  30980. '\u222F': '\u222E\u222E',
  30981. '\u2230': '\u222E\u222E\u222E',
  30982. '\u2474': '\u0028\u0031\u0029',
  30983. '\u2475': '\u0028\u0032\u0029',
  30984. '\u2476': '\u0028\u0033\u0029',
  30985. '\u2477': '\u0028\u0034\u0029',
  30986. '\u2478': '\u0028\u0035\u0029',
  30987. '\u2479': '\u0028\u0036\u0029',
  30988. '\u247A': '\u0028\u0037\u0029',
  30989. '\u247B': '\u0028\u0038\u0029',
  30990. '\u247C': '\u0028\u0039\u0029',
  30991. '\u247D': '\u0028\u0031\u0030\u0029',
  30992. '\u247E': '\u0028\u0031\u0031\u0029',
  30993. '\u247F': '\u0028\u0031\u0032\u0029',
  30994. '\u2480': '\u0028\u0031\u0033\u0029',
  30995. '\u2481': '\u0028\u0031\u0034\u0029',
  30996. '\u2482': '\u0028\u0031\u0035\u0029',
  30997. '\u2483': '\u0028\u0031\u0036\u0029',
  30998. '\u2484': '\u0028\u0031\u0037\u0029',
  30999. '\u2485': '\u0028\u0031\u0038\u0029',
  31000. '\u2486': '\u0028\u0031\u0039\u0029',
  31001. '\u2487': '\u0028\u0032\u0030\u0029',
  31002. '\u2488': '\u0031\u002E',
  31003. '\u2489': '\u0032\u002E',
  31004. '\u248A': '\u0033\u002E',
  31005. '\u248B': '\u0034\u002E',
  31006. '\u248C': '\u0035\u002E',
  31007. '\u248D': '\u0036\u002E',
  31008. '\u248E': '\u0037\u002E',
  31009. '\u248F': '\u0038\u002E',
  31010. '\u2490': '\u0039\u002E',
  31011. '\u2491': '\u0031\u0030\u002E',
  31012. '\u2492': '\u0031\u0031\u002E',
  31013. '\u2493': '\u0031\u0032\u002E',
  31014. '\u2494': '\u0031\u0033\u002E',
  31015. '\u2495': '\u0031\u0034\u002E',
  31016. '\u2496': '\u0031\u0035\u002E',
  31017. '\u2497': '\u0031\u0036\u002E',
  31018. '\u2498': '\u0031\u0037\u002E',
  31019. '\u2499': '\u0031\u0038\u002E',
  31020. '\u249A': '\u0031\u0039\u002E',
  31021. '\u249B': '\u0032\u0030\u002E',
  31022. '\u249C': '\u0028\u0061\u0029',
  31023. '\u249D': '\u0028\u0062\u0029',
  31024. '\u249E': '\u0028\u0063\u0029',
  31025. '\u249F': '\u0028\u0064\u0029',
  31026. '\u24A0': '\u0028\u0065\u0029',
  31027. '\u24A1': '\u0028\u0066\u0029',
  31028. '\u24A2': '\u0028\u0067\u0029',
  31029. '\u24A3': '\u0028\u0068\u0029',
  31030. '\u24A4': '\u0028\u0069\u0029',
  31031. '\u24A5': '\u0028\u006A\u0029',
  31032. '\u24A6': '\u0028\u006B\u0029',
  31033. '\u24A7': '\u0028\u006C\u0029',
  31034. '\u24A8': '\u0028\u006D\u0029',
  31035. '\u24A9': '\u0028\u006E\u0029',
  31036. '\u24AA': '\u0028\u006F\u0029',
  31037. '\u24AB': '\u0028\u0070\u0029',
  31038. '\u24AC': '\u0028\u0071\u0029',
  31039. '\u24AD': '\u0028\u0072\u0029',
  31040. '\u24AE': '\u0028\u0073\u0029',
  31041. '\u24AF': '\u0028\u0074\u0029',
  31042. '\u24B0': '\u0028\u0075\u0029',
  31043. '\u24B1': '\u0028\u0076\u0029',
  31044. '\u24B2': '\u0028\u0077\u0029',
  31045. '\u24B3': '\u0028\u0078\u0029',
  31046. '\u24B4': '\u0028\u0079\u0029',
  31047. '\u24B5': '\u0028\u007A\u0029',
  31048. '\u2A0C': '\u222B\u222B\u222B\u222B',
  31049. '\u2A74': '\u003A\u003A\u003D',
  31050. '\u2A75': '\u003D\u003D',
  31051. '\u2A76': '\u003D\u003D\u003D',
  31052. '\u2E9F': '\u6BCD',
  31053. '\u2EF3': '\u9F9F',
  31054. '\u2F00': '\u4E00',
  31055. '\u2F01': '\u4E28',
  31056. '\u2F02': '\u4E36',
  31057. '\u2F03': '\u4E3F',
  31058. '\u2F04': '\u4E59',
  31059. '\u2F05': '\u4E85',
  31060. '\u2F06': '\u4E8C',
  31061. '\u2F07': '\u4EA0',
  31062. '\u2F08': '\u4EBA',
  31063. '\u2F09': '\u513F',
  31064. '\u2F0A': '\u5165',
  31065. '\u2F0B': '\u516B',
  31066. '\u2F0C': '\u5182',
  31067. '\u2F0D': '\u5196',
  31068. '\u2F0E': '\u51AB',
  31069. '\u2F0F': '\u51E0',
  31070. '\u2F10': '\u51F5',
  31071. '\u2F11': '\u5200',
  31072. '\u2F12': '\u529B',
  31073. '\u2F13': '\u52F9',
  31074. '\u2F14': '\u5315',
  31075. '\u2F15': '\u531A',
  31076. '\u2F16': '\u5338',
  31077. '\u2F17': '\u5341',
  31078. '\u2F18': '\u535C',
  31079. '\u2F19': '\u5369',
  31080. '\u2F1A': '\u5382',
  31081. '\u2F1B': '\u53B6',
  31082. '\u2F1C': '\u53C8',
  31083. '\u2F1D': '\u53E3',
  31084. '\u2F1E': '\u56D7',
  31085. '\u2F1F': '\u571F',
  31086. '\u2F20': '\u58EB',
  31087. '\u2F21': '\u5902',
  31088. '\u2F22': '\u590A',
  31089. '\u2F23': '\u5915',
  31090. '\u2F24': '\u5927',
  31091. '\u2F25': '\u5973',
  31092. '\u2F26': '\u5B50',
  31093. '\u2F27': '\u5B80',
  31094. '\u2F28': '\u5BF8',
  31095. '\u2F29': '\u5C0F',
  31096. '\u2F2A': '\u5C22',
  31097. '\u2F2B': '\u5C38',
  31098. '\u2F2C': '\u5C6E',
  31099. '\u2F2D': '\u5C71',
  31100. '\u2F2E': '\u5DDB',
  31101. '\u2F2F': '\u5DE5',
  31102. '\u2F30': '\u5DF1',
  31103. '\u2F31': '\u5DFE',
  31104. '\u2F32': '\u5E72',
  31105. '\u2F33': '\u5E7A',
  31106. '\u2F34': '\u5E7F',
  31107. '\u2F35': '\u5EF4',
  31108. '\u2F36': '\u5EFE',
  31109. '\u2F37': '\u5F0B',
  31110. '\u2F38': '\u5F13',
  31111. '\u2F39': '\u5F50',
  31112. '\u2F3A': '\u5F61',
  31113. '\u2F3B': '\u5F73',
  31114. '\u2F3C': '\u5FC3',
  31115. '\u2F3D': '\u6208',
  31116. '\u2F3E': '\u6236',
  31117. '\u2F3F': '\u624B',
  31118. '\u2F40': '\u652F',
  31119. '\u2F41': '\u6534',
  31120. '\u2F42': '\u6587',
  31121. '\u2F43': '\u6597',
  31122. '\u2F44': '\u65A4',
  31123. '\u2F45': '\u65B9',
  31124. '\u2F46': '\u65E0',
  31125. '\u2F47': '\u65E5',
  31126. '\u2F48': '\u66F0',
  31127. '\u2F49': '\u6708',
  31128. '\u2F4A': '\u6728',
  31129. '\u2F4B': '\u6B20',
  31130. '\u2F4C': '\u6B62',
  31131. '\u2F4D': '\u6B79',
  31132. '\u2F4E': '\u6BB3',
  31133. '\u2F4F': '\u6BCB',
  31134. '\u2F50': '\u6BD4',
  31135. '\u2F51': '\u6BDB',
  31136. '\u2F52': '\u6C0F',
  31137. '\u2F53': '\u6C14',
  31138. '\u2F54': '\u6C34',
  31139. '\u2F55': '\u706B',
  31140. '\u2F56': '\u722A',
  31141. '\u2F57': '\u7236',
  31142. '\u2F58': '\u723B',
  31143. '\u2F59': '\u723F',
  31144. '\u2F5A': '\u7247',
  31145. '\u2F5B': '\u7259',
  31146. '\u2F5C': '\u725B',
  31147. '\u2F5D': '\u72AC',
  31148. '\u2F5E': '\u7384',
  31149. '\u2F5F': '\u7389',
  31150. '\u2F60': '\u74DC',
  31151. '\u2F61': '\u74E6',
  31152. '\u2F62': '\u7518',
  31153. '\u2F63': '\u751F',
  31154. '\u2F64': '\u7528',
  31155. '\u2F65': '\u7530',
  31156. '\u2F66': '\u758B',
  31157. '\u2F67': '\u7592',
  31158. '\u2F68': '\u7676',
  31159. '\u2F69': '\u767D',
  31160. '\u2F6A': '\u76AE',
  31161. '\u2F6B': '\u76BF',
  31162. '\u2F6C': '\u76EE',
  31163. '\u2F6D': '\u77DB',
  31164. '\u2F6E': '\u77E2',
  31165. '\u2F6F': '\u77F3',
  31166. '\u2F70': '\u793A',
  31167. '\u2F71': '\u79B8',
  31168. '\u2F72': '\u79BE',
  31169. '\u2F73': '\u7A74',
  31170. '\u2F74': '\u7ACB',
  31171. '\u2F75': '\u7AF9',
  31172. '\u2F76': '\u7C73',
  31173. '\u2F77': '\u7CF8',
  31174. '\u2F78': '\u7F36',
  31175. '\u2F79': '\u7F51',
  31176. '\u2F7A': '\u7F8A',
  31177. '\u2F7B': '\u7FBD',
  31178. '\u2F7C': '\u8001',
  31179. '\u2F7D': '\u800C',
  31180. '\u2F7E': '\u8012',
  31181. '\u2F7F': '\u8033',
  31182. '\u2F80': '\u807F',
  31183. '\u2F81': '\u8089',
  31184. '\u2F82': '\u81E3',
  31185. '\u2F83': '\u81EA',
  31186. '\u2F84': '\u81F3',
  31187. '\u2F85': '\u81FC',
  31188. '\u2F86': '\u820C',
  31189. '\u2F87': '\u821B',
  31190. '\u2F88': '\u821F',
  31191. '\u2F89': '\u826E',
  31192. '\u2F8A': '\u8272',
  31193. '\u2F8B': '\u8278',
  31194. '\u2F8C': '\u864D',
  31195. '\u2F8D': '\u866B',
  31196. '\u2F8E': '\u8840',
  31197. '\u2F8F': '\u884C',
  31198. '\u2F90': '\u8863',
  31199. '\u2F91': '\u897E',
  31200. '\u2F92': '\u898B',
  31201. '\u2F93': '\u89D2',
  31202. '\u2F94': '\u8A00',
  31203. '\u2F95': '\u8C37',
  31204. '\u2F96': '\u8C46',
  31205. '\u2F97': '\u8C55',
  31206. '\u2F98': '\u8C78',
  31207. '\u2F99': '\u8C9D',
  31208. '\u2F9A': '\u8D64',
  31209. '\u2F9B': '\u8D70',
  31210. '\u2F9C': '\u8DB3',
  31211. '\u2F9D': '\u8EAB',
  31212. '\u2F9E': '\u8ECA',
  31213. '\u2F9F': '\u8F9B',
  31214. '\u2FA0': '\u8FB0',
  31215. '\u2FA1': '\u8FB5',
  31216. '\u2FA2': '\u9091',
  31217. '\u2FA3': '\u9149',
  31218. '\u2FA4': '\u91C6',
  31219. '\u2FA5': '\u91CC',
  31220. '\u2FA6': '\u91D1',
  31221. '\u2FA7': '\u9577',
  31222. '\u2FA8': '\u9580',
  31223. '\u2FA9': '\u961C',
  31224. '\u2FAA': '\u96B6',
  31225. '\u2FAB': '\u96B9',
  31226. '\u2FAC': '\u96E8',
  31227. '\u2FAD': '\u9751',
  31228. '\u2FAE': '\u975E',
  31229. '\u2FAF': '\u9762',
  31230. '\u2FB0': '\u9769',
  31231. '\u2FB1': '\u97CB',
  31232. '\u2FB2': '\u97ED',
  31233. '\u2FB3': '\u97F3',
  31234. '\u2FB4': '\u9801',
  31235. '\u2FB5': '\u98A8',
  31236. '\u2FB6': '\u98DB',
  31237. '\u2FB7': '\u98DF',
  31238. '\u2FB8': '\u9996',
  31239. '\u2FB9': '\u9999',
  31240. '\u2FBA': '\u99AC',
  31241. '\u2FBB': '\u9AA8',
  31242. '\u2FBC': '\u9AD8',
  31243. '\u2FBD': '\u9ADF',
  31244. '\u2FBE': '\u9B25',
  31245. '\u2FBF': '\u9B2F',
  31246. '\u2FC0': '\u9B32',
  31247. '\u2FC1': '\u9B3C',
  31248. '\u2FC2': '\u9B5A',
  31249. '\u2FC3': '\u9CE5',
  31250. '\u2FC4': '\u9E75',
  31251. '\u2FC5': '\u9E7F',
  31252. '\u2FC6': '\u9EA5',
  31253. '\u2FC7': '\u9EBB',
  31254. '\u2FC8': '\u9EC3',
  31255. '\u2FC9': '\u9ECD',
  31256. '\u2FCA': '\u9ED1',
  31257. '\u2FCB': '\u9EF9',
  31258. '\u2FCC': '\u9EFD',
  31259. '\u2FCD': '\u9F0E',
  31260. '\u2FCE': '\u9F13',
  31261. '\u2FCF': '\u9F20',
  31262. '\u2FD0': '\u9F3B',
  31263. '\u2FD1': '\u9F4A',
  31264. '\u2FD2': '\u9F52',
  31265. '\u2FD3': '\u9F8D',
  31266. '\u2FD4': '\u9F9C',
  31267. '\u2FD5': '\u9FA0',
  31268. '\u3036': '\u3012',
  31269. '\u3038': '\u5341',
  31270. '\u3039': '\u5344',
  31271. '\u303A': '\u5345',
  31272. '\u309B': '\u0020\u3099',
  31273. '\u309C': '\u0020\u309A',
  31274. '\u3131': '\u1100',
  31275. '\u3132': '\u1101',
  31276. '\u3133': '\u11AA',
  31277. '\u3134': '\u1102',
  31278. '\u3135': '\u11AC',
  31279. '\u3136': '\u11AD',
  31280. '\u3137': '\u1103',
  31281. '\u3138': '\u1104',
  31282. '\u3139': '\u1105',
  31283. '\u313A': '\u11B0',
  31284. '\u313B': '\u11B1',
  31285. '\u313C': '\u11B2',
  31286. '\u313D': '\u11B3',
  31287. '\u313E': '\u11B4',
  31288. '\u313F': '\u11B5',
  31289. '\u3140': '\u111A',
  31290. '\u3141': '\u1106',
  31291. '\u3142': '\u1107',
  31292. '\u3143': '\u1108',
  31293. '\u3144': '\u1121',
  31294. '\u3145': '\u1109',
  31295. '\u3146': '\u110A',
  31296. '\u3147': '\u110B',
  31297. '\u3148': '\u110C',
  31298. '\u3149': '\u110D',
  31299. '\u314A': '\u110E',
  31300. '\u314B': '\u110F',
  31301. '\u314C': '\u1110',
  31302. '\u314D': '\u1111',
  31303. '\u314E': '\u1112',
  31304. '\u314F': '\u1161',
  31305. '\u3150': '\u1162',
  31306. '\u3151': '\u1163',
  31307. '\u3152': '\u1164',
  31308. '\u3153': '\u1165',
  31309. '\u3154': '\u1166',
  31310. '\u3155': '\u1167',
  31311. '\u3156': '\u1168',
  31312. '\u3157': '\u1169',
  31313. '\u3158': '\u116A',
  31314. '\u3159': '\u116B',
  31315. '\u315A': '\u116C',
  31316. '\u315B': '\u116D',
  31317. '\u315C': '\u116E',
  31318. '\u315D': '\u116F',
  31319. '\u315E': '\u1170',
  31320. '\u315F': '\u1171',
  31321. '\u3160': '\u1172',
  31322. '\u3161': '\u1173',
  31323. '\u3162': '\u1174',
  31324. '\u3163': '\u1175',
  31325. '\u3164': '\u1160',
  31326. '\u3165': '\u1114',
  31327. '\u3166': '\u1115',
  31328. '\u3167': '\u11C7',
  31329. '\u3168': '\u11C8',
  31330. '\u3169': '\u11CC',
  31331. '\u316A': '\u11CE',
  31332. '\u316B': '\u11D3',
  31333. '\u316C': '\u11D7',
  31334. '\u316D': '\u11D9',
  31335. '\u316E': '\u111C',
  31336. '\u316F': '\u11DD',
  31337. '\u3170': '\u11DF',
  31338. '\u3171': '\u111D',
  31339. '\u3172': '\u111E',
  31340. '\u3173': '\u1120',
  31341. '\u3174': '\u1122',
  31342. '\u3175': '\u1123',
  31343. '\u3176': '\u1127',
  31344. '\u3177': '\u1129',
  31345. '\u3178': '\u112B',
  31346. '\u3179': '\u112C',
  31347. '\u317A': '\u112D',
  31348. '\u317B': '\u112E',
  31349. '\u317C': '\u112F',
  31350. '\u317D': '\u1132',
  31351. '\u317E': '\u1136',
  31352. '\u317F': '\u1140',
  31353. '\u3180': '\u1147',
  31354. '\u3181': '\u114C',
  31355. '\u3182': '\u11F1',
  31356. '\u3183': '\u11F2',
  31357. '\u3184': '\u1157',
  31358. '\u3185': '\u1158',
  31359. '\u3186': '\u1159',
  31360. '\u3187': '\u1184',
  31361. '\u3188': '\u1185',
  31362. '\u3189': '\u1188',
  31363. '\u318A': '\u1191',
  31364. '\u318B': '\u1192',
  31365. '\u318C': '\u1194',
  31366. '\u318D': '\u119E',
  31367. '\u318E': '\u11A1',
  31368. '\u3200': '\u0028\u1100\u0029',
  31369. '\u3201': '\u0028\u1102\u0029',
  31370. '\u3202': '\u0028\u1103\u0029',
  31371. '\u3203': '\u0028\u1105\u0029',
  31372. '\u3204': '\u0028\u1106\u0029',
  31373. '\u3205': '\u0028\u1107\u0029',
  31374. '\u3206': '\u0028\u1109\u0029',
  31375. '\u3207': '\u0028\u110B\u0029',
  31376. '\u3208': '\u0028\u110C\u0029',
  31377. '\u3209': '\u0028\u110E\u0029',
  31378. '\u320A': '\u0028\u110F\u0029',
  31379. '\u320B': '\u0028\u1110\u0029',
  31380. '\u320C': '\u0028\u1111\u0029',
  31381. '\u320D': '\u0028\u1112\u0029',
  31382. '\u320E': '\u0028\u1100\u1161\u0029',
  31383. '\u320F': '\u0028\u1102\u1161\u0029',
  31384. '\u3210': '\u0028\u1103\u1161\u0029',
  31385. '\u3211': '\u0028\u1105\u1161\u0029',
  31386. '\u3212': '\u0028\u1106\u1161\u0029',
  31387. '\u3213': '\u0028\u1107\u1161\u0029',
  31388. '\u3214': '\u0028\u1109\u1161\u0029',
  31389. '\u3215': '\u0028\u110B\u1161\u0029',
  31390. '\u3216': '\u0028\u110C\u1161\u0029',
  31391. '\u3217': '\u0028\u110E\u1161\u0029',
  31392. '\u3218': '\u0028\u110F\u1161\u0029',
  31393. '\u3219': '\u0028\u1110\u1161\u0029',
  31394. '\u321A': '\u0028\u1111\u1161\u0029',
  31395. '\u321B': '\u0028\u1112\u1161\u0029',
  31396. '\u321C': '\u0028\u110C\u116E\u0029',
  31397. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  31398. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  31399. '\u3220': '\u0028\u4E00\u0029',
  31400. '\u3221': '\u0028\u4E8C\u0029',
  31401. '\u3222': '\u0028\u4E09\u0029',
  31402. '\u3223': '\u0028\u56DB\u0029',
  31403. '\u3224': '\u0028\u4E94\u0029',
  31404. '\u3225': '\u0028\u516D\u0029',
  31405. '\u3226': '\u0028\u4E03\u0029',
  31406. '\u3227': '\u0028\u516B\u0029',
  31407. '\u3228': '\u0028\u4E5D\u0029',
  31408. '\u3229': '\u0028\u5341\u0029',
  31409. '\u322A': '\u0028\u6708\u0029',
  31410. '\u322B': '\u0028\u706B\u0029',
  31411. '\u322C': '\u0028\u6C34\u0029',
  31412. '\u322D': '\u0028\u6728\u0029',
  31413. '\u322E': '\u0028\u91D1\u0029',
  31414. '\u322F': '\u0028\u571F\u0029',
  31415. '\u3230': '\u0028\u65E5\u0029',
  31416. '\u3231': '\u0028\u682A\u0029',
  31417. '\u3232': '\u0028\u6709\u0029',
  31418. '\u3233': '\u0028\u793E\u0029',
  31419. '\u3234': '\u0028\u540D\u0029',
  31420. '\u3235': '\u0028\u7279\u0029',
  31421. '\u3236': '\u0028\u8CA1\u0029',
  31422. '\u3237': '\u0028\u795D\u0029',
  31423. '\u3238': '\u0028\u52B4\u0029',
  31424. '\u3239': '\u0028\u4EE3\u0029',
  31425. '\u323A': '\u0028\u547C\u0029',
  31426. '\u323B': '\u0028\u5B66\u0029',
  31427. '\u323C': '\u0028\u76E3\u0029',
  31428. '\u323D': '\u0028\u4F01\u0029',
  31429. '\u323E': '\u0028\u8CC7\u0029',
  31430. '\u323F': '\u0028\u5354\u0029',
  31431. '\u3240': '\u0028\u796D\u0029',
  31432. '\u3241': '\u0028\u4F11\u0029',
  31433. '\u3242': '\u0028\u81EA\u0029',
  31434. '\u3243': '\u0028\u81F3\u0029',
  31435. '\u32C0': '\u0031\u6708',
  31436. '\u32C1': '\u0032\u6708',
  31437. '\u32C2': '\u0033\u6708',
  31438. '\u32C3': '\u0034\u6708',
  31439. '\u32C4': '\u0035\u6708',
  31440. '\u32C5': '\u0036\u6708',
  31441. '\u32C6': '\u0037\u6708',
  31442. '\u32C7': '\u0038\u6708',
  31443. '\u32C8': '\u0039\u6708',
  31444. '\u32C9': '\u0031\u0030\u6708',
  31445. '\u32CA': '\u0031\u0031\u6708',
  31446. '\u32CB': '\u0031\u0032\u6708',
  31447. '\u3358': '\u0030\u70B9',
  31448. '\u3359': '\u0031\u70B9',
  31449. '\u335A': '\u0032\u70B9',
  31450. '\u335B': '\u0033\u70B9',
  31451. '\u335C': '\u0034\u70B9',
  31452. '\u335D': '\u0035\u70B9',
  31453. '\u335E': '\u0036\u70B9',
  31454. '\u335F': '\u0037\u70B9',
  31455. '\u3360': '\u0038\u70B9',
  31456. '\u3361': '\u0039\u70B9',
  31457. '\u3362': '\u0031\u0030\u70B9',
  31458. '\u3363': '\u0031\u0031\u70B9',
  31459. '\u3364': '\u0031\u0032\u70B9',
  31460. '\u3365': '\u0031\u0033\u70B9',
  31461. '\u3366': '\u0031\u0034\u70B9',
  31462. '\u3367': '\u0031\u0035\u70B9',
  31463. '\u3368': '\u0031\u0036\u70B9',
  31464. '\u3369': '\u0031\u0037\u70B9',
  31465. '\u336A': '\u0031\u0038\u70B9',
  31466. '\u336B': '\u0031\u0039\u70B9',
  31467. '\u336C': '\u0032\u0030\u70B9',
  31468. '\u336D': '\u0032\u0031\u70B9',
  31469. '\u336E': '\u0032\u0032\u70B9',
  31470. '\u336F': '\u0032\u0033\u70B9',
  31471. '\u3370': '\u0032\u0034\u70B9',
  31472. '\u33E0': '\u0031\u65E5',
  31473. '\u33E1': '\u0032\u65E5',
  31474. '\u33E2': '\u0033\u65E5',
  31475. '\u33E3': '\u0034\u65E5',
  31476. '\u33E4': '\u0035\u65E5',
  31477. '\u33E5': '\u0036\u65E5',
  31478. '\u33E6': '\u0037\u65E5',
  31479. '\u33E7': '\u0038\u65E5',
  31480. '\u33E8': '\u0039\u65E5',
  31481. '\u33E9': '\u0031\u0030\u65E5',
  31482. '\u33EA': '\u0031\u0031\u65E5',
  31483. '\u33EB': '\u0031\u0032\u65E5',
  31484. '\u33EC': '\u0031\u0033\u65E5',
  31485. '\u33ED': '\u0031\u0034\u65E5',
  31486. '\u33EE': '\u0031\u0035\u65E5',
  31487. '\u33EF': '\u0031\u0036\u65E5',
  31488. '\u33F0': '\u0031\u0037\u65E5',
  31489. '\u33F1': '\u0031\u0038\u65E5',
  31490. '\u33F2': '\u0031\u0039\u65E5',
  31491. '\u33F3': '\u0032\u0030\u65E5',
  31492. '\u33F4': '\u0032\u0031\u65E5',
  31493. '\u33F5': '\u0032\u0032\u65E5',
  31494. '\u33F6': '\u0032\u0033\u65E5',
  31495. '\u33F7': '\u0032\u0034\u65E5',
  31496. '\u33F8': '\u0032\u0035\u65E5',
  31497. '\u33F9': '\u0032\u0036\u65E5',
  31498. '\u33FA': '\u0032\u0037\u65E5',
  31499. '\u33FB': '\u0032\u0038\u65E5',
  31500. '\u33FC': '\u0032\u0039\u65E5',
  31501. '\u33FD': '\u0033\u0030\u65E5',
  31502. '\u33FE': '\u0033\u0031\u65E5',
  31503. '\uFB00': '\u0066\u0066',
  31504. '\uFB01': '\u0066\u0069',
  31505. '\uFB02': '\u0066\u006C',
  31506. '\uFB03': '\u0066\u0066\u0069',
  31507. '\uFB04': '\u0066\u0066\u006C',
  31508. '\uFB05': '\u017F\u0074',
  31509. '\uFB06': '\u0073\u0074',
  31510. '\uFB13': '\u0574\u0576',
  31511. '\uFB14': '\u0574\u0565',
  31512. '\uFB15': '\u0574\u056B',
  31513. '\uFB16': '\u057E\u0576',
  31514. '\uFB17': '\u0574\u056D',
  31515. '\uFB4F': '\u05D0\u05DC',
  31516. '\uFB50': '\u0671',
  31517. '\uFB51': '\u0671',
  31518. '\uFB52': '\u067B',
  31519. '\uFB53': '\u067B',
  31520. '\uFB54': '\u067B',
  31521. '\uFB55': '\u067B',
  31522. '\uFB56': '\u067E',
  31523. '\uFB57': '\u067E',
  31524. '\uFB58': '\u067E',
  31525. '\uFB59': '\u067E',
  31526. '\uFB5A': '\u0680',
  31527. '\uFB5B': '\u0680',
  31528. '\uFB5C': '\u0680',
  31529. '\uFB5D': '\u0680',
  31530. '\uFB5E': '\u067A',
  31531. '\uFB5F': '\u067A',
  31532. '\uFB60': '\u067A',
  31533. '\uFB61': '\u067A',
  31534. '\uFB62': '\u067F',
  31535. '\uFB63': '\u067F',
  31536. '\uFB64': '\u067F',
  31537. '\uFB65': '\u067F',
  31538. '\uFB66': '\u0679',
  31539. '\uFB67': '\u0679',
  31540. '\uFB68': '\u0679',
  31541. '\uFB69': '\u0679',
  31542. '\uFB6A': '\u06A4',
  31543. '\uFB6B': '\u06A4',
  31544. '\uFB6C': '\u06A4',
  31545. '\uFB6D': '\u06A4',
  31546. '\uFB6E': '\u06A6',
  31547. '\uFB6F': '\u06A6',
  31548. '\uFB70': '\u06A6',
  31549. '\uFB71': '\u06A6',
  31550. '\uFB72': '\u0684',
  31551. '\uFB73': '\u0684',
  31552. '\uFB74': '\u0684',
  31553. '\uFB75': '\u0684',
  31554. '\uFB76': '\u0683',
  31555. '\uFB77': '\u0683',
  31556. '\uFB78': '\u0683',
  31557. '\uFB79': '\u0683',
  31558. '\uFB7A': '\u0686',
  31559. '\uFB7B': '\u0686',
  31560. '\uFB7C': '\u0686',
  31561. '\uFB7D': '\u0686',
  31562. '\uFB7E': '\u0687',
  31563. '\uFB7F': '\u0687',
  31564. '\uFB80': '\u0687',
  31565. '\uFB81': '\u0687',
  31566. '\uFB82': '\u068D',
  31567. '\uFB83': '\u068D',
  31568. '\uFB84': '\u068C',
  31569. '\uFB85': '\u068C',
  31570. '\uFB86': '\u068E',
  31571. '\uFB87': '\u068E',
  31572. '\uFB88': '\u0688',
  31573. '\uFB89': '\u0688',
  31574. '\uFB8A': '\u0698',
  31575. '\uFB8B': '\u0698',
  31576. '\uFB8C': '\u0691',
  31577. '\uFB8D': '\u0691',
  31578. '\uFB8E': '\u06A9',
  31579. '\uFB8F': '\u06A9',
  31580. '\uFB90': '\u06A9',
  31581. '\uFB91': '\u06A9',
  31582. '\uFB92': '\u06AF',
  31583. '\uFB93': '\u06AF',
  31584. '\uFB94': '\u06AF',
  31585. '\uFB95': '\u06AF',
  31586. '\uFB96': '\u06B3',
  31587. '\uFB97': '\u06B3',
  31588. '\uFB98': '\u06B3',
  31589. '\uFB99': '\u06B3',
  31590. '\uFB9A': '\u06B1',
  31591. '\uFB9B': '\u06B1',
  31592. '\uFB9C': '\u06B1',
  31593. '\uFB9D': '\u06B1',
  31594. '\uFB9E': '\u06BA',
  31595. '\uFB9F': '\u06BA',
  31596. '\uFBA0': '\u06BB',
  31597. '\uFBA1': '\u06BB',
  31598. '\uFBA2': '\u06BB',
  31599. '\uFBA3': '\u06BB',
  31600. '\uFBA4': '\u06C0',
  31601. '\uFBA5': '\u06C0',
  31602. '\uFBA6': '\u06C1',
  31603. '\uFBA7': '\u06C1',
  31604. '\uFBA8': '\u06C1',
  31605. '\uFBA9': '\u06C1',
  31606. '\uFBAA': '\u06BE',
  31607. '\uFBAB': '\u06BE',
  31608. '\uFBAC': '\u06BE',
  31609. '\uFBAD': '\u06BE',
  31610. '\uFBAE': '\u06D2',
  31611. '\uFBAF': '\u06D2',
  31612. '\uFBB0': '\u06D3',
  31613. '\uFBB1': '\u06D3',
  31614. '\uFBD3': '\u06AD',
  31615. '\uFBD4': '\u06AD',
  31616. '\uFBD5': '\u06AD',
  31617. '\uFBD6': '\u06AD',
  31618. '\uFBD7': '\u06C7',
  31619. '\uFBD8': '\u06C7',
  31620. '\uFBD9': '\u06C6',
  31621. '\uFBDA': '\u06C6',
  31622. '\uFBDB': '\u06C8',
  31623. '\uFBDC': '\u06C8',
  31624. '\uFBDD': '\u0677',
  31625. '\uFBDE': '\u06CB',
  31626. '\uFBDF': '\u06CB',
  31627. '\uFBE0': '\u06C5',
  31628. '\uFBE1': '\u06C5',
  31629. '\uFBE2': '\u06C9',
  31630. '\uFBE3': '\u06C9',
  31631. '\uFBE4': '\u06D0',
  31632. '\uFBE5': '\u06D0',
  31633. '\uFBE6': '\u06D0',
  31634. '\uFBE7': '\u06D0',
  31635. '\uFBE8': '\u0649',
  31636. '\uFBE9': '\u0649',
  31637. '\uFBEA': '\u0626\u0627',
  31638. '\uFBEB': '\u0626\u0627',
  31639. '\uFBEC': '\u0626\u06D5',
  31640. '\uFBED': '\u0626\u06D5',
  31641. '\uFBEE': '\u0626\u0648',
  31642. '\uFBEF': '\u0626\u0648',
  31643. '\uFBF0': '\u0626\u06C7',
  31644. '\uFBF1': '\u0626\u06C7',
  31645. '\uFBF2': '\u0626\u06C6',
  31646. '\uFBF3': '\u0626\u06C6',
  31647. '\uFBF4': '\u0626\u06C8',
  31648. '\uFBF5': '\u0626\u06C8',
  31649. '\uFBF6': '\u0626\u06D0',
  31650. '\uFBF7': '\u0626\u06D0',
  31651. '\uFBF8': '\u0626\u06D0',
  31652. '\uFBF9': '\u0626\u0649',
  31653. '\uFBFA': '\u0626\u0649',
  31654. '\uFBFB': '\u0626\u0649',
  31655. '\uFBFC': '\u06CC',
  31656. '\uFBFD': '\u06CC',
  31657. '\uFBFE': '\u06CC',
  31658. '\uFBFF': '\u06CC',
  31659. '\uFC00': '\u0626\u062C',
  31660. '\uFC01': '\u0626\u062D',
  31661. '\uFC02': '\u0626\u0645',
  31662. '\uFC03': '\u0626\u0649',
  31663. '\uFC04': '\u0626\u064A',
  31664. '\uFC05': '\u0628\u062C',
  31665. '\uFC06': '\u0628\u062D',
  31666. '\uFC07': '\u0628\u062E',
  31667. '\uFC08': '\u0628\u0645',
  31668. '\uFC09': '\u0628\u0649',
  31669. '\uFC0A': '\u0628\u064A',
  31670. '\uFC0B': '\u062A\u062C',
  31671. '\uFC0C': '\u062A\u062D',
  31672. '\uFC0D': '\u062A\u062E',
  31673. '\uFC0E': '\u062A\u0645',
  31674. '\uFC0F': '\u062A\u0649',
  31675. '\uFC10': '\u062A\u064A',
  31676. '\uFC11': '\u062B\u062C',
  31677. '\uFC12': '\u062B\u0645',
  31678. '\uFC13': '\u062B\u0649',
  31679. '\uFC14': '\u062B\u064A',
  31680. '\uFC15': '\u062C\u062D',
  31681. '\uFC16': '\u062C\u0645',
  31682. '\uFC17': '\u062D\u062C',
  31683. '\uFC18': '\u062D\u0645',
  31684. '\uFC19': '\u062E\u062C',
  31685. '\uFC1A': '\u062E\u062D',
  31686. '\uFC1B': '\u062E\u0645',
  31687. '\uFC1C': '\u0633\u062C',
  31688. '\uFC1D': '\u0633\u062D',
  31689. '\uFC1E': '\u0633\u062E',
  31690. '\uFC1F': '\u0633\u0645',
  31691. '\uFC20': '\u0635\u062D',
  31692. '\uFC21': '\u0635\u0645',
  31693. '\uFC22': '\u0636\u062C',
  31694. '\uFC23': '\u0636\u062D',
  31695. '\uFC24': '\u0636\u062E',
  31696. '\uFC25': '\u0636\u0645',
  31697. '\uFC26': '\u0637\u062D',
  31698. '\uFC27': '\u0637\u0645',
  31699. '\uFC28': '\u0638\u0645',
  31700. '\uFC29': '\u0639\u062C',
  31701. '\uFC2A': '\u0639\u0645',
  31702. '\uFC2B': '\u063A\u062C',
  31703. '\uFC2C': '\u063A\u0645',
  31704. '\uFC2D': '\u0641\u062C',
  31705. '\uFC2E': '\u0641\u062D',
  31706. '\uFC2F': '\u0641\u062E',
  31707. '\uFC30': '\u0641\u0645',
  31708. '\uFC31': '\u0641\u0649',
  31709. '\uFC32': '\u0641\u064A',
  31710. '\uFC33': '\u0642\u062D',
  31711. '\uFC34': '\u0642\u0645',
  31712. '\uFC35': '\u0642\u0649',
  31713. '\uFC36': '\u0642\u064A',
  31714. '\uFC37': '\u0643\u0627',
  31715. '\uFC38': '\u0643\u062C',
  31716. '\uFC39': '\u0643\u062D',
  31717. '\uFC3A': '\u0643\u062E',
  31718. '\uFC3B': '\u0643\u0644',
  31719. '\uFC3C': '\u0643\u0645',
  31720. '\uFC3D': '\u0643\u0649',
  31721. '\uFC3E': '\u0643\u064A',
  31722. '\uFC3F': '\u0644\u062C',
  31723. '\uFC40': '\u0644\u062D',
  31724. '\uFC41': '\u0644\u062E',
  31725. '\uFC42': '\u0644\u0645',
  31726. '\uFC43': '\u0644\u0649',
  31727. '\uFC44': '\u0644\u064A',
  31728. '\uFC45': '\u0645\u062C',
  31729. '\uFC46': '\u0645\u062D',
  31730. '\uFC47': '\u0645\u062E',
  31731. '\uFC48': '\u0645\u0645',
  31732. '\uFC49': '\u0645\u0649',
  31733. '\uFC4A': '\u0645\u064A',
  31734. '\uFC4B': '\u0646\u062C',
  31735. '\uFC4C': '\u0646\u062D',
  31736. '\uFC4D': '\u0646\u062E',
  31737. '\uFC4E': '\u0646\u0645',
  31738. '\uFC4F': '\u0646\u0649',
  31739. '\uFC50': '\u0646\u064A',
  31740. '\uFC51': '\u0647\u062C',
  31741. '\uFC52': '\u0647\u0645',
  31742. '\uFC53': '\u0647\u0649',
  31743. '\uFC54': '\u0647\u064A',
  31744. '\uFC55': '\u064A\u062C',
  31745. '\uFC56': '\u064A\u062D',
  31746. '\uFC57': '\u064A\u062E',
  31747. '\uFC58': '\u064A\u0645',
  31748. '\uFC59': '\u064A\u0649',
  31749. '\uFC5A': '\u064A\u064A',
  31750. '\uFC5B': '\u0630\u0670',
  31751. '\uFC5C': '\u0631\u0670',
  31752. '\uFC5D': '\u0649\u0670',
  31753. '\uFC5E': '\u0020\u064C\u0651',
  31754. '\uFC5F': '\u0020\u064D\u0651',
  31755. '\uFC60': '\u0020\u064E\u0651',
  31756. '\uFC61': '\u0020\u064F\u0651',
  31757. '\uFC62': '\u0020\u0650\u0651',
  31758. '\uFC63': '\u0020\u0651\u0670',
  31759. '\uFC64': '\u0626\u0631',
  31760. '\uFC65': '\u0626\u0632',
  31761. '\uFC66': '\u0626\u0645',
  31762. '\uFC67': '\u0626\u0646',
  31763. '\uFC68': '\u0626\u0649',
  31764. '\uFC69': '\u0626\u064A',
  31765. '\uFC6A': '\u0628\u0631',
  31766. '\uFC6B': '\u0628\u0632',
  31767. '\uFC6C': '\u0628\u0645',
  31768. '\uFC6D': '\u0628\u0646',
  31769. '\uFC6E': '\u0628\u0649',
  31770. '\uFC6F': '\u0628\u064A',
  31771. '\uFC70': '\u062A\u0631',
  31772. '\uFC71': '\u062A\u0632',
  31773. '\uFC72': '\u062A\u0645',
  31774. '\uFC73': '\u062A\u0646',
  31775. '\uFC74': '\u062A\u0649',
  31776. '\uFC75': '\u062A\u064A',
  31777. '\uFC76': '\u062B\u0631',
  31778. '\uFC77': '\u062B\u0632',
  31779. '\uFC78': '\u062B\u0645',
  31780. '\uFC79': '\u062B\u0646',
  31781. '\uFC7A': '\u062B\u0649',
  31782. '\uFC7B': '\u062B\u064A',
  31783. '\uFC7C': '\u0641\u0649',
  31784. '\uFC7D': '\u0641\u064A',
  31785. '\uFC7E': '\u0642\u0649',
  31786. '\uFC7F': '\u0642\u064A',
  31787. '\uFC80': '\u0643\u0627',
  31788. '\uFC81': '\u0643\u0644',
  31789. '\uFC82': '\u0643\u0645',
  31790. '\uFC83': '\u0643\u0649',
  31791. '\uFC84': '\u0643\u064A',
  31792. '\uFC85': '\u0644\u0645',
  31793. '\uFC86': '\u0644\u0649',
  31794. '\uFC87': '\u0644\u064A',
  31795. '\uFC88': '\u0645\u0627',
  31796. '\uFC89': '\u0645\u0645',
  31797. '\uFC8A': '\u0646\u0631',
  31798. '\uFC8B': '\u0646\u0632',
  31799. '\uFC8C': '\u0646\u0645',
  31800. '\uFC8D': '\u0646\u0646',
  31801. '\uFC8E': '\u0646\u0649',
  31802. '\uFC8F': '\u0646\u064A',
  31803. '\uFC90': '\u0649\u0670',
  31804. '\uFC91': '\u064A\u0631',
  31805. '\uFC92': '\u064A\u0632',
  31806. '\uFC93': '\u064A\u0645',
  31807. '\uFC94': '\u064A\u0646',
  31808. '\uFC95': '\u064A\u0649',
  31809. '\uFC96': '\u064A\u064A',
  31810. '\uFC97': '\u0626\u062C',
  31811. '\uFC98': '\u0626\u062D',
  31812. '\uFC99': '\u0626\u062E',
  31813. '\uFC9A': '\u0626\u0645',
  31814. '\uFC9B': '\u0626\u0647',
  31815. '\uFC9C': '\u0628\u062C',
  31816. '\uFC9D': '\u0628\u062D',
  31817. '\uFC9E': '\u0628\u062E',
  31818. '\uFC9F': '\u0628\u0645',
  31819. '\uFCA0': '\u0628\u0647',
  31820. '\uFCA1': '\u062A\u062C',
  31821. '\uFCA2': '\u062A\u062D',
  31822. '\uFCA3': '\u062A\u062E',
  31823. '\uFCA4': '\u062A\u0645',
  31824. '\uFCA5': '\u062A\u0647',
  31825. '\uFCA6': '\u062B\u0645',
  31826. '\uFCA7': '\u062C\u062D',
  31827. '\uFCA8': '\u062C\u0645',
  31828. '\uFCA9': '\u062D\u062C',
  31829. '\uFCAA': '\u062D\u0645',
  31830. '\uFCAB': '\u062E\u062C',
  31831. '\uFCAC': '\u062E\u0645',
  31832. '\uFCAD': '\u0633\u062C',
  31833. '\uFCAE': '\u0633\u062D',
  31834. '\uFCAF': '\u0633\u062E',
  31835. '\uFCB0': '\u0633\u0645',
  31836. '\uFCB1': '\u0635\u062D',
  31837. '\uFCB2': '\u0635\u062E',
  31838. '\uFCB3': '\u0635\u0645',
  31839. '\uFCB4': '\u0636\u062C',
  31840. '\uFCB5': '\u0636\u062D',
  31841. '\uFCB6': '\u0636\u062E',
  31842. '\uFCB7': '\u0636\u0645',
  31843. '\uFCB8': '\u0637\u062D',
  31844. '\uFCB9': '\u0638\u0645',
  31845. '\uFCBA': '\u0639\u062C',
  31846. '\uFCBB': '\u0639\u0645',
  31847. '\uFCBC': '\u063A\u062C',
  31848. '\uFCBD': '\u063A\u0645',
  31849. '\uFCBE': '\u0641\u062C',
  31850. '\uFCBF': '\u0641\u062D',
  31851. '\uFCC0': '\u0641\u062E',
  31852. '\uFCC1': '\u0641\u0645',
  31853. '\uFCC2': '\u0642\u062D',
  31854. '\uFCC3': '\u0642\u0645',
  31855. '\uFCC4': '\u0643\u062C',
  31856. '\uFCC5': '\u0643\u062D',
  31857. '\uFCC6': '\u0643\u062E',
  31858. '\uFCC7': '\u0643\u0644',
  31859. '\uFCC8': '\u0643\u0645',
  31860. '\uFCC9': '\u0644\u062C',
  31861. '\uFCCA': '\u0644\u062D',
  31862. '\uFCCB': '\u0644\u062E',
  31863. '\uFCCC': '\u0644\u0645',
  31864. '\uFCCD': '\u0644\u0647',
  31865. '\uFCCE': '\u0645\u062C',
  31866. '\uFCCF': '\u0645\u062D',
  31867. '\uFCD0': '\u0645\u062E',
  31868. '\uFCD1': '\u0645\u0645',
  31869. '\uFCD2': '\u0646\u062C',
  31870. '\uFCD3': '\u0646\u062D',
  31871. '\uFCD4': '\u0646\u062E',
  31872. '\uFCD5': '\u0646\u0645',
  31873. '\uFCD6': '\u0646\u0647',
  31874. '\uFCD7': '\u0647\u062C',
  31875. '\uFCD8': '\u0647\u0645',
  31876. '\uFCD9': '\u0647\u0670',
  31877. '\uFCDA': '\u064A\u062C',
  31878. '\uFCDB': '\u064A\u062D',
  31879. '\uFCDC': '\u064A\u062E',
  31880. '\uFCDD': '\u064A\u0645',
  31881. '\uFCDE': '\u064A\u0647',
  31882. '\uFCDF': '\u0626\u0645',
  31883. '\uFCE0': '\u0626\u0647',
  31884. '\uFCE1': '\u0628\u0645',
  31885. '\uFCE2': '\u0628\u0647',
  31886. '\uFCE3': '\u062A\u0645',
  31887. '\uFCE4': '\u062A\u0647',
  31888. '\uFCE5': '\u062B\u0645',
  31889. '\uFCE6': '\u062B\u0647',
  31890. '\uFCE7': '\u0633\u0645',
  31891. '\uFCE8': '\u0633\u0647',
  31892. '\uFCE9': '\u0634\u0645',
  31893. '\uFCEA': '\u0634\u0647',
  31894. '\uFCEB': '\u0643\u0644',
  31895. '\uFCEC': '\u0643\u0645',
  31896. '\uFCED': '\u0644\u0645',
  31897. '\uFCEE': '\u0646\u0645',
  31898. '\uFCEF': '\u0646\u0647',
  31899. '\uFCF0': '\u064A\u0645',
  31900. '\uFCF1': '\u064A\u0647',
  31901. '\uFCF2': '\u0640\u064E\u0651',
  31902. '\uFCF3': '\u0640\u064F\u0651',
  31903. '\uFCF4': '\u0640\u0650\u0651',
  31904. '\uFCF5': '\u0637\u0649',
  31905. '\uFCF6': '\u0637\u064A',
  31906. '\uFCF7': '\u0639\u0649',
  31907. '\uFCF8': '\u0639\u064A',
  31908. '\uFCF9': '\u063A\u0649',
  31909. '\uFCFA': '\u063A\u064A',
  31910. '\uFCFB': '\u0633\u0649',
  31911. '\uFCFC': '\u0633\u064A',
  31912. '\uFCFD': '\u0634\u0649',
  31913. '\uFCFE': '\u0634\u064A',
  31914. '\uFCFF': '\u062D\u0649',
  31915. '\uFD00': '\u062D\u064A',
  31916. '\uFD01': '\u062C\u0649',
  31917. '\uFD02': '\u062C\u064A',
  31918. '\uFD03': '\u062E\u0649',
  31919. '\uFD04': '\u062E\u064A',
  31920. '\uFD05': '\u0635\u0649',
  31921. '\uFD06': '\u0635\u064A',
  31922. '\uFD07': '\u0636\u0649',
  31923. '\uFD08': '\u0636\u064A',
  31924. '\uFD09': '\u0634\u062C',
  31925. '\uFD0A': '\u0634\u062D',
  31926. '\uFD0B': '\u0634\u062E',
  31927. '\uFD0C': '\u0634\u0645',
  31928. '\uFD0D': '\u0634\u0631',
  31929. '\uFD0E': '\u0633\u0631',
  31930. '\uFD0F': '\u0635\u0631',
  31931. '\uFD10': '\u0636\u0631',
  31932. '\uFD11': '\u0637\u0649',
  31933. '\uFD12': '\u0637\u064A',
  31934. '\uFD13': '\u0639\u0649',
  31935. '\uFD14': '\u0639\u064A',
  31936. '\uFD15': '\u063A\u0649',
  31937. '\uFD16': '\u063A\u064A',
  31938. '\uFD17': '\u0633\u0649',
  31939. '\uFD18': '\u0633\u064A',
  31940. '\uFD19': '\u0634\u0649',
  31941. '\uFD1A': '\u0634\u064A',
  31942. '\uFD1B': '\u062D\u0649',
  31943. '\uFD1C': '\u062D\u064A',
  31944. '\uFD1D': '\u062C\u0649',
  31945. '\uFD1E': '\u062C\u064A',
  31946. '\uFD1F': '\u062E\u0649',
  31947. '\uFD20': '\u062E\u064A',
  31948. '\uFD21': '\u0635\u0649',
  31949. '\uFD22': '\u0635\u064A',
  31950. '\uFD23': '\u0636\u0649',
  31951. '\uFD24': '\u0636\u064A',
  31952. '\uFD25': '\u0634\u062C',
  31953. '\uFD26': '\u0634\u062D',
  31954. '\uFD27': '\u0634\u062E',
  31955. '\uFD28': '\u0634\u0645',
  31956. '\uFD29': '\u0634\u0631',
  31957. '\uFD2A': '\u0633\u0631',
  31958. '\uFD2B': '\u0635\u0631',
  31959. '\uFD2C': '\u0636\u0631',
  31960. '\uFD2D': '\u0634\u062C',
  31961. '\uFD2E': '\u0634\u062D',
  31962. '\uFD2F': '\u0634\u062E',
  31963. '\uFD30': '\u0634\u0645',
  31964. '\uFD31': '\u0633\u0647',
  31965. '\uFD32': '\u0634\u0647',
  31966. '\uFD33': '\u0637\u0645',
  31967. '\uFD34': '\u0633\u062C',
  31968. '\uFD35': '\u0633\u062D',
  31969. '\uFD36': '\u0633\u062E',
  31970. '\uFD37': '\u0634\u062C',
  31971. '\uFD38': '\u0634\u062D',
  31972. '\uFD39': '\u0634\u062E',
  31973. '\uFD3A': '\u0637\u0645',
  31974. '\uFD3B': '\u0638\u0645',
  31975. '\uFD3C': '\u0627\u064B',
  31976. '\uFD3D': '\u0627\u064B',
  31977. '\uFD50': '\u062A\u062C\u0645',
  31978. '\uFD51': '\u062A\u062D\u062C',
  31979. '\uFD52': '\u062A\u062D\u062C',
  31980. '\uFD53': '\u062A\u062D\u0645',
  31981. '\uFD54': '\u062A\u062E\u0645',
  31982. '\uFD55': '\u062A\u0645\u062C',
  31983. '\uFD56': '\u062A\u0645\u062D',
  31984. '\uFD57': '\u062A\u0645\u062E',
  31985. '\uFD58': '\u062C\u0645\u062D',
  31986. '\uFD59': '\u062C\u0645\u062D',
  31987. '\uFD5A': '\u062D\u0645\u064A',
  31988. '\uFD5B': '\u062D\u0645\u0649',
  31989. '\uFD5C': '\u0633\u062D\u062C',
  31990. '\uFD5D': '\u0633\u062C\u062D',
  31991. '\uFD5E': '\u0633\u062C\u0649',
  31992. '\uFD5F': '\u0633\u0645\u062D',
  31993. '\uFD60': '\u0633\u0645\u062D',
  31994. '\uFD61': '\u0633\u0645\u062C',
  31995. '\uFD62': '\u0633\u0645\u0645',
  31996. '\uFD63': '\u0633\u0645\u0645',
  31997. '\uFD64': '\u0635\u062D\u062D',
  31998. '\uFD65': '\u0635\u062D\u062D',
  31999. '\uFD66': '\u0635\u0645\u0645',
  32000. '\uFD67': '\u0634\u062D\u0645',
  32001. '\uFD68': '\u0634\u062D\u0645',
  32002. '\uFD69': '\u0634\u062C\u064A',
  32003. '\uFD6A': '\u0634\u0645\u062E',
  32004. '\uFD6B': '\u0634\u0645\u062E',
  32005. '\uFD6C': '\u0634\u0645\u0645',
  32006. '\uFD6D': '\u0634\u0645\u0645',
  32007. '\uFD6E': '\u0636\u062D\u0649',
  32008. '\uFD6F': '\u0636\u062E\u0645',
  32009. '\uFD70': '\u0636\u062E\u0645',
  32010. '\uFD71': '\u0637\u0645\u062D',
  32011. '\uFD72': '\u0637\u0645\u062D',
  32012. '\uFD73': '\u0637\u0645\u0645',
  32013. '\uFD74': '\u0637\u0645\u064A',
  32014. '\uFD75': '\u0639\u062C\u0645',
  32015. '\uFD76': '\u0639\u0645\u0645',
  32016. '\uFD77': '\u0639\u0645\u0645',
  32017. '\uFD78': '\u0639\u0645\u0649',
  32018. '\uFD79': '\u063A\u0645\u0645',
  32019. '\uFD7A': '\u063A\u0645\u064A',
  32020. '\uFD7B': '\u063A\u0645\u0649',
  32021. '\uFD7C': '\u0641\u062E\u0645',
  32022. '\uFD7D': '\u0641\u062E\u0645',
  32023. '\uFD7E': '\u0642\u0645\u062D',
  32024. '\uFD7F': '\u0642\u0645\u0645',
  32025. '\uFD80': '\u0644\u062D\u0645',
  32026. '\uFD81': '\u0644\u062D\u064A',
  32027. '\uFD82': '\u0644\u062D\u0649',
  32028. '\uFD83': '\u0644\u062C\u062C',
  32029. '\uFD84': '\u0644\u062C\u062C',
  32030. '\uFD85': '\u0644\u062E\u0645',
  32031. '\uFD86': '\u0644\u062E\u0645',
  32032. '\uFD87': '\u0644\u0645\u062D',
  32033. '\uFD88': '\u0644\u0645\u062D',
  32034. '\uFD89': '\u0645\u062D\u062C',
  32035. '\uFD8A': '\u0645\u062D\u0645',
  32036. '\uFD8B': '\u0645\u062D\u064A',
  32037. '\uFD8C': '\u0645\u062C\u062D',
  32038. '\uFD8D': '\u0645\u062C\u0645',
  32039. '\uFD8E': '\u0645\u062E\u062C',
  32040. '\uFD8F': '\u0645\u062E\u0645',
  32041. '\uFD92': '\u0645\u062C\u062E',
  32042. '\uFD93': '\u0647\u0645\u062C',
  32043. '\uFD94': '\u0647\u0645\u0645',
  32044. '\uFD95': '\u0646\u062D\u0645',
  32045. '\uFD96': '\u0646\u062D\u0649',
  32046. '\uFD97': '\u0646\u062C\u0645',
  32047. '\uFD98': '\u0646\u062C\u0645',
  32048. '\uFD99': '\u0646\u062C\u0649',
  32049. '\uFD9A': '\u0646\u0645\u064A',
  32050. '\uFD9B': '\u0646\u0645\u0649',
  32051. '\uFD9C': '\u064A\u0645\u0645',
  32052. '\uFD9D': '\u064A\u0645\u0645',
  32053. '\uFD9E': '\u0628\u062E\u064A',
  32054. '\uFD9F': '\u062A\u062C\u064A',
  32055. '\uFDA0': '\u062A\u062C\u0649',
  32056. '\uFDA1': '\u062A\u062E\u064A',
  32057. '\uFDA2': '\u062A\u062E\u0649',
  32058. '\uFDA3': '\u062A\u0645\u064A',
  32059. '\uFDA4': '\u062A\u0645\u0649',
  32060. '\uFDA5': '\u062C\u0645\u064A',
  32061. '\uFDA6': '\u062C\u062D\u0649',
  32062. '\uFDA7': '\u062C\u0645\u0649',
  32063. '\uFDA8': '\u0633\u062E\u0649',
  32064. '\uFDA9': '\u0635\u062D\u064A',
  32065. '\uFDAA': '\u0634\u062D\u064A',
  32066. '\uFDAB': '\u0636\u062D\u064A',
  32067. '\uFDAC': '\u0644\u062C\u064A',
  32068. '\uFDAD': '\u0644\u0645\u064A',
  32069. '\uFDAE': '\u064A\u062D\u064A',
  32070. '\uFDAF': '\u064A\u062C\u064A',
  32071. '\uFDB0': '\u064A\u0645\u064A',
  32072. '\uFDB1': '\u0645\u0645\u064A',
  32073. '\uFDB2': '\u0642\u0645\u064A',
  32074. '\uFDB3': '\u0646\u062D\u064A',
  32075. '\uFDB4': '\u0642\u0645\u062D',
  32076. '\uFDB5': '\u0644\u062D\u0645',
  32077. '\uFDB6': '\u0639\u0645\u064A',
  32078. '\uFDB7': '\u0643\u0645\u064A',
  32079. '\uFDB8': '\u0646\u062C\u062D',
  32080. '\uFDB9': '\u0645\u062E\u064A',
  32081. '\uFDBA': '\u0644\u062C\u0645',
  32082. '\uFDBB': '\u0643\u0645\u0645',
  32083. '\uFDBC': '\u0644\u062C\u0645',
  32084. '\uFDBD': '\u0646\u062C\u062D',
  32085. '\uFDBE': '\u062C\u062D\u064A',
  32086. '\uFDBF': '\u062D\u062C\u064A',
  32087. '\uFDC0': '\u0645\u062C\u064A',
  32088. '\uFDC1': '\u0641\u0645\u064A',
  32089. '\uFDC2': '\u0628\u062D\u064A',
  32090. '\uFDC3': '\u0643\u0645\u0645',
  32091. '\uFDC4': '\u0639\u062C\u0645',
  32092. '\uFDC5': '\u0635\u0645\u0645',
  32093. '\uFDC6': '\u0633\u062E\u064A',
  32094. '\uFDC7': '\u0646\u062C\u064A',
  32095. '\uFE49': '\u203E',
  32096. '\uFE4A': '\u203E',
  32097. '\uFE4B': '\u203E',
  32098. '\uFE4C': '\u203E',
  32099. '\uFE4D': '\u005F',
  32100. '\uFE4E': '\u005F',
  32101. '\uFE4F': '\u005F',
  32102. '\uFE80': '\u0621',
  32103. '\uFE81': '\u0622',
  32104. '\uFE82': '\u0622',
  32105. '\uFE83': '\u0623',
  32106. '\uFE84': '\u0623',
  32107. '\uFE85': '\u0624',
  32108. '\uFE86': '\u0624',
  32109. '\uFE87': '\u0625',
  32110. '\uFE88': '\u0625',
  32111. '\uFE89': '\u0626',
  32112. '\uFE8A': '\u0626',
  32113. '\uFE8B': '\u0626',
  32114. '\uFE8C': '\u0626',
  32115. '\uFE8D': '\u0627',
  32116. '\uFE8E': '\u0627',
  32117. '\uFE8F': '\u0628',
  32118. '\uFE90': '\u0628',
  32119. '\uFE91': '\u0628',
  32120. '\uFE92': '\u0628',
  32121. '\uFE93': '\u0629',
  32122. '\uFE94': '\u0629',
  32123. '\uFE95': '\u062A',
  32124. '\uFE96': '\u062A',
  32125. '\uFE97': '\u062A',
  32126. '\uFE98': '\u062A',
  32127. '\uFE99': '\u062B',
  32128. '\uFE9A': '\u062B',
  32129. '\uFE9B': '\u062B',
  32130. '\uFE9C': '\u062B',
  32131. '\uFE9D': '\u062C',
  32132. '\uFE9E': '\u062C',
  32133. '\uFE9F': '\u062C',
  32134. '\uFEA0': '\u062C',
  32135. '\uFEA1': '\u062D',
  32136. '\uFEA2': '\u062D',
  32137. '\uFEA3': '\u062D',
  32138. '\uFEA4': '\u062D',
  32139. '\uFEA5': '\u062E',
  32140. '\uFEA6': '\u062E',
  32141. '\uFEA7': '\u062E',
  32142. '\uFEA8': '\u062E',
  32143. '\uFEA9': '\u062F',
  32144. '\uFEAA': '\u062F',
  32145. '\uFEAB': '\u0630',
  32146. '\uFEAC': '\u0630',
  32147. '\uFEAD': '\u0631',
  32148. '\uFEAE': '\u0631',
  32149. '\uFEAF': '\u0632',
  32150. '\uFEB0': '\u0632',
  32151. '\uFEB1': '\u0633',
  32152. '\uFEB2': '\u0633',
  32153. '\uFEB3': '\u0633',
  32154. '\uFEB4': '\u0633',
  32155. '\uFEB5': '\u0634',
  32156. '\uFEB6': '\u0634',
  32157. '\uFEB7': '\u0634',
  32158. '\uFEB8': '\u0634',
  32159. '\uFEB9': '\u0635',
  32160. '\uFEBA': '\u0635',
  32161. '\uFEBB': '\u0635',
  32162. '\uFEBC': '\u0635',
  32163. '\uFEBD': '\u0636',
  32164. '\uFEBE': '\u0636',
  32165. '\uFEBF': '\u0636',
  32166. '\uFEC0': '\u0636',
  32167. '\uFEC1': '\u0637',
  32168. '\uFEC2': '\u0637',
  32169. '\uFEC3': '\u0637',
  32170. '\uFEC4': '\u0637',
  32171. '\uFEC5': '\u0638',
  32172. '\uFEC6': '\u0638',
  32173. '\uFEC7': '\u0638',
  32174. '\uFEC8': '\u0638',
  32175. '\uFEC9': '\u0639',
  32176. '\uFECA': '\u0639',
  32177. '\uFECB': '\u0639',
  32178. '\uFECC': '\u0639',
  32179. '\uFECD': '\u063A',
  32180. '\uFECE': '\u063A',
  32181. '\uFECF': '\u063A',
  32182. '\uFED0': '\u063A',
  32183. '\uFED1': '\u0641',
  32184. '\uFED2': '\u0641',
  32185. '\uFED3': '\u0641',
  32186. '\uFED4': '\u0641',
  32187. '\uFED5': '\u0642',
  32188. '\uFED6': '\u0642',
  32189. '\uFED7': '\u0642',
  32190. '\uFED8': '\u0642',
  32191. '\uFED9': '\u0643',
  32192. '\uFEDA': '\u0643',
  32193. '\uFEDB': '\u0643',
  32194. '\uFEDC': '\u0643',
  32195. '\uFEDD': '\u0644',
  32196. '\uFEDE': '\u0644',
  32197. '\uFEDF': '\u0644',
  32198. '\uFEE0': '\u0644',
  32199. '\uFEE1': '\u0645',
  32200. '\uFEE2': '\u0645',
  32201. '\uFEE3': '\u0645',
  32202. '\uFEE4': '\u0645',
  32203. '\uFEE5': '\u0646',
  32204. '\uFEE6': '\u0646',
  32205. '\uFEE7': '\u0646',
  32206. '\uFEE8': '\u0646',
  32207. '\uFEE9': '\u0647',
  32208. '\uFEEA': '\u0647',
  32209. '\uFEEB': '\u0647',
  32210. '\uFEEC': '\u0647',
  32211. '\uFEED': '\u0648',
  32212. '\uFEEE': '\u0648',
  32213. '\uFEEF': '\u0649',
  32214. '\uFEF0': '\u0649',
  32215. '\uFEF1': '\u064A',
  32216. '\uFEF2': '\u064A',
  32217. '\uFEF3': '\u064A',
  32218. '\uFEF4': '\u064A',
  32219. '\uFEF5': '\u0644\u0622',
  32220. '\uFEF6': '\u0644\u0622',
  32221. '\uFEF7': '\u0644\u0623',
  32222. '\uFEF8': '\u0644\u0623',
  32223. '\uFEF9': '\u0644\u0625',
  32224. '\uFEFA': '\u0644\u0625',
  32225. '\uFEFB': '\u0644\u0627',
  32226. '\uFEFC': '\u0644\u0627'
  32227. };
  32228. function reverseIfRtl(chars) {
  32229. var charsLength = chars.length;
  32230. //reverse an arabic ligature
  32231. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  32232. return chars;
  32233. }
  32234. var s = '';
  32235. for (var ii = charsLength - 1; ii >= 0; ii--) {
  32236. s += chars[ii];
  32237. }
  32238. return s;
  32239. }
  32240. function adjustWidths(properties) {
  32241. if (!properties.fontMatrix) {
  32242. return;
  32243. }
  32244. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  32245. return;
  32246. }
  32247. // adjusting width to fontMatrix scale
  32248. var scale = 0.001 / properties.fontMatrix[0];
  32249. var glyphsWidths = properties.widths;
  32250. for (var glyph in glyphsWidths) {
  32251. glyphsWidths[glyph] *= scale;
  32252. }
  32253. properties.defaultWidth *= scale;
  32254. }
  32255. function getFontType(type, subtype) {
  32256. switch (type) {
  32257. case 'Type1':
  32258. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  32259. case 'CIDFontType0':
  32260. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  32261. FontType.CIDFONTTYPE0;
  32262. case 'OpenType':
  32263. return FontType.OPENTYPE;
  32264. case 'TrueType':
  32265. return FontType.TRUETYPE;
  32266. case 'CIDFontType2':
  32267. return FontType.CIDFONTTYPE2;
  32268. case 'MMType1':
  32269. return FontType.MMTYPE1;
  32270. case 'Type0':
  32271. return FontType.TYPE0;
  32272. default:
  32273. return FontType.UNKNOWN;
  32274. }
  32275. }
  32276. var Glyph = (function GlyphClosure() {
  32277. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  32278. isSpace) {
  32279. this.fontChar = fontChar;
  32280. this.unicode = unicode;
  32281. this.accent = accent;
  32282. this.width = width;
  32283. this.vmetric = vmetric;
  32284. this.operatorListId = operatorListId;
  32285. this.isSpace = isSpace;
  32286. }
  32287. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  32288. vmetric, operatorListId, isSpace) {
  32289. return this.fontChar === fontChar &&
  32290. this.unicode === unicode &&
  32291. this.accent === accent &&
  32292. this.width === width &&
  32293. this.vmetric === vmetric &&
  32294. this.operatorListId === operatorListId &&
  32295. this.isSpace === isSpace;
  32296. };
  32297. return Glyph;
  32298. })();
  32299. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  32300. function ToUnicodeMap(cmap) {
  32301. // The elements of this._map can be integers or strings, depending on how
  32302. // |cmap| was created.
  32303. this._map = cmap;
  32304. }
  32305. ToUnicodeMap.prototype = {
  32306. get length() {
  32307. return this._map.length;
  32308. },
  32309. forEach: function(callback) {
  32310. for (var charCode in this._map) {
  32311. callback(charCode, this._map[charCode].charCodeAt(0));
  32312. }
  32313. },
  32314. has: function(i) {
  32315. return this._map[i] !== undefined;
  32316. },
  32317. get: function(i) {
  32318. return this._map[i];
  32319. },
  32320. charCodeOf: function(v) {
  32321. return this._map.indexOf(v);
  32322. }
  32323. };
  32324. return ToUnicodeMap;
  32325. })();
  32326. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  32327. function IdentityToUnicodeMap(firstChar, lastChar) {
  32328. this.firstChar = firstChar;
  32329. this.lastChar = lastChar;
  32330. }
  32331. IdentityToUnicodeMap.prototype = {
  32332. get length() {
  32333. return (this.lastChar + 1) - this.firstChar;
  32334. },
  32335. forEach: function (callback) {
  32336. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  32337. callback(i, i);
  32338. }
  32339. },
  32340. has: function (i) {
  32341. return this.firstChar <= i && i <= this.lastChar;
  32342. },
  32343. get: function (i) {
  32344. if (this.firstChar <= i && i <= this.lastChar) {
  32345. return String.fromCharCode(i);
  32346. }
  32347. return undefined;
  32348. },
  32349. charCodeOf: function (v) {
  32350. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  32351. }
  32352. };
  32353. return IdentityToUnicodeMap;
  32354. })();
  32355. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  32356. function writeInt16(dest, offset, num) {
  32357. dest[offset] = (num >> 8) & 0xFF;
  32358. dest[offset + 1] = num & 0xFF;
  32359. }
  32360. function writeInt32(dest, offset, num) {
  32361. dest[offset] = (num >> 24) & 0xFF;
  32362. dest[offset + 1] = (num >> 16) & 0xFF;
  32363. dest[offset + 2] = (num >> 8) & 0xFF;
  32364. dest[offset + 3] = num & 0xFF;
  32365. }
  32366. function writeData(dest, offset, data) {
  32367. var i, ii;
  32368. if (data instanceof Uint8Array) {
  32369. dest.set(data, offset);
  32370. } else if (typeof data === 'string') {
  32371. for (i = 0, ii = data.length; i < ii; i++) {
  32372. dest[offset++] = data.charCodeAt(i) & 0xFF;
  32373. }
  32374. } else {
  32375. // treating everything else as array
  32376. for (i = 0, ii = data.length; i < ii; i++) {
  32377. dest[offset++] = data[i] & 0xFF;
  32378. }
  32379. }
  32380. }
  32381. function OpenTypeFileBuilder(sfnt) {
  32382. this.sfnt = sfnt;
  32383. this.tables = Object.create(null);
  32384. }
  32385. OpenTypeFileBuilder.getSearchParams =
  32386. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  32387. var maxPower2 = 1, log2 = 0;
  32388. while ((maxPower2 ^ entriesCount) > maxPower2) {
  32389. maxPower2 <<= 1;
  32390. log2++;
  32391. }
  32392. var searchRange = maxPower2 * entrySize;
  32393. return {
  32394. range: searchRange,
  32395. entry: log2,
  32396. rangeShift: entrySize * entriesCount - searchRange
  32397. };
  32398. };
  32399. var OTF_HEADER_SIZE = 12;
  32400. var OTF_TABLE_ENTRY_SIZE = 16;
  32401. OpenTypeFileBuilder.prototype = {
  32402. toArray: function OpenTypeFileBuilder_toArray() {
  32403. var sfnt = this.sfnt;
  32404. // Tables needs to be written by ascendant alphabetic order
  32405. var tables = this.tables;
  32406. var tablesNames = Object.keys(tables);
  32407. tablesNames.sort();
  32408. var numTables = tablesNames.length;
  32409. var i, j, jj, table, tableName;
  32410. // layout the tables data
  32411. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  32412. var tableOffsets = [offset];
  32413. for (i = 0; i < numTables; i++) {
  32414. table = tables[tablesNames[i]];
  32415. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  32416. offset += paddedLength;
  32417. tableOffsets.push(offset);
  32418. }
  32419. var file = new Uint8Array(offset);
  32420. // write the table data first (mostly for checksum)
  32421. for (i = 0; i < numTables; i++) {
  32422. table = tables[tablesNames[i]];
  32423. writeData(file, tableOffsets[i], table);
  32424. }
  32425. // sfnt version (4 bytes)
  32426. if (sfnt === 'true') {
  32427. // Windows hates the Mac TrueType sfnt version number
  32428. sfnt = string32(0x00010000);
  32429. }
  32430. file[0] = sfnt.charCodeAt(0) & 0xFF;
  32431. file[1] = sfnt.charCodeAt(1) & 0xFF;
  32432. file[2] = sfnt.charCodeAt(2) & 0xFF;
  32433. file[3] = sfnt.charCodeAt(3) & 0xFF;
  32434. // numTables (2 bytes)
  32435. writeInt16(file, 4, numTables);
  32436. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  32437. // searchRange (2 bytes)
  32438. writeInt16(file, 6, searchParams.range);
  32439. // entrySelector (2 bytes)
  32440. writeInt16(file, 8, searchParams.entry);
  32441. // rangeShift (2 bytes)
  32442. writeInt16(file, 10, searchParams.rangeShift);
  32443. offset = OTF_HEADER_SIZE;
  32444. // writing table entries
  32445. for (i = 0; i < numTables; i++) {
  32446. tableName = tablesNames[i];
  32447. file[offset] = tableName.charCodeAt(0) & 0xFF;
  32448. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  32449. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  32450. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  32451. // checksum
  32452. var checksum = 0;
  32453. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  32454. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  32455. (file[j + 2] << 8) + file[j + 3];
  32456. checksum = (checksum + quad) | 0;
  32457. }
  32458. writeInt32(file, offset + 4, checksum);
  32459. // offset
  32460. writeInt32(file, offset + 8, tableOffsets[i]);
  32461. // length
  32462. writeInt32(file, offset + 12, tables[tableName].length);
  32463. offset += OTF_TABLE_ENTRY_SIZE;
  32464. }
  32465. return file;
  32466. },
  32467. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  32468. if (tag in this.tables) {
  32469. throw new Error('Table ' + tag + ' already exists');
  32470. }
  32471. this.tables[tag] = data;
  32472. }
  32473. };
  32474. return OpenTypeFileBuilder;
  32475. })();
  32476. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  32477. // issues when they are painted on the canvas, e.g. complex-script shaping or
  32478. // control/whitespace characters. The ranges are listed in pairs: the first item
  32479. // is a code of the first problematic code, the second one is the next
  32480. // non-problematic code. The ranges must be in sorted order.
  32481. var ProblematicCharRanges = new Int32Array([
  32482. // Control characters.
  32483. 0x0000, 0x0020,
  32484. 0x007F, 0x00A1,
  32485. 0x00AD, 0x00AE,
  32486. // Chars that is used in complex-script shaping.
  32487. 0x0600, 0x0780,
  32488. 0x08A0, 0x10A0,
  32489. 0x1780, 0x1800,
  32490. // General punctuation chars.
  32491. 0x2000, 0x2010,
  32492. 0x2011, 0x2012,
  32493. 0x2028, 0x2030,
  32494. 0x205F, 0x2070,
  32495. 0x25CC, 0x25CD,
  32496. // Chars that is used in complex-script shaping.
  32497. 0xAA60, 0xAA80,
  32498. // Specials Unicode block.
  32499. 0xFFF0, 0x10000
  32500. ]);
  32501. /**
  32502. * 'Font' is the class the outside world should use, it encapsulate all the font
  32503. * decoding logics whatever type it is (assuming the font type is supported).
  32504. *
  32505. * For example to read a Type1 font and to attach it to the document:
  32506. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  32507. * type1Font.bind();
  32508. */
  32509. var Font = (function FontClosure() {
  32510. function Font(name, file, properties) {
  32511. var charCode, glyphName, fontChar;
  32512. this.name = name;
  32513. this.loadedName = properties.loadedName;
  32514. this.isType3Font = properties.isType3Font;
  32515. this.sizes = [];
  32516. this.glyphCache = {};
  32517. var names = name.split('+');
  32518. names = names.length > 1 ? names[1] : names[0];
  32519. names = names.split(/[-,_]/g)[0];
  32520. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  32521. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  32522. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  32523. var type = properties.type;
  32524. var subtype = properties.subtype;
  32525. this.type = type;
  32526. this.fallbackName = (this.isMonospace ? 'monospace' :
  32527. (this.isSerifFont ? 'serif' : 'sans-serif'));
  32528. this.differences = properties.differences;
  32529. this.widths = properties.widths;
  32530. this.defaultWidth = properties.defaultWidth;
  32531. this.composite = properties.composite;
  32532. this.wideChars = properties.wideChars;
  32533. this.cMap = properties.cMap;
  32534. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  32535. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  32536. this.fontMatrix = properties.fontMatrix;
  32537. this.bbox = properties.bbox;
  32538. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  32539. this.toFontChar = [];
  32540. if (properties.type === 'Type3') {
  32541. for (charCode = 0; charCode < 256; charCode++) {
  32542. this.toFontChar[charCode] = (this.differences[charCode] ||
  32543. properties.defaultEncoding[charCode]);
  32544. }
  32545. this.fontType = FontType.TYPE3;
  32546. return;
  32547. }
  32548. this.cidEncoding = properties.cidEncoding;
  32549. this.vertical = properties.vertical;
  32550. if (this.vertical) {
  32551. this.vmetrics = properties.vmetrics;
  32552. this.defaultVMetrics = properties.defaultVMetrics;
  32553. }
  32554. if (!file || file.isEmpty) {
  32555. if (file) {
  32556. // Some bad PDF generators will include empty font files,
  32557. // attempting to recover by assuming that no file exists.
  32558. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  32559. }
  32560. this.missingFile = true;
  32561. // The file data is not specified. Trying to fix the font name
  32562. // to be used with the canvas.font.
  32563. var fontName = name.replace(/[,_]/g, '-');
  32564. var isStandardFont = !!stdFontMap[fontName] ||
  32565. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32566. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32567. this.bold = (fontName.search(/bold/gi) !== -1);
  32568. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32569. (fontName.search(/italic/gi) !== -1));
  32570. // Use 'name' instead of 'fontName' here because the original
  32571. // name ArialBlack for example will be replaced by Helvetica.
  32572. this.black = (name.search(/Black/g) !== -1);
  32573. // if at least one width is present, remeasure all chars when exists
  32574. this.remeasure = Object.keys(this.widths).length > 0;
  32575. if (isStandardFont && type === 'CIDFontType2' &&
  32576. properties.cidEncoding.indexOf('Identity-') === 0) {
  32577. // Standard fonts might be embedded as CID font without glyph mapping.
  32578. // Building one based on GlyphMapForStandardFonts.
  32579. var map = [];
  32580. for (charCode in GlyphMapForStandardFonts) {
  32581. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32582. }
  32583. if (/ArialBlack/i.test(name)) {
  32584. for (charCode in SupplementalGlyphMapForArialBlack) {
  32585. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32586. }
  32587. }
  32588. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32589. if (!isIdentityUnicode) {
  32590. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32591. map[+charCode] = unicodeCharCode;
  32592. });
  32593. }
  32594. this.toFontChar = map;
  32595. this.toUnicode = new ToUnicodeMap(map);
  32596. } else if (/Symbol/i.test(fontName)) {
  32597. var symbols = Encodings.SymbolSetEncoding;
  32598. for (charCode in symbols) {
  32599. fontChar = GlyphsUnicode[symbols[charCode]];
  32600. if (!fontChar) {
  32601. continue;
  32602. }
  32603. this.toFontChar[charCode] = fontChar;
  32604. }
  32605. for (charCode in properties.differences) {
  32606. fontChar = GlyphsUnicode[properties.differences[charCode]];
  32607. if (!fontChar) {
  32608. continue;
  32609. }
  32610. this.toFontChar[charCode] = fontChar;
  32611. }
  32612. } else if (/Dingbats/i.test(fontName)) {
  32613. if (/Wingdings/i.test(name)) {
  32614. warn('Wingdings font without embedded font file, ' +
  32615. 'falling back to the ZapfDingbats encoding.');
  32616. }
  32617. var dingbats = Encodings.ZapfDingbatsEncoding;
  32618. for (charCode in dingbats) {
  32619. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  32620. if (!fontChar) {
  32621. continue;
  32622. }
  32623. this.toFontChar[charCode] = fontChar;
  32624. }
  32625. for (charCode in properties.differences) {
  32626. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  32627. if (!fontChar) {
  32628. continue;
  32629. }
  32630. this.toFontChar[charCode] = fontChar;
  32631. }
  32632. } else if (isStandardFont) {
  32633. this.toFontChar = [];
  32634. for (charCode in properties.defaultEncoding) {
  32635. glyphName = (properties.differences[charCode] ||
  32636. properties.defaultEncoding[charCode]);
  32637. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  32638. }
  32639. } else {
  32640. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  32641. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32642. if (notCidFont) {
  32643. glyphName = (properties.differences[charCode] ||
  32644. properties.defaultEncoding[charCode]);
  32645. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  32646. }
  32647. this.toFontChar[charCode] = unicodeCharCode;
  32648. }.bind(this));
  32649. }
  32650. this.loadedName = fontName.split('-')[0];
  32651. this.loading = false;
  32652. this.fontType = getFontType(type, subtype);
  32653. return;
  32654. }
  32655. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32656. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32657. // Some TrueType fonts by mistake claim Type1C
  32658. if (isTrueTypeFile(file)) {
  32659. subtype = 'TrueType';
  32660. } else {
  32661. type = 'Type1';
  32662. }
  32663. }
  32664. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32665. type = 'CIDFontType0';
  32666. }
  32667. if (subtype === 'OpenType') {
  32668. type = 'OpenType';
  32669. }
  32670. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32671. if (type === 'CIDFontType0') {
  32672. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  32673. }
  32674. var data;
  32675. switch (type) {
  32676. case 'MMType1':
  32677. info('MMType1 font (' + name + '), falling back to Type1.');
  32678. /* falls through */
  32679. case 'Type1':
  32680. case 'CIDFontType0':
  32681. this.mimetype = 'font/opentype';
  32682. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32683. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32684. adjustWidths(properties);
  32685. // Wrap the CFF data inside an OTF font file
  32686. data = this.convert(name, cff, properties);
  32687. break;
  32688. case 'OpenType':
  32689. case 'TrueType':
  32690. case 'CIDFontType2':
  32691. this.mimetype = 'font/opentype';
  32692. // Repair the TrueType file. It is can be damaged in the point of
  32693. // view of the sanitizer
  32694. data = this.checkAndRepair(name, file, properties);
  32695. if (this.isOpenType) {
  32696. adjustWidths(properties);
  32697. type = 'OpenType';
  32698. }
  32699. break;
  32700. default:
  32701. error('Font ' + type + ' is not supported');
  32702. break;
  32703. }
  32704. this.data = data;
  32705. this.fontType = getFontType(type, subtype);
  32706. // Transfer some properties again that could change during font conversion
  32707. this.fontMatrix = properties.fontMatrix;
  32708. this.widths = properties.widths;
  32709. this.defaultWidth = properties.defaultWidth;
  32710. this.encoding = properties.baseEncoding;
  32711. this.seacMap = properties.seacMap;
  32712. this.loading = true;
  32713. }
  32714. Font.getFontID = (function () {
  32715. var ID = 1;
  32716. return function Font_getFontID() {
  32717. return String(ID++);
  32718. };
  32719. })();
  32720. function int16(b0, b1) {
  32721. return (b0 << 8) + b1;
  32722. }
  32723. function int32(b0, b1, b2, b3) {
  32724. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32725. }
  32726. function string16(value) {
  32727. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32728. }
  32729. function safeString16(value) {
  32730. // clamp value to the 16-bit int range
  32731. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32732. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32733. }
  32734. function isTrueTypeFile(file) {
  32735. var header = file.peekBytes(4);
  32736. return readUint32(header, 0) === 0x00010000;
  32737. }
  32738. function isType1File(file) {
  32739. var header = file.peekBytes(2);
  32740. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32741. if (header[0] === 0x25 && header[1] === 0x21) {
  32742. return true;
  32743. }
  32744. // ... obviously some fonts violate that part of the specification,
  32745. // please refer to the comment in |Type1Font| below.
  32746. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32747. return true;
  32748. }
  32749. return false;
  32750. }
  32751. /**
  32752. * Helper function for |adjustMapping|.
  32753. * @return {boolean}
  32754. */
  32755. function isProblematicUnicodeLocation(code) {
  32756. // Using binary search to find a range start.
  32757. var i = 0, j = ProblematicCharRanges.length - 1;
  32758. while (i < j) {
  32759. var c = (i + j + 1) >> 1;
  32760. if (code < ProblematicCharRanges[c]) {
  32761. j = c - 1;
  32762. } else {
  32763. i = c;
  32764. }
  32765. }
  32766. // Even index means code in problematic range.
  32767. return !(i & 1);
  32768. }
  32769. /**
  32770. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32771. * with their unicode value. It also moves char codes that are in known
  32772. * problematic locations.
  32773. * @return {Object} Two properties:
  32774. * 'toFontChar' - maps original char codes(the value that will be read
  32775. * from commands such as show text) to the char codes that will be used in the
  32776. * font that we build
  32777. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32778. */
  32779. function adjustMapping(charCodeToGlyphId, properties) {
  32780. var toUnicode = properties.toUnicode;
  32781. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32782. var isIdentityUnicode =
  32783. properties.toUnicode instanceof IdentityToUnicodeMap;
  32784. var newMap = Object.create(null);
  32785. var toFontChar = [];
  32786. var usedFontCharCodes = [];
  32787. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32788. for (var originalCharCode in charCodeToGlyphId) {
  32789. originalCharCode |= 0;
  32790. var glyphId = charCodeToGlyphId[originalCharCode];
  32791. var fontCharCode = originalCharCode;
  32792. // First try to map the value to a unicode position if a non identity map
  32793. // was created.
  32794. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32795. var unicode = toUnicode.get(fontCharCode);
  32796. // TODO: Try to map ligatures to the correct spot.
  32797. if (unicode.length === 1) {
  32798. fontCharCode = unicode.charCodeAt(0);
  32799. }
  32800. }
  32801. // Try to move control characters, special characters and already mapped
  32802. // characters to the private use area since they will not be drawn by
  32803. // canvas if left in their current position. Also, move characters if the
  32804. // font was symbolic and there is only an identity unicode map since the
  32805. // characters probably aren't in the correct position (fixes an issue
  32806. // with firefox and thuluthfont).
  32807. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32808. isProblematicUnicodeLocation(fontCharCode) ||
  32809. (isSymbolic && isIdentityUnicode)) &&
  32810. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32811. // Loop to try and find a free spot in the private use area.
  32812. do {
  32813. fontCharCode = nextAvailableFontCharCode++;
  32814. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32815. fontCharCode = 0xF020;
  32816. nextAvailableFontCharCode = fontCharCode + 1;
  32817. }
  32818. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32819. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32820. }
  32821. newMap[fontCharCode] = glyphId;
  32822. toFontChar[originalCharCode] = fontCharCode;
  32823. usedFontCharCodes[fontCharCode] = true;
  32824. }
  32825. return {
  32826. toFontChar: toFontChar,
  32827. charCodeToGlyphId: newMap,
  32828. nextAvailableFontCharCode: nextAvailableFontCharCode
  32829. };
  32830. }
  32831. function getRanges(glyphs, numGlyphs) {
  32832. // Array.sort() sorts by characters, not numerically, so convert to an
  32833. // array of characters.
  32834. var codes = [];
  32835. for (var charCode in glyphs) {
  32836. // Remove an invalid glyph ID mappings to make OTS happy.
  32837. if (glyphs[charCode] >= numGlyphs) {
  32838. continue;
  32839. }
  32840. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32841. }
  32842. codes.sort(function fontGetRangesSort(a, b) {
  32843. return a.fontCharCode - b.fontCharCode;
  32844. });
  32845. // Split the sorted codes into ranges.
  32846. var ranges = [];
  32847. var length = codes.length;
  32848. for (var n = 0; n < length; ) {
  32849. var start = codes[n].fontCharCode;
  32850. var codeIndices = [codes[n].glyphId];
  32851. ++n;
  32852. var end = start;
  32853. while (n < length && end + 1 === codes[n].fontCharCode) {
  32854. codeIndices.push(codes[n].glyphId);
  32855. ++end;
  32856. ++n;
  32857. if (end === 0xFFFF) {
  32858. break;
  32859. }
  32860. }
  32861. ranges.push([start, end, codeIndices]);
  32862. }
  32863. return ranges;
  32864. }
  32865. function createCmapTable(glyphs, numGlyphs) {
  32866. var ranges = getRanges(glyphs, numGlyphs);
  32867. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32868. var cmap = '\x00\x00' + // version
  32869. string16(numTables) + // numTables
  32870. '\x00\x03' + // platformID
  32871. '\x00\x01' + // encodingID
  32872. string32(4 + numTables * 8); // start of the table record
  32873. var i, ii, j, jj;
  32874. for (i = ranges.length - 1; i >= 0; --i) {
  32875. if (ranges[i][0] <= 0xFFFF) { break; }
  32876. }
  32877. var bmpLength = i + 1;
  32878. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32879. ranges[i][1] = 0xFFFE;
  32880. }
  32881. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32882. var segCount = bmpLength + trailingRangesCount;
  32883. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32884. // Fill up the 4 parallel arrays describing the segments.
  32885. var startCount = '';
  32886. var endCount = '';
  32887. var idDeltas = '';
  32888. var idRangeOffsets = '';
  32889. var glyphsIds = '';
  32890. var bias = 0;
  32891. var range, start, end, codes;
  32892. for (i = 0, ii = bmpLength; i < ii; i++) {
  32893. range = ranges[i];
  32894. start = range[0];
  32895. end = range[1];
  32896. startCount += string16(start);
  32897. endCount += string16(end);
  32898. codes = range[2];
  32899. var contiguous = true;
  32900. for (j = 1, jj = codes.length; j < jj; ++j) {
  32901. if (codes[j] !== codes[j - 1] + 1) {
  32902. contiguous = false;
  32903. break;
  32904. }
  32905. }
  32906. if (!contiguous) {
  32907. var offset = (segCount - i) * 2 + bias * 2;
  32908. bias += (end - start + 1);
  32909. idDeltas += string16(0);
  32910. idRangeOffsets += string16(offset);
  32911. for (j = 0, jj = codes.length; j < jj; ++j) {
  32912. glyphsIds += string16(codes[j]);
  32913. }
  32914. } else {
  32915. var startCode = codes[0];
  32916. idDeltas += string16((startCode - start) & 0xFFFF);
  32917. idRangeOffsets += string16(0);
  32918. }
  32919. }
  32920. if (trailingRangesCount > 0) {
  32921. endCount += '\xFF\xFF';
  32922. startCount += '\xFF\xFF';
  32923. idDeltas += '\x00\x01';
  32924. idRangeOffsets += '\x00\x00';
  32925. }
  32926. var format314 = '\x00\x00' + // language
  32927. string16(2 * segCount) +
  32928. string16(searchParams.range) +
  32929. string16(searchParams.entry) +
  32930. string16(searchParams.rangeShift) +
  32931. endCount + '\x00\x00' + startCount +
  32932. idDeltas + idRangeOffsets + glyphsIds;
  32933. var format31012 = '';
  32934. var header31012 = '';
  32935. if (numTables > 1) {
  32936. cmap += '\x00\x03' + // platformID
  32937. '\x00\x0A' + // encodingID
  32938. string32(4 + numTables * 8 +
  32939. 4 + format314.length); // start of the table record
  32940. format31012 = '';
  32941. for (i = 0, ii = ranges.length; i < ii; i++) {
  32942. range = ranges[i];
  32943. start = range[0];
  32944. codes = range[2];
  32945. var code = codes[0];
  32946. for (j = 1, jj = codes.length; j < jj; ++j) {
  32947. if (codes[j] !== codes[j - 1] + 1) {
  32948. end = range[0] + j - 1;
  32949. format31012 += string32(start) + // startCharCode
  32950. string32(end) + // endCharCode
  32951. string32(code); // startGlyphID
  32952. start = end + 1;
  32953. code = codes[j];
  32954. }
  32955. }
  32956. format31012 += string32(start) + // startCharCode
  32957. string32(range[1]) + // endCharCode
  32958. string32(code); // startGlyphID
  32959. }
  32960. header31012 = '\x00\x0C' + // format
  32961. '\x00\x00' + // reserved
  32962. string32(format31012.length + 16) + // length
  32963. '\x00\x00\x00\x00' + // language
  32964. string32(format31012.length / 12); // nGroups
  32965. }
  32966. return cmap + '\x00\x04' + // format
  32967. string16(format314.length + 4) + // length
  32968. format314 + header31012 + format31012;
  32969. }
  32970. function validateOS2Table(os2) {
  32971. var stream = new Stream(os2.data);
  32972. var version = stream.getUint16();
  32973. // TODO verify all OS/2 tables fields, but currently we validate only those
  32974. // that give us issues
  32975. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32976. var selection = stream.getUint16();
  32977. if (version < 4 && (selection & 0x0300)) {
  32978. return false;
  32979. }
  32980. var firstChar = stream.getUint16();
  32981. var lastChar = stream.getUint16();
  32982. if (firstChar > lastChar) {
  32983. return false;
  32984. }
  32985. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32986. var usWinAscent = stream.getUint16();
  32987. if (usWinAscent === 0) { // makes font unreadable by windows
  32988. return false;
  32989. }
  32990. // OS/2 appears to be valid, resetting some fields
  32991. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32992. return true;
  32993. }
  32994. function createOS2Table(properties, charstrings, override) {
  32995. override = override || {
  32996. unitsPerEm: 0,
  32997. yMax: 0,
  32998. yMin: 0,
  32999. ascent: 0,
  33000. descent: 0
  33001. };
  33002. var ulUnicodeRange1 = 0;
  33003. var ulUnicodeRange2 = 0;
  33004. var ulUnicodeRange3 = 0;
  33005. var ulUnicodeRange4 = 0;
  33006. var firstCharIndex = null;
  33007. var lastCharIndex = 0;
  33008. if (charstrings) {
  33009. for (var code in charstrings) {
  33010. code |= 0;
  33011. if (firstCharIndex > code || !firstCharIndex) {
  33012. firstCharIndex = code;
  33013. }
  33014. if (lastCharIndex < code) {
  33015. lastCharIndex = code;
  33016. }
  33017. var position = getUnicodeRangeFor(code);
  33018. if (position < 32) {
  33019. ulUnicodeRange1 |= 1 << position;
  33020. } else if (position < 64) {
  33021. ulUnicodeRange2 |= 1 << position - 32;
  33022. } else if (position < 96) {
  33023. ulUnicodeRange3 |= 1 << position - 64;
  33024. } else if (position < 123) {
  33025. ulUnicodeRange4 |= 1 << position - 96;
  33026. } else {
  33027. error('Unicode ranges Bits > 123 are reserved for internal usage');
  33028. }
  33029. }
  33030. } else {
  33031. // TODO
  33032. firstCharIndex = 0;
  33033. lastCharIndex = 255;
  33034. }
  33035. var bbox = properties.bbox || [0, 0, 0, 0];
  33036. var unitsPerEm = (override.unitsPerEm ||
  33037. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  33038. // if the font units differ to the PDF glyph space units
  33039. // then scale up the values
  33040. var scale = (properties.ascentScaled ? 1.0 :
  33041. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  33042. var typoAscent = (override.ascent ||
  33043. Math.round(scale * (properties.ascent || bbox[3])));
  33044. var typoDescent = (override.descent ||
  33045. Math.round(scale * (properties.descent || bbox[1])));
  33046. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  33047. typoDescent = -typoDescent; // fixing incorrect descent
  33048. }
  33049. var winAscent = override.yMax || typoAscent;
  33050. var winDescent = -override.yMin || -typoDescent;
  33051. return '\x00\x03' + // version
  33052. '\x02\x24' + // xAvgCharWidth
  33053. '\x01\xF4' + // usWeightClass
  33054. '\x00\x05' + // usWidthClass
  33055. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  33056. '\x02\x8A' + // ySubscriptXSize
  33057. '\x02\xBB' + // ySubscriptYSize
  33058. '\x00\x00' + // ySubscriptXOffset
  33059. '\x00\x8C' + // ySubscriptYOffset
  33060. '\x02\x8A' + // ySuperScriptXSize
  33061. '\x02\xBB' + // ySuperScriptYSize
  33062. '\x00\x00' + // ySuperScriptXOffset
  33063. '\x01\xDF' + // ySuperScriptYOffset
  33064. '\x00\x31' + // yStrikeOutSize
  33065. '\x01\x02' + // yStrikeOutPosition
  33066. '\x00\x00' + // sFamilyClass
  33067. '\x00\x00\x06' +
  33068. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  33069. '\x00\x00\x00\x00\x00\x00' + // Panose
  33070. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  33071. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  33072. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  33073. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  33074. '\x2A\x32\x31\x2A' + // achVendID
  33075. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  33076. string16(firstCharIndex ||
  33077. properties.firstChar) + // usFirstCharIndex
  33078. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  33079. string16(typoAscent) + // sTypoAscender
  33080. string16(typoDescent) + // sTypoDescender
  33081. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  33082. string16(winAscent) + // usWinAscent
  33083. string16(winDescent) + // usWinDescent
  33084. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  33085. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  33086. string16(properties.xHeight) + // sxHeight
  33087. string16(properties.capHeight) + // sCapHeight
  33088. string16(0) + // usDefaultChar
  33089. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  33090. '\x00\x03'; // usMaxContext
  33091. }
  33092. function createPostTable(properties) {
  33093. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  33094. return ('\x00\x03\x00\x00' + // Version number
  33095. string32(angle) + // italicAngle
  33096. '\x00\x00' + // underlinePosition
  33097. '\x00\x00' + // underlineThickness
  33098. string32(properties.fixedPitch) + // isFixedPitch
  33099. '\x00\x00\x00\x00' + // minMemType42
  33100. '\x00\x00\x00\x00' + // maxMemType42
  33101. '\x00\x00\x00\x00' + // minMemType1
  33102. '\x00\x00\x00\x00'); // maxMemType1
  33103. }
  33104. function createNameTable(name, proto) {
  33105. if (!proto) {
  33106. proto = [[], []]; // no strings and unicode strings
  33107. }
  33108. var strings = [
  33109. proto[0][0] || 'Original licence', // 0.Copyright
  33110. proto[0][1] || name, // 1.Font family
  33111. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  33112. proto[0][3] || 'uniqueID', // 3.Unique ID
  33113. proto[0][4] || name, // 4.Full font name
  33114. proto[0][5] || 'Version 0.11', // 5.Version
  33115. proto[0][6] || '', // 6.Postscript name
  33116. proto[0][7] || 'Unknown', // 7.Trademark
  33117. proto[0][8] || 'Unknown', // 8.Manufacturer
  33118. proto[0][9] || 'Unknown' // 9.Designer
  33119. ];
  33120. // Mac want 1-byte per character strings while Windows want
  33121. // 2-bytes per character, so duplicate the names table
  33122. var stringsUnicode = [];
  33123. var i, ii, j, jj, str;
  33124. for (i = 0, ii = strings.length; i < ii; i++) {
  33125. str = proto[1][i] || strings[i];
  33126. var strBufUnicode = [];
  33127. for (j = 0, jj = str.length; j < jj; j++) {
  33128. strBufUnicode.push(string16(str.charCodeAt(j)));
  33129. }
  33130. stringsUnicode.push(strBufUnicode.join(''));
  33131. }
  33132. var names = [strings, stringsUnicode];
  33133. var platforms = ['\x00\x01', '\x00\x03'];
  33134. var encodings = ['\x00\x00', '\x00\x01'];
  33135. var languages = ['\x00\x00', '\x04\x09'];
  33136. var namesRecordCount = strings.length * platforms.length;
  33137. var nameTable =
  33138. '\x00\x00' + // format
  33139. string16(namesRecordCount) + // Number of names Record
  33140. string16(namesRecordCount * 12 + 6); // Storage
  33141. // Build the name records field
  33142. var strOffset = 0;
  33143. for (i = 0, ii = platforms.length; i < ii; i++) {
  33144. var strs = names[i];
  33145. for (j = 0, jj = strs.length; j < jj; j++) {
  33146. str = strs[j];
  33147. var nameRecord =
  33148. platforms[i] + // platform ID
  33149. encodings[i] + // encoding ID
  33150. languages[i] + // language ID
  33151. string16(j) + // name ID
  33152. string16(str.length) +
  33153. string16(strOffset);
  33154. nameTable += nameRecord;
  33155. strOffset += str.length;
  33156. }
  33157. }
  33158. nameTable += strings.join('') + stringsUnicode.join('');
  33159. return nameTable;
  33160. }
  33161. Font.prototype = {
  33162. name: null,
  33163. font: null,
  33164. mimetype: null,
  33165. encoding: null,
  33166. get renderer() {
  33167. var renderer = FontRendererFactory.create(this);
  33168. return shadow(this, 'renderer', renderer);
  33169. },
  33170. exportData: function Font_exportData() {
  33171. var data = {};
  33172. for (var i in this) {
  33173. if (this.hasOwnProperty(i)) {
  33174. data[i] = this[i];
  33175. }
  33176. }
  33177. return data;
  33178. },
  33179. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  33180. function readTableEntry(file) {
  33181. var tag = bytesToString(file.getBytes(4));
  33182. var checksum = file.getInt32();
  33183. var offset = file.getInt32() >>> 0;
  33184. var length = file.getInt32() >>> 0;
  33185. // Read the table associated data
  33186. var previousPosition = file.pos;
  33187. file.pos = file.start ? file.start : 0;
  33188. file.skip(offset);
  33189. var data = file.getBytes(length);
  33190. file.pos = previousPosition;
  33191. if (tag === 'head') {
  33192. // clearing checksum adjustment
  33193. data[8] = data[9] = data[10] = data[11] = 0;
  33194. data[17] |= 0x20; //Set font optimized for cleartype flag
  33195. }
  33196. return {
  33197. tag: tag,
  33198. checksum: checksum,
  33199. length: length,
  33200. offset: offset,
  33201. data: data
  33202. };
  33203. }
  33204. function readOpenTypeHeader(ttf) {
  33205. return {
  33206. version: bytesToString(ttf.getBytes(4)),
  33207. numTables: ttf.getUint16(),
  33208. searchRange: ttf.getUint16(),
  33209. entrySelector: ttf.getUint16(),
  33210. rangeShift: ttf.getUint16()
  33211. };
  33212. }
  33213. /**
  33214. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  33215. * PDF spec
  33216. */
  33217. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  33218. if (!cmap) {
  33219. warn('No cmap table available.');
  33220. return {
  33221. platformId: -1,
  33222. encodingId: -1,
  33223. mappings: [],
  33224. hasShortCmap: false
  33225. };
  33226. }
  33227. var segment;
  33228. var start = (font.start ? font.start : 0) + cmap.offset;
  33229. font.pos = start;
  33230. var version = font.getUint16();
  33231. var numTables = font.getUint16();
  33232. var potentialTable;
  33233. var canBreak = false;
  33234. // There's an order of preference in terms of which cmap subtable to
  33235. // use:
  33236. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  33237. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  33238. // The following takes advantage of the fact that the tables are sorted
  33239. // to work.
  33240. for (var i = 0; i < numTables; i++) {
  33241. var platformId = font.getUint16();
  33242. var encodingId = font.getUint16();
  33243. var offset = font.getInt32() >>> 0;
  33244. var useTable = false;
  33245. if (platformId === 0 && encodingId === 0) {
  33246. useTable = true;
  33247. // Continue the loop since there still may be a higher priority
  33248. // table.
  33249. } else if (platformId === 1 && encodingId === 0) {
  33250. useTable = true;
  33251. // Continue the loop since there still may be a higher priority
  33252. // table.
  33253. } else if (platformId === 3 && encodingId === 1 &&
  33254. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  33255. useTable = true;
  33256. if (!isSymbolicFont) {
  33257. canBreak = true;
  33258. }
  33259. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  33260. useTable = true;
  33261. canBreak = true;
  33262. }
  33263. if (useTable) {
  33264. potentialTable = {
  33265. platformId: platformId,
  33266. encodingId: encodingId,
  33267. offset: offset
  33268. };
  33269. }
  33270. if (canBreak) {
  33271. break;
  33272. }
  33273. }
  33274. if (potentialTable) {
  33275. font.pos = start + potentialTable.offset;
  33276. }
  33277. if (!potentialTable || font.peekByte() === -1) {
  33278. warn('Could not find a preferred cmap table.');
  33279. return {
  33280. platformId: -1,
  33281. encodingId: -1,
  33282. mappings: [],
  33283. hasShortCmap: false
  33284. };
  33285. }
  33286. var format = font.getUint16();
  33287. var length = font.getUint16();
  33288. var language = font.getUint16();
  33289. var hasShortCmap = false;
  33290. var mappings = [];
  33291. var j, glyphId;
  33292. // TODO(mack): refactor this cmap subtable reading logic out
  33293. if (format === 0) {
  33294. for (j = 0; j < 256; j++) {
  33295. var index = font.getByte();
  33296. if (!index) {
  33297. continue;
  33298. }
  33299. mappings.push({
  33300. charCode: j,
  33301. glyphId: index
  33302. });
  33303. }
  33304. hasShortCmap = true;
  33305. } else if (format === 4) {
  33306. // re-creating the table in format 4 since the encoding
  33307. // might be changed
  33308. var segCount = (font.getUint16() >> 1);
  33309. font.getBytes(6); // skipping range fields
  33310. var segIndex, segments = [];
  33311. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33312. segments.push({ end: font.getUint16() });
  33313. }
  33314. font.getUint16();
  33315. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33316. segments[segIndex].start = font.getUint16();
  33317. }
  33318. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33319. segments[segIndex].delta = font.getUint16();
  33320. }
  33321. var offsetsCount = 0;
  33322. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33323. segment = segments[segIndex];
  33324. var rangeOffset = font.getUint16();
  33325. if (!rangeOffset) {
  33326. segment.offsetIndex = -1;
  33327. continue;
  33328. }
  33329. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  33330. segment.offsetIndex = offsetIndex;
  33331. offsetsCount = Math.max(offsetsCount, offsetIndex +
  33332. segment.end - segment.start + 1);
  33333. }
  33334. var offsets = [];
  33335. for (j = 0; j < offsetsCount; j++) {
  33336. offsets.push(font.getUint16());
  33337. }
  33338. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33339. segment = segments[segIndex];
  33340. start = segment.start;
  33341. var end = segment.end;
  33342. var delta = segment.delta;
  33343. offsetIndex = segment.offsetIndex;
  33344. for (j = start; j <= end; j++) {
  33345. if (j === 0xFFFF) {
  33346. continue;
  33347. }
  33348. glyphId = (offsetIndex < 0 ?
  33349. j : offsets[offsetIndex + j - start]);
  33350. glyphId = (glyphId + delta) & 0xFFFF;
  33351. if (glyphId === 0) {
  33352. continue;
  33353. }
  33354. mappings.push({
  33355. charCode: j,
  33356. glyphId: glyphId
  33357. });
  33358. }
  33359. }
  33360. } else if (format === 6) {
  33361. // Format 6 is a 2-bytes dense mapping, which means the font data
  33362. // lives glue together even if they are pretty far in the unicode
  33363. // table. (This looks weird, so I can have missed something), this
  33364. // works on Linux but seems to fails on Mac so let's rewrite the
  33365. // cmap table to a 3-1-4 style
  33366. var firstCode = font.getUint16();
  33367. var entryCount = font.getUint16();
  33368. for (j = 0; j < entryCount; j++) {
  33369. glyphId = font.getUint16();
  33370. var charCode = firstCode + j;
  33371. mappings.push({
  33372. charCode: charCode,
  33373. glyphId: glyphId
  33374. });
  33375. }
  33376. } else {
  33377. warn('cmap table has unsupported format: ' + format);
  33378. return {
  33379. platformId: -1,
  33380. encodingId: -1,
  33381. mappings: [],
  33382. hasShortCmap: false
  33383. };
  33384. }
  33385. // removing duplicate entries
  33386. mappings.sort(function (a, b) {
  33387. return a.charCode - b.charCode;
  33388. });
  33389. for (i = 1; i < mappings.length; i++) {
  33390. if (mappings[i - 1].charCode === mappings[i].charCode) {
  33391. mappings.splice(i, 1);
  33392. i--;
  33393. }
  33394. }
  33395. return {
  33396. platformId: potentialTable.platformId,
  33397. encodingId: potentialTable.encodingId,
  33398. mappings: mappings,
  33399. hasShortCmap: hasShortCmap
  33400. };
  33401. }
  33402. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  33403. if (!header) {
  33404. if (metrics) {
  33405. metrics.data = null;
  33406. }
  33407. return;
  33408. }
  33409. font.pos = (font.start ? font.start : 0) + header.offset;
  33410. font.pos += header.length - 2;
  33411. var numOfMetrics = font.getUint16();
  33412. if (numOfMetrics > numGlyphs) {
  33413. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  33414. 'greater than the numGlyphs (' + numGlyphs + ')');
  33415. // Reduce numOfMetrics if it is greater than numGlyphs
  33416. numOfMetrics = numGlyphs;
  33417. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  33418. header.data[35] = numOfMetrics & 0x00ff;
  33419. }
  33420. var numOfSidebearings = numGlyphs - numOfMetrics;
  33421. var numMissing = numOfSidebearings -
  33422. ((metrics.length - numOfMetrics * 4) >> 1);
  33423. if (numMissing > 0) {
  33424. // For each missing glyph, we set both the width and lsb to 0 (zero).
  33425. // Since we need to add two properties for each glyph, this explains
  33426. // the use of |numMissing * 2| when initializing the typed array.
  33427. var entries = new Uint8Array(metrics.length + numMissing * 2);
  33428. entries.set(metrics.data);
  33429. metrics.data = entries;
  33430. }
  33431. }
  33432. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  33433. hintsValid) {
  33434. if (sourceEnd - sourceStart <= 12) {
  33435. // glyph with data less than 12 is invalid one
  33436. return 0;
  33437. }
  33438. var glyf = source.subarray(sourceStart, sourceEnd);
  33439. var contoursCount = (glyf[0] << 8) | glyf[1];
  33440. if (contoursCount & 0x8000) {
  33441. // complex glyph, writing as is
  33442. dest.set(glyf, destStart);
  33443. return glyf.length;
  33444. }
  33445. var i, j = 10, flagsCount = 0;
  33446. for (i = 0; i < contoursCount; i++) {
  33447. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  33448. flagsCount = endPoint + 1;
  33449. j += 2;
  33450. }
  33451. // skipping instructions
  33452. var instructionsStart = j;
  33453. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  33454. j += 2 + instructionsLength;
  33455. var instructionsEnd = j;
  33456. // validating flags
  33457. var coordinatesLength = 0;
  33458. for (i = 0; i < flagsCount; i++) {
  33459. var flag = glyf[j++];
  33460. if (flag & 0xC0) {
  33461. // reserved flags must be zero, cleaning up
  33462. glyf[j - 1] = flag & 0x3F;
  33463. }
  33464. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  33465. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  33466. coordinatesLength += xyLength;
  33467. if (flag & 8) {
  33468. var repeat = glyf[j++];
  33469. i += repeat;
  33470. coordinatesLength += repeat * xyLength;
  33471. }
  33472. }
  33473. // glyph without coordinates will be rejected
  33474. if (coordinatesLength === 0) {
  33475. return 0;
  33476. }
  33477. var glyphDataLength = j + coordinatesLength;
  33478. if (glyphDataLength > glyf.length) {
  33479. // not enough data for coordinates
  33480. return 0;
  33481. }
  33482. if (!hintsValid && instructionsLength > 0) {
  33483. dest.set(glyf.subarray(0, instructionsStart), destStart);
  33484. dest.set([0, 0], destStart + instructionsStart);
  33485. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  33486. destStart + instructionsStart + 2);
  33487. glyphDataLength -= instructionsLength;
  33488. if (glyf.length - glyphDataLength > 3) {
  33489. glyphDataLength = (glyphDataLength + 3) & ~3;
  33490. }
  33491. return glyphDataLength;
  33492. }
  33493. if (glyf.length - glyphDataLength > 3) {
  33494. // truncating and aligning to 4 bytes the long glyph data
  33495. glyphDataLength = (glyphDataLength + 3) & ~3;
  33496. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  33497. return glyphDataLength;
  33498. }
  33499. // glyph data is fine
  33500. dest.set(glyf, destStart);
  33501. return glyf.length;
  33502. }
  33503. function sanitizeHead(head, numGlyphs, locaLength) {
  33504. var data = head.data;
  33505. // Validate version:
  33506. // Should always be 0x00010000
  33507. var version = int32(data[0], data[1], data[2], data[3]);
  33508. if (version >> 16 !== 1) {
  33509. info('Attempting to fix invalid version in head table: ' + version);
  33510. data[0] = 0;
  33511. data[1] = 1;
  33512. data[2] = 0;
  33513. data[3] = 0;
  33514. }
  33515. var indexToLocFormat = int16(data[50], data[51]);
  33516. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  33517. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  33518. indexToLocFormat);
  33519. // The value of indexToLocFormat should be 0 if the loca table
  33520. // consists of short offsets, and should be 1 if the loca table
  33521. // consists of long offsets.
  33522. //
  33523. // The number of entries in the loca table should be numGlyphs + 1.
  33524. //
  33525. // Using this information, we can work backwards to deduce if the
  33526. // size of each offset in the loca table, and thus figure out the
  33527. // appropriate value for indexToLocFormat.
  33528. var numGlyphsPlusOne = numGlyphs + 1;
  33529. if (locaLength === numGlyphsPlusOne << 1) {
  33530. // 0x0000 indicates the loca table consists of short offsets
  33531. data[50] = 0;
  33532. data[51] = 0;
  33533. } else if (locaLength === numGlyphsPlusOne << 2) {
  33534. // 0x0001 indicates the loca table consists of long offsets
  33535. data[50] = 0;
  33536. data[51] = 1;
  33537. } else {
  33538. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  33539. }
  33540. }
  33541. }
  33542. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  33543. isGlyphLocationsLong, hintsValid,
  33544. dupFirstEntry) {
  33545. var itemSize, itemDecode, itemEncode;
  33546. if (isGlyphLocationsLong) {
  33547. itemSize = 4;
  33548. itemDecode = function fontItemDecodeLong(data, offset) {
  33549. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33550. (data[offset + 2] << 8) | data[offset + 3];
  33551. };
  33552. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33553. data[offset] = (value >>> 24) & 0xFF;
  33554. data[offset + 1] = (value >> 16) & 0xFF;
  33555. data[offset + 2] = (value >> 8) & 0xFF;
  33556. data[offset + 3] = value & 0xFF;
  33557. };
  33558. } else {
  33559. itemSize = 2;
  33560. itemDecode = function fontItemDecode(data, offset) {
  33561. return (data[offset] << 9) | (data[offset + 1] << 1);
  33562. };
  33563. itemEncode = function fontItemEncode(data, offset, value) {
  33564. data[offset] = (value >> 9) & 0xFF;
  33565. data[offset + 1] = (value >> 1) & 0xFF;
  33566. };
  33567. }
  33568. var locaData = loca.data;
  33569. var locaDataSize = itemSize * (1 + numGlyphs);
  33570. // is loca.data too short or long?
  33571. if (locaData.length !== locaDataSize) {
  33572. locaData = new Uint8Array(locaDataSize);
  33573. locaData.set(loca.data.subarray(0, locaDataSize));
  33574. loca.data = locaData;
  33575. }
  33576. // removing the invalid glyphs
  33577. var oldGlyfData = glyf.data;
  33578. var oldGlyfDataLength = oldGlyfData.length;
  33579. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33580. var startOffset = itemDecode(locaData, 0);
  33581. var writeOffset = 0;
  33582. var missingGlyphData = {};
  33583. itemEncode(locaData, 0, writeOffset);
  33584. var i, j;
  33585. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33586. var endOffset = itemDecode(locaData, j);
  33587. if (endOffset > oldGlyfDataLength &&
  33588. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33589. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33590. // the glyf table size, which makes last glyph out of range.
  33591. endOffset = oldGlyfDataLength;
  33592. }
  33593. if (endOffset > oldGlyfDataLength) {
  33594. // glyph end offset points outside glyf data, rejecting the glyph
  33595. itemEncode(locaData, j, writeOffset);
  33596. startOffset = endOffset;
  33597. continue;
  33598. }
  33599. if (startOffset === endOffset) {
  33600. missingGlyphData[i] = true;
  33601. }
  33602. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33603. newGlyfData, writeOffset, hintsValid);
  33604. writeOffset += newLength;
  33605. itemEncode(locaData, j, writeOffset);
  33606. startOffset = endOffset;
  33607. }
  33608. if (writeOffset === 0) {
  33609. // glyf table cannot be empty -- redoing the glyf and loca tables
  33610. // to have single glyph with one point
  33611. var simpleGlyph = new Uint8Array(
  33612. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33613. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33614. itemEncode(locaData, j, simpleGlyph.length);
  33615. }
  33616. glyf.data = simpleGlyph;
  33617. return missingGlyphData;
  33618. }
  33619. if (dupFirstEntry) {
  33620. var firstEntryLength = itemDecode(locaData, itemSize);
  33621. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33622. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33623. } else {
  33624. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33625. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33626. }
  33627. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33628. itemEncode(loca.data, locaData.length - itemSize,
  33629. writeOffset + firstEntryLength);
  33630. } else {
  33631. glyf.data = newGlyfData.subarray(0, writeOffset);
  33632. }
  33633. return missingGlyphData;
  33634. }
  33635. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33636. var start = (font.start ? font.start : 0) + post.offset;
  33637. font.pos = start;
  33638. var length = post.length, end = start + length;
  33639. var version = font.getInt32();
  33640. // skip rest to the tables
  33641. font.getBytes(28);
  33642. var glyphNames;
  33643. var valid = true;
  33644. var i;
  33645. switch (version) {
  33646. case 0x00010000:
  33647. glyphNames = MacStandardGlyphOrdering;
  33648. break;
  33649. case 0x00020000:
  33650. var numGlyphs = font.getUint16();
  33651. if (numGlyphs !== maxpNumGlyphs) {
  33652. valid = false;
  33653. break;
  33654. }
  33655. var glyphNameIndexes = [];
  33656. for (i = 0; i < numGlyphs; ++i) {
  33657. var index = font.getUint16();
  33658. if (index >= 32768) {
  33659. valid = false;
  33660. break;
  33661. }
  33662. glyphNameIndexes.push(index);
  33663. }
  33664. if (!valid) {
  33665. break;
  33666. }
  33667. var customNames = [];
  33668. var strBuf = [];
  33669. while (font.pos < end) {
  33670. var stringLength = font.getByte();
  33671. strBuf.length = stringLength;
  33672. for (i = 0; i < stringLength; ++i) {
  33673. strBuf[i] = String.fromCharCode(font.getByte());
  33674. }
  33675. customNames.push(strBuf.join(''));
  33676. }
  33677. glyphNames = [];
  33678. for (i = 0; i < numGlyphs; ++i) {
  33679. var j = glyphNameIndexes[i];
  33680. if (j < 258) {
  33681. glyphNames.push(MacStandardGlyphOrdering[j]);
  33682. continue;
  33683. }
  33684. glyphNames.push(customNames[j - 258]);
  33685. }
  33686. break;
  33687. case 0x00030000:
  33688. break;
  33689. default:
  33690. warn('Unknown/unsupported post table version ' + version);
  33691. valid = false;
  33692. if (properties.defaultEncoding) {
  33693. glyphNames = properties.defaultEncoding;
  33694. }
  33695. break;
  33696. }
  33697. properties.glyphNames = glyphNames;
  33698. return valid;
  33699. }
  33700. function readNameTable(nameTable) {
  33701. var start = (font.start ? font.start : 0) + nameTable.offset;
  33702. font.pos = start;
  33703. var names = [[], []];
  33704. var length = nameTable.length, end = start + length;
  33705. var format = font.getUint16();
  33706. var FORMAT_0_HEADER_LENGTH = 6;
  33707. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33708. // unsupported name table format or table "too" small
  33709. return names;
  33710. }
  33711. var numRecords = font.getUint16();
  33712. var stringsStart = font.getUint16();
  33713. var records = [];
  33714. var NAME_RECORD_LENGTH = 12;
  33715. var i, ii;
  33716. for (i = 0; i < numRecords &&
  33717. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33718. var r = {
  33719. platform: font.getUint16(),
  33720. encoding: font.getUint16(),
  33721. language: font.getUint16(),
  33722. name: font.getUint16(),
  33723. length: font.getUint16(),
  33724. offset: font.getUint16()
  33725. };
  33726. // using only Macintosh and Windows platform/encoding names
  33727. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33728. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33729. records.push(r);
  33730. }
  33731. }
  33732. for (i = 0, ii = records.length; i < ii; i++) {
  33733. var record = records[i];
  33734. var pos = start + stringsStart + record.offset;
  33735. if (pos + record.length > end) {
  33736. continue; // outside of name table, ignoring
  33737. }
  33738. font.pos = pos;
  33739. var nameIndex = record.name;
  33740. if (record.encoding) {
  33741. // unicode
  33742. var str = '';
  33743. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33744. str += String.fromCharCode(font.getUint16());
  33745. }
  33746. names[1][nameIndex] = str;
  33747. } else {
  33748. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33749. }
  33750. }
  33751. return names;
  33752. }
  33753. var TTOpsStackDeltas = [
  33754. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33755. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33756. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33757. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33758. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33759. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33760. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33761. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33762. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33763. // 0xC0-DF == -1 and 0xE0-FF == -2
  33764. function sanitizeTTProgram(table, ttContext) {
  33765. var data = table.data;
  33766. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33767. var stack = [];
  33768. var callstack = [];
  33769. var functionsCalled = [];
  33770. var tooComplexToFollowFunctions =
  33771. ttContext.tooComplexToFollowFunctions;
  33772. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33773. for (var ii = data.length; i < ii;) {
  33774. var op = data[i++];
  33775. // The TrueType instruction set docs can be found at
  33776. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33777. if (op === 0x40) { // NPUSHB - pushes n bytes
  33778. n = data[i++];
  33779. if (inFDEF || inELSE) {
  33780. i += n;
  33781. } else {
  33782. for (j = 0; j < n; j++) {
  33783. stack.push(data[i++]);
  33784. }
  33785. }
  33786. } else if (op === 0x41) { // NPUSHW - pushes n words
  33787. n = data[i++];
  33788. if (inFDEF || inELSE) {
  33789. i += n * 2;
  33790. } else {
  33791. for (j = 0; j < n; j++) {
  33792. b = data[i++];
  33793. stack.push((b << 8) | data[i++]);
  33794. }
  33795. }
  33796. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33797. n = op - 0xB0 + 1;
  33798. if (inFDEF || inELSE) {
  33799. i += n;
  33800. } else {
  33801. for (j = 0; j < n; j++) {
  33802. stack.push(data[i++]);
  33803. }
  33804. }
  33805. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33806. n = op - 0xB8 + 1;
  33807. if (inFDEF || inELSE) {
  33808. i += n * 2;
  33809. } else {
  33810. for (j = 0; j < n; j++) {
  33811. b = data[i++];
  33812. stack.push((b << 8) | data[i++]);
  33813. }
  33814. }
  33815. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33816. if (!inFDEF && !inELSE) {
  33817. // collecting inforamtion about which functions are used
  33818. funcId = stack[stack.length - 1];
  33819. ttContext.functionsUsed[funcId] = true;
  33820. if (funcId in ttContext.functionsStackDeltas) {
  33821. stack.length += ttContext.functionsStackDeltas[funcId];
  33822. } else if (funcId in ttContext.functionsDefined &&
  33823. functionsCalled.indexOf(funcId) < 0) {
  33824. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33825. functionsCalled.push(funcId);
  33826. pc = ttContext.functionsDefined[funcId];
  33827. if (!pc) {
  33828. warn('TT: CALL non-existent function');
  33829. ttContext.hintsValid = false;
  33830. return;
  33831. }
  33832. data = pc.data;
  33833. i = pc.i;
  33834. }
  33835. }
  33836. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33837. if (inFDEF || inELSE) {
  33838. warn('TT: nested FDEFs not allowed');
  33839. tooComplexToFollowFunctions = true;
  33840. }
  33841. inFDEF = true;
  33842. // collecting inforamtion about which functions are defined
  33843. lastDeff = i;
  33844. funcId = stack.pop();
  33845. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33846. } else if (op === 0x2D) { // ENDF - end of function
  33847. if (inFDEF) {
  33848. inFDEF = false;
  33849. lastEndf = i;
  33850. } else {
  33851. pc = callstack.pop();
  33852. if (!pc) {
  33853. warn('TT: ENDF bad stack');
  33854. ttContext.hintsValid = false;
  33855. return;
  33856. }
  33857. funcId = functionsCalled.pop();
  33858. data = pc.data;
  33859. i = pc.i;
  33860. ttContext.functionsStackDeltas[funcId] =
  33861. stack.length - pc.stackTop;
  33862. }
  33863. } else if (op === 0x89) { // IDEF - instruction definition
  33864. if (inFDEF || inELSE) {
  33865. warn('TT: nested IDEFs not allowed');
  33866. tooComplexToFollowFunctions = true;
  33867. }
  33868. inFDEF = true;
  33869. // recording it as a function to track ENDF
  33870. lastDeff = i;
  33871. } else if (op === 0x58) { // IF
  33872. ++ifLevel;
  33873. } else if (op === 0x1B) { // ELSE
  33874. inELSE = ifLevel;
  33875. } else if (op === 0x59) { // EIF
  33876. if (inELSE === ifLevel) {
  33877. inELSE = 0;
  33878. }
  33879. --ifLevel;
  33880. } else if (op === 0x1C) { // JMPR
  33881. if (!inFDEF && !inELSE) {
  33882. var offset = stack[stack.length - 1];
  33883. // only jumping forward to prevent infinite loop
  33884. if (offset > 0) {
  33885. i += offset - 1;
  33886. }
  33887. }
  33888. }
  33889. // Adjusting stack not extactly, but just enough to get function id
  33890. if (!inFDEF && !inELSE) {
  33891. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33892. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33893. if (op >= 0x71 && op <= 0x75) {
  33894. n = stack.pop();
  33895. if (n === n) {
  33896. stackDelta = -n * 2;
  33897. }
  33898. }
  33899. while (stackDelta < 0 && stack.length > 0) {
  33900. stack.pop();
  33901. stackDelta++;
  33902. }
  33903. while (stackDelta > 0) {
  33904. stack.push(NaN); // pushing any number into stack
  33905. stackDelta--;
  33906. }
  33907. }
  33908. }
  33909. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33910. var content = [data];
  33911. if (i > data.length) {
  33912. content.push(new Uint8Array(i - data.length));
  33913. }
  33914. if (lastDeff > lastEndf) {
  33915. warn('TT: complementing a missing function tail');
  33916. // new function definition started, but not finished
  33917. // complete function by [CLEAR, ENDF]
  33918. content.push(new Uint8Array([0x22, 0x2D]));
  33919. }
  33920. foldTTTable(table, content);
  33921. }
  33922. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33923. if (ttContext.tooComplexToFollowFunctions) {
  33924. return;
  33925. }
  33926. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33927. warn('TT: more functions defined than expected');
  33928. ttContext.hintsValid = false;
  33929. return;
  33930. }
  33931. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33932. if (j > maxFunctionDefs) {
  33933. warn('TT: invalid function id: ' + j);
  33934. ttContext.hintsValid = false;
  33935. return;
  33936. }
  33937. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33938. warn('TT: undefined function: ' + j);
  33939. ttContext.hintsValid = false;
  33940. return;
  33941. }
  33942. }
  33943. }
  33944. function foldTTTable(table, content) {
  33945. if (content.length > 1) {
  33946. // concatenating the content items
  33947. var newLength = 0;
  33948. var j, jj;
  33949. for (j = 0, jj = content.length; j < jj; j++) {
  33950. newLength += content[j].length;
  33951. }
  33952. newLength = (newLength + 3) & ~3;
  33953. var result = new Uint8Array(newLength);
  33954. var pos = 0;
  33955. for (j = 0, jj = content.length; j < jj; j++) {
  33956. result.set(content[j], pos);
  33957. pos += content[j].length;
  33958. }
  33959. table.data = result;
  33960. table.length = newLength;
  33961. }
  33962. }
  33963. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33964. var ttContext = {
  33965. functionsDefined: [],
  33966. functionsUsed: [],
  33967. functionsStackDeltas: [],
  33968. tooComplexToFollowFunctions: false,
  33969. hintsValid: true
  33970. };
  33971. if (fpgm) {
  33972. sanitizeTTProgram(fpgm, ttContext);
  33973. }
  33974. if (prep) {
  33975. sanitizeTTProgram(prep, ttContext);
  33976. }
  33977. if (fpgm) {
  33978. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33979. }
  33980. if (cvt && (cvt.length & 1)) {
  33981. var cvtData = new Uint8Array(cvt.length + 1);
  33982. cvtData.set(cvt.data);
  33983. cvt.data = cvtData;
  33984. }
  33985. return ttContext.hintsValid;
  33986. }
  33987. // The following steps modify the original font data, making copy
  33988. font = new Stream(new Uint8Array(font.getBytes()));
  33989. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33990. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33991. var header = readOpenTypeHeader(font);
  33992. var numTables = header.numTables;
  33993. var cff, cffFile;
  33994. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  33995. hmtx: null, maxp: null, name: null, post: null };
  33996. var table;
  33997. for (var i = 0; i < numTables; i++) {
  33998. table = readTableEntry(font);
  33999. if (VALID_TABLES.indexOf(table.tag) < 0) {
  34000. continue; // skipping table if it's not a required or optional table
  34001. }
  34002. if (table.length === 0) {
  34003. continue; // skipping empty tables
  34004. }
  34005. tables[table.tag] = table;
  34006. }
  34007. var isTrueType = !tables['CFF '];
  34008. if (!isTrueType) {
  34009. // OpenType font
  34010. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  34011. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  34012. // no major tables: throwing everything at CFFFont
  34013. cffFile = new Stream(tables['CFF '].data);
  34014. cff = new CFFFont(cffFile, properties);
  34015. adjustWidths(properties);
  34016. return this.convert(name, cff, properties);
  34017. }
  34018. delete tables.glyf;
  34019. delete tables.loca;
  34020. delete tables.fpgm;
  34021. delete tables.prep;
  34022. delete tables['cvt '];
  34023. this.isOpenType = true;
  34024. } else {
  34025. if (!tables.glyf || !tables.loca) {
  34026. error('Required "glyf" or "loca" tables are not found');
  34027. }
  34028. this.isOpenType = false;
  34029. }
  34030. if (!tables.maxp) {
  34031. error('Required "maxp" table is not found');
  34032. }
  34033. font.pos = (font.start || 0) + tables.maxp.offset;
  34034. var version = font.getInt32();
  34035. var numGlyphs = font.getUint16();
  34036. var maxFunctionDefs = 0;
  34037. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  34038. // maxZones can be invalid
  34039. font.pos += 8;
  34040. var maxZones = font.getUint16();
  34041. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  34042. tables.maxp.data[14] = 0;
  34043. tables.maxp.data[15] = 2;
  34044. }
  34045. font.pos += 4;
  34046. maxFunctionDefs = font.getUint16();
  34047. }
  34048. var dupFirstEntry = false;
  34049. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  34050. properties.toUnicode.get(0) > '\u0000') {
  34051. // oracle's defect (see 3427), duplicating first entry
  34052. dupFirstEntry = true;
  34053. numGlyphs++;
  34054. tables.maxp.data[4] = numGlyphs >> 8;
  34055. tables.maxp.data[5] = numGlyphs & 255;
  34056. }
  34057. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  34058. tables['cvt '], maxFunctionDefs);
  34059. if (!hintsValid) {
  34060. delete tables.fpgm;
  34061. delete tables.prep;
  34062. delete tables['cvt '];
  34063. }
  34064. // Ensure the hmtx table contains the advance width and
  34065. // sidebearings information for numGlyphs in the maxp table
  34066. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  34067. if (!tables.head) {
  34068. error('Required "head" table is not found');
  34069. }
  34070. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  34071. var missingGlyphs = {};
  34072. if (isTrueType) {
  34073. var isGlyphLocationsLong = int16(tables.head.data[50],
  34074. tables.head.data[51]);
  34075. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  34076. numGlyphs, isGlyphLocationsLong,
  34077. hintsValid, dupFirstEntry);
  34078. }
  34079. if (!tables.hhea) {
  34080. error('Required "hhea" table is not found');
  34081. }
  34082. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  34083. // Sometimes it's 0. That needs to be fixed
  34084. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  34085. tables.hhea.data[10] = 0xFF;
  34086. tables.hhea.data[11] = 0xFF;
  34087. }
  34088. // Extract some more font properties from the OpenType head and
  34089. // hhea tables; yMin and descent value are always negative.
  34090. var metricsOverride = {
  34091. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  34092. yMax: int16(tables.head.data[42], tables.head.data[43]),
  34093. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  34094. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  34095. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  34096. };
  34097. // PDF FontDescriptor metrics lie -- using data from actual font.
  34098. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  34099. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  34100. // The 'post' table has glyphs names.
  34101. if (tables.post) {
  34102. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  34103. if (!valid) {
  34104. tables.post = null;
  34105. }
  34106. }
  34107. var charCodeToGlyphId = [], charCode;
  34108. var toUnicode = properties.toUnicode, widths = properties.widths;
  34109. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  34110. toUnicode.length === 0x10000);
  34111. // Helper function to try to skip mapping of empty glyphs.
  34112. // Note: In some cases, just relying on the glyph data doesn't work,
  34113. // hence we also use a few heuristics to fix various PDF files.
  34114. function hasGlyph(glyphId, charCode, widthCode) {
  34115. if (!missingGlyphs[glyphId]) {
  34116. return true;
  34117. }
  34118. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  34119. return true;
  34120. }
  34121. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  34122. return true;
  34123. }
  34124. return false;
  34125. }
  34126. if (properties.type === 'CIDFontType2') {
  34127. var cidToGidMap = properties.cidToGidMap || [];
  34128. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  34129. properties.cMap.forEach(function(charCode, cid) {
  34130. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34131. var glyphId = -1;
  34132. if (isCidToGidMapEmpty) {
  34133. glyphId = charCode;
  34134. } else if (cidToGidMap[cid] !== undefined) {
  34135. glyphId = cidToGidMap[cid];
  34136. }
  34137. if (glyphId >= 0 && glyphId < numGlyphs &&
  34138. hasGlyph(glyphId, charCode, cid)) {
  34139. charCodeToGlyphId[charCode] = glyphId;
  34140. }
  34141. });
  34142. if (dupFirstEntry) {
  34143. charCodeToGlyphId[0] = numGlyphs - 1;
  34144. }
  34145. } else {
  34146. // Most of the following logic in this code branch is based on the
  34147. // 9.6.6.4 of the PDF spec.
  34148. var hasEncoding =
  34149. properties.differences.length > 0 || !!properties.baseEncodingName;
  34150. var cmapTable =
  34151. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  34152. var cmapPlatformId = cmapTable.platformId;
  34153. var cmapEncodingId = cmapTable.encodingId;
  34154. var cmapMappings = cmapTable.mappings;
  34155. var cmapMappingsLength = cmapMappings.length;
  34156. // The spec seems to imply that if the font is symbolic the encoding
  34157. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  34158. // where the the font is symbolic and it has an encoding.
  34159. if (hasEncoding &&
  34160. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  34161. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  34162. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  34163. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  34164. // When no preferred cmap table was found and |baseEncodingName| is
  34165. // one of the predefined encodings, we seem to obtain a better
  34166. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  34167. // TODO: Note that this is a hack which should be removed as soon as
  34168. // we have proper support for more exotic cmap tables.
  34169. var baseEncoding = [];
  34170. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  34171. properties.baseEncodingName === 'WinAnsiEncoding') {
  34172. baseEncoding = Encodings[properties.baseEncodingName];
  34173. }
  34174. for (charCode = 0; charCode < 256; charCode++) {
  34175. var glyphName;
  34176. if (this.differences && charCode in this.differences) {
  34177. glyphName = this.differences[charCode];
  34178. } else if (charCode in baseEncoding &&
  34179. baseEncoding[charCode] !== '') {
  34180. glyphName = baseEncoding[charCode];
  34181. } else {
  34182. glyphName = Encodings.StandardEncoding[charCode];
  34183. }
  34184. if (!glyphName) {
  34185. continue;
  34186. }
  34187. var unicodeOrCharCode, isUnicode = false;
  34188. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  34189. unicodeOrCharCode = GlyphsUnicode[glyphName];
  34190. isUnicode = true;
  34191. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  34192. // TODO: the encoding needs to be updated with mac os table.
  34193. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  34194. }
  34195. var found = false;
  34196. for (i = 0; i < cmapMappingsLength; ++i) {
  34197. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  34198. continue;
  34199. }
  34200. var code = isUnicode ? charCode : unicodeOrCharCode;
  34201. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  34202. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34203. found = true;
  34204. break;
  34205. }
  34206. }
  34207. if (!found && properties.glyphNames) {
  34208. // Try to map using the post table.
  34209. var glyphId = properties.glyphNames.indexOf(glyphName);
  34210. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  34211. charCodeToGlyphId[charCode] = glyphId;
  34212. } else {
  34213. charCodeToGlyphId[charCode] = 0; // notdef
  34214. }
  34215. }
  34216. }
  34217. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  34218. // Default Unicode semantics, use the charcodes as is.
  34219. for (i = 0; i < cmapMappingsLength; ++i) {
  34220. charCodeToGlyphId[cmapMappings[i].charCode] =
  34221. cmapMappings[i].glyphId;
  34222. }
  34223. } else {
  34224. // For (3, 0) cmap tables:
  34225. // The charcode key being stored in charCodeToGlyphId is the lower
  34226. // byte of the two-byte charcodes of the cmap table since according to
  34227. // the spec: 'each byte from the string shall be prepended with the
  34228. // high byte of the range [of charcodes in the cmap table], to form
  34229. // a two-byte character, which shall be used to select the
  34230. // associated glyph description from the subtable'.
  34231. //
  34232. // For (1, 0) cmap tables:
  34233. // 'single bytes from the string shall be used to look up the
  34234. // associated glyph descriptions from the subtable'. This means
  34235. // charcodes in the cmap will be single bytes, so no-op since
  34236. // glyph.charCode & 0xFF === glyph.charCode
  34237. for (i = 0; i < cmapMappingsLength; ++i) {
  34238. charCode = cmapMappings[i].charCode & 0xFF;
  34239. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34240. }
  34241. }
  34242. }
  34243. if (charCodeToGlyphId.length === 0) {
  34244. // defines at least one glyph
  34245. charCodeToGlyphId[0] = 0;
  34246. }
  34247. // Converting glyphs and ids into font's cmap table
  34248. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  34249. this.toFontChar = newMapping.toFontChar;
  34250. tables.cmap = {
  34251. tag: 'cmap',
  34252. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  34253. };
  34254. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  34255. tables['OS/2'] = {
  34256. tag: 'OS/2',
  34257. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  34258. metricsOverride)
  34259. };
  34260. }
  34261. // Rewrite the 'post' table if needed
  34262. if (!tables.post) {
  34263. tables.post = {
  34264. tag: 'post',
  34265. data: createPostTable(properties)
  34266. };
  34267. }
  34268. if (!isTrueType) {
  34269. try {
  34270. // Trying to repair CFF file
  34271. cffFile = new Stream(tables['CFF '].data);
  34272. var parser = new CFFParser(cffFile, properties);
  34273. cff = parser.parse();
  34274. var compiler = new CFFCompiler(cff);
  34275. tables['CFF '].data = compiler.compile();
  34276. } catch (e) {
  34277. warn('Failed to compile font ' + properties.loadedName);
  34278. }
  34279. }
  34280. // Re-creating 'name' table
  34281. if (!tables.name) {
  34282. tables.name = {
  34283. tag: 'name',
  34284. data: createNameTable(this.name)
  34285. };
  34286. } else {
  34287. // ... using existing 'name' table as prototype
  34288. var namePrototype = readNameTable(tables.name);
  34289. tables.name.data = createNameTable(name, namePrototype);
  34290. }
  34291. var builder = new OpenTypeFileBuilder(header.version);
  34292. for (var tableTag in tables) {
  34293. builder.addTable(tableTag, tables[tableTag].data);
  34294. }
  34295. return builder.toArray();
  34296. },
  34297. convert: function Font_convert(fontName, font, properties) {
  34298. // TODO: Check the charstring widths to determine this.
  34299. properties.fixedPitch = false;
  34300. var mapping = font.getGlyphMapping(properties);
  34301. var newMapping = adjustMapping(mapping, properties);
  34302. this.toFontChar = newMapping.toFontChar;
  34303. var numGlyphs = font.numGlyphs;
  34304. function getCharCodes(charCodeToGlyphId, glyphId) {
  34305. var charCodes = null;
  34306. for (var charCode in charCodeToGlyphId) {
  34307. if (glyphId === charCodeToGlyphId[charCode]) {
  34308. if (!charCodes) {
  34309. charCodes = [];
  34310. }
  34311. charCodes.push(charCode | 0);
  34312. }
  34313. }
  34314. return charCodes;
  34315. }
  34316. function createCharCode(charCodeToGlyphId, glyphId) {
  34317. for (var charCode in charCodeToGlyphId) {
  34318. if (glyphId === charCodeToGlyphId[charCode]) {
  34319. return charCode | 0;
  34320. }
  34321. }
  34322. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  34323. glyphId;
  34324. return newMapping.nextAvailableFontCharCode++;
  34325. }
  34326. var seacs = font.seacs;
  34327. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  34328. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  34329. var charset = font.getCharset();
  34330. var seacMap = Object.create(null);
  34331. for (var glyphId in seacs) {
  34332. glyphId |= 0;
  34333. var seac = seacs[glyphId];
  34334. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  34335. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  34336. var baseGlyphId = charset.indexOf(baseGlyphName);
  34337. var accentGlyphId = charset.indexOf(accentGlyphName);
  34338. if (baseGlyphId < 0 || accentGlyphId < 0) {
  34339. continue;
  34340. }
  34341. var accentOffset = {
  34342. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  34343. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  34344. };
  34345. var charCodes = getCharCodes(mapping, glyphId);
  34346. if (!charCodes) {
  34347. // There's no point in mapping it if the char code was never mapped
  34348. // to begin with.
  34349. continue;
  34350. }
  34351. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  34352. var charCode = charCodes[i];
  34353. // Find a fontCharCode that maps to the base and accent glyphs.
  34354. // If one doesn't exists, create it.
  34355. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  34356. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  34357. baseGlyphId);
  34358. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  34359. accentGlyphId);
  34360. seacMap[charCode] = {
  34361. baseFontCharCode: baseFontCharCode,
  34362. accentFontCharCode: accentFontCharCode,
  34363. accentOffset: accentOffset
  34364. };
  34365. }
  34366. }
  34367. properties.seacMap = seacMap;
  34368. }
  34369. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  34370. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  34371. // PostScript Font Program
  34372. builder.addTable('CFF ', font.data);
  34373. // OS/2 and Windows Specific metrics
  34374. builder.addTable('OS/2', createOS2Table(properties,
  34375. newMapping.charCodeToGlyphId));
  34376. // Character to glyphs mapping
  34377. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  34378. numGlyphs));
  34379. // Font header
  34380. builder.addTable('head',
  34381. '\x00\x01\x00\x00' + // Version number
  34382. '\x00\x00\x10\x00' + // fontRevision
  34383. '\x00\x00\x00\x00' + // checksumAdjustement
  34384. '\x5F\x0F\x3C\xF5' + // magicNumber
  34385. '\x00\x00' + // Flags
  34386. safeString16(unitsPerEm) + // unitsPerEM
  34387. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  34388. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  34389. '\x00\x00' + // xMin
  34390. safeString16(properties.descent) + // yMin
  34391. '\x0F\xFF' + // xMax
  34392. safeString16(properties.ascent) + // yMax
  34393. string16(properties.italicAngle ? 2 : 0) + // macStyle
  34394. '\x00\x11' + // lowestRecPPEM
  34395. '\x00\x00' + // fontDirectionHint
  34396. '\x00\x00' + // indexToLocFormat
  34397. '\x00\x00'); // glyphDataFormat
  34398. // Horizontal header
  34399. builder.addTable('hhea',
  34400. '\x00\x01\x00\x00' + // Version number
  34401. safeString16(properties.ascent) + // Typographic Ascent
  34402. safeString16(properties.descent) + // Typographic Descent
  34403. '\x00\x00' + // Line Gap
  34404. '\xFF\xFF' + // advanceWidthMax
  34405. '\x00\x00' + // minLeftSidebearing
  34406. '\x00\x00' + // minRightSidebearing
  34407. '\x00\x00' + // xMaxExtent
  34408. safeString16(properties.capHeight) + // caretSlopeRise
  34409. safeString16(Math.tan(properties.italicAngle) *
  34410. properties.xHeight) + // caretSlopeRun
  34411. '\x00\x00' + // caretOffset
  34412. '\x00\x00' + // -reserved-
  34413. '\x00\x00' + // -reserved-
  34414. '\x00\x00' + // -reserved-
  34415. '\x00\x00' + // -reserved-
  34416. '\x00\x00' + // metricDataFormat
  34417. string16(numGlyphs)); // Number of HMetrics
  34418. // Horizontal metrics
  34419. builder.addTable('hmtx', (function fontFieldsHmtx() {
  34420. var charstrings = font.charstrings;
  34421. var cffWidths = font.cff ? font.cff.widths : null;
  34422. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  34423. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  34424. var width = 0;
  34425. if (charstrings) {
  34426. var charstring = charstrings[i - 1];
  34427. width = 'width' in charstring ? charstring.width : 0;
  34428. } else if (cffWidths) {
  34429. width = Math.ceil(cffWidths[i] || 0);
  34430. }
  34431. hmtx += string16(width) + string16(0);
  34432. }
  34433. return hmtx;
  34434. })());
  34435. // Maximum profile
  34436. builder.addTable('maxp',
  34437. '\x00\x00\x50\x00' + // Version number
  34438. string16(numGlyphs)); // Num of glyphs
  34439. // Naming tables
  34440. builder.addTable('name', createNameTable(fontName));
  34441. // PostScript informations
  34442. builder.addTable('post', createPostTable(properties));
  34443. return builder.toArray();
  34444. },
  34445. /**
  34446. * Builds a char code to unicode map based on section 9.10 of the spec.
  34447. * @param {Object} properties Font properties object.
  34448. * @return {Object} A ToUnicodeMap object.
  34449. */
  34450. buildToUnicode: function Font_buildToUnicode(properties) {
  34451. // Section 9.10.2 Mapping Character Codes to Unicode Values
  34452. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  34453. return properties.toUnicode;
  34454. }
  34455. // According to the spec if the font is a simple font we should only map
  34456. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  34457. // the differences array only contains adobe standard or symbol set names,
  34458. // in pratice it seems better to always try to create a toUnicode
  34459. // map based of the default encoding.
  34460. var toUnicode, charcode;
  34461. if (!properties.composite /* is simple font */) {
  34462. toUnicode = [];
  34463. var encoding = properties.defaultEncoding.slice();
  34464. var baseEncodingName = properties.baseEncodingName;
  34465. // Merge in the differences array.
  34466. var differences = properties.differences;
  34467. for (charcode in differences) {
  34468. encoding[charcode] = differences[charcode];
  34469. }
  34470. for (charcode in encoding) {
  34471. // a) Map the character code to a character name.
  34472. var glyphName = encoding[charcode];
  34473. // b) Look up the character name in the Adobe Glyph List (see the
  34474. // Bibliography) to obtain the corresponding Unicode value.
  34475. if (glyphName === '') {
  34476. continue;
  34477. } else if (GlyphsUnicode[glyphName] === undefined) {
  34478. // (undocumented) c) Few heuristics to recognize unknown glyphs
  34479. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  34480. var code = 0;
  34481. switch (glyphName[0]) {
  34482. case 'G': // Gxx glyph
  34483. if (glyphName.length === 3) {
  34484. code = parseInt(glyphName.substr(1), 16);
  34485. }
  34486. break;
  34487. case 'g': // g00xx glyph
  34488. if (glyphName.length === 5) {
  34489. code = parseInt(glyphName.substr(1), 16);
  34490. }
  34491. break;
  34492. case 'C': // Cddd glyph
  34493. case 'c': // cddd glyph
  34494. if (glyphName.length >= 3) {
  34495. code = +glyphName.substr(1);
  34496. }
  34497. break;
  34498. }
  34499. if (code) {
  34500. // If |baseEncodingName| is one the predefined encodings,
  34501. // and |code| equals |charcode|, using the glyph defined in the
  34502. // baseEncoding seems to yield a better |toUnicode| mapping
  34503. // (fixes issue 5070).
  34504. if (baseEncodingName && code === +charcode) {
  34505. var baseEncoding = Encodings[baseEncodingName];
  34506. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  34507. toUnicode[charcode] =
  34508. String.fromCharCode(GlyphsUnicode[glyphName]);
  34509. continue;
  34510. }
  34511. }
  34512. toUnicode[charcode] = String.fromCharCode(code);
  34513. }
  34514. continue;
  34515. }
  34516. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  34517. }
  34518. return new ToUnicodeMap(toUnicode);
  34519. }
  34520. // If the font is a composite font that uses one of the predefined CMaps
  34521. // listed in Table 118 (except Identity–H and Identity–V) or whose
  34522. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  34523. // Adobe-Korea1 character collection:
  34524. if (properties.composite && (
  34525. (properties.cMap.builtInCMap &&
  34526. !(properties.cMap instanceof IdentityCMap)) ||
  34527. (properties.cidSystemInfo.registry === 'Adobe' &&
  34528. (properties.cidSystemInfo.ordering === 'GB1' ||
  34529. properties.cidSystemInfo.ordering === 'CNS1' ||
  34530. properties.cidSystemInfo.ordering === 'Japan1' ||
  34531. properties.cidSystemInfo.ordering === 'Korea1')))) {
  34532. // Then:
  34533. // a) Map the character code to a character identifier (CID) according
  34534. // to the font’s CMap.
  34535. // b) Obtain the registry and ordering of the character collection used
  34536. // by the font’s CMap (for example, Adobe and Japan1) from its
  34537. // CIDSystemInfo dictionary.
  34538. var registry = properties.cidSystemInfo.registry;
  34539. var ordering = properties.cidSystemInfo.ordering;
  34540. // c) Construct a second CMap name by concatenating the registry and
  34541. // ordering obtained in step (b) in the format registry–ordering–UCS2
  34542. // (for example, Adobe–Japan1–UCS2).
  34543. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  34544. // d) Obtain the CMap with the name constructed in step (c) (available
  34545. // from the ASN Web site; see the Bibliography).
  34546. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  34547. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  34548. var cMap = properties.cMap;
  34549. toUnicode = [];
  34550. cMap.forEach(function(charcode, cid) {
  34551. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34552. // e) Map the CID obtained in step (a) according to the CMap obtained
  34553. // in step (d), producing a Unicode value.
  34554. var ucs2 = ucs2CMap.lookup(cid);
  34555. if (ucs2) {
  34556. toUnicode[charcode] =
  34557. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  34558. ucs2.charCodeAt(1));
  34559. }
  34560. });
  34561. return new ToUnicodeMap(toUnicode);
  34562. }
  34563. // The viewer's choice, just use an identity map.
  34564. return new IdentityToUnicodeMap(properties.firstChar,
  34565. properties.lastChar);
  34566. },
  34567. get spaceWidth() {
  34568. if ('_shadowWidth' in this) {
  34569. return this._shadowWidth;
  34570. }
  34571. // trying to estimate space character width
  34572. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34573. var width;
  34574. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34575. var glyphName = possibleSpaceReplacements[i];
  34576. // if possible, getting width by glyph name
  34577. if (glyphName in this.widths) {
  34578. width = this.widths[glyphName];
  34579. break;
  34580. }
  34581. var glyphUnicode = GlyphsUnicode[glyphName];
  34582. // finding the charcode via unicodeToCID map
  34583. var charcode = 0;
  34584. if (this.composite) {
  34585. if (this.cMap.contains(glyphUnicode)) {
  34586. charcode = this.cMap.lookup(glyphUnicode);
  34587. }
  34588. }
  34589. // ... via toUnicode map
  34590. if (!charcode && this.toUnicode) {
  34591. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34592. }
  34593. // setting it to unicode if negative or undefined
  34594. if (charcode <= 0) {
  34595. charcode = glyphUnicode;
  34596. }
  34597. // trying to get width via charcode
  34598. width = this.widths[charcode];
  34599. if (width) {
  34600. break; // the non-zero width found
  34601. }
  34602. }
  34603. width = width || this.defaultWidth;
  34604. // Do not shadow the property here. See discussion:
  34605. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34606. this._shadowWidth = width;
  34607. return width;
  34608. },
  34609. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34610. var fontCharCode, width, operatorListId;
  34611. var widthCode = charcode;
  34612. if (this.cMap && this.cMap.contains(charcode)) {
  34613. widthCode = this.cMap.lookup(charcode);
  34614. }
  34615. width = this.widths[widthCode];
  34616. width = isNum(width) ? width : this.defaultWidth;
  34617. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34618. var unicode = this.toUnicode.get(charcode) || charcode;
  34619. if (typeof unicode === 'number') {
  34620. unicode = String.fromCharCode(unicode);
  34621. }
  34622. // First try the toFontChar map, if it's not there then try falling
  34623. // back to the char code.
  34624. fontCharCode = this.toFontChar[charcode] || charcode;
  34625. if (this.missingFile) {
  34626. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34627. }
  34628. if (this.isType3Font) {
  34629. // Font char code in this case is actually a glyph name.
  34630. operatorListId = fontCharCode;
  34631. }
  34632. var accent = null;
  34633. if (this.seacMap && this.seacMap[charcode]) {
  34634. var seac = this.seacMap[charcode];
  34635. fontCharCode = seac.baseFontCharCode;
  34636. accent = {
  34637. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34638. offset: seac.accentOffset
  34639. };
  34640. }
  34641. var fontChar = String.fromCharCode(fontCharCode);
  34642. var glyph = this.glyphCache[charcode];
  34643. if (!glyph ||
  34644. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34645. operatorListId, isSpace)) {
  34646. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34647. operatorListId, isSpace);
  34648. this.glyphCache[charcode] = glyph;
  34649. }
  34650. return glyph;
  34651. },
  34652. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34653. var charsCache = this.charsCache;
  34654. var glyphs, glyph, charcode;
  34655. // if we translated this string before, just grab it from the cache
  34656. if (charsCache) {
  34657. glyphs = charsCache[chars];
  34658. if (glyphs) {
  34659. return glyphs;
  34660. }
  34661. }
  34662. // lazily create the translation cache
  34663. if (!charsCache) {
  34664. charsCache = this.charsCache = Object.create(null);
  34665. }
  34666. glyphs = [];
  34667. var charsCacheKey = chars;
  34668. var i = 0, ii;
  34669. if (this.cMap) {
  34670. // composite fonts have multi-byte strings convert the string from
  34671. // single-byte to multi-byte
  34672. var c = {};
  34673. while (i < chars.length) {
  34674. this.cMap.readCharCode(chars, i, c);
  34675. charcode = c.charcode;
  34676. var length = c.length;
  34677. i += length;
  34678. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34679. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34680. glyph = this.charToGlyph(charcode, isSpace);
  34681. glyphs.push(glyph);
  34682. }
  34683. } else {
  34684. for (i = 0, ii = chars.length; i < ii; ++i) {
  34685. charcode = chars.charCodeAt(i);
  34686. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34687. glyphs.push(glyph);
  34688. }
  34689. }
  34690. // Enter the translated string into the cache
  34691. return (charsCache[charsCacheKey] = glyphs);
  34692. }
  34693. };
  34694. return Font;
  34695. })();
  34696. var ErrorFont = (function ErrorFontClosure() {
  34697. function ErrorFont(error) {
  34698. this.error = error;
  34699. this.loadedName = 'g_font_error';
  34700. this.loading = false;
  34701. }
  34702. ErrorFont.prototype = {
  34703. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34704. return [];
  34705. },
  34706. exportData: function ErrorFont_exportData() {
  34707. return {error: this.error};
  34708. }
  34709. };
  34710. return ErrorFont;
  34711. })();
  34712. /**
  34713. * Shared logic for building a char code to glyph id mapping for Type1 and
  34714. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34715. * @param {Object} properties Font properties object.
  34716. * @param {Object} builtInEncoding The encoding contained within the actual font
  34717. * data.
  34718. * @param {Array} Array of glyph names where the index is the glyph ID.
  34719. * @returns {Object} A char code to glyph ID map.
  34720. */
  34721. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34722. var charCodeToGlyphId = Object.create(null);
  34723. var glyphId, charCode, baseEncoding;
  34724. if (properties.baseEncodingName) {
  34725. // If a valid base encoding name was used, the mapping is initialized with
  34726. // that.
  34727. baseEncoding = Encodings[properties.baseEncodingName];
  34728. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34729. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34730. if (glyphId >= 0) {
  34731. charCodeToGlyphId[charCode] = glyphId;
  34732. } else {
  34733. charCodeToGlyphId[charCode] = 0; // notdef
  34734. }
  34735. }
  34736. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34737. // For a symbolic font the encoding should be the fonts built-in
  34738. // encoding.
  34739. for (charCode in builtInEncoding) {
  34740. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34741. }
  34742. } else {
  34743. // For non-symbolic fonts that don't have a base encoding the standard
  34744. // encoding should be used.
  34745. baseEncoding = Encodings.StandardEncoding;
  34746. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34747. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34748. if (glyphId >= 0) {
  34749. charCodeToGlyphId[charCode] = glyphId;
  34750. } else {
  34751. charCodeToGlyphId[charCode] = 0; // notdef
  34752. }
  34753. }
  34754. }
  34755. // Lastly, merge in the differences.
  34756. var differences = properties.differences;
  34757. if (differences) {
  34758. for (charCode in differences) {
  34759. var glyphName = differences[charCode];
  34760. glyphId = glyphNames.indexOf(glyphName);
  34761. if (glyphId >= 0) {
  34762. charCodeToGlyphId[charCode] = glyphId;
  34763. } else {
  34764. charCodeToGlyphId[charCode] = 0; // notdef
  34765. }
  34766. }
  34767. }
  34768. return charCodeToGlyphId;
  34769. }
  34770. /*
  34771. * CharStrings are encoded following the the CharString Encoding sequence
  34772. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  34773. * The value in a byte indicates a command, a number, or subsequent bytes
  34774. * that are to be interpreted in a special way.
  34775. *
  34776. * CharString Number Encoding:
  34777. * A CharString byte containing the values from 32 through 255 inclusive
  34778. * indicate an integer. These values are decoded in four ranges.
  34779. *
  34780. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  34781. * indicate the integer v - 139. Thus, the integer values from -107 through
  34782. * 107 inclusive may be encoded in single byte.
  34783. *
  34784. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  34785. * indicates an integer involving the next byte, w, according to the formula:
  34786. * [(v - 247) x 256] + w + 108
  34787. *
  34788. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  34789. * indicates an integer involving the next byte, w, according to the formula:
  34790. * -[(v - 251) * 256] - w - 108
  34791. *
  34792. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  34793. * are a two complement signed integer. The first of these bytes contains the
  34794. * highest order bits, the second byte contains the next higher order bits
  34795. * and the fourth byte contain the lowest order bits.
  34796. *
  34797. *
  34798. * CharString Command Encoding:
  34799. * CharStrings commands are encoded in 1 or 2 bytes.
  34800. *
  34801. * Single byte commands are encoded in 1 byte that contains a value between
  34802. * 0 and 31 inclusive.
  34803. * If a command byte contains the value 12, then the value in the next byte
  34804. * indicates a command. This "escape" mechanism allows many extra commands
  34805. * to be encoded and this encoding technique helps to minimize the length of
  34806. * the charStrings.
  34807. */
  34808. var Type1CharString = (function Type1CharStringClosure() {
  34809. var COMMAND_MAP = {
  34810. 'hstem': [1],
  34811. 'vstem': [3],
  34812. 'vmoveto': [4],
  34813. 'rlineto': [5],
  34814. 'hlineto': [6],
  34815. 'vlineto': [7],
  34816. 'rrcurveto': [8],
  34817. 'callsubr': [10],
  34818. 'flex': [12, 35],
  34819. 'drop' : [12, 18],
  34820. 'endchar': [14],
  34821. 'rmoveto': [21],
  34822. 'hmoveto': [22],
  34823. 'vhcurveto': [30],
  34824. 'hvcurveto': [31]
  34825. };
  34826. function Type1CharString() {
  34827. this.width = 0;
  34828. this.lsb = 0;
  34829. this.flexing = false;
  34830. this.output = [];
  34831. this.stack = [];
  34832. }
  34833. Type1CharString.prototype = {
  34834. convert: function Type1CharString_convert(encoded, subrs) {
  34835. var count = encoded.length;
  34836. var error = false;
  34837. var wx, sbx, subrNumber;
  34838. for (var i = 0; i < count; i++) {
  34839. var value = encoded[i];
  34840. if (value < 32) {
  34841. if (value === 12) {
  34842. value = (value << 8) + encoded[++i];
  34843. }
  34844. switch (value) {
  34845. case 1: // hstem
  34846. if (!HINTING_ENABLED) {
  34847. this.stack = [];
  34848. break;
  34849. }
  34850. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34851. break;
  34852. case 3: // vstem
  34853. if (!HINTING_ENABLED) {
  34854. this.stack = [];
  34855. break;
  34856. }
  34857. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34858. break;
  34859. case 4: // vmoveto
  34860. if (this.flexing) {
  34861. if (this.stack.length < 1) {
  34862. error = true;
  34863. break;
  34864. }
  34865. // Add the dx for flex and but also swap the values so they are
  34866. // the right order.
  34867. var dy = this.stack.pop();
  34868. this.stack.push(0, dy);
  34869. break;
  34870. }
  34871. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  34872. break;
  34873. case 5: // rlineto
  34874. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  34875. break;
  34876. case 6: // hlineto
  34877. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  34878. break;
  34879. case 7: // vlineto
  34880. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  34881. break;
  34882. case 8: // rrcurveto
  34883. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  34884. break;
  34885. case 9: // closepath
  34886. // closepath is a Type1 command that does not take argument and is
  34887. // useless in Type2 and it can simply be ignored.
  34888. this.stack = [];
  34889. break;
  34890. case 10: // callsubr
  34891. if (this.stack.length < 1) {
  34892. error = true;
  34893. break;
  34894. }
  34895. subrNumber = this.stack.pop();
  34896. error = this.convert(subrs[subrNumber], subrs);
  34897. break;
  34898. case 11: // return
  34899. return error;
  34900. case 13: // hsbw
  34901. if (this.stack.length < 2) {
  34902. error = true;
  34903. break;
  34904. }
  34905. // To convert to type2 we have to move the width value to the
  34906. // first part of the charstring and then use hmoveto with lsb.
  34907. wx = this.stack.pop();
  34908. sbx = this.stack.pop();
  34909. this.lsb = sbx;
  34910. this.width = wx;
  34911. this.stack.push(wx, sbx);
  34912. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  34913. break;
  34914. case 14: // endchar
  34915. this.output.push(COMMAND_MAP.endchar[0]);
  34916. break;
  34917. case 21: // rmoveto
  34918. if (this.flexing) {
  34919. break;
  34920. }
  34921. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  34922. break;
  34923. case 22: // hmoveto
  34924. if (this.flexing) {
  34925. // Add the dy for flex.
  34926. this.stack.push(0);
  34927. break;
  34928. }
  34929. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  34930. break;
  34931. case 30: // vhcurveto
  34932. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  34933. break;
  34934. case 31: // hvcurveto
  34935. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  34936. break;
  34937. case (12 << 8) + 0: // dotsection
  34938. // dotsection is a Type1 command to specify some hinting feature
  34939. // for dots that do not take a parameter and it can safely be
  34940. // ignored for Type2.
  34941. this.stack = [];
  34942. break;
  34943. case (12 << 8) + 1: // vstem3
  34944. if (!HINTING_ENABLED) {
  34945. this.stack = [];
  34946. break;
  34947. }
  34948. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  34949. // multiple parameters, so instead of returning [vh]stem3 take a
  34950. // shortcut and return [vhstem] instead.
  34951. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34952. break;
  34953. case (12 << 8) + 2: // hstem3
  34954. if (!HINTING_ENABLED) {
  34955. this.stack = [];
  34956. break;
  34957. }
  34958. // See vstem3.
  34959. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34960. break;
  34961. case (12 << 8) + 6: // seac
  34962. // seac is like type 2's special endchar but it doesn't use the
  34963. // first argument asb, so remove it.
  34964. if (SEAC_ANALYSIS_ENABLED) {
  34965. this.seac = this.stack.splice(-4, 4);
  34966. error = this.executeCommand(0, COMMAND_MAP.endchar);
  34967. } else {
  34968. error = this.executeCommand(4, COMMAND_MAP.endchar);
  34969. }
  34970. break;
  34971. case (12 << 8) + 7: // sbw
  34972. if (this.stack.length < 4) {
  34973. error = true;
  34974. break;
  34975. }
  34976. // To convert to type2 we have to move the width value to the
  34977. // first part of the charstring and then use rmoveto with
  34978. // (dx, dy). The height argument will not be used for vmtx and
  34979. // vhea tables reconstruction -- ignoring it.
  34980. var wy = this.stack.pop();
  34981. wx = this.stack.pop();
  34982. var sby = this.stack.pop();
  34983. sbx = this.stack.pop();
  34984. this.lsb = sbx;
  34985. this.width = wx;
  34986. this.stack.push(wx, sbx, sby);
  34987. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  34988. break;
  34989. case (12 << 8) + 12: // div
  34990. if (this.stack.length < 2) {
  34991. error = true;
  34992. break;
  34993. }
  34994. var num2 = this.stack.pop();
  34995. var num1 = this.stack.pop();
  34996. this.stack.push(num1 / num2);
  34997. break;
  34998. case (12 << 8) + 16: // callothersubr
  34999. if (this.stack.length < 2) {
  35000. error = true;
  35001. break;
  35002. }
  35003. subrNumber = this.stack.pop();
  35004. var numArgs = this.stack.pop();
  35005. if (subrNumber === 0 && numArgs === 3) {
  35006. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  35007. this.stack.push(
  35008. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  35009. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  35010. flexArgs[4], // bcp2x
  35011. flexArgs[5], // bcp2y
  35012. flexArgs[6], // p2x
  35013. flexArgs[7], // p2y
  35014. flexArgs[8], // bcp3x
  35015. flexArgs[9], // bcp3y
  35016. flexArgs[10], // bcp4x
  35017. flexArgs[11], // bcp4y
  35018. flexArgs[12], // p3x
  35019. flexArgs[13], // p3y
  35020. flexArgs[14] // flexDepth
  35021. // 15 = finalx unused by flex
  35022. // 16 = finaly unused by flex
  35023. );
  35024. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  35025. this.flexing = false;
  35026. this.stack.push(flexArgs[15], flexArgs[16]);
  35027. } else if (subrNumber === 1 && numArgs === 0) {
  35028. this.flexing = true;
  35029. }
  35030. break;
  35031. case (12 << 8) + 17: // pop
  35032. // Ignore this since it is only used with othersubr.
  35033. break;
  35034. case (12 << 8) + 33: // setcurrentpoint
  35035. // Ignore for now.
  35036. this.stack = [];
  35037. break;
  35038. default:
  35039. warn('Unknown type 1 charstring command of "' + value + '"');
  35040. break;
  35041. }
  35042. if (error) {
  35043. break;
  35044. }
  35045. continue;
  35046. } else if (value <= 246) {
  35047. value = value - 139;
  35048. } else if (value <= 250) {
  35049. value = ((value - 247) * 256) + encoded[++i] + 108;
  35050. } else if (value <= 254) {
  35051. value = -((value - 251) * 256) - encoded[++i] - 108;
  35052. } else {
  35053. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  35054. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  35055. }
  35056. this.stack.push(value);
  35057. }
  35058. return error;
  35059. },
  35060. executeCommand: function(howManyArgs, command, keepStack) {
  35061. var stackLength = this.stack.length;
  35062. if (howManyArgs > stackLength) {
  35063. return true;
  35064. }
  35065. var start = stackLength - howManyArgs;
  35066. for (var i = start; i < stackLength; i++) {
  35067. var value = this.stack[i];
  35068. if (value === (value | 0)) { // int
  35069. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  35070. } else { // fixed point
  35071. value = (65536 * value) | 0;
  35072. this.output.push(255,
  35073. (value >> 24) & 0xFF,
  35074. (value >> 16) & 0xFF,
  35075. (value >> 8) & 0xFF,
  35076. value & 0xFF);
  35077. }
  35078. }
  35079. this.output.push.apply(this.output, command);
  35080. if (keepStack) {
  35081. this.stack.splice(start, howManyArgs);
  35082. } else {
  35083. this.stack.length = 0;
  35084. }
  35085. return false;
  35086. }
  35087. };
  35088. return Type1CharString;
  35089. })();
  35090. /*
  35091. * Type1Parser encapsulate the needed code for parsing a Type1 font
  35092. * program. Some of its logic depends on the Type2 charstrings
  35093. * structure.
  35094. * Note: this doesn't really parse the font since that would require evaluation
  35095. * of PostScript, but it is possible in most cases to extract what we need
  35096. * without a full parse.
  35097. */
  35098. var Type1Parser = (function Type1ParserClosure() {
  35099. /*
  35100. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  35101. * of Plaintext Bytes. The function took a key as a parameter which can be
  35102. * for decrypting the eexec block of for decoding charStrings.
  35103. */
  35104. var EEXEC_ENCRYPT_KEY = 55665;
  35105. var CHAR_STRS_ENCRYPT_KEY = 4330;
  35106. function isHexDigit(code) {
  35107. return code >= 48 && code <= 57 || // '0'-'9'
  35108. code >= 65 && code <= 70 || // 'A'-'F'
  35109. code >= 97 && code <= 102; // 'a'-'f'
  35110. }
  35111. function decrypt(data, key, discardNumber) {
  35112. var r = key | 0, c1 = 52845, c2 = 22719;
  35113. var count = data.length;
  35114. var decrypted = new Uint8Array(count);
  35115. for (var i = 0; i < count; i++) {
  35116. var value = data[i];
  35117. decrypted[i] = value ^ (r >> 8);
  35118. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  35119. }
  35120. return Array.prototype.slice.call(decrypted, discardNumber);
  35121. }
  35122. function decryptAscii(data, key, discardNumber) {
  35123. var r = key | 0, c1 = 52845, c2 = 22719;
  35124. var count = data.length, maybeLength = count >>> 1;
  35125. var decrypted = new Uint8Array(maybeLength);
  35126. var i, j;
  35127. for (i = 0, j = 0; i < count; i++) {
  35128. var digit1 = data[i];
  35129. if (!isHexDigit(digit1)) {
  35130. continue;
  35131. }
  35132. i++;
  35133. var digit2;
  35134. while (i < count && !isHexDigit(digit2 = data[i])) {
  35135. i++;
  35136. }
  35137. if (i < count) {
  35138. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  35139. decrypted[j++] = value ^ (r >> 8);
  35140. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  35141. }
  35142. }
  35143. return Array.prototype.slice.call(decrypted, discardNumber, j);
  35144. }
  35145. function isSpecial(c) {
  35146. return c === 0x2F || // '/'
  35147. c === 0x5B || c === 0x5D || // '[', ']'
  35148. c === 0x7B || c === 0x7D || // '{', '}'
  35149. c === 0x28 || c === 0x29; // '(', ')'
  35150. }
  35151. function Type1Parser(stream, encrypted) {
  35152. if (encrypted) {
  35153. var data = stream.getBytes();
  35154. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  35155. isHexDigit(data[2]) && isHexDigit(data[3]));
  35156. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  35157. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  35158. }
  35159. this.stream = stream;
  35160. this.nextChar();
  35161. }
  35162. Type1Parser.prototype = {
  35163. readNumberArray: function Type1Parser_readNumberArray() {
  35164. this.getToken(); // read '[' or '{' (arrays can start with either)
  35165. var array = [];
  35166. while (true) {
  35167. var token = this.getToken();
  35168. if (token === null || token === ']' || token === '}') {
  35169. break;
  35170. }
  35171. array.push(parseFloat(token || 0));
  35172. }
  35173. return array;
  35174. },
  35175. readNumber: function Type1Parser_readNumber() {
  35176. var token = this.getToken();
  35177. return parseFloat(token || 0);
  35178. },
  35179. readInt: function Type1Parser_readInt() {
  35180. // Use '| 0' to prevent setting a double into length such as the double
  35181. // does not flow into the loop variable.
  35182. var token = this.getToken();
  35183. return parseInt(token || 0, 10) | 0;
  35184. },
  35185. readBoolean: function Type1Parser_readBoolean() {
  35186. var token = this.getToken();
  35187. // Use 1 and 0 since that's what type2 charstrings use.
  35188. return token === 'true' ? 1 : 0;
  35189. },
  35190. nextChar : function Type1_nextChar() {
  35191. return (this.currentChar = this.stream.getByte());
  35192. },
  35193. getToken: function Type1Parser_getToken() {
  35194. // Eat whitespace and comments.
  35195. var comment = false;
  35196. var ch = this.currentChar;
  35197. while (true) {
  35198. if (ch === -1) {
  35199. return null;
  35200. }
  35201. if (comment) {
  35202. if (ch === 0x0A || ch === 0x0D) {
  35203. comment = false;
  35204. }
  35205. } else if (ch === 0x25) { // '%'
  35206. comment = true;
  35207. } else if (!Lexer.isSpace(ch)) {
  35208. break;
  35209. }
  35210. ch = this.nextChar();
  35211. }
  35212. if (isSpecial(ch)) {
  35213. this.nextChar();
  35214. return String.fromCharCode(ch);
  35215. }
  35216. var token = '';
  35217. do {
  35218. token += String.fromCharCode(ch);
  35219. ch = this.nextChar();
  35220. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  35221. return token;
  35222. },
  35223. /*
  35224. * Returns an object containing a Subrs array and a CharStrings
  35225. * array extracted from and eexec encrypted block of data
  35226. */
  35227. extractFontProgram: function Type1Parser_extractFontProgram() {
  35228. var stream = this.stream;
  35229. var subrs = [], charstrings = [];
  35230. var program = {
  35231. subrs: [],
  35232. charstrings: [],
  35233. properties: {
  35234. 'privateData': {
  35235. 'lenIV': 4
  35236. }
  35237. }
  35238. };
  35239. var token, length, data, lenIV, encoded;
  35240. while ((token = this.getToken()) !== null) {
  35241. if (token !== '/') {
  35242. continue;
  35243. }
  35244. token = this.getToken();
  35245. switch (token) {
  35246. case 'CharStrings':
  35247. // The number immediately following CharStrings must be greater or
  35248. // equal to the number of CharStrings.
  35249. this.getToken();
  35250. this.getToken(); // read in 'dict'
  35251. this.getToken(); // read in 'dup'
  35252. this.getToken(); // read in 'begin'
  35253. while(true) {
  35254. token = this.getToken();
  35255. if (token === null || token === 'end') {
  35256. break;
  35257. }
  35258. if (token !== '/') {
  35259. continue;
  35260. }
  35261. var glyph = this.getToken();
  35262. length = this.readInt();
  35263. this.getToken(); // read in 'RD' or '-|'
  35264. data = stream.makeSubStream(stream.pos, length);
  35265. lenIV = program.properties.privateData['lenIV'];
  35266. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35267. // Skip past the required space and binary data.
  35268. stream.skip(length);
  35269. this.nextChar();
  35270. token = this.getToken(); // read in 'ND' or '|-'
  35271. if (token === 'noaccess') {
  35272. this.getToken(); // read in 'def'
  35273. }
  35274. charstrings.push({
  35275. glyph: glyph,
  35276. encoded: encoded
  35277. });
  35278. }
  35279. break;
  35280. case 'Subrs':
  35281. var num = this.readInt();
  35282. this.getToken(); // read in 'array'
  35283. while ((token = this.getToken()) === 'dup') {
  35284. var index = this.readInt();
  35285. length = this.readInt();
  35286. this.getToken(); // read in 'RD' or '-|'
  35287. data = stream.makeSubStream(stream.pos, length);
  35288. lenIV = program.properties.privateData['lenIV'];
  35289. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35290. // Skip past the required space and binary data.
  35291. stream.skip(length);
  35292. this.nextChar();
  35293. token = this.getToken(); // read in 'NP' or '|'
  35294. if (token === 'noaccess') {
  35295. this.getToken(); // read in 'put'
  35296. }
  35297. subrs[index] = encoded;
  35298. }
  35299. break;
  35300. case 'BlueValues':
  35301. case 'OtherBlues':
  35302. case 'FamilyBlues':
  35303. case 'FamilyOtherBlues':
  35304. var blueArray = this.readNumberArray();
  35305. // *Blue* values may contain invalid data: disables reading of
  35306. // those values when hinting is disabled.
  35307. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  35308. HINTING_ENABLED) {
  35309. program.properties.privateData[token] = blueArray;
  35310. }
  35311. break;
  35312. case 'StemSnapH':
  35313. case 'StemSnapV':
  35314. program.properties.privateData[token] = this.readNumberArray();
  35315. break;
  35316. case 'StdHW':
  35317. case 'StdVW':
  35318. program.properties.privateData[token] =
  35319. this.readNumberArray()[0];
  35320. break;
  35321. case 'BlueShift':
  35322. case 'lenIV':
  35323. case 'BlueFuzz':
  35324. case 'BlueScale':
  35325. case 'LanguageGroup':
  35326. case 'ExpansionFactor':
  35327. program.properties.privateData[token] = this.readNumber();
  35328. break;
  35329. case 'ForceBold':
  35330. program.properties.privateData[token] = this.readBoolean();
  35331. break;
  35332. }
  35333. }
  35334. for (var i = 0; i < charstrings.length; i++) {
  35335. glyph = charstrings[i].glyph;
  35336. encoded = charstrings[i].encoded;
  35337. var charString = new Type1CharString();
  35338. var error = charString.convert(encoded, subrs);
  35339. var output = charString.output;
  35340. if (error) {
  35341. // It seems when FreeType encounters an error while evaluating a glyph
  35342. // that it completely ignores the glyph so we'll mimic that behaviour
  35343. // here and put an endchar to make the validator happy.
  35344. output = [14];
  35345. }
  35346. program.charstrings.push({
  35347. glyphName: glyph,
  35348. charstring: output,
  35349. width: charString.width,
  35350. lsb: charString.lsb,
  35351. seac: charString.seac
  35352. });
  35353. }
  35354. return program;
  35355. },
  35356. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  35357. var token;
  35358. while ((token = this.getToken()) !== null) {
  35359. if (token !== '/') {
  35360. continue;
  35361. }
  35362. token = this.getToken();
  35363. switch (token) {
  35364. case 'FontMatrix':
  35365. var matrix = this.readNumberArray();
  35366. properties.fontMatrix = matrix;
  35367. break;
  35368. case 'Encoding':
  35369. var encodingArg = this.getToken();
  35370. var encoding;
  35371. if (!/^\d+$/.test(encodingArg)) {
  35372. // encoding name is specified
  35373. encoding = Encodings[encodingArg];
  35374. } else {
  35375. encoding = [];
  35376. var size = parseInt(encodingArg, 10) | 0;
  35377. this.getToken(); // read in 'array'
  35378. for (var j = 0; j < size; j++) {
  35379. token = this.getToken();
  35380. // skipping till first dup or def (e.g. ignoring for statement)
  35381. while (token !== 'dup' && token !== 'def') {
  35382. token = this.getToken();
  35383. if (token === null) {
  35384. return; // invalid header
  35385. }
  35386. }
  35387. if (token === 'def') {
  35388. break; // read all array data
  35389. }
  35390. var index = this.readInt();
  35391. this.getToken(); // read in '/'
  35392. var glyph = this.getToken();
  35393. encoding[index] = glyph;
  35394. this.getToken(); // read the in 'put'
  35395. }
  35396. }
  35397. properties.builtInEncoding = encoding;
  35398. break;
  35399. case 'FontBBox':
  35400. var fontBBox = this.readNumberArray();
  35401. // adjusting ascent/descent
  35402. properties.ascent = fontBBox[3];
  35403. properties.descent = fontBBox[1];
  35404. properties.ascentScaled = true;
  35405. break;
  35406. }
  35407. }
  35408. }
  35409. };
  35410. return Type1Parser;
  35411. })();
  35412. /**
  35413. * The CFF class takes a Type1 file and wrap it into a
  35414. * 'Compact Font Format' which itself embed Type2 charstrings.
  35415. */
  35416. var CFFStandardStrings = [
  35417. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  35418. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  35419. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  35420. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  35421. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  35422. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  35423. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  35424. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  35425. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  35426. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  35427. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  35428. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  35429. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  35430. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  35431. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  35432. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  35433. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  35434. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  35435. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  35436. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  35437. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  35438. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  35439. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  35440. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  35441. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  35442. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  35443. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  35444. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  35445. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  35446. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  35447. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  35448. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  35449. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  35450. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  35451. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  35452. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  35453. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  35454. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  35455. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  35456. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  35457. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  35458. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  35459. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  35460. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  35461. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  35462. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  35463. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  35464. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  35465. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  35466. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  35467. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  35468. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  35469. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  35470. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  35471. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  35472. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  35473. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  35474. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  35475. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  35476. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  35477. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  35478. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  35479. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  35480. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  35481. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  35482. ];
  35483. // Type1Font is also a CIDFontType0.
  35484. var Type1Font = function Type1Font(name, file, properties) {
  35485. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  35486. // Also, length1 and length2 might be off by 6 bytes as well.
  35487. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  35488. var PFB_HEADER_SIZE = 6;
  35489. var headerBlockLength = properties.length1;
  35490. var eexecBlockLength = properties.length2;
  35491. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  35492. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  35493. if (pfbHeaderPresent) {
  35494. file.skip(PFB_HEADER_SIZE);
  35495. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35496. (pfbHeader[3] << 8) | pfbHeader[2];
  35497. }
  35498. // Get the data block containing glyphs and subrs informations
  35499. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  35500. var headerBlockParser = new Type1Parser(headerBlock);
  35501. headerBlockParser.extractFontHeader(properties);
  35502. if (pfbHeaderPresent) {
  35503. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  35504. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35505. (pfbHeader[3] << 8) | pfbHeader[2];
  35506. }
  35507. // Decrypt the data blocks and retrieve it's content
  35508. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  35509. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  35510. var data = eexecBlockParser.extractFontProgram();
  35511. for (var info in data.properties) {
  35512. properties[info] = data.properties[info];
  35513. }
  35514. var charstrings = data.charstrings;
  35515. var type2Charstrings = this.getType2Charstrings(charstrings);
  35516. var subrs = this.getType2Subrs(data.subrs);
  35517. this.charstrings = charstrings;
  35518. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  35519. subrs, properties);
  35520. this.seacs = this.getSeacs(data.charstrings);
  35521. };
  35522. Type1Font.prototype = {
  35523. get numGlyphs() {
  35524. return this.charstrings.length + 1;
  35525. },
  35526. getCharset: function Type1Font_getCharset() {
  35527. var charset = ['.notdef'];
  35528. var charstrings = this.charstrings;
  35529. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35530. charset.push(charstrings[glyphId].glyphName);
  35531. }
  35532. return charset;
  35533. },
  35534. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  35535. var charstrings = this.charstrings;
  35536. var glyphNames = ['.notdef'], glyphId;
  35537. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35538. glyphNames.push(charstrings[glyphId].glyphName);
  35539. }
  35540. var encoding = properties.builtInEncoding;
  35541. if (encoding) {
  35542. var builtInEncoding = {};
  35543. for (var charCode in encoding) {
  35544. glyphId = glyphNames.indexOf(encoding[charCode]);
  35545. if (glyphId >= 0) {
  35546. builtInEncoding[charCode] = glyphId;
  35547. }
  35548. }
  35549. }
  35550. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  35551. },
  35552. getSeacs: function Type1Font_getSeacs(charstrings) {
  35553. var i, ii;
  35554. var seacMap = [];
  35555. for (i = 0, ii = charstrings.length; i < ii; i++) {
  35556. var charstring = charstrings[i];
  35557. if (charstring.seac) {
  35558. // Offset by 1 for .notdef
  35559. seacMap[i + 1] = charstring.seac;
  35560. }
  35561. }
  35562. return seacMap;
  35563. },
  35564. getType2Charstrings: function Type1Font_getType2Charstrings(
  35565. type1Charstrings) {
  35566. var type2Charstrings = [];
  35567. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  35568. type2Charstrings.push(type1Charstrings[i].charstring);
  35569. }
  35570. return type2Charstrings;
  35571. },
  35572. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  35573. var bias = 0;
  35574. var count = type1Subrs.length;
  35575. if (count < 1133) {
  35576. bias = 107;
  35577. } else if (count < 33769) {
  35578. bias = 1131;
  35579. } else {
  35580. bias = 32768;
  35581. }
  35582. // Add a bunch of empty subrs to deal with the Type2 bias
  35583. var type2Subrs = [];
  35584. var i;
  35585. for (i = 0; i < bias; i++) {
  35586. type2Subrs.push([0x0B]);
  35587. }
  35588. for (i = 0; i < count; i++) {
  35589. type2Subrs.push(type1Subrs[i]);
  35590. }
  35591. return type2Subrs;
  35592. },
  35593. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  35594. var cff = new CFF();
  35595. cff.header = new CFFHeader(1, 0, 4, 4);
  35596. cff.names = [name];
  35597. var topDict = new CFFTopDict();
  35598. // CFF strings IDs 0...390 are predefined names, so refering
  35599. // to entries in our own String INDEX starts at SID 391.
  35600. topDict.setByName('version', 391);
  35601. topDict.setByName('Notice', 392);
  35602. topDict.setByName('FullName', 393);
  35603. topDict.setByName('FamilyName', 394);
  35604. topDict.setByName('Weight', 395);
  35605. topDict.setByName('Encoding', null); // placeholder
  35606. topDict.setByName('FontMatrix', properties.fontMatrix);
  35607. topDict.setByName('FontBBox', properties.bbox);
  35608. topDict.setByName('charset', null); // placeholder
  35609. topDict.setByName('CharStrings', null); // placeholder
  35610. topDict.setByName('Private', null); // placeholder
  35611. cff.topDict = topDict;
  35612. var strings = new CFFStrings();
  35613. strings.add('Version 0.11'); // Version
  35614. strings.add('See original notice'); // Notice
  35615. strings.add(name); // FullName
  35616. strings.add(name); // FamilyName
  35617. strings.add('Medium'); // Weight
  35618. cff.strings = strings;
  35619. cff.globalSubrIndex = new CFFIndex();
  35620. var count = glyphs.length;
  35621. var charsetArray = [0];
  35622. var i, ii;
  35623. for (i = 0; i < count; i++) {
  35624. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  35625. // TODO: Insert the string and correctly map it. Previously it was
  35626. // thought mapping names that aren't in the standard strings to .notdef
  35627. // was fine, however in issue818 when mapping them all to .notdef the
  35628. // adieresis glyph no longer worked.
  35629. if (index === -1) {
  35630. index = 0;
  35631. }
  35632. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  35633. }
  35634. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  35635. var charStringsIndex = new CFFIndex();
  35636. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  35637. for (i = 0; i < count; i++) {
  35638. charStringsIndex.add(glyphs[i]);
  35639. }
  35640. cff.charStrings = charStringsIndex;
  35641. var privateDict = new CFFPrivateDict();
  35642. privateDict.setByName('Subrs', null); // placeholder
  35643. var fields = [
  35644. 'BlueValues',
  35645. 'OtherBlues',
  35646. 'FamilyBlues',
  35647. 'FamilyOtherBlues',
  35648. 'StemSnapH',
  35649. 'StemSnapV',
  35650. 'BlueShift',
  35651. 'BlueFuzz',
  35652. 'BlueScale',
  35653. 'LanguageGroup',
  35654. 'ExpansionFactor',
  35655. 'ForceBold',
  35656. 'StdHW',
  35657. 'StdVW'
  35658. ];
  35659. for (i = 0, ii = fields.length; i < ii; i++) {
  35660. var field = fields[i];
  35661. if (!properties.privateData.hasOwnProperty(field)) {
  35662. continue;
  35663. }
  35664. var value = properties.privateData[field];
  35665. if (isArray(value)) {
  35666. // All of the private dictionary array data in CFF must be stored as
  35667. // "delta-encoded" numbers.
  35668. for (var j = value.length - 1; j > 0; j--) {
  35669. value[j] -= value[j - 1]; // ... difference from previous value
  35670. }
  35671. }
  35672. privateDict.setByName(field, value);
  35673. }
  35674. cff.topDict.privateDict = privateDict;
  35675. var subrIndex = new CFFIndex();
  35676. for (i = 0, ii = subrs.length; i < ii; i++) {
  35677. subrIndex.add(subrs[i]);
  35678. }
  35679. privateDict.subrsIndex = subrIndex;
  35680. var compiler = new CFFCompiler(cff);
  35681. return compiler.compile();
  35682. }
  35683. };
  35684. var CFFFont = (function CFFFontClosure() {
  35685. function CFFFont(file, properties) {
  35686. this.properties = properties;
  35687. var parser = new CFFParser(file, properties);
  35688. this.cff = parser.parse();
  35689. var compiler = new CFFCompiler(this.cff);
  35690. this.seacs = this.cff.seacs;
  35691. try {
  35692. this.data = compiler.compile();
  35693. } catch (e) {
  35694. warn('Failed to compile font ' + properties.loadedName);
  35695. // There may have just been an issue with the compiler, set the data
  35696. // anyway and hope the font loaded.
  35697. this.data = file;
  35698. }
  35699. }
  35700. CFFFont.prototype = {
  35701. get numGlyphs() {
  35702. return this.cff.charStrings.count;
  35703. },
  35704. getCharset: function CFFFont_getCharset() {
  35705. return this.cff.charset.charset;
  35706. },
  35707. getGlyphMapping: function CFFFont_getGlyphMapping() {
  35708. var cff = this.cff;
  35709. var properties = this.properties;
  35710. var charsets = cff.charset.charset;
  35711. var charCodeToGlyphId;
  35712. var glyphId;
  35713. if (properties.composite) {
  35714. charCodeToGlyphId = Object.create(null);
  35715. if (cff.isCIDFont) {
  35716. // If the font is actually a CID font then we should use the charset
  35717. // to map CIDs to GIDs.
  35718. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  35719. var cid = charsets[glyphId];
  35720. var charCode = properties.cMap.charCodeOf(cid);
  35721. charCodeToGlyphId[charCode] = glyphId;
  35722. }
  35723. } else {
  35724. // If it is NOT actually a CID font then CIDs should be mapped
  35725. // directly to GIDs.
  35726. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  35727. charCodeToGlyphId[glyphId] = glyphId;
  35728. }
  35729. }
  35730. return charCodeToGlyphId;
  35731. }
  35732. var encoding = cff.encoding ? cff.encoding.encoding : null;
  35733. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  35734. return charCodeToGlyphId;
  35735. }
  35736. };
  35737. return CFFFont;
  35738. })();
  35739. var CFFParser = (function CFFParserClosure() {
  35740. var CharstringValidationData = [
  35741. null,
  35742. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  35743. null,
  35744. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  35745. { id: 'vmoveto', min: 1, stackClearing: true },
  35746. { id: 'rlineto', min: 2, resetStack: true },
  35747. { id: 'hlineto', min: 1, resetStack: true },
  35748. { id: 'vlineto', min: 1, resetStack: true },
  35749. { id: 'rrcurveto', min: 6, resetStack: true },
  35750. null,
  35751. { id: 'callsubr', min: 1, undefStack: true },
  35752. { id: 'return', min: 0, undefStack: true },
  35753. null, // 12
  35754. null,
  35755. { id: 'endchar', min: 0, stackClearing: true },
  35756. null,
  35757. null,
  35758. null,
  35759. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  35760. { id: 'hintmask', min: 0, stackClearing: true },
  35761. { id: 'cntrmask', min: 0, stackClearing: true },
  35762. { id: 'rmoveto', min: 2, stackClearing: true },
  35763. { id: 'hmoveto', min: 1, stackClearing: true },
  35764. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  35765. { id: 'rcurveline', min: 8, resetStack: true },
  35766. { id: 'rlinecurve', min: 8, resetStack: true },
  35767. { id: 'vvcurveto', min: 4, resetStack: true },
  35768. { id: 'hhcurveto', min: 4, resetStack: true },
  35769. null, // shortint
  35770. { id: 'callgsubr', min: 1, undefStack: true },
  35771. { id: 'vhcurveto', min: 4, resetStack: true },
  35772. { id: 'hvcurveto', min: 4, resetStack: true }
  35773. ];
  35774. var CharstringValidationData12 = [
  35775. null,
  35776. null,
  35777. null,
  35778. { id: 'and', min: 2, stackDelta: -1 },
  35779. { id: 'or', min: 2, stackDelta: -1 },
  35780. { id: 'not', min: 1, stackDelta: 0 },
  35781. null,
  35782. null,
  35783. null,
  35784. { id: 'abs', min: 1, stackDelta: 0 },
  35785. { id: 'add', min: 2, stackDelta: -1,
  35786. stackFn: function stack_div(stack, index) {
  35787. stack[index - 2] = stack[index - 2] + stack[index - 1];
  35788. }
  35789. },
  35790. { id: 'sub', min: 2, stackDelta: -1,
  35791. stackFn: function stack_div(stack, index) {
  35792. stack[index - 2] = stack[index - 2] - stack[index - 1];
  35793. }
  35794. },
  35795. { id: 'div', min: 2, stackDelta: -1,
  35796. stackFn: function stack_div(stack, index) {
  35797. stack[index - 2] = stack[index - 2] / stack[index - 1];
  35798. }
  35799. },
  35800. null,
  35801. { id: 'neg', min: 1, stackDelta: 0,
  35802. stackFn: function stack_div(stack, index) {
  35803. stack[index - 1] = -stack[index - 1];
  35804. }
  35805. },
  35806. { id: 'eq', min: 2, stackDelta: -1 },
  35807. null,
  35808. null,
  35809. { id: 'drop', min: 1, stackDelta: -1 },
  35810. null,
  35811. { id: 'put', min: 2, stackDelta: -2 },
  35812. { id: 'get', min: 1, stackDelta: 0 },
  35813. { id: 'ifelse', min: 4, stackDelta: -3 },
  35814. { id: 'random', min: 0, stackDelta: 1 },
  35815. { id: 'mul', min: 2, stackDelta: -1,
  35816. stackFn: function stack_div(stack, index) {
  35817. stack[index - 2] = stack[index - 2] * stack[index - 1];
  35818. }
  35819. },
  35820. null,
  35821. { id: 'sqrt', min: 1, stackDelta: 0 },
  35822. { id: 'dup', min: 1, stackDelta: 1 },
  35823. { id: 'exch', min: 2, stackDelta: 0 },
  35824. { id: 'index', min: 2, stackDelta: 0 },
  35825. { id: 'roll', min: 3, stackDelta: -2 },
  35826. null,
  35827. null,
  35828. null,
  35829. { id: 'hflex', min: 7, resetStack: true },
  35830. { id: 'flex', min: 13, resetStack: true },
  35831. { id: 'hflex1', min: 9, resetStack: true },
  35832. { id: 'flex1', min: 11, resetStack: true }
  35833. ];
  35834. function CFFParser(file, properties) {
  35835. this.bytes = file.getBytes();
  35836. this.properties = properties;
  35837. }
  35838. CFFParser.prototype = {
  35839. parse: function CFFParser_parse() {
  35840. var properties = this.properties;
  35841. var cff = new CFF();
  35842. this.cff = cff;
  35843. // The first five sections must be in order, all the others are reached
  35844. // via offsets contained in one of the below.
  35845. var header = this.parseHeader();
  35846. var nameIndex = this.parseIndex(header.endPos);
  35847. var topDictIndex = this.parseIndex(nameIndex.endPos);
  35848. var stringIndex = this.parseIndex(topDictIndex.endPos);
  35849. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  35850. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  35851. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  35852. cff.header = header.obj;
  35853. cff.names = this.parseNameIndex(nameIndex.obj);
  35854. cff.strings = this.parseStringIndex(stringIndex.obj);
  35855. cff.topDict = topDict;
  35856. cff.globalSubrIndex = globalSubrIndex.obj;
  35857. this.parsePrivateDict(cff.topDict);
  35858. cff.isCIDFont = topDict.hasName('ROS');
  35859. var charStringOffset = topDict.getByName('CharStrings');
  35860. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  35861. cff.charStrings = charStringsAndSeacs.charStrings;
  35862. cff.seacs = charStringsAndSeacs.seacs;
  35863. cff.widths = charStringsAndSeacs.widths;
  35864. var fontMatrix = topDict.getByName('FontMatrix');
  35865. if (fontMatrix) {
  35866. properties.fontMatrix = fontMatrix;
  35867. }
  35868. var fontBBox = topDict.getByName('FontBBox');
  35869. if (fontBBox) {
  35870. // adjusting ascent/descent
  35871. properties.ascent = fontBBox[3];
  35872. properties.descent = fontBBox[1];
  35873. properties.ascentScaled = true;
  35874. }
  35875. var charset, encoding;
  35876. if (cff.isCIDFont) {
  35877. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  35878. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  35879. var dictRaw = fdArrayIndex.get(i);
  35880. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  35881. cff.strings);
  35882. this.parsePrivateDict(fontDict);
  35883. cff.fdArray.push(fontDict);
  35884. }
  35885. // cid fonts don't have an encoding
  35886. encoding = null;
  35887. charset = this.parseCharsets(topDict.getByName('charset'),
  35888. cff.charStrings.count, cff.strings, true);
  35889. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  35890. cff.charStrings.count);
  35891. } else {
  35892. charset = this.parseCharsets(topDict.getByName('charset'),
  35893. cff.charStrings.count, cff.strings, false);
  35894. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  35895. properties,
  35896. cff.strings, charset.charset);
  35897. }
  35898. cff.charset = charset;
  35899. cff.encoding = encoding;
  35900. return cff;
  35901. },
  35902. parseHeader: function CFFParser_parseHeader() {
  35903. var bytes = this.bytes;
  35904. var bytesLength = bytes.length;
  35905. var offset = 0;
  35906. // Prevent an infinite loop, by checking that the offset is within the
  35907. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  35908. while (offset < bytesLength && bytes[offset] !== 1) {
  35909. ++offset;
  35910. }
  35911. if (offset >= bytesLength) {
  35912. error('Invalid CFF header');
  35913. } else if (offset !== 0) {
  35914. info('cff data is shifted');
  35915. bytes = bytes.subarray(offset);
  35916. this.bytes = bytes;
  35917. }
  35918. var major = bytes[0];
  35919. var minor = bytes[1];
  35920. var hdrSize = bytes[2];
  35921. var offSize = bytes[3];
  35922. var header = new CFFHeader(major, minor, hdrSize, offSize);
  35923. return { obj: header, endPos: hdrSize };
  35924. },
  35925. parseDict: function CFFParser_parseDict(dict) {
  35926. var pos = 0;
  35927. function parseOperand() {
  35928. var value = dict[pos++];
  35929. if (value === 30) {
  35930. return parseFloatOperand(pos);
  35931. } else if (value === 28) {
  35932. value = dict[pos++];
  35933. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  35934. return value;
  35935. } else if (value === 29) {
  35936. value = dict[pos++];
  35937. value = (value << 8) | dict[pos++];
  35938. value = (value << 8) | dict[pos++];
  35939. value = (value << 8) | dict[pos++];
  35940. return value;
  35941. } else if (value >= 32 && value <= 246) {
  35942. return value - 139;
  35943. } else if (value >= 247 && value <= 250) {
  35944. return ((value - 247) * 256) + dict[pos++] + 108;
  35945. } else if (value >= 251 && value <= 254) {
  35946. return -((value - 251) * 256) - dict[pos++] - 108;
  35947. } else {
  35948. error('255 is not a valid DICT command');
  35949. }
  35950. return -1;
  35951. }
  35952. function parseFloatOperand() {
  35953. var str = '';
  35954. var eof = 15;
  35955. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  35956. '9', '.', 'E', 'E-', null, '-'];
  35957. var length = dict.length;
  35958. while (pos < length) {
  35959. var b = dict[pos++];
  35960. var b1 = b >> 4;
  35961. var b2 = b & 15;
  35962. if (b1 === eof) {
  35963. break;
  35964. }
  35965. str += lookup[b1];
  35966. if (b2 === eof) {
  35967. break;
  35968. }
  35969. str += lookup[b2];
  35970. }
  35971. return parseFloat(str);
  35972. }
  35973. var operands = [];
  35974. var entries = [];
  35975. pos = 0;
  35976. var end = dict.length;
  35977. while (pos < end) {
  35978. var b = dict[pos];
  35979. if (b <= 21) {
  35980. if (b === 12) {
  35981. b = (b << 8) | dict[++pos];
  35982. }
  35983. entries.push([b, operands]);
  35984. operands = [];
  35985. ++pos;
  35986. } else {
  35987. operands.push(parseOperand());
  35988. }
  35989. }
  35990. return entries;
  35991. },
  35992. parseIndex: function CFFParser_parseIndex(pos) {
  35993. var cffIndex = new CFFIndex();
  35994. var bytes = this.bytes;
  35995. var count = (bytes[pos++] << 8) | bytes[pos++];
  35996. var offsets = [];
  35997. var end = pos;
  35998. var i, ii;
  35999. if (count !== 0) {
  36000. var offsetSize = bytes[pos++];
  36001. // add 1 for offset to determine size of last object
  36002. var startPos = pos + ((count + 1) * offsetSize) - 1;
  36003. for (i = 0, ii = count + 1; i < ii; ++i) {
  36004. var offset = 0;
  36005. for (var j = 0; j < offsetSize; ++j) {
  36006. offset <<= 8;
  36007. offset += bytes[pos++];
  36008. }
  36009. offsets.push(startPos + offset);
  36010. }
  36011. end = offsets[count];
  36012. }
  36013. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  36014. var offsetStart = offsets[i];
  36015. var offsetEnd = offsets[i + 1];
  36016. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  36017. }
  36018. return {obj: cffIndex, endPos: end};
  36019. },
  36020. parseNameIndex: function CFFParser_parseNameIndex(index) {
  36021. var names = [];
  36022. for (var i = 0, ii = index.count; i < ii; ++i) {
  36023. var name = index.get(i);
  36024. // OTS doesn't allow names to be over 127 characters.
  36025. var length = Math.min(name.length, 127);
  36026. var data = [];
  36027. // OTS also only permits certain characters in the name.
  36028. for (var j = 0; j < length; ++j) {
  36029. var c = name[j];
  36030. if (j === 0 && c === 0) {
  36031. data[j] = c;
  36032. continue;
  36033. }
  36034. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  36035. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  36036. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  36037. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  36038. data[j] = 95;
  36039. continue;
  36040. }
  36041. data[j] = c;
  36042. }
  36043. names.push(bytesToString(data));
  36044. }
  36045. return names;
  36046. },
  36047. parseStringIndex: function CFFParser_parseStringIndex(index) {
  36048. var strings = new CFFStrings();
  36049. for (var i = 0, ii = index.count; i < ii; ++i) {
  36050. var data = index.get(i);
  36051. strings.add(bytesToString(data));
  36052. }
  36053. return strings;
  36054. },
  36055. createDict: function CFFParser_createDict(Type, dict, strings) {
  36056. var cffDict = new Type(strings);
  36057. for (var i = 0, ii = dict.length; i < ii; ++i) {
  36058. var pair = dict[i];
  36059. var key = pair[0];
  36060. var value = pair[1];
  36061. cffDict.setByKey(key, value);
  36062. }
  36063. return cffDict;
  36064. },
  36065. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  36066. var charStrings = this.parseIndex(charStringOffset).obj;
  36067. var seacs = [];
  36068. var widths = [];
  36069. var count = charStrings.count;
  36070. for (var i = 0; i < count; i++) {
  36071. var charstring = charStrings.get(i);
  36072. var stackSize = 0;
  36073. var stack = [];
  36074. var undefStack = true;
  36075. var hints = 0;
  36076. var valid = true;
  36077. var data = charstring;
  36078. var length = data.length;
  36079. var firstStackClearing = true;
  36080. for (var j = 0; j < length;) {
  36081. var value = data[j++];
  36082. var validationCommand = null;
  36083. if (value === 12) {
  36084. var q = data[j++];
  36085. if (q === 0) {
  36086. // The CFF specification state that the 'dotsection' command
  36087. // (12, 0) is deprecated and treated as a no-op, but all Type2
  36088. // charstrings processors should support them. Unfortunately
  36089. // the font sanitizer don't. As a workaround the sequence (12, 0)
  36090. // is replaced by a useless (0, hmoveto).
  36091. data[j - 2] = 139;
  36092. data[j - 1] = 22;
  36093. stackSize = 0;
  36094. } else {
  36095. validationCommand = CharstringValidationData12[q];
  36096. }
  36097. } else if (value === 28) { // number (16 bit)
  36098. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  36099. j += 2;
  36100. stackSize++;
  36101. } else if (value === 14) {
  36102. if (stackSize >= 4) {
  36103. stackSize -= 4;
  36104. if (SEAC_ANALYSIS_ENABLED) {
  36105. seacs[i] = stack.slice(stackSize, stackSize + 4);
  36106. valid = false;
  36107. }
  36108. }
  36109. validationCommand = CharstringValidationData[value];
  36110. } else if (value >= 32 && value <= 246) { // number
  36111. stack[stackSize] = value - 139;
  36112. stackSize++;
  36113. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  36114. stack[stackSize] = (value < 251 ?
  36115. ((value - 247) << 8) + data[j] + 108 :
  36116. -((value - 251) << 8) - data[j] - 108);
  36117. j++;
  36118. stackSize++;
  36119. } else if (value === 255) { // number (32 bit)
  36120. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  36121. (data[j + 2] << 8) | data[j + 3]) / 65536;
  36122. j += 4;
  36123. stackSize++;
  36124. } else if (value === 19 || value === 20) {
  36125. hints += stackSize >> 1;
  36126. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  36127. stackSize %= 2;
  36128. validationCommand = CharstringValidationData[value];
  36129. } else {
  36130. validationCommand = CharstringValidationData[value];
  36131. }
  36132. if (validationCommand) {
  36133. if (validationCommand.stem) {
  36134. hints += stackSize >> 1;
  36135. }
  36136. if ('min' in validationCommand) {
  36137. if (!undefStack && stackSize < validationCommand.min) {
  36138. warn('Not enough parameters for ' + validationCommand.id +
  36139. '; actual: ' + stackSize +
  36140. ', expected: ' + validationCommand.min);
  36141. valid = false;
  36142. break;
  36143. }
  36144. }
  36145. if (firstStackClearing && validationCommand.stackClearing) {
  36146. firstStackClearing = false;
  36147. // the optional character width can be found before the first
  36148. // stack-clearing command arguments
  36149. stackSize -= validationCommand.min;
  36150. if (stackSize >= 2 && validationCommand.stem) {
  36151. // there are even amount of arguments for stem commands
  36152. stackSize %= 2;
  36153. } else if (stackSize > 1) {
  36154. warn('Found too many parameters for stack-clearing command');
  36155. }
  36156. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  36157. widths[i] = stack[stackSize - 1];
  36158. }
  36159. }
  36160. if ('stackDelta' in validationCommand) {
  36161. if ('stackFn' in validationCommand) {
  36162. validationCommand.stackFn(stack, stackSize);
  36163. }
  36164. stackSize += validationCommand.stackDelta;
  36165. } else if (validationCommand.stackClearing) {
  36166. stackSize = 0;
  36167. } else if (validationCommand.resetStack) {
  36168. stackSize = 0;
  36169. undefStack = false;
  36170. } else if (validationCommand.undefStack) {
  36171. stackSize = 0;
  36172. undefStack = true;
  36173. firstStackClearing = false;
  36174. }
  36175. }
  36176. }
  36177. if (!valid) {
  36178. // resetting invalid charstring to single 'endchar'
  36179. charStrings.set(i, new Uint8Array([14]));
  36180. }
  36181. }
  36182. return { charStrings: charStrings, seacs: seacs, widths: widths };
  36183. },
  36184. emptyPrivateDictionary:
  36185. function CFFParser_emptyPrivateDictionary(parentDict) {
  36186. var privateDict = this.createDict(CFFPrivateDict, [],
  36187. parentDict.strings);
  36188. parentDict.setByKey(18, [0, 0]);
  36189. parentDict.privateDict = privateDict;
  36190. },
  36191. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  36192. // no private dict, do nothing
  36193. if (!parentDict.hasName('Private')) {
  36194. this.emptyPrivateDictionary(parentDict);
  36195. return;
  36196. }
  36197. var privateOffset = parentDict.getByName('Private');
  36198. // make sure the params are formatted correctly
  36199. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  36200. parentDict.removeByName('Private');
  36201. return;
  36202. }
  36203. var size = privateOffset[0];
  36204. var offset = privateOffset[1];
  36205. // remove empty dicts or ones that refer to invalid location
  36206. if (size === 0 || offset >= this.bytes.length) {
  36207. this.emptyPrivateDictionary(parentDict);
  36208. return;
  36209. }
  36210. var privateDictEnd = offset + size;
  36211. var dictData = this.bytes.subarray(offset, privateDictEnd);
  36212. var dict = this.parseDict(dictData);
  36213. var privateDict = this.createDict(CFFPrivateDict, dict,
  36214. parentDict.strings);
  36215. parentDict.privateDict = privateDict;
  36216. // Parse the Subrs index also since it's relative to the private dict.
  36217. if (!privateDict.getByName('Subrs')) {
  36218. return;
  36219. }
  36220. var subrsOffset = privateDict.getByName('Subrs');
  36221. var relativeOffset = offset + subrsOffset;
  36222. // Validate the offset.
  36223. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  36224. this.emptyPrivateDictionary(parentDict);
  36225. return;
  36226. }
  36227. var subrsIndex = this.parseIndex(relativeOffset);
  36228. privateDict.subrsIndex = subrsIndex.obj;
  36229. },
  36230. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  36231. if (pos === 0) {
  36232. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  36233. ISOAdobeCharset);
  36234. } else if (pos === 1) {
  36235. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  36236. ExpertCharset);
  36237. } else if (pos === 2) {
  36238. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  36239. ExpertSubsetCharset);
  36240. }
  36241. var bytes = this.bytes;
  36242. var start = pos;
  36243. var format = bytes[pos++];
  36244. var charset = ['.notdef'];
  36245. var id, count, i;
  36246. // subtract 1 for the .notdef glyph
  36247. length -= 1;
  36248. switch (format) {
  36249. case 0:
  36250. for (i = 0; i < length; i++) {
  36251. id = (bytes[pos++] << 8) | bytes[pos++];
  36252. charset.push(cid ? id : strings.get(id));
  36253. }
  36254. break;
  36255. case 1:
  36256. while (charset.length <= length) {
  36257. id = (bytes[pos++] << 8) | bytes[pos++];
  36258. count = bytes[pos++];
  36259. for (i = 0; i <= count; i++) {
  36260. charset.push(cid ? id++ : strings.get(id++));
  36261. }
  36262. }
  36263. break;
  36264. case 2:
  36265. while (charset.length <= length) {
  36266. id = (bytes[pos++] << 8) | bytes[pos++];
  36267. count = (bytes[pos++] << 8) | bytes[pos++];
  36268. for (i = 0; i <= count; i++) {
  36269. charset.push(cid ? id++ : strings.get(id++));
  36270. }
  36271. }
  36272. break;
  36273. default:
  36274. error('Unknown charset format');
  36275. }
  36276. // Raw won't be needed if we actually compile the charset.
  36277. var end = pos;
  36278. var raw = bytes.subarray(start, end);
  36279. return new CFFCharset(false, format, charset, raw);
  36280. },
  36281. parseEncoding: function CFFParser_parseEncoding(pos,
  36282. properties,
  36283. strings,
  36284. charset) {
  36285. var encoding = {};
  36286. var bytes = this.bytes;
  36287. var predefined = false;
  36288. var hasSupplement = false;
  36289. var format, i, ii;
  36290. var raw = null;
  36291. function readSupplement() {
  36292. var supplementsCount = bytes[pos++];
  36293. for (i = 0; i < supplementsCount; i++) {
  36294. var code = bytes[pos++];
  36295. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  36296. encoding[code] = charset.indexOf(strings.get(sid));
  36297. }
  36298. }
  36299. if (pos === 0 || pos === 1) {
  36300. predefined = true;
  36301. format = pos;
  36302. var baseEncoding = pos ? Encodings.ExpertEncoding :
  36303. Encodings.StandardEncoding;
  36304. for (i = 0, ii = charset.length; i < ii; i++) {
  36305. var index = baseEncoding.indexOf(charset[i]);
  36306. if (index !== -1) {
  36307. encoding[index] = i;
  36308. }
  36309. }
  36310. } else {
  36311. var dataStart = pos;
  36312. format = bytes[pos++];
  36313. switch (format & 0x7f) {
  36314. case 0:
  36315. var glyphsCount = bytes[pos++];
  36316. for (i = 1; i <= glyphsCount; i++) {
  36317. encoding[bytes[pos++]] = i;
  36318. }
  36319. break;
  36320. case 1:
  36321. var rangesCount = bytes[pos++];
  36322. var gid = 1;
  36323. for (i = 0; i < rangesCount; i++) {
  36324. var start = bytes[pos++];
  36325. var left = bytes[pos++];
  36326. for (var j = start; j <= start + left; j++) {
  36327. encoding[j] = gid++;
  36328. }
  36329. }
  36330. break;
  36331. default:
  36332. error('Unknow encoding format: ' + format + ' in CFF');
  36333. break;
  36334. }
  36335. var dataEnd = pos;
  36336. if (format & 0x80) {
  36337. // The font sanitizer does not support CFF encoding with a
  36338. // supplement, since the encoding is not really used to map
  36339. // between gid to glyph, let's overwrite what is declared in
  36340. // the top dictionary to let the sanitizer think the font use
  36341. // StandardEncoding, that's a lie but that's ok.
  36342. bytes[dataStart] &= 0x7f;
  36343. readSupplement();
  36344. hasSupplement = true;
  36345. }
  36346. raw = bytes.subarray(dataStart, dataEnd);
  36347. }
  36348. format = format & 0x7f;
  36349. return new CFFEncoding(predefined, format, encoding, raw);
  36350. },
  36351. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  36352. var start = pos;
  36353. var bytes = this.bytes;
  36354. var format = bytes[pos++];
  36355. var fdSelect = [];
  36356. var i;
  36357. switch (format) {
  36358. case 0:
  36359. for (i = 0; i < length; ++i) {
  36360. var id = bytes[pos++];
  36361. fdSelect.push(id);
  36362. }
  36363. break;
  36364. case 3:
  36365. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  36366. for (i = 0; i < rangesCount; ++i) {
  36367. var first = (bytes[pos++] << 8) | bytes[pos++];
  36368. var fdIndex = bytes[pos++];
  36369. var next = (bytes[pos] << 8) | bytes[pos + 1];
  36370. for (var j = first; j < next; ++j) {
  36371. fdSelect.push(fdIndex);
  36372. }
  36373. }
  36374. // Advance past the sentinel(next).
  36375. pos += 2;
  36376. break;
  36377. default:
  36378. error('Unknown fdselect format ' + format);
  36379. break;
  36380. }
  36381. var end = pos;
  36382. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  36383. }
  36384. };
  36385. return CFFParser;
  36386. })();
  36387. // Compact Font Format
  36388. var CFF = (function CFFClosure() {
  36389. function CFF() {
  36390. this.header = null;
  36391. this.names = [];
  36392. this.topDict = null;
  36393. this.strings = new CFFStrings();
  36394. this.globalSubrIndex = null;
  36395. // The following could really be per font, but since we only have one font
  36396. // store them here.
  36397. this.encoding = null;
  36398. this.charset = null;
  36399. this.charStrings = null;
  36400. this.fdArray = [];
  36401. this.fdSelect = null;
  36402. this.isCIDFont = false;
  36403. }
  36404. return CFF;
  36405. })();
  36406. var CFFHeader = (function CFFHeaderClosure() {
  36407. function CFFHeader(major, minor, hdrSize, offSize) {
  36408. this.major = major;
  36409. this.minor = minor;
  36410. this.hdrSize = hdrSize;
  36411. this.offSize = offSize;
  36412. }
  36413. return CFFHeader;
  36414. })();
  36415. var CFFStrings = (function CFFStringsClosure() {
  36416. function CFFStrings() {
  36417. this.strings = [];
  36418. }
  36419. CFFStrings.prototype = {
  36420. get: function CFFStrings_get(index) {
  36421. if (index >= 0 && index <= 390) {
  36422. return CFFStandardStrings[index];
  36423. }
  36424. if (index - 391 <= this.strings.length) {
  36425. return this.strings[index - 391];
  36426. }
  36427. return CFFStandardStrings[0];
  36428. },
  36429. add: function CFFStrings_add(value) {
  36430. this.strings.push(value);
  36431. },
  36432. get count() {
  36433. return this.strings.length;
  36434. }
  36435. };
  36436. return CFFStrings;
  36437. })();
  36438. var CFFIndex = (function CFFIndexClosure() {
  36439. function CFFIndex() {
  36440. this.objects = [];
  36441. this.length = 0;
  36442. }
  36443. CFFIndex.prototype = {
  36444. add: function CFFIndex_add(data) {
  36445. this.length += data.length;
  36446. this.objects.push(data);
  36447. },
  36448. set: function CFFIndex_set(index, data) {
  36449. this.length += data.length - this.objects[index].length;
  36450. this.objects[index] = data;
  36451. },
  36452. get: function CFFIndex_get(index) {
  36453. return this.objects[index];
  36454. },
  36455. get count() {
  36456. return this.objects.length;
  36457. }
  36458. };
  36459. return CFFIndex;
  36460. })();
  36461. var CFFDict = (function CFFDictClosure() {
  36462. function CFFDict(tables, strings) {
  36463. this.keyToNameMap = tables.keyToNameMap;
  36464. this.nameToKeyMap = tables.nameToKeyMap;
  36465. this.defaults = tables.defaults;
  36466. this.types = tables.types;
  36467. this.opcodes = tables.opcodes;
  36468. this.order = tables.order;
  36469. this.strings = strings;
  36470. this.values = {};
  36471. }
  36472. CFFDict.prototype = {
  36473. // value should always be an array
  36474. setByKey: function CFFDict_setByKey(key, value) {
  36475. if (!(key in this.keyToNameMap)) {
  36476. return false;
  36477. }
  36478. // ignore empty values
  36479. if (value.length === 0) {
  36480. return true;
  36481. }
  36482. var type = this.types[key];
  36483. // remove the array wrapping these types of values
  36484. if (type === 'num' || type === 'sid' || type === 'offset') {
  36485. value = value[0];
  36486. }
  36487. this.values[key] = value;
  36488. return true;
  36489. },
  36490. setByName: function CFFDict_setByName(name, value) {
  36491. if (!(name in this.nameToKeyMap)) {
  36492. error('Invalid dictionary name "' + name + '"');
  36493. }
  36494. this.values[this.nameToKeyMap[name]] = value;
  36495. },
  36496. hasName: function CFFDict_hasName(name) {
  36497. return this.nameToKeyMap[name] in this.values;
  36498. },
  36499. getByName: function CFFDict_getByName(name) {
  36500. if (!(name in this.nameToKeyMap)) {
  36501. error('Invalid dictionary name "' + name + '"');
  36502. }
  36503. var key = this.nameToKeyMap[name];
  36504. if (!(key in this.values)) {
  36505. return this.defaults[key];
  36506. }
  36507. return this.values[key];
  36508. },
  36509. removeByName: function CFFDict_removeByName(name) {
  36510. delete this.values[this.nameToKeyMap[name]];
  36511. }
  36512. };
  36513. CFFDict.createTables = function CFFDict_createTables(layout) {
  36514. var tables = {
  36515. keyToNameMap: {},
  36516. nameToKeyMap: {},
  36517. defaults: {},
  36518. types: {},
  36519. opcodes: {},
  36520. order: []
  36521. };
  36522. for (var i = 0, ii = layout.length; i < ii; ++i) {
  36523. var entry = layout[i];
  36524. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  36525. tables.keyToNameMap[key] = entry[1];
  36526. tables.nameToKeyMap[entry[1]] = key;
  36527. tables.types[key] = entry[2];
  36528. tables.defaults[key] = entry[3];
  36529. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  36530. tables.order.push(key);
  36531. }
  36532. return tables;
  36533. };
  36534. return CFFDict;
  36535. })();
  36536. var CFFTopDict = (function CFFTopDictClosure() {
  36537. var layout = [
  36538. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  36539. [[12, 20], 'SyntheticBase', 'num', null],
  36540. [0, 'version', 'sid', null],
  36541. [1, 'Notice', 'sid', null],
  36542. [[12, 0], 'Copyright', 'sid', null],
  36543. [2, 'FullName', 'sid', null],
  36544. [3, 'FamilyName', 'sid', null],
  36545. [4, 'Weight', 'sid', null],
  36546. [[12, 1], 'isFixedPitch', 'num', 0],
  36547. [[12, 2], 'ItalicAngle', 'num', 0],
  36548. [[12, 3], 'UnderlinePosition', 'num', -100],
  36549. [[12, 4], 'UnderlineThickness', 'num', 50],
  36550. [[12, 5], 'PaintType', 'num', 0],
  36551. [[12, 6], 'CharstringType', 'num', 2],
  36552. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  36553. [0.001, 0, 0, 0.001, 0, 0]],
  36554. [13, 'UniqueID', 'num', null],
  36555. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  36556. [[12, 8], 'StrokeWidth', 'num', 0],
  36557. [14, 'XUID', 'array', null],
  36558. [15, 'charset', 'offset', 0],
  36559. [16, 'Encoding', 'offset', 0],
  36560. [17, 'CharStrings', 'offset', 0],
  36561. [18, 'Private', ['offset', 'offset'], null],
  36562. [[12, 21], 'PostScript', 'sid', null],
  36563. [[12, 22], 'BaseFontName', 'sid', null],
  36564. [[12, 23], 'BaseFontBlend', 'delta', null],
  36565. [[12, 31], 'CIDFontVersion', 'num', 0],
  36566. [[12, 32], 'CIDFontRevision', 'num', 0],
  36567. [[12, 33], 'CIDFontType', 'num', 0],
  36568. [[12, 34], 'CIDCount', 'num', 8720],
  36569. [[12, 35], 'UIDBase', 'num', null],
  36570. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  36571. // before FDArray.
  36572. [[12, 37], 'FDSelect', 'offset', null],
  36573. [[12, 36], 'FDArray', 'offset', null],
  36574. [[12, 38], 'FontName', 'sid', null]
  36575. ];
  36576. var tables = null;
  36577. function CFFTopDict(strings) {
  36578. if (tables === null) {
  36579. tables = CFFDict.createTables(layout);
  36580. }
  36581. CFFDict.call(this, tables, strings);
  36582. this.privateDict = null;
  36583. }
  36584. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  36585. return CFFTopDict;
  36586. })();
  36587. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  36588. var layout = [
  36589. [6, 'BlueValues', 'delta', null],
  36590. [7, 'OtherBlues', 'delta', null],
  36591. [8, 'FamilyBlues', 'delta', null],
  36592. [9, 'FamilyOtherBlues', 'delta', null],
  36593. [[12, 9], 'BlueScale', 'num', 0.039625],
  36594. [[12, 10], 'BlueShift', 'num', 7],
  36595. [[12, 11], 'BlueFuzz', 'num', 1],
  36596. [10, 'StdHW', 'num', null],
  36597. [11, 'StdVW', 'num', null],
  36598. [[12, 12], 'StemSnapH', 'delta', null],
  36599. [[12, 13], 'StemSnapV', 'delta', null],
  36600. [[12, 14], 'ForceBold', 'num', 0],
  36601. [[12, 17], 'LanguageGroup', 'num', 0],
  36602. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  36603. [[12, 19], 'initialRandomSeed', 'num', 0],
  36604. [20, 'defaultWidthX', 'num', 0],
  36605. [21, 'nominalWidthX', 'num', 0],
  36606. [19, 'Subrs', 'offset', null]
  36607. ];
  36608. var tables = null;
  36609. function CFFPrivateDict(strings) {
  36610. if (tables === null) {
  36611. tables = CFFDict.createTables(layout);
  36612. }
  36613. CFFDict.call(this, tables, strings);
  36614. this.subrsIndex = null;
  36615. }
  36616. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  36617. return CFFPrivateDict;
  36618. })();
  36619. var CFFCharsetPredefinedTypes = {
  36620. ISO_ADOBE: 0,
  36621. EXPERT: 1,
  36622. EXPERT_SUBSET: 2
  36623. };
  36624. var CFFCharset = (function CFFCharsetClosure() {
  36625. function CFFCharset(predefined, format, charset, raw) {
  36626. this.predefined = predefined;
  36627. this.format = format;
  36628. this.charset = charset;
  36629. this.raw = raw;
  36630. }
  36631. return CFFCharset;
  36632. })();
  36633. var CFFEncoding = (function CFFEncodingClosure() {
  36634. function CFFEncoding(predefined, format, encoding, raw) {
  36635. this.predefined = predefined;
  36636. this.format = format;
  36637. this.encoding = encoding;
  36638. this.raw = raw;
  36639. }
  36640. return CFFEncoding;
  36641. })();
  36642. var CFFFDSelect = (function CFFFDSelectClosure() {
  36643. function CFFFDSelect(fdSelect, raw) {
  36644. this.fdSelect = fdSelect;
  36645. this.raw = raw;
  36646. }
  36647. return CFFFDSelect;
  36648. })();
  36649. // Helper class to keep track of where an offset is within the data and helps
  36650. // filling in that offset once it's known.
  36651. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  36652. function CFFOffsetTracker() {
  36653. this.offsets = {};
  36654. }
  36655. CFFOffsetTracker.prototype = {
  36656. isTracking: function CFFOffsetTracker_isTracking(key) {
  36657. return key in this.offsets;
  36658. },
  36659. track: function CFFOffsetTracker_track(key, location) {
  36660. if (key in this.offsets) {
  36661. error('Already tracking location of ' + key);
  36662. }
  36663. this.offsets[key] = location;
  36664. },
  36665. offset: function CFFOffsetTracker_offset(value) {
  36666. for (var key in this.offsets) {
  36667. this.offsets[key] += value;
  36668. }
  36669. },
  36670. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  36671. values,
  36672. output) {
  36673. if (!(key in this.offsets)) {
  36674. error('Not tracking location of ' + key);
  36675. }
  36676. var data = output.data;
  36677. var dataOffset = this.offsets[key];
  36678. var size = 5;
  36679. for (var i = 0, ii = values.length; i < ii; ++i) {
  36680. var offset0 = i * size + dataOffset;
  36681. var offset1 = offset0 + 1;
  36682. var offset2 = offset0 + 2;
  36683. var offset3 = offset0 + 3;
  36684. var offset4 = offset0 + 4;
  36685. // It's easy to screw up offsets so perform this sanity check.
  36686. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  36687. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  36688. error('writing to an offset that is not empty');
  36689. }
  36690. var value = values[i];
  36691. data[offset0] = 0x1d;
  36692. data[offset1] = (value >> 24) & 0xFF;
  36693. data[offset2] = (value >> 16) & 0xFF;
  36694. data[offset3] = (value >> 8) & 0xFF;
  36695. data[offset4] = value & 0xFF;
  36696. }
  36697. }
  36698. };
  36699. return CFFOffsetTracker;
  36700. })();
  36701. // Takes a CFF and converts it to the binary representation.
  36702. var CFFCompiler = (function CFFCompilerClosure() {
  36703. function CFFCompiler(cff) {
  36704. this.cff = cff;
  36705. }
  36706. CFFCompiler.prototype = {
  36707. compile: function CFFCompiler_compile() {
  36708. var cff = this.cff;
  36709. var output = {
  36710. data: [],
  36711. length: 0,
  36712. add: function CFFCompiler_add(data) {
  36713. this.data = this.data.concat(data);
  36714. this.length = this.data.length;
  36715. }
  36716. };
  36717. // Compile the five entries that must be in order.
  36718. var header = this.compileHeader(cff.header);
  36719. output.add(header);
  36720. var nameIndex = this.compileNameIndex(cff.names);
  36721. output.add(nameIndex);
  36722. if (cff.isCIDFont) {
  36723. // The spec is unclear on how font matrices should relate to each other
  36724. // when there is one in the main top dict and the sub top dicts.
  36725. // Windows handles this differently than linux and osx so we have to
  36726. // normalize to work on all.
  36727. // Rules based off of some mailing list discussions:
  36728. // - If main font has a matrix and subfont doesn't, use the main matrix.
  36729. // - If no main font matrix and there is a subfont matrix, use the
  36730. // subfont matrix.
  36731. // - If both have matrices, concat together.
  36732. // - If neither have matrices, use default.
  36733. // To make this work on all platforms we move the top matrix into each
  36734. // sub top dict and concat if necessary.
  36735. if (cff.topDict.hasName('FontMatrix')) {
  36736. var base = cff.topDict.getByName('FontMatrix');
  36737. cff.topDict.removeByName('FontMatrix');
  36738. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  36739. var subDict = cff.fdArray[i];
  36740. var matrix = base.slice(0);
  36741. if (subDict.hasName('FontMatrix')) {
  36742. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  36743. }
  36744. subDict.setByName('FontMatrix', matrix);
  36745. }
  36746. }
  36747. }
  36748. var compiled = this.compileTopDicts([cff.topDict],
  36749. output.length,
  36750. cff.isCIDFont);
  36751. output.add(compiled.output);
  36752. var topDictTracker = compiled.trackers[0];
  36753. var stringIndex = this.compileStringIndex(cff.strings.strings);
  36754. output.add(stringIndex);
  36755. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  36756. output.add(globalSubrIndex);
  36757. // Now start on the other entries that have no specfic order.
  36758. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  36759. if (cff.encoding.predefined) {
  36760. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  36761. output);
  36762. } else {
  36763. var encoding = this.compileEncoding(cff.encoding);
  36764. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  36765. output.add(encoding);
  36766. }
  36767. }
  36768. if (cff.charset && cff.topDict.hasName('charset')) {
  36769. if (cff.charset.predefined) {
  36770. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  36771. output);
  36772. } else {
  36773. var charset = this.compileCharset(cff.charset);
  36774. topDictTracker.setEntryLocation('charset', [output.length], output);
  36775. output.add(charset);
  36776. }
  36777. }
  36778. var charStrings = this.compileCharStrings(cff.charStrings);
  36779. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  36780. output.add(charStrings);
  36781. if (cff.isCIDFont) {
  36782. // For some reason FDSelect must be in front of FDArray on windows. OSX
  36783. // and linux don't seem to care.
  36784. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  36785. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  36786. output.add(fdSelect);
  36787. // It is unclear if the sub font dictionary can have CID related
  36788. // dictionary keys, but the sanitizer doesn't like them so remove them.
  36789. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  36790. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  36791. output.add(compiled.output);
  36792. var fontDictTrackers = compiled.trackers;
  36793. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  36794. }
  36795. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  36796. // If the font data ends with INDEX whose object data is zero-length,
  36797. // the sanitizer will bail out. Add a dummy byte to avoid that.
  36798. output.add([0]);
  36799. return output.data;
  36800. },
  36801. encodeNumber: function CFFCompiler_encodeNumber(value) {
  36802. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  36803. return this.encodeInteger(value);
  36804. } else {
  36805. return this.encodeFloat(value);
  36806. }
  36807. },
  36808. encodeFloat: function CFFCompiler_encodeFloat(num) {
  36809. var value = num.toString();
  36810. // rounding inaccurate doubles
  36811. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36812. if (m) {
  36813. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36814. value = (Math.round(num * epsilon) / epsilon).toString();
  36815. }
  36816. var nibbles = '';
  36817. var i, ii;
  36818. for (i = 0, ii = value.length; i < ii; ++i) {
  36819. var a = value[i];
  36820. if (a === 'e') {
  36821. nibbles += value[++i] === '-' ? 'c' : 'b';
  36822. } else if (a === '.') {
  36823. nibbles += 'a';
  36824. } else if (a === '-') {
  36825. nibbles += 'e';
  36826. } else {
  36827. nibbles += a;
  36828. }
  36829. }
  36830. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  36831. var out = [30];
  36832. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  36833. out.push(parseInt(nibbles.substr(i, 2), 16));
  36834. }
  36835. return out;
  36836. },
  36837. encodeInteger: function CFFCompiler_encodeInteger(value) {
  36838. var code;
  36839. if (value >= -107 && value <= 107) {
  36840. code = [value + 139];
  36841. } else if (value >= 108 && value <= 1131) {
  36842. value = [value - 108];
  36843. code = [(value >> 8) + 247, value & 0xFF];
  36844. } else if (value >= -1131 && value <= -108) {
  36845. value = -value - 108;
  36846. code = [(value >> 8) + 251, value & 0xFF];
  36847. } else if (value >= -32768 && value <= 32767) {
  36848. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  36849. } else {
  36850. code = [0x1d,
  36851. (value >> 24) & 0xFF,
  36852. (value >> 16) & 0xFF,
  36853. (value >> 8) & 0xFF,
  36854. value & 0xFF];
  36855. }
  36856. return code;
  36857. },
  36858. compileHeader: function CFFCompiler_compileHeader(header) {
  36859. return [
  36860. header.major,
  36861. header.minor,
  36862. header.hdrSize,
  36863. header.offSize
  36864. ];
  36865. },
  36866. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  36867. var nameIndex = new CFFIndex();
  36868. for (var i = 0, ii = names.length; i < ii; ++i) {
  36869. nameIndex.add(stringToBytes(names[i]));
  36870. }
  36871. return this.compileIndex(nameIndex);
  36872. },
  36873. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  36874. length,
  36875. removeCidKeys) {
  36876. var fontDictTrackers = [];
  36877. var fdArrayIndex = new CFFIndex();
  36878. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36879. var fontDict = dicts[i];
  36880. if (removeCidKeys) {
  36881. fontDict.removeByName('CIDFontVersion');
  36882. fontDict.removeByName('CIDFontRevision');
  36883. fontDict.removeByName('CIDFontType');
  36884. fontDict.removeByName('CIDCount');
  36885. fontDict.removeByName('UIDBase');
  36886. }
  36887. var fontDictTracker = new CFFOffsetTracker();
  36888. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  36889. fontDictTrackers.push(fontDictTracker);
  36890. fdArrayIndex.add(fontDictData);
  36891. fontDictTracker.offset(length);
  36892. }
  36893. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  36894. return {
  36895. trackers: fontDictTrackers,
  36896. output: fdArrayIndex
  36897. };
  36898. },
  36899. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  36900. trackers,
  36901. output) {
  36902. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36903. var fontDict = dicts[i];
  36904. assert(fontDict.privateDict && fontDict.hasName('Private'),
  36905. 'There must be an private dictionary.');
  36906. var privateDict = fontDict.privateDict;
  36907. var privateDictTracker = new CFFOffsetTracker();
  36908. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  36909. var outputLength = output.length;
  36910. privateDictTracker.offset(outputLength);
  36911. if (!privateDictData.length) {
  36912. // The private dictionary was empty, set the output length to zero to
  36913. // ensure the offset length isn't out of bounds in the eyes of the
  36914. // sanitizer.
  36915. outputLength = 0;
  36916. }
  36917. trackers[i].setEntryLocation('Private',
  36918. [privateDictData.length, outputLength],
  36919. output);
  36920. output.add(privateDictData);
  36921. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  36922. var subrs = this.compileIndex(privateDict.subrsIndex);
  36923. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  36924. output);
  36925. output.add(subrs);
  36926. }
  36927. }
  36928. },
  36929. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  36930. var out = [];
  36931. // The dictionary keys must be in a certain order.
  36932. var order = dict.order;
  36933. for (var i = 0; i < order.length; ++i) {
  36934. var key = order[i];
  36935. if (!(key in dict.values)) {
  36936. continue;
  36937. }
  36938. var values = dict.values[key];
  36939. var types = dict.types[key];
  36940. if (!isArray(types)) {
  36941. types = [types];
  36942. }
  36943. if (!isArray(values)) {
  36944. values = [values];
  36945. }
  36946. // Remove any empty dict values.
  36947. if (values.length === 0) {
  36948. continue;
  36949. }
  36950. for (var j = 0, jj = types.length; j < jj; ++j) {
  36951. var type = types[j];
  36952. var value = values[j];
  36953. switch (type) {
  36954. case 'num':
  36955. case 'sid':
  36956. out = out.concat(this.encodeNumber(value));
  36957. break;
  36958. case 'offset':
  36959. // For offsets we just insert a 32bit integer so we don't have to
  36960. // deal with figuring out the length of the offset when it gets
  36961. // replaced later on by the compiler.
  36962. var name = dict.keyToNameMap[key];
  36963. // Some offsets have the offset and the length, so just record the
  36964. // position of the first one.
  36965. if (!offsetTracker.isTracking(name)) {
  36966. offsetTracker.track(name, out.length);
  36967. }
  36968. out = out.concat([0x1d, 0, 0, 0, 0]);
  36969. break;
  36970. case 'array':
  36971. case 'delta':
  36972. out = out.concat(this.encodeNumber(value));
  36973. for (var k = 1, kk = values.length; k < kk; ++k) {
  36974. out = out.concat(this.encodeNumber(values[k]));
  36975. }
  36976. break;
  36977. default:
  36978. error('Unknown data type of ' + type);
  36979. break;
  36980. }
  36981. }
  36982. out = out.concat(dict.opcodes[key]);
  36983. }
  36984. return out;
  36985. },
  36986. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  36987. var stringIndex = new CFFIndex();
  36988. for (var i = 0, ii = strings.length; i < ii; ++i) {
  36989. stringIndex.add(stringToBytes(strings[i]));
  36990. }
  36991. return this.compileIndex(stringIndex);
  36992. },
  36993. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  36994. var globalSubrIndex = this.cff.globalSubrIndex;
  36995. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  36996. },
  36997. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  36998. return this.compileIndex(charStrings);
  36999. },
  37000. compileCharset: function CFFCompiler_compileCharset(charset) {
  37001. return this.compileTypedArray(charset.raw);
  37002. },
  37003. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  37004. return this.compileTypedArray(encoding.raw);
  37005. },
  37006. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  37007. return this.compileTypedArray(fdSelect);
  37008. },
  37009. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  37010. var out = [];
  37011. for (var i = 0, ii = data.length; i < ii; ++i) {
  37012. out[i] = data[i];
  37013. }
  37014. return out;
  37015. },
  37016. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  37017. trackers = trackers || [];
  37018. var objects = index.objects;
  37019. // First 2 bytes contains the number of objects contained into this index
  37020. var count = objects.length;
  37021. // If there is no object, just create an index. This technically
  37022. // should just be [0, 0] but OTS has an issue with that.
  37023. if (count === 0) {
  37024. return [0, 0, 0];
  37025. }
  37026. var data = [(count >> 8) & 0xFF, count & 0xff];
  37027. var lastOffset = 1, i;
  37028. for (i = 0; i < count; ++i) {
  37029. lastOffset += objects[i].length;
  37030. }
  37031. var offsetSize;
  37032. if (lastOffset < 0x100) {
  37033. offsetSize = 1;
  37034. } else if (lastOffset < 0x10000) {
  37035. offsetSize = 2;
  37036. } else if (lastOffset < 0x1000000) {
  37037. offsetSize = 3;
  37038. } else {
  37039. offsetSize = 4;
  37040. }
  37041. // Next byte contains the offset size use to reference object in the file
  37042. data.push(offsetSize);
  37043. // Add another offset after this one because we need a new offset
  37044. var relativeOffset = 1;
  37045. for (i = 0; i < count + 1; i++) {
  37046. if (offsetSize === 1) {
  37047. data.push(relativeOffset & 0xFF);
  37048. } else if (offsetSize === 2) {
  37049. data.push((relativeOffset >> 8) & 0xFF,
  37050. relativeOffset & 0xFF);
  37051. } else if (offsetSize === 3) {
  37052. data.push((relativeOffset >> 16) & 0xFF,
  37053. (relativeOffset >> 8) & 0xFF,
  37054. relativeOffset & 0xFF);
  37055. } else {
  37056. data.push((relativeOffset >>> 24) & 0xFF,
  37057. (relativeOffset >> 16) & 0xFF,
  37058. (relativeOffset >> 8) & 0xFF,
  37059. relativeOffset & 0xFF);
  37060. }
  37061. if (objects[i]) {
  37062. relativeOffset += objects[i].length;
  37063. }
  37064. }
  37065. for (i = 0; i < count; i++) {
  37066. // Notify the tracker where the object will be offset in the data.
  37067. if (trackers[i]) {
  37068. trackers[i].offset(data.length);
  37069. }
  37070. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  37071. data.push(objects[i][j]);
  37072. }
  37073. }
  37074. return data;
  37075. }
  37076. };
  37077. return CFFCompiler;
  37078. })();
  37079. function _enableSeacAnalysis(enabled) {
  37080. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  37081. }
  37082. // Workaround for seac on Windows.
  37083. (function checkSeacSupport() {
  37084. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  37085. SEAC_ANALYSIS_ENABLED = true;
  37086. }
  37087. })();
  37088. // Workaround for Private Use Area characters in Chrome on Windows
  37089. // http://code.google.com/p/chromium/issues/detail?id=122465
  37090. // https://github.com/mozilla/pdf.js/issues/1689
  37091. (function checkChromeWindows() {
  37092. if (typeof navigator !== 'undefined' &&
  37093. /Windows.*Chrome/.test(navigator.userAgent)) {
  37094. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  37095. }
  37096. })();
  37097. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  37098. exports.CFFCompiler = CFFCompiler;
  37099. exports.CFFIndex = CFFIndex;
  37100. exports.CFFParser = CFFParser;
  37101. exports.CFFStrings = CFFStrings;
  37102. exports.Encodings = Encodings;
  37103. exports.ErrorFont = ErrorFont;
  37104. exports.FontFlags = FontFlags;
  37105. exports.Font = Font;
  37106. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  37107. exports.NormalizedUnicodes = NormalizedUnicodes;
  37108. exports.ToUnicodeMap = ToUnicodeMap;
  37109. exports.Type1Parser = Type1Parser;
  37110. exports.getFontType = getFontType;
  37111. exports.reverseIfRtl = reverseIfRtl;
  37112. exports.serifFonts = serifFonts;
  37113. exports.symbolsFonts = symbolsFonts;
  37114. exports.stdFontMap = stdFontMap;
  37115. exports._enableSeacAnalysis = _enableSeacAnalysis;
  37116. // TODO refactor to remove cyclic dependency on font_renderer.js
  37117. coreFontRenderer._setCoreFonts(exports);
  37118. }));
  37119. (function (root, factory) {
  37120. {
  37121. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  37122. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  37123. }
  37124. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  37125. var error = sharedUtil.error;
  37126. var info = sharedUtil.info;
  37127. var isArray = sharedUtil.isArray;
  37128. var isBool = sharedUtil.isBool;
  37129. var isDict = corePrimitives.isDict;
  37130. var isStream = corePrimitives.isStream;
  37131. var PostScriptLexer = corePsParser.PostScriptLexer;
  37132. var PostScriptParser = corePsParser.PostScriptParser;
  37133. var PDFFunction = (function PDFFunctionClosure() {
  37134. var CONSTRUCT_SAMPLED = 0;
  37135. var CONSTRUCT_INTERPOLATED = 2;
  37136. var CONSTRUCT_STICHED = 3;
  37137. var CONSTRUCT_POSTSCRIPT = 4;
  37138. return {
  37139. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  37140. str) {
  37141. var i, ii;
  37142. var length = 1;
  37143. for (i = 0, ii = size.length; i < ii; i++) {
  37144. length *= size[i];
  37145. }
  37146. length *= outputSize;
  37147. var array = new Array(length);
  37148. var codeSize = 0;
  37149. var codeBuf = 0;
  37150. // 32 is a valid bps so shifting won't work
  37151. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  37152. var strBytes = str.getBytes((length * bps + 7) / 8);
  37153. var strIdx = 0;
  37154. for (i = 0; i < length; i++) {
  37155. while (codeSize < bps) {
  37156. codeBuf <<= 8;
  37157. codeBuf |= strBytes[strIdx++];
  37158. codeSize += 8;
  37159. }
  37160. codeSize -= bps;
  37161. array[i] = (codeBuf >> codeSize) * sampleMul;
  37162. codeBuf &= (1 << codeSize) - 1;
  37163. }
  37164. return array;
  37165. },
  37166. getIR: function PDFFunction_getIR(xref, fn) {
  37167. var dict = fn.dict;
  37168. if (!dict) {
  37169. dict = fn;
  37170. }
  37171. var types = [this.constructSampled,
  37172. null,
  37173. this.constructInterpolated,
  37174. this.constructStiched,
  37175. this.constructPostScript];
  37176. var typeNum = dict.get('FunctionType');
  37177. var typeFn = types[typeNum];
  37178. if (!typeFn) {
  37179. error('Unknown type of function');
  37180. }
  37181. return typeFn.call(this, fn, dict, xref);
  37182. },
  37183. fromIR: function PDFFunction_fromIR(IR) {
  37184. var type = IR[0];
  37185. switch (type) {
  37186. case CONSTRUCT_SAMPLED:
  37187. return this.constructSampledFromIR(IR);
  37188. case CONSTRUCT_INTERPOLATED:
  37189. return this.constructInterpolatedFromIR(IR);
  37190. case CONSTRUCT_STICHED:
  37191. return this.constructStichedFromIR(IR);
  37192. //case CONSTRUCT_POSTSCRIPT:
  37193. default:
  37194. return this.constructPostScriptFromIR(IR);
  37195. }
  37196. },
  37197. parse: function PDFFunction_parse(xref, fn) {
  37198. var IR = this.getIR(xref, fn);
  37199. return this.fromIR(IR);
  37200. },
  37201. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  37202. if (!isArray(fnObj)) {
  37203. // not an array -- parsing as regular function
  37204. return this.parse(xref, fnObj);
  37205. }
  37206. var fnArray = [];
  37207. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  37208. var obj = xref.fetchIfRef(fnObj[j]);
  37209. fnArray.push(PDFFunction.parse(xref, obj));
  37210. }
  37211. return function (src, srcOffset, dest, destOffset) {
  37212. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  37213. fnArray[i](src, srcOffset, dest, destOffset + i);
  37214. }
  37215. };
  37216. },
  37217. constructSampled: function PDFFunction_constructSampled(str, dict) {
  37218. function toMultiArray(arr) {
  37219. var inputLength = arr.length;
  37220. var out = [];
  37221. var index = 0;
  37222. for (var i = 0; i < inputLength; i += 2) {
  37223. out[index] = [arr[i], arr[i + 1]];
  37224. ++index;
  37225. }
  37226. return out;
  37227. }
  37228. var domain = dict.get('Domain');
  37229. var range = dict.get('Range');
  37230. if (!domain || !range) {
  37231. error('No domain or range');
  37232. }
  37233. var inputSize = domain.length / 2;
  37234. var outputSize = range.length / 2;
  37235. domain = toMultiArray(domain);
  37236. range = toMultiArray(range);
  37237. var size = dict.get('Size');
  37238. var bps = dict.get('BitsPerSample');
  37239. var order = dict.get('Order') || 1;
  37240. if (order !== 1) {
  37241. // No description how cubic spline interpolation works in PDF32000:2008
  37242. // As in poppler, ignoring order, linear interpolation may work as good
  37243. info('No support for cubic spline interpolation: ' + order);
  37244. }
  37245. var encode = dict.get('Encode');
  37246. if (!encode) {
  37247. encode = [];
  37248. for (var i = 0; i < inputSize; ++i) {
  37249. encode.push(0);
  37250. encode.push(size[i] - 1);
  37251. }
  37252. }
  37253. encode = toMultiArray(encode);
  37254. var decode = dict.get('Decode');
  37255. if (!decode) {
  37256. decode = range;
  37257. } else {
  37258. decode = toMultiArray(decode);
  37259. }
  37260. var samples = this.getSampleArray(size, outputSize, bps, str);
  37261. return [
  37262. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  37263. outputSize, Math.pow(2, bps) - 1, range
  37264. ];
  37265. },
  37266. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  37267. // See chapter 3, page 109 of the PDF reference
  37268. function interpolate(x, xmin, xmax, ymin, ymax) {
  37269. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  37270. }
  37271. return function constructSampledFromIRResult(src, srcOffset,
  37272. dest, destOffset) {
  37273. // See chapter 3, page 110 of the PDF reference.
  37274. var m = IR[1];
  37275. var domain = IR[2];
  37276. var encode = IR[3];
  37277. var decode = IR[4];
  37278. var samples = IR[5];
  37279. var size = IR[6];
  37280. var n = IR[7];
  37281. //var mask = IR[8];
  37282. var range = IR[9];
  37283. // Building the cube vertices: its part and sample index
  37284. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  37285. var cubeVertices = 1 << m;
  37286. var cubeN = new Float64Array(cubeVertices);
  37287. var cubeVertex = new Uint32Array(cubeVertices);
  37288. var i, j;
  37289. for (j = 0; j < cubeVertices; j++) {
  37290. cubeN[j] = 1;
  37291. }
  37292. var k = n, pos = 1;
  37293. // Map x_i to y_j for 0 <= i < m using the sampled function.
  37294. for (i = 0; i < m; ++i) {
  37295. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  37296. var domain_2i = domain[i][0];
  37297. var domain_2i_1 = domain[i][1];
  37298. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  37299. domain_2i_1);
  37300. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  37301. // Encode_2i, Encode_2i+1)
  37302. var e = interpolate(xi, domain_2i, domain_2i_1,
  37303. encode[i][0], encode[i][1]);
  37304. // e_i' = min(max(e_i, 0), Size_i - 1)
  37305. var size_i = size[i];
  37306. e = Math.min(Math.max(e, 0), size_i - 1);
  37307. // Adjusting the cube: N and vertex sample index
  37308. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  37309. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  37310. var n1 = e - e0; // (e - e0) / (e1 - e0);
  37311. var offset0 = e0 * k;
  37312. var offset1 = offset0 + k; // e1 * k
  37313. for (j = 0; j < cubeVertices; j++) {
  37314. if (j & pos) {
  37315. cubeN[j] *= n1;
  37316. cubeVertex[j] += offset1;
  37317. } else {
  37318. cubeN[j] *= n0;
  37319. cubeVertex[j] += offset0;
  37320. }
  37321. }
  37322. k *= size_i;
  37323. pos <<= 1;
  37324. }
  37325. for (j = 0; j < n; ++j) {
  37326. // Sum all cube vertices' samples portions
  37327. var rj = 0;
  37328. for (i = 0; i < cubeVertices; i++) {
  37329. rj += samples[cubeVertex[i] + j] * cubeN[i];
  37330. }
  37331. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  37332. // Decode_2j, Decode_2j+1)
  37333. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  37334. // y_j = min(max(r_j, range_2j), range_2j+1)
  37335. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  37336. range[j][1]);
  37337. }
  37338. };
  37339. },
  37340. constructInterpolated: function PDFFunction_constructInterpolated(str,
  37341. dict) {
  37342. var c0 = dict.get('C0') || [0];
  37343. var c1 = dict.get('C1') || [1];
  37344. var n = dict.get('N');
  37345. if (!isArray(c0) || !isArray(c1)) {
  37346. error('Illegal dictionary for interpolated function');
  37347. }
  37348. var length = c0.length;
  37349. var diff = [];
  37350. for (var i = 0; i < length; ++i) {
  37351. diff.push(c1[i] - c0[i]);
  37352. }
  37353. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  37354. },
  37355. constructInterpolatedFromIR:
  37356. function PDFFunction_constructInterpolatedFromIR(IR) {
  37357. var c0 = IR[1];
  37358. var diff = IR[2];
  37359. var n = IR[3];
  37360. var length = diff.length;
  37361. return function constructInterpolatedFromIRResult(src, srcOffset,
  37362. dest, destOffset) {
  37363. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  37364. for (var j = 0; j < length; ++j) {
  37365. dest[destOffset + j] = c0[j] + (x * diff[j]);
  37366. }
  37367. };
  37368. },
  37369. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  37370. var domain = dict.get('Domain');
  37371. if (!domain) {
  37372. error('No domain');
  37373. }
  37374. var inputSize = domain.length / 2;
  37375. if (inputSize !== 1) {
  37376. error('Bad domain for stiched function');
  37377. }
  37378. var fnRefs = dict.get('Functions');
  37379. var fns = [];
  37380. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  37381. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  37382. }
  37383. var bounds = dict.get('Bounds');
  37384. var encode = dict.get('Encode');
  37385. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  37386. },
  37387. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  37388. var domain = IR[1];
  37389. var bounds = IR[2];
  37390. var encode = IR[3];
  37391. var fnsIR = IR[4];
  37392. var fns = [];
  37393. var tmpBuf = new Float32Array(1);
  37394. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  37395. fns.push(PDFFunction.fromIR(fnsIR[i]));
  37396. }
  37397. return function constructStichedFromIRResult(src, srcOffset,
  37398. dest, destOffset) {
  37399. var clip = function constructStichedFromIRClip(v, min, max) {
  37400. if (v > max) {
  37401. v = max;
  37402. } else if (v < min) {
  37403. v = min;
  37404. }
  37405. return v;
  37406. };
  37407. // clip to domain
  37408. var v = clip(src[srcOffset], domain[0], domain[1]);
  37409. // calulate which bound the value is in
  37410. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  37411. if (v < bounds[i]) {
  37412. break;
  37413. }
  37414. }
  37415. // encode value into domain of function
  37416. var dmin = domain[0];
  37417. if (i > 0) {
  37418. dmin = bounds[i - 1];
  37419. }
  37420. var dmax = domain[1];
  37421. if (i < bounds.length) {
  37422. dmax = bounds[i];
  37423. }
  37424. var rmin = encode[2 * i];
  37425. var rmax = encode[2 * i + 1];
  37426. // Prevent the value from becoming NaN as a result
  37427. // of division by zero (fixes issue6113.pdf).
  37428. tmpBuf[0] = dmin === dmax ? rmin :
  37429. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  37430. // call the appropriate function
  37431. fns[i](tmpBuf, 0, dest, destOffset);
  37432. };
  37433. },
  37434. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  37435. xref) {
  37436. var domain = dict.get('Domain');
  37437. var range = dict.get('Range');
  37438. if (!domain) {
  37439. error('No domain.');
  37440. }
  37441. if (!range) {
  37442. error('No range.');
  37443. }
  37444. var lexer = new PostScriptLexer(fn);
  37445. var parser = new PostScriptParser(lexer);
  37446. var code = parser.parse();
  37447. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  37448. },
  37449. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  37450. IR) {
  37451. var domain = IR[1];
  37452. var range = IR[2];
  37453. var code = IR[3];
  37454. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  37455. if (compiled) {
  37456. // Compiled function consists of simple expressions such as addition,
  37457. // subtraction, Math.max, and also contains 'var' and 'return'
  37458. // statements. See the generation in the PostScriptCompiler below.
  37459. /*jshint -W054 */
  37460. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  37461. }
  37462. info('Unable to compile PS function');
  37463. var numOutputs = range.length >> 1;
  37464. var numInputs = domain.length >> 1;
  37465. var evaluator = new PostScriptEvaluator(code);
  37466. // Cache the values for a big speed up, the cache size is limited though
  37467. // since the number of possible values can be huge from a PS function.
  37468. var cache = {};
  37469. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  37470. // seen in our tests.
  37471. var MAX_CACHE_SIZE = 2048 * 4;
  37472. var cache_available = MAX_CACHE_SIZE;
  37473. var tmpBuf = new Float32Array(numInputs);
  37474. return function constructPostScriptFromIRResult(src, srcOffset,
  37475. dest, destOffset) {
  37476. var i, value;
  37477. var key = '';
  37478. var input = tmpBuf;
  37479. for (i = 0; i < numInputs; i++) {
  37480. value = src[srcOffset + i];
  37481. input[i] = value;
  37482. key += value + '_';
  37483. }
  37484. var cachedValue = cache[key];
  37485. if (cachedValue !== undefined) {
  37486. dest.set(cachedValue, destOffset);
  37487. return;
  37488. }
  37489. var output = new Float32Array(numOutputs);
  37490. var stack = evaluator.execute(input);
  37491. var stackIndex = stack.length - numOutputs;
  37492. for (i = 0; i < numOutputs; i++) {
  37493. value = stack[stackIndex + i];
  37494. var bound = range[i * 2];
  37495. if (value < bound) {
  37496. value = bound;
  37497. } else {
  37498. bound = range[i * 2 +1];
  37499. if (value > bound) {
  37500. value = bound;
  37501. }
  37502. }
  37503. output[i] = value;
  37504. }
  37505. if (cache_available > 0) {
  37506. cache_available--;
  37507. cache[key] = output;
  37508. }
  37509. dest.set(output, destOffset);
  37510. };
  37511. }
  37512. };
  37513. })();
  37514. function isPDFFunction(v) {
  37515. var fnDict;
  37516. if (typeof v !== 'object') {
  37517. return false;
  37518. } else if (isDict(v)) {
  37519. fnDict = v;
  37520. } else if (isStream(v)) {
  37521. fnDict = v.dict;
  37522. } else {
  37523. return false;
  37524. }
  37525. return fnDict.has('FunctionType');
  37526. }
  37527. var PostScriptStack = (function PostScriptStackClosure() {
  37528. var MAX_STACK_SIZE = 100;
  37529. function PostScriptStack(initialStack) {
  37530. this.stack = !initialStack ? [] :
  37531. Array.prototype.slice.call(initialStack, 0);
  37532. }
  37533. PostScriptStack.prototype = {
  37534. push: function PostScriptStack_push(value) {
  37535. if (this.stack.length >= MAX_STACK_SIZE) {
  37536. error('PostScript function stack overflow.');
  37537. }
  37538. this.stack.push(value);
  37539. },
  37540. pop: function PostScriptStack_pop() {
  37541. if (this.stack.length <= 0) {
  37542. error('PostScript function stack underflow.');
  37543. }
  37544. return this.stack.pop();
  37545. },
  37546. copy: function PostScriptStack_copy(n) {
  37547. if (this.stack.length + n >= MAX_STACK_SIZE) {
  37548. error('PostScript function stack overflow.');
  37549. }
  37550. var stack = this.stack;
  37551. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  37552. stack.push(stack[i]);
  37553. }
  37554. },
  37555. index: function PostScriptStack_index(n) {
  37556. this.push(this.stack[this.stack.length - n - 1]);
  37557. },
  37558. // rotate the last n stack elements p times
  37559. roll: function PostScriptStack_roll(n, p) {
  37560. var stack = this.stack;
  37561. var l = stack.length - n;
  37562. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  37563. for (i = l, j = r; i < j; i++, j--) {
  37564. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37565. }
  37566. for (i = l, j = c - 1; i < j; i++, j--) {
  37567. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37568. }
  37569. for (i = c, j = r; i < j; i++, j--) {
  37570. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37571. }
  37572. }
  37573. };
  37574. return PostScriptStack;
  37575. })();
  37576. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  37577. function PostScriptEvaluator(operators) {
  37578. this.operators = operators;
  37579. }
  37580. PostScriptEvaluator.prototype = {
  37581. execute: function PostScriptEvaluator_execute(initialStack) {
  37582. var stack = new PostScriptStack(initialStack);
  37583. var counter = 0;
  37584. var operators = this.operators;
  37585. var length = operators.length;
  37586. var operator, a, b;
  37587. while (counter < length) {
  37588. operator = operators[counter++];
  37589. if (typeof operator === 'number') {
  37590. // Operator is really an operand and should be pushed to the stack.
  37591. stack.push(operator);
  37592. continue;
  37593. }
  37594. switch (operator) {
  37595. // non standard ps operators
  37596. case 'jz': // jump if false
  37597. b = stack.pop();
  37598. a = stack.pop();
  37599. if (!a) {
  37600. counter = b;
  37601. }
  37602. break;
  37603. case 'j': // jump
  37604. a = stack.pop();
  37605. counter = a;
  37606. break;
  37607. // all ps operators in alphabetical order (excluding if/ifelse)
  37608. case 'abs':
  37609. a = stack.pop();
  37610. stack.push(Math.abs(a));
  37611. break;
  37612. case 'add':
  37613. b = stack.pop();
  37614. a = stack.pop();
  37615. stack.push(a + b);
  37616. break;
  37617. case 'and':
  37618. b = stack.pop();
  37619. a = stack.pop();
  37620. if (isBool(a) && isBool(b)) {
  37621. stack.push(a && b);
  37622. } else {
  37623. stack.push(a & b);
  37624. }
  37625. break;
  37626. case 'atan':
  37627. a = stack.pop();
  37628. stack.push(Math.atan(a));
  37629. break;
  37630. case 'bitshift':
  37631. b = stack.pop();
  37632. a = stack.pop();
  37633. if (a > 0) {
  37634. stack.push(a << b);
  37635. } else {
  37636. stack.push(a >> b);
  37637. }
  37638. break;
  37639. case 'ceiling':
  37640. a = stack.pop();
  37641. stack.push(Math.ceil(a));
  37642. break;
  37643. case 'copy':
  37644. a = stack.pop();
  37645. stack.copy(a);
  37646. break;
  37647. case 'cos':
  37648. a = stack.pop();
  37649. stack.push(Math.cos(a));
  37650. break;
  37651. case 'cvi':
  37652. a = stack.pop() | 0;
  37653. stack.push(a);
  37654. break;
  37655. case 'cvr':
  37656. // noop
  37657. break;
  37658. case 'div':
  37659. b = stack.pop();
  37660. a = stack.pop();
  37661. stack.push(a / b);
  37662. break;
  37663. case 'dup':
  37664. stack.copy(1);
  37665. break;
  37666. case 'eq':
  37667. b = stack.pop();
  37668. a = stack.pop();
  37669. stack.push(a === b);
  37670. break;
  37671. case 'exch':
  37672. stack.roll(2, 1);
  37673. break;
  37674. case 'exp':
  37675. b = stack.pop();
  37676. a = stack.pop();
  37677. stack.push(Math.pow(a, b));
  37678. break;
  37679. case 'false':
  37680. stack.push(false);
  37681. break;
  37682. case 'floor':
  37683. a = stack.pop();
  37684. stack.push(Math.floor(a));
  37685. break;
  37686. case 'ge':
  37687. b = stack.pop();
  37688. a = stack.pop();
  37689. stack.push(a >= b);
  37690. break;
  37691. case 'gt':
  37692. b = stack.pop();
  37693. a = stack.pop();
  37694. stack.push(a > b);
  37695. break;
  37696. case 'idiv':
  37697. b = stack.pop();
  37698. a = stack.pop();
  37699. stack.push((a / b) | 0);
  37700. break;
  37701. case 'index':
  37702. a = stack.pop();
  37703. stack.index(a);
  37704. break;
  37705. case 'le':
  37706. b = stack.pop();
  37707. a = stack.pop();
  37708. stack.push(a <= b);
  37709. break;
  37710. case 'ln':
  37711. a = stack.pop();
  37712. stack.push(Math.log(a));
  37713. break;
  37714. case 'log':
  37715. a = stack.pop();
  37716. stack.push(Math.log(a) / Math.LN10);
  37717. break;
  37718. case 'lt':
  37719. b = stack.pop();
  37720. a = stack.pop();
  37721. stack.push(a < b);
  37722. break;
  37723. case 'mod':
  37724. b = stack.pop();
  37725. a = stack.pop();
  37726. stack.push(a % b);
  37727. break;
  37728. case 'mul':
  37729. b = stack.pop();
  37730. a = stack.pop();
  37731. stack.push(a * b);
  37732. break;
  37733. case 'ne':
  37734. b = stack.pop();
  37735. a = stack.pop();
  37736. stack.push(a !== b);
  37737. break;
  37738. case 'neg':
  37739. a = stack.pop();
  37740. stack.push(-a);
  37741. break;
  37742. case 'not':
  37743. a = stack.pop();
  37744. if (isBool(a)) {
  37745. stack.push(!a);
  37746. } else {
  37747. stack.push(~a);
  37748. }
  37749. break;
  37750. case 'or':
  37751. b = stack.pop();
  37752. a = stack.pop();
  37753. if (isBool(a) && isBool(b)) {
  37754. stack.push(a || b);
  37755. } else {
  37756. stack.push(a | b);
  37757. }
  37758. break;
  37759. case 'pop':
  37760. stack.pop();
  37761. break;
  37762. case 'roll':
  37763. b = stack.pop();
  37764. a = stack.pop();
  37765. stack.roll(a, b);
  37766. break;
  37767. case 'round':
  37768. a = stack.pop();
  37769. stack.push(Math.round(a));
  37770. break;
  37771. case 'sin':
  37772. a = stack.pop();
  37773. stack.push(Math.sin(a));
  37774. break;
  37775. case 'sqrt':
  37776. a = stack.pop();
  37777. stack.push(Math.sqrt(a));
  37778. break;
  37779. case 'sub':
  37780. b = stack.pop();
  37781. a = stack.pop();
  37782. stack.push(a - b);
  37783. break;
  37784. case 'true':
  37785. stack.push(true);
  37786. break;
  37787. case 'truncate':
  37788. a = stack.pop();
  37789. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  37790. stack.push(a);
  37791. break;
  37792. case 'xor':
  37793. b = stack.pop();
  37794. a = stack.pop();
  37795. if (isBool(a) && isBool(b)) {
  37796. stack.push(a !== b);
  37797. } else {
  37798. stack.push(a ^ b);
  37799. }
  37800. break;
  37801. default:
  37802. error('Unknown operator ' + operator);
  37803. break;
  37804. }
  37805. }
  37806. return stack.stack;
  37807. }
  37808. };
  37809. return PostScriptEvaluator;
  37810. })();
  37811. // Most of the PDFs functions consist of simple operations such as:
  37812. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  37813. //
  37814. // We can compile most of such programs, and at the same moment, we can
  37815. // optimize some expressions using basic math properties. Keeping track of
  37816. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  37817. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  37818. function AstNode(type) {
  37819. this.type = type;
  37820. }
  37821. AstNode.prototype.visit = function (visitor) {
  37822. throw new Error('abstract method');
  37823. };
  37824. function AstArgument(index, min, max) {
  37825. AstNode.call(this, 'args');
  37826. this.index = index;
  37827. this.min = min;
  37828. this.max = max;
  37829. }
  37830. AstArgument.prototype = Object.create(AstNode.prototype);
  37831. AstArgument.prototype.visit = function (visitor) {
  37832. visitor.visitArgument(this);
  37833. };
  37834. function AstLiteral(number) {
  37835. AstNode.call(this, 'literal');
  37836. this.number = number;
  37837. this.min = number;
  37838. this.max = number;
  37839. }
  37840. AstLiteral.prototype = Object.create(AstNode.prototype);
  37841. AstLiteral.prototype.visit = function (visitor) {
  37842. visitor.visitLiteral(this);
  37843. };
  37844. function AstBinaryOperation(op, arg1, arg2, min, max) {
  37845. AstNode.call(this, 'binary');
  37846. this.op = op;
  37847. this.arg1 = arg1;
  37848. this.arg2 = arg2;
  37849. this.min = min;
  37850. this.max = max;
  37851. }
  37852. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  37853. AstBinaryOperation.prototype.visit = function (visitor) {
  37854. visitor.visitBinaryOperation(this);
  37855. };
  37856. function AstMin(arg, max) {
  37857. AstNode.call(this, 'max');
  37858. this.arg = arg;
  37859. this.min = arg.min;
  37860. this.max = max;
  37861. }
  37862. AstMin.prototype = Object.create(AstNode.prototype);
  37863. AstMin.prototype.visit = function (visitor) {
  37864. visitor.visitMin(this);
  37865. };
  37866. function AstVariable(index, min, max) {
  37867. AstNode.call(this, 'var');
  37868. this.index = index;
  37869. this.min = min;
  37870. this.max = max;
  37871. }
  37872. AstVariable.prototype = Object.create(AstNode.prototype);
  37873. AstVariable.prototype.visit = function (visitor) {
  37874. visitor.visitVariable(this);
  37875. };
  37876. function AstVariableDefinition(variable, arg) {
  37877. AstNode.call(this, 'definition');
  37878. this.variable = variable;
  37879. this.arg = arg;
  37880. }
  37881. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  37882. AstVariableDefinition.prototype.visit = function (visitor) {
  37883. visitor.visitVariableDefinition(this);
  37884. };
  37885. function ExpressionBuilderVisitor() {
  37886. this.parts = [];
  37887. }
  37888. ExpressionBuilderVisitor.prototype = {
  37889. visitArgument: function (arg) {
  37890. this.parts.push('Math.max(', arg.min, ', Math.min(',
  37891. arg.max, ', src[srcOffset + ', arg.index, ']))');
  37892. },
  37893. visitVariable: function (variable) {
  37894. this.parts.push('v', variable.index);
  37895. },
  37896. visitLiteral: function (literal) {
  37897. this.parts.push(literal.number);
  37898. },
  37899. visitBinaryOperation: function (operation) {
  37900. this.parts.push('(');
  37901. operation.arg1.visit(this);
  37902. this.parts.push(' ', operation.op, ' ');
  37903. operation.arg2.visit(this);
  37904. this.parts.push(')');
  37905. },
  37906. visitVariableDefinition: function (definition) {
  37907. this.parts.push('var ');
  37908. definition.variable.visit(this);
  37909. this.parts.push(' = ');
  37910. definition.arg.visit(this);
  37911. this.parts.push(';');
  37912. },
  37913. visitMin: function (max) {
  37914. this.parts.push('Math.min(');
  37915. max.arg.visit(this);
  37916. this.parts.push(', ', max.max, ')');
  37917. },
  37918. toString: function () {
  37919. return this.parts.join('');
  37920. }
  37921. };
  37922. function buildAddOperation(num1, num2) {
  37923. if (num2.type === 'literal' && num2.number === 0) {
  37924. // optimization: second operand is 0
  37925. return num1;
  37926. }
  37927. if (num1.type === 'literal' && num1.number === 0) {
  37928. // optimization: first operand is 0
  37929. return num2;
  37930. }
  37931. if (num2.type === 'literal' && num1.type === 'literal') {
  37932. // optimization: operands operand are literals
  37933. return new AstLiteral(num1.number + num2.number);
  37934. }
  37935. return new AstBinaryOperation('+', num1, num2,
  37936. num1.min + num2.min, num1.max + num2.max);
  37937. }
  37938. function buildMulOperation(num1, num2) {
  37939. if (num2.type === 'literal') {
  37940. // optimization: second operands is a literal...
  37941. if (num2.number === 0) {
  37942. return new AstLiteral(0); // and it's 0
  37943. } else if (num2.number === 1) {
  37944. return num1; // and it's 1
  37945. } else if (num1.type === 'literal') {
  37946. // ... and first operands is a literal too
  37947. return new AstLiteral(num1.number * num2.number);
  37948. }
  37949. }
  37950. if (num1.type === 'literal') {
  37951. // optimization: first operands is a literal...
  37952. if (num1.number === 0) {
  37953. return new AstLiteral(0); // and it's 0
  37954. } else if (num1.number === 1) {
  37955. return num2; // and it's 1
  37956. }
  37957. }
  37958. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  37959. num1.max * num2.min, num1.max * num2.max);
  37960. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  37961. num1.max * num2.min, num1.max * num2.max);
  37962. return new AstBinaryOperation('*', num1, num2, min, max);
  37963. }
  37964. function buildSubOperation(num1, num2) {
  37965. if (num2.type === 'literal') {
  37966. // optimization: second operands is a literal...
  37967. if (num2.number === 0) {
  37968. return num1; // ... and it's 0
  37969. } else if (num1.type === 'literal') {
  37970. // ... and first operands is a literal too
  37971. return new AstLiteral(num1.number - num2.number);
  37972. }
  37973. }
  37974. if (num2.type === 'binary' && num2.op === '-' &&
  37975. num1.type === 'literal' && num1.number === 1 &&
  37976. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  37977. // optimization for case: 1 - (1 - x)
  37978. return num2.arg2;
  37979. }
  37980. return new AstBinaryOperation('-', num1, num2,
  37981. num1.min - num2.max, num1.max - num2.min);
  37982. }
  37983. function buildMinOperation(num1, max) {
  37984. if (num1.min >= max) {
  37985. // optimization: num1 min value is not less than required max
  37986. return new AstLiteral(max); // just returning max
  37987. } else if (num1.max <= max) {
  37988. // optimization: num1 max value is not greater than required max
  37989. return num1; // just returning an argument
  37990. }
  37991. return new AstMin(num1, max);
  37992. }
  37993. function PostScriptCompiler() {}
  37994. PostScriptCompiler.prototype = {
  37995. compile: function PostScriptCompiler_compile(code, domain, range) {
  37996. var stack = [];
  37997. var i, ii;
  37998. var instructions = [];
  37999. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  38000. var lastRegister = 0;
  38001. var n, j;
  38002. var num1, num2, ast1, ast2, tmpVar, item;
  38003. for (i = 0; i < inputSize; i++) {
  38004. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  38005. }
  38006. for (i = 0, ii = code.length; i < ii; i++) {
  38007. item = code[i];
  38008. if (typeof item === 'number') {
  38009. stack.push(new AstLiteral(item));
  38010. continue;
  38011. }
  38012. switch (item) {
  38013. case 'add':
  38014. if (stack.length < 2) {
  38015. return null;
  38016. }
  38017. num2 = stack.pop();
  38018. num1 = stack.pop();
  38019. stack.push(buildAddOperation(num1, num2));
  38020. break;
  38021. case 'cvr':
  38022. if (stack.length < 1) {
  38023. return null;
  38024. }
  38025. break;
  38026. case 'mul':
  38027. if (stack.length < 2) {
  38028. return null;
  38029. }
  38030. num2 = stack.pop();
  38031. num1 = stack.pop();
  38032. stack.push(buildMulOperation(num1, num2));
  38033. break;
  38034. case 'sub':
  38035. if (stack.length < 2) {
  38036. return null;
  38037. }
  38038. num2 = stack.pop();
  38039. num1 = stack.pop();
  38040. stack.push(buildSubOperation(num1, num2));
  38041. break;
  38042. case 'exch':
  38043. if (stack.length < 2) {
  38044. return null;
  38045. }
  38046. ast1 = stack.pop(); ast2 = stack.pop();
  38047. stack.push(ast1, ast2);
  38048. break;
  38049. case 'pop':
  38050. if (stack.length < 1) {
  38051. return null;
  38052. }
  38053. stack.pop();
  38054. break;
  38055. case 'index':
  38056. if (stack.length < 1) {
  38057. return null;
  38058. }
  38059. num1 = stack.pop();
  38060. if (num1.type !== 'literal') {
  38061. return null;
  38062. }
  38063. n = num1.number;
  38064. if (n < 0 || (n|0) !== n || stack.length < n) {
  38065. return null;
  38066. }
  38067. ast1 = stack[stack.length - n - 1];
  38068. if (ast1.type === 'literal' || ast1.type === 'var') {
  38069. stack.push(ast1);
  38070. break;
  38071. }
  38072. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  38073. stack[stack.length - n - 1] = tmpVar;
  38074. stack.push(tmpVar);
  38075. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  38076. break;
  38077. case 'dup':
  38078. if (stack.length < 1) {
  38079. return null;
  38080. }
  38081. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  38082. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  38083. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  38084. // special case of the commands sequence for the min operation
  38085. num1 = stack.pop();
  38086. stack.push(buildMinOperation(num1, code[i + 1]));
  38087. i += 6;
  38088. break;
  38089. }
  38090. ast1 = stack[stack.length - 1];
  38091. if (ast1.type === 'literal' || ast1.type === 'var') {
  38092. // we don't have to save into intermediate variable a literal or
  38093. // variable.
  38094. stack.push(ast1);
  38095. break;
  38096. }
  38097. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  38098. stack[stack.length - 1] = tmpVar;
  38099. stack.push(tmpVar);
  38100. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  38101. break;
  38102. case 'roll':
  38103. if (stack.length < 2) {
  38104. return null;
  38105. }
  38106. num2 = stack.pop();
  38107. num1 = stack.pop();
  38108. if (num2.type !== 'literal' || num1.type !== 'literal') {
  38109. // both roll operands must be numbers
  38110. return null;
  38111. }
  38112. j = num2.number;
  38113. n = num1.number;
  38114. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  38115. // ... and integers
  38116. return null;
  38117. }
  38118. j = ((j % n) + n) % n;
  38119. if (j === 0) {
  38120. break; // just skipping -- there are nothing to rotate
  38121. }
  38122. Array.prototype.push.apply(stack,
  38123. stack.splice(stack.length - n, n - j));
  38124. break;
  38125. default:
  38126. return null; // unsupported operator
  38127. }
  38128. }
  38129. if (stack.length !== outputSize) {
  38130. return null;
  38131. }
  38132. var result = [];
  38133. instructions.forEach(function (instruction) {
  38134. var statementBuilder = new ExpressionBuilderVisitor();
  38135. instruction.visit(statementBuilder);
  38136. result.push(statementBuilder.toString());
  38137. });
  38138. stack.forEach(function (expr, i) {
  38139. var statementBuilder = new ExpressionBuilderVisitor();
  38140. expr.visit(statementBuilder);
  38141. var min = range[i * 2], max = range[i * 2 + 1];
  38142. var out = [statementBuilder.toString()];
  38143. if (min > expr.min) {
  38144. out.unshift('Math.max(', min, ', ');
  38145. out.push(')');
  38146. }
  38147. if (max < expr.max) {
  38148. out.unshift('Math.min(', max, ', ');
  38149. out.push(')');
  38150. }
  38151. out.unshift('dest[destOffset + ', i, '] = ');
  38152. out.push(';');
  38153. result.push(out.join(''));
  38154. });
  38155. return result.join('\n');
  38156. }
  38157. };
  38158. return PostScriptCompiler;
  38159. })();
  38160. exports.isPDFFunction = isPDFFunction;
  38161. exports.PDFFunction = PDFFunction;
  38162. exports.PostScriptEvaluator = PostScriptEvaluator;
  38163. exports.PostScriptCompiler = PostScriptCompiler;
  38164. }));
  38165. (function (root, factory) {
  38166. {
  38167. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38168. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  38169. }
  38170. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  38171. coreStream) {
  38172. var error = sharedUtil.error;
  38173. var info = sharedUtil.info;
  38174. var isArray = sharedUtil.isArray;
  38175. var isString = sharedUtil.isString;
  38176. var shadow = sharedUtil.shadow;
  38177. var warn = sharedUtil.warn;
  38178. var isDict = corePrimitives.isDict;
  38179. var isName = corePrimitives.isName;
  38180. var isStream = corePrimitives.isStream;
  38181. var PDFFunction = coreFunction.PDFFunction;
  38182. var coreImage; // see _setCoreImage below
  38183. var PDFImage; // = coreImage.PDFImage;
  38184. var ColorSpace = (function ColorSpaceClosure() {
  38185. // Constructor should define this.numComps, this.defaultColor, this.name
  38186. function ColorSpace() {
  38187. error('should not call ColorSpace constructor');
  38188. }
  38189. ColorSpace.prototype = {
  38190. /**
  38191. * Converts the color value to the RGB color. The color components are
  38192. * located in the src array starting from the srcOffset. Returns the array
  38193. * of the rgb components, each value ranging from [0,255].
  38194. */
  38195. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38196. var rgb = new Uint8Array(3);
  38197. this.getRgbItem(src, srcOffset, rgb, 0);
  38198. return rgb;
  38199. },
  38200. /**
  38201. * Converts the color value to the RGB color, similar to the getRgb method.
  38202. * The result placed into the dest array starting from the destOffset.
  38203. */
  38204. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38205. dest, destOffset) {
  38206. error('Should not call ColorSpace.getRgbItem');
  38207. },
  38208. /**
  38209. * Converts the specified number of the color values to the RGB colors.
  38210. * The colors are located in the src array starting from the srcOffset.
  38211. * The result is placed into the dest array starting from the destOffset.
  38212. * The src array items shall be in [0,2^bits) range, the dest array items
  38213. * will be in [0,255] range. alpha01 indicates how many alpha components
  38214. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38215. * array).
  38216. */
  38217. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38218. dest, destOffset, bits,
  38219. alpha01) {
  38220. error('Should not call ColorSpace.getRgbBuffer');
  38221. },
  38222. /**
  38223. * Determines the number of bytes required to store the result of the
  38224. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38225. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38226. */
  38227. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38228. alpha01) {
  38229. error('Should not call ColorSpace.getOutputLength');
  38230. },
  38231. /**
  38232. * Returns true if source data will be equal the result/output data.
  38233. */
  38234. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38235. return false;
  38236. },
  38237. /**
  38238. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38239. * how many alpha components there are in the dest array; it will be either
  38240. * 0 (RGB array) or 1 (RGBA array).
  38241. */
  38242. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38243. originalHeight, width, height,
  38244. actualHeight, bpc, comps, alpha01) {
  38245. var count = originalWidth * originalHeight;
  38246. var rgbBuf = null;
  38247. var numComponentColors = 1 << bpc;
  38248. var needsResizing = originalHeight !== height || originalWidth !== width;
  38249. var i, ii;
  38250. if (this.isPassthrough(bpc)) {
  38251. rgbBuf = comps;
  38252. } else if (this.numComps === 1 && count > numComponentColors &&
  38253. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38254. // Optimization: create a color map when there is just one component and
  38255. // we are converting more colors than the size of the color map. We
  38256. // don't build the map if the colorspace is gray or rgb since those
  38257. // methods are faster than building a map. This mainly offers big speed
  38258. // ups for indexed and alternate colorspaces.
  38259. //
  38260. // TODO it may be worth while to cache the color map. While running
  38261. // testing I never hit a cache so I will leave that out for now (perhaps
  38262. // we are reparsing colorspaces too much?).
  38263. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38264. new Uint16Array(numComponentColors);
  38265. var key;
  38266. for (i = 0; i < numComponentColors; i++) {
  38267. allColors[i] = i;
  38268. }
  38269. var colorMap = new Uint8Array(numComponentColors * 3);
  38270. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38271. /* alpha01 = */ 0);
  38272. var destPos, rgbPos;
  38273. if (!needsResizing) {
  38274. // Fill in the RGB values directly into |dest|.
  38275. destPos = 0;
  38276. for (i = 0; i < count; ++i) {
  38277. key = comps[i] * 3;
  38278. dest[destPos++] = colorMap[key];
  38279. dest[destPos++] = colorMap[key + 1];
  38280. dest[destPos++] = colorMap[key + 2];
  38281. destPos += alpha01;
  38282. }
  38283. } else {
  38284. rgbBuf = new Uint8Array(count * 3);
  38285. rgbPos = 0;
  38286. for (i = 0; i < count; ++i) {
  38287. key = comps[i] * 3;
  38288. rgbBuf[rgbPos++] = colorMap[key];
  38289. rgbBuf[rgbPos++] = colorMap[key + 1];
  38290. rgbBuf[rgbPos++] = colorMap[key + 2];
  38291. }
  38292. }
  38293. } else {
  38294. if (!needsResizing) {
  38295. // Fill in the RGB values directly into |dest|.
  38296. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38297. alpha01);
  38298. } else {
  38299. rgbBuf = new Uint8Array(count * 3);
  38300. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38301. /* alpha01 = */ 0);
  38302. }
  38303. }
  38304. if (rgbBuf) {
  38305. if (needsResizing) {
  38306. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  38307. height, dest, alpha01);
  38308. } else {
  38309. rgbPos = 0;
  38310. destPos = 0;
  38311. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38312. dest[destPos++] = rgbBuf[rgbPos++];
  38313. dest[destPos++] = rgbBuf[rgbPos++];
  38314. dest[destPos++] = rgbBuf[rgbPos++];
  38315. destPos += alpha01;
  38316. }
  38317. }
  38318. }
  38319. },
  38320. /**
  38321. * True if the colorspace has components in the default range of [0, 1].
  38322. * This should be true for all colorspaces except for lab color spaces
  38323. * which are [0,100], [-128, 127], [-128, 127].
  38324. */
  38325. usesZeroToOneRange: true
  38326. };
  38327. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38328. var IR = ColorSpace.parseToIR(cs, xref, res);
  38329. if (IR instanceof AlternateCS) {
  38330. return IR;
  38331. }
  38332. return ColorSpace.fromIR(IR);
  38333. };
  38334. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38335. var name = isArray(IR) ? IR[0] : IR;
  38336. var whitePoint, blackPoint, gamma;
  38337. switch (name) {
  38338. case 'DeviceGrayCS':
  38339. return this.singletons.gray;
  38340. case 'DeviceRgbCS':
  38341. return this.singletons.rgb;
  38342. case 'DeviceCmykCS':
  38343. return this.singletons.cmyk;
  38344. case 'CalGrayCS':
  38345. whitePoint = IR[1].WhitePoint;
  38346. blackPoint = IR[1].BlackPoint;
  38347. gamma = IR[1].Gamma;
  38348. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38349. case 'CalRGBCS':
  38350. whitePoint = IR[1].WhitePoint;
  38351. blackPoint = IR[1].BlackPoint;
  38352. gamma = IR[1].Gamma;
  38353. var matrix = IR[1].Matrix;
  38354. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38355. case 'PatternCS':
  38356. var basePatternCS = IR[1];
  38357. if (basePatternCS) {
  38358. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38359. }
  38360. return new PatternCS(basePatternCS);
  38361. case 'IndexedCS':
  38362. var baseIndexedCS = IR[1];
  38363. var hiVal = IR[2];
  38364. var lookup = IR[3];
  38365. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38366. case 'AlternateCS':
  38367. var numComps = IR[1];
  38368. var alt = IR[2];
  38369. var tintFnIR = IR[3];
  38370. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38371. PDFFunction.fromIR(tintFnIR));
  38372. case 'LabCS':
  38373. whitePoint = IR[1].WhitePoint;
  38374. blackPoint = IR[1].BlackPoint;
  38375. var range = IR[1].Range;
  38376. return new LabCS(whitePoint, blackPoint, range);
  38377. default:
  38378. error('Unknown name ' + name);
  38379. }
  38380. return null;
  38381. };
  38382. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38383. if (isName(cs)) {
  38384. var colorSpaces = res.get('ColorSpace');
  38385. if (isDict(colorSpaces)) {
  38386. var refcs = colorSpaces.get(cs.name);
  38387. if (refcs) {
  38388. cs = refcs;
  38389. }
  38390. }
  38391. }
  38392. cs = xref.fetchIfRef(cs);
  38393. var mode;
  38394. if (isName(cs)) {
  38395. mode = cs.name;
  38396. this.mode = mode;
  38397. switch (mode) {
  38398. case 'DeviceGray':
  38399. case 'G':
  38400. return 'DeviceGrayCS';
  38401. case 'DeviceRGB':
  38402. case 'RGB':
  38403. return 'DeviceRgbCS';
  38404. case 'DeviceCMYK':
  38405. case 'CMYK':
  38406. return 'DeviceCmykCS';
  38407. case 'Pattern':
  38408. return ['PatternCS', null];
  38409. default:
  38410. error('unrecognized colorspace ' + mode);
  38411. }
  38412. } else if (isArray(cs)) {
  38413. mode = xref.fetchIfRef(cs[0]).name;
  38414. this.mode = mode;
  38415. var numComps, params, alt;
  38416. switch (mode) {
  38417. case 'DeviceGray':
  38418. case 'G':
  38419. return 'DeviceGrayCS';
  38420. case 'DeviceRGB':
  38421. case 'RGB':
  38422. return 'DeviceRgbCS';
  38423. case 'DeviceCMYK':
  38424. case 'CMYK':
  38425. return 'DeviceCmykCS';
  38426. case 'CalGray':
  38427. params = xref.fetchIfRef(cs[1]).getAll();
  38428. return ['CalGrayCS', params];
  38429. case 'CalRGB':
  38430. params = xref.fetchIfRef(cs[1]).getAll();
  38431. return ['CalRGBCS', params];
  38432. case 'ICCBased':
  38433. var stream = xref.fetchIfRef(cs[1]);
  38434. var dict = stream.dict;
  38435. numComps = dict.get('N');
  38436. alt = dict.get('Alternate');
  38437. if (alt) {
  38438. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38439. // Parse the /Alternate CS to ensure that the number of components
  38440. // are correct, and also (indirectly) that it is not a PatternCS.
  38441. var altCS = ColorSpace.fromIR(altIR);
  38442. if (altCS.numComps === numComps) {
  38443. return altIR;
  38444. }
  38445. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38446. }
  38447. if (numComps === 1) {
  38448. return 'DeviceGrayCS';
  38449. } else if (numComps === 3) {
  38450. return 'DeviceRgbCS';
  38451. } else if (numComps === 4) {
  38452. return 'DeviceCmykCS';
  38453. }
  38454. break;
  38455. case 'Pattern':
  38456. var basePatternCS = cs[1] || null;
  38457. if (basePatternCS) {
  38458. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38459. }
  38460. return ['PatternCS', basePatternCS];
  38461. case 'Indexed':
  38462. case 'I':
  38463. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38464. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38465. var lookup = xref.fetchIfRef(cs[3]);
  38466. if (isStream(lookup)) {
  38467. lookup = lookup.getBytes();
  38468. }
  38469. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38470. case 'Separation':
  38471. case 'DeviceN':
  38472. var name = xref.fetchIfRef(cs[1]);
  38473. numComps = 1;
  38474. if (isName(name)) {
  38475. numComps = 1;
  38476. } else if (isArray(name)) {
  38477. numComps = name.length;
  38478. }
  38479. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38480. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38481. return ['AlternateCS', numComps, alt, tintFnIR];
  38482. case 'Lab':
  38483. params = xref.fetchIfRef(cs[1]).getAll();
  38484. return ['LabCS', params];
  38485. default:
  38486. error('unimplemented color space object "' + mode + '"');
  38487. }
  38488. } else {
  38489. error('unrecognized color space object: "' + cs + '"');
  38490. }
  38491. return null;
  38492. };
  38493. /**
  38494. * Checks if a decode map matches the default decode map for a color space.
  38495. * This handles the general decode maps where there are two values per
  38496. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38497. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38498. * slightly different.
  38499. * @param {Array} decode Decode map (usually from an image).
  38500. * @param {Number} n Number of components the color space has.
  38501. */
  38502. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38503. if (!isArray(decode)) {
  38504. return true;
  38505. }
  38506. if (n * 2 !== decode.length) {
  38507. warn('The decode map is not the correct length');
  38508. return true;
  38509. }
  38510. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38511. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38512. return false;
  38513. }
  38514. }
  38515. return true;
  38516. };
  38517. ColorSpace.singletons = {
  38518. get gray() {
  38519. return shadow(this, 'gray', new DeviceGrayCS());
  38520. },
  38521. get rgb() {
  38522. return shadow(this, 'rgb', new DeviceRgbCS());
  38523. },
  38524. get cmyk() {
  38525. return shadow(this, 'cmyk', new DeviceCmykCS());
  38526. }
  38527. };
  38528. return ColorSpace;
  38529. })();
  38530. /**
  38531. * Alternate color space handles both Separation and DeviceN color spaces. A
  38532. * Separation color space is actually just a DeviceN with one color component.
  38533. * Both color spaces use a tinting function to convert colors to a base color
  38534. * space.
  38535. */
  38536. var AlternateCS = (function AlternateCSClosure() {
  38537. function AlternateCS(numComps, base, tintFn) {
  38538. this.name = 'Alternate';
  38539. this.numComps = numComps;
  38540. this.defaultColor = new Float32Array(numComps);
  38541. for (var i = 0; i < numComps; ++i) {
  38542. this.defaultColor[i] = 1;
  38543. }
  38544. this.base = base;
  38545. this.tintFn = tintFn;
  38546. this.tmpBuf = new Float32Array(base.numComps);
  38547. }
  38548. AlternateCS.prototype = {
  38549. getRgb: ColorSpace.prototype.getRgb,
  38550. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38551. dest, destOffset) {
  38552. var tmpBuf = this.tmpBuf;
  38553. this.tintFn(src, srcOffset, tmpBuf, 0);
  38554. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38555. },
  38556. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38557. dest, destOffset, bits,
  38558. alpha01) {
  38559. var tintFn = this.tintFn;
  38560. var base = this.base;
  38561. var scale = 1 / ((1 << bits) - 1);
  38562. var baseNumComps = base.numComps;
  38563. var usesZeroToOneRange = base.usesZeroToOneRange;
  38564. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38565. alpha01 === 0;
  38566. var pos = isPassthrough ? destOffset : 0;
  38567. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38568. var numComps = this.numComps;
  38569. var scaled = new Float32Array(numComps);
  38570. var tinted = new Float32Array(baseNumComps);
  38571. var i, j;
  38572. if (usesZeroToOneRange) {
  38573. for (i = 0; i < count; i++) {
  38574. for (j = 0; j < numComps; j++) {
  38575. scaled[j] = src[srcOffset++] * scale;
  38576. }
  38577. tintFn(scaled, 0, tinted, 0);
  38578. for (j = 0; j < baseNumComps; j++) {
  38579. baseBuf[pos++] = tinted[j] * 255;
  38580. }
  38581. }
  38582. } else {
  38583. for (i = 0; i < count; i++) {
  38584. for (j = 0; j < numComps; j++) {
  38585. scaled[j] = src[srcOffset++] * scale;
  38586. }
  38587. tintFn(scaled, 0, tinted, 0);
  38588. base.getRgbItem(tinted, 0, baseBuf, pos);
  38589. pos += baseNumComps;
  38590. }
  38591. }
  38592. if (!isPassthrough) {
  38593. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38594. }
  38595. },
  38596. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38597. alpha01) {
  38598. return this.base.getOutputLength(inputLength *
  38599. this.base.numComps / this.numComps,
  38600. alpha01);
  38601. },
  38602. isPassthrough: ColorSpace.prototype.isPassthrough,
  38603. fillRgb: ColorSpace.prototype.fillRgb,
  38604. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38605. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38606. },
  38607. usesZeroToOneRange: true
  38608. };
  38609. return AlternateCS;
  38610. })();
  38611. var PatternCS = (function PatternCSClosure() {
  38612. function PatternCS(baseCS) {
  38613. this.name = 'Pattern';
  38614. this.base = baseCS;
  38615. }
  38616. PatternCS.prototype = {};
  38617. return PatternCS;
  38618. })();
  38619. var IndexedCS = (function IndexedCSClosure() {
  38620. function IndexedCS(base, highVal, lookup) {
  38621. this.name = 'Indexed';
  38622. this.numComps = 1;
  38623. this.defaultColor = new Uint8Array([0]);
  38624. this.base = base;
  38625. this.highVal = highVal;
  38626. var baseNumComps = base.numComps;
  38627. var length = baseNumComps * highVal;
  38628. var lookupArray;
  38629. if (isStream(lookup)) {
  38630. lookupArray = new Uint8Array(length);
  38631. var bytes = lookup.getBytes(length);
  38632. lookupArray.set(bytes);
  38633. } else if (isString(lookup)) {
  38634. lookupArray = new Uint8Array(length);
  38635. for (var i = 0; i < length; ++i) {
  38636. lookupArray[i] = lookup.charCodeAt(i);
  38637. }
  38638. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38639. lookupArray = lookup;
  38640. } else {
  38641. error('Unrecognized lookup table: ' + lookup);
  38642. }
  38643. this.lookup = lookupArray;
  38644. }
  38645. IndexedCS.prototype = {
  38646. getRgb: ColorSpace.prototype.getRgb,
  38647. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38648. dest, destOffset) {
  38649. var numComps = this.base.numComps;
  38650. var start = src[srcOffset] * numComps;
  38651. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38652. },
  38653. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38654. dest, destOffset, bits,
  38655. alpha01) {
  38656. var base = this.base;
  38657. var numComps = base.numComps;
  38658. var outputDelta = base.getOutputLength(numComps, alpha01);
  38659. var lookup = this.lookup;
  38660. for (var i = 0; i < count; ++i) {
  38661. var lookupPos = src[srcOffset++] * numComps;
  38662. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38663. destOffset += outputDelta;
  38664. }
  38665. },
  38666. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38667. return this.base.getOutputLength(inputLength * this.base.numComps,
  38668. alpha01);
  38669. },
  38670. isPassthrough: ColorSpace.prototype.isPassthrough,
  38671. fillRgb: ColorSpace.prototype.fillRgb,
  38672. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38673. // indexed color maps shouldn't be changed
  38674. return true;
  38675. },
  38676. usesZeroToOneRange: true
  38677. };
  38678. return IndexedCS;
  38679. })();
  38680. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38681. function DeviceGrayCS() {
  38682. this.name = 'DeviceGray';
  38683. this.numComps = 1;
  38684. this.defaultColor = new Float32Array([0]);
  38685. }
  38686. DeviceGrayCS.prototype = {
  38687. getRgb: ColorSpace.prototype.getRgb,
  38688. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38689. dest, destOffset) {
  38690. var c = (src[srcOffset] * 255) | 0;
  38691. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38692. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38693. },
  38694. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38695. dest, destOffset, bits,
  38696. alpha01) {
  38697. var scale = 255 / ((1 << bits) - 1);
  38698. var j = srcOffset, q = destOffset;
  38699. for (var i = 0; i < count; ++i) {
  38700. var c = (scale * src[j++]) | 0;
  38701. dest[q++] = c;
  38702. dest[q++] = c;
  38703. dest[q++] = c;
  38704. q += alpha01;
  38705. }
  38706. },
  38707. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38708. alpha01) {
  38709. return inputLength * (3 + alpha01);
  38710. },
  38711. isPassthrough: ColorSpace.prototype.isPassthrough,
  38712. fillRgb: ColorSpace.prototype.fillRgb,
  38713. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38714. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38715. },
  38716. usesZeroToOneRange: true
  38717. };
  38718. return DeviceGrayCS;
  38719. })();
  38720. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38721. function DeviceRgbCS() {
  38722. this.name = 'DeviceRGB';
  38723. this.numComps = 3;
  38724. this.defaultColor = new Float32Array([0, 0, 0]);
  38725. }
  38726. DeviceRgbCS.prototype = {
  38727. getRgb: ColorSpace.prototype.getRgb,
  38728. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38729. dest, destOffset) {
  38730. var r = (src[srcOffset] * 255) | 0;
  38731. var g = (src[srcOffset + 1] * 255) | 0;
  38732. var b = (src[srcOffset + 2] * 255) | 0;
  38733. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38734. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38735. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38736. },
  38737. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38738. dest, destOffset, bits,
  38739. alpha01) {
  38740. if (bits === 8 && alpha01 === 0) {
  38741. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38742. return;
  38743. }
  38744. var scale = 255 / ((1 << bits) - 1);
  38745. var j = srcOffset, q = destOffset;
  38746. for (var i = 0; i < count; ++i) {
  38747. dest[q++] = (scale * src[j++]) | 0;
  38748. dest[q++] = (scale * src[j++]) | 0;
  38749. dest[q++] = (scale * src[j++]) | 0;
  38750. q += alpha01;
  38751. }
  38752. },
  38753. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38754. alpha01) {
  38755. return (inputLength * (3 + alpha01) / 3) | 0;
  38756. },
  38757. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38758. return bits === 8;
  38759. },
  38760. fillRgb: ColorSpace.prototype.fillRgb,
  38761. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38762. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38763. },
  38764. usesZeroToOneRange: true
  38765. };
  38766. return DeviceRgbCS;
  38767. })();
  38768. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38769. // The coefficients below was found using numerical analysis: the method of
  38770. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38771. // where color_value is the tabular value from the table of sampled RGB colors
  38772. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38773. // CMYK color conversion using the estimation below:
  38774. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38775. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38776. var c = src[srcOffset + 0] * srcScale;
  38777. var m = src[srcOffset + 1] * srcScale;
  38778. var y = src[srcOffset + 2] * srcScale;
  38779. var k = src[srcOffset + 3] * srcScale;
  38780. var r =
  38781. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38782. 18.82290502165302 * y + 212.25662451639585 * k +
  38783. -285.2331026137004) +
  38784. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38785. -17.873870861415444 * k - 5.497006427196366) +
  38786. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38787. 17.5119270841813) +
  38788. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38789. var g =
  38790. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38791. 6.871425592049007 * y + 31.159100130055922 * k +
  38792. -79.2970844816548) +
  38793. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38794. 131.35250912493976 * k - 190.9453302588951) +
  38795. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38796. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38797. var b =
  38798. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38799. 30.89978309703729 * y - 0.23883238689178934 * k +
  38800. -14.183576799673286) +
  38801. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38802. 50.606957656360734 * k - 112.23884253719248) +
  38803. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38804. -193.58209356861505) +
  38805. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38806. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38807. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38808. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38809. }
  38810. function DeviceCmykCS() {
  38811. this.name = 'DeviceCMYK';
  38812. this.numComps = 4;
  38813. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38814. }
  38815. DeviceCmykCS.prototype = {
  38816. getRgb: ColorSpace.prototype.getRgb,
  38817. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38818. dest, destOffset) {
  38819. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38820. },
  38821. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38822. dest, destOffset, bits,
  38823. alpha01) {
  38824. var scale = 1 / ((1 << bits) - 1);
  38825. for (var i = 0; i < count; i++) {
  38826. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38827. srcOffset += 4;
  38828. destOffset += 3 + alpha01;
  38829. }
  38830. },
  38831. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38832. alpha01) {
  38833. return (inputLength / 4 * (3 + alpha01)) | 0;
  38834. },
  38835. isPassthrough: ColorSpace.prototype.isPassthrough,
  38836. fillRgb: ColorSpace.prototype.fillRgb,
  38837. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38838. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38839. },
  38840. usesZeroToOneRange: true
  38841. };
  38842. return DeviceCmykCS;
  38843. })();
  38844. //
  38845. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38846. //
  38847. var CalGrayCS = (function CalGrayCSClosure() {
  38848. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38849. this.name = 'CalGray';
  38850. this.numComps = 1;
  38851. this.defaultColor = new Float32Array([0]);
  38852. if (!whitePoint) {
  38853. error('WhitePoint missing - required for color space CalGray');
  38854. }
  38855. blackPoint = blackPoint || [0, 0, 0];
  38856. gamma = gamma || 1;
  38857. // Translate arguments to spec variables.
  38858. this.XW = whitePoint[0];
  38859. this.YW = whitePoint[1];
  38860. this.ZW = whitePoint[2];
  38861. this.XB = blackPoint[0];
  38862. this.YB = blackPoint[1];
  38863. this.ZB = blackPoint[2];
  38864. this.G = gamma;
  38865. // Validate variables as per spec.
  38866. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38867. error('Invalid WhitePoint components for ' + this.name +
  38868. ', no fallback available');
  38869. }
  38870. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38871. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38872. this.XB = this.YB = this.ZB = 0;
  38873. }
  38874. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38875. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38876. ', ZB: ' + this.ZB + ', only default values are supported.');
  38877. }
  38878. if (this.G < 1) {
  38879. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38880. ', falling back to default');
  38881. this.G = 1;
  38882. }
  38883. }
  38884. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38885. // A represents a gray component of a calibrated gray space.
  38886. // A <---> AG in the spec
  38887. var A = src[srcOffset] * scale;
  38888. var AG = Math.pow(A, cs.G);
  38889. // Computes L as per spec. ( = cs.YW * AG )
  38890. // Except if other than default BlackPoint values are used.
  38891. var L = cs.YW * AG;
  38892. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38893. // Convert values to rgb range [0, 255].
  38894. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38895. dest[destOffset] = val;
  38896. dest[destOffset + 1] = val;
  38897. dest[destOffset + 2] = val;
  38898. }
  38899. CalGrayCS.prototype = {
  38900. getRgb: ColorSpace.prototype.getRgb,
  38901. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38902. dest, destOffset) {
  38903. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38904. },
  38905. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38906. dest, destOffset, bits,
  38907. alpha01) {
  38908. var scale = 1 / ((1 << bits) - 1);
  38909. for (var i = 0; i < count; ++i) {
  38910. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38911. srcOffset += 1;
  38912. destOffset += 3 + alpha01;
  38913. }
  38914. },
  38915. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38916. return inputLength * (3 + alpha01);
  38917. },
  38918. isPassthrough: ColorSpace.prototype.isPassthrough,
  38919. fillRgb: ColorSpace.prototype.fillRgb,
  38920. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38921. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38922. },
  38923. usesZeroToOneRange: true
  38924. };
  38925. return CalGrayCS;
  38926. })();
  38927. //
  38928. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38929. //
  38930. var CalRGBCS = (function CalRGBCSClosure() {
  38931. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38932. // matrices.
  38933. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38934. 0.8951, 0.2664, -0.1614,
  38935. -0.7502, 1.7135, 0.0367,
  38936. 0.0389, -0.0685, 1.0296]);
  38937. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38938. 0.9869929, -0.1470543, 0.1599627,
  38939. 0.4323053, 0.5183603, 0.0492912,
  38940. -0.0085287, 0.0400428, 0.9684867]);
  38941. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38942. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38943. 3.2404542, -1.5371385, -0.4985314,
  38944. -0.9692660, 1.8760108, 0.0415560,
  38945. 0.0556434, -0.2040259, 1.0572252]);
  38946. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38947. var tempNormalizeMatrix = new Float32Array(3);
  38948. var tempConvertMatrix1 = new Float32Array(3);
  38949. var tempConvertMatrix2 = new Float32Array(3);
  38950. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38951. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38952. this.name = 'CalRGB';
  38953. this.numComps = 3;
  38954. this.defaultColor = new Float32Array(3);
  38955. if (!whitePoint) {
  38956. error('WhitePoint missing - required for color space CalRGB');
  38957. }
  38958. blackPoint = blackPoint || new Float32Array(3);
  38959. gamma = gamma || new Float32Array([1, 1, 1]);
  38960. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38961. // Translate arguments to spec variables.
  38962. var XW = whitePoint[0];
  38963. var YW = whitePoint[1];
  38964. var ZW = whitePoint[2];
  38965. this.whitePoint = whitePoint;
  38966. var XB = blackPoint[0];
  38967. var YB = blackPoint[1];
  38968. var ZB = blackPoint[2];
  38969. this.blackPoint = blackPoint;
  38970. this.GR = gamma[0];
  38971. this.GG = gamma[1];
  38972. this.GB = gamma[2];
  38973. this.MXA = matrix[0];
  38974. this.MYA = matrix[1];
  38975. this.MZA = matrix[2];
  38976. this.MXB = matrix[3];
  38977. this.MYB = matrix[4];
  38978. this.MZB = matrix[5];
  38979. this.MXC = matrix[6];
  38980. this.MYC = matrix[7];
  38981. this.MZC = matrix[8];
  38982. // Validate variables as per spec.
  38983. if (XW < 0 || ZW < 0 || YW !== 1) {
  38984. error('Invalid WhitePoint components for ' + this.name +
  38985. ', no fallback available');
  38986. }
  38987. if (XB < 0 || YB < 0 || ZB < 0) {
  38988. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38989. ', ' + ZB + '], falling back to default');
  38990. this.blackPoint = new Float32Array(3);
  38991. }
  38992. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38993. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38994. '] for ' + this.name + ', falling back to default');
  38995. this.GR = this.GG = this.GB = 1;
  38996. }
  38997. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38998. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38999. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  39000. info('Invalid Matrix for ' + this.name + ' [' +
  39001. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  39002. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  39003. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  39004. '], falling back to default');
  39005. this.MXA = this.MYB = this.MZC = 1;
  39006. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  39007. }
  39008. }
  39009. function matrixProduct(a, b, result) {
  39010. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  39011. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  39012. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  39013. }
  39014. function convertToFlat(sourceWhitePoint, LMS, result) {
  39015. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  39016. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  39017. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  39018. }
  39019. function convertToD65(sourceWhitePoint, LMS, result) {
  39020. var D65X = 0.95047;
  39021. var D65Y = 1;
  39022. var D65Z = 1.08883;
  39023. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  39024. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  39025. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  39026. }
  39027. function sRGBTransferFunction(color) {
  39028. // See http://en.wikipedia.org/wiki/SRGB.
  39029. if (color <= 0.0031308){
  39030. return adjustToRange(0, 1, 12.92 * color);
  39031. }
  39032. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  39033. }
  39034. function adjustToRange(min, max, value) {
  39035. return Math.max(min, Math.min(max, value));
  39036. }
  39037. function decodeL(L) {
  39038. if (L < 0) {
  39039. return -decodeL(-L);
  39040. }
  39041. if (L > 8.0) {
  39042. return Math.pow(((L + 16) / 116), 3);
  39043. }
  39044. return L * DECODE_L_CONSTANT;
  39045. }
  39046. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  39047. // In case the blackPoint is already the default blackPoint then there is
  39048. // no need to do compensation.
  39049. if (sourceBlackPoint[0] === 0 &&
  39050. sourceBlackPoint[1] === 0 &&
  39051. sourceBlackPoint[2] === 0) {
  39052. result[0] = XYZ_Flat[0];
  39053. result[1] = XYZ_Flat[1];
  39054. result[2] = XYZ_Flat[2];
  39055. return;
  39056. }
  39057. // For the blackPoint calculation details, please see
  39058. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39059. // AdobeBPC.pdf.
  39060. // The destination blackPoint is the default blackPoint [0, 0, 0].
  39061. var zeroDecodeL = decodeL(0);
  39062. var X_DST = zeroDecodeL;
  39063. var X_SRC = decodeL(sourceBlackPoint[0]);
  39064. var Y_DST = zeroDecodeL;
  39065. var Y_SRC = decodeL(sourceBlackPoint[1]);
  39066. var Z_DST = zeroDecodeL;
  39067. var Z_SRC = decodeL(sourceBlackPoint[2]);
  39068. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  39069. var X_Offset = 1 - X_Scale;
  39070. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  39071. var Y_Offset = 1 - Y_Scale;
  39072. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  39073. var Z_Offset = 1 - Z_Scale;
  39074. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  39075. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  39076. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  39077. }
  39078. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  39079. // In case the whitePoint is already flat then there is no need to do
  39080. // normalization.
  39081. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  39082. result[0] = XYZ_In[0];
  39083. result[1] = XYZ_In[1];
  39084. result[2] = XYZ_In[2];
  39085. return;
  39086. }
  39087. var LMS = result;
  39088. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39089. var LMS_Flat = tempNormalizeMatrix;
  39090. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  39091. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  39092. }
  39093. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  39094. var LMS = result;
  39095. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  39096. var LMS_D65 = tempNormalizeMatrix;
  39097. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  39098. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  39099. }
  39100. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39101. // A, B and C represent a red, green and blue components of a calibrated
  39102. // rgb space.
  39103. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  39104. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  39105. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  39106. // A <---> AGR in the spec
  39107. // B <---> BGG in the spec
  39108. // C <---> CGB in the spec
  39109. var AGR = Math.pow(A, cs.GR);
  39110. var BGG = Math.pow(B, cs.GG);
  39111. var CGB = Math.pow(C, cs.GB);
  39112. // Computes intermediate variables L, M, N as per spec.
  39113. // To decode X, Y, Z values map L, M, N directly to them.
  39114. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  39115. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  39116. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  39117. // The following calculations are based on this document:
  39118. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  39119. // AdobeBPC.pdf.
  39120. var XYZ = tempConvertMatrix1;
  39121. XYZ[0] = X;
  39122. XYZ[1] = Y;
  39123. XYZ[2] = Z;
  39124. var XYZ_Flat = tempConvertMatrix2;
  39125. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  39126. var XYZ_Black = tempConvertMatrix1;
  39127. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  39128. var XYZ_D65 = tempConvertMatrix2;
  39129. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  39130. var SRGB = tempConvertMatrix1;
  39131. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  39132. var sR = sRGBTransferFunction(SRGB[0]);
  39133. var sG = sRGBTransferFunction(SRGB[1]);
  39134. var sB = sRGBTransferFunction(SRGB[2]);
  39135. // Convert the values to rgb range [0, 255].
  39136. dest[destOffset] = Math.round(sR * 255);
  39137. dest[destOffset + 1] = Math.round(sG * 255);
  39138. dest[destOffset + 2] = Math.round(sB * 255);
  39139. }
  39140. CalRGBCS.prototype = {
  39141. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39142. var rgb = new Uint8Array(3);
  39143. this.getRgbItem(src, srcOffset, rgb, 0);
  39144. return rgb;
  39145. },
  39146. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39147. dest, destOffset) {
  39148. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39149. },
  39150. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39151. dest, destOffset, bits,
  39152. alpha01) {
  39153. var scale = 1 / ((1 << bits) - 1);
  39154. for (var i = 0; i < count; ++i) {
  39155. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39156. srcOffset += 3;
  39157. destOffset += 3 + alpha01;
  39158. }
  39159. },
  39160. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39161. return (inputLength * (3 + alpha01) / 3) | 0;
  39162. },
  39163. isPassthrough: ColorSpace.prototype.isPassthrough,
  39164. fillRgb: ColorSpace.prototype.fillRgb,
  39165. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39166. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39167. },
  39168. usesZeroToOneRange: true
  39169. };
  39170. return CalRGBCS;
  39171. })();
  39172. //
  39173. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39174. //
  39175. var LabCS = (function LabCSClosure() {
  39176. function LabCS(whitePoint, blackPoint, range) {
  39177. this.name = 'Lab';
  39178. this.numComps = 3;
  39179. this.defaultColor = new Float32Array([0, 0, 0]);
  39180. if (!whitePoint) {
  39181. error('WhitePoint missing - required for color space Lab');
  39182. }
  39183. blackPoint = blackPoint || [0, 0, 0];
  39184. range = range || [-100, 100, -100, 100];
  39185. // Translate args to spec variables
  39186. this.XW = whitePoint[0];
  39187. this.YW = whitePoint[1];
  39188. this.ZW = whitePoint[2];
  39189. this.amin = range[0];
  39190. this.amax = range[1];
  39191. this.bmin = range[2];
  39192. this.bmax = range[3];
  39193. // These are here just for completeness - the spec doesn't offer any
  39194. // formulas that use BlackPoint in Lab
  39195. this.XB = blackPoint[0];
  39196. this.YB = blackPoint[1];
  39197. this.ZB = blackPoint[2];
  39198. // Validate vars as per spec
  39199. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39200. error('Invalid WhitePoint components, no fallback available');
  39201. }
  39202. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39203. info('Invalid BlackPoint, falling back to default');
  39204. this.XB = this.YB = this.ZB = 0;
  39205. }
  39206. if (this.amin > this.amax || this.bmin > this.bmax) {
  39207. info('Invalid Range, falling back to defaults');
  39208. this.amin = -100;
  39209. this.amax = 100;
  39210. this.bmin = -100;
  39211. this.bmax = 100;
  39212. }
  39213. }
  39214. // Function g(x) from spec
  39215. function fn_g(x) {
  39216. if (x >= 6 / 29) {
  39217. return x * x * x;
  39218. } else {
  39219. return (108 / 841) * (x - 4 / 29);
  39220. }
  39221. }
  39222. function decode(value, high1, low2, high2) {
  39223. return low2 + (value) * (high2 - low2) / (high1);
  39224. }
  39225. // If decoding is needed maxVal should be 2^bits per component - 1.
  39226. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39227. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39228. // not the usual [0, 1]. If a command like setFillColor is used the src
  39229. // values will already be within the correct range. However, if we are
  39230. // converting an image we have to map the values to the correct range given
  39231. // above.
  39232. // Ls,as,bs <---> L*,a*,b* in the spec
  39233. var Ls = src[srcOffset];
  39234. var as = src[srcOffset + 1];
  39235. var bs = src[srcOffset + 2];
  39236. if (maxVal !== false) {
  39237. Ls = decode(Ls, maxVal, 0, 100);
  39238. as = decode(as, maxVal, cs.amin, cs.amax);
  39239. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39240. }
  39241. // Adjust limits of 'as' and 'bs'
  39242. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39243. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39244. // Computes intermediate variables X,Y,Z as per spec
  39245. var M = (Ls + 16) / 116;
  39246. var L = M + (as / 500);
  39247. var N = M - (bs / 200);
  39248. var X = cs.XW * fn_g(L);
  39249. var Y = cs.YW * fn_g(M);
  39250. var Z = cs.ZW * fn_g(N);
  39251. var r, g, b;
  39252. // Using different conversions for D50 and D65 white points,
  39253. // per http://www.color.org/srgb.pdf
  39254. if (cs.ZW < 1) {
  39255. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39256. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39257. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39258. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39259. } else {
  39260. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39261. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39262. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39263. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39264. }
  39265. // clamp color values to [0,1] range then convert to [0,255] range.
  39266. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39267. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39268. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39269. }
  39270. LabCS.prototype = {
  39271. getRgb: ColorSpace.prototype.getRgb,
  39272. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39273. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39274. },
  39275. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39276. dest, destOffset, bits,
  39277. alpha01) {
  39278. var maxVal = (1 << bits) - 1;
  39279. for (var i = 0; i < count; i++) {
  39280. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39281. srcOffset += 3;
  39282. destOffset += 3 + alpha01;
  39283. }
  39284. },
  39285. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39286. return (inputLength * (3 + alpha01) / 3) | 0;
  39287. },
  39288. isPassthrough: ColorSpace.prototype.isPassthrough,
  39289. fillRgb: ColorSpace.prototype.fillRgb,
  39290. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39291. // XXX: Decoding is handled with the lab conversion because of the strange
  39292. // ranges that are used.
  39293. return true;
  39294. },
  39295. usesZeroToOneRange: false
  39296. };
  39297. return LabCS;
  39298. })();
  39299. // TODO refactor to remove dependency on image.js
  39300. function _setCoreImage(coreImage_) {
  39301. coreImage = coreImage_;
  39302. PDFImage = coreImage_.PDFImage;
  39303. }
  39304. exports._setCoreImage = _setCoreImage;
  39305. exports.ColorSpace = ColorSpace;
  39306. // TODO refactor to remove dependency on colorspace.js
  39307. coreStream._setCoreColorSpace(exports);
  39308. }));
  39309. (function (root, factory) {
  39310. {
  39311. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39312. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39313. root.pdfjsCoreJpx);
  39314. }
  39315. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39316. coreStream, coreJpx) {
  39317. var ImageKind = sharedUtil.ImageKind;
  39318. var assert = sharedUtil.assert;
  39319. var error = sharedUtil.error;
  39320. var info = sharedUtil.info;
  39321. var isArray = sharedUtil.isArray;
  39322. var warn = sharedUtil.warn;
  39323. var Name = corePrimitives.Name;
  39324. var isStream = corePrimitives.isStream;
  39325. var ColorSpace = coreColorSpace.ColorSpace;
  39326. var DecodeStream = coreStream.DecodeStream;
  39327. var Stream = coreStream.Stream;
  39328. var JpegStream = coreStream.JpegStream;
  39329. var JpxImage = coreJpx.JpxImage;
  39330. var PDFImage = (function PDFImageClosure() {
  39331. /**
  39332. * Decode the image in the main thread if it supported. Resovles the promise
  39333. * when the image data is ready.
  39334. */
  39335. function handleImageData(handler, xref, res, image) {
  39336. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  39337. // For natively supported jpegs send them to the main thread for decoding.
  39338. var dict = image.dict;
  39339. var colorSpace = dict.get('ColorSpace', 'CS');
  39340. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39341. var numComps = colorSpace.numComps;
  39342. var decodePromise = handler.sendWithPromise('JpegDecode',
  39343. [image.getIR(), numComps]);
  39344. return decodePromise.then(function (message) {
  39345. var data = message.data;
  39346. return new Stream(data, 0, data.length, image.dict);
  39347. });
  39348. } else {
  39349. return Promise.resolve(image);
  39350. }
  39351. }
  39352. /**
  39353. * Decode and clamp a value. The formula is different from the spec because we
  39354. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39355. */
  39356. function decodeAndClamp(value, addend, coefficient, max) {
  39357. value = addend + value * coefficient;
  39358. // Clamp the value to the range
  39359. return (value < 0 ? 0 : (value > max ? max : value));
  39360. }
  39361. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39362. this.image = image;
  39363. var dict = image.dict;
  39364. if (dict.has('Filter')) {
  39365. var filter = dict.get('Filter').name;
  39366. if (filter === 'JPXDecode') {
  39367. var jpxImage = new JpxImage();
  39368. jpxImage.parseImageProperties(image.stream);
  39369. image.stream.reset();
  39370. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39371. image.numComps = jpxImage.componentsCount;
  39372. } else if (filter === 'JBIG2Decode') {
  39373. image.bitsPerComponent = 1;
  39374. image.numComps = 1;
  39375. }
  39376. }
  39377. // TODO cache rendered images?
  39378. this.width = dict.get('Width', 'W');
  39379. this.height = dict.get('Height', 'H');
  39380. if (this.width < 1 || this.height < 1) {
  39381. error('Invalid image width: ' + this.width + ' or height: ' +
  39382. this.height);
  39383. }
  39384. this.interpolate = dict.get('Interpolate', 'I') || false;
  39385. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39386. this.matte = dict.get('Matte') || false;
  39387. var bitsPerComponent = image.bitsPerComponent;
  39388. if (!bitsPerComponent) {
  39389. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39390. if (!bitsPerComponent) {
  39391. if (this.imageMask) {
  39392. bitsPerComponent = 1;
  39393. } else {
  39394. error('Bits per component missing in image: ' + this.imageMask);
  39395. }
  39396. }
  39397. }
  39398. this.bpc = bitsPerComponent;
  39399. if (!this.imageMask) {
  39400. var colorSpace = dict.get('ColorSpace', 'CS');
  39401. if (!colorSpace) {
  39402. info('JPX images (which do not require color spaces)');
  39403. switch (image.numComps) {
  39404. case 1:
  39405. colorSpace = Name.get('DeviceGray');
  39406. break;
  39407. case 3:
  39408. colorSpace = Name.get('DeviceRGB');
  39409. break;
  39410. case 4:
  39411. colorSpace = Name.get('DeviceCMYK');
  39412. break;
  39413. default:
  39414. error('JPX images with ' + this.numComps +
  39415. ' color components not supported.');
  39416. }
  39417. }
  39418. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39419. this.numComps = this.colorSpace.numComps;
  39420. }
  39421. this.decode = dict.get('Decode', 'D');
  39422. this.needsDecode = false;
  39423. if (this.decode &&
  39424. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39425. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39426. this.needsDecode = true;
  39427. // Do some preprocessing to avoid more math.
  39428. var max = (1 << bitsPerComponent) - 1;
  39429. this.decodeCoefficients = [];
  39430. this.decodeAddends = [];
  39431. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39432. var dmin = this.decode[i];
  39433. var dmax = this.decode[i + 1];
  39434. this.decodeCoefficients[j] = dmax - dmin;
  39435. this.decodeAddends[j] = max * dmin;
  39436. }
  39437. }
  39438. if (smask) {
  39439. this.smask = new PDFImage(xref, res, smask, false);
  39440. } else if (mask) {
  39441. if (isStream(mask)) {
  39442. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39443. if (!imageMask) {
  39444. warn('Ignoring /Mask in image without /ImageMask.');
  39445. } else {
  39446. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39447. }
  39448. } else {
  39449. // Color key mask (just an array).
  39450. this.mask = mask;
  39451. }
  39452. }
  39453. }
  39454. /**
  39455. * Handles processing of image data and returns the Promise that is resolved
  39456. * with a PDFImage when the image is ready to be used.
  39457. */
  39458. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39459. res, image, inline) {
  39460. var imagePromise = handleImageData(handler, xref, res, image);
  39461. var smaskPromise;
  39462. var maskPromise;
  39463. var smask = image.dict.get('SMask');
  39464. var mask = image.dict.get('Mask');
  39465. if (smask) {
  39466. smaskPromise = handleImageData(handler, xref, res, smask);
  39467. maskPromise = Promise.resolve(null);
  39468. } else {
  39469. smaskPromise = Promise.resolve(null);
  39470. if (mask) {
  39471. if (isStream(mask)) {
  39472. maskPromise = handleImageData(handler, xref, res, mask);
  39473. } else if (isArray(mask)) {
  39474. maskPromise = Promise.resolve(mask);
  39475. } else {
  39476. warn('Unsupported mask format.');
  39477. maskPromise = Promise.resolve(null);
  39478. }
  39479. } else {
  39480. maskPromise = Promise.resolve(null);
  39481. }
  39482. }
  39483. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39484. function(results) {
  39485. var imageData = results[0];
  39486. var smaskData = results[1];
  39487. var maskData = results[2];
  39488. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39489. });
  39490. };
  39491. /**
  39492. * Resize an image using the nearest neighbor algorithm. Currently only
  39493. * supports one and three component images.
  39494. * @param {TypedArray} pixels The original image with one component.
  39495. * @param {Number} bpc Number of bits per component.
  39496. * @param {Number} components Number of color components, 1 or 3 is supported.
  39497. * @param {Number} w1 Original width.
  39498. * @param {Number} h1 Original height.
  39499. * @param {Number} w2 New width.
  39500. * @param {Number} h2 New height.
  39501. * @param {TypedArray} dest (Optional) The destination buffer.
  39502. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39503. * @return {TypedArray} Resized image data.
  39504. */
  39505. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39506. w1, h1, w2, h2, dest, alpha01) {
  39507. if (components !== 1 && components !== 3) {
  39508. error('Unsupported component count for resizing.');
  39509. }
  39510. var length = w2 * h2 * components;
  39511. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39512. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39513. var xRatio = w1 / w2;
  39514. var yRatio = h1 / h2;
  39515. var i, j, py, newIndex = 0, oldIndex;
  39516. var xScaled = new Uint16Array(w2);
  39517. var w1Scanline = w1 * components;
  39518. if (alpha01 !== 1) {
  39519. alpha01 = 0;
  39520. }
  39521. for (j = 0; j < w2; j++) {
  39522. xScaled[j] = Math.floor(j * xRatio) * components;
  39523. }
  39524. if (components === 1) {
  39525. for (i = 0; i < h2; i++) {
  39526. py = Math.floor(i * yRatio) * w1Scanline;
  39527. for (j = 0; j < w2; j++) {
  39528. oldIndex = py + xScaled[j];
  39529. temp[newIndex++] = pixels[oldIndex];
  39530. }
  39531. }
  39532. } else if (components === 3) {
  39533. for (i = 0; i < h2; i++) {
  39534. py = Math.floor(i * yRatio) * w1Scanline;
  39535. for (j = 0; j < w2; j++) {
  39536. oldIndex = py + xScaled[j];
  39537. temp[newIndex++] = pixels[oldIndex++];
  39538. temp[newIndex++] = pixels[oldIndex++];
  39539. temp[newIndex++] = pixels[oldIndex++];
  39540. newIndex += alpha01;
  39541. }
  39542. }
  39543. }
  39544. return temp;
  39545. };
  39546. PDFImage.createMask =
  39547. function PDFImage_createMask(imgArray, width, height,
  39548. imageIsFromDecodeStream, inverseDecode) {
  39549. // |imgArray| might not contain full data for every pixel of the mask, so
  39550. // we need to distinguish between |computedLength| and |actualLength|.
  39551. // In particular, if inverseDecode is true, then the array we return must
  39552. // have a length of |computedLength|.
  39553. var computedLength = ((width + 7) >> 3) * height;
  39554. var actualLength = imgArray.byteLength;
  39555. var haveFullData = computedLength === actualLength;
  39556. var data, i;
  39557. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39558. // imgArray came from a DecodeStream and its data is in an appropriate
  39559. // form, so we can just transfer it.
  39560. data = imgArray;
  39561. } else if (!inverseDecode) {
  39562. data = new Uint8Array(actualLength);
  39563. data.set(imgArray);
  39564. } else {
  39565. data = new Uint8Array(computedLength);
  39566. data.set(imgArray);
  39567. for (i = actualLength; i < computedLength; i++) {
  39568. data[i] = 0xff;
  39569. }
  39570. }
  39571. // If necessary, invert the original mask data (but not any extra we might
  39572. // have added above). It's safe to modify the array -- whether it's the
  39573. // original or a copy, we're about to transfer it anyway, so nothing else
  39574. // in this thread can be relying on its contents.
  39575. if (inverseDecode) {
  39576. for (i = 0; i < actualLength; i++) {
  39577. data[i] = ~data[i];
  39578. }
  39579. }
  39580. return {data: data, width: width, height: height};
  39581. };
  39582. PDFImage.prototype = {
  39583. get drawWidth() {
  39584. return Math.max(this.width,
  39585. this.smask && this.smask.width || 0,
  39586. this.mask && this.mask.width || 0);
  39587. },
  39588. get drawHeight() {
  39589. return Math.max(this.height,
  39590. this.smask && this.smask.height || 0,
  39591. this.mask && this.mask.height || 0);
  39592. },
  39593. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39594. var bpc = this.bpc;
  39595. var numComps = this.numComps;
  39596. var decodeAddends = this.decodeAddends;
  39597. var decodeCoefficients = this.decodeCoefficients;
  39598. var max = (1 << bpc) - 1;
  39599. var i, ii;
  39600. if (bpc === 1) {
  39601. // If the buffer needed decode that means it just needs to be inverted.
  39602. for (i = 0, ii = buffer.length; i < ii; i++) {
  39603. buffer[i] = +!(buffer[i]);
  39604. }
  39605. return;
  39606. }
  39607. var index = 0;
  39608. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39609. for (var j = 0; j < numComps; j++) {
  39610. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39611. decodeCoefficients[j], max);
  39612. index++;
  39613. }
  39614. }
  39615. },
  39616. getComponents: function PDFImage_getComponents(buffer) {
  39617. var bpc = this.bpc;
  39618. // This image doesn't require any extra work.
  39619. if (bpc === 8) {
  39620. return buffer;
  39621. }
  39622. var width = this.width;
  39623. var height = this.height;
  39624. var numComps = this.numComps;
  39625. var length = width * height * numComps;
  39626. var bufferPos = 0;
  39627. var output = (bpc <= 8 ? new Uint8Array(length) :
  39628. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39629. var rowComps = width * numComps;
  39630. var max = (1 << bpc) - 1;
  39631. var i = 0, ii, buf;
  39632. if (bpc === 1) {
  39633. // Optimization for reading 1 bpc images.
  39634. var mask, loop1End, loop2End;
  39635. for (var j = 0; j < height; j++) {
  39636. loop1End = i + (rowComps & ~7);
  39637. loop2End = i + rowComps;
  39638. // unroll loop for all full bytes
  39639. while (i < loop1End) {
  39640. buf = buffer[bufferPos++];
  39641. output[i] = (buf >> 7) & 1;
  39642. output[i + 1] = (buf >> 6) & 1;
  39643. output[i + 2] = (buf >> 5) & 1;
  39644. output[i + 3] = (buf >> 4) & 1;
  39645. output[i + 4] = (buf >> 3) & 1;
  39646. output[i + 5] = (buf >> 2) & 1;
  39647. output[i + 6] = (buf >> 1) & 1;
  39648. output[i + 7] = buf & 1;
  39649. i += 8;
  39650. }
  39651. // handle remaing bits
  39652. if (i < loop2End) {
  39653. buf = buffer[bufferPos++];
  39654. mask = 128;
  39655. while (i < loop2End) {
  39656. output[i++] = +!!(buf & mask);
  39657. mask >>= 1;
  39658. }
  39659. }
  39660. }
  39661. } else {
  39662. // The general case that handles all other bpc values.
  39663. var bits = 0;
  39664. buf = 0;
  39665. for (i = 0, ii = length; i < ii; ++i) {
  39666. if (i % rowComps === 0) {
  39667. buf = 0;
  39668. bits = 0;
  39669. }
  39670. while (bits < bpc) {
  39671. buf = (buf << 8) | buffer[bufferPos++];
  39672. bits += 8;
  39673. }
  39674. var remainingBits = bits - bpc;
  39675. var value = buf >> remainingBits;
  39676. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39677. buf = buf & ((1 << remainingBits) - 1);
  39678. bits = remainingBits;
  39679. }
  39680. }
  39681. return output;
  39682. },
  39683. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39684. actualHeight, image) {
  39685. var smask = this.smask;
  39686. var mask = this.mask;
  39687. var alphaBuf, sw, sh, i, ii, j;
  39688. if (smask) {
  39689. sw = smask.width;
  39690. sh = smask.height;
  39691. alphaBuf = new Uint8Array(sw * sh);
  39692. smask.fillGrayBuffer(alphaBuf);
  39693. if (sw !== width || sh !== height) {
  39694. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39695. height);
  39696. }
  39697. } else if (mask) {
  39698. if (mask instanceof PDFImage) {
  39699. sw = mask.width;
  39700. sh = mask.height;
  39701. alphaBuf = new Uint8Array(sw * sh);
  39702. mask.numComps = 1;
  39703. mask.fillGrayBuffer(alphaBuf);
  39704. // Need to invert values in rgbaBuf
  39705. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39706. alphaBuf[i] = 255 - alphaBuf[i];
  39707. }
  39708. if (sw !== width || sh !== height) {
  39709. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39710. height);
  39711. }
  39712. } else if (isArray(mask)) {
  39713. // Color key mask: if any of the compontents are outside the range
  39714. // then they should be painted.
  39715. alphaBuf = new Uint8Array(width * height);
  39716. var numComps = this.numComps;
  39717. for (i = 0, ii = width * height; i < ii; ++i) {
  39718. var opacity = 0;
  39719. var imageOffset = i * numComps;
  39720. for (j = 0; j < numComps; ++j) {
  39721. var color = image[imageOffset + j];
  39722. var maskOffset = j * 2;
  39723. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39724. opacity = 255;
  39725. break;
  39726. }
  39727. }
  39728. alphaBuf[i] = opacity;
  39729. }
  39730. } else {
  39731. error('Unknown mask format.');
  39732. }
  39733. }
  39734. if (alphaBuf) {
  39735. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39736. rgbaBuf[j] = alphaBuf[i];
  39737. }
  39738. } else {
  39739. // No mask.
  39740. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39741. rgbaBuf[j] = 255;
  39742. }
  39743. }
  39744. },
  39745. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39746. var matte = this.smask && this.smask.matte;
  39747. if (!matte) {
  39748. return;
  39749. }
  39750. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39751. var matteR = matteRgb[0];
  39752. var matteG = matteRgb[1];
  39753. var matteB = matteRgb[2];
  39754. var length = width * height * 4;
  39755. var r, g, b;
  39756. for (var i = 0; i < length; i += 4) {
  39757. var alpha = buffer[i + 3];
  39758. if (alpha === 0) {
  39759. // according formula we have to get Infinity in all components
  39760. // making it white (typical paper color) should be okay
  39761. buffer[i] = 255;
  39762. buffer[i + 1] = 255;
  39763. buffer[i + 2] = 255;
  39764. continue;
  39765. }
  39766. var k = 255 / alpha;
  39767. r = (buffer[i] - matteR) * k + matteR;
  39768. g = (buffer[i + 1] - matteG) * k + matteG;
  39769. b = (buffer[i + 2] - matteB) * k + matteB;
  39770. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39771. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39772. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39773. }
  39774. },
  39775. createImageData: function PDFImage_createImageData(forceRGBA) {
  39776. var drawWidth = this.drawWidth;
  39777. var drawHeight = this.drawHeight;
  39778. var imgData = { // other fields are filled in below
  39779. width: drawWidth,
  39780. height: drawHeight
  39781. };
  39782. var numComps = this.numComps;
  39783. var originalWidth = this.width;
  39784. var originalHeight = this.height;
  39785. var bpc = this.bpc;
  39786. // Rows start at byte boundary.
  39787. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39788. var imgArray;
  39789. if (!forceRGBA) {
  39790. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39791. // without any complications, we pass a same-sized copy to the main
  39792. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39793. // of memory for many scanned documents. It's also much faster.
  39794. //
  39795. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39796. // complications, we avoid expanding by 1.333x to RGBA form.
  39797. var kind;
  39798. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39799. kind = ImageKind.GRAYSCALE_1BPP;
  39800. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39801. !this.needsDecode) {
  39802. kind = ImageKind.RGB_24BPP;
  39803. }
  39804. if (kind && !this.smask && !this.mask &&
  39805. drawWidth === originalWidth && drawHeight === originalHeight) {
  39806. imgData.kind = kind;
  39807. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39808. // If imgArray came from a DecodeStream, we're safe to transfer it
  39809. // (and thus neuter it) because it will constitute the entire
  39810. // DecodeStream's data. But if it came from a Stream, we need to
  39811. // copy it because it'll only be a portion of the Stream's data, and
  39812. // the rest will be read later on.
  39813. if (this.image instanceof DecodeStream) {
  39814. imgData.data = imgArray;
  39815. } else {
  39816. var newArray = new Uint8Array(imgArray.length);
  39817. newArray.set(imgArray);
  39818. imgData.data = newArray;
  39819. }
  39820. if (this.needsDecode) {
  39821. // Invert the buffer (which must be grayscale if we reached here).
  39822. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39823. var buffer = imgData.data;
  39824. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39825. buffer[i] ^= 0xff;
  39826. }
  39827. }
  39828. return imgData;
  39829. }
  39830. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39831. (this.colorSpace.name === 'DeviceGray' ||
  39832. this.colorSpace.name === 'DeviceRGB' ||
  39833. this.colorSpace.name === 'DeviceCMYK')) {
  39834. imgData.kind = ImageKind.RGB_24BPP;
  39835. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39836. drawWidth, drawHeight, true);
  39837. return imgData;
  39838. }
  39839. }
  39840. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39841. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39842. var actualHeight = 0 | (imgArray.length / rowBytes *
  39843. drawHeight / originalHeight);
  39844. var comps = this.getComponents(imgArray);
  39845. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39846. // more compact RGB_24BPP form if allowable.
  39847. var alpha01, maybeUndoPreblend;
  39848. if (!forceRGBA && !this.smask && !this.mask) {
  39849. imgData.kind = ImageKind.RGB_24BPP;
  39850. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39851. alpha01 = 0;
  39852. maybeUndoPreblend = false;
  39853. } else {
  39854. imgData.kind = ImageKind.RGBA_32BPP;
  39855. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39856. alpha01 = 1;
  39857. maybeUndoPreblend = true;
  39858. // Color key masking (opacity) must be performed before decoding.
  39859. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39860. comps);
  39861. }
  39862. if (this.needsDecode) {
  39863. this.decodeBuffer(comps);
  39864. }
  39865. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39866. drawWidth, drawHeight, actualHeight, bpc, comps,
  39867. alpha01);
  39868. if (maybeUndoPreblend) {
  39869. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39870. }
  39871. return imgData;
  39872. },
  39873. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39874. var numComps = this.numComps;
  39875. if (numComps !== 1) {
  39876. error('Reading gray scale from a color image: ' + numComps);
  39877. }
  39878. var width = this.width;
  39879. var height = this.height;
  39880. var bpc = this.bpc;
  39881. // rows start at byte boundary
  39882. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39883. var imgArray = this.getImageBytes(height * rowBytes);
  39884. var comps = this.getComponents(imgArray);
  39885. var i, length;
  39886. if (bpc === 1) {
  39887. // inline decoding (= inversion) for 1 bpc images
  39888. length = width * height;
  39889. if (this.needsDecode) {
  39890. // invert and scale to {0, 255}
  39891. for (i = 0; i < length; ++i) {
  39892. buffer[i] = (comps[i] - 1) & 255;
  39893. }
  39894. } else {
  39895. // scale to {0, 255}
  39896. for (i = 0; i < length; ++i) {
  39897. buffer[i] = (-comps[i]) & 255;
  39898. }
  39899. }
  39900. return;
  39901. }
  39902. if (this.needsDecode) {
  39903. this.decodeBuffer(comps);
  39904. }
  39905. length = width * height;
  39906. // we aren't using a colorspace so we need to scale the value
  39907. var scale = 255 / ((1 << bpc) - 1);
  39908. for (i = 0; i < length; ++i) {
  39909. buffer[i] = (scale * comps[i]) | 0;
  39910. }
  39911. },
  39912. getImageBytes: function PDFImage_getImageBytes(length,
  39913. drawWidth, drawHeight,
  39914. forceRGB) {
  39915. this.image.reset();
  39916. this.image.drawWidth = drawWidth || this.width;
  39917. this.image.drawHeight = drawHeight || this.height;
  39918. this.image.forceRGB = !!forceRGB;
  39919. return this.image.getBytes(length);
  39920. }
  39921. };
  39922. return PDFImage;
  39923. })();
  39924. exports.PDFImage = PDFImage;
  39925. // TODO refactor to remove dependency on colorspace.js
  39926. coreColorSpace._setCoreImage(exports);
  39927. }));
  39928. (function (root, factory) {
  39929. {
  39930. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  39931. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  39932. root.pdfjsCoreColorSpace);
  39933. }
  39934. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  39935. coreColorSpace) {
  39936. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39937. var MissingDataException = sharedUtil.MissingDataException;
  39938. var Util = sharedUtil.Util;
  39939. var assert = sharedUtil.assert;
  39940. var error = sharedUtil.error;
  39941. var info = sharedUtil.info;
  39942. var warn = sharedUtil.warn;
  39943. var isStream = corePrimitives.isStream;
  39944. var PDFFunction = coreFunction.PDFFunction;
  39945. var ColorSpace = coreColorSpace.ColorSpace;
  39946. var ShadingType = {
  39947. FUNCTION_BASED: 1,
  39948. AXIAL: 2,
  39949. RADIAL: 3,
  39950. FREE_FORM_MESH: 4,
  39951. LATTICE_FORM_MESH: 5,
  39952. COONS_PATCH_MESH: 6,
  39953. TENSOR_PATCH_MESH: 7
  39954. };
  39955. var Pattern = (function PatternClosure() {
  39956. // Constructor should define this.getPattern
  39957. function Pattern() {
  39958. error('should not call Pattern constructor');
  39959. }
  39960. Pattern.prototype = {
  39961. // Input: current Canvas context
  39962. // Output: the appropriate fillStyle or strokeStyle
  39963. getPattern: function Pattern_getPattern(ctx) {
  39964. error('Should not call Pattern.getStyle: ' + ctx);
  39965. }
  39966. };
  39967. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  39968. res, handler) {
  39969. var dict = isStream(shading) ? shading.dict : shading;
  39970. var type = dict.get('ShadingType');
  39971. try {
  39972. switch (type) {
  39973. case ShadingType.AXIAL:
  39974. case ShadingType.RADIAL:
  39975. // Both radial and axial shadings are handled by RadialAxial shading.
  39976. return new Shadings.RadialAxial(dict, matrix, xref, res);
  39977. case ShadingType.FREE_FORM_MESH:
  39978. case ShadingType.LATTICE_FORM_MESH:
  39979. case ShadingType.COONS_PATCH_MESH:
  39980. case ShadingType.TENSOR_PATCH_MESH:
  39981. return new Shadings.Mesh(shading, matrix, xref, res);
  39982. default:
  39983. throw new Error('Unsupported ShadingType: ' + type);
  39984. }
  39985. } catch (ex) {
  39986. if (ex instanceof MissingDataException) {
  39987. throw ex;
  39988. }
  39989. handler.send('UnsupportedFeature',
  39990. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  39991. warn(ex);
  39992. return new Shadings.Dummy();
  39993. }
  39994. };
  39995. return Pattern;
  39996. })();
  39997. var Shadings = {};
  39998. // A small number to offset the first/last color stops so we can insert ones to
  39999. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  40000. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  40001. // internally so we have to go bigger.
  40002. Shadings.SMALL_NUMBER = 1e-2;
  40003. // Radial and axial shading have very similar implementations
  40004. // If needed, the implementations can be broken into two classes
  40005. Shadings.RadialAxial = (function RadialAxialClosure() {
  40006. function RadialAxial(dict, matrix, xref, res) {
  40007. this.matrix = matrix;
  40008. this.coordsArr = dict.get('Coords');
  40009. this.shadingType = dict.get('ShadingType');
  40010. this.type = 'Pattern';
  40011. var cs = dict.get('ColorSpace', 'CS');
  40012. cs = ColorSpace.parse(cs, xref, res);
  40013. this.cs = cs;
  40014. var t0 = 0.0, t1 = 1.0;
  40015. if (dict.has('Domain')) {
  40016. var domainArr = dict.get('Domain');
  40017. t0 = domainArr[0];
  40018. t1 = domainArr[1];
  40019. }
  40020. var extendStart = false, extendEnd = false;
  40021. if (dict.has('Extend')) {
  40022. var extendArr = dict.get('Extend');
  40023. extendStart = extendArr[0];
  40024. extendEnd = extendArr[1];
  40025. }
  40026. if (this.shadingType === ShadingType.RADIAL &&
  40027. (!extendStart || !extendEnd)) {
  40028. // Radial gradient only currently works if either circle is fully within
  40029. // the other circle.
  40030. var x1 = this.coordsArr[0];
  40031. var y1 = this.coordsArr[1];
  40032. var r1 = this.coordsArr[2];
  40033. var x2 = this.coordsArr[3];
  40034. var y2 = this.coordsArr[4];
  40035. var r2 = this.coordsArr[5];
  40036. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  40037. if (r1 <= r2 + distance &&
  40038. r2 <= r1 + distance) {
  40039. warn('Unsupported radial gradient.');
  40040. }
  40041. }
  40042. this.extendStart = extendStart;
  40043. this.extendEnd = extendEnd;
  40044. var fnObj = dict.get('Function');
  40045. var fn = PDFFunction.parseArray(xref, fnObj);
  40046. // 10 samples seems good enough for now, but probably won't work
  40047. // if there are sharp color changes. Ideally, we would implement
  40048. // the spec faithfully and add lossless optimizations.
  40049. var diff = t1 - t0;
  40050. var step = diff / 10;
  40051. var colorStops = this.colorStops = [];
  40052. // Protect against bad domains so we don't end up in an infinte loop below.
  40053. if (t0 >= t1 || step <= 0) {
  40054. // Acrobat doesn't seem to handle these cases so we'll ignore for
  40055. // now.
  40056. info('Bad shading domain.');
  40057. return;
  40058. }
  40059. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  40060. var rgbColor;
  40061. for (var i = t0; i <= t1; i += step) {
  40062. ratio[0] = i;
  40063. fn(ratio, 0, color, 0);
  40064. rgbColor = cs.getRgb(color, 0);
  40065. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  40066. colorStops.push([(i - t0) / diff, cssColor]);
  40067. }
  40068. var background = 'transparent';
  40069. if (dict.has('Background')) {
  40070. rgbColor = cs.getRgb(dict.get('Background'), 0);
  40071. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  40072. }
  40073. if (!extendStart) {
  40074. // Insert a color stop at the front and offset the first real color stop
  40075. // so it doesn't conflict with the one we insert.
  40076. colorStops.unshift([0, background]);
  40077. colorStops[1][0] += Shadings.SMALL_NUMBER;
  40078. }
  40079. if (!extendEnd) {
  40080. // Same idea as above in extendStart but for the end.
  40081. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  40082. colorStops.push([1, background]);
  40083. }
  40084. this.colorStops = colorStops;
  40085. }
  40086. RadialAxial.prototype = {
  40087. getIR: function RadialAxial_getIR() {
  40088. var coordsArr = this.coordsArr;
  40089. var shadingType = this.shadingType;
  40090. var type, p0, p1, r0, r1;
  40091. if (shadingType === ShadingType.AXIAL) {
  40092. p0 = [coordsArr[0], coordsArr[1]];
  40093. p1 = [coordsArr[2], coordsArr[3]];
  40094. r0 = null;
  40095. r1 = null;
  40096. type = 'axial';
  40097. } else if (shadingType === ShadingType.RADIAL) {
  40098. p0 = [coordsArr[0], coordsArr[1]];
  40099. p1 = [coordsArr[3], coordsArr[4]];
  40100. r0 = coordsArr[2];
  40101. r1 = coordsArr[5];
  40102. type = 'radial';
  40103. } else {
  40104. error('getPattern type unknown: ' + shadingType);
  40105. }
  40106. var matrix = this.matrix;
  40107. if (matrix) {
  40108. p0 = Util.applyTransform(p0, matrix);
  40109. p1 = Util.applyTransform(p1, matrix);
  40110. if (shadingType === ShadingType.RADIAL) {
  40111. var scale = Util.singularValueDecompose2dScale(matrix);
  40112. r0 *= scale[0];
  40113. r1 *= scale[1];
  40114. }
  40115. }
  40116. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  40117. }
  40118. };
  40119. return RadialAxial;
  40120. })();
  40121. // All mesh shading. For now, they will be presented as set of the triangles
  40122. // to be drawn on the canvas and rgb color for each vertex.
  40123. Shadings.Mesh = (function MeshClosure() {
  40124. function MeshStreamReader(stream, context) {
  40125. this.stream = stream;
  40126. this.context = context;
  40127. this.buffer = 0;
  40128. this.bufferLength = 0;
  40129. var numComps = context.numComps;
  40130. this.tmpCompsBuf = new Float32Array(numComps);
  40131. var csNumComps = context.colorSpace.numComps;
  40132. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  40133. this.tmpCompsBuf;
  40134. }
  40135. MeshStreamReader.prototype = {
  40136. get hasData() {
  40137. if (this.stream.end) {
  40138. return this.stream.pos < this.stream.end;
  40139. }
  40140. if (this.bufferLength > 0) {
  40141. return true;
  40142. }
  40143. var nextByte = this.stream.getByte();
  40144. if (nextByte < 0) {
  40145. return false;
  40146. }
  40147. this.buffer = nextByte;
  40148. this.bufferLength = 8;
  40149. return true;
  40150. },
  40151. readBits: function MeshStreamReader_readBits(n) {
  40152. var buffer = this.buffer;
  40153. var bufferLength = this.bufferLength;
  40154. if (n === 32) {
  40155. if (bufferLength === 0) {
  40156. return ((this.stream.getByte() << 24) |
  40157. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  40158. this.stream.getByte()) >>> 0;
  40159. }
  40160. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  40161. (this.stream.getByte() << 8) | this.stream.getByte();
  40162. var nextByte = this.stream.getByte();
  40163. this.buffer = nextByte & ((1 << bufferLength) - 1);
  40164. return ((buffer << (8 - bufferLength)) |
  40165. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  40166. }
  40167. if (n === 8 && bufferLength === 0) {
  40168. return this.stream.getByte();
  40169. }
  40170. while (bufferLength < n) {
  40171. buffer = (buffer << 8) | this.stream.getByte();
  40172. bufferLength += 8;
  40173. }
  40174. bufferLength -= n;
  40175. this.bufferLength = bufferLength;
  40176. this.buffer = buffer & ((1 << bufferLength) - 1);
  40177. return buffer >> bufferLength;
  40178. },
  40179. align: function MeshStreamReader_align() {
  40180. this.buffer = 0;
  40181. this.bufferLength = 0;
  40182. },
  40183. readFlag: function MeshStreamReader_readFlag() {
  40184. return this.readBits(this.context.bitsPerFlag);
  40185. },
  40186. readCoordinate: function MeshStreamReader_readCoordinate() {
  40187. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  40188. var xi = this.readBits(bitsPerCoordinate);
  40189. var yi = this.readBits(bitsPerCoordinate);
  40190. var decode = this.context.decode;
  40191. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  40192. 2.3283064365386963e-10; // 2 ^ -32
  40193. return [
  40194. xi * scale * (decode[1] - decode[0]) + decode[0],
  40195. yi * scale * (decode[3] - decode[2]) + decode[2]
  40196. ];
  40197. },
  40198. readComponents: function MeshStreamReader_readComponents() {
  40199. var numComps = this.context.numComps;
  40200. var bitsPerComponent = this.context.bitsPerComponent;
  40201. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  40202. 2.3283064365386963e-10; // 2 ^ -32
  40203. var decode = this.context.decode;
  40204. var components = this.tmpCompsBuf;
  40205. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  40206. var ci = this.readBits(bitsPerComponent);
  40207. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  40208. }
  40209. var color = this.tmpCsCompsBuf;
  40210. if (this.context.colorFn) {
  40211. this.context.colorFn(components, 0, color, 0);
  40212. }
  40213. return this.context.colorSpace.getRgb(color, 0);
  40214. }
  40215. };
  40216. function decodeType4Shading(mesh, reader) {
  40217. var coords = mesh.coords;
  40218. var colors = mesh.colors;
  40219. var operators = [];
  40220. var ps = []; // not maintaining cs since that will match ps
  40221. var verticesLeft = 0; // assuming we have all data to start a new triangle
  40222. while (reader.hasData) {
  40223. var f = reader.readFlag();
  40224. var coord = reader.readCoordinate();
  40225. var color = reader.readComponents();
  40226. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  40227. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  40228. switch (f) {
  40229. case 0:
  40230. verticesLeft = 3;
  40231. break;
  40232. case 1:
  40233. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  40234. verticesLeft = 1;
  40235. break;
  40236. case 2:
  40237. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  40238. verticesLeft = 1;
  40239. break;
  40240. }
  40241. operators.push(f);
  40242. }
  40243. ps.push(coords.length);
  40244. coords.push(coord);
  40245. colors.push(color);
  40246. verticesLeft--;
  40247. reader.align();
  40248. }
  40249. mesh.figures.push({
  40250. type: 'triangles',
  40251. coords: new Int32Array(ps),
  40252. colors: new Int32Array(ps),
  40253. });
  40254. }
  40255. function decodeType5Shading(mesh, reader, verticesPerRow) {
  40256. var coords = mesh.coords;
  40257. var colors = mesh.colors;
  40258. var ps = []; // not maintaining cs since that will match ps
  40259. while (reader.hasData) {
  40260. var coord = reader.readCoordinate();
  40261. var color = reader.readComponents();
  40262. ps.push(coords.length);
  40263. coords.push(coord);
  40264. colors.push(color);
  40265. }
  40266. mesh.figures.push({
  40267. type: 'lattice',
  40268. coords: new Int32Array(ps),
  40269. colors: new Int32Array(ps),
  40270. verticesPerRow: verticesPerRow
  40271. });
  40272. }
  40273. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  40274. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  40275. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  40276. var getB = (function getBClosure() {
  40277. function buildB(count) {
  40278. var lut = [];
  40279. for (var i = 0; i <= count; i++) {
  40280. var t = i / count, t_ = 1 - t;
  40281. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  40282. 3 * t * t * t_, t * t * t]));
  40283. }
  40284. return lut;
  40285. }
  40286. var cache = [];
  40287. return function getB(count) {
  40288. if (!cache[count]) {
  40289. cache[count] = buildB(count);
  40290. }
  40291. return cache[count];
  40292. };
  40293. })();
  40294. function buildFigureFromPatch(mesh, index) {
  40295. var figure = mesh.figures[index];
  40296. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  40297. var coords = mesh.coords, colors = mesh.colors;
  40298. var pi = figure.coords;
  40299. var ci = figure.colors;
  40300. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  40301. coords[pi[12]][0], coords[pi[15]][0]);
  40302. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  40303. coords[pi[12]][1], coords[pi[15]][1]);
  40304. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  40305. coords[pi[12]][0], coords[pi[15]][0]);
  40306. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  40307. coords[pi[12]][1], coords[pi[15]][1]);
  40308. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  40309. (mesh.bounds[2] - mesh.bounds[0]));
  40310. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  40311. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  40312. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  40313. (mesh.bounds[3] - mesh.bounds[1]));
  40314. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  40315. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  40316. var verticesPerRow = splitXBy + 1;
  40317. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  40318. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  40319. var k = 0;
  40320. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  40321. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  40322. c2 = colors[ci[2]], c3 = colors[ci[3]];
  40323. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  40324. for (var row = 0; row <= splitYBy; row++) {
  40325. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  40326. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  40327. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  40328. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  40329. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  40330. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  40331. for (var col = 0; col <= splitXBy; col++, k++) {
  40332. if ((row === 0 || row === splitYBy) &&
  40333. (col === 0 || col === splitXBy)) {
  40334. continue;
  40335. }
  40336. var x = 0, y = 0;
  40337. var q = 0;
  40338. for (var i = 0; i <= 3; i++) {
  40339. for (var j = 0; j <= 3; j++, q++) {
  40340. var m = bRow[row][i] * bCol[col][j];
  40341. x += coords[pi[q]][0] * m;
  40342. y += coords[pi[q]][1] * m;
  40343. }
  40344. }
  40345. figureCoords[k] = coords.length;
  40346. coords.push([x, y]);
  40347. figureColors[k] = colors.length;
  40348. var newColor = new Uint8Array(3);
  40349. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  40350. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  40351. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  40352. colors.push(newColor);
  40353. }
  40354. }
  40355. figureCoords[0] = pi[0];
  40356. figureColors[0] = ci[0];
  40357. figureCoords[splitXBy] = pi[3];
  40358. figureColors[splitXBy] = ci[1];
  40359. figureCoords[verticesPerRow * splitYBy] = pi[12];
  40360. figureColors[verticesPerRow * splitYBy] = ci[2];
  40361. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  40362. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  40363. mesh.figures[index] = {
  40364. type: 'lattice',
  40365. coords: figureCoords,
  40366. colors: figureColors,
  40367. verticesPerRow: verticesPerRow
  40368. };
  40369. }
  40370. function decodeType6Shading(mesh, reader) {
  40371. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  40372. var coords = mesh.coords;
  40373. var colors = mesh.colors;
  40374. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40375. var cs = new Int32Array(4); // c00, c30, c03, c33
  40376. while (reader.hasData) {
  40377. var f = reader.readFlag();
  40378. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  40379. var i, ii;
  40380. var pi = coords.length;
  40381. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  40382. coords.push(reader.readCoordinate());
  40383. }
  40384. var ci = colors.length;
  40385. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40386. colors.push(reader.readComponents());
  40387. }
  40388. var tmp1, tmp2, tmp3, tmp4;
  40389. switch (f) {
  40390. case 0:
  40391. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40392. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  40393. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  40394. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40395. cs[2] = ci + 1; cs[3] = ci + 2;
  40396. cs[0] = ci; cs[1] = ci + 3;
  40397. break;
  40398. case 1:
  40399. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40400. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40401. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40402. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40403. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40404. tmp1 = cs[2]; tmp2 = cs[3];
  40405. cs[2] = tmp2; cs[3] = ci;
  40406. cs[0] = tmp1; cs[1] = ci + 1;
  40407. break;
  40408. case 2:
  40409. tmp1 = ps[15];
  40410. tmp2 = ps[11];
  40411. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40412. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40413. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40414. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40415. tmp1 = cs[3];
  40416. cs[2] = cs[1]; cs[3] = ci;
  40417. cs[0] = tmp1; cs[1] = ci + 1;
  40418. break;
  40419. case 3:
  40420. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40421. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40422. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  40423. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40424. cs[2] = cs[0]; cs[3] = ci;
  40425. cs[0] = cs[1]; cs[1] = ci + 1;
  40426. break;
  40427. }
  40428. // set p11, p12, p21, p22
  40429. ps[5] = coords.length;
  40430. coords.push([
  40431. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  40432. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  40433. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40434. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  40435. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  40436. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  40437. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40438. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  40439. ]);
  40440. ps[6] = coords.length;
  40441. coords.push([
  40442. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  40443. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  40444. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40445. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  40446. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  40447. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  40448. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40449. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  40450. ]);
  40451. ps[9] = coords.length;
  40452. coords.push([
  40453. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  40454. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  40455. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40456. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  40457. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  40458. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  40459. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40460. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  40461. ]);
  40462. ps[10] = coords.length;
  40463. coords.push([
  40464. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  40465. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  40466. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40467. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  40468. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  40469. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  40470. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40471. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  40472. ]);
  40473. mesh.figures.push({
  40474. type: 'patch',
  40475. coords: new Int32Array(ps), // making copies of ps and cs
  40476. colors: new Int32Array(cs)
  40477. });
  40478. }
  40479. }
  40480. function decodeType7Shading(mesh, reader) {
  40481. var coords = mesh.coords;
  40482. var colors = mesh.colors;
  40483. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40484. var cs = new Int32Array(4); // c00, c30, c03, c33
  40485. while (reader.hasData) {
  40486. var f = reader.readFlag();
  40487. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  40488. var i, ii;
  40489. var pi = coords.length;
  40490. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  40491. coords.push(reader.readCoordinate());
  40492. }
  40493. var ci = colors.length;
  40494. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40495. colors.push(reader.readComponents());
  40496. }
  40497. var tmp1, tmp2, tmp3, tmp4;
  40498. switch (f) {
  40499. case 0:
  40500. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40501. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  40502. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  40503. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40504. cs[2] = ci + 1; cs[3] = ci + 2;
  40505. cs[0] = ci; cs[1] = ci + 3;
  40506. break;
  40507. case 1:
  40508. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40509. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40510. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40511. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40512. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40513. tmp1 = cs[2]; tmp2 = cs[3];
  40514. cs[2] = tmp2; cs[3] = ci;
  40515. cs[0] = tmp1; cs[1] = ci + 1;
  40516. break;
  40517. case 2:
  40518. tmp1 = ps[15];
  40519. tmp2 = ps[11];
  40520. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40521. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40522. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40523. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40524. tmp1 = cs[3];
  40525. cs[2] = cs[1]; cs[3] = ci;
  40526. cs[0] = tmp1; cs[1] = ci + 1;
  40527. break;
  40528. case 3:
  40529. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40530. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40531. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40532. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40533. cs[2] = cs[0]; cs[3] = ci;
  40534. cs[0] = cs[1]; cs[1] = ci + 1;
  40535. break;
  40536. }
  40537. mesh.figures.push({
  40538. type: 'patch',
  40539. coords: new Int32Array(ps), // making copies of ps and cs
  40540. colors: new Int32Array(cs)
  40541. });
  40542. }
  40543. }
  40544. function updateBounds(mesh) {
  40545. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  40546. maxX = minX, maxY = minY;
  40547. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  40548. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  40549. minX = minX > x ? x : minX;
  40550. minY = minY > y ? y : minY;
  40551. maxX = maxX < x ? x : maxX;
  40552. maxY = maxY < y ? y : maxY;
  40553. }
  40554. mesh.bounds = [minX, minY, maxX, maxY];
  40555. }
  40556. function packData(mesh) {
  40557. var i, ii, j, jj;
  40558. var coords = mesh.coords;
  40559. var coordsPacked = new Float32Array(coords.length * 2);
  40560. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  40561. var xy = coords[i];
  40562. coordsPacked[j++] = xy[0];
  40563. coordsPacked[j++] = xy[1];
  40564. }
  40565. mesh.coords = coordsPacked;
  40566. var colors = mesh.colors;
  40567. var colorsPacked = new Uint8Array(colors.length * 3);
  40568. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  40569. var c = colors[i];
  40570. colorsPacked[j++] = c[0];
  40571. colorsPacked[j++] = c[1];
  40572. colorsPacked[j++] = c[2];
  40573. }
  40574. mesh.colors = colorsPacked;
  40575. var figures = mesh.figures;
  40576. for (i = 0, ii = figures.length; i < ii; i++) {
  40577. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  40578. for (j = 0, jj = ps.length; j < jj; j++) {
  40579. ps[j] *= 2;
  40580. cs[j] *= 3;
  40581. }
  40582. }
  40583. }
  40584. function Mesh(stream, matrix, xref, res) {
  40585. assert(isStream(stream), 'Mesh data is not a stream');
  40586. var dict = stream.dict;
  40587. this.matrix = matrix;
  40588. this.shadingType = dict.get('ShadingType');
  40589. this.type = 'Pattern';
  40590. this.bbox = dict.get('BBox');
  40591. var cs = dict.get('ColorSpace', 'CS');
  40592. cs = ColorSpace.parse(cs, xref, res);
  40593. this.cs = cs;
  40594. this.background = dict.has('Background') ?
  40595. cs.getRgb(dict.get('Background'), 0) : null;
  40596. var fnObj = dict.get('Function');
  40597. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  40598. this.coords = [];
  40599. this.colors = [];
  40600. this.figures = [];
  40601. var decodeContext = {
  40602. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  40603. bitsPerComponent: dict.get('BitsPerComponent'),
  40604. bitsPerFlag: dict.get('BitsPerFlag'),
  40605. decode: dict.get('Decode'),
  40606. colorFn: fn,
  40607. colorSpace: cs,
  40608. numComps: fn ? 1 : cs.numComps
  40609. };
  40610. var reader = new MeshStreamReader(stream, decodeContext);
  40611. var patchMesh = false;
  40612. switch (this.shadingType) {
  40613. case ShadingType.FREE_FORM_MESH:
  40614. decodeType4Shading(this, reader);
  40615. break;
  40616. case ShadingType.LATTICE_FORM_MESH:
  40617. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  40618. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  40619. decodeType5Shading(this, reader, verticesPerRow);
  40620. break;
  40621. case ShadingType.COONS_PATCH_MESH:
  40622. decodeType6Shading(this, reader);
  40623. patchMesh = true;
  40624. break;
  40625. case ShadingType.TENSOR_PATCH_MESH:
  40626. decodeType7Shading(this, reader);
  40627. patchMesh = true;
  40628. break;
  40629. default:
  40630. error('Unsupported mesh type.');
  40631. break;
  40632. }
  40633. if (patchMesh) {
  40634. // dirty bounds calculation for determining, how dense shall be triangles
  40635. updateBounds(this);
  40636. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  40637. buildFigureFromPatch(this, i);
  40638. }
  40639. }
  40640. // calculate bounds
  40641. updateBounds(this);
  40642. packData(this);
  40643. }
  40644. Mesh.prototype = {
  40645. getIR: function Mesh_getIR() {
  40646. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  40647. this.bounds, this.matrix, this.bbox, this.background];
  40648. }
  40649. };
  40650. return Mesh;
  40651. })();
  40652. Shadings.Dummy = (function DummyClosure() {
  40653. function Dummy() {
  40654. this.type = 'Pattern';
  40655. }
  40656. Dummy.prototype = {
  40657. getIR: function Dummy_getIR() {
  40658. return ['Dummy'];
  40659. }
  40660. };
  40661. return Dummy;
  40662. })();
  40663. function getTilingPatternIR(operatorList, dict, args) {
  40664. var matrix = dict.get('Matrix');
  40665. var bbox = dict.get('BBox');
  40666. var xstep = dict.get('XStep');
  40667. var ystep = dict.get('YStep');
  40668. var paintType = dict.get('PaintType');
  40669. var tilingType = dict.get('TilingType');
  40670. return [
  40671. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  40672. paintType, tilingType
  40673. ];
  40674. }
  40675. exports.Pattern = Pattern;
  40676. exports.getTilingPatternIR = getTilingPatternIR;
  40677. }));
  40678. (function (root, factory) {
  40679. {
  40680. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  40681. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  40682. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  40683. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  40684. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  40685. }
  40686. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  40687. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  40688. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  40689. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  40690. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  40691. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  40692. var ImageKind = sharedUtil.ImageKind;
  40693. var OPS = sharedUtil.OPS;
  40694. var TextRenderingMode = sharedUtil.TextRenderingMode;
  40695. var Util = sharedUtil.Util;
  40696. var assert = sharedUtil.assert;
  40697. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40698. var error = sharedUtil.error;
  40699. var info = sharedUtil.info;
  40700. var isArray = sharedUtil.isArray;
  40701. var isNum = sharedUtil.isNum;
  40702. var isString = sharedUtil.isString;
  40703. var warn = sharedUtil.warn;
  40704. var Dict = corePrimitives.Dict;
  40705. var Name = corePrimitives.Name;
  40706. var isCmd = corePrimitives.isCmd;
  40707. var isDict = corePrimitives.isDict;
  40708. var isName = corePrimitives.isName;
  40709. var isRef = corePrimitives.isRef;
  40710. var isStream = corePrimitives.isStream;
  40711. var DecodeStream = coreStream.DecodeStream;
  40712. var JpegStream = coreStream.JpegStream;
  40713. var Lexer = coreParser.Lexer;
  40714. var Parser = coreParser.Parser;
  40715. var isEOF = coreParser.isEOF;
  40716. var PDFImage = coreImage.PDFImage;
  40717. var ColorSpace = coreColorSpace.ColorSpace;
  40718. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  40719. var Encodings = coreFonts.Encodings;
  40720. var ErrorFont = coreFonts.ErrorFont;
  40721. var FontFlags = coreFonts.FontFlags;
  40722. var Font = coreFonts.Font;
  40723. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  40724. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  40725. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  40726. var getFontType = coreFonts.getFontType;
  40727. var reverseIfRtl = coreFonts.reverseIfRtl;
  40728. var serifFonts = coreFonts.serifFonts;
  40729. var symbolsFonts = coreFonts.symbolsFonts;
  40730. var stdFontMap = coreFonts.stdFontMap;
  40731. var isPDFFunction = coreFunction.isPDFFunction;
  40732. var PDFFunction = coreFunction.PDFFunction;
  40733. var Pattern = corePattern.Pattern;
  40734. var getTilingPatternIR = corePattern.getTilingPatternIR;
  40735. var CMapFactory = coreCMap.CMapFactory;
  40736. var IdentityCMap = coreCMap.IdentityCMap;
  40737. var Metrics = coreMetrics.Metrics;
  40738. var bidi = coreBidi.bidi;
  40739. var PartialEvaluator = (function PartialEvaluatorClosure() {
  40740. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  40741. uniquePrefix, idCounters, fontCache) {
  40742. this.pdfManager = pdfManager;
  40743. this.xref = xref;
  40744. this.handler = handler;
  40745. this.pageIndex = pageIndex;
  40746. this.uniquePrefix = uniquePrefix;
  40747. this.idCounters = idCounters;
  40748. this.fontCache = fontCache;
  40749. }
  40750. // Trying to minimize Date.now() usage and check every 100 time
  40751. var TIME_SLOT_DURATION_MS = 20;
  40752. var CHECK_TIME_EVERY = 100;
  40753. function TimeSlotManager() {
  40754. this.reset();
  40755. }
  40756. TimeSlotManager.prototype = {
  40757. check: function TimeSlotManager_check() {
  40758. if (++this.checked < CHECK_TIME_EVERY) {
  40759. return false;
  40760. }
  40761. this.checked = 0;
  40762. return this.endTime <= Date.now();
  40763. },
  40764. reset: function TimeSlotManager_reset() {
  40765. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  40766. this.checked = 0;
  40767. }
  40768. };
  40769. var deferred = Promise.resolve();
  40770. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  40771. PartialEvaluator.prototype = {
  40772. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  40773. if (!isDict(resources)) {
  40774. return false;
  40775. }
  40776. var processed = Object.create(null);
  40777. if (resources.objId) {
  40778. processed[resources.objId] = true;
  40779. }
  40780. var nodes = [resources];
  40781. while (nodes.length) {
  40782. var key;
  40783. var node = nodes.shift();
  40784. // First check the current resources for blend modes.
  40785. var graphicStates = node.get('ExtGState');
  40786. if (isDict(graphicStates)) {
  40787. graphicStates = graphicStates.getAll();
  40788. for (key in graphicStates) {
  40789. var graphicState = graphicStates[key];
  40790. var bm = graphicState['BM'];
  40791. if (isName(bm) && bm.name !== 'Normal') {
  40792. return true;
  40793. }
  40794. }
  40795. }
  40796. // Descend into the XObjects to look for more resources and blend modes.
  40797. var xObjects = node.get('XObject');
  40798. if (!isDict(xObjects)) {
  40799. continue;
  40800. }
  40801. xObjects = xObjects.getAll();
  40802. for (key in xObjects) {
  40803. var xObject = xObjects[key];
  40804. if (!isStream(xObject)) {
  40805. continue;
  40806. }
  40807. if (xObject.dict.objId) {
  40808. if (processed[xObject.dict.objId]) {
  40809. // stream has objId and is processed already
  40810. continue;
  40811. }
  40812. processed[xObject.dict.objId] = true;
  40813. }
  40814. var xResources = xObject.dict.get('Resources');
  40815. // Checking objId to detect an infinite loop.
  40816. if (isDict(xResources) &&
  40817. (!xResources.objId || !processed[xResources.objId])) {
  40818. nodes.push(xResources);
  40819. if (xResources.objId) {
  40820. processed[xResources.objId] = true;
  40821. }
  40822. }
  40823. }
  40824. }
  40825. return false;
  40826. },
  40827. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  40828. xobj, smask,
  40829. operatorList,
  40830. task,
  40831. initialState) {
  40832. var matrix = xobj.dict.getArray('Matrix');
  40833. var bbox = xobj.dict.getArray('BBox');
  40834. var group = xobj.dict.get('Group');
  40835. if (group) {
  40836. var groupOptions = {
  40837. matrix: matrix,
  40838. bbox: bbox,
  40839. smask: smask,
  40840. isolated: false,
  40841. knockout: false
  40842. };
  40843. var groupSubtype = group.get('S');
  40844. var colorSpace;
  40845. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  40846. groupOptions.isolated = (group.get('I') || false);
  40847. groupOptions.knockout = (group.get('K') || false);
  40848. colorSpace = (group.has('CS') ?
  40849. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  40850. }
  40851. if (smask && smask.backdrop) {
  40852. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  40853. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  40854. }
  40855. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  40856. }
  40857. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  40858. return this.getOperatorList(xobj, task,
  40859. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  40860. then(function () {
  40861. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  40862. if (group) {
  40863. operatorList.addOp(OPS.endGroup, [groupOptions]);
  40864. }
  40865. });
  40866. },
  40867. buildPaintImageXObject:
  40868. function PartialEvaluator_buildPaintImageXObject(resources, image,
  40869. inline, operatorList,
  40870. cacheKey, imageCache) {
  40871. var self = this;
  40872. var dict = image.dict;
  40873. var w = dict.get('Width', 'W');
  40874. var h = dict.get('Height', 'H');
  40875. if (!(w && isNum(w)) || !(h && isNum(h))) {
  40876. warn('Image dimensions are missing, or not numbers.');
  40877. return;
  40878. }
  40879. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  40880. warn('Image exceeded maximum allowed size and was removed.');
  40881. return;
  40882. }
  40883. var imageMask = (dict.get('ImageMask', 'IM') || false);
  40884. var imgData, args;
  40885. if (imageMask) {
  40886. // This depends on a tmpCanvas being filled with the
  40887. // current fillStyle, such that processing the pixel
  40888. // data can't be done here. Instead of creating a
  40889. // complete PDFImage, only read the information needed
  40890. // for later.
  40891. var width = dict.get('Width', 'W');
  40892. var height = dict.get('Height', 'H');
  40893. var bitStrideLength = (width + 7) >> 3;
  40894. var imgArray = image.getBytes(bitStrideLength * height);
  40895. var decode = dict.get('Decode', 'D');
  40896. var inverseDecode = (!!decode && decode[0] > 0);
  40897. imgData = PDFImage.createMask(imgArray, width, height,
  40898. image instanceof DecodeStream,
  40899. inverseDecode);
  40900. imgData.cached = true;
  40901. args = [imgData];
  40902. operatorList.addOp(OPS.paintImageMaskXObject, args);
  40903. if (cacheKey) {
  40904. imageCache[cacheKey] = {
  40905. fn: OPS.paintImageMaskXObject,
  40906. args: args
  40907. };
  40908. }
  40909. return;
  40910. }
  40911. var softMask = (dict.get('SMask', 'SM') || false);
  40912. var mask = (dict.get('Mask') || false);
  40913. var SMALL_IMAGE_DIMENSIONS = 200;
  40914. // Inlining small images into the queue as RGB data
  40915. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  40916. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  40917. var imageObj = new PDFImage(this.xref, resources, image,
  40918. inline, null, null);
  40919. // We force the use of RGBA_32BPP images here, because we can't handle
  40920. // any other kind.
  40921. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  40922. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  40923. return;
  40924. }
  40925. // If there is no imageMask, create the PDFImage and a lot
  40926. // of image processing can be done here.
  40927. var uniquePrefix = (this.uniquePrefix || '');
  40928. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  40929. operatorList.addDependency(objId);
  40930. args = [objId, w, h];
  40931. if (!softMask && !mask && image instanceof JpegStream &&
  40932. image.isNativelySupported(this.xref, resources)) {
  40933. // These JPEGs don't need any more processing so we can just send it.
  40934. operatorList.addOp(OPS.paintJpegXObject, args);
  40935. this.handler.send('obj',
  40936. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  40937. return;
  40938. }
  40939. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  40940. then(function(imageObj) {
  40941. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  40942. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  40943. [imgData.data.buffer]);
  40944. }).then(undefined, function (reason) {
  40945. warn('Unable to decode image: ' + reason);
  40946. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  40947. });
  40948. operatorList.addOp(OPS.paintImageXObject, args);
  40949. if (cacheKey) {
  40950. imageCache[cacheKey] = {
  40951. fn: OPS.paintImageXObject,
  40952. args: args
  40953. };
  40954. }
  40955. },
  40956. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  40957. operatorList, task,
  40958. stateManager) {
  40959. var smaskContent = smask.get('G');
  40960. var smaskOptions = {
  40961. subtype: smask.get('S').name,
  40962. backdrop: smask.get('BC')
  40963. };
  40964. // The SMask might have a alpha/luminosity value transfer function --
  40965. // we will build a map of integer values in range 0..255 to be fast.
  40966. var transferObj = smask.get('TR');
  40967. if (isPDFFunction(transferObj)) {
  40968. var transferFn = PDFFunction.parse(this.xref, transferObj);
  40969. var transferMap = new Uint8Array(256);
  40970. var tmp = new Float32Array(1);
  40971. for (var i = 0; i < 255; i++) {
  40972. tmp[0] = i / 255;
  40973. transferFn(tmp, 0, tmp, 0);
  40974. transferMap[i] = (tmp[0] * 255) | 0;
  40975. }
  40976. smaskOptions.transferMap = transferMap;
  40977. }
  40978. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  40979. operatorList, task, stateManager.state.clone());
  40980. },
  40981. handleTilingType:
  40982. function PartialEvaluator_handleTilingType(fn, args, resources,
  40983. pattern, patternDict,
  40984. operatorList, task) {
  40985. // Create an IR of the pattern code.
  40986. var tilingOpList = new OperatorList();
  40987. // Merge the available resources, to prevent issues when the patternDict
  40988. // is missing some /Resources entries (fixes issue6541.pdf).
  40989. var resourcesArray = [patternDict.get('Resources'), resources];
  40990. var patternResources = Dict.merge(this.xref, resourcesArray);
  40991. return this.getOperatorList(pattern, task, patternResources,
  40992. tilingOpList).then(function () {
  40993. // Add the dependencies to the parent operator list so they are
  40994. // resolved before sub operator list is executed synchronously.
  40995. operatorList.addDependencies(tilingOpList.dependencies);
  40996. operatorList.addOp(fn, getTilingPatternIR({
  40997. fnArray: tilingOpList.fnArray,
  40998. argsArray: tilingOpList.argsArray
  40999. }, patternDict, args));
  41000. });
  41001. },
  41002. handleSetFont:
  41003. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  41004. operatorList, task, state) {
  41005. // TODO(mack): Not needed?
  41006. var fontName;
  41007. if (fontArgs) {
  41008. fontArgs = fontArgs.slice();
  41009. fontName = fontArgs[0].name;
  41010. }
  41011. var self = this;
  41012. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  41013. function (translated) {
  41014. if (!translated.font.isType3Font) {
  41015. return translated;
  41016. }
  41017. return translated.loadType3Data(self, resources, operatorList, task).
  41018. then(function () {
  41019. return translated;
  41020. }, function (reason) {
  41021. // Error in the font data -- sending unsupported feature notification.
  41022. self.handler.send('UnsupportedFeature',
  41023. {featureId: UNSUPPORTED_FEATURES.font});
  41024. return new TranslatedFont('g_font_error',
  41025. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  41026. });
  41027. }).then(function (translated) {
  41028. state.font = translated.font;
  41029. translated.send(self.handler);
  41030. return translated.loadedName;
  41031. });
  41032. },
  41033. handleText: function PartialEvaluator_handleText(chars, state) {
  41034. var font = state.font;
  41035. var glyphs = font.charsToGlyphs(chars);
  41036. var isAddToPathSet = !!(state.textRenderingMode &
  41037. TextRenderingMode.ADD_TO_PATH_FLAG);
  41038. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  41039. var buildPath = function (fontChar) {
  41040. if (!font.renderer.hasBuiltPath(fontChar)) {
  41041. var path = font.renderer.getPathJs(fontChar);
  41042. this.handler.send('commonobj', [
  41043. font.loadedName + '_path_' + fontChar,
  41044. 'FontPath',
  41045. path
  41046. ]);
  41047. }
  41048. }.bind(this);
  41049. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  41050. var glyph = glyphs[i];
  41051. buildPath(glyph.fontChar);
  41052. // If the glyph has an accent we need to build a path for its
  41053. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  41054. var accent = glyph.accent;
  41055. if (accent && accent.fontChar) {
  41056. buildPath(accent.fontChar);
  41057. }
  41058. }
  41059. }
  41060. return glyphs;
  41061. },
  41062. setGState: function PartialEvaluator_setGState(resources, gState,
  41063. operatorList, task,
  41064. xref, stateManager) {
  41065. // This array holds the converted/processed state data.
  41066. var gStateObj = [];
  41067. var gStateMap = gState.map;
  41068. var self = this;
  41069. var promise = Promise.resolve();
  41070. for (var key in gStateMap) {
  41071. var value = gStateMap[key];
  41072. switch (key) {
  41073. case 'Type':
  41074. break;
  41075. case 'LW':
  41076. case 'LC':
  41077. case 'LJ':
  41078. case 'ML':
  41079. case 'D':
  41080. case 'RI':
  41081. case 'FL':
  41082. case 'CA':
  41083. case 'ca':
  41084. gStateObj.push([key, value]);
  41085. break;
  41086. case 'Font':
  41087. promise = promise.then(function () {
  41088. return self.handleSetFont(resources, null, value[0], operatorList,
  41089. task, stateManager.state).
  41090. then(function (loadedName) {
  41091. operatorList.addDependency(loadedName);
  41092. gStateObj.push([key, [loadedName, value[1]]]);
  41093. });
  41094. });
  41095. break;
  41096. case 'BM':
  41097. gStateObj.push([key, value]);
  41098. break;
  41099. case 'SMask':
  41100. if (isName(value) && value.name === 'None') {
  41101. gStateObj.push([key, false]);
  41102. break;
  41103. }
  41104. var dict = xref.fetchIfRef(value);
  41105. if (isDict(dict)) {
  41106. promise = promise.then(function () {
  41107. return self.handleSMask(dict, resources, operatorList,
  41108. task, stateManager);
  41109. });
  41110. gStateObj.push([key, true]);
  41111. } else {
  41112. warn('Unsupported SMask type');
  41113. }
  41114. break;
  41115. // Only generate info log messages for the following since
  41116. // they are unlikely to have a big impact on the rendering.
  41117. case 'OP':
  41118. case 'op':
  41119. case 'OPM':
  41120. case 'BG':
  41121. case 'BG2':
  41122. case 'UCR':
  41123. case 'UCR2':
  41124. case 'TR':
  41125. case 'TR2':
  41126. case 'HT':
  41127. case 'SM':
  41128. case 'SA':
  41129. case 'AIS':
  41130. case 'TK':
  41131. // TODO implement these operators.
  41132. info('graphic state operator ' + key);
  41133. break;
  41134. default:
  41135. info('Unknown graphic state operator ' + key);
  41136. break;
  41137. }
  41138. }
  41139. return promise.then(function () {
  41140. if (gStateObj.length >= 0) {
  41141. operatorList.addOp(OPS.setGState, [gStateObj]);
  41142. }
  41143. });
  41144. },
  41145. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  41146. resources) {
  41147. function errorFont() {
  41148. return Promise.resolve(new TranslatedFont('g_font_error',
  41149. new ErrorFont('Font ' + fontName + ' is not available'), font));
  41150. }
  41151. var fontRef;
  41152. if (font) { // Loading by ref.
  41153. assert(isRef(font));
  41154. fontRef = font;
  41155. } else { // Loading by name.
  41156. var fontRes = resources.get('Font');
  41157. if (fontRes) {
  41158. fontRef = fontRes.getRaw(fontName);
  41159. } else {
  41160. warn('fontRes not available');
  41161. return errorFont();
  41162. }
  41163. }
  41164. if (!fontRef) {
  41165. warn('fontRef not available');
  41166. return errorFont();
  41167. }
  41168. if (this.fontCache.has(fontRef)) {
  41169. return this.fontCache.get(fontRef);
  41170. }
  41171. font = xref.fetchIfRef(fontRef);
  41172. if (!isDict(font)) {
  41173. return errorFont();
  41174. }
  41175. // We are holding font.translated references just for fontRef that are not
  41176. // dictionaries (Dict). See explanation below.
  41177. if (font.translated) {
  41178. return font.translated;
  41179. }
  41180. var fontCapability = createPromiseCapability();
  41181. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  41182. var descriptor = preEvaluatedFont.descriptor;
  41183. var fontID = fontRef.num + '_' + fontRef.gen;
  41184. if (isDict(descriptor)) {
  41185. if (!descriptor.fontAliases) {
  41186. descriptor.fontAliases = Object.create(null);
  41187. }
  41188. var fontAliases = descriptor.fontAliases;
  41189. var hash = preEvaluatedFont.hash;
  41190. if (fontAliases[hash]) {
  41191. var aliasFontRef = fontAliases[hash].aliasRef;
  41192. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  41193. this.fontCache.putAlias(fontRef, aliasFontRef);
  41194. return this.fontCache.get(fontRef);
  41195. }
  41196. }
  41197. if (!fontAliases[hash]) {
  41198. fontAliases[hash] = {
  41199. fontID: Font.getFontID()
  41200. };
  41201. }
  41202. fontAliases[hash].aliasRef = fontRef;
  41203. fontID = fontAliases[hash].fontID;
  41204. }
  41205. // Workaround for bad PDF generators that don't reference fonts
  41206. // properly, i.e. by not using an object identifier.
  41207. // Check if the fontRef is a Dict (as opposed to a standard object),
  41208. // in which case we don't cache the font and instead reference it by
  41209. // fontName in font.loadedName below.
  41210. var fontRefIsDict = isDict(fontRef);
  41211. if (!fontRefIsDict) {
  41212. this.fontCache.put(fontRef, fontCapability.promise);
  41213. }
  41214. // Keep track of each font we translated so the caller can
  41215. // load them asynchronously before calling display on a page.
  41216. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  41217. fontName.replace(/\W/g, '') : fontID);
  41218. font.translated = fontCapability.promise;
  41219. // TODO move promises into translate font
  41220. var translatedPromise;
  41221. try {
  41222. translatedPromise = Promise.resolve(
  41223. this.translateFont(preEvaluatedFont, xref));
  41224. } catch (e) {
  41225. translatedPromise = Promise.reject(e);
  41226. }
  41227. var self = this;
  41228. translatedPromise.then(function (translatedFont) {
  41229. if (translatedFont.fontType !== undefined) {
  41230. var xrefFontStats = xref.stats.fontTypes;
  41231. xrefFontStats[translatedFont.fontType] = true;
  41232. }
  41233. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41234. translatedFont, font));
  41235. }, function (reason) {
  41236. // TODO fontCapability.reject?
  41237. // Error in the font data -- sending unsupported feature notification.
  41238. self.handler.send('UnsupportedFeature',
  41239. {featureId: UNSUPPORTED_FEATURES.font});
  41240. try {
  41241. // error, but it's still nice to have font type reported
  41242. var descriptor = preEvaluatedFont.descriptor;
  41243. var fontFile3 = descriptor && descriptor.get('FontFile3');
  41244. var subtype = fontFile3 && fontFile3.get('Subtype');
  41245. var fontType = getFontType(preEvaluatedFont.type,
  41246. subtype && subtype.name);
  41247. var xrefFontStats = xref.stats.fontTypes;
  41248. xrefFontStats[fontType] = true;
  41249. } catch (ex) { }
  41250. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41251. new ErrorFont(reason instanceof Error ? reason.message : reason),
  41252. font));
  41253. });
  41254. return fontCapability.promise;
  41255. },
  41256. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  41257. var lastIndex = operatorList.length - 1;
  41258. if (!args) {
  41259. args = [];
  41260. }
  41261. if (lastIndex < 0 ||
  41262. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  41263. operatorList.addOp(OPS.constructPath, [[fn], args]);
  41264. } else {
  41265. var opArgs = operatorList.argsArray[lastIndex];
  41266. opArgs[0].push(fn);
  41267. Array.prototype.push.apply(opArgs[1], args);
  41268. }
  41269. },
  41270. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  41271. cs, patterns, resources, task, xref) {
  41272. // compile tiling patterns
  41273. var patternName = args[args.length - 1];
  41274. // SCN/scn applies patterns along with normal colors
  41275. var pattern;
  41276. if (isName(patternName) &&
  41277. (pattern = patterns.get(patternName.name))) {
  41278. var dict = (isStream(pattern) ? pattern.dict : pattern);
  41279. var typeNum = dict.get('PatternType');
  41280. if (typeNum === TILING_PATTERN) {
  41281. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  41282. return this.handleTilingType(fn, color, resources, pattern,
  41283. dict, operatorList, task);
  41284. } else if (typeNum === SHADING_PATTERN) {
  41285. var shading = dict.get('Shading');
  41286. var matrix = dict.get('Matrix');
  41287. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  41288. this.handler);
  41289. operatorList.addOp(fn, pattern.getIR());
  41290. return Promise.resolve();
  41291. } else {
  41292. return Promise.reject('Unknown PatternType: ' + typeNum);
  41293. }
  41294. }
  41295. // TODO shall we fail here?
  41296. operatorList.addOp(fn, args);
  41297. return Promise.resolve();
  41298. },
  41299. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  41300. task,
  41301. resources,
  41302. operatorList,
  41303. initialState) {
  41304. var self = this;
  41305. var xref = this.xref;
  41306. var imageCache = {};
  41307. assert(operatorList);
  41308. resources = (resources || Dict.empty);
  41309. var xobjs = (resources.get('XObject') || Dict.empty);
  41310. var patterns = (resources.get('Pattern') || Dict.empty);
  41311. var stateManager = new StateManager(initialState || new EvalState());
  41312. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41313. var timeSlotManager = new TimeSlotManager();
  41314. return new Promise(function next(resolve, reject) {
  41315. task.ensureNotTerminated();
  41316. timeSlotManager.reset();
  41317. var stop, operation = {}, i, ii, cs;
  41318. while (!(stop = timeSlotManager.check())) {
  41319. // The arguments parsed by read() are used beyond this loop, so we
  41320. // cannot reuse the same array on each iteration. Therefore we pass
  41321. // in |null| as the initial value (see the comment on
  41322. // EvaluatorPreprocessor_read() for why).
  41323. operation.args = null;
  41324. if (!(preprocessor.read(operation))) {
  41325. break;
  41326. }
  41327. var args = operation.args;
  41328. var fn = operation.fn;
  41329. switch (fn | 0) {
  41330. case OPS.paintXObject:
  41331. if (args[0].code) {
  41332. break;
  41333. }
  41334. // eagerly compile XForm objects
  41335. var name = args[0].name;
  41336. if (!name) {
  41337. warn('XObject must be referred to by name.');
  41338. continue;
  41339. }
  41340. if (imageCache[name] !== undefined) {
  41341. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  41342. args = null;
  41343. continue;
  41344. }
  41345. var xobj = xobjs.get(name);
  41346. if (xobj) {
  41347. assert(isStream(xobj), 'XObject should be a stream');
  41348. var type = xobj.dict.get('Subtype');
  41349. assert(isName(type),
  41350. 'XObject should have a Name subtype');
  41351. if (type.name === 'Form') {
  41352. stateManager.save();
  41353. return self.buildFormXObject(resources, xobj, null,
  41354. operatorList, task,
  41355. stateManager.state.clone()).
  41356. then(function () {
  41357. stateManager.restore();
  41358. next(resolve, reject);
  41359. }, reject);
  41360. } else if (type.name === 'Image') {
  41361. self.buildPaintImageXObject(resources, xobj, false,
  41362. operatorList, name, imageCache);
  41363. args = null;
  41364. continue;
  41365. } else if (type.name === 'PS') {
  41366. // PostScript XObjects are unused when viewing documents.
  41367. // See section 4.7.1 of Adobe's PDF reference.
  41368. info('Ignored XObject subtype PS');
  41369. continue;
  41370. } else {
  41371. error('Unhandled XObject subtype ' + type.name);
  41372. }
  41373. }
  41374. break;
  41375. case OPS.setFont:
  41376. var fontSize = args[1];
  41377. // eagerly collect all fonts
  41378. return self.handleSetFont(resources, args, null, operatorList,
  41379. task, stateManager.state).
  41380. then(function (loadedName) {
  41381. operatorList.addDependency(loadedName);
  41382. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  41383. next(resolve, reject);
  41384. }, reject);
  41385. case OPS.endInlineImage:
  41386. var cacheKey = args[0].cacheKey;
  41387. if (cacheKey) {
  41388. var cacheEntry = imageCache[cacheKey];
  41389. if (cacheEntry !== undefined) {
  41390. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  41391. args = null;
  41392. continue;
  41393. }
  41394. }
  41395. self.buildPaintImageXObject(resources, args[0], true,
  41396. operatorList, cacheKey, imageCache);
  41397. args = null;
  41398. continue;
  41399. case OPS.showText:
  41400. args[0] = self.handleText(args[0], stateManager.state);
  41401. break;
  41402. case OPS.showSpacedText:
  41403. var arr = args[0];
  41404. var combinedGlyphs = [];
  41405. var arrLength = arr.length;
  41406. var state = stateManager.state;
  41407. for (i = 0; i < arrLength; ++i) {
  41408. var arrItem = arr[i];
  41409. if (isString(arrItem)) {
  41410. Array.prototype.push.apply(combinedGlyphs,
  41411. self.handleText(arrItem, state));
  41412. } else if (isNum(arrItem)) {
  41413. combinedGlyphs.push(arrItem);
  41414. }
  41415. }
  41416. args[0] = combinedGlyphs;
  41417. fn = OPS.showText;
  41418. break;
  41419. case OPS.nextLineShowText:
  41420. operatorList.addOp(OPS.nextLine);
  41421. args[0] = self.handleText(args[0], stateManager.state);
  41422. fn = OPS.showText;
  41423. break;
  41424. case OPS.nextLineSetSpacingShowText:
  41425. operatorList.addOp(OPS.nextLine);
  41426. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  41427. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  41428. args[0] = self.handleText(args[0], stateManager.state);
  41429. fn = OPS.showText;
  41430. break;
  41431. case OPS.setTextRenderingMode:
  41432. stateManager.state.textRenderingMode = args[0];
  41433. break;
  41434. case OPS.setFillColorSpace:
  41435. stateManager.state.fillColorSpace =
  41436. ColorSpace.parse(args[0], xref, resources);
  41437. continue;
  41438. case OPS.setStrokeColorSpace:
  41439. stateManager.state.strokeColorSpace =
  41440. ColorSpace.parse(args[0], xref, resources);
  41441. continue;
  41442. case OPS.setFillColor:
  41443. cs = stateManager.state.fillColorSpace;
  41444. args = cs.getRgb(args, 0);
  41445. fn = OPS.setFillRGBColor;
  41446. break;
  41447. case OPS.setStrokeColor:
  41448. cs = stateManager.state.strokeColorSpace;
  41449. args = cs.getRgb(args, 0);
  41450. fn = OPS.setStrokeRGBColor;
  41451. break;
  41452. case OPS.setFillGray:
  41453. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  41454. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41455. fn = OPS.setFillRGBColor;
  41456. break;
  41457. case OPS.setStrokeGray:
  41458. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  41459. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41460. fn = OPS.setStrokeRGBColor;
  41461. break;
  41462. case OPS.setFillCMYKColor:
  41463. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  41464. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41465. fn = OPS.setFillRGBColor;
  41466. break;
  41467. case OPS.setStrokeCMYKColor:
  41468. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  41469. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41470. fn = OPS.setStrokeRGBColor;
  41471. break;
  41472. case OPS.setFillRGBColor:
  41473. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  41474. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41475. break;
  41476. case OPS.setStrokeRGBColor:
  41477. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  41478. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41479. break;
  41480. case OPS.setFillColorN:
  41481. cs = stateManager.state.fillColorSpace;
  41482. if (cs.name === 'Pattern') {
  41483. return self.handleColorN(operatorList, OPS.setFillColorN,
  41484. args, cs, patterns, resources, task, xref).then(function() {
  41485. next(resolve, reject);
  41486. }, reject);
  41487. }
  41488. args = cs.getRgb(args, 0);
  41489. fn = OPS.setFillRGBColor;
  41490. break;
  41491. case OPS.setStrokeColorN:
  41492. cs = stateManager.state.strokeColorSpace;
  41493. if (cs.name === 'Pattern') {
  41494. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  41495. args, cs, patterns, resources, task, xref).then(function() {
  41496. next(resolve, reject);
  41497. }, reject);
  41498. }
  41499. args = cs.getRgb(args, 0);
  41500. fn = OPS.setStrokeRGBColor;
  41501. break;
  41502. case OPS.shadingFill:
  41503. var shadingRes = resources.get('Shading');
  41504. if (!shadingRes) {
  41505. error('No shading resource found');
  41506. }
  41507. var shading = shadingRes.get(args[0].name);
  41508. if (!shading) {
  41509. error('No shading object found');
  41510. }
  41511. var shadingFill = Pattern.parseShading(shading, null, xref,
  41512. resources, self.handler);
  41513. var patternIR = shadingFill.getIR();
  41514. args = [patternIR];
  41515. fn = OPS.shadingFill;
  41516. break;
  41517. case OPS.setGState:
  41518. var dictName = args[0];
  41519. var extGState = resources.get('ExtGState');
  41520. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41521. break;
  41522. }
  41523. var gState = extGState.get(dictName.name);
  41524. return self.setGState(resources, gState, operatorList, task,
  41525. xref, stateManager).then(function() {
  41526. next(resolve, reject);
  41527. }, reject);
  41528. case OPS.moveTo:
  41529. case OPS.lineTo:
  41530. case OPS.curveTo:
  41531. case OPS.curveTo2:
  41532. case OPS.curveTo3:
  41533. case OPS.closePath:
  41534. self.buildPath(operatorList, fn, args);
  41535. continue;
  41536. case OPS.rectangle:
  41537. self.buildPath(operatorList, fn, args);
  41538. continue;
  41539. case OPS.markPoint:
  41540. case OPS.markPointProps:
  41541. case OPS.beginMarkedContent:
  41542. case OPS.beginMarkedContentProps:
  41543. case OPS.endMarkedContent:
  41544. case OPS.beginCompat:
  41545. case OPS.endCompat:
  41546. // Ignore operators where the corresponding handlers are known to
  41547. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  41548. // serialization errors and is also a bit more efficient.
  41549. // We could also try to serialize all objects in a general way,
  41550. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  41551. // but doing so is meaningless without knowing the semantics.
  41552. continue;
  41553. default:
  41554. // Note: Let's hope that the ignored operator does not have any
  41555. // non-serializable arguments, otherwise postMessage will throw
  41556. // "An object could not be cloned.".
  41557. }
  41558. operatorList.addOp(fn, args);
  41559. }
  41560. if (stop) {
  41561. deferred.then(function () {
  41562. next(resolve, reject);
  41563. }, reject);
  41564. return;
  41565. }
  41566. // Some PDFs don't close all restores inside object/form.
  41567. // Closing those for them.
  41568. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  41569. operatorList.addOp(OPS.restore, []);
  41570. }
  41571. resolve();
  41572. });
  41573. },
  41574. getTextContent:
  41575. function PartialEvaluator_getTextContent(stream, task, resources,
  41576. stateManager,
  41577. normalizeWhitespace) {
  41578. stateManager = (stateManager || new StateManager(new TextState()));
  41579. var WhitespaceRegexp = /\s/g;
  41580. var textContent = {
  41581. items: [],
  41582. styles: Object.create(null)
  41583. };
  41584. var textContentItem = {
  41585. initialized: false,
  41586. str: [],
  41587. width: 0,
  41588. height: 0,
  41589. vertical: false,
  41590. lastAdvanceWidth: 0,
  41591. lastAdvanceHeight: 0,
  41592. textAdvanceScale: 0,
  41593. spaceWidth: 0,
  41594. fakeSpaceMin: Infinity,
  41595. fakeMultiSpaceMin: Infinity,
  41596. fakeMultiSpaceMax: -0,
  41597. textRunBreakAllowed: false,
  41598. transform: null,
  41599. fontName: null
  41600. };
  41601. var SPACE_FACTOR = 0.3;
  41602. var MULTI_SPACE_FACTOR = 1.5;
  41603. var MULTI_SPACE_FACTOR_MAX = 4;
  41604. var self = this;
  41605. var xref = this.xref;
  41606. resources = (xref.fetchIfRef(resources) || Dict.empty);
  41607. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  41608. var xobjs = null;
  41609. var xobjsCache = {};
  41610. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41611. var textState;
  41612. function ensureTextContentItem() {
  41613. if (textContentItem.initialized) {
  41614. return textContentItem;
  41615. }
  41616. var font = textState.font;
  41617. if (!(font.loadedName in textContent.styles)) {
  41618. textContent.styles[font.loadedName] = {
  41619. fontFamily: font.fallbackName,
  41620. ascent: font.ascent,
  41621. descent: font.descent,
  41622. vertical: font.vertical
  41623. };
  41624. }
  41625. textContentItem.fontName = font.loadedName;
  41626. // 9.4.4 Text Space Details
  41627. var tsm = [textState.fontSize * textState.textHScale, 0,
  41628. 0, textState.fontSize,
  41629. 0, textState.textRise];
  41630. if (font.isType3Font &&
  41631. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  41632. textState.fontSize === 1) {
  41633. var glyphHeight = font.bbox[3] - font.bbox[1];
  41634. if (glyphHeight > 0) {
  41635. glyphHeight = glyphHeight * textState.fontMatrix[3];
  41636. tsm[3] *= glyphHeight;
  41637. }
  41638. }
  41639. var trm = Util.transform(textState.ctm,
  41640. Util.transform(textState.textMatrix, tsm));
  41641. textContentItem.transform = trm;
  41642. if (!font.vertical) {
  41643. textContentItem.width = 0;
  41644. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  41645. textContentItem.vertical = false;
  41646. } else {
  41647. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  41648. textContentItem.height = 0;
  41649. textContentItem.vertical = true;
  41650. }
  41651. var a = textState.textLineMatrix[0];
  41652. var b = textState.textLineMatrix[1];
  41653. var scaleLineX = Math.sqrt(a * a + b * b);
  41654. a = textState.ctm[0];
  41655. b = textState.ctm[1];
  41656. var scaleCtmX = Math.sqrt(a * a + b * b);
  41657. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  41658. textContentItem.lastAdvanceWidth = 0;
  41659. textContentItem.lastAdvanceHeight = 0;
  41660. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  41661. if (spaceWidth) {
  41662. textContentItem.spaceWidth = spaceWidth;
  41663. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  41664. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  41665. textContentItem.fakeMultiSpaceMax =
  41666. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  41667. // It's okay for monospace fonts to fake as much space as needed.
  41668. textContentItem.textRunBreakAllowed = !font.isMonospace;
  41669. } else {
  41670. textContentItem.spaceWidth = 0;
  41671. textContentItem.fakeSpaceMin = Infinity;
  41672. textContentItem.fakeMultiSpaceMin = Infinity;
  41673. textContentItem.fakeMultiSpaceMax = 0;
  41674. textContentItem.textRunBreakAllowed = false;
  41675. }
  41676. textContentItem.initialized = true;
  41677. return textContentItem;
  41678. }
  41679. function replaceWhitespace(str) {
  41680. // Replaces all whitespaces with standard spaces (0x20), to avoid
  41681. // alignment issues between the textLayer and the canvas if the text
  41682. // contains e.g. tabs (fixes issue6612.pdf).
  41683. var i = 0, ii = str.length, code;
  41684. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  41685. i++;
  41686. }
  41687. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  41688. }
  41689. function runBidiTransform(textChunk) {
  41690. var str = textChunk.str.join('');
  41691. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  41692. return {
  41693. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  41694. bidiResult.str),
  41695. dir: bidiResult.dir,
  41696. width: textChunk.width,
  41697. height: textChunk.height,
  41698. transform: textChunk.transform,
  41699. fontName: textChunk.fontName
  41700. };
  41701. }
  41702. function handleSetFont(fontName, fontRef) {
  41703. return self.loadFont(fontName, fontRef, xref, resources).
  41704. then(function (translated) {
  41705. textState.font = translated.font;
  41706. textState.fontMatrix = translated.font.fontMatrix ||
  41707. FONT_IDENTITY_MATRIX;
  41708. });
  41709. }
  41710. function buildTextContentItem(chars) {
  41711. var font = textState.font;
  41712. var textChunk = ensureTextContentItem();
  41713. var width = 0;
  41714. var height = 0;
  41715. var glyphs = font.charsToGlyphs(chars);
  41716. var defaultVMetrics = font.defaultVMetrics;
  41717. for (var i = 0; i < glyphs.length; i++) {
  41718. var glyph = glyphs[i];
  41719. var vMetricX = null;
  41720. var vMetricY = null;
  41721. var glyphWidth = null;
  41722. if (font.vertical) {
  41723. if (glyph.vmetric) {
  41724. glyphWidth = glyph.vmetric[0];
  41725. vMetricX = glyph.vmetric[1];
  41726. vMetricY = glyph.vmetric[2];
  41727. } else {
  41728. glyphWidth = glyph.width;
  41729. vMetricX = glyph.width * 0.5;
  41730. vMetricY = defaultVMetrics[2];
  41731. }
  41732. } else {
  41733. glyphWidth = glyph.width;
  41734. }
  41735. var glyphUnicode = glyph.unicode;
  41736. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  41737. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  41738. }
  41739. glyphUnicode = reverseIfRtl(glyphUnicode);
  41740. // The following will calculate the x and y of the individual glyphs.
  41741. // if (font.vertical) {
  41742. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  41743. // textState.fontMatrix[0];
  41744. // tsm[5] -= vMetricY * textState.fontSize *
  41745. // textState.fontMatrix[0];
  41746. // }
  41747. // var trm = Util.transform(textState.textMatrix, tsm);
  41748. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  41749. // var x = pt[0];
  41750. // var y = pt[1];
  41751. var charSpacing = textState.charSpacing;
  41752. if (glyph.isSpace) {
  41753. var wordSpacing = textState.wordSpacing;
  41754. charSpacing += wordSpacing;
  41755. if (wordSpacing > 0) {
  41756. addFakeSpaces(wordSpacing, textChunk.str);
  41757. }
  41758. }
  41759. var tx = 0;
  41760. var ty = 0;
  41761. if (!font.vertical) {
  41762. var w0 = glyphWidth * textState.fontMatrix[0];
  41763. tx = (w0 * textState.fontSize + charSpacing) *
  41764. textState.textHScale;
  41765. width += tx;
  41766. } else {
  41767. var w1 = glyphWidth * textState.fontMatrix[0];
  41768. ty = w1 * textState.fontSize + charSpacing;
  41769. height += ty;
  41770. }
  41771. textState.translateTextMatrix(tx, ty);
  41772. textChunk.str.push(glyphUnicode);
  41773. }
  41774. if (!font.vertical) {
  41775. textChunk.lastAdvanceWidth = width;
  41776. textChunk.width += width * textChunk.textAdvanceScale;
  41777. } else {
  41778. textChunk.lastAdvanceHeight = height;
  41779. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  41780. }
  41781. return textChunk;
  41782. }
  41783. function addFakeSpaces(width, strBuf) {
  41784. if (width < textContentItem.fakeSpaceMin) {
  41785. return;
  41786. }
  41787. if (width < textContentItem.fakeMultiSpaceMin) {
  41788. strBuf.push(' ');
  41789. return;
  41790. }
  41791. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  41792. while (fakeSpaces-- > 0) {
  41793. strBuf.push(' ');
  41794. }
  41795. }
  41796. function flushTextContentItem() {
  41797. if (!textContentItem.initialized) {
  41798. return;
  41799. }
  41800. textContent.items.push(runBidiTransform(textContentItem));
  41801. textContentItem.initialized = false;
  41802. textContentItem.str.length = 0;
  41803. }
  41804. var timeSlotManager = new TimeSlotManager();
  41805. return new Promise(function next(resolve, reject) {
  41806. task.ensureNotTerminated();
  41807. timeSlotManager.reset();
  41808. var stop, operation = {}, args = [];
  41809. while (!(stop = timeSlotManager.check())) {
  41810. // The arguments parsed by read() are not used beyond this loop, so
  41811. // we can reuse the same array on every iteration, thus avoiding
  41812. // unnecessary allocations.
  41813. args.length = 0;
  41814. operation.args = args;
  41815. if (!(preprocessor.read(operation))) {
  41816. break;
  41817. }
  41818. textState = stateManager.state;
  41819. var fn = operation.fn;
  41820. args = operation.args;
  41821. var advance;
  41822. switch (fn | 0) {
  41823. case OPS.setFont:
  41824. flushTextContentItem();
  41825. textState.fontSize = args[1];
  41826. return handleSetFont(args[0].name).then(function() {
  41827. next(resolve, reject);
  41828. }, reject);
  41829. case OPS.setTextRise:
  41830. flushTextContentItem();
  41831. textState.textRise = args[0];
  41832. break;
  41833. case OPS.setHScale:
  41834. flushTextContentItem();
  41835. textState.textHScale = args[0] / 100;
  41836. break;
  41837. case OPS.setLeading:
  41838. flushTextContentItem();
  41839. textState.leading = args[0];
  41840. break;
  41841. case OPS.moveText:
  41842. // Optimization to treat same line movement as advance
  41843. var isSameTextLine = !textState.font ? false :
  41844. ((textState.font.vertical ? args[0] : args[1]) === 0);
  41845. advance = args[0] - args[1];
  41846. if (isSameTextLine && textContentItem.initialized &&
  41847. advance > 0 &&
  41848. advance <= textContentItem.fakeMultiSpaceMax) {
  41849. textState.translateTextLineMatrix(args[0], args[1]);
  41850. textContentItem.width +=
  41851. (args[0] - textContentItem.lastAdvanceWidth);
  41852. textContentItem.height +=
  41853. (args[1] - textContentItem.lastAdvanceHeight);
  41854. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  41855. (args[1] - textContentItem.lastAdvanceHeight);
  41856. addFakeSpaces(diff, textContentItem.str);
  41857. break;
  41858. }
  41859. flushTextContentItem();
  41860. textState.translateTextLineMatrix(args[0], args[1]);
  41861. textState.textMatrix = textState.textLineMatrix.slice();
  41862. break;
  41863. case OPS.setLeadingMoveText:
  41864. flushTextContentItem();
  41865. textState.leading = -args[1];
  41866. textState.translateTextLineMatrix(args[0], args[1]);
  41867. textState.textMatrix = textState.textLineMatrix.slice();
  41868. break;
  41869. case OPS.nextLine:
  41870. flushTextContentItem();
  41871. textState.carriageReturn();
  41872. break;
  41873. case OPS.setTextMatrix:
  41874. flushTextContentItem();
  41875. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  41876. args[4], args[5]);
  41877. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  41878. args[4], args[5]);
  41879. break;
  41880. case OPS.setCharSpacing:
  41881. textState.charSpacing = args[0];
  41882. break;
  41883. case OPS.setWordSpacing:
  41884. textState.wordSpacing = args[0];
  41885. break;
  41886. case OPS.beginText:
  41887. flushTextContentItem();
  41888. textState.textMatrix = IDENTITY_MATRIX.slice();
  41889. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  41890. break;
  41891. case OPS.showSpacedText:
  41892. var items = args[0];
  41893. var offset;
  41894. for (var j = 0, jj = items.length; j < jj; j++) {
  41895. if (typeof items[j] === 'string') {
  41896. buildTextContentItem(items[j]);
  41897. } else {
  41898. ensureTextContentItem();
  41899. // PDF Specification 5.3.2 states:
  41900. // The number is expressed in thousandths of a unit of text
  41901. // space.
  41902. // This amount is subtracted from the current horizontal or
  41903. // vertical coordinate, depending on the writing mode.
  41904. // In the default coordinate system, a positive adjustment
  41905. // has the effect of moving the next glyph painted either to
  41906. // the left or down by the given amount.
  41907. advance = items[j] * textState.fontSize / 1000;
  41908. var breakTextRun = false;
  41909. if (textState.font.vertical) {
  41910. offset = advance *
  41911. (textState.textHScale * textState.textMatrix[2] +
  41912. textState.textMatrix[3]);
  41913. textState.translateTextMatrix(0, advance);
  41914. breakTextRun = textContentItem.textRunBreakAllowed &&
  41915. advance > textContentItem.fakeMultiSpaceMax;
  41916. if (!breakTextRun) {
  41917. // Value needs to be added to height to paint down.
  41918. textContentItem.height += offset;
  41919. }
  41920. } else {
  41921. advance = -advance;
  41922. offset = advance * (
  41923. textState.textHScale * textState.textMatrix[0] +
  41924. textState.textMatrix[1]);
  41925. textState.translateTextMatrix(advance, 0);
  41926. breakTextRun = textContentItem.textRunBreakAllowed &&
  41927. advance > textContentItem.fakeMultiSpaceMax;
  41928. if (!breakTextRun) {
  41929. // Value needs to be subtracted from width to paint left.
  41930. textContentItem.width += offset;
  41931. }
  41932. }
  41933. if (breakTextRun) {
  41934. flushTextContentItem();
  41935. } else if (advance > 0) {
  41936. addFakeSpaces(advance, textContentItem.str);
  41937. }
  41938. }
  41939. }
  41940. break;
  41941. case OPS.showText:
  41942. buildTextContentItem(args[0]);
  41943. break;
  41944. case OPS.nextLineShowText:
  41945. flushTextContentItem();
  41946. textState.carriageReturn();
  41947. buildTextContentItem(args[0]);
  41948. break;
  41949. case OPS.nextLineSetSpacingShowText:
  41950. flushTextContentItem();
  41951. textState.wordSpacing = args[0];
  41952. textState.charSpacing = args[1];
  41953. textState.carriageReturn();
  41954. buildTextContentItem(args[2]);
  41955. break;
  41956. case OPS.paintXObject:
  41957. flushTextContentItem();
  41958. if (args[0].code) {
  41959. break;
  41960. }
  41961. if (!xobjs) {
  41962. xobjs = (resources.get('XObject') || Dict.empty);
  41963. }
  41964. var name = args[0].name;
  41965. if (xobjsCache.key === name) {
  41966. if (xobjsCache.texts) {
  41967. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  41968. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  41969. }
  41970. break;
  41971. }
  41972. var xobj = xobjs.get(name);
  41973. if (!xobj) {
  41974. break;
  41975. }
  41976. assert(isStream(xobj), 'XObject should be a stream');
  41977. var type = xobj.dict.get('Subtype');
  41978. assert(isName(type),
  41979. 'XObject should have a Name subtype');
  41980. if ('Form' !== type.name) {
  41981. xobjsCache.key = name;
  41982. xobjsCache.texts = null;
  41983. break;
  41984. }
  41985. stateManager.save();
  41986. var matrix = xobj.dict.get('Matrix');
  41987. if (isArray(matrix) && matrix.length === 6) {
  41988. stateManager.transform(matrix);
  41989. }
  41990. return self.getTextContent(xobj, task,
  41991. xobj.dict.get('Resources') || resources, stateManager,
  41992. normalizeWhitespace).then(function (formTextContent) {
  41993. Util.appendToArray(textContent.items, formTextContent.items);
  41994. Util.extendObj(textContent.styles, formTextContent.styles);
  41995. stateManager.restore();
  41996. xobjsCache.key = name;
  41997. xobjsCache.texts = formTextContent;
  41998. next(resolve, reject);
  41999. }, reject);
  42000. case OPS.setGState:
  42001. flushTextContentItem();
  42002. var dictName = args[0];
  42003. var extGState = resources.get('ExtGState');
  42004. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42005. break;
  42006. }
  42007. var gsStateMap = extGState.get(dictName.name);
  42008. var gsStateFont = null;
  42009. for (var key in gsStateMap) {
  42010. if (key === 'Font') {
  42011. assert(!gsStateFont);
  42012. gsStateFont = gsStateMap[key];
  42013. }
  42014. }
  42015. if (gsStateFont) {
  42016. textState.fontSize = gsStateFont[1];
  42017. return handleSetFont(gsStateFont[0]).then(function() {
  42018. next(resolve, reject);
  42019. }, reject);
  42020. }
  42021. break;
  42022. } // switch
  42023. } // while
  42024. if (stop) {
  42025. deferred.then(function () {
  42026. next(resolve, reject);
  42027. }, reject);
  42028. return;
  42029. }
  42030. flushTextContentItem();
  42031. resolve(textContent);
  42032. });
  42033. },
  42034. extractDataStructures: function
  42035. partialEvaluatorExtractDataStructures(dict, baseDict,
  42036. xref, properties) {
  42037. // 9.10.2
  42038. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  42039. if (toUnicode) {
  42040. properties.toUnicode = this.readToUnicode(toUnicode);
  42041. }
  42042. if (properties.composite) {
  42043. // CIDSystemInfo helps to match CID to glyphs
  42044. var cidSystemInfo = dict.get('CIDSystemInfo');
  42045. if (isDict(cidSystemInfo)) {
  42046. properties.cidSystemInfo = {
  42047. registry: cidSystemInfo.get('Registry'),
  42048. ordering: cidSystemInfo.get('Ordering'),
  42049. supplement: cidSystemInfo.get('Supplement')
  42050. };
  42051. }
  42052. var cidToGidMap = dict.get('CIDToGIDMap');
  42053. if (isStream(cidToGidMap)) {
  42054. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  42055. }
  42056. }
  42057. // Based on 9.6.6 of the spec the encoding can come from multiple places
  42058. // and depends on the font type. The base encoding and differences are
  42059. // read here, but the encoding that is actually used is chosen during
  42060. // glyph mapping in the font.
  42061. // TODO: Loading the built in encoding in the font would allow the
  42062. // differences to be merged in here not require us to hold on to it.
  42063. var differences = [];
  42064. var baseEncodingName = null;
  42065. var encoding;
  42066. if (dict.has('Encoding')) {
  42067. encoding = dict.get('Encoding');
  42068. if (isDict(encoding)) {
  42069. baseEncodingName = encoding.get('BaseEncoding');
  42070. baseEncodingName = (isName(baseEncodingName) ?
  42071. baseEncodingName.name : null);
  42072. // Load the differences between the base and original
  42073. if (encoding.has('Differences')) {
  42074. var diffEncoding = encoding.get('Differences');
  42075. var index = 0;
  42076. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  42077. var data = diffEncoding[j];
  42078. if (isNum(data)) {
  42079. index = data;
  42080. } else if (isName(data)) {
  42081. differences[index++] = data.name;
  42082. } else if (isRef(data)) {
  42083. diffEncoding[j--] = xref.fetch(data);
  42084. continue;
  42085. } else {
  42086. error('Invalid entry in \'Differences\' array: ' + data);
  42087. }
  42088. }
  42089. }
  42090. } else if (isName(encoding)) {
  42091. baseEncodingName = encoding.name;
  42092. } else {
  42093. error('Encoding is not a Name nor a Dict');
  42094. }
  42095. // According to table 114 if the encoding is a named encoding it must be
  42096. // one of these predefined encodings.
  42097. if ((baseEncodingName !== 'MacRomanEncoding' &&
  42098. baseEncodingName !== 'MacExpertEncoding' &&
  42099. baseEncodingName !== 'WinAnsiEncoding')) {
  42100. baseEncodingName = null;
  42101. }
  42102. }
  42103. if (baseEncodingName) {
  42104. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  42105. } else {
  42106. encoding = (properties.type === 'TrueType' ?
  42107. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  42108. // The Symbolic attribute can be misused for regular fonts
  42109. // Heuristic: we have to check if the font is a standard one also
  42110. if (!!(properties.flags & FontFlags.Symbolic)) {
  42111. encoding = Encodings.MacRomanEncoding;
  42112. if (!properties.file) {
  42113. if (/Symbol/i.test(properties.name)) {
  42114. encoding = Encodings.SymbolSetEncoding;
  42115. } else if (/Dingbats/i.test(properties.name)) {
  42116. encoding = Encodings.ZapfDingbatsEncoding;
  42117. }
  42118. }
  42119. }
  42120. properties.defaultEncoding = encoding;
  42121. }
  42122. properties.differences = differences;
  42123. properties.baseEncodingName = baseEncodingName;
  42124. properties.dict = dict;
  42125. },
  42126. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  42127. var cmap, cmapObj = toUnicode;
  42128. if (isName(cmapObj)) {
  42129. cmap = CMapFactory.create(cmapObj,
  42130. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42131. if (cmap instanceof IdentityCMap) {
  42132. return new IdentityToUnicodeMap(0, 0xFFFF);
  42133. }
  42134. return new ToUnicodeMap(cmap.getMap());
  42135. } else if (isStream(cmapObj)) {
  42136. cmap = CMapFactory.create(cmapObj,
  42137. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42138. if (cmap instanceof IdentityCMap) {
  42139. return new IdentityToUnicodeMap(0, 0xFFFF);
  42140. }
  42141. var map = new Array(cmap.length);
  42142. // Convert UTF-16BE
  42143. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  42144. // to iterate over all keys.
  42145. cmap.forEach(function(charCode, token) {
  42146. var str = [];
  42147. for (var k = 0; k < token.length; k += 2) {
  42148. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42149. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  42150. str.push(w1);
  42151. continue;
  42152. }
  42153. k += 2;
  42154. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42155. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  42156. }
  42157. map[charCode] = String.fromCharCode.apply(String, str);
  42158. });
  42159. return new ToUnicodeMap(map);
  42160. }
  42161. return null;
  42162. },
  42163. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  42164. // Extract the encoding from the CIDToGIDMap
  42165. var glyphsData = cidToGidStream.getBytes();
  42166. // Set encoding 0 to later verify the font has an encoding
  42167. var result = [];
  42168. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  42169. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  42170. if (glyphID === 0) {
  42171. continue;
  42172. }
  42173. var code = j >> 1;
  42174. result[code] = glyphID;
  42175. }
  42176. return result;
  42177. },
  42178. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  42179. descriptor,
  42180. properties) {
  42181. var glyphsWidths = [];
  42182. var defaultWidth = 0;
  42183. var glyphsVMetrics = [];
  42184. var defaultVMetrics;
  42185. var i, ii, j, jj, start, code, widths;
  42186. if (properties.composite) {
  42187. defaultWidth = dict.get('DW') || 1000;
  42188. widths = dict.get('W');
  42189. if (widths) {
  42190. for (i = 0, ii = widths.length; i < ii; i++) {
  42191. start = widths[i++];
  42192. code = xref.fetchIfRef(widths[i]);
  42193. if (isArray(code)) {
  42194. for (j = 0, jj = code.length; j < jj; j++) {
  42195. glyphsWidths[start++] = code[j];
  42196. }
  42197. } else {
  42198. var width = widths[++i];
  42199. for (j = start; j <= code; j++) {
  42200. glyphsWidths[j] = width;
  42201. }
  42202. }
  42203. }
  42204. }
  42205. if (properties.vertical) {
  42206. var vmetrics = (dict.get('DW2') || [880, -1000]);
  42207. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  42208. vmetrics = dict.get('W2');
  42209. if (vmetrics) {
  42210. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  42211. start = vmetrics[i++];
  42212. code = xref.fetchIfRef(vmetrics[i]);
  42213. if (isArray(code)) {
  42214. for (j = 0, jj = code.length; j < jj; j++) {
  42215. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  42216. }
  42217. } else {
  42218. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  42219. for (j = start; j <= code; j++) {
  42220. glyphsVMetrics[j] = vmetric;
  42221. }
  42222. }
  42223. }
  42224. }
  42225. }
  42226. } else {
  42227. var firstChar = properties.firstChar;
  42228. widths = dict.get('Widths');
  42229. if (widths) {
  42230. j = firstChar;
  42231. for (i = 0, ii = widths.length; i < ii; i++) {
  42232. glyphsWidths[j++] = widths[i];
  42233. }
  42234. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  42235. } else {
  42236. // Trying get the BaseFont metrics (see comment above).
  42237. var baseFontName = dict.get('BaseFont');
  42238. if (isName(baseFontName)) {
  42239. var metrics = this.getBaseFontMetrics(baseFontName.name);
  42240. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  42241. properties);
  42242. defaultWidth = metrics.defaultWidth;
  42243. }
  42244. }
  42245. }
  42246. // Heuristic: detection of monospace font by checking all non-zero widths
  42247. var isMonospace = true;
  42248. var firstWidth = defaultWidth;
  42249. for (var glyph in glyphsWidths) {
  42250. var glyphWidth = glyphsWidths[glyph];
  42251. if (!glyphWidth) {
  42252. continue;
  42253. }
  42254. if (!firstWidth) {
  42255. firstWidth = glyphWidth;
  42256. continue;
  42257. }
  42258. if (firstWidth !== glyphWidth) {
  42259. isMonospace = false;
  42260. break;
  42261. }
  42262. }
  42263. if (isMonospace) {
  42264. properties.flags |= FontFlags.FixedPitch;
  42265. }
  42266. properties.defaultWidth = defaultWidth;
  42267. properties.widths = glyphsWidths;
  42268. properties.defaultVMetrics = defaultVMetrics;
  42269. properties.vmetrics = glyphsVMetrics;
  42270. },
  42271. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  42272. // Simulating descriptor flags attribute
  42273. var fontNameWoStyle = baseFontName.split('-')[0];
  42274. return (fontNameWoStyle in serifFonts) ||
  42275. (fontNameWoStyle.search(/serif/gi) !== -1);
  42276. },
  42277. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  42278. var defaultWidth = 0;
  42279. var widths = [];
  42280. var monospace = false;
  42281. var lookupName = (stdFontMap[name] || name);
  42282. if (!(lookupName in Metrics)) {
  42283. // Use default fonts for looking up font metrics if the passed
  42284. // font is not a base font
  42285. if (this.isSerifFont(name)) {
  42286. lookupName = 'Times-Roman';
  42287. } else {
  42288. lookupName = 'Helvetica';
  42289. }
  42290. }
  42291. var glyphWidths = Metrics[lookupName];
  42292. if (isNum(glyphWidths)) {
  42293. defaultWidth = glyphWidths;
  42294. monospace = true;
  42295. } else {
  42296. widths = glyphWidths;
  42297. }
  42298. return {
  42299. defaultWidth: defaultWidth,
  42300. monospace: monospace,
  42301. widths: widths
  42302. };
  42303. },
  42304. buildCharCodeToWidth:
  42305. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  42306. properties) {
  42307. var widths = Object.create(null);
  42308. var differences = properties.differences;
  42309. var encoding = properties.defaultEncoding;
  42310. for (var charCode = 0; charCode < 256; charCode++) {
  42311. if (charCode in differences &&
  42312. widthsByGlyphName[differences[charCode]]) {
  42313. widths[charCode] = widthsByGlyphName[differences[charCode]];
  42314. continue;
  42315. }
  42316. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  42317. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  42318. continue;
  42319. }
  42320. }
  42321. return widths;
  42322. },
  42323. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  42324. var baseDict = dict;
  42325. var type = dict.get('Subtype');
  42326. assert(isName(type), 'invalid font Subtype');
  42327. var composite = false;
  42328. var uint8array;
  42329. if (type.name === 'Type0') {
  42330. // If font is a composite
  42331. // - get the descendant font
  42332. // - set the type according to the descendant font
  42333. // - get the FontDescriptor from the descendant font
  42334. var df = dict.get('DescendantFonts');
  42335. if (!df) {
  42336. error('Descendant fonts are not specified');
  42337. }
  42338. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  42339. type = dict.get('Subtype');
  42340. assert(isName(type), 'invalid font Subtype');
  42341. composite = true;
  42342. }
  42343. var descriptor = dict.get('FontDescriptor');
  42344. if (descriptor) {
  42345. var hash = new MurmurHash3_64();
  42346. var encoding = baseDict.getRaw('Encoding');
  42347. if (isName(encoding)) {
  42348. hash.update(encoding.name);
  42349. } else if (isRef(encoding)) {
  42350. hash.update(encoding.num + '_' + encoding.gen);
  42351. } else if (isDict(encoding)) {
  42352. var keys = encoding.getKeys();
  42353. for (var i = 0, ii = keys.length; i < ii; i++) {
  42354. var entry = encoding.getRaw(keys[i]);
  42355. if (isName(entry)) {
  42356. hash.update(entry.name);
  42357. } else if (isRef(entry)) {
  42358. hash.update(entry.num + '_' + entry.gen);
  42359. } else if (isArray(entry)) { // 'Differences' entry.
  42360. // Ideally we should check the contents of the array, but to avoid
  42361. // parsing it here and then again in |extractDataStructures|,
  42362. // we only use the array length for now (fixes bug1157493.pdf).
  42363. hash.update(entry.length.toString());
  42364. }
  42365. }
  42366. }
  42367. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  42368. if (isStream(toUnicode)) {
  42369. var stream = toUnicode.str || toUnicode;
  42370. uint8array = stream.buffer ?
  42371. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  42372. new Uint8Array(stream.bytes.buffer,
  42373. stream.start, stream.end - stream.start);
  42374. hash.update(uint8array);
  42375. } else if (isName(toUnicode)) {
  42376. hash.update(toUnicode.name);
  42377. }
  42378. var widths = dict.get('Widths') || baseDict.get('Widths');
  42379. if (widths) {
  42380. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  42381. hash.update(uint8array);
  42382. }
  42383. }
  42384. return {
  42385. descriptor: descriptor,
  42386. dict: dict,
  42387. baseDict: baseDict,
  42388. composite: composite,
  42389. type: type.name,
  42390. hash: hash ? hash.hexdigest() : ''
  42391. };
  42392. },
  42393. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  42394. xref) {
  42395. var baseDict = preEvaluatedFont.baseDict;
  42396. var dict = preEvaluatedFont.dict;
  42397. var composite = preEvaluatedFont.composite;
  42398. var descriptor = preEvaluatedFont.descriptor;
  42399. var type = preEvaluatedFont.type;
  42400. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  42401. var properties;
  42402. if (!descriptor) {
  42403. if (type === 'Type3') {
  42404. // FontDescriptor is only required for Type3 fonts when the document
  42405. // is a tagged pdf. Create a barbebones one to get by.
  42406. descriptor = new Dict(null);
  42407. descriptor.set('FontName', Name.get(type));
  42408. descriptor.set('FontBBox', dict.get('FontBBox'));
  42409. } else {
  42410. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  42411. // FontDescriptor was not required.
  42412. // This case is here for compatibility.
  42413. var baseFontName = dict.get('BaseFont');
  42414. if (!isName(baseFontName)) {
  42415. error('Base font is not specified');
  42416. }
  42417. // Using base font name as a font name.
  42418. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  42419. var metrics = this.getBaseFontMetrics(baseFontName);
  42420. // Simulating descriptor flags attribute
  42421. var fontNameWoStyle = baseFontName.split('-')[0];
  42422. var flags =
  42423. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  42424. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  42425. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  42426. FontFlags.Nonsymbolic);
  42427. properties = {
  42428. type: type,
  42429. name: baseFontName,
  42430. widths: metrics.widths,
  42431. defaultWidth: metrics.defaultWidth,
  42432. flags: flags,
  42433. firstChar: 0,
  42434. lastChar: maxCharIndex
  42435. };
  42436. this.extractDataStructures(dict, dict, xref, properties);
  42437. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  42438. properties);
  42439. return new Font(baseFontName, null, properties);
  42440. }
  42441. }
  42442. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  42443. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  42444. // to ignore this rule when a variant of a standart font is used.
  42445. // TODO Fill the width array depending on which of the base font this is
  42446. // a variant.
  42447. var firstChar = (dict.get('FirstChar') || 0);
  42448. var lastChar = (dict.get('LastChar') || maxCharIndex);
  42449. var fontName = descriptor.get('FontName');
  42450. var baseFont = dict.get('BaseFont');
  42451. // Some bad PDFs have a string as the font name.
  42452. if (isString(fontName)) {
  42453. fontName = Name.get(fontName);
  42454. }
  42455. if (isString(baseFont)) {
  42456. baseFont = Name.get(baseFont);
  42457. }
  42458. if (type !== 'Type3') {
  42459. var fontNameStr = fontName && fontName.name;
  42460. var baseFontStr = baseFont && baseFont.name;
  42461. if (fontNameStr !== baseFontStr) {
  42462. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  42463. '" but should be the same as the Font\'s BaseFont "' +
  42464. baseFontStr + '"');
  42465. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  42466. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  42467. if (fontNameStr && baseFontStr &&
  42468. baseFontStr.indexOf(fontNameStr) === 0) {
  42469. fontName = baseFont;
  42470. }
  42471. }
  42472. }
  42473. fontName = (fontName || baseFont);
  42474. assert(isName(fontName), 'invalid font name');
  42475. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  42476. if (fontFile) {
  42477. if (fontFile.dict) {
  42478. var subtype = fontFile.dict.get('Subtype');
  42479. if (subtype) {
  42480. subtype = subtype.name;
  42481. }
  42482. var length1 = fontFile.dict.get('Length1');
  42483. var length2 = fontFile.dict.get('Length2');
  42484. }
  42485. }
  42486. properties = {
  42487. type: type,
  42488. name: fontName.name,
  42489. subtype: subtype,
  42490. file: fontFile,
  42491. length1: length1,
  42492. length2: length2,
  42493. loadedName: baseDict.loadedName,
  42494. composite: composite,
  42495. wideChars: composite,
  42496. fixedPitch: false,
  42497. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  42498. firstChar: firstChar || 0,
  42499. lastChar: (lastChar || maxCharIndex),
  42500. bbox: descriptor.get('FontBBox'),
  42501. ascent: descriptor.get('Ascent'),
  42502. descent: descriptor.get('Descent'),
  42503. xHeight: descriptor.get('XHeight'),
  42504. capHeight: descriptor.get('CapHeight'),
  42505. flags: descriptor.get('Flags'),
  42506. italicAngle: descriptor.get('ItalicAngle'),
  42507. coded: false
  42508. };
  42509. if (composite) {
  42510. var cidEncoding = baseDict.get('Encoding');
  42511. if (isName(cidEncoding)) {
  42512. properties.cidEncoding = cidEncoding.name;
  42513. }
  42514. properties.cMap = CMapFactory.create(cidEncoding,
  42515. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42516. properties.vertical = properties.cMap.vertical;
  42517. }
  42518. this.extractDataStructures(dict, baseDict, xref, properties);
  42519. this.extractWidths(dict, xref, descriptor, properties);
  42520. if (type === 'Type3') {
  42521. properties.isType3Font = true;
  42522. }
  42523. return new Font(fontName.name, fontFile, properties);
  42524. }
  42525. };
  42526. return PartialEvaluator;
  42527. })();
  42528. var TranslatedFont = (function TranslatedFontClosure() {
  42529. function TranslatedFont(loadedName, font, dict) {
  42530. this.loadedName = loadedName;
  42531. this.font = font;
  42532. this.dict = dict;
  42533. this.type3Loaded = null;
  42534. this.sent = false;
  42535. }
  42536. TranslatedFont.prototype = {
  42537. send: function (handler) {
  42538. if (this.sent) {
  42539. return;
  42540. }
  42541. var fontData = this.font.exportData();
  42542. handler.send('commonobj', [
  42543. this.loadedName,
  42544. 'Font',
  42545. fontData
  42546. ]);
  42547. this.sent = true;
  42548. },
  42549. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  42550. assert(this.font.isType3Font);
  42551. if (this.type3Loaded) {
  42552. return this.type3Loaded;
  42553. }
  42554. var translatedFont = this.font;
  42555. var loadCharProcsPromise = Promise.resolve();
  42556. var charProcs = this.dict.get('CharProcs').getAll();
  42557. var fontResources = this.dict.get('Resources') || resources;
  42558. var charProcKeys = Object.keys(charProcs);
  42559. var charProcOperatorList = {};
  42560. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  42561. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  42562. var glyphStream = charProcs[key];
  42563. var operatorList = new OperatorList();
  42564. return evaluator.getOperatorList(glyphStream, task, fontResources,
  42565. operatorList).then(function () {
  42566. charProcOperatorList[key] = operatorList.getIR();
  42567. // Add the dependencies to the parent operator list so they are
  42568. // resolved before sub operator list is executed synchronously.
  42569. parentOperatorList.addDependencies(operatorList.dependencies);
  42570. }, function (reason) {
  42571. warn('Type3 font resource \"' + key + '\" is not available');
  42572. var operatorList = new OperatorList();
  42573. charProcOperatorList[key] = operatorList.getIR();
  42574. });
  42575. }.bind(this, charProcKeys[i]));
  42576. }
  42577. this.type3Loaded = loadCharProcsPromise.then(function () {
  42578. translatedFont.charProcOperatorList = charProcOperatorList;
  42579. });
  42580. return this.type3Loaded;
  42581. }
  42582. };
  42583. return TranslatedFont;
  42584. })();
  42585. var OperatorList = (function OperatorListClosure() {
  42586. var CHUNK_SIZE = 1000;
  42587. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  42588. function getTransfers(queue) {
  42589. var transfers = [];
  42590. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  42591. for (var i = 0, ii = queue.length; i < ii; i++) {
  42592. switch (fnArray[i]) {
  42593. case OPS.paintInlineImageXObject:
  42594. case OPS.paintInlineImageXObjectGroup:
  42595. case OPS.paintImageMaskXObject:
  42596. var arg = argsArray[i][0]; // first param in imgData
  42597. if (!arg.cached) {
  42598. transfers.push(arg.data.buffer);
  42599. }
  42600. break;
  42601. }
  42602. }
  42603. return transfers;
  42604. }
  42605. function OperatorList(intent, messageHandler, pageIndex) {
  42606. this.messageHandler = messageHandler;
  42607. this.fnArray = [];
  42608. this.argsArray = [];
  42609. this.dependencies = {};
  42610. this._totalLength = 0;
  42611. this.pageIndex = pageIndex;
  42612. this.intent = intent;
  42613. }
  42614. OperatorList.prototype = {
  42615. get length() {
  42616. return this.argsArray.length;
  42617. },
  42618. /**
  42619. * @returns {number} The total length of the entire operator list,
  42620. * since `this.length === 0` after flushing.
  42621. */
  42622. get totalLength() {
  42623. return (this._totalLength + this.length);
  42624. },
  42625. addOp: function(fn, args) {
  42626. this.fnArray.push(fn);
  42627. this.argsArray.push(args);
  42628. if (this.messageHandler) {
  42629. if (this.fnArray.length >= CHUNK_SIZE) {
  42630. this.flush();
  42631. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  42632. (fn === OPS.restore || fn === OPS.endText)) {
  42633. // heuristic to flush on boundary of restore or endText
  42634. this.flush();
  42635. }
  42636. }
  42637. },
  42638. addDependency: function(dependency) {
  42639. if (dependency in this.dependencies) {
  42640. return;
  42641. }
  42642. this.dependencies[dependency] = true;
  42643. this.addOp(OPS.dependency, [dependency]);
  42644. },
  42645. addDependencies: function(dependencies) {
  42646. for (var key in dependencies) {
  42647. this.addDependency(key);
  42648. }
  42649. },
  42650. addOpList: function(opList) {
  42651. Util.extendObj(this.dependencies, opList.dependencies);
  42652. for (var i = 0, ii = opList.length; i < ii; i++) {
  42653. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  42654. }
  42655. },
  42656. getIR: function() {
  42657. return {
  42658. fnArray: this.fnArray,
  42659. argsArray: this.argsArray,
  42660. length: this.length
  42661. };
  42662. },
  42663. flush: function(lastChunk) {
  42664. if (this.intent !== 'oplist') {
  42665. new QueueOptimizer().optimize(this);
  42666. }
  42667. var transfers = getTransfers(this);
  42668. var length = this.length;
  42669. this._totalLength += length;
  42670. this.messageHandler.send('RenderPageChunk', {
  42671. operatorList: {
  42672. fnArray: this.fnArray,
  42673. argsArray: this.argsArray,
  42674. lastChunk: lastChunk,
  42675. length: length
  42676. },
  42677. pageIndex: this.pageIndex,
  42678. intent: this.intent
  42679. }, transfers);
  42680. this.dependencies = {};
  42681. this.fnArray.length = 0;
  42682. this.argsArray.length = 0;
  42683. }
  42684. };
  42685. return OperatorList;
  42686. })();
  42687. var StateManager = (function StateManagerClosure() {
  42688. function StateManager(initialState) {
  42689. this.state = initialState;
  42690. this.stateStack = [];
  42691. }
  42692. StateManager.prototype = {
  42693. save: function () {
  42694. var old = this.state;
  42695. this.stateStack.push(this.state);
  42696. this.state = old.clone();
  42697. },
  42698. restore: function () {
  42699. var prev = this.stateStack.pop();
  42700. if (prev) {
  42701. this.state = prev;
  42702. }
  42703. },
  42704. transform: function (args) {
  42705. this.state.ctm = Util.transform(this.state.ctm, args);
  42706. }
  42707. };
  42708. return StateManager;
  42709. })();
  42710. var TextState = (function TextStateClosure() {
  42711. function TextState() {
  42712. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42713. this.fontSize = 0;
  42714. this.font = null;
  42715. this.fontMatrix = FONT_IDENTITY_MATRIX;
  42716. this.textMatrix = IDENTITY_MATRIX.slice();
  42717. this.textLineMatrix = IDENTITY_MATRIX.slice();
  42718. this.charSpacing = 0;
  42719. this.wordSpacing = 0;
  42720. this.leading = 0;
  42721. this.textHScale = 1;
  42722. this.textRise = 0;
  42723. }
  42724. TextState.prototype = {
  42725. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42726. var m = this.textMatrix;
  42727. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42728. },
  42729. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42730. var m = this.textLineMatrix;
  42731. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42732. },
  42733. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  42734. var m = this.textMatrix;
  42735. m[4] = m[0] * x + m[2] * y + m[4];
  42736. m[5] = m[1] * x + m[3] * y + m[5];
  42737. },
  42738. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  42739. var m = this.textLineMatrix;
  42740. m[4] = m[0] * x + m[2] * y + m[4];
  42741. m[5] = m[1] * x + m[3] * y + m[5];
  42742. },
  42743. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  42744. // 9.4.4 Text Space Details
  42745. var tsm = [this.fontSize * this.textHScale, 0,
  42746. 0, this.fontSize,
  42747. 0, this.textRise];
  42748. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  42749. },
  42750. carriageReturn: function TextState_carriageReturn() {
  42751. this.translateTextLineMatrix(0, -this.leading);
  42752. this.textMatrix = this.textLineMatrix.slice();
  42753. },
  42754. clone: function TextState_clone() {
  42755. var clone = Object.create(this);
  42756. clone.textMatrix = this.textMatrix.slice();
  42757. clone.textLineMatrix = this.textLineMatrix.slice();
  42758. clone.fontMatrix = this.fontMatrix.slice();
  42759. return clone;
  42760. }
  42761. };
  42762. return TextState;
  42763. })();
  42764. var EvalState = (function EvalStateClosure() {
  42765. function EvalState() {
  42766. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42767. this.font = null;
  42768. this.textRenderingMode = TextRenderingMode.FILL;
  42769. this.fillColorSpace = ColorSpace.singletons.gray;
  42770. this.strokeColorSpace = ColorSpace.singletons.gray;
  42771. }
  42772. EvalState.prototype = {
  42773. clone: function CanvasExtraState_clone() {
  42774. return Object.create(this);
  42775. },
  42776. };
  42777. return EvalState;
  42778. })();
  42779. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  42780. // Specifies properties for each command
  42781. //
  42782. // If variableArgs === true: [0, `numArgs`] expected
  42783. // If variableArgs === false: exactly `numArgs` expected
  42784. var OP_MAP = {
  42785. // Graphic state
  42786. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  42787. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  42788. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  42789. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  42790. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  42791. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  42792. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  42793. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  42794. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  42795. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  42796. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  42797. // Path
  42798. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  42799. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  42800. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  42801. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  42802. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  42803. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  42804. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  42805. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  42806. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  42807. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42808. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42809. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  42810. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  42811. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  42812. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  42813. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  42814. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  42815. // Clipping
  42816. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  42817. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  42818. // Text
  42819. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  42820. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  42821. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  42822. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  42823. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  42824. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  42825. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  42826. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  42827. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  42828. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  42829. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  42830. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  42831. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  42832. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  42833. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  42834. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  42835. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  42836. variableArgs: false },
  42837. // Type3 fonts
  42838. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  42839. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  42840. // Color
  42841. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  42842. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  42843. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  42844. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  42845. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  42846. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  42847. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  42848. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  42849. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  42850. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  42851. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  42852. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  42853. // Shading
  42854. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  42855. // Images
  42856. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  42857. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  42858. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  42859. // XObjects
  42860. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  42861. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  42862. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  42863. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  42864. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  42865. variableArgs: false },
  42866. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  42867. // Compatibility
  42868. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  42869. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  42870. // (reserved partial commands for the lexer)
  42871. BM: null,
  42872. BD: null,
  42873. 'true': null,
  42874. fa: null,
  42875. fal: null,
  42876. fals: null,
  42877. 'false': null,
  42878. nu: null,
  42879. nul: null,
  42880. 'null': null
  42881. };
  42882. function EvaluatorPreprocessor(stream, xref, stateManager) {
  42883. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  42884. // dictionary
  42885. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  42886. this.stateManager = stateManager;
  42887. this.nonProcessedArgs = [];
  42888. }
  42889. EvaluatorPreprocessor.prototype = {
  42890. get savedStatesDepth() {
  42891. return this.stateManager.stateStack.length;
  42892. },
  42893. // |operation| is an object with two fields:
  42894. //
  42895. // - |fn| is an out param.
  42896. //
  42897. // - |args| is an inout param. On entry, it should have one of two values.
  42898. //
  42899. // - An empty array. This indicates that the caller is providing the
  42900. // array in which the args will be stored in. The caller should use
  42901. // this value if it can reuse a single array for each call to read().
  42902. //
  42903. // - |null|. This indicates that the caller needs this function to create
  42904. // the array in which any args are stored in. If there are zero args,
  42905. // this function will leave |operation.args| as |null| (thus avoiding
  42906. // allocations that would occur if we used an empty array to represent
  42907. // zero arguments). Otherwise, it will replace |null| with a new array
  42908. // containing the arguments. The caller should use this value if it
  42909. // cannot reuse an array for each call to read().
  42910. //
  42911. // These two modes are present because this function is very hot and so
  42912. // avoiding allocations where possible is worthwhile.
  42913. //
  42914. read: function EvaluatorPreprocessor_read(operation) {
  42915. var args = operation.args;
  42916. while (true) {
  42917. var obj = this.parser.getObj();
  42918. if (isCmd(obj)) {
  42919. var cmd = obj.cmd;
  42920. // Check that the command is valid
  42921. var opSpec = OP_MAP[cmd];
  42922. if (!opSpec) {
  42923. warn('Unknown command "' + cmd + '"');
  42924. continue;
  42925. }
  42926. var fn = opSpec.id;
  42927. var numArgs = opSpec.numArgs;
  42928. var argsLength = args !== null ? args.length : 0;
  42929. if (!opSpec.variableArgs) {
  42930. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  42931. if (argsLength !== numArgs) {
  42932. var nonProcessedArgs = this.nonProcessedArgs;
  42933. while (argsLength > numArgs) {
  42934. nonProcessedArgs.push(args.shift());
  42935. argsLength--;
  42936. }
  42937. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  42938. if (!args) {
  42939. args = [];
  42940. }
  42941. args.unshift(nonProcessedArgs.pop());
  42942. argsLength++;
  42943. }
  42944. }
  42945. if (argsLength < numArgs) {
  42946. // If we receive too few args, it's not possible to possible
  42947. // to execute the command, so skip the command
  42948. info('Command ' + fn + ': because expected ' +
  42949. numArgs + ' args, but received ' + argsLength +
  42950. ' args; skipping');
  42951. args = null;
  42952. continue;
  42953. }
  42954. } else if (argsLength > numArgs) {
  42955. info('Command ' + fn + ': expected [0,' + numArgs +
  42956. '] args, but received ' + argsLength + ' args');
  42957. }
  42958. // TODO figure out how to type-check vararg functions
  42959. this.preprocessCommand(fn, args);
  42960. operation.fn = fn;
  42961. operation.args = args;
  42962. return true;
  42963. } else {
  42964. if (isEOF(obj)) {
  42965. return false; // no more commands
  42966. }
  42967. // argument
  42968. if (obj !== null) {
  42969. if (!args) {
  42970. args = [];
  42971. }
  42972. args.push((obj instanceof Dict ? obj.getAll() : obj));
  42973. assert(args.length <= 33, 'Too many arguments');
  42974. }
  42975. }
  42976. }
  42977. },
  42978. preprocessCommand:
  42979. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  42980. switch (fn | 0) {
  42981. case OPS.save:
  42982. this.stateManager.save();
  42983. break;
  42984. case OPS.restore:
  42985. this.stateManager.restore();
  42986. break;
  42987. case OPS.transform:
  42988. this.stateManager.transform(args);
  42989. break;
  42990. }
  42991. }
  42992. };
  42993. return EvaluatorPreprocessor;
  42994. })();
  42995. var QueueOptimizer = (function QueueOptimizerClosure() {
  42996. function addState(parentState, pattern, fn) {
  42997. var state = parentState;
  42998. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  42999. var item = pattern[i];
  43000. state = (state[item] || (state[item] = []));
  43001. }
  43002. state[pattern[pattern.length - 1]] = fn;
  43003. }
  43004. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  43005. argsArray) {
  43006. // Handles special case of mainly LaTeX documents which use image masks to
  43007. // draw lines with the current fill style.
  43008. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  43009. // have been found at iFirstSave.
  43010. var iFirstPIMXO = iFirstSave + 2;
  43011. for (var i = 0; i < count; i++) {
  43012. var arg = argsArray[iFirstPIMXO + 4 * i];
  43013. var imageMask = arg.length === 1 && arg[0];
  43014. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  43015. (!imageMask.data.length ||
  43016. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  43017. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  43018. continue;
  43019. }
  43020. break;
  43021. }
  43022. return count - i;
  43023. }
  43024. var InitialState = [];
  43025. // This replaces (save, transform, paintInlineImageXObject, restore)+
  43026. // sequences with one |paintInlineImageXObjectGroup| operation.
  43027. addState(InitialState,
  43028. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  43029. function foundInlineImageGroup(context) {
  43030. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  43031. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  43032. var MAX_WIDTH = 1000;
  43033. var IMAGE_PADDING = 1;
  43034. var fnArray = context.fnArray, argsArray = context.argsArray;
  43035. var curr = context.iCurr;
  43036. var iFirstSave = curr - 3;
  43037. var iFirstTransform = curr - 2;
  43038. var iFirstPIIXO = curr - 1;
  43039. // Look for the quartets.
  43040. var i = iFirstSave + 4;
  43041. var ii = fnArray.length;
  43042. while (i + 3 < ii) {
  43043. if (fnArray[i] !== OPS.save ||
  43044. fnArray[i + 1] !== OPS.transform ||
  43045. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  43046. fnArray[i + 3] !== OPS.restore) {
  43047. break; // ops don't match
  43048. }
  43049. i += 4;
  43050. }
  43051. // At this point, i is the index of the first op past the last valid
  43052. // quartet.
  43053. var count = Math.min((i - iFirstSave) / 4,
  43054. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  43055. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  43056. return i;
  43057. }
  43058. // assuming that heights of those image is too small (~1 pixel)
  43059. // packing as much as possible by lines
  43060. var maxX = 0;
  43061. var map = [], maxLineHeight = 0;
  43062. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  43063. var q;
  43064. for (q = 0; q < count; q++) {
  43065. var transform = argsArray[iFirstTransform + (q << 2)];
  43066. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  43067. if (currentX + img.width > MAX_WIDTH) {
  43068. // starting new line
  43069. maxX = Math.max(maxX, currentX);
  43070. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  43071. currentX = 0;
  43072. maxLineHeight = 0;
  43073. }
  43074. map.push({
  43075. transform: transform,
  43076. x: currentX, y: currentY,
  43077. w: img.width, h: img.height
  43078. });
  43079. currentX += img.width + 2 * IMAGE_PADDING;
  43080. maxLineHeight = Math.max(maxLineHeight, img.height);
  43081. }
  43082. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  43083. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  43084. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  43085. var imgRowSize = imgWidth << 2;
  43086. for (q = 0; q < count; q++) {
  43087. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  43088. // Copy image by lines and extends pixels into padding.
  43089. var rowSize = map[q].w << 2;
  43090. var dataOffset = 0;
  43091. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  43092. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  43093. for (var k = 0, kk = map[q].h; k < kk; k++) {
  43094. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  43095. dataOffset += rowSize;
  43096. offset += imgRowSize;
  43097. }
  43098. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  43099. while (offset >= 0) {
  43100. data[offset - 4] = data[offset];
  43101. data[offset - 3] = data[offset + 1];
  43102. data[offset - 2] = data[offset + 2];
  43103. data[offset - 1] = data[offset + 3];
  43104. data[offset + rowSize] = data[offset + rowSize - 4];
  43105. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  43106. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  43107. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  43108. offset -= imgRowSize;
  43109. }
  43110. }
  43111. // Replace queue items.
  43112. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  43113. argsArray.splice(iFirstSave, count * 4,
  43114. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  43115. data: imgData }, map]);
  43116. return iFirstSave + 1;
  43117. });
  43118. // This replaces (save, transform, paintImageMaskXObject, restore)+
  43119. // sequences with one |paintImageMaskXObjectGroup| or one
  43120. // |paintImageMaskXObjectRepeat| operation.
  43121. addState(InitialState,
  43122. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  43123. function foundImageMaskGroup(context) {
  43124. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  43125. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  43126. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  43127. var fnArray = context.fnArray, argsArray = context.argsArray;
  43128. var curr = context.iCurr;
  43129. var iFirstSave = curr - 3;
  43130. var iFirstTransform = curr - 2;
  43131. var iFirstPIMXO = curr - 1;
  43132. // Look for the quartets.
  43133. var i = iFirstSave + 4;
  43134. var ii = fnArray.length;
  43135. while (i + 3 < ii) {
  43136. if (fnArray[i] !== OPS.save ||
  43137. fnArray[i + 1] !== OPS.transform ||
  43138. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  43139. fnArray[i + 3] !== OPS.restore) {
  43140. break; // ops don't match
  43141. }
  43142. i += 4;
  43143. }
  43144. // At this point, i is the index of the first op past the last valid
  43145. // quartet.
  43146. var count = (i - iFirstSave) / 4;
  43147. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  43148. argsArray);
  43149. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  43150. return i;
  43151. }
  43152. var q;
  43153. var isSameImage = false;
  43154. var iTransform, transformArgs;
  43155. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  43156. if (argsArray[iFirstTransform][1] === 0 &&
  43157. argsArray[iFirstTransform][2] === 0) {
  43158. isSameImage = true;
  43159. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43160. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43161. iTransform = iFirstTransform + 4;
  43162. var iPIMXO = iFirstPIMXO + 4;
  43163. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  43164. transformArgs = argsArray[iTransform];
  43165. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  43166. transformArgs[0] !== firstTransformArg0 ||
  43167. transformArgs[1] !== 0 ||
  43168. transformArgs[2] !== 0 ||
  43169. transformArgs[3] !== firstTransformArg3) {
  43170. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  43171. isSameImage = false;
  43172. } else {
  43173. count = q;
  43174. }
  43175. break; // different image or transform
  43176. }
  43177. }
  43178. }
  43179. if (isSameImage) {
  43180. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  43181. var positions = new Float32Array(count * 2);
  43182. iTransform = iFirstTransform;
  43183. for (q = 0; q < count; q++, iTransform += 4) {
  43184. transformArgs = argsArray[iTransform];
  43185. positions[(q << 1)] = transformArgs[4];
  43186. positions[(q << 1) + 1] = transformArgs[5];
  43187. }
  43188. // Replace queue items.
  43189. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  43190. argsArray.splice(iFirstSave, count * 4,
  43191. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  43192. } else {
  43193. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  43194. var images = [];
  43195. for (q = 0; q < count; q++) {
  43196. transformArgs = argsArray[iFirstTransform + (q << 2)];
  43197. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  43198. images.push({ data: maskParams.data, width: maskParams.width,
  43199. height: maskParams.height,
  43200. transform: transformArgs });
  43201. }
  43202. // Replace queue items.
  43203. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  43204. argsArray.splice(iFirstSave, count * 4, [images]);
  43205. }
  43206. return iFirstSave + 1;
  43207. });
  43208. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  43209. // with one paintImageXObjectRepeat operation, if the |transform| and
  43210. // |paintImageXObjectRepeat| ops are appropriate.
  43211. addState(InitialState,
  43212. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  43213. function (context) {
  43214. var MIN_IMAGES_IN_BLOCK = 3;
  43215. var MAX_IMAGES_IN_BLOCK = 1000;
  43216. var fnArray = context.fnArray, argsArray = context.argsArray;
  43217. var curr = context.iCurr;
  43218. var iFirstSave = curr - 3;
  43219. var iFirstTransform = curr - 2;
  43220. var iFirstPIXO = curr - 1;
  43221. var iFirstRestore = curr;
  43222. if (argsArray[iFirstTransform][1] !== 0 ||
  43223. argsArray[iFirstTransform][2] !== 0) {
  43224. return iFirstRestore + 1; // transform has the wrong form
  43225. }
  43226. // Look for the quartets.
  43227. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  43228. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43229. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43230. var i = iFirstSave + 4;
  43231. var ii = fnArray.length;
  43232. while (i + 3 < ii) {
  43233. if (fnArray[i] !== OPS.save ||
  43234. fnArray[i + 1] !== OPS.transform ||
  43235. fnArray[i + 2] !== OPS.paintImageXObject ||
  43236. fnArray[i + 3] !== OPS.restore) {
  43237. break; // ops don't match
  43238. }
  43239. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  43240. argsArray[i + 1][1] !== 0 ||
  43241. argsArray[i + 1][2] !== 0 ||
  43242. argsArray[i + 1][3] !== firstTransformArg3) {
  43243. break; // transforms don't match
  43244. }
  43245. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  43246. break; // images don't match
  43247. }
  43248. i += 4;
  43249. }
  43250. // At this point, i is the index of the first op past the last valid
  43251. // quartet.
  43252. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  43253. if (count < MIN_IMAGES_IN_BLOCK) {
  43254. return i;
  43255. }
  43256. // Extract the (x,y) positions from all of the matching transforms.
  43257. var positions = new Float32Array(count * 2);
  43258. var iTransform = iFirstTransform;
  43259. for (var q = 0; q < count; q++, iTransform += 4) {
  43260. var transformArgs = argsArray[iTransform];
  43261. positions[(q << 1)] = transformArgs[4];
  43262. positions[(q << 1) + 1] = transformArgs[5];
  43263. }
  43264. // Replace queue items.
  43265. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  43266. positions];
  43267. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  43268. argsArray.splice(iFirstSave, count * 4, args);
  43269. return iFirstSave + 1;
  43270. });
  43271. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  43272. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  43273. // sequences, if the font for each one is the same.
  43274. addState(InitialState,
  43275. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  43276. function (context) {
  43277. var MIN_CHARS_IN_BLOCK = 3;
  43278. var MAX_CHARS_IN_BLOCK = 1000;
  43279. var fnArray = context.fnArray, argsArray = context.argsArray;
  43280. var curr = context.iCurr;
  43281. var iFirstBeginText = curr - 4;
  43282. var iFirstSetFont = curr - 3;
  43283. var iFirstSetTextMatrix = curr - 2;
  43284. var iFirstShowText = curr - 1;
  43285. var iFirstEndText = curr;
  43286. // Look for the quintets.
  43287. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  43288. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  43289. var i = iFirstBeginText + 5;
  43290. var ii = fnArray.length;
  43291. while (i + 4 < ii) {
  43292. if (fnArray[i] !== OPS.beginText ||
  43293. fnArray[i + 1] !== OPS.setFont ||
  43294. fnArray[i + 2] !== OPS.setTextMatrix ||
  43295. fnArray[i + 3] !== OPS.showText ||
  43296. fnArray[i + 4] !== OPS.endText) {
  43297. break; // ops don't match
  43298. }
  43299. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  43300. argsArray[i + 1][1] !== firstSetFontArg1) {
  43301. break; // fonts don't match
  43302. }
  43303. i += 5;
  43304. }
  43305. // At this point, i is the index of the first op past the last valid
  43306. // quintet.
  43307. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  43308. if (count < MIN_CHARS_IN_BLOCK) {
  43309. return i;
  43310. }
  43311. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  43312. // showText, endText), include that as well. (E.g. <something> might be
  43313. // |dependency|.)
  43314. var iFirst = iFirstBeginText;
  43315. if (iFirstBeginText >= 4 &&
  43316. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  43317. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  43318. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  43319. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  43320. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  43321. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  43322. count++;
  43323. iFirst -= 5;
  43324. }
  43325. // Remove (endText, beginText, setFont) trios.
  43326. var iEndText = iFirst + 4;
  43327. for (var q = 1; q < count; q++) {
  43328. fnArray.splice(iEndText, 3);
  43329. argsArray.splice(iEndText, 3);
  43330. iEndText += 2;
  43331. }
  43332. return iEndText + 1;
  43333. });
  43334. function QueueOptimizer() {}
  43335. QueueOptimizer.prototype = {
  43336. optimize: function QueueOptimizer_optimize(queue) {
  43337. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43338. var context = {
  43339. iCurr: 0,
  43340. fnArray: fnArray,
  43341. argsArray: argsArray
  43342. };
  43343. var state;
  43344. var i = 0, ii = fnArray.length;
  43345. while (i < ii) {
  43346. state = (state || InitialState)[fnArray[i]];
  43347. if (typeof state === 'function') { // we found some handler
  43348. context.iCurr = i;
  43349. // state() returns the index of the first non-matching op (if we
  43350. // didn't match) or the first op past the modified ops (if we did
  43351. // match and replace).
  43352. i = state(context);
  43353. state = undefined; // reset the state machine
  43354. ii = context.fnArray.length;
  43355. } else {
  43356. i++;
  43357. }
  43358. }
  43359. }
  43360. };
  43361. return QueueOptimizer;
  43362. })();
  43363. exports.OperatorList = OperatorList;
  43364. exports.PartialEvaluator = PartialEvaluator;
  43365. }));
  43366. (function (root, factory) {
  43367. {
  43368. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  43369. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  43370. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  43371. }
  43372. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  43373. coreColorSpace, coreObj, coreEvaluator) {
  43374. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  43375. var AnnotationFlag = sharedUtil.AnnotationFlag;
  43376. var AnnotationType = sharedUtil.AnnotationType;
  43377. var OPS = sharedUtil.OPS;
  43378. var Util = sharedUtil.Util;
  43379. var isArray = sharedUtil.isArray;
  43380. var isInt = sharedUtil.isInt;
  43381. var isValidUrl = sharedUtil.isValidUrl;
  43382. var stringToBytes = sharedUtil.stringToBytes;
  43383. var stringToPDFString = sharedUtil.stringToPDFString;
  43384. var stringToUTF8String = sharedUtil.stringToUTF8String;
  43385. var warn = sharedUtil.warn;
  43386. var Dict = corePrimitives.Dict;
  43387. var isDict = corePrimitives.isDict;
  43388. var isName = corePrimitives.isName;
  43389. var Stream = coreStream.Stream;
  43390. var ColorSpace = coreColorSpace.ColorSpace;
  43391. var ObjectLoader = coreObj.ObjectLoader;
  43392. var OperatorList = coreEvaluator.OperatorList;
  43393. /**
  43394. * @class
  43395. * @alias AnnotationFactory
  43396. */
  43397. function AnnotationFactory() {}
  43398. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  43399. /**
  43400. * @param {XRef} xref
  43401. * @param {Object} ref
  43402. * @returns {Annotation}
  43403. */
  43404. create: function AnnotationFactory_create(xref, ref) {
  43405. var dict = xref.fetchIfRef(ref);
  43406. if (!isDict(dict)) {
  43407. return;
  43408. }
  43409. // Determine the annotation's subtype.
  43410. var subtype = dict.get('Subtype');
  43411. subtype = isName(subtype) ? subtype.name : '';
  43412. // Return the right annotation object based on the subtype and field type.
  43413. var parameters = {
  43414. dict: dict,
  43415. ref: ref
  43416. };
  43417. switch (subtype) {
  43418. case 'Link':
  43419. return new LinkAnnotation(parameters);
  43420. case 'Text':
  43421. return new TextAnnotation(parameters);
  43422. case 'Widget':
  43423. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43424. if (isName(fieldType) && fieldType.name === 'Tx') {
  43425. return new TextWidgetAnnotation(parameters);
  43426. }
  43427. return new WidgetAnnotation(parameters);
  43428. case 'Popup':
  43429. return new PopupAnnotation(parameters);
  43430. case 'Highlight':
  43431. return new HighlightAnnotation(parameters);
  43432. case 'Underline':
  43433. return new UnderlineAnnotation(parameters);
  43434. case 'Squiggly':
  43435. return new SquigglyAnnotation(parameters);
  43436. case 'StrikeOut':
  43437. return new StrikeOutAnnotation(parameters);
  43438. default:
  43439. warn('Unimplemented annotation type "' + subtype + '", ' +
  43440. 'falling back to base annotation');
  43441. return new Annotation(parameters);
  43442. }
  43443. }
  43444. };
  43445. var Annotation = (function AnnotationClosure() {
  43446. // 12.5.5: Algorithm: Appearance streams
  43447. function getTransformMatrix(rect, bbox, matrix) {
  43448. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  43449. var minX = bounds[0];
  43450. var minY = bounds[1];
  43451. var maxX = bounds[2];
  43452. var maxY = bounds[3];
  43453. if (minX === maxX || minY === maxY) {
  43454. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  43455. // just apply the transform for rect
  43456. return [1, 0, 0, 1, rect[0], rect[1]];
  43457. }
  43458. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  43459. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  43460. return [
  43461. xRatio,
  43462. 0,
  43463. 0,
  43464. yRatio,
  43465. rect[0] - minX * xRatio,
  43466. rect[1] - minY * yRatio
  43467. ];
  43468. }
  43469. function getDefaultAppearance(dict) {
  43470. var appearanceState = dict.get('AP');
  43471. if (!isDict(appearanceState)) {
  43472. return;
  43473. }
  43474. var appearance;
  43475. var appearances = appearanceState.get('N');
  43476. if (isDict(appearances)) {
  43477. var as = dict.get('AS');
  43478. if (as && appearances.has(as.name)) {
  43479. appearance = appearances.get(as.name);
  43480. }
  43481. } else {
  43482. appearance = appearances;
  43483. }
  43484. return appearance;
  43485. }
  43486. function Annotation(params) {
  43487. var dict = params.dict;
  43488. this.setFlags(dict.get('F'));
  43489. this.setRectangle(dict.get('Rect'));
  43490. this.setColor(dict.get('C'));
  43491. this.setBorderStyle(dict);
  43492. this.appearance = getDefaultAppearance(dict);
  43493. // Expose public properties using a data object.
  43494. this.data = {};
  43495. this.data.id = params.ref.toString();
  43496. this.data.subtype = dict.get('Subtype').name;
  43497. this.data.annotationFlags = this.flags;
  43498. this.data.rect = this.rectangle;
  43499. this.data.color = this.color;
  43500. this.data.borderStyle = this.borderStyle;
  43501. this.data.hasAppearance = !!this.appearance;
  43502. }
  43503. Annotation.prototype = {
  43504. /**
  43505. * @return {boolean}
  43506. */
  43507. get viewable() {
  43508. if (this.flags) {
  43509. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43510. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  43511. !this.hasFlag(AnnotationFlag.NOVIEW);
  43512. }
  43513. return true;
  43514. },
  43515. /**
  43516. * @return {boolean}
  43517. */
  43518. get printable() {
  43519. if (this.flags) {
  43520. return this.hasFlag(AnnotationFlag.PRINT) &&
  43521. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43522. !this.hasFlag(AnnotationFlag.HIDDEN);
  43523. }
  43524. return false;
  43525. },
  43526. /**
  43527. * Set the flags.
  43528. *
  43529. * @public
  43530. * @memberof Annotation
  43531. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  43532. * characteristics
  43533. * @see {@link shared/util.js}
  43534. */
  43535. setFlags: function Annotation_setFlags(flags) {
  43536. if (isInt(flags)) {
  43537. this.flags = flags;
  43538. } else {
  43539. this.flags = 0;
  43540. }
  43541. },
  43542. /**
  43543. * Check if a provided flag is set.
  43544. *
  43545. * @public
  43546. * @memberof Annotation
  43547. * @param {number} flag - Hexadecimal representation for an annotation
  43548. * characteristic
  43549. * @return {boolean}
  43550. * @see {@link shared/util.js}
  43551. */
  43552. hasFlag: function Annotation_hasFlag(flag) {
  43553. if (this.flags) {
  43554. return (this.flags & flag) > 0;
  43555. }
  43556. return false;
  43557. },
  43558. /**
  43559. * Set the rectangle.
  43560. *
  43561. * @public
  43562. * @memberof Annotation
  43563. * @param {Array} rectangle - The rectangle array with exactly four entries
  43564. */
  43565. setRectangle: function Annotation_setRectangle(rectangle) {
  43566. if (isArray(rectangle) && rectangle.length === 4) {
  43567. this.rectangle = Util.normalizeRect(rectangle);
  43568. } else {
  43569. this.rectangle = [0, 0, 0, 0];
  43570. }
  43571. },
  43572. /**
  43573. * Set the color and take care of color space conversion.
  43574. *
  43575. * @public
  43576. * @memberof Annotation
  43577. * @param {Array} color - The color array containing either 0
  43578. * (transparent), 1 (grayscale), 3 (RGB) or
  43579. * 4 (CMYK) elements
  43580. */
  43581. setColor: function Annotation_setColor(color) {
  43582. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  43583. if (!isArray(color)) {
  43584. this.color = rgbColor;
  43585. return;
  43586. }
  43587. switch (color.length) {
  43588. case 0: // Transparent, which we indicate with a null value
  43589. this.color = null;
  43590. break;
  43591. case 1: // Convert grayscale to RGB
  43592. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  43593. this.color = rgbColor;
  43594. break;
  43595. case 3: // Convert RGB percentages to RGB
  43596. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  43597. this.color = rgbColor;
  43598. break;
  43599. case 4: // Convert CMYK to RGB
  43600. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  43601. this.color = rgbColor;
  43602. break;
  43603. default:
  43604. this.color = rgbColor;
  43605. break;
  43606. }
  43607. },
  43608. /**
  43609. * Set the border style (as AnnotationBorderStyle object).
  43610. *
  43611. * @public
  43612. * @memberof Annotation
  43613. * @param {Dict} borderStyle - The border style dictionary
  43614. */
  43615. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  43616. this.borderStyle = new AnnotationBorderStyle();
  43617. if (!isDict(borderStyle)) {
  43618. return;
  43619. }
  43620. if (borderStyle.has('BS')) {
  43621. var dict = borderStyle.get('BS');
  43622. var dictType;
  43623. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  43624. dictType.name === 'Border')) {
  43625. this.borderStyle.setWidth(dict.get('W'));
  43626. this.borderStyle.setStyle(dict.get('S'));
  43627. this.borderStyle.setDashArray(dict.get('D'));
  43628. }
  43629. } else if (borderStyle.has('Border')) {
  43630. var array = borderStyle.get('Border');
  43631. if (isArray(array) && array.length >= 3) {
  43632. this.borderStyle.setHorizontalCornerRadius(array[0]);
  43633. this.borderStyle.setVerticalCornerRadius(array[1]);
  43634. this.borderStyle.setWidth(array[2]);
  43635. if (array.length === 4) { // Dash array available
  43636. this.borderStyle.setDashArray(array[3]);
  43637. }
  43638. }
  43639. } else {
  43640. // There are no border entries in the dictionary. According to the
  43641. // specification, we should draw a solid border of width 1 in that
  43642. // case, but Adobe Reader did not implement that part of the
  43643. // specification and instead draws no border at all, so we do the same.
  43644. // See also https://github.com/mozilla/pdf.js/issues/6179.
  43645. this.borderStyle.setWidth(0);
  43646. }
  43647. },
  43648. loadResources: function Annotation_loadResources(keys) {
  43649. return new Promise(function (resolve, reject) {
  43650. this.appearance.dict.getAsync('Resources').then(function (resources) {
  43651. if (!resources) {
  43652. resolve();
  43653. return;
  43654. }
  43655. var objectLoader = new ObjectLoader(resources.map,
  43656. keys,
  43657. resources.xref);
  43658. objectLoader.load().then(function() {
  43659. resolve(resources);
  43660. }, reject);
  43661. }, reject);
  43662. }.bind(this));
  43663. },
  43664. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  43665. if (!this.appearance) {
  43666. return Promise.resolve(new OperatorList());
  43667. }
  43668. var data = this.data;
  43669. var appearanceDict = this.appearance.dict;
  43670. var resourcesPromise = this.loadResources([
  43671. 'ExtGState',
  43672. 'ColorSpace',
  43673. 'Pattern',
  43674. 'Shading',
  43675. 'XObject',
  43676. 'Font'
  43677. // ProcSet
  43678. // Properties
  43679. ]);
  43680. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  43681. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  43682. var transform = getTransformMatrix(data.rect, bbox, matrix);
  43683. var self = this;
  43684. return resourcesPromise.then(function(resources) {
  43685. var opList = new OperatorList();
  43686. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  43687. return evaluator.getOperatorList(self.appearance, task,
  43688. resources, opList).
  43689. then(function () {
  43690. opList.addOp(OPS.endAnnotation, []);
  43691. self.appearance.reset();
  43692. return opList;
  43693. });
  43694. });
  43695. }
  43696. };
  43697. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  43698. annotations, opList, partialEvaluator, task, intent) {
  43699. var annotationPromises = [];
  43700. for (var i = 0, n = annotations.length; i < n; ++i) {
  43701. if ((intent === 'display' && annotations[i].viewable) ||
  43702. (intent === 'print' && annotations[i].printable)) {
  43703. annotationPromises.push(
  43704. annotations[i].getOperatorList(partialEvaluator, task));
  43705. }
  43706. }
  43707. return Promise.all(annotationPromises).then(function(operatorLists) {
  43708. opList.addOp(OPS.beginAnnotations, []);
  43709. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  43710. opList.addOpList(operatorLists[i]);
  43711. }
  43712. opList.addOp(OPS.endAnnotations, []);
  43713. });
  43714. };
  43715. return Annotation;
  43716. })();
  43717. /**
  43718. * Contains all data regarding an annotation's border style.
  43719. *
  43720. * @class
  43721. */
  43722. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  43723. /**
  43724. * @constructor
  43725. * @private
  43726. */
  43727. function AnnotationBorderStyle() {
  43728. this.width = 1;
  43729. this.style = AnnotationBorderStyleType.SOLID;
  43730. this.dashArray = [3];
  43731. this.horizontalCornerRadius = 0;
  43732. this.verticalCornerRadius = 0;
  43733. }
  43734. AnnotationBorderStyle.prototype = {
  43735. /**
  43736. * Set the width.
  43737. *
  43738. * @public
  43739. * @memberof AnnotationBorderStyle
  43740. * @param {integer} width - The width
  43741. */
  43742. setWidth: function AnnotationBorderStyle_setWidth(width) {
  43743. if (width === (width | 0)) {
  43744. this.width = width;
  43745. }
  43746. },
  43747. /**
  43748. * Set the style.
  43749. *
  43750. * @public
  43751. * @memberof AnnotationBorderStyle
  43752. * @param {Object} style - The style object
  43753. * @see {@link shared/util.js}
  43754. */
  43755. setStyle: function AnnotationBorderStyle_setStyle(style) {
  43756. if (!style) {
  43757. return;
  43758. }
  43759. switch (style.name) {
  43760. case 'S':
  43761. this.style = AnnotationBorderStyleType.SOLID;
  43762. break;
  43763. case 'D':
  43764. this.style = AnnotationBorderStyleType.DASHED;
  43765. break;
  43766. case 'B':
  43767. this.style = AnnotationBorderStyleType.BEVELED;
  43768. break;
  43769. case 'I':
  43770. this.style = AnnotationBorderStyleType.INSET;
  43771. break;
  43772. case 'U':
  43773. this.style = AnnotationBorderStyleType.UNDERLINE;
  43774. break;
  43775. default:
  43776. break;
  43777. }
  43778. },
  43779. /**
  43780. * Set the dash array.
  43781. *
  43782. * @public
  43783. * @memberof AnnotationBorderStyle
  43784. * @param {Array} dashArray - The dash array with at least one element
  43785. */
  43786. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  43787. // We validate the dash array, but we do not use it because CSS does not
  43788. // allow us to change spacing of dashes. For more information, visit
  43789. // http://www.w3.org/TR/css3-background/#the-border-style.
  43790. if (isArray(dashArray) && dashArray.length > 0) {
  43791. // According to the PDF specification: the elements in a dashArray
  43792. // shall be numbers that are nonnegative and not all equal to zero.
  43793. var isValid = true;
  43794. var allZeros = true;
  43795. for (var i = 0, len = dashArray.length; i < len; i++) {
  43796. var element = dashArray[i];
  43797. var validNumber = (+element >= 0);
  43798. if (!validNumber) {
  43799. isValid = false;
  43800. break;
  43801. } else if (element > 0) {
  43802. allZeros = false;
  43803. }
  43804. }
  43805. if (isValid && !allZeros) {
  43806. this.dashArray = dashArray;
  43807. } else {
  43808. this.width = 0; // Adobe behavior when the array is invalid.
  43809. }
  43810. } else if (dashArray) {
  43811. this.width = 0; // Adobe behavior when the array is invalid.
  43812. }
  43813. },
  43814. /**
  43815. * Set the horizontal corner radius (from a Border dictionary).
  43816. *
  43817. * @public
  43818. * @memberof AnnotationBorderStyle
  43819. * @param {integer} radius - The horizontal corner radius
  43820. */
  43821. setHorizontalCornerRadius:
  43822. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  43823. if (radius === (radius | 0)) {
  43824. this.horizontalCornerRadius = radius;
  43825. }
  43826. },
  43827. /**
  43828. * Set the vertical corner radius (from a Border dictionary).
  43829. *
  43830. * @public
  43831. * @memberof AnnotationBorderStyle
  43832. * @param {integer} radius - The vertical corner radius
  43833. */
  43834. setVerticalCornerRadius:
  43835. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  43836. if (radius === (radius | 0)) {
  43837. this.verticalCornerRadius = radius;
  43838. }
  43839. }
  43840. };
  43841. return AnnotationBorderStyle;
  43842. })();
  43843. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  43844. function WidgetAnnotation(params) {
  43845. Annotation.call(this, params);
  43846. var dict = params.dict;
  43847. var data = this.data;
  43848. data.annotationType = AnnotationType.WIDGET;
  43849. data.fieldValue = stringToPDFString(
  43850. Util.getInheritableProperty(dict, 'V') || '');
  43851. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  43852. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  43853. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43854. data.fieldType = isName(fieldType) ? fieldType.name : '';
  43855. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  43856. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  43857. // Hide unsupported Widget signatures.
  43858. if (data.fieldType === 'Sig') {
  43859. warn('unimplemented annotation type: Widget signature');
  43860. this.setFlags(AnnotationFlag.HIDDEN);
  43861. }
  43862. // Building the full field name by collecting the field and
  43863. // its ancestors 'T' data and joining them using '.'.
  43864. var fieldName = [];
  43865. var namedItem = dict;
  43866. var ref = params.ref;
  43867. while (namedItem) {
  43868. var parent = namedItem.get('Parent');
  43869. var parentRef = namedItem.getRaw('Parent');
  43870. var name = namedItem.get('T');
  43871. if (name) {
  43872. fieldName.unshift(stringToPDFString(name));
  43873. } else if (parent && ref) {
  43874. // The field name is absent, that means more than one field
  43875. // with the same name may exist. Replacing the empty name
  43876. // with the '`' plus index in the parent's 'Kids' array.
  43877. // This is not in the PDF spec but necessary to id the
  43878. // the input controls.
  43879. var kids = parent.get('Kids');
  43880. var j, jj;
  43881. for (j = 0, jj = kids.length; j < jj; j++) {
  43882. var kidRef = kids[j];
  43883. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  43884. break;
  43885. }
  43886. }
  43887. fieldName.unshift('`' + j);
  43888. }
  43889. namedItem = parent;
  43890. ref = parentRef;
  43891. }
  43892. data.fullName = fieldName.join('.');
  43893. }
  43894. Util.inherit(WidgetAnnotation, Annotation, {});
  43895. return WidgetAnnotation;
  43896. })();
  43897. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  43898. function TextWidgetAnnotation(params) {
  43899. WidgetAnnotation.call(this, params);
  43900. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  43901. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  43902. }
  43903. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  43904. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  43905. task) {
  43906. if (this.appearance) {
  43907. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  43908. }
  43909. var opList = new OperatorList();
  43910. var data = this.data;
  43911. // Even if there is an appearance stream, ignore it. This is the
  43912. // behaviour used by Adobe Reader.
  43913. if (!data.defaultAppearance) {
  43914. return Promise.resolve(opList);
  43915. }
  43916. var stream = new Stream(stringToBytes(data.defaultAppearance));
  43917. return evaluator.getOperatorList(stream, task,
  43918. this.fieldResources, opList).
  43919. then(function () {
  43920. return opList;
  43921. });
  43922. }
  43923. });
  43924. return TextWidgetAnnotation;
  43925. })();
  43926. var TextAnnotation = (function TextAnnotationClosure() {
  43927. var DEFAULT_ICON_SIZE = 22; // px
  43928. function TextAnnotation(parameters) {
  43929. Annotation.call(this, parameters);
  43930. this.data.annotationType = AnnotationType.TEXT;
  43931. this.data.hasHtml = true;
  43932. var dict = parameters.dict;
  43933. if (this.data.hasAppearance) {
  43934. this.data.name = 'NoIcon';
  43935. } else {
  43936. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  43937. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  43938. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  43939. }
  43940. if (!dict.has('C')) {
  43941. // Fall back to the default background color.
  43942. this.data.color = null;
  43943. }
  43944. this.data.hasPopup = dict.has('Popup');
  43945. if (!this.data.hasPopup) {
  43946. // There is no associated Popup annotation, so the Text annotation
  43947. // must create its own popup.
  43948. this.data.title = stringToPDFString(dict.get('T') || '');
  43949. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  43950. this.data.hasHtml = (this.data.title || this.data.contents);
  43951. }
  43952. }
  43953. Util.inherit(TextAnnotation, Annotation, {});
  43954. return TextAnnotation;
  43955. })();
  43956. var LinkAnnotation = (function LinkAnnotationClosure() {
  43957. function LinkAnnotation(params) {
  43958. Annotation.call(this, params);
  43959. var dict = params.dict;
  43960. var data = this.data;
  43961. data.annotationType = AnnotationType.LINK;
  43962. data.hasHtml = true;
  43963. var action = dict.get('A');
  43964. if (action && isDict(action)) {
  43965. var linkType = action.get('S').name;
  43966. if (linkType === 'URI') {
  43967. var url = action.get('URI');
  43968. if (isName(url)) {
  43969. // Some bad PDFs do not put parentheses around relative URLs.
  43970. url = '/' + url.name;
  43971. } else if (url) {
  43972. url = addDefaultProtocolToUrl(url);
  43973. }
  43974. // TODO: pdf spec mentions urls can be relative to a Base
  43975. // entry in the dictionary.
  43976. if (!isValidUrl(url, false)) {
  43977. url = '';
  43978. }
  43979. // According to ISO 32000-1:2008, section 12.6.4.7,
  43980. // URI should to be encoded in 7-bit ASCII.
  43981. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  43982. try {
  43983. data.url = stringToUTF8String(url);
  43984. } catch (e) {
  43985. // Fall back to a simple copy.
  43986. data.url = url;
  43987. }
  43988. } else if (linkType === 'GoTo') {
  43989. data.dest = action.get('D');
  43990. } else if (linkType === 'GoToR') {
  43991. var urlDict = action.get('F');
  43992. if (isDict(urlDict)) {
  43993. // We assume that the 'url' is a Filspec dictionary
  43994. // and fetch the url without checking any further
  43995. url = urlDict.get('F') || '';
  43996. }
  43997. // TODO: pdf reference says that GoToR
  43998. // can also have 'NewWindow' attribute
  43999. if (!isValidUrl(url, false)) {
  44000. url = '';
  44001. }
  44002. data.url = url;
  44003. data.dest = action.get('D');
  44004. } else if (linkType === 'Named') {
  44005. data.action = action.get('N').name;
  44006. } else {
  44007. warn('unrecognized link type: ' + linkType);
  44008. }
  44009. } else if (dict.has('Dest')) {
  44010. // simple destination link
  44011. var dest = dict.get('Dest');
  44012. data.dest = isName(dest) ? dest.name : dest;
  44013. }
  44014. }
  44015. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  44016. function addDefaultProtocolToUrl(url) {
  44017. if (url && url.indexOf('www.') === 0) {
  44018. return ('http://' + url);
  44019. }
  44020. return url;
  44021. }
  44022. Util.inherit(LinkAnnotation, Annotation, {});
  44023. return LinkAnnotation;
  44024. })();
  44025. var PopupAnnotation = (function PopupAnnotationClosure() {
  44026. function PopupAnnotation(parameters) {
  44027. Annotation.call(this, parameters);
  44028. this.data.annotationType = AnnotationType.POPUP;
  44029. var dict = parameters.dict;
  44030. var parentItem = dict.get('Parent');
  44031. if (!parentItem) {
  44032. warn('Popup annotation has a missing or invalid parent annotation.');
  44033. return;
  44034. }
  44035. this.data.parentId = dict.getRaw('Parent').toString();
  44036. this.data.title = stringToPDFString(parentItem.get('T') || '');
  44037. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  44038. if (!parentItem.has('C')) {
  44039. // Fall back to the default background color.
  44040. this.data.color = null;
  44041. } else {
  44042. this.setColor(parentItem.get('C'));
  44043. this.data.color = this.color;
  44044. }
  44045. this.data.hasHtml = (this.data.title || this.data.contents);
  44046. }
  44047. Util.inherit(PopupAnnotation, Annotation, {});
  44048. return PopupAnnotation;
  44049. })();
  44050. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  44051. function HighlightAnnotation(parameters) {
  44052. Annotation.call(this, parameters);
  44053. this.data.annotationType = AnnotationType.HIGHLIGHT;
  44054. this.data.hasHtml = true;
  44055. // PDF viewers completely ignore any border styles.
  44056. this.data.borderStyle.setWidth(0);
  44057. }
  44058. Util.inherit(HighlightAnnotation, Annotation, {});
  44059. return HighlightAnnotation;
  44060. })();
  44061. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  44062. function UnderlineAnnotation(parameters) {
  44063. Annotation.call(this, parameters);
  44064. this.data.annotationType = AnnotationType.UNDERLINE;
  44065. this.data.hasHtml = true;
  44066. // PDF viewers completely ignore any border styles.
  44067. this.data.borderStyle.setWidth(0);
  44068. }
  44069. Util.inherit(UnderlineAnnotation, Annotation, {});
  44070. return UnderlineAnnotation;
  44071. })();
  44072. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  44073. function SquigglyAnnotation(parameters) {
  44074. Annotation.call(this, parameters);
  44075. this.data.annotationType = AnnotationType.SQUIGGLY;
  44076. this.data.hasHtml = true;
  44077. // PDF viewers completely ignore any border styles.
  44078. this.data.borderStyle.setWidth(0);
  44079. }
  44080. Util.inherit(SquigglyAnnotation, Annotation, {});
  44081. return SquigglyAnnotation;
  44082. })();
  44083. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  44084. function StrikeOutAnnotation(parameters) {
  44085. Annotation.call(this, parameters);
  44086. this.data.annotationType = AnnotationType.STRIKEOUT;
  44087. this.data.hasHtml = true;
  44088. // PDF viewers completely ignore any border styles.
  44089. this.data.borderStyle.setWidth(0);
  44090. }
  44091. Util.inherit(StrikeOutAnnotation, Annotation, {});
  44092. return StrikeOutAnnotation;
  44093. })();
  44094. exports.Annotation = Annotation;
  44095. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  44096. exports.AnnotationFactory = AnnotationFactory;
  44097. }));
  44098. (function (root, factory) {
  44099. {
  44100. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  44101. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  44102. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  44103. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  44104. }
  44105. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  44106. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  44107. var MissingDataException = sharedUtil.MissingDataException;
  44108. var Util = sharedUtil.Util;
  44109. var assert = sharedUtil.assert;
  44110. var error = sharedUtil.error;
  44111. var info = sharedUtil.info;
  44112. var isArray = sharedUtil.isArray;
  44113. var isArrayBuffer = sharedUtil.isArrayBuffer;
  44114. var isString = sharedUtil.isString;
  44115. var shadow = sharedUtil.shadow;
  44116. var stringToBytes = sharedUtil.stringToBytes;
  44117. var stringToPDFString = sharedUtil.stringToPDFString;
  44118. var warn = sharedUtil.warn;
  44119. var Dict = corePrimitives.Dict;
  44120. var isDict = corePrimitives.isDict;
  44121. var isName = corePrimitives.isName;
  44122. var isStream = corePrimitives.isStream;
  44123. var NullStream = coreStream.NullStream;
  44124. var Stream = coreStream.Stream;
  44125. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  44126. var Catalog = coreObj.Catalog;
  44127. var ObjectLoader = coreObj.ObjectLoader;
  44128. var XRef = coreObj.XRef;
  44129. var Lexer = coreParser.Lexer;
  44130. var Linearization = coreParser.Linearization;
  44131. var calculateMD5 = coreCrypto.calculateMD5;
  44132. var OperatorList = coreEvaluator.OperatorList;
  44133. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  44134. var Annotation = coreAnnotation.Annotation;
  44135. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  44136. var Page = (function PageClosure() {
  44137. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  44138. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  44139. this.pdfManager = pdfManager;
  44140. this.pageIndex = pageIndex;
  44141. this.pageDict = pageDict;
  44142. this.xref = xref;
  44143. this.ref = ref;
  44144. this.fontCache = fontCache;
  44145. this.idCounters = {
  44146. obj: 0
  44147. };
  44148. this.resourcesPromise = null;
  44149. }
  44150. Page.prototype = {
  44151. getPageProp: function Page_getPageProp(key) {
  44152. return this.pageDict.get(key);
  44153. },
  44154. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  44155. var dict = this.pageDict, valueArray = null, loopCount = 0;
  44156. var MAX_LOOP_COUNT = 100;
  44157. // Always walk up the entire parent chain, to be able to find
  44158. // e.g. \Resources placed on multiple levels of the tree.
  44159. while (dict) {
  44160. var value = dict.get(key);
  44161. if (value) {
  44162. if (!valueArray) {
  44163. valueArray = [];
  44164. }
  44165. valueArray.push(value);
  44166. }
  44167. if (++loopCount > MAX_LOOP_COUNT) {
  44168. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  44169. break;
  44170. }
  44171. dict = dict.get('Parent');
  44172. }
  44173. if (!valueArray) {
  44174. return Dict.empty;
  44175. }
  44176. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  44177. loopCount > MAX_LOOP_COUNT) {
  44178. return valueArray[0];
  44179. }
  44180. return Dict.merge(this.xref, valueArray);
  44181. },
  44182. get content() {
  44183. return this.getPageProp('Contents');
  44184. },
  44185. get resources() {
  44186. // For robustness: The spec states that a \Resources entry has to be
  44187. // present, but can be empty. Some document omit it still, in this case
  44188. // we return an empty dictionary.
  44189. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  44190. },
  44191. get mediaBox() {
  44192. var obj = this.getInheritedPageProp('MediaBox');
  44193. // Reset invalid media box to letter size.
  44194. if (!isArray(obj) || obj.length !== 4) {
  44195. obj = LETTER_SIZE_MEDIABOX;
  44196. }
  44197. return shadow(this, 'mediaBox', obj);
  44198. },
  44199. get view() {
  44200. var mediaBox = this.mediaBox;
  44201. var cropBox = this.getInheritedPageProp('CropBox');
  44202. if (!isArray(cropBox) || cropBox.length !== 4) {
  44203. return shadow(this, 'view', mediaBox);
  44204. }
  44205. // From the spec, 6th ed., p.963:
  44206. // "The crop, bleed, trim, and art boxes should not ordinarily
  44207. // extend beyond the boundaries of the media box. If they do, they are
  44208. // effectively reduced to their intersection with the media box."
  44209. cropBox = Util.intersect(cropBox, mediaBox);
  44210. if (!cropBox) {
  44211. return shadow(this, 'view', mediaBox);
  44212. }
  44213. return shadow(this, 'view', cropBox);
  44214. },
  44215. get rotate() {
  44216. var rotate = this.getInheritedPageProp('Rotate') || 0;
  44217. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  44218. if (rotate % 90 !== 0) {
  44219. rotate = 0;
  44220. } else if (rotate >= 360) {
  44221. rotate = rotate % 360;
  44222. } else if (rotate < 0) {
  44223. // The spec doesn't cover negatives, assume its counterclockwise
  44224. // rotation. The following is the other implementation of modulo.
  44225. rotate = ((rotate % 360) + 360) % 360;
  44226. }
  44227. return shadow(this, 'rotate', rotate);
  44228. },
  44229. getContentStream: function Page_getContentStream() {
  44230. var content = this.content;
  44231. var stream;
  44232. if (isArray(content)) {
  44233. // fetching items
  44234. var xref = this.xref;
  44235. var i, n = content.length;
  44236. var streams = [];
  44237. for (i = 0; i < n; ++i) {
  44238. streams.push(xref.fetchIfRef(content[i]));
  44239. }
  44240. stream = new StreamsSequenceStream(streams);
  44241. } else if (isStream(content)) {
  44242. stream = content;
  44243. } else {
  44244. // replacing non-existent page content with empty one
  44245. stream = new NullStream();
  44246. }
  44247. return stream;
  44248. },
  44249. loadResources: function Page_loadResources(keys) {
  44250. if (!this.resourcesPromise) {
  44251. // TODO: add async getInheritedPageProp and remove this.
  44252. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  44253. }
  44254. return this.resourcesPromise.then(function resourceSuccess() {
  44255. var objectLoader = new ObjectLoader(this.resources.map,
  44256. keys,
  44257. this.xref);
  44258. return objectLoader.load();
  44259. }.bind(this));
  44260. },
  44261. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  44262. var self = this;
  44263. var pdfManager = this.pdfManager;
  44264. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44265. []);
  44266. var resourcesPromise = this.loadResources([
  44267. 'ExtGState',
  44268. 'ColorSpace',
  44269. 'Pattern',
  44270. 'Shading',
  44271. 'XObject',
  44272. 'Font'
  44273. // ProcSet
  44274. // Properties
  44275. ]);
  44276. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  44277. handler, this.pageIndex,
  44278. 'p' + this.pageIndex + '_',
  44279. this.idCounters,
  44280. this.fontCache);
  44281. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  44282. var pageListPromise = dataPromises.then(function(data) {
  44283. var contentStream = data[0];
  44284. var opList = new OperatorList(intent, handler, self.pageIndex);
  44285. handler.send('StartRenderPage', {
  44286. transparency: partialEvaluator.hasBlendModes(self.resources),
  44287. pageIndex: self.pageIndex,
  44288. intent: intent
  44289. });
  44290. return partialEvaluator.getOperatorList(contentStream, task,
  44291. self.resources, opList).then(function () {
  44292. return opList;
  44293. });
  44294. });
  44295. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  44296. return Promise.all([pageListPromise, annotationsPromise]).then(
  44297. function(datas) {
  44298. var pageOpList = datas[0];
  44299. var annotations = datas[1];
  44300. if (annotations.length === 0) {
  44301. pageOpList.flush(true);
  44302. return pageOpList;
  44303. }
  44304. var annotationsReadyPromise = Annotation.appendToOperatorList(
  44305. annotations, pageOpList, partialEvaluator, task, intent);
  44306. return annotationsReadyPromise.then(function () {
  44307. pageOpList.flush(true);
  44308. return pageOpList;
  44309. });
  44310. });
  44311. },
  44312. extractTextContent: function Page_extractTextContent(task,
  44313. normalizeWhitespace) {
  44314. var handler = {
  44315. on: function nullHandlerOn() {},
  44316. send: function nullHandlerSend() {}
  44317. };
  44318. var self = this;
  44319. var pdfManager = this.pdfManager;
  44320. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44321. []);
  44322. var resourcesPromise = this.loadResources([
  44323. 'ExtGState',
  44324. 'XObject',
  44325. 'Font'
  44326. ]);
  44327. var dataPromises = Promise.all([contentStreamPromise,
  44328. resourcesPromise]);
  44329. return dataPromises.then(function(data) {
  44330. var contentStream = data[0];
  44331. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  44332. handler, self.pageIndex,
  44333. 'p' + self.pageIndex + '_',
  44334. self.idCounters,
  44335. self.fontCache);
  44336. return partialEvaluator.getTextContent(contentStream,
  44337. task,
  44338. self.resources,
  44339. /* stateManager = */ null,
  44340. normalizeWhitespace);
  44341. });
  44342. },
  44343. getAnnotationsData: function Page_getAnnotationsData(intent) {
  44344. var annotations = this.annotations;
  44345. var annotationsData = [];
  44346. for (var i = 0, n = annotations.length; i < n; ++i) {
  44347. if (intent) {
  44348. if (!(intent === 'display' && annotations[i].viewable) &&
  44349. !(intent === 'print' && annotations[i].printable)) {
  44350. continue;
  44351. }
  44352. }
  44353. annotationsData.push(annotations[i].data);
  44354. }
  44355. return annotationsData;
  44356. },
  44357. get annotations() {
  44358. var annotations = [];
  44359. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  44360. var annotationFactory = new AnnotationFactory();
  44361. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  44362. var annotationRef = annotationRefs[i];
  44363. var annotation = annotationFactory.create(this.xref, annotationRef);
  44364. if (annotation) {
  44365. annotations.push(annotation);
  44366. }
  44367. }
  44368. return shadow(this, 'annotations', annotations);
  44369. }
  44370. };
  44371. return Page;
  44372. })();
  44373. /**
  44374. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  44375. * `PDFDoc`, this one doesn't have any job management code.
  44376. * Right now there exists one PDFDocument on the main thread + one object
  44377. * for each worker. If there is no worker support enabled, there are two
  44378. * `PDFDocument` objects on the main thread created.
  44379. */
  44380. var PDFDocument = (function PDFDocumentClosure() {
  44381. var FINGERPRINT_FIRST_BYTES = 1024;
  44382. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  44383. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  44384. function PDFDocument(pdfManager, arg, password) {
  44385. if (isStream(arg)) {
  44386. init.call(this, pdfManager, arg, password);
  44387. } else if (isArrayBuffer(arg)) {
  44388. init.call(this, pdfManager, new Stream(arg), password);
  44389. } else {
  44390. error('PDFDocument: Unknown argument type');
  44391. }
  44392. }
  44393. function init(pdfManager, stream, password) {
  44394. assert(stream.length > 0, 'stream must have data');
  44395. this.pdfManager = pdfManager;
  44396. this.stream = stream;
  44397. var xref = new XRef(this.stream, password, pdfManager);
  44398. this.xref = xref;
  44399. }
  44400. function find(stream, needle, limit, backwards) {
  44401. var pos = stream.pos;
  44402. var end = stream.end;
  44403. var strBuf = [];
  44404. if (pos + limit > end) {
  44405. limit = end - pos;
  44406. }
  44407. for (var n = 0; n < limit; ++n) {
  44408. strBuf.push(String.fromCharCode(stream.getByte()));
  44409. }
  44410. var str = strBuf.join('');
  44411. stream.pos = pos;
  44412. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  44413. if (index === -1) {
  44414. return false; /* not found */
  44415. }
  44416. stream.pos += index;
  44417. return true; /* found */
  44418. }
  44419. var DocumentInfoValidators = {
  44420. get entries() {
  44421. // Lazily build this since all the validation functions below are not
  44422. // defined until after this file loads.
  44423. return shadow(this, 'entries', {
  44424. Title: isString,
  44425. Author: isString,
  44426. Subject: isString,
  44427. Keywords: isString,
  44428. Creator: isString,
  44429. Producer: isString,
  44430. CreationDate: isString,
  44431. ModDate: isString,
  44432. Trapped: isName
  44433. });
  44434. }
  44435. };
  44436. PDFDocument.prototype = {
  44437. parse: function PDFDocument_parse(recoveryMode) {
  44438. this.setup(recoveryMode);
  44439. var version = this.catalog.catDict.get('Version');
  44440. if (isName(version)) {
  44441. this.pdfFormatVersion = version.name;
  44442. }
  44443. try {
  44444. // checking if AcroForm is present
  44445. this.acroForm = this.catalog.catDict.get('AcroForm');
  44446. if (this.acroForm) {
  44447. this.xfa = this.acroForm.get('XFA');
  44448. var fields = this.acroForm.get('Fields');
  44449. if ((!fields || !isArray(fields) || fields.length === 0) &&
  44450. !this.xfa) {
  44451. // no fields and no XFA -- not a form (?)
  44452. this.acroForm = null;
  44453. }
  44454. }
  44455. } catch (ex) {
  44456. info('Something wrong with AcroForm entry');
  44457. this.acroForm = null;
  44458. }
  44459. },
  44460. get linearization() {
  44461. var linearization = null;
  44462. if (this.stream.length) {
  44463. try {
  44464. linearization = Linearization.create(this.stream);
  44465. } catch (err) {
  44466. if (err instanceof MissingDataException) {
  44467. throw err;
  44468. }
  44469. info(err);
  44470. }
  44471. }
  44472. // shadow the prototype getter with a data property
  44473. return shadow(this, 'linearization', linearization);
  44474. },
  44475. get startXRef() {
  44476. var stream = this.stream;
  44477. var startXRef = 0;
  44478. var linearization = this.linearization;
  44479. if (linearization) {
  44480. // Find end of first obj.
  44481. stream.reset();
  44482. if (find(stream, 'endobj', 1024)) {
  44483. startXRef = stream.pos + 6;
  44484. }
  44485. } else {
  44486. // Find startxref by jumping backward from the end of the file.
  44487. var step = 1024;
  44488. var found = false, pos = stream.end;
  44489. while (!found && pos > 0) {
  44490. pos -= step - 'startxref'.length;
  44491. if (pos < 0) {
  44492. pos = 0;
  44493. }
  44494. stream.pos = pos;
  44495. found = find(stream, 'startxref', step, true);
  44496. }
  44497. if (found) {
  44498. stream.skip(9);
  44499. var ch;
  44500. do {
  44501. ch = stream.getByte();
  44502. } while (Lexer.isSpace(ch));
  44503. var str = '';
  44504. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  44505. str += String.fromCharCode(ch);
  44506. ch = stream.getByte();
  44507. }
  44508. startXRef = parseInt(str, 10);
  44509. if (isNaN(startXRef)) {
  44510. startXRef = 0;
  44511. }
  44512. }
  44513. }
  44514. // shadow the prototype getter with a data property
  44515. return shadow(this, 'startXRef', startXRef);
  44516. },
  44517. get mainXRefEntriesOffset() {
  44518. var mainXRefEntriesOffset = 0;
  44519. var linearization = this.linearization;
  44520. if (linearization) {
  44521. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  44522. }
  44523. // shadow the prototype getter with a data property
  44524. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  44525. },
  44526. // Find the header, remove leading garbage and setup the stream
  44527. // starting from the header.
  44528. checkHeader: function PDFDocument_checkHeader() {
  44529. var stream = this.stream;
  44530. stream.reset();
  44531. if (find(stream, '%PDF-', 1024)) {
  44532. // Found the header, trim off any garbage before it.
  44533. stream.moveStart();
  44534. // Reading file format version
  44535. var MAX_VERSION_LENGTH = 12;
  44536. var version = '', ch;
  44537. while ((ch = stream.getByte()) > 0x20) { // SPACE
  44538. if (version.length >= MAX_VERSION_LENGTH) {
  44539. break;
  44540. }
  44541. version += String.fromCharCode(ch);
  44542. }
  44543. if (!this.pdfFormatVersion) {
  44544. // removing "%PDF-"-prefix
  44545. this.pdfFormatVersion = version.substring(5);
  44546. }
  44547. return;
  44548. }
  44549. // May not be a PDF file, continue anyway.
  44550. },
  44551. parseStartXRef: function PDFDocument_parseStartXRef() {
  44552. var startXRef = this.startXRef;
  44553. this.xref.setStartXRef(startXRef);
  44554. },
  44555. setup: function PDFDocument_setup(recoveryMode) {
  44556. this.xref.parse(recoveryMode);
  44557. var self = this;
  44558. var pageFactory = {
  44559. createPage: function (pageIndex, dict, ref, fontCache) {
  44560. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  44561. fontCache);
  44562. }
  44563. };
  44564. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  44565. },
  44566. get numPages() {
  44567. var linearization = this.linearization;
  44568. var num = linearization ? linearization.numPages : this.catalog.numPages;
  44569. // shadow the prototype getter
  44570. return shadow(this, 'numPages', num);
  44571. },
  44572. get documentInfo() {
  44573. var docInfo = {
  44574. PDFFormatVersion: this.pdfFormatVersion,
  44575. IsAcroFormPresent: !!this.acroForm,
  44576. IsXFAPresent: !!this.xfa
  44577. };
  44578. var infoDict;
  44579. try {
  44580. infoDict = this.xref.trailer.get('Info');
  44581. } catch (err) {
  44582. info('The document information dictionary is invalid.');
  44583. }
  44584. if (infoDict) {
  44585. var validEntries = DocumentInfoValidators.entries;
  44586. // Only fill the document info with valid entries from the spec.
  44587. for (var key in validEntries) {
  44588. if (infoDict.has(key)) {
  44589. var value = infoDict.get(key);
  44590. // Make sure the value conforms to the spec.
  44591. if (validEntries[key](value)) {
  44592. docInfo[key] = (typeof value !== 'string' ?
  44593. value : stringToPDFString(value));
  44594. } else {
  44595. info('Bad value in document info for "' + key + '"');
  44596. }
  44597. }
  44598. }
  44599. }
  44600. return shadow(this, 'documentInfo', docInfo);
  44601. },
  44602. get fingerprint() {
  44603. var xref = this.xref, hash, fileID = '';
  44604. var idArray = xref.trailer.get('ID');
  44605. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  44606. idArray[0] !== EMPTY_FINGERPRINT) {
  44607. hash = stringToBytes(idArray[0]);
  44608. } else {
  44609. if (this.stream.ensureRange) {
  44610. this.stream.ensureRange(0,
  44611. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  44612. }
  44613. hash = calculateMD5(this.stream.bytes.subarray(0,
  44614. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  44615. }
  44616. for (var i = 0, n = hash.length; i < n; i++) {
  44617. var hex = hash[i].toString(16);
  44618. fileID += hex.length === 1 ? '0' + hex : hex;
  44619. }
  44620. return shadow(this, 'fingerprint', fileID);
  44621. },
  44622. getPage: function PDFDocument_getPage(pageIndex) {
  44623. return this.catalog.getPage(pageIndex);
  44624. },
  44625. cleanup: function PDFDocument_cleanup() {
  44626. return this.catalog.cleanup();
  44627. }
  44628. };
  44629. return PDFDocument;
  44630. })();
  44631. exports.Page = Page;
  44632. exports.PDFDocument = PDFDocument;
  44633. }));
  44634. (function (root, factory) {
  44635. {
  44636. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  44637. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  44638. root.pdfjsCoreDocument);
  44639. }
  44640. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  44641. coreDocument) {
  44642. var NotImplementedException = sharedUtil.NotImplementedException;
  44643. var MissingDataException = sharedUtil.MissingDataException;
  44644. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44645. var Util = sharedUtil.Util;
  44646. var Stream = coreStream.Stream;
  44647. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  44648. var PDFDocument = coreDocument.PDFDocument;
  44649. var BasePdfManager = (function BasePdfManagerClosure() {
  44650. function BasePdfManager() {
  44651. throw new Error('Cannot initialize BaseManagerManager');
  44652. }
  44653. BasePdfManager.prototype = {
  44654. get docId() {
  44655. return this._docId;
  44656. },
  44657. onLoadedStream: function BasePdfManager_onLoadedStream() {
  44658. throw new NotImplementedException();
  44659. },
  44660. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  44661. return this.ensure(this.pdfDocument, prop, args);
  44662. },
  44663. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  44664. return this.ensure(this.pdfDocument.xref, prop, args);
  44665. },
  44666. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  44667. return this.ensure(this.pdfDocument.catalog, prop, args);
  44668. },
  44669. getPage: function BasePdfManager_getPage(pageIndex) {
  44670. return this.pdfDocument.getPage(pageIndex);
  44671. },
  44672. cleanup: function BasePdfManager_cleanup() {
  44673. return this.pdfDocument.cleanup();
  44674. },
  44675. ensure: function BasePdfManager_ensure(obj, prop, args) {
  44676. return new NotImplementedException();
  44677. },
  44678. requestRange: function BasePdfManager_requestRange(begin, end) {
  44679. return new NotImplementedException();
  44680. },
  44681. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  44682. return new NotImplementedException();
  44683. },
  44684. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  44685. return new NotImplementedException();
  44686. },
  44687. updatePassword: function BasePdfManager_updatePassword(password) {
  44688. this.pdfDocument.xref.password = this.password = password;
  44689. if (this._passwordChangedCapability) {
  44690. this._passwordChangedCapability.resolve();
  44691. }
  44692. },
  44693. passwordChanged: function BasePdfManager_passwordChanged() {
  44694. this._passwordChangedCapability = createPromiseCapability();
  44695. return this._passwordChangedCapability.promise;
  44696. },
  44697. terminate: function BasePdfManager_terminate() {
  44698. return new NotImplementedException();
  44699. }
  44700. };
  44701. return BasePdfManager;
  44702. })();
  44703. var LocalPdfManager = (function LocalPdfManagerClosure() {
  44704. function LocalPdfManager(docId, data, password) {
  44705. this._docId = docId;
  44706. var stream = new Stream(data);
  44707. this.pdfDocument = new PDFDocument(this, stream, password);
  44708. this._loadedStreamCapability = createPromiseCapability();
  44709. this._loadedStreamCapability.resolve(stream);
  44710. }
  44711. Util.inherit(LocalPdfManager, BasePdfManager, {
  44712. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  44713. return new Promise(function (resolve, reject) {
  44714. try {
  44715. var value = obj[prop];
  44716. var result;
  44717. if (typeof value === 'function') {
  44718. result = value.apply(obj, args);
  44719. } else {
  44720. result = value;
  44721. }
  44722. resolve(result);
  44723. } catch (e) {
  44724. reject(e);
  44725. }
  44726. });
  44727. },
  44728. requestRange: function LocalPdfManager_requestRange(begin, end) {
  44729. return Promise.resolve();
  44730. },
  44731. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  44732. return;
  44733. },
  44734. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  44735. return this._loadedStreamCapability.promise;
  44736. },
  44737. terminate: function LocalPdfManager_terminate() {
  44738. return;
  44739. }
  44740. });
  44741. return LocalPdfManager;
  44742. })();
  44743. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  44744. function NetworkPdfManager(docId, args, msgHandler) {
  44745. this._docId = docId;
  44746. this.msgHandler = msgHandler;
  44747. var params = {
  44748. msgHandler: msgHandler,
  44749. httpHeaders: args.httpHeaders,
  44750. withCredentials: args.withCredentials,
  44751. chunkedViewerLoading: args.chunkedViewerLoading,
  44752. disableAutoFetch: args.disableAutoFetch,
  44753. initialData: args.initialData
  44754. };
  44755. this.streamManager = new ChunkedStreamManager(args.length,
  44756. args.rangeChunkSize,
  44757. args.url, params);
  44758. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  44759. args.password);
  44760. }
  44761. Util.inherit(NetworkPdfManager, BasePdfManager, {
  44762. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  44763. var pdfManager = this;
  44764. return new Promise(function (resolve, reject) {
  44765. function ensureHelper() {
  44766. try {
  44767. var result;
  44768. var value = obj[prop];
  44769. if (typeof value === 'function') {
  44770. result = value.apply(obj, args);
  44771. } else {
  44772. result = value;
  44773. }
  44774. resolve(result);
  44775. } catch(e) {
  44776. if (!(e instanceof MissingDataException)) {
  44777. reject(e);
  44778. return;
  44779. }
  44780. pdfManager.streamManager.requestRange(e.begin, e.end).
  44781. then(ensureHelper, reject);
  44782. }
  44783. }
  44784. ensureHelper();
  44785. });
  44786. },
  44787. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  44788. return this.streamManager.requestRange(begin, end);
  44789. },
  44790. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  44791. this.streamManager.requestAllChunks();
  44792. },
  44793. sendProgressiveData:
  44794. function NetworkPdfManager_sendProgressiveData(chunk) {
  44795. this.streamManager.onReceiveData({ chunk: chunk });
  44796. },
  44797. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  44798. return this.streamManager.onLoadedStream();
  44799. },
  44800. terminate: function NetworkPdfManager_terminate() {
  44801. this.streamManager.abort();
  44802. }
  44803. });
  44804. return NetworkPdfManager;
  44805. })();
  44806. exports.LocalPdfManager = LocalPdfManager;
  44807. exports.NetworkPdfManager = NetworkPdfManager;
  44808. }));
  44809. (function (root, factory) {
  44810. {
  44811. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  44812. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  44813. root.pdfjsSharedGlobal);
  44814. }
  44815. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  44816. sharedGlobal) {
  44817. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  44818. var InvalidPDFException = sharedUtil.InvalidPDFException;
  44819. var MessageHandler = sharedUtil.MessageHandler;
  44820. var MissingPDFException = sharedUtil.MissingPDFException;
  44821. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  44822. var PasswordException = sharedUtil.PasswordException;
  44823. var PasswordResponses = sharedUtil.PasswordResponses;
  44824. var UnknownErrorException = sharedUtil.UnknownErrorException;
  44825. var XRefParseException = sharedUtil.XRefParseException;
  44826. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44827. var error = sharedUtil.error;
  44828. var info = sharedUtil.info;
  44829. var isInt = sharedUtil.isInt;
  44830. var warn = sharedUtil.warn;
  44831. var Ref = corePrimitives.Ref;
  44832. var LocalPdfManager = corePdfManager.LocalPdfManager;
  44833. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  44834. var globalScope = sharedGlobal.globalScope;
  44835. var PDFJS = sharedGlobal.PDFJS;
  44836. var WorkerTask = (function WorkerTaskClosure() {
  44837. function WorkerTask(name) {
  44838. this.name = name;
  44839. this.terminated = false;
  44840. this._capability = createPromiseCapability();
  44841. }
  44842. WorkerTask.prototype = {
  44843. get finished() {
  44844. return this._capability.promise;
  44845. },
  44846. finish: function () {
  44847. this._capability.resolve();
  44848. },
  44849. terminate: function () {
  44850. this.terminated = true;
  44851. },
  44852. ensureNotTerminated: function () {
  44853. if (this.terminated) {
  44854. throw new Error('Worker task was terminated');
  44855. }
  44856. }
  44857. };
  44858. return WorkerTask;
  44859. })();
  44860. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  44861. setup: function wphSetup(handler, port) {
  44862. var testMessageProcessed = false;
  44863. handler.on('test', function wphSetupTest(data) {
  44864. if (testMessageProcessed) {
  44865. return; // we already processed 'test' message once
  44866. }
  44867. testMessageProcessed = true;
  44868. // check if Uint8Array can be sent to worker
  44869. if (!(data instanceof Uint8Array)) {
  44870. handler.send('test', 'main', false);
  44871. return;
  44872. }
  44873. // making sure postMessage transfers are working
  44874. var supportTransfers = data[0] === 255;
  44875. handler.postMessageTransfers = supportTransfers;
  44876. // check if the response property is supported by xhr
  44877. var xhr = new XMLHttpRequest();
  44878. var responseExists = 'response' in xhr;
  44879. // check if the property is actually implemented
  44880. try {
  44881. var dummy = xhr.responseType;
  44882. } catch (e) {
  44883. responseExists = false;
  44884. }
  44885. if (!responseExists) {
  44886. handler.send('test', false);
  44887. return;
  44888. }
  44889. handler.send('test', {
  44890. supportTypedArray: true,
  44891. supportTransfers: supportTransfers
  44892. });
  44893. });
  44894. handler.on('GetDocRequest', function wphSetupDoc(data) {
  44895. return WorkerMessageHandler.createDocumentHandler(data, port);
  44896. });
  44897. },
  44898. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  44899. // This context is actually holds references on pdfManager and handler,
  44900. // until the latter is destroyed.
  44901. var pdfManager;
  44902. var terminated = false;
  44903. var cancelXHRs = null;
  44904. var WorkerTasks = [];
  44905. var docId = docParams.docId;
  44906. var workerHandlerName = docParams.docId + '_worker';
  44907. var handler = new MessageHandler(workerHandlerName, docId, port);
  44908. function ensureNotTerminated() {
  44909. if (terminated) {
  44910. throw new Error('Worker was terminated');
  44911. }
  44912. }
  44913. function startWorkerTask(task) {
  44914. WorkerTasks.push(task);
  44915. }
  44916. function finishWorkerTask(task) {
  44917. task.finish();
  44918. var i = WorkerTasks.indexOf(task);
  44919. WorkerTasks.splice(i, 1);
  44920. }
  44921. function loadDocument(recoveryMode) {
  44922. var loadDocumentCapability = createPromiseCapability();
  44923. var parseSuccess = function parseSuccess() {
  44924. var numPagesPromise = pdfManager.ensureDoc('numPages');
  44925. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  44926. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  44927. Promise.all([numPagesPromise, fingerprintPromise,
  44928. encryptedPromise]).then(function onDocReady(results) {
  44929. var doc = {
  44930. numPages: results[0],
  44931. fingerprint: results[1],
  44932. encrypted: !!results[2],
  44933. };
  44934. loadDocumentCapability.resolve(doc);
  44935. },
  44936. parseFailure);
  44937. };
  44938. var parseFailure = function parseFailure(e) {
  44939. loadDocumentCapability.reject(e);
  44940. };
  44941. pdfManager.ensureDoc('checkHeader', []).then(function() {
  44942. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  44943. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  44944. parseSuccess, parseFailure);
  44945. }, parseFailure);
  44946. }, parseFailure);
  44947. return loadDocumentCapability.promise;
  44948. }
  44949. function getPdfManager(data) {
  44950. var pdfManagerCapability = createPromiseCapability();
  44951. var pdfManager;
  44952. var source = data.source;
  44953. var disableRange = data.disableRange;
  44954. if (source.data) {
  44955. try {
  44956. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  44957. pdfManagerCapability.resolve(pdfManager);
  44958. } catch (ex) {
  44959. pdfManagerCapability.reject(ex);
  44960. }
  44961. return pdfManagerCapability.promise;
  44962. } else if (source.chunkedViewerLoading) {
  44963. try {
  44964. pdfManager = new NetworkPdfManager(docId, source, handler);
  44965. pdfManagerCapability.resolve(pdfManager);
  44966. } catch (ex) {
  44967. pdfManagerCapability.reject(ex);
  44968. }
  44969. return pdfManagerCapability.promise;
  44970. }
  44971. var networkManager = new NetworkManager(source.url, {
  44972. httpHeaders: source.httpHeaders,
  44973. withCredentials: source.withCredentials
  44974. });
  44975. var cachedChunks = [];
  44976. var fullRequestXhrId = networkManager.requestFull({
  44977. onHeadersReceived: function onHeadersReceived() {
  44978. if (disableRange) {
  44979. return;
  44980. }
  44981. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  44982. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  44983. return;
  44984. }
  44985. var contentEncoding =
  44986. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  44987. if (contentEncoding !== 'identity') {
  44988. return;
  44989. }
  44990. var length = fullRequestXhr.getResponseHeader('Content-Length');
  44991. length = parseInt(length, 10);
  44992. if (!isInt(length)) {
  44993. return;
  44994. }
  44995. source.length = length;
  44996. if (length <= 2 * source.rangeChunkSize) {
  44997. // The file size is smaller than the size of two chunks, so it does
  44998. // not make any sense to abort the request and retry with a range
  44999. // request.
  45000. return;
  45001. }
  45002. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  45003. // We can continue fetching when progressive loading is enabled,
  45004. // and we don't need the autoFetch feature.
  45005. source.disableAutoFetch = true;
  45006. } else {
  45007. // NOTE: by cancelling the full request, and then issuing range
  45008. // requests, there will be an issue for sites where you can only
  45009. // request the pdf once. However, if this is the case, then the
  45010. // server should not be returning that it can support range
  45011. // requests.
  45012. networkManager.abortRequest(fullRequestXhrId);
  45013. }
  45014. try {
  45015. pdfManager = new NetworkPdfManager(docId, source, handler);
  45016. pdfManagerCapability.resolve(pdfManager);
  45017. } catch (ex) {
  45018. pdfManagerCapability.reject(ex);
  45019. }
  45020. cancelXHRs = null;
  45021. },
  45022. onProgressiveData: source.disableStream ? null :
  45023. function onProgressiveData(chunk) {
  45024. if (!pdfManager) {
  45025. cachedChunks.push(chunk);
  45026. return;
  45027. }
  45028. pdfManager.sendProgressiveData(chunk);
  45029. },
  45030. onDone: function onDone(args) {
  45031. if (pdfManager) {
  45032. return; // already processed
  45033. }
  45034. var pdfFile;
  45035. if (args === null) {
  45036. // TODO add some streaming manager, e.g. for unknown length files.
  45037. // The data was returned in the onProgressiveData, combining...
  45038. var pdfFileLength = 0, pos = 0;
  45039. cachedChunks.forEach(function (chunk) {
  45040. pdfFileLength += chunk.byteLength;
  45041. });
  45042. if (source.length && pdfFileLength !== source.length) {
  45043. warn('reported HTTP length is different from actual');
  45044. }
  45045. var pdfFileArray = new Uint8Array(pdfFileLength);
  45046. cachedChunks.forEach(function (chunk) {
  45047. pdfFileArray.set(new Uint8Array(chunk), pos);
  45048. pos += chunk.byteLength;
  45049. });
  45050. pdfFile = pdfFileArray.buffer;
  45051. } else {
  45052. pdfFile = args.chunk;
  45053. }
  45054. // the data is array, instantiating directly from it
  45055. try {
  45056. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  45057. pdfManagerCapability.resolve(pdfManager);
  45058. } catch (ex) {
  45059. pdfManagerCapability.reject(ex);
  45060. }
  45061. cancelXHRs = null;
  45062. },
  45063. onError: function onError(status) {
  45064. var exception;
  45065. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  45066. exception = new MissingPDFException('Missing PDF "' +
  45067. source.url + '".');
  45068. handler.send('MissingPDF', exception);
  45069. } else {
  45070. exception = new UnexpectedResponseException(
  45071. 'Unexpected server response (' + status +
  45072. ') while retrieving PDF "' + source.url + '".', status);
  45073. handler.send('UnexpectedResponse', exception);
  45074. }
  45075. cancelXHRs = null;
  45076. },
  45077. onProgress: function onProgress(evt) {
  45078. handler.send('DocProgress', {
  45079. loaded: evt.loaded,
  45080. total: evt.lengthComputable ? evt.total : source.length
  45081. });
  45082. }
  45083. });
  45084. cancelXHRs = function () {
  45085. networkManager.abortRequest(fullRequestXhrId);
  45086. };
  45087. return pdfManagerCapability.promise;
  45088. }
  45089. var setupDoc = function(data) {
  45090. var onSuccess = function(doc) {
  45091. ensureNotTerminated();
  45092. handler.send('GetDoc', { pdfInfo: doc });
  45093. };
  45094. var onFailure = function(e) {
  45095. if (e instanceof PasswordException) {
  45096. if (e.code === PasswordResponses.NEED_PASSWORD) {
  45097. handler.send('NeedPassword', e);
  45098. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  45099. handler.send('IncorrectPassword', e);
  45100. }
  45101. } else if (e instanceof InvalidPDFException) {
  45102. handler.send('InvalidPDF', e);
  45103. } else if (e instanceof MissingPDFException) {
  45104. handler.send('MissingPDF', e);
  45105. } else if (e instanceof UnexpectedResponseException) {
  45106. handler.send('UnexpectedResponse', e);
  45107. } else {
  45108. handler.send('UnknownError',
  45109. new UnknownErrorException(e.message, e.toString()));
  45110. }
  45111. };
  45112. ensureNotTerminated();
  45113. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  45114. -1 : data.maxImageSize;
  45115. PDFJS.disableFontFace = data.disableFontFace;
  45116. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  45117. PDFJS.verbosity = data.verbosity;
  45118. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  45119. null : data.cMapUrl;
  45120. PDFJS.cMapPacked = data.cMapPacked === true;
  45121. getPdfManager(data).then(function (newPdfManager) {
  45122. if (terminated) {
  45123. // We were in a process of setting up the manager, but it got
  45124. // terminated in the middle.
  45125. newPdfManager.terminate();
  45126. throw new Error('Worker was terminated');
  45127. }
  45128. pdfManager = newPdfManager;
  45129. handler.send('PDFManagerReady', null);
  45130. pdfManager.onLoadedStream().then(function(stream) {
  45131. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  45132. });
  45133. }).then(function pdfManagerReady() {
  45134. ensureNotTerminated();
  45135. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  45136. ensureNotTerminated();
  45137. // Try again with recoveryMode == true
  45138. if (!(ex instanceof XRefParseException)) {
  45139. if (ex instanceof PasswordException) {
  45140. // after password exception prepare to receive a new password
  45141. // to repeat loading
  45142. pdfManager.passwordChanged().then(pdfManagerReady);
  45143. }
  45144. onFailure(ex);
  45145. return;
  45146. }
  45147. pdfManager.requestLoadedStream();
  45148. pdfManager.onLoadedStream().then(function() {
  45149. ensureNotTerminated();
  45150. loadDocument(true).then(onSuccess, onFailure);
  45151. });
  45152. }, onFailure);
  45153. }, onFailure);
  45154. };
  45155. handler.on('GetPage', function wphSetupGetPage(data) {
  45156. return pdfManager.getPage(data.pageIndex).then(function(page) {
  45157. var rotatePromise = pdfManager.ensure(page, 'rotate');
  45158. var refPromise = pdfManager.ensure(page, 'ref');
  45159. var viewPromise = pdfManager.ensure(page, 'view');
  45160. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  45161. function(results) {
  45162. return {
  45163. rotate: results[0],
  45164. ref: results[1],
  45165. view: results[2]
  45166. };
  45167. });
  45168. });
  45169. });
  45170. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  45171. var ref = new Ref(data.ref.num, data.ref.gen);
  45172. var catalog = pdfManager.pdfDocument.catalog;
  45173. return catalog.getPageIndex(ref);
  45174. });
  45175. handler.on('GetDestinations',
  45176. function wphSetupGetDestinations(data) {
  45177. return pdfManager.ensureCatalog('destinations');
  45178. }
  45179. );
  45180. handler.on('GetDestination',
  45181. function wphSetupGetDestination(data) {
  45182. return pdfManager.ensureCatalog('getDestination', [data.id]);
  45183. }
  45184. );
  45185. handler.on('GetAttachments',
  45186. function wphSetupGetAttachments(data) {
  45187. return pdfManager.ensureCatalog('attachments');
  45188. }
  45189. );
  45190. handler.on('GetJavaScript',
  45191. function wphSetupGetJavaScript(data) {
  45192. return pdfManager.ensureCatalog('javaScript');
  45193. }
  45194. );
  45195. handler.on('GetOutline',
  45196. function wphSetupGetOutline(data) {
  45197. return pdfManager.ensureCatalog('documentOutline');
  45198. }
  45199. );
  45200. handler.on('GetMetadata',
  45201. function wphSetupGetMetadata(data) {
  45202. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  45203. pdfManager.ensureCatalog('metadata')]);
  45204. }
  45205. );
  45206. handler.on('GetData', function wphSetupGetData(data) {
  45207. pdfManager.requestLoadedStream();
  45208. return pdfManager.onLoadedStream().then(function(stream) {
  45209. return stream.bytes;
  45210. });
  45211. });
  45212. handler.on('GetStats',
  45213. function wphSetupGetStats(data) {
  45214. return pdfManager.pdfDocument.xref.stats;
  45215. }
  45216. );
  45217. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  45218. pdfManager.updatePassword(data);
  45219. });
  45220. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  45221. return pdfManager.getPage(data.pageIndex).then(function(page) {
  45222. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  45223. });
  45224. });
  45225. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  45226. var pageIndex = data.pageIndex;
  45227. pdfManager.getPage(pageIndex).then(function(page) {
  45228. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  45229. startWorkerTask(task);
  45230. var pageNum = pageIndex + 1;
  45231. var start = Date.now();
  45232. // Pre compile the pdf page and fetch the fonts/images.
  45233. page.getOperatorList(handler, task, data.intent).then(
  45234. function(operatorList) {
  45235. finishWorkerTask(task);
  45236. info('page=' + pageNum + ' - getOperatorList: time=' +
  45237. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  45238. }, function(e) {
  45239. finishWorkerTask(task);
  45240. if (task.terminated) {
  45241. return; // ignoring errors from the terminated thread
  45242. }
  45243. // For compatibility with older behavior, generating unknown
  45244. // unsupported feature notification on errors.
  45245. handler.send('UnsupportedFeature',
  45246. {featureId: UNSUPPORTED_FEATURES.unknown});
  45247. var minimumStackMessage =
  45248. 'worker.js: while trying to getPage() and getOperatorList()';
  45249. var wrappedException;
  45250. // Turn the error into an obj that can be serialized
  45251. if (typeof e === 'string') {
  45252. wrappedException = {
  45253. message: e,
  45254. stack: minimumStackMessage
  45255. };
  45256. } else if (typeof e === 'object') {
  45257. wrappedException = {
  45258. message: e.message || e.toString(),
  45259. stack: e.stack || minimumStackMessage
  45260. };
  45261. } else {
  45262. wrappedException = {
  45263. message: 'Unknown exception type: ' + (typeof e),
  45264. stack: minimumStackMessage
  45265. };
  45266. }
  45267. handler.send('PageError', {
  45268. pageNum: pageNum,
  45269. error: wrappedException,
  45270. intent: data.intent
  45271. });
  45272. });
  45273. });
  45274. }, this);
  45275. handler.on('GetTextContent', function wphExtractText(data) {
  45276. var pageIndex = data.pageIndex;
  45277. var normalizeWhitespace = data.normalizeWhitespace;
  45278. return pdfManager.getPage(pageIndex).then(function(page) {
  45279. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  45280. startWorkerTask(task);
  45281. var pageNum = pageIndex + 1;
  45282. var start = Date.now();
  45283. return page.extractTextContent(task, normalizeWhitespace).then(
  45284. function(textContent) {
  45285. finishWorkerTask(task);
  45286. info('text indexing: page=' + pageNum + ' - time=' +
  45287. (Date.now() - start) + 'ms');
  45288. return textContent;
  45289. }, function (reason) {
  45290. finishWorkerTask(task);
  45291. if (task.terminated) {
  45292. return; // ignoring errors from the terminated thread
  45293. }
  45294. throw reason;
  45295. });
  45296. });
  45297. });
  45298. handler.on('Cleanup', function wphCleanup(data) {
  45299. return pdfManager.cleanup();
  45300. });
  45301. handler.on('Terminate', function wphTerminate(data) {
  45302. terminated = true;
  45303. if (pdfManager) {
  45304. pdfManager.terminate();
  45305. pdfManager = null;
  45306. }
  45307. if (cancelXHRs) {
  45308. cancelXHRs();
  45309. }
  45310. var waitOn = [];
  45311. WorkerTasks.forEach(function (task) {
  45312. waitOn.push(task.finished);
  45313. task.terminate();
  45314. });
  45315. return Promise.all(waitOn).then(function () {
  45316. // Notice that even if we destroying handler, resolved response promise
  45317. // must be sent back.
  45318. handler.destroy();
  45319. handler = null;
  45320. });
  45321. });
  45322. handler.on('Ready', function wphReady(data) {
  45323. setupDoc(docParams);
  45324. docParams = null; // we don't need docParams anymore -- saving memory.
  45325. });
  45326. return workerHandlerName;
  45327. }
  45328. };
  45329. function initializeWorker() {
  45330. if (!('console' in globalScope)) {
  45331. var consoleTimer = {};
  45332. var workerConsole = {
  45333. log: function log() {
  45334. var args = Array.prototype.slice.call(arguments);
  45335. globalScope.postMessage({
  45336. targetName: 'main',
  45337. action: 'console_log',
  45338. data: args
  45339. });
  45340. },
  45341. error: function error() {
  45342. var args = Array.prototype.slice.call(arguments);
  45343. globalScope.postMessage({
  45344. targetName: 'main',
  45345. action: 'console_error',
  45346. data: args
  45347. });
  45348. throw 'pdf.js execution error';
  45349. },
  45350. time: function time(name) {
  45351. consoleTimer[name] = Date.now();
  45352. },
  45353. timeEnd: function timeEnd(name) {
  45354. var time = consoleTimer[name];
  45355. if (!time) {
  45356. error('Unknown timer name ' + name);
  45357. }
  45358. this.log('Timer:', name, Date.now() - time);
  45359. }
  45360. };
  45361. globalScope.console = workerConsole;
  45362. }
  45363. var handler = new MessageHandler('worker', 'main', self);
  45364. WorkerMessageHandler.setup(handler, self);
  45365. handler.send('ready', null);
  45366. }
  45367. // Worker thread (and not node.js)?
  45368. if (typeof window === 'undefined' &&
  45369. !(typeof module !== 'undefined' && module.require)) {
  45370. initializeWorker();
  45371. }
  45372. exports.WorkerTask = WorkerTask;
  45373. exports.WorkerMessageHandler = WorkerMessageHandler;
  45374. }));
  45375. }).call((typeof window === 'undefined') ? this : window);
  45376. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  45377. // workerSrc is not set -- using last script url to define default location
  45378. PDFJS.workerSrc = (function () {
  45379. 'use strict';
  45380. var pdfJsSrc = document.currentScript.src;
  45381. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  45382. })();
  45383. }