2
0

pdf.combined.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.0.927';
  24. PDFJS.build = 'd65db7c';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. PDFJS.PasswordException = PasswordException;
  346. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  347. function UnknownErrorException(msg, details) {
  348. this.name = 'UnknownErrorException';
  349. this.message = msg;
  350. this.details = details;
  351. }
  352. UnknownErrorException.prototype = new Error();
  353. UnknownErrorException.constructor = UnknownErrorException;
  354. return UnknownErrorException;
  355. })();
  356. PDFJS.UnknownErrorException = UnknownErrorException;
  357. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  358. function InvalidPDFException(msg) {
  359. this.name = 'InvalidPDFException';
  360. this.message = msg;
  361. }
  362. InvalidPDFException.prototype = new Error();
  363. InvalidPDFException.constructor = InvalidPDFException;
  364. return InvalidPDFException;
  365. })();
  366. PDFJS.InvalidPDFException = InvalidPDFException;
  367. var MissingPDFException = (function MissingPDFExceptionClosure() {
  368. function MissingPDFException(msg) {
  369. this.name = 'MissingPDFException';
  370. this.message = msg;
  371. }
  372. MissingPDFException.prototype = new Error();
  373. MissingPDFException.constructor = MissingPDFException;
  374. return MissingPDFException;
  375. })();
  376. PDFJS.MissingPDFException = MissingPDFException;
  377. var UnexpectedResponseException =
  378. (function UnexpectedResponseExceptionClosure() {
  379. function UnexpectedResponseException(msg, status) {
  380. this.name = 'UnexpectedResponseException';
  381. this.message = msg;
  382. this.status = status;
  383. }
  384. UnexpectedResponseException.prototype = new Error();
  385. UnexpectedResponseException.constructor = UnexpectedResponseException;
  386. return UnexpectedResponseException;
  387. })();
  388. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  389. var NotImplementedException = (function NotImplementedExceptionClosure() {
  390. function NotImplementedException(msg) {
  391. this.message = msg;
  392. }
  393. NotImplementedException.prototype = new Error();
  394. NotImplementedException.prototype.name = 'NotImplementedException';
  395. NotImplementedException.constructor = NotImplementedException;
  396. return NotImplementedException;
  397. })();
  398. var MissingDataException = (function MissingDataExceptionClosure() {
  399. function MissingDataException(begin, end) {
  400. this.begin = begin;
  401. this.end = end;
  402. this.message = 'Missing data [' + begin + ', ' + end + ')';
  403. }
  404. MissingDataException.prototype = new Error();
  405. MissingDataException.prototype.name = 'MissingDataException';
  406. MissingDataException.constructor = MissingDataException;
  407. return MissingDataException;
  408. })();
  409. var XRefParseException = (function XRefParseExceptionClosure() {
  410. function XRefParseException(msg) {
  411. this.message = msg;
  412. }
  413. XRefParseException.prototype = new Error();
  414. XRefParseException.prototype.name = 'XRefParseException';
  415. XRefParseException.constructor = XRefParseException;
  416. return XRefParseException;
  417. })();
  418. function bytesToString(bytes) {
  419. var length = bytes.length;
  420. var MAX_ARGUMENT_COUNT = 8192;
  421. if (length < MAX_ARGUMENT_COUNT) {
  422. return String.fromCharCode.apply(null, bytes);
  423. }
  424. var strBuf = [];
  425. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  426. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  427. var chunk = bytes.subarray(i, chunkEnd);
  428. strBuf.push(String.fromCharCode.apply(null, chunk));
  429. }
  430. return strBuf.join('');
  431. }
  432. function stringToBytes(str) {
  433. var length = str.length;
  434. var bytes = new Uint8Array(length);
  435. for (var i = 0; i < length; ++i) {
  436. bytes[i] = str.charCodeAt(i) & 0xFF;
  437. }
  438. return bytes;
  439. }
  440. function string32(value) {
  441. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  442. (value >> 8) & 0xff, value & 0xff);
  443. }
  444. function log2(x) {
  445. var n = 1, i = 0;
  446. while (x > n) {
  447. n <<= 1;
  448. i++;
  449. }
  450. return i;
  451. }
  452. function readInt8(data, start) {
  453. return (data[start] << 24) >> 24;
  454. }
  455. function readUint16(data, offset) {
  456. return (data[offset] << 8) | data[offset + 1];
  457. }
  458. function readUint32(data, offset) {
  459. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  460. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  461. }
  462. // Lazy test the endianness of the platform
  463. // NOTE: This will be 'true' for simulated TypedArrays
  464. function isLittleEndian() {
  465. var buffer8 = new Uint8Array(2);
  466. buffer8[0] = 1;
  467. var buffer16 = new Uint16Array(buffer8.buffer);
  468. return (buffer16[0] === 1);
  469. }
  470. Object.defineProperty(PDFJS, 'isLittleEndian', {
  471. configurable: true,
  472. get: function PDFJS_isLittleEndian() {
  473. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  474. }
  475. });
  476. // Lazy test if the userAgant support CanvasTypedArrays
  477. function hasCanvasTypedArrays() {
  478. var canvas = document.createElement('canvas');
  479. canvas.width = canvas.height = 1;
  480. var ctx = canvas.getContext('2d');
  481. var imageData = ctx.createImageData(1, 1);
  482. return (typeof imageData.data.buffer !== 'undefined');
  483. }
  484. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  485. configurable: true,
  486. get: function PDFJS_hasCanvasTypedArrays() {
  487. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  488. }
  489. });
  490. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  491. function Uint32ArrayView(buffer, length) {
  492. this.buffer = buffer;
  493. this.byteLength = buffer.length;
  494. this.length = length === undefined ? (this.byteLength >> 2) : length;
  495. ensureUint32ArrayViewProps(this.length);
  496. }
  497. Uint32ArrayView.prototype = Object.create(null);
  498. var uint32ArrayViewSetters = 0;
  499. function createUint32ArrayProp(index) {
  500. return {
  501. get: function () {
  502. var buffer = this.buffer, offset = index << 2;
  503. return (buffer[offset] | (buffer[offset + 1] << 8) |
  504. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  505. },
  506. set: function (value) {
  507. var buffer = this.buffer, offset = index << 2;
  508. buffer[offset] = value & 255;
  509. buffer[offset + 1] = (value >> 8) & 255;
  510. buffer[offset + 2] = (value >> 16) & 255;
  511. buffer[offset + 3] = (value >>> 24) & 255;
  512. }
  513. };
  514. }
  515. function ensureUint32ArrayViewProps(length) {
  516. while (uint32ArrayViewSetters < length) {
  517. Object.defineProperty(Uint32ArrayView.prototype,
  518. uint32ArrayViewSetters,
  519. createUint32ArrayProp(uint32ArrayViewSetters));
  520. uint32ArrayViewSetters++;
  521. }
  522. }
  523. return Uint32ArrayView;
  524. })();
  525. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  526. var Util = PDFJS.Util = (function UtilClosure() {
  527. function Util() {}
  528. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  529. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  530. // creating many intermediate strings.
  531. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  532. rgbBuf[1] = rgb[0];
  533. rgbBuf[3] = rgb[1];
  534. rgbBuf[5] = rgb[2];
  535. return rgbBuf.join('');
  536. };
  537. // Concatenates two transformation matrices together and returns the result.
  538. Util.transform = function Util_transform(m1, m2) {
  539. return [
  540. m1[0] * m2[0] + m1[2] * m2[1],
  541. m1[1] * m2[0] + m1[3] * m2[1],
  542. m1[0] * m2[2] + m1[2] * m2[3],
  543. m1[1] * m2[2] + m1[3] * m2[3],
  544. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  545. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  546. ];
  547. };
  548. // For 2d affine transforms
  549. Util.applyTransform = function Util_applyTransform(p, m) {
  550. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  551. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  552. return [xt, yt];
  553. };
  554. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  555. var d = m[0] * m[3] - m[1] * m[2];
  556. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  557. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  558. return [xt, yt];
  559. };
  560. // Applies the transform to the rectangle and finds the minimum axially
  561. // aligned bounding box.
  562. Util.getAxialAlignedBoundingBox =
  563. function Util_getAxialAlignedBoundingBox(r, m) {
  564. var p1 = Util.applyTransform(r, m);
  565. var p2 = Util.applyTransform(r.slice(2, 4), m);
  566. var p3 = Util.applyTransform([r[0], r[3]], m);
  567. var p4 = Util.applyTransform([r[2], r[1]], m);
  568. return [
  569. Math.min(p1[0], p2[0], p3[0], p4[0]),
  570. Math.min(p1[1], p2[1], p3[1], p4[1]),
  571. Math.max(p1[0], p2[0], p3[0], p4[0]),
  572. Math.max(p1[1], p2[1], p3[1], p4[1])
  573. ];
  574. };
  575. Util.inverseTransform = function Util_inverseTransform(m) {
  576. var d = m[0] * m[3] - m[1] * m[2];
  577. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  578. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  579. };
  580. // Apply a generic 3d matrix M on a 3-vector v:
  581. // | a b c | | X |
  582. // | d e f | x | Y |
  583. // | g h i | | Z |
  584. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  585. // with v as [X,Y,Z]
  586. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  587. return [
  588. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  589. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  590. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  591. ];
  592. };
  593. // This calculation uses Singular Value Decomposition.
  594. // The SVD can be represented with formula A = USV. We are interested in the
  595. // matrix S here because it represents the scale values.
  596. Util.singularValueDecompose2dScale =
  597. function Util_singularValueDecompose2dScale(m) {
  598. var transpose = [m[0], m[2], m[1], m[3]];
  599. // Multiply matrix m with its transpose.
  600. var a = m[0] * transpose[0] + m[1] * transpose[2];
  601. var b = m[0] * transpose[1] + m[1] * transpose[3];
  602. var c = m[2] * transpose[0] + m[3] * transpose[2];
  603. var d = m[2] * transpose[1] + m[3] * transpose[3];
  604. // Solve the second degree polynomial to get roots.
  605. var first = (a + d) / 2;
  606. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  607. var sx = first + second || 1;
  608. var sy = first - second || 1;
  609. // Scale values are the square roots of the eigenvalues.
  610. return [Math.sqrt(sx), Math.sqrt(sy)];
  611. };
  612. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  613. // For coordinate systems whose origin lies in the bottom-left, this
  614. // means normalization to (BL,TR) ordering. For systems with origin in the
  615. // top-left, this means (TL,BR) ordering.
  616. Util.normalizeRect = function Util_normalizeRect(rect) {
  617. var r = rect.slice(0); // clone rect
  618. if (rect[0] > rect[2]) {
  619. r[0] = rect[2];
  620. r[2] = rect[0];
  621. }
  622. if (rect[1] > rect[3]) {
  623. r[1] = rect[3];
  624. r[3] = rect[1];
  625. }
  626. return r;
  627. };
  628. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  629. // intersection of rect1 and rect2. If no intersection, returns 'false'
  630. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  631. Util.intersect = function Util_intersect(rect1, rect2) {
  632. function compare(a, b) {
  633. return a - b;
  634. }
  635. // Order points along the axes
  636. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  637. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  638. result = [];
  639. rect1 = Util.normalizeRect(rect1);
  640. rect2 = Util.normalizeRect(rect2);
  641. // X: first and second points belong to different rectangles?
  642. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  643. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  644. // Intersection must be between second and third points
  645. result[0] = orderedX[1];
  646. result[2] = orderedX[2];
  647. } else {
  648. return false;
  649. }
  650. // Y: first and second points belong to different rectangles?
  651. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  652. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  653. // Intersection must be between second and third points
  654. result[1] = orderedY[1];
  655. result[3] = orderedY[2];
  656. } else {
  657. return false;
  658. }
  659. return result;
  660. };
  661. Util.sign = function Util_sign(num) {
  662. return num < 0 ? -1 : 1;
  663. };
  664. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  665. Array.prototype.push.apply(arr1, arr2);
  666. };
  667. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  668. Array.prototype.unshift.apply(arr1, arr2);
  669. };
  670. Util.extendObj = function extendObj(obj1, obj2) {
  671. for (var key in obj2) {
  672. obj1[key] = obj2[key];
  673. }
  674. };
  675. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  676. name) {
  677. while (dict && !dict.has(name)) {
  678. dict = dict.get('Parent');
  679. }
  680. if (!dict) {
  681. return null;
  682. }
  683. return dict.get(name);
  684. };
  685. Util.inherit = function Util_inherit(sub, base, prototype) {
  686. sub.prototype = Object.create(base.prototype);
  687. sub.prototype.constructor = sub;
  688. for (var prop in prototype) {
  689. sub.prototype[prop] = prototype[prop];
  690. }
  691. };
  692. Util.loadScript = function Util_loadScript(src, callback) {
  693. var script = document.createElement('script');
  694. var loaded = false;
  695. script.setAttribute('src', src);
  696. if (callback) {
  697. script.onload = function() {
  698. if (!loaded) {
  699. callback();
  700. }
  701. loaded = true;
  702. };
  703. }
  704. document.getElementsByTagName('head')[0].appendChild(script);
  705. };
  706. return Util;
  707. })();
  708. /**
  709. * PDF page viewport created based on scale, rotation and offset.
  710. * @class
  711. * @alias PDFJS.PageViewport
  712. */
  713. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  714. /**
  715. * @constructor
  716. * @private
  717. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  718. * @param scale {number} scale of the viewport.
  719. * @param rotation {number} rotations of the viewport in degrees.
  720. * @param offsetX {number} offset X
  721. * @param offsetY {number} offset Y
  722. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  723. */
  724. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  725. this.viewBox = viewBox;
  726. this.scale = scale;
  727. this.rotation = rotation;
  728. this.offsetX = offsetX;
  729. this.offsetY = offsetY;
  730. // creating transform to convert pdf coordinate system to the normal
  731. // canvas like coordinates taking in account scale and rotation
  732. var centerX = (viewBox[2] + viewBox[0]) / 2;
  733. var centerY = (viewBox[3] + viewBox[1]) / 2;
  734. var rotateA, rotateB, rotateC, rotateD;
  735. rotation = rotation % 360;
  736. rotation = rotation < 0 ? rotation + 360 : rotation;
  737. switch (rotation) {
  738. case 180:
  739. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  740. break;
  741. case 90:
  742. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  743. break;
  744. case 270:
  745. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  746. break;
  747. //case 0:
  748. default:
  749. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  750. break;
  751. }
  752. if (dontFlip) {
  753. rotateC = -rotateC; rotateD = -rotateD;
  754. }
  755. var offsetCanvasX, offsetCanvasY;
  756. var width, height;
  757. if (rotateA === 0) {
  758. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  759. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  760. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  761. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  762. } else {
  763. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  765. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  766. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  767. }
  768. // creating transform for the following operations:
  769. // translate(-centerX, -centerY), rotate and flip vertically,
  770. // scale, and translate(offsetCanvasX, offsetCanvasY)
  771. this.transform = [
  772. rotateA * scale,
  773. rotateB * scale,
  774. rotateC * scale,
  775. rotateD * scale,
  776. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  777. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  778. ];
  779. this.width = width;
  780. this.height = height;
  781. this.fontScale = scale;
  782. }
  783. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  784. /**
  785. * Clones viewport with additional properties.
  786. * @param args {Object} (optional) If specified, may contain the 'scale' or
  787. * 'rotation' properties to override the corresponding properties in
  788. * the cloned viewport.
  789. * @returns {PDFJS.PageViewport} Cloned viewport.
  790. */
  791. clone: function PageViewPort_clone(args) {
  792. args = args || {};
  793. var scale = 'scale' in args ? args.scale : this.scale;
  794. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  795. return new PageViewport(this.viewBox.slice(), scale, rotation,
  796. this.offsetX, this.offsetY, args.dontFlip);
  797. },
  798. /**
  799. * Converts PDF point to the viewport coordinates. For examples, useful for
  800. * converting PDF location into canvas pixel coordinates.
  801. * @param x {number} X coordinate.
  802. * @param y {number} Y coordinate.
  803. * @returns {Object} Object that contains 'x' and 'y' properties of the
  804. * point in the viewport coordinate space.
  805. * @see {@link convertToPdfPoint}
  806. * @see {@link convertToViewportRectangle}
  807. */
  808. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  809. return Util.applyTransform([x, y], this.transform);
  810. },
  811. /**
  812. * Converts PDF rectangle to the viewport coordinates.
  813. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  814. * @returns {Array} Contains corresponding coordinates of the rectangle
  815. * in the viewport coordinate space.
  816. * @see {@link convertToViewportPoint}
  817. */
  818. convertToViewportRectangle:
  819. function PageViewport_convertToViewportRectangle(rect) {
  820. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  821. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  822. return [tl[0], tl[1], br[0], br[1]];
  823. },
  824. /**
  825. * Converts viewport coordinates to the PDF location. For examples, useful
  826. * for converting canvas pixel location into PDF one.
  827. * @param x {number} X coordinate.
  828. * @param y {number} Y coordinate.
  829. * @returns {Object} Object that contains 'x' and 'y' properties of the
  830. * point in the PDF coordinate space.
  831. * @see {@link convertToViewportPoint}
  832. */
  833. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  834. return Util.applyInverseTransform([x, y], this.transform);
  835. }
  836. };
  837. return PageViewport;
  838. })();
  839. var PDFStringTranslateTable = [
  840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  841. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  842. 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,
  843. 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,
  844. 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,
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  846. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  847. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  848. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  849. ];
  850. function stringToPDFString(str) {
  851. var i, n = str.length, strBuf = [];
  852. if (str[0] === '\xFE' && str[1] === '\xFF') {
  853. // UTF16BE BOM
  854. for (i = 2; i < n; i += 2) {
  855. strBuf.push(String.fromCharCode(
  856. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  857. }
  858. } else {
  859. for (i = 0; i < n; ++i) {
  860. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  861. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  862. }
  863. }
  864. return strBuf.join('');
  865. }
  866. function stringToUTF8String(str) {
  867. return decodeURIComponent(escape(str));
  868. }
  869. function isEmptyObj(obj) {
  870. for (var key in obj) {
  871. return false;
  872. }
  873. return true;
  874. }
  875. function isBool(v) {
  876. return typeof v === 'boolean';
  877. }
  878. function isInt(v) {
  879. return typeof v === 'number' && ((v | 0) === v);
  880. }
  881. function isNum(v) {
  882. return typeof v === 'number';
  883. }
  884. function isString(v) {
  885. return typeof v === 'string';
  886. }
  887. function isNull(v) {
  888. return v === null;
  889. }
  890. function isName(v) {
  891. return v instanceof Name;
  892. }
  893. function isCmd(v, cmd) {
  894. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  895. }
  896. function isDict(v, type) {
  897. if (!(v instanceof Dict)) {
  898. return false;
  899. }
  900. if (!type) {
  901. return true;
  902. }
  903. var dictType = v.get('Type');
  904. return isName(dictType) && dictType.name === type;
  905. }
  906. function isArray(v) {
  907. return v instanceof Array;
  908. }
  909. function isStream(v) {
  910. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  911. }
  912. function isArrayBuffer(v) {
  913. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  914. }
  915. function isRef(v) {
  916. return v instanceof Ref;
  917. }
  918. /**
  919. * Promise Capability object.
  920. *
  921. * @typedef {Object} PromiseCapability
  922. * @property {Promise} promise - A promise object.
  923. * @property {function} resolve - Fullfills the promise.
  924. * @property {function} reject - Rejects the promise.
  925. */
  926. /**
  927. * Creates a promise capability object.
  928. * @alias PDFJS.createPromiseCapability
  929. *
  930. * @return {PromiseCapability} A capability object contains:
  931. * - a Promise, resolve and reject methods.
  932. */
  933. function createPromiseCapability() {
  934. var capability = {};
  935. capability.promise = new Promise(function (resolve, reject) {
  936. capability.resolve = resolve;
  937. capability.reject = reject;
  938. });
  939. return capability;
  940. }
  941. PDFJS.createPromiseCapability = createPromiseCapability;
  942. /**
  943. * Polyfill for Promises:
  944. * The following promise implementation tries to generally implement the
  945. * Promise/A+ spec. Some notable differences from other promise libaries are:
  946. * - There currently isn't a seperate deferred and promise object.
  947. * - Unhandled rejections eventually show an error if they aren't handled.
  948. *
  949. * Based off of the work in:
  950. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  951. */
  952. (function PromiseClosure() {
  953. if (globalScope.Promise) {
  954. // Promises existing in the DOM/Worker, checking presence of all/resolve
  955. if (typeof globalScope.Promise.all !== 'function') {
  956. globalScope.Promise.all = function (iterable) {
  957. var count = 0, results = [], resolve, reject;
  958. var promise = new globalScope.Promise(function (resolve_, reject_) {
  959. resolve = resolve_;
  960. reject = reject_;
  961. });
  962. iterable.forEach(function (p, i) {
  963. count++;
  964. p.then(function (result) {
  965. results[i] = result;
  966. count--;
  967. if (count === 0) {
  968. resolve(results);
  969. }
  970. }, reject);
  971. });
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. return promise;
  976. };
  977. }
  978. if (typeof globalScope.Promise.resolve !== 'function') {
  979. globalScope.Promise.resolve = function (value) {
  980. return new globalScope.Promise(function (resolve) { resolve(value); });
  981. };
  982. }
  983. if (typeof globalScope.Promise.reject !== 'function') {
  984. globalScope.Promise.reject = function (reason) {
  985. return new globalScope.Promise(function (resolve, reject) {
  986. reject(reason);
  987. });
  988. };
  989. }
  990. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  991. globalScope.Promise.prototype.catch = function (onReject) {
  992. return globalScope.Promise.prototype.then(undefined, onReject);
  993. };
  994. }
  995. return;
  996. }
  997. var STATUS_PENDING = 0;
  998. var STATUS_RESOLVED = 1;
  999. var STATUS_REJECTED = 2;
  1000. // In an attempt to avoid silent exceptions, unhandled rejections are
  1001. // tracked and if they aren't handled in a certain amount of time an
  1002. // error is logged.
  1003. var REJECTION_TIMEOUT = 500;
  1004. var HandlerManager = {
  1005. handlers: [],
  1006. running: false,
  1007. unhandledRejections: [],
  1008. pendingRejectionCheck: false,
  1009. scheduleHandlers: function scheduleHandlers(promise) {
  1010. if (promise._status === STATUS_PENDING) {
  1011. return;
  1012. }
  1013. this.handlers = this.handlers.concat(promise._handlers);
  1014. promise._handlers = [];
  1015. if (this.running) {
  1016. return;
  1017. }
  1018. this.running = true;
  1019. setTimeout(this.runHandlers.bind(this), 0);
  1020. },
  1021. runHandlers: function runHandlers() {
  1022. var RUN_TIMEOUT = 1; // ms
  1023. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1024. while (this.handlers.length > 0) {
  1025. var handler = this.handlers.shift();
  1026. var nextStatus = handler.thisPromise._status;
  1027. var nextValue = handler.thisPromise._value;
  1028. try {
  1029. if (nextStatus === STATUS_RESOLVED) {
  1030. if (typeof handler.onResolve === 'function') {
  1031. nextValue = handler.onResolve(nextValue);
  1032. }
  1033. } else if (typeof handler.onReject === 'function') {
  1034. nextValue = handler.onReject(nextValue);
  1035. nextStatus = STATUS_RESOLVED;
  1036. if (handler.thisPromise._unhandledRejection) {
  1037. this.removeUnhandeledRejection(handler.thisPromise);
  1038. }
  1039. }
  1040. } catch (ex) {
  1041. nextStatus = STATUS_REJECTED;
  1042. nextValue = ex;
  1043. }
  1044. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1045. if (Date.now() >= timeoutAt) {
  1046. break;
  1047. }
  1048. }
  1049. if (this.handlers.length > 0) {
  1050. setTimeout(this.runHandlers.bind(this), 0);
  1051. return;
  1052. }
  1053. this.running = false;
  1054. },
  1055. addUnhandledRejection: function addUnhandledRejection(promise) {
  1056. this.unhandledRejections.push({
  1057. promise: promise,
  1058. time: Date.now()
  1059. });
  1060. this.scheduleRejectionCheck();
  1061. },
  1062. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1063. promise._unhandledRejection = false;
  1064. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1065. if (this.unhandledRejections[i].promise === promise) {
  1066. this.unhandledRejections.splice(i);
  1067. i--;
  1068. }
  1069. }
  1070. },
  1071. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1072. if (this.pendingRejectionCheck) {
  1073. return;
  1074. }
  1075. this.pendingRejectionCheck = true;
  1076. setTimeout(function rejectionCheck() {
  1077. this.pendingRejectionCheck = false;
  1078. var now = Date.now();
  1079. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1080. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1081. var unhandled = this.unhandledRejections[i].promise._value;
  1082. var msg = 'Unhandled rejection: ' + unhandled;
  1083. if (unhandled.stack) {
  1084. msg += '\n' + unhandled.stack;
  1085. }
  1086. warn(msg);
  1087. this.unhandledRejections.splice(i);
  1088. i--;
  1089. }
  1090. }
  1091. if (this.unhandledRejections.length) {
  1092. this.scheduleRejectionCheck();
  1093. }
  1094. }.bind(this), REJECTION_TIMEOUT);
  1095. }
  1096. };
  1097. function Promise(resolver) {
  1098. this._status = STATUS_PENDING;
  1099. this._handlers = [];
  1100. try {
  1101. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1102. } catch (e) {
  1103. this._reject(e);
  1104. }
  1105. }
  1106. /**
  1107. * Builds a promise that is resolved when all the passed in promises are
  1108. * resolved.
  1109. * @param {array} array of data and/or promises to wait for.
  1110. * @return {Promise} New dependant promise.
  1111. */
  1112. Promise.all = function Promise_all(promises) {
  1113. var resolveAll, rejectAll;
  1114. var deferred = new Promise(function (resolve, reject) {
  1115. resolveAll = resolve;
  1116. rejectAll = reject;
  1117. });
  1118. var unresolved = promises.length;
  1119. var results = [];
  1120. if (unresolved === 0) {
  1121. resolveAll(results);
  1122. return deferred;
  1123. }
  1124. function reject(reason) {
  1125. if (deferred._status === STATUS_REJECTED) {
  1126. return;
  1127. }
  1128. results = [];
  1129. rejectAll(reason);
  1130. }
  1131. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1132. var promise = promises[i];
  1133. var resolve = (function(i) {
  1134. return function(value) {
  1135. if (deferred._status === STATUS_REJECTED) {
  1136. return;
  1137. }
  1138. results[i] = value;
  1139. unresolved--;
  1140. if (unresolved === 0) {
  1141. resolveAll(results);
  1142. }
  1143. };
  1144. })(i);
  1145. if (Promise.isPromise(promise)) {
  1146. promise.then(resolve, reject);
  1147. } else {
  1148. resolve(promise);
  1149. }
  1150. }
  1151. return deferred;
  1152. };
  1153. /**
  1154. * Checks if the value is likely a promise (has a 'then' function).
  1155. * @return {boolean} true if value is thenable
  1156. */
  1157. Promise.isPromise = function Promise_isPromise(value) {
  1158. return value && typeof value.then === 'function';
  1159. };
  1160. /**
  1161. * Creates resolved promise
  1162. * @param value resolve value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.resolve = function Promise_resolve(value) {
  1166. return new Promise(function (resolve) { resolve(value); });
  1167. };
  1168. /**
  1169. * Creates rejected promise
  1170. * @param reason rejection value
  1171. * @returns {Promise}
  1172. */
  1173. Promise.reject = function Promise_reject(reason) {
  1174. return new Promise(function (resolve, reject) { reject(reason); });
  1175. };
  1176. Promise.prototype = {
  1177. _status: null,
  1178. _value: null,
  1179. _handlers: null,
  1180. _unhandledRejection: null,
  1181. _updateStatus: function Promise__updateStatus(status, value) {
  1182. if (this._status === STATUS_RESOLVED ||
  1183. this._status === STATUS_REJECTED) {
  1184. return;
  1185. }
  1186. if (status === STATUS_RESOLVED &&
  1187. Promise.isPromise(value)) {
  1188. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1189. this._updateStatus.bind(this, STATUS_REJECTED));
  1190. return;
  1191. }
  1192. this._status = status;
  1193. this._value = value;
  1194. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1195. this._unhandledRejection = true;
  1196. HandlerManager.addUnhandledRejection(this);
  1197. }
  1198. HandlerManager.scheduleHandlers(this);
  1199. },
  1200. _resolve: function Promise_resolve(value) {
  1201. this._updateStatus(STATUS_RESOLVED, value);
  1202. },
  1203. _reject: function Promise_reject(reason) {
  1204. this._updateStatus(STATUS_REJECTED, reason);
  1205. },
  1206. then: function Promise_then(onResolve, onReject) {
  1207. var nextPromise = new Promise(function (resolve, reject) {
  1208. this.resolve = resolve;
  1209. this.reject = reject;
  1210. });
  1211. this._handlers.push({
  1212. thisPromise: this,
  1213. onResolve: onResolve,
  1214. onReject: onReject,
  1215. nextPromise: nextPromise
  1216. });
  1217. HandlerManager.scheduleHandlers(this);
  1218. return nextPromise;
  1219. },
  1220. catch: function Promise_catch(onReject) {
  1221. return this.then(undefined, onReject);
  1222. }
  1223. };
  1224. globalScope.Promise = Promise;
  1225. })();
  1226. var StatTimer = (function StatTimerClosure() {
  1227. function rpad(str, pad, length) {
  1228. while (str.length < length) {
  1229. str += pad;
  1230. }
  1231. return str;
  1232. }
  1233. function StatTimer() {
  1234. this.started = {};
  1235. this.times = [];
  1236. this.enabled = true;
  1237. }
  1238. StatTimer.prototype = {
  1239. time: function StatTimer_time(name) {
  1240. if (!this.enabled) {
  1241. return;
  1242. }
  1243. if (name in this.started) {
  1244. warn('Timer is already running for ' + name);
  1245. }
  1246. this.started[name] = Date.now();
  1247. },
  1248. timeEnd: function StatTimer_timeEnd(name) {
  1249. if (!this.enabled) {
  1250. return;
  1251. }
  1252. if (!(name in this.started)) {
  1253. warn('Timer has not been started for ' + name);
  1254. }
  1255. this.times.push({
  1256. 'name': name,
  1257. 'start': this.started[name],
  1258. 'end': Date.now()
  1259. });
  1260. // Remove timer from started so it can be called again.
  1261. delete this.started[name];
  1262. },
  1263. toString: function StatTimer_toString() {
  1264. var i, ii;
  1265. var times = this.times;
  1266. var out = '';
  1267. // Find the longest name for padding purposes.
  1268. var longest = 0;
  1269. for (i = 0, ii = times.length; i < ii; ++i) {
  1270. var name = times[i]['name'];
  1271. if (name.length > longest) {
  1272. longest = name.length;
  1273. }
  1274. }
  1275. for (i = 0, ii = times.length; i < ii; ++i) {
  1276. var span = times[i];
  1277. var duration = span.end - span.start;
  1278. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1279. }
  1280. return out;
  1281. }
  1282. };
  1283. return StatTimer;
  1284. })();
  1285. PDFJS.createBlob = function createBlob(data, contentType) {
  1286. if (typeof Blob !== 'undefined') {
  1287. return new Blob([data], { type: contentType });
  1288. }
  1289. // Blob builder is deprecated in FF14 and removed in FF18.
  1290. var bb = new MozBlobBuilder();
  1291. bb.append(data);
  1292. return bb.getBlob(contentType);
  1293. };
  1294. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1295. // Blob/createObjectURL is not available, falling back to data schema.
  1296. var digits =
  1297. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1298. return function createObjectURL(data, contentType) {
  1299. if (!PDFJS.disableCreateObjectURL &&
  1300. typeof URL !== 'undefined' && URL.createObjectURL) {
  1301. var blob = PDFJS.createBlob(data, contentType);
  1302. return URL.createObjectURL(blob);
  1303. }
  1304. var buffer = 'data:' + contentType + ';base64,';
  1305. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1306. var b1 = data[i] & 0xFF;
  1307. var b2 = data[i + 1] & 0xFF;
  1308. var b3 = data[i + 2] & 0xFF;
  1309. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1310. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1311. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1312. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1313. }
  1314. return buffer;
  1315. };
  1316. })();
  1317. function MessageHandler(name, comObj) {
  1318. this.name = name;
  1319. this.comObj = comObj;
  1320. this.callbackIndex = 1;
  1321. this.postMessageTransfers = true;
  1322. var callbacksCapabilities = this.callbacksCapabilities = {};
  1323. var ah = this.actionHandler = {};
  1324. ah['console_log'] = [function ahConsoleLog(data) {
  1325. console.log.apply(console, data);
  1326. }];
  1327. ah['console_error'] = [function ahConsoleError(data) {
  1328. console.error.apply(console, data);
  1329. }];
  1330. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1331. UnsupportedManager.notify(data);
  1332. }];
  1333. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1334. var data = event.data;
  1335. if (data.isReply) {
  1336. var callbackId = data.callbackId;
  1337. if (data.callbackId in callbacksCapabilities) {
  1338. var callback = callbacksCapabilities[callbackId];
  1339. delete callbacksCapabilities[callbackId];
  1340. if ('error' in data) {
  1341. callback.reject(data.error);
  1342. } else {
  1343. callback.resolve(data.data);
  1344. }
  1345. } else {
  1346. error('Cannot resolve callback ' + callbackId);
  1347. }
  1348. } else if (data.action in ah) {
  1349. var action = ah[data.action];
  1350. if (data.callbackId) {
  1351. Promise.resolve().then(function () {
  1352. return action[0].call(action[1], data.data);
  1353. }).then(function (result) {
  1354. comObj.postMessage({
  1355. isReply: true,
  1356. callbackId: data.callbackId,
  1357. data: result
  1358. });
  1359. }, function (reason) {
  1360. comObj.postMessage({
  1361. isReply: true,
  1362. callbackId: data.callbackId,
  1363. error: reason
  1364. });
  1365. });
  1366. } else {
  1367. action[0].call(action[1], data.data);
  1368. }
  1369. } else {
  1370. error('Unknown action from worker: ' + data.action);
  1371. }
  1372. };
  1373. }
  1374. MessageHandler.prototype = {
  1375. on: function messageHandlerOn(actionName, handler, scope) {
  1376. var ah = this.actionHandler;
  1377. if (ah[actionName]) {
  1378. error('There is already an actionName called "' + actionName + '"');
  1379. }
  1380. ah[actionName] = [handler, scope];
  1381. },
  1382. /**
  1383. * Sends a message to the comObj to invoke the action with the supplied data.
  1384. * @param {String} actionName Action to call.
  1385. * @param {JSON} data JSON data to send.
  1386. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1387. */
  1388. send: function messageHandlerSend(actionName, data, transfers) {
  1389. var message = {
  1390. action: actionName,
  1391. data: data
  1392. };
  1393. this.postMessage(message, transfers);
  1394. },
  1395. /**
  1396. * Sends a message to the comObj to invoke the action with the supplied data.
  1397. * Expects that other side will callback with the response.
  1398. * @param {String} actionName Action to call.
  1399. * @param {JSON} data JSON data to send.
  1400. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1401. * @returns {Promise} Promise to be resolved with response data.
  1402. */
  1403. sendWithPromise:
  1404. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1405. var callbackId = this.callbackIndex++;
  1406. var message = {
  1407. action: actionName,
  1408. data: data,
  1409. callbackId: callbackId
  1410. };
  1411. var capability = createPromiseCapability();
  1412. this.callbacksCapabilities[callbackId] = capability;
  1413. try {
  1414. this.postMessage(message, transfers);
  1415. } catch (e) {
  1416. capability.reject(e);
  1417. }
  1418. return capability.promise;
  1419. },
  1420. /**
  1421. * Sends raw message to the comObj.
  1422. * @private
  1423. * @param message {Object} Raw message.
  1424. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1425. */
  1426. postMessage: function (message, transfers) {
  1427. if (transfers && this.postMessageTransfers) {
  1428. this.comObj.postMessage(message, transfers);
  1429. } else {
  1430. this.comObj.postMessage(message);
  1431. }
  1432. }
  1433. };
  1434. function loadJpegStream(id, imageUrl, objs) {
  1435. var img = new Image();
  1436. img.onload = (function loadJpegStream_onloadClosure() {
  1437. objs.resolve(id, img);
  1438. });
  1439. img.onerror = (function loadJpegStream_onerrorClosure() {
  1440. objs.resolve(id, null);
  1441. warn('Error during JPEG image loading');
  1442. });
  1443. img.src = imageUrl;
  1444. }
  1445. /**
  1446. * The maximum allowed image size in total pixels e.g. width * height. Images
  1447. * above this value will not be drawn. Use -1 for no limit.
  1448. * @var {number}
  1449. */
  1450. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1451. -1 : PDFJS.maxImageSize);
  1452. /**
  1453. * The url of where the predefined Adobe CMaps are located. Include trailing
  1454. * slash.
  1455. * @var {string}
  1456. */
  1457. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1458. /**
  1459. * Specifies if CMaps are binary packed.
  1460. * @var {boolean}
  1461. */
  1462. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1463. /*
  1464. * By default fonts are converted to OpenType fonts and loaded via font face
  1465. * rules. If disabled, the font will be rendered using a built in font renderer
  1466. * that constructs the glyphs with primitive path commands.
  1467. * @var {boolean}
  1468. */
  1469. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1470. false : PDFJS.disableFontFace);
  1471. /**
  1472. * Path for image resources, mainly for annotation icons. Include trailing
  1473. * slash.
  1474. * @var {string}
  1475. */
  1476. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1477. '' : PDFJS.imageResourcesPath);
  1478. /**
  1479. * Disable the web worker and run all code on the main thread. This will happen
  1480. * automatically if the browser doesn't support workers or sending typed arrays
  1481. * to workers.
  1482. * @var {boolean}
  1483. */
  1484. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1485. false : PDFJS.disableWorker);
  1486. /**
  1487. * Path and filename of the worker file. Required when the worker is enabled in
  1488. * development mode. If unspecified in the production build, the worker will be
  1489. * loaded based on the location of the pdf.js file.
  1490. * @var {string}
  1491. */
  1492. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1493. /**
  1494. * Disable range request loading of PDF files. When enabled and if the server
  1495. * supports partial content requests then the PDF will be fetched in chunks.
  1496. * Enabled (false) by default.
  1497. * @var {boolean}
  1498. */
  1499. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1500. false : PDFJS.disableRange);
  1501. /**
  1502. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1503. * in chunks. This default behavior can be disabled.
  1504. * @var {boolean}
  1505. */
  1506. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1507. false : PDFJS.disableStream);
  1508. /**
  1509. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1510. * will automatically keep fetching more data even if it isn't needed to display
  1511. * the current page. This default behavior can be disabled.
  1512. * @var {boolean}
  1513. */
  1514. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1515. false : PDFJS.disableAutoFetch);
  1516. /**
  1517. * Enables special hooks for debugging PDF.js.
  1518. * @var {boolean}
  1519. */
  1520. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1521. /**
  1522. * Enables transfer usage in postMessage for ArrayBuffers.
  1523. * @var {boolean}
  1524. */
  1525. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1526. true : PDFJS.postMessageTransfers);
  1527. /**
  1528. * Disables URL.createObjectURL usage.
  1529. * @var {boolean}
  1530. */
  1531. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1532. false : PDFJS.disableCreateObjectURL);
  1533. /**
  1534. * Disables WebGL usage.
  1535. * @var {boolean}
  1536. */
  1537. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1538. true : PDFJS.disableWebGL);
  1539. /**
  1540. * Enables CSS only zooming.
  1541. * @var {boolean}
  1542. */
  1543. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1544. false : PDFJS.useOnlyCssZoom);
  1545. /**
  1546. * Controls the logging level.
  1547. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1548. * - errors
  1549. * - warnings [default]
  1550. * - infos
  1551. * @var {number}
  1552. */
  1553. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1554. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1555. /**
  1556. * The maximum supported canvas size in total pixels e.g. width * height.
  1557. * The default value is 4096 * 4096. Use -1 for no limit.
  1558. * @var {number}
  1559. */
  1560. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1561. 16777216 : PDFJS.maxCanvasPixels);
  1562. /**
  1563. * Document initialization / loading parameters object.
  1564. *
  1565. * @typedef {Object} DocumentInitParameters
  1566. * @property {string} url - The URL of the PDF.
  1567. * @property {TypedArray} data - A typed array with PDF data.
  1568. * @property {Object} httpHeaders - Basic authentication headers.
  1569. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1570. * Access-Control requests should be made using credentials such as cookies
  1571. * or authorization headers. The default is false.
  1572. * @property {string} password - For decrypting password-protected PDFs.
  1573. * @property {TypedArray} initialData - A typed array with the first portion or
  1574. * all of the pdf data. Used by the extension since some data is already
  1575. * loaded before the switch to range requests.
  1576. */
  1577. /**
  1578. * @typedef {Object} PDFDocumentStats
  1579. * @property {Array} streamTypes - Used stream types in the document (an item
  1580. * is set to true if specific stream ID was used in the document).
  1581. * @property {Array} fontTypes - Used font type in the document (an item is set
  1582. * to true if specific font ID was used in the document).
  1583. */
  1584. /**
  1585. * This is the main entry point for loading a PDF and interacting with it.
  1586. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1587. * is used, which means it must follow the same origin rules that any XHR does
  1588. * e.g. No cross domain requests without CORS.
  1589. *
  1590. * @param {string|TypedArray|DocumentInitParameters} source Can be a url to
  1591. * where a PDF is located, a typed array (Uint8Array) already populated with
  1592. * data or parameter object.
  1593. *
  1594. * @param {Object} pdfDataRangeTransport is optional. It is used if you want
  1595. * to manually serve range requests for data in the PDF. See viewer.js for
  1596. * an example of pdfDataRangeTransport's interface.
  1597. *
  1598. * @param {function} passwordCallback is optional. It is used to request a
  1599. * password if wrong or no password was provided. The callback receives two
  1600. * parameters: function that needs to be called with new password and reason
  1601. * (see {PasswordResponses}).
  1602. *
  1603. * @param {function} progressCallback is optional. It is used to be able to
  1604. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1605. * a loading bar). The callback receives an {Object} with the properties:
  1606. * {number} loaded and {number} total.
  1607. *
  1608. * @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
  1609. * object.
  1610. */
  1611. PDFJS.getDocument = function getDocument(source,
  1612. pdfDataRangeTransport,
  1613. passwordCallback,
  1614. progressCallback) {
  1615. var workerInitializedCapability, workerReadyCapability, transport;
  1616. if (typeof source === 'string') {
  1617. source = { url: source };
  1618. } else if (isArrayBuffer(source)) {
  1619. source = { data: source };
  1620. } else if (typeof source !== 'object') {
  1621. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1622. 'string or a parameter object');
  1623. }
  1624. if (!source.url && !source.data) {
  1625. error('Invalid parameter array, need either .data or .url');
  1626. }
  1627. // copy/use all keys as is except 'url' -- full path is required
  1628. var params = {};
  1629. for (var key in source) {
  1630. if (key === 'url' && typeof window !== 'undefined') {
  1631. params[key] = combineUrl(window.location.href, source[key]);
  1632. continue;
  1633. }
  1634. params[key] = source[key];
  1635. }
  1636. workerInitializedCapability = createPromiseCapability();
  1637. workerReadyCapability = createPromiseCapability();
  1638. transport = new WorkerTransport(workerInitializedCapability,
  1639. workerReadyCapability, pdfDataRangeTransport,
  1640. progressCallback);
  1641. workerInitializedCapability.promise.then(function transportInitialized() {
  1642. transport.passwordCallback = passwordCallback;
  1643. transport.fetchDocument(params);
  1644. });
  1645. return workerReadyCapability.promise;
  1646. };
  1647. /**
  1648. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1649. * properties that can be read synchronously.
  1650. * @class
  1651. */
  1652. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1653. function PDFDocumentProxy(pdfInfo, transport) {
  1654. this.pdfInfo = pdfInfo;
  1655. this.transport = transport;
  1656. }
  1657. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1658. /**
  1659. * @return {number} Total number of pages the PDF contains.
  1660. */
  1661. get numPages() {
  1662. return this.pdfInfo.numPages;
  1663. },
  1664. /**
  1665. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1666. * unique.
  1667. */
  1668. get fingerprint() {
  1669. return this.pdfInfo.fingerprint;
  1670. },
  1671. /**
  1672. * @param {number} pageNumber The page number to get. The first page is 1.
  1673. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1674. * object.
  1675. */
  1676. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1677. return this.transport.getPage(pageNumber);
  1678. },
  1679. /**
  1680. * @param {{num: number, gen: number}} ref The page reference. Must have
  1681. * the 'num' and 'gen' properties.
  1682. * @return {Promise} A promise that is resolved with the page index that is
  1683. * associated with the reference.
  1684. */
  1685. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1686. return this.transport.getPageIndex(ref);
  1687. },
  1688. /**
  1689. * @return {Promise} A promise that is resolved with a lookup table for
  1690. * mapping named destinations to reference numbers.
  1691. *
  1692. * This can be slow for large documents: use getDestination instead
  1693. */
  1694. getDestinations: function PDFDocumentProxy_getDestinations() {
  1695. return this.transport.getDestinations();
  1696. },
  1697. /**
  1698. * @param {string} id The named destination to get.
  1699. * @return {Promise} A promise that is resolved with all information
  1700. * of the given named destination.
  1701. */
  1702. getDestination: function PDFDocumentProxy_getDestination(id) {
  1703. return this.transport.getDestination(id);
  1704. },
  1705. /**
  1706. * @return {Promise} A promise that is resolved with a lookup table for
  1707. * mapping named attachments to their content.
  1708. */
  1709. getAttachments: function PDFDocumentProxy_getAttachments() {
  1710. return this.transport.getAttachments();
  1711. },
  1712. /**
  1713. * @return {Promise} A promise that is resolved with an array of all the
  1714. * JavaScript strings in the name tree.
  1715. */
  1716. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1717. return this.transport.getJavaScript();
  1718. },
  1719. /**
  1720. * @return {Promise} A promise that is resolved with an {Array} that is a
  1721. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1722. * [
  1723. * {
  1724. * title: string,
  1725. * bold: boolean,
  1726. * italic: boolean,
  1727. * color: rgb array,
  1728. * dest: dest obj,
  1729. * items: array of more items like this
  1730. * },
  1731. * ...
  1732. * ].
  1733. */
  1734. getOutline: function PDFDocumentProxy_getOutline() {
  1735. return this.transport.getOutline();
  1736. },
  1737. /**
  1738. * @return {Promise} A promise that is resolved with an {Object} that has
  1739. * info and metadata properties. Info is an {Object} filled with anything
  1740. * available in the information dictionary and similarly metadata is a
  1741. * {Metadata} object with information from the metadata section of the PDF.
  1742. */
  1743. getMetadata: function PDFDocumentProxy_getMetadata() {
  1744. return this.transport.getMetadata();
  1745. },
  1746. /**
  1747. * @return {Promise} A promise that is resolved with a TypedArray that has
  1748. * the raw data from the PDF.
  1749. */
  1750. getData: function PDFDocumentProxy_getData() {
  1751. return this.transport.getData();
  1752. },
  1753. /**
  1754. * @return {Promise} A promise that is resolved when the document's data
  1755. * is loaded. It is resolved with an {Object} that contains the length
  1756. * property that indicates size of the PDF data in bytes.
  1757. */
  1758. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1759. return this.transport.downloadInfoCapability.promise;
  1760. },
  1761. /**
  1762. * @returns {Promise} A promise this is resolved with current stats about
  1763. * document structures (see {@link PDFDocumentStats}).
  1764. */
  1765. getStats: function PDFDocumentProxy_getStats() {
  1766. return this.transport.getStats();
  1767. },
  1768. /**
  1769. * Cleans up resources allocated by the document, e.g. created @font-face.
  1770. */
  1771. cleanup: function PDFDocumentProxy_cleanup() {
  1772. this.transport.startCleanup();
  1773. },
  1774. /**
  1775. * Destroys current document instance and terminates worker.
  1776. */
  1777. destroy: function PDFDocumentProxy_destroy() {
  1778. this.transport.destroy();
  1779. }
  1780. };
  1781. return PDFDocumentProxy;
  1782. })();
  1783. /**
  1784. * Page text content.
  1785. *
  1786. * @typedef {Object} TextContent
  1787. * @property {array} items - array of {@link TextItem}
  1788. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1789. * name.
  1790. */
  1791. /**
  1792. * Page text content part.
  1793. *
  1794. * @typedef {Object} TextItem
  1795. * @property {string} str - text content.
  1796. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1797. * @property {array} transform - transformation matrix.
  1798. * @property {number} width - width in device space.
  1799. * @property {number} height - height in device space.
  1800. * @property {string} fontName - font name used by pdf.js for converted font.
  1801. */
  1802. /**
  1803. * Text style.
  1804. *
  1805. * @typedef {Object} TextStyle
  1806. * @property {number} ascent - font ascent.
  1807. * @property {number} descent - font descent.
  1808. * @property {boolean} vertical - text is in vertical mode.
  1809. * @property {string} fontFamily - possible font family
  1810. */
  1811. /**
  1812. * Page render parameters.
  1813. *
  1814. * @typedef {Object} RenderParameters
  1815. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1816. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1817. * calling of PDFPage.getViewport method.
  1818. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1819. * (default value is 'display').
  1820. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1821. * endLayout and appendImage functions.
  1822. * @property {function} continueCallback - (optional) A function that will be
  1823. * called each time the rendering is paused. To continue
  1824. * rendering call the function that is the first argument
  1825. * to the callback.
  1826. */
  1827. /**
  1828. * PDF page operator list.
  1829. *
  1830. * @typedef {Object} PDFOperatorList
  1831. * @property {Array} fnArray - Array containing the operator functions.
  1832. * @property {Array} argsArray - Array containing the arguments of the
  1833. * functions.
  1834. */
  1835. /**
  1836. * Proxy to a PDFPage in the worker thread.
  1837. * @class
  1838. */
  1839. var PDFPageProxy = (function PDFPageProxyClosure() {
  1840. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1841. this.pageIndex = pageIndex;
  1842. this.pageInfo = pageInfo;
  1843. this.transport = transport;
  1844. this.stats = new StatTimer();
  1845. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1846. this.commonObjs = transport.commonObjs;
  1847. this.objs = new PDFObjects();
  1848. this.cleanupAfterRender = false;
  1849. this.pendingDestroy = false;
  1850. this.intentStates = {};
  1851. }
  1852. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  1853. /**
  1854. * @return {number} Page number of the page. First page is 1.
  1855. */
  1856. get pageNumber() {
  1857. return this.pageIndex + 1;
  1858. },
  1859. /**
  1860. * @return {number} The number of degrees the page is rotated clockwise.
  1861. */
  1862. get rotate() {
  1863. return this.pageInfo.rotate;
  1864. },
  1865. /**
  1866. * @return {Object} The reference that points to this page. It has 'num' and
  1867. * 'gen' properties.
  1868. */
  1869. get ref() {
  1870. return this.pageInfo.ref;
  1871. },
  1872. /**
  1873. * @return {Array} An array of the visible portion of the PDF page in the
  1874. * user space units - [x1, y1, x2, y2].
  1875. */
  1876. get view() {
  1877. return this.pageInfo.view;
  1878. },
  1879. /**
  1880. * @param {number} scale The desired scale of the viewport.
  1881. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  1882. * defaults to the page rotation.
  1883. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  1884. * along with transforms required for rendering.
  1885. */
  1886. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  1887. if (arguments.length < 2) {
  1888. rotate = this.rotate;
  1889. }
  1890. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  1891. },
  1892. /**
  1893. * @return {Promise} A promise that is resolved with an {Array} of the
  1894. * annotation objects.
  1895. */
  1896. getAnnotations: function PDFPageProxy_getAnnotations() {
  1897. if (this.annotationsPromise) {
  1898. return this.annotationsPromise;
  1899. }
  1900. var promise = this.transport.getAnnotations(this.pageIndex);
  1901. this.annotationsPromise = promise;
  1902. return promise;
  1903. },
  1904. /**
  1905. * Begins the process of rendering a page to the desired context.
  1906. * @param {RenderParameters} params Page render parameters.
  1907. * @return {RenderTask} An object that contains the promise, which
  1908. * is resolved when the page finishes rendering.
  1909. */
  1910. render: function PDFPageProxy_render(params) {
  1911. var stats = this.stats;
  1912. stats.time('Overall');
  1913. // If there was a pending destroy cancel it so no cleanup happens during
  1914. // this call to render.
  1915. this.pendingDestroy = false;
  1916. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  1917. if (!this.intentStates[renderingIntent]) {
  1918. this.intentStates[renderingIntent] = {};
  1919. }
  1920. var intentState = this.intentStates[renderingIntent];
  1921. // If there's no displayReadyCapability yet, then the operatorList
  1922. // was never requested before. Make the request and create the promise.
  1923. if (!intentState.displayReadyCapability) {
  1924. intentState.receivingOperatorList = true;
  1925. intentState.displayReadyCapability = createPromiseCapability();
  1926. intentState.operatorList = {
  1927. fnArray: [],
  1928. argsArray: [],
  1929. lastChunk: false
  1930. };
  1931. this.stats.time('Page Request');
  1932. this.transport.messageHandler.send('RenderPageRequest', {
  1933. pageIndex: this.pageNumber - 1,
  1934. intent: renderingIntent
  1935. });
  1936. }
  1937. var internalRenderTask = new InternalRenderTask(complete, params,
  1938. this.objs,
  1939. this.commonObjs,
  1940. intentState.operatorList,
  1941. this.pageNumber);
  1942. if (!intentState.renderTasks) {
  1943. intentState.renderTasks = [];
  1944. }
  1945. intentState.renderTasks.push(internalRenderTask);
  1946. var renderTask = new RenderTask(internalRenderTask);
  1947. var self = this;
  1948. intentState.displayReadyCapability.promise.then(
  1949. function pageDisplayReadyPromise(transparency) {
  1950. if (self.pendingDestroy) {
  1951. complete();
  1952. return;
  1953. }
  1954. stats.time('Rendering');
  1955. internalRenderTask.initalizeGraphics(transparency);
  1956. internalRenderTask.operatorListChanged();
  1957. },
  1958. function pageDisplayReadPromiseError(reason) {
  1959. complete(reason);
  1960. }
  1961. );
  1962. function complete(error) {
  1963. var i = intentState.renderTasks.indexOf(internalRenderTask);
  1964. if (i >= 0) {
  1965. intentState.renderTasks.splice(i, 1);
  1966. }
  1967. if (self.cleanupAfterRender) {
  1968. self.pendingDestroy = true;
  1969. }
  1970. self._tryDestroy();
  1971. if (error) {
  1972. internalRenderTask.capability.reject(error);
  1973. } else {
  1974. internalRenderTask.capability.resolve();
  1975. }
  1976. stats.timeEnd('Rendering');
  1977. stats.timeEnd('Overall');
  1978. }
  1979. return renderTask;
  1980. },
  1981. /**
  1982. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  1983. * object that represents page's operator list.
  1984. */
  1985. getOperatorList: function PDFPageProxy_getOperatorList() {
  1986. function operatorListChanged() {
  1987. if (intentState.operatorList.lastChunk) {
  1988. intentState.opListReadCapability.resolve(intentState.operatorList);
  1989. }
  1990. }
  1991. var renderingIntent = 'oplist';
  1992. if (!this.intentStates[renderingIntent]) {
  1993. this.intentStates[renderingIntent] = {};
  1994. }
  1995. var intentState = this.intentStates[renderingIntent];
  1996. if (!intentState.opListReadCapability) {
  1997. var opListTask = {};
  1998. opListTask.operatorListChanged = operatorListChanged;
  1999. intentState.receivingOperatorList = true;
  2000. intentState.opListReadCapability = createPromiseCapability();
  2001. intentState.renderTasks = [];
  2002. intentState.renderTasks.push(opListTask);
  2003. intentState.operatorList = {
  2004. fnArray: [],
  2005. argsArray: [],
  2006. lastChunk: false
  2007. };
  2008. this.transport.messageHandler.send('RenderPageRequest', {
  2009. pageIndex: this.pageIndex,
  2010. intent: renderingIntent
  2011. });
  2012. }
  2013. return intentState.opListReadCapability.promise;
  2014. },
  2015. /**
  2016. * @return {Promise} That is resolved a {@link TextContent}
  2017. * object that represent the page text content.
  2018. */
  2019. getTextContent: function PDFPageProxy_getTextContent() {
  2020. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2021. pageIndex: this.pageNumber - 1
  2022. });
  2023. },
  2024. /**
  2025. * Destroys resources allocated by the page.
  2026. */
  2027. destroy: function PDFPageProxy_destroy() {
  2028. this.pendingDestroy = true;
  2029. this._tryDestroy();
  2030. },
  2031. /**
  2032. * For internal use only. Attempts to clean up if rendering is in a state
  2033. * where that's possible.
  2034. * @ignore
  2035. */
  2036. _tryDestroy: function PDFPageProxy__destroy() {
  2037. if (!this.pendingDestroy ||
  2038. Object.keys(this.intentStates).some(function(intent) {
  2039. var intentState = this.intentStates[intent];
  2040. return (intentState.renderTasks.length !== 0 ||
  2041. intentState.receivingOperatorList);
  2042. }, this)) {
  2043. return;
  2044. }
  2045. Object.keys(this.intentStates).forEach(function(intent) {
  2046. delete this.intentStates[intent];
  2047. }, this);
  2048. this.objs.clear();
  2049. this.annotationsPromise = null;
  2050. this.pendingDestroy = false;
  2051. },
  2052. /**
  2053. * For internal use only.
  2054. * @ignore
  2055. */
  2056. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2057. intent) {
  2058. var intentState = this.intentStates[intent];
  2059. // TODO Refactor RenderPageRequest to separate rendering
  2060. // and operator list logic
  2061. if (intentState.displayReadyCapability) {
  2062. intentState.displayReadyCapability.resolve(transparency);
  2063. }
  2064. },
  2065. /**
  2066. * For internal use only.
  2067. * @ignore
  2068. */
  2069. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2070. intent) {
  2071. var intentState = this.intentStates[intent];
  2072. var i, ii;
  2073. // Add the new chunk to the current operator list.
  2074. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2075. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2076. intentState.operatorList.argsArray.push(
  2077. operatorListChunk.argsArray[i]);
  2078. }
  2079. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2080. // Notify all the rendering tasks there are more operators to be consumed.
  2081. for (i = 0; i < intentState.renderTasks.length; i++) {
  2082. intentState.renderTasks[i].operatorListChanged();
  2083. }
  2084. if (operatorListChunk.lastChunk) {
  2085. intentState.receivingOperatorList = false;
  2086. this._tryDestroy();
  2087. }
  2088. }
  2089. };
  2090. return PDFPageProxy;
  2091. })();
  2092. /**
  2093. * For internal use only.
  2094. * @ignore
  2095. */
  2096. var WorkerTransport = (function WorkerTransportClosure() {
  2097. function WorkerTransport(workerInitializedCapability, workerReadyCapability,
  2098. pdfDataRangeTransport, progressCallback) {
  2099. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2100. this.workerInitializedCapability = workerInitializedCapability;
  2101. this.workerReadyCapability = workerReadyCapability;
  2102. this.progressCallback = progressCallback;
  2103. this.commonObjs = new PDFObjects();
  2104. this.pageCache = [];
  2105. this.pagePromises = [];
  2106. this.downloadInfoCapability = createPromiseCapability();
  2107. this.passwordCallback = null;
  2108. // If worker support isn't disabled explicit and the browser has worker
  2109. // support, create a new web worker and test if it/the browser fullfills
  2110. // all requirements to run parts of pdf.js in a web worker.
  2111. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2112. // as it arrives on the worker. Chrome added this with version 15.
  2113. // Either workers are disabled, not supported or have thrown an exception.
  2114. // Thus, we fallback to a faked worker.
  2115. this.setupFakeWorker();
  2116. }
  2117. WorkerTransport.prototype = {
  2118. destroy: function WorkerTransport_destroy() {
  2119. this.pageCache = [];
  2120. this.pagePromises = [];
  2121. var self = this;
  2122. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2123. FontLoader.clear();
  2124. if (self.worker) {
  2125. self.worker.terminate();
  2126. }
  2127. });
  2128. },
  2129. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2130. globalScope.PDFJS.disableWorker = true;
  2131. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2132. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2133. // In the developer build load worker_loader which in turn loads all the
  2134. // other files and resolves the promise. In production only the
  2135. // pdf.worker.js file is needed.
  2136. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2137. }
  2138. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2139. warn('Setting up fake worker.');
  2140. // If we don't use a worker, just post/sendMessage to the main thread.
  2141. var fakeWorker = {
  2142. postMessage: function WorkerTransport_postMessage(obj) {
  2143. fakeWorker.onmessage({data: obj});
  2144. },
  2145. terminate: function WorkerTransport_terminate() {}
  2146. };
  2147. var messageHandler = new MessageHandler('main', fakeWorker);
  2148. this.setupMessageHandler(messageHandler);
  2149. // If the main thread is our worker, setup the handling for the messages
  2150. // the main thread sends to it self.
  2151. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2152. this.workerInitializedCapability.resolve();
  2153. }.bind(this));
  2154. },
  2155. setupMessageHandler:
  2156. function WorkerTransport_setupMessageHandler(messageHandler) {
  2157. this.messageHandler = messageHandler;
  2158. function updatePassword(password) {
  2159. messageHandler.send('UpdatePassword', password);
  2160. }
  2161. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2162. if (pdfDataRangeTransport) {
  2163. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2164. messageHandler.send('OnDataRange', {
  2165. begin: begin,
  2166. chunk: chunk
  2167. });
  2168. });
  2169. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2170. messageHandler.send('OnDataProgress', {
  2171. loaded: loaded
  2172. });
  2173. });
  2174. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2175. messageHandler.send('OnDataRange', {
  2176. chunk: chunk
  2177. });
  2178. });
  2179. messageHandler.on('RequestDataRange',
  2180. function transportDataRange(data) {
  2181. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2182. }, this);
  2183. }
  2184. messageHandler.on('GetDoc', function transportDoc(data) {
  2185. var pdfInfo = data.pdfInfo;
  2186. this.numPages = data.pdfInfo.numPages;
  2187. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2188. this.pdfDocument = pdfDocument;
  2189. this.workerReadyCapability.resolve(pdfDocument);
  2190. }, this);
  2191. messageHandler.on('NeedPassword',
  2192. function transportNeedPassword(exception) {
  2193. if (this.passwordCallback) {
  2194. return this.passwordCallback(updatePassword,
  2195. PasswordResponses.NEED_PASSWORD);
  2196. }
  2197. this.workerReadyCapability.reject(
  2198. new PasswordException(exception.message, exception.code));
  2199. }, this);
  2200. messageHandler.on('IncorrectPassword',
  2201. function transportIncorrectPassword(exception) {
  2202. if (this.passwordCallback) {
  2203. return this.passwordCallback(updatePassword,
  2204. PasswordResponses.INCORRECT_PASSWORD);
  2205. }
  2206. this.workerReadyCapability.reject(
  2207. new PasswordException(exception.message, exception.code));
  2208. }, this);
  2209. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2210. this.workerReadyCapability.reject(
  2211. new InvalidPDFException(exception.message));
  2212. }, this);
  2213. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2214. this.workerReadyCapability.reject(
  2215. new MissingPDFException(exception.message));
  2216. }, this);
  2217. messageHandler.on('UnexpectedResponse',
  2218. function transportUnexpectedResponse(exception) {
  2219. this.workerReadyCapability.reject(
  2220. new UnexpectedResponseException(exception.message, exception.status));
  2221. }, this);
  2222. messageHandler.on('UnknownError',
  2223. function transportUnknownError(exception) {
  2224. this.workerReadyCapability.reject(
  2225. new UnknownErrorException(exception.message, exception.details));
  2226. }, this);
  2227. messageHandler.on('DataLoaded', function transportPage(data) {
  2228. this.downloadInfoCapability.resolve(data);
  2229. }, this);
  2230. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2231. if (this.pdfDataRangeTransport) {
  2232. this.pdfDataRangeTransport.transportReady();
  2233. }
  2234. }, this);
  2235. messageHandler.on('StartRenderPage', function transportRender(data) {
  2236. var page = this.pageCache[data.pageIndex];
  2237. page.stats.timeEnd('Page Request');
  2238. page._startRenderPage(data.transparency, data.intent);
  2239. }, this);
  2240. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2241. var page = this.pageCache[data.pageIndex];
  2242. page._renderPageChunk(data.operatorList, data.intent);
  2243. }, this);
  2244. messageHandler.on('commonobj', function transportObj(data) {
  2245. var id = data[0];
  2246. var type = data[1];
  2247. if (this.commonObjs.hasData(id)) {
  2248. return;
  2249. }
  2250. switch (type) {
  2251. case 'Font':
  2252. var exportedData = data[2];
  2253. var font;
  2254. if ('error' in exportedData) {
  2255. var error = exportedData.error;
  2256. warn('Error during font loading: ' + error);
  2257. this.commonObjs.resolve(id, error);
  2258. break;
  2259. } else {
  2260. font = new FontFaceObject(exportedData);
  2261. }
  2262. FontLoader.bind(
  2263. [font],
  2264. function fontReady(fontObjs) {
  2265. this.commonObjs.resolve(id, font);
  2266. }.bind(this)
  2267. );
  2268. break;
  2269. case 'FontPath':
  2270. this.commonObjs.resolve(id, data[2]);
  2271. break;
  2272. default:
  2273. error('Got unknown common object type ' + type);
  2274. }
  2275. }, this);
  2276. messageHandler.on('obj', function transportObj(data) {
  2277. var id = data[0];
  2278. var pageIndex = data[1];
  2279. var type = data[2];
  2280. var pageProxy = this.pageCache[pageIndex];
  2281. var imageData;
  2282. if (pageProxy.objs.hasData(id)) {
  2283. return;
  2284. }
  2285. switch (type) {
  2286. case 'JpegStream':
  2287. imageData = data[3];
  2288. loadJpegStream(id, imageData, pageProxy.objs);
  2289. break;
  2290. case 'Image':
  2291. imageData = data[3];
  2292. pageProxy.objs.resolve(id, imageData);
  2293. // heuristics that will allow not to store large data
  2294. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2295. if (imageData && 'data' in imageData &&
  2296. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2297. pageProxy.cleanupAfterRender = true;
  2298. }
  2299. break;
  2300. default:
  2301. error('Got unknown object type ' + type);
  2302. }
  2303. }, this);
  2304. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2305. if (this.progressCallback) {
  2306. this.progressCallback({
  2307. loaded: data.loaded,
  2308. total: data.total
  2309. });
  2310. }
  2311. }, this);
  2312. messageHandler.on('PageError', function transportError(data) {
  2313. var page = this.pageCache[data.pageNum - 1];
  2314. var intentState = page.intentStates[data.intent];
  2315. if (intentState.displayReadyCapability) {
  2316. intentState.displayReadyCapability.reject(data.error);
  2317. } else {
  2318. error(data.error);
  2319. }
  2320. }, this);
  2321. messageHandler.on('JpegDecode', function(data) {
  2322. var imageUrl = data[0];
  2323. var components = data[1];
  2324. if (components !== 3 && components !== 1) {
  2325. return Promise.reject(
  2326. new Error('Only 3 components or 1 component can be returned'));
  2327. }
  2328. return new Promise(function (resolve, reject) {
  2329. var img = new Image();
  2330. img.onload = function () {
  2331. var width = img.width;
  2332. var height = img.height;
  2333. var size = width * height;
  2334. var rgbaLength = size * 4;
  2335. var buf = new Uint8Array(size * components);
  2336. var tmpCanvas = createScratchCanvas(width, height);
  2337. var tmpCtx = tmpCanvas.getContext('2d');
  2338. tmpCtx.drawImage(img, 0, 0);
  2339. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2340. var i, j;
  2341. if (components === 3) {
  2342. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2343. buf[j] = data[i];
  2344. buf[j + 1] = data[i + 1];
  2345. buf[j + 2] = data[i + 2];
  2346. }
  2347. } else if (components === 1) {
  2348. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2349. buf[j] = data[i];
  2350. }
  2351. }
  2352. resolve({ data: buf, width: width, height: height});
  2353. };
  2354. img.onerror = function () {
  2355. reject(new Error('JpegDecode failed to load image'));
  2356. };
  2357. img.src = imageUrl;
  2358. });
  2359. });
  2360. },
  2361. fetchDocument: function WorkerTransport_fetchDocument(source) {
  2362. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2363. source.disableStream = PDFJS.disableStream;
  2364. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2365. this.messageHandler.send('GetDocRequest', {
  2366. source: source,
  2367. disableRange: PDFJS.disableRange,
  2368. maxImageSize: PDFJS.maxImageSize,
  2369. cMapUrl: PDFJS.cMapUrl,
  2370. cMapPacked: PDFJS.cMapPacked,
  2371. disableFontFace: PDFJS.disableFontFace,
  2372. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2373. verbosity: PDFJS.verbosity
  2374. });
  2375. },
  2376. getData: function WorkerTransport_getData() {
  2377. return this.messageHandler.sendWithPromise('GetData', null);
  2378. },
  2379. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2380. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2381. (pageNumber|0) !== pageNumber) {
  2382. return Promise.reject(new Error('Invalid page request'));
  2383. }
  2384. var pageIndex = pageNumber - 1;
  2385. if (pageIndex in this.pagePromises) {
  2386. return this.pagePromises[pageIndex];
  2387. }
  2388. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2389. pageIndex: pageIndex
  2390. }).then(function (pageInfo) {
  2391. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2392. this.pageCache[pageIndex] = page;
  2393. return page;
  2394. }.bind(this));
  2395. this.pagePromises[pageIndex] = promise;
  2396. return promise;
  2397. },
  2398. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2399. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2400. },
  2401. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2402. return this.messageHandler.sendWithPromise('GetAnnotations',
  2403. { pageIndex: pageIndex });
  2404. },
  2405. getDestinations: function WorkerTransport_getDestinations() {
  2406. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2407. },
  2408. getDestination: function WorkerTransport_getDestination(id) {
  2409. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2410. },
  2411. getAttachments: function WorkerTransport_getAttachments() {
  2412. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2413. },
  2414. getJavaScript: function WorkerTransport_getJavaScript() {
  2415. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2416. },
  2417. getOutline: function WorkerTransport_getOutline() {
  2418. return this.messageHandler.sendWithPromise('GetOutline', null);
  2419. },
  2420. getMetadata: function WorkerTransport_getMetadata() {
  2421. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2422. then(function transportMetadata(results) {
  2423. return {
  2424. info: results[0],
  2425. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2426. };
  2427. });
  2428. },
  2429. getStats: function WorkerTransport_getStats() {
  2430. return this.messageHandler.sendWithPromise('GetStats', null);
  2431. },
  2432. startCleanup: function WorkerTransport_startCleanup() {
  2433. this.messageHandler.sendWithPromise('Cleanup', null).
  2434. then(function endCleanup() {
  2435. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2436. var page = this.pageCache[i];
  2437. if (page) {
  2438. page.destroy();
  2439. }
  2440. }
  2441. this.commonObjs.clear();
  2442. FontLoader.clear();
  2443. }.bind(this));
  2444. }
  2445. };
  2446. return WorkerTransport;
  2447. })();
  2448. /**
  2449. * A PDF document and page is built of many objects. E.g. there are objects
  2450. * for fonts, images, rendering code and such. These objects might get processed
  2451. * inside of a worker. The `PDFObjects` implements some basic functions to
  2452. * manage these objects.
  2453. * @ignore
  2454. */
  2455. var PDFObjects = (function PDFObjectsClosure() {
  2456. function PDFObjects() {
  2457. this.objs = {};
  2458. }
  2459. PDFObjects.prototype = {
  2460. /**
  2461. * Internal function.
  2462. * Ensures there is an object defined for `objId`.
  2463. */
  2464. ensureObj: function PDFObjects_ensureObj(objId) {
  2465. if (this.objs[objId]) {
  2466. return this.objs[objId];
  2467. }
  2468. var obj = {
  2469. capability: createPromiseCapability(),
  2470. data: null,
  2471. resolved: false
  2472. };
  2473. this.objs[objId] = obj;
  2474. return obj;
  2475. },
  2476. /**
  2477. * If called *without* callback, this returns the data of `objId` but the
  2478. * object needs to be resolved. If it isn't, this function throws.
  2479. *
  2480. * If called *with* a callback, the callback is called with the data of the
  2481. * object once the object is resolved. That means, if you call this
  2482. * function and the object is already resolved, the callback gets called
  2483. * right away.
  2484. */
  2485. get: function PDFObjects_get(objId, callback) {
  2486. // If there is a callback, then the get can be async and the object is
  2487. // not required to be resolved right now
  2488. if (callback) {
  2489. this.ensureObj(objId).capability.promise.then(callback);
  2490. return null;
  2491. }
  2492. // If there isn't a callback, the user expects to get the resolved data
  2493. // directly.
  2494. var obj = this.objs[objId];
  2495. // If there isn't an object yet or the object isn't resolved, then the
  2496. // data isn't ready yet!
  2497. if (!obj || !obj.resolved) {
  2498. error('Requesting object that isn\'t resolved yet ' + objId);
  2499. }
  2500. return obj.data;
  2501. },
  2502. /**
  2503. * Resolves the object `objId` with optional `data`.
  2504. */
  2505. resolve: function PDFObjects_resolve(objId, data) {
  2506. var obj = this.ensureObj(objId);
  2507. obj.resolved = true;
  2508. obj.data = data;
  2509. obj.capability.resolve(data);
  2510. },
  2511. isResolved: function PDFObjects_isResolved(objId) {
  2512. var objs = this.objs;
  2513. if (!objs[objId]) {
  2514. return false;
  2515. } else {
  2516. return objs[objId].resolved;
  2517. }
  2518. },
  2519. hasData: function PDFObjects_hasData(objId) {
  2520. return this.isResolved(objId);
  2521. },
  2522. /**
  2523. * Returns the data of `objId` if object exists, null otherwise.
  2524. */
  2525. getData: function PDFObjects_getData(objId) {
  2526. var objs = this.objs;
  2527. if (!objs[objId] || !objs[objId].resolved) {
  2528. return null;
  2529. } else {
  2530. return objs[objId].data;
  2531. }
  2532. },
  2533. clear: function PDFObjects_clear() {
  2534. this.objs = {};
  2535. }
  2536. };
  2537. return PDFObjects;
  2538. })();
  2539. /**
  2540. * Allows controlling of the rendering tasks.
  2541. * @class
  2542. */
  2543. var RenderTask = (function RenderTaskClosure() {
  2544. function RenderTask(internalRenderTask) {
  2545. this.internalRenderTask = internalRenderTask;
  2546. /**
  2547. * Promise for rendering task completion.
  2548. * @type {Promise}
  2549. */
  2550. this.promise = this.internalRenderTask.capability.promise;
  2551. }
  2552. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2553. /**
  2554. * Cancels the rendering task. If the task is currently rendering it will
  2555. * not be cancelled until graphics pauses with a timeout. The promise that
  2556. * this object extends will resolved when cancelled.
  2557. */
  2558. cancel: function RenderTask_cancel() {
  2559. this.internalRenderTask.cancel();
  2560. },
  2561. /**
  2562. * Registers callback to indicate the rendering task completion.
  2563. *
  2564. * @param {function} onFulfilled The callback for the rendering completion.
  2565. * @param {function} onRejected The callback for the rendering failure.
  2566. * @return {Promise} A promise that is resolved after the onFulfilled or
  2567. * onRejected callback.
  2568. */
  2569. then: function RenderTask_then(onFulfilled, onRejected) {
  2570. return this.promise.then(onFulfilled, onRejected);
  2571. }
  2572. };
  2573. return RenderTask;
  2574. })();
  2575. /**
  2576. * For internal use only.
  2577. * @ignore
  2578. */
  2579. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2580. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2581. pageNumber) {
  2582. this.callback = callback;
  2583. this.params = params;
  2584. this.objs = objs;
  2585. this.commonObjs = commonObjs;
  2586. this.operatorListIdx = null;
  2587. this.operatorList = operatorList;
  2588. this.pageNumber = pageNumber;
  2589. this.running = false;
  2590. this.graphicsReadyCallback = null;
  2591. this.graphicsReady = false;
  2592. this.cancelled = false;
  2593. this.capability = createPromiseCapability();
  2594. // caching this-bound methods
  2595. this._continueBound = this._continue.bind(this);
  2596. this._scheduleNextBound = this._scheduleNext.bind(this);
  2597. this._nextBound = this._next.bind(this);
  2598. }
  2599. InternalRenderTask.prototype = {
  2600. initalizeGraphics:
  2601. function InternalRenderTask_initalizeGraphics(transparency) {
  2602. if (this.cancelled) {
  2603. return;
  2604. }
  2605. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2606. globalScope.StepperManager.enabled) {
  2607. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2608. this.stepper.init(this.operatorList);
  2609. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2610. }
  2611. var params = this.params;
  2612. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2613. this.objs, params.imageLayer);
  2614. this.gfx.beginDrawing(params.viewport, transparency);
  2615. this.operatorListIdx = 0;
  2616. this.graphicsReady = true;
  2617. if (this.graphicsReadyCallback) {
  2618. this.graphicsReadyCallback();
  2619. }
  2620. },
  2621. cancel: function InternalRenderTask_cancel() {
  2622. this.running = false;
  2623. this.cancelled = true;
  2624. this.callback('cancelled');
  2625. },
  2626. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2627. if (!this.graphicsReady) {
  2628. if (!this.graphicsReadyCallback) {
  2629. this.graphicsReadyCallback = this._continueBound;
  2630. }
  2631. return;
  2632. }
  2633. if (this.stepper) {
  2634. this.stepper.updateOperatorList(this.operatorList);
  2635. }
  2636. if (this.running) {
  2637. return;
  2638. }
  2639. this._continue();
  2640. },
  2641. _continue: function InternalRenderTask__continue() {
  2642. this.running = true;
  2643. if (this.cancelled) {
  2644. return;
  2645. }
  2646. if (this.params.continueCallback) {
  2647. this.params.continueCallback(this._scheduleNextBound);
  2648. } else {
  2649. this._scheduleNext();
  2650. }
  2651. },
  2652. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2653. window.requestAnimationFrame(this._nextBound);
  2654. },
  2655. _next: function InternalRenderTask__next() {
  2656. if (this.cancelled) {
  2657. return;
  2658. }
  2659. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2660. this.operatorListIdx,
  2661. this._continueBound,
  2662. this.stepper);
  2663. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2664. this.running = false;
  2665. if (this.operatorList.lastChunk) {
  2666. this.gfx.endDrawing();
  2667. this.callback();
  2668. }
  2669. }
  2670. }
  2671. };
  2672. return InternalRenderTask;
  2673. })();
  2674. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2675. function fixMetadata(meta) {
  2676. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2677. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2678. function(code, d1, d2, d3) {
  2679. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2680. });
  2681. var chars = '';
  2682. for (var i = 0; i < bytes.length; i += 2) {
  2683. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2684. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2685. code !== 38 && false ? String.fromCharCode(code) :
  2686. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2687. }
  2688. return '>' + chars;
  2689. });
  2690. }
  2691. function Metadata(meta) {
  2692. if (typeof meta === 'string') {
  2693. // Ghostscript produces invalid metadata
  2694. meta = fixMetadata(meta);
  2695. var parser = new DOMParser();
  2696. meta = parser.parseFromString(meta, 'application/xml');
  2697. } else if (!(meta instanceof Document)) {
  2698. error('Metadata: Invalid metadata object');
  2699. }
  2700. this.metaDocument = meta;
  2701. this.metadata = {};
  2702. this.parse();
  2703. }
  2704. Metadata.prototype = {
  2705. parse: function Metadata_parse() {
  2706. var doc = this.metaDocument;
  2707. var rdf = doc.documentElement;
  2708. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2709. rdf = rdf.firstChild;
  2710. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2711. rdf = rdf.nextSibling;
  2712. }
  2713. }
  2714. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2715. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2716. return;
  2717. }
  2718. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2719. for (i = 0, length = children.length; i < length; i++) {
  2720. desc = children[i];
  2721. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2722. continue;
  2723. }
  2724. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2725. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2726. entry = desc.childNodes[ii];
  2727. name = entry.nodeName.toLowerCase();
  2728. this.metadata[name] = entry.textContent.trim();
  2729. }
  2730. }
  2731. }
  2732. },
  2733. get: function Metadata_get(name) {
  2734. return this.metadata[name] || null;
  2735. },
  2736. has: function Metadata_has(name) {
  2737. return typeof this.metadata[name] !== 'undefined';
  2738. }
  2739. };
  2740. return Metadata;
  2741. })();
  2742. // <canvas> contexts store most of the state we need natively.
  2743. // However, PDF needs a bit more state, which we store here.
  2744. // Minimal font size that would be used during canvas fillText operations.
  2745. var MIN_FONT_SIZE = 16;
  2746. var MAX_GROUP_SIZE = 4096;
  2747. var COMPILE_TYPE3_GLYPHS = true;
  2748. function createScratchCanvas(width, height) {
  2749. var canvas = document.createElement('canvas');
  2750. canvas.width = width;
  2751. canvas.height = height;
  2752. return canvas;
  2753. }
  2754. function addContextCurrentTransform(ctx) {
  2755. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2756. if (!ctx.mozCurrentTransform) {
  2757. // Store the original context
  2758. ctx._scaleX = ctx._scaleX || 1.0;
  2759. ctx._scaleY = ctx._scaleY || 1.0;
  2760. ctx._originalSave = ctx.save;
  2761. ctx._originalRestore = ctx.restore;
  2762. ctx._originalRotate = ctx.rotate;
  2763. ctx._originalScale = ctx.scale;
  2764. ctx._originalTranslate = ctx.translate;
  2765. ctx._originalTransform = ctx.transform;
  2766. ctx._originalSetTransform = ctx.setTransform;
  2767. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2768. ctx._transformStack = [];
  2769. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2770. get: function getCurrentTransform() {
  2771. return this._transformMatrix;
  2772. }
  2773. });
  2774. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2775. get: function getCurrentTransformInverse() {
  2776. // Calculation done using WolframAlpha:
  2777. // http://www.wolframalpha.com/input/?
  2778. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2779. var m = this._transformMatrix;
  2780. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2781. var ad_bc = a * d - b * c;
  2782. var bc_ad = b * c - a * d;
  2783. return [
  2784. d / ad_bc,
  2785. b / bc_ad,
  2786. c / bc_ad,
  2787. a / ad_bc,
  2788. (d * e - c * f) / bc_ad,
  2789. (b * e - a * f) / ad_bc
  2790. ];
  2791. }
  2792. });
  2793. ctx.save = function ctxSave() {
  2794. var old = this._transformMatrix;
  2795. this._transformStack.push(old);
  2796. this._transformMatrix = old.slice(0, 6);
  2797. this._originalSave();
  2798. };
  2799. ctx.restore = function ctxRestore() {
  2800. var prev = this._transformStack.pop();
  2801. if (prev) {
  2802. this._transformMatrix = prev;
  2803. this._originalRestore();
  2804. }
  2805. };
  2806. ctx.translate = function ctxTranslate(x, y) {
  2807. var m = this._transformMatrix;
  2808. m[4] = m[0] * x + m[2] * y + m[4];
  2809. m[5] = m[1] * x + m[3] * y + m[5];
  2810. this._originalTranslate(x, y);
  2811. };
  2812. ctx.scale = function ctxScale(x, y) {
  2813. var m = this._transformMatrix;
  2814. m[0] = m[0] * x;
  2815. m[1] = m[1] * x;
  2816. m[2] = m[2] * y;
  2817. m[3] = m[3] * y;
  2818. this._originalScale(x, y);
  2819. };
  2820. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2821. var m = this._transformMatrix;
  2822. this._transformMatrix = [
  2823. m[0] * a + m[2] * b,
  2824. m[1] * a + m[3] * b,
  2825. m[0] * c + m[2] * d,
  2826. m[1] * c + m[3] * d,
  2827. m[0] * e + m[2] * f + m[4],
  2828. m[1] * e + m[3] * f + m[5]
  2829. ];
  2830. ctx._originalTransform(a, b, c, d, e, f);
  2831. };
  2832. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  2833. this._transformMatrix = [a, b, c, d, e, f];
  2834. ctx._originalSetTransform(a, b, c, d, e, f);
  2835. };
  2836. ctx.rotate = function ctxRotate(angle) {
  2837. var cosValue = Math.cos(angle);
  2838. var sinValue = Math.sin(angle);
  2839. var m = this._transformMatrix;
  2840. this._transformMatrix = [
  2841. m[0] * cosValue + m[2] * sinValue,
  2842. m[1] * cosValue + m[3] * sinValue,
  2843. m[0] * (-sinValue) + m[2] * cosValue,
  2844. m[1] * (-sinValue) + m[3] * cosValue,
  2845. m[4],
  2846. m[5]
  2847. ];
  2848. this._originalRotate(angle);
  2849. };
  2850. }
  2851. }
  2852. var CachedCanvases = (function CachedCanvasesClosure() {
  2853. var cache = {};
  2854. return {
  2855. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  2856. trackTransform) {
  2857. var canvasEntry;
  2858. if (id in cache) {
  2859. canvasEntry = cache[id];
  2860. canvasEntry.canvas.width = width;
  2861. canvasEntry.canvas.height = height;
  2862. // reset canvas transform for emulated mozCurrentTransform, if needed
  2863. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  2864. } else {
  2865. var canvas = createScratchCanvas(width, height);
  2866. var ctx = canvas.getContext('2d');
  2867. if (trackTransform) {
  2868. addContextCurrentTransform(ctx);
  2869. }
  2870. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  2871. }
  2872. return canvasEntry;
  2873. },
  2874. clear: function () {
  2875. for (var id in cache) {
  2876. var canvasEntry = cache[id];
  2877. // Zeroing the width and height causes Firefox to release graphics
  2878. // resources immediately, which can greatly reduce memory consumption.
  2879. canvasEntry.canvas.width = 0;
  2880. canvasEntry.canvas.height = 0;
  2881. delete cache[id];
  2882. }
  2883. }
  2884. };
  2885. })();
  2886. function compileType3Glyph(imgData) {
  2887. var POINT_TO_PROCESS_LIMIT = 1000;
  2888. var width = imgData.width, height = imgData.height;
  2889. var i, j, j0, width1 = width + 1;
  2890. var points = new Uint8Array(width1 * (height + 1));
  2891. var POINT_TYPES =
  2892. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  2893. // decodes bit-packed mask data
  2894. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  2895. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  2896. for (i = 0, ii = data0.length; i < ii; i++) {
  2897. var mask = 128, elem = data0[i];
  2898. while (mask > 0) {
  2899. data[pos++] = (elem & mask) ? 0 : 255;
  2900. mask >>= 1;
  2901. }
  2902. }
  2903. // finding iteresting points: every point is located between mask pixels,
  2904. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  2905. // will have flags assigned based on neighboring mask pixels:
  2906. // 4 | 8
  2907. // --P--
  2908. // 2 | 1
  2909. // We are interested only in points with the flags:
  2910. // - outside corners: 1, 2, 4, 8;
  2911. // - inside corners: 7, 11, 13, 14;
  2912. // - and, intersections: 5, 10.
  2913. var count = 0;
  2914. pos = 0;
  2915. if (data[pos] !== 0) {
  2916. points[0] = 1;
  2917. ++count;
  2918. }
  2919. for (j = 1; j < width; j++) {
  2920. if (data[pos] !== data[pos + 1]) {
  2921. points[j] = data[pos] ? 2 : 1;
  2922. ++count;
  2923. }
  2924. pos++;
  2925. }
  2926. if (data[pos] !== 0) {
  2927. points[j] = 2;
  2928. ++count;
  2929. }
  2930. for (i = 1; i < height; i++) {
  2931. pos = i * lineSize;
  2932. j0 = i * width1;
  2933. if (data[pos - lineSize] !== data[pos]) {
  2934. points[j0] = data[pos] ? 1 : 8;
  2935. ++count;
  2936. }
  2937. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  2938. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  2939. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  2940. for (j = 1; j < width; j++) {
  2941. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  2942. (data[pos - lineSize + 1] ? 8 : 0);
  2943. if (POINT_TYPES[sum]) {
  2944. points[j0 + j] = POINT_TYPES[sum];
  2945. ++count;
  2946. }
  2947. pos++;
  2948. }
  2949. if (data[pos - lineSize] !== data[pos]) {
  2950. points[j0 + j] = data[pos] ? 2 : 4;
  2951. ++count;
  2952. }
  2953. if (count > POINT_TO_PROCESS_LIMIT) {
  2954. return null;
  2955. }
  2956. }
  2957. pos = lineSize * (height - 1);
  2958. j0 = i * width1;
  2959. if (data[pos] !== 0) {
  2960. points[j0] = 8;
  2961. ++count;
  2962. }
  2963. for (j = 1; j < width; j++) {
  2964. if (data[pos] !== data[pos + 1]) {
  2965. points[j0 + j] = data[pos] ? 4 : 8;
  2966. ++count;
  2967. }
  2968. pos++;
  2969. }
  2970. if (data[pos] !== 0) {
  2971. points[j0 + j] = 4;
  2972. ++count;
  2973. }
  2974. if (count > POINT_TO_PROCESS_LIMIT) {
  2975. return null;
  2976. }
  2977. // building outlines
  2978. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  2979. var outlines = [];
  2980. for (i = 0; count && i <= height; i++) {
  2981. var p = i * width1;
  2982. var end = p + width;
  2983. while (p < end && !points[p]) {
  2984. p++;
  2985. }
  2986. if (p === end) {
  2987. continue;
  2988. }
  2989. var coords = [p % width1, i];
  2990. var type = points[p], p0 = p, pp;
  2991. do {
  2992. var step = steps[type];
  2993. do {
  2994. p += step;
  2995. } while (!points[p]);
  2996. pp = points[p];
  2997. if (pp !== 5 && pp !== 10) {
  2998. // set new direction
  2999. type = pp;
  3000. // delete mark
  3001. points[p] = 0;
  3002. } else { // type is 5 or 10, ie, a crossing
  3003. // set new direction
  3004. type = pp & ((0x33 * type) >> 4);
  3005. // set new type for "future hit"
  3006. points[p] &= (type >> 2 | type << 2);
  3007. }
  3008. coords.push(p % width1);
  3009. coords.push((p / width1) | 0);
  3010. --count;
  3011. } while (p0 !== p);
  3012. outlines.push(coords);
  3013. --i;
  3014. }
  3015. var drawOutline = function(c) {
  3016. c.save();
  3017. // the path shall be painted in [0..1]x[0..1] space
  3018. c.scale(1 / width, -1 / height);
  3019. c.translate(0, -height);
  3020. c.beginPath();
  3021. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3022. var o = outlines[i];
  3023. c.moveTo(o[0], o[1]);
  3024. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3025. c.lineTo(o[j], o[j+1]);
  3026. }
  3027. }
  3028. c.fill();
  3029. c.beginPath();
  3030. c.restore();
  3031. };
  3032. return drawOutline;
  3033. }
  3034. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3035. function CanvasExtraState(old) {
  3036. // Are soft masks and alpha values shapes or opacities?
  3037. this.alphaIsShape = false;
  3038. this.fontSize = 0;
  3039. this.fontSizeScale = 1;
  3040. this.textMatrix = IDENTITY_MATRIX;
  3041. this.textMatrixScale = 1;
  3042. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3043. this.leading = 0;
  3044. // Current point (in user coordinates)
  3045. this.x = 0;
  3046. this.y = 0;
  3047. // Start of text line (in text coordinates)
  3048. this.lineX = 0;
  3049. this.lineY = 0;
  3050. // Character and word spacing
  3051. this.charSpacing = 0;
  3052. this.wordSpacing = 0;
  3053. this.textHScale = 1;
  3054. this.textRenderingMode = TextRenderingMode.FILL;
  3055. this.textRise = 0;
  3056. // Default fore and background colors
  3057. this.fillColor = '#000000';
  3058. this.strokeColor = '#000000';
  3059. // Note: fill alpha applies to all non-stroking operations
  3060. this.fillAlpha = 1;
  3061. this.strokeAlpha = 1;
  3062. this.lineWidth = 1;
  3063. this.activeSMask = null; // nonclonable field (see the save method below)
  3064. this.old = old;
  3065. }
  3066. CanvasExtraState.prototype = {
  3067. clone: function CanvasExtraState_clone() {
  3068. return Object.create(this);
  3069. },
  3070. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3071. this.x = x;
  3072. this.y = y;
  3073. }
  3074. };
  3075. return CanvasExtraState;
  3076. })();
  3077. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3078. // Defines the time the executeOperatorList is going to be executing
  3079. // before it stops and shedules a continue of execution.
  3080. var EXECUTION_TIME = 15;
  3081. // Defines the number of steps before checking the execution time
  3082. var EXECUTION_STEPS = 10;
  3083. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3084. this.ctx = canvasCtx;
  3085. this.current = new CanvasExtraState();
  3086. this.stateStack = [];
  3087. this.pendingClip = null;
  3088. this.pendingEOFill = false;
  3089. this.res = null;
  3090. this.xobjs = null;
  3091. this.commonObjs = commonObjs;
  3092. this.objs = objs;
  3093. this.imageLayer = imageLayer;
  3094. this.groupStack = [];
  3095. this.processingType3 = null;
  3096. // Patterns are painted relative to the initial page/form transform, see pdf
  3097. // spec 8.7.2 NOTE 1.
  3098. this.baseTransform = null;
  3099. this.baseTransformStack = [];
  3100. this.groupLevel = 0;
  3101. this.smaskStack = [];
  3102. this.smaskCounter = 0;
  3103. this.tempSMask = null;
  3104. if (canvasCtx) {
  3105. addContextCurrentTransform(canvasCtx);
  3106. }
  3107. }
  3108. function putBinaryImageData(ctx, imgData) {
  3109. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3110. ctx.putImageData(imgData, 0, 0);
  3111. return;
  3112. }
  3113. // Put the image data to the canvas in chunks, rather than putting the
  3114. // whole image at once. This saves JS memory, because the ImageData object
  3115. // is smaller. It also possibly saves C++ memory within the implementation
  3116. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3117. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3118. // because too many putImageData() calls will slow things down.
  3119. //
  3120. // Note: as written, if the last chunk is partial, the putImageData() call
  3121. // will (conceptually) put pixels past the bounds of the canvas. But
  3122. // that's ok; any such pixels are ignored.
  3123. var height = imgData.height, width = imgData.width;
  3124. var fullChunkHeight = 16;
  3125. var fracChunks = height / fullChunkHeight;
  3126. var fullChunks = Math.floor(fracChunks);
  3127. var totalChunks = Math.ceil(fracChunks);
  3128. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3129. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3130. var srcPos = 0, destPos;
  3131. var src = imgData.data;
  3132. var dest = chunkImgData.data;
  3133. var i, j, thisChunkHeight, elemsInThisChunk;
  3134. // There are multiple forms in which the pixel data can be passed, and
  3135. // imgData.kind tells us which one this is.
  3136. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3137. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3138. var srcLength = src.byteLength;
  3139. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3140. new Uint32ArrayView(dest);
  3141. var dest32DataLength = dest32.length;
  3142. var fullSrcDiff = (width + 7) >> 3;
  3143. var white = 0xFFFFFFFF;
  3144. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3145. 0xFF000000 : 0x000000FF;
  3146. for (i = 0; i < totalChunks; i++) {
  3147. thisChunkHeight =
  3148. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3149. destPos = 0;
  3150. for (j = 0; j < thisChunkHeight; j++) {
  3151. var srcDiff = srcLength - srcPos;
  3152. var k = 0;
  3153. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3154. var kEndUnrolled = kEnd & ~7;
  3155. var mask = 0;
  3156. var srcByte = 0;
  3157. for (; k < kEndUnrolled; k += 8) {
  3158. srcByte = src[srcPos++];
  3159. dest32[destPos++] = (srcByte & 128) ? white : black;
  3160. dest32[destPos++] = (srcByte & 64) ? white : black;
  3161. dest32[destPos++] = (srcByte & 32) ? white : black;
  3162. dest32[destPos++] = (srcByte & 16) ? white : black;
  3163. dest32[destPos++] = (srcByte & 8) ? white : black;
  3164. dest32[destPos++] = (srcByte & 4) ? white : black;
  3165. dest32[destPos++] = (srcByte & 2) ? white : black;
  3166. dest32[destPos++] = (srcByte & 1) ? white : black;
  3167. }
  3168. for (; k < kEnd; k++) {
  3169. if (mask === 0) {
  3170. srcByte = src[srcPos++];
  3171. mask = 128;
  3172. }
  3173. dest32[destPos++] = (srcByte & mask) ? white : black;
  3174. mask >>= 1;
  3175. }
  3176. }
  3177. // We ran out of input. Make all remaining pixels transparent.
  3178. while (destPos < dest32DataLength) {
  3179. dest32[destPos++] = 0;
  3180. }
  3181. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3182. }
  3183. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3184. // RGBA, 32-bits per pixel.
  3185. j = 0;
  3186. elemsInThisChunk = width * fullChunkHeight * 4;
  3187. for (i = 0; i < fullChunks; i++) {
  3188. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3189. srcPos += elemsInThisChunk;
  3190. ctx.putImageData(chunkImgData, 0, j);
  3191. j += fullChunkHeight;
  3192. }
  3193. if (i < totalChunks) {
  3194. elemsInThisChunk = width * partialChunkHeight * 4;
  3195. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3196. ctx.putImageData(chunkImgData, 0, j);
  3197. }
  3198. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3199. // RGB, 24-bits per pixel.
  3200. thisChunkHeight = fullChunkHeight;
  3201. elemsInThisChunk = width * thisChunkHeight;
  3202. for (i = 0; i < totalChunks; i++) {
  3203. if (i >= fullChunks) {
  3204. thisChunkHeight =partialChunkHeight;
  3205. elemsInThisChunk = width * thisChunkHeight;
  3206. }
  3207. destPos = 0;
  3208. for (j = elemsInThisChunk; j--;) {
  3209. dest[destPos++] = src[srcPos++];
  3210. dest[destPos++] = src[srcPos++];
  3211. dest[destPos++] = src[srcPos++];
  3212. dest[destPos++] = 255;
  3213. }
  3214. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3215. }
  3216. } else {
  3217. error('bad image kind: ' + imgData.kind);
  3218. }
  3219. }
  3220. function putBinaryImageMask(ctx, imgData) {
  3221. var height = imgData.height, width = imgData.width;
  3222. var fullChunkHeight = 16;
  3223. var fracChunks = height / fullChunkHeight;
  3224. var fullChunks = Math.floor(fracChunks);
  3225. var totalChunks = Math.ceil(fracChunks);
  3226. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3227. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3228. var srcPos = 0;
  3229. var src = imgData.data;
  3230. var dest = chunkImgData.data;
  3231. for (var i = 0; i < totalChunks; i++) {
  3232. var thisChunkHeight =
  3233. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3234. // Expand the mask so it can be used by the canvas. Any required
  3235. // inversion has already been handled.
  3236. var destPos = 3; // alpha component offset
  3237. for (var j = 0; j < thisChunkHeight; j++) {
  3238. var mask = 0;
  3239. for (var k = 0; k < width; k++) {
  3240. if (!mask) {
  3241. var elem = src[srcPos++];
  3242. mask = 128;
  3243. }
  3244. dest[destPos] = (elem & mask) ? 0 : 255;
  3245. destPos += 4;
  3246. mask >>= 1;
  3247. }
  3248. }
  3249. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3250. }
  3251. }
  3252. function copyCtxState(sourceCtx, destCtx) {
  3253. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3254. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3255. 'globalCompositeOperation', 'font'];
  3256. for (var i = 0, ii = properties.length; i < ii; i++) {
  3257. var property = properties[i];
  3258. if (property in sourceCtx) {
  3259. destCtx[property] = sourceCtx[property];
  3260. }
  3261. }
  3262. if ('setLineDash' in sourceCtx) {
  3263. destCtx.setLineDash(sourceCtx.getLineDash());
  3264. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3265. } else if ('mozDash' in sourceCtx) {
  3266. destCtx.mozDash = sourceCtx.mozDash;
  3267. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3268. }
  3269. }
  3270. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3271. var length = bytes.length;
  3272. for (var i = 3; i < length; i += 4) {
  3273. var alpha = bytes[i];
  3274. if (alpha === 0) {
  3275. bytes[i - 3] = r0;
  3276. bytes[i - 2] = g0;
  3277. bytes[i - 1] = b0;
  3278. } else if (alpha < 255) {
  3279. var alpha_ = 255 - alpha;
  3280. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3281. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3282. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3283. }
  3284. }
  3285. }
  3286. function composeSMaskAlpha(maskData, layerData) {
  3287. var length = maskData.length;
  3288. var scale = 1 / 255;
  3289. for (var i = 3; i < length; i += 4) {
  3290. var alpha = maskData[i];
  3291. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3292. }
  3293. }
  3294. function composeSMaskLuminosity(maskData, layerData) {
  3295. var length = maskData.length;
  3296. for (var i = 3; i < length; i += 4) {
  3297. var y = ((maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3298. (maskData[i - 2] * 152) + // * 0.59 ....
  3299. (maskData[i - 1] * 28)) | 0; // * 0.11 ....
  3300. layerData[i] = (layerData[i] * y) >> 16;
  3301. }
  3302. }
  3303. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3304. subtype, backdrop) {
  3305. var hasBackdrop = !!backdrop;
  3306. var r0 = hasBackdrop ? backdrop[0] : 0;
  3307. var g0 = hasBackdrop ? backdrop[1] : 0;
  3308. var b0 = hasBackdrop ? backdrop[2] : 0;
  3309. var composeFn;
  3310. if (subtype === 'Luminosity') {
  3311. composeFn = composeSMaskLuminosity;
  3312. } else {
  3313. composeFn = composeSMaskAlpha;
  3314. }
  3315. // processing image in chunks to save memory
  3316. var PIXELS_TO_PROCESS = 65536;
  3317. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3318. for (var row = 0; row < height; row += chunkSize) {
  3319. var chunkHeight = Math.min(chunkSize, height - row);
  3320. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3321. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3322. if (hasBackdrop) {
  3323. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3324. }
  3325. composeFn(maskData.data, layerData.data);
  3326. maskCtx.putImageData(layerData, 0, row);
  3327. }
  3328. }
  3329. function composeSMask(ctx, smask, layerCtx) {
  3330. var mask = smask.canvas;
  3331. var maskCtx = smask.context;
  3332. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3333. smask.offsetX, smask.offsetY);
  3334. var backdrop = smask.backdrop || null;
  3335. if (WebGLUtils.isEnabled) {
  3336. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3337. {subtype: smask.subtype, backdrop: backdrop});
  3338. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3339. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3340. return;
  3341. }
  3342. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3343. smask.subtype, backdrop);
  3344. ctx.drawImage(mask, 0, 0);
  3345. }
  3346. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3347. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3348. var NORMAL_CLIP = {};
  3349. var EO_CLIP = {};
  3350. CanvasGraphics.prototype = {
  3351. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3352. // For pdfs that use blend modes we have to clear the canvas else certain
  3353. // blend modes can look wrong since we'd be blending with a white
  3354. // backdrop. The problem with a transparent backdrop though is we then
  3355. // don't get sub pixel anti aliasing on text, so we fill with white if
  3356. // we can.
  3357. var width = this.ctx.canvas.width;
  3358. var height = this.ctx.canvas.height;
  3359. if (transparency) {
  3360. this.ctx.clearRect(0, 0, width, height);
  3361. } else {
  3362. this.ctx.mozOpaque = true;
  3363. this.ctx.save();
  3364. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3365. this.ctx.fillRect(0, 0, width, height);
  3366. this.ctx.restore();
  3367. }
  3368. var transform = viewport.transform;
  3369. this.ctx.save();
  3370. this.ctx.transform.apply(this.ctx, transform);
  3371. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3372. if (this.imageLayer) {
  3373. this.imageLayer.beginLayout();
  3374. }
  3375. },
  3376. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3377. operatorList,
  3378. executionStartIdx, continueCallback,
  3379. stepper) {
  3380. var argsArray = operatorList.argsArray;
  3381. var fnArray = operatorList.fnArray;
  3382. var i = executionStartIdx || 0;
  3383. var argsArrayLen = argsArray.length;
  3384. // Sometimes the OperatorList to execute is empty.
  3385. if (argsArrayLen === i) {
  3386. return i;
  3387. }
  3388. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3389. typeof continueCallback === 'function');
  3390. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3391. var steps = 0;
  3392. var commonObjs = this.commonObjs;
  3393. var objs = this.objs;
  3394. var fnId;
  3395. while (true) {
  3396. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3397. stepper.breakIt(i, continueCallback);
  3398. return i;
  3399. }
  3400. fnId = fnArray[i];
  3401. if (fnId !== OPS.dependency) {
  3402. this[fnId].apply(this, argsArray[i]);
  3403. } else {
  3404. var deps = argsArray[i];
  3405. for (var n = 0, nn = deps.length; n < nn; n++) {
  3406. var depObjId = deps[n];
  3407. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3408. var objsPool = common ? commonObjs : objs;
  3409. // If the promise isn't resolved yet, add the continueCallback
  3410. // to the promise and bail out.
  3411. if (!objsPool.isResolved(depObjId)) {
  3412. objsPool.get(depObjId, continueCallback);
  3413. return i;
  3414. }
  3415. }
  3416. }
  3417. i++;
  3418. // If the entire operatorList was executed, stop as were done.
  3419. if (i === argsArrayLen) {
  3420. return i;
  3421. }
  3422. // If the execution took longer then a certain amount of time and
  3423. // `continueCallback` is specified, interrupt the execution.
  3424. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3425. if (Date.now() > endTime) {
  3426. continueCallback();
  3427. return i;
  3428. }
  3429. steps = 0;
  3430. }
  3431. // If the operatorList isn't executed completely yet OR the execution
  3432. // time was short enough, do another execution round.
  3433. }
  3434. },
  3435. endDrawing: function CanvasGraphics_endDrawing() {
  3436. this.ctx.restore();
  3437. CachedCanvases.clear();
  3438. WebGLUtils.clear();
  3439. if (this.imageLayer) {
  3440. this.imageLayer.endLayout();
  3441. }
  3442. },
  3443. // Graphics state
  3444. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3445. this.current.lineWidth = width;
  3446. this.ctx.lineWidth = width;
  3447. },
  3448. setLineCap: function CanvasGraphics_setLineCap(style) {
  3449. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3450. },
  3451. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3452. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3453. },
  3454. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3455. this.ctx.miterLimit = limit;
  3456. },
  3457. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3458. var ctx = this.ctx;
  3459. if ('setLineDash' in ctx) {
  3460. ctx.setLineDash(dashArray);
  3461. ctx.lineDashOffset = dashPhase;
  3462. } else {
  3463. ctx.mozDash = dashArray;
  3464. ctx.mozDashOffset = dashPhase;
  3465. }
  3466. },
  3467. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3468. // Maybe if we one day fully support color spaces this will be important
  3469. // for now we can ignore.
  3470. // TODO set rendering intent?
  3471. },
  3472. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3473. // There's no way to control this with canvas, but we can safely ignore.
  3474. // TODO set flatness?
  3475. },
  3476. setGState: function CanvasGraphics_setGState(states) {
  3477. for (var i = 0, ii = states.length; i < ii; i++) {
  3478. var state = states[i];
  3479. var key = state[0];
  3480. var value = state[1];
  3481. switch (key) {
  3482. case 'LW':
  3483. this.setLineWidth(value);
  3484. break;
  3485. case 'LC':
  3486. this.setLineCap(value);
  3487. break;
  3488. case 'LJ':
  3489. this.setLineJoin(value);
  3490. break;
  3491. case 'ML':
  3492. this.setMiterLimit(value);
  3493. break;
  3494. case 'D':
  3495. this.setDash(value[0], value[1]);
  3496. break;
  3497. case 'RI':
  3498. this.setRenderingIntent(value);
  3499. break;
  3500. case 'FL':
  3501. this.setFlatness(value);
  3502. break;
  3503. case 'Font':
  3504. this.setFont(value[0], value[1]);
  3505. break;
  3506. case 'CA':
  3507. this.current.strokeAlpha = state[1];
  3508. break;
  3509. case 'ca':
  3510. this.current.fillAlpha = state[1];
  3511. this.ctx.globalAlpha = state[1];
  3512. break;
  3513. case 'BM':
  3514. if (value && value.name && (value.name !== 'Normal')) {
  3515. var mode = value.name.replace(/([A-Z])/g,
  3516. function(c) {
  3517. return '-' + c.toLowerCase();
  3518. }
  3519. ).substring(1);
  3520. this.ctx.globalCompositeOperation = mode;
  3521. if (this.ctx.globalCompositeOperation !== mode) {
  3522. warn('globalCompositeOperation "' + mode +
  3523. '" is not supported');
  3524. }
  3525. } else {
  3526. this.ctx.globalCompositeOperation = 'source-over';
  3527. }
  3528. break;
  3529. case 'SMask':
  3530. if (this.current.activeSMask) {
  3531. this.endSMaskGroup();
  3532. }
  3533. this.current.activeSMask = value ? this.tempSMask : null;
  3534. if (this.current.activeSMask) {
  3535. this.beginSMaskGroup();
  3536. }
  3537. this.tempSMask = null;
  3538. break;
  3539. }
  3540. }
  3541. },
  3542. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3543. var activeSMask = this.current.activeSMask;
  3544. var drawnWidth = activeSMask.canvas.width;
  3545. var drawnHeight = activeSMask.canvas.height;
  3546. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3547. var scratchCanvas = CachedCanvases.getCanvas(
  3548. cacheId, drawnWidth, drawnHeight, true);
  3549. var currentCtx = this.ctx;
  3550. var currentTransform = currentCtx.mozCurrentTransform;
  3551. this.ctx.save();
  3552. var groupCtx = scratchCanvas.context;
  3553. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3554. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3555. groupCtx.transform.apply(groupCtx, currentTransform);
  3556. copyCtxState(currentCtx, groupCtx);
  3557. this.ctx = groupCtx;
  3558. this.setGState([
  3559. ['BM', 'Normal'],
  3560. ['ca', 1],
  3561. ['CA', 1]
  3562. ]);
  3563. this.groupStack.push(currentCtx);
  3564. this.groupLevel++;
  3565. },
  3566. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3567. var groupCtx = this.ctx;
  3568. this.groupLevel--;
  3569. this.ctx = this.groupStack.pop();
  3570. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3571. this.ctx.restore();
  3572. },
  3573. save: function CanvasGraphics_save() {
  3574. this.ctx.save();
  3575. var old = this.current;
  3576. this.stateStack.push(old);
  3577. this.current = old.clone();
  3578. this.current.activeSMask = null;
  3579. },
  3580. restore: function CanvasGraphics_restore() {
  3581. if (this.stateStack.length !== 0) {
  3582. if (this.current.activeSMask !== null) {
  3583. this.endSMaskGroup();
  3584. }
  3585. this.current = this.stateStack.pop();
  3586. this.ctx.restore();
  3587. }
  3588. },
  3589. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3590. this.ctx.transform(a, b, c, d, e, f);
  3591. },
  3592. // Path
  3593. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3594. var ctx = this.ctx;
  3595. var current = this.current;
  3596. var x = current.x, y = current.y;
  3597. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3598. switch (ops[i] | 0) {
  3599. case OPS.rectangle:
  3600. x = args[j++];
  3601. y = args[j++];
  3602. var width = args[j++];
  3603. var height = args[j++];
  3604. if (width === 0) {
  3605. width = this.getSinglePixelWidth();
  3606. }
  3607. if (height === 0) {
  3608. height = this.getSinglePixelWidth();
  3609. }
  3610. var xw = x + width;
  3611. var yh = y + height;
  3612. this.ctx.moveTo(x, y);
  3613. this.ctx.lineTo(xw, y);
  3614. this.ctx.lineTo(xw, yh);
  3615. this.ctx.lineTo(x, yh);
  3616. this.ctx.lineTo(x, y);
  3617. this.ctx.closePath();
  3618. break;
  3619. case OPS.moveTo:
  3620. x = args[j++];
  3621. y = args[j++];
  3622. ctx.moveTo(x, y);
  3623. break;
  3624. case OPS.lineTo:
  3625. x = args[j++];
  3626. y = args[j++];
  3627. ctx.lineTo(x, y);
  3628. break;
  3629. case OPS.curveTo:
  3630. x = args[j + 4];
  3631. y = args[j + 5];
  3632. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3633. x, y);
  3634. j += 6;
  3635. break;
  3636. case OPS.curveTo2:
  3637. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3638. args[j + 2], args[j + 3]);
  3639. x = args[j + 2];
  3640. y = args[j + 3];
  3641. j += 4;
  3642. break;
  3643. case OPS.curveTo3:
  3644. x = args[j + 2];
  3645. y = args[j + 3];
  3646. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3647. j += 4;
  3648. break;
  3649. case OPS.closePath:
  3650. ctx.closePath();
  3651. break;
  3652. }
  3653. }
  3654. current.setCurrentPoint(x, y);
  3655. },
  3656. closePath: function CanvasGraphics_closePath() {
  3657. this.ctx.closePath();
  3658. },
  3659. stroke: function CanvasGraphics_stroke(consumePath) {
  3660. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3661. var ctx = this.ctx;
  3662. var strokeColor = this.current.strokeColor;
  3663. if (this.current.lineWidth === 0) {
  3664. ctx.lineWidth = this.getSinglePixelWidth();
  3665. }
  3666. // For stroke we want to temporarily change the global alpha to the
  3667. // stroking alpha.
  3668. ctx.globalAlpha = this.current.strokeAlpha;
  3669. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3670. strokeColor.type === 'Pattern') {
  3671. // for patterns, we transform to pattern space, calculate
  3672. // the pattern, call stroke, and restore to user space
  3673. ctx.save();
  3674. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3675. ctx.stroke();
  3676. ctx.restore();
  3677. } else {
  3678. ctx.stroke();
  3679. }
  3680. if (consumePath) {
  3681. this.consumePath();
  3682. }
  3683. // Restore the global alpha to the fill alpha
  3684. ctx.globalAlpha = this.current.fillAlpha;
  3685. },
  3686. closeStroke: function CanvasGraphics_closeStroke() {
  3687. this.closePath();
  3688. this.stroke();
  3689. },
  3690. fill: function CanvasGraphics_fill(consumePath) {
  3691. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3692. var ctx = this.ctx;
  3693. var fillColor = this.current.fillColor;
  3694. var needRestore = false;
  3695. if (fillColor && fillColor.hasOwnProperty('type') &&
  3696. fillColor.type === 'Pattern') {
  3697. ctx.save();
  3698. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3699. needRestore = true;
  3700. }
  3701. if (this.pendingEOFill) {
  3702. if (ctx.mozFillRule !== undefined) {
  3703. ctx.mozFillRule = 'evenodd';
  3704. ctx.fill();
  3705. ctx.mozFillRule = 'nonzero';
  3706. } else {
  3707. try {
  3708. ctx.fill('evenodd');
  3709. } catch (ex) {
  3710. // shouldn't really happen, but browsers might think differently
  3711. ctx.fill();
  3712. }
  3713. }
  3714. this.pendingEOFill = false;
  3715. } else {
  3716. ctx.fill();
  3717. }
  3718. if (needRestore) {
  3719. ctx.restore();
  3720. }
  3721. if (consumePath) {
  3722. this.consumePath();
  3723. }
  3724. },
  3725. eoFill: function CanvasGraphics_eoFill() {
  3726. this.pendingEOFill = true;
  3727. this.fill();
  3728. },
  3729. fillStroke: function CanvasGraphics_fillStroke() {
  3730. this.fill(false);
  3731. this.stroke(false);
  3732. this.consumePath();
  3733. },
  3734. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3735. this.pendingEOFill = true;
  3736. this.fillStroke();
  3737. },
  3738. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3739. this.closePath();
  3740. this.fillStroke();
  3741. },
  3742. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3743. this.pendingEOFill = true;
  3744. this.closePath();
  3745. this.fillStroke();
  3746. },
  3747. endPath: function CanvasGraphics_endPath() {
  3748. this.consumePath();
  3749. },
  3750. // Clipping
  3751. clip: function CanvasGraphics_clip() {
  3752. this.pendingClip = NORMAL_CLIP;
  3753. },
  3754. eoClip: function CanvasGraphics_eoClip() {
  3755. this.pendingClip = EO_CLIP;
  3756. },
  3757. // Text
  3758. beginText: function CanvasGraphics_beginText() {
  3759. this.current.textMatrix = IDENTITY_MATRIX;
  3760. this.current.textMatrixScale = 1;
  3761. this.current.x = this.current.lineX = 0;
  3762. this.current.y = this.current.lineY = 0;
  3763. },
  3764. endText: function CanvasGraphics_endText() {
  3765. var paths = this.pendingTextPaths;
  3766. var ctx = this.ctx;
  3767. if (paths === undefined) {
  3768. ctx.beginPath();
  3769. return;
  3770. }
  3771. ctx.save();
  3772. ctx.beginPath();
  3773. for (var i = 0; i < paths.length; i++) {
  3774. var path = paths[i];
  3775. ctx.setTransform.apply(ctx, path.transform);
  3776. ctx.translate(path.x, path.y);
  3777. path.addToPath(ctx, path.fontSize);
  3778. }
  3779. ctx.restore();
  3780. ctx.clip();
  3781. ctx.beginPath();
  3782. delete this.pendingTextPaths;
  3783. },
  3784. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3785. this.current.charSpacing = spacing;
  3786. },
  3787. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3788. this.current.wordSpacing = spacing;
  3789. },
  3790. setHScale: function CanvasGraphics_setHScale(scale) {
  3791. this.current.textHScale = scale / 100;
  3792. },
  3793. setLeading: function CanvasGraphics_setLeading(leading) {
  3794. this.current.leading = -leading;
  3795. },
  3796. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3797. var fontObj = this.commonObjs.get(fontRefName);
  3798. var current = this.current;
  3799. if (!fontObj) {
  3800. error('Can\'t find font for ' + fontRefName);
  3801. }
  3802. current.fontMatrix = (fontObj.fontMatrix ?
  3803. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3804. // A valid matrix needs all main diagonal elements to be non-zero
  3805. // This also ensures we bypass FF bugzilla bug #719844.
  3806. if (current.fontMatrix[0] === 0 ||
  3807. current.fontMatrix[3] === 0) {
  3808. warn('Invalid font matrix for font ' + fontRefName);
  3809. }
  3810. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3811. // and in some docs this can be negative (inverted x-y axes).
  3812. if (size < 0) {
  3813. size = -size;
  3814. current.fontDirection = -1;
  3815. } else {
  3816. current.fontDirection = 1;
  3817. }
  3818. this.current.font = fontObj;
  3819. this.current.fontSize = size;
  3820. if (fontObj.isType3Font) {
  3821. return; // we don't need ctx.font for Type3 fonts
  3822. }
  3823. var name = fontObj.loadedName || 'sans-serif';
  3824. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3825. (fontObj.bold ? 'bold' : 'normal');
  3826. var italic = fontObj.italic ? 'italic' : 'normal';
  3827. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  3828. // Some font backends cannot handle fonts below certain size.
  3829. // Keeping the font at minimal size and using the fontSizeScale to change
  3830. // the current transformation matrix before the fillText/strokeText.
  3831. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  3832. var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
  3833. this.current.fontSizeScale = browserFontSize !== MIN_FONT_SIZE ? 1.0 :
  3834. size / MIN_FONT_SIZE;
  3835. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  3836. this.ctx.font = rule;
  3837. },
  3838. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  3839. this.current.textRenderingMode = mode;
  3840. },
  3841. setTextRise: function CanvasGraphics_setTextRise(rise) {
  3842. this.current.textRise = rise;
  3843. },
  3844. moveText: function CanvasGraphics_moveText(x, y) {
  3845. this.current.x = this.current.lineX += x;
  3846. this.current.y = this.current.lineY += y;
  3847. },
  3848. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  3849. this.setLeading(-y);
  3850. this.moveText(x, y);
  3851. },
  3852. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  3853. this.current.textMatrix = [a, b, c, d, e, f];
  3854. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  3855. this.current.x = this.current.lineX = 0;
  3856. this.current.y = this.current.lineY = 0;
  3857. },
  3858. nextLine: function CanvasGraphics_nextLine() {
  3859. this.moveText(0, this.current.leading);
  3860. },
  3861. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  3862. var ctx = this.ctx;
  3863. var current = this.current;
  3864. var font = current.font;
  3865. var textRenderingMode = current.textRenderingMode;
  3866. var fontSize = current.fontSize / current.fontSizeScale;
  3867. var fillStrokeMode = textRenderingMode &
  3868. TextRenderingMode.FILL_STROKE_MASK;
  3869. var isAddToPathSet = !!(textRenderingMode &
  3870. TextRenderingMode.ADD_TO_PATH_FLAG);
  3871. var addToPath;
  3872. if (font.disableFontFace || isAddToPathSet) {
  3873. addToPath = font.getPathGenerator(this.commonObjs, character);
  3874. }
  3875. if (font.disableFontFace) {
  3876. ctx.save();
  3877. ctx.translate(x, y);
  3878. ctx.beginPath();
  3879. addToPath(ctx, fontSize);
  3880. if (fillStrokeMode === TextRenderingMode.FILL ||
  3881. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3882. ctx.fill();
  3883. }
  3884. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3885. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3886. ctx.stroke();
  3887. }
  3888. ctx.restore();
  3889. } else {
  3890. if (fillStrokeMode === TextRenderingMode.FILL ||
  3891. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3892. ctx.fillText(character, x, y);
  3893. }
  3894. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3895. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3896. ctx.strokeText(character, x, y);
  3897. }
  3898. }
  3899. if (isAddToPathSet) {
  3900. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  3901. paths.push({
  3902. transform: ctx.mozCurrentTransform,
  3903. x: x,
  3904. y: y,
  3905. fontSize: fontSize,
  3906. addToPath: addToPath
  3907. });
  3908. }
  3909. },
  3910. get isFontSubpixelAAEnabled() {
  3911. // Checks if anti-aliasing is enabled when scaled text is painted.
  3912. // On Windows GDI scaled fonts looks bad.
  3913. var ctx = document.createElement('canvas').getContext('2d');
  3914. ctx.scale(1.5, 1);
  3915. ctx.fillText('I', 0, 10);
  3916. var data = ctx.getImageData(0, 0, 10, 10).data;
  3917. var enabled = false;
  3918. for (var i = 3; i < data.length; i += 4) {
  3919. if (data[i] > 0 && data[i] < 255) {
  3920. enabled = true;
  3921. break;
  3922. }
  3923. }
  3924. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  3925. },
  3926. showText: function CanvasGraphics_showText(glyphs) {
  3927. var current = this.current;
  3928. var font = current.font;
  3929. if (font.isType3Font) {
  3930. return this.showType3Text(glyphs);
  3931. }
  3932. var fontSize = current.fontSize;
  3933. if (fontSize === 0) {
  3934. return;
  3935. }
  3936. var ctx = this.ctx;
  3937. var fontSizeScale = current.fontSizeScale;
  3938. var charSpacing = current.charSpacing;
  3939. var wordSpacing = current.wordSpacing;
  3940. var fontDirection = current.fontDirection;
  3941. var textHScale = current.textHScale * fontDirection;
  3942. var glyphsLength = glyphs.length;
  3943. var vertical = font.vertical;
  3944. var defaultVMetrics = font.defaultVMetrics;
  3945. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  3946. var simpleFillText =
  3947. current.textRenderingMode === TextRenderingMode.FILL &&
  3948. !font.disableFontFace;
  3949. ctx.save();
  3950. ctx.transform.apply(ctx, current.textMatrix);
  3951. ctx.translate(current.x, current.y + current.textRise);
  3952. if (fontDirection > 0) {
  3953. ctx.scale(textHScale, -1);
  3954. } else {
  3955. ctx.scale(textHScale, 1);
  3956. }
  3957. var lineWidth = current.lineWidth;
  3958. var scale = current.textMatrixScale;
  3959. if (scale === 0 || lineWidth === 0) {
  3960. lineWidth = this.getSinglePixelWidth();
  3961. } else {
  3962. lineWidth /= scale;
  3963. }
  3964. if (fontSizeScale !== 1.0) {
  3965. ctx.scale(fontSizeScale, fontSizeScale);
  3966. lineWidth /= fontSizeScale;
  3967. }
  3968. ctx.lineWidth = lineWidth;
  3969. var x = 0, i;
  3970. for (i = 0; i < glyphsLength; ++i) {
  3971. var glyph = glyphs[i];
  3972. if (glyph === null) {
  3973. // word break
  3974. x += fontDirection * wordSpacing;
  3975. continue;
  3976. } else if (isNum(glyph)) {
  3977. x += -glyph * fontSize * 0.001;
  3978. continue;
  3979. }
  3980. var restoreNeeded = false;
  3981. var character = glyph.fontChar;
  3982. var accent = glyph.accent;
  3983. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  3984. var width = glyph.width;
  3985. if (vertical) {
  3986. var vmetric, vx, vy;
  3987. vmetric = glyph.vmetric || defaultVMetrics;
  3988. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  3989. vx = -vx * widthAdvanceScale;
  3990. vy = vmetric[2] * widthAdvanceScale;
  3991. width = vmetric ? -vmetric[0] : width;
  3992. scaledX = vx / fontSizeScale;
  3993. scaledY = (x + vy) / fontSizeScale;
  3994. } else {
  3995. scaledX = x / fontSizeScale;
  3996. scaledY = 0;
  3997. }
  3998. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  3999. // some standard fonts may not have the exact width, trying to
  4000. // rescale per character
  4001. var measuredWidth = ctx.measureText(character).width * 1000 /
  4002. fontSize * fontSizeScale;
  4003. var characterScaleX = width / measuredWidth;
  4004. restoreNeeded = true;
  4005. ctx.save();
  4006. ctx.scale(characterScaleX, 1);
  4007. scaledX /= characterScaleX;
  4008. }
  4009. if (simpleFillText && !accent) {
  4010. // common case
  4011. ctx.fillText(character, scaledX, scaledY);
  4012. } else {
  4013. this.paintChar(character, scaledX, scaledY);
  4014. if (accent) {
  4015. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4016. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4017. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4018. }
  4019. }
  4020. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4021. x += charWidth;
  4022. if (restoreNeeded) {
  4023. ctx.restore();
  4024. }
  4025. }
  4026. if (vertical) {
  4027. current.y -= x * textHScale;
  4028. } else {
  4029. current.x += x * textHScale;
  4030. }
  4031. ctx.restore();
  4032. },
  4033. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4034. // Type3 fonts - each glyph is a "mini-PDF"
  4035. var ctx = this.ctx;
  4036. var current = this.current;
  4037. var font = current.font;
  4038. var fontSize = current.fontSize;
  4039. var fontDirection = current.fontDirection;
  4040. var charSpacing = current.charSpacing;
  4041. var wordSpacing = current.wordSpacing;
  4042. var textHScale = current.textHScale * fontDirection;
  4043. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4044. var glyphsLength = glyphs.length;
  4045. var isTextInvisible =
  4046. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4047. var i, glyph, width;
  4048. if (isTextInvisible || fontSize === 0) {
  4049. return;
  4050. }
  4051. ctx.save();
  4052. ctx.transform.apply(ctx, current.textMatrix);
  4053. ctx.translate(current.x, current.y);
  4054. ctx.scale(textHScale, fontDirection);
  4055. for (i = 0; i < glyphsLength; ++i) {
  4056. glyph = glyphs[i];
  4057. if (glyph === null) {
  4058. // word break
  4059. this.ctx.translate(wordSpacing, 0);
  4060. current.x += wordSpacing * textHScale;
  4061. continue;
  4062. } else if (isNum(glyph)) {
  4063. var spacingLength = -glyph * 0.001 * fontSize;
  4064. this.ctx.translate(spacingLength, 0);
  4065. current.x += spacingLength * textHScale;
  4066. continue;
  4067. }
  4068. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4069. if (!operatorList) {
  4070. warn('Type3 character \"' + glyph.operatorListId +
  4071. '\" is not available');
  4072. continue;
  4073. }
  4074. this.processingType3 = glyph;
  4075. this.save();
  4076. ctx.scale(fontSize, fontSize);
  4077. ctx.transform.apply(ctx, fontMatrix);
  4078. this.executeOperatorList(operatorList);
  4079. this.restore();
  4080. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4081. width = transformed[0] * fontSize + charSpacing;
  4082. ctx.translate(width, 0);
  4083. current.x += width * textHScale;
  4084. }
  4085. ctx.restore();
  4086. this.processingType3 = null;
  4087. },
  4088. // Type3 fonts
  4089. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4090. // We can safely ignore this since the width should be the same
  4091. // as the width in the Widths array.
  4092. },
  4093. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4094. yWidth,
  4095. llx,
  4096. lly,
  4097. urx,
  4098. ury) {
  4099. // TODO According to the spec we're also suppose to ignore any operators
  4100. // that set color or include images while processing this type3 font.
  4101. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4102. this.clip();
  4103. this.endPath();
  4104. },
  4105. // Color
  4106. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4107. var pattern;
  4108. if (IR[0] === 'TilingPattern') {
  4109. var color = IR[1];
  4110. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4111. this.commonObjs, this.baseTransform);
  4112. } else {
  4113. pattern = getShadingPatternFromIR(IR);
  4114. }
  4115. return pattern;
  4116. },
  4117. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4118. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4119. },
  4120. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4121. this.current.fillColor = this.getColorN_Pattern(arguments);
  4122. },
  4123. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4124. var color = Util.makeCssRgb(arguments);
  4125. this.ctx.strokeStyle = color;
  4126. this.current.strokeColor = color;
  4127. },
  4128. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4129. var color = Util.makeCssRgb(arguments);
  4130. this.ctx.fillStyle = color;
  4131. this.current.fillColor = color;
  4132. },
  4133. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4134. var ctx = this.ctx;
  4135. this.save();
  4136. var pattern = getShadingPatternFromIR(patternIR);
  4137. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4138. var inv = ctx.mozCurrentTransformInverse;
  4139. if (inv) {
  4140. var canvas = ctx.canvas;
  4141. var width = canvas.width;
  4142. var height = canvas.height;
  4143. var bl = Util.applyTransform([0, 0], inv);
  4144. var br = Util.applyTransform([0, height], inv);
  4145. var ul = Util.applyTransform([width, 0], inv);
  4146. var ur = Util.applyTransform([width, height], inv);
  4147. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4148. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4149. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4150. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4151. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4152. } else {
  4153. // HACK to draw the gradient onto an infinite rectangle.
  4154. // PDF gradients are drawn across the entire image while
  4155. // Canvas only allows gradients to be drawn in a rectangle
  4156. // The following bug should allow us to remove this.
  4157. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4158. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4159. }
  4160. this.restore();
  4161. },
  4162. // Images
  4163. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4164. error('Should not call beginInlineImage');
  4165. },
  4166. beginImageData: function CanvasGraphics_beginImageData() {
  4167. error('Should not call beginImageData');
  4168. },
  4169. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4170. bbox) {
  4171. this.save();
  4172. this.baseTransformStack.push(this.baseTransform);
  4173. if (isArray(matrix) && 6 === matrix.length) {
  4174. this.transform.apply(this, matrix);
  4175. }
  4176. this.baseTransform = this.ctx.mozCurrentTransform;
  4177. if (isArray(bbox) && 4 === bbox.length) {
  4178. var width = bbox[2] - bbox[0];
  4179. var height = bbox[3] - bbox[1];
  4180. this.ctx.rect(bbox[0], bbox[1], width, height);
  4181. this.clip();
  4182. this.endPath();
  4183. }
  4184. },
  4185. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4186. this.restore();
  4187. this.baseTransform = this.baseTransformStack.pop();
  4188. },
  4189. beginGroup: function CanvasGraphics_beginGroup(group) {
  4190. this.save();
  4191. var currentCtx = this.ctx;
  4192. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4193. // group results aren't usually that different and they even have tools
  4194. // that ignore this setting. Notes from Rik on implmenting:
  4195. // - When you encounter an transparency group, create a new canvas with
  4196. // the dimensions of the bbox
  4197. // - copy the content from the previous canvas to the new canvas
  4198. // - draw as usual
  4199. // - remove the backdrop alpha:
  4200. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4201. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4202. // backdrop
  4203. // - remove background color:
  4204. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4205. if (!group.isolated) {
  4206. info('TODO: Support non-isolated groups.');
  4207. }
  4208. // TODO knockout - supposedly possible with the clever use of compositing
  4209. // modes.
  4210. if (group.knockout) {
  4211. warn('Knockout groups not supported.');
  4212. }
  4213. var currentTransform = currentCtx.mozCurrentTransform;
  4214. if (group.matrix) {
  4215. currentCtx.transform.apply(currentCtx, group.matrix);
  4216. }
  4217. assert(group.bbox, 'Bounding box is required.');
  4218. // Based on the current transform figure out how big the bounding box
  4219. // will actually be.
  4220. var bounds = Util.getAxialAlignedBoundingBox(
  4221. group.bbox,
  4222. currentCtx.mozCurrentTransform);
  4223. // Clip the bounding box to the current canvas.
  4224. var canvasBounds = [0,
  4225. 0,
  4226. currentCtx.canvas.width,
  4227. currentCtx.canvas.height];
  4228. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4229. // Use ceil in case we're between sizes so we don't create canvas that is
  4230. // too small and make the canvas at least 1x1 pixels.
  4231. var offsetX = Math.floor(bounds[0]);
  4232. var offsetY = Math.floor(bounds[1]);
  4233. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4234. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4235. var scaleX = 1, scaleY = 1;
  4236. if (drawnWidth > MAX_GROUP_SIZE) {
  4237. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4238. drawnWidth = MAX_GROUP_SIZE;
  4239. }
  4240. if (drawnHeight > MAX_GROUP_SIZE) {
  4241. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4242. drawnHeight = MAX_GROUP_SIZE;
  4243. }
  4244. var cacheId = 'groupAt' + this.groupLevel;
  4245. if (group.smask) {
  4246. // Using two cache entries is case if masks are used one after another.
  4247. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4248. }
  4249. var scratchCanvas = CachedCanvases.getCanvas(
  4250. cacheId, drawnWidth, drawnHeight, true);
  4251. var groupCtx = scratchCanvas.context;
  4252. // Since we created a new canvas that is just the size of the bounding box
  4253. // we have to translate the group ctx.
  4254. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4255. groupCtx.translate(-offsetX, -offsetY);
  4256. groupCtx.transform.apply(groupCtx, currentTransform);
  4257. if (group.smask) {
  4258. // Saving state and cached mask to be used in setGState.
  4259. this.smaskStack.push({
  4260. canvas: scratchCanvas.canvas,
  4261. context: groupCtx,
  4262. offsetX: offsetX,
  4263. offsetY: offsetY,
  4264. scaleX: scaleX,
  4265. scaleY: scaleY,
  4266. subtype: group.smask.subtype,
  4267. backdrop: group.smask.backdrop
  4268. });
  4269. } else {
  4270. // Setup the current ctx so when the group is popped we draw it at the
  4271. // right location.
  4272. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4273. currentCtx.translate(offsetX, offsetY);
  4274. currentCtx.scale(scaleX, scaleY);
  4275. }
  4276. // The transparency group inherits all off the current graphics state
  4277. // except the blend mode, soft mask, and alpha constants.
  4278. copyCtxState(currentCtx, groupCtx);
  4279. this.ctx = groupCtx;
  4280. this.setGState([
  4281. ['BM', 'Normal'],
  4282. ['ca', 1],
  4283. ['CA', 1]
  4284. ]);
  4285. this.groupStack.push(currentCtx);
  4286. this.groupLevel++;
  4287. },
  4288. endGroup: function CanvasGraphics_endGroup(group) {
  4289. this.groupLevel--;
  4290. var groupCtx = this.ctx;
  4291. this.ctx = this.groupStack.pop();
  4292. // Turn off image smoothing to avoid sub pixel interpolation which can
  4293. // look kind of blurry for some pdfs.
  4294. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4295. this.ctx.imageSmoothingEnabled = false;
  4296. } else {
  4297. this.ctx.mozImageSmoothingEnabled = false;
  4298. }
  4299. if (group.smask) {
  4300. this.tempSMask = this.smaskStack.pop();
  4301. } else {
  4302. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4303. }
  4304. this.restore();
  4305. },
  4306. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4307. this.save();
  4308. this.current = new CanvasExtraState();
  4309. },
  4310. endAnnotations: function CanvasGraphics_endAnnotations() {
  4311. this.restore();
  4312. },
  4313. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4314. matrix) {
  4315. this.save();
  4316. if (isArray(rect) && 4 === rect.length) {
  4317. var width = rect[2] - rect[0];
  4318. var height = rect[3] - rect[1];
  4319. this.ctx.rect(rect[0], rect[1], width, height);
  4320. this.clip();
  4321. this.endPath();
  4322. }
  4323. this.transform.apply(this, transform);
  4324. this.transform.apply(this, matrix);
  4325. },
  4326. endAnnotation: function CanvasGraphics_endAnnotation() {
  4327. this.restore();
  4328. },
  4329. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4330. var domImage = this.objs.get(objId);
  4331. if (!domImage) {
  4332. warn('Dependent image isn\'t ready yet');
  4333. return;
  4334. }
  4335. this.save();
  4336. var ctx = this.ctx;
  4337. // scale the image to the unit square
  4338. ctx.scale(1 / w, -1 / h);
  4339. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4340. 0, -h, w, h);
  4341. if (this.imageLayer) {
  4342. var currentTransform = ctx.mozCurrentTransformInverse;
  4343. var position = this.getCanvasPosition(0, 0);
  4344. this.imageLayer.appendImage({
  4345. objId: objId,
  4346. left: position[0],
  4347. top: position[1],
  4348. width: w / currentTransform[0],
  4349. height: h / currentTransform[3]
  4350. });
  4351. }
  4352. this.restore();
  4353. },
  4354. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4355. var ctx = this.ctx;
  4356. var width = img.width, height = img.height;
  4357. var glyph = this.processingType3;
  4358. if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
  4359. var MAX_SIZE_TO_COMPILE = 1000;
  4360. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4361. glyph.compiled =
  4362. compileType3Glyph({data: img.data, width: width, height: height});
  4363. } else {
  4364. glyph.compiled = null;
  4365. }
  4366. }
  4367. if (glyph && glyph.compiled) {
  4368. glyph.compiled(ctx);
  4369. return;
  4370. }
  4371. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4372. var maskCtx = maskCanvas.context;
  4373. maskCtx.save();
  4374. putBinaryImageMask(maskCtx, img);
  4375. maskCtx.globalCompositeOperation = 'source-in';
  4376. var fillColor = this.current.fillColor;
  4377. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4378. fillColor.type === 'Pattern') ?
  4379. fillColor.getPattern(maskCtx, this) : fillColor;
  4380. maskCtx.fillRect(0, 0, width, height);
  4381. maskCtx.restore();
  4382. this.paintInlineImageXObject(maskCanvas.canvas);
  4383. },
  4384. paintImageMaskXObjectRepeat:
  4385. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4386. scaleY, positions) {
  4387. var width = imgData.width;
  4388. var height = imgData.height;
  4389. var ctx = this.ctx;
  4390. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4391. var maskCtx = maskCanvas.context;
  4392. maskCtx.save();
  4393. putBinaryImageMask(maskCtx, imgData);
  4394. maskCtx.globalCompositeOperation = 'source-in';
  4395. var fillColor = this.current.fillColor;
  4396. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4397. fillColor.type === 'Pattern') ?
  4398. fillColor.getPattern(maskCtx, this) : fillColor;
  4399. maskCtx.fillRect(0, 0, width, height);
  4400. maskCtx.restore();
  4401. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4402. ctx.save();
  4403. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4404. ctx.scale(1, -1);
  4405. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4406. 0, -1, 1, 1);
  4407. ctx.restore();
  4408. }
  4409. },
  4410. paintImageMaskXObjectGroup:
  4411. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4412. var ctx = this.ctx;
  4413. for (var i = 0, ii = images.length; i < ii; i++) {
  4414. var image = images[i];
  4415. var width = image.width, height = image.height;
  4416. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4417. var maskCtx = maskCanvas.context;
  4418. maskCtx.save();
  4419. putBinaryImageMask(maskCtx, image);
  4420. maskCtx.globalCompositeOperation = 'source-in';
  4421. var fillColor = this.current.fillColor;
  4422. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4423. fillColor.type === 'Pattern') ?
  4424. fillColor.getPattern(maskCtx, this) : fillColor;
  4425. maskCtx.fillRect(0, 0, width, height);
  4426. maskCtx.restore();
  4427. ctx.save();
  4428. ctx.transform.apply(ctx, image.transform);
  4429. ctx.scale(1, -1);
  4430. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4431. 0, -1, 1, 1);
  4432. ctx.restore();
  4433. }
  4434. },
  4435. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4436. var imgData = this.objs.get(objId);
  4437. if (!imgData) {
  4438. warn('Dependent image isn\'t ready yet');
  4439. return;
  4440. }
  4441. this.paintInlineImageXObject(imgData);
  4442. },
  4443. paintImageXObjectRepeat:
  4444. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4445. positions) {
  4446. var imgData = this.objs.get(objId);
  4447. if (!imgData) {
  4448. warn('Dependent image isn\'t ready yet');
  4449. return;
  4450. }
  4451. var width = imgData.width;
  4452. var height = imgData.height;
  4453. var map = [];
  4454. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4455. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4456. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4457. }
  4458. this.paintInlineImageXObjectGroup(imgData, map);
  4459. },
  4460. paintInlineImageXObject:
  4461. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4462. var width = imgData.width;
  4463. var height = imgData.height;
  4464. var ctx = this.ctx;
  4465. this.save();
  4466. // scale the image to the unit square
  4467. ctx.scale(1 / width, -1 / height);
  4468. var currentTransform = ctx.mozCurrentTransformInverse;
  4469. var a = currentTransform[0], b = currentTransform[1];
  4470. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4471. var c = currentTransform[2], d = currentTransform[3];
  4472. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4473. var imgToPaint, tmpCanvas;
  4474. // instanceof HTMLElement does not work in jsdom node.js module
  4475. if (imgData instanceof HTMLElement || !imgData.data) {
  4476. imgToPaint = imgData;
  4477. } else {
  4478. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4479. var tmpCtx = tmpCanvas.context;
  4480. putBinaryImageData(tmpCtx, imgData);
  4481. imgToPaint = tmpCanvas.canvas;
  4482. }
  4483. var paintWidth = width, paintHeight = height;
  4484. var tmpCanvasId = 'prescale1';
  4485. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4486. // pixels during drawImage operation, painting on the temporary canvas(es)
  4487. // that are twice smaller in size
  4488. while ((widthScale > 2 && paintWidth > 1) ||
  4489. (heightScale > 2 && paintHeight > 1)) {
  4490. var newWidth = paintWidth, newHeight = paintHeight;
  4491. if (widthScale > 2 && paintWidth > 1) {
  4492. newWidth = Math.ceil(paintWidth / 2);
  4493. widthScale /= paintWidth / newWidth;
  4494. }
  4495. if (heightScale > 2 && paintHeight > 1) {
  4496. newHeight = Math.ceil(paintHeight / 2);
  4497. heightScale /= paintHeight / newHeight;
  4498. }
  4499. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4500. tmpCtx = tmpCanvas.context;
  4501. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4502. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4503. 0, 0, newWidth, newHeight);
  4504. imgToPaint = tmpCanvas.canvas;
  4505. paintWidth = newWidth;
  4506. paintHeight = newHeight;
  4507. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4508. }
  4509. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4510. 0, -height, width, height);
  4511. if (this.imageLayer) {
  4512. var position = this.getCanvasPosition(0, -height);
  4513. this.imageLayer.appendImage({
  4514. imgData: imgData,
  4515. left: position[0],
  4516. top: position[1],
  4517. width: width / currentTransform[0],
  4518. height: height / currentTransform[3]
  4519. });
  4520. }
  4521. this.restore();
  4522. },
  4523. paintInlineImageXObjectGroup:
  4524. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4525. var ctx = this.ctx;
  4526. var w = imgData.width;
  4527. var h = imgData.height;
  4528. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4529. var tmpCtx = tmpCanvas.context;
  4530. putBinaryImageData(tmpCtx, imgData);
  4531. for (var i = 0, ii = map.length; i < ii; i++) {
  4532. var entry = map[i];
  4533. ctx.save();
  4534. ctx.transform.apply(ctx, entry.transform);
  4535. ctx.scale(1, -1);
  4536. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4537. 0, -1, 1, 1);
  4538. if (this.imageLayer) {
  4539. var position = this.getCanvasPosition(entry.x, entry.y);
  4540. this.imageLayer.appendImage({
  4541. imgData: imgData,
  4542. left: position[0],
  4543. top: position[1],
  4544. width: w,
  4545. height: h
  4546. });
  4547. }
  4548. ctx.restore();
  4549. }
  4550. },
  4551. paintSolidColorImageMask:
  4552. function CanvasGraphics_paintSolidColorImageMask() {
  4553. this.ctx.fillRect(0, 0, 1, 1);
  4554. },
  4555. // Marked content
  4556. markPoint: function CanvasGraphics_markPoint(tag) {
  4557. // TODO Marked content.
  4558. },
  4559. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4560. // TODO Marked content.
  4561. },
  4562. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4563. // TODO Marked content.
  4564. },
  4565. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4566. tag, properties) {
  4567. // TODO Marked content.
  4568. },
  4569. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4570. // TODO Marked content.
  4571. },
  4572. // Compatibility
  4573. beginCompat: function CanvasGraphics_beginCompat() {
  4574. // TODO ignore undefined operators (should we do that anyway?)
  4575. },
  4576. endCompat: function CanvasGraphics_endCompat() {
  4577. // TODO stop ignoring undefined operators
  4578. },
  4579. // Helper functions
  4580. consumePath: function CanvasGraphics_consumePath() {
  4581. var ctx = this.ctx;
  4582. if (this.pendingClip) {
  4583. if (this.pendingClip === EO_CLIP) {
  4584. if (ctx.mozFillRule !== undefined) {
  4585. ctx.mozFillRule = 'evenodd';
  4586. ctx.clip();
  4587. ctx.mozFillRule = 'nonzero';
  4588. } else {
  4589. try {
  4590. ctx.clip('evenodd');
  4591. } catch (ex) {
  4592. // shouldn't really happen, but browsers might think differently
  4593. ctx.clip();
  4594. }
  4595. }
  4596. } else {
  4597. ctx.clip();
  4598. }
  4599. this.pendingClip = null;
  4600. }
  4601. ctx.beginPath();
  4602. },
  4603. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4604. var inverse = this.ctx.mozCurrentTransformInverse;
  4605. // max of the current horizontal and vertical scale
  4606. return Math.sqrt(Math.max(
  4607. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4608. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4609. },
  4610. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4611. var transform = this.ctx.mozCurrentTransform;
  4612. return [
  4613. transform[0] * x + transform[2] * y + transform[4],
  4614. transform[1] * x + transform[3] * y + transform[5]
  4615. ];
  4616. }
  4617. };
  4618. for (var op in OPS) {
  4619. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4620. }
  4621. return CanvasGraphics;
  4622. })();
  4623. var WebGLUtils = (function WebGLUtilsClosure() {
  4624. function loadShader(gl, code, shaderType) {
  4625. var shader = gl.createShader(shaderType);
  4626. gl.shaderSource(shader, code);
  4627. gl.compileShader(shader);
  4628. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4629. if (!compiled) {
  4630. var errorMsg = gl.getShaderInfoLog(shader);
  4631. throw new Error('Error during shader compilation: ' + errorMsg);
  4632. }
  4633. return shader;
  4634. }
  4635. function createVertexShader(gl, code) {
  4636. return loadShader(gl, code, gl.VERTEX_SHADER);
  4637. }
  4638. function createFragmentShader(gl, code) {
  4639. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4640. }
  4641. function createProgram(gl, shaders) {
  4642. var program = gl.createProgram();
  4643. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4644. gl.attachShader(program, shaders[i]);
  4645. }
  4646. gl.linkProgram(program);
  4647. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4648. if (!linked) {
  4649. var errorMsg = gl.getProgramInfoLog(program);
  4650. throw new Error('Error during program linking: ' + errorMsg);
  4651. }
  4652. return program;
  4653. }
  4654. function createTexture(gl, image, textureId) {
  4655. gl.activeTexture(textureId);
  4656. var texture = gl.createTexture();
  4657. gl.bindTexture(gl.TEXTURE_2D, texture);
  4658. // Set the parameters so we can render any size image.
  4659. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4660. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4661. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4662. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4663. // Upload the image into the texture.
  4664. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4665. return texture;
  4666. }
  4667. var currentGL, currentCanvas;
  4668. function generageGL() {
  4669. if (currentGL) {
  4670. return;
  4671. }
  4672. currentCanvas = document.createElement('canvas');
  4673. currentGL = currentCanvas.getContext('webgl',
  4674. { premultipliedalpha: false });
  4675. }
  4676. var smaskVertexShaderCode = '\
  4677. attribute vec2 a_position; \
  4678. attribute vec2 a_texCoord; \
  4679. \
  4680. uniform vec2 u_resolution; \
  4681. \
  4682. varying vec2 v_texCoord; \
  4683. \
  4684. void main() { \
  4685. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4686. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4687. \
  4688. v_texCoord = a_texCoord; \
  4689. } ';
  4690. var smaskFragmentShaderCode = '\
  4691. precision mediump float; \
  4692. \
  4693. uniform vec4 u_backdrop; \
  4694. uniform int u_subtype; \
  4695. uniform sampler2D u_image; \
  4696. uniform sampler2D u_mask; \
  4697. \
  4698. varying vec2 v_texCoord; \
  4699. \
  4700. void main() { \
  4701. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4702. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4703. if (u_backdrop.a > 0.0) { \
  4704. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4705. u_backdrop.rgb * (1.0 - maskColor.a); \
  4706. } \
  4707. float lum; \
  4708. if (u_subtype == 0) { \
  4709. lum = maskColor.a; \
  4710. } else { \
  4711. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4712. maskColor.b * 0.11; \
  4713. } \
  4714. imageColor.a *= lum; \
  4715. imageColor.rgb *= imageColor.a; \
  4716. gl_FragColor = imageColor; \
  4717. } ';
  4718. var smaskCache = null;
  4719. function initSmaskGL() {
  4720. var canvas, gl;
  4721. generageGL();
  4722. canvas = currentCanvas;
  4723. currentCanvas = null;
  4724. gl = currentGL;
  4725. currentGL = null;
  4726. // setup a GLSL program
  4727. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4728. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4729. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4730. gl.useProgram(program);
  4731. var cache = {};
  4732. cache.gl = gl;
  4733. cache.canvas = canvas;
  4734. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4735. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4736. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4737. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4738. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4739. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4740. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4741. // provide texture coordinates for the rectangle.
  4742. var texCoordBuffer = gl.createBuffer();
  4743. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4744. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4745. 0.0, 0.0,
  4746. 1.0, 0.0,
  4747. 0.0, 1.0,
  4748. 0.0, 1.0,
  4749. 1.0, 0.0,
  4750. 1.0, 1.0]), gl.STATIC_DRAW);
  4751. gl.enableVertexAttribArray(texCoordLocation);
  4752. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4753. gl.uniform1i(texLayerLocation, 0);
  4754. gl.uniform1i(texMaskLocation, 1);
  4755. smaskCache = cache;
  4756. }
  4757. function composeSMask(layer, mask, properties) {
  4758. var width = layer.width, height = layer.height;
  4759. if (!smaskCache) {
  4760. initSmaskGL();
  4761. }
  4762. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4763. canvas.width = width;
  4764. canvas.height = height;
  4765. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4766. gl.uniform2f(cache.resolutionLocation, width, height);
  4767. if (properties.backdrop) {
  4768. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4769. properties.backdrop[1], properties.backdrop[2], 1);
  4770. } else {
  4771. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4772. }
  4773. gl.uniform1i(cache.subtypeLocation,
  4774. properties.subtype === 'Luminosity' ? 1 : 0);
  4775. // Create a textures
  4776. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4777. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4778. // Create a buffer and put a single clipspace rectangle in
  4779. // it (2 triangles)
  4780. var buffer = gl.createBuffer();
  4781. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4782. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4783. 0, 0,
  4784. width, 0,
  4785. 0, height,
  4786. 0, height,
  4787. width, 0,
  4788. width, height]), gl.STATIC_DRAW);
  4789. gl.enableVertexAttribArray(cache.positionLocation);
  4790. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4791. // draw
  4792. gl.clearColor(0, 0, 0, 0);
  4793. gl.enable(gl.BLEND);
  4794. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4795. gl.clear(gl.COLOR_BUFFER_BIT);
  4796. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4797. gl.flush();
  4798. gl.deleteTexture(texture);
  4799. gl.deleteTexture(maskTexture);
  4800. gl.deleteBuffer(buffer);
  4801. return canvas;
  4802. }
  4803. var figuresVertexShaderCode = '\
  4804. attribute vec2 a_position; \
  4805. attribute vec3 a_color; \
  4806. \
  4807. uniform vec2 u_resolution; \
  4808. uniform vec2 u_scale; \
  4809. uniform vec2 u_offset; \
  4810. \
  4811. varying vec4 v_color; \
  4812. \
  4813. void main() { \
  4814. vec2 position = (a_position + u_offset) * u_scale; \
  4815. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4816. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4817. \
  4818. v_color = vec4(a_color / 255.0, 1.0); \
  4819. } ';
  4820. var figuresFragmentShaderCode = '\
  4821. precision mediump float; \
  4822. \
  4823. varying vec4 v_color; \
  4824. \
  4825. void main() { \
  4826. gl_FragColor = v_color; \
  4827. } ';
  4828. var figuresCache = null;
  4829. function initFiguresGL() {
  4830. var canvas, gl;
  4831. generageGL();
  4832. canvas = currentCanvas;
  4833. currentCanvas = null;
  4834. gl = currentGL;
  4835. currentGL = null;
  4836. // setup a GLSL program
  4837. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  4838. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  4839. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4840. gl.useProgram(program);
  4841. var cache = {};
  4842. cache.gl = gl;
  4843. cache.canvas = canvas;
  4844. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4845. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  4846. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  4847. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4848. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  4849. figuresCache = cache;
  4850. }
  4851. function drawFigures(width, height, backgroundColor, figures, context) {
  4852. if (!figuresCache) {
  4853. initFiguresGL();
  4854. }
  4855. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  4856. canvas.width = width;
  4857. canvas.height = height;
  4858. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4859. gl.uniform2f(cache.resolutionLocation, width, height);
  4860. // count triangle points
  4861. var count = 0;
  4862. var i, ii, rows;
  4863. for (i = 0, ii = figures.length; i < ii; i++) {
  4864. switch (figures[i].type) {
  4865. case 'lattice':
  4866. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  4867. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  4868. break;
  4869. case 'triangles':
  4870. count += figures[i].coords.length;
  4871. break;
  4872. }
  4873. }
  4874. // transfer data
  4875. var coords = new Float32Array(count * 2);
  4876. var colors = new Uint8Array(count * 3);
  4877. var coordsMap = context.coords, colorsMap = context.colors;
  4878. var pIndex = 0, cIndex = 0;
  4879. for (i = 0, ii = figures.length; i < ii; i++) {
  4880. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  4881. switch (figure.type) {
  4882. case 'lattice':
  4883. var cols = figure.verticesPerRow;
  4884. rows = (ps.length / cols) | 0;
  4885. for (var row = 1; row < rows; row++) {
  4886. var offset = row * cols + 1;
  4887. for (var col = 1; col < cols; col++, offset++) {
  4888. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  4889. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  4890. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  4891. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  4892. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  4893. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  4894. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  4895. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  4896. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  4897. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  4898. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  4899. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  4900. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  4901. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  4902. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  4903. coords[pIndex + 6] = coords[pIndex + 2];
  4904. coords[pIndex + 7] = coords[pIndex + 3];
  4905. coords[pIndex + 8] = coords[pIndex + 4];
  4906. coords[pIndex + 9] = coords[pIndex + 5];
  4907. coords[pIndex + 10] = coordsMap[ps[offset]];
  4908. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  4909. colors[cIndex + 9] = colors[cIndex + 3];
  4910. colors[cIndex + 10] = colors[cIndex + 4];
  4911. colors[cIndex + 11] = colors[cIndex + 5];
  4912. colors[cIndex + 12] = colors[cIndex + 6];
  4913. colors[cIndex + 13] = colors[cIndex + 7];
  4914. colors[cIndex + 14] = colors[cIndex + 8];
  4915. colors[cIndex + 15] = colorsMap[cs[offset]];
  4916. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  4917. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  4918. pIndex += 12;
  4919. cIndex += 18;
  4920. }
  4921. }
  4922. break;
  4923. case 'triangles':
  4924. for (var j = 0, jj = ps.length; j < jj; j++) {
  4925. coords[pIndex] = coordsMap[ps[j]];
  4926. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  4927. colors[cIndex] = colorsMap[cs[i]];
  4928. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  4929. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  4930. pIndex += 2;
  4931. cIndex += 3;
  4932. }
  4933. break;
  4934. }
  4935. }
  4936. // draw
  4937. if (backgroundColor) {
  4938. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  4939. backgroundColor[2] / 255, 1.0);
  4940. } else {
  4941. gl.clearColor(0, 0, 0, 0);
  4942. }
  4943. gl.clear(gl.COLOR_BUFFER_BIT);
  4944. var coordsBuffer = gl.createBuffer();
  4945. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  4946. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  4947. gl.enableVertexAttribArray(cache.positionLocation);
  4948. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4949. var colorsBuffer = gl.createBuffer();
  4950. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  4951. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  4952. gl.enableVertexAttribArray(cache.colorLocation);
  4953. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  4954. 0, 0);
  4955. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  4956. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  4957. gl.drawArrays(gl.TRIANGLES, 0, count);
  4958. gl.flush();
  4959. gl.deleteBuffer(coordsBuffer);
  4960. gl.deleteBuffer(colorsBuffer);
  4961. return canvas;
  4962. }
  4963. function cleanup() {
  4964. if (smaskCache && smaskCache.canvas) {
  4965. smaskCache.canvas.width = 0;
  4966. smaskCache.canvas.height = 0;
  4967. }
  4968. if (figuresCache && figuresCache.canvas) {
  4969. figuresCache.canvas.width = 0;
  4970. figuresCache.canvas.height = 0;
  4971. }
  4972. smaskCache = null;
  4973. figuresCache = null;
  4974. }
  4975. return {
  4976. get isEnabled() {
  4977. if (PDFJS.disableWebGL) {
  4978. return false;
  4979. }
  4980. var enabled = false;
  4981. try {
  4982. generageGL();
  4983. enabled = !!currentGL;
  4984. } catch (e) { }
  4985. return shadow(this, 'isEnabled', enabled);
  4986. },
  4987. composeSMask: composeSMask,
  4988. drawFigures: drawFigures,
  4989. clear: cleanup
  4990. };
  4991. })();
  4992. var ShadingIRs = {};
  4993. ShadingIRs.RadialAxial = {
  4994. fromIR: function RadialAxial_fromIR(raw) {
  4995. var type = raw[1];
  4996. var colorStops = raw[2];
  4997. var p0 = raw[3];
  4998. var p1 = raw[4];
  4999. var r0 = raw[5];
  5000. var r1 = raw[6];
  5001. return {
  5002. type: 'Pattern',
  5003. getPattern: function RadialAxial_getPattern(ctx) {
  5004. var grad;
  5005. if (type === 'axial') {
  5006. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5007. } else if (type === 'radial') {
  5008. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5009. }
  5010. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5011. var c = colorStops[i];
  5012. grad.addColorStop(c[0], c[1]);
  5013. }
  5014. return grad;
  5015. }
  5016. };
  5017. }
  5018. };
  5019. var createMeshCanvas = (function createMeshCanvasClosure() {
  5020. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5021. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5022. var coords = context.coords, colors = context.colors;
  5023. var bytes = data.data, rowSize = data.width * 4;
  5024. var tmp;
  5025. if (coords[p1 + 1] > coords[p2 + 1]) {
  5026. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5027. }
  5028. if (coords[p2 + 1] > coords[p3 + 1]) {
  5029. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5030. }
  5031. if (coords[p1 + 1] > coords[p2 + 1]) {
  5032. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5033. }
  5034. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5035. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5036. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5037. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5038. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5039. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5040. if (y1 >= y3) {
  5041. return;
  5042. }
  5043. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5044. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5045. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5046. var minY = Math.round(y1), maxY = Math.round(y3);
  5047. var xa, car, cag, cab;
  5048. var xb, cbr, cbg, cbb;
  5049. var k;
  5050. for (var y = minY; y <= maxY; y++) {
  5051. if (y < y2) {
  5052. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5053. xa = x1 - (x1 - x2) * k;
  5054. car = c1r - (c1r - c2r) * k;
  5055. cag = c1g - (c1g - c2g) * k;
  5056. cab = c1b - (c1b - c2b) * k;
  5057. } else {
  5058. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5059. xa = x2 - (x2 - x3) * k;
  5060. car = c2r - (c2r - c3r) * k;
  5061. cag = c2g - (c2g - c3g) * k;
  5062. cab = c2b - (c2b - c3b) * k;
  5063. }
  5064. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5065. xb = x1 - (x1 - x3) * k;
  5066. cbr = c1r - (c1r - c3r) * k;
  5067. cbg = c1g - (c1g - c3g) * k;
  5068. cbb = c1b - (c1b - c3b) * k;
  5069. var x1_ = Math.round(Math.min(xa, xb));
  5070. var x2_ = Math.round(Math.max(xa, xb));
  5071. var j = rowSize * y + x1_ * 4;
  5072. for (var x = x1_; x <= x2_; x++) {
  5073. k = (xa - x) / (xa - xb);
  5074. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5075. bytes[j++] = (car - (car - cbr) * k) | 0;
  5076. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5077. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5078. bytes[j++] = 255;
  5079. }
  5080. }
  5081. }
  5082. function drawFigure(data, figure, context) {
  5083. var ps = figure.coords;
  5084. var cs = figure.colors;
  5085. var i, ii;
  5086. switch (figure.type) {
  5087. case 'lattice':
  5088. var verticesPerRow = figure.verticesPerRow;
  5089. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5090. var cols = verticesPerRow - 1;
  5091. for (i = 0; i < rows; i++) {
  5092. var q = i * verticesPerRow;
  5093. for (var j = 0; j < cols; j++, q++) {
  5094. drawTriangle(data, context,
  5095. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5096. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5097. drawTriangle(data, context,
  5098. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5099. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5100. }
  5101. }
  5102. break;
  5103. case 'triangles':
  5104. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5105. drawTriangle(data, context,
  5106. ps[i], ps[i + 1], ps[i + 2],
  5107. cs[i], cs[i + 1], cs[i + 2]);
  5108. }
  5109. break;
  5110. default:
  5111. error('illigal figure');
  5112. break;
  5113. }
  5114. }
  5115. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5116. backgroundColor) {
  5117. // we will increase scale on some weird factor to let antialiasing take
  5118. // care of "rough" edges
  5119. var EXPECTED_SCALE = 1.1;
  5120. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5121. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5122. var offsetX = Math.floor(bounds[0]);
  5123. var offsetY = Math.floor(bounds[1]);
  5124. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5125. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5126. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5127. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5128. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5129. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5130. var scaleX = boundsWidth / width;
  5131. var scaleY = boundsHeight / height;
  5132. var context = {
  5133. coords: coords,
  5134. colors: colors,
  5135. offsetX: -offsetX,
  5136. offsetY: -offsetY,
  5137. scaleX: 1 / scaleX,
  5138. scaleY: 1 / scaleY
  5139. };
  5140. var canvas, tmpCanvas, i, ii;
  5141. if (WebGLUtils.isEnabled) {
  5142. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5143. figures, context);
  5144. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5145. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5146. tmpCanvas.context.drawImage(canvas, 0, 0);
  5147. canvas = tmpCanvas.canvas;
  5148. } else {
  5149. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5150. var tmpCtx = tmpCanvas.context;
  5151. var data = tmpCtx.createImageData(width, height);
  5152. if (backgroundColor) {
  5153. var bytes = data.data;
  5154. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5155. bytes[i] = backgroundColor[0];
  5156. bytes[i + 1] = backgroundColor[1];
  5157. bytes[i + 2] = backgroundColor[2];
  5158. bytes[i + 3] = 255;
  5159. }
  5160. }
  5161. for (i = 0; i < figures.length; i++) {
  5162. drawFigure(data, figures[i], context);
  5163. }
  5164. tmpCtx.putImageData(data, 0, 0);
  5165. canvas = tmpCanvas.canvas;
  5166. }
  5167. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5168. scaleX: scaleX, scaleY: scaleY};
  5169. }
  5170. return createMeshCanvas;
  5171. })();
  5172. ShadingIRs.Mesh = {
  5173. fromIR: function Mesh_fromIR(raw) {
  5174. //var type = raw[1];
  5175. var coords = raw[2];
  5176. var colors = raw[3];
  5177. var figures = raw[4];
  5178. var bounds = raw[5];
  5179. var matrix = raw[6];
  5180. //var bbox = raw[7];
  5181. var background = raw[8];
  5182. return {
  5183. type: 'Pattern',
  5184. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5185. var scale;
  5186. if (shadingFill) {
  5187. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5188. } else {
  5189. // Obtain scale from matrix and current transformation matrix.
  5190. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5191. if (matrix) {
  5192. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5193. scale = [scale[0] * matrixScale[0],
  5194. scale[1] * matrixScale[1]];
  5195. }
  5196. }
  5197. // Rasterizing on the main thread since sending/queue large canvases
  5198. // might cause OOM.
  5199. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5200. colors, figures, shadingFill ? null : background);
  5201. if (!shadingFill) {
  5202. ctx.setTransform.apply(ctx, owner.baseTransform);
  5203. if (matrix) {
  5204. ctx.transform.apply(ctx, matrix);
  5205. }
  5206. }
  5207. ctx.translate(temporaryPatternCanvas.offsetX,
  5208. temporaryPatternCanvas.offsetY);
  5209. ctx.scale(temporaryPatternCanvas.scaleX,
  5210. temporaryPatternCanvas.scaleY);
  5211. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5212. }
  5213. };
  5214. }
  5215. };
  5216. ShadingIRs.Dummy = {
  5217. fromIR: function Dummy_fromIR() {
  5218. return {
  5219. type: 'Pattern',
  5220. getPattern: function Dummy_fromIR_getPattern() {
  5221. return 'hotpink';
  5222. }
  5223. };
  5224. }
  5225. };
  5226. function getShadingPatternFromIR(raw) {
  5227. var shadingIR = ShadingIRs[raw[0]];
  5228. if (!shadingIR) {
  5229. error('Unknown IR type: ' + raw[0]);
  5230. }
  5231. return shadingIR.fromIR(raw);
  5232. }
  5233. var TilingPattern = (function TilingPatternClosure() {
  5234. var PaintType = {
  5235. COLORED: 1,
  5236. UNCOLORED: 2
  5237. };
  5238. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5239. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5240. this.operatorList = IR[2];
  5241. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5242. this.bbox = IR[4];
  5243. this.xstep = IR[5];
  5244. this.ystep = IR[6];
  5245. this.paintType = IR[7];
  5246. this.tilingType = IR[8];
  5247. this.color = color;
  5248. this.objs = objs;
  5249. this.commonObjs = commonObjs;
  5250. this.baseTransform = baseTransform;
  5251. this.type = 'Pattern';
  5252. this.ctx = ctx;
  5253. }
  5254. TilingPattern.prototype = {
  5255. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5256. var operatorList = this.operatorList;
  5257. var bbox = this.bbox;
  5258. var xstep = this.xstep;
  5259. var ystep = this.ystep;
  5260. var paintType = this.paintType;
  5261. var tilingType = this.tilingType;
  5262. var color = this.color;
  5263. var objs = this.objs;
  5264. var commonObjs = this.commonObjs;
  5265. info('TilingType: ' + tilingType);
  5266. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5267. var topLeft = [x0, y0];
  5268. // we want the canvas to be as large as the step size
  5269. var botRight = [x0 + xstep, y0 + ystep];
  5270. var width = botRight[0] - topLeft[0];
  5271. var height = botRight[1] - topLeft[1];
  5272. // Obtain scale from matrix and current transformation matrix.
  5273. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5274. var curMatrixScale = Util.singularValueDecompose2dScale(
  5275. this.baseTransform);
  5276. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5277. matrixScale[1] * curMatrixScale[1]];
  5278. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5279. // Use width and height values that are as close as possible to the end
  5280. // result when the pattern is used. Too low value makes the pattern look
  5281. // blurry. Too large value makes it look too crispy.
  5282. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5283. MAX_PATTERN_SIZE);
  5284. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5285. MAX_PATTERN_SIZE);
  5286. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5287. var tmpCtx = tmpCanvas.context;
  5288. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5289. graphics.groupLevel = owner.groupLevel;
  5290. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5291. this.setScale(width, height, xstep, ystep);
  5292. this.transformToScale(graphics);
  5293. // transform coordinates to pattern space
  5294. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5295. graphics.transform.apply(graphics, tmpTranslate);
  5296. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5297. graphics.executeOperatorList(operatorList);
  5298. return tmpCanvas.canvas;
  5299. },
  5300. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5301. this.scale = [width / xstep, height / ystep];
  5302. },
  5303. transformToScale: function TilingPattern_transformToScale(graphics) {
  5304. var scale = this.scale;
  5305. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5306. graphics.transform.apply(graphics, tmpScale);
  5307. },
  5308. scaleToContext: function TilingPattern_scaleToContext() {
  5309. var scale = this.scale;
  5310. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5311. },
  5312. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5313. if (bbox && isArray(bbox) && bbox.length === 4) {
  5314. var bboxWidth = x1 - x0;
  5315. var bboxHeight = y1 - y0;
  5316. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5317. graphics.clip();
  5318. graphics.endPath();
  5319. }
  5320. },
  5321. setFillAndStrokeStyleToContext:
  5322. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5323. switch (paintType) {
  5324. case PaintType.COLORED:
  5325. var ctx = this.ctx;
  5326. context.fillStyle = ctx.fillStyle;
  5327. context.strokeStyle = ctx.strokeStyle;
  5328. break;
  5329. case PaintType.UNCOLORED:
  5330. var cssColor = Util.makeCssRgb(color);
  5331. context.fillStyle = cssColor;
  5332. context.strokeStyle = cssColor;
  5333. break;
  5334. default:
  5335. error('Unsupported paint type: ' + paintType);
  5336. }
  5337. },
  5338. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5339. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5340. ctx = this.ctx;
  5341. ctx.setTransform.apply(ctx, this.baseTransform);
  5342. ctx.transform.apply(ctx, this.matrix);
  5343. this.scaleToContext();
  5344. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5345. }
  5346. };
  5347. return TilingPattern;
  5348. })();
  5349. PDFJS.disableFontFace = false;
  5350. var FontLoader = {
  5351. insertRule: function fontLoaderInsertRule(rule) {
  5352. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5353. if (!styleElement) {
  5354. styleElement = document.createElement('style');
  5355. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5356. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5357. styleElement);
  5358. }
  5359. var styleSheet = styleElement.sheet;
  5360. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5361. },
  5362. clear: function fontLoaderClear() {
  5363. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5364. if (styleElement) {
  5365. styleElement.parentNode.removeChild(styleElement);
  5366. }
  5367. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5368. document.fonts.delete(nativeFontFace);
  5369. });
  5370. this.nativeFontFaces.length = 0;
  5371. },
  5372. get loadTestFont() {
  5373. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5374. // height.
  5375. return shadow(this, 'loadTestFont', atob(
  5376. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5377. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5378. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5379. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5380. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5381. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5382. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5383. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5384. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5385. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5386. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5387. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5388. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5389. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5390. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5391. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5392. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5393. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5394. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5395. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5396. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5397. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5398. ));
  5399. },
  5400. loadTestFontId: 0,
  5401. loadingContext: {
  5402. requests: [],
  5403. nextRequestId: 0
  5404. },
  5405. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5406. if (isWorker) {
  5407. return false;
  5408. }
  5409. // User agent string sniffing is bad, but there is no reliable way to tell
  5410. // if font is fully loaded and ready to be used with canvas.
  5411. var userAgent = window.navigator.userAgent;
  5412. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5413. if (m && m[1] >= 14) {
  5414. return true;
  5415. }
  5416. // TODO other browsers
  5417. if (userAgent === 'node') {
  5418. return true;
  5419. }
  5420. return false;
  5421. })(),
  5422. nativeFontFaces: [],
  5423. isFontLoadingAPISupported: !isWorker && !!document.fonts,
  5424. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5425. this.nativeFontFaces.push(nativeFontFace);
  5426. document.fonts.add(nativeFontFace);
  5427. },
  5428. bind: function fontLoaderBind(fonts, callback) {
  5429. assert(!isWorker, 'bind() shall be called from main thread');
  5430. var rules = [];
  5431. var fontsToLoad = [];
  5432. var fontLoadPromises = [];
  5433. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5434. var font = fonts[i];
  5435. // Add the font to the DOM only once or skip if the font
  5436. // is already loaded.
  5437. if (font.attached || font.loading === false) {
  5438. continue;
  5439. }
  5440. font.attached = true;
  5441. if (this.isFontLoadingAPISupported) {
  5442. var nativeFontFace = font.createNativeFontFace();
  5443. if (nativeFontFace) {
  5444. fontLoadPromises.push(nativeFontFace.loaded);
  5445. }
  5446. } else {
  5447. var rule = font.bindDOM();
  5448. if (rule) {
  5449. rules.push(rule);
  5450. fontsToLoad.push(font);
  5451. }
  5452. }
  5453. }
  5454. var request = FontLoader.queueLoadingCallback(callback);
  5455. if (this.isFontLoadingAPISupported) {
  5456. Promise.all(fontsToLoad).then(function() {
  5457. request.complete();
  5458. });
  5459. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5460. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5461. } else {
  5462. request.complete();
  5463. }
  5464. },
  5465. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5466. function LoadLoader_completeRequest() {
  5467. assert(!request.end, 'completeRequest() cannot be called twice');
  5468. request.end = Date.now();
  5469. // sending all completed requests in order how they were queued
  5470. while (context.requests.length > 0 && context.requests[0].end) {
  5471. var otherRequest = context.requests.shift();
  5472. setTimeout(otherRequest.callback, 0);
  5473. }
  5474. }
  5475. var context = FontLoader.loadingContext;
  5476. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5477. var request = {
  5478. id: requestId,
  5479. complete: LoadLoader_completeRequest,
  5480. callback: callback,
  5481. started: Date.now()
  5482. };
  5483. context.requests.push(request);
  5484. return request;
  5485. },
  5486. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5487. fonts,
  5488. request) {
  5489. /** Hack begin */
  5490. // There's currently no event when a font has finished downloading so the
  5491. // following code is a dirty hack to 'guess' when a font is
  5492. // ready. It's assumed fonts are loaded in order, so add a known test
  5493. // font after the desired fonts and then test for the loading of that
  5494. // test font.
  5495. function int32(data, offset) {
  5496. return (data.charCodeAt(offset) << 24) |
  5497. (data.charCodeAt(offset + 1) << 16) |
  5498. (data.charCodeAt(offset + 2) << 8) |
  5499. (data.charCodeAt(offset + 3) & 0xff);
  5500. }
  5501. function spliceString(s, offset, remove, insert) {
  5502. var chunk1 = s.substr(0, offset);
  5503. var chunk2 = s.substr(offset + remove);
  5504. return chunk1 + insert + chunk2;
  5505. }
  5506. var i, ii;
  5507. var canvas = document.createElement('canvas');
  5508. canvas.width = 1;
  5509. canvas.height = 1;
  5510. var ctx = canvas.getContext('2d');
  5511. var called = 0;
  5512. function isFontReady(name, callback) {
  5513. called++;
  5514. // With setTimeout clamping this gives the font ~100ms to load.
  5515. if(called > 30) {
  5516. warn('Load test font never loaded.');
  5517. callback();
  5518. return;
  5519. }
  5520. ctx.font = '30px ' + name;
  5521. ctx.fillText('.', 0, 20);
  5522. var imageData = ctx.getImageData(0, 0, 1, 1);
  5523. if (imageData.data[3] > 0) {
  5524. callback();
  5525. return;
  5526. }
  5527. setTimeout(isFontReady.bind(null, name, callback));
  5528. }
  5529. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5530. // Chromium seems to cache fonts based on a hash of the actual font data,
  5531. // so the font must be modified for each load test else it will appear to
  5532. // be loaded already.
  5533. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5534. // font by splitting it in chunks before hand and padding the font id.
  5535. var data = this.loadTestFont;
  5536. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5537. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5538. loadTestFontId);
  5539. // CFF checksum is important for IE, adjusting it
  5540. var CFF_CHECKSUM_OFFSET = 16;
  5541. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5542. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5543. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5544. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5545. }
  5546. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5547. checksum = (checksum - XXXX_VALUE +
  5548. int32(loadTestFontId + 'XXX', i)) | 0;
  5549. }
  5550. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5551. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5552. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5553. url + '}';
  5554. FontLoader.insertRule(rule);
  5555. var names = [];
  5556. for (i = 0, ii = fonts.length; i < ii; i++) {
  5557. names.push(fonts[i].loadedName);
  5558. }
  5559. names.push(loadTestFontId);
  5560. var div = document.createElement('div');
  5561. div.setAttribute('style',
  5562. 'visibility: hidden;' +
  5563. 'width: 10px; height: 10px;' +
  5564. 'position: absolute; top: 0px; left: 0px;');
  5565. for (i = 0, ii = names.length; i < ii; ++i) {
  5566. var span = document.createElement('span');
  5567. span.textContent = 'Hi';
  5568. span.style.fontFamily = names[i];
  5569. div.appendChild(span);
  5570. }
  5571. document.body.appendChild(div);
  5572. isFontReady(loadTestFontId, function() {
  5573. document.body.removeChild(div);
  5574. request.complete();
  5575. });
  5576. /** Hack end */
  5577. }
  5578. };
  5579. var FontFaceObject = (function FontFaceObjectClosure() {
  5580. function FontFaceObject(name, file, properties) {
  5581. this.compiledGlyphs = {};
  5582. if (arguments.length === 1) {
  5583. // importing translated data
  5584. var data = arguments[0];
  5585. for (var i in data) {
  5586. this[i] = data[i];
  5587. }
  5588. return;
  5589. }
  5590. }
  5591. FontFaceObject.prototype = {
  5592. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5593. if (!this.data) {
  5594. return null;
  5595. }
  5596. if (PDFJS.disableFontFace) {
  5597. this.disableFontFace = true;
  5598. return null;
  5599. }
  5600. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5601. FontLoader.addNativeFontFace(nativeFontFace);
  5602. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5603. globalScope['FontInspector'].enabled) {
  5604. globalScope['FontInspector'].fontAdded(this);
  5605. }
  5606. return nativeFontFace;
  5607. },
  5608. bindDOM: function FontFaceObject_bindDOM() {
  5609. if (!this.data) {
  5610. return null;
  5611. }
  5612. if (PDFJS.disableFontFace) {
  5613. this.disableFontFace = true;
  5614. return null;
  5615. }
  5616. var data = bytesToString(new Uint8Array(this.data));
  5617. var fontName = this.loadedName;
  5618. // Add the font-face rule to the document
  5619. var url = ('url(data:' + this.mimetype + ';base64,' +
  5620. window.btoa(data) + ');');
  5621. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5622. FontLoader.insertRule(rule);
  5623. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5624. globalScope['FontInspector'].enabled) {
  5625. globalScope['FontInspector'].fontAdded(this, url);
  5626. }
  5627. return rule;
  5628. },
  5629. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5630. if (!(character in this.compiledGlyphs)) {
  5631. var js = objs.get(this.loadedName + '_path_' + character);
  5632. /*jshint -W054 */
  5633. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5634. }
  5635. return this.compiledGlyphs[character];
  5636. }
  5637. };
  5638. return FontFaceObject;
  5639. })();
  5640. var HIGHLIGHT_OFFSET = 4; // px
  5641. var ANNOT_MIN_SIZE = 10; // px
  5642. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5643. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5644. function setTextStyles(element, item, fontObj) {
  5645. var style = element.style;
  5646. style.fontSize = item.fontSize + 'px';
  5647. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5648. if (!fontObj) {
  5649. return;
  5650. }
  5651. style.fontWeight = fontObj.black ?
  5652. (fontObj.bold ? 'bolder' : 'bold') :
  5653. (fontObj.bold ? 'bold' : 'normal');
  5654. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5655. var fontName = fontObj.loadedName;
  5656. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5657. // Use a reasonable default font if the font doesn't specify a fallback
  5658. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5659. style.fontFamily = fontFamily + fallbackName;
  5660. }
  5661. // TODO(mack): Remove this, it's not really that helpful.
  5662. function getEmptyContainer(tagName, rect, borderWidth) {
  5663. var bWidth = borderWidth || 0;
  5664. var element = document.createElement(tagName);
  5665. element.style.borderWidth = bWidth + 'px';
  5666. var width = rect[2] - rect[0] - 2 * bWidth;
  5667. var height = rect[3] - rect[1] - 2 * bWidth;
  5668. element.style.width = width + 'px';
  5669. element.style.height = height + 'px';
  5670. return element;
  5671. }
  5672. function initContainer(item) {
  5673. var container = getEmptyContainer('section', item.rect, item.borderWidth);
  5674. container.style.backgroundColor = item.color;
  5675. var color = item.color;
  5676. var rgb = [];
  5677. for (var i = 0; i < 3; ++i) {
  5678. rgb[i] = Math.round(color[i] * 255);
  5679. }
  5680. item.colorCssRgb = Util.makeCssRgb(rgb);
  5681. var highlight = document.createElement('div');
  5682. highlight.className = 'annotationHighlight';
  5683. highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
  5684. highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
  5685. highlight.setAttribute('hidden', true);
  5686. item.highlightElement = highlight;
  5687. container.appendChild(item.highlightElement);
  5688. return container;
  5689. }
  5690. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5691. var element = getEmptyContainer('div', item.rect, 0);
  5692. element.style.display = 'table';
  5693. var content = document.createElement('div');
  5694. content.textContent = item.fieldValue;
  5695. var textAlignment = item.textAlignment;
  5696. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5697. content.style.verticalAlign = 'middle';
  5698. content.style.display = 'table-cell';
  5699. var fontObj = item.fontRefName ?
  5700. commonObjs.getData(item.fontRefName) : null;
  5701. setTextStyles(content, item, fontObj);
  5702. element.appendChild(content);
  5703. return element;
  5704. }
  5705. function getHtmlElementForTextAnnotation(item) {
  5706. var rect = item.rect;
  5707. // sanity check because of OOo-generated PDFs
  5708. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5709. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5710. }
  5711. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5712. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5713. }
  5714. var container = initContainer(item);
  5715. container.className = 'annotText';
  5716. var image = document.createElement('img');
  5717. image.style.height = container.style.height;
  5718. image.style.width = container.style.width;
  5719. var iconName = item.name;
  5720. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5721. iconName.toLowerCase() + '.svg';
  5722. image.alt = '[{{type}} Annotation]';
  5723. image.dataset.l10nId = 'text_annotation_type';
  5724. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5725. var contentWrapper = document.createElement('div');
  5726. contentWrapper.className = 'annotTextContentWrapper';
  5727. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5728. contentWrapper.style.top = '-10px';
  5729. var content = document.createElement('div');
  5730. content.className = 'annotTextContent';
  5731. content.setAttribute('hidden', true);
  5732. var i, ii;
  5733. if (item.hasBgColor) {
  5734. var color = item.color;
  5735. var rgb = [];
  5736. for (i = 0; i < 3; ++i) {
  5737. // Enlighten the color (70%)
  5738. var c = Math.round(color[i] * 255);
  5739. rgb[i] = Math.round((255 - c) * 0.7) + c;
  5740. }
  5741. content.style.backgroundColor = Util.makeCssRgb(rgb);
  5742. }
  5743. var title = document.createElement('h1');
  5744. var text = document.createElement('p');
  5745. title.textContent = item.title;
  5746. if (!item.content && !item.title) {
  5747. content.setAttribute('hidden', true);
  5748. } else {
  5749. var e = document.createElement('span');
  5750. var lines = item.content.split(/(?:\r\n?|\n)/);
  5751. for (i = 0, ii = lines.length; i < ii; ++i) {
  5752. var line = lines[i];
  5753. e.appendChild(document.createTextNode(line));
  5754. if (i < (ii - 1)) {
  5755. e.appendChild(document.createElement('br'));
  5756. }
  5757. }
  5758. text.appendChild(e);
  5759. var pinned = false;
  5760. var showAnnotation = function showAnnotation(pin) {
  5761. if (pin) {
  5762. pinned = true;
  5763. }
  5764. if (content.hasAttribute('hidden')) {
  5765. container.style.zIndex += 1;
  5766. content.removeAttribute('hidden');
  5767. }
  5768. };
  5769. var hideAnnotation = function hideAnnotation(unpin) {
  5770. if (unpin) {
  5771. pinned = false;
  5772. }
  5773. if (!content.hasAttribute('hidden') && !pinned) {
  5774. container.style.zIndex -= 1;
  5775. content.setAttribute('hidden', true);
  5776. }
  5777. };
  5778. var toggleAnnotation = function toggleAnnotation() {
  5779. if (pinned) {
  5780. hideAnnotation(true);
  5781. } else {
  5782. showAnnotation(true);
  5783. }
  5784. };
  5785. image.addEventListener('click', function image_clickHandler() {
  5786. toggleAnnotation();
  5787. }, false);
  5788. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5789. showAnnotation();
  5790. }, false);
  5791. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5792. hideAnnotation();
  5793. }, false);
  5794. content.addEventListener('click', function content_clickHandler() {
  5795. hideAnnotation(true);
  5796. }, false);
  5797. }
  5798. content.appendChild(title);
  5799. content.appendChild(text);
  5800. contentWrapper.appendChild(content);
  5801. container.appendChild(image);
  5802. container.appendChild(contentWrapper);
  5803. return container;
  5804. }
  5805. function getHtmlElementForLinkAnnotation(item) {
  5806. var container = initContainer(item);
  5807. container.className = 'annotLink';
  5808. container.style.borderColor = item.colorCssRgb;
  5809. container.style.borderStyle = 'solid';
  5810. var link = document.createElement('a');
  5811. link.href = link.title = item.url || '';
  5812. container.appendChild(link);
  5813. return container;
  5814. }
  5815. function getHtmlElement(data, objs) {
  5816. switch (data.annotationType) {
  5817. case AnnotationType.WIDGET:
  5818. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5819. case AnnotationType.TEXT:
  5820. return getHtmlElementForTextAnnotation(data);
  5821. case AnnotationType.LINK:
  5822. return getHtmlElementForLinkAnnotation(data);
  5823. default:
  5824. throw new Error('Unsupported annotationType: ' + data.annotationType);
  5825. }
  5826. }
  5827. return {
  5828. getHtmlElement: getHtmlElement
  5829. };
  5830. })();
  5831. PDFJS.AnnotationUtils = AnnotationUtils;
  5832. var SVG_DEFAULTS = {
  5833. fontStyle: 'normal',
  5834. fontWeight: 'normal',
  5835. fillColor: '#000000'
  5836. };
  5837. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  5838. var PNG_HEADER =
  5839. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  5840. var CHUNK_WRAPPER_SIZE = 12;
  5841. var crcTable = new Int32Array(256);
  5842. for (var i = 0; i < 256; i++) {
  5843. var c = i;
  5844. for (var h = 0; h < 8; h++) {
  5845. if (c & 1) {
  5846. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  5847. } else {
  5848. c = (c >> 1) & 0x7fffffff;
  5849. }
  5850. }
  5851. crcTable[i] = c;
  5852. }
  5853. function crc32(data, start, end) {
  5854. var crc = -1;
  5855. for (var i = start; i < end; i++) {
  5856. var a = (crc ^ data[i]) & 0xff;
  5857. var b = crcTable[a];
  5858. crc = (crc >>> 8) ^ b;
  5859. }
  5860. return crc ^ -1;
  5861. }
  5862. function writePngChunk(type, body, data, offset) {
  5863. var p = offset;
  5864. var len = body.length;
  5865. data[p] = len >> 24 & 0xff;
  5866. data[p + 1] = len >> 16 & 0xff;
  5867. data[p + 2] = len >> 8 & 0xff;
  5868. data[p + 3] = len & 0xff;
  5869. p += 4;
  5870. data[p] = type.charCodeAt(0) & 0xff;
  5871. data[p + 1] = type.charCodeAt(1) & 0xff;
  5872. data[p + 2] = type.charCodeAt(2) & 0xff;
  5873. data[p + 3] = type.charCodeAt(3) & 0xff;
  5874. p += 4;
  5875. data.set(body, p);
  5876. p += body.length;
  5877. var crc = crc32(data, offset + 4, p);
  5878. data[p] = crc >> 24 & 0xff;
  5879. data[p + 1] = crc >> 16 & 0xff;
  5880. data[p + 2] = crc >> 8 & 0xff;
  5881. data[p + 3] = crc & 0xff;
  5882. }
  5883. function adler32(data, start, end) {
  5884. var a = 1;
  5885. var b = 0;
  5886. for (var i = start; i < end; ++i) {
  5887. a = (a + (data[i] & 0xff)) % 65521;
  5888. b = (b + a) % 65521;
  5889. }
  5890. return (b << 16) | a;
  5891. }
  5892. function encode(imgData, kind) {
  5893. var width = imgData.width;
  5894. var height = imgData.height;
  5895. var bitDepth, colorType, lineSize;
  5896. var bytes = imgData.data;
  5897. switch (kind) {
  5898. case ImageKind.GRAYSCALE_1BPP:
  5899. colorType = 0;
  5900. bitDepth = 1;
  5901. lineSize = (width + 7) >> 3;
  5902. break;
  5903. case ImageKind.RGB_24BPP:
  5904. colorType = 2;
  5905. bitDepth = 8;
  5906. lineSize = width * 3;
  5907. break;
  5908. case ImageKind.RGBA_32BPP:
  5909. colorType = 6;
  5910. bitDepth = 8;
  5911. lineSize = width * 4;
  5912. break;
  5913. default:
  5914. throw new Error('invalid format');
  5915. }
  5916. // prefix every row with predictor 0
  5917. var literals = new Uint8Array((1 + lineSize) * height);
  5918. var offsetLiterals = 0, offsetBytes = 0;
  5919. var y, i;
  5920. for (y = 0; y < height; ++y) {
  5921. literals[offsetLiterals++] = 0; // no prediction
  5922. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  5923. offsetLiterals);
  5924. offsetBytes += lineSize;
  5925. offsetLiterals += lineSize;
  5926. }
  5927. if (kind === ImageKind.GRAYSCALE_1BPP) {
  5928. // inverting for B/W
  5929. offsetLiterals = 0;
  5930. for (y = 0; y < height; y++) {
  5931. offsetLiterals++; // skipping predictor
  5932. for (i = 0; i < lineSize; i++) {
  5933. literals[offsetLiterals++] ^= 0xFF;
  5934. }
  5935. }
  5936. }
  5937. var ihdr = new Uint8Array([
  5938. width >> 24 & 0xff,
  5939. width >> 16 & 0xff,
  5940. width >> 8 & 0xff,
  5941. width & 0xff,
  5942. height >> 24 & 0xff,
  5943. height >> 16 & 0xff,
  5944. height >> 8 & 0xff,
  5945. height & 0xff,
  5946. bitDepth, // bit depth
  5947. colorType, // color type
  5948. 0x00, // compression method
  5949. 0x00, // filter method
  5950. 0x00 // interlace method
  5951. ]);
  5952. var len = literals.length;
  5953. var maxBlockLength = 0xFFFF;
  5954. var deflateBlocks = Math.ceil(len / maxBlockLength);
  5955. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  5956. var pi = 0;
  5957. idat[pi++] = 0x78; // compression method and flags
  5958. idat[pi++] = 0x9c; // flags
  5959. var pos = 0;
  5960. while (len > maxBlockLength) {
  5961. // writing non-final DEFLATE blocks type 0 and length of 65535
  5962. idat[pi++] = 0x00;
  5963. idat[pi++] = 0xff;
  5964. idat[pi++] = 0xff;
  5965. idat[pi++] = 0x00;
  5966. idat[pi++] = 0x00;
  5967. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  5968. pi += maxBlockLength;
  5969. pos += maxBlockLength;
  5970. len -= maxBlockLength;
  5971. }
  5972. // writing non-final DEFLATE blocks type 0
  5973. idat[pi++] = 0x01;
  5974. idat[pi++] = len & 0xff;
  5975. idat[pi++] = len >> 8 & 0xff;
  5976. idat[pi++] = (~len & 0xffff) & 0xff;
  5977. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  5978. idat.set(literals.subarray(pos), pi);
  5979. pi += literals.length - pos;
  5980. var adler = adler32(literals, 0, literals.length); // checksum
  5981. idat[pi++] = adler >> 24 & 0xff;
  5982. idat[pi++] = adler >> 16 & 0xff;
  5983. idat[pi++] = adler >> 8 & 0xff;
  5984. idat[pi++] = adler & 0xff;
  5985. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  5986. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  5987. ihdr.length + idat.length;
  5988. var data = new Uint8Array(pngLength);
  5989. var offset = 0;
  5990. data.set(PNG_HEADER, offset);
  5991. offset += PNG_HEADER.length;
  5992. writePngChunk('IHDR', ihdr, data, offset);
  5993. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  5994. writePngChunk('IDATA', idat, data, offset);
  5995. offset += CHUNK_WRAPPER_SIZE + idat.length;
  5996. writePngChunk('IEND', new Uint8Array(0), data, offset);
  5997. return PDFJS.createObjectURL(data, 'image/png');
  5998. }
  5999. return function convertImgDataToPng(imgData) {
  6000. var kind = (imgData.kind === undefined ?
  6001. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6002. return encode(imgData, kind);
  6003. };
  6004. })();
  6005. var SVGExtraState = (function SVGExtraStateClosure() {
  6006. function SVGExtraState() {
  6007. this.fontSizeScale = 1;
  6008. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6009. this.fontSize = 0;
  6010. this.textMatrix = IDENTITY_MATRIX;
  6011. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6012. this.leading = 0;
  6013. // Current point (in user coordinates)
  6014. this.x = 0;
  6015. this.y = 0;
  6016. // Start of text line (in text coordinates)
  6017. this.lineX = 0;
  6018. this.lineY = 0;
  6019. // Character and word spacing
  6020. this.charSpacing = 0;
  6021. this.wordSpacing = 0;
  6022. this.textHScale = 1;
  6023. this.textRise = 0;
  6024. // Default foreground and background colors
  6025. this.fillColor = SVG_DEFAULTS.fillColor;
  6026. this.strokeColor = '#000000';
  6027. this.fillAlpha = 1;
  6028. this.strokeAlpha = 1;
  6029. this.lineWidth = 1;
  6030. this.lineJoin = '';
  6031. this.lineCap = '';
  6032. this.miterLimit = 0;
  6033. this.dashArray = [];
  6034. this.dashPhase = 0;
  6035. this.dependencies = [];
  6036. // Clipping
  6037. this.clipId = '';
  6038. this.pendingClip = false;
  6039. this.maskId = '';
  6040. }
  6041. SVGExtraState.prototype = {
  6042. clone: function SVGExtraState_clone() {
  6043. return Object.create(this);
  6044. },
  6045. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6046. this.x = x;
  6047. this.y = y;
  6048. }
  6049. };
  6050. return SVGExtraState;
  6051. })();
  6052. var SVGGraphics = (function SVGGraphicsClosure() {
  6053. function createScratchSVG(width, height) {
  6054. var NS = 'http://www.w3.org/2000/svg';
  6055. var svg = document.createElementNS(NS, 'svg:svg');
  6056. svg.setAttributeNS(null, 'version', '1.1');
  6057. svg.setAttributeNS(null, 'width', width + 'px');
  6058. svg.setAttributeNS(null, 'height', height + 'px');
  6059. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6060. return svg;
  6061. }
  6062. function opListToTree(opList) {
  6063. var opTree = [];
  6064. var tmp = [];
  6065. var opListLen = opList.length;
  6066. for (var x = 0; x < opListLen; x++) {
  6067. if (opList[x].fn === 'save') {
  6068. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6069. tmp.push(opTree);
  6070. opTree = opTree[opTree.length - 1].items;
  6071. continue;
  6072. }
  6073. if(opList[x].fn === 'restore') {
  6074. opTree = tmp.pop();
  6075. } else {
  6076. opTree.push(opList[x]);
  6077. }
  6078. }
  6079. return opTree;
  6080. }
  6081. /**
  6082. * Formats float number.
  6083. * @param value {number} number to format.
  6084. * @returns {string}
  6085. */
  6086. function pf(value) {
  6087. if (value === (value | 0)) { // integer number
  6088. return value.toString();
  6089. }
  6090. var s = value.toFixed(10);
  6091. var i = s.length - 1;
  6092. if (s[i] !== '0') {
  6093. return s;
  6094. }
  6095. // removing trailing zeros
  6096. do {
  6097. i--;
  6098. } while (s[i] === '0');
  6099. return s.substr(0, s[i] === '.' ? i : i + 1);
  6100. }
  6101. /**
  6102. * Formats transform matrix. The standard rotation, scale and translate
  6103. * matrices are replaced by their shorter forms, and for identity matrix
  6104. * returns empty string to save the memory.
  6105. * @param m {Array} matrix to format.
  6106. * @returns {string}
  6107. */
  6108. function pm(m) {
  6109. if (m[4] === 0 && m[5] === 0) {
  6110. if (m[1] === 0 && m[2] === 0) {
  6111. if (m[0] === 1 && m[3] === 1) {
  6112. return '';
  6113. }
  6114. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6115. }
  6116. if (m[0] === m[3] && m[1] === -m[2]) {
  6117. var a = Math.acos(m[0]) * 180 / Math.PI;
  6118. return 'rotate(' + pf(a) + ')';
  6119. }
  6120. } else {
  6121. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6122. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6123. }
  6124. }
  6125. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6126. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6127. }
  6128. function SVGGraphics(commonObjs, objs) {
  6129. this.current = new SVGExtraState();
  6130. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6131. this.transformStack = [];
  6132. this.extraStack = [];
  6133. this.commonObjs = commonObjs;
  6134. this.objs = objs;
  6135. this.pendingEOFill = false;
  6136. this.embedFonts = false;
  6137. this.embeddedFonts = {};
  6138. this.cssStyle = null;
  6139. }
  6140. var NS = 'http://www.w3.org/2000/svg';
  6141. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6142. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6143. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6144. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6145. var clipCount = 0;
  6146. var maskCount = 0;
  6147. SVGGraphics.prototype = {
  6148. save: function SVGGraphics_save() {
  6149. this.transformStack.push(this.transformMatrix);
  6150. var old = this.current;
  6151. this.extraStack.push(old);
  6152. this.current = old.clone();
  6153. },
  6154. restore: function SVGGraphics_restore() {
  6155. this.transformMatrix = this.transformStack.pop();
  6156. this.current = this.extraStack.pop();
  6157. this.tgrp = document.createElementNS(NS, 'svg:g');
  6158. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6159. this.pgrp.appendChild(this.tgrp);
  6160. },
  6161. group: function SVGGraphics_group(items) {
  6162. this.save();
  6163. this.executeOpTree(items);
  6164. this.restore();
  6165. },
  6166. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6167. var fnArray = operatorList.fnArray;
  6168. var fnArrayLen = fnArray.length;
  6169. var argsArray = operatorList.argsArray;
  6170. var self = this;
  6171. for (var i = 0; i < fnArrayLen; i++) {
  6172. if (OPS.dependency === fnArray[i]) {
  6173. var deps = argsArray[i];
  6174. for (var n = 0, nn = deps.length; n < nn; n++) {
  6175. var obj = deps[n];
  6176. var common = obj.substring(0, 2) === 'g_';
  6177. var promise;
  6178. if (common) {
  6179. promise = new Promise(function(resolve) {
  6180. self.commonObjs.get(obj, resolve);
  6181. });
  6182. } else {
  6183. promise = new Promise(function(resolve) {
  6184. self.objs.get(obj, resolve);
  6185. });
  6186. }
  6187. this.current.dependencies.push(promise);
  6188. }
  6189. }
  6190. }
  6191. return Promise.all(this.current.dependencies);
  6192. },
  6193. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6194. var transformMatrix = [a, b, c, d, e, f];
  6195. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6196. transformMatrix);
  6197. this.tgrp = document.createElementNS(NS, 'svg:g');
  6198. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6199. },
  6200. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6201. this.svg = createScratchSVG(viewport.width, viewport.height);
  6202. this.viewport = viewport;
  6203. return this.loadDependencies(operatorList).then(function () {
  6204. this.transformMatrix = IDENTITY_MATRIX;
  6205. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6206. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6207. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6208. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6209. this.defs = document.createElementNS(NS, 'svg:defs');
  6210. this.pgrp.appendChild(this.defs);
  6211. this.pgrp.appendChild(this.tgrp);
  6212. this.svg.appendChild(this.pgrp);
  6213. var opTree = this.convertOpList(operatorList);
  6214. this.executeOpTree(opTree);
  6215. return this.svg;
  6216. }.bind(this));
  6217. },
  6218. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6219. var argsArray = operatorList.argsArray;
  6220. var fnArray = operatorList.fnArray;
  6221. var fnArrayLen = fnArray.length;
  6222. var REVOPS = [];
  6223. var opList = [];
  6224. for (var op in OPS) {
  6225. REVOPS[OPS[op]] = op;
  6226. }
  6227. for (var x = 0; x < fnArrayLen; x++) {
  6228. var fnId = fnArray[x];
  6229. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6230. }
  6231. return opListToTree(opList);
  6232. },
  6233. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6234. var opTreeLen = opTree.length;
  6235. for(var x = 0; x < opTreeLen; x++) {
  6236. var fn = opTree[x].fn;
  6237. var fnId = opTree[x].fnId;
  6238. var args = opTree[x].args;
  6239. switch (fnId | 0) {
  6240. case OPS.beginText:
  6241. this.beginText();
  6242. break;
  6243. case OPS.setLeading:
  6244. this.setLeading(args);
  6245. break;
  6246. case OPS.setLeadingMoveText:
  6247. this.setLeadingMoveText(args[0], args[1]);
  6248. break;
  6249. case OPS.setFont:
  6250. this.setFont(args);
  6251. break;
  6252. case OPS.showText:
  6253. this.showText(args[0]);
  6254. break;
  6255. case OPS.showSpacedText:
  6256. this.showText(args[0]);
  6257. break;
  6258. case OPS.endText:
  6259. this.endText();
  6260. break;
  6261. case OPS.moveText:
  6262. this.moveText(args[0], args[1]);
  6263. break;
  6264. case OPS.setCharSpacing:
  6265. this.setCharSpacing(args[0]);
  6266. break;
  6267. case OPS.setWordSpacing:
  6268. this.setWordSpacing(args[0]);
  6269. break;
  6270. case OPS.setTextMatrix:
  6271. this.setTextMatrix(args[0], args[1], args[2],
  6272. args[3], args[4], args[5]);
  6273. break;
  6274. case OPS.setLineWidth:
  6275. this.setLineWidth(args[0]);
  6276. break;
  6277. case OPS.setLineJoin:
  6278. this.setLineJoin(args[0]);
  6279. break;
  6280. case OPS.setLineCap:
  6281. this.setLineCap(args[0]);
  6282. break;
  6283. case OPS.setMiterLimit:
  6284. this.setMiterLimit(args[0]);
  6285. break;
  6286. case OPS.setFillRGBColor:
  6287. this.setFillRGBColor(args[0], args[1], args[2]);
  6288. break;
  6289. case OPS.setStrokeRGBColor:
  6290. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6291. break;
  6292. case OPS.setDash:
  6293. this.setDash(args[0], args[1]);
  6294. break;
  6295. case OPS.setGState:
  6296. this.setGState(args[0]);
  6297. break;
  6298. case OPS.fill:
  6299. this.fill();
  6300. break;
  6301. case OPS.eoFill:
  6302. this.eoFill();
  6303. break;
  6304. case OPS.stroke:
  6305. this.stroke();
  6306. break;
  6307. case OPS.fillStroke:
  6308. this.fillStroke();
  6309. break;
  6310. case OPS.eoFillStroke:
  6311. this.eoFillStroke();
  6312. break;
  6313. case OPS.clip:
  6314. this.clip('nonzero');
  6315. break;
  6316. case OPS.eoClip:
  6317. this.clip('evenodd');
  6318. break;
  6319. case OPS.paintSolidColorImageMask:
  6320. this.paintSolidColorImageMask();
  6321. break;
  6322. case OPS.paintJpegXObject:
  6323. this.paintJpegXObject(args[0], args[1], args[2]);
  6324. break;
  6325. case OPS.paintImageXObject:
  6326. this.paintImageXObject(args[0]);
  6327. break;
  6328. case OPS.paintInlineImageXObject:
  6329. this.paintInlineImageXObject(args[0]);
  6330. break;
  6331. case OPS.paintImageMaskXObject:
  6332. this.paintImageMaskXObject(args[0]);
  6333. break;
  6334. case OPS.paintFormXObjectBegin:
  6335. this.paintFormXObjectBegin(args[0], args[1]);
  6336. break;
  6337. case OPS.paintFormXObjectEnd:
  6338. this.paintFormXObjectEnd();
  6339. break;
  6340. case OPS.closePath:
  6341. this.closePath();
  6342. break;
  6343. case OPS.closeStroke:
  6344. this.closeStroke();
  6345. break;
  6346. case OPS.closeFillStroke:
  6347. this.closeFillStroke();
  6348. break;
  6349. case OPS.nextLine:
  6350. this.nextLine();
  6351. break;
  6352. case OPS.transform:
  6353. this.transform(args[0], args[1], args[2], args[3],
  6354. args[4], args[5]);
  6355. break;
  6356. case OPS.constructPath:
  6357. this.constructPath(args[0], args[1]);
  6358. break;
  6359. case OPS.endPath:
  6360. this.endPath();
  6361. break;
  6362. case 92:
  6363. this.group(opTree[x].items);
  6364. break;
  6365. default:
  6366. warn('Unimplemented method '+ fn);
  6367. break;
  6368. }
  6369. }
  6370. },
  6371. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6372. this.current.wordSpacing = wordSpacing;
  6373. },
  6374. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6375. this.current.charSpacing = charSpacing;
  6376. },
  6377. nextLine: function SVGGraphics_nextLine() {
  6378. this.moveText(0, this.current.leading);
  6379. },
  6380. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6381. var current = this.current;
  6382. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6383. this.current.x = this.current.lineX = 0;
  6384. this.current.y = this.current.lineY = 0;
  6385. current.xcoords = [];
  6386. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6387. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6388. current.tspan.setAttributeNS(null, 'font-size',
  6389. pf(current.fontSize) + 'px');
  6390. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6391. current.txtElement = document.createElementNS(NS, 'svg:text');
  6392. current.txtElement.appendChild(current.tspan);
  6393. },
  6394. beginText: function SVGGraphics_beginText() {
  6395. this.current.x = this.current.lineX = 0;
  6396. this.current.y = this.current.lineY = 0;
  6397. this.current.textMatrix = IDENTITY_MATRIX;
  6398. this.current.lineMatrix = IDENTITY_MATRIX;
  6399. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6400. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6401. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6402. this.current.xcoords = [];
  6403. },
  6404. moveText: function SVGGraphics_moveText(x, y) {
  6405. var current = this.current;
  6406. this.current.x = this.current.lineX += x;
  6407. this.current.y = this.current.lineY += y;
  6408. current.xcoords = [];
  6409. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6410. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6411. current.tspan.setAttributeNS(null, 'font-size',
  6412. pf(current.fontSize) + 'px');
  6413. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6414. },
  6415. showText: function SVGGraphics_showText(glyphs) {
  6416. var current = this.current;
  6417. var font = current.font;
  6418. var fontSize = current.fontSize;
  6419. if (fontSize === 0) {
  6420. return;
  6421. }
  6422. var charSpacing = current.charSpacing;
  6423. var wordSpacing = current.wordSpacing;
  6424. var fontDirection = current.fontDirection;
  6425. var textHScale = current.textHScale * fontDirection;
  6426. var glyphsLength = glyphs.length;
  6427. var vertical = font.vertical;
  6428. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6429. var x = 0, i;
  6430. for (i = 0; i < glyphsLength; ++i) {
  6431. var glyph = glyphs[i];
  6432. if (glyph === null) {
  6433. // word break
  6434. x += fontDirection * wordSpacing;
  6435. continue;
  6436. } else if (isNum(glyph)) {
  6437. x += -glyph * fontSize * 0.001;
  6438. continue;
  6439. }
  6440. current.xcoords.push(current.x + x * textHScale);
  6441. var width = glyph.width;
  6442. var character = glyph.fontChar;
  6443. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6444. x += charWidth;
  6445. current.tspan.textContent += character;
  6446. }
  6447. if (vertical) {
  6448. current.y -= x * textHScale;
  6449. } else {
  6450. current.x += x * textHScale;
  6451. }
  6452. current.tspan.setAttributeNS(null, 'x',
  6453. current.xcoords.map(pf).join(' '));
  6454. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6455. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6456. current.tspan.setAttributeNS(null, 'font-size',
  6457. pf(current.fontSize) + 'px');
  6458. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6459. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6460. }
  6461. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6462. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6463. }
  6464. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6465. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6466. }
  6467. current.txtElement.setAttributeNS(null, 'transform',
  6468. pm(current.textMatrix) +
  6469. ' scale(1, -1)' );
  6470. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6471. current.txtElement.appendChild(current.tspan);
  6472. current.txtgrp.appendChild(current.txtElement);
  6473. this.tgrp.appendChild(current.txtElement);
  6474. },
  6475. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6476. this.setLeading(-y);
  6477. this.moveText(x, y);
  6478. },
  6479. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6480. if (!this.cssStyle) {
  6481. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6482. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6483. this.defs.appendChild(this.cssStyle);
  6484. }
  6485. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6486. this.cssStyle.textContent +=
  6487. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6488. ' src: url(' + url + '); }\n';
  6489. },
  6490. setFont: function SVGGraphics_setFont(details) {
  6491. var current = this.current;
  6492. var fontObj = this.commonObjs.get(details[0]);
  6493. var size = details[1];
  6494. this.current.font = fontObj;
  6495. if (this.embedFonts && fontObj.data &&
  6496. !this.embeddedFonts[fontObj.loadedName]) {
  6497. this.addFontStyle(fontObj);
  6498. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6499. }
  6500. current.fontMatrix = (fontObj.fontMatrix ?
  6501. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6502. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6503. (fontObj.bold ? 'bold' : 'normal');
  6504. var italic = fontObj.italic ? 'italic' : 'normal';
  6505. if (size < 0) {
  6506. size = -size;
  6507. current.fontDirection = -1;
  6508. } else {
  6509. current.fontDirection = 1;
  6510. }
  6511. current.fontSize = size;
  6512. current.fontFamily = fontObj.loadedName;
  6513. current.fontWeight = bold;
  6514. current.fontStyle = italic;
  6515. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6516. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6517. current.xcoords = [];
  6518. },
  6519. endText: function SVGGraphics_endText() {
  6520. if (this.current.pendingClip) {
  6521. this.cgrp.appendChild(this.tgrp);
  6522. this.pgrp.appendChild(this.cgrp);
  6523. } else {
  6524. this.pgrp.appendChild(this.tgrp);
  6525. }
  6526. this.tgrp = document.createElementNS(NS, 'svg:g');
  6527. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6528. },
  6529. // Path properties
  6530. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6531. this.current.lineWidth = width;
  6532. },
  6533. setLineCap: function SVGGraphics_setLineCap(style) {
  6534. this.current.lineCap = LINE_CAP_STYLES[style];
  6535. },
  6536. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6537. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6538. },
  6539. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6540. this.current.miterLimit = limit;
  6541. },
  6542. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6543. var color = Util.makeCssRgb(arguments);
  6544. this.current.strokeColor = color;
  6545. },
  6546. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6547. var color = Util.makeCssRgb(arguments);
  6548. this.current.fillColor = color;
  6549. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6550. this.current.xcoords = [];
  6551. },
  6552. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6553. this.current.dashArray = dashArray;
  6554. this.current.dashPhase = dashPhase;
  6555. },
  6556. constructPath: function SVGGraphics_constructPath(ops, args) {
  6557. var current = this.current;
  6558. var x = current.x, y = current.y;
  6559. current.path = document.createElementNS(NS, 'svg:path');
  6560. var d = [];
  6561. var opLength = ops.length;
  6562. for (var i = 0, j = 0; i < opLength; i++) {
  6563. switch (ops[i] | 0) {
  6564. case OPS.rectangle:
  6565. x = args[j++];
  6566. y = args[j++];
  6567. var width = args[j++];
  6568. var height = args[j++];
  6569. var xw = x + width;
  6570. var yh = y + height;
  6571. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6572. 'L', pf(x), pf(yh), 'Z');
  6573. break;
  6574. case OPS.moveTo:
  6575. x = args[j++];
  6576. y = args[j++];
  6577. d.push('M', pf(x), pf(y));
  6578. break;
  6579. case OPS.lineTo:
  6580. x = args[j++];
  6581. y = args[j++];
  6582. d.push('L', pf(x) , pf(y));
  6583. break;
  6584. case OPS.curveTo:
  6585. x = args[j + 4];
  6586. y = args[j + 5];
  6587. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6588. pf(args[j + 3]), pf(x), pf(y));
  6589. j += 6;
  6590. break;
  6591. case OPS.curveTo2:
  6592. x = args[j + 2];
  6593. y = args[j + 3];
  6594. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6595. pf(args[j + 2]), pf(args[j + 3]));
  6596. j += 4;
  6597. break;
  6598. case OPS.curveTo3:
  6599. x = args[j + 2];
  6600. y = args[j + 3];
  6601. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6602. pf(x), pf(y));
  6603. j += 4;
  6604. break;
  6605. case OPS.closePath:
  6606. d.push('Z');
  6607. break;
  6608. }
  6609. }
  6610. current.path.setAttributeNS(null, 'd', d.join(' '));
  6611. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6612. pf(current.miterLimit));
  6613. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6614. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6615. current.path.setAttributeNS(null, 'stroke-width',
  6616. pf(current.lineWidth) + 'px');
  6617. current.path.setAttributeNS(null, 'stroke-dasharray',
  6618. current.dashArray.map(pf).join(' '));
  6619. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6620. pf(current.dashPhase) + 'px');
  6621. current.path.setAttributeNS(null, 'fill', 'none');
  6622. this.tgrp.appendChild(current.path);
  6623. if (current.pendingClip) {
  6624. this.cgrp.appendChild(this.tgrp);
  6625. this.pgrp.appendChild(this.cgrp);
  6626. } else {
  6627. this.pgrp.appendChild(this.tgrp);
  6628. }
  6629. // Saving a reference in current.element so that it can be addressed
  6630. // in 'fill' and 'stroke'
  6631. current.element = current.path;
  6632. current.setCurrentPoint(x, y);
  6633. },
  6634. endPath: function SVGGraphics_endPath() {
  6635. var current = this.current;
  6636. if (current.pendingClip) {
  6637. this.cgrp.appendChild(this.tgrp);
  6638. this.pgrp.appendChild(this.cgrp);
  6639. } else {
  6640. this.pgrp.appendChild(this.tgrp);
  6641. }
  6642. this.tgrp = document.createElementNS(NS, 'svg:g');
  6643. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6644. },
  6645. clip: function SVGGraphics_clip(type) {
  6646. var current = this.current;
  6647. // Add current path to clipping path
  6648. current.clipId = 'clippath' + clipCount;
  6649. clipCount++;
  6650. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6651. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6652. var clipElement = current.element.cloneNode();
  6653. if (type === 'evenodd') {
  6654. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6655. } else {
  6656. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6657. }
  6658. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6659. this.clippath.appendChild(clipElement);
  6660. this.defs.appendChild(this.clippath);
  6661. // Create a new group with that attribute
  6662. current.pendingClip = true;
  6663. this.cgrp = document.createElementNS(NS, 'svg:g');
  6664. this.cgrp.setAttributeNS(null, 'clip-path',
  6665. 'url(#' + current.clipId + ')');
  6666. this.pgrp.appendChild(this.cgrp);
  6667. },
  6668. closePath: function SVGGraphics_closePath() {
  6669. var current = this.current;
  6670. var d = current.path.getAttributeNS(null, 'd');
  6671. d += 'Z';
  6672. current.path.setAttributeNS(null, 'd', d);
  6673. },
  6674. setLeading: function SVGGraphics_setLeading(leading) {
  6675. this.current.leading = -leading;
  6676. },
  6677. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6678. this.current.textRise = textRise;
  6679. },
  6680. setHScale: function SVGGraphics_setHScale(scale) {
  6681. this.current.textHScale = scale / 100;
  6682. },
  6683. setGState: function SVGGraphics_setGState(states) {
  6684. for (var i = 0, ii = states.length; i < ii; i++) {
  6685. var state = states[i];
  6686. var key = state[0];
  6687. var value = state[1];
  6688. switch (key) {
  6689. case 'LW':
  6690. this.setLineWidth(value);
  6691. break;
  6692. case 'LC':
  6693. this.setLineCap(value);
  6694. break;
  6695. case 'LJ':
  6696. this.setLineJoin(value);
  6697. break;
  6698. case 'ML':
  6699. this.setMiterLimit(value);
  6700. break;
  6701. case 'D':
  6702. this.setDash(value[0], value[1]);
  6703. break;
  6704. case 'RI':
  6705. break;
  6706. case 'FL':
  6707. break;
  6708. case 'Font':
  6709. this.setFont(value);
  6710. break;
  6711. case 'CA':
  6712. break;
  6713. case 'ca':
  6714. break;
  6715. case 'BM':
  6716. break;
  6717. case 'SMask':
  6718. break;
  6719. }
  6720. }
  6721. },
  6722. fill: function SVGGraphics_fill() {
  6723. var current = this.current;
  6724. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6725. },
  6726. stroke: function SVGGraphics_stroke() {
  6727. var current = this.current;
  6728. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6729. current.element.setAttributeNS(null, 'fill', 'none');
  6730. },
  6731. eoFill: function SVGGraphics_eoFill() {
  6732. var current = this.current;
  6733. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6734. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6735. },
  6736. fillStroke: function SVGGraphics_fillStroke() {
  6737. // Order is important since stroke wants fill to be none.
  6738. // First stroke, then if fill needed, it will be overwritten.
  6739. this.stroke();
  6740. this.fill();
  6741. },
  6742. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6743. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6744. this.fillStroke();
  6745. },
  6746. closeStroke: function SVGGraphics_closeStroke() {
  6747. this.closePath();
  6748. this.stroke();
  6749. },
  6750. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6751. this.closePath();
  6752. this.fillStroke();
  6753. },
  6754. paintSolidColorImageMask:
  6755. function SVGGraphics_paintSolidColorImageMask() {
  6756. var current = this.current;
  6757. var rect = document.createElementNS(NS, 'svg:rect');
  6758. rect.setAttributeNS(null, 'x', '0');
  6759. rect.setAttributeNS(null, 'y', '0');
  6760. rect.setAttributeNS(null, 'width', '1px');
  6761. rect.setAttributeNS(null, 'height', '1px');
  6762. rect.setAttributeNS(null, 'fill', current.fillColor);
  6763. this.tgrp.appendChild(rect);
  6764. },
  6765. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6766. var current = this.current;
  6767. var imgObj = this.objs.get(objId);
  6768. var imgEl = document.createElementNS(NS, 'svg:image');
  6769. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6770. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6771. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6772. imgEl.setAttributeNS(null, 'x', '0');
  6773. imgEl.setAttributeNS(null, 'y', pf(-h));
  6774. imgEl.setAttributeNS(null, 'transform',
  6775. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6776. this.tgrp.appendChild(imgEl);
  6777. if (current.pendingClip) {
  6778. this.cgrp.appendChild(this.tgrp);
  6779. this.pgrp.appendChild(this.cgrp);
  6780. } else {
  6781. this.pgrp.appendChild(this.tgrp);
  6782. }
  6783. },
  6784. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6785. var imgData = this.objs.get(objId);
  6786. if (!imgData) {
  6787. warn('Dependent image isn\'t ready yet');
  6788. return;
  6789. }
  6790. this.paintInlineImageXObject(imgData);
  6791. },
  6792. paintInlineImageXObject:
  6793. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6794. var current = this.current;
  6795. var width = imgData.width;
  6796. var height = imgData.height;
  6797. var imgSrc = convertImgDataToPng(imgData);
  6798. var cliprect = document.createElementNS(NS, 'svg:rect');
  6799. cliprect.setAttributeNS(null, 'x', '0');
  6800. cliprect.setAttributeNS(null, 'y', '0');
  6801. cliprect.setAttributeNS(null, 'width', pf(width));
  6802. cliprect.setAttributeNS(null, 'height', pf(height));
  6803. current.element = cliprect;
  6804. this.clip('nonzero');
  6805. var imgEl = document.createElementNS(NS, 'svg:image');
  6806. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  6807. imgEl.setAttributeNS(null, 'x', '0');
  6808. imgEl.setAttributeNS(null, 'y', pf(-height));
  6809. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  6810. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  6811. imgEl.setAttributeNS(null, 'transform',
  6812. 'scale(' + pf(1 / width) + ' ' +
  6813. pf(-1 / height) + ')');
  6814. if (mask) {
  6815. mask.appendChild(imgEl);
  6816. } else {
  6817. this.tgrp.appendChild(imgEl);
  6818. }
  6819. if (current.pendingClip) {
  6820. this.cgrp.appendChild(this.tgrp);
  6821. this.pgrp.appendChild(this.cgrp);
  6822. } else {
  6823. this.pgrp.appendChild(this.tgrp);
  6824. }
  6825. },
  6826. paintImageMaskXObject:
  6827. function SVGGraphics_paintImageMaskXObject(imgData) {
  6828. var current = this.current;
  6829. var width = imgData.width;
  6830. var height = imgData.height;
  6831. var fillColor = current.fillColor;
  6832. current.maskId = 'mask' + maskCount++;
  6833. var mask = document.createElementNS(NS, 'svg:mask');
  6834. mask.setAttributeNS(null, 'id', current.maskId);
  6835. var rect = document.createElementNS(NS, 'svg:rect');
  6836. rect.setAttributeNS(null, 'x', '0');
  6837. rect.setAttributeNS(null, 'y', '0');
  6838. rect.setAttributeNS(null, 'width', pf(width));
  6839. rect.setAttributeNS(null, 'height', pf(height));
  6840. rect.setAttributeNS(null, 'fill', fillColor);
  6841. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  6842. this.defs.appendChild(mask);
  6843. this.tgrp.appendChild(rect);
  6844. this.paintInlineImageXObject(imgData, mask);
  6845. },
  6846. paintFormXObjectBegin:
  6847. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  6848. this.save();
  6849. if (isArray(matrix) && matrix.length === 6) {
  6850. this.transform(matrix[0], matrix[1], matrix[2],
  6851. matrix[3], matrix[4], matrix[5]);
  6852. }
  6853. if (isArray(bbox) && bbox.length === 4) {
  6854. var width = bbox[2] - bbox[0];
  6855. var height = bbox[3] - bbox[1];
  6856. var cliprect = document.createElementNS(NS, 'svg:rect');
  6857. cliprect.setAttributeNS(null, 'x', bbox[0]);
  6858. cliprect.setAttributeNS(null, 'y', bbox[1]);
  6859. cliprect.setAttributeNS(null, 'width', pf(width));
  6860. cliprect.setAttributeNS(null, 'height', pf(height));
  6861. this.current.element = cliprect;
  6862. this.clip('nonzero');
  6863. this.endPath();
  6864. }
  6865. },
  6866. paintFormXObjectEnd:
  6867. function SVGGraphics_paintFormXObjectEnd() {
  6868. this.restore();
  6869. }
  6870. };
  6871. return SVGGraphics;
  6872. })();
  6873. PDFJS.SVGGraphics = SVGGraphics;
  6874. var NetworkManager = (function NetworkManagerClosure() {
  6875. var OK_RESPONSE = 200;
  6876. var PARTIAL_CONTENT_RESPONSE = 206;
  6877. function NetworkManager(url, args) {
  6878. this.url = url;
  6879. args = args || {};
  6880. this.isHttp = /^https?:/i.test(url);
  6881. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  6882. this.withCredentials = args.withCredentials || false;
  6883. this.getXhr = args.getXhr ||
  6884. function NetworkManager_getXhr() {
  6885. return new XMLHttpRequest();
  6886. };
  6887. this.currXhrId = 0;
  6888. this.pendingRequests = {};
  6889. this.loadedRequests = {};
  6890. }
  6891. function getArrayBuffer(xhr) {
  6892. var data = xhr.response;
  6893. if (typeof data !== 'string') {
  6894. return data;
  6895. }
  6896. var length = data.length;
  6897. var array = new Uint8Array(length);
  6898. for (var i = 0; i < length; i++) {
  6899. array[i] = data.charCodeAt(i) & 0xFF;
  6900. }
  6901. return array.buffer;
  6902. }
  6903. NetworkManager.prototype = {
  6904. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  6905. var args = {
  6906. begin: begin,
  6907. end: end
  6908. };
  6909. for (var prop in listeners) {
  6910. args[prop] = listeners[prop];
  6911. }
  6912. return this.request(args);
  6913. },
  6914. requestFull: function NetworkManager_requestFull(listeners) {
  6915. return this.request(listeners);
  6916. },
  6917. request: function NetworkManager_request(args) {
  6918. var xhr = this.getXhr();
  6919. var xhrId = this.currXhrId++;
  6920. var pendingRequest = this.pendingRequests[xhrId] = {
  6921. xhr: xhr
  6922. };
  6923. xhr.open('GET', this.url);
  6924. xhr.withCredentials = this.withCredentials;
  6925. for (var property in this.httpHeaders) {
  6926. var value = this.httpHeaders[property];
  6927. if (typeof value === 'undefined') {
  6928. continue;
  6929. }
  6930. xhr.setRequestHeader(property, value);
  6931. }
  6932. if (this.isHttp && 'begin' in args && 'end' in args) {
  6933. var rangeStr = args.begin + '-' + (args.end - 1);
  6934. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  6935. pendingRequest.expectedStatus = 206;
  6936. } else {
  6937. pendingRequest.expectedStatus = 200;
  6938. }
  6939. if (args.onProgressiveData) {
  6940. xhr.responseType = 'moz-chunked-arraybuffer';
  6941. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  6942. pendingRequest.onProgressiveData = args.onProgressiveData;
  6943. pendingRequest.mozChunked = true;
  6944. } else {
  6945. xhr.responseType = 'arraybuffer';
  6946. }
  6947. } else {
  6948. xhr.responseType = 'arraybuffer';
  6949. }
  6950. if (args.onError) {
  6951. xhr.onerror = function(evt) {
  6952. args.onError(xhr.status);
  6953. };
  6954. }
  6955. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  6956. xhr.onprogress = this.onProgress.bind(this, xhrId);
  6957. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  6958. pendingRequest.onDone = args.onDone;
  6959. pendingRequest.onError = args.onError;
  6960. pendingRequest.onProgress = args.onProgress;
  6961. xhr.send(null);
  6962. return xhrId;
  6963. },
  6964. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  6965. var pendingRequest = this.pendingRequests[xhrId];
  6966. if (!pendingRequest) {
  6967. // Maybe abortRequest was called...
  6968. return;
  6969. }
  6970. if (pendingRequest.mozChunked) {
  6971. var chunk = getArrayBuffer(pendingRequest.xhr);
  6972. pendingRequest.onProgressiveData(chunk);
  6973. }
  6974. var onProgress = pendingRequest.onProgress;
  6975. if (onProgress) {
  6976. onProgress(evt);
  6977. }
  6978. },
  6979. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  6980. var pendingRequest = this.pendingRequests[xhrId];
  6981. if (!pendingRequest) {
  6982. // Maybe abortRequest was called...
  6983. return;
  6984. }
  6985. var xhr = pendingRequest.xhr;
  6986. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  6987. pendingRequest.onHeadersReceived();
  6988. delete pendingRequest.onHeadersReceived;
  6989. }
  6990. if (xhr.readyState !== 4) {
  6991. return;
  6992. }
  6993. if (!(xhrId in this.pendingRequests)) {
  6994. // The XHR request might have been aborted in onHeadersReceived()
  6995. // callback, in which case we should abort request
  6996. return;
  6997. }
  6998. delete this.pendingRequests[xhrId];
  6999. // success status == 0 can be on ftp, file and other protocols
  7000. if (xhr.status === 0 && this.isHttp) {
  7001. if (pendingRequest.onError) {
  7002. pendingRequest.onError(xhr.status);
  7003. }
  7004. return;
  7005. }
  7006. var xhrStatus = xhr.status || OK_RESPONSE;
  7007. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7008. // "A server MAY ignore the Range header". This means it's possible to
  7009. // get a 200 rather than a 206 response from a range request.
  7010. var ok_response_on_range_request =
  7011. xhrStatus === OK_RESPONSE &&
  7012. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7013. if (!ok_response_on_range_request &&
  7014. xhrStatus !== pendingRequest.expectedStatus) {
  7015. if (pendingRequest.onError) {
  7016. pendingRequest.onError(xhr.status);
  7017. }
  7018. return;
  7019. }
  7020. this.loadedRequests[xhrId] = true;
  7021. var chunk = getArrayBuffer(xhr);
  7022. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7023. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7024. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7025. var begin = parseInt(matches[1], 10);
  7026. pendingRequest.onDone({
  7027. begin: begin,
  7028. chunk: chunk
  7029. });
  7030. } else if (pendingRequest.onProgressiveData) {
  7031. pendingRequest.onDone(null);
  7032. } else {
  7033. pendingRequest.onDone({
  7034. begin: 0,
  7035. chunk: chunk
  7036. });
  7037. }
  7038. },
  7039. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7040. for (var xhrId in this.pendingRequests) {
  7041. return true;
  7042. }
  7043. return false;
  7044. },
  7045. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7046. return this.pendingRequests[xhrId].xhr;
  7047. },
  7048. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7049. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7050. },
  7051. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7052. return xhrId in this.pendingRequests;
  7053. },
  7054. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7055. return xhrId in this.loadedRequests;
  7056. },
  7057. abortAllRequests: function NetworkManager_abortAllRequests() {
  7058. for (var xhrId in this.pendingRequests) {
  7059. this.abortRequest(xhrId | 0);
  7060. }
  7061. },
  7062. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7063. var xhr = this.pendingRequests[xhrId].xhr;
  7064. delete this.pendingRequests[xhrId];
  7065. xhr.abort();
  7066. }
  7067. };
  7068. return NetworkManager;
  7069. })();
  7070. var ChunkedStream = (function ChunkedStreamClosure() {
  7071. function ChunkedStream(length, chunkSize, manager) {
  7072. this.bytes = new Uint8Array(length);
  7073. this.start = 0;
  7074. this.pos = 0;
  7075. this.end = length;
  7076. this.chunkSize = chunkSize;
  7077. this.loadedChunks = [];
  7078. this.numChunksLoaded = 0;
  7079. this.numChunks = Math.ceil(length / chunkSize);
  7080. this.manager = manager;
  7081. this.progressiveDataLength = 0;
  7082. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7083. }
  7084. // required methods for a stream. if a particular stream does not
  7085. // implement these, an error should be thrown
  7086. ChunkedStream.prototype = {
  7087. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7088. var chunks = [];
  7089. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7090. if (!this.loadedChunks[chunk]) {
  7091. chunks.push(chunk);
  7092. }
  7093. }
  7094. return chunks;
  7095. },
  7096. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7097. return [this];
  7098. },
  7099. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7100. return this.numChunksLoaded === this.numChunks;
  7101. },
  7102. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7103. var end = begin + chunk.byteLength;
  7104. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7105. // Using this.length is inaccurate here since this.start can be moved
  7106. // See ChunkedStream.moveStart()
  7107. var length = this.bytes.length;
  7108. assert(end % this.chunkSize === 0 || end === length,
  7109. 'Bad end offset: ' + end);
  7110. this.bytes.set(new Uint8Array(chunk), begin);
  7111. var chunkSize = this.chunkSize;
  7112. var beginChunk = Math.floor(begin / chunkSize);
  7113. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7114. var curChunk;
  7115. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7116. if (!this.loadedChunks[curChunk]) {
  7117. this.loadedChunks[curChunk] = true;
  7118. ++this.numChunksLoaded;
  7119. }
  7120. }
  7121. },
  7122. onReceiveProgressiveData:
  7123. function ChunkedStream_onReceiveProgressiveData(data) {
  7124. var position = this.progressiveDataLength;
  7125. var beginChunk = Math.floor(position / this.chunkSize);
  7126. this.bytes.set(new Uint8Array(data), position);
  7127. position += data.byteLength;
  7128. this.progressiveDataLength = position;
  7129. var endChunk = position >= this.end ? this.numChunks :
  7130. Math.floor(position / this.chunkSize);
  7131. var curChunk;
  7132. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7133. if (!this.loadedChunks[curChunk]) {
  7134. this.loadedChunks[curChunk] = true;
  7135. ++this.numChunksLoaded;
  7136. }
  7137. }
  7138. },
  7139. ensureByte: function ChunkedStream_ensureByte(pos) {
  7140. var chunk = Math.floor(pos / this.chunkSize);
  7141. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7142. return;
  7143. }
  7144. if (!this.loadedChunks[chunk]) {
  7145. throw new MissingDataException(pos, pos + 1);
  7146. }
  7147. this.lastSuccessfulEnsureByteChunk = chunk;
  7148. },
  7149. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7150. if (begin >= end) {
  7151. return;
  7152. }
  7153. if (end <= this.progressiveDataLength) {
  7154. return;
  7155. }
  7156. var chunkSize = this.chunkSize;
  7157. var beginChunk = Math.floor(begin / chunkSize);
  7158. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7159. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7160. if (!this.loadedChunks[chunk]) {
  7161. throw new MissingDataException(begin, end);
  7162. }
  7163. }
  7164. },
  7165. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7166. var chunk, n;
  7167. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7168. if (!this.loadedChunks[chunk]) {
  7169. return chunk;
  7170. }
  7171. }
  7172. // Wrap around to beginning
  7173. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7174. if (!this.loadedChunks[chunk]) {
  7175. return chunk;
  7176. }
  7177. }
  7178. return null;
  7179. },
  7180. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7181. return !!this.loadedChunks[chunk];
  7182. },
  7183. get length() {
  7184. return this.end - this.start;
  7185. },
  7186. get isEmpty() {
  7187. return this.length === 0;
  7188. },
  7189. getByte: function ChunkedStream_getByte() {
  7190. var pos = this.pos;
  7191. if (pos >= this.end) {
  7192. return -1;
  7193. }
  7194. this.ensureByte(pos);
  7195. return this.bytes[this.pos++];
  7196. },
  7197. getUint16: function ChunkedStream_getUint16() {
  7198. var b0 = this.getByte();
  7199. var b1 = this.getByte();
  7200. return (b0 << 8) + b1;
  7201. },
  7202. getInt32: function ChunkedStream_getInt32() {
  7203. var b0 = this.getByte();
  7204. var b1 = this.getByte();
  7205. var b2 = this.getByte();
  7206. var b3 = this.getByte();
  7207. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7208. },
  7209. // returns subarray of original buffer
  7210. // should only be read
  7211. getBytes: function ChunkedStream_getBytes(length) {
  7212. var bytes = this.bytes;
  7213. var pos = this.pos;
  7214. var strEnd = this.end;
  7215. if (!length) {
  7216. this.ensureRange(pos, strEnd);
  7217. return bytes.subarray(pos, strEnd);
  7218. }
  7219. var end = pos + length;
  7220. if (end > strEnd) {
  7221. end = strEnd;
  7222. }
  7223. this.ensureRange(pos, end);
  7224. this.pos = end;
  7225. return bytes.subarray(pos, end);
  7226. },
  7227. peekByte: function ChunkedStream_peekByte() {
  7228. var peekedByte = this.getByte();
  7229. this.pos--;
  7230. return peekedByte;
  7231. },
  7232. peekBytes: function ChunkedStream_peekBytes(length) {
  7233. var bytes = this.getBytes(length);
  7234. this.pos -= bytes.length;
  7235. return bytes;
  7236. },
  7237. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7238. this.ensureRange(begin, end);
  7239. return this.bytes.subarray(begin, end);
  7240. },
  7241. skip: function ChunkedStream_skip(n) {
  7242. if (!n) {
  7243. n = 1;
  7244. }
  7245. this.pos += n;
  7246. },
  7247. reset: function ChunkedStream_reset() {
  7248. this.pos = this.start;
  7249. },
  7250. moveStart: function ChunkedStream_moveStart() {
  7251. this.start = this.pos;
  7252. },
  7253. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7254. this.ensureRange(start, start + length);
  7255. function ChunkedStreamSubstream() {}
  7256. ChunkedStreamSubstream.prototype = Object.create(this);
  7257. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7258. var chunkSize = this.chunkSize;
  7259. var beginChunk = Math.floor(this.start / chunkSize);
  7260. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7261. var missingChunks = [];
  7262. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7263. if (!this.loadedChunks[chunk]) {
  7264. missingChunks.push(chunk);
  7265. }
  7266. }
  7267. return missingChunks;
  7268. };
  7269. var subStream = new ChunkedStreamSubstream();
  7270. subStream.pos = subStream.start = start;
  7271. subStream.end = start + length || this.end;
  7272. subStream.dict = dict;
  7273. return subStream;
  7274. },
  7275. isStream: true
  7276. };
  7277. return ChunkedStream;
  7278. })();
  7279. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7280. function ChunkedStreamManager(length, chunkSize, url, args) {
  7281. this.stream = new ChunkedStream(length, chunkSize, this);
  7282. this.length = length;
  7283. this.chunkSize = chunkSize;
  7284. this.url = url;
  7285. this.disableAutoFetch = args.disableAutoFetch;
  7286. var msgHandler = this.msgHandler = args.msgHandler;
  7287. if (args.chunkedViewerLoading) {
  7288. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7289. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7290. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7291. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7292. };
  7293. } else {
  7294. var getXhr = function getXhr() {
  7295. return new XMLHttpRequest();
  7296. };
  7297. this.networkManager = new NetworkManager(this.url, {
  7298. getXhr: getXhr,
  7299. httpHeaders: args.httpHeaders,
  7300. withCredentials: args.withCredentials
  7301. });
  7302. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7303. this.networkManager.requestRange(begin, end, {
  7304. onDone: this.onReceiveData.bind(this),
  7305. onProgress: this.onProgress.bind(this)
  7306. });
  7307. };
  7308. }
  7309. this.currRequestId = 0;
  7310. this.chunksNeededByRequest = {};
  7311. this.requestsByChunk = {};
  7312. this.callbacksByRequest = {};
  7313. this.progressiveDataLength = 0;
  7314. this._loadedStreamCapability = createPromiseCapability();
  7315. if (args.initialData) {
  7316. this.onReceiveData({chunk: args.initialData});
  7317. }
  7318. }
  7319. ChunkedStreamManager.prototype = {
  7320. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7321. return this._loadedStreamCapability.promise;
  7322. },
  7323. // Get all the chunks that are not yet loaded and groups them into
  7324. // contiguous ranges to load in as few requests as possible
  7325. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7326. var missingChunks = this.stream.getMissingChunks();
  7327. this.requestChunks(missingChunks);
  7328. return this._loadedStreamCapability.promise;
  7329. },
  7330. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7331. callback) {
  7332. var requestId = this.currRequestId++;
  7333. var chunksNeeded;
  7334. var i, ii;
  7335. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7336. for (i = 0, ii = chunks.length; i < ii; i++) {
  7337. if (!this.stream.hasChunk(chunks[i])) {
  7338. chunksNeeded[chunks[i]] = true;
  7339. }
  7340. }
  7341. if (isEmptyObj(chunksNeeded)) {
  7342. if (callback) {
  7343. callback();
  7344. }
  7345. return;
  7346. }
  7347. this.callbacksByRequest[requestId] = callback;
  7348. var chunksToRequest = [];
  7349. for (var chunk in chunksNeeded) {
  7350. chunk = chunk | 0;
  7351. if (!(chunk in this.requestsByChunk)) {
  7352. this.requestsByChunk[chunk] = [];
  7353. chunksToRequest.push(chunk);
  7354. }
  7355. this.requestsByChunk[chunk].push(requestId);
  7356. }
  7357. if (!chunksToRequest.length) {
  7358. return;
  7359. }
  7360. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7361. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7362. var groupedChunk = groupedChunksToRequest[i];
  7363. var begin = groupedChunk.beginChunk * this.chunkSize;
  7364. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7365. this.sendRequest(begin, end);
  7366. }
  7367. },
  7368. getStream: function ChunkedStreamManager_getStream() {
  7369. return this.stream;
  7370. },
  7371. // Loads any chunks in the requested range that are not yet loaded
  7372. requestRange: function ChunkedStreamManager_requestRange(
  7373. begin, end, callback) {
  7374. end = Math.min(end, this.length);
  7375. var beginChunk = this.getBeginChunk(begin);
  7376. var endChunk = this.getEndChunk(end);
  7377. var chunks = [];
  7378. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7379. chunks.push(chunk);
  7380. }
  7381. this.requestChunks(chunks, callback);
  7382. },
  7383. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7384. callback) {
  7385. ranges = ranges || [];
  7386. var chunksToRequest = [];
  7387. for (var i = 0; i < ranges.length; i++) {
  7388. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7389. var endChunk = this.getEndChunk(ranges[i].end);
  7390. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7391. if (chunksToRequest.indexOf(chunk) < 0) {
  7392. chunksToRequest.push(chunk);
  7393. }
  7394. }
  7395. }
  7396. chunksToRequest.sort(function(a, b) { return a - b; });
  7397. this.requestChunks(chunksToRequest, callback);
  7398. },
  7399. // Groups a sorted array of chunks into as few continguous larger
  7400. // chunks as possible
  7401. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7402. var groupedChunks = [];
  7403. var beginChunk = -1;
  7404. var prevChunk = -1;
  7405. for (var i = 0; i < chunks.length; ++i) {
  7406. var chunk = chunks[i];
  7407. if (beginChunk < 0) {
  7408. beginChunk = chunk;
  7409. }
  7410. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7411. groupedChunks.push({ beginChunk: beginChunk,
  7412. endChunk: prevChunk + 1 });
  7413. beginChunk = chunk;
  7414. }
  7415. if (i + 1 === chunks.length) {
  7416. groupedChunks.push({ beginChunk: beginChunk,
  7417. endChunk: chunk + 1 });
  7418. }
  7419. prevChunk = chunk;
  7420. }
  7421. return groupedChunks;
  7422. },
  7423. onProgress: function ChunkedStreamManager_onProgress(args) {
  7424. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7425. args.loaded);
  7426. this.msgHandler.send('DocProgress', {
  7427. loaded: bytesLoaded,
  7428. total: this.length
  7429. });
  7430. },
  7431. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7432. var chunk = args.chunk;
  7433. var isProgressive = args.begin === undefined;
  7434. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7435. var end = begin + chunk.byteLength;
  7436. var beginChunk = Math.floor(begin / this.chunkSize);
  7437. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7438. Math.ceil(end / this.chunkSize);
  7439. if (isProgressive) {
  7440. this.stream.onReceiveProgressiveData(chunk);
  7441. this.progressiveDataLength = end;
  7442. } else {
  7443. this.stream.onReceiveData(begin, chunk);
  7444. }
  7445. if (this.stream.allChunksLoaded()) {
  7446. this._loadedStreamCapability.resolve(this.stream);
  7447. }
  7448. var loadedRequests = [];
  7449. var i, requestId;
  7450. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7451. // The server might return more chunks than requested
  7452. var requestIds = this.requestsByChunk[chunk] || [];
  7453. delete this.requestsByChunk[chunk];
  7454. for (i = 0; i < requestIds.length; ++i) {
  7455. requestId = requestIds[i];
  7456. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7457. if (chunk in chunksNeeded) {
  7458. delete chunksNeeded[chunk];
  7459. }
  7460. if (!isEmptyObj(chunksNeeded)) {
  7461. continue;
  7462. }
  7463. loadedRequests.push(requestId);
  7464. }
  7465. }
  7466. // If there are no pending requests, automatically fetch the next
  7467. // unfetched chunk of the PDF
  7468. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7469. var nextEmptyChunk;
  7470. if (this.stream.numChunksLoaded === 1) {
  7471. // This is a special optimization so that after fetching the first
  7472. // chunk, rather than fetching the second chunk, we fetch the last
  7473. // chunk.
  7474. var lastChunk = this.stream.numChunks - 1;
  7475. if (!this.stream.hasChunk(lastChunk)) {
  7476. nextEmptyChunk = lastChunk;
  7477. }
  7478. } else {
  7479. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7480. }
  7481. if (isInt(nextEmptyChunk)) {
  7482. this.requestChunks([nextEmptyChunk]);
  7483. }
  7484. }
  7485. for (i = 0; i < loadedRequests.length; ++i) {
  7486. requestId = loadedRequests[i];
  7487. var callback = this.callbacksByRequest[requestId];
  7488. delete this.callbacksByRequest[requestId];
  7489. if (callback) {
  7490. callback();
  7491. }
  7492. }
  7493. this.msgHandler.send('DocProgress', {
  7494. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7495. total: this.length
  7496. });
  7497. },
  7498. onError: function ChunkedStreamManager_onError(err) {
  7499. this._loadedStreamCapability.reject(err);
  7500. },
  7501. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7502. var chunk = Math.floor(begin / this.chunkSize);
  7503. return chunk;
  7504. },
  7505. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7506. if (end % this.chunkSize === 0) {
  7507. return end / this.chunkSize;
  7508. }
  7509. // 0 -> 0
  7510. // 1 -> 1
  7511. // 99 -> 1
  7512. // 100 -> 1
  7513. // 101 -> 2
  7514. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7515. return chunk;
  7516. }
  7517. };
  7518. return ChunkedStreamManager;
  7519. })();
  7520. // The maximum number of bytes fetched per range request
  7521. var RANGE_CHUNK_SIZE = 65536;
  7522. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7523. var BasePdfManager = (function BasePdfManagerClosure() {
  7524. function BasePdfManager() {
  7525. throw new Error('Cannot initialize BaseManagerManager');
  7526. }
  7527. BasePdfManager.prototype = {
  7528. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7529. throw new NotImplementedException();
  7530. },
  7531. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7532. return this.ensure(this.pdfDocument, prop, args);
  7533. },
  7534. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7535. return this.ensure(this.pdfDocument.xref, prop, args);
  7536. },
  7537. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7538. return this.ensure(this.pdfDocument.catalog, prop, args);
  7539. },
  7540. getPage: function BasePdfManager_pagePage(pageIndex) {
  7541. return this.pdfDocument.getPage(pageIndex);
  7542. },
  7543. cleanup: function BasePdfManager_cleanup() {
  7544. return this.pdfDocument.cleanup();
  7545. },
  7546. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7547. return new NotImplementedException();
  7548. },
  7549. requestRange: function BasePdfManager_ensure(begin, end) {
  7550. return new NotImplementedException();
  7551. },
  7552. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7553. return new NotImplementedException();
  7554. },
  7555. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7556. return new NotImplementedException();
  7557. },
  7558. updatePassword: function BasePdfManager_updatePassword(password) {
  7559. this.pdfDocument.xref.password = this.password = password;
  7560. if (this._passwordChangedCapability) {
  7561. this._passwordChangedCapability.resolve();
  7562. }
  7563. },
  7564. passwordChanged: function BasePdfManager_passwordChanged() {
  7565. this._passwordChangedCapability = createPromiseCapability();
  7566. return this._passwordChangedCapability.promise;
  7567. },
  7568. terminate: function BasePdfManager_terminate() {
  7569. return new NotImplementedException();
  7570. }
  7571. };
  7572. return BasePdfManager;
  7573. })();
  7574. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7575. function LocalPdfManager(data, password) {
  7576. var stream = new Stream(data);
  7577. this.pdfDocument = new PDFDocument(this, stream, password);
  7578. this._loadedStreamCapability = createPromiseCapability();
  7579. this._loadedStreamCapability.resolve(stream);
  7580. }
  7581. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7582. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7583. LocalPdfManager.prototype.ensure =
  7584. function LocalPdfManager_ensure(obj, prop, args) {
  7585. return new Promise(function (resolve, reject) {
  7586. try {
  7587. var value = obj[prop];
  7588. var result;
  7589. if (typeof value === 'function') {
  7590. result = value.apply(obj, args);
  7591. } else {
  7592. result = value;
  7593. }
  7594. resolve(result);
  7595. } catch (e) {
  7596. reject(e);
  7597. }
  7598. });
  7599. };
  7600. LocalPdfManager.prototype.requestRange =
  7601. function LocalPdfManager_requestRange(begin, end) {
  7602. return Promise.resolve();
  7603. };
  7604. LocalPdfManager.prototype.requestLoadedStream =
  7605. function LocalPdfManager_requestLoadedStream() {
  7606. };
  7607. LocalPdfManager.prototype.onLoadedStream =
  7608. function LocalPdfManager_getLoadedStream() {
  7609. return this._loadedStreamCapability.promise;
  7610. };
  7611. LocalPdfManager.prototype.terminate =
  7612. function LocalPdfManager_terminate() {
  7613. return;
  7614. };
  7615. return LocalPdfManager;
  7616. })();
  7617. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7618. function NetworkPdfManager(args, msgHandler) {
  7619. this.msgHandler = msgHandler;
  7620. var params = {
  7621. msgHandler: msgHandler,
  7622. httpHeaders: args.httpHeaders,
  7623. withCredentials: args.withCredentials,
  7624. chunkedViewerLoading: args.chunkedViewerLoading,
  7625. disableAutoFetch: args.disableAutoFetch,
  7626. initialData: args.initialData
  7627. };
  7628. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7629. args.url, params);
  7630. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7631. args.password);
  7632. }
  7633. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7634. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7635. NetworkPdfManager.prototype.ensure =
  7636. function NetworkPdfManager_ensure(obj, prop, args) {
  7637. var pdfManager = this;
  7638. return new Promise(function (resolve, reject) {
  7639. function ensureHelper() {
  7640. try {
  7641. var result;
  7642. var value = obj[prop];
  7643. if (typeof value === 'function') {
  7644. result = value.apply(obj, args);
  7645. } else {
  7646. result = value;
  7647. }
  7648. resolve(result);
  7649. } catch(e) {
  7650. if (!(e instanceof MissingDataException)) {
  7651. reject(e);
  7652. return;
  7653. }
  7654. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7655. }
  7656. }
  7657. ensureHelper();
  7658. });
  7659. };
  7660. NetworkPdfManager.prototype.requestRange =
  7661. function NetworkPdfManager_requestRange(begin, end) {
  7662. return new Promise(function (resolve) {
  7663. this.streamManager.requestRange(begin, end, function() {
  7664. resolve();
  7665. });
  7666. }.bind(this));
  7667. };
  7668. NetworkPdfManager.prototype.requestLoadedStream =
  7669. function NetworkPdfManager_requestLoadedStream() {
  7670. this.streamManager.requestAllChunks();
  7671. };
  7672. NetworkPdfManager.prototype.sendProgressiveData =
  7673. function NetworkPdfManager_sendProgressiveData(chunk) {
  7674. this.streamManager.onReceiveData({ chunk: chunk });
  7675. };
  7676. NetworkPdfManager.prototype.onLoadedStream =
  7677. function NetworkPdfManager_getLoadedStream() {
  7678. return this.streamManager.onLoadedStream();
  7679. };
  7680. NetworkPdfManager.prototype.terminate =
  7681. function NetworkPdfManager_terminate() {
  7682. this.streamManager.networkManager.abortAllRequests();
  7683. };
  7684. return NetworkPdfManager;
  7685. })();
  7686. var Page = (function PageClosure() {
  7687. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7688. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7689. this.pdfManager = pdfManager;
  7690. this.pageIndex = pageIndex;
  7691. this.pageDict = pageDict;
  7692. this.xref = xref;
  7693. this.ref = ref;
  7694. this.fontCache = fontCache;
  7695. this.idCounters = {
  7696. obj: 0
  7697. };
  7698. this.resourcesPromise = null;
  7699. }
  7700. Page.prototype = {
  7701. getPageProp: function Page_getPageProp(key) {
  7702. return this.pageDict.get(key);
  7703. },
  7704. getInheritedPageProp: function Page_inheritPageProp(key) {
  7705. var dict = this.pageDict;
  7706. var value = dict.get(key);
  7707. while (value === undefined) {
  7708. dict = dict.get('Parent');
  7709. if (!dict) {
  7710. break;
  7711. }
  7712. value = dict.get(key);
  7713. }
  7714. return value;
  7715. },
  7716. get content() {
  7717. return this.getPageProp('Contents');
  7718. },
  7719. get resources() {
  7720. var value = this.getInheritedPageProp('Resources');
  7721. // For robustness: The spec states that a \Resources entry has to be
  7722. // present, but can be empty. Some document omit it still. In this case
  7723. // return an empty dictionary:
  7724. if (value === undefined) {
  7725. value = Dict.empty;
  7726. }
  7727. return shadow(this, 'resources', value);
  7728. },
  7729. get mediaBox() {
  7730. var obj = this.getInheritedPageProp('MediaBox');
  7731. // Reset invalid media box to letter size.
  7732. if (!isArray(obj) || obj.length !== 4) {
  7733. obj = LETTER_SIZE_MEDIABOX;
  7734. }
  7735. return shadow(this, 'mediaBox', obj);
  7736. },
  7737. get view() {
  7738. var mediaBox = this.mediaBox;
  7739. var cropBox = this.getInheritedPageProp('CropBox');
  7740. if (!isArray(cropBox) || cropBox.length !== 4) {
  7741. return shadow(this, 'view', mediaBox);
  7742. }
  7743. // From the spec, 6th ed., p.963:
  7744. // "The crop, bleed, trim, and art boxes should not ordinarily
  7745. // extend beyond the boundaries of the media box. If they do, they are
  7746. // effectively reduced to their intersection with the media box."
  7747. cropBox = Util.intersect(cropBox, mediaBox);
  7748. if (!cropBox) {
  7749. return shadow(this, 'view', mediaBox);
  7750. }
  7751. return shadow(this, 'view', cropBox);
  7752. },
  7753. get annotationRefs() {
  7754. return shadow(this, 'annotationRefs',
  7755. this.getInheritedPageProp('Annots'));
  7756. },
  7757. get rotate() {
  7758. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7759. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7760. if (rotate % 90 !== 0) {
  7761. rotate = 0;
  7762. } else if (rotate >= 360) {
  7763. rotate = rotate % 360;
  7764. } else if (rotate < 0) {
  7765. // The spec doesn't cover negatives, assume its counterclockwise
  7766. // rotation. The following is the other implementation of modulo.
  7767. rotate = ((rotate % 360) + 360) % 360;
  7768. }
  7769. return shadow(this, 'rotate', rotate);
  7770. },
  7771. getContentStream: function Page_getContentStream() {
  7772. var content = this.content;
  7773. var stream;
  7774. if (isArray(content)) {
  7775. // fetching items
  7776. var xref = this.xref;
  7777. var i, n = content.length;
  7778. var streams = [];
  7779. for (i = 0; i < n; ++i) {
  7780. streams.push(xref.fetchIfRef(content[i]));
  7781. }
  7782. stream = new StreamsSequenceStream(streams);
  7783. } else if (isStream(content)) {
  7784. stream = content;
  7785. } else {
  7786. // replacing non-existent page content with empty one
  7787. stream = new NullStream();
  7788. }
  7789. return stream;
  7790. },
  7791. loadResources: function Page_loadResources(keys) {
  7792. if (!this.resourcesPromise) {
  7793. // TODO: add async getInheritedPageProp and remove this.
  7794. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  7795. }
  7796. return this.resourcesPromise.then(function resourceSuccess() {
  7797. var objectLoader = new ObjectLoader(this.resources.map,
  7798. keys,
  7799. this.xref);
  7800. return objectLoader.load();
  7801. }.bind(this));
  7802. },
  7803. getOperatorList: function Page_getOperatorList(handler, intent) {
  7804. var self = this;
  7805. var pdfManager = this.pdfManager;
  7806. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7807. []);
  7808. var resourcesPromise = this.loadResources([
  7809. 'ExtGState',
  7810. 'ColorSpace',
  7811. 'Pattern',
  7812. 'Shading',
  7813. 'XObject',
  7814. 'Font'
  7815. // ProcSet
  7816. // Properties
  7817. ]);
  7818. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  7819. handler, this.pageIndex,
  7820. 'p' + this.pageIndex + '_',
  7821. this.idCounters,
  7822. this.fontCache);
  7823. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  7824. var pageListPromise = dataPromises.then(function(data) {
  7825. var contentStream = data[0];
  7826. var opList = new OperatorList(intent, handler, self.pageIndex);
  7827. handler.send('StartRenderPage', {
  7828. transparency: partialEvaluator.hasBlendModes(self.resources),
  7829. pageIndex: self.pageIndex,
  7830. intent: intent
  7831. });
  7832. return partialEvaluator.getOperatorList(contentStream, self.resources,
  7833. opList).then(function () {
  7834. return opList;
  7835. });
  7836. });
  7837. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  7838. return Promise.all([pageListPromise, annotationsPromise]).then(
  7839. function(datas) {
  7840. var pageOpList = datas[0];
  7841. var annotations = datas[1];
  7842. if (annotations.length === 0) {
  7843. pageOpList.flush(true);
  7844. return pageOpList;
  7845. }
  7846. var annotationsReadyPromise = Annotation.appendToOperatorList(
  7847. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  7848. return annotationsReadyPromise.then(function () {
  7849. pageOpList.flush(true);
  7850. return pageOpList;
  7851. });
  7852. });
  7853. },
  7854. extractTextContent: function Page_extractTextContent() {
  7855. var handler = {
  7856. on: function nullHandlerOn() {},
  7857. send: function nullHandlerSend() {}
  7858. };
  7859. var self = this;
  7860. var pdfManager = this.pdfManager;
  7861. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7862. []);
  7863. var resourcesPromise = this.loadResources([
  7864. 'ExtGState',
  7865. 'XObject',
  7866. 'Font'
  7867. ]);
  7868. var dataPromises = Promise.all([contentStreamPromise,
  7869. resourcesPromise]);
  7870. return dataPromises.then(function(data) {
  7871. var contentStream = data[0];
  7872. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  7873. handler, self.pageIndex,
  7874. 'p' + self.pageIndex + '_',
  7875. self.idCounters,
  7876. self.fontCache);
  7877. return partialEvaluator.getTextContent(contentStream,
  7878. self.resources);
  7879. });
  7880. },
  7881. getAnnotationsData: function Page_getAnnotationsData() {
  7882. var annotations = this.annotations;
  7883. var annotationsData = [];
  7884. for (var i = 0, n = annotations.length; i < n; ++i) {
  7885. annotationsData.push(annotations[i].getData());
  7886. }
  7887. return annotationsData;
  7888. },
  7889. get annotations() {
  7890. var annotations = [];
  7891. var annotationRefs = (this.annotationRefs || []);
  7892. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  7893. var annotationRef = annotationRefs[i];
  7894. var annotation = Annotation.fromRef(this.xref, annotationRef);
  7895. if (annotation) {
  7896. annotations.push(annotation);
  7897. }
  7898. }
  7899. return shadow(this, 'annotations', annotations);
  7900. }
  7901. };
  7902. return Page;
  7903. })();
  7904. /**
  7905. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  7906. * `PDFDoc`, this one doesn't have any job management code.
  7907. * Right now there exists one PDFDocument on the main thread + one object
  7908. * for each worker. If there is no worker support enabled, there are two
  7909. * `PDFDocument` objects on the main thread created.
  7910. */
  7911. var PDFDocument = (function PDFDocumentClosure() {
  7912. function PDFDocument(pdfManager, arg, password) {
  7913. if (isStream(arg)) {
  7914. init.call(this, pdfManager, arg, password);
  7915. } else if (isArrayBuffer(arg)) {
  7916. init.call(this, pdfManager, new Stream(arg), password);
  7917. } else {
  7918. error('PDFDocument: Unknown argument type');
  7919. }
  7920. }
  7921. function init(pdfManager, stream, password) {
  7922. assert(stream.length > 0, 'stream must have data');
  7923. this.pdfManager = pdfManager;
  7924. this.stream = stream;
  7925. var xref = new XRef(this.stream, password, pdfManager);
  7926. this.xref = xref;
  7927. }
  7928. function find(stream, needle, limit, backwards) {
  7929. var pos = stream.pos;
  7930. var end = stream.end;
  7931. var strBuf = [];
  7932. if (pos + limit > end) {
  7933. limit = end - pos;
  7934. }
  7935. for (var n = 0; n < limit; ++n) {
  7936. strBuf.push(String.fromCharCode(stream.getByte()));
  7937. }
  7938. var str = strBuf.join('');
  7939. stream.pos = pos;
  7940. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  7941. if (index === -1) {
  7942. return false; /* not found */
  7943. }
  7944. stream.pos += index;
  7945. return true; /* found */
  7946. }
  7947. var DocumentInfoValidators = {
  7948. get entries() {
  7949. // Lazily build this since all the validation functions below are not
  7950. // defined until after this file loads.
  7951. return shadow(this, 'entries', {
  7952. Title: isString,
  7953. Author: isString,
  7954. Subject: isString,
  7955. Keywords: isString,
  7956. Creator: isString,
  7957. Producer: isString,
  7958. CreationDate: isString,
  7959. ModDate: isString,
  7960. Trapped: isName
  7961. });
  7962. }
  7963. };
  7964. PDFDocument.prototype = {
  7965. parse: function PDFDocument_parse(recoveryMode) {
  7966. this.setup(recoveryMode);
  7967. try {
  7968. // checking if AcroForm is present
  7969. this.acroForm = this.catalog.catDict.get('AcroForm');
  7970. if (this.acroForm) {
  7971. this.xfa = this.acroForm.get('XFA');
  7972. var fields = this.acroForm.get('Fields');
  7973. if ((!fields || !isArray(fields) || fields.length === 0) &&
  7974. !this.xfa) {
  7975. // no fields and no XFA -- not a form (?)
  7976. this.acroForm = null;
  7977. }
  7978. }
  7979. } catch (ex) {
  7980. info('Something wrong with AcroForm entry');
  7981. this.acroForm = null;
  7982. }
  7983. },
  7984. get linearization() {
  7985. var linearization = null;
  7986. if (this.stream.length) {
  7987. try {
  7988. linearization = Linearization.create(this.stream);
  7989. } catch (err) {
  7990. if (err instanceof MissingDataException) {
  7991. throw err;
  7992. }
  7993. info(err);
  7994. }
  7995. }
  7996. // shadow the prototype getter with a data property
  7997. return shadow(this, 'linearization', linearization);
  7998. },
  7999. get startXRef() {
  8000. var stream = this.stream;
  8001. var startXRef = 0;
  8002. var linearization = this.linearization;
  8003. if (linearization) {
  8004. // Find end of first obj.
  8005. stream.reset();
  8006. if (find(stream, 'endobj', 1024)) {
  8007. startXRef = stream.pos + 6;
  8008. }
  8009. } else {
  8010. // Find startxref by jumping backward from the end of the file.
  8011. var step = 1024;
  8012. var found = false, pos = stream.end;
  8013. while (!found && pos > 0) {
  8014. pos -= step - 'startxref'.length;
  8015. if (pos < 0) {
  8016. pos = 0;
  8017. }
  8018. stream.pos = pos;
  8019. found = find(stream, 'startxref', step, true);
  8020. }
  8021. if (found) {
  8022. stream.skip(9);
  8023. var ch;
  8024. do {
  8025. ch = stream.getByte();
  8026. } while (Lexer.isSpace(ch));
  8027. var str = '';
  8028. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8029. str += String.fromCharCode(ch);
  8030. ch = stream.getByte();
  8031. }
  8032. startXRef = parseInt(str, 10);
  8033. if (isNaN(startXRef)) {
  8034. startXRef = 0;
  8035. }
  8036. }
  8037. }
  8038. // shadow the prototype getter with a data property
  8039. return shadow(this, 'startXRef', startXRef);
  8040. },
  8041. get mainXRefEntriesOffset() {
  8042. var mainXRefEntriesOffset = 0;
  8043. var linearization = this.linearization;
  8044. if (linearization) {
  8045. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8046. }
  8047. // shadow the prototype getter with a data property
  8048. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8049. },
  8050. // Find the header, remove leading garbage and setup the stream
  8051. // starting from the header.
  8052. checkHeader: function PDFDocument_checkHeader() {
  8053. var stream = this.stream;
  8054. stream.reset();
  8055. if (find(stream, '%PDF-', 1024)) {
  8056. // Found the header, trim off any garbage before it.
  8057. stream.moveStart();
  8058. // Reading file format version
  8059. var MAX_VERSION_LENGTH = 12;
  8060. var version = '', ch;
  8061. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8062. if (version.length >= MAX_VERSION_LENGTH) {
  8063. break;
  8064. }
  8065. version += String.fromCharCode(ch);
  8066. }
  8067. // removing "%PDF-"-prefix
  8068. this.pdfFormatVersion = version.substring(5);
  8069. return;
  8070. }
  8071. // May not be a PDF file, continue anyway.
  8072. },
  8073. parseStartXRef: function PDFDocument_parseStartXRef() {
  8074. var startXRef = this.startXRef;
  8075. this.xref.setStartXRef(startXRef);
  8076. },
  8077. setup: function PDFDocument_setup(recoveryMode) {
  8078. this.xref.parse(recoveryMode);
  8079. this.catalog = new Catalog(this.pdfManager, this.xref);
  8080. },
  8081. get numPages() {
  8082. var linearization = this.linearization;
  8083. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8084. // shadow the prototype getter
  8085. return shadow(this, 'numPages', num);
  8086. },
  8087. get documentInfo() {
  8088. var docInfo = {
  8089. PDFFormatVersion: this.pdfFormatVersion,
  8090. IsAcroFormPresent: !!this.acroForm,
  8091. IsXFAPresent: !!this.xfa
  8092. };
  8093. var infoDict;
  8094. try {
  8095. infoDict = this.xref.trailer.get('Info');
  8096. } catch (err) {
  8097. info('The document information dictionary is invalid.');
  8098. }
  8099. if (infoDict) {
  8100. var validEntries = DocumentInfoValidators.entries;
  8101. // Only fill the document info with valid entries from the spec.
  8102. for (var key in validEntries) {
  8103. if (infoDict.has(key)) {
  8104. var value = infoDict.get(key);
  8105. // Make sure the value conforms to the spec.
  8106. if (validEntries[key](value)) {
  8107. docInfo[key] = (typeof value !== 'string' ?
  8108. value : stringToPDFString(value));
  8109. } else {
  8110. info('Bad value in document info for "' + key + '"');
  8111. }
  8112. }
  8113. }
  8114. }
  8115. return shadow(this, 'documentInfo', docInfo);
  8116. },
  8117. get fingerprint() {
  8118. var xref = this.xref, hash, fileID = '';
  8119. if (xref.trailer.has('ID')) {
  8120. hash = stringToBytes(xref.trailer.get('ID')[0]);
  8121. } else {
  8122. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  8123. }
  8124. for (var i = 0, n = hash.length; i < n; i++) {
  8125. fileID += hash[i].toString(16);
  8126. }
  8127. return shadow(this, 'fingerprint', fileID);
  8128. },
  8129. getPage: function PDFDocument_getPage(pageIndex) {
  8130. return this.catalog.getPage(pageIndex);
  8131. },
  8132. cleanup: function PDFDocument_cleanup() {
  8133. return this.catalog.cleanup();
  8134. }
  8135. };
  8136. return PDFDocument;
  8137. })();
  8138. var Name = (function NameClosure() {
  8139. function Name(name) {
  8140. this.name = name;
  8141. }
  8142. Name.prototype = {};
  8143. var nameCache = {};
  8144. Name.get = function Name_get(name) {
  8145. var nameValue = nameCache[name];
  8146. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8147. };
  8148. return Name;
  8149. })();
  8150. var Cmd = (function CmdClosure() {
  8151. function Cmd(cmd) {
  8152. this.cmd = cmd;
  8153. }
  8154. Cmd.prototype = {};
  8155. var cmdCache = {};
  8156. Cmd.get = function Cmd_get(cmd) {
  8157. var cmdValue = cmdCache[cmd];
  8158. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8159. };
  8160. return Cmd;
  8161. })();
  8162. var Dict = (function DictClosure() {
  8163. var nonSerializable = function nonSerializableClosure() {
  8164. return nonSerializable; // creating closure on some variable
  8165. };
  8166. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8167. 'Background': true,
  8168. 'ExtGState': true,
  8169. 'Halftone': true,
  8170. 'Layout': true,
  8171. 'Mask': true,
  8172. 'Pagination': true,
  8173. 'Printing': true
  8174. };
  8175. function isRecursionAllowedFor(dict) {
  8176. if (!isName(dict.Type)) {
  8177. return true;
  8178. }
  8179. var dictType = dict.Type.name;
  8180. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8181. }
  8182. // xref is optional
  8183. function Dict(xref) {
  8184. // Map should only be used internally, use functions below to access.
  8185. this.map = Object.create(null);
  8186. this.xref = xref;
  8187. this.objId = null;
  8188. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8189. }
  8190. Dict.prototype = {
  8191. assignXref: function Dict_assignXref(newXref) {
  8192. this.xref = newXref;
  8193. },
  8194. // automatically dereferences Ref objects
  8195. get: function Dict_get(key1, key2, key3) {
  8196. var value;
  8197. var xref = this.xref;
  8198. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8199. typeof key2 === 'undefined') {
  8200. return xref ? xref.fetchIfRef(value) : value;
  8201. }
  8202. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8203. typeof key3 === 'undefined') {
  8204. return xref ? xref.fetchIfRef(value) : value;
  8205. }
  8206. value = this.map[key3] || null;
  8207. return xref ? xref.fetchIfRef(value) : value;
  8208. },
  8209. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8210. getAsync: function Dict_getAsync(key1, key2, key3) {
  8211. var value;
  8212. var xref = this.xref;
  8213. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8214. typeof key2 === 'undefined') {
  8215. if (xref) {
  8216. return xref.fetchIfRefAsync(value);
  8217. }
  8218. return Promise.resolve(value);
  8219. }
  8220. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8221. typeof key3 === 'undefined') {
  8222. if (xref) {
  8223. return xref.fetchIfRefAsync(value);
  8224. }
  8225. return Promise.resolve(value);
  8226. }
  8227. value = this.map[key3] || null;
  8228. if (xref) {
  8229. return xref.fetchIfRefAsync(value);
  8230. }
  8231. return Promise.resolve(value);
  8232. },
  8233. // no dereferencing
  8234. getRaw: function Dict_getRaw(key) {
  8235. return this.map[key];
  8236. },
  8237. // creates new map and dereferences all Refs
  8238. getAll: function Dict_getAll() {
  8239. var all = Object.create(null);
  8240. var queue = null;
  8241. var key, obj;
  8242. for (key in this.map) {
  8243. obj = this.get(key);
  8244. if (obj instanceof Dict) {
  8245. if (isRecursionAllowedFor(obj)) {
  8246. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8247. } else {
  8248. all[key] = this.getRaw(key);
  8249. }
  8250. } else {
  8251. all[key] = obj;
  8252. }
  8253. }
  8254. if (!queue) {
  8255. return all;
  8256. }
  8257. // trying to take cyclic references into the account
  8258. var processed = Object.create(null);
  8259. while (queue.length > 0) {
  8260. var item = queue.shift();
  8261. var itemObj = item.obj;
  8262. var objId = itemObj.objId;
  8263. if (objId && objId in processed) {
  8264. item.target[item.key] = processed[objId];
  8265. continue;
  8266. }
  8267. var dereferenced = Object.create(null);
  8268. for (key in itemObj.map) {
  8269. obj = itemObj.get(key);
  8270. if (obj instanceof Dict) {
  8271. if (isRecursionAllowedFor(obj)) {
  8272. queue.push({target: dereferenced, key: key, obj: obj});
  8273. } else {
  8274. dereferenced[key] = itemObj.getRaw(key);
  8275. }
  8276. } else {
  8277. dereferenced[key] = obj;
  8278. }
  8279. }
  8280. if (objId) {
  8281. processed[objId] = dereferenced;
  8282. }
  8283. item.target[item.key] = dereferenced;
  8284. }
  8285. return all;
  8286. },
  8287. set: function Dict_set(key, value) {
  8288. this.map[key] = value;
  8289. },
  8290. has: function Dict_has(key) {
  8291. return key in this.map;
  8292. },
  8293. forEach: function Dict_forEach(callback) {
  8294. for (var key in this.map) {
  8295. callback(key, this.get(key));
  8296. }
  8297. }
  8298. };
  8299. Dict.empty = new Dict(null);
  8300. return Dict;
  8301. })();
  8302. var Ref = (function RefClosure() {
  8303. function Ref(num, gen) {
  8304. this.num = num;
  8305. this.gen = gen;
  8306. }
  8307. Ref.prototype = {
  8308. toString: function Ref_toString() {
  8309. // This function is hot, so we make the string as compact as possible.
  8310. // |this.gen| is almost always zero, so we treat that case specially.
  8311. var str = this.num + 'R';
  8312. if (this.gen !== 0) {
  8313. str += this.gen;
  8314. }
  8315. return str;
  8316. }
  8317. };
  8318. return Ref;
  8319. })();
  8320. // The reference is identified by number and generation.
  8321. // This structure stores only one instance of the reference.
  8322. var RefSet = (function RefSetClosure() {
  8323. function RefSet() {
  8324. this.dict = {};
  8325. }
  8326. RefSet.prototype = {
  8327. has: function RefSet_has(ref) {
  8328. return ref.toString() in this.dict;
  8329. },
  8330. put: function RefSet_put(ref) {
  8331. this.dict[ref.toString()] = true;
  8332. },
  8333. remove: function RefSet_remove(ref) {
  8334. delete this.dict[ref.toString()];
  8335. }
  8336. };
  8337. return RefSet;
  8338. })();
  8339. var RefSetCache = (function RefSetCacheClosure() {
  8340. function RefSetCache() {
  8341. this.dict = Object.create(null);
  8342. }
  8343. RefSetCache.prototype = {
  8344. get: function RefSetCache_get(ref) {
  8345. return this.dict[ref.toString()];
  8346. },
  8347. has: function RefSetCache_has(ref) {
  8348. return ref.toString() in this.dict;
  8349. },
  8350. put: function RefSetCache_put(ref, obj) {
  8351. this.dict[ref.toString()] = obj;
  8352. },
  8353. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8354. this.dict[ref.toString()] = this.get(aliasRef);
  8355. },
  8356. forEach: function RefSetCache_forEach(fn, thisArg) {
  8357. for (var i in this.dict) {
  8358. fn.call(thisArg, this.dict[i]);
  8359. }
  8360. },
  8361. clear: function RefSetCache_clear() {
  8362. this.dict = Object.create(null);
  8363. }
  8364. };
  8365. return RefSetCache;
  8366. })();
  8367. var Catalog = (function CatalogClosure() {
  8368. function Catalog(pdfManager, xref) {
  8369. this.pdfManager = pdfManager;
  8370. this.xref = xref;
  8371. this.catDict = xref.getCatalogObj();
  8372. this.fontCache = new RefSetCache();
  8373. assert(isDict(this.catDict),
  8374. 'catalog object is not a dictionary');
  8375. this.pagePromises = [];
  8376. }
  8377. Catalog.prototype = {
  8378. get metadata() {
  8379. var streamRef = this.catDict.getRaw('Metadata');
  8380. if (!isRef(streamRef)) {
  8381. return shadow(this, 'metadata', null);
  8382. }
  8383. var encryptMetadata = (!this.xref.encrypt ? false :
  8384. this.xref.encrypt.encryptMetadata);
  8385. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8386. var metadata;
  8387. if (stream && isDict(stream.dict)) {
  8388. var type = stream.dict.get('Type');
  8389. var subtype = stream.dict.get('Subtype');
  8390. if (isName(type) && isName(subtype) &&
  8391. type.name === 'Metadata' && subtype.name === 'XML') {
  8392. // XXX: This should examine the charset the XML document defines,
  8393. // however since there are currently no real means to decode
  8394. // arbitrary charsets, let's just hope that the author of the PDF
  8395. // was reasonable enough to stick with the XML default charset,
  8396. // which is UTF-8.
  8397. try {
  8398. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8399. } catch (e) {
  8400. info('Skipping invalid metadata.');
  8401. }
  8402. }
  8403. }
  8404. return shadow(this, 'metadata', metadata);
  8405. },
  8406. get toplevelPagesDict() {
  8407. var pagesObj = this.catDict.get('Pages');
  8408. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8409. // shadow the prototype getter
  8410. return shadow(this, 'toplevelPagesDict', pagesObj);
  8411. },
  8412. get documentOutline() {
  8413. var obj = null;
  8414. try {
  8415. obj = this.readDocumentOutline();
  8416. } catch (ex) {
  8417. if (ex instanceof MissingDataException) {
  8418. throw ex;
  8419. }
  8420. warn('Unable to read document outline');
  8421. }
  8422. return shadow(this, 'documentOutline', obj);
  8423. },
  8424. readDocumentOutline: function Catalog_readDocumentOutline() {
  8425. var xref = this.xref;
  8426. var obj = this.catDict.get('Outlines');
  8427. var root = { items: [] };
  8428. if (isDict(obj)) {
  8429. obj = obj.getRaw('First');
  8430. var processed = new RefSet();
  8431. if (isRef(obj)) {
  8432. var queue = [{obj: obj, parent: root}];
  8433. // to avoid recursion keeping track of the items
  8434. // in the processed dictionary
  8435. processed.put(obj);
  8436. while (queue.length > 0) {
  8437. var i = queue.shift();
  8438. var outlineDict = xref.fetchIfRef(i.obj);
  8439. if (outlineDict === null) {
  8440. continue;
  8441. }
  8442. if (!outlineDict.has('Title')) {
  8443. error('Invalid outline item');
  8444. }
  8445. var dest = outlineDict.get('A');
  8446. if (dest) {
  8447. dest = dest.get('D');
  8448. } else if (outlineDict.has('Dest')) {
  8449. dest = outlineDict.getRaw('Dest');
  8450. if (isName(dest)) {
  8451. dest = dest.name;
  8452. }
  8453. }
  8454. var title = outlineDict.get('Title');
  8455. var outlineItem = {
  8456. dest: dest,
  8457. title: stringToPDFString(title),
  8458. color: outlineDict.get('C') || [0, 0, 0],
  8459. count: outlineDict.get('Count'),
  8460. bold: !!(outlineDict.get('F') & 2),
  8461. italic: !!(outlineDict.get('F') & 1),
  8462. items: []
  8463. };
  8464. i.parent.items.push(outlineItem);
  8465. obj = outlineDict.getRaw('First');
  8466. if (isRef(obj) && !processed.has(obj)) {
  8467. queue.push({obj: obj, parent: outlineItem});
  8468. processed.put(obj);
  8469. }
  8470. obj = outlineDict.getRaw('Next');
  8471. if (isRef(obj) && !processed.has(obj)) {
  8472. queue.push({obj: obj, parent: i.parent});
  8473. processed.put(obj);
  8474. }
  8475. }
  8476. }
  8477. }
  8478. return (root.items.length > 0 ? root.items : null);
  8479. },
  8480. get numPages() {
  8481. var obj = this.toplevelPagesDict.get('Count');
  8482. assert(
  8483. isInt(obj),
  8484. 'page count in top level pages object is not an integer'
  8485. );
  8486. // shadow the prototype getter
  8487. return shadow(this, 'num', obj);
  8488. },
  8489. get destinations() {
  8490. function fetchDestination(dest) {
  8491. return isDict(dest) ? dest.get('D') : dest;
  8492. }
  8493. var xref = this.xref;
  8494. var dests = {}, nameTreeRef, nameDictionaryRef;
  8495. var obj = this.catDict.get('Names');
  8496. if (obj && obj.has('Dests')) {
  8497. nameTreeRef = obj.getRaw('Dests');
  8498. } else if (this.catDict.has('Dests')) {
  8499. nameDictionaryRef = this.catDict.get('Dests');
  8500. }
  8501. if (nameDictionaryRef) {
  8502. // reading simple destination dictionary
  8503. obj = nameDictionaryRef;
  8504. obj.forEach(function catalogForEach(key, value) {
  8505. if (!value) {
  8506. return;
  8507. }
  8508. dests[key] = fetchDestination(value);
  8509. });
  8510. }
  8511. if (nameTreeRef) {
  8512. var nameTree = new NameTree(nameTreeRef, xref);
  8513. var names = nameTree.getAll();
  8514. for (var name in names) {
  8515. if (!names.hasOwnProperty(name)) {
  8516. continue;
  8517. }
  8518. dests[name] = fetchDestination(names[name]);
  8519. }
  8520. }
  8521. return shadow(this, 'destinations', dests);
  8522. },
  8523. getDestination: function Catalog_getDestination(destinationId) {
  8524. function fetchDestination(dest) {
  8525. return isDict(dest) ? dest.get('D') : dest;
  8526. }
  8527. var xref = this.xref;
  8528. var dest, nameTreeRef, nameDictionaryRef;
  8529. var obj = this.catDict.get('Names');
  8530. if (obj && obj.has('Dests')) {
  8531. nameTreeRef = obj.getRaw('Dests');
  8532. } else if (this.catDict.has('Dests')) {
  8533. nameDictionaryRef = this.catDict.get('Dests');
  8534. }
  8535. if (nameDictionaryRef) {
  8536. // reading simple destination dictionary
  8537. obj = nameDictionaryRef;
  8538. obj.forEach(function catalogForEach(key, value) {
  8539. if (!value) {
  8540. return;
  8541. }
  8542. if (key === destinationId) {
  8543. dest = fetchDestination(value);
  8544. }
  8545. });
  8546. }
  8547. if (nameTreeRef) {
  8548. var nameTree = new NameTree(nameTreeRef, xref);
  8549. dest = fetchDestination(nameTree.get(destinationId));
  8550. }
  8551. return dest;
  8552. },
  8553. get attachments() {
  8554. var xref = this.xref;
  8555. var attachments = null, nameTreeRef;
  8556. var obj = this.catDict.get('Names');
  8557. if (obj) {
  8558. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8559. }
  8560. if (nameTreeRef) {
  8561. var nameTree = new NameTree(nameTreeRef, xref);
  8562. var names = nameTree.getAll();
  8563. for (var name in names) {
  8564. if (!names.hasOwnProperty(name)) {
  8565. continue;
  8566. }
  8567. var fs = new FileSpec(names[name], xref);
  8568. if (!attachments) {
  8569. attachments = {};
  8570. }
  8571. attachments[stringToPDFString(name)] = fs.serializable;
  8572. }
  8573. }
  8574. return shadow(this, 'attachments', attachments);
  8575. },
  8576. get javaScript() {
  8577. var xref = this.xref;
  8578. var obj = this.catDict.get('Names');
  8579. var javaScript = [];
  8580. if (obj && obj.has('JavaScript')) {
  8581. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8582. var names = nameTree.getAll();
  8583. for (var name in names) {
  8584. if (!names.hasOwnProperty(name)) {
  8585. continue;
  8586. }
  8587. // We don't really use the JavaScript right now. This code is
  8588. // defensive so we don't cause errors on document load.
  8589. var jsDict = names[name];
  8590. if (!isDict(jsDict)) {
  8591. continue;
  8592. }
  8593. var type = jsDict.get('S');
  8594. if (!isName(type) || type.name !== 'JavaScript') {
  8595. continue;
  8596. }
  8597. var js = jsDict.get('JS');
  8598. if (!isString(js) && !isStream(js)) {
  8599. continue;
  8600. }
  8601. if (isStream(js)) {
  8602. js = bytesToString(js.getBytes());
  8603. }
  8604. javaScript.push(stringToPDFString(js));
  8605. }
  8606. }
  8607. // Append OpenAction actions to javaScript array
  8608. var openactionDict = this.catDict.get('OpenAction');
  8609. if (isDict(openactionDict)) {
  8610. var objType = openactionDict.get('Type');
  8611. var actionType = openactionDict.get('S');
  8612. var action = openactionDict.get('N');
  8613. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8614. isName(actionType) && actionType.name === 'Named' &&
  8615. isName(action) && action.name === 'Print');
  8616. if (isPrintAction) {
  8617. javaScript.push('print(true);');
  8618. }
  8619. }
  8620. return shadow(this, 'javaScript', javaScript);
  8621. },
  8622. cleanup: function Catalog_cleanup() {
  8623. var promises = [];
  8624. this.fontCache.forEach(function (promise) {
  8625. promises.push(promise);
  8626. });
  8627. return Promise.all(promises).then(function (translatedFonts) {
  8628. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8629. var font = translatedFonts[i].dict;
  8630. delete font.translated;
  8631. }
  8632. this.fontCache.clear();
  8633. }.bind(this));
  8634. },
  8635. getPage: function Catalog_getPage(pageIndex) {
  8636. if (!(pageIndex in this.pagePromises)) {
  8637. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8638. function (a) {
  8639. var dict = a[0];
  8640. var ref = a[1];
  8641. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8642. this.fontCache);
  8643. }.bind(this)
  8644. );
  8645. }
  8646. return this.pagePromises[pageIndex];
  8647. },
  8648. getPageDict: function Catalog_getPageDict(pageIndex) {
  8649. var capability = createPromiseCapability();
  8650. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8651. var currentPageIndex = 0;
  8652. var xref = this.xref;
  8653. function next() {
  8654. while (nodesToVisit.length) {
  8655. var currentNode = nodesToVisit.pop();
  8656. if (isRef(currentNode)) {
  8657. xref.fetchAsync(currentNode).then(function (obj) {
  8658. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8659. if (pageIndex === currentPageIndex) {
  8660. capability.resolve([obj, currentNode]);
  8661. } else {
  8662. currentPageIndex++;
  8663. next();
  8664. }
  8665. return;
  8666. }
  8667. nodesToVisit.push(obj);
  8668. next();
  8669. }, capability.reject);
  8670. return;
  8671. }
  8672. // must be a child page dictionary
  8673. assert(
  8674. isDict(currentNode),
  8675. 'page dictionary kid reference points to wrong type of object'
  8676. );
  8677. var count = currentNode.get('Count');
  8678. // Skip nodes where the page can't be.
  8679. if (currentPageIndex + count <= pageIndex) {
  8680. currentPageIndex += count;
  8681. continue;
  8682. }
  8683. var kids = currentNode.get('Kids');
  8684. assert(isArray(kids), 'page dictionary kids object is not an array');
  8685. if (count === kids.length) {
  8686. // Nodes that don't have the page have been skipped and this is the
  8687. // bottom of the tree which means the page requested must be a
  8688. // descendant of this pages node. Ideally we would just resolve the
  8689. // promise with the page ref here, but there is the case where more
  8690. // pages nodes could link to single a page (see issue 3666 pdf). To
  8691. // handle this push it back on the queue so if it is a pages node it
  8692. // will be descended into.
  8693. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8694. currentPageIndex = pageIndex;
  8695. continue;
  8696. } else {
  8697. for (var last = kids.length - 1; last >= 0; last--) {
  8698. nodesToVisit.push(kids[last]);
  8699. }
  8700. }
  8701. }
  8702. capability.reject('Page index ' + pageIndex + ' not found.');
  8703. }
  8704. next();
  8705. return capability.promise;
  8706. },
  8707. getPageIndex: function Catalog_getPageIndex(ref) {
  8708. // The page tree nodes have the count of all the leaves below them. To get
  8709. // how many pages are before we just have to walk up the tree and keep
  8710. // adding the count of siblings to the left of the node.
  8711. var xref = this.xref;
  8712. function pagesBeforeRef(kidRef) {
  8713. var total = 0;
  8714. var parentRef;
  8715. return xref.fetchAsync(kidRef).then(function (node) {
  8716. if (!node) {
  8717. return null;
  8718. }
  8719. parentRef = node.getRaw('Parent');
  8720. return node.getAsync('Parent');
  8721. }).then(function (parent) {
  8722. if (!parent) {
  8723. return null;
  8724. }
  8725. return parent.getAsync('Kids');
  8726. }).then(function (kids) {
  8727. if (!kids) {
  8728. return null;
  8729. }
  8730. var kidPromises = [];
  8731. var found = false;
  8732. for (var i = 0; i < kids.length; i++) {
  8733. var kid = kids[i];
  8734. assert(isRef(kid), 'kids must be a ref');
  8735. if (kid.num === kidRef.num) {
  8736. found = true;
  8737. break;
  8738. }
  8739. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8740. if (kid.has('Count')) {
  8741. var count = kid.get('Count');
  8742. total += count;
  8743. } else { // page leaf node
  8744. total++;
  8745. }
  8746. }));
  8747. }
  8748. if (!found) {
  8749. error('kid ref not found in parents kids');
  8750. }
  8751. return Promise.all(kidPromises).then(function () {
  8752. return [total, parentRef];
  8753. });
  8754. });
  8755. }
  8756. var total = 0;
  8757. function next(ref) {
  8758. return pagesBeforeRef(ref).then(function (args) {
  8759. if (!args) {
  8760. return total;
  8761. }
  8762. var count = args[0];
  8763. var parentRef = args[1];
  8764. total += count;
  8765. return next(parentRef);
  8766. });
  8767. }
  8768. return next(ref);
  8769. }
  8770. };
  8771. return Catalog;
  8772. })();
  8773. var XRef = (function XRefClosure() {
  8774. function XRef(stream, password) {
  8775. this.stream = stream;
  8776. this.entries = [];
  8777. this.xrefstms = {};
  8778. // prepare the XRef cache
  8779. this.cache = [];
  8780. this.password = password;
  8781. this.stats = {
  8782. streamTypes: [],
  8783. fontTypes: []
  8784. };
  8785. }
  8786. XRef.prototype = {
  8787. setStartXRef: function XRef_setStartXRef(startXRef) {
  8788. // Store the starting positions of xref tables as we process them
  8789. // so we can recover from missing data errors
  8790. this.startXRefQueue = [startXRef];
  8791. },
  8792. parse: function XRef_parse(recoveryMode) {
  8793. var trailerDict;
  8794. if (!recoveryMode) {
  8795. trailerDict = this.readXRef();
  8796. } else {
  8797. warn('Indexing all PDF objects');
  8798. trailerDict = this.indexObjects();
  8799. }
  8800. trailerDict.assignXref(this);
  8801. this.trailer = trailerDict;
  8802. var encrypt = trailerDict.get('Encrypt');
  8803. if (encrypt) {
  8804. var ids = trailerDict.get('ID');
  8805. var fileId = (ids && ids.length) ? ids[0] : '';
  8806. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  8807. this.password);
  8808. }
  8809. // get the root dictionary (catalog) object
  8810. if (!(this.root = trailerDict.get('Root'))) {
  8811. error('Invalid root reference');
  8812. }
  8813. },
  8814. processXRefTable: function XRef_processXRefTable(parser) {
  8815. if (!('tableState' in this)) {
  8816. // Stores state of the table as we process it so we can resume
  8817. // from middle of table in case of missing data error
  8818. this.tableState = {
  8819. entryNum: 0,
  8820. streamPos: parser.lexer.stream.pos,
  8821. parserBuf1: parser.buf1,
  8822. parserBuf2: parser.buf2
  8823. };
  8824. }
  8825. var obj = this.readXRefTable(parser);
  8826. // Sanity check
  8827. if (!isCmd(obj, 'trailer')) {
  8828. error('Invalid XRef table: could not find trailer dictionary');
  8829. }
  8830. // Read trailer dictionary, e.g.
  8831. // trailer
  8832. // << /Size 22
  8833. // /Root 20R
  8834. // /Info 10R
  8835. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  8836. // >>
  8837. // The parser goes through the entire stream << ... >> and provides
  8838. // a getter interface for the key-value table
  8839. var dict = parser.getObj();
  8840. // The pdflib PDF generator can generate a nested trailer dictionary
  8841. if (!isDict(dict) && dict.dict) {
  8842. dict = dict.dict;
  8843. }
  8844. if (!isDict(dict)) {
  8845. error('Invalid XRef table: could not parse trailer dictionary');
  8846. }
  8847. delete this.tableState;
  8848. return dict;
  8849. },
  8850. readXRefTable: function XRef_readXRefTable(parser) {
  8851. // Example of cross-reference table:
  8852. // xref
  8853. // 0 1 <-- subsection header (first obj #, obj count)
  8854. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  8855. // 23 2 <-- subsection header ... and so on ...
  8856. // 0000025518 00002 n
  8857. // 0000025635 00000 n
  8858. // trailer
  8859. // ...
  8860. var stream = parser.lexer.stream;
  8861. var tableState = this.tableState;
  8862. stream.pos = tableState.streamPos;
  8863. parser.buf1 = tableState.parserBuf1;
  8864. parser.buf2 = tableState.parserBuf2;
  8865. // Outer loop is over subsection headers
  8866. var obj;
  8867. while (true) {
  8868. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  8869. if (isCmd(obj = parser.getObj(), 'trailer')) {
  8870. break;
  8871. }
  8872. tableState.firstEntryNum = obj;
  8873. tableState.entryCount = parser.getObj();
  8874. }
  8875. var first = tableState.firstEntryNum;
  8876. var count = tableState.entryCount;
  8877. if (!isInt(first) || !isInt(count)) {
  8878. error('Invalid XRef table: wrong types in subsection header');
  8879. }
  8880. // Inner loop is over objects themselves
  8881. for (var i = tableState.entryNum; i < count; i++) {
  8882. tableState.streamPos = stream.pos;
  8883. tableState.entryNum = i;
  8884. tableState.parserBuf1 = parser.buf1;
  8885. tableState.parserBuf2 = parser.buf2;
  8886. var entry = {};
  8887. entry.offset = parser.getObj();
  8888. entry.gen = parser.getObj();
  8889. var type = parser.getObj();
  8890. if (isCmd(type, 'f')) {
  8891. entry.free = true;
  8892. } else if (isCmd(type, 'n')) {
  8893. entry.uncompressed = true;
  8894. }
  8895. // Validate entry obj
  8896. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  8897. !(entry.free || entry.uncompressed)) {
  8898. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  8899. }
  8900. if (!this.entries[i + first]) {
  8901. this.entries[i + first] = entry;
  8902. }
  8903. }
  8904. tableState.entryNum = 0;
  8905. tableState.streamPos = stream.pos;
  8906. tableState.parserBuf1 = parser.buf1;
  8907. tableState.parserBuf2 = parser.buf2;
  8908. delete tableState.firstEntryNum;
  8909. delete tableState.entryCount;
  8910. }
  8911. // Per issue 3248: hp scanners generate bad XRef
  8912. if (first === 1 && this.entries[1] && this.entries[1].free) {
  8913. // shifting the entries
  8914. this.entries.shift();
  8915. }
  8916. // Sanity check: as per spec, first object must be free
  8917. if (this.entries[0] && !this.entries[0].free) {
  8918. error('Invalid XRef table: unexpected first object');
  8919. }
  8920. return obj;
  8921. },
  8922. processXRefStream: function XRef_processXRefStream(stream) {
  8923. if (!('streamState' in this)) {
  8924. // Stores state of the stream as we process it so we can resume
  8925. // from middle of stream in case of missing data error
  8926. var streamParameters = stream.dict;
  8927. var byteWidths = streamParameters.get('W');
  8928. var range = streamParameters.get('Index');
  8929. if (!range) {
  8930. range = [0, streamParameters.get('Size')];
  8931. }
  8932. this.streamState = {
  8933. entryRanges: range,
  8934. byteWidths: byteWidths,
  8935. entryNum: 0,
  8936. streamPos: stream.pos
  8937. };
  8938. }
  8939. this.readXRefStream(stream);
  8940. delete this.streamState;
  8941. return stream.dict;
  8942. },
  8943. readXRefStream: function XRef_readXRefStream(stream) {
  8944. var i, j;
  8945. var streamState = this.streamState;
  8946. stream.pos = streamState.streamPos;
  8947. var byteWidths = streamState.byteWidths;
  8948. var typeFieldWidth = byteWidths[0];
  8949. var offsetFieldWidth = byteWidths[1];
  8950. var generationFieldWidth = byteWidths[2];
  8951. var entryRanges = streamState.entryRanges;
  8952. while (entryRanges.length > 0) {
  8953. var first = entryRanges[0];
  8954. var n = entryRanges[1];
  8955. if (!isInt(first) || !isInt(n)) {
  8956. error('Invalid XRef range fields: ' + first + ', ' + n);
  8957. }
  8958. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  8959. !isInt(generationFieldWidth)) {
  8960. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  8961. }
  8962. for (i = streamState.entryNum; i < n; ++i) {
  8963. streamState.entryNum = i;
  8964. streamState.streamPos = stream.pos;
  8965. var type = 0, offset = 0, generation = 0;
  8966. for (j = 0; j < typeFieldWidth; ++j) {
  8967. type = (type << 8) | stream.getByte();
  8968. }
  8969. // if type field is absent, its default value is 1
  8970. if (typeFieldWidth === 0) {
  8971. type = 1;
  8972. }
  8973. for (j = 0; j < offsetFieldWidth; ++j) {
  8974. offset = (offset << 8) | stream.getByte();
  8975. }
  8976. for (j = 0; j < generationFieldWidth; ++j) {
  8977. generation = (generation << 8) | stream.getByte();
  8978. }
  8979. var entry = {};
  8980. entry.offset = offset;
  8981. entry.gen = generation;
  8982. switch (type) {
  8983. case 0:
  8984. entry.free = true;
  8985. break;
  8986. case 1:
  8987. entry.uncompressed = true;
  8988. break;
  8989. case 2:
  8990. break;
  8991. default:
  8992. error('Invalid XRef entry type: ' + type);
  8993. }
  8994. if (!this.entries[first + i]) {
  8995. this.entries[first + i] = entry;
  8996. }
  8997. }
  8998. streamState.entryNum = 0;
  8999. streamState.streamPos = stream.pos;
  9000. entryRanges.splice(0, 2);
  9001. }
  9002. },
  9003. indexObjects: function XRef_indexObjects() {
  9004. // Simple scan through the PDF content to find objects,
  9005. // trailers and XRef streams.
  9006. function readToken(data, offset) {
  9007. var token = '', ch = data[offset];
  9008. while (ch !== 13 && ch !== 10) {
  9009. if (++offset >= data.length) {
  9010. break;
  9011. }
  9012. token += String.fromCharCode(ch);
  9013. ch = data[offset];
  9014. }
  9015. return token;
  9016. }
  9017. function skipUntil(data, offset, what) {
  9018. var length = what.length, dataLength = data.length;
  9019. var skipped = 0;
  9020. // finding byte sequence
  9021. while (offset < dataLength) {
  9022. var i = 0;
  9023. while (i < length && data[offset + i] === what[i]) {
  9024. ++i;
  9025. }
  9026. if (i >= length) {
  9027. break; // sequence found
  9028. }
  9029. offset++;
  9030. skipped++;
  9031. }
  9032. return skipped;
  9033. }
  9034. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9035. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9036. 101, 102]);
  9037. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9038. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9039. var stream = this.stream;
  9040. stream.pos = 0;
  9041. var buffer = stream.getBytes();
  9042. var position = stream.start, length = buffer.length;
  9043. var trailers = [], xrefStms = [];
  9044. while (position < length) {
  9045. var ch = buffer[position];
  9046. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9047. ++position;
  9048. continue;
  9049. }
  9050. if (ch === 37) { // %-comment
  9051. do {
  9052. ++position;
  9053. if (position >= length) {
  9054. break;
  9055. }
  9056. ch = buffer[position];
  9057. } while (ch !== 13 && ch !== 10);
  9058. continue;
  9059. }
  9060. var token = readToken(buffer, position);
  9061. var m;
  9062. if (token === 'xref') {
  9063. position += skipUntil(buffer, position, trailerBytes);
  9064. trailers.push(position);
  9065. position += skipUntil(buffer, position, startxrefBytes);
  9066. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9067. this.entries[m[1]] = {
  9068. offset: position,
  9069. gen: m[2] | 0,
  9070. uncompressed: true
  9071. };
  9072. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9073. var content = buffer.subarray(position, position + contentLength);
  9074. // checking XRef stream suspect
  9075. // (it shall have '/XRef' and next char is not a letter)
  9076. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9077. if (xrefTagOffset < contentLength &&
  9078. content[xrefTagOffset + 5] < 64) {
  9079. xrefStms.push(position);
  9080. this.xrefstms[position] = 1; // don't read it recursively
  9081. }
  9082. position += contentLength;
  9083. } else {
  9084. position += token.length + 1;
  9085. }
  9086. }
  9087. // reading XRef streams
  9088. var i, ii;
  9089. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9090. this.startXRefQueue.push(xrefStms[i]);
  9091. this.readXRef(/* recoveryMode */ true);
  9092. }
  9093. // finding main trailer
  9094. var dict;
  9095. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9096. stream.pos = trailers[i];
  9097. var parser = new Parser(new Lexer(stream), true, this);
  9098. var obj = parser.getObj();
  9099. if (!isCmd(obj, 'trailer')) {
  9100. continue;
  9101. }
  9102. // read the trailer dictionary
  9103. if (!isDict(dict = parser.getObj())) {
  9104. continue;
  9105. }
  9106. // taking the first one with 'ID'
  9107. if (dict.has('ID')) {
  9108. return dict;
  9109. }
  9110. }
  9111. // no tailer with 'ID', taking last one (if exists)
  9112. if (dict) {
  9113. return dict;
  9114. }
  9115. // nothing helps
  9116. // calling error() would reject worker with an UnknownErrorException.
  9117. throw new InvalidPDFException('Invalid PDF structure');
  9118. },
  9119. readXRef: function XRef_readXRef(recoveryMode) {
  9120. var stream = this.stream;
  9121. try {
  9122. while (this.startXRefQueue.length) {
  9123. var startXRef = this.startXRefQueue[0];
  9124. stream.pos = startXRef + stream.start;
  9125. var parser = new Parser(new Lexer(stream), true, this);
  9126. var obj = parser.getObj();
  9127. var dict;
  9128. // Get dictionary
  9129. if (isCmd(obj, 'xref')) {
  9130. // Parse end-of-file XRef
  9131. dict = this.processXRefTable(parser);
  9132. if (!this.topDict) {
  9133. this.topDict = dict;
  9134. }
  9135. // Recursively get other XRefs 'XRefStm', if any
  9136. obj = dict.get('XRefStm');
  9137. if (isInt(obj)) {
  9138. var pos = obj;
  9139. // ignore previously loaded xref streams
  9140. // (possible infinite recursion)
  9141. if (!(pos in this.xrefstms)) {
  9142. this.xrefstms[pos] = 1;
  9143. this.startXRefQueue.push(pos);
  9144. }
  9145. }
  9146. } else if (isInt(obj)) {
  9147. // Parse in-stream XRef
  9148. if (!isInt(parser.getObj()) ||
  9149. !isCmd(parser.getObj(), 'obj') ||
  9150. !isStream(obj = parser.getObj())) {
  9151. error('Invalid XRef stream');
  9152. }
  9153. dict = this.processXRefStream(obj);
  9154. if (!this.topDict) {
  9155. this.topDict = dict;
  9156. }
  9157. if (!dict) {
  9158. error('Failed to read XRef stream');
  9159. }
  9160. } else {
  9161. error('Invalid XRef stream header');
  9162. }
  9163. // Recursively get previous dictionary, if any
  9164. obj = dict.get('Prev');
  9165. if (isInt(obj)) {
  9166. this.startXRefQueue.push(obj);
  9167. } else if (isRef(obj)) {
  9168. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9169. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9170. this.startXRefQueue.push(obj.num);
  9171. }
  9172. this.startXRefQueue.shift();
  9173. }
  9174. return this.topDict;
  9175. } catch (e) {
  9176. if (e instanceof MissingDataException) {
  9177. throw e;
  9178. }
  9179. info('(while reading XRef): ' + e);
  9180. }
  9181. if (recoveryMode) {
  9182. return;
  9183. }
  9184. throw new XRefParseException();
  9185. },
  9186. getEntry: function XRef_getEntry(i) {
  9187. var xrefEntry = this.entries[i];
  9188. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9189. return xrefEntry;
  9190. }
  9191. return null;
  9192. },
  9193. fetchIfRef: function XRef_fetchIfRef(obj) {
  9194. if (!isRef(obj)) {
  9195. return obj;
  9196. }
  9197. return this.fetch(obj);
  9198. },
  9199. fetch: function XRef_fetch(ref, suppressEncryption) {
  9200. assert(isRef(ref), 'ref object is not a reference');
  9201. var num = ref.num;
  9202. if (num in this.cache) {
  9203. var cacheEntry = this.cache[num];
  9204. return cacheEntry;
  9205. }
  9206. var xrefEntry = this.getEntry(num);
  9207. // the referenced entry can be free
  9208. if (xrefEntry === null) {
  9209. return (this.cache[num] = null);
  9210. }
  9211. if (xrefEntry.uncompressed) {
  9212. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9213. } else {
  9214. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9215. }
  9216. if (isDict(xrefEntry)){
  9217. xrefEntry.objId = ref.toString();
  9218. } else if (isStream(xrefEntry)) {
  9219. xrefEntry.dict.objId = ref.toString();
  9220. }
  9221. return xrefEntry;
  9222. },
  9223. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9224. suppressEncryption) {
  9225. var gen = ref.gen;
  9226. var num = ref.num;
  9227. if (xrefEntry.gen !== gen) {
  9228. error('inconsistent generation in XRef');
  9229. }
  9230. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9231. this.stream.start);
  9232. var parser = new Parser(new Lexer(stream), true, this);
  9233. var obj1 = parser.getObj();
  9234. var obj2 = parser.getObj();
  9235. var obj3 = parser.getObj();
  9236. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9237. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9238. !isCmd(obj3)) {
  9239. error('bad XRef entry');
  9240. }
  9241. if (!isCmd(obj3, 'obj')) {
  9242. // some bad PDFs use "obj1234" and really mean 1234
  9243. if (obj3.cmd.indexOf('obj') === 0) {
  9244. num = parseInt(obj3.cmd.substring(3), 10);
  9245. if (!isNaN(num)) {
  9246. return num;
  9247. }
  9248. }
  9249. error('bad XRef entry');
  9250. }
  9251. if (this.encrypt && !suppressEncryption) {
  9252. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9253. } else {
  9254. xrefEntry = parser.getObj();
  9255. }
  9256. if (!isStream(xrefEntry)) {
  9257. this.cache[num] = xrefEntry;
  9258. }
  9259. return xrefEntry;
  9260. },
  9261. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9262. suppressEncryption) {
  9263. var tableOffset = xrefEntry.offset;
  9264. var stream = this.fetch(new Ref(tableOffset, 0));
  9265. if (!isStream(stream)) {
  9266. error('bad ObjStm stream');
  9267. }
  9268. var first = stream.dict.get('First');
  9269. var n = stream.dict.get('N');
  9270. if (!isInt(first) || !isInt(n)) {
  9271. error('invalid first and n parameters for ObjStm stream');
  9272. }
  9273. var parser = new Parser(new Lexer(stream), false, this);
  9274. parser.allowStreams = true;
  9275. var i, entries = [], num, nums = [];
  9276. // read the object numbers to populate cache
  9277. for (i = 0; i < n; ++i) {
  9278. num = parser.getObj();
  9279. if (!isInt(num)) {
  9280. error('invalid object number in the ObjStm stream: ' + num);
  9281. }
  9282. nums.push(num);
  9283. var offset = parser.getObj();
  9284. if (!isInt(offset)) {
  9285. error('invalid object offset in the ObjStm stream: ' + offset);
  9286. }
  9287. }
  9288. // read stream objects for cache
  9289. for (i = 0; i < n; ++i) {
  9290. entries.push(parser.getObj());
  9291. num = nums[i];
  9292. var entry = this.entries[num];
  9293. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9294. this.cache[num] = entries[i];
  9295. }
  9296. }
  9297. xrefEntry = entries[xrefEntry.gen];
  9298. if (xrefEntry === undefined) {
  9299. error('bad XRef entry for compressed object');
  9300. }
  9301. return xrefEntry;
  9302. },
  9303. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9304. if (!isRef(obj)) {
  9305. return Promise.resolve(obj);
  9306. }
  9307. return this.fetchAsync(obj);
  9308. },
  9309. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9310. var streamManager = this.stream.manager;
  9311. var xref = this;
  9312. return new Promise(function tryFetch(resolve, reject) {
  9313. try {
  9314. resolve(xref.fetch(ref, suppressEncryption));
  9315. } catch (e) {
  9316. if (e instanceof MissingDataException) {
  9317. streamManager.requestRange(e.begin, e.end, function () {
  9318. tryFetch(resolve, reject);
  9319. });
  9320. return;
  9321. }
  9322. reject(e);
  9323. }
  9324. });
  9325. },
  9326. getCatalogObj: function XRef_getCatalogObj() {
  9327. return this.root;
  9328. }
  9329. };
  9330. return XRef;
  9331. })();
  9332. /**
  9333. * A NameTree is like a Dict but has some advantageous properties, see the
  9334. * spec (7.9.6) for more details.
  9335. * TODO: implement all the Dict functions and make this more efficent.
  9336. */
  9337. var NameTree = (function NameTreeClosure() {
  9338. function NameTree(root, xref) {
  9339. this.root = root;
  9340. this.xref = xref;
  9341. }
  9342. NameTree.prototype = {
  9343. getAll: function NameTree_getAll() {
  9344. var dict = {};
  9345. if (!this.root) {
  9346. return dict;
  9347. }
  9348. var xref = this.xref;
  9349. // reading name tree
  9350. var processed = new RefSet();
  9351. processed.put(this.root);
  9352. var queue = [this.root];
  9353. while (queue.length > 0) {
  9354. var i, n;
  9355. var obj = xref.fetchIfRef(queue.shift());
  9356. if (!isDict(obj)) {
  9357. continue;
  9358. }
  9359. if (obj.has('Kids')) {
  9360. var kids = obj.get('Kids');
  9361. for (i = 0, n = kids.length; i < n; i++) {
  9362. var kid = kids[i];
  9363. if (processed.has(kid)) {
  9364. error('invalid destinations');
  9365. }
  9366. queue.push(kid);
  9367. processed.put(kid);
  9368. }
  9369. continue;
  9370. }
  9371. var names = obj.get('Names');
  9372. if (names) {
  9373. for (i = 0, n = names.length; i < n; i += 2) {
  9374. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9375. }
  9376. }
  9377. }
  9378. return dict;
  9379. },
  9380. get: function NameTree_get(destinationId) {
  9381. if (!this.root) {
  9382. return null;
  9383. }
  9384. var xref = this.xref;
  9385. var kidsOrNames = xref.fetchIfRef(this.root);
  9386. var loopCount = 0;
  9387. var MAX_NAMES_LEVELS = 10;
  9388. var l, r, m;
  9389. // Perform a binary search to quickly find the entry that
  9390. // contains the named destination we are looking for.
  9391. while (kidsOrNames.has('Kids')) {
  9392. loopCount++;
  9393. if (loopCount > MAX_NAMES_LEVELS) {
  9394. warn('Search depth limit for named destionations has been reached.');
  9395. return null;
  9396. }
  9397. var kids = kidsOrNames.get('Kids');
  9398. if (!isArray(kids)) {
  9399. return null;
  9400. }
  9401. l = 0;
  9402. r = kids.length - 1;
  9403. while (l <= r) {
  9404. m = (l + r) >> 1;
  9405. var kid = xref.fetchIfRef(kids[m]);
  9406. var limits = kid.get('Limits');
  9407. if (destinationId < limits[0]) {
  9408. r = m - 1;
  9409. } else if (destinationId > limits[1]) {
  9410. l = m + 1;
  9411. } else {
  9412. kidsOrNames = xref.fetchIfRef(kids[m]);
  9413. break;
  9414. }
  9415. }
  9416. if (l > r) {
  9417. return null;
  9418. }
  9419. }
  9420. // If we get here, then we have found the right entry. Now
  9421. // go through the named destinations in the Named dictionary
  9422. // until we find the exact destination we're looking for.
  9423. var names = kidsOrNames.get('Names');
  9424. if (isArray(names)) {
  9425. // Perform a binary search to reduce the lookup time.
  9426. l = 0;
  9427. r = names.length - 2;
  9428. while (l <= r) {
  9429. // Check only even indices (0, 2, 4, ...) because the
  9430. // odd indices contain the actual D array.
  9431. m = (l + r) & ~1;
  9432. if (destinationId < names[m]) {
  9433. r = m - 2;
  9434. } else if (destinationId > names[m]) {
  9435. l = m + 2;
  9436. } else {
  9437. return xref.fetchIfRef(names[m + 1]);
  9438. }
  9439. }
  9440. }
  9441. return null;
  9442. }
  9443. };
  9444. return NameTree;
  9445. })();
  9446. /**
  9447. * "A PDF file can refer to the contents of another file by using a File
  9448. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9449. * NOTE: Only embedded files are supported (as part of the attachments support)
  9450. * TODO: support the 'URL' file system (with caching if !/V), portable
  9451. * collections attributes and related files (/RF)
  9452. */
  9453. var FileSpec = (function FileSpecClosure() {
  9454. function FileSpec(root, xref) {
  9455. if (!root || !isDict(root)) {
  9456. return;
  9457. }
  9458. this.xref = xref;
  9459. this.root = root;
  9460. if (root.has('FS')) {
  9461. this.fs = root.get('FS');
  9462. }
  9463. this.description = root.has('Desc') ?
  9464. stringToPDFString(root.get('Desc')) :
  9465. '';
  9466. if (root.has('RF')) {
  9467. warn('Related file specifications are not supported');
  9468. }
  9469. this.contentAvailable = true;
  9470. if (!root.has('EF')) {
  9471. this.contentAvailable = false;
  9472. warn('Non-embedded file specifications are not supported');
  9473. }
  9474. }
  9475. function pickPlatformItem(dict) {
  9476. // Look for the filename in this order:
  9477. // UF, F, Unix, Mac, DOS
  9478. if (dict.has('UF')) {
  9479. return dict.get('UF');
  9480. } else if (dict.has('F')) {
  9481. return dict.get('F');
  9482. } else if (dict.has('Unix')) {
  9483. return dict.get('Unix');
  9484. } else if (dict.has('Mac')) {
  9485. return dict.get('Mac');
  9486. } else if (dict.has('DOS')) {
  9487. return dict.get('DOS');
  9488. } else {
  9489. return null;
  9490. }
  9491. }
  9492. FileSpec.prototype = {
  9493. get filename() {
  9494. if (!this._filename && this.root) {
  9495. var filename = pickPlatformItem(this.root) || 'unnamed';
  9496. this._filename = stringToPDFString(filename).
  9497. replace(/\\\\/g, '\\').
  9498. replace(/\\\//g, '/').
  9499. replace(/\\/g, '/');
  9500. }
  9501. return this._filename;
  9502. },
  9503. get content() {
  9504. if (!this.contentAvailable) {
  9505. return null;
  9506. }
  9507. if (!this.contentRef && this.root) {
  9508. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9509. }
  9510. var content = null;
  9511. if (this.contentRef) {
  9512. var xref = this.xref;
  9513. var fileObj = xref.fetchIfRef(this.contentRef);
  9514. if (fileObj && isStream(fileObj)) {
  9515. content = fileObj.getBytes();
  9516. } else {
  9517. warn('Embedded file specification points to non-existing/invalid ' +
  9518. 'content');
  9519. }
  9520. } else {
  9521. warn('Embedded file specification does not have a content');
  9522. }
  9523. return content;
  9524. },
  9525. get serializable() {
  9526. return {
  9527. filename: this.filename,
  9528. content: this.content
  9529. };
  9530. }
  9531. };
  9532. return FileSpec;
  9533. })();
  9534. /**
  9535. * A helper for loading missing data in object graphs. It traverses the graph
  9536. * depth first and queues up any objects that have missing data. Once it has
  9537. * has traversed as many objects that are available it attempts to bundle the
  9538. * missing data requests and then resume from the nodes that weren't ready.
  9539. *
  9540. * NOTE: It provides protection from circular references by keeping track of
  9541. * of loaded references. However, you must be careful not to load any graphs
  9542. * that have references to the catalog or other pages since that will cause the
  9543. * entire PDF document object graph to be traversed.
  9544. */
  9545. var ObjectLoader = (function() {
  9546. function mayHaveChildren(value) {
  9547. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9548. }
  9549. function addChildren(node, nodesToVisit) {
  9550. var value;
  9551. if (isDict(node) || isStream(node)) {
  9552. var map;
  9553. if (isDict(node)) {
  9554. map = node.map;
  9555. } else {
  9556. map = node.dict.map;
  9557. }
  9558. for (var key in map) {
  9559. value = map[key];
  9560. if (mayHaveChildren(value)) {
  9561. nodesToVisit.push(value);
  9562. }
  9563. }
  9564. } else if (isArray(node)) {
  9565. for (var i = 0, ii = node.length; i < ii; i++) {
  9566. value = node[i];
  9567. if (mayHaveChildren(value)) {
  9568. nodesToVisit.push(value);
  9569. }
  9570. }
  9571. }
  9572. }
  9573. function ObjectLoader(obj, keys, xref) {
  9574. this.obj = obj;
  9575. this.keys = keys;
  9576. this.xref = xref;
  9577. this.refSet = null;
  9578. }
  9579. ObjectLoader.prototype = {
  9580. load: function ObjectLoader_load() {
  9581. var keys = this.keys;
  9582. this.capability = createPromiseCapability();
  9583. // Don't walk the graph if all the data is already loaded.
  9584. if (!(this.xref.stream instanceof ChunkedStream) ||
  9585. this.xref.stream.getMissingChunks().length === 0) {
  9586. this.capability.resolve();
  9587. return this.capability.promise;
  9588. }
  9589. this.refSet = new RefSet();
  9590. // Setup the initial nodes to visit.
  9591. var nodesToVisit = [];
  9592. for (var i = 0; i < keys.length; i++) {
  9593. nodesToVisit.push(this.obj[keys[i]]);
  9594. }
  9595. this.walk(nodesToVisit);
  9596. return this.capability.promise;
  9597. },
  9598. walk: function ObjectLoader_walk(nodesToVisit) {
  9599. var nodesToRevisit = [];
  9600. var pendingRequests = [];
  9601. // DFS walk of the object graph.
  9602. while (nodesToVisit.length) {
  9603. var currentNode = nodesToVisit.pop();
  9604. // Only references or chunked streams can cause missing data exceptions.
  9605. if (isRef(currentNode)) {
  9606. // Skip nodes that have already been visited.
  9607. if (this.refSet.has(currentNode)) {
  9608. continue;
  9609. }
  9610. try {
  9611. var ref = currentNode;
  9612. this.refSet.put(ref);
  9613. currentNode = this.xref.fetch(currentNode);
  9614. } catch (e) {
  9615. if (!(e instanceof MissingDataException)) {
  9616. throw e;
  9617. }
  9618. nodesToRevisit.push(currentNode);
  9619. pendingRequests.push({ begin: e.begin, end: e.end });
  9620. }
  9621. }
  9622. if (currentNode && currentNode.getBaseStreams) {
  9623. var baseStreams = currentNode.getBaseStreams();
  9624. var foundMissingData = false;
  9625. for (var i = 0; i < baseStreams.length; i++) {
  9626. var stream = baseStreams[i];
  9627. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9628. foundMissingData = true;
  9629. pendingRequests.push({
  9630. begin: stream.start,
  9631. end: stream.end
  9632. });
  9633. }
  9634. }
  9635. if (foundMissingData) {
  9636. nodesToRevisit.push(currentNode);
  9637. }
  9638. }
  9639. addChildren(currentNode, nodesToVisit);
  9640. }
  9641. if (pendingRequests.length) {
  9642. this.xref.stream.manager.requestRanges(pendingRequests,
  9643. function pendingRequestCallback() {
  9644. nodesToVisit = nodesToRevisit;
  9645. for (var i = 0; i < nodesToRevisit.length; i++) {
  9646. var node = nodesToRevisit[i];
  9647. // Remove any reference nodes from the currrent refset so they
  9648. // aren't skipped when we revist them.
  9649. if (isRef(node)) {
  9650. this.refSet.remove(node);
  9651. }
  9652. }
  9653. this.walk(nodesToVisit);
  9654. }.bind(this));
  9655. return;
  9656. }
  9657. // Everything is loaded.
  9658. this.refSet = null;
  9659. this.capability.resolve();
  9660. }
  9661. };
  9662. return ObjectLoader;
  9663. })();
  9664. var ISOAdobeCharset = [
  9665. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9666. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9667. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9668. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9669. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9670. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9671. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9672. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9673. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9674. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9675. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9676. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9677. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9678. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9679. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9680. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9681. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9682. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9683. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9684. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9685. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9686. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9687. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9688. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9689. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9690. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9691. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9692. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9693. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9694. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9695. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9696. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9697. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9698. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9699. ];
  9700. var ExpertCharset = [
  9701. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9702. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9703. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9704. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9705. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9706. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9707. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9708. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9709. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9710. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9711. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9712. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9713. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9714. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9715. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9716. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9717. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9718. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9719. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9720. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9721. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9722. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9723. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9724. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9725. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9726. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9727. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9728. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9729. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9730. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9731. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9732. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9733. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9734. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9735. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9736. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9737. 'Ydieresissmall'
  9738. ];
  9739. var ExpertSubsetCharset = [
  9740. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9741. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9742. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9743. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9744. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9745. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9746. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9747. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9748. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9749. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9750. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9751. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9752. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9753. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9754. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9755. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9756. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9757. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9758. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9759. 'periodinferior', 'commainferior'
  9760. ];
  9761. var DEFAULT_ICON_SIZE = 22; // px
  9762. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9763. var Annotation = (function AnnotationClosure() {
  9764. // 12.5.5: Algorithm: Appearance streams
  9765. function getTransformMatrix(rect, bbox, matrix) {
  9766. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9767. var minX = bounds[0];
  9768. var minY = bounds[1];
  9769. var maxX = bounds[2];
  9770. var maxY = bounds[3];
  9771. if (minX === maxX || minY === maxY) {
  9772. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9773. // just apply the transform for rect
  9774. return [1, 0, 0, 1, rect[0], rect[1]];
  9775. }
  9776. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9777. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9778. return [
  9779. xRatio,
  9780. 0,
  9781. 0,
  9782. yRatio,
  9783. rect[0] - minX * xRatio,
  9784. rect[1] - minY * yRatio
  9785. ];
  9786. }
  9787. function getDefaultAppearance(dict) {
  9788. var appearanceState = dict.get('AP');
  9789. if (!isDict(appearanceState)) {
  9790. return;
  9791. }
  9792. var appearance;
  9793. var appearances = appearanceState.get('N');
  9794. if (isDict(appearances)) {
  9795. var as = dict.get('AS');
  9796. if (as && appearances.has(as.name)) {
  9797. appearance = appearances.get(as.name);
  9798. }
  9799. } else {
  9800. appearance = appearances;
  9801. }
  9802. return appearance;
  9803. }
  9804. function Annotation(params) {
  9805. var dict = params.dict;
  9806. var data = this.data = {};
  9807. data.subtype = dict.get('Subtype').name;
  9808. var rect = dict.get('Rect') || [0, 0, 0, 0];
  9809. data.rect = Util.normalizeRect(rect);
  9810. data.annotationFlags = dict.get('F');
  9811. var color = dict.get('C');
  9812. if (isArray(color) && color.length === 3) {
  9813. // TODO(mack): currently only supporting rgb; need support different
  9814. // colorspaces
  9815. data.color = color;
  9816. } else {
  9817. data.color = [0, 0, 0];
  9818. }
  9819. // Some types of annotations have border style dict which has more
  9820. // info than the border array
  9821. if (dict.has('BS')) {
  9822. var borderStyle = dict.get('BS');
  9823. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  9824. } else {
  9825. var borderArray = dict.get('Border') || [0, 0, 1];
  9826. data.borderWidth = borderArray[2] || 0;
  9827. // TODO: implement proper support for annotations with line dash patterns.
  9828. var dashArray = borderArray[3];
  9829. if (data.borderWidth > 0 && dashArray) {
  9830. if (!isArray(dashArray)) {
  9831. // Ignore the border if dashArray is not actually an array,
  9832. // this is consistent with the behaviour in Adobe Reader.
  9833. data.borderWidth = 0;
  9834. } else {
  9835. var dashArrayLength = dashArray.length;
  9836. if (dashArrayLength > 0) {
  9837. // According to the PDF specification: the elements in a dashArray
  9838. // shall be numbers that are nonnegative and not all equal to zero.
  9839. var isInvalid = false;
  9840. var numPositive = 0;
  9841. for (var i = 0; i < dashArrayLength; i++) {
  9842. var validNumber = (+dashArray[i] >= 0);
  9843. if (!validNumber) {
  9844. isInvalid = true;
  9845. break;
  9846. } else if (dashArray[i] > 0) {
  9847. numPositive++;
  9848. }
  9849. }
  9850. if (isInvalid || numPositive === 0) {
  9851. data.borderWidth = 0;
  9852. }
  9853. }
  9854. }
  9855. }
  9856. }
  9857. this.appearance = getDefaultAppearance(dict);
  9858. data.hasAppearance = !!this.appearance;
  9859. data.id = params.ref.num;
  9860. }
  9861. Annotation.prototype = {
  9862. getData: function Annotation_getData() {
  9863. return this.data;
  9864. },
  9865. isInvisible: function Annotation_isInvisible() {
  9866. var data = this.data;
  9867. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  9868. return false;
  9869. } else {
  9870. return !!(data &&
  9871. data.annotationFlags && // Default: not invisible
  9872. data.annotationFlags & 0x1); // Invisible
  9873. }
  9874. },
  9875. isViewable: function Annotation_isViewable() {
  9876. var data = this.data;
  9877. return !!(!this.isInvisible() &&
  9878. data &&
  9879. (!data.annotationFlags ||
  9880. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  9881. data.rect); // rectangle is necessary
  9882. },
  9883. isPrintable: function Annotation_isPrintable() {
  9884. var data = this.data;
  9885. return !!(!this.isInvisible() &&
  9886. data &&
  9887. data.annotationFlags && // Default: not printable
  9888. data.annotationFlags & 0x4 && // Print
  9889. !(data.annotationFlags & 0x2) && // Hidden
  9890. data.rect); // rectangle is necessary
  9891. },
  9892. loadResources: function Annotation_loadResources(keys) {
  9893. return new Promise(function (resolve, reject) {
  9894. this.appearance.dict.getAsync('Resources').then(function (resources) {
  9895. if (!resources) {
  9896. resolve();
  9897. return;
  9898. }
  9899. var objectLoader = new ObjectLoader(resources.map,
  9900. keys,
  9901. resources.xref);
  9902. objectLoader.load().then(function() {
  9903. resolve(resources);
  9904. }, reject);
  9905. }, reject);
  9906. }.bind(this));
  9907. },
  9908. getOperatorList: function Annotation_getOperatorList(evaluator) {
  9909. if (!this.appearance) {
  9910. return Promise.resolve(new OperatorList());
  9911. }
  9912. var data = this.data;
  9913. var appearanceDict = this.appearance.dict;
  9914. var resourcesPromise = this.loadResources([
  9915. 'ExtGState',
  9916. 'ColorSpace',
  9917. 'Pattern',
  9918. 'Shading',
  9919. 'XObject',
  9920. 'Font'
  9921. // ProcSet
  9922. // Properties
  9923. ]);
  9924. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  9925. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  9926. var transform = getTransformMatrix(data.rect, bbox, matrix);
  9927. var self = this;
  9928. return resourcesPromise.then(function(resources) {
  9929. var opList = new OperatorList();
  9930. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  9931. return evaluator.getOperatorList(self.appearance, resources, opList).
  9932. then(function () {
  9933. opList.addOp(OPS.endAnnotation, []);
  9934. self.appearance.reset();
  9935. return opList;
  9936. });
  9937. });
  9938. }
  9939. };
  9940. Annotation.getConstructor =
  9941. function Annotation_getConstructor(subtype, fieldType) {
  9942. if (!subtype) {
  9943. return;
  9944. }
  9945. // TODO(mack): Implement FreeText annotations
  9946. if (subtype === 'Link') {
  9947. return LinkAnnotation;
  9948. } else if (subtype === 'Text') {
  9949. return TextAnnotation;
  9950. } else if (subtype === 'Widget') {
  9951. if (!fieldType) {
  9952. return;
  9953. }
  9954. if (fieldType === 'Tx') {
  9955. return TextWidgetAnnotation;
  9956. } else {
  9957. return WidgetAnnotation;
  9958. }
  9959. } else {
  9960. return Annotation;
  9961. }
  9962. };
  9963. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  9964. var dict = xref.fetchIfRef(ref);
  9965. if (!isDict(dict)) {
  9966. return;
  9967. }
  9968. var subtype = dict.get('Subtype');
  9969. subtype = isName(subtype) ? subtype.name : '';
  9970. if (!subtype) {
  9971. return;
  9972. }
  9973. var fieldType = Util.getInheritableProperty(dict, 'FT');
  9974. fieldType = isName(fieldType) ? fieldType.name : '';
  9975. var Constructor = Annotation.getConstructor(subtype, fieldType);
  9976. if (!Constructor) {
  9977. return;
  9978. }
  9979. var params = {
  9980. dict: dict,
  9981. ref: ref,
  9982. };
  9983. var annotation = new Constructor(params);
  9984. if (annotation.isViewable() || annotation.isPrintable()) {
  9985. return annotation;
  9986. } else {
  9987. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  9988. warn('unimplemented annotation type: ' + subtype);
  9989. }
  9990. }
  9991. };
  9992. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  9993. annotations, opList, pdfManager, partialEvaluator, intent) {
  9994. function reject(e) {
  9995. annotationsReadyCapability.reject(e);
  9996. }
  9997. var annotationsReadyCapability = createPromiseCapability();
  9998. var annotationPromises = [];
  9999. for (var i = 0, n = annotations.length; i < n; ++i) {
  10000. if (intent === 'display' && annotations[i].isViewable() ||
  10001. intent === 'print' && annotations[i].isPrintable()) {
  10002. annotationPromises.push(
  10003. annotations[i].getOperatorList(partialEvaluator));
  10004. }
  10005. }
  10006. Promise.all(annotationPromises).then(function(datas) {
  10007. opList.addOp(OPS.beginAnnotations, []);
  10008. for (var i = 0, n = datas.length; i < n; ++i) {
  10009. var annotOpList = datas[i];
  10010. opList.addOpList(annotOpList);
  10011. }
  10012. opList.addOp(OPS.endAnnotations, []);
  10013. annotationsReadyCapability.resolve();
  10014. }, reject);
  10015. return annotationsReadyCapability.promise;
  10016. };
  10017. return Annotation;
  10018. })();
  10019. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10020. function WidgetAnnotation(params) {
  10021. Annotation.call(this, params);
  10022. var dict = params.dict;
  10023. var data = this.data;
  10024. data.fieldValue = stringToPDFString(
  10025. Util.getInheritableProperty(dict, 'V') || '');
  10026. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10027. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10028. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10029. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10030. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10031. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10032. // Building the full field name by collecting the field and
  10033. // its ancestors 'T' data and joining them using '.'.
  10034. var fieldName = [];
  10035. var namedItem = dict;
  10036. var ref = params.ref;
  10037. while (namedItem) {
  10038. var parent = namedItem.get('Parent');
  10039. var parentRef = namedItem.getRaw('Parent');
  10040. var name = namedItem.get('T');
  10041. if (name) {
  10042. fieldName.unshift(stringToPDFString(name));
  10043. } else if (parent && ref) {
  10044. // The field name is absent, that means more than one field
  10045. // with the same name may exist. Replacing the empty name
  10046. // with the '`' plus index in the parent's 'Kids' array.
  10047. // This is not in the PDF spec but necessary to id the
  10048. // the input controls.
  10049. var kids = parent.get('Kids');
  10050. var j, jj;
  10051. for (j = 0, jj = kids.length; j < jj; j++) {
  10052. var kidRef = kids[j];
  10053. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10054. break;
  10055. }
  10056. }
  10057. fieldName.unshift('`' + j);
  10058. }
  10059. namedItem = parent;
  10060. ref = parentRef;
  10061. }
  10062. data.fullName = fieldName.join('.');
  10063. }
  10064. var parent = Annotation.prototype;
  10065. Util.inherit(WidgetAnnotation, Annotation, {
  10066. isViewable: function WidgetAnnotation_isViewable() {
  10067. if (this.data.fieldType === 'Sig') {
  10068. warn('unimplemented annotation type: Widget signature');
  10069. return false;
  10070. }
  10071. return parent.isViewable.call(this);
  10072. }
  10073. });
  10074. return WidgetAnnotation;
  10075. })();
  10076. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10077. function TextWidgetAnnotation(params) {
  10078. WidgetAnnotation.call(this, params);
  10079. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10080. this.data.annotationType = AnnotationType.WIDGET;
  10081. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10082. }
  10083. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10084. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10085. if (this.appearance) {
  10086. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10087. }
  10088. var opList = new OperatorList();
  10089. var data = this.data;
  10090. // Even if there is an appearance stream, ignore it. This is the
  10091. // behaviour used by Adobe Reader.
  10092. if (!data.defaultAppearance) {
  10093. return Promise.resolve(opList);
  10094. }
  10095. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10096. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10097. then(function () {
  10098. return opList;
  10099. });
  10100. }
  10101. });
  10102. return TextWidgetAnnotation;
  10103. })();
  10104. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10105. function InteractiveAnnotation(params) {
  10106. Annotation.call(this, params);
  10107. this.data.hasHtml = true;
  10108. }
  10109. Util.inherit(InteractiveAnnotation, Annotation, { });
  10110. return InteractiveAnnotation;
  10111. })();
  10112. var TextAnnotation = (function TextAnnotationClosure() {
  10113. function TextAnnotation(params) {
  10114. InteractiveAnnotation.call(this, params);
  10115. var dict = params.dict;
  10116. var data = this.data;
  10117. var content = dict.get('Contents');
  10118. var title = dict.get('T');
  10119. data.annotationType = AnnotationType.TEXT;
  10120. data.content = stringToPDFString(content || '');
  10121. data.title = stringToPDFString(title || '');
  10122. if (data.hasAppearance) {
  10123. data.name = 'NoIcon';
  10124. } else {
  10125. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10126. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10127. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10128. }
  10129. if (dict.has('C')) {
  10130. data.hasBgColor = true;
  10131. }
  10132. }
  10133. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10134. return TextAnnotation;
  10135. })();
  10136. var LinkAnnotation = (function LinkAnnotationClosure() {
  10137. function LinkAnnotation(params) {
  10138. InteractiveAnnotation.call(this, params);
  10139. var dict = params.dict;
  10140. var data = this.data;
  10141. data.annotationType = AnnotationType.LINK;
  10142. var action = dict.get('A');
  10143. if (action) {
  10144. var linkType = action.get('S').name;
  10145. if (linkType === 'URI') {
  10146. var url = action.get('URI');
  10147. if (isName(url)) {
  10148. // Some bad PDFs do not put parentheses around relative URLs.
  10149. url = '/' + url.name;
  10150. } else if (url) {
  10151. url = addDefaultProtocolToUrl(url);
  10152. }
  10153. // TODO: pdf spec mentions urls can be relative to a Base
  10154. // entry in the dictionary.
  10155. if (!isValidUrl(url, false)) {
  10156. url = '';
  10157. }
  10158. data.url = url;
  10159. } else if (linkType === 'GoTo') {
  10160. data.dest = action.get('D');
  10161. } else if (linkType === 'GoToR') {
  10162. var urlDict = action.get('F');
  10163. if (isDict(urlDict)) {
  10164. // We assume that the 'url' is a Filspec dictionary
  10165. // and fetch the url without checking any further
  10166. url = urlDict.get('F') || '';
  10167. }
  10168. // TODO: pdf reference says that GoToR
  10169. // can also have 'NewWindow' attribute
  10170. if (!isValidUrl(url, false)) {
  10171. url = '';
  10172. }
  10173. data.url = url;
  10174. data.dest = action.get('D');
  10175. } else if (linkType === 'Named') {
  10176. data.action = action.get('N').name;
  10177. } else {
  10178. warn('unrecognized link type: ' + linkType);
  10179. }
  10180. } else if (dict.has('Dest')) {
  10181. // simple destination link
  10182. var dest = dict.get('Dest');
  10183. data.dest = isName(dest) ? dest.name : dest;
  10184. }
  10185. }
  10186. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10187. function addDefaultProtocolToUrl(url) {
  10188. if (url && url.indexOf('www.') === 0) {
  10189. return ('http://' + url);
  10190. }
  10191. return url;
  10192. }
  10193. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  10194. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  10195. return false;
  10196. }
  10197. });
  10198. return LinkAnnotation;
  10199. })();
  10200. var PDFFunction = (function PDFFunctionClosure() {
  10201. var CONSTRUCT_SAMPLED = 0;
  10202. var CONSTRUCT_INTERPOLATED = 2;
  10203. var CONSTRUCT_STICHED = 3;
  10204. var CONSTRUCT_POSTSCRIPT = 4;
  10205. return {
  10206. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10207. str) {
  10208. var i, ii;
  10209. var length = 1;
  10210. for (i = 0, ii = size.length; i < ii; i++) {
  10211. length *= size[i];
  10212. }
  10213. length *= outputSize;
  10214. var array = new Array(length);
  10215. var codeSize = 0;
  10216. var codeBuf = 0;
  10217. // 32 is a valid bps so shifting won't work
  10218. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10219. var strBytes = str.getBytes((length * bps + 7) / 8);
  10220. var strIdx = 0;
  10221. for (i = 0; i < length; i++) {
  10222. while (codeSize < bps) {
  10223. codeBuf <<= 8;
  10224. codeBuf |= strBytes[strIdx++];
  10225. codeSize += 8;
  10226. }
  10227. codeSize -= bps;
  10228. array[i] = (codeBuf >> codeSize) * sampleMul;
  10229. codeBuf &= (1 << codeSize) - 1;
  10230. }
  10231. return array;
  10232. },
  10233. getIR: function PDFFunction_getIR(xref, fn) {
  10234. var dict = fn.dict;
  10235. if (!dict) {
  10236. dict = fn;
  10237. }
  10238. var types = [this.constructSampled,
  10239. null,
  10240. this.constructInterpolated,
  10241. this.constructStiched,
  10242. this.constructPostScript];
  10243. var typeNum = dict.get('FunctionType');
  10244. var typeFn = types[typeNum];
  10245. if (!typeFn) {
  10246. error('Unknown type of function');
  10247. }
  10248. return typeFn.call(this, fn, dict, xref);
  10249. },
  10250. fromIR: function PDFFunction_fromIR(IR) {
  10251. var type = IR[0];
  10252. switch (type) {
  10253. case CONSTRUCT_SAMPLED:
  10254. return this.constructSampledFromIR(IR);
  10255. case CONSTRUCT_INTERPOLATED:
  10256. return this.constructInterpolatedFromIR(IR);
  10257. case CONSTRUCT_STICHED:
  10258. return this.constructStichedFromIR(IR);
  10259. //case CONSTRUCT_POSTSCRIPT:
  10260. default:
  10261. return this.constructPostScriptFromIR(IR);
  10262. }
  10263. },
  10264. parse: function PDFFunction_parse(xref, fn) {
  10265. var IR = this.getIR(xref, fn);
  10266. return this.fromIR(IR);
  10267. },
  10268. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10269. if (!isArray(fnObj)) {
  10270. // not an array -- parsing as regular function
  10271. return this.parse(xref, fnObj);
  10272. }
  10273. var fnArray = [];
  10274. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10275. var obj = xref.fetchIfRef(fnObj[j]);
  10276. fnArray.push(PDFFunction.parse(xref, obj));
  10277. }
  10278. return function (src, srcOffset, dest, destOffset) {
  10279. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10280. fnArray[i](src, srcOffset, dest, destOffset + i);
  10281. }
  10282. };
  10283. },
  10284. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10285. function toMultiArray(arr) {
  10286. var inputLength = arr.length;
  10287. var out = [];
  10288. var index = 0;
  10289. for (var i = 0; i < inputLength; i += 2) {
  10290. out[index] = [arr[i], arr[i + 1]];
  10291. ++index;
  10292. }
  10293. return out;
  10294. }
  10295. var domain = dict.get('Domain');
  10296. var range = dict.get('Range');
  10297. if (!domain || !range) {
  10298. error('No domain or range');
  10299. }
  10300. var inputSize = domain.length / 2;
  10301. var outputSize = range.length / 2;
  10302. domain = toMultiArray(domain);
  10303. range = toMultiArray(range);
  10304. var size = dict.get('Size');
  10305. var bps = dict.get('BitsPerSample');
  10306. var order = dict.get('Order') || 1;
  10307. if (order !== 1) {
  10308. // No description how cubic spline interpolation works in PDF32000:2008
  10309. // As in poppler, ignoring order, linear interpolation may work as good
  10310. info('No support for cubic spline interpolation: ' + order);
  10311. }
  10312. var encode = dict.get('Encode');
  10313. if (!encode) {
  10314. encode = [];
  10315. for (var i = 0; i < inputSize; ++i) {
  10316. encode.push(0);
  10317. encode.push(size[i] - 1);
  10318. }
  10319. }
  10320. encode = toMultiArray(encode);
  10321. var decode = dict.get('Decode');
  10322. if (!decode) {
  10323. decode = range;
  10324. } else {
  10325. decode = toMultiArray(decode);
  10326. }
  10327. var samples = this.getSampleArray(size, outputSize, bps, str);
  10328. return [
  10329. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10330. outputSize, Math.pow(2, bps) - 1, range
  10331. ];
  10332. },
  10333. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10334. // See chapter 3, page 109 of the PDF reference
  10335. function interpolate(x, xmin, xmax, ymin, ymax) {
  10336. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10337. }
  10338. return function constructSampledFromIRResult(src, srcOffset,
  10339. dest, destOffset) {
  10340. // See chapter 3, page 110 of the PDF reference.
  10341. var m = IR[1];
  10342. var domain = IR[2];
  10343. var encode = IR[3];
  10344. var decode = IR[4];
  10345. var samples = IR[5];
  10346. var size = IR[6];
  10347. var n = IR[7];
  10348. //var mask = IR[8];
  10349. var range = IR[9];
  10350. // Building the cube vertices: its part and sample index
  10351. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10352. var cubeVertices = 1 << m;
  10353. var cubeN = new Float64Array(cubeVertices);
  10354. var cubeVertex = new Uint32Array(cubeVertices);
  10355. var i, j;
  10356. for (j = 0; j < cubeVertices; j++) {
  10357. cubeN[j] = 1;
  10358. }
  10359. var k = n, pos = 1;
  10360. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10361. for (i = 0; i < m; ++i) {
  10362. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10363. var domain_2i = domain[i][0];
  10364. var domain_2i_1 = domain[i][1];
  10365. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10366. domain_2i_1);
  10367. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10368. // Encode_2i, Encode_2i+1)
  10369. var e = interpolate(xi, domain_2i, domain_2i_1,
  10370. encode[i][0], encode[i][1]);
  10371. // e_i' = min(max(e_i, 0), Size_i - 1)
  10372. var size_i = size[i];
  10373. e = Math.min(Math.max(e, 0), size_i - 1);
  10374. // Adjusting the cube: N and vertex sample index
  10375. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10376. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10377. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10378. var offset0 = e0 * k;
  10379. var offset1 = offset0 + k; // e1 * k
  10380. for (j = 0; j < cubeVertices; j++) {
  10381. if (j & pos) {
  10382. cubeN[j] *= n1;
  10383. cubeVertex[j] += offset1;
  10384. } else {
  10385. cubeN[j] *= n0;
  10386. cubeVertex[j] += offset0;
  10387. }
  10388. }
  10389. k *= size_i;
  10390. pos <<= 1;
  10391. }
  10392. for (j = 0; j < n; ++j) {
  10393. // Sum all cube vertices' samples portions
  10394. var rj = 0;
  10395. for (i = 0; i < cubeVertices; i++) {
  10396. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10397. }
  10398. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10399. // Decode_2j, Decode_2j+1)
  10400. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10401. // y_j = min(max(r_j, range_2j), range_2j+1)
  10402. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10403. range[j][1]);
  10404. }
  10405. };
  10406. },
  10407. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10408. dict) {
  10409. var c0 = dict.get('C0') || [0];
  10410. var c1 = dict.get('C1') || [1];
  10411. var n = dict.get('N');
  10412. if (!isArray(c0) || !isArray(c1)) {
  10413. error('Illegal dictionary for interpolated function');
  10414. }
  10415. var length = c0.length;
  10416. var diff = [];
  10417. for (var i = 0; i < length; ++i) {
  10418. diff.push(c1[i] - c0[i]);
  10419. }
  10420. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10421. },
  10422. constructInterpolatedFromIR:
  10423. function PDFFunction_constructInterpolatedFromIR(IR) {
  10424. var c0 = IR[1];
  10425. var diff = IR[2];
  10426. var n = IR[3];
  10427. var length = diff.length;
  10428. return function constructInterpolatedFromIRResult(src, srcOffset,
  10429. dest, destOffset) {
  10430. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10431. for (var j = 0; j < length; ++j) {
  10432. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10433. }
  10434. };
  10435. },
  10436. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10437. var domain = dict.get('Domain');
  10438. if (!domain) {
  10439. error('No domain');
  10440. }
  10441. var inputSize = domain.length / 2;
  10442. if (inputSize !== 1) {
  10443. error('Bad domain for stiched function');
  10444. }
  10445. var fnRefs = dict.get('Functions');
  10446. var fns = [];
  10447. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10448. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10449. }
  10450. var bounds = dict.get('Bounds');
  10451. var encode = dict.get('Encode');
  10452. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10453. },
  10454. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10455. var domain = IR[1];
  10456. var bounds = IR[2];
  10457. var encode = IR[3];
  10458. var fnsIR = IR[4];
  10459. var fns = [];
  10460. var tmpBuf = new Float32Array(1);
  10461. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10462. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10463. }
  10464. return function constructStichedFromIRResult(src, srcOffset,
  10465. dest, destOffset) {
  10466. var clip = function constructStichedFromIRClip(v, min, max) {
  10467. if (v > max) {
  10468. v = max;
  10469. } else if (v < min) {
  10470. v = min;
  10471. }
  10472. return v;
  10473. };
  10474. // clip to domain
  10475. var v = clip(src[srcOffset], domain[0], domain[1]);
  10476. // calulate which bound the value is in
  10477. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10478. if (v < bounds[i]) {
  10479. break;
  10480. }
  10481. }
  10482. // encode value into domain of function
  10483. var dmin = domain[0];
  10484. if (i > 0) {
  10485. dmin = bounds[i - 1];
  10486. }
  10487. var dmax = domain[1];
  10488. if (i < bounds.length) {
  10489. dmax = bounds[i];
  10490. }
  10491. var rmin = encode[2 * i];
  10492. var rmax = encode[2 * i + 1];
  10493. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10494. // call the appropriate function
  10495. fns[i](tmpBuf, 0, dest, destOffset);
  10496. };
  10497. },
  10498. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10499. xref) {
  10500. var domain = dict.get('Domain');
  10501. var range = dict.get('Range');
  10502. if (!domain) {
  10503. error('No domain.');
  10504. }
  10505. if (!range) {
  10506. error('No range.');
  10507. }
  10508. var lexer = new PostScriptLexer(fn);
  10509. var parser = new PostScriptParser(lexer);
  10510. var code = parser.parse();
  10511. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10512. },
  10513. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10514. IR) {
  10515. var domain = IR[1];
  10516. var range = IR[2];
  10517. var code = IR[3];
  10518. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10519. if (compiled) {
  10520. // Compiled function consists of simple expressions such as addition,
  10521. // subtraction, Math.max, and also contains 'var' and 'return'
  10522. // statements. See the generation in the PostScriptCompiler below.
  10523. /*jshint -W054 */
  10524. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10525. }
  10526. info('Unable to compile PS function');
  10527. var numOutputs = range.length >> 1;
  10528. var numInputs = domain.length >> 1;
  10529. var evaluator = new PostScriptEvaluator(code);
  10530. // Cache the values for a big speed up, the cache size is limited though
  10531. // since the number of possible values can be huge from a PS function.
  10532. var cache = {};
  10533. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10534. // seen in our tests.
  10535. var MAX_CACHE_SIZE = 2048 * 4;
  10536. var cache_available = MAX_CACHE_SIZE;
  10537. var tmpBuf = new Float32Array(numInputs);
  10538. return function constructPostScriptFromIRResult(src, srcOffset,
  10539. dest, destOffset) {
  10540. var i, value;
  10541. var key = '';
  10542. var input = tmpBuf;
  10543. for (i = 0; i < numInputs; i++) {
  10544. value = src[srcOffset + i];
  10545. input[i] = value;
  10546. key += value + '_';
  10547. }
  10548. var cachedValue = cache[key];
  10549. if (cachedValue !== undefined) {
  10550. cachedValue.set(dest, destOffset);
  10551. return;
  10552. }
  10553. var output = new Float32Array(numOutputs);
  10554. var stack = evaluator.execute(input);
  10555. var stackIndex = stack.length - numOutputs;
  10556. for (i = 0; i < numOutputs; i++) {
  10557. value = stack[stackIndex + i];
  10558. var bound = range[i * 2];
  10559. if (value < bound) {
  10560. value = bound;
  10561. } else {
  10562. bound = range[i * 2 +1];
  10563. if (value > bound) {
  10564. value = bound;
  10565. }
  10566. }
  10567. output[i] = value;
  10568. }
  10569. if (cache_available > 0) {
  10570. cache_available--;
  10571. cache[key] = output;
  10572. }
  10573. output.set(dest, destOffset);
  10574. };
  10575. }
  10576. };
  10577. })();
  10578. function isPDFFunction(v) {
  10579. var fnDict;
  10580. if (typeof v !== 'object') {
  10581. return false;
  10582. } else if (isDict(v)) {
  10583. fnDict = v;
  10584. } else if (isStream(v)) {
  10585. fnDict = v.dict;
  10586. } else {
  10587. return false;
  10588. }
  10589. return fnDict.has('FunctionType');
  10590. }
  10591. var PostScriptStack = (function PostScriptStackClosure() {
  10592. var MAX_STACK_SIZE = 100;
  10593. function PostScriptStack(initialStack) {
  10594. this.stack = !initialStack ? [] :
  10595. Array.prototype.slice.call(initialStack, 0);
  10596. }
  10597. PostScriptStack.prototype = {
  10598. push: function PostScriptStack_push(value) {
  10599. if (this.stack.length >= MAX_STACK_SIZE) {
  10600. error('PostScript function stack overflow.');
  10601. }
  10602. this.stack.push(value);
  10603. },
  10604. pop: function PostScriptStack_pop() {
  10605. if (this.stack.length <= 0) {
  10606. error('PostScript function stack underflow.');
  10607. }
  10608. return this.stack.pop();
  10609. },
  10610. copy: function PostScriptStack_copy(n) {
  10611. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10612. error('PostScript function stack overflow.');
  10613. }
  10614. var stack = this.stack;
  10615. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10616. stack.push(stack[i]);
  10617. }
  10618. },
  10619. index: function PostScriptStack_index(n) {
  10620. this.push(this.stack[this.stack.length - n - 1]);
  10621. },
  10622. // rotate the last n stack elements p times
  10623. roll: function PostScriptStack_roll(n, p) {
  10624. var stack = this.stack;
  10625. var l = stack.length - n;
  10626. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10627. for (i = l, j = r; i < j; i++, j--) {
  10628. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10629. }
  10630. for (i = l, j = c - 1; i < j; i++, j--) {
  10631. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10632. }
  10633. for (i = c, j = r; i < j; i++, j--) {
  10634. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10635. }
  10636. }
  10637. };
  10638. return PostScriptStack;
  10639. })();
  10640. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10641. function PostScriptEvaluator(operators) {
  10642. this.operators = operators;
  10643. }
  10644. PostScriptEvaluator.prototype = {
  10645. execute: function PostScriptEvaluator_execute(initialStack) {
  10646. var stack = new PostScriptStack(initialStack);
  10647. var counter = 0;
  10648. var operators = this.operators;
  10649. var length = operators.length;
  10650. var operator, a, b;
  10651. while (counter < length) {
  10652. operator = operators[counter++];
  10653. if (typeof operator === 'number') {
  10654. // Operator is really an operand and should be pushed to the stack.
  10655. stack.push(operator);
  10656. continue;
  10657. }
  10658. switch (operator) {
  10659. // non standard ps operators
  10660. case 'jz': // jump if false
  10661. b = stack.pop();
  10662. a = stack.pop();
  10663. if (!a) {
  10664. counter = b;
  10665. }
  10666. break;
  10667. case 'j': // jump
  10668. a = stack.pop();
  10669. counter = a;
  10670. break;
  10671. // all ps operators in alphabetical order (excluding if/ifelse)
  10672. case 'abs':
  10673. a = stack.pop();
  10674. stack.push(Math.abs(a));
  10675. break;
  10676. case 'add':
  10677. b = stack.pop();
  10678. a = stack.pop();
  10679. stack.push(a + b);
  10680. break;
  10681. case 'and':
  10682. b = stack.pop();
  10683. a = stack.pop();
  10684. if (isBool(a) && isBool(b)) {
  10685. stack.push(a && b);
  10686. } else {
  10687. stack.push(a & b);
  10688. }
  10689. break;
  10690. case 'atan':
  10691. a = stack.pop();
  10692. stack.push(Math.atan(a));
  10693. break;
  10694. case 'bitshift':
  10695. b = stack.pop();
  10696. a = stack.pop();
  10697. if (a > 0) {
  10698. stack.push(a << b);
  10699. } else {
  10700. stack.push(a >> b);
  10701. }
  10702. break;
  10703. case 'ceiling':
  10704. a = stack.pop();
  10705. stack.push(Math.ceil(a));
  10706. break;
  10707. case 'copy':
  10708. a = stack.pop();
  10709. stack.copy(a);
  10710. break;
  10711. case 'cos':
  10712. a = stack.pop();
  10713. stack.push(Math.cos(a));
  10714. break;
  10715. case 'cvi':
  10716. a = stack.pop() | 0;
  10717. stack.push(a);
  10718. break;
  10719. case 'cvr':
  10720. // noop
  10721. break;
  10722. case 'div':
  10723. b = stack.pop();
  10724. a = stack.pop();
  10725. stack.push(a / b);
  10726. break;
  10727. case 'dup':
  10728. stack.copy(1);
  10729. break;
  10730. case 'eq':
  10731. b = stack.pop();
  10732. a = stack.pop();
  10733. stack.push(a === b);
  10734. break;
  10735. case 'exch':
  10736. stack.roll(2, 1);
  10737. break;
  10738. case 'exp':
  10739. b = stack.pop();
  10740. a = stack.pop();
  10741. stack.push(Math.pow(a, b));
  10742. break;
  10743. case 'false':
  10744. stack.push(false);
  10745. break;
  10746. case 'floor':
  10747. a = stack.pop();
  10748. stack.push(Math.floor(a));
  10749. break;
  10750. case 'ge':
  10751. b = stack.pop();
  10752. a = stack.pop();
  10753. stack.push(a >= b);
  10754. break;
  10755. case 'gt':
  10756. b = stack.pop();
  10757. a = stack.pop();
  10758. stack.push(a > b);
  10759. break;
  10760. case 'idiv':
  10761. b = stack.pop();
  10762. a = stack.pop();
  10763. stack.push((a / b) | 0);
  10764. break;
  10765. case 'index':
  10766. a = stack.pop();
  10767. stack.index(a);
  10768. break;
  10769. case 'le':
  10770. b = stack.pop();
  10771. a = stack.pop();
  10772. stack.push(a <= b);
  10773. break;
  10774. case 'ln':
  10775. a = stack.pop();
  10776. stack.push(Math.log(a));
  10777. break;
  10778. case 'log':
  10779. a = stack.pop();
  10780. stack.push(Math.log(a) / Math.LN10);
  10781. break;
  10782. case 'lt':
  10783. b = stack.pop();
  10784. a = stack.pop();
  10785. stack.push(a < b);
  10786. break;
  10787. case 'mod':
  10788. b = stack.pop();
  10789. a = stack.pop();
  10790. stack.push(a % b);
  10791. break;
  10792. case 'mul':
  10793. b = stack.pop();
  10794. a = stack.pop();
  10795. stack.push(a * b);
  10796. break;
  10797. case 'ne':
  10798. b = stack.pop();
  10799. a = stack.pop();
  10800. stack.push(a !== b);
  10801. break;
  10802. case 'neg':
  10803. a = stack.pop();
  10804. stack.push(-a);
  10805. break;
  10806. case 'not':
  10807. a = stack.pop();
  10808. if (isBool(a)) {
  10809. stack.push(!a);
  10810. } else {
  10811. stack.push(~a);
  10812. }
  10813. break;
  10814. case 'or':
  10815. b = stack.pop();
  10816. a = stack.pop();
  10817. if (isBool(a) && isBool(b)) {
  10818. stack.push(a || b);
  10819. } else {
  10820. stack.push(a | b);
  10821. }
  10822. break;
  10823. case 'pop':
  10824. stack.pop();
  10825. break;
  10826. case 'roll':
  10827. b = stack.pop();
  10828. a = stack.pop();
  10829. stack.roll(a, b);
  10830. break;
  10831. case 'round':
  10832. a = stack.pop();
  10833. stack.push(Math.round(a));
  10834. break;
  10835. case 'sin':
  10836. a = stack.pop();
  10837. stack.push(Math.sin(a));
  10838. break;
  10839. case 'sqrt':
  10840. a = stack.pop();
  10841. stack.push(Math.sqrt(a));
  10842. break;
  10843. case 'sub':
  10844. b = stack.pop();
  10845. a = stack.pop();
  10846. stack.push(a - b);
  10847. break;
  10848. case 'true':
  10849. stack.push(true);
  10850. break;
  10851. case 'truncate':
  10852. a = stack.pop();
  10853. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  10854. stack.push(a);
  10855. break;
  10856. case 'xor':
  10857. b = stack.pop();
  10858. a = stack.pop();
  10859. if (isBool(a) && isBool(b)) {
  10860. stack.push(a !== b);
  10861. } else {
  10862. stack.push(a ^ b);
  10863. }
  10864. break;
  10865. default:
  10866. error('Unknown operator ' + operator);
  10867. break;
  10868. }
  10869. }
  10870. return stack.stack;
  10871. }
  10872. };
  10873. return PostScriptEvaluator;
  10874. })();
  10875. // Most of the PDFs functions consist of simple operations such as:
  10876. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  10877. //
  10878. // We can compile most of such programs, and at the same moment, we can
  10879. // optimize some expressions using basic math properties. Keeping track of
  10880. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  10881. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  10882. function AstNode(type) {
  10883. this.type = type;
  10884. }
  10885. AstNode.prototype.visit = function (visitor) {
  10886. throw new Error('abstract method');
  10887. };
  10888. function AstArgument(index, min, max) {
  10889. AstNode.call(this, 'args');
  10890. this.index = index;
  10891. this.min = min;
  10892. this.max = max;
  10893. }
  10894. AstArgument.prototype = Object.create(AstNode.prototype);
  10895. AstArgument.prototype.visit = function (visitor) {
  10896. visitor.visitArgument(this);
  10897. };
  10898. function AstLiteral(number) {
  10899. AstNode.call(this, 'literal');
  10900. this.number = number;
  10901. this.min = number;
  10902. this.max = number;
  10903. }
  10904. AstLiteral.prototype = Object.create(AstNode.prototype);
  10905. AstLiteral.prototype.visit = function (visitor) {
  10906. visitor.visitLiteral(this);
  10907. };
  10908. function AstBinaryOperation(op, arg1, arg2, min, max) {
  10909. AstNode.call(this, 'binary');
  10910. this.op = op;
  10911. this.arg1 = arg1;
  10912. this.arg2 = arg2;
  10913. this.min = min;
  10914. this.max = max;
  10915. }
  10916. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  10917. AstBinaryOperation.prototype.visit = function (visitor) {
  10918. visitor.visitBinaryOperation(this);
  10919. };
  10920. function AstMin(arg, max) {
  10921. AstNode.call(this, 'max');
  10922. this.arg = arg;
  10923. this.min = arg.min;
  10924. this.max = max;
  10925. }
  10926. AstMin.prototype = Object.create(AstNode.prototype);
  10927. AstMin.prototype.visit = function (visitor) {
  10928. visitor.visitMin(this);
  10929. };
  10930. function AstVariable(index, min, max) {
  10931. AstNode.call(this, 'var');
  10932. this.index = index;
  10933. this.min = min;
  10934. this.max = max;
  10935. }
  10936. AstVariable.prototype = Object.create(AstNode.prototype);
  10937. AstVariable.prototype.visit = function (visitor) {
  10938. visitor.visitVariable(this);
  10939. };
  10940. function AstVariableDefinition(variable, arg) {
  10941. AstNode.call(this, 'definition');
  10942. this.variable = variable;
  10943. this.arg = arg;
  10944. }
  10945. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  10946. AstVariableDefinition.prototype.visit = function (visitor) {
  10947. visitor.visitVariableDefinition(this);
  10948. };
  10949. function ExpressionBuilderVisitor() {
  10950. this.parts = [];
  10951. }
  10952. ExpressionBuilderVisitor.prototype = {
  10953. visitArgument: function (arg) {
  10954. this.parts.push('Math.max(', arg.min, ', Math.min(',
  10955. arg.max, ', src[srcOffset + ', arg.index, ']))');
  10956. },
  10957. visitVariable: function (variable) {
  10958. this.parts.push('v', variable.index);
  10959. },
  10960. visitLiteral: function (literal) {
  10961. this.parts.push(literal.number);
  10962. },
  10963. visitBinaryOperation: function (operation) {
  10964. this.parts.push('(');
  10965. operation.arg1.visit(this);
  10966. this.parts.push(' ', operation.op, ' ');
  10967. operation.arg2.visit(this);
  10968. this.parts.push(')');
  10969. },
  10970. visitVariableDefinition: function (definition) {
  10971. this.parts.push('var ');
  10972. definition.variable.visit(this);
  10973. this.parts.push(' = ');
  10974. definition.arg.visit(this);
  10975. this.parts.push(';');
  10976. },
  10977. visitMin: function (max) {
  10978. this.parts.push('Math.min(');
  10979. max.arg.visit(this);
  10980. this.parts.push(', ', max.max, ')');
  10981. },
  10982. toString: function () {
  10983. return this.parts.join('');
  10984. }
  10985. };
  10986. function buildAddOperation(num1, num2) {
  10987. if (num2.type === 'literal' && num2.number === 0) {
  10988. // optimization: second operand is 0
  10989. return num1;
  10990. }
  10991. if (num1.type === 'literal' && num1.number === 0) {
  10992. // optimization: first operand is 0
  10993. return num2;
  10994. }
  10995. if (num2.type === 'literal' && num1.type === 'literal') {
  10996. // optimization: operands operand are literals
  10997. return new AstLiteral(num1.number + num2.number);
  10998. }
  10999. return new AstBinaryOperation('+', num1, num2,
  11000. num1.min + num2.min, num1.max + num2.max);
  11001. }
  11002. function buildMulOperation(num1, num2) {
  11003. if (num2.type === 'literal') {
  11004. // optimization: second operands is a literal...
  11005. if (num2.number === 0) {
  11006. return new AstLiteral(0); // and it's 0
  11007. } else if (num2.number === 1) {
  11008. return num1; // and it's 1
  11009. } else if (num1.type === 'literal') {
  11010. // ... and first operands is a literal too
  11011. return new AstLiteral(num1.number * num2.number);
  11012. }
  11013. }
  11014. if (num1.type === 'literal') {
  11015. // optimization: first operands is a literal...
  11016. if (num1.number === 0) {
  11017. return new AstLiteral(0); // and it's 0
  11018. } else if (num1.number === 1) {
  11019. return num2; // and it's 1
  11020. }
  11021. }
  11022. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11023. num1.max * num2.min, num1.max * num2.max);
  11024. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11025. num1.max * num2.min, num1.max * num2.max);
  11026. return new AstBinaryOperation('*', num1, num2, min, max);
  11027. }
  11028. function buildSubOperation(num1, num2) {
  11029. if (num2.type === 'literal') {
  11030. // optimization: second operands is a literal...
  11031. if (num2.number === 0) {
  11032. return num1; // ... and it's 0
  11033. } else if (num1.type === 'literal') {
  11034. // ... and first operands is a literal too
  11035. return new AstLiteral(num1.number - num2.number);
  11036. }
  11037. }
  11038. if (num2.type === 'binary' && num2.op === '-' &&
  11039. num1.type === 'literal' && num1.number === 1 &&
  11040. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11041. // optimization for case: 1 - (1 - x)
  11042. return num2.arg2;
  11043. }
  11044. return new AstBinaryOperation('-', num1, num2,
  11045. num1.min - num2.max, num1.max - num2.min);
  11046. }
  11047. function buildMinOperation(num1, max) {
  11048. if (num1.min >= max) {
  11049. // optimization: num1 min value is not less than required max
  11050. return new AstLiteral(max); // just returning max
  11051. } else if (num1.max <= max) {
  11052. // optimization: num1 max value is not greater than required max
  11053. return num1; // just returning an argument
  11054. }
  11055. return new AstMin(num1, max);
  11056. }
  11057. function PostScriptCompiler() {}
  11058. PostScriptCompiler.prototype = {
  11059. compile: function PostScriptCompiler_compile(code, domain, range) {
  11060. var stack = [];
  11061. var i, ii;
  11062. var instructions = [];
  11063. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11064. var lastRegister = 0;
  11065. var n, j, min, max;
  11066. var num1, num2, ast1, ast2, tmpVar, item;
  11067. for (i = 0; i < inputSize; i++) {
  11068. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11069. }
  11070. for (i = 0, ii = code.length; i < ii; i++) {
  11071. item = code[i];
  11072. if (typeof item === 'number') {
  11073. stack.push(new AstLiteral(item));
  11074. continue;
  11075. }
  11076. switch (item) {
  11077. case 'add':
  11078. if (stack.length < 2) {
  11079. return null;
  11080. }
  11081. num2 = stack.pop();
  11082. num1 = stack.pop();
  11083. stack.push(buildAddOperation(num1, num2));
  11084. break;
  11085. case 'cvr':
  11086. if (stack.length < 1) {
  11087. return null;
  11088. }
  11089. break;
  11090. case 'mul':
  11091. if (stack.length < 2) {
  11092. return null;
  11093. }
  11094. num2 = stack.pop();
  11095. num1 = stack.pop();
  11096. stack.push(buildMulOperation(num1, num2));
  11097. break;
  11098. case 'sub':
  11099. if (stack.length < 2) {
  11100. return null;
  11101. }
  11102. num2 = stack.pop();
  11103. num1 = stack.pop();
  11104. stack.push(buildSubOperation(num1, num2));
  11105. break;
  11106. case 'exch':
  11107. if (stack.length < 2) {
  11108. return null;
  11109. }
  11110. ast1 = stack.pop(); ast2 = stack.pop();
  11111. stack.push(ast1, ast2);
  11112. break;
  11113. case 'pop':
  11114. if (stack.length < 1) {
  11115. return null;
  11116. }
  11117. stack.pop();
  11118. break;
  11119. case 'index':
  11120. if (stack.length < 1) {
  11121. return null;
  11122. }
  11123. num1 = stack.pop();
  11124. if (num1.type !== 'literal') {
  11125. return null;
  11126. }
  11127. n = num1.number;
  11128. if (n < 0 || (n|0) !== n || stack.length < n) {
  11129. return null;
  11130. }
  11131. ast1 = stack[stack.length - n - 1];
  11132. if (ast1.type === 'literal' || ast1.type === 'var') {
  11133. stack.push(ast1);
  11134. break;
  11135. }
  11136. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11137. stack[stack.length - n - 1] = tmpVar;
  11138. stack.push(tmpVar);
  11139. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11140. break;
  11141. case 'dup':
  11142. if (stack.length < 1) {
  11143. return null;
  11144. }
  11145. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11146. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11147. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11148. // special case of the commands sequence for the min operation
  11149. num1 = stack.pop();
  11150. stack.push(buildMinOperation(num1, code[i + 1]));
  11151. i += 6;
  11152. break;
  11153. }
  11154. ast1 = stack[stack.length - 1];
  11155. if (ast1.type === 'literal' || ast1.type === 'var') {
  11156. // we don't have to save into intermediate variable a literal or
  11157. // variable.
  11158. stack.push(ast1);
  11159. break;
  11160. }
  11161. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11162. stack[stack.length - 1] = tmpVar;
  11163. stack.push(tmpVar);
  11164. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11165. break;
  11166. case 'roll':
  11167. if (stack.length < 2) {
  11168. return null;
  11169. }
  11170. num2 = stack.pop();
  11171. num1 = stack.pop();
  11172. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11173. // both roll operands must be numbers
  11174. return null;
  11175. }
  11176. j = num2.number;
  11177. n = num1.number;
  11178. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11179. // ... and integers
  11180. return null;
  11181. }
  11182. j = ((j % n) + n) % n;
  11183. if (j === 0) {
  11184. break; // just skipping -- there are nothing to rotate
  11185. }
  11186. Array.prototype.push.apply(stack,
  11187. stack.splice(stack.length - n, n - j));
  11188. break;
  11189. default:
  11190. return null; // unsupported operator
  11191. }
  11192. }
  11193. if (stack.length !== outputSize) {
  11194. return null;
  11195. }
  11196. var result = [];
  11197. instructions.forEach(function (instruction) {
  11198. var statementBuilder = new ExpressionBuilderVisitor();
  11199. instruction.visit(statementBuilder);
  11200. result.push(statementBuilder.toString());
  11201. });
  11202. stack.forEach(function (expr, i) {
  11203. var statementBuilder = new ExpressionBuilderVisitor();
  11204. expr.visit(statementBuilder);
  11205. var min = range[i * 2], max = range[i * 2 + 1];
  11206. var out = [statementBuilder.toString()];
  11207. if (min > expr.min) {
  11208. out.unshift('Math.max(', min, ', ');
  11209. out.push(')');
  11210. }
  11211. if (max < expr.max) {
  11212. out.unshift('Math.min(', max, ', ');
  11213. out.push(')');
  11214. }
  11215. out.unshift('dest[destOffset + ', i, '] = ');
  11216. out.push(';');
  11217. result.push(out.join(''));
  11218. });
  11219. return result.join('\n');
  11220. }
  11221. };
  11222. return PostScriptCompiler;
  11223. })();
  11224. var ColorSpace = (function ColorSpaceClosure() {
  11225. // Constructor should define this.numComps, this.defaultColor, this.name
  11226. function ColorSpace() {
  11227. error('should not call ColorSpace constructor');
  11228. }
  11229. ColorSpace.prototype = {
  11230. /**
  11231. * Converts the color value to the RGB color. The color components are
  11232. * located in the src array starting from the srcOffset. Returns the array
  11233. * of the rgb components, each value ranging from [0,255].
  11234. */
  11235. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11236. var rgb = new Uint8Array(3);
  11237. this.getRgbItem(src, srcOffset, rgb, 0);
  11238. return rgb;
  11239. },
  11240. /**
  11241. * Converts the color value to the RGB color, similar to the getRgb method.
  11242. * The result placed into the dest array starting from the destOffset.
  11243. */
  11244. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11245. dest, destOffset) {
  11246. error('Should not call ColorSpace.getRgbItem');
  11247. },
  11248. /**
  11249. * Converts the specified number of the color values to the RGB colors.
  11250. * The colors are located in the src array starting from the srcOffset.
  11251. * The result is placed into the dest array starting from the destOffset.
  11252. * The src array items shall be in [0,2^bits) range, the dest array items
  11253. * will be in [0,255] range. alpha01 indicates how many alpha components
  11254. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11255. * array).
  11256. */
  11257. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11258. dest, destOffset, bits,
  11259. alpha01) {
  11260. error('Should not call ColorSpace.getRgbBuffer');
  11261. },
  11262. /**
  11263. * Determines the number of bytes required to store the result of the
  11264. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11265. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11266. */
  11267. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11268. alpha01) {
  11269. error('Should not call ColorSpace.getOutputLength');
  11270. },
  11271. /**
  11272. * Returns true if source data will be equal the result/output data.
  11273. */
  11274. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11275. return false;
  11276. },
  11277. /**
  11278. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11279. * how many alpha components there are in the dest array; it will be either
  11280. * 0 (RGB array) or 1 (RGBA array).
  11281. */
  11282. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11283. originalHeight, width, height,
  11284. actualHeight, bpc, comps, alpha01) {
  11285. var count = originalWidth * originalHeight;
  11286. var rgbBuf = null;
  11287. var numComponentColors = 1 << bpc;
  11288. var needsResizing = originalHeight !== height || originalWidth !== width;
  11289. var i, ii;
  11290. if (this.isPassthrough(bpc)) {
  11291. rgbBuf = comps;
  11292. } else if (this.numComps === 1 && count > numComponentColors &&
  11293. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11294. // Optimization: create a color map when there is just one component and
  11295. // we are converting more colors than the size of the color map. We
  11296. // don't build the map if the colorspace is gray or rgb since those
  11297. // methods are faster than building a map. This mainly offers big speed
  11298. // ups for indexed and alternate colorspaces.
  11299. //
  11300. // TODO it may be worth while to cache the color map. While running
  11301. // testing I never hit a cache so I will leave that out for now (perhaps
  11302. // we are reparsing colorspaces too much?).
  11303. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11304. new Uint16Array(numComponentColors);
  11305. var key;
  11306. for (i = 0; i < numComponentColors; i++) {
  11307. allColors[i] = i;
  11308. }
  11309. var colorMap = new Uint8Array(numComponentColors * 3);
  11310. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11311. /* alpha01 = */ 0);
  11312. var destPos, rgbPos;
  11313. if (!needsResizing) {
  11314. // Fill in the RGB values directly into |dest|.
  11315. destPos = 0;
  11316. for (i = 0; i < count; ++i) {
  11317. key = comps[i] * 3;
  11318. dest[destPos++] = colorMap[key];
  11319. dest[destPos++] = colorMap[key + 1];
  11320. dest[destPos++] = colorMap[key + 2];
  11321. destPos += alpha01;
  11322. }
  11323. } else {
  11324. rgbBuf = new Uint8Array(count * 3);
  11325. rgbPos = 0;
  11326. for (i = 0; i < count; ++i) {
  11327. key = comps[i] * 3;
  11328. rgbBuf[rgbPos++] = colorMap[key];
  11329. rgbBuf[rgbPos++] = colorMap[key + 1];
  11330. rgbBuf[rgbPos++] = colorMap[key + 2];
  11331. }
  11332. }
  11333. } else {
  11334. if (!needsResizing) {
  11335. // Fill in the RGB values directly into |dest|.
  11336. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11337. alpha01);
  11338. } else {
  11339. rgbBuf = new Uint8Array(count * 3);
  11340. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11341. /* alpha01 = */ 0);
  11342. }
  11343. }
  11344. if (rgbBuf) {
  11345. if (needsResizing) {
  11346. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11347. height, dest, alpha01);
  11348. } else {
  11349. rgbPos = 0;
  11350. destPos = 0;
  11351. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11352. dest[destPos++] = rgbBuf[rgbPos++];
  11353. dest[destPos++] = rgbBuf[rgbPos++];
  11354. dest[destPos++] = rgbBuf[rgbPos++];
  11355. destPos += alpha01;
  11356. }
  11357. }
  11358. }
  11359. },
  11360. /**
  11361. * True if the colorspace has components in the default range of [0, 1].
  11362. * This should be true for all colorspaces except for lab color spaces
  11363. * which are [0,100], [-128, 127], [-128, 127].
  11364. */
  11365. usesZeroToOneRange: true
  11366. };
  11367. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11368. var IR = ColorSpace.parseToIR(cs, xref, res);
  11369. if (IR instanceof AlternateCS) {
  11370. return IR;
  11371. }
  11372. return ColorSpace.fromIR(IR);
  11373. };
  11374. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11375. var name = isArray(IR) ? IR[0] : IR;
  11376. var whitePoint, blackPoint, gamma;
  11377. switch (name) {
  11378. case 'DeviceGrayCS':
  11379. return this.singletons.gray;
  11380. case 'DeviceRgbCS':
  11381. return this.singletons.rgb;
  11382. case 'DeviceCmykCS':
  11383. return this.singletons.cmyk;
  11384. case 'CalGrayCS':
  11385. whitePoint = IR[1].WhitePoint;
  11386. blackPoint = IR[1].BlackPoint;
  11387. gamma = IR[1].Gamma;
  11388. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11389. case 'CalRGBCS':
  11390. whitePoint = IR[1].WhitePoint;
  11391. blackPoint = IR[1].BlackPoint;
  11392. gamma = IR[1].Gamma;
  11393. var matrix = IR[1].Matrix;
  11394. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11395. case 'PatternCS':
  11396. var basePatternCS = IR[1];
  11397. if (basePatternCS) {
  11398. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11399. }
  11400. return new PatternCS(basePatternCS);
  11401. case 'IndexedCS':
  11402. var baseIndexedCS = IR[1];
  11403. var hiVal = IR[2];
  11404. var lookup = IR[3];
  11405. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11406. case 'AlternateCS':
  11407. var numComps = IR[1];
  11408. var alt = IR[2];
  11409. var tintFnIR = IR[3];
  11410. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11411. PDFFunction.fromIR(tintFnIR));
  11412. case 'LabCS':
  11413. whitePoint = IR[1].WhitePoint;
  11414. blackPoint = IR[1].BlackPoint;
  11415. var range = IR[1].Range;
  11416. return new LabCS(whitePoint, blackPoint, range);
  11417. default:
  11418. error('Unknown name ' + name);
  11419. }
  11420. return null;
  11421. };
  11422. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11423. if (isName(cs)) {
  11424. var colorSpaces = res.get('ColorSpace');
  11425. if (isDict(colorSpaces)) {
  11426. var refcs = colorSpaces.get(cs.name);
  11427. if (refcs) {
  11428. cs = refcs;
  11429. }
  11430. }
  11431. }
  11432. cs = xref.fetchIfRef(cs);
  11433. var mode;
  11434. if (isName(cs)) {
  11435. mode = cs.name;
  11436. this.mode = mode;
  11437. switch (mode) {
  11438. case 'DeviceGray':
  11439. case 'G':
  11440. return 'DeviceGrayCS';
  11441. case 'DeviceRGB':
  11442. case 'RGB':
  11443. return 'DeviceRgbCS';
  11444. case 'DeviceCMYK':
  11445. case 'CMYK':
  11446. return 'DeviceCmykCS';
  11447. case 'Pattern':
  11448. return ['PatternCS', null];
  11449. default:
  11450. error('unrecognized colorspace ' + mode);
  11451. }
  11452. } else if (isArray(cs)) {
  11453. mode = cs[0].name;
  11454. this.mode = mode;
  11455. var numComps, params;
  11456. switch (mode) {
  11457. case 'DeviceGray':
  11458. case 'G':
  11459. return 'DeviceGrayCS';
  11460. case 'DeviceRGB':
  11461. case 'RGB':
  11462. return 'DeviceRgbCS';
  11463. case 'DeviceCMYK':
  11464. case 'CMYK':
  11465. return 'DeviceCmykCS';
  11466. case 'CalGray':
  11467. params = cs[1].getAll();
  11468. return ['CalGrayCS', params];
  11469. case 'CalRGB':
  11470. params = cs[1].getAll();
  11471. return ['CalRGBCS', params];
  11472. case 'ICCBased':
  11473. var stream = xref.fetchIfRef(cs[1]);
  11474. var dict = stream.dict;
  11475. numComps = dict.get('N');
  11476. if (numComps === 1) {
  11477. return 'DeviceGrayCS';
  11478. } else if (numComps === 3) {
  11479. return 'DeviceRgbCS';
  11480. } else if (numComps === 4) {
  11481. return 'DeviceCmykCS';
  11482. }
  11483. break;
  11484. case 'Pattern':
  11485. var basePatternCS = cs[1];
  11486. if (basePatternCS) {
  11487. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11488. }
  11489. return ['PatternCS', basePatternCS];
  11490. case 'Indexed':
  11491. case 'I':
  11492. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11493. var hiVal = cs[2] + 1;
  11494. var lookup = xref.fetchIfRef(cs[3]);
  11495. if (isStream(lookup)) {
  11496. lookup = lookup.getBytes();
  11497. }
  11498. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11499. case 'Separation':
  11500. case 'DeviceN':
  11501. var name = cs[1];
  11502. numComps = 1;
  11503. if (isName(name)) {
  11504. numComps = 1;
  11505. } else if (isArray(name)) {
  11506. numComps = name.length;
  11507. }
  11508. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11509. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11510. return ['AlternateCS', numComps, alt, tintFnIR];
  11511. case 'Lab':
  11512. params = cs[1].getAll();
  11513. return ['LabCS', params];
  11514. default:
  11515. error('unimplemented color space object "' + mode + '"');
  11516. }
  11517. } else {
  11518. error('unrecognized color space object: "' + cs + '"');
  11519. }
  11520. return null;
  11521. };
  11522. /**
  11523. * Checks if a decode map matches the default decode map for a color space.
  11524. * This handles the general decode maps where there are two values per
  11525. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11526. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11527. * slightly different.
  11528. * @param {Array} decode Decode map (usually from an image).
  11529. * @param {Number} n Number of components the color space has.
  11530. */
  11531. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11532. if (!decode) {
  11533. return true;
  11534. }
  11535. if (n * 2 !== decode.length) {
  11536. warn('The decode map is not the correct length');
  11537. return true;
  11538. }
  11539. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11540. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11541. return false;
  11542. }
  11543. }
  11544. return true;
  11545. };
  11546. ColorSpace.singletons = {
  11547. get gray() {
  11548. return shadow(this, 'gray', new DeviceGrayCS());
  11549. },
  11550. get rgb() {
  11551. return shadow(this, 'rgb', new DeviceRgbCS());
  11552. },
  11553. get cmyk() {
  11554. return shadow(this, 'cmyk', new DeviceCmykCS());
  11555. }
  11556. };
  11557. return ColorSpace;
  11558. })();
  11559. /**
  11560. * Alternate color space handles both Separation and DeviceN color spaces. A
  11561. * Separation color space is actually just a DeviceN with one color component.
  11562. * Both color spaces use a tinting function to convert colors to a base color
  11563. * space.
  11564. */
  11565. var AlternateCS = (function AlternateCSClosure() {
  11566. function AlternateCS(numComps, base, tintFn) {
  11567. this.name = 'Alternate';
  11568. this.numComps = numComps;
  11569. this.defaultColor = new Float32Array(numComps);
  11570. for (var i = 0; i < numComps; ++i) {
  11571. this.defaultColor[i] = 1;
  11572. }
  11573. this.base = base;
  11574. this.tintFn = tintFn;
  11575. this.tmpBuf = new Float32Array(base.numComps);
  11576. }
  11577. AlternateCS.prototype = {
  11578. getRgb: ColorSpace.prototype.getRgb,
  11579. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11580. dest, destOffset) {
  11581. var tmpBuf = this.tmpBuf;
  11582. this.tintFn(src, srcOffset, tmpBuf, 0);
  11583. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11584. },
  11585. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11586. dest, destOffset, bits,
  11587. alpha01) {
  11588. var tintFn = this.tintFn;
  11589. var base = this.base;
  11590. var scale = 1 / ((1 << bits) - 1);
  11591. var baseNumComps = base.numComps;
  11592. var usesZeroToOneRange = base.usesZeroToOneRange;
  11593. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11594. alpha01 === 0;
  11595. var pos = isPassthrough ? destOffset : 0;
  11596. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11597. var numComps = this.numComps;
  11598. var scaled = new Float32Array(numComps);
  11599. var tinted = new Float32Array(baseNumComps);
  11600. var i, j;
  11601. if (usesZeroToOneRange) {
  11602. for (i = 0; i < count; i++) {
  11603. for (j = 0; j < numComps; j++) {
  11604. scaled[j] = src[srcOffset++] * scale;
  11605. }
  11606. tintFn(scaled, 0, tinted, 0);
  11607. for (j = 0; j < baseNumComps; j++) {
  11608. baseBuf[pos++] = tinted[j] * 255;
  11609. }
  11610. }
  11611. } else {
  11612. for (i = 0; i < count; i++) {
  11613. for (j = 0; j < numComps; j++) {
  11614. scaled[j] = src[srcOffset++] * scale;
  11615. }
  11616. tintFn(scaled, 0, tinted, 0);
  11617. base.getRgbItem(tinted, 0, baseBuf, pos);
  11618. pos += baseNumComps;
  11619. }
  11620. }
  11621. if (!isPassthrough) {
  11622. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11623. }
  11624. },
  11625. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11626. alpha01) {
  11627. return this.base.getOutputLength(inputLength *
  11628. this.base.numComps / this.numComps,
  11629. alpha01);
  11630. },
  11631. isPassthrough: ColorSpace.prototype.isPassthrough,
  11632. fillRgb: ColorSpace.prototype.fillRgb,
  11633. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11634. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11635. },
  11636. usesZeroToOneRange: true
  11637. };
  11638. return AlternateCS;
  11639. })();
  11640. var PatternCS = (function PatternCSClosure() {
  11641. function PatternCS(baseCS) {
  11642. this.name = 'Pattern';
  11643. this.base = baseCS;
  11644. }
  11645. PatternCS.prototype = {};
  11646. return PatternCS;
  11647. })();
  11648. var IndexedCS = (function IndexedCSClosure() {
  11649. function IndexedCS(base, highVal, lookup) {
  11650. this.name = 'Indexed';
  11651. this.numComps = 1;
  11652. this.defaultColor = new Uint8Array([0]);
  11653. this.base = base;
  11654. this.highVal = highVal;
  11655. var baseNumComps = base.numComps;
  11656. var length = baseNumComps * highVal;
  11657. var lookupArray;
  11658. if (isStream(lookup)) {
  11659. lookupArray = new Uint8Array(length);
  11660. var bytes = lookup.getBytes(length);
  11661. lookupArray.set(bytes);
  11662. } else if (isString(lookup)) {
  11663. lookupArray = new Uint8Array(length);
  11664. for (var i = 0; i < length; ++i) {
  11665. lookupArray[i] = lookup.charCodeAt(i);
  11666. }
  11667. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11668. lookupArray = lookup;
  11669. } else {
  11670. error('Unrecognized lookup table: ' + lookup);
  11671. }
  11672. this.lookup = lookupArray;
  11673. }
  11674. IndexedCS.prototype = {
  11675. getRgb: ColorSpace.prototype.getRgb,
  11676. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11677. dest, destOffset) {
  11678. var numComps = this.base.numComps;
  11679. var start = src[srcOffset] * numComps;
  11680. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11681. },
  11682. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11683. dest, destOffset, bits,
  11684. alpha01) {
  11685. var base = this.base;
  11686. var numComps = base.numComps;
  11687. var outputDelta = base.getOutputLength(numComps, alpha01);
  11688. var lookup = this.lookup;
  11689. for (var i = 0; i < count; ++i) {
  11690. var lookupPos = src[srcOffset++] * numComps;
  11691. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11692. destOffset += outputDelta;
  11693. }
  11694. },
  11695. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11696. return this.base.getOutputLength(inputLength * this.base.numComps,
  11697. alpha01);
  11698. },
  11699. isPassthrough: ColorSpace.prototype.isPassthrough,
  11700. fillRgb: ColorSpace.prototype.fillRgb,
  11701. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11702. // indexed color maps shouldn't be changed
  11703. return true;
  11704. },
  11705. usesZeroToOneRange: true
  11706. };
  11707. return IndexedCS;
  11708. })();
  11709. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11710. function DeviceGrayCS() {
  11711. this.name = 'DeviceGray';
  11712. this.numComps = 1;
  11713. this.defaultColor = new Float32Array([0]);
  11714. }
  11715. DeviceGrayCS.prototype = {
  11716. getRgb: ColorSpace.prototype.getRgb,
  11717. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11718. dest, destOffset) {
  11719. var c = (src[srcOffset] * 255) | 0;
  11720. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11721. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11722. },
  11723. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11724. dest, destOffset, bits,
  11725. alpha01) {
  11726. var scale = 255 / ((1 << bits) - 1);
  11727. var j = srcOffset, q = destOffset;
  11728. for (var i = 0; i < count; ++i) {
  11729. var c = (scale * src[j++]) | 0;
  11730. dest[q++] = c;
  11731. dest[q++] = c;
  11732. dest[q++] = c;
  11733. q += alpha01;
  11734. }
  11735. },
  11736. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11737. alpha01) {
  11738. return inputLength * (3 + alpha01);
  11739. },
  11740. isPassthrough: ColorSpace.prototype.isPassthrough,
  11741. fillRgb: ColorSpace.prototype.fillRgb,
  11742. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11743. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11744. },
  11745. usesZeroToOneRange: true
  11746. };
  11747. return DeviceGrayCS;
  11748. })();
  11749. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11750. function DeviceRgbCS() {
  11751. this.name = 'DeviceRGB';
  11752. this.numComps = 3;
  11753. this.defaultColor = new Float32Array([0, 0, 0]);
  11754. }
  11755. DeviceRgbCS.prototype = {
  11756. getRgb: ColorSpace.prototype.getRgb,
  11757. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11758. dest, destOffset) {
  11759. var r = (src[srcOffset] * 255) | 0;
  11760. var g = (src[srcOffset + 1] * 255) | 0;
  11761. var b = (src[srcOffset + 2] * 255) | 0;
  11762. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11763. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11764. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11765. },
  11766. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11767. dest, destOffset, bits,
  11768. alpha01) {
  11769. if (bits === 8 && alpha01 === 0) {
  11770. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11771. return;
  11772. }
  11773. var scale = 255 / ((1 << bits) - 1);
  11774. var j = srcOffset, q = destOffset;
  11775. for (var i = 0; i < count; ++i) {
  11776. dest[q++] = (scale * src[j++]) | 0;
  11777. dest[q++] = (scale * src[j++]) | 0;
  11778. dest[q++] = (scale * src[j++]) | 0;
  11779. q += alpha01;
  11780. }
  11781. },
  11782. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  11783. alpha01) {
  11784. return (inputLength * (3 + alpha01) / 3) | 0;
  11785. },
  11786. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  11787. return bits === 8;
  11788. },
  11789. fillRgb: ColorSpace.prototype.fillRgb,
  11790. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  11791. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11792. },
  11793. usesZeroToOneRange: true
  11794. };
  11795. return DeviceRgbCS;
  11796. })();
  11797. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  11798. // The coefficients below was found using numerical analysis: the method of
  11799. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  11800. // where color_value is the tabular value from the table of sampled RGB colors
  11801. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  11802. // CMYK color conversion using the estimation below:
  11803. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  11804. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  11805. var c = src[srcOffset + 0] * srcScale;
  11806. var m = src[srcOffset + 1] * srcScale;
  11807. var y = src[srcOffset + 2] * srcScale;
  11808. var k = src[srcOffset + 3] * srcScale;
  11809. var r =
  11810. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11811. 18.82290502165302 * y + 212.25662451639585 * k +
  11812. -285.2331026137004) +
  11813. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  11814. -17.873870861415444 * k - 5.497006427196366) +
  11815. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11816. 17.5119270841813) +
  11817. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  11818. var g =
  11819. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  11820. 6.871425592049007 * y + 31.159100130055922 * k +
  11821. -79.2970844816548) +
  11822. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11823. 131.35250912493976 * k - 190.9453302588951) +
  11824. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  11825. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  11826. var b =
  11827. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11828. 30.89978309703729 * y - 0.23883238689178934 * k +
  11829. -14.183576799673286) +
  11830. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11831. 50.606957656360734 * k - 112.23884253719248) +
  11832. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  11833. -193.58209356861505) +
  11834. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  11835. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  11836. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  11837. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  11838. }
  11839. function DeviceCmykCS() {
  11840. this.name = 'DeviceCMYK';
  11841. this.numComps = 4;
  11842. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  11843. }
  11844. DeviceCmykCS.prototype = {
  11845. getRgb: ColorSpace.prototype.getRgb,
  11846. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  11847. dest, destOffset) {
  11848. convertToRgb(src, srcOffset, 1, dest, destOffset);
  11849. },
  11850. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  11851. dest, destOffset, bits,
  11852. alpha01) {
  11853. var scale = 1 / ((1 << bits) - 1);
  11854. for (var i = 0; i < count; i++) {
  11855. convertToRgb(src, srcOffset, scale, dest, destOffset);
  11856. srcOffset += 4;
  11857. destOffset += 3 + alpha01;
  11858. }
  11859. },
  11860. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  11861. alpha01) {
  11862. return (inputLength / 4 * (3 + alpha01)) | 0;
  11863. },
  11864. isPassthrough: ColorSpace.prototype.isPassthrough,
  11865. fillRgb: ColorSpace.prototype.fillRgb,
  11866. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  11867. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11868. },
  11869. usesZeroToOneRange: true
  11870. };
  11871. return DeviceCmykCS;
  11872. })();
  11873. //
  11874. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  11875. //
  11876. var CalGrayCS = (function CalGrayCSClosure() {
  11877. function CalGrayCS(whitePoint, blackPoint, gamma) {
  11878. this.name = 'CalGray';
  11879. this.numComps = 1;
  11880. this.defaultColor = new Float32Array([0]);
  11881. if (!whitePoint) {
  11882. error('WhitePoint missing - required for color space CalGray');
  11883. }
  11884. blackPoint = blackPoint || [0, 0, 0];
  11885. gamma = gamma || 1;
  11886. // Translate arguments to spec variables.
  11887. this.XW = whitePoint[0];
  11888. this.YW = whitePoint[1];
  11889. this.ZW = whitePoint[2];
  11890. this.XB = blackPoint[0];
  11891. this.YB = blackPoint[1];
  11892. this.ZB = blackPoint[2];
  11893. this.G = gamma;
  11894. // Validate variables as per spec.
  11895. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  11896. error('Invalid WhitePoint components for ' + this.name +
  11897. ', no fallback available');
  11898. }
  11899. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  11900. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  11901. this.XB = this.YB = this.ZB = 0;
  11902. }
  11903. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  11904. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  11905. ', ZB: ' + this.ZB + ', only default values are supported.');
  11906. }
  11907. if (this.G < 1) {
  11908. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  11909. ', falling back to default');
  11910. this.G = 1;
  11911. }
  11912. }
  11913. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  11914. // A represents a gray component of a calibrated gray space.
  11915. // A <---> AG in the spec
  11916. var A = src[srcOffset] * scale;
  11917. var AG = Math.pow(A, cs.G);
  11918. // Computes L as per spec. ( = cs.YW * AG )
  11919. // Except if other than default BlackPoint values are used.
  11920. var L = cs.YW * AG;
  11921. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  11922. // Convert values to rgb range [0, 255].
  11923. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  11924. dest[destOffset] = val;
  11925. dest[destOffset + 1] = val;
  11926. dest[destOffset + 2] = val;
  11927. }
  11928. CalGrayCS.prototype = {
  11929. getRgb: ColorSpace.prototype.getRgb,
  11930. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  11931. dest, destOffset) {
  11932. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  11933. },
  11934. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  11935. dest, destOffset, bits,
  11936. alpha01) {
  11937. var scale = 1 / ((1 << bits) - 1);
  11938. for (var i = 0; i < count; ++i) {
  11939. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  11940. srcOffset += 1;
  11941. destOffset += 3 + alpha01;
  11942. }
  11943. },
  11944. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  11945. return inputLength * (3 + alpha01);
  11946. },
  11947. isPassthrough: ColorSpace.prototype.isPassthrough,
  11948. fillRgb: ColorSpace.prototype.fillRgb,
  11949. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  11950. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11951. },
  11952. usesZeroToOneRange: true
  11953. };
  11954. return CalGrayCS;
  11955. })();
  11956. //
  11957. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  11958. //
  11959. var CalRGBCS = (function CalRGBCSClosure() {
  11960. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  11961. // matrices.
  11962. var BRADFORD_SCALE_MATRIX = new Float32Array([
  11963. 0.8951, 0.2664, -0.1614,
  11964. -0.7502, 1.7135, 0.0367,
  11965. 0.0389, -0.0685, 1.0296]);
  11966. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  11967. 0.9869929, -0.1470543, 0.1599627,
  11968. 0.4323053, 0.5183603, 0.0492912,
  11969. -0.0085287, 0.0400428, 0.9684867]);
  11970. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  11971. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  11972. 3.2404542, -1.5371385, -0.4985314,
  11973. -0.9692660, 1.8760108, 0.0415560,
  11974. 0.0556434, -0.2040259, 1.0572252]);
  11975. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  11976. var tempNormalizeMatrix = new Float32Array(3);
  11977. var tempConvertMatrix1 = new Float32Array(3);
  11978. var tempConvertMatrix2 = new Float32Array(3);
  11979. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  11980. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  11981. this.name = 'CalRGB';
  11982. this.numComps = 3;
  11983. this.defaultColor = new Float32Array(3);
  11984. if (!whitePoint) {
  11985. error('WhitePoint missing - required for color space CalRGB');
  11986. }
  11987. blackPoint = blackPoint || new Float32Array(3);
  11988. gamma = gamma || new Float32Array([1, 1, 1]);
  11989. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  11990. // Translate arguments to spec variables.
  11991. var XW = whitePoint[0];
  11992. var YW = whitePoint[1];
  11993. var ZW = whitePoint[2];
  11994. this.whitePoint = whitePoint;
  11995. var XB = blackPoint[0];
  11996. var YB = blackPoint[1];
  11997. var ZB = blackPoint[2];
  11998. this.blackPoint = blackPoint;
  11999. this.GR = gamma[0];
  12000. this.GG = gamma[1];
  12001. this.GB = gamma[2];
  12002. this.MXA = matrix[0];
  12003. this.MYA = matrix[1];
  12004. this.MZA = matrix[2];
  12005. this.MXB = matrix[3];
  12006. this.MYB = matrix[4];
  12007. this.MZB = matrix[5];
  12008. this.MXC = matrix[6];
  12009. this.MYC = matrix[7];
  12010. this.MZC = matrix[8];
  12011. // Validate variables as per spec.
  12012. if (XW < 0 || ZW < 0 || YW !== 1) {
  12013. error('Invalid WhitePoint components for ' + this.name +
  12014. ', no fallback available');
  12015. }
  12016. if (XB < 0 || YB < 0 || ZB < 0) {
  12017. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12018. ', ' + ZB + '], falling back to default');
  12019. this.blackPoint = new Float32Array(3);
  12020. }
  12021. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12022. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12023. '] for ' + this.name + ', falling back to default');
  12024. this.GR = this.GG = this.GB = 1;
  12025. }
  12026. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12027. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12028. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12029. info('Invalid Matrix for ' + this.name + ' [' +
  12030. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12031. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12032. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12033. '], falling back to default');
  12034. this.MXA = this.MYB = this.MZC = 1;
  12035. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12036. }
  12037. }
  12038. function matrixProduct(a, b, result) {
  12039. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12040. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12041. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12042. }
  12043. function convertToFlat(sourceWhitePoint, LMS, result) {
  12044. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12045. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12046. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12047. }
  12048. function convertToD65(sourceWhitePoint, LMS, result) {
  12049. var D65X = 0.95047;
  12050. var D65Y = 1;
  12051. var D65Z = 1.08883;
  12052. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12053. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12054. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12055. }
  12056. function sRGBTransferFunction(color) {
  12057. // See http://en.wikipedia.org/wiki/SRGB.
  12058. if (color <= 0.0031308){
  12059. return adjustToRange(0, 1, 12.92 * color);
  12060. }
  12061. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12062. }
  12063. function adjustToRange(min, max, value) {
  12064. return Math.max(min, Math.min(max, value));
  12065. }
  12066. function decodeL(L) {
  12067. if (L < 0) {
  12068. return -decodeL(-L);
  12069. }
  12070. if (L > 8.0) {
  12071. return Math.pow(((L + 16) / 116), 3);
  12072. }
  12073. return L * DECODE_L_CONSTANT;
  12074. }
  12075. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12076. // In case the blackPoint is already the default blackPoint then there is
  12077. // no need to do compensation.
  12078. if (sourceBlackPoint[0] === 0 &&
  12079. sourceBlackPoint[1] === 0 &&
  12080. sourceBlackPoint[2] === 0) {
  12081. result[0] = XYZ_Flat[0];
  12082. result[1] = XYZ_Flat[1];
  12083. result[2] = XYZ_Flat[2];
  12084. return;
  12085. }
  12086. // For the blackPoint calculation details, please see
  12087. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12088. // AdobeBPC.pdf.
  12089. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12090. var zeroDecodeL = decodeL(0);
  12091. var X_DST = zeroDecodeL;
  12092. var X_SRC = decodeL(sourceBlackPoint[0]);
  12093. var Y_DST = zeroDecodeL;
  12094. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12095. var Z_DST = zeroDecodeL;
  12096. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12097. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12098. var X_Offset = 1 - X_Scale;
  12099. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12100. var Y_Offset = 1 - Y_Scale;
  12101. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12102. var Z_Offset = 1 - Z_Scale;
  12103. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12104. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12105. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12106. }
  12107. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12108. // In case the whitePoint is already flat then there is no need to do
  12109. // normalization.
  12110. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12111. result[0] = XYZ_In[0];
  12112. result[1] = XYZ_In[1];
  12113. result[2] = XYZ_In[2];
  12114. return;
  12115. }
  12116. var LMS = result;
  12117. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12118. var LMS_Flat = tempNormalizeMatrix;
  12119. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12120. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12121. }
  12122. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12123. var LMS = result;
  12124. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12125. var LMS_D65 = tempNormalizeMatrix;
  12126. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12127. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12128. }
  12129. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12130. // A, B and C represent a red, green and blue components of a calibrated
  12131. // rgb space.
  12132. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12133. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12134. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12135. // A <---> AGR in the spec
  12136. // B <---> BGG in the spec
  12137. // C <---> CGB in the spec
  12138. var AGR = Math.pow(A, cs.GR);
  12139. var BGG = Math.pow(B, cs.GG);
  12140. var CGB = Math.pow(C, cs.GB);
  12141. // Computes intermediate variables L, M, N as per spec.
  12142. // To decode X, Y, Z values map L, M, N directly to them.
  12143. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12144. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12145. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12146. // The following calculations are based on this document:
  12147. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12148. // AdobeBPC.pdf.
  12149. var XYZ = tempConvertMatrix1;
  12150. XYZ[0] = X;
  12151. XYZ[1] = Y;
  12152. XYZ[2] = Z;
  12153. var XYZ_Flat = tempConvertMatrix2;
  12154. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12155. var XYZ_Black = tempConvertMatrix1;
  12156. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12157. var XYZ_D65 = tempConvertMatrix2;
  12158. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12159. var SRGB = tempConvertMatrix1;
  12160. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12161. var sR = sRGBTransferFunction(SRGB[0]);
  12162. var sG = sRGBTransferFunction(SRGB[1]);
  12163. var sB = sRGBTransferFunction(SRGB[2]);
  12164. // Convert the values to rgb range [0, 255].
  12165. dest[destOffset] = Math.round(sR * 255);
  12166. dest[destOffset + 1] = Math.round(sG * 255);
  12167. dest[destOffset + 2] = Math.round(sB * 255);
  12168. }
  12169. CalRGBCS.prototype = {
  12170. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12171. var rgb = new Uint8Array(3);
  12172. this.getRgbItem(src, srcOffset, rgb, 0);
  12173. return rgb;
  12174. },
  12175. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12176. dest, destOffset) {
  12177. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12178. },
  12179. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12180. dest, destOffset, bits,
  12181. alpha01) {
  12182. var scale = 1 / ((1 << bits) - 1);
  12183. for (var i = 0; i < count; ++i) {
  12184. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12185. srcOffset += 3;
  12186. destOffset += 3 + alpha01;
  12187. }
  12188. },
  12189. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12190. return (inputLength * (3 + alpha01) / 3) | 0;
  12191. },
  12192. isPassthrough: ColorSpace.prototype.isPassthrough,
  12193. fillRgb: ColorSpace.prototype.fillRgb,
  12194. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12195. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12196. },
  12197. usesZeroToOneRange: true
  12198. };
  12199. return CalRGBCS;
  12200. })();
  12201. //
  12202. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12203. //
  12204. var LabCS = (function LabCSClosure() {
  12205. function LabCS(whitePoint, blackPoint, range) {
  12206. this.name = 'Lab';
  12207. this.numComps = 3;
  12208. this.defaultColor = new Float32Array([0, 0, 0]);
  12209. if (!whitePoint) {
  12210. error('WhitePoint missing - required for color space Lab');
  12211. }
  12212. blackPoint = blackPoint || [0, 0, 0];
  12213. range = range || [-100, 100, -100, 100];
  12214. // Translate args to spec variables
  12215. this.XW = whitePoint[0];
  12216. this.YW = whitePoint[1];
  12217. this.ZW = whitePoint[2];
  12218. this.amin = range[0];
  12219. this.amax = range[1];
  12220. this.bmin = range[2];
  12221. this.bmax = range[3];
  12222. // These are here just for completeness - the spec doesn't offer any
  12223. // formulas that use BlackPoint in Lab
  12224. this.XB = blackPoint[0];
  12225. this.YB = blackPoint[1];
  12226. this.ZB = blackPoint[2];
  12227. // Validate vars as per spec
  12228. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12229. error('Invalid WhitePoint components, no fallback available');
  12230. }
  12231. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12232. info('Invalid BlackPoint, falling back to default');
  12233. this.XB = this.YB = this.ZB = 0;
  12234. }
  12235. if (this.amin > this.amax || this.bmin > this.bmax) {
  12236. info('Invalid Range, falling back to defaults');
  12237. this.amin = -100;
  12238. this.amax = 100;
  12239. this.bmin = -100;
  12240. this.bmax = 100;
  12241. }
  12242. }
  12243. // Function g(x) from spec
  12244. function fn_g(x) {
  12245. if (x >= 6 / 29) {
  12246. return x * x * x;
  12247. } else {
  12248. return (108 / 841) * (x - 4 / 29);
  12249. }
  12250. }
  12251. function decode(value, high1, low2, high2) {
  12252. return low2 + (value) * (high2 - low2) / (high1);
  12253. }
  12254. // If decoding is needed maxVal should be 2^bits per component - 1.
  12255. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12256. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12257. // not the usual [0, 1]. If a command like setFillColor is used the src
  12258. // values will already be within the correct range. However, if we are
  12259. // converting an image we have to map the values to the correct range given
  12260. // above.
  12261. // Ls,as,bs <---> L*,a*,b* in the spec
  12262. var Ls = src[srcOffset];
  12263. var as = src[srcOffset + 1];
  12264. var bs = src[srcOffset + 2];
  12265. if (maxVal !== false) {
  12266. Ls = decode(Ls, maxVal, 0, 100);
  12267. as = decode(as, maxVal, cs.amin, cs.amax);
  12268. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12269. }
  12270. // Adjust limits of 'as' and 'bs'
  12271. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12272. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12273. // Computes intermediate variables X,Y,Z as per spec
  12274. var M = (Ls + 16) / 116;
  12275. var L = M + (as / 500);
  12276. var N = M - (bs / 200);
  12277. var X = cs.XW * fn_g(L);
  12278. var Y = cs.YW * fn_g(M);
  12279. var Z = cs.ZW * fn_g(N);
  12280. var r, g, b;
  12281. // Using different conversions for D50 and D65 white points,
  12282. // per http://www.color.org/srgb.pdf
  12283. if (cs.ZW < 1) {
  12284. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12285. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12286. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12287. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12288. } else {
  12289. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12290. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12291. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12292. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12293. }
  12294. // clamp color values to [0,1] range then convert to [0,255] range.
  12295. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12296. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12297. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12298. }
  12299. LabCS.prototype = {
  12300. getRgb: ColorSpace.prototype.getRgb,
  12301. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12302. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12303. },
  12304. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12305. dest, destOffset, bits,
  12306. alpha01) {
  12307. var maxVal = (1 << bits) - 1;
  12308. for (var i = 0; i < count; i++) {
  12309. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12310. srcOffset += 3;
  12311. destOffset += 3 + alpha01;
  12312. }
  12313. },
  12314. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12315. return (inputLength * (3 + alpha01) / 3) | 0;
  12316. },
  12317. isPassthrough: ColorSpace.prototype.isPassthrough,
  12318. fillRgb: ColorSpace.prototype.fillRgb,
  12319. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12320. // XXX: Decoding is handled with the lab conversion because of the strange
  12321. // ranges that are used.
  12322. return true;
  12323. },
  12324. usesZeroToOneRange: false
  12325. };
  12326. return LabCS;
  12327. })();
  12328. var ARCFourCipher = (function ARCFourCipherClosure() {
  12329. function ARCFourCipher(key) {
  12330. this.a = 0;
  12331. this.b = 0;
  12332. var s = new Uint8Array(256);
  12333. var i, j = 0, tmp, keyLength = key.length;
  12334. for (i = 0; i < 256; ++i) {
  12335. s[i] = i;
  12336. }
  12337. for (i = 0; i < 256; ++i) {
  12338. tmp = s[i];
  12339. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12340. s[i] = s[j];
  12341. s[j] = tmp;
  12342. }
  12343. this.s = s;
  12344. }
  12345. ARCFourCipher.prototype = {
  12346. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12347. var i, n = data.length, tmp, tmp2;
  12348. var a = this.a, b = this.b, s = this.s;
  12349. var output = new Uint8Array(n);
  12350. for (i = 0; i < n; ++i) {
  12351. a = (a + 1) & 0xFF;
  12352. tmp = s[a];
  12353. b = (b + tmp) & 0xFF;
  12354. tmp2 = s[b];
  12355. s[a] = tmp2;
  12356. s[b] = tmp;
  12357. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12358. }
  12359. this.a = a;
  12360. this.b = b;
  12361. return output;
  12362. }
  12363. };
  12364. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12365. return ARCFourCipher;
  12366. })();
  12367. var calculateMD5 = (function calculateMD5Closure() {
  12368. var r = new Uint8Array([
  12369. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12370. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12371. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12372. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12373. var k = new Int32Array([
  12374. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12375. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12376. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12377. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12378. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12379. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12380. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12381. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12382. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12383. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12384. -145523070, -1120210379, 718787259, -343485551]);
  12385. function hash(data, offset, length) {
  12386. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12387. // pre-processing
  12388. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12389. var padded = new Uint8Array(paddedLength);
  12390. var i, j, n;
  12391. for (i = 0; i < length; ++i) {
  12392. padded[i] = data[offset++];
  12393. }
  12394. padded[i++] = 0x80;
  12395. n = paddedLength - 8;
  12396. while (i < n) {
  12397. padded[i++] = 0;
  12398. }
  12399. padded[i++] = (length << 3) & 0xFF;
  12400. padded[i++] = (length >> 5) & 0xFF;
  12401. padded[i++] = (length >> 13) & 0xFF;
  12402. padded[i++] = (length >> 21) & 0xFF;
  12403. padded[i++] = (length >>> 29) & 0xFF;
  12404. padded[i++] = 0;
  12405. padded[i++] = 0;
  12406. padded[i++] = 0;
  12407. var w = new Int32Array(16);
  12408. for (i = 0; i < paddedLength;) {
  12409. for (j = 0; j < 16; ++j, i += 4) {
  12410. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12411. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12412. }
  12413. var a = h0, b = h1, c = h2, d = h3, f, g;
  12414. for (j = 0; j < 64; ++j) {
  12415. if (j < 16) {
  12416. f = (b & c) | ((~b) & d);
  12417. g = j;
  12418. } else if (j < 32) {
  12419. f = (d & b) | ((~d) & c);
  12420. g = (5 * j + 1) & 15;
  12421. } else if (j < 48) {
  12422. f = b ^ c ^ d;
  12423. g = (3 * j + 5) & 15;
  12424. } else {
  12425. f = c ^ (b | (~d));
  12426. g = (7 * j) & 15;
  12427. }
  12428. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12429. d = c;
  12430. c = b;
  12431. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12432. a = tmp;
  12433. }
  12434. h0 = (h0 + a) | 0;
  12435. h1 = (h1 + b) | 0;
  12436. h2 = (h2 + c) | 0;
  12437. h3 = (h3 + d) | 0;
  12438. }
  12439. return new Uint8Array([
  12440. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12441. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12442. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12443. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12444. ]);
  12445. }
  12446. return hash;
  12447. })();
  12448. var Word64 = (function Word64Closure() {
  12449. function Word64(highInteger, lowInteger) {
  12450. this.high = highInteger | 0;
  12451. this.low = lowInteger | 0;
  12452. }
  12453. Word64.prototype = {
  12454. and: function Word64_and(word) {
  12455. this.high &= word.high;
  12456. this.low &= word.low;
  12457. },
  12458. xor: function Word64_xor(word) {
  12459. this.high ^= word.high;
  12460. this.low ^= word.low;
  12461. },
  12462. or: function Word64_or(word) {
  12463. this.high |= word.high;
  12464. this.low |= word.low;
  12465. },
  12466. shiftRight: function Word64_shiftRight(places) {
  12467. if (places >= 32) {
  12468. this.low = (this.high >>> (places - 32)) | 0;
  12469. this.high = 0;
  12470. } else {
  12471. this.low = (this.low >>> places) | (this.high << (32 - places));
  12472. this.high = (this.high >>> places) | 0;
  12473. }
  12474. },
  12475. shiftLeft: function Word64_shiftLeft(places) {
  12476. if (places >= 32) {
  12477. this.high = this.low << (places - 32);
  12478. this.low = 0;
  12479. } else {
  12480. this.high = (this.high << places) | (this.low >>> (32 - places));
  12481. this.low = this.low << places;
  12482. }
  12483. },
  12484. rotateRight: function Word64_rotateRight(places) {
  12485. var low, high;
  12486. if (places & 32) {
  12487. high = this.low;
  12488. low = this.high;
  12489. } else {
  12490. low = this.low;
  12491. high = this.high;
  12492. }
  12493. places &= 31;
  12494. this.low = (low >>> places) | (high << (32 - places));
  12495. this.high = (high >>> places) | (low << (32 - places));
  12496. },
  12497. not: function Word64_not() {
  12498. this.high = ~this.high;
  12499. this.low = ~this.low;
  12500. },
  12501. add: function Word64_add(word) {
  12502. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12503. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12504. if (lowAdd > 0xFFFFFFFF) {
  12505. highAdd += 1;
  12506. }
  12507. this.low = lowAdd | 0;
  12508. this.high = highAdd | 0;
  12509. },
  12510. copyTo: function Word64_copyTo(bytes, offset) {
  12511. bytes[offset] = (this.high >>> 24) & 0xFF;
  12512. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12513. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12514. bytes[offset + 3] = this.high & 0xFF;
  12515. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12516. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12517. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12518. bytes[offset + 7] = this.low & 0xFF;
  12519. },
  12520. assign: function Word64_assign(word) {
  12521. this.high = word.high;
  12522. this.low = word.low;
  12523. }
  12524. };
  12525. return Word64;
  12526. })();
  12527. var calculateSHA256 = (function calculateSHA256Closure() {
  12528. function rotr(x, n) {
  12529. return (x >>> n) | (x << 32 - n);
  12530. }
  12531. function ch(x, y, z) {
  12532. return (x & y) ^ (~x & z);
  12533. }
  12534. function maj(x, y, z) {
  12535. return (x & y) ^ (x & z) ^ (y & z);
  12536. }
  12537. function sigma(x) {
  12538. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12539. }
  12540. function sigmaPrime(x) {
  12541. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12542. }
  12543. function littleSigma(x) {
  12544. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12545. }
  12546. function littleSigmaPrime(x) {
  12547. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12548. }
  12549. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12550. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12551. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12552. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12553. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12554. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12555. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12556. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12557. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12558. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12559. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12560. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12561. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12562. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12563. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12564. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12565. function hash(data, offset, length) {
  12566. // initial hash values
  12567. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12568. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12569. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12570. // pre-processing
  12571. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12572. var padded = new Uint8Array(paddedLength);
  12573. var i, j, n;
  12574. for (i = 0; i < length; ++i) {
  12575. padded[i] = data[offset++];
  12576. }
  12577. padded[i++] = 0x80;
  12578. n = paddedLength - 8;
  12579. while (i < n) {
  12580. padded[i++] = 0;
  12581. }
  12582. padded[i++] = 0;
  12583. padded[i++] = 0;
  12584. padded[i++] = 0;
  12585. padded[i++] = (length >>> 29) & 0xFF;
  12586. padded[i++] = (length >> 21) & 0xFF;
  12587. padded[i++] = (length >> 13) & 0xFF;
  12588. padded[i++] = (length >> 5) & 0xFF;
  12589. padded[i++] = (length << 3) & 0xFF;
  12590. var w = new Uint32Array(64);
  12591. // for each 512 bit block
  12592. for (i = 0; i < paddedLength;) {
  12593. for (j = 0; j < 16; ++j) {
  12594. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12595. (padded[i + 2] << 8) | (padded[i + 3]));
  12596. i += 4;
  12597. }
  12598. for (j = 16; j < 64; ++j) {
  12599. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12600. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12601. }
  12602. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12603. f = h5, g = h6, h = h7, t1, t2;
  12604. for (j = 0; j < 64; ++j) {
  12605. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12606. t2 = sigma(a) + maj(a, b, c);
  12607. h = g;
  12608. g = f;
  12609. f = e;
  12610. e = (d + t1) | 0;
  12611. d = c;
  12612. c = b;
  12613. b = a;
  12614. a = (t1 + t2) | 0;
  12615. }
  12616. h0 = (h0 + a) | 0;
  12617. h1 = (h1 + b) | 0;
  12618. h2 = (h2 + c) | 0;
  12619. h3 = (h3 + d) | 0;
  12620. h4 = (h4 + e) | 0;
  12621. h5 = (h5 + f) | 0;
  12622. h6 = (h6 + g) | 0;
  12623. h7 = (h7 + h) | 0;
  12624. }
  12625. return new Uint8Array([
  12626. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12627. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12628. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12629. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12630. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12631. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12632. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12633. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12634. ]);
  12635. }
  12636. return hash;
  12637. })();
  12638. var calculateSHA512 = (function calculateSHA512Closure() {
  12639. function ch(result, x, y, z, tmp) {
  12640. result.assign(x);
  12641. result.and(y);
  12642. tmp.assign(x);
  12643. tmp.not();
  12644. tmp.and(z);
  12645. result.xor(tmp);
  12646. }
  12647. function maj(result, x, y, z, tmp) {
  12648. result.assign(x);
  12649. result.and(y);
  12650. tmp.assign(x);
  12651. tmp.and(z);
  12652. result.xor(tmp);
  12653. tmp.assign(y);
  12654. tmp.and(z);
  12655. result.xor(tmp);
  12656. }
  12657. function sigma(result, x, tmp) {
  12658. result.assign(x);
  12659. result.rotateRight(28);
  12660. tmp.assign(x);
  12661. tmp.rotateRight(34);
  12662. result.xor(tmp);
  12663. tmp.assign(x);
  12664. tmp.rotateRight(39);
  12665. result.xor(tmp);
  12666. }
  12667. function sigmaPrime(result, x, tmp) {
  12668. result.assign(x);
  12669. result.rotateRight(14);
  12670. tmp.assign(x);
  12671. tmp.rotateRight(18);
  12672. result.xor(tmp);
  12673. tmp.assign(x);
  12674. tmp.rotateRight(41);
  12675. result.xor(tmp);
  12676. }
  12677. function littleSigma(result, x, tmp) {
  12678. result.assign(x);
  12679. result.rotateRight(1);
  12680. tmp.assign(x);
  12681. tmp.rotateRight(8);
  12682. result.xor(tmp);
  12683. tmp.assign(x);
  12684. tmp.shiftRight(7);
  12685. result.xor(tmp);
  12686. }
  12687. function littleSigmaPrime(result, x, tmp) {
  12688. result.assign(x);
  12689. result.rotateRight(19);
  12690. tmp.assign(x);
  12691. tmp.rotateRight(61);
  12692. result.xor(tmp);
  12693. tmp.assign(x);
  12694. tmp.shiftRight(6);
  12695. result.xor(tmp);
  12696. }
  12697. var k = [
  12698. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12699. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12700. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12701. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12702. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12703. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12704. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12705. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12706. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12707. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12708. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12709. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12710. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12711. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12712. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12713. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12714. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12715. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12716. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12717. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12718. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12719. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12720. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12721. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12722. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12723. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12724. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12725. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12726. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12727. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12728. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12729. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12730. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12731. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12732. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12733. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12734. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12735. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12736. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12737. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12738. function hash(data, offset, length, mode384) {
  12739. mode384 = !!mode384;
  12740. // initial hash values
  12741. var h0, h1, h2, h3, h4, h5, h6, h7;
  12742. if (!mode384) {
  12743. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12744. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12745. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12746. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12747. h4 = new Word64(0x510e527f, 0xade682d1);
  12748. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12749. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12750. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12751. }
  12752. else {
  12753. // SHA384 is exactly the same
  12754. // except with different starting values and a trimmed result
  12755. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12756. h1 = new Word64(0x629a292a, 0x367cd507);
  12757. h2 = new Word64(0x9159015a, 0x3070dd17);
  12758. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12759. h4 = new Word64(0x67332667, 0xffc00b31);
  12760. h5 = new Word64(0x8eb44a87, 0x68581511);
  12761. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12762. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12763. }
  12764. // pre-processing
  12765. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12766. var padded = new Uint8Array(paddedLength);
  12767. var i, j, n;
  12768. for (i = 0; i < length; ++i) {
  12769. padded[i] = data[offset++];
  12770. }
  12771. padded[i++] = 0x80;
  12772. n = paddedLength - 16;
  12773. while (i < n) {
  12774. padded[i++] = 0;
  12775. }
  12776. padded[i++] = 0;
  12777. padded[i++] = 0;
  12778. padded[i++] = 0;
  12779. padded[i++] = 0;
  12780. padded[i++] = 0;
  12781. padded[i++] = 0;
  12782. padded[i++] = 0;
  12783. padded[i++] = 0;
  12784. padded[i++] = 0;
  12785. padded[i++] = 0;
  12786. padded[i++] = 0;
  12787. padded[i++] = (length >>> 29) & 0xFF;
  12788. padded[i++] = (length >> 21) & 0xFF;
  12789. padded[i++] = (length >> 13) & 0xFF;
  12790. padded[i++] = (length >> 5) & 0xFF;
  12791. padded[i++] = (length << 3) & 0xFF;
  12792. var w = new Array(80);
  12793. for (i = 0; i < 80; i++) {
  12794. w[i] = new Word64(0, 0);
  12795. }
  12796. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  12797. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  12798. var g = new Word64(0, 0), h = new Word64(0, 0);
  12799. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  12800. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  12801. // for each 1024 bit block
  12802. for (i = 0; i < paddedLength;) {
  12803. for (j = 0; j < 16; ++j) {
  12804. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  12805. (padded[i + 2] << 8) | (padded[i + 3]);
  12806. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  12807. (padded[i + 6]) << 8 | (padded[i + 7]);
  12808. i += 8;
  12809. }
  12810. for (j = 16; j < 80; ++j) {
  12811. tmp3 = w[j];
  12812. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  12813. tmp3.add(w[j - 7]);
  12814. littleSigma(tmp1, w[j - 15], tmp2);
  12815. tmp3.add(tmp1);
  12816. tmp3.add(w[j - 16]);
  12817. }
  12818. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  12819. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  12820. for (j = 0; j < 80; ++j) {
  12821. t1.assign(h);
  12822. sigmaPrime(tmp1, e, tmp2);
  12823. t1.add(tmp1);
  12824. ch(tmp1, e, f, g, tmp2);
  12825. t1.add(tmp1);
  12826. t1.add(k[j]);
  12827. t1.add(w[j]);
  12828. sigma(t2, a, tmp2);
  12829. maj(tmp1, a, b, c, tmp2);
  12830. t2.add(tmp1);
  12831. tmp3 = h;
  12832. h = g;
  12833. g = f;
  12834. f = e;
  12835. d.add(t1);
  12836. e = d;
  12837. d = c;
  12838. c = b;
  12839. b = a;
  12840. tmp3.assign(t1);
  12841. tmp3.add(t2);
  12842. a = tmp3;
  12843. }
  12844. h0.add(a);
  12845. h1.add(b);
  12846. h2.add(c);
  12847. h3.add(d);
  12848. h4.add(e);
  12849. h5.add(f);
  12850. h6.add(g);
  12851. h7.add(h);
  12852. }
  12853. var result;
  12854. if (!mode384) {
  12855. result = new Uint8Array(64);
  12856. h0.copyTo(result,0);
  12857. h1.copyTo(result,8);
  12858. h2.copyTo(result,16);
  12859. h3.copyTo(result,24);
  12860. h4.copyTo(result,32);
  12861. h5.copyTo(result,40);
  12862. h6.copyTo(result,48);
  12863. h7.copyTo(result,56);
  12864. }
  12865. else {
  12866. result = new Uint8Array(48);
  12867. h0.copyTo(result,0);
  12868. h1.copyTo(result,8);
  12869. h2.copyTo(result,16);
  12870. h3.copyTo(result,24);
  12871. h4.copyTo(result,32);
  12872. h5.copyTo(result,40);
  12873. }
  12874. return result;
  12875. }
  12876. return hash;
  12877. })();
  12878. var calculateSHA384 = (function calculateSHA384Closure() {
  12879. function hash(data, offset, length) {
  12880. return calculateSHA512(data, offset, length, true);
  12881. }
  12882. return hash;
  12883. })();
  12884. var NullCipher = (function NullCipherClosure() {
  12885. function NullCipher() {
  12886. }
  12887. NullCipher.prototype = {
  12888. decryptBlock: function NullCipher_decryptBlock(data) {
  12889. return data;
  12890. }
  12891. };
  12892. return NullCipher;
  12893. })();
  12894. var AES128Cipher = (function AES128CipherClosure() {
  12895. var rcon = new Uint8Array([
  12896. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12897. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12898. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12899. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12900. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  12901. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  12902. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  12903. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  12904. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  12905. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  12906. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  12907. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  12908. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  12909. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  12910. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  12911. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  12912. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  12913. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12914. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12915. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12916. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12917. 0x74, 0xe8, 0xcb, 0x8d]);
  12918. var s = new Uint8Array([
  12919. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  12920. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  12921. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  12922. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  12923. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  12924. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  12925. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  12926. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  12927. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  12928. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  12929. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  12930. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  12931. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  12932. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  12933. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  12934. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  12935. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  12936. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  12937. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  12938. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  12939. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  12940. 0xb0, 0x54, 0xbb, 0x16]);
  12941. var inv_s = new Uint8Array([
  12942. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  12943. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  12944. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  12945. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  12946. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  12947. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  12948. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  12949. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  12950. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  12951. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  12952. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  12953. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  12954. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  12955. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  12956. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  12957. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  12958. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  12959. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  12960. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  12961. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  12962. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  12963. 0x55, 0x21, 0x0c, 0x7d]);
  12964. var mixCol = new Uint8Array(256);
  12965. for (var i = 0; i < 256; i++) {
  12966. if (i < 128) {
  12967. mixCol[i] = i << 1;
  12968. } else {
  12969. mixCol[i] = (i << 1) ^ 0x1b;
  12970. }
  12971. }
  12972. var mix = new Uint32Array([
  12973. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  12974. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  12975. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  12976. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  12977. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  12978. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  12979. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  12980. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  12981. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  12982. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  12983. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  12984. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  12985. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  12986. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  12987. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  12988. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  12989. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  12990. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  12991. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  12992. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  12993. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  12994. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  12995. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  12996. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  12997. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  12998. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  12999. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13000. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13001. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13002. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13003. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13004. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13005. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13006. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13007. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13008. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13009. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13010. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13011. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13012. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13013. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13014. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13015. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13016. function expandKey128(cipherKey) {
  13017. var b = 176, result = new Uint8Array(b);
  13018. result.set(cipherKey);
  13019. for (var j = 16, i = 1; j < b; ++i) {
  13020. // RotWord
  13021. var t1 = result[j - 3], t2 = result[j - 2],
  13022. t3 = result[j - 1], t4 = result[j - 4];
  13023. // SubWord
  13024. t1 = s[t1];
  13025. t2 = s[t2];
  13026. t3 = s[t3];
  13027. t4 = s[t4];
  13028. // Rcon
  13029. t1 = t1 ^ rcon[i];
  13030. for (var n = 0; n < 4; ++n) {
  13031. result[j] = (t1 ^= result[j - 16]);
  13032. j++;
  13033. result[j] = (t2 ^= result[j - 16]);
  13034. j++;
  13035. result[j] = (t3 ^= result[j - 16]);
  13036. j++;
  13037. result[j] = (t4 ^= result[j - 16]);
  13038. j++;
  13039. }
  13040. }
  13041. return result;
  13042. }
  13043. function decrypt128(input, key) {
  13044. var state = new Uint8Array(16);
  13045. state.set(input);
  13046. var i, j, k;
  13047. var t, u, v;
  13048. // AddRoundKey
  13049. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13050. state[j] ^= key[k];
  13051. }
  13052. for (i = 9; i >= 1; --i) {
  13053. // InvShiftRows
  13054. t = state[13];
  13055. state[13] = state[9];
  13056. state[9] = state[5];
  13057. state[5] = state[1];
  13058. state[1] = t;
  13059. t = state[14];
  13060. u = state[10];
  13061. state[14] = state[6];
  13062. state[10] = state[2];
  13063. state[6] = t;
  13064. state[2] = u;
  13065. t = state[15];
  13066. u = state[11];
  13067. v = state[7];
  13068. state[15] = state[3];
  13069. state[11] = t;
  13070. state[7] = u;
  13071. state[3] = v;
  13072. // InvSubBytes
  13073. for (j = 0; j < 16; ++j) {
  13074. state[j] = inv_s[state[j]];
  13075. }
  13076. // AddRoundKey
  13077. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13078. state[j] ^= key[k];
  13079. }
  13080. // InvMixColumns
  13081. for (j = 0; j < 16; j += 4) {
  13082. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13083. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13084. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13085. (s3 >>> 24) ^ (s3 << 8));
  13086. state[j] = (t >>> 24) & 0xFF;
  13087. state[j + 1] = (t >> 16) & 0xFF;
  13088. state[j + 2] = (t >> 8) & 0xFF;
  13089. state[j + 3] = t & 0xFF;
  13090. }
  13091. }
  13092. // InvShiftRows
  13093. t = state[13];
  13094. state[13] = state[9];
  13095. state[9] = state[5];
  13096. state[5] = state[1];
  13097. state[1] = t;
  13098. t = state[14];
  13099. u = state[10];
  13100. state[14] = state[6];
  13101. state[10] = state[2];
  13102. state[6] = t;
  13103. state[2] = u;
  13104. t = state[15];
  13105. u = state[11];
  13106. v = state[7];
  13107. state[15] = state[3];
  13108. state[11] = t;
  13109. state[7] = u;
  13110. state[3] = v;
  13111. for (j = 0; j < 16; ++j) {
  13112. // InvSubBytes
  13113. state[j] = inv_s[state[j]];
  13114. // AddRoundKey
  13115. state[j] ^= key[j];
  13116. }
  13117. return state;
  13118. }
  13119. function encrypt128(input, key) {
  13120. var t, u, v, k;
  13121. var state = new Uint8Array(16);
  13122. state.set(input);
  13123. for (j = 0; j < 16; ++j) {
  13124. // AddRoundKey
  13125. state[j] ^= key[j];
  13126. }
  13127. for (i = 1; i < 10; i++) {
  13128. //SubBytes
  13129. for (j = 0; j < 16; ++j) {
  13130. state[j] = s[state[j]];
  13131. }
  13132. //ShiftRows
  13133. v = state[1];
  13134. state[1] = state[5];
  13135. state[5] = state[9];
  13136. state[9] = state[13];
  13137. state[13] = v;
  13138. v = state[2];
  13139. u = state[6];
  13140. state[2] = state[10];
  13141. state[6] = state[14];
  13142. state[10] = v;
  13143. state[14] = u;
  13144. v = state[3];
  13145. u = state[7];
  13146. t = state[11];
  13147. state[3] = state[15];
  13148. state[7] = v;
  13149. state[11] = u;
  13150. state[15] = t;
  13151. //MixColumns
  13152. for (var j = 0; j < 16; j += 4) {
  13153. var s0 = state[j + 0], s1 = state[j + 1];
  13154. var s2 = state[j + 2], s3 = state[j + 3];
  13155. t = s0 ^ s1 ^ s2 ^ s3;
  13156. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13157. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13158. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13159. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13160. }
  13161. //AddRoundKey
  13162. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13163. state[j] ^= key[k];
  13164. }
  13165. }
  13166. //SubBytes
  13167. for (j = 0; j < 16; ++j) {
  13168. state[j] = s[state[j]];
  13169. }
  13170. //ShiftRows
  13171. v = state[1];
  13172. state[1] = state[5];
  13173. state[5] = state[9];
  13174. state[9] = state[13];
  13175. state[13] = v;
  13176. v = state[2];
  13177. u = state[6];
  13178. state[2] = state[10];
  13179. state[6] = state[14];
  13180. state[10] = v;
  13181. state[14] = u;
  13182. v = state[3];
  13183. u = state[7];
  13184. t = state[11];
  13185. state[3] = state[15];
  13186. state[7] = v;
  13187. state[11] = u;
  13188. state[15] = t;
  13189. //AddRoundKey
  13190. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13191. state[j] ^= key[k];
  13192. }
  13193. return state;
  13194. }
  13195. function AES128Cipher(key) {
  13196. this.key = expandKey128(key);
  13197. this.buffer = new Uint8Array(16);
  13198. this.bufferPosition = 0;
  13199. }
  13200. function decryptBlock2(data, finalize) {
  13201. var i, j, ii, sourceLength = data.length,
  13202. buffer = this.buffer, bufferLength = this.bufferPosition,
  13203. result = [], iv = this.iv;
  13204. for (i = 0; i < sourceLength; ++i) {
  13205. buffer[bufferLength] = data[i];
  13206. ++bufferLength;
  13207. if (bufferLength < 16) {
  13208. continue;
  13209. }
  13210. // buffer is full, decrypting
  13211. var plain = decrypt128(buffer, this.key);
  13212. // xor-ing the IV vector to get plain text
  13213. for (j = 0; j < 16; ++j) {
  13214. plain[j] ^= iv[j];
  13215. }
  13216. iv = buffer;
  13217. result.push(plain);
  13218. buffer = new Uint8Array(16);
  13219. bufferLength = 0;
  13220. }
  13221. // saving incomplete buffer
  13222. this.buffer = buffer;
  13223. this.bufferLength = bufferLength;
  13224. this.iv = iv;
  13225. if (result.length === 0) {
  13226. return new Uint8Array([]);
  13227. }
  13228. // combining plain text blocks into one
  13229. var outputLength = 16 * result.length;
  13230. if (finalize) {
  13231. // undo a padding that is described in RFC 2898
  13232. var lastBlock = result[result.length - 1];
  13233. var psLen = lastBlock[15];
  13234. if (psLen <= 16) {
  13235. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13236. if (lastBlock[i] !== psLen) {
  13237. // Invalid padding, assume that the block has no padding.
  13238. psLen = 0;
  13239. break;
  13240. }
  13241. }
  13242. outputLength -= psLen;
  13243. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13244. }
  13245. }
  13246. var output = new Uint8Array(outputLength);
  13247. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13248. output.set(result[i], j);
  13249. }
  13250. return output;
  13251. }
  13252. AES128Cipher.prototype = {
  13253. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13254. var i, sourceLength = data.length;
  13255. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13256. // waiting for IV values -- they are at the start of the stream
  13257. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13258. buffer[bufferLength] = data[i];
  13259. }
  13260. if (bufferLength < 16) {
  13261. // need more data
  13262. this.bufferLength = bufferLength;
  13263. return new Uint8Array([]);
  13264. }
  13265. this.iv = buffer;
  13266. this.buffer = new Uint8Array(16);
  13267. this.bufferLength = 0;
  13268. // starting decryption
  13269. this.decryptBlock = decryptBlock2;
  13270. return this.decryptBlock(data.subarray(16), finalize);
  13271. },
  13272. encrypt: function AES128Cipher_encrypt(data, iv) {
  13273. var i, j, ii, sourceLength = data.length,
  13274. buffer = this.buffer, bufferLength = this.bufferPosition,
  13275. result = [];
  13276. if (!iv) {
  13277. iv = new Uint8Array(16);
  13278. }
  13279. for (i = 0; i < sourceLength; ++i) {
  13280. buffer[bufferLength] = data[i];
  13281. ++bufferLength;
  13282. if (bufferLength < 16) {
  13283. continue;
  13284. }
  13285. for (j = 0; j < 16; ++j) {
  13286. buffer[j] ^= iv[j];
  13287. }
  13288. // buffer is full, encrypting
  13289. var cipher = encrypt128(buffer, this.key);
  13290. iv = cipher;
  13291. result.push(cipher);
  13292. buffer = new Uint8Array(16);
  13293. bufferLength = 0;
  13294. }
  13295. // saving incomplete buffer
  13296. this.buffer = buffer;
  13297. this.bufferLength = bufferLength;
  13298. this.iv = iv;
  13299. if (result.length === 0) {
  13300. return new Uint8Array([]);
  13301. }
  13302. // combining plain text blocks into one
  13303. var outputLength = 16 * result.length;
  13304. var output = new Uint8Array(outputLength);
  13305. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13306. output.set(result[i], j);
  13307. }
  13308. return output;
  13309. }
  13310. };
  13311. return AES128Cipher;
  13312. })();
  13313. var AES256Cipher = (function AES256CipherClosure() {
  13314. var rcon = new Uint8Array([
  13315. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13316. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13317. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13318. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13319. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13320. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13321. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13322. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13323. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13324. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13325. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13326. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13327. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13328. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13329. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13330. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13331. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13332. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13333. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13334. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13335. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13336. 0x74, 0xe8, 0xcb, 0x8d]);
  13337. var s = new Uint8Array([
  13338. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13339. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13340. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13341. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13342. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13343. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13344. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13345. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13346. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13347. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13348. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13349. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13350. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13351. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13352. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13353. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13354. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13355. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13356. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13357. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13358. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13359. 0xb0, 0x54, 0xbb, 0x16]);
  13360. var inv_s = new Uint8Array([
  13361. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13362. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13363. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13364. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13365. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13366. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13367. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13368. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13369. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13370. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13371. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13372. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13373. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13374. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13375. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13376. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13377. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13378. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13379. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13380. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13381. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13382. 0x55, 0x21, 0x0c, 0x7d]);
  13383. var mixCol = new Uint8Array(256);
  13384. for (var i = 0; i < 256; i++) {
  13385. if (i < 128) {
  13386. mixCol[i] = i << 1;
  13387. } else {
  13388. mixCol[i] = (i << 1) ^ 0x1b;
  13389. }
  13390. }
  13391. var mix = new Uint32Array([
  13392. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13393. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13394. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13395. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13396. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13397. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13398. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13399. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13400. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13401. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13402. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13403. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13404. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13405. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13406. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13407. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13408. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13409. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13410. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13411. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13412. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13413. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13414. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13415. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13416. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13417. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13418. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13419. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13420. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13421. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13422. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13423. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13424. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13425. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13426. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13427. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13428. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13429. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13430. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13431. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13432. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13433. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13434. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13435. function expandKey256(cipherKey) {
  13436. var b = 240, result = new Uint8Array(b);
  13437. var r = 1;
  13438. result.set(cipherKey);
  13439. for (var j = 32, i = 1; j < b; ++i) {
  13440. if (j % 32 === 16) {
  13441. t1 = s[t1];
  13442. t2 = s[t2];
  13443. t3 = s[t3];
  13444. t4 = s[t4];
  13445. } else if (j % 32 === 0) {
  13446. // RotWord
  13447. var t1 = result[j - 3], t2 = result[j - 2],
  13448. t3 = result[j - 1], t4 = result[j - 4];
  13449. // SubWord
  13450. t1 = s[t1];
  13451. t2 = s[t2];
  13452. t3 = s[t3];
  13453. t4 = s[t4];
  13454. // Rcon
  13455. t1 = t1 ^ r;
  13456. if ((r <<= 1) >= 256) {
  13457. r = (r ^ 0x1b) & 0xFF;
  13458. }
  13459. }
  13460. for (var n = 0; n < 4; ++n) {
  13461. result[j] = (t1 ^= result[j - 32]);
  13462. j++;
  13463. result[j] = (t2 ^= result[j - 32]);
  13464. j++;
  13465. result[j] = (t3 ^= result[j - 32]);
  13466. j++;
  13467. result[j] = (t4 ^= result[j - 32]);
  13468. j++;
  13469. }
  13470. }
  13471. return result;
  13472. }
  13473. function decrypt256(input, key) {
  13474. var state = new Uint8Array(16);
  13475. state.set(input);
  13476. var i, j, k;
  13477. var t, u, v;
  13478. // AddRoundKey
  13479. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13480. state[j] ^= key[k];
  13481. }
  13482. for (i = 13; i >= 1; --i) {
  13483. // InvShiftRows
  13484. t = state[13];
  13485. state[13] = state[9];
  13486. state[9] = state[5];
  13487. state[5] = state[1];
  13488. state[1] = t;
  13489. t = state[14];
  13490. u = state[10];
  13491. state[14] = state[6];
  13492. state[10] = state[2];
  13493. state[6] = t;
  13494. state[2] = u;
  13495. t = state[15];
  13496. u = state[11];
  13497. v = state[7];
  13498. state[15] = state[3];
  13499. state[11] = t;
  13500. state[7] = u;
  13501. state[3] = v;
  13502. // InvSubBytes
  13503. for (j = 0; j < 16; ++j) {
  13504. state[j] = inv_s[state[j]];
  13505. }
  13506. // AddRoundKey
  13507. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13508. state[j] ^= key[k];
  13509. }
  13510. // InvMixColumns
  13511. for (j = 0; j < 16; j += 4) {
  13512. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13513. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13514. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13515. (s3 >>> 24) ^ (s3 << 8));
  13516. state[j] = (t >>> 24) & 0xFF;
  13517. state[j + 1] = (t >> 16) & 0xFF;
  13518. state[j + 2] = (t >> 8) & 0xFF;
  13519. state[j + 3] = t & 0xFF;
  13520. }
  13521. }
  13522. // InvShiftRows
  13523. t = state[13];
  13524. state[13] = state[9];
  13525. state[9] = state[5];
  13526. state[5] = state[1];
  13527. state[1] = t;
  13528. t = state[14];
  13529. u = state[10];
  13530. state[14] = state[6];
  13531. state[10] = state[2];
  13532. state[6] = t;
  13533. state[2] = u;
  13534. t = state[15];
  13535. u = state[11];
  13536. v = state[7];
  13537. state[15] = state[3];
  13538. state[11] = t;
  13539. state[7] = u;
  13540. state[3] = v;
  13541. for (j = 0; j < 16; ++j) {
  13542. // InvSubBytes
  13543. state[j] = inv_s[state[j]];
  13544. // AddRoundKey
  13545. state[j] ^= key[j];
  13546. }
  13547. return state;
  13548. }
  13549. function encrypt256(input, key) {
  13550. var t, u, v, k;
  13551. var state = new Uint8Array(16);
  13552. state.set(input);
  13553. for (j = 0; j < 16; ++j) {
  13554. // AddRoundKey
  13555. state[j] ^= key[j];
  13556. }
  13557. for (i = 1; i < 14; i++) {
  13558. //SubBytes
  13559. for (j = 0; j < 16; ++j) {
  13560. state[j] = s[state[j]];
  13561. }
  13562. //ShiftRows
  13563. v = state[1];
  13564. state[1] = state[5];
  13565. state[5] = state[9];
  13566. state[9] = state[13];
  13567. state[13] = v;
  13568. v = state[2];
  13569. u = state[6];
  13570. state[2] = state[10];
  13571. state[6] = state[14];
  13572. state[10] = v;
  13573. state[14] = u;
  13574. v = state[3];
  13575. u = state[7];
  13576. t = state[11];
  13577. state[3] = state[15];
  13578. state[7] = v;
  13579. state[11] = u;
  13580. state[15] = t;
  13581. //MixColumns
  13582. for (var j = 0; j < 16; j += 4) {
  13583. var s0 = state[j + 0], s1 = state[j + 1];
  13584. var s2 = state[j + 2], s3 = state[j + 3];
  13585. t = s0 ^ s1 ^ s2 ^ s3;
  13586. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13587. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13588. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13589. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13590. }
  13591. //AddRoundKey
  13592. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13593. state[j] ^= key[k];
  13594. }
  13595. }
  13596. //SubBytes
  13597. for (j = 0; j < 16; ++j) {
  13598. state[j] = s[state[j]];
  13599. }
  13600. //ShiftRows
  13601. v = state[1];
  13602. state[1] = state[5];
  13603. state[5] = state[9];
  13604. state[9] = state[13];
  13605. state[13] = v;
  13606. v = state[2];
  13607. u = state[6];
  13608. state[2] = state[10];
  13609. state[6] = state[14];
  13610. state[10] = v;
  13611. state[14] = u;
  13612. v = state[3];
  13613. u = state[7];
  13614. t = state[11];
  13615. state[3] = state[15];
  13616. state[7] = v;
  13617. state[11] = u;
  13618. state[15] = t;
  13619. //AddRoundKey
  13620. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13621. state[j] ^= key[k];
  13622. }
  13623. return state;
  13624. }
  13625. function AES256Cipher(key) {
  13626. this.key = expandKey256(key);
  13627. this.buffer = new Uint8Array(16);
  13628. this.bufferPosition = 0;
  13629. }
  13630. function decryptBlock2(data, finalize) {
  13631. var i, j, ii, sourceLength = data.length,
  13632. buffer = this.buffer, bufferLength = this.bufferPosition,
  13633. result = [], iv = this.iv;
  13634. for (i = 0; i < sourceLength; ++i) {
  13635. buffer[bufferLength] = data[i];
  13636. ++bufferLength;
  13637. if (bufferLength < 16) {
  13638. continue;
  13639. }
  13640. // buffer is full, decrypting
  13641. var plain = decrypt256(buffer, this.key);
  13642. // xor-ing the IV vector to get plain text
  13643. for (j = 0; j < 16; ++j) {
  13644. plain[j] ^= iv[j];
  13645. }
  13646. iv = buffer;
  13647. result.push(plain);
  13648. buffer = new Uint8Array(16);
  13649. bufferLength = 0;
  13650. }
  13651. // saving incomplete buffer
  13652. this.buffer = buffer;
  13653. this.bufferLength = bufferLength;
  13654. this.iv = iv;
  13655. if (result.length === 0) {
  13656. return new Uint8Array([]);
  13657. }
  13658. // combining plain text blocks into one
  13659. var outputLength = 16 * result.length;
  13660. if (finalize) {
  13661. // undo a padding that is described in RFC 2898
  13662. var lastBlock = result[result.length - 1];
  13663. var psLen = lastBlock[15];
  13664. if (psLen <= 16) {
  13665. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13666. if (lastBlock[i] !== psLen) {
  13667. // Invalid padding, assume that the block has no padding.
  13668. psLen = 0;
  13669. break;
  13670. }
  13671. }
  13672. outputLength -= psLen;
  13673. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13674. }
  13675. }
  13676. var output = new Uint8Array(outputLength);
  13677. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13678. output.set(result[i], j);
  13679. }
  13680. return output;
  13681. }
  13682. AES256Cipher.prototype = {
  13683. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13684. var i, sourceLength = data.length;
  13685. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13686. // if not supplied an IV wait for IV values
  13687. // they are at the start of the stream
  13688. if (iv) {
  13689. this.iv = iv;
  13690. } else {
  13691. for (i = 0; bufferLength < 16 &&
  13692. i < sourceLength; ++i, ++bufferLength) {
  13693. buffer[bufferLength] = data[i];
  13694. }
  13695. if (bufferLength < 16) {
  13696. //need more data
  13697. this.bufferLength = bufferLength;
  13698. return new Uint8Array([]);
  13699. }
  13700. this.iv = buffer;
  13701. data = data.subarray(16);
  13702. }
  13703. this.buffer = new Uint8Array(16);
  13704. this.bufferLength = 0;
  13705. // starting decryption
  13706. this.decryptBlock = decryptBlock2;
  13707. return this.decryptBlock(data, finalize);
  13708. },
  13709. encrypt: function AES256Cipher_encrypt(data, iv) {
  13710. var i, j, ii, sourceLength = data.length,
  13711. buffer = this.buffer, bufferLength = this.bufferPosition,
  13712. result = [];
  13713. if (!iv) {
  13714. iv = new Uint8Array(16);
  13715. }
  13716. for (i = 0; i < sourceLength; ++i) {
  13717. buffer[bufferLength] = data[i];
  13718. ++bufferLength;
  13719. if (bufferLength < 16) {
  13720. continue;
  13721. }
  13722. for (j = 0; j < 16; ++j) {
  13723. buffer[j] ^= iv[j];
  13724. }
  13725. // buffer is full, encrypting
  13726. var cipher = encrypt256(buffer, this.key);
  13727. this.iv = cipher;
  13728. result.push(cipher);
  13729. buffer = new Uint8Array(16);
  13730. bufferLength = 0;
  13731. }
  13732. // saving incomplete buffer
  13733. this.buffer = buffer;
  13734. this.bufferLength = bufferLength;
  13735. this.iv = iv;
  13736. if (result.length === 0) {
  13737. return new Uint8Array([]);
  13738. }
  13739. // combining plain text blocks into one
  13740. var outputLength = 16 * result.length;
  13741. var output = new Uint8Array(outputLength);
  13742. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13743. output.set(result[i], j);
  13744. }
  13745. return output;
  13746. }
  13747. };
  13748. return AES256Cipher;
  13749. })();
  13750. var PDF17 = (function PDF17Closure() {
  13751. function compareByteArrays(array1, array2) {
  13752. if (array1.length !== array2.length) {
  13753. return false;
  13754. }
  13755. for (var i = 0; i < array1.length; i++) {
  13756. if (array1[i] !== array2[i]) {
  13757. return false;
  13758. }
  13759. }
  13760. return true;
  13761. }
  13762. function PDF17() {
  13763. }
  13764. PDF17.prototype = {
  13765. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13766. ownerValidationSalt,
  13767. userBytes,
  13768. ownerPassword) {
  13769. var hashData = new Uint8Array(password.length + 56);
  13770. hashData.set(password, 0);
  13771. hashData.set(ownerValidationSalt, password.length);
  13772. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13773. var result = calculateSHA256(hashData, 0, hashData.length);
  13774. return compareByteArrays(result, ownerPassword);
  13775. },
  13776. checkUserPassword: function PDF17_checkUserPassword(password,
  13777. userValidationSalt,
  13778. userPassword) {
  13779. var hashData = new Uint8Array(password.length + 8);
  13780. hashData.set(password, 0);
  13781. hashData.set(userValidationSalt, password.length);
  13782. var result = calculateSHA256(hashData, 0, hashData.length);
  13783. return compareByteArrays(result, userPassword);
  13784. },
  13785. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  13786. ownerEncryption) {
  13787. var hashData = new Uint8Array(password.length + 56);
  13788. hashData.set(password, 0);
  13789. hashData.set(ownerKeySalt, password.length);
  13790. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13791. var key = calculateSHA256(hashData, 0, hashData.length);
  13792. var cipher = new AES256Cipher(key);
  13793. return cipher.decryptBlock(ownerEncryption,
  13794. false,
  13795. new Uint8Array(16));
  13796. },
  13797. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  13798. userEncryption) {
  13799. var hashData = new Uint8Array(password.length + 8);
  13800. hashData.set(password, 0);
  13801. hashData.set(userKeySalt, password.length);
  13802. //key is the decryption key for the UE string
  13803. var key = calculateSHA256(hashData, 0, hashData.length);
  13804. var cipher = new AES256Cipher(key);
  13805. return cipher.decryptBlock(userEncryption,
  13806. false,
  13807. new Uint8Array(16));
  13808. }
  13809. };
  13810. return PDF17;
  13811. })();
  13812. var PDF20 = (function PDF20Closure() {
  13813. function concatArrays(array1, array2) {
  13814. var t = new Uint8Array(array1.length + array2.length);
  13815. t.set(array1, 0);
  13816. t.set(array2, array1.length);
  13817. return t;
  13818. }
  13819. function calculatePDF20Hash(password, input, userBytes) {
  13820. //This refers to Algorithm 2.B as defined in ISO 32000-2
  13821. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  13822. var e = [0];
  13823. var i = 0;
  13824. while (i < 64 || e[e.length - 1] > i - 32) {
  13825. var arrayLength = password.length + k.length + userBytes.length;
  13826. var k1 = new Uint8Array(arrayLength * 64);
  13827. var array = concatArrays(password, k);
  13828. array = concatArrays(array, userBytes);
  13829. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  13830. k1.set(array, pos);
  13831. }
  13832. //AES128 CBC NO PADDING with
  13833. //first 16 bytes of k as the key and the second 16 as the iv.
  13834. var cipher = new AES128Cipher(k.subarray(0, 16));
  13835. e = cipher.encrypt(k1, k.subarray(16, 32));
  13836. //Now we have to take the first 16 bytes of an unsigned
  13837. //big endian integer... and compute the remainder
  13838. //modulo 3.... That is a fairly large number and
  13839. //JavaScript isn't going to handle that well...
  13840. //So we're using a trick that allows us to perform
  13841. //modulo math byte by byte
  13842. var remainder = 0;
  13843. for (var z = 0; z < 16; z++) {
  13844. remainder *= (256 % 3);
  13845. remainder %= 3;
  13846. remainder += ((e[z] >>> 0) % 3);
  13847. remainder %= 3;
  13848. }
  13849. if (remainder === 0) {
  13850. k = calculateSHA256(e, 0, e.length);
  13851. }
  13852. else if (remainder === 1) {
  13853. k = calculateSHA384(e, 0, e.length);
  13854. }
  13855. else if (remainder === 2) {
  13856. k = calculateSHA512(e, 0, e.length);
  13857. }
  13858. i++;
  13859. }
  13860. return k.subarray(0, 32);
  13861. }
  13862. function PDF20() {
  13863. }
  13864. function compareByteArrays(array1, array2) {
  13865. if (array1.length !== array2.length) {
  13866. return false;
  13867. }
  13868. for (var i = 0; i < array1.length; i++) {
  13869. if (array1[i] !== array2[i]) {
  13870. return false;
  13871. }
  13872. }
  13873. return true;
  13874. }
  13875. PDF20.prototype = {
  13876. hash: function PDF20_hash(password, concatBytes, userBytes) {
  13877. return calculatePDF20Hash(password, concatBytes, userBytes);
  13878. },
  13879. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  13880. ownerValidationSalt,
  13881. userBytes,
  13882. ownerPassword) {
  13883. var hashData = new Uint8Array(password.length + 56);
  13884. hashData.set(password, 0);
  13885. hashData.set(ownerValidationSalt, password.length);
  13886. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13887. var result = calculatePDF20Hash(password, hashData, userBytes);
  13888. return compareByteArrays(result, ownerPassword);
  13889. },
  13890. checkUserPassword: function PDF20_checkUserPassword(password,
  13891. userValidationSalt,
  13892. userPassword) {
  13893. var hashData = new Uint8Array(password.length + 8);
  13894. hashData.set(password, 0);
  13895. hashData.set(userValidationSalt, password.length);
  13896. var result = calculatePDF20Hash(password, hashData, []);
  13897. return compareByteArrays(result, userPassword);
  13898. },
  13899. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  13900. ownerEncryption) {
  13901. var hashData = new Uint8Array(password.length + 56);
  13902. hashData.set(password, 0);
  13903. hashData.set(ownerKeySalt, password.length);
  13904. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13905. var key = calculatePDF20Hash(password, hashData, userBytes);
  13906. var cipher = new AES256Cipher(key);
  13907. return cipher.decryptBlock(ownerEncryption,
  13908. false,
  13909. new Uint8Array(16));
  13910. },
  13911. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  13912. userEncryption) {
  13913. var hashData = new Uint8Array(password.length + 8);
  13914. hashData.set(password, 0);
  13915. hashData.set(userKeySalt, password.length);
  13916. //key is the decryption key for the UE string
  13917. var key = calculatePDF20Hash(password, hashData, []);
  13918. var cipher = new AES256Cipher(key);
  13919. return cipher.decryptBlock(userEncryption,
  13920. false,
  13921. new Uint8Array(16));
  13922. }
  13923. };
  13924. return PDF20;
  13925. })();
  13926. var CipherTransform = (function CipherTransformClosure() {
  13927. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  13928. this.stringCipherConstructor = stringCipherConstructor;
  13929. this.streamCipherConstructor = streamCipherConstructor;
  13930. }
  13931. CipherTransform.prototype = {
  13932. createStream: function CipherTransform_createStream(stream, length) {
  13933. var cipher = new this.streamCipherConstructor();
  13934. return new DecryptStream(stream, length,
  13935. function cipherTransformDecryptStream(data, finalize) {
  13936. return cipher.decryptBlock(data, finalize);
  13937. }
  13938. );
  13939. },
  13940. decryptString: function CipherTransform_decryptString(s) {
  13941. var cipher = new this.stringCipherConstructor();
  13942. var data = stringToBytes(s);
  13943. data = cipher.decryptBlock(data, true);
  13944. return bytesToString(data);
  13945. }
  13946. };
  13947. return CipherTransform;
  13948. })();
  13949. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  13950. var defaultPasswordBytes = new Uint8Array([
  13951. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  13952. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  13953. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  13954. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  13955. function createEncryptionKey20(revision, password, ownerPassword,
  13956. ownerValidationSalt, ownerKeySalt, uBytes,
  13957. userPassword, userValidationSalt, userKeySalt,
  13958. ownerEncryption, userEncryption, perms) {
  13959. if (password) {
  13960. var passwordLength = Math.min(127, password.length);
  13961. password = password.subarray(0, passwordLength);
  13962. } else {
  13963. password = [];
  13964. }
  13965. var pdfAlgorithm;
  13966. if (revision === 6) {
  13967. pdfAlgorithm = new PDF20();
  13968. } else {
  13969. pdfAlgorithm = new PDF17();
  13970. }
  13971. if (pdfAlgorithm) {
  13972. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  13973. userPassword)) {
  13974. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  13975. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  13976. uBytes,
  13977. ownerPassword)) {
  13978. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  13979. ownerEncryption);
  13980. }
  13981. }
  13982. return null;
  13983. }
  13984. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  13985. flags, revision, keyLength, encryptMetadata) {
  13986. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  13987. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  13988. if (password) {
  13989. n = Math.min(32, password.length);
  13990. for (; i < n; ++i) {
  13991. hashData[i] = password[i];
  13992. }
  13993. }
  13994. j = 0;
  13995. while (i < 32) {
  13996. hashData[i++] = defaultPasswordBytes[j++];
  13997. }
  13998. // as now the padded password in the hashData[0..i]
  13999. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14000. hashData[i++] = ownerPassword[j];
  14001. }
  14002. hashData[i++] = flags & 0xFF;
  14003. hashData[i++] = (flags >> 8) & 0xFF;
  14004. hashData[i++] = (flags >> 16) & 0xFF;
  14005. hashData[i++] = (flags >>> 24) & 0xFF;
  14006. for (j = 0, n = fileId.length; j < n; ++j) {
  14007. hashData[i++] = fileId[j];
  14008. }
  14009. if (revision >= 4 && !encryptMetadata) {
  14010. hashData[i++] = 0xFF;
  14011. hashData[i++] = 0xFF;
  14012. hashData[i++] = 0xFF;
  14013. hashData[i++] = 0xFF;
  14014. }
  14015. var hash = calculateMD5(hashData, 0, i);
  14016. var keyLengthInBytes = keyLength >> 3;
  14017. if (revision >= 3) {
  14018. for (j = 0; j < 50; ++j) {
  14019. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14020. }
  14021. }
  14022. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14023. var cipher, checkData;
  14024. if (revision >= 3) {
  14025. for (i = 0; i < 32; ++i) {
  14026. hashData[i] = defaultPasswordBytes[i];
  14027. }
  14028. for (j = 0, n = fileId.length; j < n; ++j) {
  14029. hashData[i++] = fileId[j];
  14030. }
  14031. cipher = new ARCFourCipher(encryptionKey);
  14032. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14033. n = encryptionKey.length;
  14034. var derivedKey = new Uint8Array(n), k;
  14035. for (j = 1; j <= 19; ++j) {
  14036. for (k = 0; k < n; ++k) {
  14037. derivedKey[k] = encryptionKey[k] ^ j;
  14038. }
  14039. cipher = new ARCFourCipher(derivedKey);
  14040. checkData = cipher.encryptBlock(checkData);
  14041. }
  14042. for (j = 0, n = checkData.length; j < n; ++j) {
  14043. if (userPassword[j] !== checkData[j]) {
  14044. return null;
  14045. }
  14046. }
  14047. } else {
  14048. cipher = new ARCFourCipher(encryptionKey);
  14049. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14050. for (j = 0, n = checkData.length; j < n; ++j) {
  14051. if (userPassword[j] !== checkData[j]) {
  14052. return null;
  14053. }
  14054. }
  14055. }
  14056. return encryptionKey;
  14057. }
  14058. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14059. var hashData = new Uint8Array(32), i = 0, j, n;
  14060. n = Math.min(32, password.length);
  14061. for (; i < n; ++i) {
  14062. hashData[i] = password[i];
  14063. }
  14064. j = 0;
  14065. while (i < 32) {
  14066. hashData[i++] = defaultPasswordBytes[j++];
  14067. }
  14068. var hash = calculateMD5(hashData, 0, i);
  14069. var keyLengthInBytes = keyLength >> 3;
  14070. if (revision >= 3) {
  14071. for (j = 0; j < 50; ++j) {
  14072. hash = calculateMD5(hash, 0, hash.length);
  14073. }
  14074. }
  14075. var cipher, userPassword;
  14076. if (revision >= 3) {
  14077. userPassword = ownerPassword;
  14078. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14079. for (j = 19; j >= 0; j--) {
  14080. for (k = 0; k < keyLengthInBytes; ++k) {
  14081. derivedKey[k] = hash[k] ^ j;
  14082. }
  14083. cipher = new ARCFourCipher(derivedKey);
  14084. userPassword = cipher.encryptBlock(userPassword);
  14085. }
  14086. } else {
  14087. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14088. userPassword = cipher.encryptBlock(ownerPassword);
  14089. }
  14090. return userPassword;
  14091. }
  14092. var identityName = Name.get('Identity');
  14093. function CipherTransformFactory(dict, fileId, password) {
  14094. var filter = dict.get('Filter');
  14095. if (!isName(filter) || filter.name !== 'Standard') {
  14096. error('unknown encryption method');
  14097. }
  14098. this.dict = dict;
  14099. var algorithm = dict.get('V');
  14100. if (!isInt(algorithm) ||
  14101. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14102. algorithm !== 5)) {
  14103. error('unsupported encryption algorithm');
  14104. }
  14105. this.algorithm = algorithm;
  14106. var keyLength = dict.get('Length') || 40;
  14107. if (!isInt(keyLength) ||
  14108. keyLength < 40 || (keyLength % 8) !== 0) {
  14109. error('invalid key length');
  14110. }
  14111. // prepare keys
  14112. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14113. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14114. var flags = dict.get('P');
  14115. var revision = dict.get('R');
  14116. // meaningful when V is 4 or 5
  14117. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14118. dict.get('EncryptMetadata') !== false);
  14119. this.encryptMetadata = encryptMetadata;
  14120. var fileIdBytes = stringToBytes(fileId);
  14121. var passwordBytes;
  14122. if (password) {
  14123. passwordBytes = stringToBytes(password);
  14124. }
  14125. var encryptionKey;
  14126. if (algorithm !== 5) {
  14127. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14128. ownerPassword, userPassword, flags,
  14129. revision, keyLength, encryptMetadata);
  14130. }
  14131. else {
  14132. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14133. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14134. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14135. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14136. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14137. var ownerEncryption = stringToBytes(dict.get('OE'));
  14138. var userEncryption = stringToBytes(dict.get('UE'));
  14139. var perms = stringToBytes(dict.get('Perms'));
  14140. encryptionKey =
  14141. createEncryptionKey20(revision, passwordBytes,
  14142. ownerPassword, ownerValidationSalt,
  14143. ownerKeySalt, uBytes,
  14144. userPassword, userValidationSalt,
  14145. userKeySalt, ownerEncryption,
  14146. userEncryption, perms);
  14147. }
  14148. if (!encryptionKey && !password) {
  14149. throw new PasswordException('No password given',
  14150. PasswordResponses.NEED_PASSWORD);
  14151. } else if (!encryptionKey && password) {
  14152. // Attempting use the password as an owner password
  14153. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14154. revision, keyLength);
  14155. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14156. ownerPassword, userPassword, flags,
  14157. revision, keyLength, encryptMetadata);
  14158. }
  14159. if (!encryptionKey) {
  14160. throw new PasswordException('Incorrect Password',
  14161. PasswordResponses.INCORRECT_PASSWORD);
  14162. }
  14163. this.encryptionKey = encryptionKey;
  14164. if (algorithm >= 4) {
  14165. this.cf = dict.get('CF');
  14166. this.stmf = dict.get('StmF') || identityName;
  14167. this.strf = dict.get('StrF') || identityName;
  14168. this.eff = dict.get('EFF') || this.strf;
  14169. }
  14170. }
  14171. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14172. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14173. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14174. key[i] = encryptionKey[i];
  14175. }
  14176. key[i++] = num & 0xFF;
  14177. key[i++] = (num >> 8) & 0xFF;
  14178. key[i++] = (num >> 16) & 0xFF;
  14179. key[i++] = gen & 0xFF;
  14180. key[i++] = (gen >> 8) & 0xFF;
  14181. if (isAes) {
  14182. key[i++] = 0x73;
  14183. key[i++] = 0x41;
  14184. key[i++] = 0x6C;
  14185. key[i++] = 0x54;
  14186. }
  14187. var hash = calculateMD5(key, 0, i);
  14188. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14189. }
  14190. function buildCipherConstructor(cf, name, num, gen, key) {
  14191. var cryptFilter = cf.get(name.name);
  14192. var cfm;
  14193. if (cryptFilter !== null && cryptFilter !== undefined) {
  14194. cfm = cryptFilter.get('CFM');
  14195. }
  14196. if (!cfm || cfm.name === 'None') {
  14197. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14198. return new NullCipher();
  14199. };
  14200. }
  14201. if ('V2' === cfm.name) {
  14202. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14203. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14204. };
  14205. }
  14206. if ('AESV2' === cfm.name) {
  14207. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14208. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14209. };
  14210. }
  14211. if ('AESV3' === cfm.name) {
  14212. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14213. return new AES256Cipher(key);
  14214. };
  14215. }
  14216. error('Unknown crypto method');
  14217. }
  14218. CipherTransformFactory.prototype = {
  14219. createCipherTransform:
  14220. function CipherTransformFactory_createCipherTransform(num, gen) {
  14221. if (this.algorithm === 4 || this.algorithm === 5) {
  14222. return new CipherTransform(
  14223. buildCipherConstructor(this.cf, this.stmf,
  14224. num, gen, this.encryptionKey),
  14225. buildCipherConstructor(this.cf, this.strf,
  14226. num, gen, this.encryptionKey));
  14227. }
  14228. // algorithms 1 and 2
  14229. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14230. var cipherConstructor = function buildCipherCipherConstructor() {
  14231. return new ARCFourCipher(key);
  14232. };
  14233. return new CipherTransform(cipherConstructor, cipherConstructor);
  14234. }
  14235. };
  14236. return CipherTransformFactory;
  14237. })();
  14238. var PatternType = {
  14239. FUNCTION_BASED: 1,
  14240. AXIAL: 2,
  14241. RADIAL: 3,
  14242. FREE_FORM_MESH: 4,
  14243. LATTICE_FORM_MESH: 5,
  14244. COONS_PATCH_MESH: 6,
  14245. TENSOR_PATCH_MESH: 7
  14246. };
  14247. var Pattern = (function PatternClosure() {
  14248. // Constructor should define this.getPattern
  14249. function Pattern() {
  14250. error('should not call Pattern constructor');
  14251. }
  14252. Pattern.prototype = {
  14253. // Input: current Canvas context
  14254. // Output: the appropriate fillStyle or strokeStyle
  14255. getPattern: function Pattern_getPattern(ctx) {
  14256. error('Should not call Pattern.getStyle: ' + ctx);
  14257. }
  14258. };
  14259. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14260. res) {
  14261. var dict = isStream(shading) ? shading.dict : shading;
  14262. var type = dict.get('ShadingType');
  14263. switch (type) {
  14264. case PatternType.AXIAL:
  14265. case PatternType.RADIAL:
  14266. // Both radial and axial shadings are handled by RadialAxial shading.
  14267. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14268. case PatternType.FREE_FORM_MESH:
  14269. case PatternType.LATTICE_FORM_MESH:
  14270. case PatternType.COONS_PATCH_MESH:
  14271. case PatternType.TENSOR_PATCH_MESH:
  14272. return new Shadings.Mesh(shading, matrix, xref, res);
  14273. default:
  14274. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14275. return new Shadings.Dummy();
  14276. }
  14277. };
  14278. return Pattern;
  14279. })();
  14280. var Shadings = {};
  14281. // A small number to offset the first/last color stops so we can insert ones to
  14282. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14283. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14284. // internally so we have to go bigger.
  14285. Shadings.SMALL_NUMBER = 1e-2;
  14286. // Radial and axial shading have very similar implementations
  14287. // If needed, the implementations can be broken into two classes
  14288. Shadings.RadialAxial = (function RadialAxialClosure() {
  14289. function RadialAxial(dict, matrix, xref, res) {
  14290. this.matrix = matrix;
  14291. this.coordsArr = dict.get('Coords');
  14292. this.shadingType = dict.get('ShadingType');
  14293. this.type = 'Pattern';
  14294. var cs = dict.get('ColorSpace', 'CS');
  14295. cs = ColorSpace.parse(cs, xref, res);
  14296. this.cs = cs;
  14297. var t0 = 0.0, t1 = 1.0;
  14298. if (dict.has('Domain')) {
  14299. var domainArr = dict.get('Domain');
  14300. t0 = domainArr[0];
  14301. t1 = domainArr[1];
  14302. }
  14303. var extendStart = false, extendEnd = false;
  14304. if (dict.has('Extend')) {
  14305. var extendArr = dict.get('Extend');
  14306. extendStart = extendArr[0];
  14307. extendEnd = extendArr[1];
  14308. }
  14309. if (this.shadingType === PatternType.RADIAL &&
  14310. (!extendStart || !extendEnd)) {
  14311. // Radial gradient only currently works if either circle is fully within
  14312. // the other circle.
  14313. var x1 = this.coordsArr[0];
  14314. var y1 = this.coordsArr[1];
  14315. var r1 = this.coordsArr[2];
  14316. var x2 = this.coordsArr[3];
  14317. var y2 = this.coordsArr[4];
  14318. var r2 = this.coordsArr[5];
  14319. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14320. if (r1 <= r2 + distance &&
  14321. r2 <= r1 + distance) {
  14322. warn('Unsupported radial gradient.');
  14323. }
  14324. }
  14325. this.extendStart = extendStart;
  14326. this.extendEnd = extendEnd;
  14327. var fnObj = dict.get('Function');
  14328. var fn = PDFFunction.parseArray(xref, fnObj);
  14329. // 10 samples seems good enough for now, but probably won't work
  14330. // if there are sharp color changes. Ideally, we would implement
  14331. // the spec faithfully and add lossless optimizations.
  14332. var diff = t1 - t0;
  14333. var step = diff / 10;
  14334. var colorStops = this.colorStops = [];
  14335. // Protect against bad domains so we don't end up in an infinte loop below.
  14336. if (t0 >= t1 || step <= 0) {
  14337. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14338. // now.
  14339. info('Bad shading domain.');
  14340. return;
  14341. }
  14342. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14343. var rgbColor;
  14344. for (var i = t0; i <= t1; i += step) {
  14345. ratio[0] = i;
  14346. fn(ratio, 0, color, 0);
  14347. rgbColor = cs.getRgb(color, 0);
  14348. var cssColor = Util.makeCssRgb(rgbColor);
  14349. colorStops.push([(i - t0) / diff, cssColor]);
  14350. }
  14351. var background = 'transparent';
  14352. if (dict.has('Background')) {
  14353. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14354. background = Util.makeCssRgb(rgbColor);
  14355. }
  14356. if (!extendStart) {
  14357. // Insert a color stop at the front and offset the first real color stop
  14358. // so it doesn't conflict with the one we insert.
  14359. colorStops.unshift([0, background]);
  14360. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14361. }
  14362. if (!extendEnd) {
  14363. // Same idea as above in extendStart but for the end.
  14364. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14365. colorStops.push([1, background]);
  14366. }
  14367. this.colorStops = colorStops;
  14368. }
  14369. RadialAxial.prototype = {
  14370. getIR: function RadialAxial_getIR() {
  14371. var coordsArr = this.coordsArr;
  14372. var shadingType = this.shadingType;
  14373. var type, p0, p1, r0, r1;
  14374. if (shadingType === PatternType.AXIAL) {
  14375. p0 = [coordsArr[0], coordsArr[1]];
  14376. p1 = [coordsArr[2], coordsArr[3]];
  14377. r0 = null;
  14378. r1 = null;
  14379. type = 'axial';
  14380. } else if (shadingType === PatternType.RADIAL) {
  14381. p0 = [coordsArr[0], coordsArr[1]];
  14382. p1 = [coordsArr[3], coordsArr[4]];
  14383. r0 = coordsArr[2];
  14384. r1 = coordsArr[5];
  14385. type = 'radial';
  14386. } else {
  14387. error('getPattern type unknown: ' + shadingType);
  14388. }
  14389. var matrix = this.matrix;
  14390. if (matrix) {
  14391. p0 = Util.applyTransform(p0, matrix);
  14392. p1 = Util.applyTransform(p1, matrix);
  14393. }
  14394. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14395. }
  14396. };
  14397. return RadialAxial;
  14398. })();
  14399. // All mesh shading. For now, they will be presented as set of the triangles
  14400. // to be drawn on the canvas and rgb color for each vertex.
  14401. Shadings.Mesh = (function MeshClosure() {
  14402. function MeshStreamReader(stream, context) {
  14403. this.stream = stream;
  14404. this.context = context;
  14405. this.buffer = 0;
  14406. this.bufferLength = 0;
  14407. var numComps = context.numComps;
  14408. this.tmpCompsBuf = new Float32Array(numComps);
  14409. var csNumComps = context.colorSpace;
  14410. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14411. this.tmpCompsBuf;
  14412. }
  14413. MeshStreamReader.prototype = {
  14414. get hasData() {
  14415. if (this.stream.end) {
  14416. return this.stream.pos < this.stream.end;
  14417. }
  14418. if (this.bufferLength > 0) {
  14419. return true;
  14420. }
  14421. var nextByte = this.stream.getByte();
  14422. if (nextByte < 0) {
  14423. return false;
  14424. }
  14425. this.buffer = nextByte;
  14426. this.bufferLength = 8;
  14427. return true;
  14428. },
  14429. readBits: function MeshStreamReader_readBits(n) {
  14430. var buffer = this.buffer;
  14431. var bufferLength = this.bufferLength;
  14432. if (n === 32) {
  14433. if (bufferLength === 0) {
  14434. return ((this.stream.getByte() << 24) |
  14435. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14436. this.stream.getByte()) >>> 0;
  14437. }
  14438. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14439. (this.stream.getByte() << 8) | this.stream.getByte();
  14440. var nextByte = this.stream.getByte();
  14441. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14442. return ((buffer << (8 - bufferLength)) |
  14443. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14444. }
  14445. if (n === 8 && bufferLength === 0) {
  14446. return this.stream.getByte();
  14447. }
  14448. while (bufferLength < n) {
  14449. buffer = (buffer << 8) | this.stream.getByte();
  14450. bufferLength += 8;
  14451. }
  14452. bufferLength -= n;
  14453. this.bufferLength = bufferLength;
  14454. this.buffer = buffer & ((1 << bufferLength) - 1);
  14455. return buffer >> bufferLength;
  14456. },
  14457. align: function MeshStreamReader_align() {
  14458. this.buffer = 0;
  14459. this.bufferLength = 0;
  14460. },
  14461. readFlag: function MeshStreamReader_readFlag() {
  14462. return this.readBits(this.context.bitsPerFlag);
  14463. },
  14464. readCoordinate: function MeshStreamReader_readCoordinate() {
  14465. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14466. var xi = this.readBits(bitsPerCoordinate);
  14467. var yi = this.readBits(bitsPerCoordinate);
  14468. var decode = this.context.decode;
  14469. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14470. 2.3283064365386963e-10; // 2 ^ -32
  14471. return [
  14472. xi * scale * (decode[1] - decode[0]) + decode[0],
  14473. yi * scale * (decode[3] - decode[2]) + decode[2]
  14474. ];
  14475. },
  14476. readComponents: function MeshStreamReader_readComponents() {
  14477. var numComps = this.context.numComps;
  14478. var bitsPerComponent = this.context.bitsPerComponent;
  14479. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14480. 2.3283064365386963e-10; // 2 ^ -32
  14481. var decode = this.context.decode;
  14482. var components = this.tmpCompsBuf;
  14483. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14484. var ci = this.readBits(bitsPerComponent);
  14485. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14486. }
  14487. var color = this.tmpCsCompsBuf;
  14488. if (this.context.colorFn) {
  14489. this.context.colorFn(components, 0, color, 0);
  14490. }
  14491. return this.context.colorSpace.getRgb(color, 0);
  14492. }
  14493. };
  14494. function decodeType4Shading(mesh, reader) {
  14495. var coords = mesh.coords;
  14496. var colors = mesh.colors;
  14497. var operators = [];
  14498. var ps = []; // not maintaining cs since that will match ps
  14499. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14500. while (reader.hasData) {
  14501. var f = reader.readFlag();
  14502. var coord = reader.readCoordinate();
  14503. var color = reader.readComponents();
  14504. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14505. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14506. switch (f) {
  14507. case 0:
  14508. verticesLeft = 3;
  14509. break;
  14510. case 1:
  14511. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14512. verticesLeft = 1;
  14513. break;
  14514. case 2:
  14515. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14516. verticesLeft = 1;
  14517. break;
  14518. }
  14519. operators.push(f);
  14520. }
  14521. ps.push(coords.length);
  14522. coords.push(coord);
  14523. colors.push(color);
  14524. verticesLeft--;
  14525. reader.align();
  14526. }
  14527. var psPacked = new Int32Array(ps);
  14528. mesh.figures.push({
  14529. type: 'triangles',
  14530. coords: psPacked,
  14531. colors: psPacked
  14532. });
  14533. }
  14534. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14535. var coords = mesh.coords;
  14536. var colors = mesh.colors;
  14537. var ps = []; // not maintaining cs since that will match ps
  14538. while (reader.hasData) {
  14539. var coord = reader.readCoordinate();
  14540. var color = reader.readComponents();
  14541. ps.push(coords.length);
  14542. coords.push(coord);
  14543. colors.push(color);
  14544. }
  14545. var psPacked = new Int32Array(ps);
  14546. mesh.figures.push({
  14547. type: 'lattice',
  14548. coords: psPacked,
  14549. colors: psPacked,
  14550. verticesPerRow: verticesPerRow
  14551. });
  14552. }
  14553. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14554. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14555. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14556. var getB = (function getBClosure() {
  14557. function buildB(count) {
  14558. var lut = [];
  14559. for (var i = 0; i <= count; i++) {
  14560. var t = i / count, t_ = 1 - t;
  14561. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14562. 3 * t * t * t_, t * t * t]));
  14563. }
  14564. return lut;
  14565. }
  14566. var cache = [];
  14567. return function getB(count) {
  14568. if (!cache[count]) {
  14569. cache[count] = buildB(count);
  14570. }
  14571. return cache[count];
  14572. };
  14573. })();
  14574. function buildFigureFromPatch(mesh, index) {
  14575. var figure = mesh.figures[index];
  14576. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14577. var coords = mesh.coords, colors = mesh.colors;
  14578. var pi = figure.coords;
  14579. var ci = figure.colors;
  14580. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14581. coords[pi[12]][0], coords[pi[15]][0]);
  14582. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14583. coords[pi[12]][1], coords[pi[15]][1]);
  14584. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14585. coords[pi[12]][0], coords[pi[15]][0]);
  14586. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14587. coords[pi[12]][1], coords[pi[15]][1]);
  14588. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14589. (mesh.bounds[2] - mesh.bounds[0]));
  14590. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14591. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14592. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14593. (mesh.bounds[3] - mesh.bounds[1]));
  14594. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14595. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14596. var verticesPerRow = splitXBy + 1;
  14597. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14598. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14599. var k = 0;
  14600. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14601. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14602. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14603. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14604. for (var row = 0; row <= splitYBy; row++) {
  14605. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14606. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14607. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14608. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14609. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14610. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14611. for (var col = 0; col <= splitXBy; col++, k++) {
  14612. if ((row === 0 || row === splitYBy) &&
  14613. (col === 0 || col === splitXBy)) {
  14614. continue;
  14615. }
  14616. var x = 0, y = 0;
  14617. var q = 0;
  14618. for (var i = 0; i <= 3; i++) {
  14619. for (var j = 0; j <= 3; j++, q++) {
  14620. var m = bRow[row][i] * bCol[col][j];
  14621. x += coords[pi[q]][0] * m;
  14622. y += coords[pi[q]][1] * m;
  14623. }
  14624. }
  14625. figureCoords[k] = coords.length;
  14626. coords.push([x, y]);
  14627. figureColors[k] = colors.length;
  14628. var newColor = new Uint8Array(3);
  14629. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14630. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14631. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14632. colors.push(newColor);
  14633. }
  14634. }
  14635. figureCoords[0] = pi[0];
  14636. figureColors[0] = ci[0];
  14637. figureCoords[splitXBy] = pi[3];
  14638. figureColors[splitXBy] = ci[1];
  14639. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14640. figureColors[verticesPerRow * splitYBy] = ci[2];
  14641. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14642. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14643. mesh.figures[index] = {
  14644. type: 'lattice',
  14645. coords: figureCoords,
  14646. colors: figureColors,
  14647. verticesPerRow: verticesPerRow
  14648. };
  14649. }
  14650. function decodeType6Shading(mesh, reader) {
  14651. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14652. var coords = mesh.coords;
  14653. var colors = mesh.colors;
  14654. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14655. var cs = new Int32Array(4); // c00, c30, c03, c33
  14656. while (reader.hasData) {
  14657. var f = reader.readFlag();
  14658. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14659. var i, ii;
  14660. var pi = coords.length;
  14661. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14662. coords.push(reader.readCoordinate());
  14663. }
  14664. var ci = colors.length;
  14665. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14666. colors.push(reader.readComponents());
  14667. }
  14668. var tmp1, tmp2, tmp3, tmp4;
  14669. switch (f) {
  14670. case 0:
  14671. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14672. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14673. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14674. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14675. cs[2] = ci + 1; cs[3] = ci + 2;
  14676. cs[0] = ci; cs[1] = ci + 3;
  14677. break;
  14678. case 1:
  14679. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14680. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14681. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14682. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14683. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14684. tmp1 = cs[2]; tmp2 = cs[3];
  14685. cs[2] = ci + 1; cs[3] = ci;
  14686. cs[0] = tmp1; cs[1] = tmp2;
  14687. break;
  14688. case 2:
  14689. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14690. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14691. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14692. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14693. cs[2] = cs[3]; cs[3] = ci + 1;
  14694. cs[0] = cs[1]; cs[1] = ci;
  14695. break;
  14696. case 3:
  14697. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14698. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14699. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14700. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14701. cs[2] = cs[0]; cs[3] = cs[1];
  14702. cs[0] = ci; cs[1] = ci + 1;
  14703. break;
  14704. }
  14705. // set p11, p12, p21, p22
  14706. ps[5] = coords.length;
  14707. coords.push([
  14708. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14709. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14710. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14711. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14712. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14713. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14714. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14715. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14716. ]);
  14717. ps[6] = coords.length;
  14718. coords.push([
  14719. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14720. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14721. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14722. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14723. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14724. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14725. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14726. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14727. ]);
  14728. ps[9] = coords.length;
  14729. coords.push([
  14730. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14731. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14732. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14733. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14734. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14735. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14736. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14737. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14738. ]);
  14739. ps[10] = coords.length;
  14740. coords.push([
  14741. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14742. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14743. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14744. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14745. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14746. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14747. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14748. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14749. ]);
  14750. mesh.figures.push({
  14751. type: 'patch',
  14752. coords: new Int32Array(ps), // making copies of ps and cs
  14753. colors: new Int32Array(cs)
  14754. });
  14755. }
  14756. }
  14757. function decodeType7Shading(mesh, reader) {
  14758. var coords = mesh.coords;
  14759. var colors = mesh.colors;
  14760. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14761. var cs = new Int32Array(4); // c00, c30, c03, c33
  14762. while (reader.hasData) {
  14763. var f = reader.readFlag();
  14764. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  14765. var i, ii;
  14766. var pi = coords.length;
  14767. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  14768. coords.push(reader.readCoordinate());
  14769. }
  14770. var ci = colors.length;
  14771. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14772. colors.push(reader.readComponents());
  14773. }
  14774. var tmp1, tmp2, tmp3, tmp4;
  14775. switch (f) {
  14776. case 0:
  14777. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14778. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  14779. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  14780. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14781. cs[2] = ci + 1; cs[3] = ci + 2;
  14782. cs[0] = ci; cs[1] = ci + 3;
  14783. break;
  14784. case 1:
  14785. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14786. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14787. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  14788. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  14789. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14790. tmp1 = cs[2]; tmp2 = cs[3];
  14791. cs[2] = ci + 1; cs[3] = ci;
  14792. cs[0] = tmp1; cs[1] = tmp2;
  14793. break;
  14794. case 2:
  14795. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14796. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  14797. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  14798. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14799. cs[2] = cs[3]; cs[3] = ci + 1;
  14800. cs[0] = cs[1]; cs[1] = ci;
  14801. break;
  14802. case 3:
  14803. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14804. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  14805. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  14806. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14807. cs[2] = cs[0]; cs[3] = cs[1];
  14808. cs[0] = ci; cs[1] = ci + 1;
  14809. break;
  14810. }
  14811. mesh.figures.push({
  14812. type: 'patch',
  14813. coords: new Int32Array(ps), // making copies of ps and cs
  14814. colors: new Int32Array(cs)
  14815. });
  14816. }
  14817. }
  14818. function updateBounds(mesh) {
  14819. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  14820. maxX = minX, maxY = minY;
  14821. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  14822. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  14823. minX = minX > x ? x : minX;
  14824. minY = minY > y ? y : minY;
  14825. maxX = maxX < x ? x : maxX;
  14826. maxY = maxY < y ? y : maxY;
  14827. }
  14828. mesh.bounds = [minX, minY, maxX, maxY];
  14829. }
  14830. function packData(mesh) {
  14831. var i, ii, j, jj;
  14832. var coords = mesh.coords;
  14833. var coordsPacked = new Float32Array(coords.length * 2);
  14834. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  14835. var xy = coords[i];
  14836. coordsPacked[j++] = xy[0];
  14837. coordsPacked[j++] = xy[1];
  14838. }
  14839. mesh.coords = coordsPacked;
  14840. var colors = mesh.colors;
  14841. var colorsPacked = new Uint8Array(colors.length * 3);
  14842. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  14843. var c = colors[i];
  14844. colorsPacked[j++] = c[0];
  14845. colorsPacked[j++] = c[1];
  14846. colorsPacked[j++] = c[2];
  14847. }
  14848. mesh.colors = colorsPacked;
  14849. var figures = mesh.figures;
  14850. for (i = 0, ii = figures.length; i < ii; i++) {
  14851. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  14852. for (j = 0, jj = ps.length; j < jj; j++) {
  14853. ps[j] *= 2;
  14854. cs[j] *= 3;
  14855. }
  14856. }
  14857. }
  14858. function Mesh(stream, matrix, xref, res) {
  14859. assert(isStream(stream), 'Mesh data is not a stream');
  14860. var dict = stream.dict;
  14861. this.matrix = matrix;
  14862. this.shadingType = dict.get('ShadingType');
  14863. this.type = 'Pattern';
  14864. this.bbox = dict.get('BBox');
  14865. var cs = dict.get('ColorSpace', 'CS');
  14866. cs = ColorSpace.parse(cs, xref, res);
  14867. this.cs = cs;
  14868. this.background = dict.has('Background') ?
  14869. cs.getRgb(dict.get('Background'), 0) : null;
  14870. var fnObj = dict.get('Function');
  14871. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  14872. this.coords = [];
  14873. this.colors = [];
  14874. this.figures = [];
  14875. var decodeContext = {
  14876. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  14877. bitsPerComponent: dict.get('BitsPerComponent'),
  14878. bitsPerFlag: dict.get('BitsPerFlag'),
  14879. decode: dict.get('Decode'),
  14880. colorFn: fn,
  14881. colorSpace: cs,
  14882. numComps: fn ? 1 : cs.numComps
  14883. };
  14884. var reader = new MeshStreamReader(stream, decodeContext);
  14885. var patchMesh = false;
  14886. switch (this.shadingType) {
  14887. case PatternType.FREE_FORM_MESH:
  14888. decodeType4Shading(this, reader);
  14889. break;
  14890. case PatternType.LATTICE_FORM_MESH:
  14891. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  14892. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  14893. decodeType5Shading(this, reader, verticesPerRow);
  14894. break;
  14895. case PatternType.COONS_PATCH_MESH:
  14896. decodeType6Shading(this, reader);
  14897. patchMesh = true;
  14898. break;
  14899. case PatternType.TENSOR_PATCH_MESH:
  14900. decodeType7Shading(this, reader);
  14901. patchMesh = true;
  14902. break;
  14903. default:
  14904. error('Unsupported mesh type.');
  14905. break;
  14906. }
  14907. if (patchMesh) {
  14908. // dirty bounds calculation for determining, how dense shall be triangles
  14909. updateBounds(this);
  14910. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  14911. buildFigureFromPatch(this, i);
  14912. }
  14913. }
  14914. // calculate bounds
  14915. updateBounds(this);
  14916. packData(this);
  14917. }
  14918. Mesh.prototype = {
  14919. getIR: function Mesh_getIR() {
  14920. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  14921. this.bounds, this.matrix, this.bbox, this.background];
  14922. }
  14923. };
  14924. return Mesh;
  14925. })();
  14926. Shadings.Dummy = (function DummyClosure() {
  14927. function Dummy() {
  14928. this.type = 'Pattern';
  14929. }
  14930. Dummy.prototype = {
  14931. getIR: function Dummy_getIR() {
  14932. return ['Dummy'];
  14933. }
  14934. };
  14935. return Dummy;
  14936. })();
  14937. function getTilingPatternIR(operatorList, dict, args) {
  14938. var matrix = dict.get('Matrix');
  14939. var bbox = dict.get('BBox');
  14940. var xstep = dict.get('XStep');
  14941. var ystep = dict.get('YStep');
  14942. var paintType = dict.get('PaintType');
  14943. var tilingType = dict.get('TilingType');
  14944. return [
  14945. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  14946. paintType, tilingType
  14947. ];
  14948. }
  14949. var PartialEvaluator = (function PartialEvaluatorClosure() {
  14950. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  14951. uniquePrefix, idCounters, fontCache) {
  14952. this.pdfManager = pdfManager;
  14953. this.xref = xref;
  14954. this.handler = handler;
  14955. this.pageIndex = pageIndex;
  14956. this.uniquePrefix = uniquePrefix;
  14957. this.idCounters = idCounters;
  14958. this.fontCache = fontCache;
  14959. }
  14960. // Trying to minimize Date.now() usage and check every 100 time
  14961. var TIME_SLOT_DURATION_MS = 20;
  14962. var CHECK_TIME_EVERY = 100;
  14963. function TimeSlotManager() {
  14964. this.reset();
  14965. }
  14966. TimeSlotManager.prototype = {
  14967. check: function TimeSlotManager_check() {
  14968. if (++this.checked < CHECK_TIME_EVERY) {
  14969. return false;
  14970. }
  14971. this.checked = 0;
  14972. return this.endTime <= Date.now();
  14973. },
  14974. reset: function TimeSlotManager_reset() {
  14975. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  14976. this.checked = 0;
  14977. }
  14978. };
  14979. var deferred = Promise.resolve();
  14980. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  14981. PartialEvaluator.prototype = {
  14982. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  14983. if (!isDict(resources)) {
  14984. return false;
  14985. }
  14986. var processed = Object.create(null);
  14987. if (resources.objId) {
  14988. processed[resources.objId] = true;
  14989. }
  14990. var nodes = [resources];
  14991. while (nodes.length) {
  14992. var key;
  14993. var node = nodes.shift();
  14994. // First check the current resources for blend modes.
  14995. var graphicStates = node.get('ExtGState');
  14996. if (isDict(graphicStates)) {
  14997. graphicStates = graphicStates.getAll();
  14998. for (key in graphicStates) {
  14999. var graphicState = graphicStates[key];
  15000. var bm = graphicState['BM'];
  15001. if (isName(bm) && bm.name !== 'Normal') {
  15002. return true;
  15003. }
  15004. }
  15005. }
  15006. // Descend into the XObjects to look for more resources and blend modes.
  15007. var xObjects = node.get('XObject');
  15008. if (!isDict(xObjects)) {
  15009. continue;
  15010. }
  15011. xObjects = xObjects.getAll();
  15012. for (key in xObjects) {
  15013. var xObject = xObjects[key];
  15014. if (!isStream(xObject)) {
  15015. continue;
  15016. }
  15017. if (xObject.dict.objId) {
  15018. if (processed[xObject.dict.objId]) {
  15019. // stream has objId and is processed already
  15020. continue;
  15021. }
  15022. processed[xObject.dict.objId] = true;
  15023. }
  15024. var xResources = xObject.dict.get('Resources');
  15025. // Checking objId to detect an infinite loop.
  15026. if (isDict(xResources) &&
  15027. (!xResources.objId || !processed[xResources.objId])) {
  15028. nodes.push(xResources);
  15029. if (xResources.objId) {
  15030. processed[xResources.objId] = true;
  15031. }
  15032. }
  15033. }
  15034. }
  15035. return false;
  15036. },
  15037. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15038. xobj, smask,
  15039. operatorList,
  15040. initialState) {
  15041. var matrix = xobj.dict.get('Matrix');
  15042. var bbox = xobj.dict.get('BBox');
  15043. var group = xobj.dict.get('Group');
  15044. if (group) {
  15045. var groupOptions = {
  15046. matrix: matrix,
  15047. bbox: bbox,
  15048. smask: smask,
  15049. isolated: false,
  15050. knockout: false
  15051. };
  15052. var groupSubtype = group.get('S');
  15053. var colorSpace;
  15054. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15055. groupOptions.isolated = (group.get('I') || false);
  15056. groupOptions.knockout = (group.get('K') || false);
  15057. colorSpace = (group.has('CS') ?
  15058. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15059. }
  15060. if (smask && smask.backdrop) {
  15061. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15062. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15063. }
  15064. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15065. }
  15066. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15067. return this.getOperatorList(xobj,
  15068. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15069. then(function () {
  15070. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15071. if (group) {
  15072. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15073. }
  15074. });
  15075. },
  15076. buildPaintImageXObject:
  15077. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15078. inline, operatorList,
  15079. cacheKey, cache) {
  15080. var self = this;
  15081. var dict = image.dict;
  15082. var w = dict.get('Width', 'W');
  15083. var h = dict.get('Height', 'H');
  15084. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15085. warn('Image dimensions are missing, or not numbers.');
  15086. return;
  15087. }
  15088. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15089. warn('Image exceeded maximum allowed size and was removed.');
  15090. return;
  15091. }
  15092. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15093. var imgData, args;
  15094. if (imageMask) {
  15095. // This depends on a tmpCanvas being filled with the
  15096. // current fillStyle, such that processing the pixel
  15097. // data can't be done here. Instead of creating a
  15098. // complete PDFImage, only read the information needed
  15099. // for later.
  15100. var width = dict.get('Width', 'W');
  15101. var height = dict.get('Height', 'H');
  15102. var bitStrideLength = (width + 7) >> 3;
  15103. var imgArray = image.getBytes(bitStrideLength * height);
  15104. var decode = dict.get('Decode', 'D');
  15105. var inverseDecode = (!!decode && decode[0] > 0);
  15106. imgData = PDFImage.createMask(imgArray, width, height,
  15107. image instanceof DecodeStream,
  15108. inverseDecode);
  15109. imgData.cached = true;
  15110. args = [imgData];
  15111. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15112. if (cacheKey) {
  15113. cache.key = cacheKey;
  15114. cache.fn = OPS.paintImageMaskXObject;
  15115. cache.args = args;
  15116. }
  15117. return;
  15118. }
  15119. var softMask = (dict.get('SMask', 'SM') || false);
  15120. var mask = (dict.get('Mask') || false);
  15121. var SMALL_IMAGE_DIMENSIONS = 200;
  15122. // Inlining small images into the queue as RGB data
  15123. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15124. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15125. var imageObj = new PDFImage(this.xref, resources, image,
  15126. inline, null, null);
  15127. // We force the use of RGBA_32BPP images here, because we can't handle
  15128. // any other kind.
  15129. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15130. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15131. return;
  15132. }
  15133. // If there is no imageMask, create the PDFImage and a lot
  15134. // of image processing can be done here.
  15135. var uniquePrefix = (this.uniquePrefix || '');
  15136. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15137. operatorList.addDependency(objId);
  15138. args = [objId, w, h];
  15139. if (!softMask && !mask && image instanceof JpegStream &&
  15140. image.isNativelySupported(this.xref, resources)) {
  15141. // These JPEGs don't need any more processing so we can just send it.
  15142. operatorList.addOp(OPS.paintJpegXObject, args);
  15143. this.handler.send('obj',
  15144. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15145. return;
  15146. }
  15147. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15148. then(function(imageObj) {
  15149. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15150. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15151. [imgData.data.buffer]);
  15152. }).then(null, function (reason) {
  15153. warn('Unable to decode image: ' + reason);
  15154. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15155. });
  15156. operatorList.addOp(OPS.paintImageXObject, args);
  15157. if (cacheKey) {
  15158. cache.key = cacheKey;
  15159. cache.fn = OPS.paintImageXObject;
  15160. cache.args = args;
  15161. }
  15162. },
  15163. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15164. operatorList,
  15165. stateManager) {
  15166. var smaskContent = smask.get('G');
  15167. var smaskOptions = {
  15168. subtype: smask.get('S').name,
  15169. backdrop: smask.get('BC')
  15170. };
  15171. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15172. operatorList, stateManager.state.clone());
  15173. },
  15174. handleTilingType:
  15175. function PartialEvaluator_handleTilingType(fn, args, resources,
  15176. pattern, patternDict,
  15177. operatorList) {
  15178. // Create an IR of the pattern code.
  15179. var tilingOpList = new OperatorList();
  15180. return this.getOperatorList(pattern,
  15181. (patternDict.get('Resources') || resources), tilingOpList).
  15182. then(function () {
  15183. // Add the dependencies to the parent operator list so they are
  15184. // resolved before sub operator list is executed synchronously.
  15185. operatorList.addDependencies(tilingOpList.dependencies);
  15186. operatorList.addOp(fn, getTilingPatternIR({
  15187. fnArray: tilingOpList.fnArray,
  15188. argsArray: tilingOpList.argsArray
  15189. }, patternDict, args));
  15190. });
  15191. },
  15192. handleSetFont:
  15193. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15194. operatorList, state) {
  15195. // TODO(mack): Not needed?
  15196. var fontName;
  15197. if (fontArgs) {
  15198. fontArgs = fontArgs.slice();
  15199. fontName = fontArgs[0].name;
  15200. }
  15201. var self = this;
  15202. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15203. function (translated) {
  15204. if (!translated.font.isType3Font) {
  15205. return translated;
  15206. }
  15207. return translated.loadType3Data(self, resources, operatorList).then(
  15208. function () {
  15209. return translated;
  15210. });
  15211. }).then(function (translated) {
  15212. state.font = translated.font;
  15213. translated.send(self.handler);
  15214. return translated.loadedName;
  15215. });
  15216. },
  15217. handleText: function PartialEvaluator_handleText(chars, state) {
  15218. var font = state.font;
  15219. var glyphs = font.charsToGlyphs(chars);
  15220. var isAddToPathSet = !!(state.textRenderingMode &
  15221. TextRenderingMode.ADD_TO_PATH_FLAG);
  15222. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15223. var buildPath = function (fontChar) {
  15224. if (!font.renderer.hasBuiltPath(fontChar)) {
  15225. var path = font.renderer.getPathJs(fontChar);
  15226. this.handler.send('commonobj', [
  15227. font.loadedName + '_path_' + fontChar,
  15228. 'FontPath',
  15229. path
  15230. ]);
  15231. }
  15232. }.bind(this);
  15233. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15234. var glyph = glyphs[i];
  15235. if (glyph === null) {
  15236. continue;
  15237. }
  15238. buildPath(glyph.fontChar);
  15239. // If the glyph has an accent we need to build a path for its
  15240. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15241. var accent = glyph.accent;
  15242. if (accent && accent.fontChar) {
  15243. buildPath(accent.fontChar);
  15244. }
  15245. }
  15246. }
  15247. return glyphs;
  15248. },
  15249. setGState: function PartialEvaluator_setGState(resources, gState,
  15250. operatorList, xref,
  15251. stateManager) {
  15252. // This array holds the converted/processed state data.
  15253. var gStateObj = [];
  15254. var gStateMap = gState.map;
  15255. var self = this;
  15256. var promise = Promise.resolve();
  15257. for (var key in gStateMap) {
  15258. var value = gStateMap[key];
  15259. switch (key) {
  15260. case 'Type':
  15261. break;
  15262. case 'LW':
  15263. case 'LC':
  15264. case 'LJ':
  15265. case 'ML':
  15266. case 'D':
  15267. case 'RI':
  15268. case 'FL':
  15269. case 'CA':
  15270. case 'ca':
  15271. gStateObj.push([key, value]);
  15272. break;
  15273. case 'Font':
  15274. promise = promise.then(function () {
  15275. return self.handleSetFont(resources, null, value[0],
  15276. operatorList, stateManager.state).
  15277. then(function (loadedName) {
  15278. operatorList.addDependency(loadedName);
  15279. gStateObj.push([key, [loadedName, value[1]]]);
  15280. });
  15281. });
  15282. break;
  15283. case 'BM':
  15284. gStateObj.push([key, value]);
  15285. break;
  15286. case 'SMask':
  15287. if (isName(value) && value.name === 'None') {
  15288. gStateObj.push([key, false]);
  15289. break;
  15290. }
  15291. var dict = xref.fetchIfRef(value);
  15292. if (isDict(dict)) {
  15293. promise = promise.then(function () {
  15294. return self.handleSMask(dict, resources, operatorList,
  15295. stateManager);
  15296. });
  15297. gStateObj.push([key, true]);
  15298. } else {
  15299. warn('Unsupported SMask type');
  15300. }
  15301. break;
  15302. // Only generate info log messages for the following since
  15303. // they are unlikely to have a big impact on the rendering.
  15304. case 'OP':
  15305. case 'op':
  15306. case 'OPM':
  15307. case 'BG':
  15308. case 'BG2':
  15309. case 'UCR':
  15310. case 'UCR2':
  15311. case 'TR':
  15312. case 'TR2':
  15313. case 'HT':
  15314. case 'SM':
  15315. case 'SA':
  15316. case 'AIS':
  15317. case 'TK':
  15318. // TODO implement these operators.
  15319. info('graphic state operator ' + key);
  15320. break;
  15321. default:
  15322. info('Unknown graphic state operator ' + key);
  15323. break;
  15324. }
  15325. }
  15326. return promise.then(function () {
  15327. if (gStateObj.length >= 0) {
  15328. operatorList.addOp(OPS.setGState, [gStateObj]);
  15329. }
  15330. });
  15331. },
  15332. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15333. resources) {
  15334. function errorFont() {
  15335. return Promise.resolve(new TranslatedFont('g_font_error',
  15336. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15337. }
  15338. var fontRef;
  15339. if (font) { // Loading by ref.
  15340. assert(isRef(font));
  15341. fontRef = font;
  15342. } else { // Loading by name.
  15343. var fontRes = resources.get('Font');
  15344. if (fontRes) {
  15345. fontRef = fontRes.getRaw(fontName);
  15346. } else {
  15347. warn('fontRes not available');
  15348. return errorFont();
  15349. }
  15350. }
  15351. if (!fontRef) {
  15352. warn('fontRef not available');
  15353. return errorFont();
  15354. }
  15355. if (this.fontCache.has(fontRef)) {
  15356. return this.fontCache.get(fontRef);
  15357. }
  15358. font = xref.fetchIfRef(fontRef);
  15359. if (!isDict(font)) {
  15360. return errorFont();
  15361. }
  15362. // We are holding font.translated references just for fontRef that are not
  15363. // dictionaries (Dict). See explanation below.
  15364. if (font.translated) {
  15365. return font.translated;
  15366. }
  15367. var fontCapability = createPromiseCapability();
  15368. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15369. var descriptor = preEvaluatedFont.descriptor;
  15370. var fontID = fontRef.num + '_' + fontRef.gen;
  15371. if (isDict(descriptor)) {
  15372. if (!descriptor.fontAliases) {
  15373. descriptor.fontAliases = Object.create(null);
  15374. }
  15375. var fontAliases = descriptor.fontAliases;
  15376. var hash = preEvaluatedFont.hash;
  15377. if (fontAliases[hash]) {
  15378. var aliasFontRef = fontAliases[hash].aliasRef;
  15379. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15380. this.fontCache.putAlias(fontRef, aliasFontRef);
  15381. return this.fontCache.get(fontRef);
  15382. }
  15383. }
  15384. if (!fontAliases[hash]) {
  15385. fontAliases[hash] = {
  15386. fontID: Font.getFontID()
  15387. };
  15388. }
  15389. fontAliases[hash].aliasRef = fontRef;
  15390. fontID = fontAliases[hash].fontID;
  15391. }
  15392. // Workaround for bad PDF generators that don't reference fonts
  15393. // properly, i.e. by not using an object identifier.
  15394. // Check if the fontRef is a Dict (as opposed to a standard object),
  15395. // in which case we don't cache the font and instead reference it by
  15396. // fontName in font.loadedName below.
  15397. var fontRefIsDict = isDict(fontRef);
  15398. if (!fontRefIsDict) {
  15399. this.fontCache.put(fontRef, fontCapability.promise);
  15400. }
  15401. // Keep track of each font we translated so the caller can
  15402. // load them asynchronously before calling display on a page.
  15403. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15404. fontName.replace(/\W/g, '') : fontID);
  15405. font.translated = fontCapability.promise;
  15406. // TODO move promises into translate font
  15407. var translatedPromise;
  15408. try {
  15409. translatedPromise = Promise.resolve(
  15410. this.translateFont(preEvaluatedFont, xref));
  15411. } catch (e) {
  15412. translatedPromise = Promise.reject(e);
  15413. }
  15414. translatedPromise.then(function (translatedFont) {
  15415. if (translatedFont.fontType !== undefined) {
  15416. var xrefFontStats = xref.stats.fontTypes;
  15417. xrefFontStats[translatedFont.fontType] = true;
  15418. }
  15419. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15420. translatedFont, font));
  15421. }, function (reason) {
  15422. // TODO fontCapability.reject?
  15423. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15424. try {
  15425. // error, but it's still nice to have font type reported
  15426. var descriptor = preEvaluatedFont.descriptor;
  15427. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15428. var subtype = fontFile3 && fontFile3.get('Subtype');
  15429. var fontType = getFontType(preEvaluatedFont.type,
  15430. subtype && subtype.name);
  15431. var xrefFontStats = xref.stats.fontTypes;
  15432. xrefFontStats[fontType] = true;
  15433. } catch (ex) { }
  15434. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15435. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15436. font));
  15437. });
  15438. return fontCapability.promise;
  15439. },
  15440. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15441. var lastIndex = operatorList.length - 1;
  15442. if (!args) {
  15443. args = [];
  15444. }
  15445. if (lastIndex < 0 ||
  15446. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15447. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15448. } else {
  15449. var opArgs = operatorList.argsArray[lastIndex];
  15450. opArgs[0].push(fn);
  15451. Array.prototype.push.apply(opArgs[1], args);
  15452. }
  15453. },
  15454. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15455. cs, patterns, resources, xref) {
  15456. // compile tiling patterns
  15457. var patternName = args[args.length - 1];
  15458. // SCN/scn applies patterns along with normal colors
  15459. var pattern;
  15460. if (isName(patternName) &&
  15461. (pattern = patterns.get(patternName.name))) {
  15462. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15463. var typeNum = dict.get('PatternType');
  15464. if (typeNum === TILING_PATTERN) {
  15465. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15466. return this.handleTilingType(fn, color, resources, pattern,
  15467. dict, operatorList);
  15468. } else if (typeNum === SHADING_PATTERN) {
  15469. var shading = dict.get('Shading');
  15470. var matrix = dict.get('Matrix');
  15471. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15472. operatorList.addOp(fn, pattern.getIR());
  15473. return Promise.resolve();
  15474. } else {
  15475. return Promise.reject('Unknown PatternType: ' + typeNum);
  15476. }
  15477. }
  15478. // TODO shall we fail here?
  15479. operatorList.addOp(fn, args);
  15480. return Promise.resolve();
  15481. },
  15482. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15483. resources,
  15484. operatorList,
  15485. initialState) {
  15486. var self = this;
  15487. var xref = this.xref;
  15488. var imageCache = {};
  15489. assert(operatorList);
  15490. resources = (resources || Dict.empty);
  15491. var xobjs = (resources.get('XObject') || Dict.empty);
  15492. var patterns = (resources.get('Pattern') || Dict.empty);
  15493. var stateManager = new StateManager(initialState || new EvalState());
  15494. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15495. var timeSlotManager = new TimeSlotManager();
  15496. return new Promise(function next(resolve, reject) {
  15497. timeSlotManager.reset();
  15498. var stop, operation = {}, i, ii, cs;
  15499. while (!(stop = timeSlotManager.check())) {
  15500. // The arguments parsed by read() are used beyond this loop, so we
  15501. // cannot reuse the same array on each iteration. Therefore we pass
  15502. // in |null| as the initial value (see the comment on
  15503. // EvaluatorPreprocessor_read() for why).
  15504. operation.args = null;
  15505. if (!(preprocessor.read(operation))) {
  15506. break;
  15507. }
  15508. var args = operation.args;
  15509. var fn = operation.fn;
  15510. switch (fn | 0) {
  15511. case OPS.paintXObject:
  15512. if (args[0].code) {
  15513. break;
  15514. }
  15515. // eagerly compile XForm objects
  15516. var name = args[0].name;
  15517. if (imageCache.key === name) {
  15518. operatorList.addOp(imageCache.fn, imageCache.args);
  15519. args = null;
  15520. continue;
  15521. }
  15522. var xobj = xobjs.get(name);
  15523. if (xobj) {
  15524. assert(isStream(xobj), 'XObject should be a stream');
  15525. var type = xobj.dict.get('Subtype');
  15526. assert(isName(type),
  15527. 'XObject should have a Name subtype');
  15528. if (type.name === 'Form') {
  15529. stateManager.save();
  15530. return self.buildFormXObject(resources, xobj, null,
  15531. operatorList,
  15532. stateManager.state.clone()).
  15533. then(function () {
  15534. stateManager.restore();
  15535. next(resolve, reject);
  15536. }, reject);
  15537. } else if (type.name === 'Image') {
  15538. self.buildPaintImageXObject(resources, xobj, false,
  15539. operatorList, name, imageCache);
  15540. args = null;
  15541. continue;
  15542. } else if (type.name === 'PS') {
  15543. // PostScript XObjects are unused when viewing documents.
  15544. // See section 4.7.1 of Adobe's PDF reference.
  15545. info('Ignored XObject subtype PS');
  15546. continue;
  15547. } else {
  15548. error('Unhandled XObject subtype ' + type.name);
  15549. }
  15550. }
  15551. break;
  15552. case OPS.setFont:
  15553. var fontSize = args[1];
  15554. // eagerly collect all fonts
  15555. return self.handleSetFont(resources, args, null,
  15556. operatorList, stateManager.state).
  15557. then(function (loadedName) {
  15558. operatorList.addDependency(loadedName);
  15559. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15560. next(resolve, reject);
  15561. }, reject);
  15562. case OPS.endInlineImage:
  15563. var cacheKey = args[0].cacheKey;
  15564. if (cacheKey && imageCache.key === cacheKey) {
  15565. operatorList.addOp(imageCache.fn, imageCache.args);
  15566. args = null;
  15567. continue;
  15568. }
  15569. self.buildPaintImageXObject(resources, args[0], true,
  15570. operatorList, cacheKey, imageCache);
  15571. args = null;
  15572. continue;
  15573. case OPS.showText:
  15574. args[0] = self.handleText(args[0], stateManager.state);
  15575. break;
  15576. case OPS.showSpacedText:
  15577. var arr = args[0];
  15578. var combinedGlyphs = [];
  15579. var arrLength = arr.length;
  15580. for (i = 0; i < arrLength; ++i) {
  15581. var arrItem = arr[i];
  15582. if (isString(arrItem)) {
  15583. Array.prototype.push.apply(combinedGlyphs,
  15584. self.handleText(arrItem, stateManager.state));
  15585. } else if (isNum(arrItem)) {
  15586. combinedGlyphs.push(arrItem);
  15587. }
  15588. }
  15589. args[0] = combinedGlyphs;
  15590. fn = OPS.showText;
  15591. break;
  15592. case OPS.nextLineShowText:
  15593. operatorList.addOp(OPS.nextLine);
  15594. args[0] = self.handleText(args[0], stateManager.state);
  15595. fn = OPS.showText;
  15596. break;
  15597. case OPS.nextLineSetSpacingShowText:
  15598. operatorList.addOp(OPS.nextLine);
  15599. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15600. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15601. args[0] = self.handleText(args[0], stateManager.state);
  15602. fn = OPS.showText;
  15603. break;
  15604. case OPS.setTextRenderingMode:
  15605. stateManager.state.textRenderingMode = args[0];
  15606. break;
  15607. case OPS.setFillColorSpace:
  15608. stateManager.state.fillColorSpace =
  15609. ColorSpace.parse(args[0], xref, resources);
  15610. continue;
  15611. case OPS.setStrokeColorSpace:
  15612. stateManager.state.strokeColorSpace =
  15613. ColorSpace.parse(args[0], xref, resources);
  15614. continue;
  15615. case OPS.setFillColor:
  15616. cs = stateManager.state.fillColorSpace;
  15617. args = cs.getRgb(args, 0);
  15618. fn = OPS.setFillRGBColor;
  15619. break;
  15620. case OPS.setStrokeColor:
  15621. cs = stateManager.state.strokeColorSpace;
  15622. args = cs.getRgb(args, 0);
  15623. fn = OPS.setStrokeRGBColor;
  15624. break;
  15625. case OPS.setFillGray:
  15626. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15627. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15628. fn = OPS.setFillRGBColor;
  15629. break;
  15630. case OPS.setStrokeGray:
  15631. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15632. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15633. fn = OPS.setStrokeRGBColor;
  15634. break;
  15635. case OPS.setFillCMYKColor:
  15636. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15637. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15638. fn = OPS.setFillRGBColor;
  15639. break;
  15640. case OPS.setStrokeCMYKColor:
  15641. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15642. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15643. fn = OPS.setStrokeRGBColor;
  15644. break;
  15645. case OPS.setFillRGBColor:
  15646. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15647. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15648. break;
  15649. case OPS.setStrokeRGBColor:
  15650. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15651. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15652. break;
  15653. case OPS.setFillColorN:
  15654. cs = stateManager.state.fillColorSpace;
  15655. if (cs.name === 'Pattern') {
  15656. return self.handleColorN(operatorList, OPS.setFillColorN,
  15657. args, cs, patterns, resources, xref).then(function() {
  15658. next(resolve, reject);
  15659. }, reject);
  15660. }
  15661. args = cs.getRgb(args, 0);
  15662. fn = OPS.setFillRGBColor;
  15663. break;
  15664. case OPS.setStrokeColorN:
  15665. cs = stateManager.state.strokeColorSpace;
  15666. if (cs.name === 'Pattern') {
  15667. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15668. args, cs, patterns, resources, xref).then(function() {
  15669. next(resolve, reject);
  15670. }, reject);
  15671. }
  15672. args = cs.getRgb(args, 0);
  15673. fn = OPS.setStrokeRGBColor;
  15674. break;
  15675. case OPS.shadingFill:
  15676. var shadingRes = resources.get('Shading');
  15677. if (!shadingRes) {
  15678. error('No shading resource found');
  15679. }
  15680. var shading = shadingRes.get(args[0].name);
  15681. if (!shading) {
  15682. error('No shading object found');
  15683. }
  15684. var shadingFill = Pattern.parseShading(shading, null, xref,
  15685. resources);
  15686. var patternIR = shadingFill.getIR();
  15687. args = [patternIR];
  15688. fn = OPS.shadingFill;
  15689. break;
  15690. case OPS.setGState:
  15691. var dictName = args[0];
  15692. var extGState = resources.get('ExtGState');
  15693. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15694. break;
  15695. }
  15696. var gState = extGState.get(dictName.name);
  15697. return self.setGState(resources, gState, operatorList, xref,
  15698. stateManager).then(function() {
  15699. next(resolve, reject);
  15700. }, reject);
  15701. case OPS.moveTo:
  15702. case OPS.lineTo:
  15703. case OPS.curveTo:
  15704. case OPS.curveTo2:
  15705. case OPS.curveTo3:
  15706. case OPS.closePath:
  15707. self.buildPath(operatorList, fn, args);
  15708. continue;
  15709. case OPS.rectangle:
  15710. self.buildPath(operatorList, fn, args);
  15711. continue;
  15712. }
  15713. operatorList.addOp(fn, args);
  15714. }
  15715. if (stop) {
  15716. deferred.then(function () {
  15717. next(resolve, reject);
  15718. });
  15719. return;
  15720. }
  15721. // Some PDFs don't close all restores inside object/form.
  15722. // Closing those for them.
  15723. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15724. operatorList.addOp(OPS.restore, []);
  15725. }
  15726. resolve();
  15727. });
  15728. },
  15729. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15730. stateManager) {
  15731. stateManager = (stateManager || new StateManager(new TextState()));
  15732. var textContent = {
  15733. items: [],
  15734. styles: Object.create(null)
  15735. };
  15736. var bidiTexts = textContent.items;
  15737. var SPACE_FACTOR = 0.35;
  15738. var MULTI_SPACE_FACTOR = 1.5;
  15739. var self = this;
  15740. var xref = this.xref;
  15741. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15742. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15743. var xobjs = null;
  15744. var xobjsCache = {};
  15745. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15746. var textState;
  15747. function newTextChunk() {
  15748. var font = textState.font;
  15749. if (!(font.loadedName in textContent.styles)) {
  15750. textContent.styles[font.loadedName] = {
  15751. fontFamily: font.fallbackName,
  15752. ascent: font.ascent,
  15753. descent: font.descent,
  15754. vertical: font.vertical
  15755. };
  15756. }
  15757. return {
  15758. // |str| is initially an array which we push individual chars to, and
  15759. // then runBidi() overwrites it with the final string.
  15760. str: [],
  15761. dir: null,
  15762. width: 0,
  15763. height: 0,
  15764. transform: null,
  15765. fontName: font.loadedName
  15766. };
  15767. }
  15768. function runBidi(textChunk) {
  15769. var str = textChunk.str.join('');
  15770. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  15771. textChunk.str = bidiResult.str;
  15772. textChunk.dir = bidiResult.dir;
  15773. return textChunk;
  15774. }
  15775. function handleSetFont(fontName, fontRef) {
  15776. return self.loadFont(fontName, fontRef, xref, resources).
  15777. then(function (translated) {
  15778. textState.font = translated.font;
  15779. textState.fontMatrix = translated.font.fontMatrix ||
  15780. FONT_IDENTITY_MATRIX;
  15781. });
  15782. }
  15783. function buildTextGeometry(chars, textChunk) {
  15784. var font = textState.font;
  15785. textChunk = textChunk || newTextChunk();
  15786. if (!textChunk.transform) {
  15787. // 9.4.4 Text Space Details
  15788. var tsm = [textState.fontSize * textState.textHScale, 0,
  15789. 0, textState.fontSize,
  15790. 0, textState.textRise];
  15791. var trm = textChunk.transform = Util.transform(textState.ctm,
  15792. Util.transform(textState.textMatrix, tsm));
  15793. if (!font.vertical) {
  15794. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  15795. } else {
  15796. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  15797. }
  15798. }
  15799. var width = 0;
  15800. var height = 0;
  15801. var glyphs = font.charsToGlyphs(chars);
  15802. var defaultVMetrics = font.defaultVMetrics;
  15803. for (var i = 0; i < glyphs.length; i++) {
  15804. var glyph = glyphs[i];
  15805. if (!glyph) { // Previous glyph was a space.
  15806. width += textState.wordSpacing * textState.textHScale;
  15807. continue;
  15808. }
  15809. var vMetricX = null;
  15810. var vMetricY = null;
  15811. var glyphWidth = null;
  15812. if (font.vertical) {
  15813. if (glyph.vmetric) {
  15814. glyphWidth = glyph.vmetric[0];
  15815. vMetricX = glyph.vmetric[1];
  15816. vMetricY = glyph.vmetric[2];
  15817. } else {
  15818. glyphWidth = glyph.width;
  15819. vMetricX = glyph.width * 0.5;
  15820. vMetricY = defaultVMetrics[2];
  15821. }
  15822. } else {
  15823. glyphWidth = glyph.width;
  15824. }
  15825. var glyphUnicode = glyph.unicode;
  15826. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  15827. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  15828. }
  15829. glyphUnicode = reverseIfRtl(glyphUnicode);
  15830. // The following will calculate the x and y of the individual glyphs.
  15831. // if (font.vertical) {
  15832. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  15833. // textState.fontMatrix[0];
  15834. // tsm[5] -= vMetricY * textState.fontSize *
  15835. // textState.fontMatrix[0];
  15836. // }
  15837. // var trm = Util.transform(textState.textMatrix, tsm);
  15838. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  15839. // var x = pt[0];
  15840. // var y = pt[1];
  15841. var tx = 0;
  15842. var ty = 0;
  15843. if (!font.vertical) {
  15844. var w0 = glyphWidth * textState.fontMatrix[0];
  15845. tx = (w0 * textState.fontSize + textState.charSpacing) *
  15846. textState.textHScale;
  15847. width += tx;
  15848. } else {
  15849. var w1 = glyphWidth * textState.fontMatrix[0];
  15850. ty = w1 * textState.fontSize + textState.charSpacing;
  15851. height += ty;
  15852. }
  15853. textState.translateTextMatrix(tx, ty);
  15854. textChunk.str.push(glyphUnicode);
  15855. }
  15856. var a = textState.textLineMatrix[0];
  15857. var b = textState.textLineMatrix[1];
  15858. var scaleLineX = Math.sqrt(a * a + b * b);
  15859. a = textState.ctm[0];
  15860. b = textState.ctm[1];
  15861. var scaleCtmX = Math.sqrt(a * a + b * b);
  15862. if (!font.vertical) {
  15863. textChunk.width += width * scaleCtmX * scaleLineX;
  15864. } else {
  15865. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  15866. }
  15867. return textChunk;
  15868. }
  15869. var timeSlotManager = new TimeSlotManager();
  15870. return new Promise(function next(resolve, reject) {
  15871. timeSlotManager.reset();
  15872. var stop, operation = {}, args = [];
  15873. while (!(stop = timeSlotManager.check())) {
  15874. // The arguments parsed by read() are not used beyond this loop, so
  15875. // we can reuse the same array on every iteration, thus avoiding
  15876. // unnecessary allocations.
  15877. args.length = 0;
  15878. operation.args = args;
  15879. if (!(preprocessor.read(operation))) {
  15880. break;
  15881. }
  15882. textState = stateManager.state;
  15883. var fn = operation.fn;
  15884. args = operation.args;
  15885. switch (fn | 0) {
  15886. case OPS.setFont:
  15887. textState.fontSize = args[1];
  15888. return handleSetFont(args[0].name).then(function() {
  15889. next(resolve, reject);
  15890. }, reject);
  15891. case OPS.setTextRise:
  15892. textState.textRise = args[0];
  15893. break;
  15894. case OPS.setHScale:
  15895. textState.textHScale = args[0] / 100;
  15896. break;
  15897. case OPS.setLeading:
  15898. textState.leading = args[0];
  15899. break;
  15900. case OPS.moveText:
  15901. textState.translateTextLineMatrix(args[0], args[1]);
  15902. textState.textMatrix = textState.textLineMatrix.slice();
  15903. break;
  15904. case OPS.setLeadingMoveText:
  15905. textState.leading = -args[1];
  15906. textState.translateTextLineMatrix(args[0], args[1]);
  15907. textState.textMatrix = textState.textLineMatrix.slice();
  15908. break;
  15909. case OPS.nextLine:
  15910. textState.carriageReturn();
  15911. break;
  15912. case OPS.setTextMatrix:
  15913. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  15914. args[4], args[5]);
  15915. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  15916. args[4], args[5]);
  15917. break;
  15918. case OPS.setCharSpacing:
  15919. textState.charSpacing = args[0];
  15920. break;
  15921. case OPS.setWordSpacing:
  15922. textState.wordSpacing = args[0];
  15923. break;
  15924. case OPS.beginText:
  15925. textState.textMatrix = IDENTITY_MATRIX.slice();
  15926. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  15927. break;
  15928. case OPS.showSpacedText:
  15929. var items = args[0];
  15930. var textChunk = newTextChunk();
  15931. var offset;
  15932. for (var j = 0, jj = items.length; j < jj; j++) {
  15933. if (typeof items[j] === 'string') {
  15934. buildTextGeometry(items[j], textChunk);
  15935. } else {
  15936. var val = items[j] / 1000;
  15937. if (!textState.font.vertical) {
  15938. offset = -val * textState.fontSize * textState.textHScale *
  15939. textState.textMatrix[0];
  15940. textState.translateTextMatrix(offset, 0);
  15941. textChunk.width += offset;
  15942. } else {
  15943. offset = -val * textState.fontSize *
  15944. textState.textMatrix[3];
  15945. textState.translateTextMatrix(0, offset);
  15946. textChunk.height += offset;
  15947. }
  15948. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  15949. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  15950. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  15951. fakeSpaces = Math.round(fakeSpaces);
  15952. while (fakeSpaces--) {
  15953. textChunk.str.push(' ');
  15954. }
  15955. } else if (fakeSpaces > SPACE_FACTOR) {
  15956. textChunk.str.push(' ');
  15957. }
  15958. }
  15959. }
  15960. }
  15961. bidiTexts.push(runBidi(textChunk));
  15962. break;
  15963. case OPS.showText:
  15964. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  15965. break;
  15966. case OPS.nextLineShowText:
  15967. textState.carriageReturn();
  15968. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  15969. break;
  15970. case OPS.nextLineSetSpacingShowText:
  15971. textState.wordSpacing = args[0];
  15972. textState.charSpacing = args[1];
  15973. textState.carriageReturn();
  15974. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  15975. break;
  15976. case OPS.paintXObject:
  15977. if (args[0].code) {
  15978. break;
  15979. }
  15980. if (!xobjs) {
  15981. xobjs = (resources.get('XObject') || Dict.empty);
  15982. }
  15983. var name = args[0].name;
  15984. if (xobjsCache.key === name) {
  15985. if (xobjsCache.texts) {
  15986. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  15987. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  15988. }
  15989. break;
  15990. }
  15991. var xobj = xobjs.get(name);
  15992. if (!xobj) {
  15993. break;
  15994. }
  15995. assert(isStream(xobj), 'XObject should be a stream');
  15996. var type = xobj.dict.get('Subtype');
  15997. assert(isName(type),
  15998. 'XObject should have a Name subtype');
  15999. if ('Form' !== type.name) {
  16000. xobjsCache.key = name;
  16001. xobjsCache.texts = null;
  16002. break;
  16003. }
  16004. stateManager.save();
  16005. var matrix = xobj.dict.get('Matrix');
  16006. if (isArray(matrix) && matrix.length === 6) {
  16007. stateManager.transform(matrix);
  16008. }
  16009. return self.getTextContent(xobj,
  16010. xobj.dict.get('Resources') || resources, stateManager).
  16011. then(function (formTextContent) {
  16012. Util.appendToArray(bidiTexts, formTextContent.items);
  16013. Util.extendObj(textContent.styles, formTextContent.styles);
  16014. stateManager.restore();
  16015. xobjsCache.key = name;
  16016. xobjsCache.texts = formTextContent;
  16017. next(resolve, reject);
  16018. }, reject);
  16019. case OPS.setGState:
  16020. var dictName = args[0];
  16021. var extGState = resources.get('ExtGState');
  16022. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16023. break;
  16024. }
  16025. var gsStateMap = extGState.get(dictName.name);
  16026. var gsStateFont = null;
  16027. for (var key in gsStateMap) {
  16028. if (key === 'Font') {
  16029. assert(!gsStateFont);
  16030. gsStateFont = gsStateMap[key];
  16031. }
  16032. }
  16033. if (gsStateFont) {
  16034. textState.fontSize = gsStateFont[1];
  16035. return handleSetFont(gsStateFont[0]).then(function() {
  16036. next(resolve, reject);
  16037. }, reject);
  16038. }
  16039. break;
  16040. } // switch
  16041. } // while
  16042. if (stop) {
  16043. deferred.then(function () {
  16044. next(resolve, reject);
  16045. });
  16046. return;
  16047. }
  16048. resolve(textContent);
  16049. });
  16050. },
  16051. extractDataStructures: function
  16052. partialEvaluatorExtractDataStructures(dict, baseDict,
  16053. xref, properties) {
  16054. // 9.10.2
  16055. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16056. if (toUnicode) {
  16057. properties.toUnicode = this.readToUnicode(toUnicode);
  16058. }
  16059. if (properties.composite) {
  16060. // CIDSystemInfo helps to match CID to glyphs
  16061. var cidSystemInfo = dict.get('CIDSystemInfo');
  16062. if (isDict(cidSystemInfo)) {
  16063. properties.cidSystemInfo = {
  16064. registry: cidSystemInfo.get('Registry'),
  16065. ordering: cidSystemInfo.get('Ordering'),
  16066. supplement: cidSystemInfo.get('Supplement')
  16067. };
  16068. }
  16069. var cidToGidMap = dict.get('CIDToGIDMap');
  16070. if (isStream(cidToGidMap)) {
  16071. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16072. }
  16073. }
  16074. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16075. // and depends on the font type. The base encoding and differences are
  16076. // read here, but the encoding that is actually used is chosen during
  16077. // glyph mapping in the font.
  16078. // TODO: Loading the built in encoding in the font would allow the
  16079. // differences to be merged in here not require us to hold on to it.
  16080. var differences = [];
  16081. var baseEncodingName = null;
  16082. var encoding;
  16083. if (dict.has('Encoding')) {
  16084. encoding = dict.get('Encoding');
  16085. if (isDict(encoding)) {
  16086. baseEncodingName = encoding.get('BaseEncoding');
  16087. baseEncodingName = (isName(baseEncodingName) ?
  16088. baseEncodingName.name : null);
  16089. // Load the differences between the base and original
  16090. if (encoding.has('Differences')) {
  16091. var diffEncoding = encoding.get('Differences');
  16092. var index = 0;
  16093. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16094. var data = diffEncoding[j];
  16095. if (isNum(data)) {
  16096. index = data;
  16097. } else {
  16098. differences[index++] = data.name;
  16099. }
  16100. }
  16101. }
  16102. } else if (isName(encoding)) {
  16103. baseEncodingName = encoding.name;
  16104. } else {
  16105. error('Encoding is not a Name nor a Dict');
  16106. }
  16107. // According to table 114 if the encoding is a named encoding it must be
  16108. // one of these predefined encodings.
  16109. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16110. baseEncodingName !== 'MacExpertEncoding' &&
  16111. baseEncodingName !== 'WinAnsiEncoding')) {
  16112. baseEncodingName = null;
  16113. }
  16114. }
  16115. if (baseEncodingName) {
  16116. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16117. } else {
  16118. encoding = (properties.type === 'TrueType' ?
  16119. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16120. // The Symbolic attribute can be misused for regular fonts
  16121. // Heuristic: we have to check if the font is a standard one also
  16122. if (!!(properties.flags & FontFlags.Symbolic)) {
  16123. encoding = Encodings.MacRomanEncoding;
  16124. if (!properties.file) {
  16125. if (/Symbol/i.test(properties.name)) {
  16126. encoding = Encodings.SymbolSetEncoding;
  16127. } else if (/Dingbats/i.test(properties.name)) {
  16128. encoding = Encodings.ZapfDingbatsEncoding;
  16129. }
  16130. }
  16131. }
  16132. properties.defaultEncoding = encoding;
  16133. }
  16134. properties.differences = differences;
  16135. properties.baseEncodingName = baseEncodingName;
  16136. properties.dict = dict;
  16137. },
  16138. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16139. var cmap, cmapObj = toUnicode;
  16140. if (isName(cmapObj)) {
  16141. cmap = CMapFactory.create(cmapObj,
  16142. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16143. return new ToUnicodeMap(cmap);
  16144. } else if (isStream(cmapObj)) {
  16145. cmap = CMapFactory.create(cmapObj,
  16146. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16147. // Convert UTF-16BE
  16148. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16149. // to iterate over all keys.
  16150. cmap.forEach(function(token, i) {
  16151. var str = [];
  16152. for (var k = 0; k < token.length; k += 2) {
  16153. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16154. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16155. str.push(w1);
  16156. continue;
  16157. }
  16158. k += 2;
  16159. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16160. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16161. }
  16162. cmap[i] = String.fromCharCode.apply(String, str);
  16163. });
  16164. return new ToUnicodeMap(cmap);
  16165. }
  16166. return null;
  16167. },
  16168. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16169. // Extract the encoding from the CIDToGIDMap
  16170. var glyphsData = cidToGidStream.getBytes();
  16171. // Set encoding 0 to later verify the font has an encoding
  16172. var result = [];
  16173. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16174. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16175. if (glyphID === 0) {
  16176. continue;
  16177. }
  16178. var code = j >> 1;
  16179. result[code] = glyphID;
  16180. }
  16181. return result;
  16182. },
  16183. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16184. descriptor,
  16185. properties) {
  16186. var glyphsWidths = [];
  16187. var defaultWidth = 0;
  16188. var glyphsVMetrics = [];
  16189. var defaultVMetrics;
  16190. var i, ii, j, jj, start, code, widths;
  16191. if (properties.composite) {
  16192. defaultWidth = dict.get('DW') || 1000;
  16193. widths = dict.get('W');
  16194. if (widths) {
  16195. for (i = 0, ii = widths.length; i < ii; i++) {
  16196. start = widths[i++];
  16197. code = xref.fetchIfRef(widths[i]);
  16198. if (isArray(code)) {
  16199. for (j = 0, jj = code.length; j < jj; j++) {
  16200. glyphsWidths[start++] = code[j];
  16201. }
  16202. } else {
  16203. var width = widths[++i];
  16204. for (j = start; j <= code; j++) {
  16205. glyphsWidths[j] = width;
  16206. }
  16207. }
  16208. }
  16209. }
  16210. if (properties.vertical) {
  16211. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16212. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16213. vmetrics = dict.get('W2');
  16214. if (vmetrics) {
  16215. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16216. start = vmetrics[i++];
  16217. code = xref.fetchIfRef(vmetrics[i]);
  16218. if (isArray(code)) {
  16219. for (j = 0, jj = code.length; j < jj; j++) {
  16220. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16221. }
  16222. } else {
  16223. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16224. for (j = start; j <= code; j++) {
  16225. glyphsVMetrics[j] = vmetric;
  16226. }
  16227. }
  16228. }
  16229. }
  16230. }
  16231. } else {
  16232. var firstChar = properties.firstChar;
  16233. widths = dict.get('Widths');
  16234. if (widths) {
  16235. j = firstChar;
  16236. for (i = 0, ii = widths.length; i < ii; i++) {
  16237. glyphsWidths[j++] = widths[i];
  16238. }
  16239. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16240. } else {
  16241. // Trying get the BaseFont metrics (see comment above).
  16242. var baseFontName = dict.get('BaseFont');
  16243. if (isName(baseFontName)) {
  16244. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16245. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16246. properties);
  16247. defaultWidth = metrics.defaultWidth;
  16248. }
  16249. }
  16250. }
  16251. // Heuristic: detection of monospace font by checking all non-zero widths
  16252. var isMonospace = true;
  16253. var firstWidth = defaultWidth;
  16254. for (var glyph in glyphsWidths) {
  16255. var glyphWidth = glyphsWidths[glyph];
  16256. if (!glyphWidth) {
  16257. continue;
  16258. }
  16259. if (!firstWidth) {
  16260. firstWidth = glyphWidth;
  16261. continue;
  16262. }
  16263. if (firstWidth !== glyphWidth) {
  16264. isMonospace = false;
  16265. break;
  16266. }
  16267. }
  16268. if (isMonospace) {
  16269. properties.flags |= FontFlags.FixedPitch;
  16270. }
  16271. properties.defaultWidth = defaultWidth;
  16272. properties.widths = glyphsWidths;
  16273. properties.defaultVMetrics = defaultVMetrics;
  16274. properties.vmetrics = glyphsVMetrics;
  16275. },
  16276. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16277. // Simulating descriptor flags attribute
  16278. var fontNameWoStyle = baseFontName.split('-')[0];
  16279. return (fontNameWoStyle in serifFonts) ||
  16280. (fontNameWoStyle.search(/serif/gi) !== -1);
  16281. },
  16282. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16283. var defaultWidth = 0;
  16284. var widths = [];
  16285. var monospace = false;
  16286. var lookupName = (stdFontMap[name] || name);
  16287. if (!(lookupName in Metrics)) {
  16288. // Use default fonts for looking up font metrics if the passed
  16289. // font is not a base font
  16290. if (this.isSerifFont(name)) {
  16291. lookupName = 'Times-Roman';
  16292. } else {
  16293. lookupName = 'Helvetica';
  16294. }
  16295. }
  16296. var glyphWidths = Metrics[lookupName];
  16297. if (isNum(glyphWidths)) {
  16298. defaultWidth = glyphWidths;
  16299. monospace = true;
  16300. } else {
  16301. widths = glyphWidths;
  16302. }
  16303. return {
  16304. defaultWidth: defaultWidth,
  16305. monospace: monospace,
  16306. widths: widths
  16307. };
  16308. },
  16309. buildCharCodeToWidth:
  16310. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16311. properties) {
  16312. var widths = Object.create(null);
  16313. var differences = properties.differences;
  16314. var encoding = properties.defaultEncoding;
  16315. for (var charCode = 0; charCode < 256; charCode++) {
  16316. if (charCode in differences &&
  16317. widthsByGlyphName[differences[charCode]]) {
  16318. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16319. continue;
  16320. }
  16321. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16322. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16323. continue;
  16324. }
  16325. }
  16326. return widths;
  16327. },
  16328. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16329. var baseDict = dict;
  16330. var type = dict.get('Subtype');
  16331. assert(isName(type), 'invalid font Subtype');
  16332. var composite = false;
  16333. var uint8array;
  16334. if (type.name === 'Type0') {
  16335. // If font is a composite
  16336. // - get the descendant font
  16337. // - set the type according to the descendant font
  16338. // - get the FontDescriptor from the descendant font
  16339. var df = dict.get('DescendantFonts');
  16340. if (!df) {
  16341. error('Descendant fonts are not specified');
  16342. }
  16343. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16344. type = dict.get('Subtype');
  16345. assert(isName(type), 'invalid font Subtype');
  16346. composite = true;
  16347. }
  16348. var descriptor = dict.get('FontDescriptor');
  16349. if (descriptor) {
  16350. var hash = new MurmurHash3_64();
  16351. var encoding = baseDict.getRaw('Encoding');
  16352. if (isName(encoding)) {
  16353. hash.update(encoding.name);
  16354. } else if (isRef(encoding)) {
  16355. hash.update(encoding.num + '_' + encoding.gen);
  16356. }
  16357. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16358. if (isStream(toUnicode)) {
  16359. var stream = toUnicode.str || toUnicode;
  16360. uint8array = stream.buffer ?
  16361. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16362. new Uint8Array(stream.bytes.buffer,
  16363. stream.start, stream.end - stream.start);
  16364. hash.update(uint8array);
  16365. } else if (isName(toUnicode)) {
  16366. hash.update(toUnicode.name);
  16367. }
  16368. var widths = dict.get('Widths') || baseDict.get('Widths');
  16369. if (widths) {
  16370. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16371. hash.update(uint8array);
  16372. }
  16373. }
  16374. return {
  16375. descriptor: descriptor,
  16376. dict: dict,
  16377. baseDict: baseDict,
  16378. composite: composite,
  16379. type: type.name,
  16380. hash: hash ? hash.hexdigest() : ''
  16381. };
  16382. },
  16383. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16384. xref) {
  16385. var baseDict = preEvaluatedFont.baseDict;
  16386. var dict = preEvaluatedFont.dict;
  16387. var composite = preEvaluatedFont.composite;
  16388. var descriptor = preEvaluatedFont.descriptor;
  16389. var type = preEvaluatedFont.type;
  16390. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16391. var properties;
  16392. if (!descriptor) {
  16393. if (type === 'Type3') {
  16394. // FontDescriptor is only required for Type3 fonts when the document
  16395. // is a tagged pdf. Create a barbebones one to get by.
  16396. descriptor = new Dict(null);
  16397. descriptor.set('FontName', Name.get(type));
  16398. } else {
  16399. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16400. // FontDescriptor was not required.
  16401. // This case is here for compatibility.
  16402. var baseFontName = dict.get('BaseFont');
  16403. if (!isName(baseFontName)) {
  16404. error('Base font is not specified');
  16405. }
  16406. // Using base font name as a font name.
  16407. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16408. var metrics = this.getBaseFontMetrics(baseFontName);
  16409. // Simulating descriptor flags attribute
  16410. var fontNameWoStyle = baseFontName.split('-')[0];
  16411. var flags =
  16412. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16413. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16414. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16415. FontFlags.Nonsymbolic);
  16416. properties = {
  16417. type: type,
  16418. name: baseFontName,
  16419. widths: metrics.widths,
  16420. defaultWidth: metrics.defaultWidth,
  16421. flags: flags,
  16422. firstChar: 0,
  16423. lastChar: maxCharIndex
  16424. };
  16425. this.extractDataStructures(dict, dict, xref, properties);
  16426. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16427. properties);
  16428. return new Font(baseFontName, null, properties);
  16429. }
  16430. }
  16431. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16432. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16433. // to ignore this rule when a variant of a standart font is used.
  16434. // TODO Fill the width array depending on which of the base font this is
  16435. // a variant.
  16436. var firstChar = (dict.get('FirstChar') || 0);
  16437. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16438. var fontName = descriptor.get('FontName');
  16439. var baseFont = dict.get('BaseFont');
  16440. // Some bad PDFs have a string as the font name.
  16441. if (isString(fontName)) {
  16442. fontName = Name.get(fontName);
  16443. }
  16444. if (isString(baseFont)) {
  16445. baseFont = Name.get(baseFont);
  16446. }
  16447. if (type !== 'Type3') {
  16448. var fontNameStr = fontName && fontName.name;
  16449. var baseFontStr = baseFont && baseFont.name;
  16450. if (fontNameStr !== baseFontStr) {
  16451. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16452. '" but should be the same as the Font\'s BaseFont "' +
  16453. baseFontStr + '"');
  16454. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16455. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16456. if (fontNameStr && baseFontStr &&
  16457. baseFontStr.indexOf(fontNameStr) === 0) {
  16458. fontName = baseFont;
  16459. }
  16460. }
  16461. }
  16462. fontName = (fontName || baseFont);
  16463. assert(isName(fontName), 'invalid font name');
  16464. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16465. if (fontFile) {
  16466. if (fontFile.dict) {
  16467. var subtype = fontFile.dict.get('Subtype');
  16468. if (subtype) {
  16469. subtype = subtype.name;
  16470. }
  16471. var length1 = fontFile.dict.get('Length1');
  16472. var length2 = fontFile.dict.get('Length2');
  16473. }
  16474. }
  16475. properties = {
  16476. type: type,
  16477. name: fontName.name,
  16478. subtype: subtype,
  16479. file: fontFile,
  16480. length1: length1,
  16481. length2: length2,
  16482. loadedName: baseDict.loadedName,
  16483. composite: composite,
  16484. wideChars: composite,
  16485. fixedPitch: false,
  16486. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16487. firstChar: firstChar || 0,
  16488. lastChar: (lastChar || maxCharIndex),
  16489. bbox: descriptor.get('FontBBox'),
  16490. ascent: descriptor.get('Ascent'),
  16491. descent: descriptor.get('Descent'),
  16492. xHeight: descriptor.get('XHeight'),
  16493. capHeight: descriptor.get('CapHeight'),
  16494. flags: descriptor.get('Flags'),
  16495. italicAngle: descriptor.get('ItalicAngle'),
  16496. coded: false
  16497. };
  16498. if (composite) {
  16499. var cidEncoding = baseDict.get('Encoding');
  16500. if (isName(cidEncoding)) {
  16501. properties.cidEncoding = cidEncoding.name;
  16502. }
  16503. properties.cMap = CMapFactory.create(cidEncoding,
  16504. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16505. properties.vertical = properties.cMap.vertical;
  16506. }
  16507. this.extractDataStructures(dict, baseDict, xref, properties);
  16508. this.extractWidths(dict, xref, descriptor, properties);
  16509. if (type === 'Type3') {
  16510. properties.isType3Font = true;
  16511. }
  16512. return new Font(fontName.name, fontFile, properties);
  16513. }
  16514. };
  16515. return PartialEvaluator;
  16516. })();
  16517. var TranslatedFont = (function TranslatedFontClosure() {
  16518. function TranslatedFont(loadedName, font, dict) {
  16519. this.loadedName = loadedName;
  16520. this.font = font;
  16521. this.dict = dict;
  16522. this.type3Loaded = null;
  16523. this.sent = false;
  16524. }
  16525. TranslatedFont.prototype = {
  16526. send: function (handler) {
  16527. if (this.sent) {
  16528. return;
  16529. }
  16530. var fontData = this.font.exportData();
  16531. handler.send('commonobj', [
  16532. this.loadedName,
  16533. 'Font',
  16534. fontData
  16535. ]);
  16536. this.sent = true;
  16537. },
  16538. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16539. assert(this.font.isType3Font);
  16540. if (this.type3Loaded) {
  16541. return this.type3Loaded;
  16542. }
  16543. var translatedFont = this.font;
  16544. var loadCharProcsPromise = Promise.resolve();
  16545. var charProcs = this.dict.get('CharProcs').getAll();
  16546. var fontResources = this.dict.get('Resources') || resources;
  16547. var charProcKeys = Object.keys(charProcs);
  16548. var charProcOperatorList = {};
  16549. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16550. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16551. var glyphStream = charProcs[key];
  16552. var operatorList = new OperatorList();
  16553. return evaluator.getOperatorList(glyphStream, fontResources,
  16554. operatorList).then(function () {
  16555. charProcOperatorList[key] = operatorList.getIR();
  16556. // Add the dependencies to the parent operator list so they are
  16557. // resolved before sub operator list is executed synchronously.
  16558. parentOperatorList.addDependencies(operatorList.dependencies);
  16559. }, function (reason) {
  16560. warn('Type3 font resource \"' + key + '\" is not available');
  16561. var operatorList = new OperatorList();
  16562. charProcOperatorList[key] = operatorList.getIR();
  16563. });
  16564. }.bind(this, charProcKeys[i]));
  16565. }
  16566. this.type3Loaded = loadCharProcsPromise.then(function () {
  16567. translatedFont.charProcOperatorList = charProcOperatorList;
  16568. });
  16569. return this.type3Loaded;
  16570. }
  16571. };
  16572. return TranslatedFont;
  16573. })();
  16574. var OperatorList = (function OperatorListClosure() {
  16575. var CHUNK_SIZE = 1000;
  16576. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16577. function getTransfers(queue) {
  16578. var transfers = [];
  16579. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16580. for (var i = 0, ii = queue.length; i < ii; i++) {
  16581. switch (fnArray[i]) {
  16582. case OPS.paintInlineImageXObject:
  16583. case OPS.paintInlineImageXObjectGroup:
  16584. case OPS.paintImageMaskXObject:
  16585. var arg = argsArray[i][0]; // first param in imgData
  16586. if (!arg.cached) {
  16587. transfers.push(arg.data.buffer);
  16588. }
  16589. break;
  16590. }
  16591. }
  16592. return transfers;
  16593. }
  16594. function OperatorList(intent, messageHandler, pageIndex) {
  16595. this.messageHandler = messageHandler;
  16596. this.fnArray = [];
  16597. this.argsArray = [];
  16598. this.dependencies = {};
  16599. this.pageIndex = pageIndex;
  16600. this.intent = intent;
  16601. }
  16602. OperatorList.prototype = {
  16603. get length() {
  16604. return this.argsArray.length;
  16605. },
  16606. addOp: function(fn, args) {
  16607. this.fnArray.push(fn);
  16608. this.argsArray.push(args);
  16609. if (this.messageHandler) {
  16610. if (this.fnArray.length >= CHUNK_SIZE) {
  16611. this.flush();
  16612. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16613. (fn === OPS.restore || fn === OPS.endText)) {
  16614. // heuristic to flush on boundary of restore or endText
  16615. this.flush();
  16616. }
  16617. }
  16618. },
  16619. addDependency: function(dependency) {
  16620. if (dependency in this.dependencies) {
  16621. return;
  16622. }
  16623. this.dependencies[dependency] = true;
  16624. this.addOp(OPS.dependency, [dependency]);
  16625. },
  16626. addDependencies: function(dependencies) {
  16627. for (var key in dependencies) {
  16628. this.addDependency(key);
  16629. }
  16630. },
  16631. addOpList: function(opList) {
  16632. Util.extendObj(this.dependencies, opList.dependencies);
  16633. for (var i = 0, ii = opList.length; i < ii; i++) {
  16634. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16635. }
  16636. },
  16637. getIR: function() {
  16638. return {
  16639. fnArray: this.fnArray,
  16640. argsArray: this.argsArray,
  16641. length: this.length
  16642. };
  16643. },
  16644. flush: function(lastChunk) {
  16645. if (this.intent !== 'oplist') {
  16646. new QueueOptimizer().optimize(this);
  16647. }
  16648. var transfers = getTransfers(this);
  16649. this.messageHandler.send('RenderPageChunk', {
  16650. operatorList: {
  16651. fnArray: this.fnArray,
  16652. argsArray: this.argsArray,
  16653. lastChunk: lastChunk,
  16654. length: this.length
  16655. },
  16656. pageIndex: this.pageIndex,
  16657. intent: this.intent
  16658. }, transfers);
  16659. this.dependencies = {};
  16660. this.fnArray.length = 0;
  16661. this.argsArray.length = 0;
  16662. }
  16663. };
  16664. return OperatorList;
  16665. })();
  16666. var StateManager = (function StateManagerClosure() {
  16667. function StateManager(initialState) {
  16668. this.state = initialState;
  16669. this.stateStack = [];
  16670. }
  16671. StateManager.prototype = {
  16672. save: function () {
  16673. var old = this.state;
  16674. this.stateStack.push(this.state);
  16675. this.state = old.clone();
  16676. },
  16677. restore: function () {
  16678. var prev = this.stateStack.pop();
  16679. if (prev) {
  16680. this.state = prev;
  16681. }
  16682. },
  16683. transform: function (args) {
  16684. this.state.ctm = Util.transform(this.state.ctm, args);
  16685. }
  16686. };
  16687. return StateManager;
  16688. })();
  16689. var TextState = (function TextStateClosure() {
  16690. function TextState() {
  16691. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16692. this.fontSize = 0;
  16693. this.font = null;
  16694. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16695. this.textMatrix = IDENTITY_MATRIX.slice();
  16696. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16697. this.charSpacing = 0;
  16698. this.wordSpacing = 0;
  16699. this.leading = 0;
  16700. this.textHScale = 1;
  16701. this.textRise = 0;
  16702. }
  16703. TextState.prototype = {
  16704. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16705. var m = this.textMatrix;
  16706. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16707. },
  16708. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16709. var m = this.textLineMatrix;
  16710. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16711. },
  16712. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16713. var m = this.textMatrix;
  16714. m[4] = m[0] * x + m[2] * y + m[4];
  16715. m[5] = m[1] * x + m[3] * y + m[5];
  16716. },
  16717. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16718. var m = this.textLineMatrix;
  16719. m[4] = m[0] * x + m[2] * y + m[4];
  16720. m[5] = m[1] * x + m[3] * y + m[5];
  16721. },
  16722. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16723. // 9.4.4 Text Space Details
  16724. var tsm = [this.fontSize * this.textHScale, 0,
  16725. 0, this.fontSize,
  16726. 0, this.textRise];
  16727. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16728. },
  16729. carriageReturn: function TextState_carriageReturn() {
  16730. this.translateTextLineMatrix(0, -this.leading);
  16731. this.textMatrix = this.textLineMatrix.slice();
  16732. },
  16733. clone: function TextState_clone() {
  16734. var clone = Object.create(this);
  16735. clone.textMatrix = this.textMatrix.slice();
  16736. clone.textLineMatrix = this.textLineMatrix.slice();
  16737. clone.fontMatrix = this.fontMatrix.slice();
  16738. return clone;
  16739. }
  16740. };
  16741. return TextState;
  16742. })();
  16743. var EvalState = (function EvalStateClosure() {
  16744. function EvalState() {
  16745. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16746. this.font = null;
  16747. this.textRenderingMode = TextRenderingMode.FILL;
  16748. this.fillColorSpace = ColorSpace.singletons.gray;
  16749. this.strokeColorSpace = ColorSpace.singletons.gray;
  16750. }
  16751. EvalState.prototype = {
  16752. clone: function CanvasExtraState_clone() {
  16753. return Object.create(this);
  16754. },
  16755. };
  16756. return EvalState;
  16757. })();
  16758. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  16759. // Specifies properties for each command
  16760. //
  16761. // If variableArgs === true: [0, `numArgs`] expected
  16762. // If variableArgs === false: exactly `numArgs` expected
  16763. var OP_MAP = {
  16764. // Graphic state
  16765. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  16766. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  16767. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  16768. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  16769. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  16770. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  16771. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  16772. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  16773. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  16774. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  16775. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  16776. // Path
  16777. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  16778. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  16779. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  16780. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  16781. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  16782. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  16783. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  16784. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  16785. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  16786. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  16787. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  16788. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  16789. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  16790. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  16791. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  16792. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  16793. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  16794. // Clipping
  16795. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  16796. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  16797. // Text
  16798. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  16799. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  16800. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  16801. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  16802. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  16803. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  16804. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  16805. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  16806. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  16807. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  16808. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  16809. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  16810. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  16811. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  16812. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  16813. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  16814. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  16815. variableArgs: false },
  16816. // Type3 fonts
  16817. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  16818. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  16819. // Color
  16820. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  16821. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  16822. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  16823. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  16824. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  16825. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  16826. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  16827. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  16828. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  16829. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  16830. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  16831. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  16832. // Shading
  16833. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  16834. // Images
  16835. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  16836. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  16837. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  16838. // XObjects
  16839. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  16840. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  16841. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  16842. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  16843. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  16844. variableArgs: false },
  16845. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  16846. // Compatibility
  16847. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  16848. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  16849. // (reserved partial commands for the lexer)
  16850. BM: null,
  16851. BD: null,
  16852. 'true': null,
  16853. fa: null,
  16854. fal: null,
  16855. fals: null,
  16856. 'false': null,
  16857. nu: null,
  16858. nul: null,
  16859. 'null': null
  16860. };
  16861. function EvaluatorPreprocessor(stream, xref, stateManager) {
  16862. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  16863. // dictionary
  16864. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  16865. this.stateManager = stateManager;
  16866. this.nonProcessedArgs = [];
  16867. }
  16868. EvaluatorPreprocessor.prototype = {
  16869. get savedStatesDepth() {
  16870. return this.stateManager.stateStack.length;
  16871. },
  16872. // |operation| is an object with two fields:
  16873. //
  16874. // - |fn| is an out param.
  16875. //
  16876. // - |args| is an inout param. On entry, it should have one of two values.
  16877. //
  16878. // - An empty array. This indicates that the caller is providing the
  16879. // array in which the args will be stored in. The caller should use
  16880. // this value if it can reuse a single array for each call to read().
  16881. //
  16882. // - |null|. This indicates that the caller needs this function to create
  16883. // the array in which any args are stored in. If there are zero args,
  16884. // this function will leave |operation.args| as |null| (thus avoiding
  16885. // allocations that would occur if we used an empty array to represent
  16886. // zero arguments). Otherwise, it will replace |null| with a new array
  16887. // containing the arguments. The caller should use this value if it
  16888. // cannot reuse an array for each call to read().
  16889. //
  16890. // These two modes are present because this function is very hot and so
  16891. // avoiding allocations where possible is worthwhile.
  16892. //
  16893. read: function EvaluatorPreprocessor_read(operation) {
  16894. var args = operation.args;
  16895. while (true) {
  16896. var obj = this.parser.getObj();
  16897. if (isCmd(obj)) {
  16898. var cmd = obj.cmd;
  16899. // Check that the command is valid
  16900. var opSpec = OP_MAP[cmd];
  16901. if (!opSpec) {
  16902. warn('Unknown command "' + cmd + '"');
  16903. continue;
  16904. }
  16905. var fn = opSpec.id;
  16906. var numArgs = opSpec.numArgs;
  16907. var argsLength = args !== null ? args.length : 0;
  16908. if (!opSpec.variableArgs) {
  16909. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  16910. if (argsLength !== numArgs) {
  16911. var nonProcessedArgs = this.nonProcessedArgs;
  16912. while (argsLength > numArgs) {
  16913. nonProcessedArgs.push(args.shift());
  16914. argsLength--;
  16915. }
  16916. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  16917. if (!args) {
  16918. args = [];
  16919. }
  16920. args.unshift(nonProcessedArgs.pop());
  16921. argsLength++;
  16922. }
  16923. }
  16924. if (argsLength < numArgs) {
  16925. // If we receive too few args, it's not possible to possible
  16926. // to execute the command, so skip the command
  16927. info('Command ' + fn + ': because expected ' +
  16928. numArgs + ' args, but received ' + argsLength +
  16929. ' args; skipping');
  16930. args = null;
  16931. continue;
  16932. }
  16933. } else if (argsLength > numArgs) {
  16934. info('Command ' + fn + ': expected [0,' + numArgs +
  16935. '] args, but received ' + argsLength + ' args');
  16936. }
  16937. // TODO figure out how to type-check vararg functions
  16938. this.preprocessCommand(fn, args);
  16939. operation.fn = fn;
  16940. operation.args = args;
  16941. return true;
  16942. } else {
  16943. if (isEOF(obj)) {
  16944. return false; // no more commands
  16945. }
  16946. // argument
  16947. if (obj !== null) {
  16948. if (!args) {
  16949. args = [];
  16950. }
  16951. args.push((obj instanceof Dict ? obj.getAll() : obj));
  16952. assert(args.length <= 33, 'Too many arguments');
  16953. }
  16954. }
  16955. }
  16956. },
  16957. preprocessCommand:
  16958. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  16959. switch (fn | 0) {
  16960. case OPS.save:
  16961. this.stateManager.save();
  16962. break;
  16963. case OPS.restore:
  16964. this.stateManager.restore();
  16965. break;
  16966. case OPS.transform:
  16967. this.stateManager.transform(args);
  16968. break;
  16969. }
  16970. }
  16971. };
  16972. return EvaluatorPreprocessor;
  16973. })();
  16974. var QueueOptimizer = (function QueueOptimizerClosure() {
  16975. function addState(parentState, pattern, fn) {
  16976. var state = parentState;
  16977. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  16978. var item = pattern[i];
  16979. state = (state[item] || (state[item] = []));
  16980. }
  16981. state[pattern[pattern.length - 1]] = fn;
  16982. }
  16983. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  16984. argsArray) {
  16985. // Handles special case of mainly LaTeX documents which use image masks to
  16986. // draw lines with the current fill style.
  16987. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  16988. // have been found at iFirstSave.
  16989. var iFirstPIMXO = iFirstSave + 2;
  16990. for (var i = 0; i < count; i++) {
  16991. var arg = argsArray[iFirstPIMXO + 4 * i];
  16992. var imageMask = arg.length === 1 && arg[0];
  16993. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  16994. (!imageMask.data.length ||
  16995. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  16996. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  16997. continue;
  16998. }
  16999. break;
  17000. }
  17001. return count - i;
  17002. }
  17003. var InitialState = [];
  17004. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17005. // sequences with one |paintInlineImageXObjectGroup| operation.
  17006. addState(InitialState,
  17007. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17008. function foundInlineImageGroup(context) {
  17009. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17010. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17011. var MAX_WIDTH = 1000;
  17012. var IMAGE_PADDING = 1;
  17013. var fnArray = context.fnArray, argsArray = context.argsArray;
  17014. var curr = context.iCurr;
  17015. var iFirstSave = curr - 3;
  17016. var iFirstTransform = curr - 2;
  17017. var iFirstPIIXO = curr - 1;
  17018. // Look for the quartets.
  17019. var i = iFirstSave + 4;
  17020. var ii = fnArray.length;
  17021. while (i + 3 < ii) {
  17022. if (fnArray[i] !== OPS.save ||
  17023. fnArray[i + 1] !== OPS.transform ||
  17024. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17025. fnArray[i + 3] !== OPS.restore) {
  17026. break; // ops don't match
  17027. }
  17028. i += 4;
  17029. }
  17030. // At this point, i is the index of the first op past the last valid
  17031. // quartet.
  17032. var count = Math.min((i - iFirstSave) / 4,
  17033. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17034. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17035. return i;
  17036. }
  17037. // assuming that heights of those image is too small (~1 pixel)
  17038. // packing as much as possible by lines
  17039. var maxX = 0;
  17040. var map = [], maxLineHeight = 0;
  17041. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17042. var q;
  17043. for (q = 0; q < count; q++) {
  17044. var transform = argsArray[iFirstTransform + (q << 2)];
  17045. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17046. if (currentX + img.width > MAX_WIDTH) {
  17047. // starting new line
  17048. maxX = Math.max(maxX, currentX);
  17049. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17050. currentX = 0;
  17051. maxLineHeight = 0;
  17052. }
  17053. map.push({
  17054. transform: transform,
  17055. x: currentX, y: currentY,
  17056. w: img.width, h: img.height
  17057. });
  17058. currentX += img.width + 2 * IMAGE_PADDING;
  17059. maxLineHeight = Math.max(maxLineHeight, img.height);
  17060. }
  17061. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17062. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17063. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17064. var imgRowSize = imgWidth << 2;
  17065. for (q = 0; q < count; q++) {
  17066. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17067. // Copy image by lines and extends pixels into padding.
  17068. var rowSize = map[q].w << 2;
  17069. var dataOffset = 0;
  17070. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17071. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17072. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17073. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17074. dataOffset += rowSize;
  17075. offset += imgRowSize;
  17076. }
  17077. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17078. while (offset >= 0) {
  17079. data[offset - 4] = data[offset];
  17080. data[offset - 3] = data[offset + 1];
  17081. data[offset - 2] = data[offset + 2];
  17082. data[offset - 1] = data[offset + 3];
  17083. data[offset + rowSize] = data[offset + rowSize - 4];
  17084. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17085. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17086. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17087. offset -= imgRowSize;
  17088. }
  17089. }
  17090. // Replace queue items.
  17091. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17092. argsArray.splice(iFirstSave, count * 4,
  17093. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17094. data: imgData }, map]);
  17095. return iFirstSave + 1;
  17096. });
  17097. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17098. // sequences with one |paintImageMaskXObjectGroup| or one
  17099. // |paintImageMaskXObjectRepeat| operation.
  17100. addState(InitialState,
  17101. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17102. function foundImageMaskGroup(context) {
  17103. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17104. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17105. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17106. var fnArray = context.fnArray, argsArray = context.argsArray;
  17107. var curr = context.iCurr;
  17108. var iFirstSave = curr - 3;
  17109. var iFirstTransform = curr - 2;
  17110. var iFirstPIMXO = curr - 1;
  17111. // Look for the quartets.
  17112. var i = iFirstSave + 4;
  17113. var ii = fnArray.length;
  17114. while (i + 3 < ii) {
  17115. if (fnArray[i] !== OPS.save ||
  17116. fnArray[i + 1] !== OPS.transform ||
  17117. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17118. fnArray[i + 3] !== OPS.restore) {
  17119. break; // ops don't match
  17120. }
  17121. i += 4;
  17122. }
  17123. // At this point, i is the index of the first op past the last valid
  17124. // quartet.
  17125. var count = (i - iFirstSave) / 4;
  17126. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17127. argsArray);
  17128. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17129. return i;
  17130. }
  17131. var q;
  17132. var isSameImage = false;
  17133. var iTransform, transformArgs;
  17134. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17135. if (argsArray[iFirstTransform][1] === 0 &&
  17136. argsArray[iFirstTransform][2] === 0) {
  17137. isSameImage = true;
  17138. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17139. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17140. iTransform = iFirstTransform + 4;
  17141. var iPIMXO = iFirstPIMXO + 4;
  17142. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17143. transformArgs = argsArray[iTransform];
  17144. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17145. transformArgs[0] !== firstTransformArg0 ||
  17146. transformArgs[1] !== 0 ||
  17147. transformArgs[2] !== 0 ||
  17148. transformArgs[3] !== firstTransformArg3) {
  17149. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17150. isSameImage = false;
  17151. } else {
  17152. count = q;
  17153. }
  17154. break; // different image or transform
  17155. }
  17156. }
  17157. }
  17158. if (isSameImage) {
  17159. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17160. var positions = new Float32Array(count * 2);
  17161. iTransform = iFirstTransform;
  17162. for (q = 0; q < count; q++, iTransform += 4) {
  17163. transformArgs = argsArray[iTransform];
  17164. positions[(q << 1)] = transformArgs[4];
  17165. positions[(q << 1) + 1] = transformArgs[5];
  17166. }
  17167. // Replace queue items.
  17168. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17169. argsArray.splice(iFirstSave, count * 4,
  17170. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17171. } else {
  17172. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17173. var images = [];
  17174. for (q = 0; q < count; q++) {
  17175. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17176. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17177. images.push({ data: maskParams.data, width: maskParams.width,
  17178. height: maskParams.height,
  17179. transform: transformArgs });
  17180. }
  17181. // Replace queue items.
  17182. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17183. argsArray.splice(iFirstSave, count * 4, [images]);
  17184. }
  17185. return iFirstSave + 1;
  17186. });
  17187. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17188. // with one paintImageXObjectRepeat operation, if the |transform| and
  17189. // |paintImageXObjectRepeat| ops are appropriate.
  17190. addState(InitialState,
  17191. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17192. function (context) {
  17193. var MIN_IMAGES_IN_BLOCK = 3;
  17194. var MAX_IMAGES_IN_BLOCK = 1000;
  17195. var fnArray = context.fnArray, argsArray = context.argsArray;
  17196. var curr = context.iCurr;
  17197. var iFirstSave = curr - 3;
  17198. var iFirstTransform = curr - 2;
  17199. var iFirstPIXO = curr - 1;
  17200. var iFirstRestore = curr;
  17201. if (argsArray[iFirstTransform][1] !== 0 ||
  17202. argsArray[iFirstTransform][2] !== 0) {
  17203. return iFirstRestore + 1; // transform has the wrong form
  17204. }
  17205. // Look for the quartets.
  17206. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17207. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17208. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17209. var i = iFirstSave + 4;
  17210. var ii = fnArray.length;
  17211. while (i + 3 < ii) {
  17212. if (fnArray[i] !== OPS.save ||
  17213. fnArray[i + 1] !== OPS.transform ||
  17214. fnArray[i + 2] !== OPS.paintImageXObject ||
  17215. fnArray[i + 3] !== OPS.restore) {
  17216. break; // ops don't match
  17217. }
  17218. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17219. argsArray[i + 1][1] !== 0 ||
  17220. argsArray[i + 1][2] !== 0 ||
  17221. argsArray[i + 1][3] !== firstTransformArg3) {
  17222. break; // transforms don't match
  17223. }
  17224. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17225. break; // images don't match
  17226. }
  17227. i += 4;
  17228. }
  17229. // At this point, i is the index of the first op past the last valid
  17230. // quartet.
  17231. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17232. if (count < MIN_IMAGES_IN_BLOCK) {
  17233. return i;
  17234. }
  17235. // Extract the (x,y) positions from all of the matching transforms.
  17236. var positions = new Float32Array(count * 2);
  17237. var iTransform = iFirstTransform;
  17238. for (var q = 0; q < count; q++, iTransform += 4) {
  17239. var transformArgs = argsArray[iTransform];
  17240. positions[(q << 1)] = transformArgs[4];
  17241. positions[(q << 1) + 1] = transformArgs[5];
  17242. }
  17243. // Replace queue items.
  17244. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17245. positions];
  17246. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17247. argsArray.splice(iFirstSave, count * 4, args);
  17248. return iFirstSave + 1;
  17249. });
  17250. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17251. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17252. // sequences, if the font for each one is the same.
  17253. addState(InitialState,
  17254. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17255. function (context) {
  17256. var MIN_CHARS_IN_BLOCK = 3;
  17257. var MAX_CHARS_IN_BLOCK = 1000;
  17258. var fnArray = context.fnArray, argsArray = context.argsArray;
  17259. var curr = context.iCurr;
  17260. var iFirstBeginText = curr - 4;
  17261. var iFirstSetFont = curr - 3;
  17262. var iFirstSetTextMatrix = curr - 2;
  17263. var iFirstShowText = curr - 1;
  17264. var iFirstEndText = curr;
  17265. // Look for the quintets.
  17266. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17267. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17268. var i = iFirstBeginText + 5;
  17269. var ii = fnArray.length;
  17270. while (i + 4 < ii) {
  17271. if (fnArray[i] !== OPS.beginText ||
  17272. fnArray[i + 1] !== OPS.setFont ||
  17273. fnArray[i + 2] !== OPS.setTextMatrix ||
  17274. fnArray[i + 3] !== OPS.showText ||
  17275. fnArray[i + 4] !== OPS.endText) {
  17276. break; // ops don't match
  17277. }
  17278. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17279. argsArray[i + 1][1] !== firstSetFontArg1) {
  17280. break; // fonts don't match
  17281. }
  17282. i += 5;
  17283. }
  17284. // At this point, i is the index of the first op past the last valid
  17285. // quintet.
  17286. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17287. if (count < MIN_CHARS_IN_BLOCK) {
  17288. return i;
  17289. }
  17290. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17291. // showText, endText), include that as well. (E.g. <something> might be
  17292. // |dependency|.)
  17293. var iFirst = iFirstBeginText;
  17294. if (iFirstBeginText >= 4 &&
  17295. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17296. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17297. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17298. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17299. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17300. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17301. count++;
  17302. iFirst -= 5;
  17303. }
  17304. // Remove (endText, beginText, setFont) trios.
  17305. var iEndText = iFirst + 4;
  17306. for (var q = 1; q < count; q++) {
  17307. fnArray.splice(iEndText, 3);
  17308. argsArray.splice(iEndText, 3);
  17309. iEndText += 2;
  17310. }
  17311. return iEndText + 1;
  17312. });
  17313. function QueueOptimizer() {}
  17314. QueueOptimizer.prototype = {
  17315. optimize: function QueueOptimizer_optimize(queue) {
  17316. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17317. var context = {
  17318. iCurr: 0,
  17319. fnArray: fnArray,
  17320. argsArray: argsArray
  17321. };
  17322. var state;
  17323. var i = 0, ii = fnArray.length;
  17324. while (i < ii) {
  17325. state = (state || InitialState)[fnArray[i]];
  17326. if (typeof state === 'function') { // we found some handler
  17327. context.iCurr = i;
  17328. // state() returns the index of the first non-matching op (if we
  17329. // didn't match) or the first op past the modified ops (if we did
  17330. // match and replace).
  17331. i = state(context);
  17332. state = undefined; // reset the state machine
  17333. ii = context.fnArray.length;
  17334. } else {
  17335. i++;
  17336. }
  17337. }
  17338. }
  17339. };
  17340. return QueueOptimizer;
  17341. })();
  17342. var BUILT_IN_CMAPS = [
  17343. // << Start unicode maps.
  17344. 'Adobe-GB1-UCS2',
  17345. 'Adobe-CNS1-UCS2',
  17346. 'Adobe-Japan1-UCS2',
  17347. 'Adobe-Korea1-UCS2',
  17348. // >> End unicode maps.
  17349. '78-EUC-H',
  17350. '78-EUC-V',
  17351. '78-H',
  17352. '78-RKSJ-H',
  17353. '78-RKSJ-V',
  17354. '78-V',
  17355. '78ms-RKSJ-H',
  17356. '78ms-RKSJ-V',
  17357. '83pv-RKSJ-H',
  17358. '90ms-RKSJ-H',
  17359. '90ms-RKSJ-V',
  17360. '90msp-RKSJ-H',
  17361. '90msp-RKSJ-V',
  17362. '90pv-RKSJ-H',
  17363. '90pv-RKSJ-V',
  17364. 'Add-H',
  17365. 'Add-RKSJ-H',
  17366. 'Add-RKSJ-V',
  17367. 'Add-V',
  17368. 'Adobe-CNS1-0',
  17369. 'Adobe-CNS1-1',
  17370. 'Adobe-CNS1-2',
  17371. 'Adobe-CNS1-3',
  17372. 'Adobe-CNS1-4',
  17373. 'Adobe-CNS1-5',
  17374. 'Adobe-CNS1-6',
  17375. 'Adobe-GB1-0',
  17376. 'Adobe-GB1-1',
  17377. 'Adobe-GB1-2',
  17378. 'Adobe-GB1-3',
  17379. 'Adobe-GB1-4',
  17380. 'Adobe-GB1-5',
  17381. 'Adobe-Japan1-0',
  17382. 'Adobe-Japan1-1',
  17383. 'Adobe-Japan1-2',
  17384. 'Adobe-Japan1-3',
  17385. 'Adobe-Japan1-4',
  17386. 'Adobe-Japan1-5',
  17387. 'Adobe-Japan1-6',
  17388. 'Adobe-Korea1-0',
  17389. 'Adobe-Korea1-1',
  17390. 'Adobe-Korea1-2',
  17391. 'B5-H',
  17392. 'B5-V',
  17393. 'B5pc-H',
  17394. 'B5pc-V',
  17395. 'CNS-EUC-H',
  17396. 'CNS-EUC-V',
  17397. 'CNS1-H',
  17398. 'CNS1-V',
  17399. 'CNS2-H',
  17400. 'CNS2-V',
  17401. 'ETHK-B5-H',
  17402. 'ETHK-B5-V',
  17403. 'ETen-B5-H',
  17404. 'ETen-B5-V',
  17405. 'ETenms-B5-H',
  17406. 'ETenms-B5-V',
  17407. 'EUC-H',
  17408. 'EUC-V',
  17409. 'Ext-H',
  17410. 'Ext-RKSJ-H',
  17411. 'Ext-RKSJ-V',
  17412. 'Ext-V',
  17413. 'GB-EUC-H',
  17414. 'GB-EUC-V',
  17415. 'GB-H',
  17416. 'GB-V',
  17417. 'GBK-EUC-H',
  17418. 'GBK-EUC-V',
  17419. 'GBK2K-H',
  17420. 'GBK2K-V',
  17421. 'GBKp-EUC-H',
  17422. 'GBKp-EUC-V',
  17423. 'GBT-EUC-H',
  17424. 'GBT-EUC-V',
  17425. 'GBT-H',
  17426. 'GBT-V',
  17427. 'GBTpc-EUC-H',
  17428. 'GBTpc-EUC-V',
  17429. 'GBpc-EUC-H',
  17430. 'GBpc-EUC-V',
  17431. 'H',
  17432. 'HKdla-B5-H',
  17433. 'HKdla-B5-V',
  17434. 'HKdlb-B5-H',
  17435. 'HKdlb-B5-V',
  17436. 'HKgccs-B5-H',
  17437. 'HKgccs-B5-V',
  17438. 'HKm314-B5-H',
  17439. 'HKm314-B5-V',
  17440. 'HKm471-B5-H',
  17441. 'HKm471-B5-V',
  17442. 'HKscs-B5-H',
  17443. 'HKscs-B5-V',
  17444. 'Hankaku',
  17445. 'Hiragana',
  17446. 'KSC-EUC-H',
  17447. 'KSC-EUC-V',
  17448. 'KSC-H',
  17449. 'KSC-Johab-H',
  17450. 'KSC-Johab-V',
  17451. 'KSC-V',
  17452. 'KSCms-UHC-H',
  17453. 'KSCms-UHC-HW-H',
  17454. 'KSCms-UHC-HW-V',
  17455. 'KSCms-UHC-V',
  17456. 'KSCpc-EUC-H',
  17457. 'KSCpc-EUC-V',
  17458. 'Katakana',
  17459. 'NWP-H',
  17460. 'NWP-V',
  17461. 'RKSJ-H',
  17462. 'RKSJ-V',
  17463. 'Roman',
  17464. 'UniCNS-UCS2-H',
  17465. 'UniCNS-UCS2-V',
  17466. 'UniCNS-UTF16-H',
  17467. 'UniCNS-UTF16-V',
  17468. 'UniCNS-UTF32-H',
  17469. 'UniCNS-UTF32-V',
  17470. 'UniCNS-UTF8-H',
  17471. 'UniCNS-UTF8-V',
  17472. 'UniGB-UCS2-H',
  17473. 'UniGB-UCS2-V',
  17474. 'UniGB-UTF16-H',
  17475. 'UniGB-UTF16-V',
  17476. 'UniGB-UTF32-H',
  17477. 'UniGB-UTF32-V',
  17478. 'UniGB-UTF8-H',
  17479. 'UniGB-UTF8-V',
  17480. 'UniJIS-UCS2-H',
  17481. 'UniJIS-UCS2-HW-H',
  17482. 'UniJIS-UCS2-HW-V',
  17483. 'UniJIS-UCS2-V',
  17484. 'UniJIS-UTF16-H',
  17485. 'UniJIS-UTF16-V',
  17486. 'UniJIS-UTF32-H',
  17487. 'UniJIS-UTF32-V',
  17488. 'UniJIS-UTF8-H',
  17489. 'UniJIS-UTF8-V',
  17490. 'UniJIS2004-UTF16-H',
  17491. 'UniJIS2004-UTF16-V',
  17492. 'UniJIS2004-UTF32-H',
  17493. 'UniJIS2004-UTF32-V',
  17494. 'UniJIS2004-UTF8-H',
  17495. 'UniJIS2004-UTF8-V',
  17496. 'UniJISPro-UCS2-HW-V',
  17497. 'UniJISPro-UCS2-V',
  17498. 'UniJISPro-UTF8-V',
  17499. 'UniJISX0213-UTF32-H',
  17500. 'UniJISX0213-UTF32-V',
  17501. 'UniJISX02132004-UTF32-H',
  17502. 'UniJISX02132004-UTF32-V',
  17503. 'UniKS-UCS2-H',
  17504. 'UniKS-UCS2-V',
  17505. 'UniKS-UTF16-H',
  17506. 'UniKS-UTF16-V',
  17507. 'UniKS-UTF32-H',
  17508. 'UniKS-UTF32-V',
  17509. 'UniKS-UTF8-H',
  17510. 'UniKS-UTF8-V',
  17511. 'V',
  17512. 'WP-Symbol'];
  17513. // CMap, not to be confused with TrueType's cmap.
  17514. var CMap = (function CMapClosure() {
  17515. function CMap(builtInCMap) {
  17516. // Codespace ranges are stored as follows:
  17517. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17518. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17519. this.codespaceRanges = [[], [], [], []];
  17520. this.numCodespaceRanges = 0;
  17521. // Map entries have one of two forms.
  17522. // - cid chars are 16-bit unsigned integers, stored as integers.
  17523. // - bf chars are variable-length byte sequences, stored as strings, with
  17524. // one byte per character.
  17525. this._map = [];
  17526. this.vertical = false;
  17527. this.useCMap = null;
  17528. this.builtInCMap = builtInCMap;
  17529. }
  17530. CMap.prototype = {
  17531. addCodespaceRange: function(n, low, high) {
  17532. this.codespaceRanges[n - 1].push(low, high);
  17533. this.numCodespaceRanges++;
  17534. },
  17535. mapCidRange: function(low, high, dstLow) {
  17536. while (low <= high) {
  17537. this._map[low++] = dstLow++;
  17538. }
  17539. },
  17540. mapBfRange: function(low, high, dstLow) {
  17541. var lastByte = dstLow.length - 1;
  17542. while (low <= high) {
  17543. this._map[low++] = dstLow;
  17544. // Only the last byte has to be incremented.
  17545. dstLow = dstLow.substr(0, lastByte) +
  17546. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17547. }
  17548. },
  17549. mapBfRangeToArray: function(low, high, array) {
  17550. var i = 0, ii = array.length;
  17551. while (low <= high && i < ii) {
  17552. this._map[low] = array[i++];
  17553. ++low;
  17554. }
  17555. },
  17556. // This is used for both bf and cid chars.
  17557. mapOne: function(src, dst) {
  17558. this._map[src] = dst;
  17559. },
  17560. lookup: function(code) {
  17561. return this._map[code];
  17562. },
  17563. contains: function(code) {
  17564. return this._map[code] !== undefined;
  17565. },
  17566. forEach: function(callback) {
  17567. // Most maps have fewer than 65536 entries, and for those we use normal
  17568. // array iteration. But really sparse tables are possible -- e.g. with
  17569. // indices in the *billions*. For such tables we use for..in, which isn't
  17570. // ideal because it stringifies the indices for all present elements, but
  17571. // it does avoid iterating over every undefined entry.
  17572. var map = this._map;
  17573. var length = map.length;
  17574. var i;
  17575. if (length <= 0x10000) {
  17576. for (i = 0; i < length; i++) {
  17577. if (map[i] !== undefined) {
  17578. callback(i, map[i]);
  17579. }
  17580. }
  17581. } else {
  17582. for (i in this._map) {
  17583. callback(i, map[i]);
  17584. }
  17585. }
  17586. },
  17587. charCodeOf: function(value) {
  17588. return this._map.indexOf(value);
  17589. },
  17590. getMap: function() {
  17591. return this._map;
  17592. },
  17593. readCharCode: function(str, offset, out) {
  17594. var c = 0;
  17595. var codespaceRanges = this.codespaceRanges;
  17596. var codespaceRangesLen = this.codespaceRanges.length;
  17597. // 9.7.6.2 CMap Mapping
  17598. // The code length is at most 4.
  17599. for (var n = 0; n < codespaceRangesLen; n++) {
  17600. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17601. // Check each codespace range to see if it falls within.
  17602. var codespaceRange = codespaceRanges[n];
  17603. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17604. var low = codespaceRange[k++];
  17605. var high = codespaceRange[k++];
  17606. if (c >= low && c <= high) {
  17607. out.charcode = c;
  17608. out.length = n + 1;
  17609. return;
  17610. }
  17611. }
  17612. }
  17613. out.charcode = 0;
  17614. out.length = 1;
  17615. }
  17616. };
  17617. return CMap;
  17618. })();
  17619. // A special case of CMap, where the _map array implicitly has a length of
  17620. // 65535 and each element is equal to its index.
  17621. var IdentityCMap = (function IdentityCMapClosure() {
  17622. function IdentityCMap(vertical, n) {
  17623. CMap.call(this);
  17624. this.vertical = vertical;
  17625. this.addCodespaceRange(n, 0, 0xffff);
  17626. }
  17627. Util.inherit(IdentityCMap, CMap, {});
  17628. IdentityCMap.prototype = {
  17629. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17630. mapCidRange: function(low, high, dstLow) {
  17631. error('should not call mapCidRange');
  17632. },
  17633. mapBfRange: function(low, high, dstLow) {
  17634. error('should not call mapBfRange');
  17635. },
  17636. mapBfRangeToArray: function(low, high, array) {
  17637. error('should not call mapBfRangeToArray');
  17638. },
  17639. mapOne: function(src, dst) {
  17640. error('should not call mapCidOne');
  17641. },
  17642. lookup: function(code) {
  17643. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17644. },
  17645. contains: function(code) {
  17646. return isInt(code) && code <= 0xffff;
  17647. },
  17648. forEach: function(callback) {
  17649. for (var i = 0; i <= 0xffff; i++) {
  17650. callback(i, i);
  17651. }
  17652. },
  17653. charCodeOf: function(value) {
  17654. return (isInt(value) && value <= 0xffff) ? value : -1;
  17655. },
  17656. getMap: function() {
  17657. // Sometimes identity maps must be instantiated, but it's rare.
  17658. var map = new Array(0x10000);
  17659. for (var i = 0; i <= 0xffff; i++) {
  17660. map[i] = i;
  17661. }
  17662. return map;
  17663. },
  17664. readCharCode: CMap.prototype.readCharCode
  17665. };
  17666. return IdentityCMap;
  17667. })();
  17668. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17669. function fetchBinaryData(url) {
  17670. var nonBinaryRequest = PDFJS.disableWorker;
  17671. var request = new XMLHttpRequest();
  17672. request.open('GET', url, false);
  17673. if (!nonBinaryRequest) {
  17674. try {
  17675. request.responseType = 'arraybuffer';
  17676. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17677. } catch (e) {
  17678. nonBinaryRequest = true;
  17679. }
  17680. }
  17681. if (nonBinaryRequest && request.overrideMimeType) {
  17682. request.overrideMimeType('text/plain; charset=x-user-defined');
  17683. }
  17684. request.send(null);
  17685. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17686. error('Unable to get binary cMap at: ' + url);
  17687. }
  17688. if (nonBinaryRequest) {
  17689. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17690. return ch.charCodeAt(0) & 255;
  17691. });
  17692. return new Uint8Array(data);
  17693. }
  17694. return new Uint8Array(request.response);
  17695. }
  17696. function hexToInt(a, size) {
  17697. var n = 0;
  17698. for (var i = 0; i <= size; i++) {
  17699. n = (n << 8) | a[i];
  17700. }
  17701. return n >>> 0;
  17702. }
  17703. function hexToStr(a, size) {
  17704. // This code is hot. Special-case some common values to avoid creating an
  17705. // object with subarray().
  17706. if (size === 1) {
  17707. return String.fromCharCode(a[0], a[1]);
  17708. }
  17709. if (size === 3) {
  17710. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17711. }
  17712. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17713. }
  17714. function addHex(a, b, size) {
  17715. var c = 0;
  17716. for (var i = size; i >= 0; i--) {
  17717. c += a[i] + b[i];
  17718. a[i] = c & 255;
  17719. c >>= 8;
  17720. }
  17721. }
  17722. function incHex(a, size) {
  17723. var c = 1;
  17724. for (var i = size; i >= 0 && c > 0; i--) {
  17725. c += a[i];
  17726. a[i] = c & 255;
  17727. c >>= 8;
  17728. }
  17729. }
  17730. var MAX_NUM_SIZE = 16;
  17731. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17732. function BinaryCMapStream(data) {
  17733. this.buffer = data;
  17734. this.pos = 0;
  17735. this.end = data.length;
  17736. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17737. }
  17738. BinaryCMapStream.prototype = {
  17739. readByte: function () {
  17740. if (this.pos >= this.end) {
  17741. return -1;
  17742. }
  17743. return this.buffer[this.pos++];
  17744. },
  17745. readNumber: function () {
  17746. var n = 0;
  17747. var last;
  17748. do {
  17749. var b = this.readByte();
  17750. if (b < 0) {
  17751. error('unexpected EOF in bcmap');
  17752. }
  17753. last = !(b & 0x80);
  17754. n = (n << 7) | (b & 0x7F);
  17755. } while (!last);
  17756. return n;
  17757. },
  17758. readSigned: function () {
  17759. var n = this.readNumber();
  17760. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  17761. },
  17762. readHex: function (num, size) {
  17763. num.set(this.buffer.subarray(this.pos,
  17764. this.pos + size + 1));
  17765. this.pos += size + 1;
  17766. },
  17767. readHexNumber: function (num, size) {
  17768. var last;
  17769. var stack = this.tmpBuf, sp = 0;
  17770. do {
  17771. var b = this.readByte();
  17772. if (b < 0) {
  17773. error('unexpected EOF in bcmap');
  17774. }
  17775. last = !(b & 0x80);
  17776. stack[sp++] = b & 0x7F;
  17777. } while (!last);
  17778. var i = size, buffer = 0, bufferSize = 0;
  17779. while (i >= 0) {
  17780. while (bufferSize < 8 && stack.length > 0) {
  17781. buffer = (stack[--sp] << bufferSize) | buffer;
  17782. bufferSize += 7;
  17783. }
  17784. num[i] = buffer & 255;
  17785. i--;
  17786. buffer >>= 8;
  17787. bufferSize -= 8;
  17788. }
  17789. },
  17790. readHexSigned: function (num, size) {
  17791. this.readHexNumber(num, size);
  17792. var sign = num[size] & 1 ? 255 : 0;
  17793. var c = 0;
  17794. for (var i = 0; i <= size; i++) {
  17795. c = ((c & 1) << 8) | num[i];
  17796. num[i] = (c >> 1) ^ sign;
  17797. }
  17798. },
  17799. readString: function () {
  17800. var len = this.readNumber();
  17801. var s = '';
  17802. for (var i = 0; i < len; i++) {
  17803. s += String.fromCharCode(this.readNumber());
  17804. }
  17805. return s;
  17806. }
  17807. };
  17808. function processBinaryCMap(url, cMap, extend) {
  17809. var data = fetchBinaryData(url);
  17810. var stream = new BinaryCMapStream(data);
  17811. var header = stream.readByte();
  17812. cMap.vertical = !!(header & 1);
  17813. var useCMap = null;
  17814. var start = new Uint8Array(MAX_NUM_SIZE);
  17815. var end = new Uint8Array(MAX_NUM_SIZE);
  17816. var char = new Uint8Array(MAX_NUM_SIZE);
  17817. var charCode = new Uint8Array(MAX_NUM_SIZE);
  17818. var tmp = new Uint8Array(MAX_NUM_SIZE);
  17819. var code;
  17820. var b;
  17821. while ((b = stream.readByte()) >= 0) {
  17822. var type = b >> 5;
  17823. if (type === 7) { // metadata, e.g. comment or usecmap
  17824. switch (b & 0x1F) {
  17825. case 0:
  17826. stream.readString(); // skipping comment
  17827. break;
  17828. case 1:
  17829. useCMap = stream.readString();
  17830. break;
  17831. }
  17832. continue;
  17833. }
  17834. var sequence = !!(b & 0x10);
  17835. var dataSize = b & 15;
  17836. assert(dataSize + 1 <= MAX_NUM_SIZE);
  17837. var ucs2DataSize = 1;
  17838. var subitemsCount = stream.readNumber();
  17839. var i;
  17840. switch (type) {
  17841. case 0: // codespacerange
  17842. stream.readHex(start, dataSize);
  17843. stream.readHexNumber(end, dataSize);
  17844. addHex(end, start, dataSize);
  17845. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  17846. hexToInt(end, dataSize));
  17847. for (i = 1; i < subitemsCount; i++) {
  17848. incHex(end, dataSize);
  17849. stream.readHexNumber(start, dataSize);
  17850. addHex(start, end, dataSize);
  17851. stream.readHexNumber(end, dataSize);
  17852. addHex(end, start, dataSize);
  17853. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  17854. hexToInt(end, dataSize));
  17855. }
  17856. break;
  17857. case 1: // notdefrange
  17858. stream.readHex(start, dataSize);
  17859. stream.readHexNumber(end, dataSize);
  17860. addHex(end, start, dataSize);
  17861. code = stream.readNumber();
  17862. // undefined range, skipping
  17863. for (i = 1; i < subitemsCount; i++) {
  17864. incHex(end, dataSize);
  17865. stream.readHexNumber(start, dataSize);
  17866. addHex(start, end, dataSize);
  17867. stream.readHexNumber(end, dataSize);
  17868. addHex(end, start, dataSize);
  17869. code = stream.readNumber();
  17870. // nop
  17871. }
  17872. break;
  17873. case 2: // cidchar
  17874. stream.readHex(char, dataSize);
  17875. code = stream.readNumber();
  17876. cMap.mapOne(hexToInt(char, dataSize), code);
  17877. for (i = 1; i < subitemsCount; i++) {
  17878. incHex(char, dataSize);
  17879. if (!sequence) {
  17880. stream.readHexNumber(tmp, dataSize);
  17881. addHex(char, tmp, dataSize);
  17882. }
  17883. code = stream.readSigned() + (code + 1);
  17884. cMap.mapOne(hexToInt(char, dataSize), code);
  17885. }
  17886. break;
  17887. case 3: // cidrange
  17888. stream.readHex(start, dataSize);
  17889. stream.readHexNumber(end, dataSize);
  17890. addHex(end, start, dataSize);
  17891. code = stream.readNumber();
  17892. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  17893. code);
  17894. for (i = 1; i < subitemsCount; i++) {
  17895. incHex(end, dataSize);
  17896. if (!sequence) {
  17897. stream.readHexNumber(start, dataSize);
  17898. addHex(start, end, dataSize);
  17899. } else {
  17900. start.set(end);
  17901. }
  17902. stream.readHexNumber(end, dataSize);
  17903. addHex(end, start, dataSize);
  17904. code = stream.readNumber();
  17905. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  17906. code);
  17907. }
  17908. break;
  17909. case 4: // bfchar
  17910. stream.readHex(char, ucs2DataSize);
  17911. stream.readHex(charCode, dataSize);
  17912. cMap.mapOne(hexToInt(char, ucs2DataSize),
  17913. hexToStr(charCode, dataSize));
  17914. for (i = 1; i < subitemsCount; i++) {
  17915. incHex(char, ucs2DataSize);
  17916. if (!sequence) {
  17917. stream.readHexNumber(tmp, ucs2DataSize);
  17918. addHex(char, tmp, ucs2DataSize);
  17919. }
  17920. incHex(charCode, dataSize);
  17921. stream.readHexSigned(tmp, dataSize);
  17922. addHex(charCode, tmp, dataSize);
  17923. cMap.mapOne(hexToInt(char, ucs2DataSize),
  17924. hexToStr(charCode, dataSize));
  17925. }
  17926. break;
  17927. case 5: // bfrange
  17928. stream.readHex(start, ucs2DataSize);
  17929. stream.readHexNumber(end, ucs2DataSize);
  17930. addHex(end, start, ucs2DataSize);
  17931. stream.readHex(charCode, dataSize);
  17932. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  17933. hexToInt(end, ucs2DataSize),
  17934. hexToStr(charCode, dataSize));
  17935. for (i = 1; i < subitemsCount; i++) {
  17936. incHex(end, ucs2DataSize);
  17937. if (!sequence) {
  17938. stream.readHexNumber(start, ucs2DataSize);
  17939. addHex(start, end, ucs2DataSize);
  17940. } else {
  17941. start.set(end);
  17942. }
  17943. stream.readHexNumber(end, ucs2DataSize);
  17944. addHex(end, start, ucs2DataSize);
  17945. stream.readHex(charCode, dataSize);
  17946. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  17947. hexToInt(end, ucs2DataSize),
  17948. hexToStr(charCode, dataSize));
  17949. }
  17950. break;
  17951. default:
  17952. error('Unknown type: ' + type);
  17953. break;
  17954. }
  17955. }
  17956. if (useCMap) {
  17957. extend(useCMap);
  17958. }
  17959. return cMap;
  17960. }
  17961. function BinaryCMapReader() {}
  17962. BinaryCMapReader.prototype = {
  17963. read: processBinaryCMap
  17964. };
  17965. return BinaryCMapReader;
  17966. })();
  17967. var CMapFactory = (function CMapFactoryClosure() {
  17968. function strToInt(str) {
  17969. var a = 0;
  17970. for (var i = 0; i < str.length; i++) {
  17971. a = (a << 8) | str.charCodeAt(i);
  17972. }
  17973. return a >>> 0;
  17974. }
  17975. function expectString(obj) {
  17976. if (!isString(obj)) {
  17977. error('Malformed CMap: expected string.');
  17978. }
  17979. }
  17980. function expectInt(obj) {
  17981. if (!isInt(obj)) {
  17982. error('Malformed CMap: expected int.');
  17983. }
  17984. }
  17985. function parseBfChar(cMap, lexer) {
  17986. while (true) {
  17987. var obj = lexer.getObj();
  17988. if (isEOF(obj)) {
  17989. break;
  17990. }
  17991. if (isCmd(obj, 'endbfchar')) {
  17992. return;
  17993. }
  17994. expectString(obj);
  17995. var src = strToInt(obj);
  17996. obj = lexer.getObj();
  17997. // TODO are /dstName used?
  17998. expectString(obj);
  17999. var dst = obj;
  18000. cMap.mapOne(src, dst);
  18001. }
  18002. }
  18003. function parseBfRange(cMap, lexer) {
  18004. while (true) {
  18005. var obj = lexer.getObj();
  18006. if (isEOF(obj)) {
  18007. break;
  18008. }
  18009. if (isCmd(obj, 'endbfrange')) {
  18010. return;
  18011. }
  18012. expectString(obj);
  18013. var low = strToInt(obj);
  18014. obj = lexer.getObj();
  18015. expectString(obj);
  18016. var high = strToInt(obj);
  18017. obj = lexer.getObj();
  18018. if (isInt(obj) || isString(obj)) {
  18019. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18020. cMap.mapBfRange(low, high, dstLow);
  18021. } else if (isCmd(obj, '[')) {
  18022. obj = lexer.getObj();
  18023. var array = [];
  18024. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18025. array.push(obj);
  18026. obj = lexer.getObj();
  18027. }
  18028. cMap.mapBfRangeToArray(low, high, array);
  18029. } else {
  18030. break;
  18031. }
  18032. }
  18033. error('Invalid bf range.');
  18034. }
  18035. function parseCidChar(cMap, lexer) {
  18036. while (true) {
  18037. var obj = lexer.getObj();
  18038. if (isEOF(obj)) {
  18039. break;
  18040. }
  18041. if (isCmd(obj, 'endcidchar')) {
  18042. return;
  18043. }
  18044. expectString(obj);
  18045. var src = strToInt(obj);
  18046. obj = lexer.getObj();
  18047. expectInt(obj);
  18048. var dst = obj;
  18049. cMap.mapOne(src, dst);
  18050. }
  18051. }
  18052. function parseCidRange(cMap, lexer) {
  18053. while (true) {
  18054. var obj = lexer.getObj();
  18055. if (isEOF(obj)) {
  18056. break;
  18057. }
  18058. if (isCmd(obj, 'endcidrange')) {
  18059. return;
  18060. }
  18061. expectString(obj);
  18062. var low = strToInt(obj);
  18063. obj = lexer.getObj();
  18064. expectString(obj);
  18065. var high = strToInt(obj);
  18066. obj = lexer.getObj();
  18067. expectInt(obj);
  18068. var dstLow = obj;
  18069. cMap.mapCidRange(low, high, dstLow);
  18070. }
  18071. }
  18072. function parseCodespaceRange(cMap, lexer) {
  18073. while (true) {
  18074. var obj = lexer.getObj();
  18075. if (isEOF(obj)) {
  18076. break;
  18077. }
  18078. if (isCmd(obj, 'endcodespacerange')) {
  18079. return;
  18080. }
  18081. if (!isString(obj)) {
  18082. break;
  18083. }
  18084. var low = strToInt(obj);
  18085. obj = lexer.getObj();
  18086. if (!isString(obj)) {
  18087. break;
  18088. }
  18089. var high = strToInt(obj);
  18090. cMap.addCodespaceRange(obj.length, low, high);
  18091. }
  18092. error('Invalid codespace range.');
  18093. }
  18094. function parseWMode(cMap, lexer) {
  18095. var obj = lexer.getObj();
  18096. if (isInt(obj)) {
  18097. cMap.vertical = !!obj;
  18098. }
  18099. }
  18100. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18101. var previous;
  18102. var embededUseCMap;
  18103. objLoop: while (true) {
  18104. var obj = lexer.getObj();
  18105. if (isEOF(obj)) {
  18106. break;
  18107. } else if (isName(obj)) {
  18108. if (obj.name === 'WMode') {
  18109. parseWMode(cMap, lexer);
  18110. }
  18111. previous = obj;
  18112. } else if (isCmd(obj)) {
  18113. switch (obj.cmd) {
  18114. case 'endcmap':
  18115. break objLoop;
  18116. case 'usecmap':
  18117. if (isName(previous)) {
  18118. embededUseCMap = previous.name;
  18119. }
  18120. break;
  18121. case 'begincodespacerange':
  18122. parseCodespaceRange(cMap, lexer);
  18123. break;
  18124. case 'beginbfchar':
  18125. parseBfChar(cMap, lexer);
  18126. break;
  18127. case 'begincidchar':
  18128. parseCidChar(cMap, lexer);
  18129. break;
  18130. case 'beginbfrange':
  18131. parseBfRange(cMap, lexer);
  18132. break;
  18133. case 'begincidrange':
  18134. parseCidRange(cMap, lexer);
  18135. break;
  18136. }
  18137. }
  18138. }
  18139. if (!useCMap && embededUseCMap) {
  18140. // Load the usecmap definition from the file only if there wasn't one
  18141. // specified.
  18142. useCMap = embededUseCMap;
  18143. }
  18144. if (useCMap) {
  18145. extendCMap(cMap, builtInCMapParams, useCMap);
  18146. }
  18147. }
  18148. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18149. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18150. // If there aren't any code space ranges defined clone all the parent ones
  18151. // into this cMap.
  18152. if (cMap.numCodespaceRanges === 0) {
  18153. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18154. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18155. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18156. }
  18157. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18158. }
  18159. // Merge the map into the current one, making sure not to override
  18160. // any previously defined entries.
  18161. cMap.useCMap.forEach(function(key, value) {
  18162. if (!cMap.contains(key)) {
  18163. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18164. }
  18165. });
  18166. }
  18167. function parseBinaryCMap(name, builtInCMapParams) {
  18168. var url = builtInCMapParams.url + name + '.bcmap';
  18169. var cMap = new CMap(true);
  18170. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18171. extendCMap(cMap, builtInCMapParams, useCMap);
  18172. });
  18173. return cMap;
  18174. }
  18175. function createBuiltInCMap(name, builtInCMapParams) {
  18176. if (name === 'Identity-H') {
  18177. return new IdentityCMap(false, 2);
  18178. } else if (name === 'Identity-V') {
  18179. return new IdentityCMap(true, 2);
  18180. }
  18181. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18182. error('Unknown cMap name: ' + name);
  18183. }
  18184. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18185. if (builtInCMapParams.packed) {
  18186. return parseBinaryCMap(name, builtInCMapParams);
  18187. }
  18188. var request = new XMLHttpRequest();
  18189. var url = builtInCMapParams.url + name;
  18190. request.open('GET', url, false);
  18191. request.send(null);
  18192. if (!request.responseText) {
  18193. error('Unable to get cMap at: ' + url);
  18194. }
  18195. var cMap = new CMap(true);
  18196. var lexer = new Lexer(new StringStream(request.responseText));
  18197. parseCMap(cMap, lexer, builtInCMapParams, null);
  18198. return cMap;
  18199. }
  18200. return {
  18201. create: function (encoding, builtInCMapParams, useCMap) {
  18202. if (isName(encoding)) {
  18203. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18204. } else if (isStream(encoding)) {
  18205. var cMap = new CMap();
  18206. var lexer = new Lexer(encoding);
  18207. try {
  18208. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18209. } catch (e) {
  18210. warn('Invalid CMap data. ' + e);
  18211. }
  18212. return cMap;
  18213. }
  18214. error('Encoding required.');
  18215. }
  18216. };
  18217. })();
  18218. // Unicode Private Use Area
  18219. var PRIVATE_USE_OFFSET_START = 0xE000;
  18220. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18221. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18222. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18223. // except for Type 3 fonts
  18224. var PDF_GLYPH_SPACE_UNITS = 1000;
  18225. // Hinting is currently disabled due to unknown problems on windows
  18226. // in tracemonkey and various other pdfs with type1 fonts.
  18227. var HINTING_ENABLED = false;
  18228. // Accented charactars are not displayed properly on windows, using this flag
  18229. // to control analysis of seac charstrings.
  18230. var SEAC_ANALYSIS_ENABLED = false;
  18231. var FontFlags = {
  18232. FixedPitch: 1,
  18233. Serif: 2,
  18234. Symbolic: 4,
  18235. Script: 8,
  18236. Nonsymbolic: 32,
  18237. Italic: 64,
  18238. AllCap: 65536,
  18239. SmallCap: 131072,
  18240. ForceBold: 262144
  18241. };
  18242. var Encodings = {
  18243. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18244. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18245. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18246. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18247. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18248. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18249. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18250. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18251. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18252. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18253. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18254. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18255. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18256. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18257. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18258. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18259. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18260. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18261. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18262. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18263. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18264. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18265. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18266. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18267. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18268. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18269. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18270. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18271. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18272. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18273. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18274. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18275. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18276. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18277. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18278. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18279. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18280. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18281. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18282. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18283. 'Ydieresissmall'],
  18284. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18285. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18286. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18287. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18288. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18289. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18290. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18291. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18292. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18293. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18294. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18295. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18296. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18297. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18298. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18299. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18300. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18301. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18302. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18303. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18304. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18305. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18306. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18307. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18308. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18309. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18310. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18311. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18312. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18313. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18314. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18315. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18316. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18317. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18318. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18319. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18320. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18321. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18322. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18323. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18324. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18325. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18326. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18327. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18328. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18329. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18330. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18331. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18332. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18333. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18334. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18335. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18336. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18337. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18338. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18339. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18340. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18341. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18342. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18343. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18344. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18345. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18346. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18347. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18348. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18349. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18350. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18351. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18352. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18353. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18354. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18355. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18356. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18357. 'ogonek', 'caron'],
  18358. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18359. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18360. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18361. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18362. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18363. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18364. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18365. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18366. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18367. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18368. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18369. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18370. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18371. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18372. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18373. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18374. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18375. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18376. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18377. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18378. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18379. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18380. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18381. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18382. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18383. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18384. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18385. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18386. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18387. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18388. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18389. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18390. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18391. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18392. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18393. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18394. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18395. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18396. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18397. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18398. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18399. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18400. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18401. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18402. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18403. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18404. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18405. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18406. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18407. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18408. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18409. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18410. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18411. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18412. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18413. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18414. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18415. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18416. 'ydieresis'],
  18417. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18418. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18419. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18420. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18421. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18422. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18423. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18424. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18425. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18426. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18427. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18428. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18429. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18430. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18431. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18432. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18433. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18434. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18435. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18436. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18437. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18438. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18439. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18440. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18441. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18442. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18443. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18444. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18445. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18446. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18447. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18448. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18449. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18450. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18451. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18452. 'bracerightbt'],
  18453. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18454. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18455. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18456. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18457. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18458. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18459. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18460. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18461. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18462. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18463. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18464. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18465. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18466. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18467. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18468. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18469. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18470. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18471. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18472. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18473. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18474. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18475. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18476. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18477. };
  18478. /**
  18479. * Hold a map of decoded fonts and of the standard fourteen Type1
  18480. * fonts and their acronyms.
  18481. */
  18482. var stdFontMap = {
  18483. 'ArialNarrow': 'Helvetica',
  18484. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18485. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18486. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18487. 'ArialBlack': 'Helvetica',
  18488. 'ArialBlack-Bold': 'Helvetica-Bold',
  18489. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18490. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18491. 'Arial': 'Helvetica',
  18492. 'Arial-Bold': 'Helvetica-Bold',
  18493. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18494. 'Arial-Italic': 'Helvetica-Oblique',
  18495. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18496. 'Arial-BoldMT': 'Helvetica-Bold',
  18497. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18498. 'ArialMT': 'Helvetica',
  18499. 'Courier-Bold': 'Courier-Bold',
  18500. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18501. 'Courier-Italic': 'Courier-Oblique',
  18502. 'CourierNew': 'Courier',
  18503. 'CourierNew-Bold': 'Courier-Bold',
  18504. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18505. 'CourierNew-Italic': 'Courier-Oblique',
  18506. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18507. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18508. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18509. 'CourierNewPSMT': 'Courier',
  18510. 'Helvetica-Bold': 'Helvetica-Bold',
  18511. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18512. 'Helvetica-Italic': 'Helvetica-Oblique',
  18513. 'Symbol-Bold': 'Symbol',
  18514. 'Symbol-BoldItalic': 'Symbol',
  18515. 'Symbol-Italic': 'Symbol',
  18516. 'TimesNewRoman': 'Times-Roman',
  18517. 'TimesNewRoman-Bold': 'Times-Bold',
  18518. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18519. 'TimesNewRoman-Italic': 'Times-Italic',
  18520. 'TimesNewRomanPS': 'Times-Roman',
  18521. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18522. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18523. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18524. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18525. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18526. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18527. 'TimesNewRomanPSMT': 'Times-Roman',
  18528. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18529. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18530. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18531. };
  18532. /**
  18533. * Holds the map of the non-standard fonts that might be included as a standard
  18534. * fonts without glyph data.
  18535. */
  18536. var nonStdFontMap = {
  18537. 'ComicSansMS': 'Comic Sans MS',
  18538. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18539. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18540. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18541. 'LucidaConsole': 'Courier',
  18542. 'LucidaConsole-Bold': 'Courier-Bold',
  18543. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18544. 'LucidaConsole-Italic': 'Courier-Oblique',
  18545. 'MS-Gothic': 'MS Gothic',
  18546. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18547. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18548. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18549. 'MS-Mincho': 'MS Mincho',
  18550. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18551. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18552. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18553. 'MS-PGothic': 'MS PGothic',
  18554. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18555. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18556. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18557. 'MS-PMincho': 'MS PMincho',
  18558. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18559. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18560. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  18561. };
  18562. var serifFonts = {
  18563. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18564. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18565. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18566. 'Arno': true, 'Aster': true, 'Aurora': true,
  18567. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18568. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18569. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18570. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18571. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18572. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18573. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18574. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18575. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18576. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18577. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18578. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18579. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18580. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18581. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18582. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18583. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18584. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18585. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18586. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18587. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18588. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18589. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18590. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18591. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18592. 'Miller': true, 'Minion': true, 'Modern': true,
  18593. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18594. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18595. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18596. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18597. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18598. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18599. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18600. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18601. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18602. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18603. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18604. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18605. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18606. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18607. };
  18608. var symbolsFonts = {
  18609. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18610. };
  18611. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18612. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18613. // glyphs, but common for some set of the standard fonts.
  18614. var GlyphMapForStandardFonts = {
  18615. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18616. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18617. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18618. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18619. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18620. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18621. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18622. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18623. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18624. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18625. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18626. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18627. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18628. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18629. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18630. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18631. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18632. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18633. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18634. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18635. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18636. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18637. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18638. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18639. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18640. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18641. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18642. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18643. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18644. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18645. '298': 380, '305': 963,
  18646. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18647. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18648. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18649. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18650. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18651. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18652. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18653. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18654. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18655. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18656. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18657. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18658. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18659. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18660. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18661. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18662. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18663. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18664. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18665. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18666. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18667. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18668. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18669. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18670. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18671. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18672. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18673. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18674. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18675. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18676. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18677. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18678. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18679. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18680. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18681. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18682. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18683. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18684. };
  18685. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18686. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18687. // to the similar equivalents in the normal characters range.
  18688. var SpecialPUASymbols = {
  18689. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18690. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18691. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18692. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18693. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18694. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18695. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18696. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18697. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18698. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18699. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18700. '63742': 0x23AD, // bracerightmid (0xF8FE)
  18701. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18702. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18703. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18704. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18705. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18706. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18707. '63723': 0x239B, // parenlefttp (0xF8EB)
  18708. '63724': 0x239C, // parenleftex (0xF8EC)
  18709. '63725': 0x239D, // parenleftbt (0xF8ED)
  18710. '63734': 0x239E, // parenrighttp (0xF8F6)
  18711. '63735': 0x239F, // parenrightex (0xF8F7)
  18712. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18713. };
  18714. function mapSpecialUnicodeValues(code) {
  18715. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18716. return 0;
  18717. } else if (code >= 0xF600 && code <= 0xF8FF) {
  18718. return (SpecialPUASymbols[code] || code);
  18719. }
  18720. return code;
  18721. }
  18722. var UnicodeRanges = [
  18723. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18724. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18725. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18726. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18727. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18728. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18729. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18730. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18731. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18732. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18733. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18734. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18735. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18736. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18737. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18738. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18739. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18740. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18741. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18742. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18743. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18744. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18745. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18746. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  18747. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  18748. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  18749. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  18750. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  18751. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  18752. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  18753. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  18754. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  18755. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  18756. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  18757. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  18758. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  18759. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  18760. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  18761. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  18762. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  18763. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  18764. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  18765. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  18766. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  18767. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  18768. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  18769. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  18770. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  18771. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  18772. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  18773. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  18774. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  18775. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  18776. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  18777. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  18778. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  18779. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  18780. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  18781. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  18782. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  18783. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  18784. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  18785. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  18786. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  18787. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  18788. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  18789. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  18790. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  18791. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  18792. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  18793. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  18794. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  18795. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  18796. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  18797. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  18798. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  18799. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  18800. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  18801. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  18802. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  18803. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  18804. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  18805. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  18806. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  18807. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  18808. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  18809. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  18810. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  18811. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  18812. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  18813. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  18814. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  18815. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  18816. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  18817. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  18818. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  18819. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  18820. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  18821. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  18822. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  18823. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  18824. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  18825. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  18826. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  18827. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  18828. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  18829. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  18830. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  18831. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  18832. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  18833. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  18834. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  18835. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  18836. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  18837. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  18838. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  18839. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  18840. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  18841. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  18842. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  18843. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  18844. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  18845. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  18846. ];
  18847. var MacStandardGlyphOrdering = [
  18848. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  18849. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  18850. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  18851. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  18852. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  18853. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  18854. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  18855. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  18856. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  18857. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  18858. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  18859. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  18860. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18861. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  18862. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  18863. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  18864. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  18865. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  18866. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  18867. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  18868. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  18869. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  18870. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  18871. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  18872. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  18873. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  18874. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  18875. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  18876. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  18877. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  18878. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  18879. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  18880. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  18881. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  18882. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  18883. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  18884. function getUnicodeRangeFor(value) {
  18885. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  18886. var range = UnicodeRanges[i];
  18887. if (value >= range.begin && value < range.end) {
  18888. return i;
  18889. }
  18890. }
  18891. return -1;
  18892. }
  18893. function isRTLRangeFor(value) {
  18894. var range = UnicodeRanges[13];
  18895. if (value >= range.begin && value < range.end) {
  18896. return true;
  18897. }
  18898. range = UnicodeRanges[11];
  18899. if (value >= range.begin && value < range.end) {
  18900. return true;
  18901. }
  18902. return false;
  18903. }
  18904. // The normalization table is obtained by filtering the Unicode characters
  18905. // database with <compat> entries.
  18906. var NormalizedUnicodes = {
  18907. '\u00A8': '\u0020\u0308',
  18908. '\u00AF': '\u0020\u0304',
  18909. '\u00B4': '\u0020\u0301',
  18910. '\u00B5': '\u03BC',
  18911. '\u00B8': '\u0020\u0327',
  18912. '\u0132': '\u0049\u004A',
  18913. '\u0133': '\u0069\u006A',
  18914. '\u013F': '\u004C\u00B7',
  18915. '\u0140': '\u006C\u00B7',
  18916. '\u0149': '\u02BC\u006E',
  18917. '\u017F': '\u0073',
  18918. '\u01C4': '\u0044\u017D',
  18919. '\u01C5': '\u0044\u017E',
  18920. '\u01C6': '\u0064\u017E',
  18921. '\u01C7': '\u004C\u004A',
  18922. '\u01C8': '\u004C\u006A',
  18923. '\u01C9': '\u006C\u006A',
  18924. '\u01CA': '\u004E\u004A',
  18925. '\u01CB': '\u004E\u006A',
  18926. '\u01CC': '\u006E\u006A',
  18927. '\u01F1': '\u0044\u005A',
  18928. '\u01F2': '\u0044\u007A',
  18929. '\u01F3': '\u0064\u007A',
  18930. '\u02D8': '\u0020\u0306',
  18931. '\u02D9': '\u0020\u0307',
  18932. '\u02DA': '\u0020\u030A',
  18933. '\u02DB': '\u0020\u0328',
  18934. '\u02DC': '\u0020\u0303',
  18935. '\u02DD': '\u0020\u030B',
  18936. '\u037A': '\u0020\u0345',
  18937. '\u0384': '\u0020\u0301',
  18938. '\u03D0': '\u03B2',
  18939. '\u03D1': '\u03B8',
  18940. '\u03D2': '\u03A5',
  18941. '\u03D5': '\u03C6',
  18942. '\u03D6': '\u03C0',
  18943. '\u03F0': '\u03BA',
  18944. '\u03F1': '\u03C1',
  18945. '\u03F2': '\u03C2',
  18946. '\u03F4': '\u0398',
  18947. '\u03F5': '\u03B5',
  18948. '\u03F9': '\u03A3',
  18949. '\u0587': '\u0565\u0582',
  18950. '\u0675': '\u0627\u0674',
  18951. '\u0676': '\u0648\u0674',
  18952. '\u0677': '\u06C7\u0674',
  18953. '\u0678': '\u064A\u0674',
  18954. '\u0E33': '\u0E4D\u0E32',
  18955. '\u0EB3': '\u0ECD\u0EB2',
  18956. '\u0EDC': '\u0EAB\u0E99',
  18957. '\u0EDD': '\u0EAB\u0EA1',
  18958. '\u0F77': '\u0FB2\u0F81',
  18959. '\u0F79': '\u0FB3\u0F81',
  18960. '\u1E9A': '\u0061\u02BE',
  18961. '\u1FBD': '\u0020\u0313',
  18962. '\u1FBF': '\u0020\u0313',
  18963. '\u1FC0': '\u0020\u0342',
  18964. '\u1FFE': '\u0020\u0314',
  18965. '\u2002': '\u0020',
  18966. '\u2003': '\u0020',
  18967. '\u2004': '\u0020',
  18968. '\u2005': '\u0020',
  18969. '\u2006': '\u0020',
  18970. '\u2008': '\u0020',
  18971. '\u2009': '\u0020',
  18972. '\u200A': '\u0020',
  18973. '\u2017': '\u0020\u0333',
  18974. '\u2024': '\u002E',
  18975. '\u2025': '\u002E\u002E',
  18976. '\u2026': '\u002E\u002E\u002E',
  18977. '\u2033': '\u2032\u2032',
  18978. '\u2034': '\u2032\u2032\u2032',
  18979. '\u2036': '\u2035\u2035',
  18980. '\u2037': '\u2035\u2035\u2035',
  18981. '\u203C': '\u0021\u0021',
  18982. '\u203E': '\u0020\u0305',
  18983. '\u2047': '\u003F\u003F',
  18984. '\u2048': '\u003F\u0021',
  18985. '\u2049': '\u0021\u003F',
  18986. '\u2057': '\u2032\u2032\u2032\u2032',
  18987. '\u205F': '\u0020',
  18988. '\u20A8': '\u0052\u0073',
  18989. '\u2100': '\u0061\u002F\u0063',
  18990. '\u2101': '\u0061\u002F\u0073',
  18991. '\u2103': '\u00B0\u0043',
  18992. '\u2105': '\u0063\u002F\u006F',
  18993. '\u2106': '\u0063\u002F\u0075',
  18994. '\u2107': '\u0190',
  18995. '\u2109': '\u00B0\u0046',
  18996. '\u2116': '\u004E\u006F',
  18997. '\u2121': '\u0054\u0045\u004C',
  18998. '\u2135': '\u05D0',
  18999. '\u2136': '\u05D1',
  19000. '\u2137': '\u05D2',
  19001. '\u2138': '\u05D3',
  19002. '\u213B': '\u0046\u0041\u0058',
  19003. '\u2160': '\u0049',
  19004. '\u2161': '\u0049\u0049',
  19005. '\u2162': '\u0049\u0049\u0049',
  19006. '\u2163': '\u0049\u0056',
  19007. '\u2164': '\u0056',
  19008. '\u2165': '\u0056\u0049',
  19009. '\u2166': '\u0056\u0049\u0049',
  19010. '\u2167': '\u0056\u0049\u0049\u0049',
  19011. '\u2168': '\u0049\u0058',
  19012. '\u2169': '\u0058',
  19013. '\u216A': '\u0058\u0049',
  19014. '\u216B': '\u0058\u0049\u0049',
  19015. '\u216C': '\u004C',
  19016. '\u216D': '\u0043',
  19017. '\u216E': '\u0044',
  19018. '\u216F': '\u004D',
  19019. '\u2170': '\u0069',
  19020. '\u2171': '\u0069\u0069',
  19021. '\u2172': '\u0069\u0069\u0069',
  19022. '\u2173': '\u0069\u0076',
  19023. '\u2174': '\u0076',
  19024. '\u2175': '\u0076\u0069',
  19025. '\u2176': '\u0076\u0069\u0069',
  19026. '\u2177': '\u0076\u0069\u0069\u0069',
  19027. '\u2178': '\u0069\u0078',
  19028. '\u2179': '\u0078',
  19029. '\u217A': '\u0078\u0069',
  19030. '\u217B': '\u0078\u0069\u0069',
  19031. '\u217C': '\u006C',
  19032. '\u217D': '\u0063',
  19033. '\u217E': '\u0064',
  19034. '\u217F': '\u006D',
  19035. '\u222C': '\u222B\u222B',
  19036. '\u222D': '\u222B\u222B\u222B',
  19037. '\u222F': '\u222E\u222E',
  19038. '\u2230': '\u222E\u222E\u222E',
  19039. '\u2474': '\u0028\u0031\u0029',
  19040. '\u2475': '\u0028\u0032\u0029',
  19041. '\u2476': '\u0028\u0033\u0029',
  19042. '\u2477': '\u0028\u0034\u0029',
  19043. '\u2478': '\u0028\u0035\u0029',
  19044. '\u2479': '\u0028\u0036\u0029',
  19045. '\u247A': '\u0028\u0037\u0029',
  19046. '\u247B': '\u0028\u0038\u0029',
  19047. '\u247C': '\u0028\u0039\u0029',
  19048. '\u247D': '\u0028\u0031\u0030\u0029',
  19049. '\u247E': '\u0028\u0031\u0031\u0029',
  19050. '\u247F': '\u0028\u0031\u0032\u0029',
  19051. '\u2480': '\u0028\u0031\u0033\u0029',
  19052. '\u2481': '\u0028\u0031\u0034\u0029',
  19053. '\u2482': '\u0028\u0031\u0035\u0029',
  19054. '\u2483': '\u0028\u0031\u0036\u0029',
  19055. '\u2484': '\u0028\u0031\u0037\u0029',
  19056. '\u2485': '\u0028\u0031\u0038\u0029',
  19057. '\u2486': '\u0028\u0031\u0039\u0029',
  19058. '\u2487': '\u0028\u0032\u0030\u0029',
  19059. '\u2488': '\u0031\u002E',
  19060. '\u2489': '\u0032\u002E',
  19061. '\u248A': '\u0033\u002E',
  19062. '\u248B': '\u0034\u002E',
  19063. '\u248C': '\u0035\u002E',
  19064. '\u248D': '\u0036\u002E',
  19065. '\u248E': '\u0037\u002E',
  19066. '\u248F': '\u0038\u002E',
  19067. '\u2490': '\u0039\u002E',
  19068. '\u2491': '\u0031\u0030\u002E',
  19069. '\u2492': '\u0031\u0031\u002E',
  19070. '\u2493': '\u0031\u0032\u002E',
  19071. '\u2494': '\u0031\u0033\u002E',
  19072. '\u2495': '\u0031\u0034\u002E',
  19073. '\u2496': '\u0031\u0035\u002E',
  19074. '\u2497': '\u0031\u0036\u002E',
  19075. '\u2498': '\u0031\u0037\u002E',
  19076. '\u2499': '\u0031\u0038\u002E',
  19077. '\u249A': '\u0031\u0039\u002E',
  19078. '\u249B': '\u0032\u0030\u002E',
  19079. '\u249C': '\u0028\u0061\u0029',
  19080. '\u249D': '\u0028\u0062\u0029',
  19081. '\u249E': '\u0028\u0063\u0029',
  19082. '\u249F': '\u0028\u0064\u0029',
  19083. '\u24A0': '\u0028\u0065\u0029',
  19084. '\u24A1': '\u0028\u0066\u0029',
  19085. '\u24A2': '\u0028\u0067\u0029',
  19086. '\u24A3': '\u0028\u0068\u0029',
  19087. '\u24A4': '\u0028\u0069\u0029',
  19088. '\u24A5': '\u0028\u006A\u0029',
  19089. '\u24A6': '\u0028\u006B\u0029',
  19090. '\u24A7': '\u0028\u006C\u0029',
  19091. '\u24A8': '\u0028\u006D\u0029',
  19092. '\u24A9': '\u0028\u006E\u0029',
  19093. '\u24AA': '\u0028\u006F\u0029',
  19094. '\u24AB': '\u0028\u0070\u0029',
  19095. '\u24AC': '\u0028\u0071\u0029',
  19096. '\u24AD': '\u0028\u0072\u0029',
  19097. '\u24AE': '\u0028\u0073\u0029',
  19098. '\u24AF': '\u0028\u0074\u0029',
  19099. '\u24B0': '\u0028\u0075\u0029',
  19100. '\u24B1': '\u0028\u0076\u0029',
  19101. '\u24B2': '\u0028\u0077\u0029',
  19102. '\u24B3': '\u0028\u0078\u0029',
  19103. '\u24B4': '\u0028\u0079\u0029',
  19104. '\u24B5': '\u0028\u007A\u0029',
  19105. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19106. '\u2A74': '\u003A\u003A\u003D',
  19107. '\u2A75': '\u003D\u003D',
  19108. '\u2A76': '\u003D\u003D\u003D',
  19109. '\u2E9F': '\u6BCD',
  19110. '\u2EF3': '\u9F9F',
  19111. '\u2F00': '\u4E00',
  19112. '\u2F01': '\u4E28',
  19113. '\u2F02': '\u4E36',
  19114. '\u2F03': '\u4E3F',
  19115. '\u2F04': '\u4E59',
  19116. '\u2F05': '\u4E85',
  19117. '\u2F06': '\u4E8C',
  19118. '\u2F07': '\u4EA0',
  19119. '\u2F08': '\u4EBA',
  19120. '\u2F09': '\u513F',
  19121. '\u2F0A': '\u5165',
  19122. '\u2F0B': '\u516B',
  19123. '\u2F0C': '\u5182',
  19124. '\u2F0D': '\u5196',
  19125. '\u2F0E': '\u51AB',
  19126. '\u2F0F': '\u51E0',
  19127. '\u2F10': '\u51F5',
  19128. '\u2F11': '\u5200',
  19129. '\u2F12': '\u529B',
  19130. '\u2F13': '\u52F9',
  19131. '\u2F14': '\u5315',
  19132. '\u2F15': '\u531A',
  19133. '\u2F16': '\u5338',
  19134. '\u2F17': '\u5341',
  19135. '\u2F18': '\u535C',
  19136. '\u2F19': '\u5369',
  19137. '\u2F1A': '\u5382',
  19138. '\u2F1B': '\u53B6',
  19139. '\u2F1C': '\u53C8',
  19140. '\u2F1D': '\u53E3',
  19141. '\u2F1E': '\u56D7',
  19142. '\u2F1F': '\u571F',
  19143. '\u2F20': '\u58EB',
  19144. '\u2F21': '\u5902',
  19145. '\u2F22': '\u590A',
  19146. '\u2F23': '\u5915',
  19147. '\u2F24': '\u5927',
  19148. '\u2F25': '\u5973',
  19149. '\u2F26': '\u5B50',
  19150. '\u2F27': '\u5B80',
  19151. '\u2F28': '\u5BF8',
  19152. '\u2F29': '\u5C0F',
  19153. '\u2F2A': '\u5C22',
  19154. '\u2F2B': '\u5C38',
  19155. '\u2F2C': '\u5C6E',
  19156. '\u2F2D': '\u5C71',
  19157. '\u2F2E': '\u5DDB',
  19158. '\u2F2F': '\u5DE5',
  19159. '\u2F30': '\u5DF1',
  19160. '\u2F31': '\u5DFE',
  19161. '\u2F32': '\u5E72',
  19162. '\u2F33': '\u5E7A',
  19163. '\u2F34': '\u5E7F',
  19164. '\u2F35': '\u5EF4',
  19165. '\u2F36': '\u5EFE',
  19166. '\u2F37': '\u5F0B',
  19167. '\u2F38': '\u5F13',
  19168. '\u2F39': '\u5F50',
  19169. '\u2F3A': '\u5F61',
  19170. '\u2F3B': '\u5F73',
  19171. '\u2F3C': '\u5FC3',
  19172. '\u2F3D': '\u6208',
  19173. '\u2F3E': '\u6236',
  19174. '\u2F3F': '\u624B',
  19175. '\u2F40': '\u652F',
  19176. '\u2F41': '\u6534',
  19177. '\u2F42': '\u6587',
  19178. '\u2F43': '\u6597',
  19179. '\u2F44': '\u65A4',
  19180. '\u2F45': '\u65B9',
  19181. '\u2F46': '\u65E0',
  19182. '\u2F47': '\u65E5',
  19183. '\u2F48': '\u66F0',
  19184. '\u2F49': '\u6708',
  19185. '\u2F4A': '\u6728',
  19186. '\u2F4B': '\u6B20',
  19187. '\u2F4C': '\u6B62',
  19188. '\u2F4D': '\u6B79',
  19189. '\u2F4E': '\u6BB3',
  19190. '\u2F4F': '\u6BCB',
  19191. '\u2F50': '\u6BD4',
  19192. '\u2F51': '\u6BDB',
  19193. '\u2F52': '\u6C0F',
  19194. '\u2F53': '\u6C14',
  19195. '\u2F54': '\u6C34',
  19196. '\u2F55': '\u706B',
  19197. '\u2F56': '\u722A',
  19198. '\u2F57': '\u7236',
  19199. '\u2F58': '\u723B',
  19200. '\u2F59': '\u723F',
  19201. '\u2F5A': '\u7247',
  19202. '\u2F5B': '\u7259',
  19203. '\u2F5C': '\u725B',
  19204. '\u2F5D': '\u72AC',
  19205. '\u2F5E': '\u7384',
  19206. '\u2F5F': '\u7389',
  19207. '\u2F60': '\u74DC',
  19208. '\u2F61': '\u74E6',
  19209. '\u2F62': '\u7518',
  19210. '\u2F63': '\u751F',
  19211. '\u2F64': '\u7528',
  19212. '\u2F65': '\u7530',
  19213. '\u2F66': '\u758B',
  19214. '\u2F67': '\u7592',
  19215. '\u2F68': '\u7676',
  19216. '\u2F69': '\u767D',
  19217. '\u2F6A': '\u76AE',
  19218. '\u2F6B': '\u76BF',
  19219. '\u2F6C': '\u76EE',
  19220. '\u2F6D': '\u77DB',
  19221. '\u2F6E': '\u77E2',
  19222. '\u2F6F': '\u77F3',
  19223. '\u2F70': '\u793A',
  19224. '\u2F71': '\u79B8',
  19225. '\u2F72': '\u79BE',
  19226. '\u2F73': '\u7A74',
  19227. '\u2F74': '\u7ACB',
  19228. '\u2F75': '\u7AF9',
  19229. '\u2F76': '\u7C73',
  19230. '\u2F77': '\u7CF8',
  19231. '\u2F78': '\u7F36',
  19232. '\u2F79': '\u7F51',
  19233. '\u2F7A': '\u7F8A',
  19234. '\u2F7B': '\u7FBD',
  19235. '\u2F7C': '\u8001',
  19236. '\u2F7D': '\u800C',
  19237. '\u2F7E': '\u8012',
  19238. '\u2F7F': '\u8033',
  19239. '\u2F80': '\u807F',
  19240. '\u2F81': '\u8089',
  19241. '\u2F82': '\u81E3',
  19242. '\u2F83': '\u81EA',
  19243. '\u2F84': '\u81F3',
  19244. '\u2F85': '\u81FC',
  19245. '\u2F86': '\u820C',
  19246. '\u2F87': '\u821B',
  19247. '\u2F88': '\u821F',
  19248. '\u2F89': '\u826E',
  19249. '\u2F8A': '\u8272',
  19250. '\u2F8B': '\u8278',
  19251. '\u2F8C': '\u864D',
  19252. '\u2F8D': '\u866B',
  19253. '\u2F8E': '\u8840',
  19254. '\u2F8F': '\u884C',
  19255. '\u2F90': '\u8863',
  19256. '\u2F91': '\u897E',
  19257. '\u2F92': '\u898B',
  19258. '\u2F93': '\u89D2',
  19259. '\u2F94': '\u8A00',
  19260. '\u2F95': '\u8C37',
  19261. '\u2F96': '\u8C46',
  19262. '\u2F97': '\u8C55',
  19263. '\u2F98': '\u8C78',
  19264. '\u2F99': '\u8C9D',
  19265. '\u2F9A': '\u8D64',
  19266. '\u2F9B': '\u8D70',
  19267. '\u2F9C': '\u8DB3',
  19268. '\u2F9D': '\u8EAB',
  19269. '\u2F9E': '\u8ECA',
  19270. '\u2F9F': '\u8F9B',
  19271. '\u2FA0': '\u8FB0',
  19272. '\u2FA1': '\u8FB5',
  19273. '\u2FA2': '\u9091',
  19274. '\u2FA3': '\u9149',
  19275. '\u2FA4': '\u91C6',
  19276. '\u2FA5': '\u91CC',
  19277. '\u2FA6': '\u91D1',
  19278. '\u2FA7': '\u9577',
  19279. '\u2FA8': '\u9580',
  19280. '\u2FA9': '\u961C',
  19281. '\u2FAA': '\u96B6',
  19282. '\u2FAB': '\u96B9',
  19283. '\u2FAC': '\u96E8',
  19284. '\u2FAD': '\u9751',
  19285. '\u2FAE': '\u975E',
  19286. '\u2FAF': '\u9762',
  19287. '\u2FB0': '\u9769',
  19288. '\u2FB1': '\u97CB',
  19289. '\u2FB2': '\u97ED',
  19290. '\u2FB3': '\u97F3',
  19291. '\u2FB4': '\u9801',
  19292. '\u2FB5': '\u98A8',
  19293. '\u2FB6': '\u98DB',
  19294. '\u2FB7': '\u98DF',
  19295. '\u2FB8': '\u9996',
  19296. '\u2FB9': '\u9999',
  19297. '\u2FBA': '\u99AC',
  19298. '\u2FBB': '\u9AA8',
  19299. '\u2FBC': '\u9AD8',
  19300. '\u2FBD': '\u9ADF',
  19301. '\u2FBE': '\u9B25',
  19302. '\u2FBF': '\u9B2F',
  19303. '\u2FC0': '\u9B32',
  19304. '\u2FC1': '\u9B3C',
  19305. '\u2FC2': '\u9B5A',
  19306. '\u2FC3': '\u9CE5',
  19307. '\u2FC4': '\u9E75',
  19308. '\u2FC5': '\u9E7F',
  19309. '\u2FC6': '\u9EA5',
  19310. '\u2FC7': '\u9EBB',
  19311. '\u2FC8': '\u9EC3',
  19312. '\u2FC9': '\u9ECD',
  19313. '\u2FCA': '\u9ED1',
  19314. '\u2FCB': '\u9EF9',
  19315. '\u2FCC': '\u9EFD',
  19316. '\u2FCD': '\u9F0E',
  19317. '\u2FCE': '\u9F13',
  19318. '\u2FCF': '\u9F20',
  19319. '\u2FD0': '\u9F3B',
  19320. '\u2FD1': '\u9F4A',
  19321. '\u2FD2': '\u9F52',
  19322. '\u2FD3': '\u9F8D',
  19323. '\u2FD4': '\u9F9C',
  19324. '\u2FD5': '\u9FA0',
  19325. '\u3036': '\u3012',
  19326. '\u3038': '\u5341',
  19327. '\u3039': '\u5344',
  19328. '\u303A': '\u5345',
  19329. '\u309B': '\u0020\u3099',
  19330. '\u309C': '\u0020\u309A',
  19331. '\u3131': '\u1100',
  19332. '\u3132': '\u1101',
  19333. '\u3133': '\u11AA',
  19334. '\u3134': '\u1102',
  19335. '\u3135': '\u11AC',
  19336. '\u3136': '\u11AD',
  19337. '\u3137': '\u1103',
  19338. '\u3138': '\u1104',
  19339. '\u3139': '\u1105',
  19340. '\u313A': '\u11B0',
  19341. '\u313B': '\u11B1',
  19342. '\u313C': '\u11B2',
  19343. '\u313D': '\u11B3',
  19344. '\u313E': '\u11B4',
  19345. '\u313F': '\u11B5',
  19346. '\u3140': '\u111A',
  19347. '\u3141': '\u1106',
  19348. '\u3142': '\u1107',
  19349. '\u3143': '\u1108',
  19350. '\u3144': '\u1121',
  19351. '\u3145': '\u1109',
  19352. '\u3146': '\u110A',
  19353. '\u3147': '\u110B',
  19354. '\u3148': '\u110C',
  19355. '\u3149': '\u110D',
  19356. '\u314A': '\u110E',
  19357. '\u314B': '\u110F',
  19358. '\u314C': '\u1110',
  19359. '\u314D': '\u1111',
  19360. '\u314E': '\u1112',
  19361. '\u314F': '\u1161',
  19362. '\u3150': '\u1162',
  19363. '\u3151': '\u1163',
  19364. '\u3152': '\u1164',
  19365. '\u3153': '\u1165',
  19366. '\u3154': '\u1166',
  19367. '\u3155': '\u1167',
  19368. '\u3156': '\u1168',
  19369. '\u3157': '\u1169',
  19370. '\u3158': '\u116A',
  19371. '\u3159': '\u116B',
  19372. '\u315A': '\u116C',
  19373. '\u315B': '\u116D',
  19374. '\u315C': '\u116E',
  19375. '\u315D': '\u116F',
  19376. '\u315E': '\u1170',
  19377. '\u315F': '\u1171',
  19378. '\u3160': '\u1172',
  19379. '\u3161': '\u1173',
  19380. '\u3162': '\u1174',
  19381. '\u3163': '\u1175',
  19382. '\u3164': '\u1160',
  19383. '\u3165': '\u1114',
  19384. '\u3166': '\u1115',
  19385. '\u3167': '\u11C7',
  19386. '\u3168': '\u11C8',
  19387. '\u3169': '\u11CC',
  19388. '\u316A': '\u11CE',
  19389. '\u316B': '\u11D3',
  19390. '\u316C': '\u11D7',
  19391. '\u316D': '\u11D9',
  19392. '\u316E': '\u111C',
  19393. '\u316F': '\u11DD',
  19394. '\u3170': '\u11DF',
  19395. '\u3171': '\u111D',
  19396. '\u3172': '\u111E',
  19397. '\u3173': '\u1120',
  19398. '\u3174': '\u1122',
  19399. '\u3175': '\u1123',
  19400. '\u3176': '\u1127',
  19401. '\u3177': '\u1129',
  19402. '\u3178': '\u112B',
  19403. '\u3179': '\u112C',
  19404. '\u317A': '\u112D',
  19405. '\u317B': '\u112E',
  19406. '\u317C': '\u112F',
  19407. '\u317D': '\u1132',
  19408. '\u317E': '\u1136',
  19409. '\u317F': '\u1140',
  19410. '\u3180': '\u1147',
  19411. '\u3181': '\u114C',
  19412. '\u3182': '\u11F1',
  19413. '\u3183': '\u11F2',
  19414. '\u3184': '\u1157',
  19415. '\u3185': '\u1158',
  19416. '\u3186': '\u1159',
  19417. '\u3187': '\u1184',
  19418. '\u3188': '\u1185',
  19419. '\u3189': '\u1188',
  19420. '\u318A': '\u1191',
  19421. '\u318B': '\u1192',
  19422. '\u318C': '\u1194',
  19423. '\u318D': '\u119E',
  19424. '\u318E': '\u11A1',
  19425. '\u3200': '\u0028\u1100\u0029',
  19426. '\u3201': '\u0028\u1102\u0029',
  19427. '\u3202': '\u0028\u1103\u0029',
  19428. '\u3203': '\u0028\u1105\u0029',
  19429. '\u3204': '\u0028\u1106\u0029',
  19430. '\u3205': '\u0028\u1107\u0029',
  19431. '\u3206': '\u0028\u1109\u0029',
  19432. '\u3207': '\u0028\u110B\u0029',
  19433. '\u3208': '\u0028\u110C\u0029',
  19434. '\u3209': '\u0028\u110E\u0029',
  19435. '\u320A': '\u0028\u110F\u0029',
  19436. '\u320B': '\u0028\u1110\u0029',
  19437. '\u320C': '\u0028\u1111\u0029',
  19438. '\u320D': '\u0028\u1112\u0029',
  19439. '\u320E': '\u0028\u1100\u1161\u0029',
  19440. '\u320F': '\u0028\u1102\u1161\u0029',
  19441. '\u3210': '\u0028\u1103\u1161\u0029',
  19442. '\u3211': '\u0028\u1105\u1161\u0029',
  19443. '\u3212': '\u0028\u1106\u1161\u0029',
  19444. '\u3213': '\u0028\u1107\u1161\u0029',
  19445. '\u3214': '\u0028\u1109\u1161\u0029',
  19446. '\u3215': '\u0028\u110B\u1161\u0029',
  19447. '\u3216': '\u0028\u110C\u1161\u0029',
  19448. '\u3217': '\u0028\u110E\u1161\u0029',
  19449. '\u3218': '\u0028\u110F\u1161\u0029',
  19450. '\u3219': '\u0028\u1110\u1161\u0029',
  19451. '\u321A': '\u0028\u1111\u1161\u0029',
  19452. '\u321B': '\u0028\u1112\u1161\u0029',
  19453. '\u321C': '\u0028\u110C\u116E\u0029',
  19454. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19455. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19456. '\u3220': '\u0028\u4E00\u0029',
  19457. '\u3221': '\u0028\u4E8C\u0029',
  19458. '\u3222': '\u0028\u4E09\u0029',
  19459. '\u3223': '\u0028\u56DB\u0029',
  19460. '\u3224': '\u0028\u4E94\u0029',
  19461. '\u3225': '\u0028\u516D\u0029',
  19462. '\u3226': '\u0028\u4E03\u0029',
  19463. '\u3227': '\u0028\u516B\u0029',
  19464. '\u3228': '\u0028\u4E5D\u0029',
  19465. '\u3229': '\u0028\u5341\u0029',
  19466. '\u322A': '\u0028\u6708\u0029',
  19467. '\u322B': '\u0028\u706B\u0029',
  19468. '\u322C': '\u0028\u6C34\u0029',
  19469. '\u322D': '\u0028\u6728\u0029',
  19470. '\u322E': '\u0028\u91D1\u0029',
  19471. '\u322F': '\u0028\u571F\u0029',
  19472. '\u3230': '\u0028\u65E5\u0029',
  19473. '\u3231': '\u0028\u682A\u0029',
  19474. '\u3232': '\u0028\u6709\u0029',
  19475. '\u3233': '\u0028\u793E\u0029',
  19476. '\u3234': '\u0028\u540D\u0029',
  19477. '\u3235': '\u0028\u7279\u0029',
  19478. '\u3236': '\u0028\u8CA1\u0029',
  19479. '\u3237': '\u0028\u795D\u0029',
  19480. '\u3238': '\u0028\u52B4\u0029',
  19481. '\u3239': '\u0028\u4EE3\u0029',
  19482. '\u323A': '\u0028\u547C\u0029',
  19483. '\u323B': '\u0028\u5B66\u0029',
  19484. '\u323C': '\u0028\u76E3\u0029',
  19485. '\u323D': '\u0028\u4F01\u0029',
  19486. '\u323E': '\u0028\u8CC7\u0029',
  19487. '\u323F': '\u0028\u5354\u0029',
  19488. '\u3240': '\u0028\u796D\u0029',
  19489. '\u3241': '\u0028\u4F11\u0029',
  19490. '\u3242': '\u0028\u81EA\u0029',
  19491. '\u3243': '\u0028\u81F3\u0029',
  19492. '\u32C0': '\u0031\u6708',
  19493. '\u32C1': '\u0032\u6708',
  19494. '\u32C2': '\u0033\u6708',
  19495. '\u32C3': '\u0034\u6708',
  19496. '\u32C4': '\u0035\u6708',
  19497. '\u32C5': '\u0036\u6708',
  19498. '\u32C6': '\u0037\u6708',
  19499. '\u32C7': '\u0038\u6708',
  19500. '\u32C8': '\u0039\u6708',
  19501. '\u32C9': '\u0031\u0030\u6708',
  19502. '\u32CA': '\u0031\u0031\u6708',
  19503. '\u32CB': '\u0031\u0032\u6708',
  19504. '\u3358': '\u0030\u70B9',
  19505. '\u3359': '\u0031\u70B9',
  19506. '\u335A': '\u0032\u70B9',
  19507. '\u335B': '\u0033\u70B9',
  19508. '\u335C': '\u0034\u70B9',
  19509. '\u335D': '\u0035\u70B9',
  19510. '\u335E': '\u0036\u70B9',
  19511. '\u335F': '\u0037\u70B9',
  19512. '\u3360': '\u0038\u70B9',
  19513. '\u3361': '\u0039\u70B9',
  19514. '\u3362': '\u0031\u0030\u70B9',
  19515. '\u3363': '\u0031\u0031\u70B9',
  19516. '\u3364': '\u0031\u0032\u70B9',
  19517. '\u3365': '\u0031\u0033\u70B9',
  19518. '\u3366': '\u0031\u0034\u70B9',
  19519. '\u3367': '\u0031\u0035\u70B9',
  19520. '\u3368': '\u0031\u0036\u70B9',
  19521. '\u3369': '\u0031\u0037\u70B9',
  19522. '\u336A': '\u0031\u0038\u70B9',
  19523. '\u336B': '\u0031\u0039\u70B9',
  19524. '\u336C': '\u0032\u0030\u70B9',
  19525. '\u336D': '\u0032\u0031\u70B9',
  19526. '\u336E': '\u0032\u0032\u70B9',
  19527. '\u336F': '\u0032\u0033\u70B9',
  19528. '\u3370': '\u0032\u0034\u70B9',
  19529. '\u33E0': '\u0031\u65E5',
  19530. '\u33E1': '\u0032\u65E5',
  19531. '\u33E2': '\u0033\u65E5',
  19532. '\u33E3': '\u0034\u65E5',
  19533. '\u33E4': '\u0035\u65E5',
  19534. '\u33E5': '\u0036\u65E5',
  19535. '\u33E6': '\u0037\u65E5',
  19536. '\u33E7': '\u0038\u65E5',
  19537. '\u33E8': '\u0039\u65E5',
  19538. '\u33E9': '\u0031\u0030\u65E5',
  19539. '\u33EA': '\u0031\u0031\u65E5',
  19540. '\u33EB': '\u0031\u0032\u65E5',
  19541. '\u33EC': '\u0031\u0033\u65E5',
  19542. '\u33ED': '\u0031\u0034\u65E5',
  19543. '\u33EE': '\u0031\u0035\u65E5',
  19544. '\u33EF': '\u0031\u0036\u65E5',
  19545. '\u33F0': '\u0031\u0037\u65E5',
  19546. '\u33F1': '\u0031\u0038\u65E5',
  19547. '\u33F2': '\u0031\u0039\u65E5',
  19548. '\u33F3': '\u0032\u0030\u65E5',
  19549. '\u33F4': '\u0032\u0031\u65E5',
  19550. '\u33F5': '\u0032\u0032\u65E5',
  19551. '\u33F6': '\u0032\u0033\u65E5',
  19552. '\u33F7': '\u0032\u0034\u65E5',
  19553. '\u33F8': '\u0032\u0035\u65E5',
  19554. '\u33F9': '\u0032\u0036\u65E5',
  19555. '\u33FA': '\u0032\u0037\u65E5',
  19556. '\u33FB': '\u0032\u0038\u65E5',
  19557. '\u33FC': '\u0032\u0039\u65E5',
  19558. '\u33FD': '\u0033\u0030\u65E5',
  19559. '\u33FE': '\u0033\u0031\u65E5',
  19560. '\uFB00': '\u0066\u0066',
  19561. '\uFB01': '\u0066\u0069',
  19562. '\uFB02': '\u0066\u006C',
  19563. '\uFB03': '\u0066\u0066\u0069',
  19564. '\uFB04': '\u0066\u0066\u006C',
  19565. '\uFB05': '\u017F\u0074',
  19566. '\uFB06': '\u0073\u0074',
  19567. '\uFB13': '\u0574\u0576',
  19568. '\uFB14': '\u0574\u0565',
  19569. '\uFB15': '\u0574\u056B',
  19570. '\uFB16': '\u057E\u0576',
  19571. '\uFB17': '\u0574\u056D',
  19572. '\uFB4F': '\u05D0\u05DC',
  19573. '\uFB50': '\u0671',
  19574. '\uFB51': '\u0671',
  19575. '\uFB52': '\u067B',
  19576. '\uFB53': '\u067B',
  19577. '\uFB54': '\u067B',
  19578. '\uFB55': '\u067B',
  19579. '\uFB56': '\u067E',
  19580. '\uFB57': '\u067E',
  19581. '\uFB58': '\u067E',
  19582. '\uFB59': '\u067E',
  19583. '\uFB5A': '\u0680',
  19584. '\uFB5B': '\u0680',
  19585. '\uFB5C': '\u0680',
  19586. '\uFB5D': '\u0680',
  19587. '\uFB5E': '\u067A',
  19588. '\uFB5F': '\u067A',
  19589. '\uFB60': '\u067A',
  19590. '\uFB61': '\u067A',
  19591. '\uFB62': '\u067F',
  19592. '\uFB63': '\u067F',
  19593. '\uFB64': '\u067F',
  19594. '\uFB65': '\u067F',
  19595. '\uFB66': '\u0679',
  19596. '\uFB67': '\u0679',
  19597. '\uFB68': '\u0679',
  19598. '\uFB69': '\u0679',
  19599. '\uFB6A': '\u06A4',
  19600. '\uFB6B': '\u06A4',
  19601. '\uFB6C': '\u06A4',
  19602. '\uFB6D': '\u06A4',
  19603. '\uFB6E': '\u06A6',
  19604. '\uFB6F': '\u06A6',
  19605. '\uFB70': '\u06A6',
  19606. '\uFB71': '\u06A6',
  19607. '\uFB72': '\u0684',
  19608. '\uFB73': '\u0684',
  19609. '\uFB74': '\u0684',
  19610. '\uFB75': '\u0684',
  19611. '\uFB76': '\u0683',
  19612. '\uFB77': '\u0683',
  19613. '\uFB78': '\u0683',
  19614. '\uFB79': '\u0683',
  19615. '\uFB7A': '\u0686',
  19616. '\uFB7B': '\u0686',
  19617. '\uFB7C': '\u0686',
  19618. '\uFB7D': '\u0686',
  19619. '\uFB7E': '\u0687',
  19620. '\uFB7F': '\u0687',
  19621. '\uFB80': '\u0687',
  19622. '\uFB81': '\u0687',
  19623. '\uFB82': '\u068D',
  19624. '\uFB83': '\u068D',
  19625. '\uFB84': '\u068C',
  19626. '\uFB85': '\u068C',
  19627. '\uFB86': '\u068E',
  19628. '\uFB87': '\u068E',
  19629. '\uFB88': '\u0688',
  19630. '\uFB89': '\u0688',
  19631. '\uFB8A': '\u0698',
  19632. '\uFB8B': '\u0698',
  19633. '\uFB8C': '\u0691',
  19634. '\uFB8D': '\u0691',
  19635. '\uFB8E': '\u06A9',
  19636. '\uFB8F': '\u06A9',
  19637. '\uFB90': '\u06A9',
  19638. '\uFB91': '\u06A9',
  19639. '\uFB92': '\u06AF',
  19640. '\uFB93': '\u06AF',
  19641. '\uFB94': '\u06AF',
  19642. '\uFB95': '\u06AF',
  19643. '\uFB96': '\u06B3',
  19644. '\uFB97': '\u06B3',
  19645. '\uFB98': '\u06B3',
  19646. '\uFB99': '\u06B3',
  19647. '\uFB9A': '\u06B1',
  19648. '\uFB9B': '\u06B1',
  19649. '\uFB9C': '\u06B1',
  19650. '\uFB9D': '\u06B1',
  19651. '\uFB9E': '\u06BA',
  19652. '\uFB9F': '\u06BA',
  19653. '\uFBA0': '\u06BB',
  19654. '\uFBA1': '\u06BB',
  19655. '\uFBA2': '\u06BB',
  19656. '\uFBA3': '\u06BB',
  19657. '\uFBA4': '\u06C0',
  19658. '\uFBA5': '\u06C0',
  19659. '\uFBA6': '\u06C1',
  19660. '\uFBA7': '\u06C1',
  19661. '\uFBA8': '\u06C1',
  19662. '\uFBA9': '\u06C1',
  19663. '\uFBAA': '\u06BE',
  19664. '\uFBAB': '\u06BE',
  19665. '\uFBAC': '\u06BE',
  19666. '\uFBAD': '\u06BE',
  19667. '\uFBAE': '\u06D2',
  19668. '\uFBAF': '\u06D2',
  19669. '\uFBB0': '\u06D3',
  19670. '\uFBB1': '\u06D3',
  19671. '\uFBD3': '\u06AD',
  19672. '\uFBD4': '\u06AD',
  19673. '\uFBD5': '\u06AD',
  19674. '\uFBD6': '\u06AD',
  19675. '\uFBD7': '\u06C7',
  19676. '\uFBD8': '\u06C7',
  19677. '\uFBD9': '\u06C6',
  19678. '\uFBDA': '\u06C6',
  19679. '\uFBDB': '\u06C8',
  19680. '\uFBDC': '\u06C8',
  19681. '\uFBDD': '\u0677',
  19682. '\uFBDE': '\u06CB',
  19683. '\uFBDF': '\u06CB',
  19684. '\uFBE0': '\u06C5',
  19685. '\uFBE1': '\u06C5',
  19686. '\uFBE2': '\u06C9',
  19687. '\uFBE3': '\u06C9',
  19688. '\uFBE4': '\u06D0',
  19689. '\uFBE5': '\u06D0',
  19690. '\uFBE6': '\u06D0',
  19691. '\uFBE7': '\u06D0',
  19692. '\uFBE8': '\u0649',
  19693. '\uFBE9': '\u0649',
  19694. '\uFBEA': '\u0626\u0627',
  19695. '\uFBEB': '\u0626\u0627',
  19696. '\uFBEC': '\u0626\u06D5',
  19697. '\uFBED': '\u0626\u06D5',
  19698. '\uFBEE': '\u0626\u0648',
  19699. '\uFBEF': '\u0626\u0648',
  19700. '\uFBF0': '\u0626\u06C7',
  19701. '\uFBF1': '\u0626\u06C7',
  19702. '\uFBF2': '\u0626\u06C6',
  19703. '\uFBF3': '\u0626\u06C6',
  19704. '\uFBF4': '\u0626\u06C8',
  19705. '\uFBF5': '\u0626\u06C8',
  19706. '\uFBF6': '\u0626\u06D0',
  19707. '\uFBF7': '\u0626\u06D0',
  19708. '\uFBF8': '\u0626\u06D0',
  19709. '\uFBF9': '\u0626\u0649',
  19710. '\uFBFA': '\u0626\u0649',
  19711. '\uFBFB': '\u0626\u0649',
  19712. '\uFBFC': '\u06CC',
  19713. '\uFBFD': '\u06CC',
  19714. '\uFBFE': '\u06CC',
  19715. '\uFBFF': '\u06CC',
  19716. '\uFC00': '\u0626\u062C',
  19717. '\uFC01': '\u0626\u062D',
  19718. '\uFC02': '\u0626\u0645',
  19719. '\uFC03': '\u0626\u0649',
  19720. '\uFC04': '\u0626\u064A',
  19721. '\uFC05': '\u0628\u062C',
  19722. '\uFC06': '\u0628\u062D',
  19723. '\uFC07': '\u0628\u062E',
  19724. '\uFC08': '\u0628\u0645',
  19725. '\uFC09': '\u0628\u0649',
  19726. '\uFC0A': '\u0628\u064A',
  19727. '\uFC0B': '\u062A\u062C',
  19728. '\uFC0C': '\u062A\u062D',
  19729. '\uFC0D': '\u062A\u062E',
  19730. '\uFC0E': '\u062A\u0645',
  19731. '\uFC0F': '\u062A\u0649',
  19732. '\uFC10': '\u062A\u064A',
  19733. '\uFC11': '\u062B\u062C',
  19734. '\uFC12': '\u062B\u0645',
  19735. '\uFC13': '\u062B\u0649',
  19736. '\uFC14': '\u062B\u064A',
  19737. '\uFC15': '\u062C\u062D',
  19738. '\uFC16': '\u062C\u0645',
  19739. '\uFC17': '\u062D\u062C',
  19740. '\uFC18': '\u062D\u0645',
  19741. '\uFC19': '\u062E\u062C',
  19742. '\uFC1A': '\u062E\u062D',
  19743. '\uFC1B': '\u062E\u0645',
  19744. '\uFC1C': '\u0633\u062C',
  19745. '\uFC1D': '\u0633\u062D',
  19746. '\uFC1E': '\u0633\u062E',
  19747. '\uFC1F': '\u0633\u0645',
  19748. '\uFC20': '\u0635\u062D',
  19749. '\uFC21': '\u0635\u0645',
  19750. '\uFC22': '\u0636\u062C',
  19751. '\uFC23': '\u0636\u062D',
  19752. '\uFC24': '\u0636\u062E',
  19753. '\uFC25': '\u0636\u0645',
  19754. '\uFC26': '\u0637\u062D',
  19755. '\uFC27': '\u0637\u0645',
  19756. '\uFC28': '\u0638\u0645',
  19757. '\uFC29': '\u0639\u062C',
  19758. '\uFC2A': '\u0639\u0645',
  19759. '\uFC2B': '\u063A\u062C',
  19760. '\uFC2C': '\u063A\u0645',
  19761. '\uFC2D': '\u0641\u062C',
  19762. '\uFC2E': '\u0641\u062D',
  19763. '\uFC2F': '\u0641\u062E',
  19764. '\uFC30': '\u0641\u0645',
  19765. '\uFC31': '\u0641\u0649',
  19766. '\uFC32': '\u0641\u064A',
  19767. '\uFC33': '\u0642\u062D',
  19768. '\uFC34': '\u0642\u0645',
  19769. '\uFC35': '\u0642\u0649',
  19770. '\uFC36': '\u0642\u064A',
  19771. '\uFC37': '\u0643\u0627',
  19772. '\uFC38': '\u0643\u062C',
  19773. '\uFC39': '\u0643\u062D',
  19774. '\uFC3A': '\u0643\u062E',
  19775. '\uFC3B': '\u0643\u0644',
  19776. '\uFC3C': '\u0643\u0645',
  19777. '\uFC3D': '\u0643\u0649',
  19778. '\uFC3E': '\u0643\u064A',
  19779. '\uFC3F': '\u0644\u062C',
  19780. '\uFC40': '\u0644\u062D',
  19781. '\uFC41': '\u0644\u062E',
  19782. '\uFC42': '\u0644\u0645',
  19783. '\uFC43': '\u0644\u0649',
  19784. '\uFC44': '\u0644\u064A',
  19785. '\uFC45': '\u0645\u062C',
  19786. '\uFC46': '\u0645\u062D',
  19787. '\uFC47': '\u0645\u062E',
  19788. '\uFC48': '\u0645\u0645',
  19789. '\uFC49': '\u0645\u0649',
  19790. '\uFC4A': '\u0645\u064A',
  19791. '\uFC4B': '\u0646\u062C',
  19792. '\uFC4C': '\u0646\u062D',
  19793. '\uFC4D': '\u0646\u062E',
  19794. '\uFC4E': '\u0646\u0645',
  19795. '\uFC4F': '\u0646\u0649',
  19796. '\uFC50': '\u0646\u064A',
  19797. '\uFC51': '\u0647\u062C',
  19798. '\uFC52': '\u0647\u0645',
  19799. '\uFC53': '\u0647\u0649',
  19800. '\uFC54': '\u0647\u064A',
  19801. '\uFC55': '\u064A\u062C',
  19802. '\uFC56': '\u064A\u062D',
  19803. '\uFC57': '\u064A\u062E',
  19804. '\uFC58': '\u064A\u0645',
  19805. '\uFC59': '\u064A\u0649',
  19806. '\uFC5A': '\u064A\u064A',
  19807. '\uFC5B': '\u0630\u0670',
  19808. '\uFC5C': '\u0631\u0670',
  19809. '\uFC5D': '\u0649\u0670',
  19810. '\uFC5E': '\u0020\u064C\u0651',
  19811. '\uFC5F': '\u0020\u064D\u0651',
  19812. '\uFC60': '\u0020\u064E\u0651',
  19813. '\uFC61': '\u0020\u064F\u0651',
  19814. '\uFC62': '\u0020\u0650\u0651',
  19815. '\uFC63': '\u0020\u0651\u0670',
  19816. '\uFC64': '\u0626\u0631',
  19817. '\uFC65': '\u0626\u0632',
  19818. '\uFC66': '\u0626\u0645',
  19819. '\uFC67': '\u0626\u0646',
  19820. '\uFC68': '\u0626\u0649',
  19821. '\uFC69': '\u0626\u064A',
  19822. '\uFC6A': '\u0628\u0631',
  19823. '\uFC6B': '\u0628\u0632',
  19824. '\uFC6C': '\u0628\u0645',
  19825. '\uFC6D': '\u0628\u0646',
  19826. '\uFC6E': '\u0628\u0649',
  19827. '\uFC6F': '\u0628\u064A',
  19828. '\uFC70': '\u062A\u0631',
  19829. '\uFC71': '\u062A\u0632',
  19830. '\uFC72': '\u062A\u0645',
  19831. '\uFC73': '\u062A\u0646',
  19832. '\uFC74': '\u062A\u0649',
  19833. '\uFC75': '\u062A\u064A',
  19834. '\uFC76': '\u062B\u0631',
  19835. '\uFC77': '\u062B\u0632',
  19836. '\uFC78': '\u062B\u0645',
  19837. '\uFC79': '\u062B\u0646',
  19838. '\uFC7A': '\u062B\u0649',
  19839. '\uFC7B': '\u062B\u064A',
  19840. '\uFC7C': '\u0641\u0649',
  19841. '\uFC7D': '\u0641\u064A',
  19842. '\uFC7E': '\u0642\u0649',
  19843. '\uFC7F': '\u0642\u064A',
  19844. '\uFC80': '\u0643\u0627',
  19845. '\uFC81': '\u0643\u0644',
  19846. '\uFC82': '\u0643\u0645',
  19847. '\uFC83': '\u0643\u0649',
  19848. '\uFC84': '\u0643\u064A',
  19849. '\uFC85': '\u0644\u0645',
  19850. '\uFC86': '\u0644\u0649',
  19851. '\uFC87': '\u0644\u064A',
  19852. '\uFC88': '\u0645\u0627',
  19853. '\uFC89': '\u0645\u0645',
  19854. '\uFC8A': '\u0646\u0631',
  19855. '\uFC8B': '\u0646\u0632',
  19856. '\uFC8C': '\u0646\u0645',
  19857. '\uFC8D': '\u0646\u0646',
  19858. '\uFC8E': '\u0646\u0649',
  19859. '\uFC8F': '\u0646\u064A',
  19860. '\uFC90': '\u0649\u0670',
  19861. '\uFC91': '\u064A\u0631',
  19862. '\uFC92': '\u064A\u0632',
  19863. '\uFC93': '\u064A\u0645',
  19864. '\uFC94': '\u064A\u0646',
  19865. '\uFC95': '\u064A\u0649',
  19866. '\uFC96': '\u064A\u064A',
  19867. '\uFC97': '\u0626\u062C',
  19868. '\uFC98': '\u0626\u062D',
  19869. '\uFC99': '\u0626\u062E',
  19870. '\uFC9A': '\u0626\u0645',
  19871. '\uFC9B': '\u0626\u0647',
  19872. '\uFC9C': '\u0628\u062C',
  19873. '\uFC9D': '\u0628\u062D',
  19874. '\uFC9E': '\u0628\u062E',
  19875. '\uFC9F': '\u0628\u0645',
  19876. '\uFCA0': '\u0628\u0647',
  19877. '\uFCA1': '\u062A\u062C',
  19878. '\uFCA2': '\u062A\u062D',
  19879. '\uFCA3': '\u062A\u062E',
  19880. '\uFCA4': '\u062A\u0645',
  19881. '\uFCA5': '\u062A\u0647',
  19882. '\uFCA6': '\u062B\u0645',
  19883. '\uFCA7': '\u062C\u062D',
  19884. '\uFCA8': '\u062C\u0645',
  19885. '\uFCA9': '\u062D\u062C',
  19886. '\uFCAA': '\u062D\u0645',
  19887. '\uFCAB': '\u062E\u062C',
  19888. '\uFCAC': '\u062E\u0645',
  19889. '\uFCAD': '\u0633\u062C',
  19890. '\uFCAE': '\u0633\u062D',
  19891. '\uFCAF': '\u0633\u062E',
  19892. '\uFCB0': '\u0633\u0645',
  19893. '\uFCB1': '\u0635\u062D',
  19894. '\uFCB2': '\u0635\u062E',
  19895. '\uFCB3': '\u0635\u0645',
  19896. '\uFCB4': '\u0636\u062C',
  19897. '\uFCB5': '\u0636\u062D',
  19898. '\uFCB6': '\u0636\u062E',
  19899. '\uFCB7': '\u0636\u0645',
  19900. '\uFCB8': '\u0637\u062D',
  19901. '\uFCB9': '\u0638\u0645',
  19902. '\uFCBA': '\u0639\u062C',
  19903. '\uFCBB': '\u0639\u0645',
  19904. '\uFCBC': '\u063A\u062C',
  19905. '\uFCBD': '\u063A\u0645',
  19906. '\uFCBE': '\u0641\u062C',
  19907. '\uFCBF': '\u0641\u062D',
  19908. '\uFCC0': '\u0641\u062E',
  19909. '\uFCC1': '\u0641\u0645',
  19910. '\uFCC2': '\u0642\u062D',
  19911. '\uFCC3': '\u0642\u0645',
  19912. '\uFCC4': '\u0643\u062C',
  19913. '\uFCC5': '\u0643\u062D',
  19914. '\uFCC6': '\u0643\u062E',
  19915. '\uFCC7': '\u0643\u0644',
  19916. '\uFCC8': '\u0643\u0645',
  19917. '\uFCC9': '\u0644\u062C',
  19918. '\uFCCA': '\u0644\u062D',
  19919. '\uFCCB': '\u0644\u062E',
  19920. '\uFCCC': '\u0644\u0645',
  19921. '\uFCCD': '\u0644\u0647',
  19922. '\uFCCE': '\u0645\u062C',
  19923. '\uFCCF': '\u0645\u062D',
  19924. '\uFCD0': '\u0645\u062E',
  19925. '\uFCD1': '\u0645\u0645',
  19926. '\uFCD2': '\u0646\u062C',
  19927. '\uFCD3': '\u0646\u062D',
  19928. '\uFCD4': '\u0646\u062E',
  19929. '\uFCD5': '\u0646\u0645',
  19930. '\uFCD6': '\u0646\u0647',
  19931. '\uFCD7': '\u0647\u062C',
  19932. '\uFCD8': '\u0647\u0645',
  19933. '\uFCD9': '\u0647\u0670',
  19934. '\uFCDA': '\u064A\u062C',
  19935. '\uFCDB': '\u064A\u062D',
  19936. '\uFCDC': '\u064A\u062E',
  19937. '\uFCDD': '\u064A\u0645',
  19938. '\uFCDE': '\u064A\u0647',
  19939. '\uFCDF': '\u0626\u0645',
  19940. '\uFCE0': '\u0626\u0647',
  19941. '\uFCE1': '\u0628\u0645',
  19942. '\uFCE2': '\u0628\u0647',
  19943. '\uFCE3': '\u062A\u0645',
  19944. '\uFCE4': '\u062A\u0647',
  19945. '\uFCE5': '\u062B\u0645',
  19946. '\uFCE6': '\u062B\u0647',
  19947. '\uFCE7': '\u0633\u0645',
  19948. '\uFCE8': '\u0633\u0647',
  19949. '\uFCE9': '\u0634\u0645',
  19950. '\uFCEA': '\u0634\u0647',
  19951. '\uFCEB': '\u0643\u0644',
  19952. '\uFCEC': '\u0643\u0645',
  19953. '\uFCED': '\u0644\u0645',
  19954. '\uFCEE': '\u0646\u0645',
  19955. '\uFCEF': '\u0646\u0647',
  19956. '\uFCF0': '\u064A\u0645',
  19957. '\uFCF1': '\u064A\u0647',
  19958. '\uFCF2': '\u0640\u064E\u0651',
  19959. '\uFCF3': '\u0640\u064F\u0651',
  19960. '\uFCF4': '\u0640\u0650\u0651',
  19961. '\uFCF5': '\u0637\u0649',
  19962. '\uFCF6': '\u0637\u064A',
  19963. '\uFCF7': '\u0639\u0649',
  19964. '\uFCF8': '\u0639\u064A',
  19965. '\uFCF9': '\u063A\u0649',
  19966. '\uFCFA': '\u063A\u064A',
  19967. '\uFCFB': '\u0633\u0649',
  19968. '\uFCFC': '\u0633\u064A',
  19969. '\uFCFD': '\u0634\u0649',
  19970. '\uFCFE': '\u0634\u064A',
  19971. '\uFCFF': '\u062D\u0649',
  19972. '\uFD00': '\u062D\u064A',
  19973. '\uFD01': '\u062C\u0649',
  19974. '\uFD02': '\u062C\u064A',
  19975. '\uFD03': '\u062E\u0649',
  19976. '\uFD04': '\u062E\u064A',
  19977. '\uFD05': '\u0635\u0649',
  19978. '\uFD06': '\u0635\u064A',
  19979. '\uFD07': '\u0636\u0649',
  19980. '\uFD08': '\u0636\u064A',
  19981. '\uFD09': '\u0634\u062C',
  19982. '\uFD0A': '\u0634\u062D',
  19983. '\uFD0B': '\u0634\u062E',
  19984. '\uFD0C': '\u0634\u0645',
  19985. '\uFD0D': '\u0634\u0631',
  19986. '\uFD0E': '\u0633\u0631',
  19987. '\uFD0F': '\u0635\u0631',
  19988. '\uFD10': '\u0636\u0631',
  19989. '\uFD11': '\u0637\u0649',
  19990. '\uFD12': '\u0637\u064A',
  19991. '\uFD13': '\u0639\u0649',
  19992. '\uFD14': '\u0639\u064A',
  19993. '\uFD15': '\u063A\u0649',
  19994. '\uFD16': '\u063A\u064A',
  19995. '\uFD17': '\u0633\u0649',
  19996. '\uFD18': '\u0633\u064A',
  19997. '\uFD19': '\u0634\u0649',
  19998. '\uFD1A': '\u0634\u064A',
  19999. '\uFD1B': '\u062D\u0649',
  20000. '\uFD1C': '\u062D\u064A',
  20001. '\uFD1D': '\u062C\u0649',
  20002. '\uFD1E': '\u062C\u064A',
  20003. '\uFD1F': '\u062E\u0649',
  20004. '\uFD20': '\u062E\u064A',
  20005. '\uFD21': '\u0635\u0649',
  20006. '\uFD22': '\u0635\u064A',
  20007. '\uFD23': '\u0636\u0649',
  20008. '\uFD24': '\u0636\u064A',
  20009. '\uFD25': '\u0634\u062C',
  20010. '\uFD26': '\u0634\u062D',
  20011. '\uFD27': '\u0634\u062E',
  20012. '\uFD28': '\u0634\u0645',
  20013. '\uFD29': '\u0634\u0631',
  20014. '\uFD2A': '\u0633\u0631',
  20015. '\uFD2B': '\u0635\u0631',
  20016. '\uFD2C': '\u0636\u0631',
  20017. '\uFD2D': '\u0634\u062C',
  20018. '\uFD2E': '\u0634\u062D',
  20019. '\uFD2F': '\u0634\u062E',
  20020. '\uFD30': '\u0634\u0645',
  20021. '\uFD31': '\u0633\u0647',
  20022. '\uFD32': '\u0634\u0647',
  20023. '\uFD33': '\u0637\u0645',
  20024. '\uFD34': '\u0633\u062C',
  20025. '\uFD35': '\u0633\u062D',
  20026. '\uFD36': '\u0633\u062E',
  20027. '\uFD37': '\u0634\u062C',
  20028. '\uFD38': '\u0634\u062D',
  20029. '\uFD39': '\u0634\u062E',
  20030. '\uFD3A': '\u0637\u0645',
  20031. '\uFD3B': '\u0638\u0645',
  20032. '\uFD3C': '\u0627\u064B',
  20033. '\uFD3D': '\u0627\u064B',
  20034. '\uFD50': '\u062A\u062C\u0645',
  20035. '\uFD51': '\u062A\u062D\u062C',
  20036. '\uFD52': '\u062A\u062D\u062C',
  20037. '\uFD53': '\u062A\u062D\u0645',
  20038. '\uFD54': '\u062A\u062E\u0645',
  20039. '\uFD55': '\u062A\u0645\u062C',
  20040. '\uFD56': '\u062A\u0645\u062D',
  20041. '\uFD57': '\u062A\u0645\u062E',
  20042. '\uFD58': '\u062C\u0645\u062D',
  20043. '\uFD59': '\u062C\u0645\u062D',
  20044. '\uFD5A': '\u062D\u0645\u064A',
  20045. '\uFD5B': '\u062D\u0645\u0649',
  20046. '\uFD5C': '\u0633\u062D\u062C',
  20047. '\uFD5D': '\u0633\u062C\u062D',
  20048. '\uFD5E': '\u0633\u062C\u0649',
  20049. '\uFD5F': '\u0633\u0645\u062D',
  20050. '\uFD60': '\u0633\u0645\u062D',
  20051. '\uFD61': '\u0633\u0645\u062C',
  20052. '\uFD62': '\u0633\u0645\u0645',
  20053. '\uFD63': '\u0633\u0645\u0645',
  20054. '\uFD64': '\u0635\u062D\u062D',
  20055. '\uFD65': '\u0635\u062D\u062D',
  20056. '\uFD66': '\u0635\u0645\u0645',
  20057. '\uFD67': '\u0634\u062D\u0645',
  20058. '\uFD68': '\u0634\u062D\u0645',
  20059. '\uFD69': '\u0634\u062C\u064A',
  20060. '\uFD6A': '\u0634\u0645\u062E',
  20061. '\uFD6B': '\u0634\u0645\u062E',
  20062. '\uFD6C': '\u0634\u0645\u0645',
  20063. '\uFD6D': '\u0634\u0645\u0645',
  20064. '\uFD6E': '\u0636\u062D\u0649',
  20065. '\uFD6F': '\u0636\u062E\u0645',
  20066. '\uFD70': '\u0636\u062E\u0645',
  20067. '\uFD71': '\u0637\u0645\u062D',
  20068. '\uFD72': '\u0637\u0645\u062D',
  20069. '\uFD73': '\u0637\u0645\u0645',
  20070. '\uFD74': '\u0637\u0645\u064A',
  20071. '\uFD75': '\u0639\u062C\u0645',
  20072. '\uFD76': '\u0639\u0645\u0645',
  20073. '\uFD77': '\u0639\u0645\u0645',
  20074. '\uFD78': '\u0639\u0645\u0649',
  20075. '\uFD79': '\u063A\u0645\u0645',
  20076. '\uFD7A': '\u063A\u0645\u064A',
  20077. '\uFD7B': '\u063A\u0645\u0649',
  20078. '\uFD7C': '\u0641\u062E\u0645',
  20079. '\uFD7D': '\u0641\u062E\u0645',
  20080. '\uFD7E': '\u0642\u0645\u062D',
  20081. '\uFD7F': '\u0642\u0645\u0645',
  20082. '\uFD80': '\u0644\u062D\u0645',
  20083. '\uFD81': '\u0644\u062D\u064A',
  20084. '\uFD82': '\u0644\u062D\u0649',
  20085. '\uFD83': '\u0644\u062C\u062C',
  20086. '\uFD84': '\u0644\u062C\u062C',
  20087. '\uFD85': '\u0644\u062E\u0645',
  20088. '\uFD86': '\u0644\u062E\u0645',
  20089. '\uFD87': '\u0644\u0645\u062D',
  20090. '\uFD88': '\u0644\u0645\u062D',
  20091. '\uFD89': '\u0645\u062D\u062C',
  20092. '\uFD8A': '\u0645\u062D\u0645',
  20093. '\uFD8B': '\u0645\u062D\u064A',
  20094. '\uFD8C': '\u0645\u062C\u062D',
  20095. '\uFD8D': '\u0645\u062C\u0645',
  20096. '\uFD8E': '\u0645\u062E\u062C',
  20097. '\uFD8F': '\u0645\u062E\u0645',
  20098. '\uFD92': '\u0645\u062C\u062E',
  20099. '\uFD93': '\u0647\u0645\u062C',
  20100. '\uFD94': '\u0647\u0645\u0645',
  20101. '\uFD95': '\u0646\u062D\u0645',
  20102. '\uFD96': '\u0646\u062D\u0649',
  20103. '\uFD97': '\u0646\u062C\u0645',
  20104. '\uFD98': '\u0646\u062C\u0645',
  20105. '\uFD99': '\u0646\u062C\u0649',
  20106. '\uFD9A': '\u0646\u0645\u064A',
  20107. '\uFD9B': '\u0646\u0645\u0649',
  20108. '\uFD9C': '\u064A\u0645\u0645',
  20109. '\uFD9D': '\u064A\u0645\u0645',
  20110. '\uFD9E': '\u0628\u062E\u064A',
  20111. '\uFD9F': '\u062A\u062C\u064A',
  20112. '\uFDA0': '\u062A\u062C\u0649',
  20113. '\uFDA1': '\u062A\u062E\u064A',
  20114. '\uFDA2': '\u062A\u062E\u0649',
  20115. '\uFDA3': '\u062A\u0645\u064A',
  20116. '\uFDA4': '\u062A\u0645\u0649',
  20117. '\uFDA5': '\u062C\u0645\u064A',
  20118. '\uFDA6': '\u062C\u062D\u0649',
  20119. '\uFDA7': '\u062C\u0645\u0649',
  20120. '\uFDA8': '\u0633\u062E\u0649',
  20121. '\uFDA9': '\u0635\u062D\u064A',
  20122. '\uFDAA': '\u0634\u062D\u064A',
  20123. '\uFDAB': '\u0636\u062D\u064A',
  20124. '\uFDAC': '\u0644\u062C\u064A',
  20125. '\uFDAD': '\u0644\u0645\u064A',
  20126. '\uFDAE': '\u064A\u062D\u064A',
  20127. '\uFDAF': '\u064A\u062C\u064A',
  20128. '\uFDB0': '\u064A\u0645\u064A',
  20129. '\uFDB1': '\u0645\u0645\u064A',
  20130. '\uFDB2': '\u0642\u0645\u064A',
  20131. '\uFDB3': '\u0646\u062D\u064A',
  20132. '\uFDB4': '\u0642\u0645\u062D',
  20133. '\uFDB5': '\u0644\u062D\u0645',
  20134. '\uFDB6': '\u0639\u0645\u064A',
  20135. '\uFDB7': '\u0643\u0645\u064A',
  20136. '\uFDB8': '\u0646\u062C\u062D',
  20137. '\uFDB9': '\u0645\u062E\u064A',
  20138. '\uFDBA': '\u0644\u062C\u0645',
  20139. '\uFDBB': '\u0643\u0645\u0645',
  20140. '\uFDBC': '\u0644\u062C\u0645',
  20141. '\uFDBD': '\u0646\u062C\u062D',
  20142. '\uFDBE': '\u062C\u062D\u064A',
  20143. '\uFDBF': '\u062D\u062C\u064A',
  20144. '\uFDC0': '\u0645\u062C\u064A',
  20145. '\uFDC1': '\u0641\u0645\u064A',
  20146. '\uFDC2': '\u0628\u062D\u064A',
  20147. '\uFDC3': '\u0643\u0645\u0645',
  20148. '\uFDC4': '\u0639\u062C\u0645',
  20149. '\uFDC5': '\u0635\u0645\u0645',
  20150. '\uFDC6': '\u0633\u062E\u064A',
  20151. '\uFDC7': '\u0646\u062C\u064A',
  20152. '\uFE49': '\u203E',
  20153. '\uFE4A': '\u203E',
  20154. '\uFE4B': '\u203E',
  20155. '\uFE4C': '\u203E',
  20156. '\uFE4D': '\u005F',
  20157. '\uFE4E': '\u005F',
  20158. '\uFE4F': '\u005F',
  20159. '\uFE80': '\u0621',
  20160. '\uFE81': '\u0622',
  20161. '\uFE82': '\u0622',
  20162. '\uFE83': '\u0623',
  20163. '\uFE84': '\u0623',
  20164. '\uFE85': '\u0624',
  20165. '\uFE86': '\u0624',
  20166. '\uFE87': '\u0625',
  20167. '\uFE88': '\u0625',
  20168. '\uFE89': '\u0626',
  20169. '\uFE8A': '\u0626',
  20170. '\uFE8B': '\u0626',
  20171. '\uFE8C': '\u0626',
  20172. '\uFE8D': '\u0627',
  20173. '\uFE8E': '\u0627',
  20174. '\uFE8F': '\u0628',
  20175. '\uFE90': '\u0628',
  20176. '\uFE91': '\u0628',
  20177. '\uFE92': '\u0628',
  20178. '\uFE93': '\u0629',
  20179. '\uFE94': '\u0629',
  20180. '\uFE95': '\u062A',
  20181. '\uFE96': '\u062A',
  20182. '\uFE97': '\u062A',
  20183. '\uFE98': '\u062A',
  20184. '\uFE99': '\u062B',
  20185. '\uFE9A': '\u062B',
  20186. '\uFE9B': '\u062B',
  20187. '\uFE9C': '\u062B',
  20188. '\uFE9D': '\u062C',
  20189. '\uFE9E': '\u062C',
  20190. '\uFE9F': '\u062C',
  20191. '\uFEA0': '\u062C',
  20192. '\uFEA1': '\u062D',
  20193. '\uFEA2': '\u062D',
  20194. '\uFEA3': '\u062D',
  20195. '\uFEA4': '\u062D',
  20196. '\uFEA5': '\u062E',
  20197. '\uFEA6': '\u062E',
  20198. '\uFEA7': '\u062E',
  20199. '\uFEA8': '\u062E',
  20200. '\uFEA9': '\u062F',
  20201. '\uFEAA': '\u062F',
  20202. '\uFEAB': '\u0630',
  20203. '\uFEAC': '\u0630',
  20204. '\uFEAD': '\u0631',
  20205. '\uFEAE': '\u0631',
  20206. '\uFEAF': '\u0632',
  20207. '\uFEB0': '\u0632',
  20208. '\uFEB1': '\u0633',
  20209. '\uFEB2': '\u0633',
  20210. '\uFEB3': '\u0633',
  20211. '\uFEB4': '\u0633',
  20212. '\uFEB5': '\u0634',
  20213. '\uFEB6': '\u0634',
  20214. '\uFEB7': '\u0634',
  20215. '\uFEB8': '\u0634',
  20216. '\uFEB9': '\u0635',
  20217. '\uFEBA': '\u0635',
  20218. '\uFEBB': '\u0635',
  20219. '\uFEBC': '\u0635',
  20220. '\uFEBD': '\u0636',
  20221. '\uFEBE': '\u0636',
  20222. '\uFEBF': '\u0636',
  20223. '\uFEC0': '\u0636',
  20224. '\uFEC1': '\u0637',
  20225. '\uFEC2': '\u0637',
  20226. '\uFEC3': '\u0637',
  20227. '\uFEC4': '\u0637',
  20228. '\uFEC5': '\u0638',
  20229. '\uFEC6': '\u0638',
  20230. '\uFEC7': '\u0638',
  20231. '\uFEC8': '\u0638',
  20232. '\uFEC9': '\u0639',
  20233. '\uFECA': '\u0639',
  20234. '\uFECB': '\u0639',
  20235. '\uFECC': '\u0639',
  20236. '\uFECD': '\u063A',
  20237. '\uFECE': '\u063A',
  20238. '\uFECF': '\u063A',
  20239. '\uFED0': '\u063A',
  20240. '\uFED1': '\u0641',
  20241. '\uFED2': '\u0641',
  20242. '\uFED3': '\u0641',
  20243. '\uFED4': '\u0641',
  20244. '\uFED5': '\u0642',
  20245. '\uFED6': '\u0642',
  20246. '\uFED7': '\u0642',
  20247. '\uFED8': '\u0642',
  20248. '\uFED9': '\u0643',
  20249. '\uFEDA': '\u0643',
  20250. '\uFEDB': '\u0643',
  20251. '\uFEDC': '\u0643',
  20252. '\uFEDD': '\u0644',
  20253. '\uFEDE': '\u0644',
  20254. '\uFEDF': '\u0644',
  20255. '\uFEE0': '\u0644',
  20256. '\uFEE1': '\u0645',
  20257. '\uFEE2': '\u0645',
  20258. '\uFEE3': '\u0645',
  20259. '\uFEE4': '\u0645',
  20260. '\uFEE5': '\u0646',
  20261. '\uFEE6': '\u0646',
  20262. '\uFEE7': '\u0646',
  20263. '\uFEE8': '\u0646',
  20264. '\uFEE9': '\u0647',
  20265. '\uFEEA': '\u0647',
  20266. '\uFEEB': '\u0647',
  20267. '\uFEEC': '\u0647',
  20268. '\uFEED': '\u0648',
  20269. '\uFEEE': '\u0648',
  20270. '\uFEEF': '\u0649',
  20271. '\uFEF0': '\u0649',
  20272. '\uFEF1': '\u064A',
  20273. '\uFEF2': '\u064A',
  20274. '\uFEF3': '\u064A',
  20275. '\uFEF4': '\u064A',
  20276. '\uFEF5': '\u0644\u0622',
  20277. '\uFEF6': '\u0644\u0622',
  20278. '\uFEF7': '\u0644\u0623',
  20279. '\uFEF8': '\u0644\u0623',
  20280. '\uFEF9': '\u0644\u0625',
  20281. '\uFEFA': '\u0644\u0625',
  20282. '\uFEFB': '\u0644\u0627',
  20283. '\uFEFC': '\u0644\u0627'
  20284. };
  20285. function reverseIfRtl(chars) {
  20286. var charsLength = chars.length;
  20287. //reverse an arabic ligature
  20288. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20289. return chars;
  20290. }
  20291. var s = '';
  20292. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20293. s += chars[ii];
  20294. }
  20295. return s;
  20296. }
  20297. function adjustWidths(properties) {
  20298. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20299. return;
  20300. }
  20301. // adjusting width to fontMatrix scale
  20302. var scale = 0.001 / properties.fontMatrix[0];
  20303. var glyphsWidths = properties.widths;
  20304. for (var glyph in glyphsWidths) {
  20305. glyphsWidths[glyph] *= scale;
  20306. }
  20307. properties.defaultWidth *= scale;
  20308. }
  20309. function getFontType(type, subtype) {
  20310. switch (type) {
  20311. case 'Type1':
  20312. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20313. case 'CIDFontType0':
  20314. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20315. FontType.CIDFONTTYPE0;
  20316. case 'OpenType':
  20317. return FontType.OPENTYPE;
  20318. case 'TrueType':
  20319. return FontType.TRUETYPE;
  20320. case 'CIDFontType2':
  20321. return FontType.CIDFONTTYPE2;
  20322. case 'MMType1':
  20323. return FontType.MMTYPE1;
  20324. case 'Type0':
  20325. return FontType.TYPE0;
  20326. default:
  20327. return FontType.UNKNOWN;
  20328. }
  20329. }
  20330. var Glyph = (function GlyphClosure() {
  20331. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20332. this.fontChar = fontChar;
  20333. this.unicode = unicode;
  20334. this.accent = accent;
  20335. this.width = width;
  20336. this.vmetric = vmetric;
  20337. this.operatorListId = operatorListId;
  20338. }
  20339. Glyph.prototype.matchesForCache =
  20340. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20341. return this.fontChar === fontChar &&
  20342. this.unicode === unicode &&
  20343. this.accent === accent &&
  20344. this.width === width &&
  20345. this.vmetric === vmetric &&
  20346. this.operatorListId === operatorListId;
  20347. };
  20348. return Glyph;
  20349. })();
  20350. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20351. function ToUnicodeMap(cmap) {
  20352. // The elements of this._map can be integers or strings, depending on how
  20353. // |cmap| was created.
  20354. this._map = cmap;
  20355. }
  20356. ToUnicodeMap.prototype = {
  20357. get length() {
  20358. return this._map.length;
  20359. },
  20360. forEach: function(callback) {
  20361. for (var charCode in this._map) {
  20362. callback(charCode, this._map[charCode].charCodeAt(0));
  20363. }
  20364. },
  20365. get: function(i) {
  20366. return this._map[i];
  20367. },
  20368. charCodeOf: function(v) {
  20369. return this._map.indexOf(v);
  20370. }
  20371. };
  20372. return ToUnicodeMap;
  20373. })();
  20374. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20375. function IdentityToUnicodeMap(firstChar, lastChar) {
  20376. this.firstChar = firstChar;
  20377. this.lastChar = lastChar;
  20378. }
  20379. IdentityToUnicodeMap.prototype = {
  20380. get length() {
  20381. error('should not access .length');
  20382. },
  20383. forEach: function (callback) {
  20384. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20385. callback(i, i);
  20386. }
  20387. },
  20388. get: function (i) {
  20389. if (this.firstChar <= i && i <= this.lastChar) {
  20390. return String.fromCharCode(i);
  20391. }
  20392. return undefined;
  20393. },
  20394. charCodeOf: function (v) {
  20395. error('should not call .charCodeOf');
  20396. }
  20397. };
  20398. return IdentityToUnicodeMap;
  20399. })();
  20400. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20401. function writeInt16(dest, offset, num) {
  20402. dest[offset] = (num >> 8) & 0xFF;
  20403. dest[offset + 1] = num & 0xFF;
  20404. }
  20405. function writeInt32(dest, offset, num) {
  20406. dest[offset] = (num >> 24) & 0xFF;
  20407. dest[offset + 1] = (num >> 16) & 0xFF;
  20408. dest[offset + 2] = (num >> 8) & 0xFF;
  20409. dest[offset + 3] = num & 0xFF;
  20410. }
  20411. function writeData(dest, offset, data) {
  20412. var i, ii;
  20413. if (data instanceof Uint8Array) {
  20414. dest.set(data, offset);
  20415. } else if (typeof data === 'string') {
  20416. for (i = 0, ii = data.length; i < ii; i++) {
  20417. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20418. }
  20419. } else {
  20420. // treating everything else as array
  20421. for (i = 0, ii = data.length; i < ii; i++) {
  20422. dest[offset++] = data[i] & 0xFF;
  20423. }
  20424. }
  20425. }
  20426. function OpenTypeFileBuilder(sfnt) {
  20427. this.sfnt = sfnt;
  20428. this.tables = Object.create(null);
  20429. }
  20430. OpenTypeFileBuilder.getSearchParams =
  20431. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20432. var maxPower2 = 1, log2 = 0;
  20433. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20434. maxPower2 <<= 1;
  20435. log2++;
  20436. }
  20437. var searchRange = maxPower2 * entrySize;
  20438. return {
  20439. range: searchRange,
  20440. entry: log2,
  20441. rangeShift: entrySize * entriesCount - searchRange
  20442. };
  20443. };
  20444. var OTF_HEADER_SIZE = 12;
  20445. var OTF_TABLE_ENTRY_SIZE = 16;
  20446. OpenTypeFileBuilder.prototype = {
  20447. toArray: function OpenTypeFileBuilder_toArray() {
  20448. var sfnt = this.sfnt;
  20449. // Tables needs to be written by ascendant alphabetic order
  20450. var tables = this.tables;
  20451. var tablesNames = Object.keys(tables);
  20452. tablesNames.sort();
  20453. var numTables = tablesNames.length;
  20454. var i, j, jj, table, tableName;
  20455. // layout the tables data
  20456. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20457. var tableOffsets = [offset];
  20458. for (i = 0; i < numTables; i++) {
  20459. table = tables[tablesNames[i]];
  20460. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20461. offset += paddedLength;
  20462. tableOffsets.push(offset);
  20463. }
  20464. var file = new Uint8Array(offset);
  20465. // write the table data first (mostly for checksum)
  20466. for (i = 0; i < numTables; i++) {
  20467. table = tables[tablesNames[i]];
  20468. writeData(file, tableOffsets[i], table);
  20469. }
  20470. // sfnt version (4 bytes)
  20471. if (sfnt === 'true') {
  20472. // Windows hates the Mac TrueType sfnt version number
  20473. sfnt = string32(0x00010000);
  20474. }
  20475. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20476. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20477. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20478. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20479. // numTables (2 bytes)
  20480. writeInt16(file, 4, numTables);
  20481. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20482. // searchRange (2 bytes)
  20483. writeInt16(file, 6, searchParams.range);
  20484. // entrySelector (2 bytes)
  20485. writeInt16(file, 8, searchParams.entry);
  20486. // rangeShift (2 bytes)
  20487. writeInt16(file, 10, searchParams.rangeShift);
  20488. offset = OTF_HEADER_SIZE;
  20489. // writing table entries
  20490. for (i = 0; i < numTables; i++) {
  20491. tableName = tablesNames[i];
  20492. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20493. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20494. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20495. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20496. // checksum
  20497. var checksum = 0;
  20498. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20499. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20500. (file[j + 2] << 8) + file[j + 3];
  20501. checksum = (checksum + quad) | 0;
  20502. }
  20503. writeInt32(file, offset + 4, checksum);
  20504. // offset
  20505. writeInt32(file, offset + 8, tableOffsets[i]);
  20506. // length
  20507. writeInt32(file, offset + 12, tables[tableName].length);
  20508. offset += OTF_TABLE_ENTRY_SIZE;
  20509. }
  20510. return file;
  20511. },
  20512. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20513. if (tag in this.tables) {
  20514. throw new Error('Table ' + tag + ' already exists');
  20515. }
  20516. this.tables[tag] = data;
  20517. }
  20518. };
  20519. return OpenTypeFileBuilder;
  20520. })();
  20521. /**
  20522. * 'Font' is the class the outside world should use, it encapsulate all the font
  20523. * decoding logics whatever type it is (assuming the font type is supported).
  20524. *
  20525. * For example to read a Type1 font and to attach it to the document:
  20526. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20527. * type1Font.bind();
  20528. */
  20529. var Font = (function FontClosure() {
  20530. function Font(name, file, properties) {
  20531. var charCode, glyphName, fontChar;
  20532. this.name = name;
  20533. this.loadedName = properties.loadedName;
  20534. this.isType3Font = properties.isType3Font;
  20535. this.sizes = [];
  20536. this.glyphCache = {};
  20537. var names = name.split('+');
  20538. names = names.length > 1 ? names[1] : names[0];
  20539. names = names.split(/[-,_]/g)[0];
  20540. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20541. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20542. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20543. var type = properties.type;
  20544. var subtype = properties.subtype;
  20545. this.type = type;
  20546. this.fallbackName = (this.isMonospace ? 'monospace' :
  20547. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20548. this.differences = properties.differences;
  20549. this.widths = properties.widths;
  20550. this.defaultWidth = properties.defaultWidth;
  20551. this.composite = properties.composite;
  20552. this.wideChars = properties.wideChars;
  20553. this.cMap = properties.cMap;
  20554. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20555. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20556. this.fontMatrix = properties.fontMatrix;
  20557. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20558. this.toFontChar = [];
  20559. if (properties.type === 'Type3') {
  20560. for (charCode = 0; charCode < 256; charCode++) {
  20561. this.toFontChar[charCode] = (this.differences[charCode] ||
  20562. properties.defaultEncoding[charCode]);
  20563. }
  20564. this.fontType = FontType.TYPE3;
  20565. return;
  20566. }
  20567. this.cidEncoding = properties.cidEncoding;
  20568. this.vertical = properties.vertical;
  20569. if (this.vertical) {
  20570. this.vmetrics = properties.vmetrics;
  20571. this.defaultVMetrics = properties.defaultVMetrics;
  20572. }
  20573. if (!file || file.isEmpty) {
  20574. if (file) {
  20575. // Some bad PDF generators will include empty font files,
  20576. // attempting to recover by assuming that no file exists.
  20577. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20578. }
  20579. this.missingFile = true;
  20580. // The file data is not specified. Trying to fix the font name
  20581. // to be used with the canvas.font.
  20582. var fontName = name.replace(/[,_]/g, '-');
  20583. var isStandardFont = fontName in stdFontMap;
  20584. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20585. this.bold = (fontName.search(/bold/gi) !== -1);
  20586. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20587. (fontName.search(/italic/gi) !== -1));
  20588. // Use 'name' instead of 'fontName' here because the original
  20589. // name ArialBlack for example will be replaced by Helvetica.
  20590. this.black = (name.search(/Black/g) !== -1);
  20591. // if at least one width is present, remeasure all chars when exists
  20592. this.remeasure = Object.keys(this.widths).length > 0;
  20593. if (isStandardFont && type === 'CIDFontType2' &&
  20594. properties.cidEncoding.indexOf('Identity-') === 0) {
  20595. // Standard fonts might be embedded as CID font without glyph mapping.
  20596. // Building one based on GlyphMapForStandardFonts.
  20597. var map = [];
  20598. for (var code in GlyphMapForStandardFonts) {
  20599. map[+code] = GlyphMapForStandardFonts[code];
  20600. }
  20601. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20602. if (!isIdentityUnicode) {
  20603. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20604. map[+charCode] = unicodeCharCode;
  20605. });
  20606. }
  20607. this.toFontChar = map;
  20608. this.toUnicode = new ToUnicodeMap(map);
  20609. } else if (/Symbol/i.test(fontName)) {
  20610. var symbols = Encodings.SymbolSetEncoding;
  20611. for (charCode in symbols) {
  20612. fontChar = GlyphsUnicode[symbols[charCode]];
  20613. if (!fontChar) {
  20614. continue;
  20615. }
  20616. this.toFontChar[charCode] = fontChar;
  20617. }
  20618. for (charCode in properties.differences) {
  20619. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20620. if (!fontChar) {
  20621. continue;
  20622. }
  20623. this.toFontChar[charCode] = fontChar;
  20624. }
  20625. } else if (/Dingbats/i.test(fontName)) {
  20626. var dingbats = Encodings.ZapfDingbatsEncoding;
  20627. for (charCode in dingbats) {
  20628. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20629. if (!fontChar) {
  20630. continue;
  20631. }
  20632. this.toFontChar[charCode] = fontChar;
  20633. }
  20634. for (charCode in properties.differences) {
  20635. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20636. if (!fontChar) {
  20637. continue;
  20638. }
  20639. this.toFontChar[charCode] = fontChar;
  20640. }
  20641. } else if (isStandardFont) {
  20642. this.toFontChar = [];
  20643. for (charCode in properties.defaultEncoding) {
  20644. glyphName = (properties.differences[charCode] ||
  20645. properties.defaultEncoding[charCode]);
  20646. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20647. }
  20648. } else {
  20649. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20650. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20651. if (notCidFont) {
  20652. glyphName = (properties.differences[charCode] ||
  20653. properties.defaultEncoding[charCode]);
  20654. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20655. }
  20656. this.toFontChar[charCode] = unicodeCharCode;
  20657. }.bind(this));
  20658. }
  20659. this.loadedName = fontName.split('-')[0];
  20660. this.loading = false;
  20661. this.fontType = getFontType(type, subtype);
  20662. return;
  20663. }
  20664. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20665. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20666. // Some TrueType fonts by mistake claim Type1C
  20667. if (isTrueTypeFile(file)) {
  20668. subtype = 'TrueType';
  20669. } else {
  20670. type = 'Type1';
  20671. }
  20672. }
  20673. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20674. type = 'CIDFontType0';
  20675. }
  20676. // XXX: Temporarily change the type for open type so we trigger a warning.
  20677. // This should be removed when we add support for open type.
  20678. if (subtype === 'OpenType') {
  20679. type = 'OpenType';
  20680. }
  20681. var data;
  20682. switch (type) {
  20683. case 'MMType1':
  20684. info('MMType1 font (' + name + '), falling back to Type1.');
  20685. /* falls through */
  20686. case 'Type1':
  20687. case 'CIDFontType0':
  20688. this.mimetype = 'font/opentype';
  20689. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20690. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20691. adjustWidths(properties);
  20692. // Wrap the CFF data inside an OTF font file
  20693. data = this.convert(name, cff, properties);
  20694. break;
  20695. case 'OpenType':
  20696. case 'TrueType':
  20697. case 'CIDFontType2':
  20698. this.mimetype = 'font/opentype';
  20699. // Repair the TrueType file. It is can be damaged in the point of
  20700. // view of the sanitizer
  20701. data = this.checkAndRepair(name, file, properties);
  20702. if (this.isOpenType) {
  20703. type = 'OpenType';
  20704. }
  20705. break;
  20706. default:
  20707. error('Font ' + type + ' is not supported');
  20708. break;
  20709. }
  20710. this.data = data;
  20711. this.fontType = getFontType(type, subtype);
  20712. // Transfer some properties again that could change during font conversion
  20713. this.fontMatrix = properties.fontMatrix;
  20714. this.widths = properties.widths;
  20715. this.defaultWidth = properties.defaultWidth;
  20716. this.encoding = properties.baseEncoding;
  20717. this.seacMap = properties.seacMap;
  20718. this.loading = true;
  20719. }
  20720. Font.getFontID = (function () {
  20721. var ID = 1;
  20722. return function Font_getFontID() {
  20723. return String(ID++);
  20724. };
  20725. })();
  20726. function int16(b0, b1) {
  20727. return (b0 << 8) + b1;
  20728. }
  20729. function int32(b0, b1, b2, b3) {
  20730. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20731. }
  20732. function string16(value) {
  20733. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20734. }
  20735. function safeString16(value) {
  20736. // clamp value to the 16-bit int range
  20737. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  20738. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20739. }
  20740. function isTrueTypeFile(file) {
  20741. var header = file.peekBytes(4);
  20742. return readUint32(header, 0) === 0x00010000;
  20743. }
  20744. /**
  20745. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  20746. * with their unicode value. It also moves char codes that are in known
  20747. * problematic locations.
  20748. * @return {Object} Two properties:
  20749. * 'toFontChar' - maps original char codes(the value that will be read
  20750. * from commands such as show text) to the char codes that will be used in the
  20751. * font that we build
  20752. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  20753. */
  20754. function adjustMapping(charCodeToGlyphId, properties) {
  20755. var toUnicode = properties.toUnicode;
  20756. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  20757. var isIdentityUnicode =
  20758. properties.toUnicode instanceof IdentityToUnicodeMap;
  20759. var isCidFontType2 = (properties.type === 'CIDFontType2');
  20760. var newMap = Object.create(null);
  20761. var toFontChar = [];
  20762. var usedFontCharCodes = [];
  20763. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  20764. for (var originalCharCode in charCodeToGlyphId) {
  20765. originalCharCode |= 0;
  20766. var glyphId = charCodeToGlyphId[originalCharCode];
  20767. var fontCharCode = originalCharCode;
  20768. // First try to map the value to a unicode position if a non identity map
  20769. // was created.
  20770. if (!isIdentityUnicode) {
  20771. if (toUnicode.get(originalCharCode) !== undefined) {
  20772. var unicode = toUnicode.get(fontCharCode);
  20773. // TODO: Try to map ligatures to the correct spot.
  20774. if (unicode.length === 1) {
  20775. fontCharCode = unicode.charCodeAt(0);
  20776. }
  20777. } else if (isCidFontType2) {
  20778. // For CIDFontType2, move characters not present in toUnicode
  20779. // to the private use area (fixes bug 1028735 and issue 4881).
  20780. fontCharCode = nextAvailableFontCharCode;
  20781. }
  20782. }
  20783. // Try to move control characters, special characters and already mapped
  20784. // characters to the private use area since they will not be drawn by
  20785. // canvas if left in their current position. Also, move characters if the
  20786. // font was symbolic and there is only an identity unicode map since the
  20787. // characters probably aren't in the correct position (fixes an issue
  20788. // with firefox and thuluthfont).
  20789. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  20790. fontCharCode <= 0x1f || // Control chars
  20791. fontCharCode === 0x7F || // Control char
  20792. fontCharCode === 0xAD || // Soft hyphen
  20793. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  20794. // Prevent drawing characters in the specials unicode block.
  20795. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  20796. (isSymbolic && isIdentityUnicode)) &&
  20797. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  20798. // Loop to try and find a free spot in the private use area.
  20799. do {
  20800. fontCharCode = nextAvailableFontCharCode++;
  20801. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  20802. fontCharCode = 0xF020;
  20803. nextAvailableFontCharCode = fontCharCode + 1;
  20804. }
  20805. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  20806. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  20807. }
  20808. newMap[fontCharCode] = glyphId;
  20809. toFontChar[originalCharCode] = fontCharCode;
  20810. usedFontCharCodes[fontCharCode] = true;
  20811. }
  20812. return {
  20813. toFontChar: toFontChar,
  20814. charCodeToGlyphId: newMap,
  20815. nextAvailableFontCharCode: nextAvailableFontCharCode
  20816. };
  20817. }
  20818. function getRanges(glyphs) {
  20819. // Array.sort() sorts by characters, not numerically, so convert to an
  20820. // array of characters.
  20821. var codes = [];
  20822. for (var charCode in glyphs) {
  20823. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  20824. }
  20825. codes.sort(function fontGetRangesSort(a, b) {
  20826. return a.fontCharCode - b.fontCharCode;
  20827. });
  20828. // Split the sorted codes into ranges.
  20829. var ranges = [];
  20830. var length = codes.length;
  20831. for (var n = 0; n < length; ) {
  20832. var start = codes[n].fontCharCode;
  20833. var codeIndices = [codes[n].glyphId];
  20834. ++n;
  20835. var end = start;
  20836. while (n < length && end + 1 === codes[n].fontCharCode) {
  20837. codeIndices.push(codes[n].glyphId);
  20838. ++end;
  20839. ++n;
  20840. if (end === 0xFFFF) {
  20841. break;
  20842. }
  20843. }
  20844. ranges.push([start, end, codeIndices]);
  20845. }
  20846. return ranges;
  20847. }
  20848. function createCmapTable(glyphs) {
  20849. var ranges = getRanges(glyphs);
  20850. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  20851. var cmap = '\x00\x00' + // version
  20852. string16(numTables) + // numTables
  20853. '\x00\x03' + // platformID
  20854. '\x00\x01' + // encodingID
  20855. string32(4 + numTables * 8); // start of the table record
  20856. var i, ii, j, jj;
  20857. for (i = ranges.length - 1; i >= 0; --i) {
  20858. if (ranges[i][0] <= 0xFFFF) { break; }
  20859. }
  20860. var bmpLength = i + 1;
  20861. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  20862. ranges[i][1] = 0xFFFE;
  20863. }
  20864. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  20865. var segCount = bmpLength + trailingRangesCount;
  20866. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  20867. // Fill up the 4 parallel arrays describing the segments.
  20868. var startCount = '';
  20869. var endCount = '';
  20870. var idDeltas = '';
  20871. var idRangeOffsets = '';
  20872. var glyphsIds = '';
  20873. var bias = 0;
  20874. var range, start, end, codes;
  20875. for (i = 0, ii = bmpLength; i < ii; i++) {
  20876. range = ranges[i];
  20877. start = range[0];
  20878. end = range[1];
  20879. startCount += string16(start);
  20880. endCount += string16(end);
  20881. codes = range[2];
  20882. var contiguous = true;
  20883. for (j = 1, jj = codes.length; j < jj; ++j) {
  20884. if (codes[j] !== codes[j - 1] + 1) {
  20885. contiguous = false;
  20886. break;
  20887. }
  20888. }
  20889. if (!contiguous) {
  20890. var offset = (segCount - i) * 2 + bias * 2;
  20891. bias += (end - start + 1);
  20892. idDeltas += string16(0);
  20893. idRangeOffsets += string16(offset);
  20894. for (j = 0, jj = codes.length; j < jj; ++j) {
  20895. glyphsIds += string16(codes[j]);
  20896. }
  20897. } else {
  20898. var startCode = codes[0];
  20899. idDeltas += string16((startCode - start) & 0xFFFF);
  20900. idRangeOffsets += string16(0);
  20901. }
  20902. }
  20903. if (trailingRangesCount > 0) {
  20904. endCount += '\xFF\xFF';
  20905. startCount += '\xFF\xFF';
  20906. idDeltas += '\x00\x01';
  20907. idRangeOffsets += '\x00\x00';
  20908. }
  20909. var format314 = '\x00\x00' + // language
  20910. string16(2 * segCount) +
  20911. string16(searchParams.range) +
  20912. string16(searchParams.entry) +
  20913. string16(searchParams.rangeShift) +
  20914. endCount + '\x00\x00' + startCount +
  20915. idDeltas + idRangeOffsets + glyphsIds;
  20916. var format31012 = '';
  20917. var header31012 = '';
  20918. if (numTables > 1) {
  20919. cmap += '\x00\x03' + // platformID
  20920. '\x00\x0A' + // encodingID
  20921. string32(4 + numTables * 8 +
  20922. 4 + format314.length); // start of the table record
  20923. format31012 = '';
  20924. for (i = 0, ii = ranges.length; i < ii; i++) {
  20925. range = ranges[i];
  20926. start = range[0];
  20927. codes = range[2];
  20928. var code = codes[0];
  20929. for (j = 1, jj = codes.length; j < jj; ++j) {
  20930. if (codes[j] !== codes[j - 1] + 1) {
  20931. end = range[0] + j - 1;
  20932. format31012 += string32(start) + // startCharCode
  20933. string32(end) + // endCharCode
  20934. string32(code); // startGlyphID
  20935. start = end + 1;
  20936. code = codes[j];
  20937. }
  20938. }
  20939. format31012 += string32(start) + // startCharCode
  20940. string32(range[1]) + // endCharCode
  20941. string32(code); // startGlyphID
  20942. }
  20943. header31012 = '\x00\x0C' + // format
  20944. '\x00\x00' + // reserved
  20945. string32(format31012.length + 16) + // length
  20946. '\x00\x00\x00\x00' + // language
  20947. string32(format31012.length / 12); // nGroups
  20948. }
  20949. return cmap + '\x00\x04' + // format
  20950. string16(format314.length + 4) + // length
  20951. format314 + header31012 + format31012;
  20952. }
  20953. function validateOS2Table(os2) {
  20954. var stream = new Stream(os2.data);
  20955. var version = stream.getUint16();
  20956. // TODO verify all OS/2 tables fields, but currently we validate only those
  20957. // that give us issues
  20958. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  20959. var selection = stream.getUint16();
  20960. if (version < 4 && (selection & 0x0300)) {
  20961. return false;
  20962. }
  20963. var firstChar = stream.getUint16();
  20964. var lastChar = stream.getUint16();
  20965. if (firstChar > lastChar) {
  20966. return false;
  20967. }
  20968. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  20969. var usWinAscent = stream.getUint16();
  20970. if (usWinAscent === 0) { // makes font unreadable by windows
  20971. return false;
  20972. }
  20973. // OS/2 appears to be valid, resetting some fields
  20974. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  20975. return true;
  20976. }
  20977. function createOS2Table(properties, charstrings, override) {
  20978. override = override || {
  20979. unitsPerEm: 0,
  20980. yMax: 0,
  20981. yMin: 0,
  20982. ascent: 0,
  20983. descent: 0
  20984. };
  20985. var ulUnicodeRange1 = 0;
  20986. var ulUnicodeRange2 = 0;
  20987. var ulUnicodeRange3 = 0;
  20988. var ulUnicodeRange4 = 0;
  20989. var firstCharIndex = null;
  20990. var lastCharIndex = 0;
  20991. if (charstrings) {
  20992. for (var code in charstrings) {
  20993. code |= 0;
  20994. if (firstCharIndex > code || !firstCharIndex) {
  20995. firstCharIndex = code;
  20996. }
  20997. if (lastCharIndex < code) {
  20998. lastCharIndex = code;
  20999. }
  21000. var position = getUnicodeRangeFor(code);
  21001. if (position < 32) {
  21002. ulUnicodeRange1 |= 1 << position;
  21003. } else if (position < 64) {
  21004. ulUnicodeRange2 |= 1 << position - 32;
  21005. } else if (position < 96) {
  21006. ulUnicodeRange3 |= 1 << position - 64;
  21007. } else if (position < 123) {
  21008. ulUnicodeRange4 |= 1 << position - 96;
  21009. } else {
  21010. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21011. }
  21012. }
  21013. } else {
  21014. // TODO
  21015. firstCharIndex = 0;
  21016. lastCharIndex = 255;
  21017. }
  21018. var bbox = properties.bbox || [0, 0, 0, 0];
  21019. var unitsPerEm = (override.unitsPerEm ||
  21020. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21021. // if the font units differ to the PDF glyph space units
  21022. // then scale up the values
  21023. var scale = (properties.ascentScaled ? 1.0 :
  21024. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21025. var typoAscent = (override.ascent ||
  21026. Math.round(scale * (properties.ascent || bbox[3])));
  21027. var typoDescent = (override.descent ||
  21028. Math.round(scale * (properties.descent || bbox[1])));
  21029. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21030. typoDescent = -typoDescent; // fixing incorrect descent
  21031. }
  21032. var winAscent = override.yMax || typoAscent;
  21033. var winDescent = -override.yMin || -typoDescent;
  21034. return '\x00\x03' + // version
  21035. '\x02\x24' + // xAvgCharWidth
  21036. '\x01\xF4' + // usWeightClass
  21037. '\x00\x05' + // usWidthClass
  21038. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21039. '\x02\x8A' + // ySubscriptXSize
  21040. '\x02\xBB' + // ySubscriptYSize
  21041. '\x00\x00' + // ySubscriptXOffset
  21042. '\x00\x8C' + // ySubscriptYOffset
  21043. '\x02\x8A' + // ySuperScriptXSize
  21044. '\x02\xBB' + // ySuperScriptYSize
  21045. '\x00\x00' + // ySuperScriptXOffset
  21046. '\x01\xDF' + // ySuperScriptYOffset
  21047. '\x00\x31' + // yStrikeOutSize
  21048. '\x01\x02' + // yStrikeOutPosition
  21049. '\x00\x00' + // sFamilyClass
  21050. '\x00\x00\x06' +
  21051. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21052. '\x00\x00\x00\x00\x00\x00' + // Panose
  21053. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21054. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21055. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21056. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21057. '\x2A\x32\x31\x2A' + // achVendID
  21058. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21059. string16(firstCharIndex ||
  21060. properties.firstChar) + // usFirstCharIndex
  21061. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21062. string16(typoAscent) + // sTypoAscender
  21063. string16(typoDescent) + // sTypoDescender
  21064. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21065. string16(winAscent) + // usWinAscent
  21066. string16(winDescent) + // usWinDescent
  21067. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21068. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21069. string16(properties.xHeight) + // sxHeight
  21070. string16(properties.capHeight) + // sCapHeight
  21071. string16(0) + // usDefaultChar
  21072. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21073. '\x00\x03'; // usMaxContext
  21074. }
  21075. function createPostTable(properties) {
  21076. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21077. return ('\x00\x03\x00\x00' + // Version number
  21078. string32(angle) + // italicAngle
  21079. '\x00\x00' + // underlinePosition
  21080. '\x00\x00' + // underlineThickness
  21081. string32(properties.fixedPitch) + // isFixedPitch
  21082. '\x00\x00\x00\x00' + // minMemType42
  21083. '\x00\x00\x00\x00' + // maxMemType42
  21084. '\x00\x00\x00\x00' + // minMemType1
  21085. '\x00\x00\x00\x00'); // maxMemType1
  21086. }
  21087. function createNameTable(name, proto) {
  21088. if (!proto) {
  21089. proto = [[], []]; // no strings and unicode strings
  21090. }
  21091. var strings = [
  21092. proto[0][0] || 'Original licence', // 0.Copyright
  21093. proto[0][1] || name, // 1.Font family
  21094. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21095. proto[0][3] || 'uniqueID', // 3.Unique ID
  21096. proto[0][4] || name, // 4.Full font name
  21097. proto[0][5] || 'Version 0.11', // 5.Version
  21098. proto[0][6] || '', // 6.Postscript name
  21099. proto[0][7] || 'Unknown', // 7.Trademark
  21100. proto[0][8] || 'Unknown', // 8.Manufacturer
  21101. proto[0][9] || 'Unknown' // 9.Designer
  21102. ];
  21103. // Mac want 1-byte per character strings while Windows want
  21104. // 2-bytes per character, so duplicate the names table
  21105. var stringsUnicode = [];
  21106. var i, ii, j, jj, str;
  21107. for (i = 0, ii = strings.length; i < ii; i++) {
  21108. str = proto[1][i] || strings[i];
  21109. var strBufUnicode = [];
  21110. for (j = 0, jj = str.length; j < jj; j++) {
  21111. strBufUnicode.push(string16(str.charCodeAt(j)));
  21112. }
  21113. stringsUnicode.push(strBufUnicode.join(''));
  21114. }
  21115. var names = [strings, stringsUnicode];
  21116. var platforms = ['\x00\x01', '\x00\x03'];
  21117. var encodings = ['\x00\x00', '\x00\x01'];
  21118. var languages = ['\x00\x00', '\x04\x09'];
  21119. var namesRecordCount = strings.length * platforms.length;
  21120. var nameTable =
  21121. '\x00\x00' + // format
  21122. string16(namesRecordCount) + // Number of names Record
  21123. string16(namesRecordCount * 12 + 6); // Storage
  21124. // Build the name records field
  21125. var strOffset = 0;
  21126. for (i = 0, ii = platforms.length; i < ii; i++) {
  21127. var strs = names[i];
  21128. for (j = 0, jj = strs.length; j < jj; j++) {
  21129. str = strs[j];
  21130. var nameRecord =
  21131. platforms[i] + // platform ID
  21132. encodings[i] + // encoding ID
  21133. languages[i] + // language ID
  21134. string16(j) + // name ID
  21135. string16(str.length) +
  21136. string16(strOffset);
  21137. nameTable += nameRecord;
  21138. strOffset += str.length;
  21139. }
  21140. }
  21141. nameTable += strings.join('') + stringsUnicode.join('');
  21142. return nameTable;
  21143. }
  21144. Font.prototype = {
  21145. name: null,
  21146. font: null,
  21147. mimetype: null,
  21148. encoding: null,
  21149. get renderer() {
  21150. var renderer = FontRendererFactory.create(this);
  21151. return shadow(this, 'renderer', renderer);
  21152. },
  21153. exportData: function Font_exportData() {
  21154. var data = {};
  21155. for (var i in this) {
  21156. if (this.hasOwnProperty(i)) {
  21157. data[i] = this[i];
  21158. }
  21159. }
  21160. return data;
  21161. },
  21162. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21163. function readTableEntry(file) {
  21164. var tag = bytesToString(file.getBytes(4));
  21165. var checksum = file.getInt32();
  21166. var offset = file.getInt32() >>> 0;
  21167. var length = file.getInt32() >>> 0;
  21168. // Read the table associated data
  21169. var previousPosition = file.pos;
  21170. file.pos = file.start ? file.start : 0;
  21171. file.skip(offset);
  21172. var data = file.getBytes(length);
  21173. file.pos = previousPosition;
  21174. if (tag === 'head') {
  21175. // clearing checksum adjustment
  21176. data[8] = data[9] = data[10] = data[11] = 0;
  21177. data[17] |= 0x20; //Set font optimized for cleartype flag
  21178. }
  21179. return {
  21180. tag: tag,
  21181. checksum: checksum,
  21182. length: length,
  21183. offset: offset,
  21184. data: data
  21185. };
  21186. }
  21187. function readOpenTypeHeader(ttf) {
  21188. return {
  21189. version: bytesToString(ttf.getBytes(4)),
  21190. numTables: ttf.getUint16(),
  21191. searchRange: ttf.getUint16(),
  21192. entrySelector: ttf.getUint16(),
  21193. rangeShift: ttf.getUint16()
  21194. };
  21195. }
  21196. /**
  21197. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21198. * PDF spec
  21199. */
  21200. function readCmapTable(cmap, font, isSymbolicFont) {
  21201. var segment;
  21202. var start = (font.start ? font.start : 0) + cmap.offset;
  21203. font.pos = start;
  21204. var version = font.getUint16();
  21205. var numTables = font.getUint16();
  21206. var potentialTable;
  21207. var canBreak = false;
  21208. // There's an order of preference in terms of which cmap subtable to
  21209. // use:
  21210. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21211. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21212. // The following takes advantage of the fact that the tables are sorted
  21213. // to work.
  21214. for (var i = 0; i < numTables; i++) {
  21215. var platformId = font.getUint16();
  21216. var encodingId = font.getUint16();
  21217. var offset = font.getInt32() >>> 0;
  21218. var useTable = false;
  21219. if (platformId === 1 && encodingId === 0) {
  21220. useTable = true;
  21221. // Continue the loop since there still may be a higher priority
  21222. // table.
  21223. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  21224. useTable = true;
  21225. canBreak = true;
  21226. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21227. useTable = true;
  21228. canBreak = true;
  21229. }
  21230. if (useTable) {
  21231. potentialTable = {
  21232. platformId: platformId,
  21233. encodingId: encodingId,
  21234. offset: offset
  21235. };
  21236. }
  21237. if (canBreak) {
  21238. break;
  21239. }
  21240. }
  21241. if (!potentialTable) {
  21242. warn('Could not find a preferred cmap table.');
  21243. return {
  21244. platformId: -1,
  21245. encodingId: -1,
  21246. mappings: [],
  21247. hasShortCmap: false
  21248. };
  21249. }
  21250. font.pos = start + potentialTable.offset;
  21251. var format = font.getUint16();
  21252. var length = font.getUint16();
  21253. var language = font.getUint16();
  21254. var hasShortCmap = false;
  21255. var mappings = [];
  21256. var j, glyphId;
  21257. // TODO(mack): refactor this cmap subtable reading logic out
  21258. if (format === 0) {
  21259. for (j = 0; j < 256; j++) {
  21260. var index = font.getByte();
  21261. if (!index) {
  21262. continue;
  21263. }
  21264. mappings.push({
  21265. charCode: j,
  21266. glyphId: index
  21267. });
  21268. }
  21269. hasShortCmap = true;
  21270. } else if (format === 4) {
  21271. // re-creating the table in format 4 since the encoding
  21272. // might be changed
  21273. var segCount = (font.getUint16() >> 1);
  21274. font.getBytes(6); // skipping range fields
  21275. var segIndex, segments = [];
  21276. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21277. segments.push({ end: font.getUint16() });
  21278. }
  21279. font.getUint16();
  21280. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21281. segments[segIndex].start = font.getUint16();
  21282. }
  21283. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21284. segments[segIndex].delta = font.getUint16();
  21285. }
  21286. var offsetsCount = 0;
  21287. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21288. segment = segments[segIndex];
  21289. var rangeOffset = font.getUint16();
  21290. if (!rangeOffset) {
  21291. segment.offsetIndex = -1;
  21292. continue;
  21293. }
  21294. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21295. segment.offsetIndex = offsetIndex;
  21296. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21297. segment.end - segment.start + 1);
  21298. }
  21299. var offsets = [];
  21300. for (j = 0; j < offsetsCount; j++) {
  21301. offsets.push(font.getUint16());
  21302. }
  21303. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21304. segment = segments[segIndex];
  21305. start = segment.start;
  21306. var end = segment.end;
  21307. var delta = segment.delta;
  21308. offsetIndex = segment.offsetIndex;
  21309. for (j = start; j <= end; j++) {
  21310. if (j === 0xFFFF) {
  21311. continue;
  21312. }
  21313. glyphId = (offsetIndex < 0 ?
  21314. j : offsets[offsetIndex + j - start]);
  21315. glyphId = (glyphId + delta) & 0xFFFF;
  21316. if (glyphId === 0) {
  21317. continue;
  21318. }
  21319. mappings.push({
  21320. charCode: j,
  21321. glyphId: glyphId
  21322. });
  21323. }
  21324. }
  21325. } else if (format === 6) {
  21326. // Format 6 is a 2-bytes dense mapping, which means the font data
  21327. // lives glue together even if they are pretty far in the unicode
  21328. // table. (This looks weird, so I can have missed something), this
  21329. // works on Linux but seems to fails on Mac so let's rewrite the
  21330. // cmap table to a 3-1-4 style
  21331. var firstCode = font.getUint16();
  21332. var entryCount = font.getUint16();
  21333. for (j = 0; j < entryCount; j++) {
  21334. glyphId = font.getUint16();
  21335. var charCode = firstCode + j;
  21336. mappings.push({
  21337. charCode: charCode,
  21338. glyphId: glyphId
  21339. });
  21340. }
  21341. } else {
  21342. error('cmap table has unsupported format: ' + format);
  21343. }
  21344. // removing duplicate entries
  21345. mappings.sort(function (a, b) {
  21346. return a.charCode - b.charCode;
  21347. });
  21348. for (i = 1; i < mappings.length; i++) {
  21349. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21350. mappings.splice(i, 1);
  21351. i--;
  21352. }
  21353. }
  21354. return {
  21355. platformId: potentialTable.platformId,
  21356. encodingId: potentialTable.encodingId,
  21357. mappings: mappings,
  21358. hasShortCmap: hasShortCmap
  21359. };
  21360. }
  21361. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21362. if (!header) {
  21363. if (metrics) {
  21364. metrics.data = null;
  21365. }
  21366. return;
  21367. }
  21368. font.pos = (font.start ? font.start : 0) + header.offset;
  21369. font.pos += header.length - 2;
  21370. var numOfMetrics = font.getUint16();
  21371. if (numOfMetrics > numGlyphs) {
  21372. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21373. 'greater than the numGlyphs (' + numGlyphs + ')');
  21374. // Reduce numOfMetrics if it is greater than numGlyphs
  21375. numOfMetrics = numGlyphs;
  21376. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21377. header.data[35] = numOfMetrics & 0x00ff;
  21378. }
  21379. var numOfSidebearings = numGlyphs - numOfMetrics;
  21380. var numMissing = numOfSidebearings -
  21381. ((metrics.length - numOfMetrics * 4) >> 1);
  21382. if (numMissing > 0) {
  21383. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21384. // Since we need to add two properties for each glyph, this explains
  21385. // the use of |numMissing * 2| when initializing the typed array.
  21386. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21387. entries.set(metrics.data);
  21388. metrics.data = entries;
  21389. }
  21390. }
  21391. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21392. hintsValid) {
  21393. if (sourceEnd - sourceStart <= 12) {
  21394. // glyph with data less than 12 is invalid one
  21395. return 0;
  21396. }
  21397. var glyf = source.subarray(sourceStart, sourceEnd);
  21398. var contoursCount = (glyf[0] << 8) | glyf[1];
  21399. if (contoursCount & 0x8000) {
  21400. // complex glyph, writing as is
  21401. dest.set(glyf, destStart);
  21402. return glyf.length;
  21403. }
  21404. var i, j = 10, flagsCount = 0;
  21405. for (i = 0; i < contoursCount; i++) {
  21406. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21407. flagsCount = endPoint + 1;
  21408. j += 2;
  21409. }
  21410. // skipping instructions
  21411. var instructionsStart = j;
  21412. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21413. j += 2 + instructionsLength;
  21414. var instructionsEnd = j;
  21415. // validating flags
  21416. var coordinatesLength = 0;
  21417. for (i = 0; i < flagsCount; i++) {
  21418. var flag = glyf[j++];
  21419. if (flag & 0xC0) {
  21420. // reserved flags must be zero, cleaning up
  21421. glyf[j - 1] = flag & 0x3F;
  21422. }
  21423. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21424. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21425. coordinatesLength += xyLength;
  21426. if (flag & 8) {
  21427. var repeat = glyf[j++];
  21428. i += repeat;
  21429. coordinatesLength += repeat * xyLength;
  21430. }
  21431. }
  21432. // glyph without coordinates will be rejected
  21433. if (coordinatesLength === 0) {
  21434. return 0;
  21435. }
  21436. var glyphDataLength = j + coordinatesLength;
  21437. if (glyphDataLength > glyf.length) {
  21438. // not enough data for coordinates
  21439. return 0;
  21440. }
  21441. if (!hintsValid && instructionsLength > 0) {
  21442. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21443. dest.set([0, 0], destStart + instructionsStart);
  21444. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21445. destStart + instructionsStart + 2);
  21446. glyphDataLength -= instructionsLength;
  21447. if (glyf.length - glyphDataLength > 3) {
  21448. glyphDataLength = (glyphDataLength + 3) & ~3;
  21449. }
  21450. return glyphDataLength;
  21451. }
  21452. if (glyf.length - glyphDataLength > 3) {
  21453. // truncating and aligning to 4 bytes the long glyph data
  21454. glyphDataLength = (glyphDataLength + 3) & ~3;
  21455. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21456. return glyphDataLength;
  21457. }
  21458. // glyph data is fine
  21459. dest.set(glyf, destStart);
  21460. return glyf.length;
  21461. }
  21462. function sanitizeHead(head, numGlyphs, locaLength) {
  21463. var data = head.data;
  21464. // Validate version:
  21465. // Should always be 0x00010000
  21466. var version = int32(data[0], data[1], data[2], data[3]);
  21467. if (version >> 16 !== 1) {
  21468. info('Attempting to fix invalid version in head table: ' + version);
  21469. data[0] = 0;
  21470. data[1] = 1;
  21471. data[2] = 0;
  21472. data[3] = 0;
  21473. }
  21474. var indexToLocFormat = int16(data[50], data[51]);
  21475. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21476. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21477. indexToLocFormat);
  21478. // The value of indexToLocFormat should be 0 if the loca table
  21479. // consists of short offsets, and should be 1 if the loca table
  21480. // consists of long offsets.
  21481. //
  21482. // The number of entries in the loca table should be numGlyphs + 1.
  21483. //
  21484. // Using this information, we can work backwards to deduce if the
  21485. // size of each offset in the loca table, and thus figure out the
  21486. // appropriate value for indexToLocFormat.
  21487. var numGlyphsPlusOne = numGlyphs + 1;
  21488. if (locaLength === numGlyphsPlusOne << 1) {
  21489. // 0x0000 indicates the loca table consists of short offsets
  21490. data[50] = 0;
  21491. data[51] = 0;
  21492. } else if (locaLength === numGlyphsPlusOne << 2) {
  21493. // 0x0001 indicates the loca table consists of long offsets
  21494. data[50] = 0;
  21495. data[51] = 1;
  21496. } else {
  21497. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21498. }
  21499. }
  21500. }
  21501. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21502. isGlyphLocationsLong, hintsValid,
  21503. dupFirstEntry) {
  21504. var itemSize, itemDecode, itemEncode;
  21505. if (isGlyphLocationsLong) {
  21506. itemSize = 4;
  21507. itemDecode = function fontItemDecodeLong(data, offset) {
  21508. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21509. (data[offset + 2] << 8) | data[offset + 3];
  21510. };
  21511. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21512. data[offset] = (value >>> 24) & 0xFF;
  21513. data[offset + 1] = (value >> 16) & 0xFF;
  21514. data[offset + 2] = (value >> 8) & 0xFF;
  21515. data[offset + 3] = value & 0xFF;
  21516. };
  21517. } else {
  21518. itemSize = 2;
  21519. itemDecode = function fontItemDecode(data, offset) {
  21520. return (data[offset] << 9) | (data[offset + 1] << 1);
  21521. };
  21522. itemEncode = function fontItemEncode(data, offset, value) {
  21523. data[offset] = (value >> 9) & 0xFF;
  21524. data[offset + 1] = (value >> 1) & 0xFF;
  21525. };
  21526. }
  21527. var locaData = loca.data;
  21528. var locaDataSize = itemSize * (1 + numGlyphs);
  21529. // is loca.data too short or long?
  21530. if (locaData.length !== locaDataSize) {
  21531. locaData = new Uint8Array(locaDataSize);
  21532. locaData.set(loca.data.subarray(0, locaDataSize));
  21533. loca.data = locaData;
  21534. }
  21535. // removing the invalid glyphs
  21536. var oldGlyfData = glyf.data;
  21537. var oldGlyfDataLength = oldGlyfData.length;
  21538. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21539. var startOffset = itemDecode(locaData, 0);
  21540. var writeOffset = 0;
  21541. itemEncode(locaData, 0, writeOffset);
  21542. var i, j;
  21543. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21544. var endOffset = itemDecode(locaData, j);
  21545. if (endOffset > oldGlyfDataLength &&
  21546. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21547. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21548. // the glyf table size, which makes last glyph out of range.
  21549. endOffset = oldGlyfDataLength;
  21550. }
  21551. if (endOffset > oldGlyfDataLength) {
  21552. // glyph end offset points outside glyf data, rejecting the glyph
  21553. itemEncode(locaData, j, writeOffset);
  21554. startOffset = endOffset;
  21555. continue;
  21556. }
  21557. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21558. newGlyfData, writeOffset, hintsValid);
  21559. writeOffset += newLength;
  21560. itemEncode(locaData, j, writeOffset);
  21561. startOffset = endOffset;
  21562. }
  21563. if (writeOffset === 0) {
  21564. // glyf table cannot be empty -- redoing the glyf and loca tables
  21565. // to have single glyph with one point
  21566. var simpleGlyph = new Uint8Array(
  21567. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21568. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21569. itemEncode(locaData, j, simpleGlyph.length);
  21570. }
  21571. glyf.data = simpleGlyph;
  21572. return;
  21573. }
  21574. if (dupFirstEntry) {
  21575. var firstEntryLength = itemDecode(locaData, itemSize);
  21576. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21577. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21578. } else {
  21579. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21580. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21581. }
  21582. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21583. itemEncode(loca.data, locaData.length - itemSize,
  21584. writeOffset + firstEntryLength);
  21585. } else {
  21586. glyf.data = newGlyfData.subarray(0, writeOffset);
  21587. }
  21588. }
  21589. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21590. var start = (font.start ? font.start : 0) + post.offset;
  21591. font.pos = start;
  21592. var length = post.length, end = start + length;
  21593. var version = font.getInt32();
  21594. // skip rest to the tables
  21595. font.getBytes(28);
  21596. var glyphNames;
  21597. var valid = true;
  21598. var i;
  21599. switch (version) {
  21600. case 0x00010000:
  21601. glyphNames = MacStandardGlyphOrdering;
  21602. break;
  21603. case 0x00020000:
  21604. var numGlyphs = font.getUint16();
  21605. if (numGlyphs !== maxpNumGlyphs) {
  21606. valid = false;
  21607. break;
  21608. }
  21609. var glyphNameIndexes = [];
  21610. for (i = 0; i < numGlyphs; ++i) {
  21611. var index = font.getUint16();
  21612. if (index >= 32768) {
  21613. valid = false;
  21614. break;
  21615. }
  21616. glyphNameIndexes.push(index);
  21617. }
  21618. if (!valid) {
  21619. break;
  21620. }
  21621. var customNames = [];
  21622. var strBuf = [];
  21623. while (font.pos < end) {
  21624. var stringLength = font.getByte();
  21625. strBuf.length = stringLength;
  21626. for (i = 0; i < stringLength; ++i) {
  21627. strBuf[i] = String.fromCharCode(font.getByte());
  21628. }
  21629. customNames.push(strBuf.join(''));
  21630. }
  21631. glyphNames = [];
  21632. for (i = 0; i < numGlyphs; ++i) {
  21633. var j = glyphNameIndexes[i];
  21634. if (j < 258) {
  21635. glyphNames.push(MacStandardGlyphOrdering[j]);
  21636. continue;
  21637. }
  21638. glyphNames.push(customNames[j - 258]);
  21639. }
  21640. break;
  21641. case 0x00030000:
  21642. break;
  21643. default:
  21644. warn('Unknown/unsupported post table version ' + version);
  21645. valid = false;
  21646. break;
  21647. }
  21648. properties.glyphNames = glyphNames;
  21649. return valid;
  21650. }
  21651. function readNameTable(nameTable) {
  21652. var start = (font.start ? font.start : 0) + nameTable.offset;
  21653. font.pos = start;
  21654. var names = [[], []];
  21655. var length = nameTable.length, end = start + length;
  21656. var format = font.getUint16();
  21657. var FORMAT_0_HEADER_LENGTH = 6;
  21658. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21659. // unsupported name table format or table "too" small
  21660. return names;
  21661. }
  21662. var numRecords = font.getUint16();
  21663. var stringsStart = font.getUint16();
  21664. var records = [];
  21665. var NAME_RECORD_LENGTH = 12;
  21666. var i, ii;
  21667. for (i = 0; i < numRecords &&
  21668. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21669. var r = {
  21670. platform: font.getUint16(),
  21671. encoding: font.getUint16(),
  21672. language: font.getUint16(),
  21673. name: font.getUint16(),
  21674. length: font.getUint16(),
  21675. offset: font.getUint16()
  21676. };
  21677. // using only Macintosh and Windows platform/encoding names
  21678. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21679. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21680. records.push(r);
  21681. }
  21682. }
  21683. for (i = 0, ii = records.length; i < ii; i++) {
  21684. var record = records[i];
  21685. var pos = start + stringsStart + record.offset;
  21686. if (pos + record.length > end) {
  21687. continue; // outside of name table, ignoring
  21688. }
  21689. font.pos = pos;
  21690. var nameIndex = record.name;
  21691. if (record.encoding) {
  21692. // unicode
  21693. var str = '';
  21694. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21695. str += String.fromCharCode(font.getUint16());
  21696. }
  21697. names[1][nameIndex] = str;
  21698. } else {
  21699. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21700. }
  21701. }
  21702. return names;
  21703. }
  21704. var TTOpsStackDeltas = [
  21705. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21706. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21707. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21708. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21709. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21710. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21711. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21712. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21713. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21714. // 0xC0-DF == -1 and 0xE0-FF == -2
  21715. function sanitizeTTProgram(table, ttContext) {
  21716. var data = table.data;
  21717. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21718. var stack = [];
  21719. var callstack = [];
  21720. var functionsCalled = [];
  21721. var tooComplexToFollowFunctions =
  21722. ttContext.tooComplexToFollowFunctions;
  21723. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21724. for (var ii = data.length; i < ii;) {
  21725. var op = data[i++];
  21726. // The TrueType instruction set docs can be found at
  21727. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21728. if (op === 0x40) { // NPUSHB - pushes n bytes
  21729. n = data[i++];
  21730. if (inFDEF || inELSE) {
  21731. i += n;
  21732. } else {
  21733. for (j = 0; j < n; j++) {
  21734. stack.push(data[i++]);
  21735. }
  21736. }
  21737. } else if (op === 0x41) { // NPUSHW - pushes n words
  21738. n = data[i++];
  21739. if (inFDEF || inELSE) {
  21740. i += n * 2;
  21741. } else {
  21742. for (j = 0; j < n; j++) {
  21743. b = data[i++];
  21744. stack.push((b << 8) | data[i++]);
  21745. }
  21746. }
  21747. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  21748. n = op - 0xB0 + 1;
  21749. if (inFDEF || inELSE) {
  21750. i += n;
  21751. } else {
  21752. for (j = 0; j < n; j++) {
  21753. stack.push(data[i++]);
  21754. }
  21755. }
  21756. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  21757. n = op - 0xB8 + 1;
  21758. if (inFDEF || inELSE) {
  21759. i += n * 2;
  21760. } else {
  21761. for (j = 0; j < n; j++) {
  21762. b = data[i++];
  21763. stack.push((b << 8) | data[i++]);
  21764. }
  21765. }
  21766. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  21767. if (!inFDEF && !inELSE) {
  21768. // collecting inforamtion about which functions are used
  21769. funcId = stack[stack.length - 1];
  21770. ttContext.functionsUsed[funcId] = true;
  21771. if (funcId in ttContext.functionsStackDeltas) {
  21772. stack.length += ttContext.functionsStackDeltas[funcId];
  21773. } else if (funcId in ttContext.functionsDefined &&
  21774. functionsCalled.indexOf(funcId) < 0) {
  21775. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  21776. functionsCalled.push(funcId);
  21777. pc = ttContext.functionsDefined[funcId];
  21778. if (!pc) {
  21779. warn('TT: CALL non-existent function');
  21780. ttContext.hintsValid = false;
  21781. return;
  21782. }
  21783. data = pc.data;
  21784. i = pc.i;
  21785. }
  21786. }
  21787. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  21788. if (inFDEF || inELSE) {
  21789. warn('TT: nested FDEFs not allowed');
  21790. tooComplexToFollowFunctions = true;
  21791. }
  21792. inFDEF = true;
  21793. // collecting inforamtion about which functions are defined
  21794. lastDeff = i;
  21795. funcId = stack.pop();
  21796. ttContext.functionsDefined[funcId] = {data: data, i: i};
  21797. } else if (op === 0x2D) { // ENDF - end of function
  21798. if (inFDEF) {
  21799. inFDEF = false;
  21800. lastEndf = i;
  21801. } else {
  21802. pc = callstack.pop();
  21803. if (!pc) {
  21804. warn('TT: ENDF bad stack');
  21805. ttContext.hintsValid = false;
  21806. return;
  21807. }
  21808. funcId = functionsCalled.pop();
  21809. data = pc.data;
  21810. i = pc.i;
  21811. ttContext.functionsStackDeltas[funcId] =
  21812. stack.length - pc.stackTop;
  21813. }
  21814. } else if (op === 0x89) { // IDEF - instruction definition
  21815. if (inFDEF || inELSE) {
  21816. warn('TT: nested IDEFs not allowed');
  21817. tooComplexToFollowFunctions = true;
  21818. }
  21819. inFDEF = true;
  21820. // recording it as a function to track ENDF
  21821. lastDeff = i;
  21822. } else if (op === 0x58) { // IF
  21823. ++ifLevel;
  21824. } else if (op === 0x1B) { // ELSE
  21825. inELSE = ifLevel;
  21826. } else if (op === 0x59) { // EIF
  21827. if (inELSE === ifLevel) {
  21828. inELSE = 0;
  21829. }
  21830. --ifLevel;
  21831. } else if (op === 0x1C) { // JMPR
  21832. if (!inFDEF && !inELSE) {
  21833. var offset = stack[stack.length - 1];
  21834. // only jumping forward to prevent infinite loop
  21835. if (offset > 0) {
  21836. i += offset - 1;
  21837. }
  21838. }
  21839. }
  21840. // Adjusting stack not extactly, but just enough to get function id
  21841. if (!inFDEF && !inELSE) {
  21842. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  21843. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  21844. if (op >= 0x71 && op <= 0x75) {
  21845. n = stack.pop();
  21846. if (n === n) {
  21847. stackDelta = -n * 2;
  21848. }
  21849. }
  21850. while (stackDelta < 0 && stack.length > 0) {
  21851. stack.pop();
  21852. stackDelta++;
  21853. }
  21854. while (stackDelta > 0) {
  21855. stack.push(NaN); // pushing any number into stack
  21856. stackDelta--;
  21857. }
  21858. }
  21859. }
  21860. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  21861. var content = [data];
  21862. if (i > data.length) {
  21863. content.push(new Uint8Array(i - data.length));
  21864. }
  21865. if (lastDeff > lastEndf) {
  21866. warn('TT: complementing a missing function tail');
  21867. // new function definition started, but not finished
  21868. // complete function by [CLEAR, ENDF]
  21869. content.push(new Uint8Array([0x22, 0x2D]));
  21870. }
  21871. foldTTTable(table, content);
  21872. }
  21873. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  21874. if (ttContext.tooComplexToFollowFunctions) {
  21875. return;
  21876. }
  21877. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  21878. warn('TT: more functions defined than expected');
  21879. ttContext.hintsValid = false;
  21880. return;
  21881. }
  21882. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  21883. if (j > maxFunctionDefs) {
  21884. warn('TT: invalid function id: ' + j);
  21885. ttContext.hintsValid = false;
  21886. return;
  21887. }
  21888. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  21889. warn('TT: undefined function: ' + j);
  21890. ttContext.hintsValid = false;
  21891. return;
  21892. }
  21893. }
  21894. }
  21895. function foldTTTable(table, content) {
  21896. if (content.length > 1) {
  21897. // concatenating the content items
  21898. var newLength = 0;
  21899. var j, jj;
  21900. for (j = 0, jj = content.length; j < jj; j++) {
  21901. newLength += content[j].length;
  21902. }
  21903. newLength = (newLength + 3) & ~3;
  21904. var result = new Uint8Array(newLength);
  21905. var pos = 0;
  21906. for (j = 0, jj = content.length; j < jj; j++) {
  21907. result.set(content[j], pos);
  21908. pos += content[j].length;
  21909. }
  21910. table.data = result;
  21911. table.length = newLength;
  21912. }
  21913. }
  21914. function sanitizeTTPrograms(fpgm, prep, cvt) {
  21915. var ttContext = {
  21916. functionsDefined: [],
  21917. functionsUsed: [],
  21918. functionsStackDeltas: [],
  21919. tooComplexToFollowFunctions: false,
  21920. hintsValid: true
  21921. };
  21922. if (fpgm) {
  21923. sanitizeTTProgram(fpgm, ttContext);
  21924. }
  21925. if (prep) {
  21926. sanitizeTTProgram(prep, ttContext);
  21927. }
  21928. if (fpgm) {
  21929. checkInvalidFunctions(ttContext, maxFunctionDefs);
  21930. }
  21931. if (cvt && (cvt.length & 1)) {
  21932. var cvtData = new Uint8Array(cvt.length + 1);
  21933. cvtData.set(cvt.data);
  21934. cvt.data = cvtData;
  21935. }
  21936. return ttContext.hintsValid;
  21937. }
  21938. // The following steps modify the original font data, making copy
  21939. font = new Stream(new Uint8Array(font.getBytes()));
  21940. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  21941. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  21942. var header = readOpenTypeHeader(font);
  21943. var numTables = header.numTables;
  21944. var cff, cffFile;
  21945. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  21946. hmtx: null, maxp: null, name: null, post: null };
  21947. var table;
  21948. for (var i = 0; i < numTables; i++) {
  21949. table = readTableEntry(font);
  21950. if (VALID_TABLES.indexOf(table.tag) < 0) {
  21951. continue; // skipping table if it's not a required or optional table
  21952. }
  21953. if (table.length === 0) {
  21954. continue; // skipping empty tables
  21955. }
  21956. tables[table.tag] = table;
  21957. }
  21958. var isTrueType = !tables['CFF '];
  21959. if (!isTrueType) {
  21960. // OpenType font
  21961. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  21962. // no major tables: throwing everything at CFFFont
  21963. cffFile = new Stream(tables['CFF '].data);
  21964. cff = new CFFFont(cffFile, properties);
  21965. return this.convert(name, cff, properties);
  21966. }
  21967. delete tables.glyf;
  21968. delete tables.loca;
  21969. delete tables.fpgm;
  21970. delete tables.prep;
  21971. delete tables['cvt '];
  21972. this.isOpenType = true;
  21973. } else {
  21974. if (!tables.glyf || !tables.loca) {
  21975. error('Required "glyf" or "loca" tables are not found');
  21976. }
  21977. this.isOpenType = false;
  21978. }
  21979. if (!tables.maxp) {
  21980. error('Required "maxp" table is not found');
  21981. }
  21982. font.pos = (font.start || 0) + tables.maxp.offset;
  21983. var version = font.getInt32();
  21984. var numGlyphs = font.getUint16();
  21985. var maxFunctionDefs = 0;
  21986. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  21987. // maxZones can be invalid
  21988. font.pos += 8;
  21989. var maxZones = font.getUint16();
  21990. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  21991. tables.maxp.data[14] = 0;
  21992. tables.maxp.data[15] = 2;
  21993. }
  21994. font.pos += 4;
  21995. maxFunctionDefs = font.getUint16();
  21996. }
  21997. var dupFirstEntry = false;
  21998. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  21999. properties.toUnicode.get(0) > '\u0000') {
  22000. // oracle's defect (see 3427), duplicating first entry
  22001. dupFirstEntry = true;
  22002. numGlyphs++;
  22003. tables.maxp.data[4] = numGlyphs >> 8;
  22004. tables.maxp.data[5] = numGlyphs & 255;
  22005. }
  22006. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22007. tables['cvt '], maxFunctionDefs);
  22008. if (!hintsValid) {
  22009. delete tables.fpgm;
  22010. delete tables.prep;
  22011. delete tables['cvt '];
  22012. }
  22013. // Ensure the hmtx table contains the advance width and
  22014. // sidebearings information for numGlyphs in the maxp table
  22015. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22016. if (!tables.head) {
  22017. error('Required "head" table is not found');
  22018. }
  22019. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22020. if (isTrueType) {
  22021. var isGlyphLocationsLong = int16(tables.head.data[50],
  22022. tables.head.data[51]);
  22023. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  22024. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  22025. }
  22026. if (!tables.hhea) {
  22027. error('Required "hhea" table is not found');
  22028. }
  22029. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22030. // Sometimes it's 0. That needs to be fixed
  22031. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22032. tables.hhea.data[10] = 0xFF;
  22033. tables.hhea.data[11] = 0xFF;
  22034. }
  22035. // The 'post' table has glyphs names.
  22036. if (tables.post) {
  22037. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22038. if (!valid) {
  22039. tables.post = null;
  22040. }
  22041. }
  22042. var charCodeToGlyphId = [], charCode;
  22043. if (properties.type === 'CIDFontType2') {
  22044. var cidToGidMap = properties.cidToGidMap || [];
  22045. var cidToGidMapLength = cidToGidMap.length;
  22046. properties.cMap.forEach(function(charCode, cid) {
  22047. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22048. var glyphId = -1;
  22049. if (cidToGidMapLength === 0) {
  22050. glyphId = charCode;
  22051. } else if (cidToGidMap[cid] !== undefined) {
  22052. glyphId = cidToGidMap[cid];
  22053. }
  22054. if (glyphId >= 0 && glyphId < numGlyphs) {
  22055. charCodeToGlyphId[charCode] = glyphId;
  22056. }
  22057. });
  22058. if (dupFirstEntry) {
  22059. charCodeToGlyphId[0] = numGlyphs - 1;
  22060. }
  22061. } else {
  22062. // Most of the following logic in this code branch is based on the
  22063. // 9.6.6.4 of the PDF spec.
  22064. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22065. var cmapPlatformId = cmapTable.platformId;
  22066. var cmapEncodingId = cmapTable.encodingId;
  22067. var cmapMappings = cmapTable.mappings;
  22068. var cmapMappingsLength = cmapMappings.length;
  22069. var hasEncoding = properties.differences.length ||
  22070. !!properties.baseEncodingName;
  22071. // The spec seems to imply that if the font is symbolic the encoding
  22072. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22073. // where the the font is symbolic and it has an encoding.
  22074. if (hasEncoding &&
  22075. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22076. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22077. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22078. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22079. // When no preferred cmap table was found and |baseEncodingName| is
  22080. // one of the predefined encodings, we seem to obtain a better
  22081. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22082. // TODO: Note that this is a hack which should be removed as soon as
  22083. // we have proper support for more exotic cmap tables.
  22084. var baseEncoding = [];
  22085. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22086. properties.baseEncodingName === 'WinAnsiEncoding') {
  22087. baseEncoding = Encodings[properties.baseEncodingName];
  22088. }
  22089. for (charCode = 0; charCode < 256; charCode++) {
  22090. var glyphName;
  22091. if (this.differences && charCode in this.differences) {
  22092. glyphName = this.differences[charCode];
  22093. } else if (charCode in baseEncoding &&
  22094. baseEncoding[charCode] !== '') {
  22095. glyphName = baseEncoding[charCode];
  22096. } else {
  22097. glyphName = Encodings.StandardEncoding[charCode];
  22098. }
  22099. if (!glyphName) {
  22100. continue;
  22101. }
  22102. var unicodeOrCharCode;
  22103. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22104. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22105. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22106. // TODO: the encoding needs to be updated with mac os table.
  22107. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22108. }
  22109. var found = false;
  22110. for (i = 0; i < cmapMappingsLength; ++i) {
  22111. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  22112. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22113. found = true;
  22114. break;
  22115. }
  22116. }
  22117. if (!found && properties.glyphNames) {
  22118. // Try to map using the post table. There are currently no known
  22119. // pdfs that this fixes.
  22120. var glyphId = properties.glyphNames.indexOf(glyphName);
  22121. if (glyphId > 0) {
  22122. charCodeToGlyphId[charCode] = glyphId;
  22123. }
  22124. }
  22125. }
  22126. } else {
  22127. // For (3, 0) cmap tables:
  22128. // The charcode key being stored in charCodeToGlyphId is the lower
  22129. // byte of the two-byte charcodes of the cmap table since according to
  22130. // the spec: 'each byte from the string shall be prepended with the
  22131. // high byte of the range [of charcodes in the cmap table], to form
  22132. // a two-byte character, which shall be used to select the
  22133. // associated glyph description from the subtable'.
  22134. //
  22135. // For (1, 0) cmap tables:
  22136. // 'single bytes from the string shall be used to look up the
  22137. // associated glyph descriptions from the subtable'. This means
  22138. // charcodes in the cmap will be single bytes, so no-op since
  22139. // glyph.charCode & 0xFF === glyph.charCode
  22140. for (i = 0; i < cmapMappingsLength; ++i) {
  22141. charCode = cmapMappings[i].charCode & 0xFF;
  22142. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22143. }
  22144. }
  22145. }
  22146. if (charCodeToGlyphId.length === 0) {
  22147. // defines at least one glyph
  22148. charCodeToGlyphId[0] = 0;
  22149. }
  22150. // Converting glyphs and ids into font's cmap table
  22151. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22152. this.toFontChar = newMapping.toFontChar;
  22153. tables.cmap = {
  22154. tag: 'cmap',
  22155. data: createCmapTable(newMapping.charCodeToGlyphId)
  22156. };
  22157. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22158. // extract some more font properties from the OpenType head and
  22159. // hhea tables; yMin and descent value are always negative
  22160. var override = {
  22161. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22162. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22163. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22164. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22165. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22166. };
  22167. tables['OS/2'] = {
  22168. tag: 'OS/2',
  22169. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22170. override)
  22171. };
  22172. }
  22173. // Rewrite the 'post' table if needed
  22174. if (!tables.post) {
  22175. tables.post = {
  22176. tag: 'post',
  22177. data: createPostTable(properties)
  22178. };
  22179. }
  22180. if (!isTrueType) {
  22181. try {
  22182. // Trying to repair CFF file
  22183. cffFile = new Stream(tables['CFF '].data);
  22184. var parser = new CFFParser(cffFile, properties);
  22185. cff = parser.parse();
  22186. var compiler = new CFFCompiler(cff);
  22187. tables['CFF '].data = compiler.compile();
  22188. } catch (e) {
  22189. warn('Failed to compile font ' + properties.loadedName);
  22190. }
  22191. }
  22192. // Re-creating 'name' table
  22193. if (!tables.name) {
  22194. tables.name = {
  22195. tag: 'name',
  22196. data: createNameTable(this.name)
  22197. };
  22198. } else {
  22199. // ... using existing 'name' table as prototype
  22200. var namePrototype = readNameTable(tables.name);
  22201. tables.name.data = createNameTable(name, namePrototype);
  22202. }
  22203. var builder = new OpenTypeFileBuilder(header.version);
  22204. for (var tableTag in tables) {
  22205. builder.addTable(tableTag, tables[tableTag].data);
  22206. }
  22207. return builder.toArray();
  22208. },
  22209. convert: function Font_convert(fontName, font, properties) {
  22210. // TODO: Check the charstring widths to determine this.
  22211. properties.fixedPitch = false;
  22212. var mapping = font.getGlyphMapping(properties);
  22213. var newMapping = adjustMapping(mapping, properties);
  22214. this.toFontChar = newMapping.toFontChar;
  22215. var numGlyphs = font.numGlyphs;
  22216. function getCharCodes(charCodeToGlyphId, glyphId) {
  22217. var charCodes = null;
  22218. for (var charCode in charCodeToGlyphId) {
  22219. if (glyphId === charCodeToGlyphId[charCode]) {
  22220. if (!charCodes) {
  22221. charCodes = [];
  22222. }
  22223. charCodes.push(charCode | 0);
  22224. }
  22225. }
  22226. return charCodes;
  22227. }
  22228. function createCharCode(charCodeToGlyphId, glyphId) {
  22229. for (var charCode in charCodeToGlyphId) {
  22230. if (glyphId === charCodeToGlyphId[charCode]) {
  22231. return charCode | 0;
  22232. }
  22233. }
  22234. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22235. glyphId;
  22236. return newMapping.nextAvailableFontCharCode++;
  22237. }
  22238. var seacs = font.seacs;
  22239. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22240. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22241. var charset = font.getCharset();
  22242. var seacMap = Object.create(null);
  22243. for (var glyphId in seacs) {
  22244. glyphId |= 0;
  22245. var seac = seacs[glyphId];
  22246. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22247. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22248. var baseGlyphId = charset.indexOf(baseGlyphName);
  22249. var accentGlyphId = charset.indexOf(accentGlyphName);
  22250. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22251. continue;
  22252. }
  22253. var accentOffset = {
  22254. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22255. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22256. };
  22257. var charCodes = getCharCodes(mapping, glyphId);
  22258. if (!charCodes) {
  22259. // There's no point in mapping it if the char code was never mapped
  22260. // to begin with.
  22261. continue;
  22262. }
  22263. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22264. var charCode = charCodes[i];
  22265. // Find a fontCharCode that maps to the base and accent glyphs.
  22266. // If one doesn't exists, create it.
  22267. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22268. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22269. baseGlyphId);
  22270. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22271. accentGlyphId);
  22272. seacMap[charCode] = {
  22273. baseFontCharCode: baseFontCharCode,
  22274. accentFontCharCode: accentFontCharCode,
  22275. accentOffset: accentOffset
  22276. };
  22277. }
  22278. }
  22279. properties.seacMap = seacMap;
  22280. }
  22281. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22282. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22283. // PostScript Font Program
  22284. builder.addTable('CFF ', font.data);
  22285. // OS/2 and Windows Specific metrics
  22286. builder.addTable('OS/2', createOS2Table(properties,
  22287. newMapping.charCodeToGlyphId));
  22288. // Character to glyphs mapping
  22289. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22290. // Font header
  22291. builder.addTable('head',
  22292. '\x00\x01\x00\x00' + // Version number
  22293. '\x00\x00\x10\x00' + // fontRevision
  22294. '\x00\x00\x00\x00' + // checksumAdjustement
  22295. '\x5F\x0F\x3C\xF5' + // magicNumber
  22296. '\x00\x00' + // Flags
  22297. safeString16(unitsPerEm) + // unitsPerEM
  22298. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22299. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22300. '\x00\x00' + // xMin
  22301. safeString16(properties.descent) + // yMin
  22302. '\x0F\xFF' + // xMax
  22303. safeString16(properties.ascent) + // yMax
  22304. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22305. '\x00\x11' + // lowestRecPPEM
  22306. '\x00\x00' + // fontDirectionHint
  22307. '\x00\x00' + // indexToLocFormat
  22308. '\x00\x00'); // glyphDataFormat
  22309. // Horizontal header
  22310. builder.addTable('hhea',
  22311. '\x00\x01\x00\x00' + // Version number
  22312. safeString16(properties.ascent) + // Typographic Ascent
  22313. safeString16(properties.descent) + // Typographic Descent
  22314. '\x00\x00' + // Line Gap
  22315. '\xFF\xFF' + // advanceWidthMax
  22316. '\x00\x00' + // minLeftSidebearing
  22317. '\x00\x00' + // minRightSidebearing
  22318. '\x00\x00' + // xMaxExtent
  22319. safeString16(properties.capHeight) + // caretSlopeRise
  22320. safeString16(Math.tan(properties.italicAngle) *
  22321. properties.xHeight) + // caretSlopeRun
  22322. '\x00\x00' + // caretOffset
  22323. '\x00\x00' + // -reserved-
  22324. '\x00\x00' + // -reserved-
  22325. '\x00\x00' + // -reserved-
  22326. '\x00\x00' + // -reserved-
  22327. '\x00\x00' + // metricDataFormat
  22328. string16(numGlyphs)); // Number of HMetrics
  22329. // Horizontal metrics
  22330. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22331. var charstrings = font.charstrings;
  22332. var cffWidths = font.cff ? font.cff.widths : null;
  22333. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22334. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22335. var width = 0;
  22336. if (charstrings) {
  22337. var charstring = charstrings[i - 1];
  22338. width = 'width' in charstring ? charstring.width : 0;
  22339. } else if (cffWidths) {
  22340. width = Math.ceil(cffWidths[i] || 0);
  22341. }
  22342. hmtx += string16(width) + string16(0);
  22343. }
  22344. return hmtx;
  22345. })());
  22346. // Maximum profile
  22347. builder.addTable('maxp',
  22348. '\x00\x00\x50\x00' + // Version number
  22349. string16(numGlyphs)); // Num of glyphs
  22350. // Naming tables
  22351. builder.addTable('name', createNameTable(fontName));
  22352. // PostScript informations
  22353. builder.addTable('post', createPostTable(properties));
  22354. return builder.toArray();
  22355. },
  22356. /**
  22357. * Builds a char code to unicode map based on section 9.10 of the spec.
  22358. * @param {Object} properties Font properties object.
  22359. * @return {Object} A ToUnicodeMap object.
  22360. */
  22361. buildToUnicode: function Font_buildToUnicode(properties) {
  22362. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22363. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22364. return properties.toUnicode;
  22365. }
  22366. // According to the spec if the font is a simple font we should only map
  22367. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22368. // the differences array only contains adobe standard or symbol set names,
  22369. // in pratice it seems better to always try to create a toUnicode
  22370. // map based of the default encoding.
  22371. var toUnicode, charcode;
  22372. if (!properties.composite /* is simple font */) {
  22373. toUnicode = [];
  22374. var encoding = properties.defaultEncoding.slice();
  22375. var baseEncodingName = properties.baseEncodingName;
  22376. // Merge in the differences array.
  22377. var differences = properties.differences;
  22378. for (charcode in differences) {
  22379. encoding[charcode] = differences[charcode];
  22380. }
  22381. for (charcode in encoding) {
  22382. // a) Map the character code to a character name.
  22383. var glyphName = encoding[charcode];
  22384. // b) Look up the character name in the Adobe Glyph List (see the
  22385. // Bibliography) to obtain the corresponding Unicode value.
  22386. if (glyphName === '') {
  22387. continue;
  22388. } else if (GlyphsUnicode[glyphName] === undefined) {
  22389. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22390. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22391. var code = 0;
  22392. switch (glyphName[0]) {
  22393. case 'G': // Gxx glyph
  22394. if (glyphName.length === 3) {
  22395. code = parseInt(glyphName.substr(1), 16);
  22396. }
  22397. break;
  22398. case 'g': // g00xx glyph
  22399. if (glyphName.length === 5) {
  22400. code = parseInt(glyphName.substr(1), 16);
  22401. }
  22402. break;
  22403. case 'C': // Cddd glyph
  22404. case 'c': // cddd glyph
  22405. if (glyphName.length >= 3) {
  22406. code = +glyphName.substr(1);
  22407. }
  22408. break;
  22409. }
  22410. if (code) {
  22411. // If |baseEncodingName| is one the predefined encodings,
  22412. // and |code| equals |charcode|, using the glyph defined in the
  22413. // baseEncoding seems to yield a better |toUnicode| mapping
  22414. // (fixes issue 5070).
  22415. if (baseEncodingName && code === +charcode) {
  22416. var baseEncoding = Encodings[baseEncodingName];
  22417. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22418. toUnicode[charcode] =
  22419. String.fromCharCode(GlyphsUnicode[glyphName]);
  22420. continue;
  22421. }
  22422. }
  22423. toUnicode[charcode] = String.fromCharCode(code);
  22424. }
  22425. continue;
  22426. }
  22427. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22428. }
  22429. return new ToUnicodeMap(toUnicode);
  22430. }
  22431. // If the font is a composite font that uses one of the predefined CMaps
  22432. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22433. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22434. // Adobe-Korea1 character collection:
  22435. if (properties.composite && (
  22436. (properties.cMap.builtInCMap &&
  22437. !(properties.cMap instanceof IdentityCMap)) ||
  22438. (properties.cidSystemInfo.registry === 'Adobe' &&
  22439. (properties.cidSystemInfo.ordering === 'GB1' ||
  22440. properties.cidSystemInfo.ordering === 'CNS1' ||
  22441. properties.cidSystemInfo.ordering === 'Japan1' ||
  22442. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22443. // Then:
  22444. // a) Map the character code to a character identifier (CID) according
  22445. // to the font’s CMap.
  22446. // b) Obtain the registry and ordering of the character collection used
  22447. // by the font’s CMap (for example, Adobe and Japan1) from its
  22448. // CIDSystemInfo dictionary.
  22449. var registry = properties.cidSystemInfo.registry;
  22450. var ordering = properties.cidSystemInfo.ordering;
  22451. // c) Construct a second CMap name by concatenating the registry and
  22452. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22453. // (for example, Adobe–Japan1–UCS2).
  22454. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22455. // d) Obtain the CMap with the name constructed in step (c) (available
  22456. // from the ASN Web site; see the Bibliography).
  22457. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22458. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22459. var cMap = properties.cMap;
  22460. toUnicode = [];
  22461. cMap.forEach(function(charcode, cid) {
  22462. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22463. // e) Map the CID obtained in step (a) according to the CMap obtained
  22464. // in step (d), producing a Unicode value.
  22465. var ucs2 = ucs2CMap.lookup(cid);
  22466. if (ucs2) {
  22467. toUnicode[charcode] =
  22468. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22469. ucs2.charCodeAt(1));
  22470. }
  22471. });
  22472. return new ToUnicodeMap(toUnicode);
  22473. }
  22474. // The viewer's choice, just use an identity map.
  22475. return new IdentityToUnicodeMap(properties.firstChar,
  22476. properties.lastChar);
  22477. },
  22478. get spaceWidth() {
  22479. if ('_shadowWidth' in this) {
  22480. return this._shadowWidth;
  22481. }
  22482. // trying to estimate space character width
  22483. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22484. var width;
  22485. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22486. var glyphName = possibleSpaceReplacements[i];
  22487. // if possible, getting width by glyph name
  22488. if (glyphName in this.widths) {
  22489. width = this.widths[glyphName];
  22490. break;
  22491. }
  22492. var glyphUnicode = GlyphsUnicode[glyphName];
  22493. // finding the charcode via unicodeToCID map
  22494. var charcode = 0;
  22495. if (this.composite) {
  22496. if (this.cMap.contains(glyphUnicode)) {
  22497. charcode = this.cMap.lookup(glyphUnicode);
  22498. }
  22499. }
  22500. // ... via toUnicode map
  22501. if (!charcode && 'toUnicode' in this) {
  22502. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22503. }
  22504. // setting it to unicode if negative or undefined
  22505. if (charcode <= 0) {
  22506. charcode = glyphUnicode;
  22507. }
  22508. // trying to get width via charcode
  22509. width = this.widths[charcode];
  22510. if (width) {
  22511. break; // the non-zero width found
  22512. }
  22513. }
  22514. width = width || this.defaultWidth;
  22515. // Do not shadow the property here. See discussion:
  22516. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22517. this._shadowWidth = width;
  22518. return width;
  22519. },
  22520. charToGlyph: function Font_charToGlyph(charcode) {
  22521. var fontCharCode, width, operatorListId;
  22522. var widthCode = charcode;
  22523. if (this.cMap && this.cMap.contains(charcode)) {
  22524. widthCode = this.cMap.lookup(charcode);
  22525. }
  22526. width = this.widths[widthCode];
  22527. width = isNum(width) ? width : this.defaultWidth;
  22528. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22529. var unicode = this.toUnicode.get(charcode) || charcode;
  22530. if (typeof unicode === 'number') {
  22531. unicode = String.fromCharCode(unicode);
  22532. }
  22533. // First try the toFontChar map, if it's not there then try falling
  22534. // back to the char code.
  22535. fontCharCode = this.toFontChar[charcode] || charcode;
  22536. if (this.missingFile) {
  22537. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22538. }
  22539. if (this.isType3Font) {
  22540. // Font char code in this case is actually a glyph name.
  22541. operatorListId = fontCharCode;
  22542. }
  22543. var accent = null;
  22544. if (this.seacMap && this.seacMap[charcode]) {
  22545. var seac = this.seacMap[charcode];
  22546. fontCharCode = seac.baseFontCharCode;
  22547. accent = {
  22548. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22549. offset: seac.accentOffset
  22550. };
  22551. }
  22552. var fontChar = String.fromCharCode(fontCharCode);
  22553. var glyph = this.glyphCache[charcode];
  22554. if (!glyph ||
  22555. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22556. operatorListId)) {
  22557. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22558. operatorListId);
  22559. this.glyphCache[charcode] = glyph;
  22560. }
  22561. return glyph;
  22562. },
  22563. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22564. var charsCache = this.charsCache;
  22565. var glyphs, glyph, charcode;
  22566. // if we translated this string before, just grab it from the cache
  22567. if (charsCache) {
  22568. glyphs = charsCache[chars];
  22569. if (glyphs) {
  22570. return glyphs;
  22571. }
  22572. }
  22573. // lazily create the translation cache
  22574. if (!charsCache) {
  22575. charsCache = this.charsCache = Object.create(null);
  22576. }
  22577. glyphs = [];
  22578. var charsCacheKey = chars;
  22579. var i = 0, ii;
  22580. if (this.cMap) {
  22581. // composite fonts have multi-byte strings convert the string from
  22582. // single-byte to multi-byte
  22583. var c = {};
  22584. while (i < chars.length) {
  22585. this.cMap.readCharCode(chars, i, c);
  22586. charcode = c.charcode;
  22587. var length = c.length;
  22588. i += length;
  22589. glyph = this.charToGlyph(charcode);
  22590. glyphs.push(glyph);
  22591. // placing null after each word break charcode (ASCII SPACE)
  22592. // Ignore occurences of 0x20 in multiple-byte codes.
  22593. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22594. glyphs.push(null);
  22595. }
  22596. }
  22597. } else {
  22598. for (i = 0, ii = chars.length; i < ii; ++i) {
  22599. charcode = chars.charCodeAt(i);
  22600. glyph = this.charToGlyph(charcode);
  22601. glyphs.push(glyph);
  22602. if (charcode === 0x20) {
  22603. glyphs.push(null);
  22604. }
  22605. }
  22606. }
  22607. // Enter the translated string into the cache
  22608. return (charsCache[charsCacheKey] = glyphs);
  22609. }
  22610. };
  22611. return Font;
  22612. })();
  22613. var ErrorFont = (function ErrorFontClosure() {
  22614. function ErrorFont(error) {
  22615. this.error = error;
  22616. this.loadedName = 'g_font_error';
  22617. this.loading = false;
  22618. }
  22619. ErrorFont.prototype = {
  22620. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22621. return [];
  22622. },
  22623. exportData: function ErrorFont_exportData() {
  22624. return {error: this.error};
  22625. }
  22626. };
  22627. return ErrorFont;
  22628. })();
  22629. /**
  22630. * Shared logic for building a char code to glyph id mapping for Type1 and
  22631. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22632. * @param {Object} properties Font properties object.
  22633. * @param {Object} builtInEncoding The encoding contained within the actual font
  22634. * data.
  22635. * @param {Array} Array of glyph names where the index is the glyph ID.
  22636. * @returns {Object} A char code to glyph ID map.
  22637. */
  22638. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22639. var charCodeToGlyphId = Object.create(null);
  22640. var glyphId, charCode, baseEncoding;
  22641. if (properties.baseEncodingName) {
  22642. // If a valid base encoding name was used, the mapping is initialized with
  22643. // that.
  22644. baseEncoding = Encodings[properties.baseEncodingName];
  22645. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22646. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22647. if (glyphId >= 0) {
  22648. charCodeToGlyphId[charCode] = glyphId;
  22649. }
  22650. }
  22651. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22652. // For a symbolic font the encoding should be the fonts built-in
  22653. // encoding.
  22654. for (charCode in builtInEncoding) {
  22655. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22656. }
  22657. } else {
  22658. // For non-symbolic fonts that don't have a base encoding the standard
  22659. // encoding should be used.
  22660. baseEncoding = Encodings.StandardEncoding;
  22661. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22662. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22663. if (glyphId >= 0) {
  22664. charCodeToGlyphId[charCode] = glyphId;
  22665. }
  22666. }
  22667. }
  22668. // Lastly, merge in the differences.
  22669. var differences = properties.differences;
  22670. if (differences) {
  22671. for (charCode in differences) {
  22672. var glyphName = differences[charCode];
  22673. glyphId = glyphNames.indexOf(glyphName);
  22674. if (glyphId >= 0) {
  22675. charCodeToGlyphId[charCode] = glyphId;
  22676. }
  22677. }
  22678. }
  22679. return charCodeToGlyphId;
  22680. }
  22681. /*
  22682. * CharStrings are encoded following the the CharString Encoding sequence
  22683. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22684. * The value in a byte indicates a command, a number, or subsequent bytes
  22685. * that are to be interpreted in a special way.
  22686. *
  22687. * CharString Number Encoding:
  22688. * A CharString byte containing the values from 32 through 255 inclusive
  22689. * indicate an integer. These values are decoded in four ranges.
  22690. *
  22691. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22692. * indicate the integer v - 139. Thus, the integer values from -107 through
  22693. * 107 inclusive may be encoded in single byte.
  22694. *
  22695. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22696. * indicates an integer involving the next byte, w, according to the formula:
  22697. * [(v - 247) x 256] + w + 108
  22698. *
  22699. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22700. * indicates an integer involving the next byte, w, according to the formula:
  22701. * -[(v - 251) * 256] - w - 108
  22702. *
  22703. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22704. * are a two complement signed integer. The first of these bytes contains the
  22705. * highest order bits, the second byte contains the next higher order bits
  22706. * and the fourth byte contain the lowest order bits.
  22707. *
  22708. *
  22709. * CharString Command Encoding:
  22710. * CharStrings commands are encoded in 1 or 2 bytes.
  22711. *
  22712. * Single byte commands are encoded in 1 byte that contains a value between
  22713. * 0 and 31 inclusive.
  22714. * If a command byte contains the value 12, then the value in the next byte
  22715. * indicates a command. This "escape" mechanism allows many extra commands
  22716. * to be encoded and this encoding technique helps to minimize the length of
  22717. * the charStrings.
  22718. */
  22719. var Type1CharString = (function Type1CharStringClosure() {
  22720. var COMMAND_MAP = {
  22721. 'hstem': [1],
  22722. 'vstem': [3],
  22723. 'vmoveto': [4],
  22724. 'rlineto': [5],
  22725. 'hlineto': [6],
  22726. 'vlineto': [7],
  22727. 'rrcurveto': [8],
  22728. 'callsubr': [10],
  22729. 'flex': [12, 35],
  22730. 'drop' : [12, 18],
  22731. 'endchar': [14],
  22732. 'rmoveto': [21],
  22733. 'hmoveto': [22],
  22734. 'vhcurveto': [30],
  22735. 'hvcurveto': [31]
  22736. };
  22737. function Type1CharString() {
  22738. this.width = 0;
  22739. this.lsb = 0;
  22740. this.flexing = false;
  22741. this.output = [];
  22742. this.stack = [];
  22743. }
  22744. Type1CharString.prototype = {
  22745. convert: function Type1CharString_convert(encoded, subrs) {
  22746. var count = encoded.length;
  22747. var error = false;
  22748. var wx, sbx, subrNumber;
  22749. for (var i = 0; i < count; i++) {
  22750. var value = encoded[i];
  22751. if (value < 32) {
  22752. if (value === 12) {
  22753. value = (value << 8) + encoded[++i];
  22754. }
  22755. switch (value) {
  22756. case 1: // hstem
  22757. if (!HINTING_ENABLED) {
  22758. this.stack = [];
  22759. break;
  22760. }
  22761. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22762. break;
  22763. case 3: // vstem
  22764. if (!HINTING_ENABLED) {
  22765. this.stack = [];
  22766. break;
  22767. }
  22768. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22769. break;
  22770. case 4: // vmoveto
  22771. if (this.flexing) {
  22772. if (this.stack.length < 1) {
  22773. error = true;
  22774. break;
  22775. }
  22776. // Add the dx for flex and but also swap the values so they are
  22777. // the right order.
  22778. var dy = this.stack.pop();
  22779. this.stack.push(0, dy);
  22780. break;
  22781. }
  22782. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  22783. break;
  22784. case 5: // rlineto
  22785. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  22786. break;
  22787. case 6: // hlineto
  22788. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  22789. break;
  22790. case 7: // vlineto
  22791. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  22792. break;
  22793. case 8: // rrcurveto
  22794. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  22795. break;
  22796. case 9: // closepath
  22797. // closepath is a Type1 command that does not take argument and is
  22798. // useless in Type2 and it can simply be ignored.
  22799. this.stack = [];
  22800. break;
  22801. case 10: // callsubr
  22802. if (this.stack.length < 1) {
  22803. error = true;
  22804. break;
  22805. }
  22806. subrNumber = this.stack.pop();
  22807. error = this.convert(subrs[subrNumber], subrs);
  22808. break;
  22809. case 11: // return
  22810. return error;
  22811. case 13: // hsbw
  22812. if (this.stack.length < 2) {
  22813. error = true;
  22814. break;
  22815. }
  22816. // To convert to type2 we have to move the width value to the
  22817. // first part of the charstring and then use hmoveto with lsb.
  22818. wx = this.stack.pop();
  22819. sbx = this.stack.pop();
  22820. this.lsb = sbx;
  22821. this.width = wx;
  22822. this.stack.push(wx, sbx);
  22823. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  22824. break;
  22825. case 14: // endchar
  22826. this.output.push(COMMAND_MAP.endchar[0]);
  22827. break;
  22828. case 21: // rmoveto
  22829. if (this.flexing) {
  22830. break;
  22831. }
  22832. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  22833. break;
  22834. case 22: // hmoveto
  22835. if (this.flexing) {
  22836. // Add the dy for flex.
  22837. this.stack.push(0);
  22838. break;
  22839. }
  22840. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  22841. break;
  22842. case 30: // vhcurveto
  22843. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  22844. break;
  22845. case 31: // hvcurveto
  22846. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  22847. break;
  22848. case (12 << 8) + 0: // dotsection
  22849. // dotsection is a Type1 command to specify some hinting feature
  22850. // for dots that do not take a parameter and it can safely be
  22851. // ignored for Type2.
  22852. this.stack = [];
  22853. break;
  22854. case (12 << 8) + 1: // vstem3
  22855. if (!HINTING_ENABLED) {
  22856. this.stack = [];
  22857. break;
  22858. }
  22859. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  22860. // multiple parameters, so instead of returning [vh]stem3 take a
  22861. // shortcut and return [vhstem] instead.
  22862. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22863. break;
  22864. case (12 << 8) + 2: // hstem3
  22865. if (!HINTING_ENABLED) {
  22866. this.stack = [];
  22867. break;
  22868. }
  22869. // See vstem3.
  22870. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22871. break;
  22872. case (12 << 8) + 6: // seac
  22873. // seac is like type 2's special endchar but it doesn't use the
  22874. // first argument asb, so remove it.
  22875. if (SEAC_ANALYSIS_ENABLED) {
  22876. this.seac = this.stack.splice(-4, 4);
  22877. error = this.executeCommand(0, COMMAND_MAP.endchar);
  22878. } else {
  22879. error = this.executeCommand(4, COMMAND_MAP.endchar);
  22880. }
  22881. break;
  22882. case (12 << 8) + 7: // sbw
  22883. if (this.stack.length < 4) {
  22884. error = true;
  22885. break;
  22886. }
  22887. // To convert to type2 we have to move the width value to the
  22888. // first part of the charstring and then use rmoveto with
  22889. // (dx, dy). The height argument will not be used for vmtx and
  22890. // vhea tables reconstruction -- ignoring it.
  22891. var wy = this.stack.pop();
  22892. wx = this.stack.pop();
  22893. var sby = this.stack.pop();
  22894. sbx = this.stack.pop();
  22895. this.lsb = sbx;
  22896. this.width = wx;
  22897. this.stack.push(wx, sbx, sby);
  22898. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  22899. break;
  22900. case (12 << 8) + 12: // div
  22901. if (this.stack.length < 2) {
  22902. error = true;
  22903. break;
  22904. }
  22905. var num2 = this.stack.pop();
  22906. var num1 = this.stack.pop();
  22907. this.stack.push(num1 / num2);
  22908. break;
  22909. case (12 << 8) + 16: // callothersubr
  22910. if (this.stack.length < 2) {
  22911. error = true;
  22912. break;
  22913. }
  22914. subrNumber = this.stack.pop();
  22915. var numArgs = this.stack.pop();
  22916. if (subrNumber === 0 && numArgs === 3) {
  22917. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  22918. this.stack.push(
  22919. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  22920. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  22921. flexArgs[4], // bcp2x
  22922. flexArgs[5], // bcp2y
  22923. flexArgs[6], // p2x
  22924. flexArgs[7], // p2y
  22925. flexArgs[8], // bcp3x
  22926. flexArgs[9], // bcp3y
  22927. flexArgs[10], // bcp4x
  22928. flexArgs[11], // bcp4y
  22929. flexArgs[12], // p3x
  22930. flexArgs[13], // p3y
  22931. flexArgs[14] // flexDepth
  22932. // 15 = finalx unused by flex
  22933. // 16 = finaly unused by flex
  22934. );
  22935. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  22936. this.flexing = false;
  22937. this.stack.push(flexArgs[15], flexArgs[16]);
  22938. } else if (subrNumber === 1 && numArgs === 0) {
  22939. this.flexing = true;
  22940. }
  22941. break;
  22942. case (12 << 8) + 17: // pop
  22943. // Ignore this since it is only used with othersubr.
  22944. break;
  22945. case (12 << 8) + 33: // setcurrentpoint
  22946. // Ignore for now.
  22947. this.stack = [];
  22948. break;
  22949. default:
  22950. warn('Unknown type 1 charstring command of "' + value + '"');
  22951. break;
  22952. }
  22953. if (error) {
  22954. break;
  22955. }
  22956. continue;
  22957. } else if (value <= 246) {
  22958. value = value - 139;
  22959. } else if (value <= 250) {
  22960. value = ((value - 247) * 256) + encoded[++i] + 108;
  22961. } else if (value <= 254) {
  22962. value = -((value - 251) * 256) - encoded[++i] - 108;
  22963. } else {
  22964. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  22965. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  22966. }
  22967. this.stack.push(value);
  22968. }
  22969. return error;
  22970. },
  22971. executeCommand: function(howManyArgs, command, keepStack) {
  22972. var stackLength = this.stack.length;
  22973. if (howManyArgs > stackLength) {
  22974. return true;
  22975. }
  22976. var start = stackLength - howManyArgs;
  22977. for (var i = start; i < stackLength; i++) {
  22978. var value = this.stack[i];
  22979. if (value === (value | 0)) { // int
  22980. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  22981. } else { // fixed point
  22982. value = (65536 * value) | 0;
  22983. this.output.push(255,
  22984. (value >> 24) & 0xFF,
  22985. (value >> 16) & 0xFF,
  22986. (value >> 8) & 0xFF,
  22987. value & 0xFF);
  22988. }
  22989. }
  22990. this.output.push.apply(this.output, command);
  22991. if (keepStack) {
  22992. this.stack.splice(start, howManyArgs);
  22993. } else {
  22994. this.stack.length = 0;
  22995. }
  22996. return false;
  22997. }
  22998. };
  22999. return Type1CharString;
  23000. })();
  23001. /*
  23002. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23003. * program. Some of its logic depends on the Type2 charstrings
  23004. * structure.
  23005. * Note: this doesn't really parse the font since that would require evaluation
  23006. * of PostScript, but it is possible in most cases to extract what we need
  23007. * without a full parse.
  23008. */
  23009. var Type1Parser = (function Type1ParserClosure() {
  23010. /*
  23011. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23012. * of Plaintext Bytes. The function took a key as a parameter which can be
  23013. * for decrypting the eexec block of for decoding charStrings.
  23014. */
  23015. var EEXEC_ENCRYPT_KEY = 55665;
  23016. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23017. function isHexDigit(code) {
  23018. return code >= 48 && code <= 57 || // '0'-'9'
  23019. code >= 65 && code <= 70 || // 'A'-'F'
  23020. code >= 97 && code <= 102; // 'a'-'f'
  23021. }
  23022. function decrypt(data, key, discardNumber) {
  23023. var r = key | 0, c1 = 52845, c2 = 22719;
  23024. var count = data.length;
  23025. var decrypted = new Uint8Array(count);
  23026. for (var i = 0; i < count; i++) {
  23027. var value = data[i];
  23028. decrypted[i] = value ^ (r >> 8);
  23029. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23030. }
  23031. return Array.prototype.slice.call(decrypted, discardNumber);
  23032. }
  23033. function decryptAscii(data, key, discardNumber) {
  23034. var r = key | 0, c1 = 52845, c2 = 22719;
  23035. var count = data.length, maybeLength = count >>> 1;
  23036. var decrypted = new Uint8Array(maybeLength);
  23037. var i, j;
  23038. for (i = 0, j = 0; i < count; i++) {
  23039. var digit1 = data[i];
  23040. if (!isHexDigit(digit1)) {
  23041. continue;
  23042. }
  23043. i++;
  23044. var digit2;
  23045. while (i < count && !isHexDigit(digit2 = data[i])) {
  23046. i++;
  23047. }
  23048. if (i < count) {
  23049. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23050. decrypted[j++] = value ^ (r >> 8);
  23051. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23052. }
  23053. }
  23054. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23055. }
  23056. function isSpecial(c) {
  23057. return c === 0x2F || // '/'
  23058. c === 0x5B || c === 0x5D || // '[', ']'
  23059. c === 0x7B || c === 0x7D || // '{', '}'
  23060. c === 0x28 || c === 0x29; // '(', ')'
  23061. }
  23062. function Type1Parser(stream, encrypted) {
  23063. if (encrypted) {
  23064. var data = stream.getBytes();
  23065. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23066. isHexDigit(data[2]) && isHexDigit(data[3]));
  23067. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23068. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23069. }
  23070. this.stream = stream;
  23071. this.nextChar();
  23072. }
  23073. Type1Parser.prototype = {
  23074. readNumberArray: function Type1Parser_readNumberArray() {
  23075. this.getToken(); // read '[' or '{' (arrays can start with either)
  23076. var array = [];
  23077. while (true) {
  23078. var token = this.getToken();
  23079. if (token === null || token === ']' || token === '}') {
  23080. break;
  23081. }
  23082. array.push(parseFloat(token || 0));
  23083. }
  23084. return array;
  23085. },
  23086. readNumber: function Type1Parser_readNumber() {
  23087. var token = this.getToken();
  23088. return parseFloat(token || 0);
  23089. },
  23090. readInt: function Type1Parser_readInt() {
  23091. // Use '| 0' to prevent setting a double into length such as the double
  23092. // does not flow into the loop variable.
  23093. var token = this.getToken();
  23094. return parseInt(token || 0, 10) | 0;
  23095. },
  23096. readBoolean: function Type1Parser_readBoolean() {
  23097. var token = this.getToken();
  23098. // Use 1 and 0 since that's what type2 charstrings use.
  23099. return token === 'true' ? 1 : 0;
  23100. },
  23101. nextChar : function Type1_nextChar() {
  23102. return (this.currentChar = this.stream.getByte());
  23103. },
  23104. getToken: function Type1Parser_getToken() {
  23105. // Eat whitespace and comments.
  23106. var comment = false;
  23107. var ch = this.currentChar;
  23108. while (true) {
  23109. if (ch === -1) {
  23110. return null;
  23111. }
  23112. if (comment) {
  23113. if (ch === 0x0A || ch === 0x0D) {
  23114. comment = false;
  23115. }
  23116. } else if (ch === 0x25) { // '%'
  23117. comment = true;
  23118. } else if (!Lexer.isSpace(ch)) {
  23119. break;
  23120. }
  23121. ch = this.nextChar();
  23122. }
  23123. if (isSpecial(ch)) {
  23124. this.nextChar();
  23125. return String.fromCharCode(ch);
  23126. }
  23127. var token = '';
  23128. do {
  23129. token += String.fromCharCode(ch);
  23130. ch = this.nextChar();
  23131. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23132. return token;
  23133. },
  23134. /*
  23135. * Returns an object containing a Subrs array and a CharStrings
  23136. * array extracted from and eexec encrypted block of data
  23137. */
  23138. extractFontProgram: function Type1Parser_extractFontProgram() {
  23139. var stream = this.stream;
  23140. var subrs = [], charstrings = [];
  23141. var program = {
  23142. subrs: [],
  23143. charstrings: [],
  23144. properties: {
  23145. 'privateData': {
  23146. 'lenIV': 4
  23147. }
  23148. }
  23149. };
  23150. var token, length, data, lenIV, encoded;
  23151. while ((token = this.getToken()) !== null) {
  23152. if (token !== '/') {
  23153. continue;
  23154. }
  23155. token = this.getToken();
  23156. switch (token) {
  23157. case 'CharStrings':
  23158. // The number immediately following CharStrings must be greater or
  23159. // equal to the number of CharStrings.
  23160. this.getToken();
  23161. this.getToken(); // read in 'dict'
  23162. this.getToken(); // read in 'dup'
  23163. this.getToken(); // read in 'begin'
  23164. while(true) {
  23165. token = this.getToken();
  23166. if (token === null || token === 'end') {
  23167. break;
  23168. }
  23169. if (token !== '/') {
  23170. continue;
  23171. }
  23172. var glyph = this.getToken();
  23173. length = this.readInt();
  23174. this.getToken(); // read in 'RD' or '-|'
  23175. data = stream.makeSubStream(stream.pos, length);
  23176. lenIV = program.properties.privateData['lenIV'];
  23177. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23178. // Skip past the required space and binary data.
  23179. stream.skip(length);
  23180. this.nextChar();
  23181. token = this.getToken(); // read in 'ND' or '|-'
  23182. if (token === 'noaccess') {
  23183. this.getToken(); // read in 'def'
  23184. }
  23185. charstrings.push({
  23186. glyph: glyph,
  23187. encoded: encoded
  23188. });
  23189. }
  23190. break;
  23191. case 'Subrs':
  23192. var num = this.readInt();
  23193. this.getToken(); // read in 'array'
  23194. while ((token = this.getToken()) === 'dup') {
  23195. var index = this.readInt();
  23196. length = this.readInt();
  23197. this.getToken(); // read in 'RD' or '-|'
  23198. data = stream.makeSubStream(stream.pos, length);
  23199. lenIV = program.properties.privateData['lenIV'];
  23200. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23201. // Skip past the required space and binary data.
  23202. stream.skip(length);
  23203. this.nextChar();
  23204. token = this.getToken(); // read in 'NP' or '|'
  23205. if (token === 'noaccess') {
  23206. this.getToken(); // read in 'put'
  23207. }
  23208. subrs[index] = encoded;
  23209. }
  23210. break;
  23211. case 'BlueValues':
  23212. case 'OtherBlues':
  23213. case 'FamilyBlues':
  23214. case 'FamilyOtherBlues':
  23215. var blueArray = this.readNumberArray();
  23216. // *Blue* values may contain invalid data: disables reading of
  23217. // those values when hinting is disabled.
  23218. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23219. HINTING_ENABLED) {
  23220. program.properties.privateData[token] = blueArray;
  23221. }
  23222. break;
  23223. case 'StemSnapH':
  23224. case 'StemSnapV':
  23225. program.properties.privateData[token] = this.readNumberArray();
  23226. break;
  23227. case 'StdHW':
  23228. case 'StdVW':
  23229. program.properties.privateData[token] =
  23230. this.readNumberArray()[0];
  23231. break;
  23232. case 'BlueShift':
  23233. case 'lenIV':
  23234. case 'BlueFuzz':
  23235. case 'BlueScale':
  23236. case 'LanguageGroup':
  23237. case 'ExpansionFactor':
  23238. program.properties.privateData[token] = this.readNumber();
  23239. break;
  23240. case 'ForceBold':
  23241. program.properties.privateData[token] = this.readBoolean();
  23242. break;
  23243. }
  23244. }
  23245. for (var i = 0; i < charstrings.length; i++) {
  23246. glyph = charstrings[i].glyph;
  23247. encoded = charstrings[i].encoded;
  23248. var charString = new Type1CharString();
  23249. var error = charString.convert(encoded, subrs);
  23250. var output = charString.output;
  23251. if (error) {
  23252. // It seems when FreeType encounters an error while evaluating a glyph
  23253. // that it completely ignores the glyph so we'll mimic that behaviour
  23254. // here and put an endchar to make the validator happy.
  23255. output = [14];
  23256. }
  23257. program.charstrings.push({
  23258. glyphName: glyph,
  23259. charstring: output,
  23260. width: charString.width,
  23261. lsb: charString.lsb,
  23262. seac: charString.seac
  23263. });
  23264. }
  23265. return program;
  23266. },
  23267. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23268. var token;
  23269. while ((token = this.getToken()) !== null) {
  23270. if (token !== '/') {
  23271. continue;
  23272. }
  23273. token = this.getToken();
  23274. switch (token) {
  23275. case 'FontMatrix':
  23276. var matrix = this.readNumberArray();
  23277. properties.fontMatrix = matrix;
  23278. break;
  23279. case 'Encoding':
  23280. var encodingArg = this.getToken();
  23281. var encoding;
  23282. if (!/^\d+$/.test(encodingArg)) {
  23283. // encoding name is specified
  23284. encoding = Encodings[encodingArg];
  23285. } else {
  23286. encoding = [];
  23287. var size = parseInt(encodingArg, 10) | 0;
  23288. this.getToken(); // read in 'array'
  23289. for (var j = 0; j < size; j++) {
  23290. token = this.getToken();
  23291. // skipping till first dup or def (e.g. ignoring for statement)
  23292. while (token !== 'dup' && token !== 'def') {
  23293. token = this.getToken();
  23294. if (token === null) {
  23295. return; // invalid header
  23296. }
  23297. }
  23298. if (token === 'def') {
  23299. break; // read all array data
  23300. }
  23301. var index = this.readInt();
  23302. this.getToken(); // read in '/'
  23303. var glyph = this.getToken();
  23304. encoding[index] = glyph;
  23305. this.getToken(); // read the in 'put'
  23306. }
  23307. }
  23308. properties.builtInEncoding = encoding;
  23309. break;
  23310. case 'FontBBox':
  23311. var fontBBox = this.readNumberArray();
  23312. // adjusting ascent/descent
  23313. properties.ascent = fontBBox[3];
  23314. properties.descent = fontBBox[1];
  23315. properties.ascentScaled = true;
  23316. break;
  23317. }
  23318. }
  23319. }
  23320. };
  23321. return Type1Parser;
  23322. })();
  23323. /**
  23324. * The CFF class takes a Type1 file and wrap it into a
  23325. * 'Compact Font Format' which itself embed Type2 charstrings.
  23326. */
  23327. var CFFStandardStrings = [
  23328. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23329. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23330. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23331. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23332. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23333. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23334. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23335. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23336. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23337. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23338. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23339. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23340. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23341. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23342. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23343. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23344. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23345. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23346. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23347. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23348. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23349. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23350. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23351. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23352. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23353. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23354. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23355. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23356. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23357. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23358. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23359. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23360. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23361. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23362. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23363. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23364. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23365. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23366. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23367. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23368. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23369. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23370. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23371. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23372. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23373. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23374. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23375. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23376. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23377. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23378. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23379. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23380. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23381. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23382. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23383. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23384. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23385. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23386. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23387. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23388. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23389. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23390. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23391. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23392. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23393. ];
  23394. // Type1Font is also a CIDFontType0.
  23395. var Type1Font = function Type1Font(name, file, properties) {
  23396. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23397. // Also, length1 and length2 might be off by 6 bytes as well.
  23398. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23399. var PFB_HEADER_SIZE = 6;
  23400. var headerBlockLength = properties.length1;
  23401. var eexecBlockLength = properties.length2;
  23402. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23403. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23404. if (pfbHeaderPresent) {
  23405. file.skip(PFB_HEADER_SIZE);
  23406. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23407. (pfbHeader[3] << 8) | pfbHeader[2];
  23408. }
  23409. // Get the data block containing glyphs and subrs informations
  23410. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23411. var headerBlockParser = new Type1Parser(headerBlock);
  23412. headerBlockParser.extractFontHeader(properties);
  23413. if (pfbHeaderPresent) {
  23414. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23415. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23416. (pfbHeader[3] << 8) | pfbHeader[2];
  23417. }
  23418. // Decrypt the data blocks and retrieve it's content
  23419. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23420. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23421. var data = eexecBlockParser.extractFontProgram();
  23422. for (var info in data.properties) {
  23423. properties[info] = data.properties[info];
  23424. }
  23425. var charstrings = data.charstrings;
  23426. var type2Charstrings = this.getType2Charstrings(charstrings);
  23427. var subrs = this.getType2Subrs(data.subrs);
  23428. this.charstrings = charstrings;
  23429. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23430. subrs, properties);
  23431. this.seacs = this.getSeacs(data.charstrings);
  23432. };
  23433. Type1Font.prototype = {
  23434. get numGlyphs() {
  23435. return this.charstrings.length + 1;
  23436. },
  23437. getCharset: function Type1Font_getCharset() {
  23438. var charset = ['.notdef'];
  23439. var charstrings = this.charstrings;
  23440. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23441. charset.push(charstrings[glyphId].glyphName);
  23442. }
  23443. return charset;
  23444. },
  23445. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23446. var charstrings = this.charstrings;
  23447. var glyphNames = ['.notdef'], glyphId;
  23448. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23449. glyphNames.push(charstrings[glyphId].glyphName);
  23450. }
  23451. var encoding = properties.builtInEncoding;
  23452. if (encoding) {
  23453. var builtInEncoding = {};
  23454. for (var charCode in encoding) {
  23455. glyphId = glyphNames.indexOf(encoding[charCode]);
  23456. if (glyphId >= 0) {
  23457. builtInEncoding[charCode] = glyphId;
  23458. }
  23459. }
  23460. }
  23461. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23462. },
  23463. getSeacs: function Type1Font_getSeacs(charstrings) {
  23464. var i, ii;
  23465. var seacMap = [];
  23466. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23467. var charstring = charstrings[i];
  23468. if (charstring.seac) {
  23469. // Offset by 1 for .notdef
  23470. seacMap[i + 1] = charstring.seac;
  23471. }
  23472. }
  23473. return seacMap;
  23474. },
  23475. getType2Charstrings: function Type1Font_getType2Charstrings(
  23476. type1Charstrings) {
  23477. var type2Charstrings = [];
  23478. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23479. type2Charstrings.push(type1Charstrings[i].charstring);
  23480. }
  23481. return type2Charstrings;
  23482. },
  23483. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23484. var bias = 0;
  23485. var count = type1Subrs.length;
  23486. if (count < 1133) {
  23487. bias = 107;
  23488. } else if (count < 33769) {
  23489. bias = 1131;
  23490. } else {
  23491. bias = 32768;
  23492. }
  23493. // Add a bunch of empty subrs to deal with the Type2 bias
  23494. var type2Subrs = [];
  23495. var i;
  23496. for (i = 0; i < bias; i++) {
  23497. type2Subrs.push([0x0B]);
  23498. }
  23499. for (i = 0; i < count; i++) {
  23500. type2Subrs.push(type1Subrs[i]);
  23501. }
  23502. return type2Subrs;
  23503. },
  23504. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23505. var cff = new CFF();
  23506. cff.header = new CFFHeader(1, 0, 4, 4);
  23507. cff.names = [name];
  23508. var topDict = new CFFTopDict();
  23509. // CFF strings IDs 0...390 are predefined names, so refering
  23510. // to entries in our own String INDEX starts at SID 391.
  23511. topDict.setByName('version', 391);
  23512. topDict.setByName('Notice', 392);
  23513. topDict.setByName('FullName', 393);
  23514. topDict.setByName('FamilyName', 394);
  23515. topDict.setByName('Weight', 395);
  23516. topDict.setByName('Encoding', null); // placeholder
  23517. topDict.setByName('FontMatrix', properties.fontMatrix);
  23518. topDict.setByName('FontBBox', properties.bbox);
  23519. topDict.setByName('charset', null); // placeholder
  23520. topDict.setByName('CharStrings', null); // placeholder
  23521. topDict.setByName('Private', null); // placeholder
  23522. cff.topDict = topDict;
  23523. var strings = new CFFStrings();
  23524. strings.add('Version 0.11'); // Version
  23525. strings.add('See original notice'); // Notice
  23526. strings.add(name); // FullName
  23527. strings.add(name); // FamilyName
  23528. strings.add('Medium'); // Weight
  23529. cff.strings = strings;
  23530. cff.globalSubrIndex = new CFFIndex();
  23531. var count = glyphs.length;
  23532. var charsetArray = [0];
  23533. var i, ii;
  23534. for (i = 0; i < count; i++) {
  23535. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23536. // TODO: Insert the string and correctly map it. Previously it was
  23537. // thought mapping names that aren't in the standard strings to .notdef
  23538. // was fine, however in issue818 when mapping them all to .notdef the
  23539. // adieresis glyph no longer worked.
  23540. if (index === -1) {
  23541. index = 0;
  23542. }
  23543. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23544. }
  23545. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23546. var charStringsIndex = new CFFIndex();
  23547. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23548. for (i = 0; i < count; i++) {
  23549. charStringsIndex.add(glyphs[i]);
  23550. }
  23551. cff.charStrings = charStringsIndex;
  23552. var privateDict = new CFFPrivateDict();
  23553. privateDict.setByName('Subrs', null); // placeholder
  23554. var fields = [
  23555. 'BlueValues',
  23556. 'OtherBlues',
  23557. 'FamilyBlues',
  23558. 'FamilyOtherBlues',
  23559. 'StemSnapH',
  23560. 'StemSnapV',
  23561. 'BlueShift',
  23562. 'BlueFuzz',
  23563. 'BlueScale',
  23564. 'LanguageGroup',
  23565. 'ExpansionFactor',
  23566. 'ForceBold',
  23567. 'StdHW',
  23568. 'StdVW'
  23569. ];
  23570. for (i = 0, ii = fields.length; i < ii; i++) {
  23571. var field = fields[i];
  23572. if (!properties.privateData.hasOwnProperty(field)) {
  23573. continue;
  23574. }
  23575. var value = properties.privateData[field];
  23576. if (isArray(value)) {
  23577. // All of the private dictionary array data in CFF must be stored as
  23578. // "delta-encoded" numbers.
  23579. for (var j = value.length - 1; j > 0; j--) {
  23580. value[j] -= value[j - 1]; // ... difference from previous value
  23581. }
  23582. }
  23583. privateDict.setByName(field, value);
  23584. }
  23585. cff.topDict.privateDict = privateDict;
  23586. var subrIndex = new CFFIndex();
  23587. for (i = 0, ii = subrs.length; i < ii; i++) {
  23588. subrIndex.add(subrs[i]);
  23589. }
  23590. privateDict.subrsIndex = subrIndex;
  23591. var compiler = new CFFCompiler(cff);
  23592. return compiler.compile();
  23593. }
  23594. };
  23595. var CFFFont = (function CFFFontClosure() {
  23596. function CFFFont(file, properties) {
  23597. this.properties = properties;
  23598. var parser = new CFFParser(file, properties);
  23599. this.cff = parser.parse();
  23600. var compiler = new CFFCompiler(this.cff);
  23601. this.seacs = this.cff.seacs;
  23602. try {
  23603. this.data = compiler.compile();
  23604. } catch (e) {
  23605. warn('Failed to compile font ' + properties.loadedName);
  23606. // There may have just been an issue with the compiler, set the data
  23607. // anyway and hope the font loaded.
  23608. this.data = file;
  23609. }
  23610. }
  23611. CFFFont.prototype = {
  23612. get numGlyphs() {
  23613. return this.cff.charStrings.count;
  23614. },
  23615. getCharset: function CFFFont_getCharset() {
  23616. return this.cff.charset.charset;
  23617. },
  23618. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23619. var cff = this.cff;
  23620. var properties = this.properties;
  23621. var charsets = cff.charset.charset;
  23622. var charCodeToGlyphId;
  23623. var glyphId;
  23624. if (properties.composite) {
  23625. charCodeToGlyphId = Object.create(null);
  23626. if (cff.isCIDFont) {
  23627. // If the font is actually a CID font then we should use the charset
  23628. // to map CIDs to GIDs.
  23629. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23630. var cid = charsets[glyphId];
  23631. var charCode = properties.cMap.charCodeOf(cid);
  23632. charCodeToGlyphId[charCode] = glyphId;
  23633. }
  23634. } else {
  23635. // If it is NOT actually a CID font then CIDs should be mapped
  23636. // directly to GIDs.
  23637. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23638. charCodeToGlyphId[glyphId] = glyphId;
  23639. }
  23640. }
  23641. return charCodeToGlyphId;
  23642. }
  23643. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23644. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23645. return charCodeToGlyphId;
  23646. }
  23647. };
  23648. return CFFFont;
  23649. })();
  23650. var CFFParser = (function CFFParserClosure() {
  23651. var CharstringValidationData = [
  23652. null,
  23653. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23654. null,
  23655. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23656. { id: 'vmoveto', min: 1, stackClearing: true },
  23657. { id: 'rlineto', min: 2, resetStack: true },
  23658. { id: 'hlineto', min: 1, resetStack: true },
  23659. { id: 'vlineto', min: 1, resetStack: true },
  23660. { id: 'rrcurveto', min: 6, resetStack: true },
  23661. null,
  23662. { id: 'callsubr', min: 1, undefStack: true },
  23663. { id: 'return', min: 0, undefStack: true },
  23664. null, // 12
  23665. null,
  23666. { id: 'endchar', min: 0, stackClearing: true },
  23667. null,
  23668. null,
  23669. null,
  23670. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23671. { id: 'hintmask', min: 0, stackClearing: true },
  23672. { id: 'cntrmask', min: 0, stackClearing: true },
  23673. { id: 'rmoveto', min: 2, stackClearing: true },
  23674. { id: 'hmoveto', min: 1, stackClearing: true },
  23675. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23676. { id: 'rcurveline', min: 8, resetStack: true },
  23677. { id: 'rlinecurve', min: 8, resetStack: true },
  23678. { id: 'vvcurveto', min: 4, resetStack: true },
  23679. { id: 'hhcurveto', min: 4, resetStack: true },
  23680. null, // shortint
  23681. { id: 'callgsubr', min: 1, undefStack: true },
  23682. { id: 'vhcurveto', min: 4, resetStack: true },
  23683. { id: 'hvcurveto', min: 4, resetStack: true }
  23684. ];
  23685. var CharstringValidationData12 = [
  23686. null,
  23687. null,
  23688. null,
  23689. { id: 'and', min: 2, stackDelta: -1 },
  23690. { id: 'or', min: 2, stackDelta: -1 },
  23691. { id: 'not', min: 1, stackDelta: 0 },
  23692. null,
  23693. null,
  23694. null,
  23695. { id: 'abs', min: 1, stackDelta: 0 },
  23696. { id: 'add', min: 2, stackDelta: -1,
  23697. stackFn: function stack_div(stack, index) {
  23698. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23699. }
  23700. },
  23701. { id: 'sub', min: 2, stackDelta: -1,
  23702. stackFn: function stack_div(stack, index) {
  23703. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23704. }
  23705. },
  23706. { id: 'div', min: 2, stackDelta: -1,
  23707. stackFn: function stack_div(stack, index) {
  23708. stack[index - 2] = stack[index - 2] / stack[index - 1];
  23709. }
  23710. },
  23711. null,
  23712. { id: 'neg', min: 1, stackDelta: 0,
  23713. stackFn: function stack_div(stack, index) {
  23714. stack[index - 1] = -stack[index - 1];
  23715. }
  23716. },
  23717. { id: 'eq', min: 2, stackDelta: -1 },
  23718. null,
  23719. null,
  23720. { id: 'drop', min: 1, stackDelta: -1 },
  23721. null,
  23722. { id: 'put', min: 2, stackDelta: -2 },
  23723. { id: 'get', min: 1, stackDelta: 0 },
  23724. { id: 'ifelse', min: 4, stackDelta: -3 },
  23725. { id: 'random', min: 0, stackDelta: 1 },
  23726. { id: 'mul', min: 2, stackDelta: -1,
  23727. stackFn: function stack_div(stack, index) {
  23728. stack[index - 2] = stack[index - 2] * stack[index - 1];
  23729. }
  23730. },
  23731. null,
  23732. { id: 'sqrt', min: 1, stackDelta: 0 },
  23733. { id: 'dup', min: 1, stackDelta: 1 },
  23734. { id: 'exch', min: 2, stackDelta: 0 },
  23735. { id: 'index', min: 2, stackDelta: 0 },
  23736. { id: 'roll', min: 3, stackDelta: -2 },
  23737. null,
  23738. null,
  23739. null,
  23740. { id: 'hflex', min: 7, resetStack: true },
  23741. { id: 'flex', min: 13, resetStack: true },
  23742. { id: 'hflex1', min: 9, resetStack: true },
  23743. { id: 'flex1', min: 11, resetStack: true }
  23744. ];
  23745. function CFFParser(file, properties) {
  23746. this.bytes = file.getBytes();
  23747. this.properties = properties;
  23748. }
  23749. CFFParser.prototype = {
  23750. parse: function CFFParser_parse() {
  23751. var properties = this.properties;
  23752. var cff = new CFF();
  23753. this.cff = cff;
  23754. // The first five sections must be in order, all the others are reached
  23755. // via offsets contained in one of the below.
  23756. var header = this.parseHeader();
  23757. var nameIndex = this.parseIndex(header.endPos);
  23758. var topDictIndex = this.parseIndex(nameIndex.endPos);
  23759. var stringIndex = this.parseIndex(topDictIndex.endPos);
  23760. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  23761. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  23762. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  23763. cff.header = header.obj;
  23764. cff.names = this.parseNameIndex(nameIndex.obj);
  23765. cff.strings = this.parseStringIndex(stringIndex.obj);
  23766. cff.topDict = topDict;
  23767. cff.globalSubrIndex = globalSubrIndex.obj;
  23768. this.parsePrivateDict(cff.topDict);
  23769. cff.isCIDFont = topDict.hasName('ROS');
  23770. var charStringOffset = topDict.getByName('CharStrings');
  23771. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  23772. cff.charStrings = charStringsAndSeacs.charStrings;
  23773. cff.seacs = charStringsAndSeacs.seacs;
  23774. cff.widths = charStringsAndSeacs.widths;
  23775. var fontMatrix = topDict.getByName('FontMatrix');
  23776. if (fontMatrix) {
  23777. properties.fontMatrix = fontMatrix;
  23778. }
  23779. var fontBBox = topDict.getByName('FontBBox');
  23780. if (fontBBox) {
  23781. // adjusting ascent/descent
  23782. properties.ascent = fontBBox[3];
  23783. properties.descent = fontBBox[1];
  23784. properties.ascentScaled = true;
  23785. }
  23786. var charset, encoding;
  23787. if (cff.isCIDFont) {
  23788. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  23789. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  23790. var dictRaw = fdArrayIndex.get(i);
  23791. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  23792. cff.strings);
  23793. this.parsePrivateDict(fontDict);
  23794. cff.fdArray.push(fontDict);
  23795. }
  23796. // cid fonts don't have an encoding
  23797. encoding = null;
  23798. charset = this.parseCharsets(topDict.getByName('charset'),
  23799. cff.charStrings.count, cff.strings, true);
  23800. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  23801. cff.charStrings.count);
  23802. } else {
  23803. charset = this.parseCharsets(topDict.getByName('charset'),
  23804. cff.charStrings.count, cff.strings, false);
  23805. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  23806. properties,
  23807. cff.strings, charset.charset);
  23808. }
  23809. cff.charset = charset;
  23810. cff.encoding = encoding;
  23811. return cff;
  23812. },
  23813. parseHeader: function CFFParser_parseHeader() {
  23814. var bytes = this.bytes;
  23815. var bytesLength = bytes.length;
  23816. var offset = 0;
  23817. // Prevent an infinite loop, by checking that the offset is within the
  23818. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  23819. while (offset < bytesLength && bytes[offset] !== 1) {
  23820. ++offset;
  23821. }
  23822. if (offset >= bytesLength) {
  23823. error('Invalid CFF header');
  23824. } else if (offset !== 0) {
  23825. info('cff data is shifted');
  23826. bytes = bytes.subarray(offset);
  23827. this.bytes = bytes;
  23828. }
  23829. var major = bytes[0];
  23830. var minor = bytes[1];
  23831. var hdrSize = bytes[2];
  23832. var offSize = bytes[3];
  23833. var header = new CFFHeader(major, minor, hdrSize, offSize);
  23834. return { obj: header, endPos: hdrSize };
  23835. },
  23836. parseDict: function CFFParser_parseDict(dict) {
  23837. var pos = 0;
  23838. function parseOperand() {
  23839. var value = dict[pos++];
  23840. if (value === 30) {
  23841. return parseFloatOperand(pos);
  23842. } else if (value === 28) {
  23843. value = dict[pos++];
  23844. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  23845. return value;
  23846. } else if (value === 29) {
  23847. value = dict[pos++];
  23848. value = (value << 8) | dict[pos++];
  23849. value = (value << 8) | dict[pos++];
  23850. value = (value << 8) | dict[pos++];
  23851. return value;
  23852. } else if (value >= 32 && value <= 246) {
  23853. return value - 139;
  23854. } else if (value >= 247 && value <= 250) {
  23855. return ((value - 247) * 256) + dict[pos++] + 108;
  23856. } else if (value >= 251 && value <= 254) {
  23857. return -((value - 251) * 256) - dict[pos++] - 108;
  23858. } else {
  23859. error('255 is not a valid DICT command');
  23860. }
  23861. return -1;
  23862. }
  23863. function parseFloatOperand() {
  23864. var str = '';
  23865. var eof = 15;
  23866. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  23867. '9', '.', 'E', 'E-', null, '-'];
  23868. var length = dict.length;
  23869. while (pos < length) {
  23870. var b = dict[pos++];
  23871. var b1 = b >> 4;
  23872. var b2 = b & 15;
  23873. if (b1 === eof) {
  23874. break;
  23875. }
  23876. str += lookup[b1];
  23877. if (b2 === eof) {
  23878. break;
  23879. }
  23880. str += lookup[b2];
  23881. }
  23882. return parseFloat(str);
  23883. }
  23884. var operands = [];
  23885. var entries = [];
  23886. pos = 0;
  23887. var end = dict.length;
  23888. while (pos < end) {
  23889. var b = dict[pos];
  23890. if (b <= 21) {
  23891. if (b === 12) {
  23892. b = (b << 8) | dict[++pos];
  23893. }
  23894. entries.push([b, operands]);
  23895. operands = [];
  23896. ++pos;
  23897. } else {
  23898. operands.push(parseOperand());
  23899. }
  23900. }
  23901. return entries;
  23902. },
  23903. parseIndex: function CFFParser_parseIndex(pos) {
  23904. var cffIndex = new CFFIndex();
  23905. var bytes = this.bytes;
  23906. var count = (bytes[pos++] << 8) | bytes[pos++];
  23907. var offsets = [];
  23908. var end = pos;
  23909. var i, ii;
  23910. if (count !== 0) {
  23911. var offsetSize = bytes[pos++];
  23912. // add 1 for offset to determine size of last object
  23913. var startPos = pos + ((count + 1) * offsetSize) - 1;
  23914. for (i = 0, ii = count + 1; i < ii; ++i) {
  23915. var offset = 0;
  23916. for (var j = 0; j < offsetSize; ++j) {
  23917. offset <<= 8;
  23918. offset += bytes[pos++];
  23919. }
  23920. offsets.push(startPos + offset);
  23921. }
  23922. end = offsets[count];
  23923. }
  23924. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  23925. var offsetStart = offsets[i];
  23926. var offsetEnd = offsets[i + 1];
  23927. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  23928. }
  23929. return {obj: cffIndex, endPos: end};
  23930. },
  23931. parseNameIndex: function CFFParser_parseNameIndex(index) {
  23932. var names = [];
  23933. for (var i = 0, ii = index.count; i < ii; ++i) {
  23934. var name = index.get(i);
  23935. // OTS doesn't allow names to be over 127 characters.
  23936. var length = Math.min(name.length, 127);
  23937. var data = [];
  23938. // OTS also only permits certain characters in the name.
  23939. for (var j = 0; j < length; ++j) {
  23940. var c = name[j];
  23941. if (j === 0 && c === 0) {
  23942. data[j] = c;
  23943. continue;
  23944. }
  23945. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  23946. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  23947. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  23948. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  23949. data[j] = 95;
  23950. continue;
  23951. }
  23952. data[j] = c;
  23953. }
  23954. names.push(bytesToString(data));
  23955. }
  23956. return names;
  23957. },
  23958. parseStringIndex: function CFFParser_parseStringIndex(index) {
  23959. var strings = new CFFStrings();
  23960. for (var i = 0, ii = index.count; i < ii; ++i) {
  23961. var data = index.get(i);
  23962. strings.add(bytesToString(data));
  23963. }
  23964. return strings;
  23965. },
  23966. createDict: function CFFParser_createDict(Type, dict, strings) {
  23967. var cffDict = new Type(strings);
  23968. for (var i = 0, ii = dict.length; i < ii; ++i) {
  23969. var pair = dict[i];
  23970. var key = pair[0];
  23971. var value = pair[1];
  23972. cffDict.setByKey(key, value);
  23973. }
  23974. return cffDict;
  23975. },
  23976. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  23977. var charStrings = this.parseIndex(charStringOffset).obj;
  23978. var seacs = [];
  23979. var widths = [];
  23980. var count = charStrings.count;
  23981. for (var i = 0; i < count; i++) {
  23982. var charstring = charStrings.get(i);
  23983. var stackSize = 0;
  23984. var stack = [];
  23985. var undefStack = true;
  23986. var hints = 0;
  23987. var valid = true;
  23988. var data = charstring;
  23989. var length = data.length;
  23990. var firstStackClearing = true;
  23991. for (var j = 0; j < length;) {
  23992. var value = data[j++];
  23993. var validationCommand = null;
  23994. if (value === 12) {
  23995. var q = data[j++];
  23996. if (q === 0) {
  23997. // The CFF specification state that the 'dotsection' command
  23998. // (12, 0) is deprecated and treated as a no-op, but all Type2
  23999. // charstrings processors should support them. Unfortunately
  24000. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24001. // is replaced by a useless (0, hmoveto).
  24002. data[j - 2] = 139;
  24003. data[j - 1] = 22;
  24004. stackSize = 0;
  24005. } else {
  24006. validationCommand = CharstringValidationData12[q];
  24007. }
  24008. } else if (value === 28) { // number (16 bit)
  24009. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24010. j += 2;
  24011. stackSize++;
  24012. } else if (value === 14) {
  24013. if (stackSize >= 4) {
  24014. stackSize -= 4;
  24015. if (SEAC_ANALYSIS_ENABLED) {
  24016. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24017. valid = false;
  24018. }
  24019. }
  24020. validationCommand = CharstringValidationData[value];
  24021. } else if (value >= 32 && value <= 246) { // number
  24022. stack[stackSize] = value - 139;
  24023. stackSize++;
  24024. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24025. stack[stackSize] = (value < 251 ?
  24026. ((value - 247) << 8) + data[j] + 108 :
  24027. -((value - 251) << 8) - data[j] - 108);
  24028. j++;
  24029. stackSize++;
  24030. } else if (value === 255) { // number (32 bit)
  24031. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24032. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24033. j += 4;
  24034. stackSize++;
  24035. } else if (value === 19 || value === 20) {
  24036. hints += stackSize >> 1;
  24037. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24038. stackSize %= 2;
  24039. validationCommand = CharstringValidationData[value];
  24040. } else {
  24041. validationCommand = CharstringValidationData[value];
  24042. }
  24043. if (validationCommand) {
  24044. if (validationCommand.stem) {
  24045. hints += stackSize >> 1;
  24046. }
  24047. if ('min' in validationCommand) {
  24048. if (!undefStack && stackSize < validationCommand.min) {
  24049. warn('Not enough parameters for ' + validationCommand.id +
  24050. '; actual: ' + stackSize +
  24051. ', expected: ' + validationCommand.min);
  24052. valid = false;
  24053. break;
  24054. }
  24055. }
  24056. if (firstStackClearing && validationCommand.stackClearing) {
  24057. firstStackClearing = false;
  24058. // the optional character width can be found before the first
  24059. // stack-clearing command arguments
  24060. stackSize -= validationCommand.min;
  24061. if (stackSize >= 2 && validationCommand.stem) {
  24062. // there are even amount of arguments for stem commands
  24063. stackSize %= 2;
  24064. } else if (stackSize > 1) {
  24065. warn('Found too many parameters for stack-clearing command');
  24066. }
  24067. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24068. widths[i] = stack[stackSize - 1];
  24069. }
  24070. }
  24071. if ('stackDelta' in validationCommand) {
  24072. if ('stackFn' in validationCommand) {
  24073. validationCommand.stackFn(stack, stackSize);
  24074. }
  24075. stackSize += validationCommand.stackDelta;
  24076. } else if (validationCommand.stackClearing) {
  24077. stackSize = 0;
  24078. } else if (validationCommand.resetStack) {
  24079. stackSize = 0;
  24080. undefStack = false;
  24081. } else if (validationCommand.undefStack) {
  24082. stackSize = 0;
  24083. undefStack = true;
  24084. firstStackClearing = false;
  24085. }
  24086. }
  24087. }
  24088. if (!valid) {
  24089. // resetting invalid charstring to single 'endchar'
  24090. charStrings.set(i, new Uint8Array([14]));
  24091. }
  24092. }
  24093. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24094. },
  24095. emptyPrivateDictionary:
  24096. function CFFParser_emptyPrivateDictionary(parentDict) {
  24097. var privateDict = this.createDict(CFFPrivateDict, [],
  24098. parentDict.strings);
  24099. parentDict.setByKey(18, [0, 0]);
  24100. parentDict.privateDict = privateDict;
  24101. },
  24102. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24103. // no private dict, do nothing
  24104. if (!parentDict.hasName('Private')) {
  24105. this.emptyPrivateDictionary(parentDict);
  24106. return;
  24107. }
  24108. var privateOffset = parentDict.getByName('Private');
  24109. // make sure the params are formatted correctly
  24110. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24111. parentDict.removeByName('Private');
  24112. return;
  24113. }
  24114. var size = privateOffset[0];
  24115. var offset = privateOffset[1];
  24116. // remove empty dicts or ones that refer to invalid location
  24117. if (size === 0 || offset >= this.bytes.length) {
  24118. this.emptyPrivateDictionary(parentDict);
  24119. return;
  24120. }
  24121. var privateDictEnd = offset + size;
  24122. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24123. var dict = this.parseDict(dictData);
  24124. var privateDict = this.createDict(CFFPrivateDict, dict,
  24125. parentDict.strings);
  24126. parentDict.privateDict = privateDict;
  24127. // Parse the Subrs index also since it's relative to the private dict.
  24128. if (!privateDict.getByName('Subrs')) {
  24129. return;
  24130. }
  24131. var subrsOffset = privateDict.getByName('Subrs');
  24132. var relativeOffset = offset + subrsOffset;
  24133. // Validate the offset.
  24134. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24135. this.emptyPrivateDictionary(parentDict);
  24136. return;
  24137. }
  24138. var subrsIndex = this.parseIndex(relativeOffset);
  24139. privateDict.subrsIndex = subrsIndex.obj;
  24140. },
  24141. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24142. if (pos === 0) {
  24143. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24144. ISOAdobeCharset);
  24145. } else if (pos === 1) {
  24146. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24147. ExpertCharset);
  24148. } else if (pos === 2) {
  24149. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24150. ExpertSubsetCharset);
  24151. }
  24152. var bytes = this.bytes;
  24153. var start = pos;
  24154. var format = bytes[pos++];
  24155. var charset = ['.notdef'];
  24156. var id, count, i;
  24157. // subtract 1 for the .notdef glyph
  24158. length -= 1;
  24159. switch (format) {
  24160. case 0:
  24161. for (i = 0; i < length; i++) {
  24162. id = (bytes[pos++] << 8) | bytes[pos++];
  24163. charset.push(cid ? id : strings.get(id));
  24164. }
  24165. break;
  24166. case 1:
  24167. while (charset.length <= length) {
  24168. id = (bytes[pos++] << 8) | bytes[pos++];
  24169. count = bytes[pos++];
  24170. for (i = 0; i <= count; i++) {
  24171. charset.push(cid ? id++ : strings.get(id++));
  24172. }
  24173. }
  24174. break;
  24175. case 2:
  24176. while (charset.length <= length) {
  24177. id = (bytes[pos++] << 8) | bytes[pos++];
  24178. count = (bytes[pos++] << 8) | bytes[pos++];
  24179. for (i = 0; i <= count; i++) {
  24180. charset.push(cid ? id++ : strings.get(id++));
  24181. }
  24182. }
  24183. break;
  24184. default:
  24185. error('Unknown charset format');
  24186. }
  24187. // Raw won't be needed if we actually compile the charset.
  24188. var end = pos;
  24189. var raw = bytes.subarray(start, end);
  24190. return new CFFCharset(false, format, charset, raw);
  24191. },
  24192. parseEncoding: function CFFParser_parseEncoding(pos,
  24193. properties,
  24194. strings,
  24195. charset) {
  24196. var encoding = {};
  24197. var bytes = this.bytes;
  24198. var predefined = false;
  24199. var hasSupplement = false;
  24200. var format, i, ii;
  24201. var raw = null;
  24202. function readSupplement() {
  24203. var supplementsCount = bytes[pos++];
  24204. for (i = 0; i < supplementsCount; i++) {
  24205. var code = bytes[pos++];
  24206. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24207. encoding[code] = charset.indexOf(strings.get(sid));
  24208. }
  24209. }
  24210. if (pos === 0 || pos === 1) {
  24211. predefined = true;
  24212. format = pos;
  24213. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24214. Encodings.StandardEncoding;
  24215. for (i = 0, ii = charset.length; i < ii; i++) {
  24216. var index = baseEncoding.indexOf(charset[i]);
  24217. if (index !== -1) {
  24218. encoding[index] = i;
  24219. }
  24220. }
  24221. } else {
  24222. var dataStart = pos;
  24223. format = bytes[pos++];
  24224. switch (format & 0x7f) {
  24225. case 0:
  24226. var glyphsCount = bytes[pos++];
  24227. for (i = 1; i <= glyphsCount; i++) {
  24228. encoding[bytes[pos++]] = i;
  24229. }
  24230. break;
  24231. case 1:
  24232. var rangesCount = bytes[pos++];
  24233. var gid = 1;
  24234. for (i = 0; i < rangesCount; i++) {
  24235. var start = bytes[pos++];
  24236. var left = bytes[pos++];
  24237. for (var j = start; j <= start + left; j++) {
  24238. encoding[j] = gid++;
  24239. }
  24240. }
  24241. break;
  24242. default:
  24243. error('Unknow encoding format: ' + format + ' in CFF');
  24244. break;
  24245. }
  24246. var dataEnd = pos;
  24247. if (format & 0x80) {
  24248. // The font sanitizer does not support CFF encoding with a
  24249. // supplement, since the encoding is not really used to map
  24250. // between gid to glyph, let's overwrite what is declared in
  24251. // the top dictionary to let the sanitizer think the font use
  24252. // StandardEncoding, that's a lie but that's ok.
  24253. bytes[dataStart] &= 0x7f;
  24254. readSupplement();
  24255. hasSupplement = true;
  24256. }
  24257. raw = bytes.subarray(dataStart, dataEnd);
  24258. }
  24259. format = format & 0x7f;
  24260. return new CFFEncoding(predefined, format, encoding, raw);
  24261. },
  24262. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24263. var start = pos;
  24264. var bytes = this.bytes;
  24265. var format = bytes[pos++];
  24266. var fdSelect = [];
  24267. var i;
  24268. switch (format) {
  24269. case 0:
  24270. for (i = 0; i < length; ++i) {
  24271. var id = bytes[pos++];
  24272. fdSelect.push(id);
  24273. }
  24274. break;
  24275. case 3:
  24276. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24277. for (i = 0; i < rangesCount; ++i) {
  24278. var first = (bytes[pos++] << 8) | bytes[pos++];
  24279. var fdIndex = bytes[pos++];
  24280. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24281. for (var j = first; j < next; ++j) {
  24282. fdSelect.push(fdIndex);
  24283. }
  24284. }
  24285. // Advance past the sentinel(next).
  24286. pos += 2;
  24287. break;
  24288. default:
  24289. error('Unknown fdselect format ' + format);
  24290. break;
  24291. }
  24292. var end = pos;
  24293. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24294. }
  24295. };
  24296. return CFFParser;
  24297. })();
  24298. // Compact Font Format
  24299. var CFF = (function CFFClosure() {
  24300. function CFF() {
  24301. this.header = null;
  24302. this.names = [];
  24303. this.topDict = null;
  24304. this.strings = new CFFStrings();
  24305. this.globalSubrIndex = null;
  24306. // The following could really be per font, but since we only have one font
  24307. // store them here.
  24308. this.encoding = null;
  24309. this.charset = null;
  24310. this.charStrings = null;
  24311. this.fdArray = [];
  24312. this.fdSelect = null;
  24313. this.isCIDFont = false;
  24314. }
  24315. return CFF;
  24316. })();
  24317. var CFFHeader = (function CFFHeaderClosure() {
  24318. function CFFHeader(major, minor, hdrSize, offSize) {
  24319. this.major = major;
  24320. this.minor = minor;
  24321. this.hdrSize = hdrSize;
  24322. this.offSize = offSize;
  24323. }
  24324. return CFFHeader;
  24325. })();
  24326. var CFFStrings = (function CFFStringsClosure() {
  24327. function CFFStrings() {
  24328. this.strings = [];
  24329. }
  24330. CFFStrings.prototype = {
  24331. get: function CFFStrings_get(index) {
  24332. if (index >= 0 && index <= 390) {
  24333. return CFFStandardStrings[index];
  24334. }
  24335. if (index - 391 <= this.strings.length) {
  24336. return this.strings[index - 391];
  24337. }
  24338. return CFFStandardStrings[0];
  24339. },
  24340. add: function CFFStrings_add(value) {
  24341. this.strings.push(value);
  24342. },
  24343. get count() {
  24344. return this.strings.length;
  24345. }
  24346. };
  24347. return CFFStrings;
  24348. })();
  24349. var CFFIndex = (function CFFIndexClosure() {
  24350. function CFFIndex() {
  24351. this.objects = [];
  24352. this.length = 0;
  24353. }
  24354. CFFIndex.prototype = {
  24355. add: function CFFIndex_add(data) {
  24356. this.length += data.length;
  24357. this.objects.push(data);
  24358. },
  24359. set: function CFFIndex_set(index, data) {
  24360. this.length += data.length - this.objects[index].length;
  24361. this.objects[index] = data;
  24362. },
  24363. get: function CFFIndex_get(index) {
  24364. return this.objects[index];
  24365. },
  24366. get count() {
  24367. return this.objects.length;
  24368. }
  24369. };
  24370. return CFFIndex;
  24371. })();
  24372. var CFFDict = (function CFFDictClosure() {
  24373. function CFFDict(tables, strings) {
  24374. this.keyToNameMap = tables.keyToNameMap;
  24375. this.nameToKeyMap = tables.nameToKeyMap;
  24376. this.defaults = tables.defaults;
  24377. this.types = tables.types;
  24378. this.opcodes = tables.opcodes;
  24379. this.order = tables.order;
  24380. this.strings = strings;
  24381. this.values = {};
  24382. }
  24383. CFFDict.prototype = {
  24384. // value should always be an array
  24385. setByKey: function CFFDict_setByKey(key, value) {
  24386. if (!(key in this.keyToNameMap)) {
  24387. return false;
  24388. }
  24389. // ignore empty values
  24390. if (value.length === 0) {
  24391. return true;
  24392. }
  24393. var type = this.types[key];
  24394. // remove the array wrapping these types of values
  24395. if (type === 'num' || type === 'sid' || type === 'offset') {
  24396. value = value[0];
  24397. }
  24398. this.values[key] = value;
  24399. return true;
  24400. },
  24401. setByName: function CFFDict_setByName(name, value) {
  24402. if (!(name in this.nameToKeyMap)) {
  24403. error('Invalid dictionary name "' + name + '"');
  24404. }
  24405. this.values[this.nameToKeyMap[name]] = value;
  24406. },
  24407. hasName: function CFFDict_hasName(name) {
  24408. return this.nameToKeyMap[name] in this.values;
  24409. },
  24410. getByName: function CFFDict_getByName(name) {
  24411. if (!(name in this.nameToKeyMap)) {
  24412. error('Invalid dictionary name "' + name + '"');
  24413. }
  24414. var key = this.nameToKeyMap[name];
  24415. if (!(key in this.values)) {
  24416. return this.defaults[key];
  24417. }
  24418. return this.values[key];
  24419. },
  24420. removeByName: function CFFDict_removeByName(name) {
  24421. delete this.values[this.nameToKeyMap[name]];
  24422. }
  24423. };
  24424. CFFDict.createTables = function CFFDict_createTables(layout) {
  24425. var tables = {
  24426. keyToNameMap: {},
  24427. nameToKeyMap: {},
  24428. defaults: {},
  24429. types: {},
  24430. opcodes: {},
  24431. order: []
  24432. };
  24433. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24434. var entry = layout[i];
  24435. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24436. tables.keyToNameMap[key] = entry[1];
  24437. tables.nameToKeyMap[entry[1]] = key;
  24438. tables.types[key] = entry[2];
  24439. tables.defaults[key] = entry[3];
  24440. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24441. tables.order.push(key);
  24442. }
  24443. return tables;
  24444. };
  24445. return CFFDict;
  24446. })();
  24447. var CFFTopDict = (function CFFTopDictClosure() {
  24448. var layout = [
  24449. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24450. [[12, 20], 'SyntheticBase', 'num', null],
  24451. [0, 'version', 'sid', null],
  24452. [1, 'Notice', 'sid', null],
  24453. [[12, 0], 'Copyright', 'sid', null],
  24454. [2, 'FullName', 'sid', null],
  24455. [3, 'FamilyName', 'sid', null],
  24456. [4, 'Weight', 'sid', null],
  24457. [[12, 1], 'isFixedPitch', 'num', 0],
  24458. [[12, 2], 'ItalicAngle', 'num', 0],
  24459. [[12, 3], 'UnderlinePosition', 'num', -100],
  24460. [[12, 4], 'UnderlineThickness', 'num', 50],
  24461. [[12, 5], 'PaintType', 'num', 0],
  24462. [[12, 6], 'CharstringType', 'num', 2],
  24463. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24464. [0.001, 0, 0, 0.001, 0, 0]],
  24465. [13, 'UniqueID', 'num', null],
  24466. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24467. [[12, 8], 'StrokeWidth', 'num', 0],
  24468. [14, 'XUID', 'array', null],
  24469. [15, 'charset', 'offset', 0],
  24470. [16, 'Encoding', 'offset', 0],
  24471. [17, 'CharStrings', 'offset', 0],
  24472. [18, 'Private', ['offset', 'offset'], null],
  24473. [[12, 21], 'PostScript', 'sid', null],
  24474. [[12, 22], 'BaseFontName', 'sid', null],
  24475. [[12, 23], 'BaseFontBlend', 'delta', null],
  24476. [[12, 31], 'CIDFontVersion', 'num', 0],
  24477. [[12, 32], 'CIDFontRevision', 'num', 0],
  24478. [[12, 33], 'CIDFontType', 'num', 0],
  24479. [[12, 34], 'CIDCount', 'num', 8720],
  24480. [[12, 35], 'UIDBase', 'num', null],
  24481. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24482. // before FDArray.
  24483. [[12, 37], 'FDSelect', 'offset', null],
  24484. [[12, 36], 'FDArray', 'offset', null],
  24485. [[12, 38], 'FontName', 'sid', null]
  24486. ];
  24487. var tables = null;
  24488. function CFFTopDict(strings) {
  24489. if (tables === null) {
  24490. tables = CFFDict.createTables(layout);
  24491. }
  24492. CFFDict.call(this, tables, strings);
  24493. this.privateDict = null;
  24494. }
  24495. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24496. return CFFTopDict;
  24497. })();
  24498. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24499. var layout = [
  24500. [6, 'BlueValues', 'delta', null],
  24501. [7, 'OtherBlues', 'delta', null],
  24502. [8, 'FamilyBlues', 'delta', null],
  24503. [9, 'FamilyOtherBlues', 'delta', null],
  24504. [[12, 9], 'BlueScale', 'num', 0.039625],
  24505. [[12, 10], 'BlueShift', 'num', 7],
  24506. [[12, 11], 'BlueFuzz', 'num', 1],
  24507. [10, 'StdHW', 'num', null],
  24508. [11, 'StdVW', 'num', null],
  24509. [[12, 12], 'StemSnapH', 'delta', null],
  24510. [[12, 13], 'StemSnapV', 'delta', null],
  24511. [[12, 14], 'ForceBold', 'num', 0],
  24512. [[12, 17], 'LanguageGroup', 'num', 0],
  24513. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24514. [[12, 19], 'initialRandomSeed', 'num', 0],
  24515. [20, 'defaultWidthX', 'num', 0],
  24516. [21, 'nominalWidthX', 'num', 0],
  24517. [19, 'Subrs', 'offset', null]
  24518. ];
  24519. var tables = null;
  24520. function CFFPrivateDict(strings) {
  24521. if (tables === null) {
  24522. tables = CFFDict.createTables(layout);
  24523. }
  24524. CFFDict.call(this, tables, strings);
  24525. this.subrsIndex = null;
  24526. }
  24527. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24528. return CFFPrivateDict;
  24529. })();
  24530. var CFFCharsetPredefinedTypes = {
  24531. ISO_ADOBE: 0,
  24532. EXPERT: 1,
  24533. EXPERT_SUBSET: 2
  24534. };
  24535. var CFFCharset = (function CFFCharsetClosure() {
  24536. function CFFCharset(predefined, format, charset, raw) {
  24537. this.predefined = predefined;
  24538. this.format = format;
  24539. this.charset = charset;
  24540. this.raw = raw;
  24541. }
  24542. return CFFCharset;
  24543. })();
  24544. var CFFEncoding = (function CFFEncodingClosure() {
  24545. function CFFEncoding(predefined, format, encoding, raw) {
  24546. this.predefined = predefined;
  24547. this.format = format;
  24548. this.encoding = encoding;
  24549. this.raw = raw;
  24550. }
  24551. return CFFEncoding;
  24552. })();
  24553. var CFFFDSelect = (function CFFFDSelectClosure() {
  24554. function CFFFDSelect(fdSelect, raw) {
  24555. this.fdSelect = fdSelect;
  24556. this.raw = raw;
  24557. }
  24558. return CFFFDSelect;
  24559. })();
  24560. // Helper class to keep track of where an offset is within the data and helps
  24561. // filling in that offset once it's known.
  24562. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24563. function CFFOffsetTracker() {
  24564. this.offsets = {};
  24565. }
  24566. CFFOffsetTracker.prototype = {
  24567. isTracking: function CFFOffsetTracker_isTracking(key) {
  24568. return key in this.offsets;
  24569. },
  24570. track: function CFFOffsetTracker_track(key, location) {
  24571. if (key in this.offsets) {
  24572. error('Already tracking location of ' + key);
  24573. }
  24574. this.offsets[key] = location;
  24575. },
  24576. offset: function CFFOffsetTracker_offset(value) {
  24577. for (var key in this.offsets) {
  24578. this.offsets[key] += value;
  24579. }
  24580. },
  24581. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24582. values,
  24583. output) {
  24584. if (!(key in this.offsets)) {
  24585. error('Not tracking location of ' + key);
  24586. }
  24587. var data = output.data;
  24588. var dataOffset = this.offsets[key];
  24589. var size = 5;
  24590. for (var i = 0, ii = values.length; i < ii; ++i) {
  24591. var offset0 = i * size + dataOffset;
  24592. var offset1 = offset0 + 1;
  24593. var offset2 = offset0 + 2;
  24594. var offset3 = offset0 + 3;
  24595. var offset4 = offset0 + 4;
  24596. // It's easy to screw up offsets so perform this sanity check.
  24597. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24598. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24599. error('writing to an offset that is not empty');
  24600. }
  24601. var value = values[i];
  24602. data[offset0] = 0x1d;
  24603. data[offset1] = (value >> 24) & 0xFF;
  24604. data[offset2] = (value >> 16) & 0xFF;
  24605. data[offset3] = (value >> 8) & 0xFF;
  24606. data[offset4] = value & 0xFF;
  24607. }
  24608. }
  24609. };
  24610. return CFFOffsetTracker;
  24611. })();
  24612. // Takes a CFF and converts it to the binary representation.
  24613. var CFFCompiler = (function CFFCompilerClosure() {
  24614. function CFFCompiler(cff) {
  24615. this.cff = cff;
  24616. }
  24617. CFFCompiler.prototype = {
  24618. compile: function CFFCompiler_compile() {
  24619. var cff = this.cff;
  24620. var output = {
  24621. data: [],
  24622. length: 0,
  24623. add: function CFFCompiler_add(data) {
  24624. this.data = this.data.concat(data);
  24625. this.length = this.data.length;
  24626. }
  24627. };
  24628. // Compile the five entries that must be in order.
  24629. var header = this.compileHeader(cff.header);
  24630. output.add(header);
  24631. var nameIndex = this.compileNameIndex(cff.names);
  24632. output.add(nameIndex);
  24633. if (cff.isCIDFont) {
  24634. // The spec is unclear on how font matrices should relate to each other
  24635. // when there is one in the main top dict and the sub top dicts.
  24636. // Windows handles this differently than linux and osx so we have to
  24637. // normalize to work on all.
  24638. // Rules based off of some mailing list discussions:
  24639. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24640. // - If no main font matrix and there is a subfont matrix, use the
  24641. // subfont matrix.
  24642. // - If both have matrices, concat together.
  24643. // - If neither have matrices, use default.
  24644. // To make this work on all platforms we move the top matrix into each
  24645. // sub top dict and concat if necessary.
  24646. if (cff.topDict.hasName('FontMatrix')) {
  24647. var base = cff.topDict.getByName('FontMatrix');
  24648. cff.topDict.removeByName('FontMatrix');
  24649. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24650. var subDict = cff.fdArray[i];
  24651. var matrix = base.slice(0);
  24652. if (subDict.hasName('FontMatrix')) {
  24653. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24654. }
  24655. subDict.setByName('FontMatrix', matrix);
  24656. }
  24657. }
  24658. }
  24659. var compiled = this.compileTopDicts([cff.topDict],
  24660. output.length,
  24661. cff.isCIDFont);
  24662. output.add(compiled.output);
  24663. var topDictTracker = compiled.trackers[0];
  24664. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24665. output.add(stringIndex);
  24666. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24667. output.add(globalSubrIndex);
  24668. // Now start on the other entries that have no specfic order.
  24669. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24670. if (cff.encoding.predefined) {
  24671. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24672. output);
  24673. } else {
  24674. var encoding = this.compileEncoding(cff.encoding);
  24675. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24676. output.add(encoding);
  24677. }
  24678. }
  24679. if (cff.charset && cff.topDict.hasName('charset')) {
  24680. if (cff.charset.predefined) {
  24681. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24682. output);
  24683. } else {
  24684. var charset = this.compileCharset(cff.charset);
  24685. topDictTracker.setEntryLocation('charset', [output.length], output);
  24686. output.add(charset);
  24687. }
  24688. }
  24689. var charStrings = this.compileCharStrings(cff.charStrings);
  24690. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24691. output.add(charStrings);
  24692. if (cff.isCIDFont) {
  24693. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24694. // and linux don't seem to care.
  24695. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24696. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24697. output.add(fdSelect);
  24698. // It is unclear if the sub font dictionary can have CID related
  24699. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24700. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24701. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24702. output.add(compiled.output);
  24703. var fontDictTrackers = compiled.trackers;
  24704. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  24705. }
  24706. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  24707. // If the font data ends with INDEX whose object data is zero-length,
  24708. // the sanitizer will bail out. Add a dummy byte to avoid that.
  24709. output.add([0]);
  24710. return output.data;
  24711. },
  24712. encodeNumber: function CFFCompiler_encodeNumber(value) {
  24713. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  24714. return this.encodeInteger(value);
  24715. } else {
  24716. return this.encodeFloat(value);
  24717. }
  24718. },
  24719. encodeFloat: function CFFCompiler_encodeFloat(num) {
  24720. var value = num.toString();
  24721. // rounding inaccurate doubles
  24722. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  24723. if (m) {
  24724. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  24725. value = (Math.round(num * epsilon) / epsilon).toString();
  24726. }
  24727. var nibbles = '';
  24728. var i, ii;
  24729. for (i = 0, ii = value.length; i < ii; ++i) {
  24730. var a = value[i];
  24731. if (a === 'e') {
  24732. nibbles += value[++i] === '-' ? 'c' : 'b';
  24733. } else if (a === '.') {
  24734. nibbles += 'a';
  24735. } else if (a === '-') {
  24736. nibbles += 'e';
  24737. } else {
  24738. nibbles += a;
  24739. }
  24740. }
  24741. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  24742. var out = [30];
  24743. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  24744. out.push(parseInt(nibbles.substr(i, 2), 16));
  24745. }
  24746. return out;
  24747. },
  24748. encodeInteger: function CFFCompiler_encodeInteger(value) {
  24749. var code;
  24750. if (value >= -107 && value <= 107) {
  24751. code = [value + 139];
  24752. } else if (value >= 108 && value <= 1131) {
  24753. value = [value - 108];
  24754. code = [(value >> 8) + 247, value & 0xFF];
  24755. } else if (value >= -1131 && value <= -108) {
  24756. value = -value - 108;
  24757. code = [(value >> 8) + 251, value & 0xFF];
  24758. } else if (value >= -32768 && value <= 32767) {
  24759. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  24760. } else {
  24761. code = [0x1d,
  24762. (value >> 24) & 0xFF,
  24763. (value >> 16) & 0xFF,
  24764. (value >> 8) & 0xFF,
  24765. value & 0xFF];
  24766. }
  24767. return code;
  24768. },
  24769. compileHeader: function CFFCompiler_compileHeader(header) {
  24770. return [
  24771. header.major,
  24772. header.minor,
  24773. header.hdrSize,
  24774. header.offSize
  24775. ];
  24776. },
  24777. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  24778. var nameIndex = new CFFIndex();
  24779. for (var i = 0, ii = names.length; i < ii; ++i) {
  24780. nameIndex.add(stringToBytes(names[i]));
  24781. }
  24782. return this.compileIndex(nameIndex);
  24783. },
  24784. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  24785. length,
  24786. removeCidKeys) {
  24787. var fontDictTrackers = [];
  24788. var fdArrayIndex = new CFFIndex();
  24789. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  24790. var fontDict = dicts[i];
  24791. if (removeCidKeys) {
  24792. fontDict.removeByName('CIDFontVersion');
  24793. fontDict.removeByName('CIDFontRevision');
  24794. fontDict.removeByName('CIDFontType');
  24795. fontDict.removeByName('CIDCount');
  24796. fontDict.removeByName('UIDBase');
  24797. }
  24798. var fontDictTracker = new CFFOffsetTracker();
  24799. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  24800. fontDictTrackers.push(fontDictTracker);
  24801. fdArrayIndex.add(fontDictData);
  24802. fontDictTracker.offset(length);
  24803. }
  24804. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  24805. return {
  24806. trackers: fontDictTrackers,
  24807. output: fdArrayIndex
  24808. };
  24809. },
  24810. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  24811. trackers,
  24812. output) {
  24813. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  24814. var fontDict = dicts[i];
  24815. assert(fontDict.privateDict && fontDict.hasName('Private'),
  24816. 'There must be an private dictionary.');
  24817. var privateDict = fontDict.privateDict;
  24818. var privateDictTracker = new CFFOffsetTracker();
  24819. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  24820. var outputLength = output.length;
  24821. privateDictTracker.offset(outputLength);
  24822. if (!privateDictData.length) {
  24823. // The private dictionary was empty, set the output length to zero to
  24824. // ensure the offset length isn't out of bounds in the eyes of the
  24825. // sanitizer.
  24826. outputLength = 0;
  24827. }
  24828. trackers[i].setEntryLocation('Private',
  24829. [privateDictData.length, outputLength],
  24830. output);
  24831. output.add(privateDictData);
  24832. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  24833. var subrs = this.compileIndex(privateDict.subrsIndex);
  24834. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  24835. output);
  24836. output.add(subrs);
  24837. }
  24838. }
  24839. },
  24840. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  24841. var out = [];
  24842. // The dictionary keys must be in a certain order.
  24843. var order = dict.order;
  24844. for (var i = 0; i < order.length; ++i) {
  24845. var key = order[i];
  24846. if (!(key in dict.values)) {
  24847. continue;
  24848. }
  24849. var values = dict.values[key];
  24850. var types = dict.types[key];
  24851. if (!isArray(types)) {
  24852. types = [types];
  24853. }
  24854. if (!isArray(values)) {
  24855. values = [values];
  24856. }
  24857. // Remove any empty dict values.
  24858. if (values.length === 0) {
  24859. continue;
  24860. }
  24861. for (var j = 0, jj = types.length; j < jj; ++j) {
  24862. var type = types[j];
  24863. var value = values[j];
  24864. switch (type) {
  24865. case 'num':
  24866. case 'sid':
  24867. out = out.concat(this.encodeNumber(value));
  24868. break;
  24869. case 'offset':
  24870. // For offsets we just insert a 32bit integer so we don't have to
  24871. // deal with figuring out the length of the offset when it gets
  24872. // replaced later on by the compiler.
  24873. var name = dict.keyToNameMap[key];
  24874. // Some offsets have the offset and the length, so just record the
  24875. // position of the first one.
  24876. if (!offsetTracker.isTracking(name)) {
  24877. offsetTracker.track(name, out.length);
  24878. }
  24879. out = out.concat([0x1d, 0, 0, 0, 0]);
  24880. break;
  24881. case 'array':
  24882. case 'delta':
  24883. out = out.concat(this.encodeNumber(value));
  24884. for (var k = 1, kk = values.length; k < kk; ++k) {
  24885. out = out.concat(this.encodeNumber(values[k]));
  24886. }
  24887. break;
  24888. default:
  24889. error('Unknown data type of ' + type);
  24890. break;
  24891. }
  24892. }
  24893. out = out.concat(dict.opcodes[key]);
  24894. }
  24895. return out;
  24896. },
  24897. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  24898. var stringIndex = new CFFIndex();
  24899. for (var i = 0, ii = strings.length; i < ii; ++i) {
  24900. stringIndex.add(stringToBytes(strings[i]));
  24901. }
  24902. return this.compileIndex(stringIndex);
  24903. },
  24904. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  24905. var globalSubrIndex = this.cff.globalSubrIndex;
  24906. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  24907. },
  24908. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  24909. return this.compileIndex(charStrings);
  24910. },
  24911. compileCharset: function CFFCompiler_compileCharset(charset) {
  24912. return this.compileTypedArray(charset.raw);
  24913. },
  24914. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  24915. return this.compileTypedArray(encoding.raw);
  24916. },
  24917. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  24918. return this.compileTypedArray(fdSelect);
  24919. },
  24920. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  24921. var out = [];
  24922. for (var i = 0, ii = data.length; i < ii; ++i) {
  24923. out[i] = data[i];
  24924. }
  24925. return out;
  24926. },
  24927. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  24928. trackers = trackers || [];
  24929. var objects = index.objects;
  24930. // First 2 bytes contains the number of objects contained into this index
  24931. var count = objects.length;
  24932. // If there is no object, just create an index. This technically
  24933. // should just be [0, 0] but OTS has an issue with that.
  24934. if (count === 0) {
  24935. return [0, 0, 0];
  24936. }
  24937. var data = [(count >> 8) & 0xFF, count & 0xff];
  24938. var lastOffset = 1, i;
  24939. for (i = 0; i < count; ++i) {
  24940. lastOffset += objects[i].length;
  24941. }
  24942. var offsetSize;
  24943. if (lastOffset < 0x100) {
  24944. offsetSize = 1;
  24945. } else if (lastOffset < 0x10000) {
  24946. offsetSize = 2;
  24947. } else if (lastOffset < 0x1000000) {
  24948. offsetSize = 3;
  24949. } else {
  24950. offsetSize = 4;
  24951. }
  24952. // Next byte contains the offset size use to reference object in the file
  24953. data.push(offsetSize);
  24954. // Add another offset after this one because we need a new offset
  24955. var relativeOffset = 1;
  24956. for (i = 0; i < count + 1; i++) {
  24957. if (offsetSize === 1) {
  24958. data.push(relativeOffset & 0xFF);
  24959. } else if (offsetSize === 2) {
  24960. data.push((relativeOffset >> 8) & 0xFF,
  24961. relativeOffset & 0xFF);
  24962. } else if (offsetSize === 3) {
  24963. data.push((relativeOffset >> 16) & 0xFF,
  24964. (relativeOffset >> 8) & 0xFF,
  24965. relativeOffset & 0xFF);
  24966. } else {
  24967. data.push((relativeOffset >>> 24) & 0xFF,
  24968. (relativeOffset >> 16) & 0xFF,
  24969. (relativeOffset >> 8) & 0xFF,
  24970. relativeOffset & 0xFF);
  24971. }
  24972. if (objects[i]) {
  24973. relativeOffset += objects[i].length;
  24974. }
  24975. }
  24976. for (i = 0; i < count; i++) {
  24977. // Notify the tracker where the object will be offset in the data.
  24978. if (trackers[i]) {
  24979. trackers[i].offset(data.length);
  24980. }
  24981. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  24982. data.push(objects[i][j]);
  24983. }
  24984. }
  24985. return data;
  24986. }
  24987. };
  24988. return CFFCompiler;
  24989. })();
  24990. // Workaround for seac on Windows.
  24991. (function checkSeacSupport() {
  24992. if (/Windows/.test(navigator.userAgent)) {
  24993. SEAC_ANALYSIS_ENABLED = true;
  24994. }
  24995. })();
  24996. // Workaround for Private Use Area characters in Chrome on Windows
  24997. // http://code.google.com/p/chromium/issues/detail?id=122465
  24998. // https://github.com/mozilla/pdf.js/issues/1689
  24999. (function checkChromeWindows() {
  25000. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25001. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25002. }
  25003. })();
  25004. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25005. function getLong(data, offset) {
  25006. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25007. (data[offset + 2] << 8) | data[offset + 3];
  25008. }
  25009. function getUshort(data, offset) {
  25010. return (data[offset] << 8) | data[offset + 1];
  25011. }
  25012. function parseCmap(data, start, end) {
  25013. var offset = (getUshort(data, start + 2) === 1 ?
  25014. getLong(data, start + 8) : getLong(data, start + 16));
  25015. var format = getUshort(data, start + offset);
  25016. var length, ranges, p, i;
  25017. if (format === 4) {
  25018. length = getUshort(data, start + offset + 2);
  25019. var segCount = getUshort(data, start + offset + 6) >> 1;
  25020. p = start + offset + 14;
  25021. ranges = [];
  25022. for (i = 0; i < segCount; i++, p += 2) {
  25023. ranges[i] = {end: getUshort(data, p)};
  25024. }
  25025. p += 2;
  25026. for (i = 0; i < segCount; i++, p += 2) {
  25027. ranges[i].start = getUshort(data, p);
  25028. }
  25029. for (i = 0; i < segCount; i++, p += 2) {
  25030. ranges[i].idDelta = getUshort(data, p);
  25031. }
  25032. for (i = 0; i < segCount; i++, p += 2) {
  25033. var idOffset = getUshort(data, p);
  25034. if (idOffset === 0) {
  25035. continue;
  25036. }
  25037. ranges[i].ids = [];
  25038. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25039. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25040. idOffset += 2;
  25041. }
  25042. }
  25043. return ranges;
  25044. } else if (format === 12) {
  25045. length = getLong(data, start + offset + 4);
  25046. var groups = getLong(data, start + offset + 12);
  25047. p = start + offset + 16;
  25048. ranges = [];
  25049. for (i = 0; i < groups; i++) {
  25050. ranges.push({
  25051. start: getLong(data, p),
  25052. end: getLong(data, p + 4),
  25053. idDelta: getLong(data, p + 8) - getLong(data, p)
  25054. });
  25055. p += 12;
  25056. }
  25057. return ranges;
  25058. }
  25059. error('not supported cmap: ' + format);
  25060. }
  25061. function parseCff(data, start, end) {
  25062. var properties = {};
  25063. var parser = new CFFParser(new Stream(data, start, end - start),
  25064. properties);
  25065. var cff = parser.parse();
  25066. return {
  25067. glyphs: cff.charStrings.objects,
  25068. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25069. cff.topDict.privateDict.subrsIndex.objects),
  25070. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25071. };
  25072. }
  25073. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25074. var itemSize, itemDecode;
  25075. if (isGlyphLocationsLong) {
  25076. itemSize = 4;
  25077. itemDecode = function fontItemDecodeLong(data, offset) {
  25078. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25079. (data[offset + 2] << 8) | data[offset + 3];
  25080. };
  25081. } else {
  25082. itemSize = 2;
  25083. itemDecode = function fontItemDecode(data, offset) {
  25084. return (data[offset] << 9) | (data[offset + 1] << 1);
  25085. };
  25086. }
  25087. var glyphs = [];
  25088. var startOffset = itemDecode(loca, 0);
  25089. for (var j = itemSize; j < loca.length; j += itemSize) {
  25090. var endOffset = itemDecode(loca, j);
  25091. glyphs.push(glyf.subarray(startOffset, endOffset));
  25092. startOffset = endOffset;
  25093. }
  25094. return glyphs;
  25095. }
  25096. function lookupCmap(ranges, unicode) {
  25097. var code = unicode.charCodeAt(0);
  25098. var l = 0, r = ranges.length - 1;
  25099. while (l < r) {
  25100. var c = (l + r + 1) >> 1;
  25101. if (code < ranges[c].start) {
  25102. r = c - 1;
  25103. } else {
  25104. l = c;
  25105. }
  25106. }
  25107. if (ranges[l].start <= code && code <= ranges[l].end) {
  25108. return (ranges[l].idDelta + (ranges[l].ids ?
  25109. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25110. }
  25111. return 0;
  25112. }
  25113. function compileGlyf(code, js, font) {
  25114. function moveTo(x, y) {
  25115. js.push('c.moveTo(' + x + ',' + y + ');');
  25116. }
  25117. function lineTo(x, y) {
  25118. js.push('c.lineTo(' + x + ',' + y + ');');
  25119. }
  25120. function quadraticCurveTo(xa, ya, x, y) {
  25121. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25122. x + ',' + y + ');');
  25123. }
  25124. var i = 0;
  25125. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25126. var flags;
  25127. var x = 0, y = 0;
  25128. i += 10;
  25129. if (numberOfContours < 0) {
  25130. // composite glyph
  25131. do {
  25132. flags = (code[i] << 8) | code[i + 1];
  25133. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25134. i += 4;
  25135. var arg1, arg2;
  25136. if ((flags & 0x01)) {
  25137. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25138. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25139. i += 4;
  25140. } else {
  25141. arg1 = code[i++]; arg2 = code[i++];
  25142. }
  25143. if ((flags & 0x02)) {
  25144. x = arg1;
  25145. y = arg2;
  25146. } else {
  25147. x = 0; y = 0; // TODO "they are points" ?
  25148. }
  25149. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25150. if ((flags & 0x08)) {
  25151. scaleX =
  25152. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25153. i += 2;
  25154. } else if ((flags & 0x40)) {
  25155. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25156. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25157. i += 4;
  25158. } else if ((flags & 0x80)) {
  25159. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25160. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25161. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25162. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25163. i += 8;
  25164. }
  25165. var subglyph = font.glyphs[glyphIndex];
  25166. if (subglyph) {
  25167. js.push('c.save();');
  25168. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25169. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25170. compileGlyf(subglyph, js, font);
  25171. js.push('c.restore();');
  25172. }
  25173. } while ((flags & 0x20));
  25174. } else {
  25175. // simple glyph
  25176. var endPtsOfContours = [];
  25177. var j, jj;
  25178. for (j = 0; j < numberOfContours; j++) {
  25179. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25180. i += 2;
  25181. }
  25182. var instructionLength = (code[i] << 8) | code[i + 1];
  25183. i += 2 + instructionLength; // skipping the instructions
  25184. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25185. var points = [];
  25186. while (points.length < numberOfPoints) {
  25187. flags = code[i++];
  25188. var repeat = 1;
  25189. if ((flags & 0x08)) {
  25190. repeat += code[i++];
  25191. }
  25192. while (repeat-- > 0) {
  25193. points.push({flags: flags});
  25194. }
  25195. }
  25196. for (j = 0; j < numberOfPoints; j++) {
  25197. switch (points[j].flags & 0x12) {
  25198. case 0x00:
  25199. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25200. i += 2;
  25201. break;
  25202. case 0x02:
  25203. x -= code[i++];
  25204. break;
  25205. case 0x12:
  25206. x += code[i++];
  25207. break;
  25208. }
  25209. points[j].x = x;
  25210. }
  25211. for (j = 0; j < numberOfPoints; j++) {
  25212. switch (points[j].flags & 0x24) {
  25213. case 0x00:
  25214. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25215. i += 2;
  25216. break;
  25217. case 0x04:
  25218. y -= code[i++];
  25219. break;
  25220. case 0x24:
  25221. y += code[i++];
  25222. break;
  25223. }
  25224. points[j].y = y;
  25225. }
  25226. var startPoint = 0;
  25227. for (i = 0; i < numberOfContours; i++) {
  25228. var endPoint = endPtsOfContours[i];
  25229. // contours might have implicit points, which is located in the middle
  25230. // between two neighboring off-curve points
  25231. var contour = points.slice(startPoint, endPoint + 1);
  25232. if ((contour[0].flags & 1)) {
  25233. contour.push(contour[0]); // using start point at the contour end
  25234. } else if ((contour[contour.length - 1].flags & 1)) {
  25235. // first is off-curve point, trying to use one from the end
  25236. contour.unshift(contour[contour.length - 1]);
  25237. } else {
  25238. // start and end are off-curve points, creating implicit one
  25239. var p = {
  25240. flags: 1,
  25241. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25242. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25243. };
  25244. contour.unshift(p);
  25245. contour.push(p);
  25246. }
  25247. moveTo(contour[0].x, contour[0].y);
  25248. for (j = 1, jj = contour.length; j < jj; j++) {
  25249. if ((contour[j].flags & 1)) {
  25250. lineTo(contour[j].x, contour[j].y);
  25251. } else if ((contour[j + 1].flags & 1)){
  25252. quadraticCurveTo(contour[j].x, contour[j].y,
  25253. contour[j + 1].x, contour[j + 1].y);
  25254. j++;
  25255. } else {
  25256. quadraticCurveTo(contour[j].x, contour[j].y,
  25257. (contour[j].x + contour[j + 1].x) / 2,
  25258. (contour[j].y + contour[j + 1].y) / 2);
  25259. }
  25260. }
  25261. startPoint = endPoint + 1;
  25262. }
  25263. }
  25264. }
  25265. function compileCharString(code, js, font) {
  25266. var stack = [];
  25267. var x = 0, y = 0;
  25268. var stems = 0;
  25269. function moveTo(x, y) {
  25270. js.push('c.moveTo(' + x + ',' + y + ');');
  25271. }
  25272. function lineTo(x, y) {
  25273. js.push('c.lineTo(' + x + ',' + y + ');');
  25274. }
  25275. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25276. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25277. x + ',' + y + ');');
  25278. }
  25279. function parse(code) {
  25280. var i = 0;
  25281. while (i < code.length) {
  25282. var stackClean = false;
  25283. var v = code[i++];
  25284. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25285. switch (v) {
  25286. case 1: // hstem
  25287. stems += stack.length >> 1;
  25288. stackClean = true;
  25289. break;
  25290. case 3: // vstem
  25291. stems += stack.length >> 1;
  25292. stackClean = true;
  25293. break;
  25294. case 4: // vmoveto
  25295. y += stack.pop();
  25296. moveTo(x, y);
  25297. stackClean = true;
  25298. break;
  25299. case 5: // rlineto
  25300. while (stack.length > 0) {
  25301. x += stack.shift();
  25302. y += stack.shift();
  25303. lineTo(x, y);
  25304. }
  25305. break;
  25306. case 6: // hlineto
  25307. while (stack.length > 0) {
  25308. x += stack.shift();
  25309. lineTo(x, y);
  25310. if (stack.length === 0) {
  25311. break;
  25312. }
  25313. y += stack.shift();
  25314. lineTo(x, y);
  25315. }
  25316. break;
  25317. case 7: // vlineto
  25318. while (stack.length > 0) {
  25319. y += stack.shift();
  25320. lineTo(x, y);
  25321. if (stack.length === 0) {
  25322. break;
  25323. }
  25324. x += stack.shift();
  25325. lineTo(x, y);
  25326. }
  25327. break;
  25328. case 8: // rrcurveto
  25329. while (stack.length > 0) {
  25330. xa = x + stack.shift(); ya = y + stack.shift();
  25331. xb = xa + stack.shift(); yb = ya + stack.shift();
  25332. x = xb + stack.shift(); y = yb + stack.shift();
  25333. bezierCurveTo(xa, ya, xb, yb, x, y);
  25334. }
  25335. break;
  25336. case 10: // callsubr
  25337. n = stack.pop() + font.subrsBias;
  25338. subrCode = font.subrs[n];
  25339. if (subrCode) {
  25340. parse(subrCode);
  25341. }
  25342. break;
  25343. case 11: // return
  25344. return;
  25345. case 12:
  25346. v = code[i++];
  25347. switch (v) {
  25348. case 34: // flex
  25349. xa = x + stack.shift();
  25350. xb = xa + stack.shift(); y1 = y + stack.shift();
  25351. x = xb + stack.shift();
  25352. bezierCurveTo(xa, y, xb, y1, x, y1);
  25353. xa = x + stack.shift();
  25354. xb = xa + stack.shift();
  25355. x = xb + stack.shift();
  25356. bezierCurveTo(xa, y1, xb, y, x, y);
  25357. break;
  25358. case 35: // flex
  25359. xa = x + stack.shift(); ya = y + stack.shift();
  25360. xb = xa + stack.shift(); yb = ya + stack.shift();
  25361. x = xb + stack.shift(); y = yb + stack.shift();
  25362. bezierCurveTo(xa, ya, xb, yb, x, y);
  25363. xa = x + stack.shift(); ya = y + stack.shift();
  25364. xb = xa + stack.shift(); yb = ya + stack.shift();
  25365. x = xb + stack.shift(); y = yb + stack.shift();
  25366. bezierCurveTo(xa, ya, xb, yb, x, y);
  25367. stack.pop(); // fd
  25368. break;
  25369. case 36: // hflex1
  25370. xa = x + stack.shift(); y1 = y + stack.shift();
  25371. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25372. x = xb + stack.shift();
  25373. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25374. xa = x + stack.shift();
  25375. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25376. x = xb + stack.shift();
  25377. bezierCurveTo(xa, y2, xb, y3, x, y);
  25378. break;
  25379. case 37: // flex1
  25380. var x0 = x, y0 = y;
  25381. xa = x + stack.shift(); ya = y + stack.shift();
  25382. xb = xa + stack.shift(); yb = ya + stack.shift();
  25383. x = xb + stack.shift(); y = yb + stack.shift();
  25384. bezierCurveTo(xa, ya, xb, yb, x, y);
  25385. xa = x + stack.shift(); ya = y + stack.shift();
  25386. xb = xa + stack.shift(); yb = ya + stack.shift();
  25387. x = xb; y = yb;
  25388. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25389. x += stack.shift();
  25390. } else {
  25391. y += stack.shift();
  25392. }
  25393. bezierCurveTo(xa, ya, xb, yb, x, y);
  25394. break;
  25395. default:
  25396. error('unknown operator: 12 ' + v);
  25397. }
  25398. break;
  25399. case 14: // endchar
  25400. if (stack.length >= 4) {
  25401. var achar = stack.pop();
  25402. var bchar = stack.pop();
  25403. y = stack.pop();
  25404. x = stack.pop();
  25405. js.push('c.save();');
  25406. js.push('c.translate('+ x + ',' + y + ');');
  25407. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25408. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25409. compileCharString(font.glyphs[gid], js, font);
  25410. js.push('c.restore();');
  25411. gid = lookupCmap(font.cmap, String.fromCharCode(
  25412. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25413. compileCharString(font.glyphs[gid], js, font);
  25414. }
  25415. return;
  25416. case 18: // hstemhm
  25417. stems += stack.length >> 1;
  25418. stackClean = true;
  25419. break;
  25420. case 19: // hintmask
  25421. stems += stack.length >> 1;
  25422. i += (stems + 7) >> 3;
  25423. stackClean = true;
  25424. break;
  25425. case 20: // cntrmask
  25426. stems += stack.length >> 1;
  25427. i += (stems + 7) >> 3;
  25428. stackClean = true;
  25429. break;
  25430. case 21: // rmoveto
  25431. y += stack.pop();
  25432. x += stack.pop();
  25433. moveTo(x, y);
  25434. stackClean = true;
  25435. break;
  25436. case 22: // hmoveto
  25437. x += stack.pop();
  25438. moveTo(x, y);
  25439. stackClean = true;
  25440. break;
  25441. case 23: // vstemhm
  25442. stems += stack.length >> 1;
  25443. stackClean = true;
  25444. break;
  25445. case 24: // rcurveline
  25446. while (stack.length > 2) {
  25447. xa = x + stack.shift(); ya = y + stack.shift();
  25448. xb = xa + stack.shift(); yb = ya + stack.shift();
  25449. x = xb + stack.shift(); y = yb + stack.shift();
  25450. bezierCurveTo(xa, ya, xb, yb, x, y);
  25451. }
  25452. x += stack.shift();
  25453. y += stack.shift();
  25454. lineTo(x, y);
  25455. break;
  25456. case 25: // rlinecurve
  25457. while (stack.length > 6) {
  25458. x += stack.shift();
  25459. y += stack.shift();
  25460. lineTo(x, y);
  25461. }
  25462. xa = x + stack.shift(); ya = y + stack.shift();
  25463. xb = xa + stack.shift(); yb = ya + stack.shift();
  25464. x = xb + stack.shift(); y = yb + stack.shift();
  25465. bezierCurveTo(xa, ya, xb, yb, x, y);
  25466. break;
  25467. case 26: // vvcurveto
  25468. if (stack.length % 2) {
  25469. x += stack.shift();
  25470. }
  25471. while (stack.length > 0) {
  25472. xa = x; ya = y + stack.shift();
  25473. xb = xa + stack.shift(); yb = ya + stack.shift();
  25474. x = xb; y = yb + stack.shift();
  25475. bezierCurveTo(xa, ya, xb, yb, x, y);
  25476. }
  25477. break;
  25478. case 27: // hhcurveto
  25479. if (stack.length % 2) {
  25480. y += stack.shift();
  25481. }
  25482. while (stack.length > 0) {
  25483. xa = x + stack.shift(); ya = y;
  25484. xb = xa + stack.shift(); yb = ya + stack.shift();
  25485. x = xb + stack.shift(); y = yb;
  25486. bezierCurveTo(xa, ya, xb, yb, x, y);
  25487. }
  25488. break;
  25489. case 28:
  25490. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25491. i += 2;
  25492. break;
  25493. case 29: // callgsubr
  25494. n = stack.pop() + font.gsubrsBias;
  25495. subrCode = font.gsubrs[n];
  25496. if (subrCode) {
  25497. parse(subrCode);
  25498. }
  25499. break;
  25500. case 30: // vhcurveto
  25501. while (stack.length > 0) {
  25502. xa = x; ya = y + stack.shift();
  25503. xb = xa + stack.shift(); yb = ya + stack.shift();
  25504. x = xb + stack.shift();
  25505. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25506. bezierCurveTo(xa, ya, xb, yb, x, y);
  25507. if (stack.length === 0) {
  25508. break;
  25509. }
  25510. xa = x + stack.shift(); ya = y;
  25511. xb = xa + stack.shift(); yb = ya + stack.shift();
  25512. y = yb + stack.shift();
  25513. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25514. bezierCurveTo(xa, ya, xb, yb, x, y);
  25515. }
  25516. break;
  25517. case 31: // hvcurveto
  25518. while (stack.length > 0) {
  25519. xa = x + stack.shift(); ya = y;
  25520. xb = xa + stack.shift(); yb = ya + stack.shift();
  25521. y = yb + stack.shift();
  25522. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25523. bezierCurveTo(xa, ya, xb, yb, x, y);
  25524. if (stack.length === 0) {
  25525. break;
  25526. }
  25527. xa = x; ya = y + stack.shift();
  25528. xb = xa + stack.shift(); yb = ya + stack.shift();
  25529. x = xb + stack.shift();
  25530. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25531. bezierCurveTo(xa, ya, xb, yb, x, y);
  25532. }
  25533. break;
  25534. default:
  25535. if (v < 32) {
  25536. error('unknown operator: ' + v);
  25537. }
  25538. if (v < 247) {
  25539. stack.push(v - 139);
  25540. } else if (v < 251) {
  25541. stack.push((v - 247) * 256 + code[i++] + 108);
  25542. } else if (v < 255) {
  25543. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25544. } else {
  25545. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25546. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25547. i += 4;
  25548. }
  25549. break;
  25550. }
  25551. if (stackClean) {
  25552. stack.length = 0;
  25553. }
  25554. }
  25555. }
  25556. parse(code);
  25557. }
  25558. var noop = '';
  25559. function CompiledFont(fontMatrix) {
  25560. this.compiledGlyphs = {};
  25561. this.fontMatrix = fontMatrix;
  25562. }
  25563. CompiledFont.prototype = {
  25564. getPathJs: function (unicode) {
  25565. var gid = lookupCmap(this.cmap, unicode);
  25566. var fn = this.compiledGlyphs[gid];
  25567. if (!fn) {
  25568. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25569. }
  25570. return fn;
  25571. },
  25572. compileGlyph: function (code) {
  25573. if (!code || code.length === 0 || code[0] === 14) {
  25574. return noop;
  25575. }
  25576. var js = [];
  25577. js.push('c.save();');
  25578. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25579. js.push('c.scale(size, -size);');
  25580. this.compileGlyphImpl(code, js);
  25581. js.push('c.restore();');
  25582. return js.join('\n');
  25583. },
  25584. compileGlyphImpl: function () {
  25585. error('Children classes should implement this.');
  25586. },
  25587. hasBuiltPath: function (unicode) {
  25588. var gid = lookupCmap(this.cmap, unicode);
  25589. return gid in this.compiledGlyphs;
  25590. }
  25591. };
  25592. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25593. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25594. CompiledFont.call(this, fontMatrix);
  25595. this.glyphs = glyphs;
  25596. this.cmap = cmap;
  25597. this.compiledGlyphs = [];
  25598. }
  25599. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25600. compileGlyphImpl: function (code, js) {
  25601. compileGlyf(code, js, this);
  25602. }
  25603. });
  25604. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25605. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25606. CompiledFont.call(this, fontMatrix);
  25607. this.glyphs = cffInfo.glyphs;
  25608. this.gsubrs = cffInfo.gsubrs || [];
  25609. this.subrs = cffInfo.subrs || [];
  25610. this.cmap = cmap;
  25611. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25612. this.compiledGlyphs = [];
  25613. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25614. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25615. this.subrsBias = (this.subrs.length < 1240 ?
  25616. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25617. }
  25618. Util.inherit(Type2Compiled, CompiledFont, {
  25619. compileGlyphImpl: function (code, js) {
  25620. compileCharString(code, js, this);
  25621. }
  25622. });
  25623. return {
  25624. create: function FontRendererFactory_create(font) {
  25625. var data = new Uint8Array(font.data);
  25626. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25627. var numTables = getUshort(data, 4);
  25628. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25629. var tag = bytesToString(data.subarray(p, p + 4));
  25630. var offset = getLong(data, p + 8);
  25631. var length = getLong(data, p + 12);
  25632. switch (tag) {
  25633. case 'cmap':
  25634. cmap = parseCmap(data, offset, offset + length);
  25635. break;
  25636. case 'glyf':
  25637. glyf = data.subarray(offset, offset + length);
  25638. break;
  25639. case 'loca':
  25640. loca = data.subarray(offset, offset + length);
  25641. break;
  25642. case 'head':
  25643. unitsPerEm = getUshort(data, offset + 18);
  25644. indexToLocFormat = getUshort(data, offset + 50);
  25645. break;
  25646. case 'CFF ':
  25647. cff = parseCff(data, offset, offset + length);
  25648. break;
  25649. }
  25650. }
  25651. if (glyf) {
  25652. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25653. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25654. return new TrueTypeCompiled(
  25655. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25656. } else {
  25657. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25658. }
  25659. }
  25660. };
  25661. })();
  25662. var GlyphsUnicode = {
  25663. A: 0x0041,
  25664. AE: 0x00C6,
  25665. AEacute: 0x01FC,
  25666. AEmacron: 0x01E2,
  25667. AEsmall: 0xF7E6,
  25668. Aacute: 0x00C1,
  25669. Aacutesmall: 0xF7E1,
  25670. Abreve: 0x0102,
  25671. Abreveacute: 0x1EAE,
  25672. Abrevecyrillic: 0x04D0,
  25673. Abrevedotbelow: 0x1EB6,
  25674. Abrevegrave: 0x1EB0,
  25675. Abrevehookabove: 0x1EB2,
  25676. Abrevetilde: 0x1EB4,
  25677. Acaron: 0x01CD,
  25678. Acircle: 0x24B6,
  25679. Acircumflex: 0x00C2,
  25680. Acircumflexacute: 0x1EA4,
  25681. Acircumflexdotbelow: 0x1EAC,
  25682. Acircumflexgrave: 0x1EA6,
  25683. Acircumflexhookabove: 0x1EA8,
  25684. Acircumflexsmall: 0xF7E2,
  25685. Acircumflextilde: 0x1EAA,
  25686. Acute: 0xF6C9,
  25687. Acutesmall: 0xF7B4,
  25688. Acyrillic: 0x0410,
  25689. Adblgrave: 0x0200,
  25690. Adieresis: 0x00C4,
  25691. Adieresiscyrillic: 0x04D2,
  25692. Adieresismacron: 0x01DE,
  25693. Adieresissmall: 0xF7E4,
  25694. Adotbelow: 0x1EA0,
  25695. Adotmacron: 0x01E0,
  25696. Agrave: 0x00C0,
  25697. Agravesmall: 0xF7E0,
  25698. Ahookabove: 0x1EA2,
  25699. Aiecyrillic: 0x04D4,
  25700. Ainvertedbreve: 0x0202,
  25701. Alpha: 0x0391,
  25702. Alphatonos: 0x0386,
  25703. Amacron: 0x0100,
  25704. Amonospace: 0xFF21,
  25705. Aogonek: 0x0104,
  25706. Aring: 0x00C5,
  25707. Aringacute: 0x01FA,
  25708. Aringbelow: 0x1E00,
  25709. Aringsmall: 0xF7E5,
  25710. Asmall: 0xF761,
  25711. Atilde: 0x00C3,
  25712. Atildesmall: 0xF7E3,
  25713. Aybarmenian: 0x0531,
  25714. B: 0x0042,
  25715. Bcircle: 0x24B7,
  25716. Bdotaccent: 0x1E02,
  25717. Bdotbelow: 0x1E04,
  25718. Becyrillic: 0x0411,
  25719. Benarmenian: 0x0532,
  25720. Beta: 0x0392,
  25721. Bhook: 0x0181,
  25722. Blinebelow: 0x1E06,
  25723. Bmonospace: 0xFF22,
  25724. Brevesmall: 0xF6F4,
  25725. Bsmall: 0xF762,
  25726. Btopbar: 0x0182,
  25727. C: 0x0043,
  25728. Caarmenian: 0x053E,
  25729. Cacute: 0x0106,
  25730. Caron: 0xF6CA,
  25731. Caronsmall: 0xF6F5,
  25732. Ccaron: 0x010C,
  25733. Ccedilla: 0x00C7,
  25734. Ccedillaacute: 0x1E08,
  25735. Ccedillasmall: 0xF7E7,
  25736. Ccircle: 0x24B8,
  25737. Ccircumflex: 0x0108,
  25738. Cdot: 0x010A,
  25739. Cdotaccent: 0x010A,
  25740. Cedillasmall: 0xF7B8,
  25741. Chaarmenian: 0x0549,
  25742. Cheabkhasiancyrillic: 0x04BC,
  25743. Checyrillic: 0x0427,
  25744. Chedescenderabkhasiancyrillic: 0x04BE,
  25745. Chedescendercyrillic: 0x04B6,
  25746. Chedieresiscyrillic: 0x04F4,
  25747. Cheharmenian: 0x0543,
  25748. Chekhakassiancyrillic: 0x04CB,
  25749. Cheverticalstrokecyrillic: 0x04B8,
  25750. Chi: 0x03A7,
  25751. Chook: 0x0187,
  25752. Circumflexsmall: 0xF6F6,
  25753. Cmonospace: 0xFF23,
  25754. Coarmenian: 0x0551,
  25755. Csmall: 0xF763,
  25756. D: 0x0044,
  25757. DZ: 0x01F1,
  25758. DZcaron: 0x01C4,
  25759. Daarmenian: 0x0534,
  25760. Dafrican: 0x0189,
  25761. Dcaron: 0x010E,
  25762. Dcedilla: 0x1E10,
  25763. Dcircle: 0x24B9,
  25764. Dcircumflexbelow: 0x1E12,
  25765. Dcroat: 0x0110,
  25766. Ddotaccent: 0x1E0A,
  25767. Ddotbelow: 0x1E0C,
  25768. Decyrillic: 0x0414,
  25769. Deicoptic: 0x03EE,
  25770. Delta: 0x2206,
  25771. Deltagreek: 0x0394,
  25772. Dhook: 0x018A,
  25773. Dieresis: 0xF6CB,
  25774. DieresisAcute: 0xF6CC,
  25775. DieresisGrave: 0xF6CD,
  25776. Dieresissmall: 0xF7A8,
  25777. Digammagreek: 0x03DC,
  25778. Djecyrillic: 0x0402,
  25779. Dlinebelow: 0x1E0E,
  25780. Dmonospace: 0xFF24,
  25781. Dotaccentsmall: 0xF6F7,
  25782. Dslash: 0x0110,
  25783. Dsmall: 0xF764,
  25784. Dtopbar: 0x018B,
  25785. Dz: 0x01F2,
  25786. Dzcaron: 0x01C5,
  25787. Dzeabkhasiancyrillic: 0x04E0,
  25788. Dzecyrillic: 0x0405,
  25789. Dzhecyrillic: 0x040F,
  25790. E: 0x0045,
  25791. Eacute: 0x00C9,
  25792. Eacutesmall: 0xF7E9,
  25793. Ebreve: 0x0114,
  25794. Ecaron: 0x011A,
  25795. Ecedillabreve: 0x1E1C,
  25796. Echarmenian: 0x0535,
  25797. Ecircle: 0x24BA,
  25798. Ecircumflex: 0x00CA,
  25799. Ecircumflexacute: 0x1EBE,
  25800. Ecircumflexbelow: 0x1E18,
  25801. Ecircumflexdotbelow: 0x1EC6,
  25802. Ecircumflexgrave: 0x1EC0,
  25803. Ecircumflexhookabove: 0x1EC2,
  25804. Ecircumflexsmall: 0xF7EA,
  25805. Ecircumflextilde: 0x1EC4,
  25806. Ecyrillic: 0x0404,
  25807. Edblgrave: 0x0204,
  25808. Edieresis: 0x00CB,
  25809. Edieresissmall: 0xF7EB,
  25810. Edot: 0x0116,
  25811. Edotaccent: 0x0116,
  25812. Edotbelow: 0x1EB8,
  25813. Efcyrillic: 0x0424,
  25814. Egrave: 0x00C8,
  25815. Egravesmall: 0xF7E8,
  25816. Eharmenian: 0x0537,
  25817. Ehookabove: 0x1EBA,
  25818. Eightroman: 0x2167,
  25819. Einvertedbreve: 0x0206,
  25820. Eiotifiedcyrillic: 0x0464,
  25821. Elcyrillic: 0x041B,
  25822. Elevenroman: 0x216A,
  25823. Emacron: 0x0112,
  25824. Emacronacute: 0x1E16,
  25825. Emacrongrave: 0x1E14,
  25826. Emcyrillic: 0x041C,
  25827. Emonospace: 0xFF25,
  25828. Encyrillic: 0x041D,
  25829. Endescendercyrillic: 0x04A2,
  25830. Eng: 0x014A,
  25831. Enghecyrillic: 0x04A4,
  25832. Enhookcyrillic: 0x04C7,
  25833. Eogonek: 0x0118,
  25834. Eopen: 0x0190,
  25835. Epsilon: 0x0395,
  25836. Epsilontonos: 0x0388,
  25837. Ercyrillic: 0x0420,
  25838. Ereversed: 0x018E,
  25839. Ereversedcyrillic: 0x042D,
  25840. Escyrillic: 0x0421,
  25841. Esdescendercyrillic: 0x04AA,
  25842. Esh: 0x01A9,
  25843. Esmall: 0xF765,
  25844. Eta: 0x0397,
  25845. Etarmenian: 0x0538,
  25846. Etatonos: 0x0389,
  25847. Eth: 0x00D0,
  25848. Ethsmall: 0xF7F0,
  25849. Etilde: 0x1EBC,
  25850. Etildebelow: 0x1E1A,
  25851. Euro: 0x20AC,
  25852. Ezh: 0x01B7,
  25853. Ezhcaron: 0x01EE,
  25854. Ezhreversed: 0x01B8,
  25855. F: 0x0046,
  25856. Fcircle: 0x24BB,
  25857. Fdotaccent: 0x1E1E,
  25858. Feharmenian: 0x0556,
  25859. Feicoptic: 0x03E4,
  25860. Fhook: 0x0191,
  25861. Fitacyrillic: 0x0472,
  25862. Fiveroman: 0x2164,
  25863. Fmonospace: 0xFF26,
  25864. Fourroman: 0x2163,
  25865. Fsmall: 0xF766,
  25866. G: 0x0047,
  25867. GBsquare: 0x3387,
  25868. Gacute: 0x01F4,
  25869. Gamma: 0x0393,
  25870. Gammaafrican: 0x0194,
  25871. Gangiacoptic: 0x03EA,
  25872. Gbreve: 0x011E,
  25873. Gcaron: 0x01E6,
  25874. Gcedilla: 0x0122,
  25875. Gcircle: 0x24BC,
  25876. Gcircumflex: 0x011C,
  25877. Gcommaaccent: 0x0122,
  25878. Gdot: 0x0120,
  25879. Gdotaccent: 0x0120,
  25880. Gecyrillic: 0x0413,
  25881. Ghadarmenian: 0x0542,
  25882. Ghemiddlehookcyrillic: 0x0494,
  25883. Ghestrokecyrillic: 0x0492,
  25884. Gheupturncyrillic: 0x0490,
  25885. Ghook: 0x0193,
  25886. Gimarmenian: 0x0533,
  25887. Gjecyrillic: 0x0403,
  25888. Gmacron: 0x1E20,
  25889. Gmonospace: 0xFF27,
  25890. Grave: 0xF6CE,
  25891. Gravesmall: 0xF760,
  25892. Gsmall: 0xF767,
  25893. Gsmallhook: 0x029B,
  25894. Gstroke: 0x01E4,
  25895. H: 0x0048,
  25896. H18533: 0x25CF,
  25897. H18543: 0x25AA,
  25898. H18551: 0x25AB,
  25899. H22073: 0x25A1,
  25900. HPsquare: 0x33CB,
  25901. Haabkhasiancyrillic: 0x04A8,
  25902. Hadescendercyrillic: 0x04B2,
  25903. Hardsigncyrillic: 0x042A,
  25904. Hbar: 0x0126,
  25905. Hbrevebelow: 0x1E2A,
  25906. Hcedilla: 0x1E28,
  25907. Hcircle: 0x24BD,
  25908. Hcircumflex: 0x0124,
  25909. Hdieresis: 0x1E26,
  25910. Hdotaccent: 0x1E22,
  25911. Hdotbelow: 0x1E24,
  25912. Hmonospace: 0xFF28,
  25913. Hoarmenian: 0x0540,
  25914. Horicoptic: 0x03E8,
  25915. Hsmall: 0xF768,
  25916. Hungarumlaut: 0xF6CF,
  25917. Hungarumlautsmall: 0xF6F8,
  25918. Hzsquare: 0x3390,
  25919. I: 0x0049,
  25920. IAcyrillic: 0x042F,
  25921. IJ: 0x0132,
  25922. IUcyrillic: 0x042E,
  25923. Iacute: 0x00CD,
  25924. Iacutesmall: 0xF7ED,
  25925. Ibreve: 0x012C,
  25926. Icaron: 0x01CF,
  25927. Icircle: 0x24BE,
  25928. Icircumflex: 0x00CE,
  25929. Icircumflexsmall: 0xF7EE,
  25930. Icyrillic: 0x0406,
  25931. Idblgrave: 0x0208,
  25932. Idieresis: 0x00CF,
  25933. Idieresisacute: 0x1E2E,
  25934. Idieresiscyrillic: 0x04E4,
  25935. Idieresissmall: 0xF7EF,
  25936. Idot: 0x0130,
  25937. Idotaccent: 0x0130,
  25938. Idotbelow: 0x1ECA,
  25939. Iebrevecyrillic: 0x04D6,
  25940. Iecyrillic: 0x0415,
  25941. Ifraktur: 0x2111,
  25942. Igrave: 0x00CC,
  25943. Igravesmall: 0xF7EC,
  25944. Ihookabove: 0x1EC8,
  25945. Iicyrillic: 0x0418,
  25946. Iinvertedbreve: 0x020A,
  25947. Iishortcyrillic: 0x0419,
  25948. Imacron: 0x012A,
  25949. Imacroncyrillic: 0x04E2,
  25950. Imonospace: 0xFF29,
  25951. Iniarmenian: 0x053B,
  25952. Iocyrillic: 0x0401,
  25953. Iogonek: 0x012E,
  25954. Iota: 0x0399,
  25955. Iotaafrican: 0x0196,
  25956. Iotadieresis: 0x03AA,
  25957. Iotatonos: 0x038A,
  25958. Ismall: 0xF769,
  25959. Istroke: 0x0197,
  25960. Itilde: 0x0128,
  25961. Itildebelow: 0x1E2C,
  25962. Izhitsacyrillic: 0x0474,
  25963. Izhitsadblgravecyrillic: 0x0476,
  25964. J: 0x004A,
  25965. Jaarmenian: 0x0541,
  25966. Jcircle: 0x24BF,
  25967. Jcircumflex: 0x0134,
  25968. Jecyrillic: 0x0408,
  25969. Jheharmenian: 0x054B,
  25970. Jmonospace: 0xFF2A,
  25971. Jsmall: 0xF76A,
  25972. K: 0x004B,
  25973. KBsquare: 0x3385,
  25974. KKsquare: 0x33CD,
  25975. Kabashkircyrillic: 0x04A0,
  25976. Kacute: 0x1E30,
  25977. Kacyrillic: 0x041A,
  25978. Kadescendercyrillic: 0x049A,
  25979. Kahookcyrillic: 0x04C3,
  25980. Kappa: 0x039A,
  25981. Kastrokecyrillic: 0x049E,
  25982. Kaverticalstrokecyrillic: 0x049C,
  25983. Kcaron: 0x01E8,
  25984. Kcedilla: 0x0136,
  25985. Kcircle: 0x24C0,
  25986. Kcommaaccent: 0x0136,
  25987. Kdotbelow: 0x1E32,
  25988. Keharmenian: 0x0554,
  25989. Kenarmenian: 0x053F,
  25990. Khacyrillic: 0x0425,
  25991. Kheicoptic: 0x03E6,
  25992. Khook: 0x0198,
  25993. Kjecyrillic: 0x040C,
  25994. Klinebelow: 0x1E34,
  25995. Kmonospace: 0xFF2B,
  25996. Koppacyrillic: 0x0480,
  25997. Koppagreek: 0x03DE,
  25998. Ksicyrillic: 0x046E,
  25999. Ksmall: 0xF76B,
  26000. L: 0x004C,
  26001. LJ: 0x01C7,
  26002. LL: 0xF6BF,
  26003. Lacute: 0x0139,
  26004. Lambda: 0x039B,
  26005. Lcaron: 0x013D,
  26006. Lcedilla: 0x013B,
  26007. Lcircle: 0x24C1,
  26008. Lcircumflexbelow: 0x1E3C,
  26009. Lcommaaccent: 0x013B,
  26010. Ldot: 0x013F,
  26011. Ldotaccent: 0x013F,
  26012. Ldotbelow: 0x1E36,
  26013. Ldotbelowmacron: 0x1E38,
  26014. Liwnarmenian: 0x053C,
  26015. Lj: 0x01C8,
  26016. Ljecyrillic: 0x0409,
  26017. Llinebelow: 0x1E3A,
  26018. Lmonospace: 0xFF2C,
  26019. Lslash: 0x0141,
  26020. Lslashsmall: 0xF6F9,
  26021. Lsmall: 0xF76C,
  26022. M: 0x004D,
  26023. MBsquare: 0x3386,
  26024. Macron: 0xF6D0,
  26025. Macronsmall: 0xF7AF,
  26026. Macute: 0x1E3E,
  26027. Mcircle: 0x24C2,
  26028. Mdotaccent: 0x1E40,
  26029. Mdotbelow: 0x1E42,
  26030. Menarmenian: 0x0544,
  26031. Mmonospace: 0xFF2D,
  26032. Msmall: 0xF76D,
  26033. Mturned: 0x019C,
  26034. Mu: 0x039C,
  26035. N: 0x004E,
  26036. NJ: 0x01CA,
  26037. Nacute: 0x0143,
  26038. Ncaron: 0x0147,
  26039. Ncedilla: 0x0145,
  26040. Ncircle: 0x24C3,
  26041. Ncircumflexbelow: 0x1E4A,
  26042. Ncommaaccent: 0x0145,
  26043. Ndotaccent: 0x1E44,
  26044. Ndotbelow: 0x1E46,
  26045. Nhookleft: 0x019D,
  26046. Nineroman: 0x2168,
  26047. Nj: 0x01CB,
  26048. Njecyrillic: 0x040A,
  26049. Nlinebelow: 0x1E48,
  26050. Nmonospace: 0xFF2E,
  26051. Nowarmenian: 0x0546,
  26052. Nsmall: 0xF76E,
  26053. Ntilde: 0x00D1,
  26054. Ntildesmall: 0xF7F1,
  26055. Nu: 0x039D,
  26056. O: 0x004F,
  26057. OE: 0x0152,
  26058. OEsmall: 0xF6FA,
  26059. Oacute: 0x00D3,
  26060. Oacutesmall: 0xF7F3,
  26061. Obarredcyrillic: 0x04E8,
  26062. Obarreddieresiscyrillic: 0x04EA,
  26063. Obreve: 0x014E,
  26064. Ocaron: 0x01D1,
  26065. Ocenteredtilde: 0x019F,
  26066. Ocircle: 0x24C4,
  26067. Ocircumflex: 0x00D4,
  26068. Ocircumflexacute: 0x1ED0,
  26069. Ocircumflexdotbelow: 0x1ED8,
  26070. Ocircumflexgrave: 0x1ED2,
  26071. Ocircumflexhookabove: 0x1ED4,
  26072. Ocircumflexsmall: 0xF7F4,
  26073. Ocircumflextilde: 0x1ED6,
  26074. Ocyrillic: 0x041E,
  26075. Odblacute: 0x0150,
  26076. Odblgrave: 0x020C,
  26077. Odieresis: 0x00D6,
  26078. Odieresiscyrillic: 0x04E6,
  26079. Odieresissmall: 0xF7F6,
  26080. Odotbelow: 0x1ECC,
  26081. Ogoneksmall: 0xF6FB,
  26082. Ograve: 0x00D2,
  26083. Ogravesmall: 0xF7F2,
  26084. Oharmenian: 0x0555,
  26085. Ohm: 0x2126,
  26086. Ohookabove: 0x1ECE,
  26087. Ohorn: 0x01A0,
  26088. Ohornacute: 0x1EDA,
  26089. Ohorndotbelow: 0x1EE2,
  26090. Ohorngrave: 0x1EDC,
  26091. Ohornhookabove: 0x1EDE,
  26092. Ohorntilde: 0x1EE0,
  26093. Ohungarumlaut: 0x0150,
  26094. Oi: 0x01A2,
  26095. Oinvertedbreve: 0x020E,
  26096. Omacron: 0x014C,
  26097. Omacronacute: 0x1E52,
  26098. Omacrongrave: 0x1E50,
  26099. Omega: 0x2126,
  26100. Omegacyrillic: 0x0460,
  26101. Omegagreek: 0x03A9,
  26102. Omegaroundcyrillic: 0x047A,
  26103. Omegatitlocyrillic: 0x047C,
  26104. Omegatonos: 0x038F,
  26105. Omicron: 0x039F,
  26106. Omicrontonos: 0x038C,
  26107. Omonospace: 0xFF2F,
  26108. Oneroman: 0x2160,
  26109. Oogonek: 0x01EA,
  26110. Oogonekmacron: 0x01EC,
  26111. Oopen: 0x0186,
  26112. Oslash: 0x00D8,
  26113. Oslashacute: 0x01FE,
  26114. Oslashsmall: 0xF7F8,
  26115. Osmall: 0xF76F,
  26116. Ostrokeacute: 0x01FE,
  26117. Otcyrillic: 0x047E,
  26118. Otilde: 0x00D5,
  26119. Otildeacute: 0x1E4C,
  26120. Otildedieresis: 0x1E4E,
  26121. Otildesmall: 0xF7F5,
  26122. P: 0x0050,
  26123. Pacute: 0x1E54,
  26124. Pcircle: 0x24C5,
  26125. Pdotaccent: 0x1E56,
  26126. Pecyrillic: 0x041F,
  26127. Peharmenian: 0x054A,
  26128. Pemiddlehookcyrillic: 0x04A6,
  26129. Phi: 0x03A6,
  26130. Phook: 0x01A4,
  26131. Pi: 0x03A0,
  26132. Piwrarmenian: 0x0553,
  26133. Pmonospace: 0xFF30,
  26134. Psi: 0x03A8,
  26135. Psicyrillic: 0x0470,
  26136. Psmall: 0xF770,
  26137. Q: 0x0051,
  26138. Qcircle: 0x24C6,
  26139. Qmonospace: 0xFF31,
  26140. Qsmall: 0xF771,
  26141. R: 0x0052,
  26142. Raarmenian: 0x054C,
  26143. Racute: 0x0154,
  26144. Rcaron: 0x0158,
  26145. Rcedilla: 0x0156,
  26146. Rcircle: 0x24C7,
  26147. Rcommaaccent: 0x0156,
  26148. Rdblgrave: 0x0210,
  26149. Rdotaccent: 0x1E58,
  26150. Rdotbelow: 0x1E5A,
  26151. Rdotbelowmacron: 0x1E5C,
  26152. Reharmenian: 0x0550,
  26153. Rfraktur: 0x211C,
  26154. Rho: 0x03A1,
  26155. Ringsmall: 0xF6FC,
  26156. Rinvertedbreve: 0x0212,
  26157. Rlinebelow: 0x1E5E,
  26158. Rmonospace: 0xFF32,
  26159. Rsmall: 0xF772,
  26160. Rsmallinverted: 0x0281,
  26161. Rsmallinvertedsuperior: 0x02B6,
  26162. S: 0x0053,
  26163. SF010000: 0x250C,
  26164. SF020000: 0x2514,
  26165. SF030000: 0x2510,
  26166. SF040000: 0x2518,
  26167. SF050000: 0x253C,
  26168. SF060000: 0x252C,
  26169. SF070000: 0x2534,
  26170. SF080000: 0x251C,
  26171. SF090000: 0x2524,
  26172. SF100000: 0x2500,
  26173. SF110000: 0x2502,
  26174. SF190000: 0x2561,
  26175. SF200000: 0x2562,
  26176. SF210000: 0x2556,
  26177. SF220000: 0x2555,
  26178. SF230000: 0x2563,
  26179. SF240000: 0x2551,
  26180. SF250000: 0x2557,
  26181. SF260000: 0x255D,
  26182. SF270000: 0x255C,
  26183. SF280000: 0x255B,
  26184. SF360000: 0x255E,
  26185. SF370000: 0x255F,
  26186. SF380000: 0x255A,
  26187. SF390000: 0x2554,
  26188. SF400000: 0x2569,
  26189. SF410000: 0x2566,
  26190. SF420000: 0x2560,
  26191. SF430000: 0x2550,
  26192. SF440000: 0x256C,
  26193. SF450000: 0x2567,
  26194. SF460000: 0x2568,
  26195. SF470000: 0x2564,
  26196. SF480000: 0x2565,
  26197. SF490000: 0x2559,
  26198. SF500000: 0x2558,
  26199. SF510000: 0x2552,
  26200. SF520000: 0x2553,
  26201. SF530000: 0x256B,
  26202. SF540000: 0x256A,
  26203. Sacute: 0x015A,
  26204. Sacutedotaccent: 0x1E64,
  26205. Sampigreek: 0x03E0,
  26206. Scaron: 0x0160,
  26207. Scarondotaccent: 0x1E66,
  26208. Scaronsmall: 0xF6FD,
  26209. Scedilla: 0x015E,
  26210. Schwa: 0x018F,
  26211. Schwacyrillic: 0x04D8,
  26212. Schwadieresiscyrillic: 0x04DA,
  26213. Scircle: 0x24C8,
  26214. Scircumflex: 0x015C,
  26215. Scommaaccent: 0x0218,
  26216. Sdotaccent: 0x1E60,
  26217. Sdotbelow: 0x1E62,
  26218. Sdotbelowdotaccent: 0x1E68,
  26219. Seharmenian: 0x054D,
  26220. Sevenroman: 0x2166,
  26221. Shaarmenian: 0x0547,
  26222. Shacyrillic: 0x0428,
  26223. Shchacyrillic: 0x0429,
  26224. Sheicoptic: 0x03E2,
  26225. Shhacyrillic: 0x04BA,
  26226. Shimacoptic: 0x03EC,
  26227. Sigma: 0x03A3,
  26228. Sixroman: 0x2165,
  26229. Smonospace: 0xFF33,
  26230. Softsigncyrillic: 0x042C,
  26231. Ssmall: 0xF773,
  26232. Stigmagreek: 0x03DA,
  26233. T: 0x0054,
  26234. Tau: 0x03A4,
  26235. Tbar: 0x0166,
  26236. Tcaron: 0x0164,
  26237. Tcedilla: 0x0162,
  26238. Tcircle: 0x24C9,
  26239. Tcircumflexbelow: 0x1E70,
  26240. Tcommaaccent: 0x0162,
  26241. Tdotaccent: 0x1E6A,
  26242. Tdotbelow: 0x1E6C,
  26243. Tecyrillic: 0x0422,
  26244. Tedescendercyrillic: 0x04AC,
  26245. Tenroman: 0x2169,
  26246. Tetsecyrillic: 0x04B4,
  26247. Theta: 0x0398,
  26248. Thook: 0x01AC,
  26249. Thorn: 0x00DE,
  26250. Thornsmall: 0xF7FE,
  26251. Threeroman: 0x2162,
  26252. Tildesmall: 0xF6FE,
  26253. Tiwnarmenian: 0x054F,
  26254. Tlinebelow: 0x1E6E,
  26255. Tmonospace: 0xFF34,
  26256. Toarmenian: 0x0539,
  26257. Tonefive: 0x01BC,
  26258. Tonesix: 0x0184,
  26259. Tonetwo: 0x01A7,
  26260. Tretroflexhook: 0x01AE,
  26261. Tsecyrillic: 0x0426,
  26262. Tshecyrillic: 0x040B,
  26263. Tsmall: 0xF774,
  26264. Twelveroman: 0x216B,
  26265. Tworoman: 0x2161,
  26266. U: 0x0055,
  26267. Uacute: 0x00DA,
  26268. Uacutesmall: 0xF7FA,
  26269. Ubreve: 0x016C,
  26270. Ucaron: 0x01D3,
  26271. Ucircle: 0x24CA,
  26272. Ucircumflex: 0x00DB,
  26273. Ucircumflexbelow: 0x1E76,
  26274. Ucircumflexsmall: 0xF7FB,
  26275. Ucyrillic: 0x0423,
  26276. Udblacute: 0x0170,
  26277. Udblgrave: 0x0214,
  26278. Udieresis: 0x00DC,
  26279. Udieresisacute: 0x01D7,
  26280. Udieresisbelow: 0x1E72,
  26281. Udieresiscaron: 0x01D9,
  26282. Udieresiscyrillic: 0x04F0,
  26283. Udieresisgrave: 0x01DB,
  26284. Udieresismacron: 0x01D5,
  26285. Udieresissmall: 0xF7FC,
  26286. Udotbelow: 0x1EE4,
  26287. Ugrave: 0x00D9,
  26288. Ugravesmall: 0xF7F9,
  26289. Uhookabove: 0x1EE6,
  26290. Uhorn: 0x01AF,
  26291. Uhornacute: 0x1EE8,
  26292. Uhorndotbelow: 0x1EF0,
  26293. Uhorngrave: 0x1EEA,
  26294. Uhornhookabove: 0x1EEC,
  26295. Uhorntilde: 0x1EEE,
  26296. Uhungarumlaut: 0x0170,
  26297. Uhungarumlautcyrillic: 0x04F2,
  26298. Uinvertedbreve: 0x0216,
  26299. Ukcyrillic: 0x0478,
  26300. Umacron: 0x016A,
  26301. Umacroncyrillic: 0x04EE,
  26302. Umacrondieresis: 0x1E7A,
  26303. Umonospace: 0xFF35,
  26304. Uogonek: 0x0172,
  26305. Upsilon: 0x03A5,
  26306. Upsilon1: 0x03D2,
  26307. Upsilonacutehooksymbolgreek: 0x03D3,
  26308. Upsilonafrican: 0x01B1,
  26309. Upsilondieresis: 0x03AB,
  26310. Upsilondieresishooksymbolgreek: 0x03D4,
  26311. Upsilonhooksymbol: 0x03D2,
  26312. Upsilontonos: 0x038E,
  26313. Uring: 0x016E,
  26314. Ushortcyrillic: 0x040E,
  26315. Usmall: 0xF775,
  26316. Ustraightcyrillic: 0x04AE,
  26317. Ustraightstrokecyrillic: 0x04B0,
  26318. Utilde: 0x0168,
  26319. Utildeacute: 0x1E78,
  26320. Utildebelow: 0x1E74,
  26321. V: 0x0056,
  26322. Vcircle: 0x24CB,
  26323. Vdotbelow: 0x1E7E,
  26324. Vecyrillic: 0x0412,
  26325. Vewarmenian: 0x054E,
  26326. Vhook: 0x01B2,
  26327. Vmonospace: 0xFF36,
  26328. Voarmenian: 0x0548,
  26329. Vsmall: 0xF776,
  26330. Vtilde: 0x1E7C,
  26331. W: 0x0057,
  26332. Wacute: 0x1E82,
  26333. Wcircle: 0x24CC,
  26334. Wcircumflex: 0x0174,
  26335. Wdieresis: 0x1E84,
  26336. Wdotaccent: 0x1E86,
  26337. Wdotbelow: 0x1E88,
  26338. Wgrave: 0x1E80,
  26339. Wmonospace: 0xFF37,
  26340. Wsmall: 0xF777,
  26341. X: 0x0058,
  26342. Xcircle: 0x24CD,
  26343. Xdieresis: 0x1E8C,
  26344. Xdotaccent: 0x1E8A,
  26345. Xeharmenian: 0x053D,
  26346. Xi: 0x039E,
  26347. Xmonospace: 0xFF38,
  26348. Xsmall: 0xF778,
  26349. Y: 0x0059,
  26350. Yacute: 0x00DD,
  26351. Yacutesmall: 0xF7FD,
  26352. Yatcyrillic: 0x0462,
  26353. Ycircle: 0x24CE,
  26354. Ycircumflex: 0x0176,
  26355. Ydieresis: 0x0178,
  26356. Ydieresissmall: 0xF7FF,
  26357. Ydotaccent: 0x1E8E,
  26358. Ydotbelow: 0x1EF4,
  26359. Yericyrillic: 0x042B,
  26360. Yerudieresiscyrillic: 0x04F8,
  26361. Ygrave: 0x1EF2,
  26362. Yhook: 0x01B3,
  26363. Yhookabove: 0x1EF6,
  26364. Yiarmenian: 0x0545,
  26365. Yicyrillic: 0x0407,
  26366. Yiwnarmenian: 0x0552,
  26367. Ymonospace: 0xFF39,
  26368. Ysmall: 0xF779,
  26369. Ytilde: 0x1EF8,
  26370. Yusbigcyrillic: 0x046A,
  26371. Yusbigiotifiedcyrillic: 0x046C,
  26372. Yuslittlecyrillic: 0x0466,
  26373. Yuslittleiotifiedcyrillic: 0x0468,
  26374. Z: 0x005A,
  26375. Zaarmenian: 0x0536,
  26376. Zacute: 0x0179,
  26377. Zcaron: 0x017D,
  26378. Zcaronsmall: 0xF6FF,
  26379. Zcircle: 0x24CF,
  26380. Zcircumflex: 0x1E90,
  26381. Zdot: 0x017B,
  26382. Zdotaccent: 0x017B,
  26383. Zdotbelow: 0x1E92,
  26384. Zecyrillic: 0x0417,
  26385. Zedescendercyrillic: 0x0498,
  26386. Zedieresiscyrillic: 0x04DE,
  26387. Zeta: 0x0396,
  26388. Zhearmenian: 0x053A,
  26389. Zhebrevecyrillic: 0x04C1,
  26390. Zhecyrillic: 0x0416,
  26391. Zhedescendercyrillic: 0x0496,
  26392. Zhedieresiscyrillic: 0x04DC,
  26393. Zlinebelow: 0x1E94,
  26394. Zmonospace: 0xFF3A,
  26395. Zsmall: 0xF77A,
  26396. Zstroke: 0x01B5,
  26397. a: 0x0061,
  26398. aabengali: 0x0986,
  26399. aacute: 0x00E1,
  26400. aadeva: 0x0906,
  26401. aagujarati: 0x0A86,
  26402. aagurmukhi: 0x0A06,
  26403. aamatragurmukhi: 0x0A3E,
  26404. aarusquare: 0x3303,
  26405. aavowelsignbengali: 0x09BE,
  26406. aavowelsigndeva: 0x093E,
  26407. aavowelsigngujarati: 0x0ABE,
  26408. abbreviationmarkarmenian: 0x055F,
  26409. abbreviationsigndeva: 0x0970,
  26410. abengali: 0x0985,
  26411. abopomofo: 0x311A,
  26412. abreve: 0x0103,
  26413. abreveacute: 0x1EAF,
  26414. abrevecyrillic: 0x04D1,
  26415. abrevedotbelow: 0x1EB7,
  26416. abrevegrave: 0x1EB1,
  26417. abrevehookabove: 0x1EB3,
  26418. abrevetilde: 0x1EB5,
  26419. acaron: 0x01CE,
  26420. acircle: 0x24D0,
  26421. acircumflex: 0x00E2,
  26422. acircumflexacute: 0x1EA5,
  26423. acircumflexdotbelow: 0x1EAD,
  26424. acircumflexgrave: 0x1EA7,
  26425. acircumflexhookabove: 0x1EA9,
  26426. acircumflextilde: 0x1EAB,
  26427. acute: 0x00B4,
  26428. acutebelowcmb: 0x0317,
  26429. acutecmb: 0x0301,
  26430. acutecomb: 0x0301,
  26431. acutedeva: 0x0954,
  26432. acutelowmod: 0x02CF,
  26433. acutetonecmb: 0x0341,
  26434. acyrillic: 0x0430,
  26435. adblgrave: 0x0201,
  26436. addakgurmukhi: 0x0A71,
  26437. adeva: 0x0905,
  26438. adieresis: 0x00E4,
  26439. adieresiscyrillic: 0x04D3,
  26440. adieresismacron: 0x01DF,
  26441. adotbelow: 0x1EA1,
  26442. adotmacron: 0x01E1,
  26443. ae: 0x00E6,
  26444. aeacute: 0x01FD,
  26445. aekorean: 0x3150,
  26446. aemacron: 0x01E3,
  26447. afii00208: 0x2015,
  26448. afii08941: 0x20A4,
  26449. afii10017: 0x0410,
  26450. afii10018: 0x0411,
  26451. afii10019: 0x0412,
  26452. afii10020: 0x0413,
  26453. afii10021: 0x0414,
  26454. afii10022: 0x0415,
  26455. afii10023: 0x0401,
  26456. afii10024: 0x0416,
  26457. afii10025: 0x0417,
  26458. afii10026: 0x0418,
  26459. afii10027: 0x0419,
  26460. afii10028: 0x041A,
  26461. afii10029: 0x041B,
  26462. afii10030: 0x041C,
  26463. afii10031: 0x041D,
  26464. afii10032: 0x041E,
  26465. afii10033: 0x041F,
  26466. afii10034: 0x0420,
  26467. afii10035: 0x0421,
  26468. afii10036: 0x0422,
  26469. afii10037: 0x0423,
  26470. afii10038: 0x0424,
  26471. afii10039: 0x0425,
  26472. afii10040: 0x0426,
  26473. afii10041: 0x0427,
  26474. afii10042: 0x0428,
  26475. afii10043: 0x0429,
  26476. afii10044: 0x042A,
  26477. afii10045: 0x042B,
  26478. afii10046: 0x042C,
  26479. afii10047: 0x042D,
  26480. afii10048: 0x042E,
  26481. afii10049: 0x042F,
  26482. afii10050: 0x0490,
  26483. afii10051: 0x0402,
  26484. afii10052: 0x0403,
  26485. afii10053: 0x0404,
  26486. afii10054: 0x0405,
  26487. afii10055: 0x0406,
  26488. afii10056: 0x0407,
  26489. afii10057: 0x0408,
  26490. afii10058: 0x0409,
  26491. afii10059: 0x040A,
  26492. afii10060: 0x040B,
  26493. afii10061: 0x040C,
  26494. afii10062: 0x040E,
  26495. afii10063: 0xF6C4,
  26496. afii10064: 0xF6C5,
  26497. afii10065: 0x0430,
  26498. afii10066: 0x0431,
  26499. afii10067: 0x0432,
  26500. afii10068: 0x0433,
  26501. afii10069: 0x0434,
  26502. afii10070: 0x0435,
  26503. afii10071: 0x0451,
  26504. afii10072: 0x0436,
  26505. afii10073: 0x0437,
  26506. afii10074: 0x0438,
  26507. afii10075: 0x0439,
  26508. afii10076: 0x043A,
  26509. afii10077: 0x043B,
  26510. afii10078: 0x043C,
  26511. afii10079: 0x043D,
  26512. afii10080: 0x043E,
  26513. afii10081: 0x043F,
  26514. afii10082: 0x0440,
  26515. afii10083: 0x0441,
  26516. afii10084: 0x0442,
  26517. afii10085: 0x0443,
  26518. afii10086: 0x0444,
  26519. afii10087: 0x0445,
  26520. afii10088: 0x0446,
  26521. afii10089: 0x0447,
  26522. afii10090: 0x0448,
  26523. afii10091: 0x0449,
  26524. afii10092: 0x044A,
  26525. afii10093: 0x044B,
  26526. afii10094: 0x044C,
  26527. afii10095: 0x044D,
  26528. afii10096: 0x044E,
  26529. afii10097: 0x044F,
  26530. afii10098: 0x0491,
  26531. afii10099: 0x0452,
  26532. afii10100: 0x0453,
  26533. afii10101: 0x0454,
  26534. afii10102: 0x0455,
  26535. afii10103: 0x0456,
  26536. afii10104: 0x0457,
  26537. afii10105: 0x0458,
  26538. afii10106: 0x0459,
  26539. afii10107: 0x045A,
  26540. afii10108: 0x045B,
  26541. afii10109: 0x045C,
  26542. afii10110: 0x045E,
  26543. afii10145: 0x040F,
  26544. afii10146: 0x0462,
  26545. afii10147: 0x0472,
  26546. afii10148: 0x0474,
  26547. afii10192: 0xF6C6,
  26548. afii10193: 0x045F,
  26549. afii10194: 0x0463,
  26550. afii10195: 0x0473,
  26551. afii10196: 0x0475,
  26552. afii10831: 0xF6C7,
  26553. afii10832: 0xF6C8,
  26554. afii10846: 0x04D9,
  26555. afii299: 0x200E,
  26556. afii300: 0x200F,
  26557. afii301: 0x200D,
  26558. afii57381: 0x066A,
  26559. afii57388: 0x060C,
  26560. afii57392: 0x0660,
  26561. afii57393: 0x0661,
  26562. afii57394: 0x0662,
  26563. afii57395: 0x0663,
  26564. afii57396: 0x0664,
  26565. afii57397: 0x0665,
  26566. afii57398: 0x0666,
  26567. afii57399: 0x0667,
  26568. afii57400: 0x0668,
  26569. afii57401: 0x0669,
  26570. afii57403: 0x061B,
  26571. afii57407: 0x061F,
  26572. afii57409: 0x0621,
  26573. afii57410: 0x0622,
  26574. afii57411: 0x0623,
  26575. afii57412: 0x0624,
  26576. afii57413: 0x0625,
  26577. afii57414: 0x0626,
  26578. afii57415: 0x0627,
  26579. afii57416: 0x0628,
  26580. afii57417: 0x0629,
  26581. afii57418: 0x062A,
  26582. afii57419: 0x062B,
  26583. afii57420: 0x062C,
  26584. afii57421: 0x062D,
  26585. afii57422: 0x062E,
  26586. afii57423: 0x062F,
  26587. afii57424: 0x0630,
  26588. afii57425: 0x0631,
  26589. afii57426: 0x0632,
  26590. afii57427: 0x0633,
  26591. afii57428: 0x0634,
  26592. afii57429: 0x0635,
  26593. afii57430: 0x0636,
  26594. afii57431: 0x0637,
  26595. afii57432: 0x0638,
  26596. afii57433: 0x0639,
  26597. afii57434: 0x063A,
  26598. afii57440: 0x0640,
  26599. afii57441: 0x0641,
  26600. afii57442: 0x0642,
  26601. afii57443: 0x0643,
  26602. afii57444: 0x0644,
  26603. afii57445: 0x0645,
  26604. afii57446: 0x0646,
  26605. afii57448: 0x0648,
  26606. afii57449: 0x0649,
  26607. afii57450: 0x064A,
  26608. afii57451: 0x064B,
  26609. afii57452: 0x064C,
  26610. afii57453: 0x064D,
  26611. afii57454: 0x064E,
  26612. afii57455: 0x064F,
  26613. afii57456: 0x0650,
  26614. afii57457: 0x0651,
  26615. afii57458: 0x0652,
  26616. afii57470: 0x0647,
  26617. afii57505: 0x06A4,
  26618. afii57506: 0x067E,
  26619. afii57507: 0x0686,
  26620. afii57508: 0x0698,
  26621. afii57509: 0x06AF,
  26622. afii57511: 0x0679,
  26623. afii57512: 0x0688,
  26624. afii57513: 0x0691,
  26625. afii57514: 0x06BA,
  26626. afii57519: 0x06D2,
  26627. afii57534: 0x06D5,
  26628. afii57636: 0x20AA,
  26629. afii57645: 0x05BE,
  26630. afii57658: 0x05C3,
  26631. afii57664: 0x05D0,
  26632. afii57665: 0x05D1,
  26633. afii57666: 0x05D2,
  26634. afii57667: 0x05D3,
  26635. afii57668: 0x05D4,
  26636. afii57669: 0x05D5,
  26637. afii57670: 0x05D6,
  26638. afii57671: 0x05D7,
  26639. afii57672: 0x05D8,
  26640. afii57673: 0x05D9,
  26641. afii57674: 0x05DA,
  26642. afii57675: 0x05DB,
  26643. afii57676: 0x05DC,
  26644. afii57677: 0x05DD,
  26645. afii57678: 0x05DE,
  26646. afii57679: 0x05DF,
  26647. afii57680: 0x05E0,
  26648. afii57681: 0x05E1,
  26649. afii57682: 0x05E2,
  26650. afii57683: 0x05E3,
  26651. afii57684: 0x05E4,
  26652. afii57685: 0x05E5,
  26653. afii57686: 0x05E6,
  26654. afii57687: 0x05E7,
  26655. afii57688: 0x05E8,
  26656. afii57689: 0x05E9,
  26657. afii57690: 0x05EA,
  26658. afii57694: 0xFB2A,
  26659. afii57695: 0xFB2B,
  26660. afii57700: 0xFB4B,
  26661. afii57705: 0xFB1F,
  26662. afii57716: 0x05F0,
  26663. afii57717: 0x05F1,
  26664. afii57718: 0x05F2,
  26665. afii57723: 0xFB35,
  26666. afii57793: 0x05B4,
  26667. afii57794: 0x05B5,
  26668. afii57795: 0x05B6,
  26669. afii57796: 0x05BB,
  26670. afii57797: 0x05B8,
  26671. afii57798: 0x05B7,
  26672. afii57799: 0x05B0,
  26673. afii57800: 0x05B2,
  26674. afii57801: 0x05B1,
  26675. afii57802: 0x05B3,
  26676. afii57803: 0x05C2,
  26677. afii57804: 0x05C1,
  26678. afii57806: 0x05B9,
  26679. afii57807: 0x05BC,
  26680. afii57839: 0x05BD,
  26681. afii57841: 0x05BF,
  26682. afii57842: 0x05C0,
  26683. afii57929: 0x02BC,
  26684. afii61248: 0x2105,
  26685. afii61289: 0x2113,
  26686. afii61352: 0x2116,
  26687. afii61573: 0x202C,
  26688. afii61574: 0x202D,
  26689. afii61575: 0x202E,
  26690. afii61664: 0x200C,
  26691. afii63167: 0x066D,
  26692. afii64937: 0x02BD,
  26693. agrave: 0x00E0,
  26694. agujarati: 0x0A85,
  26695. agurmukhi: 0x0A05,
  26696. ahiragana: 0x3042,
  26697. ahookabove: 0x1EA3,
  26698. aibengali: 0x0990,
  26699. aibopomofo: 0x311E,
  26700. aideva: 0x0910,
  26701. aiecyrillic: 0x04D5,
  26702. aigujarati: 0x0A90,
  26703. aigurmukhi: 0x0A10,
  26704. aimatragurmukhi: 0x0A48,
  26705. ainarabic: 0x0639,
  26706. ainfinalarabic: 0xFECA,
  26707. aininitialarabic: 0xFECB,
  26708. ainmedialarabic: 0xFECC,
  26709. ainvertedbreve: 0x0203,
  26710. aivowelsignbengali: 0x09C8,
  26711. aivowelsigndeva: 0x0948,
  26712. aivowelsigngujarati: 0x0AC8,
  26713. akatakana: 0x30A2,
  26714. akatakanahalfwidth: 0xFF71,
  26715. akorean: 0x314F,
  26716. alef: 0x05D0,
  26717. alefarabic: 0x0627,
  26718. alefdageshhebrew: 0xFB30,
  26719. aleffinalarabic: 0xFE8E,
  26720. alefhamzaabovearabic: 0x0623,
  26721. alefhamzaabovefinalarabic: 0xFE84,
  26722. alefhamzabelowarabic: 0x0625,
  26723. alefhamzabelowfinalarabic: 0xFE88,
  26724. alefhebrew: 0x05D0,
  26725. aleflamedhebrew: 0xFB4F,
  26726. alefmaddaabovearabic: 0x0622,
  26727. alefmaddaabovefinalarabic: 0xFE82,
  26728. alefmaksuraarabic: 0x0649,
  26729. alefmaksurafinalarabic: 0xFEF0,
  26730. alefmaksurainitialarabic: 0xFEF3,
  26731. alefmaksuramedialarabic: 0xFEF4,
  26732. alefpatahhebrew: 0xFB2E,
  26733. alefqamatshebrew: 0xFB2F,
  26734. aleph: 0x2135,
  26735. allequal: 0x224C,
  26736. alpha: 0x03B1,
  26737. alphatonos: 0x03AC,
  26738. amacron: 0x0101,
  26739. amonospace: 0xFF41,
  26740. ampersand: 0x0026,
  26741. ampersandmonospace: 0xFF06,
  26742. ampersandsmall: 0xF726,
  26743. amsquare: 0x33C2,
  26744. anbopomofo: 0x3122,
  26745. angbopomofo: 0x3124,
  26746. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  26747. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  26748. angkhankhuthai: 0x0E5A,
  26749. angle: 0x2220,
  26750. anglebracketleft: 0x3008,
  26751. anglebracketleftvertical: 0xFE3F,
  26752. anglebracketright: 0x3009,
  26753. anglebracketrightvertical: 0xFE40,
  26754. angleleft: 0x2329,
  26755. angleright: 0x232A,
  26756. angstrom: 0x212B,
  26757. anoteleia: 0x0387,
  26758. anudattadeva: 0x0952,
  26759. anusvarabengali: 0x0982,
  26760. anusvaradeva: 0x0902,
  26761. anusvaragujarati: 0x0A82,
  26762. aogonek: 0x0105,
  26763. apaatosquare: 0x3300,
  26764. aparen: 0x249C,
  26765. apostrophearmenian: 0x055A,
  26766. apostrophemod: 0x02BC,
  26767. apple: 0xF8FF,
  26768. approaches: 0x2250,
  26769. approxequal: 0x2248,
  26770. approxequalorimage: 0x2252,
  26771. approximatelyequal: 0x2245,
  26772. araeaekorean: 0x318E,
  26773. araeakorean: 0x318D,
  26774. arc: 0x2312,
  26775. arighthalfring: 0x1E9A,
  26776. aring: 0x00E5,
  26777. aringacute: 0x01FB,
  26778. aringbelow: 0x1E01,
  26779. arrowboth: 0x2194,
  26780. arrowdashdown: 0x21E3,
  26781. arrowdashleft: 0x21E0,
  26782. arrowdashright: 0x21E2,
  26783. arrowdashup: 0x21E1,
  26784. arrowdblboth: 0x21D4,
  26785. arrowdbldown: 0x21D3,
  26786. arrowdblleft: 0x21D0,
  26787. arrowdblright: 0x21D2,
  26788. arrowdblup: 0x21D1,
  26789. arrowdown: 0x2193,
  26790. arrowdownleft: 0x2199,
  26791. arrowdownright: 0x2198,
  26792. arrowdownwhite: 0x21E9,
  26793. arrowheaddownmod: 0x02C5,
  26794. arrowheadleftmod: 0x02C2,
  26795. arrowheadrightmod: 0x02C3,
  26796. arrowheadupmod: 0x02C4,
  26797. arrowhorizex: 0xF8E7,
  26798. arrowleft: 0x2190,
  26799. arrowleftdbl: 0x21D0,
  26800. arrowleftdblstroke: 0x21CD,
  26801. arrowleftoverright: 0x21C6,
  26802. arrowleftwhite: 0x21E6,
  26803. arrowright: 0x2192,
  26804. arrowrightdblstroke: 0x21CF,
  26805. arrowrightheavy: 0x279E,
  26806. arrowrightoverleft: 0x21C4,
  26807. arrowrightwhite: 0x21E8,
  26808. arrowtableft: 0x21E4,
  26809. arrowtabright: 0x21E5,
  26810. arrowup: 0x2191,
  26811. arrowupdn: 0x2195,
  26812. arrowupdnbse: 0x21A8,
  26813. arrowupdownbase: 0x21A8,
  26814. arrowupleft: 0x2196,
  26815. arrowupleftofdown: 0x21C5,
  26816. arrowupright: 0x2197,
  26817. arrowupwhite: 0x21E7,
  26818. arrowvertex: 0xF8E6,
  26819. asciicircum: 0x005E,
  26820. asciicircummonospace: 0xFF3E,
  26821. asciitilde: 0x007E,
  26822. asciitildemonospace: 0xFF5E,
  26823. ascript: 0x0251,
  26824. ascriptturned: 0x0252,
  26825. asmallhiragana: 0x3041,
  26826. asmallkatakana: 0x30A1,
  26827. asmallkatakanahalfwidth: 0xFF67,
  26828. asterisk: 0x002A,
  26829. asteriskaltonearabic: 0x066D,
  26830. asteriskarabic: 0x066D,
  26831. asteriskmath: 0x2217,
  26832. asteriskmonospace: 0xFF0A,
  26833. asterisksmall: 0xFE61,
  26834. asterism: 0x2042,
  26835. asuperior: 0xF6E9,
  26836. asymptoticallyequal: 0x2243,
  26837. at: 0x0040,
  26838. atilde: 0x00E3,
  26839. atmonospace: 0xFF20,
  26840. atsmall: 0xFE6B,
  26841. aturned: 0x0250,
  26842. aubengali: 0x0994,
  26843. aubopomofo: 0x3120,
  26844. audeva: 0x0914,
  26845. augujarati: 0x0A94,
  26846. augurmukhi: 0x0A14,
  26847. aulengthmarkbengali: 0x09D7,
  26848. aumatragurmukhi: 0x0A4C,
  26849. auvowelsignbengali: 0x09CC,
  26850. auvowelsigndeva: 0x094C,
  26851. auvowelsigngujarati: 0x0ACC,
  26852. avagrahadeva: 0x093D,
  26853. aybarmenian: 0x0561,
  26854. ayin: 0x05E2,
  26855. ayinaltonehebrew: 0xFB20,
  26856. ayinhebrew: 0x05E2,
  26857. b: 0x0062,
  26858. babengali: 0x09AC,
  26859. backslash: 0x005C,
  26860. backslashmonospace: 0xFF3C,
  26861. badeva: 0x092C,
  26862. bagujarati: 0x0AAC,
  26863. bagurmukhi: 0x0A2C,
  26864. bahiragana: 0x3070,
  26865. bahtthai: 0x0E3F,
  26866. bakatakana: 0x30D0,
  26867. bar: 0x007C,
  26868. barmonospace: 0xFF5C,
  26869. bbopomofo: 0x3105,
  26870. bcircle: 0x24D1,
  26871. bdotaccent: 0x1E03,
  26872. bdotbelow: 0x1E05,
  26873. beamedsixteenthnotes: 0x266C,
  26874. because: 0x2235,
  26875. becyrillic: 0x0431,
  26876. beharabic: 0x0628,
  26877. behfinalarabic: 0xFE90,
  26878. behinitialarabic: 0xFE91,
  26879. behiragana: 0x3079,
  26880. behmedialarabic: 0xFE92,
  26881. behmeeminitialarabic: 0xFC9F,
  26882. behmeemisolatedarabic: 0xFC08,
  26883. behnoonfinalarabic: 0xFC6D,
  26884. bekatakana: 0x30D9,
  26885. benarmenian: 0x0562,
  26886. bet: 0x05D1,
  26887. beta: 0x03B2,
  26888. betasymbolgreek: 0x03D0,
  26889. betdagesh: 0xFB31,
  26890. betdageshhebrew: 0xFB31,
  26891. bethebrew: 0x05D1,
  26892. betrafehebrew: 0xFB4C,
  26893. bhabengali: 0x09AD,
  26894. bhadeva: 0x092D,
  26895. bhagujarati: 0x0AAD,
  26896. bhagurmukhi: 0x0A2D,
  26897. bhook: 0x0253,
  26898. bihiragana: 0x3073,
  26899. bikatakana: 0x30D3,
  26900. bilabialclick: 0x0298,
  26901. bindigurmukhi: 0x0A02,
  26902. birusquare: 0x3331,
  26903. blackcircle: 0x25CF,
  26904. blackdiamond: 0x25C6,
  26905. blackdownpointingtriangle: 0x25BC,
  26906. blackleftpointingpointer: 0x25C4,
  26907. blackleftpointingtriangle: 0x25C0,
  26908. blacklenticularbracketleft: 0x3010,
  26909. blacklenticularbracketleftvertical: 0xFE3B,
  26910. blacklenticularbracketright: 0x3011,
  26911. blacklenticularbracketrightvertical: 0xFE3C,
  26912. blacklowerlefttriangle: 0x25E3,
  26913. blacklowerrighttriangle: 0x25E2,
  26914. blackrectangle: 0x25AC,
  26915. blackrightpointingpointer: 0x25BA,
  26916. blackrightpointingtriangle: 0x25B6,
  26917. blacksmallsquare: 0x25AA,
  26918. blacksmilingface: 0x263B,
  26919. blacksquare: 0x25A0,
  26920. blackstar: 0x2605,
  26921. blackupperlefttriangle: 0x25E4,
  26922. blackupperrighttriangle: 0x25E5,
  26923. blackuppointingsmalltriangle: 0x25B4,
  26924. blackuppointingtriangle: 0x25B2,
  26925. blank: 0x2423,
  26926. blinebelow: 0x1E07,
  26927. block: 0x2588,
  26928. bmonospace: 0xFF42,
  26929. bobaimaithai: 0x0E1A,
  26930. bohiragana: 0x307C,
  26931. bokatakana: 0x30DC,
  26932. bparen: 0x249D,
  26933. bqsquare: 0x33C3,
  26934. braceex: 0xF8F4,
  26935. braceleft: 0x007B,
  26936. braceleftbt: 0xF8F3,
  26937. braceleftmid: 0xF8F2,
  26938. braceleftmonospace: 0xFF5B,
  26939. braceleftsmall: 0xFE5B,
  26940. bracelefttp: 0xF8F1,
  26941. braceleftvertical: 0xFE37,
  26942. braceright: 0x007D,
  26943. bracerightbt: 0xF8FE,
  26944. bracerightmid: 0xF8FD,
  26945. bracerightmonospace: 0xFF5D,
  26946. bracerightsmall: 0xFE5C,
  26947. bracerighttp: 0xF8FC,
  26948. bracerightvertical: 0xFE38,
  26949. bracketleft: 0x005B,
  26950. bracketleftbt: 0xF8F0,
  26951. bracketleftex: 0xF8EF,
  26952. bracketleftmonospace: 0xFF3B,
  26953. bracketlefttp: 0xF8EE,
  26954. bracketright: 0x005D,
  26955. bracketrightbt: 0xF8FB,
  26956. bracketrightex: 0xF8FA,
  26957. bracketrightmonospace: 0xFF3D,
  26958. bracketrighttp: 0xF8F9,
  26959. breve: 0x02D8,
  26960. brevebelowcmb: 0x032E,
  26961. brevecmb: 0x0306,
  26962. breveinvertedbelowcmb: 0x032F,
  26963. breveinvertedcmb: 0x0311,
  26964. breveinverteddoublecmb: 0x0361,
  26965. bridgebelowcmb: 0x032A,
  26966. bridgeinvertedbelowcmb: 0x033A,
  26967. brokenbar: 0x00A6,
  26968. bstroke: 0x0180,
  26969. bsuperior: 0xF6EA,
  26970. btopbar: 0x0183,
  26971. buhiragana: 0x3076,
  26972. bukatakana: 0x30D6,
  26973. bullet: 0x2022,
  26974. bulletinverse: 0x25D8,
  26975. bulletoperator: 0x2219,
  26976. bullseye: 0x25CE,
  26977. c: 0x0063,
  26978. caarmenian: 0x056E,
  26979. cabengali: 0x099A,
  26980. cacute: 0x0107,
  26981. cadeva: 0x091A,
  26982. cagujarati: 0x0A9A,
  26983. cagurmukhi: 0x0A1A,
  26984. calsquare: 0x3388,
  26985. candrabindubengali: 0x0981,
  26986. candrabinducmb: 0x0310,
  26987. candrabindudeva: 0x0901,
  26988. candrabindugujarati: 0x0A81,
  26989. capslock: 0x21EA,
  26990. careof: 0x2105,
  26991. caron: 0x02C7,
  26992. caronbelowcmb: 0x032C,
  26993. caroncmb: 0x030C,
  26994. carriagereturn: 0x21B5,
  26995. cbopomofo: 0x3118,
  26996. ccaron: 0x010D,
  26997. ccedilla: 0x00E7,
  26998. ccedillaacute: 0x1E09,
  26999. ccircle: 0x24D2,
  27000. ccircumflex: 0x0109,
  27001. ccurl: 0x0255,
  27002. cdot: 0x010B,
  27003. cdotaccent: 0x010B,
  27004. cdsquare: 0x33C5,
  27005. cedilla: 0x00B8,
  27006. cedillacmb: 0x0327,
  27007. cent: 0x00A2,
  27008. centigrade: 0x2103,
  27009. centinferior: 0xF6DF,
  27010. centmonospace: 0xFFE0,
  27011. centoldstyle: 0xF7A2,
  27012. centsuperior: 0xF6E0,
  27013. chaarmenian: 0x0579,
  27014. chabengali: 0x099B,
  27015. chadeva: 0x091B,
  27016. chagujarati: 0x0A9B,
  27017. chagurmukhi: 0x0A1B,
  27018. chbopomofo: 0x3114,
  27019. cheabkhasiancyrillic: 0x04BD,
  27020. checkmark: 0x2713,
  27021. checyrillic: 0x0447,
  27022. chedescenderabkhasiancyrillic: 0x04BF,
  27023. chedescendercyrillic: 0x04B7,
  27024. chedieresiscyrillic: 0x04F5,
  27025. cheharmenian: 0x0573,
  27026. chekhakassiancyrillic: 0x04CC,
  27027. cheverticalstrokecyrillic: 0x04B9,
  27028. chi: 0x03C7,
  27029. chieuchacirclekorean: 0x3277,
  27030. chieuchaparenkorean: 0x3217,
  27031. chieuchcirclekorean: 0x3269,
  27032. chieuchkorean: 0x314A,
  27033. chieuchparenkorean: 0x3209,
  27034. chochangthai: 0x0E0A,
  27035. chochanthai: 0x0E08,
  27036. chochingthai: 0x0E09,
  27037. chochoethai: 0x0E0C,
  27038. chook: 0x0188,
  27039. cieucacirclekorean: 0x3276,
  27040. cieucaparenkorean: 0x3216,
  27041. cieuccirclekorean: 0x3268,
  27042. cieuckorean: 0x3148,
  27043. cieucparenkorean: 0x3208,
  27044. cieucuparenkorean: 0x321C,
  27045. circle: 0x25CB,
  27046. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27047. circlemultiply: 0x2297,
  27048. circleot: 0x2299,
  27049. circleplus: 0x2295,
  27050. circlepostalmark: 0x3036,
  27051. circlewithlefthalfblack: 0x25D0,
  27052. circlewithrighthalfblack: 0x25D1,
  27053. circumflex: 0x02C6,
  27054. circumflexbelowcmb: 0x032D,
  27055. circumflexcmb: 0x0302,
  27056. clear: 0x2327,
  27057. clickalveolar: 0x01C2,
  27058. clickdental: 0x01C0,
  27059. clicklateral: 0x01C1,
  27060. clickretroflex: 0x01C3,
  27061. club: 0x2663,
  27062. clubsuitblack: 0x2663,
  27063. clubsuitwhite: 0x2667,
  27064. cmcubedsquare: 0x33A4,
  27065. cmonospace: 0xFF43,
  27066. cmsquaredsquare: 0x33A0,
  27067. coarmenian: 0x0581,
  27068. colon: 0x003A,
  27069. colonmonetary: 0x20A1,
  27070. colonmonospace: 0xFF1A,
  27071. colonsign: 0x20A1,
  27072. colonsmall: 0xFE55,
  27073. colontriangularhalfmod: 0x02D1,
  27074. colontriangularmod: 0x02D0,
  27075. comma: 0x002C,
  27076. commaabovecmb: 0x0313,
  27077. commaaboverightcmb: 0x0315,
  27078. commaaccent: 0xF6C3,
  27079. commaarabic: 0x060C,
  27080. commaarmenian: 0x055D,
  27081. commainferior: 0xF6E1,
  27082. commamonospace: 0xFF0C,
  27083. commareversedabovecmb: 0x0314,
  27084. commareversedmod: 0x02BD,
  27085. commasmall: 0xFE50,
  27086. commasuperior: 0xF6E2,
  27087. commaturnedabovecmb: 0x0312,
  27088. commaturnedmod: 0x02BB,
  27089. compass: 0x263C,
  27090. congruent: 0x2245,
  27091. contourintegral: 0x222E,
  27092. control: 0x2303,
  27093. controlACK: 0x0006,
  27094. controlBEL: 0x0007,
  27095. controlBS: 0x0008,
  27096. controlCAN: 0x0018,
  27097. controlCR: 0x000D,
  27098. controlDC1: 0x0011,
  27099. controlDC2: 0x0012,
  27100. controlDC3: 0x0013,
  27101. controlDC4: 0x0014,
  27102. controlDEL: 0x007F,
  27103. controlDLE: 0x0010,
  27104. controlEM: 0x0019,
  27105. controlENQ: 0x0005,
  27106. controlEOT: 0x0004,
  27107. controlESC: 0x001B,
  27108. controlETB: 0x0017,
  27109. controlETX: 0x0003,
  27110. controlFF: 0x000C,
  27111. controlFS: 0x001C,
  27112. controlGS: 0x001D,
  27113. controlHT: 0x0009,
  27114. controlLF: 0x000A,
  27115. controlNAK: 0x0015,
  27116. controlRS: 0x001E,
  27117. controlSI: 0x000F,
  27118. controlSO: 0x000E,
  27119. controlSOT: 0x0002,
  27120. controlSTX: 0x0001,
  27121. controlSUB: 0x001A,
  27122. controlSYN: 0x0016,
  27123. controlUS: 0x001F,
  27124. controlVT: 0x000B,
  27125. copyright: 0x00A9,
  27126. copyrightsans: 0xF8E9,
  27127. copyrightserif: 0xF6D9,
  27128. cornerbracketleft: 0x300C,
  27129. cornerbracketlefthalfwidth: 0xFF62,
  27130. cornerbracketleftvertical: 0xFE41,
  27131. cornerbracketright: 0x300D,
  27132. cornerbracketrighthalfwidth: 0xFF63,
  27133. cornerbracketrightvertical: 0xFE42,
  27134. corporationsquare: 0x337F,
  27135. cosquare: 0x33C7,
  27136. coverkgsquare: 0x33C6,
  27137. cparen: 0x249E,
  27138. cruzeiro: 0x20A2,
  27139. cstretched: 0x0297,
  27140. curlyand: 0x22CF,
  27141. curlyor: 0x22CE,
  27142. currency: 0x00A4,
  27143. cyrBreve: 0xF6D1,
  27144. cyrFlex: 0xF6D2,
  27145. cyrbreve: 0xF6D4,
  27146. cyrflex: 0xF6D5,
  27147. d: 0x0064,
  27148. daarmenian: 0x0564,
  27149. dabengali: 0x09A6,
  27150. dadarabic: 0x0636,
  27151. dadeva: 0x0926,
  27152. dadfinalarabic: 0xFEBE,
  27153. dadinitialarabic: 0xFEBF,
  27154. dadmedialarabic: 0xFEC0,
  27155. dagesh: 0x05BC,
  27156. dageshhebrew: 0x05BC,
  27157. dagger: 0x2020,
  27158. daggerdbl: 0x2021,
  27159. dagujarati: 0x0AA6,
  27160. dagurmukhi: 0x0A26,
  27161. dahiragana: 0x3060,
  27162. dakatakana: 0x30C0,
  27163. dalarabic: 0x062F,
  27164. dalet: 0x05D3,
  27165. daletdagesh: 0xFB33,
  27166. daletdageshhebrew: 0xFB33,
  27167. dalethebrew: 0x05D3,
  27168. dalfinalarabic: 0xFEAA,
  27169. dammaarabic: 0x064F,
  27170. dammalowarabic: 0x064F,
  27171. dammatanaltonearabic: 0x064C,
  27172. dammatanarabic: 0x064C,
  27173. danda: 0x0964,
  27174. dargahebrew: 0x05A7,
  27175. dargalefthebrew: 0x05A7,
  27176. dasiapneumatacyrilliccmb: 0x0485,
  27177. dblGrave: 0xF6D3,
  27178. dblanglebracketleft: 0x300A,
  27179. dblanglebracketleftvertical: 0xFE3D,
  27180. dblanglebracketright: 0x300B,
  27181. dblanglebracketrightvertical: 0xFE3E,
  27182. dblarchinvertedbelowcmb: 0x032B,
  27183. dblarrowleft: 0x21D4,
  27184. dblarrowright: 0x21D2,
  27185. dbldanda: 0x0965,
  27186. dblgrave: 0xF6D6,
  27187. dblgravecmb: 0x030F,
  27188. dblintegral: 0x222C,
  27189. dbllowline: 0x2017,
  27190. dbllowlinecmb: 0x0333,
  27191. dbloverlinecmb: 0x033F,
  27192. dblprimemod: 0x02BA,
  27193. dblverticalbar: 0x2016,
  27194. dblverticallineabovecmb: 0x030E,
  27195. dbopomofo: 0x3109,
  27196. dbsquare: 0x33C8,
  27197. dcaron: 0x010F,
  27198. dcedilla: 0x1E11,
  27199. dcircle: 0x24D3,
  27200. dcircumflexbelow: 0x1E13,
  27201. dcroat: 0x0111,
  27202. ddabengali: 0x09A1,
  27203. ddadeva: 0x0921,
  27204. ddagujarati: 0x0AA1,
  27205. ddagurmukhi: 0x0A21,
  27206. ddalarabic: 0x0688,
  27207. ddalfinalarabic: 0xFB89,
  27208. dddhadeva: 0x095C,
  27209. ddhabengali: 0x09A2,
  27210. ddhadeva: 0x0922,
  27211. ddhagujarati: 0x0AA2,
  27212. ddhagurmukhi: 0x0A22,
  27213. ddotaccent: 0x1E0B,
  27214. ddotbelow: 0x1E0D,
  27215. decimalseparatorarabic: 0x066B,
  27216. decimalseparatorpersian: 0x066B,
  27217. decyrillic: 0x0434,
  27218. degree: 0x00B0,
  27219. dehihebrew: 0x05AD,
  27220. dehiragana: 0x3067,
  27221. deicoptic: 0x03EF,
  27222. dekatakana: 0x30C7,
  27223. deleteleft: 0x232B,
  27224. deleteright: 0x2326,
  27225. delta: 0x03B4,
  27226. deltaturned: 0x018D,
  27227. denominatorminusonenumeratorbengali: 0x09F8,
  27228. dezh: 0x02A4,
  27229. dhabengali: 0x09A7,
  27230. dhadeva: 0x0927,
  27231. dhagujarati: 0x0AA7,
  27232. dhagurmukhi: 0x0A27,
  27233. dhook: 0x0257,
  27234. dialytikatonos: 0x0385,
  27235. dialytikatonoscmb: 0x0344,
  27236. diamond: 0x2666,
  27237. diamondsuitwhite: 0x2662,
  27238. dieresis: 0x00A8,
  27239. dieresisacute: 0xF6D7,
  27240. dieresisbelowcmb: 0x0324,
  27241. dieresiscmb: 0x0308,
  27242. dieresisgrave: 0xF6D8,
  27243. dieresistonos: 0x0385,
  27244. dihiragana: 0x3062,
  27245. dikatakana: 0x30C2,
  27246. dittomark: 0x3003,
  27247. divide: 0x00F7,
  27248. divides: 0x2223,
  27249. divisionslash: 0x2215,
  27250. djecyrillic: 0x0452,
  27251. dkshade: 0x2593,
  27252. dlinebelow: 0x1E0F,
  27253. dlsquare: 0x3397,
  27254. dmacron: 0x0111,
  27255. dmonospace: 0xFF44,
  27256. dnblock: 0x2584,
  27257. dochadathai: 0x0E0E,
  27258. dodekthai: 0x0E14,
  27259. dohiragana: 0x3069,
  27260. dokatakana: 0x30C9,
  27261. dollar: 0x0024,
  27262. dollarinferior: 0xF6E3,
  27263. dollarmonospace: 0xFF04,
  27264. dollaroldstyle: 0xF724,
  27265. dollarsmall: 0xFE69,
  27266. dollarsuperior: 0xF6E4,
  27267. dong: 0x20AB,
  27268. dorusquare: 0x3326,
  27269. dotaccent: 0x02D9,
  27270. dotaccentcmb: 0x0307,
  27271. dotbelowcmb: 0x0323,
  27272. dotbelowcomb: 0x0323,
  27273. dotkatakana: 0x30FB,
  27274. dotlessi: 0x0131,
  27275. dotlessj: 0xF6BE,
  27276. dotlessjstrokehook: 0x0284,
  27277. dotmath: 0x22C5,
  27278. dottedcircle: 0x25CC,
  27279. doubleyodpatah: 0xFB1F,
  27280. doubleyodpatahhebrew: 0xFB1F,
  27281. downtackbelowcmb: 0x031E,
  27282. downtackmod: 0x02D5,
  27283. dparen: 0x249F,
  27284. dsuperior: 0xF6EB,
  27285. dtail: 0x0256,
  27286. dtopbar: 0x018C,
  27287. duhiragana: 0x3065,
  27288. dukatakana: 0x30C5,
  27289. dz: 0x01F3,
  27290. dzaltone: 0x02A3,
  27291. dzcaron: 0x01C6,
  27292. dzcurl: 0x02A5,
  27293. dzeabkhasiancyrillic: 0x04E1,
  27294. dzecyrillic: 0x0455,
  27295. dzhecyrillic: 0x045F,
  27296. e: 0x0065,
  27297. eacute: 0x00E9,
  27298. earth: 0x2641,
  27299. ebengali: 0x098F,
  27300. ebopomofo: 0x311C,
  27301. ebreve: 0x0115,
  27302. ecandradeva: 0x090D,
  27303. ecandragujarati: 0x0A8D,
  27304. ecandravowelsigndeva: 0x0945,
  27305. ecandravowelsigngujarati: 0x0AC5,
  27306. ecaron: 0x011B,
  27307. ecedillabreve: 0x1E1D,
  27308. echarmenian: 0x0565,
  27309. echyiwnarmenian: 0x0587,
  27310. ecircle: 0x24D4,
  27311. ecircumflex: 0x00EA,
  27312. ecircumflexacute: 0x1EBF,
  27313. ecircumflexbelow: 0x1E19,
  27314. ecircumflexdotbelow: 0x1EC7,
  27315. ecircumflexgrave: 0x1EC1,
  27316. ecircumflexhookabove: 0x1EC3,
  27317. ecircumflextilde: 0x1EC5,
  27318. ecyrillic: 0x0454,
  27319. edblgrave: 0x0205,
  27320. edeva: 0x090F,
  27321. edieresis: 0x00EB,
  27322. edot: 0x0117,
  27323. edotaccent: 0x0117,
  27324. edotbelow: 0x1EB9,
  27325. eegurmukhi: 0x0A0F,
  27326. eematragurmukhi: 0x0A47,
  27327. efcyrillic: 0x0444,
  27328. egrave: 0x00E8,
  27329. egujarati: 0x0A8F,
  27330. eharmenian: 0x0567,
  27331. ehbopomofo: 0x311D,
  27332. ehiragana: 0x3048,
  27333. ehookabove: 0x1EBB,
  27334. eibopomofo: 0x311F,
  27335. eight: 0x0038,
  27336. eightarabic: 0x0668,
  27337. eightbengali: 0x09EE,
  27338. eightcircle: 0x2467,
  27339. eightcircleinversesansserif: 0x2791,
  27340. eightdeva: 0x096E,
  27341. eighteencircle: 0x2471,
  27342. eighteenparen: 0x2485,
  27343. eighteenperiod: 0x2499,
  27344. eightgujarati: 0x0AEE,
  27345. eightgurmukhi: 0x0A6E,
  27346. eighthackarabic: 0x0668,
  27347. eighthangzhou: 0x3028,
  27348. eighthnotebeamed: 0x266B,
  27349. eightideographicparen: 0x3227,
  27350. eightinferior: 0x2088,
  27351. eightmonospace: 0xFF18,
  27352. eightoldstyle: 0xF738,
  27353. eightparen: 0x247B,
  27354. eightperiod: 0x248F,
  27355. eightpersian: 0x06F8,
  27356. eightroman: 0x2177,
  27357. eightsuperior: 0x2078,
  27358. eightthai: 0x0E58,
  27359. einvertedbreve: 0x0207,
  27360. eiotifiedcyrillic: 0x0465,
  27361. ekatakana: 0x30A8,
  27362. ekatakanahalfwidth: 0xFF74,
  27363. ekonkargurmukhi: 0x0A74,
  27364. ekorean: 0x3154,
  27365. elcyrillic: 0x043B,
  27366. element: 0x2208,
  27367. elevencircle: 0x246A,
  27368. elevenparen: 0x247E,
  27369. elevenperiod: 0x2492,
  27370. elevenroman: 0x217A,
  27371. ellipsis: 0x2026,
  27372. ellipsisvertical: 0x22EE,
  27373. emacron: 0x0113,
  27374. emacronacute: 0x1E17,
  27375. emacrongrave: 0x1E15,
  27376. emcyrillic: 0x043C,
  27377. emdash: 0x2014,
  27378. emdashvertical: 0xFE31,
  27379. emonospace: 0xFF45,
  27380. emphasismarkarmenian: 0x055B,
  27381. emptyset: 0x2205,
  27382. enbopomofo: 0x3123,
  27383. encyrillic: 0x043D,
  27384. endash: 0x2013,
  27385. endashvertical: 0xFE32,
  27386. endescendercyrillic: 0x04A3,
  27387. eng: 0x014B,
  27388. engbopomofo: 0x3125,
  27389. enghecyrillic: 0x04A5,
  27390. enhookcyrillic: 0x04C8,
  27391. enspace: 0x2002,
  27392. eogonek: 0x0119,
  27393. eokorean: 0x3153,
  27394. eopen: 0x025B,
  27395. eopenclosed: 0x029A,
  27396. eopenreversed: 0x025C,
  27397. eopenreversedclosed: 0x025E,
  27398. eopenreversedhook: 0x025D,
  27399. eparen: 0x24A0,
  27400. epsilon: 0x03B5,
  27401. epsilontonos: 0x03AD,
  27402. equal: 0x003D,
  27403. equalmonospace: 0xFF1D,
  27404. equalsmall: 0xFE66,
  27405. equalsuperior: 0x207C,
  27406. equivalence: 0x2261,
  27407. erbopomofo: 0x3126,
  27408. ercyrillic: 0x0440,
  27409. ereversed: 0x0258,
  27410. ereversedcyrillic: 0x044D,
  27411. escyrillic: 0x0441,
  27412. esdescendercyrillic: 0x04AB,
  27413. esh: 0x0283,
  27414. eshcurl: 0x0286,
  27415. eshortdeva: 0x090E,
  27416. eshortvowelsigndeva: 0x0946,
  27417. eshreversedloop: 0x01AA,
  27418. eshsquatreversed: 0x0285,
  27419. esmallhiragana: 0x3047,
  27420. esmallkatakana: 0x30A7,
  27421. esmallkatakanahalfwidth: 0xFF6A,
  27422. estimated: 0x212E,
  27423. esuperior: 0xF6EC,
  27424. eta: 0x03B7,
  27425. etarmenian: 0x0568,
  27426. etatonos: 0x03AE,
  27427. eth: 0x00F0,
  27428. etilde: 0x1EBD,
  27429. etildebelow: 0x1E1B,
  27430. etnahtafoukhhebrew: 0x0591,
  27431. etnahtafoukhlefthebrew: 0x0591,
  27432. etnahtahebrew: 0x0591,
  27433. etnahtalefthebrew: 0x0591,
  27434. eturned: 0x01DD,
  27435. eukorean: 0x3161,
  27436. euro: 0x20AC,
  27437. evowelsignbengali: 0x09C7,
  27438. evowelsigndeva: 0x0947,
  27439. evowelsigngujarati: 0x0AC7,
  27440. exclam: 0x0021,
  27441. exclamarmenian: 0x055C,
  27442. exclamdbl: 0x203C,
  27443. exclamdown: 0x00A1,
  27444. exclamdownsmall: 0xF7A1,
  27445. exclammonospace: 0xFF01,
  27446. exclamsmall: 0xF721,
  27447. existential: 0x2203,
  27448. ezh: 0x0292,
  27449. ezhcaron: 0x01EF,
  27450. ezhcurl: 0x0293,
  27451. ezhreversed: 0x01B9,
  27452. ezhtail: 0x01BA,
  27453. f: 0x0066,
  27454. fadeva: 0x095E,
  27455. fagurmukhi: 0x0A5E,
  27456. fahrenheit: 0x2109,
  27457. fathaarabic: 0x064E,
  27458. fathalowarabic: 0x064E,
  27459. fathatanarabic: 0x064B,
  27460. fbopomofo: 0x3108,
  27461. fcircle: 0x24D5,
  27462. fdotaccent: 0x1E1F,
  27463. feharabic: 0x0641,
  27464. feharmenian: 0x0586,
  27465. fehfinalarabic: 0xFED2,
  27466. fehinitialarabic: 0xFED3,
  27467. fehmedialarabic: 0xFED4,
  27468. feicoptic: 0x03E5,
  27469. female: 0x2640,
  27470. ff: 0xFB00,
  27471. ffi: 0xFB03,
  27472. ffl: 0xFB04,
  27473. fi: 0xFB01,
  27474. fifteencircle: 0x246E,
  27475. fifteenparen: 0x2482,
  27476. fifteenperiod: 0x2496,
  27477. figuredash: 0x2012,
  27478. filledbox: 0x25A0,
  27479. filledrect: 0x25AC,
  27480. finalkaf: 0x05DA,
  27481. finalkafdagesh: 0xFB3A,
  27482. finalkafdageshhebrew: 0xFB3A,
  27483. finalkafhebrew: 0x05DA,
  27484. finalmem: 0x05DD,
  27485. finalmemhebrew: 0x05DD,
  27486. finalnun: 0x05DF,
  27487. finalnunhebrew: 0x05DF,
  27488. finalpe: 0x05E3,
  27489. finalpehebrew: 0x05E3,
  27490. finaltsadi: 0x05E5,
  27491. finaltsadihebrew: 0x05E5,
  27492. firsttonechinese: 0x02C9,
  27493. fisheye: 0x25C9,
  27494. fitacyrillic: 0x0473,
  27495. five: 0x0035,
  27496. fivearabic: 0x0665,
  27497. fivebengali: 0x09EB,
  27498. fivecircle: 0x2464,
  27499. fivecircleinversesansserif: 0x278E,
  27500. fivedeva: 0x096B,
  27501. fiveeighths: 0x215D,
  27502. fivegujarati: 0x0AEB,
  27503. fivegurmukhi: 0x0A6B,
  27504. fivehackarabic: 0x0665,
  27505. fivehangzhou: 0x3025,
  27506. fiveideographicparen: 0x3224,
  27507. fiveinferior: 0x2085,
  27508. fivemonospace: 0xFF15,
  27509. fiveoldstyle: 0xF735,
  27510. fiveparen: 0x2478,
  27511. fiveperiod: 0x248C,
  27512. fivepersian: 0x06F5,
  27513. fiveroman: 0x2174,
  27514. fivesuperior: 0x2075,
  27515. fivethai: 0x0E55,
  27516. fl: 0xFB02,
  27517. florin: 0x0192,
  27518. fmonospace: 0xFF46,
  27519. fmsquare: 0x3399,
  27520. fofanthai: 0x0E1F,
  27521. fofathai: 0x0E1D,
  27522. fongmanthai: 0x0E4F,
  27523. forall: 0x2200,
  27524. four: 0x0034,
  27525. fourarabic: 0x0664,
  27526. fourbengali: 0x09EA,
  27527. fourcircle: 0x2463,
  27528. fourcircleinversesansserif: 0x278D,
  27529. fourdeva: 0x096A,
  27530. fourgujarati: 0x0AEA,
  27531. fourgurmukhi: 0x0A6A,
  27532. fourhackarabic: 0x0664,
  27533. fourhangzhou: 0x3024,
  27534. fourideographicparen: 0x3223,
  27535. fourinferior: 0x2084,
  27536. fourmonospace: 0xFF14,
  27537. fournumeratorbengali: 0x09F7,
  27538. fouroldstyle: 0xF734,
  27539. fourparen: 0x2477,
  27540. fourperiod: 0x248B,
  27541. fourpersian: 0x06F4,
  27542. fourroman: 0x2173,
  27543. foursuperior: 0x2074,
  27544. fourteencircle: 0x246D,
  27545. fourteenparen: 0x2481,
  27546. fourteenperiod: 0x2495,
  27547. fourthai: 0x0E54,
  27548. fourthtonechinese: 0x02CB,
  27549. fparen: 0x24A1,
  27550. fraction: 0x2044,
  27551. franc: 0x20A3,
  27552. g: 0x0067,
  27553. gabengali: 0x0997,
  27554. gacute: 0x01F5,
  27555. gadeva: 0x0917,
  27556. gafarabic: 0x06AF,
  27557. gaffinalarabic: 0xFB93,
  27558. gafinitialarabic: 0xFB94,
  27559. gafmedialarabic: 0xFB95,
  27560. gagujarati: 0x0A97,
  27561. gagurmukhi: 0x0A17,
  27562. gahiragana: 0x304C,
  27563. gakatakana: 0x30AC,
  27564. gamma: 0x03B3,
  27565. gammalatinsmall: 0x0263,
  27566. gammasuperior: 0x02E0,
  27567. gangiacoptic: 0x03EB,
  27568. gbopomofo: 0x310D,
  27569. gbreve: 0x011F,
  27570. gcaron: 0x01E7,
  27571. gcedilla: 0x0123,
  27572. gcircle: 0x24D6,
  27573. gcircumflex: 0x011D,
  27574. gcommaaccent: 0x0123,
  27575. gdot: 0x0121,
  27576. gdotaccent: 0x0121,
  27577. gecyrillic: 0x0433,
  27578. gehiragana: 0x3052,
  27579. gekatakana: 0x30B2,
  27580. geometricallyequal: 0x2251,
  27581. gereshaccenthebrew: 0x059C,
  27582. gereshhebrew: 0x05F3,
  27583. gereshmuqdamhebrew: 0x059D,
  27584. germandbls: 0x00DF,
  27585. gershayimaccenthebrew: 0x059E,
  27586. gershayimhebrew: 0x05F4,
  27587. getamark: 0x3013,
  27588. ghabengali: 0x0998,
  27589. ghadarmenian: 0x0572,
  27590. ghadeva: 0x0918,
  27591. ghagujarati: 0x0A98,
  27592. ghagurmukhi: 0x0A18,
  27593. ghainarabic: 0x063A,
  27594. ghainfinalarabic: 0xFECE,
  27595. ghaininitialarabic: 0xFECF,
  27596. ghainmedialarabic: 0xFED0,
  27597. ghemiddlehookcyrillic: 0x0495,
  27598. ghestrokecyrillic: 0x0493,
  27599. gheupturncyrillic: 0x0491,
  27600. ghhadeva: 0x095A,
  27601. ghhagurmukhi: 0x0A5A,
  27602. ghook: 0x0260,
  27603. ghzsquare: 0x3393,
  27604. gihiragana: 0x304E,
  27605. gikatakana: 0x30AE,
  27606. gimarmenian: 0x0563,
  27607. gimel: 0x05D2,
  27608. gimeldagesh: 0xFB32,
  27609. gimeldageshhebrew: 0xFB32,
  27610. gimelhebrew: 0x05D2,
  27611. gjecyrillic: 0x0453,
  27612. glottalinvertedstroke: 0x01BE,
  27613. glottalstop: 0x0294,
  27614. glottalstopinverted: 0x0296,
  27615. glottalstopmod: 0x02C0,
  27616. glottalstopreversed: 0x0295,
  27617. glottalstopreversedmod: 0x02C1,
  27618. glottalstopreversedsuperior: 0x02E4,
  27619. glottalstopstroke: 0x02A1,
  27620. glottalstopstrokereversed: 0x02A2,
  27621. gmacron: 0x1E21,
  27622. gmonospace: 0xFF47,
  27623. gohiragana: 0x3054,
  27624. gokatakana: 0x30B4,
  27625. gparen: 0x24A2,
  27626. gpasquare: 0x33AC,
  27627. gradient: 0x2207,
  27628. grave: 0x0060,
  27629. gravebelowcmb: 0x0316,
  27630. gravecmb: 0x0300,
  27631. gravecomb: 0x0300,
  27632. gravedeva: 0x0953,
  27633. gravelowmod: 0x02CE,
  27634. gravemonospace: 0xFF40,
  27635. gravetonecmb: 0x0340,
  27636. greater: 0x003E,
  27637. greaterequal: 0x2265,
  27638. greaterequalorless: 0x22DB,
  27639. greatermonospace: 0xFF1E,
  27640. greaterorequivalent: 0x2273,
  27641. greaterorless: 0x2277,
  27642. greateroverequal: 0x2267,
  27643. greatersmall: 0xFE65,
  27644. gscript: 0x0261,
  27645. gstroke: 0x01E5,
  27646. guhiragana: 0x3050,
  27647. guillemotleft: 0x00AB,
  27648. guillemotright: 0x00BB,
  27649. guilsinglleft: 0x2039,
  27650. guilsinglright: 0x203A,
  27651. gukatakana: 0x30B0,
  27652. guramusquare: 0x3318,
  27653. gysquare: 0x33C9,
  27654. h: 0x0068,
  27655. haabkhasiancyrillic: 0x04A9,
  27656. haaltonearabic: 0x06C1,
  27657. habengali: 0x09B9,
  27658. hadescendercyrillic: 0x04B3,
  27659. hadeva: 0x0939,
  27660. hagujarati: 0x0AB9,
  27661. hagurmukhi: 0x0A39,
  27662. haharabic: 0x062D,
  27663. hahfinalarabic: 0xFEA2,
  27664. hahinitialarabic: 0xFEA3,
  27665. hahiragana: 0x306F,
  27666. hahmedialarabic: 0xFEA4,
  27667. haitusquare: 0x332A,
  27668. hakatakana: 0x30CF,
  27669. hakatakanahalfwidth: 0xFF8A,
  27670. halantgurmukhi: 0x0A4D,
  27671. hamzaarabic: 0x0621,
  27672. hamzalowarabic: 0x0621,
  27673. hangulfiller: 0x3164,
  27674. hardsigncyrillic: 0x044A,
  27675. harpoonleftbarbup: 0x21BC,
  27676. harpoonrightbarbup: 0x21C0,
  27677. hasquare: 0x33CA,
  27678. hatafpatah: 0x05B2,
  27679. hatafpatah16: 0x05B2,
  27680. hatafpatah23: 0x05B2,
  27681. hatafpatah2f: 0x05B2,
  27682. hatafpatahhebrew: 0x05B2,
  27683. hatafpatahnarrowhebrew: 0x05B2,
  27684. hatafpatahquarterhebrew: 0x05B2,
  27685. hatafpatahwidehebrew: 0x05B2,
  27686. hatafqamats: 0x05B3,
  27687. hatafqamats1b: 0x05B3,
  27688. hatafqamats28: 0x05B3,
  27689. hatafqamats34: 0x05B3,
  27690. hatafqamatshebrew: 0x05B3,
  27691. hatafqamatsnarrowhebrew: 0x05B3,
  27692. hatafqamatsquarterhebrew: 0x05B3,
  27693. hatafqamatswidehebrew: 0x05B3,
  27694. hatafsegol: 0x05B1,
  27695. hatafsegol17: 0x05B1,
  27696. hatafsegol24: 0x05B1,
  27697. hatafsegol30: 0x05B1,
  27698. hatafsegolhebrew: 0x05B1,
  27699. hatafsegolnarrowhebrew: 0x05B1,
  27700. hatafsegolquarterhebrew: 0x05B1,
  27701. hatafsegolwidehebrew: 0x05B1,
  27702. hbar: 0x0127,
  27703. hbopomofo: 0x310F,
  27704. hbrevebelow: 0x1E2B,
  27705. hcedilla: 0x1E29,
  27706. hcircle: 0x24D7,
  27707. hcircumflex: 0x0125,
  27708. hdieresis: 0x1E27,
  27709. hdotaccent: 0x1E23,
  27710. hdotbelow: 0x1E25,
  27711. he: 0x05D4,
  27712. heart: 0x2665,
  27713. heartsuitblack: 0x2665,
  27714. heartsuitwhite: 0x2661,
  27715. hedagesh: 0xFB34,
  27716. hedageshhebrew: 0xFB34,
  27717. hehaltonearabic: 0x06C1,
  27718. heharabic: 0x0647,
  27719. hehebrew: 0x05D4,
  27720. hehfinalaltonearabic: 0xFBA7,
  27721. hehfinalalttwoarabic: 0xFEEA,
  27722. hehfinalarabic: 0xFEEA,
  27723. hehhamzaabovefinalarabic: 0xFBA5,
  27724. hehhamzaaboveisolatedarabic: 0xFBA4,
  27725. hehinitialaltonearabic: 0xFBA8,
  27726. hehinitialarabic: 0xFEEB,
  27727. hehiragana: 0x3078,
  27728. hehmedialaltonearabic: 0xFBA9,
  27729. hehmedialarabic: 0xFEEC,
  27730. heiseierasquare: 0x337B,
  27731. hekatakana: 0x30D8,
  27732. hekatakanahalfwidth: 0xFF8D,
  27733. hekutaarusquare: 0x3336,
  27734. henghook: 0x0267,
  27735. herutusquare: 0x3339,
  27736. het: 0x05D7,
  27737. hethebrew: 0x05D7,
  27738. hhook: 0x0266,
  27739. hhooksuperior: 0x02B1,
  27740. hieuhacirclekorean: 0x327B,
  27741. hieuhaparenkorean: 0x321B,
  27742. hieuhcirclekorean: 0x326D,
  27743. hieuhkorean: 0x314E,
  27744. hieuhparenkorean: 0x320D,
  27745. hihiragana: 0x3072,
  27746. hikatakana: 0x30D2,
  27747. hikatakanahalfwidth: 0xFF8B,
  27748. hiriq: 0x05B4,
  27749. hiriq14: 0x05B4,
  27750. hiriq21: 0x05B4,
  27751. hiriq2d: 0x05B4,
  27752. hiriqhebrew: 0x05B4,
  27753. hiriqnarrowhebrew: 0x05B4,
  27754. hiriqquarterhebrew: 0x05B4,
  27755. hiriqwidehebrew: 0x05B4,
  27756. hlinebelow: 0x1E96,
  27757. hmonospace: 0xFF48,
  27758. hoarmenian: 0x0570,
  27759. hohipthai: 0x0E2B,
  27760. hohiragana: 0x307B,
  27761. hokatakana: 0x30DB,
  27762. hokatakanahalfwidth: 0xFF8E,
  27763. holam: 0x05B9,
  27764. holam19: 0x05B9,
  27765. holam26: 0x05B9,
  27766. holam32: 0x05B9,
  27767. holamhebrew: 0x05B9,
  27768. holamnarrowhebrew: 0x05B9,
  27769. holamquarterhebrew: 0x05B9,
  27770. holamwidehebrew: 0x05B9,
  27771. honokhukthai: 0x0E2E,
  27772. hookabovecomb: 0x0309,
  27773. hookcmb: 0x0309,
  27774. hookpalatalizedbelowcmb: 0x0321,
  27775. hookretroflexbelowcmb: 0x0322,
  27776. hoonsquare: 0x3342,
  27777. horicoptic: 0x03E9,
  27778. horizontalbar: 0x2015,
  27779. horncmb: 0x031B,
  27780. hotsprings: 0x2668,
  27781. house: 0x2302,
  27782. hparen: 0x24A3,
  27783. hsuperior: 0x02B0,
  27784. hturned: 0x0265,
  27785. huhiragana: 0x3075,
  27786. huiitosquare: 0x3333,
  27787. hukatakana: 0x30D5,
  27788. hukatakanahalfwidth: 0xFF8C,
  27789. hungarumlaut: 0x02DD,
  27790. hungarumlautcmb: 0x030B,
  27791. hv: 0x0195,
  27792. hyphen: 0x002D,
  27793. hypheninferior: 0xF6E5,
  27794. hyphenmonospace: 0xFF0D,
  27795. hyphensmall: 0xFE63,
  27796. hyphensuperior: 0xF6E6,
  27797. hyphentwo: 0x2010,
  27798. i: 0x0069,
  27799. iacute: 0x00ED,
  27800. iacyrillic: 0x044F,
  27801. ibengali: 0x0987,
  27802. ibopomofo: 0x3127,
  27803. ibreve: 0x012D,
  27804. icaron: 0x01D0,
  27805. icircle: 0x24D8,
  27806. icircumflex: 0x00EE,
  27807. icyrillic: 0x0456,
  27808. idblgrave: 0x0209,
  27809. ideographearthcircle: 0x328F,
  27810. ideographfirecircle: 0x328B,
  27811. ideographicallianceparen: 0x323F,
  27812. ideographiccallparen: 0x323A,
  27813. ideographiccentrecircle: 0x32A5,
  27814. ideographicclose: 0x3006,
  27815. ideographiccomma: 0x3001,
  27816. ideographiccommaleft: 0xFF64,
  27817. ideographiccongratulationparen: 0x3237,
  27818. ideographiccorrectcircle: 0x32A3,
  27819. ideographicearthparen: 0x322F,
  27820. ideographicenterpriseparen: 0x323D,
  27821. ideographicexcellentcircle: 0x329D,
  27822. ideographicfestivalparen: 0x3240,
  27823. ideographicfinancialcircle: 0x3296,
  27824. ideographicfinancialparen: 0x3236,
  27825. ideographicfireparen: 0x322B,
  27826. ideographichaveparen: 0x3232,
  27827. ideographichighcircle: 0x32A4,
  27828. ideographiciterationmark: 0x3005,
  27829. ideographiclaborcircle: 0x3298,
  27830. ideographiclaborparen: 0x3238,
  27831. ideographicleftcircle: 0x32A7,
  27832. ideographiclowcircle: 0x32A6,
  27833. ideographicmedicinecircle: 0x32A9,
  27834. ideographicmetalparen: 0x322E,
  27835. ideographicmoonparen: 0x322A,
  27836. ideographicnameparen: 0x3234,
  27837. ideographicperiod: 0x3002,
  27838. ideographicprintcircle: 0x329E,
  27839. ideographicreachparen: 0x3243,
  27840. ideographicrepresentparen: 0x3239,
  27841. ideographicresourceparen: 0x323E,
  27842. ideographicrightcircle: 0x32A8,
  27843. ideographicsecretcircle: 0x3299,
  27844. ideographicselfparen: 0x3242,
  27845. ideographicsocietyparen: 0x3233,
  27846. ideographicspace: 0x3000,
  27847. ideographicspecialparen: 0x3235,
  27848. ideographicstockparen: 0x3231,
  27849. ideographicstudyparen: 0x323B,
  27850. ideographicsunparen: 0x3230,
  27851. ideographicsuperviseparen: 0x323C,
  27852. ideographicwaterparen: 0x322C,
  27853. ideographicwoodparen: 0x322D,
  27854. ideographiczero: 0x3007,
  27855. ideographmetalcircle: 0x328E,
  27856. ideographmooncircle: 0x328A,
  27857. ideographnamecircle: 0x3294,
  27858. ideographsuncircle: 0x3290,
  27859. ideographwatercircle: 0x328C,
  27860. ideographwoodcircle: 0x328D,
  27861. ideva: 0x0907,
  27862. idieresis: 0x00EF,
  27863. idieresisacute: 0x1E2F,
  27864. idieresiscyrillic: 0x04E5,
  27865. idotbelow: 0x1ECB,
  27866. iebrevecyrillic: 0x04D7,
  27867. iecyrillic: 0x0435,
  27868. ieungacirclekorean: 0x3275,
  27869. ieungaparenkorean: 0x3215,
  27870. ieungcirclekorean: 0x3267,
  27871. ieungkorean: 0x3147,
  27872. ieungparenkorean: 0x3207,
  27873. igrave: 0x00EC,
  27874. igujarati: 0x0A87,
  27875. igurmukhi: 0x0A07,
  27876. ihiragana: 0x3044,
  27877. ihookabove: 0x1EC9,
  27878. iibengali: 0x0988,
  27879. iicyrillic: 0x0438,
  27880. iideva: 0x0908,
  27881. iigujarati: 0x0A88,
  27882. iigurmukhi: 0x0A08,
  27883. iimatragurmukhi: 0x0A40,
  27884. iinvertedbreve: 0x020B,
  27885. iishortcyrillic: 0x0439,
  27886. iivowelsignbengali: 0x09C0,
  27887. iivowelsigndeva: 0x0940,
  27888. iivowelsigngujarati: 0x0AC0,
  27889. ij: 0x0133,
  27890. ikatakana: 0x30A4,
  27891. ikatakanahalfwidth: 0xFF72,
  27892. ikorean: 0x3163,
  27893. ilde: 0x02DC,
  27894. iluyhebrew: 0x05AC,
  27895. imacron: 0x012B,
  27896. imacroncyrillic: 0x04E3,
  27897. imageorapproximatelyequal: 0x2253,
  27898. imatragurmukhi: 0x0A3F,
  27899. imonospace: 0xFF49,
  27900. increment: 0x2206,
  27901. infinity: 0x221E,
  27902. iniarmenian: 0x056B,
  27903. integral: 0x222B,
  27904. integralbottom: 0x2321,
  27905. integralbt: 0x2321,
  27906. integralex: 0xF8F5,
  27907. integraltop: 0x2320,
  27908. integraltp: 0x2320,
  27909. intersection: 0x2229,
  27910. intisquare: 0x3305,
  27911. invbullet: 0x25D8,
  27912. invcircle: 0x25D9,
  27913. invsmileface: 0x263B,
  27914. iocyrillic: 0x0451,
  27915. iogonek: 0x012F,
  27916. iota: 0x03B9,
  27917. iotadieresis: 0x03CA,
  27918. iotadieresistonos: 0x0390,
  27919. iotalatin: 0x0269,
  27920. iotatonos: 0x03AF,
  27921. iparen: 0x24A4,
  27922. irigurmukhi: 0x0A72,
  27923. ismallhiragana: 0x3043,
  27924. ismallkatakana: 0x30A3,
  27925. ismallkatakanahalfwidth: 0xFF68,
  27926. issharbengali: 0x09FA,
  27927. istroke: 0x0268,
  27928. isuperior: 0xF6ED,
  27929. iterationhiragana: 0x309D,
  27930. iterationkatakana: 0x30FD,
  27931. itilde: 0x0129,
  27932. itildebelow: 0x1E2D,
  27933. iubopomofo: 0x3129,
  27934. iucyrillic: 0x044E,
  27935. ivowelsignbengali: 0x09BF,
  27936. ivowelsigndeva: 0x093F,
  27937. ivowelsigngujarati: 0x0ABF,
  27938. izhitsacyrillic: 0x0475,
  27939. izhitsadblgravecyrillic: 0x0477,
  27940. j: 0x006A,
  27941. jaarmenian: 0x0571,
  27942. jabengali: 0x099C,
  27943. jadeva: 0x091C,
  27944. jagujarati: 0x0A9C,
  27945. jagurmukhi: 0x0A1C,
  27946. jbopomofo: 0x3110,
  27947. jcaron: 0x01F0,
  27948. jcircle: 0x24D9,
  27949. jcircumflex: 0x0135,
  27950. jcrossedtail: 0x029D,
  27951. jdotlessstroke: 0x025F,
  27952. jecyrillic: 0x0458,
  27953. jeemarabic: 0x062C,
  27954. jeemfinalarabic: 0xFE9E,
  27955. jeeminitialarabic: 0xFE9F,
  27956. jeemmedialarabic: 0xFEA0,
  27957. jeharabic: 0x0698,
  27958. jehfinalarabic: 0xFB8B,
  27959. jhabengali: 0x099D,
  27960. jhadeva: 0x091D,
  27961. jhagujarati: 0x0A9D,
  27962. jhagurmukhi: 0x0A1D,
  27963. jheharmenian: 0x057B,
  27964. jis: 0x3004,
  27965. jmonospace: 0xFF4A,
  27966. jparen: 0x24A5,
  27967. jsuperior: 0x02B2,
  27968. k: 0x006B,
  27969. kabashkircyrillic: 0x04A1,
  27970. kabengali: 0x0995,
  27971. kacute: 0x1E31,
  27972. kacyrillic: 0x043A,
  27973. kadescendercyrillic: 0x049B,
  27974. kadeva: 0x0915,
  27975. kaf: 0x05DB,
  27976. kafarabic: 0x0643,
  27977. kafdagesh: 0xFB3B,
  27978. kafdageshhebrew: 0xFB3B,
  27979. kaffinalarabic: 0xFEDA,
  27980. kafhebrew: 0x05DB,
  27981. kafinitialarabic: 0xFEDB,
  27982. kafmedialarabic: 0xFEDC,
  27983. kafrafehebrew: 0xFB4D,
  27984. kagujarati: 0x0A95,
  27985. kagurmukhi: 0x0A15,
  27986. kahiragana: 0x304B,
  27987. kahookcyrillic: 0x04C4,
  27988. kakatakana: 0x30AB,
  27989. kakatakanahalfwidth: 0xFF76,
  27990. kappa: 0x03BA,
  27991. kappasymbolgreek: 0x03F0,
  27992. kapyeounmieumkorean: 0x3171,
  27993. kapyeounphieuphkorean: 0x3184,
  27994. kapyeounpieupkorean: 0x3178,
  27995. kapyeounssangpieupkorean: 0x3179,
  27996. karoriisquare: 0x330D,
  27997. kashidaautoarabic: 0x0640,
  27998. kashidaautonosidebearingarabic: 0x0640,
  27999. kasmallkatakana: 0x30F5,
  28000. kasquare: 0x3384,
  28001. kasraarabic: 0x0650,
  28002. kasratanarabic: 0x064D,
  28003. kastrokecyrillic: 0x049F,
  28004. katahiraprolongmarkhalfwidth: 0xFF70,
  28005. kaverticalstrokecyrillic: 0x049D,
  28006. kbopomofo: 0x310E,
  28007. kcalsquare: 0x3389,
  28008. kcaron: 0x01E9,
  28009. kcedilla: 0x0137,
  28010. kcircle: 0x24DA,
  28011. kcommaaccent: 0x0137,
  28012. kdotbelow: 0x1E33,
  28013. keharmenian: 0x0584,
  28014. kehiragana: 0x3051,
  28015. kekatakana: 0x30B1,
  28016. kekatakanahalfwidth: 0xFF79,
  28017. kenarmenian: 0x056F,
  28018. kesmallkatakana: 0x30F6,
  28019. kgreenlandic: 0x0138,
  28020. khabengali: 0x0996,
  28021. khacyrillic: 0x0445,
  28022. khadeva: 0x0916,
  28023. khagujarati: 0x0A96,
  28024. khagurmukhi: 0x0A16,
  28025. khaharabic: 0x062E,
  28026. khahfinalarabic: 0xFEA6,
  28027. khahinitialarabic: 0xFEA7,
  28028. khahmedialarabic: 0xFEA8,
  28029. kheicoptic: 0x03E7,
  28030. khhadeva: 0x0959,
  28031. khhagurmukhi: 0x0A59,
  28032. khieukhacirclekorean: 0x3278,
  28033. khieukhaparenkorean: 0x3218,
  28034. khieukhcirclekorean: 0x326A,
  28035. khieukhkorean: 0x314B,
  28036. khieukhparenkorean: 0x320A,
  28037. khokhaithai: 0x0E02,
  28038. khokhonthai: 0x0E05,
  28039. khokhuatthai: 0x0E03,
  28040. khokhwaithai: 0x0E04,
  28041. khomutthai: 0x0E5B,
  28042. khook: 0x0199,
  28043. khorakhangthai: 0x0E06,
  28044. khzsquare: 0x3391,
  28045. kihiragana: 0x304D,
  28046. kikatakana: 0x30AD,
  28047. kikatakanahalfwidth: 0xFF77,
  28048. kiroguramusquare: 0x3315,
  28049. kiromeetorusquare: 0x3316,
  28050. kirosquare: 0x3314,
  28051. kiyeokacirclekorean: 0x326E,
  28052. kiyeokaparenkorean: 0x320E,
  28053. kiyeokcirclekorean: 0x3260,
  28054. kiyeokkorean: 0x3131,
  28055. kiyeokparenkorean: 0x3200,
  28056. kiyeoksioskorean: 0x3133,
  28057. kjecyrillic: 0x045C,
  28058. klinebelow: 0x1E35,
  28059. klsquare: 0x3398,
  28060. kmcubedsquare: 0x33A6,
  28061. kmonospace: 0xFF4B,
  28062. kmsquaredsquare: 0x33A2,
  28063. kohiragana: 0x3053,
  28064. kohmsquare: 0x33C0,
  28065. kokaithai: 0x0E01,
  28066. kokatakana: 0x30B3,
  28067. kokatakanahalfwidth: 0xFF7A,
  28068. kooposquare: 0x331E,
  28069. koppacyrillic: 0x0481,
  28070. koreanstandardsymbol: 0x327F,
  28071. koroniscmb: 0x0343,
  28072. kparen: 0x24A6,
  28073. kpasquare: 0x33AA,
  28074. ksicyrillic: 0x046F,
  28075. ktsquare: 0x33CF,
  28076. kturned: 0x029E,
  28077. kuhiragana: 0x304F,
  28078. kukatakana: 0x30AF,
  28079. kukatakanahalfwidth: 0xFF78,
  28080. kvsquare: 0x33B8,
  28081. kwsquare: 0x33BE,
  28082. l: 0x006C,
  28083. labengali: 0x09B2,
  28084. lacute: 0x013A,
  28085. ladeva: 0x0932,
  28086. lagujarati: 0x0AB2,
  28087. lagurmukhi: 0x0A32,
  28088. lakkhangyaothai: 0x0E45,
  28089. lamaleffinalarabic: 0xFEFC,
  28090. lamalefhamzaabovefinalarabic: 0xFEF8,
  28091. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28092. lamalefhamzabelowfinalarabic: 0xFEFA,
  28093. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28094. lamalefisolatedarabic: 0xFEFB,
  28095. lamalefmaddaabovefinalarabic: 0xFEF6,
  28096. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28097. lamarabic: 0x0644,
  28098. lambda: 0x03BB,
  28099. lambdastroke: 0x019B,
  28100. lamed: 0x05DC,
  28101. lameddagesh: 0xFB3C,
  28102. lameddageshhebrew: 0xFB3C,
  28103. lamedhebrew: 0x05DC,
  28104. lamfinalarabic: 0xFEDE,
  28105. lamhahinitialarabic: 0xFCCA,
  28106. laminitialarabic: 0xFEDF,
  28107. lamjeeminitialarabic: 0xFCC9,
  28108. lamkhahinitialarabic: 0xFCCB,
  28109. lamlamhehisolatedarabic: 0xFDF2,
  28110. lammedialarabic: 0xFEE0,
  28111. lammeemhahinitialarabic: 0xFD88,
  28112. lammeeminitialarabic: 0xFCCC,
  28113. largecircle: 0x25EF,
  28114. lbar: 0x019A,
  28115. lbelt: 0x026C,
  28116. lbopomofo: 0x310C,
  28117. lcaron: 0x013E,
  28118. lcedilla: 0x013C,
  28119. lcircle: 0x24DB,
  28120. lcircumflexbelow: 0x1E3D,
  28121. lcommaaccent: 0x013C,
  28122. ldot: 0x0140,
  28123. ldotaccent: 0x0140,
  28124. ldotbelow: 0x1E37,
  28125. ldotbelowmacron: 0x1E39,
  28126. leftangleabovecmb: 0x031A,
  28127. lefttackbelowcmb: 0x0318,
  28128. less: 0x003C,
  28129. lessequal: 0x2264,
  28130. lessequalorgreater: 0x22DA,
  28131. lessmonospace: 0xFF1C,
  28132. lessorequivalent: 0x2272,
  28133. lessorgreater: 0x2276,
  28134. lessoverequal: 0x2266,
  28135. lesssmall: 0xFE64,
  28136. lezh: 0x026E,
  28137. lfblock: 0x258C,
  28138. lhookretroflex: 0x026D,
  28139. lira: 0x20A4,
  28140. liwnarmenian: 0x056C,
  28141. lj: 0x01C9,
  28142. ljecyrillic: 0x0459,
  28143. ll: 0xF6C0,
  28144. lladeva: 0x0933,
  28145. llagujarati: 0x0AB3,
  28146. llinebelow: 0x1E3B,
  28147. llladeva: 0x0934,
  28148. llvocalicbengali: 0x09E1,
  28149. llvocalicdeva: 0x0961,
  28150. llvocalicvowelsignbengali: 0x09E3,
  28151. llvocalicvowelsigndeva: 0x0963,
  28152. lmiddletilde: 0x026B,
  28153. lmonospace: 0xFF4C,
  28154. lmsquare: 0x33D0,
  28155. lochulathai: 0x0E2C,
  28156. logicaland: 0x2227,
  28157. logicalnot: 0x00AC,
  28158. logicalnotreversed: 0x2310,
  28159. logicalor: 0x2228,
  28160. lolingthai: 0x0E25,
  28161. longs: 0x017F,
  28162. lowlinecenterline: 0xFE4E,
  28163. lowlinecmb: 0x0332,
  28164. lowlinedashed: 0xFE4D,
  28165. lozenge: 0x25CA,
  28166. lparen: 0x24A7,
  28167. lslash: 0x0142,
  28168. lsquare: 0x2113,
  28169. lsuperior: 0xF6EE,
  28170. ltshade: 0x2591,
  28171. luthai: 0x0E26,
  28172. lvocalicbengali: 0x098C,
  28173. lvocalicdeva: 0x090C,
  28174. lvocalicvowelsignbengali: 0x09E2,
  28175. lvocalicvowelsigndeva: 0x0962,
  28176. lxsquare: 0x33D3,
  28177. m: 0x006D,
  28178. mabengali: 0x09AE,
  28179. macron: 0x00AF,
  28180. macronbelowcmb: 0x0331,
  28181. macroncmb: 0x0304,
  28182. macronlowmod: 0x02CD,
  28183. macronmonospace: 0xFFE3,
  28184. macute: 0x1E3F,
  28185. madeva: 0x092E,
  28186. magujarati: 0x0AAE,
  28187. magurmukhi: 0x0A2E,
  28188. mahapakhhebrew: 0x05A4,
  28189. mahapakhlefthebrew: 0x05A4,
  28190. mahiragana: 0x307E,
  28191. maichattawalowleftthai: 0xF895,
  28192. maichattawalowrightthai: 0xF894,
  28193. maichattawathai: 0x0E4B,
  28194. maichattawaupperleftthai: 0xF893,
  28195. maieklowleftthai: 0xF88C,
  28196. maieklowrightthai: 0xF88B,
  28197. maiekthai: 0x0E48,
  28198. maiekupperleftthai: 0xF88A,
  28199. maihanakatleftthai: 0xF884,
  28200. maihanakatthai: 0x0E31,
  28201. maitaikhuleftthai: 0xF889,
  28202. maitaikhuthai: 0x0E47,
  28203. maitholowleftthai: 0xF88F,
  28204. maitholowrightthai: 0xF88E,
  28205. maithothai: 0x0E49,
  28206. maithoupperleftthai: 0xF88D,
  28207. maitrilowleftthai: 0xF892,
  28208. maitrilowrightthai: 0xF891,
  28209. maitrithai: 0x0E4A,
  28210. maitriupperleftthai: 0xF890,
  28211. maiyamokthai: 0x0E46,
  28212. makatakana: 0x30DE,
  28213. makatakanahalfwidth: 0xFF8F,
  28214. male: 0x2642,
  28215. mansyonsquare: 0x3347,
  28216. maqafhebrew: 0x05BE,
  28217. mars: 0x2642,
  28218. masoracirclehebrew: 0x05AF,
  28219. masquare: 0x3383,
  28220. mbopomofo: 0x3107,
  28221. mbsquare: 0x33D4,
  28222. mcircle: 0x24DC,
  28223. mcubedsquare: 0x33A5,
  28224. mdotaccent: 0x1E41,
  28225. mdotbelow: 0x1E43,
  28226. meemarabic: 0x0645,
  28227. meemfinalarabic: 0xFEE2,
  28228. meeminitialarabic: 0xFEE3,
  28229. meemmedialarabic: 0xFEE4,
  28230. meemmeeminitialarabic: 0xFCD1,
  28231. meemmeemisolatedarabic: 0xFC48,
  28232. meetorusquare: 0x334D,
  28233. mehiragana: 0x3081,
  28234. meizierasquare: 0x337E,
  28235. mekatakana: 0x30E1,
  28236. mekatakanahalfwidth: 0xFF92,
  28237. mem: 0x05DE,
  28238. memdagesh: 0xFB3E,
  28239. memdageshhebrew: 0xFB3E,
  28240. memhebrew: 0x05DE,
  28241. menarmenian: 0x0574,
  28242. merkhahebrew: 0x05A5,
  28243. merkhakefulahebrew: 0x05A6,
  28244. merkhakefulalefthebrew: 0x05A6,
  28245. merkhalefthebrew: 0x05A5,
  28246. mhook: 0x0271,
  28247. mhzsquare: 0x3392,
  28248. middledotkatakanahalfwidth: 0xFF65,
  28249. middot: 0x00B7,
  28250. mieumacirclekorean: 0x3272,
  28251. mieumaparenkorean: 0x3212,
  28252. mieumcirclekorean: 0x3264,
  28253. mieumkorean: 0x3141,
  28254. mieumpansioskorean: 0x3170,
  28255. mieumparenkorean: 0x3204,
  28256. mieumpieupkorean: 0x316E,
  28257. mieumsioskorean: 0x316F,
  28258. mihiragana: 0x307F,
  28259. mikatakana: 0x30DF,
  28260. mikatakanahalfwidth: 0xFF90,
  28261. minus: 0x2212,
  28262. minusbelowcmb: 0x0320,
  28263. minuscircle: 0x2296,
  28264. minusmod: 0x02D7,
  28265. minusplus: 0x2213,
  28266. minute: 0x2032,
  28267. miribaarusquare: 0x334A,
  28268. mirisquare: 0x3349,
  28269. mlonglegturned: 0x0270,
  28270. mlsquare: 0x3396,
  28271. mmcubedsquare: 0x33A3,
  28272. mmonospace: 0xFF4D,
  28273. mmsquaredsquare: 0x339F,
  28274. mohiragana: 0x3082,
  28275. mohmsquare: 0x33C1,
  28276. mokatakana: 0x30E2,
  28277. mokatakanahalfwidth: 0xFF93,
  28278. molsquare: 0x33D6,
  28279. momathai: 0x0E21,
  28280. moverssquare: 0x33A7,
  28281. moverssquaredsquare: 0x33A8,
  28282. mparen: 0x24A8,
  28283. mpasquare: 0x33AB,
  28284. mssquare: 0x33B3,
  28285. msuperior: 0xF6EF,
  28286. mturned: 0x026F,
  28287. mu: 0x00B5,
  28288. mu1: 0x00B5,
  28289. muasquare: 0x3382,
  28290. muchgreater: 0x226B,
  28291. muchless: 0x226A,
  28292. mufsquare: 0x338C,
  28293. mugreek: 0x03BC,
  28294. mugsquare: 0x338D,
  28295. muhiragana: 0x3080,
  28296. mukatakana: 0x30E0,
  28297. mukatakanahalfwidth: 0xFF91,
  28298. mulsquare: 0x3395,
  28299. multiply: 0x00D7,
  28300. mumsquare: 0x339B,
  28301. munahhebrew: 0x05A3,
  28302. munahlefthebrew: 0x05A3,
  28303. musicalnote: 0x266A,
  28304. musicalnotedbl: 0x266B,
  28305. musicflatsign: 0x266D,
  28306. musicsharpsign: 0x266F,
  28307. mussquare: 0x33B2,
  28308. muvsquare: 0x33B6,
  28309. muwsquare: 0x33BC,
  28310. mvmegasquare: 0x33B9,
  28311. mvsquare: 0x33B7,
  28312. mwmegasquare: 0x33BF,
  28313. mwsquare: 0x33BD,
  28314. n: 0x006E,
  28315. nabengali: 0x09A8,
  28316. nabla: 0x2207,
  28317. nacute: 0x0144,
  28318. nadeva: 0x0928,
  28319. nagujarati: 0x0AA8,
  28320. nagurmukhi: 0x0A28,
  28321. nahiragana: 0x306A,
  28322. nakatakana: 0x30CA,
  28323. nakatakanahalfwidth: 0xFF85,
  28324. napostrophe: 0x0149,
  28325. nasquare: 0x3381,
  28326. nbopomofo: 0x310B,
  28327. nbspace: 0x00A0,
  28328. ncaron: 0x0148,
  28329. ncedilla: 0x0146,
  28330. ncircle: 0x24DD,
  28331. ncircumflexbelow: 0x1E4B,
  28332. ncommaaccent: 0x0146,
  28333. ndotaccent: 0x1E45,
  28334. ndotbelow: 0x1E47,
  28335. nehiragana: 0x306D,
  28336. nekatakana: 0x30CD,
  28337. nekatakanahalfwidth: 0xFF88,
  28338. newsheqelsign: 0x20AA,
  28339. nfsquare: 0x338B,
  28340. ngabengali: 0x0999,
  28341. ngadeva: 0x0919,
  28342. ngagujarati: 0x0A99,
  28343. ngagurmukhi: 0x0A19,
  28344. ngonguthai: 0x0E07,
  28345. nhiragana: 0x3093,
  28346. nhookleft: 0x0272,
  28347. nhookretroflex: 0x0273,
  28348. nieunacirclekorean: 0x326F,
  28349. nieunaparenkorean: 0x320F,
  28350. nieuncieuckorean: 0x3135,
  28351. nieuncirclekorean: 0x3261,
  28352. nieunhieuhkorean: 0x3136,
  28353. nieunkorean: 0x3134,
  28354. nieunpansioskorean: 0x3168,
  28355. nieunparenkorean: 0x3201,
  28356. nieunsioskorean: 0x3167,
  28357. nieuntikeutkorean: 0x3166,
  28358. nihiragana: 0x306B,
  28359. nikatakana: 0x30CB,
  28360. nikatakanahalfwidth: 0xFF86,
  28361. nikhahitleftthai: 0xF899,
  28362. nikhahitthai: 0x0E4D,
  28363. nine: 0x0039,
  28364. ninearabic: 0x0669,
  28365. ninebengali: 0x09EF,
  28366. ninecircle: 0x2468,
  28367. ninecircleinversesansserif: 0x2792,
  28368. ninedeva: 0x096F,
  28369. ninegujarati: 0x0AEF,
  28370. ninegurmukhi: 0x0A6F,
  28371. ninehackarabic: 0x0669,
  28372. ninehangzhou: 0x3029,
  28373. nineideographicparen: 0x3228,
  28374. nineinferior: 0x2089,
  28375. ninemonospace: 0xFF19,
  28376. nineoldstyle: 0xF739,
  28377. nineparen: 0x247C,
  28378. nineperiod: 0x2490,
  28379. ninepersian: 0x06F9,
  28380. nineroman: 0x2178,
  28381. ninesuperior: 0x2079,
  28382. nineteencircle: 0x2472,
  28383. nineteenparen: 0x2486,
  28384. nineteenperiod: 0x249A,
  28385. ninethai: 0x0E59,
  28386. nj: 0x01CC,
  28387. njecyrillic: 0x045A,
  28388. nkatakana: 0x30F3,
  28389. nkatakanahalfwidth: 0xFF9D,
  28390. nlegrightlong: 0x019E,
  28391. nlinebelow: 0x1E49,
  28392. nmonospace: 0xFF4E,
  28393. nmsquare: 0x339A,
  28394. nnabengali: 0x09A3,
  28395. nnadeva: 0x0923,
  28396. nnagujarati: 0x0AA3,
  28397. nnagurmukhi: 0x0A23,
  28398. nnnadeva: 0x0929,
  28399. nohiragana: 0x306E,
  28400. nokatakana: 0x30CE,
  28401. nokatakanahalfwidth: 0xFF89,
  28402. nonbreakingspace: 0x00A0,
  28403. nonenthai: 0x0E13,
  28404. nonuthai: 0x0E19,
  28405. noonarabic: 0x0646,
  28406. noonfinalarabic: 0xFEE6,
  28407. noonghunnaarabic: 0x06BA,
  28408. noonghunnafinalarabic: 0xFB9F,
  28409. nooninitialarabic: 0xFEE7,
  28410. noonjeeminitialarabic: 0xFCD2,
  28411. noonjeemisolatedarabic: 0xFC4B,
  28412. noonmedialarabic: 0xFEE8,
  28413. noonmeeminitialarabic: 0xFCD5,
  28414. noonmeemisolatedarabic: 0xFC4E,
  28415. noonnoonfinalarabic: 0xFC8D,
  28416. notcontains: 0x220C,
  28417. notelement: 0x2209,
  28418. notelementof: 0x2209,
  28419. notequal: 0x2260,
  28420. notgreater: 0x226F,
  28421. notgreaternorequal: 0x2271,
  28422. notgreaternorless: 0x2279,
  28423. notidentical: 0x2262,
  28424. notless: 0x226E,
  28425. notlessnorequal: 0x2270,
  28426. notparallel: 0x2226,
  28427. notprecedes: 0x2280,
  28428. notsubset: 0x2284,
  28429. notsucceeds: 0x2281,
  28430. notsuperset: 0x2285,
  28431. nowarmenian: 0x0576,
  28432. nparen: 0x24A9,
  28433. nssquare: 0x33B1,
  28434. nsuperior: 0x207F,
  28435. ntilde: 0x00F1,
  28436. nu: 0x03BD,
  28437. nuhiragana: 0x306C,
  28438. nukatakana: 0x30CC,
  28439. nukatakanahalfwidth: 0xFF87,
  28440. nuktabengali: 0x09BC,
  28441. nuktadeva: 0x093C,
  28442. nuktagujarati: 0x0ABC,
  28443. nuktagurmukhi: 0x0A3C,
  28444. numbersign: 0x0023,
  28445. numbersignmonospace: 0xFF03,
  28446. numbersignsmall: 0xFE5F,
  28447. numeralsigngreek: 0x0374,
  28448. numeralsignlowergreek: 0x0375,
  28449. numero: 0x2116,
  28450. nun: 0x05E0,
  28451. nundagesh: 0xFB40,
  28452. nundageshhebrew: 0xFB40,
  28453. nunhebrew: 0x05E0,
  28454. nvsquare: 0x33B5,
  28455. nwsquare: 0x33BB,
  28456. nyabengali: 0x099E,
  28457. nyadeva: 0x091E,
  28458. nyagujarati: 0x0A9E,
  28459. nyagurmukhi: 0x0A1E,
  28460. o: 0x006F,
  28461. oacute: 0x00F3,
  28462. oangthai: 0x0E2D,
  28463. obarred: 0x0275,
  28464. obarredcyrillic: 0x04E9,
  28465. obarreddieresiscyrillic: 0x04EB,
  28466. obengali: 0x0993,
  28467. obopomofo: 0x311B,
  28468. obreve: 0x014F,
  28469. ocandradeva: 0x0911,
  28470. ocandragujarati: 0x0A91,
  28471. ocandravowelsigndeva: 0x0949,
  28472. ocandravowelsigngujarati: 0x0AC9,
  28473. ocaron: 0x01D2,
  28474. ocircle: 0x24DE,
  28475. ocircumflex: 0x00F4,
  28476. ocircumflexacute: 0x1ED1,
  28477. ocircumflexdotbelow: 0x1ED9,
  28478. ocircumflexgrave: 0x1ED3,
  28479. ocircumflexhookabove: 0x1ED5,
  28480. ocircumflextilde: 0x1ED7,
  28481. ocyrillic: 0x043E,
  28482. odblacute: 0x0151,
  28483. odblgrave: 0x020D,
  28484. odeva: 0x0913,
  28485. odieresis: 0x00F6,
  28486. odieresiscyrillic: 0x04E7,
  28487. odotbelow: 0x1ECD,
  28488. oe: 0x0153,
  28489. oekorean: 0x315A,
  28490. ogonek: 0x02DB,
  28491. ogonekcmb: 0x0328,
  28492. ograve: 0x00F2,
  28493. ogujarati: 0x0A93,
  28494. oharmenian: 0x0585,
  28495. ohiragana: 0x304A,
  28496. ohookabove: 0x1ECF,
  28497. ohorn: 0x01A1,
  28498. ohornacute: 0x1EDB,
  28499. ohorndotbelow: 0x1EE3,
  28500. ohorngrave: 0x1EDD,
  28501. ohornhookabove: 0x1EDF,
  28502. ohorntilde: 0x1EE1,
  28503. ohungarumlaut: 0x0151,
  28504. oi: 0x01A3,
  28505. oinvertedbreve: 0x020F,
  28506. okatakana: 0x30AA,
  28507. okatakanahalfwidth: 0xFF75,
  28508. okorean: 0x3157,
  28509. olehebrew: 0x05AB,
  28510. omacron: 0x014D,
  28511. omacronacute: 0x1E53,
  28512. omacrongrave: 0x1E51,
  28513. omdeva: 0x0950,
  28514. omega: 0x03C9,
  28515. omega1: 0x03D6,
  28516. omegacyrillic: 0x0461,
  28517. omegalatinclosed: 0x0277,
  28518. omegaroundcyrillic: 0x047B,
  28519. omegatitlocyrillic: 0x047D,
  28520. omegatonos: 0x03CE,
  28521. omgujarati: 0x0AD0,
  28522. omicron: 0x03BF,
  28523. omicrontonos: 0x03CC,
  28524. omonospace: 0xFF4F,
  28525. one: 0x0031,
  28526. onearabic: 0x0661,
  28527. onebengali: 0x09E7,
  28528. onecircle: 0x2460,
  28529. onecircleinversesansserif: 0x278A,
  28530. onedeva: 0x0967,
  28531. onedotenleader: 0x2024,
  28532. oneeighth: 0x215B,
  28533. onefitted: 0xF6DC,
  28534. onegujarati: 0x0AE7,
  28535. onegurmukhi: 0x0A67,
  28536. onehackarabic: 0x0661,
  28537. onehalf: 0x00BD,
  28538. onehangzhou: 0x3021,
  28539. oneideographicparen: 0x3220,
  28540. oneinferior: 0x2081,
  28541. onemonospace: 0xFF11,
  28542. onenumeratorbengali: 0x09F4,
  28543. oneoldstyle: 0xF731,
  28544. oneparen: 0x2474,
  28545. oneperiod: 0x2488,
  28546. onepersian: 0x06F1,
  28547. onequarter: 0x00BC,
  28548. oneroman: 0x2170,
  28549. onesuperior: 0x00B9,
  28550. onethai: 0x0E51,
  28551. onethird: 0x2153,
  28552. oogonek: 0x01EB,
  28553. oogonekmacron: 0x01ED,
  28554. oogurmukhi: 0x0A13,
  28555. oomatragurmukhi: 0x0A4B,
  28556. oopen: 0x0254,
  28557. oparen: 0x24AA,
  28558. openbullet: 0x25E6,
  28559. option: 0x2325,
  28560. ordfeminine: 0x00AA,
  28561. ordmasculine: 0x00BA,
  28562. orthogonal: 0x221F,
  28563. oshortdeva: 0x0912,
  28564. oshortvowelsigndeva: 0x094A,
  28565. oslash: 0x00F8,
  28566. oslashacute: 0x01FF,
  28567. osmallhiragana: 0x3049,
  28568. osmallkatakana: 0x30A9,
  28569. osmallkatakanahalfwidth: 0xFF6B,
  28570. ostrokeacute: 0x01FF,
  28571. osuperior: 0xF6F0,
  28572. otcyrillic: 0x047F,
  28573. otilde: 0x00F5,
  28574. otildeacute: 0x1E4D,
  28575. otildedieresis: 0x1E4F,
  28576. oubopomofo: 0x3121,
  28577. overline: 0x203E,
  28578. overlinecenterline: 0xFE4A,
  28579. overlinecmb: 0x0305,
  28580. overlinedashed: 0xFE49,
  28581. overlinedblwavy: 0xFE4C,
  28582. overlinewavy: 0xFE4B,
  28583. overscore: 0x00AF,
  28584. ovowelsignbengali: 0x09CB,
  28585. ovowelsigndeva: 0x094B,
  28586. ovowelsigngujarati: 0x0ACB,
  28587. p: 0x0070,
  28588. paampssquare: 0x3380,
  28589. paasentosquare: 0x332B,
  28590. pabengali: 0x09AA,
  28591. pacute: 0x1E55,
  28592. padeva: 0x092A,
  28593. pagedown: 0x21DF,
  28594. pageup: 0x21DE,
  28595. pagujarati: 0x0AAA,
  28596. pagurmukhi: 0x0A2A,
  28597. pahiragana: 0x3071,
  28598. paiyannoithai: 0x0E2F,
  28599. pakatakana: 0x30D1,
  28600. palatalizationcyrilliccmb: 0x0484,
  28601. palochkacyrillic: 0x04C0,
  28602. pansioskorean: 0x317F,
  28603. paragraph: 0x00B6,
  28604. parallel: 0x2225,
  28605. parenleft: 0x0028,
  28606. parenleftaltonearabic: 0xFD3E,
  28607. parenleftbt: 0xF8ED,
  28608. parenleftex: 0xF8EC,
  28609. parenleftinferior: 0x208D,
  28610. parenleftmonospace: 0xFF08,
  28611. parenleftsmall: 0xFE59,
  28612. parenleftsuperior: 0x207D,
  28613. parenlefttp: 0xF8EB,
  28614. parenleftvertical: 0xFE35,
  28615. parenright: 0x0029,
  28616. parenrightaltonearabic: 0xFD3F,
  28617. parenrightbt: 0xF8F8,
  28618. parenrightex: 0xF8F7,
  28619. parenrightinferior: 0x208E,
  28620. parenrightmonospace: 0xFF09,
  28621. parenrightsmall: 0xFE5A,
  28622. parenrightsuperior: 0x207E,
  28623. parenrighttp: 0xF8F6,
  28624. parenrightvertical: 0xFE36,
  28625. partialdiff: 0x2202,
  28626. paseqhebrew: 0x05C0,
  28627. pashtahebrew: 0x0599,
  28628. pasquare: 0x33A9,
  28629. patah: 0x05B7,
  28630. patah11: 0x05B7,
  28631. patah1d: 0x05B7,
  28632. patah2a: 0x05B7,
  28633. patahhebrew: 0x05B7,
  28634. patahnarrowhebrew: 0x05B7,
  28635. patahquarterhebrew: 0x05B7,
  28636. patahwidehebrew: 0x05B7,
  28637. pazerhebrew: 0x05A1,
  28638. pbopomofo: 0x3106,
  28639. pcircle: 0x24DF,
  28640. pdotaccent: 0x1E57,
  28641. pe: 0x05E4,
  28642. pecyrillic: 0x043F,
  28643. pedagesh: 0xFB44,
  28644. pedageshhebrew: 0xFB44,
  28645. peezisquare: 0x333B,
  28646. pefinaldageshhebrew: 0xFB43,
  28647. peharabic: 0x067E,
  28648. peharmenian: 0x057A,
  28649. pehebrew: 0x05E4,
  28650. pehfinalarabic: 0xFB57,
  28651. pehinitialarabic: 0xFB58,
  28652. pehiragana: 0x307A,
  28653. pehmedialarabic: 0xFB59,
  28654. pekatakana: 0x30DA,
  28655. pemiddlehookcyrillic: 0x04A7,
  28656. perafehebrew: 0xFB4E,
  28657. percent: 0x0025,
  28658. percentarabic: 0x066A,
  28659. percentmonospace: 0xFF05,
  28660. percentsmall: 0xFE6A,
  28661. period: 0x002E,
  28662. periodarmenian: 0x0589,
  28663. periodcentered: 0x00B7,
  28664. periodhalfwidth: 0xFF61,
  28665. periodinferior: 0xF6E7,
  28666. periodmonospace: 0xFF0E,
  28667. periodsmall: 0xFE52,
  28668. periodsuperior: 0xF6E8,
  28669. perispomenigreekcmb: 0x0342,
  28670. perpendicular: 0x22A5,
  28671. perthousand: 0x2030,
  28672. peseta: 0x20A7,
  28673. pfsquare: 0x338A,
  28674. phabengali: 0x09AB,
  28675. phadeva: 0x092B,
  28676. phagujarati: 0x0AAB,
  28677. phagurmukhi: 0x0A2B,
  28678. phi: 0x03C6,
  28679. phi1: 0x03D5,
  28680. phieuphacirclekorean: 0x327A,
  28681. phieuphaparenkorean: 0x321A,
  28682. phieuphcirclekorean: 0x326C,
  28683. phieuphkorean: 0x314D,
  28684. phieuphparenkorean: 0x320C,
  28685. philatin: 0x0278,
  28686. phinthuthai: 0x0E3A,
  28687. phisymbolgreek: 0x03D5,
  28688. phook: 0x01A5,
  28689. phophanthai: 0x0E1E,
  28690. phophungthai: 0x0E1C,
  28691. phosamphaothai: 0x0E20,
  28692. pi: 0x03C0,
  28693. pieupacirclekorean: 0x3273,
  28694. pieupaparenkorean: 0x3213,
  28695. pieupcieuckorean: 0x3176,
  28696. pieupcirclekorean: 0x3265,
  28697. pieupkiyeokkorean: 0x3172,
  28698. pieupkorean: 0x3142,
  28699. pieupparenkorean: 0x3205,
  28700. pieupsioskiyeokkorean: 0x3174,
  28701. pieupsioskorean: 0x3144,
  28702. pieupsiostikeutkorean: 0x3175,
  28703. pieupthieuthkorean: 0x3177,
  28704. pieuptikeutkorean: 0x3173,
  28705. pihiragana: 0x3074,
  28706. pikatakana: 0x30D4,
  28707. pisymbolgreek: 0x03D6,
  28708. piwrarmenian: 0x0583,
  28709. plus: 0x002B,
  28710. plusbelowcmb: 0x031F,
  28711. pluscircle: 0x2295,
  28712. plusminus: 0x00B1,
  28713. plusmod: 0x02D6,
  28714. plusmonospace: 0xFF0B,
  28715. plussmall: 0xFE62,
  28716. plussuperior: 0x207A,
  28717. pmonospace: 0xFF50,
  28718. pmsquare: 0x33D8,
  28719. pohiragana: 0x307D,
  28720. pointingindexdownwhite: 0x261F,
  28721. pointingindexleftwhite: 0x261C,
  28722. pointingindexrightwhite: 0x261E,
  28723. pointingindexupwhite: 0x261D,
  28724. pokatakana: 0x30DD,
  28725. poplathai: 0x0E1B,
  28726. postalmark: 0x3012,
  28727. postalmarkface: 0x3020,
  28728. pparen: 0x24AB,
  28729. precedes: 0x227A,
  28730. prescription: 0x211E,
  28731. primemod: 0x02B9,
  28732. primereversed: 0x2035,
  28733. product: 0x220F,
  28734. projective: 0x2305,
  28735. prolongedkana: 0x30FC,
  28736. propellor: 0x2318,
  28737. propersubset: 0x2282,
  28738. propersuperset: 0x2283,
  28739. proportion: 0x2237,
  28740. proportional: 0x221D,
  28741. psi: 0x03C8,
  28742. psicyrillic: 0x0471,
  28743. psilipneumatacyrilliccmb: 0x0486,
  28744. pssquare: 0x33B0,
  28745. puhiragana: 0x3077,
  28746. pukatakana: 0x30D7,
  28747. pvsquare: 0x33B4,
  28748. pwsquare: 0x33BA,
  28749. q: 0x0071,
  28750. qadeva: 0x0958,
  28751. qadmahebrew: 0x05A8,
  28752. qafarabic: 0x0642,
  28753. qaffinalarabic: 0xFED6,
  28754. qafinitialarabic: 0xFED7,
  28755. qafmedialarabic: 0xFED8,
  28756. qamats: 0x05B8,
  28757. qamats10: 0x05B8,
  28758. qamats1a: 0x05B8,
  28759. qamats1c: 0x05B8,
  28760. qamats27: 0x05B8,
  28761. qamats29: 0x05B8,
  28762. qamats33: 0x05B8,
  28763. qamatsde: 0x05B8,
  28764. qamatshebrew: 0x05B8,
  28765. qamatsnarrowhebrew: 0x05B8,
  28766. qamatsqatanhebrew: 0x05B8,
  28767. qamatsqatannarrowhebrew: 0x05B8,
  28768. qamatsqatanquarterhebrew: 0x05B8,
  28769. qamatsqatanwidehebrew: 0x05B8,
  28770. qamatsquarterhebrew: 0x05B8,
  28771. qamatswidehebrew: 0x05B8,
  28772. qarneyparahebrew: 0x059F,
  28773. qbopomofo: 0x3111,
  28774. qcircle: 0x24E0,
  28775. qhook: 0x02A0,
  28776. qmonospace: 0xFF51,
  28777. qof: 0x05E7,
  28778. qofdagesh: 0xFB47,
  28779. qofdageshhebrew: 0xFB47,
  28780. qofhebrew: 0x05E7,
  28781. qparen: 0x24AC,
  28782. quarternote: 0x2669,
  28783. qubuts: 0x05BB,
  28784. qubuts18: 0x05BB,
  28785. qubuts25: 0x05BB,
  28786. qubuts31: 0x05BB,
  28787. qubutshebrew: 0x05BB,
  28788. qubutsnarrowhebrew: 0x05BB,
  28789. qubutsquarterhebrew: 0x05BB,
  28790. qubutswidehebrew: 0x05BB,
  28791. question: 0x003F,
  28792. questionarabic: 0x061F,
  28793. questionarmenian: 0x055E,
  28794. questiondown: 0x00BF,
  28795. questiondownsmall: 0xF7BF,
  28796. questiongreek: 0x037E,
  28797. questionmonospace: 0xFF1F,
  28798. questionsmall: 0xF73F,
  28799. quotedbl: 0x0022,
  28800. quotedblbase: 0x201E,
  28801. quotedblleft: 0x201C,
  28802. quotedblmonospace: 0xFF02,
  28803. quotedblprime: 0x301E,
  28804. quotedblprimereversed: 0x301D,
  28805. quotedblright: 0x201D,
  28806. quoteleft: 0x2018,
  28807. quoteleftreversed: 0x201B,
  28808. quotereversed: 0x201B,
  28809. quoteright: 0x2019,
  28810. quoterightn: 0x0149,
  28811. quotesinglbase: 0x201A,
  28812. quotesingle: 0x0027,
  28813. quotesinglemonospace: 0xFF07,
  28814. r: 0x0072,
  28815. raarmenian: 0x057C,
  28816. rabengali: 0x09B0,
  28817. racute: 0x0155,
  28818. radeva: 0x0930,
  28819. radical: 0x221A,
  28820. radicalex: 0xF8E5,
  28821. radoverssquare: 0x33AE,
  28822. radoverssquaredsquare: 0x33AF,
  28823. radsquare: 0x33AD,
  28824. rafe: 0x05BF,
  28825. rafehebrew: 0x05BF,
  28826. ragujarati: 0x0AB0,
  28827. ragurmukhi: 0x0A30,
  28828. rahiragana: 0x3089,
  28829. rakatakana: 0x30E9,
  28830. rakatakanahalfwidth: 0xFF97,
  28831. ralowerdiagonalbengali: 0x09F1,
  28832. ramiddlediagonalbengali: 0x09F0,
  28833. ramshorn: 0x0264,
  28834. ratio: 0x2236,
  28835. rbopomofo: 0x3116,
  28836. rcaron: 0x0159,
  28837. rcedilla: 0x0157,
  28838. rcircle: 0x24E1,
  28839. rcommaaccent: 0x0157,
  28840. rdblgrave: 0x0211,
  28841. rdotaccent: 0x1E59,
  28842. rdotbelow: 0x1E5B,
  28843. rdotbelowmacron: 0x1E5D,
  28844. referencemark: 0x203B,
  28845. reflexsubset: 0x2286,
  28846. reflexsuperset: 0x2287,
  28847. registered: 0x00AE,
  28848. registersans: 0xF8E8,
  28849. registerserif: 0xF6DA,
  28850. reharabic: 0x0631,
  28851. reharmenian: 0x0580,
  28852. rehfinalarabic: 0xFEAE,
  28853. rehiragana: 0x308C,
  28854. rekatakana: 0x30EC,
  28855. rekatakanahalfwidth: 0xFF9A,
  28856. resh: 0x05E8,
  28857. reshdageshhebrew: 0xFB48,
  28858. reshhebrew: 0x05E8,
  28859. reversedtilde: 0x223D,
  28860. reviahebrew: 0x0597,
  28861. reviamugrashhebrew: 0x0597,
  28862. revlogicalnot: 0x2310,
  28863. rfishhook: 0x027E,
  28864. rfishhookreversed: 0x027F,
  28865. rhabengali: 0x09DD,
  28866. rhadeva: 0x095D,
  28867. rho: 0x03C1,
  28868. rhook: 0x027D,
  28869. rhookturned: 0x027B,
  28870. rhookturnedsuperior: 0x02B5,
  28871. rhosymbolgreek: 0x03F1,
  28872. rhotichookmod: 0x02DE,
  28873. rieulacirclekorean: 0x3271,
  28874. rieulaparenkorean: 0x3211,
  28875. rieulcirclekorean: 0x3263,
  28876. rieulhieuhkorean: 0x3140,
  28877. rieulkiyeokkorean: 0x313A,
  28878. rieulkiyeoksioskorean: 0x3169,
  28879. rieulkorean: 0x3139,
  28880. rieulmieumkorean: 0x313B,
  28881. rieulpansioskorean: 0x316C,
  28882. rieulparenkorean: 0x3203,
  28883. rieulphieuphkorean: 0x313F,
  28884. rieulpieupkorean: 0x313C,
  28885. rieulpieupsioskorean: 0x316B,
  28886. rieulsioskorean: 0x313D,
  28887. rieulthieuthkorean: 0x313E,
  28888. rieultikeutkorean: 0x316A,
  28889. rieulyeorinhieuhkorean: 0x316D,
  28890. rightangle: 0x221F,
  28891. righttackbelowcmb: 0x0319,
  28892. righttriangle: 0x22BF,
  28893. rihiragana: 0x308A,
  28894. rikatakana: 0x30EA,
  28895. rikatakanahalfwidth: 0xFF98,
  28896. ring: 0x02DA,
  28897. ringbelowcmb: 0x0325,
  28898. ringcmb: 0x030A,
  28899. ringhalfleft: 0x02BF,
  28900. ringhalfleftarmenian: 0x0559,
  28901. ringhalfleftbelowcmb: 0x031C,
  28902. ringhalfleftcentered: 0x02D3,
  28903. ringhalfright: 0x02BE,
  28904. ringhalfrightbelowcmb: 0x0339,
  28905. ringhalfrightcentered: 0x02D2,
  28906. rinvertedbreve: 0x0213,
  28907. rittorusquare: 0x3351,
  28908. rlinebelow: 0x1E5F,
  28909. rlongleg: 0x027C,
  28910. rlonglegturned: 0x027A,
  28911. rmonospace: 0xFF52,
  28912. rohiragana: 0x308D,
  28913. rokatakana: 0x30ED,
  28914. rokatakanahalfwidth: 0xFF9B,
  28915. roruathai: 0x0E23,
  28916. rparen: 0x24AD,
  28917. rrabengali: 0x09DC,
  28918. rradeva: 0x0931,
  28919. rragurmukhi: 0x0A5C,
  28920. rreharabic: 0x0691,
  28921. rrehfinalarabic: 0xFB8D,
  28922. rrvocalicbengali: 0x09E0,
  28923. rrvocalicdeva: 0x0960,
  28924. rrvocalicgujarati: 0x0AE0,
  28925. rrvocalicvowelsignbengali: 0x09C4,
  28926. rrvocalicvowelsigndeva: 0x0944,
  28927. rrvocalicvowelsigngujarati: 0x0AC4,
  28928. rsuperior: 0xF6F1,
  28929. rtblock: 0x2590,
  28930. rturned: 0x0279,
  28931. rturnedsuperior: 0x02B4,
  28932. ruhiragana: 0x308B,
  28933. rukatakana: 0x30EB,
  28934. rukatakanahalfwidth: 0xFF99,
  28935. rupeemarkbengali: 0x09F2,
  28936. rupeesignbengali: 0x09F3,
  28937. rupiah: 0xF6DD,
  28938. ruthai: 0x0E24,
  28939. rvocalicbengali: 0x098B,
  28940. rvocalicdeva: 0x090B,
  28941. rvocalicgujarati: 0x0A8B,
  28942. rvocalicvowelsignbengali: 0x09C3,
  28943. rvocalicvowelsigndeva: 0x0943,
  28944. rvocalicvowelsigngujarati: 0x0AC3,
  28945. s: 0x0073,
  28946. sabengali: 0x09B8,
  28947. sacute: 0x015B,
  28948. sacutedotaccent: 0x1E65,
  28949. sadarabic: 0x0635,
  28950. sadeva: 0x0938,
  28951. sadfinalarabic: 0xFEBA,
  28952. sadinitialarabic: 0xFEBB,
  28953. sadmedialarabic: 0xFEBC,
  28954. sagujarati: 0x0AB8,
  28955. sagurmukhi: 0x0A38,
  28956. sahiragana: 0x3055,
  28957. sakatakana: 0x30B5,
  28958. sakatakanahalfwidth: 0xFF7B,
  28959. sallallahoualayhewasallamarabic: 0xFDFA,
  28960. samekh: 0x05E1,
  28961. samekhdagesh: 0xFB41,
  28962. samekhdageshhebrew: 0xFB41,
  28963. samekhhebrew: 0x05E1,
  28964. saraaathai: 0x0E32,
  28965. saraaethai: 0x0E41,
  28966. saraaimaimalaithai: 0x0E44,
  28967. saraaimaimuanthai: 0x0E43,
  28968. saraamthai: 0x0E33,
  28969. saraathai: 0x0E30,
  28970. saraethai: 0x0E40,
  28971. saraiileftthai: 0xF886,
  28972. saraiithai: 0x0E35,
  28973. saraileftthai: 0xF885,
  28974. saraithai: 0x0E34,
  28975. saraothai: 0x0E42,
  28976. saraueeleftthai: 0xF888,
  28977. saraueethai: 0x0E37,
  28978. saraueleftthai: 0xF887,
  28979. sarauethai: 0x0E36,
  28980. sarauthai: 0x0E38,
  28981. sarauuthai: 0x0E39,
  28982. sbopomofo: 0x3119,
  28983. scaron: 0x0161,
  28984. scarondotaccent: 0x1E67,
  28985. scedilla: 0x015F,
  28986. schwa: 0x0259,
  28987. schwacyrillic: 0x04D9,
  28988. schwadieresiscyrillic: 0x04DB,
  28989. schwahook: 0x025A,
  28990. scircle: 0x24E2,
  28991. scircumflex: 0x015D,
  28992. scommaaccent: 0x0219,
  28993. sdotaccent: 0x1E61,
  28994. sdotbelow: 0x1E63,
  28995. sdotbelowdotaccent: 0x1E69,
  28996. seagullbelowcmb: 0x033C,
  28997. second: 0x2033,
  28998. secondtonechinese: 0x02CA,
  28999. section: 0x00A7,
  29000. seenarabic: 0x0633,
  29001. seenfinalarabic: 0xFEB2,
  29002. seeninitialarabic: 0xFEB3,
  29003. seenmedialarabic: 0xFEB4,
  29004. segol: 0x05B6,
  29005. segol13: 0x05B6,
  29006. segol1f: 0x05B6,
  29007. segol2c: 0x05B6,
  29008. segolhebrew: 0x05B6,
  29009. segolnarrowhebrew: 0x05B6,
  29010. segolquarterhebrew: 0x05B6,
  29011. segoltahebrew: 0x0592,
  29012. segolwidehebrew: 0x05B6,
  29013. seharmenian: 0x057D,
  29014. sehiragana: 0x305B,
  29015. sekatakana: 0x30BB,
  29016. sekatakanahalfwidth: 0xFF7E,
  29017. semicolon: 0x003B,
  29018. semicolonarabic: 0x061B,
  29019. semicolonmonospace: 0xFF1B,
  29020. semicolonsmall: 0xFE54,
  29021. semivoicedmarkkana: 0x309C,
  29022. semivoicedmarkkanahalfwidth: 0xFF9F,
  29023. sentisquare: 0x3322,
  29024. sentosquare: 0x3323,
  29025. seven: 0x0037,
  29026. sevenarabic: 0x0667,
  29027. sevenbengali: 0x09ED,
  29028. sevencircle: 0x2466,
  29029. sevencircleinversesansserif: 0x2790,
  29030. sevendeva: 0x096D,
  29031. seveneighths: 0x215E,
  29032. sevengujarati: 0x0AED,
  29033. sevengurmukhi: 0x0A6D,
  29034. sevenhackarabic: 0x0667,
  29035. sevenhangzhou: 0x3027,
  29036. sevenideographicparen: 0x3226,
  29037. seveninferior: 0x2087,
  29038. sevenmonospace: 0xFF17,
  29039. sevenoldstyle: 0xF737,
  29040. sevenparen: 0x247A,
  29041. sevenperiod: 0x248E,
  29042. sevenpersian: 0x06F7,
  29043. sevenroman: 0x2176,
  29044. sevensuperior: 0x2077,
  29045. seventeencircle: 0x2470,
  29046. seventeenparen: 0x2484,
  29047. seventeenperiod: 0x2498,
  29048. seventhai: 0x0E57,
  29049. sfthyphen: 0x00AD,
  29050. shaarmenian: 0x0577,
  29051. shabengali: 0x09B6,
  29052. shacyrillic: 0x0448,
  29053. shaddaarabic: 0x0651,
  29054. shaddadammaarabic: 0xFC61,
  29055. shaddadammatanarabic: 0xFC5E,
  29056. shaddafathaarabic: 0xFC60,
  29057. shaddakasraarabic: 0xFC62,
  29058. shaddakasratanarabic: 0xFC5F,
  29059. shade: 0x2592,
  29060. shadedark: 0x2593,
  29061. shadelight: 0x2591,
  29062. shademedium: 0x2592,
  29063. shadeva: 0x0936,
  29064. shagujarati: 0x0AB6,
  29065. shagurmukhi: 0x0A36,
  29066. shalshelethebrew: 0x0593,
  29067. shbopomofo: 0x3115,
  29068. shchacyrillic: 0x0449,
  29069. sheenarabic: 0x0634,
  29070. sheenfinalarabic: 0xFEB6,
  29071. sheeninitialarabic: 0xFEB7,
  29072. sheenmedialarabic: 0xFEB8,
  29073. sheicoptic: 0x03E3,
  29074. sheqel: 0x20AA,
  29075. sheqelhebrew: 0x20AA,
  29076. sheva: 0x05B0,
  29077. sheva115: 0x05B0,
  29078. sheva15: 0x05B0,
  29079. sheva22: 0x05B0,
  29080. sheva2e: 0x05B0,
  29081. shevahebrew: 0x05B0,
  29082. shevanarrowhebrew: 0x05B0,
  29083. shevaquarterhebrew: 0x05B0,
  29084. shevawidehebrew: 0x05B0,
  29085. shhacyrillic: 0x04BB,
  29086. shimacoptic: 0x03ED,
  29087. shin: 0x05E9,
  29088. shindagesh: 0xFB49,
  29089. shindageshhebrew: 0xFB49,
  29090. shindageshshindot: 0xFB2C,
  29091. shindageshshindothebrew: 0xFB2C,
  29092. shindageshsindot: 0xFB2D,
  29093. shindageshsindothebrew: 0xFB2D,
  29094. shindothebrew: 0x05C1,
  29095. shinhebrew: 0x05E9,
  29096. shinshindot: 0xFB2A,
  29097. shinshindothebrew: 0xFB2A,
  29098. shinsindot: 0xFB2B,
  29099. shinsindothebrew: 0xFB2B,
  29100. shook: 0x0282,
  29101. sigma: 0x03C3,
  29102. sigma1: 0x03C2,
  29103. sigmafinal: 0x03C2,
  29104. sigmalunatesymbolgreek: 0x03F2,
  29105. sihiragana: 0x3057,
  29106. sikatakana: 0x30B7,
  29107. sikatakanahalfwidth: 0xFF7C,
  29108. siluqhebrew: 0x05BD,
  29109. siluqlefthebrew: 0x05BD,
  29110. similar: 0x223C,
  29111. sindothebrew: 0x05C2,
  29112. siosacirclekorean: 0x3274,
  29113. siosaparenkorean: 0x3214,
  29114. sioscieuckorean: 0x317E,
  29115. sioscirclekorean: 0x3266,
  29116. sioskiyeokkorean: 0x317A,
  29117. sioskorean: 0x3145,
  29118. siosnieunkorean: 0x317B,
  29119. siosparenkorean: 0x3206,
  29120. siospieupkorean: 0x317D,
  29121. siostikeutkorean: 0x317C,
  29122. six: 0x0036,
  29123. sixarabic: 0x0666,
  29124. sixbengali: 0x09EC,
  29125. sixcircle: 0x2465,
  29126. sixcircleinversesansserif: 0x278F,
  29127. sixdeva: 0x096C,
  29128. sixgujarati: 0x0AEC,
  29129. sixgurmukhi: 0x0A6C,
  29130. sixhackarabic: 0x0666,
  29131. sixhangzhou: 0x3026,
  29132. sixideographicparen: 0x3225,
  29133. sixinferior: 0x2086,
  29134. sixmonospace: 0xFF16,
  29135. sixoldstyle: 0xF736,
  29136. sixparen: 0x2479,
  29137. sixperiod: 0x248D,
  29138. sixpersian: 0x06F6,
  29139. sixroman: 0x2175,
  29140. sixsuperior: 0x2076,
  29141. sixteencircle: 0x246F,
  29142. sixteencurrencydenominatorbengali: 0x09F9,
  29143. sixteenparen: 0x2483,
  29144. sixteenperiod: 0x2497,
  29145. sixthai: 0x0E56,
  29146. slash: 0x002F,
  29147. slashmonospace: 0xFF0F,
  29148. slong: 0x017F,
  29149. slongdotaccent: 0x1E9B,
  29150. smileface: 0x263A,
  29151. smonospace: 0xFF53,
  29152. sofpasuqhebrew: 0x05C3,
  29153. softhyphen: 0x00AD,
  29154. softsigncyrillic: 0x044C,
  29155. sohiragana: 0x305D,
  29156. sokatakana: 0x30BD,
  29157. sokatakanahalfwidth: 0xFF7F,
  29158. soliduslongoverlaycmb: 0x0338,
  29159. solidusshortoverlaycmb: 0x0337,
  29160. sorusithai: 0x0E29,
  29161. sosalathai: 0x0E28,
  29162. sosothai: 0x0E0B,
  29163. sosuathai: 0x0E2A,
  29164. space: 0x0020,
  29165. spacehackarabic: 0x0020,
  29166. spade: 0x2660,
  29167. spadesuitblack: 0x2660,
  29168. spadesuitwhite: 0x2664,
  29169. sparen: 0x24AE,
  29170. squarebelowcmb: 0x033B,
  29171. squarecc: 0x33C4,
  29172. squarecm: 0x339D,
  29173. squarediagonalcrosshatchfill: 0x25A9,
  29174. squarehorizontalfill: 0x25A4,
  29175. squarekg: 0x338F,
  29176. squarekm: 0x339E,
  29177. squarekmcapital: 0x33CE,
  29178. squareln: 0x33D1,
  29179. squarelog: 0x33D2,
  29180. squaremg: 0x338E,
  29181. squaremil: 0x33D5,
  29182. squaremm: 0x339C,
  29183. squaremsquared: 0x33A1,
  29184. squareorthogonalcrosshatchfill: 0x25A6,
  29185. squareupperlefttolowerrightfill: 0x25A7,
  29186. squareupperrighttolowerleftfill: 0x25A8,
  29187. squareverticalfill: 0x25A5,
  29188. squarewhitewithsmallblack: 0x25A3,
  29189. srsquare: 0x33DB,
  29190. ssabengali: 0x09B7,
  29191. ssadeva: 0x0937,
  29192. ssagujarati: 0x0AB7,
  29193. ssangcieuckorean: 0x3149,
  29194. ssanghieuhkorean: 0x3185,
  29195. ssangieungkorean: 0x3180,
  29196. ssangkiyeokkorean: 0x3132,
  29197. ssangnieunkorean: 0x3165,
  29198. ssangpieupkorean: 0x3143,
  29199. ssangsioskorean: 0x3146,
  29200. ssangtikeutkorean: 0x3138,
  29201. ssuperior: 0xF6F2,
  29202. sterling: 0x00A3,
  29203. sterlingmonospace: 0xFFE1,
  29204. strokelongoverlaycmb: 0x0336,
  29205. strokeshortoverlaycmb: 0x0335,
  29206. subset: 0x2282,
  29207. subsetnotequal: 0x228A,
  29208. subsetorequal: 0x2286,
  29209. succeeds: 0x227B,
  29210. suchthat: 0x220B,
  29211. suhiragana: 0x3059,
  29212. sukatakana: 0x30B9,
  29213. sukatakanahalfwidth: 0xFF7D,
  29214. sukunarabic: 0x0652,
  29215. summation: 0x2211,
  29216. sun: 0x263C,
  29217. superset: 0x2283,
  29218. supersetnotequal: 0x228B,
  29219. supersetorequal: 0x2287,
  29220. svsquare: 0x33DC,
  29221. syouwaerasquare: 0x337C,
  29222. t: 0x0074,
  29223. tabengali: 0x09A4,
  29224. tackdown: 0x22A4,
  29225. tackleft: 0x22A3,
  29226. tadeva: 0x0924,
  29227. tagujarati: 0x0AA4,
  29228. tagurmukhi: 0x0A24,
  29229. taharabic: 0x0637,
  29230. tahfinalarabic: 0xFEC2,
  29231. tahinitialarabic: 0xFEC3,
  29232. tahiragana: 0x305F,
  29233. tahmedialarabic: 0xFEC4,
  29234. taisyouerasquare: 0x337D,
  29235. takatakana: 0x30BF,
  29236. takatakanahalfwidth: 0xFF80,
  29237. tatweelarabic: 0x0640,
  29238. tau: 0x03C4,
  29239. tav: 0x05EA,
  29240. tavdages: 0xFB4A,
  29241. tavdagesh: 0xFB4A,
  29242. tavdageshhebrew: 0xFB4A,
  29243. tavhebrew: 0x05EA,
  29244. tbar: 0x0167,
  29245. tbopomofo: 0x310A,
  29246. tcaron: 0x0165,
  29247. tccurl: 0x02A8,
  29248. tcedilla: 0x0163,
  29249. tcheharabic: 0x0686,
  29250. tchehfinalarabic: 0xFB7B,
  29251. tchehinitialarabic: 0xFB7C,
  29252. tchehmedialarabic: 0xFB7D,
  29253. tcircle: 0x24E3,
  29254. tcircumflexbelow: 0x1E71,
  29255. tcommaaccent: 0x0163,
  29256. tdieresis: 0x1E97,
  29257. tdotaccent: 0x1E6B,
  29258. tdotbelow: 0x1E6D,
  29259. tecyrillic: 0x0442,
  29260. tedescendercyrillic: 0x04AD,
  29261. teharabic: 0x062A,
  29262. tehfinalarabic: 0xFE96,
  29263. tehhahinitialarabic: 0xFCA2,
  29264. tehhahisolatedarabic: 0xFC0C,
  29265. tehinitialarabic: 0xFE97,
  29266. tehiragana: 0x3066,
  29267. tehjeeminitialarabic: 0xFCA1,
  29268. tehjeemisolatedarabic: 0xFC0B,
  29269. tehmarbutaarabic: 0x0629,
  29270. tehmarbutafinalarabic: 0xFE94,
  29271. tehmedialarabic: 0xFE98,
  29272. tehmeeminitialarabic: 0xFCA4,
  29273. tehmeemisolatedarabic: 0xFC0E,
  29274. tehnoonfinalarabic: 0xFC73,
  29275. tekatakana: 0x30C6,
  29276. tekatakanahalfwidth: 0xFF83,
  29277. telephone: 0x2121,
  29278. telephoneblack: 0x260E,
  29279. telishagedolahebrew: 0x05A0,
  29280. telishaqetanahebrew: 0x05A9,
  29281. tencircle: 0x2469,
  29282. tenideographicparen: 0x3229,
  29283. tenparen: 0x247D,
  29284. tenperiod: 0x2491,
  29285. tenroman: 0x2179,
  29286. tesh: 0x02A7,
  29287. tet: 0x05D8,
  29288. tetdagesh: 0xFB38,
  29289. tetdageshhebrew: 0xFB38,
  29290. tethebrew: 0x05D8,
  29291. tetsecyrillic: 0x04B5,
  29292. tevirhebrew: 0x059B,
  29293. tevirlefthebrew: 0x059B,
  29294. thabengali: 0x09A5,
  29295. thadeva: 0x0925,
  29296. thagujarati: 0x0AA5,
  29297. thagurmukhi: 0x0A25,
  29298. thalarabic: 0x0630,
  29299. thalfinalarabic: 0xFEAC,
  29300. thanthakhatlowleftthai: 0xF898,
  29301. thanthakhatlowrightthai: 0xF897,
  29302. thanthakhatthai: 0x0E4C,
  29303. thanthakhatupperleftthai: 0xF896,
  29304. theharabic: 0x062B,
  29305. thehfinalarabic: 0xFE9A,
  29306. thehinitialarabic: 0xFE9B,
  29307. thehmedialarabic: 0xFE9C,
  29308. thereexists: 0x2203,
  29309. therefore: 0x2234,
  29310. theta: 0x03B8,
  29311. theta1: 0x03D1,
  29312. thetasymbolgreek: 0x03D1,
  29313. thieuthacirclekorean: 0x3279,
  29314. thieuthaparenkorean: 0x3219,
  29315. thieuthcirclekorean: 0x326B,
  29316. thieuthkorean: 0x314C,
  29317. thieuthparenkorean: 0x320B,
  29318. thirteencircle: 0x246C,
  29319. thirteenparen: 0x2480,
  29320. thirteenperiod: 0x2494,
  29321. thonangmonthothai: 0x0E11,
  29322. thook: 0x01AD,
  29323. thophuthaothai: 0x0E12,
  29324. thorn: 0x00FE,
  29325. thothahanthai: 0x0E17,
  29326. thothanthai: 0x0E10,
  29327. thothongthai: 0x0E18,
  29328. thothungthai: 0x0E16,
  29329. thousandcyrillic: 0x0482,
  29330. thousandsseparatorarabic: 0x066C,
  29331. thousandsseparatorpersian: 0x066C,
  29332. three: 0x0033,
  29333. threearabic: 0x0663,
  29334. threebengali: 0x09E9,
  29335. threecircle: 0x2462,
  29336. threecircleinversesansserif: 0x278C,
  29337. threedeva: 0x0969,
  29338. threeeighths: 0x215C,
  29339. threegujarati: 0x0AE9,
  29340. threegurmukhi: 0x0A69,
  29341. threehackarabic: 0x0663,
  29342. threehangzhou: 0x3023,
  29343. threeideographicparen: 0x3222,
  29344. threeinferior: 0x2083,
  29345. threemonospace: 0xFF13,
  29346. threenumeratorbengali: 0x09F6,
  29347. threeoldstyle: 0xF733,
  29348. threeparen: 0x2476,
  29349. threeperiod: 0x248A,
  29350. threepersian: 0x06F3,
  29351. threequarters: 0x00BE,
  29352. threequartersemdash: 0xF6DE,
  29353. threeroman: 0x2172,
  29354. threesuperior: 0x00B3,
  29355. threethai: 0x0E53,
  29356. thzsquare: 0x3394,
  29357. tihiragana: 0x3061,
  29358. tikatakana: 0x30C1,
  29359. tikatakanahalfwidth: 0xFF81,
  29360. tikeutacirclekorean: 0x3270,
  29361. tikeutaparenkorean: 0x3210,
  29362. tikeutcirclekorean: 0x3262,
  29363. tikeutkorean: 0x3137,
  29364. tikeutparenkorean: 0x3202,
  29365. tilde: 0x02DC,
  29366. tildebelowcmb: 0x0330,
  29367. tildecmb: 0x0303,
  29368. tildecomb: 0x0303,
  29369. tildedoublecmb: 0x0360,
  29370. tildeoperator: 0x223C,
  29371. tildeoverlaycmb: 0x0334,
  29372. tildeverticalcmb: 0x033E,
  29373. timescircle: 0x2297,
  29374. tipehahebrew: 0x0596,
  29375. tipehalefthebrew: 0x0596,
  29376. tippigurmukhi: 0x0A70,
  29377. titlocyrilliccmb: 0x0483,
  29378. tiwnarmenian: 0x057F,
  29379. tlinebelow: 0x1E6F,
  29380. tmonospace: 0xFF54,
  29381. toarmenian: 0x0569,
  29382. tohiragana: 0x3068,
  29383. tokatakana: 0x30C8,
  29384. tokatakanahalfwidth: 0xFF84,
  29385. tonebarextrahighmod: 0x02E5,
  29386. tonebarextralowmod: 0x02E9,
  29387. tonebarhighmod: 0x02E6,
  29388. tonebarlowmod: 0x02E8,
  29389. tonebarmidmod: 0x02E7,
  29390. tonefive: 0x01BD,
  29391. tonesix: 0x0185,
  29392. tonetwo: 0x01A8,
  29393. tonos: 0x0384,
  29394. tonsquare: 0x3327,
  29395. topatakthai: 0x0E0F,
  29396. tortoiseshellbracketleft: 0x3014,
  29397. tortoiseshellbracketleftsmall: 0xFE5D,
  29398. tortoiseshellbracketleftvertical: 0xFE39,
  29399. tortoiseshellbracketright: 0x3015,
  29400. tortoiseshellbracketrightsmall: 0xFE5E,
  29401. tortoiseshellbracketrightvertical: 0xFE3A,
  29402. totaothai: 0x0E15,
  29403. tpalatalhook: 0x01AB,
  29404. tparen: 0x24AF,
  29405. trademark: 0x2122,
  29406. trademarksans: 0xF8EA,
  29407. trademarkserif: 0xF6DB,
  29408. tretroflexhook: 0x0288,
  29409. triagdn: 0x25BC,
  29410. triaglf: 0x25C4,
  29411. triagrt: 0x25BA,
  29412. triagup: 0x25B2,
  29413. ts: 0x02A6,
  29414. tsadi: 0x05E6,
  29415. tsadidagesh: 0xFB46,
  29416. tsadidageshhebrew: 0xFB46,
  29417. tsadihebrew: 0x05E6,
  29418. tsecyrillic: 0x0446,
  29419. tsere: 0x05B5,
  29420. tsere12: 0x05B5,
  29421. tsere1e: 0x05B5,
  29422. tsere2b: 0x05B5,
  29423. tserehebrew: 0x05B5,
  29424. tserenarrowhebrew: 0x05B5,
  29425. tserequarterhebrew: 0x05B5,
  29426. tserewidehebrew: 0x05B5,
  29427. tshecyrillic: 0x045B,
  29428. tsuperior: 0xF6F3,
  29429. ttabengali: 0x099F,
  29430. ttadeva: 0x091F,
  29431. ttagujarati: 0x0A9F,
  29432. ttagurmukhi: 0x0A1F,
  29433. tteharabic: 0x0679,
  29434. ttehfinalarabic: 0xFB67,
  29435. ttehinitialarabic: 0xFB68,
  29436. ttehmedialarabic: 0xFB69,
  29437. tthabengali: 0x09A0,
  29438. tthadeva: 0x0920,
  29439. tthagujarati: 0x0AA0,
  29440. tthagurmukhi: 0x0A20,
  29441. tturned: 0x0287,
  29442. tuhiragana: 0x3064,
  29443. tukatakana: 0x30C4,
  29444. tukatakanahalfwidth: 0xFF82,
  29445. tusmallhiragana: 0x3063,
  29446. tusmallkatakana: 0x30C3,
  29447. tusmallkatakanahalfwidth: 0xFF6F,
  29448. twelvecircle: 0x246B,
  29449. twelveparen: 0x247F,
  29450. twelveperiod: 0x2493,
  29451. twelveroman: 0x217B,
  29452. twentycircle: 0x2473,
  29453. twentyhangzhou: 0x5344,
  29454. twentyparen: 0x2487,
  29455. twentyperiod: 0x249B,
  29456. two: 0x0032,
  29457. twoarabic: 0x0662,
  29458. twobengali: 0x09E8,
  29459. twocircle: 0x2461,
  29460. twocircleinversesansserif: 0x278B,
  29461. twodeva: 0x0968,
  29462. twodotenleader: 0x2025,
  29463. twodotleader: 0x2025,
  29464. twodotleadervertical: 0xFE30,
  29465. twogujarati: 0x0AE8,
  29466. twogurmukhi: 0x0A68,
  29467. twohackarabic: 0x0662,
  29468. twohangzhou: 0x3022,
  29469. twoideographicparen: 0x3221,
  29470. twoinferior: 0x2082,
  29471. twomonospace: 0xFF12,
  29472. twonumeratorbengali: 0x09F5,
  29473. twooldstyle: 0xF732,
  29474. twoparen: 0x2475,
  29475. twoperiod: 0x2489,
  29476. twopersian: 0x06F2,
  29477. tworoman: 0x2171,
  29478. twostroke: 0x01BB,
  29479. twosuperior: 0x00B2,
  29480. twothai: 0x0E52,
  29481. twothirds: 0x2154,
  29482. u: 0x0075,
  29483. uacute: 0x00FA,
  29484. ubar: 0x0289,
  29485. ubengali: 0x0989,
  29486. ubopomofo: 0x3128,
  29487. ubreve: 0x016D,
  29488. ucaron: 0x01D4,
  29489. ucircle: 0x24E4,
  29490. ucircumflex: 0x00FB,
  29491. ucircumflexbelow: 0x1E77,
  29492. ucyrillic: 0x0443,
  29493. udattadeva: 0x0951,
  29494. udblacute: 0x0171,
  29495. udblgrave: 0x0215,
  29496. udeva: 0x0909,
  29497. udieresis: 0x00FC,
  29498. udieresisacute: 0x01D8,
  29499. udieresisbelow: 0x1E73,
  29500. udieresiscaron: 0x01DA,
  29501. udieresiscyrillic: 0x04F1,
  29502. udieresisgrave: 0x01DC,
  29503. udieresismacron: 0x01D6,
  29504. udotbelow: 0x1EE5,
  29505. ugrave: 0x00F9,
  29506. ugujarati: 0x0A89,
  29507. ugurmukhi: 0x0A09,
  29508. uhiragana: 0x3046,
  29509. uhookabove: 0x1EE7,
  29510. uhorn: 0x01B0,
  29511. uhornacute: 0x1EE9,
  29512. uhorndotbelow: 0x1EF1,
  29513. uhorngrave: 0x1EEB,
  29514. uhornhookabove: 0x1EED,
  29515. uhorntilde: 0x1EEF,
  29516. uhungarumlaut: 0x0171,
  29517. uhungarumlautcyrillic: 0x04F3,
  29518. uinvertedbreve: 0x0217,
  29519. ukatakana: 0x30A6,
  29520. ukatakanahalfwidth: 0xFF73,
  29521. ukcyrillic: 0x0479,
  29522. ukorean: 0x315C,
  29523. umacron: 0x016B,
  29524. umacroncyrillic: 0x04EF,
  29525. umacrondieresis: 0x1E7B,
  29526. umatragurmukhi: 0x0A41,
  29527. umonospace: 0xFF55,
  29528. underscore: 0x005F,
  29529. underscoredbl: 0x2017,
  29530. underscoremonospace: 0xFF3F,
  29531. underscorevertical: 0xFE33,
  29532. underscorewavy: 0xFE4F,
  29533. union: 0x222A,
  29534. universal: 0x2200,
  29535. uogonek: 0x0173,
  29536. uparen: 0x24B0,
  29537. upblock: 0x2580,
  29538. upperdothebrew: 0x05C4,
  29539. upsilon: 0x03C5,
  29540. upsilondieresis: 0x03CB,
  29541. upsilondieresistonos: 0x03B0,
  29542. upsilonlatin: 0x028A,
  29543. upsilontonos: 0x03CD,
  29544. uptackbelowcmb: 0x031D,
  29545. uptackmod: 0x02D4,
  29546. uragurmukhi: 0x0A73,
  29547. uring: 0x016F,
  29548. ushortcyrillic: 0x045E,
  29549. usmallhiragana: 0x3045,
  29550. usmallkatakana: 0x30A5,
  29551. usmallkatakanahalfwidth: 0xFF69,
  29552. ustraightcyrillic: 0x04AF,
  29553. ustraightstrokecyrillic: 0x04B1,
  29554. utilde: 0x0169,
  29555. utildeacute: 0x1E79,
  29556. utildebelow: 0x1E75,
  29557. uubengali: 0x098A,
  29558. uudeva: 0x090A,
  29559. uugujarati: 0x0A8A,
  29560. uugurmukhi: 0x0A0A,
  29561. uumatragurmukhi: 0x0A42,
  29562. uuvowelsignbengali: 0x09C2,
  29563. uuvowelsigndeva: 0x0942,
  29564. uuvowelsigngujarati: 0x0AC2,
  29565. uvowelsignbengali: 0x09C1,
  29566. uvowelsigndeva: 0x0941,
  29567. uvowelsigngujarati: 0x0AC1,
  29568. v: 0x0076,
  29569. vadeva: 0x0935,
  29570. vagujarati: 0x0AB5,
  29571. vagurmukhi: 0x0A35,
  29572. vakatakana: 0x30F7,
  29573. vav: 0x05D5,
  29574. vavdagesh: 0xFB35,
  29575. vavdagesh65: 0xFB35,
  29576. vavdageshhebrew: 0xFB35,
  29577. vavhebrew: 0x05D5,
  29578. vavholam: 0xFB4B,
  29579. vavholamhebrew: 0xFB4B,
  29580. vavvavhebrew: 0x05F0,
  29581. vavyodhebrew: 0x05F1,
  29582. vcircle: 0x24E5,
  29583. vdotbelow: 0x1E7F,
  29584. vecyrillic: 0x0432,
  29585. veharabic: 0x06A4,
  29586. vehfinalarabic: 0xFB6B,
  29587. vehinitialarabic: 0xFB6C,
  29588. vehmedialarabic: 0xFB6D,
  29589. vekatakana: 0x30F9,
  29590. venus: 0x2640,
  29591. verticalbar: 0x007C,
  29592. verticallineabovecmb: 0x030D,
  29593. verticallinebelowcmb: 0x0329,
  29594. verticallinelowmod: 0x02CC,
  29595. verticallinemod: 0x02C8,
  29596. vewarmenian: 0x057E,
  29597. vhook: 0x028B,
  29598. vikatakana: 0x30F8,
  29599. viramabengali: 0x09CD,
  29600. viramadeva: 0x094D,
  29601. viramagujarati: 0x0ACD,
  29602. visargabengali: 0x0983,
  29603. visargadeva: 0x0903,
  29604. visargagujarati: 0x0A83,
  29605. vmonospace: 0xFF56,
  29606. voarmenian: 0x0578,
  29607. voicediterationhiragana: 0x309E,
  29608. voicediterationkatakana: 0x30FE,
  29609. voicedmarkkana: 0x309B,
  29610. voicedmarkkanahalfwidth: 0xFF9E,
  29611. vokatakana: 0x30FA,
  29612. vparen: 0x24B1,
  29613. vtilde: 0x1E7D,
  29614. vturned: 0x028C,
  29615. vuhiragana: 0x3094,
  29616. vukatakana: 0x30F4,
  29617. w: 0x0077,
  29618. wacute: 0x1E83,
  29619. waekorean: 0x3159,
  29620. wahiragana: 0x308F,
  29621. wakatakana: 0x30EF,
  29622. wakatakanahalfwidth: 0xFF9C,
  29623. wakorean: 0x3158,
  29624. wasmallhiragana: 0x308E,
  29625. wasmallkatakana: 0x30EE,
  29626. wattosquare: 0x3357,
  29627. wavedash: 0x301C,
  29628. wavyunderscorevertical: 0xFE34,
  29629. wawarabic: 0x0648,
  29630. wawfinalarabic: 0xFEEE,
  29631. wawhamzaabovearabic: 0x0624,
  29632. wawhamzaabovefinalarabic: 0xFE86,
  29633. wbsquare: 0x33DD,
  29634. wcircle: 0x24E6,
  29635. wcircumflex: 0x0175,
  29636. wdieresis: 0x1E85,
  29637. wdotaccent: 0x1E87,
  29638. wdotbelow: 0x1E89,
  29639. wehiragana: 0x3091,
  29640. weierstrass: 0x2118,
  29641. wekatakana: 0x30F1,
  29642. wekorean: 0x315E,
  29643. weokorean: 0x315D,
  29644. wgrave: 0x1E81,
  29645. whitebullet: 0x25E6,
  29646. whitecircle: 0x25CB,
  29647. whitecircleinverse: 0x25D9,
  29648. whitecornerbracketleft: 0x300E,
  29649. whitecornerbracketleftvertical: 0xFE43,
  29650. whitecornerbracketright: 0x300F,
  29651. whitecornerbracketrightvertical: 0xFE44,
  29652. whitediamond: 0x25C7,
  29653. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29654. whitedownpointingsmalltriangle: 0x25BF,
  29655. whitedownpointingtriangle: 0x25BD,
  29656. whiteleftpointingsmalltriangle: 0x25C3,
  29657. whiteleftpointingtriangle: 0x25C1,
  29658. whitelenticularbracketleft: 0x3016,
  29659. whitelenticularbracketright: 0x3017,
  29660. whiterightpointingsmalltriangle: 0x25B9,
  29661. whiterightpointingtriangle: 0x25B7,
  29662. whitesmallsquare: 0x25AB,
  29663. whitesmilingface: 0x263A,
  29664. whitesquare: 0x25A1,
  29665. whitestar: 0x2606,
  29666. whitetelephone: 0x260F,
  29667. whitetortoiseshellbracketleft: 0x3018,
  29668. whitetortoiseshellbracketright: 0x3019,
  29669. whiteuppointingsmalltriangle: 0x25B5,
  29670. whiteuppointingtriangle: 0x25B3,
  29671. wihiragana: 0x3090,
  29672. wikatakana: 0x30F0,
  29673. wikorean: 0x315F,
  29674. wmonospace: 0xFF57,
  29675. wohiragana: 0x3092,
  29676. wokatakana: 0x30F2,
  29677. wokatakanahalfwidth: 0xFF66,
  29678. won: 0x20A9,
  29679. wonmonospace: 0xFFE6,
  29680. wowaenthai: 0x0E27,
  29681. wparen: 0x24B2,
  29682. wring: 0x1E98,
  29683. wsuperior: 0x02B7,
  29684. wturned: 0x028D,
  29685. wynn: 0x01BF,
  29686. x: 0x0078,
  29687. xabovecmb: 0x033D,
  29688. xbopomofo: 0x3112,
  29689. xcircle: 0x24E7,
  29690. xdieresis: 0x1E8D,
  29691. xdotaccent: 0x1E8B,
  29692. xeharmenian: 0x056D,
  29693. xi: 0x03BE,
  29694. xmonospace: 0xFF58,
  29695. xparen: 0x24B3,
  29696. xsuperior: 0x02E3,
  29697. y: 0x0079,
  29698. yaadosquare: 0x334E,
  29699. yabengali: 0x09AF,
  29700. yacute: 0x00FD,
  29701. yadeva: 0x092F,
  29702. yaekorean: 0x3152,
  29703. yagujarati: 0x0AAF,
  29704. yagurmukhi: 0x0A2F,
  29705. yahiragana: 0x3084,
  29706. yakatakana: 0x30E4,
  29707. yakatakanahalfwidth: 0xFF94,
  29708. yakorean: 0x3151,
  29709. yamakkanthai: 0x0E4E,
  29710. yasmallhiragana: 0x3083,
  29711. yasmallkatakana: 0x30E3,
  29712. yasmallkatakanahalfwidth: 0xFF6C,
  29713. yatcyrillic: 0x0463,
  29714. ycircle: 0x24E8,
  29715. ycircumflex: 0x0177,
  29716. ydieresis: 0x00FF,
  29717. ydotaccent: 0x1E8F,
  29718. ydotbelow: 0x1EF5,
  29719. yeharabic: 0x064A,
  29720. yehbarreearabic: 0x06D2,
  29721. yehbarreefinalarabic: 0xFBAF,
  29722. yehfinalarabic: 0xFEF2,
  29723. yehhamzaabovearabic: 0x0626,
  29724. yehhamzaabovefinalarabic: 0xFE8A,
  29725. yehhamzaaboveinitialarabic: 0xFE8B,
  29726. yehhamzaabovemedialarabic: 0xFE8C,
  29727. yehinitialarabic: 0xFEF3,
  29728. yehmedialarabic: 0xFEF4,
  29729. yehmeeminitialarabic: 0xFCDD,
  29730. yehmeemisolatedarabic: 0xFC58,
  29731. yehnoonfinalarabic: 0xFC94,
  29732. yehthreedotsbelowarabic: 0x06D1,
  29733. yekorean: 0x3156,
  29734. yen: 0x00A5,
  29735. yenmonospace: 0xFFE5,
  29736. yeokorean: 0x3155,
  29737. yeorinhieuhkorean: 0x3186,
  29738. yerahbenyomohebrew: 0x05AA,
  29739. yerahbenyomolefthebrew: 0x05AA,
  29740. yericyrillic: 0x044B,
  29741. yerudieresiscyrillic: 0x04F9,
  29742. yesieungkorean: 0x3181,
  29743. yesieungpansioskorean: 0x3183,
  29744. yesieungsioskorean: 0x3182,
  29745. yetivhebrew: 0x059A,
  29746. ygrave: 0x1EF3,
  29747. yhook: 0x01B4,
  29748. yhookabove: 0x1EF7,
  29749. yiarmenian: 0x0575,
  29750. yicyrillic: 0x0457,
  29751. yikorean: 0x3162,
  29752. yinyang: 0x262F,
  29753. yiwnarmenian: 0x0582,
  29754. ymonospace: 0xFF59,
  29755. yod: 0x05D9,
  29756. yoddagesh: 0xFB39,
  29757. yoddageshhebrew: 0xFB39,
  29758. yodhebrew: 0x05D9,
  29759. yodyodhebrew: 0x05F2,
  29760. yodyodpatahhebrew: 0xFB1F,
  29761. yohiragana: 0x3088,
  29762. yoikorean: 0x3189,
  29763. yokatakana: 0x30E8,
  29764. yokatakanahalfwidth: 0xFF96,
  29765. yokorean: 0x315B,
  29766. yosmallhiragana: 0x3087,
  29767. yosmallkatakana: 0x30E7,
  29768. yosmallkatakanahalfwidth: 0xFF6E,
  29769. yotgreek: 0x03F3,
  29770. yoyaekorean: 0x3188,
  29771. yoyakorean: 0x3187,
  29772. yoyakthai: 0x0E22,
  29773. yoyingthai: 0x0E0D,
  29774. yparen: 0x24B4,
  29775. ypogegrammeni: 0x037A,
  29776. ypogegrammenigreekcmb: 0x0345,
  29777. yr: 0x01A6,
  29778. yring: 0x1E99,
  29779. ysuperior: 0x02B8,
  29780. ytilde: 0x1EF9,
  29781. yturned: 0x028E,
  29782. yuhiragana: 0x3086,
  29783. yuikorean: 0x318C,
  29784. yukatakana: 0x30E6,
  29785. yukatakanahalfwidth: 0xFF95,
  29786. yukorean: 0x3160,
  29787. yusbigcyrillic: 0x046B,
  29788. yusbigiotifiedcyrillic: 0x046D,
  29789. yuslittlecyrillic: 0x0467,
  29790. yuslittleiotifiedcyrillic: 0x0469,
  29791. yusmallhiragana: 0x3085,
  29792. yusmallkatakana: 0x30E5,
  29793. yusmallkatakanahalfwidth: 0xFF6D,
  29794. yuyekorean: 0x318B,
  29795. yuyeokorean: 0x318A,
  29796. yyabengali: 0x09DF,
  29797. yyadeva: 0x095F,
  29798. z: 0x007A,
  29799. zaarmenian: 0x0566,
  29800. zacute: 0x017A,
  29801. zadeva: 0x095B,
  29802. zagurmukhi: 0x0A5B,
  29803. zaharabic: 0x0638,
  29804. zahfinalarabic: 0xFEC6,
  29805. zahinitialarabic: 0xFEC7,
  29806. zahiragana: 0x3056,
  29807. zahmedialarabic: 0xFEC8,
  29808. zainarabic: 0x0632,
  29809. zainfinalarabic: 0xFEB0,
  29810. zakatakana: 0x30B6,
  29811. zaqefgadolhebrew: 0x0595,
  29812. zaqefqatanhebrew: 0x0594,
  29813. zarqahebrew: 0x0598,
  29814. zayin: 0x05D6,
  29815. zayindagesh: 0xFB36,
  29816. zayindageshhebrew: 0xFB36,
  29817. zayinhebrew: 0x05D6,
  29818. zbopomofo: 0x3117,
  29819. zcaron: 0x017E,
  29820. zcircle: 0x24E9,
  29821. zcircumflex: 0x1E91,
  29822. zcurl: 0x0291,
  29823. zdot: 0x017C,
  29824. zdotaccent: 0x017C,
  29825. zdotbelow: 0x1E93,
  29826. zecyrillic: 0x0437,
  29827. zedescendercyrillic: 0x0499,
  29828. zedieresiscyrillic: 0x04DF,
  29829. zehiragana: 0x305C,
  29830. zekatakana: 0x30BC,
  29831. zero: 0x0030,
  29832. zeroarabic: 0x0660,
  29833. zerobengali: 0x09E6,
  29834. zerodeva: 0x0966,
  29835. zerogujarati: 0x0AE6,
  29836. zerogurmukhi: 0x0A66,
  29837. zerohackarabic: 0x0660,
  29838. zeroinferior: 0x2080,
  29839. zeromonospace: 0xFF10,
  29840. zerooldstyle: 0xF730,
  29841. zeropersian: 0x06F0,
  29842. zerosuperior: 0x2070,
  29843. zerothai: 0x0E50,
  29844. zerowidthjoiner: 0xFEFF,
  29845. zerowidthnonjoiner: 0x200C,
  29846. zerowidthspace: 0x200B,
  29847. zeta: 0x03B6,
  29848. zhbopomofo: 0x3113,
  29849. zhearmenian: 0x056A,
  29850. zhebrevecyrillic: 0x04C2,
  29851. zhecyrillic: 0x0436,
  29852. zhedescendercyrillic: 0x0497,
  29853. zhedieresiscyrillic: 0x04DD,
  29854. zihiragana: 0x3058,
  29855. zikatakana: 0x30B8,
  29856. zinorhebrew: 0x05AE,
  29857. zlinebelow: 0x1E95,
  29858. zmonospace: 0xFF5A,
  29859. zohiragana: 0x305E,
  29860. zokatakana: 0x30BE,
  29861. zparen: 0x24B5,
  29862. zretroflexhook: 0x0290,
  29863. zstroke: 0x01B6,
  29864. zuhiragana: 0x305A,
  29865. zukatakana: 0x30BA,
  29866. '.notdef': 0x0000
  29867. };
  29868. var DingbatsGlyphsUnicode = {
  29869. space: 0x0020,
  29870. a1: 0x2701,
  29871. a2: 0x2702,
  29872. a202: 0x2703,
  29873. a3: 0x2704,
  29874. a4: 0x260E,
  29875. a5: 0x2706,
  29876. a119: 0x2707,
  29877. a118: 0x2708,
  29878. a117: 0x2709,
  29879. a11: 0x261B,
  29880. a12: 0x261E,
  29881. a13: 0x270C,
  29882. a14: 0x270D,
  29883. a15: 0x270E,
  29884. a16: 0x270F,
  29885. a105: 0x2710,
  29886. a17: 0x2711,
  29887. a18: 0x2712,
  29888. a19: 0x2713,
  29889. a20: 0x2714,
  29890. a21: 0x2715,
  29891. a22: 0x2716,
  29892. a23: 0x2717,
  29893. a24: 0x2718,
  29894. a25: 0x2719,
  29895. a26: 0x271A,
  29896. a27: 0x271B,
  29897. a28: 0x271C,
  29898. a6: 0x271D,
  29899. a7: 0x271E,
  29900. a8: 0x271F,
  29901. a9: 0x2720,
  29902. a10: 0x2721,
  29903. a29: 0x2722,
  29904. a30: 0x2723,
  29905. a31: 0x2724,
  29906. a32: 0x2725,
  29907. a33: 0x2726,
  29908. a34: 0x2727,
  29909. a35: 0x2605,
  29910. a36: 0x2729,
  29911. a37: 0x272A,
  29912. a38: 0x272B,
  29913. a39: 0x272C,
  29914. a40: 0x272D,
  29915. a41: 0x272E,
  29916. a42: 0x272F,
  29917. a43: 0x2730,
  29918. a44: 0x2731,
  29919. a45: 0x2732,
  29920. a46: 0x2733,
  29921. a47: 0x2734,
  29922. a48: 0x2735,
  29923. a49: 0x2736,
  29924. a50: 0x2737,
  29925. a51: 0x2738,
  29926. a52: 0x2739,
  29927. a53: 0x273A,
  29928. a54: 0x273B,
  29929. a55: 0x273C,
  29930. a56: 0x273D,
  29931. a57: 0x273E,
  29932. a58: 0x273F,
  29933. a59: 0x2740,
  29934. a60: 0x2741,
  29935. a61: 0x2742,
  29936. a62: 0x2743,
  29937. a63: 0x2744,
  29938. a64: 0x2745,
  29939. a65: 0x2746,
  29940. a66: 0x2747,
  29941. a67: 0x2748,
  29942. a68: 0x2749,
  29943. a69: 0x274A,
  29944. a70: 0x274B,
  29945. a71: 0x25CF,
  29946. a72: 0x274D,
  29947. a73: 0x25A0,
  29948. a74: 0x274F,
  29949. a203: 0x2750,
  29950. a75: 0x2751,
  29951. a204: 0x2752,
  29952. a76: 0x25B2,
  29953. a77: 0x25BC,
  29954. a78: 0x25C6,
  29955. a79: 0x2756,
  29956. a81: 0x25D7,
  29957. a82: 0x2758,
  29958. a83: 0x2759,
  29959. a84: 0x275A,
  29960. a97: 0x275B,
  29961. a98: 0x275C,
  29962. a99: 0x275D,
  29963. a100: 0x275E,
  29964. a101: 0x2761,
  29965. a102: 0x2762,
  29966. a103: 0x2763,
  29967. a104: 0x2764,
  29968. a106: 0x2765,
  29969. a107: 0x2766,
  29970. a108: 0x2767,
  29971. a112: 0x2663,
  29972. a111: 0x2666,
  29973. a110: 0x2665,
  29974. a109: 0x2660,
  29975. a120: 0x2460,
  29976. a121: 0x2461,
  29977. a122: 0x2462,
  29978. a123: 0x2463,
  29979. a124: 0x2464,
  29980. a125: 0x2465,
  29981. a126: 0x2466,
  29982. a127: 0x2467,
  29983. a128: 0x2468,
  29984. a129: 0x2469,
  29985. a130: 0x2776,
  29986. a131: 0x2777,
  29987. a132: 0x2778,
  29988. a133: 0x2779,
  29989. a134: 0x277A,
  29990. a135: 0x277B,
  29991. a136: 0x277C,
  29992. a137: 0x277D,
  29993. a138: 0x277E,
  29994. a139: 0x277F,
  29995. a140: 0x2780,
  29996. a141: 0x2781,
  29997. a142: 0x2782,
  29998. a143: 0x2783,
  29999. a144: 0x2784,
  30000. a145: 0x2785,
  30001. a146: 0x2786,
  30002. a147: 0x2787,
  30003. a148: 0x2788,
  30004. a149: 0x2789,
  30005. a150: 0x278A,
  30006. a151: 0x278B,
  30007. a152: 0x278C,
  30008. a153: 0x278D,
  30009. a154: 0x278E,
  30010. a155: 0x278F,
  30011. a156: 0x2790,
  30012. a157: 0x2791,
  30013. a158: 0x2792,
  30014. a159: 0x2793,
  30015. a160: 0x2794,
  30016. a161: 0x2192,
  30017. a163: 0x2194,
  30018. a164: 0x2195,
  30019. a196: 0x2798,
  30020. a165: 0x2799,
  30021. a192: 0x279A,
  30022. a166: 0x279B,
  30023. a167: 0x279C,
  30024. a168: 0x279D,
  30025. a169: 0x279E,
  30026. a170: 0x279F,
  30027. a171: 0x27A0,
  30028. a172: 0x27A1,
  30029. a173: 0x27A2,
  30030. a162: 0x27A3,
  30031. a174: 0x27A4,
  30032. a175: 0x27A5,
  30033. a176: 0x27A6,
  30034. a177: 0x27A7,
  30035. a178: 0x27A8,
  30036. a179: 0x27A9,
  30037. a193: 0x27AA,
  30038. a180: 0x27AB,
  30039. a199: 0x27AC,
  30040. a181: 0x27AD,
  30041. a200: 0x27AE,
  30042. a182: 0x27AF,
  30043. a201: 0x27B1,
  30044. a183: 0x27B2,
  30045. a184: 0x27B3,
  30046. a197: 0x27B4,
  30047. a185: 0x27B5,
  30048. a194: 0x27B6,
  30049. a198: 0x27B7,
  30050. a186: 0x27B8,
  30051. a195: 0x27B9,
  30052. a187: 0x27BA,
  30053. a188: 0x27BB,
  30054. a189: 0x27BC,
  30055. a190: 0x27BD,
  30056. a191: 0x27BE,
  30057. a89: 0x2768, // 0xF8D7
  30058. a90: 0x2769, // 0xF8D8
  30059. a93: 0x276A, // 0xF8D9
  30060. a94: 0x276B, // 0xF8DA
  30061. a91: 0x276C, // 0xF8DB
  30062. a92: 0x276D, // 0xF8DC
  30063. a205: 0x276E, // 0xF8DD
  30064. a85: 0x276F, // 0xF8DE
  30065. a206: 0x2770, // 0xF8DF
  30066. a86: 0x2771, // 0xF8E0
  30067. a87: 0x2772, // 0xF8E1
  30068. a88: 0x2773, // 0xF8E2
  30069. a95: 0x2774, // 0xF8E3
  30070. a96: 0x2775, // 0xF8E4
  30071. '.notdef': 0x0000
  30072. };
  30073. var PDFImage = (function PDFImageClosure() {
  30074. /**
  30075. * Decode the image in the main thread if it supported. Resovles the promise
  30076. * when the image data is ready.
  30077. */
  30078. function handleImageData(handler, xref, res, image) {
  30079. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30080. // For natively supported jpegs send them to the main thread for decoding.
  30081. var dict = image.dict;
  30082. var colorSpace = dict.get('ColorSpace', 'CS');
  30083. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30084. var numComps = colorSpace.numComps;
  30085. var decodePromise = handler.sendWithPromise('JpegDecode',
  30086. [image.getIR(), numComps]);
  30087. return decodePromise.then(function (message) {
  30088. var data = message.data;
  30089. return new Stream(data, 0, data.length, image.dict);
  30090. });
  30091. } else {
  30092. return Promise.resolve(image);
  30093. }
  30094. }
  30095. /**
  30096. * Decode and clamp a value. The formula is different from the spec because we
  30097. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30098. */
  30099. function decodeAndClamp(value, addend, coefficient, max) {
  30100. value = addend + value * coefficient;
  30101. // Clamp the value to the range
  30102. return (value < 0 ? 0 : (value > max ? max : value));
  30103. }
  30104. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30105. this.image = image;
  30106. var dict = image.dict;
  30107. if (dict.has('Filter')) {
  30108. var filter = dict.get('Filter').name;
  30109. if (filter === 'JPXDecode') {
  30110. var jpxImage = new JpxImage();
  30111. jpxImage.parseImageProperties(image.stream);
  30112. image.stream.reset();
  30113. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30114. image.numComps = jpxImage.componentsCount;
  30115. } else if (filter === 'JBIG2Decode') {
  30116. image.bitsPerComponent = 1;
  30117. image.numComps = 1;
  30118. }
  30119. }
  30120. // TODO cache rendered images?
  30121. this.width = dict.get('Width', 'W');
  30122. this.height = dict.get('Height', 'H');
  30123. if (this.width < 1 || this.height < 1) {
  30124. error('Invalid image width: ' + this.width + ' or height: ' +
  30125. this.height);
  30126. }
  30127. this.interpolate = dict.get('Interpolate', 'I') || false;
  30128. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30129. this.matte = dict.get('Matte') || false;
  30130. var bitsPerComponent = image.bitsPerComponent;
  30131. if (!bitsPerComponent) {
  30132. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30133. if (!bitsPerComponent) {
  30134. if (this.imageMask) {
  30135. bitsPerComponent = 1;
  30136. } else {
  30137. error('Bits per component missing in image: ' + this.imageMask);
  30138. }
  30139. }
  30140. }
  30141. this.bpc = bitsPerComponent;
  30142. if (!this.imageMask) {
  30143. var colorSpace = dict.get('ColorSpace', 'CS');
  30144. if (!colorSpace) {
  30145. info('JPX images (which do not require color spaces)');
  30146. switch (image.numComps) {
  30147. case 1:
  30148. colorSpace = Name.get('DeviceGray');
  30149. break;
  30150. case 3:
  30151. colorSpace = Name.get('DeviceRGB');
  30152. break;
  30153. case 4:
  30154. colorSpace = Name.get('DeviceCMYK');
  30155. break;
  30156. default:
  30157. error('JPX images with ' + this.numComps +
  30158. ' color components not supported.');
  30159. }
  30160. }
  30161. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30162. this.numComps = this.colorSpace.numComps;
  30163. }
  30164. this.decode = dict.get('Decode', 'D');
  30165. this.needsDecode = false;
  30166. if (this.decode &&
  30167. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30168. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30169. this.needsDecode = true;
  30170. // Do some preprocessing to avoid more math.
  30171. var max = (1 << bitsPerComponent) - 1;
  30172. this.decodeCoefficients = [];
  30173. this.decodeAddends = [];
  30174. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30175. var dmin = this.decode[i];
  30176. var dmax = this.decode[i + 1];
  30177. this.decodeCoefficients[j] = dmax - dmin;
  30178. this.decodeAddends[j] = max * dmin;
  30179. }
  30180. }
  30181. if (smask) {
  30182. this.smask = new PDFImage(xref, res, smask, false);
  30183. } else if (mask) {
  30184. if (isStream(mask)) {
  30185. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30186. } else {
  30187. // Color key mask (just an array).
  30188. this.mask = mask;
  30189. }
  30190. }
  30191. }
  30192. /**
  30193. * Handles processing of image data and returns the Promise that is resolved
  30194. * with a PDFImage when the image is ready to be used.
  30195. */
  30196. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30197. res, image, inline) {
  30198. var imagePromise = handleImageData(handler, xref, res, image);
  30199. var smaskPromise;
  30200. var maskPromise;
  30201. var smask = image.dict.get('SMask');
  30202. var mask = image.dict.get('Mask');
  30203. if (smask) {
  30204. smaskPromise = handleImageData(handler, xref, res, smask);
  30205. maskPromise = Promise.resolve(null);
  30206. } else {
  30207. smaskPromise = Promise.resolve(null);
  30208. if (mask) {
  30209. if (isStream(mask)) {
  30210. maskPromise = handleImageData(handler, xref, res, mask);
  30211. } else if (isArray(mask)) {
  30212. maskPromise = Promise.resolve(mask);
  30213. } else {
  30214. warn('Unsupported mask format.');
  30215. maskPromise = Promise.resolve(null);
  30216. }
  30217. } else {
  30218. maskPromise = Promise.resolve(null);
  30219. }
  30220. }
  30221. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30222. function(results) {
  30223. var imageData = results[0];
  30224. var smaskData = results[1];
  30225. var maskData = results[2];
  30226. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30227. });
  30228. };
  30229. /**
  30230. * Resize an image using the nearest neighbor algorithm. Currently only
  30231. * supports one and three component images.
  30232. * @param {TypedArray} pixels The original image with one component.
  30233. * @param {Number} bpc Number of bits per component.
  30234. * @param {Number} components Number of color components, 1 or 3 is supported.
  30235. * @param {Number} w1 Original width.
  30236. * @param {Number} h1 Original height.
  30237. * @param {Number} w2 New width.
  30238. * @param {Number} h2 New height.
  30239. * @param {TypedArray} dest (Optional) The destination buffer.
  30240. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30241. * @return {TypedArray} Resized image data.
  30242. */
  30243. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30244. w1, h1, w2, h2, dest, alpha01) {
  30245. if (components !== 1 && components !== 3) {
  30246. error('Unsupported component count for resizing.');
  30247. }
  30248. var length = w2 * h2 * components;
  30249. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30250. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30251. var xRatio = w1 / w2;
  30252. var yRatio = h1 / h2;
  30253. var i, j, py, newIndex = 0, oldIndex;
  30254. var xScaled = new Uint16Array(w2);
  30255. var w1Scanline = w1 * components;
  30256. if (alpha01 !== 1) {
  30257. alpha01 = 0;
  30258. }
  30259. for (j = 0; j < w2; j++) {
  30260. xScaled[j] = Math.floor(j * xRatio) * components;
  30261. }
  30262. if (components === 1) {
  30263. for (i = 0; i < h2; i++) {
  30264. py = Math.floor(i * yRatio) * w1Scanline;
  30265. for (j = 0; j < w2; j++) {
  30266. oldIndex = py + xScaled[j];
  30267. temp[newIndex++] = pixels[oldIndex];
  30268. }
  30269. }
  30270. } else if (components === 3) {
  30271. for (i = 0; i < h2; i++) {
  30272. py = Math.floor(i * yRatio) * w1Scanline;
  30273. for (j = 0; j < w2; j++) {
  30274. oldIndex = py + xScaled[j];
  30275. temp[newIndex++] = pixels[oldIndex++];
  30276. temp[newIndex++] = pixels[oldIndex++];
  30277. temp[newIndex++] = pixels[oldIndex++];
  30278. newIndex += alpha01;
  30279. }
  30280. }
  30281. }
  30282. return temp;
  30283. };
  30284. PDFImage.createMask =
  30285. function PDFImage_createMask(imgArray, width, height,
  30286. imageIsFromDecodeStream, inverseDecode) {
  30287. // |imgArray| might not contain full data for every pixel of the mask, so
  30288. // we need to distinguish between |computedLength| and |actualLength|.
  30289. // In particular, if inverseDecode is true, then the array we return must
  30290. // have a length of |computedLength|.
  30291. var computedLength = ((width + 7) >> 3) * height;
  30292. var actualLength = imgArray.byteLength;
  30293. var haveFullData = computedLength === actualLength;
  30294. var data, i;
  30295. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30296. // imgArray came from a DecodeStream and its data is in an appropriate
  30297. // form, so we can just transfer it.
  30298. data = imgArray;
  30299. } else if (!inverseDecode) {
  30300. data = new Uint8Array(actualLength);
  30301. data.set(imgArray);
  30302. } else {
  30303. data = new Uint8Array(computedLength);
  30304. data.set(imgArray);
  30305. for (i = actualLength; i < computedLength; i++) {
  30306. data[i] = 0xff;
  30307. }
  30308. }
  30309. // If necessary, invert the original mask data (but not any extra we might
  30310. // have added above). It's safe to modify the array -- whether it's the
  30311. // original or a copy, we're about to transfer it anyway, so nothing else
  30312. // in this thread can be relying on its contents.
  30313. if (inverseDecode) {
  30314. for (i = 0; i < actualLength; i++) {
  30315. data[i] = ~data[i];
  30316. }
  30317. }
  30318. return {data: data, width: width, height: height};
  30319. };
  30320. PDFImage.prototype = {
  30321. get drawWidth() {
  30322. return Math.max(this.width,
  30323. this.smask && this.smask.width || 0,
  30324. this.mask && this.mask.width || 0);
  30325. },
  30326. get drawHeight() {
  30327. return Math.max(this.height,
  30328. this.smask && this.smask.height || 0,
  30329. this.mask && this.mask.height || 0);
  30330. },
  30331. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30332. var bpc = this.bpc;
  30333. var numComps = this.numComps;
  30334. var decodeAddends = this.decodeAddends;
  30335. var decodeCoefficients = this.decodeCoefficients;
  30336. var max = (1 << bpc) - 1;
  30337. var i, ii;
  30338. if (bpc === 1) {
  30339. // If the buffer needed decode that means it just needs to be inverted.
  30340. for (i = 0, ii = buffer.length; i < ii; i++) {
  30341. buffer[i] = +!(buffer[i]);
  30342. }
  30343. return;
  30344. }
  30345. var index = 0;
  30346. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30347. for (var j = 0; j < numComps; j++) {
  30348. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30349. decodeCoefficients[j], max);
  30350. index++;
  30351. }
  30352. }
  30353. },
  30354. getComponents: function PDFImage_getComponents(buffer) {
  30355. var bpc = this.bpc;
  30356. // This image doesn't require any extra work.
  30357. if (bpc === 8) {
  30358. return buffer;
  30359. }
  30360. var width = this.width;
  30361. var height = this.height;
  30362. var numComps = this.numComps;
  30363. var length = width * height * numComps;
  30364. var bufferPos = 0;
  30365. var output = (bpc <= 8 ? new Uint8Array(length) :
  30366. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30367. var rowComps = width * numComps;
  30368. var max = (1 << bpc) - 1;
  30369. var i = 0, ii, buf;
  30370. if (bpc === 1) {
  30371. // Optimization for reading 1 bpc images.
  30372. var mask, loop1End, loop2End;
  30373. for (var j = 0; j < height; j++) {
  30374. loop1End = i + (rowComps & ~7);
  30375. loop2End = i + rowComps;
  30376. // unroll loop for all full bytes
  30377. while (i < loop1End) {
  30378. buf = buffer[bufferPos++];
  30379. output[i] = (buf >> 7) & 1;
  30380. output[i + 1] = (buf >> 6) & 1;
  30381. output[i + 2] = (buf >> 5) & 1;
  30382. output[i + 3] = (buf >> 4) & 1;
  30383. output[i + 4] = (buf >> 3) & 1;
  30384. output[i + 5] = (buf >> 2) & 1;
  30385. output[i + 6] = (buf >> 1) & 1;
  30386. output[i + 7] = buf & 1;
  30387. i += 8;
  30388. }
  30389. // handle remaing bits
  30390. if (i < loop2End) {
  30391. buf = buffer[bufferPos++];
  30392. mask = 128;
  30393. while (i < loop2End) {
  30394. output[i++] = +!!(buf & mask);
  30395. mask >>= 1;
  30396. }
  30397. }
  30398. }
  30399. } else {
  30400. // The general case that handles all other bpc values.
  30401. var bits = 0;
  30402. buf = 0;
  30403. for (i = 0, ii = length; i < ii; ++i) {
  30404. if (i % rowComps === 0) {
  30405. buf = 0;
  30406. bits = 0;
  30407. }
  30408. while (bits < bpc) {
  30409. buf = (buf << 8) | buffer[bufferPos++];
  30410. bits += 8;
  30411. }
  30412. var remainingBits = bits - bpc;
  30413. var value = buf >> remainingBits;
  30414. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30415. buf = buf & ((1 << remainingBits) - 1);
  30416. bits = remainingBits;
  30417. }
  30418. }
  30419. return output;
  30420. },
  30421. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30422. actualHeight, image) {
  30423. var smask = this.smask;
  30424. var mask = this.mask;
  30425. var alphaBuf, sw, sh, i, ii, j;
  30426. if (smask) {
  30427. sw = smask.width;
  30428. sh = smask.height;
  30429. alphaBuf = new Uint8Array(sw * sh);
  30430. smask.fillGrayBuffer(alphaBuf);
  30431. if (sw !== width || sh !== height) {
  30432. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30433. height);
  30434. }
  30435. } else if (mask) {
  30436. if (mask instanceof PDFImage) {
  30437. sw = mask.width;
  30438. sh = mask.height;
  30439. alphaBuf = new Uint8Array(sw * sh);
  30440. mask.numComps = 1;
  30441. mask.fillGrayBuffer(alphaBuf);
  30442. // Need to invert values in rgbaBuf
  30443. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30444. alphaBuf[i] = 255 - alphaBuf[i];
  30445. }
  30446. if (sw !== width || sh !== height) {
  30447. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30448. height);
  30449. }
  30450. } else if (isArray(mask)) {
  30451. // Color key mask: if any of the compontents are outside the range
  30452. // then they should be painted.
  30453. alphaBuf = new Uint8Array(width * height);
  30454. var numComps = this.numComps;
  30455. for (i = 0, ii = width * height; i < ii; ++i) {
  30456. var opacity = 0;
  30457. var imageOffset = i * numComps;
  30458. for (j = 0; j < numComps; ++j) {
  30459. var color = image[imageOffset + j];
  30460. var maskOffset = j * 2;
  30461. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30462. opacity = 255;
  30463. break;
  30464. }
  30465. }
  30466. alphaBuf[i] = opacity;
  30467. }
  30468. } else {
  30469. error('Unknown mask format.');
  30470. }
  30471. }
  30472. if (alphaBuf) {
  30473. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30474. rgbaBuf[j] = alphaBuf[i];
  30475. }
  30476. } else {
  30477. // No mask.
  30478. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30479. rgbaBuf[j] = 255;
  30480. }
  30481. }
  30482. },
  30483. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30484. var matte = this.smask && this.smask.matte;
  30485. if (!matte) {
  30486. return;
  30487. }
  30488. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30489. var matteR = matteRgb[0];
  30490. var matteG = matteRgb[1];
  30491. var matteB = matteRgb[2];
  30492. var length = width * height * 4;
  30493. var r, g, b;
  30494. for (var i = 0; i < length; i += 4) {
  30495. var alpha = buffer[i + 3];
  30496. if (alpha === 0) {
  30497. // according formula we have to get Infinity in all components
  30498. // making it white (typical paper color) should be okay
  30499. buffer[i] = 255;
  30500. buffer[i + 1] = 255;
  30501. buffer[i + 2] = 255;
  30502. continue;
  30503. }
  30504. var k = 255 / alpha;
  30505. r = (buffer[i] - matteR) * k + matteR;
  30506. g = (buffer[i + 1] - matteG) * k + matteG;
  30507. b = (buffer[i + 2] - matteB) * k + matteB;
  30508. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30509. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30510. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30511. }
  30512. },
  30513. createImageData: function PDFImage_createImageData(forceRGBA) {
  30514. var drawWidth = this.drawWidth;
  30515. var drawHeight = this.drawHeight;
  30516. var imgData = { // other fields are filled in below
  30517. width: drawWidth,
  30518. height: drawHeight
  30519. };
  30520. var numComps = this.numComps;
  30521. var originalWidth = this.width;
  30522. var originalHeight = this.height;
  30523. var bpc = this.bpc;
  30524. // Rows start at byte boundary.
  30525. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30526. var imgArray;
  30527. if (!forceRGBA) {
  30528. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30529. // without any complications, we pass a same-sized copy to the main
  30530. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30531. // of memory for many scanned documents. It's also much faster.
  30532. //
  30533. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30534. // complications, we avoid expanding by 1.333x to RGBA form.
  30535. var kind;
  30536. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30537. kind = ImageKind.GRAYSCALE_1BPP;
  30538. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30539. !this.needsDecode) {
  30540. kind = ImageKind.RGB_24BPP;
  30541. }
  30542. if (kind && !this.smask && !this.mask &&
  30543. drawWidth === originalWidth && drawHeight === originalHeight) {
  30544. imgData.kind = kind;
  30545. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30546. // If imgArray came from a DecodeStream, we're safe to transfer it
  30547. // (and thus neuter it) because it will constitute the entire
  30548. // DecodeStream's data. But if it came from a Stream, we need to
  30549. // copy it because it'll only be a portion of the Stream's data, and
  30550. // the rest will be read later on.
  30551. if (this.image instanceof DecodeStream) {
  30552. imgData.data = imgArray;
  30553. } else {
  30554. var newArray = new Uint8Array(imgArray.length);
  30555. newArray.set(imgArray);
  30556. imgData.data = newArray;
  30557. }
  30558. if (this.needsDecode) {
  30559. // Invert the buffer (which must be grayscale if we reached here).
  30560. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30561. var buffer = imgData.data;
  30562. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30563. buffer[i] ^= 0xff;
  30564. }
  30565. }
  30566. return imgData;
  30567. }
  30568. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30569. imgData.kind = ImageKind.RGB_24BPP;
  30570. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30571. drawWidth, drawHeight, true);
  30572. return imgData;
  30573. }
  30574. }
  30575. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30576. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30577. var actualHeight = 0 | (imgArray.length / rowBytes *
  30578. drawHeight / originalHeight);
  30579. var comps = this.getComponents(imgArray);
  30580. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30581. // more compact RGB_24BPP form if allowable.
  30582. var alpha01, maybeUndoPreblend;
  30583. if (!forceRGBA && !this.smask && !this.mask) {
  30584. imgData.kind = ImageKind.RGB_24BPP;
  30585. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30586. alpha01 = 0;
  30587. maybeUndoPreblend = false;
  30588. } else {
  30589. imgData.kind = ImageKind.RGBA_32BPP;
  30590. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30591. alpha01 = 1;
  30592. maybeUndoPreblend = true;
  30593. // Color key masking (opacity) must be performed before decoding.
  30594. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30595. comps);
  30596. }
  30597. if (this.needsDecode) {
  30598. this.decodeBuffer(comps);
  30599. }
  30600. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30601. drawWidth, drawHeight, actualHeight, bpc, comps,
  30602. alpha01);
  30603. if (maybeUndoPreblend) {
  30604. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30605. }
  30606. return imgData;
  30607. },
  30608. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30609. var numComps = this.numComps;
  30610. if (numComps !== 1) {
  30611. error('Reading gray scale from a color image: ' + numComps);
  30612. }
  30613. var width = this.width;
  30614. var height = this.height;
  30615. var bpc = this.bpc;
  30616. // rows start at byte boundary
  30617. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30618. var imgArray = this.getImageBytes(height * rowBytes);
  30619. var comps = this.getComponents(imgArray);
  30620. var i, length;
  30621. if (bpc === 1) {
  30622. // inline decoding (= inversion) for 1 bpc images
  30623. length = width * height;
  30624. if (this.needsDecode) {
  30625. // invert and scale to {0, 255}
  30626. for (i = 0; i < length; ++i) {
  30627. buffer[i] = (comps[i] - 1) & 255;
  30628. }
  30629. } else {
  30630. // scale to {0, 255}
  30631. for (i = 0; i < length; ++i) {
  30632. buffer[i] = (-comps[i]) & 255;
  30633. }
  30634. }
  30635. return;
  30636. }
  30637. if (this.needsDecode) {
  30638. this.decodeBuffer(comps);
  30639. }
  30640. length = width * height;
  30641. // we aren't using a colorspace so we need to scale the value
  30642. var scale = 255 / ((1 << bpc) - 1);
  30643. for (i = 0; i < length; ++i) {
  30644. buffer[i] = (scale * comps[i]) | 0;
  30645. }
  30646. },
  30647. getImageBytes: function PDFImage_getImageBytes(length,
  30648. drawWidth, drawHeight,
  30649. forceRGB) {
  30650. this.image.reset();
  30651. this.image.drawWidth = drawWidth || this.width;
  30652. this.image.drawHeight = drawHeight || this.height;
  30653. this.image.forceRGB = !!forceRGB;
  30654. return this.image.getBytes(length);
  30655. }
  30656. };
  30657. return PDFImage;
  30658. })();
  30659. // The Metrics object contains glyph widths (in glyph space units).
  30660. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  30661. // space unit corresponds to 1/1000th of text space unit.
  30662. var Metrics = {
  30663. 'Courier': 600,
  30664. 'Courier-Bold': 600,
  30665. 'Courier-BoldOblique': 600,
  30666. 'Courier-Oblique': 600,
  30667. 'Helvetica' : {
  30668. 'space': 278,
  30669. 'exclam': 278,
  30670. 'quotedbl': 355,
  30671. 'numbersign': 556,
  30672. 'dollar': 556,
  30673. 'percent': 889,
  30674. 'ampersand': 667,
  30675. 'quoteright': 222,
  30676. 'parenleft': 333,
  30677. 'parenright': 333,
  30678. 'asterisk': 389,
  30679. 'plus': 584,
  30680. 'comma': 278,
  30681. 'hyphen': 333,
  30682. 'period': 278,
  30683. 'slash': 278,
  30684. 'zero': 556,
  30685. 'one': 556,
  30686. 'two': 556,
  30687. 'three': 556,
  30688. 'four': 556,
  30689. 'five': 556,
  30690. 'six': 556,
  30691. 'seven': 556,
  30692. 'eight': 556,
  30693. 'nine': 556,
  30694. 'colon': 278,
  30695. 'semicolon': 278,
  30696. 'less': 584,
  30697. 'equal': 584,
  30698. 'greater': 584,
  30699. 'question': 556,
  30700. 'at': 1015,
  30701. 'A': 667,
  30702. 'B': 667,
  30703. 'C': 722,
  30704. 'D': 722,
  30705. 'E': 667,
  30706. 'F': 611,
  30707. 'G': 778,
  30708. 'H': 722,
  30709. 'I': 278,
  30710. 'J': 500,
  30711. 'K': 667,
  30712. 'L': 556,
  30713. 'M': 833,
  30714. 'N': 722,
  30715. 'O': 778,
  30716. 'P': 667,
  30717. 'Q': 778,
  30718. 'R': 722,
  30719. 'S': 667,
  30720. 'T': 611,
  30721. 'U': 722,
  30722. 'V': 667,
  30723. 'W': 944,
  30724. 'X': 667,
  30725. 'Y': 667,
  30726. 'Z': 611,
  30727. 'bracketleft': 278,
  30728. 'backslash': 278,
  30729. 'bracketright': 278,
  30730. 'asciicircum': 469,
  30731. 'underscore': 556,
  30732. 'quoteleft': 222,
  30733. 'a': 556,
  30734. 'b': 556,
  30735. 'c': 500,
  30736. 'd': 556,
  30737. 'e': 556,
  30738. 'f': 278,
  30739. 'g': 556,
  30740. 'h': 556,
  30741. 'i': 222,
  30742. 'j': 222,
  30743. 'k': 500,
  30744. 'l': 222,
  30745. 'm': 833,
  30746. 'n': 556,
  30747. 'o': 556,
  30748. 'p': 556,
  30749. 'q': 556,
  30750. 'r': 333,
  30751. 's': 500,
  30752. 't': 278,
  30753. 'u': 556,
  30754. 'v': 500,
  30755. 'w': 722,
  30756. 'x': 500,
  30757. 'y': 500,
  30758. 'z': 500,
  30759. 'braceleft': 334,
  30760. 'bar': 260,
  30761. 'braceright': 334,
  30762. 'asciitilde': 584,
  30763. 'exclamdown': 333,
  30764. 'cent': 556,
  30765. 'sterling': 556,
  30766. 'fraction': 167,
  30767. 'yen': 556,
  30768. 'florin': 556,
  30769. 'section': 556,
  30770. 'currency': 556,
  30771. 'quotesingle': 191,
  30772. 'quotedblleft': 333,
  30773. 'guillemotleft': 556,
  30774. 'guilsinglleft': 333,
  30775. 'guilsinglright': 333,
  30776. 'fi': 500,
  30777. 'fl': 500,
  30778. 'endash': 556,
  30779. 'dagger': 556,
  30780. 'daggerdbl': 556,
  30781. 'periodcentered': 278,
  30782. 'paragraph': 537,
  30783. 'bullet': 350,
  30784. 'quotesinglbase': 222,
  30785. 'quotedblbase': 333,
  30786. 'quotedblright': 333,
  30787. 'guillemotright': 556,
  30788. 'ellipsis': 1000,
  30789. 'perthousand': 1000,
  30790. 'questiondown': 611,
  30791. 'grave': 333,
  30792. 'acute': 333,
  30793. 'circumflex': 333,
  30794. 'tilde': 333,
  30795. 'macron': 333,
  30796. 'breve': 333,
  30797. 'dotaccent': 333,
  30798. 'dieresis': 333,
  30799. 'ring': 333,
  30800. 'cedilla': 333,
  30801. 'hungarumlaut': 333,
  30802. 'ogonek': 333,
  30803. 'caron': 333,
  30804. 'emdash': 1000,
  30805. 'AE': 1000,
  30806. 'ordfeminine': 370,
  30807. 'Lslash': 556,
  30808. 'Oslash': 778,
  30809. 'OE': 1000,
  30810. 'ordmasculine': 365,
  30811. 'ae': 889,
  30812. 'dotlessi': 278,
  30813. 'lslash': 222,
  30814. 'oslash': 611,
  30815. 'oe': 944,
  30816. 'germandbls': 611,
  30817. 'Idieresis': 278,
  30818. 'eacute': 556,
  30819. 'abreve': 556,
  30820. 'uhungarumlaut': 556,
  30821. 'ecaron': 556,
  30822. 'Ydieresis': 667,
  30823. 'divide': 584,
  30824. 'Yacute': 667,
  30825. 'Acircumflex': 667,
  30826. 'aacute': 556,
  30827. 'Ucircumflex': 722,
  30828. 'yacute': 500,
  30829. 'scommaaccent': 500,
  30830. 'ecircumflex': 556,
  30831. 'Uring': 722,
  30832. 'Udieresis': 722,
  30833. 'aogonek': 556,
  30834. 'Uacute': 722,
  30835. 'uogonek': 556,
  30836. 'Edieresis': 667,
  30837. 'Dcroat': 722,
  30838. 'commaaccent': 250,
  30839. 'copyright': 737,
  30840. 'Emacron': 667,
  30841. 'ccaron': 500,
  30842. 'aring': 556,
  30843. 'Ncommaaccent': 722,
  30844. 'lacute': 222,
  30845. 'agrave': 556,
  30846. 'Tcommaaccent': 611,
  30847. 'Cacute': 722,
  30848. 'atilde': 556,
  30849. 'Edotaccent': 667,
  30850. 'scaron': 500,
  30851. 'scedilla': 500,
  30852. 'iacute': 278,
  30853. 'lozenge': 471,
  30854. 'Rcaron': 722,
  30855. 'Gcommaaccent': 778,
  30856. 'ucircumflex': 556,
  30857. 'acircumflex': 556,
  30858. 'Amacron': 667,
  30859. 'rcaron': 333,
  30860. 'ccedilla': 500,
  30861. 'Zdotaccent': 611,
  30862. 'Thorn': 667,
  30863. 'Omacron': 778,
  30864. 'Racute': 722,
  30865. 'Sacute': 667,
  30866. 'dcaron': 643,
  30867. 'Umacron': 722,
  30868. 'uring': 556,
  30869. 'threesuperior': 333,
  30870. 'Ograve': 778,
  30871. 'Agrave': 667,
  30872. 'Abreve': 667,
  30873. 'multiply': 584,
  30874. 'uacute': 556,
  30875. 'Tcaron': 611,
  30876. 'partialdiff': 476,
  30877. 'ydieresis': 500,
  30878. 'Nacute': 722,
  30879. 'icircumflex': 278,
  30880. 'Ecircumflex': 667,
  30881. 'adieresis': 556,
  30882. 'edieresis': 556,
  30883. 'cacute': 500,
  30884. 'nacute': 556,
  30885. 'umacron': 556,
  30886. 'Ncaron': 722,
  30887. 'Iacute': 278,
  30888. 'plusminus': 584,
  30889. 'brokenbar': 260,
  30890. 'registered': 737,
  30891. 'Gbreve': 778,
  30892. 'Idotaccent': 278,
  30893. 'summation': 600,
  30894. 'Egrave': 667,
  30895. 'racute': 333,
  30896. 'omacron': 556,
  30897. 'Zacute': 611,
  30898. 'Zcaron': 611,
  30899. 'greaterequal': 549,
  30900. 'Eth': 722,
  30901. 'Ccedilla': 722,
  30902. 'lcommaaccent': 222,
  30903. 'tcaron': 317,
  30904. 'eogonek': 556,
  30905. 'Uogonek': 722,
  30906. 'Aacute': 667,
  30907. 'Adieresis': 667,
  30908. 'egrave': 556,
  30909. 'zacute': 500,
  30910. 'iogonek': 222,
  30911. 'Oacute': 778,
  30912. 'oacute': 556,
  30913. 'amacron': 556,
  30914. 'sacute': 500,
  30915. 'idieresis': 278,
  30916. 'Ocircumflex': 778,
  30917. 'Ugrave': 722,
  30918. 'Delta': 612,
  30919. 'thorn': 556,
  30920. 'twosuperior': 333,
  30921. 'Odieresis': 778,
  30922. 'mu': 556,
  30923. 'igrave': 278,
  30924. 'ohungarumlaut': 556,
  30925. 'Eogonek': 667,
  30926. 'dcroat': 556,
  30927. 'threequarters': 834,
  30928. 'Scedilla': 667,
  30929. 'lcaron': 299,
  30930. 'Kcommaaccent': 667,
  30931. 'Lacute': 556,
  30932. 'trademark': 1000,
  30933. 'edotaccent': 556,
  30934. 'Igrave': 278,
  30935. 'Imacron': 278,
  30936. 'Lcaron': 556,
  30937. 'onehalf': 834,
  30938. 'lessequal': 549,
  30939. 'ocircumflex': 556,
  30940. 'ntilde': 556,
  30941. 'Uhungarumlaut': 722,
  30942. 'Eacute': 667,
  30943. 'emacron': 556,
  30944. 'gbreve': 556,
  30945. 'onequarter': 834,
  30946. 'Scaron': 667,
  30947. 'Scommaaccent': 667,
  30948. 'Ohungarumlaut': 778,
  30949. 'degree': 400,
  30950. 'ograve': 556,
  30951. 'Ccaron': 722,
  30952. 'ugrave': 556,
  30953. 'radical': 453,
  30954. 'Dcaron': 722,
  30955. 'rcommaaccent': 333,
  30956. 'Ntilde': 722,
  30957. 'otilde': 556,
  30958. 'Rcommaaccent': 722,
  30959. 'Lcommaaccent': 556,
  30960. 'Atilde': 667,
  30961. 'Aogonek': 667,
  30962. 'Aring': 667,
  30963. 'Otilde': 778,
  30964. 'zdotaccent': 500,
  30965. 'Ecaron': 667,
  30966. 'Iogonek': 278,
  30967. 'kcommaaccent': 500,
  30968. 'minus': 584,
  30969. 'Icircumflex': 278,
  30970. 'ncaron': 556,
  30971. 'tcommaaccent': 278,
  30972. 'logicalnot': 584,
  30973. 'odieresis': 556,
  30974. 'udieresis': 556,
  30975. 'notequal': 549,
  30976. 'gcommaaccent': 556,
  30977. 'eth': 556,
  30978. 'zcaron': 500,
  30979. 'ncommaaccent': 556,
  30980. 'onesuperior': 333,
  30981. 'imacron': 278,
  30982. 'Euro': 556
  30983. },
  30984. 'Helvetica-Bold': {
  30985. 'space': 278,
  30986. 'exclam': 333,
  30987. 'quotedbl': 474,
  30988. 'numbersign': 556,
  30989. 'dollar': 556,
  30990. 'percent': 889,
  30991. 'ampersand': 722,
  30992. 'quoteright': 278,
  30993. 'parenleft': 333,
  30994. 'parenright': 333,
  30995. 'asterisk': 389,
  30996. 'plus': 584,
  30997. 'comma': 278,
  30998. 'hyphen': 333,
  30999. 'period': 278,
  31000. 'slash': 278,
  31001. 'zero': 556,
  31002. 'one': 556,
  31003. 'two': 556,
  31004. 'three': 556,
  31005. 'four': 556,
  31006. 'five': 556,
  31007. 'six': 556,
  31008. 'seven': 556,
  31009. 'eight': 556,
  31010. 'nine': 556,
  31011. 'colon': 333,
  31012. 'semicolon': 333,
  31013. 'less': 584,
  31014. 'equal': 584,
  31015. 'greater': 584,
  31016. 'question': 611,
  31017. 'at': 975,
  31018. 'A': 722,
  31019. 'B': 722,
  31020. 'C': 722,
  31021. 'D': 722,
  31022. 'E': 667,
  31023. 'F': 611,
  31024. 'G': 778,
  31025. 'H': 722,
  31026. 'I': 278,
  31027. 'J': 556,
  31028. 'K': 722,
  31029. 'L': 611,
  31030. 'M': 833,
  31031. 'N': 722,
  31032. 'O': 778,
  31033. 'P': 667,
  31034. 'Q': 778,
  31035. 'R': 722,
  31036. 'S': 667,
  31037. 'T': 611,
  31038. 'U': 722,
  31039. 'V': 667,
  31040. 'W': 944,
  31041. 'X': 667,
  31042. 'Y': 667,
  31043. 'Z': 611,
  31044. 'bracketleft': 333,
  31045. 'backslash': 278,
  31046. 'bracketright': 333,
  31047. 'asciicircum': 584,
  31048. 'underscore': 556,
  31049. 'quoteleft': 278,
  31050. 'a': 556,
  31051. 'b': 611,
  31052. 'c': 556,
  31053. 'd': 611,
  31054. 'e': 556,
  31055. 'f': 333,
  31056. 'g': 611,
  31057. 'h': 611,
  31058. 'i': 278,
  31059. 'j': 278,
  31060. 'k': 556,
  31061. 'l': 278,
  31062. 'm': 889,
  31063. 'n': 611,
  31064. 'o': 611,
  31065. 'p': 611,
  31066. 'q': 611,
  31067. 'r': 389,
  31068. 's': 556,
  31069. 't': 333,
  31070. 'u': 611,
  31071. 'v': 556,
  31072. 'w': 778,
  31073. 'x': 556,
  31074. 'y': 556,
  31075. 'z': 500,
  31076. 'braceleft': 389,
  31077. 'bar': 280,
  31078. 'braceright': 389,
  31079. 'asciitilde': 584,
  31080. 'exclamdown': 333,
  31081. 'cent': 556,
  31082. 'sterling': 556,
  31083. 'fraction': 167,
  31084. 'yen': 556,
  31085. 'florin': 556,
  31086. 'section': 556,
  31087. 'currency': 556,
  31088. 'quotesingle': 238,
  31089. 'quotedblleft': 500,
  31090. 'guillemotleft': 556,
  31091. 'guilsinglleft': 333,
  31092. 'guilsinglright': 333,
  31093. 'fi': 611,
  31094. 'fl': 611,
  31095. 'endash': 556,
  31096. 'dagger': 556,
  31097. 'daggerdbl': 556,
  31098. 'periodcentered': 278,
  31099. 'paragraph': 556,
  31100. 'bullet': 350,
  31101. 'quotesinglbase': 278,
  31102. 'quotedblbase': 500,
  31103. 'quotedblright': 500,
  31104. 'guillemotright': 556,
  31105. 'ellipsis': 1000,
  31106. 'perthousand': 1000,
  31107. 'questiondown': 611,
  31108. 'grave': 333,
  31109. 'acute': 333,
  31110. 'circumflex': 333,
  31111. 'tilde': 333,
  31112. 'macron': 333,
  31113. 'breve': 333,
  31114. 'dotaccent': 333,
  31115. 'dieresis': 333,
  31116. 'ring': 333,
  31117. 'cedilla': 333,
  31118. 'hungarumlaut': 333,
  31119. 'ogonek': 333,
  31120. 'caron': 333,
  31121. 'emdash': 1000,
  31122. 'AE': 1000,
  31123. 'ordfeminine': 370,
  31124. 'Lslash': 611,
  31125. 'Oslash': 778,
  31126. 'OE': 1000,
  31127. 'ordmasculine': 365,
  31128. 'ae': 889,
  31129. 'dotlessi': 278,
  31130. 'lslash': 278,
  31131. 'oslash': 611,
  31132. 'oe': 944,
  31133. 'germandbls': 611,
  31134. 'Idieresis': 278,
  31135. 'eacute': 556,
  31136. 'abreve': 556,
  31137. 'uhungarumlaut': 611,
  31138. 'ecaron': 556,
  31139. 'Ydieresis': 667,
  31140. 'divide': 584,
  31141. 'Yacute': 667,
  31142. 'Acircumflex': 722,
  31143. 'aacute': 556,
  31144. 'Ucircumflex': 722,
  31145. 'yacute': 556,
  31146. 'scommaaccent': 556,
  31147. 'ecircumflex': 556,
  31148. 'Uring': 722,
  31149. 'Udieresis': 722,
  31150. 'aogonek': 556,
  31151. 'Uacute': 722,
  31152. 'uogonek': 611,
  31153. 'Edieresis': 667,
  31154. 'Dcroat': 722,
  31155. 'commaaccent': 250,
  31156. 'copyright': 737,
  31157. 'Emacron': 667,
  31158. 'ccaron': 556,
  31159. 'aring': 556,
  31160. 'Ncommaaccent': 722,
  31161. 'lacute': 278,
  31162. 'agrave': 556,
  31163. 'Tcommaaccent': 611,
  31164. 'Cacute': 722,
  31165. 'atilde': 556,
  31166. 'Edotaccent': 667,
  31167. 'scaron': 556,
  31168. 'scedilla': 556,
  31169. 'iacute': 278,
  31170. 'lozenge': 494,
  31171. 'Rcaron': 722,
  31172. 'Gcommaaccent': 778,
  31173. 'ucircumflex': 611,
  31174. 'acircumflex': 556,
  31175. 'Amacron': 722,
  31176. 'rcaron': 389,
  31177. 'ccedilla': 556,
  31178. 'Zdotaccent': 611,
  31179. 'Thorn': 667,
  31180. 'Omacron': 778,
  31181. 'Racute': 722,
  31182. 'Sacute': 667,
  31183. 'dcaron': 743,
  31184. 'Umacron': 722,
  31185. 'uring': 611,
  31186. 'threesuperior': 333,
  31187. 'Ograve': 778,
  31188. 'Agrave': 722,
  31189. 'Abreve': 722,
  31190. 'multiply': 584,
  31191. 'uacute': 611,
  31192. 'Tcaron': 611,
  31193. 'partialdiff': 494,
  31194. 'ydieresis': 556,
  31195. 'Nacute': 722,
  31196. 'icircumflex': 278,
  31197. 'Ecircumflex': 667,
  31198. 'adieresis': 556,
  31199. 'edieresis': 556,
  31200. 'cacute': 556,
  31201. 'nacute': 611,
  31202. 'umacron': 611,
  31203. 'Ncaron': 722,
  31204. 'Iacute': 278,
  31205. 'plusminus': 584,
  31206. 'brokenbar': 280,
  31207. 'registered': 737,
  31208. 'Gbreve': 778,
  31209. 'Idotaccent': 278,
  31210. 'summation': 600,
  31211. 'Egrave': 667,
  31212. 'racute': 389,
  31213. 'omacron': 611,
  31214. 'Zacute': 611,
  31215. 'Zcaron': 611,
  31216. 'greaterequal': 549,
  31217. 'Eth': 722,
  31218. 'Ccedilla': 722,
  31219. 'lcommaaccent': 278,
  31220. 'tcaron': 389,
  31221. 'eogonek': 556,
  31222. 'Uogonek': 722,
  31223. 'Aacute': 722,
  31224. 'Adieresis': 722,
  31225. 'egrave': 556,
  31226. 'zacute': 500,
  31227. 'iogonek': 278,
  31228. 'Oacute': 778,
  31229. 'oacute': 611,
  31230. 'amacron': 556,
  31231. 'sacute': 556,
  31232. 'idieresis': 278,
  31233. 'Ocircumflex': 778,
  31234. 'Ugrave': 722,
  31235. 'Delta': 612,
  31236. 'thorn': 611,
  31237. 'twosuperior': 333,
  31238. 'Odieresis': 778,
  31239. 'mu': 611,
  31240. 'igrave': 278,
  31241. 'ohungarumlaut': 611,
  31242. 'Eogonek': 667,
  31243. 'dcroat': 611,
  31244. 'threequarters': 834,
  31245. 'Scedilla': 667,
  31246. 'lcaron': 400,
  31247. 'Kcommaaccent': 722,
  31248. 'Lacute': 611,
  31249. 'trademark': 1000,
  31250. 'edotaccent': 556,
  31251. 'Igrave': 278,
  31252. 'Imacron': 278,
  31253. 'Lcaron': 611,
  31254. 'onehalf': 834,
  31255. 'lessequal': 549,
  31256. 'ocircumflex': 611,
  31257. 'ntilde': 611,
  31258. 'Uhungarumlaut': 722,
  31259. 'Eacute': 667,
  31260. 'emacron': 556,
  31261. 'gbreve': 611,
  31262. 'onequarter': 834,
  31263. 'Scaron': 667,
  31264. 'Scommaaccent': 667,
  31265. 'Ohungarumlaut': 778,
  31266. 'degree': 400,
  31267. 'ograve': 611,
  31268. 'Ccaron': 722,
  31269. 'ugrave': 611,
  31270. 'radical': 549,
  31271. 'Dcaron': 722,
  31272. 'rcommaaccent': 389,
  31273. 'Ntilde': 722,
  31274. 'otilde': 611,
  31275. 'Rcommaaccent': 722,
  31276. 'Lcommaaccent': 611,
  31277. 'Atilde': 722,
  31278. 'Aogonek': 722,
  31279. 'Aring': 722,
  31280. 'Otilde': 778,
  31281. 'zdotaccent': 500,
  31282. 'Ecaron': 667,
  31283. 'Iogonek': 278,
  31284. 'kcommaaccent': 556,
  31285. 'minus': 584,
  31286. 'Icircumflex': 278,
  31287. 'ncaron': 611,
  31288. 'tcommaaccent': 333,
  31289. 'logicalnot': 584,
  31290. 'odieresis': 611,
  31291. 'udieresis': 611,
  31292. 'notequal': 549,
  31293. 'gcommaaccent': 611,
  31294. 'eth': 611,
  31295. 'zcaron': 500,
  31296. 'ncommaaccent': 611,
  31297. 'onesuperior': 333,
  31298. 'imacron': 278,
  31299. 'Euro': 556
  31300. },
  31301. 'Helvetica-BoldOblique': {
  31302. 'space': 278,
  31303. 'exclam': 333,
  31304. 'quotedbl': 474,
  31305. 'numbersign': 556,
  31306. 'dollar': 556,
  31307. 'percent': 889,
  31308. 'ampersand': 722,
  31309. 'quoteright': 278,
  31310. 'parenleft': 333,
  31311. 'parenright': 333,
  31312. 'asterisk': 389,
  31313. 'plus': 584,
  31314. 'comma': 278,
  31315. 'hyphen': 333,
  31316. 'period': 278,
  31317. 'slash': 278,
  31318. 'zero': 556,
  31319. 'one': 556,
  31320. 'two': 556,
  31321. 'three': 556,
  31322. 'four': 556,
  31323. 'five': 556,
  31324. 'six': 556,
  31325. 'seven': 556,
  31326. 'eight': 556,
  31327. 'nine': 556,
  31328. 'colon': 333,
  31329. 'semicolon': 333,
  31330. 'less': 584,
  31331. 'equal': 584,
  31332. 'greater': 584,
  31333. 'question': 611,
  31334. 'at': 975,
  31335. 'A': 722,
  31336. 'B': 722,
  31337. 'C': 722,
  31338. 'D': 722,
  31339. 'E': 667,
  31340. 'F': 611,
  31341. 'G': 778,
  31342. 'H': 722,
  31343. 'I': 278,
  31344. 'J': 556,
  31345. 'K': 722,
  31346. 'L': 611,
  31347. 'M': 833,
  31348. 'N': 722,
  31349. 'O': 778,
  31350. 'P': 667,
  31351. 'Q': 778,
  31352. 'R': 722,
  31353. 'S': 667,
  31354. 'T': 611,
  31355. 'U': 722,
  31356. 'V': 667,
  31357. 'W': 944,
  31358. 'X': 667,
  31359. 'Y': 667,
  31360. 'Z': 611,
  31361. 'bracketleft': 333,
  31362. 'backslash': 278,
  31363. 'bracketright': 333,
  31364. 'asciicircum': 584,
  31365. 'underscore': 556,
  31366. 'quoteleft': 278,
  31367. 'a': 556,
  31368. 'b': 611,
  31369. 'c': 556,
  31370. 'd': 611,
  31371. 'e': 556,
  31372. 'f': 333,
  31373. 'g': 611,
  31374. 'h': 611,
  31375. 'i': 278,
  31376. 'j': 278,
  31377. 'k': 556,
  31378. 'l': 278,
  31379. 'm': 889,
  31380. 'n': 611,
  31381. 'o': 611,
  31382. 'p': 611,
  31383. 'q': 611,
  31384. 'r': 389,
  31385. 's': 556,
  31386. 't': 333,
  31387. 'u': 611,
  31388. 'v': 556,
  31389. 'w': 778,
  31390. 'x': 556,
  31391. 'y': 556,
  31392. 'z': 500,
  31393. 'braceleft': 389,
  31394. 'bar': 280,
  31395. 'braceright': 389,
  31396. 'asciitilde': 584,
  31397. 'exclamdown': 333,
  31398. 'cent': 556,
  31399. 'sterling': 556,
  31400. 'fraction': 167,
  31401. 'yen': 556,
  31402. 'florin': 556,
  31403. 'section': 556,
  31404. 'currency': 556,
  31405. 'quotesingle': 238,
  31406. 'quotedblleft': 500,
  31407. 'guillemotleft': 556,
  31408. 'guilsinglleft': 333,
  31409. 'guilsinglright': 333,
  31410. 'fi': 611,
  31411. 'fl': 611,
  31412. 'endash': 556,
  31413. 'dagger': 556,
  31414. 'daggerdbl': 556,
  31415. 'periodcentered': 278,
  31416. 'paragraph': 556,
  31417. 'bullet': 350,
  31418. 'quotesinglbase': 278,
  31419. 'quotedblbase': 500,
  31420. 'quotedblright': 500,
  31421. 'guillemotright': 556,
  31422. 'ellipsis': 1000,
  31423. 'perthousand': 1000,
  31424. 'questiondown': 611,
  31425. 'grave': 333,
  31426. 'acute': 333,
  31427. 'circumflex': 333,
  31428. 'tilde': 333,
  31429. 'macron': 333,
  31430. 'breve': 333,
  31431. 'dotaccent': 333,
  31432. 'dieresis': 333,
  31433. 'ring': 333,
  31434. 'cedilla': 333,
  31435. 'hungarumlaut': 333,
  31436. 'ogonek': 333,
  31437. 'caron': 333,
  31438. 'emdash': 1000,
  31439. 'AE': 1000,
  31440. 'ordfeminine': 370,
  31441. 'Lslash': 611,
  31442. 'Oslash': 778,
  31443. 'OE': 1000,
  31444. 'ordmasculine': 365,
  31445. 'ae': 889,
  31446. 'dotlessi': 278,
  31447. 'lslash': 278,
  31448. 'oslash': 611,
  31449. 'oe': 944,
  31450. 'germandbls': 611,
  31451. 'Idieresis': 278,
  31452. 'eacute': 556,
  31453. 'abreve': 556,
  31454. 'uhungarumlaut': 611,
  31455. 'ecaron': 556,
  31456. 'Ydieresis': 667,
  31457. 'divide': 584,
  31458. 'Yacute': 667,
  31459. 'Acircumflex': 722,
  31460. 'aacute': 556,
  31461. 'Ucircumflex': 722,
  31462. 'yacute': 556,
  31463. 'scommaaccent': 556,
  31464. 'ecircumflex': 556,
  31465. 'Uring': 722,
  31466. 'Udieresis': 722,
  31467. 'aogonek': 556,
  31468. 'Uacute': 722,
  31469. 'uogonek': 611,
  31470. 'Edieresis': 667,
  31471. 'Dcroat': 722,
  31472. 'commaaccent': 250,
  31473. 'copyright': 737,
  31474. 'Emacron': 667,
  31475. 'ccaron': 556,
  31476. 'aring': 556,
  31477. 'Ncommaaccent': 722,
  31478. 'lacute': 278,
  31479. 'agrave': 556,
  31480. 'Tcommaaccent': 611,
  31481. 'Cacute': 722,
  31482. 'atilde': 556,
  31483. 'Edotaccent': 667,
  31484. 'scaron': 556,
  31485. 'scedilla': 556,
  31486. 'iacute': 278,
  31487. 'lozenge': 494,
  31488. 'Rcaron': 722,
  31489. 'Gcommaaccent': 778,
  31490. 'ucircumflex': 611,
  31491. 'acircumflex': 556,
  31492. 'Amacron': 722,
  31493. 'rcaron': 389,
  31494. 'ccedilla': 556,
  31495. 'Zdotaccent': 611,
  31496. 'Thorn': 667,
  31497. 'Omacron': 778,
  31498. 'Racute': 722,
  31499. 'Sacute': 667,
  31500. 'dcaron': 743,
  31501. 'Umacron': 722,
  31502. 'uring': 611,
  31503. 'threesuperior': 333,
  31504. 'Ograve': 778,
  31505. 'Agrave': 722,
  31506. 'Abreve': 722,
  31507. 'multiply': 584,
  31508. 'uacute': 611,
  31509. 'Tcaron': 611,
  31510. 'partialdiff': 494,
  31511. 'ydieresis': 556,
  31512. 'Nacute': 722,
  31513. 'icircumflex': 278,
  31514. 'Ecircumflex': 667,
  31515. 'adieresis': 556,
  31516. 'edieresis': 556,
  31517. 'cacute': 556,
  31518. 'nacute': 611,
  31519. 'umacron': 611,
  31520. 'Ncaron': 722,
  31521. 'Iacute': 278,
  31522. 'plusminus': 584,
  31523. 'brokenbar': 280,
  31524. 'registered': 737,
  31525. 'Gbreve': 778,
  31526. 'Idotaccent': 278,
  31527. 'summation': 600,
  31528. 'Egrave': 667,
  31529. 'racute': 389,
  31530. 'omacron': 611,
  31531. 'Zacute': 611,
  31532. 'Zcaron': 611,
  31533. 'greaterequal': 549,
  31534. 'Eth': 722,
  31535. 'Ccedilla': 722,
  31536. 'lcommaaccent': 278,
  31537. 'tcaron': 389,
  31538. 'eogonek': 556,
  31539. 'Uogonek': 722,
  31540. 'Aacute': 722,
  31541. 'Adieresis': 722,
  31542. 'egrave': 556,
  31543. 'zacute': 500,
  31544. 'iogonek': 278,
  31545. 'Oacute': 778,
  31546. 'oacute': 611,
  31547. 'amacron': 556,
  31548. 'sacute': 556,
  31549. 'idieresis': 278,
  31550. 'Ocircumflex': 778,
  31551. 'Ugrave': 722,
  31552. 'Delta': 612,
  31553. 'thorn': 611,
  31554. 'twosuperior': 333,
  31555. 'Odieresis': 778,
  31556. 'mu': 611,
  31557. 'igrave': 278,
  31558. 'ohungarumlaut': 611,
  31559. 'Eogonek': 667,
  31560. 'dcroat': 611,
  31561. 'threequarters': 834,
  31562. 'Scedilla': 667,
  31563. 'lcaron': 400,
  31564. 'Kcommaaccent': 722,
  31565. 'Lacute': 611,
  31566. 'trademark': 1000,
  31567. 'edotaccent': 556,
  31568. 'Igrave': 278,
  31569. 'Imacron': 278,
  31570. 'Lcaron': 611,
  31571. 'onehalf': 834,
  31572. 'lessequal': 549,
  31573. 'ocircumflex': 611,
  31574. 'ntilde': 611,
  31575. 'Uhungarumlaut': 722,
  31576. 'Eacute': 667,
  31577. 'emacron': 556,
  31578. 'gbreve': 611,
  31579. 'onequarter': 834,
  31580. 'Scaron': 667,
  31581. 'Scommaaccent': 667,
  31582. 'Ohungarumlaut': 778,
  31583. 'degree': 400,
  31584. 'ograve': 611,
  31585. 'Ccaron': 722,
  31586. 'ugrave': 611,
  31587. 'radical': 549,
  31588. 'Dcaron': 722,
  31589. 'rcommaaccent': 389,
  31590. 'Ntilde': 722,
  31591. 'otilde': 611,
  31592. 'Rcommaaccent': 722,
  31593. 'Lcommaaccent': 611,
  31594. 'Atilde': 722,
  31595. 'Aogonek': 722,
  31596. 'Aring': 722,
  31597. 'Otilde': 778,
  31598. 'zdotaccent': 500,
  31599. 'Ecaron': 667,
  31600. 'Iogonek': 278,
  31601. 'kcommaaccent': 556,
  31602. 'minus': 584,
  31603. 'Icircumflex': 278,
  31604. 'ncaron': 611,
  31605. 'tcommaaccent': 333,
  31606. 'logicalnot': 584,
  31607. 'odieresis': 611,
  31608. 'udieresis': 611,
  31609. 'notequal': 549,
  31610. 'gcommaaccent': 611,
  31611. 'eth': 611,
  31612. 'zcaron': 500,
  31613. 'ncommaaccent': 611,
  31614. 'onesuperior': 333,
  31615. 'imacron': 278,
  31616. 'Euro': 556
  31617. },
  31618. 'Helvetica-Oblique' : {
  31619. 'space': 278,
  31620. 'exclam': 278,
  31621. 'quotedbl': 355,
  31622. 'numbersign': 556,
  31623. 'dollar': 556,
  31624. 'percent': 889,
  31625. 'ampersand': 667,
  31626. 'quoteright': 222,
  31627. 'parenleft': 333,
  31628. 'parenright': 333,
  31629. 'asterisk': 389,
  31630. 'plus': 584,
  31631. 'comma': 278,
  31632. 'hyphen': 333,
  31633. 'period': 278,
  31634. 'slash': 278,
  31635. 'zero': 556,
  31636. 'one': 556,
  31637. 'two': 556,
  31638. 'three': 556,
  31639. 'four': 556,
  31640. 'five': 556,
  31641. 'six': 556,
  31642. 'seven': 556,
  31643. 'eight': 556,
  31644. 'nine': 556,
  31645. 'colon': 278,
  31646. 'semicolon': 278,
  31647. 'less': 584,
  31648. 'equal': 584,
  31649. 'greater': 584,
  31650. 'question': 556,
  31651. 'at': 1015,
  31652. 'A': 667,
  31653. 'B': 667,
  31654. 'C': 722,
  31655. 'D': 722,
  31656. 'E': 667,
  31657. 'F': 611,
  31658. 'G': 778,
  31659. 'H': 722,
  31660. 'I': 278,
  31661. 'J': 500,
  31662. 'K': 667,
  31663. 'L': 556,
  31664. 'M': 833,
  31665. 'N': 722,
  31666. 'O': 778,
  31667. 'P': 667,
  31668. 'Q': 778,
  31669. 'R': 722,
  31670. 'S': 667,
  31671. 'T': 611,
  31672. 'U': 722,
  31673. 'V': 667,
  31674. 'W': 944,
  31675. 'X': 667,
  31676. 'Y': 667,
  31677. 'Z': 611,
  31678. 'bracketleft': 278,
  31679. 'backslash': 278,
  31680. 'bracketright': 278,
  31681. 'asciicircum': 469,
  31682. 'underscore': 556,
  31683. 'quoteleft': 222,
  31684. 'a': 556,
  31685. 'b': 556,
  31686. 'c': 500,
  31687. 'd': 556,
  31688. 'e': 556,
  31689. 'f': 278,
  31690. 'g': 556,
  31691. 'h': 556,
  31692. 'i': 222,
  31693. 'j': 222,
  31694. 'k': 500,
  31695. 'l': 222,
  31696. 'm': 833,
  31697. 'n': 556,
  31698. 'o': 556,
  31699. 'p': 556,
  31700. 'q': 556,
  31701. 'r': 333,
  31702. 's': 500,
  31703. 't': 278,
  31704. 'u': 556,
  31705. 'v': 500,
  31706. 'w': 722,
  31707. 'x': 500,
  31708. 'y': 500,
  31709. 'z': 500,
  31710. 'braceleft': 334,
  31711. 'bar': 260,
  31712. 'braceright': 334,
  31713. 'asciitilde': 584,
  31714. 'exclamdown': 333,
  31715. 'cent': 556,
  31716. 'sterling': 556,
  31717. 'fraction': 167,
  31718. 'yen': 556,
  31719. 'florin': 556,
  31720. 'section': 556,
  31721. 'currency': 556,
  31722. 'quotesingle': 191,
  31723. 'quotedblleft': 333,
  31724. 'guillemotleft': 556,
  31725. 'guilsinglleft': 333,
  31726. 'guilsinglright': 333,
  31727. 'fi': 500,
  31728. 'fl': 500,
  31729. 'endash': 556,
  31730. 'dagger': 556,
  31731. 'daggerdbl': 556,
  31732. 'periodcentered': 278,
  31733. 'paragraph': 537,
  31734. 'bullet': 350,
  31735. 'quotesinglbase': 222,
  31736. 'quotedblbase': 333,
  31737. 'quotedblright': 333,
  31738. 'guillemotright': 556,
  31739. 'ellipsis': 1000,
  31740. 'perthousand': 1000,
  31741. 'questiondown': 611,
  31742. 'grave': 333,
  31743. 'acute': 333,
  31744. 'circumflex': 333,
  31745. 'tilde': 333,
  31746. 'macron': 333,
  31747. 'breve': 333,
  31748. 'dotaccent': 333,
  31749. 'dieresis': 333,
  31750. 'ring': 333,
  31751. 'cedilla': 333,
  31752. 'hungarumlaut': 333,
  31753. 'ogonek': 333,
  31754. 'caron': 333,
  31755. 'emdash': 1000,
  31756. 'AE': 1000,
  31757. 'ordfeminine': 370,
  31758. 'Lslash': 556,
  31759. 'Oslash': 778,
  31760. 'OE': 1000,
  31761. 'ordmasculine': 365,
  31762. 'ae': 889,
  31763. 'dotlessi': 278,
  31764. 'lslash': 222,
  31765. 'oslash': 611,
  31766. 'oe': 944,
  31767. 'germandbls': 611,
  31768. 'Idieresis': 278,
  31769. 'eacute': 556,
  31770. 'abreve': 556,
  31771. 'uhungarumlaut': 556,
  31772. 'ecaron': 556,
  31773. 'Ydieresis': 667,
  31774. 'divide': 584,
  31775. 'Yacute': 667,
  31776. 'Acircumflex': 667,
  31777. 'aacute': 556,
  31778. 'Ucircumflex': 722,
  31779. 'yacute': 500,
  31780. 'scommaaccent': 500,
  31781. 'ecircumflex': 556,
  31782. 'Uring': 722,
  31783. 'Udieresis': 722,
  31784. 'aogonek': 556,
  31785. 'Uacute': 722,
  31786. 'uogonek': 556,
  31787. 'Edieresis': 667,
  31788. 'Dcroat': 722,
  31789. 'commaaccent': 250,
  31790. 'copyright': 737,
  31791. 'Emacron': 667,
  31792. 'ccaron': 500,
  31793. 'aring': 556,
  31794. 'Ncommaaccent': 722,
  31795. 'lacute': 222,
  31796. 'agrave': 556,
  31797. 'Tcommaaccent': 611,
  31798. 'Cacute': 722,
  31799. 'atilde': 556,
  31800. 'Edotaccent': 667,
  31801. 'scaron': 500,
  31802. 'scedilla': 500,
  31803. 'iacute': 278,
  31804. 'lozenge': 471,
  31805. 'Rcaron': 722,
  31806. 'Gcommaaccent': 778,
  31807. 'ucircumflex': 556,
  31808. 'acircumflex': 556,
  31809. 'Amacron': 667,
  31810. 'rcaron': 333,
  31811. 'ccedilla': 500,
  31812. 'Zdotaccent': 611,
  31813. 'Thorn': 667,
  31814. 'Omacron': 778,
  31815. 'Racute': 722,
  31816. 'Sacute': 667,
  31817. 'dcaron': 643,
  31818. 'Umacron': 722,
  31819. 'uring': 556,
  31820. 'threesuperior': 333,
  31821. 'Ograve': 778,
  31822. 'Agrave': 667,
  31823. 'Abreve': 667,
  31824. 'multiply': 584,
  31825. 'uacute': 556,
  31826. 'Tcaron': 611,
  31827. 'partialdiff': 476,
  31828. 'ydieresis': 500,
  31829. 'Nacute': 722,
  31830. 'icircumflex': 278,
  31831. 'Ecircumflex': 667,
  31832. 'adieresis': 556,
  31833. 'edieresis': 556,
  31834. 'cacute': 500,
  31835. 'nacute': 556,
  31836. 'umacron': 556,
  31837. 'Ncaron': 722,
  31838. 'Iacute': 278,
  31839. 'plusminus': 584,
  31840. 'brokenbar': 260,
  31841. 'registered': 737,
  31842. 'Gbreve': 778,
  31843. 'Idotaccent': 278,
  31844. 'summation': 600,
  31845. 'Egrave': 667,
  31846. 'racute': 333,
  31847. 'omacron': 556,
  31848. 'Zacute': 611,
  31849. 'Zcaron': 611,
  31850. 'greaterequal': 549,
  31851. 'Eth': 722,
  31852. 'Ccedilla': 722,
  31853. 'lcommaaccent': 222,
  31854. 'tcaron': 317,
  31855. 'eogonek': 556,
  31856. 'Uogonek': 722,
  31857. 'Aacute': 667,
  31858. 'Adieresis': 667,
  31859. 'egrave': 556,
  31860. 'zacute': 500,
  31861. 'iogonek': 222,
  31862. 'Oacute': 778,
  31863. 'oacute': 556,
  31864. 'amacron': 556,
  31865. 'sacute': 500,
  31866. 'idieresis': 278,
  31867. 'Ocircumflex': 778,
  31868. 'Ugrave': 722,
  31869. 'Delta': 612,
  31870. 'thorn': 556,
  31871. 'twosuperior': 333,
  31872. 'Odieresis': 778,
  31873. 'mu': 556,
  31874. 'igrave': 278,
  31875. 'ohungarumlaut': 556,
  31876. 'Eogonek': 667,
  31877. 'dcroat': 556,
  31878. 'threequarters': 834,
  31879. 'Scedilla': 667,
  31880. 'lcaron': 299,
  31881. 'Kcommaaccent': 667,
  31882. 'Lacute': 556,
  31883. 'trademark': 1000,
  31884. 'edotaccent': 556,
  31885. 'Igrave': 278,
  31886. 'Imacron': 278,
  31887. 'Lcaron': 556,
  31888. 'onehalf': 834,
  31889. 'lessequal': 549,
  31890. 'ocircumflex': 556,
  31891. 'ntilde': 556,
  31892. 'Uhungarumlaut': 722,
  31893. 'Eacute': 667,
  31894. 'emacron': 556,
  31895. 'gbreve': 556,
  31896. 'onequarter': 834,
  31897. 'Scaron': 667,
  31898. 'Scommaaccent': 667,
  31899. 'Ohungarumlaut': 778,
  31900. 'degree': 400,
  31901. 'ograve': 556,
  31902. 'Ccaron': 722,
  31903. 'ugrave': 556,
  31904. 'radical': 453,
  31905. 'Dcaron': 722,
  31906. 'rcommaaccent': 333,
  31907. 'Ntilde': 722,
  31908. 'otilde': 556,
  31909. 'Rcommaaccent': 722,
  31910. 'Lcommaaccent': 556,
  31911. 'Atilde': 667,
  31912. 'Aogonek': 667,
  31913. 'Aring': 667,
  31914. 'Otilde': 778,
  31915. 'zdotaccent': 500,
  31916. 'Ecaron': 667,
  31917. 'Iogonek': 278,
  31918. 'kcommaaccent': 500,
  31919. 'minus': 584,
  31920. 'Icircumflex': 278,
  31921. 'ncaron': 556,
  31922. 'tcommaaccent': 278,
  31923. 'logicalnot': 584,
  31924. 'odieresis': 556,
  31925. 'udieresis': 556,
  31926. 'notequal': 549,
  31927. 'gcommaaccent': 556,
  31928. 'eth': 556,
  31929. 'zcaron': 500,
  31930. 'ncommaaccent': 556,
  31931. 'onesuperior': 333,
  31932. 'imacron': 278,
  31933. 'Euro': 556
  31934. },
  31935. 'Symbol': {
  31936. 'space': 250,
  31937. 'exclam': 333,
  31938. 'universal': 713,
  31939. 'numbersign': 500,
  31940. 'existential': 549,
  31941. 'percent': 833,
  31942. 'ampersand': 778,
  31943. 'suchthat': 439,
  31944. 'parenleft': 333,
  31945. 'parenright': 333,
  31946. 'asteriskmath': 500,
  31947. 'plus': 549,
  31948. 'comma': 250,
  31949. 'minus': 549,
  31950. 'period': 250,
  31951. 'slash': 278,
  31952. 'zero': 500,
  31953. 'one': 500,
  31954. 'two': 500,
  31955. 'three': 500,
  31956. 'four': 500,
  31957. 'five': 500,
  31958. 'six': 500,
  31959. 'seven': 500,
  31960. 'eight': 500,
  31961. 'nine': 500,
  31962. 'colon': 278,
  31963. 'semicolon': 278,
  31964. 'less': 549,
  31965. 'equal': 549,
  31966. 'greater': 549,
  31967. 'question': 444,
  31968. 'congruent': 549,
  31969. 'Alpha': 722,
  31970. 'Beta': 667,
  31971. 'Chi': 722,
  31972. 'Delta': 612,
  31973. 'Epsilon': 611,
  31974. 'Phi': 763,
  31975. 'Gamma': 603,
  31976. 'Eta': 722,
  31977. 'Iota': 333,
  31978. 'theta1': 631,
  31979. 'Kappa': 722,
  31980. 'Lambda': 686,
  31981. 'Mu': 889,
  31982. 'Nu': 722,
  31983. 'Omicron': 722,
  31984. 'Pi': 768,
  31985. 'Theta': 741,
  31986. 'Rho': 556,
  31987. 'Sigma': 592,
  31988. 'Tau': 611,
  31989. 'Upsilon': 690,
  31990. 'sigma1': 439,
  31991. 'Omega': 768,
  31992. 'Xi': 645,
  31993. 'Psi': 795,
  31994. 'Zeta': 611,
  31995. 'bracketleft': 333,
  31996. 'therefore': 863,
  31997. 'bracketright': 333,
  31998. 'perpendicular': 658,
  31999. 'underscore': 500,
  32000. 'radicalex': 500,
  32001. 'alpha': 631,
  32002. 'beta': 549,
  32003. 'chi': 549,
  32004. 'delta': 494,
  32005. 'epsilon': 439,
  32006. 'phi': 521,
  32007. 'gamma': 411,
  32008. 'eta': 603,
  32009. 'iota': 329,
  32010. 'phi1': 603,
  32011. 'kappa': 549,
  32012. 'lambda': 549,
  32013. 'mu': 576,
  32014. 'nu': 521,
  32015. 'omicron': 549,
  32016. 'pi': 549,
  32017. 'theta': 521,
  32018. 'rho': 549,
  32019. 'sigma': 603,
  32020. 'tau': 439,
  32021. 'upsilon': 576,
  32022. 'omega1': 713,
  32023. 'omega': 686,
  32024. 'xi': 493,
  32025. 'psi': 686,
  32026. 'zeta': 494,
  32027. 'braceleft': 480,
  32028. 'bar': 200,
  32029. 'braceright': 480,
  32030. 'similar': 549,
  32031. 'Euro': 750,
  32032. 'Upsilon1': 620,
  32033. 'minute': 247,
  32034. 'lessequal': 549,
  32035. 'fraction': 167,
  32036. 'infinity': 713,
  32037. 'florin': 500,
  32038. 'club': 753,
  32039. 'diamond': 753,
  32040. 'heart': 753,
  32041. 'spade': 753,
  32042. 'arrowboth': 1042,
  32043. 'arrowleft': 987,
  32044. 'arrowup': 603,
  32045. 'arrowright': 987,
  32046. 'arrowdown': 603,
  32047. 'degree': 400,
  32048. 'plusminus': 549,
  32049. 'second': 411,
  32050. 'greaterequal': 549,
  32051. 'multiply': 549,
  32052. 'proportional': 713,
  32053. 'partialdiff': 494,
  32054. 'bullet': 460,
  32055. 'divide': 549,
  32056. 'notequal': 549,
  32057. 'equivalence': 549,
  32058. 'approxequal': 549,
  32059. 'ellipsis': 1000,
  32060. 'arrowvertex': 603,
  32061. 'arrowhorizex': 1000,
  32062. 'carriagereturn': 658,
  32063. 'aleph': 823,
  32064. 'Ifraktur': 686,
  32065. 'Rfraktur': 795,
  32066. 'weierstrass': 987,
  32067. 'circlemultiply': 768,
  32068. 'circleplus': 768,
  32069. 'emptyset': 823,
  32070. 'intersection': 768,
  32071. 'union': 768,
  32072. 'propersuperset': 713,
  32073. 'reflexsuperset': 713,
  32074. 'notsubset': 713,
  32075. 'propersubset': 713,
  32076. 'reflexsubset': 713,
  32077. 'element': 713,
  32078. 'notelement': 713,
  32079. 'angle': 768,
  32080. 'gradient': 713,
  32081. 'registerserif': 790,
  32082. 'copyrightserif': 790,
  32083. 'trademarkserif': 890,
  32084. 'product': 823,
  32085. 'radical': 549,
  32086. 'dotmath': 250,
  32087. 'logicalnot': 713,
  32088. 'logicaland': 603,
  32089. 'logicalor': 603,
  32090. 'arrowdblboth': 1042,
  32091. 'arrowdblleft': 987,
  32092. 'arrowdblup': 603,
  32093. 'arrowdblright': 987,
  32094. 'arrowdbldown': 603,
  32095. 'lozenge': 494,
  32096. 'angleleft': 329,
  32097. 'registersans': 790,
  32098. 'copyrightsans': 790,
  32099. 'trademarksans': 786,
  32100. 'summation': 713,
  32101. 'parenlefttp': 384,
  32102. 'parenleftex': 384,
  32103. 'parenleftbt': 384,
  32104. 'bracketlefttp': 384,
  32105. 'bracketleftex': 384,
  32106. 'bracketleftbt': 384,
  32107. 'bracelefttp': 494,
  32108. 'braceleftmid': 494,
  32109. 'braceleftbt': 494,
  32110. 'braceex': 494,
  32111. 'angleright': 329,
  32112. 'integral': 274,
  32113. 'integraltp': 686,
  32114. 'integralex': 686,
  32115. 'integralbt': 686,
  32116. 'parenrighttp': 384,
  32117. 'parenrightex': 384,
  32118. 'parenrightbt': 384,
  32119. 'bracketrighttp': 384,
  32120. 'bracketrightex': 384,
  32121. 'bracketrightbt': 384,
  32122. 'bracerighttp': 494,
  32123. 'bracerightmid': 494,
  32124. 'bracerightbt': 494,
  32125. 'apple': 790
  32126. },
  32127. 'Times-Roman': {
  32128. 'space': 250,
  32129. 'exclam': 333,
  32130. 'quotedbl': 408,
  32131. 'numbersign': 500,
  32132. 'dollar': 500,
  32133. 'percent': 833,
  32134. 'ampersand': 778,
  32135. 'quoteright': 333,
  32136. 'parenleft': 333,
  32137. 'parenright': 333,
  32138. 'asterisk': 500,
  32139. 'plus': 564,
  32140. 'comma': 250,
  32141. 'hyphen': 333,
  32142. 'period': 250,
  32143. 'slash': 278,
  32144. 'zero': 500,
  32145. 'one': 500,
  32146. 'two': 500,
  32147. 'three': 500,
  32148. 'four': 500,
  32149. 'five': 500,
  32150. 'six': 500,
  32151. 'seven': 500,
  32152. 'eight': 500,
  32153. 'nine': 500,
  32154. 'colon': 278,
  32155. 'semicolon': 278,
  32156. 'less': 564,
  32157. 'equal': 564,
  32158. 'greater': 564,
  32159. 'question': 444,
  32160. 'at': 921,
  32161. 'A': 722,
  32162. 'B': 667,
  32163. 'C': 667,
  32164. 'D': 722,
  32165. 'E': 611,
  32166. 'F': 556,
  32167. 'G': 722,
  32168. 'H': 722,
  32169. 'I': 333,
  32170. 'J': 389,
  32171. 'K': 722,
  32172. 'L': 611,
  32173. 'M': 889,
  32174. 'N': 722,
  32175. 'O': 722,
  32176. 'P': 556,
  32177. 'Q': 722,
  32178. 'R': 667,
  32179. 'S': 556,
  32180. 'T': 611,
  32181. 'U': 722,
  32182. 'V': 722,
  32183. 'W': 944,
  32184. 'X': 722,
  32185. 'Y': 722,
  32186. 'Z': 611,
  32187. 'bracketleft': 333,
  32188. 'backslash': 278,
  32189. 'bracketright': 333,
  32190. 'asciicircum': 469,
  32191. 'underscore': 500,
  32192. 'quoteleft': 333,
  32193. 'a': 444,
  32194. 'b': 500,
  32195. 'c': 444,
  32196. 'd': 500,
  32197. 'e': 444,
  32198. 'f': 333,
  32199. 'g': 500,
  32200. 'h': 500,
  32201. 'i': 278,
  32202. 'j': 278,
  32203. 'k': 500,
  32204. 'l': 278,
  32205. 'm': 778,
  32206. 'n': 500,
  32207. 'o': 500,
  32208. 'p': 500,
  32209. 'q': 500,
  32210. 'r': 333,
  32211. 's': 389,
  32212. 't': 278,
  32213. 'u': 500,
  32214. 'v': 500,
  32215. 'w': 722,
  32216. 'x': 500,
  32217. 'y': 500,
  32218. 'z': 444,
  32219. 'braceleft': 480,
  32220. 'bar': 200,
  32221. 'braceright': 480,
  32222. 'asciitilde': 541,
  32223. 'exclamdown': 333,
  32224. 'cent': 500,
  32225. 'sterling': 500,
  32226. 'fraction': 167,
  32227. 'yen': 500,
  32228. 'florin': 500,
  32229. 'section': 500,
  32230. 'currency': 500,
  32231. 'quotesingle': 180,
  32232. 'quotedblleft': 444,
  32233. 'guillemotleft': 500,
  32234. 'guilsinglleft': 333,
  32235. 'guilsinglright': 333,
  32236. 'fi': 556,
  32237. 'fl': 556,
  32238. 'endash': 500,
  32239. 'dagger': 500,
  32240. 'daggerdbl': 500,
  32241. 'periodcentered': 250,
  32242. 'paragraph': 453,
  32243. 'bullet': 350,
  32244. 'quotesinglbase': 333,
  32245. 'quotedblbase': 444,
  32246. 'quotedblright': 444,
  32247. 'guillemotright': 500,
  32248. 'ellipsis': 1000,
  32249. 'perthousand': 1000,
  32250. 'questiondown': 444,
  32251. 'grave': 333,
  32252. 'acute': 333,
  32253. 'circumflex': 333,
  32254. 'tilde': 333,
  32255. 'macron': 333,
  32256. 'breve': 333,
  32257. 'dotaccent': 333,
  32258. 'dieresis': 333,
  32259. 'ring': 333,
  32260. 'cedilla': 333,
  32261. 'hungarumlaut': 333,
  32262. 'ogonek': 333,
  32263. 'caron': 333,
  32264. 'emdash': 1000,
  32265. 'AE': 889,
  32266. 'ordfeminine': 276,
  32267. 'Lslash': 611,
  32268. 'Oslash': 722,
  32269. 'OE': 889,
  32270. 'ordmasculine': 310,
  32271. 'ae': 667,
  32272. 'dotlessi': 278,
  32273. 'lslash': 278,
  32274. 'oslash': 500,
  32275. 'oe': 722,
  32276. 'germandbls': 500,
  32277. 'Idieresis': 333,
  32278. 'eacute': 444,
  32279. 'abreve': 444,
  32280. 'uhungarumlaut': 500,
  32281. 'ecaron': 444,
  32282. 'Ydieresis': 722,
  32283. 'divide': 564,
  32284. 'Yacute': 722,
  32285. 'Acircumflex': 722,
  32286. 'aacute': 444,
  32287. 'Ucircumflex': 722,
  32288. 'yacute': 500,
  32289. 'scommaaccent': 389,
  32290. 'ecircumflex': 444,
  32291. 'Uring': 722,
  32292. 'Udieresis': 722,
  32293. 'aogonek': 444,
  32294. 'Uacute': 722,
  32295. 'uogonek': 500,
  32296. 'Edieresis': 611,
  32297. 'Dcroat': 722,
  32298. 'commaaccent': 250,
  32299. 'copyright': 760,
  32300. 'Emacron': 611,
  32301. 'ccaron': 444,
  32302. 'aring': 444,
  32303. 'Ncommaaccent': 722,
  32304. 'lacute': 278,
  32305. 'agrave': 444,
  32306. 'Tcommaaccent': 611,
  32307. 'Cacute': 667,
  32308. 'atilde': 444,
  32309. 'Edotaccent': 611,
  32310. 'scaron': 389,
  32311. 'scedilla': 389,
  32312. 'iacute': 278,
  32313. 'lozenge': 471,
  32314. 'Rcaron': 667,
  32315. 'Gcommaaccent': 722,
  32316. 'ucircumflex': 500,
  32317. 'acircumflex': 444,
  32318. 'Amacron': 722,
  32319. 'rcaron': 333,
  32320. 'ccedilla': 444,
  32321. 'Zdotaccent': 611,
  32322. 'Thorn': 556,
  32323. 'Omacron': 722,
  32324. 'Racute': 667,
  32325. 'Sacute': 556,
  32326. 'dcaron': 588,
  32327. 'Umacron': 722,
  32328. 'uring': 500,
  32329. 'threesuperior': 300,
  32330. 'Ograve': 722,
  32331. 'Agrave': 722,
  32332. 'Abreve': 722,
  32333. 'multiply': 564,
  32334. 'uacute': 500,
  32335. 'Tcaron': 611,
  32336. 'partialdiff': 476,
  32337. 'ydieresis': 500,
  32338. 'Nacute': 722,
  32339. 'icircumflex': 278,
  32340. 'Ecircumflex': 611,
  32341. 'adieresis': 444,
  32342. 'edieresis': 444,
  32343. 'cacute': 444,
  32344. 'nacute': 500,
  32345. 'umacron': 500,
  32346. 'Ncaron': 722,
  32347. 'Iacute': 333,
  32348. 'plusminus': 564,
  32349. 'brokenbar': 200,
  32350. 'registered': 760,
  32351. 'Gbreve': 722,
  32352. 'Idotaccent': 333,
  32353. 'summation': 600,
  32354. 'Egrave': 611,
  32355. 'racute': 333,
  32356. 'omacron': 500,
  32357. 'Zacute': 611,
  32358. 'Zcaron': 611,
  32359. 'greaterequal': 549,
  32360. 'Eth': 722,
  32361. 'Ccedilla': 667,
  32362. 'lcommaaccent': 278,
  32363. 'tcaron': 326,
  32364. 'eogonek': 444,
  32365. 'Uogonek': 722,
  32366. 'Aacute': 722,
  32367. 'Adieresis': 722,
  32368. 'egrave': 444,
  32369. 'zacute': 444,
  32370. 'iogonek': 278,
  32371. 'Oacute': 722,
  32372. 'oacute': 500,
  32373. 'amacron': 444,
  32374. 'sacute': 389,
  32375. 'idieresis': 278,
  32376. 'Ocircumflex': 722,
  32377. 'Ugrave': 722,
  32378. 'Delta': 612,
  32379. 'thorn': 500,
  32380. 'twosuperior': 300,
  32381. 'Odieresis': 722,
  32382. 'mu': 500,
  32383. 'igrave': 278,
  32384. 'ohungarumlaut': 500,
  32385. 'Eogonek': 611,
  32386. 'dcroat': 500,
  32387. 'threequarters': 750,
  32388. 'Scedilla': 556,
  32389. 'lcaron': 344,
  32390. 'Kcommaaccent': 722,
  32391. 'Lacute': 611,
  32392. 'trademark': 980,
  32393. 'edotaccent': 444,
  32394. 'Igrave': 333,
  32395. 'Imacron': 333,
  32396. 'Lcaron': 611,
  32397. 'onehalf': 750,
  32398. 'lessequal': 549,
  32399. 'ocircumflex': 500,
  32400. 'ntilde': 500,
  32401. 'Uhungarumlaut': 722,
  32402. 'Eacute': 611,
  32403. 'emacron': 444,
  32404. 'gbreve': 500,
  32405. 'onequarter': 750,
  32406. 'Scaron': 556,
  32407. 'Scommaaccent': 556,
  32408. 'Ohungarumlaut': 722,
  32409. 'degree': 400,
  32410. 'ograve': 500,
  32411. 'Ccaron': 667,
  32412. 'ugrave': 500,
  32413. 'radical': 453,
  32414. 'Dcaron': 722,
  32415. 'rcommaaccent': 333,
  32416. 'Ntilde': 722,
  32417. 'otilde': 500,
  32418. 'Rcommaaccent': 667,
  32419. 'Lcommaaccent': 611,
  32420. 'Atilde': 722,
  32421. 'Aogonek': 722,
  32422. 'Aring': 722,
  32423. 'Otilde': 722,
  32424. 'zdotaccent': 444,
  32425. 'Ecaron': 611,
  32426. 'Iogonek': 333,
  32427. 'kcommaaccent': 500,
  32428. 'minus': 564,
  32429. 'Icircumflex': 333,
  32430. 'ncaron': 500,
  32431. 'tcommaaccent': 278,
  32432. 'logicalnot': 564,
  32433. 'odieresis': 500,
  32434. 'udieresis': 500,
  32435. 'notequal': 549,
  32436. 'gcommaaccent': 500,
  32437. 'eth': 500,
  32438. 'zcaron': 444,
  32439. 'ncommaaccent': 500,
  32440. 'onesuperior': 300,
  32441. 'imacron': 278,
  32442. 'Euro': 500
  32443. },
  32444. 'Times-Bold': {
  32445. 'space': 250,
  32446. 'exclam': 333,
  32447. 'quotedbl': 555,
  32448. 'numbersign': 500,
  32449. 'dollar': 500,
  32450. 'percent': 1000,
  32451. 'ampersand': 833,
  32452. 'quoteright': 333,
  32453. 'parenleft': 333,
  32454. 'parenright': 333,
  32455. 'asterisk': 500,
  32456. 'plus': 570,
  32457. 'comma': 250,
  32458. 'hyphen': 333,
  32459. 'period': 250,
  32460. 'slash': 278,
  32461. 'zero': 500,
  32462. 'one': 500,
  32463. 'two': 500,
  32464. 'three': 500,
  32465. 'four': 500,
  32466. 'five': 500,
  32467. 'six': 500,
  32468. 'seven': 500,
  32469. 'eight': 500,
  32470. 'nine': 500,
  32471. 'colon': 333,
  32472. 'semicolon': 333,
  32473. 'less': 570,
  32474. 'equal': 570,
  32475. 'greater': 570,
  32476. 'question': 500,
  32477. 'at': 930,
  32478. 'A': 722,
  32479. 'B': 667,
  32480. 'C': 722,
  32481. 'D': 722,
  32482. 'E': 667,
  32483. 'F': 611,
  32484. 'G': 778,
  32485. 'H': 778,
  32486. 'I': 389,
  32487. 'J': 500,
  32488. 'K': 778,
  32489. 'L': 667,
  32490. 'M': 944,
  32491. 'N': 722,
  32492. 'O': 778,
  32493. 'P': 611,
  32494. 'Q': 778,
  32495. 'R': 722,
  32496. 'S': 556,
  32497. 'T': 667,
  32498. 'U': 722,
  32499. 'V': 722,
  32500. 'W': 1000,
  32501. 'X': 722,
  32502. 'Y': 722,
  32503. 'Z': 667,
  32504. 'bracketleft': 333,
  32505. 'backslash': 278,
  32506. 'bracketright': 333,
  32507. 'asciicircum': 581,
  32508. 'underscore': 500,
  32509. 'quoteleft': 333,
  32510. 'a': 500,
  32511. 'b': 556,
  32512. 'c': 444,
  32513. 'd': 556,
  32514. 'e': 444,
  32515. 'f': 333,
  32516. 'g': 500,
  32517. 'h': 556,
  32518. 'i': 278,
  32519. 'j': 333,
  32520. 'k': 556,
  32521. 'l': 278,
  32522. 'm': 833,
  32523. 'n': 556,
  32524. 'o': 500,
  32525. 'p': 556,
  32526. 'q': 556,
  32527. 'r': 444,
  32528. 's': 389,
  32529. 't': 333,
  32530. 'u': 556,
  32531. 'v': 500,
  32532. 'w': 722,
  32533. 'x': 500,
  32534. 'y': 500,
  32535. 'z': 444,
  32536. 'braceleft': 394,
  32537. 'bar': 220,
  32538. 'braceright': 394,
  32539. 'asciitilde': 520,
  32540. 'exclamdown': 333,
  32541. 'cent': 500,
  32542. 'sterling': 500,
  32543. 'fraction': 167,
  32544. 'yen': 500,
  32545. 'florin': 500,
  32546. 'section': 500,
  32547. 'currency': 500,
  32548. 'quotesingle': 278,
  32549. 'quotedblleft': 500,
  32550. 'guillemotleft': 500,
  32551. 'guilsinglleft': 333,
  32552. 'guilsinglright': 333,
  32553. 'fi': 556,
  32554. 'fl': 556,
  32555. 'endash': 500,
  32556. 'dagger': 500,
  32557. 'daggerdbl': 500,
  32558. 'periodcentered': 250,
  32559. 'paragraph': 540,
  32560. 'bullet': 350,
  32561. 'quotesinglbase': 333,
  32562. 'quotedblbase': 500,
  32563. 'quotedblright': 500,
  32564. 'guillemotright': 500,
  32565. 'ellipsis': 1000,
  32566. 'perthousand': 1000,
  32567. 'questiondown': 500,
  32568. 'grave': 333,
  32569. 'acute': 333,
  32570. 'circumflex': 333,
  32571. 'tilde': 333,
  32572. 'macron': 333,
  32573. 'breve': 333,
  32574. 'dotaccent': 333,
  32575. 'dieresis': 333,
  32576. 'ring': 333,
  32577. 'cedilla': 333,
  32578. 'hungarumlaut': 333,
  32579. 'ogonek': 333,
  32580. 'caron': 333,
  32581. 'emdash': 1000,
  32582. 'AE': 1000,
  32583. 'ordfeminine': 300,
  32584. 'Lslash': 667,
  32585. 'Oslash': 778,
  32586. 'OE': 1000,
  32587. 'ordmasculine': 330,
  32588. 'ae': 722,
  32589. 'dotlessi': 278,
  32590. 'lslash': 278,
  32591. 'oslash': 500,
  32592. 'oe': 722,
  32593. 'germandbls': 556,
  32594. 'Idieresis': 389,
  32595. 'eacute': 444,
  32596. 'abreve': 500,
  32597. 'uhungarumlaut': 556,
  32598. 'ecaron': 444,
  32599. 'Ydieresis': 722,
  32600. 'divide': 570,
  32601. 'Yacute': 722,
  32602. 'Acircumflex': 722,
  32603. 'aacute': 500,
  32604. 'Ucircumflex': 722,
  32605. 'yacute': 500,
  32606. 'scommaaccent': 389,
  32607. 'ecircumflex': 444,
  32608. 'Uring': 722,
  32609. 'Udieresis': 722,
  32610. 'aogonek': 500,
  32611. 'Uacute': 722,
  32612. 'uogonek': 556,
  32613. 'Edieresis': 667,
  32614. 'Dcroat': 722,
  32615. 'commaaccent': 250,
  32616. 'copyright': 747,
  32617. 'Emacron': 667,
  32618. 'ccaron': 444,
  32619. 'aring': 500,
  32620. 'Ncommaaccent': 722,
  32621. 'lacute': 278,
  32622. 'agrave': 500,
  32623. 'Tcommaaccent': 667,
  32624. 'Cacute': 722,
  32625. 'atilde': 500,
  32626. 'Edotaccent': 667,
  32627. 'scaron': 389,
  32628. 'scedilla': 389,
  32629. 'iacute': 278,
  32630. 'lozenge': 494,
  32631. 'Rcaron': 722,
  32632. 'Gcommaaccent': 778,
  32633. 'ucircumflex': 556,
  32634. 'acircumflex': 500,
  32635. 'Amacron': 722,
  32636. 'rcaron': 444,
  32637. 'ccedilla': 444,
  32638. 'Zdotaccent': 667,
  32639. 'Thorn': 611,
  32640. 'Omacron': 778,
  32641. 'Racute': 722,
  32642. 'Sacute': 556,
  32643. 'dcaron': 672,
  32644. 'Umacron': 722,
  32645. 'uring': 556,
  32646. 'threesuperior': 300,
  32647. 'Ograve': 778,
  32648. 'Agrave': 722,
  32649. 'Abreve': 722,
  32650. 'multiply': 570,
  32651. 'uacute': 556,
  32652. 'Tcaron': 667,
  32653. 'partialdiff': 494,
  32654. 'ydieresis': 500,
  32655. 'Nacute': 722,
  32656. 'icircumflex': 278,
  32657. 'Ecircumflex': 667,
  32658. 'adieresis': 500,
  32659. 'edieresis': 444,
  32660. 'cacute': 444,
  32661. 'nacute': 556,
  32662. 'umacron': 556,
  32663. 'Ncaron': 722,
  32664. 'Iacute': 389,
  32665. 'plusminus': 570,
  32666. 'brokenbar': 220,
  32667. 'registered': 747,
  32668. 'Gbreve': 778,
  32669. 'Idotaccent': 389,
  32670. 'summation': 600,
  32671. 'Egrave': 667,
  32672. 'racute': 444,
  32673. 'omacron': 500,
  32674. 'Zacute': 667,
  32675. 'Zcaron': 667,
  32676. 'greaterequal': 549,
  32677. 'Eth': 722,
  32678. 'Ccedilla': 722,
  32679. 'lcommaaccent': 278,
  32680. 'tcaron': 416,
  32681. 'eogonek': 444,
  32682. 'Uogonek': 722,
  32683. 'Aacute': 722,
  32684. 'Adieresis': 722,
  32685. 'egrave': 444,
  32686. 'zacute': 444,
  32687. 'iogonek': 278,
  32688. 'Oacute': 778,
  32689. 'oacute': 500,
  32690. 'amacron': 500,
  32691. 'sacute': 389,
  32692. 'idieresis': 278,
  32693. 'Ocircumflex': 778,
  32694. 'Ugrave': 722,
  32695. 'Delta': 612,
  32696. 'thorn': 556,
  32697. 'twosuperior': 300,
  32698. 'Odieresis': 778,
  32699. 'mu': 556,
  32700. 'igrave': 278,
  32701. 'ohungarumlaut': 500,
  32702. 'Eogonek': 667,
  32703. 'dcroat': 556,
  32704. 'threequarters': 750,
  32705. 'Scedilla': 556,
  32706. 'lcaron': 394,
  32707. 'Kcommaaccent': 778,
  32708. 'Lacute': 667,
  32709. 'trademark': 1000,
  32710. 'edotaccent': 444,
  32711. 'Igrave': 389,
  32712. 'Imacron': 389,
  32713. 'Lcaron': 667,
  32714. 'onehalf': 750,
  32715. 'lessequal': 549,
  32716. 'ocircumflex': 500,
  32717. 'ntilde': 556,
  32718. 'Uhungarumlaut': 722,
  32719. 'Eacute': 667,
  32720. 'emacron': 444,
  32721. 'gbreve': 500,
  32722. 'onequarter': 750,
  32723. 'Scaron': 556,
  32724. 'Scommaaccent': 556,
  32725. 'Ohungarumlaut': 778,
  32726. 'degree': 400,
  32727. 'ograve': 500,
  32728. 'Ccaron': 722,
  32729. 'ugrave': 556,
  32730. 'radical': 549,
  32731. 'Dcaron': 722,
  32732. 'rcommaaccent': 444,
  32733. 'Ntilde': 722,
  32734. 'otilde': 500,
  32735. 'Rcommaaccent': 722,
  32736. 'Lcommaaccent': 667,
  32737. 'Atilde': 722,
  32738. 'Aogonek': 722,
  32739. 'Aring': 722,
  32740. 'Otilde': 778,
  32741. 'zdotaccent': 444,
  32742. 'Ecaron': 667,
  32743. 'Iogonek': 389,
  32744. 'kcommaaccent': 556,
  32745. 'minus': 570,
  32746. 'Icircumflex': 389,
  32747. 'ncaron': 556,
  32748. 'tcommaaccent': 333,
  32749. 'logicalnot': 570,
  32750. 'odieresis': 500,
  32751. 'udieresis': 556,
  32752. 'notequal': 549,
  32753. 'gcommaaccent': 500,
  32754. 'eth': 500,
  32755. 'zcaron': 444,
  32756. 'ncommaaccent': 556,
  32757. 'onesuperior': 300,
  32758. 'imacron': 278,
  32759. 'Euro': 500
  32760. },
  32761. 'Times-BoldItalic': {
  32762. 'space': 250,
  32763. 'exclam': 389,
  32764. 'quotedbl': 555,
  32765. 'numbersign': 500,
  32766. 'dollar': 500,
  32767. 'percent': 833,
  32768. 'ampersand': 778,
  32769. 'quoteright': 333,
  32770. 'parenleft': 333,
  32771. 'parenright': 333,
  32772. 'asterisk': 500,
  32773. 'plus': 570,
  32774. 'comma': 250,
  32775. 'hyphen': 333,
  32776. 'period': 250,
  32777. 'slash': 278,
  32778. 'zero': 500,
  32779. 'one': 500,
  32780. 'two': 500,
  32781. 'three': 500,
  32782. 'four': 500,
  32783. 'five': 500,
  32784. 'six': 500,
  32785. 'seven': 500,
  32786. 'eight': 500,
  32787. 'nine': 500,
  32788. 'colon': 333,
  32789. 'semicolon': 333,
  32790. 'less': 570,
  32791. 'equal': 570,
  32792. 'greater': 570,
  32793. 'question': 500,
  32794. 'at': 832,
  32795. 'A': 667,
  32796. 'B': 667,
  32797. 'C': 667,
  32798. 'D': 722,
  32799. 'E': 667,
  32800. 'F': 667,
  32801. 'G': 722,
  32802. 'H': 778,
  32803. 'I': 389,
  32804. 'J': 500,
  32805. 'K': 667,
  32806. 'L': 611,
  32807. 'M': 889,
  32808. 'N': 722,
  32809. 'O': 722,
  32810. 'P': 611,
  32811. 'Q': 722,
  32812. 'R': 667,
  32813. 'S': 556,
  32814. 'T': 611,
  32815. 'U': 722,
  32816. 'V': 667,
  32817. 'W': 889,
  32818. 'X': 667,
  32819. 'Y': 611,
  32820. 'Z': 611,
  32821. 'bracketleft': 333,
  32822. 'backslash': 278,
  32823. 'bracketright': 333,
  32824. 'asciicircum': 570,
  32825. 'underscore': 500,
  32826. 'quoteleft': 333,
  32827. 'a': 500,
  32828. 'b': 500,
  32829. 'c': 444,
  32830. 'd': 500,
  32831. 'e': 444,
  32832. 'f': 333,
  32833. 'g': 500,
  32834. 'h': 556,
  32835. 'i': 278,
  32836. 'j': 278,
  32837. 'k': 500,
  32838. 'l': 278,
  32839. 'm': 778,
  32840. 'n': 556,
  32841. 'o': 500,
  32842. 'p': 500,
  32843. 'q': 500,
  32844. 'r': 389,
  32845. 's': 389,
  32846. 't': 278,
  32847. 'u': 556,
  32848. 'v': 444,
  32849. 'w': 667,
  32850. 'x': 500,
  32851. 'y': 444,
  32852. 'z': 389,
  32853. 'braceleft': 348,
  32854. 'bar': 220,
  32855. 'braceright': 348,
  32856. 'asciitilde': 570,
  32857. 'exclamdown': 389,
  32858. 'cent': 500,
  32859. 'sterling': 500,
  32860. 'fraction': 167,
  32861. 'yen': 500,
  32862. 'florin': 500,
  32863. 'section': 500,
  32864. 'currency': 500,
  32865. 'quotesingle': 278,
  32866. 'quotedblleft': 500,
  32867. 'guillemotleft': 500,
  32868. 'guilsinglleft': 333,
  32869. 'guilsinglright': 333,
  32870. 'fi': 556,
  32871. 'fl': 556,
  32872. 'endash': 500,
  32873. 'dagger': 500,
  32874. 'daggerdbl': 500,
  32875. 'periodcentered': 250,
  32876. 'paragraph': 500,
  32877. 'bullet': 350,
  32878. 'quotesinglbase': 333,
  32879. 'quotedblbase': 500,
  32880. 'quotedblright': 500,
  32881. 'guillemotright': 500,
  32882. 'ellipsis': 1000,
  32883. 'perthousand': 1000,
  32884. 'questiondown': 500,
  32885. 'grave': 333,
  32886. 'acute': 333,
  32887. 'circumflex': 333,
  32888. 'tilde': 333,
  32889. 'macron': 333,
  32890. 'breve': 333,
  32891. 'dotaccent': 333,
  32892. 'dieresis': 333,
  32893. 'ring': 333,
  32894. 'cedilla': 333,
  32895. 'hungarumlaut': 333,
  32896. 'ogonek': 333,
  32897. 'caron': 333,
  32898. 'emdash': 1000,
  32899. 'AE': 944,
  32900. 'ordfeminine': 266,
  32901. 'Lslash': 611,
  32902. 'Oslash': 722,
  32903. 'OE': 944,
  32904. 'ordmasculine': 300,
  32905. 'ae': 722,
  32906. 'dotlessi': 278,
  32907. 'lslash': 278,
  32908. 'oslash': 500,
  32909. 'oe': 722,
  32910. 'germandbls': 500,
  32911. 'Idieresis': 389,
  32912. 'eacute': 444,
  32913. 'abreve': 500,
  32914. 'uhungarumlaut': 556,
  32915. 'ecaron': 444,
  32916. 'Ydieresis': 611,
  32917. 'divide': 570,
  32918. 'Yacute': 611,
  32919. 'Acircumflex': 667,
  32920. 'aacute': 500,
  32921. 'Ucircumflex': 722,
  32922. 'yacute': 444,
  32923. 'scommaaccent': 389,
  32924. 'ecircumflex': 444,
  32925. 'Uring': 722,
  32926. 'Udieresis': 722,
  32927. 'aogonek': 500,
  32928. 'Uacute': 722,
  32929. 'uogonek': 556,
  32930. 'Edieresis': 667,
  32931. 'Dcroat': 722,
  32932. 'commaaccent': 250,
  32933. 'copyright': 747,
  32934. 'Emacron': 667,
  32935. 'ccaron': 444,
  32936. 'aring': 500,
  32937. 'Ncommaaccent': 722,
  32938. 'lacute': 278,
  32939. 'agrave': 500,
  32940. 'Tcommaaccent': 611,
  32941. 'Cacute': 667,
  32942. 'atilde': 500,
  32943. 'Edotaccent': 667,
  32944. 'scaron': 389,
  32945. 'scedilla': 389,
  32946. 'iacute': 278,
  32947. 'lozenge': 494,
  32948. 'Rcaron': 667,
  32949. 'Gcommaaccent': 722,
  32950. 'ucircumflex': 556,
  32951. 'acircumflex': 500,
  32952. 'Amacron': 667,
  32953. 'rcaron': 389,
  32954. 'ccedilla': 444,
  32955. 'Zdotaccent': 611,
  32956. 'Thorn': 611,
  32957. 'Omacron': 722,
  32958. 'Racute': 667,
  32959. 'Sacute': 556,
  32960. 'dcaron': 608,
  32961. 'Umacron': 722,
  32962. 'uring': 556,
  32963. 'threesuperior': 300,
  32964. 'Ograve': 722,
  32965. 'Agrave': 667,
  32966. 'Abreve': 667,
  32967. 'multiply': 570,
  32968. 'uacute': 556,
  32969. 'Tcaron': 611,
  32970. 'partialdiff': 494,
  32971. 'ydieresis': 444,
  32972. 'Nacute': 722,
  32973. 'icircumflex': 278,
  32974. 'Ecircumflex': 667,
  32975. 'adieresis': 500,
  32976. 'edieresis': 444,
  32977. 'cacute': 444,
  32978. 'nacute': 556,
  32979. 'umacron': 556,
  32980. 'Ncaron': 722,
  32981. 'Iacute': 389,
  32982. 'plusminus': 570,
  32983. 'brokenbar': 220,
  32984. 'registered': 747,
  32985. 'Gbreve': 722,
  32986. 'Idotaccent': 389,
  32987. 'summation': 600,
  32988. 'Egrave': 667,
  32989. 'racute': 389,
  32990. 'omacron': 500,
  32991. 'Zacute': 611,
  32992. 'Zcaron': 611,
  32993. 'greaterequal': 549,
  32994. 'Eth': 722,
  32995. 'Ccedilla': 667,
  32996. 'lcommaaccent': 278,
  32997. 'tcaron': 366,
  32998. 'eogonek': 444,
  32999. 'Uogonek': 722,
  33000. 'Aacute': 667,
  33001. 'Adieresis': 667,
  33002. 'egrave': 444,
  33003. 'zacute': 389,
  33004. 'iogonek': 278,
  33005. 'Oacute': 722,
  33006. 'oacute': 500,
  33007. 'amacron': 500,
  33008. 'sacute': 389,
  33009. 'idieresis': 278,
  33010. 'Ocircumflex': 722,
  33011. 'Ugrave': 722,
  33012. 'Delta': 612,
  33013. 'thorn': 500,
  33014. 'twosuperior': 300,
  33015. 'Odieresis': 722,
  33016. 'mu': 576,
  33017. 'igrave': 278,
  33018. 'ohungarumlaut': 500,
  33019. 'Eogonek': 667,
  33020. 'dcroat': 500,
  33021. 'threequarters': 750,
  33022. 'Scedilla': 556,
  33023. 'lcaron': 382,
  33024. 'Kcommaaccent': 667,
  33025. 'Lacute': 611,
  33026. 'trademark': 1000,
  33027. 'edotaccent': 444,
  33028. 'Igrave': 389,
  33029. 'Imacron': 389,
  33030. 'Lcaron': 611,
  33031. 'onehalf': 750,
  33032. 'lessequal': 549,
  33033. 'ocircumflex': 500,
  33034. 'ntilde': 556,
  33035. 'Uhungarumlaut': 722,
  33036. 'Eacute': 667,
  33037. 'emacron': 444,
  33038. 'gbreve': 500,
  33039. 'onequarter': 750,
  33040. 'Scaron': 556,
  33041. 'Scommaaccent': 556,
  33042. 'Ohungarumlaut': 722,
  33043. 'degree': 400,
  33044. 'ograve': 500,
  33045. 'Ccaron': 667,
  33046. 'ugrave': 556,
  33047. 'radical': 549,
  33048. 'Dcaron': 722,
  33049. 'rcommaaccent': 389,
  33050. 'Ntilde': 722,
  33051. 'otilde': 500,
  33052. 'Rcommaaccent': 667,
  33053. 'Lcommaaccent': 611,
  33054. 'Atilde': 667,
  33055. 'Aogonek': 667,
  33056. 'Aring': 667,
  33057. 'Otilde': 722,
  33058. 'zdotaccent': 389,
  33059. 'Ecaron': 667,
  33060. 'Iogonek': 389,
  33061. 'kcommaaccent': 500,
  33062. 'minus': 606,
  33063. 'Icircumflex': 389,
  33064. 'ncaron': 556,
  33065. 'tcommaaccent': 278,
  33066. 'logicalnot': 606,
  33067. 'odieresis': 500,
  33068. 'udieresis': 556,
  33069. 'notequal': 549,
  33070. 'gcommaaccent': 500,
  33071. 'eth': 500,
  33072. 'zcaron': 389,
  33073. 'ncommaaccent': 556,
  33074. 'onesuperior': 300,
  33075. 'imacron': 278,
  33076. 'Euro': 500
  33077. },
  33078. 'Times-Italic': {
  33079. 'space': 250,
  33080. 'exclam': 333,
  33081. 'quotedbl': 420,
  33082. 'numbersign': 500,
  33083. 'dollar': 500,
  33084. 'percent': 833,
  33085. 'ampersand': 778,
  33086. 'quoteright': 333,
  33087. 'parenleft': 333,
  33088. 'parenright': 333,
  33089. 'asterisk': 500,
  33090. 'plus': 675,
  33091. 'comma': 250,
  33092. 'hyphen': 333,
  33093. 'period': 250,
  33094. 'slash': 278,
  33095. 'zero': 500,
  33096. 'one': 500,
  33097. 'two': 500,
  33098. 'three': 500,
  33099. 'four': 500,
  33100. 'five': 500,
  33101. 'six': 500,
  33102. 'seven': 500,
  33103. 'eight': 500,
  33104. 'nine': 500,
  33105. 'colon': 333,
  33106. 'semicolon': 333,
  33107. 'less': 675,
  33108. 'equal': 675,
  33109. 'greater': 675,
  33110. 'question': 500,
  33111. 'at': 920,
  33112. 'A': 611,
  33113. 'B': 611,
  33114. 'C': 667,
  33115. 'D': 722,
  33116. 'E': 611,
  33117. 'F': 611,
  33118. 'G': 722,
  33119. 'H': 722,
  33120. 'I': 333,
  33121. 'J': 444,
  33122. 'K': 667,
  33123. 'L': 556,
  33124. 'M': 833,
  33125. 'N': 667,
  33126. 'O': 722,
  33127. 'P': 611,
  33128. 'Q': 722,
  33129. 'R': 611,
  33130. 'S': 500,
  33131. 'T': 556,
  33132. 'U': 722,
  33133. 'V': 611,
  33134. 'W': 833,
  33135. 'X': 611,
  33136. 'Y': 556,
  33137. 'Z': 556,
  33138. 'bracketleft': 389,
  33139. 'backslash': 278,
  33140. 'bracketright': 389,
  33141. 'asciicircum': 422,
  33142. 'underscore': 500,
  33143. 'quoteleft': 333,
  33144. 'a': 500,
  33145. 'b': 500,
  33146. 'c': 444,
  33147. 'd': 500,
  33148. 'e': 444,
  33149. 'f': 278,
  33150. 'g': 500,
  33151. 'h': 500,
  33152. 'i': 278,
  33153. 'j': 278,
  33154. 'k': 444,
  33155. 'l': 278,
  33156. 'm': 722,
  33157. 'n': 500,
  33158. 'o': 500,
  33159. 'p': 500,
  33160. 'q': 500,
  33161. 'r': 389,
  33162. 's': 389,
  33163. 't': 278,
  33164. 'u': 500,
  33165. 'v': 444,
  33166. 'w': 667,
  33167. 'x': 444,
  33168. 'y': 444,
  33169. 'z': 389,
  33170. 'braceleft': 400,
  33171. 'bar': 275,
  33172. 'braceright': 400,
  33173. 'asciitilde': 541,
  33174. 'exclamdown': 389,
  33175. 'cent': 500,
  33176. 'sterling': 500,
  33177. 'fraction': 167,
  33178. 'yen': 500,
  33179. 'florin': 500,
  33180. 'section': 500,
  33181. 'currency': 500,
  33182. 'quotesingle': 214,
  33183. 'quotedblleft': 556,
  33184. 'guillemotleft': 500,
  33185. 'guilsinglleft': 333,
  33186. 'guilsinglright': 333,
  33187. 'fi': 500,
  33188. 'fl': 500,
  33189. 'endash': 500,
  33190. 'dagger': 500,
  33191. 'daggerdbl': 500,
  33192. 'periodcentered': 250,
  33193. 'paragraph': 523,
  33194. 'bullet': 350,
  33195. 'quotesinglbase': 333,
  33196. 'quotedblbase': 556,
  33197. 'quotedblright': 556,
  33198. 'guillemotright': 500,
  33199. 'ellipsis': 889,
  33200. 'perthousand': 1000,
  33201. 'questiondown': 500,
  33202. 'grave': 333,
  33203. 'acute': 333,
  33204. 'circumflex': 333,
  33205. 'tilde': 333,
  33206. 'macron': 333,
  33207. 'breve': 333,
  33208. 'dotaccent': 333,
  33209. 'dieresis': 333,
  33210. 'ring': 333,
  33211. 'cedilla': 333,
  33212. 'hungarumlaut': 333,
  33213. 'ogonek': 333,
  33214. 'caron': 333,
  33215. 'emdash': 889,
  33216. 'AE': 889,
  33217. 'ordfeminine': 276,
  33218. 'Lslash': 556,
  33219. 'Oslash': 722,
  33220. 'OE': 944,
  33221. 'ordmasculine': 310,
  33222. 'ae': 667,
  33223. 'dotlessi': 278,
  33224. 'lslash': 278,
  33225. 'oslash': 500,
  33226. 'oe': 667,
  33227. 'germandbls': 500,
  33228. 'Idieresis': 333,
  33229. 'eacute': 444,
  33230. 'abreve': 500,
  33231. 'uhungarumlaut': 500,
  33232. 'ecaron': 444,
  33233. 'Ydieresis': 556,
  33234. 'divide': 675,
  33235. 'Yacute': 556,
  33236. 'Acircumflex': 611,
  33237. 'aacute': 500,
  33238. 'Ucircumflex': 722,
  33239. 'yacute': 444,
  33240. 'scommaaccent': 389,
  33241. 'ecircumflex': 444,
  33242. 'Uring': 722,
  33243. 'Udieresis': 722,
  33244. 'aogonek': 500,
  33245. 'Uacute': 722,
  33246. 'uogonek': 500,
  33247. 'Edieresis': 611,
  33248. 'Dcroat': 722,
  33249. 'commaaccent': 250,
  33250. 'copyright': 760,
  33251. 'Emacron': 611,
  33252. 'ccaron': 444,
  33253. 'aring': 500,
  33254. 'Ncommaaccent': 667,
  33255. 'lacute': 278,
  33256. 'agrave': 500,
  33257. 'Tcommaaccent': 556,
  33258. 'Cacute': 667,
  33259. 'atilde': 500,
  33260. 'Edotaccent': 611,
  33261. 'scaron': 389,
  33262. 'scedilla': 389,
  33263. 'iacute': 278,
  33264. 'lozenge': 471,
  33265. 'Rcaron': 611,
  33266. 'Gcommaaccent': 722,
  33267. 'ucircumflex': 500,
  33268. 'acircumflex': 500,
  33269. 'Amacron': 611,
  33270. 'rcaron': 389,
  33271. 'ccedilla': 444,
  33272. 'Zdotaccent': 556,
  33273. 'Thorn': 611,
  33274. 'Omacron': 722,
  33275. 'Racute': 611,
  33276. 'Sacute': 500,
  33277. 'dcaron': 544,
  33278. 'Umacron': 722,
  33279. 'uring': 500,
  33280. 'threesuperior': 300,
  33281. 'Ograve': 722,
  33282. 'Agrave': 611,
  33283. 'Abreve': 611,
  33284. 'multiply': 675,
  33285. 'uacute': 500,
  33286. 'Tcaron': 556,
  33287. 'partialdiff': 476,
  33288. 'ydieresis': 444,
  33289. 'Nacute': 667,
  33290. 'icircumflex': 278,
  33291. 'Ecircumflex': 611,
  33292. 'adieresis': 500,
  33293. 'edieresis': 444,
  33294. 'cacute': 444,
  33295. 'nacute': 500,
  33296. 'umacron': 500,
  33297. 'Ncaron': 667,
  33298. 'Iacute': 333,
  33299. 'plusminus': 675,
  33300. 'brokenbar': 275,
  33301. 'registered': 760,
  33302. 'Gbreve': 722,
  33303. 'Idotaccent': 333,
  33304. 'summation': 600,
  33305. 'Egrave': 611,
  33306. 'racute': 389,
  33307. 'omacron': 500,
  33308. 'Zacute': 556,
  33309. 'Zcaron': 556,
  33310. 'greaterequal': 549,
  33311. 'Eth': 722,
  33312. 'Ccedilla': 667,
  33313. 'lcommaaccent': 278,
  33314. 'tcaron': 300,
  33315. 'eogonek': 444,
  33316. 'Uogonek': 722,
  33317. 'Aacute': 611,
  33318. 'Adieresis': 611,
  33319. 'egrave': 444,
  33320. 'zacute': 389,
  33321. 'iogonek': 278,
  33322. 'Oacute': 722,
  33323. 'oacute': 500,
  33324. 'amacron': 500,
  33325. 'sacute': 389,
  33326. 'idieresis': 278,
  33327. 'Ocircumflex': 722,
  33328. 'Ugrave': 722,
  33329. 'Delta': 612,
  33330. 'thorn': 500,
  33331. 'twosuperior': 300,
  33332. 'Odieresis': 722,
  33333. 'mu': 500,
  33334. 'igrave': 278,
  33335. 'ohungarumlaut': 500,
  33336. 'Eogonek': 611,
  33337. 'dcroat': 500,
  33338. 'threequarters': 750,
  33339. 'Scedilla': 500,
  33340. 'lcaron': 300,
  33341. 'Kcommaaccent': 667,
  33342. 'Lacute': 556,
  33343. 'trademark': 980,
  33344. 'edotaccent': 444,
  33345. 'Igrave': 333,
  33346. 'Imacron': 333,
  33347. 'Lcaron': 611,
  33348. 'onehalf': 750,
  33349. 'lessequal': 549,
  33350. 'ocircumflex': 500,
  33351. 'ntilde': 500,
  33352. 'Uhungarumlaut': 722,
  33353. 'Eacute': 611,
  33354. 'emacron': 444,
  33355. 'gbreve': 500,
  33356. 'onequarter': 750,
  33357. 'Scaron': 500,
  33358. 'Scommaaccent': 500,
  33359. 'Ohungarumlaut': 722,
  33360. 'degree': 400,
  33361. 'ograve': 500,
  33362. 'Ccaron': 667,
  33363. 'ugrave': 500,
  33364. 'radical': 453,
  33365. 'Dcaron': 722,
  33366. 'rcommaaccent': 389,
  33367. 'Ntilde': 667,
  33368. 'otilde': 500,
  33369. 'Rcommaaccent': 611,
  33370. 'Lcommaaccent': 556,
  33371. 'Atilde': 611,
  33372. 'Aogonek': 611,
  33373. 'Aring': 611,
  33374. 'Otilde': 722,
  33375. 'zdotaccent': 389,
  33376. 'Ecaron': 611,
  33377. 'Iogonek': 333,
  33378. 'kcommaaccent': 444,
  33379. 'minus': 675,
  33380. 'Icircumflex': 333,
  33381. 'ncaron': 500,
  33382. 'tcommaaccent': 278,
  33383. 'logicalnot': 675,
  33384. 'odieresis': 500,
  33385. 'udieresis': 500,
  33386. 'notequal': 549,
  33387. 'gcommaaccent': 500,
  33388. 'eth': 500,
  33389. 'zcaron': 389,
  33390. 'ncommaaccent': 500,
  33391. 'onesuperior': 300,
  33392. 'imacron': 278,
  33393. 'Euro': 500
  33394. },
  33395. 'ZapfDingbats': {
  33396. 'space': 278,
  33397. 'a1': 974,
  33398. 'a2': 961,
  33399. 'a202': 974,
  33400. 'a3': 980,
  33401. 'a4': 719,
  33402. 'a5': 789,
  33403. 'a119': 790,
  33404. 'a118': 791,
  33405. 'a117': 690,
  33406. 'a11': 960,
  33407. 'a12': 939,
  33408. 'a13': 549,
  33409. 'a14': 855,
  33410. 'a15': 911,
  33411. 'a16': 933,
  33412. 'a105': 911,
  33413. 'a17': 945,
  33414. 'a18': 974,
  33415. 'a19': 755,
  33416. 'a20': 846,
  33417. 'a21': 762,
  33418. 'a22': 761,
  33419. 'a23': 571,
  33420. 'a24': 677,
  33421. 'a25': 763,
  33422. 'a26': 760,
  33423. 'a27': 759,
  33424. 'a28': 754,
  33425. 'a6': 494,
  33426. 'a7': 552,
  33427. 'a8': 537,
  33428. 'a9': 577,
  33429. 'a10': 692,
  33430. 'a29': 786,
  33431. 'a30': 788,
  33432. 'a31': 788,
  33433. 'a32': 790,
  33434. 'a33': 793,
  33435. 'a34': 794,
  33436. 'a35': 816,
  33437. 'a36': 823,
  33438. 'a37': 789,
  33439. 'a38': 841,
  33440. 'a39': 823,
  33441. 'a40': 833,
  33442. 'a41': 816,
  33443. 'a42': 831,
  33444. 'a43': 923,
  33445. 'a44': 744,
  33446. 'a45': 723,
  33447. 'a46': 749,
  33448. 'a47': 790,
  33449. 'a48': 792,
  33450. 'a49': 695,
  33451. 'a50': 776,
  33452. 'a51': 768,
  33453. 'a52': 792,
  33454. 'a53': 759,
  33455. 'a54': 707,
  33456. 'a55': 708,
  33457. 'a56': 682,
  33458. 'a57': 701,
  33459. 'a58': 826,
  33460. 'a59': 815,
  33461. 'a60': 789,
  33462. 'a61': 789,
  33463. 'a62': 707,
  33464. 'a63': 687,
  33465. 'a64': 696,
  33466. 'a65': 689,
  33467. 'a66': 786,
  33468. 'a67': 787,
  33469. 'a68': 713,
  33470. 'a69': 791,
  33471. 'a70': 785,
  33472. 'a71': 791,
  33473. 'a72': 873,
  33474. 'a73': 761,
  33475. 'a74': 762,
  33476. 'a203': 762,
  33477. 'a75': 759,
  33478. 'a204': 759,
  33479. 'a76': 892,
  33480. 'a77': 892,
  33481. 'a78': 788,
  33482. 'a79': 784,
  33483. 'a81': 438,
  33484. 'a82': 138,
  33485. 'a83': 277,
  33486. 'a84': 415,
  33487. 'a97': 392,
  33488. 'a98': 392,
  33489. 'a99': 668,
  33490. 'a100': 668,
  33491. 'a89': 390,
  33492. 'a90': 390,
  33493. 'a93': 317,
  33494. 'a94': 317,
  33495. 'a91': 276,
  33496. 'a92': 276,
  33497. 'a205': 509,
  33498. 'a85': 509,
  33499. 'a206': 410,
  33500. 'a86': 410,
  33501. 'a87': 234,
  33502. 'a88': 234,
  33503. 'a95': 334,
  33504. 'a96': 334,
  33505. 'a101': 732,
  33506. 'a102': 544,
  33507. 'a103': 544,
  33508. 'a104': 910,
  33509. 'a106': 667,
  33510. 'a107': 760,
  33511. 'a108': 760,
  33512. 'a112': 776,
  33513. 'a111': 595,
  33514. 'a110': 694,
  33515. 'a109': 626,
  33516. 'a120': 788,
  33517. 'a121': 788,
  33518. 'a122': 788,
  33519. 'a123': 788,
  33520. 'a124': 788,
  33521. 'a125': 788,
  33522. 'a126': 788,
  33523. 'a127': 788,
  33524. 'a128': 788,
  33525. 'a129': 788,
  33526. 'a130': 788,
  33527. 'a131': 788,
  33528. 'a132': 788,
  33529. 'a133': 788,
  33530. 'a134': 788,
  33531. 'a135': 788,
  33532. 'a136': 788,
  33533. 'a137': 788,
  33534. 'a138': 788,
  33535. 'a139': 788,
  33536. 'a140': 788,
  33537. 'a141': 788,
  33538. 'a142': 788,
  33539. 'a143': 788,
  33540. 'a144': 788,
  33541. 'a145': 788,
  33542. 'a146': 788,
  33543. 'a147': 788,
  33544. 'a148': 788,
  33545. 'a149': 788,
  33546. 'a150': 788,
  33547. 'a151': 788,
  33548. 'a152': 788,
  33549. 'a153': 788,
  33550. 'a154': 788,
  33551. 'a155': 788,
  33552. 'a156': 788,
  33553. 'a157': 788,
  33554. 'a158': 788,
  33555. 'a159': 788,
  33556. 'a160': 894,
  33557. 'a161': 838,
  33558. 'a163': 1016,
  33559. 'a164': 458,
  33560. 'a196': 748,
  33561. 'a165': 924,
  33562. 'a192': 748,
  33563. 'a166': 918,
  33564. 'a167': 927,
  33565. 'a168': 928,
  33566. 'a169': 928,
  33567. 'a170': 834,
  33568. 'a171': 873,
  33569. 'a172': 828,
  33570. 'a173': 924,
  33571. 'a162': 924,
  33572. 'a174': 917,
  33573. 'a175': 930,
  33574. 'a176': 931,
  33575. 'a177': 463,
  33576. 'a178': 883,
  33577. 'a179': 836,
  33578. 'a193': 836,
  33579. 'a180': 867,
  33580. 'a199': 867,
  33581. 'a181': 696,
  33582. 'a200': 696,
  33583. 'a182': 874,
  33584. 'a201': 874,
  33585. 'a183': 760,
  33586. 'a184': 946,
  33587. 'a197': 771,
  33588. 'a185': 865,
  33589. 'a194': 771,
  33590. 'a198': 888,
  33591. 'a186': 967,
  33592. 'a195': 888,
  33593. 'a187': 831,
  33594. 'a188': 873,
  33595. 'a189': 927,
  33596. 'a190': 970,
  33597. 'a191': 918
  33598. }
  33599. };
  33600. var EOF = {};
  33601. function isEOF(v) {
  33602. return (v === EOF);
  33603. }
  33604. var Parser = (function ParserClosure() {
  33605. function Parser(lexer, allowStreams, xref) {
  33606. this.lexer = lexer;
  33607. this.allowStreams = allowStreams;
  33608. this.xref = xref;
  33609. this.imageCache = {
  33610. length: 0,
  33611. adler32: 0,
  33612. stream: null
  33613. };
  33614. this.refill();
  33615. }
  33616. Parser.prototype = {
  33617. refill: function Parser_refill() {
  33618. this.buf1 = this.lexer.getObj();
  33619. this.buf2 = this.lexer.getObj();
  33620. },
  33621. shift: function Parser_shift() {
  33622. if (isCmd(this.buf2, 'ID')) {
  33623. this.buf1 = this.buf2;
  33624. this.buf2 = null;
  33625. } else {
  33626. this.buf1 = this.buf2;
  33627. this.buf2 = this.lexer.getObj();
  33628. }
  33629. },
  33630. getObj: function Parser_getObj(cipherTransform) {
  33631. var buf1 = this.buf1;
  33632. this.shift();
  33633. if (buf1 instanceof Cmd) {
  33634. switch (buf1.cmd) {
  33635. case 'BI': // inline image
  33636. return this.makeInlineImage(cipherTransform);
  33637. case '[': // array
  33638. var array = [];
  33639. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  33640. array.push(this.getObj(cipherTransform));
  33641. }
  33642. if (isEOF(this.buf1)) {
  33643. error('End of file inside array');
  33644. }
  33645. this.shift();
  33646. return array;
  33647. case '<<': // dictionary or stream
  33648. var dict = new Dict(this.xref);
  33649. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  33650. if (!isName(this.buf1)) {
  33651. info('Malformed dictionary: key must be a name object');
  33652. this.shift();
  33653. continue;
  33654. }
  33655. var key = this.buf1.name;
  33656. this.shift();
  33657. if (isEOF(this.buf1)) {
  33658. break;
  33659. }
  33660. dict.set(key, this.getObj(cipherTransform));
  33661. }
  33662. if (isEOF(this.buf1)) {
  33663. error('End of file inside dictionary');
  33664. }
  33665. // Stream objects are not allowed inside content streams or
  33666. // object streams.
  33667. if (isCmd(this.buf2, 'stream')) {
  33668. return (this.allowStreams ?
  33669. this.makeStream(dict, cipherTransform) : dict);
  33670. }
  33671. this.shift();
  33672. return dict;
  33673. default: // simple object
  33674. return buf1;
  33675. }
  33676. }
  33677. if (isInt(buf1)) { // indirect reference or integer
  33678. var num = buf1;
  33679. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  33680. var ref = new Ref(num, this.buf1);
  33681. this.shift();
  33682. this.shift();
  33683. return ref;
  33684. }
  33685. return num;
  33686. }
  33687. if (isString(buf1)) { // string
  33688. var str = buf1;
  33689. if (cipherTransform) {
  33690. str = cipherTransform.decryptString(str);
  33691. }
  33692. return str;
  33693. }
  33694. // simple object
  33695. return buf1;
  33696. },
  33697. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  33698. var lexer = this.lexer;
  33699. var stream = lexer.stream;
  33700. // parse dictionary
  33701. var dict = new Dict(null);
  33702. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  33703. if (!isName(this.buf1)) {
  33704. error('Dictionary key must be a name object');
  33705. }
  33706. var key = this.buf1.name;
  33707. this.shift();
  33708. if (isEOF(this.buf1)) {
  33709. break;
  33710. }
  33711. dict.set(key, this.getObj(cipherTransform));
  33712. }
  33713. // parse image stream
  33714. var startPos = stream.pos;
  33715. // searching for the /EI\s/
  33716. var state = 0, ch, i, ii;
  33717. var E = 0x45, I = 0x49, SPACE = 0x20, NL = 0xA, CR = 0xD;
  33718. while ((ch = stream.getByte()) !== -1) {
  33719. if (state === 0) {
  33720. state = (ch === E) ? 1 : 0;
  33721. } else if (state === 1) {
  33722. state = (ch === I) ? 2 : 0;
  33723. } else {
  33724. assert(state === 2);
  33725. if (ch === SPACE || ch === NL || ch === CR) {
  33726. // Let's check the next five bytes are ASCII... just be sure.
  33727. var n = 5;
  33728. var followingBytes = stream.peekBytes(n);
  33729. for (i = 0; i < n; i++) {
  33730. ch = followingBytes[i];
  33731. if (ch !== NL && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  33732. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  33733. // it's binary stuff. Resetting the state.
  33734. state = 0;
  33735. break;
  33736. }
  33737. }
  33738. if (state === 2) {
  33739. break; // finished!
  33740. }
  33741. } else {
  33742. state = 0;
  33743. }
  33744. }
  33745. }
  33746. var length = (stream.pos - 4) - startPos;
  33747. var imageStream = stream.makeSubStream(startPos, length, dict);
  33748. // trying to cache repeat images, first we are trying to "warm up" caching
  33749. // using length, then comparing adler32
  33750. var MAX_LENGTH_TO_CACHE = 1000;
  33751. var cacheImage = false, adler32;
  33752. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  33753. var imageBytes = imageStream.getBytes();
  33754. imageStream.reset();
  33755. var a = 1;
  33756. var b = 0;
  33757. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  33758. a = (a + (imageBytes[i] & 0xff)) % 65521;
  33759. b = (b + a) % 65521;
  33760. }
  33761. adler32 = (b << 16) | a;
  33762. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  33763. this.buf2 = Cmd.get('EI');
  33764. this.shift();
  33765. this.imageCache.stream.reset();
  33766. return this.imageCache.stream;
  33767. }
  33768. cacheImage = true;
  33769. }
  33770. if (!cacheImage && !this.imageCache.stream) {
  33771. this.imageCache.length = length;
  33772. this.imageCache.stream = null;
  33773. }
  33774. if (cipherTransform) {
  33775. imageStream = cipherTransform.createStream(imageStream, length);
  33776. }
  33777. imageStream = this.filter(imageStream, dict, length);
  33778. imageStream.dict = dict;
  33779. if (cacheImage) {
  33780. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  33781. this.imageCache.adler32 = adler32;
  33782. this.imageCache.stream = imageStream;
  33783. }
  33784. this.buf2 = Cmd.get('EI');
  33785. this.shift();
  33786. return imageStream;
  33787. },
  33788. fetchIfRef: function Parser_fetchIfRef(obj) {
  33789. // not relying on the xref.fetchIfRef -- xref might not be set
  33790. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  33791. },
  33792. makeStream: function Parser_makeStream(dict, cipherTransform) {
  33793. var lexer = this.lexer;
  33794. var stream = lexer.stream;
  33795. // get stream start position
  33796. lexer.skipToNextLine();
  33797. var pos = stream.pos - 1;
  33798. // get length
  33799. var length = this.fetchIfRef(dict.get('Length'));
  33800. if (!isInt(length)) {
  33801. info('Bad ' + length + ' attribute in stream');
  33802. length = 0;
  33803. }
  33804. // skip over the stream data
  33805. stream.pos = pos + length;
  33806. lexer.nextChar();
  33807. this.shift(); // '>>'
  33808. this.shift(); // 'stream'
  33809. if (!isCmd(this.buf1, 'endstream')) {
  33810. // bad stream length, scanning for endstream
  33811. stream.pos = pos;
  33812. var SCAN_BLOCK_SIZE = 2048;
  33813. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  33814. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  33815. 0x61, 0x6D];
  33816. var skipped = 0, found = false, i, j;
  33817. while (stream.pos < stream.end) {
  33818. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  33819. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  33820. if (scanLength <= 0) {
  33821. break;
  33822. }
  33823. found = false;
  33824. for (i = 0, j = 0; i < scanLength; i++) {
  33825. var b = scanBytes[i];
  33826. if (b !== ENDSTREAM_SIGNATURE[j]) {
  33827. i -= j;
  33828. j = 0;
  33829. } else {
  33830. j++;
  33831. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  33832. i++;
  33833. found = true;
  33834. break;
  33835. }
  33836. }
  33837. }
  33838. if (found) {
  33839. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  33840. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  33841. break;
  33842. }
  33843. skipped += scanLength;
  33844. stream.pos += scanLength;
  33845. }
  33846. if (!found) {
  33847. error('Missing endstream');
  33848. }
  33849. length = skipped;
  33850. lexer.nextChar();
  33851. this.shift();
  33852. this.shift();
  33853. }
  33854. this.shift(); // 'endstream'
  33855. stream = stream.makeSubStream(pos, length, dict);
  33856. if (cipherTransform) {
  33857. stream = cipherTransform.createStream(stream, length);
  33858. }
  33859. stream = this.filter(stream, dict, length);
  33860. stream.dict = dict;
  33861. return stream;
  33862. },
  33863. filter: function Parser_filter(stream, dict, length) {
  33864. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  33865. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  33866. if (isName(filter)) {
  33867. return this.makeFilter(stream, filter.name, length, params);
  33868. }
  33869. var maybeLength = length;
  33870. if (isArray(filter)) {
  33871. var filterArray = filter;
  33872. var paramsArray = params;
  33873. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  33874. filter = filterArray[i];
  33875. if (!isName(filter)) {
  33876. error('Bad filter name: ' + filter);
  33877. }
  33878. params = null;
  33879. if (isArray(paramsArray) && (i in paramsArray)) {
  33880. params = paramsArray[i];
  33881. }
  33882. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  33883. // after the first stream the length variable is invalid
  33884. maybeLength = null;
  33885. }
  33886. }
  33887. return stream;
  33888. },
  33889. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  33890. if (stream.dict.get('Length') === 0) {
  33891. return new NullStream(stream);
  33892. }
  33893. try {
  33894. if (params) {
  33895. params = this.fetchIfRef(params);
  33896. }
  33897. var xrefStreamStats = this.xref.stats.streamTypes;
  33898. if (name === 'FlateDecode' || name === 'Fl') {
  33899. xrefStreamStats[StreamType.FLATE] = true;
  33900. if (params) {
  33901. return new PredictorStream(new FlateStream(stream, maybeLength),
  33902. maybeLength, params);
  33903. }
  33904. return new FlateStream(stream, maybeLength);
  33905. }
  33906. if (name === 'LZWDecode' || name === 'LZW') {
  33907. xrefStreamStats[StreamType.LZW] = true;
  33908. var earlyChange = 1;
  33909. if (params) {
  33910. if (params.has('EarlyChange')) {
  33911. earlyChange = params.get('EarlyChange');
  33912. }
  33913. return new PredictorStream(
  33914. new LZWStream(stream, maybeLength, earlyChange),
  33915. maybeLength, params);
  33916. }
  33917. return new LZWStream(stream, maybeLength, earlyChange);
  33918. }
  33919. if (name === 'DCTDecode' || name === 'DCT') {
  33920. // According to the specification: for inline images, the ID operator
  33921. // shall be followed by a single whitespace character (unless it uses
  33922. // ASCII85Decode or ASCIIHexDecode filters).
  33923. // In practice this only seems to be followed for inline JPEG images,
  33924. // and generally ignoring the first byte of the stream if it is a
  33925. // whitespace char can even *cause* issues (e.g. in the CCITTFaxDecode
  33926. // filters used in issue2984.pdf).
  33927. // Hence when the first byte of the stream of an inline JPEG image is
  33928. // a whitespace character, we thus simply skip over it.
  33929. if (isCmd(this.buf1, 'ID')) {
  33930. var firstByte = stream.peekByte();
  33931. if (firstByte === 0x0A /* LF */ || firstByte === 0x0D /* CR */ ||
  33932. firstByte === 0x20 /* SPACE */) {
  33933. stream.skip();
  33934. }
  33935. }
  33936. xrefStreamStats[StreamType.DCT] = true;
  33937. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  33938. }
  33939. if (name === 'JPXDecode' || name === 'JPX') {
  33940. xrefStreamStats[StreamType.JPX] = true;
  33941. return new JpxStream(stream, maybeLength, stream.dict);
  33942. }
  33943. if (name === 'ASCII85Decode' || name === 'A85') {
  33944. xrefStreamStats[StreamType.A85] = true;
  33945. return new Ascii85Stream(stream, maybeLength);
  33946. }
  33947. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  33948. xrefStreamStats[StreamType.AHX] = true;
  33949. return new AsciiHexStream(stream, maybeLength);
  33950. }
  33951. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  33952. xrefStreamStats[StreamType.CCF] = true;
  33953. return new CCITTFaxStream(stream, maybeLength, params);
  33954. }
  33955. if (name === 'RunLengthDecode' || name === 'RL') {
  33956. xrefStreamStats[StreamType.RL] = true;
  33957. return new RunLengthStream(stream, maybeLength);
  33958. }
  33959. if (name === 'JBIG2Decode') {
  33960. xrefStreamStats[StreamType.JBIG] = true;
  33961. return new Jbig2Stream(stream, maybeLength, stream.dict);
  33962. }
  33963. warn('filter "' + name + '" not supported yet');
  33964. return stream;
  33965. } catch (ex) {
  33966. if (ex instanceof MissingDataException) {
  33967. throw ex;
  33968. }
  33969. warn('Invalid stream: \"' + ex + '\"');
  33970. return new NullStream(stream);
  33971. }
  33972. }
  33973. };
  33974. return Parser;
  33975. })();
  33976. var Lexer = (function LexerClosure() {
  33977. function Lexer(stream, knownCommands) {
  33978. this.stream = stream;
  33979. this.nextChar();
  33980. // While lexing, we build up many strings one char at a time. Using += for
  33981. // this can result in lots of garbage strings. It's better to build an
  33982. // array of single-char strings and then join() them together at the end.
  33983. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  33984. // purpose uses less memory than using a new array for each string.
  33985. this.strBuf = [];
  33986. // The PDFs might have "glued" commands with other commands, operands or
  33987. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  33988. // commands and their prefixes. The prefixes are built the following way:
  33989. // if there a command that is a prefix of the other valid command or
  33990. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  33991. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  33992. // other commands or literals as a prefix. The knowCommands is optional.
  33993. this.knownCommands = knownCommands;
  33994. }
  33995. Lexer.isSpace = function Lexer_isSpace(ch) {
  33996. // Space is one of the following characters: SPACE, TAB, CR or LF.
  33997. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  33998. };
  33999. // A '1' in this array means the character is white space. A '1' or
  34000. // '2' means the character ends a name or command.
  34001. var specialChars = [
  34002. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34004. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34018. ];
  34019. function toHexDigit(ch) {
  34020. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34021. return ch & 0x0F;
  34022. }
  34023. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34024. // 'A'-'F', 'a'-'f'
  34025. return (ch & 0x0F) + 9;
  34026. }
  34027. return -1;
  34028. }
  34029. Lexer.prototype = {
  34030. nextChar: function Lexer_nextChar() {
  34031. return (this.currentChar = this.stream.getByte());
  34032. },
  34033. peekChar: function Lexer_peekChar() {
  34034. return this.stream.peekByte();
  34035. },
  34036. getNumber: function Lexer_getNumber() {
  34037. var ch = this.currentChar;
  34038. var eNotation = false;
  34039. var divideBy = 0; // different from 0 if it's a floating point value
  34040. var sign = 1;
  34041. if (ch === 0x2D) { // '-'
  34042. sign = -1;
  34043. ch = this.nextChar();
  34044. } else if (ch === 0x2B) { // '+'
  34045. ch = this.nextChar();
  34046. }
  34047. if (ch === 0x2E) { // '.'
  34048. divideBy = 10;
  34049. ch = this.nextChar();
  34050. }
  34051. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34052. error('Invalid number: ' + String.fromCharCode(ch));
  34053. return 0;
  34054. }
  34055. var baseValue = ch - 0x30; // '0'
  34056. var powerValue = 0;
  34057. var powerValueSign = 1;
  34058. while ((ch = this.nextChar()) >= 0) {
  34059. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34060. var currentDigit = ch - 0x30; // '0'
  34061. if (eNotation) { // We are after an 'e' or 'E'
  34062. powerValue = powerValue * 10 + currentDigit;
  34063. } else {
  34064. if (divideBy !== 0) { // We are after a point
  34065. divideBy *= 10;
  34066. }
  34067. baseValue = baseValue * 10 + currentDigit;
  34068. }
  34069. } else if (ch === 0x2E) { // '.'
  34070. if (divideBy === 0) {
  34071. divideBy = 1;
  34072. } else {
  34073. // A number can have only one '.'
  34074. break;
  34075. }
  34076. } else if (ch === 0x2D) { // '-'
  34077. // ignore minus signs in the middle of numbers to match
  34078. // Adobe's behavior
  34079. warn('Badly formated number');
  34080. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34081. // 'E' can be either a scientific notation or the beginning of a new
  34082. // operator
  34083. ch = this.peekChar();
  34084. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34085. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34086. this.nextChar(); // Consume the sign character
  34087. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34088. // The 'E' must be the beginning of a new operator
  34089. break;
  34090. }
  34091. eNotation = true;
  34092. } else {
  34093. // the last character doesn't belong to us
  34094. break;
  34095. }
  34096. }
  34097. if (divideBy !== 0) {
  34098. baseValue /= divideBy;
  34099. }
  34100. if (eNotation) {
  34101. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34102. }
  34103. return sign * baseValue;
  34104. },
  34105. getString: function Lexer_getString() {
  34106. var numParen = 1;
  34107. var done = false;
  34108. var strBuf = this.strBuf;
  34109. strBuf.length = 0;
  34110. var ch = this.nextChar();
  34111. while (true) {
  34112. var charBuffered = false;
  34113. switch (ch | 0) {
  34114. case -1:
  34115. warn('Unterminated string');
  34116. done = true;
  34117. break;
  34118. case 0x28: // '('
  34119. ++numParen;
  34120. strBuf.push('(');
  34121. break;
  34122. case 0x29: // ')'
  34123. if (--numParen === 0) {
  34124. this.nextChar(); // consume strings ')'
  34125. done = true;
  34126. } else {
  34127. strBuf.push(')');
  34128. }
  34129. break;
  34130. case 0x5C: // '\\'
  34131. ch = this.nextChar();
  34132. switch (ch) {
  34133. case -1:
  34134. warn('Unterminated string');
  34135. done = true;
  34136. break;
  34137. case 0x6E: // 'n'
  34138. strBuf.push('\n');
  34139. break;
  34140. case 0x72: // 'r'
  34141. strBuf.push('\r');
  34142. break;
  34143. case 0x74: // 't'
  34144. strBuf.push('\t');
  34145. break;
  34146. case 0x62: // 'b'
  34147. strBuf.push('\b');
  34148. break;
  34149. case 0x66: // 'f'
  34150. strBuf.push('\f');
  34151. break;
  34152. case 0x5C: // '\'
  34153. case 0x28: // '('
  34154. case 0x29: // ')'
  34155. strBuf.push(String.fromCharCode(ch));
  34156. break;
  34157. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34158. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34159. var x = ch & 0x0F;
  34160. ch = this.nextChar();
  34161. charBuffered = true;
  34162. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34163. x = (x << 3) + (ch & 0x0F);
  34164. ch = this.nextChar();
  34165. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34166. charBuffered = false;
  34167. x = (x << 3) + (ch & 0x0F);
  34168. }
  34169. }
  34170. strBuf.push(String.fromCharCode(x));
  34171. break;
  34172. case 0x0D: // CR
  34173. if (this.peekChar() === 0x0A) { // LF
  34174. this.nextChar();
  34175. }
  34176. break;
  34177. case 0x0A: // LF
  34178. break;
  34179. default:
  34180. strBuf.push(String.fromCharCode(ch));
  34181. break;
  34182. }
  34183. break;
  34184. default:
  34185. strBuf.push(String.fromCharCode(ch));
  34186. break;
  34187. }
  34188. if (done) {
  34189. break;
  34190. }
  34191. if (!charBuffered) {
  34192. ch = this.nextChar();
  34193. }
  34194. }
  34195. return strBuf.join('');
  34196. },
  34197. getName: function Lexer_getName() {
  34198. var ch;
  34199. var strBuf = this.strBuf;
  34200. strBuf.length = 0;
  34201. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34202. if (ch === 0x23) { // '#'
  34203. ch = this.nextChar();
  34204. var x = toHexDigit(ch);
  34205. if (x !== -1) {
  34206. var x2 = toHexDigit(this.nextChar());
  34207. if (x2 === -1) {
  34208. error('Illegal digit in hex char in name: ' + x2);
  34209. }
  34210. strBuf.push(String.fromCharCode((x << 4) | x2));
  34211. } else {
  34212. strBuf.push('#', String.fromCharCode(ch));
  34213. }
  34214. } else {
  34215. strBuf.push(String.fromCharCode(ch));
  34216. }
  34217. }
  34218. if (strBuf.length > 128) {
  34219. error('Warning: name token is longer than allowed by the spec: ' +
  34220. strBuf.length);
  34221. }
  34222. return Name.get(strBuf.join(''));
  34223. },
  34224. getHexString: function Lexer_getHexString() {
  34225. var strBuf = this.strBuf;
  34226. strBuf.length = 0;
  34227. var ch = this.currentChar;
  34228. var isFirstHex = true;
  34229. var firstDigit;
  34230. var secondDigit;
  34231. while (true) {
  34232. if (ch < 0) {
  34233. warn('Unterminated hex string');
  34234. break;
  34235. } else if (ch === 0x3E) { // '>'
  34236. this.nextChar();
  34237. break;
  34238. } else if (specialChars[ch] === 1) {
  34239. ch = this.nextChar();
  34240. continue;
  34241. } else {
  34242. if (isFirstHex) {
  34243. firstDigit = toHexDigit(ch);
  34244. if (firstDigit === -1) {
  34245. warn('Ignoring invalid character "' + ch + '" in hex string');
  34246. ch = this.nextChar();
  34247. continue;
  34248. }
  34249. } else {
  34250. secondDigit = toHexDigit(ch);
  34251. if (secondDigit === -1) {
  34252. warn('Ignoring invalid character "' + ch + '" in hex string');
  34253. ch = this.nextChar();
  34254. continue;
  34255. }
  34256. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34257. }
  34258. isFirstHex = !isFirstHex;
  34259. ch = this.nextChar();
  34260. }
  34261. }
  34262. return strBuf.join('');
  34263. },
  34264. getObj: function Lexer_getObj() {
  34265. // skip whitespace and comments
  34266. var comment = false;
  34267. var ch = this.currentChar;
  34268. while (true) {
  34269. if (ch < 0) {
  34270. return EOF;
  34271. }
  34272. if (comment) {
  34273. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34274. comment = false;
  34275. }
  34276. } else if (ch === 0x25) { // '%'
  34277. comment = true;
  34278. } else if (specialChars[ch] !== 1) {
  34279. break;
  34280. }
  34281. ch = this.nextChar();
  34282. }
  34283. // start reading token
  34284. switch (ch | 0) {
  34285. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34286. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34287. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34288. return this.getNumber();
  34289. case 0x28: // '('
  34290. return this.getString();
  34291. case 0x2F: // '/'
  34292. return this.getName();
  34293. // array punctuation
  34294. case 0x5B: // '['
  34295. this.nextChar();
  34296. return Cmd.get('[');
  34297. case 0x5D: // ']'
  34298. this.nextChar();
  34299. return Cmd.get(']');
  34300. // hex string or dict punctuation
  34301. case 0x3C: // '<'
  34302. ch = this.nextChar();
  34303. if (ch === 0x3C) {
  34304. // dict punctuation
  34305. this.nextChar();
  34306. return Cmd.get('<<');
  34307. }
  34308. return this.getHexString();
  34309. // dict punctuation
  34310. case 0x3E: // '>'
  34311. ch = this.nextChar();
  34312. if (ch === 0x3E) {
  34313. this.nextChar();
  34314. return Cmd.get('>>');
  34315. }
  34316. return Cmd.get('>');
  34317. case 0x7B: // '{'
  34318. this.nextChar();
  34319. return Cmd.get('{');
  34320. case 0x7D: // '}'
  34321. this.nextChar();
  34322. return Cmd.get('}');
  34323. case 0x29: // ')'
  34324. error('Illegal character: ' + ch);
  34325. break;
  34326. }
  34327. // command
  34328. var str = String.fromCharCode(ch);
  34329. var knownCommands = this.knownCommands;
  34330. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34331. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34332. // stop if known command is found and next character does not make
  34333. // the str a command
  34334. var possibleCommand = str + String.fromCharCode(ch);
  34335. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34336. break;
  34337. }
  34338. if (str.length === 128) {
  34339. error('Command token too long: ' + str.length);
  34340. }
  34341. str = possibleCommand;
  34342. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34343. }
  34344. if (str === 'true') {
  34345. return true;
  34346. }
  34347. if (str === 'false') {
  34348. return false;
  34349. }
  34350. if (str === 'null') {
  34351. return null;
  34352. }
  34353. return Cmd.get(str);
  34354. },
  34355. skipToNextLine: function Lexer_skipToNextLine() {
  34356. var ch = this.currentChar;
  34357. while (ch >= 0) {
  34358. if (ch === 0x0D) { // CR
  34359. ch = this.nextChar();
  34360. if (ch === 0x0A) { // LF
  34361. this.nextChar();
  34362. }
  34363. break;
  34364. } else if (ch === 0x0A) { // LF
  34365. this.nextChar();
  34366. break;
  34367. }
  34368. ch = this.nextChar();
  34369. }
  34370. }
  34371. };
  34372. return Lexer;
  34373. })();
  34374. var Linearization = {
  34375. create: function LinearizationCreate(stream) {
  34376. function getInt(name, allowZeroValue) {
  34377. var obj = linDict.get(name);
  34378. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34379. return obj;
  34380. }
  34381. throw new Error('The "' + name + '" parameter in the linearization ' +
  34382. 'dictionary is invalid.');
  34383. }
  34384. function getHints() {
  34385. var hints = linDict.get('H'), hintsLength, item;
  34386. if (isArray(hints) &&
  34387. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34388. for (var index = 0; index < hintsLength; index++) {
  34389. if (!(isInt(item = hints[index]) && item > 0)) {
  34390. throw new Error('Hint (' + index +
  34391. ') in the linearization dictionary is invalid.');
  34392. }
  34393. }
  34394. return hints;
  34395. }
  34396. throw new Error('Hint array in the linearization dictionary is invalid.');
  34397. }
  34398. var parser = new Parser(new Lexer(stream), false, null);
  34399. var obj1 = parser.getObj();
  34400. var obj2 = parser.getObj();
  34401. var obj3 = parser.getObj();
  34402. var linDict = parser.getObj();
  34403. var obj, length;
  34404. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34405. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34406. return null; // No valid linearization dictionary found.
  34407. } else if ((length = getInt('L')) !== stream.length) {
  34408. throw new Error('The "L" parameter in the linearization dictionary ' +
  34409. 'does not equal the stream length.');
  34410. }
  34411. return {
  34412. length: length,
  34413. hints: getHints(),
  34414. objectNumberFirst: getInt('O'),
  34415. endFirst: getInt('E'),
  34416. numPages: getInt('N'),
  34417. mainXRefEntriesOffset: getInt('T'),
  34418. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34419. };
  34420. }
  34421. };
  34422. var PostScriptParser = (function PostScriptParserClosure() {
  34423. function PostScriptParser(lexer) {
  34424. this.lexer = lexer;
  34425. this.operators = [];
  34426. this.token = null;
  34427. this.prev = null;
  34428. }
  34429. PostScriptParser.prototype = {
  34430. nextToken: function PostScriptParser_nextToken() {
  34431. this.prev = this.token;
  34432. this.token = this.lexer.getToken();
  34433. },
  34434. accept: function PostScriptParser_accept(type) {
  34435. if (this.token.type === type) {
  34436. this.nextToken();
  34437. return true;
  34438. }
  34439. return false;
  34440. },
  34441. expect: function PostScriptParser_expect(type) {
  34442. if (this.accept(type)) {
  34443. return true;
  34444. }
  34445. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34446. type + '.');
  34447. },
  34448. parse: function PostScriptParser_parse() {
  34449. this.nextToken();
  34450. this.expect(PostScriptTokenTypes.LBRACE);
  34451. this.parseBlock();
  34452. this.expect(PostScriptTokenTypes.RBRACE);
  34453. return this.operators;
  34454. },
  34455. parseBlock: function PostScriptParser_parseBlock() {
  34456. while (true) {
  34457. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34458. this.operators.push(this.prev.value);
  34459. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34460. this.operators.push(this.prev.value);
  34461. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34462. this.parseCondition();
  34463. } else {
  34464. return;
  34465. }
  34466. }
  34467. },
  34468. parseCondition: function PostScriptParser_parseCondition() {
  34469. // Add two place holders that will be updated later
  34470. var conditionLocation = this.operators.length;
  34471. this.operators.push(null, null);
  34472. this.parseBlock();
  34473. this.expect(PostScriptTokenTypes.RBRACE);
  34474. if (this.accept(PostScriptTokenTypes.IF)) {
  34475. // The true block is right after the 'if' so it just falls through on
  34476. // true else it jumps and skips the true block.
  34477. this.operators[conditionLocation] = this.operators.length;
  34478. this.operators[conditionLocation + 1] = 'jz';
  34479. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34480. var jumpLocation = this.operators.length;
  34481. this.operators.push(null, null);
  34482. var endOfTrue = this.operators.length;
  34483. this.parseBlock();
  34484. this.expect(PostScriptTokenTypes.RBRACE);
  34485. this.expect(PostScriptTokenTypes.IFELSE);
  34486. // The jump is added at the end of the true block to skip the false
  34487. // block.
  34488. this.operators[jumpLocation] = this.operators.length;
  34489. this.operators[jumpLocation + 1] = 'j';
  34490. this.operators[conditionLocation] = endOfTrue;
  34491. this.operators[conditionLocation + 1] = 'jz';
  34492. } else {
  34493. error('PS Function: error parsing conditional.');
  34494. }
  34495. }
  34496. };
  34497. return PostScriptParser;
  34498. })();
  34499. var PostScriptTokenTypes = {
  34500. LBRACE: 0,
  34501. RBRACE: 1,
  34502. NUMBER: 2,
  34503. OPERATOR: 3,
  34504. IF: 4,
  34505. IFELSE: 5
  34506. };
  34507. var PostScriptToken = (function PostScriptTokenClosure() {
  34508. function PostScriptToken(type, value) {
  34509. this.type = type;
  34510. this.value = value;
  34511. }
  34512. var opCache = {};
  34513. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  34514. var opValue = opCache[op];
  34515. if (opValue) {
  34516. return opValue;
  34517. }
  34518. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  34519. };
  34520. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  34521. '{');
  34522. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  34523. '}');
  34524. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  34525. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  34526. 'IFELSE');
  34527. return PostScriptToken;
  34528. })();
  34529. var PostScriptLexer = (function PostScriptLexerClosure() {
  34530. function PostScriptLexer(stream) {
  34531. this.stream = stream;
  34532. this.nextChar();
  34533. this.strBuf = [];
  34534. }
  34535. PostScriptLexer.prototype = {
  34536. nextChar: function PostScriptLexer_nextChar() {
  34537. return (this.currentChar = this.stream.getByte());
  34538. },
  34539. getToken: function PostScriptLexer_getToken() {
  34540. var comment = false;
  34541. var ch = this.currentChar;
  34542. // skip comments
  34543. while (true) {
  34544. if (ch < 0) {
  34545. return EOF;
  34546. }
  34547. if (comment) {
  34548. if (ch === 0x0A || ch === 0x0D) {
  34549. comment = false;
  34550. }
  34551. } else if (ch === 0x25) { // '%'
  34552. comment = true;
  34553. } else if (!Lexer.isSpace(ch)) {
  34554. break;
  34555. }
  34556. ch = this.nextChar();
  34557. }
  34558. switch (ch | 0) {
  34559. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34560. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34561. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34562. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  34563. this.getNumber());
  34564. case 0x7B: // '{'
  34565. this.nextChar();
  34566. return PostScriptToken.LBRACE;
  34567. case 0x7D: // '}'
  34568. this.nextChar();
  34569. return PostScriptToken.RBRACE;
  34570. }
  34571. // operator
  34572. var strBuf = this.strBuf;
  34573. strBuf.length = 0;
  34574. strBuf[0] = String.fromCharCode(ch);
  34575. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  34576. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  34577. strBuf.push(String.fromCharCode(ch));
  34578. }
  34579. var str = strBuf.join('');
  34580. switch (str.toLowerCase()) {
  34581. case 'if':
  34582. return PostScriptToken.IF;
  34583. case 'ifelse':
  34584. return PostScriptToken.IFELSE;
  34585. default:
  34586. return PostScriptToken.getOperator(str);
  34587. }
  34588. },
  34589. getNumber: function PostScriptLexer_getNumber() {
  34590. var ch = this.currentChar;
  34591. var strBuf = this.strBuf;
  34592. strBuf.length = 0;
  34593. strBuf[0] = String.fromCharCode(ch);
  34594. while ((ch = this.nextChar()) >= 0) {
  34595. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  34596. ch === 0x2D || ch === 0x2E) { // '-', '.'
  34597. strBuf.push(String.fromCharCode(ch));
  34598. } else {
  34599. break;
  34600. }
  34601. }
  34602. var value = parseFloat(strBuf.join(''));
  34603. if (isNaN(value)) {
  34604. error('Invalid floating point number: ' + value);
  34605. }
  34606. return value;
  34607. }
  34608. };
  34609. return PostScriptLexer;
  34610. })();
  34611. var Stream = (function StreamClosure() {
  34612. function Stream(arrayBuffer, start, length, dict) {
  34613. this.bytes = (arrayBuffer instanceof Uint8Array ?
  34614. arrayBuffer : new Uint8Array(arrayBuffer));
  34615. this.start = start || 0;
  34616. this.pos = this.start;
  34617. this.end = (start + length) || this.bytes.length;
  34618. this.dict = dict;
  34619. }
  34620. // required methods for a stream. if a particular stream does not
  34621. // implement these, an error should be thrown
  34622. Stream.prototype = {
  34623. get length() {
  34624. return this.end - this.start;
  34625. },
  34626. get isEmpty() {
  34627. return this.length === 0;
  34628. },
  34629. getByte: function Stream_getByte() {
  34630. if (this.pos >= this.end) {
  34631. return -1;
  34632. }
  34633. return this.bytes[this.pos++];
  34634. },
  34635. getUint16: function Stream_getUint16() {
  34636. var b0 = this.getByte();
  34637. var b1 = this.getByte();
  34638. return (b0 << 8) + b1;
  34639. },
  34640. getInt32: function Stream_getInt32() {
  34641. var b0 = this.getByte();
  34642. var b1 = this.getByte();
  34643. var b2 = this.getByte();
  34644. var b3 = this.getByte();
  34645. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  34646. },
  34647. // returns subarray of original buffer
  34648. // should only be read
  34649. getBytes: function Stream_getBytes(length) {
  34650. var bytes = this.bytes;
  34651. var pos = this.pos;
  34652. var strEnd = this.end;
  34653. if (!length) {
  34654. return bytes.subarray(pos, strEnd);
  34655. }
  34656. var end = pos + length;
  34657. if (end > strEnd) {
  34658. end = strEnd;
  34659. }
  34660. this.pos = end;
  34661. return bytes.subarray(pos, end);
  34662. },
  34663. peekByte: function Stream_peekByte() {
  34664. var peekedByte = this.getByte();
  34665. this.pos--;
  34666. return peekedByte;
  34667. },
  34668. peekBytes: function Stream_peekBytes(length) {
  34669. var bytes = this.getBytes(length);
  34670. this.pos -= bytes.length;
  34671. return bytes;
  34672. },
  34673. skip: function Stream_skip(n) {
  34674. if (!n) {
  34675. n = 1;
  34676. }
  34677. this.pos += n;
  34678. },
  34679. reset: function Stream_reset() {
  34680. this.pos = this.start;
  34681. },
  34682. moveStart: function Stream_moveStart() {
  34683. this.start = this.pos;
  34684. },
  34685. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  34686. return new Stream(this.bytes.buffer, start, length, dict);
  34687. },
  34688. isStream: true
  34689. };
  34690. return Stream;
  34691. })();
  34692. var StringStream = (function StringStreamClosure() {
  34693. function StringStream(str) {
  34694. var length = str.length;
  34695. var bytes = new Uint8Array(length);
  34696. for (var n = 0; n < length; ++n) {
  34697. bytes[n] = str.charCodeAt(n);
  34698. }
  34699. Stream.call(this, bytes);
  34700. }
  34701. StringStream.prototype = Stream.prototype;
  34702. return StringStream;
  34703. })();
  34704. // super class for the decoding streams
  34705. var DecodeStream = (function DecodeStreamClosure() {
  34706. // Lots of DecodeStreams are created whose buffers are never used. For these
  34707. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  34708. // having special cases that would be required if we used |null| for an empty
  34709. // buffer.
  34710. var emptyBuffer = new Uint8Array(0);
  34711. function DecodeStream(maybeMinBufferLength) {
  34712. this.pos = 0;
  34713. this.bufferLength = 0;
  34714. this.eof = false;
  34715. this.buffer = emptyBuffer;
  34716. this.minBufferLength = 512;
  34717. if (maybeMinBufferLength) {
  34718. // Compute the first power of two that is as big as maybeMinBufferLength.
  34719. while (this.minBufferLength < maybeMinBufferLength) {
  34720. this.minBufferLength *= 2;
  34721. }
  34722. }
  34723. }
  34724. DecodeStream.prototype = {
  34725. get isEmpty() {
  34726. while (!this.eof && this.bufferLength === 0) {
  34727. this.readBlock();
  34728. }
  34729. return this.bufferLength === 0;
  34730. },
  34731. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  34732. var buffer = this.buffer;
  34733. if (requested <= buffer.byteLength) {
  34734. return buffer;
  34735. }
  34736. var size = this.minBufferLength;
  34737. while (size < requested) {
  34738. size *= 2;
  34739. }
  34740. var buffer2 = new Uint8Array(size);
  34741. buffer2.set(buffer);
  34742. return (this.buffer = buffer2);
  34743. },
  34744. getByte: function DecodeStream_getByte() {
  34745. var pos = this.pos;
  34746. while (this.bufferLength <= pos) {
  34747. if (this.eof) {
  34748. return -1;
  34749. }
  34750. this.readBlock();
  34751. }
  34752. return this.buffer[this.pos++];
  34753. },
  34754. getUint16: function DecodeStream_getUint16() {
  34755. var b0 = this.getByte();
  34756. var b1 = this.getByte();
  34757. return (b0 << 8) + b1;
  34758. },
  34759. getInt32: function DecodeStream_getInt32() {
  34760. var b0 = this.getByte();
  34761. var b1 = this.getByte();
  34762. var b2 = this.getByte();
  34763. var b3 = this.getByte();
  34764. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  34765. },
  34766. getBytes: function DecodeStream_getBytes(length) {
  34767. var end, pos = this.pos;
  34768. if (length) {
  34769. this.ensureBuffer(pos + length);
  34770. end = pos + length;
  34771. while (!this.eof && this.bufferLength < end) {
  34772. this.readBlock();
  34773. }
  34774. var bufEnd = this.bufferLength;
  34775. if (end > bufEnd) {
  34776. end = bufEnd;
  34777. }
  34778. } else {
  34779. while (!this.eof) {
  34780. this.readBlock();
  34781. }
  34782. end = this.bufferLength;
  34783. }
  34784. this.pos = end;
  34785. return this.buffer.subarray(pos, end);
  34786. },
  34787. peekByte: function DecodeStream_peekByte() {
  34788. var peekedByte = this.getByte();
  34789. this.pos--;
  34790. return peekedByte;
  34791. },
  34792. peekBytes: function DecodeStream_peekBytes(length) {
  34793. var bytes = this.getBytes(length);
  34794. this.pos -= bytes.length;
  34795. return bytes;
  34796. },
  34797. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  34798. var end = start + length;
  34799. while (this.bufferLength <= end && !this.eof) {
  34800. this.readBlock();
  34801. }
  34802. return new Stream(this.buffer, start, length, dict);
  34803. },
  34804. skip: function DecodeStream_skip(n) {
  34805. if (!n) {
  34806. n = 1;
  34807. }
  34808. this.pos += n;
  34809. },
  34810. reset: function DecodeStream_reset() {
  34811. this.pos = 0;
  34812. },
  34813. getBaseStreams: function DecodeStream_getBaseStreams() {
  34814. if (this.str && this.str.getBaseStreams) {
  34815. return this.str.getBaseStreams();
  34816. }
  34817. return [];
  34818. }
  34819. };
  34820. return DecodeStream;
  34821. })();
  34822. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  34823. function StreamsSequenceStream(streams) {
  34824. this.streams = streams;
  34825. DecodeStream.call(this, /* maybeLength = */ null);
  34826. }
  34827. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  34828. StreamsSequenceStream.prototype.readBlock =
  34829. function streamSequenceStreamReadBlock() {
  34830. var streams = this.streams;
  34831. if (streams.length === 0) {
  34832. this.eof = true;
  34833. return;
  34834. }
  34835. var stream = streams.shift();
  34836. var chunk = stream.getBytes();
  34837. var bufferLength = this.bufferLength;
  34838. var newLength = bufferLength + chunk.length;
  34839. var buffer = this.ensureBuffer(newLength);
  34840. buffer.set(chunk, bufferLength);
  34841. this.bufferLength = newLength;
  34842. };
  34843. StreamsSequenceStream.prototype.getBaseStreams =
  34844. function StreamsSequenceStream_getBaseStreams() {
  34845. var baseStreams = [];
  34846. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  34847. var stream = this.streams[i];
  34848. if (stream.getBaseStreams) {
  34849. Util.appendToArray(baseStreams, stream.getBaseStreams());
  34850. }
  34851. }
  34852. return baseStreams;
  34853. };
  34854. return StreamsSequenceStream;
  34855. })();
  34856. var FlateStream = (function FlateStreamClosure() {
  34857. var codeLenCodeMap = new Uint32Array([
  34858. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  34859. ]);
  34860. var lengthDecode = new Uint32Array([
  34861. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  34862. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  34863. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  34864. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  34865. ]);
  34866. var distDecode = new Uint32Array([
  34867. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  34868. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  34869. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  34870. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  34871. ]);
  34872. var fixedLitCodeTab = [new Uint32Array([
  34873. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  34874. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  34875. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  34876. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  34877. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  34878. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  34879. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  34880. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  34881. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  34882. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  34883. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  34884. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  34885. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  34886. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  34887. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  34888. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  34889. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  34890. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  34891. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  34892. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  34893. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  34894. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  34895. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  34896. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  34897. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  34898. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  34899. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  34900. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  34901. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  34902. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  34903. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  34904. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  34905. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  34906. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  34907. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  34908. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  34909. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  34910. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  34911. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  34912. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  34913. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  34914. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  34915. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  34916. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  34917. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  34918. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  34919. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  34920. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  34921. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  34922. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  34923. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  34924. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  34925. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  34926. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  34927. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  34928. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  34929. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  34930. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  34931. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  34932. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  34933. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  34934. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  34935. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  34936. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  34937. ]), 9];
  34938. var fixedDistCodeTab = [new Uint32Array([
  34939. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  34940. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  34941. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  34942. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  34943. ]), 5];
  34944. function FlateStream(str, maybeLength) {
  34945. this.str = str;
  34946. this.dict = str.dict;
  34947. var cmf = str.getByte();
  34948. var flg = str.getByte();
  34949. if (cmf === -1 || flg === -1) {
  34950. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  34951. }
  34952. if ((cmf & 0x0f) !== 0x08) {
  34953. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  34954. }
  34955. if ((((cmf << 8) + flg) % 31) !== 0) {
  34956. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  34957. }
  34958. if (flg & 0x20) {
  34959. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  34960. }
  34961. this.codeSize = 0;
  34962. this.codeBuf = 0;
  34963. DecodeStream.call(this, maybeLength);
  34964. }
  34965. FlateStream.prototype = Object.create(DecodeStream.prototype);
  34966. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  34967. var str = this.str;
  34968. var codeSize = this.codeSize;
  34969. var codeBuf = this.codeBuf;
  34970. var b;
  34971. while (codeSize < bits) {
  34972. if ((b = str.getByte()) === -1) {
  34973. error('Bad encoding in flate stream');
  34974. }
  34975. codeBuf |= b << codeSize;
  34976. codeSize += 8;
  34977. }
  34978. b = codeBuf & ((1 << bits) - 1);
  34979. this.codeBuf = codeBuf >> bits;
  34980. this.codeSize = codeSize -= bits;
  34981. return b;
  34982. };
  34983. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  34984. var str = this.str;
  34985. var codes = table[0];
  34986. var maxLen = table[1];
  34987. var codeSize = this.codeSize;
  34988. var codeBuf = this.codeBuf;
  34989. var b;
  34990. while (codeSize < maxLen) {
  34991. if ((b = str.getByte()) === -1) {
  34992. // premature end of stream. code might however still be valid.
  34993. // codeSize < codeLen check below guards against incomplete codeVal.
  34994. break;
  34995. }
  34996. codeBuf |= (b << codeSize);
  34997. codeSize += 8;
  34998. }
  34999. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35000. var codeLen = code >> 16;
  35001. var codeVal = code & 0xffff;
  35002. if (codeLen < 1 || codeSize < codeLen) {
  35003. error('Bad encoding in flate stream');
  35004. }
  35005. this.codeBuf = (codeBuf >> codeLen);
  35006. this.codeSize = (codeSize - codeLen);
  35007. return codeVal;
  35008. };
  35009. FlateStream.prototype.generateHuffmanTable =
  35010. function flateStreamGenerateHuffmanTable(lengths) {
  35011. var n = lengths.length;
  35012. // find max code length
  35013. var maxLen = 0;
  35014. var i;
  35015. for (i = 0; i < n; ++i) {
  35016. if (lengths[i] > maxLen) {
  35017. maxLen = lengths[i];
  35018. }
  35019. }
  35020. // build the table
  35021. var size = 1 << maxLen;
  35022. var codes = new Uint32Array(size);
  35023. for (var len = 1, code = 0, skip = 2;
  35024. len <= maxLen;
  35025. ++len, code <<= 1, skip <<= 1) {
  35026. for (var val = 0; val < n; ++val) {
  35027. if (lengths[val] === len) {
  35028. // bit-reverse the code
  35029. var code2 = 0;
  35030. var t = code;
  35031. for (i = 0; i < len; ++i) {
  35032. code2 = (code2 << 1) | (t & 1);
  35033. t >>= 1;
  35034. }
  35035. // fill the table entries
  35036. for (i = code2; i < size; i += skip) {
  35037. codes[i] = (len << 16) | val;
  35038. }
  35039. ++code;
  35040. }
  35041. }
  35042. }
  35043. return [codes, maxLen];
  35044. };
  35045. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35046. var buffer, len;
  35047. var str = this.str;
  35048. // read block header
  35049. var hdr = this.getBits(3);
  35050. if (hdr & 1) {
  35051. this.eof = true;
  35052. }
  35053. hdr >>= 1;
  35054. if (hdr === 0) { // uncompressed block
  35055. var b;
  35056. if ((b = str.getByte()) === -1) {
  35057. error('Bad block header in flate stream');
  35058. }
  35059. var blockLen = b;
  35060. if ((b = str.getByte()) === -1) {
  35061. error('Bad block header in flate stream');
  35062. }
  35063. blockLen |= (b << 8);
  35064. if ((b = str.getByte()) === -1) {
  35065. error('Bad block header in flate stream');
  35066. }
  35067. var check = b;
  35068. if ((b = str.getByte()) === -1) {
  35069. error('Bad block header in flate stream');
  35070. }
  35071. check |= (b << 8);
  35072. if (check !== (~blockLen & 0xffff) &&
  35073. (blockLen !== 0 || check !== 0)) {
  35074. // Ignoring error for bad "empty" block (see issue 1277)
  35075. error('Bad uncompressed block length in flate stream');
  35076. }
  35077. this.codeBuf = 0;
  35078. this.codeSize = 0;
  35079. var bufferLength = this.bufferLength;
  35080. buffer = this.ensureBuffer(bufferLength + blockLen);
  35081. var end = bufferLength + blockLen;
  35082. this.bufferLength = end;
  35083. if (blockLen === 0) {
  35084. if (str.peekByte() === -1) {
  35085. this.eof = true;
  35086. }
  35087. } else {
  35088. for (var n = bufferLength; n < end; ++n) {
  35089. if ((b = str.getByte()) === -1) {
  35090. this.eof = true;
  35091. break;
  35092. }
  35093. buffer[n] = b;
  35094. }
  35095. }
  35096. return;
  35097. }
  35098. var litCodeTable;
  35099. var distCodeTable;
  35100. if (hdr === 1) { // compressed block, fixed codes
  35101. litCodeTable = fixedLitCodeTab;
  35102. distCodeTable = fixedDistCodeTab;
  35103. } else if (hdr === 2) { // compressed block, dynamic codes
  35104. var numLitCodes = this.getBits(5) + 257;
  35105. var numDistCodes = this.getBits(5) + 1;
  35106. var numCodeLenCodes = this.getBits(4) + 4;
  35107. // build the code lengths code table
  35108. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35109. var i;
  35110. for (i = 0; i < numCodeLenCodes; ++i) {
  35111. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35112. }
  35113. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35114. // build the literal and distance code tables
  35115. len = 0;
  35116. i = 0;
  35117. var codes = numLitCodes + numDistCodes;
  35118. var codeLengths = new Uint8Array(codes);
  35119. var bitsLength, bitsOffset, what;
  35120. while (i < codes) {
  35121. var code = this.getCode(codeLenCodeTab);
  35122. if (code === 16) {
  35123. bitsLength = 2; bitsOffset = 3; what = len;
  35124. } else if (code === 17) {
  35125. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35126. } else if (code === 18) {
  35127. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35128. } else {
  35129. codeLengths[i++] = len = code;
  35130. continue;
  35131. }
  35132. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35133. while (repeatLength-- > 0) {
  35134. codeLengths[i++] = what;
  35135. }
  35136. }
  35137. litCodeTable =
  35138. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35139. distCodeTable =
  35140. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35141. } else {
  35142. error('Unknown block type in flate stream');
  35143. }
  35144. buffer = this.buffer;
  35145. var limit = buffer ? buffer.length : 0;
  35146. var pos = this.bufferLength;
  35147. while (true) {
  35148. var code1 = this.getCode(litCodeTable);
  35149. if (code1 < 256) {
  35150. if (pos + 1 >= limit) {
  35151. buffer = this.ensureBuffer(pos + 1);
  35152. limit = buffer.length;
  35153. }
  35154. buffer[pos++] = code1;
  35155. continue;
  35156. }
  35157. if (code1 === 256) {
  35158. this.bufferLength = pos;
  35159. return;
  35160. }
  35161. code1 -= 257;
  35162. code1 = lengthDecode[code1];
  35163. var code2 = code1 >> 16;
  35164. if (code2 > 0) {
  35165. code2 = this.getBits(code2);
  35166. }
  35167. len = (code1 & 0xffff) + code2;
  35168. code1 = this.getCode(distCodeTable);
  35169. code1 = distDecode[code1];
  35170. code2 = code1 >> 16;
  35171. if (code2 > 0) {
  35172. code2 = this.getBits(code2);
  35173. }
  35174. var dist = (code1 & 0xffff) + code2;
  35175. if (pos + len >= limit) {
  35176. buffer = this.ensureBuffer(pos + len);
  35177. limit = buffer.length;
  35178. }
  35179. for (var k = 0; k < len; ++k, ++pos) {
  35180. buffer[pos] = buffer[pos - dist];
  35181. }
  35182. }
  35183. };
  35184. return FlateStream;
  35185. })();
  35186. var PredictorStream = (function PredictorStreamClosure() {
  35187. function PredictorStream(str, maybeLength, params) {
  35188. var predictor = this.predictor = params.get('Predictor') || 1;
  35189. if (predictor <= 1) {
  35190. return str; // no prediction
  35191. }
  35192. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35193. error('Unsupported predictor: ' + predictor);
  35194. }
  35195. if (predictor === 2) {
  35196. this.readBlock = this.readBlockTiff;
  35197. } else {
  35198. this.readBlock = this.readBlockPng;
  35199. }
  35200. this.str = str;
  35201. this.dict = str.dict;
  35202. var colors = this.colors = params.get('Colors') || 1;
  35203. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35204. var columns = this.columns = params.get('Columns') || 1;
  35205. this.pixBytes = (colors * bits + 7) >> 3;
  35206. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35207. DecodeStream.call(this, maybeLength);
  35208. return this;
  35209. }
  35210. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35211. PredictorStream.prototype.readBlockTiff =
  35212. function predictorStreamReadBlockTiff() {
  35213. var rowBytes = this.rowBytes;
  35214. var bufferLength = this.bufferLength;
  35215. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35216. var bits = this.bits;
  35217. var colors = this.colors;
  35218. var rawBytes = this.str.getBytes(rowBytes);
  35219. this.eof = !rawBytes.length;
  35220. if (this.eof) {
  35221. return;
  35222. }
  35223. var inbuf = 0, outbuf = 0;
  35224. var inbits = 0, outbits = 0;
  35225. var pos = bufferLength;
  35226. var i;
  35227. if (bits === 1) {
  35228. for (i = 0; i < rowBytes; ++i) {
  35229. var c = rawBytes[i];
  35230. inbuf = (inbuf << 8) | c;
  35231. // bitwise addition is exclusive or
  35232. // first shift inbuf and then add
  35233. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35234. // truncate inbuf (assumes colors < 16)
  35235. inbuf &= 0xFFFF;
  35236. }
  35237. } else if (bits === 8) {
  35238. for (i = 0; i < colors; ++i) {
  35239. buffer[pos++] = rawBytes[i];
  35240. }
  35241. for (; i < rowBytes; ++i) {
  35242. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35243. pos++;
  35244. }
  35245. } else {
  35246. var compArray = new Uint8Array(colors + 1);
  35247. var bitMask = (1 << bits) - 1;
  35248. var j = 0, k = bufferLength;
  35249. var columns = this.columns;
  35250. for (i = 0; i < columns; ++i) {
  35251. for (var kk = 0; kk < colors; ++kk) {
  35252. if (inbits < bits) {
  35253. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35254. inbits += 8;
  35255. }
  35256. compArray[kk] = (compArray[kk] +
  35257. (inbuf >> (inbits - bits))) & bitMask;
  35258. inbits -= bits;
  35259. outbuf = (outbuf << bits) | compArray[kk];
  35260. outbits += bits;
  35261. if (outbits >= 8) {
  35262. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35263. outbits -= 8;
  35264. }
  35265. }
  35266. }
  35267. if (outbits > 0) {
  35268. buffer[k++] = (outbuf << (8 - outbits)) +
  35269. (inbuf & ((1 << (8 - outbits)) - 1));
  35270. }
  35271. }
  35272. this.bufferLength += rowBytes;
  35273. };
  35274. PredictorStream.prototype.readBlockPng =
  35275. function predictorStreamReadBlockPng() {
  35276. var rowBytes = this.rowBytes;
  35277. var pixBytes = this.pixBytes;
  35278. var predictor = this.str.getByte();
  35279. var rawBytes = this.str.getBytes(rowBytes);
  35280. this.eof = !rawBytes.length;
  35281. if (this.eof) {
  35282. return;
  35283. }
  35284. var bufferLength = this.bufferLength;
  35285. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35286. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35287. if (prevRow.length === 0) {
  35288. prevRow = new Uint8Array(rowBytes);
  35289. }
  35290. var i, j = bufferLength, up, c;
  35291. switch (predictor) {
  35292. case 0:
  35293. for (i = 0; i < rowBytes; ++i) {
  35294. buffer[j++] = rawBytes[i];
  35295. }
  35296. break;
  35297. case 1:
  35298. for (i = 0; i < pixBytes; ++i) {
  35299. buffer[j++] = rawBytes[i];
  35300. }
  35301. for (; i < rowBytes; ++i) {
  35302. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35303. j++;
  35304. }
  35305. break;
  35306. case 2:
  35307. for (i = 0; i < rowBytes; ++i) {
  35308. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35309. }
  35310. break;
  35311. case 3:
  35312. for (i = 0; i < pixBytes; ++i) {
  35313. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35314. }
  35315. for (; i < rowBytes; ++i) {
  35316. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35317. rawBytes[i]) & 0xFF;
  35318. j++;
  35319. }
  35320. break;
  35321. case 4:
  35322. // we need to save the up left pixels values. the simplest way
  35323. // is to create a new buffer
  35324. for (i = 0; i < pixBytes; ++i) {
  35325. up = prevRow[i];
  35326. c = rawBytes[i];
  35327. buffer[j++] = up + c;
  35328. }
  35329. for (; i < rowBytes; ++i) {
  35330. up = prevRow[i];
  35331. var upLeft = prevRow[i - pixBytes];
  35332. var left = buffer[j - pixBytes];
  35333. var p = left + up - upLeft;
  35334. var pa = p - left;
  35335. if (pa < 0) {
  35336. pa = -pa;
  35337. }
  35338. var pb = p - up;
  35339. if (pb < 0) {
  35340. pb = -pb;
  35341. }
  35342. var pc = p - upLeft;
  35343. if (pc < 0) {
  35344. pc = -pc;
  35345. }
  35346. c = rawBytes[i];
  35347. if (pa <= pb && pa <= pc) {
  35348. buffer[j++] = left + c;
  35349. } else if (pb <= pc) {
  35350. buffer[j++] = up + c;
  35351. } else {
  35352. buffer[j++] = upLeft + c;
  35353. }
  35354. }
  35355. break;
  35356. default:
  35357. error('Unsupported predictor: ' + predictor);
  35358. }
  35359. this.bufferLength += rowBytes;
  35360. };
  35361. return PredictorStream;
  35362. })();
  35363. /**
  35364. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35365. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35366. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35367. * a library to decode these images and the stream behaves like all the other
  35368. * DecodeStreams.
  35369. */
  35370. var JpegStream = (function JpegStreamClosure() {
  35371. function JpegStream(stream, maybeLength, dict, xref) {
  35372. // TODO: per poppler, some images may have 'junk' before that
  35373. // need to be removed
  35374. this.stream = stream;
  35375. this.maybeLength = maybeLength;
  35376. this.dict = dict;
  35377. DecodeStream.call(this, maybeLength);
  35378. }
  35379. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35380. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35381. get: function JpegStream_bytes() {
  35382. // If this.maybeLength is null, we'll get the entire stream.
  35383. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35384. },
  35385. configurable: true
  35386. });
  35387. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35388. if (this.bufferLength) {
  35389. return;
  35390. }
  35391. try {
  35392. var jpegImage = new JpegImage();
  35393. // checking if values needs to be transformed before conversion
  35394. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35395. var decodeArr = this.dict.get('Decode');
  35396. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35397. var decodeArrLength = decodeArr.length;
  35398. var transform = new Int32Array(decodeArrLength);
  35399. var transformNeeded = false;
  35400. var maxValue = (1 << bitsPerComponent) - 1;
  35401. for (var i = 0; i < decodeArrLength; i += 2) {
  35402. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35403. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35404. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35405. transformNeeded = true;
  35406. }
  35407. }
  35408. if (transformNeeded) {
  35409. jpegImage.decodeTransform = transform;
  35410. }
  35411. }
  35412. jpegImage.parse(this.bytes);
  35413. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35414. this.forceRGB);
  35415. this.buffer = data;
  35416. this.bufferLength = data.length;
  35417. this.eof = true;
  35418. } catch (e) {
  35419. error('JPEG error: ' + e);
  35420. }
  35421. };
  35422. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35423. this.ensureBuffer();
  35424. return this.buffer;
  35425. };
  35426. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35427. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35428. };
  35429. /**
  35430. * Checks if the image can be decoded and displayed by the browser without any
  35431. * further processing such as color space conversions.
  35432. */
  35433. JpegStream.prototype.isNativelySupported =
  35434. function JpegStream_isNativelySupported(xref, res) {
  35435. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35436. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35437. };
  35438. /**
  35439. * Checks if the image can be decoded by the browser.
  35440. */
  35441. JpegStream.prototype.isNativelyDecodable =
  35442. function JpegStream_isNativelyDecodable(xref, res) {
  35443. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35444. var numComps = cs.numComps;
  35445. return numComps === 1 || numComps === 3;
  35446. };
  35447. return JpegStream;
  35448. })();
  35449. /**
  35450. * For JPEG 2000's we use a library to decode these images and
  35451. * the stream behaves like all the other DecodeStreams.
  35452. */
  35453. var JpxStream = (function JpxStreamClosure() {
  35454. function JpxStream(stream, maybeLength, dict) {
  35455. this.stream = stream;
  35456. this.maybeLength = maybeLength;
  35457. this.dict = dict;
  35458. DecodeStream.call(this, maybeLength);
  35459. }
  35460. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35461. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35462. get: function JpxStream_bytes() {
  35463. // If this.maybeLength is null, we'll get the entire stream.
  35464. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35465. },
  35466. configurable: true
  35467. });
  35468. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35469. if (this.bufferLength) {
  35470. return;
  35471. }
  35472. var jpxImage = new JpxImage();
  35473. jpxImage.parse(this.bytes);
  35474. var width = jpxImage.width;
  35475. var height = jpxImage.height;
  35476. var componentsCount = jpxImage.componentsCount;
  35477. var tileCount = jpxImage.tiles.length;
  35478. if (tileCount === 1) {
  35479. this.buffer = jpxImage.tiles[0].items;
  35480. } else {
  35481. var data = new Uint8Array(width * height * componentsCount);
  35482. for (var k = 0; k < tileCount; k++) {
  35483. var tileComponents = jpxImage.tiles[k];
  35484. var tileWidth = tileComponents.width;
  35485. var tileHeight = tileComponents.height;
  35486. var tileLeft = tileComponents.left;
  35487. var tileTop = tileComponents.top;
  35488. var src = tileComponents.items;
  35489. var srcPosition = 0;
  35490. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  35491. var imgRowSize = width * componentsCount;
  35492. var tileRowSize = tileWidth * componentsCount;
  35493. for (var j = 0; j < tileHeight; j++) {
  35494. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  35495. data.set(rowBytes, dataPosition);
  35496. srcPosition += tileRowSize;
  35497. dataPosition += imgRowSize;
  35498. }
  35499. }
  35500. this.buffer = data;
  35501. }
  35502. this.bufferLength = this.buffer.length;
  35503. this.eof = true;
  35504. };
  35505. return JpxStream;
  35506. })();
  35507. /**
  35508. * For JBIG2's we use a library to decode these images and
  35509. * the stream behaves like all the other DecodeStreams.
  35510. */
  35511. var Jbig2Stream = (function Jbig2StreamClosure() {
  35512. function Jbig2Stream(stream, maybeLength, dict) {
  35513. this.stream = stream;
  35514. this.maybeLength = maybeLength;
  35515. this.dict = dict;
  35516. DecodeStream.call(this, maybeLength);
  35517. }
  35518. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  35519. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  35520. get: function Jbig2Stream_bytes() {
  35521. // If this.maybeLength is null, we'll get the entire stream.
  35522. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35523. },
  35524. configurable: true
  35525. });
  35526. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  35527. if (this.bufferLength) {
  35528. return;
  35529. }
  35530. var jbig2Image = new Jbig2Image();
  35531. var chunks = [], xref = this.dict.xref;
  35532. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  35533. // According to the PDF specification, DecodeParms can be either
  35534. // a dictionary, or an array whose elements are dictionaries.
  35535. if (isArray(decodeParams)) {
  35536. if (decodeParams.length > 1) {
  35537. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  35538. 'not supported.');
  35539. }
  35540. decodeParams = xref.fetchIfRef(decodeParams[0]);
  35541. }
  35542. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  35543. var globalsStream = decodeParams.get('JBIG2Globals');
  35544. var globals = globalsStream.getBytes();
  35545. chunks.push({data: globals, start: 0, end: globals.length});
  35546. }
  35547. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  35548. var data = jbig2Image.parseChunks(chunks);
  35549. var dataLength = data.length;
  35550. // JBIG2 had black as 1 and white as 0, inverting the colors
  35551. for (var i = 0; i < dataLength; i++) {
  35552. data[i] ^= 0xFF;
  35553. }
  35554. this.buffer = data;
  35555. this.bufferLength = dataLength;
  35556. this.eof = true;
  35557. };
  35558. return Jbig2Stream;
  35559. })();
  35560. var DecryptStream = (function DecryptStreamClosure() {
  35561. function DecryptStream(str, maybeLength, decrypt) {
  35562. this.str = str;
  35563. this.dict = str.dict;
  35564. this.decrypt = decrypt;
  35565. this.nextChunk = null;
  35566. this.initialized = false;
  35567. DecodeStream.call(this, maybeLength);
  35568. }
  35569. var chunkSize = 512;
  35570. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  35571. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  35572. var chunk;
  35573. if (this.initialized) {
  35574. chunk = this.nextChunk;
  35575. } else {
  35576. chunk = this.str.getBytes(chunkSize);
  35577. this.initialized = true;
  35578. }
  35579. if (!chunk || chunk.length === 0) {
  35580. this.eof = true;
  35581. return;
  35582. }
  35583. this.nextChunk = this.str.getBytes(chunkSize);
  35584. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  35585. var decrypt = this.decrypt;
  35586. chunk = decrypt(chunk, !hasMoreData);
  35587. var bufferLength = this.bufferLength;
  35588. var i, n = chunk.length;
  35589. var buffer = this.ensureBuffer(bufferLength + n);
  35590. for (i = 0; i < n; i++) {
  35591. buffer[bufferLength++] = chunk[i];
  35592. }
  35593. this.bufferLength = bufferLength;
  35594. };
  35595. return DecryptStream;
  35596. })();
  35597. var Ascii85Stream = (function Ascii85StreamClosure() {
  35598. function Ascii85Stream(str, maybeLength) {
  35599. this.str = str;
  35600. this.dict = str.dict;
  35601. this.input = new Uint8Array(5);
  35602. // Most streams increase in size when decoded, but Ascii85 streams
  35603. // typically shrink by ~20%.
  35604. if (maybeLength) {
  35605. maybeLength = 0.8 * maybeLength;
  35606. }
  35607. DecodeStream.call(this, maybeLength);
  35608. }
  35609. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  35610. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  35611. var TILDA_CHAR = 0x7E; // '~'
  35612. var Z_LOWER_CHAR = 0x7A; // 'z'
  35613. var EOF = -1;
  35614. var str = this.str;
  35615. var c = str.getByte();
  35616. while (Lexer.isSpace(c)) {
  35617. c = str.getByte();
  35618. }
  35619. if (c === EOF || c === TILDA_CHAR) {
  35620. this.eof = true;
  35621. return;
  35622. }
  35623. var bufferLength = this.bufferLength, buffer;
  35624. var i;
  35625. // special code for z
  35626. if (c === Z_LOWER_CHAR) {
  35627. buffer = this.ensureBuffer(bufferLength + 4);
  35628. for (i = 0; i < 4; ++i) {
  35629. buffer[bufferLength + i] = 0;
  35630. }
  35631. this.bufferLength += 4;
  35632. } else {
  35633. var input = this.input;
  35634. input[0] = c;
  35635. for (i = 1; i < 5; ++i) {
  35636. c = str.getByte();
  35637. while (Lexer.isSpace(c)) {
  35638. c = str.getByte();
  35639. }
  35640. input[i] = c;
  35641. if (c === EOF || c === TILDA_CHAR) {
  35642. break;
  35643. }
  35644. }
  35645. buffer = this.ensureBuffer(bufferLength + i - 1);
  35646. this.bufferLength += i - 1;
  35647. // partial ending;
  35648. if (i < 5) {
  35649. for (; i < 5; ++i) {
  35650. input[i] = 0x21 + 84;
  35651. }
  35652. this.eof = true;
  35653. }
  35654. var t = 0;
  35655. for (i = 0; i < 5; ++i) {
  35656. t = t * 85 + (input[i] - 0x21);
  35657. }
  35658. for (i = 3; i >= 0; --i) {
  35659. buffer[bufferLength + i] = t & 0xFF;
  35660. t >>= 8;
  35661. }
  35662. }
  35663. };
  35664. return Ascii85Stream;
  35665. })();
  35666. var AsciiHexStream = (function AsciiHexStreamClosure() {
  35667. function AsciiHexStream(str, maybeLength) {
  35668. this.str = str;
  35669. this.dict = str.dict;
  35670. this.firstDigit = -1;
  35671. // Most streams increase in size when decoded, but AsciiHex streams shrink
  35672. // by 50%.
  35673. if (maybeLength) {
  35674. maybeLength = 0.5 * maybeLength;
  35675. }
  35676. DecodeStream.call(this, maybeLength);
  35677. }
  35678. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  35679. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  35680. var UPSTREAM_BLOCK_SIZE = 8000;
  35681. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  35682. if (!bytes.length) {
  35683. this.eof = true;
  35684. return;
  35685. }
  35686. var maxDecodeLength = (bytes.length + 1) >> 1;
  35687. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  35688. var bufferLength = this.bufferLength;
  35689. var firstDigit = this.firstDigit;
  35690. for (var i = 0, ii = bytes.length; i < ii; i++) {
  35691. var ch = bytes[i], digit;
  35692. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  35693. digit = ch & 0x0F;
  35694. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  35695. // 'A'-'Z', 'a'-'z'
  35696. digit = (ch & 0x0F) + 9;
  35697. } else if (ch === 0x3E) { // '>'
  35698. this.eof = true;
  35699. break;
  35700. } else { // probably whitespace
  35701. continue; // ignoring
  35702. }
  35703. if (firstDigit < 0) {
  35704. firstDigit = digit;
  35705. } else {
  35706. buffer[bufferLength++] = (firstDigit << 4) | digit;
  35707. firstDigit = -1;
  35708. }
  35709. }
  35710. if (firstDigit >= 0 && this.eof) {
  35711. // incomplete byte
  35712. buffer[bufferLength++] = (firstDigit << 4);
  35713. firstDigit = -1;
  35714. }
  35715. this.firstDigit = firstDigit;
  35716. this.bufferLength = bufferLength;
  35717. };
  35718. return AsciiHexStream;
  35719. })();
  35720. var RunLengthStream = (function RunLengthStreamClosure() {
  35721. function RunLengthStream(str, maybeLength) {
  35722. this.str = str;
  35723. this.dict = str.dict;
  35724. DecodeStream.call(this, maybeLength);
  35725. }
  35726. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  35727. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  35728. // The repeatHeader has following format. The first byte defines type of run
  35729. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  35730. // (in addition to the second byte from the header), n = 129 through 255 -
  35731. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  35732. var repeatHeader = this.str.getBytes(2);
  35733. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  35734. this.eof = true;
  35735. return;
  35736. }
  35737. var buffer;
  35738. var bufferLength = this.bufferLength;
  35739. var n = repeatHeader[0];
  35740. if (n < 128) {
  35741. // copy n bytes
  35742. buffer = this.ensureBuffer(bufferLength + n + 1);
  35743. buffer[bufferLength++] = repeatHeader[1];
  35744. if (n > 0) {
  35745. var source = this.str.getBytes(n);
  35746. buffer.set(source, bufferLength);
  35747. bufferLength += n;
  35748. }
  35749. } else {
  35750. n = 257 - n;
  35751. var b = repeatHeader[1];
  35752. buffer = this.ensureBuffer(bufferLength + n + 1);
  35753. for (var i = 0; i < n; i++) {
  35754. buffer[bufferLength++] = b;
  35755. }
  35756. }
  35757. this.bufferLength = bufferLength;
  35758. };
  35759. return RunLengthStream;
  35760. })();
  35761. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  35762. var ccittEOL = -2;
  35763. var twoDimPass = 0;
  35764. var twoDimHoriz = 1;
  35765. var twoDimVert0 = 2;
  35766. var twoDimVertR1 = 3;
  35767. var twoDimVertL1 = 4;
  35768. var twoDimVertR2 = 5;
  35769. var twoDimVertL2 = 6;
  35770. var twoDimVertR3 = 7;
  35771. var twoDimVertL3 = 8;
  35772. var twoDimTable = [
  35773. [-1, -1], [-1, -1], // 000000x
  35774. [7, twoDimVertL3], // 0000010
  35775. [7, twoDimVertR3], // 0000011
  35776. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  35777. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  35778. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  35779. [4, twoDimPass], [4, twoDimPass],
  35780. [4, twoDimPass], [4, twoDimPass],
  35781. [4, twoDimPass], [4, twoDimPass],
  35782. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  35783. [3, twoDimHoriz], [3, twoDimHoriz],
  35784. [3, twoDimHoriz], [3, twoDimHoriz],
  35785. [3, twoDimHoriz], [3, twoDimHoriz],
  35786. [3, twoDimHoriz], [3, twoDimHoriz],
  35787. [3, twoDimHoriz], [3, twoDimHoriz],
  35788. [3, twoDimHoriz], [3, twoDimHoriz],
  35789. [3, twoDimHoriz], [3, twoDimHoriz],
  35790. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  35791. [3, twoDimVertL1], [3, twoDimVertL1],
  35792. [3, twoDimVertL1], [3, twoDimVertL1],
  35793. [3, twoDimVertL1], [3, twoDimVertL1],
  35794. [3, twoDimVertL1], [3, twoDimVertL1],
  35795. [3, twoDimVertL1], [3, twoDimVertL1],
  35796. [3, twoDimVertL1], [3, twoDimVertL1],
  35797. [3, twoDimVertL1], [3, twoDimVertL1],
  35798. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  35799. [3, twoDimVertR1], [3, twoDimVertR1],
  35800. [3, twoDimVertR1], [3, twoDimVertR1],
  35801. [3, twoDimVertR1], [3, twoDimVertR1],
  35802. [3, twoDimVertR1], [3, twoDimVertR1],
  35803. [3, twoDimVertR1], [3, twoDimVertR1],
  35804. [3, twoDimVertR1], [3, twoDimVertR1],
  35805. [3, twoDimVertR1], [3, twoDimVertR1],
  35806. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  35807. [1, twoDimVert0], [1, twoDimVert0],
  35808. [1, twoDimVert0], [1, twoDimVert0],
  35809. [1, twoDimVert0], [1, twoDimVert0],
  35810. [1, twoDimVert0], [1, twoDimVert0],
  35811. [1, twoDimVert0], [1, twoDimVert0],
  35812. [1, twoDimVert0], [1, twoDimVert0],
  35813. [1, twoDimVert0], [1, twoDimVert0],
  35814. [1, twoDimVert0], [1, twoDimVert0],
  35815. [1, twoDimVert0], [1, twoDimVert0],
  35816. [1, twoDimVert0], [1, twoDimVert0],
  35817. [1, twoDimVert0], [1, twoDimVert0],
  35818. [1, twoDimVert0], [1, twoDimVert0],
  35819. [1, twoDimVert0], [1, twoDimVert0],
  35820. [1, twoDimVert0], [1, twoDimVert0],
  35821. [1, twoDimVert0], [1, twoDimVert0],
  35822. [1, twoDimVert0], [1, twoDimVert0],
  35823. [1, twoDimVert0], [1, twoDimVert0],
  35824. [1, twoDimVert0], [1, twoDimVert0],
  35825. [1, twoDimVert0], [1, twoDimVert0],
  35826. [1, twoDimVert0], [1, twoDimVert0],
  35827. [1, twoDimVert0], [1, twoDimVert0],
  35828. [1, twoDimVert0], [1, twoDimVert0],
  35829. [1, twoDimVert0], [1, twoDimVert0],
  35830. [1, twoDimVert0], [1, twoDimVert0],
  35831. [1, twoDimVert0], [1, twoDimVert0],
  35832. [1, twoDimVert0], [1, twoDimVert0],
  35833. [1, twoDimVert0], [1, twoDimVert0],
  35834. [1, twoDimVert0], [1, twoDimVert0],
  35835. [1, twoDimVert0], [1, twoDimVert0],
  35836. [1, twoDimVert0], [1, twoDimVert0],
  35837. [1, twoDimVert0], [1, twoDimVert0]
  35838. ];
  35839. var whiteTable1 = [
  35840. [-1, -1], // 00000
  35841. [12, ccittEOL], // 00001
  35842. [-1, -1], [-1, -1], // 0001x
  35843. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  35844. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  35845. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  35846. [11, 1792], [11, 1792], // 1000x
  35847. [12, 1984], // 10010
  35848. [12, 2048], // 10011
  35849. [12, 2112], // 10100
  35850. [12, 2176], // 10101
  35851. [12, 2240], // 10110
  35852. [12, 2304], // 10111
  35853. [11, 1856], [11, 1856], // 1100x
  35854. [11, 1920], [11, 1920], // 1101x
  35855. [12, 2368], // 11100
  35856. [12, 2432], // 11101
  35857. [12, 2496], // 11110
  35858. [12, 2560] // 11111
  35859. ];
  35860. var whiteTable2 = [
  35861. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  35862. [8, 29], [8, 29], // 00000010x
  35863. [8, 30], [8, 30], // 00000011x
  35864. [8, 45], [8, 45], // 00000100x
  35865. [8, 46], [8, 46], // 00000101x
  35866. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  35867. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  35868. [8, 47], [8, 47], // 00001010x
  35869. [8, 48], [8, 48], // 00001011x
  35870. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  35871. [6, 13], [6, 13], [6, 13], [6, 13],
  35872. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  35873. [8, 33], [8, 33], // 00010010x
  35874. [8, 34], [8, 34], // 00010011x
  35875. [8, 35], [8, 35], // 00010100x
  35876. [8, 36], [8, 36], // 00010101x
  35877. [8, 37], [8, 37], // 00010110x
  35878. [8, 38], [8, 38], // 00010111x
  35879. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  35880. [8, 31], [8, 31], // 00011010x
  35881. [8, 32], [8, 32], // 00011011x
  35882. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  35883. [6, 1], [6, 1], [6, 1], [6, 1],
  35884. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  35885. [6, 12], [6, 12], [6, 12], [6, 12],
  35886. [8, 53], [8, 53], // 00100100x
  35887. [8, 54], [8, 54], // 00100101x
  35888. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  35889. [8, 39], [8, 39], // 00101000x
  35890. [8, 40], [8, 40], // 00101001x
  35891. [8, 41], [8, 41], // 00101010x
  35892. [8, 42], [8, 42], // 00101011x
  35893. [8, 43], [8, 43], // 00101100x
  35894. [8, 44], [8, 44], // 00101101x
  35895. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  35896. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  35897. [8, 61], [8, 61], // 00110010x
  35898. [8, 62], [8, 62], // 00110011x
  35899. [8, 63], [8, 63], // 00110100x
  35900. [8, 0], [8, 0], // 00110101x
  35901. [8, 320], [8, 320], // 00110110x
  35902. [8, 384], [8, 384], // 00110111x
  35903. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  35904. [5, 10], [5, 10], [5, 10], [5, 10],
  35905. [5, 10], [5, 10], [5, 10], [5, 10],
  35906. [5, 10], [5, 10], [5, 10], [5, 10],
  35907. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  35908. [5, 11], [5, 11], [5, 11], [5, 11],
  35909. [5, 11], [5, 11], [5, 11], [5, 11],
  35910. [5, 11], [5, 11], [5, 11], [5, 11],
  35911. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  35912. [8, 59], [8, 59], // 01001010x
  35913. [8, 60], [8, 60], // 01001011x
  35914. [9, 1472], // 010011000
  35915. [9, 1536], // 010011001
  35916. [9, 1600], // 010011010
  35917. [9, 1728], // 010011011
  35918. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  35919. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  35920. [8, 49], [8, 49], // 01010010x
  35921. [8, 50], [8, 50], // 01010011x
  35922. [8, 51], [8, 51], // 01010100x
  35923. [8, 52], [8, 52], // 01010101x
  35924. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  35925. [8, 55], [8, 55], // 01011000x
  35926. [8, 56], [8, 56], // 01011001x
  35927. [8, 57], [8, 57], // 01011010x
  35928. [8, 58], [8, 58], // 01011011x
  35929. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  35930. [6, 192], [6, 192], [6, 192], [6, 192],
  35931. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  35932. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  35933. [8, 448], [8, 448], // 01100100x
  35934. [8, 512], [8, 512], // 01100101x
  35935. [9, 704], // 011001100
  35936. [9, 768], // 011001101
  35937. [8, 640], [8, 640], // 01100111x
  35938. [8, 576], [8, 576], // 01101000x
  35939. [9, 832], // 011010010
  35940. [9, 896], // 011010011
  35941. [9, 960], // 011010100
  35942. [9, 1024], // 011010101
  35943. [9, 1088], // 011010110
  35944. [9, 1152], // 011010111
  35945. [9, 1216], // 011011000
  35946. [9, 1280], // 011011001
  35947. [9, 1344], // 011011010
  35948. [9, 1408], // 011011011
  35949. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  35950. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  35951. [4, 2], [4, 2], [4, 2], [4, 2],
  35952. [4, 2], [4, 2], [4, 2], [4, 2],
  35953. [4, 2], [4, 2], [4, 2], [4, 2],
  35954. [4, 2], [4, 2], [4, 2], [4, 2],
  35955. [4, 2], [4, 2], [4, 2], [4, 2],
  35956. [4, 2], [4, 2], [4, 2], [4, 2],
  35957. [4, 2], [4, 2], [4, 2], [4, 2],
  35958. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  35959. [4, 3], [4, 3], [4, 3], [4, 3],
  35960. [4, 3], [4, 3], [4, 3], [4, 3],
  35961. [4, 3], [4, 3], [4, 3], [4, 3],
  35962. [4, 3], [4, 3], [4, 3], [4, 3],
  35963. [4, 3], [4, 3], [4, 3], [4, 3],
  35964. [4, 3], [4, 3], [4, 3], [4, 3],
  35965. [4, 3], [4, 3], [4, 3], [4, 3],
  35966. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  35967. [5, 128], [5, 128], [5, 128], [5, 128],
  35968. [5, 128], [5, 128], [5, 128], [5, 128],
  35969. [5, 128], [5, 128], [5, 128], [5, 128],
  35970. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  35971. [5, 8], [5, 8], [5, 8], [5, 8],
  35972. [5, 8], [5, 8], [5, 8], [5, 8],
  35973. [5, 8], [5, 8], [5, 8], [5, 8],
  35974. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  35975. [5, 9], [5, 9], [5, 9], [5, 9],
  35976. [5, 9], [5, 9], [5, 9], [5, 9],
  35977. [5, 9], [5, 9], [5, 9], [5, 9],
  35978. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  35979. [6, 16], [6, 16], [6, 16], [6, 16],
  35980. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  35981. [6, 17], [6, 17], [6, 17], [6, 17],
  35982. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  35983. [4, 4], [4, 4], [4, 4], [4, 4],
  35984. [4, 4], [4, 4], [4, 4], [4, 4],
  35985. [4, 4], [4, 4], [4, 4], [4, 4],
  35986. [4, 4], [4, 4], [4, 4], [4, 4],
  35987. [4, 4], [4, 4], [4, 4], [4, 4],
  35988. [4, 4], [4, 4], [4, 4], [4, 4],
  35989. [4, 4], [4, 4], [4, 4], [4, 4],
  35990. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  35991. [4, 5], [4, 5], [4, 5], [4, 5],
  35992. [4, 5], [4, 5], [4, 5], [4, 5],
  35993. [4, 5], [4, 5], [4, 5], [4, 5],
  35994. [4, 5], [4, 5], [4, 5], [4, 5],
  35995. [4, 5], [4, 5], [4, 5], [4, 5],
  35996. [4, 5], [4, 5], [4, 5], [4, 5],
  35997. [4, 5], [4, 5], [4, 5], [4, 5],
  35998. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  35999. [6, 14], [6, 14], [6, 14], [6, 14],
  36000. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36001. [6, 15], [6, 15], [6, 15], [6, 15],
  36002. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36003. [5, 64], [5, 64], [5, 64], [5, 64],
  36004. [5, 64], [5, 64], [5, 64], [5, 64],
  36005. [5, 64], [5, 64], [5, 64], [5, 64],
  36006. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36007. [4, 6], [4, 6], [4, 6], [4, 6],
  36008. [4, 6], [4, 6], [4, 6], [4, 6],
  36009. [4, 6], [4, 6], [4, 6], [4, 6],
  36010. [4, 6], [4, 6], [4, 6], [4, 6],
  36011. [4, 6], [4, 6], [4, 6], [4, 6],
  36012. [4, 6], [4, 6], [4, 6], [4, 6],
  36013. [4, 6], [4, 6], [4, 6], [4, 6],
  36014. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36015. [4, 7], [4, 7], [4, 7], [4, 7],
  36016. [4, 7], [4, 7], [4, 7], [4, 7],
  36017. [4, 7], [4, 7], [4, 7], [4, 7],
  36018. [4, 7], [4, 7], [4, 7], [4, 7],
  36019. [4, 7], [4, 7], [4, 7], [4, 7],
  36020. [4, 7], [4, 7], [4, 7], [4, 7],
  36021. [4, 7], [4, 7], [4, 7], [4, 7]
  36022. ];
  36023. var blackTable1 = [
  36024. [-1, -1], [-1, -1], // 000000000000x
  36025. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36026. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36027. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36028. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36029. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36030. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36031. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36032. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36033. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36034. [12, 1984], [12, 1984], // 000000010010x
  36035. [12, 2048], [12, 2048], // 000000010011x
  36036. [12, 2112], [12, 2112], // 000000010100x
  36037. [12, 2176], [12, 2176], // 000000010101x
  36038. [12, 2240], [12, 2240], // 000000010110x
  36039. [12, 2304], [12, 2304], // 000000010111x
  36040. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36041. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36042. [12, 2368], [12, 2368], // 000000011100x
  36043. [12, 2432], [12, 2432], // 000000011101x
  36044. [12, 2496], [12, 2496], // 000000011110x
  36045. [12, 2560], [12, 2560], // 000000011111x
  36046. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36047. [10, 18], [10, 18], [10, 18], [10, 18],
  36048. [12, 52], [12, 52], // 000000100100x
  36049. [13, 640], // 0000001001010
  36050. [13, 704], // 0000001001011
  36051. [13, 768], // 0000001001100
  36052. [13, 832], // 0000001001101
  36053. [12, 55], [12, 55], // 000000100111x
  36054. [12, 56], [12, 56], // 000000101000x
  36055. [13, 1280], // 0000001010010
  36056. [13, 1344], // 0000001010011
  36057. [13, 1408], // 0000001010100
  36058. [13, 1472], // 0000001010101
  36059. [12, 59], [12, 59], // 000000101011x
  36060. [12, 60], [12, 60], // 000000101100x
  36061. [13, 1536], // 0000001011010
  36062. [13, 1600], // 0000001011011
  36063. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36064. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36065. [13, 1664], // 0000001100100
  36066. [13, 1728], // 0000001100101
  36067. [12, 320], [12, 320], // 000000110011x
  36068. [12, 384], [12, 384], // 000000110100x
  36069. [12, 448], [12, 448], // 000000110101x
  36070. [13, 512], // 0000001101100
  36071. [13, 576], // 0000001101101
  36072. [12, 53], [12, 53], // 000000110111x
  36073. [12, 54], [12, 54], // 000000111000x
  36074. [13, 896], // 0000001110010
  36075. [13, 960], // 0000001110011
  36076. [13, 1024], // 0000001110100
  36077. [13, 1088], // 0000001110101
  36078. [13, 1152], // 0000001110110
  36079. [13, 1216], // 0000001110111
  36080. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36081. [10, 64], [10, 64], [10, 64], [10, 64]
  36082. ];
  36083. var blackTable2 = [
  36084. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36085. [8, 13], [8, 13], [8, 13], [8, 13],
  36086. [8, 13], [8, 13], [8, 13], [8, 13],
  36087. [8, 13], [8, 13], [8, 13], [8, 13],
  36088. [11, 23], [11, 23], // 00000101000x
  36089. [12, 50], // 000001010010
  36090. [12, 51], // 000001010011
  36091. [12, 44], // 000001010100
  36092. [12, 45], // 000001010101
  36093. [12, 46], // 000001010110
  36094. [12, 47], // 000001010111
  36095. [12, 57], // 000001011000
  36096. [12, 58], // 000001011001
  36097. [12, 61], // 000001011010
  36098. [12, 256], // 000001011011
  36099. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36100. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36101. [12, 48], // 000001100100
  36102. [12, 49], // 000001100101
  36103. [12, 62], // 000001100110
  36104. [12, 63], // 000001100111
  36105. [12, 30], // 000001101000
  36106. [12, 31], // 000001101001
  36107. [12, 32], // 000001101010
  36108. [12, 33], // 000001101011
  36109. [12, 40], // 000001101100
  36110. [12, 41], // 000001101101
  36111. [11, 22], [11, 22], // 00000110111x
  36112. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36113. [8, 14], [8, 14], [8, 14], [8, 14],
  36114. [8, 14], [8, 14], [8, 14], [8, 14],
  36115. [8, 14], [8, 14], [8, 14], [8, 14],
  36116. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36117. [7, 10], [7, 10], [7, 10], [7, 10],
  36118. [7, 10], [7, 10], [7, 10], [7, 10],
  36119. [7, 10], [7, 10], [7, 10], [7, 10],
  36120. [7, 10], [7, 10], [7, 10], [7, 10],
  36121. [7, 10], [7, 10], [7, 10], [7, 10],
  36122. [7, 10], [7, 10], [7, 10], [7, 10],
  36123. [7, 10], [7, 10], [7, 10], [7, 10],
  36124. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36125. [7, 11], [7, 11], [7, 11], [7, 11],
  36126. [7, 11], [7, 11], [7, 11], [7, 11],
  36127. [7, 11], [7, 11], [7, 11], [7, 11],
  36128. [7, 11], [7, 11], [7, 11], [7, 11],
  36129. [7, 11], [7, 11], [7, 11], [7, 11],
  36130. [7, 11], [7, 11], [7, 11], [7, 11],
  36131. [7, 11], [7, 11], [7, 11], [7, 11],
  36132. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36133. [9, 15], [9, 15], [9, 15], [9, 15],
  36134. [12, 128], // 000011001000
  36135. [12, 192], // 000011001001
  36136. [12, 26], // 000011001010
  36137. [12, 27], // 000011001011
  36138. [12, 28], // 000011001100
  36139. [12, 29], // 000011001101
  36140. [11, 19], [11, 19], // 00001100111x
  36141. [11, 20], [11, 20], // 00001101000x
  36142. [12, 34], // 000011010010
  36143. [12, 35], // 000011010011
  36144. [12, 36], // 000011010100
  36145. [12, 37], // 000011010101
  36146. [12, 38], // 000011010110
  36147. [12, 39], // 000011010111
  36148. [11, 21], [11, 21], // 00001101100x
  36149. [12, 42], // 000011011010
  36150. [12, 43], // 000011011011
  36151. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36152. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36153. [7, 12], [7, 12], [7, 12], [7, 12],
  36154. [7, 12], [7, 12], [7, 12], [7, 12],
  36155. [7, 12], [7, 12], [7, 12], [7, 12],
  36156. [7, 12], [7, 12], [7, 12], [7, 12],
  36157. [7, 12], [7, 12], [7, 12], [7, 12],
  36158. [7, 12], [7, 12], [7, 12], [7, 12],
  36159. [7, 12], [7, 12], [7, 12], [7, 12]
  36160. ];
  36161. var blackTable3 = [
  36162. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36163. [6, 9], // 000100
  36164. [6, 8], // 000101
  36165. [5, 7], [5, 7], // 00011x
  36166. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36167. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36168. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36169. [3, 1], [3, 1], [3, 1], [3, 1],
  36170. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36171. [3, 4], [3, 4], [3, 4], [3, 4],
  36172. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36173. [2, 3], [2, 3], [2, 3], [2, 3],
  36174. [2, 3], [2, 3], [2, 3], [2, 3],
  36175. [2, 3], [2, 3], [2, 3], [2, 3],
  36176. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36177. [2, 2], [2, 2], [2, 2], [2, 2],
  36178. [2, 2], [2, 2], [2, 2], [2, 2],
  36179. [2, 2], [2, 2], [2, 2], [2, 2]
  36180. ];
  36181. function CCITTFaxStream(str, maybeLength, params) {
  36182. this.str = str;
  36183. this.dict = str.dict;
  36184. params = params || Dict.empty;
  36185. this.encoding = params.get('K') || 0;
  36186. this.eoline = params.get('EndOfLine') || false;
  36187. this.byteAlign = params.get('EncodedByteAlign') || false;
  36188. this.columns = params.get('Columns') || 1728;
  36189. this.rows = params.get('Rows') || 0;
  36190. var eoblock = params.get('EndOfBlock');
  36191. if (eoblock === null || eoblock === undefined) {
  36192. eoblock = true;
  36193. }
  36194. this.eoblock = eoblock;
  36195. this.black = params.get('BlackIs1') || false;
  36196. this.codingLine = new Uint32Array(this.columns + 1);
  36197. this.refLine = new Uint32Array(this.columns + 2);
  36198. this.codingLine[0] = this.columns;
  36199. this.codingPos = 0;
  36200. this.row = 0;
  36201. this.nextLine2D = this.encoding < 0;
  36202. this.inputBits = 0;
  36203. this.inputBuf = 0;
  36204. this.outputBits = 0;
  36205. var code1;
  36206. while ((code1 = this.lookBits(12)) === 0) {
  36207. this.eatBits(1);
  36208. }
  36209. if (code1 === 1) {
  36210. this.eatBits(12);
  36211. }
  36212. if (this.encoding > 0) {
  36213. this.nextLine2D = !this.lookBits(1);
  36214. this.eatBits(1);
  36215. }
  36216. DecodeStream.call(this, maybeLength);
  36217. }
  36218. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36219. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36220. while (!this.eof) {
  36221. var c = this.lookChar();
  36222. this.ensureBuffer(this.bufferLength + 1);
  36223. this.buffer[this.bufferLength++] = c;
  36224. }
  36225. };
  36226. CCITTFaxStream.prototype.addPixels =
  36227. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36228. var codingLine = this.codingLine;
  36229. var codingPos = this.codingPos;
  36230. if (a1 > codingLine[codingPos]) {
  36231. if (a1 > this.columns) {
  36232. info('row is wrong length');
  36233. this.err = true;
  36234. a1 = this.columns;
  36235. }
  36236. if ((codingPos & 1) ^ blackPixels) {
  36237. ++codingPos;
  36238. }
  36239. codingLine[codingPos] = a1;
  36240. }
  36241. this.codingPos = codingPos;
  36242. };
  36243. CCITTFaxStream.prototype.addPixelsNeg =
  36244. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36245. var codingLine = this.codingLine;
  36246. var codingPos = this.codingPos;
  36247. if (a1 > codingLine[codingPos]) {
  36248. if (a1 > this.columns) {
  36249. info('row is wrong length');
  36250. this.err = true;
  36251. a1 = this.columns;
  36252. }
  36253. if ((codingPos & 1) ^ blackPixels) {
  36254. ++codingPos;
  36255. }
  36256. codingLine[codingPos] = a1;
  36257. } else if (a1 < codingLine[codingPos]) {
  36258. if (a1 < 0) {
  36259. info('invalid code');
  36260. this.err = true;
  36261. a1 = 0;
  36262. }
  36263. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36264. --codingPos;
  36265. }
  36266. codingLine[codingPos] = a1;
  36267. }
  36268. this.codingPos = codingPos;
  36269. };
  36270. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36271. var refLine = this.refLine;
  36272. var codingLine = this.codingLine;
  36273. var columns = this.columns;
  36274. var refPos, blackPixels, bits, i;
  36275. if (this.outputBits === 0) {
  36276. if (this.eof) {
  36277. return null;
  36278. }
  36279. this.err = false;
  36280. var code1, code2, code3;
  36281. if (this.nextLine2D) {
  36282. for (i = 0; codingLine[i] < columns; ++i) {
  36283. refLine[i] = codingLine[i];
  36284. }
  36285. refLine[i++] = columns;
  36286. refLine[i] = columns;
  36287. codingLine[0] = 0;
  36288. this.codingPos = 0;
  36289. refPos = 0;
  36290. blackPixels = 0;
  36291. while (codingLine[this.codingPos] < columns) {
  36292. code1 = this.getTwoDimCode();
  36293. switch (code1) {
  36294. case twoDimPass:
  36295. this.addPixels(refLine[refPos + 1], blackPixels);
  36296. if (refLine[refPos + 1] < columns) {
  36297. refPos += 2;
  36298. }
  36299. break;
  36300. case twoDimHoriz:
  36301. code1 = code2 = 0;
  36302. if (blackPixels) {
  36303. do {
  36304. code1 += (code3 = this.getBlackCode());
  36305. } while (code3 >= 64);
  36306. do {
  36307. code2 += (code3 = this.getWhiteCode());
  36308. } while (code3 >= 64);
  36309. } else {
  36310. do {
  36311. code1 += (code3 = this.getWhiteCode());
  36312. } while (code3 >= 64);
  36313. do {
  36314. code2 += (code3 = this.getBlackCode());
  36315. } while (code3 >= 64);
  36316. }
  36317. this.addPixels(codingLine[this.codingPos] +
  36318. code1, blackPixels);
  36319. if (codingLine[this.codingPos] < columns) {
  36320. this.addPixels(codingLine[this.codingPos] + code2,
  36321. blackPixels ^ 1);
  36322. }
  36323. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36324. refLine[refPos] < columns) {
  36325. refPos += 2;
  36326. }
  36327. break;
  36328. case twoDimVertR3:
  36329. this.addPixels(refLine[refPos] + 3, blackPixels);
  36330. blackPixels ^= 1;
  36331. if (codingLine[this.codingPos] < columns) {
  36332. ++refPos;
  36333. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36334. refLine[refPos] < columns) {
  36335. refPos += 2;
  36336. }
  36337. }
  36338. break;
  36339. case twoDimVertR2:
  36340. this.addPixels(refLine[refPos] + 2, blackPixels);
  36341. blackPixels ^= 1;
  36342. if (codingLine[this.codingPos] < columns) {
  36343. ++refPos;
  36344. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36345. refLine[refPos] < columns) {
  36346. refPos += 2;
  36347. }
  36348. }
  36349. break;
  36350. case twoDimVertR1:
  36351. this.addPixels(refLine[refPos] + 1, blackPixels);
  36352. blackPixels ^= 1;
  36353. if (codingLine[this.codingPos] < columns) {
  36354. ++refPos;
  36355. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36356. refLine[refPos] < columns) {
  36357. refPos += 2;
  36358. }
  36359. }
  36360. break;
  36361. case twoDimVert0:
  36362. this.addPixels(refLine[refPos], blackPixels);
  36363. blackPixels ^= 1;
  36364. if (codingLine[this.codingPos] < columns) {
  36365. ++refPos;
  36366. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36367. refLine[refPos] < columns) {
  36368. refPos += 2;
  36369. }
  36370. }
  36371. break;
  36372. case twoDimVertL3:
  36373. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36374. blackPixels ^= 1;
  36375. if (codingLine[this.codingPos] < columns) {
  36376. if (refPos > 0) {
  36377. --refPos;
  36378. } else {
  36379. ++refPos;
  36380. }
  36381. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36382. refLine[refPos] < columns) {
  36383. refPos += 2;
  36384. }
  36385. }
  36386. break;
  36387. case twoDimVertL2:
  36388. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36389. blackPixels ^= 1;
  36390. if (codingLine[this.codingPos] < columns) {
  36391. if (refPos > 0) {
  36392. --refPos;
  36393. } else {
  36394. ++refPos;
  36395. }
  36396. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36397. refLine[refPos] < columns) {
  36398. refPos += 2;
  36399. }
  36400. }
  36401. break;
  36402. case twoDimVertL1:
  36403. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36404. blackPixels ^= 1;
  36405. if (codingLine[this.codingPos] < columns) {
  36406. if (refPos > 0) {
  36407. --refPos;
  36408. } else {
  36409. ++refPos;
  36410. }
  36411. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36412. refLine[refPos] < columns) {
  36413. refPos += 2;
  36414. }
  36415. }
  36416. break;
  36417. case EOF:
  36418. this.addPixels(columns, 0);
  36419. this.eof = true;
  36420. break;
  36421. default:
  36422. info('bad 2d code');
  36423. this.addPixels(columns, 0);
  36424. this.err = true;
  36425. }
  36426. }
  36427. } else {
  36428. codingLine[0] = 0;
  36429. this.codingPos = 0;
  36430. blackPixels = 0;
  36431. while (codingLine[this.codingPos] < columns) {
  36432. code1 = 0;
  36433. if (blackPixels) {
  36434. do {
  36435. code1 += (code3 = this.getBlackCode());
  36436. } while (code3 >= 64);
  36437. } else {
  36438. do {
  36439. code1 += (code3 = this.getWhiteCode());
  36440. } while (code3 >= 64);
  36441. }
  36442. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36443. blackPixels ^= 1;
  36444. }
  36445. }
  36446. var gotEOL = false;
  36447. if (!this.eoblock && this.row === this.rows - 1) {
  36448. this.eof = true;
  36449. } else if (this.eoline || !this.byteAlign) {
  36450. code1 = this.lookBits(12);
  36451. if (this.eoline) {
  36452. while (code1 !== EOF && code1 !== 1) {
  36453. this.eatBits(1);
  36454. code1 = this.lookBits(12);
  36455. }
  36456. } else {
  36457. while (code1 === 0) {
  36458. this.eatBits(1);
  36459. code1 = this.lookBits(12);
  36460. }
  36461. }
  36462. if (code1 === 1) {
  36463. this.eatBits(12);
  36464. gotEOL = true;
  36465. } else if (code1 === EOF) {
  36466. this.eof = true;
  36467. }
  36468. }
  36469. if (this.byteAlign && !gotEOL) {
  36470. this.inputBits &= ~7;
  36471. }
  36472. if (!this.eof && this.encoding > 0) {
  36473. this.nextLine2D = !this.lookBits(1);
  36474. this.eatBits(1);
  36475. }
  36476. if (this.eoblock && gotEOL && this.byteAlign) {
  36477. code1 = this.lookBits(12);
  36478. if (code1 === 1) {
  36479. this.eatBits(12);
  36480. if (this.encoding > 0) {
  36481. this.lookBits(1);
  36482. this.eatBits(1);
  36483. }
  36484. if (this.encoding >= 0) {
  36485. for (i = 0; i < 4; ++i) {
  36486. code1 = this.lookBits(12);
  36487. if (code1 !== 1) {
  36488. info('bad rtc code: ' + code1);
  36489. }
  36490. this.eatBits(12);
  36491. if (this.encoding > 0) {
  36492. this.lookBits(1);
  36493. this.eatBits(1);
  36494. }
  36495. }
  36496. }
  36497. this.eof = true;
  36498. }
  36499. } else if (this.err && this.eoline) {
  36500. while (true) {
  36501. code1 = this.lookBits(13);
  36502. if (code1 === EOF) {
  36503. this.eof = true;
  36504. return null;
  36505. }
  36506. if ((code1 >> 1) === 1) {
  36507. break;
  36508. }
  36509. this.eatBits(1);
  36510. }
  36511. this.eatBits(12);
  36512. if (this.encoding > 0) {
  36513. this.eatBits(1);
  36514. this.nextLine2D = !(code1 & 1);
  36515. }
  36516. }
  36517. if (codingLine[0] > 0) {
  36518. this.outputBits = codingLine[this.codingPos = 0];
  36519. } else {
  36520. this.outputBits = codingLine[this.codingPos = 1];
  36521. }
  36522. this.row++;
  36523. }
  36524. var c;
  36525. if (this.outputBits >= 8) {
  36526. c = (this.codingPos & 1) ? 0 : 0xFF;
  36527. this.outputBits -= 8;
  36528. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  36529. this.codingPos++;
  36530. this.outputBits = (codingLine[this.codingPos] -
  36531. codingLine[this.codingPos - 1]);
  36532. }
  36533. } else {
  36534. bits = 8;
  36535. c = 0;
  36536. do {
  36537. if (this.outputBits > bits) {
  36538. c <<= bits;
  36539. if (!(this.codingPos & 1)) {
  36540. c |= 0xFF >> (8 - bits);
  36541. }
  36542. this.outputBits -= bits;
  36543. bits = 0;
  36544. } else {
  36545. c <<= this.outputBits;
  36546. if (!(this.codingPos & 1)) {
  36547. c |= 0xFF >> (8 - this.outputBits);
  36548. }
  36549. bits -= this.outputBits;
  36550. this.outputBits = 0;
  36551. if (codingLine[this.codingPos] < columns) {
  36552. this.codingPos++;
  36553. this.outputBits = (codingLine[this.codingPos] -
  36554. codingLine[this.codingPos - 1]);
  36555. } else if (bits > 0) {
  36556. c <<= bits;
  36557. bits = 0;
  36558. }
  36559. }
  36560. } while (bits);
  36561. }
  36562. if (this.black) {
  36563. c ^= 0xFF;
  36564. }
  36565. return c;
  36566. };
  36567. // This functions returns the code found from the table.
  36568. // The start and end parameters set the boundaries for searching the table.
  36569. // The limit parameter is optional. Function returns an array with three
  36570. // values. The first array element indicates whether a valid code is being
  36571. // returned. The second array element is the actual code. The third array
  36572. // element indicates whether EOF was reached.
  36573. CCITTFaxStream.prototype.findTableCode =
  36574. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  36575. var limitValue = limit || 0;
  36576. for (var i = start; i <= end; ++i) {
  36577. var code = this.lookBits(i);
  36578. if (code === EOF) {
  36579. return [true, 1, false];
  36580. }
  36581. if (i < end) {
  36582. code <<= end - i;
  36583. }
  36584. if (!limitValue || code >= limitValue) {
  36585. var p = table[code - limitValue];
  36586. if (p[0] === i) {
  36587. this.eatBits(i);
  36588. return [true, p[1], true];
  36589. }
  36590. }
  36591. }
  36592. return [false, 0, false];
  36593. };
  36594. CCITTFaxStream.prototype.getTwoDimCode =
  36595. function ccittFaxStreamGetTwoDimCode() {
  36596. var code = 0;
  36597. var p;
  36598. if (this.eoblock) {
  36599. code = this.lookBits(7);
  36600. p = twoDimTable[code];
  36601. if (p && p[0] > 0) {
  36602. this.eatBits(p[0]);
  36603. return p[1];
  36604. }
  36605. } else {
  36606. var result = this.findTableCode(1, 7, twoDimTable);
  36607. if (result[0] && result[2]) {
  36608. return result[1];
  36609. }
  36610. }
  36611. info('Bad two dim code');
  36612. return EOF;
  36613. };
  36614. CCITTFaxStream.prototype.getWhiteCode =
  36615. function ccittFaxStreamGetWhiteCode() {
  36616. var code = 0;
  36617. var p;
  36618. if (this.eoblock) {
  36619. code = this.lookBits(12);
  36620. if (code === EOF) {
  36621. return 1;
  36622. }
  36623. if ((code >> 5) === 0) {
  36624. p = whiteTable1[code];
  36625. } else {
  36626. p = whiteTable2[code >> 3];
  36627. }
  36628. if (p[0] > 0) {
  36629. this.eatBits(p[0]);
  36630. return p[1];
  36631. }
  36632. } else {
  36633. var result = this.findTableCode(1, 9, whiteTable2);
  36634. if (result[0]) {
  36635. return result[1];
  36636. }
  36637. result = this.findTableCode(11, 12, whiteTable1);
  36638. if (result[0]) {
  36639. return result[1];
  36640. }
  36641. }
  36642. info('bad white code');
  36643. this.eatBits(1);
  36644. return 1;
  36645. };
  36646. CCITTFaxStream.prototype.getBlackCode =
  36647. function ccittFaxStreamGetBlackCode() {
  36648. var code, p;
  36649. if (this.eoblock) {
  36650. code = this.lookBits(13);
  36651. if (code === EOF) {
  36652. return 1;
  36653. }
  36654. if ((code >> 7) === 0) {
  36655. p = blackTable1[code];
  36656. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  36657. p = blackTable2[(code >> 1) - 64];
  36658. } else {
  36659. p = blackTable3[code >> 7];
  36660. }
  36661. if (p[0] > 0) {
  36662. this.eatBits(p[0]);
  36663. return p[1];
  36664. }
  36665. } else {
  36666. var result = this.findTableCode(2, 6, blackTable3);
  36667. if (result[0]) {
  36668. return result[1];
  36669. }
  36670. result = this.findTableCode(7, 12, blackTable2, 64);
  36671. if (result[0]) {
  36672. return result[1];
  36673. }
  36674. result = this.findTableCode(10, 13, blackTable1);
  36675. if (result[0]) {
  36676. return result[1];
  36677. }
  36678. }
  36679. info('bad black code');
  36680. this.eatBits(1);
  36681. return 1;
  36682. };
  36683. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  36684. var c;
  36685. while (this.inputBits < n) {
  36686. if ((c = this.str.getByte()) === -1) {
  36687. if (this.inputBits === 0) {
  36688. return EOF;
  36689. }
  36690. return ((this.inputBuf << (n - this.inputBits)) &
  36691. (0xFFFF >> (16 - n)));
  36692. }
  36693. this.inputBuf = (this.inputBuf << 8) + c;
  36694. this.inputBits += 8;
  36695. }
  36696. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  36697. };
  36698. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  36699. if ((this.inputBits -= n) < 0) {
  36700. this.inputBits = 0;
  36701. }
  36702. };
  36703. return CCITTFaxStream;
  36704. })();
  36705. var LZWStream = (function LZWStreamClosure() {
  36706. function LZWStream(str, maybeLength, earlyChange) {
  36707. this.str = str;
  36708. this.dict = str.dict;
  36709. this.cachedData = 0;
  36710. this.bitsCached = 0;
  36711. var maxLzwDictionarySize = 4096;
  36712. var lzwState = {
  36713. earlyChange: earlyChange,
  36714. codeLength: 9,
  36715. nextCode: 258,
  36716. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  36717. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  36718. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  36719. currentSequence: new Uint8Array(maxLzwDictionarySize),
  36720. currentSequenceLength: 0
  36721. };
  36722. for (var i = 0; i < 256; ++i) {
  36723. lzwState.dictionaryValues[i] = i;
  36724. lzwState.dictionaryLengths[i] = 1;
  36725. }
  36726. this.lzwState = lzwState;
  36727. DecodeStream.call(this, maybeLength);
  36728. }
  36729. LZWStream.prototype = Object.create(DecodeStream.prototype);
  36730. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  36731. var bitsCached = this.bitsCached;
  36732. var cachedData = this.cachedData;
  36733. while (bitsCached < n) {
  36734. var c = this.str.getByte();
  36735. if (c === -1) {
  36736. this.eof = true;
  36737. return null;
  36738. }
  36739. cachedData = (cachedData << 8) | c;
  36740. bitsCached += 8;
  36741. }
  36742. this.bitsCached = (bitsCached -= n);
  36743. this.cachedData = cachedData;
  36744. this.lastCode = null;
  36745. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  36746. };
  36747. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  36748. var blockSize = 512;
  36749. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  36750. var i, j, q;
  36751. var lzwState = this.lzwState;
  36752. if (!lzwState) {
  36753. return; // eof was found
  36754. }
  36755. var earlyChange = lzwState.earlyChange;
  36756. var nextCode = lzwState.nextCode;
  36757. var dictionaryValues = lzwState.dictionaryValues;
  36758. var dictionaryLengths = lzwState.dictionaryLengths;
  36759. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  36760. var codeLength = lzwState.codeLength;
  36761. var prevCode = lzwState.prevCode;
  36762. var currentSequence = lzwState.currentSequence;
  36763. var currentSequenceLength = lzwState.currentSequenceLength;
  36764. var decodedLength = 0;
  36765. var currentBufferLength = this.bufferLength;
  36766. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  36767. for (i = 0; i < blockSize; i++) {
  36768. var code = this.readBits(codeLength);
  36769. var hasPrev = currentSequenceLength > 0;
  36770. if (code < 256) {
  36771. currentSequence[0] = code;
  36772. currentSequenceLength = 1;
  36773. } else if (code >= 258) {
  36774. if (code < nextCode) {
  36775. currentSequenceLength = dictionaryLengths[code];
  36776. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  36777. currentSequence[j] = dictionaryValues[q];
  36778. q = dictionaryPrevCodes[q];
  36779. }
  36780. } else {
  36781. currentSequence[currentSequenceLength++] = currentSequence[0];
  36782. }
  36783. } else if (code === 256) {
  36784. codeLength = 9;
  36785. nextCode = 258;
  36786. currentSequenceLength = 0;
  36787. continue;
  36788. } else {
  36789. this.eof = true;
  36790. delete this.lzwState;
  36791. break;
  36792. }
  36793. if (hasPrev) {
  36794. dictionaryPrevCodes[nextCode] = prevCode;
  36795. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  36796. dictionaryValues[nextCode] = currentSequence[0];
  36797. nextCode++;
  36798. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  36799. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  36800. 0.6931471805599453 + 1, 12) | 0;
  36801. }
  36802. prevCode = code;
  36803. decodedLength += currentSequenceLength;
  36804. if (estimatedDecodedSize < decodedLength) {
  36805. do {
  36806. estimatedDecodedSize += decodedSizeDelta;
  36807. } while (estimatedDecodedSize < decodedLength);
  36808. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  36809. }
  36810. for (j = 0; j < currentSequenceLength; j++) {
  36811. buffer[currentBufferLength++] = currentSequence[j];
  36812. }
  36813. }
  36814. lzwState.nextCode = nextCode;
  36815. lzwState.codeLength = codeLength;
  36816. lzwState.prevCode = prevCode;
  36817. lzwState.currentSequenceLength = currentSequenceLength;
  36818. this.bufferLength = currentBufferLength;
  36819. };
  36820. return LZWStream;
  36821. })();
  36822. var NullStream = (function NullStreamClosure() {
  36823. function NullStream() {
  36824. Stream.call(this, new Uint8Array(0));
  36825. }
  36826. NullStream.prototype = Stream.prototype;
  36827. return NullStream;
  36828. })();
  36829. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  36830. setup: function wphSetup(handler) {
  36831. var pdfManager;
  36832. function loadDocument(recoveryMode) {
  36833. var loadDocumentCapability = createPromiseCapability();
  36834. var parseSuccess = function parseSuccess() {
  36835. var numPagesPromise = pdfManager.ensureDoc('numPages');
  36836. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  36837. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  36838. Promise.all([numPagesPromise, fingerprintPromise,
  36839. encryptedPromise]).then(function onDocReady(results) {
  36840. var doc = {
  36841. numPages: results[0],
  36842. fingerprint: results[1],
  36843. encrypted: !!results[2],
  36844. };
  36845. loadDocumentCapability.resolve(doc);
  36846. },
  36847. parseFailure);
  36848. };
  36849. var parseFailure = function parseFailure(e) {
  36850. loadDocumentCapability.reject(e);
  36851. };
  36852. pdfManager.ensureDoc('checkHeader', []).then(function() {
  36853. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  36854. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  36855. parseSuccess, parseFailure);
  36856. }, parseFailure);
  36857. }, parseFailure);
  36858. return loadDocumentCapability.promise;
  36859. }
  36860. function getPdfManager(data) {
  36861. var pdfManagerCapability = createPromiseCapability();
  36862. var source = data.source;
  36863. var disableRange = data.disableRange;
  36864. if (source.data) {
  36865. try {
  36866. pdfManager = new LocalPdfManager(source.data, source.password);
  36867. pdfManagerCapability.resolve();
  36868. } catch (ex) {
  36869. pdfManagerCapability.reject(ex);
  36870. }
  36871. return pdfManagerCapability.promise;
  36872. } else if (source.chunkedViewerLoading) {
  36873. try {
  36874. pdfManager = new NetworkPdfManager(source, handler);
  36875. pdfManagerCapability.resolve();
  36876. } catch (ex) {
  36877. pdfManagerCapability.reject(ex);
  36878. }
  36879. return pdfManagerCapability.promise;
  36880. }
  36881. var networkManager = new NetworkManager(source.url, {
  36882. httpHeaders: source.httpHeaders,
  36883. withCredentials: source.withCredentials
  36884. });
  36885. var cachedChunks = [];
  36886. var fullRequestXhrId = networkManager.requestFull({
  36887. onHeadersReceived: function onHeadersReceived() {
  36888. if (disableRange) {
  36889. return;
  36890. }
  36891. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  36892. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  36893. return;
  36894. }
  36895. var contentEncoding =
  36896. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  36897. if (contentEncoding !== 'identity') {
  36898. return;
  36899. }
  36900. var length = fullRequestXhr.getResponseHeader('Content-Length');
  36901. length = parseInt(length, 10);
  36902. if (!isInt(length)) {
  36903. return;
  36904. }
  36905. source.length = length;
  36906. if (length <= 2 * RANGE_CHUNK_SIZE) {
  36907. // The file size is smaller than the size of two chunks, so it does
  36908. // not make any sense to abort the request and retry with a range
  36909. // request.
  36910. return;
  36911. }
  36912. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  36913. // We can continue fetching when progressive loading is enabled,
  36914. // and we don't need the autoFetch feature.
  36915. source.disableAutoFetch = true;
  36916. } else {
  36917. // NOTE: by cancelling the full request, and then issuing range
  36918. // requests, there will be an issue for sites where you can only
  36919. // request the pdf once. However, if this is the case, then the
  36920. // server should not be returning that it can support range
  36921. // requests.
  36922. networkManager.abortRequest(fullRequestXhrId);
  36923. }
  36924. try {
  36925. pdfManager = new NetworkPdfManager(source, handler);
  36926. pdfManagerCapability.resolve(pdfManager);
  36927. } catch (ex) {
  36928. pdfManagerCapability.reject(ex);
  36929. }
  36930. },
  36931. onProgressiveData: source.disableStream ? null :
  36932. function onProgressiveData(chunk) {
  36933. if (!pdfManager) {
  36934. cachedChunks.push(chunk);
  36935. return;
  36936. }
  36937. pdfManager.sendProgressiveData(chunk);
  36938. },
  36939. onDone: function onDone(args) {
  36940. if (pdfManager) {
  36941. return; // already processed
  36942. }
  36943. var pdfFile;
  36944. if (args === null) {
  36945. // TODO add some streaming manager, e.g. for unknown length files.
  36946. // The data was returned in the onProgressiveData, combining...
  36947. var pdfFileLength = 0, pos = 0;
  36948. cachedChunks.forEach(function (chunk) {
  36949. pdfFileLength += chunk.byteLength;
  36950. });
  36951. if (source.length && pdfFileLength !== source.length) {
  36952. warn('reported HTTP length is different from actual');
  36953. }
  36954. var pdfFileArray = new Uint8Array(pdfFileLength);
  36955. cachedChunks.forEach(function (chunk) {
  36956. pdfFileArray.set(new Uint8Array(chunk), pos);
  36957. pos += chunk.byteLength;
  36958. });
  36959. pdfFile = pdfFileArray.buffer;
  36960. } else {
  36961. pdfFile = args.chunk;
  36962. }
  36963. // the data is array, instantiating directly from it
  36964. try {
  36965. pdfManager = new LocalPdfManager(pdfFile, source.password);
  36966. pdfManagerCapability.resolve();
  36967. } catch (ex) {
  36968. pdfManagerCapability.reject(ex);
  36969. }
  36970. },
  36971. onError: function onError(status) {
  36972. var exception;
  36973. if (status === 404) {
  36974. exception = new MissingPDFException('Missing PDF "' +
  36975. source.url + '".');
  36976. handler.send('MissingPDF', exception);
  36977. } else {
  36978. exception = new UnexpectedResponseException(
  36979. 'Unexpected server response (' + status +
  36980. ') while retrieving PDF "' + source.url + '".', status);
  36981. handler.send('UnexpectedResponse', exception);
  36982. }
  36983. },
  36984. onProgress: function onProgress(evt) {
  36985. handler.send('DocProgress', {
  36986. loaded: evt.loaded,
  36987. total: evt.lengthComputable ? evt.total : source.length
  36988. });
  36989. }
  36990. });
  36991. return pdfManagerCapability.promise;
  36992. }
  36993. handler.on('test', function wphSetupTest(data) {
  36994. // check if Uint8Array can be sent to worker
  36995. if (!(data instanceof Uint8Array)) {
  36996. handler.send('test', false);
  36997. return;
  36998. }
  36999. // making sure postMessage transfers are working
  37000. var supportTransfers = data[0] === 255;
  37001. handler.postMessageTransfers = supportTransfers;
  37002. // check if the response property is supported by xhr
  37003. var xhr = new XMLHttpRequest();
  37004. var responseExists = 'response' in xhr;
  37005. // check if the property is actually implemented
  37006. try {
  37007. var dummy = xhr.responseType;
  37008. } catch (e) {
  37009. responseExists = false;
  37010. }
  37011. if (!responseExists) {
  37012. handler.send('test', false);
  37013. return;
  37014. }
  37015. handler.send('test', {
  37016. supportTypedArray: true,
  37017. supportTransfers: supportTransfers
  37018. });
  37019. });
  37020. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37021. var onSuccess = function(doc) {
  37022. handler.send('GetDoc', { pdfInfo: doc });
  37023. };
  37024. var onFailure = function(e) {
  37025. if (e instanceof PasswordException) {
  37026. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37027. handler.send('NeedPassword', e);
  37028. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37029. handler.send('IncorrectPassword', e);
  37030. }
  37031. } else if (e instanceof InvalidPDFException) {
  37032. handler.send('InvalidPDF', e);
  37033. } else if (e instanceof MissingPDFException) {
  37034. handler.send('MissingPDF', e);
  37035. } else if (e instanceof UnexpectedResponseException) {
  37036. handler.send('UnexpectedResponse', e);
  37037. } else {
  37038. handler.send('UnknownError',
  37039. new UnknownErrorException(e.message, e.toString()));
  37040. }
  37041. };
  37042. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37043. -1 : data.maxImageSize;
  37044. PDFJS.disableFontFace = data.disableFontFace;
  37045. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37046. PDFJS.verbosity = data.verbosity;
  37047. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37048. null : data.cMapUrl;
  37049. PDFJS.cMapPacked = data.cMapPacked === true;
  37050. getPdfManager(data).then(function () {
  37051. handler.send('PDFManagerReady', null);
  37052. pdfManager.onLoadedStream().then(function(stream) {
  37053. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37054. });
  37055. }).then(function pdfManagerReady() {
  37056. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37057. // Try again with recoveryMode == true
  37058. if (!(ex instanceof XRefParseException)) {
  37059. if (ex instanceof PasswordException) {
  37060. // after password exception prepare to receive a new password
  37061. // to repeat loading
  37062. pdfManager.passwordChanged().then(pdfManagerReady);
  37063. }
  37064. onFailure(ex);
  37065. return;
  37066. }
  37067. pdfManager.requestLoadedStream();
  37068. pdfManager.onLoadedStream().then(function() {
  37069. loadDocument(true).then(onSuccess, onFailure);
  37070. });
  37071. }, onFailure);
  37072. }, onFailure);
  37073. });
  37074. handler.on('GetPage', function wphSetupGetPage(data) {
  37075. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37076. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37077. var refPromise = pdfManager.ensure(page, 'ref');
  37078. var viewPromise = pdfManager.ensure(page, 'view');
  37079. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37080. function(results) {
  37081. return {
  37082. rotate: results[0],
  37083. ref: results[1],
  37084. view: results[2]
  37085. };
  37086. });
  37087. });
  37088. });
  37089. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37090. var ref = new Ref(data.ref.num, data.ref.gen);
  37091. var catalog = pdfManager.pdfDocument.catalog;
  37092. return catalog.getPageIndex(ref);
  37093. });
  37094. handler.on('GetDestinations',
  37095. function wphSetupGetDestinations(data) {
  37096. return pdfManager.ensureCatalog('destinations');
  37097. }
  37098. );
  37099. handler.on('GetDestination',
  37100. function wphSetupGetDestination(data) {
  37101. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37102. }
  37103. );
  37104. handler.on('GetAttachments',
  37105. function wphSetupGetAttachments(data) {
  37106. return pdfManager.ensureCatalog('attachments');
  37107. }
  37108. );
  37109. handler.on('GetJavaScript',
  37110. function wphSetupGetJavaScript(data) {
  37111. return pdfManager.ensureCatalog('javaScript');
  37112. }
  37113. );
  37114. handler.on('GetOutline',
  37115. function wphSetupGetOutline(data) {
  37116. return pdfManager.ensureCatalog('documentOutline');
  37117. }
  37118. );
  37119. handler.on('GetMetadata',
  37120. function wphSetupGetMetadata(data) {
  37121. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37122. pdfManager.ensureCatalog('metadata')]);
  37123. }
  37124. );
  37125. handler.on('GetData', function wphSetupGetData(data) {
  37126. pdfManager.requestLoadedStream();
  37127. return pdfManager.onLoadedStream().then(function(stream) {
  37128. return stream.bytes;
  37129. });
  37130. });
  37131. handler.on('GetStats',
  37132. function wphSetupGetStats(data) {
  37133. return pdfManager.pdfDocument.xref.stats;
  37134. }
  37135. );
  37136. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37137. pdfManager.updatePassword(data);
  37138. });
  37139. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37140. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37141. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37142. });
  37143. });
  37144. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37145. pdfManager.getPage(data.pageIndex).then(function(page) {
  37146. var pageNum = data.pageIndex + 1;
  37147. var start = Date.now();
  37148. // Pre compile the pdf page and fetch the fonts/images.
  37149. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37150. info('page=' + pageNum + ' - getOperatorList: time=' +
  37151. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37152. }, function(e) {
  37153. var minimumStackMessage =
  37154. 'worker.js: while trying to getPage() and getOperatorList()';
  37155. var wrappedException;
  37156. // Turn the error into an obj that can be serialized
  37157. if (typeof e === 'string') {
  37158. wrappedException = {
  37159. message: e,
  37160. stack: minimumStackMessage
  37161. };
  37162. } else if (typeof e === 'object') {
  37163. wrappedException = {
  37164. message: e.message || e.toString(),
  37165. stack: e.stack || minimumStackMessage
  37166. };
  37167. } else {
  37168. wrappedException = {
  37169. message: 'Unknown exception type: ' + (typeof e),
  37170. stack: minimumStackMessage
  37171. };
  37172. }
  37173. handler.send('PageError', {
  37174. pageNum: pageNum,
  37175. error: wrappedException,
  37176. intent: data.intent
  37177. });
  37178. });
  37179. });
  37180. }, this);
  37181. handler.on('GetTextContent', function wphExtractText(data) {
  37182. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37183. var pageNum = data.pageIndex + 1;
  37184. var start = Date.now();
  37185. return page.extractTextContent().then(function(textContent) {
  37186. info('text indexing: page=' + pageNum + ' - time=' +
  37187. (Date.now() - start) + 'ms');
  37188. return textContent;
  37189. });
  37190. });
  37191. });
  37192. handler.on('Cleanup', function wphCleanup(data) {
  37193. return pdfManager.cleanup();
  37194. });
  37195. handler.on('Terminate', function wphTerminate(data) {
  37196. pdfManager.terminate();
  37197. });
  37198. }
  37199. };
  37200. var consoleTimer = {};
  37201. var workerConsole = {
  37202. log: function log() {
  37203. var args = Array.prototype.slice.call(arguments);
  37204. globalScope.postMessage({
  37205. action: 'console_log',
  37206. data: args
  37207. });
  37208. },
  37209. error: function error() {
  37210. var args = Array.prototype.slice.call(arguments);
  37211. globalScope.postMessage({
  37212. action: 'console_error',
  37213. data: args
  37214. });
  37215. throw 'pdf.js execution error';
  37216. },
  37217. time: function time(name) {
  37218. consoleTimer[name] = Date.now();
  37219. },
  37220. timeEnd: function timeEnd(name) {
  37221. var time = consoleTimer[name];
  37222. if (!time) {
  37223. error('Unknown timer name ' + name);
  37224. }
  37225. this.log('Timer:', name, Date.now() - time);
  37226. }
  37227. };
  37228. // Worker thread?
  37229. if (typeof window === 'undefined') {
  37230. if (!('console' in globalScope)) {
  37231. globalScope.console = workerConsole;
  37232. }
  37233. // Listen for unsupported features so we can pass them on to the main thread.
  37234. PDFJS.UnsupportedManager.listen(function (msg) {
  37235. globalScope.postMessage({
  37236. action: '_unsupported_feature',
  37237. data: msg
  37238. });
  37239. });
  37240. var handler = new MessageHandler('worker_processor', this);
  37241. WorkerMessageHandler.setup(handler);
  37242. }
  37243. /* This class implements the QM Coder decoding as defined in
  37244. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37245. * Annex C.3 Arithmetic decoding procedure
  37246. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37247. *
  37248. * The arithmetic decoder is used in conjunction with context models to decode
  37249. * JPEG2000 and JBIG2 streams.
  37250. */
  37251. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37252. // Table C-2
  37253. var QeTable = [
  37254. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37255. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37256. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37257. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37258. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37259. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37260. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37261. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37262. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37263. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37264. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37265. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37266. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37267. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37268. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37269. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37270. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37271. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37272. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37273. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37274. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37275. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37276. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37277. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37278. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37279. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37280. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37281. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37282. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37283. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37284. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37285. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37286. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37287. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37288. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37289. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37290. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37291. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37292. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37293. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37294. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37295. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37296. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37297. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37298. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37299. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37300. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37301. ];
  37302. // C.3.5 Initialisation of the decoder (INITDEC)
  37303. function ArithmeticDecoder(data, start, end) {
  37304. this.data = data;
  37305. this.bp = start;
  37306. this.dataEnd = end;
  37307. this.chigh = data[start];
  37308. this.clow = 0;
  37309. this.byteIn();
  37310. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37311. this.clow = (this.clow << 7) & 0xFFFF;
  37312. this.ct -= 7;
  37313. this.a = 0x8000;
  37314. }
  37315. ArithmeticDecoder.prototype = {
  37316. // C.3.4 Compressed data input (BYTEIN)
  37317. byteIn: function ArithmeticDecoder_byteIn() {
  37318. var data = this.data;
  37319. var bp = this.bp;
  37320. if (data[bp] === 0xFF) {
  37321. var b1 = data[bp + 1];
  37322. if (b1 > 0x8F) {
  37323. this.clow += 0xFF00;
  37324. this.ct = 8;
  37325. } else {
  37326. bp++;
  37327. this.clow += (data[bp] << 9);
  37328. this.ct = 7;
  37329. this.bp = bp;
  37330. }
  37331. } else {
  37332. bp++;
  37333. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37334. this.ct = 8;
  37335. this.bp = bp;
  37336. }
  37337. if (this.clow > 0xFFFF) {
  37338. this.chigh += (this.clow >> 16);
  37339. this.clow &= 0xFFFF;
  37340. }
  37341. },
  37342. // C.3.2 Decoding a decision (DECODE)
  37343. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37344. // contexts are packed into 1 byte:
  37345. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37346. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37347. var qeTableIcx = QeTable[cx_index];
  37348. var qeIcx = qeTableIcx.qe;
  37349. var d;
  37350. var a = this.a - qeIcx;
  37351. if (this.chigh < qeIcx) {
  37352. // exchangeLps
  37353. if (a < qeIcx) {
  37354. a = qeIcx;
  37355. d = cx_mps;
  37356. cx_index = qeTableIcx.nmps;
  37357. } else {
  37358. a = qeIcx;
  37359. d = 1 ^ cx_mps;
  37360. if (qeTableIcx.switchFlag === 1) {
  37361. cx_mps = d;
  37362. }
  37363. cx_index = qeTableIcx.nlps;
  37364. }
  37365. } else {
  37366. this.chigh -= qeIcx;
  37367. if ((a & 0x8000) !== 0) {
  37368. this.a = a;
  37369. return cx_mps;
  37370. }
  37371. // exchangeMps
  37372. if (a < qeIcx) {
  37373. d = 1 ^ cx_mps;
  37374. if (qeTableIcx.switchFlag === 1) {
  37375. cx_mps = d;
  37376. }
  37377. cx_index = qeTableIcx.nlps;
  37378. } else {
  37379. d = cx_mps;
  37380. cx_index = qeTableIcx.nmps;
  37381. }
  37382. }
  37383. // C.3.3 renormD;
  37384. do {
  37385. if (this.ct === 0) {
  37386. this.byteIn();
  37387. }
  37388. a <<= 1;
  37389. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37390. this.clow = (this.clow << 1) & 0xFFFF;
  37391. this.ct--;
  37392. } while ((a & 0x8000) === 0);
  37393. this.a = a;
  37394. contexts[pos] = cx_index << 1 | cx_mps;
  37395. return d;
  37396. }
  37397. };
  37398. return ArithmeticDecoder;
  37399. })();
  37400. var JpegImage = (function jpegImage() {
  37401. var dctZigZag = new Uint8Array([
  37402. 0,
  37403. 1, 8,
  37404. 16, 9, 2,
  37405. 3, 10, 17, 24,
  37406. 32, 25, 18, 11, 4,
  37407. 5, 12, 19, 26, 33, 40,
  37408. 48, 41, 34, 27, 20, 13, 6,
  37409. 7, 14, 21, 28, 35, 42, 49, 56,
  37410. 57, 50, 43, 36, 29, 22, 15,
  37411. 23, 30, 37, 44, 51, 58,
  37412. 59, 52, 45, 38, 31,
  37413. 39, 46, 53, 60,
  37414. 61, 54, 47,
  37415. 55, 62,
  37416. 63
  37417. ]);
  37418. var dctCos1 = 4017; // cos(pi/16)
  37419. var dctSin1 = 799; // sin(pi/16)
  37420. var dctCos3 = 3406; // cos(3*pi/16)
  37421. var dctSin3 = 2276; // sin(3*pi/16)
  37422. var dctCos6 = 1567; // cos(6*pi/16)
  37423. var dctSin6 = 3784; // sin(6*pi/16)
  37424. var dctSqrt2 = 5793; // sqrt(2)
  37425. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37426. function constructor() {
  37427. }
  37428. function buildHuffmanTable(codeLengths, values) {
  37429. var k = 0, code = [], i, j, length = 16;
  37430. while (length > 0 && !codeLengths[length - 1]) {
  37431. length--;
  37432. }
  37433. code.push({children: [], index: 0});
  37434. var p = code[0], q;
  37435. for (i = 0; i < length; i++) {
  37436. for (j = 0; j < codeLengths[i]; j++) {
  37437. p = code.pop();
  37438. p.children[p.index] = values[k];
  37439. while (p.index > 0) {
  37440. p = code.pop();
  37441. }
  37442. p.index++;
  37443. code.push(p);
  37444. while (code.length <= i) {
  37445. code.push(q = {children: [], index: 0});
  37446. p.children[p.index] = q.children;
  37447. p = q;
  37448. }
  37449. k++;
  37450. }
  37451. if (i + 1 < length) {
  37452. // p here points to last code
  37453. code.push(q = {children: [], index: 0});
  37454. p.children[p.index] = q.children;
  37455. p = q;
  37456. }
  37457. }
  37458. return code[0].children;
  37459. }
  37460. function getBlockBufferOffset(component, row, col) {
  37461. return 64 * ((component.blocksPerLine + 1) * row + col);
  37462. }
  37463. function decodeScan(data, offset, frame, components, resetInterval,
  37464. spectralStart, spectralEnd, successivePrev, successive) {
  37465. var precision = frame.precision;
  37466. var samplesPerLine = frame.samplesPerLine;
  37467. var scanLines = frame.scanLines;
  37468. var mcusPerLine = frame.mcusPerLine;
  37469. var progressive = frame.progressive;
  37470. var maxH = frame.maxH, maxV = frame.maxV;
  37471. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37472. function readBit() {
  37473. if (bitsCount > 0) {
  37474. bitsCount--;
  37475. return (bitsData >> bitsCount) & 1;
  37476. }
  37477. bitsData = data[offset++];
  37478. if (bitsData === 0xFF) {
  37479. var nextByte = data[offset++];
  37480. if (nextByte) {
  37481. throw 'unexpected marker: ' +
  37482. ((bitsData << 8) | nextByte).toString(16);
  37483. }
  37484. // unstuff 0
  37485. }
  37486. bitsCount = 7;
  37487. return bitsData >>> 7;
  37488. }
  37489. function decodeHuffman(tree) {
  37490. var node = tree;
  37491. var bit;
  37492. while ((bit = readBit()) !== null) {
  37493. node = node[bit];
  37494. if (typeof node === 'number') {
  37495. return node;
  37496. }
  37497. if (typeof node !== 'object') {
  37498. throw 'invalid huffman sequence';
  37499. }
  37500. }
  37501. return null;
  37502. }
  37503. function receive(length) {
  37504. var n = 0;
  37505. while (length > 0) {
  37506. var bit = readBit();
  37507. if (bit === null) {
  37508. return;
  37509. }
  37510. n = (n << 1) | bit;
  37511. length--;
  37512. }
  37513. return n;
  37514. }
  37515. function receiveAndExtend(length) {
  37516. if (length === 1) {
  37517. return readBit() === 1 ? 1 : -1;
  37518. }
  37519. var n = receive(length);
  37520. if (n >= 1 << (length - 1)) {
  37521. return n;
  37522. }
  37523. return n + (-1 << length) + 1;
  37524. }
  37525. function decodeBaseline(component, offset) {
  37526. var t = decodeHuffman(component.huffmanTableDC);
  37527. var diff = t === 0 ? 0 : receiveAndExtend(t);
  37528. component.blockData[offset] = (component.pred += diff);
  37529. var k = 1;
  37530. while (k < 64) {
  37531. var rs = decodeHuffman(component.huffmanTableAC);
  37532. var s = rs & 15, r = rs >> 4;
  37533. if (s === 0) {
  37534. if (r < 15) {
  37535. break;
  37536. }
  37537. k += 16;
  37538. continue;
  37539. }
  37540. k += r;
  37541. var z = dctZigZag[k];
  37542. component.blockData[offset + z] = receiveAndExtend(s);
  37543. k++;
  37544. }
  37545. }
  37546. function decodeDCFirst(component, offset) {
  37547. var t = decodeHuffman(component.huffmanTableDC);
  37548. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  37549. component.blockData[offset] = (component.pred += diff);
  37550. }
  37551. function decodeDCSuccessive(component, offset) {
  37552. component.blockData[offset] |= readBit() << successive;
  37553. }
  37554. var eobrun = 0;
  37555. function decodeACFirst(component, offset) {
  37556. if (eobrun > 0) {
  37557. eobrun--;
  37558. return;
  37559. }
  37560. var k = spectralStart, e = spectralEnd;
  37561. while (k <= e) {
  37562. var rs = decodeHuffman(component.huffmanTableAC);
  37563. var s = rs & 15, r = rs >> 4;
  37564. if (s === 0) {
  37565. if (r < 15) {
  37566. eobrun = receive(r) + (1 << r) - 1;
  37567. break;
  37568. }
  37569. k += 16;
  37570. continue;
  37571. }
  37572. k += r;
  37573. var z = dctZigZag[k];
  37574. component.blockData[offset + z] =
  37575. receiveAndExtend(s) * (1 << successive);
  37576. k++;
  37577. }
  37578. }
  37579. var successiveACState = 0, successiveACNextValue;
  37580. function decodeACSuccessive(component, offset) {
  37581. var k = spectralStart;
  37582. var e = spectralEnd;
  37583. var r = 0;
  37584. var s;
  37585. var rs;
  37586. while (k <= e) {
  37587. var z = dctZigZag[k];
  37588. switch (successiveACState) {
  37589. case 0: // initial state
  37590. rs = decodeHuffman(component.huffmanTableAC);
  37591. s = rs & 15;
  37592. r = rs >> 4;
  37593. if (s === 0) {
  37594. if (r < 15) {
  37595. eobrun = receive(r) + (1 << r);
  37596. successiveACState = 4;
  37597. } else {
  37598. r = 16;
  37599. successiveACState = 1;
  37600. }
  37601. } else {
  37602. if (s !== 1) {
  37603. throw 'invalid ACn encoding';
  37604. }
  37605. successiveACNextValue = receiveAndExtend(s);
  37606. successiveACState = r ? 2 : 3;
  37607. }
  37608. continue;
  37609. case 1: // skipping r zero items
  37610. case 2:
  37611. if (component.blockData[offset + z]) {
  37612. component.blockData[offset + z] += (readBit() << successive);
  37613. } else {
  37614. r--;
  37615. if (r === 0) {
  37616. successiveACState = successiveACState === 2 ? 3 : 0;
  37617. }
  37618. }
  37619. break;
  37620. case 3: // set value for a zero item
  37621. if (component.blockData[offset + z]) {
  37622. component.blockData[offset + z] += (readBit() << successive);
  37623. } else {
  37624. component.blockData[offset + z] =
  37625. successiveACNextValue << successive;
  37626. successiveACState = 0;
  37627. }
  37628. break;
  37629. case 4: // eob
  37630. if (component.blockData[offset + z]) {
  37631. component.blockData[offset + z] += (readBit() << successive);
  37632. }
  37633. break;
  37634. }
  37635. k++;
  37636. }
  37637. if (successiveACState === 4) {
  37638. eobrun--;
  37639. if (eobrun === 0) {
  37640. successiveACState = 0;
  37641. }
  37642. }
  37643. }
  37644. function decodeMcu(component, decode, mcu, row, col) {
  37645. var mcuRow = (mcu / mcusPerLine) | 0;
  37646. var mcuCol = mcu % mcusPerLine;
  37647. var blockRow = mcuRow * component.v + row;
  37648. var blockCol = mcuCol * component.h + col;
  37649. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37650. decode(component, offset);
  37651. }
  37652. function decodeBlock(component, decode, mcu) {
  37653. var blockRow = (mcu / component.blocksPerLine) | 0;
  37654. var blockCol = mcu % component.blocksPerLine;
  37655. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37656. decode(component, offset);
  37657. }
  37658. var componentsLength = components.length;
  37659. var component, i, j, k, n;
  37660. var decodeFn;
  37661. if (progressive) {
  37662. if (spectralStart === 0) {
  37663. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  37664. } else {
  37665. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  37666. }
  37667. } else {
  37668. decodeFn = decodeBaseline;
  37669. }
  37670. var mcu = 0, marker;
  37671. var mcuExpected;
  37672. if (componentsLength === 1) {
  37673. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  37674. } else {
  37675. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  37676. }
  37677. if (!resetInterval) {
  37678. resetInterval = mcuExpected;
  37679. }
  37680. var h, v;
  37681. while (mcu < mcuExpected) {
  37682. // reset interval stuff
  37683. for (i = 0; i < componentsLength; i++) {
  37684. components[i].pred = 0;
  37685. }
  37686. eobrun = 0;
  37687. if (componentsLength === 1) {
  37688. component = components[0];
  37689. for (n = 0; n < resetInterval; n++) {
  37690. decodeBlock(component, decodeFn, mcu);
  37691. mcu++;
  37692. }
  37693. } else {
  37694. for (n = 0; n < resetInterval; n++) {
  37695. for (i = 0; i < componentsLength; i++) {
  37696. component = components[i];
  37697. h = component.h;
  37698. v = component.v;
  37699. for (j = 0; j < v; j++) {
  37700. for (k = 0; k < h; k++) {
  37701. decodeMcu(component, decodeFn, mcu, j, k);
  37702. }
  37703. }
  37704. }
  37705. mcu++;
  37706. }
  37707. }
  37708. // find marker
  37709. bitsCount = 0;
  37710. marker = (data[offset] << 8) | data[offset + 1];
  37711. if (marker <= 0xFF00) {
  37712. throw 'marker was not found';
  37713. }
  37714. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  37715. offset += 2;
  37716. } else {
  37717. break;
  37718. }
  37719. }
  37720. return offset - startOffset;
  37721. }
  37722. // A port of poppler's IDCT method which in turn is taken from:
  37723. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  37724. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  37725. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  37726. // 988-991.
  37727. function quantizeAndInverse(component, blockBufferOffset, p) {
  37728. var qt = component.quantizationTable, blockData = component.blockData;
  37729. var v0, v1, v2, v3, v4, v5, v6, v7;
  37730. var p0, p1, p2, p3, p4, p5, p6, p7;
  37731. var t;
  37732. // inverse DCT on rows
  37733. for (var row = 0; row < 64; row += 8) {
  37734. // gather block data
  37735. p0 = blockData[blockBufferOffset + row];
  37736. p1 = blockData[blockBufferOffset + row + 1];
  37737. p2 = blockData[blockBufferOffset + row + 2];
  37738. p3 = blockData[blockBufferOffset + row + 3];
  37739. p4 = blockData[blockBufferOffset + row + 4];
  37740. p5 = blockData[blockBufferOffset + row + 5];
  37741. p6 = blockData[blockBufferOffset + row + 6];
  37742. p7 = blockData[blockBufferOffset + row + 7];
  37743. // dequant p0
  37744. p0 *= qt[row];
  37745. // check for all-zero AC coefficients
  37746. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  37747. t = (dctSqrt2 * p0 + 512) >> 10;
  37748. p[row] = t;
  37749. p[row + 1] = t;
  37750. p[row + 2] = t;
  37751. p[row + 3] = t;
  37752. p[row + 4] = t;
  37753. p[row + 5] = t;
  37754. p[row + 6] = t;
  37755. p[row + 7] = t;
  37756. continue;
  37757. }
  37758. // dequant p1 ... p7
  37759. p1 *= qt[row + 1];
  37760. p2 *= qt[row + 2];
  37761. p3 *= qt[row + 3];
  37762. p4 *= qt[row + 4];
  37763. p5 *= qt[row + 5];
  37764. p6 *= qt[row + 6];
  37765. p7 *= qt[row + 7];
  37766. // stage 4
  37767. v0 = (dctSqrt2 * p0 + 128) >> 8;
  37768. v1 = (dctSqrt2 * p4 + 128) >> 8;
  37769. v2 = p2;
  37770. v3 = p6;
  37771. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  37772. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  37773. v5 = p3 << 4;
  37774. v6 = p5 << 4;
  37775. // stage 3
  37776. v0 = (v0 + v1 + 1) >> 1;
  37777. v1 = v0 - v1;
  37778. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  37779. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  37780. v3 = t;
  37781. v4 = (v4 + v6 + 1) >> 1;
  37782. v6 = v4 - v6;
  37783. v7 = (v7 + v5 + 1) >> 1;
  37784. v5 = v7 - v5;
  37785. // stage 2
  37786. v0 = (v0 + v3 + 1) >> 1;
  37787. v3 = v0 - v3;
  37788. v1 = (v1 + v2 + 1) >> 1;
  37789. v2 = v1 - v2;
  37790. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  37791. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  37792. v7 = t;
  37793. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  37794. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  37795. v6 = t;
  37796. // stage 1
  37797. p[row] = v0 + v7;
  37798. p[row + 7] = v0 - v7;
  37799. p[row + 1] = v1 + v6;
  37800. p[row + 6] = v1 - v6;
  37801. p[row + 2] = v2 + v5;
  37802. p[row + 5] = v2 - v5;
  37803. p[row + 3] = v3 + v4;
  37804. p[row + 4] = v3 - v4;
  37805. }
  37806. // inverse DCT on columns
  37807. for (var col = 0; col < 8; ++col) {
  37808. p0 = p[col];
  37809. p1 = p[col + 8];
  37810. p2 = p[col + 16];
  37811. p3 = p[col + 24];
  37812. p4 = p[col + 32];
  37813. p5 = p[col + 40];
  37814. p6 = p[col + 48];
  37815. p7 = p[col + 56];
  37816. // check for all-zero AC coefficients
  37817. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  37818. t = (dctSqrt2 * p0 + 8192) >> 14;
  37819. // convert to 8 bit
  37820. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  37821. blockData[blockBufferOffset + col] = t;
  37822. blockData[blockBufferOffset + col + 8] = t;
  37823. blockData[blockBufferOffset + col + 16] = t;
  37824. blockData[blockBufferOffset + col + 24] = t;
  37825. blockData[blockBufferOffset + col + 32] = t;
  37826. blockData[blockBufferOffset + col + 40] = t;
  37827. blockData[blockBufferOffset + col + 48] = t;
  37828. blockData[blockBufferOffset + col + 56] = t;
  37829. continue;
  37830. }
  37831. // stage 4
  37832. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  37833. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  37834. v2 = p2;
  37835. v3 = p6;
  37836. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  37837. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  37838. v5 = p3;
  37839. v6 = p5;
  37840. // stage 3
  37841. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  37842. // converting to UInt8 range later.
  37843. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  37844. v1 = v0 - v1;
  37845. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  37846. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  37847. v3 = t;
  37848. v4 = (v4 + v6 + 1) >> 1;
  37849. v6 = v4 - v6;
  37850. v7 = (v7 + v5 + 1) >> 1;
  37851. v5 = v7 - v5;
  37852. // stage 2
  37853. v0 = (v0 + v3 + 1) >> 1;
  37854. v3 = v0 - v3;
  37855. v1 = (v1 + v2 + 1) >> 1;
  37856. v2 = v1 - v2;
  37857. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  37858. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  37859. v7 = t;
  37860. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  37861. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  37862. v6 = t;
  37863. // stage 1
  37864. p0 = v0 + v7;
  37865. p7 = v0 - v7;
  37866. p1 = v1 + v6;
  37867. p6 = v1 - v6;
  37868. p2 = v2 + v5;
  37869. p5 = v2 - v5;
  37870. p3 = v3 + v4;
  37871. p4 = v3 - v4;
  37872. // convert to 8-bit integers
  37873. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  37874. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  37875. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  37876. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  37877. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  37878. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  37879. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  37880. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  37881. // store block data
  37882. blockData[blockBufferOffset + col] = p0;
  37883. blockData[blockBufferOffset + col + 8] = p1;
  37884. blockData[blockBufferOffset + col + 16] = p2;
  37885. blockData[blockBufferOffset + col + 24] = p3;
  37886. blockData[blockBufferOffset + col + 32] = p4;
  37887. blockData[blockBufferOffset + col + 40] = p5;
  37888. blockData[blockBufferOffset + col + 48] = p6;
  37889. blockData[blockBufferOffset + col + 56] = p7;
  37890. }
  37891. }
  37892. function buildComponentData(frame, component) {
  37893. var blocksPerLine = component.blocksPerLine;
  37894. var blocksPerColumn = component.blocksPerColumn;
  37895. var computationBuffer = new Int16Array(64);
  37896. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  37897. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  37898. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37899. quantizeAndInverse(component, offset, computationBuffer);
  37900. }
  37901. }
  37902. return component.blockData;
  37903. }
  37904. function clamp0to255(a) {
  37905. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  37906. }
  37907. constructor.prototype = {
  37908. parse: function parse(data) {
  37909. function readUint16() {
  37910. var value = (data[offset] << 8) | data[offset + 1];
  37911. offset += 2;
  37912. return value;
  37913. }
  37914. function readDataBlock() {
  37915. var length = readUint16();
  37916. var array = data.subarray(offset, offset + length - 2);
  37917. offset += array.length;
  37918. return array;
  37919. }
  37920. function prepareComponents(frame) {
  37921. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  37922. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  37923. for (var i = 0; i < frame.components.length; i++) {
  37924. component = frame.components[i];
  37925. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  37926. component.h / frame.maxH);
  37927. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  37928. component.v / frame.maxV);
  37929. var blocksPerLineForMcu = mcusPerLine * component.h;
  37930. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  37931. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  37932. (blocksPerLineForMcu + 1);
  37933. component.blockData = new Int16Array(blocksBufferSize);
  37934. component.blocksPerLine = blocksPerLine;
  37935. component.blocksPerColumn = blocksPerColumn;
  37936. }
  37937. frame.mcusPerLine = mcusPerLine;
  37938. frame.mcusPerColumn = mcusPerColumn;
  37939. }
  37940. var offset = 0, length = data.length;
  37941. var jfif = null;
  37942. var adobe = null;
  37943. var pixels = null;
  37944. var frame, resetInterval;
  37945. var quantizationTables = [];
  37946. var huffmanTablesAC = [], huffmanTablesDC = [];
  37947. var fileMarker = readUint16();
  37948. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  37949. throw 'SOI not found';
  37950. }
  37951. fileMarker = readUint16();
  37952. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  37953. var i, j, l;
  37954. switch(fileMarker) {
  37955. case 0xFFE0: // APP0 (Application Specific)
  37956. case 0xFFE1: // APP1
  37957. case 0xFFE2: // APP2
  37958. case 0xFFE3: // APP3
  37959. case 0xFFE4: // APP4
  37960. case 0xFFE5: // APP5
  37961. case 0xFFE6: // APP6
  37962. case 0xFFE7: // APP7
  37963. case 0xFFE8: // APP8
  37964. case 0xFFE9: // APP9
  37965. case 0xFFEA: // APP10
  37966. case 0xFFEB: // APP11
  37967. case 0xFFEC: // APP12
  37968. case 0xFFED: // APP13
  37969. case 0xFFEE: // APP14
  37970. case 0xFFEF: // APP15
  37971. case 0xFFFE: // COM (Comment)
  37972. var appData = readDataBlock();
  37973. if (fileMarker === 0xFFE0) {
  37974. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  37975. appData[2] === 0x49 && appData[3] === 0x46 &&
  37976. appData[4] === 0) { // 'JFIF\x00'
  37977. jfif = {
  37978. version: { major: appData[5], minor: appData[6] },
  37979. densityUnits: appData[7],
  37980. xDensity: (appData[8] << 8) | appData[9],
  37981. yDensity: (appData[10] << 8) | appData[11],
  37982. thumbWidth: appData[12],
  37983. thumbHeight: appData[13],
  37984. thumbData: appData.subarray(14, 14 +
  37985. 3 * appData[12] * appData[13])
  37986. };
  37987. }
  37988. }
  37989. // TODO APP1 - Exif
  37990. if (fileMarker === 0xFFEE) {
  37991. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  37992. appData[2] === 0x6F && appData[3] === 0x62 &&
  37993. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  37994. adobe = {
  37995. version: appData[6],
  37996. flags0: (appData[7] << 8) | appData[8],
  37997. flags1: (appData[9] << 8) | appData[10],
  37998. transformCode: appData[11]
  37999. };
  38000. }
  38001. }
  38002. break;
  38003. case 0xFFDB: // DQT (Define Quantization Tables)
  38004. var quantizationTablesLength = readUint16();
  38005. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38006. var z;
  38007. while (offset < quantizationTablesEnd) {
  38008. var quantizationTableSpec = data[offset++];
  38009. var tableData = new Uint16Array(64);
  38010. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38011. for (j = 0; j < 64; j++) {
  38012. z = dctZigZag[j];
  38013. tableData[z] = data[offset++];
  38014. }
  38015. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38016. for (j = 0; j < 64; j++) {
  38017. z = dctZigZag[j];
  38018. tableData[z] = readUint16();
  38019. }
  38020. } else {
  38021. throw 'DQT: invalid table spec';
  38022. }
  38023. quantizationTables[quantizationTableSpec & 15] = tableData;
  38024. }
  38025. break;
  38026. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38027. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38028. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38029. if (frame) {
  38030. throw 'Only single frame JPEGs supported';
  38031. }
  38032. readUint16(); // skip data length
  38033. frame = {};
  38034. frame.extended = (fileMarker === 0xFFC1);
  38035. frame.progressive = (fileMarker === 0xFFC2);
  38036. frame.precision = data[offset++];
  38037. frame.scanLines = readUint16();
  38038. frame.samplesPerLine = readUint16();
  38039. frame.components = [];
  38040. frame.componentIds = {};
  38041. var componentsCount = data[offset++], componentId;
  38042. var maxH = 0, maxV = 0;
  38043. for (i = 0; i < componentsCount; i++) {
  38044. componentId = data[offset];
  38045. var h = data[offset + 1] >> 4;
  38046. var v = data[offset + 1] & 15;
  38047. if (maxH < h) {
  38048. maxH = h;
  38049. }
  38050. if (maxV < v) {
  38051. maxV = v;
  38052. }
  38053. var qId = data[offset + 2];
  38054. l = frame.components.push({
  38055. h: h,
  38056. v: v,
  38057. quantizationTable: quantizationTables[qId]
  38058. });
  38059. frame.componentIds[componentId] = l - 1;
  38060. offset += 3;
  38061. }
  38062. frame.maxH = maxH;
  38063. frame.maxV = maxV;
  38064. prepareComponents(frame);
  38065. break;
  38066. case 0xFFC4: // DHT (Define Huffman Tables)
  38067. var huffmanLength = readUint16();
  38068. for (i = 2; i < huffmanLength;) {
  38069. var huffmanTableSpec = data[offset++];
  38070. var codeLengths = new Uint8Array(16);
  38071. var codeLengthSum = 0;
  38072. for (j = 0; j < 16; j++, offset++) {
  38073. codeLengthSum += (codeLengths[j] = data[offset]);
  38074. }
  38075. var huffmanValues = new Uint8Array(codeLengthSum);
  38076. for (j = 0; j < codeLengthSum; j++, offset++) {
  38077. huffmanValues[j] = data[offset];
  38078. }
  38079. i += 17 + codeLengthSum;
  38080. ((huffmanTableSpec >> 4) === 0 ?
  38081. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38082. buildHuffmanTable(codeLengths, huffmanValues);
  38083. }
  38084. break;
  38085. case 0xFFDD: // DRI (Define Restart Interval)
  38086. readUint16(); // skip data length
  38087. resetInterval = readUint16();
  38088. break;
  38089. case 0xFFDA: // SOS (Start of Scan)
  38090. var scanLength = readUint16();
  38091. var selectorsCount = data[offset++];
  38092. var components = [], component;
  38093. for (i = 0; i < selectorsCount; i++) {
  38094. var componentIndex = frame.componentIds[data[offset++]];
  38095. component = frame.components[componentIndex];
  38096. var tableSpec = data[offset++];
  38097. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38098. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38099. components.push(component);
  38100. }
  38101. var spectralStart = data[offset++];
  38102. var spectralEnd = data[offset++];
  38103. var successiveApproximation = data[offset++];
  38104. var processed = decodeScan(data, offset,
  38105. frame, components, resetInterval,
  38106. spectralStart, spectralEnd,
  38107. successiveApproximation >> 4, successiveApproximation & 15);
  38108. offset += processed;
  38109. break;
  38110. default:
  38111. if (data[offset - 3] === 0xFF &&
  38112. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38113. // could be incorrect encoding -- last 0xFF byte of the previous
  38114. // block was eaten by the encoder
  38115. offset -= 3;
  38116. break;
  38117. }
  38118. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38119. }
  38120. fileMarker = readUint16();
  38121. }
  38122. this.width = frame.samplesPerLine;
  38123. this.height = frame.scanLines;
  38124. this.jfif = jfif;
  38125. this.adobe = adobe;
  38126. this.components = [];
  38127. for (i = 0; i < frame.components.length; i++) {
  38128. component = frame.components[i];
  38129. this.components.push({
  38130. output: buildComponentData(frame, component),
  38131. scaleX: component.h / frame.maxH,
  38132. scaleY: component.v / frame.maxV,
  38133. blocksPerLine: component.blocksPerLine,
  38134. blocksPerColumn: component.blocksPerColumn
  38135. });
  38136. }
  38137. this.numComponents = this.components.length;
  38138. },
  38139. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38140. var scaleX = this.width / width, scaleY = this.height / height;
  38141. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38142. var x, y, i, j, k;
  38143. var index;
  38144. var offset = 0;
  38145. var output;
  38146. var numComponents = this.components.length;
  38147. var dataLength = width * height * numComponents;
  38148. var data = new Uint8Array(dataLength);
  38149. var xScaleBlockOffset = new Uint32Array(width);
  38150. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38151. for (i = 0; i < numComponents; i++) {
  38152. component = this.components[i];
  38153. componentScaleX = component.scaleX * scaleX;
  38154. componentScaleY = component.scaleY * scaleY;
  38155. offset = i;
  38156. output = component.output;
  38157. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38158. // precalculate the xScaleBlockOffset
  38159. for (x = 0; x < width; x++) {
  38160. j = 0 | (x * componentScaleX);
  38161. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38162. }
  38163. // linearize the blocks of the component
  38164. for (y = 0; y < height; y++) {
  38165. j = 0 | (y * componentScaleY);
  38166. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38167. for (x = 0; x < width; x++) {
  38168. data[offset] = output[index + xScaleBlockOffset[x]];
  38169. offset += numComponents;
  38170. }
  38171. }
  38172. }
  38173. // decodeTransform will contains pairs of multiplier (-256..256) and
  38174. // additive
  38175. var transform = this.decodeTransform;
  38176. if (transform) {
  38177. for (i = 0; i < dataLength;) {
  38178. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38179. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38180. }
  38181. }
  38182. }
  38183. return data;
  38184. },
  38185. _isColorConversionNeeded: function isColorConversionNeeded() {
  38186. if (this.adobe && this.adobe.transformCode) {
  38187. // The adobe transform marker overrides any previous setting
  38188. return true;
  38189. } else if (this.numComponents === 3) {
  38190. return true;
  38191. } else {
  38192. return false;
  38193. }
  38194. },
  38195. _convertYccToRgb: function convertYccToRgb(data) {
  38196. var Y, Cb, Cr;
  38197. for (var i = 0, length = data.length; i < length; i += 3) {
  38198. Y = data[i ];
  38199. Cb = data[i + 1];
  38200. Cr = data[i + 2];
  38201. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38202. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38203. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38204. }
  38205. return data;
  38206. },
  38207. _convertYcckToRgb: function convertYcckToRgb(data) {
  38208. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  38209. var offset = 0;
  38210. for (var i = 0, length = data.length; i < length; i += 4) {
  38211. Y = data[i];
  38212. Cb = data[i + 1];
  38213. Cr = data[i + 2];
  38214. k = data[i + 3];
  38215. CbCb = Cb * Cb;
  38216. CbCr = Cb * Cr;
  38217. CbY = Cb * Y;
  38218. Cbk = Cb * k;
  38219. CrCr = Cr * Cr;
  38220. Crk = Cr * k;
  38221. CrY = Cr * Y;
  38222. YY = Y * Y;
  38223. Yk = Y * k;
  38224. kk = k * k;
  38225. var r = - 122.67195406894 -
  38226. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  38227. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  38228. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  38229. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  38230. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  38231. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  38232. 0.000336197177618394 * kk + 0.484791561490776 * k;
  38233. var g = 107.268039397724 +
  38234. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  38235. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  38236. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  38237. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  38238. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  38239. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  38240. 0.000318913117588328 * kk - 0.213742400323665 * k;
  38241. var b = - 20.810012546947 -
  38242. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  38243. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  38244. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  38245. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  38246. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  38247. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  38248. 0.000343531996510555 * kk + 0.24165260232407 * k;
  38249. data[offset++] = clamp0to255(r);
  38250. data[offset++] = clamp0to255(g);
  38251. data[offset++] = clamp0to255(b);
  38252. }
  38253. return data;
  38254. },
  38255. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38256. var Y, Cb, Cr;
  38257. for (var i = 0, length = data.length; i < length; i += 4) {
  38258. Y = data[i];
  38259. Cb = data[i + 1];
  38260. Cr = data[i + 2];
  38261. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38262. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38263. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38264. // K in data[i + 3] is unchanged
  38265. }
  38266. return data;
  38267. },
  38268. _convertCmykToRgb: function convertCmykToRgb(data) {
  38269. var c, m, y, k;
  38270. var offset = 0;
  38271. var min = -255 * 255 * 255;
  38272. var scale = 1 / 255 / 255;
  38273. for (var i = 0, length = data.length; i < length; i += 4) {
  38274. c = data[i];
  38275. m = data[i + 1];
  38276. y = data[i + 2];
  38277. k = data[i + 3];
  38278. var r =
  38279. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38280. 18.82290502165302 * y + 212.25662451639585 * k -
  38281. 72734.4411664936) +
  38282. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38283. 17.873870861415444 * k - 1401.7366389350734) +
  38284. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38285. 4465.541406466231) -
  38286. k * (21.86122147463605 * k + 48317.86113160301);
  38287. var g =
  38288. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38289. 6.871425592049007 * y + 31.159100130055922 * k -
  38290. 20220.756542821975) +
  38291. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38292. 131.35250912493976 * k - 48691.05921601825) +
  38293. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38294. 6341.191035517494) -
  38295. k * (20.737325471181034 * k + 47890.15695978492);
  38296. var b =
  38297. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38298. 30.89978309703729 * y - 0.23883238689178934 * k -
  38299. 3616.812083916688) +
  38300. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38301. 50.606957656360734 * k - 28620.90484698408) +
  38302. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38303. 49363.43385999684) -
  38304. k * (22.33816807309886 * k + 45932.16563550634);
  38305. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38306. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38307. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38308. }
  38309. return data;
  38310. },
  38311. getData: function getData(width, height, forceRGBoutput) {
  38312. if (this.numComponents > 4) {
  38313. throw 'Unsupported color mode';
  38314. }
  38315. // type of data: Uint8Array(width * height * numComponents)
  38316. var data = this._getLinearizedBlockData(width, height);
  38317. if (this.numComponents === 3) {
  38318. return this._convertYccToRgb(data);
  38319. } else if (this.numComponents === 4) {
  38320. if (this._isColorConversionNeeded()) {
  38321. if (forceRGBoutput) {
  38322. return this._convertYcckToRgb(data);
  38323. } else {
  38324. return this._convertYcckToCmyk(data);
  38325. }
  38326. } else if (forceRGBoutput) {
  38327. return this._convertCmykToRgb(data);
  38328. }
  38329. }
  38330. return data;
  38331. }
  38332. };
  38333. return constructor;
  38334. })();
  38335. var JpxImage = (function JpxImageClosure() {
  38336. // Table E.1
  38337. var SubbandsGainLog2 = {
  38338. 'LL': 0,
  38339. 'LH': 1,
  38340. 'HL': 1,
  38341. 'HH': 2
  38342. };
  38343. function JpxImage() {
  38344. this.failOnCorruptedImage = false;
  38345. }
  38346. JpxImage.prototype = {
  38347. parse: function JpxImage_parse(data) {
  38348. var head = readUint16(data, 0);
  38349. // No box header, immediate start of codestream (SOC)
  38350. if (head === 0xFF4F) {
  38351. this.parseCodestream(data, 0, data.length);
  38352. return;
  38353. }
  38354. var position = 0, length = data.length;
  38355. while (position < length) {
  38356. var headerSize = 8;
  38357. var lbox = readUint32(data, position);
  38358. var tbox = readUint32(data, position + 4);
  38359. position += headerSize;
  38360. if (lbox === 1) {
  38361. // XLBox: read UInt64 according to spec.
  38362. // JavaScript's int precision of 53 bit should be sufficient here.
  38363. lbox = readUint32(data, position) * 4294967296 +
  38364. readUint32(data, position + 4);
  38365. position += 8;
  38366. headerSize += 8;
  38367. }
  38368. if (lbox === 0) {
  38369. lbox = length - position + headerSize;
  38370. }
  38371. if (lbox < headerSize) {
  38372. throw new Error('JPX Error: Invalid box field size');
  38373. }
  38374. var dataLength = lbox - headerSize;
  38375. var jumpDataLength = true;
  38376. switch (tbox) {
  38377. case 0x6A703268: // 'jp2h'
  38378. jumpDataLength = false; // parsing child boxes
  38379. break;
  38380. case 0x636F6C72: // 'colr'
  38381. // Colorspaces are not used, the CS from the PDF is used.
  38382. var method = data[position];
  38383. var precedence = data[position + 1];
  38384. var approximation = data[position + 2];
  38385. if (method === 1) {
  38386. // enumerated colorspace
  38387. var colorspace = readUint32(data, position + 3);
  38388. switch (colorspace) {
  38389. case 16: // this indicates a sRGB colorspace
  38390. case 17: // this indicates a grayscale colorspace
  38391. case 18: // this indicates a YUV colorspace
  38392. break;
  38393. default:
  38394. warn('Unknown colorspace ' + colorspace);
  38395. break;
  38396. }
  38397. } else if (method === 2) {
  38398. info('ICC profile not supported');
  38399. }
  38400. break;
  38401. case 0x6A703263: // 'jp2c'
  38402. this.parseCodestream(data, position, position + dataLength);
  38403. break;
  38404. case 0x6A502020: // 'jP\024\024'
  38405. if (0x0d0a870a !== readUint32(data, position)) {
  38406. warn('Invalid JP2 signature');
  38407. }
  38408. break;
  38409. // The following header types are valid but currently not used:
  38410. case 0x6A501A1A: // 'jP\032\032'
  38411. case 0x66747970: // 'ftyp'
  38412. case 0x72726571: // 'rreq'
  38413. case 0x72657320: // 'res '
  38414. case 0x69686472: // 'ihdr'
  38415. break;
  38416. default:
  38417. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38418. (tbox >> 16) & 0xFF,
  38419. (tbox >> 8) & 0xFF,
  38420. tbox & 0xFF);
  38421. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  38422. break;
  38423. }
  38424. if (jumpDataLength) {
  38425. position += dataLength;
  38426. }
  38427. }
  38428. },
  38429. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38430. var newByte = stream.getByte();
  38431. while (newByte >= 0) {
  38432. var oldByte = newByte;
  38433. newByte = stream.getByte();
  38434. var code = (oldByte << 8) | newByte;
  38435. // Image and tile size (SIZ)
  38436. if (code === 0xFF51) {
  38437. stream.skip(4);
  38438. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38439. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38440. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38441. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38442. stream.skip(16);
  38443. var Csiz = stream.getUint16(); // Byte 36
  38444. this.width = Xsiz - XOsiz;
  38445. this.height = Ysiz - YOsiz;
  38446. this.componentsCount = Csiz;
  38447. // Results are always returned as Uint8Arrays
  38448. this.bitsPerComponent = 8;
  38449. return;
  38450. }
  38451. }
  38452. throw new Error('JPX Error: No size marker found in JPX stream');
  38453. },
  38454. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38455. var context = {};
  38456. try {
  38457. var doNotRecover = false;
  38458. var position = start;
  38459. while (position + 1 < end) {
  38460. var code = readUint16(data, position);
  38461. position += 2;
  38462. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38463. switch (code) {
  38464. case 0xFF4F: // Start of codestream (SOC)
  38465. context.mainHeader = true;
  38466. break;
  38467. case 0xFFD9: // End of codestream (EOC)
  38468. break;
  38469. case 0xFF51: // Image and tile size (SIZ)
  38470. length = readUint16(data, position);
  38471. var siz = {};
  38472. siz.Xsiz = readUint32(data, position + 4);
  38473. siz.Ysiz = readUint32(data, position + 8);
  38474. siz.XOsiz = readUint32(data, position + 12);
  38475. siz.YOsiz = readUint32(data, position + 16);
  38476. siz.XTsiz = readUint32(data, position + 20);
  38477. siz.YTsiz = readUint32(data, position + 24);
  38478. siz.XTOsiz = readUint32(data, position + 28);
  38479. siz.YTOsiz = readUint32(data, position + 32);
  38480. var componentsCount = readUint16(data, position + 36);
  38481. siz.Csiz = componentsCount;
  38482. var components = [];
  38483. j = position + 38;
  38484. for (var i = 0; i < componentsCount; i++) {
  38485. var component = {
  38486. precision: (data[j] & 0x7F) + 1,
  38487. isSigned: !!(data[j] & 0x80),
  38488. XRsiz: data[j + 1],
  38489. YRsiz: data[j + 1]
  38490. };
  38491. calculateComponentDimensions(component, siz);
  38492. components.push(component);
  38493. }
  38494. context.SIZ = siz;
  38495. context.components = components;
  38496. calculateTileGrids(context, components);
  38497. context.QCC = [];
  38498. context.COC = [];
  38499. break;
  38500. case 0xFF55: // Tile-part lengths, main header (TLM)
  38501. var Ltlm = readUint16(data, position); // Marker segment length
  38502. // Skip tile length markers
  38503. position += Ltlm;
  38504. break;
  38505. case 0xFF5C: // Quantization default (QCD)
  38506. length = readUint16(data, position);
  38507. var qcd = {};
  38508. j = position + 2;
  38509. sqcd = data[j++];
  38510. switch (sqcd & 0x1F) {
  38511. case 0:
  38512. spqcdSize = 8;
  38513. scalarExpounded = true;
  38514. break;
  38515. case 1:
  38516. spqcdSize = 16;
  38517. scalarExpounded = false;
  38518. break;
  38519. case 2:
  38520. spqcdSize = 16;
  38521. scalarExpounded = true;
  38522. break;
  38523. default:
  38524. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38525. }
  38526. qcd.noQuantization = (spqcdSize === 8);
  38527. qcd.scalarExpounded = scalarExpounded;
  38528. qcd.guardBits = sqcd >> 5;
  38529. spqcds = [];
  38530. while (j < length + position) {
  38531. var spqcd = {};
  38532. if (spqcdSize === 8) {
  38533. spqcd.epsilon = data[j++] >> 3;
  38534. spqcd.mu = 0;
  38535. } else {
  38536. spqcd.epsilon = data[j] >> 3;
  38537. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38538. j += 2;
  38539. }
  38540. spqcds.push(spqcd);
  38541. }
  38542. qcd.SPqcds = spqcds;
  38543. if (context.mainHeader) {
  38544. context.QCD = qcd;
  38545. } else {
  38546. context.currentTile.QCD = qcd;
  38547. context.currentTile.QCC = [];
  38548. }
  38549. break;
  38550. case 0xFF5D: // Quantization component (QCC)
  38551. length = readUint16(data, position);
  38552. var qcc = {};
  38553. j = position + 2;
  38554. var cqcc;
  38555. if (context.SIZ.Csiz < 257) {
  38556. cqcc = data[j++];
  38557. } else {
  38558. cqcc = readUint16(data, j);
  38559. j += 2;
  38560. }
  38561. sqcd = data[j++];
  38562. switch (sqcd & 0x1F) {
  38563. case 0:
  38564. spqcdSize = 8;
  38565. scalarExpounded = true;
  38566. break;
  38567. case 1:
  38568. spqcdSize = 16;
  38569. scalarExpounded = false;
  38570. break;
  38571. case 2:
  38572. spqcdSize = 16;
  38573. scalarExpounded = true;
  38574. break;
  38575. default:
  38576. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38577. }
  38578. qcc.noQuantization = (spqcdSize === 8);
  38579. qcc.scalarExpounded = scalarExpounded;
  38580. qcc.guardBits = sqcd >> 5;
  38581. spqcds = [];
  38582. while (j < (length + position)) {
  38583. spqcd = {};
  38584. if (spqcdSize === 8) {
  38585. spqcd.epsilon = data[j++] >> 3;
  38586. spqcd.mu = 0;
  38587. } else {
  38588. spqcd.epsilon = data[j] >> 3;
  38589. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38590. j += 2;
  38591. }
  38592. spqcds.push(spqcd);
  38593. }
  38594. qcc.SPqcds = spqcds;
  38595. if (context.mainHeader) {
  38596. context.QCC[cqcc] = qcc;
  38597. } else {
  38598. context.currentTile.QCC[cqcc] = qcc;
  38599. }
  38600. break;
  38601. case 0xFF52: // Coding style default (COD)
  38602. length = readUint16(data, position);
  38603. var cod = {};
  38604. j = position + 2;
  38605. var scod = data[j++];
  38606. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  38607. cod.sopMarkerUsed = !!(scod & 2);
  38608. cod.ephMarkerUsed = !!(scod & 4);
  38609. cod.progressionOrder = data[j++];
  38610. cod.layersCount = readUint16(data, j);
  38611. j += 2;
  38612. cod.multipleComponentTransform = data[j++];
  38613. cod.decompositionLevelsCount = data[j++];
  38614. cod.xcb = (data[j++] & 0xF) + 2;
  38615. cod.ycb = (data[j++] & 0xF) + 2;
  38616. var blockStyle = data[j++];
  38617. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  38618. cod.resetContextProbabilities = !!(blockStyle & 2);
  38619. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  38620. cod.verticalyStripe = !!(blockStyle & 8);
  38621. cod.predictableTermination = !!(blockStyle & 16);
  38622. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  38623. cod.reversibleTransformation = data[j++];
  38624. if (cod.entropyCoderWithCustomPrecincts) {
  38625. var precinctsSizes = [];
  38626. while (j < length + position) {
  38627. var precinctsSize = data[j++];
  38628. precinctsSizes.push({
  38629. PPx: precinctsSize & 0xF,
  38630. PPy: precinctsSize >> 4
  38631. });
  38632. }
  38633. cod.precinctsSizes = precinctsSizes;
  38634. }
  38635. var unsupported = [];
  38636. if (cod.sopMarkerUsed) {
  38637. unsupported.push('sopMarkerUsed');
  38638. }
  38639. if (cod.ephMarkerUsed) {
  38640. unsupported.push('ephMarkerUsed');
  38641. }
  38642. if (cod.selectiveArithmeticCodingBypass) {
  38643. unsupported.push('selectiveArithmeticCodingBypass');
  38644. }
  38645. if (cod.resetContextProbabilities) {
  38646. unsupported.push('resetContextProbabilities');
  38647. }
  38648. if (cod.terminationOnEachCodingPass) {
  38649. unsupported.push('terminationOnEachCodingPass');
  38650. }
  38651. if (cod.verticalyStripe) {
  38652. unsupported.push('verticalyStripe');
  38653. }
  38654. if (cod.predictableTermination) {
  38655. unsupported.push('predictableTermination');
  38656. }
  38657. if (unsupported.length > 0) {
  38658. doNotRecover = true;
  38659. throw new Error('JPX Error: Unsupported COD options (' +
  38660. unsupported.join(', ') + ')');
  38661. }
  38662. if (context.mainHeader) {
  38663. context.COD = cod;
  38664. } else {
  38665. context.currentTile.COD = cod;
  38666. context.currentTile.COC = [];
  38667. }
  38668. break;
  38669. case 0xFF90: // Start of tile-part (SOT)
  38670. length = readUint16(data, position);
  38671. tile = {};
  38672. tile.index = readUint16(data, position + 2);
  38673. tile.length = readUint32(data, position + 4);
  38674. tile.dataEnd = tile.length + position - 2;
  38675. tile.partIndex = data[position + 8];
  38676. tile.partsCount = data[position + 9];
  38677. context.mainHeader = false;
  38678. if (tile.partIndex === 0) {
  38679. // reset component specific settings
  38680. tile.COD = context.COD;
  38681. tile.COC = context.COC.slice(0); // clone of the global COC
  38682. tile.QCD = context.QCD;
  38683. tile.QCC = context.QCC.slice(0); // clone of the global COC
  38684. }
  38685. context.currentTile = tile;
  38686. break;
  38687. case 0xFF93: // Start of data (SOD)
  38688. tile = context.currentTile;
  38689. if (tile.partIndex === 0) {
  38690. initializeTile(context, tile.index);
  38691. buildPackets(context);
  38692. }
  38693. // moving to the end of the data
  38694. length = tile.dataEnd - position;
  38695. parseTilePackets(context, data, position, length);
  38696. break;
  38697. case 0xFF64: // Comment (COM)
  38698. length = readUint16(data, position);
  38699. // skipping content
  38700. break;
  38701. case 0xFF53: // Coding style component (COC)
  38702. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  38703. 'not implemented');
  38704. default:
  38705. throw new Error('JPX Error: Unknown codestream code: ' +
  38706. code.toString(16));
  38707. }
  38708. position += length;
  38709. }
  38710. } catch (e) {
  38711. if (doNotRecover || this.failOnCorruptedImage) {
  38712. throw e;
  38713. } else {
  38714. warn('Trying to recover from ' + e.message);
  38715. }
  38716. }
  38717. this.tiles = transformComponents(context);
  38718. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  38719. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  38720. this.componentsCount = context.SIZ.Csiz;
  38721. }
  38722. };
  38723. function calculateComponentDimensions(component, siz) {
  38724. // Section B.2 Component mapping
  38725. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  38726. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  38727. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  38728. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  38729. component.width = component.x1 - component.x0;
  38730. component.height = component.y1 - component.y0;
  38731. }
  38732. function calculateTileGrids(context, components) {
  38733. var siz = context.SIZ;
  38734. // Section B.3 Division into tile and tile-components
  38735. var tile, tiles = [];
  38736. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  38737. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  38738. for (var q = 0; q < numYtiles; q++) {
  38739. for (var p = 0; p < numXtiles; p++) {
  38740. tile = {};
  38741. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  38742. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  38743. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  38744. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  38745. tile.width = tile.tx1 - tile.tx0;
  38746. tile.height = tile.ty1 - tile.ty0;
  38747. tile.components = [];
  38748. tiles.push(tile);
  38749. }
  38750. }
  38751. context.tiles = tiles;
  38752. var componentsCount = siz.Csiz;
  38753. for (var i = 0, ii = componentsCount; i < ii; i++) {
  38754. var component = components[i];
  38755. for (var j = 0, jj = tiles.length; j < jj; j++) {
  38756. var tileComponent = {};
  38757. tile = tiles[j];
  38758. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  38759. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  38760. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  38761. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  38762. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  38763. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  38764. tile.components[i] = tileComponent;
  38765. }
  38766. }
  38767. }
  38768. function getBlocksDimensions(context, component, r) {
  38769. var codOrCoc = component.codingStyleParameters;
  38770. var result = {};
  38771. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  38772. result.PPx = 15;
  38773. result.PPy = 15;
  38774. } else {
  38775. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  38776. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  38777. }
  38778. // calculate codeblock size as described in section B.7
  38779. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  38780. Math.min(codOrCoc.xcb, result.PPx));
  38781. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  38782. Math.min(codOrCoc.ycb, result.PPy));
  38783. return result;
  38784. }
  38785. function buildPrecincts(context, resolution, dimensions) {
  38786. // Section B.6 Division resolution to precincts
  38787. var precinctWidth = 1 << dimensions.PPx;
  38788. var precinctHeight = 1 << dimensions.PPy;
  38789. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  38790. Math.ceil(resolution.trx1 / precinctWidth) -
  38791. Math.floor(resolution.trx0 / precinctWidth) : 0);
  38792. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  38793. Math.ceil(resolution.try1 / precinctHeight) -
  38794. Math.floor(resolution.try0 / precinctHeight) : 0);
  38795. var numprecincts = numprecinctswide * numprecinctshigh;
  38796. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  38797. precinctWidth;
  38798. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  38799. precinctHeight;
  38800. resolution.precinctParameters = {
  38801. precinctXOffset: precinctXOffset,
  38802. precinctYOffset: precinctYOffset,
  38803. precinctWidth: precinctWidth,
  38804. precinctHeight: precinctHeight,
  38805. numprecinctswide: numprecinctswide,
  38806. numprecinctshigh: numprecinctshigh,
  38807. numprecincts: numprecincts
  38808. };
  38809. }
  38810. function buildCodeblocks(context, subband, dimensions) {
  38811. // Section B.7 Division sub-band into code-blocks
  38812. var xcb_ = dimensions.xcb_;
  38813. var ycb_ = dimensions.ycb_;
  38814. var codeblockWidth = 1 << xcb_;
  38815. var codeblockHeight = 1 << ycb_;
  38816. var cbx0 = subband.tbx0 >> xcb_;
  38817. var cby0 = subband.tby0 >> ycb_;
  38818. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  38819. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  38820. var precinctParameters = subband.resolution.precinctParameters;
  38821. var codeblocks = [];
  38822. var precincts = [];
  38823. var i, j, codeblock, precinctNumber;
  38824. for (j = cby0; j < cby1; j++) {
  38825. for (i = cbx0; i < cbx1; i++) {
  38826. codeblock = {
  38827. cbx: i,
  38828. cby: j,
  38829. tbx0: codeblockWidth * i,
  38830. tby0: codeblockHeight * j,
  38831. tbx1: codeblockWidth * (i + 1),
  38832. tby1: codeblockHeight * (j + 1)
  38833. };
  38834. // calculate precinct number
  38835. var pi = Math.floor((codeblock.tbx0 -
  38836. precinctParameters.precinctXOffset) /
  38837. precinctParameters.precinctWidth);
  38838. var pj = Math.floor((codeblock.tby0 -
  38839. precinctParameters.precinctYOffset) /
  38840. precinctParameters.precinctHeight);
  38841. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  38842. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  38843. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  38844. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  38845. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  38846. codeblock.precinctNumber = precinctNumber;
  38847. codeblock.subbandType = subband.type;
  38848. codeblock.Lblock = 3;
  38849. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  38850. codeblock.tby1_ <= codeblock.tby0_) {
  38851. continue;
  38852. }
  38853. codeblocks.push(codeblock);
  38854. // building precinct for the sub-band
  38855. var precinct = precincts[precinctNumber];
  38856. if (precinct !== undefined) {
  38857. if (i < precinct.cbxMin) {
  38858. precinct.cbxMin = i;
  38859. } else if (i > precinct.cbxMax) {
  38860. precinct.cbxMax = i;
  38861. }
  38862. if (j < precinct.cbyMin) {
  38863. precinct.cbxMin = j;
  38864. } else if (j > precinct.cbyMax) {
  38865. precinct.cbyMax = j;
  38866. }
  38867. } else {
  38868. precincts[precinctNumber] = precinct = {
  38869. cbxMin: i,
  38870. cbyMin: j,
  38871. cbxMax: i,
  38872. cbyMax: j
  38873. };
  38874. }
  38875. codeblock.precinct = precinct;
  38876. }
  38877. }
  38878. subband.codeblockParameters = {
  38879. codeblockWidth: xcb_,
  38880. codeblockHeight: ycb_,
  38881. numcodeblockwide: cbx1 - cbx0 + 1,
  38882. numcodeblockhigh: cby1 - cby0 + 1
  38883. };
  38884. subband.codeblocks = codeblocks;
  38885. subband.precincts = precincts;
  38886. }
  38887. function createPacket(resolution, precinctNumber, layerNumber) {
  38888. var precinctCodeblocks = [];
  38889. // Section B.10.8 Order of info in packet
  38890. var subbands = resolution.subbands;
  38891. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  38892. for (var i = 0, ii = subbands.length; i < ii; i++) {
  38893. var subband = subbands[i];
  38894. var codeblocks = subband.codeblocks;
  38895. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  38896. var codeblock = codeblocks[j];
  38897. if (codeblock.precinctNumber !== precinctNumber) {
  38898. continue;
  38899. }
  38900. precinctCodeblocks.push(codeblock);
  38901. }
  38902. }
  38903. return {
  38904. layerNumber: layerNumber,
  38905. codeblocks: precinctCodeblocks
  38906. };
  38907. }
  38908. function LayerResolutionComponentPositionIterator(context) {
  38909. var siz = context.SIZ;
  38910. var tileIndex = context.currentTile.index;
  38911. var tile = context.tiles[tileIndex];
  38912. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  38913. var componentsCount = siz.Csiz;
  38914. var maxDecompositionLevelsCount = 0;
  38915. for (var q = 0; q < componentsCount; q++) {
  38916. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  38917. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  38918. }
  38919. var l = 0, r = 0, i = 0, k = 0;
  38920. this.nextPacket = function JpxImage_nextPacket() {
  38921. // Section B.12.1.1 Layer-resolution-component-position
  38922. for (; l < layersCount; l++) {
  38923. for (; r <= maxDecompositionLevelsCount; r++) {
  38924. for (; i < componentsCount; i++) {
  38925. var component = tile.components[i];
  38926. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  38927. continue;
  38928. }
  38929. var resolution = component.resolutions[r];
  38930. var numprecincts = resolution.precinctParameters.numprecincts;
  38931. for (; k < numprecincts;) {
  38932. var packet = createPacket(resolution, k, l);
  38933. k++;
  38934. return packet;
  38935. }
  38936. k = 0;
  38937. }
  38938. i = 0;
  38939. }
  38940. r = 0;
  38941. }
  38942. throw new Error('JPX Error: Out of packets');
  38943. };
  38944. }
  38945. function ResolutionLayerComponentPositionIterator(context) {
  38946. var siz = context.SIZ;
  38947. var tileIndex = context.currentTile.index;
  38948. var tile = context.tiles[tileIndex];
  38949. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  38950. var componentsCount = siz.Csiz;
  38951. var maxDecompositionLevelsCount = 0;
  38952. for (var q = 0; q < componentsCount; q++) {
  38953. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  38954. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  38955. }
  38956. var r = 0, l = 0, i = 0, k = 0;
  38957. this.nextPacket = function JpxImage_nextPacket() {
  38958. // Section B.12.1.2 Resolution-layer-component-position
  38959. for (; r <= maxDecompositionLevelsCount; r++) {
  38960. for (; l < layersCount; l++) {
  38961. for (; i < componentsCount; i++) {
  38962. var component = tile.components[i];
  38963. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  38964. continue;
  38965. }
  38966. var resolution = component.resolutions[r];
  38967. var numprecincts = resolution.precinctParameters.numprecincts;
  38968. for (; k < numprecincts;) {
  38969. var packet = createPacket(resolution, k, l);
  38970. k++;
  38971. return packet;
  38972. }
  38973. k = 0;
  38974. }
  38975. i = 0;
  38976. }
  38977. l = 0;
  38978. }
  38979. throw new Error('JPX Error: Out of packets');
  38980. };
  38981. }
  38982. function buildPackets(context) {
  38983. var siz = context.SIZ;
  38984. var tileIndex = context.currentTile.index;
  38985. var tile = context.tiles[tileIndex];
  38986. var componentsCount = siz.Csiz;
  38987. // Creating resolutions and sub-bands for each component
  38988. for (var c = 0; c < componentsCount; c++) {
  38989. var component = tile.components[c];
  38990. var decompositionLevelsCount =
  38991. component.codingStyleParameters.decompositionLevelsCount;
  38992. // Section B.5 Resolution levels and sub-bands
  38993. var resolutions = [];
  38994. var subbands = [];
  38995. for (var r = 0; r <= decompositionLevelsCount; r++) {
  38996. var blocksDimensions = getBlocksDimensions(context, component, r);
  38997. var resolution = {};
  38998. var scale = 1 << (decompositionLevelsCount - r);
  38999. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39000. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39001. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39002. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39003. buildPrecincts(context, resolution, blocksDimensions);
  39004. resolutions.push(resolution);
  39005. var subband;
  39006. if (r === 0) {
  39007. // one sub-band (LL) with last decomposition
  39008. subband = {};
  39009. subband.type = 'LL';
  39010. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39011. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39012. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39013. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39014. subband.resolution = resolution;
  39015. buildCodeblocks(context, subband, blocksDimensions);
  39016. subbands.push(subband);
  39017. resolution.subbands = [subband];
  39018. } else {
  39019. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39020. var resolutionSubbands = [];
  39021. // three sub-bands (HL, LH and HH) with rest of decompositions
  39022. subband = {};
  39023. subband.type = 'HL';
  39024. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39025. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39026. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39027. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39028. subband.resolution = resolution;
  39029. buildCodeblocks(context, subband, blocksDimensions);
  39030. subbands.push(subband);
  39031. resolutionSubbands.push(subband);
  39032. subband = {};
  39033. subband.type = 'LH';
  39034. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39035. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39036. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39037. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39038. subband.resolution = resolution;
  39039. buildCodeblocks(context, subband, blocksDimensions);
  39040. subbands.push(subband);
  39041. resolutionSubbands.push(subband);
  39042. subband = {};
  39043. subband.type = 'HH';
  39044. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39045. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39046. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39047. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39048. subband.resolution = resolution;
  39049. buildCodeblocks(context, subband, blocksDimensions);
  39050. subbands.push(subband);
  39051. resolutionSubbands.push(subband);
  39052. resolution.subbands = resolutionSubbands;
  39053. }
  39054. }
  39055. component.resolutions = resolutions;
  39056. component.subbands = subbands;
  39057. }
  39058. // Generate the packets sequence
  39059. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39060. switch (progressionOrder) {
  39061. case 0:
  39062. tile.packetsIterator =
  39063. new LayerResolutionComponentPositionIterator(context);
  39064. break;
  39065. case 1:
  39066. tile.packetsIterator =
  39067. new ResolutionLayerComponentPositionIterator(context);
  39068. break;
  39069. default:
  39070. throw new Error('JPX Error: Unsupported progression order ' +
  39071. progressionOrder);
  39072. }
  39073. }
  39074. function parseTilePackets(context, data, offset, dataLength) {
  39075. var position = 0;
  39076. var buffer, bufferSize = 0, skipNextBit = false;
  39077. function readBits(count) {
  39078. while (bufferSize < count) {
  39079. var b = data[offset + position];
  39080. position++;
  39081. if (skipNextBit) {
  39082. buffer = (buffer << 7) | b;
  39083. bufferSize += 7;
  39084. skipNextBit = false;
  39085. } else {
  39086. buffer = (buffer << 8) | b;
  39087. bufferSize += 8;
  39088. }
  39089. if (b === 0xFF) {
  39090. skipNextBit = true;
  39091. }
  39092. }
  39093. bufferSize -= count;
  39094. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39095. }
  39096. function alignToByte() {
  39097. bufferSize = 0;
  39098. if (skipNextBit) {
  39099. position++;
  39100. skipNextBit = false;
  39101. }
  39102. }
  39103. function readCodingpasses() {
  39104. if (readBits(1) === 0) {
  39105. return 1;
  39106. }
  39107. if (readBits(1) === 0) {
  39108. return 2;
  39109. }
  39110. var value = readBits(2);
  39111. if (value < 3) {
  39112. return value + 3;
  39113. }
  39114. value = readBits(5);
  39115. if (value < 31) {
  39116. return value + 6;
  39117. }
  39118. value = readBits(7);
  39119. return value + 37;
  39120. }
  39121. var tileIndex = context.currentTile.index;
  39122. var tile = context.tiles[tileIndex];
  39123. var packetsIterator = tile.packetsIterator;
  39124. while (position < dataLength) {
  39125. alignToByte();
  39126. if (!readBits(1)) {
  39127. continue;
  39128. }
  39129. var packet = packetsIterator.nextPacket();
  39130. var layerNumber = packet.layerNumber;
  39131. var queue = [], codeblock;
  39132. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39133. codeblock = packet.codeblocks[i];
  39134. var precinct = codeblock.precinct;
  39135. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39136. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39137. var codeblockIncluded = false;
  39138. var firstTimeInclusion = false;
  39139. var valueReady;
  39140. if (codeblock['included'] !== undefined) {
  39141. codeblockIncluded = !!readBits(1);
  39142. } else {
  39143. // reading inclusion tree
  39144. precinct = codeblock.precinct;
  39145. var inclusionTree, zeroBitPlanesTree;
  39146. if (precinct['inclusionTree'] !== undefined) {
  39147. inclusionTree = precinct.inclusionTree;
  39148. } else {
  39149. // building inclusion and zero bit-planes trees
  39150. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39151. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39152. inclusionTree = new InclusionTree(width, height, layerNumber);
  39153. zeroBitPlanesTree = new TagTree(width, height);
  39154. precinct.inclusionTree = inclusionTree;
  39155. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39156. }
  39157. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39158. while (true) {
  39159. if (readBits(1)) {
  39160. valueReady = !inclusionTree.nextLevel();
  39161. if (valueReady) {
  39162. codeblock.included = true;
  39163. codeblockIncluded = firstTimeInclusion = true;
  39164. break;
  39165. }
  39166. } else {
  39167. inclusionTree.incrementValue(layerNumber);
  39168. break;
  39169. }
  39170. }
  39171. }
  39172. }
  39173. if (!codeblockIncluded) {
  39174. continue;
  39175. }
  39176. if (firstTimeInclusion) {
  39177. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39178. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39179. while (true) {
  39180. if (readBits(1)) {
  39181. valueReady = !zeroBitPlanesTree.nextLevel();
  39182. if (valueReady) {
  39183. break;
  39184. }
  39185. } else {
  39186. zeroBitPlanesTree.incrementValue();
  39187. }
  39188. }
  39189. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39190. }
  39191. var codingpasses = readCodingpasses();
  39192. while (readBits(1)) {
  39193. codeblock.Lblock++;
  39194. }
  39195. var codingpassesLog2 = log2(codingpasses);
  39196. // rounding down log2
  39197. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39198. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39199. var codedDataLength = readBits(bits);
  39200. queue.push({
  39201. codeblock: codeblock,
  39202. codingpasses: codingpasses,
  39203. dataLength: codedDataLength
  39204. });
  39205. }
  39206. alignToByte();
  39207. while (queue.length > 0) {
  39208. var packetItem = queue.shift();
  39209. codeblock = packetItem.codeblock;
  39210. if (codeblock['data'] === undefined) {
  39211. codeblock.data = [];
  39212. }
  39213. codeblock.data.push({
  39214. data: data,
  39215. start: offset + position,
  39216. end: offset + position + packetItem.dataLength,
  39217. codingpasses: packetItem.codingpasses
  39218. });
  39219. position += packetItem.dataLength;
  39220. }
  39221. }
  39222. return position;
  39223. }
  39224. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  39225. delta, mb, reversible, segmentationSymbolUsed) {
  39226. var x0 = subband.tbx0;
  39227. var y0 = subband.tby0;
  39228. var width = subband.tbx1 - subband.tbx0;
  39229. var codeblocks = subband.codeblocks;
  39230. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  39231. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  39232. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  39233. var codeblock = codeblocks[i];
  39234. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  39235. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  39236. if (blockWidth === 0 || blockHeight === 0) {
  39237. continue;
  39238. }
  39239. if (codeblock['data'] === undefined) {
  39240. continue;
  39241. }
  39242. var bitModel, currentCodingpassType;
  39243. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  39244. codeblock.zeroBitPlanes, mb);
  39245. currentCodingpassType = 2; // first bit plane starts from cleanup
  39246. // collect data
  39247. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  39248. var j, jj, dataItem;
  39249. for (j = 0, jj = data.length; j < jj; j++) {
  39250. dataItem = data[j];
  39251. totalLength += dataItem.end - dataItem.start;
  39252. codingpasses += dataItem.codingpasses;
  39253. }
  39254. var encodedData = new Uint8Array(totalLength);
  39255. var position = 0;
  39256. for (j = 0, jj = data.length; j < jj; j++) {
  39257. dataItem = data[j];
  39258. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  39259. encodedData.set(chunk, position);
  39260. position += chunk.length;
  39261. }
  39262. // decoding the item
  39263. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  39264. bitModel.setDecoder(decoder);
  39265. for (j = 0; j < codingpasses; j++) {
  39266. switch (currentCodingpassType) {
  39267. case 0:
  39268. bitModel.runSignificancePropogationPass();
  39269. break;
  39270. case 1:
  39271. bitModel.runMagnitudeRefinementPass();
  39272. break;
  39273. case 2:
  39274. bitModel.runCleanupPass();
  39275. if (segmentationSymbolUsed) {
  39276. bitModel.checkSegmentationSymbol();
  39277. }
  39278. break;
  39279. }
  39280. currentCodingpassType = (currentCodingpassType + 1) % 3;
  39281. }
  39282. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  39283. var sign = bitModel.coefficentsSign;
  39284. var magnitude = bitModel.coefficentsMagnitude;
  39285. var bitsDecoded = bitModel.bitsDecoded;
  39286. var magnitudeCorrection = reversible ? 0 : 0.5;
  39287. var k, n, nb;
  39288. position = 0;
  39289. // Do the interleaving of Section F.3.3 here, so we do not need
  39290. // to copy later. LL level is not interleaved, just copied.
  39291. var interleave = (subband.type !== 'LL');
  39292. for (j = 0; j < blockHeight; j++) {
  39293. var row = (offset / width) | 0; // row in the non-interleaved subband
  39294. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  39295. for (k = 0; k < blockWidth; k++) {
  39296. n = magnitude[position];
  39297. if (n !== 0) {
  39298. n = (n + magnitudeCorrection) * delta;
  39299. if (sign[position] !== 0) {
  39300. n = -n;
  39301. }
  39302. nb = bitsDecoded[position];
  39303. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  39304. if (reversible && (nb >= mb)) {
  39305. coefficients[pos] = n;
  39306. } else {
  39307. coefficients[pos] = n * (1 << (mb - nb));
  39308. }
  39309. }
  39310. offset++;
  39311. position++;
  39312. }
  39313. offset += width - blockWidth;
  39314. }
  39315. }
  39316. }
  39317. function transformTile(context, tile, c) {
  39318. var component = tile.components[c];
  39319. var codingStyleParameters = component.codingStyleParameters;
  39320. var quantizationParameters = component.quantizationParameters;
  39321. var decompositionLevelsCount =
  39322. codingStyleParameters.decompositionLevelsCount;
  39323. var spqcds = quantizationParameters.SPqcds;
  39324. var scalarExpounded = quantizationParameters.scalarExpounded;
  39325. var guardBits = quantizationParameters.guardBits;
  39326. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  39327. var precision = context.components[c].precision;
  39328. var reversible = codingStyleParameters.reversibleTransformation;
  39329. var transform = (reversible ? new ReversibleTransform() :
  39330. new IrreversibleTransform());
  39331. var subbandCoefficients = [];
  39332. var b = 0;
  39333. for (var i = 0; i <= decompositionLevelsCount; i++) {
  39334. var resolution = component.resolutions[i];
  39335. var width = resolution.trx1 - resolution.trx0;
  39336. var height = resolution.try1 - resolution.try0;
  39337. // Allocate space for the whole sublevel.
  39338. var coefficients = new Float32Array(width * height);
  39339. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  39340. var mu, epsilon;
  39341. if (!scalarExpounded) {
  39342. // formula E-5
  39343. mu = spqcds[0].mu;
  39344. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  39345. } else {
  39346. mu = spqcds[b].mu;
  39347. epsilon = spqcds[b].epsilon;
  39348. b++;
  39349. }
  39350. var subband = resolution.subbands[j];
  39351. var gainLog2 = SubbandsGainLog2[subband.type];
  39352. // calulate quantization coefficient (Section E.1.1.1)
  39353. var delta = (reversible ? 1 :
  39354. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  39355. var mb = (guardBits + epsilon - 1);
  39356. // In the first resolution level, copyCoefficients will fill the
  39357. // whole array with coefficients. In the succeding passes,
  39358. // copyCoefficients will consecutively fill in the values that belong
  39359. // to the interleaved positions of the HL, LH, and HH coefficients.
  39360. // The LL coefficients will then be interleaved in Transform.iterate().
  39361. copyCoefficients(coefficients, width, height, subband, delta, mb,
  39362. reversible, segmentationSymbolUsed);
  39363. }
  39364. subbandCoefficients.push({
  39365. width: width,
  39366. height: height,
  39367. items: coefficients
  39368. });
  39369. }
  39370. var result = transform.calculate(subbandCoefficients,
  39371. component.tcx0, component.tcy0);
  39372. return {
  39373. left: component.tcx0,
  39374. top: component.tcy0,
  39375. width: result.width,
  39376. height: result.height,
  39377. items: result.items
  39378. };
  39379. }
  39380. function transformComponents(context) {
  39381. var siz = context.SIZ;
  39382. var components = context.components;
  39383. var componentsCount = siz.Csiz;
  39384. var resultImages = [];
  39385. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  39386. var tile = context.tiles[i];
  39387. var transformedTiles = [];
  39388. var c;
  39389. for (c = 0; c < componentsCount; c++) {
  39390. transformedTiles[c] = transformTile(context, tile, c);
  39391. }
  39392. var tile0 = transformedTiles[0];
  39393. var out = new Uint8Array(tile0.items.length * componentsCount);
  39394. var result = {
  39395. left: tile0.left,
  39396. top: tile0.top,
  39397. width: tile0.width,
  39398. height: tile0.height,
  39399. items: out
  39400. };
  39401. // Section G.2.2 Inverse multi component transform
  39402. var shift, offset, max, min, maxK;
  39403. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  39404. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  39405. var fourComponents = componentsCount === 4;
  39406. var y0items = transformedTiles[0].items;
  39407. var y1items = transformedTiles[1].items;
  39408. var y2items = transformedTiles[2].items;
  39409. var y3items = fourComponents ? transformedTiles[3].items : null;
  39410. // HACK: The multiple component transform formulas below assume that
  39411. // all components have the same precision. With this in mind, we
  39412. // compute shift and offset only once.
  39413. shift = components[0].precision - 8;
  39414. offset = (128 << shift) + 0.5;
  39415. max = 255 * (1 << shift);
  39416. maxK = max * 0.5;
  39417. min = -maxK;
  39418. var component0 = tile.components[0];
  39419. var alpha01 = componentsCount - 3;
  39420. jj = y0items.length;
  39421. if (!component0.codingStyleParameters.reversibleTransformation) {
  39422. // inverse irreversible multiple component transform
  39423. for (j = 0; j < jj; j++, pos += alpha01) {
  39424. y0 = y0items[j] + offset;
  39425. y1 = y1items[j];
  39426. y2 = y2items[j];
  39427. r = y0 + 1.402 * y2;
  39428. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  39429. b = y0 + 1.772 * y1;
  39430. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  39431. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  39432. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  39433. }
  39434. } else {
  39435. // inverse reversible multiple component transform
  39436. for (j = 0; j < jj; j++, pos += alpha01) {
  39437. y0 = y0items[j] + offset;
  39438. y1 = y1items[j];
  39439. y2 = y2items[j];
  39440. g = y0 - ((y2 + y1) >> 2);
  39441. r = g + y2;
  39442. b = g + y1;
  39443. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  39444. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  39445. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  39446. }
  39447. }
  39448. if (fourComponents) {
  39449. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  39450. k = y3items[j];
  39451. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  39452. }
  39453. }
  39454. } else { // no multi-component transform
  39455. for (c = 0; c < componentsCount; c++) {
  39456. var items = transformedTiles[c].items;
  39457. shift = components[c].precision - 8;
  39458. offset = (128 << shift) + 0.5;
  39459. max = (127.5 * (1 << shift));
  39460. min = -max;
  39461. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  39462. val = items[j];
  39463. out[pos] = val <= min ? 0 :
  39464. val >= max ? 255 : (val + offset) >> shift;
  39465. pos += componentsCount;
  39466. }
  39467. }
  39468. }
  39469. resultImages.push(result);
  39470. }
  39471. return resultImages;
  39472. }
  39473. function initializeTile(context, tileIndex) {
  39474. var siz = context.SIZ;
  39475. var componentsCount = siz.Csiz;
  39476. var tile = context.tiles[tileIndex];
  39477. for (var c = 0; c < componentsCount; c++) {
  39478. var component = tile.components[c];
  39479. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  39480. context.currentTile.QCC[c] : context.currentTile.QCD);
  39481. component.quantizationParameters = qcdOrQcc;
  39482. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  39483. context.currentTile.COC[c] : context.currentTile.COD);
  39484. component.codingStyleParameters = codOrCoc;
  39485. }
  39486. tile.codingStyleDefaultParameters = context.currentTile.COD;
  39487. }
  39488. // Section B.10.2 Tag trees
  39489. var TagTree = (function TagTreeClosure() {
  39490. function TagTree(width, height) {
  39491. var levelsLength = log2(Math.max(width, height)) + 1;
  39492. this.levels = [];
  39493. for (var i = 0; i < levelsLength; i++) {
  39494. var level = {
  39495. width: width,
  39496. height: height,
  39497. items: []
  39498. };
  39499. this.levels.push(level);
  39500. width = Math.ceil(width / 2);
  39501. height = Math.ceil(height / 2);
  39502. }
  39503. }
  39504. TagTree.prototype = {
  39505. reset: function TagTree_reset(i, j) {
  39506. var currentLevel = 0, value = 0, level;
  39507. while (currentLevel < this.levels.length) {
  39508. level = this.levels[currentLevel];
  39509. var index = i + j * level.width;
  39510. if (level.items[index] !== undefined) {
  39511. value = level.items[index];
  39512. break;
  39513. }
  39514. level.index = index;
  39515. i >>= 1;
  39516. j >>= 1;
  39517. currentLevel++;
  39518. }
  39519. currentLevel--;
  39520. level = this.levels[currentLevel];
  39521. level.items[level.index] = value;
  39522. this.currentLevel = currentLevel;
  39523. delete this.value;
  39524. },
  39525. incrementValue: function TagTree_incrementValue() {
  39526. var level = this.levels[this.currentLevel];
  39527. level.items[level.index]++;
  39528. },
  39529. nextLevel: function TagTree_nextLevel() {
  39530. var currentLevel = this.currentLevel;
  39531. var level = this.levels[currentLevel];
  39532. var value = level.items[level.index];
  39533. currentLevel--;
  39534. if (currentLevel < 0) {
  39535. this.value = value;
  39536. return false;
  39537. }
  39538. this.currentLevel = currentLevel;
  39539. level = this.levels[currentLevel];
  39540. level.items[level.index] = value;
  39541. return true;
  39542. }
  39543. };
  39544. return TagTree;
  39545. })();
  39546. var InclusionTree = (function InclusionTreeClosure() {
  39547. function InclusionTree(width, height, defaultValue) {
  39548. var levelsLength = log2(Math.max(width, height)) + 1;
  39549. this.levels = [];
  39550. for (var i = 0; i < levelsLength; i++) {
  39551. var items = new Uint8Array(width * height);
  39552. for (var j = 0, jj = items.length; j < jj; j++) {
  39553. items[j] = defaultValue;
  39554. }
  39555. var level = {
  39556. width: width,
  39557. height: height,
  39558. items: items
  39559. };
  39560. this.levels.push(level);
  39561. width = Math.ceil(width / 2);
  39562. height = Math.ceil(height / 2);
  39563. }
  39564. }
  39565. InclusionTree.prototype = {
  39566. reset: function InclusionTree_reset(i, j, stopValue) {
  39567. var currentLevel = 0;
  39568. while (currentLevel < this.levels.length) {
  39569. var level = this.levels[currentLevel];
  39570. var index = i + j * level.width;
  39571. level.index = index;
  39572. var value = level.items[index];
  39573. if (value === 0xFF) {
  39574. break;
  39575. }
  39576. if (value > stopValue) {
  39577. this.currentLevel = currentLevel;
  39578. // already know about this one, propagating the value to top levels
  39579. this.propagateValues();
  39580. return false;
  39581. }
  39582. i >>= 1;
  39583. j >>= 1;
  39584. currentLevel++;
  39585. }
  39586. this.currentLevel = currentLevel - 1;
  39587. return true;
  39588. },
  39589. incrementValue: function InclusionTree_incrementValue(stopValue) {
  39590. var level = this.levels[this.currentLevel];
  39591. level.items[level.index] = stopValue + 1;
  39592. this.propagateValues();
  39593. },
  39594. propagateValues: function InclusionTree_propagateValues() {
  39595. var levelIndex = this.currentLevel;
  39596. var level = this.levels[levelIndex];
  39597. var currentValue = level.items[level.index];
  39598. while (--levelIndex >= 0) {
  39599. level = this.levels[levelIndex];
  39600. level.items[level.index] = currentValue;
  39601. }
  39602. },
  39603. nextLevel: function InclusionTree_nextLevel() {
  39604. var currentLevel = this.currentLevel;
  39605. var level = this.levels[currentLevel];
  39606. var value = level.items[level.index];
  39607. level.items[level.index] = 0xFF;
  39608. currentLevel--;
  39609. if (currentLevel < 0) {
  39610. return false;
  39611. }
  39612. this.currentLevel = currentLevel;
  39613. level = this.levels[currentLevel];
  39614. level.items[level.index] = value;
  39615. return true;
  39616. }
  39617. };
  39618. return InclusionTree;
  39619. })();
  39620. // Section D. Coefficient bit modeling
  39621. var BitModel = (function BitModelClosure() {
  39622. var UNIFORM_CONTEXT = 17;
  39623. var RUNLENGTH_CONTEXT = 18;
  39624. // Table D-1
  39625. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  39626. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  39627. var LLAndLHContextsLabel = new Uint8Array([
  39628. 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,
  39629. 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,
  39630. 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
  39631. ]);
  39632. var HLContextLabel = new Uint8Array([
  39633. 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,
  39634. 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,
  39635. 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
  39636. ]);
  39637. var HHContextLabel = new Uint8Array([
  39638. 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,
  39639. 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,
  39640. 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
  39641. ]);
  39642. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  39643. this.width = width;
  39644. this.height = height;
  39645. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  39646. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  39647. var coefficientCount = width * height;
  39648. // coefficients outside the encoding region treated as insignificant
  39649. // add border state cells for significanceState
  39650. this.neighborsSignificance = new Uint8Array(coefficientCount);
  39651. this.coefficentsSign = new Uint8Array(coefficientCount);
  39652. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  39653. mb > 6 ? new Uint16Array(coefficientCount) :
  39654. new Uint8Array(coefficientCount);
  39655. this.processingFlags = new Uint8Array(coefficientCount);
  39656. var bitsDecoded = new Uint8Array(coefficientCount);
  39657. if (zeroBitPlanes !== 0) {
  39658. for (var i = 0; i < coefficientCount; i++) {
  39659. bitsDecoded[i] = zeroBitPlanes;
  39660. }
  39661. }
  39662. this.bitsDecoded = bitsDecoded;
  39663. this.reset();
  39664. }
  39665. BitModel.prototype = {
  39666. setDecoder: function BitModel_setDecoder(decoder) {
  39667. this.decoder = decoder;
  39668. },
  39669. reset: function BitModel_reset() {
  39670. // We have 17 contexts that are accessed via context labels,
  39671. // plus the uniform and runlength context.
  39672. this.contexts = new Int8Array(19);
  39673. // Contexts are packed into 1 byte:
  39674. // highest 7 bits carry the index, lowest bit carries mps
  39675. this.contexts[0] = (4 << 1) | 0;
  39676. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  39677. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  39678. },
  39679. setNeighborsSignificance:
  39680. function BitModel_setNeighborsSignificance(row, column, index) {
  39681. var neighborsSignificance = this.neighborsSignificance;
  39682. var width = this.width, height = this.height;
  39683. var left = (column > 0);
  39684. var right = (column + 1 < width);
  39685. var i;
  39686. if (row > 0) {
  39687. i = index - width;
  39688. if (left) {
  39689. neighborsSignificance[i - 1] += 0x10;
  39690. }
  39691. if (right) {
  39692. neighborsSignificance[i + 1] += 0x10;
  39693. }
  39694. neighborsSignificance[i] += 0x04;
  39695. }
  39696. if (row + 1 < height) {
  39697. i = index + width;
  39698. if (left) {
  39699. neighborsSignificance[i - 1] += 0x10;
  39700. }
  39701. if (right) {
  39702. neighborsSignificance[i + 1] += 0x10;
  39703. }
  39704. neighborsSignificance[i] += 0x04;
  39705. }
  39706. if (left) {
  39707. neighborsSignificance[index - 1] += 0x01;
  39708. }
  39709. if (right) {
  39710. neighborsSignificance[index + 1] += 0x01;
  39711. }
  39712. neighborsSignificance[index] |= 0x80;
  39713. },
  39714. runSignificancePropogationPass:
  39715. function BitModel_runSignificancePropogationPass() {
  39716. var decoder = this.decoder;
  39717. var width = this.width, height = this.height;
  39718. var coefficentsMagnitude = this.coefficentsMagnitude;
  39719. var coefficentsSign = this.coefficentsSign;
  39720. var neighborsSignificance = this.neighborsSignificance;
  39721. var processingFlags = this.processingFlags;
  39722. var contexts = this.contexts;
  39723. var labels = this.contextLabelTable;
  39724. var bitsDecoded = this.bitsDecoded;
  39725. var processedInverseMask = ~1;
  39726. var processedMask = 1;
  39727. var firstMagnitudeBitMask = 2;
  39728. for (var i0 = 0; i0 < height; i0 += 4) {
  39729. for (var j = 0; j < width; j++) {
  39730. var index = i0 * width + j;
  39731. for (var i1 = 0; i1 < 4; i1++, index += width) {
  39732. var i = i0 + i1;
  39733. if (i >= height) {
  39734. break;
  39735. }
  39736. // clear processed flag first
  39737. processingFlags[index] &= processedInverseMask;
  39738. if (coefficentsMagnitude[index] ||
  39739. !neighborsSignificance[index]) {
  39740. continue;
  39741. }
  39742. var contextLabel = labels[neighborsSignificance[index]];
  39743. var decision = decoder.readBit(contexts, contextLabel);
  39744. if (decision) {
  39745. var sign = this.decodeSignBit(i, j, index);
  39746. coefficentsSign[index] = sign;
  39747. coefficentsMagnitude[index] = 1;
  39748. this.setNeighborsSignificance(i, j, index);
  39749. processingFlags[index] |= firstMagnitudeBitMask;
  39750. }
  39751. bitsDecoded[index]++;
  39752. processingFlags[index] |= processedMask;
  39753. }
  39754. }
  39755. }
  39756. },
  39757. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  39758. var width = this.width, height = this.height;
  39759. var coefficentsMagnitude = this.coefficentsMagnitude;
  39760. var coefficentsSign = this.coefficentsSign;
  39761. var contribution, sign0, sign1, significance1;
  39762. var contextLabel, decoded;
  39763. // calculate horizontal contribution
  39764. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  39765. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  39766. sign1 = coefficentsSign[index + 1];
  39767. if (significance1) {
  39768. sign0 = coefficentsSign[index - 1];
  39769. contribution = 1 - sign1 - sign0;
  39770. } else {
  39771. contribution = 1 - sign1 - sign1;
  39772. }
  39773. } else if (significance1) {
  39774. sign0 = coefficentsSign[index - 1];
  39775. contribution = 1 - sign0 - sign0;
  39776. } else {
  39777. contribution = 0;
  39778. }
  39779. var horizontalContribution = 3 * contribution;
  39780. // calculate vertical contribution and combine with the horizontal
  39781. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  39782. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  39783. sign1 = coefficentsSign[index + width];
  39784. if (significance1) {
  39785. sign0 = coefficentsSign[index - width];
  39786. contribution = 1 - sign1 - sign0 + horizontalContribution;
  39787. } else {
  39788. contribution = 1 - sign1 - sign1 + horizontalContribution;
  39789. }
  39790. } else if (significance1) {
  39791. sign0 = coefficentsSign[index - width];
  39792. contribution = 1 - sign0 - sign0 + horizontalContribution;
  39793. } else {
  39794. contribution = horizontalContribution;
  39795. }
  39796. if (contribution >= 0) {
  39797. contextLabel = 9 + contribution;
  39798. decoded = this.decoder.readBit(this.contexts, contextLabel);
  39799. } else {
  39800. contextLabel = 9 - contribution;
  39801. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  39802. }
  39803. return decoded;
  39804. },
  39805. runMagnitudeRefinementPass:
  39806. function BitModel_runMagnitudeRefinementPass() {
  39807. var decoder = this.decoder;
  39808. var width = this.width, height = this.height;
  39809. var coefficentsMagnitude = this.coefficentsMagnitude;
  39810. var neighborsSignificance = this.neighborsSignificance;
  39811. var contexts = this.contexts;
  39812. var bitsDecoded = this.bitsDecoded;
  39813. var processingFlags = this.processingFlags;
  39814. var processedMask = 1;
  39815. var firstMagnitudeBitMask = 2;
  39816. var length = width * height;
  39817. var width4 = width * 4;
  39818. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  39819. indexNext = Math.min(length, index0 + width4);
  39820. for (var j = 0; j < width; j++) {
  39821. for (var index = index0 + j; index < indexNext; index += width) {
  39822. // significant but not those that have just become
  39823. if (!coefficentsMagnitude[index] ||
  39824. (processingFlags[index] & processedMask) !== 0) {
  39825. continue;
  39826. }
  39827. var contextLabel = 16;
  39828. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  39829. processingFlags[index] ^= firstMagnitudeBitMask;
  39830. // first refinement
  39831. var significance = neighborsSignificance[index] & 127;
  39832. contextLabel = significance === 0 ? 15 : 14;
  39833. }
  39834. var bit = decoder.readBit(contexts, contextLabel);
  39835. coefficentsMagnitude[index] =
  39836. (coefficentsMagnitude[index] << 1) | bit;
  39837. bitsDecoded[index]++;
  39838. processingFlags[index] |= processedMask;
  39839. }
  39840. }
  39841. }
  39842. },
  39843. runCleanupPass: function BitModel_runCleanupPass() {
  39844. var decoder = this.decoder;
  39845. var width = this.width, height = this.height;
  39846. var neighborsSignificance = this.neighborsSignificance;
  39847. var coefficentsMagnitude = this.coefficentsMagnitude;
  39848. var coefficentsSign = this.coefficentsSign;
  39849. var contexts = this.contexts;
  39850. var labels = this.contextLabelTable;
  39851. var bitsDecoded = this.bitsDecoded;
  39852. var processingFlags = this.processingFlags;
  39853. var processedMask = 1;
  39854. var firstMagnitudeBitMask = 2;
  39855. var oneRowDown = width;
  39856. var twoRowsDown = width * 2;
  39857. var threeRowsDown = width * 3;
  39858. var iNext;
  39859. for (var i0 = 0; i0 < height; i0 = iNext) {
  39860. iNext = Math.min(i0 + 4, height);
  39861. var indexBase = i0 * width;
  39862. var checkAllEmpty = i0 + 3 < height;
  39863. for (var j = 0; j < width; j++) {
  39864. var index0 = indexBase + j;
  39865. // using the property: labels[neighborsSignificance[index]] === 0
  39866. // when neighborsSignificance[index] === 0
  39867. var allEmpty = (checkAllEmpty &&
  39868. processingFlags[index0] === 0 &&
  39869. processingFlags[index0 + oneRowDown] === 0 &&
  39870. processingFlags[index0 + twoRowsDown] === 0 &&
  39871. processingFlags[index0 + threeRowsDown] === 0 &&
  39872. neighborsSignificance[index0] === 0 &&
  39873. neighborsSignificance[index0 + oneRowDown] === 0 &&
  39874. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  39875. neighborsSignificance[index0 + threeRowsDown] === 0);
  39876. var i1 = 0, index = index0;
  39877. var i = i0, sign;
  39878. if (allEmpty) {
  39879. var hasSignificantCoefficent =
  39880. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  39881. if (!hasSignificantCoefficent) {
  39882. bitsDecoded[index0]++;
  39883. bitsDecoded[index0 + oneRowDown]++;
  39884. bitsDecoded[index0 + twoRowsDown]++;
  39885. bitsDecoded[index0 + threeRowsDown]++;
  39886. continue; // next column
  39887. }
  39888. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  39889. decoder.readBit(contexts, UNIFORM_CONTEXT);
  39890. if (i1 !== 0) {
  39891. i = i0 + i1;
  39892. index += i1 * width;
  39893. }
  39894. sign = this.decodeSignBit(i, j, index);
  39895. coefficentsSign[index] = sign;
  39896. coefficentsMagnitude[index] = 1;
  39897. this.setNeighborsSignificance(i, j, index);
  39898. processingFlags[index] |= firstMagnitudeBitMask;
  39899. index = index0;
  39900. for (var i2 = i0; i2 <= i; i2++, index += width) {
  39901. bitsDecoded[index]++;
  39902. }
  39903. i1++;
  39904. }
  39905. for (i = i0 + i1; i < iNext; i++, index += width) {
  39906. if (coefficentsMagnitude[index] ||
  39907. (processingFlags[index] & processedMask) !== 0) {
  39908. continue;
  39909. }
  39910. var contextLabel = labels[neighborsSignificance[index]];
  39911. var decision = decoder.readBit(contexts, contextLabel);
  39912. if (decision === 1) {
  39913. sign = this.decodeSignBit(i, j, index);
  39914. coefficentsSign[index] = sign;
  39915. coefficentsMagnitude[index] = 1;
  39916. this.setNeighborsSignificance(i, j, index);
  39917. processingFlags[index] |= firstMagnitudeBitMask;
  39918. }
  39919. bitsDecoded[index]++;
  39920. }
  39921. }
  39922. }
  39923. },
  39924. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  39925. var decoder = this.decoder;
  39926. var contexts = this.contexts;
  39927. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  39928. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  39929. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  39930. decoder.readBit(contexts, UNIFORM_CONTEXT);
  39931. if (symbol !== 0xA) {
  39932. throw new Error('JPX Error: Invalid segmentation symbol');
  39933. }
  39934. }
  39935. };
  39936. return BitModel;
  39937. })();
  39938. // Section F, Discrete wavelet transformation
  39939. var Transform = (function TransformClosure() {
  39940. function Transform() {}
  39941. Transform.prototype.calculate =
  39942. function transformCalculate(subbands, u0, v0) {
  39943. var ll = subbands[0];
  39944. for (var i = 1, ii = subbands.length; i < ii; i++) {
  39945. ll = this.iterate(ll, subbands[i], u0, v0);
  39946. }
  39947. return ll;
  39948. };
  39949. Transform.prototype.extend = function extend(buffer, offset, size) {
  39950. // Section F.3.7 extending... using max extension of 4
  39951. var i1 = offset - 1, j1 = offset + 1;
  39952. var i2 = offset + size - 2, j2 = offset + size;
  39953. buffer[i1--] = buffer[j1++];
  39954. buffer[j2++] = buffer[i2--];
  39955. buffer[i1--] = buffer[j1++];
  39956. buffer[j2++] = buffer[i2--];
  39957. buffer[i1--] = buffer[j1++];
  39958. buffer[j2++] = buffer[i2--];
  39959. buffer[i1] = buffer[j1];
  39960. buffer[j2] = buffer[i2];
  39961. };
  39962. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  39963. u0, v0) {
  39964. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  39965. var width = hl_lh_hh.width;
  39966. var height = hl_lh_hh.height;
  39967. var items = hl_lh_hh.items;
  39968. var i, j, k, l, u, v;
  39969. // Interleave LL according to Section F.3.3
  39970. for (k = 0, i = 0; i < llHeight; i++) {
  39971. l = i * 2 * width;
  39972. for (j = 0; j < llWidth; j++, k++, l += 2) {
  39973. items[l] = llItems[k];
  39974. }
  39975. }
  39976. // The LL band is not needed anymore.
  39977. llItems = ll.items = null;
  39978. var bufferPadding = 4;
  39979. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  39980. // Section F.3.4 HOR_SR
  39981. if (width === 1) {
  39982. // if width = 1, when u0 even keep items as is, when odd divide by 2
  39983. if ((u0 & 1) !== 0) {
  39984. for (v = 0, k = 0; v < height; v++, k += width) {
  39985. items[k] *= 0.5;
  39986. }
  39987. }
  39988. } else {
  39989. for (v = 0, k = 0; v < height; v++, k += width) {
  39990. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  39991. this.extend(rowBuffer, bufferPadding, width);
  39992. this.filter(rowBuffer, bufferPadding, width);
  39993. items.set(
  39994. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  39995. k);
  39996. }
  39997. }
  39998. // Accesses to the items array can take long, because it may not fit into
  39999. // CPU cache and has to be fetched from main memory. Since subsequent
  40000. // accesses to the items array are not local when reading columns, we
  40001. // have a cache miss every time. To reduce cache misses, get up to
  40002. // 'numBuffers' items at a time and store them into the individual
  40003. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40004. var numBuffers = 16;
  40005. var colBuffers = [];
  40006. for (i = 0; i < numBuffers; i++) {
  40007. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40008. }
  40009. var b, currentBuffer = 0;
  40010. ll = bufferPadding + height;
  40011. // Section F.3.5 VER_SR
  40012. if (height === 1) {
  40013. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40014. if ((v0 & 1) !== 0) {
  40015. for (u = 0; u < width; u++) {
  40016. items[u] *= 0.5;
  40017. }
  40018. }
  40019. } else {
  40020. for (u = 0; u < width; u++) {
  40021. // if we ran out of buffers, copy several image columns at once
  40022. if (currentBuffer === 0) {
  40023. numBuffers = Math.min(width - u, numBuffers);
  40024. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40025. for (b = 0; b < numBuffers; b++) {
  40026. colBuffers[b][l] = items[k + b];
  40027. }
  40028. }
  40029. currentBuffer = numBuffers;
  40030. }
  40031. currentBuffer--;
  40032. var buffer = colBuffers[currentBuffer];
  40033. this.extend(buffer, bufferPadding, height);
  40034. this.filter(buffer, bufferPadding, height);
  40035. // If this is last buffer in this group of buffers, flush all buffers.
  40036. if (currentBuffer === 0) {
  40037. k = u - numBuffers + 1;
  40038. for (l = bufferPadding; l < ll; k += width, l++) {
  40039. for (b = 0; b < numBuffers; b++) {
  40040. items[k + b] = colBuffers[b][l];
  40041. }
  40042. }
  40043. }
  40044. }
  40045. }
  40046. return {
  40047. width: width,
  40048. height: height,
  40049. items: items
  40050. };
  40051. };
  40052. return Transform;
  40053. })();
  40054. // Section 3.8.2 Irreversible 9-7 filter
  40055. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40056. function IrreversibleTransform() {
  40057. Transform.call(this);
  40058. }
  40059. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40060. IrreversibleTransform.prototype.filter =
  40061. function irreversibleTransformFilter(x, offset, length) {
  40062. var len = length >> 1;
  40063. offset = offset | 0;
  40064. var j, n, current, next;
  40065. var alpha = -1.586134342059924;
  40066. var beta = -0.052980118572961;
  40067. var gamma = 0.882911075530934;
  40068. var delta = 0.443506852043971;
  40069. var K = 1.230174104914001;
  40070. var K_ = 1 / K;
  40071. // step 1 is combined with step 3
  40072. // step 2
  40073. j = offset - 3;
  40074. for (n = len + 4; n--; j += 2) {
  40075. x[j] *= K_;
  40076. }
  40077. // step 1 & 3
  40078. j = offset - 2;
  40079. current = delta * x[j -1];
  40080. for (n = len + 3; n--; j += 2) {
  40081. next = delta * x[j + 1];
  40082. x[j] = K * x[j] - current - next;
  40083. if (n--) {
  40084. j += 2;
  40085. current = delta * x[j + 1];
  40086. x[j] = K * x[j] - current - next;
  40087. } else {
  40088. break;
  40089. }
  40090. }
  40091. // step 4
  40092. j = offset - 1;
  40093. current = gamma * x[j - 1];
  40094. for (n = len + 2; n--; j += 2) {
  40095. next = gamma * x[j + 1];
  40096. x[j] -= current + next;
  40097. if (n--) {
  40098. j += 2;
  40099. current = gamma * x[j + 1];
  40100. x[j] -= current + next;
  40101. } else {
  40102. break;
  40103. }
  40104. }
  40105. // step 5
  40106. j = offset;
  40107. current = beta * x[j - 1];
  40108. for (n = len + 1; n--; j += 2) {
  40109. next = beta * x[j + 1];
  40110. x[j] -= current + next;
  40111. if (n--) {
  40112. j += 2;
  40113. current = beta * x[j + 1];
  40114. x[j] -= current + next;
  40115. } else {
  40116. break;
  40117. }
  40118. }
  40119. // step 6
  40120. if (len !== 0) {
  40121. j = offset + 1;
  40122. current = alpha * x[j - 1];
  40123. for (n = len; n--; j += 2) {
  40124. next = alpha * x[j + 1];
  40125. x[j] -= current + next;
  40126. if (n--) {
  40127. j += 2;
  40128. current = alpha * x[j + 1];
  40129. x[j] -= current + next;
  40130. } else {
  40131. break;
  40132. }
  40133. }
  40134. }
  40135. };
  40136. return IrreversibleTransform;
  40137. })();
  40138. // Section 3.8.1 Reversible 5-3 filter
  40139. var ReversibleTransform = (function ReversibleTransformClosure() {
  40140. function ReversibleTransform() {
  40141. Transform.call(this);
  40142. }
  40143. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40144. ReversibleTransform.prototype.filter =
  40145. function reversibleTransformFilter(x, offset, length) {
  40146. var len = length >> 1;
  40147. offset = offset | 0;
  40148. var j, n;
  40149. for (j = offset, n = len + 1; n--; j += 2) {
  40150. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40151. }
  40152. for (j = offset + 1, n = len; n--; j += 2) {
  40153. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40154. }
  40155. };
  40156. return ReversibleTransform;
  40157. })();
  40158. return JpxImage;
  40159. })();
  40160. var Jbig2Image = (function Jbig2ImageClosure() {
  40161. // Utility data structures
  40162. function ContextCache() {}
  40163. ContextCache.prototype = {
  40164. getContexts: function(id) {
  40165. if (id in this) {
  40166. return this[id];
  40167. }
  40168. return (this[id] = new Int8Array(1 << 16));
  40169. }
  40170. };
  40171. function DecodingContext(data, start, end) {
  40172. this.data = data;
  40173. this.start = start;
  40174. this.end = end;
  40175. }
  40176. DecodingContext.prototype = {
  40177. get decoder() {
  40178. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40179. return shadow(this, 'decoder', decoder);
  40180. },
  40181. get contextCache() {
  40182. var cache = new ContextCache();
  40183. return shadow(this, 'contextCache', cache);
  40184. }
  40185. };
  40186. // Annex A. Arithmetic Integer Decoding Procedure
  40187. // A.2 Procedure for decoding values
  40188. function decodeInteger(contextCache, procedure, decoder) {
  40189. var contexts = contextCache.getContexts(procedure);
  40190. var prev = 1;
  40191. function readBits(length) {
  40192. var v = 0;
  40193. for (var i = 0; i < length; i++) {
  40194. var bit = decoder.readBit(contexts, prev);
  40195. prev = (prev < 256 ? (prev << 1) | bit :
  40196. (((prev << 1) | bit) & 511) | 256);
  40197. v = (v << 1) | bit;
  40198. }
  40199. return v >>> 0;
  40200. }
  40201. var sign = readBits(1);
  40202. var value = readBits(1) ?
  40203. (readBits(1) ?
  40204. (readBits(1) ?
  40205. (readBits(1) ?
  40206. (readBits(1) ?
  40207. (readBits(32) + 4436) :
  40208. readBits(12) + 340) :
  40209. readBits(8) + 84) :
  40210. readBits(6) + 20) :
  40211. readBits(4) + 4) :
  40212. readBits(2);
  40213. return (sign === 0 ? value : (value > 0 ? -value : null));
  40214. }
  40215. // A.3 The IAID decoding procedure
  40216. function decodeIAID(contextCache, decoder, codeLength) {
  40217. var contexts = contextCache.getContexts('IAID');
  40218. var prev = 1;
  40219. for (var i = 0; i < codeLength; i++) {
  40220. var bit = decoder.readBit(contexts, prev);
  40221. prev = (prev << 1) | bit;
  40222. }
  40223. if (codeLength < 31) {
  40224. return prev & ((1 << codeLength) - 1);
  40225. }
  40226. return prev & 0x7FFFFFFF;
  40227. }
  40228. // 7.3 Segment types
  40229. var SegmentTypes = [
  40230. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  40231. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  40232. null, null, null, null, null, 'patternDictionary', null, null, null,
  40233. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  40234. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  40235. null, null, null, null, null, 'IntermediateGenericRegion', null,
  40236. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  40237. 'IntermediateGenericRefinementRegion', null,
  40238. 'ImmediateGenericRefinementRegion',
  40239. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  40240. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  40241. 'Tables', null, null, null, null, null, null, null, null,
  40242. 'Extension'
  40243. ];
  40244. var CodingTemplates = [
  40245. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40246. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  40247. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40248. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  40249. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  40250. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40251. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40252. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  40253. {x: -1, y: 0}],
  40254. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  40255. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  40256. ];
  40257. var RefinementTemplates = [
  40258. {
  40259. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40260. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  40261. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  40262. },
  40263. {
  40264. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40265. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  40266. {x: 0, y: 1}, {x: 1, y: 1}]
  40267. }
  40268. ];
  40269. // See 6.2.5.7 Decoding the bitmap.
  40270. var ReusedContexts = [
  40271. 0x9B25, // 10011 0110010 0101
  40272. 0x0795, // 0011 110010 101
  40273. 0x00E5, // 001 11001 01
  40274. 0x0195 // 011001 0101
  40275. ];
  40276. var RefinementReusedContexts = [
  40277. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  40278. 0x0008 // '0000' + '001000'
  40279. ];
  40280. function decodeBitmapTemplate0(width, height, decodingContext) {
  40281. var decoder = decodingContext.decoder;
  40282. var contexts = decodingContext.contextCache.getContexts('GB');
  40283. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  40284. // ...ooooo....
  40285. // ..ooooooo... Context template for current pixel (X)
  40286. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  40287. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  40288. for (i = 0; i < height; i++) {
  40289. row = bitmap[i] = new Uint8Array(width);
  40290. row1 = (i < 1) ? row : bitmap[i - 1];
  40291. row2 = (i < 2) ? row : bitmap[i - 2];
  40292. // At the beginning of each row:
  40293. // Fill contextLabel with pixels that are above/right of (X)
  40294. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  40295. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  40296. (row1[3] << 4);
  40297. for (j = 0; j < width; j++) {
  40298. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  40299. // At each pixel: Clear contextLabel pixels that are shifted
  40300. // out of the context, then add new ones.
  40301. // If j + n is out of range at the right image border, then
  40302. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  40303. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  40304. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  40305. }
  40306. }
  40307. return bitmap;
  40308. }
  40309. // 6.2 Generic Region Decoding Procedure
  40310. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  40311. decodingContext) {
  40312. if (mmr) {
  40313. error('JBIG2 error: MMR encoding is not supported');
  40314. }
  40315. // Use optimized version for the most common case
  40316. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  40317. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  40318. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  40319. return decodeBitmapTemplate0(width, height, decodingContext);
  40320. }
  40321. var useskip = !!skip;
  40322. var template = CodingTemplates[templateIndex].concat(at);
  40323. // Sorting is non-standard, and it is not required. But sorting increases
  40324. // the number of template bits that can be reused from the previous
  40325. // contextLabel in the main loop.
  40326. template.sort(function (a, b) {
  40327. return (a.y - b.y) || (a.x - b.x);
  40328. });
  40329. var templateLength = template.length;
  40330. var templateX = new Int8Array(templateLength);
  40331. var templateY = new Int8Array(templateLength);
  40332. var changingTemplateEntries = [];
  40333. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  40334. var c, k;
  40335. for (k = 0; k < templateLength; k++) {
  40336. templateX[k] = template[k].x;
  40337. templateY[k] = template[k].y;
  40338. minX = Math.min(minX, template[k].x);
  40339. maxX = Math.max(maxX, template[k].x);
  40340. minY = Math.min(minY, template[k].y);
  40341. // Check if the template pixel appears in two consecutive context labels,
  40342. // so it can be reused. Otherwise, we add it to the list of changing
  40343. // template entries.
  40344. if (k < templateLength - 1 &&
  40345. template[k].y === template[k + 1].y &&
  40346. template[k].x === template[k + 1].x - 1) {
  40347. reuseMask |= 1 << (templateLength - 1 - k);
  40348. } else {
  40349. changingTemplateEntries.push(k);
  40350. }
  40351. }
  40352. var changingEntriesLength = changingTemplateEntries.length;
  40353. var changingTemplateX = new Int8Array(changingEntriesLength);
  40354. var changingTemplateY = new Int8Array(changingEntriesLength);
  40355. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  40356. for (c = 0; c < changingEntriesLength; c++) {
  40357. k = changingTemplateEntries[c];
  40358. changingTemplateX[c] = template[k].x;
  40359. changingTemplateY[c] = template[k].y;
  40360. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  40361. }
  40362. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  40363. var sbb_left = -minX;
  40364. var sbb_top = -minY;
  40365. var sbb_right = width - maxX;
  40366. var pseudoPixelContext = ReusedContexts[templateIndex];
  40367. var row = new Uint8Array(width);
  40368. var bitmap = [];
  40369. var decoder = decodingContext.decoder;
  40370. var contexts = decodingContext.contextCache.getContexts('GB');
  40371. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  40372. for (var i = 0; i < height; i++) {
  40373. if (prediction) {
  40374. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  40375. ltp ^= sltp;
  40376. if (ltp) {
  40377. bitmap.push(row); // duplicate previous row
  40378. continue;
  40379. }
  40380. }
  40381. row = new Uint8Array(row);
  40382. bitmap.push(row);
  40383. for (j = 0; j < width; j++) {
  40384. if (useskip && skip[i][j]) {
  40385. row[j] = 0;
  40386. continue;
  40387. }
  40388. // Are we in the middle of a scanline, so we can reuse contextLabel
  40389. // bits?
  40390. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  40391. // If yes, we can just shift the bits that are reusable and only
  40392. // fetch the remaining ones.
  40393. contextLabel = (contextLabel << 1) & reuseMask;
  40394. for (k = 0; k < changingEntriesLength; k++) {
  40395. i0 = i + changingTemplateY[k];
  40396. j0 = j + changingTemplateX[k];
  40397. bit = bitmap[i0][j0];
  40398. if (bit) {
  40399. bit = changingTemplateBit[k];
  40400. contextLabel |= bit;
  40401. }
  40402. }
  40403. } else {
  40404. // compute the contextLabel from scratch
  40405. contextLabel = 0;
  40406. shift = templateLength - 1;
  40407. for (k = 0; k < templateLength; k++, shift--) {
  40408. j0 = j + templateX[k];
  40409. if (j0 >= 0 && j0 < width) {
  40410. i0 = i + templateY[k];
  40411. if (i0 >= 0) {
  40412. bit = bitmap[i0][j0];
  40413. if (bit) {
  40414. contextLabel |= bit << shift;
  40415. }
  40416. }
  40417. }
  40418. }
  40419. }
  40420. var pixel = decoder.readBit(contexts, contextLabel);
  40421. row[j] = pixel;
  40422. }
  40423. }
  40424. return bitmap;
  40425. }
  40426. // 6.3.2 Generic Refinement Region Decoding Procedure
  40427. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  40428. offsetX, offsetY, prediction, at,
  40429. decodingContext) {
  40430. var codingTemplate = RefinementTemplates[templateIndex].coding;
  40431. if (templateIndex === 0) {
  40432. codingTemplate = codingTemplate.concat([at[0]]);
  40433. }
  40434. var codingTemplateLength = codingTemplate.length;
  40435. var codingTemplateX = new Int32Array(codingTemplateLength);
  40436. var codingTemplateY = new Int32Array(codingTemplateLength);
  40437. var k;
  40438. for (k = 0; k < codingTemplateLength; k++) {
  40439. codingTemplateX[k] = codingTemplate[k].x;
  40440. codingTemplateY[k] = codingTemplate[k].y;
  40441. }
  40442. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  40443. if (templateIndex === 0) {
  40444. referenceTemplate = referenceTemplate.concat([at[1]]);
  40445. }
  40446. var referenceTemplateLength = referenceTemplate.length;
  40447. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  40448. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  40449. for (k = 0; k < referenceTemplateLength; k++) {
  40450. referenceTemplateX[k] = referenceTemplate[k].x;
  40451. referenceTemplateY[k] = referenceTemplate[k].y;
  40452. }
  40453. var referenceWidth = referenceBitmap[0].length;
  40454. var referenceHeight = referenceBitmap.length;
  40455. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  40456. var bitmap = [];
  40457. var decoder = decodingContext.decoder;
  40458. var contexts = decodingContext.contextCache.getContexts('GR');
  40459. var ltp = 0;
  40460. for (var i = 0; i < height; i++) {
  40461. if (prediction) {
  40462. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  40463. ltp ^= sltp;
  40464. if (ltp) {
  40465. error('JBIG2 error: prediction is not supported');
  40466. }
  40467. }
  40468. var row = new Uint8Array(width);
  40469. bitmap.push(row);
  40470. for (var j = 0; j < width; j++) {
  40471. var i0, j0;
  40472. var contextLabel = 0;
  40473. for (k = 0; k < codingTemplateLength; k++) {
  40474. i0 = i + codingTemplateY[k];
  40475. j0 = j + codingTemplateX[k];
  40476. if (i0 < 0 || j0 < 0 || j0 >= width) {
  40477. contextLabel <<= 1; // out of bound pixel
  40478. } else {
  40479. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  40480. }
  40481. }
  40482. for (k = 0; k < referenceTemplateLength; k++) {
  40483. i0 = i + referenceTemplateY[k] + offsetY;
  40484. j0 = j + referenceTemplateX[k] + offsetX;
  40485. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  40486. j0 >= referenceWidth) {
  40487. contextLabel <<= 1; // out of bound pixel
  40488. } else {
  40489. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  40490. }
  40491. }
  40492. var pixel = decoder.readBit(contexts, contextLabel);
  40493. row[j] = pixel;
  40494. }
  40495. }
  40496. return bitmap;
  40497. }
  40498. // 6.5.5 Decoding the symbol dictionary
  40499. function decodeSymbolDictionary(huffman, refinement, symbols,
  40500. numberOfNewSymbols, numberOfExportedSymbols,
  40501. huffmanTables, templateIndex, at,
  40502. refinementTemplateIndex, refinementAt,
  40503. decodingContext) {
  40504. if (huffman) {
  40505. error('JBIG2 error: huffman is not supported');
  40506. }
  40507. var newSymbols = [];
  40508. var currentHeight = 0;
  40509. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  40510. var decoder = decodingContext.decoder;
  40511. var contextCache = decodingContext.contextCache;
  40512. while (newSymbols.length < numberOfNewSymbols) {
  40513. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  40514. currentHeight += deltaHeight;
  40515. var currentWidth = 0;
  40516. var totalWidth = 0;
  40517. while (true) {
  40518. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  40519. if (deltaWidth === null) {
  40520. break; // OOB
  40521. }
  40522. currentWidth += deltaWidth;
  40523. totalWidth += currentWidth;
  40524. var bitmap;
  40525. if (refinement) {
  40526. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  40527. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  40528. if (numberOfInstances > 1) {
  40529. bitmap = decodeTextRegion(huffman, refinement,
  40530. currentWidth, currentHeight, 0,
  40531. numberOfInstances, 1, //strip size
  40532. symbols.concat(newSymbols),
  40533. symbolCodeLength,
  40534. 0, //transposed
  40535. 0, //ds offset
  40536. 1, //top left 7.4.3.1.1
  40537. 0, //OR operator
  40538. huffmanTables,
  40539. refinementTemplateIndex, refinementAt,
  40540. decodingContext);
  40541. } else {
  40542. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  40543. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  40544. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  40545. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  40546. newSymbols[symbolId - symbols.length]);
  40547. bitmap = decodeRefinement(currentWidth, currentHeight,
  40548. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  40549. decodingContext);
  40550. }
  40551. } else {
  40552. // 6.5.8.1 Direct-coded symbol bitmap
  40553. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  40554. templateIndex, false, null, at, decodingContext);
  40555. }
  40556. newSymbols.push(bitmap);
  40557. }
  40558. }
  40559. // 6.5.10 Exported symbols
  40560. var exportedSymbols = [];
  40561. var flags = [], currentFlag = false;
  40562. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  40563. while (flags.length < totalSymbolsLength) {
  40564. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  40565. while (runLength--) {
  40566. flags.push(currentFlag);
  40567. }
  40568. currentFlag = !currentFlag;
  40569. }
  40570. for (var i = 0, ii = symbols.length; i < ii; i++) {
  40571. if (flags[i]) {
  40572. exportedSymbols.push(symbols[i]);
  40573. }
  40574. }
  40575. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  40576. if (flags[i]) {
  40577. exportedSymbols.push(newSymbols[j]);
  40578. }
  40579. }
  40580. return exportedSymbols;
  40581. }
  40582. function decodeTextRegion(huffman, refinement, width, height,
  40583. defaultPixelValue, numberOfSymbolInstances,
  40584. stripSize, inputSymbols, symbolCodeLength,
  40585. transposed, dsOffset, referenceCorner,
  40586. combinationOperator, huffmanTables,
  40587. refinementTemplateIndex, refinementAt,
  40588. decodingContext) {
  40589. if (huffman) {
  40590. error('JBIG2 error: huffman is not supported');
  40591. }
  40592. // Prepare bitmap
  40593. var bitmap = [];
  40594. var i, row;
  40595. for (i = 0; i < height; i++) {
  40596. row = new Uint8Array(width);
  40597. if (defaultPixelValue) {
  40598. for (var j = 0; j < width; j++) {
  40599. row[j] = defaultPixelValue;
  40600. }
  40601. }
  40602. bitmap.push(row);
  40603. }
  40604. var decoder = decodingContext.decoder;
  40605. var contextCache = decodingContext.contextCache;
  40606. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  40607. var firstS = 0;
  40608. i = 0;
  40609. while (i < numberOfSymbolInstances) {
  40610. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  40611. stripT += deltaT;
  40612. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  40613. firstS += deltaFirstS;
  40614. var currentS = firstS;
  40615. do {
  40616. var currentT = (stripSize === 1 ? 0 :
  40617. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  40618. var t = stripSize * stripT + currentT;
  40619. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  40620. var applyRefinement = (refinement &&
  40621. decodeInteger(contextCache, 'IARI', decoder));
  40622. var symbolBitmap = inputSymbols[symbolId];
  40623. var symbolWidth = symbolBitmap[0].length;
  40624. var symbolHeight = symbolBitmap.length;
  40625. if (applyRefinement) {
  40626. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  40627. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  40628. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  40629. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  40630. symbolWidth += rdw;
  40631. symbolHeight += rdh;
  40632. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  40633. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  40634. (rdh >> 1) + rdy, false, refinementAt,
  40635. decodingContext);
  40636. }
  40637. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  40638. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  40639. var s2, t2, symbolRow;
  40640. if (transposed) {
  40641. // Place Symbol Bitmap from T1,S1
  40642. for (s2 = 0; s2 < symbolHeight; s2++) {
  40643. row = bitmap[offsetS + s2];
  40644. if (!row) {
  40645. continue;
  40646. }
  40647. symbolRow = symbolBitmap[s2];
  40648. // To ignore Parts of Symbol bitmap which goes
  40649. // outside bitmap region
  40650. var maxWidth = Math.min(width - offsetT, symbolWidth);
  40651. switch (combinationOperator) {
  40652. case 0: // OR
  40653. for (t2 = 0; t2 < maxWidth; t2++) {
  40654. row[offsetT + t2] |= symbolRow[t2];
  40655. }
  40656. break;
  40657. case 2: // XOR
  40658. for (t2 = 0; t2 < maxWidth; t2++) {
  40659. row[offsetT + t2] ^= symbolRow[t2];
  40660. }
  40661. break;
  40662. default:
  40663. error('JBIG2 error: operator ' + combinationOperator +
  40664. ' is not supported');
  40665. }
  40666. }
  40667. currentS += symbolHeight - 1;
  40668. } else {
  40669. for (t2 = 0; t2 < symbolHeight; t2++) {
  40670. row = bitmap[offsetT + t2];
  40671. if (!row) {
  40672. continue;
  40673. }
  40674. symbolRow = symbolBitmap[t2];
  40675. switch (combinationOperator) {
  40676. case 0: // OR
  40677. for (s2 = 0; s2 < symbolWidth; s2++) {
  40678. row[offsetS + s2] |= symbolRow[s2];
  40679. }
  40680. break;
  40681. case 2: // XOR
  40682. for (s2 = 0; s2 < symbolWidth; s2++) {
  40683. row[offsetS + s2] ^= symbolRow[s2];
  40684. }
  40685. break;
  40686. default:
  40687. error('JBIG2 error: operator ' + combinationOperator +
  40688. ' is not supported');
  40689. }
  40690. }
  40691. currentS += symbolWidth - 1;
  40692. }
  40693. i++;
  40694. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  40695. if (deltaS === null) {
  40696. break; // OOB
  40697. }
  40698. currentS += deltaS + dsOffset;
  40699. } while (true);
  40700. }
  40701. return bitmap;
  40702. }
  40703. function readSegmentHeader(data, start) {
  40704. var segmentHeader = {};
  40705. segmentHeader.number = readUint32(data, start);
  40706. var flags = data[start + 4];
  40707. var segmentType = flags & 0x3F;
  40708. if (!SegmentTypes[segmentType]) {
  40709. error('JBIG2 error: invalid segment type: ' + segmentType);
  40710. }
  40711. segmentHeader.type = segmentType;
  40712. segmentHeader.typeName = SegmentTypes[segmentType];
  40713. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  40714. var pageAssociationFieldSize = !!(flags & 0x40);
  40715. var referredFlags = data[start + 5];
  40716. var referredToCount = (referredFlags >> 5) & 7;
  40717. var retainBits = [referredFlags & 31];
  40718. var position = start + 6;
  40719. if (referredFlags === 7) {
  40720. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  40721. position += 3;
  40722. var bytes = (referredToCount + 7) >> 3;
  40723. retainBits[0] = data[position++];
  40724. while (--bytes > 0) {
  40725. retainBits.push(data[position++]);
  40726. }
  40727. } else if (referredFlags === 5 || referredFlags === 6) {
  40728. error('JBIG2 error: invalid referred-to flags');
  40729. }
  40730. segmentHeader.retainBits = retainBits;
  40731. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  40732. (segmentHeader.number <= 65536 ? 2 : 4));
  40733. var referredTo = [];
  40734. var i, ii;
  40735. for (i = 0; i < referredToCount; i++) {
  40736. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  40737. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  40738. readUint32(data, position)));
  40739. referredTo.push(number);
  40740. position += referredToSegmentNumberSize;
  40741. }
  40742. segmentHeader.referredTo = referredTo;
  40743. if (!pageAssociationFieldSize) {
  40744. segmentHeader.pageAssociation = data[position++];
  40745. } else {
  40746. segmentHeader.pageAssociation = readUint32(data, position);
  40747. position += 4;
  40748. }
  40749. segmentHeader.length = readUint32(data, position);
  40750. position += 4;
  40751. if (segmentHeader.length === 0xFFFFFFFF) {
  40752. // 7.2.7 Segment data length, unknown segment length
  40753. if (segmentType === 38) { // ImmediateGenericRegion
  40754. var genericRegionInfo = readRegionSegmentInformation(data, position);
  40755. var genericRegionSegmentFlags = data[position +
  40756. RegionSegmentInformationFieldLength];
  40757. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  40758. // searching for the segment end
  40759. var searchPatternLength = 6;
  40760. var searchPattern = new Uint8Array(searchPatternLength);
  40761. if (!genericRegionMmr) {
  40762. searchPattern[0] = 0xFF;
  40763. searchPattern[1] = 0xAC;
  40764. }
  40765. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  40766. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  40767. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  40768. searchPattern[5] = genericRegionInfo.height & 0xFF;
  40769. for (i = position, ii = data.length; i < ii; i++) {
  40770. var j = 0;
  40771. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  40772. j++;
  40773. }
  40774. if (j === searchPatternLength) {
  40775. segmentHeader.length = i + searchPatternLength;
  40776. break;
  40777. }
  40778. }
  40779. if (segmentHeader.length === 0xFFFFFFFF) {
  40780. error('JBIG2 error: segment end was not found');
  40781. }
  40782. } else {
  40783. error('JBIG2 error: invalid unknown segment length');
  40784. }
  40785. }
  40786. segmentHeader.headerEnd = position;
  40787. return segmentHeader;
  40788. }
  40789. function readSegments(header, data, start, end) {
  40790. var segments = [];
  40791. var position = start;
  40792. while (position < end) {
  40793. var segmentHeader = readSegmentHeader(data, position);
  40794. position = segmentHeader.headerEnd;
  40795. var segment = {
  40796. header: segmentHeader,
  40797. data: data
  40798. };
  40799. if (!header.randomAccess) {
  40800. segment.start = position;
  40801. position += segmentHeader.length;
  40802. segment.end = position;
  40803. }
  40804. segments.push(segment);
  40805. if (segmentHeader.type === 51) {
  40806. break; // end of file is found
  40807. }
  40808. }
  40809. if (header.randomAccess) {
  40810. for (var i = 0, ii = segments.length; i < ii; i++) {
  40811. segments[i].start = position;
  40812. position += segments[i].header.length;
  40813. segments[i].end = position;
  40814. }
  40815. }
  40816. return segments;
  40817. }
  40818. // 7.4.1 Region segment information field
  40819. function readRegionSegmentInformation(data, start) {
  40820. return {
  40821. width: readUint32(data, start),
  40822. height: readUint32(data, start + 4),
  40823. x: readUint32(data, start + 8),
  40824. y: readUint32(data, start + 12),
  40825. combinationOperator: data[start + 16] & 7
  40826. };
  40827. }
  40828. var RegionSegmentInformationFieldLength = 17;
  40829. function processSegment(segment, visitor) {
  40830. var header = segment.header;
  40831. var data = segment.data, position = segment.start, end = segment.end;
  40832. var args, at, i, atLength;
  40833. switch (header.type) {
  40834. case 0: // SymbolDictionary
  40835. // 7.4.2 Symbol dictionary segment syntax
  40836. var dictionary = {};
  40837. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  40838. dictionary.huffman = !!(dictionaryFlags & 1);
  40839. dictionary.refinement = !!(dictionaryFlags & 2);
  40840. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  40841. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  40842. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  40843. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  40844. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  40845. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  40846. dictionary.template = (dictionaryFlags >> 10) & 3;
  40847. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  40848. position += 2;
  40849. if (!dictionary.huffman) {
  40850. atLength = dictionary.template === 0 ? 4 : 1;
  40851. at = [];
  40852. for (i = 0; i < atLength; i++) {
  40853. at.push({
  40854. x: readInt8(data, position),
  40855. y: readInt8(data, position + 1)
  40856. });
  40857. position += 2;
  40858. }
  40859. dictionary.at = at;
  40860. }
  40861. if (dictionary.refinement && !dictionary.refinementTemplate) {
  40862. at = [];
  40863. for (i = 0; i < 2; i++) {
  40864. at.push({
  40865. x: readInt8(data, position),
  40866. y: readInt8(data, position + 1)
  40867. });
  40868. position += 2;
  40869. }
  40870. dictionary.refinementAt = at;
  40871. }
  40872. dictionary.numberOfExportedSymbols = readUint32(data, position);
  40873. position += 4;
  40874. dictionary.numberOfNewSymbols = readUint32(data, position);
  40875. position += 4;
  40876. args = [dictionary, header.number, header.referredTo,
  40877. data, position, end];
  40878. break;
  40879. case 6: // ImmediateTextRegion
  40880. case 7: // ImmediateLosslessTextRegion
  40881. var textRegion = {};
  40882. textRegion.info = readRegionSegmentInformation(data, position);
  40883. position += RegionSegmentInformationFieldLength;
  40884. var textRegionSegmentFlags = readUint16(data, position);
  40885. position += 2;
  40886. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  40887. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  40888. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  40889. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  40890. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  40891. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  40892. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  40893. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  40894. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  40895. if (textRegion.huffman) {
  40896. var textRegionHuffmanFlags = readUint16(data, position);
  40897. position += 2;
  40898. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  40899. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  40900. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  40901. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  40902. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  40903. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  40904. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  40905. textRegion.huffmanRefinementSizeSelector =
  40906. !!(textRegionHuffmanFlags & 14);
  40907. }
  40908. if (textRegion.refinement && !textRegion.refinementTemplate) {
  40909. at = [];
  40910. for (i = 0; i < 2; i++) {
  40911. at.push({
  40912. x: readInt8(data, position),
  40913. y: readInt8(data, position + 1)
  40914. });
  40915. position += 2;
  40916. }
  40917. textRegion.refinementAt = at;
  40918. }
  40919. textRegion.numberOfSymbolInstances = readUint32(data, position);
  40920. position += 4;
  40921. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  40922. if (textRegion.huffman) {
  40923. error('JBIG2 error: huffman is not supported');
  40924. }
  40925. args = [textRegion, header.referredTo, data, position, end];
  40926. break;
  40927. case 38: // ImmediateGenericRegion
  40928. case 39: // ImmediateLosslessGenericRegion
  40929. var genericRegion = {};
  40930. genericRegion.info = readRegionSegmentInformation(data, position);
  40931. position += RegionSegmentInformationFieldLength;
  40932. var genericRegionSegmentFlags = data[position++];
  40933. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  40934. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  40935. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  40936. if (!genericRegion.mmr) {
  40937. atLength = genericRegion.template === 0 ? 4 : 1;
  40938. at = [];
  40939. for (i = 0; i < atLength; i++) {
  40940. at.push({
  40941. x: readInt8(data, position),
  40942. y: readInt8(data, position + 1)
  40943. });
  40944. position += 2;
  40945. }
  40946. genericRegion.at = at;
  40947. }
  40948. args = [genericRegion, data, position, end];
  40949. break;
  40950. case 48: // PageInformation
  40951. var pageInfo = {
  40952. width: readUint32(data, position),
  40953. height: readUint32(data, position + 4),
  40954. resolutionX: readUint32(data, position + 8),
  40955. resolutionY: readUint32(data, position + 12)
  40956. };
  40957. if (pageInfo.height === 0xFFFFFFFF) {
  40958. delete pageInfo.height;
  40959. }
  40960. var pageSegmentFlags = data[position + 16];
  40961. var pageStripingInformatiom = readUint16(data, position + 17);
  40962. pageInfo.lossless = !!(pageSegmentFlags & 1);
  40963. pageInfo.refinement = !!(pageSegmentFlags & 2);
  40964. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  40965. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  40966. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  40967. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  40968. args = [pageInfo];
  40969. break;
  40970. case 49: // EndOfPage
  40971. break;
  40972. case 50: // EndOfStripe
  40973. break;
  40974. case 51: // EndOfFile
  40975. break;
  40976. case 62: // 7.4.15 defines 2 extension types which
  40977. // are comments and can be ignored.
  40978. break;
  40979. default:
  40980. error('JBIG2 error: segment type ' + header.typeName + '(' +
  40981. header.type + ') is not implemented');
  40982. }
  40983. var callbackName = 'on' + header.typeName;
  40984. if (callbackName in visitor) {
  40985. visitor[callbackName].apply(visitor, args);
  40986. }
  40987. }
  40988. function processSegments(segments, visitor) {
  40989. for (var i = 0, ii = segments.length; i < ii; i++) {
  40990. processSegment(segments[i], visitor);
  40991. }
  40992. }
  40993. function parseJbig2(data, start, end) {
  40994. var position = start;
  40995. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  40996. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  40997. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  40998. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  40999. error('JBIG2 error: invalid header');
  41000. }
  41001. var header = {};
  41002. position += 8;
  41003. var flags = data[position++];
  41004. header.randomAccess = !(flags & 1);
  41005. if (!(flags & 2)) {
  41006. header.numberOfPages = readUint32(data, position);
  41007. position += 4;
  41008. }
  41009. var segments = readSegments(header, data, position, end);
  41010. error('Not implemented');
  41011. // processSegments(segments, new SimpleSegmentVisitor());
  41012. }
  41013. function parseJbig2Chunks(chunks) {
  41014. var visitor = new SimpleSegmentVisitor();
  41015. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41016. var chunk = chunks[i];
  41017. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41018. processSegments(segments, visitor);
  41019. }
  41020. return visitor.buffer;
  41021. }
  41022. function SimpleSegmentVisitor() {}
  41023. SimpleSegmentVisitor.prototype = {
  41024. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41025. this.currentPageInfo = info;
  41026. var rowSize = (info.width + 7) >> 3;
  41027. var buffer = new Uint8Array(rowSize * info.height);
  41028. // The contents of ArrayBuffers are initialized to 0.
  41029. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41030. if (info.defaultPixelValue) {
  41031. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41032. buffer[i] = 0xFF;
  41033. }
  41034. }
  41035. this.buffer = buffer;
  41036. },
  41037. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41038. var pageInfo = this.currentPageInfo;
  41039. var width = regionInfo.width, height = regionInfo.height;
  41040. var rowSize = (pageInfo.width + 7) >> 3;
  41041. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41042. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41043. var buffer = this.buffer;
  41044. var mask0 = 128 >> (regionInfo.x & 7);
  41045. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41046. var i, j, mask, offset;
  41047. switch (combinationOperator) {
  41048. case 0: // OR
  41049. for (i = 0; i < height; i++) {
  41050. mask = mask0;
  41051. offset = offset0;
  41052. for (j = 0; j < width; j++) {
  41053. if (bitmap[i][j]) {
  41054. buffer[offset] |= mask;
  41055. }
  41056. mask >>= 1;
  41057. if (!mask) {
  41058. mask = 128;
  41059. offset++;
  41060. }
  41061. }
  41062. offset0 += rowSize;
  41063. }
  41064. break;
  41065. case 2: // XOR
  41066. for (i = 0; i < height; i++) {
  41067. mask = mask0;
  41068. offset = offset0;
  41069. for (j = 0; j < width; j++) {
  41070. if (bitmap[i][j]) {
  41071. buffer[offset] ^= mask;
  41072. }
  41073. mask >>= 1;
  41074. if (!mask) {
  41075. mask = 128;
  41076. offset++;
  41077. }
  41078. }
  41079. offset0 += rowSize;
  41080. }
  41081. break;
  41082. default:
  41083. error('JBIG2 error: operator ' + combinationOperator +
  41084. ' is not supported');
  41085. }
  41086. },
  41087. onImmediateGenericRegion:
  41088. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41089. start, end) {
  41090. var regionInfo = region.info;
  41091. var decodingContext = new DecodingContext(data, start, end);
  41092. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41093. region.template, region.prediction, null,
  41094. region.at, decodingContext);
  41095. this.drawBitmap(regionInfo, bitmap);
  41096. },
  41097. onImmediateLosslessGenericRegion:
  41098. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41099. this.onImmediateGenericRegion.apply(this, arguments);
  41100. },
  41101. onSymbolDictionary:
  41102. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41103. currentSegment,
  41104. referredSegments,
  41105. data, start, end) {
  41106. var huffmanTables;
  41107. if (dictionary.huffman) {
  41108. error('JBIG2 error: huffman is not supported');
  41109. }
  41110. // Combines exported symbols from all referred segments
  41111. var symbols = this.symbols;
  41112. if (!symbols) {
  41113. this.symbols = symbols = {};
  41114. }
  41115. var inputSymbols = [];
  41116. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41117. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41118. }
  41119. var decodingContext = new DecodingContext(data, start, end);
  41120. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41121. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41122. dictionary.numberOfExportedSymbols, huffmanTables,
  41123. dictionary.template, dictionary.at,
  41124. dictionary.refinementTemplate, dictionary.refinementAt,
  41125. decodingContext);
  41126. },
  41127. onImmediateTextRegion:
  41128. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41129. referredSegments,
  41130. data, start, end) {
  41131. var regionInfo = region.info;
  41132. var huffmanTables;
  41133. // Combines exported symbols from all referred segments
  41134. var symbols = this.symbols;
  41135. var inputSymbols = [];
  41136. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41137. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41138. }
  41139. var symbolCodeLength = log2(inputSymbols.length);
  41140. var decodingContext = new DecodingContext(data, start, end);
  41141. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41142. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41143. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41144. symbolCodeLength, region.transposed, region.dsOffset,
  41145. region.referenceCorner, region.combinationOperator, huffmanTables,
  41146. region.refinementTemplate, region.refinementAt, decodingContext);
  41147. this.drawBitmap(regionInfo, bitmap);
  41148. },
  41149. onImmediateLosslessTextRegion:
  41150. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41151. this.onImmediateTextRegion.apply(this, arguments);
  41152. }
  41153. };
  41154. function Jbig2Image() {}
  41155. Jbig2Image.prototype = {
  41156. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41157. return parseJbig2Chunks(chunks);
  41158. }
  41159. };
  41160. return Jbig2Image;
  41161. })();
  41162. var bidi = PDFJS.bidi = (function bidiClosure() {
  41163. // Character types for symbols from 0000 to 00FF.
  41164. var baseTypes = [
  41165. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41166. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41167. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41168. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41169. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41170. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41171. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41172. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41173. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41174. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41175. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41176. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41177. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41178. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41179. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41180. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41181. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41182. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41183. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41184. ];
  41185. // Character types for symbols from 0600 to 06FF
  41186. var arabicTypes = [
  41187. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41188. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41189. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41190. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41191. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41192. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41193. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41194. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41195. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41196. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41197. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41198. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41199. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41200. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41201. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41202. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41203. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41204. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41205. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41206. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41207. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41208. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41209. ];
  41210. function isOdd(i) {
  41211. return (i & 1) !== 0;
  41212. }
  41213. function isEven(i) {
  41214. return (i & 1) === 0;
  41215. }
  41216. function findUnequal(arr, start, value) {
  41217. for (var j = start, jj = arr.length; j < jj; ++j) {
  41218. if (arr[j] !== value) {
  41219. return j;
  41220. }
  41221. }
  41222. return j;
  41223. }
  41224. function setValues(arr, start, end, value) {
  41225. for (var j = start; j < end; ++j) {
  41226. arr[j] = value;
  41227. }
  41228. }
  41229. function reverseValues(arr, start, end) {
  41230. for (var i = start, j = end - 1; i < j; ++i, --j) {
  41231. var temp = arr[i];
  41232. arr[i] = arr[j];
  41233. arr[j] = temp;
  41234. }
  41235. }
  41236. function createBidiText(str, isLTR, vertical) {
  41237. return {
  41238. str: str,
  41239. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  41240. };
  41241. }
  41242. // These are used in bidi(), which is called frequently. We re-use them on
  41243. // each call to avoid unnecessary allocations.
  41244. var chars = [];
  41245. var types = [];
  41246. function bidi(str, startLevel, vertical) {
  41247. var isLTR = true;
  41248. var strLength = str.length;
  41249. if (strLength === 0 || vertical) {
  41250. return createBidiText(str, isLTR, vertical);
  41251. }
  41252. // Get types and fill arrays
  41253. chars.length = strLength;
  41254. types.length = strLength;
  41255. var numBidi = 0;
  41256. var i, ii;
  41257. for (i = 0; i < strLength; ++i) {
  41258. chars[i] = str.charAt(i);
  41259. var charCode = str.charCodeAt(i);
  41260. var charType = 'L';
  41261. if (charCode <= 0x00ff) {
  41262. charType = baseTypes[charCode];
  41263. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  41264. charType = 'R';
  41265. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  41266. charType = arabicTypes[charCode & 0xff];
  41267. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  41268. charType = 'AL';
  41269. }
  41270. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  41271. numBidi++;
  41272. }
  41273. types[i] = charType;
  41274. }
  41275. // Detect the bidi method
  41276. // - If there are no rtl characters then no bidi needed
  41277. // - If less than 30% chars are rtl then string is primarily ltr
  41278. // - If more than 30% chars are rtl then string is primarily rtl
  41279. if (numBidi === 0) {
  41280. isLTR = true;
  41281. return createBidiText(str, isLTR);
  41282. }
  41283. if (startLevel === -1) {
  41284. if ((strLength / numBidi) < 0.3) {
  41285. isLTR = true;
  41286. startLevel = 0;
  41287. } else {
  41288. isLTR = false;
  41289. startLevel = 1;
  41290. }
  41291. }
  41292. var levels = [];
  41293. for (i = 0; i < strLength; ++i) {
  41294. levels[i] = startLevel;
  41295. }
  41296. /*
  41297. X1-X10: skip most of this, since we are NOT doing the embeddings.
  41298. */
  41299. var e = (isOdd(startLevel) ? 'R' : 'L');
  41300. var sor = e;
  41301. var eor = sor;
  41302. /*
  41303. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  41304. type of the NSM to the type of the previous character. If the NSM is at the
  41305. start of the level run, it will get the type of sor.
  41306. */
  41307. var lastType = sor;
  41308. for (i = 0; i < strLength; ++i) {
  41309. if (types[i] === 'NSM') {
  41310. types[i] = lastType;
  41311. } else {
  41312. lastType = types[i];
  41313. }
  41314. }
  41315. /*
  41316. W2. Search backwards from each instance of a European number until the
  41317. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  41318. the type of the European number to Arabic number.
  41319. */
  41320. lastType = sor;
  41321. var t;
  41322. for (i = 0; i < strLength; ++i) {
  41323. t = types[i];
  41324. if (t === 'EN') {
  41325. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  41326. } else if (t === 'R' || t === 'L' || t === 'AL') {
  41327. lastType = t;
  41328. }
  41329. }
  41330. /*
  41331. W3. Change all ALs to R.
  41332. */
  41333. for (i = 0; i < strLength; ++i) {
  41334. t = types[i];
  41335. if (t === 'AL') {
  41336. types[i] = 'R';
  41337. }
  41338. }
  41339. /*
  41340. W4. A single European separator between two European numbers changes to a
  41341. European number. A single common separator between two numbers of the same
  41342. type changes to that type:
  41343. */
  41344. for (i = 1; i < strLength - 1; ++i) {
  41345. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  41346. types[i] = 'EN';
  41347. }
  41348. if (types[i] === 'CS' &&
  41349. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  41350. types[i + 1] === types[i - 1]) {
  41351. types[i] = types[i - 1];
  41352. }
  41353. }
  41354. /*
  41355. W5. A sequence of European terminators adjacent to European numbers changes
  41356. to all European numbers:
  41357. */
  41358. for (i = 0; i < strLength; ++i) {
  41359. if (types[i] === 'EN') {
  41360. // do before
  41361. var j;
  41362. for (j = i - 1; j >= 0; --j) {
  41363. if (types[j] !== 'ET') {
  41364. break;
  41365. }
  41366. types[j] = 'EN';
  41367. }
  41368. // do after
  41369. for (j = i + 1; j < strLength; --j) {
  41370. if (types[j] !== 'ET') {
  41371. break;
  41372. }
  41373. types[j] = 'EN';
  41374. }
  41375. }
  41376. }
  41377. /*
  41378. W6. Otherwise, separators and terminators change to Other Neutral:
  41379. */
  41380. for (i = 0; i < strLength; ++i) {
  41381. t = types[i];
  41382. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  41383. types[i] = 'ON';
  41384. }
  41385. }
  41386. /*
  41387. W7. Search backwards from each instance of a European number until the
  41388. first strong type (R, L, or sor) is found. If an L is found, then change
  41389. the type of the European number to L.
  41390. */
  41391. lastType = sor;
  41392. for (i = 0; i < strLength; ++i) {
  41393. t = types[i];
  41394. if (t === 'EN') {
  41395. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  41396. } else if (t === 'R' || t === 'L') {
  41397. lastType = t;
  41398. }
  41399. }
  41400. /*
  41401. N1. A sequence of neutrals takes the direction of the surrounding strong
  41402. text if the text on both sides has the same direction. European and Arabic
  41403. numbers are treated as though they were R. Start-of-level-run (sor) and
  41404. end-of-level-run (eor) are used at level run boundaries.
  41405. */
  41406. for (i = 0; i < strLength; ++i) {
  41407. if (types[i] === 'ON') {
  41408. var end = findUnequal(types, i + 1, 'ON');
  41409. var before = sor;
  41410. if (i > 0) {
  41411. before = types[i - 1];
  41412. }
  41413. var after = eor;
  41414. if (end + 1 < strLength) {
  41415. after = types[end + 1];
  41416. }
  41417. if (before !== 'L') {
  41418. before = 'R';
  41419. }
  41420. if (after !== 'L') {
  41421. after = 'R';
  41422. }
  41423. if (before === after) {
  41424. setValues(types, i, end, before);
  41425. }
  41426. i = end - 1; // reset to end (-1 so next iteration is ok)
  41427. }
  41428. }
  41429. /*
  41430. N2. Any remaining neutrals take the embedding direction.
  41431. */
  41432. for (i = 0; i < strLength; ++i) {
  41433. if (types[i] === 'ON') {
  41434. types[i] = e;
  41435. }
  41436. }
  41437. /*
  41438. I1. For all characters with an even (left-to-right) embedding direction,
  41439. those of type R go up one level and those of type AN or EN go up two
  41440. levels.
  41441. I2. For all characters with an odd (right-to-left) embedding direction,
  41442. those of type L, EN or AN go up one level.
  41443. */
  41444. for (i = 0; i < strLength; ++i) {
  41445. t = types[i];
  41446. if (isEven(levels[i])) {
  41447. if (t === 'R') {
  41448. levels[i] += 1;
  41449. } else if (t === 'AN' || t === 'EN') {
  41450. levels[i] += 2;
  41451. }
  41452. } else { // isOdd
  41453. if (t === 'L' || t === 'AN' || t === 'EN') {
  41454. levels[i] += 1;
  41455. }
  41456. }
  41457. }
  41458. /*
  41459. L1. On each line, reset the embedding level of the following characters to
  41460. the paragraph embedding level:
  41461. segment separators,
  41462. paragraph separators,
  41463. any sequence of whitespace characters preceding a segment separator or
  41464. paragraph separator, and any sequence of white space characters at the end
  41465. of the line.
  41466. */
  41467. // don't bother as text is only single line
  41468. /*
  41469. L2. From the highest level found in the text to the lowest odd level on
  41470. each line, reverse any contiguous sequence of characters that are at that
  41471. level or higher.
  41472. */
  41473. // find highest level & lowest odd level
  41474. var highestLevel = -1;
  41475. var lowestOddLevel = 99;
  41476. var level;
  41477. for (i = 0, ii = levels.length; i < ii; ++i) {
  41478. level = levels[i];
  41479. if (highestLevel < level) {
  41480. highestLevel = level;
  41481. }
  41482. if (lowestOddLevel > level && isOdd(level)) {
  41483. lowestOddLevel = level;
  41484. }
  41485. }
  41486. // now reverse between those limits
  41487. for (level = highestLevel; level >= lowestOddLevel; --level) {
  41488. // find segments to reverse
  41489. var start = -1;
  41490. for (i = 0, ii = levels.length; i < ii; ++i) {
  41491. if (levels[i] < level) {
  41492. if (start >= 0) {
  41493. reverseValues(chars, start, i);
  41494. start = -1;
  41495. }
  41496. } else if (start < 0) {
  41497. start = i;
  41498. }
  41499. }
  41500. if (start >= 0) {
  41501. reverseValues(chars, start, levels.length);
  41502. }
  41503. }
  41504. /*
  41505. L3. Combining marks applied to a right-to-left base character will at this
  41506. point precede their base character. If the rendering engine expects them to
  41507. follow the base characters in the final display process, then the ordering
  41508. of the marks and the base character must be reversed.
  41509. */
  41510. // don't bother for now
  41511. /*
  41512. L4. A character that possesses the mirrored property as specified by
  41513. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  41514. directionality of that character is R.
  41515. */
  41516. // don't mirror as characters are already mirrored in the pdf
  41517. // Finally, return string
  41518. var result = '';
  41519. for (i = 0, ii = chars.length; i < ii; ++i) {
  41520. var ch = chars[i];
  41521. if (ch !== '<' && ch !== '>') {
  41522. result += ch;
  41523. }
  41524. }
  41525. return createBidiText(result, isLTR);
  41526. }
  41527. return bidi;
  41528. })();
  41529. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  41530. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  41531. /* Copyright 2014 Opera Software ASA
  41532. *
  41533. * Licensed under the Apache License, Version 2.0 (the "License");
  41534. * you may not use this file except in compliance with the License.
  41535. * You may obtain a copy of the License at
  41536. *
  41537. * http://www.apache.org/licenses/LICENSE-2.0
  41538. *
  41539. * Unless required by applicable law or agreed to in writing, software
  41540. * distributed under the License is distributed on an "AS IS" BASIS,
  41541. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41542. * See the License for the specific language governing permissions and
  41543. * limitations under the License.
  41544. *
  41545. *
  41546. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  41547. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  41548. */
  41549. /* globals Uint32ArrayView */
  41550. 'use strict';
  41551. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  41552. // Workaround for missing math precison in JS.
  41553. var MASK_HIGH = 0xffff0000;
  41554. var MASK_LOW = 0xffff;
  41555. function MurmurHash3_64 (seed) {
  41556. var SEED = 0xc3d2e1f0;
  41557. this.h1 = seed ? seed & 0xffffffff : SEED;
  41558. this.h2 = seed ? seed & 0xffffffff : SEED;
  41559. }
  41560. var alwaysUseUint32ArrayView = false;
  41561. // old webkits have issues with non-aligned arrays
  41562. try {
  41563. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  41564. } catch (e) {
  41565. alwaysUseUint32ArrayView = true;
  41566. }
  41567. MurmurHash3_64.prototype = {
  41568. update: function MurmurHash3_64_update(input) {
  41569. var useUint32ArrayView = alwaysUseUint32ArrayView;
  41570. var i;
  41571. if (typeof input === 'string') {
  41572. var data = new Uint8Array(input.length * 2);
  41573. var length = 0;
  41574. for (i = 0; i < input.length; i++) {
  41575. var code = input.charCodeAt(i);
  41576. if (code <= 0xff) {
  41577. data[length++] = code;
  41578. }
  41579. else {
  41580. data[length++] = code >>> 8;
  41581. data[length++] = code & 0xff;
  41582. }
  41583. }
  41584. } else if (input instanceof Uint8Array) {
  41585. data = input;
  41586. length = data.length;
  41587. } else if (typeof input === 'object' && ('length' in input)) {
  41588. // processing regular arrays as well, e.g. for IE9
  41589. data = input;
  41590. length = data.length;
  41591. useUint32ArrayView = true;
  41592. } else {
  41593. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  41594. 'Input must be a string or array.');
  41595. }
  41596. var blockCounts = length >> 2;
  41597. var tailLength = length - blockCounts * 4;
  41598. // we don't care about endianness here
  41599. var dataUint32 = useUint32ArrayView ?
  41600. new Uint32ArrayView(data, blockCounts) :
  41601. new Uint32Array(data.buffer, 0, blockCounts);
  41602. var k1 = 0;
  41603. var k2 = 0;
  41604. var h1 = this.h1;
  41605. var h2 = this.h2;
  41606. var C1 = 0xcc9e2d51;
  41607. var C2 = 0x1b873593;
  41608. var C1_LOW = C1 & MASK_LOW;
  41609. var C2_LOW = C2 & MASK_LOW;
  41610. for (i = 0; i < blockCounts; i++) {
  41611. if (i & 1) {
  41612. k1 = dataUint32[i];
  41613. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  41614. k1 = k1 << 15 | k1 >>> 17;
  41615. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  41616. h1 ^= k1;
  41617. h1 = h1 << 13 | h1 >>> 19;
  41618. h1 = h1 * 5 + 0xe6546b64;
  41619. } else {
  41620. k2 = dataUint32[i];
  41621. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  41622. k2 = k2 << 15 | k2 >>> 17;
  41623. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  41624. h2 ^= k2;
  41625. h2 = h2 << 13 | h2 >>> 19;
  41626. h2 = h2 * 5 + 0xe6546b64;
  41627. }
  41628. }
  41629. k1 = 0;
  41630. switch (tailLength) {
  41631. case 3:
  41632. k1 ^= data[blockCounts * 4 + 2] << 16;
  41633. /* falls through */
  41634. case 2:
  41635. k1 ^= data[blockCounts * 4 + 1] << 8;
  41636. /* falls through */
  41637. case 1:
  41638. k1 ^= data[blockCounts * 4];
  41639. /* falls through */
  41640. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  41641. k1 = k1 << 15 | k1 >>> 17;
  41642. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  41643. if (blockCounts & 1) {
  41644. h1 ^= k1;
  41645. } else {
  41646. h2 ^= k1;
  41647. }
  41648. }
  41649. this.h1 = h1;
  41650. this.h2 = h2;
  41651. return this;
  41652. },
  41653. hexdigest: function MurmurHash3_64_hexdigest () {
  41654. var h1 = this.h1;
  41655. var h2 = this.h2;
  41656. h1 ^= h2 >>> 1;
  41657. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  41658. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  41659. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  41660. h1 ^= h2 >>> 1;
  41661. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  41662. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  41663. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  41664. h1 ^= h2 >>> 1;
  41665. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  41666. var hex = (arr[i] >>> 0).toString(16);
  41667. while (hex.length < 8) {
  41668. hex = '0' + hex;
  41669. }
  41670. str += hex;
  41671. }
  41672. return str;
  41673. }
  41674. };
  41675. return MurmurHash3_64;
  41676. })();
  41677. }).call((typeof window === 'undefined') ? this : window);
  41678. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  41679. // workerSrc is not set -- using last script url to define default location
  41680. PDFJS.workerSrc = (function () {
  41681. 'use strict';
  41682. var scriptTagContainer = document.body ||
  41683. document.getElementsByTagName('head')[0];
  41684. var pdfjsSrc = scriptTagContainer.lastChild.src;
  41685. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  41686. })();
  41687. }