pdf.combined.js 1.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655
  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.869';
  24. PDFJS.build = '77631cc';
  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. getDestinations: function PDFDocumentProxy_getDestinations() {
  1693. return this.transport.getDestinations();
  1694. },
  1695. /**
  1696. * @return {Promise} A promise that is resolved with a lookup table for
  1697. * mapping named attachments to their content.
  1698. */
  1699. getAttachments: function PDFDocumentProxy_getAttachments() {
  1700. return this.transport.getAttachments();
  1701. },
  1702. /**
  1703. * @return {Promise} A promise that is resolved with an array of all the
  1704. * JavaScript strings in the name tree.
  1705. */
  1706. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1707. return this.transport.getJavaScript();
  1708. },
  1709. /**
  1710. * @return {Promise} A promise that is resolved with an {Array} that is a
  1711. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1712. * [
  1713. * {
  1714. * title: string,
  1715. * bold: boolean,
  1716. * italic: boolean,
  1717. * color: rgb array,
  1718. * dest: dest obj,
  1719. * items: array of more items like this
  1720. * },
  1721. * ...
  1722. * ].
  1723. */
  1724. getOutline: function PDFDocumentProxy_getOutline() {
  1725. return this.transport.getOutline();
  1726. },
  1727. /**
  1728. * @return {Promise} A promise that is resolved with an {Object} that has
  1729. * info and metadata properties. Info is an {Object} filled with anything
  1730. * available in the information dictionary and similarly metadata is a
  1731. * {Metadata} object with information from the metadata section of the PDF.
  1732. */
  1733. getMetadata: function PDFDocumentProxy_getMetadata() {
  1734. return this.transport.getMetadata();
  1735. },
  1736. /**
  1737. * @return {Promise} A promise that is resolved with a TypedArray that has
  1738. * the raw data from the PDF.
  1739. */
  1740. getData: function PDFDocumentProxy_getData() {
  1741. return this.transport.getData();
  1742. },
  1743. /**
  1744. * @return {Promise} A promise that is resolved when the document's data
  1745. * is loaded. It is resolved with an {Object} that contains the length
  1746. * property that indicates size of the PDF data in bytes.
  1747. */
  1748. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1749. return this.transport.downloadInfoCapability.promise;
  1750. },
  1751. /**
  1752. * @returns {Promise} A promise this is resolved with current stats about
  1753. * document structures (see {@link PDFDocumentStats}).
  1754. */
  1755. getStats: function PDFDocumentProxy_getStats() {
  1756. return this.transport.getStats();
  1757. },
  1758. /**
  1759. * Cleans up resources allocated by the document, e.g. created @font-face.
  1760. */
  1761. cleanup: function PDFDocumentProxy_cleanup() {
  1762. this.transport.startCleanup();
  1763. },
  1764. /**
  1765. * Destroys current document instance and terminates worker.
  1766. */
  1767. destroy: function PDFDocumentProxy_destroy() {
  1768. this.transport.destroy();
  1769. }
  1770. };
  1771. return PDFDocumentProxy;
  1772. })();
  1773. /**
  1774. * Page text content.
  1775. *
  1776. * @typedef {Object} TextContent
  1777. * @property {array} items - array of {@link TextItem}
  1778. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1779. * name.
  1780. */
  1781. /**
  1782. * Page text content part.
  1783. *
  1784. * @typedef {Object} TextItem
  1785. * @property {string} str - text content.
  1786. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1787. * @property {array} transform - transformation matrix.
  1788. * @property {number} width - width in device space.
  1789. * @property {number} height - height in device space.
  1790. * @property {string} fontName - font name used by pdf.js for converted font.
  1791. */
  1792. /**
  1793. * Text style.
  1794. *
  1795. * @typedef {Object} TextStyle
  1796. * @property {number} ascent - font ascent.
  1797. * @property {number} descent - font descent.
  1798. * @property {boolean} vertical - text is in vertical mode.
  1799. * @property {string} fontFamily - possible font family
  1800. */
  1801. /**
  1802. * Page render parameters.
  1803. *
  1804. * @typedef {Object} RenderParameters
  1805. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1806. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1807. * calling of PDFPage.getViewport method.
  1808. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1809. * (default value is 'display').
  1810. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1811. * endLayout and appendImage functions.
  1812. * @property {function} continueCallback - (optional) A function that will be
  1813. * called each time the rendering is paused. To continue
  1814. * rendering call the function that is the first argument
  1815. * to the callback.
  1816. */
  1817. /**
  1818. * PDF page operator list.
  1819. *
  1820. * @typedef {Object} PDFOperatorList
  1821. * @property {Array} fnArray - Array containing the operator functions.
  1822. * @property {Array} argsArray - Array containing the arguments of the
  1823. * functions.
  1824. */
  1825. /**
  1826. * Proxy to a PDFPage in the worker thread.
  1827. * @class
  1828. */
  1829. var PDFPageProxy = (function PDFPageProxyClosure() {
  1830. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1831. this.pageIndex = pageIndex;
  1832. this.pageInfo = pageInfo;
  1833. this.transport = transport;
  1834. this.stats = new StatTimer();
  1835. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1836. this.commonObjs = transport.commonObjs;
  1837. this.objs = new PDFObjects();
  1838. this.cleanupAfterRender = false;
  1839. this.pendingDestroy = false;
  1840. this.intentStates = {};
  1841. }
  1842. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  1843. /**
  1844. * @return {number} Page number of the page. First page is 1.
  1845. */
  1846. get pageNumber() {
  1847. return this.pageIndex + 1;
  1848. },
  1849. /**
  1850. * @return {number} The number of degrees the page is rotated clockwise.
  1851. */
  1852. get rotate() {
  1853. return this.pageInfo.rotate;
  1854. },
  1855. /**
  1856. * @return {Object} The reference that points to this page. It has 'num' and
  1857. * 'gen' properties.
  1858. */
  1859. get ref() {
  1860. return this.pageInfo.ref;
  1861. },
  1862. /**
  1863. * @return {Array} An array of the visible portion of the PDF page in the
  1864. * user space units - [x1, y1, x2, y2].
  1865. */
  1866. get view() {
  1867. return this.pageInfo.view;
  1868. },
  1869. /**
  1870. * @param {number} scale The desired scale of the viewport.
  1871. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  1872. * defaults to the page rotation.
  1873. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  1874. * along with transforms required for rendering.
  1875. */
  1876. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  1877. if (arguments.length < 2) {
  1878. rotate = this.rotate;
  1879. }
  1880. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  1881. },
  1882. /**
  1883. * @return {Promise} A promise that is resolved with an {Array} of the
  1884. * annotation objects.
  1885. */
  1886. getAnnotations: function PDFPageProxy_getAnnotations() {
  1887. if (this.annotationsPromise) {
  1888. return this.annotationsPromise;
  1889. }
  1890. var promise = this.transport.getAnnotations(this.pageIndex);
  1891. this.annotationsPromise = promise;
  1892. return promise;
  1893. },
  1894. /**
  1895. * Begins the process of rendering a page to the desired context.
  1896. * @param {RenderParameters} params Page render parameters.
  1897. * @return {RenderTask} An object that contains the promise, which
  1898. * is resolved when the page finishes rendering.
  1899. */
  1900. render: function PDFPageProxy_render(params) {
  1901. var stats = this.stats;
  1902. stats.time('Overall');
  1903. // If there was a pending destroy cancel it so no cleanup happens during
  1904. // this call to render.
  1905. this.pendingDestroy = false;
  1906. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  1907. if (!this.intentStates[renderingIntent]) {
  1908. this.intentStates[renderingIntent] = {};
  1909. }
  1910. var intentState = this.intentStates[renderingIntent];
  1911. // If there's no displayReadyCapability yet, then the operatorList
  1912. // was never requested before. Make the request and create the promise.
  1913. if (!intentState.displayReadyCapability) {
  1914. intentState.receivingOperatorList = true;
  1915. intentState.displayReadyCapability = createPromiseCapability();
  1916. intentState.operatorList = {
  1917. fnArray: [],
  1918. argsArray: [],
  1919. lastChunk: false
  1920. };
  1921. this.stats.time('Page Request');
  1922. this.transport.messageHandler.send('RenderPageRequest', {
  1923. pageIndex: this.pageNumber - 1,
  1924. intent: renderingIntent
  1925. });
  1926. }
  1927. var internalRenderTask = new InternalRenderTask(complete, params,
  1928. this.objs,
  1929. this.commonObjs,
  1930. intentState.operatorList,
  1931. this.pageNumber);
  1932. if (!intentState.renderTasks) {
  1933. intentState.renderTasks = [];
  1934. }
  1935. intentState.renderTasks.push(internalRenderTask);
  1936. var renderTask = new RenderTask(internalRenderTask);
  1937. var self = this;
  1938. intentState.displayReadyCapability.promise.then(
  1939. function pageDisplayReadyPromise(transparency) {
  1940. if (self.pendingDestroy) {
  1941. complete();
  1942. return;
  1943. }
  1944. stats.time('Rendering');
  1945. internalRenderTask.initalizeGraphics(transparency);
  1946. internalRenderTask.operatorListChanged();
  1947. },
  1948. function pageDisplayReadPromiseError(reason) {
  1949. complete(reason);
  1950. }
  1951. );
  1952. function complete(error) {
  1953. var i = intentState.renderTasks.indexOf(internalRenderTask);
  1954. if (i >= 0) {
  1955. intentState.renderTasks.splice(i, 1);
  1956. }
  1957. if (self.cleanupAfterRender) {
  1958. self.pendingDestroy = true;
  1959. }
  1960. self._tryDestroy();
  1961. if (error) {
  1962. internalRenderTask.capability.reject(error);
  1963. } else {
  1964. internalRenderTask.capability.resolve();
  1965. }
  1966. stats.timeEnd('Rendering');
  1967. stats.timeEnd('Overall');
  1968. }
  1969. return renderTask;
  1970. },
  1971. /**
  1972. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  1973. * object that represents page's operator list.
  1974. */
  1975. getOperatorList: function PDFPageProxy_getOperatorList() {
  1976. function operatorListChanged() {
  1977. if (intentState.operatorList.lastChunk) {
  1978. intentState.opListReadCapability.resolve(intentState.operatorList);
  1979. }
  1980. }
  1981. var renderingIntent = 'oplist';
  1982. if (!this.intentStates[renderingIntent]) {
  1983. this.intentStates[renderingIntent] = {};
  1984. }
  1985. var intentState = this.intentStates[renderingIntent];
  1986. if (!intentState.opListReadCapability) {
  1987. var opListTask = {};
  1988. opListTask.operatorListChanged = operatorListChanged;
  1989. intentState.receivingOperatorList = true;
  1990. intentState.opListReadCapability = createPromiseCapability();
  1991. intentState.renderTasks = [];
  1992. intentState.renderTasks.push(opListTask);
  1993. intentState.operatorList = {
  1994. fnArray: [],
  1995. argsArray: [],
  1996. lastChunk: false
  1997. };
  1998. this.transport.messageHandler.send('RenderPageRequest', {
  1999. pageIndex: this.pageIndex,
  2000. intent: renderingIntent
  2001. });
  2002. }
  2003. return intentState.opListReadCapability.promise;
  2004. },
  2005. /**
  2006. * @return {Promise} That is resolved a {@link TextContent}
  2007. * object that represent the page text content.
  2008. */
  2009. getTextContent: function PDFPageProxy_getTextContent() {
  2010. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2011. pageIndex: this.pageNumber - 1
  2012. });
  2013. },
  2014. /**
  2015. * Destroys resources allocated by the page.
  2016. */
  2017. destroy: function PDFPageProxy_destroy() {
  2018. this.pendingDestroy = true;
  2019. this._tryDestroy();
  2020. },
  2021. /**
  2022. * For internal use only. Attempts to clean up if rendering is in a state
  2023. * where that's possible.
  2024. * @ignore
  2025. */
  2026. _tryDestroy: function PDFPageProxy__destroy() {
  2027. if (!this.pendingDestroy ||
  2028. Object.keys(this.intentStates).some(function(intent) {
  2029. var intentState = this.intentStates[intent];
  2030. return (intentState.renderTasks.length !== 0 ||
  2031. intentState.receivingOperatorList);
  2032. }, this)) {
  2033. return;
  2034. }
  2035. Object.keys(this.intentStates).forEach(function(intent) {
  2036. delete this.intentStates[intent];
  2037. }, this);
  2038. this.objs.clear();
  2039. this.annotationsPromise = null;
  2040. this.pendingDestroy = false;
  2041. },
  2042. /**
  2043. * For internal use only.
  2044. * @ignore
  2045. */
  2046. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2047. intent) {
  2048. var intentState = this.intentStates[intent];
  2049. // TODO Refactor RenderPageRequest to separate rendering
  2050. // and operator list logic
  2051. if (intentState.displayReadyCapability) {
  2052. intentState.displayReadyCapability.resolve(transparency);
  2053. }
  2054. },
  2055. /**
  2056. * For internal use only.
  2057. * @ignore
  2058. */
  2059. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2060. intent) {
  2061. var intentState = this.intentStates[intent];
  2062. var i, ii;
  2063. // Add the new chunk to the current operator list.
  2064. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2065. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2066. intentState.operatorList.argsArray.push(
  2067. operatorListChunk.argsArray[i]);
  2068. }
  2069. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2070. // Notify all the rendering tasks there are more operators to be consumed.
  2071. for (i = 0; i < intentState.renderTasks.length; i++) {
  2072. intentState.renderTasks[i].operatorListChanged();
  2073. }
  2074. if (operatorListChunk.lastChunk) {
  2075. intentState.receivingOperatorList = false;
  2076. this._tryDestroy();
  2077. }
  2078. }
  2079. };
  2080. return PDFPageProxy;
  2081. })();
  2082. /**
  2083. * For internal use only.
  2084. * @ignore
  2085. */
  2086. var WorkerTransport = (function WorkerTransportClosure() {
  2087. function WorkerTransport(workerInitializedCapability, workerReadyCapability,
  2088. pdfDataRangeTransport, progressCallback) {
  2089. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2090. this.workerInitializedCapability = workerInitializedCapability;
  2091. this.workerReadyCapability = workerReadyCapability;
  2092. this.progressCallback = progressCallback;
  2093. this.commonObjs = new PDFObjects();
  2094. this.pageCache = [];
  2095. this.pagePromises = [];
  2096. this.downloadInfoCapability = createPromiseCapability();
  2097. this.passwordCallback = null;
  2098. // If worker support isn't disabled explicit and the browser has worker
  2099. // support, create a new web worker and test if it/the browser fullfills
  2100. // all requirements to run parts of pdf.js in a web worker.
  2101. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2102. // as it arrives on the worker. Chrome added this with version 15.
  2103. // Either workers are disabled, not supported or have thrown an exception.
  2104. // Thus, we fallback to a faked worker.
  2105. this.setupFakeWorker();
  2106. }
  2107. WorkerTransport.prototype = {
  2108. destroy: function WorkerTransport_destroy() {
  2109. this.pageCache = [];
  2110. this.pagePromises = [];
  2111. var self = this;
  2112. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2113. FontLoader.clear();
  2114. if (self.worker) {
  2115. self.worker.terminate();
  2116. }
  2117. });
  2118. },
  2119. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2120. globalScope.PDFJS.disableWorker = true;
  2121. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2122. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2123. // In the developer build load worker_loader which in turn loads all the
  2124. // other files and resolves the promise. In production only the
  2125. // pdf.worker.js file is needed.
  2126. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2127. }
  2128. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2129. warn('Setting up fake worker.');
  2130. // If we don't use a worker, just post/sendMessage to the main thread.
  2131. var fakeWorker = {
  2132. postMessage: function WorkerTransport_postMessage(obj) {
  2133. fakeWorker.onmessage({data: obj});
  2134. },
  2135. terminate: function WorkerTransport_terminate() {}
  2136. };
  2137. var messageHandler = new MessageHandler('main', fakeWorker);
  2138. this.setupMessageHandler(messageHandler);
  2139. // If the main thread is our worker, setup the handling for the messages
  2140. // the main thread sends to it self.
  2141. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2142. this.workerInitializedCapability.resolve();
  2143. }.bind(this));
  2144. },
  2145. setupMessageHandler:
  2146. function WorkerTransport_setupMessageHandler(messageHandler) {
  2147. this.messageHandler = messageHandler;
  2148. function updatePassword(password) {
  2149. messageHandler.send('UpdatePassword', password);
  2150. }
  2151. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2152. if (pdfDataRangeTransport) {
  2153. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2154. messageHandler.send('OnDataRange', {
  2155. begin: begin,
  2156. chunk: chunk
  2157. });
  2158. });
  2159. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2160. messageHandler.send('OnDataProgress', {
  2161. loaded: loaded
  2162. });
  2163. });
  2164. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2165. messageHandler.send('OnDataRange', {
  2166. chunk: chunk
  2167. });
  2168. });
  2169. messageHandler.on('RequestDataRange',
  2170. function transportDataRange(data) {
  2171. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2172. }, this);
  2173. }
  2174. messageHandler.on('GetDoc', function transportDoc(data) {
  2175. var pdfInfo = data.pdfInfo;
  2176. this.numPages = data.pdfInfo.numPages;
  2177. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2178. this.pdfDocument = pdfDocument;
  2179. this.workerReadyCapability.resolve(pdfDocument);
  2180. }, this);
  2181. messageHandler.on('NeedPassword',
  2182. function transportNeedPassword(exception) {
  2183. if (this.passwordCallback) {
  2184. return this.passwordCallback(updatePassword,
  2185. PasswordResponses.NEED_PASSWORD);
  2186. }
  2187. this.workerReadyCapability.reject(
  2188. new PasswordException(exception.message, exception.code));
  2189. }, this);
  2190. messageHandler.on('IncorrectPassword',
  2191. function transportIncorrectPassword(exception) {
  2192. if (this.passwordCallback) {
  2193. return this.passwordCallback(updatePassword,
  2194. PasswordResponses.INCORRECT_PASSWORD);
  2195. }
  2196. this.workerReadyCapability.reject(
  2197. new PasswordException(exception.message, exception.code));
  2198. }, this);
  2199. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2200. this.workerReadyCapability.reject(
  2201. new InvalidPDFException(exception.message));
  2202. }, this);
  2203. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2204. this.workerReadyCapability.reject(
  2205. new MissingPDFException(exception.message));
  2206. }, this);
  2207. messageHandler.on('UnexpectedResponse',
  2208. function transportUnexpectedResponse(exception) {
  2209. this.workerReadyCapability.reject(
  2210. new UnexpectedResponseException(exception.message, exception.status));
  2211. }, this);
  2212. messageHandler.on('UnknownError',
  2213. function transportUnknownError(exception) {
  2214. this.workerReadyCapability.reject(
  2215. new UnknownErrorException(exception.message, exception.details));
  2216. }, this);
  2217. messageHandler.on('DataLoaded', function transportPage(data) {
  2218. this.downloadInfoCapability.resolve(data);
  2219. }, this);
  2220. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2221. if (this.pdfDataRangeTransport) {
  2222. this.pdfDataRangeTransport.transportReady();
  2223. }
  2224. }, this);
  2225. messageHandler.on('StartRenderPage', function transportRender(data) {
  2226. var page = this.pageCache[data.pageIndex];
  2227. page.stats.timeEnd('Page Request');
  2228. page._startRenderPage(data.transparency, data.intent);
  2229. }, this);
  2230. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2231. var page = this.pageCache[data.pageIndex];
  2232. page._renderPageChunk(data.operatorList, data.intent);
  2233. }, this);
  2234. messageHandler.on('commonobj', function transportObj(data) {
  2235. var id = data[0];
  2236. var type = data[1];
  2237. if (this.commonObjs.hasData(id)) {
  2238. return;
  2239. }
  2240. switch (type) {
  2241. case 'Font':
  2242. var exportedData = data[2];
  2243. var font;
  2244. if ('error' in exportedData) {
  2245. var error = exportedData.error;
  2246. warn('Error during font loading: ' + error);
  2247. this.commonObjs.resolve(id, error);
  2248. break;
  2249. } else {
  2250. font = new FontFaceObject(exportedData);
  2251. }
  2252. FontLoader.bind(
  2253. [font],
  2254. function fontReady(fontObjs) {
  2255. this.commonObjs.resolve(id, font);
  2256. }.bind(this)
  2257. );
  2258. break;
  2259. case 'FontPath':
  2260. this.commonObjs.resolve(id, data[2]);
  2261. break;
  2262. default:
  2263. error('Got unknown common object type ' + type);
  2264. }
  2265. }, this);
  2266. messageHandler.on('obj', function transportObj(data) {
  2267. var id = data[0];
  2268. var pageIndex = data[1];
  2269. var type = data[2];
  2270. var pageProxy = this.pageCache[pageIndex];
  2271. var imageData;
  2272. if (pageProxy.objs.hasData(id)) {
  2273. return;
  2274. }
  2275. switch (type) {
  2276. case 'JpegStream':
  2277. imageData = data[3];
  2278. loadJpegStream(id, imageData, pageProxy.objs);
  2279. break;
  2280. case 'Image':
  2281. imageData = data[3];
  2282. pageProxy.objs.resolve(id, imageData);
  2283. // heuristics that will allow not to store large data
  2284. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2285. if (imageData && 'data' in imageData &&
  2286. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2287. pageProxy.cleanupAfterRender = true;
  2288. }
  2289. break;
  2290. default:
  2291. error('Got unknown object type ' + type);
  2292. }
  2293. }, this);
  2294. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2295. if (this.progressCallback) {
  2296. this.progressCallback({
  2297. loaded: data.loaded,
  2298. total: data.total
  2299. });
  2300. }
  2301. }, this);
  2302. messageHandler.on('PageError', function transportError(data) {
  2303. var page = this.pageCache[data.pageNum - 1];
  2304. var intentState = page.intentStates[data.intent];
  2305. if (intentState.displayReadyCapability) {
  2306. intentState.displayReadyCapability.reject(data.error);
  2307. } else {
  2308. error(data.error);
  2309. }
  2310. }, this);
  2311. messageHandler.on('JpegDecode', function(data) {
  2312. var imageUrl = data[0];
  2313. var components = data[1];
  2314. if (components !== 3 && components !== 1) {
  2315. return Promise.reject(
  2316. new Error('Only 3 components or 1 component can be returned'));
  2317. }
  2318. return new Promise(function (resolve, reject) {
  2319. var img = new Image();
  2320. img.onload = function () {
  2321. var width = img.width;
  2322. var height = img.height;
  2323. var size = width * height;
  2324. var rgbaLength = size * 4;
  2325. var buf = new Uint8Array(size * components);
  2326. var tmpCanvas = createScratchCanvas(width, height);
  2327. var tmpCtx = tmpCanvas.getContext('2d');
  2328. tmpCtx.drawImage(img, 0, 0);
  2329. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2330. var i, j;
  2331. if (components === 3) {
  2332. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2333. buf[j] = data[i];
  2334. buf[j + 1] = data[i + 1];
  2335. buf[j + 2] = data[i + 2];
  2336. }
  2337. } else if (components === 1) {
  2338. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2339. buf[j] = data[i];
  2340. }
  2341. }
  2342. resolve({ data: buf, width: width, height: height});
  2343. };
  2344. img.onerror = function () {
  2345. reject(new Error('JpegDecode failed to load image'));
  2346. };
  2347. img.src = imageUrl;
  2348. });
  2349. });
  2350. },
  2351. fetchDocument: function WorkerTransport_fetchDocument(source) {
  2352. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2353. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2354. this.messageHandler.send('GetDocRequest', {
  2355. source: source,
  2356. disableRange: PDFJS.disableRange,
  2357. maxImageSize: PDFJS.maxImageSize,
  2358. cMapUrl: PDFJS.cMapUrl,
  2359. cMapPacked: PDFJS.cMapPacked,
  2360. disableFontFace: PDFJS.disableFontFace,
  2361. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2362. verbosity: PDFJS.verbosity
  2363. });
  2364. },
  2365. getData: function WorkerTransport_getData() {
  2366. return this.messageHandler.sendWithPromise('GetData', null);
  2367. },
  2368. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2369. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2370. (pageNumber|0) !== pageNumber) {
  2371. return Promise.reject(new Error('Invalid page request'));
  2372. }
  2373. var pageIndex = pageNumber - 1;
  2374. if (pageIndex in this.pagePromises) {
  2375. return this.pagePromises[pageIndex];
  2376. }
  2377. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2378. pageIndex: pageIndex
  2379. }).then(function (pageInfo) {
  2380. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2381. this.pageCache[pageIndex] = page;
  2382. return page;
  2383. }.bind(this));
  2384. this.pagePromises[pageIndex] = promise;
  2385. return promise;
  2386. },
  2387. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2388. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2389. },
  2390. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2391. return this.messageHandler.sendWithPromise('GetAnnotations',
  2392. { pageIndex: pageIndex });
  2393. },
  2394. getDestinations: function WorkerTransport_getDestinations() {
  2395. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2396. },
  2397. getAttachments: function WorkerTransport_getAttachments() {
  2398. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2399. },
  2400. getJavaScript: function WorkerTransport_getJavaScript() {
  2401. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2402. },
  2403. getOutline: function WorkerTransport_getOutline() {
  2404. return this.messageHandler.sendWithPromise('GetOutline', null);
  2405. },
  2406. getMetadata: function WorkerTransport_getMetadata() {
  2407. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2408. then(function transportMetadata(results) {
  2409. return {
  2410. info: results[0],
  2411. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2412. };
  2413. });
  2414. },
  2415. getStats: function WorkerTransport_getStats() {
  2416. return this.messageHandler.sendWithPromise('GetStats', null);
  2417. },
  2418. startCleanup: function WorkerTransport_startCleanup() {
  2419. this.messageHandler.sendWithPromise('Cleanup', null).
  2420. then(function endCleanup() {
  2421. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2422. var page = this.pageCache[i];
  2423. if (page) {
  2424. page.destroy();
  2425. }
  2426. }
  2427. this.commonObjs.clear();
  2428. FontLoader.clear();
  2429. }.bind(this));
  2430. }
  2431. };
  2432. return WorkerTransport;
  2433. })();
  2434. /**
  2435. * A PDF document and page is built of many objects. E.g. there are objects
  2436. * for fonts, images, rendering code and such. These objects might get processed
  2437. * inside of a worker. The `PDFObjects` implements some basic functions to
  2438. * manage these objects.
  2439. * @ignore
  2440. */
  2441. var PDFObjects = (function PDFObjectsClosure() {
  2442. function PDFObjects() {
  2443. this.objs = {};
  2444. }
  2445. PDFObjects.prototype = {
  2446. /**
  2447. * Internal function.
  2448. * Ensures there is an object defined for `objId`.
  2449. */
  2450. ensureObj: function PDFObjects_ensureObj(objId) {
  2451. if (this.objs[objId]) {
  2452. return this.objs[objId];
  2453. }
  2454. var obj = {
  2455. capability: createPromiseCapability(),
  2456. data: null,
  2457. resolved: false
  2458. };
  2459. this.objs[objId] = obj;
  2460. return obj;
  2461. },
  2462. /**
  2463. * If called *without* callback, this returns the data of `objId` but the
  2464. * object needs to be resolved. If it isn't, this function throws.
  2465. *
  2466. * If called *with* a callback, the callback is called with the data of the
  2467. * object once the object is resolved. That means, if you call this
  2468. * function and the object is already resolved, the callback gets called
  2469. * right away.
  2470. */
  2471. get: function PDFObjects_get(objId, callback) {
  2472. // If there is a callback, then the get can be async and the object is
  2473. // not required to be resolved right now
  2474. if (callback) {
  2475. this.ensureObj(objId).capability.promise.then(callback);
  2476. return null;
  2477. }
  2478. // If there isn't a callback, the user expects to get the resolved data
  2479. // directly.
  2480. var obj = this.objs[objId];
  2481. // If there isn't an object yet or the object isn't resolved, then the
  2482. // data isn't ready yet!
  2483. if (!obj || !obj.resolved) {
  2484. error('Requesting object that isn\'t resolved yet ' + objId);
  2485. }
  2486. return obj.data;
  2487. },
  2488. /**
  2489. * Resolves the object `objId` with optional `data`.
  2490. */
  2491. resolve: function PDFObjects_resolve(objId, data) {
  2492. var obj = this.ensureObj(objId);
  2493. obj.resolved = true;
  2494. obj.data = data;
  2495. obj.capability.resolve(data);
  2496. },
  2497. isResolved: function PDFObjects_isResolved(objId) {
  2498. var objs = this.objs;
  2499. if (!objs[objId]) {
  2500. return false;
  2501. } else {
  2502. return objs[objId].resolved;
  2503. }
  2504. },
  2505. hasData: function PDFObjects_hasData(objId) {
  2506. return this.isResolved(objId);
  2507. },
  2508. /**
  2509. * Returns the data of `objId` if object exists, null otherwise.
  2510. */
  2511. getData: function PDFObjects_getData(objId) {
  2512. var objs = this.objs;
  2513. if (!objs[objId] || !objs[objId].resolved) {
  2514. return null;
  2515. } else {
  2516. return objs[objId].data;
  2517. }
  2518. },
  2519. clear: function PDFObjects_clear() {
  2520. this.objs = {};
  2521. }
  2522. };
  2523. return PDFObjects;
  2524. })();
  2525. /**
  2526. * Allows controlling of the rendering tasks.
  2527. * @class
  2528. */
  2529. var RenderTask = (function RenderTaskClosure() {
  2530. function RenderTask(internalRenderTask) {
  2531. this.internalRenderTask = internalRenderTask;
  2532. /**
  2533. * Promise for rendering task completion.
  2534. * @type {Promise}
  2535. */
  2536. this.promise = this.internalRenderTask.capability.promise;
  2537. }
  2538. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2539. /**
  2540. * Cancels the rendering task. If the task is currently rendering it will
  2541. * not be cancelled until graphics pauses with a timeout. The promise that
  2542. * this object extends will resolved when cancelled.
  2543. */
  2544. cancel: function RenderTask_cancel() {
  2545. this.internalRenderTask.cancel();
  2546. },
  2547. /**
  2548. * Registers callback to indicate the rendering task completion.
  2549. *
  2550. * @param {function} onFulfilled The callback for the rendering completion.
  2551. * @param {function} onRejected The callback for the rendering failure.
  2552. * @return {Promise} A promise that is resolved after the onFulfilled or
  2553. * onRejected callback.
  2554. */
  2555. then: function RenderTask_then(onFulfilled, onRejected) {
  2556. return this.promise.then(onFulfilled, onRejected);
  2557. }
  2558. };
  2559. return RenderTask;
  2560. })();
  2561. /**
  2562. * For internal use only.
  2563. * @ignore
  2564. */
  2565. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2566. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2567. pageNumber) {
  2568. this.callback = callback;
  2569. this.params = params;
  2570. this.objs = objs;
  2571. this.commonObjs = commonObjs;
  2572. this.operatorListIdx = null;
  2573. this.operatorList = operatorList;
  2574. this.pageNumber = pageNumber;
  2575. this.running = false;
  2576. this.graphicsReadyCallback = null;
  2577. this.graphicsReady = false;
  2578. this.cancelled = false;
  2579. this.capability = createPromiseCapability();
  2580. // caching this-bound methods
  2581. this._continueBound = this._continue.bind(this);
  2582. this._scheduleNextBound = this._scheduleNext.bind(this);
  2583. this._nextBound = this._next.bind(this);
  2584. }
  2585. InternalRenderTask.prototype = {
  2586. initalizeGraphics:
  2587. function InternalRenderTask_initalizeGraphics(transparency) {
  2588. if (this.cancelled) {
  2589. return;
  2590. }
  2591. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2592. globalScope.StepperManager.enabled) {
  2593. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2594. this.stepper.init(this.operatorList);
  2595. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2596. }
  2597. var params = this.params;
  2598. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2599. this.objs, params.imageLayer);
  2600. this.gfx.beginDrawing(params.viewport, transparency);
  2601. this.operatorListIdx = 0;
  2602. this.graphicsReady = true;
  2603. if (this.graphicsReadyCallback) {
  2604. this.graphicsReadyCallback();
  2605. }
  2606. },
  2607. cancel: function InternalRenderTask_cancel() {
  2608. this.running = false;
  2609. this.cancelled = true;
  2610. this.callback('cancelled');
  2611. },
  2612. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2613. if (!this.graphicsReady) {
  2614. if (!this.graphicsReadyCallback) {
  2615. this.graphicsReadyCallback = this._continueBound;
  2616. }
  2617. return;
  2618. }
  2619. if (this.stepper) {
  2620. this.stepper.updateOperatorList(this.operatorList);
  2621. }
  2622. if (this.running) {
  2623. return;
  2624. }
  2625. this._continue();
  2626. },
  2627. _continue: function InternalRenderTask__continue() {
  2628. this.running = true;
  2629. if (this.cancelled) {
  2630. return;
  2631. }
  2632. if (this.params.continueCallback) {
  2633. this.params.continueCallback(this._scheduleNextBound);
  2634. } else {
  2635. this._scheduleNext();
  2636. }
  2637. },
  2638. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2639. window.requestAnimationFrame(this._nextBound);
  2640. },
  2641. _next: function InternalRenderTask__next() {
  2642. if (this.cancelled) {
  2643. return;
  2644. }
  2645. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2646. this.operatorListIdx,
  2647. this._continueBound,
  2648. this.stepper);
  2649. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2650. this.running = false;
  2651. if (this.operatorList.lastChunk) {
  2652. this.gfx.endDrawing();
  2653. this.callback();
  2654. }
  2655. }
  2656. }
  2657. };
  2658. return InternalRenderTask;
  2659. })();
  2660. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2661. function fixMetadata(meta) {
  2662. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2663. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2664. function(code, d1, d2, d3) {
  2665. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2666. });
  2667. var chars = '';
  2668. for (var i = 0; i < bytes.length; i += 2) {
  2669. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2670. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2671. code !== 38 && false ? String.fromCharCode(code) :
  2672. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2673. }
  2674. return '>' + chars;
  2675. });
  2676. }
  2677. function Metadata(meta) {
  2678. if (typeof meta === 'string') {
  2679. // Ghostscript produces invalid metadata
  2680. meta = fixMetadata(meta);
  2681. var parser = new DOMParser();
  2682. meta = parser.parseFromString(meta, 'application/xml');
  2683. } else if (!(meta instanceof Document)) {
  2684. error('Metadata: Invalid metadata object');
  2685. }
  2686. this.metaDocument = meta;
  2687. this.metadata = {};
  2688. this.parse();
  2689. }
  2690. Metadata.prototype = {
  2691. parse: function Metadata_parse() {
  2692. var doc = this.metaDocument;
  2693. var rdf = doc.documentElement;
  2694. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2695. rdf = rdf.firstChild;
  2696. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2697. rdf = rdf.nextSibling;
  2698. }
  2699. }
  2700. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2701. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2702. return;
  2703. }
  2704. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2705. for (i = 0, length = children.length; i < length; i++) {
  2706. desc = children[i];
  2707. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2708. continue;
  2709. }
  2710. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2711. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2712. entry = desc.childNodes[ii];
  2713. name = entry.nodeName.toLowerCase();
  2714. this.metadata[name] = entry.textContent.trim();
  2715. }
  2716. }
  2717. }
  2718. },
  2719. get: function Metadata_get(name) {
  2720. return this.metadata[name] || null;
  2721. },
  2722. has: function Metadata_has(name) {
  2723. return typeof this.metadata[name] !== 'undefined';
  2724. }
  2725. };
  2726. return Metadata;
  2727. })();
  2728. // <canvas> contexts store most of the state we need natively.
  2729. // However, PDF needs a bit more state, which we store here.
  2730. // Minimal font size that would be used during canvas fillText operations.
  2731. var MIN_FONT_SIZE = 16;
  2732. var MAX_GROUP_SIZE = 4096;
  2733. var COMPILE_TYPE3_GLYPHS = true;
  2734. function createScratchCanvas(width, height) {
  2735. var canvas = document.createElement('canvas');
  2736. canvas.width = width;
  2737. canvas.height = height;
  2738. return canvas;
  2739. }
  2740. function addContextCurrentTransform(ctx) {
  2741. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2742. if (!ctx.mozCurrentTransform) {
  2743. // Store the original context
  2744. ctx._scaleX = ctx._scaleX || 1.0;
  2745. ctx._scaleY = ctx._scaleY || 1.0;
  2746. ctx._originalSave = ctx.save;
  2747. ctx._originalRestore = ctx.restore;
  2748. ctx._originalRotate = ctx.rotate;
  2749. ctx._originalScale = ctx.scale;
  2750. ctx._originalTranslate = ctx.translate;
  2751. ctx._originalTransform = ctx.transform;
  2752. ctx._originalSetTransform = ctx.setTransform;
  2753. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2754. ctx._transformStack = [];
  2755. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2756. get: function getCurrentTransform() {
  2757. return this._transformMatrix;
  2758. }
  2759. });
  2760. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2761. get: function getCurrentTransformInverse() {
  2762. // Calculation done using WolframAlpha:
  2763. // http://www.wolframalpha.com/input/?
  2764. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2765. var m = this._transformMatrix;
  2766. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2767. var ad_bc = a * d - b * c;
  2768. var bc_ad = b * c - a * d;
  2769. return [
  2770. d / ad_bc,
  2771. b / bc_ad,
  2772. c / bc_ad,
  2773. a / ad_bc,
  2774. (d * e - c * f) / bc_ad,
  2775. (b * e - a * f) / ad_bc
  2776. ];
  2777. }
  2778. });
  2779. ctx.save = function ctxSave() {
  2780. var old = this._transformMatrix;
  2781. this._transformStack.push(old);
  2782. this._transformMatrix = old.slice(0, 6);
  2783. this._originalSave();
  2784. };
  2785. ctx.restore = function ctxRestore() {
  2786. var prev = this._transformStack.pop();
  2787. if (prev) {
  2788. this._transformMatrix = prev;
  2789. this._originalRestore();
  2790. }
  2791. };
  2792. ctx.translate = function ctxTranslate(x, y) {
  2793. var m = this._transformMatrix;
  2794. m[4] = m[0] * x + m[2] * y + m[4];
  2795. m[5] = m[1] * x + m[3] * y + m[5];
  2796. this._originalTranslate(x, y);
  2797. };
  2798. ctx.scale = function ctxScale(x, y) {
  2799. var m = this._transformMatrix;
  2800. m[0] = m[0] * x;
  2801. m[1] = m[1] * x;
  2802. m[2] = m[2] * y;
  2803. m[3] = m[3] * y;
  2804. this._originalScale(x, y);
  2805. };
  2806. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2807. var m = this._transformMatrix;
  2808. this._transformMatrix = [
  2809. m[0] * a + m[2] * b,
  2810. m[1] * a + m[3] * b,
  2811. m[0] * c + m[2] * d,
  2812. m[1] * c + m[3] * d,
  2813. m[0] * e + m[2] * f + m[4],
  2814. m[1] * e + m[3] * f + m[5]
  2815. ];
  2816. ctx._originalTransform(a, b, c, d, e, f);
  2817. };
  2818. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  2819. this._transformMatrix = [a, b, c, d, e, f];
  2820. ctx._originalSetTransform(a, b, c, d, e, f);
  2821. };
  2822. ctx.rotate = function ctxRotate(angle) {
  2823. var cosValue = Math.cos(angle);
  2824. var sinValue = Math.sin(angle);
  2825. var m = this._transformMatrix;
  2826. this._transformMatrix = [
  2827. m[0] * cosValue + m[2] * sinValue,
  2828. m[1] * cosValue + m[3] * sinValue,
  2829. m[0] * (-sinValue) + m[2] * cosValue,
  2830. m[1] * (-sinValue) + m[3] * cosValue,
  2831. m[4],
  2832. m[5]
  2833. ];
  2834. this._originalRotate(angle);
  2835. };
  2836. }
  2837. }
  2838. var CachedCanvases = (function CachedCanvasesClosure() {
  2839. var cache = {};
  2840. return {
  2841. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  2842. trackTransform) {
  2843. var canvasEntry;
  2844. if (id in cache) {
  2845. canvasEntry = cache[id];
  2846. canvasEntry.canvas.width = width;
  2847. canvasEntry.canvas.height = height;
  2848. // reset canvas transform for emulated mozCurrentTransform, if needed
  2849. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  2850. } else {
  2851. var canvas = createScratchCanvas(width, height);
  2852. var ctx = canvas.getContext('2d');
  2853. if (trackTransform) {
  2854. addContextCurrentTransform(ctx);
  2855. }
  2856. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  2857. }
  2858. return canvasEntry;
  2859. },
  2860. clear: function () {
  2861. for (var id in cache) {
  2862. var canvasEntry = cache[id];
  2863. // Zeroing the width and height causes Firefox to release graphics
  2864. // resources immediately, which can greatly reduce memory consumption.
  2865. canvasEntry.canvas.width = 0;
  2866. canvasEntry.canvas.height = 0;
  2867. delete cache[id];
  2868. }
  2869. }
  2870. };
  2871. })();
  2872. function compileType3Glyph(imgData) {
  2873. var POINT_TO_PROCESS_LIMIT = 1000;
  2874. var width = imgData.width, height = imgData.height;
  2875. var i, j, j0, width1 = width + 1;
  2876. var points = new Uint8Array(width1 * (height + 1));
  2877. var POINT_TYPES =
  2878. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  2879. // decodes bit-packed mask data
  2880. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  2881. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  2882. for (i = 0, ii = data0.length; i < ii; i++) {
  2883. var mask = 128, elem = data0[i];
  2884. while (mask > 0) {
  2885. data[pos++] = (elem & mask) ? 0 : 255;
  2886. mask >>= 1;
  2887. }
  2888. }
  2889. // finding iteresting points: every point is located between mask pixels,
  2890. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  2891. // will have flags assigned based on neighboring mask pixels:
  2892. // 4 | 8
  2893. // --P--
  2894. // 2 | 1
  2895. // We are interested only in points with the flags:
  2896. // - outside corners: 1, 2, 4, 8;
  2897. // - inside corners: 7, 11, 13, 14;
  2898. // - and, intersections: 5, 10.
  2899. var count = 0;
  2900. pos = 0;
  2901. if (data[pos] !== 0) {
  2902. points[0] = 1;
  2903. ++count;
  2904. }
  2905. for (j = 1; j < width; j++) {
  2906. if (data[pos] !== data[pos + 1]) {
  2907. points[j] = data[pos] ? 2 : 1;
  2908. ++count;
  2909. }
  2910. pos++;
  2911. }
  2912. if (data[pos] !== 0) {
  2913. points[j] = 2;
  2914. ++count;
  2915. }
  2916. for (i = 1; i < height; i++) {
  2917. pos = i * lineSize;
  2918. j0 = i * width1;
  2919. if (data[pos - lineSize] !== data[pos]) {
  2920. points[j0] = data[pos] ? 1 : 8;
  2921. ++count;
  2922. }
  2923. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  2924. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  2925. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  2926. for (j = 1; j < width; j++) {
  2927. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  2928. (data[pos - lineSize + 1] ? 8 : 0);
  2929. if (POINT_TYPES[sum]) {
  2930. points[j0 + j] = POINT_TYPES[sum];
  2931. ++count;
  2932. }
  2933. pos++;
  2934. }
  2935. if (data[pos - lineSize] !== data[pos]) {
  2936. points[j0 + j] = data[pos] ? 2 : 4;
  2937. ++count;
  2938. }
  2939. if (count > POINT_TO_PROCESS_LIMIT) {
  2940. return null;
  2941. }
  2942. }
  2943. pos = lineSize * (height - 1);
  2944. j0 = i * width1;
  2945. if (data[pos] !== 0) {
  2946. points[j0] = 8;
  2947. ++count;
  2948. }
  2949. for (j = 1; j < width; j++) {
  2950. if (data[pos] !== data[pos + 1]) {
  2951. points[j0 + j] = data[pos] ? 4 : 8;
  2952. ++count;
  2953. }
  2954. pos++;
  2955. }
  2956. if (data[pos] !== 0) {
  2957. points[j0 + j] = 4;
  2958. ++count;
  2959. }
  2960. if (count > POINT_TO_PROCESS_LIMIT) {
  2961. return null;
  2962. }
  2963. // building outlines
  2964. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  2965. var outlines = [];
  2966. for (i = 0; count && i <= height; i++) {
  2967. var p = i * width1;
  2968. var end = p + width;
  2969. while (p < end && !points[p]) {
  2970. p++;
  2971. }
  2972. if (p === end) {
  2973. continue;
  2974. }
  2975. var coords = [p % width1, i];
  2976. var type = points[p], p0 = p, pp;
  2977. do {
  2978. var step = steps[type];
  2979. do {
  2980. p += step;
  2981. } while (!points[p]);
  2982. pp = points[p];
  2983. if (pp !== 5 && pp !== 10) {
  2984. // set new direction
  2985. type = pp;
  2986. // delete mark
  2987. points[p] = 0;
  2988. } else { // type is 5 or 10, ie, a crossing
  2989. // set new direction
  2990. type = pp & ((0x33 * type) >> 4);
  2991. // set new type for "future hit"
  2992. points[p] &= (type >> 2 | type << 2);
  2993. }
  2994. coords.push(p % width1);
  2995. coords.push((p / width1) | 0);
  2996. --count;
  2997. } while (p0 !== p);
  2998. outlines.push(coords);
  2999. --i;
  3000. }
  3001. var drawOutline = function(c) {
  3002. c.save();
  3003. // the path shall be painted in [0..1]x[0..1] space
  3004. c.scale(1 / width, -1 / height);
  3005. c.translate(0, -height);
  3006. c.beginPath();
  3007. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3008. var o = outlines[i];
  3009. c.moveTo(o[0], o[1]);
  3010. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3011. c.lineTo(o[j], o[j+1]);
  3012. }
  3013. }
  3014. c.fill();
  3015. c.beginPath();
  3016. c.restore();
  3017. };
  3018. return drawOutline;
  3019. }
  3020. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3021. function CanvasExtraState(old) {
  3022. // Are soft masks and alpha values shapes or opacities?
  3023. this.alphaIsShape = false;
  3024. this.fontSize = 0;
  3025. this.fontSizeScale = 1;
  3026. this.textMatrix = IDENTITY_MATRIX;
  3027. this.textMatrixScale = 1;
  3028. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3029. this.leading = 0;
  3030. // Current point (in user coordinates)
  3031. this.x = 0;
  3032. this.y = 0;
  3033. // Start of text line (in text coordinates)
  3034. this.lineX = 0;
  3035. this.lineY = 0;
  3036. // Character and word spacing
  3037. this.charSpacing = 0;
  3038. this.wordSpacing = 0;
  3039. this.textHScale = 1;
  3040. this.textRenderingMode = TextRenderingMode.FILL;
  3041. this.textRise = 0;
  3042. // Default fore and background colors
  3043. this.fillColor = '#000000';
  3044. this.strokeColor = '#000000';
  3045. // Note: fill alpha applies to all non-stroking operations
  3046. this.fillAlpha = 1;
  3047. this.strokeAlpha = 1;
  3048. this.lineWidth = 1;
  3049. this.activeSMask = null; // nonclonable field (see the save method below)
  3050. this.old = old;
  3051. }
  3052. CanvasExtraState.prototype = {
  3053. clone: function CanvasExtraState_clone() {
  3054. return Object.create(this);
  3055. },
  3056. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3057. this.x = x;
  3058. this.y = y;
  3059. }
  3060. };
  3061. return CanvasExtraState;
  3062. })();
  3063. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3064. // Defines the time the executeOperatorList is going to be executing
  3065. // before it stops and shedules a continue of execution.
  3066. var EXECUTION_TIME = 15;
  3067. // Defines the number of steps before checking the execution time
  3068. var EXECUTION_STEPS = 10;
  3069. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3070. this.ctx = canvasCtx;
  3071. this.current = new CanvasExtraState();
  3072. this.stateStack = [];
  3073. this.pendingClip = null;
  3074. this.pendingEOFill = false;
  3075. this.res = null;
  3076. this.xobjs = null;
  3077. this.commonObjs = commonObjs;
  3078. this.objs = objs;
  3079. this.imageLayer = imageLayer;
  3080. this.groupStack = [];
  3081. this.processingType3 = null;
  3082. // Patterns are painted relative to the initial page/form transform, see pdf
  3083. // spec 8.7.2 NOTE 1.
  3084. this.baseTransform = null;
  3085. this.baseTransformStack = [];
  3086. this.groupLevel = 0;
  3087. this.smaskStack = [];
  3088. this.smaskCounter = 0;
  3089. this.tempSMask = null;
  3090. if (canvasCtx) {
  3091. addContextCurrentTransform(canvasCtx);
  3092. }
  3093. }
  3094. function putBinaryImageData(ctx, imgData) {
  3095. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3096. ctx.putImageData(imgData, 0, 0);
  3097. return;
  3098. }
  3099. // Put the image data to the canvas in chunks, rather than putting the
  3100. // whole image at once. This saves JS memory, because the ImageData object
  3101. // is smaller. It also possibly saves C++ memory within the implementation
  3102. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3103. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3104. // because too many putImageData() calls will slow things down.
  3105. //
  3106. // Note: as written, if the last chunk is partial, the putImageData() call
  3107. // will (conceptually) put pixels past the bounds of the canvas. But
  3108. // that's ok; any such pixels are ignored.
  3109. var height = imgData.height, width = imgData.width;
  3110. var fullChunkHeight = 16;
  3111. var fracChunks = height / fullChunkHeight;
  3112. var fullChunks = Math.floor(fracChunks);
  3113. var totalChunks = Math.ceil(fracChunks);
  3114. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3115. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3116. var srcPos = 0, destPos;
  3117. var src = imgData.data;
  3118. var dest = chunkImgData.data;
  3119. var i, j, thisChunkHeight, elemsInThisChunk;
  3120. // There are multiple forms in which the pixel data can be passed, and
  3121. // imgData.kind tells us which one this is.
  3122. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3123. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3124. var srcLength = src.byteLength;
  3125. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3126. new Uint32ArrayView(dest);
  3127. var dest32DataLength = dest32.length;
  3128. var fullSrcDiff = (width + 7) >> 3;
  3129. var white = 0xFFFFFFFF;
  3130. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3131. 0xFF000000 : 0x000000FF;
  3132. for (i = 0; i < totalChunks; i++) {
  3133. thisChunkHeight =
  3134. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3135. destPos = 0;
  3136. for (j = 0; j < thisChunkHeight; j++) {
  3137. var srcDiff = srcLength - srcPos;
  3138. var k = 0;
  3139. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3140. var kEndUnrolled = kEnd & ~7;
  3141. var mask = 0;
  3142. var srcByte = 0;
  3143. for (; k < kEndUnrolled; k += 8) {
  3144. srcByte = src[srcPos++];
  3145. dest32[destPos++] = (srcByte & 128) ? white : black;
  3146. dest32[destPos++] = (srcByte & 64) ? white : black;
  3147. dest32[destPos++] = (srcByte & 32) ? white : black;
  3148. dest32[destPos++] = (srcByte & 16) ? white : black;
  3149. dest32[destPos++] = (srcByte & 8) ? white : black;
  3150. dest32[destPos++] = (srcByte & 4) ? white : black;
  3151. dest32[destPos++] = (srcByte & 2) ? white : black;
  3152. dest32[destPos++] = (srcByte & 1) ? white : black;
  3153. }
  3154. for (; k < kEnd; k++) {
  3155. if (mask === 0) {
  3156. srcByte = src[srcPos++];
  3157. mask = 128;
  3158. }
  3159. dest32[destPos++] = (srcByte & mask) ? white : black;
  3160. mask >>= 1;
  3161. }
  3162. }
  3163. // We ran out of input. Make all remaining pixels transparent.
  3164. while (destPos < dest32DataLength) {
  3165. dest32[destPos++] = 0;
  3166. }
  3167. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3168. }
  3169. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3170. // RGBA, 32-bits per pixel.
  3171. j = 0;
  3172. elemsInThisChunk = width * fullChunkHeight * 4;
  3173. for (i = 0; i < fullChunks; i++) {
  3174. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3175. srcPos += elemsInThisChunk;
  3176. ctx.putImageData(chunkImgData, 0, j);
  3177. j += fullChunkHeight;
  3178. }
  3179. if (i < totalChunks) {
  3180. elemsInThisChunk = width * partialChunkHeight * 4;
  3181. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3182. ctx.putImageData(chunkImgData, 0, j);
  3183. }
  3184. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3185. // RGB, 24-bits per pixel.
  3186. thisChunkHeight = fullChunkHeight;
  3187. elemsInThisChunk = width * thisChunkHeight;
  3188. for (i = 0; i < totalChunks; i++) {
  3189. if (i >= fullChunks) {
  3190. thisChunkHeight =partialChunkHeight;
  3191. elemsInThisChunk = width * thisChunkHeight;
  3192. }
  3193. destPos = 0;
  3194. for (j = elemsInThisChunk; j--;) {
  3195. dest[destPos++] = src[srcPos++];
  3196. dest[destPos++] = src[srcPos++];
  3197. dest[destPos++] = src[srcPos++];
  3198. dest[destPos++] = 255;
  3199. }
  3200. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3201. }
  3202. } else {
  3203. error('bad image kind: ' + imgData.kind);
  3204. }
  3205. }
  3206. function putBinaryImageMask(ctx, imgData) {
  3207. var height = imgData.height, width = imgData.width;
  3208. var fullChunkHeight = 16;
  3209. var fracChunks = height / fullChunkHeight;
  3210. var fullChunks = Math.floor(fracChunks);
  3211. var totalChunks = Math.ceil(fracChunks);
  3212. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3213. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3214. var srcPos = 0;
  3215. var src = imgData.data;
  3216. var dest = chunkImgData.data;
  3217. for (var i = 0; i < totalChunks; i++) {
  3218. var thisChunkHeight =
  3219. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3220. // Expand the mask so it can be used by the canvas. Any required
  3221. // inversion has already been handled.
  3222. var destPos = 3; // alpha component offset
  3223. for (var j = 0; j < thisChunkHeight; j++) {
  3224. var mask = 0;
  3225. for (var k = 0; k < width; k++) {
  3226. if (!mask) {
  3227. var elem = src[srcPos++];
  3228. mask = 128;
  3229. }
  3230. dest[destPos] = (elem & mask) ? 0 : 255;
  3231. destPos += 4;
  3232. mask >>= 1;
  3233. }
  3234. }
  3235. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3236. }
  3237. }
  3238. function copyCtxState(sourceCtx, destCtx) {
  3239. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3240. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3241. 'globalCompositeOperation', 'font'];
  3242. for (var i = 0, ii = properties.length; i < ii; i++) {
  3243. var property = properties[i];
  3244. if (property in sourceCtx) {
  3245. destCtx[property] = sourceCtx[property];
  3246. }
  3247. }
  3248. if ('setLineDash' in sourceCtx) {
  3249. destCtx.setLineDash(sourceCtx.getLineDash());
  3250. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3251. } else if ('mozDash' in sourceCtx) {
  3252. destCtx.mozDash = sourceCtx.mozDash;
  3253. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3254. }
  3255. }
  3256. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3257. var length = bytes.length;
  3258. for (var i = 3; i < length; i += 4) {
  3259. var alpha = bytes[i];
  3260. if (alpha === 0) {
  3261. bytes[i - 3] = r0;
  3262. bytes[i - 2] = g0;
  3263. bytes[i - 1] = b0;
  3264. } else if (alpha < 255) {
  3265. var alpha_ = 255 - alpha;
  3266. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3267. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3268. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3269. }
  3270. }
  3271. }
  3272. function composeSMaskAlpha(maskData, layerData) {
  3273. var length = maskData.length;
  3274. var scale = 1 / 255;
  3275. for (var i = 3; i < length; i += 4) {
  3276. var alpha = maskData[i];
  3277. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3278. }
  3279. }
  3280. function composeSMaskLuminosity(maskData, layerData) {
  3281. var length = maskData.length;
  3282. for (var i = 3; i < length; i += 4) {
  3283. var y = ((maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3284. (maskData[i - 2] * 152) + // * 0.59 ....
  3285. (maskData[i - 1] * 28)) | 0; // * 0.11 ....
  3286. layerData[i] = (layerData[i] * y) >> 16;
  3287. }
  3288. }
  3289. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3290. subtype, backdrop) {
  3291. var hasBackdrop = !!backdrop;
  3292. var r0 = hasBackdrop ? backdrop[0] : 0;
  3293. var g0 = hasBackdrop ? backdrop[1] : 0;
  3294. var b0 = hasBackdrop ? backdrop[2] : 0;
  3295. var composeFn;
  3296. if (subtype === 'Luminosity') {
  3297. composeFn = composeSMaskLuminosity;
  3298. } else {
  3299. composeFn = composeSMaskAlpha;
  3300. }
  3301. // processing image in chunks to save memory
  3302. var PIXELS_TO_PROCESS = 65536;
  3303. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3304. for (var row = 0; row < height; row += chunkSize) {
  3305. var chunkHeight = Math.min(chunkSize, height - row);
  3306. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3307. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3308. if (hasBackdrop) {
  3309. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3310. }
  3311. composeFn(maskData.data, layerData.data);
  3312. maskCtx.putImageData(layerData, 0, row);
  3313. }
  3314. }
  3315. function composeSMask(ctx, smask, layerCtx) {
  3316. var mask = smask.canvas;
  3317. var maskCtx = smask.context;
  3318. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3319. smask.offsetX, smask.offsetY);
  3320. var backdrop = smask.backdrop || null;
  3321. if (WebGLUtils.isEnabled) {
  3322. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3323. {subtype: smask.subtype, backdrop: backdrop});
  3324. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3325. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3326. return;
  3327. }
  3328. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3329. smask.subtype, backdrop);
  3330. ctx.drawImage(mask, 0, 0);
  3331. }
  3332. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3333. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3334. var NORMAL_CLIP = {};
  3335. var EO_CLIP = {};
  3336. CanvasGraphics.prototype = {
  3337. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3338. // For pdfs that use blend modes we have to clear the canvas else certain
  3339. // blend modes can look wrong since we'd be blending with a white
  3340. // backdrop. The problem with a transparent backdrop though is we then
  3341. // don't get sub pixel anti aliasing on text, so we fill with white if
  3342. // we can.
  3343. var width = this.ctx.canvas.width;
  3344. var height = this.ctx.canvas.height;
  3345. if (transparency) {
  3346. this.ctx.clearRect(0, 0, width, height);
  3347. } else {
  3348. this.ctx.mozOpaque = true;
  3349. this.ctx.save();
  3350. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3351. this.ctx.fillRect(0, 0, width, height);
  3352. this.ctx.restore();
  3353. }
  3354. var transform = viewport.transform;
  3355. this.ctx.save();
  3356. this.ctx.transform.apply(this.ctx, transform);
  3357. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3358. if (this.imageLayer) {
  3359. this.imageLayer.beginLayout();
  3360. }
  3361. },
  3362. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3363. operatorList,
  3364. executionStartIdx, continueCallback,
  3365. stepper) {
  3366. var argsArray = operatorList.argsArray;
  3367. var fnArray = operatorList.fnArray;
  3368. var i = executionStartIdx || 0;
  3369. var argsArrayLen = argsArray.length;
  3370. // Sometimes the OperatorList to execute is empty.
  3371. if (argsArrayLen === i) {
  3372. return i;
  3373. }
  3374. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3375. typeof continueCallback === 'function');
  3376. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3377. var steps = 0;
  3378. var commonObjs = this.commonObjs;
  3379. var objs = this.objs;
  3380. var fnId;
  3381. while (true) {
  3382. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3383. stepper.breakIt(i, continueCallback);
  3384. return i;
  3385. }
  3386. fnId = fnArray[i];
  3387. if (fnId !== OPS.dependency) {
  3388. this[fnId].apply(this, argsArray[i]);
  3389. } else {
  3390. var deps = argsArray[i];
  3391. for (var n = 0, nn = deps.length; n < nn; n++) {
  3392. var depObjId = deps[n];
  3393. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3394. var objsPool = common ? commonObjs : objs;
  3395. // If the promise isn't resolved yet, add the continueCallback
  3396. // to the promise and bail out.
  3397. if (!objsPool.isResolved(depObjId)) {
  3398. objsPool.get(depObjId, continueCallback);
  3399. return i;
  3400. }
  3401. }
  3402. }
  3403. i++;
  3404. // If the entire operatorList was executed, stop as were done.
  3405. if (i === argsArrayLen) {
  3406. return i;
  3407. }
  3408. // If the execution took longer then a certain amount of time and
  3409. // `continueCallback` is specified, interrupt the execution.
  3410. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3411. if (Date.now() > endTime) {
  3412. continueCallback();
  3413. return i;
  3414. }
  3415. steps = 0;
  3416. }
  3417. // If the operatorList isn't executed completely yet OR the execution
  3418. // time was short enough, do another execution round.
  3419. }
  3420. },
  3421. endDrawing: function CanvasGraphics_endDrawing() {
  3422. this.ctx.restore();
  3423. CachedCanvases.clear();
  3424. WebGLUtils.clear();
  3425. if (this.imageLayer) {
  3426. this.imageLayer.endLayout();
  3427. }
  3428. },
  3429. // Graphics state
  3430. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3431. this.current.lineWidth = width;
  3432. this.ctx.lineWidth = width;
  3433. },
  3434. setLineCap: function CanvasGraphics_setLineCap(style) {
  3435. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3436. },
  3437. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3438. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3439. },
  3440. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3441. this.ctx.miterLimit = limit;
  3442. },
  3443. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3444. var ctx = this.ctx;
  3445. if ('setLineDash' in ctx) {
  3446. ctx.setLineDash(dashArray);
  3447. ctx.lineDashOffset = dashPhase;
  3448. } else {
  3449. ctx.mozDash = dashArray;
  3450. ctx.mozDashOffset = dashPhase;
  3451. }
  3452. },
  3453. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3454. // Maybe if we one day fully support color spaces this will be important
  3455. // for now we can ignore.
  3456. // TODO set rendering intent?
  3457. },
  3458. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3459. // There's no way to control this with canvas, but we can safely ignore.
  3460. // TODO set flatness?
  3461. },
  3462. setGState: function CanvasGraphics_setGState(states) {
  3463. for (var i = 0, ii = states.length; i < ii; i++) {
  3464. var state = states[i];
  3465. var key = state[0];
  3466. var value = state[1];
  3467. switch (key) {
  3468. case 'LW':
  3469. this.setLineWidth(value);
  3470. break;
  3471. case 'LC':
  3472. this.setLineCap(value);
  3473. break;
  3474. case 'LJ':
  3475. this.setLineJoin(value);
  3476. break;
  3477. case 'ML':
  3478. this.setMiterLimit(value);
  3479. break;
  3480. case 'D':
  3481. this.setDash(value[0], value[1]);
  3482. break;
  3483. case 'RI':
  3484. this.setRenderingIntent(value);
  3485. break;
  3486. case 'FL':
  3487. this.setFlatness(value);
  3488. break;
  3489. case 'Font':
  3490. this.setFont(value[0], value[1]);
  3491. break;
  3492. case 'CA':
  3493. this.current.strokeAlpha = state[1];
  3494. break;
  3495. case 'ca':
  3496. this.current.fillAlpha = state[1];
  3497. this.ctx.globalAlpha = state[1];
  3498. break;
  3499. case 'BM':
  3500. if (value && value.name && (value.name !== 'Normal')) {
  3501. var mode = value.name.replace(/([A-Z])/g,
  3502. function(c) {
  3503. return '-' + c.toLowerCase();
  3504. }
  3505. ).substring(1);
  3506. this.ctx.globalCompositeOperation = mode;
  3507. if (this.ctx.globalCompositeOperation !== mode) {
  3508. warn('globalCompositeOperation "' + mode +
  3509. '" is not supported');
  3510. }
  3511. } else {
  3512. this.ctx.globalCompositeOperation = 'source-over';
  3513. }
  3514. break;
  3515. case 'SMask':
  3516. if (this.current.activeSMask) {
  3517. this.endSMaskGroup();
  3518. }
  3519. this.current.activeSMask = value ? this.tempSMask : null;
  3520. if (this.current.activeSMask) {
  3521. this.beginSMaskGroup();
  3522. }
  3523. this.tempSMask = null;
  3524. break;
  3525. }
  3526. }
  3527. },
  3528. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3529. var activeSMask = this.current.activeSMask;
  3530. var drawnWidth = activeSMask.canvas.width;
  3531. var drawnHeight = activeSMask.canvas.height;
  3532. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3533. var scratchCanvas = CachedCanvases.getCanvas(
  3534. cacheId, drawnWidth, drawnHeight, true);
  3535. var currentCtx = this.ctx;
  3536. var currentTransform = currentCtx.mozCurrentTransform;
  3537. this.ctx.save();
  3538. var groupCtx = scratchCanvas.context;
  3539. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3540. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3541. groupCtx.transform.apply(groupCtx, currentTransform);
  3542. copyCtxState(currentCtx, groupCtx);
  3543. this.ctx = groupCtx;
  3544. this.setGState([
  3545. ['BM', 'Normal'],
  3546. ['ca', 1],
  3547. ['CA', 1]
  3548. ]);
  3549. this.groupStack.push(currentCtx);
  3550. this.groupLevel++;
  3551. },
  3552. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3553. var groupCtx = this.ctx;
  3554. this.groupLevel--;
  3555. this.ctx = this.groupStack.pop();
  3556. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3557. this.ctx.restore();
  3558. },
  3559. save: function CanvasGraphics_save() {
  3560. this.ctx.save();
  3561. var old = this.current;
  3562. this.stateStack.push(old);
  3563. this.current = old.clone();
  3564. this.current.activeSMask = null;
  3565. },
  3566. restore: function CanvasGraphics_restore() {
  3567. if (this.stateStack.length !== 0) {
  3568. if (this.current.activeSMask !== null) {
  3569. this.endSMaskGroup();
  3570. }
  3571. this.current = this.stateStack.pop();
  3572. this.ctx.restore();
  3573. }
  3574. },
  3575. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3576. this.ctx.transform(a, b, c, d, e, f);
  3577. },
  3578. // Path
  3579. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3580. var ctx = this.ctx;
  3581. var current = this.current;
  3582. var x = current.x, y = current.y;
  3583. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3584. switch (ops[i] | 0) {
  3585. case OPS.rectangle:
  3586. x = args[j++];
  3587. y = args[j++];
  3588. var width = args[j++];
  3589. var height = args[j++];
  3590. if (width === 0) {
  3591. width = this.getSinglePixelWidth();
  3592. }
  3593. if (height === 0) {
  3594. height = this.getSinglePixelWidth();
  3595. }
  3596. var xw = x + width;
  3597. var yh = y + height;
  3598. this.ctx.moveTo(x, y);
  3599. this.ctx.lineTo(xw, y);
  3600. this.ctx.lineTo(xw, yh);
  3601. this.ctx.lineTo(x, yh);
  3602. this.ctx.lineTo(x, y);
  3603. this.ctx.closePath();
  3604. break;
  3605. case OPS.moveTo:
  3606. x = args[j++];
  3607. y = args[j++];
  3608. ctx.moveTo(x, y);
  3609. break;
  3610. case OPS.lineTo:
  3611. x = args[j++];
  3612. y = args[j++];
  3613. ctx.lineTo(x, y);
  3614. break;
  3615. case OPS.curveTo:
  3616. x = args[j + 4];
  3617. y = args[j + 5];
  3618. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3619. x, y);
  3620. j += 6;
  3621. break;
  3622. case OPS.curveTo2:
  3623. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3624. args[j + 2], args[j + 3]);
  3625. x = args[j + 2];
  3626. y = args[j + 3];
  3627. j += 4;
  3628. break;
  3629. case OPS.curveTo3:
  3630. x = args[j + 2];
  3631. y = args[j + 3];
  3632. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3633. j += 4;
  3634. break;
  3635. case OPS.closePath:
  3636. ctx.closePath();
  3637. break;
  3638. }
  3639. }
  3640. current.setCurrentPoint(x, y);
  3641. },
  3642. closePath: function CanvasGraphics_closePath() {
  3643. this.ctx.closePath();
  3644. },
  3645. stroke: function CanvasGraphics_stroke(consumePath) {
  3646. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3647. var ctx = this.ctx;
  3648. var strokeColor = this.current.strokeColor;
  3649. if (this.current.lineWidth === 0) {
  3650. ctx.lineWidth = this.getSinglePixelWidth();
  3651. }
  3652. // For stroke we want to temporarily change the global alpha to the
  3653. // stroking alpha.
  3654. ctx.globalAlpha = this.current.strokeAlpha;
  3655. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3656. strokeColor.type === 'Pattern') {
  3657. // for patterns, we transform to pattern space, calculate
  3658. // the pattern, call stroke, and restore to user space
  3659. ctx.save();
  3660. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3661. ctx.stroke();
  3662. ctx.restore();
  3663. } else {
  3664. ctx.stroke();
  3665. }
  3666. if (consumePath) {
  3667. this.consumePath();
  3668. }
  3669. // Restore the global alpha to the fill alpha
  3670. ctx.globalAlpha = this.current.fillAlpha;
  3671. },
  3672. closeStroke: function CanvasGraphics_closeStroke() {
  3673. this.closePath();
  3674. this.stroke();
  3675. },
  3676. fill: function CanvasGraphics_fill(consumePath) {
  3677. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3678. var ctx = this.ctx;
  3679. var fillColor = this.current.fillColor;
  3680. var needRestore = false;
  3681. if (fillColor && fillColor.hasOwnProperty('type') &&
  3682. fillColor.type === 'Pattern') {
  3683. ctx.save();
  3684. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3685. needRestore = true;
  3686. }
  3687. if (this.pendingEOFill) {
  3688. if (ctx.mozFillRule !== undefined) {
  3689. ctx.mozFillRule = 'evenodd';
  3690. ctx.fill();
  3691. ctx.mozFillRule = 'nonzero';
  3692. } else {
  3693. try {
  3694. ctx.fill('evenodd');
  3695. } catch (ex) {
  3696. // shouldn't really happen, but browsers might think differently
  3697. ctx.fill();
  3698. }
  3699. }
  3700. this.pendingEOFill = false;
  3701. } else {
  3702. ctx.fill();
  3703. }
  3704. if (needRestore) {
  3705. ctx.restore();
  3706. }
  3707. if (consumePath) {
  3708. this.consumePath();
  3709. }
  3710. },
  3711. eoFill: function CanvasGraphics_eoFill() {
  3712. this.pendingEOFill = true;
  3713. this.fill();
  3714. },
  3715. fillStroke: function CanvasGraphics_fillStroke() {
  3716. this.fill(false);
  3717. this.stroke(false);
  3718. this.consumePath();
  3719. },
  3720. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3721. this.pendingEOFill = true;
  3722. this.fillStroke();
  3723. },
  3724. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3725. this.closePath();
  3726. this.fillStroke();
  3727. },
  3728. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3729. this.pendingEOFill = true;
  3730. this.closePath();
  3731. this.fillStroke();
  3732. },
  3733. endPath: function CanvasGraphics_endPath() {
  3734. this.consumePath();
  3735. },
  3736. // Clipping
  3737. clip: function CanvasGraphics_clip() {
  3738. this.pendingClip = NORMAL_CLIP;
  3739. },
  3740. eoClip: function CanvasGraphics_eoClip() {
  3741. this.pendingClip = EO_CLIP;
  3742. },
  3743. // Text
  3744. beginText: function CanvasGraphics_beginText() {
  3745. this.current.textMatrix = IDENTITY_MATRIX;
  3746. this.current.textMatrixScale = 1;
  3747. this.current.x = this.current.lineX = 0;
  3748. this.current.y = this.current.lineY = 0;
  3749. },
  3750. endText: function CanvasGraphics_endText() {
  3751. var paths = this.pendingTextPaths;
  3752. var ctx = this.ctx;
  3753. if (paths === undefined) {
  3754. ctx.beginPath();
  3755. return;
  3756. }
  3757. ctx.save();
  3758. ctx.beginPath();
  3759. for (var i = 0; i < paths.length; i++) {
  3760. var path = paths[i];
  3761. ctx.setTransform.apply(ctx, path.transform);
  3762. ctx.translate(path.x, path.y);
  3763. path.addToPath(ctx, path.fontSize);
  3764. }
  3765. ctx.restore();
  3766. ctx.clip();
  3767. ctx.beginPath();
  3768. delete this.pendingTextPaths;
  3769. },
  3770. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3771. this.current.charSpacing = spacing;
  3772. },
  3773. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3774. this.current.wordSpacing = spacing;
  3775. },
  3776. setHScale: function CanvasGraphics_setHScale(scale) {
  3777. this.current.textHScale = scale / 100;
  3778. },
  3779. setLeading: function CanvasGraphics_setLeading(leading) {
  3780. this.current.leading = -leading;
  3781. },
  3782. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3783. var fontObj = this.commonObjs.get(fontRefName);
  3784. var current = this.current;
  3785. if (!fontObj) {
  3786. error('Can\'t find font for ' + fontRefName);
  3787. }
  3788. current.fontMatrix = (fontObj.fontMatrix ?
  3789. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3790. // A valid matrix needs all main diagonal elements to be non-zero
  3791. // This also ensures we bypass FF bugzilla bug #719844.
  3792. if (current.fontMatrix[0] === 0 ||
  3793. current.fontMatrix[3] === 0) {
  3794. warn('Invalid font matrix for font ' + fontRefName);
  3795. }
  3796. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3797. // and in some docs this can be negative (inverted x-y axes).
  3798. if (size < 0) {
  3799. size = -size;
  3800. current.fontDirection = -1;
  3801. } else {
  3802. current.fontDirection = 1;
  3803. }
  3804. this.current.font = fontObj;
  3805. this.current.fontSize = size;
  3806. if (fontObj.isType3Font) {
  3807. return; // we don't need ctx.font for Type3 fonts
  3808. }
  3809. var name = fontObj.loadedName || 'sans-serif';
  3810. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3811. (fontObj.bold ? 'bold' : 'normal');
  3812. var italic = fontObj.italic ? 'italic' : 'normal';
  3813. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  3814. // Some font backends cannot handle fonts below certain size.
  3815. // Keeping the font at minimal size and using the fontSizeScale to change
  3816. // the current transformation matrix before the fillText/strokeText.
  3817. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  3818. var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
  3819. this.current.fontSizeScale = browserFontSize !== MIN_FONT_SIZE ? 1.0 :
  3820. size / MIN_FONT_SIZE;
  3821. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  3822. this.ctx.font = rule;
  3823. },
  3824. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  3825. this.current.textRenderingMode = mode;
  3826. },
  3827. setTextRise: function CanvasGraphics_setTextRise(rise) {
  3828. this.current.textRise = rise;
  3829. },
  3830. moveText: function CanvasGraphics_moveText(x, y) {
  3831. this.current.x = this.current.lineX += x;
  3832. this.current.y = this.current.lineY += y;
  3833. },
  3834. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  3835. this.setLeading(-y);
  3836. this.moveText(x, y);
  3837. },
  3838. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  3839. this.current.textMatrix = [a, b, c, d, e, f];
  3840. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  3841. this.current.x = this.current.lineX = 0;
  3842. this.current.y = this.current.lineY = 0;
  3843. },
  3844. nextLine: function CanvasGraphics_nextLine() {
  3845. this.moveText(0, this.current.leading);
  3846. },
  3847. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  3848. var ctx = this.ctx;
  3849. var current = this.current;
  3850. var font = current.font;
  3851. var textRenderingMode = current.textRenderingMode;
  3852. var fontSize = current.fontSize / current.fontSizeScale;
  3853. var fillStrokeMode = textRenderingMode &
  3854. TextRenderingMode.FILL_STROKE_MASK;
  3855. var isAddToPathSet = !!(textRenderingMode &
  3856. TextRenderingMode.ADD_TO_PATH_FLAG);
  3857. var addToPath;
  3858. if (font.disableFontFace || isAddToPathSet) {
  3859. addToPath = font.getPathGenerator(this.commonObjs, character);
  3860. }
  3861. if (font.disableFontFace) {
  3862. ctx.save();
  3863. ctx.translate(x, y);
  3864. ctx.beginPath();
  3865. addToPath(ctx, fontSize);
  3866. if (fillStrokeMode === TextRenderingMode.FILL ||
  3867. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3868. ctx.fill();
  3869. }
  3870. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3871. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3872. ctx.stroke();
  3873. }
  3874. ctx.restore();
  3875. } else {
  3876. if (fillStrokeMode === TextRenderingMode.FILL ||
  3877. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3878. ctx.fillText(character, x, y);
  3879. }
  3880. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3881. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3882. ctx.strokeText(character, x, y);
  3883. }
  3884. }
  3885. if (isAddToPathSet) {
  3886. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  3887. paths.push({
  3888. transform: ctx.mozCurrentTransform,
  3889. x: x,
  3890. y: y,
  3891. fontSize: fontSize,
  3892. addToPath: addToPath
  3893. });
  3894. }
  3895. },
  3896. get isFontSubpixelAAEnabled() {
  3897. // Checks if anti-aliasing is enabled when scaled text is painted.
  3898. // On Windows GDI scaled fonts looks bad.
  3899. var ctx = document.createElement('canvas').getContext('2d');
  3900. ctx.scale(1.5, 1);
  3901. ctx.fillText('I', 0, 10);
  3902. var data = ctx.getImageData(0, 0, 10, 10).data;
  3903. var enabled = false;
  3904. for (var i = 3; i < data.length; i += 4) {
  3905. if (data[i] > 0 && data[i] < 255) {
  3906. enabled = true;
  3907. break;
  3908. }
  3909. }
  3910. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  3911. },
  3912. showText: function CanvasGraphics_showText(glyphs) {
  3913. var current = this.current;
  3914. var font = current.font;
  3915. if (font.isType3Font) {
  3916. return this.showType3Text(glyphs);
  3917. }
  3918. var fontSize = current.fontSize;
  3919. if (fontSize === 0) {
  3920. return;
  3921. }
  3922. var ctx = this.ctx;
  3923. var fontSizeScale = current.fontSizeScale;
  3924. var charSpacing = current.charSpacing;
  3925. var wordSpacing = current.wordSpacing;
  3926. var fontDirection = current.fontDirection;
  3927. var textHScale = current.textHScale * fontDirection;
  3928. var glyphsLength = glyphs.length;
  3929. var vertical = font.vertical;
  3930. var defaultVMetrics = font.defaultVMetrics;
  3931. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  3932. var simpleFillText =
  3933. current.textRenderingMode === TextRenderingMode.FILL &&
  3934. !font.disableFontFace;
  3935. ctx.save();
  3936. ctx.transform.apply(ctx, current.textMatrix);
  3937. ctx.translate(current.x, current.y + current.textRise);
  3938. if (fontDirection > 0) {
  3939. ctx.scale(textHScale, -1);
  3940. } else {
  3941. ctx.scale(textHScale, 1);
  3942. }
  3943. var lineWidth = current.lineWidth;
  3944. var scale = current.textMatrixScale;
  3945. if (scale === 0 || lineWidth === 0) {
  3946. lineWidth = this.getSinglePixelWidth();
  3947. } else {
  3948. lineWidth /= scale;
  3949. }
  3950. if (fontSizeScale !== 1.0) {
  3951. ctx.scale(fontSizeScale, fontSizeScale);
  3952. lineWidth /= fontSizeScale;
  3953. }
  3954. ctx.lineWidth = lineWidth;
  3955. var x = 0, i;
  3956. for (i = 0; i < glyphsLength; ++i) {
  3957. var glyph = glyphs[i];
  3958. if (glyph === null) {
  3959. // word break
  3960. x += fontDirection * wordSpacing;
  3961. continue;
  3962. } else if (isNum(glyph)) {
  3963. x += -glyph * fontSize * 0.001;
  3964. continue;
  3965. }
  3966. var restoreNeeded = false;
  3967. var character = glyph.fontChar;
  3968. var accent = glyph.accent;
  3969. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  3970. var width = glyph.width;
  3971. if (vertical) {
  3972. var vmetric, vx, vy;
  3973. vmetric = glyph.vmetric || defaultVMetrics;
  3974. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  3975. vx = -vx * widthAdvanceScale;
  3976. vy = vmetric[2] * widthAdvanceScale;
  3977. width = vmetric ? -vmetric[0] : width;
  3978. scaledX = vx / fontSizeScale;
  3979. scaledY = (x + vy) / fontSizeScale;
  3980. } else {
  3981. scaledX = x / fontSizeScale;
  3982. scaledY = 0;
  3983. }
  3984. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  3985. // some standard fonts may not have the exact width, trying to
  3986. // rescale per character
  3987. var measuredWidth = ctx.measureText(character).width * 1000 /
  3988. fontSize * fontSizeScale;
  3989. var characterScaleX = width / measuredWidth;
  3990. restoreNeeded = true;
  3991. ctx.save();
  3992. ctx.scale(characterScaleX, 1);
  3993. scaledX /= characterScaleX;
  3994. }
  3995. if (simpleFillText && !accent) {
  3996. // common case
  3997. ctx.fillText(character, scaledX, scaledY);
  3998. } else {
  3999. this.paintChar(character, scaledX, scaledY);
  4000. if (accent) {
  4001. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4002. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4003. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4004. }
  4005. }
  4006. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4007. x += charWidth;
  4008. if (restoreNeeded) {
  4009. ctx.restore();
  4010. }
  4011. }
  4012. if (vertical) {
  4013. current.y -= x * textHScale;
  4014. } else {
  4015. current.x += x * textHScale;
  4016. }
  4017. ctx.restore();
  4018. },
  4019. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4020. // Type3 fonts - each glyph is a "mini-PDF"
  4021. var ctx = this.ctx;
  4022. var current = this.current;
  4023. var font = current.font;
  4024. var fontSize = current.fontSize;
  4025. var fontDirection = current.fontDirection;
  4026. var charSpacing = current.charSpacing;
  4027. var wordSpacing = current.wordSpacing;
  4028. var textHScale = current.textHScale * fontDirection;
  4029. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4030. var glyphsLength = glyphs.length;
  4031. var i, glyph, width;
  4032. if (fontSize === 0) {
  4033. return;
  4034. }
  4035. ctx.save();
  4036. ctx.transform.apply(ctx, current.textMatrix);
  4037. ctx.translate(current.x, current.y);
  4038. ctx.scale(textHScale, fontDirection);
  4039. for (i = 0; i < glyphsLength; ++i) {
  4040. glyph = glyphs[i];
  4041. if (glyph === null) {
  4042. // word break
  4043. this.ctx.translate(wordSpacing, 0);
  4044. current.x += wordSpacing * textHScale;
  4045. continue;
  4046. } else if (isNum(glyph)) {
  4047. var spacingLength = -glyph * 0.001 * fontSize;
  4048. this.ctx.translate(spacingLength, 0);
  4049. current.x += spacingLength * textHScale;
  4050. continue;
  4051. }
  4052. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4053. if (!operatorList) {
  4054. warn('Type3 character \"' + glyph.operatorListId +
  4055. '\" is not available');
  4056. continue;
  4057. }
  4058. this.processingType3 = glyph;
  4059. this.save();
  4060. ctx.scale(fontSize, fontSize);
  4061. ctx.transform.apply(ctx, fontMatrix);
  4062. this.executeOperatorList(operatorList);
  4063. this.restore();
  4064. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4065. width = transformed[0] * fontSize + charSpacing;
  4066. ctx.translate(width, 0);
  4067. current.x += width * textHScale;
  4068. }
  4069. ctx.restore();
  4070. this.processingType3 = null;
  4071. },
  4072. // Type3 fonts
  4073. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4074. // We can safely ignore this since the width should be the same
  4075. // as the width in the Widths array.
  4076. },
  4077. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4078. yWidth,
  4079. llx,
  4080. lly,
  4081. urx,
  4082. ury) {
  4083. // TODO According to the spec we're also suppose to ignore any operators
  4084. // that set color or include images while processing this type3 font.
  4085. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4086. this.clip();
  4087. this.endPath();
  4088. },
  4089. // Color
  4090. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4091. var pattern;
  4092. if (IR[0] === 'TilingPattern') {
  4093. var color = IR[1];
  4094. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4095. this.commonObjs, this.baseTransform);
  4096. } else {
  4097. pattern = getShadingPatternFromIR(IR);
  4098. }
  4099. return pattern;
  4100. },
  4101. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4102. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4103. },
  4104. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4105. this.current.fillColor = this.getColorN_Pattern(arguments);
  4106. },
  4107. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4108. var color = Util.makeCssRgb(arguments);
  4109. this.ctx.strokeStyle = color;
  4110. this.current.strokeColor = color;
  4111. },
  4112. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4113. var color = Util.makeCssRgb(arguments);
  4114. this.ctx.fillStyle = color;
  4115. this.current.fillColor = color;
  4116. },
  4117. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4118. var ctx = this.ctx;
  4119. this.save();
  4120. var pattern = getShadingPatternFromIR(patternIR);
  4121. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4122. var inv = ctx.mozCurrentTransformInverse;
  4123. if (inv) {
  4124. var canvas = ctx.canvas;
  4125. var width = canvas.width;
  4126. var height = canvas.height;
  4127. var bl = Util.applyTransform([0, 0], inv);
  4128. var br = Util.applyTransform([0, height], inv);
  4129. var ul = Util.applyTransform([width, 0], inv);
  4130. var ur = Util.applyTransform([width, height], inv);
  4131. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4132. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4133. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4134. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4135. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4136. } else {
  4137. // HACK to draw the gradient onto an infinite rectangle.
  4138. // PDF gradients are drawn across the entire image while
  4139. // Canvas only allows gradients to be drawn in a rectangle
  4140. // The following bug should allow us to remove this.
  4141. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4142. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4143. }
  4144. this.restore();
  4145. },
  4146. // Images
  4147. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4148. error('Should not call beginInlineImage');
  4149. },
  4150. beginImageData: function CanvasGraphics_beginImageData() {
  4151. error('Should not call beginImageData');
  4152. },
  4153. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4154. bbox) {
  4155. this.save();
  4156. this.baseTransformStack.push(this.baseTransform);
  4157. if (isArray(matrix) && 6 === matrix.length) {
  4158. this.transform.apply(this, matrix);
  4159. }
  4160. this.baseTransform = this.ctx.mozCurrentTransform;
  4161. if (isArray(bbox) && 4 === bbox.length) {
  4162. var width = bbox[2] - bbox[0];
  4163. var height = bbox[3] - bbox[1];
  4164. this.ctx.rect(bbox[0], bbox[1], width, height);
  4165. this.clip();
  4166. this.endPath();
  4167. }
  4168. },
  4169. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4170. this.restore();
  4171. this.baseTransform = this.baseTransformStack.pop();
  4172. },
  4173. beginGroup: function CanvasGraphics_beginGroup(group) {
  4174. this.save();
  4175. var currentCtx = this.ctx;
  4176. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4177. // group results aren't usually that different and they even have tools
  4178. // that ignore this setting. Notes from Rik on implmenting:
  4179. // - When you encounter an transparency group, create a new canvas with
  4180. // the dimensions of the bbox
  4181. // - copy the content from the previous canvas to the new canvas
  4182. // - draw as usual
  4183. // - remove the backdrop alpha:
  4184. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4185. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4186. // backdrop
  4187. // - remove background color:
  4188. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4189. if (!group.isolated) {
  4190. info('TODO: Support non-isolated groups.');
  4191. }
  4192. // TODO knockout - supposedly possible with the clever use of compositing
  4193. // modes.
  4194. if (group.knockout) {
  4195. warn('Knockout groups not supported.');
  4196. }
  4197. var currentTransform = currentCtx.mozCurrentTransform;
  4198. if (group.matrix) {
  4199. currentCtx.transform.apply(currentCtx, group.matrix);
  4200. }
  4201. assert(group.bbox, 'Bounding box is required.');
  4202. // Based on the current transform figure out how big the bounding box
  4203. // will actually be.
  4204. var bounds = Util.getAxialAlignedBoundingBox(
  4205. group.bbox,
  4206. currentCtx.mozCurrentTransform);
  4207. // Clip the bounding box to the current canvas.
  4208. var canvasBounds = [0,
  4209. 0,
  4210. currentCtx.canvas.width,
  4211. currentCtx.canvas.height];
  4212. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4213. // Use ceil in case we're between sizes so we don't create canvas that is
  4214. // too small and make the canvas at least 1x1 pixels.
  4215. var offsetX = Math.floor(bounds[0]);
  4216. var offsetY = Math.floor(bounds[1]);
  4217. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4218. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4219. var scaleX = 1, scaleY = 1;
  4220. if (drawnWidth > MAX_GROUP_SIZE) {
  4221. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4222. drawnWidth = MAX_GROUP_SIZE;
  4223. }
  4224. if (drawnHeight > MAX_GROUP_SIZE) {
  4225. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4226. drawnHeight = MAX_GROUP_SIZE;
  4227. }
  4228. var cacheId = 'groupAt' + this.groupLevel;
  4229. if (group.smask) {
  4230. // Using two cache entries is case if masks are used one after another.
  4231. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4232. }
  4233. var scratchCanvas = CachedCanvases.getCanvas(
  4234. cacheId, drawnWidth, drawnHeight, true);
  4235. var groupCtx = scratchCanvas.context;
  4236. // Since we created a new canvas that is just the size of the bounding box
  4237. // we have to translate the group ctx.
  4238. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4239. groupCtx.translate(-offsetX, -offsetY);
  4240. groupCtx.transform.apply(groupCtx, currentTransform);
  4241. if (group.smask) {
  4242. // Saving state and cached mask to be used in setGState.
  4243. this.smaskStack.push({
  4244. canvas: scratchCanvas.canvas,
  4245. context: groupCtx,
  4246. offsetX: offsetX,
  4247. offsetY: offsetY,
  4248. scaleX: scaleX,
  4249. scaleY: scaleY,
  4250. subtype: group.smask.subtype,
  4251. backdrop: group.smask.backdrop
  4252. });
  4253. } else {
  4254. // Setup the current ctx so when the group is popped we draw it at the
  4255. // right location.
  4256. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4257. currentCtx.translate(offsetX, offsetY);
  4258. currentCtx.scale(scaleX, scaleY);
  4259. }
  4260. // The transparency group inherits all off the current graphics state
  4261. // except the blend mode, soft mask, and alpha constants.
  4262. copyCtxState(currentCtx, groupCtx);
  4263. this.ctx = groupCtx;
  4264. this.setGState([
  4265. ['BM', 'Normal'],
  4266. ['ca', 1],
  4267. ['CA', 1]
  4268. ]);
  4269. this.groupStack.push(currentCtx);
  4270. this.groupLevel++;
  4271. },
  4272. endGroup: function CanvasGraphics_endGroup(group) {
  4273. this.groupLevel--;
  4274. var groupCtx = this.ctx;
  4275. this.ctx = this.groupStack.pop();
  4276. // Turn off image smoothing to avoid sub pixel interpolation which can
  4277. // look kind of blurry for some pdfs.
  4278. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4279. this.ctx.imageSmoothingEnabled = false;
  4280. } else {
  4281. this.ctx.mozImageSmoothingEnabled = false;
  4282. }
  4283. if (group.smask) {
  4284. this.tempSMask = this.smaskStack.pop();
  4285. } else {
  4286. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4287. }
  4288. this.restore();
  4289. },
  4290. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4291. this.save();
  4292. this.current = new CanvasExtraState();
  4293. },
  4294. endAnnotations: function CanvasGraphics_endAnnotations() {
  4295. this.restore();
  4296. },
  4297. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4298. matrix) {
  4299. this.save();
  4300. if (isArray(rect) && 4 === rect.length) {
  4301. var width = rect[2] - rect[0];
  4302. var height = rect[3] - rect[1];
  4303. this.ctx.rect(rect[0], rect[1], width, height);
  4304. this.clip();
  4305. this.endPath();
  4306. }
  4307. this.transform.apply(this, transform);
  4308. this.transform.apply(this, matrix);
  4309. },
  4310. endAnnotation: function CanvasGraphics_endAnnotation() {
  4311. this.restore();
  4312. },
  4313. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4314. var domImage = this.objs.get(objId);
  4315. if (!domImage) {
  4316. warn('Dependent image isn\'t ready yet');
  4317. return;
  4318. }
  4319. this.save();
  4320. var ctx = this.ctx;
  4321. // scale the image to the unit square
  4322. ctx.scale(1 / w, -1 / h);
  4323. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4324. 0, -h, w, h);
  4325. if (this.imageLayer) {
  4326. var currentTransform = ctx.mozCurrentTransformInverse;
  4327. var position = this.getCanvasPosition(0, 0);
  4328. this.imageLayer.appendImage({
  4329. objId: objId,
  4330. left: position[0],
  4331. top: position[1],
  4332. width: w / currentTransform[0],
  4333. height: h / currentTransform[3]
  4334. });
  4335. }
  4336. this.restore();
  4337. },
  4338. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4339. var ctx = this.ctx;
  4340. var width = img.width, height = img.height;
  4341. var glyph = this.processingType3;
  4342. if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
  4343. var MAX_SIZE_TO_COMPILE = 1000;
  4344. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4345. glyph.compiled =
  4346. compileType3Glyph({data: img.data, width: width, height: height});
  4347. } else {
  4348. glyph.compiled = null;
  4349. }
  4350. }
  4351. if (glyph && glyph.compiled) {
  4352. glyph.compiled(ctx);
  4353. return;
  4354. }
  4355. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4356. var maskCtx = maskCanvas.context;
  4357. maskCtx.save();
  4358. putBinaryImageMask(maskCtx, img);
  4359. maskCtx.globalCompositeOperation = 'source-in';
  4360. var fillColor = this.current.fillColor;
  4361. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4362. fillColor.type === 'Pattern') ?
  4363. fillColor.getPattern(maskCtx, this) : fillColor;
  4364. maskCtx.fillRect(0, 0, width, height);
  4365. maskCtx.restore();
  4366. this.paintInlineImageXObject(maskCanvas.canvas);
  4367. },
  4368. paintImageMaskXObjectRepeat:
  4369. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4370. scaleY, positions) {
  4371. var width = imgData.width;
  4372. var height = imgData.height;
  4373. var ctx = this.ctx;
  4374. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4375. var maskCtx = maskCanvas.context;
  4376. maskCtx.save();
  4377. putBinaryImageMask(maskCtx, imgData);
  4378. maskCtx.globalCompositeOperation = 'source-in';
  4379. var fillColor = this.current.fillColor;
  4380. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4381. fillColor.type === 'Pattern') ?
  4382. fillColor.getPattern(maskCtx, this) : fillColor;
  4383. maskCtx.fillRect(0, 0, width, height);
  4384. maskCtx.restore();
  4385. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4386. ctx.save();
  4387. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4388. ctx.scale(1, -1);
  4389. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4390. 0, -1, 1, 1);
  4391. ctx.restore();
  4392. }
  4393. },
  4394. paintImageMaskXObjectGroup:
  4395. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4396. var ctx = this.ctx;
  4397. for (var i = 0, ii = images.length; i < ii; i++) {
  4398. var image = images[i];
  4399. var width = image.width, height = image.height;
  4400. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4401. var maskCtx = maskCanvas.context;
  4402. maskCtx.save();
  4403. putBinaryImageMask(maskCtx, image);
  4404. maskCtx.globalCompositeOperation = 'source-in';
  4405. var fillColor = this.current.fillColor;
  4406. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4407. fillColor.type === 'Pattern') ?
  4408. fillColor.getPattern(maskCtx, this) : fillColor;
  4409. maskCtx.fillRect(0, 0, width, height);
  4410. maskCtx.restore();
  4411. ctx.save();
  4412. ctx.transform.apply(ctx, image.transform);
  4413. ctx.scale(1, -1);
  4414. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4415. 0, -1, 1, 1);
  4416. ctx.restore();
  4417. }
  4418. },
  4419. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4420. var imgData = this.objs.get(objId);
  4421. if (!imgData) {
  4422. warn('Dependent image isn\'t ready yet');
  4423. return;
  4424. }
  4425. this.paintInlineImageXObject(imgData);
  4426. },
  4427. paintImageXObjectRepeat:
  4428. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4429. positions) {
  4430. var imgData = this.objs.get(objId);
  4431. if (!imgData) {
  4432. warn('Dependent image isn\'t ready yet');
  4433. return;
  4434. }
  4435. var width = imgData.width;
  4436. var height = imgData.height;
  4437. var map = [];
  4438. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4439. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4440. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4441. }
  4442. this.paintInlineImageXObjectGroup(imgData, map);
  4443. },
  4444. paintInlineImageXObject:
  4445. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4446. var width = imgData.width;
  4447. var height = imgData.height;
  4448. var ctx = this.ctx;
  4449. this.save();
  4450. // scale the image to the unit square
  4451. ctx.scale(1 / width, -1 / height);
  4452. var currentTransform = ctx.mozCurrentTransformInverse;
  4453. var a = currentTransform[0], b = currentTransform[1];
  4454. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4455. var c = currentTransform[2], d = currentTransform[3];
  4456. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4457. var imgToPaint, tmpCanvas;
  4458. // instanceof HTMLElement does not work in jsdom node.js module
  4459. if (imgData instanceof HTMLElement || !imgData.data) {
  4460. imgToPaint = imgData;
  4461. } else {
  4462. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4463. var tmpCtx = tmpCanvas.context;
  4464. putBinaryImageData(tmpCtx, imgData);
  4465. imgToPaint = tmpCanvas.canvas;
  4466. }
  4467. var paintWidth = width, paintHeight = height;
  4468. var tmpCanvasId = 'prescale1';
  4469. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4470. // pixels during drawImage operation, painting on the temporary canvas(es)
  4471. // that are twice smaller in size
  4472. while ((widthScale > 2 && paintWidth > 1) ||
  4473. (heightScale > 2 && paintHeight > 1)) {
  4474. var newWidth = paintWidth, newHeight = paintHeight;
  4475. if (widthScale > 2 && paintWidth > 1) {
  4476. newWidth = Math.ceil(paintWidth / 2);
  4477. widthScale /= paintWidth / newWidth;
  4478. }
  4479. if (heightScale > 2 && paintHeight > 1) {
  4480. newHeight = Math.ceil(paintHeight / 2);
  4481. heightScale /= paintHeight / newHeight;
  4482. }
  4483. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4484. tmpCtx = tmpCanvas.context;
  4485. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4486. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4487. 0, 0, newWidth, newHeight);
  4488. imgToPaint = tmpCanvas.canvas;
  4489. paintWidth = newWidth;
  4490. paintHeight = newHeight;
  4491. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4492. }
  4493. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4494. 0, -height, width, height);
  4495. if (this.imageLayer) {
  4496. var position = this.getCanvasPosition(0, -height);
  4497. this.imageLayer.appendImage({
  4498. imgData: imgData,
  4499. left: position[0],
  4500. top: position[1],
  4501. width: width / currentTransform[0],
  4502. height: height / currentTransform[3]
  4503. });
  4504. }
  4505. this.restore();
  4506. },
  4507. paintInlineImageXObjectGroup:
  4508. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4509. var ctx = this.ctx;
  4510. var w = imgData.width;
  4511. var h = imgData.height;
  4512. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4513. var tmpCtx = tmpCanvas.context;
  4514. putBinaryImageData(tmpCtx, imgData);
  4515. for (var i = 0, ii = map.length; i < ii; i++) {
  4516. var entry = map[i];
  4517. ctx.save();
  4518. ctx.transform.apply(ctx, entry.transform);
  4519. ctx.scale(1, -1);
  4520. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4521. 0, -1, 1, 1);
  4522. if (this.imageLayer) {
  4523. var position = this.getCanvasPosition(entry.x, entry.y);
  4524. this.imageLayer.appendImage({
  4525. imgData: imgData,
  4526. left: position[0],
  4527. top: position[1],
  4528. width: w,
  4529. height: h
  4530. });
  4531. }
  4532. ctx.restore();
  4533. }
  4534. },
  4535. paintSolidColorImageMask:
  4536. function CanvasGraphics_paintSolidColorImageMask() {
  4537. this.ctx.fillRect(0, 0, 1, 1);
  4538. },
  4539. // Marked content
  4540. markPoint: function CanvasGraphics_markPoint(tag) {
  4541. // TODO Marked content.
  4542. },
  4543. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4544. // TODO Marked content.
  4545. },
  4546. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4547. // TODO Marked content.
  4548. },
  4549. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4550. tag, properties) {
  4551. // TODO Marked content.
  4552. },
  4553. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4554. // TODO Marked content.
  4555. },
  4556. // Compatibility
  4557. beginCompat: function CanvasGraphics_beginCompat() {
  4558. // TODO ignore undefined operators (should we do that anyway?)
  4559. },
  4560. endCompat: function CanvasGraphics_endCompat() {
  4561. // TODO stop ignoring undefined operators
  4562. },
  4563. // Helper functions
  4564. consumePath: function CanvasGraphics_consumePath() {
  4565. var ctx = this.ctx;
  4566. if (this.pendingClip) {
  4567. if (this.pendingClip === EO_CLIP) {
  4568. if (ctx.mozFillRule !== undefined) {
  4569. ctx.mozFillRule = 'evenodd';
  4570. ctx.clip();
  4571. ctx.mozFillRule = 'nonzero';
  4572. } else {
  4573. try {
  4574. ctx.clip('evenodd');
  4575. } catch (ex) {
  4576. // shouldn't really happen, but browsers might think differently
  4577. ctx.clip();
  4578. }
  4579. }
  4580. } else {
  4581. ctx.clip();
  4582. }
  4583. this.pendingClip = null;
  4584. }
  4585. ctx.beginPath();
  4586. },
  4587. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4588. var inverse = this.ctx.mozCurrentTransformInverse;
  4589. // max of the current horizontal and vertical scale
  4590. return Math.sqrt(Math.max(
  4591. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4592. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4593. },
  4594. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4595. var transform = this.ctx.mozCurrentTransform;
  4596. return [
  4597. transform[0] * x + transform[2] * y + transform[4],
  4598. transform[1] * x + transform[3] * y + transform[5]
  4599. ];
  4600. }
  4601. };
  4602. for (var op in OPS) {
  4603. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4604. }
  4605. return CanvasGraphics;
  4606. })();
  4607. var WebGLUtils = (function WebGLUtilsClosure() {
  4608. function loadShader(gl, code, shaderType) {
  4609. var shader = gl.createShader(shaderType);
  4610. gl.shaderSource(shader, code);
  4611. gl.compileShader(shader);
  4612. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4613. if (!compiled) {
  4614. var errorMsg = gl.getShaderInfoLog(shader);
  4615. throw new Error('Error during shader compilation: ' + errorMsg);
  4616. }
  4617. return shader;
  4618. }
  4619. function createVertexShader(gl, code) {
  4620. return loadShader(gl, code, gl.VERTEX_SHADER);
  4621. }
  4622. function createFragmentShader(gl, code) {
  4623. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4624. }
  4625. function createProgram(gl, shaders) {
  4626. var program = gl.createProgram();
  4627. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4628. gl.attachShader(program, shaders[i]);
  4629. }
  4630. gl.linkProgram(program);
  4631. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4632. if (!linked) {
  4633. var errorMsg = gl.getProgramInfoLog(program);
  4634. throw new Error('Error during program linking: ' + errorMsg);
  4635. }
  4636. return program;
  4637. }
  4638. function createTexture(gl, image, textureId) {
  4639. gl.activeTexture(textureId);
  4640. var texture = gl.createTexture();
  4641. gl.bindTexture(gl.TEXTURE_2D, texture);
  4642. // Set the parameters so we can render any size image.
  4643. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4644. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4645. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4646. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4647. // Upload the image into the texture.
  4648. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4649. return texture;
  4650. }
  4651. var currentGL, currentCanvas;
  4652. function generageGL() {
  4653. if (currentGL) {
  4654. return;
  4655. }
  4656. currentCanvas = document.createElement('canvas');
  4657. currentGL = currentCanvas.getContext('webgl',
  4658. { premultipliedalpha: false });
  4659. }
  4660. var smaskVertexShaderCode = '\
  4661. attribute vec2 a_position; \
  4662. attribute vec2 a_texCoord; \
  4663. \
  4664. uniform vec2 u_resolution; \
  4665. \
  4666. varying vec2 v_texCoord; \
  4667. \
  4668. void main() { \
  4669. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4670. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4671. \
  4672. v_texCoord = a_texCoord; \
  4673. } ';
  4674. var smaskFragmentShaderCode = '\
  4675. precision mediump float; \
  4676. \
  4677. uniform vec4 u_backdrop; \
  4678. uniform int u_subtype; \
  4679. uniform sampler2D u_image; \
  4680. uniform sampler2D u_mask; \
  4681. \
  4682. varying vec2 v_texCoord; \
  4683. \
  4684. void main() { \
  4685. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4686. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4687. if (u_backdrop.a > 0.0) { \
  4688. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4689. u_backdrop.rgb * (1.0 - maskColor.a); \
  4690. } \
  4691. float lum; \
  4692. if (u_subtype == 0) { \
  4693. lum = maskColor.a; \
  4694. } else { \
  4695. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4696. maskColor.b * 0.11; \
  4697. } \
  4698. imageColor.a *= lum; \
  4699. imageColor.rgb *= imageColor.a; \
  4700. gl_FragColor = imageColor; \
  4701. } ';
  4702. var smaskCache = null;
  4703. function initSmaskGL() {
  4704. var canvas, gl;
  4705. generageGL();
  4706. canvas = currentCanvas;
  4707. currentCanvas = null;
  4708. gl = currentGL;
  4709. currentGL = null;
  4710. // setup a GLSL program
  4711. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4712. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4713. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4714. gl.useProgram(program);
  4715. var cache = {};
  4716. cache.gl = gl;
  4717. cache.canvas = canvas;
  4718. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4719. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4720. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4721. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4722. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4723. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4724. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4725. // provide texture coordinates for the rectangle.
  4726. var texCoordBuffer = gl.createBuffer();
  4727. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4728. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4729. 0.0, 0.0,
  4730. 1.0, 0.0,
  4731. 0.0, 1.0,
  4732. 0.0, 1.0,
  4733. 1.0, 0.0,
  4734. 1.0, 1.0]), gl.STATIC_DRAW);
  4735. gl.enableVertexAttribArray(texCoordLocation);
  4736. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4737. gl.uniform1i(texLayerLocation, 0);
  4738. gl.uniform1i(texMaskLocation, 1);
  4739. smaskCache = cache;
  4740. }
  4741. function composeSMask(layer, mask, properties) {
  4742. var width = layer.width, height = layer.height;
  4743. if (!smaskCache) {
  4744. initSmaskGL();
  4745. }
  4746. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4747. canvas.width = width;
  4748. canvas.height = height;
  4749. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4750. gl.uniform2f(cache.resolutionLocation, width, height);
  4751. if (properties.backdrop) {
  4752. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4753. properties.backdrop[1], properties.backdrop[2], 1);
  4754. } else {
  4755. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4756. }
  4757. gl.uniform1i(cache.subtypeLocation,
  4758. properties.subtype === 'Luminosity' ? 1 : 0);
  4759. // Create a textures
  4760. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4761. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4762. // Create a buffer and put a single clipspace rectangle in
  4763. // it (2 triangles)
  4764. var buffer = gl.createBuffer();
  4765. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4766. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4767. 0, 0,
  4768. width, 0,
  4769. 0, height,
  4770. 0, height,
  4771. width, 0,
  4772. width, height]), gl.STATIC_DRAW);
  4773. gl.enableVertexAttribArray(cache.positionLocation);
  4774. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4775. // draw
  4776. gl.clearColor(0, 0, 0, 0);
  4777. gl.enable(gl.BLEND);
  4778. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4779. gl.clear(gl.COLOR_BUFFER_BIT);
  4780. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4781. gl.flush();
  4782. gl.deleteTexture(texture);
  4783. gl.deleteTexture(maskTexture);
  4784. gl.deleteBuffer(buffer);
  4785. return canvas;
  4786. }
  4787. var figuresVertexShaderCode = '\
  4788. attribute vec2 a_position; \
  4789. attribute vec3 a_color; \
  4790. \
  4791. uniform vec2 u_resolution; \
  4792. uniform vec2 u_scale; \
  4793. uniform vec2 u_offset; \
  4794. \
  4795. varying vec4 v_color; \
  4796. \
  4797. void main() { \
  4798. vec2 position = (a_position + u_offset) * u_scale; \
  4799. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4800. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4801. \
  4802. v_color = vec4(a_color / 255.0, 1.0); \
  4803. } ';
  4804. var figuresFragmentShaderCode = '\
  4805. precision mediump float; \
  4806. \
  4807. varying vec4 v_color; \
  4808. \
  4809. void main() { \
  4810. gl_FragColor = v_color; \
  4811. } ';
  4812. var figuresCache = null;
  4813. function initFiguresGL() {
  4814. var canvas, gl;
  4815. generageGL();
  4816. canvas = currentCanvas;
  4817. currentCanvas = null;
  4818. gl = currentGL;
  4819. currentGL = null;
  4820. // setup a GLSL program
  4821. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  4822. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  4823. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4824. gl.useProgram(program);
  4825. var cache = {};
  4826. cache.gl = gl;
  4827. cache.canvas = canvas;
  4828. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4829. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  4830. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  4831. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4832. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  4833. figuresCache = cache;
  4834. }
  4835. function drawFigures(width, height, backgroundColor, figures, context) {
  4836. if (!figuresCache) {
  4837. initFiguresGL();
  4838. }
  4839. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  4840. canvas.width = width;
  4841. canvas.height = height;
  4842. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4843. gl.uniform2f(cache.resolutionLocation, width, height);
  4844. // count triangle points
  4845. var count = 0;
  4846. var i, ii, rows;
  4847. for (i = 0, ii = figures.length; i < ii; i++) {
  4848. switch (figures[i].type) {
  4849. case 'lattice':
  4850. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  4851. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  4852. break;
  4853. case 'triangles':
  4854. count += figures[i].coords.length;
  4855. break;
  4856. }
  4857. }
  4858. // transfer data
  4859. var coords = new Float32Array(count * 2);
  4860. var colors = new Uint8Array(count * 3);
  4861. var coordsMap = context.coords, colorsMap = context.colors;
  4862. var pIndex = 0, cIndex = 0;
  4863. for (i = 0, ii = figures.length; i < ii; i++) {
  4864. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  4865. switch (figure.type) {
  4866. case 'lattice':
  4867. var cols = figure.verticesPerRow;
  4868. rows = (ps.length / cols) | 0;
  4869. for (var row = 1; row < rows; row++) {
  4870. var offset = row * cols + 1;
  4871. for (var col = 1; col < cols; col++, offset++) {
  4872. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  4873. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  4874. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  4875. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  4876. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  4877. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  4878. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  4879. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  4880. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  4881. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  4882. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  4883. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  4884. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  4885. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  4886. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  4887. coords[pIndex + 6] = coords[pIndex + 2];
  4888. coords[pIndex + 7] = coords[pIndex + 3];
  4889. coords[pIndex + 8] = coords[pIndex + 4];
  4890. coords[pIndex + 9] = coords[pIndex + 5];
  4891. coords[pIndex + 10] = coordsMap[ps[offset]];
  4892. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  4893. colors[cIndex + 9] = colors[cIndex + 3];
  4894. colors[cIndex + 10] = colors[cIndex + 4];
  4895. colors[cIndex + 11] = colors[cIndex + 5];
  4896. colors[cIndex + 12] = colors[cIndex + 6];
  4897. colors[cIndex + 13] = colors[cIndex + 7];
  4898. colors[cIndex + 14] = colors[cIndex + 8];
  4899. colors[cIndex + 15] = colorsMap[cs[offset]];
  4900. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  4901. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  4902. pIndex += 12;
  4903. cIndex += 18;
  4904. }
  4905. }
  4906. break;
  4907. case 'triangles':
  4908. for (var j = 0, jj = ps.length; j < jj; j++) {
  4909. coords[pIndex] = coordsMap[ps[j]];
  4910. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  4911. colors[cIndex] = colorsMap[cs[i]];
  4912. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  4913. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  4914. pIndex += 2;
  4915. cIndex += 3;
  4916. }
  4917. break;
  4918. }
  4919. }
  4920. // draw
  4921. if (backgroundColor) {
  4922. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  4923. backgroundColor[2] / 255, 1.0);
  4924. } else {
  4925. gl.clearColor(0, 0, 0, 0);
  4926. }
  4927. gl.clear(gl.COLOR_BUFFER_BIT);
  4928. var coordsBuffer = gl.createBuffer();
  4929. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  4930. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  4931. gl.enableVertexAttribArray(cache.positionLocation);
  4932. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4933. var colorsBuffer = gl.createBuffer();
  4934. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  4935. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  4936. gl.enableVertexAttribArray(cache.colorLocation);
  4937. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  4938. 0, 0);
  4939. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  4940. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  4941. gl.drawArrays(gl.TRIANGLES, 0, count);
  4942. gl.flush();
  4943. gl.deleteBuffer(coordsBuffer);
  4944. gl.deleteBuffer(colorsBuffer);
  4945. return canvas;
  4946. }
  4947. function cleanup() {
  4948. if (smaskCache && smaskCache.canvas) {
  4949. smaskCache.canvas.width = 0;
  4950. smaskCache.canvas.height = 0;
  4951. }
  4952. if (figuresCache && figuresCache.canvas) {
  4953. figuresCache.canvas.width = 0;
  4954. figuresCache.canvas.height = 0;
  4955. }
  4956. smaskCache = null;
  4957. figuresCache = null;
  4958. }
  4959. return {
  4960. get isEnabled() {
  4961. if (PDFJS.disableWebGL) {
  4962. return false;
  4963. }
  4964. var enabled = false;
  4965. try {
  4966. generageGL();
  4967. enabled = !!currentGL;
  4968. } catch (e) { }
  4969. return shadow(this, 'isEnabled', enabled);
  4970. },
  4971. composeSMask: composeSMask,
  4972. drawFigures: drawFigures,
  4973. clear: cleanup
  4974. };
  4975. })();
  4976. var ShadingIRs = {};
  4977. ShadingIRs.RadialAxial = {
  4978. fromIR: function RadialAxial_fromIR(raw) {
  4979. var type = raw[1];
  4980. var colorStops = raw[2];
  4981. var p0 = raw[3];
  4982. var p1 = raw[4];
  4983. var r0 = raw[5];
  4984. var r1 = raw[6];
  4985. return {
  4986. type: 'Pattern',
  4987. getPattern: function RadialAxial_getPattern(ctx) {
  4988. var grad;
  4989. if (type === 'axial') {
  4990. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  4991. } else if (type === 'radial') {
  4992. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  4993. }
  4994. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  4995. var c = colorStops[i];
  4996. grad.addColorStop(c[0], c[1]);
  4997. }
  4998. return grad;
  4999. }
  5000. };
  5001. }
  5002. };
  5003. var createMeshCanvas = (function createMeshCanvasClosure() {
  5004. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5005. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5006. var coords = context.coords, colors = context.colors;
  5007. var bytes = data.data, rowSize = data.width * 4;
  5008. var tmp;
  5009. if (coords[p1 + 1] > coords[p2 + 1]) {
  5010. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5011. }
  5012. if (coords[p2 + 1] > coords[p3 + 1]) {
  5013. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5014. }
  5015. if (coords[p1 + 1] > coords[p2 + 1]) {
  5016. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5017. }
  5018. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5019. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5020. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5021. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5022. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5023. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5024. if (y1 >= y3) {
  5025. return;
  5026. }
  5027. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5028. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5029. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5030. var minY = Math.round(y1), maxY = Math.round(y3);
  5031. var xa, car, cag, cab;
  5032. var xb, cbr, cbg, cbb;
  5033. var k;
  5034. for (var y = minY; y <= maxY; y++) {
  5035. if (y < y2) {
  5036. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5037. xa = x1 - (x1 - x2) * k;
  5038. car = c1r - (c1r - c2r) * k;
  5039. cag = c1g - (c1g - c2g) * k;
  5040. cab = c1b - (c1b - c2b) * k;
  5041. } else {
  5042. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5043. xa = x2 - (x2 - x3) * k;
  5044. car = c2r - (c2r - c3r) * k;
  5045. cag = c2g - (c2g - c3g) * k;
  5046. cab = c2b - (c2b - c3b) * k;
  5047. }
  5048. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5049. xb = x1 - (x1 - x3) * k;
  5050. cbr = c1r - (c1r - c3r) * k;
  5051. cbg = c1g - (c1g - c3g) * k;
  5052. cbb = c1b - (c1b - c3b) * k;
  5053. var x1_ = Math.round(Math.min(xa, xb));
  5054. var x2_ = Math.round(Math.max(xa, xb));
  5055. var j = rowSize * y + x1_ * 4;
  5056. for (var x = x1_; x <= x2_; x++) {
  5057. k = (xa - x) / (xa - xb);
  5058. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5059. bytes[j++] = (car - (car - cbr) * k) | 0;
  5060. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5061. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5062. bytes[j++] = 255;
  5063. }
  5064. }
  5065. }
  5066. function drawFigure(data, figure, context) {
  5067. var ps = figure.coords;
  5068. var cs = figure.colors;
  5069. var i, ii;
  5070. switch (figure.type) {
  5071. case 'lattice':
  5072. var verticesPerRow = figure.verticesPerRow;
  5073. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5074. var cols = verticesPerRow - 1;
  5075. for (i = 0; i < rows; i++) {
  5076. var q = i * verticesPerRow;
  5077. for (var j = 0; j < cols; j++, q++) {
  5078. drawTriangle(data, context,
  5079. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5080. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5081. drawTriangle(data, context,
  5082. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5083. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5084. }
  5085. }
  5086. break;
  5087. case 'triangles':
  5088. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5089. drawTriangle(data, context,
  5090. ps[i], ps[i + 1], ps[i + 2],
  5091. cs[i], cs[i + 1], cs[i + 2]);
  5092. }
  5093. break;
  5094. default:
  5095. error('illigal figure');
  5096. break;
  5097. }
  5098. }
  5099. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5100. backgroundColor) {
  5101. // we will increase scale on some weird factor to let antialiasing take
  5102. // care of "rough" edges
  5103. var EXPECTED_SCALE = 1.1;
  5104. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5105. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5106. var offsetX = Math.floor(bounds[0]);
  5107. var offsetY = Math.floor(bounds[1]);
  5108. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5109. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5110. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5111. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5112. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5113. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5114. var scaleX = boundsWidth / width;
  5115. var scaleY = boundsHeight / height;
  5116. var context = {
  5117. coords: coords,
  5118. colors: colors,
  5119. offsetX: -offsetX,
  5120. offsetY: -offsetY,
  5121. scaleX: 1 / scaleX,
  5122. scaleY: 1 / scaleY
  5123. };
  5124. var canvas, tmpCanvas, i, ii;
  5125. if (WebGLUtils.isEnabled) {
  5126. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5127. figures, context);
  5128. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5129. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5130. tmpCanvas.context.drawImage(canvas, 0, 0);
  5131. canvas = tmpCanvas.canvas;
  5132. } else {
  5133. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5134. var tmpCtx = tmpCanvas.context;
  5135. var data = tmpCtx.createImageData(width, height);
  5136. if (backgroundColor) {
  5137. var bytes = data.data;
  5138. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5139. bytes[i] = backgroundColor[0];
  5140. bytes[i + 1] = backgroundColor[1];
  5141. bytes[i + 2] = backgroundColor[2];
  5142. bytes[i + 3] = 255;
  5143. }
  5144. }
  5145. for (i = 0; i < figures.length; i++) {
  5146. drawFigure(data, figures[i], context);
  5147. }
  5148. tmpCtx.putImageData(data, 0, 0);
  5149. canvas = tmpCanvas.canvas;
  5150. }
  5151. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5152. scaleX: scaleX, scaleY: scaleY};
  5153. }
  5154. return createMeshCanvas;
  5155. })();
  5156. ShadingIRs.Mesh = {
  5157. fromIR: function Mesh_fromIR(raw) {
  5158. //var type = raw[1];
  5159. var coords = raw[2];
  5160. var colors = raw[3];
  5161. var figures = raw[4];
  5162. var bounds = raw[5];
  5163. var matrix = raw[6];
  5164. //var bbox = raw[7];
  5165. var background = raw[8];
  5166. return {
  5167. type: 'Pattern',
  5168. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5169. var scale;
  5170. if (shadingFill) {
  5171. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5172. } else {
  5173. // Obtain scale from matrix and current transformation matrix.
  5174. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5175. if (matrix) {
  5176. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5177. scale = [scale[0] * matrixScale[0],
  5178. scale[1] * matrixScale[1]];
  5179. }
  5180. }
  5181. // Rasterizing on the main thread since sending/queue large canvases
  5182. // might cause OOM.
  5183. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5184. colors, figures, shadingFill ? null : background);
  5185. if (!shadingFill) {
  5186. ctx.setTransform.apply(ctx, owner.baseTransform);
  5187. if (matrix) {
  5188. ctx.transform.apply(ctx, matrix);
  5189. }
  5190. }
  5191. ctx.translate(temporaryPatternCanvas.offsetX,
  5192. temporaryPatternCanvas.offsetY);
  5193. ctx.scale(temporaryPatternCanvas.scaleX,
  5194. temporaryPatternCanvas.scaleY);
  5195. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5196. }
  5197. };
  5198. }
  5199. };
  5200. ShadingIRs.Dummy = {
  5201. fromIR: function Dummy_fromIR() {
  5202. return {
  5203. type: 'Pattern',
  5204. getPattern: function Dummy_fromIR_getPattern() {
  5205. return 'hotpink';
  5206. }
  5207. };
  5208. }
  5209. };
  5210. function getShadingPatternFromIR(raw) {
  5211. var shadingIR = ShadingIRs[raw[0]];
  5212. if (!shadingIR) {
  5213. error('Unknown IR type: ' + raw[0]);
  5214. }
  5215. return shadingIR.fromIR(raw);
  5216. }
  5217. var TilingPattern = (function TilingPatternClosure() {
  5218. var PaintType = {
  5219. COLORED: 1,
  5220. UNCOLORED: 2
  5221. };
  5222. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5223. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5224. this.operatorList = IR[2];
  5225. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5226. this.bbox = IR[4];
  5227. this.xstep = IR[5];
  5228. this.ystep = IR[6];
  5229. this.paintType = IR[7];
  5230. this.tilingType = IR[8];
  5231. this.color = color;
  5232. this.objs = objs;
  5233. this.commonObjs = commonObjs;
  5234. this.baseTransform = baseTransform;
  5235. this.type = 'Pattern';
  5236. this.ctx = ctx;
  5237. }
  5238. TilingPattern.prototype = {
  5239. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5240. var operatorList = this.operatorList;
  5241. var bbox = this.bbox;
  5242. var xstep = this.xstep;
  5243. var ystep = this.ystep;
  5244. var paintType = this.paintType;
  5245. var tilingType = this.tilingType;
  5246. var color = this.color;
  5247. var objs = this.objs;
  5248. var commonObjs = this.commonObjs;
  5249. info('TilingType: ' + tilingType);
  5250. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5251. var topLeft = [x0, y0];
  5252. // we want the canvas to be as large as the step size
  5253. var botRight = [x0 + xstep, y0 + ystep];
  5254. var width = botRight[0] - topLeft[0];
  5255. var height = botRight[1] - topLeft[1];
  5256. // Obtain scale from matrix and current transformation matrix.
  5257. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5258. var curMatrixScale = Util.singularValueDecompose2dScale(
  5259. this.baseTransform);
  5260. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5261. matrixScale[1] * curMatrixScale[1]];
  5262. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5263. // Use width and height values that are as close as possible to the end
  5264. // result when the pattern is used. Too low value makes the pattern look
  5265. // blurry. Too large value makes it look too crispy.
  5266. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5267. MAX_PATTERN_SIZE);
  5268. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5269. MAX_PATTERN_SIZE);
  5270. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5271. var tmpCtx = tmpCanvas.context;
  5272. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5273. graphics.groupLevel = owner.groupLevel;
  5274. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5275. this.setScale(width, height, xstep, ystep);
  5276. this.transformToScale(graphics);
  5277. // transform coordinates to pattern space
  5278. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5279. graphics.transform.apply(graphics, tmpTranslate);
  5280. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5281. graphics.executeOperatorList(operatorList);
  5282. return tmpCanvas.canvas;
  5283. },
  5284. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5285. this.scale = [width / xstep, height / ystep];
  5286. },
  5287. transformToScale: function TilingPattern_transformToScale(graphics) {
  5288. var scale = this.scale;
  5289. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5290. graphics.transform.apply(graphics, tmpScale);
  5291. },
  5292. scaleToContext: function TilingPattern_scaleToContext() {
  5293. var scale = this.scale;
  5294. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5295. },
  5296. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5297. if (bbox && isArray(bbox) && bbox.length === 4) {
  5298. var bboxWidth = x1 - x0;
  5299. var bboxHeight = y1 - y0;
  5300. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5301. graphics.clip();
  5302. graphics.endPath();
  5303. }
  5304. },
  5305. setFillAndStrokeStyleToContext:
  5306. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5307. switch (paintType) {
  5308. case PaintType.COLORED:
  5309. var ctx = this.ctx;
  5310. context.fillStyle = ctx.fillStyle;
  5311. context.strokeStyle = ctx.strokeStyle;
  5312. break;
  5313. case PaintType.UNCOLORED:
  5314. var cssColor = Util.makeCssRgb(color);
  5315. context.fillStyle = cssColor;
  5316. context.strokeStyle = cssColor;
  5317. break;
  5318. default:
  5319. error('Unsupported paint type: ' + paintType);
  5320. }
  5321. },
  5322. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5323. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5324. ctx = this.ctx;
  5325. ctx.setTransform.apply(ctx, this.baseTransform);
  5326. ctx.transform.apply(ctx, this.matrix);
  5327. this.scaleToContext();
  5328. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5329. }
  5330. };
  5331. return TilingPattern;
  5332. })();
  5333. PDFJS.disableFontFace = false;
  5334. var FontLoader = {
  5335. insertRule: function fontLoaderInsertRule(rule) {
  5336. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5337. if (!styleElement) {
  5338. styleElement = document.createElement('style');
  5339. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5340. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5341. styleElement);
  5342. }
  5343. var styleSheet = styleElement.sheet;
  5344. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5345. },
  5346. clear: function fontLoaderClear() {
  5347. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5348. if (styleElement) {
  5349. styleElement.parentNode.removeChild(styleElement);
  5350. }
  5351. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5352. document.fonts.delete(nativeFontFace);
  5353. });
  5354. this.nativeFontFaces.length = 0;
  5355. },
  5356. get loadTestFont() {
  5357. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5358. // height.
  5359. return shadow(this, 'loadTestFont', atob(
  5360. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5361. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5362. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5363. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5364. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5365. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5366. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5367. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5368. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5369. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5370. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5371. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5372. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5373. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5374. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5375. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5376. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5377. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5378. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5379. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5380. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5381. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5382. ));
  5383. },
  5384. loadTestFontId: 0,
  5385. loadingContext: {
  5386. requests: [],
  5387. nextRequestId: 0
  5388. },
  5389. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5390. if (isWorker) {
  5391. return false;
  5392. }
  5393. // User agent string sniffing is bad, but there is no reliable way to tell
  5394. // if font is fully loaded and ready to be used with canvas.
  5395. var userAgent = window.navigator.userAgent;
  5396. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5397. if (m && m[1] >= 14) {
  5398. return true;
  5399. }
  5400. // TODO other browsers
  5401. if (userAgent === 'node') {
  5402. return true;
  5403. }
  5404. return false;
  5405. })(),
  5406. nativeFontFaces: [],
  5407. isFontLoadingAPISupported: !isWorker && !!document.fonts,
  5408. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5409. this.nativeFontFaces.push(nativeFontFace);
  5410. document.fonts.add(nativeFontFace);
  5411. },
  5412. bind: function fontLoaderBind(fonts, callback) {
  5413. assert(!isWorker, 'bind() shall be called from main thread');
  5414. var rules = [];
  5415. var fontsToLoad = [];
  5416. var fontLoadPromises = [];
  5417. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5418. var font = fonts[i];
  5419. // Add the font to the DOM only once or skip if the font
  5420. // is already loaded.
  5421. if (font.attached || font.loading === false) {
  5422. continue;
  5423. }
  5424. font.attached = true;
  5425. if (this.isFontLoadingAPISupported) {
  5426. var nativeFontFace = font.createNativeFontFace();
  5427. if (nativeFontFace) {
  5428. fontLoadPromises.push(nativeFontFace.loaded);
  5429. }
  5430. } else {
  5431. var rule = font.bindDOM();
  5432. if (rule) {
  5433. rules.push(rule);
  5434. fontsToLoad.push(font);
  5435. }
  5436. }
  5437. }
  5438. var request = FontLoader.queueLoadingCallback(callback);
  5439. if (this.isFontLoadingAPISupported) {
  5440. Promise.all(fontsToLoad).then(function() {
  5441. request.complete();
  5442. });
  5443. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5444. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5445. } else {
  5446. request.complete();
  5447. }
  5448. },
  5449. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5450. function LoadLoader_completeRequest() {
  5451. assert(!request.end, 'completeRequest() cannot be called twice');
  5452. request.end = Date.now();
  5453. // sending all completed requests in order how they were queued
  5454. while (context.requests.length > 0 && context.requests[0].end) {
  5455. var otherRequest = context.requests.shift();
  5456. setTimeout(otherRequest.callback, 0);
  5457. }
  5458. }
  5459. var context = FontLoader.loadingContext;
  5460. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5461. var request = {
  5462. id: requestId,
  5463. complete: LoadLoader_completeRequest,
  5464. callback: callback,
  5465. started: Date.now()
  5466. };
  5467. context.requests.push(request);
  5468. return request;
  5469. },
  5470. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5471. fonts,
  5472. request) {
  5473. /** Hack begin */
  5474. // There's currently no event when a font has finished downloading so the
  5475. // following code is a dirty hack to 'guess' when a font is
  5476. // ready. It's assumed fonts are loaded in order, so add a known test
  5477. // font after the desired fonts and then test for the loading of that
  5478. // test font.
  5479. function int32(data, offset) {
  5480. return (data.charCodeAt(offset) << 24) |
  5481. (data.charCodeAt(offset + 1) << 16) |
  5482. (data.charCodeAt(offset + 2) << 8) |
  5483. (data.charCodeAt(offset + 3) & 0xff);
  5484. }
  5485. function spliceString(s, offset, remove, insert) {
  5486. var chunk1 = s.substr(0, offset);
  5487. var chunk2 = s.substr(offset + remove);
  5488. return chunk1 + insert + chunk2;
  5489. }
  5490. var i, ii;
  5491. var canvas = document.createElement('canvas');
  5492. canvas.width = 1;
  5493. canvas.height = 1;
  5494. var ctx = canvas.getContext('2d');
  5495. var called = 0;
  5496. function isFontReady(name, callback) {
  5497. called++;
  5498. // With setTimeout clamping this gives the font ~100ms to load.
  5499. if(called > 30) {
  5500. warn('Load test font never loaded.');
  5501. callback();
  5502. return;
  5503. }
  5504. ctx.font = '30px ' + name;
  5505. ctx.fillText('.', 0, 20);
  5506. var imageData = ctx.getImageData(0, 0, 1, 1);
  5507. if (imageData.data[3] > 0) {
  5508. callback();
  5509. return;
  5510. }
  5511. setTimeout(isFontReady.bind(null, name, callback));
  5512. }
  5513. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5514. // Chromium seems to cache fonts based on a hash of the actual font data,
  5515. // so the font must be modified for each load test else it will appear to
  5516. // be loaded already.
  5517. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5518. // font by splitting it in chunks before hand and padding the font id.
  5519. var data = this.loadTestFont;
  5520. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5521. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5522. loadTestFontId);
  5523. // CFF checksum is important for IE, adjusting it
  5524. var CFF_CHECKSUM_OFFSET = 16;
  5525. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5526. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5527. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5528. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5529. }
  5530. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5531. checksum = (checksum - XXXX_VALUE +
  5532. int32(loadTestFontId + 'XXX', i)) | 0;
  5533. }
  5534. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5535. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5536. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5537. url + '}';
  5538. FontLoader.insertRule(rule);
  5539. var names = [];
  5540. for (i = 0, ii = fonts.length; i < ii; i++) {
  5541. names.push(fonts[i].loadedName);
  5542. }
  5543. names.push(loadTestFontId);
  5544. var div = document.createElement('div');
  5545. div.setAttribute('style',
  5546. 'visibility: hidden;' +
  5547. 'width: 10px; height: 10px;' +
  5548. 'position: absolute; top: 0px; left: 0px;');
  5549. for (i = 0, ii = names.length; i < ii; ++i) {
  5550. var span = document.createElement('span');
  5551. span.textContent = 'Hi';
  5552. span.style.fontFamily = names[i];
  5553. div.appendChild(span);
  5554. }
  5555. document.body.appendChild(div);
  5556. isFontReady(loadTestFontId, function() {
  5557. document.body.removeChild(div);
  5558. request.complete();
  5559. });
  5560. /** Hack end */
  5561. }
  5562. };
  5563. var FontFaceObject = (function FontFaceObjectClosure() {
  5564. function FontFaceObject(name, file, properties) {
  5565. this.compiledGlyphs = {};
  5566. if (arguments.length === 1) {
  5567. // importing translated data
  5568. var data = arguments[0];
  5569. for (var i in data) {
  5570. this[i] = data[i];
  5571. }
  5572. return;
  5573. }
  5574. }
  5575. FontFaceObject.prototype = {
  5576. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5577. if (!this.data) {
  5578. return null;
  5579. }
  5580. if (PDFJS.disableFontFace) {
  5581. this.disableFontFace = true;
  5582. return null;
  5583. }
  5584. var nativeFontFace = new FontFace(this.loadedName, this.data);
  5585. FontLoader.addNativeFontFace(nativeFontFace);
  5586. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5587. globalScope['FontInspector'].enabled) {
  5588. globalScope['FontInspector'].fontAdded(this);
  5589. }
  5590. return nativeFontFace;
  5591. },
  5592. bindDOM: function FontFaceObject_bindDOM() {
  5593. if (!this.data) {
  5594. return null;
  5595. }
  5596. if (PDFJS.disableFontFace) {
  5597. this.disableFontFace = true;
  5598. return null;
  5599. }
  5600. var data = bytesToString(new Uint8Array(this.data));
  5601. var fontName = this.loadedName;
  5602. // Add the font-face rule to the document
  5603. var url = ('url(data:' + this.mimetype + ';base64,' +
  5604. window.btoa(data) + ');');
  5605. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5606. FontLoader.insertRule(rule);
  5607. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5608. globalScope['FontInspector'].enabled) {
  5609. globalScope['FontInspector'].fontAdded(this, url);
  5610. }
  5611. return rule;
  5612. },
  5613. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5614. if (!(character in this.compiledGlyphs)) {
  5615. var js = objs.get(this.loadedName + '_path_' + character);
  5616. /*jshint -W054 */
  5617. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5618. }
  5619. return this.compiledGlyphs[character];
  5620. }
  5621. };
  5622. return FontFaceObject;
  5623. })();
  5624. var HIGHLIGHT_OFFSET = 4; // px
  5625. var ANNOT_MIN_SIZE = 10; // px
  5626. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5627. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5628. function setTextStyles(element, item, fontObj) {
  5629. var style = element.style;
  5630. style.fontSize = item.fontSize + 'px';
  5631. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5632. if (!fontObj) {
  5633. return;
  5634. }
  5635. style.fontWeight = fontObj.black ?
  5636. (fontObj.bold ? 'bolder' : 'bold') :
  5637. (fontObj.bold ? 'bold' : 'normal');
  5638. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5639. var fontName = fontObj.loadedName;
  5640. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5641. // Use a reasonable default font if the font doesn't specify a fallback
  5642. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5643. style.fontFamily = fontFamily + fallbackName;
  5644. }
  5645. // TODO(mack): Remove this, it's not really that helpful.
  5646. function getEmptyContainer(tagName, rect, borderWidth) {
  5647. var bWidth = borderWidth || 0;
  5648. var element = document.createElement(tagName);
  5649. element.style.borderWidth = bWidth + 'px';
  5650. var width = rect[2] - rect[0] - 2 * bWidth;
  5651. var height = rect[3] - rect[1] - 2 * bWidth;
  5652. element.style.width = width + 'px';
  5653. element.style.height = height + 'px';
  5654. return element;
  5655. }
  5656. function initContainer(item) {
  5657. var container = getEmptyContainer('section', item.rect, item.borderWidth);
  5658. container.style.backgroundColor = item.color;
  5659. var color = item.color;
  5660. var rgb = [];
  5661. for (var i = 0; i < 3; ++i) {
  5662. rgb[i] = Math.round(color[i] * 255);
  5663. }
  5664. item.colorCssRgb = Util.makeCssRgb(rgb);
  5665. var highlight = document.createElement('div');
  5666. highlight.className = 'annotationHighlight';
  5667. highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
  5668. highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
  5669. highlight.setAttribute('hidden', true);
  5670. item.highlightElement = highlight;
  5671. container.appendChild(item.highlightElement);
  5672. return container;
  5673. }
  5674. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5675. var element = getEmptyContainer('div', item.rect, 0);
  5676. element.style.display = 'table';
  5677. var content = document.createElement('div');
  5678. content.textContent = item.fieldValue;
  5679. var textAlignment = item.textAlignment;
  5680. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5681. content.style.verticalAlign = 'middle';
  5682. content.style.display = 'table-cell';
  5683. var fontObj = item.fontRefName ?
  5684. commonObjs.getData(item.fontRefName) : null;
  5685. setTextStyles(content, item, fontObj);
  5686. element.appendChild(content);
  5687. return element;
  5688. }
  5689. function getHtmlElementForTextAnnotation(item) {
  5690. var rect = item.rect;
  5691. // sanity check because of OOo-generated PDFs
  5692. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5693. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5694. }
  5695. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5696. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5697. }
  5698. var container = initContainer(item);
  5699. container.className = 'annotText';
  5700. var image = document.createElement('img');
  5701. image.style.height = container.style.height;
  5702. image.style.width = container.style.width;
  5703. var iconName = item.name;
  5704. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5705. iconName.toLowerCase() + '.svg';
  5706. image.alt = '[{{type}} Annotation]';
  5707. image.dataset.l10nId = 'text_annotation_type';
  5708. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5709. var contentWrapper = document.createElement('div');
  5710. contentWrapper.className = 'annotTextContentWrapper';
  5711. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5712. contentWrapper.style.top = '-10px';
  5713. var content = document.createElement('div');
  5714. content.className = 'annotTextContent';
  5715. content.setAttribute('hidden', true);
  5716. var i, ii;
  5717. if (item.hasBgColor) {
  5718. var color = item.color;
  5719. var rgb = [];
  5720. for (i = 0; i < 3; ++i) {
  5721. // Enlighten the color (70%)
  5722. var c = Math.round(color[i] * 255);
  5723. rgb[i] = Math.round((255 - c) * 0.7) + c;
  5724. }
  5725. content.style.backgroundColor = Util.makeCssRgb(rgb);
  5726. }
  5727. var title = document.createElement('h1');
  5728. var text = document.createElement('p');
  5729. title.textContent = item.title;
  5730. if (!item.content && !item.title) {
  5731. content.setAttribute('hidden', true);
  5732. } else {
  5733. var e = document.createElement('span');
  5734. var lines = item.content.split(/(?:\r\n?|\n)/);
  5735. for (i = 0, ii = lines.length; i < ii; ++i) {
  5736. var line = lines[i];
  5737. e.appendChild(document.createTextNode(line));
  5738. if (i < (ii - 1)) {
  5739. e.appendChild(document.createElement('br'));
  5740. }
  5741. }
  5742. text.appendChild(e);
  5743. var pinned = false;
  5744. var showAnnotation = function showAnnotation(pin) {
  5745. if (pin) {
  5746. pinned = true;
  5747. }
  5748. if (content.hasAttribute('hidden')) {
  5749. container.style.zIndex += 1;
  5750. content.removeAttribute('hidden');
  5751. }
  5752. };
  5753. var hideAnnotation = function hideAnnotation(unpin) {
  5754. if (unpin) {
  5755. pinned = false;
  5756. }
  5757. if (!content.hasAttribute('hidden') && !pinned) {
  5758. container.style.zIndex -= 1;
  5759. content.setAttribute('hidden', true);
  5760. }
  5761. };
  5762. var toggleAnnotation = function toggleAnnotation() {
  5763. if (pinned) {
  5764. hideAnnotation(true);
  5765. } else {
  5766. showAnnotation(true);
  5767. }
  5768. };
  5769. image.addEventListener('click', function image_clickHandler() {
  5770. toggleAnnotation();
  5771. }, false);
  5772. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5773. showAnnotation();
  5774. }, false);
  5775. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5776. hideAnnotation();
  5777. }, false);
  5778. content.addEventListener('click', function content_clickHandler() {
  5779. hideAnnotation(true);
  5780. }, false);
  5781. }
  5782. content.appendChild(title);
  5783. content.appendChild(text);
  5784. contentWrapper.appendChild(content);
  5785. container.appendChild(image);
  5786. container.appendChild(contentWrapper);
  5787. return container;
  5788. }
  5789. function getHtmlElementForLinkAnnotation(item) {
  5790. var container = initContainer(item);
  5791. container.className = 'annotLink';
  5792. container.style.borderColor = item.colorCssRgb;
  5793. container.style.borderStyle = 'solid';
  5794. var link = document.createElement('a');
  5795. link.href = link.title = item.url || '';
  5796. container.appendChild(link);
  5797. return container;
  5798. }
  5799. function getHtmlElement(data, objs) {
  5800. switch (data.annotationType) {
  5801. case AnnotationType.WIDGET:
  5802. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5803. case AnnotationType.TEXT:
  5804. return getHtmlElementForTextAnnotation(data);
  5805. case AnnotationType.LINK:
  5806. return getHtmlElementForLinkAnnotation(data);
  5807. default:
  5808. throw new Error('Unsupported annotationType: ' + data.annotationType);
  5809. }
  5810. }
  5811. return {
  5812. getHtmlElement: getHtmlElement
  5813. };
  5814. })();
  5815. PDFJS.AnnotationUtils = AnnotationUtils;
  5816. var SVG_DEFAULTS = {
  5817. fontStyle: 'normal',
  5818. fontWeight: 'normal',
  5819. fillColor: '#000000'
  5820. };
  5821. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  5822. var PNG_HEADER =
  5823. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  5824. var CHUNK_WRAPPER_SIZE = 12;
  5825. var crcTable = new Int32Array(256);
  5826. for (var i = 0; i < 256; i++) {
  5827. var c = i;
  5828. for (var h = 0; h < 8; h++) {
  5829. if (c & 1) {
  5830. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  5831. } else {
  5832. c = (c >> 1) & 0x7fffffff;
  5833. }
  5834. }
  5835. crcTable[i] = c;
  5836. }
  5837. function crc32(data, start, end) {
  5838. var crc = -1;
  5839. for (var i = start; i < end; i++) {
  5840. var a = (crc ^ data[i]) & 0xff;
  5841. var b = crcTable[a];
  5842. crc = (crc >>> 8) ^ b;
  5843. }
  5844. return crc ^ -1;
  5845. }
  5846. function writePngChunk(type, body, data, offset) {
  5847. var p = offset;
  5848. var len = body.length;
  5849. data[p] = len >> 24 & 0xff;
  5850. data[p + 1] = len >> 16 & 0xff;
  5851. data[p + 2] = len >> 8 & 0xff;
  5852. data[p + 3] = len & 0xff;
  5853. p += 4;
  5854. data[p] = type.charCodeAt(0) & 0xff;
  5855. data[p + 1] = type.charCodeAt(1) & 0xff;
  5856. data[p + 2] = type.charCodeAt(2) & 0xff;
  5857. data[p + 3] = type.charCodeAt(3) & 0xff;
  5858. p += 4;
  5859. data.set(body, p);
  5860. p += body.length;
  5861. var crc = crc32(data, offset + 4, p);
  5862. data[p] = crc >> 24 & 0xff;
  5863. data[p + 1] = crc >> 16 & 0xff;
  5864. data[p + 2] = crc >> 8 & 0xff;
  5865. data[p + 3] = crc & 0xff;
  5866. }
  5867. function adler32(data, start, end) {
  5868. var a = 1;
  5869. var b = 0;
  5870. for (var i = start; i < end; ++i) {
  5871. a = (a + (data[i] & 0xff)) % 65521;
  5872. b = (b + a) % 65521;
  5873. }
  5874. return (b << 16) | a;
  5875. }
  5876. function encode(imgData, kind) {
  5877. var width = imgData.width;
  5878. var height = imgData.height;
  5879. var bitDepth, colorType, lineSize;
  5880. var bytes = imgData.data;
  5881. switch (kind) {
  5882. case ImageKind.GRAYSCALE_1BPP:
  5883. colorType = 0;
  5884. bitDepth = 1;
  5885. lineSize = (width + 7) >> 3;
  5886. break;
  5887. case ImageKind.RGB_24BPP:
  5888. colorType = 2;
  5889. bitDepth = 8;
  5890. lineSize = width * 3;
  5891. break;
  5892. case ImageKind.RGBA_32BPP:
  5893. colorType = 6;
  5894. bitDepth = 8;
  5895. lineSize = width * 4;
  5896. break;
  5897. default:
  5898. throw new Error('invalid format');
  5899. }
  5900. // prefix every row with predictor 0
  5901. var literals = new Uint8Array((1 + lineSize) * height);
  5902. var offsetLiterals = 0, offsetBytes = 0;
  5903. var y, i;
  5904. for (y = 0; y < height; ++y) {
  5905. literals[offsetLiterals++] = 0; // no prediction
  5906. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  5907. offsetLiterals);
  5908. offsetBytes += lineSize;
  5909. offsetLiterals += lineSize;
  5910. }
  5911. if (kind === ImageKind.GRAYSCALE_1BPP) {
  5912. // inverting for B/W
  5913. offsetLiterals = 0;
  5914. for (y = 0; y < height; y++) {
  5915. offsetLiterals++; // skipping predictor
  5916. for (i = 0; i < lineSize; i++) {
  5917. literals[offsetLiterals++] ^= 0xFF;
  5918. }
  5919. }
  5920. }
  5921. var ihdr = new Uint8Array([
  5922. width >> 24 & 0xff,
  5923. width >> 16 & 0xff,
  5924. width >> 8 & 0xff,
  5925. width & 0xff,
  5926. height >> 24 & 0xff,
  5927. height >> 16 & 0xff,
  5928. height >> 8 & 0xff,
  5929. height & 0xff,
  5930. bitDepth, // bit depth
  5931. colorType, // color type
  5932. 0x00, // compression method
  5933. 0x00, // filter method
  5934. 0x00 // interlace method
  5935. ]);
  5936. var len = literals.length;
  5937. var maxBlockLength = 0xFFFF;
  5938. var deflateBlocks = Math.ceil(len / maxBlockLength);
  5939. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  5940. var pi = 0;
  5941. idat[pi++] = 0x78; // compression method and flags
  5942. idat[pi++] = 0x9c; // flags
  5943. var pos = 0;
  5944. while (len > maxBlockLength) {
  5945. // writing non-final DEFLATE blocks type 0 and length of 65535
  5946. idat[pi++] = 0x00;
  5947. idat[pi++] = 0xff;
  5948. idat[pi++] = 0xff;
  5949. idat[pi++] = 0x00;
  5950. idat[pi++] = 0x00;
  5951. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  5952. pi += maxBlockLength;
  5953. pos += maxBlockLength;
  5954. len -= maxBlockLength;
  5955. }
  5956. // writing non-final DEFLATE blocks type 0
  5957. idat[pi++] = 0x01;
  5958. idat[pi++] = len & 0xff;
  5959. idat[pi++] = len >> 8 & 0xff;
  5960. idat[pi++] = (~len & 0xffff) & 0xff;
  5961. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  5962. idat.set(literals.subarray(pos), pi);
  5963. pi += literals.length - pos;
  5964. var adler = adler32(literals, 0, literals.length); // checksum
  5965. idat[pi++] = adler >> 24 & 0xff;
  5966. idat[pi++] = adler >> 16 & 0xff;
  5967. idat[pi++] = adler >> 8 & 0xff;
  5968. idat[pi++] = adler & 0xff;
  5969. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  5970. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  5971. ihdr.length + idat.length;
  5972. var data = new Uint8Array(pngLength);
  5973. var offset = 0;
  5974. data.set(PNG_HEADER, offset);
  5975. offset += PNG_HEADER.length;
  5976. writePngChunk('IHDR', ihdr, data, offset);
  5977. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  5978. writePngChunk('IDATA', idat, data, offset);
  5979. offset += CHUNK_WRAPPER_SIZE + idat.length;
  5980. writePngChunk('IEND', new Uint8Array(0), data, offset);
  5981. return PDFJS.createObjectURL(data, 'image/png');
  5982. }
  5983. return function convertImgDataToPng(imgData) {
  5984. var kind = (imgData.kind === undefined ?
  5985. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  5986. return encode(imgData, kind);
  5987. };
  5988. })();
  5989. var SVGExtraState = (function SVGExtraStateClosure() {
  5990. function SVGExtraState() {
  5991. this.fontSizeScale = 1;
  5992. this.fontWeight = SVG_DEFAULTS.fontWeight;
  5993. this.fontSize = 0;
  5994. this.textMatrix = IDENTITY_MATRIX;
  5995. this.fontMatrix = FONT_IDENTITY_MATRIX;
  5996. this.leading = 0;
  5997. // Current point (in user coordinates)
  5998. this.x = 0;
  5999. this.y = 0;
  6000. // Start of text line (in text coordinates)
  6001. this.lineX = 0;
  6002. this.lineY = 0;
  6003. // Character and word spacing
  6004. this.charSpacing = 0;
  6005. this.wordSpacing = 0;
  6006. this.textHScale = 1;
  6007. this.textRise = 0;
  6008. // Default foreground and background colors
  6009. this.fillColor = SVG_DEFAULTS.fillColor;
  6010. this.strokeColor = '#000000';
  6011. this.fillAlpha = 1;
  6012. this.strokeAlpha = 1;
  6013. this.lineWidth = 1;
  6014. this.lineJoin = '';
  6015. this.lineCap = '';
  6016. this.miterLimit = 0;
  6017. this.dashArray = [];
  6018. this.dashPhase = 0;
  6019. this.dependencies = [];
  6020. // Clipping
  6021. this.clipId = '';
  6022. this.pendingClip = false;
  6023. this.maskId = '';
  6024. }
  6025. SVGExtraState.prototype = {
  6026. clone: function SVGExtraState_clone() {
  6027. return Object.create(this);
  6028. },
  6029. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6030. this.x = x;
  6031. this.y = y;
  6032. }
  6033. };
  6034. return SVGExtraState;
  6035. })();
  6036. var SVGGraphics = (function SVGGraphicsClosure() {
  6037. function createScratchSVG(width, height) {
  6038. var NS = 'http://www.w3.org/2000/svg';
  6039. var svg = document.createElementNS(NS, 'svg:svg');
  6040. svg.setAttributeNS(null, 'version', '1.1');
  6041. svg.setAttributeNS(null, 'width', width + 'px');
  6042. svg.setAttributeNS(null, 'height', height + 'px');
  6043. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6044. return svg;
  6045. }
  6046. function opListToTree(opList) {
  6047. var opTree = [];
  6048. var tmp = [];
  6049. var opListLen = opList.length;
  6050. for (var x = 0; x < opListLen; x++) {
  6051. if (opList[x].fn === 'save') {
  6052. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6053. tmp.push(opTree);
  6054. opTree = opTree[opTree.length - 1].items;
  6055. continue;
  6056. }
  6057. if(opList[x].fn === 'restore') {
  6058. opTree = tmp.pop();
  6059. } else {
  6060. opTree.push(opList[x]);
  6061. }
  6062. }
  6063. return opTree;
  6064. }
  6065. /**
  6066. * Formats float number.
  6067. * @param value {number} number to format.
  6068. * @returns {string}
  6069. */
  6070. function pf(value) {
  6071. if (value === (value | 0)) { // integer number
  6072. return value.toString();
  6073. }
  6074. var s = value.toFixed(10);
  6075. var i = s.length - 1;
  6076. if (s[i] !== '0') {
  6077. return s;
  6078. }
  6079. // removing trailing zeros
  6080. do {
  6081. i--;
  6082. } while (s[i] === '0');
  6083. return s.substr(0, s[i] === '.' ? i : i + 1);
  6084. }
  6085. /**
  6086. * Formats transform matrix. The standard rotation, scale and translate
  6087. * matrices are replaced by their shorter forms, and for identity matrix
  6088. * returns empty string to save the memory.
  6089. * @param m {Array} matrix to format.
  6090. * @returns {string}
  6091. */
  6092. function pm(m) {
  6093. if (m[4] === 0 && m[5] === 0) {
  6094. if (m[1] === 0 && m[2] === 0) {
  6095. if (m[0] === 1 && m[3] === 1) {
  6096. return '';
  6097. }
  6098. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6099. }
  6100. if (m[0] === m[3] && m[1] === -m[2]) {
  6101. var a = Math.acos(m[0]) * 180 / Math.PI;
  6102. return 'rotate(' + pf(a) + ')';
  6103. }
  6104. } else {
  6105. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6106. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6107. }
  6108. }
  6109. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6110. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6111. }
  6112. function SVGGraphics(commonObjs, objs) {
  6113. this.current = new SVGExtraState();
  6114. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6115. this.transformStack = [];
  6116. this.extraStack = [];
  6117. this.commonObjs = commonObjs;
  6118. this.objs = objs;
  6119. this.pendingEOFill = false;
  6120. this.embedFonts = false;
  6121. this.embeddedFonts = {};
  6122. this.cssStyle = null;
  6123. }
  6124. var NS = 'http://www.w3.org/2000/svg';
  6125. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6126. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6127. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6128. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6129. var clipCount = 0;
  6130. var maskCount = 0;
  6131. SVGGraphics.prototype = {
  6132. save: function SVGGraphics_save() {
  6133. this.transformStack.push(this.transformMatrix);
  6134. var old = this.current;
  6135. this.extraStack.push(old);
  6136. this.current = old.clone();
  6137. },
  6138. restore: function SVGGraphics_restore() {
  6139. this.transformMatrix = this.transformStack.pop();
  6140. this.current = this.extraStack.pop();
  6141. this.tgrp = document.createElementNS(NS, 'svg:g');
  6142. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6143. this.pgrp.appendChild(this.tgrp);
  6144. },
  6145. group: function SVGGraphics_group(items) {
  6146. this.save();
  6147. this.executeOpTree(items);
  6148. this.restore();
  6149. },
  6150. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6151. var fnArray = operatorList.fnArray;
  6152. var fnArrayLen = fnArray.length;
  6153. var argsArray = operatorList.argsArray;
  6154. var self = this;
  6155. for (var i = 0; i < fnArrayLen; i++) {
  6156. if (OPS.dependency === fnArray[i]) {
  6157. var deps = argsArray[i];
  6158. for (var n = 0, nn = deps.length; n < nn; n++) {
  6159. var obj = deps[n];
  6160. var common = obj.substring(0, 2) === 'g_';
  6161. var promise;
  6162. if (common) {
  6163. promise = new Promise(function(resolve) {
  6164. self.commonObjs.get(obj, resolve);
  6165. });
  6166. } else {
  6167. promise = new Promise(function(resolve) {
  6168. self.objs.get(obj, resolve);
  6169. });
  6170. }
  6171. this.current.dependencies.push(promise);
  6172. }
  6173. }
  6174. }
  6175. return Promise.all(this.current.dependencies);
  6176. },
  6177. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6178. var transformMatrix = [a, b, c, d, e, f];
  6179. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6180. transformMatrix);
  6181. this.tgrp = document.createElementNS(NS, 'svg:g');
  6182. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6183. },
  6184. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6185. this.svg = createScratchSVG(viewport.width, viewport.height);
  6186. this.viewport = viewport;
  6187. return this.loadDependencies(operatorList).then(function () {
  6188. this.transformMatrix = IDENTITY_MATRIX;
  6189. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6190. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6191. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6192. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6193. this.defs = document.createElementNS(NS, 'svg:defs');
  6194. this.pgrp.appendChild(this.defs);
  6195. this.pgrp.appendChild(this.tgrp);
  6196. this.svg.appendChild(this.pgrp);
  6197. var opTree = this.convertOpList(operatorList);
  6198. this.executeOpTree(opTree);
  6199. return this.svg;
  6200. }.bind(this));
  6201. },
  6202. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6203. var argsArray = operatorList.argsArray;
  6204. var fnArray = operatorList.fnArray;
  6205. var fnArrayLen = fnArray.length;
  6206. var REVOPS = [];
  6207. var opList = [];
  6208. for (var op in OPS) {
  6209. REVOPS[OPS[op]] = op;
  6210. }
  6211. for (var x = 0; x < fnArrayLen; x++) {
  6212. var fnId = fnArray[x];
  6213. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6214. }
  6215. return opListToTree(opList);
  6216. },
  6217. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6218. var opTreeLen = opTree.length;
  6219. for(var x = 0; x < opTreeLen; x++) {
  6220. var fn = opTree[x].fn;
  6221. var fnId = opTree[x].fnId;
  6222. var args = opTree[x].args;
  6223. switch (fnId | 0) {
  6224. case OPS.beginText:
  6225. this.beginText();
  6226. break;
  6227. case OPS.setLeading:
  6228. this.setLeading(args);
  6229. break;
  6230. case OPS.setLeadingMoveText:
  6231. this.setLeadingMoveText(args[0], args[1]);
  6232. break;
  6233. case OPS.setFont:
  6234. this.setFont(args);
  6235. break;
  6236. case OPS.showText:
  6237. this.showText(args[0]);
  6238. break;
  6239. case OPS.showSpacedText:
  6240. this.showText(args[0]);
  6241. break;
  6242. case OPS.endText:
  6243. this.endText();
  6244. break;
  6245. case OPS.moveText:
  6246. this.moveText(args[0], args[1]);
  6247. break;
  6248. case OPS.setCharSpacing:
  6249. this.setCharSpacing(args[0]);
  6250. break;
  6251. case OPS.setWordSpacing:
  6252. this.setWordSpacing(args[0]);
  6253. break;
  6254. case OPS.setTextMatrix:
  6255. this.setTextMatrix(args[0], args[1], args[2],
  6256. args[3], args[4], args[5]);
  6257. break;
  6258. case OPS.setLineWidth:
  6259. this.setLineWidth(args[0]);
  6260. break;
  6261. case OPS.setLineJoin:
  6262. this.setLineJoin(args[0]);
  6263. break;
  6264. case OPS.setLineCap:
  6265. this.setLineCap(args[0]);
  6266. break;
  6267. case OPS.setMiterLimit:
  6268. this.setMiterLimit(args[0]);
  6269. break;
  6270. case OPS.setFillRGBColor:
  6271. this.setFillRGBColor(args[0], args[1], args[2]);
  6272. break;
  6273. case OPS.setStrokeRGBColor:
  6274. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6275. break;
  6276. case OPS.setDash:
  6277. this.setDash(args[0], args[1]);
  6278. break;
  6279. case OPS.setGState:
  6280. this.setGState(args[0]);
  6281. break;
  6282. case OPS.fill:
  6283. this.fill();
  6284. break;
  6285. case OPS.eoFill:
  6286. this.eoFill();
  6287. break;
  6288. case OPS.stroke:
  6289. this.stroke();
  6290. break;
  6291. case OPS.fillStroke:
  6292. this.fillStroke();
  6293. break;
  6294. case OPS.eoFillStroke:
  6295. this.eoFillStroke();
  6296. break;
  6297. case OPS.clip:
  6298. this.clip('nonzero');
  6299. break;
  6300. case OPS.eoClip:
  6301. this.clip('evenodd');
  6302. break;
  6303. case OPS.paintSolidColorImageMask:
  6304. this.paintSolidColorImageMask();
  6305. break;
  6306. case OPS.paintJpegXObject:
  6307. this.paintJpegXObject(args[0], args[1], args[2]);
  6308. break;
  6309. case OPS.paintImageXObject:
  6310. this.paintImageXObject(args[0]);
  6311. break;
  6312. case OPS.paintInlineImageXObject:
  6313. this.paintInlineImageXObject(args[0]);
  6314. break;
  6315. case OPS.paintImageMaskXObject:
  6316. this.paintImageMaskXObject(args[0]);
  6317. break;
  6318. case OPS.paintFormXObjectBegin:
  6319. this.paintFormXObjectBegin(args[0], args[1]);
  6320. break;
  6321. case OPS.paintFormXObjectEnd:
  6322. this.paintFormXObjectEnd();
  6323. break;
  6324. case OPS.closePath:
  6325. this.closePath();
  6326. break;
  6327. case OPS.closeStroke:
  6328. this.closeStroke();
  6329. break;
  6330. case OPS.closeFillStroke:
  6331. this.closeFillStroke();
  6332. break;
  6333. case OPS.nextLine:
  6334. this.nextLine();
  6335. break;
  6336. case OPS.transform:
  6337. this.transform(args[0], args[1], args[2], args[3],
  6338. args[4], args[5]);
  6339. break;
  6340. case OPS.constructPath:
  6341. this.constructPath(args[0], args[1]);
  6342. break;
  6343. case OPS.endPath:
  6344. this.endPath();
  6345. break;
  6346. case 92:
  6347. this.group(opTree[x].items);
  6348. break;
  6349. default:
  6350. warn('Unimplemented method '+ fn);
  6351. break;
  6352. }
  6353. }
  6354. },
  6355. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6356. this.current.wordSpacing = wordSpacing;
  6357. },
  6358. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6359. this.current.charSpacing = charSpacing;
  6360. },
  6361. nextLine: function SVGGraphics_nextLine() {
  6362. this.moveText(0, this.current.leading);
  6363. },
  6364. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6365. var current = this.current;
  6366. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6367. this.current.x = this.current.lineX = 0;
  6368. this.current.y = this.current.lineY = 0;
  6369. current.xcoords = [];
  6370. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6371. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6372. current.tspan.setAttributeNS(null, 'font-size',
  6373. pf(current.fontSize) + 'px');
  6374. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6375. current.txtElement = document.createElementNS(NS, 'svg:text');
  6376. current.txtElement.appendChild(current.tspan);
  6377. },
  6378. beginText: function SVGGraphics_beginText() {
  6379. this.current.x = this.current.lineX = 0;
  6380. this.current.y = this.current.lineY = 0;
  6381. this.current.textMatrix = IDENTITY_MATRIX;
  6382. this.current.lineMatrix = IDENTITY_MATRIX;
  6383. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6384. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6385. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6386. this.current.xcoords = [];
  6387. },
  6388. moveText: function SVGGraphics_moveText(x, y) {
  6389. var current = this.current;
  6390. this.current.x = this.current.lineX += x;
  6391. this.current.y = this.current.lineY += y;
  6392. current.xcoords = [];
  6393. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6394. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6395. current.tspan.setAttributeNS(null, 'font-size',
  6396. pf(current.fontSize) + 'px');
  6397. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6398. },
  6399. showText: function SVGGraphics_showText(glyphs) {
  6400. var current = this.current;
  6401. var font = current.font;
  6402. var fontSize = current.fontSize;
  6403. if (fontSize === 0) {
  6404. return;
  6405. }
  6406. var charSpacing = current.charSpacing;
  6407. var wordSpacing = current.wordSpacing;
  6408. var fontDirection = current.fontDirection;
  6409. var textHScale = current.textHScale * fontDirection;
  6410. var glyphsLength = glyphs.length;
  6411. var vertical = font.vertical;
  6412. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6413. var x = 0, i;
  6414. for (i = 0; i < glyphsLength; ++i) {
  6415. var glyph = glyphs[i];
  6416. if (glyph === null) {
  6417. // word break
  6418. x += fontDirection * wordSpacing;
  6419. continue;
  6420. } else if (isNum(glyph)) {
  6421. x += -glyph * fontSize * 0.001;
  6422. continue;
  6423. }
  6424. current.xcoords.push(current.x + x * textHScale);
  6425. var width = glyph.width;
  6426. var character = glyph.fontChar;
  6427. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6428. x += charWidth;
  6429. current.tspan.textContent += character;
  6430. }
  6431. if (vertical) {
  6432. current.y -= x * textHScale;
  6433. } else {
  6434. current.x += x * textHScale;
  6435. }
  6436. current.tspan.setAttributeNS(null, 'x',
  6437. current.xcoords.map(pf).join(' '));
  6438. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6439. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6440. current.tspan.setAttributeNS(null, 'font-size',
  6441. pf(current.fontSize) + 'px');
  6442. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6443. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6444. }
  6445. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6446. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6447. }
  6448. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6449. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6450. }
  6451. current.txtElement.setAttributeNS(null, 'transform',
  6452. pm(current.textMatrix) +
  6453. ' scale(1, -1)' );
  6454. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6455. current.txtElement.appendChild(current.tspan);
  6456. current.txtgrp.appendChild(current.txtElement);
  6457. this.tgrp.appendChild(current.txtElement);
  6458. },
  6459. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6460. this.setLeading(-y);
  6461. this.moveText(x, y);
  6462. },
  6463. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6464. if (!this.cssStyle) {
  6465. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6466. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6467. this.defs.appendChild(this.cssStyle);
  6468. }
  6469. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6470. this.cssStyle.textContent +=
  6471. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6472. ' src: url(' + url + '); }\n';
  6473. },
  6474. setFont: function SVGGraphics_setFont(details) {
  6475. var current = this.current;
  6476. var fontObj = this.commonObjs.get(details[0]);
  6477. var size = details[1];
  6478. this.current.font = fontObj;
  6479. if (this.embedFonts && fontObj.data &&
  6480. !this.embeddedFonts[fontObj.loadedName]) {
  6481. this.addFontStyle(fontObj);
  6482. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6483. }
  6484. current.fontMatrix = (fontObj.fontMatrix ?
  6485. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6486. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6487. (fontObj.bold ? 'bold' : 'normal');
  6488. var italic = fontObj.italic ? 'italic' : 'normal';
  6489. if (size < 0) {
  6490. size = -size;
  6491. current.fontDirection = -1;
  6492. } else {
  6493. current.fontDirection = 1;
  6494. }
  6495. current.fontSize = size;
  6496. current.fontFamily = fontObj.loadedName;
  6497. current.fontWeight = bold;
  6498. current.fontStyle = italic;
  6499. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6500. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6501. current.xcoords = [];
  6502. },
  6503. endText: function SVGGraphics_endText() {
  6504. if (this.current.pendingClip) {
  6505. this.cgrp.appendChild(this.tgrp);
  6506. this.pgrp.appendChild(this.cgrp);
  6507. } else {
  6508. this.pgrp.appendChild(this.tgrp);
  6509. }
  6510. this.tgrp = document.createElementNS(NS, 'svg:g');
  6511. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6512. },
  6513. // Path properties
  6514. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6515. this.current.lineWidth = width;
  6516. },
  6517. setLineCap: function SVGGraphics_setLineCap(style) {
  6518. this.current.lineCap = LINE_CAP_STYLES[style];
  6519. },
  6520. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6521. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6522. },
  6523. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6524. this.current.miterLimit = limit;
  6525. },
  6526. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6527. var color = Util.makeCssRgb(arguments);
  6528. this.current.strokeColor = color;
  6529. },
  6530. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6531. var color = Util.makeCssRgb(arguments);
  6532. this.current.fillColor = color;
  6533. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6534. this.current.xcoords = [];
  6535. },
  6536. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6537. this.current.dashArray = dashArray;
  6538. this.current.dashPhase = dashPhase;
  6539. },
  6540. constructPath: function SVGGraphics_constructPath(ops, args) {
  6541. var current = this.current;
  6542. var x = current.x, y = current.y;
  6543. current.path = document.createElementNS(NS, 'svg:path');
  6544. var d = [];
  6545. var opLength = ops.length;
  6546. for (var i = 0, j = 0; i < opLength; i++) {
  6547. switch (ops[i] | 0) {
  6548. case OPS.rectangle:
  6549. x = args[j++];
  6550. y = args[j++];
  6551. var width = args[j++];
  6552. var height = args[j++];
  6553. var xw = x + width;
  6554. var yh = y + height;
  6555. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6556. 'L', pf(x), pf(yh), 'Z');
  6557. break;
  6558. case OPS.moveTo:
  6559. x = args[j++];
  6560. y = args[j++];
  6561. d.push('M', pf(x), pf(y));
  6562. break;
  6563. case OPS.lineTo:
  6564. x = args[j++];
  6565. y = args[j++];
  6566. d.push('L', pf(x) , pf(y));
  6567. break;
  6568. case OPS.curveTo:
  6569. x = args[j + 4];
  6570. y = args[j + 5];
  6571. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6572. pf(args[j + 3]), pf(x), pf(y));
  6573. j += 6;
  6574. break;
  6575. case OPS.curveTo2:
  6576. x = args[j + 2];
  6577. y = args[j + 3];
  6578. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6579. pf(args[j + 2]), pf(args[j + 3]));
  6580. j += 4;
  6581. break;
  6582. case OPS.curveTo3:
  6583. x = args[j + 2];
  6584. y = args[j + 3];
  6585. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6586. pf(x), pf(y));
  6587. j += 4;
  6588. break;
  6589. case OPS.closePath:
  6590. d.push('Z');
  6591. break;
  6592. }
  6593. }
  6594. current.path.setAttributeNS(null, 'd', d.join(' '));
  6595. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6596. pf(current.miterLimit));
  6597. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6598. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6599. current.path.setAttributeNS(null, 'stroke-width',
  6600. pf(current.lineWidth) + 'px');
  6601. current.path.setAttributeNS(null, 'stroke-dasharray',
  6602. current.dashArray.map(pf).join(' '));
  6603. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6604. pf(current.dashPhase) + 'px');
  6605. current.path.setAttributeNS(null, 'fill', 'none');
  6606. this.tgrp.appendChild(current.path);
  6607. if (current.pendingClip) {
  6608. this.cgrp.appendChild(this.tgrp);
  6609. this.pgrp.appendChild(this.cgrp);
  6610. } else {
  6611. this.pgrp.appendChild(this.tgrp);
  6612. }
  6613. // Saving a reference in current.element so that it can be addressed
  6614. // in 'fill' and 'stroke'
  6615. current.element = current.path;
  6616. current.setCurrentPoint(x, y);
  6617. },
  6618. endPath: function SVGGraphics_endPath() {
  6619. var current = this.current;
  6620. if (current.pendingClip) {
  6621. this.cgrp.appendChild(this.tgrp);
  6622. this.pgrp.appendChild(this.cgrp);
  6623. } else {
  6624. this.pgrp.appendChild(this.tgrp);
  6625. }
  6626. this.tgrp = document.createElementNS(NS, 'svg:g');
  6627. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6628. },
  6629. clip: function SVGGraphics_clip(type) {
  6630. var current = this.current;
  6631. // Add current path to clipping path
  6632. current.clipId = 'clippath' + clipCount;
  6633. clipCount++;
  6634. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6635. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6636. var clipElement = current.element.cloneNode();
  6637. if (type === 'evenodd') {
  6638. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6639. } else {
  6640. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6641. }
  6642. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6643. this.clippath.appendChild(clipElement);
  6644. this.defs.appendChild(this.clippath);
  6645. // Create a new group with that attribute
  6646. current.pendingClip = true;
  6647. this.cgrp = document.createElementNS(NS, 'svg:g');
  6648. this.cgrp.setAttributeNS(null, 'clip-path',
  6649. 'url(#' + current.clipId + ')');
  6650. this.pgrp.appendChild(this.cgrp);
  6651. },
  6652. closePath: function SVGGraphics_closePath() {
  6653. var current = this.current;
  6654. var d = current.path.getAttributeNS(null, 'd');
  6655. d += 'Z';
  6656. current.path.setAttributeNS(null, 'd', d);
  6657. },
  6658. setLeading: function SVGGraphics_setLeading(leading) {
  6659. this.current.leading = -leading;
  6660. },
  6661. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6662. this.current.textRise = textRise;
  6663. },
  6664. setHScale: function SVGGraphics_setHScale(scale) {
  6665. this.current.textHScale = scale / 100;
  6666. },
  6667. setGState: function SVGGraphics_setGState(states) {
  6668. for (var i = 0, ii = states.length; i < ii; i++) {
  6669. var state = states[i];
  6670. var key = state[0];
  6671. var value = state[1];
  6672. switch (key) {
  6673. case 'LW':
  6674. this.setLineWidth(value);
  6675. break;
  6676. case 'LC':
  6677. this.setLineCap(value);
  6678. break;
  6679. case 'LJ':
  6680. this.setLineJoin(value);
  6681. break;
  6682. case 'ML':
  6683. this.setMiterLimit(value);
  6684. break;
  6685. case 'D':
  6686. this.setDash(value[0], value[1]);
  6687. break;
  6688. case 'RI':
  6689. break;
  6690. case 'FL':
  6691. break;
  6692. case 'Font':
  6693. this.setFont(value);
  6694. break;
  6695. case 'CA':
  6696. break;
  6697. case 'ca':
  6698. break;
  6699. case 'BM':
  6700. break;
  6701. case 'SMask':
  6702. break;
  6703. }
  6704. }
  6705. },
  6706. fill: function SVGGraphics_fill() {
  6707. var current = this.current;
  6708. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6709. },
  6710. stroke: function SVGGraphics_stroke() {
  6711. var current = this.current;
  6712. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6713. current.element.setAttributeNS(null, 'fill', 'none');
  6714. },
  6715. eoFill: function SVGGraphics_eoFill() {
  6716. var current = this.current;
  6717. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6718. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6719. },
  6720. fillStroke: function SVGGraphics_fillStroke() {
  6721. // Order is important since stroke wants fill to be none.
  6722. // First stroke, then if fill needed, it will be overwritten.
  6723. this.stroke();
  6724. this.fill();
  6725. },
  6726. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6727. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6728. this.fillStroke();
  6729. },
  6730. closeStroke: function SVGGraphics_closeStroke() {
  6731. this.closePath();
  6732. this.stroke();
  6733. },
  6734. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6735. this.closePath();
  6736. this.fillStroke();
  6737. },
  6738. paintSolidColorImageMask:
  6739. function SVGGraphics_paintSolidColorImageMask() {
  6740. var current = this.current;
  6741. var rect = document.createElementNS(NS, 'svg:rect');
  6742. rect.setAttributeNS(null, 'x', '0');
  6743. rect.setAttributeNS(null, 'y', '0');
  6744. rect.setAttributeNS(null, 'width', '1px');
  6745. rect.setAttributeNS(null, 'height', '1px');
  6746. rect.setAttributeNS(null, 'fill', current.fillColor);
  6747. this.tgrp.appendChild(rect);
  6748. },
  6749. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6750. var current = this.current;
  6751. var imgObj = this.objs.get(objId);
  6752. var imgEl = document.createElementNS(NS, 'svg:image');
  6753. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6754. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6755. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6756. imgEl.setAttributeNS(null, 'x', '0');
  6757. imgEl.setAttributeNS(null, 'y', pf(-h));
  6758. imgEl.setAttributeNS(null, 'transform',
  6759. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6760. this.tgrp.appendChild(imgEl);
  6761. if (current.pendingClip) {
  6762. this.cgrp.appendChild(this.tgrp);
  6763. this.pgrp.appendChild(this.cgrp);
  6764. } else {
  6765. this.pgrp.appendChild(this.tgrp);
  6766. }
  6767. },
  6768. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6769. var imgData = this.objs.get(objId);
  6770. if (!imgData) {
  6771. warn('Dependent image isn\'t ready yet');
  6772. return;
  6773. }
  6774. this.paintInlineImageXObject(imgData);
  6775. },
  6776. paintInlineImageXObject:
  6777. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6778. var current = this.current;
  6779. var width = imgData.width;
  6780. var height = imgData.height;
  6781. var imgSrc = convertImgDataToPng(imgData);
  6782. var cliprect = document.createElementNS(NS, 'svg:rect');
  6783. cliprect.setAttributeNS(null, 'x', '0');
  6784. cliprect.setAttributeNS(null, 'y', '0');
  6785. cliprect.setAttributeNS(null, 'width', pf(width));
  6786. cliprect.setAttributeNS(null, 'height', pf(height));
  6787. current.element = cliprect;
  6788. this.clip('nonzero');
  6789. var imgEl = document.createElementNS(NS, 'svg:image');
  6790. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  6791. imgEl.setAttributeNS(null, 'x', '0');
  6792. imgEl.setAttributeNS(null, 'y', pf(-height));
  6793. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  6794. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  6795. imgEl.setAttributeNS(null, 'transform',
  6796. 'scale(' + pf(1 / width) + ' ' +
  6797. pf(-1 / height) + ')');
  6798. if (mask) {
  6799. mask.appendChild(imgEl);
  6800. } else {
  6801. this.tgrp.appendChild(imgEl);
  6802. }
  6803. if (current.pendingClip) {
  6804. this.cgrp.appendChild(this.tgrp);
  6805. this.pgrp.appendChild(this.cgrp);
  6806. } else {
  6807. this.pgrp.appendChild(this.tgrp);
  6808. }
  6809. },
  6810. paintImageMaskXObject:
  6811. function SVGGraphics_paintImageMaskXObject(imgData) {
  6812. var current = this.current;
  6813. var width = imgData.width;
  6814. var height = imgData.height;
  6815. var fillColor = current.fillColor;
  6816. current.maskId = 'mask' + maskCount++;
  6817. var mask = document.createElementNS(NS, 'svg:mask');
  6818. mask.setAttributeNS(null, 'id', current.maskId);
  6819. var rect = document.createElementNS(NS, 'svg:rect');
  6820. rect.setAttributeNS(null, 'x', '0');
  6821. rect.setAttributeNS(null, 'y', '0');
  6822. rect.setAttributeNS(null, 'width', pf(width));
  6823. rect.setAttributeNS(null, 'height', pf(height));
  6824. rect.setAttributeNS(null, 'fill', fillColor);
  6825. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  6826. this.defs.appendChild(mask);
  6827. this.tgrp.appendChild(rect);
  6828. this.paintInlineImageXObject(imgData, mask);
  6829. },
  6830. paintFormXObjectBegin:
  6831. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  6832. this.save();
  6833. if (isArray(matrix) && matrix.length === 6) {
  6834. this.transform(matrix[0], matrix[1], matrix[2],
  6835. matrix[3], matrix[4], matrix[5]);
  6836. }
  6837. if (isArray(bbox) && bbox.length === 4) {
  6838. var width = bbox[2] - bbox[0];
  6839. var height = bbox[3] - bbox[1];
  6840. var cliprect = document.createElementNS(NS, 'svg:rect');
  6841. cliprect.setAttributeNS(null, 'x', bbox[0]);
  6842. cliprect.setAttributeNS(null, 'y', bbox[1]);
  6843. cliprect.setAttributeNS(null, 'width', pf(width));
  6844. cliprect.setAttributeNS(null, 'height', pf(height));
  6845. this.current.element = cliprect;
  6846. this.clip('nonzero');
  6847. this.endPath();
  6848. }
  6849. },
  6850. paintFormXObjectEnd:
  6851. function SVGGraphics_paintFormXObjectEnd() {
  6852. this.restore();
  6853. }
  6854. };
  6855. return SVGGraphics;
  6856. })();
  6857. PDFJS.SVGGraphics = SVGGraphics;
  6858. var NetworkManager = (function NetworkManagerClosure() {
  6859. var OK_RESPONSE = 200;
  6860. var PARTIAL_CONTENT_RESPONSE = 206;
  6861. function NetworkManager(url, args) {
  6862. this.url = url;
  6863. args = args || {};
  6864. this.isHttp = /^https?:/i.test(url);
  6865. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  6866. this.withCredentials = args.withCredentials || false;
  6867. this.getXhr = args.getXhr ||
  6868. function NetworkManager_getXhr() {
  6869. return new XMLHttpRequest();
  6870. };
  6871. this.currXhrId = 0;
  6872. this.pendingRequests = {};
  6873. this.loadedRequests = {};
  6874. }
  6875. function getArrayBuffer(xhr) {
  6876. var data = xhr.response;
  6877. if (typeof data !== 'string') {
  6878. return data;
  6879. }
  6880. var length = data.length;
  6881. var array = new Uint8Array(length);
  6882. for (var i = 0; i < length; i++) {
  6883. array[i] = data.charCodeAt(i) & 0xFF;
  6884. }
  6885. return array.buffer;
  6886. }
  6887. NetworkManager.prototype = {
  6888. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  6889. var args = {
  6890. begin: begin,
  6891. end: end
  6892. };
  6893. for (var prop in listeners) {
  6894. args[prop] = listeners[prop];
  6895. }
  6896. return this.request(args);
  6897. },
  6898. requestFull: function NetworkManager_requestFull(listeners) {
  6899. return this.request(listeners);
  6900. },
  6901. request: function NetworkManager_request(args) {
  6902. var xhr = this.getXhr();
  6903. var xhrId = this.currXhrId++;
  6904. var pendingRequest = this.pendingRequests[xhrId] = {
  6905. xhr: xhr
  6906. };
  6907. xhr.open('GET', this.url);
  6908. xhr.withCredentials = this.withCredentials;
  6909. for (var property in this.httpHeaders) {
  6910. var value = this.httpHeaders[property];
  6911. if (typeof value === 'undefined') {
  6912. continue;
  6913. }
  6914. xhr.setRequestHeader(property, value);
  6915. }
  6916. if (this.isHttp && 'begin' in args && 'end' in args) {
  6917. var rangeStr = args.begin + '-' + (args.end - 1);
  6918. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  6919. pendingRequest.expectedStatus = 206;
  6920. } else {
  6921. pendingRequest.expectedStatus = 200;
  6922. }
  6923. if (args.onProgressiveData) {
  6924. xhr.responseType = 'moz-chunked-arraybuffer';
  6925. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  6926. pendingRequest.onProgressiveData = args.onProgressiveData;
  6927. pendingRequest.mozChunked = true;
  6928. } else {
  6929. xhr.responseType = 'arraybuffer';
  6930. }
  6931. } else {
  6932. xhr.responseType = 'arraybuffer';
  6933. }
  6934. if (args.onError) {
  6935. xhr.onerror = function(evt) {
  6936. args.onError(xhr.status);
  6937. };
  6938. }
  6939. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  6940. xhr.onprogress = this.onProgress.bind(this, xhrId);
  6941. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  6942. pendingRequest.onDone = args.onDone;
  6943. pendingRequest.onError = args.onError;
  6944. pendingRequest.onProgress = args.onProgress;
  6945. xhr.send(null);
  6946. return xhrId;
  6947. },
  6948. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  6949. var pendingRequest = this.pendingRequests[xhrId];
  6950. if (!pendingRequest) {
  6951. // Maybe abortRequest was called...
  6952. return;
  6953. }
  6954. if (pendingRequest.mozChunked) {
  6955. var chunk = getArrayBuffer(pendingRequest.xhr);
  6956. pendingRequest.onProgressiveData(chunk);
  6957. }
  6958. var onProgress = pendingRequest.onProgress;
  6959. if (onProgress) {
  6960. onProgress(evt);
  6961. }
  6962. },
  6963. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  6964. var pendingRequest = this.pendingRequests[xhrId];
  6965. if (!pendingRequest) {
  6966. // Maybe abortRequest was called...
  6967. return;
  6968. }
  6969. var xhr = pendingRequest.xhr;
  6970. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  6971. pendingRequest.onHeadersReceived();
  6972. delete pendingRequest.onHeadersReceived;
  6973. }
  6974. if (xhr.readyState !== 4) {
  6975. return;
  6976. }
  6977. if (!(xhrId in this.pendingRequests)) {
  6978. // The XHR request might have been aborted in onHeadersReceived()
  6979. // callback, in which case we should abort request
  6980. return;
  6981. }
  6982. delete this.pendingRequests[xhrId];
  6983. // success status == 0 can be on ftp, file and other protocols
  6984. if (xhr.status === 0 && this.isHttp) {
  6985. if (pendingRequest.onError) {
  6986. pendingRequest.onError(xhr.status);
  6987. }
  6988. return;
  6989. }
  6990. var xhrStatus = xhr.status || OK_RESPONSE;
  6991. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  6992. // "A server MAY ignore the Range header". This means it's possible to
  6993. // get a 200 rather than a 206 response from a range request.
  6994. var ok_response_on_range_request =
  6995. xhrStatus === OK_RESPONSE &&
  6996. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  6997. if (!ok_response_on_range_request &&
  6998. xhrStatus !== pendingRequest.expectedStatus) {
  6999. if (pendingRequest.onError) {
  7000. pendingRequest.onError(xhr.status);
  7001. }
  7002. return;
  7003. }
  7004. this.loadedRequests[xhrId] = true;
  7005. var chunk = getArrayBuffer(xhr);
  7006. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7007. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7008. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7009. var begin = parseInt(matches[1], 10);
  7010. pendingRequest.onDone({
  7011. begin: begin,
  7012. chunk: chunk
  7013. });
  7014. } else if (pendingRequest.onProgressiveData) {
  7015. pendingRequest.onDone(null);
  7016. } else {
  7017. pendingRequest.onDone({
  7018. begin: 0,
  7019. chunk: chunk
  7020. });
  7021. }
  7022. },
  7023. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7024. for (var xhrId in this.pendingRequests) {
  7025. return true;
  7026. }
  7027. return false;
  7028. },
  7029. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7030. return this.pendingRequests[xhrId].xhr;
  7031. },
  7032. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7033. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7034. },
  7035. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7036. return xhrId in this.pendingRequests;
  7037. },
  7038. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7039. return xhrId in this.loadedRequests;
  7040. },
  7041. abortAllRequests: function NetworkManager_abortAllRequests() {
  7042. for (var xhrId in this.pendingRequests) {
  7043. this.abortRequest(xhrId | 0);
  7044. }
  7045. },
  7046. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7047. var xhr = this.pendingRequests[xhrId].xhr;
  7048. delete this.pendingRequests[xhrId];
  7049. xhr.abort();
  7050. }
  7051. };
  7052. return NetworkManager;
  7053. })();
  7054. var ChunkedStream = (function ChunkedStreamClosure() {
  7055. function ChunkedStream(length, chunkSize, manager) {
  7056. this.bytes = new Uint8Array(length);
  7057. this.start = 0;
  7058. this.pos = 0;
  7059. this.end = length;
  7060. this.chunkSize = chunkSize;
  7061. this.loadedChunks = [];
  7062. this.numChunksLoaded = 0;
  7063. this.numChunks = Math.ceil(length / chunkSize);
  7064. this.manager = manager;
  7065. this.progressiveDataLength = 0;
  7066. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7067. }
  7068. // required methods for a stream. if a particular stream does not
  7069. // implement these, an error should be thrown
  7070. ChunkedStream.prototype = {
  7071. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7072. var chunks = [];
  7073. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7074. if (!this.loadedChunks[chunk]) {
  7075. chunks.push(chunk);
  7076. }
  7077. }
  7078. return chunks;
  7079. },
  7080. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7081. return [this];
  7082. },
  7083. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7084. return this.numChunksLoaded === this.numChunks;
  7085. },
  7086. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7087. var end = begin + chunk.byteLength;
  7088. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7089. // Using this.length is inaccurate here since this.start can be moved
  7090. // See ChunkedStream.moveStart()
  7091. var length = this.bytes.length;
  7092. assert(end % this.chunkSize === 0 || end === length,
  7093. 'Bad end offset: ' + end);
  7094. this.bytes.set(new Uint8Array(chunk), begin);
  7095. var chunkSize = this.chunkSize;
  7096. var beginChunk = Math.floor(begin / chunkSize);
  7097. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7098. var curChunk;
  7099. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7100. if (!this.loadedChunks[curChunk]) {
  7101. this.loadedChunks[curChunk] = true;
  7102. ++this.numChunksLoaded;
  7103. }
  7104. }
  7105. },
  7106. onReceiveProgressiveData:
  7107. function ChunkedStream_onReceiveProgressiveData(data) {
  7108. var position = this.progressiveDataLength;
  7109. var beginChunk = Math.floor(position / this.chunkSize);
  7110. this.bytes.set(new Uint8Array(data), position);
  7111. position += data.byteLength;
  7112. this.progressiveDataLength = position;
  7113. var endChunk = position >= this.end ? this.numChunks :
  7114. Math.floor(position / this.chunkSize);
  7115. var curChunk;
  7116. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7117. if (!this.loadedChunks[curChunk]) {
  7118. this.loadedChunks[curChunk] = true;
  7119. ++this.numChunksLoaded;
  7120. }
  7121. }
  7122. },
  7123. ensureByte: function ChunkedStream_ensureByte(pos) {
  7124. var chunk = Math.floor(pos / this.chunkSize);
  7125. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7126. return;
  7127. }
  7128. if (!this.loadedChunks[chunk]) {
  7129. throw new MissingDataException(pos, pos + 1);
  7130. }
  7131. this.lastSuccessfulEnsureByteChunk = chunk;
  7132. },
  7133. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7134. if (begin >= end) {
  7135. return;
  7136. }
  7137. if (end <= this.progressiveDataLength) {
  7138. return;
  7139. }
  7140. var chunkSize = this.chunkSize;
  7141. var beginChunk = Math.floor(begin / chunkSize);
  7142. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7143. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7144. if (!this.loadedChunks[chunk]) {
  7145. throw new MissingDataException(begin, end);
  7146. }
  7147. }
  7148. },
  7149. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7150. var chunk, n;
  7151. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7152. if (!this.loadedChunks[chunk]) {
  7153. return chunk;
  7154. }
  7155. }
  7156. // Wrap around to beginning
  7157. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7158. if (!this.loadedChunks[chunk]) {
  7159. return chunk;
  7160. }
  7161. }
  7162. return null;
  7163. },
  7164. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7165. return !!this.loadedChunks[chunk];
  7166. },
  7167. get length() {
  7168. return this.end - this.start;
  7169. },
  7170. get isEmpty() {
  7171. return this.length === 0;
  7172. },
  7173. getByte: function ChunkedStream_getByte() {
  7174. var pos = this.pos;
  7175. if (pos >= this.end) {
  7176. return -1;
  7177. }
  7178. this.ensureByte(pos);
  7179. return this.bytes[this.pos++];
  7180. },
  7181. getUint16: function ChunkedStream_getUint16() {
  7182. var b0 = this.getByte();
  7183. var b1 = this.getByte();
  7184. return (b0 << 8) + b1;
  7185. },
  7186. getInt32: function ChunkedStream_getInt32() {
  7187. var b0 = this.getByte();
  7188. var b1 = this.getByte();
  7189. var b2 = this.getByte();
  7190. var b3 = this.getByte();
  7191. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7192. },
  7193. // returns subarray of original buffer
  7194. // should only be read
  7195. getBytes: function ChunkedStream_getBytes(length) {
  7196. var bytes = this.bytes;
  7197. var pos = this.pos;
  7198. var strEnd = this.end;
  7199. if (!length) {
  7200. this.ensureRange(pos, strEnd);
  7201. return bytes.subarray(pos, strEnd);
  7202. }
  7203. var end = pos + length;
  7204. if (end > strEnd) {
  7205. end = strEnd;
  7206. }
  7207. this.ensureRange(pos, end);
  7208. this.pos = end;
  7209. return bytes.subarray(pos, end);
  7210. },
  7211. peekByte: function ChunkedStream_peekByte() {
  7212. var peekedByte = this.getByte();
  7213. this.pos--;
  7214. return peekedByte;
  7215. },
  7216. peekBytes: function ChunkedStream_peekBytes(length) {
  7217. var bytes = this.getBytes(length);
  7218. this.pos -= bytes.length;
  7219. return bytes;
  7220. },
  7221. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7222. this.ensureRange(begin, end);
  7223. return this.bytes.subarray(begin, end);
  7224. },
  7225. skip: function ChunkedStream_skip(n) {
  7226. if (!n) {
  7227. n = 1;
  7228. }
  7229. this.pos += n;
  7230. },
  7231. reset: function ChunkedStream_reset() {
  7232. this.pos = this.start;
  7233. },
  7234. moveStart: function ChunkedStream_moveStart() {
  7235. this.start = this.pos;
  7236. },
  7237. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7238. this.ensureRange(start, start + length);
  7239. function ChunkedStreamSubstream() {}
  7240. ChunkedStreamSubstream.prototype = Object.create(this);
  7241. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7242. var chunkSize = this.chunkSize;
  7243. var beginChunk = Math.floor(this.start / chunkSize);
  7244. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7245. var missingChunks = [];
  7246. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7247. if (!this.loadedChunks[chunk]) {
  7248. missingChunks.push(chunk);
  7249. }
  7250. }
  7251. return missingChunks;
  7252. };
  7253. var subStream = new ChunkedStreamSubstream();
  7254. subStream.pos = subStream.start = start;
  7255. subStream.end = start + length || this.end;
  7256. subStream.dict = dict;
  7257. return subStream;
  7258. },
  7259. isStream: true
  7260. };
  7261. return ChunkedStream;
  7262. })();
  7263. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7264. function ChunkedStreamManager(length, chunkSize, url, args) {
  7265. this.stream = new ChunkedStream(length, chunkSize, this);
  7266. this.length = length;
  7267. this.chunkSize = chunkSize;
  7268. this.url = url;
  7269. this.disableAutoFetch = args.disableAutoFetch;
  7270. var msgHandler = this.msgHandler = args.msgHandler;
  7271. if (args.chunkedViewerLoading) {
  7272. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7273. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7274. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7275. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7276. };
  7277. } else {
  7278. var getXhr = function getXhr() {
  7279. return new XMLHttpRequest();
  7280. };
  7281. this.networkManager = new NetworkManager(this.url, {
  7282. getXhr: getXhr,
  7283. httpHeaders: args.httpHeaders,
  7284. withCredentials: args.withCredentials
  7285. });
  7286. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7287. this.networkManager.requestRange(begin, end, {
  7288. onDone: this.onReceiveData.bind(this),
  7289. onProgress: this.onProgress.bind(this)
  7290. });
  7291. };
  7292. }
  7293. this.currRequestId = 0;
  7294. this.chunksNeededByRequest = {};
  7295. this.requestsByChunk = {};
  7296. this.callbacksByRequest = {};
  7297. this.progressiveDataLength = 0;
  7298. this._loadedStreamCapability = createPromiseCapability();
  7299. if (args.initialData) {
  7300. this.onReceiveData({chunk: args.initialData});
  7301. }
  7302. }
  7303. ChunkedStreamManager.prototype = {
  7304. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7305. return this._loadedStreamCapability.promise;
  7306. },
  7307. // Get all the chunks that are not yet loaded and groups them into
  7308. // contiguous ranges to load in as few requests as possible
  7309. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7310. var missingChunks = this.stream.getMissingChunks();
  7311. this.requestChunks(missingChunks);
  7312. return this._loadedStreamCapability.promise;
  7313. },
  7314. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7315. callback) {
  7316. var requestId = this.currRequestId++;
  7317. var chunksNeeded;
  7318. var i, ii;
  7319. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7320. for (i = 0, ii = chunks.length; i < ii; i++) {
  7321. if (!this.stream.hasChunk(chunks[i])) {
  7322. chunksNeeded[chunks[i]] = true;
  7323. }
  7324. }
  7325. if (isEmptyObj(chunksNeeded)) {
  7326. if (callback) {
  7327. callback();
  7328. }
  7329. return;
  7330. }
  7331. this.callbacksByRequest[requestId] = callback;
  7332. var chunksToRequest = [];
  7333. for (var chunk in chunksNeeded) {
  7334. chunk = chunk | 0;
  7335. if (!(chunk in this.requestsByChunk)) {
  7336. this.requestsByChunk[chunk] = [];
  7337. chunksToRequest.push(chunk);
  7338. }
  7339. this.requestsByChunk[chunk].push(requestId);
  7340. }
  7341. if (!chunksToRequest.length) {
  7342. return;
  7343. }
  7344. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7345. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7346. var groupedChunk = groupedChunksToRequest[i];
  7347. var begin = groupedChunk.beginChunk * this.chunkSize;
  7348. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7349. this.sendRequest(begin, end);
  7350. }
  7351. },
  7352. getStream: function ChunkedStreamManager_getStream() {
  7353. return this.stream;
  7354. },
  7355. // Loads any chunks in the requested range that are not yet loaded
  7356. requestRange: function ChunkedStreamManager_requestRange(
  7357. begin, end, callback) {
  7358. end = Math.min(end, this.length);
  7359. var beginChunk = this.getBeginChunk(begin);
  7360. var endChunk = this.getEndChunk(end);
  7361. var chunks = [];
  7362. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7363. chunks.push(chunk);
  7364. }
  7365. this.requestChunks(chunks, callback);
  7366. },
  7367. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7368. callback) {
  7369. ranges = ranges || [];
  7370. var chunksToRequest = [];
  7371. for (var i = 0; i < ranges.length; i++) {
  7372. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7373. var endChunk = this.getEndChunk(ranges[i].end);
  7374. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7375. if (chunksToRequest.indexOf(chunk) < 0) {
  7376. chunksToRequest.push(chunk);
  7377. }
  7378. }
  7379. }
  7380. chunksToRequest.sort(function(a, b) { return a - b; });
  7381. this.requestChunks(chunksToRequest, callback);
  7382. },
  7383. // Groups a sorted array of chunks into as few continguous larger
  7384. // chunks as possible
  7385. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7386. var groupedChunks = [];
  7387. var beginChunk = -1;
  7388. var prevChunk = -1;
  7389. for (var i = 0; i < chunks.length; ++i) {
  7390. var chunk = chunks[i];
  7391. if (beginChunk < 0) {
  7392. beginChunk = chunk;
  7393. }
  7394. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7395. groupedChunks.push({ beginChunk: beginChunk,
  7396. endChunk: prevChunk + 1 });
  7397. beginChunk = chunk;
  7398. }
  7399. if (i + 1 === chunks.length) {
  7400. groupedChunks.push({ beginChunk: beginChunk,
  7401. endChunk: chunk + 1 });
  7402. }
  7403. prevChunk = chunk;
  7404. }
  7405. return groupedChunks;
  7406. },
  7407. onProgress: function ChunkedStreamManager_onProgress(args) {
  7408. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7409. args.loaded);
  7410. this.msgHandler.send('DocProgress', {
  7411. loaded: bytesLoaded,
  7412. total: this.length
  7413. });
  7414. },
  7415. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7416. var chunk = args.chunk;
  7417. var isProgressive = args.begin === undefined;
  7418. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7419. var end = begin + chunk.byteLength;
  7420. var beginChunk = Math.floor(begin / this.chunkSize);
  7421. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7422. Math.ceil(end / this.chunkSize);
  7423. if (isProgressive) {
  7424. this.stream.onReceiveProgressiveData(chunk);
  7425. this.progressiveDataLength = end;
  7426. } else {
  7427. this.stream.onReceiveData(begin, chunk);
  7428. }
  7429. if (this.stream.allChunksLoaded()) {
  7430. this._loadedStreamCapability.resolve(this.stream);
  7431. }
  7432. var loadedRequests = [];
  7433. var i, requestId;
  7434. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7435. // The server might return more chunks than requested
  7436. var requestIds = this.requestsByChunk[chunk] || [];
  7437. delete this.requestsByChunk[chunk];
  7438. for (i = 0; i < requestIds.length; ++i) {
  7439. requestId = requestIds[i];
  7440. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7441. if (chunk in chunksNeeded) {
  7442. delete chunksNeeded[chunk];
  7443. }
  7444. if (!isEmptyObj(chunksNeeded)) {
  7445. continue;
  7446. }
  7447. loadedRequests.push(requestId);
  7448. }
  7449. }
  7450. // If there are no pending requests, automatically fetch the next
  7451. // unfetched chunk of the PDF
  7452. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7453. var nextEmptyChunk;
  7454. if (this.stream.numChunksLoaded === 1) {
  7455. // This is a special optimization so that after fetching the first
  7456. // chunk, rather than fetching the second chunk, we fetch the last
  7457. // chunk.
  7458. var lastChunk = this.stream.numChunks - 1;
  7459. if (!this.stream.hasChunk(lastChunk)) {
  7460. nextEmptyChunk = lastChunk;
  7461. }
  7462. } else {
  7463. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7464. }
  7465. if (isInt(nextEmptyChunk)) {
  7466. this.requestChunks([nextEmptyChunk]);
  7467. }
  7468. }
  7469. for (i = 0; i < loadedRequests.length; ++i) {
  7470. requestId = loadedRequests[i];
  7471. var callback = this.callbacksByRequest[requestId];
  7472. delete this.callbacksByRequest[requestId];
  7473. if (callback) {
  7474. callback();
  7475. }
  7476. }
  7477. this.msgHandler.send('DocProgress', {
  7478. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7479. total: this.length
  7480. });
  7481. },
  7482. onError: function ChunkedStreamManager_onError(err) {
  7483. this._loadedStreamCapability.reject(err);
  7484. },
  7485. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7486. var chunk = Math.floor(begin / this.chunkSize);
  7487. return chunk;
  7488. },
  7489. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7490. if (end % this.chunkSize === 0) {
  7491. return end / this.chunkSize;
  7492. }
  7493. // 0 -> 0
  7494. // 1 -> 1
  7495. // 99 -> 1
  7496. // 100 -> 1
  7497. // 101 -> 2
  7498. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7499. return chunk;
  7500. }
  7501. };
  7502. return ChunkedStreamManager;
  7503. })();
  7504. // The maximum number of bytes fetched per range request
  7505. var RANGE_CHUNK_SIZE = 65536;
  7506. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7507. var BasePdfManager = (function BasePdfManagerClosure() {
  7508. function BasePdfManager() {
  7509. throw new Error('Cannot initialize BaseManagerManager');
  7510. }
  7511. BasePdfManager.prototype = {
  7512. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7513. throw new NotImplementedException();
  7514. },
  7515. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7516. return this.ensure(this.pdfDocument, prop, args);
  7517. },
  7518. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7519. return this.ensure(this.pdfDocument.xref, prop, args);
  7520. },
  7521. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7522. return this.ensure(this.pdfDocument.catalog, prop, args);
  7523. },
  7524. getPage: function BasePdfManager_pagePage(pageIndex) {
  7525. return this.pdfDocument.getPage(pageIndex);
  7526. },
  7527. cleanup: function BasePdfManager_cleanup() {
  7528. return this.pdfDocument.cleanup();
  7529. },
  7530. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7531. return new NotImplementedException();
  7532. },
  7533. requestRange: function BasePdfManager_ensure(begin, end) {
  7534. return new NotImplementedException();
  7535. },
  7536. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7537. return new NotImplementedException();
  7538. },
  7539. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7540. return new NotImplementedException();
  7541. },
  7542. updatePassword: function BasePdfManager_updatePassword(password) {
  7543. this.pdfDocument.xref.password = this.password = password;
  7544. if (this._passwordChangedCapability) {
  7545. this._passwordChangedCapability.resolve();
  7546. }
  7547. },
  7548. passwordChanged: function BasePdfManager_passwordChanged() {
  7549. this._passwordChangedCapability = createPromiseCapability();
  7550. return this._passwordChangedCapability.promise;
  7551. },
  7552. terminate: function BasePdfManager_terminate() {
  7553. return new NotImplementedException();
  7554. }
  7555. };
  7556. return BasePdfManager;
  7557. })();
  7558. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7559. function LocalPdfManager(data, password) {
  7560. var stream = new Stream(data);
  7561. this.pdfDocument = new PDFDocument(this, stream, password);
  7562. this._loadedStreamCapability = createPromiseCapability();
  7563. this._loadedStreamCapability.resolve(stream);
  7564. }
  7565. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7566. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7567. LocalPdfManager.prototype.ensure =
  7568. function LocalPdfManager_ensure(obj, prop, args) {
  7569. return new Promise(function (resolve, reject) {
  7570. try {
  7571. var value = obj[prop];
  7572. var result;
  7573. if (typeof value === 'function') {
  7574. result = value.apply(obj, args);
  7575. } else {
  7576. result = value;
  7577. }
  7578. resolve(result);
  7579. } catch (e) {
  7580. reject(e);
  7581. }
  7582. });
  7583. };
  7584. LocalPdfManager.prototype.requestRange =
  7585. function LocalPdfManager_requestRange(begin, end) {
  7586. return Promise.resolve();
  7587. };
  7588. LocalPdfManager.prototype.requestLoadedStream =
  7589. function LocalPdfManager_requestLoadedStream() {
  7590. };
  7591. LocalPdfManager.prototype.onLoadedStream =
  7592. function LocalPdfManager_getLoadedStream() {
  7593. return this._loadedStreamCapability.promise;
  7594. };
  7595. LocalPdfManager.prototype.terminate =
  7596. function LocalPdfManager_terminate() {
  7597. return;
  7598. };
  7599. return LocalPdfManager;
  7600. })();
  7601. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7602. function NetworkPdfManager(args, msgHandler) {
  7603. this.msgHandler = msgHandler;
  7604. var params = {
  7605. msgHandler: msgHandler,
  7606. httpHeaders: args.httpHeaders,
  7607. withCredentials: args.withCredentials,
  7608. chunkedViewerLoading: args.chunkedViewerLoading,
  7609. disableAutoFetch: args.disableAutoFetch,
  7610. initialData: args.initialData
  7611. };
  7612. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7613. args.url, params);
  7614. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7615. args.password);
  7616. }
  7617. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7618. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7619. NetworkPdfManager.prototype.ensure =
  7620. function NetworkPdfManager_ensure(obj, prop, args) {
  7621. var pdfManager = this;
  7622. return new Promise(function (resolve, reject) {
  7623. function ensureHelper() {
  7624. try {
  7625. var result;
  7626. var value = obj[prop];
  7627. if (typeof value === 'function') {
  7628. result = value.apply(obj, args);
  7629. } else {
  7630. result = value;
  7631. }
  7632. resolve(result);
  7633. } catch(e) {
  7634. if (!(e instanceof MissingDataException)) {
  7635. reject(e);
  7636. return;
  7637. }
  7638. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7639. }
  7640. }
  7641. ensureHelper();
  7642. });
  7643. };
  7644. NetworkPdfManager.prototype.requestRange =
  7645. function NetworkPdfManager_requestRange(begin, end) {
  7646. return new Promise(function (resolve) {
  7647. this.streamManager.requestRange(begin, end, function() {
  7648. resolve();
  7649. });
  7650. }.bind(this));
  7651. };
  7652. NetworkPdfManager.prototype.requestLoadedStream =
  7653. function NetworkPdfManager_requestLoadedStream() {
  7654. this.streamManager.requestAllChunks();
  7655. };
  7656. NetworkPdfManager.prototype.sendProgressiveData =
  7657. function NetworkPdfManager_sendProgressiveData(chunk) {
  7658. this.streamManager.onReceiveData({ chunk: chunk });
  7659. };
  7660. NetworkPdfManager.prototype.onLoadedStream =
  7661. function NetworkPdfManager_getLoadedStream() {
  7662. return this.streamManager.onLoadedStream();
  7663. };
  7664. NetworkPdfManager.prototype.terminate =
  7665. function NetworkPdfManager_terminate() {
  7666. this.streamManager.networkManager.abortAllRequests();
  7667. };
  7668. return NetworkPdfManager;
  7669. })();
  7670. var Page = (function PageClosure() {
  7671. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7672. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7673. this.pdfManager = pdfManager;
  7674. this.pageIndex = pageIndex;
  7675. this.pageDict = pageDict;
  7676. this.xref = xref;
  7677. this.ref = ref;
  7678. this.fontCache = fontCache;
  7679. this.idCounters = {
  7680. obj: 0
  7681. };
  7682. this.resourcesPromise = null;
  7683. }
  7684. Page.prototype = {
  7685. getPageProp: function Page_getPageProp(key) {
  7686. return this.pageDict.get(key);
  7687. },
  7688. getInheritedPageProp: function Page_inheritPageProp(key) {
  7689. var dict = this.pageDict;
  7690. var value = dict.get(key);
  7691. while (value === undefined) {
  7692. dict = dict.get('Parent');
  7693. if (!dict) {
  7694. break;
  7695. }
  7696. value = dict.get(key);
  7697. }
  7698. return value;
  7699. },
  7700. get content() {
  7701. return this.getPageProp('Contents');
  7702. },
  7703. get resources() {
  7704. var value = this.getInheritedPageProp('Resources');
  7705. // For robustness: The spec states that a \Resources entry has to be
  7706. // present, but can be empty. Some document omit it still. In this case
  7707. // return an empty dictionary:
  7708. if (value === undefined) {
  7709. value = Dict.empty;
  7710. }
  7711. return shadow(this, 'resources', value);
  7712. },
  7713. get mediaBox() {
  7714. var obj = this.getInheritedPageProp('MediaBox');
  7715. // Reset invalid media box to letter size.
  7716. if (!isArray(obj) || obj.length !== 4) {
  7717. obj = LETTER_SIZE_MEDIABOX;
  7718. }
  7719. return shadow(this, 'mediaBox', obj);
  7720. },
  7721. get view() {
  7722. var mediaBox = this.mediaBox;
  7723. var cropBox = this.getInheritedPageProp('CropBox');
  7724. if (!isArray(cropBox) || cropBox.length !== 4) {
  7725. return shadow(this, 'view', mediaBox);
  7726. }
  7727. // From the spec, 6th ed., p.963:
  7728. // "The crop, bleed, trim, and art boxes should not ordinarily
  7729. // extend beyond the boundaries of the media box. If they do, they are
  7730. // effectively reduced to their intersection with the media box."
  7731. cropBox = Util.intersect(cropBox, mediaBox);
  7732. if (!cropBox) {
  7733. return shadow(this, 'view', mediaBox);
  7734. }
  7735. return shadow(this, 'view', cropBox);
  7736. },
  7737. get annotationRefs() {
  7738. return shadow(this, 'annotationRefs',
  7739. this.getInheritedPageProp('Annots'));
  7740. },
  7741. get rotate() {
  7742. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7743. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7744. if (rotate % 90 !== 0) {
  7745. rotate = 0;
  7746. } else if (rotate >= 360) {
  7747. rotate = rotate % 360;
  7748. } else if (rotate < 0) {
  7749. // The spec doesn't cover negatives, assume its counterclockwise
  7750. // rotation. The following is the other implementation of modulo.
  7751. rotate = ((rotate % 360) + 360) % 360;
  7752. }
  7753. return shadow(this, 'rotate', rotate);
  7754. },
  7755. getContentStream: function Page_getContentStream() {
  7756. var content = this.content;
  7757. var stream;
  7758. if (isArray(content)) {
  7759. // fetching items
  7760. var xref = this.xref;
  7761. var i, n = content.length;
  7762. var streams = [];
  7763. for (i = 0; i < n; ++i) {
  7764. streams.push(xref.fetchIfRef(content[i]));
  7765. }
  7766. stream = new StreamsSequenceStream(streams);
  7767. } else if (isStream(content)) {
  7768. stream = content;
  7769. } else {
  7770. // replacing non-existent page content with empty one
  7771. stream = new NullStream();
  7772. }
  7773. return stream;
  7774. },
  7775. loadResources: function Page_loadResources(keys) {
  7776. if (!this.resourcesPromise) {
  7777. // TODO: add async getInheritedPageProp and remove this.
  7778. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  7779. }
  7780. return this.resourcesPromise.then(function resourceSuccess() {
  7781. var objectLoader = new ObjectLoader(this.resources.map,
  7782. keys,
  7783. this.xref);
  7784. return objectLoader.load();
  7785. }.bind(this));
  7786. },
  7787. getOperatorList: function Page_getOperatorList(handler, intent) {
  7788. var self = this;
  7789. var pdfManager = this.pdfManager;
  7790. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7791. []);
  7792. var resourcesPromise = this.loadResources([
  7793. 'ExtGState',
  7794. 'ColorSpace',
  7795. 'Pattern',
  7796. 'Shading',
  7797. 'XObject',
  7798. 'Font'
  7799. // ProcSet
  7800. // Properties
  7801. ]);
  7802. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  7803. handler, this.pageIndex,
  7804. 'p' + this.pageIndex + '_',
  7805. this.idCounters,
  7806. this.fontCache);
  7807. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  7808. var pageListPromise = dataPromises.then(function(data) {
  7809. var contentStream = data[0];
  7810. var opList = new OperatorList(intent, handler, self.pageIndex);
  7811. handler.send('StartRenderPage', {
  7812. transparency: partialEvaluator.hasBlendModes(self.resources),
  7813. pageIndex: self.pageIndex,
  7814. intent: intent
  7815. });
  7816. return partialEvaluator.getOperatorList(contentStream, self.resources,
  7817. opList).then(function () {
  7818. return opList;
  7819. });
  7820. });
  7821. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  7822. return Promise.all([pageListPromise, annotationsPromise]).then(
  7823. function(datas) {
  7824. var pageOpList = datas[0];
  7825. var annotations = datas[1];
  7826. if (annotations.length === 0) {
  7827. pageOpList.flush(true);
  7828. return pageOpList;
  7829. }
  7830. var annotationsReadyPromise = Annotation.appendToOperatorList(
  7831. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  7832. return annotationsReadyPromise.then(function () {
  7833. pageOpList.flush(true);
  7834. return pageOpList;
  7835. });
  7836. });
  7837. },
  7838. extractTextContent: function Page_extractTextContent() {
  7839. var handler = {
  7840. on: function nullHandlerOn() {},
  7841. send: function nullHandlerSend() {}
  7842. };
  7843. var self = this;
  7844. var pdfManager = this.pdfManager;
  7845. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7846. []);
  7847. var resourcesPromise = this.loadResources([
  7848. 'ExtGState',
  7849. 'XObject',
  7850. 'Font'
  7851. ]);
  7852. var dataPromises = Promise.all([contentStreamPromise,
  7853. resourcesPromise]);
  7854. return dataPromises.then(function(data) {
  7855. var contentStream = data[0];
  7856. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  7857. handler, self.pageIndex,
  7858. 'p' + self.pageIndex + '_',
  7859. self.idCounters,
  7860. self.fontCache);
  7861. return partialEvaluator.getTextContent(contentStream,
  7862. self.resources);
  7863. });
  7864. },
  7865. getAnnotationsData: function Page_getAnnotationsData() {
  7866. var annotations = this.annotations;
  7867. var annotationsData = [];
  7868. for (var i = 0, n = annotations.length; i < n; ++i) {
  7869. annotationsData.push(annotations[i].getData());
  7870. }
  7871. return annotationsData;
  7872. },
  7873. get annotations() {
  7874. var annotations = [];
  7875. var annotationRefs = (this.annotationRefs || []);
  7876. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  7877. var annotationRef = annotationRefs[i];
  7878. var annotation = Annotation.fromRef(this.xref, annotationRef);
  7879. if (annotation) {
  7880. annotations.push(annotation);
  7881. }
  7882. }
  7883. return shadow(this, 'annotations', annotations);
  7884. }
  7885. };
  7886. return Page;
  7887. })();
  7888. /**
  7889. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  7890. * `PDFDoc`, this one doesn't have any job management code.
  7891. * Right now there exists one PDFDocument on the main thread + one object
  7892. * for each worker. If there is no worker support enabled, there are two
  7893. * `PDFDocument` objects on the main thread created.
  7894. */
  7895. var PDFDocument = (function PDFDocumentClosure() {
  7896. function PDFDocument(pdfManager, arg, password) {
  7897. if (isStream(arg)) {
  7898. init.call(this, pdfManager, arg, password);
  7899. } else if (isArrayBuffer(arg)) {
  7900. init.call(this, pdfManager, new Stream(arg), password);
  7901. } else {
  7902. error('PDFDocument: Unknown argument type');
  7903. }
  7904. }
  7905. function init(pdfManager, stream, password) {
  7906. assert(stream.length > 0, 'stream must have data');
  7907. this.pdfManager = pdfManager;
  7908. this.stream = stream;
  7909. var xref = new XRef(this.stream, password, pdfManager);
  7910. this.xref = xref;
  7911. }
  7912. function find(stream, needle, limit, backwards) {
  7913. var pos = stream.pos;
  7914. var end = stream.end;
  7915. var strBuf = [];
  7916. if (pos + limit > end) {
  7917. limit = end - pos;
  7918. }
  7919. for (var n = 0; n < limit; ++n) {
  7920. strBuf.push(String.fromCharCode(stream.getByte()));
  7921. }
  7922. var str = strBuf.join('');
  7923. stream.pos = pos;
  7924. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  7925. if (index === -1) {
  7926. return false; /* not found */
  7927. }
  7928. stream.pos += index;
  7929. return true; /* found */
  7930. }
  7931. var DocumentInfoValidators = {
  7932. get entries() {
  7933. // Lazily build this since all the validation functions below are not
  7934. // defined until after this file loads.
  7935. return shadow(this, 'entries', {
  7936. Title: isString,
  7937. Author: isString,
  7938. Subject: isString,
  7939. Keywords: isString,
  7940. Creator: isString,
  7941. Producer: isString,
  7942. CreationDate: isString,
  7943. ModDate: isString,
  7944. Trapped: isName
  7945. });
  7946. }
  7947. };
  7948. PDFDocument.prototype = {
  7949. parse: function PDFDocument_parse(recoveryMode) {
  7950. this.setup(recoveryMode);
  7951. try {
  7952. // checking if AcroForm is present
  7953. this.acroForm = this.catalog.catDict.get('AcroForm');
  7954. if (this.acroForm) {
  7955. this.xfa = this.acroForm.get('XFA');
  7956. var fields = this.acroForm.get('Fields');
  7957. if ((!fields || !isArray(fields) || fields.length === 0) &&
  7958. !this.xfa) {
  7959. // no fields and no XFA -- not a form (?)
  7960. this.acroForm = null;
  7961. }
  7962. }
  7963. } catch (ex) {
  7964. info('Something wrong with AcroForm entry');
  7965. this.acroForm = null;
  7966. }
  7967. },
  7968. get linearization() {
  7969. var linearization = null;
  7970. if (this.stream.length) {
  7971. try {
  7972. linearization = Linearization.create(this.stream);
  7973. } catch (err) {
  7974. if (err instanceof MissingDataException) {
  7975. throw err;
  7976. }
  7977. info(err);
  7978. }
  7979. }
  7980. // shadow the prototype getter with a data property
  7981. return shadow(this, 'linearization', linearization);
  7982. },
  7983. get startXRef() {
  7984. var stream = this.stream;
  7985. var startXRef = 0;
  7986. var linearization = this.linearization;
  7987. if (linearization) {
  7988. // Find end of first obj.
  7989. stream.reset();
  7990. if (find(stream, 'endobj', 1024)) {
  7991. startXRef = stream.pos + 6;
  7992. }
  7993. } else {
  7994. // Find startxref by jumping backward from the end of the file.
  7995. var step = 1024;
  7996. var found = false, pos = stream.end;
  7997. while (!found && pos > 0) {
  7998. pos -= step - 'startxref'.length;
  7999. if (pos < 0) {
  8000. pos = 0;
  8001. }
  8002. stream.pos = pos;
  8003. found = find(stream, 'startxref', step, true);
  8004. }
  8005. if (found) {
  8006. stream.skip(9);
  8007. var ch;
  8008. do {
  8009. ch = stream.getByte();
  8010. } while (Lexer.isSpace(ch));
  8011. var str = '';
  8012. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8013. str += String.fromCharCode(ch);
  8014. ch = stream.getByte();
  8015. }
  8016. startXRef = parseInt(str, 10);
  8017. if (isNaN(startXRef)) {
  8018. startXRef = 0;
  8019. }
  8020. }
  8021. }
  8022. // shadow the prototype getter with a data property
  8023. return shadow(this, 'startXRef', startXRef);
  8024. },
  8025. get mainXRefEntriesOffset() {
  8026. var mainXRefEntriesOffset = 0;
  8027. var linearization = this.linearization;
  8028. if (linearization) {
  8029. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8030. }
  8031. // shadow the prototype getter with a data property
  8032. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8033. },
  8034. // Find the header, remove leading garbage and setup the stream
  8035. // starting from the header.
  8036. checkHeader: function PDFDocument_checkHeader() {
  8037. var stream = this.stream;
  8038. stream.reset();
  8039. if (find(stream, '%PDF-', 1024)) {
  8040. // Found the header, trim off any garbage before it.
  8041. stream.moveStart();
  8042. // Reading file format version
  8043. var MAX_VERSION_LENGTH = 12;
  8044. var version = '', ch;
  8045. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8046. if (version.length >= MAX_VERSION_LENGTH) {
  8047. break;
  8048. }
  8049. version += String.fromCharCode(ch);
  8050. }
  8051. // removing "%PDF-"-prefix
  8052. this.pdfFormatVersion = version.substring(5);
  8053. return;
  8054. }
  8055. // May not be a PDF file, continue anyway.
  8056. },
  8057. parseStartXRef: function PDFDocument_parseStartXRef() {
  8058. var startXRef = this.startXRef;
  8059. this.xref.setStartXRef(startXRef);
  8060. },
  8061. setup: function PDFDocument_setup(recoveryMode) {
  8062. this.xref.parse(recoveryMode);
  8063. this.catalog = new Catalog(this.pdfManager, this.xref);
  8064. },
  8065. get numPages() {
  8066. var linearization = this.linearization;
  8067. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8068. // shadow the prototype getter
  8069. return shadow(this, 'numPages', num);
  8070. },
  8071. get documentInfo() {
  8072. var docInfo = {
  8073. PDFFormatVersion: this.pdfFormatVersion,
  8074. IsAcroFormPresent: !!this.acroForm,
  8075. IsXFAPresent: !!this.xfa
  8076. };
  8077. var infoDict;
  8078. try {
  8079. infoDict = this.xref.trailer.get('Info');
  8080. } catch (err) {
  8081. info('The document information dictionary is invalid.');
  8082. }
  8083. if (infoDict) {
  8084. var validEntries = DocumentInfoValidators.entries;
  8085. // Only fill the document info with valid entries from the spec.
  8086. for (var key in validEntries) {
  8087. if (infoDict.has(key)) {
  8088. var value = infoDict.get(key);
  8089. // Make sure the value conforms to the spec.
  8090. if (validEntries[key](value)) {
  8091. docInfo[key] = (typeof value !== 'string' ?
  8092. value : stringToPDFString(value));
  8093. } else {
  8094. info('Bad value in document info for "' + key + '"');
  8095. }
  8096. }
  8097. }
  8098. }
  8099. return shadow(this, 'documentInfo', docInfo);
  8100. },
  8101. get fingerprint() {
  8102. var xref = this.xref, hash, fileID = '';
  8103. if (xref.trailer.has('ID')) {
  8104. hash = stringToBytes(xref.trailer.get('ID')[0]);
  8105. } else {
  8106. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  8107. }
  8108. for (var i = 0, n = hash.length; i < n; i++) {
  8109. fileID += hash[i].toString(16);
  8110. }
  8111. return shadow(this, 'fingerprint', fileID);
  8112. },
  8113. getPage: function PDFDocument_getPage(pageIndex) {
  8114. return this.catalog.getPage(pageIndex);
  8115. },
  8116. cleanup: function PDFDocument_cleanup() {
  8117. return this.catalog.cleanup();
  8118. }
  8119. };
  8120. return PDFDocument;
  8121. })();
  8122. var Name = (function NameClosure() {
  8123. function Name(name) {
  8124. this.name = name;
  8125. }
  8126. Name.prototype = {};
  8127. var nameCache = {};
  8128. Name.get = function Name_get(name) {
  8129. var nameValue = nameCache[name];
  8130. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8131. };
  8132. return Name;
  8133. })();
  8134. var Cmd = (function CmdClosure() {
  8135. function Cmd(cmd) {
  8136. this.cmd = cmd;
  8137. }
  8138. Cmd.prototype = {};
  8139. var cmdCache = {};
  8140. Cmd.get = function Cmd_get(cmd) {
  8141. var cmdValue = cmdCache[cmd];
  8142. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8143. };
  8144. return Cmd;
  8145. })();
  8146. var Dict = (function DictClosure() {
  8147. var nonSerializable = function nonSerializableClosure() {
  8148. return nonSerializable; // creating closure on some variable
  8149. };
  8150. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8151. 'Background': true,
  8152. 'ExtGState': true,
  8153. 'Halftone': true,
  8154. 'Layout': true,
  8155. 'Mask': true,
  8156. 'Pagination': true,
  8157. 'Printing': true
  8158. };
  8159. function isRecursionAllowedFor(dict) {
  8160. if (!isName(dict.Type)) {
  8161. return true;
  8162. }
  8163. var dictType = dict.Type.name;
  8164. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8165. }
  8166. // xref is optional
  8167. function Dict(xref) {
  8168. // Map should only be used internally, use functions below to access.
  8169. this.map = Object.create(null);
  8170. this.xref = xref;
  8171. this.objId = null;
  8172. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8173. }
  8174. Dict.prototype = {
  8175. assignXref: function Dict_assignXref(newXref) {
  8176. this.xref = newXref;
  8177. },
  8178. // automatically dereferences Ref objects
  8179. get: function Dict_get(key1, key2, key3) {
  8180. var value;
  8181. var xref = this.xref;
  8182. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8183. typeof key2 === 'undefined') {
  8184. return xref ? xref.fetchIfRef(value) : value;
  8185. }
  8186. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8187. typeof key3 === 'undefined') {
  8188. return xref ? xref.fetchIfRef(value) : value;
  8189. }
  8190. value = this.map[key3] || null;
  8191. return xref ? xref.fetchIfRef(value) : value;
  8192. },
  8193. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8194. getAsync: function Dict_getAsync(key1, key2, key3) {
  8195. var value;
  8196. var xref = this.xref;
  8197. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8198. typeof key2 === 'undefined') {
  8199. if (xref) {
  8200. return xref.fetchIfRefAsync(value);
  8201. }
  8202. return Promise.resolve(value);
  8203. }
  8204. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8205. typeof key3 === 'undefined') {
  8206. if (xref) {
  8207. return xref.fetchIfRefAsync(value);
  8208. }
  8209. return Promise.resolve(value);
  8210. }
  8211. value = this.map[key3] || null;
  8212. if (xref) {
  8213. return xref.fetchIfRefAsync(value);
  8214. }
  8215. return Promise.resolve(value);
  8216. },
  8217. // no dereferencing
  8218. getRaw: function Dict_getRaw(key) {
  8219. return this.map[key];
  8220. },
  8221. // creates new map and dereferences all Refs
  8222. getAll: function Dict_getAll() {
  8223. var all = Object.create(null);
  8224. var queue = null;
  8225. var key, obj;
  8226. for (key in this.map) {
  8227. obj = this.get(key);
  8228. if (obj instanceof Dict) {
  8229. if (isRecursionAllowedFor(obj)) {
  8230. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8231. } else {
  8232. all[key] = this.getRaw(key);
  8233. }
  8234. } else {
  8235. all[key] = obj;
  8236. }
  8237. }
  8238. if (!queue) {
  8239. return all;
  8240. }
  8241. // trying to take cyclic references into the account
  8242. var processed = Object.create(null);
  8243. while (queue.length > 0) {
  8244. var item = queue.shift();
  8245. var itemObj = item.obj;
  8246. var objId = itemObj.objId;
  8247. if (objId && objId in processed) {
  8248. item.target[item.key] = processed[objId];
  8249. continue;
  8250. }
  8251. var dereferenced = Object.create(null);
  8252. for (key in itemObj.map) {
  8253. obj = itemObj.get(key);
  8254. if (obj instanceof Dict) {
  8255. if (isRecursionAllowedFor(obj)) {
  8256. queue.push({target: dereferenced, key: key, obj: obj});
  8257. } else {
  8258. dereferenced[key] = itemObj.getRaw(key);
  8259. }
  8260. } else {
  8261. dereferenced[key] = obj;
  8262. }
  8263. }
  8264. if (objId) {
  8265. processed[objId] = dereferenced;
  8266. }
  8267. item.target[item.key] = dereferenced;
  8268. }
  8269. return all;
  8270. },
  8271. set: function Dict_set(key, value) {
  8272. this.map[key] = value;
  8273. },
  8274. has: function Dict_has(key) {
  8275. return key in this.map;
  8276. },
  8277. forEach: function Dict_forEach(callback) {
  8278. for (var key in this.map) {
  8279. callback(key, this.get(key));
  8280. }
  8281. }
  8282. };
  8283. Dict.empty = new Dict(null);
  8284. return Dict;
  8285. })();
  8286. var Ref = (function RefClosure() {
  8287. function Ref(num, gen) {
  8288. this.num = num;
  8289. this.gen = gen;
  8290. }
  8291. Ref.prototype = {
  8292. toString: function Ref_toString() {
  8293. // This function is hot, so we make the string as compact as possible.
  8294. // |this.gen| is almost always zero, so we treat that case specially.
  8295. var str = this.num + 'R';
  8296. if (this.gen !== 0) {
  8297. str += this.gen;
  8298. }
  8299. return str;
  8300. }
  8301. };
  8302. return Ref;
  8303. })();
  8304. // The reference is identified by number and generation.
  8305. // This structure stores only one instance of the reference.
  8306. var RefSet = (function RefSetClosure() {
  8307. function RefSet() {
  8308. this.dict = {};
  8309. }
  8310. RefSet.prototype = {
  8311. has: function RefSet_has(ref) {
  8312. return ref.toString() in this.dict;
  8313. },
  8314. put: function RefSet_put(ref) {
  8315. this.dict[ref.toString()] = true;
  8316. },
  8317. remove: function RefSet_remove(ref) {
  8318. delete this.dict[ref.toString()];
  8319. }
  8320. };
  8321. return RefSet;
  8322. })();
  8323. var RefSetCache = (function RefSetCacheClosure() {
  8324. function RefSetCache() {
  8325. this.dict = Object.create(null);
  8326. }
  8327. RefSetCache.prototype = {
  8328. get: function RefSetCache_get(ref) {
  8329. return this.dict[ref.toString()];
  8330. },
  8331. has: function RefSetCache_has(ref) {
  8332. return ref.toString() in this.dict;
  8333. },
  8334. put: function RefSetCache_put(ref, obj) {
  8335. this.dict[ref.toString()] = obj;
  8336. },
  8337. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8338. this.dict[ref.toString()] = this.get(aliasRef);
  8339. },
  8340. forEach: function RefSetCache_forEach(fn, thisArg) {
  8341. for (var i in this.dict) {
  8342. fn.call(thisArg, this.dict[i]);
  8343. }
  8344. },
  8345. clear: function RefSetCache_clear() {
  8346. this.dict = Object.create(null);
  8347. }
  8348. };
  8349. return RefSetCache;
  8350. })();
  8351. var Catalog = (function CatalogClosure() {
  8352. function Catalog(pdfManager, xref) {
  8353. this.pdfManager = pdfManager;
  8354. this.xref = xref;
  8355. this.catDict = xref.getCatalogObj();
  8356. this.fontCache = new RefSetCache();
  8357. assert(isDict(this.catDict),
  8358. 'catalog object is not a dictionary');
  8359. this.pagePromises = [];
  8360. }
  8361. Catalog.prototype = {
  8362. get metadata() {
  8363. var streamRef = this.catDict.getRaw('Metadata');
  8364. if (!isRef(streamRef)) {
  8365. return shadow(this, 'metadata', null);
  8366. }
  8367. var encryptMetadata = (!this.xref.encrypt ? false :
  8368. this.xref.encrypt.encryptMetadata);
  8369. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8370. var metadata;
  8371. if (stream && isDict(stream.dict)) {
  8372. var type = stream.dict.get('Type');
  8373. var subtype = stream.dict.get('Subtype');
  8374. if (isName(type) && isName(subtype) &&
  8375. type.name === 'Metadata' && subtype.name === 'XML') {
  8376. // XXX: This should examine the charset the XML document defines,
  8377. // however since there are currently no real means to decode
  8378. // arbitrary charsets, let's just hope that the author of the PDF
  8379. // was reasonable enough to stick with the XML default charset,
  8380. // which is UTF-8.
  8381. try {
  8382. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8383. } catch (e) {
  8384. info('Skipping invalid metadata.');
  8385. }
  8386. }
  8387. }
  8388. return shadow(this, 'metadata', metadata);
  8389. },
  8390. get toplevelPagesDict() {
  8391. var pagesObj = this.catDict.get('Pages');
  8392. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8393. // shadow the prototype getter
  8394. return shadow(this, 'toplevelPagesDict', pagesObj);
  8395. },
  8396. get documentOutline() {
  8397. var obj = null;
  8398. try {
  8399. obj = this.readDocumentOutline();
  8400. } catch (ex) {
  8401. if (ex instanceof MissingDataException) {
  8402. throw ex;
  8403. }
  8404. warn('Unable to read document outline');
  8405. }
  8406. return shadow(this, 'documentOutline', obj);
  8407. },
  8408. readDocumentOutline: function Catalog_readDocumentOutline() {
  8409. var xref = this.xref;
  8410. var obj = this.catDict.get('Outlines');
  8411. var root = { items: [] };
  8412. if (isDict(obj)) {
  8413. obj = obj.getRaw('First');
  8414. var processed = new RefSet();
  8415. if (isRef(obj)) {
  8416. var queue = [{obj: obj, parent: root}];
  8417. // to avoid recursion keeping track of the items
  8418. // in the processed dictionary
  8419. processed.put(obj);
  8420. while (queue.length > 0) {
  8421. var i = queue.shift();
  8422. var outlineDict = xref.fetchIfRef(i.obj);
  8423. if (outlineDict === null) {
  8424. continue;
  8425. }
  8426. if (!outlineDict.has('Title')) {
  8427. error('Invalid outline item');
  8428. }
  8429. var dest = outlineDict.get('A');
  8430. if (dest) {
  8431. dest = dest.get('D');
  8432. } else if (outlineDict.has('Dest')) {
  8433. dest = outlineDict.getRaw('Dest');
  8434. if (isName(dest)) {
  8435. dest = dest.name;
  8436. }
  8437. }
  8438. var title = outlineDict.get('Title');
  8439. var outlineItem = {
  8440. dest: dest,
  8441. title: stringToPDFString(title),
  8442. color: outlineDict.get('C') || [0, 0, 0],
  8443. count: outlineDict.get('Count'),
  8444. bold: !!(outlineDict.get('F') & 2),
  8445. italic: !!(outlineDict.get('F') & 1),
  8446. items: []
  8447. };
  8448. i.parent.items.push(outlineItem);
  8449. obj = outlineDict.getRaw('First');
  8450. if (isRef(obj) && !processed.has(obj)) {
  8451. queue.push({obj: obj, parent: outlineItem});
  8452. processed.put(obj);
  8453. }
  8454. obj = outlineDict.getRaw('Next');
  8455. if (isRef(obj) && !processed.has(obj)) {
  8456. queue.push({obj: obj, parent: i.parent});
  8457. processed.put(obj);
  8458. }
  8459. }
  8460. }
  8461. }
  8462. return (root.items.length > 0 ? root.items : null);
  8463. },
  8464. get numPages() {
  8465. var obj = this.toplevelPagesDict.get('Count');
  8466. assert(
  8467. isInt(obj),
  8468. 'page count in top level pages object is not an integer'
  8469. );
  8470. // shadow the prototype getter
  8471. return shadow(this, 'num', obj);
  8472. },
  8473. get destinations() {
  8474. function fetchDestination(dest) {
  8475. return isDict(dest) ? dest.get('D') : dest;
  8476. }
  8477. var xref = this.xref;
  8478. var dests = {}, nameTreeRef, nameDictionaryRef;
  8479. var obj = this.catDict.get('Names');
  8480. if (obj && obj.has('Dests')) {
  8481. nameTreeRef = obj.getRaw('Dests');
  8482. } else if (this.catDict.has('Dests')) {
  8483. nameDictionaryRef = this.catDict.get('Dests');
  8484. }
  8485. if (nameDictionaryRef) {
  8486. // reading simple destination dictionary
  8487. obj = nameDictionaryRef;
  8488. obj.forEach(function catalogForEach(key, value) {
  8489. if (!value) {
  8490. return;
  8491. }
  8492. dests[key] = fetchDestination(value);
  8493. });
  8494. }
  8495. if (nameTreeRef) {
  8496. var nameTree = new NameTree(nameTreeRef, xref);
  8497. var names = nameTree.getAll();
  8498. for (var name in names) {
  8499. if (!names.hasOwnProperty(name)) {
  8500. continue;
  8501. }
  8502. dests[name] = fetchDestination(names[name]);
  8503. }
  8504. }
  8505. return shadow(this, 'destinations', dests);
  8506. },
  8507. get attachments() {
  8508. var xref = this.xref;
  8509. var attachments = null, nameTreeRef;
  8510. var obj = this.catDict.get('Names');
  8511. if (obj) {
  8512. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8513. }
  8514. if (nameTreeRef) {
  8515. var nameTree = new NameTree(nameTreeRef, xref);
  8516. var names = nameTree.getAll();
  8517. for (var name in names) {
  8518. if (!names.hasOwnProperty(name)) {
  8519. continue;
  8520. }
  8521. var fs = new FileSpec(names[name], xref);
  8522. if (!attachments) {
  8523. attachments = {};
  8524. }
  8525. attachments[stringToPDFString(name)] = fs.serializable;
  8526. }
  8527. }
  8528. return shadow(this, 'attachments', attachments);
  8529. },
  8530. get javaScript() {
  8531. var xref = this.xref;
  8532. var obj = this.catDict.get('Names');
  8533. var javaScript = [];
  8534. if (obj && obj.has('JavaScript')) {
  8535. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8536. var names = nameTree.getAll();
  8537. for (var name in names) {
  8538. if (!names.hasOwnProperty(name)) {
  8539. continue;
  8540. }
  8541. // We don't really use the JavaScript right now. This code is
  8542. // defensive so we don't cause errors on document load.
  8543. var jsDict = names[name];
  8544. if (!isDict(jsDict)) {
  8545. continue;
  8546. }
  8547. var type = jsDict.get('S');
  8548. if (!isName(type) || type.name !== 'JavaScript') {
  8549. continue;
  8550. }
  8551. var js = jsDict.get('JS');
  8552. if (!isString(js) && !isStream(js)) {
  8553. continue;
  8554. }
  8555. if (isStream(js)) {
  8556. js = bytesToString(js.getBytes());
  8557. }
  8558. javaScript.push(stringToPDFString(js));
  8559. }
  8560. }
  8561. // Append OpenAction actions to javaScript array
  8562. var openactionDict = this.catDict.get('OpenAction');
  8563. if (isDict(openactionDict)) {
  8564. var objType = openactionDict.get('Type');
  8565. var actionType = openactionDict.get('S');
  8566. var action = openactionDict.get('N');
  8567. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8568. isName(actionType) && actionType.name === 'Named' &&
  8569. isName(action) && action.name === 'Print');
  8570. if (isPrintAction) {
  8571. javaScript.push('print(true);');
  8572. }
  8573. }
  8574. return shadow(this, 'javaScript', javaScript);
  8575. },
  8576. cleanup: function Catalog_cleanup() {
  8577. var promises = [];
  8578. this.fontCache.forEach(function (promise) {
  8579. promises.push(promise);
  8580. });
  8581. return Promise.all(promises).then(function (translatedFonts) {
  8582. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8583. var font = translatedFonts[i].dict;
  8584. delete font.translated;
  8585. }
  8586. this.fontCache.clear();
  8587. }.bind(this));
  8588. },
  8589. getPage: function Catalog_getPage(pageIndex) {
  8590. if (!(pageIndex in this.pagePromises)) {
  8591. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8592. function (a) {
  8593. var dict = a[0];
  8594. var ref = a[1];
  8595. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8596. this.fontCache);
  8597. }.bind(this)
  8598. );
  8599. }
  8600. return this.pagePromises[pageIndex];
  8601. },
  8602. getPageDict: function Catalog_getPageDict(pageIndex) {
  8603. var capability = createPromiseCapability();
  8604. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8605. var currentPageIndex = 0;
  8606. var xref = this.xref;
  8607. function next() {
  8608. while (nodesToVisit.length) {
  8609. var currentNode = nodesToVisit.pop();
  8610. if (isRef(currentNode)) {
  8611. xref.fetchAsync(currentNode).then(function (obj) {
  8612. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8613. if (pageIndex === currentPageIndex) {
  8614. capability.resolve([obj, currentNode]);
  8615. } else {
  8616. currentPageIndex++;
  8617. next();
  8618. }
  8619. return;
  8620. }
  8621. nodesToVisit.push(obj);
  8622. next();
  8623. }, capability.reject);
  8624. return;
  8625. }
  8626. // must be a child page dictionary
  8627. assert(
  8628. isDict(currentNode),
  8629. 'page dictionary kid reference points to wrong type of object'
  8630. );
  8631. var count = currentNode.get('Count');
  8632. // Skip nodes where the page can't be.
  8633. if (currentPageIndex + count <= pageIndex) {
  8634. currentPageIndex += count;
  8635. continue;
  8636. }
  8637. var kids = currentNode.get('Kids');
  8638. assert(isArray(kids), 'page dictionary kids object is not an array');
  8639. if (count === kids.length) {
  8640. // Nodes that don't have the page have been skipped and this is the
  8641. // bottom of the tree which means the page requested must be a
  8642. // descendant of this pages node. Ideally we would just resolve the
  8643. // promise with the page ref here, but there is the case where more
  8644. // pages nodes could link to single a page (see issue 3666 pdf). To
  8645. // handle this push it back on the queue so if it is a pages node it
  8646. // will be descended into.
  8647. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8648. currentPageIndex = pageIndex;
  8649. continue;
  8650. } else {
  8651. for (var last = kids.length - 1; last >= 0; last--) {
  8652. nodesToVisit.push(kids[last]);
  8653. }
  8654. }
  8655. }
  8656. capability.reject('Page index ' + pageIndex + ' not found.');
  8657. }
  8658. next();
  8659. return capability.promise;
  8660. },
  8661. getPageIndex: function Catalog_getPageIndex(ref) {
  8662. // The page tree nodes have the count of all the leaves below them. To get
  8663. // how many pages are before we just have to walk up the tree and keep
  8664. // adding the count of siblings to the left of the node.
  8665. var xref = this.xref;
  8666. function pagesBeforeRef(kidRef) {
  8667. var total = 0;
  8668. var parentRef;
  8669. return xref.fetchAsync(kidRef).then(function (node) {
  8670. if (!node) {
  8671. return null;
  8672. }
  8673. parentRef = node.getRaw('Parent');
  8674. return node.getAsync('Parent');
  8675. }).then(function (parent) {
  8676. if (!parent) {
  8677. return null;
  8678. }
  8679. return parent.getAsync('Kids');
  8680. }).then(function (kids) {
  8681. if (!kids) {
  8682. return null;
  8683. }
  8684. var kidPromises = [];
  8685. var found = false;
  8686. for (var i = 0; i < kids.length; i++) {
  8687. var kid = kids[i];
  8688. assert(isRef(kid), 'kids must be a ref');
  8689. if (kid.num === kidRef.num) {
  8690. found = true;
  8691. break;
  8692. }
  8693. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8694. if (kid.has('Count')) {
  8695. var count = kid.get('Count');
  8696. total += count;
  8697. } else { // page leaf node
  8698. total++;
  8699. }
  8700. }));
  8701. }
  8702. if (!found) {
  8703. error('kid ref not found in parents kids');
  8704. }
  8705. return Promise.all(kidPromises).then(function () {
  8706. return [total, parentRef];
  8707. });
  8708. });
  8709. }
  8710. var total = 0;
  8711. function next(ref) {
  8712. return pagesBeforeRef(ref).then(function (args) {
  8713. if (!args) {
  8714. return total;
  8715. }
  8716. var count = args[0];
  8717. var parentRef = args[1];
  8718. total += count;
  8719. return next(parentRef);
  8720. });
  8721. }
  8722. return next(ref);
  8723. }
  8724. };
  8725. return Catalog;
  8726. })();
  8727. var XRef = (function XRefClosure() {
  8728. function XRef(stream, password) {
  8729. this.stream = stream;
  8730. this.entries = [];
  8731. this.xrefstms = {};
  8732. // prepare the XRef cache
  8733. this.cache = [];
  8734. this.password = password;
  8735. this.stats = {
  8736. streamTypes: [],
  8737. fontTypes: []
  8738. };
  8739. }
  8740. XRef.prototype = {
  8741. setStartXRef: function XRef_setStartXRef(startXRef) {
  8742. // Store the starting positions of xref tables as we process them
  8743. // so we can recover from missing data errors
  8744. this.startXRefQueue = [startXRef];
  8745. },
  8746. parse: function XRef_parse(recoveryMode) {
  8747. var trailerDict;
  8748. if (!recoveryMode) {
  8749. trailerDict = this.readXRef();
  8750. } else {
  8751. warn('Indexing all PDF objects');
  8752. trailerDict = this.indexObjects();
  8753. }
  8754. trailerDict.assignXref(this);
  8755. this.trailer = trailerDict;
  8756. var encrypt = trailerDict.get('Encrypt');
  8757. if (encrypt) {
  8758. var ids = trailerDict.get('ID');
  8759. var fileId = (ids && ids.length) ? ids[0] : '';
  8760. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  8761. this.password);
  8762. }
  8763. // get the root dictionary (catalog) object
  8764. if (!(this.root = trailerDict.get('Root'))) {
  8765. error('Invalid root reference');
  8766. }
  8767. },
  8768. processXRefTable: function XRef_processXRefTable(parser) {
  8769. if (!('tableState' in this)) {
  8770. // Stores state of the table as we process it so we can resume
  8771. // from middle of table in case of missing data error
  8772. this.tableState = {
  8773. entryNum: 0,
  8774. streamPos: parser.lexer.stream.pos,
  8775. parserBuf1: parser.buf1,
  8776. parserBuf2: parser.buf2
  8777. };
  8778. }
  8779. var obj = this.readXRefTable(parser);
  8780. // Sanity check
  8781. if (!isCmd(obj, 'trailer')) {
  8782. error('Invalid XRef table: could not find trailer dictionary');
  8783. }
  8784. // Read trailer dictionary, e.g.
  8785. // trailer
  8786. // << /Size 22
  8787. // /Root 20R
  8788. // /Info 10R
  8789. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  8790. // >>
  8791. // The parser goes through the entire stream << ... >> and provides
  8792. // a getter interface for the key-value table
  8793. var dict = parser.getObj();
  8794. // The pdflib PDF generator can generate a nested trailer dictionary
  8795. if (!isDict(dict) && dict.dict) {
  8796. dict = dict.dict;
  8797. }
  8798. if (!isDict(dict)) {
  8799. error('Invalid XRef table: could not parse trailer dictionary');
  8800. }
  8801. delete this.tableState;
  8802. return dict;
  8803. },
  8804. readXRefTable: function XRef_readXRefTable(parser) {
  8805. // Example of cross-reference table:
  8806. // xref
  8807. // 0 1 <-- subsection header (first obj #, obj count)
  8808. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  8809. // 23 2 <-- subsection header ... and so on ...
  8810. // 0000025518 00002 n
  8811. // 0000025635 00000 n
  8812. // trailer
  8813. // ...
  8814. var stream = parser.lexer.stream;
  8815. var tableState = this.tableState;
  8816. stream.pos = tableState.streamPos;
  8817. parser.buf1 = tableState.parserBuf1;
  8818. parser.buf2 = tableState.parserBuf2;
  8819. // Outer loop is over subsection headers
  8820. var obj;
  8821. while (true) {
  8822. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  8823. if (isCmd(obj = parser.getObj(), 'trailer')) {
  8824. break;
  8825. }
  8826. tableState.firstEntryNum = obj;
  8827. tableState.entryCount = parser.getObj();
  8828. }
  8829. var first = tableState.firstEntryNum;
  8830. var count = tableState.entryCount;
  8831. if (!isInt(first) || !isInt(count)) {
  8832. error('Invalid XRef table: wrong types in subsection header');
  8833. }
  8834. // Inner loop is over objects themselves
  8835. for (var i = tableState.entryNum; i < count; i++) {
  8836. tableState.streamPos = stream.pos;
  8837. tableState.entryNum = i;
  8838. tableState.parserBuf1 = parser.buf1;
  8839. tableState.parserBuf2 = parser.buf2;
  8840. var entry = {};
  8841. entry.offset = parser.getObj();
  8842. entry.gen = parser.getObj();
  8843. var type = parser.getObj();
  8844. if (isCmd(type, 'f')) {
  8845. entry.free = true;
  8846. } else if (isCmd(type, 'n')) {
  8847. entry.uncompressed = true;
  8848. }
  8849. // Validate entry obj
  8850. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  8851. !(entry.free || entry.uncompressed)) {
  8852. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  8853. }
  8854. if (!this.entries[i + first]) {
  8855. this.entries[i + first] = entry;
  8856. }
  8857. }
  8858. tableState.entryNum = 0;
  8859. tableState.streamPos = stream.pos;
  8860. tableState.parserBuf1 = parser.buf1;
  8861. tableState.parserBuf2 = parser.buf2;
  8862. delete tableState.firstEntryNum;
  8863. delete tableState.entryCount;
  8864. }
  8865. // Per issue 3248: hp scanners generate bad XRef
  8866. if (first === 1 && this.entries[1] && this.entries[1].free) {
  8867. // shifting the entries
  8868. this.entries.shift();
  8869. }
  8870. // Sanity check: as per spec, first object must be free
  8871. if (this.entries[0] && !this.entries[0].free) {
  8872. error('Invalid XRef table: unexpected first object');
  8873. }
  8874. return obj;
  8875. },
  8876. processXRefStream: function XRef_processXRefStream(stream) {
  8877. if (!('streamState' in this)) {
  8878. // Stores state of the stream as we process it so we can resume
  8879. // from middle of stream in case of missing data error
  8880. var streamParameters = stream.dict;
  8881. var byteWidths = streamParameters.get('W');
  8882. var range = streamParameters.get('Index');
  8883. if (!range) {
  8884. range = [0, streamParameters.get('Size')];
  8885. }
  8886. this.streamState = {
  8887. entryRanges: range,
  8888. byteWidths: byteWidths,
  8889. entryNum: 0,
  8890. streamPos: stream.pos
  8891. };
  8892. }
  8893. this.readXRefStream(stream);
  8894. delete this.streamState;
  8895. return stream.dict;
  8896. },
  8897. readXRefStream: function XRef_readXRefStream(stream) {
  8898. var i, j;
  8899. var streamState = this.streamState;
  8900. stream.pos = streamState.streamPos;
  8901. var byteWidths = streamState.byteWidths;
  8902. var typeFieldWidth = byteWidths[0];
  8903. var offsetFieldWidth = byteWidths[1];
  8904. var generationFieldWidth = byteWidths[2];
  8905. var entryRanges = streamState.entryRanges;
  8906. while (entryRanges.length > 0) {
  8907. var first = entryRanges[0];
  8908. var n = entryRanges[1];
  8909. if (!isInt(first) || !isInt(n)) {
  8910. error('Invalid XRef range fields: ' + first + ', ' + n);
  8911. }
  8912. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  8913. !isInt(generationFieldWidth)) {
  8914. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  8915. }
  8916. for (i = streamState.entryNum; i < n; ++i) {
  8917. streamState.entryNum = i;
  8918. streamState.streamPos = stream.pos;
  8919. var type = 0, offset = 0, generation = 0;
  8920. for (j = 0; j < typeFieldWidth; ++j) {
  8921. type = (type << 8) | stream.getByte();
  8922. }
  8923. // if type field is absent, its default value is 1
  8924. if (typeFieldWidth === 0) {
  8925. type = 1;
  8926. }
  8927. for (j = 0; j < offsetFieldWidth; ++j) {
  8928. offset = (offset << 8) | stream.getByte();
  8929. }
  8930. for (j = 0; j < generationFieldWidth; ++j) {
  8931. generation = (generation << 8) | stream.getByte();
  8932. }
  8933. var entry = {};
  8934. entry.offset = offset;
  8935. entry.gen = generation;
  8936. switch (type) {
  8937. case 0:
  8938. entry.free = true;
  8939. break;
  8940. case 1:
  8941. entry.uncompressed = true;
  8942. break;
  8943. case 2:
  8944. break;
  8945. default:
  8946. error('Invalid XRef entry type: ' + type);
  8947. }
  8948. if (!this.entries[first + i]) {
  8949. this.entries[first + i] = entry;
  8950. }
  8951. }
  8952. streamState.entryNum = 0;
  8953. streamState.streamPos = stream.pos;
  8954. entryRanges.splice(0, 2);
  8955. }
  8956. },
  8957. indexObjects: function XRef_indexObjects() {
  8958. // Simple scan through the PDF content to find objects,
  8959. // trailers and XRef streams.
  8960. function readToken(data, offset) {
  8961. var token = '', ch = data[offset];
  8962. while (ch !== 13 && ch !== 10) {
  8963. if (++offset >= data.length) {
  8964. break;
  8965. }
  8966. token += String.fromCharCode(ch);
  8967. ch = data[offset];
  8968. }
  8969. return token;
  8970. }
  8971. function skipUntil(data, offset, what) {
  8972. var length = what.length, dataLength = data.length;
  8973. var skipped = 0;
  8974. // finding byte sequence
  8975. while (offset < dataLength) {
  8976. var i = 0;
  8977. while (i < length && data[offset + i] === what[i]) {
  8978. ++i;
  8979. }
  8980. if (i >= length) {
  8981. break; // sequence found
  8982. }
  8983. offset++;
  8984. skipped++;
  8985. }
  8986. return skipped;
  8987. }
  8988. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  8989. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  8990. 101, 102]);
  8991. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  8992. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  8993. var stream = this.stream;
  8994. stream.pos = 0;
  8995. var buffer = stream.getBytes();
  8996. var position = stream.start, length = buffer.length;
  8997. var trailers = [], xrefStms = [];
  8998. while (position < length) {
  8999. var ch = buffer[position];
  9000. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9001. ++position;
  9002. continue;
  9003. }
  9004. if (ch === 37) { // %-comment
  9005. do {
  9006. ++position;
  9007. if (position >= length) {
  9008. break;
  9009. }
  9010. ch = buffer[position];
  9011. } while (ch !== 13 && ch !== 10);
  9012. continue;
  9013. }
  9014. var token = readToken(buffer, position);
  9015. var m;
  9016. if (token === 'xref') {
  9017. position += skipUntil(buffer, position, trailerBytes);
  9018. trailers.push(position);
  9019. position += skipUntil(buffer, position, startxrefBytes);
  9020. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9021. this.entries[m[1]] = {
  9022. offset: position,
  9023. gen: m[2] | 0,
  9024. uncompressed: true
  9025. };
  9026. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9027. var content = buffer.subarray(position, position + contentLength);
  9028. // checking XRef stream suspect
  9029. // (it shall have '/XRef' and next char is not a letter)
  9030. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9031. if (xrefTagOffset < contentLength &&
  9032. content[xrefTagOffset + 5] < 64) {
  9033. xrefStms.push(position);
  9034. this.xrefstms[position] = 1; // don't read it recursively
  9035. }
  9036. position += contentLength;
  9037. } else {
  9038. position += token.length + 1;
  9039. }
  9040. }
  9041. // reading XRef streams
  9042. var i, ii;
  9043. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9044. this.startXRefQueue.push(xrefStms[i]);
  9045. this.readXRef(/* recoveryMode */ true);
  9046. }
  9047. // finding main trailer
  9048. var dict;
  9049. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9050. stream.pos = trailers[i];
  9051. var parser = new Parser(new Lexer(stream), true, this);
  9052. var obj = parser.getObj();
  9053. if (!isCmd(obj, 'trailer')) {
  9054. continue;
  9055. }
  9056. // read the trailer dictionary
  9057. if (!isDict(dict = parser.getObj())) {
  9058. continue;
  9059. }
  9060. // taking the first one with 'ID'
  9061. if (dict.has('ID')) {
  9062. return dict;
  9063. }
  9064. }
  9065. // no tailer with 'ID', taking last one (if exists)
  9066. if (dict) {
  9067. return dict;
  9068. }
  9069. // nothing helps
  9070. // calling error() would reject worker with an UnknownErrorException.
  9071. throw new InvalidPDFException('Invalid PDF structure');
  9072. },
  9073. readXRef: function XRef_readXRef(recoveryMode) {
  9074. var stream = this.stream;
  9075. try {
  9076. while (this.startXRefQueue.length) {
  9077. var startXRef = this.startXRefQueue[0];
  9078. stream.pos = startXRef + stream.start;
  9079. var parser = new Parser(new Lexer(stream), true, this);
  9080. var obj = parser.getObj();
  9081. var dict;
  9082. // Get dictionary
  9083. if (isCmd(obj, 'xref')) {
  9084. // Parse end-of-file XRef
  9085. dict = this.processXRefTable(parser);
  9086. if (!this.topDict) {
  9087. this.topDict = dict;
  9088. }
  9089. // Recursively get other XRefs 'XRefStm', if any
  9090. obj = dict.get('XRefStm');
  9091. if (isInt(obj)) {
  9092. var pos = obj;
  9093. // ignore previously loaded xref streams
  9094. // (possible infinite recursion)
  9095. if (!(pos in this.xrefstms)) {
  9096. this.xrefstms[pos] = 1;
  9097. this.startXRefQueue.push(pos);
  9098. }
  9099. }
  9100. } else if (isInt(obj)) {
  9101. // Parse in-stream XRef
  9102. if (!isInt(parser.getObj()) ||
  9103. !isCmd(parser.getObj(), 'obj') ||
  9104. !isStream(obj = parser.getObj())) {
  9105. error('Invalid XRef stream');
  9106. }
  9107. dict = this.processXRefStream(obj);
  9108. if (!this.topDict) {
  9109. this.topDict = dict;
  9110. }
  9111. if (!dict) {
  9112. error('Failed to read XRef stream');
  9113. }
  9114. } else {
  9115. error('Invalid XRef stream header');
  9116. }
  9117. // Recursively get previous dictionary, if any
  9118. obj = dict.get('Prev');
  9119. if (isInt(obj)) {
  9120. this.startXRefQueue.push(obj);
  9121. } else if (isRef(obj)) {
  9122. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9123. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9124. this.startXRefQueue.push(obj.num);
  9125. }
  9126. this.startXRefQueue.shift();
  9127. }
  9128. return this.topDict;
  9129. } catch (e) {
  9130. if (e instanceof MissingDataException) {
  9131. throw e;
  9132. }
  9133. info('(while reading XRef): ' + e);
  9134. }
  9135. if (recoveryMode) {
  9136. return;
  9137. }
  9138. throw new XRefParseException();
  9139. },
  9140. getEntry: function XRef_getEntry(i) {
  9141. var xrefEntry = this.entries[i];
  9142. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9143. return xrefEntry;
  9144. }
  9145. return null;
  9146. },
  9147. fetchIfRef: function XRef_fetchIfRef(obj) {
  9148. if (!isRef(obj)) {
  9149. return obj;
  9150. }
  9151. return this.fetch(obj);
  9152. },
  9153. fetch: function XRef_fetch(ref, suppressEncryption) {
  9154. assert(isRef(ref), 'ref object is not a reference');
  9155. var num = ref.num;
  9156. if (num in this.cache) {
  9157. var cacheEntry = this.cache[num];
  9158. return cacheEntry;
  9159. }
  9160. var xrefEntry = this.getEntry(num);
  9161. // the referenced entry can be free
  9162. if (xrefEntry === null) {
  9163. return (this.cache[num] = null);
  9164. }
  9165. if (xrefEntry.uncompressed) {
  9166. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9167. } else {
  9168. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9169. }
  9170. if (isDict(xrefEntry)){
  9171. xrefEntry.objId = ref.toString();
  9172. } else if (isStream(xrefEntry)) {
  9173. xrefEntry.dict.objId = ref.toString();
  9174. }
  9175. return xrefEntry;
  9176. },
  9177. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9178. suppressEncryption) {
  9179. var gen = ref.gen;
  9180. var num = ref.num;
  9181. if (xrefEntry.gen !== gen) {
  9182. error('inconsistent generation in XRef');
  9183. }
  9184. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9185. this.stream.start);
  9186. var parser = new Parser(new Lexer(stream), true, this);
  9187. var obj1 = parser.getObj();
  9188. var obj2 = parser.getObj();
  9189. var obj3 = parser.getObj();
  9190. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9191. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9192. !isCmd(obj3)) {
  9193. error('bad XRef entry');
  9194. }
  9195. if (!isCmd(obj3, 'obj')) {
  9196. // some bad PDFs use "obj1234" and really mean 1234
  9197. if (obj3.cmd.indexOf('obj') === 0) {
  9198. num = parseInt(obj3.cmd.substring(3), 10);
  9199. if (!isNaN(num)) {
  9200. return num;
  9201. }
  9202. }
  9203. error('bad XRef entry');
  9204. }
  9205. if (this.encrypt && !suppressEncryption) {
  9206. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9207. } else {
  9208. xrefEntry = parser.getObj();
  9209. }
  9210. if (!isStream(xrefEntry)) {
  9211. this.cache[num] = xrefEntry;
  9212. }
  9213. return xrefEntry;
  9214. },
  9215. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9216. suppressEncryption) {
  9217. var tableOffset = xrefEntry.offset;
  9218. var stream = this.fetch(new Ref(tableOffset, 0));
  9219. if (!isStream(stream)) {
  9220. error('bad ObjStm stream');
  9221. }
  9222. var first = stream.dict.get('First');
  9223. var n = stream.dict.get('N');
  9224. if (!isInt(first) || !isInt(n)) {
  9225. error('invalid first and n parameters for ObjStm stream');
  9226. }
  9227. var parser = new Parser(new Lexer(stream), false, this);
  9228. parser.allowStreams = true;
  9229. var i, entries = [], num, nums = [];
  9230. // read the object numbers to populate cache
  9231. for (i = 0; i < n; ++i) {
  9232. num = parser.getObj();
  9233. if (!isInt(num)) {
  9234. error('invalid object number in the ObjStm stream: ' + num);
  9235. }
  9236. nums.push(num);
  9237. var offset = parser.getObj();
  9238. if (!isInt(offset)) {
  9239. error('invalid object offset in the ObjStm stream: ' + offset);
  9240. }
  9241. }
  9242. // read stream objects for cache
  9243. for (i = 0; i < n; ++i) {
  9244. entries.push(parser.getObj());
  9245. num = nums[i];
  9246. var entry = this.entries[num];
  9247. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9248. this.cache[num] = entries[i];
  9249. }
  9250. }
  9251. xrefEntry = entries[xrefEntry.gen];
  9252. if (xrefEntry === undefined) {
  9253. error('bad XRef entry for compressed object');
  9254. }
  9255. return xrefEntry;
  9256. },
  9257. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9258. if (!isRef(obj)) {
  9259. return Promise.resolve(obj);
  9260. }
  9261. return this.fetchAsync(obj);
  9262. },
  9263. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9264. var streamManager = this.stream.manager;
  9265. var xref = this;
  9266. return new Promise(function tryFetch(resolve, reject) {
  9267. try {
  9268. resolve(xref.fetch(ref, suppressEncryption));
  9269. } catch (e) {
  9270. if (e instanceof MissingDataException) {
  9271. streamManager.requestRange(e.begin, e.end, function () {
  9272. tryFetch(resolve, reject);
  9273. });
  9274. return;
  9275. }
  9276. reject(e);
  9277. }
  9278. });
  9279. },
  9280. getCatalogObj: function XRef_getCatalogObj() {
  9281. return this.root;
  9282. }
  9283. };
  9284. return XRef;
  9285. })();
  9286. /**
  9287. * A NameTree is like a Dict but has some advantageous properties, see the
  9288. * spec (7.9.6) for more details.
  9289. * TODO: implement all the Dict functions and make this more efficent.
  9290. */
  9291. var NameTree = (function NameTreeClosure() {
  9292. function NameTree(root, xref) {
  9293. this.root = root;
  9294. this.xref = xref;
  9295. }
  9296. NameTree.prototype = {
  9297. getAll: function NameTree_getAll() {
  9298. var dict = {};
  9299. if (!this.root) {
  9300. return dict;
  9301. }
  9302. var xref = this.xref;
  9303. // reading name tree
  9304. var processed = new RefSet();
  9305. processed.put(this.root);
  9306. var queue = [this.root];
  9307. while (queue.length > 0) {
  9308. var i, n;
  9309. var obj = xref.fetchIfRef(queue.shift());
  9310. if (!isDict(obj)) {
  9311. continue;
  9312. }
  9313. if (obj.has('Kids')) {
  9314. var kids = obj.get('Kids');
  9315. for (i = 0, n = kids.length; i < n; i++) {
  9316. var kid = kids[i];
  9317. if (processed.has(kid)) {
  9318. error('invalid destinations');
  9319. }
  9320. queue.push(kid);
  9321. processed.put(kid);
  9322. }
  9323. continue;
  9324. }
  9325. var names = obj.get('Names');
  9326. if (names) {
  9327. for (i = 0, n = names.length; i < n; i += 2) {
  9328. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9329. }
  9330. }
  9331. }
  9332. return dict;
  9333. }
  9334. };
  9335. return NameTree;
  9336. })();
  9337. /**
  9338. * "A PDF file can refer to the contents of another file by using a File
  9339. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9340. * NOTE: Only embedded files are supported (as part of the attachments support)
  9341. * TODO: support the 'URL' file system (with caching if !/V), portable
  9342. * collections attributes and related files (/RF)
  9343. */
  9344. var FileSpec = (function FileSpecClosure() {
  9345. function FileSpec(root, xref) {
  9346. if (!root || !isDict(root)) {
  9347. return;
  9348. }
  9349. this.xref = xref;
  9350. this.root = root;
  9351. if (root.has('FS')) {
  9352. this.fs = root.get('FS');
  9353. }
  9354. this.description = root.has('Desc') ?
  9355. stringToPDFString(root.get('Desc')) :
  9356. '';
  9357. if (root.has('RF')) {
  9358. warn('Related file specifications are not supported');
  9359. }
  9360. this.contentAvailable = true;
  9361. if (!root.has('EF')) {
  9362. this.contentAvailable = false;
  9363. warn('Non-embedded file specifications are not supported');
  9364. }
  9365. }
  9366. function pickPlatformItem(dict) {
  9367. // Look for the filename in this order:
  9368. // UF, F, Unix, Mac, DOS
  9369. if (dict.has('UF')) {
  9370. return dict.get('UF');
  9371. } else if (dict.has('F')) {
  9372. return dict.get('F');
  9373. } else if (dict.has('Unix')) {
  9374. return dict.get('Unix');
  9375. } else if (dict.has('Mac')) {
  9376. return dict.get('Mac');
  9377. } else if (dict.has('DOS')) {
  9378. return dict.get('DOS');
  9379. } else {
  9380. return null;
  9381. }
  9382. }
  9383. FileSpec.prototype = {
  9384. get filename() {
  9385. if (!this._filename && this.root) {
  9386. var filename = pickPlatformItem(this.root) || 'unnamed';
  9387. this._filename = stringToPDFString(filename).
  9388. replace(/\\\\/g, '\\').
  9389. replace(/\\\//g, '/').
  9390. replace(/\\/g, '/');
  9391. }
  9392. return this._filename;
  9393. },
  9394. get content() {
  9395. if (!this.contentAvailable) {
  9396. return null;
  9397. }
  9398. if (!this.contentRef && this.root) {
  9399. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9400. }
  9401. var content = null;
  9402. if (this.contentRef) {
  9403. var xref = this.xref;
  9404. var fileObj = xref.fetchIfRef(this.contentRef);
  9405. if (fileObj && isStream(fileObj)) {
  9406. content = fileObj.getBytes();
  9407. } else {
  9408. warn('Embedded file specification points to non-existing/invalid ' +
  9409. 'content');
  9410. }
  9411. } else {
  9412. warn('Embedded file specification does not have a content');
  9413. }
  9414. return content;
  9415. },
  9416. get serializable() {
  9417. return {
  9418. filename: this.filename,
  9419. content: this.content
  9420. };
  9421. }
  9422. };
  9423. return FileSpec;
  9424. })();
  9425. /**
  9426. * A helper for loading missing data in object graphs. It traverses the graph
  9427. * depth first and queues up any objects that have missing data. Once it has
  9428. * has traversed as many objects that are available it attempts to bundle the
  9429. * missing data requests and then resume from the nodes that weren't ready.
  9430. *
  9431. * NOTE: It provides protection from circular references by keeping track of
  9432. * of loaded references. However, you must be careful not to load any graphs
  9433. * that have references to the catalog or other pages since that will cause the
  9434. * entire PDF document object graph to be traversed.
  9435. */
  9436. var ObjectLoader = (function() {
  9437. function mayHaveChildren(value) {
  9438. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9439. }
  9440. function addChildren(node, nodesToVisit) {
  9441. var value;
  9442. if (isDict(node) || isStream(node)) {
  9443. var map;
  9444. if (isDict(node)) {
  9445. map = node.map;
  9446. } else {
  9447. map = node.dict.map;
  9448. }
  9449. for (var key in map) {
  9450. value = map[key];
  9451. if (mayHaveChildren(value)) {
  9452. nodesToVisit.push(value);
  9453. }
  9454. }
  9455. } else if (isArray(node)) {
  9456. for (var i = 0, ii = node.length; i < ii; i++) {
  9457. value = node[i];
  9458. if (mayHaveChildren(value)) {
  9459. nodesToVisit.push(value);
  9460. }
  9461. }
  9462. }
  9463. }
  9464. function ObjectLoader(obj, keys, xref) {
  9465. this.obj = obj;
  9466. this.keys = keys;
  9467. this.xref = xref;
  9468. this.refSet = null;
  9469. }
  9470. ObjectLoader.prototype = {
  9471. load: function ObjectLoader_load() {
  9472. var keys = this.keys;
  9473. this.capability = createPromiseCapability();
  9474. // Don't walk the graph if all the data is already loaded.
  9475. if (!(this.xref.stream instanceof ChunkedStream) ||
  9476. this.xref.stream.getMissingChunks().length === 0) {
  9477. this.capability.resolve();
  9478. return this.capability.promise;
  9479. }
  9480. this.refSet = new RefSet();
  9481. // Setup the initial nodes to visit.
  9482. var nodesToVisit = [];
  9483. for (var i = 0; i < keys.length; i++) {
  9484. nodesToVisit.push(this.obj[keys[i]]);
  9485. }
  9486. this.walk(nodesToVisit);
  9487. return this.capability.promise;
  9488. },
  9489. walk: function ObjectLoader_walk(nodesToVisit) {
  9490. var nodesToRevisit = [];
  9491. var pendingRequests = [];
  9492. // DFS walk of the object graph.
  9493. while (nodesToVisit.length) {
  9494. var currentNode = nodesToVisit.pop();
  9495. // Only references or chunked streams can cause missing data exceptions.
  9496. if (isRef(currentNode)) {
  9497. // Skip nodes that have already been visited.
  9498. if (this.refSet.has(currentNode)) {
  9499. continue;
  9500. }
  9501. try {
  9502. var ref = currentNode;
  9503. this.refSet.put(ref);
  9504. currentNode = this.xref.fetch(currentNode);
  9505. } catch (e) {
  9506. if (!(e instanceof MissingDataException)) {
  9507. throw e;
  9508. }
  9509. nodesToRevisit.push(currentNode);
  9510. pendingRequests.push({ begin: e.begin, end: e.end });
  9511. }
  9512. }
  9513. if (currentNode && currentNode.getBaseStreams) {
  9514. var baseStreams = currentNode.getBaseStreams();
  9515. var foundMissingData = false;
  9516. for (var i = 0; i < baseStreams.length; i++) {
  9517. var stream = baseStreams[i];
  9518. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9519. foundMissingData = true;
  9520. pendingRequests.push({
  9521. begin: stream.start,
  9522. end: stream.end
  9523. });
  9524. }
  9525. }
  9526. if (foundMissingData) {
  9527. nodesToRevisit.push(currentNode);
  9528. }
  9529. }
  9530. addChildren(currentNode, nodesToVisit);
  9531. }
  9532. if (pendingRequests.length) {
  9533. this.xref.stream.manager.requestRanges(pendingRequests,
  9534. function pendingRequestCallback() {
  9535. nodesToVisit = nodesToRevisit;
  9536. for (var i = 0; i < nodesToRevisit.length; i++) {
  9537. var node = nodesToRevisit[i];
  9538. // Remove any reference nodes from the currrent refset so they
  9539. // aren't skipped when we revist them.
  9540. if (isRef(node)) {
  9541. this.refSet.remove(node);
  9542. }
  9543. }
  9544. this.walk(nodesToVisit);
  9545. }.bind(this));
  9546. return;
  9547. }
  9548. // Everything is loaded.
  9549. this.refSet = null;
  9550. this.capability.resolve();
  9551. }
  9552. };
  9553. return ObjectLoader;
  9554. })();
  9555. var ISOAdobeCharset = [
  9556. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9557. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9558. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9559. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9560. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9561. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9562. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9563. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9564. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9565. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9566. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9567. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9568. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9569. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9570. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9571. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9572. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9573. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9574. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9575. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9576. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9577. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9578. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9579. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9580. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9581. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9582. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9583. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9584. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9585. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9586. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9587. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9588. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9589. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9590. ];
  9591. var ExpertCharset = [
  9592. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9593. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9594. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9595. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9596. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9597. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9598. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9599. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9600. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9601. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9602. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9603. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9604. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9605. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9606. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9607. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9608. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9609. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9610. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9611. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9612. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9613. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9614. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9615. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9616. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9617. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9618. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9619. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9620. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9621. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9622. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9623. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9624. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9625. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9626. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9627. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9628. 'Ydieresissmall'
  9629. ];
  9630. var ExpertSubsetCharset = [
  9631. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9632. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9633. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9634. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9635. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9636. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9637. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9638. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9639. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9640. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9641. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9642. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9643. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9644. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9645. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9646. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9647. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9648. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9649. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9650. 'periodinferior', 'commainferior'
  9651. ];
  9652. var DEFAULT_ICON_SIZE = 22; // px
  9653. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9654. var Annotation = (function AnnotationClosure() {
  9655. // 12.5.5: Algorithm: Appearance streams
  9656. function getTransformMatrix(rect, bbox, matrix) {
  9657. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9658. var minX = bounds[0];
  9659. var minY = bounds[1];
  9660. var maxX = bounds[2];
  9661. var maxY = bounds[3];
  9662. if (minX === maxX || minY === maxY) {
  9663. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9664. // just apply the transform for rect
  9665. return [1, 0, 0, 1, rect[0], rect[1]];
  9666. }
  9667. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9668. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9669. return [
  9670. xRatio,
  9671. 0,
  9672. 0,
  9673. yRatio,
  9674. rect[0] - minX * xRatio,
  9675. rect[1] - minY * yRatio
  9676. ];
  9677. }
  9678. function getDefaultAppearance(dict) {
  9679. var appearanceState = dict.get('AP');
  9680. if (!isDict(appearanceState)) {
  9681. return;
  9682. }
  9683. var appearance;
  9684. var appearances = appearanceState.get('N');
  9685. if (isDict(appearances)) {
  9686. var as = dict.get('AS');
  9687. if (as && appearances.has(as.name)) {
  9688. appearance = appearances.get(as.name);
  9689. }
  9690. } else {
  9691. appearance = appearances;
  9692. }
  9693. return appearance;
  9694. }
  9695. function Annotation(params) {
  9696. var dict = params.dict;
  9697. var data = this.data = {};
  9698. data.subtype = dict.get('Subtype').name;
  9699. var rect = dict.get('Rect') || [0, 0, 0, 0];
  9700. data.rect = Util.normalizeRect(rect);
  9701. data.annotationFlags = dict.get('F');
  9702. var color = dict.get('C');
  9703. if (isArray(color) && color.length === 3) {
  9704. // TODO(mack): currently only supporting rgb; need support different
  9705. // colorspaces
  9706. data.color = color;
  9707. } else {
  9708. data.color = [0, 0, 0];
  9709. }
  9710. // Some types of annotations have border style dict which has more
  9711. // info than the border array
  9712. if (dict.has('BS')) {
  9713. var borderStyle = dict.get('BS');
  9714. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  9715. } else {
  9716. var borderArray = dict.get('Border') || [0, 0, 1];
  9717. data.borderWidth = borderArray[2] || 0;
  9718. // TODO: implement proper support for annotations with line dash patterns.
  9719. var dashArray = borderArray[3];
  9720. if (data.borderWidth > 0 && dashArray) {
  9721. if (!isArray(dashArray)) {
  9722. // Ignore the border if dashArray is not actually an array,
  9723. // this is consistent with the behaviour in Adobe Reader.
  9724. data.borderWidth = 0;
  9725. } else {
  9726. var dashArrayLength = dashArray.length;
  9727. if (dashArrayLength > 0) {
  9728. // According to the PDF specification: the elements in a dashArray
  9729. // shall be numbers that are nonnegative and not all equal to zero.
  9730. var isInvalid = false;
  9731. var numPositive = 0;
  9732. for (var i = 0; i < dashArrayLength; i++) {
  9733. var validNumber = (+dashArray[i] >= 0);
  9734. if (!validNumber) {
  9735. isInvalid = true;
  9736. break;
  9737. } else if (dashArray[i] > 0) {
  9738. numPositive++;
  9739. }
  9740. }
  9741. if (isInvalid || numPositive === 0) {
  9742. data.borderWidth = 0;
  9743. }
  9744. }
  9745. }
  9746. }
  9747. }
  9748. this.appearance = getDefaultAppearance(dict);
  9749. data.hasAppearance = !!this.appearance;
  9750. data.id = params.ref.num;
  9751. }
  9752. Annotation.prototype = {
  9753. getData: function Annotation_getData() {
  9754. return this.data;
  9755. },
  9756. isInvisible: function Annotation_isInvisible() {
  9757. var data = this.data;
  9758. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  9759. return false;
  9760. } else {
  9761. return !!(data &&
  9762. data.annotationFlags && // Default: not invisible
  9763. data.annotationFlags & 0x1); // Invisible
  9764. }
  9765. },
  9766. isViewable: function Annotation_isViewable() {
  9767. var data = this.data;
  9768. return !!(!this.isInvisible() &&
  9769. data &&
  9770. (!data.annotationFlags ||
  9771. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  9772. data.rect); // rectangle is necessary
  9773. },
  9774. isPrintable: function Annotation_isPrintable() {
  9775. var data = this.data;
  9776. return !!(!this.isInvisible() &&
  9777. data &&
  9778. data.annotationFlags && // Default: not printable
  9779. data.annotationFlags & 0x4 && // Print
  9780. !(data.annotationFlags & 0x2) && // Hidden
  9781. data.rect); // rectangle is necessary
  9782. },
  9783. loadResources: function Annotation_loadResources(keys) {
  9784. return new Promise(function (resolve, reject) {
  9785. this.appearance.dict.getAsync('Resources').then(function (resources) {
  9786. if (!resources) {
  9787. resolve();
  9788. return;
  9789. }
  9790. var objectLoader = new ObjectLoader(resources.map,
  9791. keys,
  9792. resources.xref);
  9793. objectLoader.load().then(function() {
  9794. resolve(resources);
  9795. }, reject);
  9796. }, reject);
  9797. }.bind(this));
  9798. },
  9799. getOperatorList: function Annotation_getOperatorList(evaluator) {
  9800. if (!this.appearance) {
  9801. return Promise.resolve(new OperatorList());
  9802. }
  9803. var data = this.data;
  9804. var appearanceDict = this.appearance.dict;
  9805. var resourcesPromise = this.loadResources([
  9806. 'ExtGState',
  9807. 'ColorSpace',
  9808. 'Pattern',
  9809. 'Shading',
  9810. 'XObject',
  9811. 'Font'
  9812. // ProcSet
  9813. // Properties
  9814. ]);
  9815. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  9816. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  9817. var transform = getTransformMatrix(data.rect, bbox, matrix);
  9818. var self = this;
  9819. return resourcesPromise.then(function(resources) {
  9820. var opList = new OperatorList();
  9821. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  9822. return evaluator.getOperatorList(self.appearance, resources, opList).
  9823. then(function () {
  9824. opList.addOp(OPS.endAnnotation, []);
  9825. self.appearance.reset();
  9826. return opList;
  9827. });
  9828. });
  9829. }
  9830. };
  9831. Annotation.getConstructor =
  9832. function Annotation_getConstructor(subtype, fieldType) {
  9833. if (!subtype) {
  9834. return;
  9835. }
  9836. // TODO(mack): Implement FreeText annotations
  9837. if (subtype === 'Link') {
  9838. return LinkAnnotation;
  9839. } else if (subtype === 'Text') {
  9840. return TextAnnotation;
  9841. } else if (subtype === 'Widget') {
  9842. if (!fieldType) {
  9843. return;
  9844. }
  9845. if (fieldType === 'Tx') {
  9846. return TextWidgetAnnotation;
  9847. } else {
  9848. return WidgetAnnotation;
  9849. }
  9850. } else {
  9851. return Annotation;
  9852. }
  9853. };
  9854. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  9855. var dict = xref.fetchIfRef(ref);
  9856. if (!isDict(dict)) {
  9857. return;
  9858. }
  9859. var subtype = dict.get('Subtype');
  9860. subtype = isName(subtype) ? subtype.name : '';
  9861. if (!subtype) {
  9862. return;
  9863. }
  9864. var fieldType = Util.getInheritableProperty(dict, 'FT');
  9865. fieldType = isName(fieldType) ? fieldType.name : '';
  9866. var Constructor = Annotation.getConstructor(subtype, fieldType);
  9867. if (!Constructor) {
  9868. return;
  9869. }
  9870. var params = {
  9871. dict: dict,
  9872. ref: ref,
  9873. };
  9874. var annotation = new Constructor(params);
  9875. if (annotation.isViewable() || annotation.isPrintable()) {
  9876. return annotation;
  9877. } else {
  9878. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  9879. warn('unimplemented annotation type: ' + subtype);
  9880. }
  9881. }
  9882. };
  9883. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  9884. annotations, opList, pdfManager, partialEvaluator, intent) {
  9885. function reject(e) {
  9886. annotationsReadyCapability.reject(e);
  9887. }
  9888. var annotationsReadyCapability = createPromiseCapability();
  9889. var annotationPromises = [];
  9890. for (var i = 0, n = annotations.length; i < n; ++i) {
  9891. if (intent === 'display' && annotations[i].isViewable() ||
  9892. intent === 'print' && annotations[i].isPrintable()) {
  9893. annotationPromises.push(
  9894. annotations[i].getOperatorList(partialEvaluator));
  9895. }
  9896. }
  9897. Promise.all(annotationPromises).then(function(datas) {
  9898. opList.addOp(OPS.beginAnnotations, []);
  9899. for (var i = 0, n = datas.length; i < n; ++i) {
  9900. var annotOpList = datas[i];
  9901. opList.addOpList(annotOpList);
  9902. }
  9903. opList.addOp(OPS.endAnnotations, []);
  9904. annotationsReadyCapability.resolve();
  9905. }, reject);
  9906. return annotationsReadyCapability.promise;
  9907. };
  9908. return Annotation;
  9909. })();
  9910. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  9911. function WidgetAnnotation(params) {
  9912. Annotation.call(this, params);
  9913. var dict = params.dict;
  9914. var data = this.data;
  9915. data.fieldValue = stringToPDFString(
  9916. Util.getInheritableProperty(dict, 'V') || '');
  9917. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  9918. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  9919. var fieldType = Util.getInheritableProperty(dict, 'FT');
  9920. data.fieldType = isName(fieldType) ? fieldType.name : '';
  9921. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  9922. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  9923. // Building the full field name by collecting the field and
  9924. // its ancestors 'T' data and joining them using '.'.
  9925. var fieldName = [];
  9926. var namedItem = dict;
  9927. var ref = params.ref;
  9928. while (namedItem) {
  9929. var parent = namedItem.get('Parent');
  9930. var parentRef = namedItem.getRaw('Parent');
  9931. var name = namedItem.get('T');
  9932. if (name) {
  9933. fieldName.unshift(stringToPDFString(name));
  9934. } else {
  9935. // The field name is absent, that means more than one field
  9936. // with the same name may exist. Replacing the empty name
  9937. // with the '`' plus index in the parent's 'Kids' array.
  9938. // This is not in the PDF spec but necessary to id the
  9939. // the input controls.
  9940. var kids = parent.get('Kids');
  9941. var j, jj;
  9942. for (j = 0, jj = kids.length; j < jj; j++) {
  9943. var kidRef = kids[j];
  9944. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  9945. break;
  9946. }
  9947. }
  9948. fieldName.unshift('`' + j);
  9949. }
  9950. namedItem = parent;
  9951. ref = parentRef;
  9952. }
  9953. data.fullName = fieldName.join('.');
  9954. }
  9955. var parent = Annotation.prototype;
  9956. Util.inherit(WidgetAnnotation, Annotation, {
  9957. isViewable: function WidgetAnnotation_isViewable() {
  9958. if (this.data.fieldType === 'Sig') {
  9959. warn('unimplemented annotation type: Widget signature');
  9960. return false;
  9961. }
  9962. return parent.isViewable.call(this);
  9963. }
  9964. });
  9965. return WidgetAnnotation;
  9966. })();
  9967. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  9968. function TextWidgetAnnotation(params) {
  9969. WidgetAnnotation.call(this, params);
  9970. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  9971. this.data.annotationType = AnnotationType.WIDGET;
  9972. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  9973. }
  9974. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  9975. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  9976. if (this.appearance) {
  9977. return Annotation.prototype.getOperatorList.call(this, evaluator);
  9978. }
  9979. var opList = new OperatorList();
  9980. var data = this.data;
  9981. // Even if there is an appearance stream, ignore it. This is the
  9982. // behaviour used by Adobe Reader.
  9983. if (!data.defaultAppearance) {
  9984. return Promise.resolve(opList);
  9985. }
  9986. var stream = new Stream(stringToBytes(data.defaultAppearance));
  9987. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  9988. then(function () {
  9989. return opList;
  9990. });
  9991. }
  9992. });
  9993. return TextWidgetAnnotation;
  9994. })();
  9995. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  9996. function InteractiveAnnotation(params) {
  9997. Annotation.call(this, params);
  9998. this.data.hasHtml = true;
  9999. }
  10000. Util.inherit(InteractiveAnnotation, Annotation, { });
  10001. return InteractiveAnnotation;
  10002. })();
  10003. var TextAnnotation = (function TextAnnotationClosure() {
  10004. function TextAnnotation(params) {
  10005. InteractiveAnnotation.call(this, params);
  10006. var dict = params.dict;
  10007. var data = this.data;
  10008. var content = dict.get('Contents');
  10009. var title = dict.get('T');
  10010. data.annotationType = AnnotationType.TEXT;
  10011. data.content = stringToPDFString(content || '');
  10012. data.title = stringToPDFString(title || '');
  10013. if (data.hasAppearance) {
  10014. data.name = 'NoIcon';
  10015. } else {
  10016. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10017. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10018. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10019. }
  10020. if (dict.has('C')) {
  10021. data.hasBgColor = true;
  10022. }
  10023. }
  10024. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10025. return TextAnnotation;
  10026. })();
  10027. var LinkAnnotation = (function LinkAnnotationClosure() {
  10028. function LinkAnnotation(params) {
  10029. InteractiveAnnotation.call(this, params);
  10030. var dict = params.dict;
  10031. var data = this.data;
  10032. data.annotationType = AnnotationType.LINK;
  10033. var action = dict.get('A');
  10034. if (action) {
  10035. var linkType = action.get('S').name;
  10036. if (linkType === 'URI') {
  10037. var url = action.get('URI');
  10038. if (isName(url)) {
  10039. // Some bad PDFs do not put parentheses around relative URLs.
  10040. url = '/' + url.name;
  10041. } else if (url) {
  10042. url = addDefaultProtocolToUrl(url);
  10043. }
  10044. // TODO: pdf spec mentions urls can be relative to a Base
  10045. // entry in the dictionary.
  10046. if (!isValidUrl(url, false)) {
  10047. url = '';
  10048. }
  10049. data.url = url;
  10050. } else if (linkType === 'GoTo') {
  10051. data.dest = action.get('D');
  10052. } else if (linkType === 'GoToR') {
  10053. var urlDict = action.get('F');
  10054. if (isDict(urlDict)) {
  10055. // We assume that the 'url' is a Filspec dictionary
  10056. // and fetch the url without checking any further
  10057. url = urlDict.get('F') || '';
  10058. }
  10059. // TODO: pdf reference says that GoToR
  10060. // can also have 'NewWindow' attribute
  10061. if (!isValidUrl(url, false)) {
  10062. url = '';
  10063. }
  10064. data.url = url;
  10065. data.dest = action.get('D');
  10066. } else if (linkType === 'Named') {
  10067. data.action = action.get('N').name;
  10068. } else {
  10069. warn('unrecognized link type: ' + linkType);
  10070. }
  10071. } else if (dict.has('Dest')) {
  10072. // simple destination link
  10073. var dest = dict.get('Dest');
  10074. data.dest = isName(dest) ? dest.name : dest;
  10075. }
  10076. }
  10077. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10078. function addDefaultProtocolToUrl(url) {
  10079. if (url && url.indexOf('www.') === 0) {
  10080. return ('http://' + url);
  10081. }
  10082. return url;
  10083. }
  10084. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  10085. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  10086. return false;
  10087. }
  10088. });
  10089. return LinkAnnotation;
  10090. })();
  10091. var PDFFunction = (function PDFFunctionClosure() {
  10092. var CONSTRUCT_SAMPLED = 0;
  10093. var CONSTRUCT_INTERPOLATED = 2;
  10094. var CONSTRUCT_STICHED = 3;
  10095. var CONSTRUCT_POSTSCRIPT = 4;
  10096. return {
  10097. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10098. str) {
  10099. var i, ii;
  10100. var length = 1;
  10101. for (i = 0, ii = size.length; i < ii; i++) {
  10102. length *= size[i];
  10103. }
  10104. length *= outputSize;
  10105. var array = new Array(length);
  10106. var codeSize = 0;
  10107. var codeBuf = 0;
  10108. // 32 is a valid bps so shifting won't work
  10109. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10110. var strBytes = str.getBytes((length * bps + 7) / 8);
  10111. var strIdx = 0;
  10112. for (i = 0; i < length; i++) {
  10113. while (codeSize < bps) {
  10114. codeBuf <<= 8;
  10115. codeBuf |= strBytes[strIdx++];
  10116. codeSize += 8;
  10117. }
  10118. codeSize -= bps;
  10119. array[i] = (codeBuf >> codeSize) * sampleMul;
  10120. codeBuf &= (1 << codeSize) - 1;
  10121. }
  10122. return array;
  10123. },
  10124. getIR: function PDFFunction_getIR(xref, fn) {
  10125. var dict = fn.dict;
  10126. if (!dict) {
  10127. dict = fn;
  10128. }
  10129. var types = [this.constructSampled,
  10130. null,
  10131. this.constructInterpolated,
  10132. this.constructStiched,
  10133. this.constructPostScript];
  10134. var typeNum = dict.get('FunctionType');
  10135. var typeFn = types[typeNum];
  10136. if (!typeFn) {
  10137. error('Unknown type of function');
  10138. }
  10139. return typeFn.call(this, fn, dict, xref);
  10140. },
  10141. fromIR: function PDFFunction_fromIR(IR) {
  10142. var type = IR[0];
  10143. switch (type) {
  10144. case CONSTRUCT_SAMPLED:
  10145. return this.constructSampledFromIR(IR);
  10146. case CONSTRUCT_INTERPOLATED:
  10147. return this.constructInterpolatedFromIR(IR);
  10148. case CONSTRUCT_STICHED:
  10149. return this.constructStichedFromIR(IR);
  10150. //case CONSTRUCT_POSTSCRIPT:
  10151. default:
  10152. return this.constructPostScriptFromIR(IR);
  10153. }
  10154. },
  10155. parse: function PDFFunction_parse(xref, fn) {
  10156. var IR = this.getIR(xref, fn);
  10157. return this.fromIR(IR);
  10158. },
  10159. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10160. if (!isArray(fnObj)) {
  10161. // not an array -- parsing as regular function
  10162. return this.parse(xref, fnObj);
  10163. }
  10164. var fnArray = [];
  10165. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10166. var obj = xref.fetchIfRef(fnObj[j]);
  10167. fnArray.push(PDFFunction.parse(xref, obj));
  10168. }
  10169. return function (src, srcOffset, dest, destOffset) {
  10170. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10171. fnArray[i](src, srcOffset, dest, destOffset + i);
  10172. }
  10173. };
  10174. },
  10175. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10176. function toMultiArray(arr) {
  10177. var inputLength = arr.length;
  10178. var out = [];
  10179. var index = 0;
  10180. for (var i = 0; i < inputLength; i += 2) {
  10181. out[index] = [arr[i], arr[i + 1]];
  10182. ++index;
  10183. }
  10184. return out;
  10185. }
  10186. var domain = dict.get('Domain');
  10187. var range = dict.get('Range');
  10188. if (!domain || !range) {
  10189. error('No domain or range');
  10190. }
  10191. var inputSize = domain.length / 2;
  10192. var outputSize = range.length / 2;
  10193. domain = toMultiArray(domain);
  10194. range = toMultiArray(range);
  10195. var size = dict.get('Size');
  10196. var bps = dict.get('BitsPerSample');
  10197. var order = dict.get('Order') || 1;
  10198. if (order !== 1) {
  10199. // No description how cubic spline interpolation works in PDF32000:2008
  10200. // As in poppler, ignoring order, linear interpolation may work as good
  10201. info('No support for cubic spline interpolation: ' + order);
  10202. }
  10203. var encode = dict.get('Encode');
  10204. if (!encode) {
  10205. encode = [];
  10206. for (var i = 0; i < inputSize; ++i) {
  10207. encode.push(0);
  10208. encode.push(size[i] - 1);
  10209. }
  10210. }
  10211. encode = toMultiArray(encode);
  10212. var decode = dict.get('Decode');
  10213. if (!decode) {
  10214. decode = range;
  10215. } else {
  10216. decode = toMultiArray(decode);
  10217. }
  10218. var samples = this.getSampleArray(size, outputSize, bps, str);
  10219. return [
  10220. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10221. outputSize, Math.pow(2, bps) - 1, range
  10222. ];
  10223. },
  10224. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10225. // See chapter 3, page 109 of the PDF reference
  10226. function interpolate(x, xmin, xmax, ymin, ymax) {
  10227. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10228. }
  10229. return function constructSampledFromIRResult(src, srcOffset,
  10230. dest, destOffset) {
  10231. // See chapter 3, page 110 of the PDF reference.
  10232. var m = IR[1];
  10233. var domain = IR[2];
  10234. var encode = IR[3];
  10235. var decode = IR[4];
  10236. var samples = IR[5];
  10237. var size = IR[6];
  10238. var n = IR[7];
  10239. //var mask = IR[8];
  10240. var range = IR[9];
  10241. // Building the cube vertices: its part and sample index
  10242. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10243. var cubeVertices = 1 << m;
  10244. var cubeN = new Float64Array(cubeVertices);
  10245. var cubeVertex = new Uint32Array(cubeVertices);
  10246. var i, j;
  10247. for (j = 0; j < cubeVertices; j++) {
  10248. cubeN[j] = 1;
  10249. }
  10250. var k = n, pos = 1;
  10251. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10252. for (i = 0; i < m; ++i) {
  10253. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10254. var domain_2i = domain[i][0];
  10255. var domain_2i_1 = domain[i][1];
  10256. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10257. domain_2i_1);
  10258. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10259. // Encode_2i, Encode_2i+1)
  10260. var e = interpolate(xi, domain_2i, domain_2i_1,
  10261. encode[i][0], encode[i][1]);
  10262. // e_i' = min(max(e_i, 0), Size_i - 1)
  10263. var size_i = size[i];
  10264. e = Math.min(Math.max(e, 0), size_i - 1);
  10265. // Adjusting the cube: N and vertex sample index
  10266. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10267. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10268. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10269. var offset0 = e0 * k;
  10270. var offset1 = offset0 + k; // e1 * k
  10271. for (j = 0; j < cubeVertices; j++) {
  10272. if (j & pos) {
  10273. cubeN[j] *= n1;
  10274. cubeVertex[j] += offset1;
  10275. } else {
  10276. cubeN[j] *= n0;
  10277. cubeVertex[j] += offset0;
  10278. }
  10279. }
  10280. k *= size_i;
  10281. pos <<= 1;
  10282. }
  10283. for (j = 0; j < n; ++j) {
  10284. // Sum all cube vertices' samples portions
  10285. var rj = 0;
  10286. for (i = 0; i < cubeVertices; i++) {
  10287. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10288. }
  10289. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10290. // Decode_2j, Decode_2j+1)
  10291. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10292. // y_j = min(max(r_j, range_2j), range_2j+1)
  10293. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10294. range[j][1]);
  10295. }
  10296. };
  10297. },
  10298. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10299. dict) {
  10300. var c0 = dict.get('C0') || [0];
  10301. var c1 = dict.get('C1') || [1];
  10302. var n = dict.get('N');
  10303. if (!isArray(c0) || !isArray(c1)) {
  10304. error('Illegal dictionary for interpolated function');
  10305. }
  10306. var length = c0.length;
  10307. var diff = [];
  10308. for (var i = 0; i < length; ++i) {
  10309. diff.push(c1[i] - c0[i]);
  10310. }
  10311. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10312. },
  10313. constructInterpolatedFromIR:
  10314. function PDFFunction_constructInterpolatedFromIR(IR) {
  10315. var c0 = IR[1];
  10316. var diff = IR[2];
  10317. var n = IR[3];
  10318. var length = diff.length;
  10319. return function constructInterpolatedFromIRResult(src, srcOffset,
  10320. dest, destOffset) {
  10321. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10322. for (var j = 0; j < length; ++j) {
  10323. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10324. }
  10325. };
  10326. },
  10327. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10328. var domain = dict.get('Domain');
  10329. if (!domain) {
  10330. error('No domain');
  10331. }
  10332. var inputSize = domain.length / 2;
  10333. if (inputSize !== 1) {
  10334. error('Bad domain for stiched function');
  10335. }
  10336. var fnRefs = dict.get('Functions');
  10337. var fns = [];
  10338. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10339. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10340. }
  10341. var bounds = dict.get('Bounds');
  10342. var encode = dict.get('Encode');
  10343. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10344. },
  10345. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10346. var domain = IR[1];
  10347. var bounds = IR[2];
  10348. var encode = IR[3];
  10349. var fnsIR = IR[4];
  10350. var fns = [];
  10351. var tmpBuf = new Float32Array(1);
  10352. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10353. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10354. }
  10355. return function constructStichedFromIRResult(src, srcOffset,
  10356. dest, destOffset) {
  10357. var clip = function constructStichedFromIRClip(v, min, max) {
  10358. if (v > max) {
  10359. v = max;
  10360. } else if (v < min) {
  10361. v = min;
  10362. }
  10363. return v;
  10364. };
  10365. // clip to domain
  10366. var v = clip(src[srcOffset], domain[0], domain[1]);
  10367. // calulate which bound the value is in
  10368. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10369. if (v < bounds[i]) {
  10370. break;
  10371. }
  10372. }
  10373. // encode value into domain of function
  10374. var dmin = domain[0];
  10375. if (i > 0) {
  10376. dmin = bounds[i - 1];
  10377. }
  10378. var dmax = domain[1];
  10379. if (i < bounds.length) {
  10380. dmax = bounds[i];
  10381. }
  10382. var rmin = encode[2 * i];
  10383. var rmax = encode[2 * i + 1];
  10384. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10385. // call the appropriate function
  10386. fns[i](tmpBuf, 0, dest, destOffset);
  10387. };
  10388. },
  10389. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10390. xref) {
  10391. var domain = dict.get('Domain');
  10392. var range = dict.get('Range');
  10393. if (!domain) {
  10394. error('No domain.');
  10395. }
  10396. if (!range) {
  10397. error('No range.');
  10398. }
  10399. var lexer = new PostScriptLexer(fn);
  10400. var parser = new PostScriptParser(lexer);
  10401. var code = parser.parse();
  10402. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10403. },
  10404. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10405. IR) {
  10406. var domain = IR[1];
  10407. var range = IR[2];
  10408. var code = IR[3];
  10409. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10410. if (compiled) {
  10411. // Compiled function consists of simple expressions such as addition,
  10412. // subtraction, Math.max, and also contains 'var' and 'return'
  10413. // statements. See the generation in the PostScriptCompiler below.
  10414. /*jshint -W054 */
  10415. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10416. }
  10417. info('Unable to compile PS function');
  10418. var numOutputs = range.length >> 1;
  10419. var numInputs = domain.length >> 1;
  10420. var evaluator = new PostScriptEvaluator(code);
  10421. // Cache the values for a big speed up, the cache size is limited though
  10422. // since the number of possible values can be huge from a PS function.
  10423. var cache = {};
  10424. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10425. // seen in our tests.
  10426. var MAX_CACHE_SIZE = 2048 * 4;
  10427. var cache_available = MAX_CACHE_SIZE;
  10428. var tmpBuf = new Float32Array(numInputs);
  10429. return function constructPostScriptFromIRResult(src, srcOffset,
  10430. dest, destOffset) {
  10431. var i, value;
  10432. var key = '';
  10433. var input = tmpBuf;
  10434. for (i = 0; i < numInputs; i++) {
  10435. value = src[srcOffset + i];
  10436. input[i] = value;
  10437. key += value + '_';
  10438. }
  10439. var cachedValue = cache[key];
  10440. if (cachedValue !== undefined) {
  10441. cachedValue.set(dest, destOffset);
  10442. return;
  10443. }
  10444. var output = new Float32Array(numOutputs);
  10445. var stack = evaluator.execute(input);
  10446. var stackIndex = stack.length - numOutputs;
  10447. for (i = 0; i < numOutputs; i++) {
  10448. value = stack[stackIndex + i];
  10449. var bound = range[i * 2];
  10450. if (value < bound) {
  10451. value = bound;
  10452. } else {
  10453. bound = range[i * 2 +1];
  10454. if (value > bound) {
  10455. value = bound;
  10456. }
  10457. }
  10458. output[i] = value;
  10459. }
  10460. if (cache_available > 0) {
  10461. cache_available--;
  10462. cache[key] = output;
  10463. }
  10464. output.set(dest, destOffset);
  10465. };
  10466. }
  10467. };
  10468. })();
  10469. function isPDFFunction(v) {
  10470. var fnDict;
  10471. if (typeof v !== 'object') {
  10472. return false;
  10473. } else if (isDict(v)) {
  10474. fnDict = v;
  10475. } else if (isStream(v)) {
  10476. fnDict = v.dict;
  10477. } else {
  10478. return false;
  10479. }
  10480. return fnDict.has('FunctionType');
  10481. }
  10482. var PostScriptStack = (function PostScriptStackClosure() {
  10483. var MAX_STACK_SIZE = 100;
  10484. function PostScriptStack(initialStack) {
  10485. this.stack = !initialStack ? [] :
  10486. Array.prototype.slice.call(initialStack, 0);
  10487. }
  10488. PostScriptStack.prototype = {
  10489. push: function PostScriptStack_push(value) {
  10490. if (this.stack.length >= MAX_STACK_SIZE) {
  10491. error('PostScript function stack overflow.');
  10492. }
  10493. this.stack.push(value);
  10494. },
  10495. pop: function PostScriptStack_pop() {
  10496. if (this.stack.length <= 0) {
  10497. error('PostScript function stack underflow.');
  10498. }
  10499. return this.stack.pop();
  10500. },
  10501. copy: function PostScriptStack_copy(n) {
  10502. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10503. error('PostScript function stack overflow.');
  10504. }
  10505. var stack = this.stack;
  10506. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10507. stack.push(stack[i]);
  10508. }
  10509. },
  10510. index: function PostScriptStack_index(n) {
  10511. this.push(this.stack[this.stack.length - n - 1]);
  10512. },
  10513. // rotate the last n stack elements p times
  10514. roll: function PostScriptStack_roll(n, p) {
  10515. var stack = this.stack;
  10516. var l = stack.length - n;
  10517. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10518. for (i = l, j = r; i < j; i++, j--) {
  10519. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10520. }
  10521. for (i = l, j = c - 1; i < j; i++, j--) {
  10522. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10523. }
  10524. for (i = c, j = r; i < j; i++, j--) {
  10525. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10526. }
  10527. }
  10528. };
  10529. return PostScriptStack;
  10530. })();
  10531. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10532. function PostScriptEvaluator(operators) {
  10533. this.operators = operators;
  10534. }
  10535. PostScriptEvaluator.prototype = {
  10536. execute: function PostScriptEvaluator_execute(initialStack) {
  10537. var stack = new PostScriptStack(initialStack);
  10538. var counter = 0;
  10539. var operators = this.operators;
  10540. var length = operators.length;
  10541. var operator, a, b;
  10542. while (counter < length) {
  10543. operator = operators[counter++];
  10544. if (typeof operator === 'number') {
  10545. // Operator is really an operand and should be pushed to the stack.
  10546. stack.push(operator);
  10547. continue;
  10548. }
  10549. switch (operator) {
  10550. // non standard ps operators
  10551. case 'jz': // jump if false
  10552. b = stack.pop();
  10553. a = stack.pop();
  10554. if (!a) {
  10555. counter = b;
  10556. }
  10557. break;
  10558. case 'j': // jump
  10559. a = stack.pop();
  10560. counter = a;
  10561. break;
  10562. // all ps operators in alphabetical order (excluding if/ifelse)
  10563. case 'abs':
  10564. a = stack.pop();
  10565. stack.push(Math.abs(a));
  10566. break;
  10567. case 'add':
  10568. b = stack.pop();
  10569. a = stack.pop();
  10570. stack.push(a + b);
  10571. break;
  10572. case 'and':
  10573. b = stack.pop();
  10574. a = stack.pop();
  10575. if (isBool(a) && isBool(b)) {
  10576. stack.push(a && b);
  10577. } else {
  10578. stack.push(a & b);
  10579. }
  10580. break;
  10581. case 'atan':
  10582. a = stack.pop();
  10583. stack.push(Math.atan(a));
  10584. break;
  10585. case 'bitshift':
  10586. b = stack.pop();
  10587. a = stack.pop();
  10588. if (a > 0) {
  10589. stack.push(a << b);
  10590. } else {
  10591. stack.push(a >> b);
  10592. }
  10593. break;
  10594. case 'ceiling':
  10595. a = stack.pop();
  10596. stack.push(Math.ceil(a));
  10597. break;
  10598. case 'copy':
  10599. a = stack.pop();
  10600. stack.copy(a);
  10601. break;
  10602. case 'cos':
  10603. a = stack.pop();
  10604. stack.push(Math.cos(a));
  10605. break;
  10606. case 'cvi':
  10607. a = stack.pop() | 0;
  10608. stack.push(a);
  10609. break;
  10610. case 'cvr':
  10611. // noop
  10612. break;
  10613. case 'div':
  10614. b = stack.pop();
  10615. a = stack.pop();
  10616. stack.push(a / b);
  10617. break;
  10618. case 'dup':
  10619. stack.copy(1);
  10620. break;
  10621. case 'eq':
  10622. b = stack.pop();
  10623. a = stack.pop();
  10624. stack.push(a === b);
  10625. break;
  10626. case 'exch':
  10627. stack.roll(2, 1);
  10628. break;
  10629. case 'exp':
  10630. b = stack.pop();
  10631. a = stack.pop();
  10632. stack.push(Math.pow(a, b));
  10633. break;
  10634. case 'false':
  10635. stack.push(false);
  10636. break;
  10637. case 'floor':
  10638. a = stack.pop();
  10639. stack.push(Math.floor(a));
  10640. break;
  10641. case 'ge':
  10642. b = stack.pop();
  10643. a = stack.pop();
  10644. stack.push(a >= b);
  10645. break;
  10646. case 'gt':
  10647. b = stack.pop();
  10648. a = stack.pop();
  10649. stack.push(a > b);
  10650. break;
  10651. case 'idiv':
  10652. b = stack.pop();
  10653. a = stack.pop();
  10654. stack.push((a / b) | 0);
  10655. break;
  10656. case 'index':
  10657. a = stack.pop();
  10658. stack.index(a);
  10659. break;
  10660. case 'le':
  10661. b = stack.pop();
  10662. a = stack.pop();
  10663. stack.push(a <= b);
  10664. break;
  10665. case 'ln':
  10666. a = stack.pop();
  10667. stack.push(Math.log(a));
  10668. break;
  10669. case 'log':
  10670. a = stack.pop();
  10671. stack.push(Math.log(a) / Math.LN10);
  10672. break;
  10673. case 'lt':
  10674. b = stack.pop();
  10675. a = stack.pop();
  10676. stack.push(a < b);
  10677. break;
  10678. case 'mod':
  10679. b = stack.pop();
  10680. a = stack.pop();
  10681. stack.push(a % b);
  10682. break;
  10683. case 'mul':
  10684. b = stack.pop();
  10685. a = stack.pop();
  10686. stack.push(a * b);
  10687. break;
  10688. case 'ne':
  10689. b = stack.pop();
  10690. a = stack.pop();
  10691. stack.push(a !== b);
  10692. break;
  10693. case 'neg':
  10694. a = stack.pop();
  10695. stack.push(-a);
  10696. break;
  10697. case 'not':
  10698. a = stack.pop();
  10699. if (isBool(a)) {
  10700. stack.push(!a);
  10701. } else {
  10702. stack.push(~a);
  10703. }
  10704. break;
  10705. case 'or':
  10706. b = stack.pop();
  10707. a = stack.pop();
  10708. if (isBool(a) && isBool(b)) {
  10709. stack.push(a || b);
  10710. } else {
  10711. stack.push(a | b);
  10712. }
  10713. break;
  10714. case 'pop':
  10715. stack.pop();
  10716. break;
  10717. case 'roll':
  10718. b = stack.pop();
  10719. a = stack.pop();
  10720. stack.roll(a, b);
  10721. break;
  10722. case 'round':
  10723. a = stack.pop();
  10724. stack.push(Math.round(a));
  10725. break;
  10726. case 'sin':
  10727. a = stack.pop();
  10728. stack.push(Math.sin(a));
  10729. break;
  10730. case 'sqrt':
  10731. a = stack.pop();
  10732. stack.push(Math.sqrt(a));
  10733. break;
  10734. case 'sub':
  10735. b = stack.pop();
  10736. a = stack.pop();
  10737. stack.push(a - b);
  10738. break;
  10739. case 'true':
  10740. stack.push(true);
  10741. break;
  10742. case 'truncate':
  10743. a = stack.pop();
  10744. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  10745. stack.push(a);
  10746. break;
  10747. case 'xor':
  10748. b = stack.pop();
  10749. a = stack.pop();
  10750. if (isBool(a) && isBool(b)) {
  10751. stack.push(a !== b);
  10752. } else {
  10753. stack.push(a ^ b);
  10754. }
  10755. break;
  10756. default:
  10757. error('Unknown operator ' + operator);
  10758. break;
  10759. }
  10760. }
  10761. return stack.stack;
  10762. }
  10763. };
  10764. return PostScriptEvaluator;
  10765. })();
  10766. // Most of the PDFs functions consist of simple operations such as:
  10767. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  10768. //
  10769. // We can compile most of such programs, and at the same moment, we can
  10770. // optimize some expressions using basic math properties. Keeping track of
  10771. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  10772. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  10773. function AstNode(type) {
  10774. this.type = type;
  10775. }
  10776. AstNode.prototype.visit = function (visitor) {
  10777. throw new Error('abstract method');
  10778. };
  10779. function AstArgument(index, min, max) {
  10780. AstNode.call(this, 'args');
  10781. this.index = index;
  10782. this.min = min;
  10783. this.max = max;
  10784. }
  10785. AstArgument.prototype = Object.create(AstNode.prototype);
  10786. AstArgument.prototype.visit = function (visitor) {
  10787. visitor.visitArgument(this);
  10788. };
  10789. function AstLiteral(number) {
  10790. AstNode.call(this, 'literal');
  10791. this.number = number;
  10792. this.min = number;
  10793. this.max = number;
  10794. }
  10795. AstLiteral.prototype = Object.create(AstNode.prototype);
  10796. AstLiteral.prototype.visit = function (visitor) {
  10797. visitor.visitLiteral(this);
  10798. };
  10799. function AstBinaryOperation(op, arg1, arg2, min, max) {
  10800. AstNode.call(this, 'binary');
  10801. this.op = op;
  10802. this.arg1 = arg1;
  10803. this.arg2 = arg2;
  10804. this.min = min;
  10805. this.max = max;
  10806. }
  10807. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  10808. AstBinaryOperation.prototype.visit = function (visitor) {
  10809. visitor.visitBinaryOperation(this);
  10810. };
  10811. function AstMin(arg, max) {
  10812. AstNode.call(this, 'max');
  10813. this.arg = arg;
  10814. this.min = arg.min;
  10815. this.max = max;
  10816. }
  10817. AstMin.prototype = Object.create(AstNode.prototype);
  10818. AstMin.prototype.visit = function (visitor) {
  10819. visitor.visitMin(this);
  10820. };
  10821. function AstVariable(index, min, max) {
  10822. AstNode.call(this, 'var');
  10823. this.index = index;
  10824. this.min = min;
  10825. this.max = max;
  10826. }
  10827. AstVariable.prototype = Object.create(AstNode.prototype);
  10828. AstVariable.prototype.visit = function (visitor) {
  10829. visitor.visitVariable(this);
  10830. };
  10831. function AstVariableDefinition(variable, arg) {
  10832. AstNode.call(this, 'definition');
  10833. this.variable = variable;
  10834. this.arg = arg;
  10835. }
  10836. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  10837. AstVariableDefinition.prototype.visit = function (visitor) {
  10838. visitor.visitVariableDefinition(this);
  10839. };
  10840. function ExpressionBuilderVisitor() {
  10841. this.parts = [];
  10842. }
  10843. ExpressionBuilderVisitor.prototype = {
  10844. visitArgument: function (arg) {
  10845. this.parts.push('Math.max(', arg.min, ', Math.min(',
  10846. arg.max, ', src[srcOffset + ', arg.index, ']))');
  10847. },
  10848. visitVariable: function (variable) {
  10849. this.parts.push('v', variable.index);
  10850. },
  10851. visitLiteral: function (literal) {
  10852. this.parts.push(literal.number);
  10853. },
  10854. visitBinaryOperation: function (operation) {
  10855. this.parts.push('(');
  10856. operation.arg1.visit(this);
  10857. this.parts.push(' ', operation.op, ' ');
  10858. operation.arg2.visit(this);
  10859. this.parts.push(')');
  10860. },
  10861. visitVariableDefinition: function (definition) {
  10862. this.parts.push('var ');
  10863. definition.variable.visit(this);
  10864. this.parts.push(' = ');
  10865. definition.arg.visit(this);
  10866. this.parts.push(';');
  10867. },
  10868. visitMin: function (max) {
  10869. this.parts.push('Math.min(');
  10870. max.arg.visit(this);
  10871. this.parts.push(', ', max.max, ')');
  10872. },
  10873. toString: function () {
  10874. return this.parts.join('');
  10875. }
  10876. };
  10877. function buildAddOperation(num1, num2) {
  10878. if (num2.type === 'literal' && num2.number === 0) {
  10879. // optimization: second operand is 0
  10880. return num1;
  10881. }
  10882. if (num1.type === 'literal' && num1.number === 0) {
  10883. // optimization: first operand is 0
  10884. return num2;
  10885. }
  10886. if (num2.type === 'literal' && num1.type === 'literal') {
  10887. // optimization: operands operand are literals
  10888. return new AstLiteral(num1.number + num2.number);
  10889. }
  10890. return new AstBinaryOperation('+', num1, num2,
  10891. num1.min + num2.min, num1.max + num2.max);
  10892. }
  10893. function buildMulOperation(num1, num2) {
  10894. if (num2.type === 'literal') {
  10895. // optimization: second operands is a literal...
  10896. if (num2.number === 0) {
  10897. return new AstLiteral(0); // and it's 0
  10898. } else if (num2.number === 1) {
  10899. return num1; // and it's 1
  10900. } else if (num1.type === 'literal') {
  10901. // ... and first operands is a literal too
  10902. return new AstLiteral(num1.number * num2.number);
  10903. }
  10904. }
  10905. if (num1.type === 'literal') {
  10906. // optimization: first operands is a literal...
  10907. if (num1.number === 0) {
  10908. return new AstLiteral(0); // and it's 0
  10909. } else if (num1.number === 1) {
  10910. return num2; // and it's 1
  10911. }
  10912. }
  10913. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  10914. num1.max * num2.min, num1.max * num2.max);
  10915. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  10916. num1.max * num2.min, num1.max * num2.max);
  10917. return new AstBinaryOperation('*', num1, num2, min, max);
  10918. }
  10919. function buildSubOperation(num1, num2) {
  10920. if (num2.type === 'literal') {
  10921. // optimization: second operands is a literal...
  10922. if (num2.number === 0) {
  10923. return num1; // ... and it's 0
  10924. } else if (num1.type === 'literal') {
  10925. // ... and first operands is a literal too
  10926. return new AstLiteral(num1.number - num2.number);
  10927. }
  10928. }
  10929. if (num2.type === 'binary' && num2.op === '-' &&
  10930. num1.type === 'literal' && num1.number === 1 &&
  10931. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  10932. // optimization for case: 1 - (1 - x)
  10933. return num2.arg2;
  10934. }
  10935. return new AstBinaryOperation('-', num1, num2,
  10936. num1.min - num2.max, num1.max - num2.min);
  10937. }
  10938. function buildMinOperation(num1, max) {
  10939. if (num1.min >= max) {
  10940. // optimization: num1 min value is not less than required max
  10941. return new AstLiteral(max); // just returning max
  10942. } else if (num1.max <= max) {
  10943. // optimization: num1 max value is not greater than required max
  10944. return num1; // just returning an argument
  10945. }
  10946. return new AstMin(num1, max);
  10947. }
  10948. function PostScriptCompiler() {}
  10949. PostScriptCompiler.prototype = {
  10950. compile: function PostScriptCompiler_compile(code, domain, range) {
  10951. var stack = [];
  10952. var i, ii;
  10953. var instructions = [];
  10954. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  10955. var lastRegister = 0;
  10956. var n, j, min, max;
  10957. var num1, num2, ast1, ast2, tmpVar, item;
  10958. for (i = 0; i < inputSize; i++) {
  10959. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  10960. }
  10961. for (i = 0, ii = code.length; i < ii; i++) {
  10962. item = code[i];
  10963. if (typeof item === 'number') {
  10964. stack.push(new AstLiteral(item));
  10965. continue;
  10966. }
  10967. switch (item) {
  10968. case 'add':
  10969. if (stack.length < 2) {
  10970. return null;
  10971. }
  10972. num2 = stack.pop();
  10973. num1 = stack.pop();
  10974. stack.push(buildAddOperation(num1, num2));
  10975. break;
  10976. case 'cvr':
  10977. if (stack.length < 1) {
  10978. return null;
  10979. }
  10980. break;
  10981. case 'mul':
  10982. if (stack.length < 2) {
  10983. return null;
  10984. }
  10985. num2 = stack.pop();
  10986. num1 = stack.pop();
  10987. stack.push(buildMulOperation(num1, num2));
  10988. break;
  10989. case 'sub':
  10990. if (stack.length < 2) {
  10991. return null;
  10992. }
  10993. num2 = stack.pop();
  10994. num1 = stack.pop();
  10995. stack.push(buildSubOperation(num1, num2));
  10996. break;
  10997. case 'exch':
  10998. if (stack.length < 2) {
  10999. return null;
  11000. }
  11001. ast1 = stack.pop(); ast2 = stack.pop();
  11002. stack.push(ast1, ast2);
  11003. break;
  11004. case 'pop':
  11005. if (stack.length < 1) {
  11006. return null;
  11007. }
  11008. stack.pop();
  11009. break;
  11010. case 'index':
  11011. if (stack.length < 1) {
  11012. return null;
  11013. }
  11014. num1 = stack.pop();
  11015. if (num1.type !== 'literal') {
  11016. return null;
  11017. }
  11018. n = num1.number;
  11019. if (n < 0 || (n|0) !== n || stack.length < n) {
  11020. return null;
  11021. }
  11022. ast1 = stack[stack.length - n - 1];
  11023. if (ast1.type === 'literal' || ast1.type === 'var') {
  11024. stack.push(ast1);
  11025. break;
  11026. }
  11027. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11028. stack[stack.length - n - 1] = tmpVar;
  11029. stack.push(tmpVar);
  11030. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11031. break;
  11032. case 'dup':
  11033. if (stack.length < 1) {
  11034. return null;
  11035. }
  11036. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11037. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11038. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11039. // special case of the commands sequence for the min operation
  11040. num1 = stack.pop();
  11041. stack.push(buildMinOperation(num1, code[i + 1]));
  11042. i += 6;
  11043. break;
  11044. }
  11045. ast1 = stack[stack.length - 1];
  11046. if (ast1.type === 'literal' || ast1.type === 'var') {
  11047. // we don't have to save into intermediate variable a literal or
  11048. // variable.
  11049. stack.push(ast1);
  11050. break;
  11051. }
  11052. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11053. stack[stack.length - 1] = tmpVar;
  11054. stack.push(tmpVar);
  11055. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11056. break;
  11057. case 'roll':
  11058. if (stack.length < 2) {
  11059. return null;
  11060. }
  11061. num2 = stack.pop();
  11062. num1 = stack.pop();
  11063. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11064. // both roll operands must be numbers
  11065. return null;
  11066. }
  11067. j = num2.number;
  11068. n = num1.number;
  11069. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11070. // ... and integers
  11071. return null;
  11072. }
  11073. j = ((j % n) + n) % n;
  11074. if (j === 0) {
  11075. break; // just skipping -- there are nothing to rotate
  11076. }
  11077. Array.prototype.push.apply(stack,
  11078. stack.splice(stack.length - n, n - j));
  11079. break;
  11080. default:
  11081. return null; // unsupported operator
  11082. }
  11083. }
  11084. if (stack.length !== outputSize) {
  11085. return null;
  11086. }
  11087. var result = [];
  11088. instructions.forEach(function (instruction) {
  11089. var statementBuilder = new ExpressionBuilderVisitor();
  11090. instruction.visit(statementBuilder);
  11091. result.push(statementBuilder.toString());
  11092. });
  11093. stack.forEach(function (expr, i) {
  11094. var statementBuilder = new ExpressionBuilderVisitor();
  11095. expr.visit(statementBuilder);
  11096. var min = range[i * 2], max = range[i * 2 + 1];
  11097. var out = [statementBuilder.toString()];
  11098. if (min > expr.min) {
  11099. out.unshift('Math.max(', min, ', ');
  11100. out.push(')');
  11101. }
  11102. if (max < expr.max) {
  11103. out.unshift('Math.min(', max, ', ');
  11104. out.push(')');
  11105. }
  11106. out.unshift('dest[destOffset + ', i, '] = ');
  11107. out.push(';');
  11108. result.push(out.join(''));
  11109. });
  11110. return result.join('\n');
  11111. }
  11112. };
  11113. return PostScriptCompiler;
  11114. })();
  11115. var ColorSpace = (function ColorSpaceClosure() {
  11116. // Constructor should define this.numComps, this.defaultColor, this.name
  11117. function ColorSpace() {
  11118. error('should not call ColorSpace constructor');
  11119. }
  11120. ColorSpace.prototype = {
  11121. /**
  11122. * Converts the color value to the RGB color. The color components are
  11123. * located in the src array starting from the srcOffset. Returns the array
  11124. * of the rgb components, each value ranging from [0,255].
  11125. */
  11126. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11127. var rgb = new Uint8Array(3);
  11128. this.getRgbItem(src, srcOffset, rgb, 0);
  11129. return rgb;
  11130. },
  11131. /**
  11132. * Converts the color value to the RGB color, similar to the getRgb method.
  11133. * The result placed into the dest array starting from the destOffset.
  11134. */
  11135. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11136. dest, destOffset) {
  11137. error('Should not call ColorSpace.getRgbItem');
  11138. },
  11139. /**
  11140. * Converts the specified number of the color values to the RGB colors.
  11141. * The colors are located in the src array starting from the srcOffset.
  11142. * The result is placed into the dest array starting from the destOffset.
  11143. * The src array items shall be in [0,2^bits) range, the dest array items
  11144. * will be in [0,255] range. alpha01 indicates how many alpha components
  11145. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11146. * array).
  11147. */
  11148. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11149. dest, destOffset, bits,
  11150. alpha01) {
  11151. error('Should not call ColorSpace.getRgbBuffer');
  11152. },
  11153. /**
  11154. * Determines the number of bytes required to store the result of the
  11155. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11156. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11157. */
  11158. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11159. alpha01) {
  11160. error('Should not call ColorSpace.getOutputLength');
  11161. },
  11162. /**
  11163. * Returns true if source data will be equal the result/output data.
  11164. */
  11165. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11166. return false;
  11167. },
  11168. /**
  11169. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11170. * how many alpha components there are in the dest array; it will be either
  11171. * 0 (RGB array) or 1 (RGBA array).
  11172. */
  11173. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11174. originalHeight, width, height,
  11175. actualHeight, bpc, comps, alpha01) {
  11176. var count = originalWidth * originalHeight;
  11177. var rgbBuf = null;
  11178. var numComponentColors = 1 << bpc;
  11179. var needsResizing = originalHeight !== height || originalWidth !== width;
  11180. var i, ii;
  11181. if (this.isPassthrough(bpc)) {
  11182. rgbBuf = comps;
  11183. } else if (this.numComps === 1 && count > numComponentColors &&
  11184. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11185. // Optimization: create a color map when there is just one component and
  11186. // we are converting more colors than the size of the color map. We
  11187. // don't build the map if the colorspace is gray or rgb since those
  11188. // methods are faster than building a map. This mainly offers big speed
  11189. // ups for indexed and alternate colorspaces.
  11190. //
  11191. // TODO it may be worth while to cache the color map. While running
  11192. // testing I never hit a cache so I will leave that out for now (perhaps
  11193. // we are reparsing colorspaces too much?).
  11194. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11195. new Uint16Array(numComponentColors);
  11196. var key;
  11197. for (i = 0; i < numComponentColors; i++) {
  11198. allColors[i] = i;
  11199. }
  11200. var colorMap = new Uint8Array(numComponentColors * 3);
  11201. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11202. /* alpha01 = */ 0);
  11203. var destPos, rgbPos;
  11204. if (!needsResizing) {
  11205. // Fill in the RGB values directly into |dest|.
  11206. destPos = 0;
  11207. for (i = 0; i < count; ++i) {
  11208. key = comps[i] * 3;
  11209. dest[destPos++] = colorMap[key];
  11210. dest[destPos++] = colorMap[key + 1];
  11211. dest[destPos++] = colorMap[key + 2];
  11212. destPos += alpha01;
  11213. }
  11214. } else {
  11215. rgbBuf = new Uint8Array(count * 3);
  11216. rgbPos = 0;
  11217. for (i = 0; i < count; ++i) {
  11218. key = comps[i] * 3;
  11219. rgbBuf[rgbPos++] = colorMap[key];
  11220. rgbBuf[rgbPos++] = colorMap[key + 1];
  11221. rgbBuf[rgbPos++] = colorMap[key + 2];
  11222. }
  11223. }
  11224. } else {
  11225. if (!needsResizing) {
  11226. // Fill in the RGB values directly into |dest|.
  11227. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11228. alpha01);
  11229. } else {
  11230. rgbBuf = new Uint8Array(count * 3);
  11231. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11232. /* alpha01 = */ 0);
  11233. }
  11234. }
  11235. if (rgbBuf) {
  11236. if (needsResizing) {
  11237. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11238. height, dest, alpha01);
  11239. } else {
  11240. rgbPos = 0;
  11241. destPos = 0;
  11242. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11243. dest[destPos++] = rgbBuf[rgbPos++];
  11244. dest[destPos++] = rgbBuf[rgbPos++];
  11245. dest[destPos++] = rgbBuf[rgbPos++];
  11246. destPos += alpha01;
  11247. }
  11248. }
  11249. }
  11250. },
  11251. /**
  11252. * True if the colorspace has components in the default range of [0, 1].
  11253. * This should be true for all colorspaces except for lab color spaces
  11254. * which are [0,100], [-128, 127], [-128, 127].
  11255. */
  11256. usesZeroToOneRange: true
  11257. };
  11258. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11259. var IR = ColorSpace.parseToIR(cs, xref, res);
  11260. if (IR instanceof AlternateCS) {
  11261. return IR;
  11262. }
  11263. return ColorSpace.fromIR(IR);
  11264. };
  11265. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11266. var name = isArray(IR) ? IR[0] : IR;
  11267. var whitePoint, blackPoint, gamma;
  11268. switch (name) {
  11269. case 'DeviceGrayCS':
  11270. return this.singletons.gray;
  11271. case 'DeviceRgbCS':
  11272. return this.singletons.rgb;
  11273. case 'DeviceCmykCS':
  11274. return this.singletons.cmyk;
  11275. case 'CalGrayCS':
  11276. whitePoint = IR[1].WhitePoint;
  11277. blackPoint = IR[1].BlackPoint;
  11278. gamma = IR[1].Gamma;
  11279. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11280. case 'CalRGBCS':
  11281. whitePoint = IR[1].WhitePoint;
  11282. blackPoint = IR[1].BlackPoint;
  11283. gamma = IR[1].Gamma;
  11284. var matrix = IR[1].Matrix;
  11285. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11286. case 'PatternCS':
  11287. var basePatternCS = IR[1];
  11288. if (basePatternCS) {
  11289. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11290. }
  11291. return new PatternCS(basePatternCS);
  11292. case 'IndexedCS':
  11293. var baseIndexedCS = IR[1];
  11294. var hiVal = IR[2];
  11295. var lookup = IR[3];
  11296. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11297. case 'AlternateCS':
  11298. var numComps = IR[1];
  11299. var alt = IR[2];
  11300. var tintFnIR = IR[3];
  11301. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11302. PDFFunction.fromIR(tintFnIR));
  11303. case 'LabCS':
  11304. whitePoint = IR[1].WhitePoint;
  11305. blackPoint = IR[1].BlackPoint;
  11306. var range = IR[1].Range;
  11307. return new LabCS(whitePoint, blackPoint, range);
  11308. default:
  11309. error('Unknown name ' + name);
  11310. }
  11311. return null;
  11312. };
  11313. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11314. if (isName(cs)) {
  11315. var colorSpaces = res.get('ColorSpace');
  11316. if (isDict(colorSpaces)) {
  11317. var refcs = colorSpaces.get(cs.name);
  11318. if (refcs) {
  11319. cs = refcs;
  11320. }
  11321. }
  11322. }
  11323. cs = xref.fetchIfRef(cs);
  11324. var mode;
  11325. if (isName(cs)) {
  11326. mode = cs.name;
  11327. this.mode = mode;
  11328. switch (mode) {
  11329. case 'DeviceGray':
  11330. case 'G':
  11331. return 'DeviceGrayCS';
  11332. case 'DeviceRGB':
  11333. case 'RGB':
  11334. return 'DeviceRgbCS';
  11335. case 'DeviceCMYK':
  11336. case 'CMYK':
  11337. return 'DeviceCmykCS';
  11338. case 'Pattern':
  11339. return ['PatternCS', null];
  11340. default:
  11341. error('unrecognized colorspace ' + mode);
  11342. }
  11343. } else if (isArray(cs)) {
  11344. mode = cs[0].name;
  11345. this.mode = mode;
  11346. var numComps, params;
  11347. switch (mode) {
  11348. case 'DeviceGray':
  11349. case 'G':
  11350. return 'DeviceGrayCS';
  11351. case 'DeviceRGB':
  11352. case 'RGB':
  11353. return 'DeviceRgbCS';
  11354. case 'DeviceCMYK':
  11355. case 'CMYK':
  11356. return 'DeviceCmykCS';
  11357. case 'CalGray':
  11358. params = cs[1].getAll();
  11359. return ['CalGrayCS', params];
  11360. case 'CalRGB':
  11361. params = cs[1].getAll();
  11362. return ['CalRGBCS', params];
  11363. case 'ICCBased':
  11364. var stream = xref.fetchIfRef(cs[1]);
  11365. var dict = stream.dict;
  11366. numComps = dict.get('N');
  11367. if (numComps === 1) {
  11368. return 'DeviceGrayCS';
  11369. } else if (numComps === 3) {
  11370. return 'DeviceRgbCS';
  11371. } else if (numComps === 4) {
  11372. return 'DeviceCmykCS';
  11373. }
  11374. break;
  11375. case 'Pattern':
  11376. var basePatternCS = cs[1];
  11377. if (basePatternCS) {
  11378. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11379. }
  11380. return ['PatternCS', basePatternCS];
  11381. case 'Indexed':
  11382. case 'I':
  11383. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11384. var hiVal = cs[2] + 1;
  11385. var lookup = xref.fetchIfRef(cs[3]);
  11386. if (isStream(lookup)) {
  11387. lookup = lookup.getBytes();
  11388. }
  11389. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11390. case 'Separation':
  11391. case 'DeviceN':
  11392. var name = cs[1];
  11393. numComps = 1;
  11394. if (isName(name)) {
  11395. numComps = 1;
  11396. } else if (isArray(name)) {
  11397. numComps = name.length;
  11398. }
  11399. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11400. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11401. return ['AlternateCS', numComps, alt, tintFnIR];
  11402. case 'Lab':
  11403. params = cs[1].getAll();
  11404. return ['LabCS', params];
  11405. default:
  11406. error('unimplemented color space object "' + mode + '"');
  11407. }
  11408. } else {
  11409. error('unrecognized color space object: "' + cs + '"');
  11410. }
  11411. return null;
  11412. };
  11413. /**
  11414. * Checks if a decode map matches the default decode map for a color space.
  11415. * This handles the general decode maps where there are two values per
  11416. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11417. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11418. * slightly different.
  11419. * @param {Array} decode Decode map (usually from an image).
  11420. * @param {Number} n Number of components the color space has.
  11421. */
  11422. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11423. if (!decode) {
  11424. return true;
  11425. }
  11426. if (n * 2 !== decode.length) {
  11427. warn('The decode map is not the correct length');
  11428. return true;
  11429. }
  11430. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11431. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11432. return false;
  11433. }
  11434. }
  11435. return true;
  11436. };
  11437. ColorSpace.singletons = {
  11438. get gray() {
  11439. return shadow(this, 'gray', new DeviceGrayCS());
  11440. },
  11441. get rgb() {
  11442. return shadow(this, 'rgb', new DeviceRgbCS());
  11443. },
  11444. get cmyk() {
  11445. return shadow(this, 'cmyk', new DeviceCmykCS());
  11446. }
  11447. };
  11448. return ColorSpace;
  11449. })();
  11450. /**
  11451. * Alternate color space handles both Separation and DeviceN color spaces. A
  11452. * Separation color space is actually just a DeviceN with one color component.
  11453. * Both color spaces use a tinting function to convert colors to a base color
  11454. * space.
  11455. */
  11456. var AlternateCS = (function AlternateCSClosure() {
  11457. function AlternateCS(numComps, base, tintFn) {
  11458. this.name = 'Alternate';
  11459. this.numComps = numComps;
  11460. this.defaultColor = new Float32Array(numComps);
  11461. for (var i = 0; i < numComps; ++i) {
  11462. this.defaultColor[i] = 1;
  11463. }
  11464. this.base = base;
  11465. this.tintFn = tintFn;
  11466. this.tmpBuf = new Float32Array(base.numComps);
  11467. }
  11468. AlternateCS.prototype = {
  11469. getRgb: ColorSpace.prototype.getRgb,
  11470. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11471. dest, destOffset) {
  11472. var tmpBuf = this.tmpBuf;
  11473. this.tintFn(src, srcOffset, tmpBuf, 0);
  11474. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11475. },
  11476. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11477. dest, destOffset, bits,
  11478. alpha01) {
  11479. var tintFn = this.tintFn;
  11480. var base = this.base;
  11481. var scale = 1 / ((1 << bits) - 1);
  11482. var baseNumComps = base.numComps;
  11483. var usesZeroToOneRange = base.usesZeroToOneRange;
  11484. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11485. alpha01 === 0;
  11486. var pos = isPassthrough ? destOffset : 0;
  11487. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11488. var numComps = this.numComps;
  11489. var scaled = new Float32Array(numComps);
  11490. var tinted = new Float32Array(baseNumComps);
  11491. var i, j;
  11492. if (usesZeroToOneRange) {
  11493. for (i = 0; i < count; i++) {
  11494. for (j = 0; j < numComps; j++) {
  11495. scaled[j] = src[srcOffset++] * scale;
  11496. }
  11497. tintFn(scaled, 0, tinted, 0);
  11498. for (j = 0; j < baseNumComps; j++) {
  11499. baseBuf[pos++] = tinted[j] * 255;
  11500. }
  11501. }
  11502. } else {
  11503. for (i = 0; i < count; i++) {
  11504. for (j = 0; j < numComps; j++) {
  11505. scaled[j] = src[srcOffset++] * scale;
  11506. }
  11507. tintFn(scaled, 0, tinted, 0);
  11508. base.getRgbItem(tinted, 0, baseBuf, pos);
  11509. pos += baseNumComps;
  11510. }
  11511. }
  11512. if (!isPassthrough) {
  11513. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11514. }
  11515. },
  11516. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11517. alpha01) {
  11518. return this.base.getOutputLength(inputLength *
  11519. this.base.numComps / this.numComps,
  11520. alpha01);
  11521. },
  11522. isPassthrough: ColorSpace.prototype.isPassthrough,
  11523. fillRgb: ColorSpace.prototype.fillRgb,
  11524. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11525. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11526. },
  11527. usesZeroToOneRange: true
  11528. };
  11529. return AlternateCS;
  11530. })();
  11531. var PatternCS = (function PatternCSClosure() {
  11532. function PatternCS(baseCS) {
  11533. this.name = 'Pattern';
  11534. this.base = baseCS;
  11535. }
  11536. PatternCS.prototype = {};
  11537. return PatternCS;
  11538. })();
  11539. var IndexedCS = (function IndexedCSClosure() {
  11540. function IndexedCS(base, highVal, lookup) {
  11541. this.name = 'Indexed';
  11542. this.numComps = 1;
  11543. this.defaultColor = new Uint8Array([0]);
  11544. this.base = base;
  11545. this.highVal = highVal;
  11546. var baseNumComps = base.numComps;
  11547. var length = baseNumComps * highVal;
  11548. var lookupArray;
  11549. if (isStream(lookup)) {
  11550. lookupArray = new Uint8Array(length);
  11551. var bytes = lookup.getBytes(length);
  11552. lookupArray.set(bytes);
  11553. } else if (isString(lookup)) {
  11554. lookupArray = new Uint8Array(length);
  11555. for (var i = 0; i < length; ++i) {
  11556. lookupArray[i] = lookup.charCodeAt(i);
  11557. }
  11558. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11559. lookupArray = lookup;
  11560. } else {
  11561. error('Unrecognized lookup table: ' + lookup);
  11562. }
  11563. this.lookup = lookupArray;
  11564. }
  11565. IndexedCS.prototype = {
  11566. getRgb: ColorSpace.prototype.getRgb,
  11567. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11568. dest, destOffset) {
  11569. var numComps = this.base.numComps;
  11570. var start = src[srcOffset] * numComps;
  11571. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11572. },
  11573. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11574. dest, destOffset, bits,
  11575. alpha01) {
  11576. var base = this.base;
  11577. var numComps = base.numComps;
  11578. var outputDelta = base.getOutputLength(numComps, alpha01);
  11579. var lookup = this.lookup;
  11580. for (var i = 0; i < count; ++i) {
  11581. var lookupPos = src[srcOffset++] * numComps;
  11582. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11583. destOffset += outputDelta;
  11584. }
  11585. },
  11586. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11587. return this.base.getOutputLength(inputLength * this.base.numComps,
  11588. alpha01);
  11589. },
  11590. isPassthrough: ColorSpace.prototype.isPassthrough,
  11591. fillRgb: ColorSpace.prototype.fillRgb,
  11592. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11593. // indexed color maps shouldn't be changed
  11594. return true;
  11595. },
  11596. usesZeroToOneRange: true
  11597. };
  11598. return IndexedCS;
  11599. })();
  11600. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11601. function DeviceGrayCS() {
  11602. this.name = 'DeviceGray';
  11603. this.numComps = 1;
  11604. this.defaultColor = new Float32Array([0]);
  11605. }
  11606. DeviceGrayCS.prototype = {
  11607. getRgb: ColorSpace.prototype.getRgb,
  11608. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11609. dest, destOffset) {
  11610. var c = (src[srcOffset] * 255) | 0;
  11611. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11612. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11613. },
  11614. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11615. dest, destOffset, bits,
  11616. alpha01) {
  11617. var scale = 255 / ((1 << bits) - 1);
  11618. var j = srcOffset, q = destOffset;
  11619. for (var i = 0; i < count; ++i) {
  11620. var c = (scale * src[j++]) | 0;
  11621. dest[q++] = c;
  11622. dest[q++] = c;
  11623. dest[q++] = c;
  11624. q += alpha01;
  11625. }
  11626. },
  11627. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11628. alpha01) {
  11629. return inputLength * (3 + alpha01);
  11630. },
  11631. isPassthrough: ColorSpace.prototype.isPassthrough,
  11632. fillRgb: ColorSpace.prototype.fillRgb,
  11633. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11634. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11635. },
  11636. usesZeroToOneRange: true
  11637. };
  11638. return DeviceGrayCS;
  11639. })();
  11640. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11641. function DeviceRgbCS() {
  11642. this.name = 'DeviceRGB';
  11643. this.numComps = 3;
  11644. this.defaultColor = new Float32Array([0, 0, 0]);
  11645. }
  11646. DeviceRgbCS.prototype = {
  11647. getRgb: ColorSpace.prototype.getRgb,
  11648. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11649. dest, destOffset) {
  11650. var r = (src[srcOffset] * 255) | 0;
  11651. var g = (src[srcOffset + 1] * 255) | 0;
  11652. var b = (src[srcOffset + 2] * 255) | 0;
  11653. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11654. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11655. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11656. },
  11657. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11658. dest, destOffset, bits,
  11659. alpha01) {
  11660. if (bits === 8 && alpha01 === 0) {
  11661. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11662. return;
  11663. }
  11664. var scale = 255 / ((1 << bits) - 1);
  11665. var j = srcOffset, q = destOffset;
  11666. for (var i = 0; i < count; ++i) {
  11667. dest[q++] = (scale * src[j++]) | 0;
  11668. dest[q++] = (scale * src[j++]) | 0;
  11669. dest[q++] = (scale * src[j++]) | 0;
  11670. q += alpha01;
  11671. }
  11672. },
  11673. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  11674. alpha01) {
  11675. return (inputLength * (3 + alpha01) / 3) | 0;
  11676. },
  11677. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  11678. return bits === 8;
  11679. },
  11680. fillRgb: ColorSpace.prototype.fillRgb,
  11681. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  11682. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11683. },
  11684. usesZeroToOneRange: true
  11685. };
  11686. return DeviceRgbCS;
  11687. })();
  11688. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  11689. // The coefficients below was found using numerical analysis: the method of
  11690. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  11691. // where color_value is the tabular value from the table of sampled RGB colors
  11692. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  11693. // CMYK color conversion using the estimation below:
  11694. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  11695. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  11696. var c = src[srcOffset + 0] * srcScale;
  11697. var m = src[srcOffset + 1] * srcScale;
  11698. var y = src[srcOffset + 2] * srcScale;
  11699. var k = src[srcOffset + 3] * srcScale;
  11700. var r =
  11701. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11702. 18.82290502165302 * y + 212.25662451639585 * k +
  11703. -285.2331026137004) +
  11704. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  11705. -17.873870861415444 * k - 5.497006427196366) +
  11706. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11707. 17.5119270841813) +
  11708. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  11709. var g =
  11710. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  11711. 6.871425592049007 * y + 31.159100130055922 * k +
  11712. -79.2970844816548) +
  11713. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11714. 131.35250912493976 * k - 190.9453302588951) +
  11715. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  11716. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  11717. var b =
  11718. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11719. 30.89978309703729 * y - 0.23883238689178934 * k +
  11720. -14.183576799673286) +
  11721. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11722. 50.606957656360734 * k - 112.23884253719248) +
  11723. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  11724. -193.58209356861505) +
  11725. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  11726. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  11727. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  11728. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  11729. }
  11730. function DeviceCmykCS() {
  11731. this.name = 'DeviceCMYK';
  11732. this.numComps = 4;
  11733. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  11734. }
  11735. DeviceCmykCS.prototype = {
  11736. getRgb: ColorSpace.prototype.getRgb,
  11737. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  11738. dest, destOffset) {
  11739. convertToRgb(src, srcOffset, 1, dest, destOffset);
  11740. },
  11741. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  11742. dest, destOffset, bits,
  11743. alpha01) {
  11744. var scale = 1 / ((1 << bits) - 1);
  11745. for (var i = 0; i < count; i++) {
  11746. convertToRgb(src, srcOffset, scale, dest, destOffset);
  11747. srcOffset += 4;
  11748. destOffset += 3 + alpha01;
  11749. }
  11750. },
  11751. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  11752. alpha01) {
  11753. return (inputLength / 4 * (3 + alpha01)) | 0;
  11754. },
  11755. isPassthrough: ColorSpace.prototype.isPassthrough,
  11756. fillRgb: ColorSpace.prototype.fillRgb,
  11757. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  11758. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11759. },
  11760. usesZeroToOneRange: true
  11761. };
  11762. return DeviceCmykCS;
  11763. })();
  11764. //
  11765. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  11766. //
  11767. var CalGrayCS = (function CalGrayCSClosure() {
  11768. function CalGrayCS(whitePoint, blackPoint, gamma) {
  11769. this.name = 'CalGray';
  11770. this.numComps = 1;
  11771. this.defaultColor = new Float32Array([0]);
  11772. if (!whitePoint) {
  11773. error('WhitePoint missing - required for color space CalGray');
  11774. }
  11775. blackPoint = blackPoint || [0, 0, 0];
  11776. gamma = gamma || 1;
  11777. // Translate arguments to spec variables.
  11778. this.XW = whitePoint[0];
  11779. this.YW = whitePoint[1];
  11780. this.ZW = whitePoint[2];
  11781. this.XB = blackPoint[0];
  11782. this.YB = blackPoint[1];
  11783. this.ZB = blackPoint[2];
  11784. this.G = gamma;
  11785. // Validate variables as per spec.
  11786. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  11787. error('Invalid WhitePoint components for ' + this.name +
  11788. ', no fallback available');
  11789. }
  11790. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  11791. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  11792. this.XB = this.YB = this.ZB = 0;
  11793. }
  11794. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  11795. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  11796. ', ZB: ' + this.ZB + ', only default values are supported.');
  11797. }
  11798. if (this.G < 1) {
  11799. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  11800. ', falling back to default');
  11801. this.G = 1;
  11802. }
  11803. }
  11804. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  11805. // A represents a gray component of a calibrated gray space.
  11806. // A <---> AG in the spec
  11807. var A = src[srcOffset] * scale;
  11808. var AG = Math.pow(A, cs.G);
  11809. // Computes L as per spec. ( = cs.YW * AG )
  11810. // Except if other than default BlackPoint values are used.
  11811. var L = cs.YW * AG;
  11812. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  11813. // Convert values to rgb range [0, 255].
  11814. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  11815. dest[destOffset] = val;
  11816. dest[destOffset + 1] = val;
  11817. dest[destOffset + 2] = val;
  11818. }
  11819. CalGrayCS.prototype = {
  11820. getRgb: ColorSpace.prototype.getRgb,
  11821. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  11822. dest, destOffset) {
  11823. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  11824. },
  11825. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  11826. dest, destOffset, bits,
  11827. alpha01) {
  11828. var scale = 1 / ((1 << bits) - 1);
  11829. for (var i = 0; i < count; ++i) {
  11830. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  11831. srcOffset += 1;
  11832. destOffset += 3 + alpha01;
  11833. }
  11834. },
  11835. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  11836. return inputLength * (3 + alpha01);
  11837. },
  11838. isPassthrough: ColorSpace.prototype.isPassthrough,
  11839. fillRgb: ColorSpace.prototype.fillRgb,
  11840. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  11841. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11842. },
  11843. usesZeroToOneRange: true
  11844. };
  11845. return CalGrayCS;
  11846. })();
  11847. //
  11848. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  11849. //
  11850. var CalRGBCS = (function CalRGBCSClosure() {
  11851. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  11852. // matrices.
  11853. var BRADFORD_SCALE_MATRIX = new Float32Array([
  11854. 0.8951, 0.2664, -0.1614,
  11855. -0.7502, 1.7135, 0.0367,
  11856. 0.0389, -0.0685, 1.0296]);
  11857. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  11858. 0.9869929, -0.1470543, 0.1599627,
  11859. 0.4323053, 0.5183603, 0.0492912,
  11860. -0.0085287, 0.0400428, 0.9684867]);
  11861. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  11862. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  11863. 3.2404542, -1.5371385, -0.4985314,
  11864. -0.9692660, 1.8760108, 0.0415560,
  11865. 0.0556434, -0.2040259, 1.0572252]);
  11866. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  11867. var tempNormalizeMatrix = new Float32Array(3);
  11868. var tempConvertMatrix1 = new Float32Array(3);
  11869. var tempConvertMatrix2 = new Float32Array(3);
  11870. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  11871. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  11872. this.name = 'CalRGB';
  11873. this.numComps = 3;
  11874. this.defaultColor = new Float32Array(3);
  11875. if (!whitePoint) {
  11876. error('WhitePoint missing - required for color space CalRGB');
  11877. }
  11878. blackPoint = blackPoint || new Float32Array(3);
  11879. gamma = gamma || new Float32Array([1, 1, 1]);
  11880. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  11881. // Translate arguments to spec variables.
  11882. var XW = whitePoint[0];
  11883. var YW = whitePoint[1];
  11884. var ZW = whitePoint[2];
  11885. this.whitePoint = whitePoint;
  11886. var XB = blackPoint[0];
  11887. var YB = blackPoint[1];
  11888. var ZB = blackPoint[2];
  11889. this.blackPoint = blackPoint;
  11890. this.GR = gamma[0];
  11891. this.GG = gamma[1];
  11892. this.GB = gamma[2];
  11893. this.MXA = matrix[0];
  11894. this.MYA = matrix[1];
  11895. this.MZA = matrix[2];
  11896. this.MXB = matrix[3];
  11897. this.MYB = matrix[4];
  11898. this.MZB = matrix[5];
  11899. this.MXC = matrix[6];
  11900. this.MYC = matrix[7];
  11901. this.MZC = matrix[8];
  11902. // Validate variables as per spec.
  11903. if (XW < 0 || ZW < 0 || YW !== 1) {
  11904. error('Invalid WhitePoint components for ' + this.name +
  11905. ', no fallback available');
  11906. }
  11907. if (XB < 0 || YB < 0 || ZB < 0) {
  11908. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  11909. ', ' + ZB + '], falling back to default');
  11910. this.blackPoint = new Float32Array(3);
  11911. }
  11912. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  11913. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  11914. '] for ' + this.name + ', falling back to default');
  11915. this.GR = this.GG = this.GB = 1;
  11916. }
  11917. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  11918. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  11919. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  11920. info('Invalid Matrix for ' + this.name + ' [' +
  11921. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  11922. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  11923. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  11924. '], falling back to default');
  11925. this.MXA = this.MYB = this.MZC = 1;
  11926. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  11927. }
  11928. }
  11929. function matrixProduct(a, b, result) {
  11930. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  11931. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  11932. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  11933. }
  11934. function convertToFlat(sourceWhitePoint, LMS, result) {
  11935. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  11936. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  11937. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  11938. }
  11939. function convertToD65(sourceWhitePoint, LMS, result) {
  11940. var D65X = 0.95047;
  11941. var D65Y = 1;
  11942. var D65Z = 1.08883;
  11943. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  11944. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  11945. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  11946. }
  11947. function sRGBTransferFunction(color) {
  11948. // See http://en.wikipedia.org/wiki/SRGB.
  11949. if (color <= 0.0031308){
  11950. return adjustToRange(0, 1, 12.92 * color);
  11951. }
  11952. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  11953. }
  11954. function adjustToRange(min, max, value) {
  11955. return Math.max(min, Math.min(max, value));
  11956. }
  11957. function decodeL(L) {
  11958. if (L < 0) {
  11959. return -decodeL(-L);
  11960. }
  11961. if (L > 8.0) {
  11962. return Math.pow(((L + 16) / 116), 3);
  11963. }
  11964. return L * DECODE_L_CONSTANT;
  11965. }
  11966. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  11967. // In case the blackPoint is already the default blackPoint then there is
  11968. // no need to do compensation.
  11969. if (sourceBlackPoint[0] === 0 &&
  11970. sourceBlackPoint[1] === 0 &&
  11971. sourceBlackPoint[2] === 0) {
  11972. result[0] = XYZ_Flat[0];
  11973. result[1] = XYZ_Flat[1];
  11974. result[2] = XYZ_Flat[2];
  11975. return;
  11976. }
  11977. // For the blackPoint calculation details, please see
  11978. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  11979. // AdobeBPC.pdf.
  11980. // The destination blackPoint is the default blackPoint [0, 0, 0].
  11981. var zeroDecodeL = decodeL(0);
  11982. var X_DST = zeroDecodeL;
  11983. var X_SRC = decodeL(sourceBlackPoint[0]);
  11984. var Y_DST = zeroDecodeL;
  11985. var Y_SRC = decodeL(sourceBlackPoint[1]);
  11986. var Z_DST = zeroDecodeL;
  11987. var Z_SRC = decodeL(sourceBlackPoint[2]);
  11988. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  11989. var X_Offset = 1 - X_Scale;
  11990. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  11991. var Y_Offset = 1 - Y_Scale;
  11992. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  11993. var Z_Offset = 1 - Z_Scale;
  11994. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  11995. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  11996. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  11997. }
  11998. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  11999. // In case the whitePoint is already flat then there is no need to do
  12000. // normalization.
  12001. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12002. result[0] = XYZ_In[0];
  12003. result[1] = XYZ_In[1];
  12004. result[2] = XYZ_In[2];
  12005. return;
  12006. }
  12007. var LMS = result;
  12008. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12009. var LMS_Flat = tempNormalizeMatrix;
  12010. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12011. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12012. }
  12013. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12014. var LMS = result;
  12015. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12016. var LMS_D65 = tempNormalizeMatrix;
  12017. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12018. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12019. }
  12020. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12021. // A, B and C represent a red, green and blue components of a calibrated
  12022. // rgb space.
  12023. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12024. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12025. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12026. // A <---> AGR in the spec
  12027. // B <---> BGG in the spec
  12028. // C <---> CGB in the spec
  12029. var AGR = Math.pow(A, cs.GR);
  12030. var BGG = Math.pow(B, cs.GG);
  12031. var CGB = Math.pow(C, cs.GB);
  12032. // Computes intermediate variables L, M, N as per spec.
  12033. // To decode X, Y, Z values map L, M, N directly to them.
  12034. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12035. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12036. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12037. // The following calculations are based on this document:
  12038. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12039. // AdobeBPC.pdf.
  12040. var XYZ = tempConvertMatrix1;
  12041. XYZ[0] = X;
  12042. XYZ[1] = Y;
  12043. XYZ[2] = Z;
  12044. var XYZ_Flat = tempConvertMatrix2;
  12045. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12046. var XYZ_Black = tempConvertMatrix1;
  12047. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12048. var XYZ_D65 = tempConvertMatrix2;
  12049. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12050. var SRGB = tempConvertMatrix1;
  12051. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12052. var sR = sRGBTransferFunction(SRGB[0]);
  12053. var sG = sRGBTransferFunction(SRGB[1]);
  12054. var sB = sRGBTransferFunction(SRGB[2]);
  12055. // Convert the values to rgb range [0, 255].
  12056. dest[destOffset] = Math.round(sR * 255);
  12057. dest[destOffset + 1] = Math.round(sG * 255);
  12058. dest[destOffset + 2] = Math.round(sB * 255);
  12059. }
  12060. CalRGBCS.prototype = {
  12061. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12062. var rgb = new Uint8Array(3);
  12063. this.getRgbItem(src, srcOffset, rgb, 0);
  12064. return rgb;
  12065. },
  12066. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12067. dest, destOffset) {
  12068. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12069. },
  12070. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12071. dest, destOffset, bits,
  12072. alpha01) {
  12073. var scale = 1 / ((1 << bits) - 1);
  12074. for (var i = 0; i < count; ++i) {
  12075. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12076. srcOffset += 3;
  12077. destOffset += 3 + alpha01;
  12078. }
  12079. },
  12080. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12081. return (inputLength * (3 + alpha01) / 3) | 0;
  12082. },
  12083. isPassthrough: ColorSpace.prototype.isPassthrough,
  12084. fillRgb: ColorSpace.prototype.fillRgb,
  12085. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12086. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12087. },
  12088. usesZeroToOneRange: true
  12089. };
  12090. return CalRGBCS;
  12091. })();
  12092. //
  12093. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12094. //
  12095. var LabCS = (function LabCSClosure() {
  12096. function LabCS(whitePoint, blackPoint, range) {
  12097. this.name = 'Lab';
  12098. this.numComps = 3;
  12099. this.defaultColor = new Float32Array([0, 0, 0]);
  12100. if (!whitePoint) {
  12101. error('WhitePoint missing - required for color space Lab');
  12102. }
  12103. blackPoint = blackPoint || [0, 0, 0];
  12104. range = range || [-100, 100, -100, 100];
  12105. // Translate args to spec variables
  12106. this.XW = whitePoint[0];
  12107. this.YW = whitePoint[1];
  12108. this.ZW = whitePoint[2];
  12109. this.amin = range[0];
  12110. this.amax = range[1];
  12111. this.bmin = range[2];
  12112. this.bmax = range[3];
  12113. // These are here just for completeness - the spec doesn't offer any
  12114. // formulas that use BlackPoint in Lab
  12115. this.XB = blackPoint[0];
  12116. this.YB = blackPoint[1];
  12117. this.ZB = blackPoint[2];
  12118. // Validate vars as per spec
  12119. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12120. error('Invalid WhitePoint components, no fallback available');
  12121. }
  12122. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12123. info('Invalid BlackPoint, falling back to default');
  12124. this.XB = this.YB = this.ZB = 0;
  12125. }
  12126. if (this.amin > this.amax || this.bmin > this.bmax) {
  12127. info('Invalid Range, falling back to defaults');
  12128. this.amin = -100;
  12129. this.amax = 100;
  12130. this.bmin = -100;
  12131. this.bmax = 100;
  12132. }
  12133. }
  12134. // Function g(x) from spec
  12135. function fn_g(x) {
  12136. if (x >= 6 / 29) {
  12137. return x * x * x;
  12138. } else {
  12139. return (108 / 841) * (x - 4 / 29);
  12140. }
  12141. }
  12142. function decode(value, high1, low2, high2) {
  12143. return low2 + (value) * (high2 - low2) / (high1);
  12144. }
  12145. // If decoding is needed maxVal should be 2^bits per component - 1.
  12146. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12147. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12148. // not the usual [0, 1]. If a command like setFillColor is used the src
  12149. // values will already be within the correct range. However, if we are
  12150. // converting an image we have to map the values to the correct range given
  12151. // above.
  12152. // Ls,as,bs <---> L*,a*,b* in the spec
  12153. var Ls = src[srcOffset];
  12154. var as = src[srcOffset + 1];
  12155. var bs = src[srcOffset + 2];
  12156. if (maxVal !== false) {
  12157. Ls = decode(Ls, maxVal, 0, 100);
  12158. as = decode(as, maxVal, cs.amin, cs.amax);
  12159. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12160. }
  12161. // Adjust limits of 'as' and 'bs'
  12162. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12163. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12164. // Computes intermediate variables X,Y,Z as per spec
  12165. var M = (Ls + 16) / 116;
  12166. var L = M + (as / 500);
  12167. var N = M - (bs / 200);
  12168. var X = cs.XW * fn_g(L);
  12169. var Y = cs.YW * fn_g(M);
  12170. var Z = cs.ZW * fn_g(N);
  12171. var r, g, b;
  12172. // Using different conversions for D50 and D65 white points,
  12173. // per http://www.color.org/srgb.pdf
  12174. if (cs.ZW < 1) {
  12175. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12176. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12177. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12178. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12179. } else {
  12180. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12181. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12182. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12183. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12184. }
  12185. // clamp color values to [0,1] range then convert to [0,255] range.
  12186. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12187. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12188. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12189. }
  12190. LabCS.prototype = {
  12191. getRgb: ColorSpace.prototype.getRgb,
  12192. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12193. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12194. },
  12195. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12196. dest, destOffset, bits,
  12197. alpha01) {
  12198. var maxVal = (1 << bits) - 1;
  12199. for (var i = 0; i < count; i++) {
  12200. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12201. srcOffset += 3;
  12202. destOffset += 3 + alpha01;
  12203. }
  12204. },
  12205. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12206. return (inputLength * (3 + alpha01) / 3) | 0;
  12207. },
  12208. isPassthrough: ColorSpace.prototype.isPassthrough,
  12209. fillRgb: ColorSpace.prototype.fillRgb,
  12210. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12211. // XXX: Decoding is handled with the lab conversion because of the strange
  12212. // ranges that are used.
  12213. return true;
  12214. },
  12215. usesZeroToOneRange: false
  12216. };
  12217. return LabCS;
  12218. })();
  12219. var ARCFourCipher = (function ARCFourCipherClosure() {
  12220. function ARCFourCipher(key) {
  12221. this.a = 0;
  12222. this.b = 0;
  12223. var s = new Uint8Array(256);
  12224. var i, j = 0, tmp, keyLength = key.length;
  12225. for (i = 0; i < 256; ++i) {
  12226. s[i] = i;
  12227. }
  12228. for (i = 0; i < 256; ++i) {
  12229. tmp = s[i];
  12230. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12231. s[i] = s[j];
  12232. s[j] = tmp;
  12233. }
  12234. this.s = s;
  12235. }
  12236. ARCFourCipher.prototype = {
  12237. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12238. var i, n = data.length, tmp, tmp2;
  12239. var a = this.a, b = this.b, s = this.s;
  12240. var output = new Uint8Array(n);
  12241. for (i = 0; i < n; ++i) {
  12242. a = (a + 1) & 0xFF;
  12243. tmp = s[a];
  12244. b = (b + tmp) & 0xFF;
  12245. tmp2 = s[b];
  12246. s[a] = tmp2;
  12247. s[b] = tmp;
  12248. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12249. }
  12250. this.a = a;
  12251. this.b = b;
  12252. return output;
  12253. }
  12254. };
  12255. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12256. return ARCFourCipher;
  12257. })();
  12258. var calculateMD5 = (function calculateMD5Closure() {
  12259. var r = new Uint8Array([
  12260. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12261. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12262. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12263. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12264. var k = new Int32Array([
  12265. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12266. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12267. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12268. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12269. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12270. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12271. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12272. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12273. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12274. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12275. -145523070, -1120210379, 718787259, -343485551]);
  12276. function hash(data, offset, length) {
  12277. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12278. // pre-processing
  12279. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12280. var padded = new Uint8Array(paddedLength);
  12281. var i, j, n;
  12282. for (i = 0; i < length; ++i) {
  12283. padded[i] = data[offset++];
  12284. }
  12285. padded[i++] = 0x80;
  12286. n = paddedLength - 8;
  12287. while (i < n) {
  12288. padded[i++] = 0;
  12289. }
  12290. padded[i++] = (length << 3) & 0xFF;
  12291. padded[i++] = (length >> 5) & 0xFF;
  12292. padded[i++] = (length >> 13) & 0xFF;
  12293. padded[i++] = (length >> 21) & 0xFF;
  12294. padded[i++] = (length >>> 29) & 0xFF;
  12295. padded[i++] = 0;
  12296. padded[i++] = 0;
  12297. padded[i++] = 0;
  12298. var w = new Int32Array(16);
  12299. for (i = 0; i < paddedLength;) {
  12300. for (j = 0; j < 16; ++j, i += 4) {
  12301. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12302. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12303. }
  12304. var a = h0, b = h1, c = h2, d = h3, f, g;
  12305. for (j = 0; j < 64; ++j) {
  12306. if (j < 16) {
  12307. f = (b & c) | ((~b) & d);
  12308. g = j;
  12309. } else if (j < 32) {
  12310. f = (d & b) | ((~d) & c);
  12311. g = (5 * j + 1) & 15;
  12312. } else if (j < 48) {
  12313. f = b ^ c ^ d;
  12314. g = (3 * j + 5) & 15;
  12315. } else {
  12316. f = c ^ (b | (~d));
  12317. g = (7 * j) & 15;
  12318. }
  12319. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12320. d = c;
  12321. c = b;
  12322. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12323. a = tmp;
  12324. }
  12325. h0 = (h0 + a) | 0;
  12326. h1 = (h1 + b) | 0;
  12327. h2 = (h2 + c) | 0;
  12328. h3 = (h3 + d) | 0;
  12329. }
  12330. return new Uint8Array([
  12331. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12332. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12333. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12334. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12335. ]);
  12336. }
  12337. return hash;
  12338. })();
  12339. var Word64 = (function Word64Closure() {
  12340. function Word64(highInteger, lowInteger) {
  12341. this.high = highInteger | 0;
  12342. this.low = lowInteger | 0;
  12343. }
  12344. Word64.prototype = {
  12345. and: function Word64_and(word) {
  12346. this.high &= word.high;
  12347. this.low &= word.low;
  12348. },
  12349. xor: function Word64_xor(word) {
  12350. this.high ^= word.high;
  12351. this.low ^= word.low;
  12352. },
  12353. or: function Word64_or(word) {
  12354. this.high |= word.high;
  12355. this.low |= word.low;
  12356. },
  12357. shiftRight: function Word64_shiftRight(places) {
  12358. if (places >= 32) {
  12359. this.low = (this.high >>> (places - 32)) | 0;
  12360. this.high = 0;
  12361. } else {
  12362. this.low = (this.low >>> places) | (this.high << (32 - places));
  12363. this.high = (this.high >>> places) | 0;
  12364. }
  12365. },
  12366. shiftLeft: function Word64_shiftLeft(places) {
  12367. if (places >= 32) {
  12368. this.high = this.low << (places - 32);
  12369. this.low = 0;
  12370. } else {
  12371. this.high = (this.high << places) | (this.low >>> (32 - places));
  12372. this.low = this.low << places;
  12373. }
  12374. },
  12375. rotateRight: function Word64_rotateRight(places) {
  12376. var low, high;
  12377. if (places & 32) {
  12378. high = this.low;
  12379. low = this.high;
  12380. } else {
  12381. low = this.low;
  12382. high = this.high;
  12383. }
  12384. places &= 31;
  12385. this.low = (low >>> places) | (high << (32 - places));
  12386. this.high = (high >>> places) | (low << (32 - places));
  12387. },
  12388. not: function Word64_not() {
  12389. this.high = ~this.high;
  12390. this.low = ~this.low;
  12391. },
  12392. add: function Word64_add(word) {
  12393. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12394. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12395. if (lowAdd > 0xFFFFFFFF) {
  12396. highAdd += 1;
  12397. }
  12398. this.low = lowAdd | 0;
  12399. this.high = highAdd | 0;
  12400. },
  12401. copyTo: function Word64_copyTo(bytes, offset) {
  12402. bytes[offset] = (this.high >>> 24) & 0xFF;
  12403. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12404. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12405. bytes[offset + 3] = this.high & 0xFF;
  12406. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12407. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12408. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12409. bytes[offset + 7] = this.low & 0xFF;
  12410. },
  12411. assign: function Word64_assign(word) {
  12412. this.high = word.high;
  12413. this.low = word.low;
  12414. }
  12415. };
  12416. return Word64;
  12417. })();
  12418. var calculateSHA256 = (function calculateSHA256Closure() {
  12419. function rotr(x, n) {
  12420. return (x >>> n) | (x << 32 - n);
  12421. }
  12422. function ch(x, y, z) {
  12423. return (x & y) ^ (~x & z);
  12424. }
  12425. function maj(x, y, z) {
  12426. return (x & y) ^ (x & z) ^ (y & z);
  12427. }
  12428. function sigma(x) {
  12429. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12430. }
  12431. function sigmaPrime(x) {
  12432. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12433. }
  12434. function littleSigma(x) {
  12435. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12436. }
  12437. function littleSigmaPrime(x) {
  12438. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12439. }
  12440. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12441. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12442. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12443. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12444. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12445. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12446. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12447. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12448. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12449. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12450. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12451. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12452. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12453. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12454. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12455. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12456. function hash(data, offset, length) {
  12457. // initial hash values
  12458. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12459. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12460. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12461. // pre-processing
  12462. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12463. var padded = new Uint8Array(paddedLength);
  12464. var i, j, n;
  12465. for (i = 0; i < length; ++i) {
  12466. padded[i] = data[offset++];
  12467. }
  12468. padded[i++] = 0x80;
  12469. n = paddedLength - 8;
  12470. while (i < n) {
  12471. padded[i++] = 0;
  12472. }
  12473. padded[i++] = 0;
  12474. padded[i++] = 0;
  12475. padded[i++] = 0;
  12476. padded[i++] = (length >>> 29) & 0xFF;
  12477. padded[i++] = (length >> 21) & 0xFF;
  12478. padded[i++] = (length >> 13) & 0xFF;
  12479. padded[i++] = (length >> 5) & 0xFF;
  12480. padded[i++] = (length << 3) & 0xFF;
  12481. var w = new Uint32Array(64);
  12482. // for each 512 bit block
  12483. for (i = 0; i < paddedLength;) {
  12484. for (j = 0; j < 16; ++j) {
  12485. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12486. (padded[i + 2] << 8) | (padded[i + 3]));
  12487. i += 4;
  12488. }
  12489. for (j = 16; j < 64; ++j) {
  12490. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12491. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12492. }
  12493. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12494. f = h5, g = h6, h = h7, t1, t2;
  12495. for (j = 0; j < 64; ++j) {
  12496. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12497. t2 = sigma(a) + maj(a, b, c);
  12498. h = g;
  12499. g = f;
  12500. f = e;
  12501. e = (d + t1) | 0;
  12502. d = c;
  12503. c = b;
  12504. b = a;
  12505. a = (t1 + t2) | 0;
  12506. }
  12507. h0 = (h0 + a) | 0;
  12508. h1 = (h1 + b) | 0;
  12509. h2 = (h2 + c) | 0;
  12510. h3 = (h3 + d) | 0;
  12511. h4 = (h4 + e) | 0;
  12512. h5 = (h5 + f) | 0;
  12513. h6 = (h6 + g) | 0;
  12514. h7 = (h7 + h) | 0;
  12515. }
  12516. return new Uint8Array([
  12517. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12518. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12519. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12520. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12521. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12522. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12523. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12524. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12525. ]);
  12526. }
  12527. return hash;
  12528. })();
  12529. var calculateSHA512 = (function calculateSHA512Closure() {
  12530. function ch(result, x, y, z, tmp) {
  12531. result.assign(x);
  12532. result.and(y);
  12533. tmp.assign(x);
  12534. tmp.not();
  12535. tmp.and(z);
  12536. result.xor(tmp);
  12537. }
  12538. function maj(result, x, y, z, tmp) {
  12539. result.assign(x);
  12540. result.and(y);
  12541. tmp.assign(x);
  12542. tmp.and(z);
  12543. result.xor(tmp);
  12544. tmp.assign(y);
  12545. tmp.and(z);
  12546. result.xor(tmp);
  12547. }
  12548. function sigma(result, x, tmp) {
  12549. result.assign(x);
  12550. result.rotateRight(28);
  12551. tmp.assign(x);
  12552. tmp.rotateRight(34);
  12553. result.xor(tmp);
  12554. tmp.assign(x);
  12555. tmp.rotateRight(39);
  12556. result.xor(tmp);
  12557. }
  12558. function sigmaPrime(result, x, tmp) {
  12559. result.assign(x);
  12560. result.rotateRight(14);
  12561. tmp.assign(x);
  12562. tmp.rotateRight(18);
  12563. result.xor(tmp);
  12564. tmp.assign(x);
  12565. tmp.rotateRight(41);
  12566. result.xor(tmp);
  12567. }
  12568. function littleSigma(result, x, tmp) {
  12569. result.assign(x);
  12570. result.rotateRight(1);
  12571. tmp.assign(x);
  12572. tmp.rotateRight(8);
  12573. result.xor(tmp);
  12574. tmp.assign(x);
  12575. tmp.shiftRight(7);
  12576. result.xor(tmp);
  12577. }
  12578. function littleSigmaPrime(result, x, tmp) {
  12579. result.assign(x);
  12580. result.rotateRight(19);
  12581. tmp.assign(x);
  12582. tmp.rotateRight(61);
  12583. result.xor(tmp);
  12584. tmp.assign(x);
  12585. tmp.shiftRight(6);
  12586. result.xor(tmp);
  12587. }
  12588. var k = [
  12589. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12590. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12591. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12592. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12593. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12594. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12595. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12596. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12597. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12598. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12599. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12600. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12601. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12602. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12603. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12604. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12605. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12606. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12607. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12608. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12609. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12610. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12611. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12612. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12613. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12614. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12615. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12616. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12617. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12618. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12619. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12620. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12621. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12622. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12623. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12624. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12625. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12626. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12627. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12628. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12629. function hash(data, offset, length, mode384) {
  12630. mode384 = !!mode384;
  12631. // initial hash values
  12632. var h0, h1, h2, h3, h4, h5, h6, h7;
  12633. if (!mode384) {
  12634. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12635. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12636. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12637. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12638. h4 = new Word64(0x510e527f, 0xade682d1);
  12639. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12640. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12641. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12642. }
  12643. else {
  12644. // SHA384 is exactly the same
  12645. // except with different starting values and a trimmed result
  12646. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12647. h1 = new Word64(0x629a292a, 0x367cd507);
  12648. h2 = new Word64(0x9159015a, 0x3070dd17);
  12649. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12650. h4 = new Word64(0x67332667, 0xffc00b31);
  12651. h5 = new Word64(0x8eb44a87, 0x68581511);
  12652. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12653. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12654. }
  12655. // pre-processing
  12656. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12657. var padded = new Uint8Array(paddedLength);
  12658. var i, j, n;
  12659. for (i = 0; i < length; ++i) {
  12660. padded[i] = data[offset++];
  12661. }
  12662. padded[i++] = 0x80;
  12663. n = paddedLength - 16;
  12664. while (i < n) {
  12665. padded[i++] = 0;
  12666. }
  12667. padded[i++] = 0;
  12668. padded[i++] = 0;
  12669. padded[i++] = 0;
  12670. padded[i++] = 0;
  12671. padded[i++] = 0;
  12672. padded[i++] = 0;
  12673. padded[i++] = 0;
  12674. padded[i++] = 0;
  12675. padded[i++] = 0;
  12676. padded[i++] = 0;
  12677. padded[i++] = 0;
  12678. padded[i++] = (length >>> 29) & 0xFF;
  12679. padded[i++] = (length >> 21) & 0xFF;
  12680. padded[i++] = (length >> 13) & 0xFF;
  12681. padded[i++] = (length >> 5) & 0xFF;
  12682. padded[i++] = (length << 3) & 0xFF;
  12683. var w = new Array(80);
  12684. for (i = 0; i < 80; i++) {
  12685. w[i] = new Word64(0, 0);
  12686. }
  12687. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  12688. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  12689. var g = new Word64(0, 0), h = new Word64(0, 0);
  12690. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  12691. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  12692. // for each 1024 bit block
  12693. for (i = 0; i < paddedLength;) {
  12694. for (j = 0; j < 16; ++j) {
  12695. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  12696. (padded[i + 2] << 8) | (padded[i + 3]);
  12697. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  12698. (padded[i + 6]) << 8 | (padded[i + 7]);
  12699. i += 8;
  12700. }
  12701. for (j = 16; j < 80; ++j) {
  12702. tmp3 = w[j];
  12703. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  12704. tmp3.add(w[j - 7]);
  12705. littleSigma(tmp1, w[j - 15], tmp2);
  12706. tmp3.add(tmp1);
  12707. tmp3.add(w[j - 16]);
  12708. }
  12709. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  12710. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  12711. for (j = 0; j < 80; ++j) {
  12712. t1.assign(h);
  12713. sigmaPrime(tmp1, e, tmp2);
  12714. t1.add(tmp1);
  12715. ch(tmp1, e, f, g, tmp2);
  12716. t1.add(tmp1);
  12717. t1.add(k[j]);
  12718. t1.add(w[j]);
  12719. sigma(t2, a, tmp2);
  12720. maj(tmp1, a, b, c, tmp2);
  12721. t2.add(tmp1);
  12722. tmp3 = h;
  12723. h = g;
  12724. g = f;
  12725. f = e;
  12726. d.add(t1);
  12727. e = d;
  12728. d = c;
  12729. c = b;
  12730. b = a;
  12731. tmp3.assign(t1);
  12732. tmp3.add(t2);
  12733. a = tmp3;
  12734. }
  12735. h0.add(a);
  12736. h1.add(b);
  12737. h2.add(c);
  12738. h3.add(d);
  12739. h4.add(e);
  12740. h5.add(f);
  12741. h6.add(g);
  12742. h7.add(h);
  12743. }
  12744. var result;
  12745. if (!mode384) {
  12746. result = new Uint8Array(64);
  12747. h0.copyTo(result,0);
  12748. h1.copyTo(result,8);
  12749. h2.copyTo(result,16);
  12750. h3.copyTo(result,24);
  12751. h4.copyTo(result,32);
  12752. h5.copyTo(result,40);
  12753. h6.copyTo(result,48);
  12754. h7.copyTo(result,56);
  12755. }
  12756. else {
  12757. result = new Uint8Array(48);
  12758. h0.copyTo(result,0);
  12759. h1.copyTo(result,8);
  12760. h2.copyTo(result,16);
  12761. h3.copyTo(result,24);
  12762. h4.copyTo(result,32);
  12763. h5.copyTo(result,40);
  12764. }
  12765. return result;
  12766. }
  12767. return hash;
  12768. })();
  12769. var calculateSHA384 = (function calculateSHA384Closure() {
  12770. function hash(data, offset, length) {
  12771. return calculateSHA512(data, offset, length, true);
  12772. }
  12773. return hash;
  12774. })();
  12775. var NullCipher = (function NullCipherClosure() {
  12776. function NullCipher() {
  12777. }
  12778. NullCipher.prototype = {
  12779. decryptBlock: function NullCipher_decryptBlock(data) {
  12780. return data;
  12781. }
  12782. };
  12783. return NullCipher;
  12784. })();
  12785. var AES128Cipher = (function AES128CipherClosure() {
  12786. var rcon = new Uint8Array([
  12787. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12788. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12789. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12790. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12791. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  12792. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  12793. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  12794. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  12795. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  12796. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  12797. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  12798. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  12799. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  12800. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  12801. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  12802. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  12803. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  12804. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12805. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12806. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12807. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12808. 0x74, 0xe8, 0xcb, 0x8d]);
  12809. var s = new Uint8Array([
  12810. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  12811. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  12812. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  12813. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  12814. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  12815. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  12816. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  12817. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  12818. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  12819. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  12820. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  12821. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  12822. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  12823. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  12824. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  12825. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  12826. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  12827. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  12828. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  12829. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  12830. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  12831. 0xb0, 0x54, 0xbb, 0x16]);
  12832. var inv_s = new Uint8Array([
  12833. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  12834. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  12835. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  12836. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  12837. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  12838. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  12839. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  12840. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  12841. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  12842. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  12843. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  12844. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  12845. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  12846. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  12847. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  12848. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  12849. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  12850. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  12851. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  12852. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  12853. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  12854. 0x55, 0x21, 0x0c, 0x7d]);
  12855. var mixCol = new Uint8Array(256);
  12856. for (var i = 0; i < 256; i++) {
  12857. if (i < 128) {
  12858. mixCol[i] = i << 1;
  12859. } else {
  12860. mixCol[i] = (i << 1) ^ 0x1b;
  12861. }
  12862. }
  12863. var mix = new Uint32Array([
  12864. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  12865. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  12866. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  12867. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  12868. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  12869. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  12870. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  12871. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  12872. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  12873. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  12874. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  12875. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  12876. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  12877. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  12878. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  12879. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  12880. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  12881. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  12882. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  12883. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  12884. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  12885. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  12886. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  12887. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  12888. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  12889. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  12890. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  12891. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  12892. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  12893. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  12894. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  12895. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  12896. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  12897. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  12898. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  12899. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  12900. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  12901. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  12902. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  12903. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  12904. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  12905. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  12906. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  12907. function expandKey128(cipherKey) {
  12908. var b = 176, result = new Uint8Array(b);
  12909. result.set(cipherKey);
  12910. for (var j = 16, i = 1; j < b; ++i) {
  12911. // RotWord
  12912. var t1 = result[j - 3], t2 = result[j - 2],
  12913. t3 = result[j - 1], t4 = result[j - 4];
  12914. // SubWord
  12915. t1 = s[t1];
  12916. t2 = s[t2];
  12917. t3 = s[t3];
  12918. t4 = s[t4];
  12919. // Rcon
  12920. t1 = t1 ^ rcon[i];
  12921. for (var n = 0; n < 4; ++n) {
  12922. result[j] = (t1 ^= result[j - 16]);
  12923. j++;
  12924. result[j] = (t2 ^= result[j - 16]);
  12925. j++;
  12926. result[j] = (t3 ^= result[j - 16]);
  12927. j++;
  12928. result[j] = (t4 ^= result[j - 16]);
  12929. j++;
  12930. }
  12931. }
  12932. return result;
  12933. }
  12934. function decrypt128(input, key) {
  12935. var state = new Uint8Array(16);
  12936. state.set(input);
  12937. var i, j, k;
  12938. var t, u, v;
  12939. // AddRoundKey
  12940. for (j = 0, k = 160; j < 16; ++j, ++k) {
  12941. state[j] ^= key[k];
  12942. }
  12943. for (i = 9; i >= 1; --i) {
  12944. // InvShiftRows
  12945. t = state[13];
  12946. state[13] = state[9];
  12947. state[9] = state[5];
  12948. state[5] = state[1];
  12949. state[1] = t;
  12950. t = state[14];
  12951. u = state[10];
  12952. state[14] = state[6];
  12953. state[10] = state[2];
  12954. state[6] = t;
  12955. state[2] = u;
  12956. t = state[15];
  12957. u = state[11];
  12958. v = state[7];
  12959. state[15] = state[3];
  12960. state[11] = t;
  12961. state[7] = u;
  12962. state[3] = v;
  12963. // InvSubBytes
  12964. for (j = 0; j < 16; ++j) {
  12965. state[j] = inv_s[state[j]];
  12966. }
  12967. // AddRoundKey
  12968. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12969. state[j] ^= key[k];
  12970. }
  12971. // InvMixColumns
  12972. for (j = 0; j < 16; j += 4) {
  12973. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  12974. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  12975. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  12976. (s3 >>> 24) ^ (s3 << 8));
  12977. state[j] = (t >>> 24) & 0xFF;
  12978. state[j + 1] = (t >> 16) & 0xFF;
  12979. state[j + 2] = (t >> 8) & 0xFF;
  12980. state[j + 3] = t & 0xFF;
  12981. }
  12982. }
  12983. // InvShiftRows
  12984. t = state[13];
  12985. state[13] = state[9];
  12986. state[9] = state[5];
  12987. state[5] = state[1];
  12988. state[1] = t;
  12989. t = state[14];
  12990. u = state[10];
  12991. state[14] = state[6];
  12992. state[10] = state[2];
  12993. state[6] = t;
  12994. state[2] = u;
  12995. t = state[15];
  12996. u = state[11];
  12997. v = state[7];
  12998. state[15] = state[3];
  12999. state[11] = t;
  13000. state[7] = u;
  13001. state[3] = v;
  13002. for (j = 0; j < 16; ++j) {
  13003. // InvSubBytes
  13004. state[j] = inv_s[state[j]];
  13005. // AddRoundKey
  13006. state[j] ^= key[j];
  13007. }
  13008. return state;
  13009. }
  13010. function encrypt128(input, key) {
  13011. var t, u, v, k;
  13012. var state = new Uint8Array(16);
  13013. state.set(input);
  13014. for (j = 0; j < 16; ++j) {
  13015. // AddRoundKey
  13016. state[j] ^= key[j];
  13017. }
  13018. for (i = 1; i < 10; i++) {
  13019. //SubBytes
  13020. for (j = 0; j < 16; ++j) {
  13021. state[j] = s[state[j]];
  13022. }
  13023. //ShiftRows
  13024. v = state[1];
  13025. state[1] = state[5];
  13026. state[5] = state[9];
  13027. state[9] = state[13];
  13028. state[13] = v;
  13029. v = state[2];
  13030. u = state[6];
  13031. state[2] = state[10];
  13032. state[6] = state[14];
  13033. state[10] = v;
  13034. state[14] = u;
  13035. v = state[3];
  13036. u = state[7];
  13037. t = state[11];
  13038. state[3] = state[15];
  13039. state[7] = v;
  13040. state[11] = u;
  13041. state[15] = t;
  13042. //MixColumns
  13043. for (var j = 0; j < 16; j += 4) {
  13044. var s0 = state[j + 0], s1 = state[j + 1];
  13045. var s2 = state[j + 2], s3 = state[j + 3];
  13046. t = s0 ^ s1 ^ s2 ^ s3;
  13047. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13048. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13049. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13050. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13051. }
  13052. //AddRoundKey
  13053. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13054. state[j] ^= key[k];
  13055. }
  13056. }
  13057. //SubBytes
  13058. for (j = 0; j < 16; ++j) {
  13059. state[j] = s[state[j]];
  13060. }
  13061. //ShiftRows
  13062. v = state[1];
  13063. state[1] = state[5];
  13064. state[5] = state[9];
  13065. state[9] = state[13];
  13066. state[13] = v;
  13067. v = state[2];
  13068. u = state[6];
  13069. state[2] = state[10];
  13070. state[6] = state[14];
  13071. state[10] = v;
  13072. state[14] = u;
  13073. v = state[3];
  13074. u = state[7];
  13075. t = state[11];
  13076. state[3] = state[15];
  13077. state[7] = v;
  13078. state[11] = u;
  13079. state[15] = t;
  13080. //AddRoundKey
  13081. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13082. state[j] ^= key[k];
  13083. }
  13084. return state;
  13085. }
  13086. function AES128Cipher(key) {
  13087. this.key = expandKey128(key);
  13088. this.buffer = new Uint8Array(16);
  13089. this.bufferPosition = 0;
  13090. }
  13091. function decryptBlock2(data, finalize) {
  13092. var i, j, ii, sourceLength = data.length,
  13093. buffer = this.buffer, bufferLength = this.bufferPosition,
  13094. result = [], iv = this.iv;
  13095. for (i = 0; i < sourceLength; ++i) {
  13096. buffer[bufferLength] = data[i];
  13097. ++bufferLength;
  13098. if (bufferLength < 16) {
  13099. continue;
  13100. }
  13101. // buffer is full, decrypting
  13102. var plain = decrypt128(buffer, this.key);
  13103. // xor-ing the IV vector to get plain text
  13104. for (j = 0; j < 16; ++j) {
  13105. plain[j] ^= iv[j];
  13106. }
  13107. iv = buffer;
  13108. result.push(plain);
  13109. buffer = new Uint8Array(16);
  13110. bufferLength = 0;
  13111. }
  13112. // saving incomplete buffer
  13113. this.buffer = buffer;
  13114. this.bufferLength = bufferLength;
  13115. this.iv = iv;
  13116. if (result.length === 0) {
  13117. return new Uint8Array([]);
  13118. }
  13119. // combining plain text blocks into one
  13120. var outputLength = 16 * result.length;
  13121. if (finalize) {
  13122. // undo a padding that is described in RFC 2898
  13123. var lastBlock = result[result.length - 1];
  13124. var psLen = lastBlock[15];
  13125. if (psLen <= 16) {
  13126. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13127. if (lastBlock[i] !== psLen) {
  13128. // Invalid padding, assume that the block has no padding.
  13129. psLen = 0;
  13130. break;
  13131. }
  13132. }
  13133. outputLength -= psLen;
  13134. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13135. }
  13136. }
  13137. var output = new Uint8Array(outputLength);
  13138. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13139. output.set(result[i], j);
  13140. }
  13141. return output;
  13142. }
  13143. AES128Cipher.prototype = {
  13144. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13145. var i, sourceLength = data.length;
  13146. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13147. // waiting for IV values -- they are at the start of the stream
  13148. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13149. buffer[bufferLength] = data[i];
  13150. }
  13151. if (bufferLength < 16) {
  13152. // need more data
  13153. this.bufferLength = bufferLength;
  13154. return new Uint8Array([]);
  13155. }
  13156. this.iv = buffer;
  13157. this.buffer = new Uint8Array(16);
  13158. this.bufferLength = 0;
  13159. // starting decryption
  13160. this.decryptBlock = decryptBlock2;
  13161. return this.decryptBlock(data.subarray(16), finalize);
  13162. },
  13163. encrypt: function AES128Cipher_encrypt(data, iv) {
  13164. var i, j, ii, sourceLength = data.length,
  13165. buffer = this.buffer, bufferLength = this.bufferPosition,
  13166. result = [];
  13167. if (!iv) {
  13168. iv = new Uint8Array(16);
  13169. }
  13170. for (i = 0; i < sourceLength; ++i) {
  13171. buffer[bufferLength] = data[i];
  13172. ++bufferLength;
  13173. if (bufferLength < 16) {
  13174. continue;
  13175. }
  13176. for (j = 0; j < 16; ++j) {
  13177. buffer[j] ^= iv[j];
  13178. }
  13179. // buffer is full, encrypting
  13180. var cipher = encrypt128(buffer, this.key);
  13181. iv = cipher;
  13182. result.push(cipher);
  13183. buffer = new Uint8Array(16);
  13184. bufferLength = 0;
  13185. }
  13186. // saving incomplete buffer
  13187. this.buffer = buffer;
  13188. this.bufferLength = bufferLength;
  13189. this.iv = iv;
  13190. if (result.length === 0) {
  13191. return new Uint8Array([]);
  13192. }
  13193. // combining plain text blocks into one
  13194. var outputLength = 16 * result.length;
  13195. var output = new Uint8Array(outputLength);
  13196. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13197. output.set(result[i], j);
  13198. }
  13199. return output;
  13200. }
  13201. };
  13202. return AES128Cipher;
  13203. })();
  13204. var AES256Cipher = (function AES256CipherClosure() {
  13205. var rcon = new Uint8Array([
  13206. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13207. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13208. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13209. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13210. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13211. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13212. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13213. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13214. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13215. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13216. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13217. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13218. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13219. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13220. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13221. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13222. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13223. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13224. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13225. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13226. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13227. 0x74, 0xe8, 0xcb, 0x8d]);
  13228. var s = new Uint8Array([
  13229. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13230. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13231. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13232. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13233. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13234. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13235. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13236. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13237. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13238. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13239. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13240. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13241. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13242. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13243. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13244. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13245. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13246. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13247. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13248. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13249. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13250. 0xb0, 0x54, 0xbb, 0x16]);
  13251. var inv_s = new Uint8Array([
  13252. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13253. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13254. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13255. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13256. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13257. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13258. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13259. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13260. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13261. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13262. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13263. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13264. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13265. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13266. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13267. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13268. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13269. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13270. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13271. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13272. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13273. 0x55, 0x21, 0x0c, 0x7d]);
  13274. var mixCol = new Uint8Array(256);
  13275. for (var i = 0; i < 256; i++) {
  13276. if (i < 128) {
  13277. mixCol[i] = i << 1;
  13278. } else {
  13279. mixCol[i] = (i << 1) ^ 0x1b;
  13280. }
  13281. }
  13282. var mix = new Uint32Array([
  13283. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13284. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13285. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13286. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13287. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13288. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13289. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13290. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13291. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13292. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13293. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13294. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13295. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13296. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13297. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13298. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13299. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13300. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13301. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13302. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13303. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13304. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13305. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13306. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13307. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13308. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13309. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13310. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13311. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13312. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13313. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13314. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13315. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13316. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13317. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13318. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13319. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13320. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13321. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13322. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13323. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13324. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13325. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13326. function expandKey256(cipherKey) {
  13327. var b = 240, result = new Uint8Array(b);
  13328. var r = 1;
  13329. result.set(cipherKey);
  13330. for (var j = 32, i = 1; j < b; ++i) {
  13331. if (j % 32 === 16) {
  13332. t1 = s[t1];
  13333. t2 = s[t2];
  13334. t3 = s[t3];
  13335. t4 = s[t4];
  13336. } else if (j % 32 === 0) {
  13337. // RotWord
  13338. var t1 = result[j - 3], t2 = result[j - 2],
  13339. t3 = result[j - 1], t4 = result[j - 4];
  13340. // SubWord
  13341. t1 = s[t1];
  13342. t2 = s[t2];
  13343. t3 = s[t3];
  13344. t4 = s[t4];
  13345. // Rcon
  13346. t1 = t1 ^ r;
  13347. if ((r <<= 1) >= 256) {
  13348. r = (r ^ 0x1b) & 0xFF;
  13349. }
  13350. }
  13351. for (var n = 0; n < 4; ++n) {
  13352. result[j] = (t1 ^= result[j - 32]);
  13353. j++;
  13354. result[j] = (t2 ^= result[j - 32]);
  13355. j++;
  13356. result[j] = (t3 ^= result[j - 32]);
  13357. j++;
  13358. result[j] = (t4 ^= result[j - 32]);
  13359. j++;
  13360. }
  13361. }
  13362. return result;
  13363. }
  13364. function decrypt256(input, key) {
  13365. var state = new Uint8Array(16);
  13366. state.set(input);
  13367. var i, j, k;
  13368. var t, u, v;
  13369. // AddRoundKey
  13370. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13371. state[j] ^= key[k];
  13372. }
  13373. for (i = 13; i >= 1; --i) {
  13374. // InvShiftRows
  13375. t = state[13];
  13376. state[13] = state[9];
  13377. state[9] = state[5];
  13378. state[5] = state[1];
  13379. state[1] = t;
  13380. t = state[14];
  13381. u = state[10];
  13382. state[14] = state[6];
  13383. state[10] = state[2];
  13384. state[6] = t;
  13385. state[2] = u;
  13386. t = state[15];
  13387. u = state[11];
  13388. v = state[7];
  13389. state[15] = state[3];
  13390. state[11] = t;
  13391. state[7] = u;
  13392. state[3] = v;
  13393. // InvSubBytes
  13394. for (j = 0; j < 16; ++j) {
  13395. state[j] = inv_s[state[j]];
  13396. }
  13397. // AddRoundKey
  13398. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13399. state[j] ^= key[k];
  13400. }
  13401. // InvMixColumns
  13402. for (j = 0; j < 16; j += 4) {
  13403. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13404. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13405. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13406. (s3 >>> 24) ^ (s3 << 8));
  13407. state[j] = (t >>> 24) & 0xFF;
  13408. state[j + 1] = (t >> 16) & 0xFF;
  13409. state[j + 2] = (t >> 8) & 0xFF;
  13410. state[j + 3] = t & 0xFF;
  13411. }
  13412. }
  13413. // InvShiftRows
  13414. t = state[13];
  13415. state[13] = state[9];
  13416. state[9] = state[5];
  13417. state[5] = state[1];
  13418. state[1] = t;
  13419. t = state[14];
  13420. u = state[10];
  13421. state[14] = state[6];
  13422. state[10] = state[2];
  13423. state[6] = t;
  13424. state[2] = u;
  13425. t = state[15];
  13426. u = state[11];
  13427. v = state[7];
  13428. state[15] = state[3];
  13429. state[11] = t;
  13430. state[7] = u;
  13431. state[3] = v;
  13432. for (j = 0; j < 16; ++j) {
  13433. // InvSubBytes
  13434. state[j] = inv_s[state[j]];
  13435. // AddRoundKey
  13436. state[j] ^= key[j];
  13437. }
  13438. return state;
  13439. }
  13440. function encrypt256(input, key) {
  13441. var t, u, v, k;
  13442. var state = new Uint8Array(16);
  13443. state.set(input);
  13444. for (j = 0; j < 16; ++j) {
  13445. // AddRoundKey
  13446. state[j] ^= key[j];
  13447. }
  13448. for (i = 1; i < 14; i++) {
  13449. //SubBytes
  13450. for (j = 0; j < 16; ++j) {
  13451. state[j] = s[state[j]];
  13452. }
  13453. //ShiftRows
  13454. v = state[1];
  13455. state[1] = state[5];
  13456. state[5] = state[9];
  13457. state[9] = state[13];
  13458. state[13] = v;
  13459. v = state[2];
  13460. u = state[6];
  13461. state[2] = state[10];
  13462. state[6] = state[14];
  13463. state[10] = v;
  13464. state[14] = u;
  13465. v = state[3];
  13466. u = state[7];
  13467. t = state[11];
  13468. state[3] = state[15];
  13469. state[7] = v;
  13470. state[11] = u;
  13471. state[15] = t;
  13472. //MixColumns
  13473. for (var j = 0; j < 16; j += 4) {
  13474. var s0 = state[j + 0], s1 = state[j + 1];
  13475. var s2 = state[j + 2], s3 = state[j + 3];
  13476. t = s0 ^ s1 ^ s2 ^ s3;
  13477. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13478. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13479. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13480. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13481. }
  13482. //AddRoundKey
  13483. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13484. state[j] ^= key[k];
  13485. }
  13486. }
  13487. //SubBytes
  13488. for (j = 0; j < 16; ++j) {
  13489. state[j] = s[state[j]];
  13490. }
  13491. //ShiftRows
  13492. v = state[1];
  13493. state[1] = state[5];
  13494. state[5] = state[9];
  13495. state[9] = state[13];
  13496. state[13] = v;
  13497. v = state[2];
  13498. u = state[6];
  13499. state[2] = state[10];
  13500. state[6] = state[14];
  13501. state[10] = v;
  13502. state[14] = u;
  13503. v = state[3];
  13504. u = state[7];
  13505. t = state[11];
  13506. state[3] = state[15];
  13507. state[7] = v;
  13508. state[11] = u;
  13509. state[15] = t;
  13510. //AddRoundKey
  13511. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13512. state[j] ^= key[k];
  13513. }
  13514. return state;
  13515. }
  13516. function AES256Cipher(key) {
  13517. this.key = expandKey256(key);
  13518. this.buffer = new Uint8Array(16);
  13519. this.bufferPosition = 0;
  13520. }
  13521. function decryptBlock2(data, finalize) {
  13522. var i, j, ii, sourceLength = data.length,
  13523. buffer = this.buffer, bufferLength = this.bufferPosition,
  13524. result = [], iv = this.iv;
  13525. for (i = 0; i < sourceLength; ++i) {
  13526. buffer[bufferLength] = data[i];
  13527. ++bufferLength;
  13528. if (bufferLength < 16) {
  13529. continue;
  13530. }
  13531. // buffer is full, decrypting
  13532. var plain = decrypt256(buffer, this.key);
  13533. // xor-ing the IV vector to get plain text
  13534. for (j = 0; j < 16; ++j) {
  13535. plain[j] ^= iv[j];
  13536. }
  13537. iv = buffer;
  13538. result.push(plain);
  13539. buffer = new Uint8Array(16);
  13540. bufferLength = 0;
  13541. }
  13542. // saving incomplete buffer
  13543. this.buffer = buffer;
  13544. this.bufferLength = bufferLength;
  13545. this.iv = iv;
  13546. if (result.length === 0) {
  13547. return new Uint8Array([]);
  13548. }
  13549. // combining plain text blocks into one
  13550. var outputLength = 16 * result.length;
  13551. if (finalize) {
  13552. // undo a padding that is described in RFC 2898
  13553. var lastBlock = result[result.length - 1];
  13554. var psLen = lastBlock[15];
  13555. if (psLen <= 16) {
  13556. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13557. if (lastBlock[i] !== psLen) {
  13558. // Invalid padding, assume that the block has no padding.
  13559. psLen = 0;
  13560. break;
  13561. }
  13562. }
  13563. outputLength -= psLen;
  13564. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13565. }
  13566. }
  13567. var output = new Uint8Array(outputLength);
  13568. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13569. output.set(result[i], j);
  13570. }
  13571. return output;
  13572. }
  13573. AES256Cipher.prototype = {
  13574. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13575. var i, sourceLength = data.length;
  13576. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13577. // if not supplied an IV wait for IV values
  13578. // they are at the start of the stream
  13579. if (iv) {
  13580. this.iv = iv;
  13581. } else {
  13582. for (i = 0; bufferLength < 16 &&
  13583. i < sourceLength; ++i, ++bufferLength) {
  13584. buffer[bufferLength] = data[i];
  13585. }
  13586. if (bufferLength < 16) {
  13587. //need more data
  13588. this.bufferLength = bufferLength;
  13589. return new Uint8Array([]);
  13590. }
  13591. this.iv = buffer;
  13592. data = data.subarray(16);
  13593. }
  13594. this.buffer = new Uint8Array(16);
  13595. this.bufferLength = 0;
  13596. // starting decryption
  13597. this.decryptBlock = decryptBlock2;
  13598. return this.decryptBlock(data, finalize);
  13599. },
  13600. encrypt: function AES256Cipher_encrypt(data, iv) {
  13601. var i, j, ii, sourceLength = data.length,
  13602. buffer = this.buffer, bufferLength = this.bufferPosition,
  13603. result = [];
  13604. if (!iv) {
  13605. iv = new Uint8Array(16);
  13606. }
  13607. for (i = 0; i < sourceLength; ++i) {
  13608. buffer[bufferLength] = data[i];
  13609. ++bufferLength;
  13610. if (bufferLength < 16) {
  13611. continue;
  13612. }
  13613. for (j = 0; j < 16; ++j) {
  13614. buffer[j] ^= iv[j];
  13615. }
  13616. // buffer is full, encrypting
  13617. var cipher = encrypt256(buffer, this.key);
  13618. this.iv = cipher;
  13619. result.push(cipher);
  13620. buffer = new Uint8Array(16);
  13621. bufferLength = 0;
  13622. }
  13623. // saving incomplete buffer
  13624. this.buffer = buffer;
  13625. this.bufferLength = bufferLength;
  13626. this.iv = iv;
  13627. if (result.length === 0) {
  13628. return new Uint8Array([]);
  13629. }
  13630. // combining plain text blocks into one
  13631. var outputLength = 16 * result.length;
  13632. var output = new Uint8Array(outputLength);
  13633. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13634. output.set(result[i], j);
  13635. }
  13636. return output;
  13637. }
  13638. };
  13639. return AES256Cipher;
  13640. })();
  13641. var PDF17 = (function PDF17Closure() {
  13642. function compareByteArrays(array1, array2) {
  13643. if (array1.length !== array2.length) {
  13644. return false;
  13645. }
  13646. for (var i = 0; i < array1.length; i++) {
  13647. if (array1[i] !== array2[i]) {
  13648. return false;
  13649. }
  13650. }
  13651. return true;
  13652. }
  13653. function PDF17() {
  13654. }
  13655. PDF17.prototype = {
  13656. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13657. ownerValidationSalt,
  13658. userBytes,
  13659. ownerPassword) {
  13660. var hashData = new Uint8Array(password.length + 56);
  13661. hashData.set(password, 0);
  13662. hashData.set(ownerValidationSalt, password.length);
  13663. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13664. var result = calculateSHA256(hashData, 0, hashData.length);
  13665. return compareByteArrays(result, ownerPassword);
  13666. },
  13667. checkUserPassword: function PDF17_checkUserPassword(password,
  13668. userValidationSalt,
  13669. userPassword) {
  13670. var hashData = new Uint8Array(password.length + 8);
  13671. hashData.set(password, 0);
  13672. hashData.set(userValidationSalt, password.length);
  13673. var result = calculateSHA256(hashData, 0, hashData.length);
  13674. return compareByteArrays(result, userPassword);
  13675. },
  13676. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  13677. ownerEncryption) {
  13678. var hashData = new Uint8Array(password.length + 56);
  13679. hashData.set(password, 0);
  13680. hashData.set(ownerKeySalt, password.length);
  13681. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13682. var key = calculateSHA256(hashData, 0, hashData.length);
  13683. var cipher = new AES256Cipher(key);
  13684. return cipher.decryptBlock(ownerEncryption,
  13685. false,
  13686. new Uint8Array(16));
  13687. },
  13688. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  13689. userEncryption) {
  13690. var hashData = new Uint8Array(password.length + 8);
  13691. hashData.set(password, 0);
  13692. hashData.set(userKeySalt, password.length);
  13693. //key is the decryption key for the UE string
  13694. var key = calculateSHA256(hashData, 0, hashData.length);
  13695. var cipher = new AES256Cipher(key);
  13696. return cipher.decryptBlock(userEncryption,
  13697. false,
  13698. new Uint8Array(16));
  13699. }
  13700. };
  13701. return PDF17;
  13702. })();
  13703. var PDF20 = (function PDF20Closure() {
  13704. function concatArrays(array1, array2) {
  13705. var t = new Uint8Array(array1.length + array2.length);
  13706. t.set(array1, 0);
  13707. t.set(array2, array1.length);
  13708. return t;
  13709. }
  13710. function calculatePDF20Hash(password, input, userBytes) {
  13711. //This refers to Algorithm 2.B as defined in ISO 32000-2
  13712. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  13713. var e = [0];
  13714. var i = 0;
  13715. while (i < 64 || e[e.length - 1] > i - 32) {
  13716. var arrayLength = password.length + k.length + userBytes.length;
  13717. var k1 = new Uint8Array(arrayLength * 64);
  13718. var array = concatArrays(password, k);
  13719. array = concatArrays(array, userBytes);
  13720. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  13721. k1.set(array, pos);
  13722. }
  13723. //AES128 CBC NO PADDING with
  13724. //first 16 bytes of k as the key and the second 16 as the iv.
  13725. var cipher = new AES128Cipher(k.subarray(0, 16));
  13726. e = cipher.encrypt(k1, k.subarray(16, 32));
  13727. //Now we have to take the first 16 bytes of an unsigned
  13728. //big endian integer... and compute the remainder
  13729. //modulo 3.... That is a fairly large number and
  13730. //JavaScript isn't going to handle that well...
  13731. //So we're using a trick that allows us to perform
  13732. //modulo math byte by byte
  13733. var remainder = 0;
  13734. for (var z = 0; z < 16; z++) {
  13735. remainder *= (256 % 3);
  13736. remainder %= 3;
  13737. remainder += ((e[z] >>> 0) % 3);
  13738. remainder %= 3;
  13739. }
  13740. if (remainder === 0) {
  13741. k = calculateSHA256(e, 0, e.length);
  13742. }
  13743. else if (remainder === 1) {
  13744. k = calculateSHA384(e, 0, e.length);
  13745. }
  13746. else if (remainder === 2) {
  13747. k = calculateSHA512(e, 0, e.length);
  13748. }
  13749. i++;
  13750. }
  13751. return k.subarray(0, 32);
  13752. }
  13753. function PDF20() {
  13754. }
  13755. function compareByteArrays(array1, array2) {
  13756. if (array1.length !== array2.length) {
  13757. return false;
  13758. }
  13759. for (var i = 0; i < array1.length; i++) {
  13760. if (array1[i] !== array2[i]) {
  13761. return false;
  13762. }
  13763. }
  13764. return true;
  13765. }
  13766. PDF20.prototype = {
  13767. hash: function PDF20_hash(password, concatBytes, userBytes) {
  13768. return calculatePDF20Hash(password, concatBytes, userBytes);
  13769. },
  13770. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  13771. ownerValidationSalt,
  13772. userBytes,
  13773. ownerPassword) {
  13774. var hashData = new Uint8Array(password.length + 56);
  13775. hashData.set(password, 0);
  13776. hashData.set(ownerValidationSalt, password.length);
  13777. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13778. var result = calculatePDF20Hash(password, hashData, userBytes);
  13779. return compareByteArrays(result, ownerPassword);
  13780. },
  13781. checkUserPassword: function PDF20_checkUserPassword(password,
  13782. userValidationSalt,
  13783. userPassword) {
  13784. var hashData = new Uint8Array(password.length + 8);
  13785. hashData.set(password, 0);
  13786. hashData.set(userValidationSalt, password.length);
  13787. var result = calculatePDF20Hash(password, hashData, []);
  13788. return compareByteArrays(result, userPassword);
  13789. },
  13790. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  13791. ownerEncryption) {
  13792. var hashData = new Uint8Array(password.length + 56);
  13793. hashData.set(password, 0);
  13794. hashData.set(ownerKeySalt, password.length);
  13795. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13796. var key = calculatePDF20Hash(password, hashData, userBytes);
  13797. var cipher = new AES256Cipher(key);
  13798. return cipher.decryptBlock(ownerEncryption,
  13799. false,
  13800. new Uint8Array(16));
  13801. },
  13802. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  13803. userEncryption) {
  13804. var hashData = new Uint8Array(password.length + 8);
  13805. hashData.set(password, 0);
  13806. hashData.set(userKeySalt, password.length);
  13807. //key is the decryption key for the UE string
  13808. var key = calculatePDF20Hash(password, hashData, []);
  13809. var cipher = new AES256Cipher(key);
  13810. return cipher.decryptBlock(userEncryption,
  13811. false,
  13812. new Uint8Array(16));
  13813. }
  13814. };
  13815. return PDF20;
  13816. })();
  13817. var CipherTransform = (function CipherTransformClosure() {
  13818. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  13819. this.stringCipherConstructor = stringCipherConstructor;
  13820. this.streamCipherConstructor = streamCipherConstructor;
  13821. }
  13822. CipherTransform.prototype = {
  13823. createStream: function CipherTransform_createStream(stream, length) {
  13824. var cipher = new this.streamCipherConstructor();
  13825. return new DecryptStream(stream, length,
  13826. function cipherTransformDecryptStream(data, finalize) {
  13827. return cipher.decryptBlock(data, finalize);
  13828. }
  13829. );
  13830. },
  13831. decryptString: function CipherTransform_decryptString(s) {
  13832. var cipher = new this.stringCipherConstructor();
  13833. var data = stringToBytes(s);
  13834. data = cipher.decryptBlock(data, true);
  13835. return bytesToString(data);
  13836. }
  13837. };
  13838. return CipherTransform;
  13839. })();
  13840. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  13841. var defaultPasswordBytes = new Uint8Array([
  13842. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  13843. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  13844. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  13845. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  13846. function createEncryptionKey20(revision, password, ownerPassword,
  13847. ownerValidationSalt, ownerKeySalt, uBytes,
  13848. userPassword, userValidationSalt, userKeySalt,
  13849. ownerEncryption, userEncryption, perms) {
  13850. if (password) {
  13851. var passwordLength = Math.min(127, password.length);
  13852. password = password.subarray(0, passwordLength);
  13853. } else {
  13854. password = [];
  13855. }
  13856. var pdfAlgorithm;
  13857. if (revision === 6) {
  13858. pdfAlgorithm = new PDF20();
  13859. } else {
  13860. pdfAlgorithm = new PDF17();
  13861. }
  13862. if (pdfAlgorithm) {
  13863. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  13864. userPassword)) {
  13865. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  13866. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  13867. uBytes,
  13868. ownerPassword)) {
  13869. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  13870. ownerEncryption);
  13871. }
  13872. }
  13873. return null;
  13874. }
  13875. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  13876. flags, revision, keyLength, encryptMetadata) {
  13877. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  13878. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  13879. if (password) {
  13880. n = Math.min(32, password.length);
  13881. for (; i < n; ++i) {
  13882. hashData[i] = password[i];
  13883. }
  13884. }
  13885. j = 0;
  13886. while (i < 32) {
  13887. hashData[i++] = defaultPasswordBytes[j++];
  13888. }
  13889. // as now the padded password in the hashData[0..i]
  13890. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  13891. hashData[i++] = ownerPassword[j];
  13892. }
  13893. hashData[i++] = flags & 0xFF;
  13894. hashData[i++] = (flags >> 8) & 0xFF;
  13895. hashData[i++] = (flags >> 16) & 0xFF;
  13896. hashData[i++] = (flags >>> 24) & 0xFF;
  13897. for (j = 0, n = fileId.length; j < n; ++j) {
  13898. hashData[i++] = fileId[j];
  13899. }
  13900. if (revision >= 4 && !encryptMetadata) {
  13901. hashData[i++] = 0xFF;
  13902. hashData[i++] = 0xFF;
  13903. hashData[i++] = 0xFF;
  13904. hashData[i++] = 0xFF;
  13905. }
  13906. var hash = calculateMD5(hashData, 0, i);
  13907. var keyLengthInBytes = keyLength >> 3;
  13908. if (revision >= 3) {
  13909. for (j = 0; j < 50; ++j) {
  13910. hash = calculateMD5(hash, 0, keyLengthInBytes);
  13911. }
  13912. }
  13913. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  13914. var cipher, checkData;
  13915. if (revision >= 3) {
  13916. for (i = 0; i < 32; ++i) {
  13917. hashData[i] = defaultPasswordBytes[i];
  13918. }
  13919. for (j = 0, n = fileId.length; j < n; ++j) {
  13920. hashData[i++] = fileId[j];
  13921. }
  13922. cipher = new ARCFourCipher(encryptionKey);
  13923. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  13924. n = encryptionKey.length;
  13925. var derivedKey = new Uint8Array(n), k;
  13926. for (j = 1; j <= 19; ++j) {
  13927. for (k = 0; k < n; ++k) {
  13928. derivedKey[k] = encryptionKey[k] ^ j;
  13929. }
  13930. cipher = new ARCFourCipher(derivedKey);
  13931. checkData = cipher.encryptBlock(checkData);
  13932. }
  13933. for (j = 0, n = checkData.length; j < n; ++j) {
  13934. if (userPassword[j] !== checkData[j]) {
  13935. return null;
  13936. }
  13937. }
  13938. } else {
  13939. cipher = new ARCFourCipher(encryptionKey);
  13940. checkData = cipher.encryptBlock(defaultPasswordBytes);
  13941. for (j = 0, n = checkData.length; j < n; ++j) {
  13942. if (userPassword[j] !== checkData[j]) {
  13943. return null;
  13944. }
  13945. }
  13946. }
  13947. return encryptionKey;
  13948. }
  13949. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  13950. var hashData = new Uint8Array(32), i = 0, j, n;
  13951. n = Math.min(32, password.length);
  13952. for (; i < n; ++i) {
  13953. hashData[i] = password[i];
  13954. }
  13955. j = 0;
  13956. while (i < 32) {
  13957. hashData[i++] = defaultPasswordBytes[j++];
  13958. }
  13959. var hash = calculateMD5(hashData, 0, i);
  13960. var keyLengthInBytes = keyLength >> 3;
  13961. if (revision >= 3) {
  13962. for (j = 0; j < 50; ++j) {
  13963. hash = calculateMD5(hash, 0, hash.length);
  13964. }
  13965. }
  13966. var cipher, userPassword;
  13967. if (revision >= 3) {
  13968. userPassword = ownerPassword;
  13969. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  13970. for (j = 19; j >= 0; j--) {
  13971. for (k = 0; k < keyLengthInBytes; ++k) {
  13972. derivedKey[k] = hash[k] ^ j;
  13973. }
  13974. cipher = new ARCFourCipher(derivedKey);
  13975. userPassword = cipher.encryptBlock(userPassword);
  13976. }
  13977. } else {
  13978. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  13979. userPassword = cipher.encryptBlock(ownerPassword);
  13980. }
  13981. return userPassword;
  13982. }
  13983. var identityName = Name.get('Identity');
  13984. function CipherTransformFactory(dict, fileId, password) {
  13985. var filter = dict.get('Filter');
  13986. if (!isName(filter) || filter.name !== 'Standard') {
  13987. error('unknown encryption method');
  13988. }
  13989. this.dict = dict;
  13990. var algorithm = dict.get('V');
  13991. if (!isInt(algorithm) ||
  13992. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  13993. algorithm !== 5)) {
  13994. error('unsupported encryption algorithm');
  13995. }
  13996. this.algorithm = algorithm;
  13997. var keyLength = dict.get('Length') || 40;
  13998. if (!isInt(keyLength) ||
  13999. keyLength < 40 || (keyLength % 8) !== 0) {
  14000. error('invalid key length');
  14001. }
  14002. // prepare keys
  14003. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14004. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14005. var flags = dict.get('P');
  14006. var revision = dict.get('R');
  14007. // meaningful when V is 4 or 5
  14008. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14009. dict.get('EncryptMetadata') !== false);
  14010. this.encryptMetadata = encryptMetadata;
  14011. var fileIdBytes = stringToBytes(fileId);
  14012. var passwordBytes;
  14013. if (password) {
  14014. passwordBytes = stringToBytes(password);
  14015. }
  14016. var encryptionKey;
  14017. if (algorithm !== 5) {
  14018. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14019. ownerPassword, userPassword, flags,
  14020. revision, keyLength, encryptMetadata);
  14021. }
  14022. else {
  14023. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14024. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14025. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14026. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14027. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14028. var ownerEncryption = stringToBytes(dict.get('OE'));
  14029. var userEncryption = stringToBytes(dict.get('UE'));
  14030. var perms = stringToBytes(dict.get('Perms'));
  14031. encryptionKey =
  14032. createEncryptionKey20(revision, passwordBytes,
  14033. ownerPassword, ownerValidationSalt,
  14034. ownerKeySalt, uBytes,
  14035. userPassword, userValidationSalt,
  14036. userKeySalt, ownerEncryption,
  14037. userEncryption, perms);
  14038. }
  14039. if (!encryptionKey && !password) {
  14040. throw new PasswordException('No password given',
  14041. PasswordResponses.NEED_PASSWORD);
  14042. } else if (!encryptionKey && password) {
  14043. // Attempting use the password as an owner password
  14044. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14045. revision, keyLength);
  14046. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14047. ownerPassword, userPassword, flags,
  14048. revision, keyLength, encryptMetadata);
  14049. }
  14050. if (!encryptionKey) {
  14051. throw new PasswordException('Incorrect Password',
  14052. PasswordResponses.INCORRECT_PASSWORD);
  14053. }
  14054. this.encryptionKey = encryptionKey;
  14055. if (algorithm >= 4) {
  14056. this.cf = dict.get('CF');
  14057. this.stmf = dict.get('StmF') || identityName;
  14058. this.strf = dict.get('StrF') || identityName;
  14059. this.eff = dict.get('EFF') || this.strf;
  14060. }
  14061. }
  14062. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14063. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14064. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14065. key[i] = encryptionKey[i];
  14066. }
  14067. key[i++] = num & 0xFF;
  14068. key[i++] = (num >> 8) & 0xFF;
  14069. key[i++] = (num >> 16) & 0xFF;
  14070. key[i++] = gen & 0xFF;
  14071. key[i++] = (gen >> 8) & 0xFF;
  14072. if (isAes) {
  14073. key[i++] = 0x73;
  14074. key[i++] = 0x41;
  14075. key[i++] = 0x6C;
  14076. key[i++] = 0x54;
  14077. }
  14078. var hash = calculateMD5(key, 0, i);
  14079. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14080. }
  14081. function buildCipherConstructor(cf, name, num, gen, key) {
  14082. var cryptFilter = cf.get(name.name);
  14083. var cfm;
  14084. if (cryptFilter !== null && cryptFilter !== undefined) {
  14085. cfm = cryptFilter.get('CFM');
  14086. }
  14087. if (!cfm || cfm.name === 'None') {
  14088. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14089. return new NullCipher();
  14090. };
  14091. }
  14092. if ('V2' === cfm.name) {
  14093. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14094. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14095. };
  14096. }
  14097. if ('AESV2' === cfm.name) {
  14098. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14099. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14100. };
  14101. }
  14102. if ('AESV3' === cfm.name) {
  14103. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14104. return new AES256Cipher(key);
  14105. };
  14106. }
  14107. error('Unknown crypto method');
  14108. }
  14109. CipherTransformFactory.prototype = {
  14110. createCipherTransform:
  14111. function CipherTransformFactory_createCipherTransform(num, gen) {
  14112. if (this.algorithm === 4 || this.algorithm === 5) {
  14113. return new CipherTransform(
  14114. buildCipherConstructor(this.cf, this.stmf,
  14115. num, gen, this.encryptionKey),
  14116. buildCipherConstructor(this.cf, this.strf,
  14117. num, gen, this.encryptionKey));
  14118. }
  14119. // algorithms 1 and 2
  14120. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14121. var cipherConstructor = function buildCipherCipherConstructor() {
  14122. return new ARCFourCipher(key);
  14123. };
  14124. return new CipherTransform(cipherConstructor, cipherConstructor);
  14125. }
  14126. };
  14127. return CipherTransformFactory;
  14128. })();
  14129. var PatternType = {
  14130. FUNCTION_BASED: 1,
  14131. AXIAL: 2,
  14132. RADIAL: 3,
  14133. FREE_FORM_MESH: 4,
  14134. LATTICE_FORM_MESH: 5,
  14135. COONS_PATCH_MESH: 6,
  14136. TENSOR_PATCH_MESH: 7
  14137. };
  14138. var Pattern = (function PatternClosure() {
  14139. // Constructor should define this.getPattern
  14140. function Pattern() {
  14141. error('should not call Pattern constructor');
  14142. }
  14143. Pattern.prototype = {
  14144. // Input: current Canvas context
  14145. // Output: the appropriate fillStyle or strokeStyle
  14146. getPattern: function Pattern_getPattern(ctx) {
  14147. error('Should not call Pattern.getStyle: ' + ctx);
  14148. }
  14149. };
  14150. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14151. res) {
  14152. var dict = isStream(shading) ? shading.dict : shading;
  14153. var type = dict.get('ShadingType');
  14154. switch (type) {
  14155. case PatternType.AXIAL:
  14156. case PatternType.RADIAL:
  14157. // Both radial and axial shadings are handled by RadialAxial shading.
  14158. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14159. case PatternType.FREE_FORM_MESH:
  14160. case PatternType.LATTICE_FORM_MESH:
  14161. case PatternType.COONS_PATCH_MESH:
  14162. case PatternType.TENSOR_PATCH_MESH:
  14163. return new Shadings.Mesh(shading, matrix, xref, res);
  14164. default:
  14165. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14166. return new Shadings.Dummy();
  14167. }
  14168. };
  14169. return Pattern;
  14170. })();
  14171. var Shadings = {};
  14172. // A small number to offset the first/last color stops so we can insert ones to
  14173. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14174. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14175. // internally so we have to go bigger.
  14176. Shadings.SMALL_NUMBER = 1e-2;
  14177. // Radial and axial shading have very similar implementations
  14178. // If needed, the implementations can be broken into two classes
  14179. Shadings.RadialAxial = (function RadialAxialClosure() {
  14180. function RadialAxial(dict, matrix, xref, res) {
  14181. this.matrix = matrix;
  14182. this.coordsArr = dict.get('Coords');
  14183. this.shadingType = dict.get('ShadingType');
  14184. this.type = 'Pattern';
  14185. var cs = dict.get('ColorSpace', 'CS');
  14186. cs = ColorSpace.parse(cs, xref, res);
  14187. this.cs = cs;
  14188. var t0 = 0.0, t1 = 1.0;
  14189. if (dict.has('Domain')) {
  14190. var domainArr = dict.get('Domain');
  14191. t0 = domainArr[0];
  14192. t1 = domainArr[1];
  14193. }
  14194. var extendStart = false, extendEnd = false;
  14195. if (dict.has('Extend')) {
  14196. var extendArr = dict.get('Extend');
  14197. extendStart = extendArr[0];
  14198. extendEnd = extendArr[1];
  14199. }
  14200. if (this.shadingType === PatternType.RADIAL &&
  14201. (!extendStart || !extendEnd)) {
  14202. // Radial gradient only currently works if either circle is fully within
  14203. // the other circle.
  14204. var x1 = this.coordsArr[0];
  14205. var y1 = this.coordsArr[1];
  14206. var r1 = this.coordsArr[2];
  14207. var x2 = this.coordsArr[3];
  14208. var y2 = this.coordsArr[4];
  14209. var r2 = this.coordsArr[5];
  14210. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14211. if (r1 <= r2 + distance &&
  14212. r2 <= r1 + distance) {
  14213. warn('Unsupported radial gradient.');
  14214. }
  14215. }
  14216. this.extendStart = extendStart;
  14217. this.extendEnd = extendEnd;
  14218. var fnObj = dict.get('Function');
  14219. var fn = PDFFunction.parseArray(xref, fnObj);
  14220. // 10 samples seems good enough for now, but probably won't work
  14221. // if there are sharp color changes. Ideally, we would implement
  14222. // the spec faithfully and add lossless optimizations.
  14223. var diff = t1 - t0;
  14224. var step = diff / 10;
  14225. var colorStops = this.colorStops = [];
  14226. // Protect against bad domains so we don't end up in an infinte loop below.
  14227. if (t0 >= t1 || step <= 0) {
  14228. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14229. // now.
  14230. info('Bad shading domain.');
  14231. return;
  14232. }
  14233. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14234. var rgbColor;
  14235. for (var i = t0; i <= t1; i += step) {
  14236. ratio[0] = i;
  14237. fn(ratio, 0, color, 0);
  14238. rgbColor = cs.getRgb(color, 0);
  14239. var cssColor = Util.makeCssRgb(rgbColor);
  14240. colorStops.push([(i - t0) / diff, cssColor]);
  14241. }
  14242. var background = 'transparent';
  14243. if (dict.has('Background')) {
  14244. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14245. background = Util.makeCssRgb(rgbColor);
  14246. }
  14247. if (!extendStart) {
  14248. // Insert a color stop at the front and offset the first real color stop
  14249. // so it doesn't conflict with the one we insert.
  14250. colorStops.unshift([0, background]);
  14251. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14252. }
  14253. if (!extendEnd) {
  14254. // Same idea as above in extendStart but for the end.
  14255. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14256. colorStops.push([1, background]);
  14257. }
  14258. this.colorStops = colorStops;
  14259. }
  14260. RadialAxial.prototype = {
  14261. getIR: function RadialAxial_getIR() {
  14262. var coordsArr = this.coordsArr;
  14263. var shadingType = this.shadingType;
  14264. var type, p0, p1, r0, r1;
  14265. if (shadingType === PatternType.AXIAL) {
  14266. p0 = [coordsArr[0], coordsArr[1]];
  14267. p1 = [coordsArr[2], coordsArr[3]];
  14268. r0 = null;
  14269. r1 = null;
  14270. type = 'axial';
  14271. } else if (shadingType === PatternType.RADIAL) {
  14272. p0 = [coordsArr[0], coordsArr[1]];
  14273. p1 = [coordsArr[3], coordsArr[4]];
  14274. r0 = coordsArr[2];
  14275. r1 = coordsArr[5];
  14276. type = 'radial';
  14277. } else {
  14278. error('getPattern type unknown: ' + shadingType);
  14279. }
  14280. var matrix = this.matrix;
  14281. if (matrix) {
  14282. p0 = Util.applyTransform(p0, matrix);
  14283. p1 = Util.applyTransform(p1, matrix);
  14284. }
  14285. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14286. }
  14287. };
  14288. return RadialAxial;
  14289. })();
  14290. // All mesh shading. For now, they will be presented as set of the triangles
  14291. // to be drawn on the canvas and rgb color for each vertex.
  14292. Shadings.Mesh = (function MeshClosure() {
  14293. function MeshStreamReader(stream, context) {
  14294. this.stream = stream;
  14295. this.context = context;
  14296. this.buffer = 0;
  14297. this.bufferLength = 0;
  14298. var numComps = context.numComps;
  14299. this.tmpCompsBuf = new Float32Array(numComps);
  14300. var csNumComps = context.colorSpace;
  14301. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14302. this.tmpCompsBuf;
  14303. }
  14304. MeshStreamReader.prototype = {
  14305. get hasData() {
  14306. if (this.stream.end) {
  14307. return this.stream.pos < this.stream.end;
  14308. }
  14309. if (this.bufferLength > 0) {
  14310. return true;
  14311. }
  14312. var nextByte = this.stream.getByte();
  14313. if (nextByte < 0) {
  14314. return false;
  14315. }
  14316. this.buffer = nextByte;
  14317. this.bufferLength = 8;
  14318. return true;
  14319. },
  14320. readBits: function MeshStreamReader_readBits(n) {
  14321. var buffer = this.buffer;
  14322. var bufferLength = this.bufferLength;
  14323. if (n === 32) {
  14324. if (bufferLength === 0) {
  14325. return ((this.stream.getByte() << 24) |
  14326. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14327. this.stream.getByte()) >>> 0;
  14328. }
  14329. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14330. (this.stream.getByte() << 8) | this.stream.getByte();
  14331. var nextByte = this.stream.getByte();
  14332. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14333. return ((buffer << (8 - bufferLength)) |
  14334. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14335. }
  14336. if (n === 8 && bufferLength === 0) {
  14337. return this.stream.getByte();
  14338. }
  14339. while (bufferLength < n) {
  14340. buffer = (buffer << 8) | this.stream.getByte();
  14341. bufferLength += 8;
  14342. }
  14343. bufferLength -= n;
  14344. this.bufferLength = bufferLength;
  14345. this.buffer = buffer & ((1 << bufferLength) - 1);
  14346. return buffer >> bufferLength;
  14347. },
  14348. align: function MeshStreamReader_align() {
  14349. this.buffer = 0;
  14350. this.bufferLength = 0;
  14351. },
  14352. readFlag: function MeshStreamReader_readFlag() {
  14353. return this.readBits(this.context.bitsPerFlag);
  14354. },
  14355. readCoordinate: function MeshStreamReader_readCoordinate() {
  14356. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14357. var xi = this.readBits(bitsPerCoordinate);
  14358. var yi = this.readBits(bitsPerCoordinate);
  14359. var decode = this.context.decode;
  14360. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14361. 2.3283064365386963e-10; // 2 ^ -32
  14362. return [
  14363. xi * scale * (decode[1] - decode[0]) + decode[0],
  14364. yi * scale * (decode[3] - decode[2]) + decode[2]
  14365. ];
  14366. },
  14367. readComponents: function MeshStreamReader_readComponents() {
  14368. var numComps = this.context.numComps;
  14369. var bitsPerComponent = this.context.bitsPerComponent;
  14370. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14371. 2.3283064365386963e-10; // 2 ^ -32
  14372. var decode = this.context.decode;
  14373. var components = this.tmpCompsBuf;
  14374. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14375. var ci = this.readBits(bitsPerComponent);
  14376. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14377. }
  14378. var color = this.tmpCsCompsBuf;
  14379. if (this.context.colorFn) {
  14380. this.context.colorFn(components, 0, color, 0);
  14381. }
  14382. return this.context.colorSpace.getRgb(color, 0);
  14383. }
  14384. };
  14385. function decodeType4Shading(mesh, reader) {
  14386. var coords = mesh.coords;
  14387. var colors = mesh.colors;
  14388. var operators = [];
  14389. var ps = []; // not maintaining cs since that will match ps
  14390. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14391. while (reader.hasData) {
  14392. var f = reader.readFlag();
  14393. var coord = reader.readCoordinate();
  14394. var color = reader.readComponents();
  14395. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14396. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14397. switch (f) {
  14398. case 0:
  14399. verticesLeft = 3;
  14400. break;
  14401. case 1:
  14402. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14403. verticesLeft = 1;
  14404. break;
  14405. case 2:
  14406. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14407. verticesLeft = 1;
  14408. break;
  14409. }
  14410. operators.push(f);
  14411. }
  14412. ps.push(coords.length);
  14413. coords.push(coord);
  14414. colors.push(color);
  14415. verticesLeft--;
  14416. reader.align();
  14417. }
  14418. var psPacked = new Int32Array(ps);
  14419. mesh.figures.push({
  14420. type: 'triangles',
  14421. coords: psPacked,
  14422. colors: psPacked
  14423. });
  14424. }
  14425. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14426. var coords = mesh.coords;
  14427. var colors = mesh.colors;
  14428. var ps = []; // not maintaining cs since that will match ps
  14429. while (reader.hasData) {
  14430. var coord = reader.readCoordinate();
  14431. var color = reader.readComponents();
  14432. ps.push(coords.length);
  14433. coords.push(coord);
  14434. colors.push(color);
  14435. }
  14436. var psPacked = new Int32Array(ps);
  14437. mesh.figures.push({
  14438. type: 'lattice',
  14439. coords: psPacked,
  14440. colors: psPacked,
  14441. verticesPerRow: verticesPerRow
  14442. });
  14443. }
  14444. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14445. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14446. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14447. var getB = (function getBClosure() {
  14448. function buildB(count) {
  14449. var lut = [];
  14450. for (var i = 0; i <= count; i++) {
  14451. var t = i / count, t_ = 1 - t;
  14452. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14453. 3 * t * t * t_, t * t * t]));
  14454. }
  14455. return lut;
  14456. }
  14457. var cache = [];
  14458. return function getB(count) {
  14459. if (!cache[count]) {
  14460. cache[count] = buildB(count);
  14461. }
  14462. return cache[count];
  14463. };
  14464. })();
  14465. function buildFigureFromPatch(mesh, index) {
  14466. var figure = mesh.figures[index];
  14467. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14468. var coords = mesh.coords, colors = mesh.colors;
  14469. var pi = figure.coords;
  14470. var ci = figure.colors;
  14471. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14472. coords[pi[12]][0], coords[pi[15]][0]);
  14473. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14474. coords[pi[12]][1], coords[pi[15]][1]);
  14475. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14476. coords[pi[12]][0], coords[pi[15]][0]);
  14477. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14478. coords[pi[12]][1], coords[pi[15]][1]);
  14479. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14480. (mesh.bounds[2] - mesh.bounds[0]));
  14481. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14482. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14483. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14484. (mesh.bounds[3] - mesh.bounds[1]));
  14485. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14486. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14487. var verticesPerRow = splitXBy + 1;
  14488. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14489. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14490. var k = 0;
  14491. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14492. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14493. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14494. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14495. for (var row = 0; row <= splitYBy; row++) {
  14496. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14497. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14498. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14499. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14500. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14501. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14502. for (var col = 0; col <= splitXBy; col++, k++) {
  14503. if ((row === 0 || row === splitYBy) &&
  14504. (col === 0 || col === splitXBy)) {
  14505. continue;
  14506. }
  14507. var x = 0, y = 0;
  14508. var q = 0;
  14509. for (var i = 0; i <= 3; i++) {
  14510. for (var j = 0; j <= 3; j++, q++) {
  14511. var m = bRow[row][i] * bCol[col][j];
  14512. x += coords[pi[q]][0] * m;
  14513. y += coords[pi[q]][1] * m;
  14514. }
  14515. }
  14516. figureCoords[k] = coords.length;
  14517. coords.push([x, y]);
  14518. figureColors[k] = colors.length;
  14519. var newColor = new Uint8Array(3);
  14520. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14521. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14522. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14523. colors.push(newColor);
  14524. }
  14525. }
  14526. figureCoords[0] = pi[0];
  14527. figureColors[0] = ci[0];
  14528. figureCoords[splitXBy] = pi[3];
  14529. figureColors[splitXBy] = ci[1];
  14530. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14531. figureColors[verticesPerRow * splitYBy] = ci[2];
  14532. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14533. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14534. mesh.figures[index] = {
  14535. type: 'lattice',
  14536. coords: figureCoords,
  14537. colors: figureColors,
  14538. verticesPerRow: verticesPerRow
  14539. };
  14540. }
  14541. function decodeType6Shading(mesh, reader) {
  14542. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14543. var coords = mesh.coords;
  14544. var colors = mesh.colors;
  14545. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14546. var cs = new Int32Array(4); // c00, c30, c03, c33
  14547. while (reader.hasData) {
  14548. var f = reader.readFlag();
  14549. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14550. var i, ii;
  14551. var pi = coords.length;
  14552. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14553. coords.push(reader.readCoordinate());
  14554. }
  14555. var ci = colors.length;
  14556. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14557. colors.push(reader.readComponents());
  14558. }
  14559. var tmp1, tmp2, tmp3, tmp4;
  14560. switch (f) {
  14561. case 0:
  14562. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14563. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14564. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14565. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14566. cs[2] = ci + 1; cs[3] = ci + 2;
  14567. cs[0] = ci; cs[1] = ci + 3;
  14568. break;
  14569. case 1:
  14570. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14571. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14572. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14573. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14574. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14575. tmp1 = cs[2]; tmp2 = cs[3];
  14576. cs[2] = ci + 1; cs[3] = ci;
  14577. cs[0] = tmp1; cs[1] = tmp2;
  14578. break;
  14579. case 2:
  14580. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14581. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14582. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14583. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14584. cs[2] = cs[3]; cs[3] = ci + 1;
  14585. cs[0] = cs[1]; cs[1] = ci;
  14586. break;
  14587. case 3:
  14588. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14589. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14590. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14591. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14592. cs[2] = cs[0]; cs[3] = cs[1];
  14593. cs[0] = ci; cs[1] = ci + 1;
  14594. break;
  14595. }
  14596. // set p11, p12, p21, p22
  14597. ps[5] = coords.length;
  14598. coords.push([
  14599. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14600. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14601. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14602. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14603. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14604. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14605. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14606. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14607. ]);
  14608. ps[6] = coords.length;
  14609. coords.push([
  14610. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14611. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14612. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14613. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14614. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14615. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14616. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14617. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14618. ]);
  14619. ps[9] = coords.length;
  14620. coords.push([
  14621. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14622. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14623. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14624. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14625. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14626. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14627. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14628. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14629. ]);
  14630. ps[10] = coords.length;
  14631. coords.push([
  14632. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14633. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14634. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14635. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14636. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14637. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14638. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14639. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14640. ]);
  14641. mesh.figures.push({
  14642. type: 'patch',
  14643. coords: new Int32Array(ps), // making copies of ps and cs
  14644. colors: new Int32Array(cs)
  14645. });
  14646. }
  14647. }
  14648. function decodeType7Shading(mesh, reader) {
  14649. var coords = mesh.coords;
  14650. var colors = mesh.colors;
  14651. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14652. var cs = new Int32Array(4); // c00, c30, c03, c33
  14653. while (reader.hasData) {
  14654. var f = reader.readFlag();
  14655. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  14656. var i, ii;
  14657. var pi = coords.length;
  14658. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  14659. coords.push(reader.readCoordinate());
  14660. }
  14661. var ci = colors.length;
  14662. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14663. colors.push(reader.readComponents());
  14664. }
  14665. var tmp1, tmp2, tmp3, tmp4;
  14666. switch (f) {
  14667. case 0:
  14668. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14669. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  14670. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  14671. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14672. cs[2] = ci + 1; cs[3] = ci + 2;
  14673. cs[0] = ci; cs[1] = ci + 3;
  14674. break;
  14675. case 1:
  14676. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14677. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14678. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  14679. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  14680. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14681. tmp1 = cs[2]; tmp2 = cs[3];
  14682. cs[2] = ci + 1; cs[3] = ci;
  14683. cs[0] = tmp1; cs[1] = tmp2;
  14684. break;
  14685. case 2:
  14686. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14687. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  14688. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  14689. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14690. cs[2] = cs[3]; cs[3] = ci + 1;
  14691. cs[0] = cs[1]; cs[1] = ci;
  14692. break;
  14693. case 3:
  14694. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14695. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  14696. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  14697. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14698. cs[2] = cs[0]; cs[3] = cs[1];
  14699. cs[0] = ci; cs[1] = ci + 1;
  14700. break;
  14701. }
  14702. mesh.figures.push({
  14703. type: 'patch',
  14704. coords: new Int32Array(ps), // making copies of ps and cs
  14705. colors: new Int32Array(cs)
  14706. });
  14707. }
  14708. }
  14709. function updateBounds(mesh) {
  14710. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  14711. maxX = minX, maxY = minY;
  14712. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  14713. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  14714. minX = minX > x ? x : minX;
  14715. minY = minY > y ? y : minY;
  14716. maxX = maxX < x ? x : maxX;
  14717. maxY = maxY < y ? y : maxY;
  14718. }
  14719. mesh.bounds = [minX, minY, maxX, maxY];
  14720. }
  14721. function packData(mesh) {
  14722. var i, ii, j, jj;
  14723. var coords = mesh.coords;
  14724. var coordsPacked = new Float32Array(coords.length * 2);
  14725. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  14726. var xy = coords[i];
  14727. coordsPacked[j++] = xy[0];
  14728. coordsPacked[j++] = xy[1];
  14729. }
  14730. mesh.coords = coordsPacked;
  14731. var colors = mesh.colors;
  14732. var colorsPacked = new Uint8Array(colors.length * 3);
  14733. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  14734. var c = colors[i];
  14735. colorsPacked[j++] = c[0];
  14736. colorsPacked[j++] = c[1];
  14737. colorsPacked[j++] = c[2];
  14738. }
  14739. mesh.colors = colorsPacked;
  14740. var figures = mesh.figures;
  14741. for (i = 0, ii = figures.length; i < ii; i++) {
  14742. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  14743. for (j = 0, jj = ps.length; j < jj; j++) {
  14744. ps[j] *= 2;
  14745. cs[j] *= 3;
  14746. }
  14747. }
  14748. }
  14749. function Mesh(stream, matrix, xref, res) {
  14750. assert(isStream(stream), 'Mesh data is not a stream');
  14751. var dict = stream.dict;
  14752. this.matrix = matrix;
  14753. this.shadingType = dict.get('ShadingType');
  14754. this.type = 'Pattern';
  14755. this.bbox = dict.get('BBox');
  14756. var cs = dict.get('ColorSpace', 'CS');
  14757. cs = ColorSpace.parse(cs, xref, res);
  14758. this.cs = cs;
  14759. this.background = dict.has('Background') ?
  14760. cs.getRgb(dict.get('Background'), 0) : null;
  14761. var fnObj = dict.get('Function');
  14762. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  14763. this.coords = [];
  14764. this.colors = [];
  14765. this.figures = [];
  14766. var decodeContext = {
  14767. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  14768. bitsPerComponent: dict.get('BitsPerComponent'),
  14769. bitsPerFlag: dict.get('BitsPerFlag'),
  14770. decode: dict.get('Decode'),
  14771. colorFn: fn,
  14772. colorSpace: cs,
  14773. numComps: fn ? 1 : cs.numComps
  14774. };
  14775. var reader = new MeshStreamReader(stream, decodeContext);
  14776. var patchMesh = false;
  14777. switch (this.shadingType) {
  14778. case PatternType.FREE_FORM_MESH:
  14779. decodeType4Shading(this, reader);
  14780. break;
  14781. case PatternType.LATTICE_FORM_MESH:
  14782. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  14783. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  14784. decodeType5Shading(this, reader, verticesPerRow);
  14785. break;
  14786. case PatternType.COONS_PATCH_MESH:
  14787. decodeType6Shading(this, reader);
  14788. patchMesh = true;
  14789. break;
  14790. case PatternType.TENSOR_PATCH_MESH:
  14791. decodeType7Shading(this, reader);
  14792. patchMesh = true;
  14793. break;
  14794. default:
  14795. error('Unsupported mesh type.');
  14796. break;
  14797. }
  14798. if (patchMesh) {
  14799. // dirty bounds calculation for determining, how dense shall be triangles
  14800. updateBounds(this);
  14801. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  14802. buildFigureFromPatch(this, i);
  14803. }
  14804. }
  14805. // calculate bounds
  14806. updateBounds(this);
  14807. packData(this);
  14808. }
  14809. Mesh.prototype = {
  14810. getIR: function Mesh_getIR() {
  14811. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  14812. this.bounds, this.matrix, this.bbox, this.background];
  14813. }
  14814. };
  14815. return Mesh;
  14816. })();
  14817. Shadings.Dummy = (function DummyClosure() {
  14818. function Dummy() {
  14819. this.type = 'Pattern';
  14820. }
  14821. Dummy.prototype = {
  14822. getIR: function Dummy_getIR() {
  14823. return ['Dummy'];
  14824. }
  14825. };
  14826. return Dummy;
  14827. })();
  14828. function getTilingPatternIR(operatorList, dict, args) {
  14829. var matrix = dict.get('Matrix');
  14830. var bbox = dict.get('BBox');
  14831. var xstep = dict.get('XStep');
  14832. var ystep = dict.get('YStep');
  14833. var paintType = dict.get('PaintType');
  14834. var tilingType = dict.get('TilingType');
  14835. return [
  14836. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  14837. paintType, tilingType
  14838. ];
  14839. }
  14840. var PartialEvaluator = (function PartialEvaluatorClosure() {
  14841. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  14842. uniquePrefix, idCounters, fontCache) {
  14843. this.pdfManager = pdfManager;
  14844. this.xref = xref;
  14845. this.handler = handler;
  14846. this.pageIndex = pageIndex;
  14847. this.uniquePrefix = uniquePrefix;
  14848. this.idCounters = idCounters;
  14849. this.fontCache = fontCache;
  14850. }
  14851. // Trying to minimize Date.now() usage and check every 100 time
  14852. var TIME_SLOT_DURATION_MS = 20;
  14853. var CHECK_TIME_EVERY = 100;
  14854. function TimeSlotManager() {
  14855. this.reset();
  14856. }
  14857. TimeSlotManager.prototype = {
  14858. check: function TimeSlotManager_check() {
  14859. if (++this.checked < CHECK_TIME_EVERY) {
  14860. return false;
  14861. }
  14862. this.checked = 0;
  14863. return this.endTime <= Date.now();
  14864. },
  14865. reset: function TimeSlotManager_reset() {
  14866. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  14867. this.checked = 0;
  14868. }
  14869. };
  14870. var deferred = Promise.resolve();
  14871. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  14872. PartialEvaluator.prototype = {
  14873. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  14874. if (!isDict(resources)) {
  14875. return false;
  14876. }
  14877. var processed = Object.create(null);
  14878. if (resources.objId) {
  14879. processed[resources.objId] = true;
  14880. }
  14881. var nodes = [resources];
  14882. while (nodes.length) {
  14883. var key;
  14884. var node = nodes.shift();
  14885. // First check the current resources for blend modes.
  14886. var graphicStates = node.get('ExtGState');
  14887. if (isDict(graphicStates)) {
  14888. graphicStates = graphicStates.getAll();
  14889. for (key in graphicStates) {
  14890. var graphicState = graphicStates[key];
  14891. var bm = graphicState['BM'];
  14892. if (isName(bm) && bm.name !== 'Normal') {
  14893. return true;
  14894. }
  14895. }
  14896. }
  14897. // Descend into the XObjects to look for more resources and blend modes.
  14898. var xObjects = node.get('XObject');
  14899. if (!isDict(xObjects)) {
  14900. continue;
  14901. }
  14902. xObjects = xObjects.getAll();
  14903. for (key in xObjects) {
  14904. var xObject = xObjects[key];
  14905. if (!isStream(xObject)) {
  14906. continue;
  14907. }
  14908. if (xObject.dict.objId) {
  14909. if (processed[xObject.dict.objId]) {
  14910. // stream has objId and is processed already
  14911. continue;
  14912. }
  14913. processed[xObject.dict.objId] = true;
  14914. }
  14915. var xResources = xObject.dict.get('Resources');
  14916. // Checking objId to detect an infinite loop.
  14917. if (isDict(xResources) &&
  14918. (!xResources.objId || !processed[xResources.objId])) {
  14919. nodes.push(xResources);
  14920. if (xResources.objId) {
  14921. processed[xResources.objId] = true;
  14922. }
  14923. }
  14924. }
  14925. }
  14926. return false;
  14927. },
  14928. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  14929. xobj, smask,
  14930. operatorList,
  14931. initialState) {
  14932. var matrix = xobj.dict.get('Matrix');
  14933. var bbox = xobj.dict.get('BBox');
  14934. var group = xobj.dict.get('Group');
  14935. if (group) {
  14936. var groupOptions = {
  14937. matrix: matrix,
  14938. bbox: bbox,
  14939. smask: smask,
  14940. isolated: false,
  14941. knockout: false
  14942. };
  14943. var groupSubtype = group.get('S');
  14944. var colorSpace;
  14945. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  14946. groupOptions.isolated = (group.get('I') || false);
  14947. groupOptions.knockout = (group.get('K') || false);
  14948. colorSpace = (group.has('CS') ?
  14949. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  14950. }
  14951. if (smask && smask.backdrop) {
  14952. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  14953. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  14954. }
  14955. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  14956. }
  14957. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  14958. return this.getOperatorList(xobj,
  14959. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  14960. then(function () {
  14961. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  14962. if (group) {
  14963. operatorList.addOp(OPS.endGroup, [groupOptions]);
  14964. }
  14965. });
  14966. },
  14967. buildPaintImageXObject:
  14968. function PartialEvaluator_buildPaintImageXObject(resources, image,
  14969. inline, operatorList,
  14970. cacheKey, cache) {
  14971. var self = this;
  14972. var dict = image.dict;
  14973. var w = dict.get('Width', 'W');
  14974. var h = dict.get('Height', 'H');
  14975. if (!(w && isNum(w)) || !(h && isNum(h))) {
  14976. warn('Image dimensions are missing, or not numbers.');
  14977. return;
  14978. }
  14979. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  14980. warn('Image exceeded maximum allowed size and was removed.');
  14981. return;
  14982. }
  14983. var imageMask = (dict.get('ImageMask', 'IM') || false);
  14984. var imgData, args;
  14985. if (imageMask) {
  14986. // This depends on a tmpCanvas being filled with the
  14987. // current fillStyle, such that processing the pixel
  14988. // data can't be done here. Instead of creating a
  14989. // complete PDFImage, only read the information needed
  14990. // for later.
  14991. var width = dict.get('Width', 'W');
  14992. var height = dict.get('Height', 'H');
  14993. var bitStrideLength = (width + 7) >> 3;
  14994. var imgArray = image.getBytes(bitStrideLength * height);
  14995. var decode = dict.get('Decode', 'D');
  14996. var inverseDecode = (!!decode && decode[0] > 0);
  14997. imgData = PDFImage.createMask(imgArray, width, height,
  14998. image instanceof DecodeStream,
  14999. inverseDecode);
  15000. imgData.cached = true;
  15001. args = [imgData];
  15002. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15003. if (cacheKey) {
  15004. cache.key = cacheKey;
  15005. cache.fn = OPS.paintImageMaskXObject;
  15006. cache.args = args;
  15007. }
  15008. return;
  15009. }
  15010. var softMask = (dict.get('SMask', 'SM') || false);
  15011. var mask = (dict.get('Mask') || false);
  15012. var SMALL_IMAGE_DIMENSIONS = 200;
  15013. // Inlining small images into the queue as RGB data
  15014. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15015. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15016. var imageObj = new PDFImage(this.xref, resources, image,
  15017. inline, null, null);
  15018. // We force the use of RGBA_32BPP images here, because we can't handle
  15019. // any other kind.
  15020. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15021. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15022. return;
  15023. }
  15024. // If there is no imageMask, create the PDFImage and a lot
  15025. // of image processing can be done here.
  15026. var uniquePrefix = (this.uniquePrefix || '');
  15027. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15028. operatorList.addDependency(objId);
  15029. args = [objId, w, h];
  15030. if (!softMask && !mask && image instanceof JpegStream &&
  15031. image.isNativelySupported(this.xref, resources)) {
  15032. // These JPEGs don't need any more processing so we can just send it.
  15033. operatorList.addOp(OPS.paintJpegXObject, args);
  15034. this.handler.send('obj',
  15035. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15036. return;
  15037. }
  15038. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15039. then(function(imageObj) {
  15040. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15041. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15042. [imgData.data.buffer]);
  15043. }).then(null, function (reason) {
  15044. warn('Unable to decode image: ' + reason);
  15045. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15046. });
  15047. operatorList.addOp(OPS.paintImageXObject, args);
  15048. if (cacheKey) {
  15049. cache.key = cacheKey;
  15050. cache.fn = OPS.paintImageXObject;
  15051. cache.args = args;
  15052. }
  15053. },
  15054. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15055. operatorList,
  15056. stateManager) {
  15057. var smaskContent = smask.get('G');
  15058. var smaskOptions = {
  15059. subtype: smask.get('S').name,
  15060. backdrop: smask.get('BC')
  15061. };
  15062. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15063. operatorList, stateManager.state.clone());
  15064. },
  15065. handleTilingType:
  15066. function PartialEvaluator_handleTilingType(fn, args, resources,
  15067. pattern, patternDict,
  15068. operatorList) {
  15069. // Create an IR of the pattern code.
  15070. var tilingOpList = new OperatorList();
  15071. return this.getOperatorList(pattern,
  15072. (patternDict.get('Resources') || resources), tilingOpList).
  15073. then(function () {
  15074. // Add the dependencies to the parent operator list so they are
  15075. // resolved before sub operator list is executed synchronously.
  15076. operatorList.addDependencies(tilingOpList.dependencies);
  15077. operatorList.addOp(fn, getTilingPatternIR({
  15078. fnArray: tilingOpList.fnArray,
  15079. argsArray: tilingOpList.argsArray
  15080. }, patternDict, args));
  15081. });
  15082. },
  15083. handleSetFont:
  15084. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15085. operatorList, state) {
  15086. // TODO(mack): Not needed?
  15087. var fontName;
  15088. if (fontArgs) {
  15089. fontArgs = fontArgs.slice();
  15090. fontName = fontArgs[0].name;
  15091. }
  15092. var self = this;
  15093. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15094. function (translated) {
  15095. if (!translated.font.isType3Font) {
  15096. return translated;
  15097. }
  15098. return translated.loadType3Data(self, resources, operatorList).then(
  15099. function () {
  15100. return translated;
  15101. });
  15102. }).then(function (translated) {
  15103. state.font = translated.font;
  15104. translated.send(self.handler);
  15105. return translated.loadedName;
  15106. });
  15107. },
  15108. handleText: function PartialEvaluator_handleText(chars, state) {
  15109. var font = state.font;
  15110. var glyphs = font.charsToGlyphs(chars);
  15111. var isAddToPathSet = !!(state.textRenderingMode &
  15112. TextRenderingMode.ADD_TO_PATH_FLAG);
  15113. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15114. var buildPath = function (fontChar) {
  15115. if (!font.renderer.hasBuiltPath(fontChar)) {
  15116. var path = font.renderer.getPathJs(fontChar);
  15117. this.handler.send('commonobj', [
  15118. font.loadedName + '_path_' + fontChar,
  15119. 'FontPath',
  15120. path
  15121. ]);
  15122. }
  15123. }.bind(this);
  15124. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15125. var glyph = glyphs[i];
  15126. if (glyph === null) {
  15127. continue;
  15128. }
  15129. buildPath(glyph.fontChar);
  15130. // If the glyph has an accent we need to build a path for its
  15131. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15132. var accent = glyph.accent;
  15133. if (accent && accent.fontChar) {
  15134. buildPath(accent.fontChar);
  15135. }
  15136. }
  15137. }
  15138. return glyphs;
  15139. },
  15140. setGState: function PartialEvaluator_setGState(resources, gState,
  15141. operatorList, xref,
  15142. stateManager) {
  15143. // This array holds the converted/processed state data.
  15144. var gStateObj = [];
  15145. var gStateMap = gState.map;
  15146. var self = this;
  15147. var promise = Promise.resolve();
  15148. for (var key in gStateMap) {
  15149. var value = gStateMap[key];
  15150. switch (key) {
  15151. case 'Type':
  15152. break;
  15153. case 'LW':
  15154. case 'LC':
  15155. case 'LJ':
  15156. case 'ML':
  15157. case 'D':
  15158. case 'RI':
  15159. case 'FL':
  15160. case 'CA':
  15161. case 'ca':
  15162. gStateObj.push([key, value]);
  15163. break;
  15164. case 'Font':
  15165. promise = promise.then(function () {
  15166. return self.handleSetFont(resources, null, value[0],
  15167. operatorList, stateManager.state).
  15168. then(function (loadedName) {
  15169. operatorList.addDependency(loadedName);
  15170. gStateObj.push([key, [loadedName, value[1]]]);
  15171. });
  15172. });
  15173. break;
  15174. case 'BM':
  15175. gStateObj.push([key, value]);
  15176. break;
  15177. case 'SMask':
  15178. if (isName(value) && value.name === 'None') {
  15179. gStateObj.push([key, false]);
  15180. break;
  15181. }
  15182. var dict = xref.fetchIfRef(value);
  15183. if (isDict(dict)) {
  15184. promise = promise.then(function () {
  15185. return self.handleSMask(dict, resources, operatorList,
  15186. stateManager);
  15187. });
  15188. gStateObj.push([key, true]);
  15189. } else {
  15190. warn('Unsupported SMask type');
  15191. }
  15192. break;
  15193. // Only generate info log messages for the following since
  15194. // they are unlikely to have a big impact on the rendering.
  15195. case 'OP':
  15196. case 'op':
  15197. case 'OPM':
  15198. case 'BG':
  15199. case 'BG2':
  15200. case 'UCR':
  15201. case 'UCR2':
  15202. case 'TR':
  15203. case 'TR2':
  15204. case 'HT':
  15205. case 'SM':
  15206. case 'SA':
  15207. case 'AIS':
  15208. case 'TK':
  15209. // TODO implement these operators.
  15210. info('graphic state operator ' + key);
  15211. break;
  15212. default:
  15213. info('Unknown graphic state operator ' + key);
  15214. break;
  15215. }
  15216. }
  15217. return promise.then(function () {
  15218. if (gStateObj.length >= 0) {
  15219. operatorList.addOp(OPS.setGState, [gStateObj]);
  15220. }
  15221. });
  15222. },
  15223. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15224. resources) {
  15225. function errorFont() {
  15226. return Promise.resolve(new TranslatedFont('g_font_error',
  15227. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15228. }
  15229. var fontRef;
  15230. if (font) { // Loading by ref.
  15231. assert(isRef(font));
  15232. fontRef = font;
  15233. } else { // Loading by name.
  15234. var fontRes = resources.get('Font');
  15235. if (fontRes) {
  15236. fontRef = fontRes.getRaw(fontName);
  15237. } else {
  15238. warn('fontRes not available');
  15239. return errorFont();
  15240. }
  15241. }
  15242. if (!fontRef) {
  15243. warn('fontRef not available');
  15244. return errorFont();
  15245. }
  15246. if (this.fontCache.has(fontRef)) {
  15247. return this.fontCache.get(fontRef);
  15248. }
  15249. font = xref.fetchIfRef(fontRef);
  15250. if (!isDict(font)) {
  15251. return errorFont();
  15252. }
  15253. // We are holding font.translated references just for fontRef that are not
  15254. // dictionaries (Dict). See explanation below.
  15255. if (font.translated) {
  15256. return font.translated;
  15257. }
  15258. var fontCapability = createPromiseCapability();
  15259. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15260. var descriptor = preEvaluatedFont.descriptor;
  15261. var fontID = fontRef.num + '_' + fontRef.gen;
  15262. if (isDict(descriptor)) {
  15263. if (!descriptor.fontAliases) {
  15264. descriptor.fontAliases = Object.create(null);
  15265. }
  15266. var fontAliases = descriptor.fontAliases;
  15267. var hash = preEvaluatedFont.hash;
  15268. if (fontAliases[hash]) {
  15269. var aliasFontRef = fontAliases[hash].aliasRef;
  15270. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15271. this.fontCache.putAlias(fontRef, aliasFontRef);
  15272. return this.fontCache.get(fontRef);
  15273. }
  15274. }
  15275. if (!fontAliases[hash]) {
  15276. fontAliases[hash] = {
  15277. fontID: Font.getFontID()
  15278. };
  15279. }
  15280. fontAliases[hash].aliasRef = fontRef;
  15281. fontID = fontAliases[hash].fontID;
  15282. }
  15283. // Workaround for bad PDF generators that don't reference fonts
  15284. // properly, i.e. by not using an object identifier.
  15285. // Check if the fontRef is a Dict (as opposed to a standard object),
  15286. // in which case we don't cache the font and instead reference it by
  15287. // fontName in font.loadedName below.
  15288. var fontRefIsDict = isDict(fontRef);
  15289. if (!fontRefIsDict) {
  15290. this.fontCache.put(fontRef, fontCapability.promise);
  15291. }
  15292. // Keep track of each font we translated so the caller can
  15293. // load them asynchronously before calling display on a page.
  15294. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15295. fontName.replace(/\W/g, '') : fontID);
  15296. font.translated = fontCapability.promise;
  15297. // TODO move promises into translate font
  15298. var translatedPromise;
  15299. try {
  15300. translatedPromise = Promise.resolve(
  15301. this.translateFont(preEvaluatedFont, xref));
  15302. } catch (e) {
  15303. translatedPromise = Promise.reject(e);
  15304. }
  15305. translatedPromise.then(function (translatedFont) {
  15306. if (translatedFont.fontType !== undefined) {
  15307. var xrefFontStats = xref.stats.fontTypes;
  15308. xrefFontStats[translatedFont.fontType] = true;
  15309. }
  15310. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15311. translatedFont, font));
  15312. }, function (reason) {
  15313. // TODO fontCapability.reject?
  15314. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15315. try {
  15316. // error, but it's still nice to have font type reported
  15317. var descriptor = preEvaluatedFont.descriptor;
  15318. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15319. var subtype = fontFile3 && fontFile3.get('Subtype');
  15320. var fontType = getFontType(preEvaluatedFont.type,
  15321. subtype && subtype.name);
  15322. var xrefFontStats = xref.stats.fontTypes;
  15323. xrefFontStats[fontType] = true;
  15324. } catch (ex) { }
  15325. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15326. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15327. font));
  15328. });
  15329. return fontCapability.promise;
  15330. },
  15331. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15332. var lastIndex = operatorList.length - 1;
  15333. if (!args) {
  15334. args = [];
  15335. }
  15336. if (lastIndex < 0 ||
  15337. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15338. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15339. } else {
  15340. var opArgs = operatorList.argsArray[lastIndex];
  15341. opArgs[0].push(fn);
  15342. Array.prototype.push.apply(opArgs[1], args);
  15343. }
  15344. },
  15345. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15346. cs, patterns, resources, xref) {
  15347. // compile tiling patterns
  15348. var patternName = args[args.length - 1];
  15349. // SCN/scn applies patterns along with normal colors
  15350. var pattern;
  15351. if (isName(patternName) &&
  15352. (pattern = patterns.get(patternName.name))) {
  15353. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15354. var typeNum = dict.get('PatternType');
  15355. if (typeNum === TILING_PATTERN) {
  15356. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15357. return this.handleTilingType(fn, color, resources, pattern,
  15358. dict, operatorList);
  15359. } else if (typeNum === SHADING_PATTERN) {
  15360. var shading = dict.get('Shading');
  15361. var matrix = dict.get('Matrix');
  15362. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15363. operatorList.addOp(fn, pattern.getIR());
  15364. return Promise.resolve();
  15365. } else {
  15366. return Promise.reject('Unknown PatternType: ' + typeNum);
  15367. }
  15368. }
  15369. // TODO shall we fail here?
  15370. operatorList.addOp(fn, args);
  15371. return Promise.resolve();
  15372. },
  15373. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15374. resources,
  15375. operatorList,
  15376. initialState) {
  15377. var self = this;
  15378. var xref = this.xref;
  15379. var imageCache = {};
  15380. assert(operatorList);
  15381. resources = (resources || Dict.empty);
  15382. var xobjs = (resources.get('XObject') || Dict.empty);
  15383. var patterns = (resources.get('Pattern') || Dict.empty);
  15384. var stateManager = new StateManager(initialState || new EvalState());
  15385. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15386. var timeSlotManager = new TimeSlotManager();
  15387. return new Promise(function next(resolve, reject) {
  15388. timeSlotManager.reset();
  15389. var stop, operation = {}, i, ii, cs;
  15390. while (!(stop = timeSlotManager.check())) {
  15391. // The arguments parsed by read() are used beyond this loop, so we
  15392. // cannot reuse the same array on each iteration. Therefore we pass
  15393. // in |null| as the initial value (see the comment on
  15394. // EvaluatorPreprocessor_read() for why).
  15395. operation.args = null;
  15396. if (!(preprocessor.read(operation))) {
  15397. break;
  15398. }
  15399. var args = operation.args;
  15400. var fn = operation.fn;
  15401. switch (fn | 0) {
  15402. case OPS.paintXObject:
  15403. if (args[0].code) {
  15404. break;
  15405. }
  15406. // eagerly compile XForm objects
  15407. var name = args[0].name;
  15408. if (imageCache.key === name) {
  15409. operatorList.addOp(imageCache.fn, imageCache.args);
  15410. args = null;
  15411. continue;
  15412. }
  15413. var xobj = xobjs.get(name);
  15414. if (xobj) {
  15415. assert(isStream(xobj), 'XObject should be a stream');
  15416. var type = xobj.dict.get('Subtype');
  15417. assert(isName(type),
  15418. 'XObject should have a Name subtype');
  15419. if (type.name === 'Form') {
  15420. stateManager.save();
  15421. return self.buildFormXObject(resources, xobj, null,
  15422. operatorList,
  15423. stateManager.state.clone()).
  15424. then(function () {
  15425. stateManager.restore();
  15426. next(resolve, reject);
  15427. }, reject);
  15428. } else if (type.name === 'Image') {
  15429. self.buildPaintImageXObject(resources, xobj, false,
  15430. operatorList, name, imageCache);
  15431. args = null;
  15432. continue;
  15433. } else if (type.name === 'PS') {
  15434. // PostScript XObjects are unused when viewing documents.
  15435. // See section 4.7.1 of Adobe's PDF reference.
  15436. info('Ignored XObject subtype PS');
  15437. continue;
  15438. } else {
  15439. error('Unhandled XObject subtype ' + type.name);
  15440. }
  15441. }
  15442. break;
  15443. case OPS.setFont:
  15444. var fontSize = args[1];
  15445. // eagerly collect all fonts
  15446. return self.handleSetFont(resources, args, null,
  15447. operatorList, stateManager.state).
  15448. then(function (loadedName) {
  15449. operatorList.addDependency(loadedName);
  15450. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15451. next(resolve, reject);
  15452. }, reject);
  15453. case OPS.endInlineImage:
  15454. var cacheKey = args[0].cacheKey;
  15455. if (cacheKey && imageCache.key === cacheKey) {
  15456. operatorList.addOp(imageCache.fn, imageCache.args);
  15457. args = null;
  15458. continue;
  15459. }
  15460. self.buildPaintImageXObject(resources, args[0], true,
  15461. operatorList, cacheKey, imageCache);
  15462. args = null;
  15463. continue;
  15464. case OPS.showText:
  15465. args[0] = self.handleText(args[0], stateManager.state);
  15466. break;
  15467. case OPS.showSpacedText:
  15468. var arr = args[0];
  15469. var combinedGlyphs = [];
  15470. var arrLength = arr.length;
  15471. for (i = 0; i < arrLength; ++i) {
  15472. var arrItem = arr[i];
  15473. if (isString(arrItem)) {
  15474. Array.prototype.push.apply(combinedGlyphs,
  15475. self.handleText(arrItem, stateManager.state));
  15476. } else if (isNum(arrItem)) {
  15477. combinedGlyphs.push(arrItem);
  15478. }
  15479. }
  15480. args[0] = combinedGlyphs;
  15481. fn = OPS.showText;
  15482. break;
  15483. case OPS.nextLineShowText:
  15484. operatorList.addOp(OPS.nextLine);
  15485. args[0] = self.handleText(args[0], stateManager.state);
  15486. fn = OPS.showText;
  15487. break;
  15488. case OPS.nextLineSetSpacingShowText:
  15489. operatorList.addOp(OPS.nextLine);
  15490. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15491. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15492. args[0] = self.handleText(args[0], stateManager.state);
  15493. fn = OPS.showText;
  15494. break;
  15495. case OPS.setTextRenderingMode:
  15496. stateManager.state.textRenderingMode = args[0];
  15497. break;
  15498. case OPS.setFillColorSpace:
  15499. stateManager.state.fillColorSpace =
  15500. ColorSpace.parse(args[0], xref, resources);
  15501. continue;
  15502. case OPS.setStrokeColorSpace:
  15503. stateManager.state.strokeColorSpace =
  15504. ColorSpace.parse(args[0], xref, resources);
  15505. continue;
  15506. case OPS.setFillColor:
  15507. cs = stateManager.state.fillColorSpace;
  15508. args = cs.getRgb(args, 0);
  15509. fn = OPS.setFillRGBColor;
  15510. break;
  15511. case OPS.setStrokeColor:
  15512. cs = stateManager.state.strokeColorSpace;
  15513. args = cs.getRgb(args, 0);
  15514. fn = OPS.setStrokeRGBColor;
  15515. break;
  15516. case OPS.setFillGray:
  15517. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15518. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15519. fn = OPS.setFillRGBColor;
  15520. break;
  15521. case OPS.setStrokeGray:
  15522. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15523. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15524. fn = OPS.setStrokeRGBColor;
  15525. break;
  15526. case OPS.setFillCMYKColor:
  15527. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15528. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15529. fn = OPS.setFillRGBColor;
  15530. break;
  15531. case OPS.setStrokeCMYKColor:
  15532. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15533. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15534. fn = OPS.setStrokeRGBColor;
  15535. break;
  15536. case OPS.setFillRGBColor:
  15537. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15538. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15539. break;
  15540. case OPS.setStrokeRGBColor:
  15541. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15542. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15543. break;
  15544. case OPS.setFillColorN:
  15545. cs = stateManager.state.fillColorSpace;
  15546. if (cs.name === 'Pattern') {
  15547. return self.handleColorN(operatorList, OPS.setFillColorN,
  15548. args, cs, patterns, resources, xref).then(function() {
  15549. next(resolve, reject);
  15550. }, reject);
  15551. }
  15552. args = cs.getRgb(args, 0);
  15553. fn = OPS.setFillRGBColor;
  15554. break;
  15555. case OPS.setStrokeColorN:
  15556. cs = stateManager.state.strokeColorSpace;
  15557. if (cs.name === 'Pattern') {
  15558. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15559. args, cs, patterns, resources, xref).then(function() {
  15560. next(resolve, reject);
  15561. }, reject);
  15562. }
  15563. args = cs.getRgb(args, 0);
  15564. fn = OPS.setStrokeRGBColor;
  15565. break;
  15566. case OPS.shadingFill:
  15567. var shadingRes = resources.get('Shading');
  15568. if (!shadingRes) {
  15569. error('No shading resource found');
  15570. }
  15571. var shading = shadingRes.get(args[0].name);
  15572. if (!shading) {
  15573. error('No shading object found');
  15574. }
  15575. var shadingFill = Pattern.parseShading(shading, null, xref,
  15576. resources);
  15577. var patternIR = shadingFill.getIR();
  15578. args = [patternIR];
  15579. fn = OPS.shadingFill;
  15580. break;
  15581. case OPS.setGState:
  15582. var dictName = args[0];
  15583. var extGState = resources.get('ExtGState');
  15584. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15585. break;
  15586. }
  15587. var gState = extGState.get(dictName.name);
  15588. return self.setGState(resources, gState, operatorList, xref,
  15589. stateManager).then(function() {
  15590. next(resolve, reject);
  15591. }, reject);
  15592. case OPS.moveTo:
  15593. case OPS.lineTo:
  15594. case OPS.curveTo:
  15595. case OPS.curveTo2:
  15596. case OPS.curveTo3:
  15597. case OPS.closePath:
  15598. self.buildPath(operatorList, fn, args);
  15599. continue;
  15600. case OPS.rectangle:
  15601. self.buildPath(operatorList, fn, args);
  15602. continue;
  15603. }
  15604. operatorList.addOp(fn, args);
  15605. }
  15606. if (stop) {
  15607. deferred.then(function () {
  15608. next(resolve, reject);
  15609. });
  15610. return;
  15611. }
  15612. // Some PDFs don't close all restores inside object/form.
  15613. // Closing those for them.
  15614. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15615. operatorList.addOp(OPS.restore, []);
  15616. }
  15617. resolve();
  15618. });
  15619. },
  15620. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15621. stateManager) {
  15622. stateManager = (stateManager || new StateManager(new TextState()));
  15623. var textContent = {
  15624. items: [],
  15625. styles: Object.create(null)
  15626. };
  15627. var bidiTexts = textContent.items;
  15628. var SPACE_FACTOR = 0.35;
  15629. var MULTI_SPACE_FACTOR = 1.5;
  15630. var self = this;
  15631. var xref = this.xref;
  15632. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15633. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15634. var xobjs = null;
  15635. var xobjsCache = {};
  15636. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15637. var textState;
  15638. function newTextChunk() {
  15639. var font = textState.font;
  15640. if (!(font.loadedName in textContent.styles)) {
  15641. textContent.styles[font.loadedName] = {
  15642. fontFamily: font.fallbackName,
  15643. ascent: font.ascent,
  15644. descent: font.descent,
  15645. vertical: font.vertical
  15646. };
  15647. }
  15648. return {
  15649. // |str| is initially an array which we push individual chars to, and
  15650. // then runBidi() overwrites it with the final string.
  15651. str: [],
  15652. dir: null,
  15653. width: 0,
  15654. height: 0,
  15655. transform: null,
  15656. fontName: font.loadedName
  15657. };
  15658. }
  15659. function runBidi(textChunk) {
  15660. var str = textChunk.str.join('');
  15661. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  15662. textChunk.str = bidiResult.str;
  15663. textChunk.dir = bidiResult.dir;
  15664. return textChunk;
  15665. }
  15666. function handleSetFont(fontName, fontRef) {
  15667. return self.loadFont(fontName, fontRef, xref, resources).
  15668. then(function (translated) {
  15669. textState.font = translated.font;
  15670. textState.fontMatrix = translated.font.fontMatrix ||
  15671. FONT_IDENTITY_MATRIX;
  15672. });
  15673. }
  15674. function buildTextGeometry(chars, textChunk) {
  15675. var font = textState.font;
  15676. textChunk = textChunk || newTextChunk();
  15677. if (!textChunk.transform) {
  15678. // 9.4.4 Text Space Details
  15679. var tsm = [textState.fontSize * textState.textHScale, 0,
  15680. 0, textState.fontSize,
  15681. 0, textState.textRise];
  15682. var trm = textChunk.transform = Util.transform(textState.ctm,
  15683. Util.transform(textState.textMatrix, tsm));
  15684. if (!font.vertical) {
  15685. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  15686. } else {
  15687. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  15688. }
  15689. }
  15690. var width = 0;
  15691. var height = 0;
  15692. var glyphs = font.charsToGlyphs(chars);
  15693. var defaultVMetrics = font.defaultVMetrics;
  15694. for (var i = 0; i < glyphs.length; i++) {
  15695. var glyph = glyphs[i];
  15696. if (!glyph) { // Previous glyph was a space.
  15697. width += textState.wordSpacing * textState.textHScale;
  15698. continue;
  15699. }
  15700. var vMetricX = null;
  15701. var vMetricY = null;
  15702. var glyphWidth = null;
  15703. if (font.vertical) {
  15704. if (glyph.vmetric) {
  15705. glyphWidth = glyph.vmetric[0];
  15706. vMetricX = glyph.vmetric[1];
  15707. vMetricY = glyph.vmetric[2];
  15708. } else {
  15709. glyphWidth = glyph.width;
  15710. vMetricX = glyph.width * 0.5;
  15711. vMetricY = defaultVMetrics[2];
  15712. }
  15713. } else {
  15714. glyphWidth = glyph.width;
  15715. }
  15716. var glyphUnicode = glyph.unicode;
  15717. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  15718. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  15719. }
  15720. glyphUnicode = reverseIfRtl(glyphUnicode);
  15721. // The following will calculate the x and y of the individual glyphs.
  15722. // if (font.vertical) {
  15723. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  15724. // textState.fontMatrix[0];
  15725. // tsm[5] -= vMetricY * textState.fontSize *
  15726. // textState.fontMatrix[0];
  15727. // }
  15728. // var trm = Util.transform(textState.textMatrix, tsm);
  15729. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  15730. // var x = pt[0];
  15731. // var y = pt[1];
  15732. var tx = 0;
  15733. var ty = 0;
  15734. if (!font.vertical) {
  15735. var w0 = glyphWidth * textState.fontMatrix[0];
  15736. tx = (w0 * textState.fontSize + textState.charSpacing) *
  15737. textState.textHScale;
  15738. width += tx;
  15739. } else {
  15740. var w1 = glyphWidth * textState.fontMatrix[0];
  15741. ty = w1 * textState.fontSize + textState.charSpacing;
  15742. height += ty;
  15743. }
  15744. textState.translateTextMatrix(tx, ty);
  15745. textChunk.str.push(glyphUnicode);
  15746. }
  15747. var a = textState.textLineMatrix[0];
  15748. var b = textState.textLineMatrix[1];
  15749. var scaleLineX = Math.sqrt(a * a + b * b);
  15750. a = textState.ctm[0];
  15751. b = textState.ctm[1];
  15752. var scaleCtmX = Math.sqrt(a * a + b * b);
  15753. if (!font.vertical) {
  15754. textChunk.width += width * scaleCtmX * scaleLineX;
  15755. } else {
  15756. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  15757. }
  15758. return textChunk;
  15759. }
  15760. var timeSlotManager = new TimeSlotManager();
  15761. return new Promise(function next(resolve, reject) {
  15762. timeSlotManager.reset();
  15763. var stop, operation = {}, args = [];
  15764. while (!(stop = timeSlotManager.check())) {
  15765. // The arguments parsed by read() are not used beyond this loop, so
  15766. // we can reuse the same array on every iteration, thus avoiding
  15767. // unnecessary allocations.
  15768. args.length = 0;
  15769. operation.args = args;
  15770. if (!(preprocessor.read(operation))) {
  15771. break;
  15772. }
  15773. textState = stateManager.state;
  15774. var fn = operation.fn;
  15775. args = operation.args;
  15776. switch (fn | 0) {
  15777. case OPS.setFont:
  15778. textState.fontSize = args[1];
  15779. return handleSetFont(args[0].name).then(function() {
  15780. next(resolve, reject);
  15781. }, reject);
  15782. case OPS.setTextRise:
  15783. textState.textRise = args[0];
  15784. break;
  15785. case OPS.setHScale:
  15786. textState.textHScale = args[0] / 100;
  15787. break;
  15788. case OPS.setLeading:
  15789. textState.leading = args[0];
  15790. break;
  15791. case OPS.moveText:
  15792. textState.translateTextLineMatrix(args[0], args[1]);
  15793. textState.textMatrix = textState.textLineMatrix.slice();
  15794. break;
  15795. case OPS.setLeadingMoveText:
  15796. textState.leading = -args[1];
  15797. textState.translateTextLineMatrix(args[0], args[1]);
  15798. textState.textMatrix = textState.textLineMatrix.slice();
  15799. break;
  15800. case OPS.nextLine:
  15801. textState.carriageReturn();
  15802. break;
  15803. case OPS.setTextMatrix:
  15804. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  15805. args[4], args[5]);
  15806. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  15807. args[4], args[5]);
  15808. break;
  15809. case OPS.setCharSpacing:
  15810. textState.charSpacing = args[0];
  15811. break;
  15812. case OPS.setWordSpacing:
  15813. textState.wordSpacing = args[0];
  15814. break;
  15815. case OPS.beginText:
  15816. textState.textMatrix = IDENTITY_MATRIX.slice();
  15817. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  15818. break;
  15819. case OPS.showSpacedText:
  15820. var items = args[0];
  15821. var textChunk = newTextChunk();
  15822. var offset;
  15823. for (var j = 0, jj = items.length; j < jj; j++) {
  15824. if (typeof items[j] === 'string') {
  15825. buildTextGeometry(items[j], textChunk);
  15826. } else {
  15827. var val = items[j] / 1000;
  15828. if (!textState.font.vertical) {
  15829. offset = -val * textState.fontSize * textState.textHScale *
  15830. textState.textMatrix[0];
  15831. textState.translateTextMatrix(offset, 0);
  15832. textChunk.width += offset;
  15833. } else {
  15834. offset = -val * textState.fontSize *
  15835. textState.textMatrix[3];
  15836. textState.translateTextMatrix(0, offset);
  15837. textChunk.height += offset;
  15838. }
  15839. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  15840. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  15841. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  15842. fakeSpaces = Math.round(fakeSpaces);
  15843. while (fakeSpaces--) {
  15844. textChunk.str.push(' ');
  15845. }
  15846. } else if (fakeSpaces > SPACE_FACTOR) {
  15847. textChunk.str.push(' ');
  15848. }
  15849. }
  15850. }
  15851. }
  15852. bidiTexts.push(runBidi(textChunk));
  15853. break;
  15854. case OPS.showText:
  15855. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  15856. break;
  15857. case OPS.nextLineShowText:
  15858. textState.carriageReturn();
  15859. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  15860. break;
  15861. case OPS.nextLineSetSpacingShowText:
  15862. textState.wordSpacing = args[0];
  15863. textState.charSpacing = args[1];
  15864. textState.carriageReturn();
  15865. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  15866. break;
  15867. case OPS.paintXObject:
  15868. if (args[0].code) {
  15869. break;
  15870. }
  15871. if (!xobjs) {
  15872. xobjs = (resources.get('XObject') || Dict.empty);
  15873. }
  15874. var name = args[0].name;
  15875. if (xobjsCache.key === name) {
  15876. if (xobjsCache.texts) {
  15877. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  15878. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  15879. }
  15880. break;
  15881. }
  15882. var xobj = xobjs.get(name);
  15883. if (!xobj) {
  15884. break;
  15885. }
  15886. assert(isStream(xobj), 'XObject should be a stream');
  15887. var type = xobj.dict.get('Subtype');
  15888. assert(isName(type),
  15889. 'XObject should have a Name subtype');
  15890. if ('Form' !== type.name) {
  15891. xobjsCache.key = name;
  15892. xobjsCache.texts = null;
  15893. break;
  15894. }
  15895. stateManager.save();
  15896. var matrix = xobj.dict.get('Matrix');
  15897. if (isArray(matrix) && matrix.length === 6) {
  15898. stateManager.transform(matrix);
  15899. }
  15900. return self.getTextContent(xobj,
  15901. xobj.dict.get('Resources') || resources, stateManager).
  15902. then(function (formTextContent) {
  15903. Util.appendToArray(bidiTexts, formTextContent.items);
  15904. Util.extendObj(textContent.styles, formTextContent.styles);
  15905. stateManager.restore();
  15906. xobjsCache.key = name;
  15907. xobjsCache.texts = formTextContent;
  15908. next(resolve, reject);
  15909. }, reject);
  15910. case OPS.setGState:
  15911. var dictName = args[0];
  15912. var extGState = resources.get('ExtGState');
  15913. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15914. break;
  15915. }
  15916. var gsStateMap = extGState.get(dictName.name);
  15917. var gsStateFont = null;
  15918. for (var key in gsStateMap) {
  15919. if (key === 'Font') {
  15920. assert(!gsStateFont);
  15921. gsStateFont = gsStateMap[key];
  15922. }
  15923. }
  15924. if (gsStateFont) {
  15925. textState.fontSize = gsStateFont[1];
  15926. return handleSetFont(gsStateFont[0]).then(function() {
  15927. next(resolve, reject);
  15928. }, reject);
  15929. }
  15930. break;
  15931. } // switch
  15932. } // while
  15933. if (stop) {
  15934. deferred.then(function () {
  15935. next(resolve, reject);
  15936. });
  15937. return;
  15938. }
  15939. resolve(textContent);
  15940. });
  15941. },
  15942. extractDataStructures: function
  15943. partialEvaluatorExtractDataStructures(dict, baseDict,
  15944. xref, properties) {
  15945. // 9.10.2
  15946. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  15947. if (toUnicode) {
  15948. properties.toUnicode = this.readToUnicode(toUnicode);
  15949. }
  15950. if (properties.composite) {
  15951. // CIDSystemInfo helps to match CID to glyphs
  15952. var cidSystemInfo = dict.get('CIDSystemInfo');
  15953. if (isDict(cidSystemInfo)) {
  15954. properties.cidSystemInfo = {
  15955. registry: cidSystemInfo.get('Registry'),
  15956. ordering: cidSystemInfo.get('Ordering'),
  15957. supplement: cidSystemInfo.get('Supplement')
  15958. };
  15959. }
  15960. var cidToGidMap = dict.get('CIDToGIDMap');
  15961. if (isStream(cidToGidMap)) {
  15962. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  15963. }
  15964. }
  15965. // Based on 9.6.6 of the spec the encoding can come from multiple places
  15966. // and depends on the font type. The base encoding and differences are
  15967. // read here, but the encoding that is actually used is chosen during
  15968. // glyph mapping in the font.
  15969. // TODO: Loading the built in encoding in the font would allow the
  15970. // differences to be merged in here not require us to hold on to it.
  15971. var differences = [];
  15972. var baseEncodingName = null;
  15973. var encoding;
  15974. if (dict.has('Encoding')) {
  15975. encoding = dict.get('Encoding');
  15976. if (isDict(encoding)) {
  15977. baseEncodingName = encoding.get('BaseEncoding');
  15978. baseEncodingName = (isName(baseEncodingName) ?
  15979. baseEncodingName.name : null);
  15980. // Load the differences between the base and original
  15981. if (encoding.has('Differences')) {
  15982. var diffEncoding = encoding.get('Differences');
  15983. var index = 0;
  15984. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  15985. var data = diffEncoding[j];
  15986. if (isNum(data)) {
  15987. index = data;
  15988. } else {
  15989. differences[index++] = data.name;
  15990. }
  15991. }
  15992. }
  15993. } else if (isName(encoding)) {
  15994. baseEncodingName = encoding.name;
  15995. } else {
  15996. error('Encoding is not a Name nor a Dict');
  15997. }
  15998. // According to table 114 if the encoding is a named encoding it must be
  15999. // one of these predefined encodings.
  16000. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16001. baseEncodingName !== 'MacExpertEncoding' &&
  16002. baseEncodingName !== 'WinAnsiEncoding')) {
  16003. baseEncodingName = null;
  16004. }
  16005. }
  16006. if (baseEncodingName) {
  16007. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16008. } else {
  16009. encoding = (properties.type === 'TrueType' ?
  16010. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16011. // The Symbolic attribute can be misused for regular fonts
  16012. // Heuristic: we have to check if the font is a standard one also
  16013. if (!!(properties.flags & FontFlags.Symbolic)) {
  16014. encoding = Encodings.MacRomanEncoding;
  16015. if (!properties.file) {
  16016. if (/Symbol/i.test(properties.name)) {
  16017. encoding = Encodings.SymbolSetEncoding;
  16018. } else if (/Dingbats/i.test(properties.name)) {
  16019. encoding = Encodings.ZapfDingbatsEncoding;
  16020. }
  16021. }
  16022. }
  16023. properties.defaultEncoding = encoding;
  16024. }
  16025. properties.differences = differences;
  16026. properties.baseEncodingName = baseEncodingName;
  16027. properties.dict = dict;
  16028. },
  16029. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16030. var cmap, cmapObj = toUnicode;
  16031. if (isName(cmapObj)) {
  16032. cmap = CMapFactory.create(cmapObj,
  16033. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16034. return new ToUnicodeMap(cmap);
  16035. } else if (isStream(cmapObj)) {
  16036. cmap = CMapFactory.create(cmapObj,
  16037. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16038. // Convert UTF-16BE
  16039. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16040. // to iterate over all keys.
  16041. cmap.forEach(function(token, i) {
  16042. var str = [];
  16043. for (var k = 0; k < token.length; k += 2) {
  16044. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16045. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16046. str.push(w1);
  16047. continue;
  16048. }
  16049. k += 2;
  16050. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16051. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16052. }
  16053. cmap[i] = String.fromCharCode.apply(String, str);
  16054. });
  16055. return new ToUnicodeMap(cmap);
  16056. }
  16057. return null;
  16058. },
  16059. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16060. // Extract the encoding from the CIDToGIDMap
  16061. var glyphsData = cidToGidStream.getBytes();
  16062. // Set encoding 0 to later verify the font has an encoding
  16063. var result = [];
  16064. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16065. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16066. if (glyphID === 0) {
  16067. continue;
  16068. }
  16069. var code = j >> 1;
  16070. result[code] = glyphID;
  16071. }
  16072. return result;
  16073. },
  16074. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16075. descriptor,
  16076. properties) {
  16077. var glyphsWidths = [];
  16078. var defaultWidth = 0;
  16079. var glyphsVMetrics = [];
  16080. var defaultVMetrics;
  16081. var i, ii, j, jj, start, code, widths;
  16082. if (properties.composite) {
  16083. defaultWidth = dict.get('DW') || 1000;
  16084. widths = dict.get('W');
  16085. if (widths) {
  16086. for (i = 0, ii = widths.length; i < ii; i++) {
  16087. start = widths[i++];
  16088. code = xref.fetchIfRef(widths[i]);
  16089. if (isArray(code)) {
  16090. for (j = 0, jj = code.length; j < jj; j++) {
  16091. glyphsWidths[start++] = code[j];
  16092. }
  16093. } else {
  16094. var width = widths[++i];
  16095. for (j = start; j <= code; j++) {
  16096. glyphsWidths[j] = width;
  16097. }
  16098. }
  16099. }
  16100. }
  16101. if (properties.vertical) {
  16102. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16103. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16104. vmetrics = dict.get('W2');
  16105. if (vmetrics) {
  16106. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16107. start = vmetrics[i++];
  16108. code = xref.fetchIfRef(vmetrics[i]);
  16109. if (isArray(code)) {
  16110. for (j = 0, jj = code.length; j < jj; j++) {
  16111. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16112. }
  16113. } else {
  16114. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16115. for (j = start; j <= code; j++) {
  16116. glyphsVMetrics[j] = vmetric;
  16117. }
  16118. }
  16119. }
  16120. }
  16121. }
  16122. } else {
  16123. var firstChar = properties.firstChar;
  16124. widths = dict.get('Widths');
  16125. if (widths) {
  16126. j = firstChar;
  16127. for (i = 0, ii = widths.length; i < ii; i++) {
  16128. glyphsWidths[j++] = widths[i];
  16129. }
  16130. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16131. } else {
  16132. // Trying get the BaseFont metrics (see comment above).
  16133. var baseFontName = dict.get('BaseFont');
  16134. if (isName(baseFontName)) {
  16135. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16136. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16137. properties);
  16138. defaultWidth = metrics.defaultWidth;
  16139. }
  16140. }
  16141. }
  16142. // Heuristic: detection of monospace font by checking all non-zero widths
  16143. var isMonospace = true;
  16144. var firstWidth = defaultWidth;
  16145. for (var glyph in glyphsWidths) {
  16146. var glyphWidth = glyphsWidths[glyph];
  16147. if (!glyphWidth) {
  16148. continue;
  16149. }
  16150. if (!firstWidth) {
  16151. firstWidth = glyphWidth;
  16152. continue;
  16153. }
  16154. if (firstWidth !== glyphWidth) {
  16155. isMonospace = false;
  16156. break;
  16157. }
  16158. }
  16159. if (isMonospace) {
  16160. properties.flags |= FontFlags.FixedPitch;
  16161. }
  16162. properties.defaultWidth = defaultWidth;
  16163. properties.widths = glyphsWidths;
  16164. properties.defaultVMetrics = defaultVMetrics;
  16165. properties.vmetrics = glyphsVMetrics;
  16166. },
  16167. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16168. // Simulating descriptor flags attribute
  16169. var fontNameWoStyle = baseFontName.split('-')[0];
  16170. return (fontNameWoStyle in serifFonts) ||
  16171. (fontNameWoStyle.search(/serif/gi) !== -1);
  16172. },
  16173. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16174. var defaultWidth = 0;
  16175. var widths = [];
  16176. var monospace = false;
  16177. var lookupName = (stdFontMap[name] || name);
  16178. if (!(lookupName in Metrics)) {
  16179. // Use default fonts for looking up font metrics if the passed
  16180. // font is not a base font
  16181. if (this.isSerifFont(name)) {
  16182. lookupName = 'Times-Roman';
  16183. } else {
  16184. lookupName = 'Helvetica';
  16185. }
  16186. }
  16187. var glyphWidths = Metrics[lookupName];
  16188. if (isNum(glyphWidths)) {
  16189. defaultWidth = glyphWidths;
  16190. monospace = true;
  16191. } else {
  16192. widths = glyphWidths;
  16193. }
  16194. return {
  16195. defaultWidth: defaultWidth,
  16196. monospace: monospace,
  16197. widths: widths
  16198. };
  16199. },
  16200. buildCharCodeToWidth:
  16201. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16202. properties) {
  16203. var widths = Object.create(null);
  16204. var differences = properties.differences;
  16205. var encoding = properties.defaultEncoding;
  16206. for (var charCode = 0; charCode < 256; charCode++) {
  16207. if (charCode in differences &&
  16208. widthsByGlyphName[differences[charCode]]) {
  16209. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16210. continue;
  16211. }
  16212. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16213. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16214. continue;
  16215. }
  16216. }
  16217. return widths;
  16218. },
  16219. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16220. var baseDict = dict;
  16221. var type = dict.get('Subtype');
  16222. assert(isName(type), 'invalid font Subtype');
  16223. var composite = false;
  16224. var uint8array;
  16225. if (type.name === 'Type0') {
  16226. // If font is a composite
  16227. // - get the descendant font
  16228. // - set the type according to the descendant font
  16229. // - get the FontDescriptor from the descendant font
  16230. var df = dict.get('DescendantFonts');
  16231. if (!df) {
  16232. error('Descendant fonts are not specified');
  16233. }
  16234. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16235. type = dict.get('Subtype');
  16236. assert(isName(type), 'invalid font Subtype');
  16237. composite = true;
  16238. }
  16239. var descriptor = dict.get('FontDescriptor');
  16240. if (descriptor) {
  16241. var hash = new MurmurHash3_64();
  16242. var encoding = baseDict.getRaw('Encoding');
  16243. if (isName(encoding)) {
  16244. hash.update(encoding.name);
  16245. } else if (isRef(encoding)) {
  16246. hash.update(encoding.num + '_' + encoding.gen);
  16247. }
  16248. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16249. if (isStream(toUnicode)) {
  16250. var stream = toUnicode.str || toUnicode;
  16251. uint8array = stream.buffer ?
  16252. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16253. new Uint8Array(stream.bytes.buffer,
  16254. stream.start, stream.end - stream.start);
  16255. hash.update(uint8array);
  16256. } else if (isName(toUnicode)) {
  16257. hash.update(toUnicode.name);
  16258. }
  16259. var widths = dict.get('Widths') || baseDict.get('Widths');
  16260. if (widths) {
  16261. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16262. hash.update(uint8array);
  16263. }
  16264. }
  16265. return {
  16266. descriptor: descriptor,
  16267. dict: dict,
  16268. baseDict: baseDict,
  16269. composite: composite,
  16270. type: type.name,
  16271. hash: hash ? hash.hexdigest() : ''
  16272. };
  16273. },
  16274. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16275. xref) {
  16276. var baseDict = preEvaluatedFont.baseDict;
  16277. var dict = preEvaluatedFont.dict;
  16278. var composite = preEvaluatedFont.composite;
  16279. var descriptor = preEvaluatedFont.descriptor;
  16280. var type = preEvaluatedFont.type;
  16281. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16282. var properties;
  16283. if (!descriptor) {
  16284. if (type === 'Type3') {
  16285. // FontDescriptor is only required for Type3 fonts when the document
  16286. // is a tagged pdf. Create a barbebones one to get by.
  16287. descriptor = new Dict(null);
  16288. descriptor.set('FontName', Name.get(type));
  16289. } else {
  16290. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16291. // FontDescriptor was not required.
  16292. // This case is here for compatibility.
  16293. var baseFontName = dict.get('BaseFont');
  16294. if (!isName(baseFontName)) {
  16295. error('Base font is not specified');
  16296. }
  16297. // Using base font name as a font name.
  16298. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16299. var metrics = this.getBaseFontMetrics(baseFontName);
  16300. // Simulating descriptor flags attribute
  16301. var fontNameWoStyle = baseFontName.split('-')[0];
  16302. var flags =
  16303. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16304. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16305. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16306. FontFlags.Nonsymbolic);
  16307. properties = {
  16308. type: type,
  16309. name: baseFontName,
  16310. widths: metrics.widths,
  16311. defaultWidth: metrics.defaultWidth,
  16312. flags: flags,
  16313. firstChar: 0,
  16314. lastChar: maxCharIndex
  16315. };
  16316. this.extractDataStructures(dict, dict, xref, properties);
  16317. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16318. properties);
  16319. return new Font(baseFontName, null, properties);
  16320. }
  16321. }
  16322. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16323. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16324. // to ignore this rule when a variant of a standart font is used.
  16325. // TODO Fill the width array depending on which of the base font this is
  16326. // a variant.
  16327. var firstChar = (dict.get('FirstChar') || 0);
  16328. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16329. var fontName = descriptor.get('FontName');
  16330. var baseFont = dict.get('BaseFont');
  16331. // Some bad PDFs have a string as the font name.
  16332. if (isString(fontName)) {
  16333. fontName = Name.get(fontName);
  16334. }
  16335. if (isString(baseFont)) {
  16336. baseFont = Name.get(baseFont);
  16337. }
  16338. if (type !== 'Type3') {
  16339. var fontNameStr = fontName && fontName.name;
  16340. var baseFontStr = baseFont && baseFont.name;
  16341. if (fontNameStr !== baseFontStr) {
  16342. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16343. '" but should be the same as the Font\'s BaseFont "' +
  16344. baseFontStr + '"');
  16345. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16346. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16347. if (fontNameStr && baseFontStr &&
  16348. baseFontStr.indexOf(fontNameStr) === 0) {
  16349. fontName = baseFont;
  16350. }
  16351. }
  16352. }
  16353. fontName = (fontName || baseFont);
  16354. assert(isName(fontName), 'invalid font name');
  16355. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16356. if (fontFile) {
  16357. if (fontFile.dict) {
  16358. var subtype = fontFile.dict.get('Subtype');
  16359. if (subtype) {
  16360. subtype = subtype.name;
  16361. }
  16362. var length1 = fontFile.dict.get('Length1');
  16363. var length2 = fontFile.dict.get('Length2');
  16364. }
  16365. }
  16366. properties = {
  16367. type: type,
  16368. name: fontName.name,
  16369. subtype: subtype,
  16370. file: fontFile,
  16371. length1: length1,
  16372. length2: length2,
  16373. loadedName: baseDict.loadedName,
  16374. composite: composite,
  16375. wideChars: composite,
  16376. fixedPitch: false,
  16377. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16378. firstChar: firstChar || 0,
  16379. lastChar: (lastChar || maxCharIndex),
  16380. bbox: descriptor.get('FontBBox'),
  16381. ascent: descriptor.get('Ascent'),
  16382. descent: descriptor.get('Descent'),
  16383. xHeight: descriptor.get('XHeight'),
  16384. capHeight: descriptor.get('CapHeight'),
  16385. flags: descriptor.get('Flags'),
  16386. italicAngle: descriptor.get('ItalicAngle'),
  16387. coded: false
  16388. };
  16389. if (composite) {
  16390. var cidEncoding = baseDict.get('Encoding');
  16391. if (isName(cidEncoding)) {
  16392. properties.cidEncoding = cidEncoding.name;
  16393. }
  16394. properties.cMap = CMapFactory.create(cidEncoding,
  16395. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16396. properties.vertical = properties.cMap.vertical;
  16397. }
  16398. this.extractDataStructures(dict, baseDict, xref, properties);
  16399. this.extractWidths(dict, xref, descriptor, properties);
  16400. if (type === 'Type3') {
  16401. properties.isType3Font = true;
  16402. }
  16403. return new Font(fontName.name, fontFile, properties);
  16404. }
  16405. };
  16406. return PartialEvaluator;
  16407. })();
  16408. var TranslatedFont = (function TranslatedFontClosure() {
  16409. function TranslatedFont(loadedName, font, dict) {
  16410. this.loadedName = loadedName;
  16411. this.font = font;
  16412. this.dict = dict;
  16413. this.type3Loaded = null;
  16414. this.sent = false;
  16415. }
  16416. TranslatedFont.prototype = {
  16417. send: function (handler) {
  16418. if (this.sent) {
  16419. return;
  16420. }
  16421. var fontData = this.font.exportData();
  16422. handler.send('commonobj', [
  16423. this.loadedName,
  16424. 'Font',
  16425. fontData
  16426. ]);
  16427. this.sent = true;
  16428. },
  16429. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16430. assert(this.font.isType3Font);
  16431. if (this.type3Loaded) {
  16432. return this.type3Loaded;
  16433. }
  16434. var translatedFont = this.font;
  16435. var loadCharProcsPromise = Promise.resolve();
  16436. var charProcs = this.dict.get('CharProcs').getAll();
  16437. var fontResources = this.dict.get('Resources') || resources;
  16438. var charProcKeys = Object.keys(charProcs);
  16439. var charProcOperatorList = {};
  16440. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16441. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16442. var glyphStream = charProcs[key];
  16443. var operatorList = new OperatorList();
  16444. return evaluator.getOperatorList(glyphStream, fontResources,
  16445. operatorList).then(function () {
  16446. charProcOperatorList[key] = operatorList.getIR();
  16447. // Add the dependencies to the parent operator list so they are
  16448. // resolved before sub operator list is executed synchronously.
  16449. parentOperatorList.addDependencies(operatorList.dependencies);
  16450. }, function (reason) {
  16451. warn('Type3 font resource \"' + key + '\" is not available');
  16452. var operatorList = new OperatorList();
  16453. charProcOperatorList[key] = operatorList.getIR();
  16454. });
  16455. }.bind(this, charProcKeys[i]));
  16456. }
  16457. this.type3Loaded = loadCharProcsPromise.then(function () {
  16458. translatedFont.charProcOperatorList = charProcOperatorList;
  16459. });
  16460. return this.type3Loaded;
  16461. }
  16462. };
  16463. return TranslatedFont;
  16464. })();
  16465. var OperatorList = (function OperatorListClosure() {
  16466. var CHUNK_SIZE = 1000;
  16467. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16468. function getTransfers(queue) {
  16469. var transfers = [];
  16470. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16471. for (var i = 0, ii = queue.length; i < ii; i++) {
  16472. switch (fnArray[i]) {
  16473. case OPS.paintInlineImageXObject:
  16474. case OPS.paintInlineImageXObjectGroup:
  16475. case OPS.paintImageMaskXObject:
  16476. var arg = argsArray[i][0]; // first param in imgData
  16477. if (!arg.cached) {
  16478. transfers.push(arg.data.buffer);
  16479. }
  16480. break;
  16481. }
  16482. }
  16483. return transfers;
  16484. }
  16485. function OperatorList(intent, messageHandler, pageIndex) {
  16486. this.messageHandler = messageHandler;
  16487. this.fnArray = [];
  16488. this.argsArray = [];
  16489. this.dependencies = {};
  16490. this.pageIndex = pageIndex;
  16491. this.intent = intent;
  16492. }
  16493. OperatorList.prototype = {
  16494. get length() {
  16495. return this.argsArray.length;
  16496. },
  16497. addOp: function(fn, args) {
  16498. this.fnArray.push(fn);
  16499. this.argsArray.push(args);
  16500. if (this.messageHandler) {
  16501. if (this.fnArray.length >= CHUNK_SIZE) {
  16502. this.flush();
  16503. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16504. (fn === OPS.restore || fn === OPS.endText)) {
  16505. // heuristic to flush on boundary of restore or endText
  16506. this.flush();
  16507. }
  16508. }
  16509. },
  16510. addDependency: function(dependency) {
  16511. if (dependency in this.dependencies) {
  16512. return;
  16513. }
  16514. this.dependencies[dependency] = true;
  16515. this.addOp(OPS.dependency, [dependency]);
  16516. },
  16517. addDependencies: function(dependencies) {
  16518. for (var key in dependencies) {
  16519. this.addDependency(key);
  16520. }
  16521. },
  16522. addOpList: function(opList) {
  16523. Util.extendObj(this.dependencies, opList.dependencies);
  16524. for (var i = 0, ii = opList.length; i < ii; i++) {
  16525. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16526. }
  16527. },
  16528. getIR: function() {
  16529. return {
  16530. fnArray: this.fnArray,
  16531. argsArray: this.argsArray,
  16532. length: this.length
  16533. };
  16534. },
  16535. flush: function(lastChunk) {
  16536. if (this.intent !== 'oplist') {
  16537. new QueueOptimizer().optimize(this);
  16538. }
  16539. var transfers = getTransfers(this);
  16540. this.messageHandler.send('RenderPageChunk', {
  16541. operatorList: {
  16542. fnArray: this.fnArray,
  16543. argsArray: this.argsArray,
  16544. lastChunk: lastChunk,
  16545. length: this.length
  16546. },
  16547. pageIndex: this.pageIndex,
  16548. intent: this.intent
  16549. }, transfers);
  16550. this.dependencies = {};
  16551. this.fnArray.length = 0;
  16552. this.argsArray.length = 0;
  16553. }
  16554. };
  16555. return OperatorList;
  16556. })();
  16557. var StateManager = (function StateManagerClosure() {
  16558. function StateManager(initialState) {
  16559. this.state = initialState;
  16560. this.stateStack = [];
  16561. }
  16562. StateManager.prototype = {
  16563. save: function () {
  16564. var old = this.state;
  16565. this.stateStack.push(this.state);
  16566. this.state = old.clone();
  16567. },
  16568. restore: function () {
  16569. var prev = this.stateStack.pop();
  16570. if (prev) {
  16571. this.state = prev;
  16572. }
  16573. },
  16574. transform: function (args) {
  16575. this.state.ctm = Util.transform(this.state.ctm, args);
  16576. }
  16577. };
  16578. return StateManager;
  16579. })();
  16580. var TextState = (function TextStateClosure() {
  16581. function TextState() {
  16582. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16583. this.fontSize = 0;
  16584. this.font = null;
  16585. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16586. this.textMatrix = IDENTITY_MATRIX.slice();
  16587. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16588. this.charSpacing = 0;
  16589. this.wordSpacing = 0;
  16590. this.leading = 0;
  16591. this.textHScale = 1;
  16592. this.textRise = 0;
  16593. }
  16594. TextState.prototype = {
  16595. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16596. var m = this.textMatrix;
  16597. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16598. },
  16599. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16600. var m = this.textLineMatrix;
  16601. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16602. },
  16603. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16604. var m = this.textMatrix;
  16605. m[4] = m[0] * x + m[2] * y + m[4];
  16606. m[5] = m[1] * x + m[3] * y + m[5];
  16607. },
  16608. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16609. var m = this.textLineMatrix;
  16610. m[4] = m[0] * x + m[2] * y + m[4];
  16611. m[5] = m[1] * x + m[3] * y + m[5];
  16612. },
  16613. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16614. // 9.4.4 Text Space Details
  16615. var tsm = [this.fontSize * this.textHScale, 0,
  16616. 0, this.fontSize,
  16617. 0, this.textRise];
  16618. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16619. },
  16620. carriageReturn: function TextState_carriageReturn() {
  16621. this.translateTextLineMatrix(0, -this.leading);
  16622. this.textMatrix = this.textLineMatrix.slice();
  16623. },
  16624. clone: function TextState_clone() {
  16625. var clone = Object.create(this);
  16626. clone.textMatrix = this.textMatrix.slice();
  16627. clone.textLineMatrix = this.textLineMatrix.slice();
  16628. clone.fontMatrix = this.fontMatrix.slice();
  16629. return clone;
  16630. }
  16631. };
  16632. return TextState;
  16633. })();
  16634. var EvalState = (function EvalStateClosure() {
  16635. function EvalState() {
  16636. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16637. this.font = null;
  16638. this.textRenderingMode = TextRenderingMode.FILL;
  16639. this.fillColorSpace = ColorSpace.singletons.gray;
  16640. this.strokeColorSpace = ColorSpace.singletons.gray;
  16641. }
  16642. EvalState.prototype = {
  16643. clone: function CanvasExtraState_clone() {
  16644. return Object.create(this);
  16645. },
  16646. };
  16647. return EvalState;
  16648. })();
  16649. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  16650. // Specifies properties for each command
  16651. //
  16652. // If variableArgs === true: [0, `numArgs`] expected
  16653. // If variableArgs === false: exactly `numArgs` expected
  16654. var OP_MAP = {
  16655. // Graphic state
  16656. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  16657. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  16658. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  16659. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  16660. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  16661. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  16662. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  16663. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  16664. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  16665. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  16666. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  16667. // Path
  16668. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  16669. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  16670. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  16671. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  16672. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  16673. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  16674. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  16675. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  16676. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  16677. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  16678. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  16679. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  16680. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  16681. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  16682. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  16683. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  16684. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  16685. // Clipping
  16686. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  16687. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  16688. // Text
  16689. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  16690. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  16691. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  16692. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  16693. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  16694. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  16695. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  16696. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  16697. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  16698. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  16699. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  16700. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  16701. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  16702. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  16703. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  16704. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  16705. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  16706. variableArgs: false },
  16707. // Type3 fonts
  16708. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  16709. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  16710. // Color
  16711. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  16712. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  16713. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  16714. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  16715. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  16716. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  16717. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  16718. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  16719. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  16720. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  16721. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  16722. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  16723. // Shading
  16724. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  16725. // Images
  16726. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  16727. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  16728. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  16729. // XObjects
  16730. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  16731. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  16732. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  16733. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  16734. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  16735. variableArgs: false },
  16736. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  16737. // Compatibility
  16738. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  16739. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  16740. // (reserved partial commands for the lexer)
  16741. BM: null,
  16742. BD: null,
  16743. 'true': null,
  16744. fa: null,
  16745. fal: null,
  16746. fals: null,
  16747. 'false': null,
  16748. nu: null,
  16749. nul: null,
  16750. 'null': null
  16751. };
  16752. function EvaluatorPreprocessor(stream, xref, stateManager) {
  16753. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  16754. // dictionary
  16755. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  16756. this.stateManager = stateManager;
  16757. this.nonProcessedArgs = [];
  16758. }
  16759. EvaluatorPreprocessor.prototype = {
  16760. get savedStatesDepth() {
  16761. return this.stateManager.stateStack.length;
  16762. },
  16763. // |operation| is an object with two fields:
  16764. //
  16765. // - |fn| is an out param.
  16766. //
  16767. // - |args| is an inout param. On entry, it should have one of two values.
  16768. //
  16769. // - An empty array. This indicates that the caller is providing the
  16770. // array in which the args will be stored in. The caller should use
  16771. // this value if it can reuse a single array for each call to read().
  16772. //
  16773. // - |null|. This indicates that the caller needs this function to create
  16774. // the array in which any args are stored in. If there are zero args,
  16775. // this function will leave |operation.args| as |null| (thus avoiding
  16776. // allocations that would occur if we used an empty array to represent
  16777. // zero arguments). Otherwise, it will replace |null| with a new array
  16778. // containing the arguments. The caller should use this value if it
  16779. // cannot reuse an array for each call to read().
  16780. //
  16781. // These two modes are present because this function is very hot and so
  16782. // avoiding allocations where possible is worthwhile.
  16783. //
  16784. read: function EvaluatorPreprocessor_read(operation) {
  16785. var args = operation.args;
  16786. while (true) {
  16787. var obj = this.parser.getObj();
  16788. if (isCmd(obj)) {
  16789. var cmd = obj.cmd;
  16790. // Check that the command is valid
  16791. var opSpec = OP_MAP[cmd];
  16792. if (!opSpec) {
  16793. warn('Unknown command "' + cmd + '"');
  16794. continue;
  16795. }
  16796. var fn = opSpec.id;
  16797. var numArgs = opSpec.numArgs;
  16798. var argsLength = args !== null ? args.length : 0;
  16799. if (!opSpec.variableArgs) {
  16800. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  16801. if (argsLength !== numArgs) {
  16802. var nonProcessedArgs = this.nonProcessedArgs;
  16803. while (argsLength > numArgs) {
  16804. nonProcessedArgs.push(args.shift());
  16805. argsLength--;
  16806. }
  16807. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  16808. if (!args) {
  16809. args = [];
  16810. }
  16811. args.unshift(nonProcessedArgs.pop());
  16812. argsLength++;
  16813. }
  16814. }
  16815. if (argsLength < numArgs) {
  16816. // If we receive too few args, it's not possible to possible
  16817. // to execute the command, so skip the command
  16818. info('Command ' + fn + ': because expected ' +
  16819. numArgs + ' args, but received ' + argsLength +
  16820. ' args; skipping');
  16821. args = null;
  16822. continue;
  16823. }
  16824. } else if (argsLength > numArgs) {
  16825. info('Command ' + fn + ': expected [0,' + numArgs +
  16826. '] args, but received ' + argsLength + ' args');
  16827. }
  16828. // TODO figure out how to type-check vararg functions
  16829. this.preprocessCommand(fn, args);
  16830. operation.fn = fn;
  16831. operation.args = args;
  16832. return true;
  16833. } else {
  16834. if (isEOF(obj)) {
  16835. return false; // no more commands
  16836. }
  16837. // argument
  16838. if (obj !== null) {
  16839. if (!args) {
  16840. args = [];
  16841. }
  16842. args.push((obj instanceof Dict ? obj.getAll() : obj));
  16843. assert(args.length <= 33, 'Too many arguments');
  16844. }
  16845. }
  16846. }
  16847. },
  16848. preprocessCommand:
  16849. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  16850. switch (fn | 0) {
  16851. case OPS.save:
  16852. this.stateManager.save();
  16853. break;
  16854. case OPS.restore:
  16855. this.stateManager.restore();
  16856. break;
  16857. case OPS.transform:
  16858. this.stateManager.transform(args);
  16859. break;
  16860. }
  16861. }
  16862. };
  16863. return EvaluatorPreprocessor;
  16864. })();
  16865. var QueueOptimizer = (function QueueOptimizerClosure() {
  16866. function addState(parentState, pattern, fn) {
  16867. var state = parentState;
  16868. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  16869. var item = pattern[i];
  16870. state = (state[item] || (state[item] = []));
  16871. }
  16872. state[pattern[pattern.length - 1]] = fn;
  16873. }
  16874. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  16875. argsArray) {
  16876. // Handles special case of mainly LaTeX documents which use image masks to
  16877. // draw lines with the current fill style.
  16878. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  16879. // have been found at iFirstSave.
  16880. var iFirstPIMXO = iFirstSave + 2;
  16881. for (var i = 0; i < count; i++) {
  16882. var arg = argsArray[iFirstPIMXO + 4 * i];
  16883. var imageMask = arg.length === 1 && arg[0];
  16884. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  16885. (!imageMask.data.length ||
  16886. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  16887. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  16888. continue;
  16889. }
  16890. break;
  16891. }
  16892. return count - i;
  16893. }
  16894. var InitialState = [];
  16895. // This replaces (save, transform, paintInlineImageXObject, restore)+
  16896. // sequences with one |paintInlineImageXObjectGroup| operation.
  16897. addState(InitialState,
  16898. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  16899. function foundInlineImageGroup(context) {
  16900. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  16901. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  16902. var MAX_WIDTH = 1000;
  16903. var IMAGE_PADDING = 1;
  16904. var fnArray = context.fnArray, argsArray = context.argsArray;
  16905. var curr = context.iCurr;
  16906. var iFirstSave = curr - 3;
  16907. var iFirstTransform = curr - 2;
  16908. var iFirstPIIXO = curr - 1;
  16909. // Look for the quartets.
  16910. var i = iFirstSave + 4;
  16911. var ii = fnArray.length;
  16912. while (i + 3 < ii) {
  16913. if (fnArray[i] !== OPS.save ||
  16914. fnArray[i + 1] !== OPS.transform ||
  16915. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  16916. fnArray[i + 3] !== OPS.restore) {
  16917. break; // ops don't match
  16918. }
  16919. i += 4;
  16920. }
  16921. // At this point, i is the index of the first op past the last valid
  16922. // quartet.
  16923. var count = Math.min((i - iFirstSave) / 4,
  16924. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  16925. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  16926. return i;
  16927. }
  16928. // assuming that heights of those image is too small (~1 pixel)
  16929. // packing as much as possible by lines
  16930. var maxX = 0;
  16931. var map = [], maxLineHeight = 0;
  16932. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  16933. var q;
  16934. for (q = 0; q < count; q++) {
  16935. var transform = argsArray[iFirstTransform + (q << 2)];
  16936. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  16937. if (currentX + img.width > MAX_WIDTH) {
  16938. // starting new line
  16939. maxX = Math.max(maxX, currentX);
  16940. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  16941. currentX = 0;
  16942. maxLineHeight = 0;
  16943. }
  16944. map.push({
  16945. transform: transform,
  16946. x: currentX, y: currentY,
  16947. w: img.width, h: img.height
  16948. });
  16949. currentX += img.width + 2 * IMAGE_PADDING;
  16950. maxLineHeight = Math.max(maxLineHeight, img.height);
  16951. }
  16952. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  16953. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  16954. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  16955. var imgRowSize = imgWidth << 2;
  16956. for (q = 0; q < count; q++) {
  16957. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  16958. // Copy image by lines and extends pixels into padding.
  16959. var rowSize = map[q].w << 2;
  16960. var dataOffset = 0;
  16961. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  16962. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  16963. for (var k = 0, kk = map[q].h; k < kk; k++) {
  16964. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  16965. dataOffset += rowSize;
  16966. offset += imgRowSize;
  16967. }
  16968. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  16969. while (offset >= 0) {
  16970. data[offset - 4] = data[offset];
  16971. data[offset - 3] = data[offset + 1];
  16972. data[offset - 2] = data[offset + 2];
  16973. data[offset - 1] = data[offset + 3];
  16974. data[offset + rowSize] = data[offset + rowSize - 4];
  16975. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  16976. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  16977. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  16978. offset -= imgRowSize;
  16979. }
  16980. }
  16981. // Replace queue items.
  16982. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  16983. argsArray.splice(iFirstSave, count * 4,
  16984. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  16985. data: imgData }, map]);
  16986. return iFirstSave + 1;
  16987. });
  16988. // This replaces (save, transform, paintImageMaskXObject, restore)+
  16989. // sequences with one |paintImageMaskXObjectGroup| or one
  16990. // |paintImageMaskXObjectRepeat| operation.
  16991. addState(InitialState,
  16992. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  16993. function foundImageMaskGroup(context) {
  16994. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  16995. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  16996. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  16997. var fnArray = context.fnArray, argsArray = context.argsArray;
  16998. var curr = context.iCurr;
  16999. var iFirstSave = curr - 3;
  17000. var iFirstTransform = curr - 2;
  17001. var iFirstPIMXO = curr - 1;
  17002. // Look for the quartets.
  17003. var i = iFirstSave + 4;
  17004. var ii = fnArray.length;
  17005. while (i + 3 < ii) {
  17006. if (fnArray[i] !== OPS.save ||
  17007. fnArray[i + 1] !== OPS.transform ||
  17008. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17009. fnArray[i + 3] !== OPS.restore) {
  17010. break; // ops don't match
  17011. }
  17012. i += 4;
  17013. }
  17014. // At this point, i is the index of the first op past the last valid
  17015. // quartet.
  17016. var count = (i - iFirstSave) / 4;
  17017. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17018. argsArray);
  17019. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17020. return i;
  17021. }
  17022. var q;
  17023. var isSameImage = false;
  17024. var iTransform, transformArgs;
  17025. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17026. if (argsArray[iFirstTransform][1] === 0 &&
  17027. argsArray[iFirstTransform][2] === 0) {
  17028. isSameImage = true;
  17029. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17030. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17031. iTransform = iFirstTransform + 4;
  17032. var iPIMXO = iFirstPIMXO + 4;
  17033. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17034. transformArgs = argsArray[iTransform];
  17035. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17036. transformArgs[0] !== firstTransformArg0 ||
  17037. transformArgs[1] !== 0 ||
  17038. transformArgs[2] !== 0 ||
  17039. transformArgs[3] !== firstTransformArg3) {
  17040. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17041. isSameImage = false;
  17042. } else {
  17043. count = q;
  17044. }
  17045. break; // different image or transform
  17046. }
  17047. }
  17048. }
  17049. if (isSameImage) {
  17050. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17051. var positions = new Float32Array(count * 2);
  17052. iTransform = iFirstTransform;
  17053. for (q = 0; q < count; q++, iTransform += 4) {
  17054. transformArgs = argsArray[iTransform];
  17055. positions[(q << 1)] = transformArgs[4];
  17056. positions[(q << 1) + 1] = transformArgs[5];
  17057. }
  17058. // Replace queue items.
  17059. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17060. argsArray.splice(iFirstSave, count * 4,
  17061. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17062. } else {
  17063. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17064. var images = [];
  17065. for (q = 0; q < count; q++) {
  17066. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17067. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17068. images.push({ data: maskParams.data, width: maskParams.width,
  17069. height: maskParams.height,
  17070. transform: transformArgs });
  17071. }
  17072. // Replace queue items.
  17073. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17074. argsArray.splice(iFirstSave, count * 4, [images]);
  17075. }
  17076. return iFirstSave + 1;
  17077. });
  17078. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17079. // with one paintImageXObjectRepeat operation, if the |transform| and
  17080. // |paintImageXObjectRepeat| ops are appropriate.
  17081. addState(InitialState,
  17082. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17083. function (context) {
  17084. var MIN_IMAGES_IN_BLOCK = 3;
  17085. var MAX_IMAGES_IN_BLOCK = 1000;
  17086. var fnArray = context.fnArray, argsArray = context.argsArray;
  17087. var curr = context.iCurr;
  17088. var iFirstSave = curr - 3;
  17089. var iFirstTransform = curr - 2;
  17090. var iFirstPIXO = curr - 1;
  17091. var iFirstRestore = curr;
  17092. if (argsArray[iFirstTransform][1] !== 0 ||
  17093. argsArray[iFirstTransform][2] !== 0) {
  17094. return iFirstRestore + 1; // transform has the wrong form
  17095. }
  17096. // Look for the quartets.
  17097. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17098. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17099. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17100. var i = iFirstSave + 4;
  17101. var ii = fnArray.length;
  17102. while (i + 3 < ii) {
  17103. if (fnArray[i] !== OPS.save ||
  17104. fnArray[i + 1] !== OPS.transform ||
  17105. fnArray[i + 2] !== OPS.paintImageXObject ||
  17106. fnArray[i + 3] !== OPS.restore) {
  17107. break; // ops don't match
  17108. }
  17109. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17110. argsArray[i + 1][1] !== 0 ||
  17111. argsArray[i + 1][2] !== 0 ||
  17112. argsArray[i + 1][3] !== firstTransformArg3) {
  17113. break; // transforms don't match
  17114. }
  17115. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17116. break; // images don't match
  17117. }
  17118. i += 4;
  17119. }
  17120. // At this point, i is the index of the first op past the last valid
  17121. // quartet.
  17122. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17123. if (count < MIN_IMAGES_IN_BLOCK) {
  17124. return i;
  17125. }
  17126. // Extract the (x,y) positions from all of the matching transforms.
  17127. var positions = new Float32Array(count * 2);
  17128. var iTransform = iFirstTransform;
  17129. for (var q = 0; q < count; q++, iTransform += 4) {
  17130. var transformArgs = argsArray[iTransform];
  17131. positions[(q << 1)] = transformArgs[4];
  17132. positions[(q << 1) + 1] = transformArgs[5];
  17133. }
  17134. // Replace queue items.
  17135. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17136. positions];
  17137. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17138. argsArray.splice(iFirstSave, count * 4, args);
  17139. return iFirstSave + 1;
  17140. });
  17141. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17142. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17143. // sequences, if the font for each one is the same.
  17144. addState(InitialState,
  17145. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17146. function (context) {
  17147. var MIN_CHARS_IN_BLOCK = 3;
  17148. var MAX_CHARS_IN_BLOCK = 1000;
  17149. var fnArray = context.fnArray, argsArray = context.argsArray;
  17150. var curr = context.iCurr;
  17151. var iFirstBeginText = curr - 4;
  17152. var iFirstSetFont = curr - 3;
  17153. var iFirstSetTextMatrix = curr - 2;
  17154. var iFirstShowText = curr - 1;
  17155. var iFirstEndText = curr;
  17156. // Look for the quintets.
  17157. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17158. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17159. var i = iFirstBeginText + 5;
  17160. var ii = fnArray.length;
  17161. while (i + 4 < ii) {
  17162. if (fnArray[i] !== OPS.beginText ||
  17163. fnArray[i + 1] !== OPS.setFont ||
  17164. fnArray[i + 2] !== OPS.setTextMatrix ||
  17165. fnArray[i + 3] !== OPS.showText ||
  17166. fnArray[i + 4] !== OPS.endText) {
  17167. break; // ops don't match
  17168. }
  17169. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17170. argsArray[i + 1][1] !== firstSetFontArg1) {
  17171. break; // fonts don't match
  17172. }
  17173. i += 5;
  17174. }
  17175. // At this point, i is the index of the first op past the last valid
  17176. // quintet.
  17177. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17178. if (count < MIN_CHARS_IN_BLOCK) {
  17179. return i;
  17180. }
  17181. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17182. // showText, endText), include that as well. (E.g. <something> might be
  17183. // |dependency|.)
  17184. var iFirst = iFirstBeginText;
  17185. if (iFirstBeginText >= 4 &&
  17186. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17187. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17188. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17189. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17190. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17191. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17192. count++;
  17193. iFirst -= 5;
  17194. }
  17195. // Remove (endText, beginText, setFont) trios.
  17196. var iEndText = iFirst + 4;
  17197. for (var q = 1; q < count; q++) {
  17198. fnArray.splice(iEndText, 3);
  17199. argsArray.splice(iEndText, 3);
  17200. iEndText += 2;
  17201. }
  17202. return iEndText + 1;
  17203. });
  17204. function QueueOptimizer() {}
  17205. QueueOptimizer.prototype = {
  17206. optimize: function QueueOptimizer_optimize(queue) {
  17207. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17208. var context = {
  17209. iCurr: 0,
  17210. fnArray: fnArray,
  17211. argsArray: argsArray
  17212. };
  17213. var state;
  17214. var i = 0, ii = fnArray.length;
  17215. while (i < ii) {
  17216. state = (state || InitialState)[fnArray[i]];
  17217. if (typeof state === 'function') { // we found some handler
  17218. context.iCurr = i;
  17219. // state() returns the index of the first non-matching op (if we
  17220. // didn't match) or the first op past the modified ops (if we did
  17221. // match and replace).
  17222. i = state(context);
  17223. state = undefined; // reset the state machine
  17224. ii = context.fnArray.length;
  17225. } else {
  17226. i++;
  17227. }
  17228. }
  17229. }
  17230. };
  17231. return QueueOptimizer;
  17232. })();
  17233. var BUILT_IN_CMAPS = [
  17234. // << Start unicode maps.
  17235. 'Adobe-GB1-UCS2',
  17236. 'Adobe-CNS1-UCS2',
  17237. 'Adobe-Japan1-UCS2',
  17238. 'Adobe-Korea1-UCS2',
  17239. // >> End unicode maps.
  17240. '78-EUC-H',
  17241. '78-EUC-V',
  17242. '78-H',
  17243. '78-RKSJ-H',
  17244. '78-RKSJ-V',
  17245. '78-V',
  17246. '78ms-RKSJ-H',
  17247. '78ms-RKSJ-V',
  17248. '83pv-RKSJ-H',
  17249. '90ms-RKSJ-H',
  17250. '90ms-RKSJ-V',
  17251. '90msp-RKSJ-H',
  17252. '90msp-RKSJ-V',
  17253. '90pv-RKSJ-H',
  17254. '90pv-RKSJ-V',
  17255. 'Add-H',
  17256. 'Add-RKSJ-H',
  17257. 'Add-RKSJ-V',
  17258. 'Add-V',
  17259. 'Adobe-CNS1-0',
  17260. 'Adobe-CNS1-1',
  17261. 'Adobe-CNS1-2',
  17262. 'Adobe-CNS1-3',
  17263. 'Adobe-CNS1-4',
  17264. 'Adobe-CNS1-5',
  17265. 'Adobe-CNS1-6',
  17266. 'Adobe-GB1-0',
  17267. 'Adobe-GB1-1',
  17268. 'Adobe-GB1-2',
  17269. 'Adobe-GB1-3',
  17270. 'Adobe-GB1-4',
  17271. 'Adobe-GB1-5',
  17272. 'Adobe-Japan1-0',
  17273. 'Adobe-Japan1-1',
  17274. 'Adobe-Japan1-2',
  17275. 'Adobe-Japan1-3',
  17276. 'Adobe-Japan1-4',
  17277. 'Adobe-Japan1-5',
  17278. 'Adobe-Japan1-6',
  17279. 'Adobe-Korea1-0',
  17280. 'Adobe-Korea1-1',
  17281. 'Adobe-Korea1-2',
  17282. 'B5-H',
  17283. 'B5-V',
  17284. 'B5pc-H',
  17285. 'B5pc-V',
  17286. 'CNS-EUC-H',
  17287. 'CNS-EUC-V',
  17288. 'CNS1-H',
  17289. 'CNS1-V',
  17290. 'CNS2-H',
  17291. 'CNS2-V',
  17292. 'ETHK-B5-H',
  17293. 'ETHK-B5-V',
  17294. 'ETen-B5-H',
  17295. 'ETen-B5-V',
  17296. 'ETenms-B5-H',
  17297. 'ETenms-B5-V',
  17298. 'EUC-H',
  17299. 'EUC-V',
  17300. 'Ext-H',
  17301. 'Ext-RKSJ-H',
  17302. 'Ext-RKSJ-V',
  17303. 'Ext-V',
  17304. 'GB-EUC-H',
  17305. 'GB-EUC-V',
  17306. 'GB-H',
  17307. 'GB-V',
  17308. 'GBK-EUC-H',
  17309. 'GBK-EUC-V',
  17310. 'GBK2K-H',
  17311. 'GBK2K-V',
  17312. 'GBKp-EUC-H',
  17313. 'GBKp-EUC-V',
  17314. 'GBT-EUC-H',
  17315. 'GBT-EUC-V',
  17316. 'GBT-H',
  17317. 'GBT-V',
  17318. 'GBTpc-EUC-H',
  17319. 'GBTpc-EUC-V',
  17320. 'GBpc-EUC-H',
  17321. 'GBpc-EUC-V',
  17322. 'H',
  17323. 'HKdla-B5-H',
  17324. 'HKdla-B5-V',
  17325. 'HKdlb-B5-H',
  17326. 'HKdlb-B5-V',
  17327. 'HKgccs-B5-H',
  17328. 'HKgccs-B5-V',
  17329. 'HKm314-B5-H',
  17330. 'HKm314-B5-V',
  17331. 'HKm471-B5-H',
  17332. 'HKm471-B5-V',
  17333. 'HKscs-B5-H',
  17334. 'HKscs-B5-V',
  17335. 'Hankaku',
  17336. 'Hiragana',
  17337. 'KSC-EUC-H',
  17338. 'KSC-EUC-V',
  17339. 'KSC-H',
  17340. 'KSC-Johab-H',
  17341. 'KSC-Johab-V',
  17342. 'KSC-V',
  17343. 'KSCms-UHC-H',
  17344. 'KSCms-UHC-HW-H',
  17345. 'KSCms-UHC-HW-V',
  17346. 'KSCms-UHC-V',
  17347. 'KSCpc-EUC-H',
  17348. 'KSCpc-EUC-V',
  17349. 'Katakana',
  17350. 'NWP-H',
  17351. 'NWP-V',
  17352. 'RKSJ-H',
  17353. 'RKSJ-V',
  17354. 'Roman',
  17355. 'UniCNS-UCS2-H',
  17356. 'UniCNS-UCS2-V',
  17357. 'UniCNS-UTF16-H',
  17358. 'UniCNS-UTF16-V',
  17359. 'UniCNS-UTF32-H',
  17360. 'UniCNS-UTF32-V',
  17361. 'UniCNS-UTF8-H',
  17362. 'UniCNS-UTF8-V',
  17363. 'UniGB-UCS2-H',
  17364. 'UniGB-UCS2-V',
  17365. 'UniGB-UTF16-H',
  17366. 'UniGB-UTF16-V',
  17367. 'UniGB-UTF32-H',
  17368. 'UniGB-UTF32-V',
  17369. 'UniGB-UTF8-H',
  17370. 'UniGB-UTF8-V',
  17371. 'UniJIS-UCS2-H',
  17372. 'UniJIS-UCS2-HW-H',
  17373. 'UniJIS-UCS2-HW-V',
  17374. 'UniJIS-UCS2-V',
  17375. 'UniJIS-UTF16-H',
  17376. 'UniJIS-UTF16-V',
  17377. 'UniJIS-UTF32-H',
  17378. 'UniJIS-UTF32-V',
  17379. 'UniJIS-UTF8-H',
  17380. 'UniJIS-UTF8-V',
  17381. 'UniJIS2004-UTF16-H',
  17382. 'UniJIS2004-UTF16-V',
  17383. 'UniJIS2004-UTF32-H',
  17384. 'UniJIS2004-UTF32-V',
  17385. 'UniJIS2004-UTF8-H',
  17386. 'UniJIS2004-UTF8-V',
  17387. 'UniJISPro-UCS2-HW-V',
  17388. 'UniJISPro-UCS2-V',
  17389. 'UniJISPro-UTF8-V',
  17390. 'UniJISX0213-UTF32-H',
  17391. 'UniJISX0213-UTF32-V',
  17392. 'UniJISX02132004-UTF32-H',
  17393. 'UniJISX02132004-UTF32-V',
  17394. 'UniKS-UCS2-H',
  17395. 'UniKS-UCS2-V',
  17396. 'UniKS-UTF16-H',
  17397. 'UniKS-UTF16-V',
  17398. 'UniKS-UTF32-H',
  17399. 'UniKS-UTF32-V',
  17400. 'UniKS-UTF8-H',
  17401. 'UniKS-UTF8-V',
  17402. 'V',
  17403. 'WP-Symbol'];
  17404. // CMap, not to be confused with TrueType's cmap.
  17405. var CMap = (function CMapClosure() {
  17406. function CMap(builtInCMap) {
  17407. // Codespace ranges are stored as follows:
  17408. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17409. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17410. this.codespaceRanges = [[], [], [], []];
  17411. this.numCodespaceRanges = 0;
  17412. // Map entries have one of two forms.
  17413. // - cid chars are 16-bit unsigned integers, stored as integers.
  17414. // - bf chars are variable-length byte sequences, stored as strings, with
  17415. // one byte per character.
  17416. this._map = [];
  17417. this.vertical = false;
  17418. this.useCMap = null;
  17419. this.builtInCMap = builtInCMap;
  17420. }
  17421. CMap.prototype = {
  17422. addCodespaceRange: function(n, low, high) {
  17423. this.codespaceRanges[n - 1].push(low, high);
  17424. this.numCodespaceRanges++;
  17425. },
  17426. mapCidRange: function(low, high, dstLow) {
  17427. while (low <= high) {
  17428. this._map[low++] = dstLow++;
  17429. }
  17430. },
  17431. mapBfRange: function(low, high, dstLow) {
  17432. var lastByte = dstLow.length - 1;
  17433. while (low <= high) {
  17434. this._map[low++] = dstLow;
  17435. // Only the last byte has to be incremented.
  17436. dstLow = dstLow.substr(0, lastByte) +
  17437. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17438. }
  17439. },
  17440. mapBfRangeToArray: function(low, high, array) {
  17441. var i = 0, ii = array.length;
  17442. while (low <= high && i < ii) {
  17443. this._map[low] = array[i++];
  17444. ++low;
  17445. }
  17446. },
  17447. // This is used for both bf and cid chars.
  17448. mapOne: function(src, dst) {
  17449. this._map[src] = dst;
  17450. },
  17451. lookup: function(code) {
  17452. return this._map[code];
  17453. },
  17454. contains: function(code) {
  17455. return this._map[code] !== undefined;
  17456. },
  17457. forEach: function(callback) {
  17458. // Most maps have fewer than 65536 entries, and for those we use normal
  17459. // array iteration. But really sparse tables are possible -- e.g. with
  17460. // indices in the *billions*. For such tables we use for..in, which isn't
  17461. // ideal because it stringifies the indices for all present elements, but
  17462. // it does avoid iterating over every undefined entry.
  17463. var map = this._map;
  17464. var length = map.length;
  17465. var i;
  17466. if (length <= 0x10000) {
  17467. for (i = 0; i < length; i++) {
  17468. if (map[i] !== undefined) {
  17469. callback(i, map[i]);
  17470. }
  17471. }
  17472. } else {
  17473. for (i in this._map) {
  17474. callback(i, map[i]);
  17475. }
  17476. }
  17477. },
  17478. charCodeOf: function(value) {
  17479. return this._map.indexOf(value);
  17480. },
  17481. getMap: function() {
  17482. return this._map;
  17483. },
  17484. readCharCode: function(str, offset, out) {
  17485. var c = 0;
  17486. var codespaceRanges = this.codespaceRanges;
  17487. var codespaceRangesLen = this.codespaceRanges.length;
  17488. // 9.7.6.2 CMap Mapping
  17489. // The code length is at most 4.
  17490. for (var n = 0; n < codespaceRangesLen; n++) {
  17491. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17492. // Check each codespace range to see if it falls within.
  17493. var codespaceRange = codespaceRanges[n];
  17494. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17495. var low = codespaceRange[k++];
  17496. var high = codespaceRange[k++];
  17497. if (c >= low && c <= high) {
  17498. out.charcode = c;
  17499. out.length = n + 1;
  17500. return;
  17501. }
  17502. }
  17503. }
  17504. out.charcode = 0;
  17505. out.length = 1;
  17506. }
  17507. };
  17508. return CMap;
  17509. })();
  17510. // A special case of CMap, where the _map array implicitly has a length of
  17511. // 65535 and each element is equal to its index.
  17512. var IdentityCMap = (function IdentityCMapClosure() {
  17513. function IdentityCMap(vertical, n) {
  17514. CMap.call(this);
  17515. this.vertical = vertical;
  17516. this.addCodespaceRange(n, 0, 0xffff);
  17517. }
  17518. Util.inherit(IdentityCMap, CMap, {});
  17519. IdentityCMap.prototype = {
  17520. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17521. mapCidRange: function(low, high, dstLow) {
  17522. error('should not call mapCidRange');
  17523. },
  17524. mapBfRange: function(low, high, dstLow) {
  17525. error('should not call mapBfRange');
  17526. },
  17527. mapBfRangeToArray: function(low, high, array) {
  17528. error('should not call mapBfRangeToArray');
  17529. },
  17530. mapOne: function(src, dst) {
  17531. error('should not call mapCidOne');
  17532. },
  17533. lookup: function(code) {
  17534. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17535. },
  17536. contains: function(code) {
  17537. return isInt(code) && code <= 0xffff;
  17538. },
  17539. forEach: function(callback) {
  17540. for (var i = 0; i <= 0xffff; i++) {
  17541. callback(i, i);
  17542. }
  17543. },
  17544. charCodeOf: function(value) {
  17545. return (isInt(value) && value <= 0xffff) ? value : -1;
  17546. },
  17547. getMap: function() {
  17548. // Sometimes identity maps must be instantiated, but it's rare.
  17549. var map = new Array(0x10000);
  17550. for (var i = 0; i <= 0xffff; i++) {
  17551. map[i] = i;
  17552. }
  17553. return map;
  17554. },
  17555. readCharCode: CMap.prototype.readCharCode
  17556. };
  17557. return IdentityCMap;
  17558. })();
  17559. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17560. function fetchBinaryData(url) {
  17561. var nonBinaryRequest = PDFJS.disableWorker;
  17562. var request = new XMLHttpRequest();
  17563. request.open('GET', url, false);
  17564. if (!nonBinaryRequest) {
  17565. try {
  17566. request.responseType = 'arraybuffer';
  17567. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17568. } catch (e) {
  17569. nonBinaryRequest = true;
  17570. }
  17571. }
  17572. if (nonBinaryRequest && request.overrideMimeType) {
  17573. request.overrideMimeType('text/plain; charset=x-user-defined');
  17574. }
  17575. request.send(null);
  17576. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17577. error('Unable to get binary cMap at: ' + url);
  17578. }
  17579. if (nonBinaryRequest) {
  17580. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17581. return ch.charCodeAt(0) & 255;
  17582. });
  17583. return new Uint8Array(data);
  17584. }
  17585. return new Uint8Array(request.response);
  17586. }
  17587. function hexToInt(a, size) {
  17588. var n = 0;
  17589. for (var i = 0; i <= size; i++) {
  17590. n = (n << 8) | a[i];
  17591. }
  17592. return n >>> 0;
  17593. }
  17594. function hexToStr(a, size) {
  17595. // This code is hot. Special-case some common values to avoid creating an
  17596. // object with subarray().
  17597. if (size === 1) {
  17598. return String.fromCharCode(a[0], a[1]);
  17599. }
  17600. if (size === 3) {
  17601. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17602. }
  17603. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17604. }
  17605. function addHex(a, b, size) {
  17606. var c = 0;
  17607. for (var i = size; i >= 0; i--) {
  17608. c += a[i] + b[i];
  17609. a[i] = c & 255;
  17610. c >>= 8;
  17611. }
  17612. }
  17613. function incHex(a, size) {
  17614. var c = 1;
  17615. for (var i = size; i >= 0 && c > 0; i--) {
  17616. c += a[i];
  17617. a[i] = c & 255;
  17618. c >>= 8;
  17619. }
  17620. }
  17621. var MAX_NUM_SIZE = 16;
  17622. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17623. function BinaryCMapStream(data) {
  17624. this.buffer = data;
  17625. this.pos = 0;
  17626. this.end = data.length;
  17627. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17628. }
  17629. BinaryCMapStream.prototype = {
  17630. readByte: function () {
  17631. if (this.pos >= this.end) {
  17632. return -1;
  17633. }
  17634. return this.buffer[this.pos++];
  17635. },
  17636. readNumber: function () {
  17637. var n = 0;
  17638. var last;
  17639. do {
  17640. var b = this.readByte();
  17641. if (b < 0) {
  17642. error('unexpected EOF in bcmap');
  17643. }
  17644. last = !(b & 0x80);
  17645. n = (n << 7) | (b & 0x7F);
  17646. } while (!last);
  17647. return n;
  17648. },
  17649. readSigned: function () {
  17650. var n = this.readNumber();
  17651. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  17652. },
  17653. readHex: function (num, size) {
  17654. num.set(this.buffer.subarray(this.pos,
  17655. this.pos + size + 1));
  17656. this.pos += size + 1;
  17657. },
  17658. readHexNumber: function (num, size) {
  17659. var last;
  17660. var stack = this.tmpBuf, sp = 0;
  17661. do {
  17662. var b = this.readByte();
  17663. if (b < 0) {
  17664. error('unexpected EOF in bcmap');
  17665. }
  17666. last = !(b & 0x80);
  17667. stack[sp++] = b & 0x7F;
  17668. } while (!last);
  17669. var i = size, buffer = 0, bufferSize = 0;
  17670. while (i >= 0) {
  17671. while (bufferSize < 8 && stack.length > 0) {
  17672. buffer = (stack[--sp] << bufferSize) | buffer;
  17673. bufferSize += 7;
  17674. }
  17675. num[i] = buffer & 255;
  17676. i--;
  17677. buffer >>= 8;
  17678. bufferSize -= 8;
  17679. }
  17680. },
  17681. readHexSigned: function (num, size) {
  17682. this.readHexNumber(num, size);
  17683. var sign = num[size] & 1 ? 255 : 0;
  17684. var c = 0;
  17685. for (var i = 0; i <= size; i++) {
  17686. c = ((c & 1) << 8) | num[i];
  17687. num[i] = (c >> 1) ^ sign;
  17688. }
  17689. },
  17690. readString: function () {
  17691. var len = this.readNumber();
  17692. var s = '';
  17693. for (var i = 0; i < len; i++) {
  17694. s += String.fromCharCode(this.readNumber());
  17695. }
  17696. return s;
  17697. }
  17698. };
  17699. function processBinaryCMap(url, cMap, extend) {
  17700. var data = fetchBinaryData(url);
  17701. var stream = new BinaryCMapStream(data);
  17702. var header = stream.readByte();
  17703. cMap.vertical = !!(header & 1);
  17704. var useCMap = null;
  17705. var start = new Uint8Array(MAX_NUM_SIZE);
  17706. var end = new Uint8Array(MAX_NUM_SIZE);
  17707. var char = new Uint8Array(MAX_NUM_SIZE);
  17708. var charCode = new Uint8Array(MAX_NUM_SIZE);
  17709. var tmp = new Uint8Array(MAX_NUM_SIZE);
  17710. var code;
  17711. var b;
  17712. while ((b = stream.readByte()) >= 0) {
  17713. var type = b >> 5;
  17714. if (type === 7) { // metadata, e.g. comment or usecmap
  17715. switch (b & 0x1F) {
  17716. case 0:
  17717. stream.readString(); // skipping comment
  17718. break;
  17719. case 1:
  17720. useCMap = stream.readString();
  17721. break;
  17722. }
  17723. continue;
  17724. }
  17725. var sequence = !!(b & 0x10);
  17726. var dataSize = b & 15;
  17727. assert(dataSize + 1 <= MAX_NUM_SIZE);
  17728. var ucs2DataSize = 1;
  17729. var subitemsCount = stream.readNumber();
  17730. var i;
  17731. switch (type) {
  17732. case 0: // codespacerange
  17733. stream.readHex(start, dataSize);
  17734. stream.readHexNumber(end, dataSize);
  17735. addHex(end, start, dataSize);
  17736. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  17737. hexToInt(end, dataSize));
  17738. for (i = 1; i < subitemsCount; i++) {
  17739. incHex(end, dataSize);
  17740. stream.readHexNumber(start, dataSize);
  17741. addHex(start, end, dataSize);
  17742. stream.readHexNumber(end, dataSize);
  17743. addHex(end, start, dataSize);
  17744. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  17745. hexToInt(end, dataSize));
  17746. }
  17747. break;
  17748. case 1: // notdefrange
  17749. stream.readHex(start, dataSize);
  17750. stream.readHexNumber(end, dataSize);
  17751. addHex(end, start, dataSize);
  17752. code = stream.readNumber();
  17753. // undefined range, skipping
  17754. for (i = 1; i < subitemsCount; i++) {
  17755. incHex(end, dataSize);
  17756. stream.readHexNumber(start, dataSize);
  17757. addHex(start, end, dataSize);
  17758. stream.readHexNumber(end, dataSize);
  17759. addHex(end, start, dataSize);
  17760. code = stream.readNumber();
  17761. // nop
  17762. }
  17763. break;
  17764. case 2: // cidchar
  17765. stream.readHex(char, dataSize);
  17766. code = stream.readNumber();
  17767. cMap.mapOne(hexToInt(char, dataSize), code);
  17768. for (i = 1; i < subitemsCount; i++) {
  17769. incHex(char, dataSize);
  17770. if (!sequence) {
  17771. stream.readHexNumber(tmp, dataSize);
  17772. addHex(char, tmp, dataSize);
  17773. }
  17774. code = stream.readSigned() + (code + 1);
  17775. cMap.mapOne(hexToInt(char, dataSize), code);
  17776. }
  17777. break;
  17778. case 3: // cidrange
  17779. stream.readHex(start, dataSize);
  17780. stream.readHexNumber(end, dataSize);
  17781. addHex(end, start, dataSize);
  17782. code = stream.readNumber();
  17783. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  17784. code);
  17785. for (i = 1; i < subitemsCount; i++) {
  17786. incHex(end, dataSize);
  17787. if (!sequence) {
  17788. stream.readHexNumber(start, dataSize);
  17789. addHex(start, end, dataSize);
  17790. } else {
  17791. start.set(end);
  17792. }
  17793. stream.readHexNumber(end, dataSize);
  17794. addHex(end, start, dataSize);
  17795. code = stream.readNumber();
  17796. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  17797. code);
  17798. }
  17799. break;
  17800. case 4: // bfchar
  17801. stream.readHex(char, ucs2DataSize);
  17802. stream.readHex(charCode, dataSize);
  17803. cMap.mapOne(hexToInt(char, ucs2DataSize),
  17804. hexToStr(charCode, dataSize));
  17805. for (i = 1; i < subitemsCount; i++) {
  17806. incHex(char, ucs2DataSize);
  17807. if (!sequence) {
  17808. stream.readHexNumber(tmp, ucs2DataSize);
  17809. addHex(char, tmp, ucs2DataSize);
  17810. }
  17811. incHex(charCode, dataSize);
  17812. stream.readHexSigned(tmp, dataSize);
  17813. addHex(charCode, tmp, dataSize);
  17814. cMap.mapOne(hexToInt(char, ucs2DataSize),
  17815. hexToStr(charCode, dataSize));
  17816. }
  17817. break;
  17818. case 5: // bfrange
  17819. stream.readHex(start, ucs2DataSize);
  17820. stream.readHexNumber(end, ucs2DataSize);
  17821. addHex(end, start, ucs2DataSize);
  17822. stream.readHex(charCode, dataSize);
  17823. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  17824. hexToInt(end, ucs2DataSize),
  17825. hexToStr(charCode, dataSize));
  17826. for (i = 1; i < subitemsCount; i++) {
  17827. incHex(end, ucs2DataSize);
  17828. if (!sequence) {
  17829. stream.readHexNumber(start, ucs2DataSize);
  17830. addHex(start, end, ucs2DataSize);
  17831. } else {
  17832. start.set(end);
  17833. }
  17834. stream.readHexNumber(end, ucs2DataSize);
  17835. addHex(end, start, ucs2DataSize);
  17836. stream.readHex(charCode, dataSize);
  17837. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  17838. hexToInt(end, ucs2DataSize),
  17839. hexToStr(charCode, dataSize));
  17840. }
  17841. break;
  17842. default:
  17843. error('Unknown type: ' + type);
  17844. break;
  17845. }
  17846. }
  17847. if (useCMap) {
  17848. extend(useCMap);
  17849. }
  17850. return cMap;
  17851. }
  17852. function BinaryCMapReader() {}
  17853. BinaryCMapReader.prototype = {
  17854. read: processBinaryCMap
  17855. };
  17856. return BinaryCMapReader;
  17857. })();
  17858. var CMapFactory = (function CMapFactoryClosure() {
  17859. function strToInt(str) {
  17860. var a = 0;
  17861. for (var i = 0; i < str.length; i++) {
  17862. a = (a << 8) | str.charCodeAt(i);
  17863. }
  17864. return a >>> 0;
  17865. }
  17866. function expectString(obj) {
  17867. if (!isString(obj)) {
  17868. error('Malformed CMap: expected string.');
  17869. }
  17870. }
  17871. function expectInt(obj) {
  17872. if (!isInt(obj)) {
  17873. error('Malformed CMap: expected int.');
  17874. }
  17875. }
  17876. function parseBfChar(cMap, lexer) {
  17877. while (true) {
  17878. var obj = lexer.getObj();
  17879. if (isEOF(obj)) {
  17880. break;
  17881. }
  17882. if (isCmd(obj, 'endbfchar')) {
  17883. return;
  17884. }
  17885. expectString(obj);
  17886. var src = strToInt(obj);
  17887. obj = lexer.getObj();
  17888. // TODO are /dstName used?
  17889. expectString(obj);
  17890. var dst = obj;
  17891. cMap.mapOne(src, dst);
  17892. }
  17893. }
  17894. function parseBfRange(cMap, lexer) {
  17895. while (true) {
  17896. var obj = lexer.getObj();
  17897. if (isEOF(obj)) {
  17898. break;
  17899. }
  17900. if (isCmd(obj, 'endbfrange')) {
  17901. return;
  17902. }
  17903. expectString(obj);
  17904. var low = strToInt(obj);
  17905. obj = lexer.getObj();
  17906. expectString(obj);
  17907. var high = strToInt(obj);
  17908. obj = lexer.getObj();
  17909. if (isInt(obj) || isString(obj)) {
  17910. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  17911. cMap.mapBfRange(low, high, dstLow);
  17912. } else if (isCmd(obj, '[')) {
  17913. obj = lexer.getObj();
  17914. var array = [];
  17915. while (!isCmd(obj, ']') && !isEOF(obj)) {
  17916. array.push(obj);
  17917. obj = lexer.getObj();
  17918. }
  17919. cMap.mapBfRangeToArray(low, high, array);
  17920. } else {
  17921. break;
  17922. }
  17923. }
  17924. error('Invalid bf range.');
  17925. }
  17926. function parseCidChar(cMap, lexer) {
  17927. while (true) {
  17928. var obj = lexer.getObj();
  17929. if (isEOF(obj)) {
  17930. break;
  17931. }
  17932. if (isCmd(obj, 'endcidchar')) {
  17933. return;
  17934. }
  17935. expectString(obj);
  17936. var src = strToInt(obj);
  17937. obj = lexer.getObj();
  17938. expectInt(obj);
  17939. var dst = obj;
  17940. cMap.mapOne(src, dst);
  17941. }
  17942. }
  17943. function parseCidRange(cMap, lexer) {
  17944. while (true) {
  17945. var obj = lexer.getObj();
  17946. if (isEOF(obj)) {
  17947. break;
  17948. }
  17949. if (isCmd(obj, 'endcidrange')) {
  17950. return;
  17951. }
  17952. expectString(obj);
  17953. var low = strToInt(obj);
  17954. obj = lexer.getObj();
  17955. expectString(obj);
  17956. var high = strToInt(obj);
  17957. obj = lexer.getObj();
  17958. expectInt(obj);
  17959. var dstLow = obj;
  17960. cMap.mapCidRange(low, high, dstLow);
  17961. }
  17962. }
  17963. function parseCodespaceRange(cMap, lexer) {
  17964. while (true) {
  17965. var obj = lexer.getObj();
  17966. if (isEOF(obj)) {
  17967. break;
  17968. }
  17969. if (isCmd(obj, 'endcodespacerange')) {
  17970. return;
  17971. }
  17972. if (!isString(obj)) {
  17973. break;
  17974. }
  17975. var low = strToInt(obj);
  17976. obj = lexer.getObj();
  17977. if (!isString(obj)) {
  17978. break;
  17979. }
  17980. var high = strToInt(obj);
  17981. cMap.addCodespaceRange(obj.length, low, high);
  17982. }
  17983. error('Invalid codespace range.');
  17984. }
  17985. function parseWMode(cMap, lexer) {
  17986. var obj = lexer.getObj();
  17987. if (isInt(obj)) {
  17988. cMap.vertical = !!obj;
  17989. }
  17990. }
  17991. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  17992. var previous;
  17993. var embededUseCMap;
  17994. objLoop: while (true) {
  17995. var obj = lexer.getObj();
  17996. if (isEOF(obj)) {
  17997. break;
  17998. } else if (isName(obj)) {
  17999. if (obj.name === 'WMode') {
  18000. parseWMode(cMap, lexer);
  18001. }
  18002. previous = obj;
  18003. } else if (isCmd(obj)) {
  18004. switch (obj.cmd) {
  18005. case 'endcmap':
  18006. break objLoop;
  18007. case 'usecmap':
  18008. if (isName(previous)) {
  18009. embededUseCMap = previous.name;
  18010. }
  18011. break;
  18012. case 'begincodespacerange':
  18013. parseCodespaceRange(cMap, lexer);
  18014. break;
  18015. case 'beginbfchar':
  18016. parseBfChar(cMap, lexer);
  18017. break;
  18018. case 'begincidchar':
  18019. parseCidChar(cMap, lexer);
  18020. break;
  18021. case 'beginbfrange':
  18022. parseBfRange(cMap, lexer);
  18023. break;
  18024. case 'begincidrange':
  18025. parseCidRange(cMap, lexer);
  18026. break;
  18027. }
  18028. }
  18029. }
  18030. if (!useCMap && embededUseCMap) {
  18031. // Load the usecmap definition from the file only if there wasn't one
  18032. // specified.
  18033. useCMap = embededUseCMap;
  18034. }
  18035. if (useCMap) {
  18036. extendCMap(cMap, builtInCMapParams, useCMap);
  18037. }
  18038. }
  18039. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18040. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18041. // If there aren't any code space ranges defined clone all the parent ones
  18042. // into this cMap.
  18043. if (cMap.numCodespaceRanges === 0) {
  18044. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18045. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18046. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18047. }
  18048. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18049. }
  18050. // Merge the map into the current one, making sure not to override
  18051. // any previously defined entries.
  18052. cMap.useCMap.forEach(function(key, value) {
  18053. if (!cMap.contains(key)) {
  18054. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18055. }
  18056. });
  18057. }
  18058. function parseBinaryCMap(name, builtInCMapParams) {
  18059. var url = builtInCMapParams.url + name + '.bcmap';
  18060. var cMap = new CMap(true);
  18061. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18062. extendCMap(cMap, builtInCMapParams, useCMap);
  18063. });
  18064. return cMap;
  18065. }
  18066. function createBuiltInCMap(name, builtInCMapParams) {
  18067. if (name === 'Identity-H') {
  18068. return new IdentityCMap(false, 2);
  18069. } else if (name === 'Identity-V') {
  18070. return new IdentityCMap(true, 2);
  18071. }
  18072. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18073. error('Unknown cMap name: ' + name);
  18074. }
  18075. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18076. if (builtInCMapParams.packed) {
  18077. return parseBinaryCMap(name, builtInCMapParams);
  18078. }
  18079. var request = new XMLHttpRequest();
  18080. var url = builtInCMapParams.url + name;
  18081. request.open('GET', url, false);
  18082. request.send(null);
  18083. if (!request.responseText) {
  18084. error('Unable to get cMap at: ' + url);
  18085. }
  18086. var cMap = new CMap(true);
  18087. var lexer = new Lexer(new StringStream(request.responseText));
  18088. parseCMap(cMap, lexer, builtInCMapParams, null);
  18089. return cMap;
  18090. }
  18091. return {
  18092. create: function (encoding, builtInCMapParams, useCMap) {
  18093. if (isName(encoding)) {
  18094. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18095. } else if (isStream(encoding)) {
  18096. var cMap = new CMap();
  18097. var lexer = new Lexer(encoding);
  18098. try {
  18099. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18100. } catch (e) {
  18101. warn('Invalid CMap data. ' + e);
  18102. }
  18103. return cMap;
  18104. }
  18105. error('Encoding required.');
  18106. }
  18107. };
  18108. })();
  18109. // Unicode Private Use Area
  18110. var PRIVATE_USE_OFFSET_START = 0xE000;
  18111. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18112. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18113. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18114. // except for Type 3 fonts
  18115. var PDF_GLYPH_SPACE_UNITS = 1000;
  18116. // Hinting is currently disabled due to unknown problems on windows
  18117. // in tracemonkey and various other pdfs with type1 fonts.
  18118. var HINTING_ENABLED = false;
  18119. // Accented charactars are not displayed properly on windows, using this flag
  18120. // to control analysis of seac charstrings.
  18121. var SEAC_ANALYSIS_ENABLED = false;
  18122. var FontFlags = {
  18123. FixedPitch: 1,
  18124. Serif: 2,
  18125. Symbolic: 4,
  18126. Script: 8,
  18127. Nonsymbolic: 32,
  18128. Italic: 64,
  18129. AllCap: 65536,
  18130. SmallCap: 131072,
  18131. ForceBold: 262144
  18132. };
  18133. var Encodings = {
  18134. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18135. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18136. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18137. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18138. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18139. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18140. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18141. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18142. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18143. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18144. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18145. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18146. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18147. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18148. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18149. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18150. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18151. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18152. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18153. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18154. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18155. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18156. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18157. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18158. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18159. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18160. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18161. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18162. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18163. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18164. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18165. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18166. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18167. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18168. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18169. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18170. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18171. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18172. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18173. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18174. 'Ydieresissmall'],
  18175. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18176. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18177. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18178. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18179. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18180. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18181. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18182. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18183. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18184. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18185. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18186. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18187. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18188. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18189. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18190. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18191. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18192. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18193. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18194. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18195. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18196. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18197. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18198. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18199. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18200. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18201. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18202. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18203. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18204. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18205. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18206. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18207. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18208. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18209. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18210. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18211. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18212. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18213. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18214. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18215. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18216. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18217. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18218. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18219. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18220. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18221. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18222. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18223. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18224. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18225. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18226. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18227. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18228. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18229. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18230. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18231. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18232. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18233. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18234. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18235. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18236. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18237. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18238. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18239. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18240. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18241. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18242. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18243. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18244. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18245. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18246. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18247. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18248. 'ogonek', 'caron'],
  18249. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18250. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18251. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18252. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18253. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18254. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18255. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18256. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18257. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18258. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18259. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18260. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18261. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18262. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18263. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18264. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18265. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18266. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18267. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18268. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18269. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18270. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18271. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18272. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18273. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18274. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18275. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18276. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18277. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18278. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18279. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18280. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18281. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18282. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18283. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18284. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18285. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18286. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18287. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18288. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18289. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18290. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18291. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18292. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18293. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18294. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18295. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18296. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18297. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18298. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18299. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18300. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18301. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18302. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18303. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18304. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18305. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18306. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18307. 'ydieresis'],
  18308. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18309. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18310. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18311. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18312. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18313. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18314. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18315. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18316. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18317. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18318. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18319. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18320. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18321. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18322. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18323. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18324. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18325. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18326. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18327. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18328. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18329. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18330. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18331. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18332. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18333. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18334. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18335. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18336. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18337. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18338. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18339. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18340. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18341. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18342. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18343. 'bracerightbt'],
  18344. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18345. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18346. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18347. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18348. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18349. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18350. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18351. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18352. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18353. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18354. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18355. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18356. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18357. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18358. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18359. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18360. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18361. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18362. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18363. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18364. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18365. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18366. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18367. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18368. };
  18369. /**
  18370. * Hold a map of decoded fonts and of the standard fourteen Type1
  18371. * fonts and their acronyms.
  18372. */
  18373. var stdFontMap = {
  18374. 'ArialNarrow': 'Helvetica',
  18375. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18376. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18377. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18378. 'ArialBlack': 'Helvetica',
  18379. 'ArialBlack-Bold': 'Helvetica-Bold',
  18380. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18381. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18382. 'Arial': 'Helvetica',
  18383. 'Arial-Bold': 'Helvetica-Bold',
  18384. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18385. 'Arial-Italic': 'Helvetica-Oblique',
  18386. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18387. 'Arial-BoldMT': 'Helvetica-Bold',
  18388. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18389. 'ArialMT': 'Helvetica',
  18390. 'Courier-Bold': 'Courier-Bold',
  18391. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18392. 'Courier-Italic': 'Courier-Oblique',
  18393. 'CourierNew': 'Courier',
  18394. 'CourierNew-Bold': 'Courier-Bold',
  18395. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18396. 'CourierNew-Italic': 'Courier-Oblique',
  18397. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18398. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18399. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18400. 'CourierNewPSMT': 'Courier',
  18401. 'Helvetica-Bold': 'Helvetica-Bold',
  18402. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18403. 'Helvetica-Italic': 'Helvetica-Oblique',
  18404. 'Symbol-Bold': 'Symbol',
  18405. 'Symbol-BoldItalic': 'Symbol',
  18406. 'Symbol-Italic': 'Symbol',
  18407. 'TimesNewRoman': 'Times-Roman',
  18408. 'TimesNewRoman-Bold': 'Times-Bold',
  18409. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18410. 'TimesNewRoman-Italic': 'Times-Italic',
  18411. 'TimesNewRomanPS': 'Times-Roman',
  18412. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18413. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18414. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18415. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18416. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18417. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18418. 'TimesNewRomanPSMT': 'Times-Roman',
  18419. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18420. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18421. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18422. };
  18423. /**
  18424. * Holds the map of the non-standard fonts that might be included as a standard
  18425. * fonts without glyph data.
  18426. */
  18427. var nonStdFontMap = {
  18428. 'ComicSansMS': 'Comic Sans MS',
  18429. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18430. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18431. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18432. 'LucidaConsole': 'Courier',
  18433. 'LucidaConsole-Bold': 'Courier-Bold',
  18434. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18435. 'LucidaConsole-Italic': 'Courier-Oblique',
  18436. 'MS-Gothic': 'MS Gothic',
  18437. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18438. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18439. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18440. 'MS-Mincho': 'MS Mincho',
  18441. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18442. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18443. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18444. 'MS-PGothic': 'MS PGothic',
  18445. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18446. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18447. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18448. 'MS-PMincho': 'MS PMincho',
  18449. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18450. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18451. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  18452. };
  18453. var serifFonts = {
  18454. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18455. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18456. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18457. 'Arno': true, 'Aster': true, 'Aurora': true,
  18458. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18459. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18460. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18461. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18462. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18463. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18464. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18465. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18466. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18467. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18468. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18469. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18470. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18471. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18472. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18473. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18474. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18475. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18476. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18477. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18478. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18479. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18480. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18481. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18482. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18483. 'Miller': true, 'Minion': true, 'Modern': true,
  18484. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18485. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18486. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18487. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18488. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18489. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18490. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18491. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18492. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18493. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18494. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18495. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18496. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18497. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18498. };
  18499. var symbolsFonts = {
  18500. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18501. };
  18502. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18503. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18504. // glyphs, but common for some set of the standard fonts.
  18505. var GlyphMapForStandardFonts = {
  18506. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18507. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18508. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18509. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18510. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18511. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18512. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18513. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18514. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18515. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18516. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18517. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18518. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18519. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18520. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18521. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18522. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18523. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18524. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18525. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18526. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18527. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18528. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18529. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18530. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18531. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18532. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18533. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18534. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18535. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18536. '298': 380, '305': 963,
  18537. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18538. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18539. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18540. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18541. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18542. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18543. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18544. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18545. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18546. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18547. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18548. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18549. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18550. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18551. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18552. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18553. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18554. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18555. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18556. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18557. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18558. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18559. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18560. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18561. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18562. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18563. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18564. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18565. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18566. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18567. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18568. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18569. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18570. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18571. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18572. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18573. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18574. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18575. };
  18576. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18577. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18578. // to the similar equivalents in the normal characters range.
  18579. var SpecialPUASymbols = {
  18580. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18581. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18582. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18583. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18584. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18585. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18586. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18587. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18588. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18589. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18590. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18591. '63742': 0x23AD, // bracerightmid (0xF8FE)
  18592. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18593. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18594. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18595. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18596. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18597. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18598. '63723': 0x239B, // parenlefttp (0xF8EB)
  18599. '63724': 0x239C, // parenleftex (0xF8EC)
  18600. '63725': 0x239D, // parenleftbt (0xF8ED)
  18601. '63734': 0x239E, // parenrighttp (0xF8F6)
  18602. '63735': 0x239F, // parenrightex (0xF8F7)
  18603. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18604. };
  18605. function mapSpecialUnicodeValues(code) {
  18606. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18607. return 0;
  18608. } else if (code >= 0xF600 && code <= 0xF8FF) {
  18609. return (SpecialPUASymbols[code] || code);
  18610. }
  18611. return code;
  18612. }
  18613. var UnicodeRanges = [
  18614. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18615. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18616. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18617. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18618. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18619. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18620. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18621. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18622. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18623. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18624. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18625. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18626. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18627. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18628. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18629. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18630. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18631. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18632. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18633. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18634. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18635. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18636. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18637. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  18638. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  18639. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  18640. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  18641. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  18642. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  18643. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  18644. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  18645. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  18646. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  18647. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  18648. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  18649. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  18650. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  18651. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  18652. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  18653. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  18654. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  18655. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  18656. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  18657. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  18658. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  18659. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  18660. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  18661. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  18662. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  18663. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  18664. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  18665. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  18666. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  18667. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  18668. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  18669. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  18670. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  18671. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  18672. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  18673. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  18674. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  18675. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  18676. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  18677. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  18678. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  18679. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  18680. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  18681. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  18682. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  18683. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  18684. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  18685. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  18686. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  18687. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  18688. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  18689. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  18690. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  18691. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  18692. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  18693. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  18694. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  18695. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  18696. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  18697. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  18698. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  18699. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  18700. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  18701. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  18702. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  18703. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  18704. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  18705. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  18706. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  18707. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  18708. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  18709. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  18710. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  18711. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  18712. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  18713. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  18714. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  18715. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  18716. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  18717. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  18718. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  18719. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  18720. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  18721. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  18722. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  18723. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  18724. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  18725. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  18726. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  18727. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  18728. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  18729. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  18730. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  18731. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  18732. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  18733. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  18734. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  18735. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  18736. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  18737. ];
  18738. var MacStandardGlyphOrdering = [
  18739. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  18740. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  18741. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  18742. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  18743. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  18744. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  18745. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  18746. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  18747. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  18748. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  18749. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  18750. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  18751. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18752. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  18753. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  18754. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  18755. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  18756. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  18757. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  18758. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  18759. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  18760. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  18761. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  18762. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  18763. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  18764. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  18765. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  18766. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  18767. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  18768. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  18769. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  18770. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  18771. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  18772. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  18773. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  18774. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  18775. function getUnicodeRangeFor(value) {
  18776. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  18777. var range = UnicodeRanges[i];
  18778. if (value >= range.begin && value < range.end) {
  18779. return i;
  18780. }
  18781. }
  18782. return -1;
  18783. }
  18784. function isRTLRangeFor(value) {
  18785. var range = UnicodeRanges[13];
  18786. if (value >= range.begin && value < range.end) {
  18787. return true;
  18788. }
  18789. range = UnicodeRanges[11];
  18790. if (value >= range.begin && value < range.end) {
  18791. return true;
  18792. }
  18793. return false;
  18794. }
  18795. // The normalization table is obtained by filtering the Unicode characters
  18796. // database with <compat> entries.
  18797. var NormalizedUnicodes = {
  18798. '\u00A8': '\u0020\u0308',
  18799. '\u00AF': '\u0020\u0304',
  18800. '\u00B4': '\u0020\u0301',
  18801. '\u00B5': '\u03BC',
  18802. '\u00B8': '\u0020\u0327',
  18803. '\u0132': '\u0049\u004A',
  18804. '\u0133': '\u0069\u006A',
  18805. '\u013F': '\u004C\u00B7',
  18806. '\u0140': '\u006C\u00B7',
  18807. '\u0149': '\u02BC\u006E',
  18808. '\u017F': '\u0073',
  18809. '\u01C4': '\u0044\u017D',
  18810. '\u01C5': '\u0044\u017E',
  18811. '\u01C6': '\u0064\u017E',
  18812. '\u01C7': '\u004C\u004A',
  18813. '\u01C8': '\u004C\u006A',
  18814. '\u01C9': '\u006C\u006A',
  18815. '\u01CA': '\u004E\u004A',
  18816. '\u01CB': '\u004E\u006A',
  18817. '\u01CC': '\u006E\u006A',
  18818. '\u01F1': '\u0044\u005A',
  18819. '\u01F2': '\u0044\u007A',
  18820. '\u01F3': '\u0064\u007A',
  18821. '\u02D8': '\u0020\u0306',
  18822. '\u02D9': '\u0020\u0307',
  18823. '\u02DA': '\u0020\u030A',
  18824. '\u02DB': '\u0020\u0328',
  18825. '\u02DC': '\u0020\u0303',
  18826. '\u02DD': '\u0020\u030B',
  18827. '\u037A': '\u0020\u0345',
  18828. '\u0384': '\u0020\u0301',
  18829. '\u03D0': '\u03B2',
  18830. '\u03D1': '\u03B8',
  18831. '\u03D2': '\u03A5',
  18832. '\u03D5': '\u03C6',
  18833. '\u03D6': '\u03C0',
  18834. '\u03F0': '\u03BA',
  18835. '\u03F1': '\u03C1',
  18836. '\u03F2': '\u03C2',
  18837. '\u03F4': '\u0398',
  18838. '\u03F5': '\u03B5',
  18839. '\u03F9': '\u03A3',
  18840. '\u0587': '\u0565\u0582',
  18841. '\u0675': '\u0627\u0674',
  18842. '\u0676': '\u0648\u0674',
  18843. '\u0677': '\u06C7\u0674',
  18844. '\u0678': '\u064A\u0674',
  18845. '\u0E33': '\u0E4D\u0E32',
  18846. '\u0EB3': '\u0ECD\u0EB2',
  18847. '\u0EDC': '\u0EAB\u0E99',
  18848. '\u0EDD': '\u0EAB\u0EA1',
  18849. '\u0F77': '\u0FB2\u0F81',
  18850. '\u0F79': '\u0FB3\u0F81',
  18851. '\u1E9A': '\u0061\u02BE',
  18852. '\u1FBD': '\u0020\u0313',
  18853. '\u1FBF': '\u0020\u0313',
  18854. '\u1FC0': '\u0020\u0342',
  18855. '\u1FFE': '\u0020\u0314',
  18856. '\u2002': '\u0020',
  18857. '\u2003': '\u0020',
  18858. '\u2004': '\u0020',
  18859. '\u2005': '\u0020',
  18860. '\u2006': '\u0020',
  18861. '\u2008': '\u0020',
  18862. '\u2009': '\u0020',
  18863. '\u200A': '\u0020',
  18864. '\u2017': '\u0020\u0333',
  18865. '\u2024': '\u002E',
  18866. '\u2025': '\u002E\u002E',
  18867. '\u2026': '\u002E\u002E\u002E',
  18868. '\u2033': '\u2032\u2032',
  18869. '\u2034': '\u2032\u2032\u2032',
  18870. '\u2036': '\u2035\u2035',
  18871. '\u2037': '\u2035\u2035\u2035',
  18872. '\u203C': '\u0021\u0021',
  18873. '\u203E': '\u0020\u0305',
  18874. '\u2047': '\u003F\u003F',
  18875. '\u2048': '\u003F\u0021',
  18876. '\u2049': '\u0021\u003F',
  18877. '\u2057': '\u2032\u2032\u2032\u2032',
  18878. '\u205F': '\u0020',
  18879. '\u20A8': '\u0052\u0073',
  18880. '\u2100': '\u0061\u002F\u0063',
  18881. '\u2101': '\u0061\u002F\u0073',
  18882. '\u2103': '\u00B0\u0043',
  18883. '\u2105': '\u0063\u002F\u006F',
  18884. '\u2106': '\u0063\u002F\u0075',
  18885. '\u2107': '\u0190',
  18886. '\u2109': '\u00B0\u0046',
  18887. '\u2116': '\u004E\u006F',
  18888. '\u2121': '\u0054\u0045\u004C',
  18889. '\u2135': '\u05D0',
  18890. '\u2136': '\u05D1',
  18891. '\u2137': '\u05D2',
  18892. '\u2138': '\u05D3',
  18893. '\u213B': '\u0046\u0041\u0058',
  18894. '\u2160': '\u0049',
  18895. '\u2161': '\u0049\u0049',
  18896. '\u2162': '\u0049\u0049\u0049',
  18897. '\u2163': '\u0049\u0056',
  18898. '\u2164': '\u0056',
  18899. '\u2165': '\u0056\u0049',
  18900. '\u2166': '\u0056\u0049\u0049',
  18901. '\u2167': '\u0056\u0049\u0049\u0049',
  18902. '\u2168': '\u0049\u0058',
  18903. '\u2169': '\u0058',
  18904. '\u216A': '\u0058\u0049',
  18905. '\u216B': '\u0058\u0049\u0049',
  18906. '\u216C': '\u004C',
  18907. '\u216D': '\u0043',
  18908. '\u216E': '\u0044',
  18909. '\u216F': '\u004D',
  18910. '\u2170': '\u0069',
  18911. '\u2171': '\u0069\u0069',
  18912. '\u2172': '\u0069\u0069\u0069',
  18913. '\u2173': '\u0069\u0076',
  18914. '\u2174': '\u0076',
  18915. '\u2175': '\u0076\u0069',
  18916. '\u2176': '\u0076\u0069\u0069',
  18917. '\u2177': '\u0076\u0069\u0069\u0069',
  18918. '\u2178': '\u0069\u0078',
  18919. '\u2179': '\u0078',
  18920. '\u217A': '\u0078\u0069',
  18921. '\u217B': '\u0078\u0069\u0069',
  18922. '\u217C': '\u006C',
  18923. '\u217D': '\u0063',
  18924. '\u217E': '\u0064',
  18925. '\u217F': '\u006D',
  18926. '\u222C': '\u222B\u222B',
  18927. '\u222D': '\u222B\u222B\u222B',
  18928. '\u222F': '\u222E\u222E',
  18929. '\u2230': '\u222E\u222E\u222E',
  18930. '\u2474': '\u0028\u0031\u0029',
  18931. '\u2475': '\u0028\u0032\u0029',
  18932. '\u2476': '\u0028\u0033\u0029',
  18933. '\u2477': '\u0028\u0034\u0029',
  18934. '\u2478': '\u0028\u0035\u0029',
  18935. '\u2479': '\u0028\u0036\u0029',
  18936. '\u247A': '\u0028\u0037\u0029',
  18937. '\u247B': '\u0028\u0038\u0029',
  18938. '\u247C': '\u0028\u0039\u0029',
  18939. '\u247D': '\u0028\u0031\u0030\u0029',
  18940. '\u247E': '\u0028\u0031\u0031\u0029',
  18941. '\u247F': '\u0028\u0031\u0032\u0029',
  18942. '\u2480': '\u0028\u0031\u0033\u0029',
  18943. '\u2481': '\u0028\u0031\u0034\u0029',
  18944. '\u2482': '\u0028\u0031\u0035\u0029',
  18945. '\u2483': '\u0028\u0031\u0036\u0029',
  18946. '\u2484': '\u0028\u0031\u0037\u0029',
  18947. '\u2485': '\u0028\u0031\u0038\u0029',
  18948. '\u2486': '\u0028\u0031\u0039\u0029',
  18949. '\u2487': '\u0028\u0032\u0030\u0029',
  18950. '\u2488': '\u0031\u002E',
  18951. '\u2489': '\u0032\u002E',
  18952. '\u248A': '\u0033\u002E',
  18953. '\u248B': '\u0034\u002E',
  18954. '\u248C': '\u0035\u002E',
  18955. '\u248D': '\u0036\u002E',
  18956. '\u248E': '\u0037\u002E',
  18957. '\u248F': '\u0038\u002E',
  18958. '\u2490': '\u0039\u002E',
  18959. '\u2491': '\u0031\u0030\u002E',
  18960. '\u2492': '\u0031\u0031\u002E',
  18961. '\u2493': '\u0031\u0032\u002E',
  18962. '\u2494': '\u0031\u0033\u002E',
  18963. '\u2495': '\u0031\u0034\u002E',
  18964. '\u2496': '\u0031\u0035\u002E',
  18965. '\u2497': '\u0031\u0036\u002E',
  18966. '\u2498': '\u0031\u0037\u002E',
  18967. '\u2499': '\u0031\u0038\u002E',
  18968. '\u249A': '\u0031\u0039\u002E',
  18969. '\u249B': '\u0032\u0030\u002E',
  18970. '\u249C': '\u0028\u0061\u0029',
  18971. '\u249D': '\u0028\u0062\u0029',
  18972. '\u249E': '\u0028\u0063\u0029',
  18973. '\u249F': '\u0028\u0064\u0029',
  18974. '\u24A0': '\u0028\u0065\u0029',
  18975. '\u24A1': '\u0028\u0066\u0029',
  18976. '\u24A2': '\u0028\u0067\u0029',
  18977. '\u24A3': '\u0028\u0068\u0029',
  18978. '\u24A4': '\u0028\u0069\u0029',
  18979. '\u24A5': '\u0028\u006A\u0029',
  18980. '\u24A6': '\u0028\u006B\u0029',
  18981. '\u24A7': '\u0028\u006C\u0029',
  18982. '\u24A8': '\u0028\u006D\u0029',
  18983. '\u24A9': '\u0028\u006E\u0029',
  18984. '\u24AA': '\u0028\u006F\u0029',
  18985. '\u24AB': '\u0028\u0070\u0029',
  18986. '\u24AC': '\u0028\u0071\u0029',
  18987. '\u24AD': '\u0028\u0072\u0029',
  18988. '\u24AE': '\u0028\u0073\u0029',
  18989. '\u24AF': '\u0028\u0074\u0029',
  18990. '\u24B0': '\u0028\u0075\u0029',
  18991. '\u24B1': '\u0028\u0076\u0029',
  18992. '\u24B2': '\u0028\u0077\u0029',
  18993. '\u24B3': '\u0028\u0078\u0029',
  18994. '\u24B4': '\u0028\u0079\u0029',
  18995. '\u24B5': '\u0028\u007A\u0029',
  18996. '\u2A0C': '\u222B\u222B\u222B\u222B',
  18997. '\u2A74': '\u003A\u003A\u003D',
  18998. '\u2A75': '\u003D\u003D',
  18999. '\u2A76': '\u003D\u003D\u003D',
  19000. '\u2E9F': '\u6BCD',
  19001. '\u2EF3': '\u9F9F',
  19002. '\u2F00': '\u4E00',
  19003. '\u2F01': '\u4E28',
  19004. '\u2F02': '\u4E36',
  19005. '\u2F03': '\u4E3F',
  19006. '\u2F04': '\u4E59',
  19007. '\u2F05': '\u4E85',
  19008. '\u2F06': '\u4E8C',
  19009. '\u2F07': '\u4EA0',
  19010. '\u2F08': '\u4EBA',
  19011. '\u2F09': '\u513F',
  19012. '\u2F0A': '\u5165',
  19013. '\u2F0B': '\u516B',
  19014. '\u2F0C': '\u5182',
  19015. '\u2F0D': '\u5196',
  19016. '\u2F0E': '\u51AB',
  19017. '\u2F0F': '\u51E0',
  19018. '\u2F10': '\u51F5',
  19019. '\u2F11': '\u5200',
  19020. '\u2F12': '\u529B',
  19021. '\u2F13': '\u52F9',
  19022. '\u2F14': '\u5315',
  19023. '\u2F15': '\u531A',
  19024. '\u2F16': '\u5338',
  19025. '\u2F17': '\u5341',
  19026. '\u2F18': '\u535C',
  19027. '\u2F19': '\u5369',
  19028. '\u2F1A': '\u5382',
  19029. '\u2F1B': '\u53B6',
  19030. '\u2F1C': '\u53C8',
  19031. '\u2F1D': '\u53E3',
  19032. '\u2F1E': '\u56D7',
  19033. '\u2F1F': '\u571F',
  19034. '\u2F20': '\u58EB',
  19035. '\u2F21': '\u5902',
  19036. '\u2F22': '\u590A',
  19037. '\u2F23': '\u5915',
  19038. '\u2F24': '\u5927',
  19039. '\u2F25': '\u5973',
  19040. '\u2F26': '\u5B50',
  19041. '\u2F27': '\u5B80',
  19042. '\u2F28': '\u5BF8',
  19043. '\u2F29': '\u5C0F',
  19044. '\u2F2A': '\u5C22',
  19045. '\u2F2B': '\u5C38',
  19046. '\u2F2C': '\u5C6E',
  19047. '\u2F2D': '\u5C71',
  19048. '\u2F2E': '\u5DDB',
  19049. '\u2F2F': '\u5DE5',
  19050. '\u2F30': '\u5DF1',
  19051. '\u2F31': '\u5DFE',
  19052. '\u2F32': '\u5E72',
  19053. '\u2F33': '\u5E7A',
  19054. '\u2F34': '\u5E7F',
  19055. '\u2F35': '\u5EF4',
  19056. '\u2F36': '\u5EFE',
  19057. '\u2F37': '\u5F0B',
  19058. '\u2F38': '\u5F13',
  19059. '\u2F39': '\u5F50',
  19060. '\u2F3A': '\u5F61',
  19061. '\u2F3B': '\u5F73',
  19062. '\u2F3C': '\u5FC3',
  19063. '\u2F3D': '\u6208',
  19064. '\u2F3E': '\u6236',
  19065. '\u2F3F': '\u624B',
  19066. '\u2F40': '\u652F',
  19067. '\u2F41': '\u6534',
  19068. '\u2F42': '\u6587',
  19069. '\u2F43': '\u6597',
  19070. '\u2F44': '\u65A4',
  19071. '\u2F45': '\u65B9',
  19072. '\u2F46': '\u65E0',
  19073. '\u2F47': '\u65E5',
  19074. '\u2F48': '\u66F0',
  19075. '\u2F49': '\u6708',
  19076. '\u2F4A': '\u6728',
  19077. '\u2F4B': '\u6B20',
  19078. '\u2F4C': '\u6B62',
  19079. '\u2F4D': '\u6B79',
  19080. '\u2F4E': '\u6BB3',
  19081. '\u2F4F': '\u6BCB',
  19082. '\u2F50': '\u6BD4',
  19083. '\u2F51': '\u6BDB',
  19084. '\u2F52': '\u6C0F',
  19085. '\u2F53': '\u6C14',
  19086. '\u2F54': '\u6C34',
  19087. '\u2F55': '\u706B',
  19088. '\u2F56': '\u722A',
  19089. '\u2F57': '\u7236',
  19090. '\u2F58': '\u723B',
  19091. '\u2F59': '\u723F',
  19092. '\u2F5A': '\u7247',
  19093. '\u2F5B': '\u7259',
  19094. '\u2F5C': '\u725B',
  19095. '\u2F5D': '\u72AC',
  19096. '\u2F5E': '\u7384',
  19097. '\u2F5F': '\u7389',
  19098. '\u2F60': '\u74DC',
  19099. '\u2F61': '\u74E6',
  19100. '\u2F62': '\u7518',
  19101. '\u2F63': '\u751F',
  19102. '\u2F64': '\u7528',
  19103. '\u2F65': '\u7530',
  19104. '\u2F66': '\u758B',
  19105. '\u2F67': '\u7592',
  19106. '\u2F68': '\u7676',
  19107. '\u2F69': '\u767D',
  19108. '\u2F6A': '\u76AE',
  19109. '\u2F6B': '\u76BF',
  19110. '\u2F6C': '\u76EE',
  19111. '\u2F6D': '\u77DB',
  19112. '\u2F6E': '\u77E2',
  19113. '\u2F6F': '\u77F3',
  19114. '\u2F70': '\u793A',
  19115. '\u2F71': '\u79B8',
  19116. '\u2F72': '\u79BE',
  19117. '\u2F73': '\u7A74',
  19118. '\u2F74': '\u7ACB',
  19119. '\u2F75': '\u7AF9',
  19120. '\u2F76': '\u7C73',
  19121. '\u2F77': '\u7CF8',
  19122. '\u2F78': '\u7F36',
  19123. '\u2F79': '\u7F51',
  19124. '\u2F7A': '\u7F8A',
  19125. '\u2F7B': '\u7FBD',
  19126. '\u2F7C': '\u8001',
  19127. '\u2F7D': '\u800C',
  19128. '\u2F7E': '\u8012',
  19129. '\u2F7F': '\u8033',
  19130. '\u2F80': '\u807F',
  19131. '\u2F81': '\u8089',
  19132. '\u2F82': '\u81E3',
  19133. '\u2F83': '\u81EA',
  19134. '\u2F84': '\u81F3',
  19135. '\u2F85': '\u81FC',
  19136. '\u2F86': '\u820C',
  19137. '\u2F87': '\u821B',
  19138. '\u2F88': '\u821F',
  19139. '\u2F89': '\u826E',
  19140. '\u2F8A': '\u8272',
  19141. '\u2F8B': '\u8278',
  19142. '\u2F8C': '\u864D',
  19143. '\u2F8D': '\u866B',
  19144. '\u2F8E': '\u8840',
  19145. '\u2F8F': '\u884C',
  19146. '\u2F90': '\u8863',
  19147. '\u2F91': '\u897E',
  19148. '\u2F92': '\u898B',
  19149. '\u2F93': '\u89D2',
  19150. '\u2F94': '\u8A00',
  19151. '\u2F95': '\u8C37',
  19152. '\u2F96': '\u8C46',
  19153. '\u2F97': '\u8C55',
  19154. '\u2F98': '\u8C78',
  19155. '\u2F99': '\u8C9D',
  19156. '\u2F9A': '\u8D64',
  19157. '\u2F9B': '\u8D70',
  19158. '\u2F9C': '\u8DB3',
  19159. '\u2F9D': '\u8EAB',
  19160. '\u2F9E': '\u8ECA',
  19161. '\u2F9F': '\u8F9B',
  19162. '\u2FA0': '\u8FB0',
  19163. '\u2FA1': '\u8FB5',
  19164. '\u2FA2': '\u9091',
  19165. '\u2FA3': '\u9149',
  19166. '\u2FA4': '\u91C6',
  19167. '\u2FA5': '\u91CC',
  19168. '\u2FA6': '\u91D1',
  19169. '\u2FA7': '\u9577',
  19170. '\u2FA8': '\u9580',
  19171. '\u2FA9': '\u961C',
  19172. '\u2FAA': '\u96B6',
  19173. '\u2FAB': '\u96B9',
  19174. '\u2FAC': '\u96E8',
  19175. '\u2FAD': '\u9751',
  19176. '\u2FAE': '\u975E',
  19177. '\u2FAF': '\u9762',
  19178. '\u2FB0': '\u9769',
  19179. '\u2FB1': '\u97CB',
  19180. '\u2FB2': '\u97ED',
  19181. '\u2FB3': '\u97F3',
  19182. '\u2FB4': '\u9801',
  19183. '\u2FB5': '\u98A8',
  19184. '\u2FB6': '\u98DB',
  19185. '\u2FB7': '\u98DF',
  19186. '\u2FB8': '\u9996',
  19187. '\u2FB9': '\u9999',
  19188. '\u2FBA': '\u99AC',
  19189. '\u2FBB': '\u9AA8',
  19190. '\u2FBC': '\u9AD8',
  19191. '\u2FBD': '\u9ADF',
  19192. '\u2FBE': '\u9B25',
  19193. '\u2FBF': '\u9B2F',
  19194. '\u2FC0': '\u9B32',
  19195. '\u2FC1': '\u9B3C',
  19196. '\u2FC2': '\u9B5A',
  19197. '\u2FC3': '\u9CE5',
  19198. '\u2FC4': '\u9E75',
  19199. '\u2FC5': '\u9E7F',
  19200. '\u2FC6': '\u9EA5',
  19201. '\u2FC7': '\u9EBB',
  19202. '\u2FC8': '\u9EC3',
  19203. '\u2FC9': '\u9ECD',
  19204. '\u2FCA': '\u9ED1',
  19205. '\u2FCB': '\u9EF9',
  19206. '\u2FCC': '\u9EFD',
  19207. '\u2FCD': '\u9F0E',
  19208. '\u2FCE': '\u9F13',
  19209. '\u2FCF': '\u9F20',
  19210. '\u2FD0': '\u9F3B',
  19211. '\u2FD1': '\u9F4A',
  19212. '\u2FD2': '\u9F52',
  19213. '\u2FD3': '\u9F8D',
  19214. '\u2FD4': '\u9F9C',
  19215. '\u2FD5': '\u9FA0',
  19216. '\u3036': '\u3012',
  19217. '\u3038': '\u5341',
  19218. '\u3039': '\u5344',
  19219. '\u303A': '\u5345',
  19220. '\u309B': '\u0020\u3099',
  19221. '\u309C': '\u0020\u309A',
  19222. '\u3131': '\u1100',
  19223. '\u3132': '\u1101',
  19224. '\u3133': '\u11AA',
  19225. '\u3134': '\u1102',
  19226. '\u3135': '\u11AC',
  19227. '\u3136': '\u11AD',
  19228. '\u3137': '\u1103',
  19229. '\u3138': '\u1104',
  19230. '\u3139': '\u1105',
  19231. '\u313A': '\u11B0',
  19232. '\u313B': '\u11B1',
  19233. '\u313C': '\u11B2',
  19234. '\u313D': '\u11B3',
  19235. '\u313E': '\u11B4',
  19236. '\u313F': '\u11B5',
  19237. '\u3140': '\u111A',
  19238. '\u3141': '\u1106',
  19239. '\u3142': '\u1107',
  19240. '\u3143': '\u1108',
  19241. '\u3144': '\u1121',
  19242. '\u3145': '\u1109',
  19243. '\u3146': '\u110A',
  19244. '\u3147': '\u110B',
  19245. '\u3148': '\u110C',
  19246. '\u3149': '\u110D',
  19247. '\u314A': '\u110E',
  19248. '\u314B': '\u110F',
  19249. '\u314C': '\u1110',
  19250. '\u314D': '\u1111',
  19251. '\u314E': '\u1112',
  19252. '\u314F': '\u1161',
  19253. '\u3150': '\u1162',
  19254. '\u3151': '\u1163',
  19255. '\u3152': '\u1164',
  19256. '\u3153': '\u1165',
  19257. '\u3154': '\u1166',
  19258. '\u3155': '\u1167',
  19259. '\u3156': '\u1168',
  19260. '\u3157': '\u1169',
  19261. '\u3158': '\u116A',
  19262. '\u3159': '\u116B',
  19263. '\u315A': '\u116C',
  19264. '\u315B': '\u116D',
  19265. '\u315C': '\u116E',
  19266. '\u315D': '\u116F',
  19267. '\u315E': '\u1170',
  19268. '\u315F': '\u1171',
  19269. '\u3160': '\u1172',
  19270. '\u3161': '\u1173',
  19271. '\u3162': '\u1174',
  19272. '\u3163': '\u1175',
  19273. '\u3164': '\u1160',
  19274. '\u3165': '\u1114',
  19275. '\u3166': '\u1115',
  19276. '\u3167': '\u11C7',
  19277. '\u3168': '\u11C8',
  19278. '\u3169': '\u11CC',
  19279. '\u316A': '\u11CE',
  19280. '\u316B': '\u11D3',
  19281. '\u316C': '\u11D7',
  19282. '\u316D': '\u11D9',
  19283. '\u316E': '\u111C',
  19284. '\u316F': '\u11DD',
  19285. '\u3170': '\u11DF',
  19286. '\u3171': '\u111D',
  19287. '\u3172': '\u111E',
  19288. '\u3173': '\u1120',
  19289. '\u3174': '\u1122',
  19290. '\u3175': '\u1123',
  19291. '\u3176': '\u1127',
  19292. '\u3177': '\u1129',
  19293. '\u3178': '\u112B',
  19294. '\u3179': '\u112C',
  19295. '\u317A': '\u112D',
  19296. '\u317B': '\u112E',
  19297. '\u317C': '\u112F',
  19298. '\u317D': '\u1132',
  19299. '\u317E': '\u1136',
  19300. '\u317F': '\u1140',
  19301. '\u3180': '\u1147',
  19302. '\u3181': '\u114C',
  19303. '\u3182': '\u11F1',
  19304. '\u3183': '\u11F2',
  19305. '\u3184': '\u1157',
  19306. '\u3185': '\u1158',
  19307. '\u3186': '\u1159',
  19308. '\u3187': '\u1184',
  19309. '\u3188': '\u1185',
  19310. '\u3189': '\u1188',
  19311. '\u318A': '\u1191',
  19312. '\u318B': '\u1192',
  19313. '\u318C': '\u1194',
  19314. '\u318D': '\u119E',
  19315. '\u318E': '\u11A1',
  19316. '\u3200': '\u0028\u1100\u0029',
  19317. '\u3201': '\u0028\u1102\u0029',
  19318. '\u3202': '\u0028\u1103\u0029',
  19319. '\u3203': '\u0028\u1105\u0029',
  19320. '\u3204': '\u0028\u1106\u0029',
  19321. '\u3205': '\u0028\u1107\u0029',
  19322. '\u3206': '\u0028\u1109\u0029',
  19323. '\u3207': '\u0028\u110B\u0029',
  19324. '\u3208': '\u0028\u110C\u0029',
  19325. '\u3209': '\u0028\u110E\u0029',
  19326. '\u320A': '\u0028\u110F\u0029',
  19327. '\u320B': '\u0028\u1110\u0029',
  19328. '\u320C': '\u0028\u1111\u0029',
  19329. '\u320D': '\u0028\u1112\u0029',
  19330. '\u320E': '\u0028\u1100\u1161\u0029',
  19331. '\u320F': '\u0028\u1102\u1161\u0029',
  19332. '\u3210': '\u0028\u1103\u1161\u0029',
  19333. '\u3211': '\u0028\u1105\u1161\u0029',
  19334. '\u3212': '\u0028\u1106\u1161\u0029',
  19335. '\u3213': '\u0028\u1107\u1161\u0029',
  19336. '\u3214': '\u0028\u1109\u1161\u0029',
  19337. '\u3215': '\u0028\u110B\u1161\u0029',
  19338. '\u3216': '\u0028\u110C\u1161\u0029',
  19339. '\u3217': '\u0028\u110E\u1161\u0029',
  19340. '\u3218': '\u0028\u110F\u1161\u0029',
  19341. '\u3219': '\u0028\u1110\u1161\u0029',
  19342. '\u321A': '\u0028\u1111\u1161\u0029',
  19343. '\u321B': '\u0028\u1112\u1161\u0029',
  19344. '\u321C': '\u0028\u110C\u116E\u0029',
  19345. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19346. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19347. '\u3220': '\u0028\u4E00\u0029',
  19348. '\u3221': '\u0028\u4E8C\u0029',
  19349. '\u3222': '\u0028\u4E09\u0029',
  19350. '\u3223': '\u0028\u56DB\u0029',
  19351. '\u3224': '\u0028\u4E94\u0029',
  19352. '\u3225': '\u0028\u516D\u0029',
  19353. '\u3226': '\u0028\u4E03\u0029',
  19354. '\u3227': '\u0028\u516B\u0029',
  19355. '\u3228': '\u0028\u4E5D\u0029',
  19356. '\u3229': '\u0028\u5341\u0029',
  19357. '\u322A': '\u0028\u6708\u0029',
  19358. '\u322B': '\u0028\u706B\u0029',
  19359. '\u322C': '\u0028\u6C34\u0029',
  19360. '\u322D': '\u0028\u6728\u0029',
  19361. '\u322E': '\u0028\u91D1\u0029',
  19362. '\u322F': '\u0028\u571F\u0029',
  19363. '\u3230': '\u0028\u65E5\u0029',
  19364. '\u3231': '\u0028\u682A\u0029',
  19365. '\u3232': '\u0028\u6709\u0029',
  19366. '\u3233': '\u0028\u793E\u0029',
  19367. '\u3234': '\u0028\u540D\u0029',
  19368. '\u3235': '\u0028\u7279\u0029',
  19369. '\u3236': '\u0028\u8CA1\u0029',
  19370. '\u3237': '\u0028\u795D\u0029',
  19371. '\u3238': '\u0028\u52B4\u0029',
  19372. '\u3239': '\u0028\u4EE3\u0029',
  19373. '\u323A': '\u0028\u547C\u0029',
  19374. '\u323B': '\u0028\u5B66\u0029',
  19375. '\u323C': '\u0028\u76E3\u0029',
  19376. '\u323D': '\u0028\u4F01\u0029',
  19377. '\u323E': '\u0028\u8CC7\u0029',
  19378. '\u323F': '\u0028\u5354\u0029',
  19379. '\u3240': '\u0028\u796D\u0029',
  19380. '\u3241': '\u0028\u4F11\u0029',
  19381. '\u3242': '\u0028\u81EA\u0029',
  19382. '\u3243': '\u0028\u81F3\u0029',
  19383. '\u32C0': '\u0031\u6708',
  19384. '\u32C1': '\u0032\u6708',
  19385. '\u32C2': '\u0033\u6708',
  19386. '\u32C3': '\u0034\u6708',
  19387. '\u32C4': '\u0035\u6708',
  19388. '\u32C5': '\u0036\u6708',
  19389. '\u32C6': '\u0037\u6708',
  19390. '\u32C7': '\u0038\u6708',
  19391. '\u32C8': '\u0039\u6708',
  19392. '\u32C9': '\u0031\u0030\u6708',
  19393. '\u32CA': '\u0031\u0031\u6708',
  19394. '\u32CB': '\u0031\u0032\u6708',
  19395. '\u3358': '\u0030\u70B9',
  19396. '\u3359': '\u0031\u70B9',
  19397. '\u335A': '\u0032\u70B9',
  19398. '\u335B': '\u0033\u70B9',
  19399. '\u335C': '\u0034\u70B9',
  19400. '\u335D': '\u0035\u70B9',
  19401. '\u335E': '\u0036\u70B9',
  19402. '\u335F': '\u0037\u70B9',
  19403. '\u3360': '\u0038\u70B9',
  19404. '\u3361': '\u0039\u70B9',
  19405. '\u3362': '\u0031\u0030\u70B9',
  19406. '\u3363': '\u0031\u0031\u70B9',
  19407. '\u3364': '\u0031\u0032\u70B9',
  19408. '\u3365': '\u0031\u0033\u70B9',
  19409. '\u3366': '\u0031\u0034\u70B9',
  19410. '\u3367': '\u0031\u0035\u70B9',
  19411. '\u3368': '\u0031\u0036\u70B9',
  19412. '\u3369': '\u0031\u0037\u70B9',
  19413. '\u336A': '\u0031\u0038\u70B9',
  19414. '\u336B': '\u0031\u0039\u70B9',
  19415. '\u336C': '\u0032\u0030\u70B9',
  19416. '\u336D': '\u0032\u0031\u70B9',
  19417. '\u336E': '\u0032\u0032\u70B9',
  19418. '\u336F': '\u0032\u0033\u70B9',
  19419. '\u3370': '\u0032\u0034\u70B9',
  19420. '\u33E0': '\u0031\u65E5',
  19421. '\u33E1': '\u0032\u65E5',
  19422. '\u33E2': '\u0033\u65E5',
  19423. '\u33E3': '\u0034\u65E5',
  19424. '\u33E4': '\u0035\u65E5',
  19425. '\u33E5': '\u0036\u65E5',
  19426. '\u33E6': '\u0037\u65E5',
  19427. '\u33E7': '\u0038\u65E5',
  19428. '\u33E8': '\u0039\u65E5',
  19429. '\u33E9': '\u0031\u0030\u65E5',
  19430. '\u33EA': '\u0031\u0031\u65E5',
  19431. '\u33EB': '\u0031\u0032\u65E5',
  19432. '\u33EC': '\u0031\u0033\u65E5',
  19433. '\u33ED': '\u0031\u0034\u65E5',
  19434. '\u33EE': '\u0031\u0035\u65E5',
  19435. '\u33EF': '\u0031\u0036\u65E5',
  19436. '\u33F0': '\u0031\u0037\u65E5',
  19437. '\u33F1': '\u0031\u0038\u65E5',
  19438. '\u33F2': '\u0031\u0039\u65E5',
  19439. '\u33F3': '\u0032\u0030\u65E5',
  19440. '\u33F4': '\u0032\u0031\u65E5',
  19441. '\u33F5': '\u0032\u0032\u65E5',
  19442. '\u33F6': '\u0032\u0033\u65E5',
  19443. '\u33F7': '\u0032\u0034\u65E5',
  19444. '\u33F8': '\u0032\u0035\u65E5',
  19445. '\u33F9': '\u0032\u0036\u65E5',
  19446. '\u33FA': '\u0032\u0037\u65E5',
  19447. '\u33FB': '\u0032\u0038\u65E5',
  19448. '\u33FC': '\u0032\u0039\u65E5',
  19449. '\u33FD': '\u0033\u0030\u65E5',
  19450. '\u33FE': '\u0033\u0031\u65E5',
  19451. '\uFB00': '\u0066\u0066',
  19452. '\uFB01': '\u0066\u0069',
  19453. '\uFB02': '\u0066\u006C',
  19454. '\uFB03': '\u0066\u0066\u0069',
  19455. '\uFB04': '\u0066\u0066\u006C',
  19456. '\uFB05': '\u017F\u0074',
  19457. '\uFB06': '\u0073\u0074',
  19458. '\uFB13': '\u0574\u0576',
  19459. '\uFB14': '\u0574\u0565',
  19460. '\uFB15': '\u0574\u056B',
  19461. '\uFB16': '\u057E\u0576',
  19462. '\uFB17': '\u0574\u056D',
  19463. '\uFB4F': '\u05D0\u05DC',
  19464. '\uFB50': '\u0671',
  19465. '\uFB51': '\u0671',
  19466. '\uFB52': '\u067B',
  19467. '\uFB53': '\u067B',
  19468. '\uFB54': '\u067B',
  19469. '\uFB55': '\u067B',
  19470. '\uFB56': '\u067E',
  19471. '\uFB57': '\u067E',
  19472. '\uFB58': '\u067E',
  19473. '\uFB59': '\u067E',
  19474. '\uFB5A': '\u0680',
  19475. '\uFB5B': '\u0680',
  19476. '\uFB5C': '\u0680',
  19477. '\uFB5D': '\u0680',
  19478. '\uFB5E': '\u067A',
  19479. '\uFB5F': '\u067A',
  19480. '\uFB60': '\u067A',
  19481. '\uFB61': '\u067A',
  19482. '\uFB62': '\u067F',
  19483. '\uFB63': '\u067F',
  19484. '\uFB64': '\u067F',
  19485. '\uFB65': '\u067F',
  19486. '\uFB66': '\u0679',
  19487. '\uFB67': '\u0679',
  19488. '\uFB68': '\u0679',
  19489. '\uFB69': '\u0679',
  19490. '\uFB6A': '\u06A4',
  19491. '\uFB6B': '\u06A4',
  19492. '\uFB6C': '\u06A4',
  19493. '\uFB6D': '\u06A4',
  19494. '\uFB6E': '\u06A6',
  19495. '\uFB6F': '\u06A6',
  19496. '\uFB70': '\u06A6',
  19497. '\uFB71': '\u06A6',
  19498. '\uFB72': '\u0684',
  19499. '\uFB73': '\u0684',
  19500. '\uFB74': '\u0684',
  19501. '\uFB75': '\u0684',
  19502. '\uFB76': '\u0683',
  19503. '\uFB77': '\u0683',
  19504. '\uFB78': '\u0683',
  19505. '\uFB79': '\u0683',
  19506. '\uFB7A': '\u0686',
  19507. '\uFB7B': '\u0686',
  19508. '\uFB7C': '\u0686',
  19509. '\uFB7D': '\u0686',
  19510. '\uFB7E': '\u0687',
  19511. '\uFB7F': '\u0687',
  19512. '\uFB80': '\u0687',
  19513. '\uFB81': '\u0687',
  19514. '\uFB82': '\u068D',
  19515. '\uFB83': '\u068D',
  19516. '\uFB84': '\u068C',
  19517. '\uFB85': '\u068C',
  19518. '\uFB86': '\u068E',
  19519. '\uFB87': '\u068E',
  19520. '\uFB88': '\u0688',
  19521. '\uFB89': '\u0688',
  19522. '\uFB8A': '\u0698',
  19523. '\uFB8B': '\u0698',
  19524. '\uFB8C': '\u0691',
  19525. '\uFB8D': '\u0691',
  19526. '\uFB8E': '\u06A9',
  19527. '\uFB8F': '\u06A9',
  19528. '\uFB90': '\u06A9',
  19529. '\uFB91': '\u06A9',
  19530. '\uFB92': '\u06AF',
  19531. '\uFB93': '\u06AF',
  19532. '\uFB94': '\u06AF',
  19533. '\uFB95': '\u06AF',
  19534. '\uFB96': '\u06B3',
  19535. '\uFB97': '\u06B3',
  19536. '\uFB98': '\u06B3',
  19537. '\uFB99': '\u06B3',
  19538. '\uFB9A': '\u06B1',
  19539. '\uFB9B': '\u06B1',
  19540. '\uFB9C': '\u06B1',
  19541. '\uFB9D': '\u06B1',
  19542. '\uFB9E': '\u06BA',
  19543. '\uFB9F': '\u06BA',
  19544. '\uFBA0': '\u06BB',
  19545. '\uFBA1': '\u06BB',
  19546. '\uFBA2': '\u06BB',
  19547. '\uFBA3': '\u06BB',
  19548. '\uFBA4': '\u06C0',
  19549. '\uFBA5': '\u06C0',
  19550. '\uFBA6': '\u06C1',
  19551. '\uFBA7': '\u06C1',
  19552. '\uFBA8': '\u06C1',
  19553. '\uFBA9': '\u06C1',
  19554. '\uFBAA': '\u06BE',
  19555. '\uFBAB': '\u06BE',
  19556. '\uFBAC': '\u06BE',
  19557. '\uFBAD': '\u06BE',
  19558. '\uFBAE': '\u06D2',
  19559. '\uFBAF': '\u06D2',
  19560. '\uFBB0': '\u06D3',
  19561. '\uFBB1': '\u06D3',
  19562. '\uFBD3': '\u06AD',
  19563. '\uFBD4': '\u06AD',
  19564. '\uFBD5': '\u06AD',
  19565. '\uFBD6': '\u06AD',
  19566. '\uFBD7': '\u06C7',
  19567. '\uFBD8': '\u06C7',
  19568. '\uFBD9': '\u06C6',
  19569. '\uFBDA': '\u06C6',
  19570. '\uFBDB': '\u06C8',
  19571. '\uFBDC': '\u06C8',
  19572. '\uFBDD': '\u0677',
  19573. '\uFBDE': '\u06CB',
  19574. '\uFBDF': '\u06CB',
  19575. '\uFBE0': '\u06C5',
  19576. '\uFBE1': '\u06C5',
  19577. '\uFBE2': '\u06C9',
  19578. '\uFBE3': '\u06C9',
  19579. '\uFBE4': '\u06D0',
  19580. '\uFBE5': '\u06D0',
  19581. '\uFBE6': '\u06D0',
  19582. '\uFBE7': '\u06D0',
  19583. '\uFBE8': '\u0649',
  19584. '\uFBE9': '\u0649',
  19585. '\uFBEA': '\u0626\u0627',
  19586. '\uFBEB': '\u0626\u0627',
  19587. '\uFBEC': '\u0626\u06D5',
  19588. '\uFBED': '\u0626\u06D5',
  19589. '\uFBEE': '\u0626\u0648',
  19590. '\uFBEF': '\u0626\u0648',
  19591. '\uFBF0': '\u0626\u06C7',
  19592. '\uFBF1': '\u0626\u06C7',
  19593. '\uFBF2': '\u0626\u06C6',
  19594. '\uFBF3': '\u0626\u06C6',
  19595. '\uFBF4': '\u0626\u06C8',
  19596. '\uFBF5': '\u0626\u06C8',
  19597. '\uFBF6': '\u0626\u06D0',
  19598. '\uFBF7': '\u0626\u06D0',
  19599. '\uFBF8': '\u0626\u06D0',
  19600. '\uFBF9': '\u0626\u0649',
  19601. '\uFBFA': '\u0626\u0649',
  19602. '\uFBFB': '\u0626\u0649',
  19603. '\uFBFC': '\u06CC',
  19604. '\uFBFD': '\u06CC',
  19605. '\uFBFE': '\u06CC',
  19606. '\uFBFF': '\u06CC',
  19607. '\uFC00': '\u0626\u062C',
  19608. '\uFC01': '\u0626\u062D',
  19609. '\uFC02': '\u0626\u0645',
  19610. '\uFC03': '\u0626\u0649',
  19611. '\uFC04': '\u0626\u064A',
  19612. '\uFC05': '\u0628\u062C',
  19613. '\uFC06': '\u0628\u062D',
  19614. '\uFC07': '\u0628\u062E',
  19615. '\uFC08': '\u0628\u0645',
  19616. '\uFC09': '\u0628\u0649',
  19617. '\uFC0A': '\u0628\u064A',
  19618. '\uFC0B': '\u062A\u062C',
  19619. '\uFC0C': '\u062A\u062D',
  19620. '\uFC0D': '\u062A\u062E',
  19621. '\uFC0E': '\u062A\u0645',
  19622. '\uFC0F': '\u062A\u0649',
  19623. '\uFC10': '\u062A\u064A',
  19624. '\uFC11': '\u062B\u062C',
  19625. '\uFC12': '\u062B\u0645',
  19626. '\uFC13': '\u062B\u0649',
  19627. '\uFC14': '\u062B\u064A',
  19628. '\uFC15': '\u062C\u062D',
  19629. '\uFC16': '\u062C\u0645',
  19630. '\uFC17': '\u062D\u062C',
  19631. '\uFC18': '\u062D\u0645',
  19632. '\uFC19': '\u062E\u062C',
  19633. '\uFC1A': '\u062E\u062D',
  19634. '\uFC1B': '\u062E\u0645',
  19635. '\uFC1C': '\u0633\u062C',
  19636. '\uFC1D': '\u0633\u062D',
  19637. '\uFC1E': '\u0633\u062E',
  19638. '\uFC1F': '\u0633\u0645',
  19639. '\uFC20': '\u0635\u062D',
  19640. '\uFC21': '\u0635\u0645',
  19641. '\uFC22': '\u0636\u062C',
  19642. '\uFC23': '\u0636\u062D',
  19643. '\uFC24': '\u0636\u062E',
  19644. '\uFC25': '\u0636\u0645',
  19645. '\uFC26': '\u0637\u062D',
  19646. '\uFC27': '\u0637\u0645',
  19647. '\uFC28': '\u0638\u0645',
  19648. '\uFC29': '\u0639\u062C',
  19649. '\uFC2A': '\u0639\u0645',
  19650. '\uFC2B': '\u063A\u062C',
  19651. '\uFC2C': '\u063A\u0645',
  19652. '\uFC2D': '\u0641\u062C',
  19653. '\uFC2E': '\u0641\u062D',
  19654. '\uFC2F': '\u0641\u062E',
  19655. '\uFC30': '\u0641\u0645',
  19656. '\uFC31': '\u0641\u0649',
  19657. '\uFC32': '\u0641\u064A',
  19658. '\uFC33': '\u0642\u062D',
  19659. '\uFC34': '\u0642\u0645',
  19660. '\uFC35': '\u0642\u0649',
  19661. '\uFC36': '\u0642\u064A',
  19662. '\uFC37': '\u0643\u0627',
  19663. '\uFC38': '\u0643\u062C',
  19664. '\uFC39': '\u0643\u062D',
  19665. '\uFC3A': '\u0643\u062E',
  19666. '\uFC3B': '\u0643\u0644',
  19667. '\uFC3C': '\u0643\u0645',
  19668. '\uFC3D': '\u0643\u0649',
  19669. '\uFC3E': '\u0643\u064A',
  19670. '\uFC3F': '\u0644\u062C',
  19671. '\uFC40': '\u0644\u062D',
  19672. '\uFC41': '\u0644\u062E',
  19673. '\uFC42': '\u0644\u0645',
  19674. '\uFC43': '\u0644\u0649',
  19675. '\uFC44': '\u0644\u064A',
  19676. '\uFC45': '\u0645\u062C',
  19677. '\uFC46': '\u0645\u062D',
  19678. '\uFC47': '\u0645\u062E',
  19679. '\uFC48': '\u0645\u0645',
  19680. '\uFC49': '\u0645\u0649',
  19681. '\uFC4A': '\u0645\u064A',
  19682. '\uFC4B': '\u0646\u062C',
  19683. '\uFC4C': '\u0646\u062D',
  19684. '\uFC4D': '\u0646\u062E',
  19685. '\uFC4E': '\u0646\u0645',
  19686. '\uFC4F': '\u0646\u0649',
  19687. '\uFC50': '\u0646\u064A',
  19688. '\uFC51': '\u0647\u062C',
  19689. '\uFC52': '\u0647\u0645',
  19690. '\uFC53': '\u0647\u0649',
  19691. '\uFC54': '\u0647\u064A',
  19692. '\uFC55': '\u064A\u062C',
  19693. '\uFC56': '\u064A\u062D',
  19694. '\uFC57': '\u064A\u062E',
  19695. '\uFC58': '\u064A\u0645',
  19696. '\uFC59': '\u064A\u0649',
  19697. '\uFC5A': '\u064A\u064A',
  19698. '\uFC5B': '\u0630\u0670',
  19699. '\uFC5C': '\u0631\u0670',
  19700. '\uFC5D': '\u0649\u0670',
  19701. '\uFC5E': '\u0020\u064C\u0651',
  19702. '\uFC5F': '\u0020\u064D\u0651',
  19703. '\uFC60': '\u0020\u064E\u0651',
  19704. '\uFC61': '\u0020\u064F\u0651',
  19705. '\uFC62': '\u0020\u0650\u0651',
  19706. '\uFC63': '\u0020\u0651\u0670',
  19707. '\uFC64': '\u0626\u0631',
  19708. '\uFC65': '\u0626\u0632',
  19709. '\uFC66': '\u0626\u0645',
  19710. '\uFC67': '\u0626\u0646',
  19711. '\uFC68': '\u0626\u0649',
  19712. '\uFC69': '\u0626\u064A',
  19713. '\uFC6A': '\u0628\u0631',
  19714. '\uFC6B': '\u0628\u0632',
  19715. '\uFC6C': '\u0628\u0645',
  19716. '\uFC6D': '\u0628\u0646',
  19717. '\uFC6E': '\u0628\u0649',
  19718. '\uFC6F': '\u0628\u064A',
  19719. '\uFC70': '\u062A\u0631',
  19720. '\uFC71': '\u062A\u0632',
  19721. '\uFC72': '\u062A\u0645',
  19722. '\uFC73': '\u062A\u0646',
  19723. '\uFC74': '\u062A\u0649',
  19724. '\uFC75': '\u062A\u064A',
  19725. '\uFC76': '\u062B\u0631',
  19726. '\uFC77': '\u062B\u0632',
  19727. '\uFC78': '\u062B\u0645',
  19728. '\uFC79': '\u062B\u0646',
  19729. '\uFC7A': '\u062B\u0649',
  19730. '\uFC7B': '\u062B\u064A',
  19731. '\uFC7C': '\u0641\u0649',
  19732. '\uFC7D': '\u0641\u064A',
  19733. '\uFC7E': '\u0642\u0649',
  19734. '\uFC7F': '\u0642\u064A',
  19735. '\uFC80': '\u0643\u0627',
  19736. '\uFC81': '\u0643\u0644',
  19737. '\uFC82': '\u0643\u0645',
  19738. '\uFC83': '\u0643\u0649',
  19739. '\uFC84': '\u0643\u064A',
  19740. '\uFC85': '\u0644\u0645',
  19741. '\uFC86': '\u0644\u0649',
  19742. '\uFC87': '\u0644\u064A',
  19743. '\uFC88': '\u0645\u0627',
  19744. '\uFC89': '\u0645\u0645',
  19745. '\uFC8A': '\u0646\u0631',
  19746. '\uFC8B': '\u0646\u0632',
  19747. '\uFC8C': '\u0646\u0645',
  19748. '\uFC8D': '\u0646\u0646',
  19749. '\uFC8E': '\u0646\u0649',
  19750. '\uFC8F': '\u0646\u064A',
  19751. '\uFC90': '\u0649\u0670',
  19752. '\uFC91': '\u064A\u0631',
  19753. '\uFC92': '\u064A\u0632',
  19754. '\uFC93': '\u064A\u0645',
  19755. '\uFC94': '\u064A\u0646',
  19756. '\uFC95': '\u064A\u0649',
  19757. '\uFC96': '\u064A\u064A',
  19758. '\uFC97': '\u0626\u062C',
  19759. '\uFC98': '\u0626\u062D',
  19760. '\uFC99': '\u0626\u062E',
  19761. '\uFC9A': '\u0626\u0645',
  19762. '\uFC9B': '\u0626\u0647',
  19763. '\uFC9C': '\u0628\u062C',
  19764. '\uFC9D': '\u0628\u062D',
  19765. '\uFC9E': '\u0628\u062E',
  19766. '\uFC9F': '\u0628\u0645',
  19767. '\uFCA0': '\u0628\u0647',
  19768. '\uFCA1': '\u062A\u062C',
  19769. '\uFCA2': '\u062A\u062D',
  19770. '\uFCA3': '\u062A\u062E',
  19771. '\uFCA4': '\u062A\u0645',
  19772. '\uFCA5': '\u062A\u0647',
  19773. '\uFCA6': '\u062B\u0645',
  19774. '\uFCA7': '\u062C\u062D',
  19775. '\uFCA8': '\u062C\u0645',
  19776. '\uFCA9': '\u062D\u062C',
  19777. '\uFCAA': '\u062D\u0645',
  19778. '\uFCAB': '\u062E\u062C',
  19779. '\uFCAC': '\u062E\u0645',
  19780. '\uFCAD': '\u0633\u062C',
  19781. '\uFCAE': '\u0633\u062D',
  19782. '\uFCAF': '\u0633\u062E',
  19783. '\uFCB0': '\u0633\u0645',
  19784. '\uFCB1': '\u0635\u062D',
  19785. '\uFCB2': '\u0635\u062E',
  19786. '\uFCB3': '\u0635\u0645',
  19787. '\uFCB4': '\u0636\u062C',
  19788. '\uFCB5': '\u0636\u062D',
  19789. '\uFCB6': '\u0636\u062E',
  19790. '\uFCB7': '\u0636\u0645',
  19791. '\uFCB8': '\u0637\u062D',
  19792. '\uFCB9': '\u0638\u0645',
  19793. '\uFCBA': '\u0639\u062C',
  19794. '\uFCBB': '\u0639\u0645',
  19795. '\uFCBC': '\u063A\u062C',
  19796. '\uFCBD': '\u063A\u0645',
  19797. '\uFCBE': '\u0641\u062C',
  19798. '\uFCBF': '\u0641\u062D',
  19799. '\uFCC0': '\u0641\u062E',
  19800. '\uFCC1': '\u0641\u0645',
  19801. '\uFCC2': '\u0642\u062D',
  19802. '\uFCC3': '\u0642\u0645',
  19803. '\uFCC4': '\u0643\u062C',
  19804. '\uFCC5': '\u0643\u062D',
  19805. '\uFCC6': '\u0643\u062E',
  19806. '\uFCC7': '\u0643\u0644',
  19807. '\uFCC8': '\u0643\u0645',
  19808. '\uFCC9': '\u0644\u062C',
  19809. '\uFCCA': '\u0644\u062D',
  19810. '\uFCCB': '\u0644\u062E',
  19811. '\uFCCC': '\u0644\u0645',
  19812. '\uFCCD': '\u0644\u0647',
  19813. '\uFCCE': '\u0645\u062C',
  19814. '\uFCCF': '\u0645\u062D',
  19815. '\uFCD0': '\u0645\u062E',
  19816. '\uFCD1': '\u0645\u0645',
  19817. '\uFCD2': '\u0646\u062C',
  19818. '\uFCD3': '\u0646\u062D',
  19819. '\uFCD4': '\u0646\u062E',
  19820. '\uFCD5': '\u0646\u0645',
  19821. '\uFCD6': '\u0646\u0647',
  19822. '\uFCD7': '\u0647\u062C',
  19823. '\uFCD8': '\u0647\u0645',
  19824. '\uFCD9': '\u0647\u0670',
  19825. '\uFCDA': '\u064A\u062C',
  19826. '\uFCDB': '\u064A\u062D',
  19827. '\uFCDC': '\u064A\u062E',
  19828. '\uFCDD': '\u064A\u0645',
  19829. '\uFCDE': '\u064A\u0647',
  19830. '\uFCDF': '\u0626\u0645',
  19831. '\uFCE0': '\u0626\u0647',
  19832. '\uFCE1': '\u0628\u0645',
  19833. '\uFCE2': '\u0628\u0647',
  19834. '\uFCE3': '\u062A\u0645',
  19835. '\uFCE4': '\u062A\u0647',
  19836. '\uFCE5': '\u062B\u0645',
  19837. '\uFCE6': '\u062B\u0647',
  19838. '\uFCE7': '\u0633\u0645',
  19839. '\uFCE8': '\u0633\u0647',
  19840. '\uFCE9': '\u0634\u0645',
  19841. '\uFCEA': '\u0634\u0647',
  19842. '\uFCEB': '\u0643\u0644',
  19843. '\uFCEC': '\u0643\u0645',
  19844. '\uFCED': '\u0644\u0645',
  19845. '\uFCEE': '\u0646\u0645',
  19846. '\uFCEF': '\u0646\u0647',
  19847. '\uFCF0': '\u064A\u0645',
  19848. '\uFCF1': '\u064A\u0647',
  19849. '\uFCF2': '\u0640\u064E\u0651',
  19850. '\uFCF3': '\u0640\u064F\u0651',
  19851. '\uFCF4': '\u0640\u0650\u0651',
  19852. '\uFCF5': '\u0637\u0649',
  19853. '\uFCF6': '\u0637\u064A',
  19854. '\uFCF7': '\u0639\u0649',
  19855. '\uFCF8': '\u0639\u064A',
  19856. '\uFCF9': '\u063A\u0649',
  19857. '\uFCFA': '\u063A\u064A',
  19858. '\uFCFB': '\u0633\u0649',
  19859. '\uFCFC': '\u0633\u064A',
  19860. '\uFCFD': '\u0634\u0649',
  19861. '\uFCFE': '\u0634\u064A',
  19862. '\uFCFF': '\u062D\u0649',
  19863. '\uFD00': '\u062D\u064A',
  19864. '\uFD01': '\u062C\u0649',
  19865. '\uFD02': '\u062C\u064A',
  19866. '\uFD03': '\u062E\u0649',
  19867. '\uFD04': '\u062E\u064A',
  19868. '\uFD05': '\u0635\u0649',
  19869. '\uFD06': '\u0635\u064A',
  19870. '\uFD07': '\u0636\u0649',
  19871. '\uFD08': '\u0636\u064A',
  19872. '\uFD09': '\u0634\u062C',
  19873. '\uFD0A': '\u0634\u062D',
  19874. '\uFD0B': '\u0634\u062E',
  19875. '\uFD0C': '\u0634\u0645',
  19876. '\uFD0D': '\u0634\u0631',
  19877. '\uFD0E': '\u0633\u0631',
  19878. '\uFD0F': '\u0635\u0631',
  19879. '\uFD10': '\u0636\u0631',
  19880. '\uFD11': '\u0637\u0649',
  19881. '\uFD12': '\u0637\u064A',
  19882. '\uFD13': '\u0639\u0649',
  19883. '\uFD14': '\u0639\u064A',
  19884. '\uFD15': '\u063A\u0649',
  19885. '\uFD16': '\u063A\u064A',
  19886. '\uFD17': '\u0633\u0649',
  19887. '\uFD18': '\u0633\u064A',
  19888. '\uFD19': '\u0634\u0649',
  19889. '\uFD1A': '\u0634\u064A',
  19890. '\uFD1B': '\u062D\u0649',
  19891. '\uFD1C': '\u062D\u064A',
  19892. '\uFD1D': '\u062C\u0649',
  19893. '\uFD1E': '\u062C\u064A',
  19894. '\uFD1F': '\u062E\u0649',
  19895. '\uFD20': '\u062E\u064A',
  19896. '\uFD21': '\u0635\u0649',
  19897. '\uFD22': '\u0635\u064A',
  19898. '\uFD23': '\u0636\u0649',
  19899. '\uFD24': '\u0636\u064A',
  19900. '\uFD25': '\u0634\u062C',
  19901. '\uFD26': '\u0634\u062D',
  19902. '\uFD27': '\u0634\u062E',
  19903. '\uFD28': '\u0634\u0645',
  19904. '\uFD29': '\u0634\u0631',
  19905. '\uFD2A': '\u0633\u0631',
  19906. '\uFD2B': '\u0635\u0631',
  19907. '\uFD2C': '\u0636\u0631',
  19908. '\uFD2D': '\u0634\u062C',
  19909. '\uFD2E': '\u0634\u062D',
  19910. '\uFD2F': '\u0634\u062E',
  19911. '\uFD30': '\u0634\u0645',
  19912. '\uFD31': '\u0633\u0647',
  19913. '\uFD32': '\u0634\u0647',
  19914. '\uFD33': '\u0637\u0645',
  19915. '\uFD34': '\u0633\u062C',
  19916. '\uFD35': '\u0633\u062D',
  19917. '\uFD36': '\u0633\u062E',
  19918. '\uFD37': '\u0634\u062C',
  19919. '\uFD38': '\u0634\u062D',
  19920. '\uFD39': '\u0634\u062E',
  19921. '\uFD3A': '\u0637\u0645',
  19922. '\uFD3B': '\u0638\u0645',
  19923. '\uFD3C': '\u0627\u064B',
  19924. '\uFD3D': '\u0627\u064B',
  19925. '\uFD50': '\u062A\u062C\u0645',
  19926. '\uFD51': '\u062A\u062D\u062C',
  19927. '\uFD52': '\u062A\u062D\u062C',
  19928. '\uFD53': '\u062A\u062D\u0645',
  19929. '\uFD54': '\u062A\u062E\u0645',
  19930. '\uFD55': '\u062A\u0645\u062C',
  19931. '\uFD56': '\u062A\u0645\u062D',
  19932. '\uFD57': '\u062A\u0645\u062E',
  19933. '\uFD58': '\u062C\u0645\u062D',
  19934. '\uFD59': '\u062C\u0645\u062D',
  19935. '\uFD5A': '\u062D\u0645\u064A',
  19936. '\uFD5B': '\u062D\u0645\u0649',
  19937. '\uFD5C': '\u0633\u062D\u062C',
  19938. '\uFD5D': '\u0633\u062C\u062D',
  19939. '\uFD5E': '\u0633\u062C\u0649',
  19940. '\uFD5F': '\u0633\u0645\u062D',
  19941. '\uFD60': '\u0633\u0645\u062D',
  19942. '\uFD61': '\u0633\u0645\u062C',
  19943. '\uFD62': '\u0633\u0645\u0645',
  19944. '\uFD63': '\u0633\u0645\u0645',
  19945. '\uFD64': '\u0635\u062D\u062D',
  19946. '\uFD65': '\u0635\u062D\u062D',
  19947. '\uFD66': '\u0635\u0645\u0645',
  19948. '\uFD67': '\u0634\u062D\u0645',
  19949. '\uFD68': '\u0634\u062D\u0645',
  19950. '\uFD69': '\u0634\u062C\u064A',
  19951. '\uFD6A': '\u0634\u0645\u062E',
  19952. '\uFD6B': '\u0634\u0645\u062E',
  19953. '\uFD6C': '\u0634\u0645\u0645',
  19954. '\uFD6D': '\u0634\u0645\u0645',
  19955. '\uFD6E': '\u0636\u062D\u0649',
  19956. '\uFD6F': '\u0636\u062E\u0645',
  19957. '\uFD70': '\u0636\u062E\u0645',
  19958. '\uFD71': '\u0637\u0645\u062D',
  19959. '\uFD72': '\u0637\u0645\u062D',
  19960. '\uFD73': '\u0637\u0645\u0645',
  19961. '\uFD74': '\u0637\u0645\u064A',
  19962. '\uFD75': '\u0639\u062C\u0645',
  19963. '\uFD76': '\u0639\u0645\u0645',
  19964. '\uFD77': '\u0639\u0645\u0645',
  19965. '\uFD78': '\u0639\u0645\u0649',
  19966. '\uFD79': '\u063A\u0645\u0645',
  19967. '\uFD7A': '\u063A\u0645\u064A',
  19968. '\uFD7B': '\u063A\u0645\u0649',
  19969. '\uFD7C': '\u0641\u062E\u0645',
  19970. '\uFD7D': '\u0641\u062E\u0645',
  19971. '\uFD7E': '\u0642\u0645\u062D',
  19972. '\uFD7F': '\u0642\u0645\u0645',
  19973. '\uFD80': '\u0644\u062D\u0645',
  19974. '\uFD81': '\u0644\u062D\u064A',
  19975. '\uFD82': '\u0644\u062D\u0649',
  19976. '\uFD83': '\u0644\u062C\u062C',
  19977. '\uFD84': '\u0644\u062C\u062C',
  19978. '\uFD85': '\u0644\u062E\u0645',
  19979. '\uFD86': '\u0644\u062E\u0645',
  19980. '\uFD87': '\u0644\u0645\u062D',
  19981. '\uFD88': '\u0644\u0645\u062D',
  19982. '\uFD89': '\u0645\u062D\u062C',
  19983. '\uFD8A': '\u0645\u062D\u0645',
  19984. '\uFD8B': '\u0645\u062D\u064A',
  19985. '\uFD8C': '\u0645\u062C\u062D',
  19986. '\uFD8D': '\u0645\u062C\u0645',
  19987. '\uFD8E': '\u0645\u062E\u062C',
  19988. '\uFD8F': '\u0645\u062E\u0645',
  19989. '\uFD92': '\u0645\u062C\u062E',
  19990. '\uFD93': '\u0647\u0645\u062C',
  19991. '\uFD94': '\u0647\u0645\u0645',
  19992. '\uFD95': '\u0646\u062D\u0645',
  19993. '\uFD96': '\u0646\u062D\u0649',
  19994. '\uFD97': '\u0646\u062C\u0645',
  19995. '\uFD98': '\u0646\u062C\u0645',
  19996. '\uFD99': '\u0646\u062C\u0649',
  19997. '\uFD9A': '\u0646\u0645\u064A',
  19998. '\uFD9B': '\u0646\u0645\u0649',
  19999. '\uFD9C': '\u064A\u0645\u0645',
  20000. '\uFD9D': '\u064A\u0645\u0645',
  20001. '\uFD9E': '\u0628\u062E\u064A',
  20002. '\uFD9F': '\u062A\u062C\u064A',
  20003. '\uFDA0': '\u062A\u062C\u0649',
  20004. '\uFDA1': '\u062A\u062E\u064A',
  20005. '\uFDA2': '\u062A\u062E\u0649',
  20006. '\uFDA3': '\u062A\u0645\u064A',
  20007. '\uFDA4': '\u062A\u0645\u0649',
  20008. '\uFDA5': '\u062C\u0645\u064A',
  20009. '\uFDA6': '\u062C\u062D\u0649',
  20010. '\uFDA7': '\u062C\u0645\u0649',
  20011. '\uFDA8': '\u0633\u062E\u0649',
  20012. '\uFDA9': '\u0635\u062D\u064A',
  20013. '\uFDAA': '\u0634\u062D\u064A',
  20014. '\uFDAB': '\u0636\u062D\u064A',
  20015. '\uFDAC': '\u0644\u062C\u064A',
  20016. '\uFDAD': '\u0644\u0645\u064A',
  20017. '\uFDAE': '\u064A\u062D\u064A',
  20018. '\uFDAF': '\u064A\u062C\u064A',
  20019. '\uFDB0': '\u064A\u0645\u064A',
  20020. '\uFDB1': '\u0645\u0645\u064A',
  20021. '\uFDB2': '\u0642\u0645\u064A',
  20022. '\uFDB3': '\u0646\u062D\u064A',
  20023. '\uFDB4': '\u0642\u0645\u062D',
  20024. '\uFDB5': '\u0644\u062D\u0645',
  20025. '\uFDB6': '\u0639\u0645\u064A',
  20026. '\uFDB7': '\u0643\u0645\u064A',
  20027. '\uFDB8': '\u0646\u062C\u062D',
  20028. '\uFDB9': '\u0645\u062E\u064A',
  20029. '\uFDBA': '\u0644\u062C\u0645',
  20030. '\uFDBB': '\u0643\u0645\u0645',
  20031. '\uFDBC': '\u0644\u062C\u0645',
  20032. '\uFDBD': '\u0646\u062C\u062D',
  20033. '\uFDBE': '\u062C\u062D\u064A',
  20034. '\uFDBF': '\u062D\u062C\u064A',
  20035. '\uFDC0': '\u0645\u062C\u064A',
  20036. '\uFDC1': '\u0641\u0645\u064A',
  20037. '\uFDC2': '\u0628\u062D\u064A',
  20038. '\uFDC3': '\u0643\u0645\u0645',
  20039. '\uFDC4': '\u0639\u062C\u0645',
  20040. '\uFDC5': '\u0635\u0645\u0645',
  20041. '\uFDC6': '\u0633\u062E\u064A',
  20042. '\uFDC7': '\u0646\u062C\u064A',
  20043. '\uFE49': '\u203E',
  20044. '\uFE4A': '\u203E',
  20045. '\uFE4B': '\u203E',
  20046. '\uFE4C': '\u203E',
  20047. '\uFE4D': '\u005F',
  20048. '\uFE4E': '\u005F',
  20049. '\uFE4F': '\u005F',
  20050. '\uFE80': '\u0621',
  20051. '\uFE81': '\u0622',
  20052. '\uFE82': '\u0622',
  20053. '\uFE83': '\u0623',
  20054. '\uFE84': '\u0623',
  20055. '\uFE85': '\u0624',
  20056. '\uFE86': '\u0624',
  20057. '\uFE87': '\u0625',
  20058. '\uFE88': '\u0625',
  20059. '\uFE89': '\u0626',
  20060. '\uFE8A': '\u0626',
  20061. '\uFE8B': '\u0626',
  20062. '\uFE8C': '\u0626',
  20063. '\uFE8D': '\u0627',
  20064. '\uFE8E': '\u0627',
  20065. '\uFE8F': '\u0628',
  20066. '\uFE90': '\u0628',
  20067. '\uFE91': '\u0628',
  20068. '\uFE92': '\u0628',
  20069. '\uFE93': '\u0629',
  20070. '\uFE94': '\u0629',
  20071. '\uFE95': '\u062A',
  20072. '\uFE96': '\u062A',
  20073. '\uFE97': '\u062A',
  20074. '\uFE98': '\u062A',
  20075. '\uFE99': '\u062B',
  20076. '\uFE9A': '\u062B',
  20077. '\uFE9B': '\u062B',
  20078. '\uFE9C': '\u062B',
  20079. '\uFE9D': '\u062C',
  20080. '\uFE9E': '\u062C',
  20081. '\uFE9F': '\u062C',
  20082. '\uFEA0': '\u062C',
  20083. '\uFEA1': '\u062D',
  20084. '\uFEA2': '\u062D',
  20085. '\uFEA3': '\u062D',
  20086. '\uFEA4': '\u062D',
  20087. '\uFEA5': '\u062E',
  20088. '\uFEA6': '\u062E',
  20089. '\uFEA7': '\u062E',
  20090. '\uFEA8': '\u062E',
  20091. '\uFEA9': '\u062F',
  20092. '\uFEAA': '\u062F',
  20093. '\uFEAB': '\u0630',
  20094. '\uFEAC': '\u0630',
  20095. '\uFEAD': '\u0631',
  20096. '\uFEAE': '\u0631',
  20097. '\uFEAF': '\u0632',
  20098. '\uFEB0': '\u0632',
  20099. '\uFEB1': '\u0633',
  20100. '\uFEB2': '\u0633',
  20101. '\uFEB3': '\u0633',
  20102. '\uFEB4': '\u0633',
  20103. '\uFEB5': '\u0634',
  20104. '\uFEB6': '\u0634',
  20105. '\uFEB7': '\u0634',
  20106. '\uFEB8': '\u0634',
  20107. '\uFEB9': '\u0635',
  20108. '\uFEBA': '\u0635',
  20109. '\uFEBB': '\u0635',
  20110. '\uFEBC': '\u0635',
  20111. '\uFEBD': '\u0636',
  20112. '\uFEBE': '\u0636',
  20113. '\uFEBF': '\u0636',
  20114. '\uFEC0': '\u0636',
  20115. '\uFEC1': '\u0637',
  20116. '\uFEC2': '\u0637',
  20117. '\uFEC3': '\u0637',
  20118. '\uFEC4': '\u0637',
  20119. '\uFEC5': '\u0638',
  20120. '\uFEC6': '\u0638',
  20121. '\uFEC7': '\u0638',
  20122. '\uFEC8': '\u0638',
  20123. '\uFEC9': '\u0639',
  20124. '\uFECA': '\u0639',
  20125. '\uFECB': '\u0639',
  20126. '\uFECC': '\u0639',
  20127. '\uFECD': '\u063A',
  20128. '\uFECE': '\u063A',
  20129. '\uFECF': '\u063A',
  20130. '\uFED0': '\u063A',
  20131. '\uFED1': '\u0641',
  20132. '\uFED2': '\u0641',
  20133. '\uFED3': '\u0641',
  20134. '\uFED4': '\u0641',
  20135. '\uFED5': '\u0642',
  20136. '\uFED6': '\u0642',
  20137. '\uFED7': '\u0642',
  20138. '\uFED8': '\u0642',
  20139. '\uFED9': '\u0643',
  20140. '\uFEDA': '\u0643',
  20141. '\uFEDB': '\u0643',
  20142. '\uFEDC': '\u0643',
  20143. '\uFEDD': '\u0644',
  20144. '\uFEDE': '\u0644',
  20145. '\uFEDF': '\u0644',
  20146. '\uFEE0': '\u0644',
  20147. '\uFEE1': '\u0645',
  20148. '\uFEE2': '\u0645',
  20149. '\uFEE3': '\u0645',
  20150. '\uFEE4': '\u0645',
  20151. '\uFEE5': '\u0646',
  20152. '\uFEE6': '\u0646',
  20153. '\uFEE7': '\u0646',
  20154. '\uFEE8': '\u0646',
  20155. '\uFEE9': '\u0647',
  20156. '\uFEEA': '\u0647',
  20157. '\uFEEB': '\u0647',
  20158. '\uFEEC': '\u0647',
  20159. '\uFEED': '\u0648',
  20160. '\uFEEE': '\u0648',
  20161. '\uFEEF': '\u0649',
  20162. '\uFEF0': '\u0649',
  20163. '\uFEF1': '\u064A',
  20164. '\uFEF2': '\u064A',
  20165. '\uFEF3': '\u064A',
  20166. '\uFEF4': '\u064A',
  20167. '\uFEF5': '\u0644\u0622',
  20168. '\uFEF6': '\u0644\u0622',
  20169. '\uFEF7': '\u0644\u0623',
  20170. '\uFEF8': '\u0644\u0623',
  20171. '\uFEF9': '\u0644\u0625',
  20172. '\uFEFA': '\u0644\u0625',
  20173. '\uFEFB': '\u0644\u0627',
  20174. '\uFEFC': '\u0644\u0627'
  20175. };
  20176. function reverseIfRtl(chars) {
  20177. var charsLength = chars.length;
  20178. //reverse an arabic ligature
  20179. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20180. return chars;
  20181. }
  20182. var s = '';
  20183. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20184. s += chars[ii];
  20185. }
  20186. return s;
  20187. }
  20188. function adjustWidths(properties) {
  20189. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20190. return;
  20191. }
  20192. // adjusting width to fontMatrix scale
  20193. var scale = 0.001 / properties.fontMatrix[0];
  20194. var glyphsWidths = properties.widths;
  20195. for (var glyph in glyphsWidths) {
  20196. glyphsWidths[glyph] *= scale;
  20197. }
  20198. properties.defaultWidth *= scale;
  20199. }
  20200. function getFontType(type, subtype) {
  20201. switch (type) {
  20202. case 'Type1':
  20203. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20204. case 'CIDFontType0':
  20205. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20206. FontType.CIDFONTTYPE0;
  20207. case 'OpenType':
  20208. return FontType.OPENTYPE;
  20209. case 'TrueType':
  20210. return FontType.TRUETYPE;
  20211. case 'CIDFontType2':
  20212. return FontType.CIDFONTTYPE2;
  20213. case 'MMType1':
  20214. return FontType.MMTYPE1;
  20215. case 'Type0':
  20216. return FontType.TYPE0;
  20217. default:
  20218. return FontType.UNKNOWN;
  20219. }
  20220. }
  20221. var Glyph = (function GlyphClosure() {
  20222. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20223. this.fontChar = fontChar;
  20224. this.unicode = unicode;
  20225. this.accent = accent;
  20226. this.width = width;
  20227. this.vmetric = vmetric;
  20228. this.operatorListId = operatorListId;
  20229. }
  20230. Glyph.prototype.matchesForCache =
  20231. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20232. return this.fontChar === fontChar &&
  20233. this.unicode === unicode &&
  20234. this.accent === accent &&
  20235. this.width === width &&
  20236. this.vmetric === vmetric &&
  20237. this.operatorListId === operatorListId;
  20238. };
  20239. return Glyph;
  20240. })();
  20241. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20242. function ToUnicodeMap(cmap) {
  20243. // The elements of this._map can be integers or strings, depending on how
  20244. // |cmap| was created.
  20245. this._map = cmap;
  20246. }
  20247. ToUnicodeMap.prototype = {
  20248. get length() {
  20249. return this._map.length;
  20250. },
  20251. forEach: function(callback) {
  20252. for (var charCode in this._map) {
  20253. callback(charCode, this._map[charCode].charCodeAt(0));
  20254. }
  20255. },
  20256. get: function(i) {
  20257. return this._map[i];
  20258. },
  20259. charCodeOf: function(v) {
  20260. return this._map.indexOf(v);
  20261. }
  20262. };
  20263. return ToUnicodeMap;
  20264. })();
  20265. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20266. function IdentityToUnicodeMap(firstChar, lastChar) {
  20267. this.firstChar = firstChar;
  20268. this.lastChar = lastChar;
  20269. }
  20270. IdentityToUnicodeMap.prototype = {
  20271. get length() {
  20272. error('should not access .length');
  20273. },
  20274. forEach: function (callback) {
  20275. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20276. callback(i, i);
  20277. }
  20278. },
  20279. get: function (i) {
  20280. if (this.firstChar <= i && i <= this.lastChar) {
  20281. return String.fromCharCode(i);
  20282. }
  20283. return undefined;
  20284. },
  20285. charCodeOf: function (v) {
  20286. error('should not call .charCodeOf');
  20287. }
  20288. };
  20289. return IdentityToUnicodeMap;
  20290. })();
  20291. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20292. function writeInt16(dest, offset, num) {
  20293. dest[offset] = (num >> 8) & 0xFF;
  20294. dest[offset + 1] = num & 0xFF;
  20295. }
  20296. function writeInt32(dest, offset, num) {
  20297. dest[offset] = (num >> 24) & 0xFF;
  20298. dest[offset + 1] = (num >> 16) & 0xFF;
  20299. dest[offset + 2] = (num >> 8) & 0xFF;
  20300. dest[offset + 3] = num & 0xFF;
  20301. }
  20302. function writeData(dest, offset, data) {
  20303. var i, ii;
  20304. if (data instanceof Uint8Array) {
  20305. dest.set(data, offset);
  20306. } else if (typeof data === 'string') {
  20307. for (i = 0, ii = data.length; i < ii; i++) {
  20308. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20309. }
  20310. } else {
  20311. // treating everything else as array
  20312. for (i = 0, ii = data.length; i < ii; i++) {
  20313. dest[offset++] = data[i] & 0xFF;
  20314. }
  20315. }
  20316. }
  20317. function OpenTypeFileBuilder(sfnt) {
  20318. this.sfnt = sfnt;
  20319. this.tables = Object.create(null);
  20320. }
  20321. OpenTypeFileBuilder.getSearchParams =
  20322. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20323. var maxPower2 = 1, log2 = 0;
  20324. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20325. maxPower2 <<= 1;
  20326. log2++;
  20327. }
  20328. var searchRange = maxPower2 * entrySize;
  20329. return {
  20330. range: searchRange,
  20331. entry: log2,
  20332. rangeShift: entrySize * entriesCount - searchRange
  20333. };
  20334. };
  20335. var OTF_HEADER_SIZE = 12;
  20336. var OTF_TABLE_ENTRY_SIZE = 16;
  20337. OpenTypeFileBuilder.prototype = {
  20338. toArray: function OpenTypeFileBuilder_toArray() {
  20339. var sfnt = this.sfnt;
  20340. // Tables needs to be written by ascendant alphabetic order
  20341. var tables = this.tables;
  20342. var tablesNames = Object.keys(tables);
  20343. tablesNames.sort();
  20344. var numTables = tablesNames.length;
  20345. var i, j, jj, table, tableName;
  20346. // layout the tables data
  20347. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20348. var tableOffsets = [offset];
  20349. for (i = 0; i < numTables; i++) {
  20350. table = tables[tablesNames[i]];
  20351. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20352. offset += paddedLength;
  20353. tableOffsets.push(offset);
  20354. }
  20355. var file = new Uint8Array(offset);
  20356. // write the table data first (mostly for checksum)
  20357. for (i = 0; i < numTables; i++) {
  20358. table = tables[tablesNames[i]];
  20359. writeData(file, tableOffsets[i], table);
  20360. }
  20361. // sfnt version (4 bytes)
  20362. if (sfnt === 'true') {
  20363. // Windows hates the Mac TrueType sfnt version number
  20364. sfnt = string32(0x00010000);
  20365. }
  20366. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20367. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20368. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20369. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20370. // numTables (2 bytes)
  20371. writeInt16(file, 4, numTables);
  20372. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20373. // searchRange (2 bytes)
  20374. writeInt16(file, 6, searchParams.range);
  20375. // entrySelector (2 bytes)
  20376. writeInt16(file, 8, searchParams.entry);
  20377. // rangeShift (2 bytes)
  20378. writeInt16(file, 10, searchParams.rangeShift);
  20379. offset = OTF_HEADER_SIZE;
  20380. // writing table entries
  20381. for (i = 0; i < numTables; i++) {
  20382. tableName = tablesNames[i];
  20383. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20384. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20385. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20386. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20387. // checksum
  20388. var checksum = 0;
  20389. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20390. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20391. (file[j + 2] << 8) + file[j + 3];
  20392. checksum = (checksum + quad) | 0;
  20393. }
  20394. writeInt32(file, offset + 4, checksum);
  20395. // offset
  20396. writeInt32(file, offset + 8, tableOffsets[i]);
  20397. // length
  20398. writeInt32(file, offset + 12, tables[tableName].length);
  20399. offset += OTF_TABLE_ENTRY_SIZE;
  20400. }
  20401. return file;
  20402. },
  20403. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20404. if (tag in this.tables) {
  20405. throw new Error('Table ' + tag + ' already exists');
  20406. }
  20407. this.tables[tag] = data;
  20408. }
  20409. };
  20410. return OpenTypeFileBuilder;
  20411. })();
  20412. /**
  20413. * 'Font' is the class the outside world should use, it encapsulate all the font
  20414. * decoding logics whatever type it is (assuming the font type is supported).
  20415. *
  20416. * For example to read a Type1 font and to attach it to the document:
  20417. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20418. * type1Font.bind();
  20419. */
  20420. var Font = (function FontClosure() {
  20421. function Font(name, file, properties) {
  20422. var charCode, glyphName, fontChar;
  20423. this.name = name;
  20424. this.loadedName = properties.loadedName;
  20425. this.isType3Font = properties.isType3Font;
  20426. this.sizes = [];
  20427. this.glyphCache = {};
  20428. var names = name.split('+');
  20429. names = names.length > 1 ? names[1] : names[0];
  20430. names = names.split(/[-,_]/g)[0];
  20431. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20432. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20433. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20434. var type = properties.type;
  20435. var subtype = properties.subtype;
  20436. this.type = type;
  20437. this.fallbackName = (this.isMonospace ? 'monospace' :
  20438. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20439. this.differences = properties.differences;
  20440. this.widths = properties.widths;
  20441. this.defaultWidth = properties.defaultWidth;
  20442. this.composite = properties.composite;
  20443. this.wideChars = properties.wideChars;
  20444. this.cMap = properties.cMap;
  20445. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20446. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20447. this.fontMatrix = properties.fontMatrix;
  20448. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20449. this.toFontChar = [];
  20450. if (properties.type === 'Type3') {
  20451. for (charCode = 0; charCode < 256; charCode++) {
  20452. this.toFontChar[charCode] = (this.differences[charCode] ||
  20453. properties.defaultEncoding[charCode]);
  20454. }
  20455. this.fontType = FontType.TYPE3;
  20456. return;
  20457. }
  20458. this.cidEncoding = properties.cidEncoding;
  20459. this.vertical = properties.vertical;
  20460. if (this.vertical) {
  20461. this.vmetrics = properties.vmetrics;
  20462. this.defaultVMetrics = properties.defaultVMetrics;
  20463. }
  20464. if (!file || file.isEmpty) {
  20465. if (file) {
  20466. // Some bad PDF generators will include empty font files,
  20467. // attempting to recover by assuming that no file exists.
  20468. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20469. }
  20470. this.missingFile = true;
  20471. // The file data is not specified. Trying to fix the font name
  20472. // to be used with the canvas.font.
  20473. var fontName = name.replace(/[,_]/g, '-');
  20474. var isStandardFont = fontName in stdFontMap;
  20475. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20476. this.bold = (fontName.search(/bold/gi) !== -1);
  20477. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20478. (fontName.search(/italic/gi) !== -1));
  20479. // Use 'name' instead of 'fontName' here because the original
  20480. // name ArialBlack for example will be replaced by Helvetica.
  20481. this.black = (name.search(/Black/g) !== -1);
  20482. // if at least one width is present, remeasure all chars when exists
  20483. this.remeasure = Object.keys(this.widths).length > 0;
  20484. if (isStandardFont && type === 'CIDFontType2' &&
  20485. properties.cidEncoding.indexOf('Identity-') === 0) {
  20486. // Standard fonts might be embedded as CID font without glyph mapping.
  20487. // Building one based on GlyphMapForStandardFonts.
  20488. var map = [];
  20489. for (var code in GlyphMapForStandardFonts) {
  20490. map[+code] = GlyphMapForStandardFonts[code];
  20491. }
  20492. this.toFontChar = map;
  20493. this.toUnicode = new ToUnicodeMap(map);
  20494. } else if (/Symbol/i.test(fontName)) {
  20495. var symbols = Encodings.SymbolSetEncoding;
  20496. for (charCode in symbols) {
  20497. fontChar = GlyphsUnicode[symbols[charCode]];
  20498. if (!fontChar) {
  20499. continue;
  20500. }
  20501. this.toFontChar[charCode] = fontChar;
  20502. }
  20503. for (charCode in properties.differences) {
  20504. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20505. if (!fontChar) {
  20506. continue;
  20507. }
  20508. this.toFontChar[charCode] = fontChar;
  20509. }
  20510. } else if (/Dingbats/i.test(fontName)) {
  20511. var dingbats = Encodings.ZapfDingbatsEncoding;
  20512. for (charCode in dingbats) {
  20513. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20514. if (!fontChar) {
  20515. continue;
  20516. }
  20517. this.toFontChar[charCode] = fontChar;
  20518. }
  20519. for (charCode in properties.differences) {
  20520. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20521. if (!fontChar) {
  20522. continue;
  20523. }
  20524. this.toFontChar[charCode] = fontChar;
  20525. }
  20526. } else if (isStandardFont) {
  20527. this.toFontChar = [];
  20528. for (charCode in properties.defaultEncoding) {
  20529. glyphName = (properties.differences[charCode] ||
  20530. properties.defaultEncoding[charCode]);
  20531. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20532. }
  20533. } else {
  20534. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20535. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20536. if (notCidFont) {
  20537. glyphName = (properties.differences[charCode] ||
  20538. properties.defaultEncoding[charCode]);
  20539. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20540. }
  20541. this.toFontChar[charCode] = unicodeCharCode;
  20542. }.bind(this));
  20543. }
  20544. this.loadedName = fontName.split('-')[0];
  20545. this.loading = false;
  20546. this.fontType = getFontType(type, subtype);
  20547. return;
  20548. }
  20549. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20550. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20551. // Some TrueType fonts by mistake claim Type1C
  20552. if (isTrueTypeFile(file)) {
  20553. subtype = 'TrueType';
  20554. } else {
  20555. type = 'Type1';
  20556. }
  20557. }
  20558. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20559. type = 'CIDFontType0';
  20560. }
  20561. // XXX: Temporarily change the type for open type so we trigger a warning.
  20562. // This should be removed when we add support for open type.
  20563. if (subtype === 'OpenType') {
  20564. type = 'OpenType';
  20565. }
  20566. var data;
  20567. switch (type) {
  20568. case 'MMType1':
  20569. info('MMType1 font (' + name + '), falling back to Type1.');
  20570. /* falls through */
  20571. case 'Type1':
  20572. case 'CIDFontType0':
  20573. this.mimetype = 'font/opentype';
  20574. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20575. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20576. adjustWidths(properties);
  20577. // Wrap the CFF data inside an OTF font file
  20578. data = this.convert(name, cff, properties);
  20579. break;
  20580. case 'OpenType':
  20581. case 'TrueType':
  20582. case 'CIDFontType2':
  20583. this.mimetype = 'font/opentype';
  20584. // Repair the TrueType file. It is can be damaged in the point of
  20585. // view of the sanitizer
  20586. data = this.checkAndRepair(name, file, properties);
  20587. if (this.isOpenType) {
  20588. type = 'OpenType';
  20589. }
  20590. break;
  20591. default:
  20592. error('Font ' + type + ' is not supported');
  20593. break;
  20594. }
  20595. this.data = data;
  20596. this.fontType = getFontType(type, subtype);
  20597. // Transfer some properties again that could change during font conversion
  20598. this.fontMatrix = properties.fontMatrix;
  20599. this.widths = properties.widths;
  20600. this.defaultWidth = properties.defaultWidth;
  20601. this.encoding = properties.baseEncoding;
  20602. this.seacMap = properties.seacMap;
  20603. this.loading = true;
  20604. }
  20605. Font.getFontID = (function () {
  20606. var ID = 1;
  20607. return function Font_getFontID() {
  20608. return String(ID++);
  20609. };
  20610. })();
  20611. function int16(b0, b1) {
  20612. return (b0 << 8) + b1;
  20613. }
  20614. function int32(b0, b1, b2, b3) {
  20615. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20616. }
  20617. function string16(value) {
  20618. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20619. }
  20620. function safeString16(value) {
  20621. // clamp value to the 16-bit int range
  20622. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  20623. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20624. }
  20625. function isTrueTypeFile(file) {
  20626. var header = file.peekBytes(4);
  20627. return readUint32(header, 0) === 0x00010000;
  20628. }
  20629. /**
  20630. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  20631. * with their unicode value. It also moves char codes that are in known
  20632. * problematic locations.
  20633. * @return {Object} Two properties:
  20634. * 'toFontChar' - maps original char codes(the value that will be read
  20635. * from commands such as show text) to the char codes that will be used in the
  20636. * font that we build
  20637. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  20638. */
  20639. function adjustMapping(charCodeToGlyphId, properties) {
  20640. var toUnicode = properties.toUnicode;
  20641. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  20642. var isIdentityUnicode =
  20643. properties.toUnicode instanceof IdentityToUnicodeMap;
  20644. var isCidFontType2 = (properties.type === 'CIDFontType2');
  20645. var newMap = Object.create(null);
  20646. var toFontChar = [];
  20647. var usedFontCharCodes = [];
  20648. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  20649. for (var originalCharCode in charCodeToGlyphId) {
  20650. originalCharCode |= 0;
  20651. var glyphId = charCodeToGlyphId[originalCharCode];
  20652. var fontCharCode = originalCharCode;
  20653. // First try to map the value to a unicode position if a non identity map
  20654. // was created.
  20655. if (!isIdentityUnicode) {
  20656. if (toUnicode.get(originalCharCode) !== undefined) {
  20657. var unicode = toUnicode.get(fontCharCode);
  20658. // TODO: Try to map ligatures to the correct spot.
  20659. if (unicode.length === 1) {
  20660. fontCharCode = unicode.charCodeAt(0);
  20661. }
  20662. } else if (isCidFontType2) {
  20663. // For CIDFontType2, move characters not present in toUnicode
  20664. // to the private use area (fixes bug 1028735 and issue 4881).
  20665. fontCharCode = nextAvailableFontCharCode;
  20666. }
  20667. }
  20668. // Try to move control characters, special characters and already mapped
  20669. // characters to the private use area since they will not be drawn by
  20670. // canvas if left in their current position. Also, move characters if the
  20671. // font was symbolic and there is only an identity unicode map since the
  20672. // characters probably aren't in the correct position (fixes an issue
  20673. // with firefox and thuluthfont).
  20674. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  20675. fontCharCode <= 0x1f || // Control chars
  20676. fontCharCode === 0x7F || // Control char
  20677. fontCharCode === 0xAD || // Soft hyphen
  20678. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  20679. // Prevent drawing characters in the specials unicode block.
  20680. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  20681. (isSymbolic && isIdentityUnicode)) &&
  20682. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  20683. // Loop to try and find a free spot in the private use area.
  20684. do {
  20685. fontCharCode = nextAvailableFontCharCode++;
  20686. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  20687. fontCharCode = 0xF020;
  20688. nextAvailableFontCharCode = fontCharCode + 1;
  20689. }
  20690. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  20691. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  20692. }
  20693. newMap[fontCharCode] = glyphId;
  20694. toFontChar[originalCharCode] = fontCharCode;
  20695. usedFontCharCodes[fontCharCode] = true;
  20696. }
  20697. return {
  20698. toFontChar: toFontChar,
  20699. charCodeToGlyphId: newMap,
  20700. nextAvailableFontCharCode: nextAvailableFontCharCode
  20701. };
  20702. }
  20703. function getRanges(glyphs) {
  20704. // Array.sort() sorts by characters, not numerically, so convert to an
  20705. // array of characters.
  20706. var codes = [];
  20707. for (var charCode in glyphs) {
  20708. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  20709. }
  20710. codes.sort(function fontGetRangesSort(a, b) {
  20711. return a.fontCharCode - b.fontCharCode;
  20712. });
  20713. // Split the sorted codes into ranges.
  20714. var ranges = [];
  20715. var length = codes.length;
  20716. for (var n = 0; n < length; ) {
  20717. var start = codes[n].fontCharCode;
  20718. var codeIndices = [codes[n].glyphId];
  20719. ++n;
  20720. var end = start;
  20721. while (n < length && end + 1 === codes[n].fontCharCode) {
  20722. codeIndices.push(codes[n].glyphId);
  20723. ++end;
  20724. ++n;
  20725. if (end === 0xFFFF) {
  20726. break;
  20727. }
  20728. }
  20729. ranges.push([start, end, codeIndices]);
  20730. }
  20731. return ranges;
  20732. }
  20733. function createCmapTable(glyphs) {
  20734. var ranges = getRanges(glyphs);
  20735. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  20736. var cmap = '\x00\x00' + // version
  20737. string16(numTables) + // numTables
  20738. '\x00\x03' + // platformID
  20739. '\x00\x01' + // encodingID
  20740. string32(4 + numTables * 8); // start of the table record
  20741. var i, ii, j, jj;
  20742. for (i = ranges.length - 1; i >= 0; --i) {
  20743. if (ranges[i][0] <= 0xFFFF) { break; }
  20744. }
  20745. var bmpLength = i + 1;
  20746. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  20747. ranges[i][1] = 0xFFFE;
  20748. }
  20749. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  20750. var segCount = bmpLength + trailingRangesCount;
  20751. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  20752. // Fill up the 4 parallel arrays describing the segments.
  20753. var startCount = '';
  20754. var endCount = '';
  20755. var idDeltas = '';
  20756. var idRangeOffsets = '';
  20757. var glyphsIds = '';
  20758. var bias = 0;
  20759. var range, start, end, codes;
  20760. for (i = 0, ii = bmpLength; i < ii; i++) {
  20761. range = ranges[i];
  20762. start = range[0];
  20763. end = range[1];
  20764. startCount += string16(start);
  20765. endCount += string16(end);
  20766. codes = range[2];
  20767. var contiguous = true;
  20768. for (j = 1, jj = codes.length; j < jj; ++j) {
  20769. if (codes[j] !== codes[j - 1] + 1) {
  20770. contiguous = false;
  20771. break;
  20772. }
  20773. }
  20774. if (!contiguous) {
  20775. var offset = (segCount - i) * 2 + bias * 2;
  20776. bias += (end - start + 1);
  20777. idDeltas += string16(0);
  20778. idRangeOffsets += string16(offset);
  20779. for (j = 0, jj = codes.length; j < jj; ++j) {
  20780. glyphsIds += string16(codes[j]);
  20781. }
  20782. } else {
  20783. var startCode = codes[0];
  20784. idDeltas += string16((startCode - start) & 0xFFFF);
  20785. idRangeOffsets += string16(0);
  20786. }
  20787. }
  20788. if (trailingRangesCount > 0) {
  20789. endCount += '\xFF\xFF';
  20790. startCount += '\xFF\xFF';
  20791. idDeltas += '\x00\x01';
  20792. idRangeOffsets += '\x00\x00';
  20793. }
  20794. var format314 = '\x00\x00' + // language
  20795. string16(2 * segCount) +
  20796. string16(searchParams.range) +
  20797. string16(searchParams.entry) +
  20798. string16(searchParams.rangeShift) +
  20799. endCount + '\x00\x00' + startCount +
  20800. idDeltas + idRangeOffsets + glyphsIds;
  20801. var format31012 = '';
  20802. var header31012 = '';
  20803. if (numTables > 1) {
  20804. cmap += '\x00\x03' + // platformID
  20805. '\x00\x0A' + // encodingID
  20806. string32(4 + numTables * 8 +
  20807. 4 + format314.length); // start of the table record
  20808. format31012 = '';
  20809. for (i = 0, ii = ranges.length; i < ii; i++) {
  20810. range = ranges[i];
  20811. start = range[0];
  20812. codes = range[2];
  20813. var code = codes[0];
  20814. for (j = 1, jj = codes.length; j < jj; ++j) {
  20815. if (codes[j] !== codes[j - 1] + 1) {
  20816. end = range[0] + j - 1;
  20817. format31012 += string32(start) + // startCharCode
  20818. string32(end) + // endCharCode
  20819. string32(code); // startGlyphID
  20820. start = end + 1;
  20821. code = codes[j];
  20822. }
  20823. }
  20824. format31012 += string32(start) + // startCharCode
  20825. string32(range[1]) + // endCharCode
  20826. string32(code); // startGlyphID
  20827. }
  20828. header31012 = '\x00\x0C' + // format
  20829. '\x00\x00' + // reserved
  20830. string32(format31012.length + 16) + // length
  20831. '\x00\x00\x00\x00' + // language
  20832. string32(format31012.length / 12); // nGroups
  20833. }
  20834. return cmap + '\x00\x04' + // format
  20835. string16(format314.length + 4) + // length
  20836. format314 + header31012 + format31012;
  20837. }
  20838. function validateOS2Table(os2) {
  20839. var stream = new Stream(os2.data);
  20840. var version = stream.getUint16();
  20841. // TODO verify all OS/2 tables fields, but currently we validate only those
  20842. // that give us issues
  20843. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  20844. var selection = stream.getUint16();
  20845. if (version < 4 && (selection & 0x0300)) {
  20846. return false;
  20847. }
  20848. var firstChar = stream.getUint16();
  20849. var lastChar = stream.getUint16();
  20850. if (firstChar > lastChar) {
  20851. return false;
  20852. }
  20853. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  20854. var usWinAscent = stream.getUint16();
  20855. if (usWinAscent === 0) { // makes font unreadable by windows
  20856. return false;
  20857. }
  20858. // OS/2 appears to be valid, resetting some fields
  20859. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  20860. return true;
  20861. }
  20862. function createOS2Table(properties, charstrings, override) {
  20863. override = override || {
  20864. unitsPerEm: 0,
  20865. yMax: 0,
  20866. yMin: 0,
  20867. ascent: 0,
  20868. descent: 0
  20869. };
  20870. var ulUnicodeRange1 = 0;
  20871. var ulUnicodeRange2 = 0;
  20872. var ulUnicodeRange3 = 0;
  20873. var ulUnicodeRange4 = 0;
  20874. var firstCharIndex = null;
  20875. var lastCharIndex = 0;
  20876. if (charstrings) {
  20877. for (var code in charstrings) {
  20878. code |= 0;
  20879. if (firstCharIndex > code || !firstCharIndex) {
  20880. firstCharIndex = code;
  20881. }
  20882. if (lastCharIndex < code) {
  20883. lastCharIndex = code;
  20884. }
  20885. var position = getUnicodeRangeFor(code);
  20886. if (position < 32) {
  20887. ulUnicodeRange1 |= 1 << position;
  20888. } else if (position < 64) {
  20889. ulUnicodeRange2 |= 1 << position - 32;
  20890. } else if (position < 96) {
  20891. ulUnicodeRange3 |= 1 << position - 64;
  20892. } else if (position < 123) {
  20893. ulUnicodeRange4 |= 1 << position - 96;
  20894. } else {
  20895. error('Unicode ranges Bits > 123 are reserved for internal usage');
  20896. }
  20897. }
  20898. } else {
  20899. // TODO
  20900. firstCharIndex = 0;
  20901. lastCharIndex = 255;
  20902. }
  20903. var bbox = properties.bbox || [0, 0, 0, 0];
  20904. var unitsPerEm = (override.unitsPerEm ||
  20905. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  20906. // if the font units differ to the PDF glyph space units
  20907. // then scale up the values
  20908. var scale = (properties.ascentScaled ? 1.0 :
  20909. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  20910. var typoAscent = (override.ascent ||
  20911. Math.round(scale * (properties.ascent || bbox[3])));
  20912. var typoDescent = (override.descent ||
  20913. Math.round(scale * (properties.descent || bbox[1])));
  20914. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  20915. typoDescent = -typoDescent; // fixing incorrect descent
  20916. }
  20917. var winAscent = override.yMax || typoAscent;
  20918. var winDescent = -override.yMin || -typoDescent;
  20919. return '\x00\x03' + // version
  20920. '\x02\x24' + // xAvgCharWidth
  20921. '\x01\xF4' + // usWeightClass
  20922. '\x00\x05' + // usWidthClass
  20923. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  20924. '\x02\x8A' + // ySubscriptXSize
  20925. '\x02\xBB' + // ySubscriptYSize
  20926. '\x00\x00' + // ySubscriptXOffset
  20927. '\x00\x8C' + // ySubscriptYOffset
  20928. '\x02\x8A' + // ySuperScriptXSize
  20929. '\x02\xBB' + // ySuperScriptYSize
  20930. '\x00\x00' + // ySuperScriptXOffset
  20931. '\x01\xDF' + // ySuperScriptYOffset
  20932. '\x00\x31' + // yStrikeOutSize
  20933. '\x01\x02' + // yStrikeOutPosition
  20934. '\x00\x00' + // sFamilyClass
  20935. '\x00\x00\x06' +
  20936. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  20937. '\x00\x00\x00\x00\x00\x00' + // Panose
  20938. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  20939. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  20940. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  20941. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  20942. '\x2A\x32\x31\x2A' + // achVendID
  20943. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  20944. string16(firstCharIndex ||
  20945. properties.firstChar) + // usFirstCharIndex
  20946. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  20947. string16(typoAscent) + // sTypoAscender
  20948. string16(typoDescent) + // sTypoDescender
  20949. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  20950. string16(winAscent) + // usWinAscent
  20951. string16(winDescent) + // usWinDescent
  20952. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  20953. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  20954. string16(properties.xHeight) + // sxHeight
  20955. string16(properties.capHeight) + // sCapHeight
  20956. string16(0) + // usDefaultChar
  20957. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  20958. '\x00\x03'; // usMaxContext
  20959. }
  20960. function createPostTable(properties) {
  20961. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  20962. return ('\x00\x03\x00\x00' + // Version number
  20963. string32(angle) + // italicAngle
  20964. '\x00\x00' + // underlinePosition
  20965. '\x00\x00' + // underlineThickness
  20966. string32(properties.fixedPitch) + // isFixedPitch
  20967. '\x00\x00\x00\x00' + // minMemType42
  20968. '\x00\x00\x00\x00' + // maxMemType42
  20969. '\x00\x00\x00\x00' + // minMemType1
  20970. '\x00\x00\x00\x00'); // maxMemType1
  20971. }
  20972. function createNameTable(name, proto) {
  20973. if (!proto) {
  20974. proto = [[], []]; // no strings and unicode strings
  20975. }
  20976. var strings = [
  20977. proto[0][0] || 'Original licence', // 0.Copyright
  20978. proto[0][1] || name, // 1.Font family
  20979. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  20980. proto[0][3] || 'uniqueID', // 3.Unique ID
  20981. proto[0][4] || name, // 4.Full font name
  20982. proto[0][5] || 'Version 0.11', // 5.Version
  20983. proto[0][6] || '', // 6.Postscript name
  20984. proto[0][7] || 'Unknown', // 7.Trademark
  20985. proto[0][8] || 'Unknown', // 8.Manufacturer
  20986. proto[0][9] || 'Unknown' // 9.Designer
  20987. ];
  20988. // Mac want 1-byte per character strings while Windows want
  20989. // 2-bytes per character, so duplicate the names table
  20990. var stringsUnicode = [];
  20991. var i, ii, j, jj, str;
  20992. for (i = 0, ii = strings.length; i < ii; i++) {
  20993. str = proto[1][i] || strings[i];
  20994. var strBufUnicode = [];
  20995. for (j = 0, jj = str.length; j < jj; j++) {
  20996. strBufUnicode.push(string16(str.charCodeAt(j)));
  20997. }
  20998. stringsUnicode.push(strBufUnicode.join(''));
  20999. }
  21000. var names = [strings, stringsUnicode];
  21001. var platforms = ['\x00\x01', '\x00\x03'];
  21002. var encodings = ['\x00\x00', '\x00\x01'];
  21003. var languages = ['\x00\x00', '\x04\x09'];
  21004. var namesRecordCount = strings.length * platforms.length;
  21005. var nameTable =
  21006. '\x00\x00' + // format
  21007. string16(namesRecordCount) + // Number of names Record
  21008. string16(namesRecordCount * 12 + 6); // Storage
  21009. // Build the name records field
  21010. var strOffset = 0;
  21011. for (i = 0, ii = platforms.length; i < ii; i++) {
  21012. var strs = names[i];
  21013. for (j = 0, jj = strs.length; j < jj; j++) {
  21014. str = strs[j];
  21015. var nameRecord =
  21016. platforms[i] + // platform ID
  21017. encodings[i] + // encoding ID
  21018. languages[i] + // language ID
  21019. string16(j) + // name ID
  21020. string16(str.length) +
  21021. string16(strOffset);
  21022. nameTable += nameRecord;
  21023. strOffset += str.length;
  21024. }
  21025. }
  21026. nameTable += strings.join('') + stringsUnicode.join('');
  21027. return nameTable;
  21028. }
  21029. Font.prototype = {
  21030. name: null,
  21031. font: null,
  21032. mimetype: null,
  21033. encoding: null,
  21034. get renderer() {
  21035. var renderer = FontRendererFactory.create(this);
  21036. return shadow(this, 'renderer', renderer);
  21037. },
  21038. exportData: function Font_exportData() {
  21039. var data = {};
  21040. for (var i in this) {
  21041. if (this.hasOwnProperty(i)) {
  21042. data[i] = this[i];
  21043. }
  21044. }
  21045. return data;
  21046. },
  21047. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21048. function readTableEntry(file) {
  21049. var tag = bytesToString(file.getBytes(4));
  21050. var checksum = file.getInt32();
  21051. var offset = file.getInt32() >>> 0;
  21052. var length = file.getInt32() >>> 0;
  21053. // Read the table associated data
  21054. var previousPosition = file.pos;
  21055. file.pos = file.start ? file.start : 0;
  21056. file.skip(offset);
  21057. var data = file.getBytes(length);
  21058. file.pos = previousPosition;
  21059. if (tag === 'head') {
  21060. // clearing checksum adjustment
  21061. data[8] = data[9] = data[10] = data[11] = 0;
  21062. data[17] |= 0x20; //Set font optimized for cleartype flag
  21063. }
  21064. return {
  21065. tag: tag,
  21066. checksum: checksum,
  21067. length: length,
  21068. offset: offset,
  21069. data: data
  21070. };
  21071. }
  21072. function readOpenTypeHeader(ttf) {
  21073. return {
  21074. version: bytesToString(ttf.getBytes(4)),
  21075. numTables: ttf.getUint16(),
  21076. searchRange: ttf.getUint16(),
  21077. entrySelector: ttf.getUint16(),
  21078. rangeShift: ttf.getUint16()
  21079. };
  21080. }
  21081. /**
  21082. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21083. * PDF spec
  21084. */
  21085. function readCmapTable(cmap, font, isSymbolicFont) {
  21086. var segment;
  21087. var start = (font.start ? font.start : 0) + cmap.offset;
  21088. font.pos = start;
  21089. var version = font.getUint16();
  21090. var numTables = font.getUint16();
  21091. var potentialTable;
  21092. var canBreak = false;
  21093. // There's an order of preference in terms of which cmap subtable to
  21094. // use:
  21095. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21096. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21097. // The following takes advantage of the fact that the tables are sorted
  21098. // to work.
  21099. for (var i = 0; i < numTables; i++) {
  21100. var platformId = font.getUint16();
  21101. var encodingId = font.getUint16();
  21102. var offset = font.getInt32() >>> 0;
  21103. var useTable = false;
  21104. if (platformId === 1 && encodingId === 0) {
  21105. useTable = true;
  21106. // Continue the loop since there still may be a higher priority
  21107. // table.
  21108. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  21109. useTable = true;
  21110. canBreak = true;
  21111. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21112. useTable = true;
  21113. canBreak = true;
  21114. }
  21115. if (useTable) {
  21116. potentialTable = {
  21117. platformId: platformId,
  21118. encodingId: encodingId,
  21119. offset: offset
  21120. };
  21121. }
  21122. if (canBreak) {
  21123. break;
  21124. }
  21125. }
  21126. if (!potentialTable) {
  21127. warn('Could not find a preferred cmap table.');
  21128. return {
  21129. platformId: -1,
  21130. encodingId: -1,
  21131. mappings: [],
  21132. hasShortCmap: false
  21133. };
  21134. }
  21135. font.pos = start + potentialTable.offset;
  21136. var format = font.getUint16();
  21137. var length = font.getUint16();
  21138. var language = font.getUint16();
  21139. var hasShortCmap = false;
  21140. var mappings = [];
  21141. var j, glyphId;
  21142. // TODO(mack): refactor this cmap subtable reading logic out
  21143. if (format === 0) {
  21144. for (j = 0; j < 256; j++) {
  21145. var index = font.getByte();
  21146. if (!index) {
  21147. continue;
  21148. }
  21149. mappings.push({
  21150. charCode: j,
  21151. glyphId: index
  21152. });
  21153. }
  21154. hasShortCmap = true;
  21155. } else if (format === 4) {
  21156. // re-creating the table in format 4 since the encoding
  21157. // might be changed
  21158. var segCount = (font.getUint16() >> 1);
  21159. font.getBytes(6); // skipping range fields
  21160. var segIndex, segments = [];
  21161. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21162. segments.push({ end: font.getUint16() });
  21163. }
  21164. font.getUint16();
  21165. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21166. segments[segIndex].start = font.getUint16();
  21167. }
  21168. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21169. segments[segIndex].delta = font.getUint16();
  21170. }
  21171. var offsetsCount = 0;
  21172. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21173. segment = segments[segIndex];
  21174. var rangeOffset = font.getUint16();
  21175. if (!rangeOffset) {
  21176. segment.offsetIndex = -1;
  21177. continue;
  21178. }
  21179. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21180. segment.offsetIndex = offsetIndex;
  21181. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21182. segment.end - segment.start + 1);
  21183. }
  21184. var offsets = [];
  21185. for (j = 0; j < offsetsCount; j++) {
  21186. offsets.push(font.getUint16());
  21187. }
  21188. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21189. segment = segments[segIndex];
  21190. start = segment.start;
  21191. var end = segment.end;
  21192. var delta = segment.delta;
  21193. offsetIndex = segment.offsetIndex;
  21194. for (j = start; j <= end; j++) {
  21195. if (j === 0xFFFF) {
  21196. continue;
  21197. }
  21198. glyphId = (offsetIndex < 0 ?
  21199. j : offsets[offsetIndex + j - start]);
  21200. glyphId = (glyphId + delta) & 0xFFFF;
  21201. if (glyphId === 0) {
  21202. continue;
  21203. }
  21204. mappings.push({
  21205. charCode: j,
  21206. glyphId: glyphId
  21207. });
  21208. }
  21209. }
  21210. } else if (format === 6) {
  21211. // Format 6 is a 2-bytes dense mapping, which means the font data
  21212. // lives glue together even if they are pretty far in the unicode
  21213. // table. (This looks weird, so I can have missed something), this
  21214. // works on Linux but seems to fails on Mac so let's rewrite the
  21215. // cmap table to a 3-1-4 style
  21216. var firstCode = font.getUint16();
  21217. var entryCount = font.getUint16();
  21218. for (j = 0; j < entryCount; j++) {
  21219. glyphId = font.getUint16();
  21220. var charCode = firstCode + j;
  21221. mappings.push({
  21222. charCode: charCode,
  21223. glyphId: glyphId
  21224. });
  21225. }
  21226. } else {
  21227. error('cmap table has unsupported format: ' + format);
  21228. }
  21229. // removing duplicate entries
  21230. mappings.sort(function (a, b) {
  21231. return a.charCode - b.charCode;
  21232. });
  21233. for (i = 1; i < mappings.length; i++) {
  21234. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21235. mappings.splice(i, 1);
  21236. i--;
  21237. }
  21238. }
  21239. return {
  21240. platformId: potentialTable.platformId,
  21241. encodingId: potentialTable.encodingId,
  21242. mappings: mappings,
  21243. hasShortCmap: hasShortCmap
  21244. };
  21245. }
  21246. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21247. if (!header) {
  21248. if (metrics) {
  21249. metrics.data = null;
  21250. }
  21251. return;
  21252. }
  21253. font.pos = (font.start ? font.start : 0) + header.offset;
  21254. font.pos += header.length - 2;
  21255. var numOfMetrics = font.getUint16();
  21256. if (numOfMetrics > numGlyphs) {
  21257. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21258. 'greater than the numGlyphs (' + numGlyphs + ')');
  21259. // Reduce numOfMetrics if it is greater than numGlyphs
  21260. numOfMetrics = numGlyphs;
  21261. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21262. header.data[35] = numOfMetrics & 0x00ff;
  21263. }
  21264. var numOfSidebearings = numGlyphs - numOfMetrics;
  21265. var numMissing = numOfSidebearings -
  21266. ((metrics.length - numOfMetrics * 4) >> 1);
  21267. if (numMissing > 0) {
  21268. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21269. // Since we need to add two properties for each glyph, this explains
  21270. // the use of |numMissing * 2| when initializing the typed array.
  21271. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21272. entries.set(metrics.data);
  21273. metrics.data = entries;
  21274. }
  21275. }
  21276. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21277. hintsValid) {
  21278. if (sourceEnd - sourceStart <= 12) {
  21279. // glyph with data less than 12 is invalid one
  21280. return 0;
  21281. }
  21282. var glyf = source.subarray(sourceStart, sourceEnd);
  21283. var contoursCount = (glyf[0] << 8) | glyf[1];
  21284. if (contoursCount & 0x8000) {
  21285. // complex glyph, writing as is
  21286. dest.set(glyf, destStart);
  21287. return glyf.length;
  21288. }
  21289. var i, j = 10, flagsCount = 0;
  21290. for (i = 0; i < contoursCount; i++) {
  21291. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21292. flagsCount = endPoint + 1;
  21293. j += 2;
  21294. }
  21295. // skipping instructions
  21296. var instructionsStart = j;
  21297. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21298. j += 2 + instructionsLength;
  21299. var instructionsEnd = j;
  21300. // validating flags
  21301. var coordinatesLength = 0;
  21302. for (i = 0; i < flagsCount; i++) {
  21303. var flag = glyf[j++];
  21304. if (flag & 0xC0) {
  21305. // reserved flags must be zero, cleaning up
  21306. glyf[j - 1] = flag & 0x3F;
  21307. }
  21308. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21309. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21310. coordinatesLength += xyLength;
  21311. if (flag & 8) {
  21312. var repeat = glyf[j++];
  21313. i += repeat;
  21314. coordinatesLength += repeat * xyLength;
  21315. }
  21316. }
  21317. // glyph without coordinates will be rejected
  21318. if (coordinatesLength === 0) {
  21319. return 0;
  21320. }
  21321. var glyphDataLength = j + coordinatesLength;
  21322. if (glyphDataLength > glyf.length) {
  21323. // not enough data for coordinates
  21324. return 0;
  21325. }
  21326. if (!hintsValid && instructionsLength > 0) {
  21327. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21328. dest.set([0, 0], destStart + instructionsStart);
  21329. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21330. destStart + instructionsStart + 2);
  21331. glyphDataLength -= instructionsLength;
  21332. if (glyf.length - glyphDataLength > 3) {
  21333. glyphDataLength = (glyphDataLength + 3) & ~3;
  21334. }
  21335. return glyphDataLength;
  21336. }
  21337. if (glyf.length - glyphDataLength > 3) {
  21338. // truncating and aligning to 4 bytes the long glyph data
  21339. glyphDataLength = (glyphDataLength + 3) & ~3;
  21340. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21341. return glyphDataLength;
  21342. }
  21343. // glyph data is fine
  21344. dest.set(glyf, destStart);
  21345. return glyf.length;
  21346. }
  21347. function sanitizeHead(head, numGlyphs, locaLength) {
  21348. var data = head.data;
  21349. // Validate version:
  21350. // Should always be 0x00010000
  21351. var version = int32(data[0], data[1], data[2], data[3]);
  21352. if (version >> 16 !== 1) {
  21353. info('Attempting to fix invalid version in head table: ' + version);
  21354. data[0] = 0;
  21355. data[1] = 1;
  21356. data[2] = 0;
  21357. data[3] = 0;
  21358. }
  21359. var indexToLocFormat = int16(data[50], data[51]);
  21360. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21361. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21362. indexToLocFormat);
  21363. // The value of indexToLocFormat should be 0 if the loca table
  21364. // consists of short offsets, and should be 1 if the loca table
  21365. // consists of long offsets.
  21366. //
  21367. // The number of entries in the loca table should be numGlyphs + 1.
  21368. //
  21369. // Using this information, we can work backwards to deduce if the
  21370. // size of each offset in the loca table, and thus figure out the
  21371. // appropriate value for indexToLocFormat.
  21372. var numGlyphsPlusOne = numGlyphs + 1;
  21373. if (locaLength === numGlyphsPlusOne << 1) {
  21374. // 0x0000 indicates the loca table consists of short offsets
  21375. data[50] = 0;
  21376. data[51] = 0;
  21377. } else if (locaLength === numGlyphsPlusOne << 2) {
  21378. // 0x0001 indicates the loca table consists of long offsets
  21379. data[50] = 0;
  21380. data[51] = 1;
  21381. } else {
  21382. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21383. }
  21384. }
  21385. }
  21386. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21387. isGlyphLocationsLong, hintsValid,
  21388. dupFirstEntry) {
  21389. var itemSize, itemDecode, itemEncode;
  21390. if (isGlyphLocationsLong) {
  21391. itemSize = 4;
  21392. itemDecode = function fontItemDecodeLong(data, offset) {
  21393. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21394. (data[offset + 2] << 8) | data[offset + 3];
  21395. };
  21396. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21397. data[offset] = (value >>> 24) & 0xFF;
  21398. data[offset + 1] = (value >> 16) & 0xFF;
  21399. data[offset + 2] = (value >> 8) & 0xFF;
  21400. data[offset + 3] = value & 0xFF;
  21401. };
  21402. } else {
  21403. itemSize = 2;
  21404. itemDecode = function fontItemDecode(data, offset) {
  21405. return (data[offset] << 9) | (data[offset + 1] << 1);
  21406. };
  21407. itemEncode = function fontItemEncode(data, offset, value) {
  21408. data[offset] = (value >> 9) & 0xFF;
  21409. data[offset + 1] = (value >> 1) & 0xFF;
  21410. };
  21411. }
  21412. var locaData = loca.data;
  21413. var locaDataSize = itemSize * (1 + numGlyphs);
  21414. // is loca.data too short or long?
  21415. if (locaData.length !== locaDataSize) {
  21416. locaData = new Uint8Array(locaDataSize);
  21417. locaData.set(loca.data.subarray(0, locaDataSize));
  21418. loca.data = locaData;
  21419. }
  21420. // removing the invalid glyphs
  21421. var oldGlyfData = glyf.data;
  21422. var oldGlyfDataLength = oldGlyfData.length;
  21423. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21424. var startOffset = itemDecode(locaData, 0);
  21425. var writeOffset = 0;
  21426. itemEncode(locaData, 0, writeOffset);
  21427. var i, j;
  21428. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21429. var endOffset = itemDecode(locaData, j);
  21430. if (endOffset > oldGlyfDataLength &&
  21431. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21432. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21433. // the glyf table size, which makes last glyph out of range.
  21434. endOffset = oldGlyfDataLength;
  21435. }
  21436. if (endOffset > oldGlyfDataLength) {
  21437. // glyph end offset points outside glyf data, rejecting the glyph
  21438. itemEncode(locaData, j, writeOffset);
  21439. startOffset = endOffset;
  21440. continue;
  21441. }
  21442. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21443. newGlyfData, writeOffset, hintsValid);
  21444. writeOffset += newLength;
  21445. itemEncode(locaData, j, writeOffset);
  21446. startOffset = endOffset;
  21447. }
  21448. if (writeOffset === 0) {
  21449. // glyf table cannot be empty -- redoing the glyf and loca tables
  21450. // to have single glyph with one point
  21451. var simpleGlyph = new Uint8Array(
  21452. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21453. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21454. itemEncode(locaData, j, simpleGlyph.length);
  21455. }
  21456. glyf.data = simpleGlyph;
  21457. return;
  21458. }
  21459. if (dupFirstEntry) {
  21460. var firstEntryLength = itemDecode(locaData, itemSize);
  21461. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21462. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21463. } else {
  21464. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21465. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21466. }
  21467. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21468. itemEncode(loca.data, locaData.length - itemSize,
  21469. writeOffset + firstEntryLength);
  21470. } else {
  21471. glyf.data = newGlyfData.subarray(0, writeOffset);
  21472. }
  21473. }
  21474. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21475. var start = (font.start ? font.start : 0) + post.offset;
  21476. font.pos = start;
  21477. var length = post.length, end = start + length;
  21478. var version = font.getInt32();
  21479. // skip rest to the tables
  21480. font.getBytes(28);
  21481. var glyphNames;
  21482. var valid = true;
  21483. var i;
  21484. switch (version) {
  21485. case 0x00010000:
  21486. glyphNames = MacStandardGlyphOrdering;
  21487. break;
  21488. case 0x00020000:
  21489. var numGlyphs = font.getUint16();
  21490. if (numGlyphs !== maxpNumGlyphs) {
  21491. valid = false;
  21492. break;
  21493. }
  21494. var glyphNameIndexes = [];
  21495. for (i = 0; i < numGlyphs; ++i) {
  21496. var index = font.getUint16();
  21497. if (index >= 32768) {
  21498. valid = false;
  21499. break;
  21500. }
  21501. glyphNameIndexes.push(index);
  21502. }
  21503. if (!valid) {
  21504. break;
  21505. }
  21506. var customNames = [];
  21507. var strBuf = [];
  21508. while (font.pos < end) {
  21509. var stringLength = font.getByte();
  21510. strBuf.length = stringLength;
  21511. for (i = 0; i < stringLength; ++i) {
  21512. strBuf[i] = String.fromCharCode(font.getByte());
  21513. }
  21514. customNames.push(strBuf.join(''));
  21515. }
  21516. glyphNames = [];
  21517. for (i = 0; i < numGlyphs; ++i) {
  21518. var j = glyphNameIndexes[i];
  21519. if (j < 258) {
  21520. glyphNames.push(MacStandardGlyphOrdering[j]);
  21521. continue;
  21522. }
  21523. glyphNames.push(customNames[j - 258]);
  21524. }
  21525. break;
  21526. case 0x00030000:
  21527. break;
  21528. default:
  21529. warn('Unknown/unsupported post table version ' + version);
  21530. valid = false;
  21531. break;
  21532. }
  21533. properties.glyphNames = glyphNames;
  21534. return valid;
  21535. }
  21536. function readNameTable(nameTable) {
  21537. var start = (font.start ? font.start : 0) + nameTable.offset;
  21538. font.pos = start;
  21539. var names = [[], []];
  21540. var length = nameTable.length, end = start + length;
  21541. var format = font.getUint16();
  21542. var FORMAT_0_HEADER_LENGTH = 6;
  21543. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21544. // unsupported name table format or table "too" small
  21545. return names;
  21546. }
  21547. var numRecords = font.getUint16();
  21548. var stringsStart = font.getUint16();
  21549. var records = [];
  21550. var NAME_RECORD_LENGTH = 12;
  21551. var i, ii;
  21552. for (i = 0; i < numRecords &&
  21553. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21554. var r = {
  21555. platform: font.getUint16(),
  21556. encoding: font.getUint16(),
  21557. language: font.getUint16(),
  21558. name: font.getUint16(),
  21559. length: font.getUint16(),
  21560. offset: font.getUint16()
  21561. };
  21562. // using only Macintosh and Windows platform/encoding names
  21563. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21564. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21565. records.push(r);
  21566. }
  21567. }
  21568. for (i = 0, ii = records.length; i < ii; i++) {
  21569. var record = records[i];
  21570. var pos = start + stringsStart + record.offset;
  21571. if (pos + record.length > end) {
  21572. continue; // outside of name table, ignoring
  21573. }
  21574. font.pos = pos;
  21575. var nameIndex = record.name;
  21576. if (record.encoding) {
  21577. // unicode
  21578. var str = '';
  21579. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21580. str += String.fromCharCode(font.getUint16());
  21581. }
  21582. names[1][nameIndex] = str;
  21583. } else {
  21584. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21585. }
  21586. }
  21587. return names;
  21588. }
  21589. var TTOpsStackDeltas = [
  21590. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21591. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21592. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21593. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21594. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21595. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21596. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21597. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21598. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21599. // 0xC0-DF == -1 and 0xE0-FF == -2
  21600. function sanitizeTTProgram(table, ttContext) {
  21601. var data = table.data;
  21602. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21603. var stack = [];
  21604. var callstack = [];
  21605. var functionsCalled = [];
  21606. var tooComplexToFollowFunctions =
  21607. ttContext.tooComplexToFollowFunctions;
  21608. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21609. for (var ii = data.length; i < ii;) {
  21610. var op = data[i++];
  21611. // The TrueType instruction set docs can be found at
  21612. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21613. if (op === 0x40) { // NPUSHB - pushes n bytes
  21614. n = data[i++];
  21615. if (inFDEF || inELSE) {
  21616. i += n;
  21617. } else {
  21618. for (j = 0; j < n; j++) {
  21619. stack.push(data[i++]);
  21620. }
  21621. }
  21622. } else if (op === 0x41) { // NPUSHW - pushes n words
  21623. n = data[i++];
  21624. if (inFDEF || inELSE) {
  21625. i += n * 2;
  21626. } else {
  21627. for (j = 0; j < n; j++) {
  21628. b = data[i++];
  21629. stack.push((b << 8) | data[i++]);
  21630. }
  21631. }
  21632. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  21633. n = op - 0xB0 + 1;
  21634. if (inFDEF || inELSE) {
  21635. i += n;
  21636. } else {
  21637. for (j = 0; j < n; j++) {
  21638. stack.push(data[i++]);
  21639. }
  21640. }
  21641. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  21642. n = op - 0xB8 + 1;
  21643. if (inFDEF || inELSE) {
  21644. i += n * 2;
  21645. } else {
  21646. for (j = 0; j < n; j++) {
  21647. b = data[i++];
  21648. stack.push((b << 8) | data[i++]);
  21649. }
  21650. }
  21651. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  21652. if (!inFDEF && !inELSE) {
  21653. // collecting inforamtion about which functions are used
  21654. funcId = stack[stack.length - 1];
  21655. ttContext.functionsUsed[funcId] = true;
  21656. if (funcId in ttContext.functionsStackDeltas) {
  21657. stack.length += ttContext.functionsStackDeltas[funcId];
  21658. } else if (funcId in ttContext.functionsDefined &&
  21659. functionsCalled.indexOf(funcId) < 0) {
  21660. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  21661. functionsCalled.push(funcId);
  21662. pc = ttContext.functionsDefined[funcId];
  21663. if (!pc) {
  21664. warn('TT: CALL non-existent function');
  21665. ttContext.hintsValid = false;
  21666. return;
  21667. }
  21668. data = pc.data;
  21669. i = pc.i;
  21670. }
  21671. }
  21672. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  21673. if (inFDEF || inELSE) {
  21674. warn('TT: nested FDEFs not allowed');
  21675. tooComplexToFollowFunctions = true;
  21676. }
  21677. inFDEF = true;
  21678. // collecting inforamtion about which functions are defined
  21679. lastDeff = i;
  21680. funcId = stack.pop();
  21681. ttContext.functionsDefined[funcId] = {data: data, i: i};
  21682. } else if (op === 0x2D) { // ENDF - end of function
  21683. if (inFDEF) {
  21684. inFDEF = false;
  21685. lastEndf = i;
  21686. } else {
  21687. pc = callstack.pop();
  21688. if (!pc) {
  21689. warn('TT: ENDF bad stack');
  21690. ttContext.hintsValid = false;
  21691. return;
  21692. }
  21693. funcId = functionsCalled.pop();
  21694. data = pc.data;
  21695. i = pc.i;
  21696. ttContext.functionsStackDeltas[funcId] =
  21697. stack.length - pc.stackTop;
  21698. }
  21699. } else if (op === 0x89) { // IDEF - instruction definition
  21700. if (inFDEF || inELSE) {
  21701. warn('TT: nested IDEFs not allowed');
  21702. tooComplexToFollowFunctions = true;
  21703. }
  21704. inFDEF = true;
  21705. // recording it as a function to track ENDF
  21706. lastDeff = i;
  21707. } else if (op === 0x58) { // IF
  21708. ++ifLevel;
  21709. } else if (op === 0x1B) { // ELSE
  21710. inELSE = ifLevel;
  21711. } else if (op === 0x59) { // EIF
  21712. if (inELSE === ifLevel) {
  21713. inELSE = 0;
  21714. }
  21715. --ifLevel;
  21716. } else if (op === 0x1C) { // JMPR
  21717. if (!inFDEF && !inELSE) {
  21718. var offset = stack[stack.length - 1];
  21719. // only jumping forward to prevent infinite loop
  21720. if (offset > 0) {
  21721. i += offset - 1;
  21722. }
  21723. }
  21724. }
  21725. // Adjusting stack not extactly, but just enough to get function id
  21726. if (!inFDEF && !inELSE) {
  21727. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  21728. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  21729. if (op >= 0x71 && op <= 0x75) {
  21730. n = stack.pop();
  21731. if (n === n) {
  21732. stackDelta = -n * 2;
  21733. }
  21734. }
  21735. while (stackDelta < 0 && stack.length > 0) {
  21736. stack.pop();
  21737. stackDelta++;
  21738. }
  21739. while (stackDelta > 0) {
  21740. stack.push(NaN); // pushing any number into stack
  21741. stackDelta--;
  21742. }
  21743. }
  21744. }
  21745. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  21746. var content = [data];
  21747. if (i > data.length) {
  21748. content.push(new Uint8Array(i - data.length));
  21749. }
  21750. if (lastDeff > lastEndf) {
  21751. warn('TT: complementing a missing function tail');
  21752. // new function definition started, but not finished
  21753. // complete function by [CLEAR, ENDF]
  21754. content.push(new Uint8Array([0x22, 0x2D]));
  21755. }
  21756. foldTTTable(table, content);
  21757. }
  21758. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  21759. if (ttContext.tooComplexToFollowFunctions) {
  21760. return;
  21761. }
  21762. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  21763. warn('TT: more functions defined than expected');
  21764. ttContext.hintsValid = false;
  21765. return;
  21766. }
  21767. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  21768. if (j > maxFunctionDefs) {
  21769. warn('TT: invalid function id: ' + j);
  21770. ttContext.hintsValid = false;
  21771. return;
  21772. }
  21773. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  21774. warn('TT: undefined function: ' + j);
  21775. ttContext.hintsValid = false;
  21776. return;
  21777. }
  21778. }
  21779. }
  21780. function foldTTTable(table, content) {
  21781. if (content.length > 1) {
  21782. // concatenating the content items
  21783. var newLength = 0;
  21784. var j, jj;
  21785. for (j = 0, jj = content.length; j < jj; j++) {
  21786. newLength += content[j].length;
  21787. }
  21788. newLength = (newLength + 3) & ~3;
  21789. var result = new Uint8Array(newLength);
  21790. var pos = 0;
  21791. for (j = 0, jj = content.length; j < jj; j++) {
  21792. result.set(content[j], pos);
  21793. pos += content[j].length;
  21794. }
  21795. table.data = result;
  21796. table.length = newLength;
  21797. }
  21798. }
  21799. function sanitizeTTPrograms(fpgm, prep, cvt) {
  21800. var ttContext = {
  21801. functionsDefined: [],
  21802. functionsUsed: [],
  21803. functionsStackDeltas: [],
  21804. tooComplexToFollowFunctions: false,
  21805. hintsValid: true
  21806. };
  21807. if (fpgm) {
  21808. sanitizeTTProgram(fpgm, ttContext);
  21809. }
  21810. if (prep) {
  21811. sanitizeTTProgram(prep, ttContext);
  21812. }
  21813. if (fpgm) {
  21814. checkInvalidFunctions(ttContext, maxFunctionDefs);
  21815. }
  21816. if (cvt && (cvt.length & 1)) {
  21817. var cvtData = new Uint8Array(cvt.length + 1);
  21818. cvtData.set(cvt.data);
  21819. cvt.data = cvtData;
  21820. }
  21821. return ttContext.hintsValid;
  21822. }
  21823. // The following steps modify the original font data, making copy
  21824. font = new Stream(new Uint8Array(font.getBytes()));
  21825. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  21826. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  21827. var header = readOpenTypeHeader(font);
  21828. var numTables = header.numTables;
  21829. var cff, cffFile;
  21830. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  21831. hmtx: null, maxp: null, name: null, post: null };
  21832. var table;
  21833. for (var i = 0; i < numTables; i++) {
  21834. table = readTableEntry(font);
  21835. if (VALID_TABLES.indexOf(table.tag) < 0) {
  21836. continue; // skipping table if it's not a required or optional table
  21837. }
  21838. if (table.length === 0) {
  21839. continue; // skipping empty tables
  21840. }
  21841. tables[table.tag] = table;
  21842. }
  21843. var isTrueType = !tables['CFF '];
  21844. if (!isTrueType) {
  21845. // OpenType font
  21846. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  21847. // no major tables: throwing everything at CFFFont
  21848. cffFile = new Stream(tables['CFF '].data);
  21849. cff = new CFFFont(cffFile, properties);
  21850. return this.convert(name, cff, properties);
  21851. }
  21852. delete tables.glyf;
  21853. delete tables.loca;
  21854. delete tables.fpgm;
  21855. delete tables.prep;
  21856. delete tables['cvt '];
  21857. this.isOpenType = true;
  21858. } else {
  21859. if (!tables.glyf || !tables.loca) {
  21860. error('Required "glyf" or "loca" tables are not found');
  21861. }
  21862. this.isOpenType = false;
  21863. }
  21864. if (!tables.maxp) {
  21865. error('Required "maxp" table is not found');
  21866. }
  21867. font.pos = (font.start || 0) + tables.maxp.offset;
  21868. var version = font.getInt32();
  21869. var numGlyphs = font.getUint16();
  21870. var maxFunctionDefs = 0;
  21871. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  21872. // maxZones can be invalid
  21873. font.pos += 8;
  21874. var maxZones = font.getUint16();
  21875. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  21876. tables.maxp.data[14] = 0;
  21877. tables.maxp.data[15] = 2;
  21878. }
  21879. font.pos += 4;
  21880. maxFunctionDefs = font.getUint16();
  21881. }
  21882. var dupFirstEntry = false;
  21883. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  21884. properties.toUnicode.get(0) > '\u0000') {
  21885. // oracle's defect (see 3427), duplicating first entry
  21886. dupFirstEntry = true;
  21887. numGlyphs++;
  21888. tables.maxp.data[4] = numGlyphs >> 8;
  21889. tables.maxp.data[5] = numGlyphs & 255;
  21890. }
  21891. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  21892. tables['cvt '], maxFunctionDefs);
  21893. if (!hintsValid) {
  21894. delete tables.fpgm;
  21895. delete tables.prep;
  21896. delete tables['cvt '];
  21897. }
  21898. // Ensure the hmtx table contains the advance width and
  21899. // sidebearings information for numGlyphs in the maxp table
  21900. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  21901. if (!tables.head) {
  21902. error('Required "head" table is not found');
  21903. }
  21904. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  21905. if (isTrueType) {
  21906. var isGlyphLocationsLong = int16(tables.head.data[50],
  21907. tables.head.data[51]);
  21908. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  21909. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  21910. }
  21911. if (!tables.hhea) {
  21912. error('Required "hhea" table is not found');
  21913. }
  21914. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  21915. // Sometimes it's 0. That needs to be fixed
  21916. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  21917. tables.hhea.data[10] = 0xFF;
  21918. tables.hhea.data[11] = 0xFF;
  21919. }
  21920. // The 'post' table has glyphs names.
  21921. if (tables.post) {
  21922. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  21923. if (!valid) {
  21924. tables.post = null;
  21925. }
  21926. }
  21927. var charCodeToGlyphId = [], charCode;
  21928. if (properties.type === 'CIDFontType2') {
  21929. var cidToGidMap = properties.cidToGidMap || [];
  21930. var cidToGidMapLength = cidToGidMap.length;
  21931. properties.cMap.forEach(function(charCode, cid) {
  21932. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  21933. var glyphId = -1;
  21934. if (cidToGidMapLength === 0) {
  21935. glyphId = charCode;
  21936. } else if (cidToGidMap[cid] !== undefined) {
  21937. glyphId = cidToGidMap[cid];
  21938. }
  21939. if (glyphId >= 0 && glyphId < numGlyphs) {
  21940. charCodeToGlyphId[charCode] = glyphId;
  21941. }
  21942. });
  21943. if (dupFirstEntry) {
  21944. charCodeToGlyphId[0] = numGlyphs - 1;
  21945. }
  21946. } else {
  21947. // Most of the following logic in this code branch is based on the
  21948. // 9.6.6.4 of the PDF spec.
  21949. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  21950. var cmapPlatformId = cmapTable.platformId;
  21951. var cmapEncodingId = cmapTable.encodingId;
  21952. var cmapMappings = cmapTable.mappings;
  21953. var cmapMappingsLength = cmapMappings.length;
  21954. var hasEncoding = properties.differences.length ||
  21955. !!properties.baseEncodingName;
  21956. // The spec seems to imply that if the font is symbolic the encoding
  21957. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  21958. // where the the font is symbolic and it has an encoding.
  21959. if (hasEncoding &&
  21960. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  21961. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  21962. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  21963. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  21964. // When no preferred cmap table was found and |baseEncodingName| is
  21965. // one of the predefined encodings, we seem to obtain a better
  21966. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  21967. // TODO: Note that this is a hack which should be removed as soon as
  21968. // we have proper support for more exotic cmap tables.
  21969. var baseEncoding = [];
  21970. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  21971. properties.baseEncodingName === 'WinAnsiEncoding') {
  21972. baseEncoding = Encodings[properties.baseEncodingName];
  21973. }
  21974. for (charCode = 0; charCode < 256; charCode++) {
  21975. var glyphName;
  21976. if (this.differences && charCode in this.differences) {
  21977. glyphName = this.differences[charCode];
  21978. } else if (charCode in baseEncoding &&
  21979. baseEncoding[charCode] !== '') {
  21980. glyphName = baseEncoding[charCode];
  21981. } else {
  21982. glyphName = Encodings.StandardEncoding[charCode];
  21983. }
  21984. if (!glyphName) {
  21985. continue;
  21986. }
  21987. var unicodeOrCharCode;
  21988. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  21989. unicodeOrCharCode = GlyphsUnicode[glyphName];
  21990. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  21991. // TODO: the encoding needs to be updated with mac os table.
  21992. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  21993. }
  21994. var found = false;
  21995. for (i = 0; i < cmapMappingsLength; ++i) {
  21996. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  21997. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  21998. found = true;
  21999. break;
  22000. }
  22001. }
  22002. if (!found && properties.glyphNames) {
  22003. // Try to map using the post table. There are currently no known
  22004. // pdfs that this fixes.
  22005. var glyphId = properties.glyphNames.indexOf(glyphName);
  22006. if (glyphId > 0) {
  22007. charCodeToGlyphId[charCode] = glyphId;
  22008. }
  22009. }
  22010. }
  22011. } else {
  22012. // For (3, 0) cmap tables:
  22013. // The charcode key being stored in charCodeToGlyphId is the lower
  22014. // byte of the two-byte charcodes of the cmap table since according to
  22015. // the spec: 'each byte from the string shall be prepended with the
  22016. // high byte of the range [of charcodes in the cmap table], to form
  22017. // a two-byte character, which shall be used to select the
  22018. // associated glyph description from the subtable'.
  22019. //
  22020. // For (1, 0) cmap tables:
  22021. // 'single bytes from the string shall be used to look up the
  22022. // associated glyph descriptions from the subtable'. This means
  22023. // charcodes in the cmap will be single bytes, so no-op since
  22024. // glyph.charCode & 0xFF === glyph.charCode
  22025. for (i = 0; i < cmapMappingsLength; ++i) {
  22026. charCode = cmapMappings[i].charCode & 0xFF;
  22027. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22028. }
  22029. }
  22030. }
  22031. if (charCodeToGlyphId.length === 0) {
  22032. // defines at least one glyph
  22033. charCodeToGlyphId[0] = 0;
  22034. }
  22035. // Converting glyphs and ids into font's cmap table
  22036. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22037. this.toFontChar = newMapping.toFontChar;
  22038. tables.cmap = {
  22039. tag: 'cmap',
  22040. data: createCmapTable(newMapping.charCodeToGlyphId)
  22041. };
  22042. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22043. // extract some more font properties from the OpenType head and
  22044. // hhea tables; yMin and descent value are always negative
  22045. var override = {
  22046. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22047. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22048. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22049. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22050. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22051. };
  22052. tables['OS/2'] = {
  22053. tag: 'OS/2',
  22054. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22055. override)
  22056. };
  22057. }
  22058. // Rewrite the 'post' table if needed
  22059. if (!tables.post) {
  22060. tables.post = {
  22061. tag: 'post',
  22062. data: createPostTable(properties)
  22063. };
  22064. }
  22065. if (!isTrueType) {
  22066. try {
  22067. // Trying to repair CFF file
  22068. cffFile = new Stream(tables['CFF '].data);
  22069. var parser = new CFFParser(cffFile, properties);
  22070. cff = parser.parse();
  22071. var compiler = new CFFCompiler(cff);
  22072. tables['CFF '].data = compiler.compile();
  22073. } catch (e) {
  22074. warn('Failed to compile font ' + properties.loadedName);
  22075. }
  22076. }
  22077. // Re-creating 'name' table
  22078. if (!tables.name) {
  22079. tables.name = {
  22080. tag: 'name',
  22081. data: createNameTable(this.name)
  22082. };
  22083. } else {
  22084. // ... using existing 'name' table as prototype
  22085. var namePrototype = readNameTable(tables.name);
  22086. tables.name.data = createNameTable(name, namePrototype);
  22087. }
  22088. var builder = new OpenTypeFileBuilder(header.version);
  22089. for (var tableTag in tables) {
  22090. builder.addTable(tableTag, tables[tableTag].data);
  22091. }
  22092. return builder.toArray();
  22093. },
  22094. convert: function Font_convert(fontName, font, properties) {
  22095. // TODO: Check the charstring widths to determine this.
  22096. properties.fixedPitch = false;
  22097. var mapping = font.getGlyphMapping(properties);
  22098. var newMapping = adjustMapping(mapping, properties);
  22099. this.toFontChar = newMapping.toFontChar;
  22100. var numGlyphs = font.numGlyphs;
  22101. function getCharCodes(charCodeToGlyphId, glyphId) {
  22102. var charCodes = null;
  22103. for (var charCode in charCodeToGlyphId) {
  22104. if (glyphId === charCodeToGlyphId[charCode]) {
  22105. if (!charCodes) {
  22106. charCodes = [];
  22107. }
  22108. charCodes.push(charCode | 0);
  22109. }
  22110. }
  22111. return charCodes;
  22112. }
  22113. function createCharCode(charCodeToGlyphId, glyphId) {
  22114. for (var charCode in charCodeToGlyphId) {
  22115. if (glyphId === charCodeToGlyphId[charCode]) {
  22116. return charCode | 0;
  22117. }
  22118. }
  22119. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22120. glyphId;
  22121. return newMapping.nextAvailableFontCharCode++;
  22122. }
  22123. var seacs = font.seacs;
  22124. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22125. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22126. var charset = font.getCharset();
  22127. var seacMap = Object.create(null);
  22128. for (var glyphId in seacs) {
  22129. glyphId |= 0;
  22130. var seac = seacs[glyphId];
  22131. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22132. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22133. var baseGlyphId = charset.indexOf(baseGlyphName);
  22134. var accentGlyphId = charset.indexOf(accentGlyphName);
  22135. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22136. continue;
  22137. }
  22138. var accentOffset = {
  22139. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22140. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22141. };
  22142. var charCodes = getCharCodes(mapping, glyphId);
  22143. if (!charCodes) {
  22144. // There's no point in mapping it if the char code was never mapped
  22145. // to begin with.
  22146. continue;
  22147. }
  22148. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22149. var charCode = charCodes[i];
  22150. // Find a fontCharCode that maps to the base and accent glyphs.
  22151. // If one doesn't exists, create it.
  22152. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22153. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22154. baseGlyphId);
  22155. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22156. accentGlyphId);
  22157. seacMap[charCode] = {
  22158. baseFontCharCode: baseFontCharCode,
  22159. accentFontCharCode: accentFontCharCode,
  22160. accentOffset: accentOffset
  22161. };
  22162. }
  22163. }
  22164. properties.seacMap = seacMap;
  22165. }
  22166. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22167. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22168. // PostScript Font Program
  22169. builder.addTable('CFF ', font.data);
  22170. // OS/2 and Windows Specific metrics
  22171. builder.addTable('OS/2', createOS2Table(properties,
  22172. newMapping.charCodeToGlyphId));
  22173. // Character to glyphs mapping
  22174. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22175. // Font header
  22176. builder.addTable('head',
  22177. '\x00\x01\x00\x00' + // Version number
  22178. '\x00\x00\x10\x00' + // fontRevision
  22179. '\x00\x00\x00\x00' + // checksumAdjustement
  22180. '\x5F\x0F\x3C\xF5' + // magicNumber
  22181. '\x00\x00' + // Flags
  22182. safeString16(unitsPerEm) + // unitsPerEM
  22183. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22184. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22185. '\x00\x00' + // xMin
  22186. safeString16(properties.descent) + // yMin
  22187. '\x0F\xFF' + // xMax
  22188. safeString16(properties.ascent) + // yMax
  22189. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22190. '\x00\x11' + // lowestRecPPEM
  22191. '\x00\x00' + // fontDirectionHint
  22192. '\x00\x00' + // indexToLocFormat
  22193. '\x00\x00'); // glyphDataFormat
  22194. // Horizontal header
  22195. builder.addTable('hhea',
  22196. '\x00\x01\x00\x00' + // Version number
  22197. safeString16(properties.ascent) + // Typographic Ascent
  22198. safeString16(properties.descent) + // Typographic Descent
  22199. '\x00\x00' + // Line Gap
  22200. '\xFF\xFF' + // advanceWidthMax
  22201. '\x00\x00' + // minLeftSidebearing
  22202. '\x00\x00' + // minRightSidebearing
  22203. '\x00\x00' + // xMaxExtent
  22204. safeString16(properties.capHeight) + // caretSlopeRise
  22205. safeString16(Math.tan(properties.italicAngle) *
  22206. properties.xHeight) + // caretSlopeRun
  22207. '\x00\x00' + // caretOffset
  22208. '\x00\x00' + // -reserved-
  22209. '\x00\x00' + // -reserved-
  22210. '\x00\x00' + // -reserved-
  22211. '\x00\x00' + // -reserved-
  22212. '\x00\x00' + // metricDataFormat
  22213. string16(numGlyphs)); // Number of HMetrics
  22214. // Horizontal metrics
  22215. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22216. var charstrings = font.charstrings;
  22217. var cffWidths = font.cff ? font.cff.widths : null;
  22218. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22219. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22220. var width = 0;
  22221. if (charstrings) {
  22222. var charstring = charstrings[i - 1];
  22223. width = 'width' in charstring ? charstring.width : 0;
  22224. } else if (cffWidths) {
  22225. width = Math.ceil(cffWidths[i] || 0);
  22226. }
  22227. hmtx += string16(width) + string16(0);
  22228. }
  22229. return hmtx;
  22230. })());
  22231. // Maximum profile
  22232. builder.addTable('maxp',
  22233. '\x00\x00\x50\x00' + // Version number
  22234. string16(numGlyphs)); // Num of glyphs
  22235. // Naming tables
  22236. builder.addTable('name', createNameTable(fontName));
  22237. // PostScript informations
  22238. builder.addTable('post', createPostTable(properties));
  22239. return builder.toArray();
  22240. },
  22241. /**
  22242. * Builds a char code to unicode map based on section 9.10 of the spec.
  22243. * @param {Object} properties Font properties object.
  22244. * @return {Object} A ToUnicodeMap object.
  22245. */
  22246. buildToUnicode: function Font_buildToUnicode(properties) {
  22247. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22248. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22249. return properties.toUnicode;
  22250. }
  22251. // According to the spec if the font is a simple font we should only map
  22252. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22253. // the differences array only contains adobe standard or symbol set names,
  22254. // in pratice it seems better to always try to create a toUnicode
  22255. // map based of the default encoding.
  22256. var toUnicode, charcode;
  22257. if (!properties.composite /* is simple font */) {
  22258. toUnicode = [];
  22259. var encoding = properties.defaultEncoding.slice();
  22260. var baseEncodingName = properties.baseEncodingName;
  22261. // Merge in the differences array.
  22262. var differences = properties.differences;
  22263. for (charcode in differences) {
  22264. encoding[charcode] = differences[charcode];
  22265. }
  22266. for (charcode in encoding) {
  22267. // a) Map the character code to a character name.
  22268. var glyphName = encoding[charcode];
  22269. // b) Look up the character name in the Adobe Glyph List (see the
  22270. // Bibliography) to obtain the corresponding Unicode value.
  22271. if (glyphName === '') {
  22272. continue;
  22273. } else if (GlyphsUnicode[glyphName] === undefined) {
  22274. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22275. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22276. var code = 0;
  22277. switch (glyphName[0]) {
  22278. case 'G': // Gxx glyph
  22279. if (glyphName.length === 3) {
  22280. code = parseInt(glyphName.substr(1), 16);
  22281. }
  22282. break;
  22283. case 'g': // g00xx glyph
  22284. if (glyphName.length === 5) {
  22285. code = parseInt(glyphName.substr(1), 16);
  22286. }
  22287. break;
  22288. case 'C': // Cddd glyph
  22289. case 'c': // cddd glyph
  22290. if (glyphName.length >= 3) {
  22291. code = +glyphName.substr(1);
  22292. }
  22293. break;
  22294. }
  22295. if (code) {
  22296. // If |baseEncodingName| is one the predefined encodings,
  22297. // and |code| equals |charcode|, using the glyph defined in the
  22298. // baseEncoding seems to yield a better |toUnicode| mapping
  22299. // (fixes issue 5070).
  22300. if (baseEncodingName && code === +charcode) {
  22301. var baseEncoding = Encodings[baseEncodingName];
  22302. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22303. toUnicode[charcode] =
  22304. String.fromCharCode(GlyphsUnicode[glyphName]);
  22305. continue;
  22306. }
  22307. }
  22308. toUnicode[charcode] = String.fromCharCode(code);
  22309. }
  22310. continue;
  22311. }
  22312. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22313. }
  22314. return new ToUnicodeMap(toUnicode);
  22315. }
  22316. // If the font is a composite font that uses one of the predefined CMaps
  22317. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22318. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22319. // Adobe-Korea1 character collection:
  22320. if (properties.composite && (
  22321. (properties.cMap.builtInCMap &&
  22322. !(properties.cMap instanceof IdentityCMap)) ||
  22323. (properties.cidSystemInfo.registry === 'Adobe' &&
  22324. (properties.cidSystemInfo.ordering === 'GB1' ||
  22325. properties.cidSystemInfo.ordering === 'CNS1' ||
  22326. properties.cidSystemInfo.ordering === 'Japan1' ||
  22327. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22328. // Then:
  22329. // a) Map the character code to a character identifier (CID) according
  22330. // to the font’s CMap.
  22331. // b) Obtain the registry and ordering of the character collection used
  22332. // by the font’s CMap (for example, Adobe and Japan1) from its
  22333. // CIDSystemInfo dictionary.
  22334. var registry = properties.cidSystemInfo.registry;
  22335. var ordering = properties.cidSystemInfo.ordering;
  22336. // c) Construct a second CMap name by concatenating the registry and
  22337. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22338. // (for example, Adobe–Japan1–UCS2).
  22339. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22340. // d) Obtain the CMap with the name constructed in step (c) (available
  22341. // from the ASN Web site; see the Bibliography).
  22342. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22343. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22344. var cMap = properties.cMap;
  22345. toUnicode = [];
  22346. cMap.forEach(function(charcode, cid) {
  22347. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22348. // e) Map the CID obtained in step (a) according to the CMap obtained
  22349. // in step (d), producing a Unicode value.
  22350. var ucs2 = ucs2CMap.lookup(cid);
  22351. if (ucs2) {
  22352. toUnicode[charcode] =
  22353. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22354. ucs2.charCodeAt(1));
  22355. }
  22356. });
  22357. return new ToUnicodeMap(toUnicode);
  22358. }
  22359. // The viewer's choice, just use an identity map.
  22360. return new IdentityToUnicodeMap(properties.firstChar,
  22361. properties.lastChar);
  22362. },
  22363. get spaceWidth() {
  22364. if ('_shadowWidth' in this) {
  22365. return this._shadowWidth;
  22366. }
  22367. // trying to estimate space character width
  22368. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22369. var width;
  22370. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22371. var glyphName = possibleSpaceReplacements[i];
  22372. // if possible, getting width by glyph name
  22373. if (glyphName in this.widths) {
  22374. width = this.widths[glyphName];
  22375. break;
  22376. }
  22377. var glyphUnicode = GlyphsUnicode[glyphName];
  22378. // finding the charcode via unicodeToCID map
  22379. var charcode = 0;
  22380. if (this.composite) {
  22381. if (this.cMap.contains(glyphUnicode)) {
  22382. charcode = this.cMap.lookup(glyphUnicode);
  22383. }
  22384. }
  22385. // ... via toUnicode map
  22386. if (!charcode && 'toUnicode' in this) {
  22387. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22388. }
  22389. // setting it to unicode if negative or undefined
  22390. if (charcode <= 0) {
  22391. charcode = glyphUnicode;
  22392. }
  22393. // trying to get width via charcode
  22394. width = this.widths[charcode];
  22395. if (width) {
  22396. break; // the non-zero width found
  22397. }
  22398. }
  22399. width = width || this.defaultWidth;
  22400. // Do not shadow the property here. See discussion:
  22401. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22402. this._shadowWidth = width;
  22403. return width;
  22404. },
  22405. charToGlyph: function Font_charToGlyph(charcode) {
  22406. var fontCharCode, width, operatorListId;
  22407. var widthCode = charcode;
  22408. if (this.cMap && this.cMap.contains(charcode)) {
  22409. widthCode = this.cMap.lookup(charcode);
  22410. }
  22411. width = this.widths[widthCode];
  22412. width = isNum(width) ? width : this.defaultWidth;
  22413. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22414. var unicode = this.toUnicode.get(charcode) || charcode;
  22415. if (typeof unicode === 'number') {
  22416. unicode = String.fromCharCode(unicode);
  22417. }
  22418. // First try the toFontChar map, if it's not there then try falling
  22419. // back to the char code.
  22420. fontCharCode = this.toFontChar[charcode] || charcode;
  22421. if (this.missingFile) {
  22422. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22423. }
  22424. if (this.isType3Font) {
  22425. // Font char code in this case is actually a glyph name.
  22426. operatorListId = fontCharCode;
  22427. }
  22428. var accent = null;
  22429. if (this.seacMap && this.seacMap[charcode]) {
  22430. var seac = this.seacMap[charcode];
  22431. fontCharCode = seac.baseFontCharCode;
  22432. accent = {
  22433. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22434. offset: seac.accentOffset
  22435. };
  22436. }
  22437. var fontChar = String.fromCharCode(fontCharCode);
  22438. var glyph = this.glyphCache[charcode];
  22439. if (!glyph ||
  22440. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22441. operatorListId)) {
  22442. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22443. operatorListId);
  22444. this.glyphCache[charcode] = glyph;
  22445. }
  22446. return glyph;
  22447. },
  22448. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22449. var charsCache = this.charsCache;
  22450. var glyphs, glyph, charcode;
  22451. // if we translated this string before, just grab it from the cache
  22452. if (charsCache) {
  22453. glyphs = charsCache[chars];
  22454. if (glyphs) {
  22455. return glyphs;
  22456. }
  22457. }
  22458. // lazily create the translation cache
  22459. if (!charsCache) {
  22460. charsCache = this.charsCache = Object.create(null);
  22461. }
  22462. glyphs = [];
  22463. var charsCacheKey = chars;
  22464. var i = 0, ii;
  22465. if (this.cMap) {
  22466. // composite fonts have multi-byte strings convert the string from
  22467. // single-byte to multi-byte
  22468. var c = {};
  22469. while (i < chars.length) {
  22470. this.cMap.readCharCode(chars, i, c);
  22471. charcode = c.charcode;
  22472. var length = c.length;
  22473. i += length;
  22474. glyph = this.charToGlyph(charcode);
  22475. glyphs.push(glyph);
  22476. // placing null after each word break charcode (ASCII SPACE)
  22477. // Ignore occurences of 0x20 in multiple-byte codes.
  22478. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22479. glyphs.push(null);
  22480. }
  22481. }
  22482. } else {
  22483. for (i = 0, ii = chars.length; i < ii; ++i) {
  22484. charcode = chars.charCodeAt(i);
  22485. glyph = this.charToGlyph(charcode);
  22486. glyphs.push(glyph);
  22487. if (charcode === 0x20) {
  22488. glyphs.push(null);
  22489. }
  22490. }
  22491. }
  22492. // Enter the translated string into the cache
  22493. return (charsCache[charsCacheKey] = glyphs);
  22494. }
  22495. };
  22496. return Font;
  22497. })();
  22498. var ErrorFont = (function ErrorFontClosure() {
  22499. function ErrorFont(error) {
  22500. this.error = error;
  22501. this.loadedName = 'g_font_error';
  22502. this.loading = false;
  22503. }
  22504. ErrorFont.prototype = {
  22505. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22506. return [];
  22507. },
  22508. exportData: function ErrorFont_exportData() {
  22509. return {error: this.error};
  22510. }
  22511. };
  22512. return ErrorFont;
  22513. })();
  22514. /**
  22515. * Shared logic for building a char code to glyph id mapping for Type1 and
  22516. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22517. * @param {Object} properties Font properties object.
  22518. * @param {Object} builtInEncoding The encoding contained within the actual font
  22519. * data.
  22520. * @param {Array} Array of glyph names where the index is the glyph ID.
  22521. * @returns {Object} A char code to glyph ID map.
  22522. */
  22523. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22524. var charCodeToGlyphId = Object.create(null);
  22525. var glyphId, charCode, baseEncoding;
  22526. if (properties.baseEncodingName) {
  22527. // If a valid base encoding name was used, the mapping is initialized with
  22528. // that.
  22529. baseEncoding = Encodings[properties.baseEncodingName];
  22530. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22531. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22532. if (glyphId >= 0) {
  22533. charCodeToGlyphId[charCode] = glyphId;
  22534. }
  22535. }
  22536. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22537. // For a symbolic font the encoding should be the fonts built-in
  22538. // encoding.
  22539. for (charCode in builtInEncoding) {
  22540. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22541. }
  22542. } else {
  22543. // For non-symbolic fonts that don't have a base encoding the standard
  22544. // encoding should be used.
  22545. baseEncoding = Encodings.StandardEncoding;
  22546. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22547. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22548. if (glyphId >= 0) {
  22549. charCodeToGlyphId[charCode] = glyphId;
  22550. }
  22551. }
  22552. }
  22553. // Lastly, merge in the differences.
  22554. var differences = properties.differences;
  22555. if (differences) {
  22556. for (charCode in differences) {
  22557. var glyphName = differences[charCode];
  22558. glyphId = glyphNames.indexOf(glyphName);
  22559. if (glyphId >= 0) {
  22560. charCodeToGlyphId[charCode] = glyphId;
  22561. }
  22562. }
  22563. }
  22564. return charCodeToGlyphId;
  22565. }
  22566. /*
  22567. * CharStrings are encoded following the the CharString Encoding sequence
  22568. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22569. * The value in a byte indicates a command, a number, or subsequent bytes
  22570. * that are to be interpreted in a special way.
  22571. *
  22572. * CharString Number Encoding:
  22573. * A CharString byte containing the values from 32 through 255 inclusive
  22574. * indicate an integer. These values are decoded in four ranges.
  22575. *
  22576. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22577. * indicate the integer v - 139. Thus, the integer values from -107 through
  22578. * 107 inclusive may be encoded in single byte.
  22579. *
  22580. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22581. * indicates an integer involving the next byte, w, according to the formula:
  22582. * [(v - 247) x 256] + w + 108
  22583. *
  22584. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22585. * indicates an integer involving the next byte, w, according to the formula:
  22586. * -[(v - 251) * 256] - w - 108
  22587. *
  22588. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22589. * are a two complement signed integer. The first of these bytes contains the
  22590. * highest order bits, the second byte contains the next higher order bits
  22591. * and the fourth byte contain the lowest order bits.
  22592. *
  22593. *
  22594. * CharString Command Encoding:
  22595. * CharStrings commands are encoded in 1 or 2 bytes.
  22596. *
  22597. * Single byte commands are encoded in 1 byte that contains a value between
  22598. * 0 and 31 inclusive.
  22599. * If a command byte contains the value 12, then the value in the next byte
  22600. * indicates a command. This "escape" mechanism allows many extra commands
  22601. * to be encoded and this encoding technique helps to minimize the length of
  22602. * the charStrings.
  22603. */
  22604. var Type1CharString = (function Type1CharStringClosure() {
  22605. var COMMAND_MAP = {
  22606. 'hstem': [1],
  22607. 'vstem': [3],
  22608. 'vmoveto': [4],
  22609. 'rlineto': [5],
  22610. 'hlineto': [6],
  22611. 'vlineto': [7],
  22612. 'rrcurveto': [8],
  22613. 'callsubr': [10],
  22614. 'flex': [12, 35],
  22615. 'drop' : [12, 18],
  22616. 'endchar': [14],
  22617. 'rmoveto': [21],
  22618. 'hmoveto': [22],
  22619. 'vhcurveto': [30],
  22620. 'hvcurveto': [31]
  22621. };
  22622. function Type1CharString() {
  22623. this.width = 0;
  22624. this.lsb = 0;
  22625. this.flexing = false;
  22626. this.output = [];
  22627. this.stack = [];
  22628. }
  22629. Type1CharString.prototype = {
  22630. convert: function Type1CharString_convert(encoded, subrs) {
  22631. var count = encoded.length;
  22632. var error = false;
  22633. var wx, sbx, subrNumber;
  22634. for (var i = 0; i < count; i++) {
  22635. var value = encoded[i];
  22636. if (value < 32) {
  22637. if (value === 12) {
  22638. value = (value << 8) + encoded[++i];
  22639. }
  22640. switch (value) {
  22641. case 1: // hstem
  22642. if (!HINTING_ENABLED) {
  22643. this.stack = [];
  22644. break;
  22645. }
  22646. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22647. break;
  22648. case 3: // vstem
  22649. if (!HINTING_ENABLED) {
  22650. this.stack = [];
  22651. break;
  22652. }
  22653. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22654. break;
  22655. case 4: // vmoveto
  22656. if (this.flexing) {
  22657. if (this.stack.length < 1) {
  22658. error = true;
  22659. break;
  22660. }
  22661. // Add the dx for flex and but also swap the values so they are
  22662. // the right order.
  22663. var dy = this.stack.pop();
  22664. this.stack.push(0, dy);
  22665. break;
  22666. }
  22667. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  22668. break;
  22669. case 5: // rlineto
  22670. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  22671. break;
  22672. case 6: // hlineto
  22673. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  22674. break;
  22675. case 7: // vlineto
  22676. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  22677. break;
  22678. case 8: // rrcurveto
  22679. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  22680. break;
  22681. case 9: // closepath
  22682. // closepath is a Type1 command that does not take argument and is
  22683. // useless in Type2 and it can simply be ignored.
  22684. this.stack = [];
  22685. break;
  22686. case 10: // callsubr
  22687. if (this.stack.length < 1) {
  22688. error = true;
  22689. break;
  22690. }
  22691. subrNumber = this.stack.pop();
  22692. error = this.convert(subrs[subrNumber], subrs);
  22693. break;
  22694. case 11: // return
  22695. return error;
  22696. case 13: // hsbw
  22697. if (this.stack.length < 2) {
  22698. error = true;
  22699. break;
  22700. }
  22701. // To convert to type2 we have to move the width value to the
  22702. // first part of the charstring and then use hmoveto with lsb.
  22703. wx = this.stack.pop();
  22704. sbx = this.stack.pop();
  22705. this.lsb = sbx;
  22706. this.width = wx;
  22707. this.stack.push(wx, sbx);
  22708. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  22709. break;
  22710. case 14: // endchar
  22711. this.output.push(COMMAND_MAP.endchar[0]);
  22712. break;
  22713. case 21: // rmoveto
  22714. if (this.flexing) {
  22715. break;
  22716. }
  22717. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  22718. break;
  22719. case 22: // hmoveto
  22720. if (this.flexing) {
  22721. // Add the dy for flex.
  22722. this.stack.push(0);
  22723. break;
  22724. }
  22725. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  22726. break;
  22727. case 30: // vhcurveto
  22728. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  22729. break;
  22730. case 31: // hvcurveto
  22731. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  22732. break;
  22733. case (12 << 8) + 0: // dotsection
  22734. // dotsection is a Type1 command to specify some hinting feature
  22735. // for dots that do not take a parameter and it can safely be
  22736. // ignored for Type2.
  22737. this.stack = [];
  22738. break;
  22739. case (12 << 8) + 1: // vstem3
  22740. if (!HINTING_ENABLED) {
  22741. this.stack = [];
  22742. break;
  22743. }
  22744. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  22745. // multiple parameters, so instead of returning [vh]stem3 take a
  22746. // shortcut and return [vhstem] instead.
  22747. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22748. break;
  22749. case (12 << 8) + 2: // hstem3
  22750. if (!HINTING_ENABLED) {
  22751. this.stack = [];
  22752. break;
  22753. }
  22754. // See vstem3.
  22755. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22756. break;
  22757. case (12 << 8) + 6: // seac
  22758. // seac is like type 2's special endchar but it doesn't use the
  22759. // first argument asb, so remove it.
  22760. if (SEAC_ANALYSIS_ENABLED) {
  22761. this.seac = this.stack.splice(-4, 4);
  22762. error = this.executeCommand(0, COMMAND_MAP.endchar);
  22763. } else {
  22764. error = this.executeCommand(4, COMMAND_MAP.endchar);
  22765. }
  22766. break;
  22767. case (12 << 8) + 7: // sbw
  22768. if (this.stack.length < 4) {
  22769. error = true;
  22770. break;
  22771. }
  22772. // To convert to type2 we have to move the width value to the
  22773. // first part of the charstring and then use rmoveto with
  22774. // (dx, dy). The height argument will not be used for vmtx and
  22775. // vhea tables reconstruction -- ignoring it.
  22776. var wy = this.stack.pop();
  22777. wx = this.stack.pop();
  22778. var sby = this.stack.pop();
  22779. sbx = this.stack.pop();
  22780. this.lsb = sbx;
  22781. this.width = wx;
  22782. this.stack.push(wx, sbx, sby);
  22783. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  22784. break;
  22785. case (12 << 8) + 12: // div
  22786. if (this.stack.length < 2) {
  22787. error = true;
  22788. break;
  22789. }
  22790. var num2 = this.stack.pop();
  22791. var num1 = this.stack.pop();
  22792. this.stack.push(num1 / num2);
  22793. break;
  22794. case (12 << 8) + 16: // callothersubr
  22795. if (this.stack.length < 2) {
  22796. error = true;
  22797. break;
  22798. }
  22799. subrNumber = this.stack.pop();
  22800. var numArgs = this.stack.pop();
  22801. if (subrNumber === 0 && numArgs === 3) {
  22802. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  22803. this.stack.push(
  22804. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  22805. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  22806. flexArgs[4], // bcp2x
  22807. flexArgs[5], // bcp2y
  22808. flexArgs[6], // p2x
  22809. flexArgs[7], // p2y
  22810. flexArgs[8], // bcp3x
  22811. flexArgs[9], // bcp3y
  22812. flexArgs[10], // bcp4x
  22813. flexArgs[11], // bcp4y
  22814. flexArgs[12], // p3x
  22815. flexArgs[13], // p3y
  22816. flexArgs[14] // flexDepth
  22817. // 15 = finalx unused by flex
  22818. // 16 = finaly unused by flex
  22819. );
  22820. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  22821. this.flexing = false;
  22822. this.stack.push(flexArgs[15], flexArgs[16]);
  22823. } else if (subrNumber === 1 && numArgs === 0) {
  22824. this.flexing = true;
  22825. }
  22826. break;
  22827. case (12 << 8) + 17: // pop
  22828. // Ignore this since it is only used with othersubr.
  22829. break;
  22830. case (12 << 8) + 33: // setcurrentpoint
  22831. // Ignore for now.
  22832. this.stack = [];
  22833. break;
  22834. default:
  22835. warn('Unknown type 1 charstring command of "' + value + '"');
  22836. break;
  22837. }
  22838. if (error) {
  22839. break;
  22840. }
  22841. continue;
  22842. } else if (value <= 246) {
  22843. value = value - 139;
  22844. } else if (value <= 250) {
  22845. value = ((value - 247) * 256) + encoded[++i] + 108;
  22846. } else if (value <= 254) {
  22847. value = -((value - 251) * 256) - encoded[++i] - 108;
  22848. } else {
  22849. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  22850. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  22851. }
  22852. this.stack.push(value);
  22853. }
  22854. return error;
  22855. },
  22856. executeCommand: function(howManyArgs, command, keepStack) {
  22857. var stackLength = this.stack.length;
  22858. if (howManyArgs > stackLength) {
  22859. return true;
  22860. }
  22861. var start = stackLength - howManyArgs;
  22862. for (var i = start; i < stackLength; i++) {
  22863. var value = this.stack[i];
  22864. if (value === (value | 0)) { // int
  22865. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  22866. } else { // fixed point
  22867. value = (65536 * value) | 0;
  22868. this.output.push(255,
  22869. (value >> 24) & 0xFF,
  22870. (value >> 16) & 0xFF,
  22871. (value >> 8) & 0xFF,
  22872. value & 0xFF);
  22873. }
  22874. }
  22875. this.output.push.apply(this.output, command);
  22876. if (keepStack) {
  22877. this.stack.splice(start, howManyArgs);
  22878. } else {
  22879. this.stack.length = 0;
  22880. }
  22881. return false;
  22882. }
  22883. };
  22884. return Type1CharString;
  22885. })();
  22886. /*
  22887. * Type1Parser encapsulate the needed code for parsing a Type1 font
  22888. * program. Some of its logic depends on the Type2 charstrings
  22889. * structure.
  22890. * Note: this doesn't really parse the font since that would require evaluation
  22891. * of PostScript, but it is possible in most cases to extract what we need
  22892. * without a full parse.
  22893. */
  22894. var Type1Parser = (function Type1ParserClosure() {
  22895. /*
  22896. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  22897. * of Plaintext Bytes. The function took a key as a parameter which can be
  22898. * for decrypting the eexec block of for decoding charStrings.
  22899. */
  22900. var EEXEC_ENCRYPT_KEY = 55665;
  22901. var CHAR_STRS_ENCRYPT_KEY = 4330;
  22902. function isHexDigit(code) {
  22903. return code >= 48 && code <= 57 || // '0'-'9'
  22904. code >= 65 && code <= 70 || // 'A'-'F'
  22905. code >= 97 && code <= 102; // 'a'-'f'
  22906. }
  22907. function decrypt(data, key, discardNumber) {
  22908. var r = key | 0, c1 = 52845, c2 = 22719;
  22909. var count = data.length;
  22910. var decrypted = new Uint8Array(count);
  22911. for (var i = 0; i < count; i++) {
  22912. var value = data[i];
  22913. decrypted[i] = value ^ (r >> 8);
  22914. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  22915. }
  22916. return Array.prototype.slice.call(decrypted, discardNumber);
  22917. }
  22918. function decryptAscii(data, key, discardNumber) {
  22919. var r = key | 0, c1 = 52845, c2 = 22719;
  22920. var count = data.length, maybeLength = count >>> 1;
  22921. var decrypted = new Uint8Array(maybeLength);
  22922. var i, j;
  22923. for (i = 0, j = 0; i < count; i++) {
  22924. var digit1 = data[i];
  22925. if (!isHexDigit(digit1)) {
  22926. continue;
  22927. }
  22928. i++;
  22929. var digit2;
  22930. while (i < count && !isHexDigit(digit2 = data[i])) {
  22931. i++;
  22932. }
  22933. if (i < count) {
  22934. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  22935. decrypted[j++] = value ^ (r >> 8);
  22936. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  22937. }
  22938. }
  22939. return Array.prototype.slice.call(decrypted, discardNumber, j);
  22940. }
  22941. function isSpecial(c) {
  22942. return c === 0x2F || // '/'
  22943. c === 0x5B || c === 0x5D || // '[', ']'
  22944. c === 0x7B || c === 0x7D || // '{', '}'
  22945. c === 0x28 || c === 0x29; // '(', ')'
  22946. }
  22947. function Type1Parser(stream, encrypted) {
  22948. if (encrypted) {
  22949. var data = stream.getBytes();
  22950. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  22951. isHexDigit(data[2]) && isHexDigit(data[3]));
  22952. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  22953. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  22954. }
  22955. this.stream = stream;
  22956. this.nextChar();
  22957. }
  22958. Type1Parser.prototype = {
  22959. readNumberArray: function Type1Parser_readNumberArray() {
  22960. this.getToken(); // read '[' or '{' (arrays can start with either)
  22961. var array = [];
  22962. while (true) {
  22963. var token = this.getToken();
  22964. if (token === null || token === ']' || token === '}') {
  22965. break;
  22966. }
  22967. array.push(parseFloat(token || 0));
  22968. }
  22969. return array;
  22970. },
  22971. readNumber: function Type1Parser_readNumber() {
  22972. var token = this.getToken();
  22973. return parseFloat(token || 0);
  22974. },
  22975. readInt: function Type1Parser_readInt() {
  22976. // Use '| 0' to prevent setting a double into length such as the double
  22977. // does not flow into the loop variable.
  22978. var token = this.getToken();
  22979. return parseInt(token || 0, 10) | 0;
  22980. },
  22981. readBoolean: function Type1Parser_readBoolean() {
  22982. var token = this.getToken();
  22983. // Use 1 and 0 since that's what type2 charstrings use.
  22984. return token === 'true' ? 1 : 0;
  22985. },
  22986. nextChar : function Type1_nextChar() {
  22987. return (this.currentChar = this.stream.getByte());
  22988. },
  22989. getToken: function Type1Parser_getToken() {
  22990. // Eat whitespace and comments.
  22991. var comment = false;
  22992. var ch = this.currentChar;
  22993. while (true) {
  22994. if (ch === -1) {
  22995. return null;
  22996. }
  22997. if (comment) {
  22998. if (ch === 0x0A || ch === 0x0D) {
  22999. comment = false;
  23000. }
  23001. } else if (ch === 0x25) { // '%'
  23002. comment = true;
  23003. } else if (!Lexer.isSpace(ch)) {
  23004. break;
  23005. }
  23006. ch = this.nextChar();
  23007. }
  23008. if (isSpecial(ch)) {
  23009. this.nextChar();
  23010. return String.fromCharCode(ch);
  23011. }
  23012. var token = '';
  23013. do {
  23014. token += String.fromCharCode(ch);
  23015. ch = this.nextChar();
  23016. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23017. return token;
  23018. },
  23019. /*
  23020. * Returns an object containing a Subrs array and a CharStrings
  23021. * array extracted from and eexec encrypted block of data
  23022. */
  23023. extractFontProgram: function Type1Parser_extractFontProgram() {
  23024. var stream = this.stream;
  23025. var subrs = [], charstrings = [];
  23026. var program = {
  23027. subrs: [],
  23028. charstrings: [],
  23029. properties: {
  23030. 'privateData': {
  23031. 'lenIV': 4
  23032. }
  23033. }
  23034. };
  23035. var token, length, data, lenIV, encoded;
  23036. while ((token = this.getToken()) !== null) {
  23037. if (token !== '/') {
  23038. continue;
  23039. }
  23040. token = this.getToken();
  23041. switch (token) {
  23042. case 'CharStrings':
  23043. // The number immediately following CharStrings must be greater or
  23044. // equal to the number of CharStrings.
  23045. this.getToken();
  23046. this.getToken(); // read in 'dict'
  23047. this.getToken(); // read in 'dup'
  23048. this.getToken(); // read in 'begin'
  23049. while(true) {
  23050. token = this.getToken();
  23051. if (token === null || token === 'end') {
  23052. break;
  23053. }
  23054. if (token !== '/') {
  23055. continue;
  23056. }
  23057. var glyph = this.getToken();
  23058. length = this.readInt();
  23059. this.getToken(); // read in 'RD' or '-|'
  23060. data = stream.makeSubStream(stream.pos, length);
  23061. lenIV = program.properties.privateData['lenIV'];
  23062. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23063. // Skip past the required space and binary data.
  23064. stream.skip(length);
  23065. this.nextChar();
  23066. token = this.getToken(); // read in 'ND' or '|-'
  23067. if (token === 'noaccess') {
  23068. this.getToken(); // read in 'def'
  23069. }
  23070. charstrings.push({
  23071. glyph: glyph,
  23072. encoded: encoded
  23073. });
  23074. }
  23075. break;
  23076. case 'Subrs':
  23077. var num = this.readInt();
  23078. this.getToken(); // read in 'array'
  23079. while ((token = this.getToken()) === 'dup') {
  23080. var index = this.readInt();
  23081. length = this.readInt();
  23082. this.getToken(); // read in 'RD' or '-|'
  23083. data = stream.makeSubStream(stream.pos, length);
  23084. lenIV = program.properties.privateData['lenIV'];
  23085. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23086. // Skip past the required space and binary data.
  23087. stream.skip(length);
  23088. this.nextChar();
  23089. token = this.getToken(); // read in 'NP' or '|'
  23090. if (token === 'noaccess') {
  23091. this.getToken(); // read in 'put'
  23092. }
  23093. subrs[index] = encoded;
  23094. }
  23095. break;
  23096. case 'BlueValues':
  23097. case 'OtherBlues':
  23098. case 'FamilyBlues':
  23099. case 'FamilyOtherBlues':
  23100. var blueArray = this.readNumberArray();
  23101. // *Blue* values may contain invalid data: disables reading of
  23102. // those values when hinting is disabled.
  23103. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23104. HINTING_ENABLED) {
  23105. program.properties.privateData[token] = blueArray;
  23106. }
  23107. break;
  23108. case 'StemSnapH':
  23109. case 'StemSnapV':
  23110. program.properties.privateData[token] = this.readNumberArray();
  23111. break;
  23112. case 'StdHW':
  23113. case 'StdVW':
  23114. program.properties.privateData[token] =
  23115. this.readNumberArray()[0];
  23116. break;
  23117. case 'BlueShift':
  23118. case 'lenIV':
  23119. case 'BlueFuzz':
  23120. case 'BlueScale':
  23121. case 'LanguageGroup':
  23122. case 'ExpansionFactor':
  23123. program.properties.privateData[token] = this.readNumber();
  23124. break;
  23125. case 'ForceBold':
  23126. program.properties.privateData[token] = this.readBoolean();
  23127. break;
  23128. }
  23129. }
  23130. for (var i = 0; i < charstrings.length; i++) {
  23131. glyph = charstrings[i].glyph;
  23132. encoded = charstrings[i].encoded;
  23133. var charString = new Type1CharString();
  23134. var error = charString.convert(encoded, subrs);
  23135. var output = charString.output;
  23136. if (error) {
  23137. // It seems when FreeType encounters an error while evaluating a glyph
  23138. // that it completely ignores the glyph so we'll mimic that behaviour
  23139. // here and put an endchar to make the validator happy.
  23140. output = [14];
  23141. }
  23142. program.charstrings.push({
  23143. glyphName: glyph,
  23144. charstring: output,
  23145. width: charString.width,
  23146. lsb: charString.lsb,
  23147. seac: charString.seac
  23148. });
  23149. }
  23150. return program;
  23151. },
  23152. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23153. var token;
  23154. while ((token = this.getToken()) !== null) {
  23155. if (token !== '/') {
  23156. continue;
  23157. }
  23158. token = this.getToken();
  23159. switch (token) {
  23160. case 'FontMatrix':
  23161. var matrix = this.readNumberArray();
  23162. properties.fontMatrix = matrix;
  23163. break;
  23164. case 'Encoding':
  23165. var encodingArg = this.getToken();
  23166. var encoding;
  23167. if (!/^\d+$/.test(encodingArg)) {
  23168. // encoding name is specified
  23169. encoding = Encodings[encodingArg];
  23170. } else {
  23171. encoding = [];
  23172. var size = parseInt(encodingArg, 10) | 0;
  23173. this.getToken(); // read in 'array'
  23174. for (var j = 0; j < size; j++) {
  23175. token = this.getToken();
  23176. // skipping till first dup or def (e.g. ignoring for statement)
  23177. while (token !== 'dup' && token !== 'def') {
  23178. token = this.getToken();
  23179. if (token === null) {
  23180. return; // invalid header
  23181. }
  23182. }
  23183. if (token === 'def') {
  23184. break; // read all array data
  23185. }
  23186. var index = this.readInt();
  23187. this.getToken(); // read in '/'
  23188. var glyph = this.getToken();
  23189. encoding[index] = glyph;
  23190. this.getToken(); // read the in 'put'
  23191. }
  23192. }
  23193. properties.builtInEncoding = encoding;
  23194. break;
  23195. case 'FontBBox':
  23196. var fontBBox = this.readNumberArray();
  23197. // adjusting ascent/descent
  23198. properties.ascent = fontBBox[3];
  23199. properties.descent = fontBBox[1];
  23200. properties.ascentScaled = true;
  23201. break;
  23202. }
  23203. }
  23204. }
  23205. };
  23206. return Type1Parser;
  23207. })();
  23208. /**
  23209. * The CFF class takes a Type1 file and wrap it into a
  23210. * 'Compact Font Format' which itself embed Type2 charstrings.
  23211. */
  23212. var CFFStandardStrings = [
  23213. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23214. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23215. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23216. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23217. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23218. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23219. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23220. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23221. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23222. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23223. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23224. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23225. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23226. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23227. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23228. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23229. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23230. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23231. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23232. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23233. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23234. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23235. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23236. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23237. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23238. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23239. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23240. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23241. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23242. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23243. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23244. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23245. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23246. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23247. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23248. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23249. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23250. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23251. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23252. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23253. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23254. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23255. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23256. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23257. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23258. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23259. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23260. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23261. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23262. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23263. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23264. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23265. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23266. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23267. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23268. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23269. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23270. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23271. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23272. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23273. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23274. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23275. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23276. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23277. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23278. ];
  23279. // Type1Font is also a CIDFontType0.
  23280. var Type1Font = function Type1Font(name, file, properties) {
  23281. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23282. // Also, length1 and length2 might be off by 6 bytes as well.
  23283. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23284. var PFB_HEADER_SIZE = 6;
  23285. var headerBlockLength = properties.length1;
  23286. var eexecBlockLength = properties.length2;
  23287. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23288. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23289. if (pfbHeaderPresent) {
  23290. file.skip(PFB_HEADER_SIZE);
  23291. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23292. (pfbHeader[3] << 8) | pfbHeader[2];
  23293. }
  23294. // Get the data block containing glyphs and subrs informations
  23295. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23296. var headerBlockParser = new Type1Parser(headerBlock);
  23297. headerBlockParser.extractFontHeader(properties);
  23298. if (pfbHeaderPresent) {
  23299. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23300. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23301. (pfbHeader[3] << 8) | pfbHeader[2];
  23302. }
  23303. // Decrypt the data blocks and retrieve it's content
  23304. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23305. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23306. var data = eexecBlockParser.extractFontProgram();
  23307. for (var info in data.properties) {
  23308. properties[info] = data.properties[info];
  23309. }
  23310. var charstrings = data.charstrings;
  23311. var type2Charstrings = this.getType2Charstrings(charstrings);
  23312. var subrs = this.getType2Subrs(data.subrs);
  23313. this.charstrings = charstrings;
  23314. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23315. subrs, properties);
  23316. this.seacs = this.getSeacs(data.charstrings);
  23317. };
  23318. Type1Font.prototype = {
  23319. get numGlyphs() {
  23320. return this.charstrings.length + 1;
  23321. },
  23322. getCharset: function Type1Font_getCharset() {
  23323. var charset = ['.notdef'];
  23324. var charstrings = this.charstrings;
  23325. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23326. charset.push(charstrings[glyphId].glyphName);
  23327. }
  23328. return charset;
  23329. },
  23330. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23331. var charstrings = this.charstrings;
  23332. var glyphNames = ['.notdef'], glyphId;
  23333. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23334. glyphNames.push(charstrings[glyphId].glyphName);
  23335. }
  23336. var encoding = properties.builtInEncoding;
  23337. if (encoding) {
  23338. var builtInEncoding = {};
  23339. for (var charCode in encoding) {
  23340. glyphId = glyphNames.indexOf(encoding[charCode]);
  23341. if (glyphId >= 0) {
  23342. builtInEncoding[charCode] = glyphId;
  23343. }
  23344. }
  23345. }
  23346. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23347. },
  23348. getSeacs: function Type1Font_getSeacs(charstrings) {
  23349. var i, ii;
  23350. var seacMap = [];
  23351. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23352. var charstring = charstrings[i];
  23353. if (charstring.seac) {
  23354. // Offset by 1 for .notdef
  23355. seacMap[i + 1] = charstring.seac;
  23356. }
  23357. }
  23358. return seacMap;
  23359. },
  23360. getType2Charstrings: function Type1Font_getType2Charstrings(
  23361. type1Charstrings) {
  23362. var type2Charstrings = [];
  23363. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23364. type2Charstrings.push(type1Charstrings[i].charstring);
  23365. }
  23366. return type2Charstrings;
  23367. },
  23368. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23369. var bias = 0;
  23370. var count = type1Subrs.length;
  23371. if (count < 1133) {
  23372. bias = 107;
  23373. } else if (count < 33769) {
  23374. bias = 1131;
  23375. } else {
  23376. bias = 32768;
  23377. }
  23378. // Add a bunch of empty subrs to deal with the Type2 bias
  23379. var type2Subrs = [];
  23380. var i;
  23381. for (i = 0; i < bias; i++) {
  23382. type2Subrs.push([0x0B]);
  23383. }
  23384. for (i = 0; i < count; i++) {
  23385. type2Subrs.push(type1Subrs[i]);
  23386. }
  23387. return type2Subrs;
  23388. },
  23389. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23390. var cff = new CFF();
  23391. cff.header = new CFFHeader(1, 0, 4, 4);
  23392. cff.names = [name];
  23393. var topDict = new CFFTopDict();
  23394. // CFF strings IDs 0...390 are predefined names, so refering
  23395. // to entries in our own String INDEX starts at SID 391.
  23396. topDict.setByName('version', 391);
  23397. topDict.setByName('Notice', 392);
  23398. topDict.setByName('FullName', 393);
  23399. topDict.setByName('FamilyName', 394);
  23400. topDict.setByName('Weight', 395);
  23401. topDict.setByName('Encoding', null); // placeholder
  23402. topDict.setByName('FontMatrix', properties.fontMatrix);
  23403. topDict.setByName('FontBBox', properties.bbox);
  23404. topDict.setByName('charset', null); // placeholder
  23405. topDict.setByName('CharStrings', null); // placeholder
  23406. topDict.setByName('Private', null); // placeholder
  23407. cff.topDict = topDict;
  23408. var strings = new CFFStrings();
  23409. strings.add('Version 0.11'); // Version
  23410. strings.add('See original notice'); // Notice
  23411. strings.add(name); // FullName
  23412. strings.add(name); // FamilyName
  23413. strings.add('Medium'); // Weight
  23414. cff.strings = strings;
  23415. cff.globalSubrIndex = new CFFIndex();
  23416. var count = glyphs.length;
  23417. var charsetArray = [0];
  23418. var i, ii;
  23419. for (i = 0; i < count; i++) {
  23420. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23421. // TODO: Insert the string and correctly map it. Previously it was
  23422. // thought mapping names that aren't in the standard strings to .notdef
  23423. // was fine, however in issue818 when mapping them all to .notdef the
  23424. // adieresis glyph no longer worked.
  23425. if (index === -1) {
  23426. index = 0;
  23427. }
  23428. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23429. }
  23430. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23431. var charStringsIndex = new CFFIndex();
  23432. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23433. for (i = 0; i < count; i++) {
  23434. charStringsIndex.add(glyphs[i]);
  23435. }
  23436. cff.charStrings = charStringsIndex;
  23437. var privateDict = new CFFPrivateDict();
  23438. privateDict.setByName('Subrs', null); // placeholder
  23439. var fields = [
  23440. 'BlueValues',
  23441. 'OtherBlues',
  23442. 'FamilyBlues',
  23443. 'FamilyOtherBlues',
  23444. 'StemSnapH',
  23445. 'StemSnapV',
  23446. 'BlueShift',
  23447. 'BlueFuzz',
  23448. 'BlueScale',
  23449. 'LanguageGroup',
  23450. 'ExpansionFactor',
  23451. 'ForceBold',
  23452. 'StdHW',
  23453. 'StdVW'
  23454. ];
  23455. for (i = 0, ii = fields.length; i < ii; i++) {
  23456. var field = fields[i];
  23457. if (!properties.privateData.hasOwnProperty(field)) {
  23458. continue;
  23459. }
  23460. var value = properties.privateData[field];
  23461. if (isArray(value)) {
  23462. // All of the private dictionary array data in CFF must be stored as
  23463. // "delta-encoded" numbers.
  23464. for (var j = value.length - 1; j > 0; j--) {
  23465. value[j] -= value[j - 1]; // ... difference from previous value
  23466. }
  23467. }
  23468. privateDict.setByName(field, value);
  23469. }
  23470. cff.topDict.privateDict = privateDict;
  23471. var subrIndex = new CFFIndex();
  23472. for (i = 0, ii = subrs.length; i < ii; i++) {
  23473. subrIndex.add(subrs[i]);
  23474. }
  23475. privateDict.subrsIndex = subrIndex;
  23476. var compiler = new CFFCompiler(cff);
  23477. return compiler.compile();
  23478. }
  23479. };
  23480. var CFFFont = (function CFFFontClosure() {
  23481. function CFFFont(file, properties) {
  23482. this.properties = properties;
  23483. var parser = new CFFParser(file, properties);
  23484. this.cff = parser.parse();
  23485. var compiler = new CFFCompiler(this.cff);
  23486. this.seacs = this.cff.seacs;
  23487. try {
  23488. this.data = compiler.compile();
  23489. } catch (e) {
  23490. warn('Failed to compile font ' + properties.loadedName);
  23491. // There may have just been an issue with the compiler, set the data
  23492. // anyway and hope the font loaded.
  23493. this.data = file;
  23494. }
  23495. }
  23496. CFFFont.prototype = {
  23497. get numGlyphs() {
  23498. return this.cff.charStrings.count;
  23499. },
  23500. getCharset: function CFFFont_getCharset() {
  23501. return this.cff.charset.charset;
  23502. },
  23503. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23504. var cff = this.cff;
  23505. var properties = this.properties;
  23506. var charsets = cff.charset.charset;
  23507. var charCodeToGlyphId;
  23508. var glyphId;
  23509. if (properties.composite) {
  23510. charCodeToGlyphId = Object.create(null);
  23511. if (cff.isCIDFont) {
  23512. // If the font is actually a CID font then we should use the charset
  23513. // to map CIDs to GIDs.
  23514. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23515. var cid = charsets[glyphId];
  23516. var charCode = properties.cMap.charCodeOf(cid);
  23517. charCodeToGlyphId[charCode] = glyphId;
  23518. }
  23519. } else {
  23520. // If it is NOT actually a CID font then CIDs should be mapped
  23521. // directly to GIDs.
  23522. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23523. charCodeToGlyphId[glyphId] = glyphId;
  23524. }
  23525. }
  23526. return charCodeToGlyphId;
  23527. }
  23528. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23529. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23530. return charCodeToGlyphId;
  23531. }
  23532. };
  23533. return CFFFont;
  23534. })();
  23535. var CFFParser = (function CFFParserClosure() {
  23536. var CharstringValidationData = [
  23537. null,
  23538. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23539. null,
  23540. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23541. { id: 'vmoveto', min: 1, stackClearing: true },
  23542. { id: 'rlineto', min: 2, resetStack: true },
  23543. { id: 'hlineto', min: 1, resetStack: true },
  23544. { id: 'vlineto', min: 1, resetStack: true },
  23545. { id: 'rrcurveto', min: 6, resetStack: true },
  23546. null,
  23547. { id: 'callsubr', min: 1, undefStack: true },
  23548. { id: 'return', min: 0, undefStack: true },
  23549. null, // 12
  23550. null,
  23551. { id: 'endchar', min: 0, stackClearing: true },
  23552. null,
  23553. null,
  23554. null,
  23555. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23556. { id: 'hintmask', min: 0, stackClearing: true },
  23557. { id: 'cntrmask', min: 0, stackClearing: true },
  23558. { id: 'rmoveto', min: 2, stackClearing: true },
  23559. { id: 'hmoveto', min: 1, stackClearing: true },
  23560. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23561. { id: 'rcurveline', min: 8, resetStack: true },
  23562. { id: 'rlinecurve', min: 8, resetStack: true },
  23563. { id: 'vvcurveto', min: 4, resetStack: true },
  23564. { id: 'hhcurveto', min: 4, resetStack: true },
  23565. null, // shortint
  23566. { id: 'callgsubr', min: 1, undefStack: true },
  23567. { id: 'vhcurveto', min: 4, resetStack: true },
  23568. { id: 'hvcurveto', min: 4, resetStack: true }
  23569. ];
  23570. var CharstringValidationData12 = [
  23571. null,
  23572. null,
  23573. null,
  23574. { id: 'and', min: 2, stackDelta: -1 },
  23575. { id: 'or', min: 2, stackDelta: -1 },
  23576. { id: 'not', min: 1, stackDelta: 0 },
  23577. null,
  23578. null,
  23579. null,
  23580. { id: 'abs', min: 1, stackDelta: 0 },
  23581. { id: 'add', min: 2, stackDelta: -1,
  23582. stackFn: function stack_div(stack, index) {
  23583. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23584. }
  23585. },
  23586. { id: 'sub', min: 2, stackDelta: -1,
  23587. stackFn: function stack_div(stack, index) {
  23588. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23589. }
  23590. },
  23591. { id: 'div', min: 2, stackDelta: -1,
  23592. stackFn: function stack_div(stack, index) {
  23593. stack[index - 2] = stack[index - 2] / stack[index - 1];
  23594. }
  23595. },
  23596. null,
  23597. { id: 'neg', min: 1, stackDelta: 0,
  23598. stackFn: function stack_div(stack, index) {
  23599. stack[index - 1] = -stack[index - 1];
  23600. }
  23601. },
  23602. { id: 'eq', min: 2, stackDelta: -1 },
  23603. null,
  23604. null,
  23605. { id: 'drop', min: 1, stackDelta: -1 },
  23606. null,
  23607. { id: 'put', min: 2, stackDelta: -2 },
  23608. { id: 'get', min: 1, stackDelta: 0 },
  23609. { id: 'ifelse', min: 4, stackDelta: -3 },
  23610. { id: 'random', min: 0, stackDelta: 1 },
  23611. { id: 'mul', min: 2, stackDelta: -1,
  23612. stackFn: function stack_div(stack, index) {
  23613. stack[index - 2] = stack[index - 2] * stack[index - 1];
  23614. }
  23615. },
  23616. null,
  23617. { id: 'sqrt', min: 1, stackDelta: 0 },
  23618. { id: 'dup', min: 1, stackDelta: 1 },
  23619. { id: 'exch', min: 2, stackDelta: 0 },
  23620. { id: 'index', min: 2, stackDelta: 0 },
  23621. { id: 'roll', min: 3, stackDelta: -2 },
  23622. null,
  23623. null,
  23624. null,
  23625. { id: 'hflex', min: 7, resetStack: true },
  23626. { id: 'flex', min: 13, resetStack: true },
  23627. { id: 'hflex1', min: 9, resetStack: true },
  23628. { id: 'flex1', min: 11, resetStack: true }
  23629. ];
  23630. function CFFParser(file, properties) {
  23631. this.bytes = file.getBytes();
  23632. this.properties = properties;
  23633. }
  23634. CFFParser.prototype = {
  23635. parse: function CFFParser_parse() {
  23636. var properties = this.properties;
  23637. var cff = new CFF();
  23638. this.cff = cff;
  23639. // The first five sections must be in order, all the others are reached
  23640. // via offsets contained in one of the below.
  23641. var header = this.parseHeader();
  23642. var nameIndex = this.parseIndex(header.endPos);
  23643. var topDictIndex = this.parseIndex(nameIndex.endPos);
  23644. var stringIndex = this.parseIndex(topDictIndex.endPos);
  23645. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  23646. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  23647. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  23648. cff.header = header.obj;
  23649. cff.names = this.parseNameIndex(nameIndex.obj);
  23650. cff.strings = this.parseStringIndex(stringIndex.obj);
  23651. cff.topDict = topDict;
  23652. cff.globalSubrIndex = globalSubrIndex.obj;
  23653. this.parsePrivateDict(cff.topDict);
  23654. cff.isCIDFont = topDict.hasName('ROS');
  23655. var charStringOffset = topDict.getByName('CharStrings');
  23656. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  23657. cff.charStrings = charStringsAndSeacs.charStrings;
  23658. cff.seacs = charStringsAndSeacs.seacs;
  23659. cff.widths = charStringsAndSeacs.widths;
  23660. var fontMatrix = topDict.getByName('FontMatrix');
  23661. if (fontMatrix) {
  23662. properties.fontMatrix = fontMatrix;
  23663. }
  23664. var fontBBox = topDict.getByName('FontBBox');
  23665. if (fontBBox) {
  23666. // adjusting ascent/descent
  23667. properties.ascent = fontBBox[3];
  23668. properties.descent = fontBBox[1];
  23669. properties.ascentScaled = true;
  23670. }
  23671. var charset, encoding;
  23672. if (cff.isCIDFont) {
  23673. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  23674. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  23675. var dictRaw = fdArrayIndex.get(i);
  23676. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  23677. cff.strings);
  23678. this.parsePrivateDict(fontDict);
  23679. cff.fdArray.push(fontDict);
  23680. }
  23681. // cid fonts don't have an encoding
  23682. encoding = null;
  23683. charset = this.parseCharsets(topDict.getByName('charset'),
  23684. cff.charStrings.count, cff.strings, true);
  23685. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  23686. cff.charStrings.count);
  23687. } else {
  23688. charset = this.parseCharsets(topDict.getByName('charset'),
  23689. cff.charStrings.count, cff.strings, false);
  23690. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  23691. properties,
  23692. cff.strings, charset.charset);
  23693. }
  23694. cff.charset = charset;
  23695. cff.encoding = encoding;
  23696. return cff;
  23697. },
  23698. parseHeader: function CFFParser_parseHeader() {
  23699. var bytes = this.bytes;
  23700. var bytesLength = bytes.length;
  23701. var offset = 0;
  23702. // Prevent an infinite loop, by checking that the offset is within the
  23703. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  23704. while (offset < bytesLength && bytes[offset] !== 1) {
  23705. ++offset;
  23706. }
  23707. if (offset >= bytesLength) {
  23708. error('Invalid CFF header');
  23709. } else if (offset !== 0) {
  23710. info('cff data is shifted');
  23711. bytes = bytes.subarray(offset);
  23712. this.bytes = bytes;
  23713. }
  23714. var major = bytes[0];
  23715. var minor = bytes[1];
  23716. var hdrSize = bytes[2];
  23717. var offSize = bytes[3];
  23718. var header = new CFFHeader(major, minor, hdrSize, offSize);
  23719. return { obj: header, endPos: hdrSize };
  23720. },
  23721. parseDict: function CFFParser_parseDict(dict) {
  23722. var pos = 0;
  23723. function parseOperand() {
  23724. var value = dict[pos++];
  23725. if (value === 30) {
  23726. return parseFloatOperand(pos);
  23727. } else if (value === 28) {
  23728. value = dict[pos++];
  23729. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  23730. return value;
  23731. } else if (value === 29) {
  23732. value = dict[pos++];
  23733. value = (value << 8) | dict[pos++];
  23734. value = (value << 8) | dict[pos++];
  23735. value = (value << 8) | dict[pos++];
  23736. return value;
  23737. } else if (value >= 32 && value <= 246) {
  23738. return value - 139;
  23739. } else if (value >= 247 && value <= 250) {
  23740. return ((value - 247) * 256) + dict[pos++] + 108;
  23741. } else if (value >= 251 && value <= 254) {
  23742. return -((value - 251) * 256) - dict[pos++] - 108;
  23743. } else {
  23744. error('255 is not a valid DICT command');
  23745. }
  23746. return -1;
  23747. }
  23748. function parseFloatOperand() {
  23749. var str = '';
  23750. var eof = 15;
  23751. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  23752. '9', '.', 'E', 'E-', null, '-'];
  23753. var length = dict.length;
  23754. while (pos < length) {
  23755. var b = dict[pos++];
  23756. var b1 = b >> 4;
  23757. var b2 = b & 15;
  23758. if (b1 === eof) {
  23759. break;
  23760. }
  23761. str += lookup[b1];
  23762. if (b2 === eof) {
  23763. break;
  23764. }
  23765. str += lookup[b2];
  23766. }
  23767. return parseFloat(str);
  23768. }
  23769. var operands = [];
  23770. var entries = [];
  23771. pos = 0;
  23772. var end = dict.length;
  23773. while (pos < end) {
  23774. var b = dict[pos];
  23775. if (b <= 21) {
  23776. if (b === 12) {
  23777. b = (b << 8) | dict[++pos];
  23778. }
  23779. entries.push([b, operands]);
  23780. operands = [];
  23781. ++pos;
  23782. } else {
  23783. operands.push(parseOperand());
  23784. }
  23785. }
  23786. return entries;
  23787. },
  23788. parseIndex: function CFFParser_parseIndex(pos) {
  23789. var cffIndex = new CFFIndex();
  23790. var bytes = this.bytes;
  23791. var count = (bytes[pos++] << 8) | bytes[pos++];
  23792. var offsets = [];
  23793. var end = pos;
  23794. var i, ii;
  23795. if (count !== 0) {
  23796. var offsetSize = bytes[pos++];
  23797. // add 1 for offset to determine size of last object
  23798. var startPos = pos + ((count + 1) * offsetSize) - 1;
  23799. for (i = 0, ii = count + 1; i < ii; ++i) {
  23800. var offset = 0;
  23801. for (var j = 0; j < offsetSize; ++j) {
  23802. offset <<= 8;
  23803. offset += bytes[pos++];
  23804. }
  23805. offsets.push(startPos + offset);
  23806. }
  23807. end = offsets[count];
  23808. }
  23809. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  23810. var offsetStart = offsets[i];
  23811. var offsetEnd = offsets[i + 1];
  23812. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  23813. }
  23814. return {obj: cffIndex, endPos: end};
  23815. },
  23816. parseNameIndex: function CFFParser_parseNameIndex(index) {
  23817. var names = [];
  23818. for (var i = 0, ii = index.count; i < ii; ++i) {
  23819. var name = index.get(i);
  23820. // OTS doesn't allow names to be over 127 characters.
  23821. var length = Math.min(name.length, 127);
  23822. var data = [];
  23823. // OTS also only permits certain characters in the name.
  23824. for (var j = 0; j < length; ++j) {
  23825. var c = name[j];
  23826. if (j === 0 && c === 0) {
  23827. data[j] = c;
  23828. continue;
  23829. }
  23830. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  23831. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  23832. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  23833. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  23834. data[j] = 95;
  23835. continue;
  23836. }
  23837. data[j] = c;
  23838. }
  23839. names.push(bytesToString(data));
  23840. }
  23841. return names;
  23842. },
  23843. parseStringIndex: function CFFParser_parseStringIndex(index) {
  23844. var strings = new CFFStrings();
  23845. for (var i = 0, ii = index.count; i < ii; ++i) {
  23846. var data = index.get(i);
  23847. strings.add(bytesToString(data));
  23848. }
  23849. return strings;
  23850. },
  23851. createDict: function CFFParser_createDict(Type, dict, strings) {
  23852. var cffDict = new Type(strings);
  23853. for (var i = 0, ii = dict.length; i < ii; ++i) {
  23854. var pair = dict[i];
  23855. var key = pair[0];
  23856. var value = pair[1];
  23857. cffDict.setByKey(key, value);
  23858. }
  23859. return cffDict;
  23860. },
  23861. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  23862. var charStrings = this.parseIndex(charStringOffset).obj;
  23863. var seacs = [];
  23864. var widths = [];
  23865. var count = charStrings.count;
  23866. for (var i = 0; i < count; i++) {
  23867. var charstring = charStrings.get(i);
  23868. var stackSize = 0;
  23869. var stack = [];
  23870. var undefStack = true;
  23871. var hints = 0;
  23872. var valid = true;
  23873. var data = charstring;
  23874. var length = data.length;
  23875. var firstStackClearing = true;
  23876. for (var j = 0; j < length;) {
  23877. var value = data[j++];
  23878. var validationCommand = null;
  23879. if (value === 12) {
  23880. var q = data[j++];
  23881. if (q === 0) {
  23882. // The CFF specification state that the 'dotsection' command
  23883. // (12, 0) is deprecated and treated as a no-op, but all Type2
  23884. // charstrings processors should support them. Unfortunately
  23885. // the font sanitizer don't. As a workaround the sequence (12, 0)
  23886. // is replaced by a useless (0, hmoveto).
  23887. data[j - 2] = 139;
  23888. data[j - 1] = 22;
  23889. stackSize = 0;
  23890. } else {
  23891. validationCommand = CharstringValidationData12[q];
  23892. }
  23893. } else if (value === 28) { // number (16 bit)
  23894. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  23895. j += 2;
  23896. stackSize++;
  23897. } else if (value === 14) {
  23898. if (stackSize >= 4) {
  23899. stackSize -= 4;
  23900. if (SEAC_ANALYSIS_ENABLED) {
  23901. seacs[i] = stack.slice(stackSize, stackSize + 4);
  23902. valid = false;
  23903. }
  23904. }
  23905. validationCommand = CharstringValidationData[value];
  23906. } else if (value >= 32 && value <= 246) { // number
  23907. stack[stackSize] = value - 139;
  23908. stackSize++;
  23909. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  23910. stack[stackSize] = (value < 251 ?
  23911. ((value - 247) << 8) + data[j] + 108 :
  23912. -((value - 251) << 8) - data[j] - 108);
  23913. j++;
  23914. stackSize++;
  23915. } else if (value === 255) { // number (32 bit)
  23916. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  23917. (data[j + 2] << 8) | data[j + 3]) / 65536;
  23918. j += 4;
  23919. stackSize++;
  23920. } else if (value === 19 || value === 20) {
  23921. hints += stackSize >> 1;
  23922. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  23923. stackSize %= 2;
  23924. validationCommand = CharstringValidationData[value];
  23925. } else {
  23926. validationCommand = CharstringValidationData[value];
  23927. }
  23928. if (validationCommand) {
  23929. if (validationCommand.stem) {
  23930. hints += stackSize >> 1;
  23931. }
  23932. if ('min' in validationCommand) {
  23933. if (!undefStack && stackSize < validationCommand.min) {
  23934. warn('Not enough parameters for ' + validationCommand.id +
  23935. '; actual: ' + stackSize +
  23936. ', expected: ' + validationCommand.min);
  23937. valid = false;
  23938. break;
  23939. }
  23940. }
  23941. if (firstStackClearing && validationCommand.stackClearing) {
  23942. firstStackClearing = false;
  23943. // the optional character width can be found before the first
  23944. // stack-clearing command arguments
  23945. stackSize -= validationCommand.min;
  23946. if (stackSize >= 2 && validationCommand.stem) {
  23947. // there are even amount of arguments for stem commands
  23948. stackSize %= 2;
  23949. } else if (stackSize > 1) {
  23950. warn('Found too many parameters for stack-clearing command');
  23951. }
  23952. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  23953. widths[i] = stack[stackSize - 1];
  23954. }
  23955. }
  23956. if ('stackDelta' in validationCommand) {
  23957. if ('stackFn' in validationCommand) {
  23958. validationCommand.stackFn(stack, stackSize);
  23959. }
  23960. stackSize += validationCommand.stackDelta;
  23961. } else if (validationCommand.stackClearing) {
  23962. stackSize = 0;
  23963. } else if (validationCommand.resetStack) {
  23964. stackSize = 0;
  23965. undefStack = false;
  23966. } else if (validationCommand.undefStack) {
  23967. stackSize = 0;
  23968. undefStack = true;
  23969. firstStackClearing = false;
  23970. }
  23971. }
  23972. }
  23973. if (!valid) {
  23974. // resetting invalid charstring to single 'endchar'
  23975. charStrings.set(i, new Uint8Array([14]));
  23976. }
  23977. }
  23978. return { charStrings: charStrings, seacs: seacs, widths: widths };
  23979. },
  23980. emptyPrivateDictionary:
  23981. function CFFParser_emptyPrivateDictionary(parentDict) {
  23982. var privateDict = this.createDict(CFFPrivateDict, [],
  23983. parentDict.strings);
  23984. parentDict.setByKey(18, [0, 0]);
  23985. parentDict.privateDict = privateDict;
  23986. },
  23987. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  23988. // no private dict, do nothing
  23989. if (!parentDict.hasName('Private')) {
  23990. this.emptyPrivateDictionary(parentDict);
  23991. return;
  23992. }
  23993. var privateOffset = parentDict.getByName('Private');
  23994. // make sure the params are formatted correctly
  23995. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  23996. parentDict.removeByName('Private');
  23997. return;
  23998. }
  23999. var size = privateOffset[0];
  24000. var offset = privateOffset[1];
  24001. // remove empty dicts or ones that refer to invalid location
  24002. if (size === 0 || offset >= this.bytes.length) {
  24003. this.emptyPrivateDictionary(parentDict);
  24004. return;
  24005. }
  24006. var privateDictEnd = offset + size;
  24007. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24008. var dict = this.parseDict(dictData);
  24009. var privateDict = this.createDict(CFFPrivateDict, dict,
  24010. parentDict.strings);
  24011. parentDict.privateDict = privateDict;
  24012. // Parse the Subrs index also since it's relative to the private dict.
  24013. if (!privateDict.getByName('Subrs')) {
  24014. return;
  24015. }
  24016. var subrsOffset = privateDict.getByName('Subrs');
  24017. var relativeOffset = offset + subrsOffset;
  24018. // Validate the offset.
  24019. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24020. this.emptyPrivateDictionary(parentDict);
  24021. return;
  24022. }
  24023. var subrsIndex = this.parseIndex(relativeOffset);
  24024. privateDict.subrsIndex = subrsIndex.obj;
  24025. },
  24026. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24027. if (pos === 0) {
  24028. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24029. ISOAdobeCharset);
  24030. } else if (pos === 1) {
  24031. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24032. ExpertCharset);
  24033. } else if (pos === 2) {
  24034. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24035. ExpertSubsetCharset);
  24036. }
  24037. var bytes = this.bytes;
  24038. var start = pos;
  24039. var format = bytes[pos++];
  24040. var charset = ['.notdef'];
  24041. var id, count, i;
  24042. // subtract 1 for the .notdef glyph
  24043. length -= 1;
  24044. switch (format) {
  24045. case 0:
  24046. for (i = 0; i < length; i++) {
  24047. id = (bytes[pos++] << 8) | bytes[pos++];
  24048. charset.push(cid ? id : strings.get(id));
  24049. }
  24050. break;
  24051. case 1:
  24052. while (charset.length <= length) {
  24053. id = (bytes[pos++] << 8) | bytes[pos++];
  24054. count = bytes[pos++];
  24055. for (i = 0; i <= count; i++) {
  24056. charset.push(cid ? id++ : strings.get(id++));
  24057. }
  24058. }
  24059. break;
  24060. case 2:
  24061. while (charset.length <= length) {
  24062. id = (bytes[pos++] << 8) | bytes[pos++];
  24063. count = (bytes[pos++] << 8) | bytes[pos++];
  24064. for (i = 0; i <= count; i++) {
  24065. charset.push(cid ? id++ : strings.get(id++));
  24066. }
  24067. }
  24068. break;
  24069. default:
  24070. error('Unknown charset format');
  24071. }
  24072. // Raw won't be needed if we actually compile the charset.
  24073. var end = pos;
  24074. var raw = bytes.subarray(start, end);
  24075. return new CFFCharset(false, format, charset, raw);
  24076. },
  24077. parseEncoding: function CFFParser_parseEncoding(pos,
  24078. properties,
  24079. strings,
  24080. charset) {
  24081. var encoding = {};
  24082. var bytes = this.bytes;
  24083. var predefined = false;
  24084. var hasSupplement = false;
  24085. var format, i, ii;
  24086. var raw = null;
  24087. function readSupplement() {
  24088. var supplementsCount = bytes[pos++];
  24089. for (i = 0; i < supplementsCount; i++) {
  24090. var code = bytes[pos++];
  24091. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24092. encoding[code] = charset.indexOf(strings.get(sid));
  24093. }
  24094. }
  24095. if (pos === 0 || pos === 1) {
  24096. predefined = true;
  24097. format = pos;
  24098. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24099. Encodings.StandardEncoding;
  24100. for (i = 0, ii = charset.length; i < ii; i++) {
  24101. var index = baseEncoding.indexOf(charset[i]);
  24102. if (index !== -1) {
  24103. encoding[index] = i;
  24104. }
  24105. }
  24106. } else {
  24107. var dataStart = pos;
  24108. format = bytes[pos++];
  24109. switch (format & 0x7f) {
  24110. case 0:
  24111. var glyphsCount = bytes[pos++];
  24112. for (i = 1; i <= glyphsCount; i++) {
  24113. encoding[bytes[pos++]] = i;
  24114. }
  24115. break;
  24116. case 1:
  24117. var rangesCount = bytes[pos++];
  24118. var gid = 1;
  24119. for (i = 0; i < rangesCount; i++) {
  24120. var start = bytes[pos++];
  24121. var left = bytes[pos++];
  24122. for (var j = start; j <= start + left; j++) {
  24123. encoding[j] = gid++;
  24124. }
  24125. }
  24126. break;
  24127. default:
  24128. error('Unknow encoding format: ' + format + ' in CFF');
  24129. break;
  24130. }
  24131. var dataEnd = pos;
  24132. if (format & 0x80) {
  24133. // The font sanitizer does not support CFF encoding with a
  24134. // supplement, since the encoding is not really used to map
  24135. // between gid to glyph, let's overwrite what is declared in
  24136. // the top dictionary to let the sanitizer think the font use
  24137. // StandardEncoding, that's a lie but that's ok.
  24138. bytes[dataStart] &= 0x7f;
  24139. readSupplement();
  24140. hasSupplement = true;
  24141. }
  24142. raw = bytes.subarray(dataStart, dataEnd);
  24143. }
  24144. format = format & 0x7f;
  24145. return new CFFEncoding(predefined, format, encoding, raw);
  24146. },
  24147. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24148. var start = pos;
  24149. var bytes = this.bytes;
  24150. var format = bytes[pos++];
  24151. var fdSelect = [];
  24152. var i;
  24153. switch (format) {
  24154. case 0:
  24155. for (i = 0; i < length; ++i) {
  24156. var id = bytes[pos++];
  24157. fdSelect.push(id);
  24158. }
  24159. break;
  24160. case 3:
  24161. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24162. for (i = 0; i < rangesCount; ++i) {
  24163. var first = (bytes[pos++] << 8) | bytes[pos++];
  24164. var fdIndex = bytes[pos++];
  24165. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24166. for (var j = first; j < next; ++j) {
  24167. fdSelect.push(fdIndex);
  24168. }
  24169. }
  24170. // Advance past the sentinel(next).
  24171. pos += 2;
  24172. break;
  24173. default:
  24174. error('Unknown fdselect format ' + format);
  24175. break;
  24176. }
  24177. var end = pos;
  24178. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24179. }
  24180. };
  24181. return CFFParser;
  24182. })();
  24183. // Compact Font Format
  24184. var CFF = (function CFFClosure() {
  24185. function CFF() {
  24186. this.header = null;
  24187. this.names = [];
  24188. this.topDict = null;
  24189. this.strings = new CFFStrings();
  24190. this.globalSubrIndex = null;
  24191. // The following could really be per font, but since we only have one font
  24192. // store them here.
  24193. this.encoding = null;
  24194. this.charset = null;
  24195. this.charStrings = null;
  24196. this.fdArray = [];
  24197. this.fdSelect = null;
  24198. this.isCIDFont = false;
  24199. }
  24200. return CFF;
  24201. })();
  24202. var CFFHeader = (function CFFHeaderClosure() {
  24203. function CFFHeader(major, minor, hdrSize, offSize) {
  24204. this.major = major;
  24205. this.minor = minor;
  24206. this.hdrSize = hdrSize;
  24207. this.offSize = offSize;
  24208. }
  24209. return CFFHeader;
  24210. })();
  24211. var CFFStrings = (function CFFStringsClosure() {
  24212. function CFFStrings() {
  24213. this.strings = [];
  24214. }
  24215. CFFStrings.prototype = {
  24216. get: function CFFStrings_get(index) {
  24217. if (index >= 0 && index <= 390) {
  24218. return CFFStandardStrings[index];
  24219. }
  24220. if (index - 391 <= this.strings.length) {
  24221. return this.strings[index - 391];
  24222. }
  24223. return CFFStandardStrings[0];
  24224. },
  24225. add: function CFFStrings_add(value) {
  24226. this.strings.push(value);
  24227. },
  24228. get count() {
  24229. return this.strings.length;
  24230. }
  24231. };
  24232. return CFFStrings;
  24233. })();
  24234. var CFFIndex = (function CFFIndexClosure() {
  24235. function CFFIndex() {
  24236. this.objects = [];
  24237. this.length = 0;
  24238. }
  24239. CFFIndex.prototype = {
  24240. add: function CFFIndex_add(data) {
  24241. this.length += data.length;
  24242. this.objects.push(data);
  24243. },
  24244. set: function CFFIndex_set(index, data) {
  24245. this.length += data.length - this.objects[index].length;
  24246. this.objects[index] = data;
  24247. },
  24248. get: function CFFIndex_get(index) {
  24249. return this.objects[index];
  24250. },
  24251. get count() {
  24252. return this.objects.length;
  24253. }
  24254. };
  24255. return CFFIndex;
  24256. })();
  24257. var CFFDict = (function CFFDictClosure() {
  24258. function CFFDict(tables, strings) {
  24259. this.keyToNameMap = tables.keyToNameMap;
  24260. this.nameToKeyMap = tables.nameToKeyMap;
  24261. this.defaults = tables.defaults;
  24262. this.types = tables.types;
  24263. this.opcodes = tables.opcodes;
  24264. this.order = tables.order;
  24265. this.strings = strings;
  24266. this.values = {};
  24267. }
  24268. CFFDict.prototype = {
  24269. // value should always be an array
  24270. setByKey: function CFFDict_setByKey(key, value) {
  24271. if (!(key in this.keyToNameMap)) {
  24272. return false;
  24273. }
  24274. // ignore empty values
  24275. if (value.length === 0) {
  24276. return true;
  24277. }
  24278. var type = this.types[key];
  24279. // remove the array wrapping these types of values
  24280. if (type === 'num' || type === 'sid' || type === 'offset') {
  24281. value = value[0];
  24282. }
  24283. this.values[key] = value;
  24284. return true;
  24285. },
  24286. setByName: function CFFDict_setByName(name, value) {
  24287. if (!(name in this.nameToKeyMap)) {
  24288. error('Invalid dictionary name "' + name + '"');
  24289. }
  24290. this.values[this.nameToKeyMap[name]] = value;
  24291. },
  24292. hasName: function CFFDict_hasName(name) {
  24293. return this.nameToKeyMap[name] in this.values;
  24294. },
  24295. getByName: function CFFDict_getByName(name) {
  24296. if (!(name in this.nameToKeyMap)) {
  24297. error('Invalid dictionary name "' + name + '"');
  24298. }
  24299. var key = this.nameToKeyMap[name];
  24300. if (!(key in this.values)) {
  24301. return this.defaults[key];
  24302. }
  24303. return this.values[key];
  24304. },
  24305. removeByName: function CFFDict_removeByName(name) {
  24306. delete this.values[this.nameToKeyMap[name]];
  24307. }
  24308. };
  24309. CFFDict.createTables = function CFFDict_createTables(layout) {
  24310. var tables = {
  24311. keyToNameMap: {},
  24312. nameToKeyMap: {},
  24313. defaults: {},
  24314. types: {},
  24315. opcodes: {},
  24316. order: []
  24317. };
  24318. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24319. var entry = layout[i];
  24320. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24321. tables.keyToNameMap[key] = entry[1];
  24322. tables.nameToKeyMap[entry[1]] = key;
  24323. tables.types[key] = entry[2];
  24324. tables.defaults[key] = entry[3];
  24325. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24326. tables.order.push(key);
  24327. }
  24328. return tables;
  24329. };
  24330. return CFFDict;
  24331. })();
  24332. var CFFTopDict = (function CFFTopDictClosure() {
  24333. var layout = [
  24334. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24335. [[12, 20], 'SyntheticBase', 'num', null],
  24336. [0, 'version', 'sid', null],
  24337. [1, 'Notice', 'sid', null],
  24338. [[12, 0], 'Copyright', 'sid', null],
  24339. [2, 'FullName', 'sid', null],
  24340. [3, 'FamilyName', 'sid', null],
  24341. [4, 'Weight', 'sid', null],
  24342. [[12, 1], 'isFixedPitch', 'num', 0],
  24343. [[12, 2], 'ItalicAngle', 'num', 0],
  24344. [[12, 3], 'UnderlinePosition', 'num', -100],
  24345. [[12, 4], 'UnderlineThickness', 'num', 50],
  24346. [[12, 5], 'PaintType', 'num', 0],
  24347. [[12, 6], 'CharstringType', 'num', 2],
  24348. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24349. [0.001, 0, 0, 0.001, 0, 0]],
  24350. [13, 'UniqueID', 'num', null],
  24351. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24352. [[12, 8], 'StrokeWidth', 'num', 0],
  24353. [14, 'XUID', 'array', null],
  24354. [15, 'charset', 'offset', 0],
  24355. [16, 'Encoding', 'offset', 0],
  24356. [17, 'CharStrings', 'offset', 0],
  24357. [18, 'Private', ['offset', 'offset'], null],
  24358. [[12, 21], 'PostScript', 'sid', null],
  24359. [[12, 22], 'BaseFontName', 'sid', null],
  24360. [[12, 23], 'BaseFontBlend', 'delta', null],
  24361. [[12, 31], 'CIDFontVersion', 'num', 0],
  24362. [[12, 32], 'CIDFontRevision', 'num', 0],
  24363. [[12, 33], 'CIDFontType', 'num', 0],
  24364. [[12, 34], 'CIDCount', 'num', 8720],
  24365. [[12, 35], 'UIDBase', 'num', null],
  24366. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24367. // before FDArray.
  24368. [[12, 37], 'FDSelect', 'offset', null],
  24369. [[12, 36], 'FDArray', 'offset', null],
  24370. [[12, 38], 'FontName', 'sid', null]
  24371. ];
  24372. var tables = null;
  24373. function CFFTopDict(strings) {
  24374. if (tables === null) {
  24375. tables = CFFDict.createTables(layout);
  24376. }
  24377. CFFDict.call(this, tables, strings);
  24378. this.privateDict = null;
  24379. }
  24380. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24381. return CFFTopDict;
  24382. })();
  24383. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24384. var layout = [
  24385. [6, 'BlueValues', 'delta', null],
  24386. [7, 'OtherBlues', 'delta', null],
  24387. [8, 'FamilyBlues', 'delta', null],
  24388. [9, 'FamilyOtherBlues', 'delta', null],
  24389. [[12, 9], 'BlueScale', 'num', 0.039625],
  24390. [[12, 10], 'BlueShift', 'num', 7],
  24391. [[12, 11], 'BlueFuzz', 'num', 1],
  24392. [10, 'StdHW', 'num', null],
  24393. [11, 'StdVW', 'num', null],
  24394. [[12, 12], 'StemSnapH', 'delta', null],
  24395. [[12, 13], 'StemSnapV', 'delta', null],
  24396. [[12, 14], 'ForceBold', 'num', 0],
  24397. [[12, 17], 'LanguageGroup', 'num', 0],
  24398. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24399. [[12, 19], 'initialRandomSeed', 'num', 0],
  24400. [20, 'defaultWidthX', 'num', 0],
  24401. [21, 'nominalWidthX', 'num', 0],
  24402. [19, 'Subrs', 'offset', null]
  24403. ];
  24404. var tables = null;
  24405. function CFFPrivateDict(strings) {
  24406. if (tables === null) {
  24407. tables = CFFDict.createTables(layout);
  24408. }
  24409. CFFDict.call(this, tables, strings);
  24410. this.subrsIndex = null;
  24411. }
  24412. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24413. return CFFPrivateDict;
  24414. })();
  24415. var CFFCharsetPredefinedTypes = {
  24416. ISO_ADOBE: 0,
  24417. EXPERT: 1,
  24418. EXPERT_SUBSET: 2
  24419. };
  24420. var CFFCharset = (function CFFCharsetClosure() {
  24421. function CFFCharset(predefined, format, charset, raw) {
  24422. this.predefined = predefined;
  24423. this.format = format;
  24424. this.charset = charset;
  24425. this.raw = raw;
  24426. }
  24427. return CFFCharset;
  24428. })();
  24429. var CFFEncoding = (function CFFEncodingClosure() {
  24430. function CFFEncoding(predefined, format, encoding, raw) {
  24431. this.predefined = predefined;
  24432. this.format = format;
  24433. this.encoding = encoding;
  24434. this.raw = raw;
  24435. }
  24436. return CFFEncoding;
  24437. })();
  24438. var CFFFDSelect = (function CFFFDSelectClosure() {
  24439. function CFFFDSelect(fdSelect, raw) {
  24440. this.fdSelect = fdSelect;
  24441. this.raw = raw;
  24442. }
  24443. return CFFFDSelect;
  24444. })();
  24445. // Helper class to keep track of where an offset is within the data and helps
  24446. // filling in that offset once it's known.
  24447. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24448. function CFFOffsetTracker() {
  24449. this.offsets = {};
  24450. }
  24451. CFFOffsetTracker.prototype = {
  24452. isTracking: function CFFOffsetTracker_isTracking(key) {
  24453. return key in this.offsets;
  24454. },
  24455. track: function CFFOffsetTracker_track(key, location) {
  24456. if (key in this.offsets) {
  24457. error('Already tracking location of ' + key);
  24458. }
  24459. this.offsets[key] = location;
  24460. },
  24461. offset: function CFFOffsetTracker_offset(value) {
  24462. for (var key in this.offsets) {
  24463. this.offsets[key] += value;
  24464. }
  24465. },
  24466. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24467. values,
  24468. output) {
  24469. if (!(key in this.offsets)) {
  24470. error('Not tracking location of ' + key);
  24471. }
  24472. var data = output.data;
  24473. var dataOffset = this.offsets[key];
  24474. var size = 5;
  24475. for (var i = 0, ii = values.length; i < ii; ++i) {
  24476. var offset0 = i * size + dataOffset;
  24477. var offset1 = offset0 + 1;
  24478. var offset2 = offset0 + 2;
  24479. var offset3 = offset0 + 3;
  24480. var offset4 = offset0 + 4;
  24481. // It's easy to screw up offsets so perform this sanity check.
  24482. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24483. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24484. error('writing to an offset that is not empty');
  24485. }
  24486. var value = values[i];
  24487. data[offset0] = 0x1d;
  24488. data[offset1] = (value >> 24) & 0xFF;
  24489. data[offset2] = (value >> 16) & 0xFF;
  24490. data[offset3] = (value >> 8) & 0xFF;
  24491. data[offset4] = value & 0xFF;
  24492. }
  24493. }
  24494. };
  24495. return CFFOffsetTracker;
  24496. })();
  24497. // Takes a CFF and converts it to the binary representation.
  24498. var CFFCompiler = (function CFFCompilerClosure() {
  24499. function CFFCompiler(cff) {
  24500. this.cff = cff;
  24501. }
  24502. CFFCompiler.prototype = {
  24503. compile: function CFFCompiler_compile() {
  24504. var cff = this.cff;
  24505. var output = {
  24506. data: [],
  24507. length: 0,
  24508. add: function CFFCompiler_add(data) {
  24509. this.data = this.data.concat(data);
  24510. this.length = this.data.length;
  24511. }
  24512. };
  24513. // Compile the five entries that must be in order.
  24514. var header = this.compileHeader(cff.header);
  24515. output.add(header);
  24516. var nameIndex = this.compileNameIndex(cff.names);
  24517. output.add(nameIndex);
  24518. if (cff.isCIDFont) {
  24519. // The spec is unclear on how font matrices should relate to each other
  24520. // when there is one in the main top dict and the sub top dicts.
  24521. // Windows handles this differently than linux and osx so we have to
  24522. // normalize to work on all.
  24523. // Rules based off of some mailing list discussions:
  24524. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24525. // - If no main font matrix and there is a subfont matrix, use the
  24526. // subfont matrix.
  24527. // - If both have matrices, concat together.
  24528. // - If neither have matrices, use default.
  24529. // To make this work on all platforms we move the top matrix into each
  24530. // sub top dict and concat if necessary.
  24531. if (cff.topDict.hasName('FontMatrix')) {
  24532. var base = cff.topDict.getByName('FontMatrix');
  24533. cff.topDict.removeByName('FontMatrix');
  24534. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24535. var subDict = cff.fdArray[i];
  24536. var matrix = base.slice(0);
  24537. if (subDict.hasName('FontMatrix')) {
  24538. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24539. }
  24540. subDict.setByName('FontMatrix', matrix);
  24541. }
  24542. }
  24543. }
  24544. var compiled = this.compileTopDicts([cff.topDict],
  24545. output.length,
  24546. cff.isCIDFont);
  24547. output.add(compiled.output);
  24548. var topDictTracker = compiled.trackers[0];
  24549. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24550. output.add(stringIndex);
  24551. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24552. output.add(globalSubrIndex);
  24553. // Now start on the other entries that have no specfic order.
  24554. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24555. if (cff.encoding.predefined) {
  24556. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24557. output);
  24558. } else {
  24559. var encoding = this.compileEncoding(cff.encoding);
  24560. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24561. output.add(encoding);
  24562. }
  24563. }
  24564. if (cff.charset && cff.topDict.hasName('charset')) {
  24565. if (cff.charset.predefined) {
  24566. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24567. output);
  24568. } else {
  24569. var charset = this.compileCharset(cff.charset);
  24570. topDictTracker.setEntryLocation('charset', [output.length], output);
  24571. output.add(charset);
  24572. }
  24573. }
  24574. var charStrings = this.compileCharStrings(cff.charStrings);
  24575. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24576. output.add(charStrings);
  24577. if (cff.isCIDFont) {
  24578. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24579. // and linux don't seem to care.
  24580. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24581. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24582. output.add(fdSelect);
  24583. // It is unclear if the sub font dictionary can have CID related
  24584. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24585. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24586. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24587. output.add(compiled.output);
  24588. var fontDictTrackers = compiled.trackers;
  24589. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  24590. }
  24591. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  24592. // If the font data ends with INDEX whose object data is zero-length,
  24593. // the sanitizer will bail out. Add a dummy byte to avoid that.
  24594. output.add([0]);
  24595. return output.data;
  24596. },
  24597. encodeNumber: function CFFCompiler_encodeNumber(value) {
  24598. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  24599. return this.encodeInteger(value);
  24600. } else {
  24601. return this.encodeFloat(value);
  24602. }
  24603. },
  24604. encodeFloat: function CFFCompiler_encodeFloat(num) {
  24605. var value = num.toString();
  24606. // rounding inaccurate doubles
  24607. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  24608. if (m) {
  24609. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  24610. value = (Math.round(num * epsilon) / epsilon).toString();
  24611. }
  24612. var nibbles = '';
  24613. var i, ii;
  24614. for (i = 0, ii = value.length; i < ii; ++i) {
  24615. var a = value[i];
  24616. if (a === 'e') {
  24617. nibbles += value[++i] === '-' ? 'c' : 'b';
  24618. } else if (a === '.') {
  24619. nibbles += 'a';
  24620. } else if (a === '-') {
  24621. nibbles += 'e';
  24622. } else {
  24623. nibbles += a;
  24624. }
  24625. }
  24626. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  24627. var out = [30];
  24628. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  24629. out.push(parseInt(nibbles.substr(i, 2), 16));
  24630. }
  24631. return out;
  24632. },
  24633. encodeInteger: function CFFCompiler_encodeInteger(value) {
  24634. var code;
  24635. if (value >= -107 && value <= 107) {
  24636. code = [value + 139];
  24637. } else if (value >= 108 && value <= 1131) {
  24638. value = [value - 108];
  24639. code = [(value >> 8) + 247, value & 0xFF];
  24640. } else if (value >= -1131 && value <= -108) {
  24641. value = -value - 108;
  24642. code = [(value >> 8) + 251, value & 0xFF];
  24643. } else if (value >= -32768 && value <= 32767) {
  24644. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  24645. } else {
  24646. code = [0x1d,
  24647. (value >> 24) & 0xFF,
  24648. (value >> 16) & 0xFF,
  24649. (value >> 8) & 0xFF,
  24650. value & 0xFF];
  24651. }
  24652. return code;
  24653. },
  24654. compileHeader: function CFFCompiler_compileHeader(header) {
  24655. return [
  24656. header.major,
  24657. header.minor,
  24658. header.hdrSize,
  24659. header.offSize
  24660. ];
  24661. },
  24662. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  24663. var nameIndex = new CFFIndex();
  24664. for (var i = 0, ii = names.length; i < ii; ++i) {
  24665. nameIndex.add(stringToBytes(names[i]));
  24666. }
  24667. return this.compileIndex(nameIndex);
  24668. },
  24669. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  24670. length,
  24671. removeCidKeys) {
  24672. var fontDictTrackers = [];
  24673. var fdArrayIndex = new CFFIndex();
  24674. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  24675. var fontDict = dicts[i];
  24676. if (removeCidKeys) {
  24677. fontDict.removeByName('CIDFontVersion');
  24678. fontDict.removeByName('CIDFontRevision');
  24679. fontDict.removeByName('CIDFontType');
  24680. fontDict.removeByName('CIDCount');
  24681. fontDict.removeByName('UIDBase');
  24682. }
  24683. var fontDictTracker = new CFFOffsetTracker();
  24684. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  24685. fontDictTrackers.push(fontDictTracker);
  24686. fdArrayIndex.add(fontDictData);
  24687. fontDictTracker.offset(length);
  24688. }
  24689. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  24690. return {
  24691. trackers: fontDictTrackers,
  24692. output: fdArrayIndex
  24693. };
  24694. },
  24695. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  24696. trackers,
  24697. output) {
  24698. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  24699. var fontDict = dicts[i];
  24700. assert(fontDict.privateDict && fontDict.hasName('Private'),
  24701. 'There must be an private dictionary.');
  24702. var privateDict = fontDict.privateDict;
  24703. var privateDictTracker = new CFFOffsetTracker();
  24704. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  24705. var outputLength = output.length;
  24706. privateDictTracker.offset(outputLength);
  24707. if (!privateDictData.length) {
  24708. // The private dictionary was empty, set the output length to zero to
  24709. // ensure the offset length isn't out of bounds in the eyes of the
  24710. // sanitizer.
  24711. outputLength = 0;
  24712. }
  24713. trackers[i].setEntryLocation('Private',
  24714. [privateDictData.length, outputLength],
  24715. output);
  24716. output.add(privateDictData);
  24717. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  24718. var subrs = this.compileIndex(privateDict.subrsIndex);
  24719. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  24720. output);
  24721. output.add(subrs);
  24722. }
  24723. }
  24724. },
  24725. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  24726. var out = [];
  24727. // The dictionary keys must be in a certain order.
  24728. var order = dict.order;
  24729. for (var i = 0; i < order.length; ++i) {
  24730. var key = order[i];
  24731. if (!(key in dict.values)) {
  24732. continue;
  24733. }
  24734. var values = dict.values[key];
  24735. var types = dict.types[key];
  24736. if (!isArray(types)) {
  24737. types = [types];
  24738. }
  24739. if (!isArray(values)) {
  24740. values = [values];
  24741. }
  24742. // Remove any empty dict values.
  24743. if (values.length === 0) {
  24744. continue;
  24745. }
  24746. for (var j = 0, jj = types.length; j < jj; ++j) {
  24747. var type = types[j];
  24748. var value = values[j];
  24749. switch (type) {
  24750. case 'num':
  24751. case 'sid':
  24752. out = out.concat(this.encodeNumber(value));
  24753. break;
  24754. case 'offset':
  24755. // For offsets we just insert a 32bit integer so we don't have to
  24756. // deal with figuring out the length of the offset when it gets
  24757. // replaced later on by the compiler.
  24758. var name = dict.keyToNameMap[key];
  24759. // Some offsets have the offset and the length, so just record the
  24760. // position of the first one.
  24761. if (!offsetTracker.isTracking(name)) {
  24762. offsetTracker.track(name, out.length);
  24763. }
  24764. out = out.concat([0x1d, 0, 0, 0, 0]);
  24765. break;
  24766. case 'array':
  24767. case 'delta':
  24768. out = out.concat(this.encodeNumber(value));
  24769. for (var k = 1, kk = values.length; k < kk; ++k) {
  24770. out = out.concat(this.encodeNumber(values[k]));
  24771. }
  24772. break;
  24773. default:
  24774. error('Unknown data type of ' + type);
  24775. break;
  24776. }
  24777. }
  24778. out = out.concat(dict.opcodes[key]);
  24779. }
  24780. return out;
  24781. },
  24782. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  24783. var stringIndex = new CFFIndex();
  24784. for (var i = 0, ii = strings.length; i < ii; ++i) {
  24785. stringIndex.add(stringToBytes(strings[i]));
  24786. }
  24787. return this.compileIndex(stringIndex);
  24788. },
  24789. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  24790. var globalSubrIndex = this.cff.globalSubrIndex;
  24791. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  24792. },
  24793. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  24794. return this.compileIndex(charStrings);
  24795. },
  24796. compileCharset: function CFFCompiler_compileCharset(charset) {
  24797. return this.compileTypedArray(charset.raw);
  24798. },
  24799. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  24800. return this.compileTypedArray(encoding.raw);
  24801. },
  24802. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  24803. return this.compileTypedArray(fdSelect);
  24804. },
  24805. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  24806. var out = [];
  24807. for (var i = 0, ii = data.length; i < ii; ++i) {
  24808. out[i] = data[i];
  24809. }
  24810. return out;
  24811. },
  24812. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  24813. trackers = trackers || [];
  24814. var objects = index.objects;
  24815. // First 2 bytes contains the number of objects contained into this index
  24816. var count = objects.length;
  24817. // If there is no object, just create an index. This technically
  24818. // should just be [0, 0] but OTS has an issue with that.
  24819. if (count === 0) {
  24820. return [0, 0, 0];
  24821. }
  24822. var data = [(count >> 8) & 0xFF, count & 0xff];
  24823. var lastOffset = 1, i;
  24824. for (i = 0; i < count; ++i) {
  24825. lastOffset += objects[i].length;
  24826. }
  24827. var offsetSize;
  24828. if (lastOffset < 0x100) {
  24829. offsetSize = 1;
  24830. } else if (lastOffset < 0x10000) {
  24831. offsetSize = 2;
  24832. } else if (lastOffset < 0x1000000) {
  24833. offsetSize = 3;
  24834. } else {
  24835. offsetSize = 4;
  24836. }
  24837. // Next byte contains the offset size use to reference object in the file
  24838. data.push(offsetSize);
  24839. // Add another offset after this one because we need a new offset
  24840. var relativeOffset = 1;
  24841. for (i = 0; i < count + 1; i++) {
  24842. if (offsetSize === 1) {
  24843. data.push(relativeOffset & 0xFF);
  24844. } else if (offsetSize === 2) {
  24845. data.push((relativeOffset >> 8) & 0xFF,
  24846. relativeOffset & 0xFF);
  24847. } else if (offsetSize === 3) {
  24848. data.push((relativeOffset >> 16) & 0xFF,
  24849. (relativeOffset >> 8) & 0xFF,
  24850. relativeOffset & 0xFF);
  24851. } else {
  24852. data.push((relativeOffset >>> 24) & 0xFF,
  24853. (relativeOffset >> 16) & 0xFF,
  24854. (relativeOffset >> 8) & 0xFF,
  24855. relativeOffset & 0xFF);
  24856. }
  24857. if (objects[i]) {
  24858. relativeOffset += objects[i].length;
  24859. }
  24860. }
  24861. for (i = 0; i < count; i++) {
  24862. // Notify the tracker where the object will be offset in the data.
  24863. if (trackers[i]) {
  24864. trackers[i].offset(data.length);
  24865. }
  24866. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  24867. data.push(objects[i][j]);
  24868. }
  24869. }
  24870. return data;
  24871. }
  24872. };
  24873. return CFFCompiler;
  24874. })();
  24875. // Workaround for seac on Windows.
  24876. (function checkSeacSupport() {
  24877. if (/Windows/.test(navigator.userAgent)) {
  24878. SEAC_ANALYSIS_ENABLED = true;
  24879. }
  24880. })();
  24881. // Workaround for Private Use Area characters in Chrome on Windows
  24882. // http://code.google.com/p/chromium/issues/detail?id=122465
  24883. // https://github.com/mozilla/pdf.js/issues/1689
  24884. (function checkChromeWindows() {
  24885. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  24886. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  24887. }
  24888. })();
  24889. var FontRendererFactory = (function FontRendererFactoryClosure() {
  24890. function getLong(data, offset) {
  24891. return (data[offset] << 24) | (data[offset + 1] << 16) |
  24892. (data[offset + 2] << 8) | data[offset + 3];
  24893. }
  24894. function getUshort(data, offset) {
  24895. return (data[offset] << 8) | data[offset + 1];
  24896. }
  24897. function parseCmap(data, start, end) {
  24898. var offset = (getUshort(data, start + 2) === 1 ?
  24899. getLong(data, start + 8) : getLong(data, start + 16));
  24900. var format = getUshort(data, start + offset);
  24901. var length, ranges, p, i;
  24902. if (format === 4) {
  24903. length = getUshort(data, start + offset + 2);
  24904. var segCount = getUshort(data, start + offset + 6) >> 1;
  24905. p = start + offset + 14;
  24906. ranges = [];
  24907. for (i = 0; i < segCount; i++, p += 2) {
  24908. ranges[i] = {end: getUshort(data, p)};
  24909. }
  24910. p += 2;
  24911. for (i = 0; i < segCount; i++, p += 2) {
  24912. ranges[i].start = getUshort(data, p);
  24913. }
  24914. for (i = 0; i < segCount; i++, p += 2) {
  24915. ranges[i].idDelta = getUshort(data, p);
  24916. }
  24917. for (i = 0; i < segCount; i++, p += 2) {
  24918. var idOffset = getUshort(data, p);
  24919. if (idOffset === 0) {
  24920. continue;
  24921. }
  24922. ranges[i].ids = [];
  24923. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  24924. ranges[i].ids[j] = getUshort(data, p + idOffset);
  24925. idOffset += 2;
  24926. }
  24927. }
  24928. return ranges;
  24929. } else if (format === 12) {
  24930. length = getLong(data, start + offset + 4);
  24931. var groups = getLong(data, start + offset + 12);
  24932. p = start + offset + 16;
  24933. ranges = [];
  24934. for (i = 0; i < groups; i++) {
  24935. ranges.push({
  24936. start: getLong(data, p),
  24937. end: getLong(data, p + 4),
  24938. idDelta: getLong(data, p + 8) - getLong(data, p)
  24939. });
  24940. p += 12;
  24941. }
  24942. return ranges;
  24943. }
  24944. error('not supported cmap: ' + format);
  24945. }
  24946. function parseCff(data, start, end) {
  24947. var properties = {};
  24948. var parser = new CFFParser(new Stream(data, start, end - start),
  24949. properties);
  24950. var cff = parser.parse();
  24951. return {
  24952. glyphs: cff.charStrings.objects,
  24953. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  24954. cff.topDict.privateDict.subrsIndex.objects),
  24955. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  24956. };
  24957. }
  24958. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  24959. var itemSize, itemDecode;
  24960. if (isGlyphLocationsLong) {
  24961. itemSize = 4;
  24962. itemDecode = function fontItemDecodeLong(data, offset) {
  24963. return (data[offset] << 24) | (data[offset + 1] << 16) |
  24964. (data[offset + 2] << 8) | data[offset + 3];
  24965. };
  24966. } else {
  24967. itemSize = 2;
  24968. itemDecode = function fontItemDecode(data, offset) {
  24969. return (data[offset] << 9) | (data[offset + 1] << 1);
  24970. };
  24971. }
  24972. var glyphs = [];
  24973. var startOffset = itemDecode(loca, 0);
  24974. for (var j = itemSize; j < loca.length; j += itemSize) {
  24975. var endOffset = itemDecode(loca, j);
  24976. glyphs.push(glyf.subarray(startOffset, endOffset));
  24977. startOffset = endOffset;
  24978. }
  24979. return glyphs;
  24980. }
  24981. function lookupCmap(ranges, unicode) {
  24982. var code = unicode.charCodeAt(0);
  24983. var l = 0, r = ranges.length - 1;
  24984. while (l < r) {
  24985. var c = (l + r + 1) >> 1;
  24986. if (code < ranges[c].start) {
  24987. r = c - 1;
  24988. } else {
  24989. l = c;
  24990. }
  24991. }
  24992. if (ranges[l].start <= code && code <= ranges[l].end) {
  24993. return (ranges[l].idDelta + (ranges[l].ids ?
  24994. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  24995. }
  24996. return 0;
  24997. }
  24998. function compileGlyf(code, js, font) {
  24999. function moveTo(x, y) {
  25000. js.push('c.moveTo(' + x + ',' + y + ');');
  25001. }
  25002. function lineTo(x, y) {
  25003. js.push('c.lineTo(' + x + ',' + y + ');');
  25004. }
  25005. function quadraticCurveTo(xa, ya, x, y) {
  25006. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25007. x + ',' + y + ');');
  25008. }
  25009. var i = 0;
  25010. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25011. var flags;
  25012. var x = 0, y = 0;
  25013. i += 10;
  25014. if (numberOfContours < 0) {
  25015. // composite glyph
  25016. do {
  25017. flags = (code[i] << 8) | code[i + 1];
  25018. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25019. i += 4;
  25020. var arg1, arg2;
  25021. if ((flags & 0x01)) {
  25022. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25023. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25024. i += 4;
  25025. } else {
  25026. arg1 = code[i++]; arg2 = code[i++];
  25027. }
  25028. if ((flags & 0x02)) {
  25029. x = arg1;
  25030. y = arg2;
  25031. } else {
  25032. x = 0; y = 0; // TODO "they are points" ?
  25033. }
  25034. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25035. if ((flags & 0x08)) {
  25036. scaleX =
  25037. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25038. i += 2;
  25039. } else if ((flags & 0x40)) {
  25040. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25041. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25042. i += 4;
  25043. } else if ((flags & 0x80)) {
  25044. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25045. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25046. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25047. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25048. i += 8;
  25049. }
  25050. var subglyph = font.glyphs[glyphIndex];
  25051. if (subglyph) {
  25052. js.push('c.save();');
  25053. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25054. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25055. compileGlyf(subglyph, js, font);
  25056. js.push('c.restore();');
  25057. }
  25058. } while ((flags & 0x20));
  25059. } else {
  25060. // simple glyph
  25061. var endPtsOfContours = [];
  25062. var j, jj;
  25063. for (j = 0; j < numberOfContours; j++) {
  25064. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25065. i += 2;
  25066. }
  25067. var instructionLength = (code[i] << 8) | code[i + 1];
  25068. i += 2 + instructionLength; // skipping the instructions
  25069. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25070. var points = [];
  25071. while (points.length < numberOfPoints) {
  25072. flags = code[i++];
  25073. var repeat = 1;
  25074. if ((flags & 0x08)) {
  25075. repeat += code[i++];
  25076. }
  25077. while (repeat-- > 0) {
  25078. points.push({flags: flags});
  25079. }
  25080. }
  25081. for (j = 0; j < numberOfPoints; j++) {
  25082. switch (points[j].flags & 0x12) {
  25083. case 0x00:
  25084. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25085. i += 2;
  25086. break;
  25087. case 0x02:
  25088. x -= code[i++];
  25089. break;
  25090. case 0x12:
  25091. x += code[i++];
  25092. break;
  25093. }
  25094. points[j].x = x;
  25095. }
  25096. for (j = 0; j < numberOfPoints; j++) {
  25097. switch (points[j].flags & 0x24) {
  25098. case 0x00:
  25099. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25100. i += 2;
  25101. break;
  25102. case 0x04:
  25103. y -= code[i++];
  25104. break;
  25105. case 0x24:
  25106. y += code[i++];
  25107. break;
  25108. }
  25109. points[j].y = y;
  25110. }
  25111. var startPoint = 0;
  25112. for (i = 0; i < numberOfContours; i++) {
  25113. var endPoint = endPtsOfContours[i];
  25114. // contours might have implicit points, which is located in the middle
  25115. // between two neighboring off-curve points
  25116. var contour = points.slice(startPoint, endPoint + 1);
  25117. if ((contour[0].flags & 1)) {
  25118. contour.push(contour[0]); // using start point at the contour end
  25119. } else if ((contour[contour.length - 1].flags & 1)) {
  25120. // first is off-curve point, trying to use one from the end
  25121. contour.unshift(contour[contour.length - 1]);
  25122. } else {
  25123. // start and end are off-curve points, creating implicit one
  25124. var p = {
  25125. flags: 1,
  25126. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25127. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25128. };
  25129. contour.unshift(p);
  25130. contour.push(p);
  25131. }
  25132. moveTo(contour[0].x, contour[0].y);
  25133. for (j = 1, jj = contour.length; j < jj; j++) {
  25134. if ((contour[j].flags & 1)) {
  25135. lineTo(contour[j].x, contour[j].y);
  25136. } else if ((contour[j + 1].flags & 1)){
  25137. quadraticCurveTo(contour[j].x, contour[j].y,
  25138. contour[j + 1].x, contour[j + 1].y);
  25139. j++;
  25140. } else {
  25141. quadraticCurveTo(contour[j].x, contour[j].y,
  25142. (contour[j].x + contour[j + 1].x) / 2,
  25143. (contour[j].y + contour[j + 1].y) / 2);
  25144. }
  25145. }
  25146. startPoint = endPoint + 1;
  25147. }
  25148. }
  25149. }
  25150. function compileCharString(code, js, font) {
  25151. var stack = [];
  25152. var x = 0, y = 0;
  25153. var stems = 0;
  25154. function moveTo(x, y) {
  25155. js.push('c.moveTo(' + x + ',' + y + ');');
  25156. }
  25157. function lineTo(x, y) {
  25158. js.push('c.lineTo(' + x + ',' + y + ');');
  25159. }
  25160. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25161. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25162. x + ',' + y + ');');
  25163. }
  25164. function parse(code) {
  25165. var i = 0;
  25166. while (i < code.length) {
  25167. var stackClean = false;
  25168. var v = code[i++];
  25169. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25170. switch (v) {
  25171. case 1: // hstem
  25172. stems += stack.length >> 1;
  25173. stackClean = true;
  25174. break;
  25175. case 3: // vstem
  25176. stems += stack.length >> 1;
  25177. stackClean = true;
  25178. break;
  25179. case 4: // vmoveto
  25180. y += stack.pop();
  25181. moveTo(x, y);
  25182. stackClean = true;
  25183. break;
  25184. case 5: // rlineto
  25185. while (stack.length > 0) {
  25186. x += stack.shift();
  25187. y += stack.shift();
  25188. lineTo(x, y);
  25189. }
  25190. break;
  25191. case 6: // hlineto
  25192. while (stack.length > 0) {
  25193. x += stack.shift();
  25194. lineTo(x, y);
  25195. if (stack.length === 0) {
  25196. break;
  25197. }
  25198. y += stack.shift();
  25199. lineTo(x, y);
  25200. }
  25201. break;
  25202. case 7: // vlineto
  25203. while (stack.length > 0) {
  25204. y += stack.shift();
  25205. lineTo(x, y);
  25206. if (stack.length === 0) {
  25207. break;
  25208. }
  25209. x += stack.shift();
  25210. lineTo(x, y);
  25211. }
  25212. break;
  25213. case 8: // rrcurveto
  25214. while (stack.length > 0) {
  25215. xa = x + stack.shift(); ya = y + stack.shift();
  25216. xb = xa + stack.shift(); yb = ya + stack.shift();
  25217. x = xb + stack.shift(); y = yb + stack.shift();
  25218. bezierCurveTo(xa, ya, xb, yb, x, y);
  25219. }
  25220. break;
  25221. case 10: // callsubr
  25222. n = stack.pop() + font.subrsBias;
  25223. subrCode = font.subrs[n];
  25224. if (subrCode) {
  25225. parse(subrCode);
  25226. }
  25227. break;
  25228. case 11: // return
  25229. return;
  25230. case 12:
  25231. v = code[i++];
  25232. switch (v) {
  25233. case 34: // flex
  25234. xa = x + stack.shift();
  25235. xb = xa + stack.shift(); y1 = y + stack.shift();
  25236. x = xb + stack.shift();
  25237. bezierCurveTo(xa, y, xb, y1, x, y1);
  25238. xa = x + stack.shift();
  25239. xb = xa + stack.shift();
  25240. x = xb + stack.shift();
  25241. bezierCurveTo(xa, y1, xb, y, x, y);
  25242. break;
  25243. case 35: // flex
  25244. xa = x + stack.shift(); ya = y + stack.shift();
  25245. xb = xa + stack.shift(); yb = ya + stack.shift();
  25246. x = xb + stack.shift(); y = yb + stack.shift();
  25247. bezierCurveTo(xa, ya, xb, yb, x, y);
  25248. xa = x + stack.shift(); ya = y + stack.shift();
  25249. xb = xa + stack.shift(); yb = ya + stack.shift();
  25250. x = xb + stack.shift(); y = yb + stack.shift();
  25251. bezierCurveTo(xa, ya, xb, yb, x, y);
  25252. stack.pop(); // fd
  25253. break;
  25254. case 36: // hflex1
  25255. xa = x + stack.shift(); y1 = y + stack.shift();
  25256. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25257. x = xb + stack.shift();
  25258. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25259. xa = x + stack.shift();
  25260. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25261. x = xb + stack.shift();
  25262. bezierCurveTo(xa, y2, xb, y3, x, y);
  25263. break;
  25264. case 37: // flex1
  25265. var x0 = x, y0 = y;
  25266. xa = x + stack.shift(); ya = y + stack.shift();
  25267. xb = xa + stack.shift(); yb = ya + stack.shift();
  25268. x = xb + stack.shift(); y = yb + stack.shift();
  25269. bezierCurveTo(xa, ya, xb, yb, x, y);
  25270. xa = x + stack.shift(); ya = y + stack.shift();
  25271. xb = xa + stack.shift(); yb = ya + stack.shift();
  25272. x = xb; y = yb;
  25273. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25274. x += stack.shift();
  25275. } else {
  25276. y += stack.shift();
  25277. }
  25278. bezierCurveTo(xa, ya, xb, yb, x, y);
  25279. break;
  25280. default:
  25281. error('unknown operator: 12 ' + v);
  25282. }
  25283. break;
  25284. case 14: // endchar
  25285. if (stack.length >= 4) {
  25286. var achar = stack.pop();
  25287. var bchar = stack.pop();
  25288. y = stack.pop();
  25289. x = stack.pop();
  25290. js.push('c.save();');
  25291. js.push('c.translate('+ x + ',' + y + ');');
  25292. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25293. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25294. compileCharString(font.glyphs[gid], js, font);
  25295. js.push('c.restore();');
  25296. gid = lookupCmap(font.cmap, String.fromCharCode(
  25297. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25298. compileCharString(font.glyphs[gid], js, font);
  25299. }
  25300. return;
  25301. case 18: // hstemhm
  25302. stems += stack.length >> 1;
  25303. stackClean = true;
  25304. break;
  25305. case 19: // hintmask
  25306. stems += stack.length >> 1;
  25307. i += (stems + 7) >> 3;
  25308. stackClean = true;
  25309. break;
  25310. case 20: // cntrmask
  25311. stems += stack.length >> 1;
  25312. i += (stems + 7) >> 3;
  25313. stackClean = true;
  25314. break;
  25315. case 21: // rmoveto
  25316. y += stack.pop();
  25317. x += stack.pop();
  25318. moveTo(x, y);
  25319. stackClean = true;
  25320. break;
  25321. case 22: // hmoveto
  25322. x += stack.pop();
  25323. moveTo(x, y);
  25324. stackClean = true;
  25325. break;
  25326. case 23: // vstemhm
  25327. stems += stack.length >> 1;
  25328. stackClean = true;
  25329. break;
  25330. case 24: // rcurveline
  25331. while (stack.length > 2) {
  25332. xa = x + stack.shift(); ya = y + stack.shift();
  25333. xb = xa + stack.shift(); yb = ya + stack.shift();
  25334. x = xb + stack.shift(); y = yb + stack.shift();
  25335. bezierCurveTo(xa, ya, xb, yb, x, y);
  25336. }
  25337. x += stack.shift();
  25338. y += stack.shift();
  25339. lineTo(x, y);
  25340. break;
  25341. case 25: // rlinecurve
  25342. while (stack.length > 6) {
  25343. x += stack.shift();
  25344. y += stack.shift();
  25345. lineTo(x, y);
  25346. }
  25347. xa = x + stack.shift(); ya = y + stack.shift();
  25348. xb = xa + stack.shift(); yb = ya + stack.shift();
  25349. x = xb + stack.shift(); y = yb + stack.shift();
  25350. bezierCurveTo(xa, ya, xb, yb, x, y);
  25351. break;
  25352. case 26: // vvcurveto
  25353. if (stack.length % 2) {
  25354. x += stack.shift();
  25355. }
  25356. while (stack.length > 0) {
  25357. xa = x; ya = y + stack.shift();
  25358. xb = xa + stack.shift(); yb = ya + stack.shift();
  25359. x = xb; y = yb + stack.shift();
  25360. bezierCurveTo(xa, ya, xb, yb, x, y);
  25361. }
  25362. break;
  25363. case 27: // hhcurveto
  25364. if (stack.length % 2) {
  25365. y += stack.shift();
  25366. }
  25367. while (stack.length > 0) {
  25368. xa = x + stack.shift(); ya = y;
  25369. xb = xa + stack.shift(); yb = ya + stack.shift();
  25370. x = xb + stack.shift(); y = yb;
  25371. bezierCurveTo(xa, ya, xb, yb, x, y);
  25372. }
  25373. break;
  25374. case 28:
  25375. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25376. i += 2;
  25377. break;
  25378. case 29: // callgsubr
  25379. n = stack.pop() + font.gsubrsBias;
  25380. subrCode = font.gsubrs[n];
  25381. if (subrCode) {
  25382. parse(subrCode);
  25383. }
  25384. break;
  25385. case 30: // vhcurveto
  25386. while (stack.length > 0) {
  25387. xa = x; ya = y + stack.shift();
  25388. xb = xa + stack.shift(); yb = ya + stack.shift();
  25389. x = xb + stack.shift();
  25390. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25391. bezierCurveTo(xa, ya, xb, yb, x, y);
  25392. if (stack.length === 0) {
  25393. break;
  25394. }
  25395. xa = x + stack.shift(); ya = y;
  25396. xb = xa + stack.shift(); yb = ya + stack.shift();
  25397. y = yb + stack.shift();
  25398. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25399. bezierCurveTo(xa, ya, xb, yb, x, y);
  25400. }
  25401. break;
  25402. case 31: // hvcurveto
  25403. while (stack.length > 0) {
  25404. xa = x + stack.shift(); ya = y;
  25405. xb = xa + stack.shift(); yb = ya + stack.shift();
  25406. y = yb + stack.shift();
  25407. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25408. bezierCurveTo(xa, ya, xb, yb, x, y);
  25409. if (stack.length === 0) {
  25410. break;
  25411. }
  25412. xa = x; ya = y + stack.shift();
  25413. xb = xa + stack.shift(); yb = ya + stack.shift();
  25414. x = xb + stack.shift();
  25415. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25416. bezierCurveTo(xa, ya, xb, yb, x, y);
  25417. }
  25418. break;
  25419. default:
  25420. if (v < 32) {
  25421. error('unknown operator: ' + v);
  25422. }
  25423. if (v < 247) {
  25424. stack.push(v - 139);
  25425. } else if (v < 251) {
  25426. stack.push((v - 247) * 256 + code[i++] + 108);
  25427. } else if (v < 255) {
  25428. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25429. } else {
  25430. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25431. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25432. i += 4;
  25433. }
  25434. break;
  25435. }
  25436. if (stackClean) {
  25437. stack.length = 0;
  25438. }
  25439. }
  25440. }
  25441. parse(code);
  25442. }
  25443. var noop = '';
  25444. function CompiledFont(fontMatrix) {
  25445. this.compiledGlyphs = {};
  25446. this.fontMatrix = fontMatrix;
  25447. }
  25448. CompiledFont.prototype = {
  25449. getPathJs: function (unicode) {
  25450. var gid = lookupCmap(this.cmap, unicode);
  25451. var fn = this.compiledGlyphs[gid];
  25452. if (!fn) {
  25453. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25454. }
  25455. return fn;
  25456. },
  25457. compileGlyph: function (code) {
  25458. if (!code || code.length === 0 || code[0] === 14) {
  25459. return noop;
  25460. }
  25461. var js = [];
  25462. js.push('c.save();');
  25463. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25464. js.push('c.scale(size, -size);');
  25465. this.compileGlyphImpl(code, js);
  25466. js.push('c.restore();');
  25467. return js.join('\n');
  25468. },
  25469. compileGlyphImpl: function () {
  25470. error('Children classes should implement this.');
  25471. },
  25472. hasBuiltPath: function (unicode) {
  25473. var gid = lookupCmap(this.cmap, unicode);
  25474. return gid in this.compiledGlyphs;
  25475. }
  25476. };
  25477. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25478. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25479. CompiledFont.call(this, fontMatrix);
  25480. this.glyphs = glyphs;
  25481. this.cmap = cmap;
  25482. this.compiledGlyphs = [];
  25483. }
  25484. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25485. compileGlyphImpl: function (code, js) {
  25486. compileGlyf(code, js, this);
  25487. }
  25488. });
  25489. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25490. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25491. CompiledFont.call(this, fontMatrix);
  25492. this.glyphs = cffInfo.glyphs;
  25493. this.gsubrs = cffInfo.gsubrs || [];
  25494. this.subrs = cffInfo.subrs || [];
  25495. this.cmap = cmap;
  25496. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25497. this.compiledGlyphs = [];
  25498. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25499. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25500. this.subrsBias = (this.subrs.length < 1240 ?
  25501. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25502. }
  25503. Util.inherit(Type2Compiled, CompiledFont, {
  25504. compileGlyphImpl: function (code, js) {
  25505. compileCharString(code, js, this);
  25506. }
  25507. });
  25508. return {
  25509. create: function FontRendererFactory_create(font) {
  25510. var data = new Uint8Array(font.data);
  25511. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25512. var numTables = getUshort(data, 4);
  25513. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25514. var tag = bytesToString(data.subarray(p, p + 4));
  25515. var offset = getLong(data, p + 8);
  25516. var length = getLong(data, p + 12);
  25517. switch (tag) {
  25518. case 'cmap':
  25519. cmap = parseCmap(data, offset, offset + length);
  25520. break;
  25521. case 'glyf':
  25522. glyf = data.subarray(offset, offset + length);
  25523. break;
  25524. case 'loca':
  25525. loca = data.subarray(offset, offset + length);
  25526. break;
  25527. case 'head':
  25528. unitsPerEm = getUshort(data, offset + 18);
  25529. indexToLocFormat = getUshort(data, offset + 50);
  25530. break;
  25531. case 'CFF ':
  25532. cff = parseCff(data, offset, offset + length);
  25533. break;
  25534. }
  25535. }
  25536. if (glyf) {
  25537. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25538. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25539. return new TrueTypeCompiled(
  25540. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25541. } else {
  25542. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25543. }
  25544. }
  25545. };
  25546. })();
  25547. var GlyphsUnicode = {
  25548. A: 0x0041,
  25549. AE: 0x00C6,
  25550. AEacute: 0x01FC,
  25551. AEmacron: 0x01E2,
  25552. AEsmall: 0xF7E6,
  25553. Aacute: 0x00C1,
  25554. Aacutesmall: 0xF7E1,
  25555. Abreve: 0x0102,
  25556. Abreveacute: 0x1EAE,
  25557. Abrevecyrillic: 0x04D0,
  25558. Abrevedotbelow: 0x1EB6,
  25559. Abrevegrave: 0x1EB0,
  25560. Abrevehookabove: 0x1EB2,
  25561. Abrevetilde: 0x1EB4,
  25562. Acaron: 0x01CD,
  25563. Acircle: 0x24B6,
  25564. Acircumflex: 0x00C2,
  25565. Acircumflexacute: 0x1EA4,
  25566. Acircumflexdotbelow: 0x1EAC,
  25567. Acircumflexgrave: 0x1EA6,
  25568. Acircumflexhookabove: 0x1EA8,
  25569. Acircumflexsmall: 0xF7E2,
  25570. Acircumflextilde: 0x1EAA,
  25571. Acute: 0xF6C9,
  25572. Acutesmall: 0xF7B4,
  25573. Acyrillic: 0x0410,
  25574. Adblgrave: 0x0200,
  25575. Adieresis: 0x00C4,
  25576. Adieresiscyrillic: 0x04D2,
  25577. Adieresismacron: 0x01DE,
  25578. Adieresissmall: 0xF7E4,
  25579. Adotbelow: 0x1EA0,
  25580. Adotmacron: 0x01E0,
  25581. Agrave: 0x00C0,
  25582. Agravesmall: 0xF7E0,
  25583. Ahookabove: 0x1EA2,
  25584. Aiecyrillic: 0x04D4,
  25585. Ainvertedbreve: 0x0202,
  25586. Alpha: 0x0391,
  25587. Alphatonos: 0x0386,
  25588. Amacron: 0x0100,
  25589. Amonospace: 0xFF21,
  25590. Aogonek: 0x0104,
  25591. Aring: 0x00C5,
  25592. Aringacute: 0x01FA,
  25593. Aringbelow: 0x1E00,
  25594. Aringsmall: 0xF7E5,
  25595. Asmall: 0xF761,
  25596. Atilde: 0x00C3,
  25597. Atildesmall: 0xF7E3,
  25598. Aybarmenian: 0x0531,
  25599. B: 0x0042,
  25600. Bcircle: 0x24B7,
  25601. Bdotaccent: 0x1E02,
  25602. Bdotbelow: 0x1E04,
  25603. Becyrillic: 0x0411,
  25604. Benarmenian: 0x0532,
  25605. Beta: 0x0392,
  25606. Bhook: 0x0181,
  25607. Blinebelow: 0x1E06,
  25608. Bmonospace: 0xFF22,
  25609. Brevesmall: 0xF6F4,
  25610. Bsmall: 0xF762,
  25611. Btopbar: 0x0182,
  25612. C: 0x0043,
  25613. Caarmenian: 0x053E,
  25614. Cacute: 0x0106,
  25615. Caron: 0xF6CA,
  25616. Caronsmall: 0xF6F5,
  25617. Ccaron: 0x010C,
  25618. Ccedilla: 0x00C7,
  25619. Ccedillaacute: 0x1E08,
  25620. Ccedillasmall: 0xF7E7,
  25621. Ccircle: 0x24B8,
  25622. Ccircumflex: 0x0108,
  25623. Cdot: 0x010A,
  25624. Cdotaccent: 0x010A,
  25625. Cedillasmall: 0xF7B8,
  25626. Chaarmenian: 0x0549,
  25627. Cheabkhasiancyrillic: 0x04BC,
  25628. Checyrillic: 0x0427,
  25629. Chedescenderabkhasiancyrillic: 0x04BE,
  25630. Chedescendercyrillic: 0x04B6,
  25631. Chedieresiscyrillic: 0x04F4,
  25632. Cheharmenian: 0x0543,
  25633. Chekhakassiancyrillic: 0x04CB,
  25634. Cheverticalstrokecyrillic: 0x04B8,
  25635. Chi: 0x03A7,
  25636. Chook: 0x0187,
  25637. Circumflexsmall: 0xF6F6,
  25638. Cmonospace: 0xFF23,
  25639. Coarmenian: 0x0551,
  25640. Csmall: 0xF763,
  25641. D: 0x0044,
  25642. DZ: 0x01F1,
  25643. DZcaron: 0x01C4,
  25644. Daarmenian: 0x0534,
  25645. Dafrican: 0x0189,
  25646. Dcaron: 0x010E,
  25647. Dcedilla: 0x1E10,
  25648. Dcircle: 0x24B9,
  25649. Dcircumflexbelow: 0x1E12,
  25650. Dcroat: 0x0110,
  25651. Ddotaccent: 0x1E0A,
  25652. Ddotbelow: 0x1E0C,
  25653. Decyrillic: 0x0414,
  25654. Deicoptic: 0x03EE,
  25655. Delta: 0x2206,
  25656. Deltagreek: 0x0394,
  25657. Dhook: 0x018A,
  25658. Dieresis: 0xF6CB,
  25659. DieresisAcute: 0xF6CC,
  25660. DieresisGrave: 0xF6CD,
  25661. Dieresissmall: 0xF7A8,
  25662. Digammagreek: 0x03DC,
  25663. Djecyrillic: 0x0402,
  25664. Dlinebelow: 0x1E0E,
  25665. Dmonospace: 0xFF24,
  25666. Dotaccentsmall: 0xF6F7,
  25667. Dslash: 0x0110,
  25668. Dsmall: 0xF764,
  25669. Dtopbar: 0x018B,
  25670. Dz: 0x01F2,
  25671. Dzcaron: 0x01C5,
  25672. Dzeabkhasiancyrillic: 0x04E0,
  25673. Dzecyrillic: 0x0405,
  25674. Dzhecyrillic: 0x040F,
  25675. E: 0x0045,
  25676. Eacute: 0x00C9,
  25677. Eacutesmall: 0xF7E9,
  25678. Ebreve: 0x0114,
  25679. Ecaron: 0x011A,
  25680. Ecedillabreve: 0x1E1C,
  25681. Echarmenian: 0x0535,
  25682. Ecircle: 0x24BA,
  25683. Ecircumflex: 0x00CA,
  25684. Ecircumflexacute: 0x1EBE,
  25685. Ecircumflexbelow: 0x1E18,
  25686. Ecircumflexdotbelow: 0x1EC6,
  25687. Ecircumflexgrave: 0x1EC0,
  25688. Ecircumflexhookabove: 0x1EC2,
  25689. Ecircumflexsmall: 0xF7EA,
  25690. Ecircumflextilde: 0x1EC4,
  25691. Ecyrillic: 0x0404,
  25692. Edblgrave: 0x0204,
  25693. Edieresis: 0x00CB,
  25694. Edieresissmall: 0xF7EB,
  25695. Edot: 0x0116,
  25696. Edotaccent: 0x0116,
  25697. Edotbelow: 0x1EB8,
  25698. Efcyrillic: 0x0424,
  25699. Egrave: 0x00C8,
  25700. Egravesmall: 0xF7E8,
  25701. Eharmenian: 0x0537,
  25702. Ehookabove: 0x1EBA,
  25703. Eightroman: 0x2167,
  25704. Einvertedbreve: 0x0206,
  25705. Eiotifiedcyrillic: 0x0464,
  25706. Elcyrillic: 0x041B,
  25707. Elevenroman: 0x216A,
  25708. Emacron: 0x0112,
  25709. Emacronacute: 0x1E16,
  25710. Emacrongrave: 0x1E14,
  25711. Emcyrillic: 0x041C,
  25712. Emonospace: 0xFF25,
  25713. Encyrillic: 0x041D,
  25714. Endescendercyrillic: 0x04A2,
  25715. Eng: 0x014A,
  25716. Enghecyrillic: 0x04A4,
  25717. Enhookcyrillic: 0x04C7,
  25718. Eogonek: 0x0118,
  25719. Eopen: 0x0190,
  25720. Epsilon: 0x0395,
  25721. Epsilontonos: 0x0388,
  25722. Ercyrillic: 0x0420,
  25723. Ereversed: 0x018E,
  25724. Ereversedcyrillic: 0x042D,
  25725. Escyrillic: 0x0421,
  25726. Esdescendercyrillic: 0x04AA,
  25727. Esh: 0x01A9,
  25728. Esmall: 0xF765,
  25729. Eta: 0x0397,
  25730. Etarmenian: 0x0538,
  25731. Etatonos: 0x0389,
  25732. Eth: 0x00D0,
  25733. Ethsmall: 0xF7F0,
  25734. Etilde: 0x1EBC,
  25735. Etildebelow: 0x1E1A,
  25736. Euro: 0x20AC,
  25737. Ezh: 0x01B7,
  25738. Ezhcaron: 0x01EE,
  25739. Ezhreversed: 0x01B8,
  25740. F: 0x0046,
  25741. Fcircle: 0x24BB,
  25742. Fdotaccent: 0x1E1E,
  25743. Feharmenian: 0x0556,
  25744. Feicoptic: 0x03E4,
  25745. Fhook: 0x0191,
  25746. Fitacyrillic: 0x0472,
  25747. Fiveroman: 0x2164,
  25748. Fmonospace: 0xFF26,
  25749. Fourroman: 0x2163,
  25750. Fsmall: 0xF766,
  25751. G: 0x0047,
  25752. GBsquare: 0x3387,
  25753. Gacute: 0x01F4,
  25754. Gamma: 0x0393,
  25755. Gammaafrican: 0x0194,
  25756. Gangiacoptic: 0x03EA,
  25757. Gbreve: 0x011E,
  25758. Gcaron: 0x01E6,
  25759. Gcedilla: 0x0122,
  25760. Gcircle: 0x24BC,
  25761. Gcircumflex: 0x011C,
  25762. Gcommaaccent: 0x0122,
  25763. Gdot: 0x0120,
  25764. Gdotaccent: 0x0120,
  25765. Gecyrillic: 0x0413,
  25766. Ghadarmenian: 0x0542,
  25767. Ghemiddlehookcyrillic: 0x0494,
  25768. Ghestrokecyrillic: 0x0492,
  25769. Gheupturncyrillic: 0x0490,
  25770. Ghook: 0x0193,
  25771. Gimarmenian: 0x0533,
  25772. Gjecyrillic: 0x0403,
  25773. Gmacron: 0x1E20,
  25774. Gmonospace: 0xFF27,
  25775. Grave: 0xF6CE,
  25776. Gravesmall: 0xF760,
  25777. Gsmall: 0xF767,
  25778. Gsmallhook: 0x029B,
  25779. Gstroke: 0x01E4,
  25780. H: 0x0048,
  25781. H18533: 0x25CF,
  25782. H18543: 0x25AA,
  25783. H18551: 0x25AB,
  25784. H22073: 0x25A1,
  25785. HPsquare: 0x33CB,
  25786. Haabkhasiancyrillic: 0x04A8,
  25787. Hadescendercyrillic: 0x04B2,
  25788. Hardsigncyrillic: 0x042A,
  25789. Hbar: 0x0126,
  25790. Hbrevebelow: 0x1E2A,
  25791. Hcedilla: 0x1E28,
  25792. Hcircle: 0x24BD,
  25793. Hcircumflex: 0x0124,
  25794. Hdieresis: 0x1E26,
  25795. Hdotaccent: 0x1E22,
  25796. Hdotbelow: 0x1E24,
  25797. Hmonospace: 0xFF28,
  25798. Hoarmenian: 0x0540,
  25799. Horicoptic: 0x03E8,
  25800. Hsmall: 0xF768,
  25801. Hungarumlaut: 0xF6CF,
  25802. Hungarumlautsmall: 0xF6F8,
  25803. Hzsquare: 0x3390,
  25804. I: 0x0049,
  25805. IAcyrillic: 0x042F,
  25806. IJ: 0x0132,
  25807. IUcyrillic: 0x042E,
  25808. Iacute: 0x00CD,
  25809. Iacutesmall: 0xF7ED,
  25810. Ibreve: 0x012C,
  25811. Icaron: 0x01CF,
  25812. Icircle: 0x24BE,
  25813. Icircumflex: 0x00CE,
  25814. Icircumflexsmall: 0xF7EE,
  25815. Icyrillic: 0x0406,
  25816. Idblgrave: 0x0208,
  25817. Idieresis: 0x00CF,
  25818. Idieresisacute: 0x1E2E,
  25819. Idieresiscyrillic: 0x04E4,
  25820. Idieresissmall: 0xF7EF,
  25821. Idot: 0x0130,
  25822. Idotaccent: 0x0130,
  25823. Idotbelow: 0x1ECA,
  25824. Iebrevecyrillic: 0x04D6,
  25825. Iecyrillic: 0x0415,
  25826. Ifraktur: 0x2111,
  25827. Igrave: 0x00CC,
  25828. Igravesmall: 0xF7EC,
  25829. Ihookabove: 0x1EC8,
  25830. Iicyrillic: 0x0418,
  25831. Iinvertedbreve: 0x020A,
  25832. Iishortcyrillic: 0x0419,
  25833. Imacron: 0x012A,
  25834. Imacroncyrillic: 0x04E2,
  25835. Imonospace: 0xFF29,
  25836. Iniarmenian: 0x053B,
  25837. Iocyrillic: 0x0401,
  25838. Iogonek: 0x012E,
  25839. Iota: 0x0399,
  25840. Iotaafrican: 0x0196,
  25841. Iotadieresis: 0x03AA,
  25842. Iotatonos: 0x038A,
  25843. Ismall: 0xF769,
  25844. Istroke: 0x0197,
  25845. Itilde: 0x0128,
  25846. Itildebelow: 0x1E2C,
  25847. Izhitsacyrillic: 0x0474,
  25848. Izhitsadblgravecyrillic: 0x0476,
  25849. J: 0x004A,
  25850. Jaarmenian: 0x0541,
  25851. Jcircle: 0x24BF,
  25852. Jcircumflex: 0x0134,
  25853. Jecyrillic: 0x0408,
  25854. Jheharmenian: 0x054B,
  25855. Jmonospace: 0xFF2A,
  25856. Jsmall: 0xF76A,
  25857. K: 0x004B,
  25858. KBsquare: 0x3385,
  25859. KKsquare: 0x33CD,
  25860. Kabashkircyrillic: 0x04A0,
  25861. Kacute: 0x1E30,
  25862. Kacyrillic: 0x041A,
  25863. Kadescendercyrillic: 0x049A,
  25864. Kahookcyrillic: 0x04C3,
  25865. Kappa: 0x039A,
  25866. Kastrokecyrillic: 0x049E,
  25867. Kaverticalstrokecyrillic: 0x049C,
  25868. Kcaron: 0x01E8,
  25869. Kcedilla: 0x0136,
  25870. Kcircle: 0x24C0,
  25871. Kcommaaccent: 0x0136,
  25872. Kdotbelow: 0x1E32,
  25873. Keharmenian: 0x0554,
  25874. Kenarmenian: 0x053F,
  25875. Khacyrillic: 0x0425,
  25876. Kheicoptic: 0x03E6,
  25877. Khook: 0x0198,
  25878. Kjecyrillic: 0x040C,
  25879. Klinebelow: 0x1E34,
  25880. Kmonospace: 0xFF2B,
  25881. Koppacyrillic: 0x0480,
  25882. Koppagreek: 0x03DE,
  25883. Ksicyrillic: 0x046E,
  25884. Ksmall: 0xF76B,
  25885. L: 0x004C,
  25886. LJ: 0x01C7,
  25887. LL: 0xF6BF,
  25888. Lacute: 0x0139,
  25889. Lambda: 0x039B,
  25890. Lcaron: 0x013D,
  25891. Lcedilla: 0x013B,
  25892. Lcircle: 0x24C1,
  25893. Lcircumflexbelow: 0x1E3C,
  25894. Lcommaaccent: 0x013B,
  25895. Ldot: 0x013F,
  25896. Ldotaccent: 0x013F,
  25897. Ldotbelow: 0x1E36,
  25898. Ldotbelowmacron: 0x1E38,
  25899. Liwnarmenian: 0x053C,
  25900. Lj: 0x01C8,
  25901. Ljecyrillic: 0x0409,
  25902. Llinebelow: 0x1E3A,
  25903. Lmonospace: 0xFF2C,
  25904. Lslash: 0x0141,
  25905. Lslashsmall: 0xF6F9,
  25906. Lsmall: 0xF76C,
  25907. M: 0x004D,
  25908. MBsquare: 0x3386,
  25909. Macron: 0xF6D0,
  25910. Macronsmall: 0xF7AF,
  25911. Macute: 0x1E3E,
  25912. Mcircle: 0x24C2,
  25913. Mdotaccent: 0x1E40,
  25914. Mdotbelow: 0x1E42,
  25915. Menarmenian: 0x0544,
  25916. Mmonospace: 0xFF2D,
  25917. Msmall: 0xF76D,
  25918. Mturned: 0x019C,
  25919. Mu: 0x039C,
  25920. N: 0x004E,
  25921. NJ: 0x01CA,
  25922. Nacute: 0x0143,
  25923. Ncaron: 0x0147,
  25924. Ncedilla: 0x0145,
  25925. Ncircle: 0x24C3,
  25926. Ncircumflexbelow: 0x1E4A,
  25927. Ncommaaccent: 0x0145,
  25928. Ndotaccent: 0x1E44,
  25929. Ndotbelow: 0x1E46,
  25930. Nhookleft: 0x019D,
  25931. Nineroman: 0x2168,
  25932. Nj: 0x01CB,
  25933. Njecyrillic: 0x040A,
  25934. Nlinebelow: 0x1E48,
  25935. Nmonospace: 0xFF2E,
  25936. Nowarmenian: 0x0546,
  25937. Nsmall: 0xF76E,
  25938. Ntilde: 0x00D1,
  25939. Ntildesmall: 0xF7F1,
  25940. Nu: 0x039D,
  25941. O: 0x004F,
  25942. OE: 0x0152,
  25943. OEsmall: 0xF6FA,
  25944. Oacute: 0x00D3,
  25945. Oacutesmall: 0xF7F3,
  25946. Obarredcyrillic: 0x04E8,
  25947. Obarreddieresiscyrillic: 0x04EA,
  25948. Obreve: 0x014E,
  25949. Ocaron: 0x01D1,
  25950. Ocenteredtilde: 0x019F,
  25951. Ocircle: 0x24C4,
  25952. Ocircumflex: 0x00D4,
  25953. Ocircumflexacute: 0x1ED0,
  25954. Ocircumflexdotbelow: 0x1ED8,
  25955. Ocircumflexgrave: 0x1ED2,
  25956. Ocircumflexhookabove: 0x1ED4,
  25957. Ocircumflexsmall: 0xF7F4,
  25958. Ocircumflextilde: 0x1ED6,
  25959. Ocyrillic: 0x041E,
  25960. Odblacute: 0x0150,
  25961. Odblgrave: 0x020C,
  25962. Odieresis: 0x00D6,
  25963. Odieresiscyrillic: 0x04E6,
  25964. Odieresissmall: 0xF7F6,
  25965. Odotbelow: 0x1ECC,
  25966. Ogoneksmall: 0xF6FB,
  25967. Ograve: 0x00D2,
  25968. Ogravesmall: 0xF7F2,
  25969. Oharmenian: 0x0555,
  25970. Ohm: 0x2126,
  25971. Ohookabove: 0x1ECE,
  25972. Ohorn: 0x01A0,
  25973. Ohornacute: 0x1EDA,
  25974. Ohorndotbelow: 0x1EE2,
  25975. Ohorngrave: 0x1EDC,
  25976. Ohornhookabove: 0x1EDE,
  25977. Ohorntilde: 0x1EE0,
  25978. Ohungarumlaut: 0x0150,
  25979. Oi: 0x01A2,
  25980. Oinvertedbreve: 0x020E,
  25981. Omacron: 0x014C,
  25982. Omacronacute: 0x1E52,
  25983. Omacrongrave: 0x1E50,
  25984. Omega: 0x2126,
  25985. Omegacyrillic: 0x0460,
  25986. Omegagreek: 0x03A9,
  25987. Omegaroundcyrillic: 0x047A,
  25988. Omegatitlocyrillic: 0x047C,
  25989. Omegatonos: 0x038F,
  25990. Omicron: 0x039F,
  25991. Omicrontonos: 0x038C,
  25992. Omonospace: 0xFF2F,
  25993. Oneroman: 0x2160,
  25994. Oogonek: 0x01EA,
  25995. Oogonekmacron: 0x01EC,
  25996. Oopen: 0x0186,
  25997. Oslash: 0x00D8,
  25998. Oslashacute: 0x01FE,
  25999. Oslashsmall: 0xF7F8,
  26000. Osmall: 0xF76F,
  26001. Ostrokeacute: 0x01FE,
  26002. Otcyrillic: 0x047E,
  26003. Otilde: 0x00D5,
  26004. Otildeacute: 0x1E4C,
  26005. Otildedieresis: 0x1E4E,
  26006. Otildesmall: 0xF7F5,
  26007. P: 0x0050,
  26008. Pacute: 0x1E54,
  26009. Pcircle: 0x24C5,
  26010. Pdotaccent: 0x1E56,
  26011. Pecyrillic: 0x041F,
  26012. Peharmenian: 0x054A,
  26013. Pemiddlehookcyrillic: 0x04A6,
  26014. Phi: 0x03A6,
  26015. Phook: 0x01A4,
  26016. Pi: 0x03A0,
  26017. Piwrarmenian: 0x0553,
  26018. Pmonospace: 0xFF30,
  26019. Psi: 0x03A8,
  26020. Psicyrillic: 0x0470,
  26021. Psmall: 0xF770,
  26022. Q: 0x0051,
  26023. Qcircle: 0x24C6,
  26024. Qmonospace: 0xFF31,
  26025. Qsmall: 0xF771,
  26026. R: 0x0052,
  26027. Raarmenian: 0x054C,
  26028. Racute: 0x0154,
  26029. Rcaron: 0x0158,
  26030. Rcedilla: 0x0156,
  26031. Rcircle: 0x24C7,
  26032. Rcommaaccent: 0x0156,
  26033. Rdblgrave: 0x0210,
  26034. Rdotaccent: 0x1E58,
  26035. Rdotbelow: 0x1E5A,
  26036. Rdotbelowmacron: 0x1E5C,
  26037. Reharmenian: 0x0550,
  26038. Rfraktur: 0x211C,
  26039. Rho: 0x03A1,
  26040. Ringsmall: 0xF6FC,
  26041. Rinvertedbreve: 0x0212,
  26042. Rlinebelow: 0x1E5E,
  26043. Rmonospace: 0xFF32,
  26044. Rsmall: 0xF772,
  26045. Rsmallinverted: 0x0281,
  26046. Rsmallinvertedsuperior: 0x02B6,
  26047. S: 0x0053,
  26048. SF010000: 0x250C,
  26049. SF020000: 0x2514,
  26050. SF030000: 0x2510,
  26051. SF040000: 0x2518,
  26052. SF050000: 0x253C,
  26053. SF060000: 0x252C,
  26054. SF070000: 0x2534,
  26055. SF080000: 0x251C,
  26056. SF090000: 0x2524,
  26057. SF100000: 0x2500,
  26058. SF110000: 0x2502,
  26059. SF190000: 0x2561,
  26060. SF200000: 0x2562,
  26061. SF210000: 0x2556,
  26062. SF220000: 0x2555,
  26063. SF230000: 0x2563,
  26064. SF240000: 0x2551,
  26065. SF250000: 0x2557,
  26066. SF260000: 0x255D,
  26067. SF270000: 0x255C,
  26068. SF280000: 0x255B,
  26069. SF360000: 0x255E,
  26070. SF370000: 0x255F,
  26071. SF380000: 0x255A,
  26072. SF390000: 0x2554,
  26073. SF400000: 0x2569,
  26074. SF410000: 0x2566,
  26075. SF420000: 0x2560,
  26076. SF430000: 0x2550,
  26077. SF440000: 0x256C,
  26078. SF450000: 0x2567,
  26079. SF460000: 0x2568,
  26080. SF470000: 0x2564,
  26081. SF480000: 0x2565,
  26082. SF490000: 0x2559,
  26083. SF500000: 0x2558,
  26084. SF510000: 0x2552,
  26085. SF520000: 0x2553,
  26086. SF530000: 0x256B,
  26087. SF540000: 0x256A,
  26088. Sacute: 0x015A,
  26089. Sacutedotaccent: 0x1E64,
  26090. Sampigreek: 0x03E0,
  26091. Scaron: 0x0160,
  26092. Scarondotaccent: 0x1E66,
  26093. Scaronsmall: 0xF6FD,
  26094. Scedilla: 0x015E,
  26095. Schwa: 0x018F,
  26096. Schwacyrillic: 0x04D8,
  26097. Schwadieresiscyrillic: 0x04DA,
  26098. Scircle: 0x24C8,
  26099. Scircumflex: 0x015C,
  26100. Scommaaccent: 0x0218,
  26101. Sdotaccent: 0x1E60,
  26102. Sdotbelow: 0x1E62,
  26103. Sdotbelowdotaccent: 0x1E68,
  26104. Seharmenian: 0x054D,
  26105. Sevenroman: 0x2166,
  26106. Shaarmenian: 0x0547,
  26107. Shacyrillic: 0x0428,
  26108. Shchacyrillic: 0x0429,
  26109. Sheicoptic: 0x03E2,
  26110. Shhacyrillic: 0x04BA,
  26111. Shimacoptic: 0x03EC,
  26112. Sigma: 0x03A3,
  26113. Sixroman: 0x2165,
  26114. Smonospace: 0xFF33,
  26115. Softsigncyrillic: 0x042C,
  26116. Ssmall: 0xF773,
  26117. Stigmagreek: 0x03DA,
  26118. T: 0x0054,
  26119. Tau: 0x03A4,
  26120. Tbar: 0x0166,
  26121. Tcaron: 0x0164,
  26122. Tcedilla: 0x0162,
  26123. Tcircle: 0x24C9,
  26124. Tcircumflexbelow: 0x1E70,
  26125. Tcommaaccent: 0x0162,
  26126. Tdotaccent: 0x1E6A,
  26127. Tdotbelow: 0x1E6C,
  26128. Tecyrillic: 0x0422,
  26129. Tedescendercyrillic: 0x04AC,
  26130. Tenroman: 0x2169,
  26131. Tetsecyrillic: 0x04B4,
  26132. Theta: 0x0398,
  26133. Thook: 0x01AC,
  26134. Thorn: 0x00DE,
  26135. Thornsmall: 0xF7FE,
  26136. Threeroman: 0x2162,
  26137. Tildesmall: 0xF6FE,
  26138. Tiwnarmenian: 0x054F,
  26139. Tlinebelow: 0x1E6E,
  26140. Tmonospace: 0xFF34,
  26141. Toarmenian: 0x0539,
  26142. Tonefive: 0x01BC,
  26143. Tonesix: 0x0184,
  26144. Tonetwo: 0x01A7,
  26145. Tretroflexhook: 0x01AE,
  26146. Tsecyrillic: 0x0426,
  26147. Tshecyrillic: 0x040B,
  26148. Tsmall: 0xF774,
  26149. Twelveroman: 0x216B,
  26150. Tworoman: 0x2161,
  26151. U: 0x0055,
  26152. Uacute: 0x00DA,
  26153. Uacutesmall: 0xF7FA,
  26154. Ubreve: 0x016C,
  26155. Ucaron: 0x01D3,
  26156. Ucircle: 0x24CA,
  26157. Ucircumflex: 0x00DB,
  26158. Ucircumflexbelow: 0x1E76,
  26159. Ucircumflexsmall: 0xF7FB,
  26160. Ucyrillic: 0x0423,
  26161. Udblacute: 0x0170,
  26162. Udblgrave: 0x0214,
  26163. Udieresis: 0x00DC,
  26164. Udieresisacute: 0x01D7,
  26165. Udieresisbelow: 0x1E72,
  26166. Udieresiscaron: 0x01D9,
  26167. Udieresiscyrillic: 0x04F0,
  26168. Udieresisgrave: 0x01DB,
  26169. Udieresismacron: 0x01D5,
  26170. Udieresissmall: 0xF7FC,
  26171. Udotbelow: 0x1EE4,
  26172. Ugrave: 0x00D9,
  26173. Ugravesmall: 0xF7F9,
  26174. Uhookabove: 0x1EE6,
  26175. Uhorn: 0x01AF,
  26176. Uhornacute: 0x1EE8,
  26177. Uhorndotbelow: 0x1EF0,
  26178. Uhorngrave: 0x1EEA,
  26179. Uhornhookabove: 0x1EEC,
  26180. Uhorntilde: 0x1EEE,
  26181. Uhungarumlaut: 0x0170,
  26182. Uhungarumlautcyrillic: 0x04F2,
  26183. Uinvertedbreve: 0x0216,
  26184. Ukcyrillic: 0x0478,
  26185. Umacron: 0x016A,
  26186. Umacroncyrillic: 0x04EE,
  26187. Umacrondieresis: 0x1E7A,
  26188. Umonospace: 0xFF35,
  26189. Uogonek: 0x0172,
  26190. Upsilon: 0x03A5,
  26191. Upsilon1: 0x03D2,
  26192. Upsilonacutehooksymbolgreek: 0x03D3,
  26193. Upsilonafrican: 0x01B1,
  26194. Upsilondieresis: 0x03AB,
  26195. Upsilondieresishooksymbolgreek: 0x03D4,
  26196. Upsilonhooksymbol: 0x03D2,
  26197. Upsilontonos: 0x038E,
  26198. Uring: 0x016E,
  26199. Ushortcyrillic: 0x040E,
  26200. Usmall: 0xF775,
  26201. Ustraightcyrillic: 0x04AE,
  26202. Ustraightstrokecyrillic: 0x04B0,
  26203. Utilde: 0x0168,
  26204. Utildeacute: 0x1E78,
  26205. Utildebelow: 0x1E74,
  26206. V: 0x0056,
  26207. Vcircle: 0x24CB,
  26208. Vdotbelow: 0x1E7E,
  26209. Vecyrillic: 0x0412,
  26210. Vewarmenian: 0x054E,
  26211. Vhook: 0x01B2,
  26212. Vmonospace: 0xFF36,
  26213. Voarmenian: 0x0548,
  26214. Vsmall: 0xF776,
  26215. Vtilde: 0x1E7C,
  26216. W: 0x0057,
  26217. Wacute: 0x1E82,
  26218. Wcircle: 0x24CC,
  26219. Wcircumflex: 0x0174,
  26220. Wdieresis: 0x1E84,
  26221. Wdotaccent: 0x1E86,
  26222. Wdotbelow: 0x1E88,
  26223. Wgrave: 0x1E80,
  26224. Wmonospace: 0xFF37,
  26225. Wsmall: 0xF777,
  26226. X: 0x0058,
  26227. Xcircle: 0x24CD,
  26228. Xdieresis: 0x1E8C,
  26229. Xdotaccent: 0x1E8A,
  26230. Xeharmenian: 0x053D,
  26231. Xi: 0x039E,
  26232. Xmonospace: 0xFF38,
  26233. Xsmall: 0xF778,
  26234. Y: 0x0059,
  26235. Yacute: 0x00DD,
  26236. Yacutesmall: 0xF7FD,
  26237. Yatcyrillic: 0x0462,
  26238. Ycircle: 0x24CE,
  26239. Ycircumflex: 0x0176,
  26240. Ydieresis: 0x0178,
  26241. Ydieresissmall: 0xF7FF,
  26242. Ydotaccent: 0x1E8E,
  26243. Ydotbelow: 0x1EF4,
  26244. Yericyrillic: 0x042B,
  26245. Yerudieresiscyrillic: 0x04F8,
  26246. Ygrave: 0x1EF2,
  26247. Yhook: 0x01B3,
  26248. Yhookabove: 0x1EF6,
  26249. Yiarmenian: 0x0545,
  26250. Yicyrillic: 0x0407,
  26251. Yiwnarmenian: 0x0552,
  26252. Ymonospace: 0xFF39,
  26253. Ysmall: 0xF779,
  26254. Ytilde: 0x1EF8,
  26255. Yusbigcyrillic: 0x046A,
  26256. Yusbigiotifiedcyrillic: 0x046C,
  26257. Yuslittlecyrillic: 0x0466,
  26258. Yuslittleiotifiedcyrillic: 0x0468,
  26259. Z: 0x005A,
  26260. Zaarmenian: 0x0536,
  26261. Zacute: 0x0179,
  26262. Zcaron: 0x017D,
  26263. Zcaronsmall: 0xF6FF,
  26264. Zcircle: 0x24CF,
  26265. Zcircumflex: 0x1E90,
  26266. Zdot: 0x017B,
  26267. Zdotaccent: 0x017B,
  26268. Zdotbelow: 0x1E92,
  26269. Zecyrillic: 0x0417,
  26270. Zedescendercyrillic: 0x0498,
  26271. Zedieresiscyrillic: 0x04DE,
  26272. Zeta: 0x0396,
  26273. Zhearmenian: 0x053A,
  26274. Zhebrevecyrillic: 0x04C1,
  26275. Zhecyrillic: 0x0416,
  26276. Zhedescendercyrillic: 0x0496,
  26277. Zhedieresiscyrillic: 0x04DC,
  26278. Zlinebelow: 0x1E94,
  26279. Zmonospace: 0xFF3A,
  26280. Zsmall: 0xF77A,
  26281. Zstroke: 0x01B5,
  26282. a: 0x0061,
  26283. aabengali: 0x0986,
  26284. aacute: 0x00E1,
  26285. aadeva: 0x0906,
  26286. aagujarati: 0x0A86,
  26287. aagurmukhi: 0x0A06,
  26288. aamatragurmukhi: 0x0A3E,
  26289. aarusquare: 0x3303,
  26290. aavowelsignbengali: 0x09BE,
  26291. aavowelsigndeva: 0x093E,
  26292. aavowelsigngujarati: 0x0ABE,
  26293. abbreviationmarkarmenian: 0x055F,
  26294. abbreviationsigndeva: 0x0970,
  26295. abengali: 0x0985,
  26296. abopomofo: 0x311A,
  26297. abreve: 0x0103,
  26298. abreveacute: 0x1EAF,
  26299. abrevecyrillic: 0x04D1,
  26300. abrevedotbelow: 0x1EB7,
  26301. abrevegrave: 0x1EB1,
  26302. abrevehookabove: 0x1EB3,
  26303. abrevetilde: 0x1EB5,
  26304. acaron: 0x01CE,
  26305. acircle: 0x24D0,
  26306. acircumflex: 0x00E2,
  26307. acircumflexacute: 0x1EA5,
  26308. acircumflexdotbelow: 0x1EAD,
  26309. acircumflexgrave: 0x1EA7,
  26310. acircumflexhookabove: 0x1EA9,
  26311. acircumflextilde: 0x1EAB,
  26312. acute: 0x00B4,
  26313. acutebelowcmb: 0x0317,
  26314. acutecmb: 0x0301,
  26315. acutecomb: 0x0301,
  26316. acutedeva: 0x0954,
  26317. acutelowmod: 0x02CF,
  26318. acutetonecmb: 0x0341,
  26319. acyrillic: 0x0430,
  26320. adblgrave: 0x0201,
  26321. addakgurmukhi: 0x0A71,
  26322. adeva: 0x0905,
  26323. adieresis: 0x00E4,
  26324. adieresiscyrillic: 0x04D3,
  26325. adieresismacron: 0x01DF,
  26326. adotbelow: 0x1EA1,
  26327. adotmacron: 0x01E1,
  26328. ae: 0x00E6,
  26329. aeacute: 0x01FD,
  26330. aekorean: 0x3150,
  26331. aemacron: 0x01E3,
  26332. afii00208: 0x2015,
  26333. afii08941: 0x20A4,
  26334. afii10017: 0x0410,
  26335. afii10018: 0x0411,
  26336. afii10019: 0x0412,
  26337. afii10020: 0x0413,
  26338. afii10021: 0x0414,
  26339. afii10022: 0x0415,
  26340. afii10023: 0x0401,
  26341. afii10024: 0x0416,
  26342. afii10025: 0x0417,
  26343. afii10026: 0x0418,
  26344. afii10027: 0x0419,
  26345. afii10028: 0x041A,
  26346. afii10029: 0x041B,
  26347. afii10030: 0x041C,
  26348. afii10031: 0x041D,
  26349. afii10032: 0x041E,
  26350. afii10033: 0x041F,
  26351. afii10034: 0x0420,
  26352. afii10035: 0x0421,
  26353. afii10036: 0x0422,
  26354. afii10037: 0x0423,
  26355. afii10038: 0x0424,
  26356. afii10039: 0x0425,
  26357. afii10040: 0x0426,
  26358. afii10041: 0x0427,
  26359. afii10042: 0x0428,
  26360. afii10043: 0x0429,
  26361. afii10044: 0x042A,
  26362. afii10045: 0x042B,
  26363. afii10046: 0x042C,
  26364. afii10047: 0x042D,
  26365. afii10048: 0x042E,
  26366. afii10049: 0x042F,
  26367. afii10050: 0x0490,
  26368. afii10051: 0x0402,
  26369. afii10052: 0x0403,
  26370. afii10053: 0x0404,
  26371. afii10054: 0x0405,
  26372. afii10055: 0x0406,
  26373. afii10056: 0x0407,
  26374. afii10057: 0x0408,
  26375. afii10058: 0x0409,
  26376. afii10059: 0x040A,
  26377. afii10060: 0x040B,
  26378. afii10061: 0x040C,
  26379. afii10062: 0x040E,
  26380. afii10063: 0xF6C4,
  26381. afii10064: 0xF6C5,
  26382. afii10065: 0x0430,
  26383. afii10066: 0x0431,
  26384. afii10067: 0x0432,
  26385. afii10068: 0x0433,
  26386. afii10069: 0x0434,
  26387. afii10070: 0x0435,
  26388. afii10071: 0x0451,
  26389. afii10072: 0x0436,
  26390. afii10073: 0x0437,
  26391. afii10074: 0x0438,
  26392. afii10075: 0x0439,
  26393. afii10076: 0x043A,
  26394. afii10077: 0x043B,
  26395. afii10078: 0x043C,
  26396. afii10079: 0x043D,
  26397. afii10080: 0x043E,
  26398. afii10081: 0x043F,
  26399. afii10082: 0x0440,
  26400. afii10083: 0x0441,
  26401. afii10084: 0x0442,
  26402. afii10085: 0x0443,
  26403. afii10086: 0x0444,
  26404. afii10087: 0x0445,
  26405. afii10088: 0x0446,
  26406. afii10089: 0x0447,
  26407. afii10090: 0x0448,
  26408. afii10091: 0x0449,
  26409. afii10092: 0x044A,
  26410. afii10093: 0x044B,
  26411. afii10094: 0x044C,
  26412. afii10095: 0x044D,
  26413. afii10096: 0x044E,
  26414. afii10097: 0x044F,
  26415. afii10098: 0x0491,
  26416. afii10099: 0x0452,
  26417. afii10100: 0x0453,
  26418. afii10101: 0x0454,
  26419. afii10102: 0x0455,
  26420. afii10103: 0x0456,
  26421. afii10104: 0x0457,
  26422. afii10105: 0x0458,
  26423. afii10106: 0x0459,
  26424. afii10107: 0x045A,
  26425. afii10108: 0x045B,
  26426. afii10109: 0x045C,
  26427. afii10110: 0x045E,
  26428. afii10145: 0x040F,
  26429. afii10146: 0x0462,
  26430. afii10147: 0x0472,
  26431. afii10148: 0x0474,
  26432. afii10192: 0xF6C6,
  26433. afii10193: 0x045F,
  26434. afii10194: 0x0463,
  26435. afii10195: 0x0473,
  26436. afii10196: 0x0475,
  26437. afii10831: 0xF6C7,
  26438. afii10832: 0xF6C8,
  26439. afii10846: 0x04D9,
  26440. afii299: 0x200E,
  26441. afii300: 0x200F,
  26442. afii301: 0x200D,
  26443. afii57381: 0x066A,
  26444. afii57388: 0x060C,
  26445. afii57392: 0x0660,
  26446. afii57393: 0x0661,
  26447. afii57394: 0x0662,
  26448. afii57395: 0x0663,
  26449. afii57396: 0x0664,
  26450. afii57397: 0x0665,
  26451. afii57398: 0x0666,
  26452. afii57399: 0x0667,
  26453. afii57400: 0x0668,
  26454. afii57401: 0x0669,
  26455. afii57403: 0x061B,
  26456. afii57407: 0x061F,
  26457. afii57409: 0x0621,
  26458. afii57410: 0x0622,
  26459. afii57411: 0x0623,
  26460. afii57412: 0x0624,
  26461. afii57413: 0x0625,
  26462. afii57414: 0x0626,
  26463. afii57415: 0x0627,
  26464. afii57416: 0x0628,
  26465. afii57417: 0x0629,
  26466. afii57418: 0x062A,
  26467. afii57419: 0x062B,
  26468. afii57420: 0x062C,
  26469. afii57421: 0x062D,
  26470. afii57422: 0x062E,
  26471. afii57423: 0x062F,
  26472. afii57424: 0x0630,
  26473. afii57425: 0x0631,
  26474. afii57426: 0x0632,
  26475. afii57427: 0x0633,
  26476. afii57428: 0x0634,
  26477. afii57429: 0x0635,
  26478. afii57430: 0x0636,
  26479. afii57431: 0x0637,
  26480. afii57432: 0x0638,
  26481. afii57433: 0x0639,
  26482. afii57434: 0x063A,
  26483. afii57440: 0x0640,
  26484. afii57441: 0x0641,
  26485. afii57442: 0x0642,
  26486. afii57443: 0x0643,
  26487. afii57444: 0x0644,
  26488. afii57445: 0x0645,
  26489. afii57446: 0x0646,
  26490. afii57448: 0x0648,
  26491. afii57449: 0x0649,
  26492. afii57450: 0x064A,
  26493. afii57451: 0x064B,
  26494. afii57452: 0x064C,
  26495. afii57453: 0x064D,
  26496. afii57454: 0x064E,
  26497. afii57455: 0x064F,
  26498. afii57456: 0x0650,
  26499. afii57457: 0x0651,
  26500. afii57458: 0x0652,
  26501. afii57470: 0x0647,
  26502. afii57505: 0x06A4,
  26503. afii57506: 0x067E,
  26504. afii57507: 0x0686,
  26505. afii57508: 0x0698,
  26506. afii57509: 0x06AF,
  26507. afii57511: 0x0679,
  26508. afii57512: 0x0688,
  26509. afii57513: 0x0691,
  26510. afii57514: 0x06BA,
  26511. afii57519: 0x06D2,
  26512. afii57534: 0x06D5,
  26513. afii57636: 0x20AA,
  26514. afii57645: 0x05BE,
  26515. afii57658: 0x05C3,
  26516. afii57664: 0x05D0,
  26517. afii57665: 0x05D1,
  26518. afii57666: 0x05D2,
  26519. afii57667: 0x05D3,
  26520. afii57668: 0x05D4,
  26521. afii57669: 0x05D5,
  26522. afii57670: 0x05D6,
  26523. afii57671: 0x05D7,
  26524. afii57672: 0x05D8,
  26525. afii57673: 0x05D9,
  26526. afii57674: 0x05DA,
  26527. afii57675: 0x05DB,
  26528. afii57676: 0x05DC,
  26529. afii57677: 0x05DD,
  26530. afii57678: 0x05DE,
  26531. afii57679: 0x05DF,
  26532. afii57680: 0x05E0,
  26533. afii57681: 0x05E1,
  26534. afii57682: 0x05E2,
  26535. afii57683: 0x05E3,
  26536. afii57684: 0x05E4,
  26537. afii57685: 0x05E5,
  26538. afii57686: 0x05E6,
  26539. afii57687: 0x05E7,
  26540. afii57688: 0x05E8,
  26541. afii57689: 0x05E9,
  26542. afii57690: 0x05EA,
  26543. afii57694: 0xFB2A,
  26544. afii57695: 0xFB2B,
  26545. afii57700: 0xFB4B,
  26546. afii57705: 0xFB1F,
  26547. afii57716: 0x05F0,
  26548. afii57717: 0x05F1,
  26549. afii57718: 0x05F2,
  26550. afii57723: 0xFB35,
  26551. afii57793: 0x05B4,
  26552. afii57794: 0x05B5,
  26553. afii57795: 0x05B6,
  26554. afii57796: 0x05BB,
  26555. afii57797: 0x05B8,
  26556. afii57798: 0x05B7,
  26557. afii57799: 0x05B0,
  26558. afii57800: 0x05B2,
  26559. afii57801: 0x05B1,
  26560. afii57802: 0x05B3,
  26561. afii57803: 0x05C2,
  26562. afii57804: 0x05C1,
  26563. afii57806: 0x05B9,
  26564. afii57807: 0x05BC,
  26565. afii57839: 0x05BD,
  26566. afii57841: 0x05BF,
  26567. afii57842: 0x05C0,
  26568. afii57929: 0x02BC,
  26569. afii61248: 0x2105,
  26570. afii61289: 0x2113,
  26571. afii61352: 0x2116,
  26572. afii61573: 0x202C,
  26573. afii61574: 0x202D,
  26574. afii61575: 0x202E,
  26575. afii61664: 0x200C,
  26576. afii63167: 0x066D,
  26577. afii64937: 0x02BD,
  26578. agrave: 0x00E0,
  26579. agujarati: 0x0A85,
  26580. agurmukhi: 0x0A05,
  26581. ahiragana: 0x3042,
  26582. ahookabove: 0x1EA3,
  26583. aibengali: 0x0990,
  26584. aibopomofo: 0x311E,
  26585. aideva: 0x0910,
  26586. aiecyrillic: 0x04D5,
  26587. aigujarati: 0x0A90,
  26588. aigurmukhi: 0x0A10,
  26589. aimatragurmukhi: 0x0A48,
  26590. ainarabic: 0x0639,
  26591. ainfinalarabic: 0xFECA,
  26592. aininitialarabic: 0xFECB,
  26593. ainmedialarabic: 0xFECC,
  26594. ainvertedbreve: 0x0203,
  26595. aivowelsignbengali: 0x09C8,
  26596. aivowelsigndeva: 0x0948,
  26597. aivowelsigngujarati: 0x0AC8,
  26598. akatakana: 0x30A2,
  26599. akatakanahalfwidth: 0xFF71,
  26600. akorean: 0x314F,
  26601. alef: 0x05D0,
  26602. alefarabic: 0x0627,
  26603. alefdageshhebrew: 0xFB30,
  26604. aleffinalarabic: 0xFE8E,
  26605. alefhamzaabovearabic: 0x0623,
  26606. alefhamzaabovefinalarabic: 0xFE84,
  26607. alefhamzabelowarabic: 0x0625,
  26608. alefhamzabelowfinalarabic: 0xFE88,
  26609. alefhebrew: 0x05D0,
  26610. aleflamedhebrew: 0xFB4F,
  26611. alefmaddaabovearabic: 0x0622,
  26612. alefmaddaabovefinalarabic: 0xFE82,
  26613. alefmaksuraarabic: 0x0649,
  26614. alefmaksurafinalarabic: 0xFEF0,
  26615. alefmaksurainitialarabic: 0xFEF3,
  26616. alefmaksuramedialarabic: 0xFEF4,
  26617. alefpatahhebrew: 0xFB2E,
  26618. alefqamatshebrew: 0xFB2F,
  26619. aleph: 0x2135,
  26620. allequal: 0x224C,
  26621. alpha: 0x03B1,
  26622. alphatonos: 0x03AC,
  26623. amacron: 0x0101,
  26624. amonospace: 0xFF41,
  26625. ampersand: 0x0026,
  26626. ampersandmonospace: 0xFF06,
  26627. ampersandsmall: 0xF726,
  26628. amsquare: 0x33C2,
  26629. anbopomofo: 0x3122,
  26630. angbopomofo: 0x3124,
  26631. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  26632. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  26633. angkhankhuthai: 0x0E5A,
  26634. angle: 0x2220,
  26635. anglebracketleft: 0x3008,
  26636. anglebracketleftvertical: 0xFE3F,
  26637. anglebracketright: 0x3009,
  26638. anglebracketrightvertical: 0xFE40,
  26639. angleleft: 0x2329,
  26640. angleright: 0x232A,
  26641. angstrom: 0x212B,
  26642. anoteleia: 0x0387,
  26643. anudattadeva: 0x0952,
  26644. anusvarabengali: 0x0982,
  26645. anusvaradeva: 0x0902,
  26646. anusvaragujarati: 0x0A82,
  26647. aogonek: 0x0105,
  26648. apaatosquare: 0x3300,
  26649. aparen: 0x249C,
  26650. apostrophearmenian: 0x055A,
  26651. apostrophemod: 0x02BC,
  26652. apple: 0xF8FF,
  26653. approaches: 0x2250,
  26654. approxequal: 0x2248,
  26655. approxequalorimage: 0x2252,
  26656. approximatelyequal: 0x2245,
  26657. araeaekorean: 0x318E,
  26658. araeakorean: 0x318D,
  26659. arc: 0x2312,
  26660. arighthalfring: 0x1E9A,
  26661. aring: 0x00E5,
  26662. aringacute: 0x01FB,
  26663. aringbelow: 0x1E01,
  26664. arrowboth: 0x2194,
  26665. arrowdashdown: 0x21E3,
  26666. arrowdashleft: 0x21E0,
  26667. arrowdashright: 0x21E2,
  26668. arrowdashup: 0x21E1,
  26669. arrowdblboth: 0x21D4,
  26670. arrowdbldown: 0x21D3,
  26671. arrowdblleft: 0x21D0,
  26672. arrowdblright: 0x21D2,
  26673. arrowdblup: 0x21D1,
  26674. arrowdown: 0x2193,
  26675. arrowdownleft: 0x2199,
  26676. arrowdownright: 0x2198,
  26677. arrowdownwhite: 0x21E9,
  26678. arrowheaddownmod: 0x02C5,
  26679. arrowheadleftmod: 0x02C2,
  26680. arrowheadrightmod: 0x02C3,
  26681. arrowheadupmod: 0x02C4,
  26682. arrowhorizex: 0xF8E7,
  26683. arrowleft: 0x2190,
  26684. arrowleftdbl: 0x21D0,
  26685. arrowleftdblstroke: 0x21CD,
  26686. arrowleftoverright: 0x21C6,
  26687. arrowleftwhite: 0x21E6,
  26688. arrowright: 0x2192,
  26689. arrowrightdblstroke: 0x21CF,
  26690. arrowrightheavy: 0x279E,
  26691. arrowrightoverleft: 0x21C4,
  26692. arrowrightwhite: 0x21E8,
  26693. arrowtableft: 0x21E4,
  26694. arrowtabright: 0x21E5,
  26695. arrowup: 0x2191,
  26696. arrowupdn: 0x2195,
  26697. arrowupdnbse: 0x21A8,
  26698. arrowupdownbase: 0x21A8,
  26699. arrowupleft: 0x2196,
  26700. arrowupleftofdown: 0x21C5,
  26701. arrowupright: 0x2197,
  26702. arrowupwhite: 0x21E7,
  26703. arrowvertex: 0xF8E6,
  26704. asciicircum: 0x005E,
  26705. asciicircummonospace: 0xFF3E,
  26706. asciitilde: 0x007E,
  26707. asciitildemonospace: 0xFF5E,
  26708. ascript: 0x0251,
  26709. ascriptturned: 0x0252,
  26710. asmallhiragana: 0x3041,
  26711. asmallkatakana: 0x30A1,
  26712. asmallkatakanahalfwidth: 0xFF67,
  26713. asterisk: 0x002A,
  26714. asteriskaltonearabic: 0x066D,
  26715. asteriskarabic: 0x066D,
  26716. asteriskmath: 0x2217,
  26717. asteriskmonospace: 0xFF0A,
  26718. asterisksmall: 0xFE61,
  26719. asterism: 0x2042,
  26720. asuperior: 0xF6E9,
  26721. asymptoticallyequal: 0x2243,
  26722. at: 0x0040,
  26723. atilde: 0x00E3,
  26724. atmonospace: 0xFF20,
  26725. atsmall: 0xFE6B,
  26726. aturned: 0x0250,
  26727. aubengali: 0x0994,
  26728. aubopomofo: 0x3120,
  26729. audeva: 0x0914,
  26730. augujarati: 0x0A94,
  26731. augurmukhi: 0x0A14,
  26732. aulengthmarkbengali: 0x09D7,
  26733. aumatragurmukhi: 0x0A4C,
  26734. auvowelsignbengali: 0x09CC,
  26735. auvowelsigndeva: 0x094C,
  26736. auvowelsigngujarati: 0x0ACC,
  26737. avagrahadeva: 0x093D,
  26738. aybarmenian: 0x0561,
  26739. ayin: 0x05E2,
  26740. ayinaltonehebrew: 0xFB20,
  26741. ayinhebrew: 0x05E2,
  26742. b: 0x0062,
  26743. babengali: 0x09AC,
  26744. backslash: 0x005C,
  26745. backslashmonospace: 0xFF3C,
  26746. badeva: 0x092C,
  26747. bagujarati: 0x0AAC,
  26748. bagurmukhi: 0x0A2C,
  26749. bahiragana: 0x3070,
  26750. bahtthai: 0x0E3F,
  26751. bakatakana: 0x30D0,
  26752. bar: 0x007C,
  26753. barmonospace: 0xFF5C,
  26754. bbopomofo: 0x3105,
  26755. bcircle: 0x24D1,
  26756. bdotaccent: 0x1E03,
  26757. bdotbelow: 0x1E05,
  26758. beamedsixteenthnotes: 0x266C,
  26759. because: 0x2235,
  26760. becyrillic: 0x0431,
  26761. beharabic: 0x0628,
  26762. behfinalarabic: 0xFE90,
  26763. behinitialarabic: 0xFE91,
  26764. behiragana: 0x3079,
  26765. behmedialarabic: 0xFE92,
  26766. behmeeminitialarabic: 0xFC9F,
  26767. behmeemisolatedarabic: 0xFC08,
  26768. behnoonfinalarabic: 0xFC6D,
  26769. bekatakana: 0x30D9,
  26770. benarmenian: 0x0562,
  26771. bet: 0x05D1,
  26772. beta: 0x03B2,
  26773. betasymbolgreek: 0x03D0,
  26774. betdagesh: 0xFB31,
  26775. betdageshhebrew: 0xFB31,
  26776. bethebrew: 0x05D1,
  26777. betrafehebrew: 0xFB4C,
  26778. bhabengali: 0x09AD,
  26779. bhadeva: 0x092D,
  26780. bhagujarati: 0x0AAD,
  26781. bhagurmukhi: 0x0A2D,
  26782. bhook: 0x0253,
  26783. bihiragana: 0x3073,
  26784. bikatakana: 0x30D3,
  26785. bilabialclick: 0x0298,
  26786. bindigurmukhi: 0x0A02,
  26787. birusquare: 0x3331,
  26788. blackcircle: 0x25CF,
  26789. blackdiamond: 0x25C6,
  26790. blackdownpointingtriangle: 0x25BC,
  26791. blackleftpointingpointer: 0x25C4,
  26792. blackleftpointingtriangle: 0x25C0,
  26793. blacklenticularbracketleft: 0x3010,
  26794. blacklenticularbracketleftvertical: 0xFE3B,
  26795. blacklenticularbracketright: 0x3011,
  26796. blacklenticularbracketrightvertical: 0xFE3C,
  26797. blacklowerlefttriangle: 0x25E3,
  26798. blacklowerrighttriangle: 0x25E2,
  26799. blackrectangle: 0x25AC,
  26800. blackrightpointingpointer: 0x25BA,
  26801. blackrightpointingtriangle: 0x25B6,
  26802. blacksmallsquare: 0x25AA,
  26803. blacksmilingface: 0x263B,
  26804. blacksquare: 0x25A0,
  26805. blackstar: 0x2605,
  26806. blackupperlefttriangle: 0x25E4,
  26807. blackupperrighttriangle: 0x25E5,
  26808. blackuppointingsmalltriangle: 0x25B4,
  26809. blackuppointingtriangle: 0x25B2,
  26810. blank: 0x2423,
  26811. blinebelow: 0x1E07,
  26812. block: 0x2588,
  26813. bmonospace: 0xFF42,
  26814. bobaimaithai: 0x0E1A,
  26815. bohiragana: 0x307C,
  26816. bokatakana: 0x30DC,
  26817. bparen: 0x249D,
  26818. bqsquare: 0x33C3,
  26819. braceex: 0xF8F4,
  26820. braceleft: 0x007B,
  26821. braceleftbt: 0xF8F3,
  26822. braceleftmid: 0xF8F2,
  26823. braceleftmonospace: 0xFF5B,
  26824. braceleftsmall: 0xFE5B,
  26825. bracelefttp: 0xF8F1,
  26826. braceleftvertical: 0xFE37,
  26827. braceright: 0x007D,
  26828. bracerightbt: 0xF8FE,
  26829. bracerightmid: 0xF8FD,
  26830. bracerightmonospace: 0xFF5D,
  26831. bracerightsmall: 0xFE5C,
  26832. bracerighttp: 0xF8FC,
  26833. bracerightvertical: 0xFE38,
  26834. bracketleft: 0x005B,
  26835. bracketleftbt: 0xF8F0,
  26836. bracketleftex: 0xF8EF,
  26837. bracketleftmonospace: 0xFF3B,
  26838. bracketlefttp: 0xF8EE,
  26839. bracketright: 0x005D,
  26840. bracketrightbt: 0xF8FB,
  26841. bracketrightex: 0xF8FA,
  26842. bracketrightmonospace: 0xFF3D,
  26843. bracketrighttp: 0xF8F9,
  26844. breve: 0x02D8,
  26845. brevebelowcmb: 0x032E,
  26846. brevecmb: 0x0306,
  26847. breveinvertedbelowcmb: 0x032F,
  26848. breveinvertedcmb: 0x0311,
  26849. breveinverteddoublecmb: 0x0361,
  26850. bridgebelowcmb: 0x032A,
  26851. bridgeinvertedbelowcmb: 0x033A,
  26852. brokenbar: 0x00A6,
  26853. bstroke: 0x0180,
  26854. bsuperior: 0xF6EA,
  26855. btopbar: 0x0183,
  26856. buhiragana: 0x3076,
  26857. bukatakana: 0x30D6,
  26858. bullet: 0x2022,
  26859. bulletinverse: 0x25D8,
  26860. bulletoperator: 0x2219,
  26861. bullseye: 0x25CE,
  26862. c: 0x0063,
  26863. caarmenian: 0x056E,
  26864. cabengali: 0x099A,
  26865. cacute: 0x0107,
  26866. cadeva: 0x091A,
  26867. cagujarati: 0x0A9A,
  26868. cagurmukhi: 0x0A1A,
  26869. calsquare: 0x3388,
  26870. candrabindubengali: 0x0981,
  26871. candrabinducmb: 0x0310,
  26872. candrabindudeva: 0x0901,
  26873. candrabindugujarati: 0x0A81,
  26874. capslock: 0x21EA,
  26875. careof: 0x2105,
  26876. caron: 0x02C7,
  26877. caronbelowcmb: 0x032C,
  26878. caroncmb: 0x030C,
  26879. carriagereturn: 0x21B5,
  26880. cbopomofo: 0x3118,
  26881. ccaron: 0x010D,
  26882. ccedilla: 0x00E7,
  26883. ccedillaacute: 0x1E09,
  26884. ccircle: 0x24D2,
  26885. ccircumflex: 0x0109,
  26886. ccurl: 0x0255,
  26887. cdot: 0x010B,
  26888. cdotaccent: 0x010B,
  26889. cdsquare: 0x33C5,
  26890. cedilla: 0x00B8,
  26891. cedillacmb: 0x0327,
  26892. cent: 0x00A2,
  26893. centigrade: 0x2103,
  26894. centinferior: 0xF6DF,
  26895. centmonospace: 0xFFE0,
  26896. centoldstyle: 0xF7A2,
  26897. centsuperior: 0xF6E0,
  26898. chaarmenian: 0x0579,
  26899. chabengali: 0x099B,
  26900. chadeva: 0x091B,
  26901. chagujarati: 0x0A9B,
  26902. chagurmukhi: 0x0A1B,
  26903. chbopomofo: 0x3114,
  26904. cheabkhasiancyrillic: 0x04BD,
  26905. checkmark: 0x2713,
  26906. checyrillic: 0x0447,
  26907. chedescenderabkhasiancyrillic: 0x04BF,
  26908. chedescendercyrillic: 0x04B7,
  26909. chedieresiscyrillic: 0x04F5,
  26910. cheharmenian: 0x0573,
  26911. chekhakassiancyrillic: 0x04CC,
  26912. cheverticalstrokecyrillic: 0x04B9,
  26913. chi: 0x03C7,
  26914. chieuchacirclekorean: 0x3277,
  26915. chieuchaparenkorean: 0x3217,
  26916. chieuchcirclekorean: 0x3269,
  26917. chieuchkorean: 0x314A,
  26918. chieuchparenkorean: 0x3209,
  26919. chochangthai: 0x0E0A,
  26920. chochanthai: 0x0E08,
  26921. chochingthai: 0x0E09,
  26922. chochoethai: 0x0E0C,
  26923. chook: 0x0188,
  26924. cieucacirclekorean: 0x3276,
  26925. cieucaparenkorean: 0x3216,
  26926. cieuccirclekorean: 0x3268,
  26927. cieuckorean: 0x3148,
  26928. cieucparenkorean: 0x3208,
  26929. cieucuparenkorean: 0x321C,
  26930. circle: 0x25CB,
  26931. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  26932. circlemultiply: 0x2297,
  26933. circleot: 0x2299,
  26934. circleplus: 0x2295,
  26935. circlepostalmark: 0x3036,
  26936. circlewithlefthalfblack: 0x25D0,
  26937. circlewithrighthalfblack: 0x25D1,
  26938. circumflex: 0x02C6,
  26939. circumflexbelowcmb: 0x032D,
  26940. circumflexcmb: 0x0302,
  26941. clear: 0x2327,
  26942. clickalveolar: 0x01C2,
  26943. clickdental: 0x01C0,
  26944. clicklateral: 0x01C1,
  26945. clickretroflex: 0x01C3,
  26946. club: 0x2663,
  26947. clubsuitblack: 0x2663,
  26948. clubsuitwhite: 0x2667,
  26949. cmcubedsquare: 0x33A4,
  26950. cmonospace: 0xFF43,
  26951. cmsquaredsquare: 0x33A0,
  26952. coarmenian: 0x0581,
  26953. colon: 0x003A,
  26954. colonmonetary: 0x20A1,
  26955. colonmonospace: 0xFF1A,
  26956. colonsign: 0x20A1,
  26957. colonsmall: 0xFE55,
  26958. colontriangularhalfmod: 0x02D1,
  26959. colontriangularmod: 0x02D0,
  26960. comma: 0x002C,
  26961. commaabovecmb: 0x0313,
  26962. commaaboverightcmb: 0x0315,
  26963. commaaccent: 0xF6C3,
  26964. commaarabic: 0x060C,
  26965. commaarmenian: 0x055D,
  26966. commainferior: 0xF6E1,
  26967. commamonospace: 0xFF0C,
  26968. commareversedabovecmb: 0x0314,
  26969. commareversedmod: 0x02BD,
  26970. commasmall: 0xFE50,
  26971. commasuperior: 0xF6E2,
  26972. commaturnedabovecmb: 0x0312,
  26973. commaturnedmod: 0x02BB,
  26974. compass: 0x263C,
  26975. congruent: 0x2245,
  26976. contourintegral: 0x222E,
  26977. control: 0x2303,
  26978. controlACK: 0x0006,
  26979. controlBEL: 0x0007,
  26980. controlBS: 0x0008,
  26981. controlCAN: 0x0018,
  26982. controlCR: 0x000D,
  26983. controlDC1: 0x0011,
  26984. controlDC2: 0x0012,
  26985. controlDC3: 0x0013,
  26986. controlDC4: 0x0014,
  26987. controlDEL: 0x007F,
  26988. controlDLE: 0x0010,
  26989. controlEM: 0x0019,
  26990. controlENQ: 0x0005,
  26991. controlEOT: 0x0004,
  26992. controlESC: 0x001B,
  26993. controlETB: 0x0017,
  26994. controlETX: 0x0003,
  26995. controlFF: 0x000C,
  26996. controlFS: 0x001C,
  26997. controlGS: 0x001D,
  26998. controlHT: 0x0009,
  26999. controlLF: 0x000A,
  27000. controlNAK: 0x0015,
  27001. controlRS: 0x001E,
  27002. controlSI: 0x000F,
  27003. controlSO: 0x000E,
  27004. controlSOT: 0x0002,
  27005. controlSTX: 0x0001,
  27006. controlSUB: 0x001A,
  27007. controlSYN: 0x0016,
  27008. controlUS: 0x001F,
  27009. controlVT: 0x000B,
  27010. copyright: 0x00A9,
  27011. copyrightsans: 0xF8E9,
  27012. copyrightserif: 0xF6D9,
  27013. cornerbracketleft: 0x300C,
  27014. cornerbracketlefthalfwidth: 0xFF62,
  27015. cornerbracketleftvertical: 0xFE41,
  27016. cornerbracketright: 0x300D,
  27017. cornerbracketrighthalfwidth: 0xFF63,
  27018. cornerbracketrightvertical: 0xFE42,
  27019. corporationsquare: 0x337F,
  27020. cosquare: 0x33C7,
  27021. coverkgsquare: 0x33C6,
  27022. cparen: 0x249E,
  27023. cruzeiro: 0x20A2,
  27024. cstretched: 0x0297,
  27025. curlyand: 0x22CF,
  27026. curlyor: 0x22CE,
  27027. currency: 0x00A4,
  27028. cyrBreve: 0xF6D1,
  27029. cyrFlex: 0xF6D2,
  27030. cyrbreve: 0xF6D4,
  27031. cyrflex: 0xF6D5,
  27032. d: 0x0064,
  27033. daarmenian: 0x0564,
  27034. dabengali: 0x09A6,
  27035. dadarabic: 0x0636,
  27036. dadeva: 0x0926,
  27037. dadfinalarabic: 0xFEBE,
  27038. dadinitialarabic: 0xFEBF,
  27039. dadmedialarabic: 0xFEC0,
  27040. dagesh: 0x05BC,
  27041. dageshhebrew: 0x05BC,
  27042. dagger: 0x2020,
  27043. daggerdbl: 0x2021,
  27044. dagujarati: 0x0AA6,
  27045. dagurmukhi: 0x0A26,
  27046. dahiragana: 0x3060,
  27047. dakatakana: 0x30C0,
  27048. dalarabic: 0x062F,
  27049. dalet: 0x05D3,
  27050. daletdagesh: 0xFB33,
  27051. daletdageshhebrew: 0xFB33,
  27052. dalethebrew: 0x05D3,
  27053. dalfinalarabic: 0xFEAA,
  27054. dammaarabic: 0x064F,
  27055. dammalowarabic: 0x064F,
  27056. dammatanaltonearabic: 0x064C,
  27057. dammatanarabic: 0x064C,
  27058. danda: 0x0964,
  27059. dargahebrew: 0x05A7,
  27060. dargalefthebrew: 0x05A7,
  27061. dasiapneumatacyrilliccmb: 0x0485,
  27062. dblGrave: 0xF6D3,
  27063. dblanglebracketleft: 0x300A,
  27064. dblanglebracketleftvertical: 0xFE3D,
  27065. dblanglebracketright: 0x300B,
  27066. dblanglebracketrightvertical: 0xFE3E,
  27067. dblarchinvertedbelowcmb: 0x032B,
  27068. dblarrowleft: 0x21D4,
  27069. dblarrowright: 0x21D2,
  27070. dbldanda: 0x0965,
  27071. dblgrave: 0xF6D6,
  27072. dblgravecmb: 0x030F,
  27073. dblintegral: 0x222C,
  27074. dbllowline: 0x2017,
  27075. dbllowlinecmb: 0x0333,
  27076. dbloverlinecmb: 0x033F,
  27077. dblprimemod: 0x02BA,
  27078. dblverticalbar: 0x2016,
  27079. dblverticallineabovecmb: 0x030E,
  27080. dbopomofo: 0x3109,
  27081. dbsquare: 0x33C8,
  27082. dcaron: 0x010F,
  27083. dcedilla: 0x1E11,
  27084. dcircle: 0x24D3,
  27085. dcircumflexbelow: 0x1E13,
  27086. dcroat: 0x0111,
  27087. ddabengali: 0x09A1,
  27088. ddadeva: 0x0921,
  27089. ddagujarati: 0x0AA1,
  27090. ddagurmukhi: 0x0A21,
  27091. ddalarabic: 0x0688,
  27092. ddalfinalarabic: 0xFB89,
  27093. dddhadeva: 0x095C,
  27094. ddhabengali: 0x09A2,
  27095. ddhadeva: 0x0922,
  27096. ddhagujarati: 0x0AA2,
  27097. ddhagurmukhi: 0x0A22,
  27098. ddotaccent: 0x1E0B,
  27099. ddotbelow: 0x1E0D,
  27100. decimalseparatorarabic: 0x066B,
  27101. decimalseparatorpersian: 0x066B,
  27102. decyrillic: 0x0434,
  27103. degree: 0x00B0,
  27104. dehihebrew: 0x05AD,
  27105. dehiragana: 0x3067,
  27106. deicoptic: 0x03EF,
  27107. dekatakana: 0x30C7,
  27108. deleteleft: 0x232B,
  27109. deleteright: 0x2326,
  27110. delta: 0x03B4,
  27111. deltaturned: 0x018D,
  27112. denominatorminusonenumeratorbengali: 0x09F8,
  27113. dezh: 0x02A4,
  27114. dhabengali: 0x09A7,
  27115. dhadeva: 0x0927,
  27116. dhagujarati: 0x0AA7,
  27117. dhagurmukhi: 0x0A27,
  27118. dhook: 0x0257,
  27119. dialytikatonos: 0x0385,
  27120. dialytikatonoscmb: 0x0344,
  27121. diamond: 0x2666,
  27122. diamondsuitwhite: 0x2662,
  27123. dieresis: 0x00A8,
  27124. dieresisacute: 0xF6D7,
  27125. dieresisbelowcmb: 0x0324,
  27126. dieresiscmb: 0x0308,
  27127. dieresisgrave: 0xF6D8,
  27128. dieresistonos: 0x0385,
  27129. dihiragana: 0x3062,
  27130. dikatakana: 0x30C2,
  27131. dittomark: 0x3003,
  27132. divide: 0x00F7,
  27133. divides: 0x2223,
  27134. divisionslash: 0x2215,
  27135. djecyrillic: 0x0452,
  27136. dkshade: 0x2593,
  27137. dlinebelow: 0x1E0F,
  27138. dlsquare: 0x3397,
  27139. dmacron: 0x0111,
  27140. dmonospace: 0xFF44,
  27141. dnblock: 0x2584,
  27142. dochadathai: 0x0E0E,
  27143. dodekthai: 0x0E14,
  27144. dohiragana: 0x3069,
  27145. dokatakana: 0x30C9,
  27146. dollar: 0x0024,
  27147. dollarinferior: 0xF6E3,
  27148. dollarmonospace: 0xFF04,
  27149. dollaroldstyle: 0xF724,
  27150. dollarsmall: 0xFE69,
  27151. dollarsuperior: 0xF6E4,
  27152. dong: 0x20AB,
  27153. dorusquare: 0x3326,
  27154. dotaccent: 0x02D9,
  27155. dotaccentcmb: 0x0307,
  27156. dotbelowcmb: 0x0323,
  27157. dotbelowcomb: 0x0323,
  27158. dotkatakana: 0x30FB,
  27159. dotlessi: 0x0131,
  27160. dotlessj: 0xF6BE,
  27161. dotlessjstrokehook: 0x0284,
  27162. dotmath: 0x22C5,
  27163. dottedcircle: 0x25CC,
  27164. doubleyodpatah: 0xFB1F,
  27165. doubleyodpatahhebrew: 0xFB1F,
  27166. downtackbelowcmb: 0x031E,
  27167. downtackmod: 0x02D5,
  27168. dparen: 0x249F,
  27169. dsuperior: 0xF6EB,
  27170. dtail: 0x0256,
  27171. dtopbar: 0x018C,
  27172. duhiragana: 0x3065,
  27173. dukatakana: 0x30C5,
  27174. dz: 0x01F3,
  27175. dzaltone: 0x02A3,
  27176. dzcaron: 0x01C6,
  27177. dzcurl: 0x02A5,
  27178. dzeabkhasiancyrillic: 0x04E1,
  27179. dzecyrillic: 0x0455,
  27180. dzhecyrillic: 0x045F,
  27181. e: 0x0065,
  27182. eacute: 0x00E9,
  27183. earth: 0x2641,
  27184. ebengali: 0x098F,
  27185. ebopomofo: 0x311C,
  27186. ebreve: 0x0115,
  27187. ecandradeva: 0x090D,
  27188. ecandragujarati: 0x0A8D,
  27189. ecandravowelsigndeva: 0x0945,
  27190. ecandravowelsigngujarati: 0x0AC5,
  27191. ecaron: 0x011B,
  27192. ecedillabreve: 0x1E1D,
  27193. echarmenian: 0x0565,
  27194. echyiwnarmenian: 0x0587,
  27195. ecircle: 0x24D4,
  27196. ecircumflex: 0x00EA,
  27197. ecircumflexacute: 0x1EBF,
  27198. ecircumflexbelow: 0x1E19,
  27199. ecircumflexdotbelow: 0x1EC7,
  27200. ecircumflexgrave: 0x1EC1,
  27201. ecircumflexhookabove: 0x1EC3,
  27202. ecircumflextilde: 0x1EC5,
  27203. ecyrillic: 0x0454,
  27204. edblgrave: 0x0205,
  27205. edeva: 0x090F,
  27206. edieresis: 0x00EB,
  27207. edot: 0x0117,
  27208. edotaccent: 0x0117,
  27209. edotbelow: 0x1EB9,
  27210. eegurmukhi: 0x0A0F,
  27211. eematragurmukhi: 0x0A47,
  27212. efcyrillic: 0x0444,
  27213. egrave: 0x00E8,
  27214. egujarati: 0x0A8F,
  27215. eharmenian: 0x0567,
  27216. ehbopomofo: 0x311D,
  27217. ehiragana: 0x3048,
  27218. ehookabove: 0x1EBB,
  27219. eibopomofo: 0x311F,
  27220. eight: 0x0038,
  27221. eightarabic: 0x0668,
  27222. eightbengali: 0x09EE,
  27223. eightcircle: 0x2467,
  27224. eightcircleinversesansserif: 0x2791,
  27225. eightdeva: 0x096E,
  27226. eighteencircle: 0x2471,
  27227. eighteenparen: 0x2485,
  27228. eighteenperiod: 0x2499,
  27229. eightgujarati: 0x0AEE,
  27230. eightgurmukhi: 0x0A6E,
  27231. eighthackarabic: 0x0668,
  27232. eighthangzhou: 0x3028,
  27233. eighthnotebeamed: 0x266B,
  27234. eightideographicparen: 0x3227,
  27235. eightinferior: 0x2088,
  27236. eightmonospace: 0xFF18,
  27237. eightoldstyle: 0xF738,
  27238. eightparen: 0x247B,
  27239. eightperiod: 0x248F,
  27240. eightpersian: 0x06F8,
  27241. eightroman: 0x2177,
  27242. eightsuperior: 0x2078,
  27243. eightthai: 0x0E58,
  27244. einvertedbreve: 0x0207,
  27245. eiotifiedcyrillic: 0x0465,
  27246. ekatakana: 0x30A8,
  27247. ekatakanahalfwidth: 0xFF74,
  27248. ekonkargurmukhi: 0x0A74,
  27249. ekorean: 0x3154,
  27250. elcyrillic: 0x043B,
  27251. element: 0x2208,
  27252. elevencircle: 0x246A,
  27253. elevenparen: 0x247E,
  27254. elevenperiod: 0x2492,
  27255. elevenroman: 0x217A,
  27256. ellipsis: 0x2026,
  27257. ellipsisvertical: 0x22EE,
  27258. emacron: 0x0113,
  27259. emacronacute: 0x1E17,
  27260. emacrongrave: 0x1E15,
  27261. emcyrillic: 0x043C,
  27262. emdash: 0x2014,
  27263. emdashvertical: 0xFE31,
  27264. emonospace: 0xFF45,
  27265. emphasismarkarmenian: 0x055B,
  27266. emptyset: 0x2205,
  27267. enbopomofo: 0x3123,
  27268. encyrillic: 0x043D,
  27269. endash: 0x2013,
  27270. endashvertical: 0xFE32,
  27271. endescendercyrillic: 0x04A3,
  27272. eng: 0x014B,
  27273. engbopomofo: 0x3125,
  27274. enghecyrillic: 0x04A5,
  27275. enhookcyrillic: 0x04C8,
  27276. enspace: 0x2002,
  27277. eogonek: 0x0119,
  27278. eokorean: 0x3153,
  27279. eopen: 0x025B,
  27280. eopenclosed: 0x029A,
  27281. eopenreversed: 0x025C,
  27282. eopenreversedclosed: 0x025E,
  27283. eopenreversedhook: 0x025D,
  27284. eparen: 0x24A0,
  27285. epsilon: 0x03B5,
  27286. epsilontonos: 0x03AD,
  27287. equal: 0x003D,
  27288. equalmonospace: 0xFF1D,
  27289. equalsmall: 0xFE66,
  27290. equalsuperior: 0x207C,
  27291. equivalence: 0x2261,
  27292. erbopomofo: 0x3126,
  27293. ercyrillic: 0x0440,
  27294. ereversed: 0x0258,
  27295. ereversedcyrillic: 0x044D,
  27296. escyrillic: 0x0441,
  27297. esdescendercyrillic: 0x04AB,
  27298. esh: 0x0283,
  27299. eshcurl: 0x0286,
  27300. eshortdeva: 0x090E,
  27301. eshortvowelsigndeva: 0x0946,
  27302. eshreversedloop: 0x01AA,
  27303. eshsquatreversed: 0x0285,
  27304. esmallhiragana: 0x3047,
  27305. esmallkatakana: 0x30A7,
  27306. esmallkatakanahalfwidth: 0xFF6A,
  27307. estimated: 0x212E,
  27308. esuperior: 0xF6EC,
  27309. eta: 0x03B7,
  27310. etarmenian: 0x0568,
  27311. etatonos: 0x03AE,
  27312. eth: 0x00F0,
  27313. etilde: 0x1EBD,
  27314. etildebelow: 0x1E1B,
  27315. etnahtafoukhhebrew: 0x0591,
  27316. etnahtafoukhlefthebrew: 0x0591,
  27317. etnahtahebrew: 0x0591,
  27318. etnahtalefthebrew: 0x0591,
  27319. eturned: 0x01DD,
  27320. eukorean: 0x3161,
  27321. euro: 0x20AC,
  27322. evowelsignbengali: 0x09C7,
  27323. evowelsigndeva: 0x0947,
  27324. evowelsigngujarati: 0x0AC7,
  27325. exclam: 0x0021,
  27326. exclamarmenian: 0x055C,
  27327. exclamdbl: 0x203C,
  27328. exclamdown: 0x00A1,
  27329. exclamdownsmall: 0xF7A1,
  27330. exclammonospace: 0xFF01,
  27331. exclamsmall: 0xF721,
  27332. existential: 0x2203,
  27333. ezh: 0x0292,
  27334. ezhcaron: 0x01EF,
  27335. ezhcurl: 0x0293,
  27336. ezhreversed: 0x01B9,
  27337. ezhtail: 0x01BA,
  27338. f: 0x0066,
  27339. fadeva: 0x095E,
  27340. fagurmukhi: 0x0A5E,
  27341. fahrenheit: 0x2109,
  27342. fathaarabic: 0x064E,
  27343. fathalowarabic: 0x064E,
  27344. fathatanarabic: 0x064B,
  27345. fbopomofo: 0x3108,
  27346. fcircle: 0x24D5,
  27347. fdotaccent: 0x1E1F,
  27348. feharabic: 0x0641,
  27349. feharmenian: 0x0586,
  27350. fehfinalarabic: 0xFED2,
  27351. fehinitialarabic: 0xFED3,
  27352. fehmedialarabic: 0xFED4,
  27353. feicoptic: 0x03E5,
  27354. female: 0x2640,
  27355. ff: 0xFB00,
  27356. ffi: 0xFB03,
  27357. ffl: 0xFB04,
  27358. fi: 0xFB01,
  27359. fifteencircle: 0x246E,
  27360. fifteenparen: 0x2482,
  27361. fifteenperiod: 0x2496,
  27362. figuredash: 0x2012,
  27363. filledbox: 0x25A0,
  27364. filledrect: 0x25AC,
  27365. finalkaf: 0x05DA,
  27366. finalkafdagesh: 0xFB3A,
  27367. finalkafdageshhebrew: 0xFB3A,
  27368. finalkafhebrew: 0x05DA,
  27369. finalmem: 0x05DD,
  27370. finalmemhebrew: 0x05DD,
  27371. finalnun: 0x05DF,
  27372. finalnunhebrew: 0x05DF,
  27373. finalpe: 0x05E3,
  27374. finalpehebrew: 0x05E3,
  27375. finaltsadi: 0x05E5,
  27376. finaltsadihebrew: 0x05E5,
  27377. firsttonechinese: 0x02C9,
  27378. fisheye: 0x25C9,
  27379. fitacyrillic: 0x0473,
  27380. five: 0x0035,
  27381. fivearabic: 0x0665,
  27382. fivebengali: 0x09EB,
  27383. fivecircle: 0x2464,
  27384. fivecircleinversesansserif: 0x278E,
  27385. fivedeva: 0x096B,
  27386. fiveeighths: 0x215D,
  27387. fivegujarati: 0x0AEB,
  27388. fivegurmukhi: 0x0A6B,
  27389. fivehackarabic: 0x0665,
  27390. fivehangzhou: 0x3025,
  27391. fiveideographicparen: 0x3224,
  27392. fiveinferior: 0x2085,
  27393. fivemonospace: 0xFF15,
  27394. fiveoldstyle: 0xF735,
  27395. fiveparen: 0x2478,
  27396. fiveperiod: 0x248C,
  27397. fivepersian: 0x06F5,
  27398. fiveroman: 0x2174,
  27399. fivesuperior: 0x2075,
  27400. fivethai: 0x0E55,
  27401. fl: 0xFB02,
  27402. florin: 0x0192,
  27403. fmonospace: 0xFF46,
  27404. fmsquare: 0x3399,
  27405. fofanthai: 0x0E1F,
  27406. fofathai: 0x0E1D,
  27407. fongmanthai: 0x0E4F,
  27408. forall: 0x2200,
  27409. four: 0x0034,
  27410. fourarabic: 0x0664,
  27411. fourbengali: 0x09EA,
  27412. fourcircle: 0x2463,
  27413. fourcircleinversesansserif: 0x278D,
  27414. fourdeva: 0x096A,
  27415. fourgujarati: 0x0AEA,
  27416. fourgurmukhi: 0x0A6A,
  27417. fourhackarabic: 0x0664,
  27418. fourhangzhou: 0x3024,
  27419. fourideographicparen: 0x3223,
  27420. fourinferior: 0x2084,
  27421. fourmonospace: 0xFF14,
  27422. fournumeratorbengali: 0x09F7,
  27423. fouroldstyle: 0xF734,
  27424. fourparen: 0x2477,
  27425. fourperiod: 0x248B,
  27426. fourpersian: 0x06F4,
  27427. fourroman: 0x2173,
  27428. foursuperior: 0x2074,
  27429. fourteencircle: 0x246D,
  27430. fourteenparen: 0x2481,
  27431. fourteenperiod: 0x2495,
  27432. fourthai: 0x0E54,
  27433. fourthtonechinese: 0x02CB,
  27434. fparen: 0x24A1,
  27435. fraction: 0x2044,
  27436. franc: 0x20A3,
  27437. g: 0x0067,
  27438. gabengali: 0x0997,
  27439. gacute: 0x01F5,
  27440. gadeva: 0x0917,
  27441. gafarabic: 0x06AF,
  27442. gaffinalarabic: 0xFB93,
  27443. gafinitialarabic: 0xFB94,
  27444. gafmedialarabic: 0xFB95,
  27445. gagujarati: 0x0A97,
  27446. gagurmukhi: 0x0A17,
  27447. gahiragana: 0x304C,
  27448. gakatakana: 0x30AC,
  27449. gamma: 0x03B3,
  27450. gammalatinsmall: 0x0263,
  27451. gammasuperior: 0x02E0,
  27452. gangiacoptic: 0x03EB,
  27453. gbopomofo: 0x310D,
  27454. gbreve: 0x011F,
  27455. gcaron: 0x01E7,
  27456. gcedilla: 0x0123,
  27457. gcircle: 0x24D6,
  27458. gcircumflex: 0x011D,
  27459. gcommaaccent: 0x0123,
  27460. gdot: 0x0121,
  27461. gdotaccent: 0x0121,
  27462. gecyrillic: 0x0433,
  27463. gehiragana: 0x3052,
  27464. gekatakana: 0x30B2,
  27465. geometricallyequal: 0x2251,
  27466. gereshaccenthebrew: 0x059C,
  27467. gereshhebrew: 0x05F3,
  27468. gereshmuqdamhebrew: 0x059D,
  27469. germandbls: 0x00DF,
  27470. gershayimaccenthebrew: 0x059E,
  27471. gershayimhebrew: 0x05F4,
  27472. getamark: 0x3013,
  27473. ghabengali: 0x0998,
  27474. ghadarmenian: 0x0572,
  27475. ghadeva: 0x0918,
  27476. ghagujarati: 0x0A98,
  27477. ghagurmukhi: 0x0A18,
  27478. ghainarabic: 0x063A,
  27479. ghainfinalarabic: 0xFECE,
  27480. ghaininitialarabic: 0xFECF,
  27481. ghainmedialarabic: 0xFED0,
  27482. ghemiddlehookcyrillic: 0x0495,
  27483. ghestrokecyrillic: 0x0493,
  27484. gheupturncyrillic: 0x0491,
  27485. ghhadeva: 0x095A,
  27486. ghhagurmukhi: 0x0A5A,
  27487. ghook: 0x0260,
  27488. ghzsquare: 0x3393,
  27489. gihiragana: 0x304E,
  27490. gikatakana: 0x30AE,
  27491. gimarmenian: 0x0563,
  27492. gimel: 0x05D2,
  27493. gimeldagesh: 0xFB32,
  27494. gimeldageshhebrew: 0xFB32,
  27495. gimelhebrew: 0x05D2,
  27496. gjecyrillic: 0x0453,
  27497. glottalinvertedstroke: 0x01BE,
  27498. glottalstop: 0x0294,
  27499. glottalstopinverted: 0x0296,
  27500. glottalstopmod: 0x02C0,
  27501. glottalstopreversed: 0x0295,
  27502. glottalstopreversedmod: 0x02C1,
  27503. glottalstopreversedsuperior: 0x02E4,
  27504. glottalstopstroke: 0x02A1,
  27505. glottalstopstrokereversed: 0x02A2,
  27506. gmacron: 0x1E21,
  27507. gmonospace: 0xFF47,
  27508. gohiragana: 0x3054,
  27509. gokatakana: 0x30B4,
  27510. gparen: 0x24A2,
  27511. gpasquare: 0x33AC,
  27512. gradient: 0x2207,
  27513. grave: 0x0060,
  27514. gravebelowcmb: 0x0316,
  27515. gravecmb: 0x0300,
  27516. gravecomb: 0x0300,
  27517. gravedeva: 0x0953,
  27518. gravelowmod: 0x02CE,
  27519. gravemonospace: 0xFF40,
  27520. gravetonecmb: 0x0340,
  27521. greater: 0x003E,
  27522. greaterequal: 0x2265,
  27523. greaterequalorless: 0x22DB,
  27524. greatermonospace: 0xFF1E,
  27525. greaterorequivalent: 0x2273,
  27526. greaterorless: 0x2277,
  27527. greateroverequal: 0x2267,
  27528. greatersmall: 0xFE65,
  27529. gscript: 0x0261,
  27530. gstroke: 0x01E5,
  27531. guhiragana: 0x3050,
  27532. guillemotleft: 0x00AB,
  27533. guillemotright: 0x00BB,
  27534. guilsinglleft: 0x2039,
  27535. guilsinglright: 0x203A,
  27536. gukatakana: 0x30B0,
  27537. guramusquare: 0x3318,
  27538. gysquare: 0x33C9,
  27539. h: 0x0068,
  27540. haabkhasiancyrillic: 0x04A9,
  27541. haaltonearabic: 0x06C1,
  27542. habengali: 0x09B9,
  27543. hadescendercyrillic: 0x04B3,
  27544. hadeva: 0x0939,
  27545. hagujarati: 0x0AB9,
  27546. hagurmukhi: 0x0A39,
  27547. haharabic: 0x062D,
  27548. hahfinalarabic: 0xFEA2,
  27549. hahinitialarabic: 0xFEA3,
  27550. hahiragana: 0x306F,
  27551. hahmedialarabic: 0xFEA4,
  27552. haitusquare: 0x332A,
  27553. hakatakana: 0x30CF,
  27554. hakatakanahalfwidth: 0xFF8A,
  27555. halantgurmukhi: 0x0A4D,
  27556. hamzaarabic: 0x0621,
  27557. hamzalowarabic: 0x0621,
  27558. hangulfiller: 0x3164,
  27559. hardsigncyrillic: 0x044A,
  27560. harpoonleftbarbup: 0x21BC,
  27561. harpoonrightbarbup: 0x21C0,
  27562. hasquare: 0x33CA,
  27563. hatafpatah: 0x05B2,
  27564. hatafpatah16: 0x05B2,
  27565. hatafpatah23: 0x05B2,
  27566. hatafpatah2f: 0x05B2,
  27567. hatafpatahhebrew: 0x05B2,
  27568. hatafpatahnarrowhebrew: 0x05B2,
  27569. hatafpatahquarterhebrew: 0x05B2,
  27570. hatafpatahwidehebrew: 0x05B2,
  27571. hatafqamats: 0x05B3,
  27572. hatafqamats1b: 0x05B3,
  27573. hatafqamats28: 0x05B3,
  27574. hatafqamats34: 0x05B3,
  27575. hatafqamatshebrew: 0x05B3,
  27576. hatafqamatsnarrowhebrew: 0x05B3,
  27577. hatafqamatsquarterhebrew: 0x05B3,
  27578. hatafqamatswidehebrew: 0x05B3,
  27579. hatafsegol: 0x05B1,
  27580. hatafsegol17: 0x05B1,
  27581. hatafsegol24: 0x05B1,
  27582. hatafsegol30: 0x05B1,
  27583. hatafsegolhebrew: 0x05B1,
  27584. hatafsegolnarrowhebrew: 0x05B1,
  27585. hatafsegolquarterhebrew: 0x05B1,
  27586. hatafsegolwidehebrew: 0x05B1,
  27587. hbar: 0x0127,
  27588. hbopomofo: 0x310F,
  27589. hbrevebelow: 0x1E2B,
  27590. hcedilla: 0x1E29,
  27591. hcircle: 0x24D7,
  27592. hcircumflex: 0x0125,
  27593. hdieresis: 0x1E27,
  27594. hdotaccent: 0x1E23,
  27595. hdotbelow: 0x1E25,
  27596. he: 0x05D4,
  27597. heart: 0x2665,
  27598. heartsuitblack: 0x2665,
  27599. heartsuitwhite: 0x2661,
  27600. hedagesh: 0xFB34,
  27601. hedageshhebrew: 0xFB34,
  27602. hehaltonearabic: 0x06C1,
  27603. heharabic: 0x0647,
  27604. hehebrew: 0x05D4,
  27605. hehfinalaltonearabic: 0xFBA7,
  27606. hehfinalalttwoarabic: 0xFEEA,
  27607. hehfinalarabic: 0xFEEA,
  27608. hehhamzaabovefinalarabic: 0xFBA5,
  27609. hehhamzaaboveisolatedarabic: 0xFBA4,
  27610. hehinitialaltonearabic: 0xFBA8,
  27611. hehinitialarabic: 0xFEEB,
  27612. hehiragana: 0x3078,
  27613. hehmedialaltonearabic: 0xFBA9,
  27614. hehmedialarabic: 0xFEEC,
  27615. heiseierasquare: 0x337B,
  27616. hekatakana: 0x30D8,
  27617. hekatakanahalfwidth: 0xFF8D,
  27618. hekutaarusquare: 0x3336,
  27619. henghook: 0x0267,
  27620. herutusquare: 0x3339,
  27621. het: 0x05D7,
  27622. hethebrew: 0x05D7,
  27623. hhook: 0x0266,
  27624. hhooksuperior: 0x02B1,
  27625. hieuhacirclekorean: 0x327B,
  27626. hieuhaparenkorean: 0x321B,
  27627. hieuhcirclekorean: 0x326D,
  27628. hieuhkorean: 0x314E,
  27629. hieuhparenkorean: 0x320D,
  27630. hihiragana: 0x3072,
  27631. hikatakana: 0x30D2,
  27632. hikatakanahalfwidth: 0xFF8B,
  27633. hiriq: 0x05B4,
  27634. hiriq14: 0x05B4,
  27635. hiriq21: 0x05B4,
  27636. hiriq2d: 0x05B4,
  27637. hiriqhebrew: 0x05B4,
  27638. hiriqnarrowhebrew: 0x05B4,
  27639. hiriqquarterhebrew: 0x05B4,
  27640. hiriqwidehebrew: 0x05B4,
  27641. hlinebelow: 0x1E96,
  27642. hmonospace: 0xFF48,
  27643. hoarmenian: 0x0570,
  27644. hohipthai: 0x0E2B,
  27645. hohiragana: 0x307B,
  27646. hokatakana: 0x30DB,
  27647. hokatakanahalfwidth: 0xFF8E,
  27648. holam: 0x05B9,
  27649. holam19: 0x05B9,
  27650. holam26: 0x05B9,
  27651. holam32: 0x05B9,
  27652. holamhebrew: 0x05B9,
  27653. holamnarrowhebrew: 0x05B9,
  27654. holamquarterhebrew: 0x05B9,
  27655. holamwidehebrew: 0x05B9,
  27656. honokhukthai: 0x0E2E,
  27657. hookabovecomb: 0x0309,
  27658. hookcmb: 0x0309,
  27659. hookpalatalizedbelowcmb: 0x0321,
  27660. hookretroflexbelowcmb: 0x0322,
  27661. hoonsquare: 0x3342,
  27662. horicoptic: 0x03E9,
  27663. horizontalbar: 0x2015,
  27664. horncmb: 0x031B,
  27665. hotsprings: 0x2668,
  27666. house: 0x2302,
  27667. hparen: 0x24A3,
  27668. hsuperior: 0x02B0,
  27669. hturned: 0x0265,
  27670. huhiragana: 0x3075,
  27671. huiitosquare: 0x3333,
  27672. hukatakana: 0x30D5,
  27673. hukatakanahalfwidth: 0xFF8C,
  27674. hungarumlaut: 0x02DD,
  27675. hungarumlautcmb: 0x030B,
  27676. hv: 0x0195,
  27677. hyphen: 0x002D,
  27678. hypheninferior: 0xF6E5,
  27679. hyphenmonospace: 0xFF0D,
  27680. hyphensmall: 0xFE63,
  27681. hyphensuperior: 0xF6E6,
  27682. hyphentwo: 0x2010,
  27683. i: 0x0069,
  27684. iacute: 0x00ED,
  27685. iacyrillic: 0x044F,
  27686. ibengali: 0x0987,
  27687. ibopomofo: 0x3127,
  27688. ibreve: 0x012D,
  27689. icaron: 0x01D0,
  27690. icircle: 0x24D8,
  27691. icircumflex: 0x00EE,
  27692. icyrillic: 0x0456,
  27693. idblgrave: 0x0209,
  27694. ideographearthcircle: 0x328F,
  27695. ideographfirecircle: 0x328B,
  27696. ideographicallianceparen: 0x323F,
  27697. ideographiccallparen: 0x323A,
  27698. ideographiccentrecircle: 0x32A5,
  27699. ideographicclose: 0x3006,
  27700. ideographiccomma: 0x3001,
  27701. ideographiccommaleft: 0xFF64,
  27702. ideographiccongratulationparen: 0x3237,
  27703. ideographiccorrectcircle: 0x32A3,
  27704. ideographicearthparen: 0x322F,
  27705. ideographicenterpriseparen: 0x323D,
  27706. ideographicexcellentcircle: 0x329D,
  27707. ideographicfestivalparen: 0x3240,
  27708. ideographicfinancialcircle: 0x3296,
  27709. ideographicfinancialparen: 0x3236,
  27710. ideographicfireparen: 0x322B,
  27711. ideographichaveparen: 0x3232,
  27712. ideographichighcircle: 0x32A4,
  27713. ideographiciterationmark: 0x3005,
  27714. ideographiclaborcircle: 0x3298,
  27715. ideographiclaborparen: 0x3238,
  27716. ideographicleftcircle: 0x32A7,
  27717. ideographiclowcircle: 0x32A6,
  27718. ideographicmedicinecircle: 0x32A9,
  27719. ideographicmetalparen: 0x322E,
  27720. ideographicmoonparen: 0x322A,
  27721. ideographicnameparen: 0x3234,
  27722. ideographicperiod: 0x3002,
  27723. ideographicprintcircle: 0x329E,
  27724. ideographicreachparen: 0x3243,
  27725. ideographicrepresentparen: 0x3239,
  27726. ideographicresourceparen: 0x323E,
  27727. ideographicrightcircle: 0x32A8,
  27728. ideographicsecretcircle: 0x3299,
  27729. ideographicselfparen: 0x3242,
  27730. ideographicsocietyparen: 0x3233,
  27731. ideographicspace: 0x3000,
  27732. ideographicspecialparen: 0x3235,
  27733. ideographicstockparen: 0x3231,
  27734. ideographicstudyparen: 0x323B,
  27735. ideographicsunparen: 0x3230,
  27736. ideographicsuperviseparen: 0x323C,
  27737. ideographicwaterparen: 0x322C,
  27738. ideographicwoodparen: 0x322D,
  27739. ideographiczero: 0x3007,
  27740. ideographmetalcircle: 0x328E,
  27741. ideographmooncircle: 0x328A,
  27742. ideographnamecircle: 0x3294,
  27743. ideographsuncircle: 0x3290,
  27744. ideographwatercircle: 0x328C,
  27745. ideographwoodcircle: 0x328D,
  27746. ideva: 0x0907,
  27747. idieresis: 0x00EF,
  27748. idieresisacute: 0x1E2F,
  27749. idieresiscyrillic: 0x04E5,
  27750. idotbelow: 0x1ECB,
  27751. iebrevecyrillic: 0x04D7,
  27752. iecyrillic: 0x0435,
  27753. ieungacirclekorean: 0x3275,
  27754. ieungaparenkorean: 0x3215,
  27755. ieungcirclekorean: 0x3267,
  27756. ieungkorean: 0x3147,
  27757. ieungparenkorean: 0x3207,
  27758. igrave: 0x00EC,
  27759. igujarati: 0x0A87,
  27760. igurmukhi: 0x0A07,
  27761. ihiragana: 0x3044,
  27762. ihookabove: 0x1EC9,
  27763. iibengali: 0x0988,
  27764. iicyrillic: 0x0438,
  27765. iideva: 0x0908,
  27766. iigujarati: 0x0A88,
  27767. iigurmukhi: 0x0A08,
  27768. iimatragurmukhi: 0x0A40,
  27769. iinvertedbreve: 0x020B,
  27770. iishortcyrillic: 0x0439,
  27771. iivowelsignbengali: 0x09C0,
  27772. iivowelsigndeva: 0x0940,
  27773. iivowelsigngujarati: 0x0AC0,
  27774. ij: 0x0133,
  27775. ikatakana: 0x30A4,
  27776. ikatakanahalfwidth: 0xFF72,
  27777. ikorean: 0x3163,
  27778. ilde: 0x02DC,
  27779. iluyhebrew: 0x05AC,
  27780. imacron: 0x012B,
  27781. imacroncyrillic: 0x04E3,
  27782. imageorapproximatelyequal: 0x2253,
  27783. imatragurmukhi: 0x0A3F,
  27784. imonospace: 0xFF49,
  27785. increment: 0x2206,
  27786. infinity: 0x221E,
  27787. iniarmenian: 0x056B,
  27788. integral: 0x222B,
  27789. integralbottom: 0x2321,
  27790. integralbt: 0x2321,
  27791. integralex: 0xF8F5,
  27792. integraltop: 0x2320,
  27793. integraltp: 0x2320,
  27794. intersection: 0x2229,
  27795. intisquare: 0x3305,
  27796. invbullet: 0x25D8,
  27797. invcircle: 0x25D9,
  27798. invsmileface: 0x263B,
  27799. iocyrillic: 0x0451,
  27800. iogonek: 0x012F,
  27801. iota: 0x03B9,
  27802. iotadieresis: 0x03CA,
  27803. iotadieresistonos: 0x0390,
  27804. iotalatin: 0x0269,
  27805. iotatonos: 0x03AF,
  27806. iparen: 0x24A4,
  27807. irigurmukhi: 0x0A72,
  27808. ismallhiragana: 0x3043,
  27809. ismallkatakana: 0x30A3,
  27810. ismallkatakanahalfwidth: 0xFF68,
  27811. issharbengali: 0x09FA,
  27812. istroke: 0x0268,
  27813. isuperior: 0xF6ED,
  27814. iterationhiragana: 0x309D,
  27815. iterationkatakana: 0x30FD,
  27816. itilde: 0x0129,
  27817. itildebelow: 0x1E2D,
  27818. iubopomofo: 0x3129,
  27819. iucyrillic: 0x044E,
  27820. ivowelsignbengali: 0x09BF,
  27821. ivowelsigndeva: 0x093F,
  27822. ivowelsigngujarati: 0x0ABF,
  27823. izhitsacyrillic: 0x0475,
  27824. izhitsadblgravecyrillic: 0x0477,
  27825. j: 0x006A,
  27826. jaarmenian: 0x0571,
  27827. jabengali: 0x099C,
  27828. jadeva: 0x091C,
  27829. jagujarati: 0x0A9C,
  27830. jagurmukhi: 0x0A1C,
  27831. jbopomofo: 0x3110,
  27832. jcaron: 0x01F0,
  27833. jcircle: 0x24D9,
  27834. jcircumflex: 0x0135,
  27835. jcrossedtail: 0x029D,
  27836. jdotlessstroke: 0x025F,
  27837. jecyrillic: 0x0458,
  27838. jeemarabic: 0x062C,
  27839. jeemfinalarabic: 0xFE9E,
  27840. jeeminitialarabic: 0xFE9F,
  27841. jeemmedialarabic: 0xFEA0,
  27842. jeharabic: 0x0698,
  27843. jehfinalarabic: 0xFB8B,
  27844. jhabengali: 0x099D,
  27845. jhadeva: 0x091D,
  27846. jhagujarati: 0x0A9D,
  27847. jhagurmukhi: 0x0A1D,
  27848. jheharmenian: 0x057B,
  27849. jis: 0x3004,
  27850. jmonospace: 0xFF4A,
  27851. jparen: 0x24A5,
  27852. jsuperior: 0x02B2,
  27853. k: 0x006B,
  27854. kabashkircyrillic: 0x04A1,
  27855. kabengali: 0x0995,
  27856. kacute: 0x1E31,
  27857. kacyrillic: 0x043A,
  27858. kadescendercyrillic: 0x049B,
  27859. kadeva: 0x0915,
  27860. kaf: 0x05DB,
  27861. kafarabic: 0x0643,
  27862. kafdagesh: 0xFB3B,
  27863. kafdageshhebrew: 0xFB3B,
  27864. kaffinalarabic: 0xFEDA,
  27865. kafhebrew: 0x05DB,
  27866. kafinitialarabic: 0xFEDB,
  27867. kafmedialarabic: 0xFEDC,
  27868. kafrafehebrew: 0xFB4D,
  27869. kagujarati: 0x0A95,
  27870. kagurmukhi: 0x0A15,
  27871. kahiragana: 0x304B,
  27872. kahookcyrillic: 0x04C4,
  27873. kakatakana: 0x30AB,
  27874. kakatakanahalfwidth: 0xFF76,
  27875. kappa: 0x03BA,
  27876. kappasymbolgreek: 0x03F0,
  27877. kapyeounmieumkorean: 0x3171,
  27878. kapyeounphieuphkorean: 0x3184,
  27879. kapyeounpieupkorean: 0x3178,
  27880. kapyeounssangpieupkorean: 0x3179,
  27881. karoriisquare: 0x330D,
  27882. kashidaautoarabic: 0x0640,
  27883. kashidaautonosidebearingarabic: 0x0640,
  27884. kasmallkatakana: 0x30F5,
  27885. kasquare: 0x3384,
  27886. kasraarabic: 0x0650,
  27887. kasratanarabic: 0x064D,
  27888. kastrokecyrillic: 0x049F,
  27889. katahiraprolongmarkhalfwidth: 0xFF70,
  27890. kaverticalstrokecyrillic: 0x049D,
  27891. kbopomofo: 0x310E,
  27892. kcalsquare: 0x3389,
  27893. kcaron: 0x01E9,
  27894. kcedilla: 0x0137,
  27895. kcircle: 0x24DA,
  27896. kcommaaccent: 0x0137,
  27897. kdotbelow: 0x1E33,
  27898. keharmenian: 0x0584,
  27899. kehiragana: 0x3051,
  27900. kekatakana: 0x30B1,
  27901. kekatakanahalfwidth: 0xFF79,
  27902. kenarmenian: 0x056F,
  27903. kesmallkatakana: 0x30F6,
  27904. kgreenlandic: 0x0138,
  27905. khabengali: 0x0996,
  27906. khacyrillic: 0x0445,
  27907. khadeva: 0x0916,
  27908. khagujarati: 0x0A96,
  27909. khagurmukhi: 0x0A16,
  27910. khaharabic: 0x062E,
  27911. khahfinalarabic: 0xFEA6,
  27912. khahinitialarabic: 0xFEA7,
  27913. khahmedialarabic: 0xFEA8,
  27914. kheicoptic: 0x03E7,
  27915. khhadeva: 0x0959,
  27916. khhagurmukhi: 0x0A59,
  27917. khieukhacirclekorean: 0x3278,
  27918. khieukhaparenkorean: 0x3218,
  27919. khieukhcirclekorean: 0x326A,
  27920. khieukhkorean: 0x314B,
  27921. khieukhparenkorean: 0x320A,
  27922. khokhaithai: 0x0E02,
  27923. khokhonthai: 0x0E05,
  27924. khokhuatthai: 0x0E03,
  27925. khokhwaithai: 0x0E04,
  27926. khomutthai: 0x0E5B,
  27927. khook: 0x0199,
  27928. khorakhangthai: 0x0E06,
  27929. khzsquare: 0x3391,
  27930. kihiragana: 0x304D,
  27931. kikatakana: 0x30AD,
  27932. kikatakanahalfwidth: 0xFF77,
  27933. kiroguramusquare: 0x3315,
  27934. kiromeetorusquare: 0x3316,
  27935. kirosquare: 0x3314,
  27936. kiyeokacirclekorean: 0x326E,
  27937. kiyeokaparenkorean: 0x320E,
  27938. kiyeokcirclekorean: 0x3260,
  27939. kiyeokkorean: 0x3131,
  27940. kiyeokparenkorean: 0x3200,
  27941. kiyeoksioskorean: 0x3133,
  27942. kjecyrillic: 0x045C,
  27943. klinebelow: 0x1E35,
  27944. klsquare: 0x3398,
  27945. kmcubedsquare: 0x33A6,
  27946. kmonospace: 0xFF4B,
  27947. kmsquaredsquare: 0x33A2,
  27948. kohiragana: 0x3053,
  27949. kohmsquare: 0x33C0,
  27950. kokaithai: 0x0E01,
  27951. kokatakana: 0x30B3,
  27952. kokatakanahalfwidth: 0xFF7A,
  27953. kooposquare: 0x331E,
  27954. koppacyrillic: 0x0481,
  27955. koreanstandardsymbol: 0x327F,
  27956. koroniscmb: 0x0343,
  27957. kparen: 0x24A6,
  27958. kpasquare: 0x33AA,
  27959. ksicyrillic: 0x046F,
  27960. ktsquare: 0x33CF,
  27961. kturned: 0x029E,
  27962. kuhiragana: 0x304F,
  27963. kukatakana: 0x30AF,
  27964. kukatakanahalfwidth: 0xFF78,
  27965. kvsquare: 0x33B8,
  27966. kwsquare: 0x33BE,
  27967. l: 0x006C,
  27968. labengali: 0x09B2,
  27969. lacute: 0x013A,
  27970. ladeva: 0x0932,
  27971. lagujarati: 0x0AB2,
  27972. lagurmukhi: 0x0A32,
  27973. lakkhangyaothai: 0x0E45,
  27974. lamaleffinalarabic: 0xFEFC,
  27975. lamalefhamzaabovefinalarabic: 0xFEF8,
  27976. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  27977. lamalefhamzabelowfinalarabic: 0xFEFA,
  27978. lamalefhamzabelowisolatedarabic: 0xFEF9,
  27979. lamalefisolatedarabic: 0xFEFB,
  27980. lamalefmaddaabovefinalarabic: 0xFEF6,
  27981. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  27982. lamarabic: 0x0644,
  27983. lambda: 0x03BB,
  27984. lambdastroke: 0x019B,
  27985. lamed: 0x05DC,
  27986. lameddagesh: 0xFB3C,
  27987. lameddageshhebrew: 0xFB3C,
  27988. lamedhebrew: 0x05DC,
  27989. lamfinalarabic: 0xFEDE,
  27990. lamhahinitialarabic: 0xFCCA,
  27991. laminitialarabic: 0xFEDF,
  27992. lamjeeminitialarabic: 0xFCC9,
  27993. lamkhahinitialarabic: 0xFCCB,
  27994. lamlamhehisolatedarabic: 0xFDF2,
  27995. lammedialarabic: 0xFEE0,
  27996. lammeemhahinitialarabic: 0xFD88,
  27997. lammeeminitialarabic: 0xFCCC,
  27998. largecircle: 0x25EF,
  27999. lbar: 0x019A,
  28000. lbelt: 0x026C,
  28001. lbopomofo: 0x310C,
  28002. lcaron: 0x013E,
  28003. lcedilla: 0x013C,
  28004. lcircle: 0x24DB,
  28005. lcircumflexbelow: 0x1E3D,
  28006. lcommaaccent: 0x013C,
  28007. ldot: 0x0140,
  28008. ldotaccent: 0x0140,
  28009. ldotbelow: 0x1E37,
  28010. ldotbelowmacron: 0x1E39,
  28011. leftangleabovecmb: 0x031A,
  28012. lefttackbelowcmb: 0x0318,
  28013. less: 0x003C,
  28014. lessequal: 0x2264,
  28015. lessequalorgreater: 0x22DA,
  28016. lessmonospace: 0xFF1C,
  28017. lessorequivalent: 0x2272,
  28018. lessorgreater: 0x2276,
  28019. lessoverequal: 0x2266,
  28020. lesssmall: 0xFE64,
  28021. lezh: 0x026E,
  28022. lfblock: 0x258C,
  28023. lhookretroflex: 0x026D,
  28024. lira: 0x20A4,
  28025. liwnarmenian: 0x056C,
  28026. lj: 0x01C9,
  28027. ljecyrillic: 0x0459,
  28028. ll: 0xF6C0,
  28029. lladeva: 0x0933,
  28030. llagujarati: 0x0AB3,
  28031. llinebelow: 0x1E3B,
  28032. llladeva: 0x0934,
  28033. llvocalicbengali: 0x09E1,
  28034. llvocalicdeva: 0x0961,
  28035. llvocalicvowelsignbengali: 0x09E3,
  28036. llvocalicvowelsigndeva: 0x0963,
  28037. lmiddletilde: 0x026B,
  28038. lmonospace: 0xFF4C,
  28039. lmsquare: 0x33D0,
  28040. lochulathai: 0x0E2C,
  28041. logicaland: 0x2227,
  28042. logicalnot: 0x00AC,
  28043. logicalnotreversed: 0x2310,
  28044. logicalor: 0x2228,
  28045. lolingthai: 0x0E25,
  28046. longs: 0x017F,
  28047. lowlinecenterline: 0xFE4E,
  28048. lowlinecmb: 0x0332,
  28049. lowlinedashed: 0xFE4D,
  28050. lozenge: 0x25CA,
  28051. lparen: 0x24A7,
  28052. lslash: 0x0142,
  28053. lsquare: 0x2113,
  28054. lsuperior: 0xF6EE,
  28055. ltshade: 0x2591,
  28056. luthai: 0x0E26,
  28057. lvocalicbengali: 0x098C,
  28058. lvocalicdeva: 0x090C,
  28059. lvocalicvowelsignbengali: 0x09E2,
  28060. lvocalicvowelsigndeva: 0x0962,
  28061. lxsquare: 0x33D3,
  28062. m: 0x006D,
  28063. mabengali: 0x09AE,
  28064. macron: 0x00AF,
  28065. macronbelowcmb: 0x0331,
  28066. macroncmb: 0x0304,
  28067. macronlowmod: 0x02CD,
  28068. macronmonospace: 0xFFE3,
  28069. macute: 0x1E3F,
  28070. madeva: 0x092E,
  28071. magujarati: 0x0AAE,
  28072. magurmukhi: 0x0A2E,
  28073. mahapakhhebrew: 0x05A4,
  28074. mahapakhlefthebrew: 0x05A4,
  28075. mahiragana: 0x307E,
  28076. maichattawalowleftthai: 0xF895,
  28077. maichattawalowrightthai: 0xF894,
  28078. maichattawathai: 0x0E4B,
  28079. maichattawaupperleftthai: 0xF893,
  28080. maieklowleftthai: 0xF88C,
  28081. maieklowrightthai: 0xF88B,
  28082. maiekthai: 0x0E48,
  28083. maiekupperleftthai: 0xF88A,
  28084. maihanakatleftthai: 0xF884,
  28085. maihanakatthai: 0x0E31,
  28086. maitaikhuleftthai: 0xF889,
  28087. maitaikhuthai: 0x0E47,
  28088. maitholowleftthai: 0xF88F,
  28089. maitholowrightthai: 0xF88E,
  28090. maithothai: 0x0E49,
  28091. maithoupperleftthai: 0xF88D,
  28092. maitrilowleftthai: 0xF892,
  28093. maitrilowrightthai: 0xF891,
  28094. maitrithai: 0x0E4A,
  28095. maitriupperleftthai: 0xF890,
  28096. maiyamokthai: 0x0E46,
  28097. makatakana: 0x30DE,
  28098. makatakanahalfwidth: 0xFF8F,
  28099. male: 0x2642,
  28100. mansyonsquare: 0x3347,
  28101. maqafhebrew: 0x05BE,
  28102. mars: 0x2642,
  28103. masoracirclehebrew: 0x05AF,
  28104. masquare: 0x3383,
  28105. mbopomofo: 0x3107,
  28106. mbsquare: 0x33D4,
  28107. mcircle: 0x24DC,
  28108. mcubedsquare: 0x33A5,
  28109. mdotaccent: 0x1E41,
  28110. mdotbelow: 0x1E43,
  28111. meemarabic: 0x0645,
  28112. meemfinalarabic: 0xFEE2,
  28113. meeminitialarabic: 0xFEE3,
  28114. meemmedialarabic: 0xFEE4,
  28115. meemmeeminitialarabic: 0xFCD1,
  28116. meemmeemisolatedarabic: 0xFC48,
  28117. meetorusquare: 0x334D,
  28118. mehiragana: 0x3081,
  28119. meizierasquare: 0x337E,
  28120. mekatakana: 0x30E1,
  28121. mekatakanahalfwidth: 0xFF92,
  28122. mem: 0x05DE,
  28123. memdagesh: 0xFB3E,
  28124. memdageshhebrew: 0xFB3E,
  28125. memhebrew: 0x05DE,
  28126. menarmenian: 0x0574,
  28127. merkhahebrew: 0x05A5,
  28128. merkhakefulahebrew: 0x05A6,
  28129. merkhakefulalefthebrew: 0x05A6,
  28130. merkhalefthebrew: 0x05A5,
  28131. mhook: 0x0271,
  28132. mhzsquare: 0x3392,
  28133. middledotkatakanahalfwidth: 0xFF65,
  28134. middot: 0x00B7,
  28135. mieumacirclekorean: 0x3272,
  28136. mieumaparenkorean: 0x3212,
  28137. mieumcirclekorean: 0x3264,
  28138. mieumkorean: 0x3141,
  28139. mieumpansioskorean: 0x3170,
  28140. mieumparenkorean: 0x3204,
  28141. mieumpieupkorean: 0x316E,
  28142. mieumsioskorean: 0x316F,
  28143. mihiragana: 0x307F,
  28144. mikatakana: 0x30DF,
  28145. mikatakanahalfwidth: 0xFF90,
  28146. minus: 0x2212,
  28147. minusbelowcmb: 0x0320,
  28148. minuscircle: 0x2296,
  28149. minusmod: 0x02D7,
  28150. minusplus: 0x2213,
  28151. minute: 0x2032,
  28152. miribaarusquare: 0x334A,
  28153. mirisquare: 0x3349,
  28154. mlonglegturned: 0x0270,
  28155. mlsquare: 0x3396,
  28156. mmcubedsquare: 0x33A3,
  28157. mmonospace: 0xFF4D,
  28158. mmsquaredsquare: 0x339F,
  28159. mohiragana: 0x3082,
  28160. mohmsquare: 0x33C1,
  28161. mokatakana: 0x30E2,
  28162. mokatakanahalfwidth: 0xFF93,
  28163. molsquare: 0x33D6,
  28164. momathai: 0x0E21,
  28165. moverssquare: 0x33A7,
  28166. moverssquaredsquare: 0x33A8,
  28167. mparen: 0x24A8,
  28168. mpasquare: 0x33AB,
  28169. mssquare: 0x33B3,
  28170. msuperior: 0xF6EF,
  28171. mturned: 0x026F,
  28172. mu: 0x00B5,
  28173. mu1: 0x00B5,
  28174. muasquare: 0x3382,
  28175. muchgreater: 0x226B,
  28176. muchless: 0x226A,
  28177. mufsquare: 0x338C,
  28178. mugreek: 0x03BC,
  28179. mugsquare: 0x338D,
  28180. muhiragana: 0x3080,
  28181. mukatakana: 0x30E0,
  28182. mukatakanahalfwidth: 0xFF91,
  28183. mulsquare: 0x3395,
  28184. multiply: 0x00D7,
  28185. mumsquare: 0x339B,
  28186. munahhebrew: 0x05A3,
  28187. munahlefthebrew: 0x05A3,
  28188. musicalnote: 0x266A,
  28189. musicalnotedbl: 0x266B,
  28190. musicflatsign: 0x266D,
  28191. musicsharpsign: 0x266F,
  28192. mussquare: 0x33B2,
  28193. muvsquare: 0x33B6,
  28194. muwsquare: 0x33BC,
  28195. mvmegasquare: 0x33B9,
  28196. mvsquare: 0x33B7,
  28197. mwmegasquare: 0x33BF,
  28198. mwsquare: 0x33BD,
  28199. n: 0x006E,
  28200. nabengali: 0x09A8,
  28201. nabla: 0x2207,
  28202. nacute: 0x0144,
  28203. nadeva: 0x0928,
  28204. nagujarati: 0x0AA8,
  28205. nagurmukhi: 0x0A28,
  28206. nahiragana: 0x306A,
  28207. nakatakana: 0x30CA,
  28208. nakatakanahalfwidth: 0xFF85,
  28209. napostrophe: 0x0149,
  28210. nasquare: 0x3381,
  28211. nbopomofo: 0x310B,
  28212. nbspace: 0x00A0,
  28213. ncaron: 0x0148,
  28214. ncedilla: 0x0146,
  28215. ncircle: 0x24DD,
  28216. ncircumflexbelow: 0x1E4B,
  28217. ncommaaccent: 0x0146,
  28218. ndotaccent: 0x1E45,
  28219. ndotbelow: 0x1E47,
  28220. nehiragana: 0x306D,
  28221. nekatakana: 0x30CD,
  28222. nekatakanahalfwidth: 0xFF88,
  28223. newsheqelsign: 0x20AA,
  28224. nfsquare: 0x338B,
  28225. ngabengali: 0x0999,
  28226. ngadeva: 0x0919,
  28227. ngagujarati: 0x0A99,
  28228. ngagurmukhi: 0x0A19,
  28229. ngonguthai: 0x0E07,
  28230. nhiragana: 0x3093,
  28231. nhookleft: 0x0272,
  28232. nhookretroflex: 0x0273,
  28233. nieunacirclekorean: 0x326F,
  28234. nieunaparenkorean: 0x320F,
  28235. nieuncieuckorean: 0x3135,
  28236. nieuncirclekorean: 0x3261,
  28237. nieunhieuhkorean: 0x3136,
  28238. nieunkorean: 0x3134,
  28239. nieunpansioskorean: 0x3168,
  28240. nieunparenkorean: 0x3201,
  28241. nieunsioskorean: 0x3167,
  28242. nieuntikeutkorean: 0x3166,
  28243. nihiragana: 0x306B,
  28244. nikatakana: 0x30CB,
  28245. nikatakanahalfwidth: 0xFF86,
  28246. nikhahitleftthai: 0xF899,
  28247. nikhahitthai: 0x0E4D,
  28248. nine: 0x0039,
  28249. ninearabic: 0x0669,
  28250. ninebengali: 0x09EF,
  28251. ninecircle: 0x2468,
  28252. ninecircleinversesansserif: 0x2792,
  28253. ninedeva: 0x096F,
  28254. ninegujarati: 0x0AEF,
  28255. ninegurmukhi: 0x0A6F,
  28256. ninehackarabic: 0x0669,
  28257. ninehangzhou: 0x3029,
  28258. nineideographicparen: 0x3228,
  28259. nineinferior: 0x2089,
  28260. ninemonospace: 0xFF19,
  28261. nineoldstyle: 0xF739,
  28262. nineparen: 0x247C,
  28263. nineperiod: 0x2490,
  28264. ninepersian: 0x06F9,
  28265. nineroman: 0x2178,
  28266. ninesuperior: 0x2079,
  28267. nineteencircle: 0x2472,
  28268. nineteenparen: 0x2486,
  28269. nineteenperiod: 0x249A,
  28270. ninethai: 0x0E59,
  28271. nj: 0x01CC,
  28272. njecyrillic: 0x045A,
  28273. nkatakana: 0x30F3,
  28274. nkatakanahalfwidth: 0xFF9D,
  28275. nlegrightlong: 0x019E,
  28276. nlinebelow: 0x1E49,
  28277. nmonospace: 0xFF4E,
  28278. nmsquare: 0x339A,
  28279. nnabengali: 0x09A3,
  28280. nnadeva: 0x0923,
  28281. nnagujarati: 0x0AA3,
  28282. nnagurmukhi: 0x0A23,
  28283. nnnadeva: 0x0929,
  28284. nohiragana: 0x306E,
  28285. nokatakana: 0x30CE,
  28286. nokatakanahalfwidth: 0xFF89,
  28287. nonbreakingspace: 0x00A0,
  28288. nonenthai: 0x0E13,
  28289. nonuthai: 0x0E19,
  28290. noonarabic: 0x0646,
  28291. noonfinalarabic: 0xFEE6,
  28292. noonghunnaarabic: 0x06BA,
  28293. noonghunnafinalarabic: 0xFB9F,
  28294. nooninitialarabic: 0xFEE7,
  28295. noonjeeminitialarabic: 0xFCD2,
  28296. noonjeemisolatedarabic: 0xFC4B,
  28297. noonmedialarabic: 0xFEE8,
  28298. noonmeeminitialarabic: 0xFCD5,
  28299. noonmeemisolatedarabic: 0xFC4E,
  28300. noonnoonfinalarabic: 0xFC8D,
  28301. notcontains: 0x220C,
  28302. notelement: 0x2209,
  28303. notelementof: 0x2209,
  28304. notequal: 0x2260,
  28305. notgreater: 0x226F,
  28306. notgreaternorequal: 0x2271,
  28307. notgreaternorless: 0x2279,
  28308. notidentical: 0x2262,
  28309. notless: 0x226E,
  28310. notlessnorequal: 0x2270,
  28311. notparallel: 0x2226,
  28312. notprecedes: 0x2280,
  28313. notsubset: 0x2284,
  28314. notsucceeds: 0x2281,
  28315. notsuperset: 0x2285,
  28316. nowarmenian: 0x0576,
  28317. nparen: 0x24A9,
  28318. nssquare: 0x33B1,
  28319. nsuperior: 0x207F,
  28320. ntilde: 0x00F1,
  28321. nu: 0x03BD,
  28322. nuhiragana: 0x306C,
  28323. nukatakana: 0x30CC,
  28324. nukatakanahalfwidth: 0xFF87,
  28325. nuktabengali: 0x09BC,
  28326. nuktadeva: 0x093C,
  28327. nuktagujarati: 0x0ABC,
  28328. nuktagurmukhi: 0x0A3C,
  28329. numbersign: 0x0023,
  28330. numbersignmonospace: 0xFF03,
  28331. numbersignsmall: 0xFE5F,
  28332. numeralsigngreek: 0x0374,
  28333. numeralsignlowergreek: 0x0375,
  28334. numero: 0x2116,
  28335. nun: 0x05E0,
  28336. nundagesh: 0xFB40,
  28337. nundageshhebrew: 0xFB40,
  28338. nunhebrew: 0x05E0,
  28339. nvsquare: 0x33B5,
  28340. nwsquare: 0x33BB,
  28341. nyabengali: 0x099E,
  28342. nyadeva: 0x091E,
  28343. nyagujarati: 0x0A9E,
  28344. nyagurmukhi: 0x0A1E,
  28345. o: 0x006F,
  28346. oacute: 0x00F3,
  28347. oangthai: 0x0E2D,
  28348. obarred: 0x0275,
  28349. obarredcyrillic: 0x04E9,
  28350. obarreddieresiscyrillic: 0x04EB,
  28351. obengali: 0x0993,
  28352. obopomofo: 0x311B,
  28353. obreve: 0x014F,
  28354. ocandradeva: 0x0911,
  28355. ocandragujarati: 0x0A91,
  28356. ocandravowelsigndeva: 0x0949,
  28357. ocandravowelsigngujarati: 0x0AC9,
  28358. ocaron: 0x01D2,
  28359. ocircle: 0x24DE,
  28360. ocircumflex: 0x00F4,
  28361. ocircumflexacute: 0x1ED1,
  28362. ocircumflexdotbelow: 0x1ED9,
  28363. ocircumflexgrave: 0x1ED3,
  28364. ocircumflexhookabove: 0x1ED5,
  28365. ocircumflextilde: 0x1ED7,
  28366. ocyrillic: 0x043E,
  28367. odblacute: 0x0151,
  28368. odblgrave: 0x020D,
  28369. odeva: 0x0913,
  28370. odieresis: 0x00F6,
  28371. odieresiscyrillic: 0x04E7,
  28372. odotbelow: 0x1ECD,
  28373. oe: 0x0153,
  28374. oekorean: 0x315A,
  28375. ogonek: 0x02DB,
  28376. ogonekcmb: 0x0328,
  28377. ograve: 0x00F2,
  28378. ogujarati: 0x0A93,
  28379. oharmenian: 0x0585,
  28380. ohiragana: 0x304A,
  28381. ohookabove: 0x1ECF,
  28382. ohorn: 0x01A1,
  28383. ohornacute: 0x1EDB,
  28384. ohorndotbelow: 0x1EE3,
  28385. ohorngrave: 0x1EDD,
  28386. ohornhookabove: 0x1EDF,
  28387. ohorntilde: 0x1EE1,
  28388. ohungarumlaut: 0x0151,
  28389. oi: 0x01A3,
  28390. oinvertedbreve: 0x020F,
  28391. okatakana: 0x30AA,
  28392. okatakanahalfwidth: 0xFF75,
  28393. okorean: 0x3157,
  28394. olehebrew: 0x05AB,
  28395. omacron: 0x014D,
  28396. omacronacute: 0x1E53,
  28397. omacrongrave: 0x1E51,
  28398. omdeva: 0x0950,
  28399. omega: 0x03C9,
  28400. omega1: 0x03D6,
  28401. omegacyrillic: 0x0461,
  28402. omegalatinclosed: 0x0277,
  28403. omegaroundcyrillic: 0x047B,
  28404. omegatitlocyrillic: 0x047D,
  28405. omegatonos: 0x03CE,
  28406. omgujarati: 0x0AD0,
  28407. omicron: 0x03BF,
  28408. omicrontonos: 0x03CC,
  28409. omonospace: 0xFF4F,
  28410. one: 0x0031,
  28411. onearabic: 0x0661,
  28412. onebengali: 0x09E7,
  28413. onecircle: 0x2460,
  28414. onecircleinversesansserif: 0x278A,
  28415. onedeva: 0x0967,
  28416. onedotenleader: 0x2024,
  28417. oneeighth: 0x215B,
  28418. onefitted: 0xF6DC,
  28419. onegujarati: 0x0AE7,
  28420. onegurmukhi: 0x0A67,
  28421. onehackarabic: 0x0661,
  28422. onehalf: 0x00BD,
  28423. onehangzhou: 0x3021,
  28424. oneideographicparen: 0x3220,
  28425. oneinferior: 0x2081,
  28426. onemonospace: 0xFF11,
  28427. onenumeratorbengali: 0x09F4,
  28428. oneoldstyle: 0xF731,
  28429. oneparen: 0x2474,
  28430. oneperiod: 0x2488,
  28431. onepersian: 0x06F1,
  28432. onequarter: 0x00BC,
  28433. oneroman: 0x2170,
  28434. onesuperior: 0x00B9,
  28435. onethai: 0x0E51,
  28436. onethird: 0x2153,
  28437. oogonek: 0x01EB,
  28438. oogonekmacron: 0x01ED,
  28439. oogurmukhi: 0x0A13,
  28440. oomatragurmukhi: 0x0A4B,
  28441. oopen: 0x0254,
  28442. oparen: 0x24AA,
  28443. openbullet: 0x25E6,
  28444. option: 0x2325,
  28445. ordfeminine: 0x00AA,
  28446. ordmasculine: 0x00BA,
  28447. orthogonal: 0x221F,
  28448. oshortdeva: 0x0912,
  28449. oshortvowelsigndeva: 0x094A,
  28450. oslash: 0x00F8,
  28451. oslashacute: 0x01FF,
  28452. osmallhiragana: 0x3049,
  28453. osmallkatakana: 0x30A9,
  28454. osmallkatakanahalfwidth: 0xFF6B,
  28455. ostrokeacute: 0x01FF,
  28456. osuperior: 0xF6F0,
  28457. otcyrillic: 0x047F,
  28458. otilde: 0x00F5,
  28459. otildeacute: 0x1E4D,
  28460. otildedieresis: 0x1E4F,
  28461. oubopomofo: 0x3121,
  28462. overline: 0x203E,
  28463. overlinecenterline: 0xFE4A,
  28464. overlinecmb: 0x0305,
  28465. overlinedashed: 0xFE49,
  28466. overlinedblwavy: 0xFE4C,
  28467. overlinewavy: 0xFE4B,
  28468. overscore: 0x00AF,
  28469. ovowelsignbengali: 0x09CB,
  28470. ovowelsigndeva: 0x094B,
  28471. ovowelsigngujarati: 0x0ACB,
  28472. p: 0x0070,
  28473. paampssquare: 0x3380,
  28474. paasentosquare: 0x332B,
  28475. pabengali: 0x09AA,
  28476. pacute: 0x1E55,
  28477. padeva: 0x092A,
  28478. pagedown: 0x21DF,
  28479. pageup: 0x21DE,
  28480. pagujarati: 0x0AAA,
  28481. pagurmukhi: 0x0A2A,
  28482. pahiragana: 0x3071,
  28483. paiyannoithai: 0x0E2F,
  28484. pakatakana: 0x30D1,
  28485. palatalizationcyrilliccmb: 0x0484,
  28486. palochkacyrillic: 0x04C0,
  28487. pansioskorean: 0x317F,
  28488. paragraph: 0x00B6,
  28489. parallel: 0x2225,
  28490. parenleft: 0x0028,
  28491. parenleftaltonearabic: 0xFD3E,
  28492. parenleftbt: 0xF8ED,
  28493. parenleftex: 0xF8EC,
  28494. parenleftinferior: 0x208D,
  28495. parenleftmonospace: 0xFF08,
  28496. parenleftsmall: 0xFE59,
  28497. parenleftsuperior: 0x207D,
  28498. parenlefttp: 0xF8EB,
  28499. parenleftvertical: 0xFE35,
  28500. parenright: 0x0029,
  28501. parenrightaltonearabic: 0xFD3F,
  28502. parenrightbt: 0xF8F8,
  28503. parenrightex: 0xF8F7,
  28504. parenrightinferior: 0x208E,
  28505. parenrightmonospace: 0xFF09,
  28506. parenrightsmall: 0xFE5A,
  28507. parenrightsuperior: 0x207E,
  28508. parenrighttp: 0xF8F6,
  28509. parenrightvertical: 0xFE36,
  28510. partialdiff: 0x2202,
  28511. paseqhebrew: 0x05C0,
  28512. pashtahebrew: 0x0599,
  28513. pasquare: 0x33A9,
  28514. patah: 0x05B7,
  28515. patah11: 0x05B7,
  28516. patah1d: 0x05B7,
  28517. patah2a: 0x05B7,
  28518. patahhebrew: 0x05B7,
  28519. patahnarrowhebrew: 0x05B7,
  28520. patahquarterhebrew: 0x05B7,
  28521. patahwidehebrew: 0x05B7,
  28522. pazerhebrew: 0x05A1,
  28523. pbopomofo: 0x3106,
  28524. pcircle: 0x24DF,
  28525. pdotaccent: 0x1E57,
  28526. pe: 0x05E4,
  28527. pecyrillic: 0x043F,
  28528. pedagesh: 0xFB44,
  28529. pedageshhebrew: 0xFB44,
  28530. peezisquare: 0x333B,
  28531. pefinaldageshhebrew: 0xFB43,
  28532. peharabic: 0x067E,
  28533. peharmenian: 0x057A,
  28534. pehebrew: 0x05E4,
  28535. pehfinalarabic: 0xFB57,
  28536. pehinitialarabic: 0xFB58,
  28537. pehiragana: 0x307A,
  28538. pehmedialarabic: 0xFB59,
  28539. pekatakana: 0x30DA,
  28540. pemiddlehookcyrillic: 0x04A7,
  28541. perafehebrew: 0xFB4E,
  28542. percent: 0x0025,
  28543. percentarabic: 0x066A,
  28544. percentmonospace: 0xFF05,
  28545. percentsmall: 0xFE6A,
  28546. period: 0x002E,
  28547. periodarmenian: 0x0589,
  28548. periodcentered: 0x00B7,
  28549. periodhalfwidth: 0xFF61,
  28550. periodinferior: 0xF6E7,
  28551. periodmonospace: 0xFF0E,
  28552. periodsmall: 0xFE52,
  28553. periodsuperior: 0xF6E8,
  28554. perispomenigreekcmb: 0x0342,
  28555. perpendicular: 0x22A5,
  28556. perthousand: 0x2030,
  28557. peseta: 0x20A7,
  28558. pfsquare: 0x338A,
  28559. phabengali: 0x09AB,
  28560. phadeva: 0x092B,
  28561. phagujarati: 0x0AAB,
  28562. phagurmukhi: 0x0A2B,
  28563. phi: 0x03C6,
  28564. phi1: 0x03D5,
  28565. phieuphacirclekorean: 0x327A,
  28566. phieuphaparenkorean: 0x321A,
  28567. phieuphcirclekorean: 0x326C,
  28568. phieuphkorean: 0x314D,
  28569. phieuphparenkorean: 0x320C,
  28570. philatin: 0x0278,
  28571. phinthuthai: 0x0E3A,
  28572. phisymbolgreek: 0x03D5,
  28573. phook: 0x01A5,
  28574. phophanthai: 0x0E1E,
  28575. phophungthai: 0x0E1C,
  28576. phosamphaothai: 0x0E20,
  28577. pi: 0x03C0,
  28578. pieupacirclekorean: 0x3273,
  28579. pieupaparenkorean: 0x3213,
  28580. pieupcieuckorean: 0x3176,
  28581. pieupcirclekorean: 0x3265,
  28582. pieupkiyeokkorean: 0x3172,
  28583. pieupkorean: 0x3142,
  28584. pieupparenkorean: 0x3205,
  28585. pieupsioskiyeokkorean: 0x3174,
  28586. pieupsioskorean: 0x3144,
  28587. pieupsiostikeutkorean: 0x3175,
  28588. pieupthieuthkorean: 0x3177,
  28589. pieuptikeutkorean: 0x3173,
  28590. pihiragana: 0x3074,
  28591. pikatakana: 0x30D4,
  28592. pisymbolgreek: 0x03D6,
  28593. piwrarmenian: 0x0583,
  28594. plus: 0x002B,
  28595. plusbelowcmb: 0x031F,
  28596. pluscircle: 0x2295,
  28597. plusminus: 0x00B1,
  28598. plusmod: 0x02D6,
  28599. plusmonospace: 0xFF0B,
  28600. plussmall: 0xFE62,
  28601. plussuperior: 0x207A,
  28602. pmonospace: 0xFF50,
  28603. pmsquare: 0x33D8,
  28604. pohiragana: 0x307D,
  28605. pointingindexdownwhite: 0x261F,
  28606. pointingindexleftwhite: 0x261C,
  28607. pointingindexrightwhite: 0x261E,
  28608. pointingindexupwhite: 0x261D,
  28609. pokatakana: 0x30DD,
  28610. poplathai: 0x0E1B,
  28611. postalmark: 0x3012,
  28612. postalmarkface: 0x3020,
  28613. pparen: 0x24AB,
  28614. precedes: 0x227A,
  28615. prescription: 0x211E,
  28616. primemod: 0x02B9,
  28617. primereversed: 0x2035,
  28618. product: 0x220F,
  28619. projective: 0x2305,
  28620. prolongedkana: 0x30FC,
  28621. propellor: 0x2318,
  28622. propersubset: 0x2282,
  28623. propersuperset: 0x2283,
  28624. proportion: 0x2237,
  28625. proportional: 0x221D,
  28626. psi: 0x03C8,
  28627. psicyrillic: 0x0471,
  28628. psilipneumatacyrilliccmb: 0x0486,
  28629. pssquare: 0x33B0,
  28630. puhiragana: 0x3077,
  28631. pukatakana: 0x30D7,
  28632. pvsquare: 0x33B4,
  28633. pwsquare: 0x33BA,
  28634. q: 0x0071,
  28635. qadeva: 0x0958,
  28636. qadmahebrew: 0x05A8,
  28637. qafarabic: 0x0642,
  28638. qaffinalarabic: 0xFED6,
  28639. qafinitialarabic: 0xFED7,
  28640. qafmedialarabic: 0xFED8,
  28641. qamats: 0x05B8,
  28642. qamats10: 0x05B8,
  28643. qamats1a: 0x05B8,
  28644. qamats1c: 0x05B8,
  28645. qamats27: 0x05B8,
  28646. qamats29: 0x05B8,
  28647. qamats33: 0x05B8,
  28648. qamatsde: 0x05B8,
  28649. qamatshebrew: 0x05B8,
  28650. qamatsnarrowhebrew: 0x05B8,
  28651. qamatsqatanhebrew: 0x05B8,
  28652. qamatsqatannarrowhebrew: 0x05B8,
  28653. qamatsqatanquarterhebrew: 0x05B8,
  28654. qamatsqatanwidehebrew: 0x05B8,
  28655. qamatsquarterhebrew: 0x05B8,
  28656. qamatswidehebrew: 0x05B8,
  28657. qarneyparahebrew: 0x059F,
  28658. qbopomofo: 0x3111,
  28659. qcircle: 0x24E0,
  28660. qhook: 0x02A0,
  28661. qmonospace: 0xFF51,
  28662. qof: 0x05E7,
  28663. qofdagesh: 0xFB47,
  28664. qofdageshhebrew: 0xFB47,
  28665. qofhebrew: 0x05E7,
  28666. qparen: 0x24AC,
  28667. quarternote: 0x2669,
  28668. qubuts: 0x05BB,
  28669. qubuts18: 0x05BB,
  28670. qubuts25: 0x05BB,
  28671. qubuts31: 0x05BB,
  28672. qubutshebrew: 0x05BB,
  28673. qubutsnarrowhebrew: 0x05BB,
  28674. qubutsquarterhebrew: 0x05BB,
  28675. qubutswidehebrew: 0x05BB,
  28676. question: 0x003F,
  28677. questionarabic: 0x061F,
  28678. questionarmenian: 0x055E,
  28679. questiondown: 0x00BF,
  28680. questiondownsmall: 0xF7BF,
  28681. questiongreek: 0x037E,
  28682. questionmonospace: 0xFF1F,
  28683. questionsmall: 0xF73F,
  28684. quotedbl: 0x0022,
  28685. quotedblbase: 0x201E,
  28686. quotedblleft: 0x201C,
  28687. quotedblmonospace: 0xFF02,
  28688. quotedblprime: 0x301E,
  28689. quotedblprimereversed: 0x301D,
  28690. quotedblright: 0x201D,
  28691. quoteleft: 0x2018,
  28692. quoteleftreversed: 0x201B,
  28693. quotereversed: 0x201B,
  28694. quoteright: 0x2019,
  28695. quoterightn: 0x0149,
  28696. quotesinglbase: 0x201A,
  28697. quotesingle: 0x0027,
  28698. quotesinglemonospace: 0xFF07,
  28699. r: 0x0072,
  28700. raarmenian: 0x057C,
  28701. rabengali: 0x09B0,
  28702. racute: 0x0155,
  28703. radeva: 0x0930,
  28704. radical: 0x221A,
  28705. radicalex: 0xF8E5,
  28706. radoverssquare: 0x33AE,
  28707. radoverssquaredsquare: 0x33AF,
  28708. radsquare: 0x33AD,
  28709. rafe: 0x05BF,
  28710. rafehebrew: 0x05BF,
  28711. ragujarati: 0x0AB0,
  28712. ragurmukhi: 0x0A30,
  28713. rahiragana: 0x3089,
  28714. rakatakana: 0x30E9,
  28715. rakatakanahalfwidth: 0xFF97,
  28716. ralowerdiagonalbengali: 0x09F1,
  28717. ramiddlediagonalbengali: 0x09F0,
  28718. ramshorn: 0x0264,
  28719. ratio: 0x2236,
  28720. rbopomofo: 0x3116,
  28721. rcaron: 0x0159,
  28722. rcedilla: 0x0157,
  28723. rcircle: 0x24E1,
  28724. rcommaaccent: 0x0157,
  28725. rdblgrave: 0x0211,
  28726. rdotaccent: 0x1E59,
  28727. rdotbelow: 0x1E5B,
  28728. rdotbelowmacron: 0x1E5D,
  28729. referencemark: 0x203B,
  28730. reflexsubset: 0x2286,
  28731. reflexsuperset: 0x2287,
  28732. registered: 0x00AE,
  28733. registersans: 0xF8E8,
  28734. registerserif: 0xF6DA,
  28735. reharabic: 0x0631,
  28736. reharmenian: 0x0580,
  28737. rehfinalarabic: 0xFEAE,
  28738. rehiragana: 0x308C,
  28739. rekatakana: 0x30EC,
  28740. rekatakanahalfwidth: 0xFF9A,
  28741. resh: 0x05E8,
  28742. reshdageshhebrew: 0xFB48,
  28743. reshhebrew: 0x05E8,
  28744. reversedtilde: 0x223D,
  28745. reviahebrew: 0x0597,
  28746. reviamugrashhebrew: 0x0597,
  28747. revlogicalnot: 0x2310,
  28748. rfishhook: 0x027E,
  28749. rfishhookreversed: 0x027F,
  28750. rhabengali: 0x09DD,
  28751. rhadeva: 0x095D,
  28752. rho: 0x03C1,
  28753. rhook: 0x027D,
  28754. rhookturned: 0x027B,
  28755. rhookturnedsuperior: 0x02B5,
  28756. rhosymbolgreek: 0x03F1,
  28757. rhotichookmod: 0x02DE,
  28758. rieulacirclekorean: 0x3271,
  28759. rieulaparenkorean: 0x3211,
  28760. rieulcirclekorean: 0x3263,
  28761. rieulhieuhkorean: 0x3140,
  28762. rieulkiyeokkorean: 0x313A,
  28763. rieulkiyeoksioskorean: 0x3169,
  28764. rieulkorean: 0x3139,
  28765. rieulmieumkorean: 0x313B,
  28766. rieulpansioskorean: 0x316C,
  28767. rieulparenkorean: 0x3203,
  28768. rieulphieuphkorean: 0x313F,
  28769. rieulpieupkorean: 0x313C,
  28770. rieulpieupsioskorean: 0x316B,
  28771. rieulsioskorean: 0x313D,
  28772. rieulthieuthkorean: 0x313E,
  28773. rieultikeutkorean: 0x316A,
  28774. rieulyeorinhieuhkorean: 0x316D,
  28775. rightangle: 0x221F,
  28776. righttackbelowcmb: 0x0319,
  28777. righttriangle: 0x22BF,
  28778. rihiragana: 0x308A,
  28779. rikatakana: 0x30EA,
  28780. rikatakanahalfwidth: 0xFF98,
  28781. ring: 0x02DA,
  28782. ringbelowcmb: 0x0325,
  28783. ringcmb: 0x030A,
  28784. ringhalfleft: 0x02BF,
  28785. ringhalfleftarmenian: 0x0559,
  28786. ringhalfleftbelowcmb: 0x031C,
  28787. ringhalfleftcentered: 0x02D3,
  28788. ringhalfright: 0x02BE,
  28789. ringhalfrightbelowcmb: 0x0339,
  28790. ringhalfrightcentered: 0x02D2,
  28791. rinvertedbreve: 0x0213,
  28792. rittorusquare: 0x3351,
  28793. rlinebelow: 0x1E5F,
  28794. rlongleg: 0x027C,
  28795. rlonglegturned: 0x027A,
  28796. rmonospace: 0xFF52,
  28797. rohiragana: 0x308D,
  28798. rokatakana: 0x30ED,
  28799. rokatakanahalfwidth: 0xFF9B,
  28800. roruathai: 0x0E23,
  28801. rparen: 0x24AD,
  28802. rrabengali: 0x09DC,
  28803. rradeva: 0x0931,
  28804. rragurmukhi: 0x0A5C,
  28805. rreharabic: 0x0691,
  28806. rrehfinalarabic: 0xFB8D,
  28807. rrvocalicbengali: 0x09E0,
  28808. rrvocalicdeva: 0x0960,
  28809. rrvocalicgujarati: 0x0AE0,
  28810. rrvocalicvowelsignbengali: 0x09C4,
  28811. rrvocalicvowelsigndeva: 0x0944,
  28812. rrvocalicvowelsigngujarati: 0x0AC4,
  28813. rsuperior: 0xF6F1,
  28814. rtblock: 0x2590,
  28815. rturned: 0x0279,
  28816. rturnedsuperior: 0x02B4,
  28817. ruhiragana: 0x308B,
  28818. rukatakana: 0x30EB,
  28819. rukatakanahalfwidth: 0xFF99,
  28820. rupeemarkbengali: 0x09F2,
  28821. rupeesignbengali: 0x09F3,
  28822. rupiah: 0xF6DD,
  28823. ruthai: 0x0E24,
  28824. rvocalicbengali: 0x098B,
  28825. rvocalicdeva: 0x090B,
  28826. rvocalicgujarati: 0x0A8B,
  28827. rvocalicvowelsignbengali: 0x09C3,
  28828. rvocalicvowelsigndeva: 0x0943,
  28829. rvocalicvowelsigngujarati: 0x0AC3,
  28830. s: 0x0073,
  28831. sabengali: 0x09B8,
  28832. sacute: 0x015B,
  28833. sacutedotaccent: 0x1E65,
  28834. sadarabic: 0x0635,
  28835. sadeva: 0x0938,
  28836. sadfinalarabic: 0xFEBA,
  28837. sadinitialarabic: 0xFEBB,
  28838. sadmedialarabic: 0xFEBC,
  28839. sagujarati: 0x0AB8,
  28840. sagurmukhi: 0x0A38,
  28841. sahiragana: 0x3055,
  28842. sakatakana: 0x30B5,
  28843. sakatakanahalfwidth: 0xFF7B,
  28844. sallallahoualayhewasallamarabic: 0xFDFA,
  28845. samekh: 0x05E1,
  28846. samekhdagesh: 0xFB41,
  28847. samekhdageshhebrew: 0xFB41,
  28848. samekhhebrew: 0x05E1,
  28849. saraaathai: 0x0E32,
  28850. saraaethai: 0x0E41,
  28851. saraaimaimalaithai: 0x0E44,
  28852. saraaimaimuanthai: 0x0E43,
  28853. saraamthai: 0x0E33,
  28854. saraathai: 0x0E30,
  28855. saraethai: 0x0E40,
  28856. saraiileftthai: 0xF886,
  28857. saraiithai: 0x0E35,
  28858. saraileftthai: 0xF885,
  28859. saraithai: 0x0E34,
  28860. saraothai: 0x0E42,
  28861. saraueeleftthai: 0xF888,
  28862. saraueethai: 0x0E37,
  28863. saraueleftthai: 0xF887,
  28864. sarauethai: 0x0E36,
  28865. sarauthai: 0x0E38,
  28866. sarauuthai: 0x0E39,
  28867. sbopomofo: 0x3119,
  28868. scaron: 0x0161,
  28869. scarondotaccent: 0x1E67,
  28870. scedilla: 0x015F,
  28871. schwa: 0x0259,
  28872. schwacyrillic: 0x04D9,
  28873. schwadieresiscyrillic: 0x04DB,
  28874. schwahook: 0x025A,
  28875. scircle: 0x24E2,
  28876. scircumflex: 0x015D,
  28877. scommaaccent: 0x0219,
  28878. sdotaccent: 0x1E61,
  28879. sdotbelow: 0x1E63,
  28880. sdotbelowdotaccent: 0x1E69,
  28881. seagullbelowcmb: 0x033C,
  28882. second: 0x2033,
  28883. secondtonechinese: 0x02CA,
  28884. section: 0x00A7,
  28885. seenarabic: 0x0633,
  28886. seenfinalarabic: 0xFEB2,
  28887. seeninitialarabic: 0xFEB3,
  28888. seenmedialarabic: 0xFEB4,
  28889. segol: 0x05B6,
  28890. segol13: 0x05B6,
  28891. segol1f: 0x05B6,
  28892. segol2c: 0x05B6,
  28893. segolhebrew: 0x05B6,
  28894. segolnarrowhebrew: 0x05B6,
  28895. segolquarterhebrew: 0x05B6,
  28896. segoltahebrew: 0x0592,
  28897. segolwidehebrew: 0x05B6,
  28898. seharmenian: 0x057D,
  28899. sehiragana: 0x305B,
  28900. sekatakana: 0x30BB,
  28901. sekatakanahalfwidth: 0xFF7E,
  28902. semicolon: 0x003B,
  28903. semicolonarabic: 0x061B,
  28904. semicolonmonospace: 0xFF1B,
  28905. semicolonsmall: 0xFE54,
  28906. semivoicedmarkkana: 0x309C,
  28907. semivoicedmarkkanahalfwidth: 0xFF9F,
  28908. sentisquare: 0x3322,
  28909. sentosquare: 0x3323,
  28910. seven: 0x0037,
  28911. sevenarabic: 0x0667,
  28912. sevenbengali: 0x09ED,
  28913. sevencircle: 0x2466,
  28914. sevencircleinversesansserif: 0x2790,
  28915. sevendeva: 0x096D,
  28916. seveneighths: 0x215E,
  28917. sevengujarati: 0x0AED,
  28918. sevengurmukhi: 0x0A6D,
  28919. sevenhackarabic: 0x0667,
  28920. sevenhangzhou: 0x3027,
  28921. sevenideographicparen: 0x3226,
  28922. seveninferior: 0x2087,
  28923. sevenmonospace: 0xFF17,
  28924. sevenoldstyle: 0xF737,
  28925. sevenparen: 0x247A,
  28926. sevenperiod: 0x248E,
  28927. sevenpersian: 0x06F7,
  28928. sevenroman: 0x2176,
  28929. sevensuperior: 0x2077,
  28930. seventeencircle: 0x2470,
  28931. seventeenparen: 0x2484,
  28932. seventeenperiod: 0x2498,
  28933. seventhai: 0x0E57,
  28934. sfthyphen: 0x00AD,
  28935. shaarmenian: 0x0577,
  28936. shabengali: 0x09B6,
  28937. shacyrillic: 0x0448,
  28938. shaddaarabic: 0x0651,
  28939. shaddadammaarabic: 0xFC61,
  28940. shaddadammatanarabic: 0xFC5E,
  28941. shaddafathaarabic: 0xFC60,
  28942. shaddakasraarabic: 0xFC62,
  28943. shaddakasratanarabic: 0xFC5F,
  28944. shade: 0x2592,
  28945. shadedark: 0x2593,
  28946. shadelight: 0x2591,
  28947. shademedium: 0x2592,
  28948. shadeva: 0x0936,
  28949. shagujarati: 0x0AB6,
  28950. shagurmukhi: 0x0A36,
  28951. shalshelethebrew: 0x0593,
  28952. shbopomofo: 0x3115,
  28953. shchacyrillic: 0x0449,
  28954. sheenarabic: 0x0634,
  28955. sheenfinalarabic: 0xFEB6,
  28956. sheeninitialarabic: 0xFEB7,
  28957. sheenmedialarabic: 0xFEB8,
  28958. sheicoptic: 0x03E3,
  28959. sheqel: 0x20AA,
  28960. sheqelhebrew: 0x20AA,
  28961. sheva: 0x05B0,
  28962. sheva115: 0x05B0,
  28963. sheva15: 0x05B0,
  28964. sheva22: 0x05B0,
  28965. sheva2e: 0x05B0,
  28966. shevahebrew: 0x05B0,
  28967. shevanarrowhebrew: 0x05B0,
  28968. shevaquarterhebrew: 0x05B0,
  28969. shevawidehebrew: 0x05B0,
  28970. shhacyrillic: 0x04BB,
  28971. shimacoptic: 0x03ED,
  28972. shin: 0x05E9,
  28973. shindagesh: 0xFB49,
  28974. shindageshhebrew: 0xFB49,
  28975. shindageshshindot: 0xFB2C,
  28976. shindageshshindothebrew: 0xFB2C,
  28977. shindageshsindot: 0xFB2D,
  28978. shindageshsindothebrew: 0xFB2D,
  28979. shindothebrew: 0x05C1,
  28980. shinhebrew: 0x05E9,
  28981. shinshindot: 0xFB2A,
  28982. shinshindothebrew: 0xFB2A,
  28983. shinsindot: 0xFB2B,
  28984. shinsindothebrew: 0xFB2B,
  28985. shook: 0x0282,
  28986. sigma: 0x03C3,
  28987. sigma1: 0x03C2,
  28988. sigmafinal: 0x03C2,
  28989. sigmalunatesymbolgreek: 0x03F2,
  28990. sihiragana: 0x3057,
  28991. sikatakana: 0x30B7,
  28992. sikatakanahalfwidth: 0xFF7C,
  28993. siluqhebrew: 0x05BD,
  28994. siluqlefthebrew: 0x05BD,
  28995. similar: 0x223C,
  28996. sindothebrew: 0x05C2,
  28997. siosacirclekorean: 0x3274,
  28998. siosaparenkorean: 0x3214,
  28999. sioscieuckorean: 0x317E,
  29000. sioscirclekorean: 0x3266,
  29001. sioskiyeokkorean: 0x317A,
  29002. sioskorean: 0x3145,
  29003. siosnieunkorean: 0x317B,
  29004. siosparenkorean: 0x3206,
  29005. siospieupkorean: 0x317D,
  29006. siostikeutkorean: 0x317C,
  29007. six: 0x0036,
  29008. sixarabic: 0x0666,
  29009. sixbengali: 0x09EC,
  29010. sixcircle: 0x2465,
  29011. sixcircleinversesansserif: 0x278F,
  29012. sixdeva: 0x096C,
  29013. sixgujarati: 0x0AEC,
  29014. sixgurmukhi: 0x0A6C,
  29015. sixhackarabic: 0x0666,
  29016. sixhangzhou: 0x3026,
  29017. sixideographicparen: 0x3225,
  29018. sixinferior: 0x2086,
  29019. sixmonospace: 0xFF16,
  29020. sixoldstyle: 0xF736,
  29021. sixparen: 0x2479,
  29022. sixperiod: 0x248D,
  29023. sixpersian: 0x06F6,
  29024. sixroman: 0x2175,
  29025. sixsuperior: 0x2076,
  29026. sixteencircle: 0x246F,
  29027. sixteencurrencydenominatorbengali: 0x09F9,
  29028. sixteenparen: 0x2483,
  29029. sixteenperiod: 0x2497,
  29030. sixthai: 0x0E56,
  29031. slash: 0x002F,
  29032. slashmonospace: 0xFF0F,
  29033. slong: 0x017F,
  29034. slongdotaccent: 0x1E9B,
  29035. smileface: 0x263A,
  29036. smonospace: 0xFF53,
  29037. sofpasuqhebrew: 0x05C3,
  29038. softhyphen: 0x00AD,
  29039. softsigncyrillic: 0x044C,
  29040. sohiragana: 0x305D,
  29041. sokatakana: 0x30BD,
  29042. sokatakanahalfwidth: 0xFF7F,
  29043. soliduslongoverlaycmb: 0x0338,
  29044. solidusshortoverlaycmb: 0x0337,
  29045. sorusithai: 0x0E29,
  29046. sosalathai: 0x0E28,
  29047. sosothai: 0x0E0B,
  29048. sosuathai: 0x0E2A,
  29049. space: 0x0020,
  29050. spacehackarabic: 0x0020,
  29051. spade: 0x2660,
  29052. spadesuitblack: 0x2660,
  29053. spadesuitwhite: 0x2664,
  29054. sparen: 0x24AE,
  29055. squarebelowcmb: 0x033B,
  29056. squarecc: 0x33C4,
  29057. squarecm: 0x339D,
  29058. squarediagonalcrosshatchfill: 0x25A9,
  29059. squarehorizontalfill: 0x25A4,
  29060. squarekg: 0x338F,
  29061. squarekm: 0x339E,
  29062. squarekmcapital: 0x33CE,
  29063. squareln: 0x33D1,
  29064. squarelog: 0x33D2,
  29065. squaremg: 0x338E,
  29066. squaremil: 0x33D5,
  29067. squaremm: 0x339C,
  29068. squaremsquared: 0x33A1,
  29069. squareorthogonalcrosshatchfill: 0x25A6,
  29070. squareupperlefttolowerrightfill: 0x25A7,
  29071. squareupperrighttolowerleftfill: 0x25A8,
  29072. squareverticalfill: 0x25A5,
  29073. squarewhitewithsmallblack: 0x25A3,
  29074. srsquare: 0x33DB,
  29075. ssabengali: 0x09B7,
  29076. ssadeva: 0x0937,
  29077. ssagujarati: 0x0AB7,
  29078. ssangcieuckorean: 0x3149,
  29079. ssanghieuhkorean: 0x3185,
  29080. ssangieungkorean: 0x3180,
  29081. ssangkiyeokkorean: 0x3132,
  29082. ssangnieunkorean: 0x3165,
  29083. ssangpieupkorean: 0x3143,
  29084. ssangsioskorean: 0x3146,
  29085. ssangtikeutkorean: 0x3138,
  29086. ssuperior: 0xF6F2,
  29087. sterling: 0x00A3,
  29088. sterlingmonospace: 0xFFE1,
  29089. strokelongoverlaycmb: 0x0336,
  29090. strokeshortoverlaycmb: 0x0335,
  29091. subset: 0x2282,
  29092. subsetnotequal: 0x228A,
  29093. subsetorequal: 0x2286,
  29094. succeeds: 0x227B,
  29095. suchthat: 0x220B,
  29096. suhiragana: 0x3059,
  29097. sukatakana: 0x30B9,
  29098. sukatakanahalfwidth: 0xFF7D,
  29099. sukunarabic: 0x0652,
  29100. summation: 0x2211,
  29101. sun: 0x263C,
  29102. superset: 0x2283,
  29103. supersetnotequal: 0x228B,
  29104. supersetorequal: 0x2287,
  29105. svsquare: 0x33DC,
  29106. syouwaerasquare: 0x337C,
  29107. t: 0x0074,
  29108. tabengali: 0x09A4,
  29109. tackdown: 0x22A4,
  29110. tackleft: 0x22A3,
  29111. tadeva: 0x0924,
  29112. tagujarati: 0x0AA4,
  29113. tagurmukhi: 0x0A24,
  29114. taharabic: 0x0637,
  29115. tahfinalarabic: 0xFEC2,
  29116. tahinitialarabic: 0xFEC3,
  29117. tahiragana: 0x305F,
  29118. tahmedialarabic: 0xFEC4,
  29119. taisyouerasquare: 0x337D,
  29120. takatakana: 0x30BF,
  29121. takatakanahalfwidth: 0xFF80,
  29122. tatweelarabic: 0x0640,
  29123. tau: 0x03C4,
  29124. tav: 0x05EA,
  29125. tavdages: 0xFB4A,
  29126. tavdagesh: 0xFB4A,
  29127. tavdageshhebrew: 0xFB4A,
  29128. tavhebrew: 0x05EA,
  29129. tbar: 0x0167,
  29130. tbopomofo: 0x310A,
  29131. tcaron: 0x0165,
  29132. tccurl: 0x02A8,
  29133. tcedilla: 0x0163,
  29134. tcheharabic: 0x0686,
  29135. tchehfinalarabic: 0xFB7B,
  29136. tchehinitialarabic: 0xFB7C,
  29137. tchehmedialarabic: 0xFB7D,
  29138. tcircle: 0x24E3,
  29139. tcircumflexbelow: 0x1E71,
  29140. tcommaaccent: 0x0163,
  29141. tdieresis: 0x1E97,
  29142. tdotaccent: 0x1E6B,
  29143. tdotbelow: 0x1E6D,
  29144. tecyrillic: 0x0442,
  29145. tedescendercyrillic: 0x04AD,
  29146. teharabic: 0x062A,
  29147. tehfinalarabic: 0xFE96,
  29148. tehhahinitialarabic: 0xFCA2,
  29149. tehhahisolatedarabic: 0xFC0C,
  29150. tehinitialarabic: 0xFE97,
  29151. tehiragana: 0x3066,
  29152. tehjeeminitialarabic: 0xFCA1,
  29153. tehjeemisolatedarabic: 0xFC0B,
  29154. tehmarbutaarabic: 0x0629,
  29155. tehmarbutafinalarabic: 0xFE94,
  29156. tehmedialarabic: 0xFE98,
  29157. tehmeeminitialarabic: 0xFCA4,
  29158. tehmeemisolatedarabic: 0xFC0E,
  29159. tehnoonfinalarabic: 0xFC73,
  29160. tekatakana: 0x30C6,
  29161. tekatakanahalfwidth: 0xFF83,
  29162. telephone: 0x2121,
  29163. telephoneblack: 0x260E,
  29164. telishagedolahebrew: 0x05A0,
  29165. telishaqetanahebrew: 0x05A9,
  29166. tencircle: 0x2469,
  29167. tenideographicparen: 0x3229,
  29168. tenparen: 0x247D,
  29169. tenperiod: 0x2491,
  29170. tenroman: 0x2179,
  29171. tesh: 0x02A7,
  29172. tet: 0x05D8,
  29173. tetdagesh: 0xFB38,
  29174. tetdageshhebrew: 0xFB38,
  29175. tethebrew: 0x05D8,
  29176. tetsecyrillic: 0x04B5,
  29177. tevirhebrew: 0x059B,
  29178. tevirlefthebrew: 0x059B,
  29179. thabengali: 0x09A5,
  29180. thadeva: 0x0925,
  29181. thagujarati: 0x0AA5,
  29182. thagurmukhi: 0x0A25,
  29183. thalarabic: 0x0630,
  29184. thalfinalarabic: 0xFEAC,
  29185. thanthakhatlowleftthai: 0xF898,
  29186. thanthakhatlowrightthai: 0xF897,
  29187. thanthakhatthai: 0x0E4C,
  29188. thanthakhatupperleftthai: 0xF896,
  29189. theharabic: 0x062B,
  29190. thehfinalarabic: 0xFE9A,
  29191. thehinitialarabic: 0xFE9B,
  29192. thehmedialarabic: 0xFE9C,
  29193. thereexists: 0x2203,
  29194. therefore: 0x2234,
  29195. theta: 0x03B8,
  29196. theta1: 0x03D1,
  29197. thetasymbolgreek: 0x03D1,
  29198. thieuthacirclekorean: 0x3279,
  29199. thieuthaparenkorean: 0x3219,
  29200. thieuthcirclekorean: 0x326B,
  29201. thieuthkorean: 0x314C,
  29202. thieuthparenkorean: 0x320B,
  29203. thirteencircle: 0x246C,
  29204. thirteenparen: 0x2480,
  29205. thirteenperiod: 0x2494,
  29206. thonangmonthothai: 0x0E11,
  29207. thook: 0x01AD,
  29208. thophuthaothai: 0x0E12,
  29209. thorn: 0x00FE,
  29210. thothahanthai: 0x0E17,
  29211. thothanthai: 0x0E10,
  29212. thothongthai: 0x0E18,
  29213. thothungthai: 0x0E16,
  29214. thousandcyrillic: 0x0482,
  29215. thousandsseparatorarabic: 0x066C,
  29216. thousandsseparatorpersian: 0x066C,
  29217. three: 0x0033,
  29218. threearabic: 0x0663,
  29219. threebengali: 0x09E9,
  29220. threecircle: 0x2462,
  29221. threecircleinversesansserif: 0x278C,
  29222. threedeva: 0x0969,
  29223. threeeighths: 0x215C,
  29224. threegujarati: 0x0AE9,
  29225. threegurmukhi: 0x0A69,
  29226. threehackarabic: 0x0663,
  29227. threehangzhou: 0x3023,
  29228. threeideographicparen: 0x3222,
  29229. threeinferior: 0x2083,
  29230. threemonospace: 0xFF13,
  29231. threenumeratorbengali: 0x09F6,
  29232. threeoldstyle: 0xF733,
  29233. threeparen: 0x2476,
  29234. threeperiod: 0x248A,
  29235. threepersian: 0x06F3,
  29236. threequarters: 0x00BE,
  29237. threequartersemdash: 0xF6DE,
  29238. threeroman: 0x2172,
  29239. threesuperior: 0x00B3,
  29240. threethai: 0x0E53,
  29241. thzsquare: 0x3394,
  29242. tihiragana: 0x3061,
  29243. tikatakana: 0x30C1,
  29244. tikatakanahalfwidth: 0xFF81,
  29245. tikeutacirclekorean: 0x3270,
  29246. tikeutaparenkorean: 0x3210,
  29247. tikeutcirclekorean: 0x3262,
  29248. tikeutkorean: 0x3137,
  29249. tikeutparenkorean: 0x3202,
  29250. tilde: 0x02DC,
  29251. tildebelowcmb: 0x0330,
  29252. tildecmb: 0x0303,
  29253. tildecomb: 0x0303,
  29254. tildedoublecmb: 0x0360,
  29255. tildeoperator: 0x223C,
  29256. tildeoverlaycmb: 0x0334,
  29257. tildeverticalcmb: 0x033E,
  29258. timescircle: 0x2297,
  29259. tipehahebrew: 0x0596,
  29260. tipehalefthebrew: 0x0596,
  29261. tippigurmukhi: 0x0A70,
  29262. titlocyrilliccmb: 0x0483,
  29263. tiwnarmenian: 0x057F,
  29264. tlinebelow: 0x1E6F,
  29265. tmonospace: 0xFF54,
  29266. toarmenian: 0x0569,
  29267. tohiragana: 0x3068,
  29268. tokatakana: 0x30C8,
  29269. tokatakanahalfwidth: 0xFF84,
  29270. tonebarextrahighmod: 0x02E5,
  29271. tonebarextralowmod: 0x02E9,
  29272. tonebarhighmod: 0x02E6,
  29273. tonebarlowmod: 0x02E8,
  29274. tonebarmidmod: 0x02E7,
  29275. tonefive: 0x01BD,
  29276. tonesix: 0x0185,
  29277. tonetwo: 0x01A8,
  29278. tonos: 0x0384,
  29279. tonsquare: 0x3327,
  29280. topatakthai: 0x0E0F,
  29281. tortoiseshellbracketleft: 0x3014,
  29282. tortoiseshellbracketleftsmall: 0xFE5D,
  29283. tortoiseshellbracketleftvertical: 0xFE39,
  29284. tortoiseshellbracketright: 0x3015,
  29285. tortoiseshellbracketrightsmall: 0xFE5E,
  29286. tortoiseshellbracketrightvertical: 0xFE3A,
  29287. totaothai: 0x0E15,
  29288. tpalatalhook: 0x01AB,
  29289. tparen: 0x24AF,
  29290. trademark: 0x2122,
  29291. trademarksans: 0xF8EA,
  29292. trademarkserif: 0xF6DB,
  29293. tretroflexhook: 0x0288,
  29294. triagdn: 0x25BC,
  29295. triaglf: 0x25C4,
  29296. triagrt: 0x25BA,
  29297. triagup: 0x25B2,
  29298. ts: 0x02A6,
  29299. tsadi: 0x05E6,
  29300. tsadidagesh: 0xFB46,
  29301. tsadidageshhebrew: 0xFB46,
  29302. tsadihebrew: 0x05E6,
  29303. tsecyrillic: 0x0446,
  29304. tsere: 0x05B5,
  29305. tsere12: 0x05B5,
  29306. tsere1e: 0x05B5,
  29307. tsere2b: 0x05B5,
  29308. tserehebrew: 0x05B5,
  29309. tserenarrowhebrew: 0x05B5,
  29310. tserequarterhebrew: 0x05B5,
  29311. tserewidehebrew: 0x05B5,
  29312. tshecyrillic: 0x045B,
  29313. tsuperior: 0xF6F3,
  29314. ttabengali: 0x099F,
  29315. ttadeva: 0x091F,
  29316. ttagujarati: 0x0A9F,
  29317. ttagurmukhi: 0x0A1F,
  29318. tteharabic: 0x0679,
  29319. ttehfinalarabic: 0xFB67,
  29320. ttehinitialarabic: 0xFB68,
  29321. ttehmedialarabic: 0xFB69,
  29322. tthabengali: 0x09A0,
  29323. tthadeva: 0x0920,
  29324. tthagujarati: 0x0AA0,
  29325. tthagurmukhi: 0x0A20,
  29326. tturned: 0x0287,
  29327. tuhiragana: 0x3064,
  29328. tukatakana: 0x30C4,
  29329. tukatakanahalfwidth: 0xFF82,
  29330. tusmallhiragana: 0x3063,
  29331. tusmallkatakana: 0x30C3,
  29332. tusmallkatakanahalfwidth: 0xFF6F,
  29333. twelvecircle: 0x246B,
  29334. twelveparen: 0x247F,
  29335. twelveperiod: 0x2493,
  29336. twelveroman: 0x217B,
  29337. twentycircle: 0x2473,
  29338. twentyhangzhou: 0x5344,
  29339. twentyparen: 0x2487,
  29340. twentyperiod: 0x249B,
  29341. two: 0x0032,
  29342. twoarabic: 0x0662,
  29343. twobengali: 0x09E8,
  29344. twocircle: 0x2461,
  29345. twocircleinversesansserif: 0x278B,
  29346. twodeva: 0x0968,
  29347. twodotenleader: 0x2025,
  29348. twodotleader: 0x2025,
  29349. twodotleadervertical: 0xFE30,
  29350. twogujarati: 0x0AE8,
  29351. twogurmukhi: 0x0A68,
  29352. twohackarabic: 0x0662,
  29353. twohangzhou: 0x3022,
  29354. twoideographicparen: 0x3221,
  29355. twoinferior: 0x2082,
  29356. twomonospace: 0xFF12,
  29357. twonumeratorbengali: 0x09F5,
  29358. twooldstyle: 0xF732,
  29359. twoparen: 0x2475,
  29360. twoperiod: 0x2489,
  29361. twopersian: 0x06F2,
  29362. tworoman: 0x2171,
  29363. twostroke: 0x01BB,
  29364. twosuperior: 0x00B2,
  29365. twothai: 0x0E52,
  29366. twothirds: 0x2154,
  29367. u: 0x0075,
  29368. uacute: 0x00FA,
  29369. ubar: 0x0289,
  29370. ubengali: 0x0989,
  29371. ubopomofo: 0x3128,
  29372. ubreve: 0x016D,
  29373. ucaron: 0x01D4,
  29374. ucircle: 0x24E4,
  29375. ucircumflex: 0x00FB,
  29376. ucircumflexbelow: 0x1E77,
  29377. ucyrillic: 0x0443,
  29378. udattadeva: 0x0951,
  29379. udblacute: 0x0171,
  29380. udblgrave: 0x0215,
  29381. udeva: 0x0909,
  29382. udieresis: 0x00FC,
  29383. udieresisacute: 0x01D8,
  29384. udieresisbelow: 0x1E73,
  29385. udieresiscaron: 0x01DA,
  29386. udieresiscyrillic: 0x04F1,
  29387. udieresisgrave: 0x01DC,
  29388. udieresismacron: 0x01D6,
  29389. udotbelow: 0x1EE5,
  29390. ugrave: 0x00F9,
  29391. ugujarati: 0x0A89,
  29392. ugurmukhi: 0x0A09,
  29393. uhiragana: 0x3046,
  29394. uhookabove: 0x1EE7,
  29395. uhorn: 0x01B0,
  29396. uhornacute: 0x1EE9,
  29397. uhorndotbelow: 0x1EF1,
  29398. uhorngrave: 0x1EEB,
  29399. uhornhookabove: 0x1EED,
  29400. uhorntilde: 0x1EEF,
  29401. uhungarumlaut: 0x0171,
  29402. uhungarumlautcyrillic: 0x04F3,
  29403. uinvertedbreve: 0x0217,
  29404. ukatakana: 0x30A6,
  29405. ukatakanahalfwidth: 0xFF73,
  29406. ukcyrillic: 0x0479,
  29407. ukorean: 0x315C,
  29408. umacron: 0x016B,
  29409. umacroncyrillic: 0x04EF,
  29410. umacrondieresis: 0x1E7B,
  29411. umatragurmukhi: 0x0A41,
  29412. umonospace: 0xFF55,
  29413. underscore: 0x005F,
  29414. underscoredbl: 0x2017,
  29415. underscoremonospace: 0xFF3F,
  29416. underscorevertical: 0xFE33,
  29417. underscorewavy: 0xFE4F,
  29418. union: 0x222A,
  29419. universal: 0x2200,
  29420. uogonek: 0x0173,
  29421. uparen: 0x24B0,
  29422. upblock: 0x2580,
  29423. upperdothebrew: 0x05C4,
  29424. upsilon: 0x03C5,
  29425. upsilondieresis: 0x03CB,
  29426. upsilondieresistonos: 0x03B0,
  29427. upsilonlatin: 0x028A,
  29428. upsilontonos: 0x03CD,
  29429. uptackbelowcmb: 0x031D,
  29430. uptackmod: 0x02D4,
  29431. uragurmukhi: 0x0A73,
  29432. uring: 0x016F,
  29433. ushortcyrillic: 0x045E,
  29434. usmallhiragana: 0x3045,
  29435. usmallkatakana: 0x30A5,
  29436. usmallkatakanahalfwidth: 0xFF69,
  29437. ustraightcyrillic: 0x04AF,
  29438. ustraightstrokecyrillic: 0x04B1,
  29439. utilde: 0x0169,
  29440. utildeacute: 0x1E79,
  29441. utildebelow: 0x1E75,
  29442. uubengali: 0x098A,
  29443. uudeva: 0x090A,
  29444. uugujarati: 0x0A8A,
  29445. uugurmukhi: 0x0A0A,
  29446. uumatragurmukhi: 0x0A42,
  29447. uuvowelsignbengali: 0x09C2,
  29448. uuvowelsigndeva: 0x0942,
  29449. uuvowelsigngujarati: 0x0AC2,
  29450. uvowelsignbengali: 0x09C1,
  29451. uvowelsigndeva: 0x0941,
  29452. uvowelsigngujarati: 0x0AC1,
  29453. v: 0x0076,
  29454. vadeva: 0x0935,
  29455. vagujarati: 0x0AB5,
  29456. vagurmukhi: 0x0A35,
  29457. vakatakana: 0x30F7,
  29458. vav: 0x05D5,
  29459. vavdagesh: 0xFB35,
  29460. vavdagesh65: 0xFB35,
  29461. vavdageshhebrew: 0xFB35,
  29462. vavhebrew: 0x05D5,
  29463. vavholam: 0xFB4B,
  29464. vavholamhebrew: 0xFB4B,
  29465. vavvavhebrew: 0x05F0,
  29466. vavyodhebrew: 0x05F1,
  29467. vcircle: 0x24E5,
  29468. vdotbelow: 0x1E7F,
  29469. vecyrillic: 0x0432,
  29470. veharabic: 0x06A4,
  29471. vehfinalarabic: 0xFB6B,
  29472. vehinitialarabic: 0xFB6C,
  29473. vehmedialarabic: 0xFB6D,
  29474. vekatakana: 0x30F9,
  29475. venus: 0x2640,
  29476. verticalbar: 0x007C,
  29477. verticallineabovecmb: 0x030D,
  29478. verticallinebelowcmb: 0x0329,
  29479. verticallinelowmod: 0x02CC,
  29480. verticallinemod: 0x02C8,
  29481. vewarmenian: 0x057E,
  29482. vhook: 0x028B,
  29483. vikatakana: 0x30F8,
  29484. viramabengali: 0x09CD,
  29485. viramadeva: 0x094D,
  29486. viramagujarati: 0x0ACD,
  29487. visargabengali: 0x0983,
  29488. visargadeva: 0x0903,
  29489. visargagujarati: 0x0A83,
  29490. vmonospace: 0xFF56,
  29491. voarmenian: 0x0578,
  29492. voicediterationhiragana: 0x309E,
  29493. voicediterationkatakana: 0x30FE,
  29494. voicedmarkkana: 0x309B,
  29495. voicedmarkkanahalfwidth: 0xFF9E,
  29496. vokatakana: 0x30FA,
  29497. vparen: 0x24B1,
  29498. vtilde: 0x1E7D,
  29499. vturned: 0x028C,
  29500. vuhiragana: 0x3094,
  29501. vukatakana: 0x30F4,
  29502. w: 0x0077,
  29503. wacute: 0x1E83,
  29504. waekorean: 0x3159,
  29505. wahiragana: 0x308F,
  29506. wakatakana: 0x30EF,
  29507. wakatakanahalfwidth: 0xFF9C,
  29508. wakorean: 0x3158,
  29509. wasmallhiragana: 0x308E,
  29510. wasmallkatakana: 0x30EE,
  29511. wattosquare: 0x3357,
  29512. wavedash: 0x301C,
  29513. wavyunderscorevertical: 0xFE34,
  29514. wawarabic: 0x0648,
  29515. wawfinalarabic: 0xFEEE,
  29516. wawhamzaabovearabic: 0x0624,
  29517. wawhamzaabovefinalarabic: 0xFE86,
  29518. wbsquare: 0x33DD,
  29519. wcircle: 0x24E6,
  29520. wcircumflex: 0x0175,
  29521. wdieresis: 0x1E85,
  29522. wdotaccent: 0x1E87,
  29523. wdotbelow: 0x1E89,
  29524. wehiragana: 0x3091,
  29525. weierstrass: 0x2118,
  29526. wekatakana: 0x30F1,
  29527. wekorean: 0x315E,
  29528. weokorean: 0x315D,
  29529. wgrave: 0x1E81,
  29530. whitebullet: 0x25E6,
  29531. whitecircle: 0x25CB,
  29532. whitecircleinverse: 0x25D9,
  29533. whitecornerbracketleft: 0x300E,
  29534. whitecornerbracketleftvertical: 0xFE43,
  29535. whitecornerbracketright: 0x300F,
  29536. whitecornerbracketrightvertical: 0xFE44,
  29537. whitediamond: 0x25C7,
  29538. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29539. whitedownpointingsmalltriangle: 0x25BF,
  29540. whitedownpointingtriangle: 0x25BD,
  29541. whiteleftpointingsmalltriangle: 0x25C3,
  29542. whiteleftpointingtriangle: 0x25C1,
  29543. whitelenticularbracketleft: 0x3016,
  29544. whitelenticularbracketright: 0x3017,
  29545. whiterightpointingsmalltriangle: 0x25B9,
  29546. whiterightpointingtriangle: 0x25B7,
  29547. whitesmallsquare: 0x25AB,
  29548. whitesmilingface: 0x263A,
  29549. whitesquare: 0x25A1,
  29550. whitestar: 0x2606,
  29551. whitetelephone: 0x260F,
  29552. whitetortoiseshellbracketleft: 0x3018,
  29553. whitetortoiseshellbracketright: 0x3019,
  29554. whiteuppointingsmalltriangle: 0x25B5,
  29555. whiteuppointingtriangle: 0x25B3,
  29556. wihiragana: 0x3090,
  29557. wikatakana: 0x30F0,
  29558. wikorean: 0x315F,
  29559. wmonospace: 0xFF57,
  29560. wohiragana: 0x3092,
  29561. wokatakana: 0x30F2,
  29562. wokatakanahalfwidth: 0xFF66,
  29563. won: 0x20A9,
  29564. wonmonospace: 0xFFE6,
  29565. wowaenthai: 0x0E27,
  29566. wparen: 0x24B2,
  29567. wring: 0x1E98,
  29568. wsuperior: 0x02B7,
  29569. wturned: 0x028D,
  29570. wynn: 0x01BF,
  29571. x: 0x0078,
  29572. xabovecmb: 0x033D,
  29573. xbopomofo: 0x3112,
  29574. xcircle: 0x24E7,
  29575. xdieresis: 0x1E8D,
  29576. xdotaccent: 0x1E8B,
  29577. xeharmenian: 0x056D,
  29578. xi: 0x03BE,
  29579. xmonospace: 0xFF58,
  29580. xparen: 0x24B3,
  29581. xsuperior: 0x02E3,
  29582. y: 0x0079,
  29583. yaadosquare: 0x334E,
  29584. yabengali: 0x09AF,
  29585. yacute: 0x00FD,
  29586. yadeva: 0x092F,
  29587. yaekorean: 0x3152,
  29588. yagujarati: 0x0AAF,
  29589. yagurmukhi: 0x0A2F,
  29590. yahiragana: 0x3084,
  29591. yakatakana: 0x30E4,
  29592. yakatakanahalfwidth: 0xFF94,
  29593. yakorean: 0x3151,
  29594. yamakkanthai: 0x0E4E,
  29595. yasmallhiragana: 0x3083,
  29596. yasmallkatakana: 0x30E3,
  29597. yasmallkatakanahalfwidth: 0xFF6C,
  29598. yatcyrillic: 0x0463,
  29599. ycircle: 0x24E8,
  29600. ycircumflex: 0x0177,
  29601. ydieresis: 0x00FF,
  29602. ydotaccent: 0x1E8F,
  29603. ydotbelow: 0x1EF5,
  29604. yeharabic: 0x064A,
  29605. yehbarreearabic: 0x06D2,
  29606. yehbarreefinalarabic: 0xFBAF,
  29607. yehfinalarabic: 0xFEF2,
  29608. yehhamzaabovearabic: 0x0626,
  29609. yehhamzaabovefinalarabic: 0xFE8A,
  29610. yehhamzaaboveinitialarabic: 0xFE8B,
  29611. yehhamzaabovemedialarabic: 0xFE8C,
  29612. yehinitialarabic: 0xFEF3,
  29613. yehmedialarabic: 0xFEF4,
  29614. yehmeeminitialarabic: 0xFCDD,
  29615. yehmeemisolatedarabic: 0xFC58,
  29616. yehnoonfinalarabic: 0xFC94,
  29617. yehthreedotsbelowarabic: 0x06D1,
  29618. yekorean: 0x3156,
  29619. yen: 0x00A5,
  29620. yenmonospace: 0xFFE5,
  29621. yeokorean: 0x3155,
  29622. yeorinhieuhkorean: 0x3186,
  29623. yerahbenyomohebrew: 0x05AA,
  29624. yerahbenyomolefthebrew: 0x05AA,
  29625. yericyrillic: 0x044B,
  29626. yerudieresiscyrillic: 0x04F9,
  29627. yesieungkorean: 0x3181,
  29628. yesieungpansioskorean: 0x3183,
  29629. yesieungsioskorean: 0x3182,
  29630. yetivhebrew: 0x059A,
  29631. ygrave: 0x1EF3,
  29632. yhook: 0x01B4,
  29633. yhookabove: 0x1EF7,
  29634. yiarmenian: 0x0575,
  29635. yicyrillic: 0x0457,
  29636. yikorean: 0x3162,
  29637. yinyang: 0x262F,
  29638. yiwnarmenian: 0x0582,
  29639. ymonospace: 0xFF59,
  29640. yod: 0x05D9,
  29641. yoddagesh: 0xFB39,
  29642. yoddageshhebrew: 0xFB39,
  29643. yodhebrew: 0x05D9,
  29644. yodyodhebrew: 0x05F2,
  29645. yodyodpatahhebrew: 0xFB1F,
  29646. yohiragana: 0x3088,
  29647. yoikorean: 0x3189,
  29648. yokatakana: 0x30E8,
  29649. yokatakanahalfwidth: 0xFF96,
  29650. yokorean: 0x315B,
  29651. yosmallhiragana: 0x3087,
  29652. yosmallkatakana: 0x30E7,
  29653. yosmallkatakanahalfwidth: 0xFF6E,
  29654. yotgreek: 0x03F3,
  29655. yoyaekorean: 0x3188,
  29656. yoyakorean: 0x3187,
  29657. yoyakthai: 0x0E22,
  29658. yoyingthai: 0x0E0D,
  29659. yparen: 0x24B4,
  29660. ypogegrammeni: 0x037A,
  29661. ypogegrammenigreekcmb: 0x0345,
  29662. yr: 0x01A6,
  29663. yring: 0x1E99,
  29664. ysuperior: 0x02B8,
  29665. ytilde: 0x1EF9,
  29666. yturned: 0x028E,
  29667. yuhiragana: 0x3086,
  29668. yuikorean: 0x318C,
  29669. yukatakana: 0x30E6,
  29670. yukatakanahalfwidth: 0xFF95,
  29671. yukorean: 0x3160,
  29672. yusbigcyrillic: 0x046B,
  29673. yusbigiotifiedcyrillic: 0x046D,
  29674. yuslittlecyrillic: 0x0467,
  29675. yuslittleiotifiedcyrillic: 0x0469,
  29676. yusmallhiragana: 0x3085,
  29677. yusmallkatakana: 0x30E5,
  29678. yusmallkatakanahalfwidth: 0xFF6D,
  29679. yuyekorean: 0x318B,
  29680. yuyeokorean: 0x318A,
  29681. yyabengali: 0x09DF,
  29682. yyadeva: 0x095F,
  29683. z: 0x007A,
  29684. zaarmenian: 0x0566,
  29685. zacute: 0x017A,
  29686. zadeva: 0x095B,
  29687. zagurmukhi: 0x0A5B,
  29688. zaharabic: 0x0638,
  29689. zahfinalarabic: 0xFEC6,
  29690. zahinitialarabic: 0xFEC7,
  29691. zahiragana: 0x3056,
  29692. zahmedialarabic: 0xFEC8,
  29693. zainarabic: 0x0632,
  29694. zainfinalarabic: 0xFEB0,
  29695. zakatakana: 0x30B6,
  29696. zaqefgadolhebrew: 0x0595,
  29697. zaqefqatanhebrew: 0x0594,
  29698. zarqahebrew: 0x0598,
  29699. zayin: 0x05D6,
  29700. zayindagesh: 0xFB36,
  29701. zayindageshhebrew: 0xFB36,
  29702. zayinhebrew: 0x05D6,
  29703. zbopomofo: 0x3117,
  29704. zcaron: 0x017E,
  29705. zcircle: 0x24E9,
  29706. zcircumflex: 0x1E91,
  29707. zcurl: 0x0291,
  29708. zdot: 0x017C,
  29709. zdotaccent: 0x017C,
  29710. zdotbelow: 0x1E93,
  29711. zecyrillic: 0x0437,
  29712. zedescendercyrillic: 0x0499,
  29713. zedieresiscyrillic: 0x04DF,
  29714. zehiragana: 0x305C,
  29715. zekatakana: 0x30BC,
  29716. zero: 0x0030,
  29717. zeroarabic: 0x0660,
  29718. zerobengali: 0x09E6,
  29719. zerodeva: 0x0966,
  29720. zerogujarati: 0x0AE6,
  29721. zerogurmukhi: 0x0A66,
  29722. zerohackarabic: 0x0660,
  29723. zeroinferior: 0x2080,
  29724. zeromonospace: 0xFF10,
  29725. zerooldstyle: 0xF730,
  29726. zeropersian: 0x06F0,
  29727. zerosuperior: 0x2070,
  29728. zerothai: 0x0E50,
  29729. zerowidthjoiner: 0xFEFF,
  29730. zerowidthnonjoiner: 0x200C,
  29731. zerowidthspace: 0x200B,
  29732. zeta: 0x03B6,
  29733. zhbopomofo: 0x3113,
  29734. zhearmenian: 0x056A,
  29735. zhebrevecyrillic: 0x04C2,
  29736. zhecyrillic: 0x0436,
  29737. zhedescendercyrillic: 0x0497,
  29738. zhedieresiscyrillic: 0x04DD,
  29739. zihiragana: 0x3058,
  29740. zikatakana: 0x30B8,
  29741. zinorhebrew: 0x05AE,
  29742. zlinebelow: 0x1E95,
  29743. zmonospace: 0xFF5A,
  29744. zohiragana: 0x305E,
  29745. zokatakana: 0x30BE,
  29746. zparen: 0x24B5,
  29747. zretroflexhook: 0x0290,
  29748. zstroke: 0x01B6,
  29749. zuhiragana: 0x305A,
  29750. zukatakana: 0x30BA,
  29751. '.notdef': 0x0000
  29752. };
  29753. var DingbatsGlyphsUnicode = {
  29754. space: 0x0020,
  29755. a1: 0x2701,
  29756. a2: 0x2702,
  29757. a202: 0x2703,
  29758. a3: 0x2704,
  29759. a4: 0x260E,
  29760. a5: 0x2706,
  29761. a119: 0x2707,
  29762. a118: 0x2708,
  29763. a117: 0x2709,
  29764. a11: 0x261B,
  29765. a12: 0x261E,
  29766. a13: 0x270C,
  29767. a14: 0x270D,
  29768. a15: 0x270E,
  29769. a16: 0x270F,
  29770. a105: 0x2710,
  29771. a17: 0x2711,
  29772. a18: 0x2712,
  29773. a19: 0x2713,
  29774. a20: 0x2714,
  29775. a21: 0x2715,
  29776. a22: 0x2716,
  29777. a23: 0x2717,
  29778. a24: 0x2718,
  29779. a25: 0x2719,
  29780. a26: 0x271A,
  29781. a27: 0x271B,
  29782. a28: 0x271C,
  29783. a6: 0x271D,
  29784. a7: 0x271E,
  29785. a8: 0x271F,
  29786. a9: 0x2720,
  29787. a10: 0x2721,
  29788. a29: 0x2722,
  29789. a30: 0x2723,
  29790. a31: 0x2724,
  29791. a32: 0x2725,
  29792. a33: 0x2726,
  29793. a34: 0x2727,
  29794. a35: 0x2605,
  29795. a36: 0x2729,
  29796. a37: 0x272A,
  29797. a38: 0x272B,
  29798. a39: 0x272C,
  29799. a40: 0x272D,
  29800. a41: 0x272E,
  29801. a42: 0x272F,
  29802. a43: 0x2730,
  29803. a44: 0x2731,
  29804. a45: 0x2732,
  29805. a46: 0x2733,
  29806. a47: 0x2734,
  29807. a48: 0x2735,
  29808. a49: 0x2736,
  29809. a50: 0x2737,
  29810. a51: 0x2738,
  29811. a52: 0x2739,
  29812. a53: 0x273A,
  29813. a54: 0x273B,
  29814. a55: 0x273C,
  29815. a56: 0x273D,
  29816. a57: 0x273E,
  29817. a58: 0x273F,
  29818. a59: 0x2740,
  29819. a60: 0x2741,
  29820. a61: 0x2742,
  29821. a62: 0x2743,
  29822. a63: 0x2744,
  29823. a64: 0x2745,
  29824. a65: 0x2746,
  29825. a66: 0x2747,
  29826. a67: 0x2748,
  29827. a68: 0x2749,
  29828. a69: 0x274A,
  29829. a70: 0x274B,
  29830. a71: 0x25CF,
  29831. a72: 0x274D,
  29832. a73: 0x25A0,
  29833. a74: 0x274F,
  29834. a203: 0x2750,
  29835. a75: 0x2751,
  29836. a204: 0x2752,
  29837. a76: 0x25B2,
  29838. a77: 0x25BC,
  29839. a78: 0x25C6,
  29840. a79: 0x2756,
  29841. a81: 0x25D7,
  29842. a82: 0x2758,
  29843. a83: 0x2759,
  29844. a84: 0x275A,
  29845. a97: 0x275B,
  29846. a98: 0x275C,
  29847. a99: 0x275D,
  29848. a100: 0x275E,
  29849. a101: 0x2761,
  29850. a102: 0x2762,
  29851. a103: 0x2763,
  29852. a104: 0x2764,
  29853. a106: 0x2765,
  29854. a107: 0x2766,
  29855. a108: 0x2767,
  29856. a112: 0x2663,
  29857. a111: 0x2666,
  29858. a110: 0x2665,
  29859. a109: 0x2660,
  29860. a120: 0x2460,
  29861. a121: 0x2461,
  29862. a122: 0x2462,
  29863. a123: 0x2463,
  29864. a124: 0x2464,
  29865. a125: 0x2465,
  29866. a126: 0x2466,
  29867. a127: 0x2467,
  29868. a128: 0x2468,
  29869. a129: 0x2469,
  29870. a130: 0x2776,
  29871. a131: 0x2777,
  29872. a132: 0x2778,
  29873. a133: 0x2779,
  29874. a134: 0x277A,
  29875. a135: 0x277B,
  29876. a136: 0x277C,
  29877. a137: 0x277D,
  29878. a138: 0x277E,
  29879. a139: 0x277F,
  29880. a140: 0x2780,
  29881. a141: 0x2781,
  29882. a142: 0x2782,
  29883. a143: 0x2783,
  29884. a144: 0x2784,
  29885. a145: 0x2785,
  29886. a146: 0x2786,
  29887. a147: 0x2787,
  29888. a148: 0x2788,
  29889. a149: 0x2789,
  29890. a150: 0x278A,
  29891. a151: 0x278B,
  29892. a152: 0x278C,
  29893. a153: 0x278D,
  29894. a154: 0x278E,
  29895. a155: 0x278F,
  29896. a156: 0x2790,
  29897. a157: 0x2791,
  29898. a158: 0x2792,
  29899. a159: 0x2793,
  29900. a160: 0x2794,
  29901. a161: 0x2192,
  29902. a163: 0x2194,
  29903. a164: 0x2195,
  29904. a196: 0x2798,
  29905. a165: 0x2799,
  29906. a192: 0x279A,
  29907. a166: 0x279B,
  29908. a167: 0x279C,
  29909. a168: 0x279D,
  29910. a169: 0x279E,
  29911. a170: 0x279F,
  29912. a171: 0x27A0,
  29913. a172: 0x27A1,
  29914. a173: 0x27A2,
  29915. a162: 0x27A3,
  29916. a174: 0x27A4,
  29917. a175: 0x27A5,
  29918. a176: 0x27A6,
  29919. a177: 0x27A7,
  29920. a178: 0x27A8,
  29921. a179: 0x27A9,
  29922. a193: 0x27AA,
  29923. a180: 0x27AB,
  29924. a199: 0x27AC,
  29925. a181: 0x27AD,
  29926. a200: 0x27AE,
  29927. a182: 0x27AF,
  29928. a201: 0x27B1,
  29929. a183: 0x27B2,
  29930. a184: 0x27B3,
  29931. a197: 0x27B4,
  29932. a185: 0x27B5,
  29933. a194: 0x27B6,
  29934. a198: 0x27B7,
  29935. a186: 0x27B8,
  29936. a195: 0x27B9,
  29937. a187: 0x27BA,
  29938. a188: 0x27BB,
  29939. a189: 0x27BC,
  29940. a190: 0x27BD,
  29941. a191: 0x27BE,
  29942. a89: 0x2768, // 0xF8D7
  29943. a90: 0x2769, // 0xF8D8
  29944. a93: 0x276A, // 0xF8D9
  29945. a94: 0x276B, // 0xF8DA
  29946. a91: 0x276C, // 0xF8DB
  29947. a92: 0x276D, // 0xF8DC
  29948. a205: 0x276E, // 0xF8DD
  29949. a85: 0x276F, // 0xF8DE
  29950. a206: 0x2770, // 0xF8DF
  29951. a86: 0x2771, // 0xF8E0
  29952. a87: 0x2772, // 0xF8E1
  29953. a88: 0x2773, // 0xF8E2
  29954. a95: 0x2774, // 0xF8E3
  29955. a96: 0x2775, // 0xF8E4
  29956. '.notdef': 0x0000
  29957. };
  29958. var PDFImage = (function PDFImageClosure() {
  29959. /**
  29960. * Decode the image in the main thread if it supported. Resovles the promise
  29961. * when the image data is ready.
  29962. */
  29963. function handleImageData(handler, xref, res, image) {
  29964. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  29965. // For natively supported jpegs send them to the main thread for decoding.
  29966. var dict = image.dict;
  29967. var colorSpace = dict.get('ColorSpace', 'CS');
  29968. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  29969. var numComps = colorSpace.numComps;
  29970. var decodePromise = handler.sendWithPromise('JpegDecode',
  29971. [image.getIR(), numComps]);
  29972. return decodePromise.then(function (message) {
  29973. var data = message.data;
  29974. return new Stream(data, 0, data.length, image.dict);
  29975. });
  29976. } else {
  29977. return Promise.resolve(image);
  29978. }
  29979. }
  29980. /**
  29981. * Decode and clamp a value. The formula is different from the spec because we
  29982. * don't decode to float range [0,1], we decode it in the [0,max] range.
  29983. */
  29984. function decodeAndClamp(value, addend, coefficient, max) {
  29985. value = addend + value * coefficient;
  29986. // Clamp the value to the range
  29987. return (value < 0 ? 0 : (value > max ? max : value));
  29988. }
  29989. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  29990. this.image = image;
  29991. var dict = image.dict;
  29992. if (dict.has('Filter')) {
  29993. var filter = dict.get('Filter').name;
  29994. if (filter === 'JPXDecode') {
  29995. var jpxImage = new JpxImage();
  29996. jpxImage.parseImageProperties(image.stream);
  29997. image.stream.reset();
  29998. image.bitsPerComponent = jpxImage.bitsPerComponent;
  29999. image.numComps = jpxImage.componentsCount;
  30000. } else if (filter === 'JBIG2Decode') {
  30001. image.bitsPerComponent = 1;
  30002. image.numComps = 1;
  30003. }
  30004. }
  30005. // TODO cache rendered images?
  30006. this.width = dict.get('Width', 'W');
  30007. this.height = dict.get('Height', 'H');
  30008. if (this.width < 1 || this.height < 1) {
  30009. error('Invalid image width: ' + this.width + ' or height: ' +
  30010. this.height);
  30011. }
  30012. this.interpolate = dict.get('Interpolate', 'I') || false;
  30013. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30014. this.matte = dict.get('Matte') || false;
  30015. var bitsPerComponent = image.bitsPerComponent;
  30016. if (!bitsPerComponent) {
  30017. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30018. if (!bitsPerComponent) {
  30019. if (this.imageMask) {
  30020. bitsPerComponent = 1;
  30021. } else {
  30022. error('Bits per component missing in image: ' + this.imageMask);
  30023. }
  30024. }
  30025. }
  30026. this.bpc = bitsPerComponent;
  30027. if (!this.imageMask) {
  30028. var colorSpace = dict.get('ColorSpace', 'CS');
  30029. if (!colorSpace) {
  30030. info('JPX images (which do not require color spaces)');
  30031. switch (image.numComps) {
  30032. case 1:
  30033. colorSpace = Name.get('DeviceGray');
  30034. break;
  30035. case 3:
  30036. colorSpace = Name.get('DeviceRGB');
  30037. break;
  30038. case 4:
  30039. colorSpace = Name.get('DeviceCMYK');
  30040. break;
  30041. default:
  30042. error('JPX images with ' + this.numComps +
  30043. ' color components not supported.');
  30044. }
  30045. }
  30046. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30047. this.numComps = this.colorSpace.numComps;
  30048. }
  30049. this.decode = dict.get('Decode', 'D');
  30050. this.needsDecode = false;
  30051. if (this.decode &&
  30052. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30053. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30054. this.needsDecode = true;
  30055. // Do some preprocessing to avoid more math.
  30056. var max = (1 << bitsPerComponent) - 1;
  30057. this.decodeCoefficients = [];
  30058. this.decodeAddends = [];
  30059. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30060. var dmin = this.decode[i];
  30061. var dmax = this.decode[i + 1];
  30062. this.decodeCoefficients[j] = dmax - dmin;
  30063. this.decodeAddends[j] = max * dmin;
  30064. }
  30065. }
  30066. if (smask) {
  30067. this.smask = new PDFImage(xref, res, smask, false);
  30068. } else if (mask) {
  30069. if (isStream(mask)) {
  30070. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30071. } else {
  30072. // Color key mask (just an array).
  30073. this.mask = mask;
  30074. }
  30075. }
  30076. }
  30077. /**
  30078. * Handles processing of image data and returns the Promise that is resolved
  30079. * with a PDFImage when the image is ready to be used.
  30080. */
  30081. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30082. res, image, inline) {
  30083. var imagePromise = handleImageData(handler, xref, res, image);
  30084. var smaskPromise;
  30085. var maskPromise;
  30086. var smask = image.dict.get('SMask');
  30087. var mask = image.dict.get('Mask');
  30088. if (smask) {
  30089. smaskPromise = handleImageData(handler, xref, res, smask);
  30090. maskPromise = Promise.resolve(null);
  30091. } else {
  30092. smaskPromise = Promise.resolve(null);
  30093. if (mask) {
  30094. if (isStream(mask)) {
  30095. maskPromise = handleImageData(handler, xref, res, mask);
  30096. } else if (isArray(mask)) {
  30097. maskPromise = Promise.resolve(mask);
  30098. } else {
  30099. warn('Unsupported mask format.');
  30100. maskPromise = Promise.resolve(null);
  30101. }
  30102. } else {
  30103. maskPromise = Promise.resolve(null);
  30104. }
  30105. }
  30106. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30107. function(results) {
  30108. var imageData = results[0];
  30109. var smaskData = results[1];
  30110. var maskData = results[2];
  30111. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30112. });
  30113. };
  30114. /**
  30115. * Resize an image using the nearest neighbor algorithm. Currently only
  30116. * supports one and three component images.
  30117. * @param {TypedArray} pixels The original image with one component.
  30118. * @param {Number} bpc Number of bits per component.
  30119. * @param {Number} components Number of color components, 1 or 3 is supported.
  30120. * @param {Number} w1 Original width.
  30121. * @param {Number} h1 Original height.
  30122. * @param {Number} w2 New width.
  30123. * @param {Number} h2 New height.
  30124. * @param {TypedArray} dest (Optional) The destination buffer.
  30125. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30126. * @return {TypedArray} Resized image data.
  30127. */
  30128. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30129. w1, h1, w2, h2, dest, alpha01) {
  30130. if (components !== 1 && components !== 3) {
  30131. error('Unsupported component count for resizing.');
  30132. }
  30133. var length = w2 * h2 * components;
  30134. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30135. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30136. var xRatio = w1 / w2;
  30137. var yRatio = h1 / h2;
  30138. var i, j, py, newIndex = 0, oldIndex;
  30139. var xScaled = new Uint16Array(w2);
  30140. var w1Scanline = w1 * components;
  30141. if (alpha01 !== 1) {
  30142. alpha01 = 0;
  30143. }
  30144. for (j = 0; j < w2; j++) {
  30145. xScaled[j] = Math.floor(j * xRatio) * components;
  30146. }
  30147. if (components === 1) {
  30148. for (i = 0; i < h2; i++) {
  30149. py = Math.floor(i * yRatio) * w1Scanline;
  30150. for (j = 0; j < w2; j++) {
  30151. oldIndex = py + xScaled[j];
  30152. temp[newIndex++] = pixels[oldIndex];
  30153. }
  30154. }
  30155. } else if (components === 3) {
  30156. for (i = 0; i < h2; i++) {
  30157. py = Math.floor(i * yRatio) * w1Scanline;
  30158. for (j = 0; j < w2; j++) {
  30159. oldIndex = py + xScaled[j];
  30160. temp[newIndex++] = pixels[oldIndex++];
  30161. temp[newIndex++] = pixels[oldIndex++];
  30162. temp[newIndex++] = pixels[oldIndex++];
  30163. newIndex += alpha01;
  30164. }
  30165. }
  30166. }
  30167. return temp;
  30168. };
  30169. PDFImage.createMask =
  30170. function PDFImage_createMask(imgArray, width, height,
  30171. imageIsFromDecodeStream, inverseDecode) {
  30172. // |imgArray| might not contain full data for every pixel of the mask, so
  30173. // we need to distinguish between |computedLength| and |actualLength|.
  30174. // In particular, if inverseDecode is true, then the array we return must
  30175. // have a length of |computedLength|.
  30176. var computedLength = ((width + 7) >> 3) * height;
  30177. var actualLength = imgArray.byteLength;
  30178. var haveFullData = computedLength === actualLength;
  30179. var data, i;
  30180. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30181. // imgArray came from a DecodeStream and its data is in an appropriate
  30182. // form, so we can just transfer it.
  30183. data = imgArray;
  30184. } else if (!inverseDecode) {
  30185. data = new Uint8Array(actualLength);
  30186. data.set(imgArray);
  30187. } else {
  30188. data = new Uint8Array(computedLength);
  30189. data.set(imgArray);
  30190. for (i = actualLength; i < computedLength; i++) {
  30191. data[i] = 0xff;
  30192. }
  30193. }
  30194. // If necessary, invert the original mask data (but not any extra we might
  30195. // have added above). It's safe to modify the array -- whether it's the
  30196. // original or a copy, we're about to transfer it anyway, so nothing else
  30197. // in this thread can be relying on its contents.
  30198. if (inverseDecode) {
  30199. for (i = 0; i < actualLength; i++) {
  30200. data[i] = ~data[i];
  30201. }
  30202. }
  30203. return {data: data, width: width, height: height};
  30204. };
  30205. PDFImage.prototype = {
  30206. get drawWidth() {
  30207. return Math.max(this.width,
  30208. this.smask && this.smask.width || 0,
  30209. this.mask && this.mask.width || 0);
  30210. },
  30211. get drawHeight() {
  30212. return Math.max(this.height,
  30213. this.smask && this.smask.height || 0,
  30214. this.mask && this.mask.height || 0);
  30215. },
  30216. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30217. var bpc = this.bpc;
  30218. var numComps = this.numComps;
  30219. var decodeAddends = this.decodeAddends;
  30220. var decodeCoefficients = this.decodeCoefficients;
  30221. var max = (1 << bpc) - 1;
  30222. var i, ii;
  30223. if (bpc === 1) {
  30224. // If the buffer needed decode that means it just needs to be inverted.
  30225. for (i = 0, ii = buffer.length; i < ii; i++) {
  30226. buffer[i] = +!(buffer[i]);
  30227. }
  30228. return;
  30229. }
  30230. var index = 0;
  30231. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30232. for (var j = 0; j < numComps; j++) {
  30233. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30234. decodeCoefficients[j], max);
  30235. index++;
  30236. }
  30237. }
  30238. },
  30239. getComponents: function PDFImage_getComponents(buffer) {
  30240. var bpc = this.bpc;
  30241. // This image doesn't require any extra work.
  30242. if (bpc === 8) {
  30243. return buffer;
  30244. }
  30245. var width = this.width;
  30246. var height = this.height;
  30247. var numComps = this.numComps;
  30248. var length = width * height * numComps;
  30249. var bufferPos = 0;
  30250. var output = (bpc <= 8 ? new Uint8Array(length) :
  30251. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30252. var rowComps = width * numComps;
  30253. var max = (1 << bpc) - 1;
  30254. var i = 0, ii, buf;
  30255. if (bpc === 1) {
  30256. // Optimization for reading 1 bpc images.
  30257. var mask, loop1End, loop2End;
  30258. for (var j = 0; j < height; j++) {
  30259. loop1End = i + (rowComps & ~7);
  30260. loop2End = i + rowComps;
  30261. // unroll loop for all full bytes
  30262. while (i < loop1End) {
  30263. buf = buffer[bufferPos++];
  30264. output[i] = (buf >> 7) & 1;
  30265. output[i + 1] = (buf >> 6) & 1;
  30266. output[i + 2] = (buf >> 5) & 1;
  30267. output[i + 3] = (buf >> 4) & 1;
  30268. output[i + 4] = (buf >> 3) & 1;
  30269. output[i + 5] = (buf >> 2) & 1;
  30270. output[i + 6] = (buf >> 1) & 1;
  30271. output[i + 7] = buf & 1;
  30272. i += 8;
  30273. }
  30274. // handle remaing bits
  30275. if (i < loop2End) {
  30276. buf = buffer[bufferPos++];
  30277. mask = 128;
  30278. while (i < loop2End) {
  30279. output[i++] = +!!(buf & mask);
  30280. mask >>= 1;
  30281. }
  30282. }
  30283. }
  30284. } else {
  30285. // The general case that handles all other bpc values.
  30286. var bits = 0;
  30287. buf = 0;
  30288. for (i = 0, ii = length; i < ii; ++i) {
  30289. if (i % rowComps === 0) {
  30290. buf = 0;
  30291. bits = 0;
  30292. }
  30293. while (bits < bpc) {
  30294. buf = (buf << 8) | buffer[bufferPos++];
  30295. bits += 8;
  30296. }
  30297. var remainingBits = bits - bpc;
  30298. var value = buf >> remainingBits;
  30299. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30300. buf = buf & ((1 << remainingBits) - 1);
  30301. bits = remainingBits;
  30302. }
  30303. }
  30304. return output;
  30305. },
  30306. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30307. actualHeight, image) {
  30308. var smask = this.smask;
  30309. var mask = this.mask;
  30310. var alphaBuf, sw, sh, i, ii, j;
  30311. if (smask) {
  30312. sw = smask.width;
  30313. sh = smask.height;
  30314. alphaBuf = new Uint8Array(sw * sh);
  30315. smask.fillGrayBuffer(alphaBuf);
  30316. if (sw !== width || sh !== height) {
  30317. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30318. height);
  30319. }
  30320. } else if (mask) {
  30321. if (mask instanceof PDFImage) {
  30322. sw = mask.width;
  30323. sh = mask.height;
  30324. alphaBuf = new Uint8Array(sw * sh);
  30325. mask.numComps = 1;
  30326. mask.fillGrayBuffer(alphaBuf);
  30327. // Need to invert values in rgbaBuf
  30328. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30329. alphaBuf[i] = 255 - alphaBuf[i];
  30330. }
  30331. if (sw !== width || sh !== height) {
  30332. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30333. height);
  30334. }
  30335. } else if (isArray(mask)) {
  30336. // Color key mask: if any of the compontents are outside the range
  30337. // then they should be painted.
  30338. alphaBuf = new Uint8Array(width * height);
  30339. var numComps = this.numComps;
  30340. for (i = 0, ii = width * height; i < ii; ++i) {
  30341. var opacity = 0;
  30342. var imageOffset = i * numComps;
  30343. for (j = 0; j < numComps; ++j) {
  30344. var color = image[imageOffset + j];
  30345. var maskOffset = j * 2;
  30346. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30347. opacity = 255;
  30348. break;
  30349. }
  30350. }
  30351. alphaBuf[i] = opacity;
  30352. }
  30353. } else {
  30354. error('Unknown mask format.');
  30355. }
  30356. }
  30357. if (alphaBuf) {
  30358. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30359. rgbaBuf[j] = alphaBuf[i];
  30360. }
  30361. } else {
  30362. // No mask.
  30363. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30364. rgbaBuf[j] = 255;
  30365. }
  30366. }
  30367. },
  30368. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30369. var matte = this.smask && this.smask.matte;
  30370. if (!matte) {
  30371. return;
  30372. }
  30373. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30374. var matteR = matteRgb[0];
  30375. var matteG = matteRgb[1];
  30376. var matteB = matteRgb[2];
  30377. var length = width * height * 4;
  30378. var r, g, b;
  30379. for (var i = 0; i < length; i += 4) {
  30380. var alpha = buffer[i + 3];
  30381. if (alpha === 0) {
  30382. // according formula we have to get Infinity in all components
  30383. // making it white (typical paper color) should be okay
  30384. buffer[i] = 255;
  30385. buffer[i + 1] = 255;
  30386. buffer[i + 2] = 255;
  30387. continue;
  30388. }
  30389. var k = 255 / alpha;
  30390. r = (buffer[i] - matteR) * k + matteR;
  30391. g = (buffer[i + 1] - matteG) * k + matteG;
  30392. b = (buffer[i + 2] - matteB) * k + matteB;
  30393. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30394. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30395. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30396. }
  30397. },
  30398. createImageData: function PDFImage_createImageData(forceRGBA) {
  30399. var drawWidth = this.drawWidth;
  30400. var drawHeight = this.drawHeight;
  30401. var imgData = { // other fields are filled in below
  30402. width: drawWidth,
  30403. height: drawHeight
  30404. };
  30405. var numComps = this.numComps;
  30406. var originalWidth = this.width;
  30407. var originalHeight = this.height;
  30408. var bpc = this.bpc;
  30409. // Rows start at byte boundary.
  30410. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30411. var imgArray;
  30412. if (!forceRGBA) {
  30413. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30414. // without any complications, we pass a same-sized copy to the main
  30415. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30416. // of memory for many scanned documents. It's also much faster.
  30417. //
  30418. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30419. // complications, we avoid expanding by 1.333x to RGBA form.
  30420. var kind;
  30421. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30422. kind = ImageKind.GRAYSCALE_1BPP;
  30423. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30424. !this.needsDecode) {
  30425. kind = ImageKind.RGB_24BPP;
  30426. }
  30427. if (kind && !this.smask && !this.mask &&
  30428. drawWidth === originalWidth && drawHeight === originalHeight) {
  30429. imgData.kind = kind;
  30430. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30431. // If imgArray came from a DecodeStream, we're safe to transfer it
  30432. // (and thus neuter it) because it will constitute the entire
  30433. // DecodeStream's data. But if it came from a Stream, we need to
  30434. // copy it because it'll only be a portion of the Stream's data, and
  30435. // the rest will be read later on.
  30436. if (this.image instanceof DecodeStream) {
  30437. imgData.data = imgArray;
  30438. } else {
  30439. var newArray = new Uint8Array(imgArray.length);
  30440. newArray.set(imgArray);
  30441. imgData.data = newArray;
  30442. }
  30443. if (this.needsDecode) {
  30444. // Invert the buffer (which must be grayscale if we reached here).
  30445. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30446. var buffer = imgData.data;
  30447. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30448. buffer[i] ^= 0xff;
  30449. }
  30450. }
  30451. return imgData;
  30452. }
  30453. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30454. imgData.kind = ImageKind.RGB_24BPP;
  30455. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30456. drawWidth, drawHeight, true);
  30457. return imgData;
  30458. }
  30459. }
  30460. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30461. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30462. var actualHeight = 0 | (imgArray.length / rowBytes *
  30463. drawHeight / originalHeight);
  30464. var comps = this.getComponents(imgArray);
  30465. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30466. // more compact RGB_24BPP form if allowable.
  30467. var alpha01, maybeUndoPreblend;
  30468. if (!forceRGBA && !this.smask && !this.mask) {
  30469. imgData.kind = ImageKind.RGB_24BPP;
  30470. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30471. alpha01 = 0;
  30472. maybeUndoPreblend = false;
  30473. } else {
  30474. imgData.kind = ImageKind.RGBA_32BPP;
  30475. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30476. alpha01 = 1;
  30477. maybeUndoPreblend = true;
  30478. // Color key masking (opacity) must be performed before decoding.
  30479. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30480. comps);
  30481. }
  30482. if (this.needsDecode) {
  30483. this.decodeBuffer(comps);
  30484. }
  30485. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30486. drawWidth, drawHeight, actualHeight, bpc, comps,
  30487. alpha01);
  30488. if (maybeUndoPreblend) {
  30489. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30490. }
  30491. return imgData;
  30492. },
  30493. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30494. var numComps = this.numComps;
  30495. if (numComps !== 1) {
  30496. error('Reading gray scale from a color image: ' + numComps);
  30497. }
  30498. var width = this.width;
  30499. var height = this.height;
  30500. var bpc = this.bpc;
  30501. // rows start at byte boundary
  30502. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30503. var imgArray = this.getImageBytes(height * rowBytes);
  30504. var comps = this.getComponents(imgArray);
  30505. var i, length;
  30506. if (bpc === 1) {
  30507. // inline decoding (= inversion) for 1 bpc images
  30508. length = width * height;
  30509. if (this.needsDecode) {
  30510. // invert and scale to {0, 255}
  30511. for (i = 0; i < length; ++i) {
  30512. buffer[i] = (comps[i] - 1) & 255;
  30513. }
  30514. } else {
  30515. // scale to {0, 255}
  30516. for (i = 0; i < length; ++i) {
  30517. buffer[i] = (-comps[i]) & 255;
  30518. }
  30519. }
  30520. return;
  30521. }
  30522. if (this.needsDecode) {
  30523. this.decodeBuffer(comps);
  30524. }
  30525. length = width * height;
  30526. // we aren't using a colorspace so we need to scale the value
  30527. var scale = 255 / ((1 << bpc) - 1);
  30528. for (i = 0; i < length; ++i) {
  30529. buffer[i] = (scale * comps[i]) | 0;
  30530. }
  30531. },
  30532. getImageBytes: function PDFImage_getImageBytes(length,
  30533. drawWidth, drawHeight,
  30534. forceRGB) {
  30535. this.image.reset();
  30536. this.image.drawWidth = drawWidth || this.width;
  30537. this.image.drawHeight = drawHeight || this.height;
  30538. this.image.forceRGB = !!forceRGB;
  30539. return this.image.getBytes(length);
  30540. }
  30541. };
  30542. return PDFImage;
  30543. })();
  30544. // The Metrics object contains glyph widths (in glyph space units).
  30545. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  30546. // space unit corresponds to 1/1000th of text space unit.
  30547. var Metrics = {
  30548. 'Courier': 600,
  30549. 'Courier-Bold': 600,
  30550. 'Courier-BoldOblique': 600,
  30551. 'Courier-Oblique': 600,
  30552. 'Helvetica' : {
  30553. 'space': 278,
  30554. 'exclam': 278,
  30555. 'quotedbl': 355,
  30556. 'numbersign': 556,
  30557. 'dollar': 556,
  30558. 'percent': 889,
  30559. 'ampersand': 667,
  30560. 'quoteright': 222,
  30561. 'parenleft': 333,
  30562. 'parenright': 333,
  30563. 'asterisk': 389,
  30564. 'plus': 584,
  30565. 'comma': 278,
  30566. 'hyphen': 333,
  30567. 'period': 278,
  30568. 'slash': 278,
  30569. 'zero': 556,
  30570. 'one': 556,
  30571. 'two': 556,
  30572. 'three': 556,
  30573. 'four': 556,
  30574. 'five': 556,
  30575. 'six': 556,
  30576. 'seven': 556,
  30577. 'eight': 556,
  30578. 'nine': 556,
  30579. 'colon': 278,
  30580. 'semicolon': 278,
  30581. 'less': 584,
  30582. 'equal': 584,
  30583. 'greater': 584,
  30584. 'question': 556,
  30585. 'at': 1015,
  30586. 'A': 667,
  30587. 'B': 667,
  30588. 'C': 722,
  30589. 'D': 722,
  30590. 'E': 667,
  30591. 'F': 611,
  30592. 'G': 778,
  30593. 'H': 722,
  30594. 'I': 278,
  30595. 'J': 500,
  30596. 'K': 667,
  30597. 'L': 556,
  30598. 'M': 833,
  30599. 'N': 722,
  30600. 'O': 778,
  30601. 'P': 667,
  30602. 'Q': 778,
  30603. 'R': 722,
  30604. 'S': 667,
  30605. 'T': 611,
  30606. 'U': 722,
  30607. 'V': 667,
  30608. 'W': 944,
  30609. 'X': 667,
  30610. 'Y': 667,
  30611. 'Z': 611,
  30612. 'bracketleft': 278,
  30613. 'backslash': 278,
  30614. 'bracketright': 278,
  30615. 'asciicircum': 469,
  30616. 'underscore': 556,
  30617. 'quoteleft': 222,
  30618. 'a': 556,
  30619. 'b': 556,
  30620. 'c': 500,
  30621. 'd': 556,
  30622. 'e': 556,
  30623. 'f': 278,
  30624. 'g': 556,
  30625. 'h': 556,
  30626. 'i': 222,
  30627. 'j': 222,
  30628. 'k': 500,
  30629. 'l': 222,
  30630. 'm': 833,
  30631. 'n': 556,
  30632. 'o': 556,
  30633. 'p': 556,
  30634. 'q': 556,
  30635. 'r': 333,
  30636. 's': 500,
  30637. 't': 278,
  30638. 'u': 556,
  30639. 'v': 500,
  30640. 'w': 722,
  30641. 'x': 500,
  30642. 'y': 500,
  30643. 'z': 500,
  30644. 'braceleft': 334,
  30645. 'bar': 260,
  30646. 'braceright': 334,
  30647. 'asciitilde': 584,
  30648. 'exclamdown': 333,
  30649. 'cent': 556,
  30650. 'sterling': 556,
  30651. 'fraction': 167,
  30652. 'yen': 556,
  30653. 'florin': 556,
  30654. 'section': 556,
  30655. 'currency': 556,
  30656. 'quotesingle': 191,
  30657. 'quotedblleft': 333,
  30658. 'guillemotleft': 556,
  30659. 'guilsinglleft': 333,
  30660. 'guilsinglright': 333,
  30661. 'fi': 500,
  30662. 'fl': 500,
  30663. 'endash': 556,
  30664. 'dagger': 556,
  30665. 'daggerdbl': 556,
  30666. 'periodcentered': 278,
  30667. 'paragraph': 537,
  30668. 'bullet': 350,
  30669. 'quotesinglbase': 222,
  30670. 'quotedblbase': 333,
  30671. 'quotedblright': 333,
  30672. 'guillemotright': 556,
  30673. 'ellipsis': 1000,
  30674. 'perthousand': 1000,
  30675. 'questiondown': 611,
  30676. 'grave': 333,
  30677. 'acute': 333,
  30678. 'circumflex': 333,
  30679. 'tilde': 333,
  30680. 'macron': 333,
  30681. 'breve': 333,
  30682. 'dotaccent': 333,
  30683. 'dieresis': 333,
  30684. 'ring': 333,
  30685. 'cedilla': 333,
  30686. 'hungarumlaut': 333,
  30687. 'ogonek': 333,
  30688. 'caron': 333,
  30689. 'emdash': 1000,
  30690. 'AE': 1000,
  30691. 'ordfeminine': 370,
  30692. 'Lslash': 556,
  30693. 'Oslash': 778,
  30694. 'OE': 1000,
  30695. 'ordmasculine': 365,
  30696. 'ae': 889,
  30697. 'dotlessi': 278,
  30698. 'lslash': 222,
  30699. 'oslash': 611,
  30700. 'oe': 944,
  30701. 'germandbls': 611,
  30702. 'Idieresis': 278,
  30703. 'eacute': 556,
  30704. 'abreve': 556,
  30705. 'uhungarumlaut': 556,
  30706. 'ecaron': 556,
  30707. 'Ydieresis': 667,
  30708. 'divide': 584,
  30709. 'Yacute': 667,
  30710. 'Acircumflex': 667,
  30711. 'aacute': 556,
  30712. 'Ucircumflex': 722,
  30713. 'yacute': 500,
  30714. 'scommaaccent': 500,
  30715. 'ecircumflex': 556,
  30716. 'Uring': 722,
  30717. 'Udieresis': 722,
  30718. 'aogonek': 556,
  30719. 'Uacute': 722,
  30720. 'uogonek': 556,
  30721. 'Edieresis': 667,
  30722. 'Dcroat': 722,
  30723. 'commaaccent': 250,
  30724. 'copyright': 737,
  30725. 'Emacron': 667,
  30726. 'ccaron': 500,
  30727. 'aring': 556,
  30728. 'Ncommaaccent': 722,
  30729. 'lacute': 222,
  30730. 'agrave': 556,
  30731. 'Tcommaaccent': 611,
  30732. 'Cacute': 722,
  30733. 'atilde': 556,
  30734. 'Edotaccent': 667,
  30735. 'scaron': 500,
  30736. 'scedilla': 500,
  30737. 'iacute': 278,
  30738. 'lozenge': 471,
  30739. 'Rcaron': 722,
  30740. 'Gcommaaccent': 778,
  30741. 'ucircumflex': 556,
  30742. 'acircumflex': 556,
  30743. 'Amacron': 667,
  30744. 'rcaron': 333,
  30745. 'ccedilla': 500,
  30746. 'Zdotaccent': 611,
  30747. 'Thorn': 667,
  30748. 'Omacron': 778,
  30749. 'Racute': 722,
  30750. 'Sacute': 667,
  30751. 'dcaron': 643,
  30752. 'Umacron': 722,
  30753. 'uring': 556,
  30754. 'threesuperior': 333,
  30755. 'Ograve': 778,
  30756. 'Agrave': 667,
  30757. 'Abreve': 667,
  30758. 'multiply': 584,
  30759. 'uacute': 556,
  30760. 'Tcaron': 611,
  30761. 'partialdiff': 476,
  30762. 'ydieresis': 500,
  30763. 'Nacute': 722,
  30764. 'icircumflex': 278,
  30765. 'Ecircumflex': 667,
  30766. 'adieresis': 556,
  30767. 'edieresis': 556,
  30768. 'cacute': 500,
  30769. 'nacute': 556,
  30770. 'umacron': 556,
  30771. 'Ncaron': 722,
  30772. 'Iacute': 278,
  30773. 'plusminus': 584,
  30774. 'brokenbar': 260,
  30775. 'registered': 737,
  30776. 'Gbreve': 778,
  30777. 'Idotaccent': 278,
  30778. 'summation': 600,
  30779. 'Egrave': 667,
  30780. 'racute': 333,
  30781. 'omacron': 556,
  30782. 'Zacute': 611,
  30783. 'Zcaron': 611,
  30784. 'greaterequal': 549,
  30785. 'Eth': 722,
  30786. 'Ccedilla': 722,
  30787. 'lcommaaccent': 222,
  30788. 'tcaron': 317,
  30789. 'eogonek': 556,
  30790. 'Uogonek': 722,
  30791. 'Aacute': 667,
  30792. 'Adieresis': 667,
  30793. 'egrave': 556,
  30794. 'zacute': 500,
  30795. 'iogonek': 222,
  30796. 'Oacute': 778,
  30797. 'oacute': 556,
  30798. 'amacron': 556,
  30799. 'sacute': 500,
  30800. 'idieresis': 278,
  30801. 'Ocircumflex': 778,
  30802. 'Ugrave': 722,
  30803. 'Delta': 612,
  30804. 'thorn': 556,
  30805. 'twosuperior': 333,
  30806. 'Odieresis': 778,
  30807. 'mu': 556,
  30808. 'igrave': 278,
  30809. 'ohungarumlaut': 556,
  30810. 'Eogonek': 667,
  30811. 'dcroat': 556,
  30812. 'threequarters': 834,
  30813. 'Scedilla': 667,
  30814. 'lcaron': 299,
  30815. 'Kcommaaccent': 667,
  30816. 'Lacute': 556,
  30817. 'trademark': 1000,
  30818. 'edotaccent': 556,
  30819. 'Igrave': 278,
  30820. 'Imacron': 278,
  30821. 'Lcaron': 556,
  30822. 'onehalf': 834,
  30823. 'lessequal': 549,
  30824. 'ocircumflex': 556,
  30825. 'ntilde': 556,
  30826. 'Uhungarumlaut': 722,
  30827. 'Eacute': 667,
  30828. 'emacron': 556,
  30829. 'gbreve': 556,
  30830. 'onequarter': 834,
  30831. 'Scaron': 667,
  30832. 'Scommaaccent': 667,
  30833. 'Ohungarumlaut': 778,
  30834. 'degree': 400,
  30835. 'ograve': 556,
  30836. 'Ccaron': 722,
  30837. 'ugrave': 556,
  30838. 'radical': 453,
  30839. 'Dcaron': 722,
  30840. 'rcommaaccent': 333,
  30841. 'Ntilde': 722,
  30842. 'otilde': 556,
  30843. 'Rcommaaccent': 722,
  30844. 'Lcommaaccent': 556,
  30845. 'Atilde': 667,
  30846. 'Aogonek': 667,
  30847. 'Aring': 667,
  30848. 'Otilde': 778,
  30849. 'zdotaccent': 500,
  30850. 'Ecaron': 667,
  30851. 'Iogonek': 278,
  30852. 'kcommaaccent': 500,
  30853. 'minus': 584,
  30854. 'Icircumflex': 278,
  30855. 'ncaron': 556,
  30856. 'tcommaaccent': 278,
  30857. 'logicalnot': 584,
  30858. 'odieresis': 556,
  30859. 'udieresis': 556,
  30860. 'notequal': 549,
  30861. 'gcommaaccent': 556,
  30862. 'eth': 556,
  30863. 'zcaron': 500,
  30864. 'ncommaaccent': 556,
  30865. 'onesuperior': 333,
  30866. 'imacron': 278,
  30867. 'Euro': 556
  30868. },
  30869. 'Helvetica-Bold': {
  30870. 'space': 278,
  30871. 'exclam': 333,
  30872. 'quotedbl': 474,
  30873. 'numbersign': 556,
  30874. 'dollar': 556,
  30875. 'percent': 889,
  30876. 'ampersand': 722,
  30877. 'quoteright': 278,
  30878. 'parenleft': 333,
  30879. 'parenright': 333,
  30880. 'asterisk': 389,
  30881. 'plus': 584,
  30882. 'comma': 278,
  30883. 'hyphen': 333,
  30884. 'period': 278,
  30885. 'slash': 278,
  30886. 'zero': 556,
  30887. 'one': 556,
  30888. 'two': 556,
  30889. 'three': 556,
  30890. 'four': 556,
  30891. 'five': 556,
  30892. 'six': 556,
  30893. 'seven': 556,
  30894. 'eight': 556,
  30895. 'nine': 556,
  30896. 'colon': 333,
  30897. 'semicolon': 333,
  30898. 'less': 584,
  30899. 'equal': 584,
  30900. 'greater': 584,
  30901. 'question': 611,
  30902. 'at': 975,
  30903. 'A': 722,
  30904. 'B': 722,
  30905. 'C': 722,
  30906. 'D': 722,
  30907. 'E': 667,
  30908. 'F': 611,
  30909. 'G': 778,
  30910. 'H': 722,
  30911. 'I': 278,
  30912. 'J': 556,
  30913. 'K': 722,
  30914. 'L': 611,
  30915. 'M': 833,
  30916. 'N': 722,
  30917. 'O': 778,
  30918. 'P': 667,
  30919. 'Q': 778,
  30920. 'R': 722,
  30921. 'S': 667,
  30922. 'T': 611,
  30923. 'U': 722,
  30924. 'V': 667,
  30925. 'W': 944,
  30926. 'X': 667,
  30927. 'Y': 667,
  30928. 'Z': 611,
  30929. 'bracketleft': 333,
  30930. 'backslash': 278,
  30931. 'bracketright': 333,
  30932. 'asciicircum': 584,
  30933. 'underscore': 556,
  30934. 'quoteleft': 278,
  30935. 'a': 556,
  30936. 'b': 611,
  30937. 'c': 556,
  30938. 'd': 611,
  30939. 'e': 556,
  30940. 'f': 333,
  30941. 'g': 611,
  30942. 'h': 611,
  30943. 'i': 278,
  30944. 'j': 278,
  30945. 'k': 556,
  30946. 'l': 278,
  30947. 'm': 889,
  30948. 'n': 611,
  30949. 'o': 611,
  30950. 'p': 611,
  30951. 'q': 611,
  30952. 'r': 389,
  30953. 's': 556,
  30954. 't': 333,
  30955. 'u': 611,
  30956. 'v': 556,
  30957. 'w': 778,
  30958. 'x': 556,
  30959. 'y': 556,
  30960. 'z': 500,
  30961. 'braceleft': 389,
  30962. 'bar': 280,
  30963. 'braceright': 389,
  30964. 'asciitilde': 584,
  30965. 'exclamdown': 333,
  30966. 'cent': 556,
  30967. 'sterling': 556,
  30968. 'fraction': 167,
  30969. 'yen': 556,
  30970. 'florin': 556,
  30971. 'section': 556,
  30972. 'currency': 556,
  30973. 'quotesingle': 238,
  30974. 'quotedblleft': 500,
  30975. 'guillemotleft': 556,
  30976. 'guilsinglleft': 333,
  30977. 'guilsinglright': 333,
  30978. 'fi': 611,
  30979. 'fl': 611,
  30980. 'endash': 556,
  30981. 'dagger': 556,
  30982. 'daggerdbl': 556,
  30983. 'periodcentered': 278,
  30984. 'paragraph': 556,
  30985. 'bullet': 350,
  30986. 'quotesinglbase': 278,
  30987. 'quotedblbase': 500,
  30988. 'quotedblright': 500,
  30989. 'guillemotright': 556,
  30990. 'ellipsis': 1000,
  30991. 'perthousand': 1000,
  30992. 'questiondown': 611,
  30993. 'grave': 333,
  30994. 'acute': 333,
  30995. 'circumflex': 333,
  30996. 'tilde': 333,
  30997. 'macron': 333,
  30998. 'breve': 333,
  30999. 'dotaccent': 333,
  31000. 'dieresis': 333,
  31001. 'ring': 333,
  31002. 'cedilla': 333,
  31003. 'hungarumlaut': 333,
  31004. 'ogonek': 333,
  31005. 'caron': 333,
  31006. 'emdash': 1000,
  31007. 'AE': 1000,
  31008. 'ordfeminine': 370,
  31009. 'Lslash': 611,
  31010. 'Oslash': 778,
  31011. 'OE': 1000,
  31012. 'ordmasculine': 365,
  31013. 'ae': 889,
  31014. 'dotlessi': 278,
  31015. 'lslash': 278,
  31016. 'oslash': 611,
  31017. 'oe': 944,
  31018. 'germandbls': 611,
  31019. 'Idieresis': 278,
  31020. 'eacute': 556,
  31021. 'abreve': 556,
  31022. 'uhungarumlaut': 611,
  31023. 'ecaron': 556,
  31024. 'Ydieresis': 667,
  31025. 'divide': 584,
  31026. 'Yacute': 667,
  31027. 'Acircumflex': 722,
  31028. 'aacute': 556,
  31029. 'Ucircumflex': 722,
  31030. 'yacute': 556,
  31031. 'scommaaccent': 556,
  31032. 'ecircumflex': 556,
  31033. 'Uring': 722,
  31034. 'Udieresis': 722,
  31035. 'aogonek': 556,
  31036. 'Uacute': 722,
  31037. 'uogonek': 611,
  31038. 'Edieresis': 667,
  31039. 'Dcroat': 722,
  31040. 'commaaccent': 250,
  31041. 'copyright': 737,
  31042. 'Emacron': 667,
  31043. 'ccaron': 556,
  31044. 'aring': 556,
  31045. 'Ncommaaccent': 722,
  31046. 'lacute': 278,
  31047. 'agrave': 556,
  31048. 'Tcommaaccent': 611,
  31049. 'Cacute': 722,
  31050. 'atilde': 556,
  31051. 'Edotaccent': 667,
  31052. 'scaron': 556,
  31053. 'scedilla': 556,
  31054. 'iacute': 278,
  31055. 'lozenge': 494,
  31056. 'Rcaron': 722,
  31057. 'Gcommaaccent': 778,
  31058. 'ucircumflex': 611,
  31059. 'acircumflex': 556,
  31060. 'Amacron': 722,
  31061. 'rcaron': 389,
  31062. 'ccedilla': 556,
  31063. 'Zdotaccent': 611,
  31064. 'Thorn': 667,
  31065. 'Omacron': 778,
  31066. 'Racute': 722,
  31067. 'Sacute': 667,
  31068. 'dcaron': 743,
  31069. 'Umacron': 722,
  31070. 'uring': 611,
  31071. 'threesuperior': 333,
  31072. 'Ograve': 778,
  31073. 'Agrave': 722,
  31074. 'Abreve': 722,
  31075. 'multiply': 584,
  31076. 'uacute': 611,
  31077. 'Tcaron': 611,
  31078. 'partialdiff': 494,
  31079. 'ydieresis': 556,
  31080. 'Nacute': 722,
  31081. 'icircumflex': 278,
  31082. 'Ecircumflex': 667,
  31083. 'adieresis': 556,
  31084. 'edieresis': 556,
  31085. 'cacute': 556,
  31086. 'nacute': 611,
  31087. 'umacron': 611,
  31088. 'Ncaron': 722,
  31089. 'Iacute': 278,
  31090. 'plusminus': 584,
  31091. 'brokenbar': 280,
  31092. 'registered': 737,
  31093. 'Gbreve': 778,
  31094. 'Idotaccent': 278,
  31095. 'summation': 600,
  31096. 'Egrave': 667,
  31097. 'racute': 389,
  31098. 'omacron': 611,
  31099. 'Zacute': 611,
  31100. 'Zcaron': 611,
  31101. 'greaterequal': 549,
  31102. 'Eth': 722,
  31103. 'Ccedilla': 722,
  31104. 'lcommaaccent': 278,
  31105. 'tcaron': 389,
  31106. 'eogonek': 556,
  31107. 'Uogonek': 722,
  31108. 'Aacute': 722,
  31109. 'Adieresis': 722,
  31110. 'egrave': 556,
  31111. 'zacute': 500,
  31112. 'iogonek': 278,
  31113. 'Oacute': 778,
  31114. 'oacute': 611,
  31115. 'amacron': 556,
  31116. 'sacute': 556,
  31117. 'idieresis': 278,
  31118. 'Ocircumflex': 778,
  31119. 'Ugrave': 722,
  31120. 'Delta': 612,
  31121. 'thorn': 611,
  31122. 'twosuperior': 333,
  31123. 'Odieresis': 778,
  31124. 'mu': 611,
  31125. 'igrave': 278,
  31126. 'ohungarumlaut': 611,
  31127. 'Eogonek': 667,
  31128. 'dcroat': 611,
  31129. 'threequarters': 834,
  31130. 'Scedilla': 667,
  31131. 'lcaron': 400,
  31132. 'Kcommaaccent': 722,
  31133. 'Lacute': 611,
  31134. 'trademark': 1000,
  31135. 'edotaccent': 556,
  31136. 'Igrave': 278,
  31137. 'Imacron': 278,
  31138. 'Lcaron': 611,
  31139. 'onehalf': 834,
  31140. 'lessequal': 549,
  31141. 'ocircumflex': 611,
  31142. 'ntilde': 611,
  31143. 'Uhungarumlaut': 722,
  31144. 'Eacute': 667,
  31145. 'emacron': 556,
  31146. 'gbreve': 611,
  31147. 'onequarter': 834,
  31148. 'Scaron': 667,
  31149. 'Scommaaccent': 667,
  31150. 'Ohungarumlaut': 778,
  31151. 'degree': 400,
  31152. 'ograve': 611,
  31153. 'Ccaron': 722,
  31154. 'ugrave': 611,
  31155. 'radical': 549,
  31156. 'Dcaron': 722,
  31157. 'rcommaaccent': 389,
  31158. 'Ntilde': 722,
  31159. 'otilde': 611,
  31160. 'Rcommaaccent': 722,
  31161. 'Lcommaaccent': 611,
  31162. 'Atilde': 722,
  31163. 'Aogonek': 722,
  31164. 'Aring': 722,
  31165. 'Otilde': 778,
  31166. 'zdotaccent': 500,
  31167. 'Ecaron': 667,
  31168. 'Iogonek': 278,
  31169. 'kcommaaccent': 556,
  31170. 'minus': 584,
  31171. 'Icircumflex': 278,
  31172. 'ncaron': 611,
  31173. 'tcommaaccent': 333,
  31174. 'logicalnot': 584,
  31175. 'odieresis': 611,
  31176. 'udieresis': 611,
  31177. 'notequal': 549,
  31178. 'gcommaaccent': 611,
  31179. 'eth': 611,
  31180. 'zcaron': 500,
  31181. 'ncommaaccent': 611,
  31182. 'onesuperior': 333,
  31183. 'imacron': 278,
  31184. 'Euro': 556
  31185. },
  31186. 'Helvetica-BoldOblique': {
  31187. 'space': 278,
  31188. 'exclam': 333,
  31189. 'quotedbl': 474,
  31190. 'numbersign': 556,
  31191. 'dollar': 556,
  31192. 'percent': 889,
  31193. 'ampersand': 722,
  31194. 'quoteright': 278,
  31195. 'parenleft': 333,
  31196. 'parenright': 333,
  31197. 'asterisk': 389,
  31198. 'plus': 584,
  31199. 'comma': 278,
  31200. 'hyphen': 333,
  31201. 'period': 278,
  31202. 'slash': 278,
  31203. 'zero': 556,
  31204. 'one': 556,
  31205. 'two': 556,
  31206. 'three': 556,
  31207. 'four': 556,
  31208. 'five': 556,
  31209. 'six': 556,
  31210. 'seven': 556,
  31211. 'eight': 556,
  31212. 'nine': 556,
  31213. 'colon': 333,
  31214. 'semicolon': 333,
  31215. 'less': 584,
  31216. 'equal': 584,
  31217. 'greater': 584,
  31218. 'question': 611,
  31219. 'at': 975,
  31220. 'A': 722,
  31221. 'B': 722,
  31222. 'C': 722,
  31223. 'D': 722,
  31224. 'E': 667,
  31225. 'F': 611,
  31226. 'G': 778,
  31227. 'H': 722,
  31228. 'I': 278,
  31229. 'J': 556,
  31230. 'K': 722,
  31231. 'L': 611,
  31232. 'M': 833,
  31233. 'N': 722,
  31234. 'O': 778,
  31235. 'P': 667,
  31236. 'Q': 778,
  31237. 'R': 722,
  31238. 'S': 667,
  31239. 'T': 611,
  31240. 'U': 722,
  31241. 'V': 667,
  31242. 'W': 944,
  31243. 'X': 667,
  31244. 'Y': 667,
  31245. 'Z': 611,
  31246. 'bracketleft': 333,
  31247. 'backslash': 278,
  31248. 'bracketright': 333,
  31249. 'asciicircum': 584,
  31250. 'underscore': 556,
  31251. 'quoteleft': 278,
  31252. 'a': 556,
  31253. 'b': 611,
  31254. 'c': 556,
  31255. 'd': 611,
  31256. 'e': 556,
  31257. 'f': 333,
  31258. 'g': 611,
  31259. 'h': 611,
  31260. 'i': 278,
  31261. 'j': 278,
  31262. 'k': 556,
  31263. 'l': 278,
  31264. 'm': 889,
  31265. 'n': 611,
  31266. 'o': 611,
  31267. 'p': 611,
  31268. 'q': 611,
  31269. 'r': 389,
  31270. 's': 556,
  31271. 't': 333,
  31272. 'u': 611,
  31273. 'v': 556,
  31274. 'w': 778,
  31275. 'x': 556,
  31276. 'y': 556,
  31277. 'z': 500,
  31278. 'braceleft': 389,
  31279. 'bar': 280,
  31280. 'braceright': 389,
  31281. 'asciitilde': 584,
  31282. 'exclamdown': 333,
  31283. 'cent': 556,
  31284. 'sterling': 556,
  31285. 'fraction': 167,
  31286. 'yen': 556,
  31287. 'florin': 556,
  31288. 'section': 556,
  31289. 'currency': 556,
  31290. 'quotesingle': 238,
  31291. 'quotedblleft': 500,
  31292. 'guillemotleft': 556,
  31293. 'guilsinglleft': 333,
  31294. 'guilsinglright': 333,
  31295. 'fi': 611,
  31296. 'fl': 611,
  31297. 'endash': 556,
  31298. 'dagger': 556,
  31299. 'daggerdbl': 556,
  31300. 'periodcentered': 278,
  31301. 'paragraph': 556,
  31302. 'bullet': 350,
  31303. 'quotesinglbase': 278,
  31304. 'quotedblbase': 500,
  31305. 'quotedblright': 500,
  31306. 'guillemotright': 556,
  31307. 'ellipsis': 1000,
  31308. 'perthousand': 1000,
  31309. 'questiondown': 611,
  31310. 'grave': 333,
  31311. 'acute': 333,
  31312. 'circumflex': 333,
  31313. 'tilde': 333,
  31314. 'macron': 333,
  31315. 'breve': 333,
  31316. 'dotaccent': 333,
  31317. 'dieresis': 333,
  31318. 'ring': 333,
  31319. 'cedilla': 333,
  31320. 'hungarumlaut': 333,
  31321. 'ogonek': 333,
  31322. 'caron': 333,
  31323. 'emdash': 1000,
  31324. 'AE': 1000,
  31325. 'ordfeminine': 370,
  31326. 'Lslash': 611,
  31327. 'Oslash': 778,
  31328. 'OE': 1000,
  31329. 'ordmasculine': 365,
  31330. 'ae': 889,
  31331. 'dotlessi': 278,
  31332. 'lslash': 278,
  31333. 'oslash': 611,
  31334. 'oe': 944,
  31335. 'germandbls': 611,
  31336. 'Idieresis': 278,
  31337. 'eacute': 556,
  31338. 'abreve': 556,
  31339. 'uhungarumlaut': 611,
  31340. 'ecaron': 556,
  31341. 'Ydieresis': 667,
  31342. 'divide': 584,
  31343. 'Yacute': 667,
  31344. 'Acircumflex': 722,
  31345. 'aacute': 556,
  31346. 'Ucircumflex': 722,
  31347. 'yacute': 556,
  31348. 'scommaaccent': 556,
  31349. 'ecircumflex': 556,
  31350. 'Uring': 722,
  31351. 'Udieresis': 722,
  31352. 'aogonek': 556,
  31353. 'Uacute': 722,
  31354. 'uogonek': 611,
  31355. 'Edieresis': 667,
  31356. 'Dcroat': 722,
  31357. 'commaaccent': 250,
  31358. 'copyright': 737,
  31359. 'Emacron': 667,
  31360. 'ccaron': 556,
  31361. 'aring': 556,
  31362. 'Ncommaaccent': 722,
  31363. 'lacute': 278,
  31364. 'agrave': 556,
  31365. 'Tcommaaccent': 611,
  31366. 'Cacute': 722,
  31367. 'atilde': 556,
  31368. 'Edotaccent': 667,
  31369. 'scaron': 556,
  31370. 'scedilla': 556,
  31371. 'iacute': 278,
  31372. 'lozenge': 494,
  31373. 'Rcaron': 722,
  31374. 'Gcommaaccent': 778,
  31375. 'ucircumflex': 611,
  31376. 'acircumflex': 556,
  31377. 'Amacron': 722,
  31378. 'rcaron': 389,
  31379. 'ccedilla': 556,
  31380. 'Zdotaccent': 611,
  31381. 'Thorn': 667,
  31382. 'Omacron': 778,
  31383. 'Racute': 722,
  31384. 'Sacute': 667,
  31385. 'dcaron': 743,
  31386. 'Umacron': 722,
  31387. 'uring': 611,
  31388. 'threesuperior': 333,
  31389. 'Ograve': 778,
  31390. 'Agrave': 722,
  31391. 'Abreve': 722,
  31392. 'multiply': 584,
  31393. 'uacute': 611,
  31394. 'Tcaron': 611,
  31395. 'partialdiff': 494,
  31396. 'ydieresis': 556,
  31397. 'Nacute': 722,
  31398. 'icircumflex': 278,
  31399. 'Ecircumflex': 667,
  31400. 'adieresis': 556,
  31401. 'edieresis': 556,
  31402. 'cacute': 556,
  31403. 'nacute': 611,
  31404. 'umacron': 611,
  31405. 'Ncaron': 722,
  31406. 'Iacute': 278,
  31407. 'plusminus': 584,
  31408. 'brokenbar': 280,
  31409. 'registered': 737,
  31410. 'Gbreve': 778,
  31411. 'Idotaccent': 278,
  31412. 'summation': 600,
  31413. 'Egrave': 667,
  31414. 'racute': 389,
  31415. 'omacron': 611,
  31416. 'Zacute': 611,
  31417. 'Zcaron': 611,
  31418. 'greaterequal': 549,
  31419. 'Eth': 722,
  31420. 'Ccedilla': 722,
  31421. 'lcommaaccent': 278,
  31422. 'tcaron': 389,
  31423. 'eogonek': 556,
  31424. 'Uogonek': 722,
  31425. 'Aacute': 722,
  31426. 'Adieresis': 722,
  31427. 'egrave': 556,
  31428. 'zacute': 500,
  31429. 'iogonek': 278,
  31430. 'Oacute': 778,
  31431. 'oacute': 611,
  31432. 'amacron': 556,
  31433. 'sacute': 556,
  31434. 'idieresis': 278,
  31435. 'Ocircumflex': 778,
  31436. 'Ugrave': 722,
  31437. 'Delta': 612,
  31438. 'thorn': 611,
  31439. 'twosuperior': 333,
  31440. 'Odieresis': 778,
  31441. 'mu': 611,
  31442. 'igrave': 278,
  31443. 'ohungarumlaut': 611,
  31444. 'Eogonek': 667,
  31445. 'dcroat': 611,
  31446. 'threequarters': 834,
  31447. 'Scedilla': 667,
  31448. 'lcaron': 400,
  31449. 'Kcommaaccent': 722,
  31450. 'Lacute': 611,
  31451. 'trademark': 1000,
  31452. 'edotaccent': 556,
  31453. 'Igrave': 278,
  31454. 'Imacron': 278,
  31455. 'Lcaron': 611,
  31456. 'onehalf': 834,
  31457. 'lessequal': 549,
  31458. 'ocircumflex': 611,
  31459. 'ntilde': 611,
  31460. 'Uhungarumlaut': 722,
  31461. 'Eacute': 667,
  31462. 'emacron': 556,
  31463. 'gbreve': 611,
  31464. 'onequarter': 834,
  31465. 'Scaron': 667,
  31466. 'Scommaaccent': 667,
  31467. 'Ohungarumlaut': 778,
  31468. 'degree': 400,
  31469. 'ograve': 611,
  31470. 'Ccaron': 722,
  31471. 'ugrave': 611,
  31472. 'radical': 549,
  31473. 'Dcaron': 722,
  31474. 'rcommaaccent': 389,
  31475. 'Ntilde': 722,
  31476. 'otilde': 611,
  31477. 'Rcommaaccent': 722,
  31478. 'Lcommaaccent': 611,
  31479. 'Atilde': 722,
  31480. 'Aogonek': 722,
  31481. 'Aring': 722,
  31482. 'Otilde': 778,
  31483. 'zdotaccent': 500,
  31484. 'Ecaron': 667,
  31485. 'Iogonek': 278,
  31486. 'kcommaaccent': 556,
  31487. 'minus': 584,
  31488. 'Icircumflex': 278,
  31489. 'ncaron': 611,
  31490. 'tcommaaccent': 333,
  31491. 'logicalnot': 584,
  31492. 'odieresis': 611,
  31493. 'udieresis': 611,
  31494. 'notequal': 549,
  31495. 'gcommaaccent': 611,
  31496. 'eth': 611,
  31497. 'zcaron': 500,
  31498. 'ncommaaccent': 611,
  31499. 'onesuperior': 333,
  31500. 'imacron': 278,
  31501. 'Euro': 556
  31502. },
  31503. 'Helvetica-Oblique' : {
  31504. 'space': 278,
  31505. 'exclam': 278,
  31506. 'quotedbl': 355,
  31507. 'numbersign': 556,
  31508. 'dollar': 556,
  31509. 'percent': 889,
  31510. 'ampersand': 667,
  31511. 'quoteright': 222,
  31512. 'parenleft': 333,
  31513. 'parenright': 333,
  31514. 'asterisk': 389,
  31515. 'plus': 584,
  31516. 'comma': 278,
  31517. 'hyphen': 333,
  31518. 'period': 278,
  31519. 'slash': 278,
  31520. 'zero': 556,
  31521. 'one': 556,
  31522. 'two': 556,
  31523. 'three': 556,
  31524. 'four': 556,
  31525. 'five': 556,
  31526. 'six': 556,
  31527. 'seven': 556,
  31528. 'eight': 556,
  31529. 'nine': 556,
  31530. 'colon': 278,
  31531. 'semicolon': 278,
  31532. 'less': 584,
  31533. 'equal': 584,
  31534. 'greater': 584,
  31535. 'question': 556,
  31536. 'at': 1015,
  31537. 'A': 667,
  31538. 'B': 667,
  31539. 'C': 722,
  31540. 'D': 722,
  31541. 'E': 667,
  31542. 'F': 611,
  31543. 'G': 778,
  31544. 'H': 722,
  31545. 'I': 278,
  31546. 'J': 500,
  31547. 'K': 667,
  31548. 'L': 556,
  31549. 'M': 833,
  31550. 'N': 722,
  31551. 'O': 778,
  31552. 'P': 667,
  31553. 'Q': 778,
  31554. 'R': 722,
  31555. 'S': 667,
  31556. 'T': 611,
  31557. 'U': 722,
  31558. 'V': 667,
  31559. 'W': 944,
  31560. 'X': 667,
  31561. 'Y': 667,
  31562. 'Z': 611,
  31563. 'bracketleft': 278,
  31564. 'backslash': 278,
  31565. 'bracketright': 278,
  31566. 'asciicircum': 469,
  31567. 'underscore': 556,
  31568. 'quoteleft': 222,
  31569. 'a': 556,
  31570. 'b': 556,
  31571. 'c': 500,
  31572. 'd': 556,
  31573. 'e': 556,
  31574. 'f': 278,
  31575. 'g': 556,
  31576. 'h': 556,
  31577. 'i': 222,
  31578. 'j': 222,
  31579. 'k': 500,
  31580. 'l': 222,
  31581. 'm': 833,
  31582. 'n': 556,
  31583. 'o': 556,
  31584. 'p': 556,
  31585. 'q': 556,
  31586. 'r': 333,
  31587. 's': 500,
  31588. 't': 278,
  31589. 'u': 556,
  31590. 'v': 500,
  31591. 'w': 722,
  31592. 'x': 500,
  31593. 'y': 500,
  31594. 'z': 500,
  31595. 'braceleft': 334,
  31596. 'bar': 260,
  31597. 'braceright': 334,
  31598. 'asciitilde': 584,
  31599. 'exclamdown': 333,
  31600. 'cent': 556,
  31601. 'sterling': 556,
  31602. 'fraction': 167,
  31603. 'yen': 556,
  31604. 'florin': 556,
  31605. 'section': 556,
  31606. 'currency': 556,
  31607. 'quotesingle': 191,
  31608. 'quotedblleft': 333,
  31609. 'guillemotleft': 556,
  31610. 'guilsinglleft': 333,
  31611. 'guilsinglright': 333,
  31612. 'fi': 500,
  31613. 'fl': 500,
  31614. 'endash': 556,
  31615. 'dagger': 556,
  31616. 'daggerdbl': 556,
  31617. 'periodcentered': 278,
  31618. 'paragraph': 537,
  31619. 'bullet': 350,
  31620. 'quotesinglbase': 222,
  31621. 'quotedblbase': 333,
  31622. 'quotedblright': 333,
  31623. 'guillemotright': 556,
  31624. 'ellipsis': 1000,
  31625. 'perthousand': 1000,
  31626. 'questiondown': 611,
  31627. 'grave': 333,
  31628. 'acute': 333,
  31629. 'circumflex': 333,
  31630. 'tilde': 333,
  31631. 'macron': 333,
  31632. 'breve': 333,
  31633. 'dotaccent': 333,
  31634. 'dieresis': 333,
  31635. 'ring': 333,
  31636. 'cedilla': 333,
  31637. 'hungarumlaut': 333,
  31638. 'ogonek': 333,
  31639. 'caron': 333,
  31640. 'emdash': 1000,
  31641. 'AE': 1000,
  31642. 'ordfeminine': 370,
  31643. 'Lslash': 556,
  31644. 'Oslash': 778,
  31645. 'OE': 1000,
  31646. 'ordmasculine': 365,
  31647. 'ae': 889,
  31648. 'dotlessi': 278,
  31649. 'lslash': 222,
  31650. 'oslash': 611,
  31651. 'oe': 944,
  31652. 'germandbls': 611,
  31653. 'Idieresis': 278,
  31654. 'eacute': 556,
  31655. 'abreve': 556,
  31656. 'uhungarumlaut': 556,
  31657. 'ecaron': 556,
  31658. 'Ydieresis': 667,
  31659. 'divide': 584,
  31660. 'Yacute': 667,
  31661. 'Acircumflex': 667,
  31662. 'aacute': 556,
  31663. 'Ucircumflex': 722,
  31664. 'yacute': 500,
  31665. 'scommaaccent': 500,
  31666. 'ecircumflex': 556,
  31667. 'Uring': 722,
  31668. 'Udieresis': 722,
  31669. 'aogonek': 556,
  31670. 'Uacute': 722,
  31671. 'uogonek': 556,
  31672. 'Edieresis': 667,
  31673. 'Dcroat': 722,
  31674. 'commaaccent': 250,
  31675. 'copyright': 737,
  31676. 'Emacron': 667,
  31677. 'ccaron': 500,
  31678. 'aring': 556,
  31679. 'Ncommaaccent': 722,
  31680. 'lacute': 222,
  31681. 'agrave': 556,
  31682. 'Tcommaaccent': 611,
  31683. 'Cacute': 722,
  31684. 'atilde': 556,
  31685. 'Edotaccent': 667,
  31686. 'scaron': 500,
  31687. 'scedilla': 500,
  31688. 'iacute': 278,
  31689. 'lozenge': 471,
  31690. 'Rcaron': 722,
  31691. 'Gcommaaccent': 778,
  31692. 'ucircumflex': 556,
  31693. 'acircumflex': 556,
  31694. 'Amacron': 667,
  31695. 'rcaron': 333,
  31696. 'ccedilla': 500,
  31697. 'Zdotaccent': 611,
  31698. 'Thorn': 667,
  31699. 'Omacron': 778,
  31700. 'Racute': 722,
  31701. 'Sacute': 667,
  31702. 'dcaron': 643,
  31703. 'Umacron': 722,
  31704. 'uring': 556,
  31705. 'threesuperior': 333,
  31706. 'Ograve': 778,
  31707. 'Agrave': 667,
  31708. 'Abreve': 667,
  31709. 'multiply': 584,
  31710. 'uacute': 556,
  31711. 'Tcaron': 611,
  31712. 'partialdiff': 476,
  31713. 'ydieresis': 500,
  31714. 'Nacute': 722,
  31715. 'icircumflex': 278,
  31716. 'Ecircumflex': 667,
  31717. 'adieresis': 556,
  31718. 'edieresis': 556,
  31719. 'cacute': 500,
  31720. 'nacute': 556,
  31721. 'umacron': 556,
  31722. 'Ncaron': 722,
  31723. 'Iacute': 278,
  31724. 'plusminus': 584,
  31725. 'brokenbar': 260,
  31726. 'registered': 737,
  31727. 'Gbreve': 778,
  31728. 'Idotaccent': 278,
  31729. 'summation': 600,
  31730. 'Egrave': 667,
  31731. 'racute': 333,
  31732. 'omacron': 556,
  31733. 'Zacute': 611,
  31734. 'Zcaron': 611,
  31735. 'greaterequal': 549,
  31736. 'Eth': 722,
  31737. 'Ccedilla': 722,
  31738. 'lcommaaccent': 222,
  31739. 'tcaron': 317,
  31740. 'eogonek': 556,
  31741. 'Uogonek': 722,
  31742. 'Aacute': 667,
  31743. 'Adieresis': 667,
  31744. 'egrave': 556,
  31745. 'zacute': 500,
  31746. 'iogonek': 222,
  31747. 'Oacute': 778,
  31748. 'oacute': 556,
  31749. 'amacron': 556,
  31750. 'sacute': 500,
  31751. 'idieresis': 278,
  31752. 'Ocircumflex': 778,
  31753. 'Ugrave': 722,
  31754. 'Delta': 612,
  31755. 'thorn': 556,
  31756. 'twosuperior': 333,
  31757. 'Odieresis': 778,
  31758. 'mu': 556,
  31759. 'igrave': 278,
  31760. 'ohungarumlaut': 556,
  31761. 'Eogonek': 667,
  31762. 'dcroat': 556,
  31763. 'threequarters': 834,
  31764. 'Scedilla': 667,
  31765. 'lcaron': 299,
  31766. 'Kcommaaccent': 667,
  31767. 'Lacute': 556,
  31768. 'trademark': 1000,
  31769. 'edotaccent': 556,
  31770. 'Igrave': 278,
  31771. 'Imacron': 278,
  31772. 'Lcaron': 556,
  31773. 'onehalf': 834,
  31774. 'lessequal': 549,
  31775. 'ocircumflex': 556,
  31776. 'ntilde': 556,
  31777. 'Uhungarumlaut': 722,
  31778. 'Eacute': 667,
  31779. 'emacron': 556,
  31780. 'gbreve': 556,
  31781. 'onequarter': 834,
  31782. 'Scaron': 667,
  31783. 'Scommaaccent': 667,
  31784. 'Ohungarumlaut': 778,
  31785. 'degree': 400,
  31786. 'ograve': 556,
  31787. 'Ccaron': 722,
  31788. 'ugrave': 556,
  31789. 'radical': 453,
  31790. 'Dcaron': 722,
  31791. 'rcommaaccent': 333,
  31792. 'Ntilde': 722,
  31793. 'otilde': 556,
  31794. 'Rcommaaccent': 722,
  31795. 'Lcommaaccent': 556,
  31796. 'Atilde': 667,
  31797. 'Aogonek': 667,
  31798. 'Aring': 667,
  31799. 'Otilde': 778,
  31800. 'zdotaccent': 500,
  31801. 'Ecaron': 667,
  31802. 'Iogonek': 278,
  31803. 'kcommaaccent': 500,
  31804. 'minus': 584,
  31805. 'Icircumflex': 278,
  31806. 'ncaron': 556,
  31807. 'tcommaaccent': 278,
  31808. 'logicalnot': 584,
  31809. 'odieresis': 556,
  31810. 'udieresis': 556,
  31811. 'notequal': 549,
  31812. 'gcommaaccent': 556,
  31813. 'eth': 556,
  31814. 'zcaron': 500,
  31815. 'ncommaaccent': 556,
  31816. 'onesuperior': 333,
  31817. 'imacron': 278,
  31818. 'Euro': 556
  31819. },
  31820. 'Symbol': {
  31821. 'space': 250,
  31822. 'exclam': 333,
  31823. 'universal': 713,
  31824. 'numbersign': 500,
  31825. 'existential': 549,
  31826. 'percent': 833,
  31827. 'ampersand': 778,
  31828. 'suchthat': 439,
  31829. 'parenleft': 333,
  31830. 'parenright': 333,
  31831. 'asteriskmath': 500,
  31832. 'plus': 549,
  31833. 'comma': 250,
  31834. 'minus': 549,
  31835. 'period': 250,
  31836. 'slash': 278,
  31837. 'zero': 500,
  31838. 'one': 500,
  31839. 'two': 500,
  31840. 'three': 500,
  31841. 'four': 500,
  31842. 'five': 500,
  31843. 'six': 500,
  31844. 'seven': 500,
  31845. 'eight': 500,
  31846. 'nine': 500,
  31847. 'colon': 278,
  31848. 'semicolon': 278,
  31849. 'less': 549,
  31850. 'equal': 549,
  31851. 'greater': 549,
  31852. 'question': 444,
  31853. 'congruent': 549,
  31854. 'Alpha': 722,
  31855. 'Beta': 667,
  31856. 'Chi': 722,
  31857. 'Delta': 612,
  31858. 'Epsilon': 611,
  31859. 'Phi': 763,
  31860. 'Gamma': 603,
  31861. 'Eta': 722,
  31862. 'Iota': 333,
  31863. 'theta1': 631,
  31864. 'Kappa': 722,
  31865. 'Lambda': 686,
  31866. 'Mu': 889,
  31867. 'Nu': 722,
  31868. 'Omicron': 722,
  31869. 'Pi': 768,
  31870. 'Theta': 741,
  31871. 'Rho': 556,
  31872. 'Sigma': 592,
  31873. 'Tau': 611,
  31874. 'Upsilon': 690,
  31875. 'sigma1': 439,
  31876. 'Omega': 768,
  31877. 'Xi': 645,
  31878. 'Psi': 795,
  31879. 'Zeta': 611,
  31880. 'bracketleft': 333,
  31881. 'therefore': 863,
  31882. 'bracketright': 333,
  31883. 'perpendicular': 658,
  31884. 'underscore': 500,
  31885. 'radicalex': 500,
  31886. 'alpha': 631,
  31887. 'beta': 549,
  31888. 'chi': 549,
  31889. 'delta': 494,
  31890. 'epsilon': 439,
  31891. 'phi': 521,
  31892. 'gamma': 411,
  31893. 'eta': 603,
  31894. 'iota': 329,
  31895. 'phi1': 603,
  31896. 'kappa': 549,
  31897. 'lambda': 549,
  31898. 'mu': 576,
  31899. 'nu': 521,
  31900. 'omicron': 549,
  31901. 'pi': 549,
  31902. 'theta': 521,
  31903. 'rho': 549,
  31904. 'sigma': 603,
  31905. 'tau': 439,
  31906. 'upsilon': 576,
  31907. 'omega1': 713,
  31908. 'omega': 686,
  31909. 'xi': 493,
  31910. 'psi': 686,
  31911. 'zeta': 494,
  31912. 'braceleft': 480,
  31913. 'bar': 200,
  31914. 'braceright': 480,
  31915. 'similar': 549,
  31916. 'Euro': 750,
  31917. 'Upsilon1': 620,
  31918. 'minute': 247,
  31919. 'lessequal': 549,
  31920. 'fraction': 167,
  31921. 'infinity': 713,
  31922. 'florin': 500,
  31923. 'club': 753,
  31924. 'diamond': 753,
  31925. 'heart': 753,
  31926. 'spade': 753,
  31927. 'arrowboth': 1042,
  31928. 'arrowleft': 987,
  31929. 'arrowup': 603,
  31930. 'arrowright': 987,
  31931. 'arrowdown': 603,
  31932. 'degree': 400,
  31933. 'plusminus': 549,
  31934. 'second': 411,
  31935. 'greaterequal': 549,
  31936. 'multiply': 549,
  31937. 'proportional': 713,
  31938. 'partialdiff': 494,
  31939. 'bullet': 460,
  31940. 'divide': 549,
  31941. 'notequal': 549,
  31942. 'equivalence': 549,
  31943. 'approxequal': 549,
  31944. 'ellipsis': 1000,
  31945. 'arrowvertex': 603,
  31946. 'arrowhorizex': 1000,
  31947. 'carriagereturn': 658,
  31948. 'aleph': 823,
  31949. 'Ifraktur': 686,
  31950. 'Rfraktur': 795,
  31951. 'weierstrass': 987,
  31952. 'circlemultiply': 768,
  31953. 'circleplus': 768,
  31954. 'emptyset': 823,
  31955. 'intersection': 768,
  31956. 'union': 768,
  31957. 'propersuperset': 713,
  31958. 'reflexsuperset': 713,
  31959. 'notsubset': 713,
  31960. 'propersubset': 713,
  31961. 'reflexsubset': 713,
  31962. 'element': 713,
  31963. 'notelement': 713,
  31964. 'angle': 768,
  31965. 'gradient': 713,
  31966. 'registerserif': 790,
  31967. 'copyrightserif': 790,
  31968. 'trademarkserif': 890,
  31969. 'product': 823,
  31970. 'radical': 549,
  31971. 'dotmath': 250,
  31972. 'logicalnot': 713,
  31973. 'logicaland': 603,
  31974. 'logicalor': 603,
  31975. 'arrowdblboth': 1042,
  31976. 'arrowdblleft': 987,
  31977. 'arrowdblup': 603,
  31978. 'arrowdblright': 987,
  31979. 'arrowdbldown': 603,
  31980. 'lozenge': 494,
  31981. 'angleleft': 329,
  31982. 'registersans': 790,
  31983. 'copyrightsans': 790,
  31984. 'trademarksans': 786,
  31985. 'summation': 713,
  31986. 'parenlefttp': 384,
  31987. 'parenleftex': 384,
  31988. 'parenleftbt': 384,
  31989. 'bracketlefttp': 384,
  31990. 'bracketleftex': 384,
  31991. 'bracketleftbt': 384,
  31992. 'bracelefttp': 494,
  31993. 'braceleftmid': 494,
  31994. 'braceleftbt': 494,
  31995. 'braceex': 494,
  31996. 'angleright': 329,
  31997. 'integral': 274,
  31998. 'integraltp': 686,
  31999. 'integralex': 686,
  32000. 'integralbt': 686,
  32001. 'parenrighttp': 384,
  32002. 'parenrightex': 384,
  32003. 'parenrightbt': 384,
  32004. 'bracketrighttp': 384,
  32005. 'bracketrightex': 384,
  32006. 'bracketrightbt': 384,
  32007. 'bracerighttp': 494,
  32008. 'bracerightmid': 494,
  32009. 'bracerightbt': 494,
  32010. 'apple': 790
  32011. },
  32012. 'Times-Roman': {
  32013. 'space': 250,
  32014. 'exclam': 333,
  32015. 'quotedbl': 408,
  32016. 'numbersign': 500,
  32017. 'dollar': 500,
  32018. 'percent': 833,
  32019. 'ampersand': 778,
  32020. 'quoteright': 333,
  32021. 'parenleft': 333,
  32022. 'parenright': 333,
  32023. 'asterisk': 500,
  32024. 'plus': 564,
  32025. 'comma': 250,
  32026. 'hyphen': 333,
  32027. 'period': 250,
  32028. 'slash': 278,
  32029. 'zero': 500,
  32030. 'one': 500,
  32031. 'two': 500,
  32032. 'three': 500,
  32033. 'four': 500,
  32034. 'five': 500,
  32035. 'six': 500,
  32036. 'seven': 500,
  32037. 'eight': 500,
  32038. 'nine': 500,
  32039. 'colon': 278,
  32040. 'semicolon': 278,
  32041. 'less': 564,
  32042. 'equal': 564,
  32043. 'greater': 564,
  32044. 'question': 444,
  32045. 'at': 921,
  32046. 'A': 722,
  32047. 'B': 667,
  32048. 'C': 667,
  32049. 'D': 722,
  32050. 'E': 611,
  32051. 'F': 556,
  32052. 'G': 722,
  32053. 'H': 722,
  32054. 'I': 333,
  32055. 'J': 389,
  32056. 'K': 722,
  32057. 'L': 611,
  32058. 'M': 889,
  32059. 'N': 722,
  32060. 'O': 722,
  32061. 'P': 556,
  32062. 'Q': 722,
  32063. 'R': 667,
  32064. 'S': 556,
  32065. 'T': 611,
  32066. 'U': 722,
  32067. 'V': 722,
  32068. 'W': 944,
  32069. 'X': 722,
  32070. 'Y': 722,
  32071. 'Z': 611,
  32072. 'bracketleft': 333,
  32073. 'backslash': 278,
  32074. 'bracketright': 333,
  32075. 'asciicircum': 469,
  32076. 'underscore': 500,
  32077. 'quoteleft': 333,
  32078. 'a': 444,
  32079. 'b': 500,
  32080. 'c': 444,
  32081. 'd': 500,
  32082. 'e': 444,
  32083. 'f': 333,
  32084. 'g': 500,
  32085. 'h': 500,
  32086. 'i': 278,
  32087. 'j': 278,
  32088. 'k': 500,
  32089. 'l': 278,
  32090. 'm': 778,
  32091. 'n': 500,
  32092. 'o': 500,
  32093. 'p': 500,
  32094. 'q': 500,
  32095. 'r': 333,
  32096. 's': 389,
  32097. 't': 278,
  32098. 'u': 500,
  32099. 'v': 500,
  32100. 'w': 722,
  32101. 'x': 500,
  32102. 'y': 500,
  32103. 'z': 444,
  32104. 'braceleft': 480,
  32105. 'bar': 200,
  32106. 'braceright': 480,
  32107. 'asciitilde': 541,
  32108. 'exclamdown': 333,
  32109. 'cent': 500,
  32110. 'sterling': 500,
  32111. 'fraction': 167,
  32112. 'yen': 500,
  32113. 'florin': 500,
  32114. 'section': 500,
  32115. 'currency': 500,
  32116. 'quotesingle': 180,
  32117. 'quotedblleft': 444,
  32118. 'guillemotleft': 500,
  32119. 'guilsinglleft': 333,
  32120. 'guilsinglright': 333,
  32121. 'fi': 556,
  32122. 'fl': 556,
  32123. 'endash': 500,
  32124. 'dagger': 500,
  32125. 'daggerdbl': 500,
  32126. 'periodcentered': 250,
  32127. 'paragraph': 453,
  32128. 'bullet': 350,
  32129. 'quotesinglbase': 333,
  32130. 'quotedblbase': 444,
  32131. 'quotedblright': 444,
  32132. 'guillemotright': 500,
  32133. 'ellipsis': 1000,
  32134. 'perthousand': 1000,
  32135. 'questiondown': 444,
  32136. 'grave': 333,
  32137. 'acute': 333,
  32138. 'circumflex': 333,
  32139. 'tilde': 333,
  32140. 'macron': 333,
  32141. 'breve': 333,
  32142. 'dotaccent': 333,
  32143. 'dieresis': 333,
  32144. 'ring': 333,
  32145. 'cedilla': 333,
  32146. 'hungarumlaut': 333,
  32147. 'ogonek': 333,
  32148. 'caron': 333,
  32149. 'emdash': 1000,
  32150. 'AE': 889,
  32151. 'ordfeminine': 276,
  32152. 'Lslash': 611,
  32153. 'Oslash': 722,
  32154. 'OE': 889,
  32155. 'ordmasculine': 310,
  32156. 'ae': 667,
  32157. 'dotlessi': 278,
  32158. 'lslash': 278,
  32159. 'oslash': 500,
  32160. 'oe': 722,
  32161. 'germandbls': 500,
  32162. 'Idieresis': 333,
  32163. 'eacute': 444,
  32164. 'abreve': 444,
  32165. 'uhungarumlaut': 500,
  32166. 'ecaron': 444,
  32167. 'Ydieresis': 722,
  32168. 'divide': 564,
  32169. 'Yacute': 722,
  32170. 'Acircumflex': 722,
  32171. 'aacute': 444,
  32172. 'Ucircumflex': 722,
  32173. 'yacute': 500,
  32174. 'scommaaccent': 389,
  32175. 'ecircumflex': 444,
  32176. 'Uring': 722,
  32177. 'Udieresis': 722,
  32178. 'aogonek': 444,
  32179. 'Uacute': 722,
  32180. 'uogonek': 500,
  32181. 'Edieresis': 611,
  32182. 'Dcroat': 722,
  32183. 'commaaccent': 250,
  32184. 'copyright': 760,
  32185. 'Emacron': 611,
  32186. 'ccaron': 444,
  32187. 'aring': 444,
  32188. 'Ncommaaccent': 722,
  32189. 'lacute': 278,
  32190. 'agrave': 444,
  32191. 'Tcommaaccent': 611,
  32192. 'Cacute': 667,
  32193. 'atilde': 444,
  32194. 'Edotaccent': 611,
  32195. 'scaron': 389,
  32196. 'scedilla': 389,
  32197. 'iacute': 278,
  32198. 'lozenge': 471,
  32199. 'Rcaron': 667,
  32200. 'Gcommaaccent': 722,
  32201. 'ucircumflex': 500,
  32202. 'acircumflex': 444,
  32203. 'Amacron': 722,
  32204. 'rcaron': 333,
  32205. 'ccedilla': 444,
  32206. 'Zdotaccent': 611,
  32207. 'Thorn': 556,
  32208. 'Omacron': 722,
  32209. 'Racute': 667,
  32210. 'Sacute': 556,
  32211. 'dcaron': 588,
  32212. 'Umacron': 722,
  32213. 'uring': 500,
  32214. 'threesuperior': 300,
  32215. 'Ograve': 722,
  32216. 'Agrave': 722,
  32217. 'Abreve': 722,
  32218. 'multiply': 564,
  32219. 'uacute': 500,
  32220. 'Tcaron': 611,
  32221. 'partialdiff': 476,
  32222. 'ydieresis': 500,
  32223. 'Nacute': 722,
  32224. 'icircumflex': 278,
  32225. 'Ecircumflex': 611,
  32226. 'adieresis': 444,
  32227. 'edieresis': 444,
  32228. 'cacute': 444,
  32229. 'nacute': 500,
  32230. 'umacron': 500,
  32231. 'Ncaron': 722,
  32232. 'Iacute': 333,
  32233. 'plusminus': 564,
  32234. 'brokenbar': 200,
  32235. 'registered': 760,
  32236. 'Gbreve': 722,
  32237. 'Idotaccent': 333,
  32238. 'summation': 600,
  32239. 'Egrave': 611,
  32240. 'racute': 333,
  32241. 'omacron': 500,
  32242. 'Zacute': 611,
  32243. 'Zcaron': 611,
  32244. 'greaterequal': 549,
  32245. 'Eth': 722,
  32246. 'Ccedilla': 667,
  32247. 'lcommaaccent': 278,
  32248. 'tcaron': 326,
  32249. 'eogonek': 444,
  32250. 'Uogonek': 722,
  32251. 'Aacute': 722,
  32252. 'Adieresis': 722,
  32253. 'egrave': 444,
  32254. 'zacute': 444,
  32255. 'iogonek': 278,
  32256. 'Oacute': 722,
  32257. 'oacute': 500,
  32258. 'amacron': 444,
  32259. 'sacute': 389,
  32260. 'idieresis': 278,
  32261. 'Ocircumflex': 722,
  32262. 'Ugrave': 722,
  32263. 'Delta': 612,
  32264. 'thorn': 500,
  32265. 'twosuperior': 300,
  32266. 'Odieresis': 722,
  32267. 'mu': 500,
  32268. 'igrave': 278,
  32269. 'ohungarumlaut': 500,
  32270. 'Eogonek': 611,
  32271. 'dcroat': 500,
  32272. 'threequarters': 750,
  32273. 'Scedilla': 556,
  32274. 'lcaron': 344,
  32275. 'Kcommaaccent': 722,
  32276. 'Lacute': 611,
  32277. 'trademark': 980,
  32278. 'edotaccent': 444,
  32279. 'Igrave': 333,
  32280. 'Imacron': 333,
  32281. 'Lcaron': 611,
  32282. 'onehalf': 750,
  32283. 'lessequal': 549,
  32284. 'ocircumflex': 500,
  32285. 'ntilde': 500,
  32286. 'Uhungarumlaut': 722,
  32287. 'Eacute': 611,
  32288. 'emacron': 444,
  32289. 'gbreve': 500,
  32290. 'onequarter': 750,
  32291. 'Scaron': 556,
  32292. 'Scommaaccent': 556,
  32293. 'Ohungarumlaut': 722,
  32294. 'degree': 400,
  32295. 'ograve': 500,
  32296. 'Ccaron': 667,
  32297. 'ugrave': 500,
  32298. 'radical': 453,
  32299. 'Dcaron': 722,
  32300. 'rcommaaccent': 333,
  32301. 'Ntilde': 722,
  32302. 'otilde': 500,
  32303. 'Rcommaaccent': 667,
  32304. 'Lcommaaccent': 611,
  32305. 'Atilde': 722,
  32306. 'Aogonek': 722,
  32307. 'Aring': 722,
  32308. 'Otilde': 722,
  32309. 'zdotaccent': 444,
  32310. 'Ecaron': 611,
  32311. 'Iogonek': 333,
  32312. 'kcommaaccent': 500,
  32313. 'minus': 564,
  32314. 'Icircumflex': 333,
  32315. 'ncaron': 500,
  32316. 'tcommaaccent': 278,
  32317. 'logicalnot': 564,
  32318. 'odieresis': 500,
  32319. 'udieresis': 500,
  32320. 'notequal': 549,
  32321. 'gcommaaccent': 500,
  32322. 'eth': 500,
  32323. 'zcaron': 444,
  32324. 'ncommaaccent': 500,
  32325. 'onesuperior': 300,
  32326. 'imacron': 278,
  32327. 'Euro': 500
  32328. },
  32329. 'Times-Bold': {
  32330. 'space': 250,
  32331. 'exclam': 333,
  32332. 'quotedbl': 555,
  32333. 'numbersign': 500,
  32334. 'dollar': 500,
  32335. 'percent': 1000,
  32336. 'ampersand': 833,
  32337. 'quoteright': 333,
  32338. 'parenleft': 333,
  32339. 'parenright': 333,
  32340. 'asterisk': 500,
  32341. 'plus': 570,
  32342. 'comma': 250,
  32343. 'hyphen': 333,
  32344. 'period': 250,
  32345. 'slash': 278,
  32346. 'zero': 500,
  32347. 'one': 500,
  32348. 'two': 500,
  32349. 'three': 500,
  32350. 'four': 500,
  32351. 'five': 500,
  32352. 'six': 500,
  32353. 'seven': 500,
  32354. 'eight': 500,
  32355. 'nine': 500,
  32356. 'colon': 333,
  32357. 'semicolon': 333,
  32358. 'less': 570,
  32359. 'equal': 570,
  32360. 'greater': 570,
  32361. 'question': 500,
  32362. 'at': 930,
  32363. 'A': 722,
  32364. 'B': 667,
  32365. 'C': 722,
  32366. 'D': 722,
  32367. 'E': 667,
  32368. 'F': 611,
  32369. 'G': 778,
  32370. 'H': 778,
  32371. 'I': 389,
  32372. 'J': 500,
  32373. 'K': 778,
  32374. 'L': 667,
  32375. 'M': 944,
  32376. 'N': 722,
  32377. 'O': 778,
  32378. 'P': 611,
  32379. 'Q': 778,
  32380. 'R': 722,
  32381. 'S': 556,
  32382. 'T': 667,
  32383. 'U': 722,
  32384. 'V': 722,
  32385. 'W': 1000,
  32386. 'X': 722,
  32387. 'Y': 722,
  32388. 'Z': 667,
  32389. 'bracketleft': 333,
  32390. 'backslash': 278,
  32391. 'bracketright': 333,
  32392. 'asciicircum': 581,
  32393. 'underscore': 500,
  32394. 'quoteleft': 333,
  32395. 'a': 500,
  32396. 'b': 556,
  32397. 'c': 444,
  32398. 'd': 556,
  32399. 'e': 444,
  32400. 'f': 333,
  32401. 'g': 500,
  32402. 'h': 556,
  32403. 'i': 278,
  32404. 'j': 333,
  32405. 'k': 556,
  32406. 'l': 278,
  32407. 'm': 833,
  32408. 'n': 556,
  32409. 'o': 500,
  32410. 'p': 556,
  32411. 'q': 556,
  32412. 'r': 444,
  32413. 's': 389,
  32414. 't': 333,
  32415. 'u': 556,
  32416. 'v': 500,
  32417. 'w': 722,
  32418. 'x': 500,
  32419. 'y': 500,
  32420. 'z': 444,
  32421. 'braceleft': 394,
  32422. 'bar': 220,
  32423. 'braceright': 394,
  32424. 'asciitilde': 520,
  32425. 'exclamdown': 333,
  32426. 'cent': 500,
  32427. 'sterling': 500,
  32428. 'fraction': 167,
  32429. 'yen': 500,
  32430. 'florin': 500,
  32431. 'section': 500,
  32432. 'currency': 500,
  32433. 'quotesingle': 278,
  32434. 'quotedblleft': 500,
  32435. 'guillemotleft': 500,
  32436. 'guilsinglleft': 333,
  32437. 'guilsinglright': 333,
  32438. 'fi': 556,
  32439. 'fl': 556,
  32440. 'endash': 500,
  32441. 'dagger': 500,
  32442. 'daggerdbl': 500,
  32443. 'periodcentered': 250,
  32444. 'paragraph': 540,
  32445. 'bullet': 350,
  32446. 'quotesinglbase': 333,
  32447. 'quotedblbase': 500,
  32448. 'quotedblright': 500,
  32449. 'guillemotright': 500,
  32450. 'ellipsis': 1000,
  32451. 'perthousand': 1000,
  32452. 'questiondown': 500,
  32453. 'grave': 333,
  32454. 'acute': 333,
  32455. 'circumflex': 333,
  32456. 'tilde': 333,
  32457. 'macron': 333,
  32458. 'breve': 333,
  32459. 'dotaccent': 333,
  32460. 'dieresis': 333,
  32461. 'ring': 333,
  32462. 'cedilla': 333,
  32463. 'hungarumlaut': 333,
  32464. 'ogonek': 333,
  32465. 'caron': 333,
  32466. 'emdash': 1000,
  32467. 'AE': 1000,
  32468. 'ordfeminine': 300,
  32469. 'Lslash': 667,
  32470. 'Oslash': 778,
  32471. 'OE': 1000,
  32472. 'ordmasculine': 330,
  32473. 'ae': 722,
  32474. 'dotlessi': 278,
  32475. 'lslash': 278,
  32476. 'oslash': 500,
  32477. 'oe': 722,
  32478. 'germandbls': 556,
  32479. 'Idieresis': 389,
  32480. 'eacute': 444,
  32481. 'abreve': 500,
  32482. 'uhungarumlaut': 556,
  32483. 'ecaron': 444,
  32484. 'Ydieresis': 722,
  32485. 'divide': 570,
  32486. 'Yacute': 722,
  32487. 'Acircumflex': 722,
  32488. 'aacute': 500,
  32489. 'Ucircumflex': 722,
  32490. 'yacute': 500,
  32491. 'scommaaccent': 389,
  32492. 'ecircumflex': 444,
  32493. 'Uring': 722,
  32494. 'Udieresis': 722,
  32495. 'aogonek': 500,
  32496. 'Uacute': 722,
  32497. 'uogonek': 556,
  32498. 'Edieresis': 667,
  32499. 'Dcroat': 722,
  32500. 'commaaccent': 250,
  32501. 'copyright': 747,
  32502. 'Emacron': 667,
  32503. 'ccaron': 444,
  32504. 'aring': 500,
  32505. 'Ncommaaccent': 722,
  32506. 'lacute': 278,
  32507. 'agrave': 500,
  32508. 'Tcommaaccent': 667,
  32509. 'Cacute': 722,
  32510. 'atilde': 500,
  32511. 'Edotaccent': 667,
  32512. 'scaron': 389,
  32513. 'scedilla': 389,
  32514. 'iacute': 278,
  32515. 'lozenge': 494,
  32516. 'Rcaron': 722,
  32517. 'Gcommaaccent': 778,
  32518. 'ucircumflex': 556,
  32519. 'acircumflex': 500,
  32520. 'Amacron': 722,
  32521. 'rcaron': 444,
  32522. 'ccedilla': 444,
  32523. 'Zdotaccent': 667,
  32524. 'Thorn': 611,
  32525. 'Omacron': 778,
  32526. 'Racute': 722,
  32527. 'Sacute': 556,
  32528. 'dcaron': 672,
  32529. 'Umacron': 722,
  32530. 'uring': 556,
  32531. 'threesuperior': 300,
  32532. 'Ograve': 778,
  32533. 'Agrave': 722,
  32534. 'Abreve': 722,
  32535. 'multiply': 570,
  32536. 'uacute': 556,
  32537. 'Tcaron': 667,
  32538. 'partialdiff': 494,
  32539. 'ydieresis': 500,
  32540. 'Nacute': 722,
  32541. 'icircumflex': 278,
  32542. 'Ecircumflex': 667,
  32543. 'adieresis': 500,
  32544. 'edieresis': 444,
  32545. 'cacute': 444,
  32546. 'nacute': 556,
  32547. 'umacron': 556,
  32548. 'Ncaron': 722,
  32549. 'Iacute': 389,
  32550. 'plusminus': 570,
  32551. 'brokenbar': 220,
  32552. 'registered': 747,
  32553. 'Gbreve': 778,
  32554. 'Idotaccent': 389,
  32555. 'summation': 600,
  32556. 'Egrave': 667,
  32557. 'racute': 444,
  32558. 'omacron': 500,
  32559. 'Zacute': 667,
  32560. 'Zcaron': 667,
  32561. 'greaterequal': 549,
  32562. 'Eth': 722,
  32563. 'Ccedilla': 722,
  32564. 'lcommaaccent': 278,
  32565. 'tcaron': 416,
  32566. 'eogonek': 444,
  32567. 'Uogonek': 722,
  32568. 'Aacute': 722,
  32569. 'Adieresis': 722,
  32570. 'egrave': 444,
  32571. 'zacute': 444,
  32572. 'iogonek': 278,
  32573. 'Oacute': 778,
  32574. 'oacute': 500,
  32575. 'amacron': 500,
  32576. 'sacute': 389,
  32577. 'idieresis': 278,
  32578. 'Ocircumflex': 778,
  32579. 'Ugrave': 722,
  32580. 'Delta': 612,
  32581. 'thorn': 556,
  32582. 'twosuperior': 300,
  32583. 'Odieresis': 778,
  32584. 'mu': 556,
  32585. 'igrave': 278,
  32586. 'ohungarumlaut': 500,
  32587. 'Eogonek': 667,
  32588. 'dcroat': 556,
  32589. 'threequarters': 750,
  32590. 'Scedilla': 556,
  32591. 'lcaron': 394,
  32592. 'Kcommaaccent': 778,
  32593. 'Lacute': 667,
  32594. 'trademark': 1000,
  32595. 'edotaccent': 444,
  32596. 'Igrave': 389,
  32597. 'Imacron': 389,
  32598. 'Lcaron': 667,
  32599. 'onehalf': 750,
  32600. 'lessequal': 549,
  32601. 'ocircumflex': 500,
  32602. 'ntilde': 556,
  32603. 'Uhungarumlaut': 722,
  32604. 'Eacute': 667,
  32605. 'emacron': 444,
  32606. 'gbreve': 500,
  32607. 'onequarter': 750,
  32608. 'Scaron': 556,
  32609. 'Scommaaccent': 556,
  32610. 'Ohungarumlaut': 778,
  32611. 'degree': 400,
  32612. 'ograve': 500,
  32613. 'Ccaron': 722,
  32614. 'ugrave': 556,
  32615. 'radical': 549,
  32616. 'Dcaron': 722,
  32617. 'rcommaaccent': 444,
  32618. 'Ntilde': 722,
  32619. 'otilde': 500,
  32620. 'Rcommaaccent': 722,
  32621. 'Lcommaaccent': 667,
  32622. 'Atilde': 722,
  32623. 'Aogonek': 722,
  32624. 'Aring': 722,
  32625. 'Otilde': 778,
  32626. 'zdotaccent': 444,
  32627. 'Ecaron': 667,
  32628. 'Iogonek': 389,
  32629. 'kcommaaccent': 556,
  32630. 'minus': 570,
  32631. 'Icircumflex': 389,
  32632. 'ncaron': 556,
  32633. 'tcommaaccent': 333,
  32634. 'logicalnot': 570,
  32635. 'odieresis': 500,
  32636. 'udieresis': 556,
  32637. 'notequal': 549,
  32638. 'gcommaaccent': 500,
  32639. 'eth': 500,
  32640. 'zcaron': 444,
  32641. 'ncommaaccent': 556,
  32642. 'onesuperior': 300,
  32643. 'imacron': 278,
  32644. 'Euro': 500
  32645. },
  32646. 'Times-BoldItalic': {
  32647. 'space': 250,
  32648. 'exclam': 389,
  32649. 'quotedbl': 555,
  32650. 'numbersign': 500,
  32651. 'dollar': 500,
  32652. 'percent': 833,
  32653. 'ampersand': 778,
  32654. 'quoteright': 333,
  32655. 'parenleft': 333,
  32656. 'parenright': 333,
  32657. 'asterisk': 500,
  32658. 'plus': 570,
  32659. 'comma': 250,
  32660. 'hyphen': 333,
  32661. 'period': 250,
  32662. 'slash': 278,
  32663. 'zero': 500,
  32664. 'one': 500,
  32665. 'two': 500,
  32666. 'three': 500,
  32667. 'four': 500,
  32668. 'five': 500,
  32669. 'six': 500,
  32670. 'seven': 500,
  32671. 'eight': 500,
  32672. 'nine': 500,
  32673. 'colon': 333,
  32674. 'semicolon': 333,
  32675. 'less': 570,
  32676. 'equal': 570,
  32677. 'greater': 570,
  32678. 'question': 500,
  32679. 'at': 832,
  32680. 'A': 667,
  32681. 'B': 667,
  32682. 'C': 667,
  32683. 'D': 722,
  32684. 'E': 667,
  32685. 'F': 667,
  32686. 'G': 722,
  32687. 'H': 778,
  32688. 'I': 389,
  32689. 'J': 500,
  32690. 'K': 667,
  32691. 'L': 611,
  32692. 'M': 889,
  32693. 'N': 722,
  32694. 'O': 722,
  32695. 'P': 611,
  32696. 'Q': 722,
  32697. 'R': 667,
  32698. 'S': 556,
  32699. 'T': 611,
  32700. 'U': 722,
  32701. 'V': 667,
  32702. 'W': 889,
  32703. 'X': 667,
  32704. 'Y': 611,
  32705. 'Z': 611,
  32706. 'bracketleft': 333,
  32707. 'backslash': 278,
  32708. 'bracketright': 333,
  32709. 'asciicircum': 570,
  32710. 'underscore': 500,
  32711. 'quoteleft': 333,
  32712. 'a': 500,
  32713. 'b': 500,
  32714. 'c': 444,
  32715. 'd': 500,
  32716. 'e': 444,
  32717. 'f': 333,
  32718. 'g': 500,
  32719. 'h': 556,
  32720. 'i': 278,
  32721. 'j': 278,
  32722. 'k': 500,
  32723. 'l': 278,
  32724. 'm': 778,
  32725. 'n': 556,
  32726. 'o': 500,
  32727. 'p': 500,
  32728. 'q': 500,
  32729. 'r': 389,
  32730. 's': 389,
  32731. 't': 278,
  32732. 'u': 556,
  32733. 'v': 444,
  32734. 'w': 667,
  32735. 'x': 500,
  32736. 'y': 444,
  32737. 'z': 389,
  32738. 'braceleft': 348,
  32739. 'bar': 220,
  32740. 'braceright': 348,
  32741. 'asciitilde': 570,
  32742. 'exclamdown': 389,
  32743. 'cent': 500,
  32744. 'sterling': 500,
  32745. 'fraction': 167,
  32746. 'yen': 500,
  32747. 'florin': 500,
  32748. 'section': 500,
  32749. 'currency': 500,
  32750. 'quotesingle': 278,
  32751. 'quotedblleft': 500,
  32752. 'guillemotleft': 500,
  32753. 'guilsinglleft': 333,
  32754. 'guilsinglright': 333,
  32755. 'fi': 556,
  32756. 'fl': 556,
  32757. 'endash': 500,
  32758. 'dagger': 500,
  32759. 'daggerdbl': 500,
  32760. 'periodcentered': 250,
  32761. 'paragraph': 500,
  32762. 'bullet': 350,
  32763. 'quotesinglbase': 333,
  32764. 'quotedblbase': 500,
  32765. 'quotedblright': 500,
  32766. 'guillemotright': 500,
  32767. 'ellipsis': 1000,
  32768. 'perthousand': 1000,
  32769. 'questiondown': 500,
  32770. 'grave': 333,
  32771. 'acute': 333,
  32772. 'circumflex': 333,
  32773. 'tilde': 333,
  32774. 'macron': 333,
  32775. 'breve': 333,
  32776. 'dotaccent': 333,
  32777. 'dieresis': 333,
  32778. 'ring': 333,
  32779. 'cedilla': 333,
  32780. 'hungarumlaut': 333,
  32781. 'ogonek': 333,
  32782. 'caron': 333,
  32783. 'emdash': 1000,
  32784. 'AE': 944,
  32785. 'ordfeminine': 266,
  32786. 'Lslash': 611,
  32787. 'Oslash': 722,
  32788. 'OE': 944,
  32789. 'ordmasculine': 300,
  32790. 'ae': 722,
  32791. 'dotlessi': 278,
  32792. 'lslash': 278,
  32793. 'oslash': 500,
  32794. 'oe': 722,
  32795. 'germandbls': 500,
  32796. 'Idieresis': 389,
  32797. 'eacute': 444,
  32798. 'abreve': 500,
  32799. 'uhungarumlaut': 556,
  32800. 'ecaron': 444,
  32801. 'Ydieresis': 611,
  32802. 'divide': 570,
  32803. 'Yacute': 611,
  32804. 'Acircumflex': 667,
  32805. 'aacute': 500,
  32806. 'Ucircumflex': 722,
  32807. 'yacute': 444,
  32808. 'scommaaccent': 389,
  32809. 'ecircumflex': 444,
  32810. 'Uring': 722,
  32811. 'Udieresis': 722,
  32812. 'aogonek': 500,
  32813. 'Uacute': 722,
  32814. 'uogonek': 556,
  32815. 'Edieresis': 667,
  32816. 'Dcroat': 722,
  32817. 'commaaccent': 250,
  32818. 'copyright': 747,
  32819. 'Emacron': 667,
  32820. 'ccaron': 444,
  32821. 'aring': 500,
  32822. 'Ncommaaccent': 722,
  32823. 'lacute': 278,
  32824. 'agrave': 500,
  32825. 'Tcommaaccent': 611,
  32826. 'Cacute': 667,
  32827. 'atilde': 500,
  32828. 'Edotaccent': 667,
  32829. 'scaron': 389,
  32830. 'scedilla': 389,
  32831. 'iacute': 278,
  32832. 'lozenge': 494,
  32833. 'Rcaron': 667,
  32834. 'Gcommaaccent': 722,
  32835. 'ucircumflex': 556,
  32836. 'acircumflex': 500,
  32837. 'Amacron': 667,
  32838. 'rcaron': 389,
  32839. 'ccedilla': 444,
  32840. 'Zdotaccent': 611,
  32841. 'Thorn': 611,
  32842. 'Omacron': 722,
  32843. 'Racute': 667,
  32844. 'Sacute': 556,
  32845. 'dcaron': 608,
  32846. 'Umacron': 722,
  32847. 'uring': 556,
  32848. 'threesuperior': 300,
  32849. 'Ograve': 722,
  32850. 'Agrave': 667,
  32851. 'Abreve': 667,
  32852. 'multiply': 570,
  32853. 'uacute': 556,
  32854. 'Tcaron': 611,
  32855. 'partialdiff': 494,
  32856. 'ydieresis': 444,
  32857. 'Nacute': 722,
  32858. 'icircumflex': 278,
  32859. 'Ecircumflex': 667,
  32860. 'adieresis': 500,
  32861. 'edieresis': 444,
  32862. 'cacute': 444,
  32863. 'nacute': 556,
  32864. 'umacron': 556,
  32865. 'Ncaron': 722,
  32866. 'Iacute': 389,
  32867. 'plusminus': 570,
  32868. 'brokenbar': 220,
  32869. 'registered': 747,
  32870. 'Gbreve': 722,
  32871. 'Idotaccent': 389,
  32872. 'summation': 600,
  32873. 'Egrave': 667,
  32874. 'racute': 389,
  32875. 'omacron': 500,
  32876. 'Zacute': 611,
  32877. 'Zcaron': 611,
  32878. 'greaterequal': 549,
  32879. 'Eth': 722,
  32880. 'Ccedilla': 667,
  32881. 'lcommaaccent': 278,
  32882. 'tcaron': 366,
  32883. 'eogonek': 444,
  32884. 'Uogonek': 722,
  32885. 'Aacute': 667,
  32886. 'Adieresis': 667,
  32887. 'egrave': 444,
  32888. 'zacute': 389,
  32889. 'iogonek': 278,
  32890. 'Oacute': 722,
  32891. 'oacute': 500,
  32892. 'amacron': 500,
  32893. 'sacute': 389,
  32894. 'idieresis': 278,
  32895. 'Ocircumflex': 722,
  32896. 'Ugrave': 722,
  32897. 'Delta': 612,
  32898. 'thorn': 500,
  32899. 'twosuperior': 300,
  32900. 'Odieresis': 722,
  32901. 'mu': 576,
  32902. 'igrave': 278,
  32903. 'ohungarumlaut': 500,
  32904. 'Eogonek': 667,
  32905. 'dcroat': 500,
  32906. 'threequarters': 750,
  32907. 'Scedilla': 556,
  32908. 'lcaron': 382,
  32909. 'Kcommaaccent': 667,
  32910. 'Lacute': 611,
  32911. 'trademark': 1000,
  32912. 'edotaccent': 444,
  32913. 'Igrave': 389,
  32914. 'Imacron': 389,
  32915. 'Lcaron': 611,
  32916. 'onehalf': 750,
  32917. 'lessequal': 549,
  32918. 'ocircumflex': 500,
  32919. 'ntilde': 556,
  32920. 'Uhungarumlaut': 722,
  32921. 'Eacute': 667,
  32922. 'emacron': 444,
  32923. 'gbreve': 500,
  32924. 'onequarter': 750,
  32925. 'Scaron': 556,
  32926. 'Scommaaccent': 556,
  32927. 'Ohungarumlaut': 722,
  32928. 'degree': 400,
  32929. 'ograve': 500,
  32930. 'Ccaron': 667,
  32931. 'ugrave': 556,
  32932. 'radical': 549,
  32933. 'Dcaron': 722,
  32934. 'rcommaaccent': 389,
  32935. 'Ntilde': 722,
  32936. 'otilde': 500,
  32937. 'Rcommaaccent': 667,
  32938. 'Lcommaaccent': 611,
  32939. 'Atilde': 667,
  32940. 'Aogonek': 667,
  32941. 'Aring': 667,
  32942. 'Otilde': 722,
  32943. 'zdotaccent': 389,
  32944. 'Ecaron': 667,
  32945. 'Iogonek': 389,
  32946. 'kcommaaccent': 500,
  32947. 'minus': 606,
  32948. 'Icircumflex': 389,
  32949. 'ncaron': 556,
  32950. 'tcommaaccent': 278,
  32951. 'logicalnot': 606,
  32952. 'odieresis': 500,
  32953. 'udieresis': 556,
  32954. 'notequal': 549,
  32955. 'gcommaaccent': 500,
  32956. 'eth': 500,
  32957. 'zcaron': 389,
  32958. 'ncommaaccent': 556,
  32959. 'onesuperior': 300,
  32960. 'imacron': 278,
  32961. 'Euro': 500
  32962. },
  32963. 'Times-Italic': {
  32964. 'space': 250,
  32965. 'exclam': 333,
  32966. 'quotedbl': 420,
  32967. 'numbersign': 500,
  32968. 'dollar': 500,
  32969. 'percent': 833,
  32970. 'ampersand': 778,
  32971. 'quoteright': 333,
  32972. 'parenleft': 333,
  32973. 'parenright': 333,
  32974. 'asterisk': 500,
  32975. 'plus': 675,
  32976. 'comma': 250,
  32977. 'hyphen': 333,
  32978. 'period': 250,
  32979. 'slash': 278,
  32980. 'zero': 500,
  32981. 'one': 500,
  32982. 'two': 500,
  32983. 'three': 500,
  32984. 'four': 500,
  32985. 'five': 500,
  32986. 'six': 500,
  32987. 'seven': 500,
  32988. 'eight': 500,
  32989. 'nine': 500,
  32990. 'colon': 333,
  32991. 'semicolon': 333,
  32992. 'less': 675,
  32993. 'equal': 675,
  32994. 'greater': 675,
  32995. 'question': 500,
  32996. 'at': 920,
  32997. 'A': 611,
  32998. 'B': 611,
  32999. 'C': 667,
  33000. 'D': 722,
  33001. 'E': 611,
  33002. 'F': 611,
  33003. 'G': 722,
  33004. 'H': 722,
  33005. 'I': 333,
  33006. 'J': 444,
  33007. 'K': 667,
  33008. 'L': 556,
  33009. 'M': 833,
  33010. 'N': 667,
  33011. 'O': 722,
  33012. 'P': 611,
  33013. 'Q': 722,
  33014. 'R': 611,
  33015. 'S': 500,
  33016. 'T': 556,
  33017. 'U': 722,
  33018. 'V': 611,
  33019. 'W': 833,
  33020. 'X': 611,
  33021. 'Y': 556,
  33022. 'Z': 556,
  33023. 'bracketleft': 389,
  33024. 'backslash': 278,
  33025. 'bracketright': 389,
  33026. 'asciicircum': 422,
  33027. 'underscore': 500,
  33028. 'quoteleft': 333,
  33029. 'a': 500,
  33030. 'b': 500,
  33031. 'c': 444,
  33032. 'd': 500,
  33033. 'e': 444,
  33034. 'f': 278,
  33035. 'g': 500,
  33036. 'h': 500,
  33037. 'i': 278,
  33038. 'j': 278,
  33039. 'k': 444,
  33040. 'l': 278,
  33041. 'm': 722,
  33042. 'n': 500,
  33043. 'o': 500,
  33044. 'p': 500,
  33045. 'q': 500,
  33046. 'r': 389,
  33047. 's': 389,
  33048. 't': 278,
  33049. 'u': 500,
  33050. 'v': 444,
  33051. 'w': 667,
  33052. 'x': 444,
  33053. 'y': 444,
  33054. 'z': 389,
  33055. 'braceleft': 400,
  33056. 'bar': 275,
  33057. 'braceright': 400,
  33058. 'asciitilde': 541,
  33059. 'exclamdown': 389,
  33060. 'cent': 500,
  33061. 'sterling': 500,
  33062. 'fraction': 167,
  33063. 'yen': 500,
  33064. 'florin': 500,
  33065. 'section': 500,
  33066. 'currency': 500,
  33067. 'quotesingle': 214,
  33068. 'quotedblleft': 556,
  33069. 'guillemotleft': 500,
  33070. 'guilsinglleft': 333,
  33071. 'guilsinglright': 333,
  33072. 'fi': 500,
  33073. 'fl': 500,
  33074. 'endash': 500,
  33075. 'dagger': 500,
  33076. 'daggerdbl': 500,
  33077. 'periodcentered': 250,
  33078. 'paragraph': 523,
  33079. 'bullet': 350,
  33080. 'quotesinglbase': 333,
  33081. 'quotedblbase': 556,
  33082. 'quotedblright': 556,
  33083. 'guillemotright': 500,
  33084. 'ellipsis': 889,
  33085. 'perthousand': 1000,
  33086. 'questiondown': 500,
  33087. 'grave': 333,
  33088. 'acute': 333,
  33089. 'circumflex': 333,
  33090. 'tilde': 333,
  33091. 'macron': 333,
  33092. 'breve': 333,
  33093. 'dotaccent': 333,
  33094. 'dieresis': 333,
  33095. 'ring': 333,
  33096. 'cedilla': 333,
  33097. 'hungarumlaut': 333,
  33098. 'ogonek': 333,
  33099. 'caron': 333,
  33100. 'emdash': 889,
  33101. 'AE': 889,
  33102. 'ordfeminine': 276,
  33103. 'Lslash': 556,
  33104. 'Oslash': 722,
  33105. 'OE': 944,
  33106. 'ordmasculine': 310,
  33107. 'ae': 667,
  33108. 'dotlessi': 278,
  33109. 'lslash': 278,
  33110. 'oslash': 500,
  33111. 'oe': 667,
  33112. 'germandbls': 500,
  33113. 'Idieresis': 333,
  33114. 'eacute': 444,
  33115. 'abreve': 500,
  33116. 'uhungarumlaut': 500,
  33117. 'ecaron': 444,
  33118. 'Ydieresis': 556,
  33119. 'divide': 675,
  33120. 'Yacute': 556,
  33121. 'Acircumflex': 611,
  33122. 'aacute': 500,
  33123. 'Ucircumflex': 722,
  33124. 'yacute': 444,
  33125. 'scommaaccent': 389,
  33126. 'ecircumflex': 444,
  33127. 'Uring': 722,
  33128. 'Udieresis': 722,
  33129. 'aogonek': 500,
  33130. 'Uacute': 722,
  33131. 'uogonek': 500,
  33132. 'Edieresis': 611,
  33133. 'Dcroat': 722,
  33134. 'commaaccent': 250,
  33135. 'copyright': 760,
  33136. 'Emacron': 611,
  33137. 'ccaron': 444,
  33138. 'aring': 500,
  33139. 'Ncommaaccent': 667,
  33140. 'lacute': 278,
  33141. 'agrave': 500,
  33142. 'Tcommaaccent': 556,
  33143. 'Cacute': 667,
  33144. 'atilde': 500,
  33145. 'Edotaccent': 611,
  33146. 'scaron': 389,
  33147. 'scedilla': 389,
  33148. 'iacute': 278,
  33149. 'lozenge': 471,
  33150. 'Rcaron': 611,
  33151. 'Gcommaaccent': 722,
  33152. 'ucircumflex': 500,
  33153. 'acircumflex': 500,
  33154. 'Amacron': 611,
  33155. 'rcaron': 389,
  33156. 'ccedilla': 444,
  33157. 'Zdotaccent': 556,
  33158. 'Thorn': 611,
  33159. 'Omacron': 722,
  33160. 'Racute': 611,
  33161. 'Sacute': 500,
  33162. 'dcaron': 544,
  33163. 'Umacron': 722,
  33164. 'uring': 500,
  33165. 'threesuperior': 300,
  33166. 'Ograve': 722,
  33167. 'Agrave': 611,
  33168. 'Abreve': 611,
  33169. 'multiply': 675,
  33170. 'uacute': 500,
  33171. 'Tcaron': 556,
  33172. 'partialdiff': 476,
  33173. 'ydieresis': 444,
  33174. 'Nacute': 667,
  33175. 'icircumflex': 278,
  33176. 'Ecircumflex': 611,
  33177. 'adieresis': 500,
  33178. 'edieresis': 444,
  33179. 'cacute': 444,
  33180. 'nacute': 500,
  33181. 'umacron': 500,
  33182. 'Ncaron': 667,
  33183. 'Iacute': 333,
  33184. 'plusminus': 675,
  33185. 'brokenbar': 275,
  33186. 'registered': 760,
  33187. 'Gbreve': 722,
  33188. 'Idotaccent': 333,
  33189. 'summation': 600,
  33190. 'Egrave': 611,
  33191. 'racute': 389,
  33192. 'omacron': 500,
  33193. 'Zacute': 556,
  33194. 'Zcaron': 556,
  33195. 'greaterequal': 549,
  33196. 'Eth': 722,
  33197. 'Ccedilla': 667,
  33198. 'lcommaaccent': 278,
  33199. 'tcaron': 300,
  33200. 'eogonek': 444,
  33201. 'Uogonek': 722,
  33202. 'Aacute': 611,
  33203. 'Adieresis': 611,
  33204. 'egrave': 444,
  33205. 'zacute': 389,
  33206. 'iogonek': 278,
  33207. 'Oacute': 722,
  33208. 'oacute': 500,
  33209. 'amacron': 500,
  33210. 'sacute': 389,
  33211. 'idieresis': 278,
  33212. 'Ocircumflex': 722,
  33213. 'Ugrave': 722,
  33214. 'Delta': 612,
  33215. 'thorn': 500,
  33216. 'twosuperior': 300,
  33217. 'Odieresis': 722,
  33218. 'mu': 500,
  33219. 'igrave': 278,
  33220. 'ohungarumlaut': 500,
  33221. 'Eogonek': 611,
  33222. 'dcroat': 500,
  33223. 'threequarters': 750,
  33224. 'Scedilla': 500,
  33225. 'lcaron': 300,
  33226. 'Kcommaaccent': 667,
  33227. 'Lacute': 556,
  33228. 'trademark': 980,
  33229. 'edotaccent': 444,
  33230. 'Igrave': 333,
  33231. 'Imacron': 333,
  33232. 'Lcaron': 611,
  33233. 'onehalf': 750,
  33234. 'lessequal': 549,
  33235. 'ocircumflex': 500,
  33236. 'ntilde': 500,
  33237. 'Uhungarumlaut': 722,
  33238. 'Eacute': 611,
  33239. 'emacron': 444,
  33240. 'gbreve': 500,
  33241. 'onequarter': 750,
  33242. 'Scaron': 500,
  33243. 'Scommaaccent': 500,
  33244. 'Ohungarumlaut': 722,
  33245. 'degree': 400,
  33246. 'ograve': 500,
  33247. 'Ccaron': 667,
  33248. 'ugrave': 500,
  33249. 'radical': 453,
  33250. 'Dcaron': 722,
  33251. 'rcommaaccent': 389,
  33252. 'Ntilde': 667,
  33253. 'otilde': 500,
  33254. 'Rcommaaccent': 611,
  33255. 'Lcommaaccent': 556,
  33256. 'Atilde': 611,
  33257. 'Aogonek': 611,
  33258. 'Aring': 611,
  33259. 'Otilde': 722,
  33260. 'zdotaccent': 389,
  33261. 'Ecaron': 611,
  33262. 'Iogonek': 333,
  33263. 'kcommaaccent': 444,
  33264. 'minus': 675,
  33265. 'Icircumflex': 333,
  33266. 'ncaron': 500,
  33267. 'tcommaaccent': 278,
  33268. 'logicalnot': 675,
  33269. 'odieresis': 500,
  33270. 'udieresis': 500,
  33271. 'notequal': 549,
  33272. 'gcommaaccent': 500,
  33273. 'eth': 500,
  33274. 'zcaron': 389,
  33275. 'ncommaaccent': 500,
  33276. 'onesuperior': 300,
  33277. 'imacron': 278,
  33278. 'Euro': 500
  33279. },
  33280. 'ZapfDingbats': {
  33281. 'space': 278,
  33282. 'a1': 974,
  33283. 'a2': 961,
  33284. 'a202': 974,
  33285. 'a3': 980,
  33286. 'a4': 719,
  33287. 'a5': 789,
  33288. 'a119': 790,
  33289. 'a118': 791,
  33290. 'a117': 690,
  33291. 'a11': 960,
  33292. 'a12': 939,
  33293. 'a13': 549,
  33294. 'a14': 855,
  33295. 'a15': 911,
  33296. 'a16': 933,
  33297. 'a105': 911,
  33298. 'a17': 945,
  33299. 'a18': 974,
  33300. 'a19': 755,
  33301. 'a20': 846,
  33302. 'a21': 762,
  33303. 'a22': 761,
  33304. 'a23': 571,
  33305. 'a24': 677,
  33306. 'a25': 763,
  33307. 'a26': 760,
  33308. 'a27': 759,
  33309. 'a28': 754,
  33310. 'a6': 494,
  33311. 'a7': 552,
  33312. 'a8': 537,
  33313. 'a9': 577,
  33314. 'a10': 692,
  33315. 'a29': 786,
  33316. 'a30': 788,
  33317. 'a31': 788,
  33318. 'a32': 790,
  33319. 'a33': 793,
  33320. 'a34': 794,
  33321. 'a35': 816,
  33322. 'a36': 823,
  33323. 'a37': 789,
  33324. 'a38': 841,
  33325. 'a39': 823,
  33326. 'a40': 833,
  33327. 'a41': 816,
  33328. 'a42': 831,
  33329. 'a43': 923,
  33330. 'a44': 744,
  33331. 'a45': 723,
  33332. 'a46': 749,
  33333. 'a47': 790,
  33334. 'a48': 792,
  33335. 'a49': 695,
  33336. 'a50': 776,
  33337. 'a51': 768,
  33338. 'a52': 792,
  33339. 'a53': 759,
  33340. 'a54': 707,
  33341. 'a55': 708,
  33342. 'a56': 682,
  33343. 'a57': 701,
  33344. 'a58': 826,
  33345. 'a59': 815,
  33346. 'a60': 789,
  33347. 'a61': 789,
  33348. 'a62': 707,
  33349. 'a63': 687,
  33350. 'a64': 696,
  33351. 'a65': 689,
  33352. 'a66': 786,
  33353. 'a67': 787,
  33354. 'a68': 713,
  33355. 'a69': 791,
  33356. 'a70': 785,
  33357. 'a71': 791,
  33358. 'a72': 873,
  33359. 'a73': 761,
  33360. 'a74': 762,
  33361. 'a203': 762,
  33362. 'a75': 759,
  33363. 'a204': 759,
  33364. 'a76': 892,
  33365. 'a77': 892,
  33366. 'a78': 788,
  33367. 'a79': 784,
  33368. 'a81': 438,
  33369. 'a82': 138,
  33370. 'a83': 277,
  33371. 'a84': 415,
  33372. 'a97': 392,
  33373. 'a98': 392,
  33374. 'a99': 668,
  33375. 'a100': 668,
  33376. 'a89': 390,
  33377. 'a90': 390,
  33378. 'a93': 317,
  33379. 'a94': 317,
  33380. 'a91': 276,
  33381. 'a92': 276,
  33382. 'a205': 509,
  33383. 'a85': 509,
  33384. 'a206': 410,
  33385. 'a86': 410,
  33386. 'a87': 234,
  33387. 'a88': 234,
  33388. 'a95': 334,
  33389. 'a96': 334,
  33390. 'a101': 732,
  33391. 'a102': 544,
  33392. 'a103': 544,
  33393. 'a104': 910,
  33394. 'a106': 667,
  33395. 'a107': 760,
  33396. 'a108': 760,
  33397. 'a112': 776,
  33398. 'a111': 595,
  33399. 'a110': 694,
  33400. 'a109': 626,
  33401. 'a120': 788,
  33402. 'a121': 788,
  33403. 'a122': 788,
  33404. 'a123': 788,
  33405. 'a124': 788,
  33406. 'a125': 788,
  33407. 'a126': 788,
  33408. 'a127': 788,
  33409. 'a128': 788,
  33410. 'a129': 788,
  33411. 'a130': 788,
  33412. 'a131': 788,
  33413. 'a132': 788,
  33414. 'a133': 788,
  33415. 'a134': 788,
  33416. 'a135': 788,
  33417. 'a136': 788,
  33418. 'a137': 788,
  33419. 'a138': 788,
  33420. 'a139': 788,
  33421. 'a140': 788,
  33422. 'a141': 788,
  33423. 'a142': 788,
  33424. 'a143': 788,
  33425. 'a144': 788,
  33426. 'a145': 788,
  33427. 'a146': 788,
  33428. 'a147': 788,
  33429. 'a148': 788,
  33430. 'a149': 788,
  33431. 'a150': 788,
  33432. 'a151': 788,
  33433. 'a152': 788,
  33434. 'a153': 788,
  33435. 'a154': 788,
  33436. 'a155': 788,
  33437. 'a156': 788,
  33438. 'a157': 788,
  33439. 'a158': 788,
  33440. 'a159': 788,
  33441. 'a160': 894,
  33442. 'a161': 838,
  33443. 'a163': 1016,
  33444. 'a164': 458,
  33445. 'a196': 748,
  33446. 'a165': 924,
  33447. 'a192': 748,
  33448. 'a166': 918,
  33449. 'a167': 927,
  33450. 'a168': 928,
  33451. 'a169': 928,
  33452. 'a170': 834,
  33453. 'a171': 873,
  33454. 'a172': 828,
  33455. 'a173': 924,
  33456. 'a162': 924,
  33457. 'a174': 917,
  33458. 'a175': 930,
  33459. 'a176': 931,
  33460. 'a177': 463,
  33461. 'a178': 883,
  33462. 'a179': 836,
  33463. 'a193': 836,
  33464. 'a180': 867,
  33465. 'a199': 867,
  33466. 'a181': 696,
  33467. 'a200': 696,
  33468. 'a182': 874,
  33469. 'a201': 874,
  33470. 'a183': 760,
  33471. 'a184': 946,
  33472. 'a197': 771,
  33473. 'a185': 865,
  33474. 'a194': 771,
  33475. 'a198': 888,
  33476. 'a186': 967,
  33477. 'a195': 888,
  33478. 'a187': 831,
  33479. 'a188': 873,
  33480. 'a189': 927,
  33481. 'a190': 970,
  33482. 'a191': 918
  33483. }
  33484. };
  33485. var EOF = {};
  33486. function isEOF(v) {
  33487. return (v === EOF);
  33488. }
  33489. var Parser = (function ParserClosure() {
  33490. function Parser(lexer, allowStreams, xref) {
  33491. this.lexer = lexer;
  33492. this.allowStreams = allowStreams;
  33493. this.xref = xref;
  33494. this.imageCache = {
  33495. length: 0,
  33496. adler32: 0,
  33497. stream: null
  33498. };
  33499. this.refill();
  33500. }
  33501. Parser.prototype = {
  33502. refill: function Parser_refill() {
  33503. this.buf1 = this.lexer.getObj();
  33504. this.buf2 = this.lexer.getObj();
  33505. },
  33506. shift: function Parser_shift() {
  33507. if (isCmd(this.buf2, 'ID')) {
  33508. this.buf1 = this.buf2;
  33509. this.buf2 = null;
  33510. } else {
  33511. this.buf1 = this.buf2;
  33512. this.buf2 = this.lexer.getObj();
  33513. }
  33514. },
  33515. getObj: function Parser_getObj(cipherTransform) {
  33516. var buf1 = this.buf1;
  33517. this.shift();
  33518. if (buf1 instanceof Cmd) {
  33519. switch (buf1.cmd) {
  33520. case 'BI': // inline image
  33521. return this.makeInlineImage(cipherTransform);
  33522. case '[': // array
  33523. var array = [];
  33524. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  33525. array.push(this.getObj(cipherTransform));
  33526. }
  33527. if (isEOF(this.buf1)) {
  33528. error('End of file inside array');
  33529. }
  33530. this.shift();
  33531. return array;
  33532. case '<<': // dictionary or stream
  33533. var dict = new Dict(this.xref);
  33534. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  33535. if (!isName(this.buf1)) {
  33536. info('Malformed dictionary: key must be a name object');
  33537. this.shift();
  33538. continue;
  33539. }
  33540. var key = this.buf1.name;
  33541. this.shift();
  33542. if (isEOF(this.buf1)) {
  33543. break;
  33544. }
  33545. dict.set(key, this.getObj(cipherTransform));
  33546. }
  33547. if (isEOF(this.buf1)) {
  33548. error('End of file inside dictionary');
  33549. }
  33550. // Stream objects are not allowed inside content streams or
  33551. // object streams.
  33552. if (isCmd(this.buf2, 'stream')) {
  33553. return (this.allowStreams ?
  33554. this.makeStream(dict, cipherTransform) : dict);
  33555. }
  33556. this.shift();
  33557. return dict;
  33558. default: // simple object
  33559. return buf1;
  33560. }
  33561. }
  33562. if (isInt(buf1)) { // indirect reference or integer
  33563. var num = buf1;
  33564. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  33565. var ref = new Ref(num, this.buf1);
  33566. this.shift();
  33567. this.shift();
  33568. return ref;
  33569. }
  33570. return num;
  33571. }
  33572. if (isString(buf1)) { // string
  33573. var str = buf1;
  33574. if (cipherTransform) {
  33575. str = cipherTransform.decryptString(str);
  33576. }
  33577. return str;
  33578. }
  33579. // simple object
  33580. return buf1;
  33581. },
  33582. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  33583. var lexer = this.lexer;
  33584. var stream = lexer.stream;
  33585. // parse dictionary
  33586. var dict = new Dict(null);
  33587. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  33588. if (!isName(this.buf1)) {
  33589. error('Dictionary key must be a name object');
  33590. }
  33591. var key = this.buf1.name;
  33592. this.shift();
  33593. if (isEOF(this.buf1)) {
  33594. break;
  33595. }
  33596. dict.set(key, this.getObj(cipherTransform));
  33597. }
  33598. // parse image stream
  33599. var startPos = stream.pos;
  33600. // searching for the /EI\s/
  33601. var state = 0, ch, i, ii;
  33602. var E = 0x45, I = 0x49, SPACE = 0x20, NL = 0xA, CR = 0xD;
  33603. while ((ch = stream.getByte()) !== -1) {
  33604. if (state === 0) {
  33605. state = (ch === E) ? 1 : 0;
  33606. } else if (state === 1) {
  33607. state = (ch === I) ? 2 : 0;
  33608. } else {
  33609. assert(state === 2);
  33610. if (ch === SPACE || ch === NL || ch === CR) {
  33611. // Let's check the next five bytes are ASCII... just be sure.
  33612. var n = 5;
  33613. var followingBytes = stream.peekBytes(n);
  33614. for (i = 0; i < n; i++) {
  33615. ch = followingBytes[i];
  33616. if (ch !== NL && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  33617. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  33618. // it's binary stuff. Resetting the state.
  33619. state = 0;
  33620. break;
  33621. }
  33622. }
  33623. if (state === 2) {
  33624. break; // finished!
  33625. }
  33626. } else {
  33627. state = 0;
  33628. }
  33629. }
  33630. }
  33631. var length = (stream.pos - 4) - startPos;
  33632. var imageStream = stream.makeSubStream(startPos, length, dict);
  33633. // trying to cache repeat images, first we are trying to "warm up" caching
  33634. // using length, then comparing adler32
  33635. var MAX_LENGTH_TO_CACHE = 1000;
  33636. var cacheImage = false, adler32;
  33637. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  33638. var imageBytes = imageStream.getBytes();
  33639. imageStream.reset();
  33640. var a = 1;
  33641. var b = 0;
  33642. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  33643. a = (a + (imageBytes[i] & 0xff)) % 65521;
  33644. b = (b + a) % 65521;
  33645. }
  33646. adler32 = (b << 16) | a;
  33647. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  33648. this.buf2 = Cmd.get('EI');
  33649. this.shift();
  33650. this.imageCache.stream.reset();
  33651. return this.imageCache.stream;
  33652. }
  33653. cacheImage = true;
  33654. }
  33655. if (!cacheImage && !this.imageCache.stream) {
  33656. this.imageCache.length = length;
  33657. this.imageCache.stream = null;
  33658. }
  33659. if (cipherTransform) {
  33660. imageStream = cipherTransform.createStream(imageStream, length);
  33661. }
  33662. imageStream = this.filter(imageStream, dict, length);
  33663. imageStream.dict = dict;
  33664. if (cacheImage) {
  33665. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  33666. this.imageCache.adler32 = adler32;
  33667. this.imageCache.stream = imageStream;
  33668. }
  33669. this.buf2 = Cmd.get('EI');
  33670. this.shift();
  33671. return imageStream;
  33672. },
  33673. fetchIfRef: function Parser_fetchIfRef(obj) {
  33674. // not relying on the xref.fetchIfRef -- xref might not be set
  33675. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  33676. },
  33677. makeStream: function Parser_makeStream(dict, cipherTransform) {
  33678. var lexer = this.lexer;
  33679. var stream = lexer.stream;
  33680. // get stream start position
  33681. lexer.skipToNextLine();
  33682. var pos = stream.pos - 1;
  33683. // get length
  33684. var length = this.fetchIfRef(dict.get('Length'));
  33685. if (!isInt(length)) {
  33686. info('Bad ' + length + ' attribute in stream');
  33687. length = 0;
  33688. }
  33689. // skip over the stream data
  33690. stream.pos = pos + length;
  33691. lexer.nextChar();
  33692. this.shift(); // '>>'
  33693. this.shift(); // 'stream'
  33694. if (!isCmd(this.buf1, 'endstream')) {
  33695. // bad stream length, scanning for endstream
  33696. stream.pos = pos;
  33697. var SCAN_BLOCK_SIZE = 2048;
  33698. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  33699. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  33700. 0x61, 0x6D];
  33701. var skipped = 0, found = false, i, j;
  33702. while (stream.pos < stream.end) {
  33703. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  33704. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  33705. if (scanLength <= 0) {
  33706. break;
  33707. }
  33708. found = false;
  33709. for (i = 0, j = 0; i < scanLength; i++) {
  33710. var b = scanBytes[i];
  33711. if (b !== ENDSTREAM_SIGNATURE[j]) {
  33712. i -= j;
  33713. j = 0;
  33714. } else {
  33715. j++;
  33716. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  33717. i++;
  33718. found = true;
  33719. break;
  33720. }
  33721. }
  33722. }
  33723. if (found) {
  33724. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  33725. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  33726. break;
  33727. }
  33728. skipped += scanLength;
  33729. stream.pos += scanLength;
  33730. }
  33731. if (!found) {
  33732. error('Missing endstream');
  33733. }
  33734. length = skipped;
  33735. lexer.nextChar();
  33736. this.shift();
  33737. this.shift();
  33738. }
  33739. this.shift(); // 'endstream'
  33740. stream = stream.makeSubStream(pos, length, dict);
  33741. if (cipherTransform) {
  33742. stream = cipherTransform.createStream(stream, length);
  33743. }
  33744. stream = this.filter(stream, dict, length);
  33745. stream.dict = dict;
  33746. return stream;
  33747. },
  33748. filter: function Parser_filter(stream, dict, length) {
  33749. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  33750. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  33751. if (isName(filter)) {
  33752. return this.makeFilter(stream, filter.name, length, params);
  33753. }
  33754. var maybeLength = length;
  33755. if (isArray(filter)) {
  33756. var filterArray = filter;
  33757. var paramsArray = params;
  33758. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  33759. filter = filterArray[i];
  33760. if (!isName(filter)) {
  33761. error('Bad filter name: ' + filter);
  33762. }
  33763. params = null;
  33764. if (isArray(paramsArray) && (i in paramsArray)) {
  33765. params = paramsArray[i];
  33766. }
  33767. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  33768. // after the first stream the length variable is invalid
  33769. maybeLength = null;
  33770. }
  33771. }
  33772. return stream;
  33773. },
  33774. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  33775. if (stream.dict.get('Length') === 0) {
  33776. return new NullStream(stream);
  33777. }
  33778. try {
  33779. if (params) {
  33780. params = this.fetchIfRef(params);
  33781. }
  33782. var xrefStreamStats = this.xref.stats.streamTypes;
  33783. if (name === 'FlateDecode' || name === 'Fl') {
  33784. xrefStreamStats[StreamType.FLATE] = true;
  33785. if (params) {
  33786. return new PredictorStream(new FlateStream(stream, maybeLength),
  33787. maybeLength, params);
  33788. }
  33789. return new FlateStream(stream, maybeLength);
  33790. }
  33791. if (name === 'LZWDecode' || name === 'LZW') {
  33792. xrefStreamStats[StreamType.LZW] = true;
  33793. var earlyChange = 1;
  33794. if (params) {
  33795. if (params.has('EarlyChange')) {
  33796. earlyChange = params.get('EarlyChange');
  33797. }
  33798. return new PredictorStream(
  33799. new LZWStream(stream, maybeLength, earlyChange),
  33800. maybeLength, params);
  33801. }
  33802. return new LZWStream(stream, maybeLength, earlyChange);
  33803. }
  33804. if (name === 'DCTDecode' || name === 'DCT') {
  33805. // According to the specification: for inline images, the ID operator
  33806. // shall be followed by a single whitespace character (unless it uses
  33807. // ASCII85Decode or ASCIIHexDecode filters).
  33808. // In practice this only seems to be followed for inline JPEG images,
  33809. // and generally ignoring the first byte of the stream if it is a
  33810. // whitespace char can even *cause* issues (e.g. in the CCITTFaxDecode
  33811. // filters used in issue2984.pdf).
  33812. // Hence when the first byte of the stream of an inline JPEG image is
  33813. // a whitespace character, we thus simply skip over it.
  33814. if (isCmd(this.buf1, 'ID')) {
  33815. var firstByte = stream.peekByte();
  33816. if (firstByte === 0x0A /* LF */ || firstByte === 0x0D /* CR */ ||
  33817. firstByte === 0x20 /* SPACE */) {
  33818. stream.skip();
  33819. }
  33820. }
  33821. xrefStreamStats[StreamType.DCT] = true;
  33822. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  33823. }
  33824. if (name === 'JPXDecode' || name === 'JPX') {
  33825. xrefStreamStats[StreamType.JPX] = true;
  33826. return new JpxStream(stream, maybeLength, stream.dict);
  33827. }
  33828. if (name === 'ASCII85Decode' || name === 'A85') {
  33829. xrefStreamStats[StreamType.A85] = true;
  33830. return new Ascii85Stream(stream, maybeLength);
  33831. }
  33832. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  33833. xrefStreamStats[StreamType.AHX] = true;
  33834. return new AsciiHexStream(stream, maybeLength);
  33835. }
  33836. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  33837. xrefStreamStats[StreamType.CCF] = true;
  33838. return new CCITTFaxStream(stream, maybeLength, params);
  33839. }
  33840. if (name === 'RunLengthDecode' || name === 'RL') {
  33841. xrefStreamStats[StreamType.RL] = true;
  33842. return new RunLengthStream(stream, maybeLength);
  33843. }
  33844. if (name === 'JBIG2Decode') {
  33845. xrefStreamStats[StreamType.JBIG] = true;
  33846. return new Jbig2Stream(stream, maybeLength, stream.dict);
  33847. }
  33848. warn('filter "' + name + '" not supported yet');
  33849. return stream;
  33850. } catch (ex) {
  33851. if (ex instanceof MissingDataException) {
  33852. throw ex;
  33853. }
  33854. warn('Invalid stream: \"' + ex + '\"');
  33855. return new NullStream(stream);
  33856. }
  33857. }
  33858. };
  33859. return Parser;
  33860. })();
  33861. var Lexer = (function LexerClosure() {
  33862. function Lexer(stream, knownCommands) {
  33863. this.stream = stream;
  33864. this.nextChar();
  33865. // While lexing, we build up many strings one char at a time. Using += for
  33866. // this can result in lots of garbage strings. It's better to build an
  33867. // array of single-char strings and then join() them together at the end.
  33868. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  33869. // purpose uses less memory than using a new array for each string.
  33870. this.strBuf = [];
  33871. // The PDFs might have "glued" commands with other commands, operands or
  33872. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  33873. // commands and their prefixes. The prefixes are built the following way:
  33874. // if there a command that is a prefix of the other valid command or
  33875. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  33876. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  33877. // other commands or literals as a prefix. The knowCommands is optional.
  33878. this.knownCommands = knownCommands;
  33879. }
  33880. Lexer.isSpace = function Lexer_isSpace(ch) {
  33881. // Space is one of the following characters: SPACE, TAB, CR or LF.
  33882. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  33883. };
  33884. // A '1' in this array means the character is white space. A '1' or
  33885. // '2' means the character ends a name or command.
  33886. var specialChars = [
  33887. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  33888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  33889. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  33890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  33891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  33892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  33893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  33894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  33895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  33896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  33897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  33898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  33899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  33900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  33901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  33902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  33903. ];
  33904. function toHexDigit(ch) {
  33905. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  33906. return ch & 0x0F;
  33907. }
  33908. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  33909. // 'A'-'F', 'a'-'f'
  33910. return (ch & 0x0F) + 9;
  33911. }
  33912. return -1;
  33913. }
  33914. Lexer.prototype = {
  33915. nextChar: function Lexer_nextChar() {
  33916. return (this.currentChar = this.stream.getByte());
  33917. },
  33918. peekChar: function Lexer_peekChar() {
  33919. return this.stream.peekByte();
  33920. },
  33921. getNumber: function Lexer_getNumber() {
  33922. var ch = this.currentChar;
  33923. var eNotation = false;
  33924. var divideBy = 0; // different from 0 if it's a floating point value
  33925. var sign = 1;
  33926. if (ch === 0x2D) { // '-'
  33927. sign = -1;
  33928. ch = this.nextChar();
  33929. } else if (ch === 0x2B) { // '+'
  33930. ch = this.nextChar();
  33931. }
  33932. if (ch === 0x2E) { // '.'
  33933. divideBy = 10;
  33934. ch = this.nextChar();
  33935. }
  33936. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  33937. error('Invalid number: ' + String.fromCharCode(ch));
  33938. return 0;
  33939. }
  33940. var baseValue = ch - 0x30; // '0'
  33941. var powerValue = 0;
  33942. var powerValueSign = 1;
  33943. while ((ch = this.nextChar()) >= 0) {
  33944. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  33945. var currentDigit = ch - 0x30; // '0'
  33946. if (eNotation) { // We are after an 'e' or 'E'
  33947. powerValue = powerValue * 10 + currentDigit;
  33948. } else {
  33949. if (divideBy !== 0) { // We are after a point
  33950. divideBy *= 10;
  33951. }
  33952. baseValue = baseValue * 10 + currentDigit;
  33953. }
  33954. } else if (ch === 0x2E) { // '.'
  33955. if (divideBy === 0) {
  33956. divideBy = 1;
  33957. } else {
  33958. // A number can have only one '.'
  33959. break;
  33960. }
  33961. } else if (ch === 0x2D) { // '-'
  33962. // ignore minus signs in the middle of numbers to match
  33963. // Adobe's behavior
  33964. warn('Badly formated number');
  33965. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  33966. // 'E' can be either a scientific notation or the beginning of a new
  33967. // operator
  33968. ch = this.peekChar();
  33969. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  33970. powerValueSign = (ch === 0x2D) ? -1 : 1;
  33971. this.nextChar(); // Consume the sign character
  33972. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  33973. // The 'E' must be the beginning of a new operator
  33974. break;
  33975. }
  33976. eNotation = true;
  33977. } else {
  33978. // the last character doesn't belong to us
  33979. break;
  33980. }
  33981. }
  33982. if (divideBy !== 0) {
  33983. baseValue /= divideBy;
  33984. }
  33985. if (eNotation) {
  33986. baseValue *= Math.pow(10, powerValueSign * powerValue);
  33987. }
  33988. return sign * baseValue;
  33989. },
  33990. getString: function Lexer_getString() {
  33991. var numParen = 1;
  33992. var done = false;
  33993. var strBuf = this.strBuf;
  33994. strBuf.length = 0;
  33995. var ch = this.nextChar();
  33996. while (true) {
  33997. var charBuffered = false;
  33998. switch (ch | 0) {
  33999. case -1:
  34000. warn('Unterminated string');
  34001. done = true;
  34002. break;
  34003. case 0x28: // '('
  34004. ++numParen;
  34005. strBuf.push('(');
  34006. break;
  34007. case 0x29: // ')'
  34008. if (--numParen === 0) {
  34009. this.nextChar(); // consume strings ')'
  34010. done = true;
  34011. } else {
  34012. strBuf.push(')');
  34013. }
  34014. break;
  34015. case 0x5C: // '\\'
  34016. ch = this.nextChar();
  34017. switch (ch) {
  34018. case -1:
  34019. warn('Unterminated string');
  34020. done = true;
  34021. break;
  34022. case 0x6E: // 'n'
  34023. strBuf.push('\n');
  34024. break;
  34025. case 0x72: // 'r'
  34026. strBuf.push('\r');
  34027. break;
  34028. case 0x74: // 't'
  34029. strBuf.push('\t');
  34030. break;
  34031. case 0x62: // 'b'
  34032. strBuf.push('\b');
  34033. break;
  34034. case 0x66: // 'f'
  34035. strBuf.push('\f');
  34036. break;
  34037. case 0x5C: // '\'
  34038. case 0x28: // '('
  34039. case 0x29: // ')'
  34040. strBuf.push(String.fromCharCode(ch));
  34041. break;
  34042. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34043. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34044. var x = ch & 0x0F;
  34045. ch = this.nextChar();
  34046. charBuffered = true;
  34047. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34048. x = (x << 3) + (ch & 0x0F);
  34049. ch = this.nextChar();
  34050. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34051. charBuffered = false;
  34052. x = (x << 3) + (ch & 0x0F);
  34053. }
  34054. }
  34055. strBuf.push(String.fromCharCode(x));
  34056. break;
  34057. case 0x0D: // CR
  34058. if (this.peekChar() === 0x0A) { // LF
  34059. this.nextChar();
  34060. }
  34061. break;
  34062. case 0x0A: // LF
  34063. break;
  34064. default:
  34065. strBuf.push(String.fromCharCode(ch));
  34066. break;
  34067. }
  34068. break;
  34069. default:
  34070. strBuf.push(String.fromCharCode(ch));
  34071. break;
  34072. }
  34073. if (done) {
  34074. break;
  34075. }
  34076. if (!charBuffered) {
  34077. ch = this.nextChar();
  34078. }
  34079. }
  34080. return strBuf.join('');
  34081. },
  34082. getName: function Lexer_getName() {
  34083. var ch;
  34084. var strBuf = this.strBuf;
  34085. strBuf.length = 0;
  34086. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34087. if (ch === 0x23) { // '#'
  34088. ch = this.nextChar();
  34089. var x = toHexDigit(ch);
  34090. if (x !== -1) {
  34091. var x2 = toHexDigit(this.nextChar());
  34092. if (x2 === -1) {
  34093. error('Illegal digit in hex char in name: ' + x2);
  34094. }
  34095. strBuf.push(String.fromCharCode((x << 4) | x2));
  34096. } else {
  34097. strBuf.push('#', String.fromCharCode(ch));
  34098. }
  34099. } else {
  34100. strBuf.push(String.fromCharCode(ch));
  34101. }
  34102. }
  34103. if (strBuf.length > 128) {
  34104. error('Warning: name token is longer than allowed by the spec: ' +
  34105. strBuf.length);
  34106. }
  34107. return Name.get(strBuf.join(''));
  34108. },
  34109. getHexString: function Lexer_getHexString() {
  34110. var strBuf = this.strBuf;
  34111. strBuf.length = 0;
  34112. var ch = this.currentChar;
  34113. var isFirstHex = true;
  34114. var firstDigit;
  34115. var secondDigit;
  34116. while (true) {
  34117. if (ch < 0) {
  34118. warn('Unterminated hex string');
  34119. break;
  34120. } else if (ch === 0x3E) { // '>'
  34121. this.nextChar();
  34122. break;
  34123. } else if (specialChars[ch] === 1) {
  34124. ch = this.nextChar();
  34125. continue;
  34126. } else {
  34127. if (isFirstHex) {
  34128. firstDigit = toHexDigit(ch);
  34129. if (firstDigit === -1) {
  34130. warn('Ignoring invalid character "' + ch + '" in hex string');
  34131. ch = this.nextChar();
  34132. continue;
  34133. }
  34134. } else {
  34135. secondDigit = toHexDigit(ch);
  34136. if (secondDigit === -1) {
  34137. warn('Ignoring invalid character "' + ch + '" in hex string');
  34138. ch = this.nextChar();
  34139. continue;
  34140. }
  34141. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34142. }
  34143. isFirstHex = !isFirstHex;
  34144. ch = this.nextChar();
  34145. }
  34146. }
  34147. return strBuf.join('');
  34148. },
  34149. getObj: function Lexer_getObj() {
  34150. // skip whitespace and comments
  34151. var comment = false;
  34152. var ch = this.currentChar;
  34153. while (true) {
  34154. if (ch < 0) {
  34155. return EOF;
  34156. }
  34157. if (comment) {
  34158. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34159. comment = false;
  34160. }
  34161. } else if (ch === 0x25) { // '%'
  34162. comment = true;
  34163. } else if (specialChars[ch] !== 1) {
  34164. break;
  34165. }
  34166. ch = this.nextChar();
  34167. }
  34168. // start reading token
  34169. switch (ch | 0) {
  34170. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34171. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34172. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34173. return this.getNumber();
  34174. case 0x28: // '('
  34175. return this.getString();
  34176. case 0x2F: // '/'
  34177. return this.getName();
  34178. // array punctuation
  34179. case 0x5B: // '['
  34180. this.nextChar();
  34181. return Cmd.get('[');
  34182. case 0x5D: // ']'
  34183. this.nextChar();
  34184. return Cmd.get(']');
  34185. // hex string or dict punctuation
  34186. case 0x3C: // '<'
  34187. ch = this.nextChar();
  34188. if (ch === 0x3C) {
  34189. // dict punctuation
  34190. this.nextChar();
  34191. return Cmd.get('<<');
  34192. }
  34193. return this.getHexString();
  34194. // dict punctuation
  34195. case 0x3E: // '>'
  34196. ch = this.nextChar();
  34197. if (ch === 0x3E) {
  34198. this.nextChar();
  34199. return Cmd.get('>>');
  34200. }
  34201. return Cmd.get('>');
  34202. case 0x7B: // '{'
  34203. this.nextChar();
  34204. return Cmd.get('{');
  34205. case 0x7D: // '}'
  34206. this.nextChar();
  34207. return Cmd.get('}');
  34208. case 0x29: // ')'
  34209. error('Illegal character: ' + ch);
  34210. break;
  34211. }
  34212. // command
  34213. var str = String.fromCharCode(ch);
  34214. var knownCommands = this.knownCommands;
  34215. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34216. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34217. // stop if known command is found and next character does not make
  34218. // the str a command
  34219. var possibleCommand = str + String.fromCharCode(ch);
  34220. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34221. break;
  34222. }
  34223. if (str.length === 128) {
  34224. error('Command token too long: ' + str.length);
  34225. }
  34226. str = possibleCommand;
  34227. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34228. }
  34229. if (str === 'true') {
  34230. return true;
  34231. }
  34232. if (str === 'false') {
  34233. return false;
  34234. }
  34235. if (str === 'null') {
  34236. return null;
  34237. }
  34238. return Cmd.get(str);
  34239. },
  34240. skipToNextLine: function Lexer_skipToNextLine() {
  34241. var ch = this.currentChar;
  34242. while (ch >= 0) {
  34243. if (ch === 0x0D) { // CR
  34244. ch = this.nextChar();
  34245. if (ch === 0x0A) { // LF
  34246. this.nextChar();
  34247. }
  34248. break;
  34249. } else if (ch === 0x0A) { // LF
  34250. this.nextChar();
  34251. break;
  34252. }
  34253. ch = this.nextChar();
  34254. }
  34255. }
  34256. };
  34257. return Lexer;
  34258. })();
  34259. var Linearization = {
  34260. create: function LinearizationCreate(stream) {
  34261. function getInt(name, allowZeroValue) {
  34262. var obj = linDict.get(name);
  34263. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34264. return obj;
  34265. }
  34266. throw new Error('The "' + name + '" parameter in the linearization ' +
  34267. 'dictionary is invalid.');
  34268. }
  34269. function getHints() {
  34270. var hints = linDict.get('H'), hintsLength, item;
  34271. if (isArray(hints) &&
  34272. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34273. for (var index = 0; index < hintsLength; index++) {
  34274. if (!(isInt(item = hints[index]) && item > 0)) {
  34275. throw new Error('Hint (' + index +
  34276. ') in the linearization dictionary is invalid.');
  34277. }
  34278. }
  34279. return hints;
  34280. }
  34281. throw new Error('Hint array in the linearization dictionary is invalid.');
  34282. }
  34283. var parser = new Parser(new Lexer(stream), false, null);
  34284. var obj1 = parser.getObj();
  34285. var obj2 = parser.getObj();
  34286. var obj3 = parser.getObj();
  34287. var linDict = parser.getObj();
  34288. var obj, length;
  34289. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34290. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34291. return null; // No valid linearization dictionary found.
  34292. } else if ((length = getInt('L')) !== stream.length) {
  34293. throw new Error('The "L" parameter in the linearization dictionary ' +
  34294. 'does not equal the stream length.');
  34295. }
  34296. return {
  34297. length: length,
  34298. hints: getHints(),
  34299. objectNumberFirst: getInt('O'),
  34300. endFirst: getInt('E'),
  34301. numPages: getInt('N'),
  34302. mainXRefEntriesOffset: getInt('T'),
  34303. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34304. };
  34305. }
  34306. };
  34307. var PostScriptParser = (function PostScriptParserClosure() {
  34308. function PostScriptParser(lexer) {
  34309. this.lexer = lexer;
  34310. this.operators = [];
  34311. this.token = null;
  34312. this.prev = null;
  34313. }
  34314. PostScriptParser.prototype = {
  34315. nextToken: function PostScriptParser_nextToken() {
  34316. this.prev = this.token;
  34317. this.token = this.lexer.getToken();
  34318. },
  34319. accept: function PostScriptParser_accept(type) {
  34320. if (this.token.type === type) {
  34321. this.nextToken();
  34322. return true;
  34323. }
  34324. return false;
  34325. },
  34326. expect: function PostScriptParser_expect(type) {
  34327. if (this.accept(type)) {
  34328. return true;
  34329. }
  34330. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34331. type + '.');
  34332. },
  34333. parse: function PostScriptParser_parse() {
  34334. this.nextToken();
  34335. this.expect(PostScriptTokenTypes.LBRACE);
  34336. this.parseBlock();
  34337. this.expect(PostScriptTokenTypes.RBRACE);
  34338. return this.operators;
  34339. },
  34340. parseBlock: function PostScriptParser_parseBlock() {
  34341. while (true) {
  34342. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34343. this.operators.push(this.prev.value);
  34344. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34345. this.operators.push(this.prev.value);
  34346. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34347. this.parseCondition();
  34348. } else {
  34349. return;
  34350. }
  34351. }
  34352. },
  34353. parseCondition: function PostScriptParser_parseCondition() {
  34354. // Add two place holders that will be updated later
  34355. var conditionLocation = this.operators.length;
  34356. this.operators.push(null, null);
  34357. this.parseBlock();
  34358. this.expect(PostScriptTokenTypes.RBRACE);
  34359. if (this.accept(PostScriptTokenTypes.IF)) {
  34360. // The true block is right after the 'if' so it just falls through on
  34361. // true else it jumps and skips the true block.
  34362. this.operators[conditionLocation] = this.operators.length;
  34363. this.operators[conditionLocation + 1] = 'jz';
  34364. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34365. var jumpLocation = this.operators.length;
  34366. this.operators.push(null, null);
  34367. var endOfTrue = this.operators.length;
  34368. this.parseBlock();
  34369. this.expect(PostScriptTokenTypes.RBRACE);
  34370. this.expect(PostScriptTokenTypes.IFELSE);
  34371. // The jump is added at the end of the true block to skip the false
  34372. // block.
  34373. this.operators[jumpLocation] = this.operators.length;
  34374. this.operators[jumpLocation + 1] = 'j';
  34375. this.operators[conditionLocation] = endOfTrue;
  34376. this.operators[conditionLocation + 1] = 'jz';
  34377. } else {
  34378. error('PS Function: error parsing conditional.');
  34379. }
  34380. }
  34381. };
  34382. return PostScriptParser;
  34383. })();
  34384. var PostScriptTokenTypes = {
  34385. LBRACE: 0,
  34386. RBRACE: 1,
  34387. NUMBER: 2,
  34388. OPERATOR: 3,
  34389. IF: 4,
  34390. IFELSE: 5
  34391. };
  34392. var PostScriptToken = (function PostScriptTokenClosure() {
  34393. function PostScriptToken(type, value) {
  34394. this.type = type;
  34395. this.value = value;
  34396. }
  34397. var opCache = {};
  34398. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  34399. var opValue = opCache[op];
  34400. if (opValue) {
  34401. return opValue;
  34402. }
  34403. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  34404. };
  34405. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  34406. '{');
  34407. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  34408. '}');
  34409. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  34410. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  34411. 'IFELSE');
  34412. return PostScriptToken;
  34413. })();
  34414. var PostScriptLexer = (function PostScriptLexerClosure() {
  34415. function PostScriptLexer(stream) {
  34416. this.stream = stream;
  34417. this.nextChar();
  34418. this.strBuf = [];
  34419. }
  34420. PostScriptLexer.prototype = {
  34421. nextChar: function PostScriptLexer_nextChar() {
  34422. return (this.currentChar = this.stream.getByte());
  34423. },
  34424. getToken: function PostScriptLexer_getToken() {
  34425. var comment = false;
  34426. var ch = this.currentChar;
  34427. // skip comments
  34428. while (true) {
  34429. if (ch < 0) {
  34430. return EOF;
  34431. }
  34432. if (comment) {
  34433. if (ch === 0x0A || ch === 0x0D) {
  34434. comment = false;
  34435. }
  34436. } else if (ch === 0x25) { // '%'
  34437. comment = true;
  34438. } else if (!Lexer.isSpace(ch)) {
  34439. break;
  34440. }
  34441. ch = this.nextChar();
  34442. }
  34443. switch (ch | 0) {
  34444. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34445. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34446. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34447. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  34448. this.getNumber());
  34449. case 0x7B: // '{'
  34450. this.nextChar();
  34451. return PostScriptToken.LBRACE;
  34452. case 0x7D: // '}'
  34453. this.nextChar();
  34454. return PostScriptToken.RBRACE;
  34455. }
  34456. // operator
  34457. var strBuf = this.strBuf;
  34458. strBuf.length = 0;
  34459. strBuf[0] = String.fromCharCode(ch);
  34460. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  34461. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  34462. strBuf.push(String.fromCharCode(ch));
  34463. }
  34464. var str = strBuf.join('');
  34465. switch (str.toLowerCase()) {
  34466. case 'if':
  34467. return PostScriptToken.IF;
  34468. case 'ifelse':
  34469. return PostScriptToken.IFELSE;
  34470. default:
  34471. return PostScriptToken.getOperator(str);
  34472. }
  34473. },
  34474. getNumber: function PostScriptLexer_getNumber() {
  34475. var ch = this.currentChar;
  34476. var strBuf = this.strBuf;
  34477. strBuf.length = 0;
  34478. strBuf[0] = String.fromCharCode(ch);
  34479. while ((ch = this.nextChar()) >= 0) {
  34480. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  34481. ch === 0x2D || ch === 0x2E) { // '-', '.'
  34482. strBuf.push(String.fromCharCode(ch));
  34483. } else {
  34484. break;
  34485. }
  34486. }
  34487. var value = parseFloat(strBuf.join(''));
  34488. if (isNaN(value)) {
  34489. error('Invalid floating point number: ' + value);
  34490. }
  34491. return value;
  34492. }
  34493. };
  34494. return PostScriptLexer;
  34495. })();
  34496. var Stream = (function StreamClosure() {
  34497. function Stream(arrayBuffer, start, length, dict) {
  34498. this.bytes = (arrayBuffer instanceof Uint8Array ?
  34499. arrayBuffer : new Uint8Array(arrayBuffer));
  34500. this.start = start || 0;
  34501. this.pos = this.start;
  34502. this.end = (start + length) || this.bytes.length;
  34503. this.dict = dict;
  34504. }
  34505. // required methods for a stream. if a particular stream does not
  34506. // implement these, an error should be thrown
  34507. Stream.prototype = {
  34508. get length() {
  34509. return this.end - this.start;
  34510. },
  34511. get isEmpty() {
  34512. return this.length === 0;
  34513. },
  34514. getByte: function Stream_getByte() {
  34515. if (this.pos >= this.end) {
  34516. return -1;
  34517. }
  34518. return this.bytes[this.pos++];
  34519. },
  34520. getUint16: function Stream_getUint16() {
  34521. var b0 = this.getByte();
  34522. var b1 = this.getByte();
  34523. return (b0 << 8) + b1;
  34524. },
  34525. getInt32: function Stream_getInt32() {
  34526. var b0 = this.getByte();
  34527. var b1 = this.getByte();
  34528. var b2 = this.getByte();
  34529. var b3 = this.getByte();
  34530. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  34531. },
  34532. // returns subarray of original buffer
  34533. // should only be read
  34534. getBytes: function Stream_getBytes(length) {
  34535. var bytes = this.bytes;
  34536. var pos = this.pos;
  34537. var strEnd = this.end;
  34538. if (!length) {
  34539. return bytes.subarray(pos, strEnd);
  34540. }
  34541. var end = pos + length;
  34542. if (end > strEnd) {
  34543. end = strEnd;
  34544. }
  34545. this.pos = end;
  34546. return bytes.subarray(pos, end);
  34547. },
  34548. peekByte: function Stream_peekByte() {
  34549. var peekedByte = this.getByte();
  34550. this.pos--;
  34551. return peekedByte;
  34552. },
  34553. peekBytes: function Stream_peekBytes(length) {
  34554. var bytes = this.getBytes(length);
  34555. this.pos -= bytes.length;
  34556. return bytes;
  34557. },
  34558. skip: function Stream_skip(n) {
  34559. if (!n) {
  34560. n = 1;
  34561. }
  34562. this.pos += n;
  34563. },
  34564. reset: function Stream_reset() {
  34565. this.pos = this.start;
  34566. },
  34567. moveStart: function Stream_moveStart() {
  34568. this.start = this.pos;
  34569. },
  34570. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  34571. return new Stream(this.bytes.buffer, start, length, dict);
  34572. },
  34573. isStream: true
  34574. };
  34575. return Stream;
  34576. })();
  34577. var StringStream = (function StringStreamClosure() {
  34578. function StringStream(str) {
  34579. var length = str.length;
  34580. var bytes = new Uint8Array(length);
  34581. for (var n = 0; n < length; ++n) {
  34582. bytes[n] = str.charCodeAt(n);
  34583. }
  34584. Stream.call(this, bytes);
  34585. }
  34586. StringStream.prototype = Stream.prototype;
  34587. return StringStream;
  34588. })();
  34589. // super class for the decoding streams
  34590. var DecodeStream = (function DecodeStreamClosure() {
  34591. // Lots of DecodeStreams are created whose buffers are never used. For these
  34592. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  34593. // having special cases that would be required if we used |null| for an empty
  34594. // buffer.
  34595. var emptyBuffer = new Uint8Array(0);
  34596. function DecodeStream(maybeMinBufferLength) {
  34597. this.pos = 0;
  34598. this.bufferLength = 0;
  34599. this.eof = false;
  34600. this.buffer = emptyBuffer;
  34601. this.minBufferLength = 512;
  34602. if (maybeMinBufferLength) {
  34603. // Compute the first power of two that is as big as maybeMinBufferLength.
  34604. while (this.minBufferLength < maybeMinBufferLength) {
  34605. this.minBufferLength *= 2;
  34606. }
  34607. }
  34608. }
  34609. DecodeStream.prototype = {
  34610. get isEmpty() {
  34611. while (!this.eof && this.bufferLength === 0) {
  34612. this.readBlock();
  34613. }
  34614. return this.bufferLength === 0;
  34615. },
  34616. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  34617. var buffer = this.buffer;
  34618. if (requested <= buffer.byteLength) {
  34619. return buffer;
  34620. }
  34621. var size = this.minBufferLength;
  34622. while (size < requested) {
  34623. size *= 2;
  34624. }
  34625. var buffer2 = new Uint8Array(size);
  34626. buffer2.set(buffer);
  34627. return (this.buffer = buffer2);
  34628. },
  34629. getByte: function DecodeStream_getByte() {
  34630. var pos = this.pos;
  34631. while (this.bufferLength <= pos) {
  34632. if (this.eof) {
  34633. return -1;
  34634. }
  34635. this.readBlock();
  34636. }
  34637. return this.buffer[this.pos++];
  34638. },
  34639. getUint16: function DecodeStream_getUint16() {
  34640. var b0 = this.getByte();
  34641. var b1 = this.getByte();
  34642. return (b0 << 8) + b1;
  34643. },
  34644. getInt32: function DecodeStream_getInt32() {
  34645. var b0 = this.getByte();
  34646. var b1 = this.getByte();
  34647. var b2 = this.getByte();
  34648. var b3 = this.getByte();
  34649. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  34650. },
  34651. getBytes: function DecodeStream_getBytes(length) {
  34652. var end, pos = this.pos;
  34653. if (length) {
  34654. this.ensureBuffer(pos + length);
  34655. end = pos + length;
  34656. while (!this.eof && this.bufferLength < end) {
  34657. this.readBlock();
  34658. }
  34659. var bufEnd = this.bufferLength;
  34660. if (end > bufEnd) {
  34661. end = bufEnd;
  34662. }
  34663. } else {
  34664. while (!this.eof) {
  34665. this.readBlock();
  34666. }
  34667. end = this.bufferLength;
  34668. }
  34669. this.pos = end;
  34670. return this.buffer.subarray(pos, end);
  34671. },
  34672. peekByte: function DecodeStream_peekByte() {
  34673. var peekedByte = this.getByte();
  34674. this.pos--;
  34675. return peekedByte;
  34676. },
  34677. peekBytes: function DecodeStream_peekBytes(length) {
  34678. var bytes = this.getBytes(length);
  34679. this.pos -= bytes.length;
  34680. return bytes;
  34681. },
  34682. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  34683. var end = start + length;
  34684. while (this.bufferLength <= end && !this.eof) {
  34685. this.readBlock();
  34686. }
  34687. return new Stream(this.buffer, start, length, dict);
  34688. },
  34689. skip: function DecodeStream_skip(n) {
  34690. if (!n) {
  34691. n = 1;
  34692. }
  34693. this.pos += n;
  34694. },
  34695. reset: function DecodeStream_reset() {
  34696. this.pos = 0;
  34697. },
  34698. getBaseStreams: function DecodeStream_getBaseStreams() {
  34699. if (this.str && this.str.getBaseStreams) {
  34700. return this.str.getBaseStreams();
  34701. }
  34702. return [];
  34703. }
  34704. };
  34705. return DecodeStream;
  34706. })();
  34707. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  34708. function StreamsSequenceStream(streams) {
  34709. this.streams = streams;
  34710. DecodeStream.call(this, /* maybeLength = */ null);
  34711. }
  34712. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  34713. StreamsSequenceStream.prototype.readBlock =
  34714. function streamSequenceStreamReadBlock() {
  34715. var streams = this.streams;
  34716. if (streams.length === 0) {
  34717. this.eof = true;
  34718. return;
  34719. }
  34720. var stream = streams.shift();
  34721. var chunk = stream.getBytes();
  34722. var bufferLength = this.bufferLength;
  34723. var newLength = bufferLength + chunk.length;
  34724. var buffer = this.ensureBuffer(newLength);
  34725. buffer.set(chunk, bufferLength);
  34726. this.bufferLength = newLength;
  34727. };
  34728. StreamsSequenceStream.prototype.getBaseStreams =
  34729. function StreamsSequenceStream_getBaseStreams() {
  34730. var baseStreams = [];
  34731. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  34732. var stream = this.streams[i];
  34733. if (stream.getBaseStreams) {
  34734. Util.appendToArray(baseStreams, stream.getBaseStreams());
  34735. }
  34736. }
  34737. return baseStreams;
  34738. };
  34739. return StreamsSequenceStream;
  34740. })();
  34741. var FlateStream = (function FlateStreamClosure() {
  34742. var codeLenCodeMap = new Uint32Array([
  34743. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  34744. ]);
  34745. var lengthDecode = new Uint32Array([
  34746. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  34747. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  34748. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  34749. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  34750. ]);
  34751. var distDecode = new Uint32Array([
  34752. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  34753. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  34754. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  34755. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  34756. ]);
  34757. var fixedLitCodeTab = [new Uint32Array([
  34758. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  34759. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  34760. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  34761. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  34762. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  34763. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  34764. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  34765. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  34766. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  34767. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  34768. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  34769. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  34770. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  34771. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  34772. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  34773. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  34774. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  34775. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  34776. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  34777. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  34778. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  34779. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  34780. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  34781. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  34782. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  34783. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  34784. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  34785. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  34786. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  34787. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  34788. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  34789. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  34790. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  34791. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  34792. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  34793. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  34794. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  34795. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  34796. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  34797. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  34798. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  34799. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  34800. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  34801. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  34802. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  34803. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  34804. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  34805. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  34806. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  34807. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  34808. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  34809. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  34810. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  34811. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  34812. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  34813. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  34814. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  34815. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  34816. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  34817. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  34818. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  34819. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  34820. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  34821. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  34822. ]), 9];
  34823. var fixedDistCodeTab = [new Uint32Array([
  34824. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  34825. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  34826. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  34827. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  34828. ]), 5];
  34829. function FlateStream(str, maybeLength) {
  34830. this.str = str;
  34831. this.dict = str.dict;
  34832. var cmf = str.getByte();
  34833. var flg = str.getByte();
  34834. if (cmf === -1 || flg === -1) {
  34835. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  34836. }
  34837. if ((cmf & 0x0f) !== 0x08) {
  34838. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  34839. }
  34840. if ((((cmf << 8) + flg) % 31) !== 0) {
  34841. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  34842. }
  34843. if (flg & 0x20) {
  34844. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  34845. }
  34846. this.codeSize = 0;
  34847. this.codeBuf = 0;
  34848. DecodeStream.call(this, maybeLength);
  34849. }
  34850. FlateStream.prototype = Object.create(DecodeStream.prototype);
  34851. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  34852. var str = this.str;
  34853. var codeSize = this.codeSize;
  34854. var codeBuf = this.codeBuf;
  34855. var b;
  34856. while (codeSize < bits) {
  34857. if ((b = str.getByte()) === -1) {
  34858. error('Bad encoding in flate stream');
  34859. }
  34860. codeBuf |= b << codeSize;
  34861. codeSize += 8;
  34862. }
  34863. b = codeBuf & ((1 << bits) - 1);
  34864. this.codeBuf = codeBuf >> bits;
  34865. this.codeSize = codeSize -= bits;
  34866. return b;
  34867. };
  34868. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  34869. var str = this.str;
  34870. var codes = table[0];
  34871. var maxLen = table[1];
  34872. var codeSize = this.codeSize;
  34873. var codeBuf = this.codeBuf;
  34874. var b;
  34875. while (codeSize < maxLen) {
  34876. if ((b = str.getByte()) === -1) {
  34877. // premature end of stream. code might however still be valid.
  34878. // codeSize < codeLen check below guards against incomplete codeVal.
  34879. break;
  34880. }
  34881. codeBuf |= (b << codeSize);
  34882. codeSize += 8;
  34883. }
  34884. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  34885. var codeLen = code >> 16;
  34886. var codeVal = code & 0xffff;
  34887. if (codeLen < 1 || codeSize < codeLen) {
  34888. error('Bad encoding in flate stream');
  34889. }
  34890. this.codeBuf = (codeBuf >> codeLen);
  34891. this.codeSize = (codeSize - codeLen);
  34892. return codeVal;
  34893. };
  34894. FlateStream.prototype.generateHuffmanTable =
  34895. function flateStreamGenerateHuffmanTable(lengths) {
  34896. var n = lengths.length;
  34897. // find max code length
  34898. var maxLen = 0;
  34899. var i;
  34900. for (i = 0; i < n; ++i) {
  34901. if (lengths[i] > maxLen) {
  34902. maxLen = lengths[i];
  34903. }
  34904. }
  34905. // build the table
  34906. var size = 1 << maxLen;
  34907. var codes = new Uint32Array(size);
  34908. for (var len = 1, code = 0, skip = 2;
  34909. len <= maxLen;
  34910. ++len, code <<= 1, skip <<= 1) {
  34911. for (var val = 0; val < n; ++val) {
  34912. if (lengths[val] === len) {
  34913. // bit-reverse the code
  34914. var code2 = 0;
  34915. var t = code;
  34916. for (i = 0; i < len; ++i) {
  34917. code2 = (code2 << 1) | (t & 1);
  34918. t >>= 1;
  34919. }
  34920. // fill the table entries
  34921. for (i = code2; i < size; i += skip) {
  34922. codes[i] = (len << 16) | val;
  34923. }
  34924. ++code;
  34925. }
  34926. }
  34927. }
  34928. return [codes, maxLen];
  34929. };
  34930. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  34931. var buffer, len;
  34932. var str = this.str;
  34933. // read block header
  34934. var hdr = this.getBits(3);
  34935. if (hdr & 1) {
  34936. this.eof = true;
  34937. }
  34938. hdr >>= 1;
  34939. if (hdr === 0) { // uncompressed block
  34940. var b;
  34941. if ((b = str.getByte()) === -1) {
  34942. error('Bad block header in flate stream');
  34943. }
  34944. var blockLen = b;
  34945. if ((b = str.getByte()) === -1) {
  34946. error('Bad block header in flate stream');
  34947. }
  34948. blockLen |= (b << 8);
  34949. if ((b = str.getByte()) === -1) {
  34950. error('Bad block header in flate stream');
  34951. }
  34952. var check = b;
  34953. if ((b = str.getByte()) === -1) {
  34954. error('Bad block header in flate stream');
  34955. }
  34956. check |= (b << 8);
  34957. if (check !== (~blockLen & 0xffff) &&
  34958. (blockLen !== 0 || check !== 0)) {
  34959. // Ignoring error for bad "empty" block (see issue 1277)
  34960. error('Bad uncompressed block length in flate stream');
  34961. }
  34962. this.codeBuf = 0;
  34963. this.codeSize = 0;
  34964. var bufferLength = this.bufferLength;
  34965. buffer = this.ensureBuffer(bufferLength + blockLen);
  34966. var end = bufferLength + blockLen;
  34967. this.bufferLength = end;
  34968. if (blockLen === 0) {
  34969. if (str.peekByte() === -1) {
  34970. this.eof = true;
  34971. }
  34972. } else {
  34973. for (var n = bufferLength; n < end; ++n) {
  34974. if ((b = str.getByte()) === -1) {
  34975. this.eof = true;
  34976. break;
  34977. }
  34978. buffer[n] = b;
  34979. }
  34980. }
  34981. return;
  34982. }
  34983. var litCodeTable;
  34984. var distCodeTable;
  34985. if (hdr === 1) { // compressed block, fixed codes
  34986. litCodeTable = fixedLitCodeTab;
  34987. distCodeTable = fixedDistCodeTab;
  34988. } else if (hdr === 2) { // compressed block, dynamic codes
  34989. var numLitCodes = this.getBits(5) + 257;
  34990. var numDistCodes = this.getBits(5) + 1;
  34991. var numCodeLenCodes = this.getBits(4) + 4;
  34992. // build the code lengths code table
  34993. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  34994. var i;
  34995. for (i = 0; i < numCodeLenCodes; ++i) {
  34996. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  34997. }
  34998. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  34999. // build the literal and distance code tables
  35000. len = 0;
  35001. i = 0;
  35002. var codes = numLitCodes + numDistCodes;
  35003. var codeLengths = new Uint8Array(codes);
  35004. var bitsLength, bitsOffset, what;
  35005. while (i < codes) {
  35006. var code = this.getCode(codeLenCodeTab);
  35007. if (code === 16) {
  35008. bitsLength = 2; bitsOffset = 3; what = len;
  35009. } else if (code === 17) {
  35010. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35011. } else if (code === 18) {
  35012. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35013. } else {
  35014. codeLengths[i++] = len = code;
  35015. continue;
  35016. }
  35017. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35018. while (repeatLength-- > 0) {
  35019. codeLengths[i++] = what;
  35020. }
  35021. }
  35022. litCodeTable =
  35023. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35024. distCodeTable =
  35025. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35026. } else {
  35027. error('Unknown block type in flate stream');
  35028. }
  35029. buffer = this.buffer;
  35030. var limit = buffer ? buffer.length : 0;
  35031. var pos = this.bufferLength;
  35032. while (true) {
  35033. var code1 = this.getCode(litCodeTable);
  35034. if (code1 < 256) {
  35035. if (pos + 1 >= limit) {
  35036. buffer = this.ensureBuffer(pos + 1);
  35037. limit = buffer.length;
  35038. }
  35039. buffer[pos++] = code1;
  35040. continue;
  35041. }
  35042. if (code1 === 256) {
  35043. this.bufferLength = pos;
  35044. return;
  35045. }
  35046. code1 -= 257;
  35047. code1 = lengthDecode[code1];
  35048. var code2 = code1 >> 16;
  35049. if (code2 > 0) {
  35050. code2 = this.getBits(code2);
  35051. }
  35052. len = (code1 & 0xffff) + code2;
  35053. code1 = this.getCode(distCodeTable);
  35054. code1 = distDecode[code1];
  35055. code2 = code1 >> 16;
  35056. if (code2 > 0) {
  35057. code2 = this.getBits(code2);
  35058. }
  35059. var dist = (code1 & 0xffff) + code2;
  35060. if (pos + len >= limit) {
  35061. buffer = this.ensureBuffer(pos + len);
  35062. limit = buffer.length;
  35063. }
  35064. for (var k = 0; k < len; ++k, ++pos) {
  35065. buffer[pos] = buffer[pos - dist];
  35066. }
  35067. }
  35068. };
  35069. return FlateStream;
  35070. })();
  35071. var PredictorStream = (function PredictorStreamClosure() {
  35072. function PredictorStream(str, maybeLength, params) {
  35073. var predictor = this.predictor = params.get('Predictor') || 1;
  35074. if (predictor <= 1) {
  35075. return str; // no prediction
  35076. }
  35077. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35078. error('Unsupported predictor: ' + predictor);
  35079. }
  35080. if (predictor === 2) {
  35081. this.readBlock = this.readBlockTiff;
  35082. } else {
  35083. this.readBlock = this.readBlockPng;
  35084. }
  35085. this.str = str;
  35086. this.dict = str.dict;
  35087. var colors = this.colors = params.get('Colors') || 1;
  35088. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35089. var columns = this.columns = params.get('Columns') || 1;
  35090. this.pixBytes = (colors * bits + 7) >> 3;
  35091. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35092. DecodeStream.call(this, maybeLength);
  35093. return this;
  35094. }
  35095. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35096. PredictorStream.prototype.readBlockTiff =
  35097. function predictorStreamReadBlockTiff() {
  35098. var rowBytes = this.rowBytes;
  35099. var bufferLength = this.bufferLength;
  35100. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35101. var bits = this.bits;
  35102. var colors = this.colors;
  35103. var rawBytes = this.str.getBytes(rowBytes);
  35104. this.eof = !rawBytes.length;
  35105. if (this.eof) {
  35106. return;
  35107. }
  35108. var inbuf = 0, outbuf = 0;
  35109. var inbits = 0, outbits = 0;
  35110. var pos = bufferLength;
  35111. var i;
  35112. if (bits === 1) {
  35113. for (i = 0; i < rowBytes; ++i) {
  35114. var c = rawBytes[i];
  35115. inbuf = (inbuf << 8) | c;
  35116. // bitwise addition is exclusive or
  35117. // first shift inbuf and then add
  35118. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35119. // truncate inbuf (assumes colors < 16)
  35120. inbuf &= 0xFFFF;
  35121. }
  35122. } else if (bits === 8) {
  35123. for (i = 0; i < colors; ++i) {
  35124. buffer[pos++] = rawBytes[i];
  35125. }
  35126. for (; i < rowBytes; ++i) {
  35127. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35128. pos++;
  35129. }
  35130. } else {
  35131. var compArray = new Uint8Array(colors + 1);
  35132. var bitMask = (1 << bits) - 1;
  35133. var j = 0, k = bufferLength;
  35134. var columns = this.columns;
  35135. for (i = 0; i < columns; ++i) {
  35136. for (var kk = 0; kk < colors; ++kk) {
  35137. if (inbits < bits) {
  35138. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35139. inbits += 8;
  35140. }
  35141. compArray[kk] = (compArray[kk] +
  35142. (inbuf >> (inbits - bits))) & bitMask;
  35143. inbits -= bits;
  35144. outbuf = (outbuf << bits) | compArray[kk];
  35145. outbits += bits;
  35146. if (outbits >= 8) {
  35147. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35148. outbits -= 8;
  35149. }
  35150. }
  35151. }
  35152. if (outbits > 0) {
  35153. buffer[k++] = (outbuf << (8 - outbits)) +
  35154. (inbuf & ((1 << (8 - outbits)) - 1));
  35155. }
  35156. }
  35157. this.bufferLength += rowBytes;
  35158. };
  35159. PredictorStream.prototype.readBlockPng =
  35160. function predictorStreamReadBlockPng() {
  35161. var rowBytes = this.rowBytes;
  35162. var pixBytes = this.pixBytes;
  35163. var predictor = this.str.getByte();
  35164. var rawBytes = this.str.getBytes(rowBytes);
  35165. this.eof = !rawBytes.length;
  35166. if (this.eof) {
  35167. return;
  35168. }
  35169. var bufferLength = this.bufferLength;
  35170. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35171. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35172. if (prevRow.length === 0) {
  35173. prevRow = new Uint8Array(rowBytes);
  35174. }
  35175. var i, j = bufferLength, up, c;
  35176. switch (predictor) {
  35177. case 0:
  35178. for (i = 0; i < rowBytes; ++i) {
  35179. buffer[j++] = rawBytes[i];
  35180. }
  35181. break;
  35182. case 1:
  35183. for (i = 0; i < pixBytes; ++i) {
  35184. buffer[j++] = rawBytes[i];
  35185. }
  35186. for (; i < rowBytes; ++i) {
  35187. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35188. j++;
  35189. }
  35190. break;
  35191. case 2:
  35192. for (i = 0; i < rowBytes; ++i) {
  35193. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35194. }
  35195. break;
  35196. case 3:
  35197. for (i = 0; i < pixBytes; ++i) {
  35198. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35199. }
  35200. for (; i < rowBytes; ++i) {
  35201. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35202. rawBytes[i]) & 0xFF;
  35203. j++;
  35204. }
  35205. break;
  35206. case 4:
  35207. // we need to save the up left pixels values. the simplest way
  35208. // is to create a new buffer
  35209. for (i = 0; i < pixBytes; ++i) {
  35210. up = prevRow[i];
  35211. c = rawBytes[i];
  35212. buffer[j++] = up + c;
  35213. }
  35214. for (; i < rowBytes; ++i) {
  35215. up = prevRow[i];
  35216. var upLeft = prevRow[i - pixBytes];
  35217. var left = buffer[j - pixBytes];
  35218. var p = left + up - upLeft;
  35219. var pa = p - left;
  35220. if (pa < 0) {
  35221. pa = -pa;
  35222. }
  35223. var pb = p - up;
  35224. if (pb < 0) {
  35225. pb = -pb;
  35226. }
  35227. var pc = p - upLeft;
  35228. if (pc < 0) {
  35229. pc = -pc;
  35230. }
  35231. c = rawBytes[i];
  35232. if (pa <= pb && pa <= pc) {
  35233. buffer[j++] = left + c;
  35234. } else if (pb <= pc) {
  35235. buffer[j++] = up + c;
  35236. } else {
  35237. buffer[j++] = upLeft + c;
  35238. }
  35239. }
  35240. break;
  35241. default:
  35242. error('Unsupported predictor: ' + predictor);
  35243. }
  35244. this.bufferLength += rowBytes;
  35245. };
  35246. return PredictorStream;
  35247. })();
  35248. /**
  35249. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35250. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35251. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35252. * a library to decode these images and the stream behaves like all the other
  35253. * DecodeStreams.
  35254. */
  35255. var JpegStream = (function JpegStreamClosure() {
  35256. function JpegStream(stream, maybeLength, dict, xref) {
  35257. // TODO: per poppler, some images may have 'junk' before that
  35258. // need to be removed
  35259. this.stream = stream;
  35260. this.maybeLength = maybeLength;
  35261. this.dict = dict;
  35262. DecodeStream.call(this, maybeLength);
  35263. }
  35264. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35265. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35266. get: function JpegStream_bytes() {
  35267. // If this.maybeLength is null, we'll get the entire stream.
  35268. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35269. },
  35270. configurable: true
  35271. });
  35272. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35273. if (this.bufferLength) {
  35274. return;
  35275. }
  35276. try {
  35277. var jpegImage = new JpegImage();
  35278. // checking if values needs to be transformed before conversion
  35279. if (this.dict && isArray(this.dict.get('Decode'))) {
  35280. var decodeArr = this.dict.get('Decode');
  35281. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35282. var decodeArrLength = decodeArr.length;
  35283. var transform = new Int32Array(decodeArrLength);
  35284. var transformNeeded = false;
  35285. var maxValue = (1 << bitsPerComponent) - 1;
  35286. for (var i = 0; i < decodeArrLength; i += 2) {
  35287. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35288. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35289. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35290. transformNeeded = true;
  35291. }
  35292. }
  35293. if (transformNeeded) {
  35294. jpegImage.decodeTransform = transform;
  35295. }
  35296. }
  35297. jpegImage.parse(this.bytes);
  35298. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35299. this.forceRGB);
  35300. this.buffer = data;
  35301. this.bufferLength = data.length;
  35302. this.eof = true;
  35303. } catch (e) {
  35304. error('JPEG error: ' + e);
  35305. }
  35306. };
  35307. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35308. this.ensureBuffer();
  35309. return this.buffer;
  35310. };
  35311. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35312. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35313. };
  35314. /**
  35315. * Checks if the image can be decoded and displayed by the browser without any
  35316. * further processing such as color space conversions.
  35317. */
  35318. JpegStream.prototype.isNativelySupported =
  35319. function JpegStream_isNativelySupported(xref, res) {
  35320. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35321. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35322. };
  35323. /**
  35324. * Checks if the image can be decoded by the browser.
  35325. */
  35326. JpegStream.prototype.isNativelyDecodable =
  35327. function JpegStream_isNativelyDecodable(xref, res) {
  35328. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35329. var numComps = cs.numComps;
  35330. return numComps === 1 || numComps === 3;
  35331. };
  35332. return JpegStream;
  35333. })();
  35334. /**
  35335. * For JPEG 2000's we use a library to decode these images and
  35336. * the stream behaves like all the other DecodeStreams.
  35337. */
  35338. var JpxStream = (function JpxStreamClosure() {
  35339. function JpxStream(stream, maybeLength, dict) {
  35340. this.stream = stream;
  35341. this.maybeLength = maybeLength;
  35342. this.dict = dict;
  35343. DecodeStream.call(this, maybeLength);
  35344. }
  35345. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35346. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35347. get: function JpxStream_bytes() {
  35348. // If this.maybeLength is null, we'll get the entire stream.
  35349. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35350. },
  35351. configurable: true
  35352. });
  35353. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35354. if (this.bufferLength) {
  35355. return;
  35356. }
  35357. var jpxImage = new JpxImage();
  35358. jpxImage.parse(this.bytes);
  35359. var width = jpxImage.width;
  35360. var height = jpxImage.height;
  35361. var componentsCount = jpxImage.componentsCount;
  35362. var tileCount = jpxImage.tiles.length;
  35363. if (tileCount === 1) {
  35364. this.buffer = jpxImage.tiles[0].items;
  35365. } else {
  35366. var data = new Uint8Array(width * height * componentsCount);
  35367. for (var k = 0; k < tileCount; k++) {
  35368. var tileComponents = jpxImage.tiles[k];
  35369. var tileWidth = tileComponents.width;
  35370. var tileHeight = tileComponents.height;
  35371. var tileLeft = tileComponents.left;
  35372. var tileTop = tileComponents.top;
  35373. var src = tileComponents.items;
  35374. var srcPosition = 0;
  35375. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  35376. var imgRowSize = width * componentsCount;
  35377. var tileRowSize = tileWidth * componentsCount;
  35378. for (var j = 0; j < tileHeight; j++) {
  35379. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  35380. data.set(rowBytes, dataPosition);
  35381. srcPosition += tileRowSize;
  35382. dataPosition += imgRowSize;
  35383. }
  35384. }
  35385. this.buffer = data;
  35386. }
  35387. this.bufferLength = this.buffer.length;
  35388. this.eof = true;
  35389. };
  35390. return JpxStream;
  35391. })();
  35392. /**
  35393. * For JBIG2's we use a library to decode these images and
  35394. * the stream behaves like all the other DecodeStreams.
  35395. */
  35396. var Jbig2Stream = (function Jbig2StreamClosure() {
  35397. function Jbig2Stream(stream, maybeLength, dict) {
  35398. this.stream = stream;
  35399. this.maybeLength = maybeLength;
  35400. this.dict = dict;
  35401. DecodeStream.call(this, maybeLength);
  35402. }
  35403. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  35404. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  35405. get: function Jbig2Stream_bytes() {
  35406. // If this.maybeLength is null, we'll get the entire stream.
  35407. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35408. },
  35409. configurable: true
  35410. });
  35411. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  35412. if (this.bufferLength) {
  35413. return;
  35414. }
  35415. var jbig2Image = new Jbig2Image();
  35416. var chunks = [], xref = this.dict.xref;
  35417. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  35418. // According to the PDF specification, DecodeParms can be either
  35419. // a dictionary, or an array whose elements are dictionaries.
  35420. if (isArray(decodeParams)) {
  35421. if (decodeParams.length > 1) {
  35422. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  35423. 'not supported.');
  35424. }
  35425. decodeParams = xref.fetchIfRef(decodeParams[0]);
  35426. }
  35427. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  35428. var globalsStream = decodeParams.get('JBIG2Globals');
  35429. var globals = globalsStream.getBytes();
  35430. chunks.push({data: globals, start: 0, end: globals.length});
  35431. }
  35432. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  35433. var data = jbig2Image.parseChunks(chunks);
  35434. var dataLength = data.length;
  35435. // JBIG2 had black as 1 and white as 0, inverting the colors
  35436. for (var i = 0; i < dataLength; i++) {
  35437. data[i] ^= 0xFF;
  35438. }
  35439. this.buffer = data;
  35440. this.bufferLength = dataLength;
  35441. this.eof = true;
  35442. };
  35443. return Jbig2Stream;
  35444. })();
  35445. var DecryptStream = (function DecryptStreamClosure() {
  35446. function DecryptStream(str, maybeLength, decrypt) {
  35447. this.str = str;
  35448. this.dict = str.dict;
  35449. this.decrypt = decrypt;
  35450. this.nextChunk = null;
  35451. this.initialized = false;
  35452. DecodeStream.call(this, maybeLength);
  35453. }
  35454. var chunkSize = 512;
  35455. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  35456. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  35457. var chunk;
  35458. if (this.initialized) {
  35459. chunk = this.nextChunk;
  35460. } else {
  35461. chunk = this.str.getBytes(chunkSize);
  35462. this.initialized = true;
  35463. }
  35464. if (!chunk || chunk.length === 0) {
  35465. this.eof = true;
  35466. return;
  35467. }
  35468. this.nextChunk = this.str.getBytes(chunkSize);
  35469. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  35470. var decrypt = this.decrypt;
  35471. chunk = decrypt(chunk, !hasMoreData);
  35472. var bufferLength = this.bufferLength;
  35473. var i, n = chunk.length;
  35474. var buffer = this.ensureBuffer(bufferLength + n);
  35475. for (i = 0; i < n; i++) {
  35476. buffer[bufferLength++] = chunk[i];
  35477. }
  35478. this.bufferLength = bufferLength;
  35479. };
  35480. return DecryptStream;
  35481. })();
  35482. var Ascii85Stream = (function Ascii85StreamClosure() {
  35483. function Ascii85Stream(str, maybeLength) {
  35484. this.str = str;
  35485. this.dict = str.dict;
  35486. this.input = new Uint8Array(5);
  35487. // Most streams increase in size when decoded, but Ascii85 streams
  35488. // typically shrink by ~20%.
  35489. if (maybeLength) {
  35490. maybeLength = 0.8 * maybeLength;
  35491. }
  35492. DecodeStream.call(this, maybeLength);
  35493. }
  35494. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  35495. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  35496. var TILDA_CHAR = 0x7E; // '~'
  35497. var Z_LOWER_CHAR = 0x7A; // 'z'
  35498. var EOF = -1;
  35499. var str = this.str;
  35500. var c = str.getByte();
  35501. while (Lexer.isSpace(c)) {
  35502. c = str.getByte();
  35503. }
  35504. if (c === EOF || c === TILDA_CHAR) {
  35505. this.eof = true;
  35506. return;
  35507. }
  35508. var bufferLength = this.bufferLength, buffer;
  35509. var i;
  35510. // special code for z
  35511. if (c === Z_LOWER_CHAR) {
  35512. buffer = this.ensureBuffer(bufferLength + 4);
  35513. for (i = 0; i < 4; ++i) {
  35514. buffer[bufferLength + i] = 0;
  35515. }
  35516. this.bufferLength += 4;
  35517. } else {
  35518. var input = this.input;
  35519. input[0] = c;
  35520. for (i = 1; i < 5; ++i) {
  35521. c = str.getByte();
  35522. while (Lexer.isSpace(c)) {
  35523. c = str.getByte();
  35524. }
  35525. input[i] = c;
  35526. if (c === EOF || c === TILDA_CHAR) {
  35527. break;
  35528. }
  35529. }
  35530. buffer = this.ensureBuffer(bufferLength + i - 1);
  35531. this.bufferLength += i - 1;
  35532. // partial ending;
  35533. if (i < 5) {
  35534. for (; i < 5; ++i) {
  35535. input[i] = 0x21 + 84;
  35536. }
  35537. this.eof = true;
  35538. }
  35539. var t = 0;
  35540. for (i = 0; i < 5; ++i) {
  35541. t = t * 85 + (input[i] - 0x21);
  35542. }
  35543. for (i = 3; i >= 0; --i) {
  35544. buffer[bufferLength + i] = t & 0xFF;
  35545. t >>= 8;
  35546. }
  35547. }
  35548. };
  35549. return Ascii85Stream;
  35550. })();
  35551. var AsciiHexStream = (function AsciiHexStreamClosure() {
  35552. function AsciiHexStream(str, maybeLength) {
  35553. this.str = str;
  35554. this.dict = str.dict;
  35555. this.firstDigit = -1;
  35556. // Most streams increase in size when decoded, but AsciiHex streams shrink
  35557. // by 50%.
  35558. if (maybeLength) {
  35559. maybeLength = 0.5 * maybeLength;
  35560. }
  35561. DecodeStream.call(this, maybeLength);
  35562. }
  35563. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  35564. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  35565. var UPSTREAM_BLOCK_SIZE = 8000;
  35566. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  35567. if (!bytes.length) {
  35568. this.eof = true;
  35569. return;
  35570. }
  35571. var maxDecodeLength = (bytes.length + 1) >> 1;
  35572. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  35573. var bufferLength = this.bufferLength;
  35574. var firstDigit = this.firstDigit;
  35575. for (var i = 0, ii = bytes.length; i < ii; i++) {
  35576. var ch = bytes[i], digit;
  35577. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  35578. digit = ch & 0x0F;
  35579. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  35580. // 'A'-'Z', 'a'-'z'
  35581. digit = (ch & 0x0F) + 9;
  35582. } else if (ch === 0x3E) { // '>'
  35583. this.eof = true;
  35584. break;
  35585. } else { // probably whitespace
  35586. continue; // ignoring
  35587. }
  35588. if (firstDigit < 0) {
  35589. firstDigit = digit;
  35590. } else {
  35591. buffer[bufferLength++] = (firstDigit << 4) | digit;
  35592. firstDigit = -1;
  35593. }
  35594. }
  35595. if (firstDigit >= 0 && this.eof) {
  35596. // incomplete byte
  35597. buffer[bufferLength++] = (firstDigit << 4);
  35598. firstDigit = -1;
  35599. }
  35600. this.firstDigit = firstDigit;
  35601. this.bufferLength = bufferLength;
  35602. };
  35603. return AsciiHexStream;
  35604. })();
  35605. var RunLengthStream = (function RunLengthStreamClosure() {
  35606. function RunLengthStream(str, maybeLength) {
  35607. this.str = str;
  35608. this.dict = str.dict;
  35609. DecodeStream.call(this, maybeLength);
  35610. }
  35611. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  35612. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  35613. // The repeatHeader has following format. The first byte defines type of run
  35614. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  35615. // (in addition to the second byte from the header), n = 129 through 255 -
  35616. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  35617. var repeatHeader = this.str.getBytes(2);
  35618. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  35619. this.eof = true;
  35620. return;
  35621. }
  35622. var buffer;
  35623. var bufferLength = this.bufferLength;
  35624. var n = repeatHeader[0];
  35625. if (n < 128) {
  35626. // copy n bytes
  35627. buffer = this.ensureBuffer(bufferLength + n + 1);
  35628. buffer[bufferLength++] = repeatHeader[1];
  35629. if (n > 0) {
  35630. var source = this.str.getBytes(n);
  35631. buffer.set(source, bufferLength);
  35632. bufferLength += n;
  35633. }
  35634. } else {
  35635. n = 257 - n;
  35636. var b = repeatHeader[1];
  35637. buffer = this.ensureBuffer(bufferLength + n + 1);
  35638. for (var i = 0; i < n; i++) {
  35639. buffer[bufferLength++] = b;
  35640. }
  35641. }
  35642. this.bufferLength = bufferLength;
  35643. };
  35644. return RunLengthStream;
  35645. })();
  35646. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  35647. var ccittEOL = -2;
  35648. var twoDimPass = 0;
  35649. var twoDimHoriz = 1;
  35650. var twoDimVert0 = 2;
  35651. var twoDimVertR1 = 3;
  35652. var twoDimVertL1 = 4;
  35653. var twoDimVertR2 = 5;
  35654. var twoDimVertL2 = 6;
  35655. var twoDimVertR3 = 7;
  35656. var twoDimVertL3 = 8;
  35657. var twoDimTable = [
  35658. [-1, -1], [-1, -1], // 000000x
  35659. [7, twoDimVertL3], // 0000010
  35660. [7, twoDimVertR3], // 0000011
  35661. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  35662. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  35663. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  35664. [4, twoDimPass], [4, twoDimPass],
  35665. [4, twoDimPass], [4, twoDimPass],
  35666. [4, twoDimPass], [4, twoDimPass],
  35667. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  35668. [3, twoDimHoriz], [3, twoDimHoriz],
  35669. [3, twoDimHoriz], [3, twoDimHoriz],
  35670. [3, twoDimHoriz], [3, twoDimHoriz],
  35671. [3, twoDimHoriz], [3, twoDimHoriz],
  35672. [3, twoDimHoriz], [3, twoDimHoriz],
  35673. [3, twoDimHoriz], [3, twoDimHoriz],
  35674. [3, twoDimHoriz], [3, twoDimHoriz],
  35675. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  35676. [3, twoDimVertL1], [3, twoDimVertL1],
  35677. [3, twoDimVertL1], [3, twoDimVertL1],
  35678. [3, twoDimVertL1], [3, twoDimVertL1],
  35679. [3, twoDimVertL1], [3, twoDimVertL1],
  35680. [3, twoDimVertL1], [3, twoDimVertL1],
  35681. [3, twoDimVertL1], [3, twoDimVertL1],
  35682. [3, twoDimVertL1], [3, twoDimVertL1],
  35683. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  35684. [3, twoDimVertR1], [3, twoDimVertR1],
  35685. [3, twoDimVertR1], [3, twoDimVertR1],
  35686. [3, twoDimVertR1], [3, twoDimVertR1],
  35687. [3, twoDimVertR1], [3, twoDimVertR1],
  35688. [3, twoDimVertR1], [3, twoDimVertR1],
  35689. [3, twoDimVertR1], [3, twoDimVertR1],
  35690. [3, twoDimVertR1], [3, twoDimVertR1],
  35691. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  35692. [1, twoDimVert0], [1, twoDimVert0],
  35693. [1, twoDimVert0], [1, twoDimVert0],
  35694. [1, twoDimVert0], [1, twoDimVert0],
  35695. [1, twoDimVert0], [1, twoDimVert0],
  35696. [1, twoDimVert0], [1, twoDimVert0],
  35697. [1, twoDimVert0], [1, twoDimVert0],
  35698. [1, twoDimVert0], [1, twoDimVert0],
  35699. [1, twoDimVert0], [1, twoDimVert0],
  35700. [1, twoDimVert0], [1, twoDimVert0],
  35701. [1, twoDimVert0], [1, twoDimVert0],
  35702. [1, twoDimVert0], [1, twoDimVert0],
  35703. [1, twoDimVert0], [1, twoDimVert0],
  35704. [1, twoDimVert0], [1, twoDimVert0],
  35705. [1, twoDimVert0], [1, twoDimVert0],
  35706. [1, twoDimVert0], [1, twoDimVert0],
  35707. [1, twoDimVert0], [1, twoDimVert0],
  35708. [1, twoDimVert0], [1, twoDimVert0],
  35709. [1, twoDimVert0], [1, twoDimVert0],
  35710. [1, twoDimVert0], [1, twoDimVert0],
  35711. [1, twoDimVert0], [1, twoDimVert0],
  35712. [1, twoDimVert0], [1, twoDimVert0],
  35713. [1, twoDimVert0], [1, twoDimVert0],
  35714. [1, twoDimVert0], [1, twoDimVert0],
  35715. [1, twoDimVert0], [1, twoDimVert0],
  35716. [1, twoDimVert0], [1, twoDimVert0],
  35717. [1, twoDimVert0], [1, twoDimVert0],
  35718. [1, twoDimVert0], [1, twoDimVert0],
  35719. [1, twoDimVert0], [1, twoDimVert0],
  35720. [1, twoDimVert0], [1, twoDimVert0],
  35721. [1, twoDimVert0], [1, twoDimVert0],
  35722. [1, twoDimVert0], [1, twoDimVert0]
  35723. ];
  35724. var whiteTable1 = [
  35725. [-1, -1], // 00000
  35726. [12, ccittEOL], // 00001
  35727. [-1, -1], [-1, -1], // 0001x
  35728. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  35729. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  35730. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  35731. [11, 1792], [11, 1792], // 1000x
  35732. [12, 1984], // 10010
  35733. [12, 2048], // 10011
  35734. [12, 2112], // 10100
  35735. [12, 2176], // 10101
  35736. [12, 2240], // 10110
  35737. [12, 2304], // 10111
  35738. [11, 1856], [11, 1856], // 1100x
  35739. [11, 1920], [11, 1920], // 1101x
  35740. [12, 2368], // 11100
  35741. [12, 2432], // 11101
  35742. [12, 2496], // 11110
  35743. [12, 2560] // 11111
  35744. ];
  35745. var whiteTable2 = [
  35746. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  35747. [8, 29], [8, 29], // 00000010x
  35748. [8, 30], [8, 30], // 00000011x
  35749. [8, 45], [8, 45], // 00000100x
  35750. [8, 46], [8, 46], // 00000101x
  35751. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  35752. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  35753. [8, 47], [8, 47], // 00001010x
  35754. [8, 48], [8, 48], // 00001011x
  35755. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  35756. [6, 13], [6, 13], [6, 13], [6, 13],
  35757. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  35758. [8, 33], [8, 33], // 00010010x
  35759. [8, 34], [8, 34], // 00010011x
  35760. [8, 35], [8, 35], // 00010100x
  35761. [8, 36], [8, 36], // 00010101x
  35762. [8, 37], [8, 37], // 00010110x
  35763. [8, 38], [8, 38], // 00010111x
  35764. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  35765. [8, 31], [8, 31], // 00011010x
  35766. [8, 32], [8, 32], // 00011011x
  35767. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  35768. [6, 1], [6, 1], [6, 1], [6, 1],
  35769. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  35770. [6, 12], [6, 12], [6, 12], [6, 12],
  35771. [8, 53], [8, 53], // 00100100x
  35772. [8, 54], [8, 54], // 00100101x
  35773. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  35774. [8, 39], [8, 39], // 00101000x
  35775. [8, 40], [8, 40], // 00101001x
  35776. [8, 41], [8, 41], // 00101010x
  35777. [8, 42], [8, 42], // 00101011x
  35778. [8, 43], [8, 43], // 00101100x
  35779. [8, 44], [8, 44], // 00101101x
  35780. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  35781. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  35782. [8, 61], [8, 61], // 00110010x
  35783. [8, 62], [8, 62], // 00110011x
  35784. [8, 63], [8, 63], // 00110100x
  35785. [8, 0], [8, 0], // 00110101x
  35786. [8, 320], [8, 320], // 00110110x
  35787. [8, 384], [8, 384], // 00110111x
  35788. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  35789. [5, 10], [5, 10], [5, 10], [5, 10],
  35790. [5, 10], [5, 10], [5, 10], [5, 10],
  35791. [5, 10], [5, 10], [5, 10], [5, 10],
  35792. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  35793. [5, 11], [5, 11], [5, 11], [5, 11],
  35794. [5, 11], [5, 11], [5, 11], [5, 11],
  35795. [5, 11], [5, 11], [5, 11], [5, 11],
  35796. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  35797. [8, 59], [8, 59], // 01001010x
  35798. [8, 60], [8, 60], // 01001011x
  35799. [9, 1472], // 010011000
  35800. [9, 1536], // 010011001
  35801. [9, 1600], // 010011010
  35802. [9, 1728], // 010011011
  35803. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  35804. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  35805. [8, 49], [8, 49], // 01010010x
  35806. [8, 50], [8, 50], // 01010011x
  35807. [8, 51], [8, 51], // 01010100x
  35808. [8, 52], [8, 52], // 01010101x
  35809. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  35810. [8, 55], [8, 55], // 01011000x
  35811. [8, 56], [8, 56], // 01011001x
  35812. [8, 57], [8, 57], // 01011010x
  35813. [8, 58], [8, 58], // 01011011x
  35814. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  35815. [6, 192], [6, 192], [6, 192], [6, 192],
  35816. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  35817. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  35818. [8, 448], [8, 448], // 01100100x
  35819. [8, 512], [8, 512], // 01100101x
  35820. [9, 704], // 011001100
  35821. [9, 768], // 011001101
  35822. [8, 640], [8, 640], // 01100111x
  35823. [8, 576], [8, 576], // 01101000x
  35824. [9, 832], // 011010010
  35825. [9, 896], // 011010011
  35826. [9, 960], // 011010100
  35827. [9, 1024], // 011010101
  35828. [9, 1088], // 011010110
  35829. [9, 1152], // 011010111
  35830. [9, 1216], // 011011000
  35831. [9, 1280], // 011011001
  35832. [9, 1344], // 011011010
  35833. [9, 1408], // 011011011
  35834. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  35835. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  35836. [4, 2], [4, 2], [4, 2], [4, 2],
  35837. [4, 2], [4, 2], [4, 2], [4, 2],
  35838. [4, 2], [4, 2], [4, 2], [4, 2],
  35839. [4, 2], [4, 2], [4, 2], [4, 2],
  35840. [4, 2], [4, 2], [4, 2], [4, 2],
  35841. [4, 2], [4, 2], [4, 2], [4, 2],
  35842. [4, 2], [4, 2], [4, 2], [4, 2],
  35843. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  35844. [4, 3], [4, 3], [4, 3], [4, 3],
  35845. [4, 3], [4, 3], [4, 3], [4, 3],
  35846. [4, 3], [4, 3], [4, 3], [4, 3],
  35847. [4, 3], [4, 3], [4, 3], [4, 3],
  35848. [4, 3], [4, 3], [4, 3], [4, 3],
  35849. [4, 3], [4, 3], [4, 3], [4, 3],
  35850. [4, 3], [4, 3], [4, 3], [4, 3],
  35851. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  35852. [5, 128], [5, 128], [5, 128], [5, 128],
  35853. [5, 128], [5, 128], [5, 128], [5, 128],
  35854. [5, 128], [5, 128], [5, 128], [5, 128],
  35855. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  35856. [5, 8], [5, 8], [5, 8], [5, 8],
  35857. [5, 8], [5, 8], [5, 8], [5, 8],
  35858. [5, 8], [5, 8], [5, 8], [5, 8],
  35859. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  35860. [5, 9], [5, 9], [5, 9], [5, 9],
  35861. [5, 9], [5, 9], [5, 9], [5, 9],
  35862. [5, 9], [5, 9], [5, 9], [5, 9],
  35863. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  35864. [6, 16], [6, 16], [6, 16], [6, 16],
  35865. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  35866. [6, 17], [6, 17], [6, 17], [6, 17],
  35867. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  35868. [4, 4], [4, 4], [4, 4], [4, 4],
  35869. [4, 4], [4, 4], [4, 4], [4, 4],
  35870. [4, 4], [4, 4], [4, 4], [4, 4],
  35871. [4, 4], [4, 4], [4, 4], [4, 4],
  35872. [4, 4], [4, 4], [4, 4], [4, 4],
  35873. [4, 4], [4, 4], [4, 4], [4, 4],
  35874. [4, 4], [4, 4], [4, 4], [4, 4],
  35875. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  35876. [4, 5], [4, 5], [4, 5], [4, 5],
  35877. [4, 5], [4, 5], [4, 5], [4, 5],
  35878. [4, 5], [4, 5], [4, 5], [4, 5],
  35879. [4, 5], [4, 5], [4, 5], [4, 5],
  35880. [4, 5], [4, 5], [4, 5], [4, 5],
  35881. [4, 5], [4, 5], [4, 5], [4, 5],
  35882. [4, 5], [4, 5], [4, 5], [4, 5],
  35883. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  35884. [6, 14], [6, 14], [6, 14], [6, 14],
  35885. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  35886. [6, 15], [6, 15], [6, 15], [6, 15],
  35887. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  35888. [5, 64], [5, 64], [5, 64], [5, 64],
  35889. [5, 64], [5, 64], [5, 64], [5, 64],
  35890. [5, 64], [5, 64], [5, 64], [5, 64],
  35891. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  35892. [4, 6], [4, 6], [4, 6], [4, 6],
  35893. [4, 6], [4, 6], [4, 6], [4, 6],
  35894. [4, 6], [4, 6], [4, 6], [4, 6],
  35895. [4, 6], [4, 6], [4, 6], [4, 6],
  35896. [4, 6], [4, 6], [4, 6], [4, 6],
  35897. [4, 6], [4, 6], [4, 6], [4, 6],
  35898. [4, 6], [4, 6], [4, 6], [4, 6],
  35899. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  35900. [4, 7], [4, 7], [4, 7], [4, 7],
  35901. [4, 7], [4, 7], [4, 7], [4, 7],
  35902. [4, 7], [4, 7], [4, 7], [4, 7],
  35903. [4, 7], [4, 7], [4, 7], [4, 7],
  35904. [4, 7], [4, 7], [4, 7], [4, 7],
  35905. [4, 7], [4, 7], [4, 7], [4, 7],
  35906. [4, 7], [4, 7], [4, 7], [4, 7]
  35907. ];
  35908. var blackTable1 = [
  35909. [-1, -1], [-1, -1], // 000000000000x
  35910. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  35911. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  35912. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  35913. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  35914. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  35915. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  35916. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  35917. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  35918. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  35919. [12, 1984], [12, 1984], // 000000010010x
  35920. [12, 2048], [12, 2048], // 000000010011x
  35921. [12, 2112], [12, 2112], // 000000010100x
  35922. [12, 2176], [12, 2176], // 000000010101x
  35923. [12, 2240], [12, 2240], // 000000010110x
  35924. [12, 2304], [12, 2304], // 000000010111x
  35925. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  35926. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  35927. [12, 2368], [12, 2368], // 000000011100x
  35928. [12, 2432], [12, 2432], // 000000011101x
  35929. [12, 2496], [12, 2496], // 000000011110x
  35930. [12, 2560], [12, 2560], // 000000011111x
  35931. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  35932. [10, 18], [10, 18], [10, 18], [10, 18],
  35933. [12, 52], [12, 52], // 000000100100x
  35934. [13, 640], // 0000001001010
  35935. [13, 704], // 0000001001011
  35936. [13, 768], // 0000001001100
  35937. [13, 832], // 0000001001101
  35938. [12, 55], [12, 55], // 000000100111x
  35939. [12, 56], [12, 56], // 000000101000x
  35940. [13, 1280], // 0000001010010
  35941. [13, 1344], // 0000001010011
  35942. [13, 1408], // 0000001010100
  35943. [13, 1472], // 0000001010101
  35944. [12, 59], [12, 59], // 000000101011x
  35945. [12, 60], [12, 60], // 000000101100x
  35946. [13, 1536], // 0000001011010
  35947. [13, 1600], // 0000001011011
  35948. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  35949. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  35950. [13, 1664], // 0000001100100
  35951. [13, 1728], // 0000001100101
  35952. [12, 320], [12, 320], // 000000110011x
  35953. [12, 384], [12, 384], // 000000110100x
  35954. [12, 448], [12, 448], // 000000110101x
  35955. [13, 512], // 0000001101100
  35956. [13, 576], // 0000001101101
  35957. [12, 53], [12, 53], // 000000110111x
  35958. [12, 54], [12, 54], // 000000111000x
  35959. [13, 896], // 0000001110010
  35960. [13, 960], // 0000001110011
  35961. [13, 1024], // 0000001110100
  35962. [13, 1088], // 0000001110101
  35963. [13, 1152], // 0000001110110
  35964. [13, 1216], // 0000001110111
  35965. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  35966. [10, 64], [10, 64], [10, 64], [10, 64]
  35967. ];
  35968. var blackTable2 = [
  35969. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  35970. [8, 13], [8, 13], [8, 13], [8, 13],
  35971. [8, 13], [8, 13], [8, 13], [8, 13],
  35972. [8, 13], [8, 13], [8, 13], [8, 13],
  35973. [11, 23], [11, 23], // 00000101000x
  35974. [12, 50], // 000001010010
  35975. [12, 51], // 000001010011
  35976. [12, 44], // 000001010100
  35977. [12, 45], // 000001010101
  35978. [12, 46], // 000001010110
  35979. [12, 47], // 000001010111
  35980. [12, 57], // 000001011000
  35981. [12, 58], // 000001011001
  35982. [12, 61], // 000001011010
  35983. [12, 256], // 000001011011
  35984. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  35985. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  35986. [12, 48], // 000001100100
  35987. [12, 49], // 000001100101
  35988. [12, 62], // 000001100110
  35989. [12, 63], // 000001100111
  35990. [12, 30], // 000001101000
  35991. [12, 31], // 000001101001
  35992. [12, 32], // 000001101010
  35993. [12, 33], // 000001101011
  35994. [12, 40], // 000001101100
  35995. [12, 41], // 000001101101
  35996. [11, 22], [11, 22], // 00000110111x
  35997. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  35998. [8, 14], [8, 14], [8, 14], [8, 14],
  35999. [8, 14], [8, 14], [8, 14], [8, 14],
  36000. [8, 14], [8, 14], [8, 14], [8, 14],
  36001. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36002. [7, 10], [7, 10], [7, 10], [7, 10],
  36003. [7, 10], [7, 10], [7, 10], [7, 10],
  36004. [7, 10], [7, 10], [7, 10], [7, 10],
  36005. [7, 10], [7, 10], [7, 10], [7, 10],
  36006. [7, 10], [7, 10], [7, 10], [7, 10],
  36007. [7, 10], [7, 10], [7, 10], [7, 10],
  36008. [7, 10], [7, 10], [7, 10], [7, 10],
  36009. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36010. [7, 11], [7, 11], [7, 11], [7, 11],
  36011. [7, 11], [7, 11], [7, 11], [7, 11],
  36012. [7, 11], [7, 11], [7, 11], [7, 11],
  36013. [7, 11], [7, 11], [7, 11], [7, 11],
  36014. [7, 11], [7, 11], [7, 11], [7, 11],
  36015. [7, 11], [7, 11], [7, 11], [7, 11],
  36016. [7, 11], [7, 11], [7, 11], [7, 11],
  36017. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36018. [9, 15], [9, 15], [9, 15], [9, 15],
  36019. [12, 128], // 000011001000
  36020. [12, 192], // 000011001001
  36021. [12, 26], // 000011001010
  36022. [12, 27], // 000011001011
  36023. [12, 28], // 000011001100
  36024. [12, 29], // 000011001101
  36025. [11, 19], [11, 19], // 00001100111x
  36026. [11, 20], [11, 20], // 00001101000x
  36027. [12, 34], // 000011010010
  36028. [12, 35], // 000011010011
  36029. [12, 36], // 000011010100
  36030. [12, 37], // 000011010101
  36031. [12, 38], // 000011010110
  36032. [12, 39], // 000011010111
  36033. [11, 21], [11, 21], // 00001101100x
  36034. [12, 42], // 000011011010
  36035. [12, 43], // 000011011011
  36036. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36037. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36038. [7, 12], [7, 12], [7, 12], [7, 12],
  36039. [7, 12], [7, 12], [7, 12], [7, 12],
  36040. [7, 12], [7, 12], [7, 12], [7, 12],
  36041. [7, 12], [7, 12], [7, 12], [7, 12],
  36042. [7, 12], [7, 12], [7, 12], [7, 12],
  36043. [7, 12], [7, 12], [7, 12], [7, 12],
  36044. [7, 12], [7, 12], [7, 12], [7, 12]
  36045. ];
  36046. var blackTable3 = [
  36047. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36048. [6, 9], // 000100
  36049. [6, 8], // 000101
  36050. [5, 7], [5, 7], // 00011x
  36051. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36052. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36053. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36054. [3, 1], [3, 1], [3, 1], [3, 1],
  36055. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36056. [3, 4], [3, 4], [3, 4], [3, 4],
  36057. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36058. [2, 3], [2, 3], [2, 3], [2, 3],
  36059. [2, 3], [2, 3], [2, 3], [2, 3],
  36060. [2, 3], [2, 3], [2, 3], [2, 3],
  36061. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36062. [2, 2], [2, 2], [2, 2], [2, 2],
  36063. [2, 2], [2, 2], [2, 2], [2, 2],
  36064. [2, 2], [2, 2], [2, 2], [2, 2]
  36065. ];
  36066. function CCITTFaxStream(str, maybeLength, params) {
  36067. this.str = str;
  36068. this.dict = str.dict;
  36069. params = params || Dict.empty;
  36070. this.encoding = params.get('K') || 0;
  36071. this.eoline = params.get('EndOfLine') || false;
  36072. this.byteAlign = params.get('EncodedByteAlign') || false;
  36073. this.columns = params.get('Columns') || 1728;
  36074. this.rows = params.get('Rows') || 0;
  36075. var eoblock = params.get('EndOfBlock');
  36076. if (eoblock === null || eoblock === undefined) {
  36077. eoblock = true;
  36078. }
  36079. this.eoblock = eoblock;
  36080. this.black = params.get('BlackIs1') || false;
  36081. this.codingLine = new Uint32Array(this.columns + 1);
  36082. this.refLine = new Uint32Array(this.columns + 2);
  36083. this.codingLine[0] = this.columns;
  36084. this.codingPos = 0;
  36085. this.row = 0;
  36086. this.nextLine2D = this.encoding < 0;
  36087. this.inputBits = 0;
  36088. this.inputBuf = 0;
  36089. this.outputBits = 0;
  36090. var code1;
  36091. while ((code1 = this.lookBits(12)) === 0) {
  36092. this.eatBits(1);
  36093. }
  36094. if (code1 === 1) {
  36095. this.eatBits(12);
  36096. }
  36097. if (this.encoding > 0) {
  36098. this.nextLine2D = !this.lookBits(1);
  36099. this.eatBits(1);
  36100. }
  36101. DecodeStream.call(this, maybeLength);
  36102. }
  36103. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36104. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36105. while (!this.eof) {
  36106. var c = this.lookChar();
  36107. this.ensureBuffer(this.bufferLength + 1);
  36108. this.buffer[this.bufferLength++] = c;
  36109. }
  36110. };
  36111. CCITTFaxStream.prototype.addPixels =
  36112. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36113. var codingLine = this.codingLine;
  36114. var codingPos = this.codingPos;
  36115. if (a1 > codingLine[codingPos]) {
  36116. if (a1 > this.columns) {
  36117. info('row is wrong length');
  36118. this.err = true;
  36119. a1 = this.columns;
  36120. }
  36121. if ((codingPos & 1) ^ blackPixels) {
  36122. ++codingPos;
  36123. }
  36124. codingLine[codingPos] = a1;
  36125. }
  36126. this.codingPos = codingPos;
  36127. };
  36128. CCITTFaxStream.prototype.addPixelsNeg =
  36129. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36130. var codingLine = this.codingLine;
  36131. var codingPos = this.codingPos;
  36132. if (a1 > codingLine[codingPos]) {
  36133. if (a1 > this.columns) {
  36134. info('row is wrong length');
  36135. this.err = true;
  36136. a1 = this.columns;
  36137. }
  36138. if ((codingPos & 1) ^ blackPixels) {
  36139. ++codingPos;
  36140. }
  36141. codingLine[codingPos] = a1;
  36142. } else if (a1 < codingLine[codingPos]) {
  36143. if (a1 < 0) {
  36144. info('invalid code');
  36145. this.err = true;
  36146. a1 = 0;
  36147. }
  36148. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36149. --codingPos;
  36150. }
  36151. codingLine[codingPos] = a1;
  36152. }
  36153. this.codingPos = codingPos;
  36154. };
  36155. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36156. var refLine = this.refLine;
  36157. var codingLine = this.codingLine;
  36158. var columns = this.columns;
  36159. var refPos, blackPixels, bits, i;
  36160. if (this.outputBits === 0) {
  36161. if (this.eof) {
  36162. return null;
  36163. }
  36164. this.err = false;
  36165. var code1, code2, code3;
  36166. if (this.nextLine2D) {
  36167. for (i = 0; codingLine[i] < columns; ++i) {
  36168. refLine[i] = codingLine[i];
  36169. }
  36170. refLine[i++] = columns;
  36171. refLine[i] = columns;
  36172. codingLine[0] = 0;
  36173. this.codingPos = 0;
  36174. refPos = 0;
  36175. blackPixels = 0;
  36176. while (codingLine[this.codingPos] < columns) {
  36177. code1 = this.getTwoDimCode();
  36178. switch (code1) {
  36179. case twoDimPass:
  36180. this.addPixels(refLine[refPos + 1], blackPixels);
  36181. if (refLine[refPos + 1] < columns) {
  36182. refPos += 2;
  36183. }
  36184. break;
  36185. case twoDimHoriz:
  36186. code1 = code2 = 0;
  36187. if (blackPixels) {
  36188. do {
  36189. code1 += (code3 = this.getBlackCode());
  36190. } while (code3 >= 64);
  36191. do {
  36192. code2 += (code3 = this.getWhiteCode());
  36193. } while (code3 >= 64);
  36194. } else {
  36195. do {
  36196. code1 += (code3 = this.getWhiteCode());
  36197. } while (code3 >= 64);
  36198. do {
  36199. code2 += (code3 = this.getBlackCode());
  36200. } while (code3 >= 64);
  36201. }
  36202. this.addPixels(codingLine[this.codingPos] +
  36203. code1, blackPixels);
  36204. if (codingLine[this.codingPos] < columns) {
  36205. this.addPixels(codingLine[this.codingPos] + code2,
  36206. blackPixels ^ 1);
  36207. }
  36208. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36209. refLine[refPos] < columns) {
  36210. refPos += 2;
  36211. }
  36212. break;
  36213. case twoDimVertR3:
  36214. this.addPixels(refLine[refPos] + 3, blackPixels);
  36215. blackPixels ^= 1;
  36216. if (codingLine[this.codingPos] < columns) {
  36217. ++refPos;
  36218. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36219. refLine[refPos] < columns) {
  36220. refPos += 2;
  36221. }
  36222. }
  36223. break;
  36224. case twoDimVertR2:
  36225. this.addPixels(refLine[refPos] + 2, blackPixels);
  36226. blackPixels ^= 1;
  36227. if (codingLine[this.codingPos] < columns) {
  36228. ++refPos;
  36229. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36230. refLine[refPos] < columns) {
  36231. refPos += 2;
  36232. }
  36233. }
  36234. break;
  36235. case twoDimVertR1:
  36236. this.addPixels(refLine[refPos] + 1, blackPixels);
  36237. blackPixels ^= 1;
  36238. if (codingLine[this.codingPos] < columns) {
  36239. ++refPos;
  36240. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36241. refLine[refPos] < columns) {
  36242. refPos += 2;
  36243. }
  36244. }
  36245. break;
  36246. case twoDimVert0:
  36247. this.addPixels(refLine[refPos], blackPixels);
  36248. blackPixels ^= 1;
  36249. if (codingLine[this.codingPos] < columns) {
  36250. ++refPos;
  36251. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36252. refLine[refPos] < columns) {
  36253. refPos += 2;
  36254. }
  36255. }
  36256. break;
  36257. case twoDimVertL3:
  36258. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36259. blackPixels ^= 1;
  36260. if (codingLine[this.codingPos] < columns) {
  36261. if (refPos > 0) {
  36262. --refPos;
  36263. } else {
  36264. ++refPos;
  36265. }
  36266. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36267. refLine[refPos] < columns) {
  36268. refPos += 2;
  36269. }
  36270. }
  36271. break;
  36272. case twoDimVertL2:
  36273. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36274. blackPixels ^= 1;
  36275. if (codingLine[this.codingPos] < columns) {
  36276. if (refPos > 0) {
  36277. --refPos;
  36278. } else {
  36279. ++refPos;
  36280. }
  36281. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36282. refLine[refPos] < columns) {
  36283. refPos += 2;
  36284. }
  36285. }
  36286. break;
  36287. case twoDimVertL1:
  36288. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36289. blackPixels ^= 1;
  36290. if (codingLine[this.codingPos] < columns) {
  36291. if (refPos > 0) {
  36292. --refPos;
  36293. } else {
  36294. ++refPos;
  36295. }
  36296. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36297. refLine[refPos] < columns) {
  36298. refPos += 2;
  36299. }
  36300. }
  36301. break;
  36302. case EOF:
  36303. this.addPixels(columns, 0);
  36304. this.eof = true;
  36305. break;
  36306. default:
  36307. info('bad 2d code');
  36308. this.addPixels(columns, 0);
  36309. this.err = true;
  36310. }
  36311. }
  36312. } else {
  36313. codingLine[0] = 0;
  36314. this.codingPos = 0;
  36315. blackPixels = 0;
  36316. while (codingLine[this.codingPos] < columns) {
  36317. code1 = 0;
  36318. if (blackPixels) {
  36319. do {
  36320. code1 += (code3 = this.getBlackCode());
  36321. } while (code3 >= 64);
  36322. } else {
  36323. do {
  36324. code1 += (code3 = this.getWhiteCode());
  36325. } while (code3 >= 64);
  36326. }
  36327. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36328. blackPixels ^= 1;
  36329. }
  36330. }
  36331. var gotEOL = false;
  36332. if (!this.eoblock && this.row === this.rows - 1) {
  36333. this.eof = true;
  36334. } else if (this.eoline || !this.byteAlign) {
  36335. code1 = this.lookBits(12);
  36336. if (this.eoline) {
  36337. while (code1 !== EOF && code1 !== 1) {
  36338. this.eatBits(1);
  36339. code1 = this.lookBits(12);
  36340. }
  36341. } else {
  36342. while (code1 === 0) {
  36343. this.eatBits(1);
  36344. code1 = this.lookBits(12);
  36345. }
  36346. }
  36347. if (code1 === 1) {
  36348. this.eatBits(12);
  36349. gotEOL = true;
  36350. } else if (code1 === EOF) {
  36351. this.eof = true;
  36352. }
  36353. }
  36354. if (this.byteAlign && !gotEOL) {
  36355. this.inputBits &= ~7;
  36356. }
  36357. if (!this.eof && this.encoding > 0) {
  36358. this.nextLine2D = !this.lookBits(1);
  36359. this.eatBits(1);
  36360. }
  36361. if (this.eoblock && gotEOL && this.byteAlign) {
  36362. code1 = this.lookBits(12);
  36363. if (code1 === 1) {
  36364. this.eatBits(12);
  36365. if (this.encoding > 0) {
  36366. this.lookBits(1);
  36367. this.eatBits(1);
  36368. }
  36369. if (this.encoding >= 0) {
  36370. for (i = 0; i < 4; ++i) {
  36371. code1 = this.lookBits(12);
  36372. if (code1 !== 1) {
  36373. info('bad rtc code: ' + code1);
  36374. }
  36375. this.eatBits(12);
  36376. if (this.encoding > 0) {
  36377. this.lookBits(1);
  36378. this.eatBits(1);
  36379. }
  36380. }
  36381. }
  36382. this.eof = true;
  36383. }
  36384. } else if (this.err && this.eoline) {
  36385. while (true) {
  36386. code1 = this.lookBits(13);
  36387. if (code1 === EOF) {
  36388. this.eof = true;
  36389. return null;
  36390. }
  36391. if ((code1 >> 1) === 1) {
  36392. break;
  36393. }
  36394. this.eatBits(1);
  36395. }
  36396. this.eatBits(12);
  36397. if (this.encoding > 0) {
  36398. this.eatBits(1);
  36399. this.nextLine2D = !(code1 & 1);
  36400. }
  36401. }
  36402. if (codingLine[0] > 0) {
  36403. this.outputBits = codingLine[this.codingPos = 0];
  36404. } else {
  36405. this.outputBits = codingLine[this.codingPos = 1];
  36406. }
  36407. this.row++;
  36408. }
  36409. var c;
  36410. if (this.outputBits >= 8) {
  36411. c = (this.codingPos & 1) ? 0 : 0xFF;
  36412. this.outputBits -= 8;
  36413. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  36414. this.codingPos++;
  36415. this.outputBits = (codingLine[this.codingPos] -
  36416. codingLine[this.codingPos - 1]);
  36417. }
  36418. } else {
  36419. bits = 8;
  36420. c = 0;
  36421. do {
  36422. if (this.outputBits > bits) {
  36423. c <<= bits;
  36424. if (!(this.codingPos & 1)) {
  36425. c |= 0xFF >> (8 - bits);
  36426. }
  36427. this.outputBits -= bits;
  36428. bits = 0;
  36429. } else {
  36430. c <<= this.outputBits;
  36431. if (!(this.codingPos & 1)) {
  36432. c |= 0xFF >> (8 - this.outputBits);
  36433. }
  36434. bits -= this.outputBits;
  36435. this.outputBits = 0;
  36436. if (codingLine[this.codingPos] < columns) {
  36437. this.codingPos++;
  36438. this.outputBits = (codingLine[this.codingPos] -
  36439. codingLine[this.codingPos - 1]);
  36440. } else if (bits > 0) {
  36441. c <<= bits;
  36442. bits = 0;
  36443. }
  36444. }
  36445. } while (bits);
  36446. }
  36447. if (this.black) {
  36448. c ^= 0xFF;
  36449. }
  36450. return c;
  36451. };
  36452. // This functions returns the code found from the table.
  36453. // The start and end parameters set the boundaries for searching the table.
  36454. // The limit parameter is optional. Function returns an array with three
  36455. // values. The first array element indicates whether a valid code is being
  36456. // returned. The second array element is the actual code. The third array
  36457. // element indicates whether EOF was reached.
  36458. CCITTFaxStream.prototype.findTableCode =
  36459. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  36460. var limitValue = limit || 0;
  36461. for (var i = start; i <= end; ++i) {
  36462. var code = this.lookBits(i);
  36463. if (code === EOF) {
  36464. return [true, 1, false];
  36465. }
  36466. if (i < end) {
  36467. code <<= end - i;
  36468. }
  36469. if (!limitValue || code >= limitValue) {
  36470. var p = table[code - limitValue];
  36471. if (p[0] === i) {
  36472. this.eatBits(i);
  36473. return [true, p[1], true];
  36474. }
  36475. }
  36476. }
  36477. return [false, 0, false];
  36478. };
  36479. CCITTFaxStream.prototype.getTwoDimCode =
  36480. function ccittFaxStreamGetTwoDimCode() {
  36481. var code = 0;
  36482. var p;
  36483. if (this.eoblock) {
  36484. code = this.lookBits(7);
  36485. p = twoDimTable[code];
  36486. if (p && p[0] > 0) {
  36487. this.eatBits(p[0]);
  36488. return p[1];
  36489. }
  36490. } else {
  36491. var result = this.findTableCode(1, 7, twoDimTable);
  36492. if (result[0] && result[2]) {
  36493. return result[1];
  36494. }
  36495. }
  36496. info('Bad two dim code');
  36497. return EOF;
  36498. };
  36499. CCITTFaxStream.prototype.getWhiteCode =
  36500. function ccittFaxStreamGetWhiteCode() {
  36501. var code = 0;
  36502. var p;
  36503. if (this.eoblock) {
  36504. code = this.lookBits(12);
  36505. if (code === EOF) {
  36506. return 1;
  36507. }
  36508. if ((code >> 5) === 0) {
  36509. p = whiteTable1[code];
  36510. } else {
  36511. p = whiteTable2[code >> 3];
  36512. }
  36513. if (p[0] > 0) {
  36514. this.eatBits(p[0]);
  36515. return p[1];
  36516. }
  36517. } else {
  36518. var result = this.findTableCode(1, 9, whiteTable2);
  36519. if (result[0]) {
  36520. return result[1];
  36521. }
  36522. result = this.findTableCode(11, 12, whiteTable1);
  36523. if (result[0]) {
  36524. return result[1];
  36525. }
  36526. }
  36527. info('bad white code');
  36528. this.eatBits(1);
  36529. return 1;
  36530. };
  36531. CCITTFaxStream.prototype.getBlackCode =
  36532. function ccittFaxStreamGetBlackCode() {
  36533. var code, p;
  36534. if (this.eoblock) {
  36535. code = this.lookBits(13);
  36536. if (code === EOF) {
  36537. return 1;
  36538. }
  36539. if ((code >> 7) === 0) {
  36540. p = blackTable1[code];
  36541. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  36542. p = blackTable2[(code >> 1) - 64];
  36543. } else {
  36544. p = blackTable3[code >> 7];
  36545. }
  36546. if (p[0] > 0) {
  36547. this.eatBits(p[0]);
  36548. return p[1];
  36549. }
  36550. } else {
  36551. var result = this.findTableCode(2, 6, blackTable3);
  36552. if (result[0]) {
  36553. return result[1];
  36554. }
  36555. result = this.findTableCode(7, 12, blackTable2, 64);
  36556. if (result[0]) {
  36557. return result[1];
  36558. }
  36559. result = this.findTableCode(10, 13, blackTable1);
  36560. if (result[0]) {
  36561. return result[1];
  36562. }
  36563. }
  36564. info('bad black code');
  36565. this.eatBits(1);
  36566. return 1;
  36567. };
  36568. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  36569. var c;
  36570. while (this.inputBits < n) {
  36571. if ((c = this.str.getByte()) === -1) {
  36572. if (this.inputBits === 0) {
  36573. return EOF;
  36574. }
  36575. return ((this.inputBuf << (n - this.inputBits)) &
  36576. (0xFFFF >> (16 - n)));
  36577. }
  36578. this.inputBuf = (this.inputBuf << 8) + c;
  36579. this.inputBits += 8;
  36580. }
  36581. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  36582. };
  36583. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  36584. if ((this.inputBits -= n) < 0) {
  36585. this.inputBits = 0;
  36586. }
  36587. };
  36588. return CCITTFaxStream;
  36589. })();
  36590. var LZWStream = (function LZWStreamClosure() {
  36591. function LZWStream(str, maybeLength, earlyChange) {
  36592. this.str = str;
  36593. this.dict = str.dict;
  36594. this.cachedData = 0;
  36595. this.bitsCached = 0;
  36596. var maxLzwDictionarySize = 4096;
  36597. var lzwState = {
  36598. earlyChange: earlyChange,
  36599. codeLength: 9,
  36600. nextCode: 258,
  36601. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  36602. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  36603. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  36604. currentSequence: new Uint8Array(maxLzwDictionarySize),
  36605. currentSequenceLength: 0
  36606. };
  36607. for (var i = 0; i < 256; ++i) {
  36608. lzwState.dictionaryValues[i] = i;
  36609. lzwState.dictionaryLengths[i] = 1;
  36610. }
  36611. this.lzwState = lzwState;
  36612. DecodeStream.call(this, maybeLength);
  36613. }
  36614. LZWStream.prototype = Object.create(DecodeStream.prototype);
  36615. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  36616. var bitsCached = this.bitsCached;
  36617. var cachedData = this.cachedData;
  36618. while (bitsCached < n) {
  36619. var c = this.str.getByte();
  36620. if (c === -1) {
  36621. this.eof = true;
  36622. return null;
  36623. }
  36624. cachedData = (cachedData << 8) | c;
  36625. bitsCached += 8;
  36626. }
  36627. this.bitsCached = (bitsCached -= n);
  36628. this.cachedData = cachedData;
  36629. this.lastCode = null;
  36630. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  36631. };
  36632. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  36633. var blockSize = 512;
  36634. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  36635. var i, j, q;
  36636. var lzwState = this.lzwState;
  36637. if (!lzwState) {
  36638. return; // eof was found
  36639. }
  36640. var earlyChange = lzwState.earlyChange;
  36641. var nextCode = lzwState.nextCode;
  36642. var dictionaryValues = lzwState.dictionaryValues;
  36643. var dictionaryLengths = lzwState.dictionaryLengths;
  36644. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  36645. var codeLength = lzwState.codeLength;
  36646. var prevCode = lzwState.prevCode;
  36647. var currentSequence = lzwState.currentSequence;
  36648. var currentSequenceLength = lzwState.currentSequenceLength;
  36649. var decodedLength = 0;
  36650. var currentBufferLength = this.bufferLength;
  36651. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  36652. for (i = 0; i < blockSize; i++) {
  36653. var code = this.readBits(codeLength);
  36654. var hasPrev = currentSequenceLength > 0;
  36655. if (code < 256) {
  36656. currentSequence[0] = code;
  36657. currentSequenceLength = 1;
  36658. } else if (code >= 258) {
  36659. if (code < nextCode) {
  36660. currentSequenceLength = dictionaryLengths[code];
  36661. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  36662. currentSequence[j] = dictionaryValues[q];
  36663. q = dictionaryPrevCodes[q];
  36664. }
  36665. } else {
  36666. currentSequence[currentSequenceLength++] = currentSequence[0];
  36667. }
  36668. } else if (code === 256) {
  36669. codeLength = 9;
  36670. nextCode = 258;
  36671. currentSequenceLength = 0;
  36672. continue;
  36673. } else {
  36674. this.eof = true;
  36675. delete this.lzwState;
  36676. break;
  36677. }
  36678. if (hasPrev) {
  36679. dictionaryPrevCodes[nextCode] = prevCode;
  36680. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  36681. dictionaryValues[nextCode] = currentSequence[0];
  36682. nextCode++;
  36683. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  36684. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  36685. 0.6931471805599453 + 1, 12) | 0;
  36686. }
  36687. prevCode = code;
  36688. decodedLength += currentSequenceLength;
  36689. if (estimatedDecodedSize < decodedLength) {
  36690. do {
  36691. estimatedDecodedSize += decodedSizeDelta;
  36692. } while (estimatedDecodedSize < decodedLength);
  36693. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  36694. }
  36695. for (j = 0; j < currentSequenceLength; j++) {
  36696. buffer[currentBufferLength++] = currentSequence[j];
  36697. }
  36698. }
  36699. lzwState.nextCode = nextCode;
  36700. lzwState.codeLength = codeLength;
  36701. lzwState.prevCode = prevCode;
  36702. lzwState.currentSequenceLength = currentSequenceLength;
  36703. this.bufferLength = currentBufferLength;
  36704. };
  36705. return LZWStream;
  36706. })();
  36707. var NullStream = (function NullStreamClosure() {
  36708. function NullStream() {
  36709. Stream.call(this, new Uint8Array(0));
  36710. }
  36711. NullStream.prototype = Stream.prototype;
  36712. return NullStream;
  36713. })();
  36714. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  36715. setup: function wphSetup(handler) {
  36716. var pdfManager;
  36717. function loadDocument(recoveryMode) {
  36718. var loadDocumentCapability = createPromiseCapability();
  36719. var parseSuccess = function parseSuccess() {
  36720. var numPagesPromise = pdfManager.ensureDoc('numPages');
  36721. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  36722. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  36723. Promise.all([numPagesPromise, fingerprintPromise,
  36724. encryptedPromise]).then(function onDocReady(results) {
  36725. var doc = {
  36726. numPages: results[0],
  36727. fingerprint: results[1],
  36728. encrypted: !!results[2],
  36729. };
  36730. loadDocumentCapability.resolve(doc);
  36731. },
  36732. parseFailure);
  36733. };
  36734. var parseFailure = function parseFailure(e) {
  36735. loadDocumentCapability.reject(e);
  36736. };
  36737. pdfManager.ensureDoc('checkHeader', []).then(function() {
  36738. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  36739. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  36740. parseSuccess, parseFailure);
  36741. }, parseFailure);
  36742. }, parseFailure);
  36743. return loadDocumentCapability.promise;
  36744. }
  36745. function getPdfManager(data) {
  36746. var pdfManagerCapability = createPromiseCapability();
  36747. var source = data.source;
  36748. var disableRange = data.disableRange;
  36749. if (source.data) {
  36750. try {
  36751. pdfManager = new LocalPdfManager(source.data, source.password);
  36752. pdfManagerCapability.resolve();
  36753. } catch (ex) {
  36754. pdfManagerCapability.reject(ex);
  36755. }
  36756. return pdfManagerCapability.promise;
  36757. } else if (source.chunkedViewerLoading) {
  36758. try {
  36759. pdfManager = new NetworkPdfManager(source, handler);
  36760. pdfManagerCapability.resolve();
  36761. } catch (ex) {
  36762. pdfManagerCapability.reject(ex);
  36763. }
  36764. return pdfManagerCapability.promise;
  36765. }
  36766. var networkManager = new NetworkManager(source.url, {
  36767. httpHeaders: source.httpHeaders,
  36768. withCredentials: source.withCredentials
  36769. });
  36770. var cachedChunks = [];
  36771. var fullRequestXhrId = networkManager.requestFull({
  36772. onHeadersReceived: function onHeadersReceived() {
  36773. if (disableRange) {
  36774. return;
  36775. }
  36776. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  36777. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  36778. return;
  36779. }
  36780. var contentEncoding =
  36781. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  36782. if (contentEncoding !== 'identity') {
  36783. return;
  36784. }
  36785. var length = fullRequestXhr.getResponseHeader('Content-Length');
  36786. length = parseInt(length, 10);
  36787. if (!isInt(length)) {
  36788. return;
  36789. }
  36790. source.length = length;
  36791. if (length <= 2 * RANGE_CHUNK_SIZE) {
  36792. // The file size is smaller than the size of two chunks, so it does
  36793. // not make any sense to abort the request and retry with a range
  36794. // request.
  36795. return;
  36796. }
  36797. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  36798. // We can continue fetching when progressive loading is enabled,
  36799. // and we don't need the autoFetch feature.
  36800. source.disableAutoFetch = true;
  36801. } else {
  36802. // NOTE: by cancelling the full request, and then issuing range
  36803. // requests, there will be an issue for sites where you can only
  36804. // request the pdf once. However, if this is the case, then the
  36805. // server should not be returning that it can support range
  36806. // requests.
  36807. networkManager.abortRequest(fullRequestXhrId);
  36808. }
  36809. try {
  36810. pdfManager = new NetworkPdfManager(source, handler);
  36811. pdfManagerCapability.resolve(pdfManager);
  36812. } catch (ex) {
  36813. pdfManagerCapability.reject(ex);
  36814. }
  36815. },
  36816. onProgressiveData: PDFJS.disableStream ? null :
  36817. function onProgressiveData(chunk) {
  36818. if (!pdfManager) {
  36819. cachedChunks.push(chunk);
  36820. return;
  36821. }
  36822. pdfManager.sendProgressiveData(chunk);
  36823. },
  36824. onDone: function onDone(args) {
  36825. if (pdfManager) {
  36826. return; // already processed
  36827. }
  36828. var pdfFile;
  36829. if (args === null) {
  36830. // TODO add some streaming manager, e.g. for unknown length files.
  36831. // The data was returned in the onProgressiveData, combining...
  36832. var pdfFileLength = 0, pos = 0;
  36833. cachedChunks.forEach(function (chunk) {
  36834. pdfFileLength += chunk.byteLength;
  36835. });
  36836. if (source.length && pdfFileLength !== source.length) {
  36837. warn('reported HTTP length is different from actual');
  36838. }
  36839. var pdfFileArray = new Uint8Array(pdfFileLength);
  36840. cachedChunks.forEach(function (chunk) {
  36841. pdfFileArray.set(new Uint8Array(chunk), pos);
  36842. pos += chunk.byteLength;
  36843. });
  36844. pdfFile = pdfFileArray.buffer;
  36845. } else {
  36846. pdfFile = args.chunk;
  36847. }
  36848. // the data is array, instantiating directly from it
  36849. try {
  36850. pdfManager = new LocalPdfManager(pdfFile, source.password);
  36851. pdfManagerCapability.resolve();
  36852. } catch (ex) {
  36853. pdfManagerCapability.reject(ex);
  36854. }
  36855. },
  36856. onError: function onError(status) {
  36857. var exception;
  36858. if (status === 404) {
  36859. exception = new MissingPDFException('Missing PDF "' +
  36860. source.url + '".');
  36861. handler.send('MissingPDF', exception);
  36862. } else {
  36863. exception = new UnexpectedResponseException(
  36864. 'Unexpected server response (' + status +
  36865. ') while retrieving PDF "' + source.url + '".', status);
  36866. handler.send('UnexpectedResponse', exception);
  36867. }
  36868. },
  36869. onProgress: function onProgress(evt) {
  36870. handler.send('DocProgress', {
  36871. loaded: evt.loaded,
  36872. total: evt.lengthComputable ? evt.total : source.length
  36873. });
  36874. }
  36875. });
  36876. return pdfManagerCapability.promise;
  36877. }
  36878. handler.on('test', function wphSetupTest(data) {
  36879. // check if Uint8Array can be sent to worker
  36880. if (!(data instanceof Uint8Array)) {
  36881. handler.send('test', false);
  36882. return;
  36883. }
  36884. // making sure postMessage transfers are working
  36885. var supportTransfers = data[0] === 255;
  36886. handler.postMessageTransfers = supportTransfers;
  36887. // check if the response property is supported by xhr
  36888. var xhr = new XMLHttpRequest();
  36889. var responseExists = 'response' in xhr;
  36890. // check if the property is actually implemented
  36891. try {
  36892. var dummy = xhr.responseType;
  36893. } catch (e) {
  36894. responseExists = false;
  36895. }
  36896. if (!responseExists) {
  36897. handler.send('test', false);
  36898. return;
  36899. }
  36900. handler.send('test', {
  36901. supportTypedArray: true,
  36902. supportTransfers: supportTransfers
  36903. });
  36904. });
  36905. handler.on('GetDocRequest', function wphSetupDoc(data) {
  36906. var onSuccess = function(doc) {
  36907. handler.send('GetDoc', { pdfInfo: doc });
  36908. };
  36909. var onFailure = function(e) {
  36910. if (e instanceof PasswordException) {
  36911. if (e.code === PasswordResponses.NEED_PASSWORD) {
  36912. handler.send('NeedPassword', e);
  36913. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  36914. handler.send('IncorrectPassword', e);
  36915. }
  36916. } else if (e instanceof InvalidPDFException) {
  36917. handler.send('InvalidPDF', e);
  36918. } else if (e instanceof MissingPDFException) {
  36919. handler.send('MissingPDF', e);
  36920. } else if (e instanceof UnexpectedResponseException) {
  36921. handler.send('UnexpectedResponse', e);
  36922. } else {
  36923. handler.send('UnknownError',
  36924. new UnknownErrorException(e.message, e.toString()));
  36925. }
  36926. };
  36927. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  36928. -1 : data.maxImageSize;
  36929. PDFJS.disableFontFace = data.disableFontFace;
  36930. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  36931. PDFJS.verbosity = data.verbosity;
  36932. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  36933. null : data.cMapUrl;
  36934. PDFJS.cMapPacked = data.cMapPacked === true;
  36935. getPdfManager(data).then(function () {
  36936. handler.send('PDFManagerReady', null);
  36937. pdfManager.onLoadedStream().then(function(stream) {
  36938. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  36939. });
  36940. }).then(function pdfManagerReady() {
  36941. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  36942. // Try again with recoveryMode == true
  36943. if (!(ex instanceof XRefParseException)) {
  36944. if (ex instanceof PasswordException) {
  36945. // after password exception prepare to receive a new password
  36946. // to repeat loading
  36947. pdfManager.passwordChanged().then(pdfManagerReady);
  36948. }
  36949. onFailure(ex);
  36950. return;
  36951. }
  36952. pdfManager.requestLoadedStream();
  36953. pdfManager.onLoadedStream().then(function() {
  36954. loadDocument(true).then(onSuccess, onFailure);
  36955. });
  36956. }, onFailure);
  36957. }, onFailure);
  36958. });
  36959. handler.on('GetPage', function wphSetupGetPage(data) {
  36960. return pdfManager.getPage(data.pageIndex).then(function(page) {
  36961. var rotatePromise = pdfManager.ensure(page, 'rotate');
  36962. var refPromise = pdfManager.ensure(page, 'ref');
  36963. var viewPromise = pdfManager.ensure(page, 'view');
  36964. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  36965. function(results) {
  36966. return {
  36967. rotate: results[0],
  36968. ref: results[1],
  36969. view: results[2]
  36970. };
  36971. });
  36972. });
  36973. });
  36974. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  36975. var ref = new Ref(data.ref.num, data.ref.gen);
  36976. var catalog = pdfManager.pdfDocument.catalog;
  36977. return catalog.getPageIndex(ref);
  36978. });
  36979. handler.on('GetDestinations',
  36980. function wphSetupGetDestinations(data) {
  36981. return pdfManager.ensureCatalog('destinations');
  36982. }
  36983. );
  36984. handler.on('GetAttachments',
  36985. function wphSetupGetAttachments(data) {
  36986. return pdfManager.ensureCatalog('attachments');
  36987. }
  36988. );
  36989. handler.on('GetJavaScript',
  36990. function wphSetupGetJavaScript(data) {
  36991. return pdfManager.ensureCatalog('javaScript');
  36992. }
  36993. );
  36994. handler.on('GetOutline',
  36995. function wphSetupGetOutline(data) {
  36996. return pdfManager.ensureCatalog('documentOutline');
  36997. }
  36998. );
  36999. handler.on('GetMetadata',
  37000. function wphSetupGetMetadata(data) {
  37001. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37002. pdfManager.ensureCatalog('metadata')]);
  37003. }
  37004. );
  37005. handler.on('GetData', function wphSetupGetData(data) {
  37006. pdfManager.requestLoadedStream();
  37007. return pdfManager.onLoadedStream().then(function(stream) {
  37008. return stream.bytes;
  37009. });
  37010. });
  37011. handler.on('GetStats',
  37012. function wphSetupGetStats(data) {
  37013. return pdfManager.pdfDocument.xref.stats;
  37014. }
  37015. );
  37016. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37017. pdfManager.updatePassword(data);
  37018. });
  37019. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37020. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37021. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37022. });
  37023. });
  37024. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37025. pdfManager.getPage(data.pageIndex).then(function(page) {
  37026. var pageNum = data.pageIndex + 1;
  37027. var start = Date.now();
  37028. // Pre compile the pdf page and fetch the fonts/images.
  37029. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37030. info('page=' + pageNum + ' - getOperatorList: time=' +
  37031. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37032. }, function(e) {
  37033. var minimumStackMessage =
  37034. 'worker.js: while trying to getPage() and getOperatorList()';
  37035. var wrappedException;
  37036. // Turn the error into an obj that can be serialized
  37037. if (typeof e === 'string') {
  37038. wrappedException = {
  37039. message: e,
  37040. stack: minimumStackMessage
  37041. };
  37042. } else if (typeof e === 'object') {
  37043. wrappedException = {
  37044. message: e.message || e.toString(),
  37045. stack: e.stack || minimumStackMessage
  37046. };
  37047. } else {
  37048. wrappedException = {
  37049. message: 'Unknown exception type: ' + (typeof e),
  37050. stack: minimumStackMessage
  37051. };
  37052. }
  37053. handler.send('PageError', {
  37054. pageNum: pageNum,
  37055. error: wrappedException,
  37056. intent: data.intent
  37057. });
  37058. });
  37059. });
  37060. }, this);
  37061. handler.on('GetTextContent', function wphExtractText(data) {
  37062. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37063. var pageNum = data.pageIndex + 1;
  37064. var start = Date.now();
  37065. return page.extractTextContent().then(function(textContent) {
  37066. info('text indexing: page=' + pageNum + ' - time=' +
  37067. (Date.now() - start) + 'ms');
  37068. return textContent;
  37069. });
  37070. });
  37071. });
  37072. handler.on('Cleanup', function wphCleanup(data) {
  37073. return pdfManager.cleanup();
  37074. });
  37075. handler.on('Terminate', function wphTerminate(data) {
  37076. pdfManager.terminate();
  37077. });
  37078. }
  37079. };
  37080. var consoleTimer = {};
  37081. var workerConsole = {
  37082. log: function log() {
  37083. var args = Array.prototype.slice.call(arguments);
  37084. globalScope.postMessage({
  37085. action: 'console_log',
  37086. data: args
  37087. });
  37088. },
  37089. error: function error() {
  37090. var args = Array.prototype.slice.call(arguments);
  37091. globalScope.postMessage({
  37092. action: 'console_error',
  37093. data: args
  37094. });
  37095. throw 'pdf.js execution error';
  37096. },
  37097. time: function time(name) {
  37098. consoleTimer[name] = Date.now();
  37099. },
  37100. timeEnd: function timeEnd(name) {
  37101. var time = consoleTimer[name];
  37102. if (!time) {
  37103. error('Unknown timer name ' + name);
  37104. }
  37105. this.log('Timer:', name, Date.now() - time);
  37106. }
  37107. };
  37108. // Worker thread?
  37109. if (typeof window === 'undefined') {
  37110. if (!('console' in globalScope)) {
  37111. globalScope.console = workerConsole;
  37112. }
  37113. // Listen for unsupported features so we can pass them on to the main thread.
  37114. PDFJS.UnsupportedManager.listen(function (msg) {
  37115. globalScope.postMessage({
  37116. action: '_unsupported_feature',
  37117. data: msg
  37118. });
  37119. });
  37120. var handler = new MessageHandler('worker_processor', this);
  37121. WorkerMessageHandler.setup(handler);
  37122. }
  37123. /* This class implements the QM Coder decoding as defined in
  37124. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37125. * Annex C.3 Arithmetic decoding procedure
  37126. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37127. *
  37128. * The arithmetic decoder is used in conjunction with context models to decode
  37129. * JPEG2000 and JBIG2 streams.
  37130. */
  37131. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37132. // Table C-2
  37133. var QeTable = [
  37134. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37135. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37136. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37137. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37138. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37139. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37140. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37141. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37142. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37143. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37144. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37145. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37146. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37147. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37148. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37149. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37150. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37151. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37152. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37153. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37154. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37155. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37156. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37157. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37158. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37159. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37160. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37161. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37162. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37163. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37164. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37165. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37166. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37167. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37168. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37169. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37170. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37171. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37172. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37173. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37174. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37175. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37176. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37177. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37178. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37179. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37180. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37181. ];
  37182. // C.3.5 Initialisation of the decoder (INITDEC)
  37183. function ArithmeticDecoder(data, start, end) {
  37184. this.data = data;
  37185. this.bp = start;
  37186. this.dataEnd = end;
  37187. this.chigh = data[start];
  37188. this.clow = 0;
  37189. this.byteIn();
  37190. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37191. this.clow = (this.clow << 7) & 0xFFFF;
  37192. this.ct -= 7;
  37193. this.a = 0x8000;
  37194. }
  37195. ArithmeticDecoder.prototype = {
  37196. // C.3.4 Compressed data input (BYTEIN)
  37197. byteIn: function ArithmeticDecoder_byteIn() {
  37198. var data = this.data;
  37199. var bp = this.bp;
  37200. if (data[bp] === 0xFF) {
  37201. var b1 = data[bp + 1];
  37202. if (b1 > 0x8F) {
  37203. this.clow += 0xFF00;
  37204. this.ct = 8;
  37205. } else {
  37206. bp++;
  37207. this.clow += (data[bp] << 9);
  37208. this.ct = 7;
  37209. this.bp = bp;
  37210. }
  37211. } else {
  37212. bp++;
  37213. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37214. this.ct = 8;
  37215. this.bp = bp;
  37216. }
  37217. if (this.clow > 0xFFFF) {
  37218. this.chigh += (this.clow >> 16);
  37219. this.clow &= 0xFFFF;
  37220. }
  37221. },
  37222. // C.3.2 Decoding a decision (DECODE)
  37223. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37224. // contexts are packed into 1 byte:
  37225. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37226. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37227. var qeTableIcx = QeTable[cx_index];
  37228. var qeIcx = qeTableIcx.qe;
  37229. var d;
  37230. var a = this.a - qeIcx;
  37231. if (this.chigh < qeIcx) {
  37232. // exchangeLps
  37233. if (a < qeIcx) {
  37234. a = qeIcx;
  37235. d = cx_mps;
  37236. cx_index = qeTableIcx.nmps;
  37237. } else {
  37238. a = qeIcx;
  37239. d = 1 ^ cx_mps;
  37240. if (qeTableIcx.switchFlag === 1) {
  37241. cx_mps = d;
  37242. }
  37243. cx_index = qeTableIcx.nlps;
  37244. }
  37245. } else {
  37246. this.chigh -= qeIcx;
  37247. if ((a & 0x8000) !== 0) {
  37248. this.a = a;
  37249. return cx_mps;
  37250. }
  37251. // exchangeMps
  37252. if (a < qeIcx) {
  37253. d = 1 ^ cx_mps;
  37254. if (qeTableIcx.switchFlag === 1) {
  37255. cx_mps = d;
  37256. }
  37257. cx_index = qeTableIcx.nlps;
  37258. } else {
  37259. d = cx_mps;
  37260. cx_index = qeTableIcx.nmps;
  37261. }
  37262. }
  37263. // C.3.3 renormD;
  37264. do {
  37265. if (this.ct === 0) {
  37266. this.byteIn();
  37267. }
  37268. a <<= 1;
  37269. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37270. this.clow = (this.clow << 1) & 0xFFFF;
  37271. this.ct--;
  37272. } while ((a & 0x8000) === 0);
  37273. this.a = a;
  37274. contexts[pos] = cx_index << 1 | cx_mps;
  37275. return d;
  37276. }
  37277. };
  37278. return ArithmeticDecoder;
  37279. })();
  37280. var JpegImage = (function jpegImage() {
  37281. var dctZigZag = new Uint8Array([
  37282. 0,
  37283. 1, 8,
  37284. 16, 9, 2,
  37285. 3, 10, 17, 24,
  37286. 32, 25, 18, 11, 4,
  37287. 5, 12, 19, 26, 33, 40,
  37288. 48, 41, 34, 27, 20, 13, 6,
  37289. 7, 14, 21, 28, 35, 42, 49, 56,
  37290. 57, 50, 43, 36, 29, 22, 15,
  37291. 23, 30, 37, 44, 51, 58,
  37292. 59, 52, 45, 38, 31,
  37293. 39, 46, 53, 60,
  37294. 61, 54, 47,
  37295. 55, 62,
  37296. 63
  37297. ]);
  37298. var dctCos1 = 4017; // cos(pi/16)
  37299. var dctSin1 = 799; // sin(pi/16)
  37300. var dctCos3 = 3406; // cos(3*pi/16)
  37301. var dctSin3 = 2276; // sin(3*pi/16)
  37302. var dctCos6 = 1567; // cos(6*pi/16)
  37303. var dctSin6 = 3784; // sin(6*pi/16)
  37304. var dctSqrt2 = 5793; // sqrt(2)
  37305. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37306. function constructor() {
  37307. }
  37308. function buildHuffmanTable(codeLengths, values) {
  37309. var k = 0, code = [], i, j, length = 16;
  37310. while (length > 0 && !codeLengths[length - 1]) {
  37311. length--;
  37312. }
  37313. code.push({children: [], index: 0});
  37314. var p = code[0], q;
  37315. for (i = 0; i < length; i++) {
  37316. for (j = 0; j < codeLengths[i]; j++) {
  37317. p = code.pop();
  37318. p.children[p.index] = values[k];
  37319. while (p.index > 0) {
  37320. p = code.pop();
  37321. }
  37322. p.index++;
  37323. code.push(p);
  37324. while (code.length <= i) {
  37325. code.push(q = {children: [], index: 0});
  37326. p.children[p.index] = q.children;
  37327. p = q;
  37328. }
  37329. k++;
  37330. }
  37331. if (i + 1 < length) {
  37332. // p here points to last code
  37333. code.push(q = {children: [], index: 0});
  37334. p.children[p.index] = q.children;
  37335. p = q;
  37336. }
  37337. }
  37338. return code[0].children;
  37339. }
  37340. function getBlockBufferOffset(component, row, col) {
  37341. return 64 * ((component.blocksPerLine + 1) * row + col);
  37342. }
  37343. function decodeScan(data, offset, frame, components, resetInterval,
  37344. spectralStart, spectralEnd, successivePrev, successive) {
  37345. var precision = frame.precision;
  37346. var samplesPerLine = frame.samplesPerLine;
  37347. var scanLines = frame.scanLines;
  37348. var mcusPerLine = frame.mcusPerLine;
  37349. var progressive = frame.progressive;
  37350. var maxH = frame.maxH, maxV = frame.maxV;
  37351. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37352. function readBit() {
  37353. if (bitsCount > 0) {
  37354. bitsCount--;
  37355. return (bitsData >> bitsCount) & 1;
  37356. }
  37357. bitsData = data[offset++];
  37358. if (bitsData === 0xFF) {
  37359. var nextByte = data[offset++];
  37360. if (nextByte) {
  37361. throw 'unexpected marker: ' +
  37362. ((bitsData << 8) | nextByte).toString(16);
  37363. }
  37364. // unstuff 0
  37365. }
  37366. bitsCount = 7;
  37367. return bitsData >>> 7;
  37368. }
  37369. function decodeHuffman(tree) {
  37370. var node = tree;
  37371. var bit;
  37372. while ((bit = readBit()) !== null) {
  37373. node = node[bit];
  37374. if (typeof node === 'number') {
  37375. return node;
  37376. }
  37377. if (typeof node !== 'object') {
  37378. throw 'invalid huffman sequence';
  37379. }
  37380. }
  37381. return null;
  37382. }
  37383. function receive(length) {
  37384. var n = 0;
  37385. while (length > 0) {
  37386. var bit = readBit();
  37387. if (bit === null) {
  37388. return;
  37389. }
  37390. n = (n << 1) | bit;
  37391. length--;
  37392. }
  37393. return n;
  37394. }
  37395. function receiveAndExtend(length) {
  37396. if (length === 1) {
  37397. return readBit() === 1 ? 1 : -1;
  37398. }
  37399. var n = receive(length);
  37400. if (n >= 1 << (length - 1)) {
  37401. return n;
  37402. }
  37403. return n + (-1 << length) + 1;
  37404. }
  37405. function decodeBaseline(component, offset) {
  37406. var t = decodeHuffman(component.huffmanTableDC);
  37407. var diff = t === 0 ? 0 : receiveAndExtend(t);
  37408. component.blockData[offset] = (component.pred += diff);
  37409. var k = 1;
  37410. while (k < 64) {
  37411. var rs = decodeHuffman(component.huffmanTableAC);
  37412. var s = rs & 15, r = rs >> 4;
  37413. if (s === 0) {
  37414. if (r < 15) {
  37415. break;
  37416. }
  37417. k += 16;
  37418. continue;
  37419. }
  37420. k += r;
  37421. var z = dctZigZag[k];
  37422. component.blockData[offset + z] = receiveAndExtend(s);
  37423. k++;
  37424. }
  37425. }
  37426. function decodeDCFirst(component, offset) {
  37427. var t = decodeHuffman(component.huffmanTableDC);
  37428. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  37429. component.blockData[offset] = (component.pred += diff);
  37430. }
  37431. function decodeDCSuccessive(component, offset) {
  37432. component.blockData[offset] |= readBit() << successive;
  37433. }
  37434. var eobrun = 0;
  37435. function decodeACFirst(component, offset) {
  37436. if (eobrun > 0) {
  37437. eobrun--;
  37438. return;
  37439. }
  37440. var k = spectralStart, e = spectralEnd;
  37441. while (k <= e) {
  37442. var rs = decodeHuffman(component.huffmanTableAC);
  37443. var s = rs & 15, r = rs >> 4;
  37444. if (s === 0) {
  37445. if (r < 15) {
  37446. eobrun = receive(r) + (1 << r) - 1;
  37447. break;
  37448. }
  37449. k += 16;
  37450. continue;
  37451. }
  37452. k += r;
  37453. var z = dctZigZag[k];
  37454. component.blockData[offset + z] =
  37455. receiveAndExtend(s) * (1 << successive);
  37456. k++;
  37457. }
  37458. }
  37459. var successiveACState = 0, successiveACNextValue;
  37460. function decodeACSuccessive(component, offset) {
  37461. var k = spectralStart;
  37462. var e = spectralEnd;
  37463. var r = 0;
  37464. var s;
  37465. var rs;
  37466. while (k <= e) {
  37467. var z = dctZigZag[k];
  37468. switch (successiveACState) {
  37469. case 0: // initial state
  37470. rs = decodeHuffman(component.huffmanTableAC);
  37471. s = rs & 15;
  37472. r = rs >> 4;
  37473. if (s === 0) {
  37474. if (r < 15) {
  37475. eobrun = receive(r) + (1 << r);
  37476. successiveACState = 4;
  37477. } else {
  37478. r = 16;
  37479. successiveACState = 1;
  37480. }
  37481. } else {
  37482. if (s !== 1) {
  37483. throw 'invalid ACn encoding';
  37484. }
  37485. successiveACNextValue = receiveAndExtend(s);
  37486. successiveACState = r ? 2 : 3;
  37487. }
  37488. continue;
  37489. case 1: // skipping r zero items
  37490. case 2:
  37491. if (component.blockData[offset + z]) {
  37492. component.blockData[offset + z] += (readBit() << successive);
  37493. } else {
  37494. r--;
  37495. if (r === 0) {
  37496. successiveACState = successiveACState === 2 ? 3 : 0;
  37497. }
  37498. }
  37499. break;
  37500. case 3: // set value for a zero item
  37501. if (component.blockData[offset + z]) {
  37502. component.blockData[offset + z] += (readBit() << successive);
  37503. } else {
  37504. component.blockData[offset + z] =
  37505. successiveACNextValue << successive;
  37506. successiveACState = 0;
  37507. }
  37508. break;
  37509. case 4: // eob
  37510. if (component.blockData[offset + z]) {
  37511. component.blockData[offset + z] += (readBit() << successive);
  37512. }
  37513. break;
  37514. }
  37515. k++;
  37516. }
  37517. if (successiveACState === 4) {
  37518. eobrun--;
  37519. if (eobrun === 0) {
  37520. successiveACState = 0;
  37521. }
  37522. }
  37523. }
  37524. function decodeMcu(component, decode, mcu, row, col) {
  37525. var mcuRow = (mcu / mcusPerLine) | 0;
  37526. var mcuCol = mcu % mcusPerLine;
  37527. var blockRow = mcuRow * component.v + row;
  37528. var blockCol = mcuCol * component.h + col;
  37529. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37530. decode(component, offset);
  37531. }
  37532. function decodeBlock(component, decode, mcu) {
  37533. var blockRow = (mcu / component.blocksPerLine) | 0;
  37534. var blockCol = mcu % component.blocksPerLine;
  37535. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37536. decode(component, offset);
  37537. }
  37538. var componentsLength = components.length;
  37539. var component, i, j, k, n;
  37540. var decodeFn;
  37541. if (progressive) {
  37542. if (spectralStart === 0) {
  37543. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  37544. } else {
  37545. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  37546. }
  37547. } else {
  37548. decodeFn = decodeBaseline;
  37549. }
  37550. var mcu = 0, marker;
  37551. var mcuExpected;
  37552. if (componentsLength === 1) {
  37553. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  37554. } else {
  37555. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  37556. }
  37557. if (!resetInterval) {
  37558. resetInterval = mcuExpected;
  37559. }
  37560. var h, v;
  37561. while (mcu < mcuExpected) {
  37562. // reset interval stuff
  37563. for (i = 0; i < componentsLength; i++) {
  37564. components[i].pred = 0;
  37565. }
  37566. eobrun = 0;
  37567. if (componentsLength === 1) {
  37568. component = components[0];
  37569. for (n = 0; n < resetInterval; n++) {
  37570. decodeBlock(component, decodeFn, mcu);
  37571. mcu++;
  37572. }
  37573. } else {
  37574. for (n = 0; n < resetInterval; n++) {
  37575. for (i = 0; i < componentsLength; i++) {
  37576. component = components[i];
  37577. h = component.h;
  37578. v = component.v;
  37579. for (j = 0; j < v; j++) {
  37580. for (k = 0; k < h; k++) {
  37581. decodeMcu(component, decodeFn, mcu, j, k);
  37582. }
  37583. }
  37584. }
  37585. mcu++;
  37586. }
  37587. }
  37588. // find marker
  37589. bitsCount = 0;
  37590. marker = (data[offset] << 8) | data[offset + 1];
  37591. if (marker <= 0xFF00) {
  37592. throw 'marker was not found';
  37593. }
  37594. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  37595. offset += 2;
  37596. } else {
  37597. break;
  37598. }
  37599. }
  37600. return offset - startOffset;
  37601. }
  37602. // A port of poppler's IDCT method which in turn is taken from:
  37603. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  37604. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  37605. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  37606. // 988-991.
  37607. function quantizeAndInverse(component, blockBufferOffset, p) {
  37608. var qt = component.quantizationTable, blockData = component.blockData;
  37609. var v0, v1, v2, v3, v4, v5, v6, v7;
  37610. var p0, p1, p2, p3, p4, p5, p6, p7;
  37611. var t;
  37612. // inverse DCT on rows
  37613. for (var row = 0; row < 64; row += 8) {
  37614. // gather block data
  37615. p0 = blockData[blockBufferOffset + row];
  37616. p1 = blockData[blockBufferOffset + row + 1];
  37617. p2 = blockData[blockBufferOffset + row + 2];
  37618. p3 = blockData[blockBufferOffset + row + 3];
  37619. p4 = blockData[blockBufferOffset + row + 4];
  37620. p5 = blockData[blockBufferOffset + row + 5];
  37621. p6 = blockData[blockBufferOffset + row + 6];
  37622. p7 = blockData[blockBufferOffset + row + 7];
  37623. // dequant p0
  37624. p0 *= qt[row];
  37625. // check for all-zero AC coefficients
  37626. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  37627. t = (dctSqrt2 * p0 + 512) >> 10;
  37628. p[row] = t;
  37629. p[row + 1] = t;
  37630. p[row + 2] = t;
  37631. p[row + 3] = t;
  37632. p[row + 4] = t;
  37633. p[row + 5] = t;
  37634. p[row + 6] = t;
  37635. p[row + 7] = t;
  37636. continue;
  37637. }
  37638. // dequant p1 ... p7
  37639. p1 *= qt[row + 1];
  37640. p2 *= qt[row + 2];
  37641. p3 *= qt[row + 3];
  37642. p4 *= qt[row + 4];
  37643. p5 *= qt[row + 5];
  37644. p6 *= qt[row + 6];
  37645. p7 *= qt[row + 7];
  37646. // stage 4
  37647. v0 = (dctSqrt2 * p0 + 128) >> 8;
  37648. v1 = (dctSqrt2 * p4 + 128) >> 8;
  37649. v2 = p2;
  37650. v3 = p6;
  37651. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  37652. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  37653. v5 = p3 << 4;
  37654. v6 = p5 << 4;
  37655. // stage 3
  37656. v0 = (v0 + v1 + 1) >> 1;
  37657. v1 = v0 - v1;
  37658. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  37659. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  37660. v3 = t;
  37661. v4 = (v4 + v6 + 1) >> 1;
  37662. v6 = v4 - v6;
  37663. v7 = (v7 + v5 + 1) >> 1;
  37664. v5 = v7 - v5;
  37665. // stage 2
  37666. v0 = (v0 + v3 + 1) >> 1;
  37667. v3 = v0 - v3;
  37668. v1 = (v1 + v2 + 1) >> 1;
  37669. v2 = v1 - v2;
  37670. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  37671. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  37672. v7 = t;
  37673. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  37674. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  37675. v6 = t;
  37676. // stage 1
  37677. p[row] = v0 + v7;
  37678. p[row + 7] = v0 - v7;
  37679. p[row + 1] = v1 + v6;
  37680. p[row + 6] = v1 - v6;
  37681. p[row + 2] = v2 + v5;
  37682. p[row + 5] = v2 - v5;
  37683. p[row + 3] = v3 + v4;
  37684. p[row + 4] = v3 - v4;
  37685. }
  37686. // inverse DCT on columns
  37687. for (var col = 0; col < 8; ++col) {
  37688. p0 = p[col];
  37689. p1 = p[col + 8];
  37690. p2 = p[col + 16];
  37691. p3 = p[col + 24];
  37692. p4 = p[col + 32];
  37693. p5 = p[col + 40];
  37694. p6 = p[col + 48];
  37695. p7 = p[col + 56];
  37696. // check for all-zero AC coefficients
  37697. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  37698. t = (dctSqrt2 * p0 + 8192) >> 14;
  37699. // convert to 8 bit
  37700. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  37701. blockData[blockBufferOffset + col] = t;
  37702. blockData[blockBufferOffset + col + 8] = t;
  37703. blockData[blockBufferOffset + col + 16] = t;
  37704. blockData[blockBufferOffset + col + 24] = t;
  37705. blockData[blockBufferOffset + col + 32] = t;
  37706. blockData[blockBufferOffset + col + 40] = t;
  37707. blockData[blockBufferOffset + col + 48] = t;
  37708. blockData[blockBufferOffset + col + 56] = t;
  37709. continue;
  37710. }
  37711. // stage 4
  37712. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  37713. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  37714. v2 = p2;
  37715. v3 = p6;
  37716. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  37717. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  37718. v5 = p3;
  37719. v6 = p5;
  37720. // stage 3
  37721. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  37722. // converting to UInt8 range later.
  37723. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  37724. v1 = v0 - v1;
  37725. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  37726. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  37727. v3 = t;
  37728. v4 = (v4 + v6 + 1) >> 1;
  37729. v6 = v4 - v6;
  37730. v7 = (v7 + v5 + 1) >> 1;
  37731. v5 = v7 - v5;
  37732. // stage 2
  37733. v0 = (v0 + v3 + 1) >> 1;
  37734. v3 = v0 - v3;
  37735. v1 = (v1 + v2 + 1) >> 1;
  37736. v2 = v1 - v2;
  37737. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  37738. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  37739. v7 = t;
  37740. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  37741. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  37742. v6 = t;
  37743. // stage 1
  37744. p0 = v0 + v7;
  37745. p7 = v0 - v7;
  37746. p1 = v1 + v6;
  37747. p6 = v1 - v6;
  37748. p2 = v2 + v5;
  37749. p5 = v2 - v5;
  37750. p3 = v3 + v4;
  37751. p4 = v3 - v4;
  37752. // convert to 8-bit integers
  37753. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  37754. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  37755. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  37756. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  37757. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  37758. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  37759. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  37760. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  37761. // store block data
  37762. blockData[blockBufferOffset + col] = p0;
  37763. blockData[blockBufferOffset + col + 8] = p1;
  37764. blockData[blockBufferOffset + col + 16] = p2;
  37765. blockData[blockBufferOffset + col + 24] = p3;
  37766. blockData[blockBufferOffset + col + 32] = p4;
  37767. blockData[blockBufferOffset + col + 40] = p5;
  37768. blockData[blockBufferOffset + col + 48] = p6;
  37769. blockData[blockBufferOffset + col + 56] = p7;
  37770. }
  37771. }
  37772. function buildComponentData(frame, component) {
  37773. var blocksPerLine = component.blocksPerLine;
  37774. var blocksPerColumn = component.blocksPerColumn;
  37775. var computationBuffer = new Int16Array(64);
  37776. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  37777. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  37778. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37779. quantizeAndInverse(component, offset, computationBuffer);
  37780. }
  37781. }
  37782. return component.blockData;
  37783. }
  37784. function clamp0to255(a) {
  37785. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  37786. }
  37787. constructor.prototype = {
  37788. parse: function parse(data) {
  37789. function readUint16() {
  37790. var value = (data[offset] << 8) | data[offset + 1];
  37791. offset += 2;
  37792. return value;
  37793. }
  37794. function readDataBlock() {
  37795. var length = readUint16();
  37796. var array = data.subarray(offset, offset + length - 2);
  37797. offset += array.length;
  37798. return array;
  37799. }
  37800. function prepareComponents(frame) {
  37801. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  37802. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  37803. for (var i = 0; i < frame.components.length; i++) {
  37804. component = frame.components[i];
  37805. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  37806. component.h / frame.maxH);
  37807. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  37808. component.v / frame.maxV);
  37809. var blocksPerLineForMcu = mcusPerLine * component.h;
  37810. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  37811. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  37812. (blocksPerLineForMcu + 1);
  37813. component.blockData = new Int16Array(blocksBufferSize);
  37814. component.blocksPerLine = blocksPerLine;
  37815. component.blocksPerColumn = blocksPerColumn;
  37816. }
  37817. frame.mcusPerLine = mcusPerLine;
  37818. frame.mcusPerColumn = mcusPerColumn;
  37819. }
  37820. var offset = 0, length = data.length;
  37821. var jfif = null;
  37822. var adobe = null;
  37823. var pixels = null;
  37824. var frame, resetInterval;
  37825. var quantizationTables = [];
  37826. var huffmanTablesAC = [], huffmanTablesDC = [];
  37827. var fileMarker = readUint16();
  37828. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  37829. throw 'SOI not found';
  37830. }
  37831. fileMarker = readUint16();
  37832. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  37833. var i, j, l;
  37834. switch(fileMarker) {
  37835. case 0xFFE0: // APP0 (Application Specific)
  37836. case 0xFFE1: // APP1
  37837. case 0xFFE2: // APP2
  37838. case 0xFFE3: // APP3
  37839. case 0xFFE4: // APP4
  37840. case 0xFFE5: // APP5
  37841. case 0xFFE6: // APP6
  37842. case 0xFFE7: // APP7
  37843. case 0xFFE8: // APP8
  37844. case 0xFFE9: // APP9
  37845. case 0xFFEA: // APP10
  37846. case 0xFFEB: // APP11
  37847. case 0xFFEC: // APP12
  37848. case 0xFFED: // APP13
  37849. case 0xFFEE: // APP14
  37850. case 0xFFEF: // APP15
  37851. case 0xFFFE: // COM (Comment)
  37852. var appData = readDataBlock();
  37853. if (fileMarker === 0xFFE0) {
  37854. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  37855. appData[2] === 0x49 && appData[3] === 0x46 &&
  37856. appData[4] === 0) { // 'JFIF\x00'
  37857. jfif = {
  37858. version: { major: appData[5], minor: appData[6] },
  37859. densityUnits: appData[7],
  37860. xDensity: (appData[8] << 8) | appData[9],
  37861. yDensity: (appData[10] << 8) | appData[11],
  37862. thumbWidth: appData[12],
  37863. thumbHeight: appData[13],
  37864. thumbData: appData.subarray(14, 14 +
  37865. 3 * appData[12] * appData[13])
  37866. };
  37867. }
  37868. }
  37869. // TODO APP1 - Exif
  37870. if (fileMarker === 0xFFEE) {
  37871. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  37872. appData[2] === 0x6F && appData[3] === 0x62 &&
  37873. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  37874. adobe = {
  37875. version: appData[6],
  37876. flags0: (appData[7] << 8) | appData[8],
  37877. flags1: (appData[9] << 8) | appData[10],
  37878. transformCode: appData[11]
  37879. };
  37880. }
  37881. }
  37882. break;
  37883. case 0xFFDB: // DQT (Define Quantization Tables)
  37884. var quantizationTablesLength = readUint16();
  37885. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  37886. var z;
  37887. while (offset < quantizationTablesEnd) {
  37888. var quantizationTableSpec = data[offset++];
  37889. var tableData = new Uint16Array(64);
  37890. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  37891. for (j = 0; j < 64; j++) {
  37892. z = dctZigZag[j];
  37893. tableData[z] = data[offset++];
  37894. }
  37895. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  37896. for (j = 0; j < 64; j++) {
  37897. z = dctZigZag[j];
  37898. tableData[z] = readUint16();
  37899. }
  37900. } else {
  37901. throw 'DQT: invalid table spec';
  37902. }
  37903. quantizationTables[quantizationTableSpec & 15] = tableData;
  37904. }
  37905. break;
  37906. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  37907. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  37908. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  37909. if (frame) {
  37910. throw 'Only single frame JPEGs supported';
  37911. }
  37912. readUint16(); // skip data length
  37913. frame = {};
  37914. frame.extended = (fileMarker === 0xFFC1);
  37915. frame.progressive = (fileMarker === 0xFFC2);
  37916. frame.precision = data[offset++];
  37917. frame.scanLines = readUint16();
  37918. frame.samplesPerLine = readUint16();
  37919. frame.components = [];
  37920. frame.componentIds = {};
  37921. var componentsCount = data[offset++], componentId;
  37922. var maxH = 0, maxV = 0;
  37923. for (i = 0; i < componentsCount; i++) {
  37924. componentId = data[offset];
  37925. var h = data[offset + 1] >> 4;
  37926. var v = data[offset + 1] & 15;
  37927. if (maxH < h) {
  37928. maxH = h;
  37929. }
  37930. if (maxV < v) {
  37931. maxV = v;
  37932. }
  37933. var qId = data[offset + 2];
  37934. l = frame.components.push({
  37935. h: h,
  37936. v: v,
  37937. quantizationTable: quantizationTables[qId]
  37938. });
  37939. frame.componentIds[componentId] = l - 1;
  37940. offset += 3;
  37941. }
  37942. frame.maxH = maxH;
  37943. frame.maxV = maxV;
  37944. prepareComponents(frame);
  37945. break;
  37946. case 0xFFC4: // DHT (Define Huffman Tables)
  37947. var huffmanLength = readUint16();
  37948. for (i = 2; i < huffmanLength;) {
  37949. var huffmanTableSpec = data[offset++];
  37950. var codeLengths = new Uint8Array(16);
  37951. var codeLengthSum = 0;
  37952. for (j = 0; j < 16; j++, offset++) {
  37953. codeLengthSum += (codeLengths[j] = data[offset]);
  37954. }
  37955. var huffmanValues = new Uint8Array(codeLengthSum);
  37956. for (j = 0; j < codeLengthSum; j++, offset++) {
  37957. huffmanValues[j] = data[offset];
  37958. }
  37959. i += 17 + codeLengthSum;
  37960. ((huffmanTableSpec >> 4) === 0 ?
  37961. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  37962. buildHuffmanTable(codeLengths, huffmanValues);
  37963. }
  37964. break;
  37965. case 0xFFDD: // DRI (Define Restart Interval)
  37966. readUint16(); // skip data length
  37967. resetInterval = readUint16();
  37968. break;
  37969. case 0xFFDA: // SOS (Start of Scan)
  37970. var scanLength = readUint16();
  37971. var selectorsCount = data[offset++];
  37972. var components = [], component;
  37973. for (i = 0; i < selectorsCount; i++) {
  37974. var componentIndex = frame.componentIds[data[offset++]];
  37975. component = frame.components[componentIndex];
  37976. var tableSpec = data[offset++];
  37977. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  37978. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  37979. components.push(component);
  37980. }
  37981. var spectralStart = data[offset++];
  37982. var spectralEnd = data[offset++];
  37983. var successiveApproximation = data[offset++];
  37984. var processed = decodeScan(data, offset,
  37985. frame, components, resetInterval,
  37986. spectralStart, spectralEnd,
  37987. successiveApproximation >> 4, successiveApproximation & 15);
  37988. offset += processed;
  37989. break;
  37990. default:
  37991. if (data[offset - 3] === 0xFF &&
  37992. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  37993. // could be incorrect encoding -- last 0xFF byte of the previous
  37994. // block was eaten by the encoder
  37995. offset -= 3;
  37996. break;
  37997. }
  37998. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  37999. }
  38000. fileMarker = readUint16();
  38001. }
  38002. this.width = frame.samplesPerLine;
  38003. this.height = frame.scanLines;
  38004. this.jfif = jfif;
  38005. this.adobe = adobe;
  38006. this.components = [];
  38007. for (i = 0; i < frame.components.length; i++) {
  38008. component = frame.components[i];
  38009. this.components.push({
  38010. output: buildComponentData(frame, component),
  38011. scaleX: component.h / frame.maxH,
  38012. scaleY: component.v / frame.maxV,
  38013. blocksPerLine: component.blocksPerLine,
  38014. blocksPerColumn: component.blocksPerColumn
  38015. });
  38016. }
  38017. this.numComponents = this.components.length;
  38018. },
  38019. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38020. var scaleX = this.width / width, scaleY = this.height / height;
  38021. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38022. var x, y, i, j, k;
  38023. var index;
  38024. var offset = 0;
  38025. var output;
  38026. var numComponents = this.components.length;
  38027. var dataLength = width * height * numComponents;
  38028. var data = new Uint8Array(dataLength);
  38029. var xScaleBlockOffset = new Uint32Array(width);
  38030. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38031. for (i = 0; i < numComponents; i++) {
  38032. component = this.components[i];
  38033. componentScaleX = component.scaleX * scaleX;
  38034. componentScaleY = component.scaleY * scaleY;
  38035. offset = i;
  38036. output = component.output;
  38037. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38038. // precalculate the xScaleBlockOffset
  38039. for (x = 0; x < width; x++) {
  38040. j = 0 | (x * componentScaleX);
  38041. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38042. }
  38043. // linearize the blocks of the component
  38044. for (y = 0; y < height; y++) {
  38045. j = 0 | (y * componentScaleY);
  38046. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38047. for (x = 0; x < width; x++) {
  38048. data[offset] = output[index + xScaleBlockOffset[x]];
  38049. offset += numComponents;
  38050. }
  38051. }
  38052. }
  38053. // decodeTransform will contains pairs of multiplier (-256..256) and
  38054. // additive
  38055. var transform = this.decodeTransform;
  38056. if (transform) {
  38057. for (i = 0; i < dataLength;) {
  38058. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38059. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38060. }
  38061. }
  38062. }
  38063. return data;
  38064. },
  38065. _isColorConversionNeeded: function isColorConversionNeeded() {
  38066. if (this.adobe && this.adobe.transformCode) {
  38067. // The adobe transform marker overrides any previous setting
  38068. return true;
  38069. } else if (this.numComponents === 3) {
  38070. return true;
  38071. } else {
  38072. return false;
  38073. }
  38074. },
  38075. _convertYccToRgb: function convertYccToRgb(data) {
  38076. var Y, Cb, Cr;
  38077. for (var i = 0, length = data.length; i < length; i += 3) {
  38078. Y = data[i ];
  38079. Cb = data[i + 1];
  38080. Cr = data[i + 2];
  38081. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38082. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38083. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38084. }
  38085. return data;
  38086. },
  38087. _convertYcckToRgb: function convertYcckToRgb(data) {
  38088. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  38089. var offset = 0;
  38090. for (var i = 0, length = data.length; i < length; i += 4) {
  38091. Y = data[i];
  38092. Cb = data[i + 1];
  38093. Cr = data[i + 2];
  38094. k = data[i + 3];
  38095. CbCb = Cb * Cb;
  38096. CbCr = Cb * Cr;
  38097. CbY = Cb * Y;
  38098. Cbk = Cb * k;
  38099. CrCr = Cr * Cr;
  38100. Crk = Cr * k;
  38101. CrY = Cr * Y;
  38102. YY = Y * Y;
  38103. Yk = Y * k;
  38104. kk = k * k;
  38105. var r = - 122.67195406894 -
  38106. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  38107. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  38108. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  38109. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  38110. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  38111. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  38112. 0.000336197177618394 * kk + 0.484791561490776 * k;
  38113. var g = 107.268039397724 +
  38114. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  38115. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  38116. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  38117. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  38118. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  38119. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  38120. 0.000318913117588328 * kk - 0.213742400323665 * k;
  38121. var b = - 20.810012546947 -
  38122. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  38123. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  38124. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  38125. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  38126. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  38127. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  38128. 0.000343531996510555 * kk + 0.24165260232407 * k;
  38129. data[offset++] = clamp0to255(r);
  38130. data[offset++] = clamp0to255(g);
  38131. data[offset++] = clamp0to255(b);
  38132. }
  38133. return data;
  38134. },
  38135. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38136. var Y, Cb, Cr;
  38137. for (var i = 0, length = data.length; i < length; i += 4) {
  38138. Y = data[i];
  38139. Cb = data[i + 1];
  38140. Cr = data[i + 2];
  38141. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38142. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38143. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38144. // K in data[i + 3] is unchanged
  38145. }
  38146. return data;
  38147. },
  38148. _convertCmykToRgb: function convertCmykToRgb(data) {
  38149. var c, m, y, k;
  38150. var offset = 0;
  38151. var min = -255 * 255 * 255;
  38152. var scale = 1 / 255 / 255;
  38153. for (var i = 0, length = data.length; i < length; i += 4) {
  38154. c = data[i];
  38155. m = data[i + 1];
  38156. y = data[i + 2];
  38157. k = data[i + 3];
  38158. var r =
  38159. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38160. 18.82290502165302 * y + 212.25662451639585 * k -
  38161. 72734.4411664936) +
  38162. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38163. 17.873870861415444 * k - 1401.7366389350734) +
  38164. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38165. 4465.541406466231) -
  38166. k * (21.86122147463605 * k + 48317.86113160301);
  38167. var g =
  38168. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38169. 6.871425592049007 * y + 31.159100130055922 * k -
  38170. 20220.756542821975) +
  38171. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38172. 131.35250912493976 * k - 48691.05921601825) +
  38173. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38174. 6341.191035517494) -
  38175. k * (20.737325471181034 * k + 47890.15695978492);
  38176. var b =
  38177. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38178. 30.89978309703729 * y - 0.23883238689178934 * k -
  38179. 3616.812083916688) +
  38180. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38181. 50.606957656360734 * k - 28620.90484698408) +
  38182. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38183. 49363.43385999684) -
  38184. k * (22.33816807309886 * k + 45932.16563550634);
  38185. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38186. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38187. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38188. }
  38189. return data;
  38190. },
  38191. getData: function getData(width, height, forceRGBoutput) {
  38192. if (this.numComponents > 4) {
  38193. throw 'Unsupported color mode';
  38194. }
  38195. // type of data: Uint8Array(width * height * numComponents)
  38196. var data = this._getLinearizedBlockData(width, height);
  38197. if (this.numComponents === 3) {
  38198. return this._convertYccToRgb(data);
  38199. } else if (this.numComponents === 4) {
  38200. if (this._isColorConversionNeeded()) {
  38201. if (forceRGBoutput) {
  38202. return this._convertYcckToRgb(data);
  38203. } else {
  38204. return this._convertYcckToCmyk(data);
  38205. }
  38206. } else if (forceRGBoutput) {
  38207. return this._convertCmykToRgb(data);
  38208. }
  38209. }
  38210. return data;
  38211. }
  38212. };
  38213. return constructor;
  38214. })();
  38215. var JpxImage = (function JpxImageClosure() {
  38216. // Table E.1
  38217. var SubbandsGainLog2 = {
  38218. 'LL': 0,
  38219. 'LH': 1,
  38220. 'HL': 1,
  38221. 'HH': 2
  38222. };
  38223. function JpxImage() {
  38224. this.failOnCorruptedImage = false;
  38225. }
  38226. JpxImage.prototype = {
  38227. parse: function JpxImage_parse(data) {
  38228. var head = readUint16(data, 0);
  38229. // No box header, immediate start of codestream (SOC)
  38230. if (head === 0xFF4F) {
  38231. this.parseCodestream(data, 0, data.length);
  38232. return;
  38233. }
  38234. var position = 0, length = data.length;
  38235. while (position < length) {
  38236. var headerSize = 8;
  38237. var lbox = readUint32(data, position);
  38238. var tbox = readUint32(data, position + 4);
  38239. position += headerSize;
  38240. if (lbox === 1) {
  38241. // XLBox: read UInt64 according to spec.
  38242. // JavaScript's int precision of 53 bit should be sufficient here.
  38243. lbox = readUint32(data, position) * 4294967296 +
  38244. readUint32(data, position + 4);
  38245. position += 8;
  38246. headerSize += 8;
  38247. }
  38248. if (lbox === 0) {
  38249. lbox = length - position + headerSize;
  38250. }
  38251. if (lbox < headerSize) {
  38252. throw new Error('JPX Error: Invalid box field size');
  38253. }
  38254. var dataLength = lbox - headerSize;
  38255. var jumpDataLength = true;
  38256. switch (tbox) {
  38257. case 0x6A501A1A: // 'jP\032\032'
  38258. // TODO
  38259. break;
  38260. case 0x6A703268: // 'jp2h'
  38261. jumpDataLength = false; // parsing child boxes
  38262. break;
  38263. case 0x636F6C72: // 'colr'
  38264. // TODO
  38265. break;
  38266. case 0x6A703263: // 'jp2c'
  38267. this.parseCodestream(data, position, position + dataLength);
  38268. break;
  38269. }
  38270. if (jumpDataLength) {
  38271. position += dataLength;
  38272. }
  38273. }
  38274. },
  38275. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38276. var newByte = stream.getByte();
  38277. while (newByte >= 0) {
  38278. var oldByte = newByte;
  38279. newByte = stream.getByte();
  38280. var code = (oldByte << 8) | newByte;
  38281. // Image and tile size (SIZ)
  38282. if (code === 0xFF51) {
  38283. stream.skip(4);
  38284. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38285. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38286. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38287. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38288. stream.skip(16);
  38289. var Csiz = stream.getUint16(); // Byte 36
  38290. this.width = Xsiz - XOsiz;
  38291. this.height = Ysiz - YOsiz;
  38292. this.componentsCount = Csiz;
  38293. // Results are always returned as Uint8Arrays
  38294. this.bitsPerComponent = 8;
  38295. return;
  38296. }
  38297. }
  38298. throw new Error('JPX Error: No size marker found in JPX stream');
  38299. },
  38300. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38301. var context = {};
  38302. try {
  38303. var doNotRecover = false;
  38304. var position = start;
  38305. while (position + 1 < end) {
  38306. var code = readUint16(data, position);
  38307. position += 2;
  38308. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38309. switch (code) {
  38310. case 0xFF4F: // Start of codestream (SOC)
  38311. context.mainHeader = true;
  38312. break;
  38313. case 0xFFD9: // End of codestream (EOC)
  38314. break;
  38315. case 0xFF51: // Image and tile size (SIZ)
  38316. length = readUint16(data, position);
  38317. var siz = {};
  38318. siz.Xsiz = readUint32(data, position + 4);
  38319. siz.Ysiz = readUint32(data, position + 8);
  38320. siz.XOsiz = readUint32(data, position + 12);
  38321. siz.YOsiz = readUint32(data, position + 16);
  38322. siz.XTsiz = readUint32(data, position + 20);
  38323. siz.YTsiz = readUint32(data, position + 24);
  38324. siz.XTOsiz = readUint32(data, position + 28);
  38325. siz.YTOsiz = readUint32(data, position + 32);
  38326. var componentsCount = readUint16(data, position + 36);
  38327. siz.Csiz = componentsCount;
  38328. var components = [];
  38329. j = position + 38;
  38330. for (var i = 0; i < componentsCount; i++) {
  38331. var component = {
  38332. precision: (data[j] & 0x7F) + 1,
  38333. isSigned: !!(data[j] & 0x80),
  38334. XRsiz: data[j + 1],
  38335. YRsiz: data[j + 1]
  38336. };
  38337. calculateComponentDimensions(component, siz);
  38338. components.push(component);
  38339. }
  38340. context.SIZ = siz;
  38341. context.components = components;
  38342. calculateTileGrids(context, components);
  38343. context.QCC = [];
  38344. context.COC = [];
  38345. break;
  38346. case 0xFF55: // Tile-part lengths, main header (TLM)
  38347. var Ltlm = readUint16(data, position); // Marker segment length
  38348. // Skip tile length markers
  38349. position += Ltlm;
  38350. break;
  38351. case 0xFF5C: // Quantization default (QCD)
  38352. length = readUint16(data, position);
  38353. var qcd = {};
  38354. j = position + 2;
  38355. sqcd = data[j++];
  38356. switch (sqcd & 0x1F) {
  38357. case 0:
  38358. spqcdSize = 8;
  38359. scalarExpounded = true;
  38360. break;
  38361. case 1:
  38362. spqcdSize = 16;
  38363. scalarExpounded = false;
  38364. break;
  38365. case 2:
  38366. spqcdSize = 16;
  38367. scalarExpounded = true;
  38368. break;
  38369. default:
  38370. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38371. }
  38372. qcd.noQuantization = (spqcdSize === 8);
  38373. qcd.scalarExpounded = scalarExpounded;
  38374. qcd.guardBits = sqcd >> 5;
  38375. spqcds = [];
  38376. while (j < length + position) {
  38377. var spqcd = {};
  38378. if (spqcdSize === 8) {
  38379. spqcd.epsilon = data[j++] >> 3;
  38380. spqcd.mu = 0;
  38381. } else {
  38382. spqcd.epsilon = data[j] >> 3;
  38383. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38384. j += 2;
  38385. }
  38386. spqcds.push(spqcd);
  38387. }
  38388. qcd.SPqcds = spqcds;
  38389. if (context.mainHeader) {
  38390. context.QCD = qcd;
  38391. } else {
  38392. context.currentTile.QCD = qcd;
  38393. context.currentTile.QCC = [];
  38394. }
  38395. break;
  38396. case 0xFF5D: // Quantization component (QCC)
  38397. length = readUint16(data, position);
  38398. var qcc = {};
  38399. j = position + 2;
  38400. var cqcc;
  38401. if (context.SIZ.Csiz < 257) {
  38402. cqcc = data[j++];
  38403. } else {
  38404. cqcc = readUint16(data, j);
  38405. j += 2;
  38406. }
  38407. sqcd = data[j++];
  38408. switch (sqcd & 0x1F) {
  38409. case 0:
  38410. spqcdSize = 8;
  38411. scalarExpounded = true;
  38412. break;
  38413. case 1:
  38414. spqcdSize = 16;
  38415. scalarExpounded = false;
  38416. break;
  38417. case 2:
  38418. spqcdSize = 16;
  38419. scalarExpounded = true;
  38420. break;
  38421. default:
  38422. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38423. }
  38424. qcc.noQuantization = (spqcdSize === 8);
  38425. qcc.scalarExpounded = scalarExpounded;
  38426. qcc.guardBits = sqcd >> 5;
  38427. spqcds = [];
  38428. while (j < (length + position)) {
  38429. spqcd = {};
  38430. if (spqcdSize === 8) {
  38431. spqcd.epsilon = data[j++] >> 3;
  38432. spqcd.mu = 0;
  38433. } else {
  38434. spqcd.epsilon = data[j] >> 3;
  38435. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38436. j += 2;
  38437. }
  38438. spqcds.push(spqcd);
  38439. }
  38440. qcc.SPqcds = spqcds;
  38441. if (context.mainHeader) {
  38442. context.QCC[cqcc] = qcc;
  38443. } else {
  38444. context.currentTile.QCC[cqcc] = qcc;
  38445. }
  38446. break;
  38447. case 0xFF52: // Coding style default (COD)
  38448. length = readUint16(data, position);
  38449. var cod = {};
  38450. j = position + 2;
  38451. var scod = data[j++];
  38452. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  38453. cod.sopMarkerUsed = !!(scod & 2);
  38454. cod.ephMarkerUsed = !!(scod & 4);
  38455. cod.progressionOrder = data[j++];
  38456. cod.layersCount = readUint16(data, j);
  38457. j += 2;
  38458. cod.multipleComponentTransform = data[j++];
  38459. cod.decompositionLevelsCount = data[j++];
  38460. cod.xcb = (data[j++] & 0xF) + 2;
  38461. cod.ycb = (data[j++] & 0xF) + 2;
  38462. var blockStyle = data[j++];
  38463. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  38464. cod.resetContextProbabilities = !!(blockStyle & 2);
  38465. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  38466. cod.verticalyStripe = !!(blockStyle & 8);
  38467. cod.predictableTermination = !!(blockStyle & 16);
  38468. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  38469. cod.reversibleTransformation = data[j++];
  38470. if (cod.entropyCoderWithCustomPrecincts) {
  38471. var precinctsSizes = [];
  38472. while (j < length + position) {
  38473. var precinctsSize = data[j++];
  38474. precinctsSizes.push({
  38475. PPx: precinctsSize & 0xF,
  38476. PPy: precinctsSize >> 4
  38477. });
  38478. }
  38479. cod.precinctsSizes = precinctsSizes;
  38480. }
  38481. var unsupported = [];
  38482. if (cod.sopMarkerUsed) {
  38483. unsupported.push('sopMarkerUsed');
  38484. }
  38485. if (cod.ephMarkerUsed) {
  38486. unsupported.push('ephMarkerUsed');
  38487. }
  38488. if (cod.selectiveArithmeticCodingBypass) {
  38489. unsupported.push('selectiveArithmeticCodingBypass');
  38490. }
  38491. if (cod.resetContextProbabilities) {
  38492. unsupported.push('resetContextProbabilities');
  38493. }
  38494. if (cod.terminationOnEachCodingPass) {
  38495. unsupported.push('terminationOnEachCodingPass');
  38496. }
  38497. if (cod.verticalyStripe) {
  38498. unsupported.push('verticalyStripe');
  38499. }
  38500. if (cod.predictableTermination) {
  38501. unsupported.push('predictableTermination');
  38502. }
  38503. if (unsupported.length > 0) {
  38504. doNotRecover = true;
  38505. throw new Error('JPX Error: Unsupported COD options (' +
  38506. unsupported.join(', ') + ')');
  38507. }
  38508. if (context.mainHeader) {
  38509. context.COD = cod;
  38510. } else {
  38511. context.currentTile.COD = cod;
  38512. context.currentTile.COC = [];
  38513. }
  38514. break;
  38515. case 0xFF90: // Start of tile-part (SOT)
  38516. length = readUint16(data, position);
  38517. tile = {};
  38518. tile.index = readUint16(data, position + 2);
  38519. tile.length = readUint32(data, position + 4);
  38520. tile.dataEnd = tile.length + position - 2;
  38521. tile.partIndex = data[position + 8];
  38522. tile.partsCount = data[position + 9];
  38523. context.mainHeader = false;
  38524. if (tile.partIndex === 0) {
  38525. // reset component specific settings
  38526. tile.COD = context.COD;
  38527. tile.COC = context.COC.slice(0); // clone of the global COC
  38528. tile.QCD = context.QCD;
  38529. tile.QCC = context.QCC.slice(0); // clone of the global COC
  38530. }
  38531. context.currentTile = tile;
  38532. break;
  38533. case 0xFF93: // Start of data (SOD)
  38534. tile = context.currentTile;
  38535. if (tile.partIndex === 0) {
  38536. initializeTile(context, tile.index);
  38537. buildPackets(context);
  38538. }
  38539. // moving to the end of the data
  38540. length = tile.dataEnd - position;
  38541. parseTilePackets(context, data, position, length);
  38542. break;
  38543. case 0xFF64: // Comment (COM)
  38544. length = readUint16(data, position);
  38545. // skipping content
  38546. break;
  38547. case 0xFF53: // Coding style component (COC)
  38548. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  38549. 'not implemented');
  38550. default:
  38551. throw new Error('JPX Error: Unknown codestream code: ' +
  38552. code.toString(16));
  38553. }
  38554. position += length;
  38555. }
  38556. } catch (e) {
  38557. if (doNotRecover || this.failOnCorruptedImage) {
  38558. throw e;
  38559. } else {
  38560. warn('Trying to recover from ' + e.message);
  38561. }
  38562. }
  38563. this.tiles = transformComponents(context);
  38564. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  38565. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  38566. this.componentsCount = context.SIZ.Csiz;
  38567. }
  38568. };
  38569. function calculateComponentDimensions(component, siz) {
  38570. // Section B.2 Component mapping
  38571. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  38572. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  38573. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  38574. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  38575. component.width = component.x1 - component.x0;
  38576. component.height = component.y1 - component.y0;
  38577. }
  38578. function calculateTileGrids(context, components) {
  38579. var siz = context.SIZ;
  38580. // Section B.3 Division into tile and tile-components
  38581. var tile, tiles = [];
  38582. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  38583. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  38584. for (var q = 0; q < numYtiles; q++) {
  38585. for (var p = 0; p < numXtiles; p++) {
  38586. tile = {};
  38587. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  38588. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  38589. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  38590. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  38591. tile.width = tile.tx1 - tile.tx0;
  38592. tile.height = tile.ty1 - tile.ty0;
  38593. tile.components = [];
  38594. tiles.push(tile);
  38595. }
  38596. }
  38597. context.tiles = tiles;
  38598. var componentsCount = siz.Csiz;
  38599. for (var i = 0, ii = componentsCount; i < ii; i++) {
  38600. var component = components[i];
  38601. for (var j = 0, jj = tiles.length; j < jj; j++) {
  38602. var tileComponent = {};
  38603. tile = tiles[j];
  38604. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  38605. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  38606. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  38607. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  38608. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  38609. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  38610. tile.components[i] = tileComponent;
  38611. }
  38612. }
  38613. }
  38614. function getBlocksDimensions(context, component, r) {
  38615. var codOrCoc = component.codingStyleParameters;
  38616. var result = {};
  38617. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  38618. result.PPx = 15;
  38619. result.PPy = 15;
  38620. } else {
  38621. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  38622. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  38623. }
  38624. // calculate codeblock size as described in section B.7
  38625. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  38626. Math.min(codOrCoc.xcb, result.PPx));
  38627. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  38628. Math.min(codOrCoc.ycb, result.PPy));
  38629. return result;
  38630. }
  38631. function buildPrecincts(context, resolution, dimensions) {
  38632. // Section B.6 Division resolution to precincts
  38633. var precinctWidth = 1 << dimensions.PPx;
  38634. var precinctHeight = 1 << dimensions.PPy;
  38635. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  38636. Math.ceil(resolution.trx1 / precinctWidth) -
  38637. Math.floor(resolution.trx0 / precinctWidth) : 0);
  38638. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  38639. Math.ceil(resolution.try1 / precinctHeight) -
  38640. Math.floor(resolution.try0 / precinctHeight) : 0);
  38641. var numprecincts = numprecinctswide * numprecinctshigh;
  38642. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  38643. precinctWidth;
  38644. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  38645. precinctHeight;
  38646. resolution.precinctParameters = {
  38647. precinctXOffset: precinctXOffset,
  38648. precinctYOffset: precinctYOffset,
  38649. precinctWidth: precinctWidth,
  38650. precinctHeight: precinctHeight,
  38651. numprecinctswide: numprecinctswide,
  38652. numprecinctshigh: numprecinctshigh,
  38653. numprecincts: numprecincts
  38654. };
  38655. }
  38656. function buildCodeblocks(context, subband, dimensions) {
  38657. // Section B.7 Division sub-band into code-blocks
  38658. var xcb_ = dimensions.xcb_;
  38659. var ycb_ = dimensions.ycb_;
  38660. var codeblockWidth = 1 << xcb_;
  38661. var codeblockHeight = 1 << ycb_;
  38662. var cbx0 = subband.tbx0 >> xcb_;
  38663. var cby0 = subband.tby0 >> ycb_;
  38664. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  38665. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  38666. var precinctParameters = subband.resolution.precinctParameters;
  38667. var codeblocks = [];
  38668. var precincts = [];
  38669. var i, j, codeblock, precinctNumber;
  38670. for (j = cby0; j < cby1; j++) {
  38671. for (i = cbx0; i < cbx1; i++) {
  38672. codeblock = {
  38673. cbx: i,
  38674. cby: j,
  38675. tbx0: codeblockWidth * i,
  38676. tby0: codeblockHeight * j,
  38677. tbx1: codeblockWidth * (i + 1),
  38678. tby1: codeblockHeight * (j + 1)
  38679. };
  38680. // calculate precinct number
  38681. var pi = Math.floor((codeblock.tbx0 -
  38682. precinctParameters.precinctXOffset) /
  38683. precinctParameters.precinctWidth);
  38684. var pj = Math.floor((codeblock.tby0 -
  38685. precinctParameters.precinctYOffset) /
  38686. precinctParameters.precinctHeight);
  38687. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  38688. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  38689. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  38690. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  38691. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  38692. codeblock.precinctNumber = precinctNumber;
  38693. codeblock.subbandType = subband.type;
  38694. codeblock.Lblock = 3;
  38695. codeblocks.push(codeblock);
  38696. // building precinct for the sub-band
  38697. var precinct = precincts[precinctNumber];
  38698. if (precinct !== undefined) {
  38699. if (i < precinct.cbxMin) {
  38700. precinct.cbxMin = i;
  38701. } else if (i > precinct.cbxMax) {
  38702. precinct.cbxMax = i;
  38703. }
  38704. if (j < precinct.cbyMin) {
  38705. precinct.cbxMin = j;
  38706. } else if (j > precinct.cbyMax) {
  38707. precinct.cbyMax = j;
  38708. }
  38709. } else {
  38710. precincts[precinctNumber] = precinct = {
  38711. cbxMin: i,
  38712. cbyMin: j,
  38713. cbxMax: i,
  38714. cbyMax: j
  38715. };
  38716. }
  38717. codeblock.precinct = precinct;
  38718. }
  38719. }
  38720. subband.codeblockParameters = {
  38721. codeblockWidth: xcb_,
  38722. codeblockHeight: ycb_,
  38723. numcodeblockwide: cbx1 - cbx0 + 1,
  38724. numcodeblockhigh: cby1 - cby0 + 1
  38725. };
  38726. subband.codeblocks = codeblocks;
  38727. subband.precincts = precincts;
  38728. }
  38729. function createPacket(resolution, precinctNumber, layerNumber) {
  38730. var precinctCodeblocks = [];
  38731. // Section B.10.8 Order of info in packet
  38732. var subbands = resolution.subbands;
  38733. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  38734. for (var i = 0, ii = subbands.length; i < ii; i++) {
  38735. var subband = subbands[i];
  38736. var codeblocks = subband.codeblocks;
  38737. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  38738. var codeblock = codeblocks[j];
  38739. if (codeblock.precinctNumber !== precinctNumber) {
  38740. continue;
  38741. }
  38742. precinctCodeblocks.push(codeblock);
  38743. }
  38744. }
  38745. return {
  38746. layerNumber: layerNumber,
  38747. codeblocks: precinctCodeblocks
  38748. };
  38749. }
  38750. function LayerResolutionComponentPositionIterator(context) {
  38751. var siz = context.SIZ;
  38752. var tileIndex = context.currentTile.index;
  38753. var tile = context.tiles[tileIndex];
  38754. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  38755. var componentsCount = siz.Csiz;
  38756. var maxDecompositionLevelsCount = 0;
  38757. for (var q = 0; q < componentsCount; q++) {
  38758. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  38759. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  38760. }
  38761. var l = 0, r = 0, i = 0, k = 0;
  38762. this.nextPacket = function JpxImage_nextPacket() {
  38763. // Section B.12.1.1 Layer-resolution-component-position
  38764. for (; l < layersCount; l++) {
  38765. for (; r <= maxDecompositionLevelsCount; r++) {
  38766. for (; i < componentsCount; i++) {
  38767. var component = tile.components[i];
  38768. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  38769. continue;
  38770. }
  38771. var resolution = component.resolutions[r];
  38772. var numprecincts = resolution.precinctParameters.numprecincts;
  38773. for (; k < numprecincts;) {
  38774. var packet = createPacket(resolution, k, l);
  38775. k++;
  38776. return packet;
  38777. }
  38778. k = 0;
  38779. }
  38780. i = 0;
  38781. }
  38782. r = 0;
  38783. }
  38784. throw new Error('JPX Error: Out of packets');
  38785. };
  38786. }
  38787. function ResolutionLayerComponentPositionIterator(context) {
  38788. var siz = context.SIZ;
  38789. var tileIndex = context.currentTile.index;
  38790. var tile = context.tiles[tileIndex];
  38791. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  38792. var componentsCount = siz.Csiz;
  38793. var maxDecompositionLevelsCount = 0;
  38794. for (var q = 0; q < componentsCount; q++) {
  38795. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  38796. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  38797. }
  38798. var r = 0, l = 0, i = 0, k = 0;
  38799. this.nextPacket = function JpxImage_nextPacket() {
  38800. // Section B.12.1.2 Resolution-layer-component-position
  38801. for (; r <= maxDecompositionLevelsCount; r++) {
  38802. for (; l < layersCount; l++) {
  38803. for (; i < componentsCount; i++) {
  38804. var component = tile.components[i];
  38805. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  38806. continue;
  38807. }
  38808. var resolution = component.resolutions[r];
  38809. var numprecincts = resolution.precinctParameters.numprecincts;
  38810. for (; k < numprecincts;) {
  38811. var packet = createPacket(resolution, k, l);
  38812. k++;
  38813. return packet;
  38814. }
  38815. k = 0;
  38816. }
  38817. i = 0;
  38818. }
  38819. l = 0;
  38820. }
  38821. throw new Error('JPX Error: Out of packets');
  38822. };
  38823. }
  38824. function buildPackets(context) {
  38825. var siz = context.SIZ;
  38826. var tileIndex = context.currentTile.index;
  38827. var tile = context.tiles[tileIndex];
  38828. var componentsCount = siz.Csiz;
  38829. // Creating resolutions and sub-bands for each component
  38830. for (var c = 0; c < componentsCount; c++) {
  38831. var component = tile.components[c];
  38832. var decompositionLevelsCount =
  38833. component.codingStyleParameters.decompositionLevelsCount;
  38834. // Section B.5 Resolution levels and sub-bands
  38835. var resolutions = [];
  38836. var subbands = [];
  38837. for (var r = 0; r <= decompositionLevelsCount; r++) {
  38838. var blocksDimensions = getBlocksDimensions(context, component, r);
  38839. var resolution = {};
  38840. var scale = 1 << (decompositionLevelsCount - r);
  38841. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  38842. resolution.try0 = Math.ceil(component.tcy0 / scale);
  38843. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  38844. resolution.try1 = Math.ceil(component.tcy1 / scale);
  38845. buildPrecincts(context, resolution, blocksDimensions);
  38846. resolutions.push(resolution);
  38847. var subband;
  38848. if (r === 0) {
  38849. // one sub-band (LL) with last decomposition
  38850. subband = {};
  38851. subband.type = 'LL';
  38852. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  38853. subband.tby0 = Math.ceil(component.tcy0 / scale);
  38854. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  38855. subband.tby1 = Math.ceil(component.tcy1 / scale);
  38856. subband.resolution = resolution;
  38857. buildCodeblocks(context, subband, blocksDimensions);
  38858. subbands.push(subband);
  38859. resolution.subbands = [subband];
  38860. } else {
  38861. var bscale = 1 << (decompositionLevelsCount - r + 1);
  38862. var resolutionSubbands = [];
  38863. // three sub-bands (HL, LH and HH) with rest of decompositions
  38864. subband = {};
  38865. subband.type = 'HL';
  38866. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  38867. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  38868. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  38869. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  38870. subband.resolution = resolution;
  38871. buildCodeblocks(context, subband, blocksDimensions);
  38872. subbands.push(subband);
  38873. resolutionSubbands.push(subband);
  38874. subband = {};
  38875. subband.type = 'LH';
  38876. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  38877. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  38878. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  38879. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  38880. subband.resolution = resolution;
  38881. buildCodeblocks(context, subband, blocksDimensions);
  38882. subbands.push(subband);
  38883. resolutionSubbands.push(subband);
  38884. subband = {};
  38885. subband.type = 'HH';
  38886. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  38887. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  38888. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  38889. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  38890. subband.resolution = resolution;
  38891. buildCodeblocks(context, subband, blocksDimensions);
  38892. subbands.push(subband);
  38893. resolutionSubbands.push(subband);
  38894. resolution.subbands = resolutionSubbands;
  38895. }
  38896. }
  38897. component.resolutions = resolutions;
  38898. component.subbands = subbands;
  38899. }
  38900. // Generate the packets sequence
  38901. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  38902. switch (progressionOrder) {
  38903. case 0:
  38904. tile.packetsIterator =
  38905. new LayerResolutionComponentPositionIterator(context);
  38906. break;
  38907. case 1:
  38908. tile.packetsIterator =
  38909. new ResolutionLayerComponentPositionIterator(context);
  38910. break;
  38911. default:
  38912. throw new Error('JPX Error: Unsupported progression order ' +
  38913. progressionOrder);
  38914. }
  38915. }
  38916. function parseTilePackets(context, data, offset, dataLength) {
  38917. var position = 0;
  38918. var buffer, bufferSize = 0, skipNextBit = false;
  38919. function readBits(count) {
  38920. while (bufferSize < count) {
  38921. var b = data[offset + position];
  38922. position++;
  38923. if (skipNextBit) {
  38924. buffer = (buffer << 7) | b;
  38925. bufferSize += 7;
  38926. skipNextBit = false;
  38927. } else {
  38928. buffer = (buffer << 8) | b;
  38929. bufferSize += 8;
  38930. }
  38931. if (b === 0xFF) {
  38932. skipNextBit = true;
  38933. }
  38934. }
  38935. bufferSize -= count;
  38936. return (buffer >>> bufferSize) & ((1 << count) - 1);
  38937. }
  38938. function alignToByte() {
  38939. bufferSize = 0;
  38940. if (skipNextBit) {
  38941. position++;
  38942. skipNextBit = false;
  38943. }
  38944. }
  38945. function readCodingpasses() {
  38946. if (readBits(1) === 0) {
  38947. return 1;
  38948. }
  38949. if (readBits(1) === 0) {
  38950. return 2;
  38951. }
  38952. var value = readBits(2);
  38953. if (value < 3) {
  38954. return value + 3;
  38955. }
  38956. value = readBits(5);
  38957. if (value < 31) {
  38958. return value + 6;
  38959. }
  38960. value = readBits(7);
  38961. return value + 37;
  38962. }
  38963. var tileIndex = context.currentTile.index;
  38964. var tile = context.tiles[tileIndex];
  38965. var packetsIterator = tile.packetsIterator;
  38966. while (position < dataLength) {
  38967. var packet = packetsIterator.nextPacket();
  38968. if (!readBits(1)) {
  38969. alignToByte();
  38970. continue;
  38971. }
  38972. var layerNumber = packet.layerNumber;
  38973. var queue = [], codeblock;
  38974. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  38975. codeblock = packet.codeblocks[i];
  38976. var precinct = codeblock.precinct;
  38977. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  38978. var codeblockRow = codeblock.cby - precinct.cbyMin;
  38979. var codeblockIncluded = false;
  38980. var firstTimeInclusion = false;
  38981. var valueReady;
  38982. if ('included' in codeblock) {
  38983. codeblockIncluded = !!readBits(1);
  38984. } else {
  38985. // reading inclusion tree
  38986. precinct = codeblock.precinct;
  38987. var inclusionTree, zeroBitPlanesTree;
  38988. if ('inclusionTree' in precinct) {
  38989. inclusionTree = precinct.inclusionTree;
  38990. } else {
  38991. // building inclusion and zero bit-planes trees
  38992. var width = precinct.cbxMax - precinct.cbxMin + 1;
  38993. var height = precinct.cbyMax - precinct.cbyMin + 1;
  38994. inclusionTree = new InclusionTree(width, height, layerNumber);
  38995. zeroBitPlanesTree = new TagTree(width, height);
  38996. precinct.inclusionTree = inclusionTree;
  38997. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  38998. }
  38999. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39000. while (true) {
  39001. if (readBits(1)) {
  39002. valueReady = !inclusionTree.nextLevel();
  39003. if (valueReady) {
  39004. codeblock.included = true;
  39005. codeblockIncluded = firstTimeInclusion = true;
  39006. break;
  39007. }
  39008. } else {
  39009. inclusionTree.incrementValue(layerNumber);
  39010. break;
  39011. }
  39012. }
  39013. }
  39014. }
  39015. if (!codeblockIncluded) {
  39016. continue;
  39017. }
  39018. if (firstTimeInclusion) {
  39019. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39020. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39021. while (true) {
  39022. if (readBits(1)) {
  39023. valueReady = !zeroBitPlanesTree.nextLevel();
  39024. if (valueReady) {
  39025. break;
  39026. }
  39027. } else {
  39028. zeroBitPlanesTree.incrementValue();
  39029. }
  39030. }
  39031. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39032. }
  39033. var codingpasses = readCodingpasses();
  39034. while (readBits(1)) {
  39035. codeblock.Lblock++;
  39036. }
  39037. var codingpassesLog2 = log2(codingpasses);
  39038. // rounding down log2
  39039. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39040. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39041. var codedDataLength = readBits(bits);
  39042. queue.push({
  39043. codeblock: codeblock,
  39044. codingpasses: codingpasses,
  39045. dataLength: codedDataLength
  39046. });
  39047. }
  39048. alignToByte();
  39049. while (queue.length > 0) {
  39050. var packetItem = queue.shift();
  39051. codeblock = packetItem.codeblock;
  39052. if (!('data' in codeblock)) {
  39053. codeblock.data = [];
  39054. }
  39055. codeblock.data.push({
  39056. data: data,
  39057. start: offset + position,
  39058. end: offset + position + packetItem.dataLength,
  39059. codingpasses: packetItem.codingpasses
  39060. });
  39061. position += packetItem.dataLength;
  39062. }
  39063. }
  39064. return position;
  39065. }
  39066. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  39067. delta, mb, reversible, segmentationSymbolUsed) {
  39068. var x0 = subband.tbx0;
  39069. var y0 = subband.tby0;
  39070. var width = subband.tbx1 - subband.tbx0;
  39071. var codeblocks = subband.codeblocks;
  39072. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  39073. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  39074. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  39075. var codeblock = codeblocks[i];
  39076. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  39077. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  39078. if (blockWidth === 0 || blockHeight === 0) {
  39079. continue;
  39080. }
  39081. if (!('data' in codeblock)) {
  39082. continue;
  39083. }
  39084. var bitModel, currentCodingpassType;
  39085. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  39086. codeblock.zeroBitPlanes, mb);
  39087. currentCodingpassType = 2; // first bit plane starts from cleanup
  39088. // collect data
  39089. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  39090. var j, jj, dataItem;
  39091. for (j = 0, jj = data.length; j < jj; j++) {
  39092. dataItem = data[j];
  39093. totalLength += dataItem.end - dataItem.start;
  39094. codingpasses += dataItem.codingpasses;
  39095. }
  39096. var encodedData = new Uint8Array(totalLength);
  39097. var position = 0;
  39098. for (j = 0, jj = data.length; j < jj; j++) {
  39099. dataItem = data[j];
  39100. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  39101. encodedData.set(chunk, position);
  39102. position += chunk.length;
  39103. }
  39104. // decoding the item
  39105. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  39106. bitModel.setDecoder(decoder);
  39107. for (j = 0; j < codingpasses; j++) {
  39108. switch (currentCodingpassType) {
  39109. case 0:
  39110. bitModel.runSignificancePropogationPass();
  39111. break;
  39112. case 1:
  39113. bitModel.runMagnitudeRefinementPass();
  39114. break;
  39115. case 2:
  39116. bitModel.runCleanupPass();
  39117. if (segmentationSymbolUsed) {
  39118. bitModel.checkSegmentationSymbol();
  39119. }
  39120. break;
  39121. }
  39122. currentCodingpassType = (currentCodingpassType + 1) % 3;
  39123. }
  39124. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  39125. var sign = bitModel.coefficentsSign;
  39126. var magnitude = bitModel.coefficentsMagnitude;
  39127. var bitsDecoded = bitModel.bitsDecoded;
  39128. var magnitudeCorrection = reversible ? 0 : 0.5;
  39129. var k, n, nb;
  39130. position = 0;
  39131. // Do the interleaving of Section F.3.3 here, so we do not need
  39132. // to copy later. LL level is not interleaved, just copied.
  39133. var interleave = (subband.type !== 'LL');
  39134. for (j = 0; j < blockHeight; j++) {
  39135. var row = (offset / width) | 0; // row in the non-interleaved subband
  39136. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  39137. for (k = 0; k < blockWidth; k++) {
  39138. n = magnitude[position];
  39139. if (n !== 0) {
  39140. n = (n + magnitudeCorrection) * delta;
  39141. if (sign[position] !== 0) {
  39142. n = -n;
  39143. }
  39144. nb = bitsDecoded[position];
  39145. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  39146. if (reversible && (nb >= mb)) {
  39147. coefficients[pos] = n;
  39148. } else {
  39149. coefficients[pos] = n * (1 << (mb - nb));
  39150. }
  39151. }
  39152. offset++;
  39153. position++;
  39154. }
  39155. offset += width - blockWidth;
  39156. }
  39157. }
  39158. }
  39159. function transformTile(context, tile, c) {
  39160. var component = tile.components[c];
  39161. var codingStyleParameters = component.codingStyleParameters;
  39162. var quantizationParameters = component.quantizationParameters;
  39163. var decompositionLevelsCount =
  39164. codingStyleParameters.decompositionLevelsCount;
  39165. var spqcds = quantizationParameters.SPqcds;
  39166. var scalarExpounded = quantizationParameters.scalarExpounded;
  39167. var guardBits = quantizationParameters.guardBits;
  39168. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  39169. var precision = context.components[c].precision;
  39170. var reversible = codingStyleParameters.reversibleTransformation;
  39171. var transform = (reversible ? new ReversibleTransform() :
  39172. new IrreversibleTransform());
  39173. var subbandCoefficients = [];
  39174. var b = 0;
  39175. for (var i = 0; i <= decompositionLevelsCount; i++) {
  39176. var resolution = component.resolutions[i];
  39177. var width = resolution.trx1 - resolution.trx0;
  39178. var height = resolution.try1 - resolution.try0;
  39179. // Allocate space for the whole sublevel.
  39180. var coefficients = new Float32Array(width * height);
  39181. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  39182. var mu, epsilon;
  39183. if (!scalarExpounded) {
  39184. // formula E-5
  39185. mu = spqcds[0].mu;
  39186. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  39187. } else {
  39188. mu = spqcds[b].mu;
  39189. epsilon = spqcds[b].epsilon;
  39190. b++;
  39191. }
  39192. var subband = resolution.subbands[j];
  39193. var gainLog2 = SubbandsGainLog2[subband.type];
  39194. // calulate quantization coefficient (Section E.1.1.1)
  39195. var delta = (reversible ? 1 :
  39196. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  39197. var mb = (guardBits + epsilon - 1);
  39198. // In the first resolution level, copyCoefficients will fill the
  39199. // whole array with coefficients. In the succeding passes,
  39200. // copyCoefficients will consecutively fill in the values that belong
  39201. // to the interleaved positions of the HL, LH, and HH coefficients.
  39202. // The LL coefficients will then be interleaved in Transform.iterate().
  39203. copyCoefficients(coefficients, width, height, subband, delta, mb,
  39204. reversible, segmentationSymbolUsed);
  39205. }
  39206. subbandCoefficients.push({
  39207. width: width,
  39208. height: height,
  39209. items: coefficients
  39210. });
  39211. }
  39212. var result = transform.calculate(subbandCoefficients,
  39213. component.tcx0, component.tcy0);
  39214. return {
  39215. left: component.tcx0,
  39216. top: component.tcy0,
  39217. width: result.width,
  39218. height: result.height,
  39219. items: result.items
  39220. };
  39221. }
  39222. function transformComponents(context) {
  39223. var siz = context.SIZ;
  39224. var components = context.components;
  39225. var componentsCount = siz.Csiz;
  39226. var resultImages = [];
  39227. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  39228. var tile = context.tiles[i];
  39229. var transformedTiles = [];
  39230. var c;
  39231. for (c = 0; c < componentsCount; c++) {
  39232. transformedTiles[c] = transformTile(context, tile, c);
  39233. }
  39234. var tile0 = transformedTiles[0];
  39235. var out = new Uint8Array(tile0.items.length * componentsCount);
  39236. var result = {
  39237. left: tile0.left,
  39238. top: tile0.top,
  39239. width: tile0.width,
  39240. height: tile0.height,
  39241. items: out
  39242. };
  39243. // Section G.2.2 Inverse multi component transform
  39244. var shift, offset, max, min, maxK;
  39245. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  39246. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  39247. var fourComponents = componentsCount === 4;
  39248. var y0items = transformedTiles[0].items;
  39249. var y1items = transformedTiles[1].items;
  39250. var y2items = transformedTiles[2].items;
  39251. var y3items = fourComponents ? transformedTiles[3].items : null;
  39252. // HACK: The multiple component transform formulas below assume that
  39253. // all components have the same precision. With this in mind, we
  39254. // compute shift and offset only once.
  39255. shift = components[0].precision - 8;
  39256. offset = (128 << shift) + 0.5;
  39257. max = 255 * (1 << shift);
  39258. maxK = max * 0.5;
  39259. min = -maxK;
  39260. var component0 = tile.components[0];
  39261. var alpha01 = componentsCount - 3;
  39262. jj = y0items.length;
  39263. if (!component0.codingStyleParameters.reversibleTransformation) {
  39264. // inverse irreversible multiple component transform
  39265. for (j = 0; j < jj; j++, pos += alpha01) {
  39266. y0 = y0items[j] + offset;
  39267. y1 = y1items[j];
  39268. y2 = y2items[j];
  39269. r = y0 + 1.402 * y2;
  39270. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  39271. b = y0 + 1.772 * y1;
  39272. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  39273. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  39274. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  39275. }
  39276. } else {
  39277. // inverse reversible multiple component transform
  39278. for (j = 0; j < jj; j++, pos += alpha01) {
  39279. y0 = y0items[j] + offset;
  39280. y1 = y1items[j];
  39281. y2 = y2items[j];
  39282. g = y0 - ((y2 + y1) >> 2);
  39283. r = g + y2;
  39284. b = g + y1;
  39285. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  39286. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  39287. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  39288. }
  39289. }
  39290. if (fourComponents) {
  39291. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  39292. k = y3items[j];
  39293. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  39294. }
  39295. }
  39296. } else { // no multi-component transform
  39297. for (c = 0; c < componentsCount; c++) {
  39298. var items = transformedTiles[c].items;
  39299. shift = components[c].precision - 8;
  39300. offset = (128 << shift) + 0.5;
  39301. max = (127.5 * (1 << shift));
  39302. min = -max;
  39303. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  39304. val = items[j];
  39305. out[pos] = val <= min ? 0 :
  39306. val >= max ? 255 : (val + offset) >> shift;
  39307. pos += componentsCount;
  39308. }
  39309. }
  39310. }
  39311. resultImages.push(result);
  39312. }
  39313. return resultImages;
  39314. }
  39315. function initializeTile(context, tileIndex) {
  39316. var siz = context.SIZ;
  39317. var componentsCount = siz.Csiz;
  39318. var tile = context.tiles[tileIndex];
  39319. for (var c = 0; c < componentsCount; c++) {
  39320. var component = tile.components[c];
  39321. var qcdOrQcc = (c in context.currentTile.QCC ?
  39322. context.currentTile.QCC[c] : context.currentTile.QCD);
  39323. component.quantizationParameters = qcdOrQcc;
  39324. var codOrCoc = (c in context.currentTile.COC ?
  39325. context.currentTile.COC[c] : context.currentTile.COD);
  39326. component.codingStyleParameters = codOrCoc;
  39327. }
  39328. tile.codingStyleDefaultParameters = context.currentTile.COD;
  39329. }
  39330. // Section B.10.2 Tag trees
  39331. var TagTree = (function TagTreeClosure() {
  39332. function TagTree(width, height) {
  39333. var levelsLength = log2(Math.max(width, height)) + 1;
  39334. this.levels = [];
  39335. for (var i = 0; i < levelsLength; i++) {
  39336. var level = {
  39337. width: width,
  39338. height: height,
  39339. items: []
  39340. };
  39341. this.levels.push(level);
  39342. width = Math.ceil(width / 2);
  39343. height = Math.ceil(height / 2);
  39344. }
  39345. }
  39346. TagTree.prototype = {
  39347. reset: function TagTree_reset(i, j) {
  39348. var currentLevel = 0, value = 0, level;
  39349. while (currentLevel < this.levels.length) {
  39350. level = this.levels[currentLevel];
  39351. var index = i + j * level.width;
  39352. if (index in level.items) {
  39353. value = level.items[index];
  39354. break;
  39355. }
  39356. level.index = index;
  39357. i >>= 1;
  39358. j >>= 1;
  39359. currentLevel++;
  39360. }
  39361. currentLevel--;
  39362. level = this.levels[currentLevel];
  39363. level.items[level.index] = value;
  39364. this.currentLevel = currentLevel;
  39365. delete this.value;
  39366. },
  39367. incrementValue: function TagTree_incrementValue() {
  39368. var level = this.levels[this.currentLevel];
  39369. level.items[level.index]++;
  39370. },
  39371. nextLevel: function TagTree_nextLevel() {
  39372. var currentLevel = this.currentLevel;
  39373. var level = this.levels[currentLevel];
  39374. var value = level.items[level.index];
  39375. currentLevel--;
  39376. if (currentLevel < 0) {
  39377. this.value = value;
  39378. return false;
  39379. }
  39380. this.currentLevel = currentLevel;
  39381. level = this.levels[currentLevel];
  39382. level.items[level.index] = value;
  39383. return true;
  39384. }
  39385. };
  39386. return TagTree;
  39387. })();
  39388. var InclusionTree = (function InclusionTreeClosure() {
  39389. function InclusionTree(width, height, defaultValue) {
  39390. var levelsLength = log2(Math.max(width, height)) + 1;
  39391. this.levels = [];
  39392. for (var i = 0; i < levelsLength; i++) {
  39393. var items = new Uint8Array(width * height);
  39394. for (var j = 0, jj = items.length; j < jj; j++) {
  39395. items[j] = defaultValue;
  39396. }
  39397. var level = {
  39398. width: width,
  39399. height: height,
  39400. items: items
  39401. };
  39402. this.levels.push(level);
  39403. width = Math.ceil(width / 2);
  39404. height = Math.ceil(height / 2);
  39405. }
  39406. }
  39407. InclusionTree.prototype = {
  39408. reset: function InclusionTree_reset(i, j, stopValue) {
  39409. var currentLevel = 0;
  39410. while (currentLevel < this.levels.length) {
  39411. var level = this.levels[currentLevel];
  39412. var index = i + j * level.width;
  39413. level.index = index;
  39414. var value = level.items[index];
  39415. if (value === 0xFF) {
  39416. break;
  39417. }
  39418. if (value > stopValue) {
  39419. this.currentLevel = currentLevel;
  39420. // already know about this one, propagating the value to top levels
  39421. this.propagateValues();
  39422. return false;
  39423. }
  39424. i >>= 1;
  39425. j >>= 1;
  39426. currentLevel++;
  39427. }
  39428. this.currentLevel = currentLevel - 1;
  39429. return true;
  39430. },
  39431. incrementValue: function InclusionTree_incrementValue(stopValue) {
  39432. var level = this.levels[this.currentLevel];
  39433. level.items[level.index] = stopValue + 1;
  39434. this.propagateValues();
  39435. },
  39436. propagateValues: function InclusionTree_propagateValues() {
  39437. var levelIndex = this.currentLevel;
  39438. var level = this.levels[levelIndex];
  39439. var currentValue = level.items[level.index];
  39440. while (--levelIndex >= 0) {
  39441. level = this.levels[levelIndex];
  39442. level.items[level.index] = currentValue;
  39443. }
  39444. },
  39445. nextLevel: function InclusionTree_nextLevel() {
  39446. var currentLevel = this.currentLevel;
  39447. var level = this.levels[currentLevel];
  39448. var value = level.items[level.index];
  39449. level.items[level.index] = 0xFF;
  39450. currentLevel--;
  39451. if (currentLevel < 0) {
  39452. return false;
  39453. }
  39454. this.currentLevel = currentLevel;
  39455. level = this.levels[currentLevel];
  39456. level.items[level.index] = value;
  39457. return true;
  39458. }
  39459. };
  39460. return InclusionTree;
  39461. })();
  39462. // Section D. Coefficient bit modeling
  39463. var BitModel = (function BitModelClosure() {
  39464. var UNIFORM_CONTEXT = 17;
  39465. var RUNLENGTH_CONTEXT = 18;
  39466. // Table D-1
  39467. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  39468. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  39469. var LLAndLHContextsLabel = new Uint8Array([
  39470. 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,
  39471. 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,
  39472. 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
  39473. ]);
  39474. var HLContextLabel = new Uint8Array([
  39475. 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,
  39476. 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,
  39477. 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
  39478. ]);
  39479. var HHContextLabel = new Uint8Array([
  39480. 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,
  39481. 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,
  39482. 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
  39483. ]);
  39484. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  39485. this.width = width;
  39486. this.height = height;
  39487. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  39488. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  39489. var coefficientCount = width * height;
  39490. // coefficients outside the encoding region treated as insignificant
  39491. // add border state cells for significanceState
  39492. this.neighborsSignificance = new Uint8Array(coefficientCount);
  39493. this.coefficentsSign = new Uint8Array(coefficientCount);
  39494. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  39495. mb > 6 ? new Uint16Array(coefficientCount) :
  39496. new Uint8Array(coefficientCount);
  39497. this.processingFlags = new Uint8Array(coefficientCount);
  39498. var bitsDecoded = new Uint8Array(coefficientCount);
  39499. if (zeroBitPlanes !== 0) {
  39500. for (var i = 0; i < coefficientCount; i++) {
  39501. bitsDecoded[i] = zeroBitPlanes;
  39502. }
  39503. }
  39504. this.bitsDecoded = bitsDecoded;
  39505. this.reset();
  39506. }
  39507. BitModel.prototype = {
  39508. setDecoder: function BitModel_setDecoder(decoder) {
  39509. this.decoder = decoder;
  39510. },
  39511. reset: function BitModel_reset() {
  39512. // We have 17 contexts that are accessed via context labels,
  39513. // plus the uniform and runlength context.
  39514. this.contexts = new Int8Array(19);
  39515. // Contexts are packed into 1 byte:
  39516. // highest 7 bits carry the index, lowest bit carries mps
  39517. this.contexts[0] = (4 << 1) | 0;
  39518. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  39519. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  39520. },
  39521. setNeighborsSignificance:
  39522. function BitModel_setNeighborsSignificance(row, column, index) {
  39523. var neighborsSignificance = this.neighborsSignificance;
  39524. var width = this.width, height = this.height;
  39525. var left = (column > 0);
  39526. var right = (column + 1 < width);
  39527. var i;
  39528. if (row > 0) {
  39529. i = index - width;
  39530. if (left) {
  39531. neighborsSignificance[i - 1] += 0x10;
  39532. }
  39533. if (right) {
  39534. neighborsSignificance[i + 1] += 0x10;
  39535. }
  39536. neighborsSignificance[i] += 0x04;
  39537. }
  39538. if (row + 1 < height) {
  39539. i = index + width;
  39540. if (left) {
  39541. neighborsSignificance[i - 1] += 0x10;
  39542. }
  39543. if (right) {
  39544. neighborsSignificance[i + 1] += 0x10;
  39545. }
  39546. neighborsSignificance[i] += 0x04;
  39547. }
  39548. if (left) {
  39549. neighborsSignificance[index - 1] += 0x01;
  39550. }
  39551. if (right) {
  39552. neighborsSignificance[index + 1] += 0x01;
  39553. }
  39554. neighborsSignificance[index] |= 0x80;
  39555. },
  39556. runSignificancePropogationPass:
  39557. function BitModel_runSignificancePropogationPass() {
  39558. var decoder = this.decoder;
  39559. var width = this.width, height = this.height;
  39560. var coefficentsMagnitude = this.coefficentsMagnitude;
  39561. var coefficentsSign = this.coefficentsSign;
  39562. var neighborsSignificance = this.neighborsSignificance;
  39563. var processingFlags = this.processingFlags;
  39564. var contexts = this.contexts;
  39565. var labels = this.contextLabelTable;
  39566. var bitsDecoded = this.bitsDecoded;
  39567. var processedInverseMask = ~1;
  39568. var processedMask = 1;
  39569. var firstMagnitudeBitMask = 2;
  39570. for (var i0 = 0; i0 < height; i0 += 4) {
  39571. for (var j = 0; j < width; j++) {
  39572. var index = i0 * width + j;
  39573. for (var i1 = 0; i1 < 4; i1++, index += width) {
  39574. var i = i0 + i1;
  39575. if (i >= height) {
  39576. break;
  39577. }
  39578. // clear processed flag first
  39579. processingFlags[index] &= processedInverseMask;
  39580. if (coefficentsMagnitude[index] ||
  39581. !neighborsSignificance[index]) {
  39582. continue;
  39583. }
  39584. var contextLabel = labels[neighborsSignificance[index]];
  39585. var decision = decoder.readBit(contexts, contextLabel);
  39586. if (decision) {
  39587. var sign = this.decodeSignBit(i, j, index);
  39588. coefficentsSign[index] = sign;
  39589. coefficentsMagnitude[index] = 1;
  39590. this.setNeighborsSignificance(i, j, index);
  39591. processingFlags[index] |= firstMagnitudeBitMask;
  39592. }
  39593. bitsDecoded[index]++;
  39594. processingFlags[index] |= processedMask;
  39595. }
  39596. }
  39597. }
  39598. },
  39599. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  39600. var width = this.width, height = this.height;
  39601. var coefficentsMagnitude = this.coefficentsMagnitude;
  39602. var coefficentsSign = this.coefficentsSign;
  39603. var contribution, sign0, sign1, significance1;
  39604. var contextLabel, decoded;
  39605. // calculate horizontal contribution
  39606. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  39607. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  39608. sign1 = coefficentsSign[index + 1];
  39609. if (significance1) {
  39610. sign0 = coefficentsSign[index - 1];
  39611. contribution = 1 - sign1 - sign0;
  39612. } else {
  39613. contribution = 1 - sign1 - sign1;
  39614. }
  39615. } else if (significance1) {
  39616. sign0 = coefficentsSign[index - 1];
  39617. contribution = 1 - sign0 - sign0;
  39618. } else {
  39619. contribution = 0;
  39620. }
  39621. var horizontalContribution = 3 * contribution;
  39622. // calculate vertical contribution and combine with the horizontal
  39623. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  39624. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  39625. sign1 = coefficentsSign[index + width];
  39626. if (significance1) {
  39627. sign0 = coefficentsSign[index - width];
  39628. contribution = 1 - sign1 - sign0 + horizontalContribution;
  39629. } else {
  39630. contribution = 1 - sign1 - sign1 + horizontalContribution;
  39631. }
  39632. } else if (significance1) {
  39633. sign0 = coefficentsSign[index - width];
  39634. contribution = 1 - sign0 - sign0 + horizontalContribution;
  39635. } else {
  39636. contribution = horizontalContribution;
  39637. }
  39638. if (contribution >= 0) {
  39639. contextLabel = 9 + contribution;
  39640. decoded = this.decoder.readBit(this.contexts, contextLabel);
  39641. } else {
  39642. contextLabel = 9 - contribution;
  39643. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  39644. }
  39645. return decoded;
  39646. },
  39647. runMagnitudeRefinementPass:
  39648. function BitModel_runMagnitudeRefinementPass() {
  39649. var decoder = this.decoder;
  39650. var width = this.width, height = this.height;
  39651. var coefficentsMagnitude = this.coefficentsMagnitude;
  39652. var neighborsSignificance = this.neighborsSignificance;
  39653. var contexts = this.contexts;
  39654. var bitsDecoded = this.bitsDecoded;
  39655. var processingFlags = this.processingFlags;
  39656. var processedMask = 1;
  39657. var firstMagnitudeBitMask = 2;
  39658. var length = width * height;
  39659. var width4 = width * 4;
  39660. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  39661. indexNext = Math.min(length, index0 + width4);
  39662. for (var j = 0; j < width; j++) {
  39663. for (var index = index0 + j; index < indexNext; index += width) {
  39664. // significant but not those that have just become
  39665. if (!coefficentsMagnitude[index] ||
  39666. (processingFlags[index] & processedMask) !== 0) {
  39667. continue;
  39668. }
  39669. var contextLabel = 16;
  39670. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  39671. processingFlags[index] ^= firstMagnitudeBitMask;
  39672. // first refinement
  39673. var significance = neighborsSignificance[index] & 127;
  39674. contextLabel = significance === 0 ? 15 : 14;
  39675. }
  39676. var bit = decoder.readBit(contexts, contextLabel);
  39677. coefficentsMagnitude[index] =
  39678. (coefficentsMagnitude[index] << 1) | bit;
  39679. bitsDecoded[index]++;
  39680. processingFlags[index] |= processedMask;
  39681. }
  39682. }
  39683. }
  39684. },
  39685. runCleanupPass: function BitModel_runCleanupPass() {
  39686. var decoder = this.decoder;
  39687. var width = this.width, height = this.height;
  39688. var neighborsSignificance = this.neighborsSignificance;
  39689. var coefficentsMagnitude = this.coefficentsMagnitude;
  39690. var coefficentsSign = this.coefficentsSign;
  39691. var contexts = this.contexts;
  39692. var labels = this.contextLabelTable;
  39693. var bitsDecoded = this.bitsDecoded;
  39694. var processingFlags = this.processingFlags;
  39695. var processedMask = 1;
  39696. var firstMagnitudeBitMask = 2;
  39697. var oneRowDown = width;
  39698. var twoRowsDown = width * 2;
  39699. var threeRowsDown = width * 3;
  39700. var iNext;
  39701. for (var i0 = 0; i0 < height; i0 = iNext) {
  39702. iNext = Math.min(i0 + 4, height);
  39703. var indexBase = i0 * width;
  39704. var checkAllEmpty = i0 + 3 < height;
  39705. for (var j = 0; j < width; j++) {
  39706. var index0 = indexBase + j;
  39707. // using the property: labels[neighborsSignificance[index]] === 0
  39708. // when neighborsSignificance[index] === 0
  39709. var allEmpty = (checkAllEmpty &&
  39710. processingFlags[index0] === 0 &&
  39711. processingFlags[index0 + oneRowDown] === 0 &&
  39712. processingFlags[index0 + twoRowsDown] === 0 &&
  39713. processingFlags[index0 + threeRowsDown] === 0 &&
  39714. neighborsSignificance[index0] === 0 &&
  39715. neighborsSignificance[index0 + oneRowDown] === 0 &&
  39716. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  39717. neighborsSignificance[index0 + threeRowsDown] === 0);
  39718. var i1 = 0, index = index0;
  39719. var i = i0, sign;
  39720. if (allEmpty) {
  39721. var hasSignificantCoefficent =
  39722. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  39723. if (!hasSignificantCoefficent) {
  39724. bitsDecoded[index0]++;
  39725. bitsDecoded[index0 + oneRowDown]++;
  39726. bitsDecoded[index0 + twoRowsDown]++;
  39727. bitsDecoded[index0 + threeRowsDown]++;
  39728. continue; // next column
  39729. }
  39730. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  39731. decoder.readBit(contexts, UNIFORM_CONTEXT);
  39732. if (i1 !== 0) {
  39733. i = i0 + i1;
  39734. index += i1 * width;
  39735. }
  39736. sign = this.decodeSignBit(i, j, index);
  39737. coefficentsSign[index] = sign;
  39738. coefficentsMagnitude[index] = 1;
  39739. this.setNeighborsSignificance(i, j, index);
  39740. processingFlags[index] |= firstMagnitudeBitMask;
  39741. index = index0;
  39742. for (var i2 = i0; i2 <= i; i2++, index += width) {
  39743. bitsDecoded[index]++;
  39744. }
  39745. i1++;
  39746. }
  39747. for (i = i0 + i1; i < iNext; i++, index += width) {
  39748. if (coefficentsMagnitude[index] ||
  39749. (processingFlags[index] & processedMask) !== 0) {
  39750. continue;
  39751. }
  39752. var contextLabel = labels[neighborsSignificance[index]];
  39753. var decision = decoder.readBit(contexts, contextLabel);
  39754. if (decision === 1) {
  39755. sign = this.decodeSignBit(i, j, index);
  39756. coefficentsSign[index] = sign;
  39757. coefficentsMagnitude[index] = 1;
  39758. this.setNeighborsSignificance(i, j, index);
  39759. processingFlags[index] |= firstMagnitudeBitMask;
  39760. }
  39761. bitsDecoded[index]++;
  39762. }
  39763. }
  39764. }
  39765. },
  39766. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  39767. var decoder = this.decoder;
  39768. var contexts = this.contexts;
  39769. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  39770. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  39771. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  39772. decoder.readBit(contexts, UNIFORM_CONTEXT);
  39773. if (symbol !== 0xA) {
  39774. throw new Error('JPX Error: Invalid segmentation symbol');
  39775. }
  39776. }
  39777. };
  39778. return BitModel;
  39779. })();
  39780. // Section F, Discrete wavelet transformation
  39781. var Transform = (function TransformClosure() {
  39782. function Transform() {}
  39783. Transform.prototype.calculate =
  39784. function transformCalculate(subbands, u0, v0) {
  39785. var ll = subbands[0];
  39786. for (var i = 1, ii = subbands.length; i < ii; i++) {
  39787. ll = this.iterate(ll, subbands[i], u0, v0);
  39788. }
  39789. return ll;
  39790. };
  39791. Transform.prototype.extend = function extend(buffer, offset, size) {
  39792. // Section F.3.7 extending... using max extension of 4
  39793. var i1 = offset - 1, j1 = offset + 1;
  39794. var i2 = offset + size - 2, j2 = offset + size;
  39795. buffer[i1--] = buffer[j1++];
  39796. buffer[j2++] = buffer[i2--];
  39797. buffer[i1--] = buffer[j1++];
  39798. buffer[j2++] = buffer[i2--];
  39799. buffer[i1--] = buffer[j1++];
  39800. buffer[j2++] = buffer[i2--];
  39801. buffer[i1] = buffer[j1];
  39802. buffer[j2] = buffer[i2];
  39803. };
  39804. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  39805. u0, v0) {
  39806. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  39807. var width = hl_lh_hh.width;
  39808. var height = hl_lh_hh.height;
  39809. var items = hl_lh_hh.items;
  39810. var i, j, k, l, u, v;
  39811. // Interleave LL according to Section F.3.3
  39812. for (k = 0, i = 0; i < llHeight; i++) {
  39813. l = i * 2 * width;
  39814. for (j = 0; j < llWidth; j++, k++, l += 2) {
  39815. items[l] = llItems[k];
  39816. }
  39817. }
  39818. // The LL band is not needed anymore.
  39819. llItems = ll.items = null;
  39820. var bufferPadding = 4;
  39821. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  39822. // Section F.3.4 HOR_SR
  39823. if (width === 1) {
  39824. // if width = 1, when u0 even keep items as is, when odd divide by 2
  39825. if ((u0 & 1) !== 0) {
  39826. for (v = 0, k = 0; v < height; v++, k += width) {
  39827. items[k] *= 0.5;
  39828. }
  39829. }
  39830. } else {
  39831. for (v = 0, k = 0; v < height; v++, k += width) {
  39832. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  39833. this.extend(rowBuffer, bufferPadding, width);
  39834. this.filter(rowBuffer, bufferPadding, width);
  39835. items.set(
  39836. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  39837. k);
  39838. }
  39839. }
  39840. // Accesses to the items array can take long, because it may not fit into
  39841. // CPU cache and has to be fetched from main memory. Since subsequent
  39842. // accesses to the items array are not local when reading columns, we
  39843. // have a cache miss every time. To reduce cache misses, get up to
  39844. // 'numBuffers' items at a time and store them into the individual
  39845. // buffers. The colBuffers should be small enough to fit into CPU cache.
  39846. var numBuffers = 16;
  39847. var colBuffers = [];
  39848. for (i = 0; i < numBuffers; i++) {
  39849. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  39850. }
  39851. var b, currentBuffer = 0;
  39852. ll = bufferPadding + height;
  39853. // Section F.3.5 VER_SR
  39854. if (height === 1) {
  39855. // if height = 1, when v0 even keep items as is, when odd divide by 2
  39856. if ((v0 & 1) !== 0) {
  39857. for (u = 0; u < width; u++) {
  39858. items[u] *= 0.5;
  39859. }
  39860. }
  39861. } else {
  39862. for (u = 0; u < width; u++) {
  39863. // if we ran out of buffers, copy several image columns at once
  39864. if (currentBuffer === 0) {
  39865. numBuffers = Math.min(width - u, numBuffers);
  39866. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  39867. for (b = 0; b < numBuffers; b++) {
  39868. colBuffers[b][l] = items[k + b];
  39869. }
  39870. }
  39871. currentBuffer = numBuffers;
  39872. }
  39873. currentBuffer--;
  39874. var buffer = colBuffers[currentBuffer];
  39875. this.extend(buffer, bufferPadding, height);
  39876. this.filter(buffer, bufferPadding, height);
  39877. // If this is last buffer in this group of buffers, flush all buffers.
  39878. if (currentBuffer === 0) {
  39879. k = u - numBuffers + 1;
  39880. for (l = bufferPadding; l < ll; k += width, l++) {
  39881. for (b = 0; b < numBuffers; b++) {
  39882. items[k + b] = colBuffers[b][l];
  39883. }
  39884. }
  39885. }
  39886. }
  39887. }
  39888. return {
  39889. width: width,
  39890. height: height,
  39891. items: items
  39892. };
  39893. };
  39894. return Transform;
  39895. })();
  39896. // Section 3.8.2 Irreversible 9-7 filter
  39897. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  39898. function IrreversibleTransform() {
  39899. Transform.call(this);
  39900. }
  39901. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  39902. IrreversibleTransform.prototype.filter =
  39903. function irreversibleTransformFilter(x, offset, length) {
  39904. var len = length >> 1;
  39905. offset = offset | 0;
  39906. var j, n, current, next;
  39907. var alpha = -1.586134342059924;
  39908. var beta = -0.052980118572961;
  39909. var gamma = 0.882911075530934;
  39910. var delta = 0.443506852043971;
  39911. var K = 1.230174104914001;
  39912. var K_ = 1 / K;
  39913. // step 1 is combined with step 3
  39914. // step 2
  39915. j = offset - 3;
  39916. for (n = len + 4; n--; j += 2) {
  39917. x[j] *= K_;
  39918. }
  39919. // step 1 & 3
  39920. j = offset - 2;
  39921. current = delta * x[j -1];
  39922. for (n = len + 3; n--; j += 2) {
  39923. next = delta * x[j + 1];
  39924. x[j] = K * x[j] - current - next;
  39925. if (n--) {
  39926. j += 2;
  39927. current = delta * x[j + 1];
  39928. x[j] = K * x[j] - current - next;
  39929. } else {
  39930. break;
  39931. }
  39932. }
  39933. // step 4
  39934. j = offset - 1;
  39935. current = gamma * x[j - 1];
  39936. for (n = len + 2; n--; j += 2) {
  39937. next = gamma * x[j + 1];
  39938. x[j] -= current + next;
  39939. if (n--) {
  39940. j += 2;
  39941. current = gamma * x[j + 1];
  39942. x[j] -= current + next;
  39943. } else {
  39944. break;
  39945. }
  39946. }
  39947. // step 5
  39948. j = offset;
  39949. current = beta * x[j - 1];
  39950. for (n = len + 1; n--; j += 2) {
  39951. next = beta * x[j + 1];
  39952. x[j] -= current + next;
  39953. if (n--) {
  39954. j += 2;
  39955. current = beta * x[j + 1];
  39956. x[j] -= current + next;
  39957. } else {
  39958. break;
  39959. }
  39960. }
  39961. // step 6
  39962. if (len !== 0) {
  39963. j = offset + 1;
  39964. current = alpha * x[j - 1];
  39965. for (n = len; n--; j += 2) {
  39966. next = alpha * x[j + 1];
  39967. x[j] -= current + next;
  39968. if (n--) {
  39969. j += 2;
  39970. current = alpha * x[j + 1];
  39971. x[j] -= current + next;
  39972. } else {
  39973. break;
  39974. }
  39975. }
  39976. }
  39977. };
  39978. return IrreversibleTransform;
  39979. })();
  39980. // Section 3.8.1 Reversible 5-3 filter
  39981. var ReversibleTransform = (function ReversibleTransformClosure() {
  39982. function ReversibleTransform() {
  39983. Transform.call(this);
  39984. }
  39985. ReversibleTransform.prototype = Object.create(Transform.prototype);
  39986. ReversibleTransform.prototype.filter =
  39987. function reversibleTransformFilter(x, offset, length) {
  39988. var len = length >> 1;
  39989. offset = offset | 0;
  39990. var j, n;
  39991. for (j = offset, n = len + 1; n--; j += 2) {
  39992. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  39993. }
  39994. for (j = offset + 1, n = len; n--; j += 2) {
  39995. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  39996. }
  39997. };
  39998. return ReversibleTransform;
  39999. })();
  40000. return JpxImage;
  40001. })();
  40002. var Jbig2Image = (function Jbig2ImageClosure() {
  40003. // Utility data structures
  40004. function ContextCache() {}
  40005. ContextCache.prototype = {
  40006. getContexts: function(id) {
  40007. if (id in this) {
  40008. return this[id];
  40009. }
  40010. return (this[id] = new Int8Array(1 << 16));
  40011. }
  40012. };
  40013. function DecodingContext(data, start, end) {
  40014. this.data = data;
  40015. this.start = start;
  40016. this.end = end;
  40017. }
  40018. DecodingContext.prototype = {
  40019. get decoder() {
  40020. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40021. return shadow(this, 'decoder', decoder);
  40022. },
  40023. get contextCache() {
  40024. var cache = new ContextCache();
  40025. return shadow(this, 'contextCache', cache);
  40026. }
  40027. };
  40028. // Annex A. Arithmetic Integer Decoding Procedure
  40029. // A.2 Procedure for decoding values
  40030. function decodeInteger(contextCache, procedure, decoder) {
  40031. var contexts = contextCache.getContexts(procedure);
  40032. var prev = 1;
  40033. function readBits(length) {
  40034. var v = 0;
  40035. for (var i = 0; i < length; i++) {
  40036. var bit = decoder.readBit(contexts, prev);
  40037. prev = (prev < 256 ? (prev << 1) | bit :
  40038. (((prev << 1) | bit) & 511) | 256);
  40039. v = (v << 1) | bit;
  40040. }
  40041. return v >>> 0;
  40042. }
  40043. var sign = readBits(1);
  40044. var value = readBits(1) ?
  40045. (readBits(1) ?
  40046. (readBits(1) ?
  40047. (readBits(1) ?
  40048. (readBits(1) ?
  40049. (readBits(32) + 4436) :
  40050. readBits(12) + 340) :
  40051. readBits(8) + 84) :
  40052. readBits(6) + 20) :
  40053. readBits(4) + 4) :
  40054. readBits(2);
  40055. return (sign === 0 ? value : (value > 0 ? -value : null));
  40056. }
  40057. // A.3 The IAID decoding procedure
  40058. function decodeIAID(contextCache, decoder, codeLength) {
  40059. var contexts = contextCache.getContexts('IAID');
  40060. var prev = 1;
  40061. for (var i = 0; i < codeLength; i++) {
  40062. var bit = decoder.readBit(contexts, prev);
  40063. prev = (prev << 1) | bit;
  40064. }
  40065. if (codeLength < 31) {
  40066. return prev & ((1 << codeLength) - 1);
  40067. }
  40068. return prev & 0x7FFFFFFF;
  40069. }
  40070. // 7.3 Segment types
  40071. var SegmentTypes = [
  40072. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  40073. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  40074. null, null, null, null, null, 'patternDictionary', null, null, null,
  40075. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  40076. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  40077. null, null, null, null, null, 'IntermediateGenericRegion', null,
  40078. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  40079. 'IntermediateGenericRefinementRegion', null,
  40080. 'ImmediateGenericRefinementRegion',
  40081. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  40082. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  40083. 'Tables', null, null, null, null, null, null, null, null,
  40084. 'Extension'
  40085. ];
  40086. var CodingTemplates = [
  40087. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40088. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  40089. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40090. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  40091. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  40092. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40093. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40094. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  40095. {x: -1, y: 0}],
  40096. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  40097. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  40098. ];
  40099. var RefinementTemplates = [
  40100. {
  40101. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40102. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  40103. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  40104. },
  40105. {
  40106. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40107. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  40108. {x: 0, y: 1}, {x: 1, y: 1}]
  40109. }
  40110. ];
  40111. // See 6.2.5.7 Decoding the bitmap.
  40112. var ReusedContexts = [
  40113. 0x9B25, // 10011 0110010 0101
  40114. 0x0795, // 0011 110010 101
  40115. 0x00E5, // 001 11001 01
  40116. 0x0195 // 011001 0101
  40117. ];
  40118. var RefinementReusedContexts = [
  40119. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  40120. 0x0008 // '0000' + '001000'
  40121. ];
  40122. function decodeBitmapTemplate0(width, height, decodingContext) {
  40123. var decoder = decodingContext.decoder;
  40124. var contexts = decodingContext.contextCache.getContexts('GB');
  40125. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  40126. // ...ooooo....
  40127. // ..ooooooo... Context template for current pixel (X)
  40128. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  40129. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  40130. for (i = 0; i < height; i++) {
  40131. row = bitmap[i] = new Uint8Array(width);
  40132. row1 = (i < 1) ? row : bitmap[i - 1];
  40133. row2 = (i < 2) ? row : bitmap[i - 2];
  40134. // At the beginning of each row:
  40135. // Fill contextLabel with pixels that are above/right of (X)
  40136. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  40137. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  40138. (row1[3] << 4);
  40139. for (j = 0; j < width; j++) {
  40140. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  40141. // At each pixel: Clear contextLabel pixels that are shifted
  40142. // out of the context, then add new ones.
  40143. // If j + n is out of range at the right image border, then
  40144. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  40145. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  40146. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  40147. }
  40148. }
  40149. return bitmap;
  40150. }
  40151. // 6.2 Generic Region Decoding Procedure
  40152. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  40153. decodingContext) {
  40154. if (mmr) {
  40155. error('JBIG2 error: MMR encoding is not supported');
  40156. }
  40157. // Use optimized version for the most common case
  40158. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  40159. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  40160. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  40161. return decodeBitmapTemplate0(width, height, decodingContext);
  40162. }
  40163. var useskip = !!skip;
  40164. var template = CodingTemplates[templateIndex].concat(at);
  40165. // Sorting is non-standard, and it is not required. But sorting increases
  40166. // the number of template bits that can be reused from the previous
  40167. // contextLabel in the main loop.
  40168. template.sort(function (a, b) {
  40169. return (a.y - b.y) || (a.x - b.x);
  40170. });
  40171. var templateLength = template.length;
  40172. var templateX = new Int8Array(templateLength);
  40173. var templateY = new Int8Array(templateLength);
  40174. var changingTemplateEntries = [];
  40175. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  40176. var c, k;
  40177. for (k = 0; k < templateLength; k++) {
  40178. templateX[k] = template[k].x;
  40179. templateY[k] = template[k].y;
  40180. minX = Math.min(minX, template[k].x);
  40181. maxX = Math.max(maxX, template[k].x);
  40182. minY = Math.min(minY, template[k].y);
  40183. // Check if the template pixel appears in two consecutive context labels,
  40184. // so it can be reused. Otherwise, we add it to the list of changing
  40185. // template entries.
  40186. if (k < templateLength - 1 &&
  40187. template[k].y === template[k + 1].y &&
  40188. template[k].x === template[k + 1].x - 1) {
  40189. reuseMask |= 1 << (templateLength - 1 - k);
  40190. } else {
  40191. changingTemplateEntries.push(k);
  40192. }
  40193. }
  40194. var changingEntriesLength = changingTemplateEntries.length;
  40195. var changingTemplateX = new Int8Array(changingEntriesLength);
  40196. var changingTemplateY = new Int8Array(changingEntriesLength);
  40197. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  40198. for (c = 0; c < changingEntriesLength; c++) {
  40199. k = changingTemplateEntries[c];
  40200. changingTemplateX[c] = template[k].x;
  40201. changingTemplateY[c] = template[k].y;
  40202. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  40203. }
  40204. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  40205. var sbb_left = -minX;
  40206. var sbb_top = -minY;
  40207. var sbb_right = width - maxX;
  40208. var pseudoPixelContext = ReusedContexts[templateIndex];
  40209. var row = new Uint8Array(width);
  40210. var bitmap = [];
  40211. var decoder = decodingContext.decoder;
  40212. var contexts = decodingContext.contextCache.getContexts('GB');
  40213. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  40214. for (var i = 0; i < height; i++) {
  40215. if (prediction) {
  40216. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  40217. ltp ^= sltp;
  40218. if (ltp) {
  40219. bitmap.push(row); // duplicate previous row
  40220. continue;
  40221. }
  40222. }
  40223. row = new Uint8Array(row);
  40224. bitmap.push(row);
  40225. for (j = 0; j < width; j++) {
  40226. if (useskip && skip[i][j]) {
  40227. row[j] = 0;
  40228. continue;
  40229. }
  40230. // Are we in the middle of a scanline, so we can reuse contextLabel
  40231. // bits?
  40232. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  40233. // If yes, we can just shift the bits that are reusable and only
  40234. // fetch the remaining ones.
  40235. contextLabel = (contextLabel << 1) & reuseMask;
  40236. for (k = 0; k < changingEntriesLength; k++) {
  40237. i0 = i + changingTemplateY[k];
  40238. j0 = j + changingTemplateX[k];
  40239. bit = bitmap[i0][j0];
  40240. if (bit) {
  40241. bit = changingTemplateBit[k];
  40242. contextLabel |= bit;
  40243. }
  40244. }
  40245. } else {
  40246. // compute the contextLabel from scratch
  40247. contextLabel = 0;
  40248. shift = templateLength - 1;
  40249. for (k = 0; k < templateLength; k++, shift--) {
  40250. j0 = j + templateX[k];
  40251. if (j0 >= 0 && j0 < width) {
  40252. i0 = i + templateY[k];
  40253. if (i0 >= 0) {
  40254. bit = bitmap[i0][j0];
  40255. if (bit) {
  40256. contextLabel |= bit << shift;
  40257. }
  40258. }
  40259. }
  40260. }
  40261. }
  40262. var pixel = decoder.readBit(contexts, contextLabel);
  40263. row[j] = pixel;
  40264. }
  40265. }
  40266. return bitmap;
  40267. }
  40268. // 6.3.2 Generic Refinement Region Decoding Procedure
  40269. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  40270. offsetX, offsetY, prediction, at,
  40271. decodingContext) {
  40272. var codingTemplate = RefinementTemplates[templateIndex].coding;
  40273. if (templateIndex === 0) {
  40274. codingTemplate = codingTemplate.concat([at[0]]);
  40275. }
  40276. var codingTemplateLength = codingTemplate.length;
  40277. var codingTemplateX = new Int32Array(codingTemplateLength);
  40278. var codingTemplateY = new Int32Array(codingTemplateLength);
  40279. var k;
  40280. for (k = 0; k < codingTemplateLength; k++) {
  40281. codingTemplateX[k] = codingTemplate[k].x;
  40282. codingTemplateY[k] = codingTemplate[k].y;
  40283. }
  40284. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  40285. if (templateIndex === 0) {
  40286. referenceTemplate = referenceTemplate.concat([at[1]]);
  40287. }
  40288. var referenceTemplateLength = referenceTemplate.length;
  40289. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  40290. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  40291. for (k = 0; k < referenceTemplateLength; k++) {
  40292. referenceTemplateX[k] = referenceTemplate[k].x;
  40293. referenceTemplateY[k] = referenceTemplate[k].y;
  40294. }
  40295. var referenceWidth = referenceBitmap[0].length;
  40296. var referenceHeight = referenceBitmap.length;
  40297. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  40298. var bitmap = [];
  40299. var decoder = decodingContext.decoder;
  40300. var contexts = decodingContext.contextCache.getContexts('GR');
  40301. var ltp = 0;
  40302. for (var i = 0; i < height; i++) {
  40303. if (prediction) {
  40304. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  40305. ltp ^= sltp;
  40306. if (ltp) {
  40307. error('JBIG2 error: prediction is not supported');
  40308. }
  40309. }
  40310. var row = new Uint8Array(width);
  40311. bitmap.push(row);
  40312. for (var j = 0; j < width; j++) {
  40313. var i0, j0;
  40314. var contextLabel = 0;
  40315. for (k = 0; k < codingTemplateLength; k++) {
  40316. i0 = i + codingTemplateY[k];
  40317. j0 = j + codingTemplateX[k];
  40318. if (i0 < 0 || j0 < 0 || j0 >= width) {
  40319. contextLabel <<= 1; // out of bound pixel
  40320. } else {
  40321. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  40322. }
  40323. }
  40324. for (k = 0; k < referenceTemplateLength; k++) {
  40325. i0 = i + referenceTemplateY[k] + offsetY;
  40326. j0 = j + referenceTemplateX[k] + offsetX;
  40327. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  40328. j0 >= referenceWidth) {
  40329. contextLabel <<= 1; // out of bound pixel
  40330. } else {
  40331. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  40332. }
  40333. }
  40334. var pixel = decoder.readBit(contexts, contextLabel);
  40335. row[j] = pixel;
  40336. }
  40337. }
  40338. return bitmap;
  40339. }
  40340. // 6.5.5 Decoding the symbol dictionary
  40341. function decodeSymbolDictionary(huffman, refinement, symbols,
  40342. numberOfNewSymbols, numberOfExportedSymbols,
  40343. huffmanTables, templateIndex, at,
  40344. refinementTemplateIndex, refinementAt,
  40345. decodingContext) {
  40346. if (huffman) {
  40347. error('JBIG2 error: huffman is not supported');
  40348. }
  40349. var newSymbols = [];
  40350. var currentHeight = 0;
  40351. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  40352. var decoder = decodingContext.decoder;
  40353. var contextCache = decodingContext.contextCache;
  40354. while (newSymbols.length < numberOfNewSymbols) {
  40355. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  40356. currentHeight += deltaHeight;
  40357. var currentWidth = 0;
  40358. var totalWidth = 0;
  40359. while (true) {
  40360. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  40361. if (deltaWidth === null) {
  40362. break; // OOB
  40363. }
  40364. currentWidth += deltaWidth;
  40365. totalWidth += currentWidth;
  40366. var bitmap;
  40367. if (refinement) {
  40368. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  40369. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  40370. if (numberOfInstances > 1) {
  40371. bitmap = decodeTextRegion(huffman, refinement,
  40372. currentWidth, currentHeight, 0,
  40373. numberOfInstances, 1, //strip size
  40374. symbols.concat(newSymbols),
  40375. symbolCodeLength,
  40376. 0, //transposed
  40377. 0, //ds offset
  40378. 1, //top left 7.4.3.1.1
  40379. 0, //OR operator
  40380. huffmanTables,
  40381. refinementTemplateIndex, refinementAt,
  40382. decodingContext);
  40383. } else {
  40384. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  40385. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  40386. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  40387. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  40388. newSymbols[symbolId - symbols.length]);
  40389. bitmap = decodeRefinement(currentWidth, currentHeight,
  40390. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  40391. decodingContext);
  40392. }
  40393. } else {
  40394. // 6.5.8.1 Direct-coded symbol bitmap
  40395. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  40396. templateIndex, false, null, at, decodingContext);
  40397. }
  40398. newSymbols.push(bitmap);
  40399. }
  40400. }
  40401. // 6.5.10 Exported symbols
  40402. var exportedSymbols = [];
  40403. var flags = [], currentFlag = false;
  40404. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  40405. while (flags.length < totalSymbolsLength) {
  40406. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  40407. while (runLength--) {
  40408. flags.push(currentFlag);
  40409. }
  40410. currentFlag = !currentFlag;
  40411. }
  40412. for (var i = 0, ii = symbols.length; i < ii; i++) {
  40413. if (flags[i]) {
  40414. exportedSymbols.push(symbols[i]);
  40415. }
  40416. }
  40417. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  40418. if (flags[i]) {
  40419. exportedSymbols.push(newSymbols[j]);
  40420. }
  40421. }
  40422. return exportedSymbols;
  40423. }
  40424. function decodeTextRegion(huffman, refinement, width, height,
  40425. defaultPixelValue, numberOfSymbolInstances,
  40426. stripSize, inputSymbols, symbolCodeLength,
  40427. transposed, dsOffset, referenceCorner,
  40428. combinationOperator, huffmanTables,
  40429. refinementTemplateIndex, refinementAt,
  40430. decodingContext) {
  40431. if (huffman) {
  40432. error('JBIG2 error: huffman is not supported');
  40433. }
  40434. // Prepare bitmap
  40435. var bitmap = [];
  40436. var i, row;
  40437. for (i = 0; i < height; i++) {
  40438. row = new Uint8Array(width);
  40439. if (defaultPixelValue) {
  40440. for (var j = 0; j < width; j++) {
  40441. row[j] = defaultPixelValue;
  40442. }
  40443. }
  40444. bitmap.push(row);
  40445. }
  40446. var decoder = decodingContext.decoder;
  40447. var contextCache = decodingContext.contextCache;
  40448. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  40449. var firstS = 0;
  40450. i = 0;
  40451. while (i < numberOfSymbolInstances) {
  40452. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  40453. stripT += deltaT;
  40454. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  40455. firstS += deltaFirstS;
  40456. var currentS = firstS;
  40457. do {
  40458. var currentT = (stripSize === 1 ? 0 :
  40459. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  40460. var t = stripSize * stripT + currentT;
  40461. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  40462. var applyRefinement = (refinement &&
  40463. decodeInteger(contextCache, 'IARI', decoder));
  40464. var symbolBitmap = inputSymbols[symbolId];
  40465. var symbolWidth = symbolBitmap[0].length;
  40466. var symbolHeight = symbolBitmap.length;
  40467. if (applyRefinement) {
  40468. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  40469. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  40470. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  40471. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  40472. symbolWidth += rdw;
  40473. symbolHeight += rdh;
  40474. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  40475. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  40476. (rdh >> 1) + rdy, false, refinementAt,
  40477. decodingContext);
  40478. }
  40479. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  40480. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  40481. var s2, t2, symbolRow;
  40482. if (transposed) {
  40483. // Place Symbol Bitmap from T1,S1
  40484. for (s2 = 0; s2 < symbolHeight; s2++) {
  40485. row = bitmap[offsetS + s2];
  40486. if (!row) {
  40487. continue;
  40488. }
  40489. symbolRow = symbolBitmap[s2];
  40490. // To ignore Parts of Symbol bitmap which goes
  40491. // outside bitmap region
  40492. var maxWidth = Math.min(width - offsetT, symbolWidth);
  40493. switch (combinationOperator) {
  40494. case 0: // OR
  40495. for (t2 = 0; t2 < maxWidth; t2++) {
  40496. row[offsetT + t2] |= symbolRow[t2];
  40497. }
  40498. break;
  40499. case 2: // XOR
  40500. for (t2 = 0; t2 < maxWidth; t2++) {
  40501. row[offsetT + t2] ^= symbolRow[t2];
  40502. }
  40503. break;
  40504. default:
  40505. error('JBIG2 error: operator ' + combinationOperator +
  40506. ' is not supported');
  40507. }
  40508. }
  40509. currentS += symbolHeight - 1;
  40510. } else {
  40511. for (t2 = 0; t2 < symbolHeight; t2++) {
  40512. row = bitmap[offsetT + t2];
  40513. if (!row) {
  40514. continue;
  40515. }
  40516. symbolRow = symbolBitmap[t2];
  40517. switch (combinationOperator) {
  40518. case 0: // OR
  40519. for (s2 = 0; s2 < symbolWidth; s2++) {
  40520. row[offsetS + s2] |= symbolRow[s2];
  40521. }
  40522. break;
  40523. case 2: // XOR
  40524. for (s2 = 0; s2 < symbolWidth; s2++) {
  40525. row[offsetS + s2] ^= symbolRow[s2];
  40526. }
  40527. break;
  40528. default:
  40529. error('JBIG2 error: operator ' + combinationOperator +
  40530. ' is not supported');
  40531. }
  40532. }
  40533. currentS += symbolWidth - 1;
  40534. }
  40535. i++;
  40536. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  40537. if (deltaS === null) {
  40538. break; // OOB
  40539. }
  40540. currentS += deltaS + dsOffset;
  40541. } while (true);
  40542. }
  40543. return bitmap;
  40544. }
  40545. function readSegmentHeader(data, start) {
  40546. var segmentHeader = {};
  40547. segmentHeader.number = readUint32(data, start);
  40548. var flags = data[start + 4];
  40549. var segmentType = flags & 0x3F;
  40550. if (!SegmentTypes[segmentType]) {
  40551. error('JBIG2 error: invalid segment type: ' + segmentType);
  40552. }
  40553. segmentHeader.type = segmentType;
  40554. segmentHeader.typeName = SegmentTypes[segmentType];
  40555. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  40556. var pageAssociationFieldSize = !!(flags & 0x40);
  40557. var referredFlags = data[start + 5];
  40558. var referredToCount = (referredFlags >> 5) & 7;
  40559. var retainBits = [referredFlags & 31];
  40560. var position = start + 6;
  40561. if (referredFlags === 7) {
  40562. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  40563. position += 3;
  40564. var bytes = (referredToCount + 7) >> 3;
  40565. retainBits[0] = data[position++];
  40566. while (--bytes > 0) {
  40567. retainBits.push(data[position++]);
  40568. }
  40569. } else if (referredFlags === 5 || referredFlags === 6) {
  40570. error('JBIG2 error: invalid referred-to flags');
  40571. }
  40572. segmentHeader.retainBits = retainBits;
  40573. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  40574. (segmentHeader.number <= 65536 ? 2 : 4));
  40575. var referredTo = [];
  40576. var i, ii;
  40577. for (i = 0; i < referredToCount; i++) {
  40578. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  40579. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  40580. readUint32(data, position)));
  40581. referredTo.push(number);
  40582. position += referredToSegmentNumberSize;
  40583. }
  40584. segmentHeader.referredTo = referredTo;
  40585. if (!pageAssociationFieldSize) {
  40586. segmentHeader.pageAssociation = data[position++];
  40587. } else {
  40588. segmentHeader.pageAssociation = readUint32(data, position);
  40589. position += 4;
  40590. }
  40591. segmentHeader.length = readUint32(data, position);
  40592. position += 4;
  40593. if (segmentHeader.length === 0xFFFFFFFF) {
  40594. // 7.2.7 Segment data length, unknown segment length
  40595. if (segmentType === 38) { // ImmediateGenericRegion
  40596. var genericRegionInfo = readRegionSegmentInformation(data, position);
  40597. var genericRegionSegmentFlags = data[position +
  40598. RegionSegmentInformationFieldLength];
  40599. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  40600. // searching for the segment end
  40601. var searchPatternLength = 6;
  40602. var searchPattern = new Uint8Array(searchPatternLength);
  40603. if (!genericRegionMmr) {
  40604. searchPattern[0] = 0xFF;
  40605. searchPattern[1] = 0xAC;
  40606. }
  40607. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  40608. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  40609. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  40610. searchPattern[5] = genericRegionInfo.height & 0xFF;
  40611. for (i = position, ii = data.length; i < ii; i++) {
  40612. var j = 0;
  40613. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  40614. j++;
  40615. }
  40616. if (j === searchPatternLength) {
  40617. segmentHeader.length = i + searchPatternLength;
  40618. break;
  40619. }
  40620. }
  40621. if (segmentHeader.length === 0xFFFFFFFF) {
  40622. error('JBIG2 error: segment end was not found');
  40623. }
  40624. } else {
  40625. error('JBIG2 error: invalid unknown segment length');
  40626. }
  40627. }
  40628. segmentHeader.headerEnd = position;
  40629. return segmentHeader;
  40630. }
  40631. function readSegments(header, data, start, end) {
  40632. var segments = [];
  40633. var position = start;
  40634. while (position < end) {
  40635. var segmentHeader = readSegmentHeader(data, position);
  40636. position = segmentHeader.headerEnd;
  40637. var segment = {
  40638. header: segmentHeader,
  40639. data: data
  40640. };
  40641. if (!header.randomAccess) {
  40642. segment.start = position;
  40643. position += segmentHeader.length;
  40644. segment.end = position;
  40645. }
  40646. segments.push(segment);
  40647. if (segmentHeader.type === 51) {
  40648. break; // end of file is found
  40649. }
  40650. }
  40651. if (header.randomAccess) {
  40652. for (var i = 0, ii = segments.length; i < ii; i++) {
  40653. segments[i].start = position;
  40654. position += segments[i].header.length;
  40655. segments[i].end = position;
  40656. }
  40657. }
  40658. return segments;
  40659. }
  40660. // 7.4.1 Region segment information field
  40661. function readRegionSegmentInformation(data, start) {
  40662. return {
  40663. width: readUint32(data, start),
  40664. height: readUint32(data, start + 4),
  40665. x: readUint32(data, start + 8),
  40666. y: readUint32(data, start + 12),
  40667. combinationOperator: data[start + 16] & 7
  40668. };
  40669. }
  40670. var RegionSegmentInformationFieldLength = 17;
  40671. function processSegment(segment, visitor) {
  40672. var header = segment.header;
  40673. var data = segment.data, position = segment.start, end = segment.end;
  40674. var args, at, i, atLength;
  40675. switch (header.type) {
  40676. case 0: // SymbolDictionary
  40677. // 7.4.2 Symbol dictionary segment syntax
  40678. var dictionary = {};
  40679. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  40680. dictionary.huffman = !!(dictionaryFlags & 1);
  40681. dictionary.refinement = !!(dictionaryFlags & 2);
  40682. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  40683. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  40684. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  40685. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  40686. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  40687. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  40688. dictionary.template = (dictionaryFlags >> 10) & 3;
  40689. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  40690. position += 2;
  40691. if (!dictionary.huffman) {
  40692. atLength = dictionary.template === 0 ? 4 : 1;
  40693. at = [];
  40694. for (i = 0; i < atLength; i++) {
  40695. at.push({
  40696. x: readInt8(data, position),
  40697. y: readInt8(data, position + 1)
  40698. });
  40699. position += 2;
  40700. }
  40701. dictionary.at = at;
  40702. }
  40703. if (dictionary.refinement && !dictionary.refinementTemplate) {
  40704. at = [];
  40705. for (i = 0; i < 2; i++) {
  40706. at.push({
  40707. x: readInt8(data, position),
  40708. y: readInt8(data, position + 1)
  40709. });
  40710. position += 2;
  40711. }
  40712. dictionary.refinementAt = at;
  40713. }
  40714. dictionary.numberOfExportedSymbols = readUint32(data, position);
  40715. position += 4;
  40716. dictionary.numberOfNewSymbols = readUint32(data, position);
  40717. position += 4;
  40718. args = [dictionary, header.number, header.referredTo,
  40719. data, position, end];
  40720. break;
  40721. case 6: // ImmediateTextRegion
  40722. case 7: // ImmediateLosslessTextRegion
  40723. var textRegion = {};
  40724. textRegion.info = readRegionSegmentInformation(data, position);
  40725. position += RegionSegmentInformationFieldLength;
  40726. var textRegionSegmentFlags = readUint16(data, position);
  40727. position += 2;
  40728. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  40729. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  40730. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  40731. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  40732. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  40733. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  40734. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  40735. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  40736. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  40737. if (textRegion.huffman) {
  40738. var textRegionHuffmanFlags = readUint16(data, position);
  40739. position += 2;
  40740. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  40741. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  40742. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  40743. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  40744. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  40745. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  40746. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  40747. textRegion.huffmanRefinementSizeSelector =
  40748. !!(textRegionHuffmanFlags & 14);
  40749. }
  40750. if (textRegion.refinement && !textRegion.refinementTemplate) {
  40751. at = [];
  40752. for (i = 0; i < 2; i++) {
  40753. at.push({
  40754. x: readInt8(data, position),
  40755. y: readInt8(data, position + 1)
  40756. });
  40757. position += 2;
  40758. }
  40759. textRegion.refinementAt = at;
  40760. }
  40761. textRegion.numberOfSymbolInstances = readUint32(data, position);
  40762. position += 4;
  40763. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  40764. if (textRegion.huffman) {
  40765. error('JBIG2 error: huffman is not supported');
  40766. }
  40767. args = [textRegion, header.referredTo, data, position, end];
  40768. break;
  40769. case 38: // ImmediateGenericRegion
  40770. case 39: // ImmediateLosslessGenericRegion
  40771. var genericRegion = {};
  40772. genericRegion.info = readRegionSegmentInformation(data, position);
  40773. position += RegionSegmentInformationFieldLength;
  40774. var genericRegionSegmentFlags = data[position++];
  40775. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  40776. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  40777. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  40778. if (!genericRegion.mmr) {
  40779. atLength = genericRegion.template === 0 ? 4 : 1;
  40780. at = [];
  40781. for (i = 0; i < atLength; i++) {
  40782. at.push({
  40783. x: readInt8(data, position),
  40784. y: readInt8(data, position + 1)
  40785. });
  40786. position += 2;
  40787. }
  40788. genericRegion.at = at;
  40789. }
  40790. args = [genericRegion, data, position, end];
  40791. break;
  40792. case 48: // PageInformation
  40793. var pageInfo = {
  40794. width: readUint32(data, position),
  40795. height: readUint32(data, position + 4),
  40796. resolutionX: readUint32(data, position + 8),
  40797. resolutionY: readUint32(data, position + 12)
  40798. };
  40799. if (pageInfo.height === 0xFFFFFFFF) {
  40800. delete pageInfo.height;
  40801. }
  40802. var pageSegmentFlags = data[position + 16];
  40803. var pageStripingInformatiom = readUint16(data, position + 17);
  40804. pageInfo.lossless = !!(pageSegmentFlags & 1);
  40805. pageInfo.refinement = !!(pageSegmentFlags & 2);
  40806. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  40807. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  40808. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  40809. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  40810. args = [pageInfo];
  40811. break;
  40812. case 49: // EndOfPage
  40813. break;
  40814. case 50: // EndOfStripe
  40815. break;
  40816. case 51: // EndOfFile
  40817. break;
  40818. case 62: // 7.4.15 defines 2 extension types which
  40819. // are comments and can be ignored.
  40820. break;
  40821. default:
  40822. error('JBIG2 error: segment type ' + header.typeName + '(' +
  40823. header.type + ') is not implemented');
  40824. }
  40825. var callbackName = 'on' + header.typeName;
  40826. if (callbackName in visitor) {
  40827. visitor[callbackName].apply(visitor, args);
  40828. }
  40829. }
  40830. function processSegments(segments, visitor) {
  40831. for (var i = 0, ii = segments.length; i < ii; i++) {
  40832. processSegment(segments[i], visitor);
  40833. }
  40834. }
  40835. function parseJbig2(data, start, end) {
  40836. var position = start;
  40837. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  40838. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  40839. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  40840. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  40841. error('JBIG2 error: invalid header');
  40842. }
  40843. var header = {};
  40844. position += 8;
  40845. var flags = data[position++];
  40846. header.randomAccess = !(flags & 1);
  40847. if (!(flags & 2)) {
  40848. header.numberOfPages = readUint32(data, position);
  40849. position += 4;
  40850. }
  40851. var segments = readSegments(header, data, position, end);
  40852. error('Not implemented');
  40853. // processSegments(segments, new SimpleSegmentVisitor());
  40854. }
  40855. function parseJbig2Chunks(chunks) {
  40856. var visitor = new SimpleSegmentVisitor();
  40857. for (var i = 0, ii = chunks.length; i < ii; i++) {
  40858. var chunk = chunks[i];
  40859. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  40860. processSegments(segments, visitor);
  40861. }
  40862. return visitor.buffer;
  40863. }
  40864. function SimpleSegmentVisitor() {}
  40865. SimpleSegmentVisitor.prototype = {
  40866. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  40867. this.currentPageInfo = info;
  40868. var rowSize = (info.width + 7) >> 3;
  40869. var buffer = new Uint8Array(rowSize * info.height);
  40870. // The contents of ArrayBuffers are initialized to 0.
  40871. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  40872. if (info.defaultPixelValue) {
  40873. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40874. buffer[i] = 0xFF;
  40875. }
  40876. }
  40877. this.buffer = buffer;
  40878. },
  40879. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  40880. var pageInfo = this.currentPageInfo;
  40881. var width = regionInfo.width, height = regionInfo.height;
  40882. var rowSize = (pageInfo.width + 7) >> 3;
  40883. var combinationOperator = pageInfo.combinationOperatorOverride ?
  40884. regionInfo.combinationOperator : pageInfo.combinationOperator;
  40885. var buffer = this.buffer;
  40886. var mask0 = 128 >> (regionInfo.x & 7);
  40887. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  40888. var i, j, mask, offset;
  40889. switch (combinationOperator) {
  40890. case 0: // OR
  40891. for (i = 0; i < height; i++) {
  40892. mask = mask0;
  40893. offset = offset0;
  40894. for (j = 0; j < width; j++) {
  40895. if (bitmap[i][j]) {
  40896. buffer[offset] |= mask;
  40897. }
  40898. mask >>= 1;
  40899. if (!mask) {
  40900. mask = 128;
  40901. offset++;
  40902. }
  40903. }
  40904. offset0 += rowSize;
  40905. }
  40906. break;
  40907. case 2: // XOR
  40908. for (i = 0; i < height; i++) {
  40909. mask = mask0;
  40910. offset = offset0;
  40911. for (j = 0; j < width; j++) {
  40912. if (bitmap[i][j]) {
  40913. buffer[offset] ^= mask;
  40914. }
  40915. mask >>= 1;
  40916. if (!mask) {
  40917. mask = 128;
  40918. offset++;
  40919. }
  40920. }
  40921. offset0 += rowSize;
  40922. }
  40923. break;
  40924. default:
  40925. error('JBIG2 error: operator ' + combinationOperator +
  40926. ' is not supported');
  40927. }
  40928. },
  40929. onImmediateGenericRegion:
  40930. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  40931. start, end) {
  40932. var regionInfo = region.info;
  40933. var decodingContext = new DecodingContext(data, start, end);
  40934. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  40935. region.template, region.prediction, null,
  40936. region.at, decodingContext);
  40937. this.drawBitmap(regionInfo, bitmap);
  40938. },
  40939. onImmediateLosslessGenericRegion:
  40940. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  40941. this.onImmediateGenericRegion.apply(this, arguments);
  40942. },
  40943. onSymbolDictionary:
  40944. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  40945. currentSegment,
  40946. referredSegments,
  40947. data, start, end) {
  40948. var huffmanTables;
  40949. if (dictionary.huffman) {
  40950. error('JBIG2 error: huffman is not supported');
  40951. }
  40952. // Combines exported symbols from all referred segments
  40953. var symbols = this.symbols;
  40954. if (!symbols) {
  40955. this.symbols = symbols = {};
  40956. }
  40957. var inputSymbols = [];
  40958. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  40959. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  40960. }
  40961. var decodingContext = new DecodingContext(data, start, end);
  40962. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  40963. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  40964. dictionary.numberOfExportedSymbols, huffmanTables,
  40965. dictionary.template, dictionary.at,
  40966. dictionary.refinementTemplate, dictionary.refinementAt,
  40967. decodingContext);
  40968. },
  40969. onImmediateTextRegion:
  40970. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  40971. referredSegments,
  40972. data, start, end) {
  40973. var regionInfo = region.info;
  40974. var huffmanTables;
  40975. // Combines exported symbols from all referred segments
  40976. var symbols = this.symbols;
  40977. var inputSymbols = [];
  40978. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  40979. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  40980. }
  40981. var symbolCodeLength = log2(inputSymbols.length);
  40982. var decodingContext = new DecodingContext(data, start, end);
  40983. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  40984. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  40985. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  40986. symbolCodeLength, region.transposed, region.dsOffset,
  40987. region.referenceCorner, region.combinationOperator, huffmanTables,
  40988. region.refinementTemplate, region.refinementAt, decodingContext);
  40989. this.drawBitmap(regionInfo, bitmap);
  40990. },
  40991. onImmediateLosslessTextRegion:
  40992. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  40993. this.onImmediateTextRegion.apply(this, arguments);
  40994. }
  40995. };
  40996. function Jbig2Image() {}
  40997. Jbig2Image.prototype = {
  40998. parseChunks: function Jbig2Image_parseChunks(chunks) {
  40999. return parseJbig2Chunks(chunks);
  41000. }
  41001. };
  41002. return Jbig2Image;
  41003. })();
  41004. var bidi = PDFJS.bidi = (function bidiClosure() {
  41005. // Character types for symbols from 0000 to 00FF.
  41006. var baseTypes = [
  41007. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41008. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41009. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41010. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41011. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41012. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41013. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41014. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41015. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41016. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41017. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41018. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41019. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41020. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41021. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41022. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41023. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41024. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41025. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41026. ];
  41027. // Character types for symbols from 0600 to 06FF
  41028. var arabicTypes = [
  41029. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41030. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41031. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41032. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41033. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41034. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41035. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41036. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41037. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41038. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41039. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41040. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41041. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41042. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41043. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41044. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41045. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41046. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41047. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41048. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41049. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41050. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41051. ];
  41052. function isOdd(i) {
  41053. return (i & 1) !== 0;
  41054. }
  41055. function isEven(i) {
  41056. return (i & 1) === 0;
  41057. }
  41058. function findUnequal(arr, start, value) {
  41059. for (var j = start, jj = arr.length; j < jj; ++j) {
  41060. if (arr[j] !== value) {
  41061. return j;
  41062. }
  41063. }
  41064. return j;
  41065. }
  41066. function setValues(arr, start, end, value) {
  41067. for (var j = start; j < end; ++j) {
  41068. arr[j] = value;
  41069. }
  41070. }
  41071. function reverseValues(arr, start, end) {
  41072. for (var i = start, j = end - 1; i < j; ++i, --j) {
  41073. var temp = arr[i];
  41074. arr[i] = arr[j];
  41075. arr[j] = temp;
  41076. }
  41077. }
  41078. function createBidiText(str, isLTR, vertical) {
  41079. return {
  41080. str: str,
  41081. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  41082. };
  41083. }
  41084. // These are used in bidi(), which is called frequently. We re-use them on
  41085. // each call to avoid unnecessary allocations.
  41086. var chars = [];
  41087. var types = [];
  41088. function bidi(str, startLevel, vertical) {
  41089. var isLTR = true;
  41090. var strLength = str.length;
  41091. if (strLength === 0 || vertical) {
  41092. return createBidiText(str, isLTR, vertical);
  41093. }
  41094. // Get types and fill arrays
  41095. chars.length = strLength;
  41096. types.length = strLength;
  41097. var numBidi = 0;
  41098. var i, ii;
  41099. for (i = 0; i < strLength; ++i) {
  41100. chars[i] = str.charAt(i);
  41101. var charCode = str.charCodeAt(i);
  41102. var charType = 'L';
  41103. if (charCode <= 0x00ff) {
  41104. charType = baseTypes[charCode];
  41105. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  41106. charType = 'R';
  41107. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  41108. charType = arabicTypes[charCode & 0xff];
  41109. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  41110. charType = 'AL';
  41111. }
  41112. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  41113. numBidi++;
  41114. }
  41115. types[i] = charType;
  41116. }
  41117. // Detect the bidi method
  41118. // - If there are no rtl characters then no bidi needed
  41119. // - If less than 30% chars are rtl then string is primarily ltr
  41120. // - If more than 30% chars are rtl then string is primarily rtl
  41121. if (numBidi === 0) {
  41122. isLTR = true;
  41123. return createBidiText(str, isLTR);
  41124. }
  41125. if (startLevel === -1) {
  41126. if ((strLength / numBidi) < 0.3) {
  41127. isLTR = true;
  41128. startLevel = 0;
  41129. } else {
  41130. isLTR = false;
  41131. startLevel = 1;
  41132. }
  41133. }
  41134. var levels = [];
  41135. for (i = 0; i < strLength; ++i) {
  41136. levels[i] = startLevel;
  41137. }
  41138. /*
  41139. X1-X10: skip most of this, since we are NOT doing the embeddings.
  41140. */
  41141. var e = (isOdd(startLevel) ? 'R' : 'L');
  41142. var sor = e;
  41143. var eor = sor;
  41144. /*
  41145. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  41146. type of the NSM to the type of the previous character. If the NSM is at the
  41147. start of the level run, it will get the type of sor.
  41148. */
  41149. var lastType = sor;
  41150. for (i = 0; i < strLength; ++i) {
  41151. if (types[i] === 'NSM') {
  41152. types[i] = lastType;
  41153. } else {
  41154. lastType = types[i];
  41155. }
  41156. }
  41157. /*
  41158. W2. Search backwards from each instance of a European number until the
  41159. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  41160. the type of the European number to Arabic number.
  41161. */
  41162. lastType = sor;
  41163. var t;
  41164. for (i = 0; i < strLength; ++i) {
  41165. t = types[i];
  41166. if (t === 'EN') {
  41167. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  41168. } else if (t === 'R' || t === 'L' || t === 'AL') {
  41169. lastType = t;
  41170. }
  41171. }
  41172. /*
  41173. W3. Change all ALs to R.
  41174. */
  41175. for (i = 0; i < strLength; ++i) {
  41176. t = types[i];
  41177. if (t === 'AL') {
  41178. types[i] = 'R';
  41179. }
  41180. }
  41181. /*
  41182. W4. A single European separator between two European numbers changes to a
  41183. European number. A single common separator between two numbers of the same
  41184. type changes to that type:
  41185. */
  41186. for (i = 1; i < strLength - 1; ++i) {
  41187. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  41188. types[i] = 'EN';
  41189. }
  41190. if (types[i] === 'CS' &&
  41191. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  41192. types[i + 1] === types[i - 1]) {
  41193. types[i] = types[i - 1];
  41194. }
  41195. }
  41196. /*
  41197. W5. A sequence of European terminators adjacent to European numbers changes
  41198. to all European numbers:
  41199. */
  41200. for (i = 0; i < strLength; ++i) {
  41201. if (types[i] === 'EN') {
  41202. // do before
  41203. var j;
  41204. for (j = i - 1; j >= 0; --j) {
  41205. if (types[j] !== 'ET') {
  41206. break;
  41207. }
  41208. types[j] = 'EN';
  41209. }
  41210. // do after
  41211. for (j = i + 1; j < strLength; --j) {
  41212. if (types[j] !== 'ET') {
  41213. break;
  41214. }
  41215. types[j] = 'EN';
  41216. }
  41217. }
  41218. }
  41219. /*
  41220. W6. Otherwise, separators and terminators change to Other Neutral:
  41221. */
  41222. for (i = 0; i < strLength; ++i) {
  41223. t = types[i];
  41224. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  41225. types[i] = 'ON';
  41226. }
  41227. }
  41228. /*
  41229. W7. Search backwards from each instance of a European number until the
  41230. first strong type (R, L, or sor) is found. If an L is found, then change
  41231. the type of the European number to L.
  41232. */
  41233. lastType = sor;
  41234. for (i = 0; i < strLength; ++i) {
  41235. t = types[i];
  41236. if (t === 'EN') {
  41237. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  41238. } else if (t === 'R' || t === 'L') {
  41239. lastType = t;
  41240. }
  41241. }
  41242. /*
  41243. N1. A sequence of neutrals takes the direction of the surrounding strong
  41244. text if the text on both sides has the same direction. European and Arabic
  41245. numbers are treated as though they were R. Start-of-level-run (sor) and
  41246. end-of-level-run (eor) are used at level run boundaries.
  41247. */
  41248. for (i = 0; i < strLength; ++i) {
  41249. if (types[i] === 'ON') {
  41250. var end = findUnequal(types, i + 1, 'ON');
  41251. var before = sor;
  41252. if (i > 0) {
  41253. before = types[i - 1];
  41254. }
  41255. var after = eor;
  41256. if (end + 1 < strLength) {
  41257. after = types[end + 1];
  41258. }
  41259. if (before !== 'L') {
  41260. before = 'R';
  41261. }
  41262. if (after !== 'L') {
  41263. after = 'R';
  41264. }
  41265. if (before === after) {
  41266. setValues(types, i, end, before);
  41267. }
  41268. i = end - 1; // reset to end (-1 so next iteration is ok)
  41269. }
  41270. }
  41271. /*
  41272. N2. Any remaining neutrals take the embedding direction.
  41273. */
  41274. for (i = 0; i < strLength; ++i) {
  41275. if (types[i] === 'ON') {
  41276. types[i] = e;
  41277. }
  41278. }
  41279. /*
  41280. I1. For all characters with an even (left-to-right) embedding direction,
  41281. those of type R go up one level and those of type AN or EN go up two
  41282. levels.
  41283. I2. For all characters with an odd (right-to-left) embedding direction,
  41284. those of type L, EN or AN go up one level.
  41285. */
  41286. for (i = 0; i < strLength; ++i) {
  41287. t = types[i];
  41288. if (isEven(levels[i])) {
  41289. if (t === 'R') {
  41290. levels[i] += 1;
  41291. } else if (t === 'AN' || t === 'EN') {
  41292. levels[i] += 2;
  41293. }
  41294. } else { // isOdd
  41295. if (t === 'L' || t === 'AN' || t === 'EN') {
  41296. levels[i] += 1;
  41297. }
  41298. }
  41299. }
  41300. /*
  41301. L1. On each line, reset the embedding level of the following characters to
  41302. the paragraph embedding level:
  41303. segment separators,
  41304. paragraph separators,
  41305. any sequence of whitespace characters preceding a segment separator or
  41306. paragraph separator, and any sequence of white space characters at the end
  41307. of the line.
  41308. */
  41309. // don't bother as text is only single line
  41310. /*
  41311. L2. From the highest level found in the text to the lowest odd level on
  41312. each line, reverse any contiguous sequence of characters that are at that
  41313. level or higher.
  41314. */
  41315. // find highest level & lowest odd level
  41316. var highestLevel = -1;
  41317. var lowestOddLevel = 99;
  41318. var level;
  41319. for (i = 0, ii = levels.length; i < ii; ++i) {
  41320. level = levels[i];
  41321. if (highestLevel < level) {
  41322. highestLevel = level;
  41323. }
  41324. if (lowestOddLevel > level && isOdd(level)) {
  41325. lowestOddLevel = level;
  41326. }
  41327. }
  41328. // now reverse between those limits
  41329. for (level = highestLevel; level >= lowestOddLevel; --level) {
  41330. // find segments to reverse
  41331. var start = -1;
  41332. for (i = 0, ii = levels.length; i < ii; ++i) {
  41333. if (levels[i] < level) {
  41334. if (start >= 0) {
  41335. reverseValues(chars, start, i);
  41336. start = -1;
  41337. }
  41338. } else if (start < 0) {
  41339. start = i;
  41340. }
  41341. }
  41342. if (start >= 0) {
  41343. reverseValues(chars, start, levels.length);
  41344. }
  41345. }
  41346. /*
  41347. L3. Combining marks applied to a right-to-left base character will at this
  41348. point precede their base character. If the rendering engine expects them to
  41349. follow the base characters in the final display process, then the ordering
  41350. of the marks and the base character must be reversed.
  41351. */
  41352. // don't bother for now
  41353. /*
  41354. L4. A character that possesses the mirrored property as specified by
  41355. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  41356. directionality of that character is R.
  41357. */
  41358. // don't mirror as characters are already mirrored in the pdf
  41359. // Finally, return string
  41360. var result = '';
  41361. for (i = 0, ii = chars.length; i < ii; ++i) {
  41362. var ch = chars[i];
  41363. if (ch !== '<' && ch !== '>') {
  41364. result += ch;
  41365. }
  41366. }
  41367. return createBidiText(result, isLTR);
  41368. }
  41369. return bidi;
  41370. })();
  41371. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  41372. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  41373. /* Copyright 2014 Opera Software ASA
  41374. *
  41375. * Licensed under the Apache License, Version 2.0 (the "License");
  41376. * you may not use this file except in compliance with the License.
  41377. * You may obtain a copy of the License at
  41378. *
  41379. * http://www.apache.org/licenses/LICENSE-2.0
  41380. *
  41381. * Unless required by applicable law or agreed to in writing, software
  41382. * distributed under the License is distributed on an "AS IS" BASIS,
  41383. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41384. * See the License for the specific language governing permissions and
  41385. * limitations under the License.
  41386. *
  41387. *
  41388. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  41389. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  41390. */
  41391. /* globals Uint32ArrayView */
  41392. 'use strict';
  41393. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  41394. // Workaround for missing math precison in JS.
  41395. var MASK_HIGH = 0xffff0000;
  41396. var MASK_LOW = 0xffff;
  41397. function MurmurHash3_64 (seed) {
  41398. var SEED = 0xc3d2e1f0;
  41399. this.h1 = seed ? seed & 0xffffffff : SEED;
  41400. this.h2 = seed ? seed & 0xffffffff : SEED;
  41401. }
  41402. var alwaysUseUint32ArrayView = false;
  41403. // old webkits have issues with non-aligned arrays
  41404. try {
  41405. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  41406. } catch (e) {
  41407. alwaysUseUint32ArrayView = true;
  41408. }
  41409. MurmurHash3_64.prototype = {
  41410. update: function MurmurHash3_64_update(input) {
  41411. var useUint32ArrayView = alwaysUseUint32ArrayView;
  41412. var i;
  41413. if (typeof input === 'string') {
  41414. var data = new Uint8Array(input.length * 2);
  41415. var length = 0;
  41416. for (i = 0; i < input.length; i++) {
  41417. var code = input.charCodeAt(i);
  41418. if (code <= 0xff) {
  41419. data[length++] = code;
  41420. }
  41421. else {
  41422. data[length++] = code >>> 8;
  41423. data[length++] = code & 0xff;
  41424. }
  41425. }
  41426. } else if (input instanceof Uint8Array) {
  41427. data = input;
  41428. length = data.length;
  41429. } else if (typeof input === 'object' && ('length' in input)) {
  41430. // processing regular arrays as well, e.g. for IE9
  41431. data = input;
  41432. length = data.length;
  41433. useUint32ArrayView = true;
  41434. } else {
  41435. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  41436. 'Input must be a string or array.');
  41437. }
  41438. var blockCounts = length >> 2;
  41439. var tailLength = length - blockCounts * 4;
  41440. // we don't care about endianness here
  41441. var dataUint32 = useUint32ArrayView ?
  41442. new Uint32ArrayView(data, blockCounts) :
  41443. new Uint32Array(data.buffer, 0, blockCounts);
  41444. var k1 = 0;
  41445. var k2 = 0;
  41446. var h1 = this.h1;
  41447. var h2 = this.h2;
  41448. var C1 = 0xcc9e2d51;
  41449. var C2 = 0x1b873593;
  41450. var C1_LOW = C1 & MASK_LOW;
  41451. var C2_LOW = C2 & MASK_LOW;
  41452. for (i = 0; i < blockCounts; i++) {
  41453. if (i & 1) {
  41454. k1 = dataUint32[i];
  41455. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  41456. k1 = k1 << 15 | k1 >>> 17;
  41457. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  41458. h1 ^= k1;
  41459. h1 = h1 << 13 | h1 >>> 19;
  41460. h1 = h1 * 5 + 0xe6546b64;
  41461. } else {
  41462. k2 = dataUint32[i];
  41463. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  41464. k2 = k2 << 15 | k2 >>> 17;
  41465. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  41466. h2 ^= k2;
  41467. h2 = h2 << 13 | h2 >>> 19;
  41468. h2 = h2 * 5 + 0xe6546b64;
  41469. }
  41470. }
  41471. k1 = 0;
  41472. switch (tailLength) {
  41473. case 3:
  41474. k1 ^= data[blockCounts * 4 + 2] << 16;
  41475. /* falls through */
  41476. case 2:
  41477. k1 ^= data[blockCounts * 4 + 1] << 8;
  41478. /* falls through */
  41479. case 1:
  41480. k1 ^= data[blockCounts * 4];
  41481. /* falls through */
  41482. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  41483. k1 = k1 << 15 | k1 >>> 17;
  41484. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  41485. if (blockCounts & 1) {
  41486. h1 ^= k1;
  41487. } else {
  41488. h2 ^= k1;
  41489. }
  41490. }
  41491. this.h1 = h1;
  41492. this.h2 = h2;
  41493. return this;
  41494. },
  41495. hexdigest: function MurmurHash3_64_hexdigest () {
  41496. var h1 = this.h1;
  41497. var h2 = this.h2;
  41498. h1 ^= h2 >>> 1;
  41499. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  41500. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  41501. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  41502. h1 ^= h2 >>> 1;
  41503. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  41504. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  41505. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  41506. h1 ^= h2 >>> 1;
  41507. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  41508. var hex = (arr[i] >>> 0).toString(16);
  41509. while (hex.length < 8) {
  41510. hex = '0' + hex;
  41511. }
  41512. str += hex;
  41513. }
  41514. return str;
  41515. }
  41516. };
  41517. return MurmurHash3_64;
  41518. })();
  41519. }).call((typeof window === 'undefined') ? this : window);
  41520. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  41521. // workerSrc is not set -- using last script url to define default location
  41522. PDFJS.workerSrc = (function () {
  41523. 'use strict';
  41524. var scriptTagContainer = document.body ||
  41525. document.getElementsByTagName('head')[0];
  41526. var pdfjsSrc = scriptTagContainer.lastChild.src;
  41527. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  41528. })();
  41529. }